OSDN Git Service

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