home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / bbs / gnu / gcc-2.6.0-src.lha / GNU / src / amiga / gcc-2.6.0 / gcc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-29  |  131.3 KB  |  4,956 lines

  1. /* Compiler driver program that can handle many languages.
  2.    Copyright (C) 1987, 1989, 1992, 1993, 1994 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. This paragraph is here to try to keep Sun CC from dying.
  21. The number of chars here seems crucial!!!!  */
  22.  
  23. /* This program is the user interface to the C compiler and possibly to
  24. other compilers.  It is used because compilation is a complicated procedure
  25. which involves running several programs and passing temporary files between
  26. them, forwarding the users switches to those programs selectively,
  27. and deleting the temporary files at the end.
  28.  
  29. CC recognizes how to compile each input file by suffixes in the file names.
  30. Once it knows which kind of compilation to perform, the procedure for
  31. compilation is specified by a string called a "spec".  */
  32.  
  33. #include <sys/types.h>
  34. #include <ctype.h>
  35. #include <signal.h>
  36. #include <sys/stat.h>
  37. #include <sys/file.h>   /* May get R_OK, etc. on some systems.  */
  38.  
  39. #include "config.h"
  40. #include "obstack.h"
  41. #ifdef __STDC__
  42. #include <stdarg.h>
  43. #else
  44. #include <varargs.h>
  45. #endif
  46. #include <stdio.h>
  47.  
  48. /* Include multi-lib information.  */
  49. #include "multilib.h"
  50.  
  51. #ifndef R_OK
  52. #define R_OK 4
  53. #define W_OK 2
  54. #define X_OK 1
  55. #endif
  56.  
  57. /* Add prototype support.  */
  58. #ifndef PROTO
  59. #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
  60. #define PROTO(ARGS) ARGS
  61. #else
  62. #define PROTO(ARGS) ()
  63. #endif
  64. #endif
  65.  
  66. #ifndef VPROTO
  67. #ifdef __STDC__
  68. #define PVPROTO(ARGS)        ARGS
  69. #define VPROTO(ARGS)        ARGS
  70. #define VA_START(va_list,var)    va_start(va_list,var)
  71. #else
  72. #define PVPROTO(ARGS)        ()
  73. #define VPROTO(ARGS)        (va_alist) va_dcl
  74. #define VA_START(va_list,var)    va_start(va_list)
  75. #endif
  76. #endif
  77.  
  78. /* Define a generic NULL if one hasn't already been defined.  */
  79.  
  80. #ifndef NULL
  81. #define NULL 0
  82. #endif
  83.  
  84. #ifndef GENERIC_PTR
  85. #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
  86. #define GENERIC_PTR void *
  87. #else
  88. #define GENERIC_PTR char *
  89. #endif
  90. #endif
  91.  
  92. #ifndef NULL_PTR
  93. #define NULL_PTR ((GENERIC_PTR)0)
  94. #endif
  95.  
  96. #ifdef USG
  97. #define vfork fork
  98. #endif /* USG */
  99.  
  100. /* On MSDOS, write temp files in current dir
  101.    because there's no place else we can expect to use.  */
  102. #ifdef __MSDOS__
  103. #ifndef P_tmpdir
  104. #define P_tmpdir "."
  105. #endif
  106. #endif
  107.  
  108. /* Test if something is a normal file.  */
  109. #ifndef S_ISREG
  110. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  111. #endif
  112.  
  113. /* Test if something is a directory.  */
  114. #ifndef S_ISDIR
  115. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  116. #endif
  117.  
  118. /* By default there is no special suffix for executables.  */
  119. #ifndef EXECUTABLE_SUFFIX
  120. #define EXECUTABLE_SUFFIX ""
  121. #endif
  122.  
  123. /* By default, colon separates directories in a path.  */
  124. #ifndef PATH_SEPARATOR
  125. #define PATH_SEPARATOR ':'
  126. #endif
  127.  
  128. #define obstack_chunk_alloc xmalloc
  129. #define obstack_chunk_free free
  130.  
  131. extern void free ();
  132. extern char *getenv ();
  133.  
  134. extern int errno, sys_nerr;
  135. #if defined(bsd4_4) || defined(__NetBSD__)
  136. extern const char *const sys_errlist[];
  137. #else
  138. extern char *sys_errlist[];
  139. #endif
  140.  
  141. extern int execv (), execvp ();
  142.  
  143. /* If a stage of compilation returns an exit status >= 1,
  144.    compilation of that file ceases.  */
  145.  
  146. #define MIN_FATAL_STATUS 1
  147.  
  148. /* Flag saying to print the full filename of this file
  149.    as found through our usual search mechanism.  */
  150.  
  151. static char *print_file_name = NULL;
  152.  
  153. /* As print_file_name, but search for executable file. */
  154.  
  155. static char *print_prog_name = NULL;
  156.  
  157. /* Flag saying to print the relative path we'd use to
  158.    find libgcc.a given the current compiler flags.  */
  159.  
  160. static int print_multi_directory;
  161.  
  162. /* Flag saying to print the list of subdirectories and
  163.    compiler flags used to select them in a standard form.  */
  164.  
  165. static int print_multi_lib;
  166.  
  167. /* Flag indicating whether we should print the command and arguments */
  168.  
  169. static int verbose_flag;
  170.  
  171. /* Nonzero means write "temp" files in source directory
  172.    and use the source file's name in them, and don't delete them.  */
  173.  
  174. static int save_temps_flag;
  175.  
  176. /* The compiler version.  */
  177.  
  178. static char *compiler_version;
  179.  
  180. /* The target version specified with -V */
  181.  
  182. static char *spec_version = DEFAULT_TARGET_VERSION;
  183.  
  184. /* The target machine specified with -b.  */
  185.  
  186. static char *spec_machine = DEFAULT_TARGET_MACHINE;
  187.  
  188. /* Nonzero if cross-compiling.
  189.    When -b is used, the value comes from the `specs' file.  */
  190.  
  191. #ifdef CROSS_COMPILE
  192. static int cross_compile = 1;
  193. #else
  194. static int cross_compile = 0;
  195. #endif
  196.  
  197. /* The number of errors that have occurred; the link phase will not be
  198.    run if this is non-zero.  */
  199. static int error_count = 0;
  200.  
  201. /* This is the obstack which we use to allocate many strings.  */
  202.  
  203. static struct obstack obstack;
  204.  
  205. /* This is the obstack to build an environment variable to pass to
  206.    collect2 that describes all of the relevant switches of what to
  207.    pass the compiler in building the list of pointers to constructors
  208.    and destructors.  */
  209.  
  210. static struct obstack collect_obstack;
  211.  
  212. extern char *version_string;
  213.  
  214. /* Forward declaration for prototypes.  */
  215. struct path_prefix;
  216.  
  217. static void set_spec        PROTO((char *, char *));
  218. static struct compiler *lookup_compiler PROTO((char *, int, char *));
  219. static char *find_a_file    PROTO((struct path_prefix *, char *, int));
  220. static void add_prefix        PROTO((struct path_prefix *, char *, int, int, int *));
  221. static char *skip_whitespace    PROTO((char *));
  222. static void record_temp_file    PROTO((char *, int, int));
  223. static void delete_if_ordinary    PROTO((char *));
  224. static void delete_temp_files    PROTO((void));
  225. static void delete_failure_queue PROTO((void));
  226. static void clear_failure_queue PROTO((void));
  227. static char *choose_temp_base_try PROTO((char *, char *));
  228. static void choose_temp_base    PROTO((void));
  229. static int check_live_switch    PROTO((int, int));
  230. static char *handle_braces    PROTO((char *));
  231. static char *save_string    PROTO((char *, int));
  232. static char *concat        PROTO((char *, char *, char *));
  233. static int do_spec        PROTO((char *));
  234. static int do_spec_1        PROTO((char *, int, char *));
  235. static char *find_file        PROTO((char *));
  236. static int is_directory        PROTO((char *, char *, int));
  237. static void validate_switches    PROTO((char *));
  238. static void validate_all_switches PROTO((void));
  239. static void give_switch        PROTO((int, int));
  240. static int used_arg        PROTO((char *, int));
  241. static void set_multilib_dir    PROTO((void));
  242. static void print_multilib_info    PROTO((void));
  243. static void pfatal_with_name    PROTO((char *));
  244. static void perror_with_name    PROTO((char *));
  245. static void perror_exec        PROTO((char *));
  246. #ifdef HAVE_VPRINTF
  247. static void fatal        PVPROTO((char *, ...));
  248. static void error        PVPROTO((char *, ...));
  249. #else
  250. /* We must not provide any prototype here, even if ANSI C.  */
  251. static void fatal        PROTO(());
  252. static void error        PROTO(());
  253. #endif
  254.  
  255. void fancy_abort ();
  256. char *xmalloc ();
  257. char *xrealloc ();
  258.  
  259. /* Specs are strings containing lines, each of which (if not blank)
  260. is made up of a program name, and arguments separated by spaces.
  261. The program name must be exact and start from root, since no path
  262. is searched and it is unreliable to depend on the current working directory.
  263. Redirection of input or output is not supported; the subprograms must
  264. accept filenames saying what files to read and write.
  265.  
  266. In addition, the specs can contain %-sequences to substitute variable text
  267. or for conditional text.  Here is a table of all defined %-sequences.
  268. Note that spaces are not generated automatically around the results of
  269. expanding these sequences; therefore, you can concatenate them together
  270. or with constant text in a single argument.
  271.  
  272.  %%    substitute one % into the program name or argument.
  273.  %i     substitute the name of the input file being processed.
  274.  %b     substitute the basename of the input file being processed.
  275.     This is the substring up to (and not including) the last period
  276.     and not including the directory.
  277.  %g     substitute the temporary-file-name-base.  This is a string chosen
  278.     once per compilation.  Different temporary file names are made by
  279.     concatenation of constant strings on the end, as in `%g.s'.
  280.     %g also has the same effect of %d.
  281.  %u    like %g, but make the temporary file name unique.
  282.  %U    returns the last file name generated with %u.
  283.  %d    marks the argument containing or following the %d as a
  284.     temporary file name, so that that file will be deleted if CC exits
  285.     successfully.  Unlike %g, this contributes no text to the argument.
  286.  %w    marks the argument containing or following the %w as the
  287.     "output file" of this compilation.  This puts the argument
  288.     into the sequence of arguments that %o will substitute later.
  289.  %W{...}
  290.     like %{...} but mark last argument supplied within
  291.     as a file to be deleted on failure.
  292.  %o    substitutes the names of all the output files, with spaces
  293.     automatically placed around them.  You should write spaces
  294.     around the %o as well or the results are undefined.
  295.     %o is for use in the specs for running the linker.
  296.     Input files whose names have no recognized suffix are not compiled
  297.     at all, but they are included among the output files, so they will
  298.     be linked.
  299.  %p    substitutes the standard macro predefinitions for the
  300.     current target machine.  Use this when running cpp.
  301.  %P    like %p, but puts `__' before and after the name of each macro.
  302.     (Except macros that already have __.)
  303.     This is for ANSI C.
  304.  %I    Substitute a -iprefix option made from GCC_EXEC_PREFIX.
  305.  %s     current argument is the name of a library or startup file of some sort.
  306.         Search for that file in a standard list of directories
  307.     and substitute the full name found.
  308.  %eSTR  Print STR as an error message.  STR is terminated by a newline.
  309.         Use this when inconsistent options are detected.
  310.  %x{OPTION}    Accumulate an option for %X.
  311.  %X    Output the accumulated linker options specified by compilations.
  312.  %Y    Output the accumulated assembler options specified by compilations.
  313.  %v1    Substitute the major version number of GCC.
  314.     (For version 2.5.n, this is 2.)
  315.  %v2    Substitute the minor version number of GCC.
  316.     (For version 2.5.n, this is 5.)
  317.  %a     process ASM_SPEC as a spec.
  318.         This allows config.h to specify part of the spec for running as.
  319.  %A    process ASM_FINAL_SPEC as a spec.  A capital A is actually
  320.     used here.  This can be used to run a post-processor after the
  321.     assembler has done it's job.
  322.  %D    Dump out a -L option for each directory in startfile_prefix.
  323.     If multilib_dir is set, extra entries are generated with it affixed.
  324.  %l     process LINK_SPEC as a spec.
  325.  %L     process LIB_SPEC as a spec.
  326.  %S     process STARTFILE_SPEC as a spec.  A capital S is actually used here.
  327.  %E     process ENDFILE_SPEC as a spec.  A capital E is actually used here.
  328.  %c    process SIGNED_CHAR_SPEC as a spec.
  329.  %C     process CPP_SPEC as a spec.  A capital C is actually used here.
  330.  %1    process CC1_SPEC as a spec.
  331.  %2    process CC1PLUS_SPEC as a spec.
  332.  %|    output "-" if the input for the current command is coming from a pipe.
  333.  %*    substitute the variable part of a matched option.  (See below.)
  334.     Note that each comma in the substituted string is replaced by
  335.     a single space.
  336.  %{S}   substitutes the -S switch, if that switch was given to CC.
  337.     If that switch was not specified, this substitutes nothing.
  338.     Here S is a metasyntactic variable.
  339.  %{S*}  substitutes all the switches specified to CC whose names start
  340.     with -S.  This is used for -o, -D, -I, etc; switches that take
  341.     arguments.  CC considers `-o foo' as being one switch whose
  342.     name starts with `o'.  %{o*} would substitute this text,
  343.     including the space; thus, two arguments would be generated.
  344.  %{S*:X} substitutes X if one or more switches whose names start with -S are
  345.     specified to CC.  Note that the tail part of the -S option
  346.     (i.e. the part matched by the `*') will be substituted for each
  347.     occurrence of %* within X.
  348.  %{S:X} substitutes X, but only if the -S switch was given to CC.
  349.  %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
  350.  %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
  351.  %{|!S:X} like %{!S:X}, but if there is an S switch, substitute `-'.
  352.  %{.S:X} substitutes X, but only if processing a file with suffix S.
  353.  %{!.S:X} substitutes X, but only if NOT processing a file with suffix S.
  354.  %(Spec) processes a specification defined in a specs file as *Spec:
  355.  %[Spec] as above, but put __ around -D arguments
  356.  
  357. The conditional text X in a %{S:X} or %{!S:X} construct may contain
  358. other nested % constructs or spaces, or even newlines.  They are
  359. processed as usual, as described above.
  360.  
  361. The -O, -f, -m, and -W switches are handled specifically in these
  362. constructs.  If another value of -O or the negated form of a -f, -m, or
  363. -W switch is found later in the command line, the earlier switch
  364. value is ignored, except with {S*} where S is just one letter; this
  365. passes all matching options.
  366.  
  367. The character | is used to indicate that a command should be piped to
  368. the following command, but only if -pipe is specified.
  369.  
  370. Note that it is built into CC which switches take arguments and which
  371. do not.  You might think it would be useful to generalize this to
  372. allow each compiler's spec to say which switches take arguments.  But
  373. this cannot be done in a consistent fashion.  CC cannot even decide
  374. which input files have been specified without knowing which switches
  375. take arguments, and it must know which input files to compile in order
  376. to tell which compilers to run.
  377.  
  378. CC also knows implicitly that arguments starting in `-l' are to be
  379. treated as compiler output files, and passed to the linker in their
  380. proper position among the other output files.  */
  381.  
  382. /* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1.  */
  383.  
  384. /* config.h can define ASM_SPEC to provide extra args to the assembler
  385.    or extra switch-translations.  */
  386. #ifndef ASM_SPEC
  387. #define ASM_SPEC ""
  388. #endif
  389.  
  390. /* config.h can define ASM_FINAL_SPEC to run a post processor after
  391.    the assembler has run.  */
  392. #ifndef ASM_FINAL_SPEC
  393. #define ASM_FINAL_SPEC ""
  394. #endif
  395.  
  396. /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
  397.    or extra switch-translations.  */
  398. #ifndef CPP_SPEC
  399. #define CPP_SPEC ""
  400. #endif
  401.  
  402. /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
  403.    or extra switch-translations.  */
  404. #ifndef CC1_SPEC
  405. #define CC1_SPEC ""
  406. #endif
  407.  
  408. /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
  409.    or extra switch-translations.  */
  410. #ifndef CC1PLUS_SPEC
  411. #define CC1PLUS_SPEC ""
  412. #endif
  413.  
  414. /* config.h can define LINK_SPEC to provide extra args to the linker
  415.    or extra switch-translations.  */
  416. #ifndef LINK_SPEC
  417. #define LINK_SPEC ""
  418. #endif
  419.  
  420. /* config.h can define LIB_SPEC to override the default libraries.  */
  421. #ifndef LIB_SPEC
  422. #define LIB_SPEC "%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}"
  423. #endif
  424.  
  425. /* config.h can define STARTFILE_SPEC to override the default crt0 files.  */
  426. #ifndef STARTFILE_SPEC
  427. #define STARTFILE_SPEC  \
  428.   "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}"
  429. #endif
  430.  
  431. /* config.h can define SWITCHES_NEED_SPACES to control passing -o and -L.
  432.    Make the string nonempty to require spaces there.  */
  433. #ifndef SWITCHES_NEED_SPACES
  434. #define SWITCHES_NEED_SPACES ""
  435. #endif
  436.  
  437. /* config.h can define ENDFILE_SPEC to override the default crtn files.  */
  438. #ifndef ENDFILE_SPEC
  439. #define ENDFILE_SPEC ""
  440. #endif
  441.  
  442. /* This spec is used for telling cpp whether char is signed or not.  */
  443. #ifndef SIGNED_CHAR_SPEC
  444. /* Use #if rather than ?:
  445.    because MIPS C compiler rejects like ?: in initializers.  */
  446. #if DEFAULT_SIGNED_CHAR
  447. #define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
  448. #else
  449. #define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
  450. #endif
  451. #endif
  452.  
  453. /* MULTILIB_SELECT comes from multilib.h.  It gives a
  454.    string interpreted by set_multilib_dir to select a library
  455.    subdirectory based on the compiler options.  */
  456. #ifndef MULTILIB_SELECT
  457. #define MULTILIB_SELECT ". ;"
  458. #endif
  459.  
  460. static char *cpp_spec = CPP_SPEC;
  461. static char *cpp_predefines = CPP_PREDEFINES;
  462. static char *cc1_spec = CC1_SPEC;
  463. static char *cc1plus_spec = CC1PLUS_SPEC;
  464. static char *signed_char_spec = SIGNED_CHAR_SPEC;
  465. static char *asm_spec = ASM_SPEC;
  466. static char *asm_final_spec = ASM_FINAL_SPEC;
  467. static char *link_spec = LINK_SPEC;
  468. static char *lib_spec = LIB_SPEC;
  469. static char *endfile_spec = ENDFILE_SPEC;
  470. static char *startfile_spec = STARTFILE_SPEC;
  471. static char *switches_need_spaces = SWITCHES_NEED_SPACES;
  472. static char *multilib_select = MULTILIB_SELECT;
  473.  
  474. /* This defines which switch letters take arguments.  */
  475.  
  476. #ifndef SWITCH_TAKES_ARG
  477. #define SWITCH_TAKES_ARG(CHAR)      \
  478.   ((CHAR) == 'D' || (CHAR) == 'U' || (CHAR) == 'o' \
  479.    || (CHAR) == 'e' || (CHAR) == 'T' || (CHAR) == 'u' \
  480.    || (CHAR) == 'I' || (CHAR) == 'm' \
  481.    || (CHAR) == 'L' || (CHAR) == 'A')
  482. #endif
  483.  
  484. /* This defines which multi-letter switches take arguments.  */
  485.  
  486. #define DEFAULT_WORD_SWITCH_TAKES_ARG(STR)        \
  487.  (!strcmp (STR, "Tdata") || !strcmp (STR, "Ttext")    \
  488.   || !strcmp (STR, "Tbss") || !strcmp (STR, "include")    \
  489.   || !strcmp (STR, "imacros") || !strcmp (STR, "aux-info") \
  490.   || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
  491.   || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
  492.   || !strcmp (STR, "isystem"))
  493.  
  494. #ifndef WORD_SWITCH_TAKES_ARG
  495. #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
  496. #endif
  497.  
  498. /* Record the mapping from file suffixes for compilation specs.  */
  499.  
  500. struct compiler
  501. {
  502.   char *suffix;            /* Use this compiler for input files
  503.                    whose names end in this suffix.  */
  504.  
  505.   char *spec[4];        /* To use this compiler, concatenate these
  506.                    specs and pass to do_spec.  */
  507. };
  508.  
  509. /* Pointer to a vector of `struct compiler' that gives the spec for
  510.    compiling a file, based on its suffix.
  511.    A file that does not end in any of these suffixes will be passed
  512.    unchanged to the loader and nothing else will be done to it.
  513.  
  514.    An entry containing two 0s is used to terminate the vector.
  515.  
  516.    If multiple entries match a file, the last matching one is used.  */
  517.  
  518. static struct compiler *compilers;
  519.  
  520. /* Number of entries in `compilers', not counting the null terminator.  */
  521.  
  522. static int n_compilers;
  523.  
  524. /* The default list of file name suffixes and their compilation specs.  */
  525.  
  526. static struct compiler default_compilers[] =
  527. {
  528.   {".c", "@c"},
  529.   {"@c",
  530.    "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
  531.     %{C:%{!E:%eGNU C does not support -C without using -E}}\
  532.     %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
  533.         -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
  534.     %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
  535.     %{!undef:%{!ansi:%p} %P} %{trigraphs} \
  536.         %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
  537.         %{traditional-cpp:-traditional}\
  538.     %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
  539.         %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
  540.    "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
  541.            %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a}\
  542.            %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
  543.            %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
  544.            %{aux-info*}\
  545.            %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
  546.            %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
  547.               %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
  548.               %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
  549.                       %{!pipe:%g.s} %A\n }}}}"},
  550.   {"-",
  551.    "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
  552.     %{C:%{!E:%eGNU C does not support -C without using -E}}\
  553.     %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
  554.         -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
  555.     %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
  556.     %{!undef:%{!ansi:%p} %P} %{trigraphs}\
  557.         %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
  558.         %{traditional-cpp:-traditional}\
  559.     %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
  560.         %i %W{o*}}\
  561.     %{!E:%e-E required when input is from standard input}"},
  562.   {".m", "@objective-c"},
  563.   {"@objective-c",
  564.    "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
  565.     %{C:%{!E:%eGNU C does not support -C without using -E}}\
  566.     %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
  567.         -undef -D__OBJC__ -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
  568.      %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
  569.     %{!undef:%{!ansi:%p} %P} %{trigraphs}\
  570.         %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
  571.         %{traditional-cpp:-traditional}\
  572.     %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
  573.         %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
  574.    "%{!M:%{!MM:%{!E:cc1obj %{!pipe:%g.i} %1 \
  575.            %{!Q:-quiet} -dumpbase %b.m %{d*} %{m*} %{a}\
  576.            %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
  577.            %{traditional} %{v:-version} %{pg:-p} %{p} %{f*} \
  578.                -lang-objc %{gen-decls} \
  579.            %{aux-info*}\
  580.            %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
  581.            %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
  582.               %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
  583.               %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
  584.                       %{!pipe:%g.s} %A\n }}}}"},
  585.   {".h", "@c-header"},
  586.   {"@c-header",
  587.    "%{!E:%eCompilation of header file requested} \
  588.     cpp %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
  589.     %{C:%{!E:%eGNU C does not support -C without using -E}}\
  590.      %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
  591.         -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
  592.      %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
  593.     %{!undef:%{!ansi:%p} %P} %{trigraphs}\
  594.         %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
  595.         %{traditional-cpp:-traditional}\
  596.     %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
  597.         %i %W{o*}"},
  598.   {".cc", "@c++"},
  599.   {".cxx", "@c++"},
  600.   {".cpp", "@c++"},
  601.   {".C", "@c++"},
  602.   {"@c++",
  603.    "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
  604.     %{C:%{!E:%eGNU C++ does not support -C without using -E}}\
  605.     %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
  606.     -undef -D__GNUC__=%v1 -D__GNUG__=%v1 -D__cplusplus -D__GNUC_MINOR__=%v2\
  607.     %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!undef:%{!ansi:%p} %P}\
  608.         %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
  609.         %{traditional-cpp:-traditional} %{trigraphs}\
  610.     %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
  611.         %i %{!M:%{!MM:%{!E:%{!pipe:%g.ii}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
  612.    "%{!M:%{!MM:%{!E:cc1plus %{!pipe:%g.ii} %1 %2\
  613.                 %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\
  614.                 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
  615.                 %{traditional} %{v:-version} %{pg:-p} %{p}\
  616.                 %{f*} %{+e*} %{aux-info*}\
  617.                 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
  618.                 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}}|\n\
  619.               %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
  620.               %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
  621.                       %{!pipe:%g.s} %A\n }}}}"},
  622.   {".i", "@cpp-output"},
  623.   {"@cpp-output",
  624.    "%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a}\
  625.             %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
  626.             %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
  627.             %{aux-info*}\
  628.             %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
  629.             %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
  630.              %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
  631.                  %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
  632.                  %{!pipe:%g.s} %A\n }}}}"},
  633.   {".ii", "@c++-cpp-output"},
  634.   {"@c++-cpp-output",
  635.    "%{!M:%{!MM:%{!E:cc1plus %i %1 %2 %{!Q:-quiet} %{d*} %{m*} %{a}\
  636.                 %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
  637.                 %{traditional} %{v:-version} %{pg:-p} %{p}\
  638.                 %{f*} %{+e*} %{aux-info*}\
  639.                 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
  640.                 %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
  641.                 %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
  642.                 %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
  643.                 %{!pipe:%g.s} %A\n }}}}"},
  644.   {".s", "@assembler"},
  645.   {"@assembler",
  646.    "%{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
  647.                     %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
  648.                 %i %A\n }}}}"},
  649.   {".S", "@assembler-with-cpp"},
  650.   {"@assembler-with-cpp",
  651.    "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
  652.     %{C:%{!E:%eGNU C does not support -C without using -E}}\
  653.     %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{trigraphs}\
  654.         -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
  655.         %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\
  656.         %{traditional-cpp:-traditional}\
  657.     %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*}\
  658.         %i %{!M:%{!MM:%{!E:%{!pipe:%g.s}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
  659.    "%{!M:%{!MM:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
  660.                     %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%u.o}\
  661.             %{!pipe:%g.s} %A\n }}}}"},
  662.   {".ads", "@ada"},
  663.   {".adb", "@ada"},
  664.   {".ada", "@ada"},
  665.   {"@ada",
  666.    "%{!M:%{!MM:%{!E:gnat1 %{k8:-gnatk8} %{w:-gnatws} %{!Q:-quiet}\
  667.                -dumpbase %b.ada %{g*} %{O*} %{p} %{pg:-p} %{f*}\
  668.               %{d*}\
  669.               %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
  670.               %i %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
  671.             %{!S:%{!gnatc:%{!gnats:as %{R} %{j} %{J} %{h} %{d2} %a %Y\
  672.                           %{c:%W{o*}%{!o*:-o %w%b.o}}\
  673.                           %{!c:-o %d%w%u.o} %{!pipe:%g.s} %A\n}}}}}} "},
  674.   /* Mark end of table */
  675.   {0, 0}
  676. };
  677.  
  678. /* Number of elements in default_compilers, not counting the terminator.  */
  679.  
  680. static int n_default_compilers
  681.   = (sizeof default_compilers / sizeof (struct compiler)) - 1;
  682.  
  683. /* Here is the spec for running the linker, after compiling all files.  */
  684.  
  685. /* -u* was put back because both BSD and SysV seem to support it.  */
  686. /* %{static:} simply prevents an error message if the target machine
  687.    doesn't handle -static.  */
  688. /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
  689.    scripts which exist in user specified directories, or in standard
  690.    directories.  */
  691. #ifdef LINK_LIBGCC_SPECIAL_1
  692. /* Have gcc do the search for libgcc.a, but generate -L options as usual.  */
  693. static char *link_command_spec = "\
  694. %{!fsyntax-only: \
  695.  %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
  696.             %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
  697.             %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
  698.             %{L*} %D %{T*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}}";
  699. #else
  700. #ifdef LINK_LIBGCC_SPECIAL
  701. /* Have gcc do the search for libgcc.a, and don't generate -L options.  */
  702. static char *link_command_spec = "\
  703. %{!fsyntax-only: \
  704.  %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
  705.             %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
  706.             %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
  707.             %{L*} %{T*} %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}}";
  708. #else
  709. /* Use -L and have the linker do the search for -lgcc.  */
  710. static char *link_command_spec = "\
  711. %{!fsyntax-only: \
  712.  %{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
  713.             %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
  714.             %{!A:%{!nostartfiles:%{!nostdlib:%S}}} %{static:}\
  715.             %{L*} %D %{T*} %o %{!nostdlib:-lgcc %L -lgcc %{!A:%E}}\n }}}}}}";
  716. #endif
  717. #endif
  718.  
  719. /* A vector of options to give to the linker.
  720.    These options are accumulated by -Xlinker and -Wl,
  721.    and substituted into the linker command with %X.  */
  722. static int n_linker_options;
  723. static char **linker_options;
  724.  
  725. /* A vector of options to give to the assembler.
  726.    These options are accumulated by -Wa,
  727.    and substituted into the assembler command with %X.  */
  728. static int n_assembler_options;
  729. static char **assembler_options;
  730.  
  731. /* Define how to map long options into short ones.  */
  732.  
  733. /* This structure describes one mapping.  */
  734. struct option_map
  735. {
  736.   /* The long option's name.  */
  737.   char *name;
  738.   /* The equivalent short option.  */
  739.   char *equivalent;
  740.   /* Argument info.  A string of flag chars; NULL equals no options.
  741.      a => argument required.
  742.      o => argument optional.
  743.      j => join argument to equivalent, making one word.
  744.      * => allow other text after NAME as an argument.  */
  745.   char *arg_info;
  746. };
  747.  
  748. /* This is the table of mappings.  Mappings are tried sequentially
  749.    for each option encountered; the first one that matches, wins.  */
  750.  
  751. struct option_map option_map[] =
  752.  {
  753.    {"--profile-blocks", "-a", 0},
  754.    {"--target", "-b", "a"},
  755.    {"--compile", "-c", 0},
  756.    {"--dump", "-d", "a"},
  757.    {"--entry", "-e", 0},
  758.    {"--debug", "-g", "oj"},
  759.    {"--include", "-include", "a"},
  760.    {"--imacros", "-imacros", "a"},
  761.    {"--include-prefix", "-iprefix", "a"},
  762.    {"--include-directory-after", "-idirafter", "a"},
  763.    {"--include-with-prefix", "-iwithprefix", "a"},
  764.    {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
  765.    {"--include-with-prefix-after", "-iwithprefix", "a"},
  766.    {"--machine-", "-m", "*j"},
  767.    {"--machine", "-m", "aj"},
  768.    {"--no-standard-includes", "-nostdinc", 0},
  769.    {"--no-standard-libraries", "-nostdlib", 0},
  770.    {"--no-precompiled-includes", "-noprecomp", 0},
  771.    {"--output", "-o", "a"},
  772.    {"--profile", "-p", 0},
  773.    {"--quiet", "-q", 0},
  774.    {"--silent", "-q", 0},
  775.    {"--force-link", "-u", "a"},
  776.    {"--verbose", "-v", 0},
  777.    {"--version", "-dumpversion", 0},
  778.    {"--no-warnings", "-w", 0},
  779.    {"--language", "-x", "a"},
  780.  
  781.    {"--assert", "-A", "a"},
  782.    {"--prefix", "-B", "a"},
  783.    {"--comments", "-C", 0},
  784.    {"--define-macro", "-D", "a"},
  785.    {"--preprocess", "-E", 0},
  786.    {"--trace-includes", "-H", 0},
  787.    {"--include-directory", "-I", "a"},
  788.    {"--include-barrier", "-I-", 0},
  789.    {"--library-directory", "-L", "a"},
  790.    {"--dependencies", "-M", 0},
  791.    {"--user-dependencies", "-MM", 0},
  792.    {"--write-dependencies", "-MD", 0},
  793.    {"--write-user-dependencies", "-MMD", 0},
  794.    {"--print-missing-file-dependencies", "-MG", 0},
  795.    {"--optimize", "-O", "oj"},
  796.    {"--no-line-commands", "-P", 0},
  797.    {"--assemble", "-S", 0},
  798.    {"--undefine-macro", "-U", "a"},
  799.    {"--use-version", "-V", "a"},
  800.    {"--for-assembler", "-Wa", "a"},
  801.    {"--extra-warnings", "-W", 0},
  802.    {"--all-warnings", "-Wall", 0},
  803.    {"--warn-", "-W", "*j"},
  804.    {"--for-linker", "-Xlinker", "a"},
  805.  
  806.    {"--ansi", "-ansi", 0},
  807.    {"--traditional", "-traditional", 0},
  808.    {"--traditional-cpp", "-traditional-cpp", 0},
  809.    {"--trigraphs", "-trigraphs", 0},
  810.    {"--pipe", "-pipe", 0},
  811.    {"--dumpbase", "-dumpbase", "a"},
  812.    {"--pedantic", "-pedantic", 0},
  813.    {"--pedantic-errors", "-pedantic-errors", 0},
  814.    {"--save-temps", "-save-temps", 0},
  815.    {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
  816.    {"--print-file-name", "-print-file-name=", "aj"},
  817.    {"--print-prog-name", "-print-prog-name=", "aj"},
  818.    {"--print-multi-lib", "-print-multi-lib", 0},
  819.    {"--print-multi-directory", "-print-multi-directory", 0},
  820.    {"--static", "-static", 0},
  821.    {"--shared", "-shared", 0},
  822.    {"--symbolic", "-symbolic", 0},
  823.    {"--", "-f", "*j"}
  824.  };
  825.  
  826. /* Translate the options described by *ARGCP and *ARGVP.
  827.    Make a new vector and store it back in *ARGVP,
  828.    and store its length in *ARGVC.  */
  829.  
  830. static void
  831. translate_options (argcp, argvp)
  832.      int *argcp;
  833.      char ***argvp;
  834. {
  835.   int i, j;
  836.   int argc = *argcp;
  837.   char **argv = *argvp;
  838.   char **newv = (char **) xmalloc ((argc + 2) * 2 * sizeof (char *));
  839.   int newindex = 0;
  840.  
  841.   i = 0;
  842.   newv[newindex++] = argv[i++];
  843.  
  844.   while (i < argc)
  845.     {
  846.       /* Translate -- options.  */
  847.       if (argv[i][0] == '-' && argv[i][1] == '-')
  848.     {
  849.       /* Find a mapping that applies to this option.  */
  850.       for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++)
  851.         {
  852.           int optlen = strlen (option_map[j].name);
  853.           int complen = strlen (argv[i]);
  854.           char *arginfo = option_map[j].arg_info;
  855.  
  856.           if (arginfo == 0)
  857.         arginfo = "";
  858.           if (complen > optlen)
  859.         complen = optlen;
  860.           if (!strncmp (argv[i], option_map[j].name, complen))
  861.         {
  862.           int extra = strlen (argv[i]) > optlen;
  863.           char *arg = 0;
  864.  
  865.           if (extra)
  866.             {
  867.               /* If the option has an argument, accept that.  */
  868.               if (argv[i][optlen] == '=')
  869.             arg = argv[i] + optlen + 1;
  870.               /* If this mapping allows extra text at end of name,
  871.              accept that as "argument".  */
  872.               else if (index (arginfo, '*') != 0)
  873.             arg = argv[i] + optlen;
  874.               /* Otherwise, extra text at end means mismatch.
  875.              Try other mappings.  */
  876.               else
  877.             continue;
  878.             }
  879.           else if (index (arginfo, '*') != 0)
  880.             error ("Incomplete `%s' option", option_map[j].name);
  881.  
  882.           /* Handle arguments.  */
  883.           if (index (arginfo, 'o') != 0)
  884.             {
  885.               if (arg == 0)
  886.             {
  887.               if (i + 1 == argc)
  888.                 error ("Missing argument to `%s' option",
  889.                    option_map[j].name);
  890.               arg = argv[++i];
  891.             }
  892.             }
  893.           else if (index (arginfo, '*') != 0)
  894.             ;
  895.           else if (index (arginfo, 'a') == 0)
  896.             {
  897.               if (arg != 0)
  898.             error ("Extraneous argument to `%s' option",
  899.                    option_map[j].name);
  900.               arg = 0;
  901.             }
  902.  
  903.           /* Store the translation as one argv elt or as two.  */
  904.           if (arg != 0 && index (arginfo, 'j') != 0)
  905.             newv[newindex++] = concat (option_map[j].equivalent,
  906.                            arg, "");
  907.           else if (arg != 0)
  908.             {
  909.               newv[newindex++] = option_map[j].equivalent;
  910.               newv[newindex++] = arg;
  911.             }
  912.           else
  913.             newv[newindex++] = option_map[j].equivalent;
  914.  
  915.           break;
  916.         }
  917.         }
  918.       i++;
  919.     }
  920.       /* Handle old-fashioned options--just copy them through,
  921.      with their arguments.  */
  922.       else if (argv[i][0] == '-')
  923.     {
  924.       char *p = argv[i] + 1;
  925.       int c = *p;
  926.       int nskip = 1;
  927.  
  928.       if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
  929.         nskip += SWITCH_TAKES_ARG (c) - (p[1] != 0);
  930.       else if (WORD_SWITCH_TAKES_ARG (p))
  931.         nskip += WORD_SWITCH_TAKES_ARG (p);
  932.       else if ((c == 'B' || c == 'b' || c == 'V' || c == 'x')
  933.            && p[1] == 0)
  934.         nskip += 1;
  935.       else if (! strcmp (p, "Xlinker"))
  936.         nskip += 1;
  937.  
  938.       /* Watch out for an option at the end of the command line that
  939.          is missing arguments, and avoid skipping past the end of the
  940.          command line.  */
  941.       if (nskip + i > argc)
  942.         nskip = argc - i;
  943.  
  944.       while (nskip > 0)
  945.         {
  946.           newv[newindex++] = argv[i++];
  947.           nskip--;
  948.         }
  949.     }
  950.       else
  951.     /* Ordinary operands, or +e options.  */
  952.     newv[newindex++] = argv[i++];
  953.     }
  954.  
  955.   newv[newindex] = 0;
  956.  
  957.   *argvp = newv;
  958.   *argcp = newindex;
  959. }
  960.  
  961. /* Read compilation specs from a file named FILENAME,
  962.    replacing the default ones.
  963.  
  964.    A suffix which starts with `*' is a definition for
  965.    one of the machine-specific sub-specs.  The "suffix" should be
  966.    *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
  967.    The corresponding spec is stored in asm_spec, etc.,
  968.    rather than in the `compilers' vector.
  969.  
  970.    Anything invalid in the file is a fatal error.  */
  971.  
  972. static void
  973. read_specs (filename)
  974.      char *filename;
  975. {
  976.   int desc;
  977.   struct stat statbuf;
  978.   char *buffer;
  979.   register char *p;
  980.  
  981.   if (verbose_flag)
  982.     fprintf (stderr, "Reading specs from %s\n", filename);
  983.  
  984.   /* Open and stat the file.  */
  985.   desc = open (filename, 0, 0);
  986.   if (desc < 0)
  987.     pfatal_with_name (filename);
  988.   if (stat (filename, &statbuf) < 0)
  989.     pfatal_with_name (filename);
  990.  
  991.   /* Read contents of file into BUFFER.  */
  992.   buffer = xmalloc ((unsigned) statbuf.st_size + 1);
  993.   read (desc, buffer, (unsigned) statbuf.st_size);
  994.   buffer[statbuf.st_size] = 0;
  995.   close (desc);
  996.  
  997.   /* Scan BUFFER for specs, putting them in the vector.  */
  998.   p = buffer;
  999.   while (1)
  1000.     {
  1001.       char *suffix;
  1002.       char *spec;
  1003.       char *in, *out, *p1, *p2;
  1004.  
  1005.       /* Advance P in BUFFER to the next nonblank nocomment line.  */
  1006.       p = skip_whitespace (p);
  1007.       if (*p == 0)
  1008.     break;
  1009.  
  1010.       /* Find the colon that should end the suffix.  */
  1011.       p1 = p;
  1012.       while (*p1 && *p1 != ':' && *p1 != '\n') p1++;
  1013.       /* The colon shouldn't be missing.  */
  1014.       if (*p1 != ':')
  1015.     fatal ("specs file malformed after %d characters", p1 - buffer);
  1016.       /* Skip back over trailing whitespace.  */
  1017.       p2 = p1;
  1018.       while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) p2--;
  1019.       /* Copy the suffix to a string.  */
  1020.       suffix = save_string (p, p2 - p);
  1021.       /* Find the next line.  */
  1022.       p = skip_whitespace (p1 + 1);
  1023.       if (p[1] == 0)
  1024.     fatal ("specs file malformed after %d characters", p - buffer);
  1025.       p1 = p;
  1026.       /* Find next blank line.  */
  1027.       while (*p1 && !(*p1 == '\n' && p1[1] == '\n')) p1++;
  1028.       /* Specs end at the blank line and do not include the newline.  */
  1029.       spec = save_string (p, p1 - p);
  1030.       p = p1;
  1031.  
  1032.       /* Delete backslash-newline sequences from the spec.  */
  1033.       in = spec;
  1034.       out = spec;
  1035.       while (*in != 0)
  1036.     {
  1037.       if (in[0] == '\\' && in[1] == '\n')
  1038.         in += 2;
  1039.       else if (in[0] == '#')
  1040.         {
  1041.           while (*in && *in != '\n') in++;
  1042.         }
  1043.       else
  1044.         *out++ = *in++;
  1045.     }
  1046.       *out = 0;
  1047.  
  1048.       if (suffix[0] == '*')
  1049.     {
  1050.       if (! strcmp (suffix, "*link_command"))
  1051.         link_command_spec = spec;
  1052.       else
  1053.         set_spec (suffix + 1, spec);
  1054.     }
  1055.       else
  1056.     {
  1057.       /* Add this pair to the vector.  */
  1058.       compilers
  1059.         = ((struct compiler *)
  1060.            xrealloc (compilers, (n_compilers + 2) * sizeof (struct compiler)));
  1061.       compilers[n_compilers].suffix = suffix;
  1062.       bzero ((char *) compilers[n_compilers].spec,
  1063.          sizeof compilers[n_compilers].spec);
  1064.       compilers[n_compilers].spec[0] = spec;
  1065.       n_compilers++;
  1066.       bzero ((char *) &compilers[n_compilers],
  1067.          sizeof compilers[n_compilers]);
  1068.     }
  1069.  
  1070.       if (*suffix == 0)
  1071.     link_command_spec = spec;
  1072.     }
  1073.  
  1074.   if (link_command_spec == 0)
  1075.     fatal ("spec file has no spec for linking");
  1076. }
  1077.  
  1078. static char *
  1079. skip_whitespace (p)
  1080.      char *p;
  1081. {
  1082.   while (1)
  1083.     {
  1084.       /* A fully-blank line is a delimiter in the SPEC file and shouldn't
  1085.      be considered whitespace.  */
  1086.       if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
  1087.     return p + 1;
  1088.       else if (*p == '\n' || *p == ' ' || *p == '\t')
  1089.     p++;
  1090.       else if (*p == '#')
  1091.     {
  1092.       while (*p != '\n') p++;
  1093.       p++;
  1094.     }
  1095.       else
  1096.     break;
  1097.     }
  1098.  
  1099.   return p;
  1100. }
  1101.  
  1102. /* Structure to keep track of the specs that have been defined so far.  These
  1103.    are accessed using %(specname) or %[specname] in a compiler or link spec. */
  1104.  
  1105. struct spec_list
  1106. {
  1107.   char *name;                 /* Name of the spec. */
  1108.   char *spec;                 /* The spec itself. */
  1109.   struct spec_list *next;     /* Next spec in linked list. */
  1110. };
  1111.  
  1112. /* List of specs that have been defined so far. */
  1113.  
  1114. static struct spec_list *specs = (struct spec_list *) 0;
  1115.  
  1116. /* Change the value of spec NAME to SPEC.  If SPEC is empty, then the spec is
  1117.    removed; If the spec starts with a + then SPEC is added to the end of the
  1118.    current spec. */
  1119.  
  1120. static void
  1121. set_spec (name, spec)
  1122.      char *name;
  1123.      char *spec;
  1124. {
  1125.   struct spec_list *sl;
  1126.   char *old_spec;
  1127.  
  1128.   /* See if the spec already exists */
  1129.   for (sl = specs; sl; sl = sl->next)
  1130.     if (strcmp (sl->name, name) == 0)
  1131.       break;
  1132.  
  1133.   if (!sl)
  1134.     {
  1135.       /* Not found - make it */
  1136.       sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
  1137.       sl->name = save_string (name, strlen (name));
  1138.       sl->spec = save_string ("", 0);
  1139.       sl->next = specs;
  1140.       specs = sl;
  1141.     }
  1142.  
  1143.   old_spec = sl->spec;
  1144.   if (name && spec[0] == '+' && isspace (spec[1]))
  1145.     sl->spec = concat (old_spec, spec + 1, "");
  1146.   else
  1147.     sl->spec = save_string (spec, strlen (spec));
  1148.  
  1149.   if (! strcmp (name, "asm"))
  1150.     asm_spec = sl->spec;
  1151.   else if (! strcmp (name, "asm_final"))
  1152.     asm_final_spec = sl->spec;
  1153.   else if (! strcmp (name, "cc1"))
  1154.     cc1_spec = sl->spec;
  1155.   else if (! strcmp (name, "cc1plus"))
  1156.     cc1plus_spec = sl->spec;
  1157.   else if (! strcmp (name, "cpp"))
  1158.     cpp_spec = sl->spec;
  1159.   else if (! strcmp (name, "endfile"))
  1160.     endfile_spec = sl->spec;
  1161.   else if (! strcmp (name, "lib"))
  1162.     lib_spec = sl->spec;
  1163.   else if (! strcmp (name, "link"))
  1164.     link_spec = sl->spec;
  1165.   else if (! strcmp (name, "predefines"))
  1166.     cpp_predefines = sl->spec;
  1167.   else if (! strcmp (name, "signed_char"))
  1168.     signed_char_spec = sl->spec;
  1169.   else if (! strcmp (name, "startfile"))
  1170.     startfile_spec = sl->spec;
  1171.   else if (! strcmp (name, "switches_need_spaces"))
  1172.     switches_need_spaces = sl->spec;
  1173.   else if (! strcmp (name, "cross_compile"))
  1174.     cross_compile = atoi (sl->spec);
  1175.   else if (! strcmp (name, "multilib"))
  1176.     multilib_select = sl->spec;
  1177.   /* Free the old spec */
  1178.   if (old_spec)
  1179.     free (old_spec);
  1180. }
  1181.  
  1182. /* Accumulate a command (program name and args), and run it.  */
  1183.  
  1184. /* Vector of pointers to arguments in the current line of specifications.  */
  1185.  
  1186. static char **argbuf;
  1187.  
  1188. /* Number of elements allocated in argbuf.  */
  1189.  
  1190. static int argbuf_length;
  1191.  
  1192. /* Number of elements in argbuf currently in use (containing args).  */
  1193.  
  1194. static int argbuf_index;
  1195.  
  1196. /* This is the list of suffixes and codes (%g/%u/%U) and the associated
  1197.    temp file.  Used only if MKTEMP_EACH_FILE.  */
  1198.  
  1199. static struct temp_name {
  1200.   char *suffix;        /* suffix associated with the code.  */
  1201.   int length;        /* strlen (suffix).  */
  1202.   int unique;        /* Indicates whether %g or %u/%U was used.  */
  1203.   char *filename;    /* associated filename.  */
  1204.   int filename_length;    /* strlen (filename).  */
  1205.   struct temp_name *next;
  1206. } *temp_names;
  1207.  
  1208. /* Number of commands executed so far.  */
  1209.  
  1210. static int execution_count;
  1211.  
  1212. /* Number of commands that exited with a signal.  */
  1213.  
  1214. static int signal_count;
  1215.  
  1216. /* Name with which this program was invoked.  */
  1217.  
  1218. static char *programname;
  1219.  
  1220. /* Structures to keep track of prefixes to try when looking for files. */
  1221.  
  1222. struct prefix_list
  1223. {
  1224.   char *prefix;               /* String to prepend to the path. */
  1225.   struct prefix_list *next;   /* Next in linked list. */
  1226.   int require_machine_suffix; /* Don't use without machine_suffix.  */
  1227.   /* 2 means try both machine_suffix and just_machine_suffix.  */
  1228.   int *used_flag_ptr;          /* 1 if a file was found with this prefix.  */
  1229. };
  1230.  
  1231. struct path_prefix
  1232. {
  1233.   struct prefix_list *plist;  /* List of prefixes to try */
  1234.   int max_len;                /* Max length of a prefix in PLIST */
  1235.   char *name;                 /* Name of this list (used in config stuff) */
  1236. };
  1237.  
  1238. /* List of prefixes to try when looking for executables. */
  1239.  
  1240. static struct path_prefix exec_prefix = { 0, 0, "exec" };
  1241.  
  1242. /* List of prefixes to try when looking for startup (crt0) files. */
  1243.  
  1244. static struct path_prefix startfile_prefix = { 0, 0, "startfile" };
  1245.  
  1246. /* List of prefixes to try when looking for include files.  */
  1247.  
  1248. static struct path_prefix include_prefix = { 0, 0, "include" };
  1249.  
  1250. /* Suffix to attach to directories searched for commands.
  1251.    This looks like `MACHINE/VERSION/'.  */
  1252.  
  1253. static char *machine_suffix = 0;
  1254.  
  1255. /* Suffix to attach to directories searched for commands.
  1256.    This is just `MACHINE/'.  */
  1257.  
  1258. static char *just_machine_suffix = 0;
  1259.  
  1260. /* Adjusted value of GCC_EXEC_PREFIX envvar.  */
  1261.  
  1262. static char *gcc_exec_prefix;
  1263.  
  1264. /* Default prefixes to attach to command names.  */
  1265.  
  1266. #ifdef CROSS_COMPILE  /* Don't use these prefixes for a cross compiler.  */
  1267. #undef MD_EXEC_PREFIX
  1268. #undef MD_STARTFILE_PREFIX
  1269. #undef MD_STARTFILE_PREFIX_1
  1270. #endif
  1271.  
  1272. #ifndef STANDARD_EXEC_PREFIX
  1273. #define STANDARD_EXEC_PREFIX "/gnu/lib/gcc-lib/"
  1274. #endif /* !defined STANDARD_EXEC_PREFIX */
  1275.  
  1276. static char *standard_exec_prefix = STANDARD_EXEC_PREFIX;
  1277. static char *standard_exec_prefix_1 = "/local/lib/gcc-lib/";
  1278. #ifdef MD_EXEC_PREFIX
  1279. static char *md_exec_prefix = MD_EXEC_PREFIX;
  1280. #endif
  1281.  
  1282. #ifndef STANDARD_STARTFILE_PREFIX
  1283. #define STANDARD_STARTFILE_PREFIX "/gnu/lib/"
  1284. #endif /* !defined STANDARD_STARTFILE_PREFIX */
  1285.  
  1286. #ifdef MD_STARTFILE_PREFIX
  1287. static char *md_startfile_prefix = MD_STARTFILE_PREFIX;
  1288. #endif
  1289. #ifdef MD_STARTFILE_PREFIX_1
  1290. static char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
  1291. #endif
  1292. static char *standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
  1293. static char *standard_startfile_prefix_1 = "/local/lib/";
  1294. static char *standard_startfile_prefix_2 = "/local/lib/";
  1295.  
  1296. #ifndef TOOLDIR_BASE_PREFIX
  1297. #define TOOLDIR_BASE_PREFIX "/local/"
  1298. #endif
  1299. static char *tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
  1300. static char *tooldir_prefix;
  1301.  
  1302. /* Subdirectory to use for locating libraries.  Set by
  1303.    set_multilib_dir based on the compilation options.  */
  1304.  
  1305. static char *multilib_dir;
  1306.  
  1307. /* Clear out the vector of arguments (after a command is executed).  */
  1308.  
  1309. static void
  1310. clear_args ()
  1311. {
  1312.   argbuf_index = 0;
  1313. }
  1314.  
  1315. /* Add one argument to the vector at the end.
  1316.    This is done when a space is seen or at the end of the line.
  1317.    If DELETE_ALWAYS is nonzero, the arg is a filename
  1318.     and the file should be deleted eventually.
  1319.    If DELETE_FAILURE is nonzero, the arg is a filename
  1320.     and the file should be deleted if this compilation fails.  */
  1321.  
  1322. static void
  1323. store_arg (arg, delete_always, delete_failure)
  1324.      char *arg;
  1325.      int delete_always, delete_failure;
  1326. {
  1327.   if (argbuf_index + 1 == argbuf_length)
  1328.     {
  1329.       argbuf = (char **) xrealloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
  1330.     }
  1331.  
  1332.   argbuf[argbuf_index++] = arg;
  1333.   argbuf[argbuf_index] = 0;
  1334.  
  1335.   if (delete_always || delete_failure)
  1336.     record_temp_file (arg, delete_always, delete_failure);
  1337. }
  1338.  
  1339. /* Record the names of temporary files we tell compilers to write,
  1340.    and delete them at the end of the run.  */
  1341.  
  1342. /* This is the common prefix we use to make temp file names.
  1343.    It is chosen once for each run of this program.
  1344.    It is substituted into a spec by %g.
  1345.    Thus, all temp file names contain this prefix.
  1346.    In practice, all temp file names start with this prefix.
  1347.  
  1348.    This prefix comes from the envvar TMPDIR if it is defined;
  1349.    otherwise, from the P_tmpdir macro if that is defined;
  1350.    otherwise, in /usr/tmp or /tmp.  */
  1351.  
  1352. static char *temp_filename;
  1353.  
  1354. /* Length of the prefix.  */
  1355.  
  1356. static int temp_filename_length;
  1357.  
  1358. /* Define the list of temporary files to delete.  */
  1359.  
  1360. struct temp_file
  1361. {
  1362.   char *name;
  1363.   struct temp_file *next;
  1364. };
  1365.  
  1366. /* Queue of files to delete on success or failure of compilation.  */
  1367. static struct temp_file *always_delete_queue;
  1368. /* Queue of files to delete on failure of compilation.  */
  1369. static struct temp_file *failure_delete_queue;
  1370.  
  1371. /* Record FILENAME as a file to be deleted automatically.
  1372.    ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
  1373.    otherwise delete it in any case.
  1374.    FAIL_DELETE nonzero means delete it if a compilation step fails;
  1375.    otherwise delete it in any case.  */
  1376.  
  1377. static void
  1378. record_temp_file (filename, always_delete, fail_delete)
  1379.      char *filename;
  1380.      int always_delete;
  1381.      int fail_delete;
  1382. {
  1383.   register char *name;
  1384.   name = xmalloc (strlen (filename) + 1);
  1385.   strcpy (name, filename);
  1386.  
  1387.   if (always_delete)
  1388.     {
  1389.       register struct temp_file *temp;
  1390.       for (temp = always_delete_queue; temp; temp = temp->next)
  1391.     if (! strcmp (name, temp->name))
  1392.       goto already1;
  1393.       temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
  1394.       temp->next = always_delete_queue;
  1395.       temp->name = name;
  1396.       always_delete_queue = temp;
  1397.     already1:;
  1398.     }
  1399.  
  1400.   if (fail_delete)
  1401.     {
  1402.       register struct temp_file *temp;
  1403.       for (temp = failure_delete_queue; temp; temp = temp->next)
  1404.     if (! strcmp (name, temp->name))
  1405.       goto already2;
  1406.       temp = (struct temp_file *) xmalloc (sizeof (struct temp_file));
  1407.       temp->next = failure_delete_queue;
  1408.       temp->name = name;
  1409.       failure_delete_queue = temp;
  1410.     already2:;
  1411.     }
  1412. }
  1413.  
  1414. /* Delete all the temporary files whose names we previously recorded.  */
  1415.  
  1416. static void
  1417. delete_if_ordinary (name)
  1418.      char *name;
  1419. {
  1420.   struct stat st;
  1421. #ifdef DEBUG
  1422.   int i, c;
  1423.  
  1424.   printf ("Delete %s? (y or n) ", name);
  1425.   fflush (stdout);
  1426.   i = getchar ();
  1427.   if (i != '\n')
  1428.     while ((c = getchar ()) != '\n' && c != EOF) ;
  1429.   if (i == 'y' || i == 'Y')
  1430. #endif /* DEBUG */
  1431.     if (stat (name, &st) >= 0 && S_ISREG (st.st_mode))
  1432.       if (unlink (name) < 0)
  1433.     if (verbose_flag)
  1434.       perror_with_name (name);
  1435. }
  1436.  
  1437. static void
  1438. delete_temp_files ()
  1439. {
  1440.   register struct temp_file *temp;
  1441.  
  1442.   for (temp = always_delete_queue; temp; temp = temp->next)
  1443.     delete_if_ordinary (temp->name);
  1444.   always_delete_queue = 0;
  1445. }
  1446.  
  1447. /* Delete all the files to be deleted on error.  */
  1448.  
  1449. static void
  1450. delete_failure_queue ()
  1451. {
  1452.   register struct temp_file *temp;
  1453.  
  1454.   for (temp = failure_delete_queue; temp; temp = temp->next)
  1455.     delete_if_ordinary (temp->name);
  1456. }
  1457.  
  1458. static void
  1459. clear_failure_queue ()
  1460. {
  1461.   failure_delete_queue = 0;
  1462. }
  1463.  
  1464. /* Compute a string to use as the base of all temporary file names.
  1465.    It is substituted for %g.  */
  1466.  
  1467. static char *
  1468. choose_temp_base_try (try, base)
  1469.      char *try;
  1470.      char *base;
  1471. {
  1472.   char *rv;
  1473.   if (base)
  1474.     rv = base;
  1475.   else if (try == (char *)0)
  1476.     rv = 0;
  1477.   else if (access (try, R_OK | W_OK) != 0)
  1478.     rv = 0;
  1479.   else
  1480.     rv = try;
  1481.   return rv;
  1482. }
  1483.  
  1484. static void
  1485. choose_temp_base ()
  1486. {
  1487.   char *base = 0;
  1488.   int len;
  1489.  
  1490.   base = choose_temp_base_try (getenv ("TMPDIR"), base);
  1491.   base = choose_temp_base_try (getenv ("TMP"), base);
  1492.   base = choose_temp_base_try (getenv ("TEMP"), base);
  1493.  
  1494. #ifdef P_tmpdir
  1495.   base = choose_temp_base_try (P_tmpdir, base);
  1496. #endif
  1497.  
  1498. #ifdef amigados
  1499.   if (!base) /* No env var set */
  1500.     base = "RAM:";
  1501. #else
  1502.   base = choose_temp_base_try ("/usr/tmp", base);
  1503.   base = choose_temp_base_try ("/tmp", base);
  1504. #endif
  1505.  
  1506.   /* If all else fails, use the current directory! */  
  1507.   if (base == (char *)0)
  1508.     base = "./";
  1509.  
  1510.   len = strlen (base);
  1511.   temp_filename = xmalloc (len + sizeof("/ccXXXXXX") + 1);
  1512.   strcpy (temp_filename, base);
  1513.   if (len > 0 && temp_filename[len-1] != '/'
  1514. #ifdef amigados
  1515.                         && temp_filename[len-1] != ':'
  1516. #endif
  1517.                                     )
  1518.     temp_filename[len++] = '/';
  1519.   strcpy (temp_filename + len, "ccXXXXXX");
  1520.  
  1521.   mktemp (temp_filename);
  1522.   temp_filename_length = strlen (temp_filename);
  1523.   if (temp_filename_length == 0)
  1524.     abort ();
  1525. }
  1526.  
  1527.  
  1528. /* Routine to add variables to the environment.  We do this to pass
  1529.    the pathname of the gcc driver, and the directories search to the
  1530.    collect2 program, which is being run as ld.  This way, we can be
  1531.    sure of executing the right compiler when collect2 wants to build
  1532.    constructors and destructors.  Since the environment variables we
  1533.    use come from an obstack, we don't have to worry about allocating
  1534.    space for them.  */
  1535.  
  1536. #ifndef HAVE_PUTENV
  1537.  
  1538. void
  1539. putenv (str)
  1540.      char *str;
  1541. {
  1542. #ifndef VMS            /* nor about VMS */
  1543.  
  1544.   extern char **environ;
  1545.   char **old_environ = environ;
  1546.   char **envp;
  1547.   int num_envs = 0;
  1548.   int name_len = 1;
  1549.   int str_len = strlen (str);
  1550.   char *p = str;
  1551.   int ch;
  1552.  
  1553.   while ((ch = *p++) != '\0' && ch != '=')
  1554.     name_len++;
  1555.  
  1556.   if (!ch)
  1557.     abort ();
  1558.  
  1559.   /* Search for replacing an existing environment variable, and
  1560.      count the number of total environment variables.  */
  1561.   for (envp = old_environ; *envp; envp++)
  1562.     {
  1563.       num_envs++;
  1564.       if (!strncmp (str, *envp, name_len))
  1565.     {
  1566.       *envp = str;
  1567.       return;
  1568.     }
  1569.     }
  1570.  
  1571.   /* Add a new environment variable */
  1572.   environ = (char **) xmalloc (sizeof (char *) * (num_envs+2));
  1573.   *environ = str;
  1574.   bcopy ((char *) old_environ, (char *) (environ + 1),
  1575.      sizeof (char *) * (num_envs+1));
  1576.  
  1577. #endif    /* VMS */
  1578. }
  1579.  
  1580. #endif    /* HAVE_PUTENV */
  1581.  
  1582.  
  1583. /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables for collect.  */
  1584.  
  1585. static void
  1586. putenv_from_prefixes (paths, env_var)
  1587.      struct path_prefix *paths;
  1588.      char *env_var;
  1589. {
  1590.   int suffix_len = (machine_suffix) ? strlen (machine_suffix) : 0;
  1591.   int just_suffix_len
  1592.     = (just_machine_suffix) ? strlen (just_machine_suffix) : 0;
  1593.   int first_time = TRUE;
  1594.   struct prefix_list *pprefix;
  1595.  
  1596.   obstack_grow (&collect_obstack, env_var, strlen (env_var));
  1597.  
  1598.   for (pprefix = paths->plist; pprefix != 0; pprefix = pprefix->next)
  1599.     {
  1600.       int len = strlen (pprefix->prefix);
  1601.  
  1602.       if (machine_suffix
  1603.       && is_directory (pprefix->prefix, machine_suffix, 0))
  1604.     {
  1605.       if (!first_time)
  1606.         obstack_1grow (&collect_obstack, PATH_SEPARATOR);
  1607.         
  1608.       first_time = FALSE;
  1609.       obstack_grow (&collect_obstack, pprefix->prefix, len);
  1610.       obstack_grow (&collect_obstack, machine_suffix, suffix_len);
  1611.     }
  1612.  
  1613.       if (just_machine_suffix
  1614.       && pprefix->require_machine_suffix == 2
  1615.       && is_directory (pprefix->prefix, just_machine_suffix, 0))
  1616.     {
  1617.       if (!first_time)
  1618.         obstack_1grow (&collect_obstack, PATH_SEPARATOR);
  1619.         
  1620.       first_time = FALSE;
  1621.       obstack_grow (&collect_obstack, pprefix->prefix, len);
  1622.       obstack_grow (&collect_obstack, just_machine_suffix,
  1623.             just_suffix_len);
  1624.     }
  1625.  
  1626.       if (!pprefix->require_machine_suffix)
  1627.     {
  1628.       if (!first_time)
  1629.         obstack_1grow (&collect_obstack, PATH_SEPARATOR);
  1630.  
  1631.       first_time = FALSE;
  1632.       obstack_grow (&collect_obstack, pprefix->prefix, len);
  1633.     }
  1634.     }
  1635.   obstack_1grow (&collect_obstack, '\0');
  1636.   putenv (obstack_finish (&collect_obstack));
  1637. }
  1638.  
  1639.  
  1640. /* Search for NAME using the prefix list PREFIXES.  MODE is passed to
  1641.    access to check permissions.
  1642.    Return 0 if not found, otherwise return its name, allocated with malloc. */
  1643.  
  1644. static char *
  1645. find_a_file (pprefix, name, mode)
  1646.      struct path_prefix *pprefix;
  1647.      char *name;
  1648.      int mode;
  1649. {
  1650.   char *temp;
  1651.   char *file_suffix = ((mode & X_OK) != 0 ? EXECUTABLE_SUFFIX : "");
  1652.   struct prefix_list *pl;
  1653.   int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
  1654.  
  1655.   if (machine_suffix)
  1656.     len += strlen (machine_suffix);
  1657.  
  1658.   temp = xmalloc (len);
  1659.  
  1660.   /* Determine the filename to execute (special case for absolute paths).  */
  1661.  
  1662.   if (*name == '/'
  1663. #ifdef amigados
  1664.           || index (name, ':')
  1665. #endif
  1666.                     )
  1667.     {
  1668.       if (access (name, mode))
  1669.     {
  1670.       strcpy (temp, name);
  1671.       return temp;
  1672.     }
  1673.     }
  1674.   else
  1675.     for (pl = pprefix->plist; pl; pl = pl->next)
  1676.       {
  1677.     if (machine_suffix)
  1678.       {
  1679.         /* Some systems have a suffix for executable files.
  1680.            So try appending that first.  */
  1681.         if (file_suffix[0] != 0)
  1682.           {
  1683.         strcpy (temp, pl->prefix);
  1684.         strcat (temp, machine_suffix);
  1685.         strcat (temp, name);
  1686.         strcat (temp, file_suffix);
  1687.         if (access (temp, mode) == 0)
  1688.           {
  1689.             if (pl->used_flag_ptr != 0)
  1690.               *pl->used_flag_ptr = 1;
  1691.             return temp;
  1692.           }
  1693.           }
  1694.  
  1695.         /* Now try just the name.  */
  1696.         strcpy (temp, pl->prefix);
  1697.         strcat (temp, machine_suffix);
  1698.         strcat (temp, name);
  1699.         if (access (temp, mode) == 0)
  1700.           {
  1701.         if (pl->used_flag_ptr != 0)
  1702.           *pl->used_flag_ptr = 1;
  1703.         return temp;
  1704.           }
  1705.       }
  1706.  
  1707.     /* Certain prefixes are tried with just the machine type,
  1708.        not the version.  This is used for finding as, ld, etc.  */
  1709.     if (just_machine_suffix && pl->require_machine_suffix == 2)
  1710.       {
  1711.         /* Some systems have a suffix for executable files.
  1712.            So try appending that first.  */
  1713.         if (file_suffix[0] != 0)
  1714.           {
  1715.         strcpy (temp, pl->prefix);
  1716.         strcat (temp, just_machine_suffix);
  1717.         strcat (temp, name);
  1718.         strcat (temp, file_suffix);
  1719.         if (access (temp, mode) == 0)
  1720.           {
  1721.             if (pl->used_flag_ptr != 0)
  1722.               *pl->used_flag_ptr = 1;
  1723.             return temp;
  1724.           }
  1725.           }
  1726.  
  1727.         strcpy (temp, pl->prefix);
  1728.         strcat (temp, just_machine_suffix);
  1729.         strcat (temp, name);
  1730.         if (access (temp, mode) == 0)
  1731.           {
  1732.         if (pl->used_flag_ptr != 0)
  1733.           *pl->used_flag_ptr = 1;
  1734.         return temp;
  1735.           }
  1736.       }
  1737.  
  1738.     /* Certain prefixes can't be used without the machine suffix
  1739.        when the machine or version is explicitly specified.  */
  1740.     if (!pl->require_machine_suffix)
  1741.       {
  1742.         /* Some systems have a suffix for executable files.
  1743.            So try appending that first.  */
  1744.         if (file_suffix[0] != 0)
  1745.           {
  1746.         strcpy (temp, pl->prefix);
  1747.         strcat (temp, name);
  1748.         strcat (temp, file_suffix);
  1749.         if (access (temp, mode) == 0)
  1750.           {
  1751.             if (pl->used_flag_ptr != 0)
  1752.               *pl->used_flag_ptr = 1;
  1753.             return temp;
  1754.           }
  1755.           }
  1756.  
  1757.         strcpy (temp, pl->prefix);
  1758.         strcat (temp, name);
  1759.         if (access (temp, mode) == 0)
  1760.           {
  1761.         if (pl->used_flag_ptr != 0)
  1762.           *pl->used_flag_ptr = 1;
  1763.         return temp;
  1764.           }
  1765.       }
  1766.       }
  1767.  
  1768.   free (temp);
  1769.   return 0;
  1770. }
  1771.  
  1772. /* Add an entry for PREFIX in PLIST.  If FIRST is set, it goes
  1773.    at the start of the list, otherwise it goes at the end.
  1774.  
  1775.    If WARN is nonzero, we will warn if no file is found
  1776.    through this prefix.  WARN should point to an int
  1777.    which will be set to 1 if this entry is used.
  1778.  
  1779.    REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
  1780.    the complete value of machine_suffix.
  1781.    2 means try both machine_suffix and just_machine_suffix.  */
  1782.  
  1783. static void
  1784. add_prefix (pprefix, prefix, first, require_machine_suffix, warn)
  1785.      struct path_prefix *pprefix;
  1786.      char *prefix;
  1787.      int first;
  1788.      int require_machine_suffix;
  1789.      int *warn;
  1790. {
  1791.   struct prefix_list *pl, **prev;
  1792.   int len;
  1793.  
  1794.   if (!first && pprefix->plist)
  1795.     {
  1796.       for (pl = pprefix->plist; pl->next; pl = pl->next)
  1797.     ;
  1798.       prev = &pl->next;
  1799.     }
  1800.   else
  1801.     prev = &pprefix->plist;
  1802.  
  1803.   /* Keep track of the longest prefix */
  1804.  
  1805.   len = strlen (prefix);
  1806.   if (len > pprefix->max_len)
  1807.     pprefix->max_len = len;
  1808.  
  1809.   pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
  1810.   pl->prefix = save_string (prefix, len);
  1811.   pl->require_machine_suffix = require_machine_suffix;
  1812.   pl->used_flag_ptr = warn;
  1813.   if (warn)
  1814.     *warn = 0;
  1815.  
  1816.   if (*prev)
  1817.     pl->next = *prev;
  1818.   else
  1819.     pl->next = (struct prefix_list *) 0;
  1820.   *prev = pl;
  1821. }
  1822.  
  1823. /* Print warnings for any prefixes in the list PPREFIX that were not used.  */
  1824.  
  1825. static void
  1826. unused_prefix_warnings (pprefix)
  1827.      struct path_prefix *pprefix;
  1828. {
  1829.   struct prefix_list *pl = pprefix->plist;
  1830.  
  1831.   while (pl)
  1832.     {
  1833.       if (pl->used_flag_ptr != 0 && !*pl->used_flag_ptr)
  1834.     {
  1835.       error ("file path prefix `%s' never used",
  1836.          pl->prefix);
  1837.       /* Prevent duplicate warnings.  */
  1838.       *pl->used_flag_ptr = 1;
  1839.     }
  1840.       pl = pl->next;
  1841.     }
  1842. }
  1843.  
  1844. /* Get rid of all prefixes built up so far in *PLISTP. */
  1845.  
  1846. static void
  1847. free_path_prefix (pprefix)
  1848.      struct path_prefix *pprefix;
  1849. {
  1850.   struct prefix_list *pl = pprefix->plist;
  1851.   struct prefix_list *temp;
  1852.  
  1853.   while (pl)
  1854.     {
  1855.       temp = pl;
  1856.       pl = pl->next;
  1857.       free (temp->prefix);
  1858.       free ((char *) temp);
  1859.     }
  1860.   pprefix->plist = (struct prefix_list *) 0;
  1861. }
  1862.  
  1863. /* stdin file number.  */
  1864. #define STDIN_FILE_NO 0
  1865.  
  1866. /* stdout file number.  */
  1867. #define STDOUT_FILE_NO 1
  1868.  
  1869. /* value of `pipe': port index for reading.  */
  1870. #define READ_PORT 0
  1871.  
  1872. /* value of `pipe': port index for writing.  */
  1873. #define WRITE_PORT 1
  1874.  
  1875. /* Pipe waiting from last process, to be used as input for the next one.
  1876.    Value is STDIN_FILE_NO if no pipe is waiting
  1877.    (i.e. the next command is the first of a group).  */
  1878.  
  1879. static int last_pipe_input;
  1880.  
  1881. /* Fork one piped subcommand.  FUNC is the system call to use
  1882.    (either execv or execvp).  ARGV is the arg vector to use.
  1883.    NOT_LAST is nonzero if this is not the last subcommand
  1884.    (i.e. its output should be piped to the next one.)  */
  1885.  
  1886. #ifndef PEXECUTE
  1887. #ifndef OS2
  1888. #ifdef __MSDOS__
  1889.  
  1890. /* Declare these to avoid compilation error.  They won't be called.  */
  1891. int execv(const char *a, const char **b){}
  1892. int execvp(const char *a, const char **b){}
  1893.  
  1894. static int
  1895. pexecute (search_flag, program, argv, not_last)
  1896.      int search_flag;
  1897.      char *program;
  1898.      char *argv[];
  1899.      int not_last;
  1900. {
  1901.   char *scmd, *rf;
  1902.   FILE *argfile;
  1903.   int i, el = search_flag ? 0 : 4;
  1904.  
  1905.   scmd = (char *)malloc (strlen (program) + strlen (temp_filename) + 6 + el);
  1906.   rf = scmd + strlen(program) + 2 + el;
  1907.   sprintf (scmd, "%s%s @%s.gp", program,
  1908.        (search_flag ? "" : ".exe"), temp_filename);
  1909.   argfile = fopen (rf, "w");
  1910.   if (argfile == 0)
  1911.     pfatal_with_name (rf);
  1912.  
  1913.   for (i=1; argv[i]; i++)
  1914.     {
  1915.       char *cp;
  1916.       for (cp = argv[i]; *cp; cp++)
  1917.     {
  1918.       if (*cp == '"' || *cp == '\'' || *cp == '\\' || isspace (*cp))
  1919.         fputc ('\\', argfile);
  1920.       fputc (*cp, argfile);
  1921.     }
  1922.       fputc ('\n', argfile);
  1923.     }
  1924.   fclose (argfile);
  1925.  
  1926.   i = system (scmd);
  1927.  
  1928.   remove (rf);
  1929.   
  1930.   if (i == -1)
  1931.     {
  1932.       perror_exec (program);
  1933.       return MIN_FATAL_STATUS << 8;
  1934.     }
  1935.  
  1936.   return i << 8;
  1937. }
  1938.  
  1939. #else /* not __MSDOS__ */
  1940.  
  1941. static int
  1942. pexecute (search_flag, program, argv, not_last)
  1943.      int search_flag;
  1944.      char *program;
  1945.      char *argv[];
  1946.      int not_last;
  1947. {
  1948.   int (*func)() = (search_flag ? execv : execvp);
  1949.   int pid;
  1950.   int pdes[2];
  1951.   int input_desc = last_pipe_input;
  1952.   int output_desc = STDOUT_FILE_NO;
  1953.   int retries, sleep_interval;
  1954.  
  1955.   /* If this isn't the last process, make a pipe for its output,
  1956.      and record it as waiting to be the input to the next process.  */
  1957.  
  1958.   if (not_last)
  1959.     {
  1960.       if (pipe (pdes) < 0)
  1961.     pfatal_with_name ("pipe");
  1962.       output_desc = pdes[WRITE_PORT];
  1963.       last_pipe_input = pdes[READ_PORT];
  1964.     }
  1965.   else
  1966.     last_pipe_input = STDIN_FILE_NO;
  1967.  
  1968.   /* Fork a subprocess; wait and retry if it fails.  */
  1969.   sleep_interval = 1;
  1970.   for (retries = 0; retries < 4; retries++)
  1971.     {
  1972.       pid = vfork ();
  1973.       if (pid >= 0)
  1974.     break;
  1975.       sleep (sleep_interval);
  1976.       sleep_interval *= 2;
  1977.     }
  1978.  
  1979.   switch (pid)
  1980.     {
  1981.     case -1:
  1982. #ifdef vfork
  1983.       pfatal_with_name ("fork");
  1984. #else
  1985.       pfatal_with_name ("vfork");
  1986. #endif
  1987.       /* NOTREACHED */
  1988.       return 0;
  1989.  
  1990.     case 0: /* child */
  1991.       /* Move the input and output pipes into place, if nec.  */
  1992.       if (input_desc != STDIN_FILE_NO)
  1993.     {
  1994.       close (STDIN_FILE_NO);
  1995.       dup (input_desc);
  1996.       close (input_desc);
  1997.     }
  1998.       if (output_desc != STDOUT_FILE_NO)
  1999.     {
  2000.       close (STDOUT_FILE_NO);
  2001.       dup (output_desc);
  2002.       close (output_desc);
  2003.     }
  2004.  
  2005.       /* Close the parent's descs that aren't wanted here.  */
  2006.       if (last_pipe_input != STDIN_FILE_NO)
  2007.     close (last_pipe_input);
  2008.  
  2009.       /* Exec the program.  */
  2010.       (*func) (program, argv);
  2011.       perror_exec (program);
  2012.       exit (-1);
  2013.       /* NOTREACHED */
  2014.       return 0;
  2015.  
  2016.     default:
  2017.       /* In the parent, after forking.
  2018.      Close the descriptors that we made for this child.  */
  2019.       if (input_desc != STDIN_FILE_NO)
  2020.     close (input_desc);
  2021.       if (output_desc != STDOUT_FILE_NO)
  2022.     close (output_desc);
  2023.  
  2024.       /* Return child's process number.  */
  2025.       return pid;
  2026.     }
  2027. }
  2028.  
  2029. #endif /* not __MSDOS__ */
  2030. #else /* not OS2 */
  2031.  
  2032. static int
  2033. pexecute (search_flag, program, argv, not_last)
  2034.      int search_flag;
  2035.      char *program;
  2036.      char *argv[];
  2037.      int not_last;
  2038. {
  2039.   return (search_flag ? spawnv : spawnvp) (1, program, argv);
  2040. }
  2041. #endif /* not OS2 */
  2042. #endif /* !defined (PEXECUTE) */
  2043.  
  2044. /* Execute the command specified by the arguments on the current line of spec.
  2045.    When using pipes, this includes several piped-together commands
  2046.    with `|' between them.
  2047.  
  2048.    Return 0 if successful, -1 if failed.  */
  2049.  
  2050. static int
  2051. execute ()
  2052. {
  2053.   int i;
  2054.   int n_commands;        /* # of command.  */
  2055.   char *string;
  2056.   struct command
  2057.     {
  2058.       char *prog;        /* program name.  */
  2059.       char **argv;        /* vector of args.  */
  2060.       int pid;            /* pid of process for this command.  */
  2061.     };
  2062.  
  2063.   struct command *commands;    /* each command buffer with above info.  */
  2064.  
  2065.   /* Count # of piped commands.  */
  2066.   for (n_commands = 1, i = 0; i < argbuf_index; i++)
  2067.     if (strcmp (argbuf[i], "|") == 0)
  2068.       n_commands++;
  2069.  
  2070.   /* Get storage for each command.  */
  2071.   commands
  2072.     = (struct command *) alloca (n_commands * sizeof (struct command));
  2073.  
  2074.   /* Split argbuf into its separate piped processes,
  2075.      and record info about each one.
  2076.      Also search for the programs that are to be run.  */
  2077.  
  2078.   commands[0].prog = argbuf[0]; /* first command.  */
  2079.   commands[0].argv = &argbuf[0];
  2080.   string = find_a_file (&exec_prefix, commands[0].prog, X_OK);
  2081.   if (string)
  2082.     commands[0].argv[0] = string;
  2083.  
  2084.   for (n_commands = 1, i = 0; i < argbuf_index; i++)
  2085.     if (strcmp (argbuf[i], "|") == 0)
  2086.       {                /* each command.  */
  2087. #ifdef __MSDOS__
  2088.         fatal ("-pipe not supported under MS-DOS");
  2089. #endif
  2090.     argbuf[i] = 0;    /* termination of command args.  */
  2091.     commands[n_commands].prog = argbuf[i + 1];
  2092.     commands[n_commands].argv = &argbuf[i + 1];
  2093.     string = find_a_file (&exec_prefix, commands[n_commands].prog, X_OK);
  2094.     if (string)
  2095.       commands[n_commands].argv[0] = string;
  2096.     n_commands++;
  2097.       }
  2098.  
  2099.   argbuf[argbuf_index] = 0;
  2100.  
  2101.   /* If -v, print what we are about to do, and maybe query.  */
  2102.  
  2103.   if (verbose_flag)
  2104.     {
  2105.       /* Print each piped command as a separate line.  */
  2106.       for (i = 0; i < n_commands ; i++)
  2107.     {
  2108.       char **j;
  2109.  
  2110.       for (j = commands[i].argv; *j; j++)
  2111.         fprintf (stderr, " %s", *j);
  2112.  
  2113.       /* Print a pipe symbol after all but the last command.  */
  2114.       if (i + 1 != n_commands)
  2115.         fprintf (stderr, " |");
  2116.       fprintf (stderr, "\n");
  2117.     }
  2118.       fflush (stderr);
  2119. #ifdef DEBUG
  2120.       fprintf (stderr, "\nGo ahead? (y or n) ");
  2121.       fflush (stderr);
  2122.       i = getchar ();
  2123.       if (i != '\n')
  2124.     while (getchar () != '\n') ;
  2125.       if (i != 'y' && i != 'Y')
  2126.     return 0;
  2127. #endif /* DEBUG */
  2128.     }
  2129.  
  2130.   /* Run each piped subprocess.  */
  2131.  
  2132.   last_pipe_input = STDIN_FILE_NO;
  2133.   for (i = 0; i < n_commands; i++)
  2134.     {
  2135.       char *string = commands[i].argv[0];
  2136.  
  2137. #ifdef PEXECUTE
  2138.       commands[i].pid = PEXECUTE (string != commands[i].prog,
  2139.                   string, commands[i].argv,
  2140.                   i + 1 < n_commands);
  2141. #else
  2142.       commands[i].pid = pexecute (string != commands[i].prog,
  2143.                   string, commands[i].argv,
  2144.                   i + 1 < n_commands);
  2145. #endif
  2146.  
  2147.       if (string != commands[i].prog)
  2148.     free (string);
  2149.     }
  2150.  
  2151.   execution_count++;
  2152.  
  2153.   /* Wait for all the subprocesses to finish.
  2154.      We don't care what order they finish in;
  2155.      we know that N_COMMANDS waits will get them all.  */
  2156.  
  2157.   {
  2158.     int ret_code = 0;
  2159.  
  2160.     for (i = 0; i < n_commands; i++)
  2161.       {
  2162.     int status;
  2163.     int pid;
  2164.     char *prog = "unknown";
  2165.  
  2166. #ifdef PEXECUTE_RESULT
  2167.     pid = PEXECUTE_RESULT (status, commands[i]);
  2168. #else /* PEXECUTE_RESULT */
  2169. #ifdef __MSDOS__
  2170.         status = pid = commands[i].pid;
  2171. #else
  2172.     pid = wait (&status);
  2173. #endif
  2174. #endif /* PEXECUTE_RESULT */
  2175.     if (pid < 0)
  2176.       abort ();
  2177.  
  2178.     if (status != 0)
  2179.       {
  2180.         int j;
  2181.         for (j = 0; j < n_commands; j++)
  2182.           if (commands[j].pid == pid)
  2183.         prog = commands[j].prog;
  2184.  
  2185.         if ((status & 0x7F) != 0)
  2186.           {
  2187.         fatal ("Internal compiler error: program %s got fatal signal %d",
  2188.                prog, (status & 0x7F));
  2189.         signal_count++;
  2190.           }
  2191.         if (((status & 0xFF00) >> 8) >= MIN_FATAL_STATUS)
  2192.           ret_code = -1;
  2193.       }
  2194.       }
  2195.     return ret_code;
  2196.   }
  2197. }
  2198.  
  2199. /* Find all the switches given to us
  2200.    and make a vector describing them.
  2201.    The elements of the vector are strings, one per switch given.
  2202.    If a switch uses following arguments, then the `part1' field
  2203.    is the switch itself and the `args' field
  2204.    is a null-terminated vector containing the following arguments.
  2205.    The `live_cond' field is 1 if the switch is true in a conditional spec,
  2206.    -1 if false (overridden by a later switch), and is initialized to zero.
  2207.    The `valid' field is nonzero if any spec has looked at this switch;
  2208.    if it remains zero at the end of the run, it must be meaningless.  */
  2209.  
  2210. struct switchstr
  2211. {
  2212.   char *part1;
  2213.   char **args;
  2214.   int live_cond;
  2215.   int valid;
  2216. };
  2217.  
  2218. static struct switchstr *switches;
  2219.  
  2220. static int n_switches;
  2221.  
  2222. struct infile
  2223. {
  2224.   char *name;
  2225.   char *language;
  2226. };
  2227.  
  2228. /* Also a vector of input files specified.  */
  2229.  
  2230. static struct infile *infiles;
  2231.  
  2232. static int n_infiles;
  2233.  
  2234. /* And a vector of corresponding output files is made up later.  */
  2235.  
  2236. static char **outfiles;
  2237.  
  2238. /* Create the vector `switches' and its contents.
  2239.    Store its length in `n_switches'.  */
  2240.  
  2241. static void
  2242. process_command (argc, argv)
  2243.      int argc;
  2244.      char **argv;
  2245. {
  2246.   register int i;
  2247.   char *temp;
  2248.   char *spec_lang = 0;
  2249.   int last_language_n_infiles;
  2250.  
  2251.   gcc_exec_prefix = getenv ("GCC_EXEC_PREFIX");
  2252.  
  2253.   n_switches = 0;
  2254.   n_infiles = 0;
  2255.  
  2256.   /* Figure compiler version from version string.  */
  2257.  
  2258.   compiler_version = save_string (version_string, strlen (version_string));
  2259.   for (temp = compiler_version; *temp; ++temp)
  2260.     {
  2261.       if (*temp == ' ')
  2262.     {
  2263.       *temp = '\0';
  2264.       break;
  2265.     }
  2266.     }
  2267.  
  2268.   /* Set up the default search paths.  */
  2269.  
  2270.   if (gcc_exec_prefix)
  2271.     {
  2272.       add_prefix (&exec_prefix, gcc_exec_prefix, 0, 0, NULL_PTR);
  2273.       add_prefix (&startfile_prefix, gcc_exec_prefix, 0, 0, NULL_PTR);
  2274.     }
  2275.  
  2276.   /* COMPILER_PATH and LIBRARY_PATH have values
  2277.      that are lists of directory names with colons.  */
  2278.  
  2279.   temp = getenv ("COMPILER_PATH");
  2280.   if (temp)
  2281.     {
  2282.       char *startp, *endp;
  2283.       char *nstore = (char *) alloca (strlen (temp) + 3);
  2284.  
  2285.       startp = endp = temp;
  2286.       while (1)
  2287.     {
  2288.       if (*endp == PATH_SEPARATOR || *endp == 0)
  2289.         {
  2290.           strncpy (nstore, startp, endp-startp);
  2291. #ifndef amigados
  2292.           if (endp == startp)
  2293.         {
  2294.           strcpy (nstore, "./");
  2295.         }
  2296.           else if (endp[-1] != '/')
  2297.         {
  2298.           nstore[endp-startp] = '/';
  2299.           nstore[endp-startp+1] = 0;
  2300.         }
  2301.           else
  2302.         nstore[endp-startp] = 0;
  2303. #else
  2304.           if (endp[-1] != '/' && endp[-1] != ':')
  2305.         {
  2306.           nstore[endp-startp] = '/';
  2307.           nstore[endp-startp+1] = 0;
  2308.         }
  2309.           else
  2310.         nstore[endp-startp] = 0;
  2311. #endif
  2312.           add_prefix (&exec_prefix, nstore, 0, 0, NULL_PTR);
  2313.           if (*endp == 0)
  2314.         break;
  2315.           endp = startp = endp + 1;
  2316.         }
  2317.       else
  2318.         endp++;
  2319.     }
  2320.     }
  2321.  
  2322.   temp = getenv ("LIBRARY_PATH");
  2323.   if (temp)
  2324.     {
  2325.       char *startp, *endp;
  2326.       char *nstore = (char *) alloca (strlen (temp) + 3);
  2327.  
  2328.       startp = endp = temp;
  2329.       while (1)
  2330.     {
  2331.       if (*endp == PATH_SEPARATOR || *endp == 0)
  2332.         {
  2333.           strncpy (nstore, startp, endp-startp);
  2334. #ifndef amigados
  2335.           if (endp == startp)
  2336.         {
  2337.           strcpy (nstore, "./");
  2338.         }
  2339.           else if (endp[-1] != '/')
  2340.         {
  2341.           nstore[endp-startp] = '/';
  2342.           nstore[endp-startp+1] = 0;
  2343.         }
  2344.           else
  2345.         nstore[endp-startp] = 0;
  2346. #else
  2347.           if (endp[-1] != '/' && endp[-1] != ':')
  2348.         {
  2349.           nstore[endp-startp] = '/';
  2350.           nstore[endp-startp+1] = 0;
  2351.         }
  2352.           else
  2353.         nstore[endp-startp] = 0;
  2354. #endif
  2355.           add_prefix (&startfile_prefix, nstore, 0, 0, NULL_PTR);
  2356.           if (*endp == 0)
  2357.         break;
  2358.           endp = startp = endp + 1;
  2359.         }
  2360.       else
  2361.         endp++;
  2362.     }
  2363.     }
  2364.  
  2365.   /* Use LPATH like LIBRARY_PATH (for the CMU build program).  */
  2366.   temp = getenv ("LPATH");
  2367.   if (temp)
  2368.     {
  2369.       char *startp, *endp;
  2370.       char *nstore = (char *) alloca (strlen (temp) + 3);
  2371.  
  2372.       startp = endp = temp;
  2373.       while (1)
  2374.     {
  2375.       if (*endp == PATH_SEPARATOR || *endp == 0)
  2376.         {
  2377.           strncpy (nstore, startp, endp-startp);
  2378. #ifndef amigados
  2379.           if (endp == startp)
  2380.         {
  2381.           strcpy (nstore, "./");
  2382.         }
  2383.           else if (endp[-1] != '/')
  2384.         {
  2385.           nstore[endp-startp] = '/';
  2386.           nstore[endp-startp+1] = 0;
  2387.         }
  2388.           else
  2389.         nstore[endp-startp] = 0;
  2390. #else
  2391.           if (endp[-1] != '/' && endp[-1] != ':')
  2392.         {
  2393.           nstore[endp-startp] = '/';
  2394.           nstore[endp-startp+1] = 0;
  2395.         }
  2396.           else
  2397.         nstore[endp-startp] = 0;
  2398. #endif
  2399.           add_prefix (&startfile_prefix, nstore, 0, 0, NULL_PTR);
  2400.           if (*endp == 0)
  2401.         break;
  2402.           endp = startp = endp + 1;
  2403.         }
  2404.       else
  2405.         endp++;
  2406.     }
  2407.     }
  2408.  
  2409.   /* Convert new-style -- options to old-style.  */
  2410.   translate_options (&argc, &argv);
  2411.  
  2412.   /* Scan argv twice.  Here, the first time, just count how many switches
  2413.      there will be in their vector, and how many input files in theirs.
  2414.      Here we also parse the switches that cc itself uses (e.g. -v).  */
  2415.  
  2416.   for (i = 1; i < argc; i++)
  2417.     {
  2418.       if (! strcmp (argv[i], "-dumpspecs"))
  2419.     {
  2420.       printf ("*asm:\n%s\n\n", asm_spec);
  2421.       printf ("*asm_final:\n%s\n\n", asm_final_spec);
  2422.       printf ("*cpp:\n%s\n\n", cpp_spec);
  2423.       printf ("*cc1:\n%s\n\n", cc1_spec);
  2424.       printf ("*cc1plus:\n%s\n\n", cc1plus_spec);
  2425.       printf ("*endfile:\n%s\n\n", endfile_spec);
  2426.       printf ("*link:\n%s\n\n", link_spec);
  2427.       printf ("*lib:\n%s\n\n", lib_spec);
  2428.       printf ("*startfile:\n%s\n\n", startfile_spec);
  2429.       printf ("*switches_need_spaces:\n%s\n\n", switches_need_spaces);
  2430.       printf ("*signed_char:\n%s\n\n", signed_char_spec);
  2431.       printf ("*predefines:\n%s\n\n", cpp_predefines);
  2432.       printf ("*cross_compile:\n%d\n\n", cross_compile);
  2433.       printf ("*multilib:\n%s\n\n", multilib_select);
  2434.  
  2435.       exit (0);
  2436.     }
  2437.       else if (! strcmp (argv[i], "-dumpversion"))
  2438.     {
  2439.       printf ("%s\n", version_string);
  2440.       exit (0);
  2441.     }
  2442.       else if (! strcmp (argv[i], "-print-libgcc-file-name"))
  2443.       print_file_name = "libgcc.a";
  2444.       else if (! strncmp (argv[i], "-print-file-name=", 17))
  2445.       print_file_name = argv[i] + 17;
  2446.       else if (! strncmp (argv[i], "-print-prog-name=", 17))
  2447.       print_prog_name = argv[i] + 17;
  2448.       else if (! strcmp (argv[i], "-print-multi-lib"))
  2449.     print_multi_lib = 1;
  2450.       else if (! strcmp (argv[i], "-print-multi-directory"))
  2451.     print_multi_directory = 1;
  2452.       else if (! strcmp (argv[i], "-Xlinker"))
  2453.     {
  2454.       /* Pass the argument of this option to the linker when we link.  */
  2455.  
  2456.       if (i + 1 == argc)
  2457.         fatal ("argument to `-Xlinker' is missing");
  2458.  
  2459.       n_linker_options++;
  2460.       if (!linker_options)
  2461.         linker_options
  2462.           = (char **) xmalloc (n_linker_options * sizeof (char **));
  2463.       else
  2464.         linker_options
  2465.           = (char **) xrealloc (linker_options,
  2466.                     n_linker_options * sizeof (char **));
  2467.  
  2468.       linker_options[n_linker_options - 1] = argv[++i];
  2469.     }
  2470.       else if (! strncmp (argv[i], "-Wl,", 4))
  2471.     {
  2472.       int prev, j;
  2473.       /* Pass the rest of this option to the linker when we link.  */
  2474.  
  2475.       n_linker_options++;
  2476.       if (!linker_options)
  2477.         linker_options
  2478.           = (char **) xmalloc (n_linker_options * sizeof (char **));
  2479.       else
  2480.         linker_options
  2481.           = (char **) xrealloc (linker_options,
  2482.                     n_linker_options * sizeof (char **));
  2483.  
  2484.       /* Split the argument at commas.  */
  2485.       prev = 4;
  2486.       for (j = 4; argv[i][j]; j++)
  2487.         if (argv[i][j] == ',')
  2488.           {
  2489.         linker_options[n_linker_options - 1]
  2490.           = save_string (argv[i] + prev, j - prev);
  2491.         n_linker_options++;
  2492.         linker_options
  2493.           = (char **) xrealloc (linker_options,
  2494.                     n_linker_options * sizeof (char **));
  2495.         prev = j + 1;
  2496.           }
  2497.       /* Record the part after the last comma.  */
  2498.       linker_options[n_linker_options - 1] = argv[i] + prev;
  2499.     }
  2500.       else if (! strncmp (argv[i], "-Wa,", 4))
  2501.     {
  2502.       int prev, j;
  2503.       /* Pass the rest of this option to the assembler.  */
  2504.  
  2505.       n_assembler_options++;
  2506.       if (!assembler_options)
  2507.         assembler_options
  2508.           = (char **) xmalloc (n_assembler_options * sizeof (char **));
  2509.       else
  2510.         assembler_options
  2511.           = (char **) xrealloc (assembler_options,
  2512.                     n_assembler_options * sizeof (char **));
  2513.  
  2514.       /* Split the argument at commas.  */
  2515.       prev = 4;
  2516.       for (j = 4; argv[i][j]; j++)
  2517.         if (argv[i][j] == ',')
  2518.           {
  2519.         assembler_options[n_assembler_options - 1]
  2520.           = save_string (argv[i] + prev, j - prev);
  2521.         n_assembler_options++;
  2522.         assembler_options
  2523.           = (char **) xrealloc (assembler_options,
  2524.                     n_assembler_options * sizeof (char **));
  2525.         prev = j + 1;
  2526.           }
  2527.       /* Record the part after the last comma.  */
  2528.       assembler_options[n_assembler_options - 1] = argv[i] + prev;
  2529.     }
  2530.       else if (argv[i][0] == '+' && argv[i][1] == 'e')
  2531.     /* The +e options to the C++ front-end.  */
  2532.     n_switches++;
  2533.       else if (argv[i][0] == '-' && argv[i][1] != 0 && argv[i][1] != 'l')
  2534.     {
  2535.       register char *p = &argv[i][1];
  2536.       register int c = *p;
  2537.  
  2538.       switch (c)
  2539.         {
  2540.         case 'b':
  2541.           if (p[1] == 0 && i + 1 == argc)
  2542.         fatal ("argument to `-b' is missing");
  2543.           if (p[1] == 0)
  2544.         spec_machine = argv[++i];
  2545.           else
  2546.         spec_machine = p + 1;
  2547.           break;
  2548.  
  2549.         case 'B':
  2550.           {
  2551.         int *temp = (int *) xmalloc (sizeof (int));
  2552.         char *value;
  2553.         if (p[1] == 0 && i + 1 == argc)
  2554.           fatal ("argument to `-B' is missing");
  2555.         if (p[1] == 0)
  2556.           value = argv[++i];
  2557.         else
  2558.           value = p + 1;
  2559.         add_prefix (&exec_prefix, value, 1, 0, temp);
  2560.         add_prefix (&startfile_prefix, value, 1, 0, temp);
  2561.         add_prefix (&include_prefix, concat (value, "include", ""),
  2562.                 1, 0, 0);
  2563.  
  2564.         /* As a kludge, if the arg is "[foo/]stageN/", just add
  2565.            "[foo/]stageN/../include" to the include prefix.  */
  2566.         {
  2567.           int len = strlen (value);
  2568.           if ((len == 7 || (len > 7 && value[len - 8] == '/'))
  2569.               && strncmp (value + len - 7, "stage", 5) == 0
  2570.               && isdigit (value[len - 2])
  2571.               && value[len - 1] == '/')
  2572.             add_prefix (&include_prefix,
  2573.                 concat (value, "../include", ""), 1, 0, 0);
  2574.         }
  2575.           }
  2576.           break;
  2577.  
  2578.         case 'v':    /* Print our subcommands and print versions.  */
  2579.           n_switches++;
  2580.           /* If they do anything other than exactly `-v', don't set
  2581.          verbose_flag; rather, continue on to give the error.  */
  2582.           if (p[1] != 0)
  2583.         break;
  2584.           verbose_flag++;
  2585.           break;
  2586.  
  2587.         case 'V':
  2588.           if (p[1] == 0 && i + 1 == argc)
  2589.         fatal ("argument to `-V' is missing");
  2590.           if (p[1] == 0)
  2591.         spec_version = argv[++i];
  2592.           else
  2593.         spec_version = p + 1;
  2594.           compiler_version = spec_version;
  2595.           break;
  2596.  
  2597.         case 's':
  2598.           if (!strcmp (p, "save-temps"))
  2599.         {
  2600.           save_temps_flag = 1;
  2601.           n_switches++;
  2602.           break;
  2603.         }
  2604.         default:
  2605.           n_switches++;
  2606.  
  2607.           if (SWITCH_TAKES_ARG (c) > (p[1] != 0))
  2608.         i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
  2609.           else if (WORD_SWITCH_TAKES_ARG (p))
  2610.         i += WORD_SWITCH_TAKES_ARG (p);
  2611.         }
  2612.     }
  2613.       else
  2614.     n_infiles++;
  2615.     }
  2616.  
  2617.   /* Set up the search paths before we go looking for config files.  */
  2618.  
  2619.   /* These come before the md prefixes so that we will find gcc's subcommands
  2620.      (such as cpp) rather than those of the host system.  */
  2621.   /* Use 2 as fourth arg meaning try just the machine as a suffix,
  2622.      as well as trying the machine and the version.  */
  2623.   add_prefix (&exec_prefix, standard_exec_prefix, 0, 2, NULL_PTR);
  2624.   add_prefix (&exec_prefix, standard_exec_prefix_1, 0, 2, NULL_PTR);
  2625.  
  2626.   add_prefix (&startfile_prefix, standard_exec_prefix, 0, 1, NULL_PTR);
  2627.   add_prefix (&startfile_prefix, standard_exec_prefix_1, 0, 1, NULL_PTR);
  2628.  
  2629.   tooldir_prefix = concat (tooldir_base_prefix, spec_machine, "/");
  2630.  
  2631.   /* If tooldir is relative, base it on exec_prefix.  A relative
  2632.      tooldir lets us move the installed tree as a unit.
  2633.  
  2634.      If GCC_EXEC_PREFIX is defined, then we want to add two relative
  2635.      directories, so that we can search both the user specified directory
  2636.      and the standard place.  */
  2637.  
  2638.   if (*tooldir_prefix != '/')
  2639.     {
  2640.       if (gcc_exec_prefix)
  2641.     {
  2642.       char *gcc_exec_tooldir_prefix
  2643.         = concat (concat (gcc_exec_prefix, spec_machine, "/"),
  2644.               concat (spec_version, "/", tooldir_prefix),
  2645.               "");
  2646.  
  2647.       add_prefix (&exec_prefix, concat (gcc_exec_tooldir_prefix, "bin", "/"),
  2648.               0, 0, NULL_PTR);
  2649.       add_prefix (&startfile_prefix, concat (gcc_exec_tooldir_prefix, "lib", "/"),
  2650.               0, 0, NULL_PTR);
  2651.     }
  2652.  
  2653.       tooldir_prefix = concat (concat (standard_exec_prefix, spec_machine, "/"),
  2654.                    concat (spec_version, "/", tooldir_prefix),
  2655.                    "");
  2656.     }
  2657.  
  2658.   add_prefix (&exec_prefix, concat (tooldir_prefix, "bin", "/"),
  2659.           0, 0, NULL_PTR);
  2660.   add_prefix (&startfile_prefix, concat (tooldir_prefix, "lib", "/"),
  2661.           0, 0, NULL_PTR);
  2662.  
  2663.   /* More prefixes are enabled in main, after we read the specs file
  2664.      and determine whether this is cross-compilation or not.  */
  2665.  
  2666.  
  2667.   /* Then create the space for the vectors and scan again.  */
  2668.  
  2669.   switches = ((struct switchstr *)
  2670.           xmalloc ((n_switches + 1) * sizeof (struct switchstr)));
  2671.   infiles = (struct infile *) xmalloc ((n_infiles + 1) * sizeof (struct infile));
  2672.   n_switches = 0;
  2673.   n_infiles = 0;
  2674.   last_language_n_infiles = -1;
  2675.  
  2676.   /* This, time, copy the text of each switch and store a pointer
  2677.      to the copy in the vector of switches.
  2678.      Store all the infiles in their vector.  */
  2679.  
  2680.   for (i = 1; i < argc; i++)
  2681.     {
  2682.       /* Just skip the switches that were handled by the preceding loop.  */
  2683.       if (!strcmp (argv[i], "-Xlinker"))
  2684.     i++;
  2685.       else if (! strncmp (argv[i], "-Wl,", 4))
  2686.     ;
  2687.       else if (! strncmp (argv[i], "-Wa,", 4))
  2688.     ;
  2689.       else if (! strcmp (argv[i], "-print-libgcc-file-name"))
  2690.     ;
  2691.       else if (! strncmp (argv[i], "-print-file-name=", 17))
  2692.     ;
  2693.       else if (! strncmp (argv[i], "-print-prog-name=", 17))
  2694.     ;
  2695.       else if (! strcmp (argv[i], "-print-multi-lib"))
  2696.     ;
  2697.       else if (! strcmp (argv[i], "-print-multi-directory"))
  2698.     ;
  2699.       else if (argv[i][0] == '+' && argv[i][1] == 'e')
  2700.     {
  2701.       /* Compensate for the +e options to the C++ front-end;
  2702.          they're there simply for cfront call-compatibility.  We do
  2703.          some magic in default_compilers to pass them down properly.
  2704.          Note we deliberately start at the `+' here, to avoid passing
  2705.          -e0 or -e1 down into the linker.  */
  2706.       switches[n_switches].part1 = &argv[i][0];
  2707.       switches[n_switches].args = 0;
  2708.       switches[n_switches].live_cond = 0;
  2709.       switches[n_switches].valid = 0;
  2710.       n_switches++;
  2711.     }
  2712.       else if (argv[i][0] == '-' && argv[i][1] != 0 && argv[i][1] != 'l')
  2713.     {
  2714.       register char *p = &argv[i][1];
  2715.       register int c = *p;
  2716.  
  2717.       if (c == 'B' || c == 'b' || c == 'V')
  2718.         {
  2719.           /* Skip a separate arg, if any.  */
  2720.           if (p[1] == 0)
  2721.         i++;
  2722.           continue;
  2723.         }
  2724.       if (c == 'x')
  2725.         {
  2726.           if (p[1] == 0 && i + 1 == argc)
  2727.         fatal ("argument to `-x' is missing");
  2728.           if (p[1] == 0)
  2729.         spec_lang = argv[++i];
  2730.           else
  2731.         spec_lang = p + 1;
  2732.           if (! strcmp (spec_lang, "none"))
  2733.         /* Suppress the warning if -xnone comes after the last input file,
  2734.            because alternate command interfaces like g++ might find it
  2735.            useful to place -xnone after each input file.  */
  2736.         spec_lang = 0;
  2737.           else
  2738.         last_language_n_infiles = n_infiles;
  2739.           continue;
  2740.         }
  2741.       switches[n_switches].part1 = p;
  2742.       /* Deal with option arguments in separate argv elements.  */
  2743.       if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
  2744.           || WORD_SWITCH_TAKES_ARG (p))
  2745.         {
  2746.           int j = 0;
  2747.           int n_args = WORD_SWITCH_TAKES_ARG (p);
  2748.  
  2749.           if (n_args == 0)
  2750.         {
  2751.           /* Count only the option arguments in separate argv elements.  */
  2752.           n_args = SWITCH_TAKES_ARG (c) - (p[1] != 0);
  2753.         }
  2754.           if (i + n_args >= argc)
  2755.         fatal ("argument to `-%s' is missing", p);
  2756.           switches[n_switches].args
  2757.         = (char **) xmalloc ((n_args + 1) * sizeof (char *));
  2758.           while (j < n_args)
  2759.         switches[n_switches].args[j++] = argv[++i];
  2760.           /* Null-terminate the vector.  */
  2761.           switches[n_switches].args[j] = 0;
  2762.         }
  2763.       else if (*switches_need_spaces != 0 && (c == 'o' || c == 'L'))
  2764.         {
  2765.           /* On some systems, ld cannot handle -o or -L without space.
  2766.          So split the -o or -L from its argument.  */
  2767.           switches[n_switches].part1 = (c == 'o' ? "o" : "L");
  2768.           switches[n_switches].args = (char **) xmalloc (2 * sizeof (char *));
  2769.           switches[n_switches].args[0] = xmalloc (strlen (p));
  2770.           strcpy (switches[n_switches].args[0], &p[1]);
  2771.           switches[n_switches].args[1] = 0;
  2772.         }
  2773.       else
  2774.         switches[n_switches].args = 0;
  2775.  
  2776.       switches[n_switches].live_cond = 0;
  2777.       switches[n_switches].valid = 0;
  2778.       /* This is always valid, since gcc.c itself understands it.  */
  2779.       if (!strcmp (p, "save-temps"))
  2780.         switches[n_switches].valid = 1;
  2781.       n_switches++;
  2782.     }
  2783.       else
  2784.     {
  2785.       if ((argv[i][0] != '-' || argv[i][1] != 'l')
  2786.           && strcmp (argv[i], "-")
  2787.           && access (argv[i], R_OK) < 0)
  2788.         {
  2789.           perror_with_name (argv[i]);
  2790.           error_count++;
  2791.         }
  2792.       else
  2793.         {
  2794.           infiles[n_infiles].language = spec_lang;
  2795.           infiles[n_infiles++].name = argv[i];
  2796.         }
  2797.     }
  2798.     }
  2799.  
  2800.   if (n_infiles == last_language_n_infiles && spec_lang != 0)
  2801.     error ("Warning: `-x %s' after last input file has no effect", spec_lang);
  2802.  
  2803.   switches[n_switches].part1 = 0;
  2804.   infiles[n_infiles].name = 0;
  2805.  
  2806.   /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake.  */
  2807.   if (gcc_exec_prefix)
  2808.     {
  2809.       temp = (char *) xmalloc (strlen (gcc_exec_prefix) + strlen (spec_version)
  2810.                    + strlen (spec_machine) + 3);
  2811.       strcpy (temp, gcc_exec_prefix);
  2812.       strcat (temp, spec_machine);
  2813.       strcat (temp, "/");
  2814.       strcat (temp, spec_version);
  2815.       strcat (temp, "/");
  2816.       gcc_exec_prefix = temp;
  2817.     }
  2818. }
  2819.  
  2820. /* Process a spec string, accumulating and running commands.  */
  2821.  
  2822. /* These variables describe the input file name.
  2823.    input_file_number is the index on outfiles of this file,
  2824.    so that the output file name can be stored for later use by %o.
  2825.    input_basename is the start of the part of the input file
  2826.    sans all directory names, and basename_length is the number
  2827.    of characters starting there excluding the suffix .c or whatever.  */
  2828.  
  2829. static char *input_filename;
  2830. static int input_file_number;
  2831. static int input_filename_length;
  2832. static int basename_length;
  2833. static char *input_basename;
  2834. static char *input_suffix;
  2835.  
  2836. /* These are variables used within do_spec and do_spec_1.  */
  2837.  
  2838. /* Nonzero if an arg has been started and not yet terminated
  2839.    (with space, tab or newline).  */
  2840. static int arg_going;
  2841.  
  2842. /* Nonzero means %d or %g has been seen; the next arg to be terminated
  2843.    is a temporary file name.  */
  2844. static int delete_this_arg;
  2845.  
  2846. /* Nonzero means %w has been seen; the next arg to be terminated
  2847.    is the output file name of this compilation.  */
  2848. static int this_is_output_file;
  2849.  
  2850. /* Nonzero means %s has been seen; the next arg to be terminated
  2851.    is the name of a library file and we should try the standard
  2852.    search dirs for it.  */
  2853. static int this_is_library_file;
  2854.  
  2855. /* Nonzero means that the input of this command is coming from a pipe.  */
  2856. static int input_from_pipe;
  2857.  
  2858. /* Process the spec SPEC and run the commands specified therein.
  2859.    Returns 0 if the spec is successfully processed; -1 if failed.  */
  2860.  
  2861. static int
  2862. do_spec (spec)
  2863.      char *spec;
  2864. {
  2865.   int value;
  2866.  
  2867.   clear_args ();
  2868.   arg_going = 0;
  2869.   delete_this_arg = 0;
  2870.   this_is_output_file = 0;
  2871.   this_is_library_file = 0;
  2872.   input_from_pipe = 0;
  2873.  
  2874.   value = do_spec_1 (spec, 0, NULL_PTR);
  2875.  
  2876.   /* Force out any unfinished command.
  2877.      If -pipe, this forces out the last command if it ended in `|'.  */
  2878.   if (value == 0)
  2879.     {
  2880.       if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
  2881.     argbuf_index--;
  2882.  
  2883.       if (argbuf_index > 0)
  2884.     value = execute ();
  2885.     }
  2886.  
  2887.   return value;
  2888. }
  2889.  
  2890. /* Process the sub-spec SPEC as a portion of a larger spec.
  2891.    This is like processing a whole spec except that we do
  2892.    not initialize at the beginning and we do not supply a
  2893.    newline by default at the end.
  2894.    INSWITCH nonzero means don't process %-sequences in SPEC;
  2895.    in this case, % is treated as an ordinary character.
  2896.    This is used while substituting switches.
  2897.    INSWITCH nonzero also causes SPC not to terminate an argument.
  2898.  
  2899.    Value is zero unless a line was finished
  2900.    and the command on that line reported an error.  */
  2901.  
  2902. static int
  2903. do_spec_1 (spec, inswitch, soft_matched_part)
  2904.      char *spec;
  2905.      int inswitch;
  2906.      char *soft_matched_part;
  2907. {
  2908.   register char *p = spec;
  2909.   register int c;
  2910.   int i;
  2911.   char *string;
  2912.   int value;
  2913.  
  2914.   while (c = *p++)
  2915.     /* If substituting a switch, treat all chars like letters.
  2916.        Otherwise, NL, SPC, TAB and % are special.  */
  2917.     switch (inswitch ? 'a' : c)
  2918.       {
  2919.       case '\n':
  2920.     /* End of line: finish any pending argument,
  2921.        then run the pending command if one has been started.  */
  2922.     if (arg_going)
  2923.       {
  2924.         obstack_1grow (&obstack, 0);
  2925.         string = obstack_finish (&obstack);
  2926.         if (this_is_library_file)
  2927.           string = find_file (string);
  2928.         store_arg (string, delete_this_arg, this_is_output_file);
  2929.         if (this_is_output_file)
  2930.           outfiles[input_file_number] = string;
  2931.       }
  2932.     arg_going = 0;
  2933.  
  2934.     if (argbuf_index > 0 && !strcmp (argbuf[argbuf_index - 1], "|"))
  2935.       {
  2936.         int i;
  2937.         for (i = 0; i < n_switches; i++)
  2938.           if (!strcmp (switches[i].part1, "pipe"))
  2939.         break;
  2940.  
  2941.         /* A `|' before the newline means use a pipe here,
  2942.            but only if -pipe was specified.
  2943.            Otherwise, execute now and don't pass the `|' as an arg.  */
  2944.         if (i < n_switches)
  2945.           {
  2946.         input_from_pipe = 1;
  2947.         switches[i].valid = 1;
  2948.         break;
  2949.           }
  2950.         else
  2951.           argbuf_index--;
  2952.       }
  2953.  
  2954.     if (argbuf_index > 0)
  2955.       {
  2956.         value = execute ();
  2957.         if (value)
  2958.           return value;
  2959.       }
  2960.     /* Reinitialize for a new command, and for a new argument.  */
  2961.     clear_args ();
  2962.     arg_going = 0;
  2963.     delete_this_arg = 0;
  2964.     this_is_output_file = 0;
  2965.     this_is_library_file = 0;
  2966.     input_from_pipe = 0;
  2967.     break;
  2968.  
  2969.       case '|':
  2970.     /* End any pending argument.  */
  2971.     if (arg_going)
  2972.       {
  2973.         obstack_1grow (&obstack, 0);
  2974.         string = obstack_finish (&obstack);
  2975.         if (this_is_library_file)
  2976.           string = find_file (string);
  2977.         store_arg (string, delete_this_arg, this_is_output_file);
  2978.         if (this_is_output_file)
  2979.           outfiles[input_file_number] = string;
  2980.       }
  2981.  
  2982.     /* Use pipe */
  2983.     obstack_1grow (&obstack, c);
  2984.     arg_going = 1;
  2985.     break;
  2986.  
  2987.       case '\t':
  2988.       case ' ':
  2989.     /* Space or tab ends an argument if one is pending.  */
  2990.     if (arg_going)
  2991.       {
  2992.         obstack_1grow (&obstack, 0);
  2993.         string = obstack_finish (&obstack);
  2994.         if (this_is_library_file)
  2995.           string = find_file (string);
  2996.         store_arg (string, delete_this_arg, this_is_output_file);
  2997.         if (this_is_output_file)
  2998.           outfiles[input_file_number] = string;
  2999.       }
  3000.     /* Reinitialize for a new argument.  */
  3001.     arg_going = 0;
  3002.     delete_this_arg = 0;
  3003.     this_is_output_file = 0;
  3004.     this_is_library_file = 0;
  3005.     break;
  3006.  
  3007.       case '%':
  3008.     switch (c = *p++)
  3009.       {
  3010.       case 0:
  3011.         fatal ("Invalid specification!  Bug in cc.");
  3012.  
  3013.       case 'b':
  3014.         obstack_grow (&obstack, input_basename, basename_length);
  3015.         arg_going = 1;
  3016.         break;
  3017.  
  3018.       case 'd':
  3019.         delete_this_arg = 2;
  3020.         break;
  3021.  
  3022.       /* Dump out the directories specified with LIBRARY_PATH,
  3023.          followed by the absolute directories
  3024.          that we search for startfiles.  */
  3025.       case 'D':
  3026.         {
  3027.           struct prefix_list *pl = startfile_prefix.plist;
  3028.           int bufsize = 100;
  3029.           char *buffer = (char *) xmalloc (bufsize);
  3030.           int idx;
  3031.  
  3032.           for (; pl; pl = pl->next)
  3033.         {
  3034. #ifdef RELATIVE_PREFIX_NOT_LINKDIR
  3035.           /* Used on systems which record the specified -L dirs
  3036.              and use them to search for dynamic linking.  */
  3037.           /* Relative directories always come from -B,
  3038.              and it is better not to use them for searching
  3039.              at run time.  In particular, stage1 loses  */
  3040.           if (pl->prefix[0] != '/')
  3041.             continue;
  3042. #endif
  3043.           /* Try subdirectory if there is one.  */
  3044.           if (multilib_dir != NULL)
  3045.             {
  3046.               if (machine_suffix)
  3047.             {
  3048.               if (strlen (pl->prefix) + strlen (machine_suffix)
  3049.                   >= bufsize)
  3050.                 bufsize = (strlen (pl->prefix)
  3051.                        + strlen (machine_suffix)) * 2 + 1;
  3052.               buffer = (char *) xrealloc (buffer, bufsize);
  3053.               strcpy (buffer, pl->prefix);
  3054.               strcat (buffer, machine_suffix);
  3055.               if (is_directory (buffer, multilib_dir, 1))
  3056.                 {
  3057.                   do_spec_1 ("-L", 0, NULL_PTR);
  3058. #ifdef SPACE_AFTER_L_OPTION
  3059.                   do_spec_1 (" ", 0, NULL_PTR);
  3060. #endif
  3061.                   do_spec_1 (buffer, 1, NULL_PTR);
  3062.                   do_spec_1 (multilib_dir, 1, NULL_PTR);
  3063.                   /* Make this a separate argument.  */
  3064.                   do_spec_1 (" ", 0, NULL_PTR);
  3065.                 }
  3066.             }
  3067.               if (!pl->require_machine_suffix)
  3068.             {
  3069.               if (is_directory (pl->prefix, multilib_dir, 1))
  3070.                 {
  3071.                   do_spec_1 ("-L", 0, NULL_PTR);
  3072. #ifdef SPACE_AFTER_L_OPTION
  3073.                   do_spec_1 (" ", 0, NULL_PTR);
  3074. #endif
  3075.                   do_spec_1 (pl->prefix, 1, NULL_PTR);
  3076.                   do_spec_1 (multilib_dir, 1, NULL_PTR);
  3077.                   /* Make this a separate argument.  */
  3078.                   do_spec_1 (" ", 0, NULL_PTR);
  3079.                 }
  3080.             }
  3081.             }
  3082.           if (machine_suffix)
  3083.             {
  3084.               if (is_directory (pl->prefix, machine_suffix, 1))
  3085.             {
  3086.               do_spec_1 ("-L", 0, NULL_PTR);
  3087. #ifdef SPACE_AFTER_L_OPTION
  3088.               do_spec_1 (" ", 0, NULL_PTR);
  3089. #endif
  3090.               do_spec_1 (pl->prefix, 1, NULL_PTR);
  3091.               /* Remove slash from machine_suffix.  */
  3092.               if (strlen (machine_suffix) >= bufsize)
  3093.                 bufsize = strlen (machine_suffix) * 2 + 1;
  3094.               buffer = (char *) xrealloc (buffer, bufsize);
  3095.               strcpy (buffer, machine_suffix);
  3096.               idx = strlen (buffer);
  3097.               if (buffer[idx - 1] == '/')
  3098.                 buffer[idx - 1] = 0;
  3099.               do_spec_1 (buffer, 1, NULL_PTR);
  3100.               /* Make this a separate argument.  */
  3101.               do_spec_1 (" ", 0, NULL_PTR);
  3102.             }
  3103.             }
  3104.           if (!pl->require_machine_suffix)
  3105.             {
  3106.               if (is_directory (pl->prefix, "", 1))
  3107.             {
  3108.               do_spec_1 ("-L", 0, NULL_PTR);
  3109. #ifdef SPACE_AFTER_L_OPTION
  3110.               do_spec_1 (" ", 0, NULL_PTR);
  3111. #endif
  3112.               /* Remove slash from pl->prefix.  */
  3113.               if (strlen (pl->prefix) >= bufsize)
  3114.                 bufsize = strlen (pl->prefix) * 2 + 1;
  3115.               buffer = (char *) xrealloc (buffer, bufsize);
  3116.               strcpy (buffer, pl->prefix);
  3117.               idx = strlen (buffer);
  3118.               if (buffer[idx - 1] == '/')
  3119.                 buffer[idx - 1] = 0;
  3120.               do_spec_1 (buffer, 1, NULL_PTR);
  3121.               /* Make this a separate argument.  */
  3122.               do_spec_1 (" ", 0, NULL_PTR);
  3123.             }
  3124.             }
  3125.         }
  3126.           free (buffer);
  3127.         }
  3128.         break;
  3129.  
  3130.       case 'e':
  3131.         /* {...:%efoo} means report an error with `foo' as error message
  3132.            and don't execute any more commands for this file.  */
  3133.         {
  3134.           char *q = p;
  3135.           char *buf;
  3136.           while (*p != 0 && *p != '\n') p++;
  3137.           buf = (char *) alloca (p - q + 1);
  3138.           strncpy (buf, q, p - q);
  3139.           buf[p - q] = 0;
  3140.           error ("%s", buf);
  3141.           return -1;
  3142.         }
  3143.         break;
  3144.  
  3145.       case 'g':
  3146.       case 'u':
  3147.       case 'U':
  3148.         if (save_temps_flag)
  3149.           {
  3150.         obstack_grow (&obstack, input_basename, basename_length);
  3151.         delete_this_arg = 0;
  3152.           }
  3153.         else
  3154.           {
  3155. #ifdef MKTEMP_EACH_FILE
  3156.         /* ??? This has a problem: the total number of
  3157.            values mktemp can return is limited.
  3158.            That matters for the names of object files.
  3159.            In 2.4, do something about that.  */
  3160.         struct temp_name *t;
  3161.         char *suffix = p;
  3162.         while (*p == '.' || isalpha (*p))
  3163.           p++;
  3164.  
  3165.         /* See if we already have an association of %g/%u/%U and
  3166.            suffix.  */
  3167.         for (t = temp_names; t; t = t->next)
  3168.           if (t->length == p - suffix
  3169.               && strncmp (t->suffix, suffix, p - suffix) == 0
  3170.               && t->unique == (c != 'g'))
  3171.             break;
  3172.  
  3173.         /* Make a new association if needed.  %u requires one.  */
  3174.         if (t == 0 || c == 'u')
  3175.           {
  3176.             if (t == 0)
  3177.               {
  3178.             t = (struct temp_name *) xmalloc (sizeof (struct temp_name));
  3179.             t->next = temp_names;
  3180.             temp_names = t;
  3181.               }
  3182.             t->length = p - suffix;
  3183.             t->suffix = save_string (suffix, p - suffix);
  3184.             t->unique = (c != 'g');
  3185.             choose_temp_base ();
  3186.             t->filename = temp_filename;
  3187.             t->filename_length = temp_filename_length;
  3188.           }
  3189.  
  3190.         obstack_grow (&obstack, t->filename, t->filename_length);
  3191.         delete_this_arg = 1;
  3192. #else
  3193.         obstack_grow (&obstack, temp_filename, temp_filename_length);
  3194.         if (c == 'u' || c == 'U')
  3195.           {
  3196.             static int unique;
  3197.             char buff[9];
  3198.             if (c == 'u')
  3199.               unique++;
  3200.             sprintf (buff, "%d", unique);
  3201.             obstack_grow (&obstack, buff, strlen (buff));
  3202.           }
  3203. #endif
  3204.         delete_this_arg = 1;
  3205.           }
  3206.         arg_going = 1;
  3207.         break;
  3208.  
  3209.       case 'i':
  3210.         obstack_grow (&obstack, input_filename, input_filename_length);
  3211.         arg_going = 1;
  3212.         break;
  3213.  
  3214.       case 'I':
  3215.         {
  3216.           struct prefix_list *pl = include_prefix.plist;
  3217.  
  3218.           if (gcc_exec_prefix)
  3219.         {
  3220.           do_spec_1 ("-iprefix", 1, NULL_PTR);
  3221.           /* Make this a separate argument.  */
  3222.           do_spec_1 (" ", 0, NULL_PTR);
  3223.           do_spec_1 (gcc_exec_prefix, 1, NULL_PTR);
  3224.           do_spec_1 (" ", 0, NULL_PTR);
  3225.         }
  3226.  
  3227.           for (; pl; pl = pl->next)
  3228.         {
  3229.           do_spec_1 ("-isystem", 1, NULL_PTR);
  3230.           /* Make this a separate argument.  */
  3231.           do_spec_1 (" ", 0, NULL_PTR);
  3232.           do_spec_1 (pl->prefix, 1, NULL_PTR);
  3233.           do_spec_1 (" ", 0, NULL_PTR);
  3234.         }
  3235.         }
  3236.         break;
  3237.  
  3238.       case 'o':
  3239.         {
  3240.           register int f;
  3241.           for (f = 0; f < n_infiles; f++)
  3242.         store_arg (outfiles[f], 0, 0);
  3243.         }
  3244.         break;
  3245.  
  3246.       case 's':
  3247.         this_is_library_file = 1;
  3248.         break;
  3249.  
  3250.       case 'w':
  3251.         this_is_output_file = 1;
  3252.         break;
  3253.  
  3254.       case 'W':
  3255.         {
  3256.           int index = argbuf_index;
  3257.           /* Handle the {...} following the %W.  */
  3258.           if (*p != '{')
  3259.         abort ();
  3260.           p = handle_braces (p + 1);
  3261.           if (p == 0)
  3262.         return -1;
  3263.           /* If any args were output, mark the last one for deletion
  3264.          on failure.  */
  3265.           if (argbuf_index != index)
  3266.         record_temp_file (argbuf[argbuf_index - 1], 0, 1);
  3267.           break;
  3268.         }
  3269.  
  3270.       /* %x{OPTION} records OPTION for %X to output.  */
  3271.       case 'x':
  3272.         {
  3273.           char *p1 = p;
  3274.           char *string;
  3275.  
  3276.           /* Skip past the option value and make a copy.  */
  3277.           if (*p != '{')
  3278.         abort ();
  3279.           while (*p++ != '}')
  3280.         ;
  3281.           string = save_string (p1 + 1, p - p1 - 2);
  3282.  
  3283.           /* See if we already recorded this option.  */
  3284.           for (i = 0; i < n_linker_options; i++)
  3285.         if (! strcmp (string, linker_options[i]))
  3286.           {
  3287.             free (string);
  3288.             return 0;
  3289.           }
  3290.  
  3291.           /* This option is new; add it.  */
  3292.           n_linker_options++;
  3293.           if (!linker_options)
  3294.         linker_options
  3295.           = (char **) xmalloc (n_linker_options * sizeof (char **));
  3296.           else
  3297.         linker_options
  3298.           = (char **) xrealloc (linker_options,
  3299.                     n_linker_options * sizeof (char **));
  3300.  
  3301.           linker_options[n_linker_options - 1] = string;
  3302.         }
  3303.         break;
  3304.  
  3305.       /* Dump out the options accumulated previously using %x,
  3306.          -Xlinker and -Wl,.  */
  3307.       case 'X':
  3308.         for (i = 0; i < n_linker_options; i++)
  3309.           {
  3310.         do_spec_1 (linker_options[i], 1, NULL_PTR);
  3311.         /* Make each accumulated option a separate argument.  */
  3312.         do_spec_1 (" ", 0, NULL_PTR);
  3313.           }
  3314.         break;
  3315.  
  3316.       /* Dump out the options accumulated previously using -Wa,.  */
  3317.       case 'Y':
  3318.         for (i = 0; i < n_assembler_options; i++)
  3319.           {
  3320.         do_spec_1 (assembler_options[i], 1, NULL_PTR);
  3321.         /* Make each accumulated option a separate argument.  */
  3322.         do_spec_1 (" ", 0, NULL_PTR);
  3323.           }
  3324.         break;
  3325.  
  3326.         /* Here are digits and numbers that just process
  3327.            a certain constant string as a spec.  */
  3328.  
  3329.       case '1':
  3330.         value = do_spec_1 (cc1_spec, 0, NULL_PTR);
  3331.         if (value != 0)
  3332.           return value;
  3333.         break;
  3334.  
  3335.       case '2':
  3336.         value = do_spec_1 (cc1plus_spec, 0, NULL_PTR);
  3337.         if (value != 0)
  3338.           return value;
  3339.         break;
  3340.  
  3341.       case 'a':
  3342.         value = do_spec_1 (asm_spec, 0, NULL_PTR);
  3343.         if (value != 0)
  3344.           return value;
  3345.         break;
  3346.  
  3347.       case 'A':
  3348.         value = do_spec_1 (asm_final_spec, 0, NULL_PTR);
  3349.         if (value != 0)
  3350.           return value;
  3351.         break;
  3352.  
  3353.       case 'c':
  3354.         value = do_spec_1 (signed_char_spec, 0, NULL_PTR);
  3355.         if (value != 0)
  3356.           return value;
  3357.         break;
  3358.  
  3359.       case 'C':
  3360.         value = do_spec_1 (cpp_spec, 0, NULL_PTR);
  3361.         if (value != 0)
  3362.           return value;
  3363.         break;
  3364.  
  3365.       case 'E':
  3366.         value = do_spec_1 (endfile_spec, 0, NULL_PTR);
  3367.         if (value != 0)
  3368.           return value;
  3369.         break;
  3370.  
  3371.       case 'l':
  3372.         value = do_spec_1 (link_spec, 0, NULL_PTR);
  3373.         if (value != 0)
  3374.           return value;
  3375.         break;
  3376.  
  3377.       case 'L':
  3378.         value = do_spec_1 (lib_spec, 0, NULL_PTR);
  3379.         if (value != 0)
  3380.           return value;
  3381.         break;
  3382.  
  3383.       case 'p':
  3384.         {
  3385.           char *x = (char *) alloca (strlen (cpp_predefines) + 1);
  3386.           char *buf = x;
  3387.           char *y;
  3388.  
  3389.           /* Copy all of the -D options in CPP_PREDEFINES into BUF.  */
  3390.           y = cpp_predefines;
  3391.           while (*y != 0)
  3392.         {
  3393.           if (! strncmp (y, "-D", 2))
  3394.             /* Copy the whole option.  */
  3395.             while (*y && *y != ' ' && *y != '\t')
  3396.               *x++ = *y++;
  3397.           else if (*y == ' ' || *y == '\t')
  3398.             /* Copy whitespace to the result.  */
  3399.             *x++ = *y++;
  3400.           /* Don't copy other options.  */
  3401.           else
  3402.             y++;
  3403.         }
  3404.  
  3405.           *x = 0;
  3406.  
  3407.           value = do_spec_1 (buf, 0, NULL_PTR);
  3408.           if (value != 0)
  3409.         return value;
  3410.         }
  3411.         break;
  3412.  
  3413.       case 'P':
  3414.         {
  3415.           char *x = (char *) alloca (strlen (cpp_predefines) * 4 + 1);
  3416.           char *buf = x;
  3417.           char *y;
  3418.  
  3419.           /* Copy all of CPP_PREDEFINES into BUF,
  3420.          but put __ after every -D and at the end of each arg.  */
  3421.           y = cpp_predefines;
  3422.           while (*y != 0)
  3423.         {
  3424.           if (! strncmp (y, "-D", 2))
  3425.             {
  3426.               int flag = 0;
  3427.  
  3428.               *x++ = *y++;
  3429.               *x++ = *y++;
  3430.  
  3431.               if (*y != '_'
  3432.               || (*(y+1) != '_' && ! isupper (*(y+1))))
  3433.                 {
  3434.               /* Stick __ at front of macro name.  */
  3435.               *x++ = '_';
  3436.               *x++ = '_';
  3437.               /* Arrange to stick __ at the end as well.  */
  3438.               flag = 1;
  3439.             }
  3440.  
  3441.               /* Copy the macro name.  */
  3442.               while (*y && *y != '=' && *y != ' ' && *y != '\t')
  3443.             *x++ = *y++;
  3444.  
  3445.               if (flag)
  3446.                 {
  3447.               *x++ = '_';
  3448.               *x++ = '_';
  3449.             }
  3450.  
  3451.               /* Copy the value given, if any.  */
  3452.               while (*y && *y != ' ' && *y != '\t')
  3453.             *x++ = *y++;
  3454.             }
  3455.           else if (*y == ' ' || *y == '\t')
  3456.             /* Copy whitespace to the result.  */
  3457.             *x++ = *y++;
  3458.           /* Don't copy -A options  */
  3459.           else
  3460.             y++;
  3461.         }
  3462.           *x++ = ' ';
  3463.  
  3464.           /* Copy all of CPP_PREDEFINES into BUF,
  3465.          but put __ after every -D.  */
  3466.           y = cpp_predefines;
  3467.           while (*y != 0)
  3468.         {
  3469.           if (! strncmp (y, "-D", 2))
  3470.             {
  3471.               y += 2;
  3472.  
  3473.               if (*y != '_'
  3474.               || (*(y+1) != '_' && ! isupper (*(y+1))))
  3475.                 {
  3476.               /* Stick -D__ at front of macro name.  */
  3477.               *x++ = '-';
  3478.               *x++ = 'D';
  3479.               *x++ = '_';
  3480.               *x++ = '_';
  3481.  
  3482.               /* Copy the macro name.  */
  3483.               while (*y && *y != '=' && *y != ' ' && *y != '\t')
  3484.                 *x++ = *y++;
  3485.  
  3486.               /* Copy the value given, if any.  */
  3487.               while (*y && *y != ' ' && *y != '\t')
  3488.                 *x++ = *y++;
  3489.             }
  3490.               else
  3491.             {
  3492.               /* Do not copy this macro - we have just done it before */
  3493.               while (*y && *y != ' ' && *y != '\t')
  3494.                 y++;
  3495.             }
  3496.             }
  3497.           else if (*y == ' ' || *y == '\t')
  3498.             /* Copy whitespace to the result.  */
  3499.             *x++ = *y++;
  3500.           /* Don't copy -A options  */
  3501.           else
  3502.             y++;
  3503.         }
  3504.           *x++ = ' ';
  3505.  
  3506.           /* Copy all of the -A options in CPP_PREDEFINES into BUF.  */
  3507.           y = cpp_predefines;
  3508.           while (*y != 0)
  3509.         {
  3510.           if (! strncmp (y, "-A", 2))
  3511.             /* Copy the whole option.  */
  3512.             while (*y && *y != ' ' && *y != '\t')
  3513.               *x++ = *y++;
  3514.           else if (*y == ' ' || *y == '\t')
  3515.             /* Copy whitespace to the result.  */
  3516.             *x++ = *y++;
  3517.           /* Don't copy other options.  */
  3518.           else
  3519.             y++;
  3520.         }
  3521.  
  3522.           *x = 0;
  3523.  
  3524.           value = do_spec_1 (buf, 0, NULL_PTR);
  3525.           if (value != 0)
  3526.         return value;
  3527.         }
  3528.         break;
  3529.  
  3530.       case 'S':
  3531.         value = do_spec_1 (startfile_spec, 0, NULL_PTR);
  3532.         if (value != 0)
  3533.           return value;
  3534.         break;
  3535.  
  3536.         /* Here we define characters other than letters and digits.  */
  3537.  
  3538.       case '{':
  3539.         p = handle_braces (p);
  3540.         if (p == 0)
  3541.           return -1;
  3542.         break;
  3543.  
  3544.       case '%':
  3545.         obstack_1grow (&obstack, '%');
  3546.         break;
  3547.  
  3548.       case '*':
  3549.         do_spec_1 (soft_matched_part, 1, NULL_PTR);
  3550.         do_spec_1 (" ", 0, NULL_PTR);
  3551.         break;
  3552.  
  3553.         /* Process a string found as the value of a spec given by name.
  3554.            This feature allows individual machine descriptions
  3555.            to add and use their own specs.
  3556.            %[...] modifies -D options the way %P does;
  3557.            %(...) uses the spec unmodified.  */
  3558.       case '(':
  3559.       case '[':
  3560.         {
  3561.           char *name = p;
  3562.           struct spec_list *sl;
  3563.           int len;
  3564.  
  3565.           /* The string after the S/P is the name of a spec that is to be
  3566.          processed. */
  3567.           while (*p && *p != ')' && *p != ']')
  3568.         p++;
  3569.  
  3570.           /* See if it's in the list */
  3571.           for (len = p - name, sl = specs; sl; sl = sl->next)
  3572.         if (strncmp (sl->name, name, len) == 0 && !sl->name[len])
  3573.           {
  3574.             name = sl->spec;
  3575.             break;
  3576.           }
  3577.  
  3578.           if (sl)
  3579.         {
  3580.           if (c == '(')
  3581.             {
  3582.               value = do_spec_1 (name, 0, NULL_PTR);
  3583.               if (value != 0)
  3584.             return value;
  3585.             }
  3586.           else
  3587.             {
  3588.               char *x = (char *) alloca (strlen (name) * 2 + 1);
  3589.               char *buf = x;
  3590.               char *y = name;
  3591.  
  3592.               /* Copy all of NAME into BUF, but put __ after
  3593.              every -D and at the end of each arg,  */
  3594.               while (1)
  3595.             {
  3596.               if (! strncmp (y, "-D", 2))
  3597.                 {
  3598.                   *x++ = '-';
  3599.                   *x++ = 'D';
  3600.                   *x++ = '_';
  3601.                   *x++ = '_';
  3602.                   y += 2;
  3603.                 }
  3604.               else if (*y == ' ' || *y == 0)
  3605.                 {
  3606.                   *x++ = '_';
  3607.                   *x++ = '_';
  3608.                   if (*y == 0)
  3609.                 break;
  3610.                   else
  3611.                 *x++ = *y++;
  3612.                 }
  3613.               else
  3614.                 *x++ = *y++;
  3615.             }
  3616.               *x = 0;
  3617.  
  3618.               value = do_spec_1 (buf, 0, NULL_PTR);
  3619.               if (value != 0)
  3620.             return value;
  3621.             }
  3622.         }
  3623.  
  3624.           /* Discard the closing paren or bracket.  */
  3625.           if (*p)
  3626.         p++;
  3627.         }
  3628.         break;
  3629.  
  3630.       case 'v':
  3631.         {
  3632.           int c1 = *p++;  /* Select first or second version number.  */
  3633.           char *v = compiler_version;
  3634.           char *q, *copy;
  3635.           /* If desired, advance to second version number.  */
  3636.           if (c1 == '2')
  3637.         {
  3638.           /* Set P after the first period.  */
  3639.           while (*v != 0 && *v != ' ' && *v != '.')
  3640.             v++;
  3641.           if (*v == '.')
  3642.             v++;
  3643.         }
  3644.           /* Set Q at the next period or at the end.  */
  3645.           q = v;
  3646.           while (*q != 0 && *q != ' ' && *q != '.')
  3647.         q++;
  3648.           /* Empty string means zero.  */
  3649.           if (p == q)
  3650.         {
  3651.           v = "0";
  3652.           q = v + 1;
  3653.         }
  3654.           /* Put that part into the command.  */
  3655.           obstack_grow (&obstack, v, q - v);
  3656.           arg_going = 1;
  3657.         }
  3658.         break;
  3659.  
  3660.       case '|':
  3661.         if (input_from_pipe)
  3662.           do_spec_1 ("-", 0, NULL_PTR);
  3663.         break;
  3664.  
  3665.       default:
  3666.         abort ();
  3667.       }
  3668.     break;
  3669.  
  3670.       case '\\':
  3671.     /* Backslash: treat next character as ordinary.  */
  3672.     c = *p++;
  3673.  
  3674.     /* fall through */
  3675.       default:
  3676.     /* Ordinary character: put it into the current argument.  */
  3677.     obstack_1grow (&obstack, c);
  3678.     arg_going = 1;
  3679.       }
  3680.  
  3681.   return 0;        /* End of string */
  3682. }
  3683.  
  3684. /* Return 0 if we call do_spec_1 and that returns -1.  */
  3685.  
  3686. static char *
  3687. handle_braces (p)
  3688.      register char *p;
  3689. {
  3690.   register char *q;
  3691.   char *filter;
  3692.   int pipe = 0;
  3693.   int negate = 0;
  3694.   int suffix = 0;
  3695.  
  3696.   if (*p == '|')
  3697.     /* A `|' after the open-brace means,
  3698.        if the test fails, output a single minus sign rather than nothing.
  3699.        This is used in %{|!pipe:...}.  */
  3700.     pipe = 1, ++p;
  3701.  
  3702.   if (*p == '!')
  3703.     /* A `!' after the open-brace negates the condition:
  3704.        succeed if the specified switch is not present.  */
  3705.     negate = 1, ++p;
  3706.  
  3707.   if (*p == '.')
  3708.     /* A `.' after the open-brace means test against the current suffix.  */
  3709.     {
  3710.       if (pipe)
  3711.     abort ();
  3712.  
  3713.       suffix = 1;
  3714.       ++p;
  3715.     }
  3716.  
  3717.   filter = p;
  3718.   while (*p != ':' && *p != '}') p++;
  3719.   if (*p != '}')
  3720.     {
  3721.       register int count = 1;
  3722.       q = p + 1;
  3723.       while (count > 0)
  3724.     {
  3725.       if (*q == '{')
  3726.         count++;
  3727.       else if (*q == '}')
  3728.         count--;
  3729.       else if (*q == 0)
  3730.         abort ();
  3731.       q++;
  3732.     }
  3733.     }
  3734.   else
  3735.     q = p + 1;
  3736.  
  3737.   if (suffix)
  3738.     {
  3739.       int found = (input_suffix != 0
  3740.            && strlen (input_suffix) == p - filter
  3741.            && strncmp (input_suffix, filter, p - filter) == 0);
  3742.  
  3743.       if (p[0] == '}')
  3744.     abort ();
  3745.  
  3746.       if (negate != found
  3747.       && do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
  3748.     return 0;
  3749.  
  3750.       return q;
  3751.     }
  3752.   else if (p[-1] == '*' && p[0] == '}')
  3753.     {
  3754.       /* Substitute all matching switches as separate args.  */
  3755.       register int i;
  3756.       --p;
  3757.       for (i = 0; i < n_switches; i++)
  3758.     if (!strncmp (switches[i].part1, filter, p - filter)
  3759.         && check_live_switch (i, p - filter))
  3760.       give_switch (i, 0);
  3761.     }
  3762.   else
  3763.     {
  3764.       /* Test for presence of the specified switch.  */
  3765.       register int i;
  3766.       int present = 0;
  3767.  
  3768.       /* If name specified ends in *, as in {x*:...},
  3769.      check for %* and handle that case.  */
  3770.       if (p[-1] == '*' && !negate)
  3771.     {
  3772.       int substitution;
  3773.       char *r = p;
  3774.  
  3775.       /* First see whether we have %*.  */
  3776.       substitution = 0;
  3777.       while (r < q)
  3778.         {
  3779.           if (*r == '%' && r[1] == '*')
  3780.         substitution = 1;
  3781.           r++;
  3782.         }
  3783.       /* If we do, handle that case.  */
  3784.       if (substitution)
  3785.         {
  3786.           /* Substitute all matching switches as separate args.
  3787.          But do this by substituting for %*
  3788.          in the text that follows the colon.  */
  3789.  
  3790.           unsigned hard_match_len = p - filter - 1;
  3791.           char *string = save_string (p + 1, q - p - 2);
  3792.  
  3793.           for (i = 0; i < n_switches; i++)
  3794.         if (!strncmp (switches[i].part1, filter, hard_match_len)
  3795.             && check_live_switch (i, -1))
  3796.           {
  3797.             do_spec_1 (string, 0, &switches[i].part1[hard_match_len]);
  3798.             /* Pass any arguments this switch has.  */
  3799.             give_switch (i, 1);
  3800.           }
  3801.  
  3802.           return q;
  3803.         }
  3804.     }
  3805.  
  3806.       /* If name specified ends in *, as in {x*:...},
  3807.      check for presence of any switch name starting with x.  */
  3808.       if (p[-1] == '*')
  3809.     {
  3810.       for (i = 0; i < n_switches; i++)
  3811.         {
  3812.           unsigned hard_match_len = p - filter - 1;
  3813.  
  3814.           if (!strncmp (switches[i].part1, filter, hard_match_len)
  3815.           && check_live_switch (i, hard_match_len))
  3816.         {
  3817.           present = 1;
  3818.         }
  3819.         }
  3820.     }
  3821.       /* Otherwise, check for presence of exact name specified.  */
  3822.       else
  3823.     {
  3824.       for (i = 0; i < n_switches; i++)
  3825.         {
  3826.           if (!strncmp (switches[i].part1, filter, p - filter)
  3827.           && switches[i].part1[p - filter] == 0
  3828.           && check_live_switch (i, -1))
  3829.         {
  3830.           present = 1;
  3831.           break;
  3832.         }
  3833.         }
  3834.     }
  3835.  
  3836.       /* If it is as desired (present for %{s...}, absent for %{-s...})
  3837.      then substitute either the switch or the specified
  3838.      conditional text.  */
  3839.       if (present != negate)
  3840.     {
  3841.       if (*p == '}')
  3842.         {
  3843.           give_switch (i, 0);
  3844.         }
  3845.       else
  3846.         {
  3847.           if (do_spec_1 (save_string (p + 1, q - p - 2), 0, NULL_PTR) < 0)
  3848.         return 0;
  3849.         }
  3850.     }
  3851.       else if (pipe)
  3852.     {
  3853.       /* Here if a %{|...} conditional fails: output a minus sign,
  3854.          which means "standard output" or "standard input".  */
  3855.       do_spec_1 ("-", 0, NULL_PTR);
  3856.     }
  3857.     }
  3858.  
  3859.   return q;
  3860. }
  3861.  
  3862. /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
  3863.    on the command line.  PREFIX_LENGTH is the length of XXX in an {XXX*}
  3864.    spec, or -1 if either exact match or %* is used.
  3865.  
  3866.    A -O switch is obsoleted by a later -O switch.  A -f, -m, or -W switch
  3867.    whose value does not begin with "no-" is obsoleted by the same value
  3868.    with the "no-", similarly for a switch with the "no-" prefix.  */
  3869.  
  3870. static int
  3871. check_live_switch (switchnum, prefix_length)
  3872.      int switchnum;
  3873.      int prefix_length;
  3874. {
  3875.   char *name = switches[switchnum].part1;
  3876.   int i;
  3877.  
  3878.   /* In the common case of {<at-most-one-letter>*}, a negating
  3879.      switch would always match, so ignore that case.  We will just
  3880.      send the conflicting switches to the compiler phase.  */
  3881.   if (prefix_length >= 0 && prefix_length <= 1)
  3882.     return 1;
  3883.  
  3884.   /* If we already processed this switch and determined if it was
  3885.      live or not, return our past determination.  */
  3886.   if (switches[switchnum].live_cond != 0)
  3887.     return switches[switchnum].live_cond > 0;
  3888.  
  3889.   /* Now search for duplicate in a manner that depends on the name.  */
  3890.   switch (*name)
  3891.     {
  3892.     case 'O':
  3893.     for (i = switchnum + 1; i < n_switches; i++)
  3894.       if (switches[i].part1[0] == 'O')
  3895.         {
  3896.           switches[switchnum].valid = 1;
  3897.           switches[switchnum].live_cond = -1;
  3898.           return 0;
  3899.         }
  3900.       break;
  3901.  
  3902.     case 'W':  case 'f':  case 'm':
  3903.       if (! strncmp (name + 1, "no-", 3))
  3904.     {
  3905.       /* We have Xno-YYY, search for XYYY. */
  3906.       for (i = switchnum + 1; i < n_switches; i++)
  3907.         if (switches[i].part1[0] == name[0]
  3908.         && ! strcmp (&switches[i].part1[1], &name[4]))
  3909.         {
  3910.           switches[switchnum].valid = 1;
  3911.           switches[switchnum].live_cond = -1;
  3912.           return 0;
  3913.         }
  3914.     }
  3915.       else
  3916.     {
  3917.       /* We have XYYY, search for Xno-YYY.  */
  3918.       for (i = switchnum + 1; i < n_switches; i++)
  3919.         if (switches[i].part1[0] == name[0]
  3920.         && switches[i].part1[1] == 'n'
  3921.         && switches[i].part1[2] == 'o'
  3922.         && switches[i].part1[3] == '-'
  3923.         && !strcmp (&switches[i].part1[4], &name[1]))
  3924.         {
  3925.           switches[switchnum].valid = 1;
  3926.           switches[switchnum].live_cond = -1;
  3927.           return 0;
  3928.         }
  3929.     }
  3930.       break;
  3931.     }
  3932.  
  3933.   /* Otherwise the switch is live.  */
  3934.   switches[switchnum].live_cond = 1;
  3935.   return 1;
  3936. }
  3937.  
  3938. /* Pass a switch to the current accumulating command
  3939.    in the same form that we received it.
  3940.    SWITCHNUM identifies the switch; it is an index into
  3941.    the vector of switches gcc received, which is `switches'.
  3942.    This cannot fail since it never finishes a command line.
  3943.  
  3944.    If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument.  */
  3945.  
  3946. static void
  3947. give_switch (switchnum, omit_first_word)
  3948.      int switchnum;
  3949.      int omit_first_word;
  3950. {
  3951.   if (!omit_first_word)
  3952.     {
  3953.       do_spec_1 ("-", 0, NULL_PTR);
  3954.       do_spec_1 (switches[switchnum].part1, 1, NULL_PTR);
  3955.     }
  3956.   do_spec_1 (" ", 0, NULL_PTR);
  3957.   if (switches[switchnum].args != 0)
  3958.     {
  3959.       char **p;
  3960.       for (p = switches[switchnum].args; *p; p++)
  3961.     {
  3962.       do_spec_1 (*p, 1, NULL_PTR);
  3963.       do_spec_1 (" ", 0, NULL_PTR);
  3964.     }
  3965.     }
  3966.   switches[switchnum].valid = 1;
  3967. }
  3968.  
  3969. /* Search for a file named NAME trying various prefixes including the
  3970.    user's -B prefix and some standard ones.
  3971.    Return the absolute file name found.  If nothing is found, return NAME.  */
  3972.  
  3973. static char *
  3974. find_file (name)
  3975.      char *name;
  3976. {
  3977.   char *newname;
  3978.  
  3979.   /* Try multilib_dir if it is defined.  */
  3980.   if (multilib_dir != NULL)
  3981.     {
  3982.       char *try;
  3983.  
  3984.       try = (char *) alloca (strlen (multilib_dir) + strlen (name) + 2);
  3985.       strcpy (try, multilib_dir);
  3986.       strcat (try, "/");
  3987.       strcat (try, name);
  3988.  
  3989.       newname = find_a_file (&startfile_prefix, try, R_OK);
  3990.  
  3991.       /* If we don't find it in the multi library dir, then fall
  3992.      through and look for it in the normal places.  */
  3993.       if (newname != NULL)
  3994.     return newname;
  3995.     }
  3996.  
  3997.   newname = find_a_file (&startfile_prefix, name, R_OK);
  3998.   return newname ? newname : name;
  3999. }
  4000.  
  4001. /* Determine whether a directory exists.  If LINKER, return 0 for
  4002.    certain fixed names not needed by the linker.  If not LINKER, it is
  4003.    only important to return 0 if the host machine has a small ARG_MAX
  4004.    limit.  */
  4005.  
  4006. static int
  4007. is_directory (path1, path2, linker)
  4008.      char *path1;
  4009.      char *path2;
  4010.      int linker;
  4011. {
  4012.   int len1 = strlen (path1);
  4013.   int len2 = strlen (path2);
  4014.   char *path = (char *) alloca (3 + len1 + len2);
  4015.   char *cp;
  4016.   struct stat st;
  4017.  
  4018. #ifndef SMALL_ARG_MAX
  4019.   if (! linker)
  4020.     return 1;
  4021. #endif
  4022.  
  4023.   /* Construct the path from the two parts.  Ensure the string ends with "/.".
  4024.      The resulting path will be a directory even if the given path is a
  4025.      symbolic link.  */
  4026.   bcopy (path1, path, len1);
  4027.   bcopy (path2, path + len1, len2);
  4028.   cp = path + len1 + len2;
  4029.   if (cp[-1] != '/')
  4030.     *cp++ = '/';
  4031.   *cp++ = '.';
  4032.   *cp = '\0';
  4033.  
  4034.   /* Exclude directories that the linker is known to search.  */
  4035.   if (linker
  4036.       && ((cp - path == 6 && strcmp (path, "/lib/.") == 0)
  4037.       || (cp - path == 10 && strcmp (path, "/usr/lib/.") == 0)))
  4038.     return 0;
  4039.  
  4040.   return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
  4041. }
  4042.  
  4043. /* On fatal signals, delete all the temporary files.  */
  4044.  
  4045. static void
  4046. fatal_error (signum)
  4047.      int signum;
  4048. {
  4049.   signal (signum, SIG_DFL);
  4050.   delete_failure_queue ();
  4051.   delete_temp_files ();
  4052.   /* Get the same signal again, this time not handled,
  4053.      so its normal effect occurs.  */
  4054.   kill (getpid (), signum);
  4055. }
  4056.  
  4057. int
  4058. main (argc, argv)
  4059.      int argc;
  4060.      char **argv;
  4061. {
  4062.   register int i;
  4063.   int j;
  4064.   int value;
  4065.   int linker_was_run = 0;
  4066.   char *explicit_link_files;
  4067.   char *specs_file;
  4068.   char *p;
  4069.  
  4070.   p = argv[0] + strlen (argv[0]);
  4071.   while (p != argv[0] && p[-1] != '/') --p;
  4072.   programname = p;
  4073.  
  4074.   if (signal (SIGINT, SIG_IGN) != SIG_IGN)
  4075.     signal (SIGINT, fatal_error);
  4076. #ifdef SIGHUP
  4077.   if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
  4078.     signal (SIGHUP, fatal_error);
  4079. #endif
  4080.   if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
  4081.     signal (SIGTERM, fatal_error);
  4082. #ifdef SIGPIPE
  4083.   if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
  4084.     signal (SIGPIPE, fatal_error);
  4085. #endif
  4086.  
  4087.   argbuf_length = 10;
  4088.   argbuf = (char **) xmalloc (argbuf_length * sizeof (char *));
  4089.  
  4090.   obstack_init (&obstack);
  4091.  
  4092.   /* Set up to remember the pathname of gcc and any options
  4093.      needed for collect.  We use argv[0] instead of programname because
  4094.      we need the complete pathname.  */
  4095.   obstack_init (&collect_obstack);
  4096.   obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=")-1);
  4097.   obstack_grow (&collect_obstack, argv[0], strlen (argv[0])+1);
  4098.   putenv (obstack_finish (&collect_obstack));
  4099.  
  4100.   /* Choose directory for temp files.  */
  4101.  
  4102.   choose_temp_base ();
  4103.  
  4104.   /* Make a table of what switches there are (switches, n_switches).
  4105.      Make a table of specified input files (infiles, n_infiles).
  4106.      Decode switches that are handled locally.  */
  4107.  
  4108.   process_command (argc, argv);
  4109.  
  4110.   /* Initialize the vector of specs to just the default.
  4111.      This means one element containing 0s, as a terminator.  */
  4112.  
  4113.   compilers = (struct compiler *) xmalloc (sizeof default_compilers);
  4114.   bcopy ((char *) default_compilers, (char *) compilers,
  4115.      sizeof default_compilers);
  4116.   n_compilers = n_default_compilers;
  4117.  
  4118.   /* Read specs from a file if there is one.  */
  4119.  
  4120.   machine_suffix = concat (spec_machine, "/", concat (spec_version, "/", ""));
  4121.   just_machine_suffix = concat (spec_machine, "/", "");
  4122.  
  4123.   specs_file = find_a_file (&startfile_prefix, "specs", R_OK);
  4124.   /* Read the specs file unless it is a default one.  */
  4125.   if (specs_file != 0 && strcmp (specs_file, "specs"))
  4126.     read_specs (specs_file);
  4127.  
  4128.   /* If not cross-compiling, look for startfiles in the standard places.  */
  4129.   /* The fact that these are done here, after reading the specs file,
  4130.      means that it cannot be found in these directories.
  4131.      But that's okay.  It should never be there anyway.  */
  4132.   if (!cross_compile)
  4133.     {
  4134. #ifdef MD_EXEC_PREFIX
  4135.       add_prefix (&exec_prefix, md_exec_prefix, 0, 0, NULL_PTR);
  4136.       add_prefix (&startfile_prefix, md_exec_prefix, 0, 0, NULL_PTR);
  4137. #endif
  4138.  
  4139. #ifdef MD_STARTFILE_PREFIX
  4140.       add_prefix (&startfile_prefix, md_startfile_prefix, 0, 0, NULL_PTR);
  4141. #endif
  4142.  
  4143. #ifdef MD_STARTFILE_PREFIX_1
  4144.       add_prefix (&startfile_prefix, md_startfile_prefix_1, 0, 0, NULL_PTR);
  4145. #endif
  4146.  
  4147.       /* If standard_startfile_prefix is relative, base it on
  4148.      standard_exec_prefix.  This lets us move the installed tree
  4149.      as a unit.  If GCC_EXEC_PREFIX is defined, base
  4150.      standard_startfile_prefix on that as well.  */
  4151.       if (*standard_startfile_prefix == '/')
  4152.     add_prefix (&startfile_prefix, standard_startfile_prefix, 0, 0,
  4153.             NULL_PTR);
  4154.       else
  4155.     {
  4156.       if (gcc_exec_prefix)
  4157.         add_prefix (&startfile_prefix,
  4158.             concat (gcc_exec_prefix,
  4159.                 standard_startfile_prefix,
  4160.                 ""),
  4161.             0, 0, NULL_PTR);
  4162.       add_prefix (&startfile_prefix,
  4163.               concat (standard_exec_prefix,
  4164.                   machine_suffix,
  4165.                   standard_startfile_prefix),
  4166.               0, 0, NULL_PTR);
  4167.     }               
  4168.  
  4169.       add_prefix (&startfile_prefix, standard_startfile_prefix_1, 0, 0,
  4170.           NULL_PTR);
  4171.       add_prefix (&startfile_prefix, standard_startfile_prefix_2, 0, 0,
  4172.           NULL_PTR);
  4173. #if 0 /* Can cause surprises, and one can use -B./ instead.  */
  4174.       add_prefix (&startfile_prefix, "./", 0, 1, NULL_PTR);
  4175. #endif
  4176.     }
  4177.  
  4178.   /* Now we have the specs.
  4179.      Set the `valid' bits for switches that match anything in any spec.  */
  4180.  
  4181.   validate_all_switches ();
  4182.  
  4183.   /* Now that we have the switches and the specs, set
  4184.      the subdirectory based on the options.  */
  4185.   set_multilib_dir ();
  4186.  
  4187.   /* Warn about any switches that no pass was interested in.  */
  4188.  
  4189.   for (i = 0; i < n_switches; i++)
  4190.     if (! switches[i].valid)
  4191.       error ("unrecognized option `-%s'", switches[i].part1);
  4192.  
  4193.   /* Obey some of the options.  */
  4194.  
  4195.   if (print_file_name)
  4196.     {
  4197.       printf ("%s\n", find_file (print_file_name));
  4198.       exit (0);
  4199.     }
  4200.  
  4201.   if (print_prog_name)
  4202.     {
  4203.       char *newname = find_a_file (&exec_prefix, print_prog_name, X_OK);
  4204.       printf ("%s\n", (newname ? newname : print_prog_name));
  4205.       exit (0);
  4206.     }
  4207.  
  4208.   if (print_multi_lib)
  4209.     {
  4210.       print_multilib_info ();
  4211.       exit (0);
  4212.     }
  4213.  
  4214.   if (print_multi_directory)
  4215.     {
  4216.       if (multilib_dir == NULL)
  4217.     printf (".\n");
  4218.       else
  4219.     printf ("%s\n", multilib_dir);
  4220.       exit (0);
  4221.     }
  4222.  
  4223.   if (verbose_flag)
  4224.     {
  4225.       fprintf (stderr, "gcc version %s\n", version_string);
  4226.       if (n_infiles == 0)
  4227.     exit (0);
  4228.     }
  4229.  
  4230.   if (n_infiles == 0)
  4231.     fatal ("No input files");
  4232.  
  4233.   /* Make a place to record the compiler output file names
  4234.      that correspond to the input files.  */
  4235.  
  4236.   outfiles = (char **) xmalloc (n_infiles * sizeof (char *));
  4237.   bzero ((char *) outfiles, n_infiles * sizeof (char *));
  4238.  
  4239.   /* Record which files were specified explicitly as link input.  */
  4240.  
  4241.   explicit_link_files = xmalloc (n_infiles);
  4242.   bzero (explicit_link_files, n_infiles);
  4243.  
  4244.   for (i = 0; i < n_infiles; i++)
  4245.     {
  4246.       register struct compiler *cp = 0;
  4247.       int this_file_error = 0;
  4248.  
  4249.       /* Tell do_spec what to substitute for %i.  */
  4250.  
  4251.       input_filename = infiles[i].name;
  4252.       input_filename_length = strlen (input_filename);
  4253.       input_file_number = i;
  4254.  
  4255.       /* Use the same thing in %o, unless cp->spec says otherwise.  */
  4256.  
  4257.       outfiles[i] = input_filename;
  4258.  
  4259.       /* Figure out which compiler from the file's suffix.  */
  4260.  
  4261.       cp = lookup_compiler (infiles[i].name, input_filename_length,
  4262.                 infiles[i].language);
  4263.  
  4264.       if (cp)
  4265.     {
  4266.       /* Ok, we found an applicable compiler.  Run its spec.  */
  4267.       /* First say how much of input_filename to substitute for %b  */
  4268.       register char *p;
  4269.       int len;
  4270.  
  4271. #ifdef FILE_NAME_NONDIRECTORY
  4272.       input_basename = FILE_NAME_NONDIRECTORY (input_filename);
  4273. #else
  4274.       input_basename = input_filename;
  4275.       for (p = input_filename; *p; p++)
  4276.         if (*p == '/')
  4277.           input_basename = p + 1;
  4278. #endif
  4279.  
  4280.       /* Find a suffix starting with the last period,
  4281.          and set basename_length to exclude that suffix.  */
  4282.       basename_length = strlen (input_basename);
  4283.       p = input_basename + basename_length;
  4284.       while (p != input_basename && *p != '.') --p;
  4285.       if (*p == '.' && p != input_basename)
  4286.         {
  4287.           basename_length = p - input_basename;
  4288.           input_suffix = p + 1;
  4289.         }
  4290.       else
  4291.         input_suffix = "";
  4292.  
  4293.       len = 0;
  4294.       for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
  4295.         if (cp->spec[j])
  4296.           len += strlen (cp->spec[j]);
  4297.  
  4298.       p = (char *) xmalloc (len + 1);
  4299.  
  4300.       len = 0;
  4301.       for (j = 0; j < sizeof cp->spec / sizeof cp->spec[0]; j++)
  4302.         if (cp->spec[j])
  4303.           {
  4304.         strcpy (p + len, cp->spec[j]);
  4305.         len += strlen (cp->spec[j]);
  4306.           }
  4307.  
  4308.       value = do_spec (p);
  4309.       free (p);
  4310.       if (value < 0)
  4311.         this_file_error = 1;
  4312.     }
  4313.  
  4314.       /* If this file's name does not contain a recognized suffix,
  4315.      record it as explicit linker input.  */
  4316.  
  4317.       else
  4318.     explicit_link_files[i] = 1;
  4319.  
  4320.       /* Clear the delete-on-failure queue, deleting the files in it
  4321.      if this compilation failed.  */
  4322.  
  4323.       if (this_file_error)
  4324.     {
  4325.       delete_failure_queue ();
  4326.       error_count++;
  4327.     }
  4328.       /* If this compilation succeeded, don't delete those files later.  */
  4329.       clear_failure_queue ();
  4330.     }
  4331.  
  4332.   /* Run ld to link all the compiler output files.  */
  4333.  
  4334.   if (error_count == 0)
  4335.     {
  4336.       int tmp = execution_count;
  4337.       int i;
  4338.       int first_time;
  4339.  
  4340.       /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
  4341.      for collect.  */
  4342.       putenv_from_prefixes (&exec_prefix, "COMPILER_PATH=");
  4343.       putenv_from_prefixes (&startfile_prefix, "LIBRARY_PATH=");
  4344.  
  4345.       /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
  4346.      the compiler.  */
  4347.       obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
  4348.             sizeof ("COLLECT_GCC_OPTIONS=")-1);
  4349.  
  4350.       first_time = TRUE;
  4351.       for (i = 0; i < n_switches; i++)
  4352.     {
  4353.       char **args;
  4354.       if (!first_time)
  4355.         obstack_grow (&collect_obstack, " ", 1);
  4356.  
  4357.       first_time = FALSE;
  4358.       obstack_grow (&collect_obstack, "-", 1);
  4359.       obstack_grow (&collect_obstack, switches[i].part1,
  4360.             strlen (switches[i].part1));
  4361.  
  4362.       for (args = switches[i].args; args && *args; args++)
  4363.         {
  4364.           obstack_grow (&collect_obstack, " ", 1);
  4365.           obstack_grow (&collect_obstack, *args, strlen (*args));
  4366.         }
  4367.     }
  4368.       obstack_grow (&collect_obstack, "\0", 1);
  4369.       putenv (obstack_finish (&collect_obstack));
  4370.  
  4371.       value = do_spec (link_command_spec);
  4372.       if (value < 0)
  4373.     error_count = 1;
  4374.       linker_was_run = (tmp != execution_count);
  4375.     }
  4376.  
  4377.   /* Warn if a -B option was specified but the prefix was never used.  */
  4378.   unused_prefix_warnings (&exec_prefix);
  4379.   unused_prefix_warnings (&startfile_prefix);
  4380.  
  4381.   /* If options said don't run linker,
  4382.      complain about input files to be given to the linker.  */
  4383.  
  4384.   if (! linker_was_run && error_count == 0)
  4385.     for (i = 0; i < n_infiles; i++)
  4386.       if (explicit_link_files[i])
  4387.     error ("%s: linker input file unused since linking not done",
  4388.            outfiles[i]);
  4389.  
  4390.   /* Delete some or all of the temporary files we made.  */
  4391.  
  4392.   if (error_count)
  4393.     delete_failure_queue ();
  4394.   delete_temp_files ();
  4395.  
  4396.   exit (error_count > 0 ? (signal_count ? 2 : 1) : 0);
  4397.   /* NOTREACHED */
  4398.   return 0;
  4399. }
  4400.  
  4401. /* Find the proper compilation spec for the file name NAME,
  4402.    whose length is LENGTH.  LANGUAGE is the specified language,
  4403.    or 0 if none specified.  */
  4404.  
  4405. static struct compiler *
  4406. lookup_compiler (name, length, language)
  4407.      char *name;
  4408.      int length;
  4409.      char *language;
  4410. {
  4411.   struct compiler *cp;
  4412.  
  4413.   /* Look for the language, if one is spec'd.  */
  4414.   if (language != 0)
  4415.     {
  4416.       for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
  4417.     {
  4418.       if (language != 0)
  4419.         {
  4420.           if (cp->suffix[0] == '@'
  4421.           && !strcmp (cp->suffix + 1, language))
  4422.         return cp;
  4423.         }
  4424.     }
  4425.       error ("language %s not recognized", language);
  4426.     }
  4427.  
  4428.   /* Look for a suffix.  */
  4429.   for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
  4430.     {
  4431.       if (/* The suffix `-' matches only the file name `-'.  */
  4432.       (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
  4433.       ||
  4434.       (strlen (cp->suffix) < length
  4435.        /* See if the suffix matches the end of NAME.  */
  4436.        && !strcmp (cp->suffix,
  4437.                name + length - strlen (cp->suffix))))
  4438.     {
  4439.       if (cp->spec[0][0] == '@')
  4440.         {
  4441.           struct compiler *new;
  4442.           /* An alias entry maps a suffix to a language.
  4443.          Search for the language; pass 0 for NAME and LENGTH
  4444.          to avoid infinite recursion if language not found.
  4445.          Construct the new compiler spec.  */
  4446.           language = cp->spec[0] + 1;
  4447.           new = (struct compiler *) xmalloc (sizeof (struct compiler));
  4448.           new->suffix = cp->suffix;
  4449.           bcopy ((char *) lookup_compiler (NULL_PTR, 0, language)->spec,
  4450.              (char *) new->spec, sizeof new->spec);
  4451.           return new;
  4452.         }
  4453.       /* A non-alias entry: return it.  */
  4454.       return cp;
  4455.     }
  4456.     }
  4457.  
  4458.   return 0;
  4459. }
  4460.  
  4461. char *
  4462. xmalloc (size)
  4463.      unsigned size;
  4464. {
  4465.   register char *value = (char *) malloc (size);
  4466.   if (value == 0)
  4467.     fatal ("virtual memory exhausted");
  4468.   return value;
  4469. }
  4470.  
  4471. char *
  4472. xrealloc (ptr, size)
  4473.      char *ptr;
  4474.      unsigned size;
  4475. {
  4476.   register char *value = (char *) realloc (ptr, size);
  4477.   if (value == 0)
  4478.     fatal ("virtual memory exhausted");
  4479.   return value;
  4480. }
  4481.  
  4482. /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3.  */
  4483.  
  4484. static char *
  4485. concat (s1, s2, s3)
  4486.      char *s1, *s2, *s3;
  4487. {
  4488.   int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
  4489.   char *result = xmalloc (len1 + len2 + len3 + 1);
  4490.  
  4491.   strcpy (result, s1);
  4492.   strcpy (result + len1, s2);
  4493.   strcpy (result + len1 + len2, s3);
  4494.   *(result + len1 + len2 + len3) = 0;
  4495.  
  4496.   return result;
  4497. }
  4498.  
  4499. static char *
  4500. save_string (s, len)
  4501.      char *s;
  4502.      int len;
  4503. {
  4504.   register char *result = xmalloc (len + 1);
  4505.  
  4506.   bcopy (s, result, len);
  4507.   result[len] = 0;
  4508.   return result;
  4509. }
  4510.  
  4511. static void
  4512. pfatal_with_name (name)
  4513.      char *name;
  4514. {
  4515.   char *s;
  4516.  
  4517.   if (errno < sys_nerr)
  4518.     s = concat ("%s: ", sys_errlist[errno], "");
  4519.   else
  4520.     s = "cannot open %s";
  4521.   fatal (s, name);
  4522. }
  4523.  
  4524. static void
  4525. perror_with_name (name)
  4526.      char *name;
  4527. {
  4528.   char *s;
  4529.  
  4530.   if (errno < sys_nerr)
  4531.     s = concat ("%s: ", sys_errlist[errno], "");
  4532.   else
  4533.     s = "cannot open %s";
  4534.   error (s, name);
  4535. }
  4536.  
  4537. static void
  4538. perror_exec (name)
  4539.      char *name;
  4540. {
  4541.   char *s;
  4542.  
  4543.   if (errno < sys_nerr)
  4544.     s = concat ("installation problem, cannot exec %s: ",
  4545.         sys_errlist[errno], "");
  4546.   else
  4547.     s = "installation problem, cannot exec %s";
  4548.   error (s, name);
  4549. }
  4550.  
  4551. /* More 'friendly' abort that prints the line and file.
  4552.    config.h can #define abort fancy_abort if you like that sort of thing.  */
  4553.  
  4554. void
  4555. fancy_abort ()
  4556. {
  4557.   fatal ("Internal gcc abort.");
  4558. }
  4559.  
  4560. #ifdef HAVE_VPRINTF
  4561.  
  4562. /* Output an error message and exit */
  4563.  
  4564. static void
  4565. fatal VPROTO((char *format, ...))
  4566. {
  4567. #ifndef __STDC__
  4568.   char *format;
  4569. #endif
  4570.   va_list ap;
  4571.  
  4572.   VA_START (ap, format);
  4573.  
  4574. #ifndef __STDC__
  4575.   format = va_arg (ap, char*);
  4576. #endif
  4577.  
  4578.   fprintf (stderr, "%s: ", programname);
  4579.   vfprintf (stderr, format, ap);
  4580.   va_end (ap);
  4581.   fprintf (stderr, "\n");
  4582.   delete_temp_files ();
  4583.   exit (1);
  4584. }
  4585.  
  4586. static void
  4587. error VPROTO((char *format, ...))
  4588. {
  4589. #ifndef __STDC__
  4590.   char *format;
  4591. #endif
  4592.   va_list ap;
  4593.  
  4594.   VA_START (ap, format);
  4595.  
  4596. #ifndef __STDC__
  4597.   format = va_arg (ap, char*);
  4598. #endif
  4599.  
  4600.   fprintf (stderr, "%s: ", programname);
  4601.   vfprintf (stderr, format, ap);
  4602.   va_end (ap);
  4603.  
  4604.   fprintf (stderr, "\n");
  4605. }
  4606.  
  4607. #else /* not HAVE_VPRINTF */
  4608.  
  4609. static void
  4610. fatal (msg, arg1, arg2)
  4611.      char *msg, *arg1, *arg2;
  4612. {
  4613.   error (msg, arg1, arg2);
  4614.   delete_temp_files ();
  4615.   exit (1);
  4616. }
  4617.  
  4618. static void
  4619. error (msg, arg1, arg2)
  4620.      char *msg, *arg1, *arg2;
  4621. {
  4622.   fprintf (stderr, "%s: ", programname);
  4623.   fprintf (stderr, msg, arg1, arg2);
  4624.   fprintf (stderr, "\n");
  4625. }
  4626.  
  4627. #endif /* not HAVE_VPRINTF */
  4628.  
  4629.  
  4630. static void
  4631. validate_all_switches ()
  4632. {
  4633.   struct compiler *comp;
  4634.   register char *p;
  4635.   register char c;
  4636.   struct spec_list *spec;
  4637.  
  4638.   for (comp = compilers; comp->spec[0]; comp++)
  4639.     {
  4640.       int i;
  4641.       for (i = 0; i < sizeof comp->spec / sizeof comp->spec[0] && comp->spec[i]; i++)
  4642.     {
  4643.       p = comp->spec[i];
  4644.       while (c = *p++)
  4645.         if (c == '%' && *p == '{')
  4646.           /* We have a switch spec.  */
  4647.           validate_switches (p + 1);
  4648.     }
  4649.     }
  4650.  
  4651.   /* look through the linked list of extra specs read from the specs file */
  4652.   for (spec = specs; spec ; spec = spec->next)
  4653.     {
  4654.       p = spec->spec;
  4655.       while (c = *p++)
  4656.     if (c == '%' && *p == '{')
  4657.       /* We have a switch spec.  */
  4658.       validate_switches (p + 1);
  4659.     }
  4660.  
  4661.   p = link_command_spec;
  4662.   while (c = *p++)
  4663.     if (c == '%' && *p == '{')
  4664.       /* We have a switch spec.  */
  4665.       validate_switches (p + 1);
  4666.  
  4667.   /* Now notice switches mentioned in the machine-specific specs.  */
  4668.  
  4669.   p = asm_spec;
  4670.   while (c = *p++)
  4671.     if (c == '%' && *p == '{')
  4672.       /* We have a switch spec.  */
  4673.       validate_switches (p + 1);
  4674.  
  4675.   p = asm_final_spec;
  4676.   while (c = *p++)
  4677.     if (c == '%' && *p == '{')
  4678.       /* We have a switch spec.  */
  4679.       validate_switches (p + 1);
  4680.  
  4681.   p = cpp_spec;
  4682.   while (c = *p++)
  4683.     if (c == '%' && *p == '{')
  4684.       /* We have a switch spec.  */
  4685.       validate_switches (p + 1);
  4686.  
  4687.   p = signed_char_spec;
  4688.   while (c = *p++)
  4689.     if (c == '%' && *p == '{')
  4690.       /* We have a switch spec.  */
  4691.       validate_switches (p + 1);
  4692.  
  4693.   p = cc1_spec;
  4694.   while (c = *p++)
  4695.     if (c == '%' && *p == '{')
  4696.       /* We have a switch spec.  */
  4697.       validate_switches (p + 1);
  4698.  
  4699.   p = cc1plus_spec;
  4700.   while (c = *p++)
  4701.     if (c == '%' && *p == '{')
  4702.       /* We have a switch spec.  */
  4703.       validate_switches (p + 1);
  4704.  
  4705.   p = link_spec;
  4706.   while (c = *p++)
  4707.     if (c == '%' && *p == '{')
  4708.       /* We have a switch spec.  */
  4709.       validate_switches (p + 1);
  4710.  
  4711.   p = lib_spec;
  4712.   while (c = *p++)
  4713.     if (c == '%' && *p == '{')
  4714.       /* We have a switch spec.  */
  4715.       validate_switches (p + 1);
  4716.  
  4717.   p = startfile_spec;
  4718.   while (c = *p++)
  4719.     if (c == '%' && *p == '{')
  4720.       /* We have a switch spec.  */
  4721.       validate_switches (p + 1);
  4722. }
  4723.  
  4724. /* Look at the switch-name that comes after START
  4725.    and mark as valid all supplied switches that match it.  */
  4726.  
  4727. static void
  4728. validate_switches (start)
  4729.      char *start;
  4730. {
  4731.   register char *p = start;
  4732.   char *filter;
  4733.   register int i;
  4734.   int suffix = 0;
  4735.  
  4736.   if (*p == '|')
  4737.     ++p;
  4738.  
  4739.   if (*p == '!')
  4740.     ++p;
  4741.  
  4742.   if (*p == '.')
  4743.     suffix = 1, ++p;
  4744.  
  4745.   filter = p;
  4746.   while (*p != ':' && *p != '}') p++;
  4747.  
  4748.   if (suffix)
  4749.     ;
  4750.   else if (p[-1] == '*')
  4751.     {
  4752.       /* Mark all matching switches as valid.  */
  4753.       --p;
  4754.       for (i = 0; i < n_switches; i++)
  4755.     if (!strncmp (switches[i].part1, filter, p - filter))
  4756.       switches[i].valid = 1;
  4757.     }
  4758.   else
  4759.     {
  4760.       /* Mark an exact matching switch as valid.  */
  4761.       for (i = 0; i < n_switches; i++)
  4762.     {
  4763.       if (!strncmp (switches[i].part1, filter, p - filter)
  4764.           && switches[i].part1[p - filter] == 0)
  4765.         switches[i].valid = 1;
  4766.     }
  4767.     }
  4768. }
  4769.  
  4770. /* Check whether a particular argument was used.  */
  4771.  
  4772. static int
  4773. used_arg (p, len)
  4774.      char *p;
  4775.      int len;
  4776. {
  4777.   int i;
  4778.  
  4779.   for (i = 0; i < n_switches; i++)
  4780.     if (! strncmp (switches[i].part1, p, len)
  4781.     && strlen (switches[i].part1) == len)
  4782.       return 1;
  4783.   return 0;
  4784. }
  4785.  
  4786. /* Work out the subdirectory to use based on the
  4787.    options.  The format of multilib_select is a list of elements.
  4788.    Each element is a subdirectory name followed by a list of options
  4789.    followed by a semicolon.  gcc will consider each line in turn.  If
  4790.    none of the options beginning with an exclamation point are
  4791.    present, and all of the other options are present, that
  4792.    subdirectory will be used.  */
  4793.  
  4794. static void
  4795. set_multilib_dir ()
  4796. {
  4797.   char *p = multilib_select;
  4798.   int this_path_len;
  4799.   char *this_path, *this_arg;
  4800.   int failed;
  4801.  
  4802.   while (*p != '\0')
  4803.     {
  4804.       /* Ignore newlines.  */
  4805.       if (*p == '\n')
  4806.     {
  4807.       ++p;
  4808.       continue;
  4809.     }
  4810.  
  4811.       /* Get the initial path.  */
  4812.       this_path = p;
  4813.       while (*p != ' ')
  4814.     {
  4815.       if (*p == '\0')
  4816.         abort ();
  4817.       ++p;
  4818.     }
  4819.       this_path_len = p - this_path;
  4820.  
  4821.       /* Check the arguments.  */
  4822.       failed = 0;
  4823.       ++p;
  4824.       while (*p != ';')
  4825.     {
  4826.       if (*p == '\0')
  4827.         abort ();
  4828.  
  4829.       if (failed)
  4830.         {
  4831.           ++p;
  4832.           continue;
  4833.         }
  4834.  
  4835.       this_arg = p;
  4836.       while (*p != ' ' && *p != ';')
  4837.         {
  4838.           if (*p == '\0')
  4839.         abort ();
  4840.           ++p;
  4841.         }
  4842.  
  4843.       if (*this_arg == '!')
  4844.         failed = used_arg (this_arg + 1, p - (this_arg + 1));
  4845.       else
  4846.         failed = ! used_arg (this_arg, p - this_arg);
  4847.  
  4848.       if (*p == ' ')
  4849.         ++p;
  4850.     }
  4851.  
  4852.       if (! failed)
  4853.     {
  4854.       if (this_path_len != 1
  4855.           || this_path[0] != '.')
  4856.         {
  4857.           multilib_dir = xmalloc (this_path_len + 1);
  4858.           strncpy (multilib_dir, this_path, this_path_len);
  4859.           multilib_dir[this_path_len] = '\0';
  4860.         }
  4861.       break;
  4862.     }
  4863.  
  4864.       ++p;
  4865.     }      
  4866. }
  4867.  
  4868. /* Print out the multiple library subdirectory selection
  4869.    information.  This prints out a series of lines.  Each line looks
  4870.    like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
  4871.    required.  Only the desired options are printed out, the negative
  4872.    matches.  The options are print without a leading dash.  There are
  4873.    no spaces to make it easy to use the information in the shell.
  4874.    Each subdirectory is printed only once.  This assumes the ordering
  4875.    generated by the genmultilib script.  */
  4876.  
  4877. static void
  4878. print_multilib_info ()
  4879. {
  4880.   char *p = multilib_select;
  4881.   char *last_path, *this_path;
  4882.   int last_path_len, skip, use_arg;
  4883.  
  4884.   while (*p != '\0')
  4885.     {
  4886.       /* Ignore newlines.  */
  4887.       if (*p == '\n')
  4888.     {
  4889.       ++p;
  4890.       continue;
  4891.     }
  4892.  
  4893.       /* Get the initial path.  */
  4894.       this_path = p;
  4895.       while (*p != ' ')
  4896.     {
  4897.       if (*p == '\0')
  4898.         abort ();
  4899.       ++p;
  4900.     }
  4901.  
  4902.       /* If this is a duplicate, skip it.  */
  4903.       skip = (p - this_path == last_path_len
  4904.           && ! strncmp (last_path, this_path, last_path_len));
  4905.  
  4906.       last_path = this_path;
  4907.       last_path_len = p - this_path;
  4908.  
  4909.       if (! skip)
  4910.     {
  4911.       char *p1;
  4912.  
  4913.       for (p1 = last_path; p1 < p; p1++)
  4914.         putchar (*p1);
  4915.       putchar (';');
  4916.     }
  4917.  
  4918.       ++p;
  4919.       while (*p != ';')
  4920.     {
  4921.       int use_arg;
  4922.  
  4923.       if (*p == '\0')
  4924.         abort ();
  4925.  
  4926.       if (skip)
  4927.         {
  4928.           ++p;
  4929.           continue;
  4930.         }
  4931.  
  4932.       use_arg = *p != '!';
  4933.  
  4934.       if (use_arg)
  4935.         putchar ('@');
  4936.  
  4937.       while (*p != ' ' && *p != ';')
  4938.         {
  4939.           if (*p == '\0')
  4940.         abort ();
  4941.           if (use_arg)
  4942.         putchar (*p);
  4943.           ++p;
  4944.         }
  4945.  
  4946.       if (*p == ' ')
  4947.         ++p;
  4948.     }
  4949.  
  4950.       if (! skip)
  4951.     putchar ('\n');
  4952.  
  4953.       ++p;
  4954.     }
  4955. }
  4956.