X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/27110317b8a2d2a4008e41be26e2f0c76416cbc8..b99357cde6568644e1b562965cf9fb3ba65af3a6:/src/files.c diff --git a/src/files.c b/src/files.c index 235deb03..eefa188d 100644 --- a/src/files.c +++ b/src/files.c @@ -27,20 +27,20 @@ #include "complain.h" FILE *finput = NULL; -FILE *foutput = NULL; -FILE *fguard = NULL; struct obstack action_obstack; struct obstack attrs_obstack; struct obstack table_obstack; struct obstack defines_obstack; +struct obstack guard_obstack; +struct obstack output_obstack; -/* File name specified with -o for the output file, or 0 if no -o. */ -char *spec_outfile; +char *spec_outfile; /* for -o. */ +char *spec_file_prefix; /* for -b. */ +char *spec_name_prefix; /* for -p. */ char *infile; char *attrsfile; -char *guardfile; static char *base_name; static char *short_base_name; @@ -185,11 +185,11 @@ compute_base_names (void) base_length = strlen (spec_outfile); if (strsuffix (spec_outfile, ".c")) base_length -= 2; + base_name = strndup (spec_outfile, base_length); /* SHORT_BASE_LENGTH includes neither ".tab" nor ".c". */ short_base_length = base_length; - if (strsuffix (spec_outfile, ".tab") || strsuffix (spec_outfile, "_tab")) + if (strsuffix (base_name, ".tab") || strsuffix (base_name, "_tab")) short_base_length -= 4; - base_name = strndup (spec_outfile, base_length); short_base_name = strndup (spec_outfile, short_base_length); return; @@ -245,23 +245,15 @@ compute_base_names (void) void open_files (void) { - compute_base_names (); - finput = xfopen (infile, "r"); - if (verbose_flag) - /* We used to use just .out if spec_name_prefix (-p) was used, but - that conflicts with Posix. */ - foutput = xfopen (stringappend (base_name, EXT_OUTPUT), "w"); - - attrsfile = stringappend (short_base_name, EXT_STYPE_H); - guardfile = stringappend (short_base_name, EXT_GUARD_C); - /* Initialize the obstacks. */ obstack_init (&action_obstack); obstack_init (&attrs_obstack); obstack_init (&table_obstack); obstack_init (&defines_obstack); + obstack_init (&guard_obstack); + obstack_init (&output_obstack); } @@ -273,9 +265,10 @@ open_files (void) void output_files (void) { - xfclose (fguard); xfclose (finput); - xfclose (foutput); + + compute_base_names (); + attrsfile = stringappend (short_base_name, EXT_STYPE_H); /* Output the main file. */ if (spec_outfile) @@ -294,5 +287,14 @@ output_files (void) /* If we produced a semantic parser ATTRS_OBSTACK must be dumped into its own file, ATTTRSFILE. */ if (semantic_parser) - obstack_save (&attrs_obstack, attrsfile); + { + obstack_save (&attrs_obstack, attrsfile); + obstack_save (&guard_obstack, + stringappend (short_base_name, EXT_GUARD_C)); + } + + if (verbose_flag) + /* We used to use just .out if spec_name_prefix (-p) was used, but + that conflicts with Posix. */ + obstack_save (&output_obstack, stringappend (short_base_name, EXT_OUTPUT)); }