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. */
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 /* Windows does not natively support inodes, and neither does MSDOS.
41 Cygwin's emulation can generate non-unique inodes, so don't use it.
42 VMS has non-numeric inodes. */
44 #define INO_T_EQ(a, b) (!memcmp (&(a), &(b), sizeof (a)))
45 #elif (defined _WIN32 && ! defined (_UWIN)) || defined __MSDOS__
46 #define INO_T_EQ(a, b) 0
48 #define INO_T_EQ(a, b) ((a) == (b))
51 #ifndef STANDARD_INCLUDE_DIR
52 #define STANDARD_INCLUDE_DIR "/usr/include"
55 /* We let tm.h override the types used here, to handle trivial differences
56 such as the choice of unsigned int or long unsigned int for size_t.
57 When machines start needing nontrivial differences in the size type,
58 it would be best to do something here to figure out automatically
59 from other information what type to use. */
61 /* The string value for __SIZE_TYPE__. */
64 #define SIZE_TYPE "long unsigned int"
67 /* The string value for __PTRDIFF_TYPE__. */
70 #define PTRDIFF_TYPE "long int"
73 /* The string value for __WCHAR_TYPE__. */
76 #define WCHAR_TYPE "int"
79 /* The string value for __USER_LABEL_PREFIX__ */
81 #ifndef USER_LABEL_PREFIX
82 #define USER_LABEL_PREFIX ""
85 /* The string value for __REGISTER_PREFIX__ */
87 #ifndef REGISTER_PREFIX
88 #define REGISTER_PREFIX ""
91 /* This is the default list of directories to search for include files.
92 It may be overridden by the various -I and -ixxx options.
94 #include "file" looks in the same directory as the current file,
96 #include <file> just looks in this list.
98 All these directories are treated as `system' include directories
99 (they are not subject to pedantic warnings in some cases). */
101 struct default_include
103 const char *fname
; /* The name of the directory. */
104 const char *component
; /* The component containing the directory
105 (see update_path in prefix.c) */
106 int cplusplus
; /* Only look here if we're compiling C++. */
107 int cxx_aware
; /* Includes in this directory don't need to
108 be wrapped in extern "C" when compiling
112 #ifndef STANDARD_INCLUDE_COMPONENT
113 #define STANDARD_INCLUDE_COMPONENT 0
117 #undef LOCAL_INCLUDE_DIR
118 #undef SYSTEM_INCLUDE_DIR
119 #undef STANDARD_INCLUDE_DIR
121 #undef CROSS_INCLUDE_DIR
124 static const struct default_include include_defaults_array
[]
125 #ifdef INCLUDE_DEFAULTS
129 #ifdef GPLUSPLUS_INCLUDE_DIR
130 /* Pick up GNU C++ specific include files. */
131 { GPLUSPLUS_INCLUDE_DIR
, "G++", 1, 1 },
133 #ifdef LOCAL_INCLUDE_DIR
134 /* /usr/local/include comes before the fixincluded header files. */
135 { LOCAL_INCLUDE_DIR
, 0, 0, 1 },
137 #ifdef GCC_INCLUDE_DIR
138 /* This is the dir for fixincludes and for gcc's private headers. */
139 { GCC_INCLUDE_DIR
, "GCC", 0, 0 },
141 #ifdef CROSS_INCLUDE_DIR
142 /* One place the target system's headers might be. */
143 { CROSS_INCLUDE_DIR
, "GCC", 0, 0 },
145 #ifdef TOOL_INCLUDE_DIR
146 /* Another place the target system's headers might be. */
147 { TOOL_INCLUDE_DIR
, "BINUTILS", 0, 1 },
149 #ifdef SYSTEM_INCLUDE_DIR
150 /* Some systems have an extra dir of include files. */
151 { SYSTEM_INCLUDE_DIR
, 0, 0, 0 },
153 #ifdef STANDARD_INCLUDE_DIR
154 /* /usr/include comes dead last. */
155 { STANDARD_INCLUDE_DIR
, STANDARD_INCLUDE_COMPONENT
, 0, 0 },
159 #endif /* no INCLUDE_DEFAULTS */
161 /* Internal structures and prototypes. */
163 /* A `struct pending_option' remembers one -D, -A, -U, -include, or -imacros
164 switch. There are four lists: one for -D and -U, one for -A, one
165 for -include, one for -imacros. `undef' is set for -U, clear for
166 -D, ignored for the others.
167 (Future: add an equivalent of -U for -A) */
169 typedef void (* cl_directive_handler
) PARAMS ((cpp_reader
*, const char *));
170 struct pending_option
172 struct pending_option
*next
;
174 cl_directive_handler handler
;
177 /* The `pending' structure accumulates all the options that are not
178 actually processed until we hit cpp_start_read. It consists of
179 several lists, one for each type of option. We keep both head and
180 tail pointers for quick insertion. */
183 struct pending_option
*directive_head
, *directive_tail
;
185 struct file_name_list
*quote_head
, *quote_tail
;
186 struct file_name_list
*brack_head
, *brack_tail
;
187 struct file_name_list
*systm_head
, *systm_tail
;
188 struct file_name_list
*after_head
, *after_tail
;
190 struct pending_option
*imacros_head
, *imacros_tail
;
191 struct pending_option
*include_head
, *include_tail
;
195 #define APPEND(pend, list, elt) \
196 do { if (!(pend)->list##_head) (pend)->list##_head = (elt); \
197 else (pend)->list##_tail->next = (elt); \
198 (pend)->list##_tail = (elt); \
201 #define APPEND(pend, list, elt) \
202 do { if (!(pend)->list/**/_head) (pend)->list/**/_head = (elt); \
203 else (pend)->list/**/_tail->next = (elt); \
204 (pend)->list/**/_tail = (elt); \
208 static void print_help
PARAMS ((void));
209 static void path_include
PARAMS ((cpp_reader
*,
210 struct cpp_pending
*,
212 static void initialize_builtins
PARAMS ((cpp_reader
*));
213 static void append_include_chain
PARAMS ((cpp_reader
*,
214 struct cpp_pending
*,
216 static void merge_include_chains
PARAMS ((cpp_reader
*));
218 static void dump_special_to_buffer
PARAMS ((cpp_reader
*, const char *));
219 static void initialize_dependency_output
PARAMS ((cpp_reader
*));
220 static void initialize_standard_includes
PARAMS ((cpp_reader
*));
221 static void new_pending_directive
PARAMS ((struct cpp_pending
*,
223 cl_directive_handler
));
225 static int opt_comp
PARAMS ((const void *, const void *));
227 static int parse_option
PARAMS ((const char *));
228 static int handle_option
PARAMS ((cpp_reader
*, int, char **));
230 /* Fourth argument to append_include_chain: chain to use */
231 enum { QUOTE
= 0, BRACKET
, SYSTEM
, AFTER
};
233 /* If we have designated initializers (GCC >2.7, or C99) this table
234 can be initialized, constant data. Otherwise, it has to be filled
237 #if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
238 #define init_IStable() /* nothing */
239 #define ISTABLE const unsigned char _cpp_IStable[256] = {
241 #define s(p, v) [p] = v,
243 #define ISTABLE unsigned char _cpp_IStable[256] = { 0 }; \
244 static void init_IStable PARAMS ((void)) { \
245 unsigned char *x = _cpp_IStable;
247 #define s(p, v) x[p] = v;
250 #define A(x) s(x, ISidnum|ISidstart)
251 #define N(x) s(x, ISidnum|ISnumstart)
252 #define H(x) s(x, IShspace|ISspace)
253 #define S(x) s(x, ISspace)
258 A('a') A('b') A('c') A('d') A('e') A('f') A('g') A('h') A('i')
259 A('j') A('k') A('l') A('m') A('n') A('o') A('p') A('q') A('r')
260 A('s') A('t') A('u') A('v') A('w') A('x') A('y') A('z')
262 A('A') A('B') A('C') A('D') A('E') A('F') A('G') A('H') A('I')
263 A('J') A('K') A('L') A('M') A('N') A('O') A('P') A('Q') A('R')
264 A('S') A('T') A('U') A('V') A('W') A('X') A('Y') A('Z')
266 N('1') N('2') N('3') N('4') N('5') N('6') N('7') N('8') N('9') N('0')
268 H('\0') H(' ') H('\t') H('\v') H('\f')
281 /* Given a colon-separated list of file names PATH,
282 add all the names to the search path for include files. */
285 path_include (pfile
, pend
, list
, path
)
287 struct cpp_pending
*pend
;
297 /* Find the end of this name. */
299 while (*q
!= 0 && *q
!= PATH_SEPARATOR
) q
++;
302 /* An empty name in the path stands for the current directory. */
303 name
= (char *) xmalloc (2);
309 /* Otherwise use the directory that is named. */
310 name
= (char *) xmalloc (q
- p
+ 1);
311 memcpy (name
, p
, q
- p
);
315 append_include_chain (pfile
, pend
, name
, path
, 0);
317 /* Advance past this name. */
325 /* Append DIR to include path PATH. DIR must be permanently allocated
328 append_include_chain (pfile
, pend
, dir
, path
, cxx_aware
)
330 struct cpp_pending
*pend
;
335 struct file_name_list
*new;
339 _cpp_simplify_pathname (dir
);
342 /* Dirs that don't exist are silently ignored. */
344 cpp_notice_from_errno (pfile
, dir
);
345 else if (CPP_OPTION (pfile
, verbose
))
346 fprintf (stderr
, _("ignoring nonexistent directory `%s'\n"), dir
);
350 if (!S_ISDIR (st
.st_mode
))
352 cpp_notice (pfile
, "%s: Not a directory", dir
);
357 if (len
> pfile
->max_include_len
)
358 pfile
->max_include_len
= len
;
360 new = (struct file_name_list
*) xmalloc (sizeof (struct file_name_list
));
363 new->ino
= st
.st_ino
;
364 new->dev
= st
.st_dev
;
366 new->sysp
= cxx_aware
? 1 : 2;
369 new->name_map
= NULL
;
375 case QUOTE
: APPEND (pend
, quote
, new); break;
376 case BRACKET
: APPEND (pend
, brack
, new); break;
377 case SYSTEM
: APPEND (pend
, systm
, new); break;
378 case AFTER
: APPEND (pend
, after
, new); break;
382 /* Merge the four include chains together in the order quote, bracket,
383 system, after. Remove duplicate dirs (as determined by
384 INO_T_EQ()). The system_include and after_include chains are never
385 referred to again after this function; all access is through the
386 bracket_include path.
388 For the future: Check if the directory is empty (but
389 how?) and possibly preload the include hash. */
392 merge_include_chains (pfile
)
395 struct file_name_list
*prev
, *cur
, *other
;
396 struct file_name_list
*quote
, *brack
, *systm
, *after
;
397 struct file_name_list
*qtail
, *btail
, *stail
, *atail
;
399 struct cpp_pending
*pend
= CPP_OPTION (pfile
, pending
);
401 qtail
= pend
->quote_tail
;
402 btail
= pend
->brack_tail
;
403 stail
= pend
->systm_tail
;
404 atail
= pend
->after_tail
;
406 quote
= pend
->quote_head
;
407 brack
= pend
->brack_head
;
408 systm
= pend
->systm_head
;
409 after
= pend
->after_head
;
411 /* Paste together bracket, system, and after include chains. */
421 /* This is a bit tricky.
422 First we drop dupes from the quote-include list.
423 Then we drop dupes from the bracket-include list.
424 Finally, if qtail and brack are the same directory,
427 We can't just merge the lists and then uniquify them because
428 then we may lose directories from the <> search path that should
429 be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however
430 safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written
431 -Ibar -I- -Ifoo -Iquux.
433 Note that this algorithm is quadratic in the number of -I switches,
434 which is acceptable since there aren't usually that many of them. */
436 for (cur
= quote
, prev
= NULL
; cur
; cur
= cur
->next
)
438 for (other
= quote
; other
!= cur
; other
= other
->next
)
439 if (INO_T_EQ (cur
->ino
, other
->ino
)
440 && cur
->dev
== other
->dev
)
442 if (CPP_OPTION (pfile
, verbose
))
443 fprintf (stderr
, _("ignoring duplicate directory `%s'\n"),
446 prev
->next
= cur
->next
;
456 for (cur
= brack
; cur
; cur
= cur
->next
)
458 for (other
= brack
; other
!= cur
; other
= other
->next
)
459 if (INO_T_EQ (cur
->ino
, other
->ino
)
460 && cur
->dev
== other
->dev
)
462 if (CPP_OPTION (pfile
, verbose
))
463 fprintf (stderr
, _("ignoring duplicate directory `%s'\n"),
466 prev
->next
= cur
->next
;
477 if (INO_T_EQ (qtail
->ino
, brack
->ino
) && qtail
->dev
== brack
->dev
)
481 if (CPP_OPTION (pfile
, verbose
))
482 fprintf (stderr
, _("ignoring duplicate directory `%s'\n"),
492 while (cur
->next
!= qtail
)
495 if (CPP_OPTION (pfile
, verbose
))
496 fprintf (stderr
, _("ignoring duplicate directory `%s'\n"),
509 CPP_OPTION (pfile
, quote_include
) = quote
;
510 CPP_OPTION (pfile
, bracket_include
) = brack
;
514 /* Write out a #define command for the special named MACRO_NAME
515 to PFILE's token_buffer. */
518 dump_special_to_buffer (pfile
, macro_name
)
520 const char *macro_name
;
522 static const char define_directive
[] = "#define ";
523 int macro_name_length
= strlen (macro_name
);
524 CPP_RESERVE (pfile
, sizeof(define_directive
) + macro_name_length
);
525 CPP_PUTS_Q (pfile
, define_directive
, sizeof(define_directive
)-1);
526 CPP_PUTS_Q (pfile
, macro_name
, macro_name_length
);
527 CPP_PUTC_Q (pfile
, ' ');
528 _cpp_expand_to_buffer (pfile
, macro_name
, macro_name_length
);
529 CPP_PUTC (pfile
, '\n');
532 /* Initialize a cpp_reader structure. */
534 cpp_reader_init (pfile
)
537 memset ((char *) pfile
, 0, sizeof (cpp_reader
));
539 pfile
->token_buffer_size
= 200;
540 pfile
->token_buffer
= (U_CHAR
*) xmalloc (pfile
->token_buffer_size
);
541 CPP_SET_WRITTEN (pfile
, 0);
543 CPP_OPTION (pfile
, dollars_in_ident
) = 1;
544 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
545 CPP_OPTION (pfile
, warn_import
) = 1;
546 CPP_OPTION (pfile
, discard_comments
) = 1;
547 CPP_OPTION (pfile
, show_column
) = 1;
549 CPP_OPTION (pfile
, pending
) =
550 (struct cpp_pending
*) xcalloc (1, sizeof (struct cpp_pending
));
552 _cpp_init_macro_hash (pfile
);
553 _cpp_init_include_hash (pfile
);
556 /* Initialize a cpp_printer structure. As a side effect, open the
559 cpp_printer_init (pfile
, print
)
563 memset (print
, '\0', sizeof (cpp_printer
));
564 if (CPP_OPTION (pfile
, out_fname
) == NULL
)
565 CPP_OPTION (pfile
, out_fname
) = "";
567 if (CPP_OPTION (pfile
, out_fname
)[0] == '\0')
568 print
->outf
= stdout
;
571 print
->outf
= fopen (CPP_OPTION (pfile
, out_fname
), "w");
574 cpp_notice_from_errno (pfile
, CPP_OPTION (pfile
, out_fname
));
581 /* Free resources used by PFILE.
582 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
587 while (CPP_BUFFER (pfile
) != NULL
)
588 cpp_pop_buffer (pfile
);
590 if (pfile
->token_buffer
)
592 free (pfile
->token_buffer
);
593 pfile
->token_buffer
= NULL
;
596 if (pfile
->input_buffer
)
598 free (pfile
->input_buffer
);
599 pfile
->input_buffer
= NULL
;
600 pfile
->input_buffer_len
= 0;
604 deps_free (pfile
->deps
);
606 htab_delete (pfile
->hashtab
);
607 htab_delete (pfile
->all_include_files
);
611 /* This structure defines one built-in macro. A node of type TYPE will
612 be entered in the macro hash table under the name NAME, with value
613 VALUE (if any). FLAGS tweaks the behavior a little:
614 DUMP write debug info for this macro
615 VERS value is the global version_string, quoted
616 ULP value is the global user_label_prefix
624 unsigned short flags
;
630 static const struct builtin builtin_array
[] =
632 { "__TIME__", 0, T_TIME
, 0 },
633 { "__DATE__", 0, T_DATE
, 0 },
634 { "__FILE__", 0, T_FILE
, 0 },
635 { "__BASE_FILE__", 0, T_BASE_FILE
, 0 },
636 { "__LINE__", 0, T_SPECLINE
, 0 },
637 { "__INCLUDE_LEVEL__", 0, T_INCLUDE_LEVEL
, 0 },
639 { "__VERSION__", 0, T_MCONST
, DUMP
|VERS
},
640 { "__USER_LABEL_PREFIX__", 0, T_CONST
, DUMP
|ULP
},
641 { "__STDC__", "1", T_STDC
, DUMP
},
642 { "__REGISTER_PREFIX__", REGISTER_PREFIX
, T_CONST
, DUMP
},
643 { "__HAVE_BUILTIN_SETJMP__", "1", T_CONST
, DUMP
},
644 #ifndef NO_BUILTIN_SIZE_TYPE
645 { "__SIZE_TYPE__", SIZE_TYPE
, T_CONST
, DUMP
},
647 #ifndef NO_BUILTIN_PTRDIFF_TYPE
648 { "__PTRDIFF_TYPE__", PTRDIFF_TYPE
, T_CONST
, DUMP
},
650 #ifndef NO_BUILTIN_WCHAR_TYPE
651 { "__WCHAR_TYPE__", WCHAR_TYPE
, T_CONST
, DUMP
},
654 #define builtin_array_end \
655 builtin_array + sizeof(builtin_array)/sizeof(struct builtin)
657 /* Subroutine of cpp_start_read; reads the builtins table above and
658 enters the macros into the hash table. */
660 initialize_builtins (pfile
)
664 const struct builtin
*b
;
667 for(b
= builtin_array
; b
< builtin_array_end
; b
++)
669 if (b
->type
== T_STDC
&& CPP_TRADITIONAL (pfile
))
673 val
= user_label_prefix
;
674 else if (b
->flags
& VERS
)
676 val
= xmalloc (strlen (version_string
) + 3);
677 sprintf ((char *)val
, "\"%s\"", version_string
);
682 len
= strlen (b
->name
);
683 hp
= _cpp_make_hashnode (b
->name
, len
, b
->type
,
684 _cpp_calc_hash (b
->name
, len
));
685 hp
->value
.cpval
= val
;
686 *(htab_find_slot (pfile
->hashtab
, (void *)hp
, 1)) = hp
;
688 if ((b
->flags
& DUMP
) && CPP_OPTION (pfile
, debug_output
))
689 dump_special_to_buffer (pfile
, b
->name
);
697 /* Another subroutine of cpp_start_read. This one sets up to do
698 dependency-file output. */
700 initialize_dependency_output (pfile
)
703 char *spec
, *s
, *output_file
;
705 /* Either of two environment variables can specify output of deps.
706 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
707 where OUTPUT_FILE is the file to write deps info to
708 and DEPS_TARGET is the target to mention in the deps. */
710 if (CPP_OPTION (pfile
, print_deps
) == 0)
712 spec
= getenv ("DEPENDENCIES_OUTPUT");
714 CPP_OPTION (pfile
, print_deps
) = 1;
717 spec
= getenv ("SUNPRO_DEPENDENCIES");
719 CPP_OPTION (pfile
, print_deps
) = 2;
724 /* Find the space before the DEPS_TARGET, if there is one. */
725 s
= strchr (spec
, ' ');
728 CPP_OPTION (pfile
, deps_target
) = s
+ 1;
729 output_file
= (char *) xmalloc (s
- spec
+ 1);
730 memcpy (output_file
, spec
, s
- spec
);
731 output_file
[s
- spec
] = 0;
735 CPP_OPTION (pfile
, deps_target
) = 0;
739 CPP_OPTION (pfile
, deps_file
) = output_file
;
740 CPP_OPTION (pfile
, print_deps_append
) = 1;
743 pfile
->deps
= deps_init ();
745 /* Print the expected object file name as the target of this Make-rule. */
746 if (CPP_OPTION (pfile
, deps_target
))
747 deps_add_target (pfile
->deps
, CPP_OPTION (pfile
, deps_target
));
748 else if (*CPP_OPTION (pfile
, in_fname
) == 0)
749 deps_add_target (pfile
->deps
, "-");
751 deps_calc_target (pfile
->deps
, CPP_OPTION (pfile
, in_fname
));
753 if (CPP_OPTION (pfile
, in_fname
))
754 deps_add_dep (pfile
->deps
, CPP_OPTION (pfile
, in_fname
));
757 /* And another subroutine. This one sets up the standard include path. */
759 initialize_standard_includes (pfile
)
763 const struct default_include
*p
;
764 const char *specd_prefix
= CPP_OPTION (pfile
, include_prefix
);
766 /* Several environment variables may add to the include search path.
767 CPATH specifies an additional list of directories to be searched
768 as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH,
769 etc. specify an additional list of directories to be searched as
770 if specified with -isystem, for the language indicated. */
772 GET_ENV_PATH_LIST (path
, "CPATH");
773 if (path
!= 0 && *path
!= 0)
774 path_include (pfile
, CPP_OPTION (pfile
, pending
), path
, BRACKET
);
776 switch ((CPP_OPTION (pfile
, objc
) << 1) + CPP_OPTION (pfile
, cplusplus
))
779 GET_ENV_PATH_LIST (path
, "C_INCLUDE_PATH");
782 GET_ENV_PATH_LIST (path
, "CPLUS_INCLUDE_PATH");
785 GET_ENV_PATH_LIST (path
, "OBJC_INCLUDE_PATH");
788 GET_ENV_PATH_LIST (path
, "OBJCPLUS_INCLUDE_PATH");
791 if (path
!= 0 && *path
!= 0)
792 path_include (pfile
, CPP_OPTION (pfile
, pending
), path
, SYSTEM
);
794 /* Search "translated" versions of GNU directories.
795 These have /usr/local/lib/gcc... replaced by specd_prefix. */
796 if (specd_prefix
!= 0)
798 char *default_prefix
= (char *) alloca (sizeof GCC_INCLUDE_DIR
- 7);
799 /* Remove the `include' from /usr/local/lib/gcc.../include.
800 GCC_INCLUDE_DIR will always end in /include. */
801 int default_len
= sizeof GCC_INCLUDE_DIR
- 8;
802 int specd_len
= strlen (specd_prefix
);
804 memcpy (default_prefix
, GCC_INCLUDE_DIR
, default_len
);
805 default_prefix
[default_len
] = '\0';
807 for (p
= include_defaults_array
; p
->fname
; p
++)
809 /* Some standard dirs are only for C++. */
811 || (CPP_OPTION (pfile
, cplusplus
)
812 && !CPP_OPTION (pfile
, no_standard_cplusplus_includes
)))
814 /* Does this dir start with the prefix? */
815 if (!strncmp (p
->fname
, default_prefix
, default_len
))
817 /* Yes; change prefix and add to search list. */
818 int flen
= strlen (p
->fname
);
819 int this_len
= specd_len
+ flen
- default_len
;
820 char *str
= (char *) xmalloc (this_len
+ 1);
821 memcpy (str
, specd_prefix
, specd_len
);
822 memcpy (str
+ specd_len
,
823 p
->fname
+ default_len
,
824 flen
- default_len
+ 1);
826 append_include_chain (pfile
, CPP_OPTION (pfile
, pending
),
827 str
, SYSTEM
, p
->cxx_aware
);
833 /* Search ordinary names for GNU include directories. */
834 for (p
= include_defaults_array
; p
->fname
; p
++)
836 /* Some standard dirs are only for C++. */
838 || (CPP_OPTION (pfile
, cplusplus
)
839 && !CPP_OPTION (pfile
, no_standard_cplusplus_includes
)))
841 /* XXX Potential memory leak! */
842 char *str
= xstrdup (update_path (p
->fname
, p
->component
));
843 append_include_chain (pfile
, CPP_OPTION (pfile
, pending
),
844 str
, SYSTEM
, p
->cxx_aware
);
849 /* This is called after options have been processed.
850 * Check options for consistency, and setup for processing input
851 * from the file named FNAME. (Use standard input if FNAME==NULL.)
852 * Return 1 on success, 0 on failure.
856 cpp_start_read (pfile
, print
, fname
)
861 struct pending_option
*p
, *q
;
863 /* -MG doesn't select the form of output and must be specified with one of
864 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
865 inhibit compilation. */
866 if (CPP_OPTION (pfile
, print_deps_missing_files
)
867 && (CPP_OPTION (pfile
, print_deps
) == 0
868 || !CPP_OPTION (pfile
, no_output
)))
870 cpp_fatal (pfile
, "-MG must be specified with one of -M or -MM");
874 /* Chill should not be used with -trigraphs. */
875 if (CPP_OPTION (pfile
, chill
) && CPP_OPTION (pfile
, trigraphs
))
877 cpp_warning (pfile
, "-lang-chill and -trigraphs are mutually exclusive");
878 CPP_OPTION (pfile
, trigraphs
) = 0;
881 /* -Wtraditional is not useful in C++ mode. */
882 if (CPP_OPTION (pfile
, cplusplus
))
883 CPP_OPTION (pfile
, warn_traditional
) = 0;
885 /* Set this if it hasn't been set already. */
886 if (user_label_prefix
== NULL
)
887 user_label_prefix
= USER_LABEL_PREFIX
;
889 /* Don't bother trying to do macro expansion if we've already done
891 if (CPP_OPTION (pfile
, preprocessed
))
892 pfile
->no_macro_expand
++;
894 /* Set up the IStable. This doesn't do anything if we were compiled
895 with a compiler that supports C99 designated initializers. */
898 /* Set up the tables used by read_and_prescan. */
899 _cpp_init_input_buffer (pfile
);
901 /* Set up the include search path now. */
902 if (! CPP_OPTION (pfile
, no_standard_includes
))
903 initialize_standard_includes (pfile
);
905 merge_include_chains (pfile
);
907 /* With -v, print the list of dirs to search. */
908 if (CPP_OPTION (pfile
, verbose
))
910 struct file_name_list
*l
;
911 fprintf (stderr
, _("#include \"...\" search starts here:\n"));
912 for (l
= CPP_OPTION (pfile
, quote_include
); l
; l
= l
->next
)
914 if (l
== CPP_OPTION (pfile
, bracket_include
))
915 fprintf (stderr
, _("#include <...> search starts here:\n"));
916 fprintf (stderr
, " %s\n", l
->name
);
918 fprintf (stderr
, _("End of search list.\n"));
921 /* Open the main input file. This must be done early, so we have a
922 buffer to stand on. */
923 if (CPP_OPTION (pfile
, in_fname
) == NULL
924 || *CPP_OPTION (pfile
, in_fname
) == 0)
926 CPP_OPTION (pfile
, in_fname
) = fname
;
927 if (CPP_OPTION (pfile
, in_fname
) == NULL
)
928 CPP_OPTION (pfile
, in_fname
) = "";
930 if (CPP_OPTION (pfile
, out_fname
) == NULL
)
931 CPP_OPTION (pfile
, out_fname
) = "";
933 if (!cpp_read_file (pfile
, fname
))
936 initialize_dependency_output (pfile
);
938 /* -D and friends may produce output, which should be identified
941 CPP_BUFFER (pfile
)->lineno
= 0;
946 print
->last_fname
= CPP_BUFFER (pfile
)->nominal_fname
;
947 print
->last_bsd
= pfile
->buffer_stack_depth
;
948 print
->written
= CPP_WRITTEN (pfile
);
951 /* Install __LINE__, etc. */
952 initialize_builtins (pfile
);
954 /* Do -U's, -D's and -A's in the order they were seen. */
955 p
= CPP_OPTION (pfile
, pending
)->directive_head
;
958 (*p
->handler
) (pfile
, p
->arg
);
963 pfile
->done_initializing
= 1;
964 pfile
->only_seen_white
= 2;
965 CPP_BUFFER (pfile
)->lineno
= 1;
966 if (print
&& ! CPP_OPTION (pfile
, no_output
))
967 cpp_output_tokens (pfile
, print
);
969 /* The -imacros files can be scanned now, but the -include files
970 have to be pushed onto the include stack and processed later,
971 in the main loop calling cpp_get_token. */
973 p
= CPP_OPTION (pfile
, pending
)->imacros_head
;
976 if (cpp_read_file (pfile
, p
->arg
))
977 cpp_scan_buffer_nooutput (pfile
);
983 p
= CPP_OPTION (pfile
, pending
)->include_head
;
986 if (cpp_read_file (pfile
, p
->arg
)
987 && print
&& ! CPP_OPTION (pfile
, no_output
))
988 cpp_output_tokens (pfile
, print
);
994 free (CPP_OPTION (pfile
, pending
));
995 CPP_OPTION (pfile
, pending
) = NULL
;
1000 /* This is called at the end of preprocessing. It pops the
1001 last buffer and writes dependency output. It should also
1002 clear macro definitions, such that you could call cpp_start_read
1003 with a new filename to restart processing. */
1005 cpp_finish (pfile
, print
)
1009 if (CPP_BUFFER (pfile
))
1011 cpp_ice (pfile
, "buffers still stacked in cpp_finish");
1012 while (CPP_BUFFER (pfile
))
1013 cpp_pop_buffer (pfile
);
1016 /* Don't write the deps file if preprocessing has failed. */
1017 if (CPP_OPTION (pfile
, print_deps
) && pfile
->errors
== 0)
1019 /* Stream on which to print the dependency information. */
1020 FILE *deps_stream
= 0;
1021 const char *deps_mode
1022 = CPP_OPTION (pfile
, print_deps_append
) ? "a" : "w";
1023 if (CPP_OPTION (pfile
, deps_file
) == 0)
1024 deps_stream
= stdout
;
1027 deps_stream
= fopen (CPP_OPTION (pfile
, deps_file
), deps_mode
);
1028 if (deps_stream
== 0)
1029 cpp_notice_from_errno (pfile
, CPP_OPTION (pfile
, deps_file
));
1033 deps_write (pfile
->deps
, deps_stream
, 72);
1034 if (CPP_OPTION (pfile
, deps_file
))
1036 if (ferror (deps_stream
) || fclose (deps_stream
) != 0)
1037 cpp_fatal (pfile
, "I/O error on output");
1042 if (CPP_OPTION (pfile
, dump_macros
) == dump_only
)
1043 _cpp_dump_macro_hash (pfile
);
1045 /* Flush any pending output. */
1048 cpp_output_tokens (pfile
, print
);
1049 if (ferror (print
->outf
) || fclose (print
->outf
))
1050 cpp_notice_from_errno (pfile
, CPP_OPTION (pfile
, out_fname
));
1055 new_pending_directive (pend
, text
, handler
)
1056 struct cpp_pending
*pend
;
1058 cl_directive_handler handler
;
1060 struct pending_option
*o
= (struct pending_option
*)
1061 xmalloc (sizeof (struct pending_option
));
1065 o
->handler
= handler
;
1066 APPEND (pend
, directive
, o
);
1069 /* Irix6 "cc -n32" and OSF4 cc have problems with char foo[] = ("string");
1070 I.e. a const string initializer with parens around it. That is
1071 what N_("string") resolves to, so we make no_* be macros instead. */
1072 #define no_arg N_("Argument missing after %s")
1073 #define no_ass N_("Assertion missing after %s")
1074 #define no_dir N_("Directory name missing after %s")
1075 #define no_fil N_("File name missing after %s")
1076 #define no_mac N_("Macro name missing after %s")
1077 #define no_pth N_("Path name missing after %s")
1079 /* This is the list of all command line options, with the leading
1080 "-" removed. It must be sorted in ASCII collating order. */
1081 #define COMMAND_LINE_OPTIONS \
1082 DEF_OPT("", 0, OPT_stdin_stdout) \
1083 DEF_OPT("$", 0, OPT_dollar) \
1084 DEF_OPT("+", 0, OPT_plus) \
1085 DEF_OPT("-help", 0, OPT__help) \
1086 DEF_OPT("-version", 0, OPT__version) \
1087 DEF_OPT("A", no_ass, OPT_A) \
1088 DEF_OPT("C", 0, OPT_C) \
1089 DEF_OPT("D", no_mac, OPT_D) \
1090 DEF_OPT("H", 0, OPT_H) \
1091 DEF_OPT("I", no_dir, OPT_I) \
1092 DEF_OPT("M", 0, OPT_M) \
1093 DEF_OPT("MD", no_fil, OPT_MD) \
1094 DEF_OPT("MG", 0, OPT_MG) \
1095 DEF_OPT("MM", 0, OPT_MM) \
1096 DEF_OPT("MMD", no_fil, OPT_MMD) \
1097 DEF_OPT("P", 0, OPT_P) \
1098 DEF_OPT("U", no_mac, OPT_U) \
1099 DEF_OPT("W", no_arg, OPT_W) /* arg optional */ \
1100 DEF_OPT("d", no_arg, OPT_d) \
1101 DEF_OPT("fleading-underscore", 0, OPT_fleading_underscore) \
1102 DEF_OPT("fno-leading-underscore", 0, OPT_fno_leading_underscore) \
1103 DEF_OPT("fno-preprocessed", 0, OPT_fno_preprocessed) \
1104 DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \
1105 DEF_OPT("fpreprocessed", 0, OPT_fpreprocessed) \
1106 DEF_OPT("fshow-column", 0, OPT_fshow_column) \
1107 DEF_OPT("g", no_arg, OPT_g) /* arg optional */ \
1108 DEF_OPT("h", 0, OPT_h) \
1109 DEF_OPT("idirafter", no_dir, OPT_idirafter) \
1110 DEF_OPT("imacros", no_fil, OPT_imacros) \
1111 DEF_OPT("include", no_fil, OPT_include) \
1112 DEF_OPT("iprefix", no_pth, OPT_iprefix) \
1113 DEF_OPT("isystem", no_dir, OPT_isystem) \
1114 DEF_OPT("iwithprefix", no_dir, OPT_iwithprefix) \
1115 DEF_OPT("iwithprefixbefore", no_dir, OPT_iwithprefixbefore) \
1116 DEF_OPT("lang-asm", 0, OPT_lang_asm) \
1117 DEF_OPT("lang-c", 0, OPT_lang_c) \
1118 DEF_OPT("lang-c++", 0, OPT_lang_cplusplus) \
1119 DEF_OPT("lang-c89", 0, OPT_lang_c89) \
1120 DEF_OPT("lang-chill", 0, OPT_lang_chill) \
1121 DEF_OPT("lang-fortran", 0, OPT_lang_fortran) \
1122 DEF_OPT("lang-objc", 0, OPT_lang_objc) \
1123 DEF_OPT("lang-objc++", 0, OPT_lang_objcplusplus) \
1124 DEF_OPT("nostdinc", 0, OPT_nostdinc) \
1125 DEF_OPT("nostdinc++", 0, OPT_nostdincplusplus) \
1126 DEF_OPT("o", no_fil, OPT_o) \
1127 DEF_OPT("pedantic", 0, OPT_pedantic) \
1128 DEF_OPT("pedantic-errors", 0, OPT_pedantic_errors) \
1129 DEF_OPT("remap", 0, OPT_remap) \
1130 DEF_OPT("std=c89", 0, OPT_std_c89) \
1131 DEF_OPT("std=c99", 0, OPT_std_c99) \
1132 DEF_OPT("std=c9x", 0, OPT_std_c9x) \
1133 DEF_OPT("std=gnu89", 0, OPT_std_gnu89) \
1134 DEF_OPT("std=gnu99", 0, OPT_std_gnu99) \
1135 DEF_OPT("std=gnu9x", 0, OPT_std_gnu9x) \
1136 DEF_OPT("std=iso9899:1990", 0, OPT_std_iso9899_1990) \
1137 DEF_OPT("std=iso9899:199409", 0, OPT_std_iso9899_199409) \
1138 DEF_OPT("std=iso9899:1999", 0, OPT_std_iso9899_1999) \
1139 DEF_OPT("std=iso9899:199x", 0, OPT_std_iso9899_199x) \
1140 DEF_OPT("traditional", 0, OPT_traditional) \
1141 DEF_OPT("trigraphs", 0, OPT_trigraphs) \
1142 DEF_OPT("v", 0, OPT_v) \
1143 DEF_OPT("w", 0, OPT_w)
1145 #define DEF_OPT(text, msg, code) code,
1148 COMMAND_LINE_OPTIONS
1155 const char *opt_text
;
1158 enum opt_code opt_code
;
1161 #define DEF_OPT(text, msg, code) { text, msg, sizeof(text) - 1, code },
1163 static struct cl_option cl_options
[] =
1165 static const struct cl_option cl_options
[] =
1168 COMMAND_LINE_OPTIONS
1171 #undef COMMAND_LINE_OPTIONS
1173 /* Perform a binary search to find which, if any, option the given
1174 command-line matches. Returns its index in the option array,
1175 negative on failure. Complications arise since some options can be
1176 suffixed with an argument, and multiple complete matches can occur,
1177 e.g. -iwithprefix and -iwithprefixbefore. Moreover, we want to
1178 accept options beginning with -g and -W that we do not recognise,
1179 but not to swallow any subsequent command line argument; these are
1180 handled as special cases in cpp_handle_option */
1182 parse_option (input
)
1185 unsigned int md
, mn
, mx
;
1196 opt_len
= cl_options
[md
].opt_len
;
1197 comp
= strncmp (input
, cl_options
[md
].opt_text
, opt_len
);
1205 if (input
[opt_len
] == '\0')
1207 /* We were passed more text. If the option takes an argument,
1208 we may match a later option or we may have been passed the
1209 argument. The longest possible option match succeeds.
1210 If the option takes no arguments we have not matched and
1211 continue the search (e.g. input="stdc++" match was "stdc") */
1213 if (cl_options
[md
].msg
)
1215 /* Scan forwards. If we get an exact match, return it.
1216 Otherwise, return the longest option-accepting match.
1217 This loops no more than twice with current options */
1219 for (; mn
< N_OPTS
; mn
++)
1221 opt_len
= cl_options
[mn
].opt_len
;
1222 if (strncmp (input
, cl_options
[mn
].opt_text
, opt_len
))
1224 if (input
[opt_len
] == '\0')
1226 if (cl_options
[mn
].msg
)
1237 /* Handle one command-line option in (argc, argv).
1238 Can be called multiple times, to handle multiple sets of options.
1239 Returns number of strings consumed. */
1242 handle_option (pfile
, argc
, argv
)
1249 if (argv
[i
][0] != '-')
1251 if (CPP_OPTION (pfile
, out_fname
) != NULL
)
1252 cpp_fatal (pfile
, "Too many arguments. Type %s --help for usage info",
1254 else if (CPP_OPTION (pfile
, in_fname
) != NULL
)
1255 CPP_OPTION (pfile
, out_fname
) = argv
[i
];
1257 CPP_OPTION (pfile
, in_fname
) = argv
[i
];
1261 enum opt_code opt_code
;
1263 const char *arg
= 0;
1266 opt_index
= parse_option (&argv
[i
][1]);
1270 opt_code
= cl_options
[opt_index
].opt_code
;
1271 if (cl_options
[opt_index
].msg
)
1273 arg
= &argv
[i
][cl_options
[opt_index
].opt_len
+ 1];
1275 /* Yuk. Special case for -g and -W as they must not swallow
1276 up any following argument. If this becomes common, add
1277 another field to the cl_options table */
1278 if (arg
[0] == '\0' && !(opt_code
== OPT_g
|| opt_code
== OPT_W
))
1283 cpp_fatal (pfile
, _(cl_options
[opt_index
].msg
), argv
[i
- 1]);
1291 case N_OPTS
: /* shut GCC up */
1293 case OPT_fleading_underscore
:
1294 user_label_prefix
= "_";
1296 case OPT_fno_leading_underscore
:
1297 user_label_prefix
= "";
1299 case OPT_fpreprocessed
:
1300 CPP_OPTION (pfile
, preprocessed
) = 1;
1302 case OPT_fno_preprocessed
:
1303 CPP_OPTION (pfile
, preprocessed
) = 0;
1305 case OPT_fshow_column
:
1306 CPP_OPTION (pfile
, show_column
) = 1;
1308 case OPT_fno_show_column
:
1309 CPP_OPTION (pfile
, show_column
) = 0;
1312 CPP_OPTION (pfile
, inhibit_warnings
) = 1;
1314 case OPT_g
: /* Silently ignore anything but -g3 */
1315 if (!strcmp(&argv
[i
][2], "3"))
1316 CPP_OPTION (pfile
, debug_output
) = 1;
1324 fprintf (stderr
, _("GNU CPP version %s (cpplib)\n"), version_string
);
1328 CPP_OPTION (pfile
, discard_comments
) = 0;
1331 CPP_OPTION (pfile
, no_line_commands
) = 1;
1333 case OPT_dollar
: /* Don't include $ in identifiers. */
1334 CPP_OPTION (pfile
, dollars_in_ident
) = 0;
1337 CPP_OPTION (pfile
, print_include_names
) = 1;
1340 new_pending_directive (CPP_OPTION (pfile
, pending
), arg
, cpp_define
);
1342 case OPT_pedantic_errors
:
1343 CPP_OPTION (pfile
, pedantic_errors
) = 1;
1346 CPP_OPTION (pfile
, pedantic
) = 1;
1348 case OPT_traditional
:
1349 CPP_OPTION (pfile
, traditional
) = 1;
1350 CPP_OPTION (pfile
, cplusplus_comments
) = 0;
1351 CPP_OPTION (pfile
, trigraphs
) = 0;
1352 CPP_OPTION (pfile
, warn_trigraphs
) = 0;
1355 CPP_OPTION (pfile
, trigraphs
) = 1;
1358 CPP_OPTION (pfile
, cplusplus
) = 1;
1359 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1362 CPP_OPTION (pfile
, remap
) = 1;
1365 CPP_OPTION (pfile
, include_prefix
) = arg
;
1366 CPP_OPTION (pfile
, include_prefix_len
) = strlen (arg
);
1369 CPP_OPTION (pfile
, cplusplus
) = 0;
1370 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1371 CPP_OPTION (pfile
, c89
) = 0;
1372 CPP_OPTION (pfile
, c99
) = 1;
1373 CPP_OPTION (pfile
, objc
) = 0;
1376 CPP_OPTION (pfile
, cplusplus
) = 0;
1377 CPP_OPTION (pfile
, cplusplus_comments
) = 0;
1378 CPP_OPTION (pfile
, c89
) = 1;
1379 CPP_OPTION (pfile
, c99
) = 0;
1380 CPP_OPTION (pfile
, objc
) = 0;
1381 CPP_OPTION (pfile
, trigraphs
) = 1;
1382 new_pending_directive (CPP_OPTION (pfile
, pending
),
1383 "__STRICT_ANSI__", cpp_define
);
1385 case OPT_lang_cplusplus
:
1386 CPP_OPTION (pfile
, cplusplus
) = 1;
1387 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1388 CPP_OPTION (pfile
, c89
) = 0;
1389 CPP_OPTION (pfile
, c99
) = 0;
1390 CPP_OPTION (pfile
, objc
) = 0;
1393 case OPT_lang_objcplusplus
:
1394 CPP_OPTION (pfile
, cplusplus
) = opt_code
== OPT_lang_objcplusplus
;
1395 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1396 CPP_OPTION (pfile
, c89
) = 0;
1397 CPP_OPTION (pfile
, c99
) = 0;
1398 CPP_OPTION (pfile
, objc
) = 1;
1401 CPP_OPTION (pfile
, lang_asm
) = 1;
1403 case OPT_lang_fortran
:
1404 CPP_OPTION (pfile
, lang_fortran
) = 1;
1405 CPP_OPTION (pfile
, cplusplus_comments
) = 0;
1407 case OPT_lang_chill
:
1408 CPP_OPTION (pfile
, objc
) = 0;
1409 CPP_OPTION (pfile
, cplusplus
) = 0;
1410 CPP_OPTION (pfile
, chill
) = 1;
1411 CPP_OPTION (pfile
, traditional
) = 1;
1414 /* -nostdinc causes no default include directories.
1415 You must specify all include-file directories with -I. */
1416 CPP_OPTION (pfile
, no_standard_includes
) = 1;
1418 case OPT_nostdincplusplus
:
1419 /* -nostdinc++ causes no default C++-specific include directories. */
1420 CPP_OPTION (pfile
, no_standard_cplusplus_includes
) = 1;
1423 CPP_OPTION (pfile
, cplusplus
) = 0;
1424 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1425 CPP_OPTION (pfile
, c89
) = 1;
1426 CPP_OPTION (pfile
, c99
) = 0;
1427 CPP_OPTION (pfile
, objc
) = 0;
1431 CPP_OPTION (pfile
, cplusplus
) = 0;
1432 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1433 CPP_OPTION (pfile
, c89
) = 0;
1434 CPP_OPTION (pfile
, c99
) = 1;
1435 CPP_OPTION (pfile
, objc
) = 0;
1436 new_pending_directive (CPP_OPTION (pfile
, pending
),
1437 "__STDC_VERSION__=199901L", cpp_define
);
1439 case OPT_std_iso9899_199409
:
1440 new_pending_directive (CPP_OPTION (pfile
, pending
),
1441 "__STDC_VERSION__=199409L", cpp_define
);
1443 case OPT_std_iso9899_1990
:
1445 CPP_OPTION (pfile
, cplusplus
) = 0;
1446 CPP_OPTION (pfile
, cplusplus_comments
) = 0;
1447 CPP_OPTION (pfile
, c89
) = 1;
1448 CPP_OPTION (pfile
, c99
) = 0;
1449 CPP_OPTION (pfile
, objc
) = 0;
1450 CPP_OPTION (pfile
, trigraphs
) = 1;
1451 new_pending_directive (CPP_OPTION (pfile
, pending
),
1452 "__STRICT_ANSI__", cpp_define
);
1454 case OPT_std_iso9899_199x
:
1455 case OPT_std_iso9899_1999
:
1458 CPP_OPTION (pfile
, cplusplus
) = 0;
1459 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1460 CPP_OPTION (pfile
, c89
) = 0;
1461 CPP_OPTION (pfile
, c99
) = 1;
1462 CPP_OPTION (pfile
, objc
) = 0;
1463 CPP_OPTION (pfile
, trigraphs
) = 1;
1464 new_pending_directive (CPP_OPTION (pfile
, pending
),
1465 "__STRICT_ANSI__", cpp_define
);
1466 new_pending_directive (CPP_OPTION (pfile
, pending
),
1467 "__STDC_VERSION__=199901L", cpp_define
);
1470 if (CPP_OPTION (pfile
, out_fname
) != NULL
)
1472 cpp_fatal (pfile
, "Output filename specified twice");
1475 CPP_OPTION (pfile
, out_fname
) = arg
;
1476 if (!strcmp (CPP_OPTION (pfile
, out_fname
), "-"))
1477 CPP_OPTION (pfile
, out_fname
) = "";
1480 fprintf (stderr
, _("GNU CPP version %s (cpplib)\n"), version_string
);
1481 #ifdef TARGET_VERSION
1484 fputc ('\n', stderr
);
1485 CPP_OPTION (pfile
, verbose
) = 1;
1487 case OPT_stdin_stdout
:
1488 /* JF handle '-' as file name meaning stdin or stdout */
1489 if (CPP_OPTION (pfile
, in_fname
) == NULL
)
1490 CPP_OPTION (pfile
, in_fname
) = "";
1491 else if (CPP_OPTION (pfile
, out_fname
) == NULL
)
1492 CPP_OPTION (pfile
, out_fname
) = "";
1495 /* Args to -d specify what parts of macros to dump.
1496 Silently ignore unrecognised options; they may
1497 be aimed at the compiler proper. */
1501 while ((c
= *arg
++) != '\0')
1505 CPP_OPTION (pfile
, dump_macros
) = dump_only
;
1506 CPP_OPTION (pfile
, no_output
) = 1;
1509 CPP_OPTION (pfile
, dump_macros
) = dump_names
;
1512 CPP_OPTION (pfile
, dump_macros
) = dump_definitions
;
1515 CPP_OPTION (pfile
, dump_includes
) = 1;
1520 /* The style of the choices here is a bit mixed.
1521 The chosen scheme is a hybrid of keeping all options in one string
1522 and specifying each option in a separate argument:
1523 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
1524 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
1525 -M[M][G][D file]. This is awkward to handle in specs, and is not
1527 /* ??? -MG must be specified in addition to one of -M or -MM.
1528 This can be relaxed in the future without breaking anything.
1529 The converse isn't true. */
1531 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
1533 CPP_OPTION (pfile
, print_deps_missing_files
) = 1;
1539 if (opt_code
== OPT_M
|| opt_code
== OPT_MD
)
1540 CPP_OPTION (pfile
, print_deps
) = 2;
1542 CPP_OPTION (pfile
, print_deps
) = 1;
1544 /* For -MD and -MMD options, write deps on file named by next arg */
1545 /* For -M and -MM, write deps on standard output
1546 and suppress the usual output. */
1547 if (opt_code
== OPT_MD
|| opt_code
== OPT_MMD
)
1548 CPP_OPTION (pfile
, deps_file
) = arg
;
1550 CPP_OPTION (pfile
, no_output
) = 1;
1555 /* -A with an argument beginning with '-' acts as
1556 #unassert on whatever immediately follows the '-'.
1557 If "-" is the whole argument, we eliminate all
1558 predefined macros and assertions, including those
1559 that were specified earlier on the command line.
1560 That way we can get rid of any that were passed
1561 automatically in from GCC. */
1565 struct pending_option
*o1
, *o2
;
1567 o1
= CPP_OPTION (pfile
, pending
)->directive_head
;
1574 CPP_OPTION (pfile
, pending
)->directive_head
= NULL
;
1575 CPP_OPTION (pfile
, pending
)->directive_tail
= NULL
;
1578 new_pending_directive (CPP_OPTION (pfile
, pending
),
1579 arg
+ 1, cpp_unassert
);
1582 new_pending_directive (CPP_OPTION (pfile
, pending
),
1586 new_pending_directive (CPP_OPTION (pfile
, pending
), arg
, cpp_undef
);
1588 case OPT_I
: /* Add directory to path for includes. */
1589 if (!strcmp (arg
, "-"))
1592 Use the preceding -I directories for #include "..."
1593 but not #include <...>.
1594 Don't search the directory of the present file
1595 for #include "...". (Note that -I. -I- is not the same as
1596 the default setup; -I. uses the compiler's working dir.) */
1597 if (! CPP_OPTION (pfile
, ignore_srcdir
))
1599 struct cpp_pending
*pend
= CPP_OPTION (pfile
, pending
);
1600 pend
->quote_head
= pend
->brack_head
;
1601 pend
->quote_tail
= pend
->brack_tail
;
1602 pend
->brack_head
= 0;
1603 pend
->brack_tail
= 0;
1604 CPP_OPTION (pfile
, ignore_srcdir
) = 1;
1608 cpp_fatal (pfile
, "-I- specified twice");
1613 append_include_chain (pfile
, CPP_OPTION (pfile
, pending
),
1614 xstrdup (arg
), BRACKET
, 0);
1617 /* Add directory to beginning of system include path, as a system
1618 include directory. */
1619 append_include_chain (pfile
, CPP_OPTION (pfile
, pending
),
1620 xstrdup (arg
), SYSTEM
, 0);
1624 struct pending_option
*o
= (struct pending_option
*)
1625 xmalloc (sizeof (struct pending_option
));
1628 /* This list has to be built in reverse order so that
1629 when cpp_start_read pushes all the -include files onto
1630 the buffer stack, they will be scanned in forward order. */
1631 o
->next
= CPP_OPTION (pfile
, pending
)->include_head
;
1632 CPP_OPTION (pfile
, pending
)->include_head
= o
;
1637 struct pending_option
*o
= (struct pending_option
*)
1638 xmalloc (sizeof (struct pending_option
));
1642 APPEND (CPP_OPTION (pfile
, pending
), imacros
, o
);
1645 case OPT_iwithprefix
:
1646 /* Add directory to end of path for includes,
1647 with the default prefix at the front of its name. */
1649 case OPT_iwithprefixbefore
:
1650 /* Add directory to main path for includes,
1651 with the default prefix at the front of its name. */
1658 if (CPP_OPTION (pfile
, include_prefix
) != 0)
1660 size_t ipl
= CPP_OPTION (pfile
, include_prefix_len
);
1661 fname
= xmalloc (ipl
+ len
+ 1);
1662 memcpy (fname
, CPP_OPTION (pfile
, include_prefix
), ipl
);
1663 memcpy (fname
+ ipl
, arg
, len
+ 1);
1667 fname
= xmalloc (sizeof GCC_INCLUDE_DIR
- 8 + len
);
1668 memcpy (fname
, GCC_INCLUDE_DIR
, sizeof GCC_INCLUDE_DIR
- 9);
1669 memcpy (fname
+ sizeof GCC_INCLUDE_DIR
- 9, arg
, len
+ 1);
1672 append_include_chain (pfile
, CPP_OPTION (pfile
, pending
), fname
,
1673 opt_code
== OPT_iwithprefix
? SYSTEM
: BRACKET
, 0);
1677 /* Add directory to end of path for includes. */
1678 append_include_chain (pfile
, CPP_OPTION (pfile
, pending
),
1679 xstrdup (arg
), AFTER
, 0);
1682 /* Silently ignore unrecognised options */
1683 if (!strcmp (argv
[i
], "-Wall"))
1685 CPP_OPTION (pfile
, warn_trigraphs
) = 1;
1686 CPP_OPTION (pfile
, warn_comments
) = 1;
1688 else if (!strcmp (argv
[i
], "-Wtraditional"))
1689 CPP_OPTION (pfile
, warn_traditional
) = 1;
1690 else if (!strcmp (argv
[i
], "-Wtrigraphs"))
1691 CPP_OPTION (pfile
, warn_trigraphs
) = 1;
1692 else if (!strcmp (argv
[i
], "-Wcomment"))
1693 CPP_OPTION (pfile
, warn_comments
) = 1;
1694 else if (!strcmp (argv
[i
], "-Wcomments"))
1695 CPP_OPTION (pfile
, warn_comments
) = 1;
1696 else if (!strcmp (argv
[i
], "-Wundef"))
1697 CPP_OPTION (pfile
, warn_undef
) = 1;
1698 else if (!strcmp (argv
[i
], "-Wimport"))
1699 CPP_OPTION (pfile
, warn_import
) = 1;
1700 else if (!strcmp (argv
[i
], "-Werror"))
1701 CPP_OPTION (pfile
, warnings_are_errors
) = 1;
1702 else if (!strcmp (argv
[i
], "-Wno-traditional"))
1703 CPP_OPTION (pfile
, warn_traditional
) = 0;
1704 else if (!strcmp (argv
[i
], "-Wno-trigraphs"))
1705 CPP_OPTION (pfile
, warn_trigraphs
) = 0;
1706 else if (!strcmp (argv
[i
], "-Wno-comment"))
1707 CPP_OPTION (pfile
, warn_comments
) = 0;
1708 else if (!strcmp (argv
[i
], "-Wno-comments"))
1709 CPP_OPTION (pfile
, warn_comments
) = 0;
1710 else if (!strcmp (argv
[i
], "-Wno-undef"))
1711 CPP_OPTION (pfile
, warn_undef
) = 0;
1712 else if (!strcmp (argv
[i
], "-Wno-import"))
1713 CPP_OPTION (pfile
, warn_import
) = 0;
1714 else if (!strcmp (argv
[i
], "-Wno-error"))
1715 CPP_OPTION (pfile
, warnings_are_errors
) = 0;
1724 opt_comp (const void *p1
, const void *p2
)
1726 return strcmp (((struct cl_option
*)p1
)->opt_text
,
1727 ((struct cl_option
*)p2
)->opt_text
);
1731 /* Handle command-line options in (argc, argv).
1732 Can be called multiple times, to handle multiple sets of options.
1733 Returns if an unrecognized option is seen.
1734 Returns number of strings consumed. */
1736 cpp_handle_options (pfile
, argc
, argv
)
1742 int strings_processed
;
1745 static int opts_sorted
= 0;
1750 /* For non-ASCII hosts, the array needs to be sorted at runtime */
1751 qsort (cl_options
, N_OPTS
, sizeof (struct cl_option
), opt_comp
);
1755 for (i
= 0; i
< argc
; i
+= strings_processed
)
1757 strings_processed
= handle_option (pfile
, argc
- i
, argv
+ i
);
1758 if (strings_processed
== 0)
1767 fprintf (stderr
, _("Usage: %s [switches] input output\n"), progname
);
1770 -include <file> Include the contents of <file> before other files\n\
1771 -imacros <file> Accept definition of macros in <file>\n\
1772 -iprefix <path> Specify <path> as a prefix for next two options\n\
1773 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1774 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1775 -isystem <dir> Add <dir> to the start of the system include path\n\
1776 -idirafter <dir> Add <dir> to the end of the system include path\n\
1777 -I <dir> Add <dir> to the end of the main include path\n\
1778 -I- Fine-grained include path control; see info docs\n\
1779 -nostdinc Do not search system include directories\n\
1780 (dirs specified with -isystem will still be used)\n\
1781 -nostdinc++ Do not search system include directories for C++\n\
1782 -o <file> Put output into <file>\n\
1783 -pedantic Issue all warnings demanded by strict ANSI C\n\
1784 -pedantic-errors Issue -pedantic warnings as errors instead\n\
1785 -traditional Follow K&R pre-processor behaviour\n\
1786 -trigraphs Support ANSI C trigraphs\n\
1787 -lang-c Assume that the input sources are in C\n\
1788 -lang-c89 Assume that the input sources are in C89\n\
1789 -lang-c++ Assume that the input sources are in C++\n\
1790 -lang-objc Assume that the input sources are in ObjectiveC\n\
1791 -lang-objc++ Assume that the input sources are in ObjectiveC++\n\
1792 -lang-asm Assume that the input sources are in assembler\n\
1793 -lang-fortran Assume that the input sources are in Fortran\n\
1794 -lang-chill Assume that the input sources are in Chill\n\
1795 -std=<std name> Specify the conformance standard; one of:\n\
1796 gnu89, gnu99, c89, c99, iso9899:1990,\n\
1797 iso9899:199409, iso9899:1999\n\
1798 -+ Allow parsing of C++ style features\n\
1799 -w Inhibit warning messages\n\
1800 -Wtrigraphs Warn if trigraphs are encountered\n\
1801 -Wno-trigraphs Do not warn about trigraphs\n\
1802 -Wcomment{s} Warn if one comment starts inside another\n\
1803 -Wno-comment{s} Do not warn about comments\n\
1804 -Wtraditional Warn if a macro argument is/would be turned into\n\
1805 a string if -traditional is specified\n\
1806 -Wno-traditional Do not warn about stringification\n\
1807 -Wundef Warn if an undefined macro is used by #if\n\
1808 -Wno-undef Do not warn about testing undefined macros\n\
1809 -Wimport Warn about the use of the #import directive\n\
1810 -Wno-import Do not warn about the use of #import\n\
1811 -Werror Treat all warnings as errors\n\
1812 -Wno-error Do not treat warnings as errors\n\
1813 -Wall Enable all preprocessor warnings\n\
1814 -M Generate make dependencies\n\
1815 -MM As -M, but ignore system header files\n\
1816 -MD As -M, but put output in a .d file\n\
1817 -MMD As -MD, but ignore system header files\n\
1818 -MG Treat missing header file as generated files\n\
1819 -g3 Include #define and #undef directives in the output\n\
1820 -D<macro> Define a <macro> with string '1' as its value\n\
1821 -D<macro>=<val> Define a <macro> with <val> as its value\n\
1822 -A<question> (<answer>) Assert the <answer> to <question>\n\
1823 -A-<question> (<answer>) Disable the <answer> to <question>\n\
1824 -U<macro> Undefine <macro> \n\
1825 -v Display the version number\n\
1826 -H Print the name of header files as they are used\n\
1827 -C Do not discard comments\n\
1828 -dM Display a list of macro definitions active at end\n\
1829 -dD Preserve macro definitions in output\n\
1830 -dN As -dD except that only the names are preserved\n\
1831 -dI Include #include directives in the output\n\
1832 -P Do not generate #line directives\n\
1833 -$ Do not allow '$' in identifiers\n\
1834 -remap Remap file names when including files.\n\
1835 --version Display version information\n\
1836 -h or --help Display this information\n\