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 68... Line 98...
68
#include "solve-cycles.h"
98
#include "solve-cycles.h"
69
 
99
 
70
/*--------------------------------------------------------------------------*/
100
/*--------------------------------------------------------------------------*/
71
 
101
 
72
static LibraryP *
102
static LibraryP *
73
builder_read_libraries PROTO_N ((arg_data, num_libs_ref, num_capsules_ref))
103
builder_read_libraries(ArgDataP  arg_data,				unsigned *num_libs_ref ,
74
		       PROTO_T (ArgDataP  arg_data X
-
 
75
				unsigned *num_libs_ref X
-
 
76
				unsigned *num_capsules_ref)
104
				unsigned *num_capsules_ref)
77
{
105
{
78
    unsigned  num_lib_files   = arg_data_num_library_files (arg_data);
106
    unsigned  num_lib_files   = arg_data_num_library_files(arg_data);
79
    CStringP *lib_files       = arg_data_library_files (arg_data);
107
    CStringP *lib_files       = arg_data_library_files(arg_data);
80
    LibraryP *libraries       = ALLOCATE_VECTOR (LibraryP, num_lib_files);
108
    LibraryP *libraries       = ALLOCATE_VECTOR(LibraryP, num_lib_files);
81
    unsigned  num_capsules    = 0;
109
    unsigned  num_capsules    = 0;
82
    unsigned  i;
110
    unsigned  i;
83
 
111
 
84
    for (i = 0; i < num_lib_files; i ++) {
112
    for (i = 0; i < num_lib_files; i++) {
85
	LibraryP library = library_create_stream_input (lib_files [i]);
113
	LibraryP library = library_create_stream_input(lib_files[i]);
86
 
114
 
87
	if (library != NIL (LibraryP)) {
115
	if (library != NIL(LibraryP)) {
88
	    ShapeTableP lib_shapes = shape_table_create ();
116
	    ShapeTableP lib_shapes = shape_table_create();
89
 
117
 
90
	    library_read (library, lib_shapes);
118
	    library_read(library, lib_shapes);
91
	    library_close (library);
119
	    library_close(library);
92
	    libraries [i] = library;
120
	    libraries[i] = library;
93
	    num_capsules += library_num_capsules (library);
121
	    num_capsules += library_num_capsules(library);
94
	    shape_table_deallocate (lib_shapes);
122
	    shape_table_deallocate(lib_shapes);
95
	} else {
123
	} else {
96
	    libraries [i] = NIL (LibraryP);
124
	    libraries[i] = NIL(LibraryP);
97
	    E_cannot_open_input_file (lib_files [i]);
125
	    E_cannot_open_input_file(lib_files[i]);
98
	}
126
	}
99
    }
127
    }
100
    *num_libs_ref = num_lib_files;
128
    *num_libs_ref = num_lib_files;
101
    *num_capsules_ref = num_capsules;
129
    *num_capsules_ref = num_capsules;
102
    return (libraries);
130
    return(libraries);
103
}
131
}
104
 
132
 
105
static void
133
static void
106
builder_read_capsule PROTO_N ((capsule, capsules, capsule_index, units,
134
builder_read_capsule(CapsuleP capsule, CapsuleP *capsules,
107
			       shapes))
-
 
108
		     PROTO_T (CapsuleP    capsule X
-
 
109
			      CapsuleP   *capsules X
-
 
110
			      unsigned    capsule_index X
135
		     unsigned capsule_index, UnitTableP units,
111
			      UnitTableP  units X
-
 
112
			      ShapeTableP shapes)
136
		     ShapeTableP shapes)
113
{
137
{
114
    CStringP name = capsule_name (capsule);
138
    CStringP name = capsule_name(capsule);
115
    unsigned i;
139
    unsigned i;
116
 
140
 
117
    for (i = 0; i < capsule_index; i ++) {
141
    for (i = 0; i < capsule_index; i++) {
118
	if (cstring_equal (name, capsule_name (capsules [i]))) {
142
	if (cstring_equal(name, capsule_name(capsules[i]))) {
119
	    E_duplicate_capsule_name (name);
143
	    E_duplicate_capsule_name(name);
120
	}
144
	}
121
    }
145
    }
122
    capsule_set_index (capsule, capsule_index);
146
    capsule_set_index(capsule, capsule_index);
123
    capsule_read (capsule, units, shapes);
147
    capsule_read(capsule, units, shapes);
124
    capsule_store_contents (capsule);
148
    capsule_store_contents(capsule);
125
    capsule_close (capsule);
149
    capsule_close(capsule);
126
    capsules [capsule_index] = capsule;
150
    capsules[capsule_index] = capsule;
127
}
151
}
128
 
