2 |
7u83 |
1 |
/*
|
6 |
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
|
6 |
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:-
|
6 |
7u83 |
42 |
|
2 |
7u83 |
43 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
44 |
reproduced upon any copies or amended versions of it;
|
6 |
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;
|
6 |
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;
|
6 |
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 "tdf.h"
|
|
|
63 |
#include "cmd_ops.h"
|
|
|
64 |
#include "spec_ops.h"
|
|
|
65 |
#include "error.h"
|
|
|
66 |
#include "input.h"
|
|
|
67 |
#include "lex.h"
|
|
|
68 |
#include "output.h"
|
|
|
69 |
#include "syntax.h"
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
/*
|
|
|
73 |
MAIN ROUTINE
|
|
|
74 |
|
|
|
75 |
This is the main routine. It processes the command-line options,
|
|
|
76 |
reads the input file, and writes the output files.
|
|
|
77 |
*/
|
|
|
78 |
|
6 |
7u83 |
79 |
int
|
|
|
80 |
main(int argc, char **argv)
|
2 |
7u83 |
81 |
{
|
6 |
7u83 |
82 |
int a;
|
|
|
83 |
int too_many = 0;
|
|
|
84 |
char *input = NULL;
|
|
|
85 |
char *templ = NULL;
|
|
|
86 |
char *output = NULL;
|
2 |
7u83 |
87 |
|
|
|
88 |
/* Process arguments */
|
6 |
7u83 |
89 |
set_progname(argv[0], "2.0");
|
|
|
90 |
for (a = 1; a < argc; a++) {
|
|
|
91 |
char *arg = argv[a];
|
|
|
92 |
if (arg[0] == '-' && arg[1]) {
|
|
|
93 |
int known = 0;
|
|
|
94 |
switch (arg[1]) {
|
|
|
95 |
case 'v': {
|
|
|
96 |
if (arg[2]) break;
|
|
|
97 |
report_version();
|
|
|
98 |
known = 1;
|
|
|
99 |
break;
|
2 |
7u83 |
100 |
}
|
|
|
101 |
}
|
6 |
7u83 |
102 |
if (!known) {
|
|
|
103 |
error(ERROR_WARNING, "Unknown option, '%s'", arg);
|
2 |
7u83 |
104 |
}
|
|
|
105 |
} else {
|
6 |
7u83 |
106 |
if (input == NULL) {
|
|
|
107 |
input = arg;
|
|
|
108 |
} else if (templ == NULL) {
|
|
|
109 |
templ = arg;
|
|
|
110 |
} else if (output == NULL) {
|
|
|
111 |
output = arg;
|
2 |
7u83 |
112 |
} else {
|
6 |
7u83 |
113 |
too_many = 1;
|
2 |
7u83 |
114 |
}
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
/* Check arguments */
|
6 |
7u83 |
119 |
if (too_many) error(ERROR_WARNING, "Too many arguments");
|
2 |
7u83 |
120 |
|
|
|
121 |
/* Process the input */
|
6 |
7u83 |
122 |
builtin_sorts();
|
|
|
123 |
if (open_file(input)) {
|
|
|
124 |
SPECIFICATION spec = NULL_spec;
|
|
|
125 |
ADVANCE_LEXER;
|
|
|
126 |
read_spec(&spec);
|
|
|
127 |
close_file();
|
|
|
128 |
if (!IS_NULL_spec(spec)) {
|
|
|
129 |
COMMAND cmd = NULL_cmd;
|
|
|
130 |
if (open_file(templ)) {
|
|
|
131 |
MAKE_cmd_simple(1, "<dummy>", cmd);
|
|
|
132 |
cmd = read_template(cmd);
|
|
|
133 |
close_file();
|
2 |
7u83 |
134 |
}
|
6 |
7u83 |
135 |
if (!IS_NULL_cmd(cmd)) {
|
|
|
136 |
output_spec(output, spec, cmd);
|
2 |
7u83 |
137 |
}
|
|
|
138 |
}
|
|
|
139 |
}
|
6 |
7u83 |
140 |
return(exit_status);
|
2 |
7u83 |
141 |
}
|