]> git.saurik.com Git - bison.git/blobdiff - src/files.c
* missing: Update from CVS Automake.
[bison.git] / src / files.c
index 2d289fee0a2a6265bf754e2fe0a5176b23225bdf..402025bfe0c00bddf7b3e962aa5992bfd3aa0744 100644 (file)
@@ -1,5 +1,5 @@
 /* Open and close files for bison,
-   Copyright 1984, 1986, 1989, 1992, 2000 Free Software Foundation, Inc.
+   Copyright 1984, 1986, 1989, 1992, 2000, 2001 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -34,6 +34,7 @@ struct obstack table_obstack;
 struct obstack defines_obstack;
 struct obstack guard_obstack;
 struct obstack output_obstack;
+struct obstack graph_obstack;
 
 char *spec_outfile = NULL;     /* for -o. */
 char *spec_file_prefix = NULL; /* for -b. */
@@ -46,9 +47,9 @@ static char *base_name = NULL;
 static char *short_base_name = NULL;
 
 /* C source file extension (the parser source). */
-static const char *src_extension = NULL;
+const char *src_extension = NULL;
 /* Header file extension (if option ``-d'' is specified). */
-static const char *header_extension = NULL;
+const char *header_extension = NULL;
 
 \f
 /*--------------------------.
@@ -209,16 +210,29 @@ get_extension_index(const char *filename)
 static void
 compute_exts_from_gf(const char *ext)
 {
-  src_extension = tr(ext, 'y', 'c');
-  src_extension = tr(src_extension, 'Y', 'C');
-  header_extension = tr(ext, 'y', 'h');
-  header_extension = tr(header_extension, 'Y', 'H');
+  /* Checks if SRC_EXTENSION is NULL. In the other case, %source_extension 
+     was specified in the grammar file.  */
+  if (src_extension == NULL)
+    {
+      src_extension = tr(ext, 'y', 'c');
+      src_extension = tr(src_extension, 'Y', 'C');
+    }
+  /* Checks if HEADER_EXTENSION is NULL. In the other case, 
+     %header_extension was specified in the grammar file.  */
+  if (header_extension == NULL)
+    {
+      header_extension = tr(ext, 'y', 'h');
+      header_extension = tr(header_extension, 'Y', 'H');
+    }
 }
 
 /* Computes extensions from the given c source file extension. */
 static void
 compute_exts_from_src(const char *ext)
 {
+  /* We use this function when the user specifies `-o' or `--output',
+     so the extenions must be computed unconditionally from the file name
+     given by this option.  */
   src_extension = xstrdup(ext);
   header_extension = tr(ext, 'c', 'h');
   header_extension = tr(header_extension, 'C', 'H');
@@ -233,10 +247,6 @@ compute_base_names (void)
   size_t short_base_length;
   size_t ext_index;
 
-  /* Set default extensions */
-  src_extension = ".c";
-  header_extension = ".h";
-
   /* If --output=foo.c was specified (SPEC_OUTFILE == foo.c),
      BASE_NAME and SHORT_BASE_NAME are `foo'.
 
@@ -257,11 +267,11 @@ compute_base_names (void)
       /* if the initial segment of extension contains 'c' or a 'C', I assume
         that it is a C or C++ source file */
       if (ext_index)
-       ext_index = (strspn(spec_outfile + ext_index + 1, "cC")) ? ext_index : 0;
+       ext_index = (strspn (spec_outfile + ext_index + 1, "cC")) ? ext_index : 0;
       if (ext_index)
        {
          base_length -= strlen (spec_outfile + ext_index);
-         compute_exts_from_src(spec_outfile + ext_index);
+         compute_exts_from_src (spec_outfile + ext_index);
        }
 
       base_name = strndup (spec_outfile, base_length);
@@ -288,6 +298,15 @@ compute_base_names (void)
                           strlen (short_base_name) + strlen (EXT_TAB) + 1);
       stpcpy (stpcpy (base_name, short_base_name), EXT_TAB);
 
+      /* Computes the extensions from the garmmar file name.  */
+      ext_index = get_extension_index (infile);
+      /* if the initial segment of extension contains a 'y' or a 'Y', I assume
+        that it is a yacc or bison grammar file */
+      if (ext_index)
+       ext_index = (strspn (infile + ext_index + 1, "yY")) ? ext_index : 0;
+      if (ext_index)
+       compute_exts_from_gf (infile + ext_index);
+      
       return;
     }
 
@@ -307,11 +326,11 @@ compute_base_names (void)
     /* if the initial segment of extension contains a 'y' or a 'Y', I assume
        that it is a yacc or bison grammar file */
     if (ext_index)
-      ext_index = (strspn(name_base + ext_index + 1, "yY")) ? ext_index : 0;
+      ext_index = (strspn (name_base + ext_index + 1, "yY")) ? ext_index : 0;
     if (ext_index)
       {
        base_length -= strlen (name_base + ext_index);
-       compute_exts_from_gf(name_base + ext_index);
+       compute_exts_from_gf (name_base + ext_index);
       }
 
     short_base_length = base_length;
@@ -342,6 +361,7 @@ open_files (void)
   obstack_init (&defines_obstack);
   obstack_init (&guard_obstack);
   obstack_init (&output_obstack);
+  obstack_init (&graph_obstack);
 }
 
 
@@ -357,6 +377,12 @@ output_files (void)
 
   compute_base_names ();
 
+  /* Set default extensions */
+  if (!src_extension)
+    src_extension = ".c";
+  if (!header_extension)
+    header_extension = ".h";
+
   attrsfile = stringappend (short_base_name, EXT_STYPE_H);
 #ifndef MSDOS
   stringappend (attrsfile, header_extension);
@@ -394,4 +420,7 @@ output_files (void)
     /* 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));
+
+  if (graph_flag)
+    obstack_save (&graph_obstack, stringappend (short_base_name, ".vcg"));
 }