]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/TianoTools/Pccts/dlg/main.c
Fix some cleanall issues
[mirror_edk2.git] / Tools / Source / TianoTools / Pccts / dlg / main.c
CommitLineData
878ddf1f 1/* Main function for dlg version\r
2 *\r
3 * SOFTWARE RIGHTS\r
4 *\r
5 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r
6 * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r
7 * company may do whatever they wish with source code distributed with\r
8 * PCCTS or the code generated by PCCTS, including the incorporation of\r
9 * PCCTS, or its output, into commerical software.\r
10 *\r
11 * We encourage users to develop software with PCCTS. However, we do ask\r
12 * that credit is given to us for developing PCCTS. By "credit",\r
13 * we mean that if you incorporate our source code into one of your\r
14 * programs (commercial product, research project, or otherwise) that you\r
15 * acknowledge this fact somewhere in the documentation, research report,\r
16 * etc... If you like PCCTS and have developed a nice tool with the\r
17 * output, please mention that you developed it using PCCTS. In\r
18 * addition, we ask that this header remain intact in our source code.\r
19 * As long as these guidelines are kept, we expect to continue enhancing\r
20 * this system and expect to make other tools available as they are\r
21 * completed.\r
22 *\r
23 * DLG 1.33\r
24 * Will Cohen\r
25 * With mods by Terence Parr; AHPCRC, University of Minnesota\r
26 * 1989-2001\r
27 */\r
28\r
29#include <stdio.h>\r
30#include "stdpccts.h"\r
31\r
32char program[] = "dlg";\r
33char version[] = "1.33MR33"; /* MRXXX */\r
34int numfiles = 0;\r
35char *file_str[2] = {NULL, NULL};\r
36char *mode_file = "mode.h";\r
37char *class_name = DEFAULT_CLASSNAME;\r
38char *OutputDirectory = TopDirectory;\r
39\r
40/* Option variables */\r
41int comp_level = 0;\r
42int interactive = FALSE;\r
43int case_insensitive = FALSE;\r
44int warn_ambig = FALSE;\r
45int gen_cpp = FALSE;\r
46\r
47#ifdef __USE_PROTOS\r
48static int ci_strequ(char *a,char *b)\r
49#else\r
50static int ci_strequ(a,b)\r
51 char *a;\r
52 char *b;\r
53#endif\r
54{\r
55 for ( ;*a != 0 && *b != 0; a++, b++) {\r
56 if (toupper(*a) != toupper(*b)) return 0;\r
57 }\r
58 return (*a == *b);\r
59}\r
60\r
61/* Option List Stuff */\r
62#ifdef __USE_PROTOS\r
63void p_comp0(void) {comp_level = 0;}\r
64void p_comp1(void) {comp_level = 1;}\r
65void p_comp2(void) {comp_level = 2;}\r
66void p_stdio(void) { file_str[numfiles++] = NULL;}\r
67void p_file(char *s) { file_str[numfiles++] = s;}\r
68void p_cl_name(char *s, char *t)\r
69 {\r
70 if ( gen_cpp ) {\r
71 class_name = t;\r
72 }\r
73 else {\r
74 warning("-cl only valid in C++ mode; -cl ignored...",0);\r
75 }\r
76 }\r
77void p_mode_file(char *s, char *t){mode_file=t;}\r
78void p_outdir(char *s,char *t) {OutputDirectory=t;}\r
79void p_ansi(void) {gen_ansi = TRUE;}\r
80void p_interactive(void) {interactive = TRUE;}\r
81void p_case_s(void) { case_insensitive = FALSE; }\r
82void p_case_i(void) { case_insensitive = TRUE; }\r
83void p_warn_ambig(void) { warn_ambig = TRUE; }\r
84void p_cpp(void) { gen_cpp = TRUE; }\r
85#else\r
86void p_comp0() {comp_level = 0;}\r
87void p_comp1() {comp_level = 1;}\r
88void p_comp2() {comp_level = 2;}\r
89void p_stdio() { file_str[numfiles++] = NULL;}\r
90void p_file(s) char *s; { file_str[numfiles++] = s;}\r
91void p_cl_name(s,t)\r
92 char *s, *t;\r
93 {\r
94 if ( gen_cpp ) {\r
95 class_name = t;\r
96 }\r
97 else {\r
98 warning("-cl only valid in C++ mode; -cl ignored...",0);\r
99 }\r
100 }\r
101void p_mode_file(s,t) char *s,*t;{mode_file=t;}\r
102void p_outdir(s,t) char *s,*t;{OutputDirectory=t;}\r
103void p_ansi() {gen_ansi = TRUE;}\r
104void p_interactive() {interactive = TRUE;}\r
105void p_case_s() { case_insensitive = FALSE; }\r
106void p_case_i() { case_insensitive = TRUE; }\r
107void p_warn_ambig() { warn_ambig = TRUE; }\r
108void p_cpp() { gen_cpp = TRUE; }\r
109#endif\r
110\r
111#ifdef __cplusplus\r
112typedef void (*WildFunc)(...);\r
113#else\r
114typedef void (*WildFunc)();\r
115#endif\r
116\r
117typedef struct {\r
118 char *option;\r
119 int arg;\r
120 WildFunc process;\r
121 char *descr;\r
122 } Opt;\r
123\r
124Opt options[] = {\r
125 { "-CC", 0, (WildFunc)p_cpp, "Generate C++ output" },\r
126 { "-C0", 0, (WildFunc)p_comp0, "No compression (default)" },\r
127 { "-C1", 0, (WildFunc)p_comp1, "Compression level 1" },\r
128 { "-C2", 0, (WildFunc)p_comp2, "Compression level 2" },\r
129 { "-ga", 0, (WildFunc)p_ansi, "Generate ansi C"},\r
130 { "-Wambiguity", 0, (WildFunc)p_warn_ambig, "Warn if expressions ambiguous"},\r
131 { "-m", 1, (WildFunc)p_mode_file, "Rename lexical mode output file"},\r
132 { "-i", 0, (WildFunc)p_interactive, "Build interactive scanner (not valid for C++ mode)"},\r
133 { "-ci", 0, (WildFunc)p_case_i, "Make lexical analyzer case insensitive"},\r
134 { "-cl", 1, (WildFunc)p_cl_name, "Rename lexer class (DLGLexer); only used for -CC"},\r
135 { "-cs", 0, (WildFunc)p_case_s, "Make lexical analyzer case sensitive (default)"},\r
136 { "-o", 1, (WildFunc)p_outdir, OutputDirectoryOption},\r
137 { "-", 0, (WildFunc)p_stdio, "Use standard i/o rather than file"},\r
138 { "*", 0, (WildFunc)p_file, ""}, /* anything else is a file */\r
139 { NULL, 0, NULL } \r
140 };\r
141\r
142#ifdef __USE_PROTOS\r
143void ProcessArgs(int argc, char **argv, Opt *options)\r
144#else\r
145void ProcessArgs(argc, argv, options)\r
146int argc;\r
147char **argv;\r
148Opt *options;\r
149#endif\r
150{\r
151 Opt *p;\r
152 \r
153 while ( argc-- > 0 )\r
154 {\r
155 p = options;\r
156 while ( p->option != NULL )\r
157 {\r
158 if ( strcmp(p->option, "*") == 0 ||\r
159 ci_strequ(p->option,*argv) )\r
160 {\r
161 if ( p->arg )\r
162 {\r
163 (*p->process)( *argv, *(argv+1) );\r
164 argv++;\r
165 argc--;\r
166 }\r
167 else\r
168 (*p->process)( *argv );\r
169 break;\r
170 }\r
171 p++;\r
172 }\r
173 argv++;\r
174 }\r
175}\r
176\r
177#ifdef __USE_PROTOS\r
178int main(int argc, char *argv[])\r
179#else\r
180int main(argc, argv)\r
181int argc;\r
182char *argv[];\r
183#endif\r
184{\r
185 init();\r
186 fprintf(stderr, "%s Version %s 1989-2001\n", &(program[0]),\r
187 &(version[0]));\r
188 if ( argc == 1 )\r
189 {\r
190 Opt *p = options;\r
191 fprintf(stderr, "%s [options] f1 f2 ... fn\n",argv[0]);\r
192 while ( *(p->option) != '*' )\r
193 {\r
194 fprintf(stderr, "\t%s %s\t%s\n",\r
195 p->option,\r
196 (p->arg)?"___":" ",\r
197 p->descr);\r
198 p++;\r
199 }\r
200 }else{\r
201 ProcessArgs(argc-1, &(argv[1]), options);\r
202 if (interactive && gen_cpp) {\r
203 fprintf(stderr,"\n");\r
204/*** MR21a This statement is wrong ! ***/\r
205#if 0\r
206*** fprintf(stderr,"Interactive lexer option (\"-i\") has no effect when in C++ mode\n");\r
207*** fprintf(stderr,"because of extra buffering provided by ANTLRTokenBuffer class.\n");\r
208*** fprintf(stderr,"\n");\r
209#endif\r
210 }\r
211 input_stream = read_stream(file_str[0]);\r
212 if (input_stream) {\r
213 /* don't overwrite unless input okay */\r
214 if ( gen_cpp ) {\r
215 output_stream = write_stream(ClassName(CPP_FILE_SUFFIX));\r
216 if ( file_str[1]!=NULL ) {\r
217 warning("output file implicit in C++ mode; ignored...",0);\r
218 }\r
219 class_stream = write_stream(ClassName(".h"));\r
220 mode_stream = class_stream;\r
221 }\r
222 else {\r
223 output_stream = write_stream(file_str[1]);\r
224 mode_stream = write_stream(mode_file);\r
225 }\r
226 }\r
227 /* make sure that error reporting routines in grammar\r
228 know what the file really is */\r
229 /* make sure that reading and writing somewhere */\r
230 if (input_stream && output_stream && mode_stream){\r
231 ANTLR(grammar(), input_stream);\r
232 }\r
233 p_class_def2(); /* MR1 */\r
234 }\r
235 if ( output_stream!=NULL ) fclose(output_stream);\r
236 if ( !gen_cpp && mode_stream!=NULL ) fclose(mode_stream);\r
237 if ( class_stream!=NULL ) fclose(class_stream);\r
238 exit(PCCTS_EXIT_SUCCESS);\r
239 return 0; /* get rid of warning message MR1 */\r
240}\r
241\r
242/* initialize all the variables */\r
243void \r
244#ifdef __USE_PROTOS\r
245init(void)\r
246#else\r
247init()\r
248#endif\r
249{\r
250 register int i;\r
251\r
252#ifdef SPECIAL_INITS\r
253 special_inits(); /* MR1 */\r
254#endif\r
255 used_chars = empty;\r
256 used_classes = empty;\r
257 /* make the valid character set */\r
258 normal_chars = empty;\r
259 /* NOTE: MIN_CHAR is EOF */\r
260 /* NOTE: EOF is not quite a valid char, it is special. Skip it*/\r
261 for (i = 1; i<CHAR_RANGE; ++i){\r
262 set_orel(i,&normal_chars);\r
263 }\r
264 make_nfa_model_node();\r
265 clear_hash();\r
266 /* NOTE: need to set this flag before the lexer starts getting */\r
267 /* tokens */\r
268 func_action = FALSE; \r
269}\r
270\r
271/* stuff that needs to be reset when a new automaton is being built */\r
272void \r
273#ifdef __USE_PROTOS\r
274new_automaton_mode(void) /* MR1 */\r
275#else\r
276new_automaton_mode() /* MR1 */\r
277#endif\r
278{\r
279 set_free(used_chars);\r
280 clear_hash();\r
281}\r