2 Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 Contributed by Per Bothner, 1994-95.
5 Based on CCCP program by Paul Rubin, June 1986
6 Adapted to ANSI C, Richard Stallman, Jan 1987
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. */
30 #include "cppdefault.h"
32 /* Windows does not natively support inodes, and neither does MSDOS.
33 Cygwin's emulation can generate non-unique inodes, so don't use it.
34 VMS has non-numeric inodes. */
36 # define INO_T_EQ(A, B) (!memcmp (&(A), &(B), sizeof (A)))
37 # define INO_T_COPY(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof (SRC))
39 # if (defined _WIN32 && ! defined (_UWIN)) || defined __MSDOS__
40 # define INO_T_EQ(A, B) 0
42 # define INO_T_EQ(A, B) ((A) == (B))
44 # define INO_T_COPY(DEST, SRC) (DEST) = (SRC)
47 /* Internal structures and prototypes. */
49 /* A `struct pending_option' remembers one -D, -A, -U, -include, or
51 typedef void (* cl_directive_handler) PARAMS ((cpp_reader *, const char *));
54 struct pending_option *next;
56 cl_directive_handler handler;
59 /* The `pending' structure accumulates all the options that are not
60 actually processed until we hit cpp_read_main_file. It consists of
61 several lists, one for each type of option. We keep both head and
62 tail pointers for quick insertion. */
65 struct pending_option *directive_head, *directive_tail;
67 struct search_path *quote_head, *quote_tail;
68 struct search_path *brack_head, *brack_tail;
69 struct search_path *systm_head, *systm_tail;
70 struct search_path *after_head, *after_tail;
72 struct pending_option *imacros_head, *imacros_tail;
73 struct pending_option *include_head, *include_tail;
77 #define APPEND(pend, list, elt) \
78 do { if (!(pend)->list##_head) (pend)->list##_head = (elt); \
79 else (pend)->list##_tail->next = (elt); \
80 (pend)->list##_tail = (elt); \
83 #define APPEND(pend, list, elt) \
84 do { if (!(pend)->list/**/_head) (pend)->list/**/_head = (elt); \
85 else (pend)->list/**/_tail->next = (elt); \
86 (pend)->list/**/_tail = (elt); \
90 static void print_help PARAMS ((void));
91 static void path_include PARAMS ((cpp_reader *,
93 static void init_library PARAMS ((void));
94 static void init_builtins PARAMS ((cpp_reader *));
95 static void mark_named_operators PARAMS ((cpp_reader *));
96 static void append_include_chain PARAMS ((cpp_reader *,
98 static struct search_path * remove_dup_dir PARAMS ((cpp_reader *,
100 struct search_path **));
101 static struct search_path * remove_dup_nonsys_dirs PARAMS ((cpp_reader *,
102 struct search_path **,
103 struct search_path *));
104 static struct search_path * remove_dup_dirs PARAMS ((cpp_reader *,
105 struct search_path **));
106 static void merge_include_chains PARAMS ((cpp_reader *));
107 static bool push_include PARAMS ((cpp_reader *,
108 struct pending_option *));
109 static void free_chain PARAMS ((struct pending_option *));
110 static void init_standard_includes PARAMS ((cpp_reader *));
111 static void read_original_filename PARAMS ((cpp_reader *));
112 static void new_pending_directive PARAMS ((struct cpp_pending *,
114 cl_directive_handler));
115 static int parse_option PARAMS ((const char *));
116 static void post_options PARAMS ((cpp_reader *));
118 /* Fourth argument to append_include_chain: chain to use.
119 Note it's never asked to append to the quote chain. */
120 enum { BRACKET = 0, SYSTEM, AFTER };
122 /* If we have designated initializers (GCC >2.7) these tables can be
123 initialized, constant data. Otherwise, they have to be filled in at
125 #if HAVE_DESIGNATED_INITIALIZERS
127 #define init_trigraph_map() /* Nothing. */
128 #define TRIGRAPH_MAP \
129 __extension__ const uchar _cpp_trigraph_map[UCHAR_MAX + 1] = {
132 #define s(p, v) [p] = v,
136 #define TRIGRAPH_MAP uchar _cpp_trigraph_map[UCHAR_MAX + 1] = { 0 }; \
137 static void init_trigraph_map PARAMS ((void)) { \
138 unsigned char *x = _cpp_trigraph_map;
141 #define s(p, v) x[p] = v;
146 s('=', '#') s(')', ']') s('!', '|')
147 s('(', '[') s('\'', '^') s('>', '}')
148 s('/', '\\') s('<', '{') s('-', '~')
155 /* Given a colon-separated list of file names PATH,
156 add all the names to the search path for include files. */
158 path_include (pfile, list, path)
169 /* Find the end of this name. */
171 while (*q != 0 && *q != PATH_SEPARATOR) q++;
174 /* An empty name in the path stands for the current directory. */
175 name = (char *) xmalloc (2);
181 /* Otherwise use the directory that is named. */
182 name = (char *) xmalloc (q - p + 1);
183 memcpy (name, p, q - p);
187 append_include_chain (pfile, name, path, path == SYSTEM);
189 /* Advance past this name. */
197 /* Append DIR to include path PATH. DIR must be allocated on the
198 heap; this routine takes responsibility for freeing it. CXX_AWARE
199 is nonzero if the header contains extern "C" guards for C++,
200 otherwise it is zero. */
202 append_include_chain (pfile, dir, path, cxx_aware)
208 struct cpp_pending *pend = CPP_OPTION (pfile, pending);
209 struct search_path *new;
218 _cpp_simplify_pathname (dir);
222 /* Dirs that don't exist are silently ignored. */
224 cpp_errno (pfile, DL_ERROR, dir);
225 else if (CPP_OPTION (pfile, verbose))
226 fprintf (stderr, _("ignoring nonexistent directory \"%s\"\n"), dir);
231 if (!S_ISDIR (st.st_mode))
233 cpp_error_with_line (pfile, DL_ERROR, 0, 0, "%s: Not a directory", dir);
239 if (len > pfile->max_include_len)
240 pfile->max_include_len = len;
242 new = (struct search_path *) xmalloc (sizeof (struct search_path));
245 INO_T_COPY (new->ino, st.st_ino);
246 new->dev = st.st_dev;
247 /* Both systm and after include file lists should be treated as system
248 include files since these two lists are really just a concatenation
249 of one "system" list. */
250 if (path == SYSTEM || path == AFTER)
251 new->sysp = cxx_aware ? 1 : 2;
254 new->name_map = NULL;
259 case BRACKET: APPEND (pend, brack, new); break;
260 case SYSTEM: APPEND (pend, systm, new); break;
261 case AFTER: APPEND (pend, after, new); break;
265 /* Handle a duplicated include path. PREV is the link in the chain
266 before the duplicate, or NULL if the duplicate is at the head of
267 the chain. The duplicate is removed from the chain and freed.
269 static struct search_path *
270 remove_dup_dir (pfile, prev, head_ptr)
272 struct search_path *prev;
273 struct search_path **head_ptr;
275 struct search_path *cur;
280 prev->next = cur->next;
285 *head_ptr = cur->next;
288 if (CPP_OPTION (pfile, verbose))
289 fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), cur->name);
291 free ((PTR) cur->name);
297 /* Remove duplicate non-system directories for which there is an equivalent
298 system directory latter in the chain. The range for removal is between
299 *HEAD_PTR and END. Returns the directory before END, or NULL if none.
300 This algorithm is quadratic in the number system directories, which is
301 acceptable since there aren't usually that many of them. */
302 static struct search_path *
303 remove_dup_nonsys_dirs (pfile, head_ptr, end)
305 struct search_path **head_ptr;
306 struct search_path *end;
309 struct search_path *prev = NULL, *cur, *other;
311 for (cur = *head_ptr; cur; cur = cur->next)
316 for (other = *head_ptr, prev = NULL;
318 other = other ? other->next : *head_ptr)
321 && INO_T_EQ (cur->ino, other->ino)
322 && cur->dev == other->dev)
324 other = remove_dup_dir (pfile, prev, head_ptr);
325 if (CPP_OPTION (pfile, verbose))
327 _(" as it is a non-system directory that duplicates a system directory\n"));
335 for (cur = *head_ptr; cur != end; cur = cur->next)
341 /* Remove duplicate directories from a chain. Returns the tail of the
342 chain, or NULL if the chain is empty. This algorithm is quadratic
343 in the number of -I switches, which is acceptable since there
344 aren't usually that many of them. */
345 static struct search_path *
346 remove_dup_dirs (pfile, head_ptr)
348 struct search_path **head_ptr;
350 struct search_path *prev = NULL, *cur, *other;
352 for (cur = *head_ptr; cur; cur = cur->next)
354 for (other = *head_ptr; other != cur; other = other->next)
355 if (INO_T_EQ (cur->ino, other->ino) && cur->dev == other->dev)
357 cur = remove_dup_dir (pfile, prev, head_ptr);
366 /* Merge the four include chains together in the order quote, bracket,
367 system, after. Remove duplicate dirs (as determined by
368 INO_T_EQ()). The system_include and after_include chains are never
369 referred to again after this function; all access is through the
370 bracket_include path. */
372 merge_include_chains (pfile)
375 struct search_path *quote, *brack, *systm, *qtail;
377 struct cpp_pending *pend = CPP_OPTION (pfile, pending);
379 quote = pend->quote_head;
380 brack = pend->brack_head;
381 systm = pend->systm_head;
382 qtail = pend->quote_tail;
384 /* Paste together bracket, system, and after include chains. */
386 pend->systm_tail->next = pend->after_head;
388 systm = pend->after_head;
391 pend->brack_tail->next = systm;
395 /* This is a bit tricky. First we drop non-system dupes of system
396 directories from the merged bracket-include list. Next we drop
397 dupes from the bracket and quote include lists. Then we drop
398 non-system dupes from the merged quote-include list. Finally,
399 if qtail and brack are the same directory, we cut out brack and
400 move brack up to point to qtail.
402 We can't just merge the lists and then uniquify them because
403 then we may lose directories from the <> search path that should
404 be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however
405 safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written
406 -Ibar -I- -Ifoo -Iquux. */
408 remove_dup_nonsys_dirs (pfile, &brack, systm);
409 remove_dup_dirs (pfile, &brack);
413 qtail = remove_dup_dirs (pfile, "e);
416 qtail = remove_dup_nonsys_dirs (pfile, "e, brack);
418 /* If brack == qtail, remove brack as it's simpler. */
419 if (qtail && brack && INO_T_EQ (qtail->ino, brack->ino)
420 && qtail->dev == brack->dev)
421 brack = remove_dup_dir (pfile, qtail, "e);
426 CPP_OPTION (pfile, quote_include) = quote;
427 CPP_OPTION (pfile, bracket_include) = brack;
430 /* A set of booleans indicating what CPP features each source language
436 char extended_numbers;
438 char dollars_in_ident;
439 char cplusplus_comments;
443 /* ??? Enable $ in identifiers in assembly? */
444 static const struct lang_flags lang_defaults[] =
445 { /* c99 c++ xnum std dollar c++comm digr */
446 /* GNUC89 */ { 0, 0, 1, 0, 1, 1, 1 },
447 /* GNUC99 */ { 1, 0, 1, 0, 1, 1, 1 },
448 /* STDC89 */ { 0, 0, 0, 1, 0, 0, 0 },
449 /* STDC94 */ { 0, 0, 0, 1, 0, 0, 1 },
450 /* STDC99 */ { 1, 0, 1, 1, 0, 1, 1 },
451 /* GNUCXX */ { 0, 1, 1, 0, 1, 1, 1 },
452 /* CXX98 */ { 0, 1, 1, 1, 0, 1, 1 },
453 /* ASM */ { 0, 0, 1, 0, 0, 1, 0 }
456 /* Sets internal flags correctly for a given language. */
458 cpp_set_lang (pfile, lang)
462 const struct lang_flags *l = &lang_defaults[(int) lang];
464 CPP_OPTION (pfile, lang) = lang;
466 CPP_OPTION (pfile, c99) = l->c99;
467 CPP_OPTION (pfile, cplusplus) = l->cplusplus;
468 CPP_OPTION (pfile, extended_numbers) = l->extended_numbers;
469 CPP_OPTION (pfile, std) = l->std;
470 CPP_OPTION (pfile, trigraphs) = l->std;
471 CPP_OPTION (pfile, dollars_in_ident) = l->dollars_in_ident;
472 CPP_OPTION (pfile, cplusplus_comments) = l->cplusplus_comments;
473 CPP_OPTION (pfile, digraphs) = l->digraphs;
477 static int opt_comp PARAMS ((const void *, const void *));
479 /* Run-time sorting of options array. */
484 return strcmp (((struct cl_option *) p1)->opt_text,
485 ((struct cl_option *) p2)->opt_text);
489 /* init initializes library global state. It might not need to
490 do anything depending on the platform and compiler. */
494 static int initialized = 0;
501 /* For non-ASCII hosts, the cl_options array needs to be sorted at
503 qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
506 /* Set up the trigraph map. This doesn't need to do anything if
507 we were compiled with a compiler that supports C99 designated
509 init_trigraph_map ();
513 /* Initialize a cpp_reader structure. */
515 cpp_create_reader (lang)
520 /* Initialize this instance of the library if it hasn't been already. */
523 pfile = (cpp_reader *) xcalloc (1, sizeof (cpp_reader));
525 cpp_set_lang (pfile, lang);
526 CPP_OPTION (pfile, warn_import) = 1;
527 CPP_OPTION (pfile, warn_multichar) = 1;
528 CPP_OPTION (pfile, discard_comments) = 1;
529 CPP_OPTION (pfile, discard_comments_in_macro_exp) = 1;
530 CPP_OPTION (pfile, show_column) = 1;
531 CPP_OPTION (pfile, tabstop) = 8;
532 CPP_OPTION (pfile, operator_names) = 1;
533 CPP_OPTION (pfile, warn_endif_labels) = 1;
534 CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99);
535 CPP_OPTION (pfile, sysroot) = cpp_SYSROOT;
536 /* SDCC _asm specific */
537 CPP_OPTION (pfile, preproc_asm) = 1;
539 CPP_OPTION (pfile, pending) =
540 (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
542 /* Default CPP arithmetic to something sensible for the host for the
543 benefit of dumb users like fix-header. */
544 CPP_OPTION (pfile, precision) = CHAR_BIT * sizeof (long);
545 CPP_OPTION (pfile, char_precision) = CHAR_BIT;
546 CPP_OPTION (pfile, wchar_precision) = CHAR_BIT * sizeof (int);
547 CPP_OPTION (pfile, int_precision) = CHAR_BIT * sizeof (int);
548 CPP_OPTION (pfile, unsigned_char) = 0;
549 CPP_OPTION (pfile, unsigned_wchar) = 1;
551 /* Initialize the line map. Start at logical line 1, so we can use
552 a line number of zero for special states. */
553 init_line_maps (&pfile->line_maps);
556 /* Initialize lexer state. */
557 pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
559 /* Set up static tokens. */
560 pfile->avoid_paste.type = CPP_PADDING;
561 pfile->avoid_paste.val.source = NULL;
562 pfile->eof.type = CPP_EOF;
563 pfile->eof.flags = 0;
565 /* Create a token buffer for the lexer. */
566 _cpp_init_tokenrun (&pfile->base_run, 250);
567 pfile->cur_run = &pfile->base_run;
568 pfile->cur_token = pfile->base_run.base;
570 /* Initialize the base context. */
571 pfile->context = &pfile->base_context;
572 pfile->base_context.macro = 0;
573 pfile->base_context.prev = pfile->base_context.next = 0;
575 /* Aligned and unaligned storage. */
576 pfile->a_buff = _cpp_get_buff (pfile, 0);
577 pfile->u_buff = _cpp_get_buff (pfile, 0);
579 /* The expression parser stack. */
580 _cpp_expand_op_stack (pfile);
582 /* Initialize the buffer obstack. */
583 gcc_obstack_init (&pfile->buffer_ob);
585 _cpp_init_includes (pfile);
590 /* Free resources used by PFILE. Accessing PFILE after this function
591 returns leads to undefined behavior. Returns the error count. */
596 struct search_path *dir, *dirn;
597 cpp_context *context, *contextn;
598 tokenrun *run, *runn;
600 free_chain (CPP_OPTION (pfile, pending)->include_head);
601 free (CPP_OPTION (pfile, pending));
602 free (pfile->op_stack);
604 while (CPP_BUFFER (pfile) != NULL)
605 _cpp_pop_buffer (pfile);
608 free (pfile->out.base);
610 if (pfile->macro_buffer)
612 free ((PTR) pfile->macro_buffer);
613 pfile->macro_buffer = NULL;
614 pfile->macro_buffer_len = 0;
618 deps_free (pfile->deps);
619 obstack_free (&pfile->buffer_ob, 0);
621 _cpp_destroy_hashtable (pfile);
622 _cpp_cleanup_includes (pfile);
624 _cpp_free_buff (pfile->a_buff);
625 _cpp_free_buff (pfile->u_buff);
626 _cpp_free_buff (pfile->free_buffs);
628 for (run = &pfile->base_run; run; run = runn)
632 if (run != &pfile->base_run)
636 for (dir = CPP_OPTION (pfile, quote_include); dir; dir = dirn)
639 free ((PTR) dir->name);
643 for (context = pfile->base_context.next; context; context = contextn)
645 contextn = context->next;
649 free_line_maps (&pfile->line_maps);
653 /* This structure defines one built-in identifier. A node will be
654 entered in the hash table under the name NAME, with value VALUE.
656 There are two tables of these. builtin_array holds all the
657 "builtin" macros: these are handled by builtin_macro() in
658 cppmacro.c. Builtin is somewhat of a misnomer -- the property of
659 interest is that these macros require special code to compute their
660 expansions. The value is a "builtin_type" enumerator.
662 operator_array holds the C++ named operators. These are keywords
663 which act as aliases for punctuators. In C++, they cannot be
664 altered through #define, and #if recognizes them as operators. In
665 C, these are not entered into the hash table at all (but see
666 <iso646.h>). The value is a token-type enumerator. */
671 unsigned short value;
674 #define B(n, t) { DSC(n), t }
675 static const struct builtin builtin_array[] =
677 B("__TIME__", BT_TIME),
678 B("__DATE__", BT_DATE),
679 B("__FILE__", BT_FILE),
680 B("__BASE_FILE__", BT_BASE_FILE),
681 B("__LINE__", BT_SPECLINE),
682 B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL),
683 /* Keep builtins not used for -traditional-cpp at the end, and
684 update init_builtins() if any more are added. */
685 B("_Pragma", BT_PRAGMA),
686 B("__STDC__", BT_STDC),
689 static const struct builtin operator_array[] =
691 B("and", CPP_AND_AND),
692 B("and_eq", CPP_AND_EQ),
693 B("bitand", CPP_AND),
695 B("compl", CPP_COMPL),
697 B("not_eq", CPP_NOT_EQ),
699 B("or_eq", CPP_OR_EQ),
701 B("xor_eq", CPP_XOR_EQ)
705 /* Mark the C++ named operators in the hash table. */
707 mark_named_operators (pfile)
710 const struct builtin *b;
712 for (b = operator_array;
713 b < (operator_array + ARRAY_SIZE (operator_array));
716 cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
717 hp->flags |= NODE_OPERATOR;
718 hp->value.operator = b->value;
722 /* Subroutine of cpp_read_main_file; reads the builtins table above and
723 enters them, and language-specific macros, into the hash table. */
725 init_builtins (pfile)
728 const struct builtin *b;
729 size_t n = ARRAY_SIZE (builtin_array);
731 if (CPP_OPTION (pfile, traditional))
734 for(b = builtin_array; b < builtin_array + n; b++)
736 cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
738 hp->flags |= NODE_BUILTIN | NODE_WARN;
739 hp->value.builtin = b->value;
742 if (CPP_OPTION (pfile, cplusplus))
743 _cpp_define_builtin (pfile, "__cplusplus 1");
744 else if (CPP_OPTION (pfile, lang) == CLK_ASM)
745 _cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
746 else if (CPP_OPTION (pfile, lang) == CLK_STDC94)
747 _cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L");
748 else if (CPP_OPTION (pfile, c99))
749 _cpp_define_builtin (pfile, "__STDC_VERSION__ 199901L");
751 if (CPP_OPTION (pfile, objc))
752 _cpp_define_builtin (pfile, "__OBJC__ 1");
754 if (pfile->cb.register_builtins)
755 (*pfile->cb.register_builtins) (pfile);
758 /* And another subroutine. This one sets up the standard include path. */
760 init_standard_includes (pfile)
764 const struct default_include *p;
765 const char *specd_prefix = CPP_OPTION (pfile, include_prefix);
767 /* Several environment variables may add to the include search path.
768 CPATH specifies an additional list of directories to be searched
769 as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH,
770 etc. specify an additional list of directories to be searched as
771 if specified with -isystem, for the language indicated. */
773 GET_ENVIRONMENT (path, "CPATH");
774 if (path != 0 && *path != 0)
775 path_include (pfile, path, BRACKET);
777 switch ((CPP_OPTION (pfile, objc) << 1) + CPP_OPTION (pfile, cplusplus))
780 GET_ENVIRONMENT (path, "C_INCLUDE_PATH");
783 GET_ENVIRONMENT (path, "CPLUS_INCLUDE_PATH");
786 GET_ENVIRONMENT (path, "OBJC_INCLUDE_PATH");
789 GET_ENVIRONMENT (path, "OBJCPLUS_INCLUDE_PATH");
792 if (path != 0 && *path != 0)
793 path_include (pfile, path, SYSTEM);
795 /* Search "translated" versions of GNU directories.
796 These have /usr/local/lib/gcc... replaced by specd_prefix. */
797 if (specd_prefix != 0 && cpp_GCC_INCLUDE_DIR_len)
799 /* Remove the `include' from /usr/local/lib/gcc.../include.
800 GCC_INCLUDE_DIR will always end in /include. */
801 int default_len = cpp_GCC_INCLUDE_DIR_len;
802 char *default_prefix = (char *) alloca (default_len + 1);
803 int specd_len = strlen (specd_prefix);
805 memcpy (default_prefix, cpp_GCC_INCLUDE_DIR, default_len);
806 default_prefix[default_len] = '\0';
808 for (p = cpp_include_defaults; p->fname; p++)
810 /* Some standard dirs are only for C++. */
812 || (CPP_OPTION (pfile, cplusplus)
813 && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
815 /* Should we be translating sysrooted dirs too? Assume
816 that iprefix and sysroot are mutually exclusive, for
818 if (p->add_sysroot && CPP_OPTION (pfile, sysroot)
819 && *(CPP_OPTION (pfile, sysroot)))
822 /* Does this dir start with the prefix? */
823 if (!strncmp (p->fname, default_prefix, default_len))
825 /* Yes; change prefix and add to search list. */
826 int flen = strlen (p->fname);
827 int this_len = specd_len + flen - default_len;
829 char *str = (char *) xmalloc (this_len + 1);
830 memcpy (str, specd_prefix, specd_len);
831 memcpy (str + specd_len,
832 p->fname + default_len,
833 flen - default_len + 1);
835 append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
841 for (p = cpp_include_defaults; p->fname; p++)
843 /* Some standard dirs are only for C++. */
845 || (CPP_OPTION (pfile, cplusplus)
846 && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
850 /* Should this dir start with the sysroot? */
851 if (p->add_sysroot && CPP_OPTION (pfile, sysroot)
852 && *(CPP_OPTION (pfile, sysroot)))
853 str = concat (CPP_OPTION (pfile, sysroot), p->fname, NULL);
856 str = update_path (p->fname, p->component);
858 append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
863 /* Pushes a command line -imacro and -include file indicated by P onto
864 the buffer stack. Returns nonzero if successful. */
866 push_include (pfile, p)
868 struct pending_option *p;
872 /* Later: maybe update this to use the #include "" search path
873 if cpp_read_file fails. */
874 header.type = CPP_STRING;
875 header.val.str.text = (const unsigned char *) p->arg;
876 header.val.str.len = strlen (p->arg);
877 /* Make the command line directive take up a line. */
880 return _cpp_execute_include (pfile, &header, IT_CMDLINE);
883 /* Frees a pending_option chain. */
886 struct pending_option *head;
888 struct pending_option *next;
898 /* Sanity-checks are dependent on command-line options, so it is
899 called as a subroutine of cpp_read_main_file (). */
901 static void sanity_checks PARAMS ((cpp_reader *));
902 static void sanity_checks (pfile)
906 size_t max_precision = 2 * CHAR_BIT * sizeof (cpp_num_part);
908 /* Sanity checks for assumptions about CPP arithmetic and target
909 type precisions made by cpplib. */
912 cpp_error (pfile, DL_ICE, "cppchar_t must be an unsigned type");
914 if (CPP_OPTION (pfile, precision) > max_precision)
915 cpp_error (pfile, DL_ICE,
916 "preprocessor arithmetic has maximum precision of %lu bits; target requires %lu bits",
917 (unsigned long) max_precision,
918 (unsigned long) CPP_OPTION (pfile, precision));
920 if (CPP_OPTION (pfile, precision) < CPP_OPTION (pfile, int_precision))
921 cpp_error (pfile, DL_ICE,
922 "CPP arithmetic must be at least as precise as a target int");
924 if (CPP_OPTION (pfile, char_precision) < 8)
925 cpp_error (pfile, DL_ICE, "target char is less than 8 bits wide");
927 if (CPP_OPTION (pfile, wchar_precision) < CPP_OPTION (pfile, char_precision))
928 cpp_error (pfile, DL_ICE,
929 "target wchar_t is narrower than target char");
931 if (CPP_OPTION (pfile, int_precision) < CPP_OPTION (pfile, char_precision))
932 cpp_error (pfile, DL_ICE,
933 "target int is narrower than target char");
935 /* This is assumed in eval_token() and could be fixed if necessary. */
936 if (sizeof (cppchar_t) > sizeof (cpp_num_part))
937 cpp_error (pfile, DL_ICE, "CPP half-integer narrower than CPP character");
939 if (CPP_OPTION (pfile, wchar_precision) > BITS_PER_CPPCHAR_T)
940 cpp_error (pfile, DL_ICE,
941 "CPP on this host cannot handle wide character constants over %lu bits, but the target requires %lu bits",
942 (unsigned long) BITS_PER_CPPCHAR_T,
943 (unsigned long) CPP_OPTION (pfile, wchar_precision));
946 # define sanity_checks(PFILE)
949 /* Add a dependency target. Can be called any number of times before
950 cpp_read_main_file(). If no targets have been added before
951 cpp_read_main_file(), then the default target is used. */
953 cpp_add_dependency_target (pfile, target, quote)
959 pfile->deps = deps_init ();
961 deps_add_target (pfile->deps, target, quote);
964 /* This is called after options have been parsed, and partially
965 processed. Setup for processing input from the file named FNAME,
966 or stdin if it is the empty string. Return the original filename
967 on success (e.g. foo.i->foo.c), or NULL on failure. */
969 cpp_read_main_file (pfile, fname, table)
974 sanity_checks (pfile);
976 post_options (pfile);
978 /* The front ends don't set up the hash table until they have
979 finished processing the command line options, so initializing the
980 hashtable is deferred until now. */
981 _cpp_init_hashtable (pfile, table);
983 /* Set up the include search path now. */
984 if (! CPP_OPTION (pfile, no_standard_includes))
985 init_standard_includes (pfile);
987 merge_include_chains (pfile);
989 /* With -v, print the list of dirs to search. */
990 if (CPP_OPTION (pfile, verbose))
992 struct search_path *l;
993 fprintf (stderr, _("#include \"...\" search starts here:\n"));
994 for (l = CPP_OPTION (pfile, quote_include); l; l = l->next)
996 if (l == CPP_OPTION (pfile, bracket_include))
997 fprintf (stderr, _("#include <...> search starts here:\n"));
998 fprintf (stderr, " %s\n", l->name);
1000 fprintf (stderr, _("End of search list.\n"));
1003 if (CPP_OPTION (pfile, deps.style) != DEPS_NONE)
1006 pfile->deps = deps_init ();
1008 /* Set the default target (if there is none already). */
1009 deps_add_default_target (pfile, fname);
1012 /* Open the main input file. */
1013 if (!_cpp_read_file (pfile, fname))
1016 /* Set this here so the client can change the option if it wishes,
1017 and after stacking the main file so we don't trace the main
1019 pfile->line_maps.trace_includes = CPP_OPTION (pfile, print_include_names);
1021 /* For foo.i, read the original filename foo.c now, for the benefit
1022 of the front ends. */
1023 if (CPP_OPTION (pfile, preprocessed))
1024 read_original_filename (pfile);
1026 return pfile->map->to_file;
1029 /* For preprocessed files, if the first tokens are of the form # NUM.
1030 handle the directive so we know the original file name. This will
1031 generate file_change callbacks, which the front ends must handle
1032 appropriately given their state of initialization. */
1034 read_original_filename (pfile)
1037 const cpp_token *token, *token1;
1039 /* Lex ahead; if the first tokens are of the form # NUM, then
1040 process the directive, otherwise back up. */
1041 token = _cpp_lex_direct (pfile);
1042 if (token->type == CPP_HASH)
1044 token1 = _cpp_lex_direct (pfile);
1045 _cpp_backup_tokens (pfile, 1);
1047 /* If it's a #line directive, handle it. */
1048 if (token1->type == CPP_NUMBER)
1050 _cpp_handle_directive (pfile, token->flags & PREV_WHITE);
1055 /* Backup as if nothing happened. */
1056 _cpp_backup_tokens (pfile, 1);
1059 /* Handle pending command line options: -D, -U, -A, -imacros and
1060 -include. This should be called after debugging has been properly
1061 set up in the front ends. */
1063 cpp_finish_options (pfile)
1066 /* Mark named operators before handling command line macros. */
1067 if (CPP_OPTION (pfile, cplusplus) && CPP_OPTION (pfile, operator_names))
1068 mark_named_operators (pfile);
1070 /* Install builtins and process command line macros etc. in the order
1071 they appeared, but only if not already preprocessed. */
1072 if (! CPP_OPTION (pfile, preprocessed))
1074 struct pending_option *p;
1076 /* Prevent -Wunused-macros with command-line redefinitions. */
1077 pfile->first_unused_line = (unsigned int) -1;
1078 _cpp_do_file_change (pfile, LC_RENAME, _("<built-in>"), 1, 0);
1079 init_builtins (pfile);
1080 _cpp_do_file_change (pfile, LC_RENAME, _("<command line>"), 1, 0);
1081 for (p = CPP_OPTION (pfile, pending)->directive_head; p; p = p->next)
1082 (*p->handler) (pfile, p->arg);
1084 /* Scan -imacros files after -D, -U, but before -include.
1085 pfile->next_include_file is NULL, so _cpp_pop_buffer does not
1086 push -include files. */
1087 for (p = CPP_OPTION (pfile, pending)->imacros_head; p; p = p->next)
1088 if (push_include (pfile, p))
1089 cpp_scan_nooutput (pfile);
1091 pfile->next_include_file = &CPP_OPTION (pfile, pending)->include_head;
1092 _cpp_maybe_push_include_file (pfile);
1095 pfile->first_unused_line = pfile->line;
1097 free_chain (CPP_OPTION (pfile, pending)->imacros_head);
1098 free_chain (CPP_OPTION (pfile, pending)->directive_head);
1101 /* Push the next buffer on the stack given by -include, if any. */
1103 _cpp_maybe_push_include_file (pfile)
1106 if (pfile->next_include_file)
1108 struct pending_option *head = *pfile->next_include_file;
1110 while (head && !push_include (pfile, head))
1114 pfile->next_include_file = &head->next;
1117 /* All done; restore the line map from <command line>. */
1118 _cpp_do_file_change (pfile, LC_RENAME,
1119 pfile->line_maps.maps[0].to_file, 1, 0);
1120 /* Don't come back here again. */
1121 pfile->next_include_file = NULL;
1126 /* This is called at the end of preprocessing. It pops the last
1127 buffer and writes dependency output, and returns the number of
1130 Maybe it should also reset state, such that you could call
1131 cpp_start_read with a new filename to restart processing. */
1133 cpp_finish (pfile, deps_stream)
1137 /* Warn about unused macros before popping the final buffer. */
1138 if (CPP_OPTION (pfile, warn_unused_macros))
1139 cpp_forall_identifiers (pfile, _cpp_warn_if_unused_macro, NULL);
1141 /* cpplex.c leaves the final buffer on the stack. This it so that
1142 it returns an unending stream of CPP_EOFs to the client. If we
1143 popped the buffer, we'd dereference a NULL buffer pointer and
1144 segfault. It's nice to allow the client to do worry-free excess
1145 cpp_get_token calls. */
1146 while (pfile->buffer)
1147 _cpp_pop_buffer (pfile);
1149 /* Don't write the deps file if there are errors. */
1150 if (CPP_OPTION (pfile, deps.style) != DEPS_NONE
1151 && deps_stream && pfile->errors == 0)
1153 deps_write (pfile->deps, deps_stream, 72);
1155 if (CPP_OPTION (pfile, deps.phony_targets))
1156 deps_phony_targets (pfile->deps, deps_stream);
1159 /* Report on headers that could use multiple include guards. */
1160 if (CPP_OPTION (pfile, print_include_names))
1161 _cpp_report_missing_guards (pfile);
1163 return pfile->errors;
1166 /* Add a directive to be handled later in the initialization phase. */
1168 new_pending_directive (pend, text, handler)
1169 struct cpp_pending *pend;
1171 cl_directive_handler handler;
1173 struct pending_option *o = (struct pending_option *)
1174 xmalloc (sizeof (struct pending_option));
1178 o->handler = handler;
1179 APPEND (pend, directive, o);
1182 /* Irix6 "cc -n32" and OSF4 cc have problems with char foo[] = ("string");
1183 I.e. a const string initializer with parens around it. That is
1184 what N_("string") resolves to, so we make no_* be macros instead. */
1185 #define no_arg N_("argument missing after %s")
1186 #define no_ass N_("assertion missing after %s")
1187 #define no_dir N_("directory name missing after %s")
1188 #define no_fil N_("file name missing after %s")
1189 #define no_mac N_("macro name missing after %s")
1190 #define no_pth N_("path name missing after %s")
1191 #define no_num N_("number missing after %s")
1192 #define no_tgt N_("target missing after %s")
1194 /* This is the list of all command line options, with the leading
1195 "-" removed. It must be sorted in ASCII collating order. */
1196 #define COMMAND_LINE_OPTIONS \
1197 DEF_OPT("$", 0, OPT_dollar) \
1198 DEF_OPT("+", 0, OPT_plus) \
1199 DEF_OPT("-help", 0, OPT__help) \
1200 DEF_OPT("-target-help", 0, OPT_target__help) \
1201 DEF_OPT("-version", 0, OPT__version) \
1202 DEF_OPT("A", no_ass, OPT_A) \
1203 DEF_OPT("C", 0, OPT_C) \
1204 DEF_OPT("D", no_mac, OPT_D) \
1205 DEF_OPT("H", 0, OPT_H) \
1206 DEF_OPT("I", no_dir, OPT_I) \
1207 DEF_OPT("M", 0, OPT_M) \
1208 DEF_OPT("MD", no_fil, OPT_MD) \
1209 DEF_OPT("MF", no_fil, OPT_MF) \
1210 DEF_OPT("MG", 0, OPT_MG) \
1211 DEF_OPT("MM", 0, OPT_MM) \
1212 DEF_OPT("MMD", no_fil, OPT_MMD) \
1213 DEF_OPT("MP", 0, OPT_MP) \
1214 DEF_OPT("MQ", no_tgt, OPT_MQ) \
1215 DEF_OPT("MT", no_tgt, OPT_MT) \
1216 DEF_OPT("P", 0, OPT_P) \
1217 DEF_OPT("U", no_mac, OPT_U) \
1218 DEF_OPT("W", no_arg, OPT_W) /* arg optional */ \
1219 DEF_OPT("d", no_arg, OPT_d) \
1220 DEF_OPT("fno-operator-names", 0, OPT_fno_operator_names) \
1221 DEF_OPT("fno-preprocessed", 0, OPT_fno_preprocessed) \
1222 DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \
1223 DEF_OPT("fpreprocessed", 0, OPT_fpreprocessed) \
1224 DEF_OPT("fshow-column", 0, OPT_fshow_column) \
1225 DEF_OPT("fsigned-char", 0, OPT_fsigned_char) \
1226 DEF_OPT("ftabstop=", no_num, OPT_ftabstop) \
1227 DEF_OPT("funsigned-char", 0, OPT_funsigned_char) \
1228 DEF_OPT("h", 0, OPT_h) \
1229 DEF_OPT("idirafter", no_dir, OPT_idirafter) \
1230 DEF_OPT("imacros", no_fil, OPT_imacros) \
1231 DEF_OPT("include", no_fil, OPT_include) \
1232 DEF_OPT("iprefix", no_pth, OPT_iprefix) \
1233 DEF_OPT("isysroot", no_dir, OPT_isysroot) \
1234 DEF_OPT("isystem", no_dir, OPT_isystem) \
1235 DEF_OPT("iwithprefix", no_dir, OPT_iwithprefix) \
1236 DEF_OPT("iwithprefixbefore", no_dir, OPT_iwithprefixbefore) \
1237 DEF_OPT("lang-asm", 0, OPT_lang_asm) \
1238 DEF_OPT("lang-c", 0, OPT_lang_c) \
1239 DEF_OPT("lang-c++", 0, OPT_lang_cplusplus) \
1240 DEF_OPT("lang-c89", 0, OPT_lang_c89) \
1241 DEF_OPT("nostdinc", 0, OPT_nostdinc) \
1242 DEF_OPT("nostdinc++", 0, OPT_nostdincplusplus) \
1243 DEF_OPT("o", no_fil, OPT_o) \
1244 /* SDCC specific */ \
1245 DEF_OPT("obj-ext=", no_arg, OPT_obj_ext) \
1246 DEF_OPT("pedantic", 0, OPT_pedantic) \
1247 DEF_OPT("pedantic-errors", 0, OPT_pedantic_errors) \
1248 /* SDCC specific */ \
1249 DEF_OPT("pedantic-parse-number", 0, OPT_pedantic_parse_number) \
1250 DEF_OPT("remap", 0, OPT_remap) \
1251 DEF_OPT("std=c++98", 0, OPT_std_cplusplus98) \
1252 DEF_OPT("std=c89", 0, OPT_std_c89) \
1253 DEF_OPT("std=c99", 0, OPT_std_c99) \
1254 DEF_OPT("std=c9x", 0, OPT_std_c9x) \
1255 DEF_OPT("std=gnu89", 0, OPT_std_gnu89) \
1256 DEF_OPT("std=gnu99", 0, OPT_std_gnu99) \
1257 DEF_OPT("std=gnu9x", 0, OPT_std_gnu9x) \
1258 DEF_OPT("std=iso9899:1990", 0, OPT_std_iso9899_1990) \
1259 DEF_OPT("std=iso9899:199409", 0, OPT_std_iso9899_199409) \
1260 DEF_OPT("std=iso9899:1999", 0, OPT_std_iso9899_1999) \
1261 DEF_OPT("std=iso9899:199x", 0, OPT_std_iso9899_199x) \
1262 DEF_OPT("trigraphs", 0, OPT_trigraphs) \
1263 DEF_OPT("v", 0, OPT_v) \
1264 DEF_OPT("version", 0, OPT_version) \
1265 DEF_OPT("w", 0, OPT_w)
1267 #define DEF_OPT(text, msg, code) code,
1270 COMMAND_LINE_OPTIONS
1277 const char *opt_text;
1280 enum opt_code opt_code;
1283 #define DEF_OPT(text, msg, code) { text, msg, sizeof(text) - 1, code },
1285 static struct cl_option cl_options[] =
1287 static const struct cl_option cl_options[] =
1290 COMMAND_LINE_OPTIONS
1293 #undef COMMAND_LINE_OPTIONS
1295 /* Perform a binary search to find which, if any, option the given
1296 command-line matches. Returns its index in the option array,
1297 negative on failure. Complications arise since some options can be
1298 suffixed with an argument, and multiple complete matches can occur,
1299 e.g. -pedantic and -pedantic-errors. */
1301 parse_option (input)
1304 unsigned int md, mn, mx;
1315 opt_len = cl_options[md].opt_len;
1316 comp = strncmp (input, cl_options[md].opt_text, opt_len);
1324 if (input[opt_len] == '\0')
1326 /* We were passed more text. If the option takes an argument,
1327 we may match a later option or we may have been passed the
1328 argument. The longest possible option match succeeds.
1329 If the option takes no arguments we have not matched and
1330 continue the search (e.g. input="stdc++" match was "stdc"). */
1332 if (cl_options[md].msg)
1334 /* Scan forwards. If we get an exact match, return it.
1335 Otherwise, return the longest option-accepting match.
1336 This loops no more than twice with current options. */
1338 for (; mn < (unsigned int) N_OPTS; mn++)
1340 opt_len = cl_options[mn].opt_len;
1341 if (strncmp (input, cl_options[mn].opt_text, opt_len))
1343 if (input[opt_len] == '\0')
1345 if (cl_options[mn].msg)
1356 /* Handle one command-line option in (argc, argv).
1357 Can be called multiple times, to handle multiple sets of options.
1358 Returns number of strings consumed. */
1360 cpp_handle_option (pfile, argc, argv)
1366 struct cpp_pending *pend = CPP_OPTION (pfile, pending);
1368 /* Interpret "-" or a non-option as a file name. */
1369 if (argv[i][0] != '-' || argv[i][1] == '\0')
1371 if (CPP_OPTION (pfile, in_fname) == NULL)
1372 CPP_OPTION (pfile, in_fname) = argv[i];
1373 else if (CPP_OPTION (pfile, out_fname) == NULL)
1374 CPP_OPTION (pfile, out_fname) = argv[i];
1376 cpp_error (pfile, DL_ERROR, "too many filenames. Type %s --help for usage info",
1381 enum opt_code opt_code;
1383 const char *arg = 0;
1385 /* Skip over '-'. */
1386 opt_index = parse_option (&argv[i][1]);
1390 opt_code = cl_options[opt_index].opt_code;
1391 if (cl_options[opt_index].msg)
1393 arg = &argv[i][cl_options[opt_index].opt_len + 1];
1394 /* Yuk. Special case for -W as it must not swallow
1395 up any following argument. If this becomes common, add
1396 another field to the cl_options table. */
1397 if (arg[0] == '\0' && opt_code != OPT_W)
1402 cpp_error (pfile, DL_ERROR,
1403 cl_options[opt_index].msg, argv[i - 1]);
1411 case N_OPTS: /* Shut GCC up. */
1413 case OPT_fno_operator_names:
1414 CPP_OPTION (pfile, operator_names) = 0;
1416 case OPT_fpreprocessed:
1417 CPP_OPTION (pfile, preprocessed) = 1;
1419 case OPT_fno_preprocessed:
1420 CPP_OPTION (pfile, preprocessed) = 0;
1422 case OPT_fshow_column:
1423 CPP_OPTION (pfile, show_column) = 1;
1425 case OPT_fno_show_column:
1426 CPP_OPTION (pfile, show_column) = 0;
1429 /* Silently ignore empty string, non-longs and silly values. */
1433 long tabstop = strtol (arg, &endptr, 10);
1434 if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
1435 CPP_OPTION (pfile, tabstop) = tabstop;
1438 case OPT_fsigned_char:
1439 CPP_OPTION (pfile, unsigned_char) = 0;
1441 case OPT_funsigned_char:
1442 CPP_OPTION (pfile, unsigned_char) = 1;
1445 CPP_OPTION (pfile, inhibit_warnings) = 1;
1450 CPP_OPTION (pfile, help_only) = 1;
1452 case OPT_target__help:
1453 /* Print if any target specific options. cpplib has none, but
1454 make sure help_only gets set. */
1455 CPP_OPTION (pfile, help_only) = 1;
1458 /* --version inhibits compilation, -version doesn't. -v means
1459 verbose and -version. Historical reasons, don't ask. */
1461 CPP_OPTION (pfile, help_only) = 1;
1462 pfile->print_version = 1;
1465 CPP_OPTION (pfile, verbose) = 1;
1466 pfile->print_version = 1;
1469 pfile->print_version = 1;
1473 CPP_OPTION (pfile, discard_comments) = 0;
1476 CPP_OPTION (pfile, no_line_commands) = 1;
1478 case OPT_dollar: /* Don't include $ in identifiers. */
1479 CPP_OPTION (pfile, dollars_in_ident) = 0;
1482 CPP_OPTION (pfile, print_include_names) = 1;
1485 new_pending_directive (pend, arg, cpp_define);
1487 case OPT_pedantic_errors:
1488 CPP_OPTION (pfile, pedantic_errors) = 1;
1491 CPP_OPTION (pfile, pedantic) = 1;
1493 case OPT_pedantic_parse_number:
1494 CPP_OPTION (pfile, pedantic_parse_number) = 1;
1497 CPP_OPTION (pfile, trigraphs) = 1;
1500 CPP_OPTION (pfile, cplusplus) = 1;
1501 CPP_OPTION (pfile, cplusplus_comments) = 1;
1504 CPP_OPTION (pfile, remap) = 1;
1507 CPP_OPTION (pfile, include_prefix) = arg;
1508 CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
1511 CPP_OPTION (pfile, sysroot) = arg;
1514 cpp_set_lang (pfile, CLK_GNUC89);
1516 case OPT_lang_cplusplus:
1517 cpp_set_lang (pfile, CLK_GNUCXX);
1520 cpp_set_lang (pfile, CLK_ASM);
1522 case OPT_std_cplusplus98:
1523 cpp_set_lang (pfile, CLK_CXX98);
1526 cpp_set_lang (pfile, CLK_GNUC89);
1530 cpp_set_lang (pfile, CLK_GNUC99);
1532 case OPT_std_iso9899_199409:
1533 cpp_set_lang (pfile, CLK_STDC94);
1535 case OPT_std_iso9899_1990:
1538 cpp_set_lang (pfile, CLK_STDC89);
1540 case OPT_std_iso9899_199x:
1541 case OPT_std_iso9899_1999:
1544 cpp_set_lang (pfile, CLK_STDC99);
1547 /* -nostdinc causes no default include directories.
1548 You must specify all include-file directories with -I. */
1549 CPP_OPTION (pfile, no_standard_includes) = 1;
1551 case OPT_nostdincplusplus:
1552 /* -nostdinc++ causes no default C++-specific include directories. */
1553 CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1;
1556 if (CPP_OPTION (pfile, out_fname) == NULL)
1557 CPP_OPTION (pfile, out_fname) = arg;
1560 cpp_error (pfile, DL_ERROR, "output filename specified twice");
1565 /* Args to -d specify what parts of macros to dump.
1566 Silently ignore unrecognised options; they may
1567 be aimed at the compiler proper. */
1571 while ((c = *arg++) != '\0')
1575 CPP_OPTION (pfile, dump_macros) = dump_only;
1578 CPP_OPTION (pfile, dump_macros) = dump_names;
1581 CPP_OPTION (pfile, dump_macros) = dump_definitions;
1584 CPP_OPTION (pfile, dump_includes) = 1;
1591 CPP_OPTION (pfile, deps.missing_files) = 1;
1594 /* When doing dependencies with -M or -MM, suppress normal
1595 preprocessed output, but still do -dM etc. as software
1596 depends on this. Preprocessed output occurs if -MD, -MMD
1597 or environment var dependency generation is used. */
1598 CPP_OPTION (pfile, deps.style) = 2;
1599 CPP_OPTION (pfile, no_output) = 1;
1602 CPP_OPTION (pfile, deps.style) = 1;
1603 CPP_OPTION (pfile, no_output) = 1;
1606 CPP_OPTION (pfile, deps.file) = arg;
1609 CPP_OPTION (pfile, deps.phony_targets) = 1;
1613 /* Add a target. -MQ quotes for Make. */
1614 deps_add_target (pfile->deps, arg, opt_code == OPT_MQ);
1618 CPP_OPTION (pfile, deps.style) = 2;
1619 CPP_OPTION (pfile, deps.file) = arg;
1622 CPP_OPTION (pfile, deps.style) = 1;
1623 CPP_OPTION (pfile, deps.file) = arg;
1629 /* -A with an argument beginning with '-' acts as
1630 #unassert on whatever immediately follows the '-'.
1631 If "-" is the whole argument, we eliminate all
1632 predefined macros and assertions, including those
1633 that were specified earlier on the command line.
1634 That way we can get rid of any that were passed
1635 automatically in from GCC. */
1639 free_chain (pend->directive_head);
1640 pend->directive_head = NULL;
1641 pend->directive_tail = NULL;
1644 new_pending_directive (pend, arg + 1, cpp_unassert);
1647 new_pending_directive (pend, arg, cpp_assert);
1650 new_pending_directive (pend, arg, cpp_undef);
1652 case OPT_I: /* Add directory to path for includes. */
1653 if (!strcmp (arg, "-"))
1656 Use the preceding -I directories for #include "..."
1657 but not #include <...>.
1658 Don't search the directory of the present file
1659 for #include "...". (Note that -I. -I- is not the same as
1660 the default setup; -I. uses the compiler's working dir.) */
1661 if (! CPP_OPTION (pfile, ignore_srcdir))
1663 pend->quote_head = pend->brack_head;
1664 pend->quote_tail = pend->brack_tail;
1665 pend->brack_head = 0;
1666 pend->brack_tail = 0;
1667 CPP_OPTION (pfile, ignore_srcdir) = 1;
1671 cpp_error (pfile, DL_ERROR, "-I- specified twice");
1676 append_include_chain (pfile, (char *)xstrdup (arg), BRACKET, 0);
1679 /* Add directory to beginning of system include path, as a system
1680 include directory. */
1681 append_include_chain (pfile, (char *)xstrdup (arg), SYSTEM, 0);
1686 struct pending_option *o = (struct pending_option *)
1687 xmalloc (sizeof (struct pending_option));
1691 if (opt_code == OPT_include)
1692 APPEND (pend, include, o);
1694 APPEND (pend, imacros, o);
1697 case OPT_iwithprefix:
1698 /* Add directory to end of path for includes,
1699 with the default prefix at the front of its name. */
1701 case OPT_iwithprefixbefore:
1702 /* Add directory to main path for includes,
1703 with the default prefix at the front of its name. */
1710 if (CPP_OPTION (pfile, include_prefix) != 0)
1712 size_t ipl = CPP_OPTION (pfile, include_prefix_len);
1713 fname = xmalloc (ipl + len + 1);
1714 memcpy (fname, CPP_OPTION (pfile, include_prefix), ipl);
1715 memcpy (fname + ipl, arg, len + 1);
1717 else if (cpp_GCC_INCLUDE_DIR_len)
1719 fname = xmalloc (cpp_GCC_INCLUDE_DIR_len + len + 1);
1720 memcpy (fname, cpp_GCC_INCLUDE_DIR, cpp_GCC_INCLUDE_DIR_len);
1721 memcpy (fname + cpp_GCC_INCLUDE_DIR_len, arg, len + 1);
1724 fname = xstrdup (arg);
1726 append_include_chain (pfile, fname,
1727 opt_code == OPT_iwithprefix ? SYSTEM: BRACKET, 0);
1731 /* Add directory to end of path for includes. */
1732 append_include_chain (pfile, (char *)xstrdup (arg), AFTER, 0);
1735 /* Silently ignore unrecognised options. */
1736 if (!strcmp (argv[i], "-Wall"))
1738 CPP_OPTION (pfile, warn_trigraphs) = 1;
1739 CPP_OPTION (pfile, warn_comments) = 1;
1741 else if (!strcmp (argv[i], "-Wtraditional"))
1742 CPP_OPTION (pfile, warn_traditional) = 1;
1743 else if (!strcmp (argv[i], "-Wtrigraphs"))
1744 CPP_OPTION (pfile, warn_trigraphs) = 1;
1745 else if (!strcmp (argv[i], "-Wcomment"))
1746 CPP_OPTION (pfile, warn_comments) = 1;
1747 else if (!strcmp (argv[i], "-Wcomments"))
1748 CPP_OPTION (pfile, warn_comments) = 1;
1749 else if (!strcmp (argv[i], "-Wundef"))
1750 CPP_OPTION (pfile, warn_undef) = 1;
1751 else if (!strcmp (argv[i], "-Wimport"))
1752 CPP_OPTION (pfile, warn_import) = 1;
1753 else if (!strcmp (argv[i], "-Werror"))
1754 CPP_OPTION (pfile, warnings_are_errors) = 1;
1755 else if (!strcmp (argv[i], "-Wsystem-headers"))
1756 CPP_OPTION (pfile, warn_system_headers) = 1;
1757 else if (!strcmp (argv[i], "-Wno-traditional"))
1758 CPP_OPTION (pfile, warn_traditional) = 0;
1759 else if (!strcmp (argv[i], "-Wno-trigraphs"))
1760 CPP_OPTION (pfile, warn_trigraphs) = 0;
1761 else if (!strcmp (argv[i], "-Wno-comment"))
1762 CPP_OPTION (pfile, warn_comments) = 0;
1763 else if (!strcmp (argv[i], "-Wno-comments"))
1764 CPP_OPTION (pfile, warn_comments) = 0;
1765 else if (!strcmp (argv[i], "-Wno-undef"))
1766 CPP_OPTION (pfile, warn_undef) = 0;
1767 else if (!strcmp (argv[i], "-Wno-import"))
1768 CPP_OPTION (pfile, warn_import) = 0;
1769 else if (!strcmp (argv[i], "-Wno-error"))
1770 CPP_OPTION (pfile, warnings_are_errors) = 0;
1771 else if (!strcmp (argv[i], "-Wno-system-headers"))
1772 CPP_OPTION (pfile, warn_system_headers) = 0;
1776 CPP_OPTION (pfile, obj_ext) = arg;
1783 /* Handle command-line options in (argc, argv).
1784 Can be called multiple times, to handle multiple sets of options.
1785 Returns if an unrecognized option is seen.
1786 Returns number of strings consumed. */
1788 cpp_handle_options (pfile, argc, argv)
1794 int strings_processed;
1796 for (i = 0; i < argc; i += strings_processed)
1798 strings_processed = cpp_handle_option (pfile, argc - i, argv + i);
1799 if (strings_processed == 0)
1807 post_options (pfile)
1810 /* -Wtraditional is not useful in C++ mode. */
1811 if (CPP_OPTION (pfile, cplusplus))
1812 CPP_OPTION (pfile, warn_traditional) = 0;
1814 /* Permanently disable macro expansion if we are rescanning
1815 preprocessed text. Read preprocesed source in ISO mode. */
1816 if (CPP_OPTION (pfile, preprocessed))
1818 pfile->state.prevent_expansion = 1;
1819 CPP_OPTION (pfile, traditional) = 0;
1822 /* Traditional CPP does not accurately track column information. */
1823 if (CPP_OPTION (pfile, traditional))
1824 CPP_OPTION (pfile, show_column) = 0;
1827 /* Handle --help output. */
1831 /* To keep the lines from getting too long for some compilers, limit
1832 to about 500 characters (6 lines) per chunk. */
1835 -include <file> Include the contents of <file> before other files\n\
1836 -imacros <file> Accept definition of macros in <file>\n\
1837 -iprefix <path> Specify <path> as a prefix for next two options\n\
1838 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1839 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1840 -isystem <dir> Add <dir> to the start of the system include path\n\
1841 -isysroot <dir> Set <dir> to be the system root directory\n\
1844 -idirafter <dir> Add <dir> to the end of the system include path\n\
1845 -I <dir> Add <dir> to the end of the main include path\n\
1846 -I- Fine-grained include path control; see info docs\n\
1847 -nostdinc Do not search system include directories\n\
1848 (dirs specified with -isystem will still be used)\n\
1849 -nostdinc++ Do not search system include directories for C++\n\
1850 -o <file> Put output into <file>\n\
1853 -pedantic Issue all warnings demanded by strict ISO C\n\
1854 -pedantic-errors Issue -pedantic warnings as errors instead\n\
1855 -trigraphs Support ISO C trigraphs\n\
1856 -lang-c Assume that the input sources are in C\n\
1857 -lang-c89 Assume that the input sources are in C89\n\
1861 -pedantic-parse-number Pedantic parse number\n\
1864 -lang-c++ Assume that the input sources are in C++\n\
1865 -lang-asm Assume that the input sources are in assembler\n\
1868 -std=<std name> Specify the conformance standard; one of:\n\
1869 gnu89, gnu99, c89, c99, iso9899:1990,\n\
1870 iso9899:199409, iso9899:1999\n\
1871 -+ Allow parsing of C++ style features\n\
1872 -w Inhibit warning messages\n\
1873 -Wtrigraphs Warn if trigraphs are encountered\n\
1874 -Wno-trigraphs Do not warn about trigraphs\n\
1875 -Wcomment{s} Warn if one comment starts inside another\n\
1878 -Wno-comment{s} Do not warn about comments\n\
1879 -Wtraditional Warn about features not present in traditional C\n\
1880 -Wno-traditional Do not warn about traditional C\n\
1881 -Wundef Warn if an undefined macro is used by #if\n\
1882 -Wno-undef Do not warn about testing undefined macros\n\
1883 -Wimport Warn about the use of the #import directive\n\
1886 -Wno-import Do not warn about the use of #import\n\
1887 -Werror Treat all warnings as errors\n\
1888 -Wno-error Do not treat warnings as errors\n\
1889 -Wsystem-headers Do not suppress warnings from system headers\n\
1890 -Wno-system-headers Suppress warnings from system headers\n\
1891 -Wall Enable all preprocessor warnings\n\
1894 -M Generate make dependencies\n\
1895 -MM As -M, but ignore system header files\n\
1896 -MD Generate make dependencies and compile\n\
1897 -MMD As -MD, but ignore system header files\n\
1898 -MF <file> Write dependency output to the given file\n\
1899 -MG Treat missing header file as generated files\n\
1902 -MP Generate phony targets for all headers\n\
1903 -MQ <target> Add a MAKE-quoted target\n\
1904 -MT <target> Add an unquoted target\n\
1908 -obj-ext=<extension> Define object file extension, used for generation\n\
1909 of make dependencies\n\
1912 -D<macro> Define a <macro> with string '1' as its value\n\
1913 -D<macro>=<val> Define a <macro> with <val> as its value\n\
1914 -A<question>=<answer> Assert the <answer> to <question>\n\
1915 -A-<question>=<answer> Disable the <answer> to <question>\n\
1916 -U<macro> Undefine <macro> \n\
1917 -v Display the version number\n\
1920 -H Print the name of header files as they are used\n\
1921 -C Do not discard comments\n\
1922 -dM Display a list of macro definitions active at end\n\
1923 -dD Preserve macro definitions in output\n\
1924 -dN As -dD except that only the names are preserved\n\
1925 -dI Include #include directives in the output\n\
1928 -fpreprocessed Treat the input file as already preprocessed\n\
1929 -ftabstop=<number> Distance between tab stops for column reporting\n\
1930 -fsigned-char Make \"char\" signed by default\n\
1931 -funsigned-char Make \"char\" unsigned by default\n\
1932 -P Do not generate #line directives\n\
1933 -$ Do not allow '$' in identifiers\n\
1934 -remap Remap file names when including files\n\
1935 --version Display version information\n\
1936 -h or --help Display this information\n\