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