]>
Commit | Line | Data |
---|---|---|
5538ada6 | 1 | /* CPP Library. |
5e7b4e25 JL |
2 | Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
3 | 1999, 2000 Free Software Foundation, Inc. | |
5538ada6 ZW |
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 | |
7 | ||
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 | |
11 | later version. | |
12 | ||
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. | |
17 | ||
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. */ | |
21 | ||
5538ada6 ZW |
22 | #include "config.h" |
23 | #include "system.h" | |
24 | ||
6de1e2a9 ZW |
25 | #include "cpplib.h" |
26 | #include "cpphash.h" | |
27 | #include "output.h" | |
28 | #include "prefix.h" | |
29 | #include "intl.h" | |
9f8f4efe | 30 | #include "version.h" |
49e6c08e | 31 | #include "mkdeps.h" |
6de1e2a9 ZW |
32 | |
33 | /* Predefined symbols, built-in macros, and the default include path. */ | |
34 | ||
35 | #ifndef GET_ENV_PATH_LIST | |
36 | #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0) | |
37 | #endif | |
38 | ||
6de1e2a9 ZW |
39 | #ifndef STANDARD_INCLUDE_DIR |
40 | #define STANDARD_INCLUDE_DIR "/usr/include" | |
41 | #endif | |
42 | ||
6de1e2a9 ZW |
43 | /* We let tm.h override the types used here, to handle trivial differences |
44 | such as the choice of unsigned int or long unsigned int for size_t. | |
45 | When machines start needing nontrivial differences in the size type, | |
46 | it would be best to do something here to figure out automatically | |
47 | from other information what type to use. */ | |
48 | ||
49 | /* The string value for __SIZE_TYPE__. */ | |
50 | ||
51 | #ifndef SIZE_TYPE | |
52 | #define SIZE_TYPE "long unsigned int" | |
53 | #endif | |
54 | ||
55 | /* The string value for __PTRDIFF_TYPE__. */ | |
56 | ||
57 | #ifndef PTRDIFF_TYPE | |
58 | #define PTRDIFF_TYPE "long int" | |
59 | #endif | |
60 | ||
61 | /* The string value for __WCHAR_TYPE__. */ | |
62 | ||
63 | #ifndef WCHAR_TYPE | |
64 | #define WCHAR_TYPE "int" | |
65 | #endif | |
6de1e2a9 ZW |
66 | |
67 | /* The string value for __USER_LABEL_PREFIX__ */ | |
68 | ||
69 | #ifndef USER_LABEL_PREFIX | |
70 | #define USER_LABEL_PREFIX "" | |
71 | #endif | |
72 | ||
73 | /* The string value for __REGISTER_PREFIX__ */ | |
74 | ||
75 | #ifndef REGISTER_PREFIX | |
76 | #define REGISTER_PREFIX "" | |
77 | #endif | |
78 | ||
0b22d65c ZW |
79 | /* This is the default list of directories to search for include files. |
80 | It may be overridden by the various -I and -ixxx options. | |
81 | ||
82 | #include "file" looks in the same directory as the current file, | |
83 | then this list. | |
84 | #include <file> just looks in this list. | |
85 | ||
86 | All these directories are treated as `system' include directories | |
87 | (they are not subject to pedantic warnings in some cases). */ | |
88 | ||
455d2586 | 89 | struct default_include |
0b22d65c | 90 | { |
bcc5cac9 KG |
91 | const char *fname; /* The name of the directory. */ |
92 | const char *component; /* The component containing the directory | |
0b22d65c | 93 | (see update_path in prefix.c) */ |
6de1e2a9 ZW |
94 | int cplusplus; /* Only look here if we're compiling C++. */ |
95 | int cxx_aware; /* Includes in this directory don't need to | |
96 | be wrapped in extern "C" when compiling | |
c45da1ca | 97 | C++. */ |
455d2586 ZW |
98 | }; |
99 | ||
100 | static const struct default_include include_defaults_array[] | |
6de1e2a9 | 101 | #ifdef INCLUDE_DEFAULTS |
0b22d65c | 102 | = INCLUDE_DEFAULTS; |
6de1e2a9 | 103 | #else |
0b22d65c | 104 | = { |
6de1e2a9 ZW |
105 | /* Pick up GNU C++ specific include files. */ |
106 | { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 }, | |
107 | #ifdef CROSS_COMPILE | |
108 | /* This is the dir for fixincludes. Put it just before | |
109 | the files that we fix. */ | |
110 | { GCC_INCLUDE_DIR, "GCC", 0, 0 }, | |
111 | /* For cross-compilation, this dir name is generated | |
112 | automatically in Makefile.in. */ | |
0b22d65c | 113 | { CROSS_INCLUDE_DIR, "GCC", 0, 0 }, |
6de1e2a9 ZW |
114 | #ifdef TOOL_INCLUDE_DIR |
115 | /* This is another place that the target system's headers might be. */ | |
116 | { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 }, | |
117 | #endif | |
118 | #else /* not CROSS_COMPILE */ | |
119 | #ifdef LOCAL_INCLUDE_DIR | |
120 | /* This should be /usr/local/include and should come before | |
121 | the fixincludes-fixed header files. */ | |
122 | { LOCAL_INCLUDE_DIR, 0, 0, 1 }, | |
123 | #endif | |
124 | #ifdef TOOL_INCLUDE_DIR | |
125 | /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here. | |
126 | Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */ | |
127 | { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 }, | |
128 | #endif | |
129 | /* This is the dir for fixincludes. Put it just before | |
130 | the files that we fix. */ | |
131 | { GCC_INCLUDE_DIR, "GCC", 0, 0 }, | |
132 | /* Some systems have an extra dir of include files. */ | |
133 | #ifdef SYSTEM_INCLUDE_DIR | |
134 | { SYSTEM_INCLUDE_DIR, 0, 0, 0 }, | |
135 | #endif | |
136 | #ifndef STANDARD_INCLUDE_COMPONENT | |
137 | #define STANDARD_INCLUDE_COMPONENT 0 | |
138 | #endif | |
139 | { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0 }, | |
140 | #endif /* not CROSS_COMPILE */ | |
141 | { 0, 0, 0, 0 } | |
0b22d65c | 142 | }; |
6de1e2a9 ZW |
143 | #endif /* no INCLUDE_DEFAULTS */ |
144 | ||
145 | /* Internal structures and prototypes. */ | |
146 | ||
0b22d65c ZW |
147 | /* A `struct pending_option' remembers one -D, -A, -U, -include, or -imacros |
148 | switch. There are four lists: one for -D and -U, one for -A, one | |
149 | for -include, one for -imacros. `undef' is set for -U, clear for | |
150 | -D, ignored for the others. | |
151 | (Future: add an equivalent of -U for -A) */ | |
152 | struct pending_option | |
6de1e2a9 | 153 | { |
0b22d65c | 154 | struct pending_option *next; |
6de1e2a9 | 155 | char *arg; |
0b22d65c | 156 | int undef; |
6de1e2a9 | 157 | }; |
0b22d65c ZW |
158 | |
159 | #ifdef __STDC__ | |
160 | #define APPEND(pend, list, elt) \ | |
161 | do { if (!(pend)->list##_head) (pend)->list##_head = (elt); \ | |
162 | else (pend)->list##_tail->next = (elt); \ | |
163 | (pend)->list##_tail = (elt); \ | |
164 | } while (0) | |
165 | #else | |
166 | #define APPEND(pend, list, elt) \ | |
167 | do { if (!(pend)->list/**/_head) (pend)->list/**/_head = (elt); \ | |
168 | else (pend)->list/**/_tail->next = (elt); \ | |
169 | (pend)->list/**/_tail = (elt); \ | |
170 | } while (0) | |
171 | #endif | |
6de1e2a9 | 172 | |
6de1e2a9 | 173 | static void print_help PARAMS ((void)); |
0b22d65c ZW |
174 | static void path_include PARAMS ((cpp_reader *, |
175 | struct cpp_pending *, | |
176 | char *, int)); | |
6de1e2a9 | 177 | static void initialize_builtins PARAMS ((cpp_reader *)); |
0b22d65c ZW |
178 | static void append_include_chain PARAMS ((cpp_reader *, |
179 | struct cpp_pending *, | |
c45da1ca | 180 | char *, int, int)); |
bcc5cac9 KG |
181 | static void dump_special_to_buffer PARAMS ((cpp_reader *, const char *)); |
182 | static void initialize_dependency_output PARAMS ((cpp_reader *)); | |
c45da1ca | 183 | static void initialize_standard_includes PARAMS ((cpp_reader *)); |
40ea76de ZW |
184 | static void new_pending_define PARAMS ((struct cpp_options *, |
185 | const char *)); | |
e23c0ba3 ZW |
186 | #ifdef HOST_EBCDIC |
187 | static int opt_comp PARAMS ((const void *, const void *)); | |
188 | #endif | |
189 | static int parse_option PARAMS ((const char *)); | |
b0699dad | 190 | static int handle_option PARAMS ((cpp_reader *, int, char **)); |
6de1e2a9 | 191 | |
c45da1ca | 192 | /* Fourth argument to append_include_chain: chain to use */ |
0b22d65c | 193 | enum { QUOTE = 0, BRACKET, SYSTEM, AFTER }; |
6de1e2a9 | 194 | |
455d2586 ZW |
195 | /* If we have designated initializers (GCC >2.7, or C99) this table |
196 | can be initialized, constant data. Otherwise, it has to be filled | |
197 | in at runtime. */ | |
a9ae4483 | 198 | |
455d2586 ZW |
199 | #if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L) |
200 | #define init_IStable() /* nothing */ | |
201 | #define ISTABLE const unsigned char _cpp_IStable[256] = { | |
a9ae4483 | 202 | #define END }; |
455d2586 | 203 | #define s(p, v) [p] = v, |
a9ae4483 | 204 | #else |
455d2586 ZW |
205 | #define ISTABLE unsigned char _cpp_IStable[256] = { 0 }; \ |
206 | static void init_IStable PARAMS ((void)) { \ | |
c6491210 | 207 | unsigned char *x = _cpp_IStable; |
a9ae4483 | 208 | #define END } |
455d2586 | 209 | #define s(p, v) x[p] = v; |
a9ae4483 | 210 | #endif |
6de1e2a9 | 211 | |
a9ae4483 ZW |
212 | #define A(x) s(x, ISidnum|ISidstart) |
213 | #define N(x) s(x, ISidnum|ISnumstart) | |
214 | #define H(x) s(x, IShspace|ISspace) | |
215 | #define S(x) s(x, ISspace) | |
6de1e2a9 | 216 | |
455d2586 | 217 | ISTABLE |
a9ae4483 | 218 | A('_') |
6de1e2a9 | 219 | |
a9ae4483 ZW |
220 | A('a') A('b') A('c') A('d') A('e') A('f') A('g') A('h') A('i') |
221 | A('j') A('k') A('l') A('m') A('n') A('o') A('p') A('q') A('r') | |
222 | A('s') A('t') A('u') A('v') A('w') A('x') A('y') A('z') | |
6de1e2a9 | 223 | |
a9ae4483 ZW |
224 | A('A') A('B') A('C') A('D') A('E') A('F') A('G') A('H') A('I') |
225 | A('J') A('K') A('L') A('M') A('N') A('O') A('P') A('Q') A('R') | |
226 | A('S') A('T') A('U') A('V') A('W') A('X') A('Y') A('Z') | |
6de1e2a9 | 227 | |
a9ae4483 | 228 | N('1') N('2') N('3') N('4') N('5') N('6') N('7') N('8') N('9') N('0') |
5538ada6 | 229 | |
a9ae4483 | 230 | H(' ') H('\t') H('\v') H('\f') |
6de1e2a9 | 231 | |
a9ae4483 ZW |
232 | S('\n') |
233 | END | |
234 | ||
235 | #undef A | |
236 | #undef N | |
237 | #undef H | |
238 | #undef S | |
a9ae4483 | 239 | #undef s |
455d2586 ZW |
240 | #undef ISTABLE |
241 | #undef END | |
6de1e2a9 ZW |
242 | |
243 | /* Given a colon-separated list of file names PATH, | |
244 | add all the names to the search path for include files. */ | |
245 | ||
246 | static void | |
0b22d65c | 247 | path_include (pfile, pend, list, path) |
6de1e2a9 | 248 | cpp_reader *pfile; |
0b22d65c ZW |
249 | struct cpp_pending *pend; |
250 | char *list; | |
251 | int path; | |
6de1e2a9 | 252 | { |
0b22d65c | 253 | char *p, *q, *name; |
6de1e2a9 | 254 | |
0b22d65c | 255 | p = list; |
6de1e2a9 | 256 | |
0b22d65c ZW |
257 | do |
258 | { | |
6de1e2a9 | 259 | /* Find the end of this name. */ |
0b22d65c | 260 | q = p; |
6de1e2a9 | 261 | while (*q != 0 && *q != PATH_SEPARATOR) q++; |
0b22d65c ZW |
262 | if (q == p) |
263 | { | |
264 | /* An empty name in the path stands for the current directory. */ | |
265 | name = (char *) xmalloc (2); | |
266 | name[0] = '.'; | |
267 | name[1] = 0; | |
268 | } | |
269 | else | |
270 | { | |
271 | /* Otherwise use the directory that is named. */ | |
272 | name = (char *) xmalloc (q - p + 1); | |
273 | memcpy (name, p, q - p); | |
274 | name[q - p] = 0; | |
275 | } | |
6de1e2a9 | 276 | |
c45da1ca | 277 | append_include_chain (pfile, pend, name, path, 0); |
6de1e2a9 ZW |
278 | |
279 | /* Advance past this name. */ | |
0b22d65c | 280 | if (*q == 0) |
6de1e2a9 | 281 | break; |
0b22d65c ZW |
282 | p = q + 1; |
283 | } | |
284 | while (1); | |
285 | } | |
286 | ||
0b22d65c ZW |
287 | /* Append DIR to include path PATH. DIR must be permanently allocated |
288 | and writable. */ | |
289 | static void | |
c45da1ca | 290 | append_include_chain (pfile, pend, dir, path, cxx_aware) |
0b22d65c ZW |
291 | cpp_reader *pfile; |
292 | struct cpp_pending *pend; | |
293 | char *dir; | |
294 | int path; | |
c45da1ca | 295 | int cxx_aware; |
0b22d65c ZW |
296 | { |
297 | struct file_name_list *new; | |
298 | struct stat st; | |
299 | unsigned int len; | |
300 | ||
b0699dad | 301 | _cpp_simplify_pathname (dir); |
0b22d65c ZW |
302 | if (stat (dir, &st)) |
303 | { | |
304 | /* Dirs that don't exist are silently ignored. */ | |
305 | if (errno != ENOENT) | |
c1212d2f | 306 | cpp_notice_from_errno (pfile, dir); |
0b22d65c | 307 | else if (CPP_OPTIONS (pfile)->verbose) |
c1212d2f | 308 | fprintf (stderr, _("ignoring nonexistent directory `%s'\n"), dir); |
0b22d65c ZW |
309 | return; |
310 | } | |
311 | ||
312 | if (!S_ISDIR (st.st_mode)) | |
313 | { | |
c1212d2f | 314 | cpp_notice (pfile, "%s: Not a directory", dir); |
0b22d65c ZW |
315 | return; |
316 | } | |
317 | ||
318 | len = strlen (dir); | |
319 | if (len > pfile->max_include_len) | |
320 | pfile->max_include_len = len; | |
321 | ||
322 | new = (struct file_name_list *)xmalloc (sizeof (struct file_name_list)); | |
323 | new->name = dir; | |
324 | new->nlen = len; | |
325 | new->ino = st.st_ino; | |
326 | new->dev = st.st_dev; | |
c45da1ca ZW |
327 | if (path == SYSTEM) |
328 | new->sysp = cxx_aware ? 1 : 2; | |
329 | else | |
330 | new->sysp = 0; | |
0b22d65c | 331 | new->name_map = NULL; |
503cb436 DB |
332 | new->next = NULL; |
333 | new->alloc = NULL; | |
0b22d65c ZW |
334 | |
335 | switch (path) | |
336 | { | |
337 | case QUOTE: APPEND (pend, quote, new); break; | |
338 | case BRACKET: APPEND (pend, brack, new); break; | |
339 | case SYSTEM: APPEND (pend, systm, new); break; | |
340 | case AFTER: APPEND (pend, after, new); break; | |
6de1e2a9 ZW |
341 | } |
342 | } | |
343 | ||
0b22d65c | 344 | |
6de1e2a9 ZW |
345 | /* Write out a #define command for the special named MACRO_NAME |
346 | to PFILE's token_buffer. */ | |
347 | ||
348 | static void | |
349 | dump_special_to_buffer (pfile, macro_name) | |
350 | cpp_reader *pfile; | |
bcc5cac9 | 351 | const char *macro_name; |
6de1e2a9 | 352 | { |
c45da1ca | 353 | static const char define_directive[] = "#define "; |
6de1e2a9 | 354 | int macro_name_length = strlen (macro_name); |
80e9dcb4 | 355 | output_line_command (pfile, same_file); |
6de1e2a9 ZW |
356 | CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length); |
357 | CPP_PUTS_Q (pfile, define_directive, sizeof(define_directive)-1); | |
358 | CPP_PUTS_Q (pfile, macro_name, macro_name_length); | |
359 | CPP_PUTC_Q (pfile, ' '); | |
360 | cpp_expand_to_buffer (pfile, macro_name, macro_name_length); | |
361 | CPP_PUTC (pfile, '\n'); | |
362 | } | |
363 | ||
6de1e2a9 ZW |
364 | /* Initialize a cpp_options structure. */ |
365 | void | |
366 | cpp_options_init (opts) | |
367 | cpp_options *opts; | |
368 | { | |
0b22d65c | 369 | bzero ((char *) opts, sizeof (struct cpp_options)); |
6de1e2a9 ZW |
370 | |
371 | opts->dollars_in_ident = 1; | |
372 | opts->cplusplus_comments = 1; | |
373 | opts->warn_import = 1; | |
564ad5f4 | 374 | opts->discard_comments = 1; |
0b22d65c | 375 | |
ad85216e KG |
376 | opts->pending = |
377 | (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending)); | |
6de1e2a9 ZW |
378 | } |
379 | ||
380 | /* Initialize a cpp_reader structure. */ | |
381 | void | |
382 | cpp_reader_init (pfile) | |
383 | cpp_reader *pfile; | |
384 | { | |
385 | bzero ((char *) pfile, sizeof (cpp_reader)); | |
6de1e2a9 ZW |
386 | |
387 | pfile->token_buffer_size = 200; | |
388 | pfile->token_buffer = (U_CHAR *) xmalloc (pfile->token_buffer_size); | |
389 | CPP_SET_WRITTEN (pfile, 0); | |
122ae89b ZW |
390 | |
391 | pfile->hashtab = (HASHNODE **) xcalloc (HASHSIZE, sizeof (HASHNODE *)); | |
6de1e2a9 ZW |
392 | } |
393 | ||
394 | /* Free resources used by PFILE. | |
395 | This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */ | |
396 | void | |
397 | cpp_cleanup (pfile) | |
398 | cpp_reader *pfile; | |
399 | { | |
400 | int i; | |
401 | while (CPP_BUFFER (pfile) != CPP_NULL_BUFFER (pfile)) | |
402 | cpp_pop_buffer (pfile); | |
403 | ||
404 | if (pfile->token_buffer) | |
405 | { | |
406 | free (pfile->token_buffer); | |
407 | pfile->token_buffer = NULL; | |
408 | } | |
409 | ||
2c826217 ZW |
410 | if (pfile->input_buffer) |
411 | { | |
412 | free (pfile->input_buffer); | |
413 | free (pfile->input_speccase); | |
414 | pfile->input_buffer = pfile->input_speccase = NULL; | |
415 | pfile->input_buffer_len = 0; | |
416 | } | |
417 | ||
49e6c08e ZW |
418 | if (pfile->deps) |
419 | deps_free (pfile->deps); | |
420 | ||
6de1e2a9 ZW |
421 | while (pfile->if_stack) |
422 | { | |
423 | IF_STACK_FRAME *temp = pfile->if_stack; | |
424 | pfile->if_stack = temp->next; | |
425 | free (temp); | |
426 | } | |
427 | ||
428 | for (i = ALL_INCLUDE_HASHSIZE; --i >= 0; ) | |
429 | { | |
430 | struct include_hash *imp = pfile->all_include_files[i]; | |
431 | while (imp) | |
432 | { | |
433 | struct include_hash *next = imp->next; | |
49e6c08e ZW |
434 | |
435 | free ((PTR) imp->name); | |
b0699dad | 436 | free ((PTR) imp->nshort); |
6de1e2a9 ZW |
437 | free (imp); |
438 | imp = next; | |
439 | } | |
440 | pfile->all_include_files[i] = 0; | |
441 | } | |
442 | ||
122ae89b ZW |
443 | for (i = HASHSIZE; --i >= 0;) |
444 | { | |
445 | while (pfile->hashtab[i]) | |
b0699dad | 446 | _cpp_delete_macro (pfile->hashtab[i]); |
122ae89b ZW |
447 | } |
448 | free (pfile->hashtab); | |
6de1e2a9 ZW |
449 | } |
450 | ||
451 | ||
a9ae4483 ZW |
452 | /* This structure defines one built-in macro. A node of type TYPE will |
453 | be entered in the macro hash table under the name NAME, with value | |
454 | VALUE (if any). FLAGS tweaks the behavior a little: | |
455 | DUMP write debug info for this macro | |
456 | STDC define only if not -traditional | |
a9ae4483 ZW |
457 | ULP value is the global user_label_prefix (which can't be |
458 | put directly into the table). | |
459 | */ | |
460 | ||
461 | struct builtin | |
462 | { | |
463 | const char *name; | |
464 | const char *value; | |
465 | unsigned short type; | |
466 | unsigned short flags; | |
467 | }; | |
468 | #define DUMP 0x01 | |
469 | #define STDC 0x02 | |
a9ae4483 ZW |
470 | #define ULP 0x10 |
471 | ||
472 | static const struct builtin builtin_array[] = | |
6de1e2a9 | 473 | { |
a9ae4483 ZW |
474 | { "__TIME__", 0, T_TIME, DUMP }, |
475 | { "__DATE__", 0, T_DATE, DUMP }, | |
476 | { "__FILE__", 0, T_FILE, 0 }, | |
c45da1ca | 477 | { "__BASE_FILE__", 0, T_BASE_FILE, 0 }, |
a9ae4483 ZW |
478 | { "__LINE__", 0, T_SPECLINE, 0 }, |
479 | { "__INCLUDE_LEVEL__", 0, T_INCLUDE_LEVEL, 0 }, | |
480 | { "__VERSION__", 0, T_VERSION, DUMP }, | |
481 | { "__STDC__", 0, T_STDC, DUMP|STDC }, | |
482 | ||
483 | { "__USER_LABEL_PREFIX__", 0, T_CONST, ULP }, | |
484 | { "__REGISTER_PREFIX__", REGISTER_PREFIX, T_CONST, 0 }, | |
485 | { "__HAVE_BUILTIN_SETJMP__", "1", T_CONST, 0 }, | |
6de1e2a9 | 486 | #ifndef NO_BUILTIN_SIZE_TYPE |
a9ae4483 | 487 | { "__SIZE_TYPE__", SIZE_TYPE, T_CONST, DUMP }, |
6de1e2a9 ZW |
488 | #endif |
489 | #ifndef NO_BUILTIN_PTRDIFF_TYPE | |
a9ae4483 | 490 | { "__PTRDIFF_TYPE__", PTRDIFF_TYPE, T_CONST, DUMP }, |
6de1e2a9 | 491 | #endif |
0209c340 | 492 | #ifndef NO_BUILTIN_WCHAR_TYPE |
a9ae4483 | 493 | { "__WCHAR_TYPE__", WCHAR_TYPE, T_CONST, DUMP }, |
0209c340 | 494 | #endif |
a9ae4483 ZW |
495 | { 0, 0, 0, 0 } |
496 | }; | |
497 | ||
498 | /* Subroutine of cpp_start_read; reads the builtins table above and | |
499 | enters the macros into the hash table. */ | |
6de1e2a9 | 500 | |
a9ae4483 ZW |
501 | static void |
502 | initialize_builtins (pfile) | |
503 | cpp_reader *pfile; | |
504 | { | |
505 | int len; | |
506 | const struct builtin *b; | |
507 | const char *val; | |
508 | for(b = builtin_array; b->name; b++) | |
6de1e2a9 | 509 | { |
a9ae4483 ZW |
510 | if ((b->flags & STDC) && CPP_TRADITIONAL (pfile)) |
511 | continue; | |
a9ae4483 ZW |
512 | |
513 | val = (b->flags & ULP) ? user_label_prefix : b->value; | |
514 | len = strlen (b->name); | |
515 | ||
b0699dad | 516 | _cpp_install (pfile, b->name, len, b->type, val); |
a9ae4483 ZW |
517 | if ((b->flags & DUMP) && CPP_OPTIONS (pfile)->debug_output) |
518 | dump_special_to_buffer (pfile, b->name); | |
6de1e2a9 | 519 | } |
a9ae4483 | 520 | |
6de1e2a9 | 521 | } |
a9ae4483 ZW |
522 | #undef DUMP |
523 | #undef STDC | |
a9ae4483 | 524 | #undef ULP |
6de1e2a9 | 525 | |
0b22d65c ZW |
526 | /* Another subroutine of cpp_start_read. This one sets up to do |
527 | dependency-file output. */ | |
528 | static void | |
529 | initialize_dependency_output (pfile) | |
530 | cpp_reader *pfile; | |
531 | { | |
532 | cpp_options *opts = CPP_OPTIONS (pfile); | |
533 | char *spec, *s, *output_file; | |
534 | ||
535 | /* Either of two environment variables can specify output of deps. | |
536 | Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET", | |
537 | where OUTPUT_FILE is the file to write deps info to | |
538 | and DEPS_TARGET is the target to mention in the deps. */ | |
539 | ||
540 | if (opts->print_deps == 0) | |
541 | { | |
542 | spec = getenv ("DEPENDENCIES_OUTPUT"); | |
543 | if (spec) | |
544 | opts->print_deps = 1; | |
545 | else | |
546 | { | |
547 | spec = getenv ("SUNPRO_DEPENDENCIES"); | |
548 | if (spec) | |
549 | opts->print_deps = 2; | |
550 | else | |
551 | return; | |
552 | } | |
553 | ||
554 | /* Find the space before the DEPS_TARGET, if there is one. */ | |
555 | s = strchr (spec, ' '); | |
556 | if (s) | |
557 | { | |
558 | opts->deps_target = s + 1; | |
559 | output_file = (char *) xmalloc (s - spec + 1); | |
560 | memcpy (output_file, spec, s - spec); | |
561 | output_file[s - spec] = 0; | |
562 | } | |
563 | else | |
564 | { | |
565 | opts->deps_target = 0; | |
566 | output_file = spec; | |
567 | } | |
568 | ||
569 | opts->deps_file = output_file; | |
570 | opts->print_deps_append = 1; | |
571 | } | |
572 | ||
49e6c08e | 573 | pfile->deps = deps_init (); |
0b22d65c | 574 | |
49e6c08e | 575 | /* Print the expected object file name as the target of this Make-rule. */ |
0b22d65c | 576 | if (opts->deps_target) |
49e6c08e | 577 | deps_add_target (pfile->deps, opts->deps_target); |
0b22d65c | 578 | else if (*opts->in_fname == 0) |
49e6c08e | 579 | deps_add_target (pfile->deps, "-"); |
0b22d65c | 580 | else |
49e6c08e | 581 | deps_calc_target (pfile->deps, opts->in_fname); |
0b22d65c | 582 | |
49e6c08e ZW |
583 | if (opts->in_fname) |
584 | deps_add_dep (pfile->deps, opts->in_fname); | |
0b22d65c ZW |
585 | } |
586 | ||
c45da1ca ZW |
587 | /* And another subroutine. This one sets up the standard include path. */ |
588 | static void | |
589 | initialize_standard_includes (pfile) | |
590 | cpp_reader *pfile; | |
591 | { | |
592 | cpp_options *opts = CPP_OPTIONS (pfile); | |
593 | char *path; | |
455d2586 | 594 | const struct default_include *p; |
c45da1ca ZW |
595 | char *specd_prefix = opts->include_prefix; |
596 | ||
597 | /* Several environment variables may add to the include search path. | |
598 | CPATH specifies an additional list of directories to be searched | |
599 | as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, | |
600 | etc. specify an additional list of directories to be searched as | |
601 | if specified with -isystem, for the language indicated. */ | |
602 | ||
603 | GET_ENV_PATH_LIST (path, "CPATH"); | |
604 | if (path != 0 && *path != 0) | |
605 | path_include (pfile, opts->pending, path, BRACKET); | |
606 | ||
607 | switch ((opts->objc << 1) + opts->cplusplus) | |
608 | { | |
609 | case 0: | |
610 | GET_ENV_PATH_LIST (path, "C_INCLUDE_PATH"); | |
611 | break; | |
612 | case 1: | |
613 | GET_ENV_PATH_LIST (path, "CPLUS_INCLUDE_PATH"); | |
614 | break; | |
615 | case 2: | |
616 | GET_ENV_PATH_LIST (path, "OBJC_INCLUDE_PATH"); | |
617 | break; | |
618 | case 3: | |
619 | GET_ENV_PATH_LIST (path, "OBJCPLUS_INCLUDE_PATH"); | |
620 | break; | |
621 | } | |
622 | if (path != 0 && *path != 0) | |
623 | path_include (pfile, opts->pending, path, SYSTEM); | |
624 | ||
625 | /* Search "translated" versions of GNU directories. | |
626 | These have /usr/local/lib/gcc... replaced by specd_prefix. */ | |
627 | if (specd_prefix != 0) | |
628 | { | |
629 | char *default_prefix = alloca (sizeof GCC_INCLUDE_DIR - 7); | |
630 | /* Remove the `include' from /usr/local/lib/gcc.../include. | |
631 | GCC_INCLUDE_DIR will always end in /include. */ | |
632 | int default_len = sizeof GCC_INCLUDE_DIR - 8; | |
633 | int specd_len = strlen (specd_prefix); | |
634 | ||
635 | memcpy (default_prefix, GCC_INCLUDE_DIR, default_len); | |
636 | default_prefix[default_len] = '\0'; | |
637 | ||
638 | for (p = include_defaults_array; p->fname; p++) | |
639 | { | |
640 | /* Some standard dirs are only for C++. */ | |
641 | if (!p->cplusplus | |
642 | || (opts->cplusplus | |
643 | && !opts->no_standard_cplusplus_includes)) | |
644 | { | |
645 | /* Does this dir start with the prefix? */ | |
646 | if (!strncmp (p->fname, default_prefix, default_len)) | |
647 | { | |
648 | /* Yes; change prefix and add to search list. */ | |
649 | int flen = strlen (p->fname); | |
650 | int this_len = specd_len + flen - default_len; | |
651 | char *str = (char *) xmalloc (this_len + 1); | |
652 | memcpy (str, specd_prefix, specd_len); | |
653 | memcpy (str + specd_len, | |
654 | p->fname + default_len, | |
655 | flen - default_len + 1); | |
656 | ||
657 | append_include_chain (pfile, opts->pending, | |
658 | str, SYSTEM, p->cxx_aware); | |
659 | } | |
660 | } | |
661 | } | |
662 | } | |
663 | ||
664 | /* Search ordinary names for GNU include directories. */ | |
665 | for (p = include_defaults_array; p->fname; p++) | |
666 | { | |
667 | /* Some standard dirs are only for C++. */ | |
668 | if (!p->cplusplus | |
669 | || (opts->cplusplus | |
670 | && !opts->no_standard_cplusplus_includes)) | |
671 | { | |
672 | /* XXX Potential memory leak! */ | |
673 | char *str = xstrdup (update_path (p->fname, p->component)); | |
674 | append_include_chain (pfile, opts->pending, str, SYSTEM, | |
675 | p->cxx_aware); | |
676 | } | |
677 | } | |
678 | } | |
679 | ||
6de1e2a9 ZW |
680 | /* This is called after options have been processed. |
681 | * Check options for consistency, and setup for processing input | |
682 | * from the file named FNAME. (Use standard input if FNAME==NULL.) | |
683 | * Return 1 on success, 0 on failure. | |
684 | */ | |
685 | ||
686 | int | |
687 | cpp_start_read (pfile, fname) | |
688 | cpp_reader *pfile; | |
689 | char *fname; | |
690 | { | |
691 | struct cpp_options *opts = CPP_OPTIONS (pfile); | |
0b22d65c | 692 | struct pending_option *p, *q; |
6de1e2a9 | 693 | |
0b22d65c ZW |
694 | /* -MG doesn't select the form of output and must be specified with one of |
695 | -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't | |
696 | inhibit compilation. */ | |
697 | if (opts->print_deps_missing_files | |
698 | && (opts->print_deps == 0 || !opts->no_output)) | |
699 | { | |
700 | cpp_fatal (pfile, "-MG must be specified with one of -M or -MM"); | |
701 | return 0; | |
702 | } | |
6de1e2a9 | 703 | |
0b22d65c ZW |
704 | /* Chill should not be used with -trigraphs. */ |
705 | if (opts->chill && opts->trigraphs) | |
706 | { | |
707 | cpp_warning (pfile, "-lang-chill and -trigraphs are mutually exclusive"); | |
708 | opts->trigraphs = 0; | |
709 | } | |
710 | ||
711 | /* Set this if it hasn't been set already. */ | |
712 | if (user_label_prefix == NULL) | |
713 | user_label_prefix = USER_LABEL_PREFIX; | |
c45da1ca ZW |
714 | |
715 | /* Don't bother trying to do macro expansion if we've already done | |
716 | preprocessing. */ | |
717 | if (opts->preprocessed) | |
718 | pfile->no_macro_expand++; | |
455d2586 ZW |
719 | |
720 | /* Set up the IStable. This doesn't do anything if we were compiled | |
721 | with a compiler that supports C99 designated initializers. */ | |
a9ae4483 | 722 | init_IStable (); |
6de1e2a9 | 723 | |
c45da1ca ZW |
724 | /* Set up the include search path now. */ |
725 | if (! opts->no_standard_includes) | |
726 | initialize_standard_includes (pfile); | |
727 | ||
b0699dad | 728 | _cpp_merge_include_chains (opts); |
c45da1ca ZW |
729 | |
730 | /* With -v, print the list of dirs to search. */ | |
731 | if (opts->verbose) | |
732 | { | |
733 | struct file_name_list *l; | |
734 | fprintf (stderr, _("#include \"...\" search starts here:\n")); | |
735 | for (l = opts->quote_include; l; l = l->next) | |
736 | { | |
737 | if (l == opts->bracket_include) | |
738 | fprintf (stderr, _("#include <...> search starts here:\n")); | |
739 | fprintf (stderr, " %s\n", l->name); | |
740 | } | |
741 | fprintf (stderr, _("End of search list.\n")); | |
742 | } | |
743 | ||
744 | initialize_dependency_output (pfile); | |
745 | ||
746 | /* Open the main input file. This must be done before -D processing | |
747 | so we have a buffer to stand on. */ | |
6de1e2a9 ZW |
748 | if (opts->in_fname == NULL || *opts->in_fname == 0) |
749 | { | |
750 | opts->in_fname = fname; | |
751 | if (opts->in_fname == NULL) | |
752 | opts->in_fname = ""; | |
753 | } | |
6de1e2a9 | 754 | |
c45da1ca ZW |
755 | if (!cpp_read_file (pfile, fname)) |
756 | return 0; | |
757 | ||
758 | /* -D and friends may produce output, which should be identified | |
759 | as line 0. */ | |
760 | ||
761 | CPP_BUFFER (pfile)->lineno = 0; | |
762 | ||
763 | /* Install __LINE__, etc. */ | |
6de1e2a9 ZW |
764 | initialize_builtins (pfile); |
765 | ||
6de1e2a9 | 766 | /* Do -U's, -D's and -A's in the order they were seen. */ |
0b22d65c ZW |
767 | p = opts->pending->define_head; |
768 | while (p) | |
6de1e2a9 | 769 | { |
0b22d65c ZW |
770 | if (p->undef) |
771 | cpp_undef (pfile, p->arg); | |
772 | else | |
773 | cpp_define (pfile, p->arg); | |
6de1e2a9 | 774 | |
0b22d65c ZW |
775 | q = p->next; |
776 | free (p); | |
777 | p = q; | |
6de1e2a9 | 778 | } |
6de1e2a9 | 779 | |
0b22d65c ZW |
780 | p = opts->pending->assert_head; |
781 | while (p) | |
6de1e2a9 | 782 | { |
0b22d65c ZW |
783 | if (p->undef) |
784 | cpp_unassert (pfile, p->arg); | |
785 | else | |
786 | cpp_assert (pfile, p->arg); | |
6de1e2a9 | 787 | |
0b22d65c ZW |
788 | q = p->next; |
789 | free (p); | |
790 | p = q; | |
791 | } | |
792 | ||
793 | opts->done_initializing = 1; | |
c45da1ca | 794 | CPP_BUFFER (pfile)->lineno = 1; |
6de1e2a9 | 795 | |
3773a46b JM |
796 | if (opts->preprocessed) |
797 | /* If we've already processed this code, we want to trust the #line | |
798 | directives in the input. But we still need to update our line | |
799 | counter accordingly. */ | |
800 | pfile->lineno = CPP_BUFFER (pfile)->lineno; | |
801 | else | |
802 | output_line_command (pfile, same_file); | |
6de1e2a9 ZW |
803 | pfile->only_seen_white = 2; |
804 | ||
805 | /* The -imacros files can be scanned now, but the -include files | |
806 | have to be pushed onto the include stack and processed later, | |
0b22d65c | 807 | in the main loop calling cpp_get_token. */ |
6de1e2a9 | 808 | |
6de1e2a9 | 809 | opts->no_output++; |
0b22d65c ZW |
810 | p = opts->pending->imacros_head; |
811 | while (p) | |
6de1e2a9 | 812 | { |
c45da1ca ZW |
813 | if (cpp_read_file (pfile, p->arg)) |
814 | cpp_scan_buffer (pfile); | |
0b22d65c ZW |
815 | |
816 | q = p->next; | |
817 | free (p); | |
818 | p = q; | |
6de1e2a9 ZW |
819 | } |
820 | opts->no_output--; | |
0b22d65c ZW |
821 | |
822 | p = opts->pending->include_head; | |
823 | while (p) | |
6de1e2a9 | 824 | { |
c45da1ca ZW |
825 | if (cpp_read_file (pfile, p->arg)) |
826 | output_line_command (pfile, enter_file); | |
827 | ||
0b22d65c ZW |
828 | q = p->next; |
829 | free (p); | |
830 | p = q; | |
6de1e2a9 | 831 | } |
6de1e2a9 | 832 | |
0b22d65c | 833 | free (opts->pending); |
6de1e2a9 ZW |
834 | opts->pending = NULL; |
835 | ||
836 | return 1; | |
837 | } | |
838 | ||
839 | /* This is called at the end of preprocessing. It pops the | |
840 | last buffer and writes dependency output. It should also | |
841 | clear macro definitions, such that you could call cpp_start_read | |
842 | with a new filename to restart processing. */ | |
843 | void | |
844 | cpp_finish (pfile) | |
845 | cpp_reader *pfile; | |
846 | { | |
847 | struct cpp_options *opts = CPP_OPTIONS (pfile); | |
848 | ||
849 | if (CPP_PREV_BUFFER (CPP_BUFFER (pfile)) != CPP_NULL_BUFFER (pfile)) | |
c1212d2f | 850 | cpp_ice (pfile, "buffers still stacked in cpp_finish"); |
6de1e2a9 | 851 | cpp_pop_buffer (pfile); |
c1212d2f | 852 | |
49e6c08e ZW |
853 | /* Don't write the deps file if preprocessing has failed. */ |
854 | if (opts->print_deps && pfile->errors == 0) | |
6de1e2a9 ZW |
855 | { |
856 | /* Stream on which to print the dependency information. */ | |
c1212d2f | 857 | FILE *deps_stream = 0; |
6de1e2a9 | 858 | |
49e6c08e ZW |
859 | const char *deps_mode = opts->print_deps_append ? "a" : "w"; |
860 | if (opts->deps_file == 0) | |
861 | deps_stream = stdout; | |
862 | else if ((deps_stream = fopen (opts->deps_file, deps_mode)) == 0) | |
863 | cpp_notice_from_errno (pfile, opts->deps_file); | |
c1212d2f | 864 | |
49e6c08e ZW |
865 | if (deps_stream) |
866 | { | |
867 | deps_write (pfile->deps, deps_stream, 72); | |
868 | if (opts->deps_file) | |
6de1e2a9 | 869 | { |
49e6c08e ZW |
870 | if (ferror (deps_stream) || fclose (deps_stream) != 0) |
871 | cpp_fatal (pfile, "I/O error on output"); | |
6de1e2a9 ZW |
872 | } |
873 | } | |
874 | } | |
3caee4a8 ZW |
875 | |
876 | if (opts->dump_macros == dump_only) | |
877 | { | |
878 | int i; | |
879 | HASHNODE *h; | |
3caee4a8 ZW |
880 | for (i = HASHSIZE; --i >= 0;) |
881 | { | |
882 | for (h = pfile->hashtab[i]; h; h = h->next) | |
883 | if (h->type == T_MACRO) | |
884 | { | |
b0699dad ZW |
885 | _cpp_dump_definition (pfile, h->name, h->length, |
886 | h->value.defn); | |
3caee4a8 ZW |
887 | CPP_PUTC (pfile, '\n'); |
888 | } | |
889 | } | |
890 | } | |
6de1e2a9 ZW |
891 | } |
892 | ||
223dca6a RH |
893 | static void |
894 | new_pending_define (opts, text) | |
895 | struct cpp_options *opts; | |
896 | const char *text; | |
897 | { | |
898 | struct pending_option *o = (struct pending_option *) | |
899 | xmalloc (sizeof (struct pending_option)); | |
900 | ||
c8d8ed65 | 901 | o->arg = (char *) text; |
223dca6a RH |
902 | o->next = NULL; |
903 | o->undef = 0; | |
904 | APPEND (opts->pending, define, o); | |
905 | } | |
906 | ||
e23c0ba3 ZW |
907 | enum opt_code |
908 | { | |
909 | OPT_stdin_stdout = 0, OPT_dollar, OPT_plus, | |
910 | OPT__help, OPT__version, | |
911 | OPT_A, OPT_C, OPT_D, OPT_H, OPT_I, OPT_M, | |
912 | OPT_MD, OPT_MG, OPT_MM, OPT_MMD, | |
913 | OPT_P, OPT_U, OPT_W, | |
914 | OPT_d, | |
915 | OPT_fleading_underscore, OPT_fno_leading_underscore, | |
916 | OPT_fpreprocessed, OPT_fno_preprocessed, | |
917 | OPT_g, OPT_h, | |
918 | OPT_idirafter, OPT_imacros, OPT_include, | |
919 | OPT_iprefix, OPT_isystem, OPT_iwithprefix, OPT_iwithprefixbefore, | |
920 | OPT_lang_asm, OPT_lang_c, OPT_lang_cplusplus, OPT_lang_c89, | |
921 | OPT_lang_chill, OPT_lang_fortran, OPT_lang_objc, OPT_lang_objcplusplus, | |
922 | OPT_nostdinc, OPT_nostdincplusplus, | |
923 | OPT_o, | |
924 | OPT_pedantic, OPT_pedantic_errors, OPT_remap, | |
925 | OPT_std_c89, OPT_std_c99, OPT_std_c9x, OPT_std_gnu89, OPT_std_gnu99, | |
926 | OPT_std_gnu9x, OPT_std_iso9899_1990, OPT_std_iso9899_199409, | |
927 | OPT_std_iso9899_1999, OPT_std_iso9899_199x, | |
928 | OPT_traditional, OPT_trigraphs, | |
929 | OPT_v, OPT_w, | |
930 | N_OPTS | |
931 | }; | |
932 | ||
933 | struct cl_option | |
934 | { | |
935 | const char *opt_text; | |
936 | const char *msg; | |
937 | size_t opt_len; | |
938 | enum opt_code opt_code; | |
939 | }; | |
940 | ||
941 | static const char no_arg[] = N_("Argument missing after `%s' option"); | |
942 | static const char no_ass[] = N_("Assertion missing after `%s' option"); | |
943 | static const char no_dir[] = N_("Directory name missing after `%s' option"); | |
944 | static const char no_fil[] = N_("File name missing after `%s' option"); | |
945 | static const char no_mac[] = N_("Macro name missing after `%s' option"); | |
946 | static const char no_pth[] = N_("Path name missing after `%s' option"); | |
947 | ||
948 | /* This list must be ASCII sorted. Make enum order above match this. */ | |
949 | #define DEF_OPT(text, msg, code) {text, msg, sizeof(text) - 1, code} | |
950 | ||
951 | #ifdef HOST_EBCDIC | |
952 | static struct cl_option cl_options[] = | |
953 | #else | |
954 | static const struct cl_option cl_options[] = | |
955 | #endif | |
956 | { | |
957 | DEF_OPT("", 0, OPT_stdin_stdout), | |
958 | DEF_OPT("$", 0, OPT_dollar), | |
959 | DEF_OPT("+", 0, OPT_plus), | |
960 | DEF_OPT("-help", 0, OPT__help), | |
961 | DEF_OPT("-version", 0, OPT__version), | |
962 | DEF_OPT("A", no_ass, OPT_A), | |
963 | DEF_OPT("C", 0, OPT_C), | |
964 | DEF_OPT("D", no_mac, OPT_D), | |
965 | DEF_OPT("H", 0, OPT_H), | |
966 | DEF_OPT("I", no_dir, OPT_I), | |
967 | DEF_OPT("M", 0, OPT_M), | |
968 | DEF_OPT("MD", no_fil, OPT_MD), | |
969 | DEF_OPT("MG", 0, OPT_MG), | |
970 | DEF_OPT("MM", 0, OPT_MM), | |
971 | DEF_OPT("MMD", no_fil, OPT_MMD), | |
972 | DEF_OPT("P", 0, OPT_P), | |
973 | DEF_OPT("U", no_mac, OPT_U), | |
974 | /* NB: Immed arg only, and not reqd */ | |
975 | DEF_OPT("W", no_arg, OPT_W), | |
976 | DEF_OPT("d", no_arg, OPT_d), | |
977 | DEF_OPT("fleading-underscore", 0, OPT_fleading_underscore), | |
978 | DEF_OPT("fno-leading-underscore", 0, OPT_fno_leading_underscore), | |
979 | DEF_OPT("fpreprocessed", 0, OPT_fpreprocessed), | |
980 | DEF_OPT("fno-preprocessed", 0, OPT_fno_preprocessed), | |
981 | /* NB: Immed arg only, and not reqd */ | |
982 | DEF_OPT("g", no_arg, OPT_g), | |
983 | DEF_OPT("h", 0, OPT_h), | |
984 | DEF_OPT("idirafter", no_dir, OPT_idirafter), | |
985 | DEF_OPT("imacros", no_fil, OPT_imacros), | |
986 | DEF_OPT("include", no_fil, OPT_include), | |
987 | DEF_OPT("iprefix", no_pth, OPT_iprefix), | |
988 | DEF_OPT("isystem", no_dir, OPT_isystem), | |
989 | DEF_OPT("iwithprefix", no_dir, OPT_iwithprefix), | |
990 | DEF_OPT("iwithprefixbefore", no_dir, OPT_iwithprefixbefore), | |
991 | DEF_OPT("lang-asm", 0, OPT_lang_asm), | |
992 | DEF_OPT("lang-c", 0, OPT_lang_c), | |
993 | DEF_OPT("lang-c++", 0, OPT_lang_cplusplus), | |
994 | DEF_OPT("lang-c89", 0, OPT_lang_c89), | |
995 | DEF_OPT("lang-chill", 0, OPT_lang_chill), | |
996 | DEF_OPT("lang-fortran", 0, OPT_lang_fortran), | |
997 | DEF_OPT("lang-objc", 0, OPT_lang_objc), | |
998 | DEF_OPT("lang-objc++", 0, OPT_lang_objcplusplus), | |
999 | DEF_OPT("nostdinc", 0, OPT_nostdinc), | |
1000 | DEF_OPT("nostdinc++", 0, OPT_nostdincplusplus), | |
1001 | DEF_OPT("o", no_fil, OPT_o), | |
1002 | DEF_OPT("pedantic", 0, OPT_pedantic), | |
1003 | DEF_OPT("pedantic-errors", 0, OPT_pedantic_errors), | |
1004 | DEF_OPT("remap", 0, OPT_remap), | |
1005 | DEF_OPT("std=c89", 0, OPT_std_c89), | |
1006 | DEF_OPT("std=c99", 0, OPT_std_c99), | |
1007 | DEF_OPT("std=c9x", 0, OPT_std_c9x), | |
1008 | DEF_OPT("std=gnu89", 0, OPT_std_gnu89), | |
1009 | DEF_OPT("std=gnu99", 0, OPT_std_gnu99), | |
1010 | DEF_OPT("std=gnu9x", 0, OPT_std_gnu9x), | |
1011 | DEF_OPT("std=iso9899:1990", 0, OPT_std_iso9899_1990), | |
1012 | DEF_OPT("std=iso9899:199409", 0, OPT_std_iso9899_199409), | |
1013 | DEF_OPT("std=iso9899:1999", 0, OPT_std_iso9899_1999), | |
1014 | DEF_OPT("std=iso9899:199x", 0, OPT_std_iso9899_199x), | |
1015 | DEF_OPT("traditional", 0, OPT_traditional), | |
1016 | DEF_OPT("trigraphs", 0, OPT_trigraphs), | |
1017 | DEF_OPT("v", 0, OPT_v), | |
1018 | DEF_OPT("w", 0, OPT_w) | |
1019 | }; | |
1020 | #undef DEF_OPT | |
1021 | ||
1022 | /* Perform a binary search to find which, if any, option the given | |
1023 | command-line matches. Returns its index in the option array, | |
1024 | negative on failure. Complications arise since some options can be | |
1025 | suffixed with an argument, and multiple complete matches can occur, | |
1026 | e.g. -iwithprefix and -iwithprefixbefore. Moreover, we want to | |
1027 | accept options beginning with -g and -W that we do not recognise, | |
1028 | but not to swallow any subsequent command line argument; these are | |
1029 | handled as special cases in cpp_handle_option */ | |
1030 | static int | |
1031 | parse_option (input) | |
1032 | const char *input; | |
1033 | { | |
1034 | unsigned int md, mn, mx; | |
1035 | size_t opt_len; | |
1036 | int comp; | |
1037 | ||
1038 | mn = 0; | |
1039 | mx = N_OPTS; | |
1040 | ||
1041 | while (mx > mn) | |
1042 | { | |
1043 | md = (mn + mx) / 2; | |
1044 | ||
1045 | opt_len = cl_options[md].opt_len; | |
1046 | comp = strncmp (input, cl_options[md].opt_text, opt_len); | |
1047 | ||
1048 | if (comp > 0) | |
1049 | mn = md + 1; | |
1050 | else if (comp < 0) | |
1051 | mx = md; | |
1052 | else | |
1053 | { | |
1054 | if (input[opt_len] == '\0') | |
1055 | return md; | |
1056 | /* We were passed more text. If the option takes an argument, | |
1057 | we may match a later option or we may have been passed the | |
1058 | argument. The longest possible option match succeeds. | |
1059 | If the option takes no arguments we have not matched and | |
1060 | continue the search (e.g. input="stdc++" match was "stdc") */ | |
1061 | mn = md + 1; | |
1062 | if (cl_options[md].msg) | |
1063 | { | |
1064 | /* Scan forwards. If we get an exact match, return it. | |
1065 | Otherwise, return the longest option-accepting match. | |
1066 | This loops no more than twice with current options */ | |
1067 | mx = md; | |
1068 | for (; mn < N_OPTS; mn++) | |
1069 | { | |
1070 | opt_len = cl_options[mn].opt_len; | |
1071 | if (strncmp (input, cl_options[mn].opt_text, opt_len)) | |
1072 | break; | |
1073 | if (input[opt_len] == '\0') | |
1074 | return mn; | |
1075 | if (cl_options[mn].msg) | |
1076 | mx = mn; | |
1077 | } | |
1078 | return mx; | |
1079 | } | |
1080 | } | |
1081 | } | |
1082 | ||
1083 | return -1; | |
1084 | } | |
1085 | ||
6de1e2a9 ZW |
1086 | /* Handle one command-line option in (argc, argv). |
1087 | Can be called multiple times, to handle multiple sets of options. | |
1088 | Returns number of strings consumed. */ | |
c8d8ed65 | 1089 | |
b0699dad ZW |
1090 | static int |
1091 | handle_option (pfile, argc, argv) | |
6de1e2a9 ZW |
1092 | cpp_reader *pfile; |
1093 | int argc; | |
1094 | char **argv; | |
1095 | { | |
1096 | struct cpp_options *opts = CPP_OPTIONS (pfile); | |
1097 | int i = 0; | |
1098 | ||
0b22d65c ZW |
1099 | if (argv[i][0] != '-') |
1100 | { | |
1101 | if (opts->out_fname != NULL) | |
6de1e2a9 | 1102 | { |
0b22d65c ZW |
1103 | print_help (); |
1104 | cpp_fatal (pfile, "Too many arguments"); | |
6de1e2a9 | 1105 | } |
0b22d65c ZW |
1106 | else if (opts->in_fname != NULL) |
1107 | opts->out_fname = argv[i]; | |
1108 | else | |
1109 | opts->in_fname = argv[i]; | |
1110 | } | |
1111 | else | |
e23c0ba3 ZW |
1112 | { |
1113 | enum opt_code opt_code; | |
1114 | int opt_index; | |
1115 | char *arg = 0; | |
1116 | ||
1117 | /* Skip over '-' */ | |
1118 | opt_index = parse_option (&argv[i][1]); | |
1119 | if (opt_index < 0) | |
1120 | return i; | |
1121 | ||
1122 | opt_code = cl_options[opt_index].opt_code; | |
1123 | if (cl_options[opt_index].msg) | |
1124 | { | |
1125 | arg = &argv[i][cl_options[opt_index].opt_len + 1]; | |
1126 | ||
1127 | /* Yuk. Special case for -g and -W as they must not swallow | |
1128 | up any following argument. If this becomes common, add | |
1129 | another field to the cl_options table */ | |
1130 | if (arg[0] == '\0' && !(opt_code == OPT_g || opt_code == OPT_W)) | |
1131 | { | |
1132 | arg = argv[++i]; | |
1133 | if (!arg) | |
1134 | { | |
1135 | cpp_fatal (pfile, _(cl_options[opt_index].msg), argv[i - 1]); | |
1136 | return argc; | |
1137 | } | |
1138 | } | |
1139 | } | |
1140 | ||
1141 | switch (opt_code) | |
1142 | { | |
1143 | case N_OPTS: /* shut GCC up */ | |
1144 | break; | |
1145 | case OPT_fleading_underscore: | |
0b22d65c | 1146 | user_label_prefix = "_"; |
e23c0ba3 ZW |
1147 | break; |
1148 | case OPT_fno_leading_underscore: | |
0b22d65c | 1149 | user_label_prefix = ""; |
e23c0ba3 ZW |
1150 | break; |
1151 | case OPT_fpreprocessed: | |
3773a46b | 1152 | opts->preprocessed = 1; |
e23c0ba3 ZW |
1153 | break; |
1154 | case OPT_fno_preprocessed: | |
3773a46b | 1155 | opts->preprocessed = 0; |
e23c0ba3 ZW |
1156 | break; |
1157 | case OPT_w: | |
1158 | opts->inhibit_warnings = 1; | |
1159 | break; | |
1160 | case OPT_g: /* Silently ignore anything but -g3 */ | |
1161 | if (!strcmp(&argv[i][2], "3")) | |
1162 | opts->debug_output = 1; | |
1163 | break; | |
1164 | case OPT_h: | |
1165 | case OPT__help: | |
1166 | print_help (); | |
1167 | exit (0); /* XXX */ | |
1168 | break; | |
1169 | case OPT__version: | |
1170 | fprintf (stderr, _("GNU CPP version %s (cpplib)\n"), version_string); | |
1171 | exit (0); /* XXX */ | |
1172 | break; | |
1173 | case OPT_C: | |
1174 | opts->discard_comments = 0; | |
1175 | break; | |
1176 | case OPT_P: | |
1177 | opts->no_line_commands = 1; | |
1178 | break; | |
1179 | case OPT_dollar: /* Don't include $ in identifiers. */ | |
1180 | opts->dollars_in_ident = 0; | |
1181 | break; | |
1182 | case OPT_H: | |
1183 | opts->print_include_names = 1; | |
1184 | break; | |
1185 | case OPT_D: | |
1186 | new_pending_define (opts, arg); | |
1187 | break; | |
1188 | case OPT_pedantic_errors: | |
1189 | opts->pedantic_errors = 1; | |
1190 | /* fall through */ | |
1191 | case OPT_pedantic: | |
1192 | opts->pedantic = 1; | |
1193 | break; | |
1194 | case OPT_traditional: | |
1195 | opts->traditional = 1; | |
1196 | opts->cplusplus_comments = 0; | |
1197 | opts->trigraphs = 0; | |
0b22d65c | 1198 | opts->warn_trigraphs = 0; |
e23c0ba3 ZW |
1199 | break; |
1200 | case OPT_trigraphs: | |
1201 | opts->trigraphs = 1; | |
1202 | break; | |
1203 | case OPT_plus: | |
1204 | opts->cplusplus = 1; | |
1205 | opts->cplusplus_comments = 1; | |
1206 | break; | |
1207 | case OPT_remap: | |
1208 | opts->remap = 1; | |
1209 | break; | |
1210 | case OPT_iprefix: | |
1211 | opts->include_prefix = arg; | |
1212 | opts->include_prefix_len = strlen (arg); | |
1213 | break; | |
1214 | case OPT_lang_c: | |
1215 | opts->cplusplus = 0, opts->cplusplus_comments = 1; | |
1216 | opts->c89 = 0, opts->c99 = 1, opts->objc = 0; | |
1217 | break; | |
1218 | case OPT_lang_c89: | |
1219 | opts->cplusplus = 0, opts->cplusplus_comments = 0; | |
1220 | opts->c89 = 1, opts->c99 = 0, opts->objc = 0; | |
1221 | opts->trigraphs = 1; | |
1222 | new_pending_define (opts, "__STRICT_ANSI__"); | |
1223 | break; | |
1224 | case OPT_lang_cplusplus: | |
1225 | opts->cplusplus = 1, opts->cplusplus_comments = 1; | |
1226 | opts->c89 = 0, opts->c99 = 0, opts->objc = 0; | |
1227 | break; | |
1228 | case OPT_lang_objc: | |
1229 | case OPT_lang_objcplusplus: | |
1230 | opts->cplusplus = opt_code == OPT_lang_objcplusplus; | |
1231 | opts->cplusplus_comments = 1; | |
1232 | opts->c89 = 0, opts->c99 = 0, opts->objc = 1; | |
1233 | break; | |
1234 | case OPT_lang_asm: | |
1235 | opts->lang_asm = 1; | |
1236 | break; | |
1237 | case OPT_lang_fortran: | |
1238 | opts->lang_fortran = 1, opts->cplusplus_comments = 0; | |
1239 | break; | |
1240 | case OPT_lang_chill: | |
1241 | opts->objc = 0, opts->cplusplus = 0; | |
1242 | opts->chill = 1, opts->traditional = 1; | |
1243 | break; | |
1244 | case OPT_nostdinc: | |
1245 | /* -nostdinc causes no default include directories. | |
1246 | You must specify all include-file directories with -I. */ | |
1247 | opts->no_standard_includes = 1; | |
1248 | break; | |
1249 | case OPT_nostdincplusplus: | |
1250 | /* -nostdinc++ causes no default C++-specific include directories. */ | |
1251 | opts->no_standard_cplusplus_includes = 1; | |
1252 | break; | |
1253 | case OPT_std_gnu89: | |
1254 | opts->cplusplus = 0, opts->cplusplus_comments = 1; | |
1255 | opts->c89 = 1, opts->c99 = 0, opts->objc = 0; | |
1256 | break; | |
1257 | case OPT_std_gnu9x: | |
1258 | case OPT_std_gnu99: | |
1259 | opts->cplusplus = 0, opts->cplusplus_comments = 1; | |
1260 | opts->c89 = 0, opts->c99 = 1, opts->objc = 0; | |
1261 | new_pending_define (opts, "__STDC_VERSION__=199901L"); | |
1262 | break; | |
1263 | case OPT_std_iso9899_199409: | |
1264 | new_pending_define (opts, "__STDC_VERSION__=199409L"); | |
1265 | /* Fall through */ | |
1266 | case OPT_std_iso9899_1990: | |
1267 | case OPT_std_c89: | |
1268 | opts->cplusplus = 0, opts->cplusplus_comments = 0; | |
1269 | opts->c89 = 1, opts->c99 = 0, opts->objc = 0; | |
1270 | opts->trigraphs = 1; | |
1271 | new_pending_define (opts, "__STRICT_ANSI__"); | |
1272 | break; | |
1273 | case OPT_std_iso9899_199x: | |
1274 | case OPT_std_iso9899_1999: | |
1275 | case OPT_std_c9x: | |
1276 | case OPT_std_c99: | |
1277 | opts->cplusplus = 0, opts->cplusplus_comments = 1; | |
1278 | opts->c89 = 0, opts->c99 = 1, opts->objc = 0; | |
1279 | opts->trigraphs = 1; | |
1280 | new_pending_define (opts, "__STRICT_ANSI__"); | |
1281 | new_pending_define (opts, "__STDC_VERSION__=199901L"); | |
1282 | break; | |
1283 | case OPT_o: | |
1284 | if (opts->out_fname != NULL) | |
0b22d65c | 1285 | { |
e23c0ba3 ZW |
1286 | cpp_fatal (pfile, "Output filename specified twice"); |
1287 | return argc; | |
1288 | } | |
1289 | opts->out_fname = arg; | |
1290 | if (!strcmp (opts->out_fname, "-")) | |
1291 | opts->out_fname = ""; | |
1292 | break; | |
1293 | case OPT_v: | |
1294 | fprintf (stderr, _("GNU CPP version %s (cpplib)\n"), version_string); | |
1295 | #ifdef TARGET_VERSION | |
1296 | TARGET_VERSION; | |
1297 | #endif | |
1298 | fputc ('\n', stderr); | |
1299 | opts->verbose = 1; | |
1300 | break; | |
1301 | case OPT_stdin_stdout: | |
1302 | /* JF handle '-' as file name meaning stdin or stdout */ | |
1303 | if (opts->in_fname == NULL) | |
1304 | opts->in_fname = ""; | |
1305 | else if (opts->out_fname == NULL) | |
1306 | opts->out_fname = ""; | |
1307 | break; | |
1308 | case OPT_d: | |
1309 | /* Args to -d specify what parts of macros to dump. | |
1310 | Silently ignore unrecognised options; they may | |
1311 | be aimed at the compiler proper. */ | |
1312 | { | |
1313 | char c; | |
1314 | ||
1315 | while ((c = *arg++) != '\0') | |
1316 | switch (c) | |
1317 | { | |
1318 | case 'M': | |
0b22d65c ZW |
1319 | opts->dump_macros = dump_only; |
1320 | opts->no_output = 1; | |
1321 | break; | |
1322 | case 'N': | |
1323 | opts->dump_macros = dump_names; | |
1324 | break; | |
1325 | case 'D': | |
1326 | opts->dump_macros = dump_definitions; | |
1327 | break; | |
1328 | case 'I': | |
1329 | opts->dump_includes = 1; | |
1330 | break; | |
1331 | } | |
e23c0ba3 ZW |
1332 | } |
1333 | break; | |
1334 | /* The style of the choices here is a bit mixed. | |
1335 | The chosen scheme is a hybrid of keeping all options in one string | |
1336 | and specifying each option in a separate argument: | |
1337 | -M|-MM|-MD file|-MMD file [-MG]. An alternative is: | |
1338 | -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely: | |
1339 | -M[M][G][D file]. This is awkward to handle in specs, and is not | |
1340 | as extensible. */ | |
1341 | /* ??? -MG must be specified in addition to one of -M or -MM. | |
1342 | This can be relaxed in the future without breaking anything. | |
1343 | The converse isn't true. */ | |
1344 | ||
1345 | /* -MG isn't valid with -MD or -MMD. This is checked for later. */ | |
1346 | case OPT_MG: | |
1347 | opts->print_deps_missing_files = 1; | |
1348 | break; | |
1349 | case OPT_M: | |
1350 | case OPT_MD: | |
1351 | case OPT_MM: | |
1352 | case OPT_MMD: | |
1353 | if (opt_code == OPT_M || opt_code == OPT_MD) | |
1354 | opts->print_deps = 2; | |
1355 | else | |
1356 | opts->print_deps = 1; | |
1357 | ||
1358 | /* For -MD and -MMD options, write deps on file named by next arg */ | |
1359 | /* For -M and -MM, write deps on standard output | |
1360 | and suppress the usual output. */ | |
1361 | if (opt_code == OPT_MD || opt_code == OPT_MMD) | |
1362 | opts->deps_file = arg; | |
1363 | else | |
1364 | opts->no_output = 1; | |
1365 | break; | |
1366 | case OPT_A: | |
1367 | if (strcmp (arg, "-")) | |
1368 | { | |
1369 | struct pending_option *o = (struct pending_option *) | |
1370 | xmalloc (sizeof (struct pending_option)); | |
1371 | ||
1372 | o->arg = arg; | |
1373 | o->next = NULL; | |
1374 | o->undef = 0; | |
1375 | APPEND (opts->pending, assert, o); | |
0b22d65c ZW |
1376 | } |
1377 | else | |
1378 | { | |
1379 | /* -A- eliminates all predefined macros and assertions. | |
1380 | Let's include also any that were specified earlier | |
1381 | on the command line. That way we can get rid of any | |
1382 | that were passed automatically in from GCC. */ | |
1383 | struct pending_option *o1, *o2; | |
1384 | ||
1385 | o1 = opts->pending->define_head; | |
1386 | while (o1) | |
1387 | { | |
1388 | o2 = o1->next; | |
1389 | free (o1); | |
1390 | o1 = o2; | |
1391 | } | |
1392 | o1 = opts->pending->assert_head; | |
1393 | while (o1) | |
6de1e2a9 | 1394 | { |
0b22d65c ZW |
1395 | o2 = o1->next; |
1396 | free (o1); | |
1397 | o1 = o2; | |
6de1e2a9 | 1398 | } |
0b22d65c ZW |
1399 | opts->pending->assert_head = NULL; |
1400 | opts->pending->assert_tail = NULL; | |
1401 | opts->pending->define_head = NULL; | |
1402 | opts->pending->define_tail = NULL; | |
6de1e2a9 | 1403 | } |
e23c0ba3 ZW |
1404 | break; |
1405 | case OPT_U: | |
1406 | { | |
1407 | struct pending_option *o = (struct pending_option *) | |
1408 | xmalloc (sizeof (struct pending_option)); | |
1409 | ||
1410 | o->arg = arg; | |
1411 | o->next = NULL; | |
1412 | o->undef = 1; | |
1413 | APPEND (opts->pending, define, o); | |
1414 | } | |
1415 | break; | |
1416 | case OPT_I: /* Add directory to path for includes. */ | |
1417 | if (!strcmp (arg, "-")) | |
1418 | { | |
1419 | /* -I- means: | |
1420 | Use the preceding -I directories for #include "..." | |
1421 | but not #include <...>. | |
1422 | Don't search the directory of the present file | |
1423 | for #include "...". (Note that -I. -I- is not the same as | |
1424 | the default setup; -I. uses the compiler's working dir.) */ | |
1425 | if (! opts->ignore_srcdir) | |
1426 | { | |
1427 | opts->ignore_srcdir = 1; | |
1428 | opts->pending->quote_head = opts->pending->brack_head; | |
1429 | opts->pending->quote_tail = opts->pending->brack_tail; | |
1430 | opts->pending->brack_head = 0; | |
1431 | opts->pending->brack_tail = 0; | |
1432 | } | |
1433 | else | |
1434 | { | |
1435 | cpp_fatal (pfile, "-I- specified twice"); | |
1436 | return argc; | |
1437 | } | |
1438 | } | |
1439 | else | |
1440 | append_include_chain (pfile, opts->pending, | |
1441 | xstrdup (arg), BRACKET, 0); | |
1442 | break; | |
1443 | case OPT_isystem: | |
1444 | /* Add directory to beginning of system include path, as a system | |
1445 | include directory. */ | |
1446 | append_include_chain (pfile, opts->pending, | |
1447 | xstrdup (arg), SYSTEM, 0); | |
1448 | break; | |
1449 | case OPT_include: | |
1450 | { | |
1451 | struct pending_option *o = (struct pending_option *) | |
1452 | xmalloc (sizeof (struct pending_option)); | |
1453 | o->arg = arg; | |
1454 | ||
1455 | /* This list has to be built in reverse order so that | |
1456 | when cpp_start_read pushes all the -include files onto | |
1457 | the buffer stack, they will be scanned in forward order. */ | |
1458 | o->next = opts->pending->include_head; | |
1459 | opts->pending->include_head = o; | |
1460 | } | |
1461 | break; | |
1462 | case OPT_imacros: | |
1463 | { | |
1464 | struct pending_option *o = (struct pending_option *) | |
1465 | xmalloc (sizeof (struct pending_option)); | |
1466 | o->arg = arg; | |
1467 | o->next = NULL; | |
1468 | ||
1469 | APPEND (opts->pending, imacros, o); | |
1470 | } | |
1471 | break; | |
1472 | case OPT_iwithprefix: | |
1473 | /* Add directory to end of path for includes, | |
1474 | with the default prefix at the front of its name. */ | |
1475 | /* fall through */ | |
1476 | case OPT_iwithprefixbefore: | |
1477 | /* Add directory to main path for includes, | |
1478 | with the default prefix at the front of its name. */ | |
1479 | { | |
1480 | char *fname; | |
1481 | int len; | |
1482 | ||
1483 | len = strlen (arg); | |
1484 | ||
1485 | if (opts->include_prefix != 0) | |
1486 | { | |
1487 | fname = xmalloc (opts->include_prefix_len + len + 1); | |
1488 | memcpy (fname, opts->include_prefix, opts->include_prefix_len); | |
1489 | memcpy (fname + opts->include_prefix_len, arg, len + 1); | |
1490 | } | |
1491 | else | |
1492 | { | |
1493 | fname = xmalloc (sizeof GCC_INCLUDE_DIR - 8 + len); | |
1494 | memcpy (fname, GCC_INCLUDE_DIR, sizeof GCC_INCLUDE_DIR - 9); | |
1495 | memcpy (fname + sizeof GCC_INCLUDE_DIR - 9, arg, len + 1); | |
1496 | } | |
1497 | ||
1498 | append_include_chain (pfile, opts->pending, fname, | |
1499 | opt_code == OPT_iwithprefix ? SYSTEM: BRACKET, 0); | |
1500 | } | |
1501 | break; | |
1502 | case OPT_idirafter: | |
1503 | /* Add directory to end of path for includes. */ | |
1504 | append_include_chain (pfile, opts->pending, | |
1505 | xstrdup (arg), AFTER, 0); | |
1506 | break; | |
1507 | case OPT_W: | |
1508 | /* Silently ignore unrecognised options */ | |
1509 | if (!strcmp (argv[i], "-Wall")) | |
0b22d65c | 1510 | { |
e23c0ba3 ZW |
1511 | opts->warn_trigraphs = 1; |
1512 | opts->warn_comments = 1; | |
0b22d65c | 1513 | } |
e23c0ba3 ZW |
1514 | else if (!strcmp (argv[i], "-Wtraditional")) |
1515 | opts->warn_stringify = 1; | |
1516 | else if (!strcmp (argv[i], "-Wtrigraphs")) | |
1517 | opts->warn_trigraphs = 1; | |
1518 | else if (!strcmp (argv[i], "-Wcomment")) | |
1519 | opts->warn_comments = 1; | |
1520 | else if (!strcmp (argv[i], "-Wcomments")) | |
1521 | opts->warn_comments = 1; | |
1522 | else if (!strcmp (argv[i], "-Wundef")) | |
1523 | opts->warn_undef = 1; | |
1524 | else if (!strcmp (argv[i], "-Wimport")) | |
1525 | opts->warn_import = 1; | |
1526 | else if (!strcmp (argv[i], "-Werror")) | |
1527 | opts->warnings_are_errors = 1; | |
1528 | else if (!strcmp (argv[i], "-Wno-traditional")) | |
1529 | opts->warn_stringify = 0; | |
1530 | else if (!strcmp (argv[i], "-Wno-trigraphs")) | |
1531 | opts->warn_trigraphs = 0; | |
1532 | else if (!strcmp (argv[i], "-Wno-comment")) | |
1533 | opts->warn_comments = 0; | |
1534 | else if (!strcmp (argv[i], "-Wno-comments")) | |
1535 | opts->warn_comments = 0; | |
1536 | else if (!strcmp (argv[i], "-Wno-undef")) | |
1537 | opts->warn_undef = 0; | |
1538 | else if (!strcmp (argv[i], "-Wno-import")) | |
1539 | opts->warn_import = 0; | |
1540 | else if (!strcmp (argv[i], "-Wno-error")) | |
1541 | opts->warnings_are_errors = 0; | |
1542 | break; | |
1543 | } | |
1544 | } | |
6de1e2a9 | 1545 | return i + 1; |
e23c0ba3 | 1546 | } |
0b22d65c | 1547 | |
e23c0ba3 ZW |
1548 | #ifdef HOST_EBCDIC |
1549 | static int | |
1550 | opt_comp (const void *p1, const void *p2) | |
1551 | { | |
1552 | return strcmp (((struct cl_option *)p1)->opt_text, | |
1553 | ((struct cl_option *)p2)->opt_text); | |
6de1e2a9 | 1554 | } |
e23c0ba3 | 1555 | #endif |
6de1e2a9 ZW |
1556 | |
1557 | /* Handle command-line options in (argc, argv). | |
1558 | Can be called multiple times, to handle multiple sets of options. | |
1559 | Returns if an unrecognized option is seen. | |
1560 | Returns number of strings consumed. */ | |
6de1e2a9 ZW |
1561 | int |
1562 | cpp_handle_options (pfile, argc, argv) | |
1563 | cpp_reader *pfile; | |
1564 | int argc; | |
1565 | char **argv; | |
1566 | { | |
1567 | int i; | |
1568 | int strings_processed; | |
e23c0ba3 ZW |
1569 | |
1570 | #ifdef HOST_EBCDIC | |
1571 | static int opts_sorted = 0; | |
1572 | ||
1573 | if (!opts_sorted) | |
1574 | { | |
1575 | opts_sorted = 1; | |
1576 | /* For non-ASCII hosts, the array needs to be sorted at runtime */ | |
1577 | qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp); | |
1578 | } | |
1579 | #endif | |
1580 | ||
6de1e2a9 ZW |
1581 | for (i = 0; i < argc; i += strings_processed) |
1582 | { | |
b0699dad | 1583 | strings_processed = handle_option (pfile, argc - i, argv + i); |
6de1e2a9 ZW |
1584 | if (strings_processed == 0) |
1585 | break; | |
1586 | } | |
1587 | return i; | |
1588 | } | |
1589 | ||
1590 | static void | |
1591 | print_help () | |
1592 | { | |
c1212d2f | 1593 | fprintf (stderr, _("Usage: %s [switches] input output\n"), progname); |
6de1e2a9 ZW |
1594 | fputs (_("\ |
1595 | Switches:\n\ | |
1596 | -include <file> Include the contents of <file> before other files\n\ | |
1597 | -imacros <file> Accept definition of macros in <file>\n\ | |
1598 | -iprefix <path> Specify <path> as a prefix for next two options\n\ | |
1599 | -iwithprefix <dir> Add <dir> to the end of the system include path\n\ | |
1600 | -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\ | |
1601 | -isystem <dir> Add <dir> to the start of the system include path\n\ | |
1602 | -idirafter <dir> Add <dir> to the end of the system include path\n\ | |
1603 | -I <dir> Add <dir> to the end of the main include path\n\ | |
e23c0ba3 | 1604 | -I- Fine-grained include path control; see info docs\n\ |
6de1e2a9 ZW |
1605 | -nostdinc Do not search system include directories\n\ |
1606 | (dirs specified with -isystem will still be used)\n\ | |
1607 | -nostdinc++ Do not search system include directories for C++\n\ | |
1608 | -o <file> Put output into <file>\n\ | |
1609 | -pedantic Issue all warnings demanded by strict ANSI C\n\ | |
e23c0ba3 | 1610 | -pedantic-errors Issue -pedantic warnings as errors instead\n\ |
6de1e2a9 ZW |
1611 | -traditional Follow K&R pre-processor behaviour\n\ |
1612 | -trigraphs Support ANSI C trigraphs\n\ | |
1613 | -lang-c Assume that the input sources are in C\n\ | |
1614 | -lang-c89 Assume that the input sources are in C89\n\ | |
1615 | -lang-c++ Assume that the input sources are in C++\n\ | |
1616 | -lang-objc Assume that the input sources are in ObjectiveC\n\ | |
1617 | -lang-objc++ Assume that the input sources are in ObjectiveC++\n\ | |
1618 | -lang-asm Assume that the input sources are in assembler\n\ | |
40c79d58 | 1619 | -lang-fortran Assume that the input sources are in Fortran\n\ |
6de1e2a9 ZW |
1620 | -lang-chill Assume that the input sources are in Chill\n\ |
1621 | -std=<std name> Specify the conformance standard; one of:\n\ | |
916269ab UD |
1622 | gnu89, gnu99, c89, c99, iso9899:1990,\n\ |
1623 | iso9899:199409, iso9899:1999\n\ | |
6de1e2a9 ZW |
1624 | -+ Allow parsing of C++ style features\n\ |
1625 | -w Inhibit warning messages\n\ | |
1626 | -Wtrigraphs Warn if trigraphs are encountered\n\ | |
1627 | -Wno-trigraphs Do not warn about trigraphs\n\ | |
1628 | -Wcomment{s} Warn if one comment starts inside another\n\ | |
1629 | -Wno-comment{s} Do not warn about comments\n\ | |
1630 | -Wtraditional Warn if a macro argument is/would be turned into\n\ | |
1631 | a string if -traditional is specified\n\ | |
1632 | -Wno-traditional Do not warn about stringification\n\ | |
1633 | -Wundef Warn if an undefined macro is used by #if\n\ | |
1634 | -Wno-undef Do not warn about testing undefined macros\n\ | |
1635 | -Wimport Warn about the use of the #import directive\n\ | |
1636 | -Wno-import Do not warn about the use of #import\n\ | |
1637 | -Werror Treat all warnings as errors\n\ | |
1638 | -Wno-error Do not treat warnings as errors\n\ | |
1639 | -Wall Enable all preprocessor warnings\n\ | |
1640 | -M Generate make dependencies\n\ | |
1641 | -MM As -M, but ignore system header files\n\ | |
1642 | -MD As -M, but put output in a .d file\n\ | |
1643 | -MMD As -MD, but ignore system header files\n\ | |
1644 | -MG Treat missing header file as generated files\n\ | |
e23c0ba3 | 1645 | -g3 Include #define and #undef directives in the output\n\ |
6de1e2a9 ZW |
1646 | -D<macro> Define a <macro> with string '1' as its value\n\ |
1647 | -D<macro>=<val> Define a <macro> with <val> as its value\n\ | |
1648 | -A<question> (<answer>) Assert the <answer> to <question>\n\ | |
1649 | -U<macro> Undefine <macro> \n\ | |
6de1e2a9 ZW |
1650 | -v Display the version number\n\ |
1651 | -H Print the name of header files as they are used\n\ | |
1652 | -C Do not discard comments\n\ | |
1653 | -dM Display a list of macro definitions active at end\n\ | |
1654 | -dD Preserve macro definitions in output\n\ | |
1655 | -dN As -dD except that only the names are preserved\n\ | |
1656 | -dI Include #include directives in the output\n\ | |
6de1e2a9 ZW |
1657 | -P Do not generate #line directives\n\ |
1658 | -$ Do not allow '$' in identifiers\n\ | |
1659 | -remap Remap file names when including files.\n\ | |
e23c0ba3 | 1660 | --version Display version information\n\ |
6de1e2a9 ZW |
1661 | -h or --help Display this information\n\ |
1662 | "), stdout); | |
1663 | } |