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