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-2005 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 53... Line 83...
53
    PROGRAM VERSION
83
    PROGRAM VERSION
54
 
84
 
55
    The program name and version number are given.
85
    The program name and version number are given.
56
*/
86
*/
57
 
87
 
58
char *progname = "tnc" ;
88
char *progname = "tnc";
59
static char *version = "Version: 1.9" ;
89
static char *version = "Version: 1.9";
60
 
90
 
61
 
91
 
62
/*
92
/*
63
    PROCESS AN OUTPUT OPTION
93
    PROCESS AN OUTPUT OPTION
64
 
94
 
65
    The show option corresponding to arg is set to t.
95
    The show option corresponding to arg is set to t.
66
*/
96
*/
67
 
97
 
68
static boolean output_option
98
static boolean
69
    PROTO_N ( ( arg, t ) )
-
 
70
    PROTO_T ( char *arg X boolean t )
99
output_option(char *arg, boolean t)
71
{
100
{
72
    boolean *p = null ;
101
    boolean *p = null;
73
    if ( streq ( arg, "tokdecs" ) ) {
102
    if (streq(arg, "tokdecs")) {
74
	p = &show_tokdecs ;
103
	p = &show_tokdecs;
75
    } else if ( streq ( arg, "tokdefs" ) ) {
104
    } else if (streq(arg, "tokdefs")) {
76
	p = &show_tokdefs ;
105
	p = &show_tokdefs;
77
    } else if ( streq ( arg, "aldecs" ) ) {
106
    } else if (streq(arg, "aldecs")) {
78
	p = &show_aldecs ;
107
	p = &show_aldecs;
79
    } else if ( streq ( arg, "aldefs" ) ) {
108
    } else if (streq(arg, "aldefs")) {
80
	p = &show_aldefs ;
109
	p = &show_aldefs;
81
    } else if ( streq ( arg, "tagdecs" ) ) {
110
    } else if (streq(arg, "tagdecs")) {
82
	p = &show_tagdecs ;
111
	p = &show_tagdecs;
83
    } else if ( streq ( arg, "tagdefs" ) ) {
112
    } else if (streq(arg, "tagdefs")) {
84
	p = &show_tagdefs ;
113
	p = &show_tagdefs;
85
    }
114
    }
86
    if ( p == null ) return ( 0 ) ;
115
    if (p == null) return(0);
87
    if ( t ) {
116
    if (t) {
88
	show_tokdecs = 0 ;
117
	show_tokdecs = 0;
89
	show_tokdefs = 0 ;
118
	show_tokdefs = 0;
90
	show_aldefs = 0 ;
119
	show_aldefs = 0;
91
	show_tagdecs = 0 ;
120
	show_tagdecs = 0;
92
	show_tagdefs = 0 ;
121
	show_tagdefs = 0;
93
    }
122
    }
94
    *p = t ;
123
    *p = t;
95
    return ( 1 ) ;
124
    return(1);
96
}
125
}
97
 
126
 
98
 
127
 
99
/*
128
/*
100
    MAIN ROUTINE
129
    MAIN ROUTINE
101
 
130
 
102
    This is the main routine.  It processes the command line arguments
131
    This is the main routine.  It processes the command line arguments
103
    and calls the appropriate input and output routines.
132
    and calls the appropriate input and output routines.
104
*/
133
*/
105
 
134
 
106
int main
135
int
107
    PROTO_N ( ( argc, argv ) )
-
 
108
    PROTO_T ( int argc X char **argv )
