2 Copyright (C) 1986, 87, 89, 92-98, 1999 Free Software Foundation, Inc.
3 Contributed by Per Bothner, 1994-95.
4 Based on CCCP program by Paul Rubin, June 1986
5 Adapted to ANSI C, Richard Stallman, Jan 1987
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 /* XXX Should be in a header file. */
32 extern char *version_string;
34 /* Predefined symbols, built-in macros, and the default include path. */
36 #ifndef GET_ENV_PATH_LIST
37 #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
40 /* By default, colon separates directories in a path. */
41 #ifndef PATH_SEPARATOR
42 #define PATH_SEPARATOR ':'
45 #ifndef STANDARD_INCLUDE_DIR
46 #define STANDARD_INCLUDE_DIR "/usr/include"
49 /* We let tm.h override the types used here, to handle trivial differences
50 such as the choice of unsigned int or long unsigned int for size_t.
51 When machines start needing nontrivial differences in the size type,
52 it would be best to do something here to figure out automatically
53 from other information what type to use. */
55 /* The string value for __SIZE_TYPE__. */
58 #define SIZE_TYPE "long unsigned int"
61 /* The string value for __PTRDIFF_TYPE__. */
64 #define PTRDIFF_TYPE "long int"
67 /* The string value for __WCHAR_TYPE__. */
70 #define WCHAR_TYPE "int"
72 #define CPP_WCHAR_TYPE(PFILE) \
73 (CPP_OPTIONS (PFILE)->cplusplus ? "__wchar_t" : WCHAR_TYPE)
75 /* The string value for __USER_LABEL_PREFIX__ */
77 #ifndef USER_LABEL_PREFIX
78 #define USER_LABEL_PREFIX ""
81 /* The string value for __REGISTER_PREFIX__ */
83 #ifndef REGISTER_PREFIX
84 #define REGISTER_PREFIX ""
87 /* Suffix for object files, and known input-file extensions. */
88 static char *known_suffixes[] =
90 ".c", ".C", ".s", ".S", ".m",
91 ".cc", ".cxx", ".cpp", ".cp", ".c++",
97 # define OBJECT_SUFFIX ".obj"
99 # define OBJECT_SUFFIX ".o"
104 /* This is the default list of directories to search for include files.
105 It may be overridden by the various -I and -ixxx options.
107 #include "file" looks in the same directory as the current file,
109 #include <file> just looks in this list.
111 All these directories are treated as `system' include directories
112 (they are not subject to pedantic warnings in some cases). */
114 static struct default_include
116 char *fname; /* The name of the directory. */
117 char *component; /* The component containing the directory
118 (see update_path in prefix.c) */
119 int cplusplus; /* Only look here if we're compiling C++. */
120 int cxx_aware; /* Includes in this directory don't need to
121 be wrapped in extern "C" when compiling
122 C++. This is not used anymore. */
124 include_defaults_array[]
125 #ifdef INCLUDE_DEFAULTS
129 /* Pick up GNU C++ specific include files. */
130 { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 },
132 /* This is the dir for fixincludes. Put it just before
133 the files that we fix. */
134 { GCC_INCLUDE_DIR, "GCC", 0, 0 },
135 /* For cross-compilation, this dir name is generated
136 automatically in Makefile.in. */
137 { CROSS_INCLUDE_DIR, "GCC", 0, 0 },
138 #ifdef TOOL_INCLUDE_DIR
139 /* This is another place that the target system's headers might be. */
140 { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
142 #else /* not CROSS_COMPILE */
143 #ifdef LOCAL_INCLUDE_DIR
144 /* This should be /usr/local/include and should come before
145 the fixincludes-fixed header files. */
146 { LOCAL_INCLUDE_DIR, 0, 0, 1 },
148 #ifdef TOOL_INCLUDE_DIR
149 /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
150 Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
151 { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
153 /* This is the dir for fixincludes. Put it just before
154 the files that we fix. */
155 { GCC_INCLUDE_DIR, "GCC", 0, 0 },
156 /* Some systems have an extra dir of include files. */
157 #ifdef SYSTEM_INCLUDE_DIR
158 { SYSTEM_INCLUDE_DIR, 0, 0, 0 },
160 #ifndef STANDARD_INCLUDE_COMPONENT
161 #define STANDARD_INCLUDE_COMPONENT 0
163 { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0 },
164 #endif /* not CROSS_COMPILE */
167 #endif /* no INCLUDE_DEFAULTS */
169 /* Internal structures and prototypes. */
171 /* A `struct pending_option' remembers one -D, -A, -U, -include, or -imacros
172 switch. There are four lists: one for -D and -U, one for -A, one
173 for -include, one for -imacros. `undef' is set for -U, clear for
174 -D, ignored for the others.
175 (Future: add an equivalent of -U for -A) */
176 struct pending_option
178 struct pending_option *next;
184 #define APPEND(pend, list, elt) \
185 do { if (!(pend)->list##_head) (pend)->list##_head = (elt); \
186 else (pend)->list##_tail->next = (elt); \
187 (pend)->list##_tail = (elt); \
190 #define APPEND(pend, list, elt) \
191 do { if (!(pend)->list/**/_head) (pend)->list/**/_head = (elt); \
192 else (pend)->list/**/_tail->next = (elt); \
193 (pend)->list/**/_tail = (elt); \
197 static void initialize_char_syntax PARAMS ((int));
198 static void print_help PARAMS ((void));
199 static void path_include PARAMS ((cpp_reader *,
200 struct cpp_pending *,
202 static void initialize_builtins PARAMS ((cpp_reader *));
203 static void append_include_chain PARAMS ((cpp_reader *,
204 struct cpp_pending *,
207 /* Last argument to append_include_chain: chain to use */
208 enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
210 /* If gcc is in use (stage2/stage3) we can make these tables initialized
212 #if defined __GNUC__ && __GNUC__ >= 2
213 /* Table to tell if a character is legal as the second or later character
214 of a C identifier. */
215 U_CHAR is_idchar[256] =
217 ['a'] = 1, ['b'] = 1, ['c'] = 1, ['d'] = 1, ['e'] = 1, ['f'] = 1,
218 ['g'] = 1, ['h'] = 1, ['i'] = 1, ['j'] = 1, ['k'] = 1, ['l'] = 1,
219 ['m'] = 1, ['n'] = 1, ['o'] = 1, ['p'] = 1, ['q'] = 1, ['r'] = 1,
220 ['s'] = 1, ['t'] = 1, ['u'] = 1, ['v'] = 1, ['w'] = 1, ['x'] = 1,
221 ['y'] = 1, ['z'] = 1,
223 ['A'] = 1, ['B'] = 1, ['C'] = 1, ['D'] = 1, ['E'] = 1, ['F'] = 1,
224 ['G'] = 1, ['H'] = 1, ['I'] = 1, ['J'] = 1, ['K'] = 1, ['L'] = 1,
225 ['M'] = 1, ['N'] = 1, ['O'] = 1, ['P'] = 1, ['Q'] = 1, ['R'] = 1,
226 ['S'] = 1, ['T'] = 1, ['U'] = 1, ['V'] = 1, ['W'] = 1, ['X'] = 1,
227 ['Y'] = 1, ['Z'] = 1,
229 ['1'] = 1, ['2'] = 1, ['3'] = 1, ['4'] = 1, ['5'] = 1, ['6'] = 1,
230 ['7'] = 1, ['8'] = 1, ['9'] = 1, ['0'] = 1,
235 /* Table to tell if a character is legal as the first character of
237 U_CHAR is_idstart[256] =
239 ['a'] = 1, ['b'] = 1, ['c'] = 1, ['d'] = 1, ['e'] = 1, ['f'] = 1,
240 ['g'] = 1, ['h'] = 1, ['i'] = 1, ['j'] = 1, ['k'] = 1, ['l'] = 1,
241 ['m'] = 1, ['n'] = 1, ['o'] = 1, ['p'] = 1, ['q'] = 1, ['r'] = 1,
242 ['s'] = 1, ['t'] = 1, ['u'] = 1, ['v'] = 1, ['w'] = 1, ['x'] = 1,
243 ['y'] = 1, ['z'] = 1,
245 ['A'] = 1, ['B'] = 1, ['C'] = 1, ['D'] = 1, ['E'] = 1, ['F'] = 1,
246 ['G'] = 1, ['H'] = 1, ['I'] = 1, ['J'] = 1, ['K'] = 1, ['L'] = 1,
247 ['M'] = 1, ['N'] = 1, ['O'] = 1, ['P'] = 1, ['Q'] = 1, ['R'] = 1,
248 ['S'] = 1, ['T'] = 1, ['U'] = 1, ['V'] = 1, ['W'] = 1, ['X'] = 1,
249 ['Y'] = 1, ['Z'] = 1,
254 /* Table to tell if a character is horizontal space.
255 \r is magical, so it is not in here. */
256 U_CHAR is_hor_space[256] =
258 [' '] = 1, ['\t'] = 1, ['\v'] = 1, ['\f'] = 1,
260 /* table to tell if a character is horizontal or vertical space. */
261 U_CHAR is_space[256] =
263 [' '] = 1, ['\t'] = 1, ['\v'] = 1, ['\f'] = 1, ['\n'] = 1,
265 /* Table to handle trigraph conversion, which occurs before all other
266 processing, everywhere in the file. (This is necessary since one
267 of the trigraphs encodes backslash.) Note it's off by default.
269 from to from to from to
274 There is not a space between the ?? and the third char. I put spaces
275 there to avoid warnings when compiling this file. */
276 U_CHAR trigraph_table[256] =
278 ['='] = '#', [')'] = ']', ['!'] = '|',
279 ['('] = '[', ['\''] = '^', ['>'] = '}',
280 ['/'] = '\\', ['<'] = '{', ['-'] = '~',
283 /* This function will be entirely removed soon. */
285 initialize_char_syntax (dollar_in_ident)
288 is_idchar['$'] = dollar_in_ident;
289 is_idstart['$'] = dollar_in_ident;
294 U_CHAR is_idchar[256] = { 0 };
295 U_CHAR is_idstart[256] = { 0 };
296 U_CHAR is_hor_space[256] = { 0 };
297 U_CHAR is_space[256] = { 0 };
298 U_CHAR trigraph_table[256] = { 0 };
300 /* Initialize syntactic classifications of characters. */
302 initialize_char_syntax (dollar_in_ident)
305 is_idstart['a'] = 1; is_idstart['b'] = 1; is_idstart['c'] = 1;
306 is_idstart['d'] = 1; is_idstart['e'] = 1; is_idstart['f'] = 1;
307 is_idstart['g'] = 1; is_idstart['h'] = 1; is_idstart['i'] = 1;
308 is_idstart['j'] = 1; is_idstart['k'] = 1; is_idstart['l'] = 1;
309 is_idstart['m'] = 1; is_idstart['n'] = 1; is_idstart['o'] = 1;
310 is_idstart['p'] = 1; is_idstart['q'] = 1; is_idstart['r'] = 1;
311 is_idstart['s'] = 1; is_idstart['t'] = 1; is_idstart['u'] = 1;
312 is_idstart['v'] = 1; is_idstart['w'] = 1; is_idstart['x'] = 1;
313 is_idstart['y'] = 1; is_idstart['z'] = 1;
315 is_idstart['A'] = 1; is_idstart['B'] = 1; is_idstart['C'] = 1;
316 is_idstart['D'] = 1; is_idstart['E'] = 1; is_idstart['F'] = 1;
317 is_idstart['G'] = 1; is_idstart['H'] = 1; is_idstart['I'] = 1;
318 is_idstart['J'] = 1; is_idstart['K'] = 1; is_idstart['L'] = 1;
319 is_idstart['M'] = 1; is_idstart['N'] = 1; is_idstart['O'] = 1;
320 is_idstart['P'] = 1; is_idstart['Q'] = 1; is_idstart['R'] = 1;
321 is_idstart['S'] = 1; is_idstart['T'] = 1; is_idstart['U'] = 1;
322 is_idstart['V'] = 1; is_idstart['W'] = 1; is_idstart['X'] = 1;
323 is_idstart['Y'] = 1; is_idstart['Z'] = 1;
327 is_idchar['a'] = 1; is_idchar['b'] = 1; is_idchar['c'] = 1;
328 is_idchar['d'] = 1; is_idchar['e'] = 1; is_idchar['f'] = 1;
329 is_idchar['g'] = 1; is_idchar['h'] = 1; is_idchar['i'] = 1;
330 is_idchar['j'] = 1; is_idchar['k'] = 1; is_idchar['l'] = 1;
331 is_idchar['m'] = 1; is_idchar['n'] = 1; is_idchar['o'] = 1;
332 is_idchar['p'] = 1; is_idchar['q'] = 1; is_idchar['r'] = 1;
333 is_idchar['s'] = 1; is_idchar['t'] = 1; is_idchar['u'] = 1;
334 is_idchar['v'] = 1; is_idchar['w'] = 1; is_idchar['x'] = 1;
335 is_idchar['y'] = 1; is_idchar['z'] = 1;
337 is_idchar['A'] = 1; is_idchar['B'] = 1; is_idchar['C'] = 1;
338 is_idchar['D'] = 1; is_idchar['E'] = 1; is_idchar['F'] = 1;
339 is_idchar['G'] = 1; is_idchar['H'] = 1; is_idchar['I'] = 1;
340 is_idchar['J'] = 1; is_idchar['K'] = 1; is_idchar['L'] = 1;
341 is_idchar['M'] = 1; is_idchar['N'] = 1; is_idchar['O'] = 1;
342 is_idchar['P'] = 1; is_idchar['Q'] = 1; is_idchar['R'] = 1;
343 is_idchar['S'] = 1; is_idchar['T'] = 1; is_idchar['U'] = 1;
344 is_idchar['V'] = 1; is_idchar['W'] = 1; is_idchar['X'] = 1;
345 is_idchar['Y'] = 1; is_idchar['Z'] = 1;
347 is_idchar['1'] = 1; is_idchar['2'] = 1; is_idchar['3'] = 1;
348 is_idchar['4'] = 1; is_idchar['5'] = 1; is_idchar['6'] = 1;
349 is_idchar['7'] = 1; is_idchar['8'] = 1; is_idchar['9'] = 1;
354 is_idchar['$'] = dollar_in_ident;
355 is_idstart['$'] = dollar_in_ident;
357 /* white space tables */
358 is_hor_space[' '] = 1;
359 is_hor_space['\t'] = 1;
360 is_hor_space['\v'] = 1;
361 is_hor_space['\f'] = 1;
369 /* trigraph conversion */
370 trigraph_table['='] = '#'; trigraph_table[')'] = ']';
371 trigraph_table['!'] = '|'; trigraph_table['('] = '[';
372 trigraph_table['\''] = '^'; trigraph_table['>'] = '}';
373 trigraph_table['/'] = '\\'; trigraph_table['<'] = '{';
374 trigraph_table['-'] = '~';
377 #endif /* Not GCC. */
379 /* Given a colon-separated list of file names PATH,
380 add all the names to the search path for include files. */
383 path_include (pfile, pend, list, path)
385 struct cpp_pending *pend;
395 /* Find the end of this name. */
397 while (*q != 0 && *q != PATH_SEPARATOR) q++;
400 /* An empty name in the path stands for the current directory. */
401 name = (char *) xmalloc (2);
407 /* Otherwise use the directory that is named. */
408 name = (char *) xmalloc (q - p + 1);
409 memcpy (name, p, q - p);
413 append_include_chain (pfile, pend, name, path);
415 /* Advance past this name. */
423 /* Find the base name of a (partial) pathname FNAME.
424 Returns a pointer into the string passed in.
425 Accepts Unix (/-separated) paths on all systems,
426 DOS and VMS paths on those systems. */
431 char *s = (char *)fname;
433 #if defined (HAVE_DOS_BASED_FILE_SYSTEM)
434 if (ISALPHA (s[0]) && s[1] == ':') s += 2;
435 if ((p = rindex (s, '\\'))) s = p + 1;
437 if ((p = rindex (s, ':'))) s = p + 1; /* Skip device. */
438 if ((p = rindex (s, ']'))) s = p + 1; /* Skip directory. */
439 if ((p = rindex (s, '>'))) s = p + 1; /* Skip alternate (int'n'l) dir. */
441 if ((p = rindex (s, '/'))) s = p + 1;
446 /* Append DIR to include path PATH. DIR must be permanently allocated
449 append_include_chain (pfile, pend, dir, path)
451 struct cpp_pending *pend;
455 struct file_name_list *new;
459 simplify_pathname (dir);
462 /* Dirs that don't exist are silently ignored. */
464 cpp_perror_with_name (pfile, dir);
465 else if (CPP_OPTIONS (pfile)->verbose)
466 cpp_notice ("ignoring nonexistent directory `%s'\n", dir);
470 if (!S_ISDIR (st.st_mode))
472 cpp_message (pfile, 1, "%s: %s: Not a directory", progname, dir);
477 if (len > pfile->max_include_len)
478 pfile->max_include_len = len;
480 new = (struct file_name_list *)xmalloc (sizeof (struct file_name_list));
483 new->ino = st.st_ino;
484 new->dev = st.st_dev;
485 new->sysp = (path == SYSTEM);
486 new->name_map = NULL;
490 case QUOTE: APPEND (pend, quote, new); break;
491 case BRACKET: APPEND (pend, brack, new); break;
492 case SYSTEM: APPEND (pend, systm, new); break;
493 case AFTER: APPEND (pend, after, new); break;
498 /* Write out a #define command for the special named MACRO_NAME
499 to PFILE's token_buffer. */
502 dump_special_to_buffer (pfile, macro_name)
506 static char define_directive[] = "#define ";
507 int macro_name_length = strlen (macro_name);
508 output_line_command (pfile, same_file);
509 CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length);
510 CPP_PUTS_Q (pfile, define_directive, sizeof(define_directive)-1);
511 CPP_PUTS_Q (pfile, macro_name, macro_name_length);
512 CPP_PUTC_Q (pfile, ' ');
513 cpp_expand_to_buffer (pfile, macro_name, macro_name_length);
514 CPP_PUTC (pfile, '\n');
517 /* Initialize a cpp_options structure. */
519 cpp_options_init (opts)
522 bzero ((char *) opts, sizeof (struct cpp_options));
524 opts->dollars_in_ident = 1;
525 opts->cplusplus_comments = 1;
526 opts->warn_import = 1;
528 opts->pending = (struct cpp_pending *) xmalloc (sizeof (struct cpp_pending));
529 bzero ((char *) opts->pending, sizeof (struct cpp_pending));
532 /* Initialize a cpp_reader structure. */
534 cpp_reader_init (pfile)
537 bzero ((char *) pfile, sizeof (cpp_reader));
539 pfile->get_token = cpp_get_token;
542 pfile->token_buffer_size = 200;
543 pfile->token_buffer = (U_CHAR *) xmalloc (pfile->token_buffer_size);
544 CPP_SET_WRITTEN (pfile, 0);
546 pfile->hashtab = (HASHNODE **) xcalloc (HASHSIZE, sizeof (HASHNODE *));
549 /* Free resources used by PFILE.
550 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
556 while (CPP_BUFFER (pfile) != CPP_NULL_BUFFER (pfile))
557 cpp_pop_buffer (pfile);
559 if (pfile->token_buffer)
561 free (pfile->token_buffer);
562 pfile->token_buffer = NULL;
565 if (pfile->deps_buffer)
567 free (pfile->deps_buffer);
568 pfile->deps_buffer = NULL;
569 pfile->deps_allocated_size = 0;
572 if (pfile->input_buffer)
574 free (pfile->input_buffer);
575 free (pfile->input_speccase);
576 pfile->input_buffer = pfile->input_speccase = NULL;
577 pfile->input_buffer_len = 0;
580 while (pfile->if_stack)
582 IF_STACK_FRAME *temp = pfile->if_stack;
583 pfile->if_stack = temp->next;
587 for (i = ALL_INCLUDE_HASHSIZE; --i >= 0; )
589 struct include_hash *imp = pfile->all_include_files[i];
592 struct include_hash *next = imp->next;
594 /* This gets freed elsewhere - I think. */
600 pfile->all_include_files[i] = 0;
603 for (i = HASHSIZE; --i >= 0;)
605 while (pfile->hashtab[i])
606 delete_macro (pfile->hashtab[i]);
608 free (pfile->hashtab);
612 /* Initialize the built-in macros. */
614 initialize_builtins (pfile)
617 #define NAME(str) (U_CHAR *)str, sizeof str - 1
618 cpp_install (pfile, NAME("__TIME__"), T_TIME, 0, -1);
619 cpp_install (pfile, NAME("__DATE__"), T_DATE, 0, -1);
620 cpp_install (pfile, NAME("__FILE__"), T_FILE, 0, -1);
621 cpp_install (pfile, NAME("__BASE_FILE__"), T_BASE_FILE, 0, -1);
622 cpp_install (pfile, NAME("__LINE__"), T_SPECLINE, 0, -1);
623 cpp_install (pfile, NAME("__INCLUDE_LEVEL__"), T_INCLUDE_LEVEL, 0, -1);
624 cpp_install (pfile, NAME("__VERSION__"), T_VERSION, 0, -1);
625 #ifndef NO_BUILTIN_SIZE_TYPE
626 cpp_install (pfile, NAME("__SIZE_TYPE__"), T_CONST, SIZE_TYPE, -1);
628 #ifndef NO_BUILTIN_PTRDIFF_TYPE
629 cpp_install (pfile, NAME("__PTRDIFF_TYPE__ "), T_CONST, PTRDIFF_TYPE, -1);
631 cpp_install (pfile, NAME("__WCHAR_TYPE__"), T_CONST, WCHAR_TYPE, -1);
632 cpp_install (pfile, NAME("__USER_LABEL_PREFIX__"), T_CONST, user_label_prefix, -1);
633 cpp_install (pfile, NAME("__REGISTER_PREFIX__"), T_CONST, REGISTER_PREFIX, -1);
634 cpp_install (pfile, NAME("__HAVE_BUILTIN_SETJMP__"), T_CONST, "1", -1);
635 if (!CPP_TRADITIONAL (pfile))
637 cpp_install (pfile, NAME("__STDC__"), T_STDC, 0, -1);
639 if (CPP_OPTIONS (pfile)->c9x)
640 cpp_install (pfile, NAME("__STDC_VERSION__"),T_CONST, "199909L", -1);
643 cpp_install (pfile, NAME("__STDC_VERSION__"),T_CONST, "199409L", -1);
647 if (CPP_OPTIONS (pfile)->debug_output)
649 dump_special_to_buffer (pfile, "__BASE_FILE__");
650 dump_special_to_buffer (pfile, "__VERSION__");
651 #ifndef NO_BUILTIN_SIZE_TYPE
652 dump_special_to_buffer (pfile, "__SIZE_TYPE__");
654 #ifndef NO_BUILTIN_PTRDIFF_TYPE
655 dump_special_to_buffer (pfile, "__PTRDIFF_TYPE__");
657 dump_special_to_buffer (pfile, "__WCHAR_TYPE__");
658 dump_special_to_buffer (pfile, "__DATE__");
659 dump_special_to_buffer (pfile, "__TIME__");
660 if (!CPP_TRADITIONAL (pfile))
661 dump_special_to_buffer (pfile, "__STDC__");
665 /* Another subroutine of cpp_start_read. This one sets up to do
666 dependency-file output. */
668 initialize_dependency_output (pfile)
671 cpp_options *opts = CPP_OPTIONS (pfile);
672 char *spec, *s, *output_file;
674 /* Either of two environment variables can specify output of deps.
675 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
676 where OUTPUT_FILE is the file to write deps info to
677 and DEPS_TARGET is the target to mention in the deps. */
679 if (opts->print_deps == 0)
681 spec = getenv ("DEPENDENCIES_OUTPUT");
683 opts->print_deps = 1;
686 spec = getenv ("SUNPRO_DEPENDENCIES");
688 opts->print_deps = 2;
693 /* Find the space before the DEPS_TARGET, if there is one. */
694 s = strchr (spec, ' ');
697 opts->deps_target = s + 1;
698 output_file = (char *) xmalloc (s - spec + 1);
699 memcpy (output_file, spec, s - spec);
700 output_file[s - spec] = 0;
704 opts->deps_target = 0;
708 opts->deps_file = output_file;
709 opts->print_deps_append = 1;
712 /* Print the expected object file name as the target of this Make-rule. */
713 pfile->deps_allocated_size = 200;
714 pfile->deps_buffer = (char *) xmalloc (pfile->deps_allocated_size);
715 pfile->deps_buffer[0] = 0;
716 pfile->deps_size = 0;
717 pfile->deps_column = 0;
719 if (opts->deps_target)
720 deps_output (pfile, opts->deps_target, ':');
721 else if (*opts->in_fname == 0)
722 deps_output (pfile, "-", ':');
728 /* Discard all directory prefixes from filename. */
729 q = base_name (opts->in_fname);
731 /* Copy remainder to mungable area. */
733 p = (char *) alloca (len + 8);
736 /* Output P, but remove known suffixes. */
738 /* Point to the filename suffix. */
740 /* Compare against the known suffixes. */
741 for (x = 0; known_suffixes[x]; x++)
743 if (strncmp (known_suffixes[x], r, q - r) == 0)
745 /* Make q point to the bit we're going to overwrite
746 with an object suffix. */
752 /* Supply our own suffix. */
753 strcpy (q, OBJECT_SUFFIX);
755 deps_output (pfile, p, ':');
756 deps_output (pfile, opts->in_fname, ' ');
760 /* This is called after options have been processed.
761 * Check options for consistency, and setup for processing input
762 * from the file named FNAME. (Use standard input if FNAME==NULL.)
763 * Return 1 on success, 0 on failure.
767 cpp_start_read (pfile, fname)
771 struct cpp_options *opts = CPP_OPTIONS (pfile);
772 struct pending_option *p, *q;
775 struct include_hash *ih_fake;
777 /* -MG doesn't select the form of output and must be specified with one of
778 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
779 inhibit compilation. */
780 if (opts->print_deps_missing_files
781 && (opts->print_deps == 0 || !opts->no_output))
783 cpp_fatal (pfile, "-MG must be specified with one of -M or -MM");
787 /* Chill should not be used with -trigraphs. */
788 if (opts->chill && opts->trigraphs)
790 cpp_warning (pfile, "-lang-chill and -trigraphs are mutually exclusive");
794 /* Set this if it hasn't been set already. */
795 if (user_label_prefix == NULL)
796 user_label_prefix = USER_LABEL_PREFIX;
798 /* Now that we know dollars_in_ident, we can initialize the syntax
800 initialize_char_syntax (opts->dollars_in_ident);
802 /* Do partial setup of input buffer for the sake of generating
803 early #line directives (when -g is in effect). */
804 fp = cpp_push_buffer (pfile, NULL, 0);
807 if (opts->in_fname == NULL || *opts->in_fname == 0)
809 opts->in_fname = fname;
810 if (opts->in_fname == NULL)
813 fp->nominal_fname = fp->fname = opts->in_fname;
816 /* Install __LINE__, etc. Must follow initialize_char_syntax
817 and option processing. */
818 initialize_builtins (pfile);
820 /* Do -U's, -D's and -A's in the order they were seen. */
821 p = opts->pending->define_head;
824 if (opts->debug_output)
825 output_line_command (pfile, same_file);
827 cpp_undef (pfile, p->arg);
829 cpp_define (pfile, p->arg);
836 p = opts->pending->assert_head;
839 if (opts->debug_output)
840 output_line_command (pfile, same_file);
842 cpp_unassert (pfile, p->arg);
844 cpp_assert (pfile, p->arg);
851 opts->done_initializing = 1;
853 /* Several environment variables may add to the include search path.
854 CPATH specifies an additional list of directories to be searched
855 as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH,
856 etc. specify an additional list of directories to be searched as
857 if specified with -isystem, for the language indicated.
859 These variables are ignored if -nostdinc is on. */
860 if (! opts->no_standard_includes)
863 GET_ENV_PATH_LIST (path, "CPATH");
864 if (path != 0 && *path != 0)
865 path_include (pfile, opts->pending, path, BRACKET);
867 switch ((opts->objc << 1) + opts->cplusplus)
870 GET_ENV_PATH_LIST (path, "C_INCLUDE_PATH");
873 GET_ENV_PATH_LIST (path, "CPLUS_INCLUDE_PATH");
876 GET_ENV_PATH_LIST (path, "OBJC_INCLUDE_PATH");
879 GET_ENV_PATH_LIST (path, "OBJCPLUS_INCLUDE_PATH");
882 if (path != 0 && *path != 0)
883 path_include (pfile, opts->pending, path, SYSTEM);
886 /* Unless -nostdinc, add the compiled-in include path to the list,
887 translating prefixes. */
888 if (!opts->no_standard_includes)
890 struct default_include *p = include_defaults_array;
891 char *specd_prefix = opts->include_prefix;
893 /* Search "translated" versions of GNU directories.
894 These have /usr/local/lib/gcc... replaced by specd_prefix. */
895 if (specd_prefix != 0)
897 char *default_prefix = alloca (sizeof GCC_INCLUDE_DIR - 7);
898 /* Remove the `include' from /usr/local/lib/gcc.../include.
899 GCC_INCLUDE_DIR will always end in /include. */
900 int default_len = sizeof GCC_INCLUDE_DIR - 8;
901 int specd_len = strlen (specd_prefix);
903 default_len = sizeof GCC_INCLUDE_DIR - 8;
904 memcpy (default_prefix, GCC_INCLUDE_DIR, default_len);
905 default_prefix[default_len] = '\0';
907 for (p = include_defaults_array; p->fname; p++)
909 /* Some standard dirs are only for C++. */
912 && !opts->no_standard_cplusplus_includes))
914 /* Does this dir start with the prefix? */
915 if (!strncmp (p->fname, default_prefix, default_len))
917 /* Yes; change prefix and add to search list. */
918 int flen = strlen (p->fname);
919 int this_len = specd_len + flen - default_len;
920 char *str = (char *) xmalloc (this_len + 1);
921 memcpy (str, specd_prefix, specd_len);
922 memcpy (str + specd_len,
923 p->fname + default_len,
924 flen - default_len + 1);
926 append_include_chain (pfile, opts->pending,
933 /* Search ordinary names for GNU include directories. */
934 for (p = include_defaults_array; p->fname; p++)
936 /* Some standard dirs are only for C++. */
939 && !opts->no_standard_cplusplus_includes))
941 char *str = (char *) update_path (p->fname, p->component);
942 str = xstrdup (str); /* XXX Potential memory leak! */
943 append_include_chain (pfile, opts->pending, str, SYSTEM);
948 merge_include_chains (opts);
950 /* With -v, print the list of dirs to search. */
953 struct file_name_list *p;
954 cpp_message (pfile, -1, "#include \"...\" search starts here:\n");
955 for (p = opts->quote_include; p; p = p->next)
957 if (p == opts->bracket_include)
958 cpp_message (pfile, -1, "#include <...> search starts here:\n");
959 fprintf (stderr, " %s\n", p->name);
961 cpp_message (pfile, -1, "End of search list.\n");
964 /* Don't bother trying to do macro expansion if we've already done
966 if (opts->preprocessed)
967 pfile->no_macro_expand++;
969 /* Open the main input file.
970 We do this in nonblocking mode so we don't get stuck here if
971 someone clever has asked cpp to process /dev/rmt0;
972 finclude() will check that we have a real file to work with. */
973 if (fname == NULL || *fname == 0)
978 else if ((f = open (fname, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666)) < 0)
979 cpp_pfatal_with_name (pfile, fname);
981 initialize_dependency_output (pfile);
983 /* Must call finclude() on the main input before processing
984 -include switches; otherwise the -included text winds up
985 after the main input. */
986 ih_fake = (struct include_hash *) xmalloc (sizeof (struct include_hash));
988 ih_fake->next_this_file = 0;
989 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
990 ih_fake->name = fname;
991 ih_fake->control_macro = 0;
992 ih_fake->buf = (char *)-1;
994 if (!finclude (pfile, f, ih_fake))
996 if (opts->preprocessed)
997 /* If we've already processed this code, we want to trust the #line
998 directives in the input. But we still need to update our line
999 counter accordingly. */
1000 pfile->lineno = CPP_BUFFER (pfile)->lineno;
1002 output_line_command (pfile, same_file);
1003 pfile->only_seen_white = 2;
1005 /* The -imacros files can be scanned now, but the -include files
1006 have to be pushed onto the include stack and processed later,
1007 in the main loop calling cpp_get_token. */
1009 pfile->no_record_file++;
1011 p = opts->pending->imacros_head;
1014 int fd = open (p->arg, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666);
1017 cpp_perror_with_name (pfile, p->arg);
1020 if (!cpp_push_buffer (pfile, NULL, 0))
1023 ih_fake = (struct include_hash *)
1024 xmalloc (sizeof (struct include_hash));
1026 ih_fake->next_this_file = 0;
1027 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
1028 ih_fake->name = p->arg;
1029 ih_fake->control_macro = 0;
1030 ih_fake->buf = (char *)-1;
1032 if (finclude (pfile, fd, ih_fake))
1034 if (CPP_PRINT_DEPS (pfile))
1035 deps_output (pfile, ih_fake->name, ' ');
1037 cpp_scan_buffer (pfile);
1040 cpp_pop_buffer (pfile);
1050 p = opts->pending->include_head;
1053 int fd = open (p->arg, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666);
1056 cpp_perror_with_name (pfile, p->arg);
1059 if (!cpp_push_buffer (pfile, NULL, 0))
1062 ih_fake = (struct include_hash *)
1063 xmalloc (sizeof (struct include_hash));
1065 ih_fake->next_this_file = 0;
1066 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
1067 ih_fake->name = p->arg;
1068 ih_fake->control_macro = 0;
1069 ih_fake->buf = (char *)-1;
1071 if (finclude (pfile, fd, ih_fake))
1073 if (CPP_PRINT_DEPS (pfile))
1074 deps_output (pfile, ih_fake->name, ' ');
1076 output_line_command (pfile, enter_file);
1079 cpp_pop_buffer (pfile);
1084 pfile->no_record_file--;
1086 free (opts->pending);
1087 opts->pending = NULL;
1092 /* This is called at the end of preprocessing. It pops the
1093 last buffer and writes dependency output. It should also
1094 clear macro definitions, such that you could call cpp_start_read
1095 with a new filename to restart processing. */
1100 struct cpp_options *opts = CPP_OPTIONS (pfile);
1102 if (CPP_PREV_BUFFER (CPP_BUFFER (pfile)) != CPP_NULL_BUFFER (pfile))
1104 "cpplib internal error: buffers still stacked in cpp_finish");
1105 cpp_pop_buffer (pfile);
1107 if (opts->print_deps)
1109 /* Stream on which to print the dependency information. */
1112 /* Don't actually write the deps file if compilation has failed. */
1113 if (pfile->errors == 0)
1115 char *deps_mode = opts->print_deps_append ? "a" : "w";
1116 if (opts->deps_file == 0)
1117 deps_stream = stdout;
1118 else if ((deps_stream = fopen (opts->deps_file, deps_mode)) == 0)
1119 cpp_pfatal_with_name (pfile, opts->deps_file);
1120 fputs (pfile->deps_buffer, deps_stream);
1121 putc ('\n', deps_stream);
1122 if (opts->deps_file)
1124 if (ferror (deps_stream) || fclose (deps_stream) != 0)
1125 cpp_fatal (pfile, "I/O error on output");
1130 if (opts->dump_macros == dump_only)
1135 for (i = HASHSIZE; --i >= 0;)
1137 for (h = pfile->hashtab[i]; h; h = h->next)
1138 if (h->type == T_MACRO)
1140 m.defn = h->value.defn;
1142 m.symlen = h->length;
1143 dump_definition (pfile, m);
1144 CPP_PUTC (pfile, '\n');
1150 /* Handle one command-line option in (argc, argv).
1151 Can be called multiple times, to handle multiple sets of options.
1152 Returns number of strings consumed. */
1154 cpp_handle_option (pfile, argc, argv)
1159 struct cpp_options *opts = CPP_OPTIONS (pfile);
1162 if (argv[i][0] != '-')
1164 if (opts->out_fname != NULL)
1167 cpp_fatal (pfile, "Too many arguments");
1169 else if (opts->in_fname != NULL)
1170 opts->out_fname = argv[i];
1172 opts->in_fname = argv[i];
1178 if (!strcmp (argv[i], "-fleading-underscore"))
1179 user_label_prefix = "_";
1180 else if (!strcmp (argv[i], "-fno-leading-underscore"))
1181 user_label_prefix = "";
1182 else if (!strcmp (argv[i], "-fpreprocessed"))
1183 opts->preprocessed = 1;
1184 else if (!strcmp (argv[i], "-fno-preprocessed"))
1185 opts->preprocessed = 0;
1188 case 'I': /* Add directory to path for includes. */
1189 if (!strcmp (argv[i] + 2, "-"))
1192 Use the preceding -I directories for #include "..."
1193 but not #include <...>.
1194 Don't search the directory of the present file
1195 for #include "...". (Note that -I. -I- is not the same as
1196 the default setup; -I. uses the compiler's working dir.) */
1197 if (! opts->ignore_srcdir)
1199 opts->ignore_srcdir = 1;
1200 opts->pending->quote_head = opts->pending->brack_head;
1201 opts->pending->quote_tail = opts->pending->brack_tail;
1202 opts->pending->brack_head = 0;
1203 opts->pending->brack_tail = 0;
1207 cpp_fatal (pfile, "-I- specified twice");
1214 if (argv[i][2] != 0)
1215 fname = argv[i] + 2;
1216 else if (i + 1 == argc)
1217 goto missing_dirname;
1220 append_include_chain (pfile, opts->pending,
1221 xstrdup (fname), BRACKET);
1226 /* Add directory to beginning of system include path, as a system
1227 include directory. */
1228 if (!strcmp (argv[i], "-isystem"))
1231 goto missing_filename;
1232 append_include_chain (pfile, opts->pending,
1233 xstrdup (argv[++i]), SYSTEM);
1235 else if (!strcmp (argv[i], "-include"))
1238 goto missing_filename;
1241 struct pending_option *o = (struct pending_option *)
1242 xmalloc (sizeof (struct pending_option));
1245 /* This list has to be built in reverse order so that
1246 when cpp_start_read pushes all the -include files onto
1247 the buffer stack, they will be scanned in forward order. */
1248 o->next = opts->pending->include_head;
1249 opts->pending->include_head = o;
1252 else if (!strcmp (argv[i], "-imacros"))
1255 goto missing_filename;
1258 struct pending_option *o = (struct pending_option *)
1259 xmalloc (sizeof (struct pending_option));
1263 APPEND (opts->pending, imacros, o);
1266 /* Add directory to end of path for includes,
1267 with the default prefix at the front of its name. */
1268 else if (!strcmp (argv[i], "-iwithprefix"))
1273 goto missing_dirname;
1275 len = strlen (argv[i]);
1277 if (opts->include_prefix != 0)
1279 fname = xmalloc (opts->include_prefix_len + len + 1);
1280 memcpy (fname, opts->include_prefix, opts->include_prefix_len);
1281 memcpy (fname + opts->include_prefix_len, argv[i], len + 1);
1285 fname = xmalloc (sizeof GCC_INCLUDE_DIR - 8 + len);
1286 memcpy (fname, GCC_INCLUDE_DIR, sizeof GCC_INCLUDE_DIR - 9);
1287 memcpy (fname + sizeof GCC_INCLUDE_DIR - 9, argv[i], len + 1);
1290 append_include_chain (pfile, opts->pending, fname, SYSTEM);
1292 /* Add directory to main path for includes,
1293 with the default prefix at the front of its name. */
1294 else if (!strcmp (argv[i], "-iwithprefixbefore"))
1299 goto missing_dirname;
1301 len = strlen (argv[i]);
1303 if (opts->include_prefix != 0)
1305 fname = xmalloc (opts->include_prefix_len + len + 1);
1306 memcpy (fname, opts->include_prefix, opts->include_prefix_len);
1307 memcpy (fname + opts->include_prefix_len, argv[i], len + 1);
1311 fname = xmalloc (sizeof GCC_INCLUDE_DIR - 8 + len);
1312 memcpy (fname, GCC_INCLUDE_DIR, sizeof GCC_INCLUDE_DIR - 9);
1313 memcpy (fname + sizeof GCC_INCLUDE_DIR - 9, argv[i], len + 1);
1316 append_include_chain (pfile, opts->pending, fname, BRACKET);
1318 /* Add directory to end of path for includes. */
1319 else if (!strcmp (argv[i], "-idirafter"))
1322 goto missing_dirname;
1323 append_include_chain (pfile, opts->pending,
1324 xstrdup (argv[++i]), AFTER);
1326 else if (!strcmp (argv[i], "-iprefix"))
1329 goto missing_filename;
1332 opts->include_prefix = argv[++i];
1333 opts->include_prefix_len = strlen (argv[i]);
1336 else if (!strcmp (argv[i], "-ifoutput"))
1337 opts->output_conditionals = 1;
1342 if (opts->out_fname != NULL)
1344 cpp_fatal (pfile, "Output filename specified twice");
1348 goto missing_filename;
1349 opts->out_fname = argv[++i];
1350 if (!strcmp (opts->out_fname, "-"))
1351 opts->out_fname = "";
1355 if (!strcmp (argv[i], "-pedantic"))
1356 CPP_PEDANTIC (pfile) = 1;
1357 else if (!strcmp (argv[i], "-pedantic-errors"))
1359 CPP_PEDANTIC (pfile) = 1;
1360 opts->pedantic_errors = 1;
1363 else if (!strcmp (argv[i], "-pcp")) {
1364 char *pcp_fname = argv[++i];
1365 pcp_outfile = ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
1366 ? fopen (pcp_fname, "w")
1367 : fdopen (dup (fileno (stdout)), "w"));
1368 if (pcp_outfile == 0)
1369 cpp_pfatal_with_name (pfile, pcp_fname);
1376 if (!strcmp (argv[i], "-traditional"))
1378 opts->traditional = 1;
1379 opts->cplusplus_comments = 0;
1381 else if (!strcmp (argv[i], "-trigraphs"))
1382 opts->trigraphs = 1;
1386 if (! strcmp (argv[i], "-lang-c"))
1387 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
1388 opts->c9x = 1, opts->objc = 0;
1389 if (! strcmp (argv[i], "-lang-c89"))
1390 opts->cplusplus = 0, opts->cplusplus_comments = 0, opts->c89 = 1,
1391 opts->c9x = 0, opts->objc = 0;
1392 if (! strcmp (argv[i], "-lang-c++"))
1393 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0,
1394 opts->c9x = 0, opts->objc = 0;
1395 if (! strcmp (argv[i], "-lang-objc"))
1396 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
1397 opts->c9x = 0, opts->objc = 1;
1398 if (! strcmp (argv[i], "-lang-objc++"))
1399 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0,
1400 opts->c9x = 0, opts->objc = 1;
1401 if (! strcmp (argv[i], "-lang-asm"))
1403 if (! strcmp (argv[i], "-lint"))
1405 if (! strcmp (argv[i], "-lang-chill"))
1406 opts->objc = 0, opts->cplusplus = 0, opts->chill = 1,
1407 opts->traditional = 1;
1411 opts->cplusplus = 1, opts->cplusplus_comments = 1;
1415 if (!strcmp (argv[i], "-std=iso9899:1990")
1416 || !strcmp (argv[i], "-std=iso9899:199409")
1417 || !strcmp (argv[i], "-std=c89")
1418 || !strcmp (argv[i], "-std=gnu89"))
1419 opts->cplusplus = 0, opts->cplusplus_comments = 0,
1420 opts->c89 = 1, opts->c9x = 0, opts->objc = 0;
1421 else if (!strcmp (argv[i], "-std=iso9899:199x")
1422 || !strcmp (argv[i], "-std=c9x")
1423 || !strcmp (argv[i], "-std=gnu9x"))
1424 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
1425 opts->c9x = 1, opts->objc = 0;
1429 opts->inhibit_warnings = 1;
1433 if (!strcmp (argv[i], "-Wtrigraphs"))
1434 opts->warn_trigraphs = 1;
1435 else if (!strcmp (argv[i], "-Wno-trigraphs"))
1436 opts->warn_trigraphs = 0;
1437 else if (!strcmp (argv[i], "-Wcomment"))
1438 opts->warn_comments = 1;
1439 else if (!strcmp (argv[i], "-Wno-comment"))
1440 opts->warn_comments = 0;
1441 else if (!strcmp (argv[i], "-Wcomments"))
1442 opts->warn_comments = 1;
1443 else if (!strcmp (argv[i], "-Wno-comments"))
1444 opts->warn_comments = 0;
1445 else if (!strcmp (argv[i], "-Wtraditional"))
1446 opts->warn_stringify = 1;
1447 else if (!strcmp (argv[i], "-Wno-traditional"))
1448 opts->warn_stringify = 0;
1449 else if (!strcmp (argv[i], "-Wundef"))
1450 opts->warn_undef = 1;
1451 else if (!strcmp (argv[i], "-Wno-undef"))
1452 opts->warn_undef = 0;
1453 else if (!strcmp (argv[i], "-Wimport"))
1454 opts->warn_import = 1;
1455 else if (!strcmp (argv[i], "-Wno-import"))
1456 opts->warn_import = 0;
1457 else if (!strcmp (argv[i], "-Werror"))
1458 opts->warnings_are_errors = 1;
1459 else if (!strcmp (argv[i], "-Wno-error"))
1460 opts->warnings_are_errors = 0;
1461 else if (!strcmp (argv[i], "-Wall"))
1463 opts->warn_trigraphs = 1;
1464 opts->warn_comments = 1;
1469 /* The style of the choices here is a bit mixed.
1470 The chosen scheme is a hybrid of keeping all options in one string
1471 and specifying each option in a separate argument:
1472 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
1473 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
1474 -M[M][G][D file]. This is awkward to handle in specs, and is not
1476 /* ??? -MG must be specified in addition to one of -M or -MM.
1477 This can be relaxed in the future without breaking anything.
1478 The converse isn't true. */
1480 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
1481 if (!strcmp (argv[i], "-MG"))
1483 opts->print_deps_missing_files = 1;
1486 if (!strcmp (argv[i], "-M"))
1487 opts->print_deps = 2;
1488 else if (!strcmp (argv[i], "-MM"))
1489 opts->print_deps = 1;
1490 else if (!strcmp (argv[i], "-MD"))
1491 opts->print_deps = 2;
1492 else if (!strcmp (argv[i], "-MMD"))
1493 opts->print_deps = 1;
1494 /* For -MD and -MMD options, write deps on file named by next arg. */
1495 if (!strcmp (argv[i], "-MD") || !strcmp (argv[i], "-MMD"))
1498 goto missing_filename;
1499 opts->deps_file = argv[++i];
1503 /* For -M and -MM, write deps on standard output
1504 and suppress the usual output. */
1505 opts->no_output = 1;
1511 char *p = argv[i] + 2;
1513 while ((c = *p++) != 0)
1515 /* Arg to -d specifies what parts of macros to dump */
1519 opts->dump_macros = dump_only;
1520 opts->no_output = 1;
1523 opts->dump_macros = dump_names;
1526 opts->dump_macros = dump_definitions;
1529 opts->dump_includes = 1;
1537 if (argv[i][2] == '3')
1538 opts->debug_output = 1;
1542 if (!strcmp (argv[i], "--help"))
1544 else if (!strcmp (argv[i], "--version"))
1545 cpp_notice ("GNU CPP version %s\n", version_string);
1550 cpp_notice ("GNU CPP version %s", version_string);
1551 #ifdef TARGET_VERSION
1554 fputc ('\n', stderr);
1559 opts->print_include_names = 1;
1564 struct pending_option *o = (struct pending_option *)
1565 xmalloc (sizeof (struct pending_option));
1566 if (argv[i][2] != 0)
1567 o->arg = argv[i] + 2;
1568 else if (i + 1 == argc)
1570 cpp_fatal (pfile, "Macro name missing after -D option");
1578 APPEND (opts->pending, define, o);
1586 if (argv[i][2] != 0)
1588 else if (i + 1 == argc)
1590 cpp_fatal (pfile, "Assertion missing after -A option");
1596 if (strcmp (p, "-"))
1598 struct pending_option *o = (struct pending_option *)
1599 xmalloc (sizeof (struct pending_option));
1604 APPEND (opts->pending, assert, o);
1608 /* -A- eliminates all predefined macros and assertions.
1609 Let's include also any that were specified earlier
1610 on the command line. That way we can get rid of any
1611 that were passed automatically in from GCC. */
1612 struct pending_option *o1, *o2;
1614 o1 = opts->pending->define_head;
1621 o1 = opts->pending->assert_head;
1628 opts->pending->assert_head = NULL;
1629 opts->pending->assert_tail = NULL;
1630 opts->pending->define_head = NULL;
1631 opts->pending->define_tail = NULL;
1638 struct pending_option *o = (struct pending_option *)
1639 xmalloc (sizeof (struct pending_option));
1641 if (argv[i][2] != 0)
1642 o->arg = argv[i] + 2;
1643 else if (i + 1 == argc)
1645 cpp_fatal (pfile, "Macro name missing after -U option");
1653 APPEND (opts->pending, define, o);
1658 opts->put_out_comments = 1;
1661 case 'E': /* -E comes from cc -E; ignore it. */
1665 opts->no_line_commands = 1;
1668 case '$': /* Don't include $ in identifiers. */
1669 opts->dollars_in_ident = 0;
1673 if (!strcmp (argv[i], "-nostdinc"))
1674 /* -nostdinc causes no default include directories.
1675 You must specify all include-file directories with -I. */
1676 opts->no_standard_includes = 1;
1677 else if (!strcmp (argv[i], "-nostdinc++"))
1678 /* -nostdinc++ causes no default C++-specific include directories. */
1679 opts->no_standard_cplusplus_includes = 1;
1681 else if (!strcmp (argv[i], "-noprecomp"))
1687 if (!strcmp (argv[i], "-remap"))
1691 case '\0': /* JF handle '-' as file name meaning stdin or stdout */
1692 if (opts->in_fname == NULL)
1693 opts->in_fname = "";
1694 else if (opts->out_fname == NULL)
1695 opts->out_fname = "";
1697 return i; /* error */
1707 cpp_fatal (pfile, "Filename missing after `%s' option", argv[i]);
1710 cpp_fatal (pfile, "Directory name missing after `%s' option", argv[i]);
1714 /* Handle command-line options in (argc, argv).
1715 Can be called multiple times, to handle multiple sets of options.
1716 Returns if an unrecognized option is seen.
1717 Returns number of strings consumed. */
1720 cpp_handle_options (pfile, argc, argv)
1726 int strings_processed;
1727 for (i = 0; i < argc; i += strings_processed)
1729 strings_processed = cpp_handle_option (pfile, argc - i, argv + i);
1730 if (strings_processed == 0)
1739 cpp_notice ("Usage: %s [switches] input output\n", progname);
1742 -include <file> Include the contents of <file> before other files\n\
1743 -imacros <file> Accept definition of macros in <file>\n\
1744 -iprefix <path> Specify <path> as a prefix for next two options\n\
1745 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1746 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1747 -isystem <dir> Add <dir> to the start of the system include path\n\
1748 -idirafter <dir> Add <dir> to the end of the system include path\n\
1749 -I <dir> Add <dir> to the end of the main include path\n\
1750 -nostdinc Do not search system include directories\n\
1751 (dirs specified with -isystem will still be used)\n\
1752 -nostdinc++ Do not search system include directories for C++\n\
1753 -o <file> Put output into <file>\n\
1754 -pedantic Issue all warnings demanded by strict ANSI C\n\
1755 -traditional Follow K&R pre-processor behaviour\n\
1756 -trigraphs Support ANSI C trigraphs\n\
1757 -lang-c Assume that the input sources are in C\n\
1758 -lang-c89 Assume that the input sources are in C89\n\
1759 -lang-c++ Assume that the input sources are in C++\n\
1760 -lang-objc Assume that the input sources are in ObjectiveC\n\
1761 -lang-objc++ Assume that the input sources are in ObjectiveC++\n\
1762 -lang-asm Assume that the input sources are in assembler\n\
1763 -lang-chill Assume that the input sources are in Chill\n\
1764 -std=<std name> Specify the conformance standard; one of:\n\
1765 gnu89, gnu9x, c89, c9x, iso9899:1990,\n\
1766 iso9899:199409, iso9899:199x\n\
1767 -+ Allow parsing of C++ style features\n\
1768 -w Inhibit warning messages\n\
1769 -Wtrigraphs Warn if trigraphs are encountered\n\
1770 -Wno-trigraphs Do not warn about trigraphs\n\
1771 -Wcomment{s} Warn if one comment starts inside another\n\
1772 -Wno-comment{s} Do not warn about comments\n\
1773 -Wtraditional Warn if a macro argument is/would be turned into\n\
1774 a string if -traditional is specified\n\
1775 -Wno-traditional Do not warn about stringification\n\
1776 -Wundef Warn if an undefined macro is used by #if\n\
1777 -Wno-undef Do not warn about testing undefined macros\n\
1778 -Wimport Warn about the use of the #import directive\n\
1779 -Wno-import Do not warn about the use of #import\n\
1780 -Werror Treat all warnings as errors\n\
1781 -Wno-error Do not treat warnings as errors\n\
1782 -Wall Enable all preprocessor warnings\n\
1783 -M Generate make dependencies\n\
1784 -MM As -M, but ignore system header files\n\
1785 -MD As -M, but put output in a .d file\n\
1786 -MMD As -MD, but ignore system header files\n\
1787 -MG Treat missing header file as generated files\n\
1788 -g Include #define and #undef directives in the output\n\
1789 -D<macro> Define a <macro> with string '1' as its value\n\
1790 -D<macro>=<val> Define a <macro> with <val> as its value\n\
1791 -A<question> (<answer>) Assert the <answer> to <question>\n\
1792 -U<macro> Undefine <macro> \n\
1793 -v Display the version number\n\
1794 -H Print the name of header files as they are used\n\
1795 -C Do not discard comments\n\
1796 -dM Display a list of macro definitions active at end\n\
1797 -dD Preserve macro definitions in output\n\
1798 -dN As -dD except that only the names are preserved\n\
1799 -dI Include #include directives in the output\n\
1800 -ifoutput Describe skipped code blocks in output \n\
1801 -P Do not generate #line directives\n\
1802 -$ Do not allow '$' in identifiers\n\
1803 -remap Remap file names when including files.\n\
1804 -h or --help Display this information\n\