* Copyright (c) 1989 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)main.c 5.2 (Berkeley) %G%";
char *temp_form
= "yacc.XXXXXXX";
char *input_file_name
= "";
FILE *action_file
; /* a temp file, used to save actions associated */
/* with rules until the parser is written */
FILE *defines_file
; /* y.tab.h */
FILE *input_file
; /* the input file */
FILE *output_file
; /* y.tab.c */
FILE *text_file
; /* a temp file, used to save text until all */
/* symbols have been defined */
FILE *union_file
; /* a temp file, used to save the union */
/* definition until all symbol have been */
FILE *verbose_file
; /* y.output */
if (action_file
) { fclose(action_file
); unlink(action_file_name
); }
if (text_file
) { fclose(text_file
); unlink(text_file_name
); }
if (union_file
) { fclose(union_file
); unlink(union_file_name
); }
if (signal(SIGINT
, SIG_IGN
) != SIG_IGN
)
if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
fprintf(stderr
, "usage: %s [-dltv] [-b prefix] filename\n", myname
);
if (argc
> 0) myname
= argv
[0];
for (i
= 1; i
< argc
; ++i
)
if (i
+ 1 < argc
) usage();
if (*++s
|| ++i
>= argc
) usage();
if (i
+ 1 != argc
) usage();
input_file_name
= argv
[i
];
p
= calloc((unsigned) 1, n
);
tmpdir
= getenv("TMPDIR");
if (tmpdir
== 0) tmpdir
= "/tmp";
if (len
&& tmpdir
[len
-1] != '/')
action_file_name
= MALLOC(i
);
if (action_file_name
== 0) no_space();
text_file_name
= MALLOC(i
);
if (text_file_name
== 0) no_space();
union_file_name
= MALLOC(i
);
if (union_file_name
== 0) no_space();
strcpy(action_file_name
, tmpdir
);
strcpy(text_file_name
, tmpdir
);
strcpy(union_file_name
, tmpdir
);
if (len
&& tmpdir
[len
- 1] != '/')
action_file_name
[len
] = '/';
text_file_name
[len
] = '/';
union_file_name
[len
] = '/';
strcpy(action_file_name
+ len
, temp_form
);
strcpy(text_file_name
+ len
, temp_form
);
strcpy(union_file_name
+ len
, temp_form
);
action_file_name
[len
+ 5] = 'a';
text_file_name
[len
+ 5] = 't';
union_file_name
[len
+ 5] = 'u';
mktemp(action_file_name
);
/* the number 7 below is the size of ".tab.h"; sizeof is not used */
/* because of a C compiler that thinks sizeof(".tab.h") == 6 */
defines_file_name
= MALLOC(len
+ 7);
if (defines_file_name
== 0) no_space();
strcpy(defines_file_name
, prefix
);
strcpy(defines_file_name
+ len
, DEFINES_SUFFIX
);
output_file_name
= MALLOC(len
+ 7);
if (output_file_name
== 0) no_space();
strcpy(output_file_name
, prefix
);
strcpy(output_file_name
+ len
, OUTPUT_SUFFIX
);
verbose_file_name
= MALLOC(len
+ 8);
if (verbose_file_name
== 0) no_space();
strcpy(verbose_file_name
, prefix
);
strcpy(verbose_file_name
+ len
, VERBOSE_SUFFIX
);
input_file
= fopen(input_file_name
, "r");
if (input_file
== 0) open_error(input_file_name
);
action_file
= fopen(action_file_name
, "w");
if (action_file
== 0) open_error(action_file_name
);
text_file
= fopen(text_file_name
, "w");
if (text_file
== 0) open_error(text_file_name
);
verbose_file
= fopen(verbose_file_name
, "w");
if (verbose_file
== 0) open_error(verbose_file_name
);
defines_file
= fopen(defines_file_name
, "w");
if (defines_file
== 0) open_error(defines_file_name
);
union_file
= fopen(union_file_name
, "w");
if (union_file
== 0) open_error(union_file_name
);
output_file
= fopen(output_file_name
, "w");
if (output_file
== 0) open_error(output_file_name
);