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 -imacros
53 switch. There are four lists: one for -D and -U, one for -A, one
54 for -include, one for -imacros. `undef' is set for -U, clear for
55 -D, ignored for the others.
56 (Future: add an equivalent of -U for -A) */
58 typedef void (* cl_directive_handler) PARAMS ((cpp_reader *, const char *));
61 struct pending_option *next;
63 cl_directive_handler handler;
66 /* The `pending' structure accumulates all the options that are not
67 actually processed until we hit cpp_start_read. It consists of
68 several lists, one for each type of option. We keep both head and
69 tail pointers for quick insertion. */
72 struct pending_option *directive_head, *directive_tail;
74 struct file_name_list *quote_head, *quote_tail;
75 struct file_name_list *brack_head, *brack_tail;
76 struct file_name_list *systm_head, *systm_tail;
77 struct file_name_list *after_head, *after_tail;
79 struct pending_option *imacros_head, *imacros_tail;
80 struct pending_option *include_head, *include_tail;
84 #define APPEND(pend, list, elt) \
85 do { if (!(pend)->list##_head) (pend)->list##_head = (elt); \
86 else (pend)->list##_tail->next = (elt); \
87 (pend)->list##_tail = (elt); \
90 #define APPEND(pend, list, elt) \
91 do { if (!(pend)->list/**/_head) (pend)->list/**/_head = (elt); \
92 else (pend)->list/**/_tail->next = (elt); \
93 (pend)->list/**/_tail = (elt); \
97 static void print_help PARAMS ((void));
98 static void path_include PARAMS ((cpp_reader *,
101 static void initialize_builtins PARAMS ((cpp_reader *));
102 static void append_include_chain PARAMS ((cpp_reader *,
103 struct cpp_pending *,
105 static void merge_include_chains PARAMS ((cpp_reader *));
107 static void initialize_dependency_output PARAMS ((cpp_reader *));
108 static void initialize_standard_includes PARAMS ((cpp_reader *));
109 static void new_pending_directive PARAMS ((struct cpp_pending *,
111 cl_directive_handler));
113 static int opt_comp PARAMS ((const void *, const void *));
115 static int parse_option PARAMS ((const char *));
116 static int handle_option PARAMS ((cpp_reader *, int, char **));
118 /* Fourth argument to append_include_chain: chain to use */
119 enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
121 /* If we have designated initializers (GCC >2.7) this table can be
122 initialized, constant data. Otherwise, it has to be filled in at
125 #if (GCC_VERSION >= 2007)
126 #define init_IStable() /* nothing */
127 #define ISTABLE __extension__ const unsigned char _cpp_IStable[256] = {
129 #define s(p, v) [p] = v,
131 #define ISTABLE unsigned char _cpp_IStable[256] = { 0 }; \
132 static void init_IStable PARAMS ((void)) { \
133 unsigned char *x = _cpp_IStable;
135 #define s(p, v) x[p] = v;
138 #define A(x) s(x, ISidnum|ISidstart)
139 #define N(x) s(x, ISidnum|ISnumstart)
140 #define H(x) s(x, IShspace|ISspace)
141 #define S(x) s(x, ISspace)
146 A('a') A('b') A('c') A('d') A('e') A('f') A('g') A('h') A('i')
147 A('j') A('k') A('l') A('m') A('n') A('o') A('p') A('q') A('r')
148 A('s') A('t') A('u') A('v') A('w') A('x') A('y') A('z')
150 A('A') A('B') A('C') A('D') A('E') A('F') A('G') A('H') A('I')
151 A('J') A('K') A('L') A('M') A('N') A('O') A('P') A('Q') A('R')
152 A('S') A('T') A('U') A('V') A('W') A('X') A('Y') A('Z')
154 N('1') N('2') N('3') N('4') N('5') N('6') N('7') N('8') N('9') N('0')
156 H('\0') H(' ') H('\t') H('\v') H('\f')
169 /* Given a colon-separated list of file names PATH,
170 add all the names to the search path for include files. */
173 path_include (pfile, pend, list, path)
175 struct cpp_pending *pend;
185 /* Find the end of this name. */
187 while (*q != 0 && *q != PATH_SEPARATOR) q++;
190 /* An empty name in the path stands for the current directory. */
191 name = (char *) xmalloc (2);
197 /* Otherwise use the directory that is named. */
198 name = (char *) xmalloc (q - p + 1);
199 memcpy (name, p, q - p);
203 append_include_chain (pfile, pend, name, path, 0);
205 /* Advance past this name. */
213 /* Append DIR to include path PATH. DIR must be permanently allocated
216 append_include_chain (pfile, pend, dir, path, cxx_aware)
218 struct cpp_pending *pend;
223 struct file_name_list *new;
227 _cpp_simplify_pathname (dir);
230 /* Dirs that don't exist are silently ignored. */
232 cpp_notice_from_errno (pfile, dir);
233 else if (CPP_OPTION (pfile, verbose))
234 fprintf (stderr, _("ignoring nonexistent directory \"%s\"\n"), dir);
238 if (!S_ISDIR (st.st_mode))
240 cpp_notice (pfile, "%s: Not a directory", dir);
245 if (len > pfile->max_include_len)
246 pfile->max_include_len = len;
248 new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
251 new->ino = st.st_ino;
252 new->dev = st.st_dev;
254 new->sysp = cxx_aware ? 1 : 2;
257 new->name_map = NULL;
263 case QUOTE: APPEND (pend, quote, new); break;
264 case BRACKET: APPEND (pend, brack, new); break;
265 case SYSTEM: APPEND (pend, systm, new); break;
266 case AFTER: APPEND (pend, after, new); break;
270 /* Merge the four include chains together in the order quote, bracket,
271 system, after. Remove duplicate dirs (as determined by
272 INO_T_EQ()). The system_include and after_include chains are never
273 referred to again after this function; all access is through the
274 bracket_include path.
276 For the future: Check if the directory is empty (but
277 how?) and possibly preload the include hash. */
280 merge_include_chains (pfile)
283 struct file_name_list *prev, *cur, *other;
284 struct file_name_list *quote, *brack, *systm, *after;
285 struct file_name_list *qtail, *btail, *stail, *atail;
287 struct cpp_pending *pend = CPP_OPTION (pfile, pending);
289 qtail = pend->quote_tail;
290 btail = pend->brack_tail;
291 stail = pend->systm_tail;
292 atail = pend->after_tail;
294 quote = pend->quote_head;
295 brack = pend->brack_head;
296 systm = pend->systm_head;
297 after = pend->after_head;
299 /* Paste together bracket, system, and after include chains. */
309 /* This is a bit tricky.
310 First we drop dupes from the quote-include list.
311 Then we drop dupes from the bracket-include list.
312 Finally, if qtail and brack are the same directory,
315 We can't just merge the lists and then uniquify them because
316 then we may lose directories from the <> search path that should
317 be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however
318 safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written
319 -Ibar -I- -Ifoo -Iquux.
321 Note that this algorithm is quadratic in the number of -I switches,
322 which is acceptable since there aren't usually that many of them. */
324 for (cur = quote, prev = NULL; cur; cur = cur->next)
326 for (other = quote; other != cur; other = other->next)
327 if (INO_T_EQ (cur->ino, other->ino)
328 && cur->dev == other->dev)
330 if (CPP_OPTION (pfile, verbose))
331 fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"),
334 prev->next = cur->next;
344 for (cur = brack; cur; cur = cur->next)
346 for (other = brack; other != cur; other = other->next)
347 if (INO_T_EQ (cur->ino, other->ino)
348 && cur->dev == other->dev)
350 if (CPP_OPTION (pfile, verbose))
351 fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"),
354 prev->next = cur->next;
365 if (INO_T_EQ (qtail->ino, brack->ino) && qtail->dev == brack->dev)
369 if (CPP_OPTION (pfile, verbose))
370 fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"),
380 while (cur->next != qtail)
383 if (CPP_OPTION (pfile, verbose))
384 fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"),
397 CPP_OPTION (pfile, quote_include) = quote;
398 CPP_OPTION (pfile, bracket_include) = brack;
402 /* Initialize a cpp_reader structure. */
404 cpp_reader_init (pfile)
407 memset ((char *) pfile, 0, sizeof (cpp_reader));
409 pfile->token_buffer_size = 200;
410 pfile->token_buffer = (U_CHAR *) xmalloc (pfile->token_buffer_size);
411 CPP_SET_WRITTEN (pfile, 0);
413 CPP_OPTION (pfile, dollars_in_ident) = 1;
414 CPP_OPTION (pfile, cplusplus_comments) = 1;
415 CPP_OPTION (pfile, warn_import) = 1;
416 CPP_OPTION (pfile, warn_paste) = 1;
417 CPP_OPTION (pfile, discard_comments) = 1;
418 CPP_OPTION (pfile, show_column) = 1;
419 CPP_OPTION (pfile, tabstop) = 8;
421 CPP_OPTION (pfile, pending) =
422 (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
424 _cpp_init_stacks (pfile);
425 _cpp_init_macros (pfile);
426 _cpp_init_includes (pfile);
429 /* Initialize a cpp_printer structure. As a side effect, open the
432 cpp_printer_init (pfile, print)
436 memset (print, '\0', sizeof (cpp_printer));
437 if (CPP_OPTION (pfile, out_fname) == NULL)
438 CPP_OPTION (pfile, out_fname) = "";
440 if (CPP_OPTION (pfile, out_fname)[0] == '\0')
441 print->outf = stdout;
444 print->outf = fopen (CPP_OPTION (pfile, out_fname), "w");
447 cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname));
454 /* Free resources used by PFILE.
455 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
460 while (CPP_BUFFER (pfile) != NULL)
461 cpp_pop_buffer (pfile);
463 if (pfile->token_buffer)
465 free (pfile->token_buffer);
466 pfile->token_buffer = NULL;
470 deps_free (pfile->deps);
472 _cpp_cleanup_stacks (pfile);
473 _cpp_cleanup_macros (pfile);
474 _cpp_cleanup_includes (pfile);
475 _cpp_free_temp_tokens (pfile);
479 /* This structure defines one built-in macro. A node of type TYPE will
480 be entered in the macro hash table under the name NAME, with value
481 VALUE (if any). Two values are not compile time constants, so we tag
482 them in the FLAGS field instead:
483 VERS value is the global version_string, quoted
484 ULP value is the global user_label_prefix
492 unsigned short flags;
498 #define B(n, t) { U n, 0, t, 0, sizeof n - 1 }
499 #define C(n, v) { U n, v, T_MACRO, 0, sizeof n - 1 }
500 #define X(n, f) { U n, 0, T_MACRO, f, sizeof n - 1 }
501 static const struct builtin builtin_array[] =
503 B("__TIME__", T_TIME),
504 B("__DATE__", T_DATE),
505 B("__FILE__", T_FILE),
506 B("__BASE_FILE__", T_BASE_FILE),
507 B("__LINE__", T_SPECLINE),
508 B("__INCLUDE_LEVEL__", T_INCLUDE_LEVEL),
509 B("__STDC__", T_STDC),
511 X("__VERSION__", VERS),
512 X("__USER_LABEL_PREFIX__", ULP),
513 C("__REGISTER_PREFIX__", REGISTER_PREFIX),
514 C("__HAVE_BUILTIN_SETJMP__", "1"),
515 #ifndef NO_BUILTIN_SIZE_TYPE
516 C("__SIZE_TYPE__", SIZE_TYPE),
518 #ifndef NO_BUILTIN_PTRDIFF_TYPE
519 C("__PTRDIFF_TYPE__", PTRDIFF_TYPE),
521 #ifndef NO_BUILTIN_WCHAR_TYPE
522 C("__WCHAR_TYPE__", WCHAR_TYPE),
528 #define builtin_array_end \
529 builtin_array + sizeof(builtin_array)/sizeof(struct builtin)
531 /* Subroutine of cpp_start_read; reads the builtins table above and
532 enters the macros into the hash table. */
534 initialize_builtins (pfile)
537 const struct builtin *b;
538 for(b = builtin_array; b < builtin_array_end; b++)
540 if (b->type == T_MACRO)
547 /* Allocate enough space for 'name="value"\0'. */
548 str = xmalloc (b->len + strlen (version_string) + 4);
549 sprintf (str, "%s=\"%s\"", b->name, version_string);
554 val = user_label_prefix;
558 /* Allocate enough space for "name=value\0". */
559 str = xmalloc (b->len + strlen (val) + 2);
560 sprintf(str, "%s=%s", b->name, val);
562 cpp_define (pfile, str);
568 if (b->type == T_STDC && CPP_TRADITIONAL (pfile))
571 hp = cpp_lookup (pfile, b->name, b->len);
578 #undef builtin_array_end
580 /* Another subroutine of cpp_start_read. This one sets up to do
581 dependency-file output. */
583 initialize_dependency_output (pfile)
586 char *spec, *s, *output_file;
588 /* Either of two environment variables can specify output of deps.
589 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
590 where OUTPUT_FILE is the file to write deps info to
591 and DEPS_TARGET is the target to mention in the deps. */
593 if (CPP_OPTION (pfile, print_deps) == 0)
595 spec = getenv ("DEPENDENCIES_OUTPUT");
597 CPP_OPTION (pfile, print_deps) = 1;
600 spec = getenv ("SUNPRO_DEPENDENCIES");
602 CPP_OPTION (pfile, print_deps) = 2;
607 /* Find the space before the DEPS_TARGET, if there is one. */
608 s = strchr (spec, ' ');
611 CPP_OPTION (pfile, deps_target) = s + 1;
612 output_file = (char *) xmalloc (s - spec + 1);
613 memcpy (output_file, spec, s - spec);
614 output_file[s - spec] = 0;
618 CPP_OPTION (pfile, deps_target) = 0;
622 CPP_OPTION (pfile, deps_file) = output_file;
623 CPP_OPTION (pfile, print_deps_append) = 1;
626 pfile->deps = deps_init ();
628 /* Print the expected object file name as the target of this Make-rule. */
629 if (CPP_OPTION (pfile, deps_target))
630 deps_add_target (pfile->deps, CPP_OPTION (pfile, deps_target));
631 else if (*CPP_OPTION (pfile, in_fname) == 0)
632 deps_add_target (pfile->deps, "-");
634 deps_calc_target (pfile->deps, CPP_OPTION (pfile, in_fname));
636 if (CPP_OPTION (pfile, in_fname))
637 deps_add_dep (pfile->deps, CPP_OPTION (pfile, in_fname));
640 /* And another subroutine. This one sets up the standard include path. */
642 initialize_standard_includes (pfile)
646 const struct default_include *p;
647 const char *specd_prefix = CPP_OPTION (pfile, include_prefix);
649 /* Several environment variables may add to the include search path.
650 CPATH specifies an additional list of directories to be searched
651 as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH,
652 etc. specify an additional list of directories to be searched as
653 if specified with -isystem, for the language indicated. */
655 GET_ENV_PATH_LIST (path, "CPATH");
656 if (path != 0 && *path != 0)
657 path_include (pfile, CPP_OPTION (pfile, pending), path, BRACKET);
659 switch ((CPP_OPTION (pfile, objc) << 1) + CPP_OPTION (pfile, cplusplus))
662 GET_ENV_PATH_LIST (path, "C_INCLUDE_PATH");
665 GET_ENV_PATH_LIST (path, "CPLUS_INCLUDE_PATH");
668 GET_ENV_PATH_LIST (path, "OBJC_INCLUDE_PATH");
671 GET_ENV_PATH_LIST (path, "OBJCPLUS_INCLUDE_PATH");
674 if (path != 0 && *path != 0)
675 path_include (pfile, CPP_OPTION (pfile, pending), path, SYSTEM);
677 /* Search "translated" versions of GNU directories.
678 These have /usr/local/lib/gcc... replaced by specd_prefix. */
679 if (specd_prefix != 0 && cpp_GCC_INCLUDE_DIR_len)
681 /* Remove the `include' from /usr/local/lib/gcc.../include.
682 GCC_INCLUDE_DIR will always end in /include. */
683 int default_len = cpp_GCC_INCLUDE_DIR_len;
684 char *default_prefix = (char *) alloca (default_len + 1);
685 int specd_len = strlen (specd_prefix);
687 memcpy (default_prefix, cpp_GCC_INCLUDE_DIR, default_len);
688 default_prefix[default_len] = '\0';
690 for (p = cpp_include_defaults; p->fname; p++)
692 /* Some standard dirs are only for C++. */
694 || (CPP_OPTION (pfile, cplusplus)
695 && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
697 /* Does this dir start with the prefix? */
698 if (!strncmp (p->fname, default_prefix, default_len))
700 /* Yes; change prefix and add to search list. */
701 int flen = strlen (p->fname);
702 int this_len = specd_len + flen - default_len;
703 char *str = (char *) xmalloc (this_len + 1);
704 memcpy (str, specd_prefix, specd_len);
705 memcpy (str + specd_len,
706 p->fname + default_len,
707 flen - default_len + 1);
709 append_include_chain (pfile, CPP_OPTION (pfile, pending),
710 str, SYSTEM, p->cxx_aware);
716 /* Search ordinary names for GNU include directories. */
717 for (p = cpp_include_defaults; p->fname; p++)
719 /* Some standard dirs are only for C++. */
721 || (CPP_OPTION (pfile, cplusplus)
722 && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
724 /* XXX Potential memory leak! */
725 char *str = xstrdup (update_path (p->fname, p->component));
726 append_include_chain (pfile, CPP_OPTION (pfile, pending),
727 str, SYSTEM, p->cxx_aware);
732 /* This is called after options have been processed.
733 * Check options for consistency, and setup for processing input
734 * from the file named FNAME. (Use standard input if FNAME==NULL.)
735 * Return 1 on success, 0 on failure.
739 cpp_start_read (pfile, print, fname)
744 struct pending_option *p, *q;
746 /* -MG doesn't select the form of output and must be specified with one of
747 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
748 inhibit compilation. */
749 if (CPP_OPTION (pfile, print_deps_missing_files)
750 && (CPP_OPTION (pfile, print_deps) == 0
751 || !CPP_OPTION (pfile, no_output)))
753 cpp_fatal (pfile, "-MG must be specified with one of -M or -MM");
757 /* Chill should not be used with -trigraphs. */
758 if (CPP_OPTION (pfile, chill) && CPP_OPTION (pfile, trigraphs))
760 cpp_warning (pfile, "-lang-chill and -trigraphs are mutually exclusive");
761 CPP_OPTION (pfile, trigraphs) = 0;
764 /* -Wtraditional is not useful in C++ mode. */
765 if (CPP_OPTION (pfile, cplusplus))
766 CPP_OPTION (pfile, warn_traditional) = 0;
768 /* Do not warn about illegal token pasting if -traditional,
769 -lang-fortran, or -lang-asm. */
770 if (CPP_OPTION (pfile, traditional)
771 || CPP_OPTION (pfile, lang_fortran)
772 || CPP_OPTION (pfile, lang_asm))
773 CPP_OPTION (pfile, warn_paste) = 0;
775 /* Set this if it hasn't been set already. */
776 if (user_label_prefix == NULL)
777 user_label_prefix = USER_LABEL_PREFIX;
779 /* Figure out if we need to save function macro parameter spellings.
780 We don't use CPP_PEDANTIC() here because that depends on whether
781 or not the current file is a system header, and there is no
783 pfile->save_parameter_spellings =
784 CPP_OPTION (pfile, pedantic)
785 || CPP_OPTION (pfile, debug_output)
786 || CPP_OPTION (pfile, dump_macros) == dump_definitions
787 || CPP_OPTION (pfile, dump_macros) == dump_only;
789 /* Set up the IStable. This doesn't do anything if we were compiled
790 with a compiler that supports C99 designated initializers. */
793 /* Set up the tables used by read_and_prescan. */
794 _cpp_init_input_buffer (pfile);
796 /* Set up the include search path now. */
797 if (! CPP_OPTION (pfile, no_standard_includes))
798 initialize_standard_includes (pfile);
800 merge_include_chains (pfile);
802 /* With -v, print the list of dirs to search. */
803 if (CPP_OPTION (pfile, verbose))
805 struct file_name_list *l;
806 fprintf (stderr, _("#include \"...\" search starts here:\n"));
807 for (l = CPP_OPTION (pfile, quote_include); l; l = l->next)
809 if (l == CPP_OPTION (pfile, bracket_include))
810 fprintf (stderr, _("#include <...> search starts here:\n"));
811 fprintf (stderr, " %s\n", l->name);
813 fprintf (stderr, _("End of search list.\n"));
816 /* Open the main input file. This must be done early, so we have a
817 buffer to stand on. */
818 if (CPP_OPTION (pfile, in_fname) == NULL
819 || *CPP_OPTION (pfile, in_fname) == 0)
821 CPP_OPTION (pfile, in_fname) = fname;
822 if (CPP_OPTION (pfile, in_fname) == NULL)
823 CPP_OPTION (pfile, in_fname) = "";
825 if (CPP_OPTION (pfile, out_fname) == NULL)
826 CPP_OPTION (pfile, out_fname) = "";
828 if (!cpp_read_file (pfile, fname))
831 initialize_dependency_output (pfile);
833 /* -D and friends may produce output, which should be identified
836 CPP_BUFFER (pfile)->lineno = 0;
839 print->last_fname = CPP_BUFFER (pfile)->nominal_fname;
840 print->last_id = pfile->include_depth;
841 print->written = CPP_WRITTEN (pfile);
845 /* Install __LINE__, etc. */
846 initialize_builtins (pfile);
848 /* Do -U's, -D's and -A's in the order they were seen. */
849 p = CPP_OPTION (pfile, pending)->directive_head;
852 (*p->handler) (pfile, p->arg);
857 pfile->done_initializing = 1;
859 /* Now flush any output recorded during initialization, and advance
860 to line 1 of the main input file. */
861 CPP_BUFFER (pfile)->lineno = 1;
863 if (print && ! CPP_OPTION (pfile, no_output))
864 cpp_output_tokens (pfile, print, 1);
866 /* The -imacros files can be scanned now, but the -include files
867 have to be pushed onto the include stack and processed later,
868 in the main loop calling cpp_get_token. */
870 p = CPP_OPTION (pfile, pending)->imacros_head;
873 if (cpp_read_file (pfile, p->arg))
874 cpp_scan_buffer_nooutput (pfile);
880 p = CPP_OPTION (pfile, pending)->include_head;
883 if (cpp_read_file (pfile, p->arg)
884 && print && ! CPP_OPTION (pfile, no_output))
885 cpp_output_tokens (pfile, print, 1); /* record entry to file */
891 free (CPP_OPTION (pfile, pending));
892 CPP_OPTION (pfile, pending) = NULL;
897 /* This is called at the end of preprocessing. It pops the
898 last buffer and writes dependency output. It should also
899 clear macro definitions, such that you could call cpp_start_read
900 with a new filename to restart processing. */
902 cpp_finish (pfile, print)
906 if (CPP_BUFFER (pfile))
908 cpp_ice (pfile, "buffers still stacked in cpp_finish");
909 while (CPP_BUFFER (pfile))
910 cpp_pop_buffer (pfile);
913 /* Don't write the deps file if preprocessing has failed. */
914 if (CPP_OPTION (pfile, print_deps) && pfile->errors == 0)
916 /* Stream on which to print the dependency information. */
917 FILE *deps_stream = 0;
918 const char *deps_mode
919 = CPP_OPTION (pfile, print_deps_append) ? "a" : "w";
920 if (CPP_OPTION (pfile, deps_file) == 0)
921 deps_stream = stdout;
924 deps_stream = fopen (CPP_OPTION (pfile, deps_file), deps_mode);
925 if (deps_stream == 0)
926 cpp_notice_from_errno (pfile, CPP_OPTION (pfile, deps_file));
930 deps_write (pfile->deps, deps_stream, 72);
931 if (CPP_OPTION (pfile, deps_file))
933 if (ferror (deps_stream) || fclose (deps_stream) != 0)
934 cpp_fatal (pfile, "I/O error on output");
939 if (CPP_OPTION (pfile, dump_macros) == dump_only)
940 _cpp_dump_macro_hash (pfile);
942 /* Flush any pending output. */
945 cpp_output_tokens (pfile, print, print->lineno);
946 if (ferror (print->outf) || fclose (print->outf))
947 cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname));
950 /* Report on headers that could use multiple include guards. */
951 if (CPP_OPTION (pfile, print_include_names))
952 _cpp_report_missing_guards (pfile);
956 new_pending_directive (pend, text, handler)
957 struct cpp_pending *pend;
959 cl_directive_handler handler;
961 struct pending_option *o = (struct pending_option *)
962 xmalloc (sizeof (struct pending_option));
966 o->handler = handler;
967 APPEND (pend, directive, o);
970 /* Irix6 "cc -n32" and OSF4 cc have problems with char foo[] = ("string");
971 I.e. a const string initializer with parens around it. That is
972 what N_("string") resolves to, so we make no_* be macros instead. */
973 #define no_arg N_("Argument missing after %s")
974 #define no_ass N_("Assertion missing after %s")
975 #define no_dir N_("Directory name missing after %s")
976 #define no_fil N_("File name missing after %s")
977 #define no_mac N_("Macro name missing after %s")
978 #define no_pth N_("Path name missing after %s")
979 #define no_num N_("Number missing after %s")
981 /* This is the list of all command line options, with the leading
982 "-" removed. It must be sorted in ASCII collating order. */
983 #define COMMAND_LINE_OPTIONS \
984 DEF_OPT("", 0, OPT_stdin_stdout) \
985 DEF_OPT("$", 0, OPT_dollar) \
986 DEF_OPT("+", 0, OPT_plus) \
987 DEF_OPT("-help", 0, OPT__help) \
988 DEF_OPT("-version", 0, OPT__version) \
989 DEF_OPT("A", no_ass, OPT_A) \
990 DEF_OPT("C", 0, OPT_C) \
991 DEF_OPT("D", no_mac, OPT_D) \
992 DEF_OPT("H", 0, OPT_H) \
993 DEF_OPT("I", no_dir, OPT_I) \
994 DEF_OPT("M", 0, OPT_M) \
995 DEF_OPT("MD", no_fil, OPT_MD) \
996 DEF_OPT("MG", 0, OPT_MG) \
997 DEF_OPT("MM", 0, OPT_MM) \
998 DEF_OPT("MMD", no_fil, OPT_MMD) \
999 DEF_OPT("P", 0, OPT_P) \
1000 DEF_OPT("U", no_mac, OPT_U) \
1001 DEF_OPT("W", no_arg, OPT_W) /* arg optional */ \
1002 DEF_OPT("d", no_arg, OPT_d) \
1003 DEF_OPT("fleading-underscore", 0, OPT_fleading_underscore) \
1004 DEF_OPT("fno-leading-underscore", 0, OPT_fno_leading_underscore) \
1005 DEF_OPT("fno-preprocessed", 0, OPT_fno_preprocessed) \
1006 DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \
1007 DEF_OPT("fpreprocessed", 0, OPT_fpreprocessed) \
1008 DEF_OPT("fshow-column", 0, OPT_fshow_column) \
1009 DEF_OPT("ftabstop=", no_num, OPT_ftabstop) \
1010 DEF_OPT("g", no_arg, OPT_g) /* arg optional */ \
1011 DEF_OPT("h", 0, OPT_h) \
1012 DEF_OPT("idirafter", no_dir, OPT_idirafter) \
1013 DEF_OPT("imacros", no_fil, OPT_imacros) \
1014 DEF_OPT("include", no_fil, OPT_include) \
1015 DEF_OPT("iprefix", no_pth, OPT_iprefix) \
1016 DEF_OPT("isystem", no_dir, OPT_isystem) \
1017 DEF_OPT("iwithprefix", no_dir, OPT_iwithprefix) \
1018 DEF_OPT("iwithprefixbefore", no_dir, OPT_iwithprefixbefore) \
1019 DEF_OPT("lang-asm", 0, OPT_lang_asm) \
1020 DEF_OPT("lang-c", 0, OPT_lang_c) \
1021 DEF_OPT("lang-c++", 0, OPT_lang_cplusplus) \
1022 DEF_OPT("lang-c89", 0, OPT_lang_c89) \
1023 DEF_OPT("lang-chill", 0, OPT_lang_chill) \
1024 DEF_OPT("lang-fortran", 0, OPT_lang_fortran) \
1025 DEF_OPT("lang-objc", 0, OPT_lang_objc) \
1026 DEF_OPT("lang-objc++", 0, OPT_lang_objcplusplus) \
1027 DEF_OPT("nostdinc", 0, OPT_nostdinc) \
1028 DEF_OPT("nostdinc++", 0, OPT_nostdincplusplus) \
1029 DEF_OPT("o", no_fil, OPT_o) \
1030 DEF_OPT("pedantic", 0, OPT_pedantic) \
1031 DEF_OPT("pedantic-errors", 0, OPT_pedantic_errors) \
1032 DEF_OPT("remap", 0, OPT_remap) \
1033 DEF_OPT("std=c89", 0, OPT_std_c89) \
1034 DEF_OPT("std=c99", 0, OPT_std_c99) \
1035 DEF_OPT("std=c9x", 0, OPT_std_c9x) \
1036 DEF_OPT("std=gnu89", 0, OPT_std_gnu89) \
1037 DEF_OPT("std=gnu99", 0, OPT_std_gnu99) \
1038 DEF_OPT("std=gnu9x", 0, OPT_std_gnu9x) \
1039 DEF_OPT("std=iso9899:1990", 0, OPT_std_iso9899_1990) \
1040 DEF_OPT("std=iso9899:199409", 0, OPT_std_iso9899_199409) \
1041 DEF_OPT("std=iso9899:1999", 0, OPT_std_iso9899_1999) \
1042 DEF_OPT("std=iso9899:199x", 0, OPT_std_iso9899_199x) \
1043 DEF_OPT("traditional", 0, OPT_traditional) \
1044 DEF_OPT("trigraphs", 0, OPT_trigraphs) \
1045 DEF_OPT("v", 0, OPT_v) \
1046 DEF_OPT("w", 0, OPT_w)
1048 #define DEF_OPT(text, msg, code) code,
1051 COMMAND_LINE_OPTIONS
1058 const char *opt_text;
1061 enum opt_code opt_code;
1064 #define DEF_OPT(text, msg, code) { text, msg, sizeof(text) - 1, code },
1066 static struct cl_option cl_options[] =
1068 static const struct cl_option cl_options[] =
1071 COMMAND_LINE_OPTIONS
1074 #undef COMMAND_LINE_OPTIONS
1076 /* Perform a binary search to find which, if any, option the given
1077 command-line matches. Returns its index in the option array,
1078 negative on failure. Complications arise since some options can be
1079 suffixed with an argument, and multiple complete matches can occur,
1080 e.g. -iwithprefix and -iwithprefixbefore. Moreover, we want to
1081 accept options beginning with -g and -W that we do not recognise,
1082 but not to swallow any subsequent command line argument; these are
1083 handled as special cases in cpp_handle_option */
1085 parse_option (input)
1088 unsigned int md, mn, mx;
1099 opt_len = cl_options[md].opt_len;
1100 comp = strncmp (input, cl_options[md].opt_text, opt_len);
1108 if (input[opt_len] == '\0')
1110 /* We were passed more text. If the option takes an argument,
1111 we may match a later option or we may have been passed the
1112 argument. The longest possible option match succeeds.
1113 If the option takes no arguments we have not matched and
1114 continue the search (e.g. input="stdc++" match was "stdc") */
1116 if (cl_options[md].msg)
1118 /* Scan forwards. If we get an exact match, return it.
1119 Otherwise, return the longest option-accepting match.
1120 This loops no more than twice with current options */
1122 for (; mn < N_OPTS; mn++)
1124 opt_len = cl_options[mn].opt_len;
1125 if (strncmp (input, cl_options[mn].opt_text, opt_len))
1127 if (input[opt_len] == '\0')
1129 if (cl_options[mn].msg)
1140 /* Handle one command-line option in (argc, argv).
1141 Can be called multiple times, to handle multiple sets of options.
1142 Returns number of strings consumed. */
1145 handle_option (pfile, argc, argv)
1151 struct cpp_pending *pend = CPP_OPTION (pfile, pending);
1153 if (argv[i][0] != '-')
1155 if (CPP_OPTION (pfile, out_fname) != NULL)
1156 cpp_fatal (pfile, "Too many arguments. Type %s --help for usage info",
1158 else if (CPP_OPTION (pfile, in_fname) != NULL)
1159 CPP_OPTION (pfile, out_fname) = argv[i];
1161 CPP_OPTION (pfile, in_fname) = argv[i];
1165 enum opt_code opt_code;
1167 const char *arg = 0;
1170 opt_index = parse_option (&argv[i][1]);
1174 opt_code = cl_options[opt_index].opt_code;
1175 if (cl_options[opt_index].msg)
1177 arg = &argv[i][cl_options[opt_index].opt_len + 1];
1179 /* Yuk. Special case for -g and -W as they must not swallow
1180 up any following argument. If this becomes common, add
1181 another field to the cl_options table */
1182 if (arg[0] == '\0' && !(opt_code == OPT_g || opt_code == OPT_W))
1187 cpp_fatal (pfile, cl_options[opt_index].msg, argv[i - 1]);
1195 case N_OPTS: /* shut GCC up */
1197 case OPT_fleading_underscore:
1198 user_label_prefix = "_";
1200 case OPT_fno_leading_underscore:
1201 user_label_prefix = "";
1203 case OPT_fpreprocessed:
1204 CPP_OPTION (pfile, preprocessed) = 1;
1206 case OPT_fno_preprocessed:
1207 CPP_OPTION (pfile, preprocessed) = 0;
1209 case OPT_fshow_column:
1210 CPP_OPTION (pfile, show_column) = 1;
1212 case OPT_fno_show_column:
1213 CPP_OPTION (pfile, show_column) = 0;
1216 /* Silently ignore empty string, non-longs and silly values. */
1220 long tabstop = strtol (arg, &endptr, 10);
1221 if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
1222 CPP_OPTION (pfile, tabstop) = tabstop;
1226 CPP_OPTION (pfile, inhibit_warnings) = 1;
1228 case OPT_g: /* Silently ignore anything but -g3 */
1229 if (!strcmp(&argv[i][2], "3"))
1230 CPP_OPTION (pfile, debug_output) = 1;
1238 fprintf (stderr, _("GNU CPP version %s (cpplib)\n"), version_string);
1242 CPP_OPTION (pfile, discard_comments) = 0;
1245 CPP_OPTION (pfile, no_line_commands) = 1;
1247 case OPT_dollar: /* Don't include $ in identifiers. */
1248 CPP_OPTION (pfile, dollars_in_ident) = 0;
1251 CPP_OPTION (pfile, print_include_names) = 1;
1254 new_pending_directive (pend, arg, cpp_define);
1256 case OPT_pedantic_errors:
1257 CPP_OPTION (pfile, pedantic_errors) = 1;
1260 CPP_OPTION (pfile, pedantic) = 1;
1262 case OPT_traditional:
1263 CPP_OPTION (pfile, traditional) = 1;
1264 CPP_OPTION (pfile, cplusplus_comments) = 0;
1265 CPP_OPTION (pfile, trigraphs) = 0;
1266 CPP_OPTION (pfile, warn_trigraphs) = 0;
1269 CPP_OPTION (pfile, trigraphs) = 1;
1272 CPP_OPTION (pfile, cplusplus) = 1;
1273 CPP_OPTION (pfile, cplusplus_comments) = 1;
1276 CPP_OPTION (pfile, remap) = 1;
1279 CPP_OPTION (pfile, include_prefix) = arg;
1280 CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
1283 CPP_OPTION (pfile, cplusplus) = 0;
1284 CPP_OPTION (pfile, cplusplus_comments) = 1;
1285 CPP_OPTION (pfile, c89) = 0;
1286 CPP_OPTION (pfile, c99) = 1;
1287 CPP_OPTION (pfile, objc) = 0;
1290 CPP_OPTION (pfile, cplusplus) = 0;
1291 CPP_OPTION (pfile, cplusplus_comments) = 0;
1292 CPP_OPTION (pfile, c89) = 1;
1293 CPP_OPTION (pfile, c99) = 0;
1294 CPP_OPTION (pfile, objc) = 0;
1295 CPP_OPTION (pfile, trigraphs) = 1;
1296 new_pending_directive (pend, "__STRICT_ANSI__", cpp_define);
1298 case OPT_lang_cplusplus:
1299 CPP_OPTION (pfile, cplusplus) = 1;
1300 CPP_OPTION (pfile, cplusplus_comments) = 1;
1301 CPP_OPTION (pfile, c89) = 0;
1302 CPP_OPTION (pfile, c99) = 0;
1303 CPP_OPTION (pfile, objc) = 0;
1304 new_pending_directive (pend, "__cplusplus", cpp_define);
1306 case OPT_lang_objcplusplus:
1307 CPP_OPTION (pfile, cplusplus) = 1;
1308 new_pending_directive (pend, "__cplusplus", cpp_define);
1311 CPP_OPTION (pfile, cplusplus_comments) = 1;
1312 CPP_OPTION (pfile, c89) = 0;
1313 CPP_OPTION (pfile, c99) = 0;
1314 CPP_OPTION (pfile, objc) = 1;
1315 new_pending_directive (pend, "__OBJC__", cpp_define);
1318 CPP_OPTION (pfile, lang_asm) = 1;
1319 CPP_OPTION (pfile, dollars_in_ident) = 0;
1320 new_pending_directive (pend, "__ASSEMBLER__", cpp_define);
1322 case OPT_lang_fortran:
1323 CPP_OPTION (pfile, lang_fortran) = 1;
1324 CPP_OPTION (pfile, traditional) = 1;
1325 CPP_OPTION (pfile, cplusplus_comments) = 0;
1326 new_pending_directive (pend, "_LANGUAGE_FORTRAN", cpp_define);
1328 case OPT_lang_chill:
1329 CPP_OPTION (pfile, objc) = 0;
1330 CPP_OPTION (pfile, cplusplus) = 0;
1331 CPP_OPTION (pfile, chill) = 1;
1332 CPP_OPTION (pfile, traditional) = 1;
1335 /* -nostdinc causes no default include directories.
1336 You must specify all include-file directories with -I. */
1337 CPP_OPTION (pfile, no_standard_includes) = 1;
1339 case OPT_nostdincplusplus:
1340 /* -nostdinc++ causes no default C++-specific include directories. */
1341 CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1;
1344 CPP_OPTION (pfile, cplusplus) = 0;
1345 CPP_OPTION (pfile, cplusplus_comments) = 1;
1346 CPP_OPTION (pfile, c89) = 1;
1347 CPP_OPTION (pfile, c99) = 0;
1348 CPP_OPTION (pfile, objc) = 0;
1352 CPP_OPTION (pfile, cplusplus) = 0;
1353 CPP_OPTION (pfile, cplusplus_comments) = 1;
1354 CPP_OPTION (pfile, c89) = 0;
1355 CPP_OPTION (pfile, c99) = 1;
1356 CPP_OPTION (pfile, objc) = 0;
1357 new_pending_directive (CPP_OPTION (pfile, pending),
1358 "__STDC_VERSION__=199901L", cpp_define);
1360 case OPT_std_iso9899_199409:
1361 new_pending_directive (CPP_OPTION (pfile, pending),
1362 "__STDC_VERSION__=199409L", cpp_define);
1364 case OPT_std_iso9899_1990:
1366 CPP_OPTION (pfile, cplusplus) = 0;
1367 CPP_OPTION (pfile, cplusplus_comments) = 0;
1368 CPP_OPTION (pfile, c89) = 1;
1369 CPP_OPTION (pfile, c99) = 0;
1370 CPP_OPTION (pfile, objc) = 0;
1371 CPP_OPTION (pfile, trigraphs) = 1;
1372 new_pending_directive (CPP_OPTION (pfile, pending),
1373 "__STRICT_ANSI__", cpp_define);
1375 case OPT_std_iso9899_199x:
1376 case OPT_std_iso9899_1999:
1379 CPP_OPTION (pfile, cplusplus) = 0;
1380 CPP_OPTION (pfile, cplusplus_comments) = 1;
1381 CPP_OPTION (pfile, c89) = 0;
1382 CPP_OPTION (pfile, c99) = 1;
1383 CPP_OPTION (pfile, objc) = 0;
1384 CPP_OPTION (pfile, trigraphs) = 1;
1385 new_pending_directive (CPP_OPTION (pfile, pending),
1386 "__STRICT_ANSI__", cpp_define);
1387 new_pending_directive (CPP_OPTION (pfile, pending),
1388 "__STDC_VERSION__=199901L", cpp_define);
1391 if (CPP_OPTION (pfile, out_fname) != NULL)
1393 cpp_fatal (pfile, "Output filename specified twice");
1396 CPP_OPTION (pfile, out_fname) = arg;
1397 if (!strcmp (CPP_OPTION (pfile, out_fname), "-"))
1398 CPP_OPTION (pfile, out_fname) = "";
1401 fprintf (stderr, _("GNU CPP version %s (cpplib)\n"), version_string);
1402 #ifdef TARGET_VERSION
1405 fputc ('\n', stderr);
1406 CPP_OPTION (pfile, verbose) = 1;
1408 case OPT_stdin_stdout:
1409 /* JF handle '-' as file name meaning stdin or stdout */
1410 if (CPP_OPTION (pfile, in_fname) == NULL)
1411 CPP_OPTION (pfile, in_fname) = "";
1412 else if (CPP_OPTION (pfile, out_fname) == NULL)
1413 CPP_OPTION (pfile, out_fname) = "";
1416 /* Args to -d specify what parts of macros to dump.
1417 Silently ignore unrecognised options; they may
1418 be aimed at the compiler proper. */
1422 while ((c = *arg++) != '\0')
1426 CPP_OPTION (pfile, dump_macros) = dump_only;
1427 CPP_OPTION (pfile, no_output) = 1;
1430 CPP_OPTION (pfile, dump_macros) = dump_names;
1433 CPP_OPTION (pfile, dump_macros) = dump_definitions;
1436 CPP_OPTION (pfile, dump_includes) = 1;
1441 /* The style of the choices here is a bit mixed.
1442 The chosen scheme is a hybrid of keeping all options in one string
1443 and specifying each option in a separate argument:
1444 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
1445 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
1446 -M[M][G][D file]. This is awkward to handle in specs, and is not
1448 /* ??? -MG must be specified in addition to one of -M or -MM.
1449 This can be relaxed in the future without breaking anything.
1450 The converse isn't true. */
1452 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
1454 CPP_OPTION (pfile, print_deps_missing_files) = 1;
1460 if (opt_code == OPT_M || opt_code == OPT_MD)
1461 CPP_OPTION (pfile, print_deps) = 2;
1463 CPP_OPTION (pfile, print_deps) = 1;
1465 /* For -MD and -MMD options, write deps on file named by next arg */
1466 /* For -M and -MM, write deps on standard output
1467 and suppress the usual output. */
1468 if (opt_code == OPT_MD || opt_code == OPT_MMD)
1469 CPP_OPTION (pfile, deps_file) = arg;
1471 CPP_OPTION (pfile, no_output) = 1;
1476 /* -A with an argument beginning with '-' acts as
1477 #unassert on whatever immediately follows the '-'.
1478 If "-" is the whole argument, we eliminate all
1479 predefined macros and assertions, including those
1480 that were specified earlier on the command line.
1481 That way we can get rid of any that were passed
1482 automatically in from GCC. */
1486 struct pending_option *o1, *o2;
1488 o1 = CPP_OPTION (pfile, pending)->directive_head;
1495 CPP_OPTION (pfile, pending)->directive_head = NULL;
1496 CPP_OPTION (pfile, pending)->directive_tail = NULL;
1499 new_pending_directive (CPP_OPTION (pfile, pending),
1500 arg + 1, cpp_unassert);
1503 new_pending_directive (CPP_OPTION (pfile, pending),
1507 new_pending_directive (CPP_OPTION (pfile, pending), arg, cpp_undef);
1509 case OPT_I: /* Add directory to path for includes. */
1510 if (!strcmp (arg, "-"))
1513 Use the preceding -I directories for #include "..."
1514 but not #include <...>.
1515 Don't search the directory of the present file
1516 for #include "...". (Note that -I. -I- is not the same as
1517 the default setup; -I. uses the compiler's working dir.) */
1518 if (! CPP_OPTION (pfile, ignore_srcdir))
1520 struct cpp_pending *pend = CPP_OPTION (pfile, pending);
1521 pend->quote_head = pend->brack_head;
1522 pend->quote_tail = pend->brack_tail;
1523 pend->brack_head = 0;
1524 pend->brack_tail = 0;
1525 CPP_OPTION (pfile, ignore_srcdir) = 1;
1529 cpp_fatal (pfile, "-I- specified twice");
1534 append_include_chain (pfile, CPP_OPTION (pfile, pending),
1535 xstrdup (arg), BRACKET, 0);
1538 /* Add directory to beginning of system include path, as a system
1539 include directory. */
1540 append_include_chain (pfile, CPP_OPTION (pfile, pending),
1541 xstrdup (arg), SYSTEM, 0);
1545 struct pending_option *o = (struct pending_option *)
1546 xmalloc (sizeof (struct pending_option));
1549 /* This list has to be built in reverse order so that
1550 when cpp_start_read pushes all the -include files onto
1551 the buffer stack, they will be scanned in forward order. */
1552 o->next = CPP_OPTION (pfile, pending)->include_head;
1553 CPP_OPTION (pfile, pending)->include_head = o;
1558 struct pending_option *o = (struct pending_option *)
1559 xmalloc (sizeof (struct pending_option));
1563 APPEND (CPP_OPTION (pfile, pending), imacros, o);
1566 case OPT_iwithprefix:
1567 /* Add directory to end of path for includes,
1568 with the default prefix at the front of its name. */
1570 case OPT_iwithprefixbefore:
1571 /* Add directory to main path for includes,
1572 with the default prefix at the front of its name. */
1579 if (CPP_OPTION (pfile, include_prefix) != 0)
1581 size_t ipl = CPP_OPTION (pfile, include_prefix_len);
1582 fname = xmalloc (ipl + len + 1);
1583 memcpy (fname, CPP_OPTION (pfile, include_prefix), ipl);
1584 memcpy (fname + ipl, arg, len + 1);
1586 else if (cpp_GCC_INCLUDE_DIR_len)
1588 fname = xmalloc (cpp_GCC_INCLUDE_DIR_len + len + 1);
1589 memcpy (fname, cpp_GCC_INCLUDE_DIR, cpp_GCC_INCLUDE_DIR_len);
1590 memcpy (fname + cpp_GCC_INCLUDE_DIR_len, arg, len + 1);
1593 fname = xstrdup (arg);
1595 append_include_chain (pfile, CPP_OPTION (pfile, pending), fname,
1596 opt_code == OPT_iwithprefix ? SYSTEM: BRACKET, 0);
1600 /* Add directory to end of path for includes. */
1601 append_include_chain (pfile, CPP_OPTION (pfile, pending),
1602 xstrdup (arg), AFTER, 0);
1605 /* Silently ignore unrecognised options */
1606 if (!strcmp (argv[i], "-Wall"))
1608 CPP_OPTION (pfile, warn_trigraphs) = 1;
1609 CPP_OPTION (pfile, warn_comments) = 1;
1611 else if (!strcmp (argv[i], "-Wtraditional"))
1612 CPP_OPTION (pfile, warn_traditional) = 1;
1613 else if (!strcmp (argv[i], "-Wtrigraphs"))
1614 CPP_OPTION (pfile, warn_trigraphs) = 1;
1615 else if (!strcmp (argv[i], "-Wcomment"))
1616 CPP_OPTION (pfile, warn_comments) = 1;
1617 else if (!strcmp (argv[i], "-Wcomments"))
1618 CPP_OPTION (pfile, warn_comments) = 1;
1619 else if (!strcmp (argv[i], "-Wundef"))
1620 CPP_OPTION (pfile, warn_undef) = 1;
1621 else if (!strcmp (argv[i], "-Wimport"))
1622 CPP_OPTION (pfile, warn_import) = 1;
1623 else if (!strcmp (argv[i], "-Wpaste"))
1624 CPP_OPTION (pfile, warn_paste) = 1;
1625 else if (!strcmp (argv[i], "-Werror"))
1626 CPP_OPTION (pfile, warnings_are_errors) = 1;
1627 else if (!strcmp (argv[i], "-Wno-traditional"))
1628 CPP_OPTION (pfile, warn_traditional) = 0;
1629 else if (!strcmp (argv[i], "-Wno-trigraphs"))
1630 CPP_OPTION (pfile, warn_trigraphs) = 0;
1631 else if (!strcmp (argv[i], "-Wno-comment"))
1632 CPP_OPTION (pfile, warn_comments) = 0;
1633 else if (!strcmp (argv[i], "-Wno-comments"))
1634 CPP_OPTION (pfile, warn_comments) = 0;
1635 else if (!strcmp (argv[i], "-Wno-undef"))
1636 CPP_OPTION (pfile, warn_undef) = 0;
1637 else if (!strcmp (argv[i], "-Wno-import"))
1638 CPP_OPTION (pfile, warn_import) = 0;
1639 else if (!strcmp (argv[i], "-Wno-paste"))
1640 CPP_OPTION (pfile, warn_paste) = 0;
1641 else if (!strcmp (argv[i], "-Wno-error"))
1642 CPP_OPTION (pfile, warnings_are_errors) = 0;
1651 opt_comp (const void *p1, const void *p2)
1653 return strcmp (((struct cl_option *)p1)->opt_text,
1654 ((struct cl_option *)p2)->opt_text);
1658 /* Handle command-line options in (argc, argv).
1659 Can be called multiple times, to handle multiple sets of options.
1660 Returns if an unrecognized option is seen.
1661 Returns number of strings consumed. */
1663 cpp_handle_options (pfile, argc, argv)
1669 int strings_processed;
1672 static int opts_sorted = 0;
1677 /* For non-ASCII hosts, the array needs to be sorted at runtime */
1678 qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
1682 for (i = 0; i < argc; i += strings_processed)
1684 strings_processed = handle_option (pfile, argc - i, argv + i);
1685 if (strings_processed == 0)
1694 fprintf (stderr, _("Usage: %s [switches] input output\n"), progname);
1697 -include <file> Include the contents of <file> before other files\n\
1698 -imacros <file> Accept definition of macros in <file>\n\
1699 -iprefix <path> Specify <path> as a prefix for next two options\n\
1700 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1701 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1702 -isystem <dir> Add <dir> to the start of the system include path\n\
1703 -idirafter <dir> Add <dir> to the end of the system include path\n\
1704 -I <dir> Add <dir> to the end of the main include path\n\
1705 -I- Fine-grained include path control; see info docs\n\
1706 -nostdinc Do not search system include directories\n\
1707 (dirs specified with -isystem will still be used)\n\
1708 -nostdinc++ Do not search system include directories for C++\n\
1709 -o <file> Put output into <file>\n\
1710 -pedantic Issue all warnings demanded by strict ISO C\n\
1711 -pedantic-errors Issue -pedantic warnings as errors instead\n\
1712 -traditional Follow K&R pre-processor behaviour\n\
1713 -trigraphs Support ISO C trigraphs\n\
1714 -lang-c Assume that the input sources are in C\n\
1715 -lang-c89 Assume that the input sources are in C89\n\
1716 -lang-c++ Assume that the input sources are in C++\n\
1717 -lang-objc Assume that the input sources are in ObjectiveC\n\
1718 -lang-objc++ Assume that the input sources are in ObjectiveC++\n\
1719 -lang-asm Assume that the input sources are in assembler\n\
1720 -lang-fortran Assume that the input sources are in Fortran\n\
1721 -lang-chill Assume that the input sources are in Chill\n\
1722 -std=<std name> Specify the conformance standard; one of:\n\
1723 gnu89, gnu99, c89, c99, iso9899:1990,\n\
1724 iso9899:199409, iso9899:1999\n\
1725 -+ Allow parsing of C++ style features\n\
1726 -w Inhibit warning messages\n\
1727 -Wtrigraphs Warn if trigraphs are encountered\n\
1728 -Wno-trigraphs Do not warn about trigraphs\n\
1729 -Wcomment{s} Warn if one comment starts inside another\n\
1730 -Wno-comment{s} Do not warn about comments\n\
1731 -Wtraditional Warn if a macro argument is/would be turned into\n\
1732 a string if -traditional is specified\n\
1733 -Wno-traditional Do not warn about stringification\n\
1734 -Wundef Warn if an undefined macro is used by #if\n\
1735 -Wno-undef Do not warn about testing undefined macros\n\
1736 -Wimport Warn about the use of the #import directive\n\
1737 -Wno-import Do not warn about the use of #import\n\
1738 -Werror Treat all warnings as errors\n\
1739 -Wno-error Do not treat warnings as errors\n\
1740 -Wall Enable all preprocessor warnings\n\
1741 -M Generate make dependencies\n\
1742 -MM As -M, but ignore system header files\n\
1743 -MD As -M, but put output in a .d file\n\
1744 -MMD As -MD, but ignore system header files\n\
1745 -MG Treat missing header file as generated files\n\
1746 -g3 Include #define and #undef directives in the output\n\
1747 -D<macro> Define a <macro> with string '1' as its value\n\
1748 -D<macro>=<val> Define a <macro> with <val> as its value\n\
1749 -A<question> (<answer>) Assert the <answer> to <question>\n\
1750 -A-<question> (<answer>) Disable the <answer> to <question>\n\
1751 -U<macro> Undefine <macro> \n\
1752 -v Display the version number\n\
1753 -H Print the name of header files as they are used\n\
1754 -C Do not discard comments\n\
1755 -dM Display a list of macro definitions active at end\n\
1756 -dD Preserve macro definitions in output\n\
1757 -dN As -dD except that only the names are preserved\n\
1758 -dI Include #include directives in the output\n\
1759 -ftabstop=<number> Distance between tab stops for column reporting\n\
1760 -P Do not generate #line directives\n\
1761 -$ Do not allow '$' in identifiers\n\
1762 -remap Remap file names when including files.\n\
1763 --version Display version information\n\
1764 -h or --help Display this information\n\