12 char *file_prefix
= "y";
13 char *myname
= "yacc";
14 char *temp_form
= "yacc.XXXXXXX";
19 char *action_file_name
;
21 char *defines_file_name
;
22 char *input_file_name
= "";
23 char *output_file_name
;
25 char *union_file_name
;
26 char *verbose_file_name
;
28 FILE *action_file
; /* a temp file, used to save actions associated */
29 /* with rules until the parser is written */
30 FILE *code_file
; /* y.code.c (used when the -r option is specified) */
31 FILE *defines_file
; /* y.tab.h */
32 FILE *input_file
; /* the input file */
33 FILE *output_file
; /* y.tab.c */
34 FILE *text_file
; /* a temp file, used to save text until all */
35 /* symbols have been defined */
36 FILE *union_file
; /* a temp file, used to save the union */
37 /* definition until all symbol have been */
39 FILE *verbose_file
; /* y.output */
61 extern char *mktemp();
62 extern char *getenv();
68 if (action_file
) { fclose(action_file
); unlink(action_file_name
); }
69 if (text_file
) { fclose(text_file
); unlink(text_file_name
); }
70 if (union_file
) { fclose(union_file
); unlink(union_file_name
); }
86 if (signal(SIGINT
, SIG_IGN
) != SIG_IGN
)
87 signal(SIGINT
, onintr
);
90 if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
91 signal(SIGTERM
, onintr
);
94 if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
95 signal(SIGHUP
, onintr
);
102 fprintf(stderr
, "usage: %s [-dlrtv] [-b file_prefix] [-p symbol_prefix] filename\n", myname
);
114 if (argc
> 0) myname
= argv
[0];
115 for (i
= 1; i
< argc
; ++i
)
118 if (*s
!= '-') break;
123 if (i
+ 1 < argc
) usage();
128 goto no_more_options
;
134 file_prefix
= argv
[i
];
151 symbol_prefix
= argv
[i
];
207 if (i
+ 1 != argc
) usage();
208 input_file_name
= argv
[i
];
233 tmpdir
= getenv("TMPDIR");
234 if (tmpdir
== 0) tmpdir
= "/tmp";
236 len
= strlen(tmpdir
);
238 if (len
&& tmpdir
[len
-1] != '/')
241 action_file_name
= MALLOC(i
);
242 if (action_file_name
== 0) no_space();
243 text_file_name
= MALLOC(i
);
244 if (text_file_name
== 0) no_space();
245 union_file_name
= MALLOC(i
);
246 if (union_file_name
== 0) no_space();
248 strcpy(action_file_name
, tmpdir
);
249 strcpy(text_file_name
, tmpdir
);
250 strcpy(union_file_name
, tmpdir
);
252 if (len
&& tmpdir
[len
- 1] != '/')
254 action_file_name
[len
] = '/';
255 text_file_name
[len
] = '/';
256 union_file_name
[len
] = '/';
260 strcpy(action_file_name
+ len
, temp_form
);
261 strcpy(text_file_name
+ len
, temp_form
);
262 strcpy(union_file_name
+ len
, temp_form
);
264 action_file_name
[len
+ 5] = 'a';
265 text_file_name
[len
+ 5] = 't';
266 union_file_name
[len
+ 5] = 'u';
268 mktemp(action_file_name
);
269 mktemp(text_file_name
);
270 mktemp(union_file_name
);
272 len
= strlen(file_prefix
);
274 output_file_name
= MALLOC(len
+ 7);
275 if (output_file_name
== 0)
277 strcpy(output_file_name
, file_prefix
);
278 strcpy(output_file_name
+ len
, OUTPUT_SUFFIX
);
282 code_file_name
= MALLOC(len
+ 8);
283 if (code_file_name
== 0)
285 strcpy(code_file_name
, file_prefix
);
286 strcpy(code_file_name
+ len
, CODE_SUFFIX
);
289 code_file_name
= output_file_name
;
293 defines_file_name
= MALLOC(len
+ 7);
294 if (defines_file_name
== 0)
296 strcpy(defines_file_name
, file_prefix
);
297 strcpy(defines_file_name
+ len
, DEFINES_SUFFIX
);
302 verbose_file_name
= MALLOC(len
+ 8);
303 if (verbose_file_name
== 0)
305 strcpy(verbose_file_name
, file_prefix
);
306 strcpy(verbose_file_name
+ len
, VERBOSE_SUFFIX
);
317 input_file
= fopen(input_file_name
, "r");
319 open_error(input_file_name
);
322 action_file
= fopen(action_file_name
, "w");
323 if (action_file
== 0)
324 open_error(action_file_name
);
326 text_file
= fopen(text_file_name
, "w");
328 open_error(text_file_name
);
332 verbose_file
= fopen(verbose_file_name
, "w");
333 if (verbose_file
== 0)
334 open_error(verbose_file_name
);
339 defines_file
= fopen(defines_file_name
, "w");
340 if (defines_file
== 0)
341 open_error(defines_file_name
);
342 union_file
= fopen(union_file_name
, "w");
344 open_error(union_file_name
);
347 output_file
= fopen(output_file_name
, "w");
348 if (output_file
== 0)
349 open_error(output_file_name
);
353 code_file
= fopen(code_file_name
, "w");
355 open_error(code_file_name
);
358 code_file
= output_file
;