OSDN Git Service

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