+ /* 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');
+}
+
+/* FIXME: Should use xstrndup. */
+
+static void
+compute_base_names (void)
+{
+ 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'.
+
+ If --output=foo.tab.c was specified, BASE_NAME is `foo.tab' and
+ SHORT_BASE_NAME is `foo'.
+
+ The precise -o name will be used for FTABLE. For other output
+ files, remove the ".c" or ".tab.c" suffix. */
+ if (spec_outfile)
+ {
+#ifdef MSDOS
+ strlwr (spec_outfile);
+#endif /* MSDOS */
+ /* BASE_LENGTH includes ".tab" but not ".c". */
+ base_length = strlen (spec_outfile);
+
+ ext_index = get_extension_index (spec_outfile);
+ /* 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;
+ if (ext_index)
+ {
+ base_length -= strlen (spec_outfile + ext_index);
+ compute_exts_from_src (spec_outfile + ext_index);
+ }
+
+ base_name = strndup (spec_outfile, base_length);
+ /* SHORT_BASE_LENGTH includes neither ".tab" nor ".c". */
+ short_base_length = base_length;
+ if (strsuffix (base_name, ".tab") || strsuffix (base_name, "_tab"))
+ short_base_length -= 4;
+ short_base_name = strndup (spec_outfile, short_base_length);
+
+ return;
+ }