From: Akim Demaille Date: Tue, 19 Dec 2000 13:05:52 +0000 (+0000) Subject: Let the handling of the skeleton files be local to the procedures X-Git-Tag: BISON-1_28b~53 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/ff61dabdbacfc6ea2737395756ea75e61ad1aa5a Let the handling of the skeleton files be local to the procedures that use it. * src/files.c (xfopen, xfclose, skeleton_find, guardfile): No longer static. (fparser, open_extra_files): Remove. (open_files, output_files): Don't take care of fparser. * src/files.h: Adjust. * src/output.c (output_parser): Open and close the file to the skeleton. * src/reader.c (read_declarations): When %semantic_parser, open fguard. --- diff --git a/ChangeLog b/ChangeLog index a9541648..c19e1b94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2000-12-19 Akim Demaille + + Let the handling of the skeleton files be local to the procedures + that use it. + + * src/files.c (xfopen, xfclose, skeleton_find, guardfile): No + longer static. + (fparser, open_extra_files): Remove. + (open_files, output_files): Don't take care of fparser. + * src/files.h: Adjust. + * src/output.c (output_parser): Open and close the file to the + skeleton. + * src/reader.c (read_declarations): When %semantic_parser, open + fguard. + 2000-12-19 Akim Demaille * src/file.h (BISON_SIMPLE, BISON_HAIRY): Move from here... diff --git a/src/files.c b/src/files.c index ccb47182..f2ac8582 100644 --- a/src/files.c +++ b/src/files.c @@ -29,7 +29,6 @@ FILE *finput = NULL; FILE *foutput = NULL; FILE *fguard = NULL; -FILE *fparser = NULL; struct obstack action_obstack; struct obstack attrs_obstack; @@ -41,11 +40,11 @@ char *spec_outfile; char *infile; char *attrsfile; +char *guardfile; static char *outfile; static char *defsfile; static char *tabfile; -static char *guardfile; static char *actfile; /*-----------------------------------------------------------------. @@ -85,7 +84,7 @@ stringappend (const char *string1, int end1, const char *string2) | if fails. | `-----------------------------------------------------------------*/ -static FILE * +FILE * xfopen (const char *name, const char *mode) { FILE *ptr; @@ -101,7 +100,7 @@ xfopen (const char *name, const char *mode) | Try to close file PTR, and print an error message if fails. | `-------------------------------------------------------------*/ -static int +int xfclose (FILE *ptr) { int result; @@ -130,7 +129,12 @@ obstack_save (struct obstack *obs, const char *filename) } -static const char * +/*------------------------------------------------------------------. +| Return the path to the skeleton which locaction might be given in | +| ENVVAR, otherwise return SKELETON. | +`------------------------------------------------------------------*/ + +const char * skeleton_find (const char *envvar, const char *skeleton) { const char *res = getenv (envvar); @@ -221,9 +225,6 @@ open_files (void) finput = xfopen (infile, "r"); - if (!no_parser_flag) - fparser = xfopen (skeleton_find ("BISON_SIMPLE", BISON_SIMPLE), "r"); - if (verbose_flag) { /* We used to use just .out if spec_name_prefix (-p) was used, @@ -261,22 +262,6 @@ open_files (void) -/*--------------------------------------------------------------------. -| Open the output files needed only for the semantic parser. This | -| is done when %semantic_parser is seen in the declarations section. | -`--------------------------------------------------------------------*/ - -void -open_extra_files (void) -{ - xfclose (fparser); - - if (!no_parser_flag) - fparser = xfopen (skeleton_find ("BISON_HAIRY", BISON_HAIRY), "r"); - fguard = xfopen (guardfile, "w"); -} - - /*-----------------------------------------------------. | Close the open files, produce all the output files. | `-----------------------------------------------------*/ @@ -286,7 +271,6 @@ output_files (void) { xfclose (fguard); xfclose (finput); - xfclose (fparser); xfclose (foutput); /* Output the main file. */ diff --git a/src/files.h b/src/files.h index 33bed545..adf734b4 100644 --- a/src/files.h +++ b/src/files.h @@ -43,9 +43,6 @@ extern FILE *foutput; /* If semantic parser, output yyguard, containing all the guard code. */ extern FILE *fguard; -/* Read the parser to copy into TABLE_OBSTACK. */ -extern FILE *fparser; - /* Output all the action code; precise form depends on which parser. */ extern struct obstack action_obstack; @@ -62,16 +59,15 @@ extern struct obstack defines_obstack; extern char *infile; -extern int lineno; -extern char *outfile; -extern char *defsfile; -extern char *tabfile; extern char *attrsfile; extern char *guardfile; -extern char *actfile; void open_files PARAMS((void)); -void open_extra_files PARAMS((void)); void output_files PARAMS((void)); + +FILE *xfopen PARAMS ((const char *name, const char *mode)); +int xfclose PARAMS ((FILE *ptr)); + +const char *skeleton_find PARAMS ((const char *envvar, const char *skeleton)); #endif /* !FILES_H_ */ diff --git a/src/output.c b/src/output.c index 27fcae4f..cf01416a 100644 --- a/src/output.c +++ b/src/output.c @@ -1153,54 +1153,47 @@ output_actions (void) output_check (); } -/* copy the parser code into the ftable file at the end. */ +/*------------------------------------------. +| Copy the parser code into TABLE_OBSTACK. | +`------------------------------------------*/ static void output_parser (void) { int c; static int number_of_dollar_signs = 0; -#ifdef DONTDEF - FILE *fpars; -#else -#define fpars fparser -#endif + FILE *fskel; if (pure_parser) obstack_grow_literal_string (&table_obstack, "#define YYPURE 1\n\n"); -#ifdef DONTDEF - /* JF no longer needed 'cuz open_extra_files changes the currently - open parser from bison.simple to bison.hairy */ + /* Loop over lines in the standard parser file. */ if (semantic_parser) - fpars = fparser; + fskel = xfopen (skeleton_find ("BISON_HAIRY", BISON_HAIRY), "r"); else - fpars = fparser1; -#endif - - /* Loop over lines in the standard parser file. */ + fskel = xfopen (skeleton_find ("BISON_SIMPLE", BISON_SIMPLE), "r"); while (1) { int write_line = 1; - c = getc (fpars); + c = getc (fskel); /* See if the line starts with `#line. If so, set write_line to 0. */ if (no_lines_flag) if (c == '#') { - c = getc (fpars); + c = getc (fskel); if (c == 'l') { - c = getc (fpars); + c = getc (fskel); if (c == 'i') { - c = getc (fpars); + c = getc (fskel); if (c == 'n') { - c = getc (fpars); + c = getc (fskel); if (c == 'e') write_line = 0; else @@ -1217,7 +1210,7 @@ output_parser (void) } /* now write out the line... */ - for (; c != '\n' && c != EOF; c = getc (fpars)) + for (; c != '\n' && c != EOF; c = getc (fskel)) if (write_line) { /* `$' in the parser file indicates where to put the @@ -1243,6 +1236,7 @@ output_parser (void) obstack_1grow (&table_obstack, c); } assert (number_of_dollar_signs == 1); + xfclose (fskel); } static void diff --git a/src/reader.c b/src/reader.c index e74ff323..cc24af65 100644 --- a/src/reader.c +++ b/src/reader.c @@ -1002,11 +1002,9 @@ read_declarations (void) break; case SEMANTIC_PARSER: - if (semantic_parser == 0) - { - semantic_parser = 1; - open_extra_files (); - } + if (!semantic_parser) + fguard = xfopen (guardfile, "w"); + semantic_parser = 1; break; case PURE_PARSER: