2 Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 Contributed by Per Bothner, 1994-95.
5 Based on CCCP program by Paul Rubin, June 1986
6 Adapted to ANSI C, Richard Stallman, Jan 1987
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #include "coretypes.h"
31 /* Internal structures and prototypes. */
33 /* A `struct pending_option' remembers one -D, -A, -U, -include, or
35 typedef void (* cl_directive_handler) PARAMS ((cpp_reader *, const char *));
38 struct pending_option *next;
40 cl_directive_handler handler;
43 /* The `pending' structure accumulates all the options that are not
44 actually processed until we hit cpp_read_main_file. It consists of
45 several lists, one for each type of option. We keep both head and
46 tail pointers for quick insertion. */
49 struct pending_option *directive_head, *directive_tail;
50 struct pending_option *imacros_head, *imacros_tail;
51 struct pending_option *include_head, *include_tail;
55 #define APPEND(pend, list, elt) \
56 do { if (!(pend)->list##_head) (pend)->list##_head = (elt); \
57 else (pend)->list##_tail->next = (elt); \
58 (pend)->list##_tail = (elt); \
61 #define APPEND(pend, list, elt) \
62 do { if (!(pend)->list/**/_head) (pend)->list/**/_head = (elt); \
63 else (pend)->list/**/_tail->next = (elt); \
64 (pend)->list/**/_tail = (elt); \
68 static void init_library PARAMS ((void));
69 static void init_builtins PARAMS ((cpp_reader *));
70 static void mark_named_operators PARAMS ((cpp_reader *));
71 static bool push_include PARAMS ((cpp_reader *,
72 struct pending_option *));
73 static void free_chain PARAMS ((struct pending_option *));
74 static void read_original_filename PARAMS ((cpp_reader *));
75 static void new_pending_directive PARAMS ((struct cpp_pending *,
77 cl_directive_handler));
78 static int parse_option PARAMS ((const char *));
79 static void post_options PARAMS ((cpp_reader *));
81 /* If we have designated initializers (GCC >2.7) these tables can be
82 initialized, constant data. Otherwise, they have to be filled in at
84 #if HAVE_DESIGNATED_INITIALIZERS
86 #define init_trigraph_map() /* Nothing. */
87 #define TRIGRAPH_MAP \
88 __extension__ const uchar _cpp_trigraph_map[UCHAR_MAX + 1] = {
91 #define s(p, v) [p] = v,
95 #define TRIGRAPH_MAP uchar _cpp_trigraph_map[UCHAR_MAX + 1] = { 0 }; \
96 static void init_trigraph_map PARAMS ((void)) { \
97 unsigned char *x = _cpp_trigraph_map;
100 #define s(p, v) x[p] = v;
105 s('=', '#') s(')', ']') s('!', '|')
106 s('(', '[') s('\'', '^') s('>', '}')
107 s('/', '\\') s('<', '{') s('-', '~')
114 /* A set of booleans indicating what CPP features each source language
120 char extended_numbers;
122 char dollars_in_ident;
123 char cplusplus_comments;
127 /* ??? Enable $ in identifiers in assembly? */
128 static const struct lang_flags lang_defaults[] =
129 { /* c99 c++ xnum std dollar c++comm digr */
130 /* GNUC89 */ { 0, 0, 1, 0, 1, 1, 1 },
131 /* GNUC99 */ { 1, 0, 1, 0, 1, 1, 1 },
132 /* STDC89 */ { 0, 0, 0, 1, 0, 0, 0 },
133 /* STDC94 */ { 0, 0, 0, 1, 0, 0, 1 },
134 /* STDC99 */ { 1, 0, 1, 1, 0, 1, 1 },
135 /* GNUCXX */ { 0, 1, 1, 0, 1, 1, 1 },
136 /* CXX98 */ { 0, 1, 1, 1, 0, 1, 1 },
137 /* ASM */ { 0, 0, 1, 0, 0, 1, 0 }
140 /* Sets internal flags correctly for a given language. */
142 cpp_set_lang (pfile, lang)
146 const struct lang_flags *l = &lang_defaults[(int) lang];
148 CPP_OPTION (pfile, lang) = lang;
150 CPP_OPTION (pfile, c99) = l->c99;
151 CPP_OPTION (pfile, cplusplus) = l->cplusplus;
152 CPP_OPTION (pfile, extended_numbers) = l->extended_numbers;
153 CPP_OPTION (pfile, std) = l->std;
154 CPP_OPTION (pfile, trigraphs) = l->std;
155 CPP_OPTION (pfile, dollars_in_ident) = l->dollars_in_ident;
156 CPP_OPTION (pfile, cplusplus_comments) = l->cplusplus_comments;
157 CPP_OPTION (pfile, digraphs) = l->digraphs;
161 static int opt_comp PARAMS ((const void *, const void *));
163 /* Run-time sorting of options array. */
168 return strcmp (((struct cl_option *) p1)->opt_text,
169 ((struct cl_option *) p2)->opt_text);
173 /* init initializes library global state. It might not need to
174 do anything depending on the platform and compiler. */
178 static int initialized = 0;
185 /* For non-ASCII hosts, the cl_options array needs to be sorted at
187 qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
190 /* Set up the trigraph map. This doesn't need to do anything if
191 we were compiled with a compiler that supports C99 designated
193 init_trigraph_map ();
197 /* Initialize a cpp_reader structure. */
199 cpp_create_reader (lang)
204 /* Initialize this instance of the library if it hasn't been already. */
207 pfile = (cpp_reader *) xcalloc (1, sizeof (cpp_reader));
209 cpp_set_lang (pfile, lang);
210 CPP_OPTION (pfile, warn_import) = 1;
211 CPP_OPTION (pfile, warn_multichar) = 1;
212 CPP_OPTION (pfile, discard_comments) = 1;
213 CPP_OPTION (pfile, discard_comments_in_macro_exp) = 1;
214 CPP_OPTION (pfile, show_column) = 1;
215 CPP_OPTION (pfile, tabstop) = 8;
216 CPP_OPTION (pfile, operator_names) = 1;
217 CPP_OPTION (pfile, warn_endif_labels) = 1;
218 CPP_OPTION (pfile, warn_deprecated) = 1;
219 CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99);
221 CPP_OPTION (pfile, pending) =
222 (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
224 /* Default CPP arithmetic to something sensible for the host for the
225 benefit of dumb users like fix-header. */
226 CPP_OPTION (pfile, precision) = CHAR_BIT * sizeof (long);
227 CPP_OPTION (pfile, char_precision) = CHAR_BIT;
228 CPP_OPTION (pfile, wchar_precision) = CHAR_BIT * sizeof (int);
229 CPP_OPTION (pfile, int_precision) = CHAR_BIT * sizeof (int);
230 CPP_OPTION (pfile, unsigned_char) = 0;
231 CPP_OPTION (pfile, unsigned_wchar) = 1;
233 /* Initialize the line map. Start at logical line 1, so we can use
234 a line number of zero for special states. */
235 init_line_maps (&pfile->line_maps);
238 /* Initialize lexer state. */
239 pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
241 /* Set up static tokens. */
242 pfile->avoid_paste.type = CPP_PADDING;
243 pfile->avoid_paste.val.source = NULL;
244 pfile->eof.type = CPP_EOF;
245 pfile->eof.flags = 0;
247 /* Create a token buffer for the lexer. */
248 _cpp_init_tokenrun (&pfile->base_run, 250);
249 pfile->cur_run = &pfile->base_run;
250 pfile->cur_token = pfile->base_run.base;
252 /* Initialize the base context. */
253 pfile->context = &pfile->base_context;
254 pfile->base_context.macro = 0;
255 pfile->base_context.prev = pfile->base_context.next = 0;
257 /* Aligned and unaligned storage. */
258 pfile->a_buff = _cpp_get_buff (pfile, 0);
259 pfile->u_buff = _cpp_get_buff (pfile, 0);
261 /* The expression parser stack. */
262 _cpp_expand_op_stack (pfile);
264 /* Initialize the buffer obstack. */
265 gcc_obstack_init (&pfile->buffer_ob);
267 _cpp_init_includes (pfile);
272 /* Free resources used by PFILE. Accessing PFILE after this function
273 returns leads to undefined behavior. Returns the error count. */
278 cpp_context *context, *contextn;
279 tokenrun *run, *runn;
281 free_chain (CPP_OPTION (pfile, pending)->include_head);
282 free (CPP_OPTION (pfile, pending));
283 free (pfile->op_stack);
285 while (CPP_BUFFER (pfile) != NULL)
286 _cpp_pop_buffer (pfile);
289 free (pfile->out.base);
291 if (pfile->macro_buffer)
293 free ((PTR) pfile->macro_buffer);
294 pfile->macro_buffer = NULL;
295 pfile->macro_buffer_len = 0;
299 deps_free (pfile->deps);
300 obstack_free (&pfile->buffer_ob, 0);
302 _cpp_destroy_hashtable (pfile);
303 _cpp_cleanup_includes (pfile);
305 _cpp_free_buff (pfile->a_buff);
306 _cpp_free_buff (pfile->u_buff);
307 _cpp_free_buff (pfile->free_buffs);
309 for (run = &pfile->base_run; run; run = runn)
313 if (run != &pfile->base_run)
317 for (context = pfile->base_context.next; context; context = contextn)
319 contextn = context->next;
323 free_line_maps (&pfile->line_maps);
327 /* This structure defines one built-in identifier. A node will be
328 entered in the hash table under the name NAME, with value VALUE.
330 There are two tables of these. builtin_array holds all the
331 "builtin" macros: these are handled by builtin_macro() in
332 cppmacro.c. Builtin is somewhat of a misnomer -- the property of
333 interest is that these macros require special code to compute their
334 expansions. The value is a "builtin_type" enumerator.
336 operator_array holds the C++ named operators. These are keywords
337 which act as aliases for punctuators. In C++, they cannot be
338 altered through #define, and #if recognizes them as operators. In
339 C, these are not entered into the hash table at all (but see
340 <iso646.h>). The value is a token-type enumerator. */
345 unsigned short value;
348 #define B(n, t) { DSC(n), t }
349 static const struct builtin builtin_array[] =
351 B("__TIME__", BT_TIME),
352 B("__DATE__", BT_DATE),
353 B("__FILE__", BT_FILE),
354 B("__BASE_FILE__", BT_BASE_FILE),
355 B("__LINE__", BT_SPECLINE),
356 B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL),
357 /* Keep builtins not used for -traditional-cpp at the end, and
358 update init_builtins() if any more are added. */
359 B("_Pragma", BT_PRAGMA),
360 B("__STDC__", BT_STDC),
363 static const struct builtin operator_array[] =
365 B("and", CPP_AND_AND),
366 B("and_eq", CPP_AND_EQ),
367 B("bitand", CPP_AND),
369 B("compl", CPP_COMPL),
371 B("not_eq", CPP_NOT_EQ),
373 B("or_eq", CPP_OR_EQ),
375 B("xor_eq", CPP_XOR_EQ)
379 /* Mark the C++ named operators in the hash table. */
381 mark_named_operators (pfile)
384 const struct builtin *b;
386 for (b = operator_array;
387 b < (operator_array + ARRAY_SIZE (operator_array));
390 cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
391 hp->flags |= NODE_OPERATOR;
392 hp->is_directive = 0;
393 hp->directive_index = b->value;
397 /* Subroutine of cpp_read_main_file; reads the builtins table above and
398 enters them, and language-specific macros, into the hash table. */
400 init_builtins (pfile)
403 const struct builtin *b;
404 size_t n = ARRAY_SIZE (builtin_array);
406 if (CPP_OPTION (pfile, traditional))
409 for(b = builtin_array; b < builtin_array + n; b++)
411 cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
413 hp->flags |= NODE_BUILTIN | NODE_WARN;
414 hp->value.builtin = b->value;
417 if (CPP_OPTION (pfile, cplusplus))
418 _cpp_define_builtin (pfile, "__cplusplus 1");
419 else if (CPP_OPTION (pfile, lang) == CLK_ASM)
420 _cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
421 else if (CPP_OPTION (pfile, lang) == CLK_STDC94)
422 _cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L");
423 else if (CPP_OPTION (pfile, c99))
424 _cpp_define_builtin (pfile, "__STDC_VERSION__ 199901L");
426 if (CPP_OPTION (pfile, objc))
427 _cpp_define_builtin (pfile, "__OBJC__ 1");
429 if (pfile->cb.register_builtins)
430 (*pfile->cb.register_builtins) (pfile);
433 /* Pushes a command line -imacro and -include file indicated by P onto
434 the buffer stack. Returns nonzero if successful. */
436 push_include (pfile, p)
438 struct pending_option *p;
442 /* Later: maybe update this to use the #include "" search path
443 if cpp_read_file fails. */
444 header.type = CPP_STRING;
445 header.val.str.text = (const unsigned char *) p->arg;
446 header.val.str.len = strlen (p->arg);
447 /* Make the command line directive take up a line. */
450 return _cpp_execute_include (pfile, &header, IT_CMDLINE);
453 /* Frees a pending_option chain. */
456 struct pending_option *head;
458 struct pending_option *next;
468 /* Sanity-checks are dependent on command-line options, so it is
469 called as a subroutine of cpp_read_main_file (). */
471 static void sanity_checks PARAMS ((cpp_reader *));
472 static void sanity_checks (pfile)
476 size_t max_precision = 2 * CHAR_BIT * sizeof (cpp_num_part);
478 /* Sanity checks for assumptions about CPP arithmetic and target
479 type precisions made by cpplib. */
482 cpp_error (pfile, DL_ICE, "cppchar_t must be an unsigned type");
484 if (CPP_OPTION (pfile, precision) > max_precision)
485 cpp_error (pfile, DL_ICE,
486 "preprocessor arithmetic has maximum precision of %lu bits; target requires %lu bits",
487 (unsigned long) max_precision,
488 (unsigned long) CPP_OPTION (pfile, precision));
490 if (CPP_OPTION (pfile, precision) < CPP_OPTION (pfile, int_precision))
491 cpp_error (pfile, DL_ICE,
492 "CPP arithmetic must be at least as precise as a target int");
494 if (CPP_OPTION (pfile, char_precision) < 8)
495 cpp_error (pfile, DL_ICE, "target char is less than 8 bits wide");
497 if (CPP_OPTION (pfile, wchar_precision) < CPP_OPTION (pfile, char_precision))
498 cpp_error (pfile, DL_ICE,
499 "target wchar_t is narrower than target char");
501 if (CPP_OPTION (pfile, int_precision) < CPP_OPTION (pfile, char_precision))
502 cpp_error (pfile, DL_ICE,
503 "target int is narrower than target char");
505 /* This is assumed in eval_token() and could be fixed if necessary. */
506 if (sizeof (cppchar_t) > sizeof (cpp_num_part))
507 cpp_error (pfile, DL_ICE, "CPP half-integer narrower than CPP character");
509 if (CPP_OPTION (pfile, wchar_precision) > BITS_PER_CPPCHAR_T)
510 cpp_error (pfile, DL_ICE,
511 "CPP on this host cannot handle wide character constants over %lu bits, but the target requires %lu bits",
512 (unsigned long) BITS_PER_CPPCHAR_T,
513 (unsigned long) CPP_OPTION (pfile, wchar_precision));
516 # define sanity_checks(PFILE)
519 /* Add a dependency target. Can be called any number of times before
520 cpp_read_main_file(). If no targets have been added before
521 cpp_read_main_file(), then the default target is used. */
523 cpp_add_dependency_target (pfile, target, quote)
529 pfile->deps = deps_init ();
531 deps_add_target (pfile->deps, target, quote);
534 /* This is called after options have been parsed, and partially
535 processed. Setup for processing input from the file named FNAME,
536 or stdin if it is the empty string. Return the original filename
537 on success (e.g. foo.i->foo.c), or NULL on failure. */
539 cpp_read_main_file (pfile, fname, table)
544 sanity_checks (pfile);
546 post_options (pfile);
548 /* The front ends don't set up the hash table until they have
549 finished processing the command line options, so initializing the
550 hashtable is deferred until now. */
551 _cpp_init_hashtable (pfile, table);
553 if (CPP_OPTION (pfile, deps.style) != DEPS_NONE)
556 pfile->deps = deps_init ();
558 /* Set the default target (if there is none already). */
559 deps_add_default_target (pfile->deps, fname);
562 /* Open the main input file. */
563 if (!_cpp_read_file (pfile, fname))
566 /* Set this here so the client can change the option if it wishes,
567 and after stacking the main file so we don't trace the main
569 pfile->line_maps.trace_includes = CPP_OPTION (pfile, print_include_names);
571 /* For foo.i, read the original filename foo.c now, for the benefit
572 of the front ends. */
573 if (CPP_OPTION (pfile, preprocessed))
574 read_original_filename (pfile);
576 return pfile->map->to_file;
579 /* For preprocessed files, if the first tokens are of the form # NUM.
580 handle the directive so we know the original file name. This will
581 generate file_change callbacks, which the front ends must handle
582 appropriately given their state of initialization. */
584 read_original_filename (pfile)
587 const cpp_token *token, *token1;
589 /* Lex ahead; if the first tokens are of the form # NUM, then
590 process the directive, otherwise back up. */
591 token = _cpp_lex_direct (pfile);
592 if (token->type == CPP_HASH)
594 token1 = _cpp_lex_direct (pfile);
595 _cpp_backup_tokens (pfile, 1);
597 /* If it's a #line directive, handle it. */
598 if (token1->type == CPP_NUMBER)
600 _cpp_handle_directive (pfile, token->flags & PREV_WHITE);
605 /* Backup as if nothing happened. */
606 _cpp_backup_tokens (pfile, 1);
609 /* Handle pending command line options: -D, -U, -A, -imacros and
610 -include. This should be called after debugging has been properly
611 set up in the front ends. */
613 cpp_finish_options (pfile)
616 /* Mark named operators before handling command line macros. */
617 if (CPP_OPTION (pfile, cplusplus) && CPP_OPTION (pfile, operator_names))
618 mark_named_operators (pfile);
620 /* Install builtins and process command line macros etc. in the order
621 they appeared, but only if not already preprocessed. */
622 if (! CPP_OPTION (pfile, preprocessed))
624 struct pending_option *p;
626 _cpp_do_file_change (pfile, LC_RENAME, _("<built-in>"), 1, 0);
627 init_builtins (pfile);
628 _cpp_do_file_change (pfile, LC_RENAME, _("<command line>"), 1, 0);
629 for (p = CPP_OPTION (pfile, pending)->directive_head; p; p = p->next)
630 (*p->handler) (pfile, p->arg);
632 /* Scan -imacros files after -D, -U, but before -include.
633 pfile->next_include_file is NULL, so _cpp_pop_buffer does not
634 push -include files. */
635 for (p = CPP_OPTION (pfile, pending)->imacros_head; p; p = p->next)
636 if (push_include (pfile, p))
637 cpp_scan_nooutput (pfile);
639 pfile->next_include_file = &CPP_OPTION (pfile, pending)->include_head;
640 _cpp_maybe_push_include_file (pfile);
643 pfile->first_unused_line = pfile->line;
645 free_chain (CPP_OPTION (pfile, pending)->imacros_head);
646 free_chain (CPP_OPTION (pfile, pending)->directive_head);
649 /* Push the next buffer on the stack given by -include, if any. */
651 _cpp_maybe_push_include_file (pfile)
654 if (pfile->next_include_file)
656 struct pending_option *head = *pfile->next_include_file;
658 while (head && !push_include (pfile, head))
662 pfile->next_include_file = &head->next;
665 /* All done; restore the line map from <command line>. */
666 _cpp_do_file_change (pfile, LC_RENAME,
667 pfile->line_maps.maps[0].to_file, 1, 0);
668 /* Don't come back here again. */
669 pfile->next_include_file = NULL;
674 /* This is called at the end of preprocessing. It pops the last
675 buffer and writes dependency output, and returns the number of
678 Maybe it should also reset state, such that you could call
679 cpp_start_read with a new filename to restart processing. */
681 cpp_finish (pfile, deps_stream)
685 /* Warn about unused macros before popping the final buffer. */
686 if (CPP_OPTION (pfile, warn_unused_macros))
687 cpp_forall_identifiers (pfile, _cpp_warn_if_unused_macro, NULL);
689 /* cpplex.c leaves the final buffer on the stack. This it so that
690 it returns an unending stream of CPP_EOFs to the client. If we
691 popped the buffer, we'd dereference a NULL buffer pointer and
692 segfault. It's nice to allow the client to do worry-free excess
693 cpp_get_token calls. */
694 while (pfile->buffer)
695 _cpp_pop_buffer (pfile);
697 /* Don't write the deps file if there are errors. */
698 if (CPP_OPTION (pfile, deps.style) != DEPS_NONE
699 && deps_stream && pfile->errors == 0)
701 deps_write (pfile->deps, deps_stream, 72);
703 if (CPP_OPTION (pfile, deps.phony_targets))
704 deps_phony_targets (pfile->deps, deps_stream);
707 /* Report on headers that could use multiple include guards. */
708 if (CPP_OPTION (pfile, print_include_names))
709 _cpp_report_missing_guards (pfile);
711 return pfile->errors;
714 /* Add a directive to be handled later in the initialization phase. */
716 new_pending_directive (pend, text, handler)
717 struct cpp_pending *pend;
719 cl_directive_handler handler;
721 struct pending_option *o = (struct pending_option *)
722 xmalloc (sizeof (struct pending_option));
726 o->handler = handler;
727 APPEND (pend, directive, o);
730 /* Irix6 "cc -n32" and OSF4 cc have problems with char foo[] = ("string");
731 I.e. a const string initializer with parens around it. That is
732 what N_("string") resolves to, so we make no_* be macros instead. */
733 #define no_ass N_("assertion missing after %s")
734 #define no_fil N_("file name missing after %s")
735 #define no_mac N_("macro name missing after %s")
737 /* This is the list of all command line options, with the leading
738 "-" removed. It must be sorted in ASCII collating order. */
739 #define COMMAND_LINE_OPTIONS \
740 DEF_OPT("A", no_ass, OPT_A) \
741 DEF_OPT("D", no_mac, OPT_D) \
742 DEF_OPT("U", no_mac, OPT_U) \
743 DEF_OPT("imacros", no_fil, OPT_imacros) \
744 DEF_OPT("include", no_fil, OPT_include)
746 #define DEF_OPT(text, msg, code) code,
756 const char *opt_text;
759 enum opt_code opt_code;
762 #define DEF_OPT(text, msg, code) { text, msg, sizeof(text) - 1, code },
764 static struct cl_option cl_options[] =
766 static const struct cl_option cl_options[] =
772 #undef COMMAND_LINE_OPTIONS
774 /* Perform a binary search to find which, if any, option the given
775 command-line matches. Returns its index in the option array,
776 negative on failure. Complications arise since some options can be
777 suffixed with an argument, and multiple complete matches can occur,
778 e.g. -pedantic and -pedantic-errors. */
783 unsigned int md, mn, mx;
794 opt_len = cl_options[md].opt_len;
795 comp = strncmp (input, cl_options[md].opt_text, opt_len);
803 if (input[opt_len] == '\0')
805 /* We were passed more text. If the option takes an argument,
806 we may match a later option or we may have been passed the
807 argument. The longest possible option match succeeds.
808 If the option takes no arguments we have not matched and
809 continue the search (e.g. input="stdc++" match was "stdc"). */
811 if (cl_options[md].msg)
813 /* Scan forwards. If we get an exact match, return it.
814 Otherwise, return the longest option-accepting match.
815 This loops no more than twice with current options. */
817 for (; mn < (unsigned int) N_OPTS; mn++)
819 opt_len = cl_options[mn].opt_len;
820 if (strncmp (input, cl_options[mn].opt_text, opt_len))
822 if (input[opt_len] == '\0')
824 if (cl_options[mn].msg)
835 /* Handle one command-line option in (argc, argv).
836 Can be called multiple times, to handle multiple sets of options.
837 Returns number of strings consumed. */
839 cpp_handle_option (pfile, argc, argv)
845 struct cpp_pending *pend = CPP_OPTION (pfile, pending);
848 enum opt_code opt_code;
853 opt_index = parse_option (&argv[i][1]);
857 opt_code = cl_options[opt_index].opt_code;
858 if (cl_options[opt_index].msg)
860 arg = &argv[i][cl_options[opt_index].opt_len + 1];
866 cpp_error (pfile, DL_ERROR,
867 cl_options[opt_index].msg, argv[i - 1]);
875 case N_OPTS: /* Shut GCC up. */
879 new_pending_directive (pend, arg, cpp_define);
885 /* -A with an argument beginning with '-' acts as
886 #unassert on whatever immediately follows the '-'.
887 If "-" is the whole argument, we eliminate all
888 predefined macros and assertions, including those
889 that were specified earlier on the command line.
890 That way we can get rid of any that were passed
891 automatically in from GCC. */
895 free_chain (pend->directive_head);
896 pend->directive_head = NULL;
897 pend->directive_tail = NULL;
900 new_pending_directive (pend, arg + 1, cpp_unassert);
903 new_pending_directive (pend, arg, cpp_assert);
906 new_pending_directive (pend, arg, cpp_undef);
911 struct pending_option *o = (struct pending_option *)
912 xmalloc (sizeof (struct pending_option));
916 if (opt_code == OPT_include)
917 APPEND (pend, include, o);
919 APPEND (pend, imacros, o);
931 /* -Wtraditional is not useful in C++ mode. */
932 if (CPP_OPTION (pfile, cplusplus))
933 CPP_OPTION (pfile, warn_traditional) = 0;
935 /* Permanently disable macro expansion if we are rescanning
936 preprocessed text. Read preprocesed source in ISO mode. */
937 if (CPP_OPTION (pfile, preprocessed))
939 pfile->state.prevent_expansion = 1;
940 CPP_OPTION (pfile, traditional) = 0;
943 /* Traditional CPP does not accurately track column information. */
944 if (CPP_OPTION (pfile, traditional))
945 CPP_OPTION (pfile, show_column) = 0;