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. */
32 /* XXX Should be in a header file. */
33 extern char *version_string;
35 /* Predefined symbols, built-in macros, and the default include path. */
37 #ifndef GET_ENV_PATH_LIST
38 #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
41 /* By default, colon separates directories in a path. */
42 #ifndef PATH_SEPARATOR
43 #define PATH_SEPARATOR ':'
46 #ifndef STANDARD_INCLUDE_DIR
47 #define STANDARD_INCLUDE_DIR "/usr/include"
50 /* We let tm.h override the types used here, to handle trivial differences
51 such as the choice of unsigned int or long unsigned int for size_t.
52 When machines start needing nontrivial differences in the size type,
53 it would be best to do something here to figure out automatically
54 from other information what type to use. */
56 /* The string value for __SIZE_TYPE__. */
59 #define SIZE_TYPE "long unsigned int"
62 /* The string value for __PTRDIFF_TYPE__. */
65 #define PTRDIFF_TYPE "long int"
68 /* The string value for __WCHAR_TYPE__. */
71 #define WCHAR_TYPE "int"
73 #define CPP_WCHAR_TYPE(PFILE) \
74 (CPP_OPTIONS (PFILE)->cplusplus ? "__wchar_t" : WCHAR_TYPE)
76 /* The string value for __USER_LABEL_PREFIX__ */
78 #ifndef USER_LABEL_PREFIX
79 #define USER_LABEL_PREFIX ""
82 /* The string value for __REGISTER_PREFIX__ */
84 #ifndef REGISTER_PREFIX
85 #define REGISTER_PREFIX ""
88 /* Suffix for object files, and known input-file extensions. */
89 static char *known_suffixes[] =
91 ".c", ".C", ".s", ".S", ".m",
92 ".cc", ".cxx", ".cpp", ".cp", ".c++",
98 # define OBJECT_SUFFIX ".obj"
100 # define OBJECT_SUFFIX ".o"
105 /* This is the default list of directories to search for include files.
106 It may be overridden by the various -I and -ixxx options.
108 #include "file" looks in the same directory as the current file,
110 #include <file> just looks in this list.
112 All these directories are treated as `system' include directories
113 (they are not subject to pedantic warnings in some cases). */
115 static struct default_include
117 char *fname; /* The name of the directory. */
118 char *component; /* The component containing the directory
119 (see update_path in prefix.c) */
120 int cplusplus; /* Only look here if we're compiling C++. */
121 int cxx_aware; /* Includes in this directory don't need to
122 be wrapped in extern "C" when compiling
123 C++. This is not used anymore. */
125 include_defaults_array[]
126 #ifdef INCLUDE_DEFAULTS
130 /* Pick up GNU C++ specific include files. */
131 { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 },
133 /* This is the dir for fixincludes. Put it just before
134 the files that we fix. */
135 { GCC_INCLUDE_DIR, "GCC", 0, 0 },
136 /* For cross-compilation, this dir name is generated
137 automatically in Makefile.in. */
138 { CROSS_INCLUDE_DIR, "GCC", 0, 0 },
139 #ifdef TOOL_INCLUDE_DIR
140 /* This is another place that the target system's headers might be. */
141 { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
143 #else /* not CROSS_COMPILE */
144 #ifdef LOCAL_INCLUDE_DIR
145 /* This should be /usr/local/include and should come before
146 the fixincludes-fixed header files. */
147 { LOCAL_INCLUDE_DIR, 0, 0, 1 },
149 #ifdef TOOL_INCLUDE_DIR
150 /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
151 Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
152 { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
154 /* This is the dir for fixincludes. Put it just before
155 the files that we fix. */
156 { GCC_INCLUDE_DIR, "GCC", 0, 0 },
157 /* Some systems have an extra dir of include files. */
158 #ifdef SYSTEM_INCLUDE_DIR
159 { SYSTEM_INCLUDE_DIR, 0, 0, 0 },
161 #ifndef STANDARD_INCLUDE_COMPONENT
162 #define STANDARD_INCLUDE_COMPONENT 0
164 { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0 },
165 #endif /* not CROSS_COMPILE */
168 #endif /* no INCLUDE_DEFAULTS */
170 /* Internal structures and prototypes. */
172 /* A `struct pending_option' remembers one -D, -A, -U, -include, or -imacros
173 switch. There are four lists: one for -D and -U, one for -A, one
174 for -include, one for -imacros. `undef' is set for -U, clear for
175 -D, ignored for the others.
176 (Future: add an equivalent of -U for -A) */
177 struct pending_option
179 struct pending_option *next;
185 #define APPEND(pend, list, elt) \
186 do { if (!(pend)->list##_head) (pend)->list##_head = (elt); \
187 else (pend)->list##_tail->next = (elt); \
188 (pend)->list##_tail = (elt); \
191 #define APPEND(pend, list, elt) \
192 do { if (!(pend)->list/**/_head) (pend)->list/**/_head = (elt); \
193 else (pend)->list/**/_tail->next = (elt); \
194 (pend)->list/**/_tail = (elt); \
198 static void initialize_char_syntax PARAMS ((int));
199 static void print_help PARAMS ((void));
200 static void path_include PARAMS ((cpp_reader *,
201 struct cpp_pending *,
203 static void initialize_builtins PARAMS ((cpp_reader *));
204 static void append_include_chain PARAMS ((cpp_reader *,
205 struct cpp_pending *,
208 /* Last argument to append_include_chain: chain to use */
209 enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
211 /* If gcc is in use (stage2/stage3) we can make these tables initialized
213 #if defined __GNUC__ && (__GNUC__ > 2 \
214 || (__GNUC__ == 2 && __GNUC_MINOR__ > 8))
215 /* Table to tell if a character is legal as the second or later character
216 of a C identifier. */
217 U_CHAR is_idchar[256] =
219 ['a'] = 1, ['b'] = 1, ['c'] = 1, ['d'] = 1, ['e'] = 1, ['f'] = 1,
220 ['g'] = 1, ['h'] = 1, ['i'] = 1, ['j'] = 1, ['k'] = 1, ['l'] = 1,
221 ['m'] = 1, ['n'] = 1, ['o'] = 1, ['p'] = 1, ['q'] = 1, ['r'] = 1,
222 ['s'] = 1, ['t'] = 1, ['u'] = 1, ['v'] = 1, ['w'] = 1, ['x'] = 1,
223 ['y'] = 1, ['z'] = 1,
225 ['A'] = 1, ['B'] = 1, ['C'] = 1, ['D'] = 1, ['E'] = 1, ['F'] = 1,
226 ['G'] = 1, ['H'] = 1, ['I'] = 1, ['J'] = 1, ['K'] = 1, ['L'] = 1,
227 ['M'] = 1, ['N'] = 1, ['O'] = 1, ['P'] = 1, ['Q'] = 1, ['R'] = 1,
228 ['S'] = 1, ['T'] = 1, ['U'] = 1, ['V'] = 1, ['W'] = 1, ['X'] = 1,
229 ['Y'] = 1, ['Z'] = 1,
231 ['1'] = 1, ['2'] = 1, ['3'] = 1, ['4'] = 1, ['5'] = 1, ['6'] = 1,
232 ['7'] = 1, ['8'] = 1, ['9'] = 1, ['0'] = 1,
237 /* Table to tell if a character is legal as the first character of
239 U_CHAR is_idstart[256] =
241 ['a'] = 1, ['b'] = 1, ['c'] = 1, ['d'] = 1, ['e'] = 1, ['f'] = 1,
242 ['g'] = 1, ['h'] = 1, ['i'] = 1, ['j'] = 1, ['k'] = 1, ['l'] = 1,
243 ['m'] = 1, ['n'] = 1, ['o'] = 1, ['p'] = 1, ['q'] = 1, ['r'] = 1,
244 ['s'] = 1, ['t'] = 1, ['u'] = 1, ['v'] = 1, ['w'] = 1, ['x'] = 1,
245 ['y'] = 1, ['z'] = 1,
247 ['A'] = 1, ['B'] = 1, ['C'] = 1, ['D'] = 1, ['E'] = 1, ['F'] = 1,
248 ['G'] = 1, ['H'] = 1, ['I'] = 1, ['J'] = 1, ['K'] = 1, ['L'] = 1,
249 ['M'] = 1, ['N'] = 1, ['O'] = 1, ['P'] = 1, ['Q'] = 1, ['R'] = 1,
250 ['S'] = 1, ['T'] = 1, ['U'] = 1, ['V'] = 1, ['W'] = 1, ['X'] = 1,
251 ['Y'] = 1, ['Z'] = 1,
256 /* Table to tell if a character is horizontal space.
257 \r is magical, so it is not in here. */
258 U_CHAR is_hor_space[256] =
260 [' '] = 1, ['\t'] = 1, ['\v'] = 1, ['\f'] = 1,
262 /* table to tell if a character is horizontal or vertical space. */
263 U_CHAR is_space[256] =
265 [' '] = 1, ['\t'] = 1, ['\v'] = 1, ['\f'] = 1, ['\n'] = 1,
267 /* Table to handle trigraph conversion, which occurs before all other
268 processing, everywhere in the file. (This is necessary since one
269 of the trigraphs encodes backslash.) Note it's off by default.
271 from to from to from to
276 There is not a space between the ?? and the third char. I put spaces
277 there to avoid warnings when compiling this file. */
278 U_CHAR trigraph_table[256] =
280 ['='] = '#', [')'] = ']', ['!'] = '|',
281 ['('] = '[', ['\''] = '^', ['>'] = '}',
282 ['/'] = '\\', ['<'] = '{', ['-'] = '~',
285 /* This function will be entirely removed soon. */
287 initialize_char_syntax (dollar_in_ident)
290 is_idchar['$'] = dollar_in_ident;
291 is_idstart['$'] = dollar_in_ident;
296 U_CHAR is_idchar[256] = { 0 };
297 U_CHAR is_idstart[256] = { 0 };
298 U_CHAR is_hor_space[256] = { 0 };
299 U_CHAR is_space[256] = { 0 };
300 U_CHAR trigraph_table[256] = { 0 };
302 /* Initialize syntactic classifications of characters. */
304 initialize_char_syntax (dollar_in_ident)
307 is_idstart['a'] = 1; is_idstart['b'] = 1; is_idstart['c'] = 1;
308 is_idstart['d'] = 1; is_idstart['e'] = 1; is_idstart['f'] = 1;
309 is_idstart['g'] = 1; is_idstart['h'] = 1; is_idstart['i'] = 1;
310 is_idstart['j'] = 1; is_idstart['k'] = 1; is_idstart['l'] = 1;
311 is_idstart['m'] = 1; is_idstart['n'] = 1; is_idstart['o'] = 1;
312 is_idstart['p'] = 1; is_idstart['q'] = 1; is_idstart['r'] = 1;
313 is_idstart['s'] = 1; is_idstart['t'] = 1; is_idstart['u'] = 1;
314 is_idstart['v'] = 1; is_idstart['w'] = 1; is_idstart['x'] = 1;
315 is_idstart['y'] = 1; is_idstart['z'] = 1;
317 is_idstart['A'] = 1; is_idstart['B'] = 1; is_idstart['C'] = 1;
318 is_idstart['D'] = 1; is_idstart['E'] = 1; is_idstart['F'] = 1;
319 is_idstart['G'] = 1; is_idstart['H'] = 1; is_idstart['I'] = 1;
320 is_idstart['J'] = 1; is_idstart['K'] = 1; is_idstart['L'] = 1;
321 is_idstart['M'] = 1; is_idstart['N'] = 1; is_idstart['O'] = 1;
322 is_idstart['P'] = 1; is_idstart['Q'] = 1; is_idstart['R'] = 1;
323 is_idstart['S'] = 1; is_idstart['T'] = 1; is_idstart['U'] = 1;
324 is_idstart['V'] = 1; is_idstart['W'] = 1; is_idstart['X'] = 1;
325 is_idstart['Y'] = 1; is_idstart['Z'] = 1;
329 is_idchar['a'] = 1; is_idchar['b'] = 1; is_idchar['c'] = 1;
330 is_idchar['d'] = 1; is_idchar['e'] = 1; is_idchar['f'] = 1;
331 is_idchar['g'] = 1; is_idchar['h'] = 1; is_idchar['i'] = 1;
332 is_idchar['j'] = 1; is_idchar['k'] = 1; is_idchar['l'] = 1;
333 is_idchar['m'] = 1; is_idchar['n'] = 1; is_idchar['o'] = 1;
334 is_idchar['p'] = 1; is_idchar['q'] = 1; is_idchar['r'] = 1;
335 is_idchar['s'] = 1; is_idchar['t'] = 1; is_idchar['u'] = 1;
336 is_idchar['v'] = 1; is_idchar['w'] = 1; is_idchar['x'] = 1;
337 is_idchar['y'] = 1; is_idchar['z'] = 1;
339 is_idchar['A'] = 1; is_idchar['B'] = 1; is_idchar['C'] = 1;
340 is_idchar['D'] = 1; is_idchar['E'] = 1; is_idchar['F'] = 1;
341 is_idchar['G'] = 1; is_idchar['H'] = 1; is_idchar['I'] = 1;
342 is_idchar['J'] = 1; is_idchar['K'] = 1; is_idchar['L'] = 1;
343 is_idchar['M'] = 1; is_idchar['N'] = 1; is_idchar['O'] = 1;
344 is_idchar['P'] = 1; is_idchar['Q'] = 1; is_idchar['R'] = 1;
345 is_idchar['S'] = 1; is_idchar['T'] = 1; is_idchar['U'] = 1;
346 is_idchar['V'] = 1; is_idchar['W'] = 1; is_idchar['X'] = 1;
347 is_idchar['Y'] = 1; is_idchar['Z'] = 1;
349 is_idchar['1'] = 1; is_idchar['2'] = 1; is_idchar['3'] = 1;
350 is_idchar['4'] = 1; is_idchar['5'] = 1; is_idchar['6'] = 1;
351 is_idchar['7'] = 1; is_idchar['8'] = 1; is_idchar['9'] = 1;
356 is_idchar['$'] = dollar_in_ident;
357 is_idstart['$'] = dollar_in_ident;
359 /* white space tables */
360 is_hor_space[' '] = 1;
361 is_hor_space['\t'] = 1;
362 is_hor_space['\v'] = 1;
363 is_hor_space['\f'] = 1;
371 /* trigraph conversion */
372 trigraph_table['='] = '#'; trigraph_table[')'] = ']';
373 trigraph_table['!'] = '|'; trigraph_table['('] = '[';
374 trigraph_table['\''] = '^'; trigraph_table['>'] = '}';
375 trigraph_table['/'] = '\\'; trigraph_table['<'] = '{';
376 trigraph_table['-'] = '~';
379 #endif /* Not GCC. */
381 /* Given a colon-separated list of file names PATH,
382 add all the names to the search path for include files. */
385 path_include (pfile, pend, list, path)
387 struct cpp_pending *pend;
397 /* Find the end of this name. */
399 while (*q != 0 && *q != PATH_SEPARATOR) q++;
402 /* An empty name in the path stands for the current directory. */
403 name = (char *) xmalloc (2);
409 /* Otherwise use the directory that is named. */
410 name = (char *) xmalloc (q - p + 1);
411 memcpy (name, p, q - p);
415 append_include_chain (pfile, pend, name, path);
417 /* Advance past this name. */
425 /* Find the base name of a (partial) pathname FNAME.
426 Returns a pointer into the string passed in.
427 Accepts Unix (/-separated) paths on all systems,
428 DOS and VMS paths on those systems. */
433 char *s = (char *)fname;
435 #if defined (HAVE_DOS_BASED_FILE_SYSTEM)
436 if (ISALPHA (s[0]) && s[1] == ':') s += 2;
437 if ((p = rindex (s, '\\'))) s = p + 1;
439 if ((p = rindex (s, ':'))) s = p + 1; /* Skip device. */
440 if ((p = rindex (s, ']'))) s = p + 1; /* Skip directory. */
441 if ((p = rindex (s, '>'))) s = p + 1; /* Skip alternate (int'n'l) dir. */
443 if ((p = rindex (s, '/'))) s = p + 1;
448 /* Append DIR to include path PATH. DIR must be permanently allocated
451 append_include_chain (pfile, pend, dir, path)
453 struct cpp_pending *pend;
457 struct file_name_list *new;
461 simplify_pathname (dir);
464 /* Dirs that don't exist are silently ignored. */
466 cpp_perror_with_name (pfile, dir);
467 else if (CPP_OPTIONS (pfile)->verbose)
468 cpp_notice ("ignoring nonexistent directory `%s'\n", dir);
472 if (!S_ISDIR (st.st_mode))
474 cpp_message (pfile, 1, "%s: %s: Not a directory", progname, dir);
479 if (len > pfile->max_include_len)
480 pfile->max_include_len = len;
482 new = (struct file_name_list *)xmalloc (sizeof (struct file_name_list));
485 new->ino = st.st_ino;
486 new->dev = st.st_dev;
487 new->sysp = (path == SYSTEM);
488 new->name_map = NULL;
492 case QUOTE: APPEND (pend, quote, new); break;
493 case BRACKET: APPEND (pend, brack, new); break;
494 case SYSTEM: APPEND (pend, systm, new); break;
495 case AFTER: APPEND (pend, after, new); break;
500 /* Write out a #define command for the special named MACRO_NAME
501 to PFILE's token_buffer. */
504 dump_special_to_buffer (pfile, macro_name)
508 static char define_directive[] = "#define ";
509 int macro_name_length = strlen (macro_name);
510 output_line_command (pfile, same_file);
511 CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length);
512 CPP_PUTS_Q (pfile, define_directive, sizeof(define_directive)-1);
513 CPP_PUTS_Q (pfile, macro_name, macro_name_length);
514 CPP_PUTC_Q (pfile, ' ');
515 cpp_expand_to_buffer (pfile, macro_name, macro_name_length);
516 CPP_PUTC (pfile, '\n');
519 /* Initialize a cpp_options structure. */
521 cpp_options_init (opts)
524 bzero ((char *) opts, sizeof (struct cpp_options));
526 opts->dollars_in_ident = 1;
527 opts->cplusplus_comments = 1;
528 opts->warn_import = 1;
530 opts->pending = (struct cpp_pending *) xmalloc (sizeof (struct cpp_pending));
531 bzero ((char *) opts->pending, sizeof (struct cpp_pending));
534 /* Initialize a cpp_reader structure. */
536 cpp_reader_init (pfile)
539 bzero ((char *) pfile, sizeof (cpp_reader));
541 pfile->get_token = cpp_get_token;
544 pfile->token_buffer_size = 200;
545 pfile->token_buffer = (U_CHAR *) xmalloc (pfile->token_buffer_size);
546 CPP_SET_WRITTEN (pfile, 0);
548 pfile->hashtab = (HASHNODE **) xcalloc (HASHSIZE, sizeof (HASHNODE *));
551 /* Free resources used by PFILE.
552 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
558 while (CPP_BUFFER (pfile) != CPP_NULL_BUFFER (pfile))
559 cpp_pop_buffer (pfile);
561 if (pfile->token_buffer)
563 free (pfile->token_buffer);
564 pfile->token_buffer = NULL;
567 if (pfile->deps_buffer)
569 free (pfile->deps_buffer);
570 pfile->deps_buffer = NULL;
571 pfile->deps_allocated_size = 0;
574 if (pfile->input_buffer)
576 free (pfile->input_buffer);
577 free (pfile->input_speccase);
578 pfile->input_buffer = pfile->input_speccase = NULL;
579 pfile->input_buffer_len = 0;
582 while (pfile->if_stack)
584 IF_STACK_FRAME *temp = pfile->if_stack;
585 pfile->if_stack = temp->next;
589 for (i = ALL_INCLUDE_HASHSIZE; --i >= 0; )
591 struct include_hash *imp = pfile->all_include_files[i];
594 struct include_hash *next = imp->next;
596 /* This gets freed elsewhere - I think. */
602 pfile->all_include_files[i] = 0;
605 for (i = HASHSIZE; --i >= 0;)
607 while (pfile->hashtab[i])
608 delete_macro (pfile->hashtab[i]);
610 free (pfile->hashtab);
614 /* Initialize the built-in macros. */
616 initialize_builtins (pfile)
619 #define NAME(str) (U_CHAR *)str, sizeof str - 1
620 cpp_install (pfile, NAME("__TIME__"), T_TIME, 0, -1);
621 cpp_install (pfile, NAME("__DATE__"), T_DATE, 0, -1);
622 cpp_install (pfile, NAME("__FILE__"), T_FILE, 0, -1);
623 cpp_install (pfile, NAME("__BASE_FILE__"), T_BASE_FILE, 0, -1);
624 cpp_install (pfile, NAME("__LINE__"), T_SPECLINE, 0, -1);
625 cpp_install (pfile, NAME("__INCLUDE_LEVEL__"), T_INCLUDE_LEVEL, 0, -1);
626 cpp_install (pfile, NAME("__VERSION__"), T_VERSION, 0, -1);
627 #ifndef NO_BUILTIN_SIZE_TYPE
628 cpp_install (pfile, NAME("__SIZE_TYPE__"), T_CONST, SIZE_TYPE, -1);
630 #ifndef NO_BUILTIN_PTRDIFF_TYPE
631 cpp_install (pfile, NAME("__PTRDIFF_TYPE__ "), T_CONST, PTRDIFF_TYPE, -1);
633 cpp_install (pfile, NAME("__WCHAR_TYPE__"), T_CONST, WCHAR_TYPE, -1);
634 cpp_install (pfile, NAME("__USER_LABEL_PREFIX__"), T_CONST, user_label_prefix, -1);
635 cpp_install (pfile, NAME("__REGISTER_PREFIX__"), T_CONST, REGISTER_PREFIX, -1);
636 cpp_install (pfile, NAME("__HAVE_BUILTIN_SETJMP__"), T_CONST, "1", -1);
637 if (!CPP_TRADITIONAL (pfile))
639 cpp_install (pfile, NAME("__STDC__"), T_STDC, 0, -1);
641 if (CPP_OPTIONS (pfile)->c9x)
642 cpp_install (pfile, NAME("__STDC_VERSION__"),T_CONST, "199909L", -1);
645 cpp_install (pfile, NAME("__STDC_VERSION__"),T_CONST, "199409L", -1);
649 if (CPP_OPTIONS (pfile)->debug_output)
651 dump_special_to_buffer (pfile, "__BASE_FILE__");
652 dump_special_to_buffer (pfile, "__VERSION__");
653 #ifndef NO_BUILTIN_SIZE_TYPE
654 dump_special_to_buffer (pfile, "__SIZE_TYPE__");
656 #ifndef NO_BUILTIN_PTRDIFF_TYPE
657 dump_special_to_buffer (pfile, "__PTRDIFF_TYPE__");
659 dump_special_to_buffer (pfile, "__WCHAR_TYPE__");
660 dump_special_to_buffer (pfile, "__DATE__");
661 dump_special_to_buffer (pfile, "__TIME__");
662 if (!CPP_TRADITIONAL (pfile))
663 dump_special_to_buffer (pfile, "__STDC__");
667 /* Another subroutine of cpp_start_read. This one sets up to do
668 dependency-file output. */
670 initialize_dependency_output (pfile)
673 cpp_options *opts = CPP_OPTIONS (pfile);
674 char *spec, *s, *output_file;
676 /* Either of two environment variables can specify output of deps.
677 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
678 where OUTPUT_FILE is the file to write deps info to
679 and DEPS_TARGET is the target to mention in the deps. */
681 if (opts->print_deps == 0)
683 spec = getenv ("DEPENDENCIES_OUTPUT");
685 opts->print_deps = 1;
688 spec = getenv ("SUNPRO_DEPENDENCIES");
690 opts->print_deps = 2;
695 /* Find the space before the DEPS_TARGET, if there is one. */
696 s = strchr (spec, ' ');
699 opts->deps_target = s + 1;
700 output_file = (char *) xmalloc (s - spec + 1);
701 memcpy (output_file, spec, s - spec);
702 output_file[s - spec] = 0;
706 opts->deps_target = 0;
710 opts->deps_file = output_file;
711 opts->print_deps_append = 1;
714 /* Print the expected object file name as the target of this Make-rule. */
715 pfile->deps_allocated_size = 200;
716 pfile->deps_buffer = (char *) xmalloc (pfile->deps_allocated_size);
717 pfile->deps_buffer[0] = 0;
718 pfile->deps_size = 0;
719 pfile->deps_column = 0;
721 if (opts->deps_target)
722 deps_output (pfile, opts->deps_target, ':');
723 else if (*opts->in_fname == 0)
724 deps_output (pfile, "-", ':');
730 /* Discard all directory prefixes from filename. */
731 q = base_name (opts->in_fname);
733 /* Copy remainder to mungable area. */
735 p = (char *) alloca (len + 8);
738 /* Output P, but remove known suffixes. */
740 /* Point to the filename suffix. */
742 /* Compare against the known suffixes. */
743 for (x = 0; known_suffixes[x]; x++)
745 if (strncmp (known_suffixes[x], r, q - r) == 0)
747 /* Make q point to the bit we're going to overwrite
748 with an object suffix. */
754 /* Supply our own suffix. */
755 strcpy (q, OBJECT_SUFFIX);
757 deps_output (pfile, p, ':');
758 deps_output (pfile, opts->in_fname, ' ');
762 /* This is called after options have been processed.
763 * Check options for consistency, and setup for processing input
764 * from the file named FNAME. (Use standard input if FNAME==NULL.)
765 * Return 1 on success, 0 on failure.
769 cpp_start_read (pfile, fname)
773 struct cpp_options *opts = CPP_OPTIONS (pfile);
774 struct pending_option *p, *q;
777 struct include_hash *ih_fake;
779 /* -MG doesn't select the form of output and must be specified with one of
780 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
781 inhibit compilation. */
782 if (opts->print_deps_missing_files
783 && (opts->print_deps == 0 || !opts->no_output))
785 cpp_fatal (pfile, "-MG must be specified with one of -M or -MM");
789 /* Chill should not be used with -trigraphs. */
790 if (opts->chill && opts->trigraphs)
792 cpp_warning (pfile, "-lang-chill and -trigraphs are mutually exclusive");
796 /* Set this if it hasn't been set already. */
797 if (user_label_prefix == NULL)
798 user_label_prefix = USER_LABEL_PREFIX;
800 /* Now that we know dollars_in_ident, we can initialize the syntax
802 initialize_char_syntax (opts->dollars_in_ident);
804 /* Do partial setup of input buffer for the sake of generating
805 early #line directives (when -g is in effect). */
806 fp = cpp_push_buffer (pfile, NULL, 0);
809 if (opts->in_fname == NULL || *opts->in_fname == 0)
811 opts->in_fname = fname;
812 if (opts->in_fname == NULL)
815 fp->nominal_fname = fp->fname = opts->in_fname;
818 /* Install __LINE__, etc. Must follow initialize_char_syntax
819 and option processing. */
820 initialize_builtins (pfile);
822 /* Do -U's, -D's and -A's in the order they were seen. */
823 p = opts->pending->define_head;
826 if (opts->debug_output)
827 output_line_command (pfile, same_file);
829 cpp_undef (pfile, p->arg);
831 cpp_define (pfile, p->arg);
838 p = opts->pending->assert_head;
841 if (opts->debug_output)
842 output_line_command (pfile, same_file);
844 cpp_unassert (pfile, p->arg);
846 cpp_assert (pfile, p->arg);
853 opts->done_initializing = 1;
855 /* Several environment variables may add to the include search path.
856 CPATH specifies an additional list of directories to be searched
857 as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH,
858 etc. specify an additional list of directories to be searched as
859 if specified with -isystem, for the language indicated.
861 These variables are ignored if -nostdinc is on. */
862 if (! opts->no_standard_includes)
865 GET_ENV_PATH_LIST (path, "CPATH");
866 if (path != 0 && *path != 0)
867 path_include (pfile, opts->pending, path, BRACKET);
869 switch ((opts->objc << 1) + opts->cplusplus)
872 GET_ENV_PATH_LIST (path, "C_INCLUDE_PATH");
875 GET_ENV_PATH_LIST (path, "CPLUS_INCLUDE_PATH");
878 GET_ENV_PATH_LIST (path, "OBJC_INCLUDE_PATH");
881 GET_ENV_PATH_LIST (path, "OBJCPLUS_INCLUDE_PATH");
884 if (path != 0 && *path != 0)
885 path_include (pfile, opts->pending, path, SYSTEM);
888 /* Unless -nostdinc, add the compiled-in include path to the list,
889 translating prefixes. */
890 if (!opts->no_standard_includes)
892 struct default_include *p = include_defaults_array;
893 char *specd_prefix = opts->include_prefix;
895 /* Search "translated" versions of GNU directories.
896 These have /usr/local/lib/gcc... replaced by specd_prefix. */
897 if (specd_prefix != 0)
899 char *default_prefix = alloca (sizeof GCC_INCLUDE_DIR - 7);
900 /* Remove the `include' from /usr/local/lib/gcc.../include.
901 GCC_INCLUDE_DIR will always end in /include. */
902 int default_len = sizeof GCC_INCLUDE_DIR - 8;
903 int specd_len = strlen (specd_prefix);
905 default_len = sizeof GCC_INCLUDE_DIR - 8;
906 memcpy (default_prefix, GCC_INCLUDE_DIR, default_len);
907 default_prefix[default_len] = '\0';
909 for (p = include_defaults_array; p->fname; p++)
911 /* Some standard dirs are only for C++. */
914 && !opts->no_standard_cplusplus_includes))
916 /* Does this dir start with the prefix? */
917 if (!strncmp (p->fname, default_prefix, default_len))
919 /* Yes; change prefix and add to search list. */
920 int flen = strlen (p->fname);
921 int this_len = specd_len + flen - default_len;
922 char *str = (char *) xmalloc (this_len + 1);
923 memcpy (str, specd_prefix, specd_len);
924 memcpy (str + specd_len,
925 p->fname + default_len,
926 flen - default_len + 1);
928 append_include_chain (pfile, opts->pending,
935 /* Search ordinary names for GNU include directories. */
936 for (p = include_defaults_array; p->fname; p++)
938 /* Some standard dirs are only for C++. */
941 && !opts->no_standard_cplusplus_includes))
943 char *str = (char *) update_path (p->fname, p->component);
944 str = xstrdup (str); /* XXX Potential memory leak! */
945 append_include_chain (pfile, opts->pending, str, SYSTEM);
950 merge_include_chains (opts);
952 /* With -v, print the list of dirs to search. */
955 struct file_name_list *p;
956 cpp_message (pfile, -1, "#include \"...\" search starts here:\n");
957 for (p = opts->quote_include; p; p = p->next)
959 if (p == opts->bracket_include)
960 cpp_message (pfile, -1, "#include <...> search starts here:\n");
961 fprintf (stderr, " %s\n", p->name);
963 cpp_message (pfile, -1, "End of search list.\n");
966 /* Open the main input file.
967 We do this in nonblocking mode so we don't get stuck here if
968 someone clever has asked cpp to process /dev/rmt0;
969 finclude() will check that we have a real file to work with. */
970 if (fname == NULL || *fname == 0)
975 else if ((f = open (fname, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666)) < 0)
976 cpp_pfatal_with_name (pfile, fname);
978 initialize_dependency_output (pfile);
980 /* Must call finclude() on the main input before processing
981 -include switches; otherwise the -included text winds up
982 after the main input. */
983 ih_fake = (struct include_hash *) xmalloc (sizeof (struct include_hash));
985 ih_fake->next_this_file = 0;
986 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
987 ih_fake->name = fname;
988 ih_fake->control_macro = 0;
989 ih_fake->buf = (char *)-1;
991 if (!finclude (pfile, f, ih_fake))
993 output_line_command (pfile, same_file);
994 pfile->only_seen_white = 2;
996 /* The -imacros files can be scanned now, but the -include files
997 have to be pushed onto the include stack and processed later,
998 in the main loop calling cpp_get_token. */
1000 pfile->no_record_file++;
1002 p = opts->pending->imacros_head;
1005 int fd = open (p->arg, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666);
1008 cpp_perror_with_name (pfile, p->arg);
1011 if (!cpp_push_buffer (pfile, NULL, 0))
1014 ih_fake = (struct include_hash *)
1015 xmalloc (sizeof (struct include_hash));
1017 ih_fake->next_this_file = 0;
1018 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
1019 ih_fake->name = p->arg;
1020 ih_fake->control_macro = 0;
1021 ih_fake->buf = (char *)-1;
1023 if (!finclude (pfile, fd, ih_fake))
1024 cpp_scan_buffer (pfile);
1034 p = opts->pending->include_head;
1037 int fd = open (p->arg, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666);
1040 cpp_perror_with_name (pfile, p->arg);
1043 if (!cpp_push_buffer (pfile, NULL, 0))
1046 ih_fake = (struct include_hash *)
1047 xmalloc (sizeof (struct include_hash));
1049 ih_fake->next_this_file = 0;
1050 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
1051 ih_fake->name = p->arg;
1052 ih_fake->control_macro = 0;
1053 ih_fake->buf = (char *)-1;
1055 if (finclude (pfile, fd, ih_fake))
1056 output_line_command (pfile, enter_file);
1062 pfile->no_record_file--;
1064 free (opts->pending);
1065 opts->pending = NULL;
1070 /* This is called at the end of preprocessing. It pops the
1071 last buffer and writes dependency output. It should also
1072 clear macro definitions, such that you could call cpp_start_read
1073 with a new filename to restart processing. */
1078 struct cpp_options *opts = CPP_OPTIONS (pfile);
1080 if (CPP_PREV_BUFFER (CPP_BUFFER (pfile)) != CPP_NULL_BUFFER (pfile))
1082 "cpplib internal error: buffers still stacked in cpp_finish");
1083 cpp_pop_buffer (pfile);
1085 if (opts->print_deps)
1087 /* Stream on which to print the dependency information. */
1090 /* Don't actually write the deps file if compilation has failed. */
1091 if (pfile->errors == 0)
1093 char *deps_mode = opts->print_deps_append ? "a" : "w";
1094 if (opts->deps_file == 0)
1095 deps_stream = stdout;
1096 else if ((deps_stream = fopen (opts->deps_file, deps_mode)) == 0)
1097 cpp_pfatal_with_name (pfile, opts->deps_file);
1098 fputs (pfile->deps_buffer, deps_stream);
1099 putc ('\n', deps_stream);
1100 if (opts->deps_file)
1102 if (ferror (deps_stream) || fclose (deps_stream) != 0)
1103 cpp_fatal (pfile, "I/O error on output");
1108 if (opts->dump_macros == dump_only)
1113 for (i = HASHSIZE; --i >= 0;)
1115 for (h = pfile->hashtab[i]; h; h = h->next)
1116 if (h->type == T_MACRO)
1118 m.defn = h->value.defn;
1120 m.symlen = h->length;
1121 dump_definition (pfile, m);
1122 CPP_PUTC (pfile, '\n');
1128 /* Handle one command-line option in (argc, argv).
1129 Can be called multiple times, to handle multiple sets of options.
1130 Returns number of strings consumed. */
1132 cpp_handle_option (pfile, argc, argv)
1137 struct cpp_options *opts = CPP_OPTIONS (pfile);
1140 if (argv[i][0] != '-')
1142 if (opts->out_fname != NULL)
1145 cpp_fatal (pfile, "Too many arguments");
1147 else if (opts->in_fname != NULL)
1148 opts->out_fname = argv[i];
1150 opts->in_fname = argv[i];
1156 if (!strcmp (argv[i], "-fleading-underscore"))
1157 user_label_prefix = "_";
1158 else if (!strcmp (argv[i], "-fno-leading-underscore"))
1159 user_label_prefix = "";
1162 case 'I': /* Add directory to path for includes. */
1163 if (!strcmp (argv[i] + 2, "-"))
1166 Use the preceding -I directories for #include "..."
1167 but not #include <...>.
1168 Don't search the directory of the present file
1169 for #include "...". (Note that -I. -I- is not the same as
1170 the default setup; -I. uses the compiler's working dir.) */
1171 if (! opts->ignore_srcdir)
1173 opts->ignore_srcdir = 1;
1174 opts->pending->quote_head = opts->pending->brack_head;
1175 opts->pending->quote_tail = opts->pending->brack_tail;
1176 opts->pending->brack_head = 0;
1177 opts->pending->brack_tail = 0;
1181 cpp_fatal (pfile, "-I- specified twice");
1188 if (argv[i][2] != 0)
1189 fname = argv[i] + 2;
1190 else if (i + 1 == argc)
1191 goto missing_dirname;
1194 append_include_chain (pfile, opts->pending,
1195 xstrdup (fname), BRACKET);
1200 /* Add directory to beginning of system include path, as a system
1201 include directory. */
1202 if (!strcmp (argv[i], "-isystem"))
1205 goto missing_filename;
1206 append_include_chain (pfile, opts->pending,
1207 xstrdup (argv[++i]), SYSTEM);
1209 else if (!strcmp (argv[i], "-include"))
1212 goto missing_filename;
1215 struct pending_option *o = (struct pending_option *)
1216 xmalloc (sizeof (struct pending_option));
1219 /* This list has to be built in reverse order so that
1220 when cpp_start_read pushes all the -include files onto
1221 the buffer stack, they will be scanned in forward order. */
1222 o->next = opts->pending->include_head;
1223 opts->pending->include_head = o;
1226 else if (!strcmp (argv[i], "-imacros"))
1229 goto missing_filename;
1232 struct pending_option *o = (struct pending_option *)
1233 xmalloc (sizeof (struct pending_option));
1237 APPEND (opts->pending, imacros, o);
1240 /* Add directory to end of path for includes,
1241 with the default prefix at the front of its name. */
1242 else if (!strcmp (argv[i], "-iwithprefix"))
1247 goto missing_dirname;
1249 len = strlen (argv[i]);
1251 if (opts->include_prefix != 0)
1253 fname = xmalloc (opts->include_prefix_len + len + 1);
1254 memcpy (fname, opts->include_prefix, opts->include_prefix_len);
1255 memcpy (fname + opts->include_prefix_len, argv[i], len + 1);
1259 fname = xmalloc (sizeof GCC_INCLUDE_DIR - 8 + len);
1260 memcpy (fname, GCC_INCLUDE_DIR, sizeof GCC_INCLUDE_DIR - 9);
1261 memcpy (fname + sizeof GCC_INCLUDE_DIR - 9, argv[i], len + 1);
1264 append_include_chain (pfile, opts->pending, fname, SYSTEM);
1266 /* Add directory to main path for includes,
1267 with the default prefix at the front of its name. */
1268 else if (!strcmp (argv[i], "-iwithprefixbefore"))
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, BRACKET);
1292 /* Add directory to end of path for includes. */
1293 else if (!strcmp (argv[i], "-idirafter"))
1296 goto missing_dirname;
1297 append_include_chain (pfile, opts->pending,
1298 xstrdup (argv[++i]), AFTER);
1300 else if (!strcmp (argv[i], "-iprefix"))
1303 goto missing_filename;
1306 opts->include_prefix = argv[++i];
1307 opts->include_prefix_len = strlen (argv[i]);
1310 else if (!strcmp (argv[i], "-ifoutput"))
1311 opts->output_conditionals = 1;
1316 if (opts->out_fname != NULL)
1318 cpp_fatal (pfile, "Output filename specified twice");
1322 goto missing_filename;
1323 opts->out_fname = argv[++i];
1324 if (!strcmp (opts->out_fname, "-"))
1325 opts->out_fname = "";
1329 if (!strcmp (argv[i], "-pedantic"))
1330 CPP_PEDANTIC (pfile) = 1;
1331 else if (!strcmp (argv[i], "-pedantic-errors"))
1333 CPP_PEDANTIC (pfile) = 1;
1334 opts->pedantic_errors = 1;
1337 else if (!strcmp (argv[i], "-pcp")) {
1338 char *pcp_fname = argv[++i];
1339 pcp_outfile = ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
1340 ? fopen (pcp_fname, "w")
1341 : fdopen (dup (fileno (stdout)), "w"));
1342 if (pcp_outfile == 0)
1343 cpp_pfatal_with_name (pfile, pcp_fname);
1350 if (!strcmp (argv[i], "-traditional"))
1352 opts->traditional = 1;
1353 opts->cplusplus_comments = 0;
1355 else if (!strcmp (argv[i], "-trigraphs"))
1356 opts->trigraphs = 1;
1360 if (! strcmp (argv[i], "-lang-c"))
1361 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
1362 opts->c9x = 1, opts->objc = 0;
1363 if (! strcmp (argv[i], "-lang-c89"))
1364 opts->cplusplus = 0, opts->cplusplus_comments = 0, opts->c89 = 1,
1365 opts->c9x = 0, opts->objc = 0;
1366 if (! strcmp (argv[i], "-lang-c++"))
1367 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0,
1368 opts->c9x = 0, opts->objc = 0;
1369 if (! strcmp (argv[i], "-lang-objc"))
1370 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
1371 opts->c9x = 0, opts->objc = 1;
1372 if (! strcmp (argv[i], "-lang-objc++"))
1373 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0,
1374 opts->c9x = 0, opts->objc = 1;
1375 if (! strcmp (argv[i], "-lang-asm"))
1377 if (! strcmp (argv[i], "-lint"))
1379 if (! strcmp (argv[i], "-lang-chill"))
1380 opts->objc = 0, opts->cplusplus = 0, opts->chill = 1,
1381 opts->traditional = 1;
1385 opts->cplusplus = 1, opts->cplusplus_comments = 1;
1389 if (!strcmp (argv[i], "-std=iso9899:1990")
1390 || !strcmp (argv[i], "-std=iso9899:199409")
1391 || !strcmp (argv[i], "-std=c89")
1392 || !strcmp (argv[i], "-std=gnu89"))
1393 opts->cplusplus = 0, opts->cplusplus_comments = 0,
1394 opts->c89 = 1, opts->c9x = 0, opts->objc = 0;
1395 else if (!strcmp (argv[i], "-std=iso9899:199x")
1396 || !strcmp (argv[i], "-std=c9x")
1397 || !strcmp (argv[i], "-std=gnu9x"))
1398 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
1399 opts->c9x = 1, opts->objc = 0;
1403 opts->inhibit_warnings = 1;
1407 if (!strcmp (argv[i], "-Wtrigraphs"))
1408 opts->warn_trigraphs = 1;
1409 else if (!strcmp (argv[i], "-Wno-trigraphs"))
1410 opts->warn_trigraphs = 0;
1411 else if (!strcmp (argv[i], "-Wcomment"))
1412 opts->warn_comments = 1;
1413 else if (!strcmp (argv[i], "-Wno-comment"))
1414 opts->warn_comments = 0;
1415 else if (!strcmp (argv[i], "-Wcomments"))
1416 opts->warn_comments = 1;
1417 else if (!strcmp (argv[i], "-Wno-comments"))
1418 opts->warn_comments = 0;
1419 else if (!strcmp (argv[i], "-Wtraditional"))
1420 opts->warn_stringify = 1;
1421 else if (!strcmp (argv[i], "-Wno-traditional"))
1422 opts->warn_stringify = 0;
1423 else if (!strcmp (argv[i], "-Wundef"))
1424 opts->warn_undef = 1;
1425 else if (!strcmp (argv[i], "-Wno-undef"))
1426 opts->warn_undef = 0;
1427 else if (!strcmp (argv[i], "-Wimport"))
1428 opts->warn_import = 1;
1429 else if (!strcmp (argv[i], "-Wno-import"))
1430 opts->warn_import = 0;
1431 else if (!strcmp (argv[i], "-Werror"))
1432 opts->warnings_are_errors = 1;
1433 else if (!strcmp (argv[i], "-Wno-error"))
1434 opts->warnings_are_errors = 0;
1435 else if (!strcmp (argv[i], "-Wall"))
1437 opts->warn_trigraphs = 1;
1438 opts->warn_comments = 1;
1443 /* The style of the choices here is a bit mixed.
1444 The chosen scheme is a hybrid of keeping all options in one string
1445 and specifying each option in a separate argument:
1446 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
1447 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
1448 -M[M][G][D file]. This is awkward to handle in specs, and is not
1450 /* ??? -MG must be specified in addition to one of -M or -MM.
1451 This can be relaxed in the future without breaking anything.
1452 The converse isn't true. */
1454 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
1455 if (!strcmp (argv[i], "-MG"))
1457 opts->print_deps_missing_files = 1;
1460 if (!strcmp (argv[i], "-M"))
1461 opts->print_deps = 2;
1462 else if (!strcmp (argv[i], "-MM"))
1463 opts->print_deps = 1;
1464 else if (!strcmp (argv[i], "-MD"))
1465 opts->print_deps = 2;
1466 else if (!strcmp (argv[i], "-MMD"))
1467 opts->print_deps = 1;
1468 /* For -MD and -MMD options, write deps on file named by next arg. */
1469 if (!strcmp (argv[i], "-MD") || !strcmp (argv[i], "-MMD"))
1472 goto missing_filename;
1473 opts->deps_file = argv[++i];
1477 /* For -M and -MM, write deps on standard output
1478 and suppress the usual output. */
1479 opts->no_output = 1;
1485 char *p = argv[i] + 2;
1487 while ((c = *p++) != 0)
1489 /* Arg to -d specifies what parts of macros to dump */
1493 opts->dump_macros = dump_only;
1494 opts->no_output = 1;
1497 opts->dump_macros = dump_names;
1500 opts->dump_macros = dump_definitions;
1503 opts->dump_includes = 1;
1511 if (argv[i][2] == '3')
1512 opts->debug_output = 1;
1516 if (!strcmp (argv[i], "--help"))
1518 else if (!strcmp (argv[i], "--version"))
1519 cpp_notice ("GNU CPP version %s\n", version_string);
1524 cpp_notice ("GNU CPP version %s", version_string);
1525 #ifdef TARGET_VERSION
1528 fputc ('\n', stderr);
1533 opts->print_include_names = 1;
1538 struct pending_option *o = (struct pending_option *)
1539 xmalloc (sizeof (struct pending_option));
1540 if (argv[i][2] != 0)
1541 o->arg = argv[i] + 2;
1542 else if (i + 1 == argc)
1544 cpp_fatal (pfile, "Macro name missing after -D option");
1552 APPEND (opts->pending, define, o);
1560 if (argv[i][2] != 0)
1562 else if (i + 1 == argc)
1564 cpp_fatal (pfile, "Assertion missing after -A option");
1570 if (strcmp (p, "-"))
1572 struct pending_option *o = (struct pending_option *)
1573 xmalloc (sizeof (struct pending_option));
1578 APPEND (opts->pending, assert, o);
1582 /* -A- eliminates all predefined macros and assertions.
1583 Let's include also any that were specified earlier
1584 on the command line. That way we can get rid of any
1585 that were passed automatically in from GCC. */
1586 struct pending_option *o1, *o2;
1588 o1 = opts->pending->define_head;
1595 o1 = opts->pending->assert_head;
1602 opts->pending->assert_head = NULL;
1603 opts->pending->assert_tail = NULL;
1604 opts->pending->define_head = NULL;
1605 opts->pending->define_tail = NULL;
1612 struct pending_option *o = (struct pending_option *)
1613 xmalloc (sizeof (struct pending_option));
1615 if (argv[i][2] != 0)
1616 o->arg = argv[i] + 2;
1617 else if (i + 1 == argc)
1619 cpp_fatal (pfile, "Macro name missing after -U option");
1627 APPEND (opts->pending, define, o);
1632 opts->put_out_comments = 1;
1635 case 'E': /* -E comes from cc -E; ignore it. */
1639 opts->no_line_commands = 1;
1642 case '$': /* Don't include $ in identifiers. */
1643 opts->dollars_in_ident = 0;
1647 if (!strcmp (argv[i], "-nostdinc"))
1648 /* -nostdinc causes no default include directories.
1649 You must specify all include-file directories with -I. */
1650 opts->no_standard_includes = 1;
1651 else if (!strcmp (argv[i], "-nostdinc++"))
1652 /* -nostdinc++ causes no default C++-specific include directories. */
1653 opts->no_standard_cplusplus_includes = 1;
1655 else if (!strcmp (argv[i], "-noprecomp"))
1661 if (!strcmp (argv[i], "-remap"))
1665 case '\0': /* JF handle '-' as file name meaning stdin or stdout */
1666 if (opts->in_fname == NULL)
1667 opts->in_fname = "";
1668 else if (opts->out_fname == NULL)
1669 opts->out_fname = "";
1671 return i; /* error */
1681 cpp_fatal (pfile, "Filename missing after `%s' option", argv[i]);
1684 cpp_fatal (pfile, "Directory name missing after `%s' option", argv[i]);
1688 /* Handle command-line options in (argc, argv).
1689 Can be called multiple times, to handle multiple sets of options.
1690 Returns if an unrecognized option is seen.
1691 Returns number of strings consumed. */
1694 cpp_handle_options (pfile, argc, argv)
1700 int strings_processed;
1701 for (i = 0; i < argc; i += strings_processed)
1703 strings_processed = cpp_handle_option (pfile, argc - i, argv + i);
1704 if (strings_processed == 0)
1713 cpp_notice ("Usage: %s [switches] input output\n", progname);
1716 -include <file> Include the contents of <file> before other files\n\
1717 -imacros <file> Accept definition of macros in <file>\n\
1718 -iprefix <path> Specify <path> as a prefix for next two options\n\
1719 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1720 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1721 -isystem <dir> Add <dir> to the start of the system include path\n\
1722 -idirafter <dir> Add <dir> to the end of the system include path\n\
1723 -I <dir> Add <dir> to the end of the main include path\n\
1724 -nostdinc Do not search system include directories\n\
1725 (dirs specified with -isystem will still be used)\n\
1726 -nostdinc++ Do not search system include directories for C++\n\
1727 -o <file> Put output into <file>\n\
1728 -pedantic Issue all warnings demanded by strict ANSI C\n\
1729 -traditional Follow K&R pre-processor behaviour\n\
1730 -trigraphs Support ANSI C trigraphs\n\
1731 -lang-c Assume that the input sources are in C\n\
1732 -lang-c89 Assume that the input sources are in C89\n\
1733 -lang-c++ Assume that the input sources are in C++\n\
1734 -lang-objc Assume that the input sources are in ObjectiveC\n\
1735 -lang-objc++ Assume that the input sources are in ObjectiveC++\n\
1736 -lang-asm Assume that the input sources are in assembler\n\
1737 -lang-chill Assume that the input sources are in Chill\n\
1738 -std=<std name> Specify the conformance standard; one of:\n\
1739 gnu89, gnu9x, c89, c9x, iso9899:1990,\n\
1740 iso9899:199409, iso9899:199x\n\
1741 -+ Allow parsing of C++ style features\n\
1742 -w Inhibit warning messages\n\
1743 -Wtrigraphs Warn if trigraphs are encountered\n\
1744 -Wno-trigraphs Do not warn about trigraphs\n\
1745 -Wcomment{s} Warn if one comment starts inside another\n\
1746 -Wno-comment{s} Do not warn about comments\n\
1747 -Wtraditional Warn if a macro argument is/would be turned into\n\
1748 a string if -traditional is specified\n\
1749 -Wno-traditional Do not warn about stringification\n\
1750 -Wundef Warn if an undefined macro is used by #if\n\
1751 -Wno-undef Do not warn about testing undefined macros\n\
1752 -Wimport Warn about the use of the #import directive\n\
1753 -Wno-import Do not warn about the use of #import\n\
1754 -Werror Treat all warnings as errors\n\
1755 -Wno-error Do not treat warnings as errors\n\
1756 -Wall Enable all preprocessor warnings\n\
1757 -M Generate make dependencies\n\
1758 -MM As -M, but ignore system header files\n\
1759 -MD As -M, but put output in a .d file\n\
1760 -MMD As -MD, but ignore system header files\n\
1761 -MG Treat missing header file as generated files\n\
1762 -g Include #define and #undef directives in the output\n\
1763 -D<macro> Define a <macro> with string '1' as its value\n\
1764 -D<macro>=<val> Define a <macro> with <val> as its value\n\
1765 -A<question> (<answer>) Assert the <answer> to <question>\n\
1766 -U<macro> Undefine <macro> \n\
1767 -v Display the version number\n\
1768 -H Print the name of header files as they are used\n\
1769 -C Do not discard comments\n\
1770 -dM Display a list of macro definitions active at end\n\
1771 -dD Preserve macro definitions in output\n\
1772 -dN As -dD except that only the names are preserved\n\
1773 -dI Include #include directives in the output\n\
1774 -ifoutput Describe skipped code blocks in output \n\
1775 -P Do not generate #line directives\n\
1776 -$ Do not allow '$' in identifiers\n\
1777 -remap Remap file names when including files.\n\
1778 -h or --help Display this information\n\