OSDN Git Service

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