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