Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 66... Line 96...
66
#include "solve-cycles.h"
96
#include "solve-cycles.h"
67
 
97
 
68
/*--------------------------------------------------------------------------*/
98
/*--------------------------------------------------------------------------*/
69
 
99
 
70
static void
100
static void
71
tdf_write_nibble PROTO_N ((writer, nibble))
101
tdf_write_nibble(TDFWriterP writer,			  unsigned   nibble)
72
		 PROTO_T (TDFWriterP writer X
-
 
73
			  unsigned   nibble)
-
 
74
{
102
{
75
    if (writer->new_byte) {
103
    if (writer->new_byte) {
76
	writer->new_byte = FALSE;
104
	writer->new_byte = FALSE;
77
	writer->byte     = (ByteT) ((nibble & 0x0F) << 4);
105
	writer->byte     = (ByteT)((nibble & 0x0F) << 4);
78
    } else {
106
    } else {
79
	writer->new_byte = TRUE;
107
	writer->new_byte = TRUE;
80
	writer->byte    |= (ByteT) (nibble & 0x0F);
108
	writer->byte    |= (ByteT)(nibble & 0x0F);
81
	bostream_write_byte (&(writer->bostream), writer->byte);
109
	bostream_write_byte(& (writer->bostream), writer->byte);
82
    }
110
    }
83
}
111
}
84
 
112
 
85
/*--------------------------------------------------------------------------*/
113
/*--------------------------------------------------------------------------*/
86
 
114
 
87
BoolT
115
BoolT
88
tdf_writer_open PROTO_N ((writer, name))
116
tdf_writer_open(TDFWriterP writer,			 CStringP   name)
89
		PROTO_T (TDFWriterP writer X
-
 
90
			 CStringP   name)
-
 
91
{
117
{
92
    writer->new_byte = TRUE;
118
    writer->new_byte = TRUE;
93
    if (!bostream_open (&(writer->bostream), name)) {
119
    if (!bostream_open(& (writer->bostream), name)) {
94
	return (FALSE);
120
	return(FALSE);
95
    }
121
    }
96
    return (TRUE);
122
    return(TRUE);
97
}
123
}
98
 
124
 
99
CStringP
125
CStringP
100
tdf_writer_name PROTO_N ((writer))
126
tdf_writer_name(TDFWriterP writer)
101
		PROTO_T (TDFWriterP writer)
-
 
102
{
127
{
103
    return (bostream_name (&(writer->bostream)));
128
    return(bostream_name(& (writer->bostream)));
104
}
129
}
105
 
130
 
106
void
131
void
107
tdf_write_int PROTO_N ((writer, value))
132
tdf_write_int(TDFWriterP writer,		       unsigned   value)
108
	      PROTO_T (TDFWriterP writer X
-
 
109
		       unsigned   value)
-
 
110
{
133
{
111
    unsigned shift = 0;
134
    unsigned shift = 0;
112
    unsigned tmp   = value;
135
    unsigned tmp   = value;
113
    unsigned mask  = (~(unsigned) 0x07);
136
    unsigned mask  = (~(unsigned)0x07);
114
 
137
 
115
    while (tmp & mask) {
138
    while (tmp & mask) {
116
	tmp >>= 3;
139
	tmp >>= 3;
117
	shift ++;
140
	shift++;
118
    }
141
    }
119
    while (shift) {
142
    while (shift) {
120
	tmp = ((value >> (3 * shift)) & 0x07);
143
	tmp = ((value >> (3 * shift)) & 0x07);
121
	shift --;
144
	shift--;
122
	tdf_write_nibble (writer, tmp);
145
	tdf_write_nibble(writer, tmp);
123
    }
146
    }
124
    tmp = ((value & 0x07) | 0x08);
147
    tmp = ((value & 0x07) | 0x08);
125
    tdf_write_nibble (writer, tmp);
148
    tdf_write_nibble(writer, tmp);
126
}
149
}
127
 
150
 
128
void
151
void
129
tdf_write_align PROTO_N ((writer))
152
tdf_write_align(TDFWriterP writer)
130
		PROTO_T (TDFWriterP writer)
-
 
131
{
153
{
132
    if (!(writer->new_byte)) {
154
    if (!(writer->new_byte)) {
133
	bostream_write_byte (&(writer->bostream), writer->byte);
155
	bostream_write_byte(& (writer->bostream), writer->byte);
134
	writer->new_byte = TRUE;
156
	writer->new_byte = TRUE;
135
    }
157
    }
136
}
158
}
137
 
