* as/link/mcs51/lkarea.c (lnkarea2): handle absolute areas, restructured
[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   DEF_OPT("remap",                    0,      OPT_remap)                      \
1249   DEF_OPT("std=c++98",                0,      OPT_std_cplusplus98)            \
1250   DEF_OPT("std=c89",                  0,      OPT_std_c89)                    \
1251   DEF_OPT("std=c99",                  0,      OPT_std_c99)                    \
1252   DEF_OPT("std=c9x",                  0,      OPT_std_c9x)                    \
1253   DEF_OPT("std=gnu89",                0,      OPT_std_gnu89)                  \
1254   DEF_OPT("std=gnu99",                0,      OPT_std_gnu99)                  \
1255   DEF_OPT("std=gnu9x",                0,      OPT_std_gnu9x)                  \
1256   DEF_OPT("std=iso9899:1990",         0,      OPT_std_iso9899_1990)           \
1257   DEF_OPT("std=iso9899:199409",       0,      OPT_std_iso9899_199409)         \
1258   DEF_OPT("std=iso9899:1999",         0,      OPT_std_iso9899_1999)           \
1259   DEF_OPT("std=iso9899:199x",         0,      OPT_std_iso9899_199x)           \
1260   DEF_OPT("trigraphs",                0,      OPT_trigraphs)                  \
1261   DEF_OPT("v",                        0,      OPT_v)                          \
1262   DEF_OPT("version",                  0,      OPT_version)                    \
1263   DEF_OPT("w",                        0,      OPT_w)
1264
1265 #define DEF_OPT(text, msg, code) code,
1266 enum opt_code
1267 {
1268   COMMAND_LINE_OPTIONS
1269   N_OPTS
1270 };
1271 #undef DEF_OPT
1272
1273 struct cl_option
1274 {
1275   const char *opt_text;
1276   const char *msg;
1277   size_t opt_len;
1278   enum opt_code opt_code;
1279 };
1280
1281 #define DEF_OPT(text, msg, code) { text, msg, sizeof(text) - 1, code },
1282 #ifdef HOST_EBCDIC
1283 static struct cl_option cl_options[] =
1284 #else
1285 static const struct cl_option cl_options[] =
1286 #endif
1287 {
1288   COMMAND_LINE_OPTIONS
1289 };
1290 #undef DEF_OPT
1291 #undef COMMAND_LINE_OPTIONS
1292
1293 /* Perform a binary search to find which, if any, option the given
1294    command-line matches.  Returns its index in the option array,
1295    negative on failure.  Complications arise since some options can be
1296    suffixed with an argument, and multiple complete matches can occur,
1297    e.g. -pedantic and -pedantic-errors.  */
1298 static int
1299 parse_option (input)
1300      const char *input;
1301 {
1302   unsigned int md, mn, mx;
1303   size_t opt_len;
1304   int comp;
1305
1306   mn = 0;
1307   mx = N_OPTS;
1308
1309   while (mx > mn)
1310     {
1311       md = (mn + mx) / 2;
1312
1313       opt_len = cl_options[md].opt_len;
1314       comp = strncmp (input, cl_options[md].opt_text, opt_len);
1315
1316       if (comp > 0)
1317         mn = md + 1;
1318       else if (comp < 0)
1319         mx = md;
1320       else
1321         {
1322           if (input[opt_len] == '\0')
1323             return md;
1324           /* We were passed more text.  If the option takes an argument,
1325              we may match a later option or we may have been passed the
1326              argument.  The longest possible option match succeeds.
1327              If the option takes no arguments we have not matched and
1328              continue the search (e.g. input="stdc++" match was "stdc").  */
1329           mn = md + 1;
1330           if (cl_options[md].msg)
1331             {
1332               /* Scan forwards.  If we get an exact match, return it.
1333                  Otherwise, return the longest option-accepting match.
1334                  This loops no more than twice with current options.  */
1335               mx = md;
1336               for (; mn < (unsigned int) N_OPTS; mn++)
1337                 {
1338                   opt_len = cl_options[mn].opt_len;
1339                   if (strncmp (input, cl_options[mn].opt_text, opt_len))
1340                     break;
1341                   if (input[opt_len] == '\0')
1342                     return mn;
1343                   if (cl_options[mn].msg)
1344                     mx = mn;
1345                 }
1346               return mx;
1347             }
1348         }
1349     }
1350
1351   return -1;
1352 }
1353
1354 /* Handle one command-line option in (argc, argv).
1355    Can be called multiple times, to handle multiple sets of options.
1356    Returns number of strings consumed.  */
1357 int
1358 cpp_handle_option (pfile, argc, argv)
1359      cpp_reader *pfile;
1360      int argc;
1361      char **argv;
1362 {
1363   int i = 0;
1364   struct cpp_pending *pend = CPP_OPTION (pfile, pending);
1365
1366   /* Interpret "-" or a non-option as a file name.  */
1367   if (argv[i][0] != '-' || argv[i][1] == '\0')
1368     {
1369       if (CPP_OPTION (pfile, in_fname) == NULL)
1370         CPP_OPTION (pfile, in_fname) = argv[i];
1371       else if (CPP_OPTION (pfile, out_fname) == NULL)
1372         CPP_OPTION (pfile, out_fname) = argv[i];
1373       else
1374         cpp_error (pfile, DL_ERROR, "too many filenames. Type %s --help for usage info",
1375                    progname);
1376     }
1377   else
1378     {
1379       enum opt_code opt_code;
1380       int opt_index;
1381       const char *arg = 0;
1382
1383       /* Skip over '-'.  */
1384       opt_index = parse_option (&argv[i][1]);
1385       if (opt_index < 0)
1386         return i;
1387
1388       opt_code = cl_options[opt_index].opt_code;
1389       if (cl_options[opt_index].msg)
1390         {
1391           arg = &argv[i][cl_options[opt_index].opt_len + 1];
1392           /* Yuk. Special case for -W as it must not swallow
1393              up any following argument.  If this becomes common, add
1394              another field to the cl_options table.  */
1395           if (arg[0] == '\0' && opt_code != OPT_W)
1396             {
1397               arg = argv[++i];
1398               if (!arg)
1399                 {
1400                   cpp_error (pfile, DL_ERROR,
1401                              cl_options[opt_index].msg, argv[i - 1]);
1402                   return argc;
1403                 }
1404             }
1405         }
1406
1407       switch (opt_code)
1408         {
1409         case N_OPTS: /* Shut GCC up.  */
1410           break;
1411         case OPT_fno_operator_names:
1412           CPP_OPTION (pfile, operator_names) = 0;
1413           break;
1414         case OPT_fpreprocessed:
1415           CPP_OPTION (pfile, preprocessed) = 1;
1416           break;
1417         case OPT_fno_preprocessed:
1418           CPP_OPTION (pfile, preprocessed) = 0;
1419           break;
1420         case OPT_fshow_column:
1421           CPP_OPTION (pfile, show_column) = 1;
1422           break;
1423         case OPT_fno_show_column:
1424           CPP_OPTION (pfile, show_column) = 0;
1425           break;
1426         case OPT_ftabstop:
1427           /* Silently ignore empty string, non-longs and silly values.  */
1428           if (arg[0] != '\0')
1429             {
1430               char *endptr;
1431               long tabstop = strtol (arg, &endptr, 10);
1432               if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
1433                 CPP_OPTION (pfile, tabstop) = tabstop;
1434             }
1435           break;
1436         case OPT_fsigned_char:
1437           CPP_OPTION (pfile, unsigned_char) = 0;
1438           break;
1439         case OPT_funsigned_char:
1440           CPP_OPTION (pfile, unsigned_char) = 1;
1441           break;
1442         case OPT_w:
1443           CPP_OPTION (pfile, inhibit_warnings) = 1;
1444           break;
1445         case OPT_h:
1446         case OPT__help:
1447           print_help ();
1448           CPP_OPTION (pfile, help_only) = 1;
1449           break;
1450         case OPT_target__help:
1451           /* Print if any target specific options. cpplib has none, but
1452              make sure help_only gets set.  */
1453           CPP_OPTION (pfile, help_only) = 1;
1454           break;
1455
1456           /* --version inhibits compilation, -version doesn't. -v means
1457              verbose and -version.  Historical reasons, don't ask.  */
1458         case OPT__version:
1459           CPP_OPTION (pfile, help_only) = 1;
1460           pfile->print_version = 1;
1461           break;
1462         case OPT_v:
1463           CPP_OPTION (pfile, verbose) = 1;
1464           pfile->print_version = 1;
1465           break;
1466         case OPT_version:
1467           pfile->print_version = 1;
1468           break;
1469
1470         case OPT_C:
1471           CPP_OPTION (pfile, discard_comments) = 0;
1472           break;
1473         case OPT_P:
1474           CPP_OPTION (pfile, no_line_commands) = 1;
1475           break;
1476         case OPT_dollar:        /* Don't include $ in identifiers.  */
1477           CPP_OPTION (pfile, dollars_in_ident) = 0;
1478           break;
1479         case OPT_H:
1480           CPP_OPTION (pfile, print_include_names) = 1;
1481           break;
1482         case OPT_D:
1483           new_pending_directive (pend, arg, cpp_define);
1484           break;
1485         case OPT_pedantic_errors:
1486           CPP_OPTION (pfile, pedantic_errors) = 1;
1487           /* fall through */
1488         case OPT_pedantic:
1489           CPP_OPTION (pfile, pedantic) = 1;
1490           break;
1491         case OPT_trigraphs:
1492           CPP_OPTION (pfile, trigraphs) = 1;
1493           break;
1494         case OPT_plus:
1495           CPP_OPTION (pfile, cplusplus) = 1;
1496           CPP_OPTION (pfile, cplusplus_comments) = 1;
1497           break;
1498         case OPT_remap:
1499           CPP_OPTION (pfile, remap) = 1;
1500           break;
1501         case OPT_iprefix:
1502           CPP_OPTION (pfile, include_prefix) = arg;
1503           CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
1504           break;
1505         case OPT_isysroot:
1506           CPP_OPTION (pfile, sysroot) = arg;
1507           break;
1508         case OPT_lang_c:
1509           cpp_set_lang (pfile, CLK_GNUC89);
1510           break;
1511         case OPT_lang_cplusplus:
1512           cpp_set_lang (pfile, CLK_GNUCXX);
1513           break;
1514         case OPT_lang_asm:
1515           cpp_set_lang (pfile, CLK_ASM);
1516           break;
1517         case OPT_std_cplusplus98:
1518           cpp_set_lang (pfile, CLK_CXX98);
1519           break;
1520         case OPT_std_gnu89:
1521           cpp_set_lang (pfile, CLK_GNUC89);
1522           break;
1523         case OPT_std_gnu9x:
1524         case OPT_std_gnu99:
1525           cpp_set_lang (pfile, CLK_GNUC99);
1526           break;
1527         case OPT_std_iso9899_199409:
1528           cpp_set_lang (pfile, CLK_STDC94);
1529           break;
1530         case OPT_std_iso9899_1990:
1531         case OPT_std_c89:
1532         case OPT_lang_c89:
1533           cpp_set_lang (pfile, CLK_STDC89);
1534           break;
1535         case OPT_std_iso9899_199x:
1536         case OPT_std_iso9899_1999:
1537         case OPT_std_c9x:
1538         case OPT_std_c99:
1539           cpp_set_lang (pfile, CLK_STDC99);
1540           break;
1541         case OPT_nostdinc:
1542           /* -nostdinc causes no default include directories.
1543              You must specify all include-file directories with -I.  */
1544           CPP_OPTION (pfile, no_standard_includes) = 1;
1545           break;
1546         case OPT_nostdincplusplus:
1547           /* -nostdinc++ causes no default C++-specific include directories.  */
1548           CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1;
1549           break;
1550         case OPT_o:
1551           if (CPP_OPTION (pfile, out_fname) == NULL)
1552             CPP_OPTION (pfile, out_fname) = arg;
1553           else
1554             {
1555               cpp_error (pfile, DL_ERROR, "output filename specified twice");
1556               return argc;
1557             }
1558           break;
1559         case OPT_d:
1560           /* Args to -d specify what parts of macros to dump.
1561              Silently ignore unrecognised options; they may
1562              be aimed at the compiler proper.  */
1563           {
1564             char c;
1565
1566             while ((c = *arg++) != '\0')
1567               switch (c)
1568                 {
1569                 case 'M':
1570                   CPP_OPTION (pfile, dump_macros) = dump_only;
1571                   break;
1572                 case 'N':
1573                   CPP_OPTION (pfile, dump_macros) = dump_names;
1574                   break;
1575                 case 'D':
1576                   CPP_OPTION (pfile, dump_macros) = dump_definitions;
1577                   break;
1578                 case 'I':
1579                   CPP_OPTION (pfile, dump_includes) = 1;
1580                   break;
1581                 }
1582           }
1583           break;
1584
1585         case OPT_MG:
1586           CPP_OPTION (pfile, deps.missing_files) = 1;
1587           break;
1588         case OPT_M:
1589           /* When doing dependencies with -M or -MM, suppress normal
1590              preprocessed output, but still do -dM etc. as software
1591              depends on this.  Preprocessed output occurs if -MD, -MMD
1592              or environment var dependency generation is used.  */
1593           CPP_OPTION (pfile, deps.style) = 2;
1594           CPP_OPTION (pfile, no_output) = 1;
1595           break;
1596         case OPT_MM:
1597           CPP_OPTION (pfile, deps.style) = 1;
1598           CPP_OPTION (pfile, no_output) = 1;
1599           break;
1600         case OPT_MF:
1601           CPP_OPTION (pfile, deps.file) = arg;
1602           break;
1603         case OPT_MP:
1604           CPP_OPTION (pfile, deps.phony_targets) = 1;
1605           break;
1606         case OPT_MQ:
1607         case OPT_MT:
1608           /* Add a target.  -MQ quotes for Make.  */
1609           deps_add_target (pfile->deps, arg, opt_code == OPT_MQ);
1610           break;
1611
1612         case OPT_MD:
1613           CPP_OPTION (pfile, deps.style) = 2;
1614           CPP_OPTION (pfile, deps.file) = arg;
1615           break;
1616         case OPT_MMD:
1617           CPP_OPTION (pfile, deps.style) = 1;
1618           CPP_OPTION (pfile, deps.file) = arg;
1619           break;
1620
1621         case OPT_A:
1622           if (arg[0] == '-')
1623             {
1624               /* -A with an argument beginning with '-' acts as
1625                  #unassert on whatever immediately follows the '-'.
1626                  If "-" is the whole argument, we eliminate all
1627                  predefined macros and assertions, including those
1628                  that were specified earlier on the command line.
1629                  That way we can get rid of any that were passed
1630                  automatically in from GCC.  */
1631
1632               if (arg[1] == '\0')
1633                 {
1634                   free_chain (pend->directive_head);
1635                   pend->directive_head = NULL;
1636                   pend->directive_tail = NULL;
1637                 }
1638               else
1639                 new_pending_directive (pend, arg + 1, cpp_unassert);
1640             }
1641           else
1642             new_pending_directive (pend, arg, cpp_assert);
1643           break;
1644         case OPT_U:
1645           new_pending_directive (pend, arg, cpp_undef);
1646           break;
1647         case OPT_I:           /* Add directory to path for includes.  */
1648           if (!strcmp (arg, "-"))
1649             {
1650               /* -I- means:
1651                  Use the preceding -I directories for #include "..."
1652                  but not #include <...>.
1653                  Don't search the directory of the present file
1654                  for #include "...".  (Note that -I. -I- is not the same as
1655                  the default setup; -I. uses the compiler's working dir.)  */
1656               if (! CPP_OPTION (pfile, ignore_srcdir))
1657                 {
1658                   pend->quote_head = pend->brack_head;
1659                   pend->quote_tail = pend->brack_tail;
1660                   pend->brack_head = 0;
1661                   pend->brack_tail = 0;
1662                   CPP_OPTION (pfile, ignore_srcdir) = 1;
1663                 }
1664               else
1665                 {
1666                   cpp_error (pfile, DL_ERROR, "-I- specified twice");
1667                   return argc;
1668                 }
1669             }
1670           else
1671             append_include_chain (pfile, (char *)xstrdup (arg), BRACKET, 0);
1672           break;
1673         case OPT_isystem:
1674           /* Add directory to beginning of system include path, as a system
1675              include directory.  */
1676           append_include_chain (pfile, (char *)xstrdup (arg), SYSTEM, 0);
1677           break;
1678         case OPT_include:
1679         case OPT_imacros:
1680           {
1681             struct pending_option *o = (struct pending_option *)
1682               xmalloc (sizeof (struct pending_option));
1683             o->arg = arg;
1684             o->next = NULL;
1685
1686             if (opt_code == OPT_include)
1687               APPEND (pend, include, o);
1688             else
1689               APPEND (pend, imacros, o);
1690           }
1691           break;
1692         case OPT_iwithprefix:
1693           /* Add directory to end of path for includes,
1694              with the default prefix at the front of its name.  */
1695           /* fall through */
1696         case OPT_iwithprefixbefore:
1697           /* Add directory to main path for includes,
1698              with the default prefix at the front of its name.  */
1699           {
1700             char *fname;
1701             int len;
1702
1703             len = strlen (arg);
1704
1705             if (CPP_OPTION (pfile, include_prefix) != 0)
1706               {
1707                 size_t ipl = CPP_OPTION (pfile, include_prefix_len);
1708                 fname = xmalloc (ipl + len + 1);
1709                 memcpy (fname, CPP_OPTION (pfile, include_prefix), ipl);
1710                 memcpy (fname + ipl, arg, len + 1);
1711               }
1712             else if (cpp_GCC_INCLUDE_DIR_len)
1713               {
1714                 fname = xmalloc (cpp_GCC_INCLUDE_DIR_len + len + 1);
1715                 memcpy (fname, cpp_GCC_INCLUDE_DIR, cpp_GCC_INCLUDE_DIR_len);
1716                 memcpy (fname + cpp_GCC_INCLUDE_DIR_len, arg, len + 1);
1717               }
1718             else
1719               fname = xstrdup (arg);
1720
1721             append_include_chain (pfile, fname,
1722                           opt_code == OPT_iwithprefix ? SYSTEM: BRACKET, 0);
1723           }
1724           break;
1725         case OPT_idirafter:
1726           /* Add directory to end of path for includes.  */
1727           append_include_chain (pfile, (char *)xstrdup (arg), AFTER, 0);
1728           break;
1729         case OPT_W:
1730           /* Silently ignore unrecognised options.  */
1731           if (!strcmp (argv[i], "-Wall"))
1732             {
1733               CPP_OPTION (pfile, warn_trigraphs) = 1;
1734               CPP_OPTION (pfile, warn_comments) = 1;
1735             }
1736           else if (!strcmp (argv[i], "-Wtraditional"))
1737             CPP_OPTION (pfile, warn_traditional) = 1;
1738           else if (!strcmp (argv[i], "-Wtrigraphs"))
1739             CPP_OPTION (pfile, warn_trigraphs) = 1;
1740           else if (!strcmp (argv[i], "-Wcomment"))
1741             CPP_OPTION (pfile, warn_comments) = 1;
1742           else if (!strcmp (argv[i], "-Wcomments"))
1743             CPP_OPTION (pfile, warn_comments) = 1;
1744           else if (!strcmp (argv[i], "-Wundef"))
1745             CPP_OPTION (pfile, warn_undef) = 1;
1746           else if (!strcmp (argv[i], "-Wimport"))
1747             CPP_OPTION (pfile, warn_import) = 1;
1748           else if (!strcmp (argv[i], "-Werror"))
1749             CPP_OPTION (pfile, warnings_are_errors) = 1;
1750           else if (!strcmp (argv[i], "-Wsystem-headers"))
1751             CPP_OPTION (pfile, warn_system_headers) = 1;
1752           else if (!strcmp (argv[i], "-Wno-traditional"))
1753             CPP_OPTION (pfile, warn_traditional) = 0;
1754           else if (!strcmp (argv[i], "-Wno-trigraphs"))
1755             CPP_OPTION (pfile, warn_trigraphs) = 0;
1756           else if (!strcmp (argv[i], "-Wno-comment"))
1757             CPP_OPTION (pfile, warn_comments) = 0;
1758           else if (!strcmp (argv[i], "-Wno-comments"))
1759             CPP_OPTION (pfile, warn_comments) = 0;
1760           else if (!strcmp (argv[i], "-Wno-undef"))
1761             CPP_OPTION (pfile, warn_undef) = 0;
1762           else if (!strcmp (argv[i], "-Wno-import"))
1763             CPP_OPTION (pfile, warn_import) = 0;
1764           else if (!strcmp (argv[i], "-Wno-error"))
1765             CPP_OPTION (pfile, warnings_are_errors) = 0;
1766           else if (!strcmp (argv[i], "-Wno-system-headers"))
1767             CPP_OPTION (pfile, warn_system_headers) = 0;
1768           break;
1769         /* SDCC specific */
1770         case OPT_obj_ext:
1771           CPP_OPTION (pfile, obj_ext) = arg;
1772           break;
1773         }
1774     }
1775   return i + 1;
1776 }
1777
1778 /* Handle command-line options in (argc, argv).
1779    Can be called multiple times, to handle multiple sets of options.
1780    Returns if an unrecognized option is seen.
1781    Returns number of strings consumed.  */
1782 int
1783 cpp_handle_options (pfile, argc, argv)
1784      cpp_reader *pfile;
1785      int argc;
1786      char **argv;
1787 {
1788   int i;
1789   int strings_processed;
1790
1791   for (i = 0; i < argc; i += strings_processed)
1792     {
1793       strings_processed = cpp_handle_option (pfile, argc - i, argv + i);
1794       if (strings_processed == 0)
1795         break;
1796     }
1797
1798   return i;
1799 }
1800
1801 static void
1802 post_options (pfile)
1803      cpp_reader *pfile;
1804 {
1805   /* -Wtraditional is not useful in C++ mode.  */
1806   if (CPP_OPTION (pfile, cplusplus))
1807     CPP_OPTION (pfile, warn_traditional) = 0;
1808
1809   /* Permanently disable macro expansion if we are rescanning
1810      preprocessed text.  Read preprocesed source in ISO mode.  */
1811   if (CPP_OPTION (pfile, preprocessed))
1812     {
1813       pfile->state.prevent_expansion = 1;
1814       CPP_OPTION (pfile, traditional) = 0;
1815     }
1816
1817   /* Traditional CPP does not accurately track column information.  */
1818   if (CPP_OPTION (pfile, traditional))
1819     CPP_OPTION (pfile, show_column) = 0;
1820 }
1821
1822 /* Handle --help output.  */
1823 static void
1824 print_help ()
1825 {
1826   /* To keep the lines from getting too long for some compilers, limit
1827      to about 500 characters (6 lines) per chunk.  */
1828   fputs (_("\
1829 Switches:\n\
1830   -include <file>           Include the contents of <file> before other files\n\
1831   -imacros <file>           Accept definition of macros in <file>\n\
1832   -iprefix <path>           Specify <path> as a prefix for next two options\n\
1833   -iwithprefix <dir>        Add <dir> to the end of the system include path\n\
1834   -iwithprefixbefore <dir>  Add <dir> to the end of the main include path\n\
1835   -isystem <dir>            Add <dir> to the start of the system include path\n\
1836   -isysroot <dir>           Set <dir> to be the system root directory\n\
1837 "), stdout);
1838   fputs (_("\
1839   -idirafter <dir>          Add <dir> to the end of the system include path\n\
1840   -I <dir>                  Add <dir> to the end of the main include path\n\
1841   -I-                       Fine-grained include path control; see info docs\n\
1842   -nostdinc                 Do not search system include directories\n\
1843                              (dirs specified with -isystem will still be used)\n\
1844   -nostdinc++               Do not search system include directories for C++\n\
1845   -o <file>                 Put output into <file>\n\
1846 "), stdout);
1847   fputs (_("\
1848   -pedantic                 Issue all warnings demanded by strict ISO C\n\
1849   -pedantic-errors          Issue -pedantic warnings as errors instead\n\
1850   -trigraphs                Support ISO C trigraphs\n\
1851   -lang-c                   Assume that the input sources are in C\n\
1852   -lang-c89                 Assume that the input sources are in C89\n\
1853 "), stdout);
1854   fputs (_("\
1855   -lang-c++                 Assume that the input sources are in C++\n\
1856   -lang-asm                 Assume that the input sources are in assembler\n\
1857 "), stdout);
1858   fputs (_("\
1859   -std=<std name>           Specify the conformance standard; one of:\n\
1860                             gnu89, gnu99, c89, c99, iso9899:1990,\n\
1861                             iso9899:199409, iso9899:1999\n\
1862   -+                        Allow parsing of C++ style features\n\
1863   -w                        Inhibit warning messages\n\
1864   -Wtrigraphs               Warn if trigraphs are encountered\n\
1865   -Wno-trigraphs            Do not warn about trigraphs\n\
1866   -Wcomment{s}              Warn if one comment starts inside another\n\
1867 "), stdout);
1868   fputs (_("\
1869   -Wno-comment{s}           Do not warn about comments\n\
1870   -Wtraditional             Warn about features not present in traditional C\n\
1871   -Wno-traditional          Do not warn about traditional C\n\
1872   -Wundef                   Warn if an undefined macro is used by #if\n\
1873   -Wno-undef                Do not warn about testing undefined macros\n\
1874   -Wimport                  Warn about the use of the #import directive\n\
1875 "), stdout);
1876   fputs (_("\
1877   -Wno-import               Do not warn about the use of #import\n\
1878   -Werror                   Treat all warnings as errors\n\
1879   -Wno-error                Do not treat warnings as errors\n\
1880   -Wsystem-headers          Do not suppress warnings from system headers\n\
1881   -Wno-system-headers       Suppress warnings from system headers\n\
1882   -Wall                     Enable all preprocessor warnings\n\
1883 "), stdout);
1884   fputs (_("\
1885   -M                        Generate make dependencies\n\
1886   -MM                       As -M, but ignore system header files\n\
1887   -MD                       Generate make dependencies and compile\n\
1888   -MMD                      As -MD, but ignore system header files\n\
1889   -MF <file>                Write dependency output to the given file\n\
1890   -MG                       Treat missing header file as generated files\n\
1891 "), stdout);
1892   fputs (_("\
1893   -MP                       Generate phony targets for all headers\n\
1894   -MQ <target>              Add a MAKE-quoted target\n\
1895   -MT <target>              Add an unquoted target\n\
1896 "), stdout);
1897   /* SDCC specific */
1898   fputs (_("\
1899   -obj-ext=<extension>      Define object file extension, used for generation\n\
1900                             of make dependencies\n\
1901 "), stdout);
1902   fputs (_("\
1903   -D<macro>                 Define a <macro> with string '1' as its value\n\
1904   -D<macro>=<val>           Define a <macro> with <val> as its value\n\
1905   -A<question>=<answer>     Assert the <answer> to <question>\n\
1906   -A-<question>=<answer>    Disable the <answer> to <question>\n\
1907   -U<macro>                 Undefine <macro> \n\
1908   -v                        Display the version number\n\
1909 "), stdout);
1910   fputs (_("\
1911   -H                        Print the name of header files as they are used\n\
1912   -C                        Do not discard comments\n\
1913   -dM                       Display a list of macro definitions active at end\n\
1914   -dD                       Preserve macro definitions in output\n\
1915   -dN                       As -dD except that only the names are preserved\n\
1916   -dI                       Include #include directives in the output\n\
1917 "), stdout);
1918   fputs (_("\
1919   -fpreprocessed            Treat the input file as already preprocessed\n\
1920   -ftabstop=<number>        Distance between tab stops for column reporting\n\
1921   -fsigned-char             Make \"char\" signed by default\n\
1922   -funsigned-char           Make \"char\" unsigned by default\n\
1923   -P                        Do not generate #line directives\n\
1924   -$                        Do not allow '$' in identifiers\n\
1925   -remap                    Remap file names when including files\n\
1926   --version                 Display version information\n\
1927   -h or --help              Display this information\n\
1928 "), stdout);
1929 }