OSDN Git Service

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