]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/gcc/cppinit.c
This commit was generated by cvs2svn to compensate for changes in r102782,
[FreeBSD/FreeBSD.git] / contrib / gcc / cppinit.c
1 /* CPP Library.
2    Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4    Contributed by Per Bothner, 1994-95.
5    Based on CCCP program by Paul Rubin, June 1986
6    Adapted to ANSI C, Richard Stallman, Jan 1987
7
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
11 later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
21
22 /* $FreeBSD$ */
23
24 #include "config.h"
25 #include "system.h"
26 #include "cpplib.h"
27 #include "cpphash.h"
28 #include "prefix.h"
29 #include "intl.h"
30 #include "version.h"
31 #include "mkdeps.h"
32 #include "cppdefault.h"
33 #include "except.h"     /* for USING_SJLJ_EXCEPTIONS */
34
35 /* Predefined symbols, built-in macros, and the default include path.  */
36
37 #ifndef GET_ENV_PATH_LIST
38 #define GET_ENV_PATH_LIST(VAR,NAME)     do { (VAR) = getenv (NAME); } while (0)
39 #endif
40
41 /* Windows does not natively support inodes, and neither does MSDOS.
42    Cygwin's emulation can generate non-unique inodes, so don't use it.
43    VMS has non-numeric inodes.  */
44 #ifdef VMS
45 # define INO_T_EQ(A, B) (!memcmp (&(A), &(B), sizeof (A)))
46 # define INO_T_COPY(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof (SRC))
47 #else
48 # if (defined _WIN32 && ! defined (_UWIN)) || defined __MSDOS__
49 #  define INO_T_EQ(A, B) 0
50 # else
51 #  define INO_T_EQ(A, B) ((A) == (B))
52 # endif
53 # define INO_T_COPY(DEST, SRC) (DEST) = (SRC)
54 #endif
55
56 /* Internal structures and prototypes.  */
57
58 /* A `struct pending_option' remembers one -D, -A, -U, -include, or
59    -imacros switch.  */
60 typedef void (* cl_directive_handler) PARAMS ((cpp_reader *, const char *));
61 struct pending_option
62 {
63   struct pending_option *next;
64   const char *arg;
65   cl_directive_handler handler;
66 };
67
68 /* The `pending' structure accumulates all the options that are not
69    actually processed until we hit cpp_read_main_file.  It consists of
70    several lists, one for each type of option.  We keep both head and
71    tail pointers for quick insertion.  */
72 struct cpp_pending
73 {
74   struct pending_option *directive_head, *directive_tail;
75
76   struct search_path *quote_head, *quote_tail;
77   struct search_path *brack_head, *brack_tail;
78   struct search_path *systm_head, *systm_tail;
79   struct search_path *after_head, *after_tail;
80
81   struct pending_option *imacros_head, *imacros_tail;
82   struct pending_option *include_head, *include_tail;
83 };
84
85 #ifdef __STDC__
86 #define APPEND(pend, list, elt) \
87   do {  if (!(pend)->list##_head) (pend)->list##_head = (elt); \
88         else (pend)->list##_tail->next = (elt); \
89         (pend)->list##_tail = (elt); \
90   } while (0)
91 #else
92 #define APPEND(pend, list, elt) \
93   do {  if (!(pend)->list/**/_head) (pend)->list/**/_head = (elt); \
94         else (pend)->list/**/_tail->next = (elt); \
95         (pend)->list/**/_tail = (elt); \
96   } while (0)
97 #endif
98
99 static void print_help                  PARAMS ((void));
100 static void path_include                PARAMS ((cpp_reader *,
101                                                  char *, int));
102 static void init_library                PARAMS ((void));
103 static void init_builtins               PARAMS ((cpp_reader *));
104 static void append_include_chain        PARAMS ((cpp_reader *,
105                                                  char *, int, int));
106 static struct search_path * remove_dup_dir      PARAMS ((cpp_reader *,
107                                                  struct search_path *));
108 static struct search_path * remove_dup_dirs PARAMS ((cpp_reader *,
109                                                  struct search_path *));
110 static void merge_include_chains        PARAMS ((cpp_reader *));
111 static bool push_include                PARAMS ((cpp_reader *,
112                                                  struct pending_option *));
113 static void free_chain                  PARAMS ((struct pending_option *));
114 static void set_lang                    PARAMS ((cpp_reader *, enum c_lang));
115 static void init_dependency_output      PARAMS ((cpp_reader *));
116 static void init_standard_includes      PARAMS ((cpp_reader *));
117 static void read_original_filename      PARAMS ((cpp_reader *));
118 static void new_pending_directive       PARAMS ((struct cpp_pending *,
119                                                  const char *,
120                                                  cl_directive_handler));
121 static void output_deps                 PARAMS ((cpp_reader *));
122 static int parse_option                 PARAMS ((const char *));
123
124 /* Fourth argument to append_include_chain: chain to use.
125    Note it's never asked to append to the quote chain.  */
126 enum { BRACKET = 0, SYSTEM, AFTER };
127
128 /* If we have designated initializers (GCC >2.7) these tables can be
129    initialized, constant data.  Otherwise, they have to be filled in at
130    runtime.  */
131 #if HAVE_DESIGNATED_INITIALIZERS
132
133 #define init_trigraph_map()  /* Nothing.  */
134 #define TRIGRAPH_MAP \
135 __extension__ const U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = {
136
137 #define END };
138 #define s(p, v) [p] = v,
139
140 #else
141
142 #define TRIGRAPH_MAP U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = { 0 }; \
143  static void init_trigraph_map PARAMS ((void)) { \
144  unsigned char *x = _cpp_trigraph_map;
145
146 #define END }
147 #define s(p, v) x[p] = v;
148
149 #endif
150
151 TRIGRAPH_MAP
152   s('=', '#')   s(')', ']')     s('!', '|')
153   s('(', '[')   s('\'', '^')    s('>', '}')
154   s('/', '\\')  s('<', '{')     s('-', '~')
155 END
156
157 #undef s
158 #undef END
159 #undef TRIGRAPH_MAP
160
161 /* Given a colon-separated list of file names PATH,
162    add all the names to the search path for include files.  */
163 static void
164 path_include (pfile, list, path)
165      cpp_reader *pfile;
166      char *list;
167      int path;
168 {
169   char *p, *q, *name;
170
171   p = list;
172
173   do
174     {
175       /* Find the end of this name.  */
176       q = p;
177       while (*q != 0 && *q != PATH_SEPARATOR) q++;
178       if (q == p)
179         {
180           /* An empty name in the path stands for the current directory.  */
181           name = (char *) xmalloc (2);
182           name[0] = '.';
183           name[1] = 0;
184         }
185       else
186         {
187           /* Otherwise use the directory that is named.  */
188           name = (char *) xmalloc (q - p + 1);
189           memcpy (name, p, q - p);
190           name[q - p] = 0;
191         }
192
193       append_include_chain (pfile, name, path, 0);
194
195       /* Advance past this name.  */
196       if (*q == 0)
197         break;
198       p = q + 1;
199     }
200   while (1);
201 }
202
203 /* Append DIR to include path PATH.  DIR must be allocated on the
204    heap; this routine takes responsibility for freeing it.  CXX_AWARE
205    is non-zero if the header contains extern "C" guards for C++,
206    otherwise it is zero.  */
207 static void
208 append_include_chain (pfile, dir, path, cxx_aware)
209      cpp_reader *pfile;
210      char *dir;
211      int path;
212      int cxx_aware ATTRIBUTE_UNUSED;
213 {
214   struct cpp_pending *pend = CPP_OPTION (pfile, pending);
215   struct search_path *new;
216   struct stat st;
217   unsigned int len;
218
219   if (*dir == '\0')
220     {
221       free (dir);
222       dir = xstrdup (".");
223     }
224   _cpp_simplify_pathname (dir);
225
226   if (stat (dir, &st))
227     {
228       /* Dirs that don't exist are silently ignored.  */
229       if (errno != ENOENT)
230         cpp_notice_from_errno (pfile, dir);
231       else if (CPP_OPTION (pfile, verbose))
232         fprintf (stderr, _("ignoring nonexistent directory \"%s\"\n"), dir);
233       free (dir);
234       return;
235     }
236
237   if (!S_ISDIR (st.st_mode))
238     {
239       cpp_notice (pfile, "%s: Not a directory", dir);
240       free (dir);
241       return;
242     }
243
244   len = strlen (dir);
245   if (len > pfile->max_include_len)
246     pfile->max_include_len = len;
247
248   new = (struct search_path *) xmalloc (sizeof (struct search_path));
249   new->name = dir;
250   new->len = len;
251   INO_T_COPY (new->ino, st.st_ino);
252   new->dev  = st.st_dev;
253   /* Both systm and after include file lists should be treated as system
254      include files since these two lists are really just a concatenation
255      of one "system" list.  */
256   if (path == SYSTEM || path == AFTER)
257 #ifdef NO_IMPLICIT_EXTERN_C
258     new->sysp = 1;
259 #else
260     new->sysp = cxx_aware ? 1 : 2;
261 #endif
262   else
263     new->sysp = 0;
264   new->name_map = NULL;
265   new->next = NULL;
266
267   switch (path)
268     {
269     case BRACKET:       APPEND (pend, brack, new); break;
270     case SYSTEM:        APPEND (pend, systm, new); break;
271     case AFTER:         APPEND (pend, after, new); break;
272     }
273 }
274
275 /* Handle a duplicated include path.  PREV is the link in the chain
276    before the duplicate.  The duplicate is removed from the chain and
277    freed.  Returns PREV.  */
278 static struct search_path *
279 remove_dup_dir (pfile, prev)
280      cpp_reader *pfile;
281      struct search_path *prev;
282 {
283   struct search_path *cur = prev->next;
284
285   if (CPP_OPTION (pfile, verbose))
286     fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), cur->name);
287
288   prev->next = cur->next;
289   free ((PTR) cur->name);
290   free (cur);
291
292   return prev;
293 }
294
295 /* Remove duplicate directories from a chain.  Returns the tail of the
296    chain, or NULL if the chain is empty.  This algorithm is quadratic
297    in the number of -I switches, which is acceptable since there
298    aren't usually that many of them.  */
299 static struct search_path *
300 remove_dup_dirs (pfile, head)
301      cpp_reader *pfile;
302      struct search_path *head;
303 {
304   struct search_path *prev = NULL, *cur, *other;
305
306   for (cur = head; cur; cur = cur->next)
307     {
308       for (other = head; other != cur; other = other->next)
309         if (INO_T_EQ (cur->ino, other->ino) && cur->dev == other->dev)
310           {
311             if (cur->sysp && !other->sysp)
312               {
313                 cpp_warning (pfile,
314                              "changing search order for system directory \"%s\"",
315                              cur->name);
316                 if (strcmp (cur->name, other->name))
317                   cpp_warning (pfile, 
318                                "  as it is the same as non-system directory \"%s\"",
319                                other->name);
320                 else
321                   cpp_warning (pfile, 
322                                "  as it has already been specified as a non-system directory");
323               }
324             cur = remove_dup_dir (pfile, prev);
325             break;
326           }
327       prev = cur;
328     }
329
330   return prev;
331 }
332
333 /* Merge the four include chains together in the order quote, bracket,
334    system, after.  Remove duplicate dirs (as determined by
335    INO_T_EQ()).  The system_include and after_include chains are never
336    referred to again after this function; all access is through the
337    bracket_include path.  */
338 static void
339 merge_include_chains (pfile)
340      cpp_reader *pfile;
341 {
342   struct search_path *quote, *brack, *systm, *qtail;
343
344   struct cpp_pending *pend = CPP_OPTION (pfile, pending);
345
346   quote = pend->quote_head;
347   brack = pend->brack_head;
348   systm = pend->systm_head;
349   qtail = pend->quote_tail;
350
351   /* Paste together bracket, system, and after include chains.  */
352   if (systm)
353     pend->systm_tail->next = pend->after_head;
354   else
355     systm = pend->after_head;
356
357   if (brack)
358     pend->brack_tail->next = systm;
359   else
360     brack = systm;
361
362   /* This is a bit tricky.  First we drop dupes from the quote-include
363      list.  Then we drop dupes from the bracket-include list.
364      Finally, if qtail and brack are the same directory, we cut out
365      brack and move brack up to point to qtail.
366
367      We can't just merge the lists and then uniquify them because
368      then we may lose directories from the <> search path that should
369      be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however
370      safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written
371      -Ibar -I- -Ifoo -Iquux.  */
372
373   remove_dup_dirs (pfile, brack);
374   qtail = remove_dup_dirs (pfile, quote);
375
376   if (quote)
377     {
378       qtail->next = brack;
379
380       /* If brack == qtail, remove brack as it's simpler.  */
381       if (brack && INO_T_EQ (qtail->ino, brack->ino)
382           && qtail->dev == brack->dev)
383         brack = remove_dup_dir (pfile, qtail);
384     }
385   else
386     quote = brack;
387
388   CPP_OPTION (pfile, quote_include) = quote;
389   CPP_OPTION (pfile, bracket_include) = brack;
390 }
391
392 /* A set of booleans indicating what CPP features each source language
393    requires.  */
394 struct lang_flags
395 {
396   char c99;
397   char objc;
398   char cplusplus;
399   char extended_numbers;
400   char trigraphs;
401   char dollars_in_ident;
402   char cplusplus_comments;
403   char digraphs;
404 };
405
406 /* ??? Enable $ in identifiers in assembly? */
407 static const struct lang_flags lang_defaults[] =
408 { /*              c99 objc c++ xnum trig dollar c++comm digr  */
409   /* GNUC89 */  { 0,  0,   0,  1,   0,   1,     1,      1     },
410   /* GNUC99 */  { 1,  0,   0,  1,   0,   1,     1,      1     },
411   /* STDC89 */  { 0,  0,   0,  0,   1,   0,     0,      0     },
412   /* STDC94 */  { 0,  0,   0,  0,   1,   0,     0,      1     },
413   /* STDC99 */  { 1,  0,   0,  1,   1,   0,     1,      1     },
414   /* GNUCXX */  { 0,  0,   1,  1,   0,   1,     1,      1     },
415   /* CXX98  */  { 0,  0,   1,  1,   1,   0,     1,      1     },
416   /* OBJC   */  { 0,  1,   0,  1,   0,   1,     1,      1     },
417   /* OBJCXX */  { 0,  1,   1,  1,   0,   1,     1,      1     },
418   /* ASM    */  { 0,  0,   0,  1,   0,   0,     1,      0     }
419 };
420
421 /* Sets internal flags correctly for a given language.  */
422 static void
423 set_lang (pfile, lang)
424      cpp_reader *pfile;
425      enum c_lang lang;
426 {
427   const struct lang_flags *l = &lang_defaults[(int) lang];
428   
429   CPP_OPTION (pfile, lang) = lang;
430
431   CPP_OPTION (pfile, c99)                = l->c99;
432   CPP_OPTION (pfile, objc)               = l->objc;
433   CPP_OPTION (pfile, cplusplus)          = l->cplusplus;
434   CPP_OPTION (pfile, extended_numbers)   = l->extended_numbers;
435   CPP_OPTION (pfile, trigraphs)          = l->trigraphs;
436   CPP_OPTION (pfile, dollars_in_ident)   = l->dollars_in_ident;
437   CPP_OPTION (pfile, cplusplus_comments) = l->cplusplus_comments;
438   CPP_OPTION (pfile, digraphs)           = l->digraphs;
439 }
440
441 #ifdef HOST_EBCDIC
442 static int opt_comp PARAMS ((const void *, const void *));
443
444 /* Run-time sorting of options array.  */
445 static int
446 opt_comp (p1, p2)
447      const void *p1, *p2;
448 {
449   return strcmp (((struct cl_option *) p1)->opt_text,
450                  ((struct cl_option *) p2)->opt_text);
451 }
452 #endif
453
454 /* init initializes library global state.  It might not need to
455    do anything depending on the platform and compiler.  */
456 static void
457 init_library ()
458 {
459   static int initialized = 0;
460
461   if (! initialized)
462     {
463       initialized = 1;
464
465 #ifdef HOST_EBCDIC
466       /* For non-ASCII hosts, the cl_options array needs to be sorted at
467          runtime.  */
468       qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
469 #endif
470
471       /* Set up the trigraph map.  This doesn't need to do anything if
472          we were compiled with a compiler that supports C99 designated
473          initializers.  */
474       init_trigraph_map ();
475     }
476 }
477
478 /* Initialize a cpp_reader structure.  */
479 cpp_reader *
480 cpp_create_reader (lang)
481      enum c_lang lang;
482 {
483   cpp_reader *pfile;
484
485   /* Initialise this instance of the library if it hasn't been already.  */
486   init_library ();
487
488   pfile = (cpp_reader *) xcalloc (1, sizeof (cpp_reader));
489
490   set_lang (pfile, lang);
491   CPP_OPTION (pfile, warn_import) = 1;
492   CPP_OPTION (pfile, discard_comments) = 1;
493   CPP_OPTION (pfile, show_column) = 1;
494   CPP_OPTION (pfile, tabstop) = 8;
495   CPP_OPTION (pfile, operator_names) = 1;
496 #if DEFAULT_SIGNED_CHAR
497   CPP_OPTION (pfile, signed_char) = 1;
498 #else
499   CPP_OPTION (pfile, signed_char) = 0;
500 #endif
501
502   CPP_OPTION (pfile, pending) =
503     (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
504
505   /* It's simplest to just create this struct whether or not it will
506      be needed.  */
507   pfile->deps = deps_init ();
508
509   /* Initialise the line map.  Start at logical line 1, so we can use
510      a line number of zero for special states.  */
511   init_line_maps (&pfile->line_maps);
512   pfile->line = 1;
513
514   /* Initialize lexer state.  */
515   pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
516
517   /* Set up static tokens.  */
518   pfile->date.type = CPP_EOF;
519   pfile->avoid_paste.type = CPP_PADDING;
520   pfile->avoid_paste.val.source = NULL;
521   pfile->eof.type = CPP_EOF;
522   pfile->eof.flags = 0;
523
524   /* Create a token buffer for the lexer.  */
525   _cpp_init_tokenrun (&pfile->base_run, 250);
526   pfile->cur_run = &pfile->base_run;
527   pfile->cur_token = pfile->base_run.base;
528
529   /* Initialise the base context.  */
530   pfile->context = &pfile->base_context;
531   pfile->base_context.macro = 0;
532   pfile->base_context.prev = pfile->base_context.next = 0;
533
534   /* Aligned and unaligned storage.  */
535   pfile->a_buff = _cpp_get_buff (pfile, 0);
536   pfile->u_buff = _cpp_get_buff (pfile, 0);
537
538   /* Initialise the buffer obstack.  */
539   gcc_obstack_init (&pfile->buffer_ob);
540
541   _cpp_init_includes (pfile);
542
543   return pfile;
544 }
545
546 /* Free resources used by PFILE.  Accessing PFILE after this function
547    returns leads to undefined behaviour.  Returns the error count.  */
548 int
549 cpp_destroy (pfile)
550      cpp_reader *pfile;
551 {
552   int result;
553   struct search_path *dir, *dirn;
554   cpp_context *context, *contextn;
555   tokenrun *run, *runn;
556
557   while (CPP_BUFFER (pfile) != NULL)
558     _cpp_pop_buffer (pfile);
559
560   if (pfile->macro_buffer)
561     {
562       free ((PTR) pfile->macro_buffer);
563       pfile->macro_buffer = NULL;
564       pfile->macro_buffer_len = 0;
565     }
566
567   deps_free (pfile->deps);
568   obstack_free (&pfile->buffer_ob, 0);
569
570   _cpp_destroy_hashtable (pfile);
571   _cpp_cleanup_includes (pfile);
572
573   _cpp_free_buff (pfile->a_buff);
574   _cpp_free_buff (pfile->u_buff);
575   _cpp_free_buff (pfile->free_buffs);
576
577   for (run = &pfile->base_run; run; run = runn)
578     {
579       runn = run->next;
580       free (run->base);
581       if (run != &pfile->base_run)
582         free (run);
583     }
584
585   for (dir = CPP_OPTION (pfile, quote_include); dir; dir = dirn)
586     {
587       dirn = dir->next;
588       free ((PTR) dir->name);
589       free (dir);
590     }
591
592   for (context = pfile->base_context.next; context; context = contextn)
593     {
594       contextn = context->next;
595       free (context);
596     }
597
598   free_line_maps (&pfile->line_maps);
599
600   result = pfile->errors;
601   free (pfile);
602
603   return result;
604 }
605
606
607 /* This structure defines one built-in identifier.  A node will be
608    entered in the hash table under the name NAME, with value VALUE (if
609    any).  If flags has OPERATOR, the node's operator field is used; if
610    flags has BUILTIN the node's builtin field is used.  Macros that are
611    known at build time should not be flagged BUILTIN, as then they do
612    not appear in macro dumps with e.g. -dM or -dD.
613
614    Two values are not compile time constants, so we tag
615    them in the FLAGS field instead:
616    VERS         value is the global version_string, quoted
617    ULP          value is the global user_label_prefix
618
619    Also, macros with CPLUS set in the flags field are entered only for C++.  */
620 struct builtin
621 {
622   const U_CHAR *name;
623   const char *value;
624   unsigned char builtin;
625   unsigned char operator;
626   unsigned short flags;
627   unsigned short len;
628 };
629 #define VERS            0x01
630 #define ULP             0x02
631 #define CPLUS           0x04
632 #define BUILTIN         0x08
633 #define OPERATOR        0x10
634
635 #define B(n, t)       { U n, 0, t, 0, BUILTIN, sizeof n - 1 }
636 #define C(n, v)       { U n, v, 0, 0, 0, sizeof n - 1 }
637 #define X(n, f)       { U n, 0, 0, 0, f, sizeof n - 1 }
638 #define O(n, c, f)    { U n, 0, 0, c, OPERATOR | f, sizeof n - 1 }
639 static const struct builtin builtin_array[] =
640 {
641   B("__TIME__",          BT_TIME),
642   B("__DATE__",          BT_DATE),
643   B("__FILE__",          BT_FILE),
644   B("__BASE_FILE__",     BT_BASE_FILE),
645   B("__LINE__",          BT_SPECLINE),
646   B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL),
647   B("_Pragma",           BT_PRAGMA),
648
649   X("__VERSION__",              VERS),
650   X("__USER_LABEL_PREFIX__",    ULP),
651   C("__REGISTER_PREFIX__",      REGISTER_PREFIX),
652   C("__HAVE_BUILTIN_SETJMP__",  "1"),
653 #if USING_SJLJ_EXCEPTIONS
654   /* libgcc needs to know this.  */
655   C("__USING_SJLJ_EXCEPTIONS__","1"),
656 #endif
657 #ifndef NO_BUILTIN_SIZE_TYPE
658   C("__SIZE_TYPE__",            SIZE_TYPE),
659 #endif
660 #ifndef NO_BUILTIN_PTRDIFF_TYPE
661   C("__PTRDIFF_TYPE__",         PTRDIFF_TYPE),
662 #endif
663 #ifndef NO_BUILTIN_WCHAR_TYPE
664   C("__WCHAR_TYPE__",           WCHAR_TYPE),
665 #endif
666 #ifndef NO_BUILTIN_WINT_TYPE
667   C("__WINT_TYPE__",            WINT_TYPE),
668 #endif
669 #ifdef STDC_0_IN_SYSTEM_HEADERS
670   B("__STDC__",          BT_STDC),
671 #else
672   C("__STDC__",          "1"),
673 #endif
674
675   /* Named operators known to the preprocessor.  These cannot be #defined
676      and always have their stated meaning.  They are treated like normal
677      identifiers except for the type code and the meaning.  Most of them
678      are only for C++ (but see iso646.h).  */
679   O("and",      CPP_AND_AND, CPLUS),
680   O("and_eq",   CPP_AND_EQ,  CPLUS),
681   O("bitand",   CPP_AND,     CPLUS),
682   O("bitor",    CPP_OR,      CPLUS),
683   O("compl",    CPP_COMPL,   CPLUS),
684   O("not",      CPP_NOT,     CPLUS),
685   O("not_eq",   CPP_NOT_EQ,  CPLUS),
686   O("or",       CPP_OR_OR,   CPLUS),
687   O("or_eq",    CPP_OR_EQ,   CPLUS),
688   O("xor",      CPP_XOR,     CPLUS),
689   O("xor_eq",   CPP_XOR_EQ,  CPLUS)
690 };
691 #undef B
692 #undef C
693 #undef X
694 #undef O
695 #define builtin_array_end \
696  builtin_array + sizeof(builtin_array)/sizeof(struct builtin)
697
698 /* Subroutine of cpp_read_main_file; reads the builtins table above and
699    enters them, and language-specific macros, into the hash table.  */
700 static void
701 init_builtins (pfile)
702      cpp_reader *pfile;
703 {
704   const struct builtin *b;
705
706   for(b = builtin_array; b < builtin_array_end; b++)
707     {
708       if ((b->flags & CPLUS) && ! CPP_OPTION (pfile, cplusplus))
709         continue;
710
711       if ((b->flags & OPERATOR) && ! CPP_OPTION (pfile, operator_names))
712         continue;
713
714       if (b->flags & (OPERATOR | BUILTIN))
715         {
716           cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
717           if (b->flags & OPERATOR)
718             {
719               hp->flags |= NODE_OPERATOR;
720               hp->value.operator = b->operator;
721             }
722           else
723             {
724               hp->type = NT_MACRO;
725               hp->flags |= NODE_BUILTIN | NODE_WARN;
726               hp->value.builtin = b->builtin;
727             }
728         }
729       else                      /* A standard macro of some kind.  */
730         {
731           const char *val;
732           char *str;
733
734           if (b->flags & VERS)
735             {
736               /* Allocate enough space for 'name "value"\n\0'.  */
737               str = alloca (b->len + strlen (version_string) + 5);
738               sprintf (str, "%s \"%s\"\n", b->name, version_string);
739             }
740           else
741             {
742               if (b->flags & ULP)
743                 val = CPP_OPTION (pfile, user_label_prefix);
744               else
745                 val = b->value;
746
747               /* Allocate enough space for "name value\n\0".  */
748               str = alloca (b->len + strlen (val) + 3);
749               sprintf(str, "%s %s\n", b->name, val);
750             }
751
752           _cpp_define_builtin (pfile, str);
753         }
754     }
755
756   if (CPP_OPTION (pfile, cplusplus))
757     {
758       _cpp_define_builtin (pfile, "__cplusplus 1");
759       if (SUPPORTS_ONE_ONLY)
760         _cpp_define_builtin (pfile, "__GXX_WEAK__ 1");
761       else
762         _cpp_define_builtin (pfile, "__GXX_WEAK__ 0");
763     }
764   if (CPP_OPTION (pfile, objc))
765     _cpp_define_builtin (pfile, "__OBJC__ 1");
766
767   if (CPP_OPTION (pfile, lang) == CLK_STDC94)
768     _cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L");
769   else if (CPP_OPTION (pfile, c99))
770     _cpp_define_builtin (pfile, "__STDC_VERSION__ 199901L");
771
772   if (CPP_OPTION (pfile, signed_char) == 0)
773     _cpp_define_builtin (pfile, "__CHAR_UNSIGNED__ 1");
774
775   if (CPP_OPTION (pfile, lang) == CLK_STDC89
776       || CPP_OPTION (pfile, lang) == CLK_STDC94
777       || CPP_OPTION (pfile, lang) == CLK_STDC99)
778     _cpp_define_builtin (pfile, "__STRICT_ANSI__ 1");
779   else if (CPP_OPTION (pfile, lang) == CLK_ASM)
780     _cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
781 }
782 #undef BUILTIN
783 #undef OPERATOR
784 #undef VERS
785 #undef ULP
786 #undef CPLUS
787 #undef builtin_array_end
788
789 /* And another subroutine.  This one sets up the standard include path.  */
790 static void
791 init_standard_includes (pfile)
792      cpp_reader *pfile;
793 {
794   char *path;
795   const struct default_include *p;
796   const char *specd_prefix = CPP_OPTION (pfile, include_prefix);
797
798   /* Several environment variables may add to the include search path.
799      CPATH specifies an additional list of directories to be searched
800      as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH,
801      etc. specify an additional list of directories to be searched as
802      if specified with -isystem, for the language indicated.  */
803
804   GET_ENV_PATH_LIST (path, "CPATH");
805   if (path != 0 && *path != 0)
806     path_include (pfile, path, BRACKET);
807
808   switch ((CPP_OPTION (pfile, objc) << 1) + CPP_OPTION (pfile, cplusplus))
809     {
810     case 0:
811       GET_ENV_PATH_LIST (path, "C_INCLUDE_PATH");
812       break;
813     case 1:
814       GET_ENV_PATH_LIST (path, "CPLUS_INCLUDE_PATH");
815       break;
816     case 2:
817       GET_ENV_PATH_LIST (path, "OBJC_INCLUDE_PATH");
818       break;
819     case 3:
820       GET_ENV_PATH_LIST (path, "OBJCPLUS_INCLUDE_PATH");
821       break;
822     }
823   if (path != 0 && *path != 0)
824     path_include (pfile, path, SYSTEM);
825
826   /* Search "translated" versions of GNU directories.
827      These have /usr/local/lib/gcc... replaced by specd_prefix.  */
828   if (specd_prefix != 0 && cpp_GCC_INCLUDE_DIR_len)
829     {
830       /* Remove the `include' from /usr/local/lib/gcc.../include.
831          GCC_INCLUDE_DIR will always end in /include.  */
832       int default_len = cpp_GCC_INCLUDE_DIR_len;
833       char *default_prefix = (char *) alloca (default_len + 1);
834       int specd_len = strlen (specd_prefix);
835
836       memcpy (default_prefix, cpp_GCC_INCLUDE_DIR, default_len);
837       default_prefix[default_len] = '\0';
838
839       for (p = cpp_include_defaults; p->fname; p++)
840         {
841           /* Some standard dirs are only for C++.  */
842           if (!p->cplusplus
843               || (CPP_OPTION (pfile, cplusplus)
844                   && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
845             {
846               /* Does this dir start with the prefix?  */
847               if (!memcmp (p->fname, default_prefix, default_len))
848                 {
849                   /* Yes; change prefix and add to search list.  */
850                   int flen = strlen (p->fname);
851                   int this_len = specd_len + flen - default_len;
852                   char *str = (char *) xmalloc (this_len + 1);
853                   memcpy (str, specd_prefix, specd_len);
854                   memcpy (str + specd_len,
855                           p->fname + default_len,
856                           flen - default_len + 1);
857
858                   append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
859                 }
860             }
861         }
862     }
863
864   /* Search ordinary names for GNU include directories.  */
865   for (p = cpp_include_defaults; p->fname; p++)
866     {
867       /* Some standard dirs are only for C++.  */
868       if (!p->cplusplus
869           || (CPP_OPTION (pfile, cplusplus)
870               && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
871         {
872           char *str = update_path (p->fname, p->component);
873           append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
874         }
875     }
876 }
877
878 /* Pushes a command line -imacro and -include file indicated by P onto
879    the buffer stack.  Returns non-zero if successful.  */
880 static bool
881 push_include (pfile, p)
882      cpp_reader *pfile;
883      struct pending_option *p;
884 {
885   cpp_token header;
886
887   /* Later: maybe update this to use the #include "" search path
888      if cpp_read_file fails.  */
889   header.type = CPP_STRING;
890   header.val.str.text = (const unsigned char *) p->arg;
891   header.val.str.len = strlen (p->arg);
892   /* Make the command line directive take up a line.  */
893   pfile->line++;
894
895   return _cpp_execute_include (pfile, &header, IT_CMDLINE);
896 }
897
898 /* Frees a pending_option chain.  */
899 static void
900 free_chain (head)
901      struct pending_option *head;
902 {
903   struct pending_option *next;
904
905   while (head)
906     {
907       next = head->next;
908       free (head);
909       head = next;
910     }
911 }
912
913 /* This is called after options have been parsed, and partially
914    processed.  Setup for processing input from the file named FNAME,
915    or stdin if it is the empty string.  Return the original filename
916    on success (e.g. foo.i->foo.c), or NULL on failure.  */
917 const char *
918 cpp_read_main_file (pfile, fname, table)
919      cpp_reader *pfile;
920      const char *fname;
921      hash_table *table;
922 {
923   /* The front ends don't set up the hash table until they have
924      finished processing the command line options, so initializing the
925      hashtable is deferred until now.  */
926   _cpp_init_hashtable (pfile, table);
927
928   /* Set up the include search path now.  */
929   if (! CPP_OPTION (pfile, no_standard_includes))
930     init_standard_includes (pfile);
931
932   merge_include_chains (pfile);
933
934   /* With -v, print the list of dirs to search.  */
935   if (CPP_OPTION (pfile, verbose))
936     {
937       struct search_path *l;
938       fprintf (stderr, _("#include \"...\" search starts here:\n"));
939       for (l = CPP_OPTION (pfile, quote_include); l; l = l->next)
940         {
941           if (l == CPP_OPTION (pfile, bracket_include))
942             fprintf (stderr, _("#include <...> search starts here:\n"));
943           fprintf (stderr, " %s\n", l->name);
944         }
945       fprintf (stderr, _("End of search list.\n"));
946     }
947
948   if (CPP_OPTION (pfile, print_deps))
949     /* Set the default target (if there is none already).  */
950     deps_add_default_target (pfile->deps, fname);
951
952   /* Open the main input file.  */
953   if (!_cpp_read_file (pfile, fname))
954     return NULL;
955
956   /* Set this after cpp_post_options so the client can change the
957      option if it wishes, and after stacking the main file so we don't
958      trace the main file.  */
959   pfile->line_maps.trace_includes = CPP_OPTION (pfile, print_include_names);
960
961   /* For foo.i, read the original filename foo.c now, for the benefit
962      of the front ends.  */
963   if (CPP_OPTION (pfile, preprocessed))
964     read_original_filename (pfile);
965
966   return pfile->map->to_file;
967 }
968
969 /* For preprocessed files, if the first tokens are of the form # NUM.
970    handle the directive so we know the original file name.  This will
971    generate file_change callbacks, which the front ends must handle
972    appropriately given their state of initialization.  */
973 static void
974 read_original_filename (pfile)
975      cpp_reader *pfile;
976 {
977   const cpp_token *token, *token1;
978
979   /* Lex ahead; if the first tokens are of the form # NUM, then
980      process the directive, otherwise back up.  */
981   token = _cpp_lex_direct (pfile);
982   if (token->type == CPP_HASH)
983     {
984       token1 = _cpp_lex_direct (pfile);
985       _cpp_backup_tokens (pfile, 1);
986
987       /* If it's a #line directive, handle it.  */
988       if (token1->type == CPP_NUMBER)
989         {
990           _cpp_handle_directive (pfile, token->flags & PREV_WHITE);
991           return;
992         }
993     }
994
995   /* Backup as if nothing happened.  */
996   _cpp_backup_tokens (pfile, 1);
997 }
998
999 /* Handle pending command line options: -D, -U, -A, -imacros and
1000    -include.  This should be called after debugging has been properly
1001    set up in the front ends.  */
1002 void
1003 cpp_finish_options (pfile)
1004      cpp_reader *pfile;
1005 {
1006   /* Install builtins and process command line macros etc. in the order
1007      they appeared, but only if not already preprocessed.  */
1008   if (! CPP_OPTION (pfile, preprocessed))
1009     {
1010       struct pending_option *p;
1011
1012       _cpp_do_file_change (pfile, LC_RENAME, _("<built-in>"), 1, 0);
1013       init_builtins (pfile);
1014       _cpp_do_file_change (pfile, LC_RENAME, _("<command line>"), 1, 0);
1015       for (p = CPP_OPTION (pfile, pending)->directive_head; p; p = p->next)
1016         (*p->handler) (pfile, p->arg);
1017
1018       /* Scan -imacros files after command line defines, but before
1019          files given with -include.  */
1020       while ((p = CPP_OPTION (pfile, pending)->imacros_head) != NULL)
1021         {
1022           if (push_include (pfile, p))
1023             {
1024               pfile->buffer->return_at_eof = true;
1025               cpp_scan_nooutput (pfile);
1026             }
1027           CPP_OPTION (pfile, pending)->imacros_head = p->next;
1028           free (p);
1029         }
1030     }
1031
1032   free_chain (CPP_OPTION (pfile, pending)->directive_head);
1033   _cpp_push_next_buffer (pfile);
1034 }
1035
1036 /* Called to push the next buffer on the stack given by -include.  If
1037    there are none, free the pending structure and restore the line map
1038    for the main file.  */
1039 bool
1040 _cpp_push_next_buffer (pfile)
1041      cpp_reader *pfile;
1042 {
1043   bool pushed = false;
1044
1045   /* This is't pretty; we'd rather not be relying on this as a boolean
1046      for reverting the line map.  Further, we only free the chains in
1047      this conditional, so an early call to cpp_finish / cpp_destroy
1048      will leak that memory.  */
1049   if (CPP_OPTION (pfile, pending)
1050       && CPP_OPTION (pfile, pending)->imacros_head == NULL)
1051     {
1052       while (!pushed)
1053         {
1054           struct pending_option *p = CPP_OPTION (pfile, pending)->include_head;
1055
1056           if (p == NULL)
1057             break;
1058           if (! CPP_OPTION (pfile, preprocessed))
1059             pushed = push_include (pfile, p);
1060           CPP_OPTION (pfile, pending)->include_head = p->next;
1061           free (p);
1062         }
1063
1064       if (!pushed)
1065         {
1066           free (CPP_OPTION (pfile, pending));
1067           CPP_OPTION (pfile, pending) = NULL;
1068
1069           /* Restore the line map for the main file.  */
1070           if (! CPP_OPTION (pfile, preprocessed))
1071             _cpp_do_file_change (pfile, LC_RENAME,
1072                                  pfile->line_maps.maps[0].to_file, 1, 0);
1073         }
1074     }
1075
1076   return pushed;
1077 }
1078
1079 /* Use mkdeps.c to output dependency information.  */
1080 static void
1081 output_deps (pfile)
1082      cpp_reader *pfile;
1083 {
1084   /* Stream on which to print the dependency information.  */
1085   FILE *deps_stream = 0;
1086   const char *const deps_mode =
1087     CPP_OPTION (pfile, print_deps_append) ? "a" : "w";
1088
1089   if (CPP_OPTION (pfile, deps_file)[0] == '\0')
1090     deps_stream = stdout;
1091   else
1092     {
1093       deps_stream = fopen (CPP_OPTION (pfile, deps_file), deps_mode);
1094       if (deps_stream == 0)
1095         {
1096           cpp_notice_from_errno (pfile, CPP_OPTION (pfile, deps_file));
1097           return;
1098         }
1099     }
1100
1101   deps_write (pfile->deps, deps_stream, 72);
1102
1103   if (CPP_OPTION (pfile, deps_phony_targets))
1104     deps_phony_targets (pfile->deps, deps_stream);
1105
1106   /* Don't close stdout.  */
1107   if (deps_stream != stdout)
1108     {
1109       if (ferror (deps_stream) || fclose (deps_stream) != 0)
1110         cpp_fatal (pfile, "I/O error on output");
1111     }
1112 }
1113
1114 /* This is called at the end of preprocessing.  It pops the
1115    last buffer and writes dependency output.  It should also
1116    clear macro definitions, such that you could call cpp_start_read
1117    with a new filename to restart processing.  */
1118 void
1119 cpp_finish (pfile)
1120      cpp_reader *pfile;
1121 {
1122   /* cpplex.c leaves the final buffer on the stack.  This it so that
1123      it returns an unending stream of CPP_EOFs to the client.  If we
1124      popped the buffer, we'd dereference a NULL buffer pointer and
1125      segfault.  It's nice to allow the client to do worry-free excess
1126      cpp_get_token calls.  */
1127   while (pfile->buffer)
1128     _cpp_pop_buffer (pfile);
1129
1130   /* Don't write the deps file if preprocessing has failed.  */
1131   if (CPP_OPTION (pfile, print_deps) && pfile->errors == 0)
1132     output_deps (pfile);
1133
1134   /* Report on headers that could use multiple include guards.  */
1135   if (CPP_OPTION (pfile, print_include_names))
1136     _cpp_report_missing_guards (pfile);
1137 }
1138
1139 /* Add a directive to be handled later in the initialization phase.  */
1140 static void
1141 new_pending_directive (pend, text, handler)
1142      struct cpp_pending *pend;
1143      const char *text;
1144      cl_directive_handler handler;
1145 {
1146   struct pending_option *o = (struct pending_option *)
1147     xmalloc (sizeof (struct pending_option));
1148
1149   o->arg = text;
1150   o->next = NULL;
1151   o->handler = handler;
1152   APPEND (pend, directive, o);
1153 }
1154
1155 /* Irix6 "cc -n32" and OSF4 cc have problems with char foo[] = ("string");
1156    I.e. a const string initializer with parens around it.  That is
1157    what N_("string") resolves to, so we make no_* be macros instead.  */
1158 #define no_arg N_("argument missing after %s")
1159 #define no_ass N_("assertion missing after %s")
1160 #define no_dir N_("directory name missing after %s")
1161 #define no_fil N_("file name missing after %s")
1162 #define no_mac N_("macro name missing after %s")
1163 #define no_pth N_("path name missing after %s")
1164 #define no_num N_("number missing after %s")
1165 #define no_tgt N_("target missing after %s")
1166
1167 /* This is the list of all command line options, with the leading
1168    "-" removed.  It must be sorted in ASCII collating order.  */
1169 #define COMMAND_LINE_OPTIONS                                                  \
1170   DEF_OPT("$",                        0,      OPT_dollar)                     \
1171   DEF_OPT("+",                        0,      OPT_plus)                       \
1172   DEF_OPT("-help",                    0,      OPT__help)                      \
1173   DEF_OPT("-target-help",             0,      OPT_target__help)               \
1174   DEF_OPT("-version",                 0,      OPT__version)                   \
1175   DEF_OPT("A",                        no_ass, OPT_A)                          \
1176   DEF_OPT("C",                        0,      OPT_C)                          \
1177   DEF_OPT("D",                        no_mac, OPT_D)                          \
1178   DEF_OPT("H",                        0,      OPT_H)                          \
1179   DEF_OPT("I",                        no_dir, OPT_I)                          \
1180   DEF_OPT("M",                        0,      OPT_M)                          \
1181   DEF_OPT("MD",                       no_fil, OPT_MD)                         \
1182   DEF_OPT("MF",                       no_fil, OPT_MF)                         \
1183   DEF_OPT("MG",                       0,      OPT_MG)                         \
1184   DEF_OPT("MM",                       0,      OPT_MM)                         \
1185   DEF_OPT("MMD",                      no_fil, OPT_MMD)                        \
1186   DEF_OPT("MP",                       0,      OPT_MP)                         \
1187   DEF_OPT("MQ",                       no_tgt, OPT_MQ)                         \
1188   DEF_OPT("MT",                       no_tgt, OPT_MT)                         \
1189   DEF_OPT("P",                        0,      OPT_P)                          \
1190   DEF_OPT("U",                        no_mac, OPT_U)                          \
1191   DEF_OPT("W",                        no_arg, OPT_W)  /* arg optional */      \
1192   DEF_OPT("d",                        no_arg, OPT_d)                          \
1193   DEF_OPT("fleading-underscore",      0,      OPT_fleading_underscore)        \
1194   DEF_OPT("fno-leading-underscore",   0,      OPT_fno_leading_underscore)     \
1195   DEF_OPT("fno-operator-names",       0,      OPT_fno_operator_names)         \
1196   DEF_OPT("fno-preprocessed",         0,      OPT_fno_preprocessed)           \
1197   DEF_OPT("fno-show-column",          0,      OPT_fno_show_column)            \
1198   DEF_OPT("fpreprocessed",            0,      OPT_fpreprocessed)              \
1199   DEF_OPT("fshow-column",             0,      OPT_fshow_column)               \
1200   DEF_OPT("fsigned-char",             0,      OPT_fsigned_char)               \
1201   DEF_OPT("ftabstop=",                no_num, OPT_ftabstop)                   \
1202   DEF_OPT("funsigned-char",           0,      OPT_funsigned_char)             \
1203   DEF_OPT("h",                        0,      OPT_h)                          \
1204   DEF_OPT("idirafter",                no_dir, OPT_idirafter)                  \
1205   DEF_OPT("imacros",                  no_fil, OPT_imacros)                    \
1206   DEF_OPT("include",                  no_fil, OPT_include)                    \
1207   DEF_OPT("iprefix",                  no_pth, OPT_iprefix)                    \
1208   DEF_OPT("isystem",                  no_dir, OPT_isystem)                    \
1209   DEF_OPT("iwithprefix",              no_dir, OPT_iwithprefix)                \
1210   DEF_OPT("iwithprefixbefore",        no_dir, OPT_iwithprefixbefore)          \
1211   DEF_OPT("lang-asm",                 0,      OPT_lang_asm)                   \
1212   DEF_OPT("lang-c",                   0,      OPT_lang_c)                     \
1213   DEF_OPT("lang-c++",                 0,      OPT_lang_cplusplus)             \
1214   DEF_OPT("lang-c89",                 0,      OPT_lang_c89)                   \
1215   DEF_OPT("lang-objc",                0,      OPT_lang_objc)                  \
1216   DEF_OPT("lang-objc++",              0,      OPT_lang_objcplusplus)          \
1217   DEF_OPT("nostdinc",                 0,      OPT_nostdinc)                   \
1218   DEF_OPT("nostdinc++",               0,      OPT_nostdincplusplus)           \
1219   DEF_OPT("o",                        no_fil, OPT_o)                          \
1220   DEF_OPT("pedantic",                 0,      OPT_pedantic)                   \
1221   DEF_OPT("pedantic-errors",          0,      OPT_pedantic_errors)            \
1222   DEF_OPT("remap",                    0,      OPT_remap)                      \
1223   DEF_OPT("std=c++98",                0,      OPT_std_cplusplus98)            \
1224   DEF_OPT("std=c89",                  0,      OPT_std_c89)                    \
1225   DEF_OPT("std=c99",                  0,      OPT_std_c99)                    \
1226   DEF_OPT("std=c9x",                  0,      OPT_std_c9x)                    \
1227   DEF_OPT("std=gnu89",                0,      OPT_std_gnu89)                  \
1228   DEF_OPT("std=gnu99",                0,      OPT_std_gnu99)                  \
1229   DEF_OPT("std=gnu9x",                0,      OPT_std_gnu9x)                  \
1230   DEF_OPT("std=bsd",                  0,      OPT_std_bsd)                    \
1231   DEF_OPT("std=iso9899:1990",         0,      OPT_std_iso9899_1990)           \
1232   DEF_OPT("std=iso9899:199409",       0,      OPT_std_iso9899_199409)         \
1233   DEF_OPT("std=iso9899:1999",         0,      OPT_std_iso9899_1999)           \
1234   DEF_OPT("std=iso9899:199x",         0,      OPT_std_iso9899_199x)           \
1235   DEF_OPT("trigraphs",                0,      OPT_trigraphs)                  \
1236   DEF_OPT("v",                        0,      OPT_v)                          \
1237   DEF_OPT("version",                  0,      OPT_version)                    \
1238   DEF_OPT("w",                        0,      OPT_w)
1239
1240 #define DEF_OPT(text, msg, code) code,
1241 enum opt_code
1242 {
1243   COMMAND_LINE_OPTIONS
1244   N_OPTS
1245 };
1246 #undef DEF_OPT
1247
1248 struct cl_option
1249 {
1250   const char *opt_text;
1251   const char *msg;
1252   size_t opt_len;
1253   enum opt_code opt_code;
1254 };
1255
1256 #define DEF_OPT(text, msg, code) { text, msg, sizeof(text) - 1, code },
1257 #ifdef HOST_EBCDIC
1258 static struct cl_option cl_options[] =
1259 #else
1260 static const struct cl_option cl_options[] =
1261 #endif
1262 {
1263   COMMAND_LINE_OPTIONS
1264 };
1265 #undef DEF_OPT
1266 #undef COMMAND_LINE_OPTIONS
1267
1268 /* Perform a binary search to find which, if any, option the given
1269    command-line matches.  Returns its index in the option array,
1270    negative on failure.  Complications arise since some options can be
1271    suffixed with an argument, and multiple complete matches can occur,
1272    e.g. -iwithprefix and -iwithprefixbefore.  Moreover, we need to
1273    accept options beginning with -W that we do not recognise, but not
1274    to swallow any subsequent command line argument; this is handled as
1275    special cases in cpp_handle_option.  */
1276 static int
1277 parse_option (input)
1278      const char *input;
1279 {
1280   unsigned int md, mn, mx;
1281   size_t opt_len;
1282   int comp;
1283
1284   mn = 0;
1285   mx = N_OPTS;
1286
1287   while (mx > mn)
1288     {
1289       md = (mn + mx) / 2;
1290
1291       opt_len = cl_options[md].opt_len;
1292       comp = memcmp (input, cl_options[md].opt_text, opt_len);
1293
1294       if (comp > 0)
1295         mn = md + 1;
1296       else if (comp < 0)
1297         mx = md;
1298       else
1299         {
1300           if (input[opt_len] == '\0')
1301             return md;
1302           /* We were passed more text.  If the option takes an argument,
1303              we may match a later option or we may have been passed the
1304              argument.  The longest possible option match succeeds.
1305              If the option takes no arguments we have not matched and
1306              continue the search (e.g. input="stdc++" match was "stdc").  */
1307           mn = md + 1;
1308           if (cl_options[md].msg)
1309             {
1310               /* Scan forwards.  If we get an exact match, return it.
1311                  Otherwise, return the longest option-accepting match.
1312                  This loops no more than twice with current options.  */
1313               mx = md;
1314               for (; mn < (unsigned int) N_OPTS; mn++)
1315                 {
1316                   opt_len = cl_options[mn].opt_len;
1317                   if (memcmp (input, cl_options[mn].opt_text, opt_len))
1318                     break;
1319                   if (input[opt_len] == '\0')
1320                     return mn;
1321                   if (cl_options[mn].msg)
1322                     mx = mn;
1323                 }
1324               return mx;
1325             }
1326         }
1327     }
1328
1329   return -1;
1330 }
1331
1332 /* Handle one command-line option in (argc, argv).
1333    Can be called multiple times, to handle multiple sets of options.
1334    If ignore is non-zero, this will ignore unrecognized -W* options.
1335    Returns number of strings consumed.  */
1336 int
1337 cpp_handle_option (pfile, argc, argv, ignore)
1338      cpp_reader *pfile;
1339      int argc;
1340      char **argv;
1341      int ignore;
1342 {
1343   int i = 0;
1344   struct cpp_pending *pend = CPP_OPTION (pfile, pending);
1345
1346   /* Interpret "-" or a non-option as a file name.  */
1347   if (argv[i][0] != '-' || argv[i][1] == '\0')
1348     {
1349       if (CPP_OPTION (pfile, in_fname) == NULL)
1350         CPP_OPTION (pfile, in_fname) = argv[i];
1351       else if (CPP_OPTION (pfile, out_fname) == NULL)
1352         CPP_OPTION (pfile, out_fname) = argv[i];
1353       else
1354         cpp_fatal (pfile, "too many filenames. Type %s --help for usage info",
1355                    progname);
1356     }
1357   else
1358     {
1359       enum opt_code opt_code;
1360       int opt_index;
1361       const char *arg = 0;
1362
1363       /* Skip over '-'.  */
1364       opt_index = parse_option (&argv[i][1]);
1365       if (opt_index < 0)
1366         return i;
1367
1368       opt_code = cl_options[opt_index].opt_code;
1369       if (cl_options[opt_index].msg)
1370         {
1371           arg = &argv[i][cl_options[opt_index].opt_len + 1];
1372
1373           /* Yuk. Special case for -W as it must not swallow
1374              up any following argument.  If this becomes common, add
1375              another field to the cl_options table.  */
1376           if (arg[0] == '\0' && opt_code != OPT_W)
1377             {
1378               arg = argv[++i];
1379               if (!arg)
1380                 {
1381                   cpp_fatal (pfile, cl_options[opt_index].msg, argv[i - 1]);
1382                   return argc;
1383                 }
1384             }
1385         }
1386
1387       switch (opt_code)
1388         {
1389         case N_OPTS: /* Shut GCC up.  */
1390           break;
1391         case OPT_fleading_underscore:
1392           CPP_OPTION (pfile, user_label_prefix) = "_";
1393           break;
1394         case OPT_fno_leading_underscore:
1395           CPP_OPTION (pfile, user_label_prefix) = "";
1396           break;
1397         case OPT_fno_operator_names:
1398           CPP_OPTION (pfile, operator_names) = 0;
1399           break;
1400         case OPT_fpreprocessed:
1401           CPP_OPTION (pfile, preprocessed) = 1;
1402           break;
1403         case OPT_fno_preprocessed:
1404           CPP_OPTION (pfile, preprocessed) = 0;
1405           break;
1406         case OPT_fshow_column:
1407           CPP_OPTION (pfile, show_column) = 1;
1408           break;
1409         case OPT_fno_show_column:
1410           CPP_OPTION (pfile, show_column) = 0;
1411           break;
1412         case OPT_fsigned_char:
1413           CPP_OPTION (pfile, signed_char) = 1;
1414           break;
1415         case OPT_funsigned_char:
1416           CPP_OPTION (pfile, signed_char) = 0;
1417           break;
1418         case OPT_ftabstop:
1419           /* Silently ignore empty string, non-longs and silly values.  */
1420           if (arg[0] != '\0')
1421             {
1422               char *endptr;
1423               long tabstop = strtol (arg, &endptr, 10);
1424               if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
1425                 CPP_OPTION (pfile, tabstop) = tabstop;
1426             }
1427           break;
1428         case OPT_w:
1429           CPP_OPTION (pfile, inhibit_warnings) = 1;
1430           break;
1431         case OPT_h:
1432         case OPT__help:
1433           print_help ();
1434           CPP_OPTION (pfile, help_only) = 1;
1435           break;
1436         case OPT_target__help:
1437           /* Print if any target specific options. cpplib has none, but
1438              make sure help_only gets set.  */
1439           CPP_OPTION (pfile, help_only) = 1;
1440           break;
1441
1442           /* --version inhibits compilation, -version doesn't. -v means
1443              verbose and -version.  Historical reasons, don't ask.  */
1444         case OPT__version:
1445           CPP_OPTION (pfile, help_only) = 1;
1446           pfile->print_version = 1;
1447           break;
1448         case OPT_v:
1449           CPP_OPTION (pfile, verbose) = 1;
1450           pfile->print_version = 1;
1451           break;
1452         case OPT_version:
1453           pfile->print_version = 1;
1454           break;
1455
1456         case OPT_C:
1457           CPP_OPTION (pfile, discard_comments) = 0;
1458           break;
1459         case OPT_P:
1460           CPP_OPTION (pfile, no_line_commands) = 1;
1461           break;
1462         case OPT_dollar:        /* Don't include $ in identifiers.  */
1463           CPP_OPTION (pfile, dollars_in_ident) = 0;
1464           break;
1465         case OPT_H:
1466           CPP_OPTION (pfile, print_include_names) = 1;
1467           break;
1468         case OPT_D:
1469           new_pending_directive (pend, arg, cpp_define);
1470           break;
1471         case OPT_pedantic_errors:
1472           CPP_OPTION (pfile, pedantic_errors) = 1;
1473           /* fall through */
1474         case OPT_pedantic:
1475           CPP_OPTION (pfile, pedantic) = 1;
1476           break;
1477         case OPT_trigraphs:
1478           CPP_OPTION (pfile, trigraphs) = 1;
1479           break;
1480         case OPT_plus:
1481           CPP_OPTION (pfile, cplusplus) = 1;
1482           CPP_OPTION (pfile, cplusplus_comments) = 1;
1483           break;
1484         case OPT_remap:
1485           CPP_OPTION (pfile, remap) = 1;
1486           break;
1487         case OPT_iprefix:
1488           CPP_OPTION (pfile, include_prefix) = arg;
1489           CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
1490           break;
1491         case OPT_lang_c:
1492           set_lang (pfile, CLK_GNUC89);
1493           break;
1494         case OPT_lang_cplusplus:
1495           set_lang (pfile, CLK_GNUCXX);
1496           break;
1497         case OPT_lang_objc:
1498           set_lang (pfile, CLK_OBJC);
1499           break;
1500         case OPT_lang_objcplusplus:
1501           set_lang (pfile, CLK_OBJCXX);
1502           break;
1503         case OPT_lang_asm:
1504           set_lang (pfile, CLK_ASM);
1505           break;
1506         case OPT_std_cplusplus98:
1507           set_lang (pfile, CLK_CXX98);
1508           break;
1509         case OPT_std_gnu89:
1510           set_lang (pfile, CLK_GNUC89);
1511           break;
1512         case OPT_std_gnu9x:
1513         case OPT_std_gnu99:
1514           set_lang (pfile, CLK_GNUC99);
1515           break;
1516         case OPT_std_bsd:
1517           set_lang (pfile, CLK_GNUC89);
1518           break;
1519         case OPT_std_iso9899_199409:
1520           set_lang (pfile, CLK_STDC94);
1521           break;
1522         case OPT_std_iso9899_1990:
1523         case OPT_std_c89:
1524         case OPT_lang_c89:
1525           set_lang (pfile, CLK_STDC89);
1526           break;
1527         case OPT_std_iso9899_199x:
1528         case OPT_std_iso9899_1999:
1529         case OPT_std_c9x:
1530         case OPT_std_c99:
1531           set_lang (pfile, CLK_STDC99);
1532           break;
1533         case OPT_nostdinc:
1534           /* -nostdinc causes no default include directories.
1535              You must specify all include-file directories with -I.  */
1536           CPP_OPTION (pfile, no_standard_includes) = 1;
1537           break;
1538         case OPT_nostdincplusplus:
1539           /* -nostdinc++ causes no default C++-specific include directories.  */
1540           CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1;
1541           break;
1542         case OPT_o:
1543           if (CPP_OPTION (pfile, out_fname) == NULL)
1544             CPP_OPTION (pfile, out_fname) = arg;
1545           else
1546             {
1547               cpp_fatal (pfile, "output filename specified twice");
1548               return argc;
1549             }
1550           break;
1551         case OPT_d:
1552           /* Args to -d specify what parts of macros to dump.
1553              Silently ignore unrecognised options; they may
1554              be aimed at the compiler proper.  */
1555           {
1556             char c;
1557
1558             while ((c = *arg++) != '\0')
1559               switch (c)
1560                 {
1561                 case 'M':
1562                   CPP_OPTION (pfile, dump_macros) = dump_only;
1563                   break;
1564                 case 'N':
1565                   CPP_OPTION (pfile, dump_macros) = dump_names;
1566                   break;
1567                 case 'D':
1568                   CPP_OPTION (pfile, dump_macros) = dump_definitions;
1569                   break;
1570                 case 'I':
1571                   CPP_OPTION (pfile, dump_includes) = 1;
1572                   break;
1573                 }
1574           }
1575           break;
1576
1577         case OPT_MG:
1578           CPP_OPTION (pfile, print_deps_missing_files) = 1;
1579           break;
1580         case OPT_M:
1581           /* When doing dependencies with -M or -MM, suppress normal
1582              preprocessed output, but still do -dM etc. as software
1583              depends on this.  Preprocessed output occurs if -MD, -MMD
1584              or environment var dependency generation is used.  */
1585           CPP_OPTION (pfile, print_deps) = 2;
1586           CPP_OPTION (pfile, no_output) = 1;
1587           break;
1588         case OPT_MM:
1589           CPP_OPTION (pfile, print_deps) = 1;
1590           CPP_OPTION (pfile, no_output) = 1;
1591           break;
1592         case OPT_MF:
1593           CPP_OPTION (pfile, deps_file) = arg;
1594           break;
1595         case OPT_MP:
1596           CPP_OPTION (pfile, deps_phony_targets) = 1;
1597           break;
1598         case OPT_MQ:
1599         case OPT_MT:
1600           /* Add a target.  -MQ quotes for Make.  */
1601           deps_add_target (pfile->deps, arg, opt_code == OPT_MQ);
1602           break;
1603
1604         case OPT_MD:
1605           CPP_OPTION (pfile, print_deps) = 2;
1606           CPP_OPTION (pfile, deps_file) = arg;
1607           break;
1608         case OPT_MMD:
1609           CPP_OPTION (pfile, print_deps) = 1;
1610           CPP_OPTION (pfile, deps_file) = arg;
1611           break;
1612
1613         case OPT_A:
1614           if (arg[0] == '-')
1615             {
1616               /* -A with an argument beginning with '-' acts as
1617                  #unassert on whatever immediately follows the '-'.
1618                  If "-" is the whole argument, we eliminate all
1619                  predefined macros and assertions, including those
1620                  that were specified earlier on the command line.
1621                  That way we can get rid of any that were passed
1622                  automatically in from GCC.  */
1623
1624               if (arg[1] == '\0')
1625                 {
1626                   free_chain (pend->directive_head);
1627                   pend->directive_head = NULL;
1628                   pend->directive_tail = NULL;
1629                 }
1630               else
1631                 new_pending_directive (pend, arg + 1, cpp_unassert);
1632             }
1633           else
1634             new_pending_directive (pend, arg, cpp_assert);
1635           break;
1636         case OPT_U:
1637           new_pending_directive (pend, arg, cpp_undef);
1638           break;
1639         case OPT_I:           /* Add directory to path for includes.  */
1640           if (!strcmp (arg, "-"))
1641             {
1642               /* -I- means:
1643                  Use the preceding -I directories for #include "..."
1644                  but not #include <...>.
1645                  Don't search the directory of the present file
1646                  for #include "...".  (Note that -I. -I- is not the same as
1647                  the default setup; -I. uses the compiler's working dir.)  */
1648               if (! CPP_OPTION (pfile, ignore_srcdir))
1649                 {
1650                   pend->quote_head = pend->brack_head;
1651                   pend->quote_tail = pend->brack_tail;
1652                   pend->brack_head = 0;
1653                   pend->brack_tail = 0;
1654                   CPP_OPTION (pfile, ignore_srcdir) = 1;
1655                 }
1656               else
1657                 {
1658                   cpp_fatal (pfile, "-I- specified twice");
1659                   return argc;
1660                 }
1661             }
1662           else
1663             append_include_chain (pfile, xstrdup (arg), BRACKET, 0);
1664           break;
1665         case OPT_isystem:
1666           /* Add directory to beginning of system include path, as a system
1667              include directory.  */
1668           append_include_chain (pfile, xstrdup (arg), SYSTEM, 0);
1669           break;
1670         case OPT_include:
1671         case OPT_imacros:
1672           {
1673             struct pending_option *o = (struct pending_option *)
1674               xmalloc (sizeof (struct pending_option));
1675             o->arg = arg;
1676             o->next = NULL;
1677
1678             if (opt_code == OPT_include)
1679               APPEND (pend, include, o);
1680             else
1681               APPEND (pend, imacros, o);
1682           }
1683           break;
1684         case OPT_iwithprefix:
1685           /* Add directory to end of path for includes,
1686              with the default prefix at the front of its name.  */
1687           /* fall through */
1688         case OPT_iwithprefixbefore:
1689           /* Add directory to main path for includes,
1690              with the default prefix at the front of its name.  */
1691           {
1692             char *fname;
1693             int len;
1694
1695             len = strlen (arg);
1696
1697             if (CPP_OPTION (pfile, include_prefix) != 0)
1698               {
1699                 size_t ipl = CPP_OPTION (pfile, include_prefix_len);
1700                 fname = xmalloc (ipl + len + 1);
1701                 memcpy (fname, CPP_OPTION (pfile, include_prefix), ipl);
1702                 memcpy (fname + ipl, arg, len + 1);
1703               }
1704             else if (cpp_GCC_INCLUDE_DIR_len)
1705               {
1706                 fname = xmalloc (cpp_GCC_INCLUDE_DIR_len + len + 1);
1707                 memcpy (fname, cpp_GCC_INCLUDE_DIR, cpp_GCC_INCLUDE_DIR_len);
1708                 memcpy (fname + cpp_GCC_INCLUDE_DIR_len, arg, len + 1);
1709               }
1710             else
1711               fname = xstrdup (arg);
1712
1713             append_include_chain (pfile, fname,
1714                           opt_code == OPT_iwithprefix ? SYSTEM: BRACKET, 0);
1715           }
1716           break;
1717         case OPT_idirafter:
1718           /* Add directory to end of path for includes.  */
1719           append_include_chain (pfile, xstrdup (arg), AFTER, 0);
1720           break;
1721         case OPT_W:
1722           /* Silently ignore unrecognised options.  */
1723           if (!strcmp (argv[i], "-Wall"))
1724             {
1725               CPP_OPTION (pfile, warn_trigraphs) = 1;
1726               CPP_OPTION (pfile, warn_comments) = 1;
1727             }
1728           else if (!strcmp (argv[i], "-Wtraditional"))
1729             CPP_OPTION (pfile, warn_traditional) = 1;
1730           else if (!strcmp (argv[i], "-Wtrigraphs"))
1731             CPP_OPTION (pfile, warn_trigraphs) = 1;
1732           else if (!strcmp (argv[i], "-Wcomment"))
1733             CPP_OPTION (pfile, warn_comments) = 1;
1734           else if (!strcmp (argv[i], "-Wcomments"))
1735             CPP_OPTION (pfile, warn_comments) = 1;
1736           else if (!strcmp (argv[i], "-Wundef"))
1737             CPP_OPTION (pfile, warn_undef) = 1;
1738           else if (!strcmp (argv[i], "-Wimport"))
1739             CPP_OPTION (pfile, warn_import) = 1;
1740           else if (!strcmp (argv[i], "-Werror"))
1741             CPP_OPTION (pfile, warnings_are_errors) = 1;
1742           else if (!strcmp (argv[i], "-Wsystem-headers"))
1743             CPP_OPTION (pfile, warn_system_headers) = 1;
1744           else if (!strcmp (argv[i], "-Wno-traditional"))
1745             CPP_OPTION (pfile, warn_traditional) = 0;
1746           else if (!strcmp (argv[i], "-Wno-trigraphs"))
1747             CPP_OPTION (pfile, warn_trigraphs) = 0;
1748           else if (!strcmp (argv[i], "-Wno-comment"))
1749             CPP_OPTION (pfile, warn_comments) = 0;
1750           else if (!strcmp (argv[i], "-Wno-comments"))
1751             CPP_OPTION (pfile, warn_comments) = 0;
1752           else if (!strcmp (argv[i], "-Wno-undef"))
1753             CPP_OPTION (pfile, warn_undef) = 0;
1754           else if (!strcmp (argv[i], "-Wno-import"))
1755             CPP_OPTION (pfile, warn_import) = 0;
1756           else if (!strcmp (argv[i], "-Wno-error"))
1757             CPP_OPTION (pfile, warnings_are_errors) = 0;
1758           else if (!strcmp (argv[i], "-Wno-system-headers"))
1759             CPP_OPTION (pfile, warn_system_headers) = 0;
1760           else if (! ignore)
1761             return i;
1762           break;
1763         }
1764     }
1765   return i + 1;
1766 }
1767
1768 /* Handle command-line options in (argc, argv).
1769    Can be called multiple times, to handle multiple sets of options.
1770    Returns if an unrecognized option is seen.
1771    Returns number of strings consumed.  */
1772 int
1773 cpp_handle_options (pfile, argc, argv)
1774      cpp_reader *pfile;
1775      int argc;
1776      char **argv;
1777 {
1778   int i;
1779   int strings_processed;
1780
1781   for (i = 0; i < argc; i += strings_processed)
1782     {
1783       strings_processed = cpp_handle_option (pfile, argc - i, argv + i, 1);
1784       if (strings_processed == 0)
1785         break;
1786     }
1787
1788   return i;
1789 }
1790
1791 /* Extra processing when all options are parsed, after all calls to
1792    cpp_handle_option[s].  Consistency checks etc.  */
1793 void
1794 cpp_post_options (pfile)
1795      cpp_reader *pfile;
1796 {
1797   if (pfile->print_version)
1798     {
1799       fprintf (stderr, _("GNU CPP version %s (cpplib)"), version_string);
1800 #ifdef TARGET_VERSION
1801       TARGET_VERSION;
1802 #endif
1803       fputc ('\n', stderr);
1804     }
1805
1806   /* Canonicalize in_fname and out_fname.  We guarantee they are not
1807      NULL, and that the empty string represents stdin / stdout.  */
1808   if (CPP_OPTION (pfile, in_fname) == NULL
1809       || !strcmp (CPP_OPTION (pfile, in_fname), "-"))
1810     CPP_OPTION (pfile, in_fname) = "";
1811
1812   if (CPP_OPTION (pfile, out_fname) == NULL
1813       || !strcmp (CPP_OPTION (pfile, out_fname), "-"))
1814     CPP_OPTION (pfile, out_fname) = "";
1815
1816   /* -Wtraditional is not useful in C++ mode.  */
1817   if (CPP_OPTION (pfile, cplusplus))
1818     CPP_OPTION (pfile, warn_traditional) = 0;
1819
1820   /* Set this if it hasn't been set already.  */
1821   if (CPP_OPTION (pfile, user_label_prefix) == NULL)
1822     CPP_OPTION (pfile, user_label_prefix) = USER_LABEL_PREFIX;
1823
1824   /* Permanently disable macro expansion if we are rescanning
1825      preprocessed text.  */
1826   if (CPP_OPTION (pfile, preprocessed))
1827     pfile->state.prevent_expansion = 1;
1828
1829   /* -dM makes no normal output.  This is set here so that -dM -dD
1830      works as expected.  */
1831   if (CPP_OPTION (pfile, dump_macros) == dump_only)
1832     CPP_OPTION (pfile, no_output) = 1;
1833
1834   /* Disable -dD, -dN and -dI if we should make no normal output
1835      (such as with -M). Allow -M -dM since some software relies on
1836      this.  */
1837   if (CPP_OPTION (pfile, no_output))
1838     {
1839       if (CPP_OPTION (pfile, dump_macros) != dump_only)
1840         CPP_OPTION (pfile, dump_macros) = dump_none;
1841       CPP_OPTION (pfile, dump_includes) = 0;
1842     }
1843
1844   /* We need to do this after option processing and before
1845      cpp_start_read, as cppmain.c relies on the options->no_output to
1846      set its callbacks correctly before calling cpp_start_read.  */
1847   init_dependency_output (pfile);
1848
1849   /* After checking the environment variables, check if -M or -MM has
1850      not been specified, but other -M options have.  */
1851   if (CPP_OPTION (pfile, print_deps) == 0 &&
1852       (CPP_OPTION (pfile, print_deps_missing_files)
1853        || CPP_OPTION (pfile, deps_file)
1854        || CPP_OPTION (pfile, deps_phony_targets)))
1855     cpp_fatal (pfile, "you must additionally specify either -M or -MM");
1856 }
1857
1858 /* Set up dependency-file output.  On exit, if print_deps is non-zero
1859    then deps_file is not NULL; stdout is the empty string.  */
1860 static void
1861 init_dependency_output (pfile)
1862      cpp_reader *pfile;
1863 {
1864   char *spec, *s, *output_file;
1865
1866   /* Either of two environment variables can specify output of deps.
1867      Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
1868      where OUTPUT_FILE is the file to write deps info to
1869      and DEPS_TARGET is the target to mention in the deps.  */
1870
1871   if (CPP_OPTION (pfile, print_deps) == 0)
1872     {
1873       spec = getenv ("DEPENDENCIES_OUTPUT");
1874       if (spec)
1875         CPP_OPTION (pfile, print_deps) = 1;
1876       else
1877         {
1878           spec = getenv ("SUNPRO_DEPENDENCIES");
1879           if (spec)
1880             CPP_OPTION (pfile, print_deps) = 2;
1881           else
1882             return;
1883         }
1884
1885       /* Find the space before the DEPS_TARGET, if there is one.  */
1886       s = strchr (spec, ' ');
1887       if (s)
1888         {
1889           /* Let the caller perform MAKE quoting.  */
1890           deps_add_target (pfile->deps, s + 1, 0);
1891           output_file = (char *) xmalloc (s - spec + 1);
1892           memcpy (output_file, spec, s - spec);
1893           output_file[s - spec] = 0;
1894         }
1895       else
1896         output_file = spec;
1897
1898       /* Command line -MF overrides environment variables and default.  */
1899       if (CPP_OPTION (pfile, deps_file) == 0)
1900         CPP_OPTION (pfile, deps_file) = output_file;
1901
1902       CPP_OPTION (pfile, print_deps_append) = 1;
1903     }
1904   else if (CPP_OPTION (pfile, deps_file) == 0)
1905     /* If -M or -MM was seen without -MF, default output to wherever
1906        was specified with -o.  out_fname is non-NULL here.  */
1907     CPP_OPTION (pfile, deps_file) = CPP_OPTION (pfile, out_fname);
1908 }
1909
1910 /* Handle --help output.  */
1911 static void
1912 print_help ()
1913 {
1914   /* To keep the lines from getting too long for some compilers, limit
1915      to about 500 characters (6 lines) per chunk.  */
1916   fputs (_("\
1917 Switches:\n\
1918   -include <file>           Include the contents of <file> before other files\n\
1919   -imacros <file>           Accept definition of macros in <file>\n\
1920   -iprefix <path>           Specify <path> as a prefix for next two options\n\
1921   -iwithprefix <dir>        Add <dir> to the end of the system include path\n\
1922   -iwithprefixbefore <dir>  Add <dir> to the end of the main include path\n\
1923   -isystem <dir>            Add <dir> to the start of the system include path\n\
1924 "), stdout);
1925   fputs (_("\
1926   -idirafter <dir>          Add <dir> to the end of the system include path\n\
1927   -I <dir>                  Add <dir> to the end of the main include path\n\
1928   -I-                       Fine-grained include path control; see info docs\n\
1929   -nostdinc                 Do not search system include directories\n\
1930                              (dirs specified with -isystem will still be used)\n\
1931   -nostdinc++               Do not search system include directories for C++\n\
1932   -o <file>                 Put output into <file>\n\
1933 "), stdout);
1934   fputs (_("\
1935   -pedantic                 Issue all warnings demanded by strict ISO C\n\
1936   -pedantic-errors          Issue -pedantic warnings as errors instead\n\
1937   -trigraphs                Support ISO C trigraphs\n\
1938   -lang-c                   Assume that the input sources are in C\n\
1939   -lang-c89                 Assume that the input sources are in C89\n\
1940 "), stdout);
1941   fputs (_("\
1942   -lang-c++                 Assume that the input sources are in C++\n\
1943   -lang-objc                Assume that the input sources are in ObjectiveC\n\
1944   -lang-objc++              Assume that the input sources are in ObjectiveC++\n\
1945   -lang-asm                 Assume that the input sources are in assembler\n\
1946 "), stdout);
1947   fputs (_("\
1948   -std=<std name>           Specify the conformance standard; one of:\n\
1949                             gnu89, gnu99, c89, c99, iso9899:1990,\n\
1950                             iso9899:199409, iso9899:1999\n\
1951   -+                        Allow parsing of C++ style features\n\
1952   -w                        Inhibit warning messages\n\
1953   -Wtrigraphs               Warn if trigraphs are encountered\n\
1954   -Wno-trigraphs            Do not warn about trigraphs\n\
1955   -Wcomment{s}              Warn if one comment starts inside another\n\
1956 "), stdout);
1957   fputs (_("\
1958   -Wno-comment{s}           Do not warn about comments\n\
1959   -Wtraditional             Warn about features not present in traditional C\n\
1960   -Wno-traditional          Do not warn about traditional C\n\
1961   -Wundef                   Warn if an undefined macro is used by #if\n\
1962   -Wno-undef                Do not warn about testing undefined macros\n\
1963   -Wimport                  Warn about the use of the #import directive\n\
1964 "), stdout);
1965   fputs (_("\
1966   -Wno-import               Do not warn about the use of #import\n\
1967   -Werror                   Treat all warnings as errors\n\
1968   -Wno-error                Do not treat warnings as errors\n\
1969   -Wsystem-headers          Do not suppress warnings from system headers\n\
1970   -Wno-system-headers       Suppress warnings from system headers\n\
1971   -Wall                     Enable all preprocessor warnings\n\
1972 "), stdout);
1973   fputs (_("\
1974   -M                        Generate make dependencies\n\
1975   -MM                       As -M, but ignore system header files\n\
1976   -MD                       Generate make dependencies and compile\n\
1977   -MMD                      As -MD, but ignore system header files\n\
1978   -MF <file>                Write dependency output to the given file\n\
1979   -MG                       Treat missing header file as generated files\n\
1980 "), stdout);
1981   fputs (_("\
1982   -MP                       Generate phony targets for all headers\n\
1983   -MQ <target>              Add a MAKE-quoted target\n\
1984   -MT <target>              Add an unquoted target\n\
1985 "), stdout);
1986   fputs (_("\
1987   -D<macro>                 Define a <macro> with string '1' as its value\n\
1988   -D<macro>=<val>           Define a <macro> with <val> as its value\n\
1989   -A<question>=<answer>     Assert the <answer> to <question>\n\
1990   -A-<question>=<answer>    Disable the <answer> to <question>\n\
1991   -U<macro>                 Undefine <macro> \n\
1992   -v                        Display the version number\n\
1993 "), stdout);
1994   fputs (_("\
1995   -H                        Print the name of header files as they are used\n\
1996   -C                        Do not discard comments\n\
1997   -dM                       Display a list of macro definitions active at end\n\
1998   -dD                       Preserve macro definitions in output\n\
1999   -dN                       As -dD except that only the names are preserved\n\
2000   -dI                       Include #include directives in the output\n\
2001 "), stdout);
2002   fputs (_("\
2003   -fpreprocessed            Treat the input file as already preprocessed\n\
2004   -ftabstop=<number>        Distance between tab stops for column reporting\n\
2005   -P                        Do not generate #line directives\n\
2006   -$                        Do not allow '$' in identifiers\n\
2007   -remap                    Remap file names when including files\n\
2008   --version                 Display version information\n\
2009   -h or --help              Display this information\n\
2010 "), stdout);
2011 }