2 * Copyright (c) 1989 The Regents of the University of California.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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
39 "@(#) Copyright (c) 1989 The Regents of the University of California.\n\
40 All rights reserved.\n";
44 static char sccsid[] = "@(#)main.c 5.5 (Berkeley) 5/24/93";
54 char *file_prefix = "y";
55 char *myname = "yacc";
56 char *temp_form = "yacc.XXXXXXX";
61 char *action_file_name;
62 char *input_file_name = "";
63 char *prolog_file_name;
64 char *local_file_name;
65 char *verbose_file_name;
67 FILE *action_file; /* a temp file, used to save actions associated */
68 /* with rules until the parser is written */
69 FILE *input_file; /* the input file */
70 FILE *prolog_file; /* temp files, used to save text until all */
71 FILE *local_file; /* symbols have been defined */
72 FILE *verbose_file; /* y.output */
94 #if defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
95 extern char* mktemp();
96 #define mkstemp mktemp
99 extern char *getenv();
104 if (action_file) { fclose(action_file); unlink(action_file_name); }
105 if (prolog_file) { fclose(prolog_file); unlink(prolog_file_name); }
106 if (local_file) { fclose(local_file); unlink(local_file_name); }
122 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
123 signal(SIGINT, onintr);
126 if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
127 signal(SIGTERM, onintr);
130 if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
131 signal(SIGHUP, onintr);
138 fprintf(stderr, "usage: %s [-tvcp] [-b file_prefix] filename\n", myname);
145 printf ("%s\n", SKEL_DIRECTORY);
156 if (argc > 0) myname = argv[0];
157 for (i = 1; i < argc; ++i)
160 if (*s != '-') break;
165 if (i + 1 < argc) usage();
170 goto no_more_options;
176 file_prefix = argv[i];
191 line_format = "#line %d \"%s\"\n";
192 default_line_format = "#line default\n";
234 if (i + 1 != argc) usage();
235 input_file_name = argv[i];
260 #if defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
263 tmpdir = getenv("TMPDIR");
264 if (tmpdir == 0) tmpdir = getenv ("TMP");
265 if (tmpdir == 0) tmpdir = getenv ("TEMP");
266 if (tmpdir == 0) tmpdir = "/tmp";
269 len = strlen(tmpdir);
271 if (len && tmpdir[len-1] != '/')
274 action_file_name = MALLOC(i);
275 if (action_file_name == 0) no_space();
276 prolog_file_name = MALLOC(i);
277 if (prolog_file_name == 0) no_space();
278 local_file_name = MALLOC(i);
279 if (local_file_name == 0) no_space();
281 strcpy(action_file_name, tmpdir);
282 strcpy(prolog_file_name, tmpdir);
283 strcpy(local_file_name, tmpdir);
285 if (len && tmpdir[len - 1] != '/')
287 action_file_name[len] = '/';
288 prolog_file_name[len] = '/';
289 local_file_name[len] = '/';
293 strcpy(action_file_name + len, temp_form);
294 strcpy(prolog_file_name + len, temp_form);
295 strcpy(local_file_name + len, temp_form);
297 action_file_name[len + 5] = 'a';
298 prolog_file_name[len + 5] = 'p';
299 local_file_name[len + 5] = 'l';
301 mkstemp(action_file_name);
302 mkstemp(prolog_file_name);
303 mkstemp(local_file_name);
305 len = strlen(file_prefix);
309 verbose_file_name = MALLOC(len + 8);
310 if (verbose_file_name == 0)
312 strcpy(verbose_file_name, file_prefix);
313 strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
324 input_file = fopen(input_file_name, "r");
326 open_error(input_file_name);
329 action_file = fopen(action_file_name, "w");
330 if (action_file == 0)
331 open_error(action_file_name);
333 prolog_file = fopen(prolog_file_name, "w");
334 if (prolog_file == 0)
335 open_error(prolog_file_name);
337 local_file = fopen(local_file_name, "w");
339 open_error(local_file_name);
343 verbose_file = fopen(verbose_file_name, "w");
344 if (verbose_file == 0)
345 open_error(verbose_file_name);