Fix typo in OIDs corresponding to SHA256, SHA384, and SHA512 (#21707)
[mono-project.git] / mcs / jay / main.c
blob02d30ad4aaf82c274958040bd113b85f56e06479
1 /*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Robert Paul Corbett.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
37 #ifndef lint
38 char copyright[] =
39 "@(#) Copyright (c) 1989 The Regents of the University of California.\n\
40 All rights reserved.\n";
41 #endif /* not lint */
43 #ifndef lint
44 static char sccsid[] = "@(#)main.c 5.5 (Berkeley) 5/24/93";
45 #endif /* not lint */
47 #include <signal.h>
48 #include "defs.h"
50 // FIXME autoconf or use remove instead of unlink
51 #ifdef _MSC_VER
52 #include <io.h>
53 #else
54 #include <unistd.h>
55 #endif
57 char tflag;
58 char vflag;
59 int csharp = 0;
61 const char *file_prefix = (char*)"y";
62 char *myname = (char*)"yacc";
63 const char *temp_form = "yacc.XXXXXXX";
65 int lineno;
66 int outline;
68 char *action_file_name;
69 char *input_file_name = (char*)"";
70 char *prolog_file_name;
71 char *local_file_name;
72 char *verbose_file_name;
73 char *output_file_name = 0;
75 FILE *action_file; /* a temp file, used to save actions associated */
76 /* with rules until the parser is written */
77 FILE *input_file; /* the input file */
78 FILE *prolog_file; /* temp files, used to save text until all */
79 FILE *local_file; /* symbols have been defined */
80 FILE *verbose_file; /* y.output */
81 FILE *output_file; /* defaults to stdout */
83 int nitems;
84 int nrules;
85 int nsyms;
86 int ntokens;
87 int nvars;
88 int nmethods;
90 int start_symbol;
91 char **symbol_name;
92 short *symbol_value;
93 short *symbol_prec;
94 char *symbol_assoc;
95 char **methods;
97 short *ritem;
98 short *rlhs;
99 short *rrhs;
100 short *rprec;
101 char *rassoc;
102 short **derives;
103 char *nullable;
105 #if defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
106 #define unlink _unlink
108 mkstemp (char *template_name)
110 _mktemp (template_name);
111 return -1;
113 #else
114 extern char* getenv (const char*);
115 #endif
117 void
118 done (int k)
120 if (action_file) { fclose(action_file); unlink(action_file_name); }
121 if (prolog_file) { fclose(prolog_file); unlink(prolog_file_name); }
122 if (local_file) { fclose(local_file); unlink(local_file_name); }
123 if (output_file && (output_file != stdout)) { fclose(output_file); if (k != 0) unlink(output_file_name); }
124 exit(k);
127 static void
128 onintr (int signo)
130 (void)signo; // unused
131 done(1);
134 static void
135 set_signals (void)
137 #ifdef SIGINT
138 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
139 signal(SIGINT, onintr);
140 #endif
141 #ifdef SIGTERM
142 if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
143 signal(SIGTERM, onintr);
144 #endif
145 #ifdef SIGHUP
146 if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
147 signal(SIGHUP, onintr);
148 #endif
151 static void
152 usage (void)
154 fprintf(stderr, "usage: %s [-tvcp] [-b file_prefix] [-o output_filename] input_filename\n", myname);
155 exit(1);
158 static void
159 print_skel_dir(void)
161 printf ("%s\n", SKEL_DIRECTORY);
162 exit (0);
165 static void
166 getargs (int argc, char *argv[])
168 register int i;
169 register char *s;
171 if (argc > 0) myname = argv[0];
172 for (i = 1; i < argc; ++i)
174 s = argv[i];
175 if (*s != '-') break;
176 switch (*++s)
178 case '\0':
179 input_file = stdin;
180 if (i + 1 < argc) usage();
181 return;
183 case '-':
184 ++i;
185 goto no_more_options;
187 case 'b':
188 if (*++s)
189 file_prefix = s;
190 else if (++i < argc)
191 file_prefix = argv[i];
192 else
193 usage();
194 continue;
196 case 'o':
197 if (*++s)
198 output_file_name = s;
199 else if (++i < argc)
200 output_file_name = argv[i];
201 else
202 usage();
203 continue;
205 case 't':
206 tflag = 1;
207 break;
209 case 'p':
210 print_skel_dir ();
211 break;
213 case 'c':
214 csharp = 1;
215 line_format = "#line %d \"%s\"\n";
216 default_line_format = "#line default\n";
217 break;
219 case 'v':
220 vflag = 1;
221 break;
223 default:
224 usage();
227 for (;;)
229 switch (*++s)
231 case '\0':
232 goto end_of_option;
234 case 't':
235 tflag = 1;
236 break;
238 case 'v':
239 vflag = 1;
240 break;
242 case 'p':
243 print_skel_dir ();
244 break;
246 case 'c':
247 csharp = 1;
248 line_format = "#line %d \"%s\"\n";
249 default_line_format = "#line default\n";
251 break;
253 default:
254 usage();
257 end_of_option:;
260 no_more_options:;
261 if (i + 1 != argc) usage();
262 input_file_name = argv[i];
265 char *
266 allocate (unsigned n)
268 register char *p;
270 p = NULL;
271 if (n)
273 p = (char*)CALLOC(1, n);
274 if (!p) no_space();
276 return (p);
279 #ifdef __GNUC__
280 #define GNUC_UNUSED __attribute__((__unused__))
281 #else
282 #define GNUC_UNUSED
283 #endif
285 static void
286 create_file_names (void)
288 int i, len;
289 const char *tmpdir;
290 int mkstemp_res GNUC_UNUSED;
292 #if defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
293 tmpdir = ".";
294 #else
295 tmpdir = getenv("TMPDIR");
296 if (tmpdir == 0) tmpdir = getenv ("TMP");
297 if (tmpdir == 0) tmpdir = getenv ("TEMP");
298 if (tmpdir == 0) tmpdir = "/tmp";
299 #endif
301 len = strlen(tmpdir);
302 i = len + 13;
303 if (len && tmpdir[len-1] != '/')
304 ++i;
306 action_file_name = (char*)MALLOC(i);
307 if (action_file_name == 0) no_space();
308 prolog_file_name = (char*)MALLOC(i);
309 if (prolog_file_name == 0) no_space();
310 local_file_name = (char*)MALLOC(i);
311 if (local_file_name == 0) no_space();
313 strcpy(action_file_name, tmpdir);
314 strcpy(prolog_file_name, tmpdir);
315 strcpy(local_file_name, tmpdir);
317 if (len && tmpdir[len - 1] != '/')
319 action_file_name[len] = '/';
320 prolog_file_name[len] = '/';
321 local_file_name[len] = '/';
322 ++len;
325 strcpy(action_file_name + len, temp_form);
326 strcpy(prolog_file_name + len, temp_form);
327 strcpy(local_file_name + len, temp_form);
329 action_file_name[len + 5] = 'a';
330 prolog_file_name[len + 5] = 'p';
331 local_file_name[len + 5] = 'l';
333 mkstemp_res = mkstemp(action_file_name);
334 mkstemp_res = mkstemp(prolog_file_name);
335 mkstemp_res = mkstemp(local_file_name);
337 len = strlen(file_prefix);
339 if (vflag)
341 verbose_file_name = (char*)MALLOC(len + 8);
342 if (verbose_file_name == 0)
343 no_space();
344 strcpy(verbose_file_name, file_prefix);
345 strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
349 static void
350 open_files (void)
352 create_file_names();
354 if (input_file == 0)
356 input_file = fopen(input_file_name, "r");
357 if (input_file == 0)
358 open_error(input_file_name);
361 action_file = fopen(action_file_name, "w");
362 if (action_file == 0)
363 open_error(action_file_name);
365 prolog_file = fopen(prolog_file_name, "w");
366 if (prolog_file == 0)
367 open_error(prolog_file_name);
369 local_file = fopen(local_file_name, "w");
370 if (local_file == 0)
371 open_error(local_file_name);
373 if (vflag)
375 verbose_file = fopen(verbose_file_name, "w");
376 if (verbose_file == 0)
377 open_error(verbose_file_name);
380 if (output_file == 0)
382 if (output_file_name != 0) {
383 output_file = fopen(output_file_name, "w");
384 if (output_file == 0)
385 open_error(output_file_name);
386 } else {
387 output_file = stdout;
394 main (int argc, char *argv[])
396 set_signals();
397 getargs(argc, argv);
398 open_files();
399 reader();
400 lr0();
401 lalr();
402 make_parser();
403 verbose();
404 output();
405 done(0);
406 /*NOTREACHED*/