OSDN Git Service

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