Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/algol60/src/tools/tnc/main.c – Rev 7

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 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
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997
7 7u83 33
 
2 7u83 34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
7 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
7 7u83 45
 
2 7u83 46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
7 7u83 49
 
2 7u83 50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
7 7u83 53
 
2 7u83 54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
#include "config.h"
62
#include "release.h"
63
#include "types.h"
64
#include "read_types.h"
65
#include "analyser.h"
66
#include "check.h"
67
#include "de_types.h"
68
#include "de_capsule.h"
69
#include "enc_cap.h"
70
#include "eval.h"
71
#include "file.h"
72
#include "help.h"
73
#include "node.h"
74
#include "read_cap.h"
75
#include "shape.h"
76
#include "tdf.h"
77
#include "table.h"
78
#include "utility.h"
79
#include "write.h"
80
 
81
 
82
/*
83
    PROGRAM VERSION
84
 
85
    The program name and version number are given.
86
*/
87
 
7 7u83 88
char *progname = "tnc";
89
static char *version = "Version: 1.9";
2 7u83 90
 
91
 
92
/*
93
    PROCESS AN OUTPUT OPTION
94
 
95
    The show option corresponding to arg is set to t.
96
*/
97
 
7 7u83 98
static boolean
99
output_option(char *arg, boolean t)
2 7u83 100
{
7 7u83 101
    boolean *p = null;
102
    if (streq(arg, "tokdecs")) {
103
	p = &show_tokdecs;
104
    } else if (streq(arg, "tokdefs")) {
105
	p = &show_tokdefs;
106
    } else if (streq(arg, "aldecs")) {
107
	p = &show_aldecs;
108
    } else if (streq(arg, "aldefs")) {
109
	p = &show_aldefs;
110
    } else if (streq(arg, "tagdecs")) {
111
	p = &show_tagdecs;
112
    } else if (streq(arg, "tagdefs")) {
113
	p = &show_tagdefs;
2 7u83 114
    }
7 7u83 115
    if (p == null) return(0);
116
    if (t) {
117
	show_tokdecs = 0;
118
	show_tokdefs = 0;
119
	show_aldefs = 0;
120
	show_tagdecs = 0;
121
	show_tagdefs = 0;
2 7u83 122
    }
7 7u83 123
    *p = t;
124
    return(1);
2 7u83 125
}
126
 
127
 
128
/*
129
    MAIN ROUTINE
130
 
131
    This is the main routine.  It processes the command line arguments
132
    and calls the appropriate input and output routines.
133
*/
134
 
