[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
.yy -> .cc & .hh
From: |
Akim Demaille |
Subject: |
.yy -> .cc & .hh |
Date: |
18 Jul 2001 12:17:07 +0200 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Academic Rigor) |
Thanks for your proposal, but
1. I'd prefer to have something which is not based on a table, but
just on something tr-like. For instance, you don't have .yxx in
your table.
Really, the algorithm is only t/yY/cC/ for .c, and likewise with h.
I guess it will also help getting rid of the atrocious #if MSDOS
you seem to need :)
2. The documentation and NEWS are not updated.
I'm waiting for an updated submission, thanks!
+2001-07-08 Marc Autret <address@hidden>
+
+ * src/system.h (EXT_GUARD_C, EXT_STYPE_H): Removed .c and .h.
+ * src/files.c: Support output file extension computing.
+ (extension_index): New static variable.
+ (struct extensions_table_s): New.
+ (extensions_table): New global table.
+ (find_ext_index): New function, sets extension_index.
+ (compute_base_names): Update.
+ (output_files): Update.
diff -u -r --exclude=Makefile* --exclude=config* --exclude=*.info* --exclude=po
bison/src/files.c bison-1.29/src/files.c
--- bison/src/files.c Thu Jan 18 14:47:08 2001
+++ bison-1.29/src/files.c Sun Jul 8 14:48:10 2001
@@ -45,6 +45,9 @@
static char *base_name;
static char *short_base_name;
+/* keep the extension index in `extensions_table'. */
+static int extension_index = 0;
+
/*--------------------------.
| Is SUFFIX ending STRING? |
@@ -160,6 +163,43 @@
| Compute BASE_NAME and SHORT_BASE_NAME. |
`----------------------------------------*/
+/* this table contains an exhaustive list of the extensions found
+ on C or C++ source files. */
+struct extensions_table_s
+{
+ char *yext; /* grammar file extension */
+ char *srcext; /* c/source file extension */
+ char *header; /* header file extension */
+};
+
+static const
+struct extensions_table_s extensions_table[] =
+{
+ {".y", ".c", ".h"},
+ {".yy", ".cc", ".hh"},
+ {".ypp", ".cpp", ".hpp"},
+#ifndef MSDOS
+ {".Y", ".C", ".H"}, /* not supported because of case sensitivity... */
+#endif /* !MSDOS */
+ {".y++", ".c++", ".h++"},
+ {0, 0, 0}
+};
+
+/* returns the index of the corresponding extension found in
+ extensions_table */
+static int
+find_ext_index(const char *filename)
+{
+ int lindex;
+
+ for (lindex = 0; extensions_table[lindex].srcext; lindex++)
+ if (strsuffix(filename, extensions_table[lindex].srcext)
+ || strsuffix(filename, extensions_table[lindex].yext))
+ break;
+ extension_index = (extensions_table[lindex].srcext ? lindex : 0);
+ return extensions_table[lindex].srcext != NULL;
+}
+
/* FIXME: Should use xstrndup. */
static void
@@ -183,8 +223,10 @@
#endif /* MSDOS */
/* BASE_LENGTH includes ".tab" but not ".c". */
base_length = strlen (spec_outfile);
- if (strsuffix (spec_outfile, ".c"))
- base_length -= 2;
+
+ if (find_ext_index(spec_outfile))
+ base_length -= strlen(extensions_table[extension_index].srcext);
+
base_name = strndup (spec_outfile, base_length);
/* SHORT_BASE_LENGTH includes neither ".tab" nor ".c". */
short_base_length = base_length;
@@ -224,8 +266,10 @@
/* BASE_LENGTH gets length of BASE_NAME, sans ".y" suffix if any. */
base_length = strlen (name_base);
- if (strsuffix (name_base, ".y"))
- base_length -= 2;
+
+ if (find_ext_index(name_base))
+ base_length -= strlen(extensions_table[extension_index].yext);
+
short_base_length = base_length;
short_base_name = strndup (name_base, short_base_length);
@@ -268,18 +312,26 @@
xfclose (finput);
compute_base_names ();
+
attrsfile = stringappend (short_base_name, EXT_STYPE_H);
-
+#ifndef MSDOS
+ stringappend (attrsfile, extensions_table[extension_index].header);
+#endif /* not MSDOS */
+
/* Output the main file. */
if (spec_outfile)
obstack_save (&table_obstack, spec_outfile);
else
- obstack_save (&table_obstack, stringappend (base_name, ".c"));
+ obstack_save (&table_obstack,
+ stringappend (base_name,
+ extensions_table[extension_index].srcext));
/* Output the header file if wanted. */
if (defines_flag)
- obstack_save (&defines_obstack, stringappend (base_name, ".h"));
-
+ obstack_save (&defines_obstack,
+ stringappend (base_name,
+ extensions_table[extension_index].header));
+
/* If we output only the table, dump the actions in ACTFILE. */
if (no_parser_flag)
obstack_save (&action_obstack, stringappend (short_base_name, ".act"));
@@ -288,11 +340,17 @@
into its own file, ATTTRSFILE. */
if (semantic_parser)
{
+ char *temp_name;
+
obstack_save (&attrs_obstack, attrsfile);
- obstack_save (&guard_obstack,
- stringappend (short_base_name, EXT_GUARD_C));
+ temp_name = stringappend (short_base_name, EXT_GUARD_C);
+#ifndef MSDOS
+ temp_name = stringappend (temp_name,
+ extensions_table[extension_index].srcext);
+#endif /* not MSDOS */
+ obstack_save (&guard_obstack, temp_name);
}
-
+
if (verbose_flag)
/* We used to use just .out if spec_name_prefix (-p) was used, but
that conflicts with Posix. */
diff -u -r --exclude=Makefile* --exclude=config* --exclude=*.info* --exclude=po
bison/src/system.h bison-1.29/src/system.h
--- bison/src/system.h Wed Dec 20 17:21:14 2000
+++ bison-1.29/src/system.h Sun Jul 8 14:22:42 2001
@@ -209,8 +209,8 @@
/* VMS. */
# define EXT_TAB "_tab"
# define EXT_OUTPUT ".output"
-# define EXT_STYPE_H "_stype.h"
-# define EXT_GUARD_C "_guard.c"
+# define EXT_STYPE_H "_stype"
+# define EXT_GUARD_C "_guard"
#else /* ! VMS */
# ifdef MSDOS
/* MS DOS. */
@@ -222,8 +222,8 @@
/* Standard. */
# define EXT_TAB ".tab"
# define EXT_OUTPUT ".output"
-# define EXT_STYPE_H ".stype.h"
-# define EXT_GUARD_C ".guard.c"
+# define EXT_STYPE_H ".stype"
+# define EXT_GUARD_C ".guard"
# endif /* ! MSDOS */
#endif /* ! VMS */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- .yy -> .cc & .hh,
Akim Demaille <=