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. */
25 #include "splay-tree.h"
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 U_CHAR
*,
220 static void initialize_dependency_output
PARAMS ((cpp_reader
*));
221 static void initialize_standard_includes
PARAMS ((cpp_reader
*));
222 static void new_pending_directive
PARAMS ((struct cpp_pending
*,
224 cl_directive_handler
));
226 static int opt_comp
PARAMS ((const void *, const void *));
228 static int parse_option
PARAMS ((const char *));
229 static int handle_option
PARAMS ((cpp_reader
*, int, char **));
231 /* Fourth argument to append_include_chain: chain to use */
232 enum { QUOTE
= 0, BRACKET
, SYSTEM
, AFTER
};
234 /* If we have designated initializers (GCC >2.7) this table can be
235 initialized, constant data. Otherwise, it has to be filled in at
238 #if (GCC_VERSION >= 2007)
239 #define init_IStable() /* nothing */
240 #define ISTABLE __extension__ const unsigned char _cpp_IStable[256] = {
242 #define s(p, v) [p] = v,
244 #define ISTABLE unsigned char _cpp_IStable[256] = { 0 }; \
245 static void init_IStable PARAMS ((void)) { \
246 unsigned char *x = _cpp_IStable;
248 #define s(p, v) x[p] = v;
251 #define A(x) s(x, ISidnum|ISidstart)
252 #define N(x) s(x, ISidnum|ISnumstart)
253 #define H(x) s(x, IShspace|ISspace)
254 #define S(x) s(x, ISspace)
259 A('a') A('b') A('c') A('d') A('e') A('f') A('g') A('h') A('i')
260 A('j') A('k') A('l') A('m') A('n') A('o') A('p') A('q') A('r')
261 A('s') A('t') A('u') A('v') A('w') A('x') A('y') A('z')
263 A('A') A('B') A('C') A('D') A('E') A('F') A('G') A('H') A('I')
264 A('J') A('K') A('L') A('M') A('N') A('O') A('P') A('Q') A('R')
265 A('S') A('T') A('U') A('V') A('W') A('X') A('Y') A('Z')
267 N('1') N('2') N('3') N('4') N('5') N('6') N('7') N('8') N('9') N('0')
269 H('\0') H(' ') H('\t') H('\v') H('\f')
282 /* Given a colon-separated list of file names PATH,
283 add all the names to the search path for include files. */
286 path_include (pfile
, pend
, list
, path
)
288 struct cpp_pending
*pend
;
298 /* Find the end of this name. */
300 while (*q
!= 0 && *q
!= PATH_SEPARATOR
) q
++;
303 /* An empty name in the path stands for the current directory. */
304 name
= (char *) xmalloc (2);
310 /* Otherwise use the directory that is named. */
311 name
= (char *) xmalloc (q
- p
+ 1);
312 memcpy (name
, p
, q
- p
);
316 append_include_chain (pfile
, pend
, name
, path
, 0);
318 /* Advance past this name. */
326 /* Append DIR to include path PATH. DIR must be permanently allocated
329 append_include_chain (pfile
, pend
, dir
, path
, cxx_aware
)
331 struct cpp_pending
*pend
;
336 struct file_name_list
*new;
340 _cpp_simplify_pathname (dir
);
343 /* Dirs that don't exist are silently ignored. */
345 cpp_notice_from_errno (pfile
, dir
);
346 else if (CPP_OPTION (pfile
, verbose
))
347 fprintf (stderr
, _("ignoring nonexistent directory `%s'\n"), dir
);
351 if (!S_ISDIR (st
.st_mode
))
353 cpp_notice (pfile
, "%s: Not a directory", dir
);
358 if (len
> pfile
->max_include_len
)
359 pfile
->max_include_len
= len
;
361 new = (struct file_name_list
*) xmalloc (sizeof (struct file_name_list
));
364 new->ino
= st
.st_ino
;
365 new->dev
= st
.st_dev
;
367 new->sysp
= cxx_aware
? 1 : 2;
370 new->name_map
= NULL
;
376 case QUOTE
: APPEND (pend
, quote
, new); break;
377 case BRACKET
: APPEND (pend
, brack
, new); break;
378 case SYSTEM
: APPEND (pend
, systm
, new); break;
379 case AFTER
: APPEND (pend
, after
, new); break;
383 /* Merge the four include chains together in the order quote, bracket,
384 system, after. Remove duplicate dirs (as determined by
385 INO_T_EQ()). The system_include and after_include chains are never
386 referred to again after this function; all access is through the
387 bracket_include path.
389 For the future: Check if the directory is empty (but
390 how?) and possibly preload the include hash. */
393 merge_include_chains (pfile
)
396 struct file_name_list
*prev
, *cur
, *other
;
397 struct file_name_list
*quote
, *brack
, *systm
, *after
;
398 struct file_name_list
*qtail
, *btail
, *stail
, *atail
;
400 struct cpp_pending
*pend
= CPP_OPTION (pfile
, pending
);
402 qtail
= pend
->quote_tail
;
403 btail
= pend
->brack_tail
;
404 stail
= pend
->systm_tail
;
405 atail
= pend
->after_tail
;
407 quote
= pend
->quote_head
;
408 brack
= pend
->brack_head
;
409 systm
= pend
->systm_head
;
410 after
= pend
->after_head
;
412 /* Paste together bracket, system, and after include chains. */
422 /* This is a bit tricky.
423 First we drop dupes from the quote-include list.
424 Then we drop dupes from the bracket-include list.
425 Finally, if qtail and brack are the same directory,
428 We can't just merge the lists and then uniquify them because
429 then we may lose directories from the <> search path that should
430 be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however
431 safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written
432 -Ibar -I- -Ifoo -Iquux.
434 Note that this algorithm is quadratic in the number of -I switches,
435 which is acceptable since there aren't usually that many of them. */
437 for (cur
= quote
, prev
= NULL
; cur
; cur
= cur
->next
)
439 for (other
= quote
; other
!= cur
; other
= other
->next
)
440 if (INO_T_EQ (cur
->ino
, other
->ino
)
441 && cur
->dev
== other
->dev
)
443 if (CPP_OPTION (pfile
, verbose
))
444 fprintf (stderr
, _("ignoring duplicate directory `%s'\n"),
447 prev
->next
= cur
->next
;
457 for (cur
= brack
; cur
; cur
= cur
->next
)
459 for (other
= brack
; other
!= cur
; other
= other
->next
)
460 if (INO_T_EQ (cur
->ino
, other
->ino
)
461 && cur
->dev
== other
->dev
)
463 if (CPP_OPTION (pfile
, verbose
))
464 fprintf (stderr
, _("ignoring duplicate directory `%s'\n"),
467 prev
->next
= cur
->next
;
478 if (INO_T_EQ (qtail
->ino
, brack
->ino
) && qtail
->dev
== brack
->dev
)
482 if (CPP_OPTION (pfile
, verbose
))
483 fprintf (stderr
, _("ignoring duplicate directory `%s'\n"),
493 while (cur
->next
!= qtail
)
496 if (CPP_OPTION (pfile
, verbose
))
497 fprintf (stderr
, _("ignoring duplicate directory `%s'\n"),
510 CPP_OPTION (pfile
, quote_include
) = quote
;
511 CPP_OPTION (pfile
, bracket_include
) = brack
;
515 /* Write out a #define command for the special named MACRO_NAME
516 to PFILE's token_buffer. */
519 dump_special_to_buffer (pfile
, macro_name
, macro_len
)
521 const U_CHAR
*macro_name
;
524 static const char define_directive
[] = "#define ";
525 CPP_RESERVE (pfile
, sizeof(define_directive
) + macro_len
);
526 CPP_PUTS_Q (pfile
, define_directive
, sizeof(define_directive
)-1);
527 CPP_PUTS_Q (pfile
, macro_name
, macro_len
);
528 CPP_PUTC_Q (pfile
, ' ');
529 _cpp_expand_to_buffer (pfile
, macro_name
, macro_len
);
530 CPP_PUTC (pfile
, '\n');
533 /* Initialize a cpp_reader structure. */
535 cpp_reader_init (pfile
)
538 memset ((char *) pfile
, 0, sizeof (cpp_reader
));
540 pfile
->token_buffer_size
= 200;
541 pfile
->token_buffer
= (U_CHAR
*) xmalloc (pfile
->token_buffer_size
);
542 CPP_SET_WRITTEN (pfile
, 0);
544 CPP_OPTION (pfile
, dollars_in_ident
) = 1;
545 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
546 CPP_OPTION (pfile
, warn_import
) = 1;
547 CPP_OPTION (pfile
, discard_comments
) = 1;
548 CPP_OPTION (pfile
, show_column
) = 1;
549 CPP_OPTION (pfile
, tabstop
) = 8;
551 CPP_OPTION (pfile
, pending
) =
552 (struct cpp_pending
*) xcalloc (1, sizeof (struct cpp_pending
));
554 _cpp_init_macro_hash (pfile
);
555 _cpp_init_include_table (pfile
);
558 /* Initialize a cpp_printer structure. As a side effect, open the
561 cpp_printer_init (pfile
, print
)
565 memset (print
, '\0', sizeof (cpp_printer
));
566 if (CPP_OPTION (pfile
, out_fname
) == NULL
)
567 CPP_OPTION (pfile
, out_fname
) = "";
569 if (CPP_OPTION (pfile
, out_fname
)[0] == '\0')
570 print
->outf
= stdout
;
573 print
->outf
= fopen (CPP_OPTION (pfile
, out_fname
), "w");
576 cpp_notice_from_errno (pfile
, CPP_OPTION (pfile
, out_fname
));
583 /* Free resources used by PFILE.
584 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
589 while (CPP_BUFFER (pfile
) != NULL
)
590 cpp_pop_buffer (pfile
);
592 if (pfile
->token_buffer
)
594 free (pfile
->token_buffer
);
595 pfile
->token_buffer
= NULL
;
598 if (pfile
->input_buffer
)
600 free (pfile
->input_buffer
);
601 pfile
->input_buffer
= NULL
;
602 pfile
->input_buffer_len
= 0;
606 deps_free (pfile
->deps
);
608 htab_delete (pfile
->hashtab
);
609 splay_tree_delete (pfile
->all_include_files
);
613 /* This structure defines one built-in macro. A node of type TYPE will
614 be entered in the macro hash table under the name NAME, with value
615 VALUE (if any). FLAGS tweaks the behavior a little:
616 DUMP write debug info for this macro
617 VERS value is the global version_string, quoted
618 ULP value is the global user_label_prefix
626 unsigned short flags
;
633 #define B(n, t) { U n, 0, t, 0, sizeof n - 1 }
634 #define C(n, v) { U n, U v, T_CONST, DUMP, sizeof n - 1 }
635 #define X(n, v, t, f) { U n, U v, t, DUMP|f, sizeof n - 1 }
636 static const struct builtin builtin_array
[] =
638 B("__TIME__", T_TIME
),
639 B("__DATE__", T_DATE
),
640 B("__FILE__", T_FILE
),
641 B("__BASE_FILE__", T_BASE_FILE
),
642 B("__LINE__", T_SPECLINE
),
643 B("__INCLUDE_LEVEL__", T_INCLUDE_LEVEL
),
645 X("__VERSION__", 0, T_XCONST
, VERS
),
646 X("__USER_LABEL_PREFIX__", 0, T_CONST
, ULP
),
647 X("__STDC__", "1", T_STDC
, 0),
648 C("__REGISTER_PREFIX__", REGISTER_PREFIX
),
649 C("__HAVE_BUILTIN_SETJMP__", "1"),
650 #ifndef NO_BUILTIN_SIZE_TYPE
651 C("__SIZE_TYPE__", SIZE_TYPE
),
653 #ifndef NO_BUILTIN_PTRDIFF_TYPE
654 C("__PTRDIFF_TYPE__", PTRDIFF_TYPE
),
656 #ifndef NO_BUILTIN_WCHAR_TYPE
657 C("__WCHAR_TYPE__", WCHAR_TYPE
),
663 #define builtin_array_end \
664 builtin_array + sizeof(builtin_array)/sizeof(struct builtin)
666 /* Subroutine of cpp_start_read; reads the builtins table above and
667 enters the macros into the hash table. */
669 initialize_builtins (pfile
)
672 const struct builtin
*b
;
675 for(b
= builtin_array
; b
< builtin_array_end
; b
++)
677 if (b
->type
== T_STDC
&& CPP_TRADITIONAL (pfile
))
681 val
= (const U_CHAR
*) user_label_prefix
;
682 else if (b
->flags
& VERS
)
684 val
= (const U_CHAR
*) xmalloc (strlen (version_string
) + 3);
685 sprintf ((char *)val
, "\"%s\"", version_string
);
690 hp
= cpp_lookup (pfile
, b
->name
, b
->len
);
691 hp
->value
.cpval
= val
;
694 if ((b
->flags
& DUMP
) && CPP_OPTION (pfile
, debug_output
))
695 dump_special_to_buffer (pfile
, b
->name
, b
->len
);
703 /* Another subroutine of cpp_start_read. This one sets up to do
704 dependency-file output. */
706 initialize_dependency_output (pfile
)
709 char *spec
, *s
, *output_file
;
711 /* Either of two environment variables can specify output of deps.
712 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
713 where OUTPUT_FILE is the file to write deps info to
714 and DEPS_TARGET is the target to mention in the deps. */
716 if (CPP_OPTION (pfile
, print_deps
) == 0)
718 spec
= getenv ("DEPENDENCIES_OUTPUT");
720 CPP_OPTION (pfile
, print_deps
) = 1;
723 spec
= getenv ("SUNPRO_DEPENDENCIES");
725 CPP_OPTION (pfile
, print_deps
) = 2;
730 /* Find the space before the DEPS_TARGET, if there is one. */
731 s
= strchr (spec
, ' ');
734 CPP_OPTION (pfile
, deps_target
) = s
+ 1;
735 output_file
= (char *) xmalloc (s
- spec
+ 1);
736 memcpy (output_file
, spec
, s
- spec
);
737 output_file
[s
- spec
] = 0;
741 CPP_OPTION (pfile
, deps_target
) = 0;
745 CPP_OPTION (pfile
, deps_file
) = output_file
;
746 CPP_OPTION (pfile
, print_deps_append
) = 1;
749 pfile
->deps
= deps_init ();
751 /* Print the expected object file name as the target of this Make-rule. */
752 if (CPP_OPTION (pfile
, deps_target
))
753 deps_add_target (pfile
->deps
, CPP_OPTION (pfile
, deps_target
));
754 else if (*CPP_OPTION (pfile
, in_fname
) == 0)
755 deps_add_target (pfile
->deps
, "-");
757 deps_calc_target (pfile
->deps
, CPP_OPTION (pfile
, in_fname
));
759 if (CPP_OPTION (pfile
, in_fname
))
760 deps_add_dep (pfile
->deps
, CPP_OPTION (pfile
, in_fname
));
763 /* And another subroutine. This one sets up the standard include path. */
765 initialize_standard_includes (pfile
)
769 const struct default_include
*p
;
770 const char *specd_prefix
= CPP_OPTION (pfile
, include_prefix
);
772 /* Several environment variables may add to the include search path.
773 CPATH specifies an additional list of directories to be searched
774 as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH,
775 etc. specify an additional list of directories to be searched as
776 if specified with -isystem, for the language indicated. */
778 GET_ENV_PATH_LIST (path
, "CPATH");
779 if (path
!= 0 && *path
!= 0)
780 path_include (pfile
, CPP_OPTION (pfile
, pending
), path
, BRACKET
);
782 switch ((CPP_OPTION (pfile
, objc
) << 1) + CPP_OPTION (pfile
, cplusplus
))
785 GET_ENV_PATH_LIST (path
, "C_INCLUDE_PATH");
788 GET_ENV_PATH_LIST (path
, "CPLUS_INCLUDE_PATH");
791 GET_ENV_PATH_LIST (path
, "OBJC_INCLUDE_PATH");
794 GET_ENV_PATH_LIST (path
, "OBJCPLUS_INCLUDE_PATH");
797 if (path
!= 0 && *path
!= 0)
798 path_include (pfile
, CPP_OPTION (pfile
, pending
), path
, SYSTEM
);
800 /* Search "translated" versions of GNU directories.
801 These have /usr/local/lib/gcc... replaced by specd_prefix. */
802 if (specd_prefix
!= 0)
804 char *default_prefix
= (char *) alloca (sizeof GCC_INCLUDE_DIR
- 7);
805 /* Remove the `include' from /usr/local/lib/gcc.../include.
806 GCC_INCLUDE_DIR will always end in /include. */
807 int default_len
= sizeof GCC_INCLUDE_DIR
- 8;
808 int specd_len
= strlen (specd_prefix
);
810 memcpy (default_prefix
, GCC_INCLUDE_DIR
, default_len
);
811 default_prefix
[default_len
] = '\0';
813 for (p
= include_defaults_array
; p
->fname
; p
++)
815 /* Some standard dirs are only for C++. */
817 || (CPP_OPTION (pfile
, cplusplus
)
818 && !CPP_OPTION (pfile
, no_standard_cplusplus_includes
)))
820 /* Does this dir start with the prefix? */
821 if (!strncmp (p
->fname
, default_prefix
, default_len
))
823 /* Yes; change prefix and add to search list. */
824 int flen
= strlen (p
->fname
);
825 int this_len
= specd_len
+ flen
- default_len
;
826 char *str
= (char *) xmalloc (this_len
+ 1);
827 memcpy (str
, specd_prefix
, specd_len
);
828 memcpy (str
+ specd_len
,
829 p
->fname
+ default_len
,
830 flen
- default_len
+ 1);
832 append_include_chain (pfile
, CPP_OPTION (pfile
, pending
),
833 str
, SYSTEM
, p
->cxx_aware
);
839 /* Search ordinary names for GNU include directories. */
840 for (p
= include_defaults_array
; p
->fname
; p
++)
842 /* Some standard dirs are only for C++. */
844 || (CPP_OPTION (pfile
, cplusplus
)
845 && !CPP_OPTION (pfile
, no_standard_cplusplus_includes
)))
847 /* XXX Potential memory leak! */
848 char *str
= xstrdup (update_path (p
->fname
, p
->component
));
849 append_include_chain (pfile
, CPP_OPTION (pfile
, pending
),
850 str
, SYSTEM
, p
->cxx_aware
);
855 /* This is called after options have been processed.
856 * Check options for consistency, and setup for processing input
857 * from the file named FNAME. (Use standard input if FNAME==NULL.)
858 * Return 1 on success, 0 on failure.
862 cpp_start_read (pfile
, print
, fname
)
867 struct pending_option
*p
, *q
;
869 /* -MG doesn't select the form of output and must be specified with one of
870 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
871 inhibit compilation. */
872 if (CPP_OPTION (pfile
, print_deps_missing_files
)
873 && (CPP_OPTION (pfile
, print_deps
) == 0
874 || !CPP_OPTION (pfile
, no_output
)))
876 cpp_fatal (pfile
, "-MG must be specified with one of -M or -MM");
880 /* Chill should not be used with -trigraphs. */
881 if (CPP_OPTION (pfile
, chill
) && CPP_OPTION (pfile
, trigraphs
))
883 cpp_warning (pfile
, "-lang-chill and -trigraphs are mutually exclusive");
884 CPP_OPTION (pfile
, trigraphs
) = 0;
887 /* -Wtraditional is not useful in C++ mode. */
888 if (CPP_OPTION (pfile
, cplusplus
))
889 CPP_OPTION (pfile
, warn_traditional
) = 0;
891 /* Set this if it hasn't been set already. */
892 if (user_label_prefix
== NULL
)
893 user_label_prefix
= USER_LABEL_PREFIX
;
895 /* Don't bother trying to do macro expansion if we've already done
897 if (CPP_OPTION (pfile
, preprocessed
))
898 pfile
->no_macro_expand
++;
900 /* Set up the IStable. This doesn't do anything if we were compiled
901 with a compiler that supports C99 designated initializers. */
904 /* Set up the tables used by read_and_prescan. */
905 _cpp_init_input_buffer (pfile
);
907 /* Set up the include search path now. */
908 if (! CPP_OPTION (pfile
, no_standard_includes
))
909 initialize_standard_includes (pfile
);
911 merge_include_chains (pfile
);
913 /* With -v, print the list of dirs to search. */
914 if (CPP_OPTION (pfile
, verbose
))
916 struct file_name_list
*l
;
917 fprintf (stderr
, _("#include \"...\" search starts here:\n"));
918 for (l
= CPP_OPTION (pfile
, quote_include
); l
; l
= l
->next
)
920 if (l
== CPP_OPTION (pfile
, bracket_include
))
921 fprintf (stderr
, _("#include <...> search starts here:\n"));
922 fprintf (stderr
, " %s\n", l
->name
);
924 fprintf (stderr
, _("End of search list.\n"));
927 /* Open the main input file. This must be done early, so we have a
928 buffer to stand on. */
929 if (CPP_OPTION (pfile
, in_fname
) == NULL
930 || *CPP_OPTION (pfile
, in_fname
) == 0)
932 CPP_OPTION (pfile
, in_fname
) = fname
;
933 if (CPP_OPTION (pfile
, in_fname
) == NULL
)
934 CPP_OPTION (pfile
, in_fname
) = "";
936 if (CPP_OPTION (pfile
, out_fname
) == NULL
)
937 CPP_OPTION (pfile
, out_fname
) = "";
939 if (!cpp_read_file (pfile
, fname
))
942 initialize_dependency_output (pfile
);
944 /* -D and friends may produce output, which should be identified
947 CPP_BUFFER (pfile
)->lineno
= 0;
952 print
->last_fname
= CPP_BUFFER (pfile
)->nominal_fname
;
953 print
->last_bsd
= pfile
->buffer_stack_depth
;
954 print
->written
= CPP_WRITTEN (pfile
);
957 /* Install __LINE__, etc. */
958 initialize_builtins (pfile
);
960 /* Do -U's, -D's and -A's in the order they were seen. */
961 p
= CPP_OPTION (pfile
, pending
)->directive_head
;
964 (*p
->handler
) (pfile
, p
->arg
);
969 pfile
->done_initializing
= 1;
970 pfile
->only_seen_white
= 2;
971 CPP_BUFFER (pfile
)->lineno
= 1;
972 if (print
&& ! CPP_OPTION (pfile
, no_output
))
973 cpp_output_tokens (pfile
, print
);
975 /* The -imacros files can be scanned now, but the -include files
976 have to be pushed onto the include stack and processed later,
977 in the main loop calling cpp_get_token. */
979 p
= CPP_OPTION (pfile
, pending
)->imacros_head
;
982 if (cpp_read_file (pfile
, p
->arg
))
983 cpp_scan_buffer_nooutput (pfile
);
989 p
= CPP_OPTION (pfile
, pending
)->include_head
;
992 if (cpp_read_file (pfile
, p
->arg
)
993 && print
&& ! CPP_OPTION (pfile
, no_output
))
994 cpp_output_tokens (pfile
, print
);
1000 free (CPP_OPTION (pfile
, pending
));
1001 CPP_OPTION (pfile
, pending
) = NULL
;
1006 /* This is called at the end of preprocessing. It pops the
1007 last buffer and writes dependency output. It should also
1008 clear macro definitions, such that you could call cpp_start_read
1009 with a new filename to restart processing. */
1011 cpp_finish (pfile
, print
)
1015 if (CPP_BUFFER (pfile
))
1017 cpp_ice (pfile
, "buffers still stacked in cpp_finish");
1018 while (CPP_BUFFER (pfile
))
1019 cpp_pop_buffer (pfile
);
1022 /* Don't write the deps file if preprocessing has failed. */
1023 if (CPP_OPTION (pfile
, print_deps
) && pfile
->errors
== 0)
1025 /* Stream on which to print the dependency information. */
1026 FILE *deps_stream
= 0;
1027 const char *deps_mode
1028 = CPP_OPTION (pfile
, print_deps_append
) ? "a" : "w";
1029 if (CPP_OPTION (pfile
, deps_file
) == 0)
1030 deps_stream
= stdout
;
1033 deps_stream
= fopen (CPP_OPTION (pfile
, deps_file
), deps_mode
);
1034 if (deps_stream
== 0)
1035 cpp_notice_from_errno (pfile
, CPP_OPTION (pfile
, deps_file
));
1039 deps_write (pfile
->deps
, deps_stream
, 72);
1040 if (CPP_OPTION (pfile
, deps_file
))
1042 if (ferror (deps_stream
) || fclose (deps_stream
) != 0)
1043 cpp_fatal (pfile
, "I/O error on output");
1048 if (CPP_OPTION (pfile
, dump_macros
) == dump_only
)
1049 _cpp_dump_macro_hash (pfile
);
1051 /* Flush any pending output. */
1054 cpp_output_tokens (pfile
, print
);
1055 if (ferror (print
->outf
) || fclose (print
->outf
))
1056 cpp_notice_from_errno (pfile
, CPP_OPTION (pfile
, out_fname
));
1061 new_pending_directive (pend
, text
, handler
)
1062 struct cpp_pending
*pend
;
1064 cl_directive_handler handler
;
1066 struct pending_option
*o
= (struct pending_option
*)
1067 xmalloc (sizeof (struct pending_option
));
1071 o
->handler
= handler
;
1072 APPEND (pend
, directive
, o
);
1075 /* Irix6 "cc -n32" and OSF4 cc have problems with char foo[] = ("string");
1076 I.e. a const string initializer with parens around it. That is
1077 what N_("string") resolves to, so we make no_* be macros instead. */
1078 #define no_arg N_("Argument missing after %s")
1079 #define no_ass N_("Assertion missing after %s")
1080 #define no_dir N_("Directory name missing after %s")
1081 #define no_fil N_("File name missing after %s")
1082 #define no_mac N_("Macro name missing after %s")
1083 #define no_pth N_("Path name missing after %s")
1084 #define no_num N_("Number missing after %s")
1086 /* This is the list of all command line options, with the leading
1087 "-" removed. It must be sorted in ASCII collating order. */
1088 #define COMMAND_LINE_OPTIONS \
1089 DEF_OPT("", 0, OPT_stdin_stdout) \
1090 DEF_OPT("$", 0, OPT_dollar) \
1091 DEF_OPT("+", 0, OPT_plus) \
1092 DEF_OPT("-help", 0, OPT__help) \
1093 DEF_OPT("-version", 0, OPT__version) \
1094 DEF_OPT("A", no_ass, OPT_A) \
1095 DEF_OPT("C", 0, OPT_C) \
1096 DEF_OPT("D", no_mac, OPT_D) \
1097 DEF_OPT("H", 0, OPT_H) \
1098 DEF_OPT("I", no_dir, OPT_I) \
1099 DEF_OPT("M", 0, OPT_M) \
1100 DEF_OPT("MD", no_fil, OPT_MD) \
1101 DEF_OPT("MG", 0, OPT_MG) \
1102 DEF_OPT("MM", 0, OPT_MM) \
1103 DEF_OPT("MMD", no_fil, OPT_MMD) \
1104 DEF_OPT("P", 0, OPT_P) \
1105 DEF_OPT("U", no_mac, OPT_U) \
1106 DEF_OPT("W", no_arg, OPT_W) /* arg optional */ \
1107 DEF_OPT("d", no_arg, OPT_d) \
1108 DEF_OPT("fleading-underscore", 0, OPT_fleading_underscore) \
1109 DEF_OPT("fno-leading-underscore", 0, OPT_fno_leading_underscore) \
1110 DEF_OPT("fno-preprocessed", 0, OPT_fno_preprocessed) \
1111 DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \
1112 DEF_OPT("fpreprocessed", 0, OPT_fpreprocessed) \
1113 DEF_OPT("fshow-column", 0, OPT_fshow_column) \
1114 DEF_OPT("ftabstop=", no_num, OPT_ftabstop) \
1115 DEF_OPT("g", no_arg, OPT_g) /* arg optional */ \
1116 DEF_OPT("h", 0, OPT_h) \
1117 DEF_OPT("idirafter", no_dir, OPT_idirafter) \
1118 DEF_OPT("imacros", no_fil, OPT_imacros) \
1119 DEF_OPT("include", no_fil, OPT_include) \
1120 DEF_OPT("iprefix", no_pth, OPT_iprefix) \
1121 DEF_OPT("isystem", no_dir, OPT_isystem) \
1122 DEF_OPT("iwithprefix", no_dir, OPT_iwithprefix) \
1123 DEF_OPT("iwithprefixbefore", no_dir, OPT_iwithprefixbefore) \
1124 DEF_OPT("lang-asm", 0, OPT_lang_asm) \
1125 DEF_OPT("lang-c", 0, OPT_lang_c) \
1126 DEF_OPT("lang-c++", 0, OPT_lang_cplusplus) \
1127 DEF_OPT("lang-c89", 0, OPT_lang_c89) \
1128 DEF_OPT("lang-chill", 0, OPT_lang_chill) \
1129 DEF_OPT("lang-fortran", 0, OPT_lang_fortran) \
1130 DEF_OPT("lang-objc", 0, OPT_lang_objc) \
1131 DEF_OPT("lang-objc++", 0, OPT_lang_objcplusplus) \
1132 DEF_OPT("nostdinc", 0, OPT_nostdinc) \
1133 DEF_OPT("nostdinc++", 0, OPT_nostdincplusplus) \
1134 DEF_OPT("o", no_fil, OPT_o) \
1135 DEF_OPT("pedantic", 0, OPT_pedantic) \
1136 DEF_OPT("pedantic-errors", 0, OPT_pedantic_errors) \
1137 DEF_OPT("remap", 0, OPT_remap) \
1138 DEF_OPT("std=c89", 0, OPT_std_c89) \
1139 DEF_OPT("std=c99", 0, OPT_std_c99) \
1140 DEF_OPT("std=c9x", 0, OPT_std_c9x) \
1141 DEF_OPT("std=gnu89", 0, OPT_std_gnu89) \
1142 DEF_OPT("std=gnu99", 0, OPT_std_gnu99) \
1143 DEF_OPT("std=gnu9x", 0, OPT_std_gnu9x) \
1144 DEF_OPT("std=iso9899:1990", 0, OPT_std_iso9899_1990) \
1145 DEF_OPT("std=iso9899:199409", 0, OPT_std_iso9899_199409) \
1146 DEF_OPT("std=iso9899:1999", 0, OPT_std_iso9899_1999) \
1147 DEF_OPT("std=iso9899:199x", 0, OPT_std_iso9899_199x) \
1148 DEF_OPT("traditional", 0, OPT_traditional) \
1149 DEF_OPT("trigraphs", 0, OPT_trigraphs) \
1150 DEF_OPT("v", 0, OPT_v) \
1151 DEF_OPT("w", 0, OPT_w)
1153 #define DEF_OPT(text, msg, code) code,
1156 COMMAND_LINE_OPTIONS
1163 const char *opt_text
;
1166 enum opt_code opt_code
;
1169 #define DEF_OPT(text, msg, code) { text, msg, sizeof(text) - 1, code },
1171 static struct cl_option cl_options
[] =
1173 static const struct cl_option cl_options
[] =
1176 COMMAND_LINE_OPTIONS
1179 #undef COMMAND_LINE_OPTIONS
1181 /* Perform a binary search to find which, if any, option the given
1182 command-line matches. Returns its index in the option array,
1183 negative on failure. Complications arise since some options can be
1184 suffixed with an argument, and multiple complete matches can occur,
1185 e.g. -iwithprefix and -iwithprefixbefore. Moreover, we want to
1186 accept options beginning with -g and -W that we do not recognise,
1187 but not to swallow any subsequent command line argument; these are
1188 handled as special cases in cpp_handle_option */
1190 parse_option (input
)
1193 unsigned int md
, mn
, mx
;
1204 opt_len
= cl_options
[md
].opt_len
;
1205 comp
= strncmp (input
, cl_options
[md
].opt_text
, opt_len
);
1213 if (input
[opt_len
] == '\0')
1215 /* We were passed more text. If the option takes an argument,
1216 we may match a later option or we may have been passed the
1217 argument. The longest possible option match succeeds.
1218 If the option takes no arguments we have not matched and
1219 continue the search (e.g. input="stdc++" match was "stdc") */
1221 if (cl_options
[md
].msg
)
1223 /* Scan forwards. If we get an exact match, return it.
1224 Otherwise, return the longest option-accepting match.
1225 This loops no more than twice with current options */
1227 for (; mn
< N_OPTS
; mn
++)
1229 opt_len
= cl_options
[mn
].opt_len
;
1230 if (strncmp (input
, cl_options
[mn
].opt_text
, opt_len
))
1232 if (input
[opt_len
] == '\0')
1234 if (cl_options
[mn
].msg
)
1245 /* Handle one command-line option in (argc, argv).
1246 Can be called multiple times, to handle multiple sets of options.
1247 Returns number of strings consumed. */
1250 handle_option (pfile
, argc
, argv
)
1256 struct cpp_pending
*pend
= CPP_OPTION (pfile
, pending
);
1258 if (argv
[i
][0] != '-')
1260 if (CPP_OPTION (pfile
, out_fname
) != NULL
)
1261 cpp_fatal (pfile
, "Too many arguments. Type %s --help for usage info",
1263 else if (CPP_OPTION (pfile
, in_fname
) != NULL
)
1264 CPP_OPTION (pfile
, out_fname
) = argv
[i
];
1266 CPP_OPTION (pfile
, in_fname
) = argv
[i
];
1270 enum opt_code opt_code
;
1272 const char *arg
= 0;
1275 opt_index
= parse_option (&argv
[i
][1]);
1279 opt_code
= cl_options
[opt_index
].opt_code
;
1280 if (cl_options
[opt_index
].msg
)
1282 arg
= &argv
[i
][cl_options
[opt_index
].opt_len
+ 1];
1284 /* Yuk. Special case for -g and -W as they must not swallow
1285 up any following argument. If this becomes common, add
1286 another field to the cl_options table */
1287 if (arg
[0] == '\0' && !(opt_code
== OPT_g
|| opt_code
== OPT_W
))
1292 cpp_fatal (pfile
, cl_options
[opt_index
].msg
, argv
[i
- 1]);
1300 case N_OPTS
: /* shut GCC up */
1302 case OPT_fleading_underscore
:
1303 user_label_prefix
= "_";
1305 case OPT_fno_leading_underscore
:
1306 user_label_prefix
= "";
1308 case OPT_fpreprocessed
:
1309 CPP_OPTION (pfile
, preprocessed
) = 1;
1311 case OPT_fno_preprocessed
:
1312 CPP_OPTION (pfile
, preprocessed
) = 0;
1314 case OPT_fshow_column
:
1315 CPP_OPTION (pfile
, show_column
) = 1;
1317 case OPT_fno_show_column
:
1318 CPP_OPTION (pfile
, show_column
) = 0;
1321 /* Silently ignore empty string, non-longs and silly values. */
1325 long tabstop
= strtol (arg
, &endptr
, 10);
1326 if (*endptr
== '\0' && tabstop
>= 1 && tabstop
<= 100)
1327 CPP_OPTION (pfile
, tabstop
) = tabstop
;
1331 CPP_OPTION (pfile
, inhibit_warnings
) = 1;
1333 case OPT_g
: /* Silently ignore anything but -g3 */
1334 if (!strcmp(&argv
[i
][2], "3"))
1335 CPP_OPTION (pfile
, debug_output
) = 1;
1343 fprintf (stderr
, _("GNU CPP version %s (cpplib)\n"), version_string
);
1347 CPP_OPTION (pfile
, discard_comments
) = 0;
1350 CPP_OPTION (pfile
, no_line_commands
) = 1;
1352 case OPT_dollar
: /* Don't include $ in identifiers. */
1353 CPP_OPTION (pfile
, dollars_in_ident
) = 0;
1356 CPP_OPTION (pfile
, print_include_names
) = 1;
1359 new_pending_directive (pend
, arg
, cpp_define
);
1361 case OPT_pedantic_errors
:
1362 CPP_OPTION (pfile
, pedantic_errors
) = 1;
1365 CPP_OPTION (pfile
, pedantic
) = 1;
1367 case OPT_traditional
:
1368 CPP_OPTION (pfile
, traditional
) = 1;
1369 CPP_OPTION (pfile
, cplusplus_comments
) = 0;
1370 CPP_OPTION (pfile
, trigraphs
) = 0;
1371 CPP_OPTION (pfile
, warn_trigraphs
) = 0;
1374 CPP_OPTION (pfile
, trigraphs
) = 1;
1377 CPP_OPTION (pfile
, cplusplus
) = 1;
1378 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1381 CPP_OPTION (pfile
, remap
) = 1;
1384 CPP_OPTION (pfile
, include_prefix
) = arg
;
1385 CPP_OPTION (pfile
, include_prefix_len
) = strlen (arg
);
1388 CPP_OPTION (pfile
, cplusplus
) = 0;
1389 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1390 CPP_OPTION (pfile
, c89
) = 0;
1391 CPP_OPTION (pfile
, c99
) = 1;
1392 CPP_OPTION (pfile
, objc
) = 0;
1395 CPP_OPTION (pfile
, cplusplus
) = 0;
1396 CPP_OPTION (pfile
, cplusplus_comments
) = 0;
1397 CPP_OPTION (pfile
, c89
) = 1;
1398 CPP_OPTION (pfile
, c99
) = 0;
1399 CPP_OPTION (pfile
, objc
) = 0;
1400 CPP_OPTION (pfile
, trigraphs
) = 1;
1401 new_pending_directive (pend
, "__STRICT_ANSI__", cpp_define
);
1403 case OPT_lang_cplusplus
:
1404 CPP_OPTION (pfile
, cplusplus
) = 1;
1405 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1406 CPP_OPTION (pfile
, c89
) = 0;
1407 CPP_OPTION (pfile
, c99
) = 0;
1408 CPP_OPTION (pfile
, objc
) = 0;
1409 new_pending_directive (pend
, "__cplusplus", cpp_define
);
1411 case OPT_lang_objcplusplus
:
1412 CPP_OPTION (pfile
, cplusplus
) = 1;
1413 new_pending_directive (pend
, "__cplusplus", cpp_define
);
1416 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1417 CPP_OPTION (pfile
, c89
) = 0;
1418 CPP_OPTION (pfile
, c99
) = 0;
1419 CPP_OPTION (pfile
, objc
) = 1;
1420 new_pending_directive (pend
, "__OBJC__", cpp_define
);
1423 CPP_OPTION (pfile
, lang_asm
) = 1;
1424 CPP_OPTION (pfile
, dollars_in_ident
) = 0;
1425 new_pending_directive (pend
, "__ASSEMBLER__", cpp_define
);
1427 case OPT_lang_fortran
:
1428 CPP_OPTION (pfile
, lang_fortran
) = 1;
1429 CPP_OPTION (pfile
, traditional
) = 1;
1430 CPP_OPTION (pfile
, cplusplus_comments
) = 0;
1431 new_pending_directive (pend
, "_LANGUAGE_FORTRAN", cpp_define
);
1433 case OPT_lang_chill
:
1434 CPP_OPTION (pfile
, objc
) = 0;
1435 CPP_OPTION (pfile
, cplusplus
) = 0;
1436 CPP_OPTION (pfile
, chill
) = 1;
1437 CPP_OPTION (pfile
, traditional
) = 1;
1440 /* -nostdinc causes no default include directories.
1441 You must specify all include-file directories with -I. */
1442 CPP_OPTION (pfile
, no_standard_includes
) = 1;
1444 case OPT_nostdincplusplus
:
1445 /* -nostdinc++ causes no default C++-specific include directories. */
1446 CPP_OPTION (pfile
, no_standard_cplusplus_includes
) = 1;
1449 CPP_OPTION (pfile
, cplusplus
) = 0;
1450 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1451 CPP_OPTION (pfile
, c89
) = 1;
1452 CPP_OPTION (pfile
, c99
) = 0;
1453 CPP_OPTION (pfile
, objc
) = 0;
1457 CPP_OPTION (pfile
, cplusplus
) = 0;
1458 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1459 CPP_OPTION (pfile
, c89
) = 0;
1460 CPP_OPTION (pfile
, c99
) = 1;
1461 CPP_OPTION (pfile
, objc
) = 0;
1462 new_pending_directive (CPP_OPTION (pfile
, pending
),
1463 "__STDC_VERSION__=199901L", cpp_define
);
1465 case OPT_std_iso9899_199409
:
1466 new_pending_directive (CPP_OPTION (pfile
, pending
),
1467 "__STDC_VERSION__=199409L", cpp_define
);
1469 case OPT_std_iso9899_1990
:
1471 CPP_OPTION (pfile
, cplusplus
) = 0;
1472 CPP_OPTION (pfile
, cplusplus_comments
) = 0;
1473 CPP_OPTION (pfile
, c89
) = 1;
1474 CPP_OPTION (pfile
, c99
) = 0;
1475 CPP_OPTION (pfile
, objc
) = 0;
1476 CPP_OPTION (pfile
, trigraphs
) = 1;
1477 new_pending_directive (CPP_OPTION (pfile
, pending
),
1478 "__STRICT_ANSI__", cpp_define
);
1480 case OPT_std_iso9899_199x
:
1481 case OPT_std_iso9899_1999
:
1484 CPP_OPTION (pfile
, cplusplus
) = 0;
1485 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1486 CPP_OPTION (pfile
, c89
) = 0;
1487 CPP_OPTION (pfile
, c99
) = 1;
1488 CPP_OPTION (pfile
, objc
) = 0;
1489 CPP_OPTION (pfile
, trigraphs
) = 1;
1490 new_pending_directive (CPP_OPTION (pfile
, pending
),
1491 "__STRICT_ANSI__", cpp_define
);
1492 new_pending_directive (CPP_OPTION (pfile
, pending
),
1493 "__STDC_VERSION__=199901L", cpp_define
);
1496 if (CPP_OPTION (pfile
, out_fname
) != NULL
)
1498 cpp_fatal (pfile
, "Output filename specified twice");
1501 CPP_OPTION (pfile
, out_fname
) = arg
;
1502 if (!strcmp (CPP_OPTION (pfile
, out_fname
), "-"))
1503 CPP_OPTION (pfile
, out_fname
) = "";
1506 fprintf (stderr
, _("GNU CPP version %s (cpplib)\n"), version_string
);
1507 #ifdef TARGET_VERSION
1510 fputc ('\n', stderr
);
1511 CPP_OPTION (pfile
, verbose
) = 1;
1513 case OPT_stdin_stdout
:
1514 /* JF handle '-' as file name meaning stdin or stdout */
1515 if (CPP_OPTION (pfile
, in_fname
) == NULL
)
1516 CPP_OPTION (pfile
, in_fname
) = "";
1517 else if (CPP_OPTION (pfile
, out_fname
) == NULL
)
1518 CPP_OPTION (pfile
, out_fname
) = "";
1521 /* Args to -d specify what parts of macros to dump.
1522 Silently ignore unrecognised options; they may
1523 be aimed at the compiler proper. */
1527 while ((c
= *arg
++) != '\0')
1531 CPP_OPTION (pfile
, dump_macros
) = dump_only
;
1532 CPP_OPTION (pfile
, no_output
) = 1;
1535 CPP_OPTION (pfile
, dump_macros
) = dump_names
;
1538 CPP_OPTION (pfile
, dump_macros
) = dump_definitions
;
1541 CPP_OPTION (pfile
, dump_includes
) = 1;
1546 /* The style of the choices here is a bit mixed.
1547 The chosen scheme is a hybrid of keeping all options in one string
1548 and specifying each option in a separate argument:
1549 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
1550 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
1551 -M[M][G][D file]. This is awkward to handle in specs, and is not
1553 /* ??? -MG must be specified in addition to one of -M or -MM.
1554 This can be relaxed in the future without breaking anything.
1555 The converse isn't true. */
1557 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
1559 CPP_OPTION (pfile
, print_deps_missing_files
) = 1;
1565 if (opt_code
== OPT_M
|| opt_code
== OPT_MD
)
1566 CPP_OPTION (pfile
, print_deps
) = 2;
1568 CPP_OPTION (pfile
, print_deps
) = 1;
1570 /* For -MD and -MMD options, write deps on file named by next arg */
1571 /* For -M and -MM, write deps on standard output
1572 and suppress the usual output. */
1573 if (opt_code
== OPT_MD
|| opt_code
== OPT_MMD
)
1574 CPP_OPTION (pfile
, deps_file
) = arg
;
1576 CPP_OPTION (pfile
, no_output
) = 1;
1581 /* -A with an argument beginning with '-' acts as
1582 #unassert on whatever immediately follows the '-'.
1583 If "-" is the whole argument, we eliminate all
1584 predefined macros and assertions, including those
1585 that were specified earlier on the command line.
1586 That way we can get rid of any that were passed
1587 automatically in from GCC. */
1591 struct pending_option
*o1
, *o2
;
1593 o1
= CPP_OPTION (pfile
, pending
)->directive_head
;
1600 CPP_OPTION (pfile
, pending
)->directive_head
= NULL
;
1601 CPP_OPTION (pfile
, pending
)->directive_tail
= NULL
;
1604 new_pending_directive (CPP_OPTION (pfile
, pending
),
1605 arg
+ 1, cpp_unassert
);
1608 new_pending_directive (CPP_OPTION (pfile
, pending
),
1612 new_pending_directive (CPP_OPTION (pfile
, pending
), arg
, cpp_undef
);
1614 case OPT_I
: /* Add directory to path for includes. */
1615 if (!strcmp (arg
, "-"))
1618 Use the preceding -I directories for #include "..."
1619 but not #include <...>.
1620 Don't search the directory of the present file
1621 for #include "...". (Note that -I. -I- is not the same as
1622 the default setup; -I. uses the compiler's working dir.) */
1623 if (! CPP_OPTION (pfile
, ignore_srcdir
))
1625 struct cpp_pending
*pend
= CPP_OPTION (pfile
, pending
);
1626 pend
->quote_head
= pend
->brack_head
;
1627 pend
->quote_tail
= pend
->brack_tail
;
1628 pend
->brack_head
= 0;
1629 pend
->brack_tail
= 0;
1630 CPP_OPTION (pfile
, ignore_srcdir
) = 1;
1634 cpp_fatal (pfile
, "-I- specified twice");
1639 append_include_chain (pfile
, CPP_OPTION (pfile
, pending
),
1640 xstrdup (arg
), BRACKET
, 0);
1643 /* Add directory to beginning of system include path, as a system
1644 include directory. */
1645 append_include_chain (pfile
, CPP_OPTION (pfile
, pending
),
1646 xstrdup (arg
), SYSTEM
, 0);
1650 struct pending_option
*o
= (struct pending_option
*)
1651 xmalloc (sizeof (struct pending_option
));
1654 /* This list has to be built in reverse order so that
1655 when cpp_start_read pushes all the -include files onto
1656 the buffer stack, they will be scanned in forward order. */
1657 o
->next
= CPP_OPTION (pfile
, pending
)->include_head
;
1658 CPP_OPTION (pfile
, pending
)->include_head
= o
;
1663 struct pending_option
*o
= (struct pending_option
*)
1664 xmalloc (sizeof (struct pending_option
));
1668 APPEND (CPP_OPTION (pfile
, pending
), imacros
, o
);
1671 case OPT_iwithprefix
:
1672 /* Add directory to end of path for includes,
1673 with the default prefix at the front of its name. */
1675 case OPT_iwithprefixbefore
:
1676 /* Add directory to main path for includes,
1677 with the default prefix at the front of its name. */
1684 if (CPP_OPTION (pfile
, include_prefix
) != 0)
1686 size_t ipl
= CPP_OPTION (pfile
, include_prefix_len
);
1687 fname
= xmalloc (ipl
+ len
+ 1);
1688 memcpy (fname
, CPP_OPTION (pfile
, include_prefix
), ipl
);
1689 memcpy (fname
+ ipl
, arg
, len
+ 1);
1693 fname
= xmalloc (sizeof GCC_INCLUDE_DIR
- 8 + len
);
1694 memcpy (fname
, GCC_INCLUDE_DIR
, sizeof GCC_INCLUDE_DIR
- 9);
1695 memcpy (fname
+ sizeof GCC_INCLUDE_DIR
- 9, arg
, len
+ 1);
1698 append_include_chain (pfile
, CPP_OPTION (pfile
, pending
), fname
,
1699 opt_code
== OPT_iwithprefix
? SYSTEM
: BRACKET
, 0);
1703 /* Add directory to end of path for includes. */
1704 append_include_chain (pfile
, CPP_OPTION (pfile
, pending
),
1705 xstrdup (arg
), AFTER
, 0);
1708 /* Silently ignore unrecognised options */
1709 if (!strcmp (argv
[i
], "-Wall"))
1711 CPP_OPTION (pfile
, warn_trigraphs
) = 1;
1712 CPP_OPTION (pfile
, warn_comments
) = 1;
1714 else if (!strcmp (argv
[i
], "-Wtraditional"))
1715 CPP_OPTION (pfile
, warn_traditional
) = 1;
1716 else if (!strcmp (argv
[i
], "-Wtrigraphs"))
1717 CPP_OPTION (pfile
, warn_trigraphs
) = 1;
1718 else if (!strcmp (argv
[i
], "-Wcomment"))
1719 CPP_OPTION (pfile
, warn_comments
) = 1;
1720 else if (!strcmp (argv
[i
], "-Wcomments"))
1721 CPP_OPTION (pfile
, warn_comments
) = 1;
1722 else if (!strcmp (argv
[i
], "-Wundef"))
1723 CPP_OPTION (pfile
, warn_undef
) = 1;
1724 else if (!strcmp (argv
[i
], "-Wimport"))
1725 CPP_OPTION (pfile
, warn_import
) = 1;
1726 else if (!strcmp (argv
[i
], "-Werror"))
1727 CPP_OPTION (pfile
, warnings_are_errors
) = 1;
1728 else if (!strcmp (argv
[i
], "-Wno-traditional"))
1729 CPP_OPTION (pfile
, warn_traditional
) = 0;
1730 else if (!strcmp (argv
[i
], "-Wno-trigraphs"))
1731 CPP_OPTION (pfile
, warn_trigraphs
) = 0;
1732 else if (!strcmp (argv
[i
], "-Wno-comment"))
1733 CPP_OPTION (pfile
, warn_comments
) = 0;
1734 else if (!strcmp (argv
[i
], "-Wno-comments"))
1735 CPP_OPTION (pfile
, warn_comments
) = 0;
1736 else if (!strcmp (argv
[i
], "-Wno-undef"))
1737 CPP_OPTION (pfile
, warn_undef
) = 0;
1738 else if (!strcmp (argv
[i
], "-Wno-import"))
1739 CPP_OPTION (pfile
, warn_import
) = 0;
1740 else if (!strcmp (argv
[i
], "-Wno-error"))
1741 CPP_OPTION (pfile
, warnings_are_errors
) = 0;
1750 opt_comp (const void *p1
, const void *p2
)
1752 return strcmp (((struct cl_option
*)p1
)->opt_text
,
1753 ((struct cl_option
*)p2
)->opt_text
);
1757 /* Handle command-line options in (argc, argv).
1758 Can be called multiple times, to handle multiple sets of options.
1759 Returns if an unrecognized option is seen.
1760 Returns number of strings consumed. */
1762 cpp_handle_options (pfile
, argc
, argv
)
1768 int strings_processed
;
1771 static int opts_sorted
= 0;
1776 /* For non-ASCII hosts, the array needs to be sorted at runtime */
1777 qsort (cl_options
, N_OPTS
, sizeof (struct cl_option
), opt_comp
);
1781 for (i
= 0; i
< argc
; i
+= strings_processed
)
1783 strings_processed
= handle_option (pfile
, argc
- i
, argv
+ i
);
1784 if (strings_processed
== 0)
1793 fprintf (stderr
, _("Usage: %s [switches] input output\n"), progname
);
1796 -include <file> Include the contents of <file> before other files\n\
1797 -imacros <file> Accept definition of macros in <file>\n\
1798 -iprefix <path> Specify <path> as a prefix for next two options\n\
1799 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1800 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1801 -isystem <dir> Add <dir> to the start of the system include path\n\
1802 -idirafter <dir> Add <dir> to the end of the system include path\n\
1803 -I <dir> Add <dir> to the end of the main include path\n\
1804 -I- Fine-grained include path control; see info docs\n\
1805 -nostdinc Do not search system include directories\n\
1806 (dirs specified with -isystem will still be used)\n\
1807 -nostdinc++ Do not search system include directories for C++\n\
1808 -o <file> Put output into <file>\n\
1809 -pedantic Issue all warnings demanded by strict ANSI C\n\
1810 -pedantic-errors Issue -pedantic warnings as errors instead\n\
1811 -traditional Follow K&R pre-processor behaviour\n\
1812 -trigraphs Support ANSI C trigraphs\n\
1813 -lang-c Assume that the input sources are in C\n\
1814 -lang-c89 Assume that the input sources are in C89\n\
1815 -lang-c++ Assume that the input sources are in C++\n\
1816 -lang-objc Assume that the input sources are in ObjectiveC\n\
1817 -lang-objc++ Assume that the input sources are in ObjectiveC++\n\
1818 -lang-asm Assume that the input sources are in assembler\n\
1819 -lang-fortran Assume that the input sources are in Fortran\n\
1820 -lang-chill Assume that the input sources are in Chill\n\
1821 -std=<std name> Specify the conformance standard; one of:\n\
1822 gnu89, gnu99, c89, c99, iso9899:1990,\n\
1823 iso9899:199409, iso9899:1999\n\
1824 -+ Allow parsing of C++ style features\n\
1825 -w Inhibit warning messages\n\
1826 -Wtrigraphs Warn if trigraphs are encountered\n\
1827 -Wno-trigraphs Do not warn about trigraphs\n\
1828 -Wcomment{s} Warn if one comment starts inside another\n\
1829 -Wno-comment{s} Do not warn about comments\n\
1830 -Wtraditional Warn if a macro argument is/would be turned into\n\
1831 a string if -traditional is specified\n\
1832 -Wno-traditional Do not warn about stringification\n\
1833 -Wundef Warn if an undefined macro is used by #if\n\
1834 -Wno-undef Do not warn about testing undefined macros\n\
1835 -Wimport Warn about the use of the #import directive\n\
1836 -Wno-import Do not warn about the use of #import\n\
1837 -Werror Treat all warnings as errors\n\
1838 -Wno-error Do not treat warnings as errors\n\
1839 -Wall Enable all preprocessor warnings\n\
1840 -M Generate make dependencies\n\
1841 -MM As -M, but ignore system header files\n\
1842 -MD As -M, but put output in a .d file\n\
1843 -MMD As -MD, but ignore system header files\n\
1844 -MG Treat missing header file as generated files\n\
1845 -g3 Include #define and #undef directives in the output\n\
1846 -D<macro> Define a <macro> with string '1' as its value\n\
1847 -D<macro>=<val> Define a <macro> with <val> as its value\n\
1848 -A<question> (<answer>) Assert the <answer> to <question>\n\
1849 -A-<question> (<answer>) Disable the <answer> to <question>\n\
1850 -U<macro> Undefine <macro> \n\
1851 -v Display the version number\n\
1852 -H Print the name of header files as they are used\n\
1853 -C Do not discard comments\n\
1854 -dM Display a list of macro definitions active at end\n\
1855 -dD Preserve macro definitions in output\n\
1856 -dN As -dD except that only the names are preserved\n\
1857 -dI Include #include directives in the output\n\
1858 -ftabstop=<number> Distance between tab stops for column reporting\n\
1859 -P Do not generate #line directives\n\
1860 -$ Do not allow '$' in identifiers\n\
1861 -remap Remap file names when including files.\n\
1862 --version Display version information\n\
1863 -h or --help Display this information\n\