Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
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 68... Line 98...
68
#include "solve-cycles.h"
98
#include "solve-cycles.h"
69
 
99
 
70
/*--------------------------------------------------------------------------*/
100
/*--------------------------------------------------------------------------*/
71
 
101
 
72
static void
102
static void
73
unit_write PROTO_N ((unit, shapes, num_shapes, writer))
103
unit_write(UnitP       unit,		    ShapeTableP shapes ,
74
	   PROTO_T (UnitP       unit X
-
 
75
		    ShapeTableP shapes X
-
 
76
		    unsigned    num_shapes X
104
		    unsigned    num_shapes ,
77
		    TDFWriterP  writer)
105
		    TDFWriterP  writer)
78
{
106
{
79
    unsigned  length = nstring_length (&(unit->contents));
107
    unsigned  length = nstring_length(& (unit->contents));
80
    MapTableP table;
108
    MapTableP table;
81
 
109
 
82
    if ((table = unit->map_table) != NIL (MapTableP)) {
110
    if ((table = unit->map_table) != NIL(MapTableP)) {
83
	ShapeClosureT shape_closure;
111
	ShapeClosureT shape_closure;
84
 
112
 
85
	shape_closure.table  = table;
113
	shape_closure.table  = table;
86
	shape_closure.writer = writer;
114
	shape_closure.writer = writer;
87
	debug_info_w_start_counts (num_shapes);
115
	debug_info_w_start_counts(num_shapes);
88
	tdf_write_int (writer, num_shapes);
116
	tdf_write_int(writer, num_shapes);
89
	shape_table_iter (shapes, shape_entry_write_count,
117
	shape_table_iter(shapes, shape_entry_write_count,
90
			  (GenericP) &shape_closure);
118
			 (GenericP) &shape_closure);
91
	debug_info_w_start_maps (num_shapes);
119
	debug_info_w_start_maps(num_shapes);
92
	tdf_write_int (writer, num_shapes);
120
	tdf_write_int(writer, num_shapes);
93
	shape_table_iter (shapes, shape_entry_write_links,
121
	shape_table_iter(shapes, shape_entry_write_links,
94
			  (GenericP) &shape_closure);
122
			 (GenericP) &shape_closure);
95
    } else {
123
    } else {
96
	debug_info_w_start_counts ((unsigned) 0);
124
	debug_info_w_start_counts((unsigned)0);
97
	tdf_write_int (writer, (unsigned) 0);
125
	tdf_write_int(writer,(unsigned)0);
98
	debug_info_w_start_maps ((unsigned) 0);
126
	debug_info_w_start_maps((unsigned)0);
99
	tdf_write_int (writer, (unsigned) 0);
127
	tdf_write_int(writer,(unsigned)0);
100
    }
128
    }
101
    debug_info_w_unit_body (length);
129
    debug_info_w_unit_body(length);
102
    tdf_write_int (writer, length);
130
    tdf_write_int(writer, length);
103
    tdf_write_bytes (writer, &(unit->contents));
131
    tdf_write_bytes(writer, & (unit->contents));
104
}
132
}
105
 
133
 
106
/*--------------------------------------------------------------------------*/
134
/*--------------------------------------------------------------------------*/
107
 
135
 
108
void
136
void
109
unit_set_contents PROTO_N ((unit, nstring))
137
unit_set_contents(UnitP    unit,			   NStringP nstring)
110
		  PROTO_T (UnitP    unit X
-
 
111
			   NStringP nstring)
-
 
112
{
138
{
113
    nstring_assign (&(unit->contents), nstring);
139
    nstring_assign(& (unit->contents), nstring);
114
}
140
}
115
 
141
 
116
MapTableP
142
MapTableP
117
unit_map_table PROTO_N ((unit))
143
unit_map_table(UnitP unit)
118
	       PROTO_T (UnitP unit)
-
 
119
{
144
{
120
    return (unit->map_table);
145
    return(unit->map_table);
121
}
146
}
122
 
147
 
123
UnitEntryP
148
UnitEntryP
124
unit_entry_create PROTO_N ((key, next, order))
149
unit_entry_create(NStringP   key,			   UnitEntryP next ,
125
		  PROTO_T (NStringP   key X
-
 
126
			   UnitEntryP next X
-
 
127
			   unsigned   order)
150
			   unsigned   order)
128
{
151
{
129
    UnitEntryP entry = ALLOCATE (UnitEntryT);
152
    UnitEntryP entry = ALLOCATE(UnitEntryT);
130
 
153
 
131
    entry->next  = next;
154
    entry->next  = next;
132
    entry->order = order;
155
    entry->order = order;
133
    nstring_copy (&(entry->key), key);
156
    nstring_copy(& (entry->key), key);
134
    entry->head  = NIL (UnitP);
157
    entry->head  = NIL(UnitP);
135
    entry->tail  = &(entry->head);
158
    entry->tail  = & (entry->head);
136
    return (entry);
159
    return(entry);
137
}
160
}
138
 
