OSDN Git Service

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