+/* FIXME: Should use xstrndup. */
+
+static void
+compute_base_names (void)
+{
+ const char *base, *tab, *ext;
+
+ /* 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)
+ {
+ 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))));
+
+ if (tab)
+ output_infix = xstrndup (tab,
+ (strlen (tab) - (ext ? strlen (ext) : 0)));
+
+ if (ext)
+ compute_exts_from_src (ext);
+ }
+
+ /* If --file-prefix=foo was specified, FULL_BASE_NAME = `foo.tab'
+ and SHORT_BASE_NAME = `foo'.
+
+ Construct names from it. */
+ else
+ {
+ if (spec_file_prefix)
+ {
+ /* If --file-prefix=foo was specified, SHORT_BASE_NAME =
+ `foo'. */
+ short_base_name = xstrdup (spec_file_prefix);
+ }
+ else if (yacc_flag)
+ {
+ /* If --yacc, then the output is `y.tab.c'. */
+ short_base_name = xstrdup ("y");
+ }
+ else
+ {
+ /* Otherwise, the short base name is computed from the input
+ grammar: `foo.yy' => `foo'. */
+ filename_split (infile, &base, &tab, &ext);
+ short_base_name =
+ xstrndup (infile,
+ (strlen (infile) - (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);
+ if (ext && !yacc_flag)
+ compute_exts_from_gf (ext);
+ }
+}
+
+/*-------------------------------------------------------.
+| Close the open files, compute the output files names. |
+`-------------------------------------------------------*/