- char *name_base;
-#ifdef MSDOS
- register char *cp;
-#endif
- char *filename;
- int base_length;
- int short_base_length;
-
-#if defined (VMS) & !defined (__VMS_POSIX)
- char *tmp_base = "sys$scratch:b_";
-#else
- char *tmp_base = "/tmp/b.";
-#endif
- int tmp_len;
-
-#ifdef MSDOS
- tmp_base = getenv ("TMP");
- if (tmp_base == 0)
- tmp_base = "";
- strlwr (infile);
-#endif /* MSDOS */
-
-#if (defined(_WIN32) && !defined(__CYGWIN32__))
- tmp_base = getenv ("TEMP"); /* Windows95 defines this ... */
- if (tmp_base == 0)
- tmp_base = getenv ("Temp"); /* ... while NT prefers this */
- if (tmp_base == 0)
- tmp_base = "";
- strlwr (infile);
-#endif /* _WIN32 && !__CYGWIN32__ */
-
-#if (defined(unix) || defined(__unix) || defined(__unix__))
- {
- char *tmp_ptr = getenv("TMPDIR");
-
- if (tmp_ptr != 0)
- tmp_base = stringappend (tmp_ptr, strlen (tmp_ptr), "/b.");
- }
-#endif /* unix || __unix || __unix__ */
-
- tmp_len = strlen (tmp_base);
-
- 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 = (char *) xmalloc (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
- {
- /* -o was not specified; compute output file name from input
- or use y.tab.c, etc., if -y was specified. */
-
- name_base = fixed_outfiles ? "y.y" : infile;
-
- /* BASE_LENGTH gets length of NAME_BASE, sans ".y" suffix if any. */
-
- base_length = strlen (name_base);
- if (!strcmp (name_base + base_length - 2, ".y"))
- base_length -= 2;
- short_base_length = base_length;
-
-#ifdef VMS
- name_base = stringappend(name_base, short_base_length, "_tab");
-#else
-#ifdef MSDOS
- name_base = stringappend(name_base, short_base_length, "_tab");
-#else
- name_base = stringappend(name_base, short_base_length, ".tab");
-#endif /* not MSDOS */
-#endif
- base_length = short_base_length + 4;
- }