X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/b906441c9568615be3ddce717a6e365b2e368af3..95612cfa608188fc323ed3f8560cc6aea953ff32:/src/files.c diff --git a/src/files.c b/src/files.c index c4c223d3..02cf0ddc 100644 --- a/src/files.c +++ b/src/files.c @@ -28,7 +28,7 @@ #include "complain.h" /* From basename.c. Almost a lie, as it returns a char *. */ -const char *base_name PARAMS ((char const *name)); +const char *base_name (char const *name); FILE *finput = NULL; @@ -50,17 +50,14 @@ char *spec_graph_file = NULL; /* for -g. */ char *spec_defines_file = NULL; /* for --defines. */ char *parser_file_name = NULL; -char *infile = NULL; +struniq_t grammar_file = NULL; +struniq_t current_file = NULL; static char *full_base_name = NULL; /* Prefix used to generate output file names. */ char *short_base_name = NULL; -/* Infix used to generate output file names (i.e., `.tab', or `_tab', - or `'). */ -char *output_infix = NULL; - /* C source file extension (the parser source). */ const char *src_extension = NULL; /* Header file extension (if option ``-d'' is specified). */ @@ -111,7 +108,7 @@ xfopen (const char *name, const char *mode) ptr = fopen (name, mode); if (!ptr) - error (2, errno, _("cannot open file `%s'"), name); + error (EXIT_FAILURE, errno, _("cannot open file `%s'"), name); return ptr; } @@ -120,19 +117,17 @@ xfopen (const char *name, const char *mode) | Try to close file PTR, and print an error message if fails. | `-------------------------------------------------------------*/ -int +void xfclose (FILE *ptr) { - int result; - if (ptr == NULL) - return 0; + return; - result = fclose (ptr); - if (result == EOF) - error (2, errno, _("cannot close file")); + if (ferror (ptr)) + error (EXIT_FAILURE, 0, _("I/O error")); - return result; + if (fclose (ptr) != 0) + error (EXIT_FAILURE, errno, _("cannot close file")); } @@ -260,10 +255,6 @@ compute_base_names (void) (strlen (spec_outfile) - (tab ? strlen (tab) : (ext ? strlen (ext) : 0)))); - if (tab) - output_infix = xstrndup (tab, - (strlen (tab) - (ext ? strlen (ext) : 0))); - if (ext) compute_exts_from_src (ext); } @@ -289,22 +280,19 @@ compute_base_names (void) { /* Otherwise, the short base name is computed from the input grammar: `foo/bar.yy' => `bar'. */ - filename_split (infile, &base, &tab, &ext); + filename_split (grammar_file, &base, &tab, &ext); short_base_name = xstrndup (base, (strlen (base) - (ext ? strlen (ext) : 0))); } - /* In these cases, always append `.tab'. */ - output_infix = xstrdup (EXT_TAB); - full_base_name = XMALLOC (char, strlen (short_base_name) + strlen (EXT_TAB) + 1); stpcpy (stpcpy (full_base_name, short_base_name), EXT_TAB); /* Computes the extensions from the grammar file name. */ - filename_split (infile, &base, &tab, &ext); + filename_split (grammar_file, &base, &tab, &ext); if (ext && !yacc_flag) compute_exts_from_gf (ext); }