7 7u83 135
int
136
main(int argc, char **argv)
2 7u83 137
{
7 7u83 138
    int a;
139
    int status = 0;
140
    boolean expand = 0;
141
    boolean evaluate = 0;
142
    boolean lib_input = 0;
143
    boolean output_next = 0;
144
    void(*input_fn)(void);
145
    void(*output_fn)(void);
2 7u83 146
 
147
    /* Default action : read text, encode TDF capsule */
7 7u83 148
    input_fn = read_capsule;
149
    output_fn = enc_capsule;
150
    text_input = 1;
151
    text_output = 0;
2 7u83 152
 
153
    /* Initialize internal tables */
7 7u83 154
    output = stdout;
155
    init_tables();
156
    init_constructs();
2 7u83 157
 
158
    /* Scan arguments */
7 7u83 159
    for (a = 1; a < argc; a++) {
160
	char *arg = argv[a];
161
	if (output_next) {
162
	    open_output(arg);
163
	    output_next = 0;
164
	} else if (*arg == '-') {
165
	    boolean known = 0;
166
	    switch (arg[1]) {
167
		case 'h': {
2 7u83 168
		    /* Help option */
7 7u83 169
		    if (streq(arg, "-help")) {
170
			if (status)warning("Too many arguments");
171
			a++;
172
			if (a == argc) {
173
			    help("all");
2 7u83 174
			} else {
7 7u83 175
			    while (a < argc) {
176
				help(argv[a]);
177
				a++;
2 7u83 178
			    }
179
			}
7 7u83 180
			exit(exit_status);
2 7u83 181
		    }
7 7u83 182
		    break;
2 7u83 183
		}
7 7u83 184
		case 'd': {
185
		    if (arg[2] == 0 || streq(arg, "-decode")) {
2 7u83 186
			/* Decode mode */
7 7u83 187
			input_fn = de_capsule;
188
			text_input = 0;
189
			known = 1;
2 7u83 190
		    }
7 7u83 191
		    break;
2 7u83 192
		}
7 7u83 193
		case 'e': {
194
		    if (arg[2] == 0 || streq(arg, "-encode")) {
2 7u83 195
			/* Encode mode */
7 7u83 196
			output_fn = enc_capsule;
197
			text_output = 0;
198
			known = 1;
199
		    } else if (streq(arg, "-eval")) {
200
			evaluate = 1;
201
			known = 1;
202
		    } else if (streq(arg, "-expand")) {
203
			expand = 1;
204
			known = 1;
2 7u83 205
		    }
7 7u83 206
		    break;
2 7u83 207
		}
7 7u83 208
		case 'r': {
209
		    if (arg[2] == 0 || streq(arg, "-read")) {
2 7u83 210
			/* Read mode */
7 7u83 211
			input_fn = read_capsule;
212
			text_input = 1;
213
			known = 1;
2 7u83 214
		    }
7 7u83 215
		    break;
2 7u83 216
		}
7 7u83 217
		case 'w': {
218
		    if (arg[2] == 0 || streq(arg, "-write")) {
2 7u83 219
			/* Write mode */
7 7u83 220
			output_fn = print_capsule;
221
			text_output = 1;
222
			known = 1;
2 7u83 223
		    }
7 7u83 224
		    break;
2 7u83 225
		}
7 7u83 226
		case 'p': {
227
		    if (arg[2] == 0 || streq(arg, "-print")) {
2 7u83 228
			/* Pretty printer mode */
7 7u83 229
			input_fn = de_capsule;
230
			output_fn = print_capsule;
231
			text_input = 0;
232
			text_output = 1;
233
			known = 1;
2 7u83 234
		    }
7 7u83 235
		    break;
2 7u83 236
		}
7 7u83 237
		case 't': {
238
		    if (arg[2] == 0 || streq(arg, "-tsimp")) {
2 7u83 239
			/* Expand token definitions */
7 7u83 240
			evaluate = 1;
241
			expand = 1;
242
			known = 1;
2 7u83 243
		    }
7 7u83 244
		    break;
2 7u83 245
		}
7 7u83 246
		case 'c': {
247
		    if (arg[2] == 0 || streq(arg, "-check")) {
2 7u83 248
			/* Switch on shape checking */
7 7u83 249
			init_shapes();
250
			do_check = 1;
251
			known = 1;
252
		    } else if (streq(arg, "-cv")) {
253
			init_shapes();
254
			do_check = 1;
255
			print_shapes = 1;
256
			known = 1;
2 7u83 257
		    }
7 7u83 258
		    break;
2 7u83 259
		}
7 7u83 260
		case 'l': {
261
		    if (arg[2] == 0 || streq(arg, "-lib")) {
262
			lib_input = 1;
263
			known = 1;
2 7u83 264
		    }
7 7u83 265
		    break;
2 7u83 266
		}
7 7u83 267
		case 'f': {
268
		    if (arg[2] == 0 || streq(arg, "-func")) {
2 7u83 269
			/* Check on form of input and output */
7 7u83 270
			func_input = 1;
271
			func_output = 1;
272
			known = 1;
273
		    } else if (streq(arg, "-func_out")) {
274
			func_output = 1;
275
			known = 1;
276
		    } else if (streq(arg, "-func_in")) {
277
			func_input = 1;
278
			known = 1;
2 7u83 279
		    }
7 7u83 280
		    break;
2 7u83 281
		}
7 7u83 282
		case 'n': {
283
		    if (strncmp(arg, "-no_", 4) == 0) {
284
			known = output_option(arg + 4, 0);
2 7u83 285
		    }
7 7u83 286
		    break;
2 7u83 287
		}
7 7u83 288
		case 'o': {
289
		    if (arg[2] == 0) {
290
			output_next = 1;
291
			known = 1;
292
		    } else if (strncmp(arg, "-only_", 6) == 0) {
293
			known = output_option(arg + 6, 1);
2 7u83 294
		    }
7 7u83 295
		    break;
2 7u83 296
		}
7 7u83 297
		case 'q': {
298
		    if (arg[2] == 0) {
299
			dont_check = 1;
300
			known = 1;
2 7u83 301
		    }
7 7u83 302
		    break;
2 7u83 303
		}
7 7u83 304
		case 'u': {
305
		    if (arg[2] == 0 || streq(arg, "-unsorted")) {
306
			order_names = 0;
307
			known = 1;
2 7u83 308
		    }
7 7u83 309
		    break;
2 7u83 310
		}
7 7u83 311
		case 'v': {
312
		    if (arg[2] == 0 || streq(arg, "-version")) {
313
			char *vn = version;
314
			char *rn = RELEASE;
315
			int v1 = VERSION_major;
316
			int v2 = VERSION_minor;
317
			IGNORE fprintf(stderr, "%s: %s", progname, vn);
318
			IGNORE fprintf(stderr, " (TDF %d.%d)", v1, v2);
319
			IGNORE fprintf(stderr, " (release %s)\n", rn);
320
			known = 1;
2 7u83 321
		    }
7 7u83 322
		    break;
2 7u83 323
		}
7 7u83 324
		case 'I': {
325
		    add_directory(arg + 2);
326
		    known = 1;
327
		    break;
2 7u83 328
		}
7 7u83 329
		case 'L': {
330
		    local_prefix = arg + 2;
331
		    known = 1;
332
		    break;
2 7u83 333
		}
7 7u83 334
		case 'V': {
335
		    if (arg[2] == 0) {
336
			verbose = 1;
337
			known = 1;
2 7u83 338
		    }
7 7u83 339
		    break;
2 7u83 340
		}
341
	    }
7 7u83 342
	    if (!known)warning("Unknown option, %s", arg);
2 7u83 343
 
344
	} else {
345
	    /* Initialize input and output files */
7 7u83 346
	    if (status == 0) {
347
		open_input(arg, 0);
348
	    } else if (status == 1) {
349
		open_output(arg);
2 7u83 350
	    } else {
7 7u83 351
		warning("Too many arguments");
2 7u83 352
	    }
7 7u83 353
	    status++;
2 7u83 354
	}
355
    }
356
 
357
    /* Check on library input */
7 7u83 358
    if (lib_input && input_fn == de_capsule)input_fn = de_library;
2 7u83 359
 
360
    /* Perform the appropriate actions */
7 7u83 361
    if (status == 0)fatal_error("Not enough arguments");
362
   (*input_fn)();
363
    if (exit_status == EXIT_SUCCESS || text_output) {
364
	if (expand)expand_all();
365
	if (evaluate)eval_all();
366
	sort_all();
367
	(*output_fn)();
2 7u83 368
    }
7 7u83 369
    return(exit_status);
2 7u83 370
}