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