-  if (spec_outfile)
-    {
-      /* -o was specified.  The precise -o name will be used for FTABLE.
-         For other output files, remove the ".c" or ".tab.c" suffix.  */
-      name_base = spec_outfile;
-#ifdef MSDOS
-      strlwr (name_base);
-#endif /* MSDOS */
-      /* BASE_LENGTH includes ".tab" but not ".c".  */
-      base_length = strlen (name_base);
-      if (!strcmp (name_base + base_length - 2, ".c"))
-       base_length -= 2;
-      /* SHORT_BASE_LENGTH includes neither ".tab" nor ".c".  */
-      short_base_length = base_length;
-      if (!strncmp (name_base + short_base_length - 4, ".tab", 4))
-       short_base_length -= 4;
-      else if (!strncmp (name_base + short_base_length - 4, "_tab", 4))
-       short_base_length -= 4;
-    }
-  else if (spec_file_prefix)
-    {
-      /* -b was specified.  Construct names from it.  */
-      /* SHORT_BASE_LENGTH includes neither ".tab" nor ".c".  */
-      short_base_length = strlen (spec_file_prefix);
-      /* Count room for `.tab'.  */
-      base_length = short_base_length + 4;
-      name_base = XMALLOC (char, base_length + 1);
-      /* Append `.tab'.  */
-      strcpy (name_base, spec_file_prefix);
-#ifdef VMS
-      strcat (name_base, "_tab");
-#else
-      strcat (name_base, ".tab");
-#endif
-#ifdef MSDOS
-      strlwr (name_base);
-#endif /* MSDOS */
-    }
-  else
+  /* Look for the extension, i.e., look for the last dot. */
+  *ext = strrchr (*base, '.');
+  *tab = NULL;
+
+  /* If there is an extension, check if there is a `.tab' part right
+     before.  */
+  if (*ext)