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 },
132 { GPLUSPLUS_INCLUDE_DIR2, "G++", 1, 1 },
134 /* This is the dir for fixincludes. Put it just before
135 the files that we fix. */
136 { GCC_INCLUDE_DIR, "GCC", 0, 0 },
137 /* For cross-compilation, this dir name is generated
138 automatically in Makefile.in. */
139 { CROSS_INCLUDE_DIR, "GCC", 0, 0 },
140 #ifdef TOOL_INCLUDE_DIR
141 /* This is another place that the target system's headers might be. */
142 { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
144 #else /* not CROSS_COMPILE */
145 #ifdef LOCAL_INCLUDE_DIR
146 /* This should be /usr/local/include and should come before
147 the fixincludes-fixed header files. */
148 { LOCAL_INCLUDE_DIR, 0, 0, 1 },
150 #ifdef TOOL_INCLUDE_DIR
151 /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
152 Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
153 { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
155 /* This is the dir for fixincludes. Put it just before
156 the files that we fix. */
157 { GCC_INCLUDE_DIR, "GCC", 0, 0 },
158 /* Some systems have an extra dir of include files. */
159 #ifdef SYSTEM_INCLUDE_DIR
160 { SYSTEM_INCLUDE_DIR, 0, 0, 0 },
162 #ifndef STANDARD_INCLUDE_COMPONENT
163 #define STANDARD_INCLUDE_COMPONENT 0
165 { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0 },
166 #endif /* not CROSS_COMPILE */
169 #endif /* no INCLUDE_DEFAULTS */
171 /* Internal structures and prototypes. */
173 /* A `struct pending_option' remembers one -D, -A, -U, -include, or -imacros
174 switch. There are four lists: one for -D and -U, one for -A, one
175 for -include, one for -imacros. `undef' is set for -U, clear for
176 -D, ignored for the others.
177 (Future: add an equivalent of -U for -A) */
178 struct pending_option
180 struct pending_option *next;
186 #define APPEND(pend, list, elt) \
187 do { if (!(pend)->list##_head) (pend)->list##_head = (elt); \
188 else (pend)->list##_tail->next = (elt); \
189 (pend)->list##_tail = (elt); \
192 #define APPEND(pend, list, elt) \
193 do { if (!(pend)->list/**/_head) (pend)->list/**/_head = (elt); \
194 else (pend)->list/**/_tail->next = (elt); \
195 (pend)->list/**/_tail = (elt); \
199 static void initialize_char_syntax PARAMS ((int));
200 static void print_help PARAMS ((void));
201 static void path_include PARAMS ((cpp_reader *,
202 struct cpp_pending *,
204 static void initialize_builtins PARAMS ((cpp_reader *));
205 static void append_include_chain PARAMS ((cpp_reader *,
206 struct cpp_pending *,
209 /* Last argument to append_include_chain: chain to use */
210 enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
212 /* If gcc is in use (stage2/stage3) we can make these tables initialized
214 #if defined __GNUC__ && (__GNUC__ > 2 \
215 || (__GNUC__ == 2 && __GNUC_MINOR__ > 8))
216 /* Table to tell if a character is legal as the second or later character
217 of a C identifier. */
218 U_CHAR is_idchar[256] =
220 ['a'] = 1, ['b'] = 1, ['c'] = 1, ['d'] = 1, ['e'] = 1, ['f'] = 1,
221 ['g'] = 1, ['h'] = 1, ['i'] = 1, ['j'] = 1, ['k'] = 1, ['l'] = 1,
222 ['m'] = 1, ['n'] = 1, ['o'] = 1, ['p'] = 1, ['q'] = 1, ['r'] = 1,
223 ['s'] = 1, ['t'] = 1, ['u'] = 1, ['v'] = 1, ['w'] = 1, ['x'] = 1,
224 ['y'] = 1, ['z'] = 1,
226 ['A'] = 1, ['B'] = 1, ['C'] = 1, ['D'] = 1, ['E'] = 1, ['F'] = 1,
227 ['G'] = 1, ['H'] = 1, ['I'] = 1, ['J'] = 1, ['K'] = 1, ['L'] = 1,
228 ['M'] = 1, ['N'] = 1, ['O'] = 1, ['P'] = 1, ['Q'] = 1, ['R'] = 1,
229 ['S'] = 1, ['T'] = 1, ['U'] = 1, ['V'] = 1, ['W'] = 1, ['X'] = 1,
230 ['Y'] = 1, ['Z'] = 1,
232 ['1'] = 1, ['2'] = 1, ['3'] = 1, ['4'] = 1, ['5'] = 1, ['6'] = 1,
233 ['7'] = 1, ['8'] = 1, ['9'] = 1, ['0'] = 1,
238 /* Table to tell if a character is legal as the first character of
240 U_CHAR is_idstart[256] =
242 ['a'] = 1, ['b'] = 1, ['c'] = 1, ['d'] = 1, ['e'] = 1, ['f'] = 1,
243 ['g'] = 1, ['h'] = 1, ['i'] = 1, ['j'] = 1, ['k'] = 1, ['l'] = 1,
244 ['m'] = 1, ['n'] = 1, ['o'] = 1, ['p'] = 1, ['q'] = 1, ['r'] = 1,
245 ['s'] = 1, ['t'] = 1, ['u'] = 1, ['v'] = 1, ['w'] = 1, ['x'] = 1,
246 ['y'] = 1, ['z'] = 1,
248 ['A'] = 1, ['B'] = 1, ['C'] = 1, ['D'] = 1, ['E'] = 1, ['F'] = 1,
249 ['G'] = 1, ['H'] = 1, ['I'] = 1, ['J'] = 1, ['K'] = 1, ['L'] = 1,
250 ['M'] = 1, ['N'] = 1, ['O'] = 1, ['P'] = 1, ['Q'] = 1, ['R'] = 1,
251 ['S'] = 1, ['T'] = 1, ['U'] = 1, ['V'] = 1, ['W'] = 1, ['X'] = 1,
252 ['Y'] = 1, ['Z'] = 1,
257 /* Table to tell if a character is horizontal space.
258 \r is magical, so it is not in here. */
259 U_CHAR is_hor_space[256] =
261 [' '] = 1, ['\t'] = 1, ['\v'] = 1, ['\f'] = 1,
263 /* table to tell if a character is horizontal or vertical space. */
264 U_CHAR is_space[256] =
266 [' '] = 1, ['\t'] = 1, ['\v'] = 1, ['\f'] = 1, ['\n'] = 1,
268 /* Table to handle trigraph conversion, which occurs before all other
269 processing, everywhere in the file. (This is necessary since one
270 of the trigraphs encodes backslash.) Note it's off by default.
272 from to from to from to
277 There is not a space between the ?? and the third char. I put spaces
278 there to avoid warnings when compiling this file. */
279 U_CHAR trigraph_table[256] =
281 ['='] = '#', [')'] = ']', ['!'] = '|',
282 ['('] = '[', ['\''] = '^', ['>'] = '}',
283 ['/'] = '\\', ['<'] = '{', ['-'] = '~',
286 /* This function will be entirely removed soon. */
288 initialize_char_syntax (dollar_in_ident)
291 is_idchar['$'] = dollar_in_ident;
292 is_idstart['$'] = dollar_in_ident;
297 U_CHAR is_idchar[256] = { 0 };
298 U_CHAR is_idstart[256] = { 0 };
299 U_CHAR is_hor_space[256] = { 0 };
300 U_CHAR is_space[256] = { 0 };
301 U_CHAR trigraph_table[256] = { 0 };
303 /* Initialize syntactic classifications of characters. */
305 initialize_char_syntax (dollar_in_ident)
308 is_idstart['a'] = 1; is_idstart['b'] = 1; is_idstart['c'] = 1;
309 is_idstart['d'] = 1; is_idstart['e'] = 1; is_idstart['f'] = 1;
310 is_idstart['g'] = 1; is_idstart['h'] = 1; is_idstart['i'] = 1;
311 is_idstart['j'] = 1; is_idstart['k'] = 1; is_idstart['l'] = 1;
312 is_idstart['m'] = 1; is_idstart['n'] = 1; is_idstart['o'] = 1;
313 is_idstart['p'] = 1; is_idstart['q'] = 1; is_idstart['r'] = 1;
314 is_idstart['s'] = 1; is_idstart['t'] = 1; is_idstart['u'] = 1;
315 is_idstart['v'] = 1; is_idstart['w'] = 1; is_idstart['x'] = 1;
316 is_idstart['y'] = 1; is_idstart['z'] = 1;
318 is_idstart['A'] = 1; is_idstart['B'] = 1; is_idstart['C'] = 1;
319 is_idstart['D'] = 1; is_idstart['E'] = 1; is_idstart['F'] = 1;
320 is_idstart['G'] = 1; is_idstart['H'] = 1; is_idstart['I'] = 1;
321 is_idstart['J'] = 1; is_idstart['K'] = 1; is_idstart['L'] = 1;
322 is_idstart['M'] = 1; is_idstart['N'] = 1; is_idstart['O'] = 1;
323 is_idstart['P'] = 1; is_idstart['Q'] = 1; is_idstart['R'] = 1;
324 is_idstart['S'] = 1; is_idstart['T'] = 1; is_idstart['U'] = 1;
325 is_idstart['V'] = 1; is_idstart['W'] = 1; is_idstart['X'] = 1;
326 is_idstart['Y'] = 1; is_idstart['Z'] = 1;
330 is_idchar['a'] = 1; is_idchar['b'] = 1; is_idchar['c'] = 1;
331 is_idchar['d'] = 1; is_idchar['e'] = 1; is_idchar['f'] = 1;
332 is_idchar['g'] = 1; is_idchar['h'] = 1; is_idchar['i'] = 1;
333 is_idchar['j'] = 1; is_idchar['k'] = 1; is_idchar['l'] = 1;
334 is_idchar['m'] = 1; is_idchar['n'] = 1; is_idchar['o'] = 1;
335 is_idchar['p'] = 1; is_idchar['q'] = 1; is_idchar['r'] = 1;
336 is_idchar['s'] = 1; is_idchar['t'] = 1; is_idchar['u'] = 1;
337 is_idchar['v'] = 1; is_idchar['w'] = 1; is_idchar['x'] = 1;
338 is_idchar['y'] = 1; is_idchar['z'] = 1;
340 is_idchar['A'] = 1; is_idchar['B'] = 1; is_idchar['C'] = 1;
341 is_idchar['D'] = 1; is_idchar['E'] = 1; is_idchar['F'] = 1;
342 is_idchar['G'] = 1; is_idchar['H'] = 1; is_idchar['I'] = 1;
343 is_idchar['J'] = 1; is_idchar['K'] = 1; is_idchar['L'] = 1;
344 is_idchar['M'] = 1; is_idchar['N'] = 1; is_idchar['O'] = 1;
345 is_idchar['P'] = 1; is_idchar['Q'] = 1; is_idchar['R'] = 1;
346 is_idchar['S'] = 1; is_idchar['T'] = 1; is_idchar['U'] = 1;
347 is_idchar['V'] = 1; is_idchar['W'] = 1; is_idchar['X'] = 1;
348 is_idchar['Y'] = 1; is_idchar['Z'] = 1;
350 is_idchar['1'] = 1; is_idchar['2'] = 1; is_idchar['3'] = 1;
351 is_idchar['4'] = 1; is_idchar['5'] = 1; is_idchar['6'] = 1;
352 is_idchar['7'] = 1; is_idchar['8'] = 1; is_idchar['9'] = 1;
357 is_idchar['$'] = dollar_in_ident;
358 is_idstart['$'] = dollar_in_ident;
360 /* white space tables */
361 is_hor_space[' '] = 1;
362 is_hor_space['\t'] = 1;
363 is_hor_space['\v'] = 1;
364 is_hor_space['\f'] = 1;
372 /* trigraph conversion */
373 trigraph_table['='] = '#'; trigraph_table[')'] = ']';
374 trigraph_table['!'] = '|'; trigraph_table['('] = '[';
375 trigraph_table['\''] = '^'; trigraph_table['>'] = '}';
376 trigraph_table['/'] = '\\'; trigraph_table['<'] = '{';
377 trigraph_table['-'] = '~';
380 #endif /* Not GCC. */
382 /* Given a colon-separated list of file names PATH,
383 add all the names to the search path for include files. */
386 path_include (pfile, pend, list, path)
388 struct cpp_pending *pend;
398 /* Find the end of this name. */
400 while (*q != 0 && *q != PATH_SEPARATOR) q++;
403 /* An empty name in the path stands for the current directory. */
404 name = (char *) xmalloc (2);
410 /* Otherwise use the directory that is named. */
411 name = (char *) xmalloc (q - p + 1);
412 memcpy (name, p, q - p);
416 append_include_chain (pfile, pend, name, path);
418 /* Advance past this name. */
426 /* Find the base name of a (partial) pathname FNAME.
427 Returns a pointer into the string passed in.
428 Accepts Unix (/-separated) paths on all systems,
429 DOS and VMS paths on those systems. */
434 char *s = (char *)fname;
436 #if defined (HAVE_DOS_BASED_FILE_SYSTEM)
437 if (ISALPHA (s[0]) && s[1] == ':') s += 2;
438 if ((p = rindex (s, '\\'))) s = p + 1;
440 if ((p = rindex (s, ':'))) s = p + 1; /* Skip device. */
441 if ((p = rindex (s, ']'))) s = p + 1; /* Skip directory. */
442 if ((p = rindex (s, '>'))) s = p + 1; /* Skip alternate (int'n'l) dir. */
444 if ((p = rindex (s, '/'))) s = p + 1;
449 /* Append DIR to include path PATH. DIR must be permanently allocated
452 append_include_chain (pfile, pend, dir, path)
454 struct cpp_pending *pend;
458 struct file_name_list *new;
462 simplify_pathname (dir);
465 /* Dirs that don't exist are silently ignored. */
467 cpp_perror_with_name (pfile, dir);
468 else if (CPP_OPTIONS (pfile)->verbose)
469 cpp_notice ("ignoring nonexistent directory `%s'\n", dir);
473 if (!S_ISDIR (st.st_mode))
475 cpp_message (pfile, 1, "%s: %s: Not a directory", progname, dir);
480 if (len > pfile->max_include_len)
481 pfile->max_include_len = len;
483 new = (struct file_name_list *)xmalloc (sizeof (struct file_name_list));
486 new->ino = st.st_ino;
487 new->dev = st.st_dev;
488 new->sysp = (path == SYSTEM);
489 new->name_map = NULL;
493 case QUOTE: APPEND (pend, quote, new); break;
494 case BRACKET: APPEND (pend, brack, new); break;
495 case SYSTEM: APPEND (pend, systm, new); break;
496 case AFTER: APPEND (pend, after, new); break;
501 /* Write out a #define command for the special named MACRO_NAME
502 to PFILE's token_buffer. */
505 dump_special_to_buffer (pfile, macro_name)
509 static char define_directive[] = "#define ";
510 int macro_name_length = strlen (macro_name);
511 output_line_command (pfile, same_file);
512 CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length);
513 CPP_PUTS_Q (pfile, define_directive, sizeof(define_directive)-1);
514 CPP_PUTS_Q (pfile, macro_name, macro_name_length);
515 CPP_PUTC_Q (pfile, ' ');
516 cpp_expand_to_buffer (pfile, macro_name, macro_name_length);
517 CPP_PUTC (pfile, '\n');
520 /* Initialize a cpp_options structure. */
522 cpp_options_init (opts)
525 bzero ((char *) opts, sizeof (struct cpp_options));
527 opts->dollars_in_ident = 1;
528 opts->cplusplus_comments = 1;
529 opts->warn_import = 1;
531 opts->pending = (struct cpp_pending *) xmalloc (sizeof (struct cpp_pending));
532 bzero ((char *) opts->pending, sizeof (struct cpp_pending));
535 /* Initialize a cpp_reader structure. */
537 cpp_reader_init (pfile)
540 bzero ((char *) pfile, sizeof (cpp_reader));
542 pfile->get_token = cpp_get_token;
545 pfile->token_buffer_size = 200;
546 pfile->token_buffer = (U_CHAR *) xmalloc (pfile->token_buffer_size);
547 CPP_SET_WRITTEN (pfile, 0);
549 pfile->hashtab = (HASHNODE **) xcalloc (HASHSIZE, sizeof (HASHNODE *));
552 /* Free resources used by PFILE.
553 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
559 while (CPP_BUFFER (pfile) != CPP_NULL_BUFFER (pfile))
560 cpp_pop_buffer (pfile);
562 if (pfile->token_buffer)
564 free (pfile->token_buffer);
565 pfile->token_buffer = NULL;
568 if (pfile->deps_buffer)
570 free (pfile->deps_buffer);
571 pfile->deps_buffer = NULL;
572 pfile->deps_allocated_size = 0;
575 if (pfile->input_buffer)
577 free (pfile->input_buffer);
578 free (pfile->input_speccase);
579 pfile->input_buffer = pfile->input_speccase = NULL;
580 pfile->input_buffer_len = 0;
583 while (pfile->if_stack)
585 IF_STACK_FRAME *temp = pfile->if_stack;
586 pfile->if_stack = temp->next;
590 for (i = ALL_INCLUDE_HASHSIZE; --i >= 0; )
592 struct include_hash *imp = pfile->all_include_files[i];
595 struct include_hash *next = imp->next;
597 /* This gets freed elsewhere - I think. */
603 pfile->all_include_files[i] = 0;
606 for (i = HASHSIZE; --i >= 0;)
608 while (pfile->hashtab[i])
609 delete_macro (pfile->hashtab[i]);
611 free (pfile->hashtab);
615 /* Initialize the built-in macros. */
617 initialize_builtins (pfile)
620 #define NAME(str) (U_CHAR *)str, sizeof str - 1
621 cpp_install (pfile, NAME("__TIME__"), T_TIME, 0, -1);
622 cpp_install (pfile, NAME("__DATE__"), T_DATE, 0, -1);
623 cpp_install (pfile, NAME("__FILE__"), T_FILE, 0, -1);
624 cpp_install (pfile, NAME("__BASE_FILE__"), T_BASE_FILE, 0, -1);
625 cpp_install (pfile, NAME("__LINE__"), T_SPECLINE, 0, -1);
626 cpp_install (pfile, NAME("__INCLUDE_LEVEL__"), T_INCLUDE_LEVEL, 0, -1);
627 cpp_install (pfile, NAME("__VERSION__"), T_VERSION, 0, -1);
628 #ifndef NO_BUILTIN_SIZE_TYPE
629 cpp_install (pfile, NAME("__SIZE_TYPE__"), T_CONST, SIZE_TYPE, -1);
631 #ifndef NO_BUILTIN_PTRDIFF_TYPE
632 cpp_install (pfile, NAME("__PTRDIFF_TYPE__ "), T_CONST, PTRDIFF_TYPE, -1);
634 cpp_install (pfile, NAME("__WCHAR_TYPE__"), T_CONST, WCHAR_TYPE, -1);
635 cpp_install (pfile, NAME("__USER_LABEL_PREFIX__"), T_CONST, user_label_prefix, -1);
636 cpp_install (pfile, NAME("__REGISTER_PREFIX__"), T_CONST, REGISTER_PREFIX, -1);
637 cpp_install (pfile, NAME("__HAVE_BUILTIN_SETJMP__"), T_CONST, "1", -1);
638 if (!CPP_TRADITIONAL (pfile))
640 cpp_install (pfile, NAME("__STDC__"), T_STDC, 0, -1);
642 if (CPP_OPTIONS (pfile)->c9x)
643 cpp_install (pfile, NAME("__STDC_VERSION__"),T_CONST, "199909L", -1);
646 cpp_install (pfile, NAME("__STDC_VERSION__"),T_CONST, "199409L", -1);
650 if (CPP_OPTIONS (pfile)->debug_output)
652 dump_special_to_buffer (pfile, "__BASE_FILE__");
653 dump_special_to_buffer (pfile, "__VERSION__");
654 #ifndef NO_BUILTIN_SIZE_TYPE
655 dump_special_to_buffer (pfile, "__SIZE_TYPE__");
657 #ifndef NO_BUILTIN_PTRDIFF_TYPE
658 dump_special_to_buffer (pfile, "__PTRDIFF_TYPE__");
660 dump_special_to_buffer (pfile, "__WCHAR_TYPE__");
661 dump_special_to_buffer (pfile, "__DATE__");
662 dump_special_to_buffer (pfile, "__TIME__");
663 if (!CPP_TRADITIONAL (pfile))
664 dump_special_to_buffer (pfile, "__STDC__");
668 /* Another subroutine of cpp_start_read. This one sets up to do
669 dependency-file output. */
671 initialize_dependency_output (pfile)
674 cpp_options *opts = CPP_OPTIONS (pfile);
675 char *spec, *s, *output_file;
677 /* Either of two environment variables can specify output of deps.
678 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
679 where OUTPUT_FILE is the file to write deps info to
680 and DEPS_TARGET is the target to mention in the deps. */
682 if (opts->print_deps == 0)
684 spec = getenv ("DEPENDENCIES_OUTPUT");
686 opts->print_deps = 1;
689 spec = getenv ("SUNPRO_DEPENDENCIES");
691 opts->print_deps = 2;
696 /* Find the space before the DEPS_TARGET, if there is one. */
697 s = strchr (spec, ' ');
700 opts->deps_target = s + 1;
701 output_file = (char *) xmalloc (s - spec + 1);
702 memcpy (output_file, spec, s - spec);
703 output_file[s - spec] = 0;
707 opts->deps_target = 0;
711 opts->deps_file = output_file;
712 opts->print_deps_append = 1;
715 /* Print the expected object file name as the target of this Make-rule. */
716 pfile->deps_allocated_size = 200;
717 pfile->deps_buffer = (char *) xmalloc (pfile->deps_allocated_size);
718 pfile->deps_buffer[0] = 0;
719 pfile->deps_size = 0;
720 pfile->deps_column = 0;
722 if (opts->deps_target)
723 deps_output (pfile, opts->deps_target, ':');
724 else if (*opts->in_fname == 0)
725 deps_output (pfile, "-", ':');
731 /* Discard all directory prefixes from filename. */
732 q = base_name (opts->in_fname);
734 /* Copy remainder to mungable area. */
736 p = (char *) alloca (len + 8);
739 /* Output P, but remove known suffixes. */
741 /* Point to the filename suffix. */
743 /* Compare against the known suffixes. */
744 for (x = 0; known_suffixes[x]; x++)
746 if (strncmp (known_suffixes[x], r, q - r) == 0)
748 /* Make q point to the bit we're going to overwrite
749 with an object suffix. */
755 /* Supply our own suffix. */
756 strcpy (q, OBJECT_SUFFIX);
758 deps_output (pfile, p, ':');
759 deps_output (pfile, opts->in_fname, ' ');
763 /* This is called after options have been processed.
764 * Check options for consistency, and setup for processing input
765 * from the file named FNAME. (Use standard input if FNAME==NULL.)
766 * Return 1 on success, 0 on failure.
770 cpp_start_read (pfile, fname)
774 struct cpp_options *opts = CPP_OPTIONS (pfile);
775 struct pending_option *p, *q;
778 struct include_hash *ih_fake;
780 /* -MG doesn't select the form of output and must be specified with one of
781 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
782 inhibit compilation. */
783 if (opts->print_deps_missing_files
784 && (opts->print_deps == 0 || !opts->no_output))
786 cpp_fatal (pfile, "-MG must be specified with one of -M or -MM");
790 /* Chill should not be used with -trigraphs. */
791 if (opts->chill && opts->trigraphs)
793 cpp_warning (pfile, "-lang-chill and -trigraphs are mutually exclusive");
797 /* Set this if it hasn't been set already. */
798 if (user_label_prefix == NULL)
799 user_label_prefix = USER_LABEL_PREFIX;
801 /* Now that we know dollars_in_ident, we can initialize the syntax
803 initialize_char_syntax (opts->dollars_in_ident);
805 /* Do partial setup of input buffer for the sake of generating
806 early #line directives (when -g is in effect). */
807 fp = cpp_push_buffer (pfile, NULL, 0);
810 if (opts->in_fname == NULL || *opts->in_fname == 0)
812 opts->in_fname = fname;
813 if (opts->in_fname == NULL)
816 fp->nominal_fname = fp->fname = opts->in_fname;
819 /* Install __LINE__, etc. Must follow initialize_char_syntax
820 and option processing. */
821 initialize_builtins (pfile);
823 /* Do -U's, -D's and -A's in the order they were seen. */
824 p = opts->pending->define_head;
827 if (opts->debug_output)
828 output_line_command (pfile, same_file);
830 cpp_undef (pfile, p->arg);
832 cpp_define (pfile, p->arg);
839 p = opts->pending->assert_head;
842 if (opts->debug_output)
843 output_line_command (pfile, same_file);
845 cpp_unassert (pfile, p->arg);
847 cpp_assert (pfile, p->arg);
854 opts->done_initializing = 1;
856 /* Several environment variables may add to the include search path.
857 CPATH specifies an additional list of directories to be searched
858 as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH,
859 etc. specify an additional list of directories to be searched as
860 if specified with -isystem, for the language indicated.
862 These variables are ignored if -nostdinc is on. */
863 if (! opts->no_standard_includes)
866 GET_ENV_PATH_LIST (path, "CPATH");
867 if (path != 0 && *path != 0)
868 path_include (pfile, opts->pending, path, BRACKET);
870 switch ((opts->objc << 1) + opts->cplusplus)
873 GET_ENV_PATH_LIST (path, "C_INCLUDE_PATH");
876 GET_ENV_PATH_LIST (path, "CPLUS_INCLUDE_PATH");
879 GET_ENV_PATH_LIST (path, "OBJC_INCLUDE_PATH");
882 GET_ENV_PATH_LIST (path, "OBJCPLUS_INCLUDE_PATH");
885 if (path != 0 && *path != 0)
886 path_include (pfile, opts->pending, path, SYSTEM);
889 /* Unless -nostdinc, add the compiled-in include path to the list,
890 translating prefixes. */
891 if (!opts->no_standard_includes)
893 struct default_include *p = include_defaults_array;
894 char *specd_prefix = opts->include_prefix;
896 /* Search "translated" versions of GNU directories.
897 These have /usr/local/lib/gcc... replaced by specd_prefix. */
898 if (specd_prefix != 0)
900 char *default_prefix = alloca (sizeof GCC_INCLUDE_DIR - 7);
901 /* Remove the `include' from /usr/local/lib/gcc.../include.
902 GCC_INCLUDE_DIR will always end in /include. */
903 int default_len = sizeof GCC_INCLUDE_DIR - 8;
904 int specd_len = strlen (specd_prefix);
906 default_len = sizeof GCC_INCLUDE_DIR - 8;
907 memcpy (default_prefix, GCC_INCLUDE_DIR, default_len);
908 default_prefix[default_len] = '\0';
910 for (p = include_defaults_array; p->fname; p++)
912 /* Some standard dirs are only for C++. */
915 && !opts->no_standard_cplusplus_includes))
917 /* Does this dir start with the prefix? */
918 if (!strncmp (p->fname, default_prefix, default_len))
920 /* Yes; change prefix and add to search list. */
921 int flen = strlen (p->fname);
922 int this_len = specd_len + flen - default_len;
923 char *str = (char *) xmalloc (this_len + 1);
924 memcpy (str, specd_prefix, specd_len);
925 memcpy (str + specd_len,
926 p->fname + default_len,
927 flen - default_len + 1);
929 append_include_chain (pfile, opts->pending,
936 /* Search ordinary names for GNU include directories. */
937 for (p = include_defaults_array; p->fname; p++)
939 /* Some standard dirs are only for C++. */
942 && !opts->no_standard_cplusplus_includes))
944 char *str = (char *) update_path (p->fname, p->component);
945 str = xstrdup (str); /* XXX Potential memory leak! */
946 append_include_chain (pfile, opts->pending, str, SYSTEM);
951 merge_include_chains (opts);
953 /* With -v, print the list of dirs to search. */
956 struct file_name_list *p;
957 cpp_message (pfile, -1, "#include \"...\" search starts here:\n");
958 for (p = opts->quote_include; p; p = p->next)
960 if (p == opts->bracket_include)
961 cpp_message (pfile, -1, "#include <...> search starts here:\n");
962 fprintf (stderr, " %s\n", p->name);
964 cpp_message (pfile, -1, "End of search list.\n");
967 /* Open the main input file.
968 We do this in nonblocking mode so we don't get stuck here if
969 someone clever has asked cpp to process /dev/rmt0;
970 finclude() will check that we have a real file to work with. */
971 if (fname == NULL || *fname == 0)
976 else if ((f = open (fname, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666)) < 0)
977 cpp_pfatal_with_name (pfile, fname);
979 initialize_dependency_output (pfile);
981 /* Must call finclude() on the main input before processing
982 -include switches; otherwise the -included text winds up
983 after the main input. */
984 ih_fake = (struct include_hash *) xmalloc (sizeof (struct include_hash));
986 ih_fake->next_this_file = 0;
987 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
988 ih_fake->name = fname;
989 ih_fake->control_macro = 0;
990 ih_fake->buf = (char *)-1;
992 if (!finclude (pfile, f, ih_fake))
994 output_line_command (pfile, same_file);
995 pfile->only_seen_white = 2;
997 /* The -imacros files can be scanned now, but the -include files
998 have to be pushed onto the include stack and processed later,
999 in the main loop calling cpp_get_token. */
1001 pfile->no_record_file++;
1003 p = opts->pending->imacros_head;
1006 int fd = open (p->arg, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666);
1009 cpp_perror_with_name (pfile, p->arg);
1012 if (!cpp_push_buffer (pfile, NULL, 0))
1015 ih_fake = (struct include_hash *)
1016 xmalloc (sizeof (struct include_hash));
1018 ih_fake->next_this_file = 0;
1019 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
1020 ih_fake->name = p->arg;
1021 ih_fake->control_macro = 0;
1022 ih_fake->buf = (char *)-1;
1024 if (!finclude (pfile, fd, ih_fake))
1025 cpp_scan_buffer (pfile);
1035 p = opts->pending->include_head;
1038 int fd = open (p->arg, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666);
1041 cpp_perror_with_name (pfile, p->arg);
1044 if (!cpp_push_buffer (pfile, NULL, 0))
1047 ih_fake = (struct include_hash *)
1048 xmalloc (sizeof (struct include_hash));
1050 ih_fake->next_this_file = 0;
1051 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
1052 ih_fake->name = p->arg;
1053 ih_fake->control_macro = 0;
1054 ih_fake->buf = (char *)-1;
1056 if (finclude (pfile, fd, ih_fake))
1057 output_line_command (pfile, enter_file);
1063 pfile->no_record_file--;
1065 free (opts->pending);
1066 opts->pending = NULL;
1071 /* This is called at the end of preprocessing. It pops the
1072 last buffer and writes dependency output. It should also
1073 clear macro definitions, such that you could call cpp_start_read
1074 with a new filename to restart processing. */
1079 struct cpp_options *opts = CPP_OPTIONS (pfile);
1081 if (CPP_PREV_BUFFER (CPP_BUFFER (pfile)) != CPP_NULL_BUFFER (pfile))
1083 "cpplib internal error: buffers still stacked in cpp_finish");
1084 cpp_pop_buffer (pfile);
1086 if (opts->print_deps)
1088 /* Stream on which to print the dependency information. */
1091 /* Don't actually write the deps file if compilation has failed. */
1092 if (pfile->errors == 0)
1094 char *deps_mode = opts->print_deps_append ? "a" : "w";
1095 if (opts->deps_file == 0)
1096 deps_stream = stdout;
1097 else if ((deps_stream = fopen (opts->deps_file, deps_mode)) == 0)
1098 cpp_pfatal_with_name (pfile, opts->deps_file);
1099 fputs (pfile->deps_buffer, deps_stream);
1100 putc ('\n', deps_stream);
1101 if (opts->deps_file)
1103 if (ferror (deps_stream) || fclose (deps_stream) != 0)
1104 cpp_fatal (pfile, "I/O error on output");
1109 if (opts->dump_macros == dump_only)
1114 for (i = HASHSIZE; --i >= 0;)
1116 for (h = pfile->hashtab[i]; h; h = h->next)
1117 if (h->type == T_MACRO)
1119 m.defn = h->value.defn;
1121 m.symlen = h->length;
1122 dump_definition (pfile, m);
1123 CPP_PUTC (pfile, '\n');
1129 /* Handle one command-line option in (argc, argv).
1130 Can be called multiple times, to handle multiple sets of options.
1131 Returns number of strings consumed. */
1133 cpp_handle_option (pfile, argc, argv)
1138 struct cpp_options *opts = CPP_OPTIONS (pfile);
1141 if (argv[i][0] != '-')
1143 if (opts->out_fname != NULL)
1146 cpp_fatal (pfile, "Too many arguments");
1148 else if (opts->in_fname != NULL)
1149 opts->out_fname = argv[i];
1151 opts->in_fname = argv[i];
1157 if (!strcmp (argv[i], "-fleading-underscore"))
1158 user_label_prefix = "_";
1159 else if (!strcmp (argv[i], "-fno-leading-underscore"))
1160 user_label_prefix = "";
1163 case 'I': /* Add directory to path for includes. */
1164 if (!strcmp (argv[i] + 2, "-"))
1167 Use the preceding -I directories for #include "..."
1168 but not #include <...>.
1169 Don't search the directory of the present file
1170 for #include "...". (Note that -I. -I- is not the same as
1171 the default setup; -I. uses the compiler's working dir.) */
1172 if (! opts->ignore_srcdir)
1174 opts->ignore_srcdir = 1;
1175 opts->pending->quote_head = opts->pending->brack_head;
1176 opts->pending->quote_tail = opts->pending->brack_tail;
1177 opts->pending->brack_head = 0;
1178 opts->pending->brack_tail = 0;
1182 cpp_fatal (pfile, "-I- specified twice");
1189 if (argv[i][2] != 0)
1190 fname = argv[i] + 2;
1191 else if (i + 1 == argc)
1192 goto missing_dirname;
1195 append_include_chain (pfile, opts->pending,
1196 xstrdup (fname), BRACKET);
1201 /* Add directory to beginning of system include path, as a system
1202 include directory. */
1203 if (!strcmp (argv[i], "-isystem"))
1206 goto missing_filename;
1207 append_include_chain (pfile, opts->pending,
1208 xstrdup (argv[++i]), SYSTEM);
1210 else if (!strcmp (argv[i], "-include"))
1213 goto missing_filename;
1216 struct pending_option *o = (struct pending_option *)
1217 xmalloc (sizeof (struct pending_option));
1220 /* This list has to be built in reverse order so that
1221 when cpp_start_read pushes all the -include files onto
1222 the buffer stack, they will be scanned in forward order. */
1223 o->next = opts->pending->include_head;
1224 opts->pending->include_head = o;
1227 else if (!strcmp (argv[i], "-imacros"))
1230 goto missing_filename;
1233 struct pending_option *o = (struct pending_option *)
1234 xmalloc (sizeof (struct pending_option));
1238 APPEND (opts->pending, imacros, o);
1241 /* Add directory to end of path for includes,
1242 with the default prefix at the front of its name. */
1243 else if (!strcmp (argv[i], "-iwithprefix"))
1248 goto missing_dirname;
1250 len = strlen (argv[i]);
1252 if (opts->include_prefix != 0)
1254 fname = xmalloc (opts->include_prefix_len + len + 1);
1255 memcpy (fname, opts->include_prefix, opts->include_prefix_len);
1256 memcpy (fname + opts->include_prefix_len, argv[i], len + 1);
1260 fname = xmalloc (sizeof GCC_INCLUDE_DIR - 8 + len);
1261 memcpy (fname, GCC_INCLUDE_DIR, sizeof GCC_INCLUDE_DIR - 9);
1262 memcpy (fname + sizeof GCC_INCLUDE_DIR - 9, argv[i], len + 1);
1265 append_include_chain (pfile, opts->pending, fname, SYSTEM);
1267 /* Add directory to main path for includes,
1268 with the default prefix at the front of its name. */
1269 else if (!strcmp (argv[i], "-iwithprefixbefore"))
1274 goto missing_dirname;
1276 len = strlen (argv[i]);
1278 if (opts->include_prefix != 0)
1280 fname = xmalloc (opts->include_prefix_len + len + 1);
1281 memcpy (fname, opts->include_prefix, opts->include_prefix_len);
1282 memcpy (fname + opts->include_prefix_len, argv[i], len + 1);
1286 fname = xmalloc (sizeof GCC_INCLUDE_DIR - 8 + len);
1287 memcpy (fname, GCC_INCLUDE_DIR, sizeof GCC_INCLUDE_DIR - 9);
1288 memcpy (fname + sizeof GCC_INCLUDE_DIR - 9, argv[i], len + 1);
1291 append_include_chain (pfile, opts->pending, fname, BRACKET);
1293 /* Add directory to end of path for includes. */
1294 else if (!strcmp (argv[i], "-idirafter"))
1297 goto missing_dirname;
1298 append_include_chain (pfile, opts->pending,
1299 xstrdup (argv[++i]), AFTER);
1301 else if (!strcmp (argv[i], "-iprefix"))
1304 goto missing_filename;
1307 opts->include_prefix = argv[++i];
1308 opts->include_prefix_len = strlen (argv[i]);
1311 else if (!strcmp (argv[i], "-ifoutput"))
1312 opts->output_conditionals = 1;
1317 if (opts->out_fname != NULL)
1319 cpp_fatal (pfile, "Output filename specified twice");
1323 goto missing_filename;
1324 opts->out_fname = argv[++i];
1325 if (!strcmp (opts->out_fname, "-"))
1326 opts->out_fname = "";
1330 if (!strcmp (argv[i], "-pedantic"))
1331 CPP_PEDANTIC (pfile) = 1;
1332 else if (!strcmp (argv[i], "-pedantic-errors"))
1334 CPP_PEDANTIC (pfile) = 1;
1335 opts->pedantic_errors = 1;
1338 else if (!strcmp (argv[i], "-pcp")) {
1339 char *pcp_fname = argv[++i];
1340 pcp_outfile = ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
1341 ? fopen (pcp_fname, "w")
1342 : fdopen (dup (fileno (stdout)), "w"));
1343 if (pcp_outfile == 0)
1344 cpp_pfatal_with_name (pfile, pcp_fname);
1351 if (!strcmp (argv[i], "-traditional"))
1353 opts->traditional = 1;
1354 opts->cplusplus_comments = 0;
1356 else if (!strcmp (argv[i], "-trigraphs"))
1357 opts->trigraphs = 1;
1361 if (! strcmp (argv[i], "-lang-c"))
1362 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
1363 opts->c9x = 1, opts->objc = 0;
1364 if (! strcmp (argv[i], "-lang-c89"))
1365 opts->cplusplus = 0, opts->cplusplus_comments = 0, opts->c89 = 1,
1366 opts->c9x = 0, opts->objc = 0;
1367 if (! strcmp (argv[i], "-lang-c++"))
1368 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0,
1369 opts->c9x = 0, opts->objc = 0;
1370 if (! strcmp (argv[i], "-lang-objc"))
1371 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
1372 opts->c9x = 0, opts->objc = 1;
1373 if (! strcmp (argv[i], "-lang-objc++"))
1374 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0,
1375 opts->c9x = 0, opts->objc = 1;
1376 if (! strcmp (argv[i], "-lang-asm"))
1378 if (! strcmp (argv[i], "-lint"))
1380 if (! strcmp (argv[i], "-lang-chill"))
1381 opts->objc = 0, opts->cplusplus = 0, opts->chill = 1,
1382 opts->traditional = 1;
1386 opts->cplusplus = 1, opts->cplusplus_comments = 1;
1390 if (!strcmp (argv[i], "-std=iso9899:1990")
1391 || !strcmp (argv[i], "-std=iso9899:199409")
1392 || !strcmp (argv[i], "-std=c89")
1393 || !strcmp (argv[i], "-std=gnu89"))
1394 opts->cplusplus = 0, opts->cplusplus_comments = 0,
1395 opts->c89 = 1, opts->c9x = 0, opts->objc = 0;
1396 else if (!strcmp (argv[i], "-std=iso9899:199x")
1397 || !strcmp (argv[i], "-std=c9x")
1398 || !strcmp (argv[i], "-std=gnu9x"))
1399 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
1400 opts->c9x = 1, opts->objc = 0;
1404 opts->inhibit_warnings = 1;
1408 if (!strcmp (argv[i], "-Wtrigraphs"))
1409 opts->warn_trigraphs = 1;
1410 else if (!strcmp (argv[i], "-Wno-trigraphs"))
1411 opts->warn_trigraphs = 0;
1412 else if (!strcmp (argv[i], "-Wcomment"))
1413 opts->warn_comments = 1;
1414 else if (!strcmp (argv[i], "-Wno-comment"))
1415 opts->warn_comments = 0;
1416 else if (!strcmp (argv[i], "-Wcomments"))
1417 opts->warn_comments = 1;
1418 else if (!strcmp (argv[i], "-Wno-comments"))
1419 opts->warn_comments = 0;
1420 else if (!strcmp (argv[i], "-Wtraditional"))
1421 opts->warn_stringify = 1;
1422 else if (!strcmp (argv[i], "-Wno-traditional"))
1423 opts->warn_stringify = 0;
1424 else if (!strcmp (argv[i], "-Wundef"))
1425 opts->warn_undef = 1;
1426 else if (!strcmp (argv[i], "-Wno-undef"))
1427 opts->warn_undef = 0;
1428 else if (!strcmp (argv[i], "-Wimport"))
1429 opts->warn_import = 1;
1430 else if (!strcmp (argv[i], "-Wno-import"))
1431 opts->warn_import = 0;
1432 else if (!strcmp (argv[i], "-Werror"))
1433 opts->warnings_are_errors = 1;
1434 else if (!strcmp (argv[i], "-Wno-error"))
1435 opts->warnings_are_errors = 0;
1436 else if (!strcmp (argv[i], "-Wall"))
1438 opts->warn_trigraphs = 1;
1439 opts->warn_comments = 1;
1444 /* The style of the choices here is a bit mixed.
1445 The chosen scheme is a hybrid of keeping all options in one string
1446 and specifying each option in a separate argument:
1447 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
1448 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
1449 -M[M][G][D file]. This is awkward to handle in specs, and is not
1451 /* ??? -MG must be specified in addition to one of -M or -MM.
1452 This can be relaxed in the future without breaking anything.
1453 The converse isn't true. */
1455 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
1456 if (!strcmp (argv[i], "-MG"))
1458 opts->print_deps_missing_files = 1;
1461 if (!strcmp (argv[i], "-M"))
1462 opts->print_deps = 2;
1463 else if (!strcmp (argv[i], "-MM"))
1464 opts->print_deps = 1;
1465 else if (!strcmp (argv[i], "-MD"))
1466 opts->print_deps = 2;
1467 else if (!strcmp (argv[i], "-MMD"))
1468 opts->print_deps = 1;
1469 /* For -MD and -MMD options, write deps on file named by next arg. */
1470 if (!strcmp (argv[i], "-MD") || !strcmp (argv[i], "-MMD"))
1473 goto missing_filename;
1474 opts->deps_file = argv[++i];
1478 /* For -M and -MM, write deps on standard output
1479 and suppress the usual output. */
1480 opts->no_output = 1;
1486 char *p = argv[i] + 2;
1488 while ((c = *p++) != 0)
1490 /* Arg to -d specifies what parts of macros to dump */
1494 opts->dump_macros = dump_only;
1495 opts->no_output = 1;
1498 opts->dump_macros = dump_names;
1501 opts->dump_macros = dump_definitions;
1504 opts->dump_includes = 1;
1512 if (argv[i][2] == '3')
1513 opts->debug_output = 1;
1517 if (!strcmp (argv[i], "--help"))
1519 else if (!strcmp (argv[i], "--version"))
1520 cpp_notice ("GNU CPP version %s\n", version_string);
1525 cpp_notice ("GNU CPP version %s", version_string);
1526 #ifdef TARGET_VERSION
1529 fputc ('\n', stderr);
1534 opts->print_include_names = 1;
1539 struct pending_option *o = (struct pending_option *)
1540 xmalloc (sizeof (struct pending_option));
1541 if (argv[i][2] != 0)
1542 o->arg = argv[i] + 2;
1543 else if (i + 1 == argc)
1545 cpp_fatal (pfile, "Macro name missing after -D option");
1553 APPEND (opts->pending, define, o);
1561 if (argv[i][2] != 0)
1563 else if (i + 1 == argc)
1565 cpp_fatal (pfile, "Assertion missing after -A option");
1571 if (strcmp (p, "-"))
1573 struct pending_option *o = (struct pending_option *)
1574 xmalloc (sizeof (struct pending_option));
1579 APPEND (opts->pending, assert, o);
1583 /* -A- eliminates all predefined macros and assertions.
1584 Let's include also any that were specified earlier
1585 on the command line. That way we can get rid of any
1586 that were passed automatically in from GCC. */
1587 struct pending_option *o1, *o2;
1589 o1 = opts->pending->define_head;
1596 o1 = opts->pending->assert_head;
1603 opts->pending->assert_head = NULL;
1604 opts->pending->assert_tail = NULL;
1605 opts->pending->define_head = NULL;
1606 opts->pending->define_tail = NULL;
1613 struct pending_option *o = (struct pending_option *)
1614 xmalloc (sizeof (struct pending_option));
1616 if (argv[i][2] != 0)
1617 o->arg = argv[i] + 2;
1618 else if (i + 1 == argc)
1620 cpp_fatal (pfile, "Macro name missing after -U option");
1628 APPEND (opts->pending, define, o);
1633 opts->put_out_comments = 1;
1636 case 'E': /* -E comes from cc -E; ignore it. */
1640 opts->no_line_commands = 1;
1643 case '$': /* Don't include $ in identifiers. */
1644 opts->dollars_in_ident = 0;
1648 if (!strcmp (argv[i], "-nostdinc"))
1649 /* -nostdinc causes no default include directories.
1650 You must specify all include-file directories with -I. */
1651 opts->no_standard_includes = 1;
1652 else if (!strcmp (argv[i], "-nostdinc++"))
1653 /* -nostdinc++ causes no default C++-specific include directories. */
1654 opts->no_standard_cplusplus_includes = 1;
1656 else if (!strcmp (argv[i], "-noprecomp"))
1662 if (!strcmp (argv[i], "-remap"))
1666 case '\0': /* JF handle '-' as file name meaning stdin or stdout */
1667 if (opts->in_fname == NULL)
1668 opts->in_fname = "";
1669 else if (opts->out_fname == NULL)
1670 opts->out_fname = "";
1672 return i; /* error */
1682 cpp_fatal (pfile, "Filename missing after `%s' option", argv[i]);
1685 cpp_fatal (pfile, "Directory name missing after `%s' option", argv[i]);
1689 /* Handle command-line options in (argc, argv).
1690 Can be called multiple times, to handle multiple sets of options.
1691 Returns if an unrecognized option is seen.
1692 Returns number of strings consumed. */
1695 cpp_handle_options (pfile, argc, argv)
1701 int strings_processed;
1702 for (i = 0; i < argc; i += strings_processed)
1704 strings_processed = cpp_handle_option (pfile, argc - i, argv + i);
1705 if (strings_processed == 0)
1714 cpp_notice ("Usage: %s [switches] input output\n", progname);
1717 -include <file> Include the contents of <file> before other files\n\
1718 -imacros <file> Accept definition of macros in <file>\n\
1719 -iprefix <path> Specify <path> as a prefix for next two options\n\
1720 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1721 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1722 -isystem <dir> Add <dir> to the start of the system include path\n\
1723 -idirafter <dir> Add <dir> to the end of the system include path\n\
1724 -I <dir> Add <dir> to the end of the main include path\n\
1725 -nostdinc Do not search system include directories\n\
1726 (dirs specified with -isystem will still be used)\n\
1727 -nostdinc++ Do not search system include directories for C++\n\
1728 -o <file> Put output into <file>\n\
1729 -pedantic Issue all warnings demanded by strict ANSI C\n\
1730 -traditional Follow K&R pre-processor behaviour\n\
1731 -trigraphs Support ANSI C trigraphs\n\
1732 -lang-c Assume that the input sources are in C\n\
1733 -lang-c89 Assume that the input sources are in C89\n\
1734 -lang-c++ Assume that the input sources are in C++\n\
1735 -lang-objc Assume that the input sources are in ObjectiveC\n\
1736 -lang-objc++ Assume that the input sources are in ObjectiveC++\n\
1737 -lang-asm Assume that the input sources are in assembler\n\
1738 -lang-chill Assume that the input sources are in Chill\n\
1739 -std=<std name> Specify the conformance standard; one of:\n\
1740 gnu89, gnu9x, c89, c9x, iso9899:1990,\n\
1741 iso9899:199409, iso9899:199x\n\
1742 -+ Allow parsing of C++ style features\n\
1743 -w Inhibit warning messages\n\
1744 -Wtrigraphs Warn if trigraphs are encountered\n\
1745 -Wno-trigraphs Do not warn about trigraphs\n\
1746 -Wcomment{s} Warn if one comment starts inside another\n\
1747 -Wno-comment{s} Do not warn about comments\n\
1748 -Wtraditional Warn if a macro argument is/would be turned into\n\
1749 a string if -traditional is specified\n\
1750 -Wno-traditional Do not warn about stringification\n\
1751 -Wundef Warn if an undefined macro is used by #if\n\
1752 -Wno-undef Do not warn about testing undefined macros\n\
1753 -Wimport Warn about the use of the #import directive\n\
1754 -Wno-import Do not warn about the use of #import\n\
1755 -Werror Treat all warnings as errors\n\
1756 -Wno-error Do not treat warnings as errors\n\
1757 -Wall Enable all preprocessor warnings\n\
1758 -M Generate make dependencies\n\
1759 -MM As -M, but ignore system header files\n\
1760 -MD As -M, but put output in a .d file\n\
1761 -MMD As -MD, but ignore system header files\n\
1762 -MG Treat missing header file as generated files\n\
1763 -g Include #define and #undef directives in the output\n\
1764 -D<macro> Define a <macro> with string '1' as its value\n\
1765 -D<macro>=<val> Define a <macro> with <val> as its value\n\
1766 -A<question> (<answer>) Assert the <answer> to <question>\n\
1767 -U<macro> Undefine <macro> \n\
1768 -v Display the version number\n\
1769 -H Print the name of header files as they are used\n\
1770 -C Do not discard comments\n\
1771 -dM Display a list of macro definitions active at end\n\
1772 -dD Preserve macro definitions in output\n\
1773 -dN As -dD except that only the names are preserved\n\
1774 -dI Include #include directives in the output\n\
1775 -ifoutput Describe skipped code blocks in output \n\
1776 -P Do not generate #line directives\n\
1777 -$ Do not allow '$' in identifiers\n\
1778 -remap Remap file names when including files.\n\
1779 -h or --help Display this information\n\