152
 
129
static CapsuleP *
153
static CapsuleP *
130
builder_read_capsules PROTO_N ((arg_data, units, shapes, num_capsules_ref))
154
builder_read_capsules(ArgDataP    arg_data,			       UnitTableP  units ,
131
		      PROTO_T (ArgDataP    arg_data X
-
 
132
			       UnitTableP  units X
-
 
133
			       ShapeTableP shapes X
155
			       ShapeTableP shapes ,
134
			       unsigned   *num_capsules_ref)
156
			       unsigned   *num_capsules_ref)
135
{
157
{
136
    unsigned  num_input_files = arg_data_get_num_files (arg_data);
158
    unsigned  num_input_files = arg_data_get_num_files(arg_data);
137
    CStringP *input_files     = arg_data_get_files (arg_data);
159
    CStringP *input_files     = arg_data_get_files(arg_data);
138
    unsigned  capsule_index   = 0;
160
    unsigned  capsule_index   = 0;
139
    unsigned  num_libraries;
161
    unsigned  num_libraries;
140
    LibraryP *libraries;
162
    LibraryP *libraries;
141
    unsigned  num_capsules;
163
    unsigned  num_capsules;
142
    CapsuleP *capsules;
164
    CapsuleP *capsules;
143
    unsigned  i;
165
    unsigned  i;
144
 
166
 
145
    libraries     = builder_read_libraries (arg_data, &num_libraries,
167
    libraries     = builder_read_libraries(arg_data, &num_libraries,
146
					    &num_capsules);
168
					    &num_capsules);
147
    num_capsules += num_input_files;
169
    num_capsules += num_input_files;
148
    capsules      = ALLOCATE_VECTOR (CapsuleP, num_capsules);
170
    capsules      = ALLOCATE_VECTOR(CapsuleP, num_capsules);
149
    for (i = 0; i < num_libraries; i ++) {
171
    for (i = 0; i < num_libraries; i++) {
150
	LibraryP library = libraries [i];
172
	LibraryP library = libraries[i];
151
 
173
 
152
	if (library != NIL (LibraryP)) {
174
	if (library != NIL(LibraryP)) {
153
	    unsigned num_lib_capsules = library_num_capsules (library);
175
	    unsigned num_lib_capsules = library_num_capsules(library);
154
	    unsigned j;
176
	    unsigned j;
155
 
177
 
156
	    for (j = 0; j < num_lib_capsules; j ++) {
178
	    for (j = 0; j < num_lib_capsules; j++) {
157
		LibCapsuleP lib_capsule = library_get_capsule (library, j);
179
		LibCapsuleP lib_capsule = library_get_capsule(library, j);
158
		CStringP    name        = lib_capsule_name (lib_capsule);
180
		CStringP    name        = lib_capsule_name(lib_capsule);
159
		NStringP    contents    = lib_capsule_contents (lib_capsule);
181
		NStringP    contents    = lib_capsule_contents(lib_capsule);
160
		CapsuleP    capsule;
182
		CapsuleP    capsule;
161
 
183
 
162
		capsule = capsule_create_string_input (name, contents);
184
		capsule = capsule_create_string_input(name, contents);
163
		builder_read_capsule (capsule, capsules, capsule_index,
185
		builder_read_capsule(capsule, capsules, capsule_index,
164
				      units, shapes);
186
				      units, shapes);
165
		capsule_index ++;
187
		capsule_index++;
166
	    }
188
	    }
167
	}
189
	}
168
    }
190
    }
169
    DEALLOCATE (libraries);
191
    DEALLOCATE(libraries);
170
    for (i = 0; i < num_input_files; i ++) {
192
    for (i = 0; i < num_input_files; i++) {
171
	CapsuleP capsule;
193
	CapsuleP capsule;
172
 
194
 
173
	if ((capsule = capsule_create_stream_input (input_files [i])) !=
195
	if ((capsule = capsule_create_stream_input(input_files[i])) !=
174
	    NIL (CapsuleP)) {
196
	    NIL(CapsuleP)) {
175
	    builder_read_capsule (capsule, capsules, capsule_index, units,
197
	    builder_read_capsule(capsule, capsules, capsule_index, units,
176
				  shapes);
198
				  shapes);
177
	    capsule_index ++;
199
	    capsule_index++;
178
	} else {
200
	} else {
179
	    E_cannot_open_input_file (input_files [i]);
201
	    E_cannot_open_input_file(input_files[i]);
180
	}
202
	}
181
    }
203
    }
182
    if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
204
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
183
	exit (EXIT_FAILURE);
205
	exit(EXIT_FAILURE);
184
	UNREACHED;
206
	UNREACHED;
185
    }
207
    }