159
 
138
void
160
void
139
tdf_write_bytes PROTO_N ((writer, nstring))
161
tdf_write_bytes(TDFWriterP writer,			 NStringP   nstring)
140
		PROTO_T (TDFWriterP writer X
-
 
141
			 NStringP   nstring)
-
 
142
{
162
{
143
    unsigned length   = nstring_length (nstring);
163
    unsigned length   = nstring_length(nstring);
144
    CStringP contents = nstring_contents (nstring);
164
    CStringP contents = nstring_contents(nstring);
145
 
165
 
146
    tdf_write_align (writer);
166
    tdf_write_align(writer);
147
    bostream_write_chars (&(writer->bostream), length, contents);
167
    bostream_write_chars(& (writer->bostream), length, contents);
148
}
168
}
149
 
169
 
150
void
170
void
151
tdf_write_string PROTO_N ((writer, nstring))
171
tdf_write_string(TDFWriterP writer,			  NStringP   nstring)
152
		 PROTO_T (TDFWriterP writer X
-
 
153
			  NStringP   nstring)
-
 
154
{
172
{
155
    unsigned length = nstring_length (nstring);
173
    unsigned length = nstring_length(nstring);
156
 
174
 
157
    tdf_write_int (writer, (unsigned) 8);
175
    tdf_write_int(writer,(unsigned)8);
158
    tdf_write_int (writer, length);
176
    tdf_write_int(writer, length);
159
    tdf_write_bytes (writer, nstring);
177
    tdf_write_bytes(writer, nstring);
160
}
178
}
161
 
179
 
162
void
180
void
163
tdf_write_name PROTO_N ((writer, name))
181
tdf_write_name(TDFWriterP writer,			NameKeyP   name)
164
	       PROTO_T (TDFWriterP writer X
-
 
165
			NameKeyP   name)
-
 
166
{
182
{
167
    unsigned  type;
183
    unsigned  type;
168
    unsigned  components;
184
    unsigned  components;
169
    unsigned  i;
185
    unsigned  i;
170
    NStringP  nstring;
186
    NStringP  nstring;
171
 
187
 
172
    switch (name_key_type (name)) EXHAUSTIVE {
188
    switch (name_key_type(name))EXHAUSTIVE {
173
      case KT_STRING:
189
      case KT_STRING:
174
	type = (unsigned) (0x1 << 2);
190
	type = (unsigned)(0x1 << 2);
175
	tdf_write_nibble (writer, type);
191
	tdf_write_nibble(writer, type);
176
	tdf_write_align (writer);
192
	tdf_write_align(writer);
177
	tdf_write_string (writer, name_key_string (name));
193
	tdf_write_string(writer, name_key_string(name));
178
	break;
194
	break;
179
      case KT_UNIQUE:
195
      case KT_UNIQUE:
180
	type = (unsigned) (0x2 << 2);
196
	type = (unsigned)(0x2 << 2);
181
	tdf_write_nibble (writer, type);
197
	tdf_write_nibble(writer, type);
182
	tdf_write_align (writer);
198
	tdf_write_align(writer);
183
	components = name_key_components (name);
199
	components = name_key_components(name);
184
	tdf_write_int (writer, components);
200
	tdf_write_int(writer, components);
185
	for (i = 0; i < components; i ++) {
201
	for (i = 0; i < components; i++) {
186
	    nstring = name_key_get_component (name, i);
202
	    nstring = name_key_get_component(name, i);
187
	    tdf_write_string (writer, nstring);
203
	    tdf_write_string(writer, nstring);
188
	}
204
	}
189
	break;
205
	break;
190
    }
206
    }
191
}
207
}
192
 
208
 
193
void
209
void
194
tdf_writer_close PROTO_N ((writer))
210
tdf_writer_close(TDFWriterP writer)
195
		 PROTO_T (TDFWriterP writer)
-
 
196
{
211
{
197
    tdf_write_align (writer);
212
    tdf_write_align(writer);
198
    bostream_close (&(writer->bostream));
213
    bostream_close(& (writer->bostream));
199
}
214
}
200

215

201
/*
216
/*
202
 * Local variables(smf):
217
 * Local variables(smf):
203
 * eval: (include::add-path-entry "../os-interface" "../library")
218
 * eval: (include::add-path-entry "../os-interface" "../library")