136
main(int argc, char **argv)
109
{
137
{
110
    int a ;
138
    int a;
111
    int status = 0 ;
139
    int status = 0;
112
    boolean expand = 0 ;
140
    boolean expand = 0;
113
    boolean evaluate = 0 ;
141
    boolean evaluate = 0;
114
    boolean lib_input = 0 ;
142
    boolean lib_input = 0;
115
    boolean output_next = 0 ;
143
    boolean output_next = 0;
116
    void ( *input_fn ) PROTO_S ( ( void ) ) ;
144
    void(*input_fn)(void);
117
    void ( *output_fn ) PROTO_S ( ( void ) ) ;
145
    void(*output_fn)(void);
118
 
146
 
119
    /* Default action : read text, encode TDF capsule */
147
    /* Default action : read text, encode TDF capsule */
120
    input_fn = read_capsule ;
148
    input_fn = read_capsule;
121
    output_fn = enc_capsule ;
149
    output_fn = enc_capsule;
122
    text_input = 1 ;
150
    text_input = 1;
123
    text_output = 0 ;
151
    text_output = 0;
124
 
152
 
125
    /* Initialize internal tables */
153
    /* Initialize internal tables */
126
    output = stdout ;
154
    output = stdout;
127
    init_tables () ;
155
    init_tables();
128
    init_constructs () ;
156
    init_constructs();
129
 
157
 
130
    /* Scan arguments */
158
    /* Scan arguments */
131
    for ( a = 1 ; a < argc ; a++ ) {
159
    for (a = 1; a < argc; a++) {
132
	char *arg = argv [a] ;
160
	char *arg = argv[a];
133
	if ( output_next ) {
161
	if (output_next) {
134
	    open_output ( arg ) ;
162
	    open_output(arg);
135
	    output_next = 0 ;
163
	    output_next = 0;
136
	} else if ( *arg == '-' ) {
164
	} else if (*arg == '-') {
137
	    boolean known = 0 ;
165
	    boolean known = 0;
138
	    switch ( arg [1] ) {
166
	    switch (arg[1]) {
139
		case 'h' : {
167
		case 'h': {
140
		    /* Help option */
168
		    /* Help option */
141
		    if ( streq ( arg, "-help" ) ) {
169
		    if (streq(arg, "-help")) {
142
			if ( status ) warning ( "Too many arguments" ) ;
170
			if (status)warning("Too many arguments");
143
			a++ ;
171
			a++;
144
			if ( a == argc ) {
172
			if (a == argc) {
145
			    help ( "all" ) ;
173
			    help("all");
146
			} else {
174
			} else {
147
			    while ( a < argc ) {
175
			    while (a < argc) {
148
				help ( argv [a] ) ;
176
				help(argv[a]);
149
				a++ ;
177
				a++;
150
			    }
178
			    }
151
			}
179
			}
152
			exit ( exit_status ) ;
180
			exit(exit_status);
153
		    }
181
		    }
154
		    break ;
182
		    break;
155
		}
183
		}
156
		case 'd' : {
184
		case 'd': {
157
		    if ( arg [2] == 0 || streq ( arg, "-decode" ) ) {
185
		    if (arg[2] == 0 || streq(arg, "-decode")) {
158
			/* Decode mode */
186
			/* Decode mode */
159
			input_fn = de_capsule ;
187
			input_fn = de_capsule;
160
			text_input = 0 ;
188
			text_input = 0;
161
			known = 1 ;
189
			known = 1;
162
		    }
190
		    }
163
		    break ;
191
		    break;
164
		}
192
		}
165
		case 'e' : {
193
		case 'e': {
166
		    if ( arg [2] == 0 || streq ( arg, "-encode" ) ) {
194
		    if (arg[2] == 0 || streq(arg, "-encode")) {
167
			/* Encode mode */
195
			/* Encode mode */
168
			output_fn = enc_capsule ;
196
			output_fn = enc_capsule;
169
			text_output = 0 ;
197
			text_output = 0;
170
			known = 1 ;
198
			known = 1;
171
		    } else if ( streq ( arg, "-eval" ) ) {
199
		    } else if (streq(arg, "-eval")) {
172
			evaluate = 1 ;
200
			evaluate = 1;
173
			known = 1 ;
201
			known = 1;
174
		    } else if ( streq ( arg, "-expand" ) ) {
202
		    } else if (streq(arg, "-expand")) {
175
			expand = 1 ;
203
			expand = 1;
176
			known = 1 ;
204
			known = 1;
177
		    }
205
		    }
178
		    break ;
206
		    break;
179
		}
207
		}
180
		case 'r' : {
208
		case 'r': {
181
		    if ( arg [2] == 0 || streq ( arg, "-read" ) ) {
209
		    if (arg[2] == 0 || streq(arg, "-read")) {
182
			/* Read mode */
210
			/* Read mode */
183
			input_fn = read_capsule ;
211
			input_fn = read_capsule;
184
			text_input = 1 ;
212
			text_input = 1;
185
			known = 1 ;
213
			known = 1;
186
		    }
214
		    }
187
		    break ;
215
		    break;
188
		}
216
		}
189
		case 'w' : {
217
		case 'w': {
190
		    if ( arg [2] == 0 || streq ( arg, "-write" ) ) {
218
		    if (arg[2] == 0 || streq(arg, "-write")) {
191
			/* Write mode */
219
			/* Write mode */
192
			output_fn = print_capsule ;
220
			output_fn = print_capsule;
193
			text_output = 1 ;
221
			text_output = 1;
194
			known = 1 ;
222
			known = 1;
195
		    }
223
		    }
196
		    break ;
224
		    break;
197
		}
225
		}
198
		case 'p' : {
226
		case 'p': {
199
		    if ( arg [2] == 0 || streq ( arg, "-print" ) ) {
227
		    if (arg[2] == 0 || streq(arg, "-print")) {
200
			/* Pretty printer mode */
228
			/* Pretty printer mode */
201
			input_fn = de_capsule ;
229
			input_fn = de_capsule;
202
			output_fn = print_capsule ;
230
			output_fn = print_capsule;
203
			text_input = 0 ;
231
			text_input = 0;
204
			text_output = 1 ;
232
			text_output = 1;
205
			known = 1 ;
233
			known = 1;
206
		    }
234
		    }
207
		    break ;
235
		    break;
208
		}
236
		}
209
		case 't' : {
237
		case 't': {
210
		    if ( arg [2] == 0 || streq ( arg, "-tsimp" ) ) {
238
		    if (arg[2] == 0 || streq(arg, "-tsimp")) {
211
			/* Expand token definitions */
239
			/* Expand token definitions */
212
			evaluate = 1 ;
240
			evaluate = 1;
213
			expand = 1 ;
241
			expand = 1;
214
			known = 1 ;
242
			known = 1;
215
		    }
243
		    }
216
		    break ;
244
		    break;
217
		}
245
		}
218
		case 'c' : {
246
		case 'c': {
219
		    if ( arg [2] == 0 || streq ( arg, "-check" ) ) {
247
		    if (arg[2] == 0 || streq(arg, "-check")) {
220
			/* Switch on shape checking */
248
			/* Switch on shape checking */
221
			init_shapes () ;
249
			init_shapes();
222
			do_check = 1 ;
250
			do_check = 1;
223
			known = 1 ;
251
			known = 1;
224
		    } else if ( streq ( arg, "-cv" ) ) {
252
		    } else if (streq(arg, "-cv")) {
225
			init_shapes () ;
253
			init_shapes();
226
			do_check = 1 ;
254
			do_check = 1;
227
			print_shapes = 1 ;
255
			print_shapes = 1;
228
			known = 1 ;
256
			known = 1;
229
		    }
257
		    }
230
		    break ;
258
		    break;
231
		}
259
		}
232
		case 'l' : {
260
		case 'l': {
233
		    if ( arg [2] == 0 || streq ( arg, "-lib" ) ) {
261
		    if (arg[2] == 0 || streq(arg, "-lib")) {
234
			lib_input = 1 ;
262
			lib_input = 1;
235
			known = 1 ;
263
			known = 1;
236
		    }
264
		    }
237
		    break ;
265
		    break;
238
		}
266
		}
239
		case 'f' : {
267
		case 'f': {
240
		    if ( arg [2] == 0 || streq ( arg, "-func" ) ) {
268
		    if (arg[2] == 0 || streq(arg, "-func")) {
241
			/* Check on form of input and output */
269
			/* Check on form of input and output */
242
			func_input = 1 ;
270
			func_input = 1;
243
			func_output = 1 ;
271
			func_output = 1;
244
			known = 1 ;
272
			known = 1;
245
		    } else if ( streq ( arg, "-func_out" ) ) {
273
		    } else if (streq(arg, "-func_out")) {
246
			func_output = 1 ;
274
			func_output = 1;
247
			known = 1 ;
275
			known = 1;
248
		    } else if ( streq ( arg, "-func_in" ) ) {
276
		    } else if (streq(arg, "-func_in")) {
249
			func_input = 1 ;
277
			func_input = 1;
250
			known = 1 ;
278
			known = 1;
251
		    }
279
		    }
252
		    break ;
280
		    break;
253
		}
281
		}
254
		case 'n' : {
282
		case 'n': {
255
		    if ( strncmp ( arg, "-no_", 4 ) == 0 ) {
283
		    if (strncmp(arg, "-no_", 4) == 0) {
256
			known = output_option ( arg + 4, 0 ) ;
284
			known = output_option(arg + 4, 0);
257
		    }
285
		    }
258
		    break ;
286
		    break;
259
		}
287
		}
260
		case 'o' : {
288
		case 'o': {
261
		    if ( arg [2] == 0 ) {
289
		    if (arg[2] == 0) {
262
			output_next = 1 ;
290
			output_next = 1;
263
			known = 1 ;
291
			known = 1;
264
		    } else if ( strncmp ( arg, "-only_", 6 ) == 0 ) {
292
		    } else if (strncmp(arg, "-only_", 6) == 0) {
265
			known = output_option ( arg + 6, 1 ) ;
293
			known = output_option(arg + 6, 1);
266
		    }
294
		    }
267
		    break ;
295
		    break;
268
		}
296
		}
269
		case 'q' : {
297
		case 'q': {
270
		    if ( arg [2] == 0 ) {
298
		    if (arg[2] == 0) {
271
			dont_check = 1 ;
299
			dont_check = 1;
272
			known = 1 ;
300
			known = 1;
273
		    }
301
		    }
274
		    break ;
302
		    break;
275
		}
303
		}
276
		case 'u' : {
304
		case 'u': {
277
		    if ( arg [2] == 0 || streq ( arg, "-unsorted" ) ) {
305
		    if (arg[2] == 0 || streq(arg, "-unsorted")) {
278
			order_names = 0 ;
306
			order_names = 0;
279
			known = 1 ;
307
			known = 1;
280
		    }
308
		    }
281
		    break ;
309
		    break;
282
		}
310
		}
283
		case 'v' : {
311
		case 'v': {
284
		    if ( arg [2] == 0 || streq ( arg, "-version" ) ) {
312
		    if (arg[2] == 0 || streq(arg, "-version")) {
285
			char *vn = version ;
313
			char *vn = version;
286
			char *rn = RELEASE ;
314
			char *rn = RELEASE;
287
			int v1 = VERSION_major ;
315
			int v1 = VERSION_major;
288
			int v2 = VERSION_minor ;
316
			int v2 = VERSION_minor;
289
			IGNORE fprintf ( stderr, "%s: %s", progname, vn ) ;
317
			IGNORE fprintf(stderr, "%s: %s", progname, vn);
290
			IGNORE fprintf ( stderr, " (TDF %d.%d)", v1, v2 ) ;
318
			IGNORE fprintf(stderr, " (TDF %d.%d)", v1, v2);
291
			IGNORE fprintf ( stderr, " (release %s)\n", rn ) ;
319
			IGNORE fprintf(stderr, " (release %s)\n", rn);
292
			known = 1 ;
320
			known = 1;
293
		    }
321
		    }
294
		    break ;
322
		    break;
295
		}
323
		}
296
		case 'I' : {
324
		case 'I': {
297
		    add_directory ( arg + 2 ) ;
325
		    add_directory(arg + 2);
298
		    known = 1 ;
326
		    known = 1;
299
		    break ;
327
		    break;
300
		}
328
		}
301
		case 'L' : {
329
		case 'L': {
302
		    local_prefix = arg + 2 ;
330
		    local_prefix = arg + 2;
303
		    known = 1 ;
331
		    known = 1;
304
		    break ;
332
		    break;
305
		}
333
		}
306
		case 'V' : {
334
		case 'V': {
307
		    if ( arg [2] == 0 ) {
335
		    if (arg[2] == 0) {
308
			verbose = 1 ;
336
			verbose = 1;
309
			known = 1 ;
337
			known = 1;
310
		    }
338
		    }
311
		    break ;
339
		    break;
312
		}
340
		}
313
	    }
341
	    }
314
	    if ( !known ) warning ( "Unknown option, %s", arg ) ;
342
	    if (!known)warning("Unknown option, %s", arg);
315
 
343
 
316
	} else {
344
	} else {
317
	    /* Initialize input and output files */
345
	    /* Initialize input and output files */
318
	    if ( status == 0 ) {
346
	    if (status == 0) {
319
		open_input ( arg, 0 ) ;
347
		open_input(arg, 0);
320
	    } else if ( status == 1 ) {
348
	    } else if (status == 1) {
321
		open_output ( arg ) ;
349
		open_output(arg);
322
	    } else {
350
	    } else {
323
		warning ( "Too many arguments" ) ;
351
		warning("Too many arguments");
324
	    }
352
	    }
325
	    status++ ;
353
	    status++;
326
	}
354
	}
327
    }
355
    }
328
 
356
 
329
    /* Check on library input */
357
    /* Check on library input */
330
    if ( lib_input && input_fn == de_capsule ) input_fn = de_library ;
358
    if (lib_input && input_fn == de_capsule)input_fn = de_library;
331
 
359
 
332
    /* Perform the appropriate actions */
360
    /* Perform the appropriate actions */
333
    if ( status == 0 ) fatal_error ( "Not enough arguments" ) ;
361
    if (status == 0)fatal_error("Not enough arguments");
334
    ( *input_fn ) () ;
362
   (*input_fn)();
335
    if ( exit_status == EXIT_SUCCESS || text_output ) {
363
    if (exit_status == EXIT_SUCCESS || text_output) {
336
	if ( expand ) expand_all () ;
364
	if (expand)expand_all();
337
	if ( evaluate ) eval_all () ;
365
	if (evaluate)eval_all();
338
	sort_all () ;
366
	sort_all();
339
	( *output_fn ) () ;
367
	(*output_fn)();
340
    }
368
    }
341
    return ( exit_status ) ;
369
    return(exit_status);
342
}
370
}