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