161
 
139
UnitEntryP
162
UnitEntryP
140
unit_entry_next PROTO_N ((entry))
163
unit_entry_next(UnitEntryP entry)
141
		PROTO_T (UnitEntryP entry)
-
 
142
{
164
{
143
    return (entry->next);
165
    return(entry->next);
144
}
166
}
145
 
167
 
146
NStringP
168
NStringP
147
unit_entry_key PROTO_N ((entry))
169
unit_entry_key(UnitEntryP entry)
148
	       PROTO_T (UnitEntryP entry)
-
 
149
{
170
{
150
    return (&(entry->key));
171
    return(& (entry->key));
151
}
172
}
152
 
173
 
153
unsigned
174
unsigned
154
unit_entry_order PROTO_N ((entry))
175
unit_entry_order(UnitEntryP entry)
155
		 PROTO_T (UnitEntryP entry)
-
 
156
{
176
{
157
    return (entry->order);
177
    return(entry->order);
158
}
178
}
159
 
179
 
160
UnitP
180
UnitP
161
unit_entry_add_unit PROTO_N ((entry, num_counts))
181
unit_entry_add_unit(UnitEntryP entry,			     unsigned   num_counts)
162
		    PROTO_T (UnitEntryP entry X
-
 
163
			     unsigned   num_counts)
-
 
164
{
182
{
165
    UnitP unit = ALLOCATE (UnitT);
183
    UnitP unit = ALLOCATE(UnitT);
166
 
184
 
167
    unit->next      = NIL (UnitP);
185
    unit->next      = NIL(UnitP);
168
    unit->map_table = ((num_counts != 0) ?
186
    unit->map_table = ((num_counts != 0)?
169
		       map_table_create () : NIL (MapTableP));
187
		       map_table_create(): NIL(MapTableP));
170
    *(entry->tail)  = unit;
188
    *(entry->tail) = unit;
171
    entry->tail     = &(unit->next);
189
    entry->tail     = & (unit->next);
172
    return (unit);
190
    return(unit);
173
}
191
}
174
 
192
 
175
/*--------------------------------------------------------------------------*/
193
/*--------------------------------------------------------------------------*/
176
 
194
 
177
void
195
void
178
unit_entry_do_count PROTO_N ((entry, gclosure))
196
unit_entry_do_count(UnitEntryP entry,			     GenericP   gclosure)
179
		    PROTO_T (UnitEntryP entry X
-
 
180
			     GenericP   gclosure)
-
 
181
{
197
{
182
    UnitSetClosureP closure = (UnitSetClosureP) gclosure;
198
    UnitSetClosureP closure = (UnitSetClosureP)gclosure;
183
    UnitP           unit;
199
    UnitP           unit;
184
 
200
 
185
    if ((unit = entry->head) != NIL (UnitP)) {
201
    if ((unit = entry->head) != NIL(UnitP)) {
186
	while (unit) {
202
	while (unit) {
187
	    MapTableP table;
203
	    MapTableP table;
188
 
204
 
189
	    if ((table = unit->map_table) != NIL (MapTableP)) {
205
	    if ((table = unit->map_table) != NIL(MapTableP)) {
190
		map_table_iter (table, map_entry_check_non_empty,
206
		map_table_iter(table, map_entry_check_non_empty,
191
				(GenericP) closure->shapes);
207
				(GenericP)closure->shapes);
192
	    }
208
	    }
193
	    unit = unit->next;
209
	    unit = unit->next;
194
	}
210
	}
195
	closure->num_unit_sets ++;
211
	closure->num_unit_sets++;
196
    }
212
    }
197
}
213
}
198
 
214
 
199
void
215
void
200
unit_entry_write_unit_set PROTO_N ((entry, tld_entry, writer))
216
unit_entry_write_unit_set(UnitEntryP entry,				   UnitEntryP tld_entry ,
201
			  PROTO_T (UnitEntryP entry X
-
 
202
				   UnitEntryP tld_entry X
-
 
203
				   TDFWriterP writer)
217
				   TDFWriterP writer)
204
{
218
{
205
    if ((entry->head) || (entry == tld_entry)) {
219
    if ((entry->head) || (entry == tld_entry)) {
206
	NStringP key = unit_entry_key (entry);
220
	NStringP key = unit_entry_key(entry);
207
 
221
 
208
	debug_info_w_unit_dec (key);
222
	debug_info_w_unit_dec(key);
209
	tdf_write_string (writer, key);
223
	tdf_write_string(writer, key);
210
    }
224
    }
211
}
225
}
212
 
