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
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
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.
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. */
31 #include "cppdefault.h"
33 /* Predefined symbols, built-in macros, and the default include path. */
35 #ifndef GET_ENV_PATH_LIST
36 #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
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. */
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
47 #define INO_T_EQ(a, b) ((a) == (b))
50 /* Internal structures and prototypes. */
52 /* A `struct pending_option' remembers one -D, -A, -U, -include, or
55 typedef void (* cl_directive_handler) PARAMS ((cpp_reader *, const char *));
58 struct pending_option *next;
60 cl_directive_handler handler;
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. */
69 struct pending_option *directive_head, *directive_tail;
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;
76 struct pending_option *imacros_head, *imacros_tail;
77 struct pending_option *include_head, *include_tail;
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); \
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); \
94 static void print_help PARAMS ((void));
95 static void path_include PARAMS ((cpp_reader *,
97 static void initialize PARAMS ((void));
98 static void initialize_builtins PARAMS ((cpp_reader *));
99 static void append_include_chain PARAMS ((cpp_reader *,
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 *,
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 *,
114 cl_directive_handler));
116 static int opt_comp PARAMS ((const void *, const void *));
118 static int parse_option PARAMS ((const char *));
120 /* Fourth argument to append_include_chain: chain to use. */
121 enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
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
126 #if HAVE_DESIGNATED_INITIALIZERS
128 #define init_IStable() /* Nothing. */
129 #define ISTABLE __extension__ const U_CHAR _cpp_IStable[UCHAR_MAX + 1] = {
131 #define init_trigraph_map() /* Nothing. */
132 #define TRIGRAPH_MAP \
133 __extension__ const U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = {
136 #define s(p, v) [p] = v,
140 #define ISTABLE unsigned char _cpp_IStable[UCHAR_MAX + 1] = { 0 }; \
141 static void init_IStable PARAMS ((void)) { \
142 unsigned char *x = _cpp_IStable;
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;
149 #define s(p, v) x[p] = v;
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)
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')
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')
170 N('1') N('2') N('3') N('4') N('5') N('6') N('7') N('8') N('9') N('0')
176 S('\0') S('\v') S('\f')
180 s('=', '#') s(')', ']') s('!', '|')
181 s('(', '[') s('\'', '^') s('>', '}')
182 s('/', '\\') s('<', '{') s('-', '~')
195 /* Given a colon-separated list of file names PATH,
196 add all the names to the search path for include files. */
199 path_include (pfile, list, path)
210 /* Find the end of this name. */
212 while (*q != 0 && *q != PATH_SEPARATOR) q++;
215 /* An empty name in the path stands for the current directory. */
216 name = (char *) xmalloc (2);
222 /* Otherwise use the directory that is named. */
223 name = (char *) xmalloc (q - p + 1);
224 memcpy (name, p, q - p);
228 append_include_chain (pfile, name, path, 0);
230 /* Advance past this name. */
238 /* Append DIR to include path PATH. DIR must be permanently allocated
241 append_include_chain (pfile, dir, path, cxx_aware)
247 struct cpp_pending *pend = CPP_OPTION (pfile, pending);
248 struct file_name_list *new;
252 _cpp_simplify_pathname (dir);
255 /* Dirs that don't exist are silently ignored. */
257 cpp_notice_from_errno (pfile, dir);
258 else if (CPP_OPTION (pfile, verbose))
259 fprintf (stderr, _("ignoring nonexistent directory \"%s\"\n"), dir);
263 if (!S_ISDIR (st.st_mode))
265 cpp_notice (pfile, "%s: Not a directory", dir);
270 if (len > pfile->max_include_len)
271 pfile->max_include_len = len;
273 new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
276 new->ino = st.st_ino;
277 new->dev = st.st_dev;
279 new->sysp = cxx_aware ? 1 : 2;
282 new->name_map = NULL;
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;
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)
301 struct file_name_list *prev;
303 struct file_name_list *cur = prev->next;
305 if (CPP_OPTION (pfile, verbose))
306 fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), cur->name);
308 prev->next = cur->next;
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)
322 struct file_name_list *head;
324 struct file_name_list *prev = NULL, *cur, *other;
326 for (cur = head; cur; cur = cur->next)
328 for (other = head; other != cur; other = other->next)
329 if (INO_T_EQ (cur->ino, other->ino) && cur->dev == other->dev)
331 cur = remove_dup_dir (pfile, prev);
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.
346 For the future: Check if the directory is empty (but
347 how?) and possibly preload the include hash. */
350 merge_include_chains (pfile)
353 struct file_name_list *quote, *brack, *systm, *qtail;
355 struct cpp_pending *pend = CPP_OPTION (pfile, pending);
357 quote = pend->quote_head;
358 brack = pend->brack_head;
359 systm = pend->systm_head;
360 qtail = pend->quote_tail;
362 /* Paste together bracket, system, and after include chains. */
364 pend->systm_tail->next = pend->after_head;
366 systm = pend->after_head;
369 pend->brack_tail->next = systm;
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
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. */
384 remove_dup_dirs (pfile, brack);
385 qtail = remove_dup_dirs (pfile, quote);
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);
398 CPP_OPTION (pfile, quote_include) = quote;
399 CPP_OPTION (pfile, bracket_include) = brack;
402 /* Sets internal flags correctly for a given language, and defines
403 macros if necessary. */
405 set_lang (pfile, lang)
409 struct cpp_pending *pend = CPP_OPTION (pfile, pending);
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. */
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);
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;
438 new_pending_directive (pend, "__STDC_VERSION__=199409L", cpp_define);
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);
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);
460 new_pending_directive (pend, "__cplusplus", cpp_define);
461 CPP_OPTION (pfile, cplusplus) = 1;
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);
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);
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);
496 /* initialize initializes library global state. It might not need to
497 do anything depending on the platform and compiler. */
499 static int initialized = 0;
505 /* For non-ASCII hosts, the cl_options array needs to be sorted at
507 qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
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 ();
519 /* Initialize a cpp_reader structure. */
521 cpp_create_reader (lang)
524 struct spec_nodes *s;
525 cpp_reader *pfile = (cpp_reader *) xcalloc (1, sizeof (cpp_reader));
527 /* Initialise this instance of the library if it hasn't been already. */
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;
536 CPP_OPTION (pfile, pending) =
537 (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
539 /* After creating pfile->pending. */
540 set_lang (pfile, lang);
542 /* Initialize lexer state. */
543 pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
545 /* Indicate date and time not yet calculated. */
546 pfile->date.type = CPP_EOF;
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;
553 /* Identifier pool initially 8K. Unaligned, permanent pool. */
554 _cpp_init_pool (&pfile->ident_pool, 8 * 1024, 1, 0);
556 /* String and number pool initially 4K. Unaligned, temporary pool. */
557 _cpp_init_pool (&pfile->temp_string_pool, 4 * 1024, 1, 1);
559 /* Argument pool initially 8K. Aligned, temporary pool. */
560 _cpp_init_pool (&pfile->argument_pool, 8 * 1024, 0, 1);
562 /* Macro pool initially 8K. Aligned, permanent pool. */
563 _cpp_init_pool (&pfile->macro_pool, 8 * 1024, 0, 0);
565 /* Start with temporary pool. */
566 pfile->string_pool = &pfile->temp_string_pool;
568 _cpp_init_hashtable (pfile);
569 _cpp_init_stacks (pfile);
570 _cpp_init_includes (pfile);
571 _cpp_init_internal_pragmas (pfile);
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;
586 /* Free resources used by PFILE.
587 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
592 struct file_name_list *dir, *dirn;
593 cpp_context *context, *contextn;
595 while (CPP_BUFFER (pfile) != NULL)
596 cpp_pop_buffer (pfile);
598 if (pfile->macro_buffer)
599 free ((PTR) pfile->macro_buffer);
602 deps_free (pfile->deps);
604 _cpp_cleanup_includes (pfile);
605 _cpp_cleanup_stacks (pfile);
606 _cpp_cleanup_hashtable (pfile);
608 _cpp_free_lookaheads (pfile);
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);
615 for (dir = CPP_OPTION (pfile, quote_include); dir; dir = dirn)
622 for (context = pfile->base_context.next; context; context = contextn)
624 contextn = context->next;
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.
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
640 Also, macros with CPLUS set in the flags field are entered only for C++. */
646 unsigned char builtin;
647 unsigned char operator;
648 unsigned short flags;
655 #define OPERATOR 0x10
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[] =
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),
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),
678 #ifndef NO_BUILTIN_PTRDIFF_TYPE
679 C("__PTRDIFF_TYPE__", PTRDIFF_TYPE),
681 #ifndef NO_BUILTIN_WCHAR_TYPE
682 C("__WCHAR_TYPE__", WCHAR_TYPE),
684 #ifndef NO_BUILTIN_WINT_TYPE
685 C("__WINT_TYPE__", WINT_TYPE),
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)
707 #define builtin_array_end \
708 builtin_array + sizeof(builtin_array)/sizeof(struct builtin)
710 /* Subroutine of cpp_start_read; reads the builtins table above and
711 enters the macros into the hash table. */
713 initialize_builtins (pfile)
716 const struct builtin *b;
718 for(b = builtin_array; b < builtin_array_end; b++)
720 if ((b->flags & CPLUS) && ! CPP_OPTION (pfile, cplusplus))
723 if (b->flags & (OPERATOR | BUILTIN))
725 cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
726 if (b->flags & OPERATOR)
728 hp->flags |= NODE_OPERATOR;
729 hp->value.operator = b->operator;
734 hp->flags |= NODE_BUILTIN;
735 hp->value.builtin = b->builtin;
738 else /* A standard macro of some kind. */
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);
752 val = CPP_OPTION (pfile, user_label_prefix);
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);
761 _cpp_define_builtin (pfile, str);
770 #undef builtin_array_end
772 /* Another subroutine of cpp_start_read. This one sets up to do
773 dependency-file output. */
775 initialize_dependency_output (pfile)
778 char *spec, *s, *output_file;
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. */
785 if (CPP_OPTION (pfile, print_deps) == 0)
787 spec = getenv ("DEPENDENCIES_OUTPUT");
789 CPP_OPTION (pfile, print_deps) = 1;
792 spec = getenv ("SUNPRO_DEPENDENCIES");
794 CPP_OPTION (pfile, print_deps) = 2;
799 /* Find the space before the DEPS_TARGET, if there is one. */
800 s = strchr (spec, ' ');
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;
810 CPP_OPTION (pfile, deps_target) = 0;
814 CPP_OPTION (pfile, deps_file) = output_file;
815 CPP_OPTION (pfile, print_deps_append) = 1;
818 pfile->deps = deps_init ();
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, "-");
826 deps_calc_target (pfile->deps, CPP_OPTION (pfile, in_fname));
828 if (CPP_OPTION (pfile, in_fname))
829 deps_add_dep (pfile->deps, CPP_OPTION (pfile, in_fname));
832 /* And another subroutine. This one sets up the standard include path. */
834 initialize_standard_includes (pfile)
838 const struct default_include *p;
839 const char *specd_prefix = CPP_OPTION (pfile, include_prefix);
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. */
847 GET_ENV_PATH_LIST (path, "CPATH");
848 if (path != 0 && *path != 0)
849 path_include (pfile, path, BRACKET);
851 switch ((CPP_OPTION (pfile, objc) << 1) + CPP_OPTION (pfile, cplusplus))
854 GET_ENV_PATH_LIST (path, "C_INCLUDE_PATH");
857 GET_ENV_PATH_LIST (path, "CPLUS_INCLUDE_PATH");
860 GET_ENV_PATH_LIST (path, "OBJC_INCLUDE_PATH");
863 GET_ENV_PATH_LIST (path, "OBJCPLUS_INCLUDE_PATH");
866 if (path != 0 && *path != 0)
867 path_include (pfile, path, SYSTEM);
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)
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);
879 memcpy (default_prefix, cpp_GCC_INCLUDE_DIR, default_len);
880 default_prefix[default_len] = '\0';
882 for (p = cpp_include_defaults; p->fname; p++)
884 /* Some standard dirs are only for C++. */
886 || (CPP_OPTION (pfile, cplusplus)
887 && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
889 /* Does this dir start with the prefix? */
890 if (!memcmp (p->fname, default_prefix, default_len))
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);
901 append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
907 /* Search ordinary names for GNU include directories. */
908 for (p = cpp_include_defaults; p->fname; p++)
910 /* Some standard dirs are only for C++. */
912 || (CPP_OPTION (pfile, cplusplus)
913 && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
915 char *str = xstrdup (update_path (p->fname, p->component));
916 append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
921 /* Handles -imacro and -include from the command line. */
923 do_includes (pfile, p, scan)
925 struct pending_option *p;
930 struct pending_option *q;
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);
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,
948 cpp_start_read (pfile, fname)
952 struct pending_option *p, *q;
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)))
961 cpp_fatal (pfile, "-MG must be specified with one of -M or -MM");
965 /* -Wtraditional is not useful in C++ mode. */
966 if (CPP_OPTION (pfile, cplusplus))
967 CPP_OPTION (pfile, warn_traditional) = 0;
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;
973 /* Set up the include search path now. */
974 if (! CPP_OPTION (pfile, no_standard_includes))
975 initialize_standard_includes (pfile);
977 merge_include_chains (pfile);
979 /* With -v, print the list of dirs to search. */
980 if (CPP_OPTION (pfile, verbose))
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)
986 if (l == CPP_OPTION (pfile, bracket_include))
987 fprintf (stderr, _("#include <...> search starts here:\n"));
988 fprintf (stderr, " %s\n", l->name);
990 fprintf (stderr, _("End of search list.\n"));
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)
998 CPP_OPTION (pfile, in_fname) = fname;
999 if (CPP_OPTION (pfile, in_fname) == NULL)
1000 CPP_OPTION (pfile, in_fname) = "";
1002 if (CPP_OPTION (pfile, out_fname) == NULL)
1003 CPP_OPTION (pfile, out_fname) = "";
1005 if (!_cpp_read_file (pfile, fname))
1008 initialize_dependency_output (pfile);
1010 /* Install __LINE__, etc. */
1011 initialize_builtins (pfile);
1013 /* Do -U's, -D's and -A's in the order they were seen. */
1014 p = CPP_OPTION (pfile, pending)->directive_head;
1017 (*p->handler) (pfile, p->arg);
1022 pfile->done_initializing = 1;
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);
1032 free (CPP_OPTION (pfile, pending));
1033 CPP_OPTION (pfile, pending) = NULL;
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. */
1046 if (CPP_BUFFER (pfile))
1048 cpp_ice (pfile, "buffers still stacked in cpp_finish");
1049 while (CPP_BUFFER (pfile))
1050 cpp_pop_buffer (pfile);
1053 /* Don't write the deps file if preprocessing has failed. */
1054 if (CPP_OPTION (pfile, print_deps) && pfile->errors == 0)
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;
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));
1070 deps_write (pfile->deps, deps_stream, 72);
1071 if (CPP_OPTION (pfile, deps_file))
1073 if (ferror (deps_stream) || fclose (deps_stream) != 0)
1074 cpp_fatal (pfile, "I/O error on output");
1079 /* Report on headers that could use multiple include guards. */
1080 if (CPP_OPTION (pfile, print_include_names))
1081 _cpp_report_missing_guards (pfile);
1085 new_pending_directive (pend, text, handler)
1086 struct cpp_pending *pend;
1088 cl_directive_handler handler;
1090 struct pending_option *o = (struct pending_option *)
1091 xmalloc (sizeof (struct pending_option));
1095 o->handler = handler;
1096 APPEND (pend, directive, o);
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")
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)
1176 #define DEF_OPT(text, msg, code) code,
1179 COMMAND_LINE_OPTIONS
1186 const char *opt_text;
1189 enum opt_code opt_code;
1192 #define DEF_OPT(text, msg, code) { text, msg, sizeof(text) - 1, code },
1194 static struct cl_option cl_options[] =
1196 static const struct cl_option cl_options[] =
1199 COMMAND_LINE_OPTIONS
1202 #undef COMMAND_LINE_OPTIONS
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. */
1213 parse_option (input)
1216 unsigned int md, mn, mx;
1227 opt_len = cl_options[md].opt_len;
1228 comp = memcmp (input, cl_options[md].opt_text, opt_len);
1236 if (input[opt_len] == '\0')
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"). */
1244 if (cl_options[md].msg)
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. */
1250 for (; mn < N_OPTS; mn++)
1252 opt_len = cl_options[mn].opt_len;
1253 if (memcmp (input, cl_options[mn].opt_text, opt_len))
1255 if (input[opt_len] == '\0')
1257 if (cl_options[mn].msg)
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. */
1273 cpp_handle_option (pfile, argc, argv)
1279 struct cpp_pending *pend = CPP_OPTION (pfile, pending);
1281 if (argv[i][0] != '-')
1283 if (CPP_OPTION (pfile, out_fname) != NULL)
1284 cpp_fatal (pfile, "Too many arguments. Type %s --help for usage info",
1286 else if (CPP_OPTION (pfile, in_fname) != NULL)
1287 CPP_OPTION (pfile, out_fname) = argv[i];
1289 CPP_OPTION (pfile, in_fname) = argv[i];
1293 enum opt_code opt_code;
1295 const char *arg = 0;
1297 /* Skip over '-'. */
1298 opt_index = parse_option (&argv[i][1]);
1302 opt_code = cl_options[opt_index].opt_code;
1303 if (cl_options[opt_index].msg)
1305 arg = &argv[i][cl_options[opt_index].opt_len + 1];
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))
1315 cpp_fatal (pfile, cl_options[opt_index].msg, argv[i - 1]);
1323 case N_OPTS: /* Shut GCC up. */
1325 case OPT_fleading_underscore:
1326 CPP_OPTION (pfile, user_label_prefix) = "_";
1328 case OPT_fno_leading_underscore:
1329 CPP_OPTION (pfile, user_label_prefix) = "";
1331 case OPT_fpreprocessed:
1332 CPP_OPTION (pfile, preprocessed) = 1;
1334 case OPT_fno_preprocessed:
1335 CPP_OPTION (pfile, preprocessed) = 0;
1337 case OPT_fshow_column:
1338 CPP_OPTION (pfile, show_column) = 1;
1340 case OPT_fno_show_column:
1341 CPP_OPTION (pfile, show_column) = 0;
1344 /* Silently ignore empty string, non-longs and silly values. */
1348 long tabstop = strtol (arg, &endptr, 10);
1349 if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
1350 CPP_OPTION (pfile, tabstop) = tabstop;
1354 CPP_OPTION (pfile, inhibit_warnings) = 1;
1356 case OPT_g: /* Silently ignore anything but -g3. */
1357 if (!strcmp(&argv[i][2], "3"))
1358 CPP_OPTION (pfile, debug_output) = 1;
1365 case OPT_target__help:
1366 /* Print if any target specific options. */
1370 fprintf (stderr, _("GNU CPP version %s (cpplib)\n"), version_string);
1374 CPP_OPTION (pfile, discard_comments) = 0;
1377 CPP_OPTION (pfile, no_line_commands) = 1;
1379 case OPT_dollar: /* Don't include $ in identifiers. */
1380 CPP_OPTION (pfile, dollars_in_ident) = 0;
1383 CPP_OPTION (pfile, print_include_names) = 1;
1386 new_pending_directive (pend, arg, cpp_define);
1388 case OPT_pedantic_errors:
1389 CPP_OPTION (pfile, pedantic_errors) = 1;
1392 CPP_OPTION (pfile, pedantic) = 1;
1395 CPP_OPTION (pfile, trigraphs) = 1;
1398 CPP_OPTION (pfile, cplusplus) = 1;
1399 CPP_OPTION (pfile, cplusplus_comments) = 1;
1402 CPP_OPTION (pfile, remap) = 1;
1405 CPP_OPTION (pfile, include_prefix) = arg;
1406 CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
1409 set_lang (pfile, CLK_GNUC89);
1411 case OPT_lang_cplusplus:
1412 set_lang (pfile, CLK_GNUCXX);
1415 set_lang (pfile, CLK_OBJC);
1417 case OPT_lang_objcplusplus:
1418 set_lang (pfile, CLK_OBJCXX);
1421 set_lang (pfile, CLK_ASM);
1423 case OPT_std_cplusplus98:
1424 set_lang (pfile, CLK_CXX98);
1427 set_lang (pfile, CLK_GNUC89);
1431 set_lang (pfile, CLK_GNUC99);
1433 case OPT_std_iso9899_199409:
1434 set_lang (pfile, CLK_STDC94);
1436 case OPT_std_iso9899_1990:
1439 set_lang (pfile, CLK_STDC89);
1441 case OPT_std_iso9899_199x:
1442 case OPT_std_iso9899_1999:
1445 set_lang (pfile, CLK_STDC99);
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;
1452 case OPT_nostdincplusplus:
1453 /* -nostdinc++ causes no default C++-specific include directories. */
1454 CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1;
1457 if (CPP_OPTION (pfile, out_fname) != NULL)
1459 cpp_fatal (pfile, "Output filename specified twice");
1462 CPP_OPTION (pfile, out_fname) = arg;
1463 if (!strcmp (CPP_OPTION (pfile, out_fname), "-"))
1464 CPP_OPTION (pfile, out_fname) = "";
1467 fprintf (stderr, _("GNU CPP version %s (cpplib)"), version_string);
1468 #ifdef TARGET_VERSION
1471 fputc ('\n', stderr);
1472 CPP_OPTION (pfile, verbose) = 1;
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) = "";
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. */
1488 while ((c = *arg++) != '\0')
1492 CPP_OPTION (pfile, dump_macros) = dump_only;
1493 CPP_OPTION (pfile, no_output) = 1;
1496 CPP_OPTION (pfile, dump_macros) = dump_names;
1499 CPP_OPTION (pfile, dump_macros) = dump_definitions;
1502 CPP_OPTION (pfile, dump_includes) = 1;
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
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. */
1518 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
1520 CPP_OPTION (pfile, print_deps_missing_files) = 1;
1526 if (opt_code == OPT_M || opt_code == OPT_MD)
1527 CPP_OPTION (pfile, print_deps) = 2;
1529 CPP_OPTION (pfile, print_deps) = 1;
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;
1537 CPP_OPTION (pfile, no_output) = 1;
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. */
1552 struct pending_option *o1, *o2;
1554 o1 = pend->directive_head;
1561 pend->directive_head = NULL;
1562 pend->directive_tail = NULL;
1565 new_pending_directive (pend, arg + 1, cpp_unassert);
1568 new_pending_directive (pend, arg, cpp_assert);
1571 new_pending_directive (pend, arg, cpp_undef);
1573 case OPT_I: /* Add directory to path for includes. */
1574 if (!strcmp (arg, "-"))
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))
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;
1592 cpp_fatal (pfile, "-I- specified twice");
1597 append_include_chain (pfile, xstrdup (arg), BRACKET, 0);
1600 /* Add directory to beginning of system include path, as a system
1601 include directory. */
1602 append_include_chain (pfile, xstrdup (arg), SYSTEM, 0);
1606 struct pending_option *o = (struct pending_option *)
1607 xmalloc (sizeof (struct pending_option));
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;
1619 struct pending_option *o = (struct pending_option *)
1620 xmalloc (sizeof (struct pending_option));
1624 APPEND (pend, imacros, o);
1627 case OPT_iwithprefix:
1628 /* Add directory to end of path for includes,
1629 with the default prefix at the front of its name. */
1631 case OPT_iwithprefixbefore:
1632 /* Add directory to main path for includes,
1633 with the default prefix at the front of its name. */
1640 if (CPP_OPTION (pfile, include_prefix) != 0)
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);
1647 else if (cpp_GCC_INCLUDE_DIR_len)
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);
1654 fname = xstrdup (arg);
1656 append_include_chain (pfile, fname,
1657 opt_code == OPT_iwithprefix ? SYSTEM: BRACKET, 0);
1661 /* Add directory to end of path for includes. */
1662 append_include_chain (pfile, xstrdup (arg), AFTER, 0);
1665 /* Silently ignore unrecognised options. */
1666 if (!strcmp (argv[i], "-Wall"))
1668 CPP_OPTION (pfile, warn_trigraphs) = 1;
1669 CPP_OPTION (pfile, warn_comments) = 1;
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;
1711 opt_comp (const void *p1, const void *p2)
1713 return strcmp (((struct cl_option *)p1)->opt_text,
1714 ((struct cl_option *)p2)->opt_text);
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. */
1723 cpp_handle_options (pfile, argc, argv)
1729 int strings_processed;
1731 for (i = 0; i < argc; i += strings_processed)
1733 strings_processed = cpp_handle_option (pfile, argc - i, argv + i);
1734 if (strings_processed == 0)
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. */
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\
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\
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\
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\
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\
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\
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\
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\
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\
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\
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\