186
    *num_capsules_ref = num_capsules;
208
    *num_capsules_ref = num_capsules;
187
    return (capsules);
209
    return(capsules);
188
}
210
}
189
 
211
 
190
static void
212
static void
191
builder_check_multi_defs PROTO_N ((shapes))
213
builder_check_multi_defs(ShapeTableP shapes)
192
			 PROTO_T (ShapeTableP shapes)
-
 
193
{
214
{
194
    shape_table_iter (shapes, shape_entry_check_multi_defs, NIL (GenericP));
215
    shape_table_iter(shapes, shape_entry_check_multi_defs, NIL(GenericP));
195
    if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
216
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
196
	exit (EXIT_FAILURE);
217
	exit(EXIT_FAILURE);
197
	UNREACHED;
218
	UNREACHED;
198
    }
219
    }
199
}
220
}
200
 
221
 
201
static void
222
static void
202
builder_suppress_1 PROTO_N ((shape, all, names, gclosure))
223
builder_suppress_1(NStringP     shape,			    BoolT        all ,
203
		   PROTO_T (NStringP     shape X
-
 
204
			    BoolT        all X
-
 
205
			    NameKeyListP names X
224
			    NameKeyListP names ,
206
			    GenericP     gclosure)
225
			    GenericP     gclosure)
207
{
226
{
208
    ShapeTableP lib_shapes = (ShapeTableP) gclosure;
227
    ShapeTableP lib_shapes = (ShapeTableP)gclosure;
209
    ShapeEntryP entry      = shape_table_get (lib_shapes, shape);
228
    ShapeEntryP entry      = shape_table_get(lib_shapes, shape);
210
 
229
 
211
    if (entry) {
230
    if (entry) {
212
	NameTableP        table = shape_entry_name_table (entry);
231
	NameTableP        table = shape_entry_name_table(entry);
213
	NameKeyListEntryP name  = name_key_list_head (names);
232
	NameKeyListEntryP name  = name_key_list_head(names);
214
 
233
 
215
	if (all) {
234
	if (all) {
216
	    name_table_iter (table, name_entry_builder_suppress,
235
	    name_table_iter(table, name_entry_builder_suppress,
217
			     (GenericP) shape);
236
			    (GenericP)shape);
218
	}
237
	}
219
	for (; name; name = name_key_list_entry_next (name)) {
238
	for (; name; name = name_key_list_entry_next(name)) {
220
	    NameKeyP   key        = name_key_list_entry_key (name);
239
	    NameKeyP   key        = name_key_list_entry_key(name);
221
	    NameEntryP name_entry = name_table_get (table, key);
240
	    NameEntryP name_entry = name_table_get(table, key);
222
 
241
 
223
	    if (name_entry) {
242
	    if (name_entry) {
224
		debug_info_l_suppress (shape, key);
243
		debug_info_l_suppress(shape, key);
225
		name_entry_set_definition (name_entry, NIL (CapsuleP));
244
		name_entry_set_definition(name_entry, NIL(CapsuleP));
226
	    }
245
	    }
227
	}
246
	}
228
    }
247
    }
229
}
248
}
230
 
249
 
