* fixed GCC 4.4.0 mingw compilation:
[fw/sdcc] / support / cpp / sdcpp-opts.c
1 /* C/ObjC/C++ command line option handling.
2    Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
3    Contributed by Neil Booth.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "intl.h"
25 #include "cppdefault.h"
26 #include "c-incpath.h"
27 #include "opts.h"
28 #include "options.h"
29 #include "mkdeps.h"
30
31 #ifndef DOLLARS_IN_IDENTIFIERS
32 # define DOLLARS_IN_IDENTIFIERS true
33 #endif
34
35 #ifndef TARGET_SYSTEM_ROOT
36 # define TARGET_SYSTEM_ROOT NULL
37 #endif
38
39 /* CPP's options.  */
40 static cpp_options *cpp_opts;
41
42 /* Input filename.  */
43 static const char *this_input_filename;
44
45 /* Filename and stream for preprocessed output.  */
46 static const char *out_fname;
47 static FILE *out_stream;
48
49 /* Append dependencies to deps_file.  */
50 static bool deps_append;
51
52 /* If dependency switches (-MF etc.) have been given.  */
53 static bool deps_seen;
54
55 /* If -v seen.  */
56 static bool verbose;
57
58 /* Dependency output file.  */
59 static const char *deps_file;
60
61 /* The prefix given by -iprefix, if any.  */
62 static const char *iprefix;
63
64 /* The multilib directory given by -imultilib, if any.  */
65 static const char *imultilib;
66
67 /* The system root, if any.  Overridden by -isysroot.  */
68 static const char *sysroot = TARGET_SYSTEM_ROOT;
69
70 /* Zero disables all standard directories for headers.  */
71 static bool std_inc = true;
72
73 /* If the quote chain has been split by -I-.  */
74 static bool quote_chain_split;
75
76 /* If -Wunused-macros.  */
77 static bool warn_unused_macros;
78
79 /* If -Wvariadic-macros.  */
80 static bool warn_variadic_macros = true;
81
82 /* Number of deferred options.  */
83 static size_t deferred_count;
84
85 /* Number of deferred options scanned for -include.  */
86 static size_t include_cursor;
87
88 static void handle_OPT_d (const char *);
89 static void set_std_c89 (int, int);
90 static void set_std_c99 (int);
91 static void check_deps_environment_vars (void);
92 static void handle_deferred_opts (void);
93 static void sanitize_cpp_opts (void);
94 static void add_prefixed_path (const char *, size_t);
95 static void push_command_line_include (void);
96 static void cb_file_change (cpp_reader *, const struct line_map *);
97 static void cb_dir_change (cpp_reader *, const char *);
98 static void finish_options (void);
99
100 #ifndef STDC_0_IN_SYSTEM_HEADERS
101 #define STDC_0_IN_SYSTEM_HEADERS 0
102 #endif
103
104 /* Holds switches parsed by sdcpp_common_handle_option (), but whose
105    handling is deferred to sdcpp_common_post_options ().  */
106 static void defer_opt (enum opt_code, const char *);
107 static struct deferred_opt
108 {
109   enum opt_code code;
110   const char *arg;
111 } *deferred_opts;
112
113 /* Complain that switch CODE expects an argument but none was
114    provided.  OPT was the command-line option.  Return FALSE to get
115    the default message in opts.c, TRUE if we provide a specialized
116    one.  */
117 bool
118 sdcpp_common_missing_argument (const char *opt, size_t code)
119 {
120   switch (code)
121     {
122     default:
123       /* Pick up the default message.  */
124       return false;
125
126     case OPT_A:
127       error ("assertion missing after \"%s\"", opt);
128       break;
129
130     case OPT_D:
131     case OPT_U:
132       error ("macro name missing after \"%s\"", opt);
133       break;
134
135     case OPT_I:
136     case OPT_idirafter:
137     case OPT_isysroot:
138     case OPT_isystem:
139     case OPT_iquote:
140       error ("missing path after \"%s\"", opt);
141       break;
142
143     case OPT_MF:
144     case OPT_MD:
145     case OPT_MMD:
146     case OPT_include:
147     case OPT_imacros:
148     case OPT_o:
149       error ("missing filename after \"%s\"", opt);
150       break;
151
152     case OPT_MQ:
153     case OPT_MT:
154       error ("missing makefile target after \"%s\"", opt);
155       break;
156     }
157
158   return true;
159 }
160
161 /* Defer option CODE with argument ARG.  */
162 static void
163 defer_opt (enum opt_code code, const char *arg)
164 {
165   deferred_opts[deferred_count].code = code;
166   deferred_opts[deferred_count].arg = arg;
167   deferred_count++;
168 }
169
170 /* Common initialization before parsing options.  */
171 unsigned int
172 sdcpp_common_init_options (unsigned int argc, const char **argv ATTRIBUTE_UNUSED)
173 {
174   parse_in = cpp_create_reader (CLK_GNUC89, NULL, &line_table);
175
176   cpp_opts = cpp_get_options (parse_in);
177   cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
178   cpp_opts->objc = 0;
179
180   /* Reset to avoid warnings on internal definitions.  We set it just
181      before passing on command-line options to cpplib.  */
182   cpp_opts->warn_dollars = 0;
183
184   deferred_opts = XNEWVEC (struct deferred_opt, argc);
185
186   return CL_SDCPP;
187 }
188
189 /* Handle switch SCODE with argument ARG.  VALUE is true, unless no-
190    form of an -f or -W option was given.  Returns 0 if the switch was
191    invalid, a negative number to prevent language-independent
192    processing in toplev.c (a hack necessary for the short-term).  */
193 int
194 sdcpp_common_handle_option (size_t scode, const char *arg, int value)
195 {
196   enum opt_code code = (enum opt_code) scode;
197   int result = 1;
198
199   switch (code)
200     {
201     default:
202       result = 0;
203       break;
204
205 #if 0 // pch not supported by sdcpp
206     case OPT__output_pch_:
207       pch_file = arg;
208       break;
209 #endif
210
211     case OPT_A:
212       defer_opt (code, arg);
213       break;
214
215     case OPT_C:
216       cpp_opts->discard_comments = 0;
217       break;
218
219     case OPT_CC:
220       cpp_opts->discard_comments = 0;
221       cpp_opts->discard_comments_in_macro_exp = 0;
222       break;
223
224     case OPT_D:
225       defer_opt (code, arg);
226       break;
227
228     case OPT_H:
229       cpp_opts->print_include_names = 1;
230       break;
231
232     case OPT_I:
233       if (strcmp (arg, "-"))
234         add_path (xstrdup (arg), BRACKET, 0, true);
235       else
236         {
237           if (quote_chain_split)
238             error ("-I- specified twice");
239           quote_chain_split = true;
240           split_quote_chain ();
241           inform ("obsolete option -I- used, please use -iquote instead");
242         }
243       break;
244
245     case OPT_M:
246     case OPT_MM:
247       /* When doing dependencies with -M or -MM, suppress normal
248          preprocessed output, but still do -dM etc. as software
249          depends on this.  Preprocessed output does occur if -MD, -MMD
250          or environment var dependency generation is used.  */
251       cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
252       flag_no_output = 1;
253       cpp_opts->inhibit_warnings = 1;
254       break;
255
256     case OPT_MD:
257     case OPT_MMD:
258       cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
259       deps_file = arg;
260       break;
261
262     case OPT_MF:
263       deps_seen = true;
264       deps_file = arg;
265       break;
266
267     case OPT_MG:
268       deps_seen = true;
269       cpp_opts->deps.missing_files = true;
270       break;
271
272     case OPT_MP:
273       deps_seen = true;
274       cpp_opts->deps.phony_targets = true;
275       break;
276
277     case OPT_MQ:
278     case OPT_MT:
279       deps_seen = true;
280       defer_opt (code, arg);
281       break;
282
283     case OPT_P:
284       flag_no_line_commands = 1;
285       break;
286
287     case OPT_fworking_directory:
288       flag_working_directory = value;
289       break;
290
291     case OPT_U:
292       defer_opt (code, arg);
293       break;
294
295     case OPT_Wall:
296       cpp_opts->warn_trigraphs = value;
297       cpp_opts->warn_comments = value;
298       cpp_opts->warn_num_sign_change = value;
299       cpp_opts->warn_multichar = value; /* Was C++ only.  */
300       break;
301
302     case OPT_Wcomment:
303     case OPT_Wcomments:
304       cpp_opts->warn_comments = value;
305       break;
306
307     case OPT_Wdeprecated:
308       cpp_opts->warn_deprecated = value;
309       break;
310
311     case OPT_Wendif_labels:
312       cpp_opts->warn_endif_labels = value;
313       break;
314
315     case OPT_Werror:
316       cpp_opts->warnings_are_errors = value;
317       break;
318
319     case OPT_Wimport:
320       /* Silently ignore for now.  */
321       break;
322
323 #if 0 // pch not supported by sdcpp
324     case OPT_Winvalid_pch:
325       cpp_opts->warn_invalid_pch = value;
326       break;
327 #endif
328
329     case OPT_Wsystem_headers:
330       cpp_opts->warn_system_headers = value;
331       break;
332
333     case OPT_Wtraditional:
334       cpp_opts->warn_traditional = value;
335       break;
336
337     case OPT_Wtrigraphs:
338       cpp_opts->warn_trigraphs = value;
339       break;
340
341     case OPT_Wundef:
342       cpp_opts->warn_undef = value;
343       break;
344
345     case OPT_Wunused_macros:
346       warn_unused_macros = value;
347       break;
348
349     case OPT_Wvariadic_macros:
350       warn_variadic_macros = value;
351       break;
352
353     case OPT_ansi:
354       set_std_c89 (false, true);
355       break;
356
357     case OPT_d:
358       handle_OPT_d (arg);
359       break;
360
361     case OPT_fdollars_in_identifiers:
362       cpp_opts->dollars_in_ident = value;
363       break;
364
365     case OPT_fsigned_char:
366       flag_signed_char = value;
367       break;
368
369     case OPT_funsigned_char:
370       flag_signed_char = !value;
371       break;
372
373 #if 0 // pch not supported by sdcpp
374     case OPT_fpch_deps:
375       cpp_opts->restore_pch_deps = value;
376       break;
377
378     case OPT_fpch_preprocess:
379       flag_pch_preprocess = value;
380       break;
381 #endif
382
383     case OPT_fpreprocessed:
384       cpp_opts->preprocessed = value;
385       break;
386
387     case OPT_fshow_column:
388       cpp_opts->show_column = value;
389       break;
390
391     case OPT_ftabstop_:
392       /* It is documented that we silently ignore silly values.  */
393       if (value >= 1 && value <= 100)
394         cpp_opts->tabstop = value;
395       break;
396
397     case OPT_fexec_charset_:
398       cpp_opts->narrow_charset = arg;
399       break;
400
401     case OPT_fwide_exec_charset_:
402       cpp_opts->wide_charset = arg;
403       break;
404
405     case OPT_finput_charset_:
406       cpp_opts->input_charset = arg;
407       break;
408
409     case OPT_idirafter:
410       add_path (xstrdup (arg), AFTER, 0, true);
411       break;
412
413     case OPT_imacros:
414     case OPT_include:
415       defer_opt (code, arg);
416       break;
417
418     case OPT_iprefix:
419       iprefix = arg;
420       break;
421
422     case OPT_imultilib:
423       imultilib = arg;
424       break;
425
426     case OPT_iquote:
427       add_path (xstrdup (arg), QUOTE, 0, true);
428       break;
429
430     case OPT_isysroot:
431       sysroot = arg;
432       break;
433
434     case OPT_isystem:
435       add_path (xstrdup (arg), SYSTEM, 0, true);
436       break;
437
438     case OPT_iwithprefix:
439       add_prefixed_path (arg, SYSTEM);
440       break;
441
442     case OPT_iwithprefixbefore:
443       add_prefixed_path (arg, BRACKET);
444       break;
445
446     case OPT_lang_asm:
447       cpp_set_lang (parse_in, CLK_ASM);
448       cpp_opts->dollars_in_ident = false;
449       break;
450
451     case OPT_lang_objc:
452       cpp_opts->objc = 1;
453       break;
454
455     case OPT_nostdinc:
456       std_inc = false;
457       break;
458
459     case OPT_o:
460       if (!out_fname)
461         out_fname = arg;
462       else
463         error ("output filename specified twice");
464       break;
465
466       /* SDCPP specfic */
467     case OPT_obj_ext_:
468       cpp_opts->obj_ext = arg;
469       break;
470
471       /* We need to handle the -pedantic switches here, rather than in
472          sdcpp_common_post_options, so that a subsequent -Wno-endif-labels
473          is not overridden.  */
474     case OPT_pedantic_errors:
475       cpp_opts->pedantic_errors = 1;
476       /* Fall through.  */
477     case OPT_pedantic:
478       cpp_opts->pedantic = 1;
479       cpp_opts->warn_endif_labels = 1;
480       break;
481
482       /* SDCPP specfic */
483     case OPT_pedantic_parse_number:
484       cpp_opts->pedantic_parse_number = 1;
485       break;
486
487 #if 0 // pch not supported by sdcpp
488     case OPT_print_pch_checksum:
489       c_common_print_pch_checksum (stdout);
490       exit_after_options = true;
491       break;
492 #endif
493
494     case OPT_remap:
495       cpp_opts->remap = 1;
496       break;
497
498     case OPT_std_c89:
499     case OPT_std_iso9899_1990:
500     case OPT_std_iso9899_199409:
501       set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
502       break;
503
504     case OPT_std_c99:
505     case OPT_std_iso9899_1999:
506       set_std_c99 (true /* ISO */);
507       break;
508
509     case OPT_trigraphs:
510       cpp_opts->trigraphs = 1;
511       break;
512
513     case OPT_traditional_cpp:
514       cpp_opts->traditional = 1;
515       break;
516
517     case OPT_w:
518       cpp_opts->inhibit_warnings = 1;
519       break;
520
521     case OPT_v:
522       verbose = true;
523       break;
524     }
525
526   return result;
527 }
528
529 /* Post-switch processing.  */
530 bool
531 sdcpp_common_post_options (const char **pfilename)
532 {
533   struct cpp_callbacks *cb;
534
535   /* Canonicalize the input and output filenames.  */
536   if (in_fnames == NULL)
537     {
538       in_fnames = XNEWVEC (const char *, 1);
539       in_fnames[0] = "";
540     }
541   else if (strcmp (in_fnames[0], "-") == 0)
542     in_fnames[0] = "";
543
544   if (out_fname == NULL || !strcmp (out_fname, "-"))
545     out_fname = "";
546
547   if (cpp_opts->deps.style == DEPS_NONE)
548     check_deps_environment_vars ();
549
550   handle_deferred_opts ();
551
552   sanitize_cpp_opts ();
553
554   register_include_chains (parse_in, sysroot, iprefix, imultilib,
555                            std_inc, 0, verbose);
556
557   /* Open the output now.  We must do so even if flag_no_output is
558      on, because there may be other output than from the actual
559      preprocessing (e.g. from -dM).  */
560   if (out_fname[0] == '\0')
561     out_stream = stdout;
562   else
563     out_stream = fopen (out_fname, "w");
564
565   if (out_stream == NULL)
566     {
567       fatal_error ("opening output file %s: %s", out_fname, strerror(errno));
568       return false;
569     }
570
571   if (num_in_fnames > 1)
572     error ("too many filenames given.  Type %s --help for usage",
573            progname);
574
575   init_pp_output (out_stream);
576
577   cb = cpp_get_callbacks (parse_in);
578   cb->file_change = cb_file_change;
579   cb->dir_change = cb_dir_change;
580   cpp_post_options (parse_in);
581
582   /* If an error has occurred in cpplib, note it so we fail
583      immediately.  */
584   errorcount += cpp_errors (parse_in);
585
586   *pfilename = this_input_filename
587     = cpp_read_main_file (parse_in, in_fnames[0]);
588   /* Don't do any compilation or preprocessing if there is no input file.  */
589   if (this_input_filename == NULL)
590     {
591       errorcount++;
592       return false;
593     }
594
595   if (flag_working_directory && !flag_no_line_commands)
596     pp_dir_change (parse_in, get_src_pwd ());
597
598   return 1;
599 }
600
601 /* Front end initialization. */
602 bool
603 sdcpp_common_init (void)
604 {
605   /* Default CPP arithmetic to something sensible for the host for the
606      benefit of dumb users like fix-header.  */
607   cpp_opts->precision = CHAR_BIT * sizeof (long);
608   cpp_opts->char_precision = CHAR_BIT;
609   cpp_opts->int_precision = CHAR_BIT * sizeof (int);
610   cpp_opts->wchar_precision = CHAR_BIT * sizeof (int);
611   cpp_opts->unsigned_wchar = 1;
612   cpp_opts->bytes_big_endian = BYTES_BIG_ENDIAN;
613
614   /* This can't happen until after wchar_precision and bytes_big_endian
615      are known.  */
616   cpp_init_iconv (parse_in);
617
618 #if 0
619   if (version_flag)
620     c_common_print_pch_checksum (stderr);
621 #endif
622
623   finish_options ();
624   preprocess_file (parse_in);
625   return false;
626 }
627
628 /* Common finish hook for the C, ObjC and C++ front ends.  */
629 void
630 sdcpp_common_finish (void)
631 {
632   FILE *deps_stream = NULL;
633
634   if (cpp_opts->deps.style != DEPS_NONE)
635     {
636       /* If -M or -MM was seen without -MF, default output to the
637          output stream.  */
638       if (!deps_file)
639         deps_stream = out_stream;
640       else
641         {
642           deps_stream = fopen (deps_file, deps_append ? "a": "w");
643           if (!deps_stream)
644             fatal_error ("opening dependency file %s: %s", deps_file, strerror(errno));
645         }
646     }
647
648   /* For performance, avoid tearing down cpplib's internal structures
649      with cpp_destroy ().  */
650   errorcount += cpp_finish (parse_in, deps_stream);
651
652   if (deps_stream && deps_stream != out_stream
653       && (ferror (deps_stream) || fclose (deps_stream)))
654     fatal_error ("closing dependency file %s: %s", deps_file, strerror(errno));
655
656   if (out_stream && (ferror (out_stream) || fclose (out_stream)))
657     fatal_error ("when writing output to %s: %s", out_fname, strerror(errno));
658 }
659
660 /* Either of two environment variables can specify output of
661    dependencies.  Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
662    DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
663    and DEPS_TARGET is the target to mention in the deps.  They also
664    result in dependency information being appended to the output file
665    rather than overwriting it, and like Sun's compiler
666    SUNPRO_DEPENDENCIES suppresses the dependency on the main file.  */
667 static void
668 check_deps_environment_vars (void)
669 {
670   char *spec;
671
672   GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT");
673   if (spec)
674     cpp_opts->deps.style = DEPS_USER;
675   else
676     {
677       GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES");
678       if (spec)
679         {
680           cpp_opts->deps.style = DEPS_SYSTEM;
681           cpp_opts->deps.ignore_main_file = true;
682         }
683     }
684
685   if (spec)
686     {
687       /* Find the space before the DEPS_TARGET, if there is one.  */
688       char *s = strchr (spec, ' ');
689       if (s)
690         {
691           /* Let the caller perform MAKE quoting.  */
692           defer_opt (OPT_MT, s + 1);
693           *s = '\0';
694         }
695
696       /* Command line -MF overrides environment variables and default.  */
697       if (!deps_file)
698         deps_file = spec;
699
700       deps_append = 1;
701       deps_seen = true;
702     }
703 }
704
705 /* Handle deferred command line switches.  */
706 static void
707 handle_deferred_opts (void)
708 {
709   size_t i;
710   struct deps *deps;
711
712   /* Avoid allocating the deps buffer if we don't need it.
713      (This flag may be true without there having been -MT or -MQ
714      options, but we'll still need the deps buffer.)  */
715   if (!deps_seen)
716     return;
717
718   deps = cpp_get_deps (parse_in);
719
720   for (i = 0; i < deferred_count; i++)
721     {
722       struct deferred_opt *opt = &deferred_opts[i];
723
724       if (opt->code == OPT_MT || opt->code == OPT_MQ)
725         deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
726     }
727 }
728
729 /* These settings are appropriate for GCC, but not necessarily so for
730    cpplib as a library.  */
731 static void
732 sanitize_cpp_opts (void)
733 {
734   /* If we don't know what style of dependencies to output, complain
735      if any other dependency switches have been given.  */
736   if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
737     error ("to generate dependencies you must specify either -M or -MM");
738
739   /* -dM and dependencies suppress normal output; do it here so that
740      the last -d[MDN] switch overrides earlier ones.  */
741   if (flag_dump_macros == 'M')
742     flag_no_output = 1;
743
744   /* Disable -dD, -dN and -dI if normal output is suppressed.  Allow
745      -dM since at least glibc relies on -M -dM to work.  */
746   /* Also, flag_no_output implies flag_no_line_commands, always. */
747   if (flag_no_output)
748     {
749       if (flag_dump_macros != 'M')
750         flag_dump_macros = 0;
751       flag_dump_includes = 0;
752       flag_no_line_commands = 1;
753     }
754
755   cpp_opts->unsigned_char = !flag_signed_char;
756   cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
757
758   /* Similarly with -Wno-variadic-macros.  No check for c99 here, since
759      this also turns off warnings about GCCs extension.  */
760   cpp_opts->warn_variadic_macros
761     = warn_variadic_macros && (pedantic || warn_traditional);
762
763   /* If we're generating preprocessor output, emit current directory
764      if explicitly requested  */
765   if (flag_working_directory == -1)
766     flag_working_directory = 0;
767 }
768
769 /* Add include path with a prefix at the front of its name.  */
770 static void
771 add_prefixed_path (const char *suffix, size_t chain)
772 {
773   char *path;
774   const char *prefix;
775   size_t prefix_len, suffix_len;
776
777   suffix_len = strlen (suffix);
778   prefix     = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
779   prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
780
781   path = (char *) xmalloc (prefix_len + suffix_len + 1);
782   memcpy (path, prefix, prefix_len);
783   memcpy (path + prefix_len, suffix, suffix_len);
784   path[prefix_len + suffix_len] = '\0';
785
786   add_path (path, chain, 0, false);
787 }
788
789 /* Handle -D, -U, -A, -imacros, and the first -include.  */
790 static void
791 finish_options (void)
792 {
793   if (!cpp_opts->preprocessed)
794     {
795       size_t i;
796
797       cb_file_change (parse_in,
798                       linemap_add (&line_table, LC_RENAME, 0,
799                                    _("<built-in>"), 0));
800
801       cpp_init_builtins (parse_in, 0 /*flag_hosted*/);
802
803       /* We're about to send user input to cpplib, so make it warn for
804          things that we previously (when we sent it internal definitions)
805          told it to not warn.
806
807          C99 permits implementation-defined characters in identifiers.
808          The documented meaning of -std= is to turn off extensions that
809          conflict with the specified standard, and since a strictly
810          conforming program cannot contain a '$', we do not condition
811          their acceptance on the -std= setting.  */
812       cpp_opts->warn_dollars = (cpp_opts->pedantic && !cpp_opts->c99);
813
814       cpp_change_file (parse_in, LC_RENAME, _("<command line>"));
815       for (i = 0; i < deferred_count; i++)
816         {
817           struct deferred_opt *opt = &deferred_opts[i];
818
819           if (opt->code == OPT_D)
820             cpp_define (parse_in, opt->arg);
821           else if (opt->code == OPT_U)
822             cpp_undef (parse_in, opt->arg);
823           else if (opt->code == OPT_A)
824             {
825               if (opt->arg[0] == '-')
826                 cpp_unassert (parse_in, opt->arg + 1);
827               else
828                 cpp_assert (parse_in, opt->arg);
829             }
830         }
831
832       /* Handle -imacros after -D and -U.  */
833       for (i = 0; i < deferred_count; i++)
834         {
835           struct deferred_opt *opt = &deferred_opts[i];
836
837           if (opt->code == OPT_imacros
838               && cpp_push_include (parse_in, opt->arg))
839             {
840               /* Disable push_command_line_include callback for now.  */
841               include_cursor = deferred_count + 1;
842               cpp_scan_nooutput (parse_in);
843             }
844         }
845     }
846
847   include_cursor = 0;
848   push_command_line_include ();
849 }
850
851 /* Give CPP the next file given by -include, if any.  */
852 static void
853 push_command_line_include (void)
854 {
855   while (include_cursor < deferred_count)
856     {
857       struct deferred_opt *opt = &deferred_opts[include_cursor++];
858
859       if (!cpp_opts->preprocessed && opt->code == OPT_include
860           && cpp_push_include (parse_in, opt->arg))
861         return;
862     }
863
864   if (include_cursor == deferred_count)
865     {
866       include_cursor++;
867       /* -Wunused-macros should only warn about macros defined hereafter.  */
868       cpp_opts->warn_unused_macros = warn_unused_macros;
869       /* Restore the line map from <command line>.  */
870       if (!cpp_opts->preprocessed)
871         cpp_change_file (parse_in, LC_RENAME, this_input_filename);
872
873       /* Set this here so the client can change the option if it wishes,
874          and after stacking the main file so we don't trace the main file.  */
875       line_table.trace_includes = cpp_opts->print_include_names;
876     }
877 }
878
879 /* File change callback.  Has to handle -include files.  */
880 static void
881 cb_file_change (cpp_reader * ARG_UNUSED (pfile),
882                 const struct line_map *new_map)
883 {
884   pp_file_change (new_map);
885
886   if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)))
887     push_command_line_include ();
888 }
889
890 void
891 cb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir)
892 {
893   if (!set_src_pwd (dir))
894     warning (0, "too late for # directive to set debug directory");
895 }
896
897 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
898    extensions if ISO).  There is no concept of gnu94.  */
899 static void
900 set_std_c89 (int c94, int iso)
901 {
902   cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
903 }
904
905 /* Set the C 99 standard (without GNU extensions if ISO).  */
906 static void
907 set_std_c99 (int iso)
908 {
909   cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
910 }
911
912 /* Args to -d specify what to dump.  Silently ignore
913    unrecognized options; they may be aimed at toplev.c.  */
914 static void
915 handle_OPT_d (const char *arg)
916 {
917   char c;
918
919   while ((c = *arg++) != '\0')
920     switch (c)
921       {
922       case 'M':                 /* Dump macros only.  */
923       case 'N':                 /* Dump names.  */
924       case 'D':                 /* Dump definitions.  */
925         flag_dump_macros = c;
926         break;
927
928       case 'I':
929         flag_dump_includes = 1;
930         break;
931       }
932 }