226
 
213
void
227
void
214
unit_entry_write_tld_unit PROTO_N ((entry, shapes, writer))
228
unit_entry_write_tld_unit(UnitEntryP  entry,				   ShapeTableP shapes ,
215
			  PROTO_T (UnitEntryP  entry X
-
 
216
				   ShapeTableP shapes X
-
 
217
				   TDFWriterP  writer)
229
				   TDFWriterP  writer)
218
{
230
{
219
    unsigned size = (tdf_int_size ((unsigned) 1) + 1);
231
    unsigned size = (tdf_int_size((unsigned)1) + 1);
220
    NStringP key  = unit_entry_key (entry);
232
    NStringP key  = unit_entry_key(entry);
221
 
233
 
222
    debug_info_w_start_units (key, (unsigned) 1);
234
    debug_info_w_start_units(key,(unsigned)1);
223
    tdf_write_int (writer, (unsigned) 1);
235
    tdf_write_int(writer,(unsigned)1);
224
    debug_info_w_start_unit (key, (unsigned) 1, (unsigned) 1);
236
    debug_info_w_start_unit(key,(unsigned)1,(unsigned)1);
225
    debug_info_w_start_counts ((unsigned) 0);
237
    debug_info_w_start_counts((unsigned)0);
226
    tdf_write_int (writer, (unsigned) 0);
238
    tdf_write_int(writer,(unsigned)0);
227
    debug_info_w_start_maps ((unsigned) 0);
239
    debug_info_w_start_maps((unsigned)0);
228
    tdf_write_int (writer, (unsigned) 0);
240
    tdf_write_int(writer,(unsigned)0);
229
    shape_table_iter (shapes, shape_entry_compute_tld_size, (GenericP) &size);
241
    shape_table_iter(shapes, shape_entry_compute_tld_size,(GenericP) &size);
230
    size /= 2;
242
    size /= 2;
231
    debug_info_w_unit_body (size);
243
    debug_info_w_unit_body(size);
232
    tdf_write_int (writer, size);
244
    tdf_write_int(writer, size);
233
    tdf_write_align (writer);
245
    tdf_write_align(writer);
234
    debug_info_w_tld_version ((unsigned) 1);
246
    debug_info_w_tld_version((unsigned)1);
235
    tdf_write_int (writer, (unsigned) 1);
247
    tdf_write_int(writer,(unsigned)1);
236
    shape_table_iter (shapes, shape_entry_write_tld, (GenericP) writer);
248
    shape_table_iter(shapes, shape_entry_write_tld,(GenericP)writer);
237
    tdf_write_align (writer);
249
    tdf_write_align(writer);
238
}
250
}
239
 
251
 
240
void
252
void
241
unit_entry_write_units PROTO_N ((entry, shapes, num_shapes, writer))
253
unit_entry_write_units(UnitEntryP  entry,				ShapeTableP shapes ,
242
		       PROTO_T (UnitEntryP  entry X
-
 
243
				ShapeTableP shapes X
-
 
244
				unsigned    num_shapes X
254
				unsigned    num_shapes ,
245
				TDFWriterP  writer)
255
				TDFWriterP  writer)
246
{
256
{
247
    unsigned num_units = 0;
257
    unsigned num_units = 0;
248
    NStringP key       = unit_entry_key (entry);
258
    NStringP key       = unit_entry_key(entry);
249
    UnitP    unit;
259
    UnitP    unit;
250
 
260
 
251
    for (unit = entry->head; unit; unit = unit->next) {
261
    for (unit = entry->head; unit; unit = unit->next) {
252
	num_units ++;
262
	num_units++;
253
    }
263
    }
254
    if (num_units > 0) {
264
    if (num_units > 0) {
255
	unsigned i;
265
	unsigned i;
256
 
266
 
257
	debug_info_w_start_units (key, num_units);
267
	debug_info_w_start_units(key, num_units);
258
	tdf_write_int (writer, num_units);
268
	tdf_write_int(writer, num_units);
259
	for (unit = entry->head, i = 1; unit; unit = unit->next, i ++) {
269
	for (unit = entry->head, i = 1; unit; unit = unit->next, i++) {
260
	    debug_info_w_start_unit (key, i, num_units);
270
	    debug_info_w_start_unit(key, i, num_units);
261
	    unit_write (unit, shapes, num_shapes, writer);
271
	    unit_write(unit, shapes, num_shapes, writer);
262
	}
272
	}
263
    }
273
    }
264
}
274
}
265

275

266
/*
276
/*