X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/ae4048011562c250d2f3c96687422d99a38745ce..32e1e0a4865d64946a5497aff057d7be28c1cc3d:/src/files.c?ds=inline diff --git a/src/files.c b/src/files.c index 5f94bd00..1252aab0 100644 --- a/src/files.c +++ b/src/files.c @@ -1,5 +1,6 @@ /* Open and close files for bison, - Copyright 1984, 1986, 1989, 1992, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002 + Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -31,9 +32,8 @@ const char *base_name PARAMS ((char const *name)); FILE *finput = NULL; -struct obstack action_obstack; -struct obstack attrs_obstack; -struct obstack output_obstack; +struct obstack pre_prologue_obstack; +struct obstack post_prologue_obstack; /* Initializing some values below (such SPEC_NAME_PREFIX to `yy') is tempting, but don't do that: for the time being our handling of the @@ -51,18 +51,20 @@ char *spec_defines_file = NULL; /* for --defines. */ char *parser_file_name = NULL; char *infile = NULL; -char *attrsfile = 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). */ const char *header_extension = NULL; - -/* Should we insert '.tab' in yacc-compatible parsers? */ -int tab_extension = 0; /*--------------------------. @@ -188,6 +190,7 @@ skeleton_find (const char *envvar, const char *skeleton_name) const char *res = getenv (envvar); #if defined (MSDOS) || defined (_WIN32) + const char *cp = getenv ("INIT"); if (!res) { /* Skeleton file name without path */ @@ -200,7 +203,6 @@ skeleton_find (const char *envvar, const char *skeleton_name) ++skel_name; /* File doesn't exist in current directory; try in INIT directory. */ - const char *cp = getenv ("INIT"); if (cp) { res = XMALLOC (char, strlen (cp) + strlen (skel_name) + 2); @@ -253,27 +255,6 @@ tr (const char *in, char from, char to) return (temp); } -/* Gets the extension index in FILENAME. Returns 0 if fails to - find an extension. */ -static int -get_extension_index (const char *filename) -{ - int len; - - len = strlen (filename); - - if (filename[len-- - 1] == '.') - return (0); - - while ((len > 0) && (filename[len - 1] != '.')) - if (filename[len - 1] == '/') - return (0); - else - len--; - - return (len - 1); -} - /* Computes extensions from the grammar file extension. */ static void compute_exts_from_gf (const char *ext) @@ -338,7 +319,7 @@ filename_split (const char *filename, /* If there is an exentension, check if there is a `.tab' part right before. */ if (*ext - && (*ext - *base) > strlen (".tab") + && (*ext - *base) > (int) strlen (".tab") && (!strncmp (*ext - strlen (".tab"), ".tab", strlen (".tab")) || !strncmp (*ext - strlen ("_tab"), "_tab", strlen ("_tab")))) *tab = *ext - strlen (".tab"); @@ -351,9 +332,6 @@ static void compute_base_names (void) { const char *base, *tab, *ext; - size_t base_length; - size_t short_base_length; - size_t ext_index; /* If --output=foo.c was specified (SPEC_OUTFILE == foo.c), BASE_NAME and SHORT_BASE_NAME are `foo'. @@ -365,21 +343,22 @@ compute_base_names (void) files, remove the ".c" or ".tab.c" suffix. */ if (spec_outfile) { - const char *cp; filename_split (spec_outfile, &base, &tab, &ext); /* The full base name goes up the EXT, excluding it. */ full_base_name = xstrndup (spec_outfile, (strlen (spec_outfile) - (ext ? strlen (ext) : 0))); + /* The short base name goes up to TAB, excluding it. */ short_base_name = xstrndup (spec_outfile, (strlen (spec_outfile) - (tab ? strlen (tab) : (ext ? strlen (ext) : 0)))); - /* Do we have a tab part? */ - tab_extension = !!tab; + if (tab) + output_infix = xstrndup (tab, + (strlen (tab) - (ext ? strlen (ext) : 0))); if (ext) compute_exts_from_src (ext); @@ -405,15 +384,16 @@ compute_base_names (void) else { /* Otherwise, the short base name is computed from the input - grammar: `foo.yy' => `foo'. */ + grammar: `foo/bar.yy' => `bar'. */ filename_split (infile, &base, &tab, &ext); short_base_name = - xstrndup (infile, - (strlen (infile) - (ext ? strlen (ext) : 0))); + xstrndup (base, + (strlen (base) - (ext ? strlen (ext) : 0))); } /* In these cases, always append `.tab'. */ - tab_extension = 1; + output_infix = xstrdup (EXT_TAB); + full_base_name = XMALLOC (char, strlen (short_base_name) + strlen (EXT_TAB) + 1); @@ -421,7 +401,7 @@ compute_base_names (void) /* Computes the extensions from the grammar file name. */ filename_split (infile, &base, &tab, &ext); - if (ext) + if (ext && !yacc_flag) compute_exts_from_gf (ext); } } @@ -435,15 +415,15 @@ compute_output_file_names (void) { compute_base_names (); - parser_file_name = - spec_outfile ? spec_outfile : stringappend (full_base_name, src_extension); - /* If not yet done. */ if (!src_extension) src_extension = ".c"; if (!header_extension) header_extension = ".h"; + parser_file_name = + spec_outfile ? spec_outfile : stringappend (full_base_name, src_extension); + /* It the defines filename if not given, we create it. */ if (!spec_defines_file) spec_defines_file = stringappend (full_base_name, header_extension); @@ -453,6 +433,4 @@ compute_output_file_names (void) spec_graph_file = stringappend (short_base_name, ".vcg"); spec_verbose_file = stringappend (short_base_name, EXT_OUTPUT); - - attrsfile = stringappend (short_base_name, EXT_STYPE_H); }