231
static void
250
static void
232
builder_suppress PROTO_N ((arg_data, lib_shapes))
251
builder_suppress(ArgDataP    arg_data,			  ShapeTableP lib_shapes)
233
		 PROTO_T (ArgDataP    arg_data X
-
 
234
			  ShapeTableP lib_shapes)
-
 
235
{
252
{
236
    if (arg_data_get_suppress_mult (arg_data)) {
253
    if (arg_data_get_suppress_mult(arg_data)) {
237
	shape_table_iter (lib_shapes, shape_entry_suppress_mult,
254
	shape_table_iter(lib_shapes, shape_entry_suppress_mult,
238
			  NIL (GenericP));
255
			  NIL(GenericP));
239
    }
256
    }
240
    shape_control_iter (arg_data_get_suppresses (arg_data), builder_suppress_1,
257
    shape_control_iter(arg_data_get_suppresses(arg_data), builder_suppress_1,
241
			(GenericP) lib_shapes);
258
			(GenericP)lib_shapes);
242
    if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
259
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
243
	exit (EXIT_FAILURE);
260
	exit(EXIT_FAILURE);
244
	UNREACHED;
261
	UNREACHED;
245
    }
262
    }
246
}
263
}
247
 
264
 
248
static void
265
static void
249
builder_write_library PROTO_N ((arg_data, shapes, num_capsules, capsules))
266
builder_write_library(ArgDataP    arg_data,			       ShapeTableP shapes ,
250
		      PROTO_T (ArgDataP    arg_data X
-
 
251
			       ShapeTableP shapes X
-
 
252
			       unsigned    num_capsules X
267
			       unsigned    num_capsules ,
253
			       CapsuleP   *capsules)
268
			       CapsuleP   *capsules)
254
{
269
{
255
    CStringP output_file = arg_data_get_output_file (arg_data);
270
    CStringP output_file = arg_data_get_output_file(arg_data);
256
    LibraryP library;
271
    LibraryP library;
257
 
272
 
258
    if ((library = library_create_stream_output (output_file)) !=
273
    if ((library = library_create_stream_output(output_file)) !=
259
	NIL (LibraryP)) {
274
	NIL(LibraryP)) {
260
	library_write (library, shapes, num_capsules, capsules);
275
	library_write(library, shapes, num_capsules, capsules);
261
	library_close (library);
276
	library_close(library);
262
    } else {
277
    } else {
263
	E_cannot_open_output_file (output_file);
278
	E_cannot_open_output_file(output_file);
264
	UNREACHED;
279
	UNREACHED;
265
    }
280
    }
266
    if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
281
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
267
	exit (EXIT_FAILURE);
282
	exit(EXIT_FAILURE);
268
	UNREACHED;
283
	UNREACHED;
269
    }
284
    }
270
}
285
}
271
 
286
 
272
/*--------------------------------------------------------------------------*/
287
/*--------------------------------------------------------------------------*/
273
 
288
 
274
void
289
void
275
builder_main PROTO_N ((arg_data))
290
builder_main(ArgDataP arg_data)
276
	     PROTO_T (ArgDataP arg_data)
-
 
277
{
291
{
278
    UnitTableP  units  = unit_table_create ();
292
    UnitTableP  units  = unit_table_create();
279
    ShapeTableP shapes = shape_table_create ();
293
    ShapeTableP shapes = shape_table_create();
280
    unsigned    num_capsules;
294
    unsigned    num_capsules;
281
    CapsuleP   *capsules;
295
    CapsuleP   *capsules;
282
 
296
 
283
    capsules = builder_read_capsules (arg_data, units, shapes, &num_capsules);
297
    capsules = builder_read_capsules(arg_data, units, shapes, &num_capsules);
284
    builder_check_multi_defs (shapes);
298
    builder_check_multi_defs(shapes);
285
    builder_suppress (arg_data, shapes);
299
    builder_suppress(arg_data, shapes);
286
    builder_write_library (arg_data, shapes, num_capsules, capsules);
300
    builder_write_library(arg_data, shapes, num_capsules, capsules);
287
}
301
}
288

302

289
/*
303
/*
290
 * Local variables(smf):
304
 * Local variables(smf):
291
 * eval: (include::add-path-entry "../os-interface" "../library" "../tdf")
305
 * eval: (include::add-path-entry "../os-interface" "../library" "../tdf")