(open_files): Initialize it.
(output_files): Dump it...
* src/files.h: Export it.
* src/reader.c (copy_guard): Use it.
+2000-12-20 Akim Demaille <akim@epita.fr>
+
+ * src/files.c (guard_obstack): New.
+ (open_files): Initialize it.
+ (output_files): Dump it...
+ * src/files.h: Export it.
+ * src/reader.c (copy_guard): Use it.
+
2000-12-19 Akim Demaille <akim@epita.fr>
* src/files.c (outfile, defsfile, actfile): Removed as global
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;
-/* 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;
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);
}
void
output_files (void)
{
- xfclose (fguard);
xfclose (finput);
xfclose (foutput);
/* 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));
+ }
}
/* File name specified with -o for the output file, or 0 if no -o. */
extern char *spec_outfile;
-/* For -a, from getargs.c */
+/* For -a. */
extern char *spec_name_prefix;
/* File name pfx specified with -b, or 0 if no -b. */
/* Optionally output messages describing the actions taken. */
extern FILE *foutput;
-/* If semantic parser, output yyguard, containing all the guard code. */
-extern FILE *fguard;
-
/* Output all the action code; precise form depends on which parser. */
extern struct obstack action_obstack;
-/* If semantic parser, output a .h file that defines YYSTYPE */
-extern struct obstack attrs_obstack;
-
/* Output the tables and the parser and also contains all the %{
... %} definitions. */
extern struct obstack table_obstack;
/* optionally output #define's for token numbers. */
extern struct obstack defines_obstack;
+/* If semantic parser, output a .h file that defines YYSTYPE... */
+extern struct obstack attrs_obstack;
+
+/* ... and output yyguard, containing all the guard code. */
+extern struct obstack guard_obstack;
+
extern char *infile;
extern char *attrsfile;
-extern char *guardfile;
void open_files PARAMS((void));
#include "files.h"
#include "getargs.h"
-char *spec_file_prefix; /* for -b. */
-char *spec_name_prefix; /* for -p. */
-
int debug_flag = 0;
int defines_flag = 0;
int locations_flag = 0;
char *attrsfile_quoted = quotearg_style (c_quoting_style, attrsfile);
if (semantic_parser)
- fprintf (fguard, GUARDSTR, attrsfile_quoted);
+ obstack_fgrow1 (&guard_obstack, GUARDSTR, attrsfile_quoted);
if (no_parser_flag)
return;
else
obstack_grow_string (&action_obstack, ACTSTR_SIMPLE);
-/* if (semantic_parser) JF moved this below
- fprintf(ftable, "#include \"%s\"\n", attrsfile);
- fprintf(ftable, "#include <stdio.h>\n\n");
-*/
-
/* Rename certain symbols if -p was specified. */
if (spec_name_prefix)
{
output_trailers (void)
{
if (semantic_parser)
- fprintf (fguard, "\n }\n}\n");
+ obstack_grow_string (&guard_obstack, "\n }\n}\n");
obstack_1grow (&action_obstack, '\n');
break;
case SEMANTIC_PARSER:
- if (!semantic_parser)
- fguard = xfopen (guardfile, "w");
semantic_parser = 1;
break;
if (semantic_parser)
stack_offset = 0;
- fprintf (fguard, "\ncase %d:\n", nrules);
+ obstack_fgrow1 (&guard_obstack, "\ncase %d:\n", nrules);
if (!no_lines_flag)
- fprintf (fguard, "#line %d %s\n",
- lineno, quotearg_style (c_quoting_style, infile));
- putc ('{', fguard);
+ obstack_fgrow2 (&guard_obstack, "#line %d %s\n",
+ lineno, quotearg_style (c_quoting_style, infile));
+ obstack_1grow (&guard_obstack, '{');
count = 0;
c = getc (finput);
switch (c)
{
case '\n':
- putc (c, fguard);
+ obstack_1grow (&guard_obstack, c);
lineno++;
break;
case '{':
- putc (c, fguard);
+ obstack_1grow (&guard_obstack, c);
brace_flag = 1;
count++;
break;
case '}':
- putc (c, fguard);
+ obstack_1grow (&guard_obstack, c);
if (count > 0)
count--;
else
case '\'':
case '"':
- copy_string (finput, fguard, 0, c);
+ copy_string (finput, 0, &guard_obstack, c);
break;
case '/':
- copy_comment (finput, fguard, 0);
+ copy_comment (finput, 0, &guard_obstack);
break;
case '$':
- copy_dollar (finput, fguard, 0, rule, stack_offset);
+ copy_dollar (finput, 0, &guard_obstack, rule, stack_offset);
break;
case '@':
- copy_at (finput, fguard, 0, stack_offset);
+ copy_at (finput, 0, &guard_obstack, stack_offset);
break;
case EOF:
fatal ("%s", _("unterminated %guard clause"));
default:
- putc (c, fguard);
+ obstack_1grow (&guard_obstack, c);
}
if (c != '}' || count != 0)
c = skip_white_space ();
- fprintf (fguard, ";\n break;}");
+ obstack_grow_string (&guard_obstack, ";\n break;}");
if (c == '{')
copy_action (rule, stack_offset);
else if (c == '=')
\f
/*-------------------------------------------------------------------.
| Read in the grammar specification and record it in the format |
-| described in gram.h. All guards are copied into the FGUARD file |
+| described in gram.h. All guards are copied into the GUARD_OBSTACK |
| and all actions into ACTION_OBSTACK, in each case forming the body |
| of a C function (YYGUARD or YYACTION) which contains a switch |
| statement to decide which guard or action to execute. |