2 Copyright (C) 1986, 87, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
3 Written by Per Bothner, 1994-95.
4 Based on CCCP program by by Paul Rubin, June 1986
5 Adapted to ANSI C, Richard Stallman, Jan 1987
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 In other words, you are welcome to use, share and improve this program.
22 You are forbidden to forbid anyone else to use, share and improve
23 what you give them. Help stamp out software-hoarding! */
27 #include "../src/config.h"
35 /* The macro EMACS is defined when cpp is distributed as part of Emacs,
36 for the sake of machines with limited C compilers. */
39 #endif /* not EMACS */
41 #ifndef STANDARD_INCLUDE_DIR
42 #define STANDARD_INCLUDE_DIR "/usr/include"
45 #ifndef LOCAL_INCLUDE_DIR
46 #define LOCAL_INCLUDE_DIR "/usr/local/include"
49 #if 0 /* We can't get ptrdiff_t, so I arranged not to need PTR_INT_TYPE. */
51 #define PTR_INT_TYPE ptrdiff_t
53 #define PTR_INT_TYPE long
64 /* By default, colon separates directories in a path. */
65 #ifndef PATH_SEPARATOR
66 #define PATH_SEPARATOR ':'
78 #include <sys/time.h> /* for __DATE__ and __TIME__ */
79 #include <sys/resource.h>
81 #include <sys/param.h> /* CYGNUS LOCAL: shebs -noquiet */
82 #include <sys/times.h>
88 /* This defines "errno" properly for VMS, and gives us EACCES. */
91 extern char *index ();
92 extern char *rindex ();
100 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
101 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
103 /* Find the largest host integer type and set its size and type. */
105 #ifndef HOST_BITS_PER_WIDE_INT
107 #if HOST_BITS_PER_LONG > HOST_BITS_PER_INT
108 #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG
109 #define HOST_WIDE_INT long
111 #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT
112 #define HOST_WIDE_INT int
118 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
122 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
125 /* Define a generic NULL if one hasn't already been defined. */
132 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
133 #define GENERIC_PTR void *
135 #define GENERIC_PTR char *
140 #define NULL_PTR ((GENERIC_PTR)0)
143 #ifndef INCLUDE_LEN_FUDGE
144 #define INCLUDE_LEN_FUDGE 0
147 /* Symbols to predefine. */
149 #ifdef CPP_PREDEFINES
150 static char *predefs = CPP_PREDEFINES;
152 static char *predefs = "";
155 /* We let tm.h override the types used here, to handle trivial differences
156 such as the choice of unsigned int or long unsigned int for size_t.
157 When machines start needing nontrivial differences in the size type,
158 it would be best to do something here to figure out automatically
159 from other information what type to use. */
161 /* The string value for __SIZE_TYPE__. */
164 #define SIZE_TYPE "long unsigned int"
167 /* The string value for __PTRDIFF_TYPE__. */
170 #define PTRDIFF_TYPE "long int"
173 /* The string value for __WCHAR_TYPE__. */
176 #define WCHAR_TYPE "int"
178 #define CPP_WCHAR_TYPE(PFILE) \
179 (CPP_OPTIONS (PFILE)->cplusplus ? "__wchar_t" : WCHAR_TYPE)
181 /* The string value for __USER_LABEL_PREFIX__ */
183 #ifndef USER_LABEL_PREFIX
184 #define USER_LABEL_PREFIX ""
187 /* The string value for __REGISTER_PREFIX__ */
189 #ifndef REGISTER_PREFIX
190 #define REGISTER_PREFIX ""
193 /* In the definition of a #assert name, this structure forms
194 a list of the individual values asserted.
195 Each value is itself a list of "tokens".
196 These are strings that are compared by name. */
198 struct tokenlist_list {
199 struct tokenlist_list *next;
200 struct arglist *tokens;
203 struct assertion_hashnode {
204 struct assertion_hashnode *next; /* double links for easy deletion */
205 struct assertion_hashnode *prev;
206 /* also, a back pointer to this node's hash
207 chain is kept, in case the node is the head
208 of the chain and gets deleted. */
209 struct assertion_hashnode **bucket_hdr;
210 int length; /* length of token, for quick comparison */
211 U_CHAR *name; /* the actual name */
212 /* List of token-sequences. */
213 struct tokenlist_list *value;
216 #define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
217 #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
219 #define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? CPP_BUFFER (pfile)->cur[N] : EOF)
220 #define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N))
221 #define GETC() CPP_BUF_GET (CPP_BUFFER (pfile))
222 #define PEEKC() CPP_BUF_PEEK (CPP_BUFFER (pfile))
223 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
224 (Note that it is false while we're expanding marco *arguments*.) */
225 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->cleanup == macro_cleanup)
227 /* Move all backslash-newline pairs out of embarrassing places.
228 Exchange all such pairs following BP
229 with any potentially-embarrassing characters that follow them.
230 Potentially-embarrassing characters are / and *
231 (because a backslash-newline inside a comment delimiter
232 would cause it not to be recognized). */
234 #define NEWLINE_FIX \
235 do {while (PEEKC() == '\\' && PEEKN(1) == '\n') FORWARD(2); } while(0)
237 /* Same, but assume we've already read the potential '\\' into C. */
238 #define NEWLINE_FIX1(C) do { \
239 while ((C) == '\\' && PEEKC() == '\n') { FORWARD(1); (C) = GETC(); }\
243 struct cpp_pending *next;
248 /* Forward declarations. */
250 extern char *xmalloc ();
252 static void add_import ();
253 static void append_include_chain ();
254 static void make_undef ();
255 static void make_assertion ();
256 static void path_include ();
257 static void initialize_builtins ();
258 static void initialize_char_syntax ();
259 static void dump_arg_n ();
260 static void dump_defn_1 ();
261 extern void delete_macro ();
262 static void trigraph_pcp ();
263 static int finclude ();
264 static void validate_else ();
265 static int comp_def_part ();
266 extern void fancy_abort ();
267 static void pipe_closed ();
268 static void print_containing_files ();
269 static int lookup_import ();
270 static int redundant_include_p ();
271 static is_system_include ();
272 static struct file_name_map *read_name_map ();
273 static char *read_filename_string ();
274 static int open_include_file ();
275 static int check_preconditions ();
276 static void pcfinclude ();
277 static void pcstring_used ();
278 static int check_macro_name ();
279 static int compare_defs ();
280 static int compare_token_lists ();
281 static HOST_WIDE_INT eval_if_expression ();
282 static int change_newlines ();
284 static int file_size_and_mode ();
285 static struct arglist *read_token_list ();
286 static void free_token_list ();
287 static int safe_read ();
288 static void push_macro_expansion PARAMS ((cpp_reader *,
289 U_CHAR*, int, HASHNODE*));
290 static struct cpp_pending *nreverse_pending PARAMS ((struct cpp_pending*));
291 extern char *xrealloc ();
292 extern char *xcalloc ();
293 static char *savestring ();
295 static void conditional_skip ();
296 static void skip_if_group ();
298 /* Last arg to output_line_command. */
299 enum file_change_code {same_file, enter_file, leave_file};
301 /* External declarations. */
303 extern HOST_WIDE_INT cpp_parse_expr PARAMS ((cpp_reader*));
305 extern char *getenv ();
306 extern FILE *fdopen ();
307 extern char *version_string;
308 extern struct tm *localtime ();
310 /* These functions are declared to return int instead of void since they
311 are going to be placed in a table and some old compilers have trouble with
312 pointers to functions returning void. */
314 static int do_define ();
315 static int do_line ();
316 static int do_include ();
317 static int do_undef ();
318 static int do_error ();
319 static int do_pragma ();
320 static int do_ident ();
322 static int do_xifdef ();
323 static int do_else ();
324 static int do_elif ();
325 static int do_endif ();
326 static int do_sccs ();
327 static int do_once ();
328 static int do_assert ();
329 static int do_unassert ();
330 static int do_warning ();
332 struct file_name_list
334 struct file_name_list *next;
336 /* If the following is nonzero, it is a macro name.
337 Don't include the file again if that macro is defined. */
338 U_CHAR *control_macro;
339 /* If the following is nonzero, it is a C-language system include
341 int c_system_include_path;
342 /* Mapping of file names for this directory. */
343 struct file_name_map *name_map;
344 /* Non-zero if name_map is valid. */
348 /* If a buffer's dir field is SELF_DIR_DUMMY, it means the file was found
349 via the same directory as the file that #included it. */
350 #define SELF_DIR_DUMMY ((struct file_name_list*)(~0))
352 /* #include "file" looks in source file dir, then stack. */
353 /* #include <file> just looks in the stack. */
354 /* -I directories are added to the end, then the defaults are added. */
356 static struct default_include {
357 char *fname; /* The name of the directory. */
358 int cplusplus; /* Only look here if we're compiling C++. */
359 int cxx_aware; /* Includes in this directory don't need to
360 be wrapped in extern "C" when compiling
362 } include_defaults_array[]
363 #ifdef INCLUDE_DEFAULTS
367 /* Pick up GNU C++ specific include files. */
368 { GPLUSPLUS_INCLUDE_DIR, 1, 1 },
370 /* This is the dir for fixincludes. Put it just before
371 the files that we fix. */
372 { GCC_INCLUDE_DIR, 0, 0 },
373 /* For cross-compilation, this dir name is generated
374 automatically in Makefile.in. */
375 { CROSS_INCLUDE_DIR, 0, 0 },
376 /* This is another place that the target system's headers might be. */
377 { TOOL_INCLUDE_DIR, 0, 1 },
378 #else /* not CROSS_COMPILE */
379 /* This should be /usr/local/include and should come before
380 the fixincludes-fixed header files. */
381 { LOCAL_INCLUDE_DIR, 0, 1 },
382 /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
383 Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
384 { TOOL_INCLUDE_DIR, 0, 1 },
385 /* This is the dir for fixincludes. Put it just before
386 the files that we fix. */
387 { GCC_INCLUDE_DIR, 0, 0 },
388 /* Some systems have an extra dir of include files. */
389 #ifdef SYSTEM_INCLUDE_DIR
390 { SYSTEM_INCLUDE_DIR, 0, 0 },
392 { STANDARD_INCLUDE_DIR, 0, 0 },
393 #endif /* not CROSS_COMPILE */
396 #endif /* no INCLUDE_DEFAULTS */
398 /* `struct directive' defines one #-directive, including how to handle it. */
401 int length; /* Length of name */
402 int (*func)(); /* Function to handle directive */
403 char *name; /* Name of directive */
404 enum node_type type; /* Code which describes which directive. */
405 char command_reads_line; /* One if rest of line is read by func. */
406 char traditional_comments; /* Nonzero: keep comments if -traditional. */
407 char pass_thru; /* Copy preprocessed directive to output file.*/
410 /* Here is the actual list of #-directives, most-often-used first.
411 The initialize_builtins function assumes #define is the very first. */
413 static struct directive directive_table[] = {
414 { 6, do_define, "define", T_DEFINE, 0, 1},
415 { 5, do_xifdef, "ifdef", T_IFDEF, 1},
416 { 6, do_xifdef, "ifndef", T_IFNDEF, 1},
417 { 7, do_include, "include", T_INCLUDE, 1},
418 { 12, do_include, "include_next", T_INCLUDE_NEXT, 1},
419 { 6, do_include, "import", T_IMPORT, 1},
420 { 5, do_endif, "endif", T_ENDIF, 1},
421 { 4, do_else, "else", T_ELSE, 1},
422 { 2, do_if, "if", T_IF, 1},
423 { 4, do_elif, "elif", T_ELIF, 1},
424 { 5, do_undef, "undef", T_UNDEF},
425 { 5, do_error, "error", T_ERROR},
426 { 7, do_warning, "warning", T_WARNING},
427 { 6, do_pragma, "pragma", T_PRAGMA, 0, 0, 1},
428 { 4, do_line, "line", T_LINE, 1},
429 { 5, do_ident, "ident", T_IDENT, 1, 0, 1},
430 #ifdef SCCS_DIRECTIVE
431 { 4, do_sccs, "sccs", T_SCCS},
433 { 6, do_assert, "assert", T_ASSERT, 1},
434 { 8, do_unassert, "unassert", T_UNASSERT, 1},
435 { -1, 0, "", T_UNUSED},
438 /* table to tell if char can be part of a C identifier. */
439 U_CHAR is_idchar[256];
440 /* table to tell if char can be first char of a c identifier. */
441 U_CHAR is_idstart[256];
442 /* table to tell if c is horizontal space. */
443 U_CHAR is_hor_space[256];
444 /* table to tell if c is horizontal or vertical space. */
445 static U_CHAR is_space[256];
447 /* Initialize syntactic classifications of characters. */
450 initialize_char_syntax (opts)
451 struct cpp_options *opts;
456 * Set up is_idchar and is_idstart tables. These should be
457 * faster than saying (is_alpha (c) || c == '_'), etc.
458 * Set up these things before calling any routines tthat
461 for (i = 'a'; i <= 'z'; i++) {
462 is_idchar[i - 'a' + 'A'] = 1;
464 is_idstart[i - 'a' + 'A'] = 1;
467 for (i = '0'; i <= '9'; i++)
471 is_idchar['$'] = opts->dollars_in_ident;
472 is_idstart['$'] = opts->dollars_in_ident;
474 /* horizontal space table */
475 is_hor_space[' '] = 1;
476 is_hor_space['\t'] = 1;
477 is_hor_space['\v'] = 1;
478 is_hor_space['\f'] = 1;
479 is_hor_space['\r'] = 1;
490 /* Place into PFILE a quoted string representing the string SRC.
491 Caller must reserve enough space in pfile->token_buffer. */
493 quote_string (pfile, src)
499 CPP_PUTC_Q (pfile, '\"');
501 switch ((c = *src++))
505 CPP_PUTC_Q (pfile, c);
508 sprintf (CPP_PWRITTEN (pfile), "\\%03o", c);
509 CPP_ADJUST_WRITTEN (pfile, 4);
515 CPP_PUTC_Q (pfile, '\\');
516 CPP_PUTC_Q (pfile, c);
520 CPP_PUTC_Q (pfile, '\"');
521 CPP_NUL_TERMINATE_Q (pfile);
526 /* Make sure PFILE->token_buffer will hold at least N more chars. */
529 cpp_grow_buffer (pfile, n)
533 long old_written = CPP_WRITTEN (pfile);
534 pfile->token_buffer_size = n + 2 * pfile->token_buffer_size;
535 pfile->token_buffer = (U_CHAR*)
536 xrealloc(pfile->token_buffer, pfile->token_buffer_size);
537 CPP_SET_WRITTEN (pfile, old_written);
542 * process a given definition string, for initialization
543 * If STR is just an identifier, define it with value 1.
544 * If STR has anything after the identifier, then it should
545 * be identifier=definition.
549 cpp_define (pfile, str)
559 cpp_error (pfile, "malformed option `-D %s'", str);
562 while (is_idchar[*++p])
566 buf = (U_CHAR *) alloca (p - buf + 4);
567 strcpy ((char *)buf, str);
568 strcat ((char *)buf, " 1");
572 cpp_error (pfile, "malformed option `-D %s'", str);
578 /* Copy the entire option so we can modify it. */
579 buf = (U_CHAR *) alloca (2 * strlen (str) + 1);
580 strncpy (buf, str, p - str);
581 /* Change the = to a space. */
583 /* Scan for any backslash-newline and remove it. */
588 if (*p == '\\' && p[1] == '\n')
596 do_define (pfile, NULL, buf, buf + strlen (buf));
599 /* Process the string STR as if it appeared as the body of a #assert.
600 OPTION is the option name for which STR was the argument. */
603 make_assertion (pfile, option, str)
609 struct directive *kt;
612 /* Copy the entire option so we can modify it. */
613 buf = (U_CHAR *) alloca (strlen (str) + 1);
614 strcpy ((char *) buf, str);
615 /* Scan for any backslash-newline and remove it. */
619 if (*p == '\\' && p[1] == '\n')
628 if (!is_idstart[*p]) {
629 cpp_error (pfile, "malformed option `%s %s'", option, str);
632 while (is_idchar[*++p])
634 while (*p == ' ' || *p == '\t') p++;
635 if (! (*p == 0 || *p == '(')) {
636 cpp_error (pfile, "malformed option `%s %s'", option, str);
640 ip = cpp_push_buffer (pfile, buf, strlen (buf));
641 do_assert (pfile, NULL, NULL, NULL);
642 cpp_pop_buffer (pfile);
645 /* Append a chain of `struct file_name_list's
646 to the end of the main include chain.
647 FIRST is the beginning of the chain to append, and LAST is the end. */
650 append_include_chain (pfile, first, last)
652 struct file_name_list *first, *last;
654 struct cpp_options *opts = CPP_OPTIONS (pfile);
655 struct file_name_list *dir;
660 if (opts->include == 0)
661 opts->include = first;
663 opts->last_include->next = first;
665 if (opts->first_bracket_include == 0)
666 opts->first_bracket_include = first;
668 for (dir = first; ; dir = dir->next) {
669 int len = strlen (dir->fname) + INCLUDE_LEN_FUDGE;
670 if (len > pfile->max_include_len)
671 pfile->max_include_len = len;
677 opts->last_include = last;
680 /* Add output to `deps_buffer' for the -M switch.
681 STRING points to the text to be output.
682 SPACER is ':' for targets, ' ' for dependencies, zero for text
683 to be inserted literally. */
686 deps_output (pfile, string, spacer)
691 int size = strlen (string);
696 #ifndef MAX_OUTPUT_COLUMNS
697 #define MAX_OUTPUT_COLUMNS 72
700 && pfile->deps_column > 0
701 && (pfile->deps_column + size) > MAX_OUTPUT_COLUMNS)
703 deps_output (pfile, " \\\n ", 0);
704 pfile->deps_column = 0;
707 if (pfile->deps_size + size + 8 > pfile->deps_allocated_size)
709 pfile->deps_allocated_size = (pfile->deps_size + size + 50) * 2;
710 pfile->deps_buffer = (char *) xrealloc (pfile->deps_buffer,
711 pfile->deps_allocated_size);
713 if (spacer == ' ' && pfile->deps_column > 0)
714 pfile->deps_buffer[pfile->deps_size++] = ' ';
715 bcopy (string, &pfile->deps_buffer[pfile->deps_size], size);
716 pfile->deps_size += size;
717 pfile->deps_column += size;
719 pfile->deps_buffer[pfile->deps_size++] = ':';
720 pfile->deps_buffer[pfile->deps_size] = 0;
723 /* Given a colon-separated list of file names PATH,
724 add all the names to the search path for include files. */
727 path_include (pfile, path)
739 struct file_name_list *dirtmp;
741 /* Find the end of this name. */
742 while (*q != 0 && *q != PATH_SEPARATOR) q++;
744 /* An empty name in the path stands for the current directory. */
745 name = (char *) xmalloc (2);
749 /* Otherwise use the directory that is named. */
750 name = (char *) xmalloc (q - p + 1);
751 bcopy (p, name, q - p);
755 dirtmp = (struct file_name_list *)
756 xmalloc (sizeof (struct file_name_list));
757 dirtmp->next = 0; /* New one goes on the end */
758 dirtmp->control_macro = 0;
759 dirtmp->c_system_include_path = 0;
760 dirtmp->fname = name;
761 dirtmp->got_name_map = 0;
762 append_include_chain (pfile, dirtmp, dirtmp);
764 /* Advance past this name. */
768 /* Skip the colon. */
774 init_parse_options (opts)
775 struct cpp_options *opts;
777 bzero ((char *) opts, sizeof *opts);
778 opts->in_fname = NULL;
779 opts->out_fname = NULL;
781 /* Initialize is_idchar to allow $. */
782 opts->dollars_in_ident = 1;
783 initialize_char_syntax (opts);
784 opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 0;
786 opts->no_line_commands = 0;
787 opts->no_trigraphs = 1;
788 opts->put_out_comments = 0;
789 opts->print_include_names = 0;
790 opts->dump_macros = dump_none;
793 opts->cplusplus_comments = 0;
800 opts->pedantic_errors = 0;
801 opts->inhibit_warnings = 0;
802 opts->warn_comments = 0;
803 opts->warn_import = 1;
804 opts->warnings_are_errors = 0;
808 null_underflow (pfile)
815 null_cleanup (pbuf, pfile)
823 macro_cleanup (pbuf, pfile)
827 HASHNODE *macro = (HASHNODE*)pbuf->data;
828 if (macro->type == T_DISABLED)
829 macro->type = T_MACRO;
830 if (macro->type != T_MACRO || pbuf->buf != macro->value.defn->expansion)
836 file_cleanup (pbuf, pfile)
855 register U_CHAR *p = bp;
857 /* First count the backslash-newline pairs here. */
859 while (p[0] == '\\' && p[1] == '\n')
862 /* What follows the backslash-newlines is not embarrassing. */
864 if (*p != '/' && *p != '*')
867 /* Copy all potentially embarrassing characters
868 that follow the backslash-newline pairs
869 down to where the pairs originally started. */
871 while (*p == '*' || *p == '/')
874 /* Now write the same number of pairs after the embarrassing chars. */
882 /* Assuming we have read '/'.
883 If this is the start of a comment (followed by '*' or '/'),
884 skip to the end of the comment, and return ' '.
885 Return EOF if we reached the end of file before the end of the comment.
886 If not the start of a comment, return '/'. */
889 skip_comment (pfile, linep)
894 while (PEEKC() == '\\' && PEEKN(1) == '\n')
909 while (c == '\\' && PEEKC() == '\n')
913 FORWARD(1), c = GETC();
915 if (prev_c == '*' && c == '/')
917 if (c == '\n' && linep)
921 else if (PEEKC() == '/' && CPP_OPTIONS (pfile)->cplusplus_comments)
928 return ' '; /* Allow // to be terminated by EOF. */
929 while (c == '\\' && PEEKC() == '\n')
938 /* Don't consider final '\n' to be part of comment. */
948 /* Skip whitespace \-newline and comments. Does not macro-expand. */
950 cpp_skip_hspace (pfile)
960 if ((c == '\f' || c == '\v') && CPP_PEDANTIC (pfile))
961 cpp_pedwarn (pfile, "%s in preprocessing directive",
962 c == '\f' ? "formfeed" : "vertical tab");
968 c = skip_comment (pfile, NULL);
971 if (c == EOF || c == '/')
974 else if (c == '\\' && PEEKN(1) == '\n') {
977 else if (c == '@' && CPP_BUFFER (pfile)->has_escapes
978 && is_hor_space[PEEKN(1)])
984 /* Read the rest of the current line.
985 The line is appended to PFILE's output buffer. */
988 copy_rest_of_line (pfile)
991 struct cpp_options *opts = CPP_OPTIONS (pfile);
1001 if (PEEKC() == '\n')
1008 goto scan_directive_token;
1012 if (nextc == '*' || (opts->cplusplus_comments && nextc == '*'))
1013 goto scan_directive_token;
1017 if (CPP_PEDANTIC (pfile))
1018 cpp_pedwarn (pfile, "%s in preprocessing directive",
1019 c == '\f' ? "formfeed" : "vertical tab");
1025 scan_directive_token:
1027 cpp_get_token (pfile);
1030 CPP_PUTC (pfile, c);
1033 CPP_NUL_TERMINATE (pfile);
1037 skip_rest_of_line (pfile)
1040 long old = CPP_WRITTEN (pfile);
1041 copy_rest_of_line (pfile);
1042 CPP_SET_WRITTEN (pfile, old);
1045 /* Handle a possible # directive.
1046 '#' has already been read. */
1049 handle_directive (pfile)
1052 register struct directive *kt;
1055 U_CHAR *ident, *line_end;
1056 long old_written = CPP_WRITTEN (pfile);
1058 cpp_skip_hspace (pfile);
1061 if (c >= '0' && c <= '9')
1063 /* Handle # followed by a line number. */
1064 if (CPP_PEDANTIC (pfile))
1065 cpp_pedwarn (pfile, "`#' followed by integer");
1066 do_line (pfile, NULL);
1067 goto done_a_directive;
1070 /* Now find the directive name. */
1071 CPP_PUTC (pfile, '#');
1072 parse_name (pfile, GETC());
1073 ident = pfile->token_buffer + old_written + 1;
1074 ident_length = CPP_PWRITTEN (pfile) - ident;
1075 if (ident_length == 0 && PEEKC() == '\n')
1077 /* A line of just `#' becomes blank. */
1078 goto done_a_directive;
1082 if (ident_length == 0 || !is_idstart[*ident]) {
1084 while (is_idchar[*p]) {
1085 if (*p < '0' || *p > '9')
1089 /* Avoid error for `###' and similar cases unless -pedantic. */
1091 while (*p == '#' || is_hor_space[*p]) p++;
1093 if (pedantic && !lang_asm)
1094 cpp_warning (pfile, "invalid preprocessor directive");
1100 cpp_error (pfile, "invalid preprocessor directive name");
1106 * Decode the keyword and call the appropriate expansion
1107 * routine, after moving the input pointer up to the next line.
1109 for (kt = directive_table; ; kt++) {
1110 if (kt->length <= 0)
1111 goto not_a_directive;
1112 if (kt->length == ident_length && !strncmp (kt->name, ident, ident_length))
1116 if (! kt->command_reads_line)
1118 /* Nonzero means do not delete comments within the directive.
1119 #define needs this when -traditional. */
1120 int comments = CPP_TRADITIONAL (pfile) && kt->traditional_comments;
1121 int save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
1122 CPP_OPTIONS (pfile)->put_out_comments = comments;
1123 after_ident = CPP_WRITTEN (pfile);
1124 copy_rest_of_line (pfile);
1125 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
1128 /* For #pragma and #define, we may want to pass through the directive.
1129 Other directives may create output, but we don't want the directive
1130 itself out, so we pop it now. For example #include may write a #line
1131 command (see comment in do_include), and conditionals may emit
1132 #failed ... #endfailed stuff. But note that popping the buffer
1133 means the parameters to kt->func may point after pfile->limit
1134 so these parameters are invalid as soon as something gets appended
1135 to the token_buffer. */
1137 line_end = CPP_PWRITTEN (pfile);
1138 if (!kt->pass_thru && kt->type != T_DEFINE)
1139 CPP_SET_WRITTEN (pfile, old_written);
1141 (*kt->func) (pfile, kt, pfile->token_buffer + after_ident, line_end);
1143 || (kt->type == T_DEFINE
1144 && CPP_OPTIONS (pfile)->dump_macros == dump_definitions))
1146 /* Just leave the entire #define in the output stack. */
1148 else if (kt->type == T_DEFINE
1149 && CPP_OPTIONS (pfile)->dump_macros == dump_names)
1151 U_CHAR *p = pfile->token_buffer + old_written + 7; /* Skip "#define". */
1152 SKIP_WHITE_SPACE (p);
1153 while (is_idchar[*p]) p++;
1155 CPP_PUTC (pfile, '\n');
1157 else if (kt->type == T_DEFINE)
1158 CPP_SET_WRITTEN (pfile, old_written);
1166 /* Pass a directive through to the output file.
1167 BUF points to the contents of the directive, as a contiguous string.
1168 LIMIT points to the first character past the end of the directive.
1169 KEYWORD is the keyword-table entry for the directive. */
1172 pass_thru_directive (buf, limit, pfile, keyword)
1173 U_CHAR *buf, *limit;
1175 struct directive *keyword;
1177 register unsigned keyword_length = keyword->length;
1179 CPP_RESERVE (pfile, 1 + keyword_length + (limit - buf));
1180 CPP_PUTC_Q (pfile, '#');
1181 CPP_PUTS_Q (pfile, keyword->name, keyword_length);
1182 if (limit != buf && buf[0] != ' ')
1183 CPP_PUTC_Q (pfile, ' ');
1184 CPP_PUTS_Q (pfile, buf, limit - buf);
1186 CPP_PUTS_Q (pfile, '\n');
1187 /* Count the line we have just made in the output,
1188 to get in sync properly. */
1193 /* The arglist structure is built by do_define to tell
1194 collect_definition where the argument names begin. That
1195 is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist
1196 would contain pointers to the strings x, y, and z.
1197 Collect_definition would then build a DEFINITION node,
1198 with reflist nodes pointing to the places x, y, and z had
1199 appeared. So the arglist is just convenience data passed
1200 between these two routines. It is not kept around after
1201 the current #define has been processed and entered into the
1205 struct arglist *next;
1212 /* Read a replacement list for a macro with parameters.
1213 Build the DEFINITION structure.
1214 Reads characters of text starting at BUF until END.
1215 ARGLIST specifies the formal parameters to look for
1216 in the text of the definition; NARGS is the number of args
1217 in that list, or -1 for a macro name that wants no argument list.
1218 MACRONAME is the macro name itself (so we can avoid recursive expansion)
1219 and NAMELEN is its length in characters.
1221 Note that comments, backslash-newlines, and leading white space
1222 have already been deleted from the argument. */
1225 collect_expansion (pfile, buf, limit, nargs, arglist)
1227 U_CHAR *buf, *limit;
1229 struct arglist *arglist;
1232 register U_CHAR *p, *lastp, *exp_p;
1233 struct reflist *endpat = NULL;
1234 /* Pointer to first nonspace after last ## seen. */
1236 /* Pointer to first nonspace after last single-# seen. */
1237 U_CHAR *stringify = 0;
1239 int expected_delimiter = '\0';
1241 /* Scan thru the replacement list, ignoring comments and quoted
1242 strings, picking up on the macro calls. It does a linear search
1243 thru the arg list on every potential symbol. Profiling might say
1244 that something smarter should happen. */
1249 /* Find the beginning of the trailing whitespace. */
1251 while (p < limit && is_space[limit[-1]]) limit--;
1253 /* Allocate space for the text in the macro definition.
1254 Leading and trailing whitespace chars need 2 bytes each.
1255 Each other input char may or may not need 1 byte,
1256 so this is an upper bound. The extra 5 are for invented
1257 leading and trailing newline-marker and final null. */
1258 maxsize = (sizeof (DEFINITION)
1260 /* Occurrences of '@' get doubled, so allocate extra space for them. */
1264 defn = (DEFINITION *) xcalloc (1, maxsize);
1266 defn->nargs = nargs;
1267 exp_p = defn->expansion = (U_CHAR *) defn + sizeof (DEFINITION);
1272 /* Add one initial space escape-marker to prevent accidental
1273 token-pasting (often removed by macroexpand). */
1277 if (limit - p >= 2 && p[0] == '#' && p[1] == '#') {
1278 cpp_error (pfile, "`##' at start of macro definition");
1282 /* Process the main body of the definition. */
1284 int skipped_arg = 0;
1285 register U_CHAR c = *p++;
1289 if (!CPP_TRADITIONAL (pfile)) {
1293 if (expected_delimiter != '\0') {
1294 if (c == expected_delimiter)
1295 expected_delimiter = '\0';
1297 expected_delimiter = c;
1301 if (p < limit && expected_delimiter) {
1302 /* In a string, backslash goes through
1303 and makes next char ordinary. */
1309 /* An '@' in a string or character constant stands for itself,
1310 and does not need to be escaped. */
1311 if (!expected_delimiter)
1316 /* # is ordinary inside a string. */
1317 if (expected_delimiter)
1319 if (p < limit && *p == '#') {
1320 /* ##: concatenate preceding and following tokens. */
1321 /* Take out the first #, discard preceding whitespace. */
1323 while (exp_p > lastp && is_hor_space[exp_p[-1]])
1325 /* Skip the second #. */
1327 /* Discard following whitespace. */
1328 SKIP_WHITE_SPACE (p);
1331 cpp_error (pfile, "`##' at end of macro definition");
1332 } else if (nargs >= 0) {
1333 /* Single #: stringify following argument ref.
1334 Don't leave the # in the expansion. */
1336 SKIP_WHITE_SPACE (p);
1337 if (p == limit || ! is_idstart[*p])
1339 "`#' operator is not followed by a macro argument name");
1346 /* In -traditional mode, recognize arguments inside strings and
1347 and character constants, and ignore special properties of #.
1348 Arguments inside strings are considered "stringified", but no
1349 extra quote marks are supplied. */
1353 if (expected_delimiter != '\0') {
1354 if (c == expected_delimiter)
1355 expected_delimiter = '\0';
1357 expected_delimiter = c;
1361 /* Backslash quotes delimiters and itself, but not macro args. */
1362 if (expected_delimiter != 0 && p < limit
1363 && (*p == expected_delimiter || *p == '\\')) {
1370 if (expected_delimiter != '\0') /* No comments inside strings. */
1373 /* If we find a comment that wasn't removed by handle_directive,
1374 this must be -traditional. So replace the comment with
1378 while (p < limit && !(p[-2] == '*' && p[-1] == '/'))
1381 /* Mark this as a concatenation-point, as if it had been ##. */
1389 /* Handle the start of a symbol. */
1390 if (is_idchar[c] && nargs > 0) {
1391 U_CHAR *id_beg = p - 1;
1395 while (p != limit && is_idchar[*p]) p++;
1396 id_len = p - id_beg;
1398 if (is_idstart[c]) {
1399 register struct arglist *arg;
1401 for (arg = arglist; arg != NULL; arg = arg->next) {
1402 struct reflist *tpat;
1404 if (arg->name[0] == c
1405 && arg->length == id_len
1406 && strncmp (arg->name, id_beg, id_len) == 0) {
1407 if (expected_delimiter && CPP_OPTIONS (pfile)->warn_stringify) {
1408 if (CPP_TRADITIONAL (pfile)) {
1409 cpp_warning (pfile, "macro argument `%.*s' is stringified.",
1413 "macro arg `%.*s' would be stringified with -traditional.",
1417 /* If ANSI, don't actually substitute inside a string. */
1418 if (!CPP_TRADITIONAL (pfile) && expected_delimiter)
1420 /* make a pat node for this arg and append it to the end of
1422 tpat = (struct reflist *) xmalloc (sizeof (struct reflist));
1424 tpat->raw_before = concat == id_beg;
1425 tpat->raw_after = 0;
1426 tpat->rest_args = arg->rest_args;
1427 tpat->stringify = (CPP_TRADITIONAL (pfile)
1428 ? expected_delimiter != '\0'
1429 : stringify == id_beg);
1432 defn->pattern = tpat;
1434 endpat->next = tpat;
1437 tpat->argno = arg->argno;
1438 tpat->nchars = exp_p - lastp;
1440 register U_CHAR *p1 = p;
1441 SKIP_WHITE_SPACE (p1);
1442 if (p1 + 2 <= limit && p1[0] == '#' && p1[1] == '#')
1443 tpat->raw_after = 1;
1445 lastp = exp_p; /* place to start copying from next time */
1452 /* If this was not a macro arg, copy it into the expansion. */
1453 if (! skipped_arg) {
1454 register U_CHAR *lim1 = p;
1458 if (stringify == id_beg)
1460 "`#' operator should be followed by a macro argument name");
1465 if (!CPP_TRADITIONAL (pfile) && expected_delimiter == 0)
1467 /* If ANSI, put in a "@ " marker to prevent token pasting.
1468 But not if "inside a string" (which in ANSI mode
1469 happens only for -D option). */
1476 defn->length = exp_p - defn->expansion;
1478 /* Crash now if we overrun the allocated size. */
1479 if (defn->length + 1 > maxsize)
1483 /* This isn't worth the time it takes. */
1484 /* give back excess storage */
1485 defn->expansion = (U_CHAR *) xrealloc (defn->expansion, defn->length + 1);
1492 * special extension string that can be added to the last macro argument to
1493 * allow it to absorb the "rest" of the arguments when expanded. Ex:
1494 * #define wow(a, b...) process (b, a, b)
1495 * { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); }
1496 * { wow (one, two); } -> { process (two, one, two); }
1497 * if this "rest_arg" is used with the concat token '##' and if it is not
1498 * supplied then the token attached to with ## will not be outputted. Ex:
1499 * #define wow (a, b...) process (b ## , a, ## b)
1500 * { wow (1, 2); } -> { process (2, 1, 2); }
1501 * { wow (one); } -> { process (one); {
1503 static char rest_extension[] = "...";
1504 #define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1)
1506 /* Create a DEFINITION node from a #define directive. Arguments are
1507 as for do_define. */
1509 create_definition (buf, limit, pfile, predefinition)
1510 U_CHAR *buf, *limit;
1514 U_CHAR *bp; /* temp ptr into input buffer */
1515 U_CHAR *symname; /* remember where symbol name starts */
1516 int sym_length; /* and how long it is */
1519 char *file = CPP_BUFFER (pfile) ? CPP_BUFFER (pfile)->nominal_fname : "";
1521 int arglengths = 0; /* Accumulate lengths of arg names
1522 plus number of args. */
1524 cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col);
1528 while (is_hor_space[*bp])
1531 symname = bp; /* remember where it starts */
1533 sym_length = check_macro_name (pfile, bp, "macro");
1536 /* Lossage will occur if identifiers or control keywords are broken
1537 across lines using backslash. This is not the right place to take
1541 struct arglist *arg_ptrs = NULL;
1544 bp++; /* skip '(' */
1545 SKIP_WHITE_SPACE (bp);
1547 /* Loop over macro argument names. */
1548 while (*bp != ')') {
1549 struct arglist *temp;
1551 temp = (struct arglist *) alloca (sizeof (struct arglist));
1553 temp->next = arg_ptrs;
1554 temp->argno = argno++;
1555 temp->rest_args = 0;
1559 cpp_pedwarn (pfile, "another parameter follows `%s'", rest_extension);
1561 if (!is_idstart[*bp])
1562 cpp_pedwarn (pfile, "invalid character in macro parameter name");
1564 /* Find the end of the arg name. */
1565 while (is_idchar[*bp]) {
1567 /* do we have a "special" rest-args extension here? */
1568 if (limit - bp > REST_EXTENSION_LENGTH &&
1569 strncmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
1571 temp->rest_args = 1;
1575 temp->length = bp - temp->name;
1577 bp += REST_EXTENSION_LENGTH;
1578 arglengths += temp->length + 2;
1579 SKIP_WHITE_SPACE (bp);
1580 if (temp->length == 0 || (*bp != ',' && *bp != ')')) {
1581 cpp_error (pfile, "badly punctuated parameter list in `#define'");
1586 SKIP_WHITE_SPACE (bp);
1589 cpp_error (pfile, "unterminated parameter list in `#define'");
1593 struct arglist *otemp;
1595 for (otemp = temp->next; otemp != NULL; otemp = otemp->next)
1596 if (temp->length == otemp->length &&
1597 strncmp (temp->name, otemp->name, temp->length) == 0) {
1600 name = (U_CHAR *) alloca (temp->length + 1);
1601 (void) strncpy (name, temp->name, temp->length);
1602 name[temp->length] = '\0';
1604 "duplicate argument name `%s' in `#define'", name);
1610 ++bp; /* skip paren */
1611 SKIP_WHITE_SPACE (bp);
1612 /* now everything from bp before limit is the definition. */
1613 defn = collect_expansion (pfile, bp, limit, argno, arg_ptrs);
1614 defn->rest_args = rest_args;
1616 /* Now set defn->args.argnames to the result of concatenating
1617 the argument names in reverse order
1618 with comma-space between them. */
1619 defn->args.argnames = (U_CHAR *) xmalloc (arglengths + 1);
1621 struct arglist *temp;
1623 for (temp = arg_ptrs; temp; temp = temp->next) {
1624 bcopy (temp->name, &defn->args.argnames[i], temp->length);
1626 if (temp->next != 0) {
1627 defn->args.argnames[i++] = ',';
1628 defn->args.argnames[i++] = ' ';
1631 defn->args.argnames[i] = 0;
1634 /* Simple expansion or empty definition. */
1638 if (is_hor_space[*bp]) {
1640 SKIP_WHITE_SPACE (bp);
1643 case '!': case '"': case '#': case '%': case '&': case '\'':
1644 case ')': case '*': case '+': case ',': case '-': case '.':
1645 case '/': case ':': case ';': case '<': case '=': case '>':
1646 case '?': case '[': case '\\': case ']': case '^': case '{':
1647 case '|': case '}': case '~':
1648 cpp_warning (pfile, "missing white space after `#define %.*s'",
1649 sym_length, symname);
1653 cpp_pedwarn (pfile, "missing white space after `#define %.*s'",
1654 sym_length, symname);
1659 /* now everything from bp before limit is the definition. */
1660 defn = collect_expansion (pfile, bp, limit, -1, NULL_PTR);
1661 defn->args.argnames = (U_CHAR *) "";
1667 /* OP is null if this is a predefinition */
1668 defn->predefined = predefinition;
1670 mdef.symnam = symname;
1671 mdef.symlen = sym_length;
1680 /* Check a purported macro name SYMNAME, and yield its length.
1681 USAGE is the kind of name this is intended for. */
1684 check_macro_name (pfile, symname, usage)
1692 for (p = symname; is_idchar[*p]; p++)
1694 sym_length = p - symname;
1695 if (sym_length == 0)
1696 cpp_error (pfile, "invalid %s name", usage);
1697 else if (!is_idstart[*symname]) {
1698 U_CHAR *msg; /* what pain... */
1699 msg = (U_CHAR *) alloca (sym_length + 1);
1700 bcopy (symname, msg, sym_length);
1701 msg[sym_length] = 0;
1702 cpp_error (pfile, "invalid %s name `%s'", usage, msg);
1704 if (! strncmp (symname, "defined", 7) && sym_length == 7)
1705 cpp_error (pfile, "invalid %s name `defined'", usage);
1711 * return zero if two DEFINITIONs are isomorphic
1714 compare_defs (d1, d2)
1715 DEFINITION *d1, *d2;
1717 register struct reflist *a1, *a2;
1718 register U_CHAR *p1 = d1->expansion;
1719 register U_CHAR *p2 = d2->expansion;
1722 if (d1->nargs != d2->nargs)
1724 if (strcmp ((char *)d1->args.argnames, (char *)d2->args.argnames))
1726 for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2;
1727 a1 = a1->next, a2 = a2->next) {
1728 if (!((a1->nchars == a2->nchars && ! strncmp (p1, p2, a1->nchars))
1729 || ! comp_def_part (first, p1, a1->nchars, p2, a2->nchars, 0))
1730 || a1->argno != a2->argno
1731 || a1->stringify != a2->stringify
1732 || a1->raw_before != a2->raw_before
1733 || a1->raw_after != a2->raw_after)
1741 if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion),
1742 p2, d2->length - (p2 - d2->expansion), 1))
1747 /* Return 1 if two parts of two macro definitions are effectively different.
1748 One of the parts starts at BEG1 and has LEN1 chars;
1749 the other has LEN2 chars at BEG2.
1750 Any sequence of whitespace matches any other sequence of whitespace.
1751 FIRST means these parts are the first of a macro definition;
1752 so ignore leading whitespace entirely.
1753 LAST means these parts are the last of a macro definition;
1754 so ignore trailing whitespace entirely. */
1757 comp_def_part (first, beg1, len1, beg2, len2, last)
1759 U_CHAR *beg1, *beg2;
1763 register U_CHAR *end1 = beg1 + len1;
1764 register U_CHAR *end2 = beg2 + len2;
1766 while (beg1 != end1 && is_space[*beg1]) beg1++;
1767 while (beg2 != end2 && is_space[*beg2]) beg2++;
1770 while (beg1 != end1 && is_space[end1[-1]]) end1--;
1771 while (beg2 != end2 && is_space[end2[-1]]) end2--;
1773 while (beg1 != end1 && beg2 != end2) {
1774 if (is_space[*beg1] && is_space[*beg2]) {
1775 while (beg1 != end1 && is_space[*beg1]) beg1++;
1776 while (beg2 != end2 && is_space[*beg2]) beg2++;
1777 } else if (*beg1 == *beg2) {
1781 return (beg1 != end1) || (beg2 != end2);
1784 /* Process a #define command.
1785 BUF points to the contents of the #define command, as a contiguous string.
1786 LIMIT points to the first character past the end of the definition.
1787 KEYWORD is the keyword-table entry for #define,
1788 or NULL for a "predefined" macro. */
1791 do_define (pfile, keyword, buf, limit)
1793 struct directive *keyword;
1794 U_CHAR *buf, *limit;
1801 /* If this is a precompiler run (with -pcp) pass thru #define commands. */
1802 if (pcp_outfile && keyword)
1803 pass_thru_directive (buf, limit, pfile, keyword);
1806 mdef = create_definition (buf, limit, pfile, keyword == NULL);
1810 hashcode = hashf (mdef.symnam, mdef.symlen, HASHSIZE);
1812 if ((hp = cpp_lookup (pfile, mdef.symnam, mdef.symlen, hashcode)) != NULL)
1815 /* Redefining a precompiled key is ok. */
1816 if (hp->type == T_PCSTRING)
1818 /* Redefining a macro is ok if the definitions are the same. */
1819 else if (hp->type == T_MACRO)
1820 ok = ! compare_defs (mdef.defn, hp->value.defn);
1821 /* Redefining a constant is ok with -D. */
1822 else if (hp->type == T_CONST)
1823 ok = ! CPP_OPTIONS (pfile)->done_initializing;
1824 /* Print the warning if it's not ok. */
1827 U_CHAR *msg; /* what pain... */
1829 /* If we are passing through #define and #undef directives, do
1830 that for this re-definition now. */
1831 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1832 pass_thru_directive (buf, limit, pfile, keyword);
1834 msg = (U_CHAR *) alloca (mdef.symlen + 22);
1836 bcopy (mdef.symnam, msg + 1, mdef.symlen);
1837 strcpy ((char *) (msg + mdef.symlen + 1), "' redefined");
1838 cpp_pedwarn (pfile, msg);
1839 if (hp->type == T_MACRO)
1840 cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file, hp->value.defn->line,
1841 "this is the location of the previous definition");
1843 /* Replace the old definition. */
1845 hp->value.defn = mdef.defn;
1849 /* If we are passing through #define and #undef directives, do
1850 that for this new definition now. */
1851 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1852 pass_thru_directive (buf, limit, pfile, keyword);
1853 install (mdef.symnam, mdef.symlen, T_MACRO, 0,
1854 (char *) mdef.defn, hashcode);
1864 /* This structure represents one parsed argument in a macro call.
1865 `raw' points to the argument text as written (`raw_length' is its length).
1866 `expanded' points to the argument's macro-expansion
1867 (its length is `expand_length').
1868 `stringified_length' is the length the argument would have
1870 `use_count' is the number of times this macro arg is substituted
1871 into the macro. If the actual use count exceeds 10,
1872 the value stored is 10. */
1874 /* raw and expanded are relative to ARG_BASE */
1875 #define ARG_BASE ((pfile)->token_buffer)
1878 /* Strings relative to pfile->token_buffer */
1879 long raw, expanded, stringified;
1880 int raw_length, expand_length;
1881 int stringified_length;
1888 cpp_push_buffer (pfile, buffer, length)
1893 #ifdef STATIC_BUFFERS
1894 register cpp_buffer *buf = CPP_BUFFER (pfile);
1895 if (buf == pfile->buffer_stack)
1896 fatal ("%s: macro or `#include' recursion too deep", buf->fname);
1898 bzero ((char *) buf, sizeof (cpp_buffer));
1899 CPP_BUFFER (pfile) = buf;
1901 register cpp_buffer *buf = (cpp_buffer*) xmalloc (sizeof(cpp_buffer));
1902 bzero ((char *) buf, sizeof (cpp_buffer));
1903 CPP_PREV_BUFFER (buf) = CPP_BUFFER (pfile);
1904 CPP_BUFFER (pfile) = buf;
1906 buf->if_stack = pfile->if_stack;
1907 buf->cleanup = null_cleanup;
1908 buf->underflow = null_underflow;
1909 buf->buf = buf->cur = buffer;
1910 buf->alimit = buf->rlimit = buffer + length;
1916 cpp_pop_buffer (pfile)
1919 cpp_buffer *buf = CPP_BUFFER (pfile);
1920 #ifdef STATIC_BUFFERS
1921 (*buf->cleanup) (buf, pfile);
1922 return ++CPP_BUFFER (pfile);
1924 cpp_buffer *next_buf = CPP_PREV_BUFFER (buf);
1925 (*buf->cleanup) (buf, pfile);
1926 CPP_BUFFER (pfile) = next_buf;
1932 /* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer.
1933 Pop the buffer when done. */
1936 cpp_scan_buffer (pfile)
1939 cpp_buffer *buffer = CPP_BUFFER (pfile);
1942 enum cpp_token token = cpp_get_token (pfile);
1943 if (token == CPP_EOF) /* Should not happen ... */
1945 if (token == CPP_POP && CPP_BUFFER (pfile) == buffer)
1947 cpp_pop_buffer (pfile);
1954 * Rescan a string (which may have escape marks) into pfile's buffer.
1955 * Place the result in pfile->token_buffer.
1957 * The input is copied before it is scanned, so it is safe to pass
1958 * it something from the token_buffer that will get overwritten
1959 * (because it follows CPP_WRITTEN). This is used by do_include.
1963 cpp_expand_to_buffer (pfile, buf, length)
1968 register cpp_buffer *ip;
1970 U_CHAR *limit = buf + length;
1973 int odepth = indepth;
1979 /* Set up the input on the input stack. */
1981 buf1 = (U_CHAR *) alloca (length + 1);
1983 register U_CHAR *p1 = buf;
1984 register U_CHAR *p2 = buf1;
1991 ip = cpp_push_buffer (pfile, buf1, length);
1992 ip->has_escapes = 1;
1994 ip->lineno = obuf.lineno = 1;
1997 /* Scan the input, create the output. */
1998 cpp_scan_buffer (pfile);
2001 if (indepth != odepth)
2005 CPP_NUL_TERMINATE (pfile);
2010 adjust_position (buf, limit, linep, colp)
2020 (*linep)++, (*colp) = 1;
2026 /* Move line_base forward, updating lineno and colno. */
2029 update_position (pbuf)
2030 register cpp_buffer *pbuf;
2032 unsigned char *old_pos = pbuf->buf + pbuf->line_base;
2033 unsigned char *new_pos = pbuf->cur;
2034 register struct parse_marker *mark;
2035 for (mark = pbuf->marks; mark != NULL; mark = mark->next)
2037 if (pbuf->buf + mark->position < new_pos)
2038 new_pos = pbuf->buf + mark->position;
2040 pbuf->line_base += new_pos - old_pos;
2041 adjust_position (old_pos, new_pos, &pbuf->lineno, &pbuf->colno);
2045 cpp_buf_line_and_col (pbuf, linep, colp)
2046 register cpp_buffer *pbuf;
2054 *linep = pbuf->lineno;
2055 *colp = pbuf->colno;
2056 adjust_position (pbuf->buf + pbuf->line_base, pbuf->cur, linep, colp);
2065 /* Return the cpp_buffer that corresponds to a file (not a macro). */
2068 cpp_file_buffer (pfile)
2071 cpp_buffer *ip = CPP_BUFFER (pfile);
2073 for ( ; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
2074 if (ip->fname != NULL)
2080 count_newlines (buf, limit)
2081 register U_CHAR *buf;
2082 register U_CHAR *limit;
2084 register long count = 0;
2095 * write out a #line command, for instance, after an #include file.
2096 * If CONDITIONAL is nonzero, we can omit the #line if it would
2097 * appear to be a no-op, and we can output a few newlines instead
2098 * if we want to increase the line number by a small amount.
2099 * FILE_CHANGE says whether we are entering a file, leaving, or neither.
2103 output_line_command (pfile, conditional, file_change)
2106 enum file_change_code file_change;
2109 char *line_cmd_buf, *line_end;
2111 cpp_buffer *ip = CPP_BUFFER (pfile);
2113 if (ip->fname == NULL || CPP_OPTIONS (pfile)->no_output) {
2117 update_position (ip);
2118 line = CPP_BUFFER (pfile)->lineno;
2119 col = CPP_BUFFER (pfile)->colno;
2120 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
2122 if (CPP_OPTIONS (pfile)->no_line_commands)
2126 if (line == pfile->lineno)
2129 /* If the inherited line number is a little too small,
2130 output some newlines instead of a #line command. */
2131 if (line > pfile->lineno && line < pfile->lineno + 8) {
2132 CPP_RESERVE (pfile, 20);
2133 while (line > pfile->lineno) {
2134 CPP_PUTC_Q (pfile, '\n');
2142 /* Don't output a line number of 0 if we can help it. */
2143 if (ip->lineno == 0 && ip->bufp - ip->buf < ip->length
2144 && *ip->bufp == '\n') {
2150 CPP_RESERVE (pfile, 4 * strlen (ip->nominal_fname) + 50);
2152 #ifdef OUTPUT_LINE_COMMANDS
2153 static char sharp_line[] = "#line ";
2155 static char sharp_line[] = "# ";
2157 CPP_PUTS_Q (pfile, sharp_line, sizeof(sharp_line)-1);
2160 sprintf (CPP_PWRITTEN (pfile), "%d ", line);
2161 CPP_ADJUST_WRITTEN (pfile, strlen (CPP_PWRITTEN (pfile)));
2163 quote_string (pfile, ip->nominal_fname);
2164 if (file_change != same_file) {
2165 CPP_PUTC_Q (pfile, ' ');
2166 CPP_PUTC_Q (pfile, file_change == enter_file ? '1' : '2');
2168 /* Tell cc1 if following text comes from a system header file. */
2169 if (ip->system_header_p) {
2170 CPP_PUTC_Q (pfile, ' ');
2171 CPP_PUTC_Q (pfile, '3');
2173 #ifndef NO_IMPLICIT_EXTERN_C
2174 /* Tell cc1plus if following text should be treated as C. */
2175 if (ip->system_header_p == 2 && CPP_OPTIONS (pfile)->cplusplus) {
2176 CPP_PUTC_Q (pfile, ' ');
2177 CPP_PUTC_Q (pfile, '4');
2180 CPP_PUTC_Q (pfile, '\n');
2181 pfile->lineno = line;
2185 * Parse a macro argument and append the info on PFILE's token_buffer.
2186 * REST_ARGS means to absorb the rest of the args.
2187 * Return nonzero to indicate a syntax error.
2190 static enum cpp_token
2191 macarg (pfile, rest_args)
2196 enum cpp_token token;
2197 long arg_start = CPP_WRITTEN (pfile);
2198 char save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
2199 CPP_OPTIONS (pfile)->put_out_comments = 0;
2201 /* Try to parse as much of the argument as exists at this
2202 input stack level. */
2203 pfile->no_macro_expand++;
2206 token = cpp_get_token (pfile);
2212 /* If we've hit end of file, it's an error (reported by caller).
2213 Ditto if it's the end of cpp_expand_to_buffer text.
2214 If we've hit end of macro, just continue. */
2215 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
2226 /* if we've returned to lowest level and
2227 we aren't absorbing all args */
2228 if (paren == 0 && rest_args == 0)
2232 /* Remove ',' or ')' from argument buffer. */
2233 CPP_ADJUST_WRITTEN (pfile, -1);
2240 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
2241 pfile->no_macro_expand--;
2246 /* Turn newlines to spaces in the string of length LENGTH at START,
2247 except inside of string constants.
2248 The string is copied into itself with its beginning staying fixed. */
2251 change_newlines (start, length)
2255 register U_CHAR *ibp;
2256 register U_CHAR *obp;
2257 register U_CHAR *limit;
2261 limit = start + length;
2264 while (ibp < limit) {
2265 *obp++ = c = *ibp++;
2270 /* Notice and skip strings, so that we don't delete newlines in them. */
2273 while (ibp < limit) {
2274 *obp++ = c = *ibp++;
2277 if (c == '\n' && quotec == '\'')
2293 if (!pfile->timebuf) {
2294 time_t t = time ((time_t *)0);
2295 pfile->timebuf = localtime (&t);
2297 return pfile->timebuf;
2300 static char *monthnames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
2301 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
2305 * expand things like __FILE__. Place the expansion into the output
2306 * buffer *without* rescanning.
2310 special_symbol (hp, pfile)
2317 cpp_buffer *ip = NULL;
2320 int paren = 0; /* For special `defined' keyword */
2323 if (pcp_outfile && pcp_inside_if
2324 && hp->type != T_SPEC_DEFINED && hp->type != T_CONST)
2326 "Predefined macro `%s' used inside `#if' during precompilation",
2330 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
2334 cpp_error (pfile, "cccp error: not in any file?!");
2335 return; /* the show must go on */
2337 if (ip->fname != NULL)
2347 if (hp->type == T_BASE_FILE)
2349 while (CPP_PREV_BUFFER (ip))
2350 ip = CPP_PREV_BUFFER (ip);
2352 string = ip->nominal_fname;
2356 CPP_RESERVE (pfile, 3 + 4 * strlen (string));
2357 quote_string (pfile, string);
2361 case T_INCLUDE_LEVEL:
2363 for (ip = CPP_BUFFER (pfile); ip != NULL; ip = CPP_PREV_BUFFER (ip))
2364 if (ip->fname != NULL)
2367 buf = (char *) alloca (8); /* Eight bytes ought to be more than enough */
2368 sprintf (buf, "%d", true_indepth - 1);
2372 buf = (char *) alloca (3 + strlen (version_string));
2373 sprintf (buf, "\"%s\"", version_string);
2376 #ifndef NO_BUILTIN_SIZE_TYPE
2382 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2383 case T_PTRDIFF_TYPE:
2389 buf = CPP_WCHAR_TYPE (pfile);
2392 case T_USER_LABEL_PREFIX_TYPE:
2393 buf = USER_LABEL_PREFIX;
2396 case T_REGISTER_PREFIX_TYPE:
2397 buf = REGISTER_PREFIX;
2401 buf = (char *) alloca (4 * sizeof (int));
2402 sprintf (buf, "%d", hp->value.ival);
2404 if (pcp_inside_if && pcp_outfile)
2405 /* Output a precondition for this macro use */
2406 fprintf (pcp_outfile, "#define %s %d\n", hp->name, hp->value.ival);
2412 long line = ip->lineno;
2413 long col = ip->colno;
2414 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
2416 buf = (char *) alloca (10);
2417 sprintf (buf, "%d", line);
2423 buf = (char *) alloca (20);
2424 timebuf = timestamp (pfile);
2425 if (hp->type == T_DATE)
2426 sprintf (buf, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon],
2427 timebuf->tm_mday, timebuf->tm_year + 1900);
2429 sprintf (buf, "\"%02d:%02d:%02d\"", timebuf->tm_hour, timebuf->tm_min,
2433 case T_SPEC_DEFINED:
2434 buf = " 0 "; /* Assume symbol is not defined */
2435 ip = CPP_BUFFER (pfile);
2436 SKIP_WHITE_SPACE (ip->cur);
2437 if (*ip->cur == '(')
2440 ip->cur++; /* Skip over the paren */
2441 SKIP_WHITE_SPACE (ip->cur);
2444 if (!is_idstart[*ip->cur])
2446 if (hp = cpp_lookup (pfile, ip->cur, -1, -1))
2449 if (pcp_outfile && pcp_inside_if
2450 && (hp->type == T_CONST
2451 || (hp->type == T_MACRO && hp->value.defn->predefined)))
2452 /* Output a precondition for this macro use. */
2453 fprintf (pcp_outfile, "#define %s\n", hp->name);
2459 if (pcp_outfile && pcp_inside_if)
2461 /* Output a precondition for this macro use */
2462 U_CHAR *cp = ip->bufp;
2463 fprintf (pcp_outfile, "#undef ");
2464 while (is_idchar[*cp]) /* Ick! */
2465 fputc (*cp++, pcp_outfile);
2466 putc ('\n', pcp_outfile);
2469 while (is_idchar[*ip->cur])
2471 SKIP_WHITE_SPACE (ip->cur);
2474 if (*ip->cur != ')')
2482 cpp_error (pfile, "`defined' without an identifier");
2486 cpp_error (pfile, "cccp error: invalid special hash type"); /* time for gdb */
2490 CPP_RESERVE (pfile, len + 1);
2491 CPP_PUTS_Q (pfile, buf, len);
2492 CPP_NUL_TERMINATE_Q (pfile);
2497 /* Initialize the built-in macros. */
2500 initialize_builtins (pfile)
2503 install ("__LINE__", -1, T_SPECLINE, 0, 0, -1);
2504 install ("__DATE__", -1, T_DATE, 0, 0, -1);
2505 install ("__FILE__", -1, T_FILE, 0, 0, -1);
2506 install ("__BASE_FILE__", -1, T_BASE_FILE, 0, 0, -1);
2507 install ("__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL, 0, 0, -1);
2508 install ("__VERSION__", -1, T_VERSION, 0, 0, -1);
2509 #ifndef NO_BUILTIN_SIZE_TYPE
2510 install ("__SIZE_TYPE__", -1, T_SIZE_TYPE, 0, 0, -1);
2512 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2513 install ("__PTRDIFF_TYPE__ ", -1, T_PTRDIFF_TYPE, 0, 0, -1);
2515 install ("__WCHAR_TYPE__", -1, T_WCHAR_TYPE, 0, 0, -1);
2516 install ("__USER_LABEL_PREFIX__", -1, T_USER_LABEL_PREFIX_TYPE, 0, 0, -1);
2517 install ("__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE, 0, 0, -1);
2518 install ("__TIME__", -1, T_TIME, 0, 0, -1);
2519 if (!CPP_TRADITIONAL (pfile))
2520 install ("__STDC__", -1, T_CONST, STDC_VALUE, 0, -1);
2521 if (CPP_OPTIONS (pfile)->objc)
2522 install ("__OBJC__", -1, T_CONST, 1, 0, -1);
2523 /* This is supplied using a -D by the compiler driver
2524 so that it is present only when truly compiling with GNU C. */
2525 /* install ("__GNUC__", -1, T_CONST, 2, 0, -1); */
2527 if (CPP_OPTIONS (pfile)->debug_output)
2529 char directive[2048];
2530 register struct directive *dp = &directive_table[0];
2531 struct tm *timebuf = timestamp (pfile);
2532 cpp_buffer *pbuffer = CPP_BUFFER (pfile);
2534 while (CPP_PREV_BUFFER (pbuffer))
2535 pbuffer = CPP_PREV_BUFFER (pbuffer);
2536 sprintf (directive, " __BASE_FILE__ \"%s\"\n",
2537 pbuffer->nominal_fname);
2538 output_line_command (pfile, 0, same_file);
2539 pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp);
2541 sprintf (directive, " __VERSION__ \"%s\"\n", version_string);
2542 output_line_command (pfile, 0, same_file);
2543 pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp);
2545 #ifndef NO_BUILTIN_SIZE_TYPE
2546 sprintf (directive, " __SIZE_TYPE__ %s\n", SIZE_TYPE);
2547 output_line_command (pfile, 0, same_file);
2548 pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp);
2551 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2552 sprintf (directive, " __PTRDIFF_TYPE__ %s\n", PTRDIFF_TYPE);
2553 output_line_command (pfile, 0, same_file);
2554 pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp);
2557 sprintf (directive, " __WCHAR_TYPE__ %s\n", CPP_WCHAR_TYPE (pfile));
2558 output_line_command (pfile, 0, same_file);
2559 pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp);
2561 sprintf (directive, " __DATE__ \"%s %2d %4d\"\n",
2562 monthnames[timebuf->tm_mon],
2563 timebuf->tm_mday, timebuf->tm_year + 1900);
2564 output_line_command (pfile, 0, same_file);
2565 pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp);
2567 sprintf (directive, " __TIME__ \"%02d:%02d:%02d\"\n",
2568 timebuf->tm_hour, timebuf->tm_min, timebuf->tm_sec);
2569 output_line_command (pfile, 0, same_file);
2570 pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp);
2572 if (!CPP_TRADITIONAL (pfile))
2574 sprintf (directive, " __STDC__ 1");
2575 output_line_command (pfile, 0, same_file);
2576 pass_thru_directive (directive, &directive[strlen (directive)],
2579 if (CPP_OPTIONS (pfile)->objc)
2581 sprintf (directive, " __OBJC__ 1");
2582 output_line_command (pfile, 0, same_file);
2583 pass_thru_directive (directive, &directive[strlen (directive)],
2589 /* Return 1 iff a token ending in C1 followed directly by a token C2
2590 could cause mis-tokenization. */
2593 unsafe_chars (c1, c2)
2599 if (c2 == c1 || c2 == '=')
2603 case '0': case '1': case '2': case '3': case '4':
2604 case '5': case '6': case '7': case '8': case '9':
2606 if (c2 == '-' || c2 == '+')
2607 return 1; /* could extend a pre-processing number */
2610 if (c2 == '\'' || c2 == '\"')
2611 return 1; /* Could turn into L"xxx" or L'xxx'. */
2615 case 'a': case 'b': case 'c': case 'd': case 'f':
2616 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
2617 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
2618 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
2620 case 'A': case 'B': case 'C': case 'D': case 'F':
2621 case 'G': case 'H': case 'I': case 'J': case 'K':
2622 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
2623 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
2625 /* We're in the middle of either a name or a pre-processing number. */
2626 return (is_idchar[c2] || c2 == '.');
2627 case '<': case '>': case '!': case '%': case '#': case ':':
2628 case '^': case '&': case '|': case '*': case '/': case '=':
2629 return (c2 == c1 || c2 == '=');
2634 /* Expand a macro call.
2635 HP points to the symbol that is the macro being called.
2636 Put the result of expansion onto the input stack
2637 so that subsequent input by our caller will use it.
2639 If macro wants arguments, caller has already verified that
2640 an argument list follows; arguments come from the input stack. */
2643 macroexpand (pfile, hp)
2648 DEFINITION *defn = hp->value.defn;
2649 register U_CHAR *xbuf;
2650 long start_line, start_column;
2652 struct argdata *args;
2653 long old_written = CPP_WRITTEN (pfile);
2655 int start_line = instack[indepth].lineno;
2657 int rest_args, rest_zero;
2661 CHECK_DEPTH (return;);
2665 /* This macro is being used inside a #if, which means it must be */
2666 /* recorded as a precondition. */
2667 if (pcp_inside_if && pcp_outfile && defn->predefined)
2668 dump_single_macro (hp, pcp_outfile);
2671 pfile->output_escapes++;
2672 cpp_buf_line_and_col (cpp_file_buffer (pfile), &start_line, &start_column);
2674 nargs = defn->nargs;
2678 enum cpp_token token;
2680 args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata));
2682 for (i = 0; i < nargs; i++)
2684 args[i].raw = args[i].expanded = 0;
2685 args[i].raw_length = 0;
2686 args[i].expand_length = args[i].stringified_length = -1;
2687 args[i].use_count = 0;
2690 /* Parse all the macro args that are supplied. I counts them.
2691 The first NARGS args are stored in ARGS.
2692 The rest are discarded. If rest_args is set then we assume
2693 macarg absorbed the rest of the args. */
2697 FORWARD(1); /* Discard the open-parenthesis before the first arg. */
2702 if (i < nargs || (nargs == 0 && i == 0))
2704 /* if we are working on last arg which absorbs rest of args... */
2705 if (i == nargs - 1 && defn->rest_args)
2707 args[i].raw = CPP_WRITTEN (pfile);
2708 token = macarg (pfile, rest_args);
2709 args[i].raw_length = CPP_WRITTEN (pfile) - args[i].raw;
2710 args[i].newlines = 0; /* FIXME */
2713 token = macarg (pfile, 0);
2714 if (token == CPP_EOF || token == CPP_POP)
2716 cpp_error_with_line (pfile, start_line, start_column,
2717 "unterminated macro call");
2721 } while (token == CPP_COMMA);
2723 /* If we got one arg but it was just whitespace, call that 0 args. */
2726 register U_CHAR *bp = ARG_BASE + args[0].raw;
2727 register U_CHAR *lim = bp + args[0].raw_length;
2728 /* cpp.texi says for foo ( ) we provide one argument.
2729 However, if foo wants just 0 arguments, treat this as 0. */
2731 while (bp != lim && is_space[*bp]) bp++;
2736 /* Don't output an error message if we have already output one for
2737 a parse error above. */
2739 if (nargs == 0 && i > 0)
2741 cpp_error (pfile, "arguments given to macro `%s'", hp->name);
2745 /* traditional C allows foo() if foo wants one argument. */
2746 if (nargs == 1 && i == 0 && CPP_TRADITIONAL (pfile))
2748 /* the rest args token is allowed to absorb 0 tokens */
2749 else if (i == nargs - 1 && defn->rest_args)
2752 cpp_error (pfile, "macro `%s' used without args", hp->name);
2754 cpp_error (pfile, "macro `%s' used with just one arg", hp->name);
2756 cpp_error (pfile, "macro `%s' used with only %d args",
2762 "macro `%s' used with too many (%d) args", hp->name, i);
2766 /* If macro wants zero args, we parsed the arglist for checking only.
2767 Read directly from the macro definition. */
2770 xbuf = defn->expansion;
2771 xbuf_len = defn->length;
2775 register U_CHAR *exp = defn->expansion;
2776 register int offset; /* offset in expansion,
2777 copied a piece at a time */
2778 register int totlen; /* total amount of exp buffer filled so far */
2780 register struct reflist *ap, *last_ap;
2782 /* Macro really takes args. Compute the expansion of this call. */
2784 /* Compute length in characters of the macro's expansion.
2785 Also count number of times each arg is used. */
2786 xbuf_len = defn->length;
2787 for (ap = defn->pattern; ap != NULL; ap = ap->next)
2791 register struct argdata *arg = &args[ap->argno];
2792 /* Stringify it it hasn't already been */
2793 if (arg->stringified_length < 0)
2795 int arglen = arg->raw_length;
2799 /* Initially need_space is -1. Otherwise, 1 means the
2800 previous character was a space, but we suppressed it;
2801 0 means the previous character was a non-space. */
2802 int need_space = -1;
2804 arg->stringified = CPP_WRITTEN (pfile);
2805 if (!CPP_TRADITIONAL (pfile))
2806 CPP_PUTC (pfile, '\"'); /* insert beginning quote */
2807 for (; i < arglen; i++)
2809 c = (ARG_BASE + arg->raw)[i];
2813 /* Internal sequences of whitespace are replaced by
2814 one space except within an string or char token.*/
2817 if (CPP_WRITTEN (pfile) > arg->stringified
2818 && (CPP_PWRITTEN (pfile))[-1] == '@')
2820 /* "@ " escape markers are removed */
2821 CPP_ADJUST_WRITTEN (pfile, -1);
2824 if (need_space == 0)
2828 else if (need_space > 0)
2829 CPP_PUTC (pfile, ' ');
2844 else if (c == '\"' || c == '\'')
2848 /* Escape these chars */
2849 if (c == '\"' || (in_string && c == '\\'))
2850 CPP_PUTC (pfile, '\\');
2852 CPP_PUTC (pfile, c);
2855 CPP_RESERVE (pfile, 4);
2856 sprintf (CPP_PWRITTEN (pfile), "\\%03o",
2858 CPP_ADJUST_WRITTEN (pfile, 4);
2861 if (!CPP_TRADITIONAL (pfile))
2862 CPP_PUTC (pfile, '\"'); /* insert ending quote */
2863 arg->stringified_length
2864 = CPP_WRITTEN (pfile) - arg->stringified;
2866 xbuf_len += args[ap->argno].stringified_length;
2868 else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
2869 /* Add 4 for two newline-space markers to prevent
2870 token concatenation. */
2871 xbuf_len += args[ap->argno].raw_length + 4;
2874 /* We have an ordinary (expanded) occurrence of the arg.
2875 So compute its expansion, if we have not already. */
2876 if (args[ap->argno].expand_length < 0)
2878 args[ap->argno].expanded = CPP_WRITTEN (pfile);
2879 cpp_expand_to_buffer (pfile,
2880 ARG_BASE + args[ap->argno].raw,
2881 args[ap->argno].raw_length);
2883 args[ap->argno].expand_length
2884 = CPP_WRITTEN (pfile) - args[ap->argno].expanded;
2887 /* Add 4 for two newline-space markers to prevent
2888 token concatenation. */
2889 xbuf_len += args[ap->argno].expand_length + 4;
2891 if (args[ap->argno].use_count < 10)
2892 args[ap->argno].use_count++;
2895 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
2897 /* Generate in XBUF the complete expansion
2898 with arguments substituted in.
2899 TOTLEN is the total size generated so far.
2900 OFFSET is the index in the definition
2901 of where we are copying from. */
2902 offset = totlen = 0;
2903 for (last_ap = NULL, ap = defn->pattern; ap != NULL;
2904 last_ap = ap, ap = ap->next)
2906 register struct argdata *arg = &args[ap->argno];
2907 int count_before = totlen;
2909 /* Add chars to XBUF. */
2910 for (i = 0; i < ap->nchars; i++, offset++)
2911 xbuf[totlen++] = exp[offset];
2913 /* If followed by an empty rest arg with concatenation,
2914 delete the last run of nonwhite chars. */
2915 if (rest_zero && totlen > count_before
2916 && ((ap->rest_args && ap->raw_before)
2917 || (last_ap != NULL && last_ap->rest_args
2918 && last_ap->raw_after)))
2920 /* Delete final whitespace. */
2921 while (totlen > count_before && is_space[xbuf[totlen - 1]])
2924 /* Delete the nonwhites before them. */
2925 while (totlen > count_before && ! is_space[xbuf[totlen - 1]])
2929 if (ap->stringify != 0)
2931 bcopy (ARG_BASE + arg->stringified,
2932 xbuf + totlen, arg->stringified_length);
2933 totlen += arg->stringified_length;
2935 else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
2937 U_CHAR *p1 = ARG_BASE + arg->raw;
2938 U_CHAR *l1 = p1 + arg->raw_length;
2941 while (p1 != l1 && is_space[*p1]) p1++;
2942 while (p1 != l1 && is_idchar[*p1])
2943 xbuf[totlen++] = *p1++;
2947 /* Arg is concatenated after: delete trailing whitespace,
2948 whitespace markers, and no-reexpansion markers. */
2951 if (is_space[l1[-1]]) l1--;
2952 else if (l1[-1] == '-')
2954 U_CHAR *p2 = l1 - 1;
2955 /* If a `-' is preceded by an odd number of newlines then it
2956 and the last newline are a no-reexpansion marker. */
2957 while (p2 != p1 && p2[-1] == '\n') p2--;
2958 if ((l1 - 1 - p2) & 1) {
2967 bcopy (p1, xbuf + totlen, l1 - p1);
2972 U_CHAR *expanded = ARG_BASE + arg->expanded;
2973 if (!ap->raw_before && totlen > 0 && arg->expand_length
2974 && !CPP_TRADITIONAL(pfile)
2975 && unsafe_chars (xbuf[totlen-1], expanded[0]))
2977 xbuf[totlen++] = '@';
2978 xbuf[totlen++] = ' ';
2981 bcopy (expanded, xbuf + totlen, arg->expand_length);
2982 totlen += arg->expand_length;
2984 if (!ap->raw_after && totlen > 0 && offset < defn->length
2985 && !CPP_TRADITIONAL(pfile)
2986 && unsafe_chars (xbuf[totlen-1], exp[offset]))
2988 xbuf[totlen++] = '@';
2989 xbuf[totlen++] = ' ';
2992 /* If a macro argument with newlines is used multiple times,
2993 then only expand the newlines once. This avoids creating
2994 output lines which don't correspond to any input line,
2995 which confuses gdb and gcov. */
2996 if (arg->use_count > 1 && arg->newlines > 0)
2998 /* Don't bother doing change_newlines for subsequent
3002 = change_newlines (expanded, arg->expand_length);
3006 if (totlen > xbuf_len)
3010 /* if there is anything left of the definition
3011 after handling the arg list, copy that in too. */
3013 for (i = offset; i < defn->length; i++)
3015 /* if we've reached the end of the macro */
3018 if (! (rest_zero && last_ap != NULL && last_ap->rest_args
3019 && last_ap->raw_after))
3020 xbuf[totlen++] = exp[i];
3028 pfile->output_escapes--;
3030 /* Now put the expansion on the input stack
3031 so our caller will commence reading from it. */
3032 push_macro_expansion (pfile, xbuf, xbuf_len, hp);
3033 CPP_BUFFER (pfile)->has_escapes = 1;
3035 /* Pop the space we've used in the token_buffer for argument expansion. */
3036 CPP_SET_WRITTEN (pfile, old_written);
3038 /* Recursive macro use sometimes works traditionally.
3039 #define foo(x,y) bar (x (y,0), y)
3042 if (!CPP_TRADITIONAL (pfile))
3043 hp->type = T_DISABLED;
3047 push_macro_expansion (pfile, xbuf, xbuf_len, hp)
3049 register U_CHAR *xbuf;
3053 register cpp_buffer *mbuf = cpp_push_buffer (pfile, xbuf, xbuf_len);
3054 mbuf->cleanup = macro_cleanup;
3057 /* The first chars of the expansion should be a "@ " added by
3058 collect_expansion. This is to prevent accidental token-pasting
3059 between the text preceding the macro invocation, and the macro
3062 We would like to avoid adding unneeded spaces (for the sake of
3063 tools that use cpp, such as imake). In some common cases we can
3064 tell that it is safe to omit the space.
3066 The character before the macro invocation cannot have been an
3067 idchar (or else it would have been pasted with the idchars of
3068 the macro name). Therefore, if the first non-space character
3069 of the expansion is an idchar, we do not need the extra space
3070 to prevent token pasting.
3072 Also, we don't need the extra space if the first char is '(',
3073 or some other (less common) characters. */
3075 if (xbuf[0] == '@' && xbuf[1] == ' '
3076 && (is_idchar[xbuf[2]] || xbuf[2] == '(' || xbuf[2] == '\''
3077 || xbuf[2] == '\"'))
3081 /* Like cpp_get_token, except that it does not read past end-of-line.
3082 Also, horizontal space is skipped, and macros are popped. */
3084 static enum cpp_token
3085 get_directive_token (pfile)
3090 long old_written = CPP_WRITTEN (pfile);
3091 enum cpp_token token;
3092 cpp_skip_hspace (pfile);
3093 if (PEEKC () == '\n')
3095 token = cpp_get_token (pfile);
3099 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
3101 /* ... else fall though ... */
3102 case CPP_HSPACE: case CPP_COMMENT:
3103 CPP_SET_WRITTEN (pfile, old_written);
3111 /* Handle #include and #import.
3112 This function expects to see "fname" or <fname> on the input.
3114 The input is normally in part of the output_buffer following
3115 CPP_WRITTEN, and will get overwritten by output_line_command.
3116 I.e. in input file specification has been popped by handle_directive.
3120 do_include (pfile, keyword, unused1, unused2)
3122 struct directive *keyword;
3123 U_CHAR *unused1, *unused2;
3125 int importing = (keyword->type == T_IMPORT);
3126 int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
3127 char *fname; /* Dynamically allocated fname buffer */
3130 U_CHAR *fbeg, *fend; /* Beginning and end of fname */
3131 enum cpp_token token;
3133 /* Chain of dirs to search */
3134 struct file_name_list *search_start = CPP_OPTIONS (pfile)->include;
3135 struct file_name_list dsp[1]; /* First in chain, if #include "..." */
3136 struct file_name_list *searchptr = 0;
3137 long old_written = CPP_WRITTEN (pfile);
3141 int f; /* file number */
3143 int retried = 0; /* Have already tried macro
3144 expanding the include line*/
3145 int angle_brackets = 0; /* 0 for "...", 1 for <...> */
3150 f= -1; /* JF we iz paranoid! */
3152 if (importing && CPP_OPTIONS (pfile)->warn_import
3153 && !CPP_OPTIONS (pfile)->inhibit_warnings
3154 && !CPP_BUFFER (pfile)->system_header_p && !pfile->import_warning)
3156 pfile->import_warning = 1;
3157 cpp_warning (pfile, "using `#import' is not recommended");
3158 fprintf (stderr, "The fact that a certain header file need not be processed more than once\n");
3159 fprintf (stderr, "should be indicated in the header file, not where it is used.\n");
3160 fprintf (stderr, "The best way to do this is with a conditional of this form:\n\n");
3161 fprintf (stderr, " #ifndef _FOO_H_INCLUDED\n");
3162 fprintf (stderr, " #define _FOO_H_INCLUDED\n");
3163 fprintf (stderr, " ... <real contents of file> ...\n");
3164 fprintf (stderr, " #endif /* Not _FOO_H_INCLUDED */\n\n");
3165 fprintf (stderr, "Then users can use `#include' any number of times.\n");
3166 fprintf (stderr, "GNU C automatically avoids processing the file more than once\n");
3167 fprintf (stderr, "when it is equipped with such a conditional.\n");
3170 pfile->parsing_include_directive++;
3171 token = get_directive_token (pfile);
3172 pfile->parsing_include_directive--;
3174 if (token == CPP_STRING)
3176 /* FIXME - check no trailing garbage */
3177 fbeg = pfile->token_buffer + old_written + 1;
3178 fend = CPP_PWRITTEN (pfile) - 1;
3179 if (fbeg[-1] == '<')
3182 /* If -I-, start with the first -I dir after the -I-. */
3183 if (CPP_OPTIONS (pfile)->first_bracket_include)
3184 search_start = CPP_OPTIONS (pfile)->first_bracket_include;
3186 /* If -I- was specified, don't search current dir, only spec'd ones. */
3187 else if (! CPP_OPTIONS (pfile)->ignore_srcdir)
3190 /* We have "filename". Figure out directory this source
3191 file is coming from and put it on the front of the list. */
3193 for (fp = CPP_BUFFER (pfile); fp != NULL; fp = CPP_PREV_BUFFER (fp))
3198 if ((nam = fp->nominal_fname) != NULL)
3200 /* Found a named file. Figure out dir of the file,
3201 and put it in front of the search list. */
3202 dsp[0].next = search_start;
3205 ep = rindex (nam, '/');
3207 ep = rindex (nam, ']');
3208 if (ep == NULL) ep = rindex (nam, '>');
3209 if (ep == NULL) ep = rindex (nam, ':');
3210 if (ep != NULL) ep++;
3215 dsp[0].fname = (char *) alloca (n + 1);
3216 strncpy (dsp[0].fname, nam, n);
3217 dsp[0].fname[n] = '\0';
3218 if (n + INCLUDE_LEN_FUDGE > pfile->max_include_len)
3219 pfile->max_include_len = n + INCLUDE_LEN_FUDGE;
3223 dsp[0].fname = 0; /* Current directory */
3225 dsp[0].got_name_map = 0;
3232 else if (token == CPP_NAME)
3235 * Support '#include xyz' like VAX-C to allow for easy use of all the
3236 * decwindow include files. It defaults to '#include <xyz.h>' (so the
3237 * code from case '<' is repeated here) and generates a warning.
3240 "VAX-C-style include specification found, use '#include <filename.h>' !");
3242 /* If -I-, start with the first -I dir after the -I-. */
3243 if (CPP_OPTIONS (pfile)->first_bracket_include)
3244 search_start = CPP_OPTIONS (pfile)->first_bracket_include;
3245 fbeg = pfile->token_buffer + old_written;
3246 fend = CPP_PWRITTEN (pfile);
3252 "`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
3253 CPP_SET_WRITTEN (pfile, old_written);
3254 skip_rest_of_line (pfile);
3260 token = get_directive_token (pfile);
3261 if (token != CPP_VSPACE)
3263 cpp_error (pfile, "junk at end of `#include'");
3264 while (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP)
3265 token = get_directive_token (pfile);
3268 /* For #include_next, skip in the search path
3269 past the dir in which the containing file was found. */
3273 for (fp = CPP_BUFFER (pfile); fp != NULL; fp = CPP_PREV_BUFFER (fp))
3274 if (fp->fname != NULL)
3276 /* fp->dir is null if the containing file was specified with
3277 an absolute file name. In that case, don't skip anything. */
3278 if (fp->dir == SELF_DIR_DUMMY)
3279 search_start = CPP_OPTIONS (pfile)->include;
3281 search_start = fp->dir->next;
3286 CPP_SET_WRITTEN (pfile, old_written);
3292 cpp_error (pfile, "empty file name in `#%s'", keyword->name);
3296 /* Allocate this permanently, because it gets stored in the definitions
3298 fname = (char *) xmalloc (pfile->max_include_len + flen + 4);
3299 /* + 2 above for slash and terminating null. */
3300 /* + 2 added for '.h' on VMS (to support '#include filename') */
3302 /* If specified file name is absolute, just open it. */
3305 strncpy (fname, fbeg, flen);
3307 if (redundant_include_p (pfile, fname))
3310 f = lookup_import (pfile, fname, NULL_PTR);
3312 f = open_include_file (pfile, fname, NULL_PTR);
3314 return 0; /* Already included this file */
3316 /* Search directory path, trying to open the file.
3317 Copy each filename tried into FNAME. */
3319 for (searchptr = search_start; searchptr; searchptr = searchptr->next) {
3320 if (searchptr->fname) {
3321 /* The empty string in a search path is ignored.
3322 This makes it possible to turn off entirely
3323 a standard piece of the list. */
3324 if (searchptr->fname[0] == 0)
3326 strcpy (fname, searchptr->fname);
3327 strcat (fname, "/");
3328 fname[strlen (fname) + flen] = 0;
3332 strncat (fname, fbeg, flen);
3334 /* Change this 1/2 Unix 1/2 VMS file specification into a
3335 full VMS file specification */
3336 if (searchptr->fname && (searchptr->fname[0] != 0)) {
3337 /* Fix up the filename */
3338 hack_vms_include_specification (fname);
3340 /* This is a normal VMS filespec, so use it unchanged. */
3341 strncpy (fname, fbeg, flen);
3343 /* if it's '#include filename', add the missing .h */
3344 if (index(fname,'.')==NULL) {
3345 strcat (fname, ".h");
3349 /* ??? There are currently 3 separate mechanisms for avoiding processing
3350 of redundant include files: #import, #pragma once, and
3351 redundant_include_p. It would be nice if they were unified. */
3352 if (redundant_include_p (pfile, fname))
3355 f = lookup_import (pfile, fname, searchptr);
3357 f = open_include_file (pfile, fname, searchptr);
3359 return 0; /* Already included this file */
3361 else if (f == -1 && errno == EACCES)
3362 cpp_warning (pfile, "Header file %s exists, but is not readable",
3372 /* A file that was not found. */
3373 strncpy (fname, fbeg, flen);
3375 /* If generating dependencies and -MG was specified, we assume missing
3376 files are leaf files, living in the same directory as the source file
3377 or other similar place; these missing files may be generated from
3378 other files and may not exist yet (eg: y.tab.h). */
3380 if (CPP_OPTIONS(pfile)->print_deps_missing_files
3381 && CPP_PRINT_DEPS (pfile)
3382 > (angle_brackets || (pfile->system_include_depth > 0)))
3384 /* If it was requested as a system header file,
3385 then assume it belongs in the first place to look for such. */
3388 for (searchptr = search_start; searchptr;
3389 searchptr = searchptr->next)
3391 if (searchptr->fname)
3395 if (searchptr->fname[0] == 0)
3397 p = (char *) alloca (strlen (searchptr->fname)
3398 + strlen (fname) + 2);
3399 strcpy (p, searchptr->fname);
3402 deps_output (pfile, p, ' ');
3409 /* Otherwise, omit the directory, as if the file existed
3410 in the directory with the source. */
3411 deps_output (pfile, fname, ' ');
3414 /* If -M was specified, and this header file won't be added to the
3415 dependency list, then don't count this as an error, because we can
3416 still produce correct output. Otherwise, we can't produce correct
3417 output, because there may be dependencies we need inside the missing
3418 file, and we don't know what directory this missing file exists in.*/
3419 else if (CPP_PRINT_DEPS (pfile)
3420 && (CPP_PRINT_DEPS (pfile)
3421 <= (angle_brackets || (pfile->system_include_depth > 0))))
3422 cpp_warning (pfile, "No include path in which to find %s", fname);
3423 else if (search_start)
3424 cpp_error_from_errno (pfile, fname);
3426 cpp_error (pfile, "No include path in which to find %s", fname);
3429 /* Check to see if this include file is a once-only include file.
3432 struct file_name_list* ptr;
3434 for (ptr = pfile->dont_repeat_files; ptr; ptr = ptr->next) {
3435 if (!strcmp (ptr->fname, fname)) {
3437 return 0; /* This file was once'd. */
3441 for (ptr = pfile->all_include_files; ptr; ptr = ptr->next) {
3442 if (!strcmp (ptr->fname, fname))
3443 break; /* This file was included before. */
3447 /* This is the first time for this file. */
3448 /* Add it to list of files included. */
3450 ptr = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
3451 ptr->control_macro = 0;
3452 ptr->c_system_include_path = 0;
3453 ptr->next = pfile->all_include_files;
3454 pfile->all_include_files = ptr;
3455 ptr->fname = savestring (fname);
3456 ptr->got_name_map = 0;
3458 /* For -M, add this file to the dependencies. */
3459 if (CPP_PRINT_DEPS (pfile)
3460 > (angle_brackets || (pfile->system_include_depth > 0)))
3461 deps_output (pfile, fname, ' ');
3464 /* Handle -H option. */
3465 if (CPP_OPTIONS(pfile)->print_include_names)
3467 cpp_buffer *buf = CPP_BUFFER (pfile);
3468 while ((buf = CPP_PREV_BUFFER (buf)) != NULL)
3470 fprintf (stderr, "%s\n", fname);
3474 pfile->system_include_depth++;
3476 /* Actually process the file. */
3478 /* Record file on "seen" list for #import. */
3479 add_import (pfile, f, fname);
3481 pcftry = (char *) alloca (strlen (fname) + 30);
3493 sprintf (pcftry, "%s%d", fname, pcfnum++);
3495 pcf = open (pcftry, O_RDONLY, 0666);
3501 if (bcmp ((char *) &stat_f.st_ino, (char *) &s.st_ino,
3503 || stat_f.st_dev != s.st_dev)
3505 pcfbuf = check_precompiled (pcf, fname, &pcfbuflimit);
3506 /* Don't need it any more. */
3511 /* Don't need it at all. */
3516 } while (pcf != -1 && !pcfbuf);
3520 /* Actually process the file */
3521 cpp_push_buffer (pfile, NULL, 0);
3522 if (finclude (pfile, f, fname, is_system_include (pfile, fname),
3523 searchptr != dsp ? searchptr : SELF_DIR_DUMMY))
3525 output_line_command (pfile, 0, enter_file);
3526 pfile->only_seen_white = 2;
3530 pfile->system_include_depth--;
3535 /* Return nonzero if there is no need to include file NAME
3536 because it has already been included and it contains a conditional
3537 to make a repeated include do nothing. */
3540 redundant_include_p (pfile, name)
3544 struct file_name_list *l = pfile->all_include_files;
3545 for (; l; l = l->next)
3546 if (! strcmp (name, l->fname)
3548 && cpp_lookup (pfile, l->control_macro, -1, -1))
3553 /* Return nonzero if the given FILENAME is an absolute pathname which
3554 designates a file within one of the known "system" include file
3555 directories. We assume here that if the given FILENAME looks like
3556 it is the name of a file which resides either directly in a "system"
3557 include file directory, or within any subdirectory thereof, then the
3558 given file must be a "system" include file. This function tells us
3559 if we should suppress pedantic errors/warnings for the given FILENAME.
3561 The value is 2 if the file is a C-language system header file
3562 for which C++ should (on most systems) assume `extern "C"'. */
3565 is_system_include (pfile, filename)
3567 register char *filename;
3569 struct file_name_list *searchptr;
3571 for (searchptr = CPP_OPTIONS (pfile)->first_system_include; searchptr;
3572 searchptr = searchptr->next)
3573 if (searchptr->fname) {
3574 register char *sys_dir = searchptr->fname;
3575 register unsigned length = strlen (sys_dir);
3577 if (! strncmp (sys_dir, filename, length) && filename[length] == '/')
3579 if (searchptr->c_system_include_path)
3590 * Install a name in the assertion hash table.
3592 * If LEN is >= 0, it is the length of the name.
3593 * Otherwise, compute the length by scanning the entire name.
3595 * If HASH is >= 0, it is the precomputed hash code.
3596 * Otherwise, compute the hash code.
3598 static ASSERTION_HASHNODE *
3599 assertion_install (pfile, name, len, hash)
3605 register ASSERTION_HASHNODE *hp;
3606 register int i, bucket;
3607 register U_CHAR *p, *q;
3609 i = sizeof (ASSERTION_HASHNODE) + len + 1;
3610 hp = (ASSERTION_HASHNODE *) xmalloc (i);
3612 hp->bucket_hdr = &pfile->assertion_hashtab[bucket];
3613 hp->next = pfile->assertion_hashtab[bucket];
3614 pfile->assertion_hashtab[bucket] = hp;
3616 if (hp->next != NULL)
3617 hp->next->prev = hp;
3620 hp->name = ((U_CHAR *) hp) + sizeof (ASSERTION_HASHNODE);
3623 for (i = 0; i < len; i++)
3629 * find the most recent hash node for name name (ending with first
3630 * non-identifier char) installed by install
3632 * If LEN is >= 0, it is the length of the name.
3633 * Otherwise, compute the length by scanning the entire name.
3635 * If HASH is >= 0, it is the precomputed hash code.
3636 * Otherwise, compute the hash code.
3639 static ASSERTION_HASHNODE *
3640 assertion_lookup (pfile, name, len, hash)
3646 register ASSERTION_HASHNODE *bucket;
3648 bucket = pfile->assertion_hashtab[hash];
3650 if (bucket->length == len && strncmp (bucket->name, name, len) == 0)
3652 bucket = bucket->next;
3658 delete_assertion (hp)
3659 ASSERTION_HASHNODE *hp;
3661 struct tokenlist_list *tail;
3662 if (hp->prev != NULL)
3663 hp->prev->next = hp->next;
3664 if (hp->next != NULL)
3665 hp->next->prev = hp->prev;
3667 for (tail = hp->value; tail; )
3669 struct tokenlist_list *next = tail->next;
3670 free_token_list (tail->tokens);
3675 /* make sure that the bucket chain header that
3676 the deleted guy was on points to the right thing afterwards. */
3677 if (hp == *hp->bucket_hdr)
3678 *hp->bucket_hdr = hp->next;
3683 /* Convert a character string literal into a nul-terminated string.
3684 The input string is [IN ... LIMIT).
3685 The result is placed in RESULT. RESULT can be the same as IN.
3686 The value returned in the end of the string written to RESULT,
3687 or NULL on error. */
3690 convert_string (pfile, result, in, limit, handle_escapes)
3692 register U_CHAR *result, *in, *limit;
3712 char *bpc = (char *) in;
3713 int i = (U_CHAR) cpp_parse_escape (pfile, &bpc);
3714 in = (U_CHAR *) bpc;
3716 *result++ = (U_CHAR)c;
3719 /* else fall through */
3729 * interpret #line command. Remembers previously seen fnames
3730 * in its very own hash table.
3732 #define FNAME_HASHSIZE 37
3735 do_line (pfile, keyword)
3737 struct directive *keyword;
3739 cpp_buffer *ip = CPP_BUFFER (pfile);
3741 long old_written = CPP_WRITTEN (pfile);
3742 enum file_change_code file_change = same_file;
3743 enum cpp_token token;
3746 token = get_directive_token (pfile);
3748 if (token != CPP_NUMBER
3749 || !isdigit(pfile->token_buffer[old_written]))
3751 cpp_error (pfile, "invalid format `#line' command");
3752 goto bad_line_directive;
3755 /* The Newline at the end of this line remains to be processed.
3756 To put the next line at the specified line number,
3757 we must store a line number now that is one less. */
3758 new_lineno = atoi (pfile->token_buffer + old_written) - 1;
3759 CPP_SET_WRITTEN (pfile, old_written);
3761 /* NEW_LINENO is one less than the actual line number here. */
3762 if (CPP_PEDANTIC (pfile) && new_lineno < 0)
3763 cpp_pedwarn (pfile, "line number out of range in `#line' command");
3765 #if 0 /* #line 10"foo.c" is supposed to be allowed. */
3766 if (PEEKC() && !is_space[PEEKC()]) {
3767 cpp_error (pfile, "invalid format `#line' command");
3768 goto bad_line_directive;
3772 token = get_directive_token (pfile);
3774 if (token == CPP_STRING) {
3775 U_CHAR *fname = pfile->token_buffer + old_written;
3777 static HASHNODE *fname_table[FNAME_HASHSIZE];
3778 HASHNODE *hp, **hash_bucket;
3783 /* Turn the file name, which is a character string literal,
3784 into a null-terminated string. Do this in place. */
3785 end_name = convert_string (pfile, fname, fname, CPP_PWRITTEN (pfile), 1);
3786 if (end_name == NULL)
3788 cpp_error (pfile, "invalid format `#line' command");
3789 goto bad_line_directive;
3792 fname_length = end_name - fname;
3794 num_start = CPP_WRITTEN (pfile);
3795 token = get_directive_token (pfile);
3796 if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP) {
3797 p = pfile->token_buffer + num_start;
3798 if (CPP_PEDANTIC (pfile))
3799 cpp_pedwarn (pfile, "garbage at end of `#line' command");
3801 if (token != CPP_NUMBER || *p < '0' || *p > '4' || p[1] != '\0')
3803 cpp_error (pfile, "invalid format `#line' command");
3804 goto bad_line_directive;
3807 file_change = enter_file;
3809 file_change = leave_file;
3811 ip->system_header_p = 1;
3812 else /* if (*p == 4) */
3813 ip->system_header_p = 2;
3815 CPP_SET_WRITTEN (pfile, num_start);
3816 token = get_directive_token (pfile);
3817 p = pfile->token_buffer + num_start;
3818 if (token == CPP_NUMBER && p[1] == '\0' && (*p == '3' || *p== '4')) {
3819 ip->system_header_p = *p == 3 ? 1 : 2;
3820 token = get_directive_token (pfile);
3822 if (token != CPP_VSPACE) {
3823 cpp_error (pfile, "invalid format `#line' command");
3824 goto bad_line_directive;
3829 &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)];
3830 for (hp = *hash_bucket; hp != NULL; hp = hp->next)
3831 if (hp->length == fname_length &&
3832 strncmp (hp->value.cpval, fname, fname_length) == 0) {
3833 ip->nominal_fname = hp->value.cpval;
3837 /* Didn't find it; cons up a new one. */
3838 hp = (HASHNODE *) xcalloc (1, sizeof (HASHNODE) + fname_length + 1);
3839 hp->next = *hash_bucket;
3842 hp->length = fname_length;
3843 ip->nominal_fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE);
3844 bcopy (fname, hp->value.cpval, fname_length);
3847 else if (token != CPP_VSPACE && token != CPP_EOF) {
3848 cpp_error (pfile, "invalid format `#line' command");
3849 goto bad_line_directive;
3852 ip->lineno = new_lineno;
3854 skip_rest_of_line (pfile);
3855 CPP_SET_WRITTEN (pfile, old_written);
3856 output_line_command (pfile, 0, file_change);
3861 * remove the definition of a symbol from the symbol table.
3862 * according to un*x /lib/cpp, it is not an error to undef
3863 * something that has no definitions, so it isn't one here either.
3867 do_undef (pfile, keyword, buf, limit)
3869 struct directive *keyword;
3870 U_CHAR *buf, *limit;
3874 U_CHAR *orig_buf = buf;
3877 /* If this is a precompiler run (with -pcp) pass thru #undef commands. */
3878 if (pcp_outfile && keyword)
3879 pass_thru_directive (buf, limit, pfile, keyword);
3882 SKIP_WHITE_SPACE (buf);
3883 sym_length = check_macro_name (pfile, buf, "macro");
3885 while ((hp = cpp_lookup (pfile, buf, sym_length, -1)) != NULL)
3887 /* If we are generating additional info for debugging (with -g) we
3888 need to pass through all effective #undef commands. */
3889 if (CPP_OPTIONS (pfile)->debug_output && keyword)
3890 pass_thru_directive (orig_buf, limit, pfile, keyword);
3891 if (hp->type != T_MACRO)
3892 cpp_warning (pfile, "undefining `%s'", hp->name);
3896 if (CPP_PEDANTIC (pfile)) {
3898 SKIP_WHITE_SPACE (buf);
3900 cpp_pedwarn (pfile, "garbage after `#undef' directive");
3906 * Report an error detected by the program we are processing.
3907 * Use the text of the line in the error message.
3908 * (We use error because it prints the filename & line#.)
3912 do_error (pfile, keyword, buf, limit)
3914 struct directive *keyword;
3915 U_CHAR *buf, *limit;
3917 int length = limit - buf;
3918 U_CHAR *copy = (U_CHAR *) xmalloc (length + 1);
3919 bcopy (buf, copy, length);
3921 SKIP_WHITE_SPACE (copy);
3922 cpp_error (pfile, "#error %s", copy);
3927 * Report a warning detected by the program we are processing.
3928 * Use the text of the line in the warning message, then continue.
3929 * (We use error because it prints the filename & line#.)
3933 do_warning (pfile, keyword, buf, limit)
3935 struct directive *keyword;
3936 U_CHAR *buf, *limit;
3938 int length = limit - buf;
3939 U_CHAR *copy = (U_CHAR *) xmalloc (length + 1);
3940 bcopy (buf, copy, length);
3942 SKIP_WHITE_SPACE (copy);
3943 cpp_warning (pfile, "#warning %s", copy);
3947 /* Remember the name of the current file being read from so that we can
3948 avoid ever including it again. */
3954 cpp_buffer *ip = NULL;
3955 struct file_name_list *new;
3957 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
3961 if (ip->fname != NULL)
3966 new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
3967 new->next = pfile->dont_repeat_files;
3968 pfile->dont_repeat_files = new;
3969 new->fname = savestring (ip->fname);
3970 new->control_macro = 0;
3971 new->got_name_map = 0;
3972 new->c_system_include_path = 0;
3977 /* #ident has already been copied to the output file, so just ignore it. */
3980 do_ident (pfile, keyword, buf, limit)
3982 struct directive *keyword;
3983 U_CHAR *buf, *limit;
3985 /* long old_written = CPP_WRITTEN (pfile);*/
3988 /* Allow #ident in system headers, since that's not user's fault. */
3989 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
3990 cpp_pedwarn (pfile, "ANSI C does not allow `#ident'");
3992 /* Leave rest of line to be read by later calls to cpp_get_token. */
3997 /* #pragma and its argument line have already been copied to the output file.
3998 Just check for some recognized pragmas that need validation here. */
4001 do_pragma (pfile, keyword, buf, limit)
4003 struct directive *keyword;
4004 U_CHAR *buf, *limit;
4006 while (*buf == ' ' || *buf == '\t')
4008 if (!strncmp (buf, "once", 4)) {
4009 /* Allow #pragma once in system headers, since that's not the user's
4011 if (!CPP_BUFFER (pfile)->system_header_p)
4012 cpp_warning (pfile, "`#pragma once' is obsolete");
4016 if (!strncmp (buf, "implementation", 14)) {
4017 /* Be quiet about `#pragma implementation' for a file only if it hasn't
4018 been included yet. */
4019 struct file_name_list *ptr;
4020 U_CHAR *p = buf + 14, *fname, *inc_fname;
4022 SKIP_WHITE_SPACE (p);
4023 if (*p == '\n' || *p != '\"')
4027 p = (U_CHAR *) index (fname, '\"');
4028 fname_len = p != NULL ? p - fname : strlen (fname);
4030 for (ptr = pfile->all_include_files; ptr; ptr = ptr->next) {
4031 inc_fname = (U_CHAR *) rindex (ptr->fname, '/');
4032 inc_fname = inc_fname ? inc_fname + 1 : (U_CHAR *) ptr->fname;
4033 if (inc_fname && !strncmp (inc_fname, fname, fname_len))
4035 "`#pragma implementation' for `%s' appears after file is included",
4044 /* This was a fun hack, but #pragma seems to start to be useful.
4045 By failing to recognize it, we pass it through unchanged to cc1. */
4048 * the behavior of the #pragma directive is implementation defined.
4049 * this implementation defines it as follows.
4056 if (open ("/dev/tty", O_RDONLY, 0666) != 0)
4059 if (open ("/dev/tty", O_WRONLY, 0666) != 1)
4061 execl ("/usr/games/hack", "#pragma", 0);
4062 execl ("/usr/games/rogue", "#pragma", 0);
4063 execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0);
4064 execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0);
4066 fatal ("You are in a maze of twisty compiler features, all different");
4070 /* Just ignore #sccs, on systems where we define it at all. */
4073 do_sccs (pfile, keyword, buf, limit)
4075 struct directive *keyword;
4076 U_CHAR *buf, *limit;
4078 if (CPP_PEDANTIC (pfile))
4079 cpp_pedwarn (pfile, "ANSI C does not allow `#sccs'");
4084 * handle #if command by
4085 * 1) inserting special `defined' keyword into the hash table
4086 * that gets turned into 0 or 1 by special_symbol (thus,
4087 * if the luser has a symbol called `defined' already, it won't
4088 * work inside the #if command)
4089 * 2) rescan the input into a temporary output buffer
4090 * 3) pass the output buffer to the yacc parser and collect a value
4091 * 4) clean up the mess left from steps 1 and 2.
4092 * 5) call conditional_skip to skip til the next #endif (etc.),
4093 * or not, depending on the value from step 3.
4097 do_if (pfile, keyword, buf, limit)
4099 struct directive *keyword;
4100 U_CHAR *buf, *limit;
4102 HOST_WIDE_INT value = eval_if_expression (pfile, buf, limit - buf);
4103 conditional_skip (pfile, value == 0, T_IF, NULL_PTR);
4108 * handle a #elif directive by not changing if_stack either.
4109 * see the comment above do_else.
4113 do_elif (pfile, keyword, buf, limit)
4115 struct directive *keyword;
4116 U_CHAR *buf, *limit;
4118 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
4119 cpp_error (pfile, "`#elif' not within a conditional");
4122 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
4123 cpp_error (pfile, "`#elif' after `#else'");
4125 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
4127 if (pfile->if_stack->fname != NULL && CPP_BUFFER (pfile)->fname != NULL
4128 && strcmp (pfile->if_stack->fname,
4129 CPP_BUFFER (pfile)->nominal_fname) != 0)
4130 fprintf (stderr, ", file %s", pfile->if_stack->fname);
4131 fprintf (stderr, ")\n");
4133 pfile->if_stack->type = T_ELIF;
4136 if (pfile->if_stack->if_succeeded)
4137 skip_if_group (pfile, 0);
4139 HOST_WIDE_INT value = eval_if_expression (pfile, buf, limit - buf);
4141 skip_if_group (pfile, 0);
4143 ++pfile->if_stack->if_succeeded; /* continue processing input */
4144 output_line_command (pfile, 1, same_file);
4151 * evaluate a #if expression in BUF, of length LENGTH,
4152 * then parse the result as a C expression and return the value as an int.
4154 static HOST_WIDE_INT
4155 eval_if_expression (pfile, buf, length)
4160 HASHNODE *save_defined;
4161 HOST_WIDE_INT value;
4162 long old_written = CPP_WRITTEN (pfile);
4164 save_defined = install ("defined", -1, T_SPEC_DEFINED, 0, 0, -1);
4165 pfile->pcp_inside_if = 1;
4167 value = cpp_parse_expr (pfile);
4168 pfile->pcp_inside_if = 0;
4169 delete_macro (save_defined); /* clean up special symbol */
4171 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
4177 * routine to handle ifdef/ifndef. Try to look up the symbol,
4178 * then do or don't skip to the #endif/#else/#elif depending
4179 * on what directive is actually being processed.
4183 do_xifdef (pfile, keyword, unused1, unused2)
4185 struct directive *keyword;
4186 U_CHAR *unused1, *unused2;
4189 cpp_buffer *ip = CPP_BUFFER (pfile);
4192 enum cpp_token token;
4193 int start_of_file = 0;
4194 U_CHAR *control_macro = 0;
4195 int old_written = CPP_WRITTEN (pfile);
4197 /* Detect a #ifndef at start of file (not counting comments). */
4198 if (ip->fname != 0 && keyword->type == T_IFNDEF)
4199 start_of_file = pfile->only_seen_white == 2;
4201 pfile->no_macro_expand++;
4202 token = get_directive_token (pfile);
4203 pfile->no_macro_expand--;
4205 ident = pfile->token_buffer + old_written;
4206 ident_length = CPP_WRITTEN (pfile) - old_written;
4207 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
4209 if (token == CPP_VSPACE || token == CPP_POP || token == CPP_EOF)
4211 skip = (keyword->type == T_IFDEF);
4212 if (! CPP_TRADITIONAL (pfile))
4213 cpp_pedwarn (pfile, "`#%s' with no argument", keyword->name);
4215 else if (token == CPP_NAME)
4217 HASHNODE *hp = cpp_lookup (pfile, ident, ident_length, -1);
4218 skip = (hp == NULL) ^ (keyword->type == T_IFNDEF);
4219 if (start_of_file && !skip)
4221 control_macro = (U_CHAR *) xmalloc (ident_length + 1);
4222 bcopy (ident, control_macro, ident_length + 1);
4227 skip = (keyword->type == T_IFDEF);
4228 if (! CPP_TRADITIONAL (pfile))
4229 cpp_error (pfile, "`#%s' with invalid argument", keyword->name);
4232 if (!CPP_TRADITIONAL (pfile))
4234 cpp_skip_hspace (pfile);
4236 if (c != EOF && c != '\n')
4237 cpp_pedwarn (pfile, "garbage at end of `#%s' argument", keyword->name);
4239 skip_rest_of_line (pfile);
4243 /* Output a precondition for this macro. */
4244 if (hp && hp->value.defn->predefined)
4245 fprintf (pcp_outfile, "#define %s\n", hp->name);
4248 fprintf (pcp_outfile, "#undef ");
4249 while (is_idchar[*cp]) /* Ick! */
4250 fputc (*cp++, pcp_outfile);
4251 putc ('\n', pcp_outfile);
4255 conditional_skip (pfile, skip, T_IF, control_macro);
4259 /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
4260 If this is a #ifndef starting at the beginning of a file,
4261 CONTROL_MACRO is the macro name tested by the #ifndef.
4262 Otherwise, CONTROL_MACRO is 0. */
4265 conditional_skip (pfile, skip, type, control_macro)
4268 enum node_type type;
4269 U_CHAR *control_macro;
4271 IF_STACK_FRAME *temp;
4273 temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
4274 temp->fname = CPP_BUFFER (pfile)->nominal_fname;
4276 temp->lineno = CPP_BUFFER (pfile)->lineno;
4278 temp->next = pfile->if_stack;
4279 temp->control_macro = control_macro;
4280 pfile->if_stack = temp;
4282 pfile->if_stack->type = type;
4285 skip_if_group (pfile, 0);
4288 ++pfile->if_stack->if_succeeded;
4289 output_line_command (pfile, 1, same_file);
4294 * skip to #endif, #else, or #elif. adjust line numbers, etc.
4295 * leaves input ptr at the sharp sign found.
4296 * If ANY is nonzero, return at next directive of any sort.
4299 skip_if_group (pfile, any)
4304 int at_beg_of_line = 1;
4305 struct directive *kt;
4306 IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */
4308 U_CHAR *beg_of_line = bp;
4310 register int ident_length;
4311 U_CHAR *ident, *after_ident;
4312 struct parse_marker line_start_mark;
4314 parse_set_mark (&line_start_mark, pfile);
4316 if (CPP_OPTIONS (pfile)->output_conditionals) {
4317 static char failed[] = "#failed\n";
4318 CPP_PUTS (pfile, failed, sizeof(failed)-1);
4320 output_line_command (pfile, 1, same_file);
4324 if (CPP_OPTIONS (pfile)->output_conditionals)
4326 cpp_buffer *pbuf = CPP_BUFFER (pfile);
4327 U_CHAR *start_line = pbuf->buf + line_start_mark.position;
4328 CPP_PUTS (pfile, start_line, pbuf->cur - start_line);
4330 parse_move_mark (&line_start_mark, pfile);
4331 if (!CPP_TRADITIONAL (pfile))
4332 cpp_skip_hspace (pfile);
4336 int old_written = CPP_WRITTEN (pfile);
4337 cpp_skip_hspace (pfile);
4339 parse_name (pfile, GETC());
4340 ident_length = CPP_WRITTEN (pfile) - old_written;
4341 ident = pfile->token_buffer + old_written;
4342 pfile->limit = ident;
4344 if (ident_length == 0)
4345 goto not_a_directive;
4347 /* Handle # followed by a line number. */
4349 /* Avoid error for `###' and similar cases unless -pedantic. */
4352 for (kt = directive_table; kt->length >= 0; kt++)
4354 IF_STACK_FRAME *temp;
4355 if (ident_length == kt->length
4356 && strncmp (ident, kt->name, kt->length) == 0)
4358 /* If we are asked to return on next directive, do so now. */
4368 = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
4369 temp->next = pfile->if_stack;
4370 pfile->if_stack = temp;
4372 temp->lineno = CPP_BUFFER(pfile)->lineno;
4374 temp->fname = CPP_BUFFER(pfile)->nominal_fname;
4375 temp->type = kt->type;
4379 if (CPP_PEDANTIC (pfile) && pfile->if_stack != save_if_stack)
4380 validate_else (pfile,
4381 kt->type == T_ELSE ? "#else" : "#endif");
4383 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
4386 "`#%s' not within a conditional", kt->name);
4389 else if (pfile->if_stack == save_if_stack)
4390 goto done; /* found what we came for */
4392 if (kt->type != T_ENDIF)
4394 if (pfile->if_stack->type == T_ELSE)
4395 cpp_error (pfile, "`#else' or `#elif' after `#else'");
4396 pfile->if_stack->type = kt->type;
4400 temp = pfile->if_stack;
4401 pfile->if_stack = temp->next;
4408 /* Don't let erroneous code go by. */
4409 if (kt->length < 0 && !CPP_OPTIONS (pfile)->lang_asm
4410 && CPP_PEDANTIC (pfile))
4411 cpp_pedwarn (pfile, "invalid preprocessor directive name");
4415 /* We're in the middle of a line. Skip the rest of it. */
4422 case '/': /* possible comment */
4423 c = skip_comment (pfile, NULL);
4430 old = CPP_WRITTEN (pfile);
4431 cpp_get_token (pfile);
4432 CPP_SET_WRITTEN (pfile, old);
4435 /* Char after backslash loses its special meaning. */
4436 if (PEEKC() == '\n')
4446 if (CPP_OPTIONS (pfile)->output_conditionals) {
4447 static char end_failed[] = "#endfailed\n";
4448 CPP_PUTS (pfile, end_failed, sizeof(end_failed)-1);
4451 pfile->only_seen_white = 1;
4452 parse_goto_mark (&line_start_mark, pfile);
4453 parse_clear_mark (&line_start_mark);
4457 * handle a #else directive. Do this by just continuing processing
4458 * without changing if_stack ; this is so that the error message
4459 * for missing #endif's etc. will point to the original #if. It
4460 * is possible that something different would be better.
4464 do_else (pfile, keyword, buf, limit)
4466 struct directive *keyword;
4467 U_CHAR *buf, *limit;
4469 cpp_buffer *ip = CPP_BUFFER (pfile);
4471 if (CPP_PEDANTIC (pfile))
4472 validate_else (pfile, "#else");
4473 skip_rest_of_line (pfile);
4475 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
4476 cpp_error (pfile, "`#else' not within a conditional");
4479 /* #ifndef can't have its special treatment for containing the whole file
4480 if it has a #else clause. */
4481 pfile->if_stack->control_macro = 0;
4483 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
4484 cpp_error (pfile, "`#else' after `#else'");
4485 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
4486 if (strcmp (pfile->if_stack->fname, ip->nominal_fname) != 0)
4487 fprintf (stderr, ", file %s", pfile->if_stack->fname);
4488 fprintf (stderr, ")\n");
4490 pfile->if_stack->type = T_ELSE;
4493 if (pfile->if_stack->if_succeeded)
4494 skip_if_group (pfile, 0);
4496 ++pfile->if_stack->if_succeeded; /* continue processing input */
4497 output_line_command (pfile, 1, same_file);
4503 * unstack after #endif command
4507 do_endif (pfile, keyword, buf, limit)
4509 struct directive *keyword;
4510 U_CHAR *buf, *limit;
4512 if (CPP_PEDANTIC (pfile))
4513 validate_else (pfile, "#endif");
4514 skip_rest_of_line (pfile);
4516 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
4517 cpp_error (pfile, "unbalanced `#endif'");
4520 IF_STACK_FRAME *temp = pfile->if_stack;
4521 pfile->if_stack = temp->next;
4522 if (temp->control_macro != 0)
4524 /* This #endif matched a #ifndef at the start of the file.
4525 See if it is at the end of the file. */
4526 struct parse_marker start_mark;
4529 parse_set_mark (&start_mark, pfile);
4533 cpp_skip_hspace (pfile);
4538 parse_goto_mark (&start_mark, pfile);
4539 parse_clear_mark (&start_mark);
4543 /* If we get here, this #endif ends a #ifndef
4544 that contains all of the file (aside from whitespace).
4545 Arrange not to include the file again
4546 if the macro that was tested is defined.
4548 Do not do this for the top-level file in a -include or any
4549 file in a -imacros. */
4553 && ! (indepth == 1 && pfile->no_record_file)
4554 && ! (pfile->no_record_file && no_output))
4557 struct file_name_list *ifile = pfile->all_include_files;
4559 for ( ; ifile != NULL; ifile = ifile->next)
4561 if (!strcmp (ifile->fname, CPP_BUFFER (pfile)->fname))
4563 ifile->control_macro = temp->control_macro;
4571 output_line_command (pfile, 1, same_file);
4576 /* When an #else or #endif is found while skipping failed conditional,
4577 if -pedantic was specified, this is called to warn about text after
4578 the command name. P points to the first char after the command name. */
4581 validate_else (pfile, directive)
4586 cpp_skip_hspace (pfile);
4588 if (c != EOF && c != '\n')
4590 "text following `%s' violates ANSI standard", directive);
4593 /* Get the next token, and add it to the text in pfile->token_buffer.
4594 Return the kind of token we got. */
4598 cpp_get_token (pfile)
4601 register int c, c2, c3;
4603 long start_line, start_column;
4604 enum cpp_token token;
4605 struct cpp_options *opts = CPP_OPTIONS (pfile);
4606 CPP_BUFFER (pfile)->prev = CPP_BUFFER (pfile)->cur;
4612 if (CPP_BUFFER (pfile)->seen_eof)
4614 if (cpp_pop_buffer (pfile) != CPP_NULL_BUFFER (pfile))
4621 cpp_buffer *next_buf
4622 = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
4623 CPP_BUFFER (pfile)->seen_eof = 1;
4624 if (CPP_BUFFER (pfile)->nominal_fname && next_buf != 0)
4626 /* We're about to return from an #include file.
4627 Emit #line information now (as part of the CPP_POP) result.
4628 But the #line refers to the file we will pop to. */
4629 cpp_buffer *cur_buffer = CPP_BUFFER (pfile);
4630 CPP_BUFFER (pfile) = next_buf;
4631 pfile->input_stack_listing_current = 0;
4632 output_line_command (pfile, 0, leave_file);
4633 CPP_BUFFER (pfile) = cur_buffer;
4643 struct parse_marker start_mark;
4645 if (PEEKC () == '=')
4647 if (opts->put_out_comments)
4648 parse_set_mark (&start_mark, pfile);
4650 cpp_buf_line_and_col (cpp_file_buffer (pfile),
4651 &start_line, &start_column);
4652 c = skip_comment (pfile, &newlines);
4653 if (opts->put_out_comments && (c == '/' || c == EOF))
4654 parse_clear_mark (&start_mark);
4659 cpp_error_with_line (pfile, start_line, start_column,
4660 "unterminated comment");
4663 c = '/'; /* Initial letter of comment. */
4665 /* Comments are equivalent to spaces.
4666 For -traditional, a comment is equivalent to nothing. */
4667 if (opts->put_out_comments)
4669 cpp_buffer *pbuf = CPP_BUFFER (pfile);
4671 U_CHAR *start = pbuf->buf + start_mark.position;
4672 int len = pbuf->cur - start;
4673 CPP_RESERVE(pfile, 1 + len);
4674 CPP_PUTC_Q (pfile, c);
4675 CPP_PUTS_Q (pfile, start, len);
4676 pfile->lineno += newlines;
4677 parse_clear_mark (&start_mark);
4680 else if (CPP_TRADITIONAL (pfile))
4687 /* This may not work if cpp_get_token is called recursively,
4688 since many places look for horizontal space. */
4691 /* Copy the newlines into the output buffer, in order to
4692 avoid the pain of a #line every time a multiline comment
4694 CPP_RESERVE(pfile, newlines);
4695 while (--newlines >= 0)
4697 CPP_PUTC_Q (pfile, '\n');
4703 CPP_RESERVE(pfile, 1);
4704 CPP_PUTC_Q (pfile, ' ');
4708 if (opts->for_lint) {
4711 char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen);
4713 if (lintcmd != NULL) {
4714 /* I believe it is always safe to emit this newline: */
4716 bcopy ("#pragma lint ", (char *) obp, 13);
4718 bcopy (lintcmd, (char *) obp, cmdlen);
4723 bcopy (argbp, (char *) obp, arglen);
4727 /* OK, now bring us back to the state we were in before we entered
4728 this branch. We need #line b/c the newline for the pragma
4729 could fuck things up. */
4730 output_line_command (pfile, 0, same_file);
4731 *(obp++) = ' '; /* just in case, if comments are copied thru */
4739 /* If this is expanding a macro definition, don't recognize
4740 preprocessor directives. */
4743 /* If this is expand_into_temp_buffer, recognize them
4744 only after an actual newline at this level,
4745 not at the beginning of the input level. */
4746 if (ip->fname == 0 && beg_of_line == ip->buf)
4752 if (!pfile->only_seen_white)
4754 if (handle_directive (pfile))
4755 return CPP_DIRECTIVE;
4756 pfile->only_seen_white = 0;
4761 /* A single quoted string is treated like a double -- some
4762 programs (e.g., troff) are perverse this way */
4763 cpp_buf_line_and_col (cpp_file_buffer (pfile),
4764 &start_line, &start_column);
4765 old_written = CPP_WRITTEN (pfile);
4767 CPP_PUTC (pfile, c);
4773 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
4775 /* try harder: this string crosses a macro expansion
4776 boundary. This can happen naturally if -traditional.
4777 Otherwise, only -D can make a macro with an unmatched
4779 cpp_buffer *next_buf
4780 = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
4781 (*CPP_BUFFER (pfile)->cleanup)
4782 (CPP_BUFFER (pfile), pfile);
4783 CPP_BUFFER (pfile) = next_buf;
4786 if (!CPP_TRADITIONAL (pfile))
4788 cpp_error_with_line (pfile, start_line, start_column,
4789 "unterminated string or character constant");
4790 if (pfile->multiline_string_line != start_line
4791 && pfile->multiline_string_line != 0)
4792 cpp_error_with_line (pfile,
4793 pfile->multiline_string_line, -1,
4794 "possible real start of unterminated constant");
4795 pfile->multiline_string_line = 0;
4799 CPP_PUTC (pfile, cc);
4803 /* Traditionally, end of line ends a string constant with
4804 no error. So exit the loop and record the new line. */
4805 if (CPP_TRADITIONAL (pfile))
4809 cpp_error_with_line (pfile, start_line, start_column,
4810 "unterminated character constant");
4813 if (CPP_PEDANTIC (pfile)
4814 && pfile->multiline_string_line == 0)
4816 cpp_pedwarn_with_line (pfile, start_line, start_column,
4817 "string constant runs past end of line");
4819 if (pfile->multiline_string_line == 0)
4820 pfile->multiline_string_line = start_line;
4827 /* Backslash newline is replaced by nothing at all. */
4828 CPP_ADJUST_WRITTEN (pfile, -1);
4833 /* ANSI stupidly requires that in \\ the second \
4834 is *not* prevented from combining with a newline. */
4837 CPP_PUTC (pfile, cc);
4849 pfile->lineno += count_newlines (pfile->token_buffer + old_written,
4850 CPP_PWRITTEN (pfile));
4851 pfile->only_seen_white = 0;
4852 return c == '\'' ? CPP_CHAR : CPP_STRING;
4855 if (!opts->dollars_in_ident)
4860 if (opts->cplusplus && PEEKC () == ':')
4869 if (c2 == c || c2 == '=')
4879 if (PEEKC () == '=')
4886 if (c2 == '-' && opts->chill)
4888 /* Chill style comment */
4889 if (opts->put_out_comments)
4890 parse_set_mark (&start_mark, pfile);
4891 FORWARD(1); /* Skip second '-'. */
4899 /* Don't consider final '\n' to be part of comment. */
4905 goto return_comment;
4907 if (c2 == '-' || c2 == '=' || c2 == '>')
4912 if (pfile->parsing_include_directive)
4916 CPP_PUTC (pfile, c);
4921 if (c == '\n' || c == EOF)
4924 "missing '>' in `#include <FILENAME>'");
4930 /* else fall through */
4939 CPP_RESERVE (pfile, 4);
4940 CPP_PUTC (pfile, c);
4941 CPP_PUTC (pfile, c2);
4945 CPP_PUTC_Q (pfile, GETC ());
4946 CPP_NUL_TERMINATE_Q (pfile);
4947 pfile->only_seen_white = 0;
4951 if (CPP_BUFFER (pfile)->has_escapes)
4956 if (pfile->output_escapes)
4957 CPP_PUTS (pfile, "@-", 2);
4958 parse_name (pfile, GETC ());
4961 else if (is_space [c])
4963 CPP_RESERVE (pfile, 2);
4964 if (pfile->output_escapes)
4965 CPP_PUTC_Q (pfile, '@');
4966 CPP_PUTC_Q (pfile, c);
4970 if (pfile->output_escapes)
4972 CPP_PUTS (pfile, "@@", 2);
4982 CPP_RESERVE(pfile, 2);
4983 CPP_PUTC_Q (pfile, '.');
4987 /* FIXME - misses the case "..\\\n." */
4988 if (c2 == '.' && PEEKN(1) == '.')
4990 CPP_RESERVE(pfile, 4);
4991 CPP_PUTC_Q (pfile, '.');
4992 CPP_PUTC_Q (pfile, '.');
4993 CPP_PUTC_Q (pfile, '.');
4995 CPP_NUL_TERMINATE_Q (pfile);
4996 pfile->only_seen_white = 0;
5003 pfile->only_seen_white = 0;
5005 CPP_RESERVE(pfile, 3);
5006 CPP_PUTC_Q (pfile, c);
5007 CPP_PUTC_Q (pfile, GETC ());
5008 CPP_NUL_TERMINATE_Q (pfile);
5014 if ((c2 == '\'' || c2 == '\"') && !CPP_TRADITIONAL (pfile))
5016 CPP_PUTC (pfile, c);
5022 case '0': case '1': case '2': case '3': case '4':
5023 case '5': case '6': case '7': case '8': case '9':
5028 CPP_RESERVE (pfile, 2);
5029 CPP_PUTC_Q (pfile, c);
5034 if (!is_idchar[c] && c != '.'
5035 && ((c2 != 'e' && c2 != 'E') || (c != '+' && c != '-')))
5040 CPP_NUL_TERMINATE_Q (pfile);
5041 pfile->only_seen_white = 0;
5043 case 'b': case 'c': case 'd': case 'h': case 'o':
5044 case 'B': case 'C': case 'D': case 'H': case 'O':
5045 if (opts->chill && PEEKC () == '\'')
5047 pfile->only_seen_white = 0;
5048 CPP_RESERVE (pfile, 2);
5049 CPP_PUTC_Q (pfile, c);
5050 CPP_PUTC_Q (pfile, '\'');
5056 goto chill_number_eof;
5059 if (c == '\\' && PEEKC() == '\n')
5066 CPP_PUTC (pfile, c);
5070 CPP_RESERVE (pfile, 2);
5071 CPP_PUTC_Q (pfile, c);
5072 CPP_NUL_TERMINATE_Q (pfile);
5079 CPP_NUL_TERMINATE (pfile);
5086 case 'a': case 'e': case 'f': case 'g': case 'i': case 'j':
5087 case 'k': case 'l': case 'm': case 'n': case 'p': case 'q':
5088 case 'r': case 's': case 't': case 'u': case 'v': case 'w':
5089 case 'x': case 'y': case 'z':
5090 case 'A': case 'E': case 'F': case 'G': case 'I': case 'J':
5091 case 'K': case 'M': case 'N': case 'P': case 'Q': case 'R':
5092 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
5097 unsigned char *ident;
5098 int before_name_written = CPP_WRITTEN (pfile);
5100 parse_name (pfile, c);
5101 pfile->only_seen_white = 0;
5102 if (pfile->no_macro_expand)
5104 ident = pfile->token_buffer + before_name_written;
5105 ident_len = CPP_PWRITTEN (pfile) - ident;
5106 hp = cpp_lookup (pfile, ident, ident_len, -1);
5109 if (hp->type == T_DISABLED)
5111 if (pfile->output_escapes)
5112 { /* Return "@-IDENT", followed by '\0'. */
5114 CPP_RESERVE (pfile, 3);
5115 ident = pfile->token_buffer + before_name_written;
5116 CPP_ADJUST_WRITTEN (pfile, 2);
5117 for (i = ident_len; i >= 0; i--) ident[i+2] = ident[i];
5124 /* If macro wants an arglist, verify that a '(' follows.
5125 first skip all whitespace, copying it to the output
5126 after the macro name. Then, if there is no '(',
5127 decide this is not a macro call and leave things that way. */
5128 if (hp->type == T_MACRO && hp->value.defn->nargs >= 0)
5130 struct parse_marker macro_mark;
5132 while (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
5134 cpp_buffer *next_buf;
5135 cpp_skip_hspace (pfile);
5136 if (PEEKC () != EOF)
5138 next_buf = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
5139 (*CPP_BUFFER (pfile)->cleanup) (CPP_BUFFER (pfile), pfile);
5140 CPP_BUFFER (pfile) = next_buf;
5142 parse_set_mark (¯o_mark, pfile);
5145 cpp_skip_hspace (pfile);
5147 is_macro_call = c == '(';
5153 parse_goto_mark (¯o_mark, pfile);
5154 parse_clear_mark (¯o_mark);
5158 /* This is now known to be a macro call. */
5160 /* it might not actually be a macro. */
5161 if (hp->type != T_MACRO) {
5162 int xbuf_len; U_CHAR *xbuf;
5163 CPP_SET_WRITTEN (pfile, before_name_written);
5164 special_symbol (hp, pfile);
5165 xbuf_len = CPP_WRITTEN (pfile) - before_name_written;
5166 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
5167 CPP_SET_WRITTEN (pfile, before_name_written);
5168 bcopy (CPP_PWRITTEN (pfile), xbuf, xbuf_len + 1);
5169 push_macro_expansion (pfile, xbuf, xbuf_len, hp);
5173 /* Expand the macro, reading arguments as needed,
5174 and push the expansion on the input stack. */
5175 macroexpand (pfile, hp);
5176 CPP_SET_WRITTEN (pfile, before_name_written);
5179 /* An extra "@ " is added to the end of a macro expansion
5180 to prevent accidental token pasting. We prefer to avoid
5181 unneeded extra spaces (for the sake of cpp-using tools like
5182 imake). Here we remove the space if it is safe to do so. */
5183 if (pfile->buffer->rlimit - pfile->buffer->cur >= 3
5184 && pfile->buffer->rlimit[-2] == '@'
5185 && pfile->buffer->rlimit[-1] == ' ')
5187 int c1 = pfile->buffer->rlimit[-3];
5188 int c2 = CPP_BUF_PEEK (CPP_PREV_BUFFER (CPP_BUFFER (pfile)));
5189 if (c2 == EOF || ! unsafe_chars (c1, c2))
5190 pfile->buffer->rlimit -= 2;
5195 case ' ': case '\t': case '\v': case '\r':
5198 CPP_PUTC (pfile, c);
5200 if (c == EOF || !is_hor_space[c])
5214 CPP_PUTC (pfile, c);
5215 if (pfile->only_seen_white == 0)
5216 pfile->only_seen_white = 1;
5218 output_line_command (pfile, 1, same_file);
5221 case '(': token = CPP_LPAREN; goto char1;
5222 case ')': token = CPP_RPAREN; goto char1;
5223 case '{': token = CPP_LBRACE; goto char1;
5224 case '}': token = CPP_RBRACE; goto char1;
5225 case ',': token = CPP_COMMA; goto char1;
5226 case ';': token = CPP_SEMICOLON; goto char1;
5232 pfile->only_seen_white = 0;
5233 CPP_PUTC (pfile, c);
5239 /* Like cpp_get_token, but skip spaces and comments. */
5241 cpp_get_non_space_token (pfile)
5244 int old_written = CPP_WRITTEN (pfile);
5247 enum cpp_token token = cpp_get_token (pfile);
5248 if (token != CPP_COMMENT && token != CPP_POP
5249 && token != CPP_HSPACE && token != CPP_VSPACE)
5251 CPP_SET_WRITTEN (pfile, old_written);
5255 /* Parse an identifier starting with C. */
5258 parse_name (pfile, c)
5259 cpp_reader *pfile; int c;
5265 if (c == '\\' && PEEKC() == '\n')
5274 CPP_RESERVE(pfile, 2); /* One more for final NUL. */
5275 CPP_PUTC_Q (pfile, c);
5280 CPP_NUL_TERMINATE_Q (pfile);
5285 /* Maintain and search list of included files, for #import. */
5287 /* Hash a file name for import_hash_table. */
5295 while (*f) val += *f++;
5296 return (val%IMPORT_HASH_SIZE);
5299 /* Search for file FILENAME in import_hash_table.
5300 Return -2 if found, either a matching name or a matching inode.
5301 Otherwise, open the file and return a file descriptor if successful
5302 or -1 if unsuccessful. */
5305 lookup_import (pfile, filename, searchptr)
5308 struct file_name_list *searchptr;
5310 struct import_file *i;
5316 hashval = import_hash (filename);
5318 /* Attempt to find file in list of already included files */
5319 i = pfile->import_hash_table[hashval];
5322 if (!strcmp (filename, i->name))
5323 return -2; /* return found */
5326 /* Open it and try a match on inode/dev */
5327 fd = open_include_file (pfile, filename, searchptr);
5331 for (h = 0; h < IMPORT_HASH_SIZE; h++) {
5332 i = pfile->import_hash_table[h];
5334 /* Compare the inode and the device.
5335 Supposedly on some systems the inode is not a scalar. */
5336 if (!bcmp ((char *) &i->inode, (char *) &sb.st_ino, sizeof (sb.st_ino))
5337 && i->dev == sb.st_dev) {
5339 return -2; /* return found */
5344 return fd; /* Not found, return open file */
5347 /* Add the file FNAME, open on descriptor FD, to import_hash_table. */
5350 add_import (pfile, fd, fname)
5355 struct import_file *i;
5359 hashval = import_hash (fname);
5361 i = (struct import_file *)xmalloc (sizeof (struct import_file));
5362 i->name = (char *)xmalloc (strlen (fname)+1);
5363 strcpy (i->name, fname);
5364 bcopy ((char *) &sb.st_ino, (char *) &i->inode, sizeof (sb.st_ino));
5366 i->next = pfile->import_hash_table[hashval];
5367 pfile->import_hash_table[hashval] = i;
5370 /* The file_name_map structure holds a mapping of file names for a
5371 particular directory. This mapping is read from the file named
5372 FILE_NAME_MAP_FILE in that directory. Such a file can be used to
5373 map filenames on a file system with severe filename restrictions,
5374 such as DOS. The format of the file name map file is just a series
5375 of lines with two tokens on each line. The first token is the name
5376 to map, and the second token is the actual name to use. */
5378 struct file_name_map
5380 struct file_name_map *map_next;
5385 #define FILE_NAME_MAP_FILE "header.gcc"
5387 /* Read a space delimited string of unlimited length from a stdio
5391 read_filename_string (ch, f)
5399 set = alloc = xmalloc (len + 1);
5403 while ((ch = getc (f)) != EOF && ! is_space[ch])
5405 if (set - alloc == len)
5408 alloc = xrealloc (alloc, len + 1);
5409 set = alloc + len / 2;
5419 /* This structure holds a linked list of file name maps, one per directory. */
5420 struct file_name_map_list
5422 struct file_name_map_list *map_list_next;
5423 char *map_list_name;
5424 struct file_name_map *map_list_map;
5427 /* Read the file name map file for DIRNAME. */
5429 static struct file_name_map *
5430 read_name_map (pfile, dirname)
5434 register struct file_name_map_list *map_list_ptr;
5438 for (map_list_ptr = CPP_OPTIONS (pfile)->map_list; map_list_ptr;
5439 map_list_ptr = map_list_ptr->map_list_next)
5440 if (! strcmp (map_list_ptr->map_list_name, dirname))
5441 return map_list_ptr->map_list_map;
5443 map_list_ptr = ((struct file_name_map_list *)
5444 xmalloc (sizeof (struct file_name_map_list)));
5445 map_list_ptr->map_list_name = savestring (dirname);
5446 map_list_ptr->map_list_map = NULL;
5448 name = (char *) alloca (strlen (dirname) + strlen (FILE_NAME_MAP_FILE) + 2);
5449 strcpy (name, dirname);
5452 strcat (name, FILE_NAME_MAP_FILE);
5453 f = fopen (name, "r");
5455 map_list_ptr->map_list_map = NULL;
5459 int dirlen = strlen (dirname);
5461 while ((ch = getc (f)) != EOF)
5464 struct file_name_map *ptr;
5468 from = read_filename_string (ch, f);
5469 while ((ch = getc (f)) != EOF && is_hor_space[ch])
5471 to = read_filename_string (ch, f);
5473 ptr = ((struct file_name_map *)
5474 xmalloc (sizeof (struct file_name_map)));
5475 ptr->map_from = from;
5477 /* Make the real filename absolute. */
5482 ptr->map_to = xmalloc (dirlen + strlen (to) + 2);
5483 strcpy (ptr->map_to, dirname);
5484 ptr->map_to[dirlen] = '/';
5485 strcpy (ptr->map_to + dirlen + 1, to);
5489 ptr->map_next = map_list_ptr->map_list_map;
5490 map_list_ptr->map_list_map = ptr;
5492 while ((ch = getc (f)) != '\n')
5499 map_list_ptr->map_list_next = CPP_OPTIONS (pfile)->map_list;
5500 CPP_OPTIONS (pfile)->map_list = map_list_ptr;
5502 return map_list_ptr->map_list_map;
5505 /* Try to open include file FILENAME. SEARCHPTR is the directory
5506 being tried from the include file search path. This function maps
5507 filenames on file systems based on information read by
5511 open_include_file (pfile, filename, searchptr)
5514 struct file_name_list *searchptr;
5516 register struct file_name_map *map;
5517 register char *from;
5520 if (searchptr && ! searchptr->got_name_map)
5522 searchptr->name_map = read_name_map (pfile,
5524 ? searchptr->fname : ".");
5525 searchptr->got_name_map = 1;
5528 /* First check the mapping for the directory we are using. */
5529 if (searchptr && searchptr->name_map)
5532 if (searchptr->fname)
5533 from += strlen (searchptr->fname) + 1;
5534 for (map = searchptr->name_map; map; map = map->map_next)
5536 if (! strcmp (map->map_from, from))
5538 /* Found a match. */
5539 return open (map->map_to, O_RDONLY, 0666);
5544 /* Try to find a mapping file for the particular directory we are
5545 looking in. Thus #include <sys/types.h> will look up sys/types.h
5546 in /usr/include/header.gcc and look up types.h in
5547 /usr/include/sys/header.gcc. */
5548 p = rindex (filename, '/');
5553 && strlen (searchptr->fname) == p - filename
5554 && ! strncmp (searchptr->fname, filename, p - filename))
5556 /* FILENAME is in SEARCHPTR, which we've already checked. */
5557 return open (filename, O_RDONLY, 0666);
5567 dir = (char *) alloca (p - filename + 1);
5568 bcopy (filename, dir, p - filename);
5569 dir[p - filename] = '\0';
5572 for (map = read_name_map (pfile, dir); map; map = map->map_next)
5573 if (! strcmp (map->map_from, from))
5574 return open (map->map_to, O_RDONLY, 0666);
5576 return open (filename, O_RDONLY, 0666);
5579 /* Process the contents of include file FNAME, already open on descriptor F,
5581 SYSTEM_HEADER_P is 1 if this file resides in any one of the known
5582 "system" include directories (as decided by the `is_system_include'
5584 DIRPTR is the link in the dir path through which this file was found,
5585 or 0 if the file name was absolute or via the current directory.
5586 Return 1 on success, 0 on failure.
5588 The caller is responsible for the cpp_push_buffer. */
5591 finclude (pfile, f, fname, system_header_p, dirptr)
5595 int system_header_p;
5596 struct file_name_list *dirptr;
5602 cpp_buffer *fp; /* For input stack frame */
5603 int missing_newline = 0;
5605 if (file_size_and_mode (f, &st_mode, &st_size) < 0)
5607 cpp_perror_with_name (pfile, fname);
5609 cpp_pop_buffer (pfile);
5613 fp = CPP_BUFFER (pfile);
5614 fp->nominal_fname = fp->fname = fname;
5619 fp->system_header_p = system_header_p;
5622 fp->cleanup = file_cleanup;
5624 if (S_ISREG (st_mode)) {
5625 fp->buf = (U_CHAR *) xmalloc (st_size + 2);
5626 fp->alimit = fp->buf + st_size + 2;
5629 /* Read the file contents, knowing that st_size is an upper bound
5630 on the number of bytes we can read. */
5631 length = safe_read (f, fp->buf, st_size);
5632 fp->rlimit = fp->buf + length;
5633 if (length < 0) goto nope;
5635 else if (S_ISDIR (st_mode)) {
5636 cpp_error (pfile, "directory `%s' specified in #include", fname);
5640 /* Cannot count its file size before reading.
5641 First read the entire file into heap and
5642 copy them into buffer on stack. */
5647 fp->buf = (U_CHAR *) xmalloc (bsize + 2);
5650 i = safe_read (f, fp->buf + st_size, bsize - st_size);
5652 goto nope; /* error! */
5654 if (st_size != bsize)
5655 break; /* End of file */
5657 fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
5662 if ((length > 0 && fp->buf[length - 1] != '\n')
5663 /* Backslash-newline at end is not good enough. */
5664 || (length > 1 && fp->buf[length - 2] == '\\')) {
5665 fp->buf[length++] = '\n';
5667 missing_newline = 1;
5670 fp->buf[length] = '\0';
5671 fp->rlimit = fp->buf + length;
5673 /* Close descriptor now, so nesting does not use lots of descriptors. */
5676 /* Must do this before calling trigraph_pcp, so that the correct file name
5677 will be printed in warning messages. */
5679 pfile->input_stack_listing_current = 0;
5689 if (missing_newline)
5692 if (CPP_PEDANTIC (pfile) && missing_newline)
5693 pedwarn ("file does not end in newline");
5696 input_file_stack_tick++;
5703 cpp_perror_with_name (pfile, fname);
5710 push_parse_file (pfile, fname)
5714 struct cpp_options *opts = CPP_OPTIONS (pfile);
5715 struct cpp_pending *pend;
5720 /* The code looks at the defaults through this pointer, rather than through
5721 the constant structure above. This pointer gets changed if an environment
5722 variable specifies other defaults. */
5723 struct default_include *include_defaults = include_defaults_array;
5725 /* Add dirs from CPATH after dirs from -I. */
5726 /* There seems to be confusion about what CPATH should do,
5727 so for the moment it is not documented. */
5728 /* Some people say that CPATH should replace the standard include dirs,
5729 but that seems pointless: it comes before them, so it overrides them
5731 p = (char *) getenv ("CPATH");
5732 if (p != 0 && ! opts->no_standard_includes)
5733 path_include (pfile, p);
5735 /* Now that dollars_in_ident is known, initialize is_idchar. */
5736 initialize_char_syntax (opts);
5738 /* Do partial setup of input buffer for the sake of generating
5739 early #line directives (when -g is in effect). */
5740 fp = cpp_push_buffer (pfile, NULL, 0);
5741 if (opts->in_fname == NULL)
5742 opts->in_fname = "";
5743 fp->nominal_fname = fp->fname = opts->in_fname;
5746 /* Install __LINE__, etc. Must follow initialize_char_syntax
5747 and option processing. */
5748 initialize_builtins (pfile);
5750 /* Do standard #defines and assertions
5751 that identify system and machine type. */
5753 if (!opts->inhibit_predefs) {
5754 char *p = (char *) alloca (strlen (predefs) + 1);
5755 strcpy (p, predefs);
5758 while (*p == ' ' || *p == '\t')
5760 /* Handle -D options. */
5761 if (p[0] == '-' && p[1] == 'D') {
5763 while (*p && *p != ' ' && *p != '\t')
5767 if (opts->debug_output)
5768 output_line_command (pfile, 0, same_file);
5769 cpp_define (pfile, q);
5770 while (*p == ' ' || *p == '\t')
5772 } else if (p[0] == '-' && p[1] == 'A') {
5773 /* Handle -A options (assertions). */
5782 past_name = assertion;
5783 /* Locate end of name. */
5784 while (*past_name && *past_name != ' '
5785 && *past_name != '\t' && *past_name != '(')
5787 /* Locate `(' at start of value. */
5789 while (*value && (*value == ' ' || *value == '\t'))
5791 if (*value++ != '(')
5793 while (*value && (*value == ' ' || *value == '\t'))
5796 /* Locate end of value. */
5797 while (*past_value && *past_value != ' '
5798 && *past_value != '\t' && *past_value != ')')
5800 termination = past_value;
5801 while (*termination && (*termination == ' ' || *termination == '\t'))
5803 if (*termination++ != ')')
5805 if (*termination && *termination != ' ' && *termination != '\t')
5807 /* Temporarily null-terminate the value. */
5808 save_char = *termination;
5809 *termination = '\0';
5810 /* Install the assertion. */
5811 make_assertion (pfile, "-A", assertion);
5812 *termination = (char) save_char;
5814 while (*p == ' ' || *p == '\t')
5822 /* Now handle the command line options. */
5824 /* Do -U's, -D's and -A's in the order they were seen. */
5825 /* First reverse the list. */
5826 opts->pending = nreverse_pending (opts->pending);
5828 for (pend = opts->pending; pend; pend = pend->next)
5830 if (pend->cmd != NULL && pend->cmd[0] == '-')
5832 switch (pend->cmd[1])
5835 if (opts->debug_output)
5836 output_line_command (pfile, 0, same_file);
5837 do_undef (pfile, NULL, pend->arg, pend->arg + strlen (pend->arg));
5840 if (opts->debug_output)
5841 output_line_command (pfile, 0, same_file);
5842 cpp_define (pfile, pend->arg);
5845 make_assertion (pfile, "-A", pend->arg);
5851 opts->done_initializing = 1;
5853 { /* read the appropriate environment variable and if it exists
5854 replace include_defaults with the listed path. */
5856 switch ((opts->objc << 1) + opts->cplusplus)
5859 epath = getenv ("C_INCLUDE_PATH");
5862 epath = getenv ("CPLUS_INCLUDE_PATH");
5865 epath = getenv ("OBJC_INCLUDE_PATH");
5868 epath = getenv ("OBJCPLUS_INCLUDE_PATH");
5871 /* If the environment var for this language is set,
5872 add to the default list of include directories. */
5874 char *nstore = (char *) alloca (strlen (epath) + 2);
5876 char *startp, *endp;
5878 for (num_dirs = 1, startp = epath; *startp; startp++)
5879 if (*startp == PATH_SEPARATOR)
5882 = (struct default_include *) xmalloc ((num_dirs
5883 * sizeof (struct default_include))
5884 + sizeof (include_defaults_array));
5885 startp = endp = epath;
5888 /* Handle cases like c:/usr/lib:d:/gcc/lib */
5889 if ((*endp == PATH_SEPARATOR)
5891 strncpy (nstore, startp, endp-startp);
5893 strcpy (nstore, ".");
5895 nstore[endp-startp] = '\0';
5897 include_defaults[num_dirs].fname = savestring (nstore);
5898 include_defaults[num_dirs].cplusplus = opts->cplusplus;
5899 include_defaults[num_dirs].cxx_aware = 1;
5903 endp = startp = endp + 1;
5907 /* Put the usual defaults back in at the end. */
5908 bcopy ((char *) include_defaults_array,
5909 (char *) &include_defaults[num_dirs],
5910 sizeof (include_defaults_array));
5914 append_include_chain (pfile, opts->before_system, opts->last_before_system);
5915 opts->first_system_include = opts->before_system;
5917 /* Unless -fnostdinc,
5918 tack on the standard include file dirs to the specified list */
5919 if (!opts->no_standard_includes) {
5920 struct default_include *p = include_defaults;
5921 char *specd_prefix = opts->include_prefix;
5922 char *default_prefix = savestring (GCC_INCLUDE_DIR);
5923 int default_len = 0;
5924 /* Remove the `include' from /usr/local/lib/gcc.../include. */
5925 if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) {
5926 default_len = strlen (default_prefix) - 7;
5927 default_prefix[default_len] = 0;
5929 /* Search "translated" versions of GNU directories.
5930 These have /usr/local/lib/gcc... replaced by specd_prefix. */
5931 if (specd_prefix != 0 && default_len != 0)
5932 for (p = include_defaults; p->fname; p++) {
5933 /* Some standard dirs are only for C++. */
5935 || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
5936 /* Does this dir start with the prefix? */
5937 if (!strncmp (p->fname, default_prefix, default_len)) {
5938 /* Yes; change prefix and add to search list. */
5939 struct file_name_list *new
5940 = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
5941 int this_len = strlen (specd_prefix) + strlen (p->fname) - default_len;
5942 char *str = (char *) xmalloc (this_len + 1);
5943 strcpy (str, specd_prefix);
5944 strcat (str, p->fname + default_len);
5946 new->control_macro = 0;
5947 new->c_system_include_path = !p->cxx_aware;
5948 new->got_name_map = 0;
5949 append_include_chain (pfile, new, new);
5950 if (opts->first_system_include == 0)
5951 opts->first_system_include = new;
5955 /* Search ordinary names for GNU include directories. */
5956 for (p = include_defaults; p->fname; p++) {
5957 /* Some standard dirs are only for C++. */
5959 || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
5960 struct file_name_list *new
5961 = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
5962 new->control_macro = 0;
5963 new->c_system_include_path = !p->cxx_aware;
5964 new->fname = p->fname;
5965 new->got_name_map = 0;
5966 append_include_chain (pfile, new, new);
5967 if (opts->first_system_include == 0)
5968 opts->first_system_include = new;
5973 /* Tack the after_include chain at the end of the include chain. */
5974 append_include_chain (pfile, opts->after_include, opts->last_after_include);
5975 if (opts->first_system_include == 0)
5976 opts->first_system_include = opts->after_include;
5978 /* With -v, print the list of dirs to search. */
5979 if (opts->verbose) {
5980 struct file_name_list *p;
5981 fprintf (stderr, "#include \"...\" search starts here:\n");
5982 for (p = opts->include; p; p = p->next) {
5983 if (p == opts->first_bracket_include)
5984 fprintf (stderr, "#include <...> search starts here:\n");
5985 fprintf (stderr, " %s\n", p->fname);
5987 fprintf (stderr, "End of search list.\n");
5990 /* Scan the -imacros files before the main input.
5991 Much like #including them, but with no_output set
5992 so that only their macro definitions matter. */
5994 opts->no_output++; pfile->no_record_file++;
5995 for (pend = opts->pending; pend; pend = pend->next)
5997 if (pend->cmd != NULL && strcmp (pend->cmd, "-imacros") == 0)
5999 int fd = open (pend->arg, O_RDONLY, 0666);
6002 cpp_perror_with_name (pfile, pend->arg);
6003 return FATAL_EXIT_CODE;
6005 cpp_push_buffer (pfile, NULL, 0);
6006 finclude (pfile, fd, pend->arg, 0, NULL_PTR);
6007 cpp_scan_buffer (pfile);
6010 opts->no_output--; pfile->no_record_file--;
6012 /* Copy the entire contents of the main input file into
6013 the stacked input buffer previously allocated for it. */
6014 if (fname == NULL || *fname == 0) {
6017 } else if ((f = open (fname, O_RDONLY, 0666)) < 0)
6018 cpp_pfatal_with_name (pfile, fname);
6020 /* -MG doesn't select the form of output and must be specified with one of
6021 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
6022 inhibit compilation. */
6023 if (opts->print_deps_missing_files
6024 && (opts->print_deps == 0 || !opts->no_output))
6025 fatal (pfile, "-MG must be specified with one of -M or -MM");
6027 /* Either of two environment variables can specify output of deps.
6028 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
6029 where OUTPUT_FILE is the file to write deps info to
6030 and DEPS_TARGET is the target to mention in the deps. */
6032 if (opts->print_deps == 0
6033 && (getenv ("SUNPRO_DEPENDENCIES") != 0
6034 || getenv ("DEPENDENCIES_OUTPUT") != 0)) {
6035 char *spec = getenv ("DEPENDENCIES_OUTPUT");
6041 spec = getenv ("SUNPRO_DEPENDENCIES");
6042 opts->print_deps = 2;
6045 opts->print_deps = 1;
6048 /* Find the space before the DEPS_TARGET, if there is one. */
6049 /* This should use index. (mrs) */
6050 while (*s != 0 && *s != ' ') s++;
6053 opts->deps_target = s + 1;
6054 output_file = (char *) xmalloc (s - spec + 1);
6055 bcopy (spec, output_file, s - spec);
6056 output_file[s - spec] = 0;
6060 opts->deps_target = 0;
6064 opts->deps_file = output_file;
6065 opts->print_deps_append = 1;
6068 /* For -M, print the expected object file name
6069 as the target of this Make-rule. */
6070 if (opts->print_deps)
6072 pfile->deps_allocated_size = 200;
6073 pfile->deps_buffer = (char *) xmalloc (pfile->deps_allocated_size);
6074 pfile->deps_buffer[0] = 0;
6075 pfile->deps_size = 0;
6076 pfile->deps_column = 0;
6078 if (opts->deps_target)
6079 deps_output (pfile, opts->deps_target, ':');
6080 else if (*opts->in_fname == 0)
6081 deps_output (pfile, "-", ':');
6087 /* Discard all directory prefixes from filename. */
6088 if ((q = rindex (opts->in_fname, '/')) != NULL
6089 #ifdef DIR_SEPARATOR
6090 && (q = rindex (opts->in_fname, DIR_SEPARATOR)) != NULL
6097 /* Copy remainder to mungable area. */
6098 p = (char *) alloca (strlen(q) + 8);
6101 /* Output P, but remove known suffixes. */
6105 && p[len - 2] == '.'
6106 && index("cCsSm", p[len - 1]))
6109 && p[len - 3] == '.'
6110 && p[len - 2] == 'c'
6111 && p[len - 1] == 'c')
6114 && p[len - 4] == '.'
6115 && p[len - 3] == 'c'
6116 && p[len - 2] == 'x'
6117 && p[len - 1] == 'x')
6120 && p[len - 4] == '.'
6121 && p[len - 3] == 'c'
6122 && p[len - 2] == 'p'
6123 && p[len - 1] == 'p')
6126 /* Supply our own suffix. */
6133 deps_output (pfile, p, ':');
6134 deps_output (pfile, opts->in_fname, ' ');
6139 /* Make sure data ends with a newline. And put a null after it. */
6141 if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n')
6142 /* Backslash-newline at end is not good enough. */
6143 || (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) {
6144 fp->buf[fp->length++] = '\n';
6145 missing_newline = 1;
6147 fp->buf[fp->length] = '\0';
6149 /* Unless inhibited, convert trigraphs in the input. */
6155 /* Scan the -include files before the main input.
6156 We push these in reverse order, so that the first one is handled first. */
6158 pfile->no_record_file++;
6159 opts->pending = nreverse_pending (opts->pending);
6160 for (pend = opts->pending; pend; pend = pend->next)
6162 if (pend->cmd != NULL && strcmp (pend->cmd, "-include") == 0)
6164 int fd = open (pend->arg, O_RDONLY, 0666);
6167 cpp_perror_with_name (pfile, pend->arg);
6168 return FATAL_EXIT_CODE;
6170 cpp_push_buffer (pfile, NULL, 0);
6171 finclude (pfile, fd, pend->arg, 0, NULL_PTR);
6174 pfile->no_record_file--;
6176 /* Free the pending list. */
6177 for (pend = opts->pending; pend; )
6179 struct cpp_pending *next = pend->next;
6183 opts->pending = NULL;
6186 /* Scan the input, processing macros and directives. */
6188 rescan (&outbuf, 0);
6190 if (missing_newline)
6193 if (CPP_PEDANTIC (pfile) && missing_newline)
6194 pedwarn ("file does not end in newline");
6197 if (finclude (pfile, f, fname, 0, NULL_PTR))
6198 output_line_command (pfile, 0, same_file);
6199 return SUCCESS_EXIT_CODE;
6203 init_parse_file (pfile)
6206 bzero ((char *) pfile, sizeof (cpp_reader));
6207 pfile->get_token = cpp_get_token;
6209 pfile->token_buffer_size = 200;
6210 pfile->token_buffer = (U_CHAR*)xmalloc (pfile->token_buffer_size);
6211 CPP_SET_WRITTEN (pfile, 0);
6213 pfile->system_include_depth = 0;
6214 pfile->dont_repeat_files = 0;
6215 pfile->all_include_files = 0;
6216 pfile->max_include_len = 0;
6217 pfile->timebuf = NULL;
6218 pfile->only_seen_white = 1;
6219 pfile->buffer = CPP_NULL_BUFFER(pfile);
6222 static struct cpp_pending *
6223 nreverse_pending (list)
6224 struct cpp_pending *list;
6227 register struct cpp_pending *prev = 0, *next, *pend;
6228 for (pend = list; pend; pend = next)
6238 push_pending (pfile, cmd, arg)
6243 struct cpp_pending *pend
6244 = (struct cpp_pending*)xmalloc (sizeof (struct cpp_pending));
6247 pend->next = CPP_OPTIONS (pfile)->pending;
6248 CPP_OPTIONS (pfile)->pending = pend;
6251 /* Handle command-line options in (argc, argv).
6252 Can be called multiple times, to handle multiple sets of options.
6253 Returns if an unrecognized option is seen.
6254 Returns number of handled arguments. */
6257 cpp_handle_options (pfile, argc, argv)
6263 struct cpp_options *opts = CPP_OPTIONS (pfile);
6264 for (i = 0; i < argc; i++) {
6265 if (argv[i][0] != '-') {
6266 if (opts->out_fname != NULL)
6267 fatal ("Usage: %s [switches] input output", argv[0]);
6268 else if (opts->in_fname != NULL)
6269 opts->out_fname = argv[i];
6271 opts->in_fname = argv[i];
6273 switch (argv[i][1]) {
6276 if (!strcmp (argv[i], "-include")
6277 || !strcmp (argv[i], "-imacros")) {
6279 fatal ("Filename missing after `%s' option", argv[i]);
6281 push_pending (pfile, argv[i], argv[i+1]), i++;
6283 if (!strcmp (argv[i], "-iprefix")) {
6285 fatal ("Filename missing after `-iprefix' option");
6287 opts->include_prefix = argv[++i];
6289 if (!strcmp (argv[i], "-ifoutput")) {
6290 opts->output_conditionals = 1;
6292 if (!strcmp (argv[i], "-isystem")) {
6293 struct file_name_list *dirtmp;
6296 fatal ("Filename missing after `-isystem' option");
6298 dirtmp = (struct file_name_list *)
6299 xmalloc (sizeof (struct file_name_list));
6301 dirtmp->control_macro = 0;
6302 dirtmp->c_system_include_path = 1;
6303 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1]) + 1);
6304 strcpy (dirtmp->fname, argv[++i]);
6305 dirtmp->got_name_map = 0;
6307 if (opts->before_system == 0)
6308 opts->before_system = dirtmp;
6310 opts->last_before_system->next = dirtmp;
6311 opts->last_before_system = dirtmp; /* Tail follows the last one */
6313 /* Add directory to end of path for includes,
6314 with the default prefix at the front of its name. */
6315 if (!strcmp (argv[i], "-iwithprefix")) {
6316 struct file_name_list *dirtmp;
6319 if (opts->include_prefix != 0)
6320 prefix = opts->include_prefix;
6322 prefix = savestring (GCC_INCLUDE_DIR);
6323 /* Remove the `include' from /usr/local/lib/gcc.../include. */
6324 if (!strcmp (prefix + strlen (prefix) - 8, "/include"))
6325 prefix[strlen (prefix) - 7] = 0;
6328 dirtmp = (struct file_name_list *)
6329 xmalloc (sizeof (struct file_name_list));
6330 dirtmp->next = 0; /* New one goes on the end */
6331 dirtmp->control_macro = 0;
6332 dirtmp->c_system_include_path = 0;
6334 fatal ("Directory name missing after `-iwithprefix' option");
6336 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1])
6337 + strlen (prefix) + 1);
6338 strcpy (dirtmp->fname, prefix);
6339 strcat (dirtmp->fname, argv[++i]);
6340 dirtmp->got_name_map = 0;
6342 if (opts->after_include == 0)
6343 opts->after_include = dirtmp;
6345 opts->last_after_include->next = dirtmp;
6346 opts->last_after_include = dirtmp; /* Tail follows the last one */
6348 /* Add directory to main path for includes,
6349 with the default prefix at the front of its name. */
6350 if (!strcmp (argv[i], "-iwithprefixbefore")) {
6351 struct file_name_list *dirtmp;
6354 if (opts->include_prefix != 0)
6355 prefix = opts->include_prefix;
6357 prefix = savestring (GCC_INCLUDE_DIR);
6358 /* Remove the `include' from /usr/local/lib/gcc.../include. */
6359 if (!strcmp (prefix + strlen (prefix) - 8, "/include"))
6360 prefix[strlen (prefix) - 7] = 0;
6363 dirtmp = (struct file_name_list *)
6364 xmalloc (sizeof (struct file_name_list));
6365 dirtmp->next = 0; /* New one goes on the end */
6366 dirtmp->control_macro = 0;
6367 dirtmp->c_system_include_path = 0;
6369 fatal ("Directory name missing after `-iwithprefixbefore' option");
6371 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1])
6372 + strlen (prefix) + 1);
6373 strcpy (dirtmp->fname, prefix);
6374 strcat (dirtmp->fname, argv[++i]);
6375 dirtmp->got_name_map = 0;
6377 append_include_chain (pfile, dirtmp, dirtmp);
6379 /* Add directory to end of path for includes. */
6380 if (!strcmp (argv[i], "-idirafter")) {
6381 struct file_name_list *dirtmp;
6383 dirtmp = (struct file_name_list *)
6384 xmalloc (sizeof (struct file_name_list));
6385 dirtmp->next = 0; /* New one goes on the end */
6386 dirtmp->control_macro = 0;
6387 dirtmp->c_system_include_path = 0;
6389 fatal ("Directory name missing after `-idirafter' option");
6391 dirtmp->fname = argv[++i];
6392 dirtmp->got_name_map = 0;
6394 if (opts->after_include == 0)
6395 opts->after_include = dirtmp;
6397 opts->last_after_include->next = dirtmp;
6398 opts->last_after_include = dirtmp; /* Tail follows the last one */
6403 if (opts->out_fname != NULL)
6404 fatal ("Output filename specified twice");
6406 fatal ("Filename missing after -o option");
6407 opts->out_fname = argv[++i];
6408 if (!strcmp (opts->out_fname, "-"))
6409 opts->out_fname = "";
6413 if (!strcmp (argv[i], "-pedantic"))
6414 CPP_PEDANTIC (pfile) = 1;
6415 else if (!strcmp (argv[i], "-pedantic-errors")) {
6416 CPP_PEDANTIC (pfile) = 1;
6417 opts->pedantic_errors = 1;
6420 else if (!strcmp (argv[i], "-pcp")) {
6421 char *pcp_fname = argv[++i];
6423 ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
6424 ? fopen (pcp_fname, "w")
6425 : fdopen (dup (fileno (stdout)), "w"));
6426 if (pcp_outfile == 0)
6427 cpp_pfatal_with_name (pfile, pcp_fname);
6434 if (!strcmp (argv[i], "-traditional")) {
6435 opts->traditional = 1;
6436 if (opts->dollars_in_ident > 0)
6437 opts->dollars_in_ident = 1;
6438 } else if (!strcmp (argv[i], "-trigraphs")) {
6440 opts->no_trigraphs = 0;
6445 if (! strcmp (argv[i], "-lang-c"))
6446 opts->cplusplus = 0, opts->cplusplus_comments = 0, opts->objc = 0;
6447 if (! strcmp (argv[i], "-lang-c++"))
6448 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->objc = 0;
6449 if (! strcmp (argv[i], "-lang-c-c++-comments"))
6450 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->objc = 0;
6451 if (! strcmp (argv[i], "-lang-objc"))
6452 opts->objc = 1, opts->cplusplus = 0, opts->cplusplus_comments = 1;
6453 if (! strcmp (argv[i], "-lang-objc++"))
6454 opts->objc = 1, opts->cplusplus = 1, opts->cplusplus_comments = 1;
6455 if (! strcmp (argv[i], "-lang-asm"))
6457 if (! strcmp (argv[i], "-lint"))
6459 if (! strcmp (argv[i], "-lang-chill"))
6460 opts->objc = 0, opts->cplusplus = 0, opts->chill = 1,
6461 opts->traditional = 1, opts->no_trigraphs = 1;
6465 opts->cplusplus = 1, opts->cplusplus_comments = 1;
6469 opts->inhibit_warnings = 1;
6473 if (!strcmp (argv[i], "-Wtrigraphs"))
6474 opts->warn_trigraphs = 1;
6475 else if (!strcmp (argv[i], "-Wno-trigraphs"))
6476 opts->warn_trigraphs = 0;
6477 else if (!strcmp (argv[i], "-Wcomment"))
6478 opts->warn_comments = 1;
6479 else if (!strcmp (argv[i], "-Wno-comment"))
6480 opts->warn_comments = 0;
6481 else if (!strcmp (argv[i], "-Wcomments"))
6482 opts->warn_comments = 1;
6483 else if (!strcmp (argv[i], "-Wno-comments"))
6484 opts->warn_comments = 0;
6485 else if (!strcmp (argv[i], "-Wtraditional"))
6486 opts->warn_stringify = 1;
6487 else if (!strcmp (argv[i], "-Wno-traditional"))
6488 opts->warn_stringify = 0;
6489 else if (!strcmp (argv[i], "-Wimport"))
6490 opts->warn_import = 1;
6491 else if (!strcmp (argv[i], "-Wno-import"))
6492 opts->warn_import = 0;
6493 else if (!strcmp (argv[i], "-Werror"))
6494 opts->warnings_are_errors = 1;
6495 else if (!strcmp (argv[i], "-Wno-error"))
6496 opts->warnings_are_errors = 0;
6497 else if (!strcmp (argv[i], "-Wall"))
6499 opts->warn_trigraphs = 1;
6500 opts->warn_comments = 1;
6505 /* The style of the choices here is a bit mixed.
6506 The chosen scheme is a hybrid of keeping all options in one string
6507 and specifying each option in a separate argument:
6508 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
6509 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
6510 -M[M][G][D file]. This is awkward to handle in specs, and is not
6512 /* ??? -MG must be specified in addition to one of -M or -MM.
6513 This can be relaxed in the future without breaking anything.
6514 The converse isn't true. */
6516 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
6517 if (!strcmp (argv[i], "-MG"))
6519 opts->print_deps_missing_files = 1;
6522 if (!strcmp (argv[i], "-M"))
6523 opts->print_deps = 2;
6524 else if (!strcmp (argv[i], "-MM"))
6525 opts->print_deps = 1;
6526 else if (!strcmp (argv[i], "-MD"))
6527 opts->print_deps = 2;
6528 else if (!strcmp (argv[i], "-MMD"))
6529 opts->print_deps = 1;
6530 /* For -MD and -MMD options, write deps on file named by next arg. */
6531 if (!strcmp (argv[i], "-MD") || !strcmp (argv[i], "-MMD"))
6534 fatal ("Filename missing after %s option", argv[i]);
6535 opts->deps_file = argv[++i];
6539 /* For -M and -MM, write deps on standard output
6540 and suppress the usual output. */
6541 opts->no_output = 1;
6547 char *p = argv[i] + 2;
6549 while ((c = *p++) != 0) {
6550 /* Arg to -d specifies what parts of macros to dump */
6553 opts->dump_macros = dump_only;
6554 opts->no_output = 1;
6557 opts->dump_macros = dump_names;
6560 opts->dump_macros = dump_definitions;
6568 if (argv[i][2] == '3')
6569 opts->debug_output = 1;
6573 fprintf (stderr, "GNU CPP version %s", version_string);
6574 #ifdef TARGET_VERSION
6577 fprintf (stderr, "\n");
6582 opts->print_include_names = 1;
6586 if (argv[i][2] != 0)
6587 push_pending (pfile, "-D", argv[i] + 2);
6588 else if (i + 1 == argc)
6589 fatal ("Macro name missing after -D option");
6591 i++, push_pending (pfile, "-D", argv[i]);
6598 if (argv[i][2] != 0)
6600 else if (i + 1 == argc)
6601 fatal ("Assertion missing after -A option");
6605 if (!strcmp (p, "-")) {
6606 struct cpp_pending **ptr;
6607 /* -A- eliminates all predefined macros and assertions.
6608 Let's include also any that were specified earlier
6609 on the command line. That way we can get rid of any
6610 that were passed automatically in from GCC. */
6612 opts->inhibit_predefs = 1;
6613 for (ptr = &opts->pending; *ptr != NULL; )
6615 struct cpp_pending *pend = *ptr;
6616 if (pend->cmd && pend->cmd[0] == '-'
6617 && (pend->cmd[1] == 'D' || pend->cmd[1] == 'A'))
6626 push_pending (pfile, "-A", p);
6631 case 'U': /* JF #undef something */
6632 if (argv[i][2] != 0)
6633 push_pending (pfile, "-U", argv[i] + 2);
6634 else if (i + 1 == argc)
6635 fatal ("Macro name missing after -U option");
6637 push_pending (pfile, "-U", argv[i+1]), i++;
6641 opts->put_out_comments = 1;
6644 case 'E': /* -E comes from cc -E; ignore it. */
6648 opts->no_line_commands = 1;
6651 case '$': /* Don't include $ in identifiers. */
6652 opts->dollars_in_ident = 0;
6655 case 'I': /* Add directory to path for includes. */
6657 struct file_name_list *dirtmp;
6659 if (! CPP_OPTIONS(pfile)->ignore_srcdir
6660 && !strcmp (argv[i] + 2, "-")) {
6661 CPP_OPTIONS (pfile)->ignore_srcdir = 1;
6662 /* Don't use any preceding -I directories for #include <...>. */
6663 CPP_OPTIONS (pfile)->first_bracket_include = 0;
6666 dirtmp = (struct file_name_list *)
6667 xmalloc (sizeof (struct file_name_list));
6668 dirtmp->next = 0; /* New one goes on the end */
6669 dirtmp->control_macro = 0;
6670 dirtmp->c_system_include_path = 0;
6671 if (argv[i][2] != 0)
6672 dirtmp->fname = argv[i] + 2;
6673 else if (i + 1 == argc)
6674 fatal ("Directory name missing after -I option");
6676 dirtmp->fname = argv[++i];
6677 dirtmp->got_name_map = 0;
6678 append_include_chain (pfile, dirtmp, dirtmp);
6684 if (!strcmp (argv[i], "-nostdinc"))
6685 /* -nostdinc causes no default include directories.
6686 You must specify all include-file directories with -I. */
6687 opts->no_standard_includes = 1;
6688 else if (!strcmp (argv[i], "-nostdinc++"))
6689 /* -nostdinc++ causes no default C++-specific include directories. */
6690 opts->no_standard_cplusplus_includes = 1;
6692 else if (!strcmp (argv[i], "-noprecomp"))
6698 /* Sun compiler passes undocumented switch "-undef".
6699 Let's assume it means to inhibit the predefined symbols. */
6700 opts->inhibit_predefs = 1;
6703 case '\0': /* JF handle '-' as file name meaning stdin or stdout */
6704 if (opts->in_fname == NULL) {
6705 opts->in_fname = "";
6707 } else if (opts->out_fname == NULL) {
6708 opts->out_fname = "";
6710 } /* else fall through into error */
6724 struct cpp_options *opts = CPP_OPTIONS (pfile);
6726 if (opts->print_deps)
6728 /* Stream on which to print the dependency information. */
6731 /* Don't actually write the deps file if compilation has failed. */
6732 if (pfile->errors == 0)
6734 char *deps_mode = opts->print_deps_append ? "a" : "w";
6735 if (opts->deps_file == 0)
6736 deps_stream = stdout;
6737 else if ((deps_stream = fopen (opts->deps_file, deps_mode)) == 0)
6738 cpp_pfatal_with_name (pfile, opts->deps_file);
6739 fputs (pfile->deps_buffer, deps_stream);
6740 putc ('\n', deps_stream);
6741 if (opts->deps_file)
6743 if (ferror (deps_stream) || fclose (deps_stream) != 0)
6744 fatal ("I/O error on output");
6750 /* Free resources used by PFILE. */
6757 while ( CPP_BUFFER (pfile) != CPP_NULL_BUFFER (pfile))
6758 cpp_pop_buffer (pfile);
6760 if (pfile->token_buffer)
6762 free (pfile->token_buffer);
6763 pfile->token_buffer = NULL;
6766 if (pfile->deps_buffer)
6768 free (pfile->deps_buffer);
6769 pfile->deps_buffer = NULL;
6770 pfile->deps_allocated_size = 0;
6773 while (pfile->if_stack)
6775 IF_STACK_FRAME *temp = pfile->if_stack;
6776 pfile->if_stack = temp->next;
6780 while (pfile->dont_repeat_files)
6782 struct file_name_list *temp = pfile->dont_repeat_files;
6783 pfile->dont_repeat_files = temp->next;
6788 while (pfile->all_include_files)
6790 struct file_name_list *temp = pfile->all_include_files;
6791 pfile->all_include_files = temp->next;
6796 for (i = IMPORT_HASH_SIZE; --i >= 0; )
6798 register struct import_file *imp = pfile->import_hash_table[i];
6801 struct import_file *next = imp->next;
6806 pfile->import_hash_table[i] = 0;
6809 for (i = ASSERTION_HASHSIZE; --i >= 0; )
6811 while (pfile->assertion_hashtab[i])
6812 delete_assertion (pfile->assertion_hashtab[i]);
6815 cpp_hash_cleanup (pfile);
6819 do_assert (pfile, keyword, buf, limit)
6821 struct directive *keyword;
6822 U_CHAR *buf, *limit;
6824 long symstart; /* remember where symbol name starts */
6826 int sym_length; /* and how long it is */
6827 struct arglist *tokens = NULL;
6829 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
6830 && !CPP_BUFFER (pfile)->system_header_p)
6831 cpp_pedwarn (pfile, "ANSI C does not allow `#assert'");
6833 cpp_skip_hspace (pfile);
6834 symstart = CPP_WRITTEN (pfile); /* remember where it starts */
6835 parse_name (pfile, GETC());
6836 sym_length = check_macro_name (pfile, pfile->token_buffer + symstart,
6839 cpp_skip_hspace (pfile);
6840 if (PEEKC() != '(') {
6841 cpp_error (pfile, "missing token-sequence in `#assert'");
6847 tokens = read_token_list (pfile, &error_flag);
6851 cpp_error (pfile, "empty token-sequence in `#assert'");
6854 cpp_skip_hspace (pfile);
6856 if (c != EOF && c != '\n')
6857 cpp_pedwarn (pfile, "junk at end of `#assert'");
6858 skip_rest_of_line (pfile);
6861 /* If this name isn't already an assertion name, make it one.
6862 Error if it was already in use in some other way. */
6865 ASSERTION_HASHNODE *hp;
6866 U_CHAR *symname = pfile->token_buffer + symstart;
6867 int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE);
6868 struct tokenlist_list *value
6869 = (struct tokenlist_list *) xmalloc (sizeof (struct tokenlist_list));
6871 hp = assertion_lookup (pfile, symname, sym_length, hashcode);
6873 if (sym_length == 7 && ! strncmp (symname, "defined", sym_length))
6874 cpp_error (pfile, "`defined' redefined as assertion");
6875 hp = assertion_install (pfile, symname, sym_length, hashcode);
6878 /* Add the spec'd token-sequence to the list of such. */
6879 value->tokens = tokens;
6880 value->next = hp->value;
6883 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6886 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6887 skip_rest_of_line (pfile);
6892 do_unassert (pfile, keyword, buf, limit)
6894 struct directive *keyword;
6895 U_CHAR *buf, *limit;
6897 long symstart; /* remember where symbol name starts */
6898 int sym_length; /* and how long it is */
6901 struct arglist *tokens = NULL;
6902 int tokens_specified = 0;
6904 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
6905 && !CPP_BUFFER (pfile)->system_header_p)
6906 cpp_pedwarn (pfile, "ANSI C does not allow `#unassert'");
6908 cpp_skip_hspace (pfile);
6910 symstart = CPP_WRITTEN (pfile); /* remember where it starts */
6911 parse_name (pfile, GETC());
6912 sym_length = check_macro_name (pfile, pfile->token_buffer + symstart,
6915 cpp_skip_hspace (pfile);
6916 if (PEEKC() == '(') {
6919 tokens = read_token_list (pfile, &error_flag);
6923 cpp_error (pfile, "empty token list in `#unassert'");
6927 tokens_specified = 1;
6930 cpp_skip_hspace (pfile);
6932 if (c != EOF && c != '\n')
6933 cpp_error (pfile, "junk at end of `#unassert'");
6934 skip_rest_of_line (pfile);
6937 ASSERTION_HASHNODE *hp;
6938 U_CHAR *symname = pfile->token_buffer + symstart;
6939 int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE);
6940 struct tokenlist_list *tail, *prev;
6942 hp = assertion_lookup (pfile, symname, sym_length, hashcode);
6946 /* If no token list was specified, then eliminate this assertion
6948 if (! tokens_specified)
6949 delete_assertion (hp);
6951 /* If a list of tokens was given, then delete any matching list. */
6956 struct tokenlist_list *next = tail->next;
6957 if (compare_token_lists (tail->tokens, tokens)) {
6961 hp->value = tail->next;
6962 free_token_list (tail->tokens);
6972 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6975 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6976 skip_rest_of_line (pfile);
6980 /* Test whether there is an assertion named NAME
6981 and optionally whether it has an asserted token list TOKENS.
6982 NAME is not null terminated; its length is SYM_LENGTH.
6983 If TOKENS_SPECIFIED is 0, then don't check for any token list. */
6986 check_assertion (pfile, name, sym_length, tokens_specified, tokens)
6990 int tokens_specified;
6991 struct arglist *tokens;
6993 ASSERTION_HASHNODE *hp;
6994 int hashcode = hashf (name, sym_length, ASSERTION_HASHSIZE);
6996 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
6997 cpp_pedwarn (pfile, "ANSI C does not allow testing assertions");
6999 hp = assertion_lookup (pfile, name, sym_length, hashcode);
7001 /* It is not an assertion; just return false. */
7004 /* If no token list was specified, then value is 1. */
7005 if (! tokens_specified)
7009 struct tokenlist_list *tail;
7013 /* If a list of tokens was given,
7014 then succeed if the assertion records a matching list. */
7017 if (compare_token_lists (tail->tokens, tokens))
7022 /* Fail if the assertion has no matching list. */
7027 /* Compare two lists of tokens for equality including order of tokens. */
7030 compare_token_lists (l1, l2)
7031 struct arglist *l1, *l2;
7034 if (l1->length != l2->length)
7036 if (strncmp (l1->name, l2->name, l1->length))
7042 /* Succeed if both lists end at the same time. */
7047 reverse_token_list (tokens)
7048 struct arglist *tokens;
7050 register struct arglist *prev = 0, *this, *next;
7051 for (this = tokens; this; this = next)
7060 /* Read a space-separated list of tokens ending in a close parenthesis.
7061 Return a list of strings, in the order they were written.
7062 (In case of error, return 0 and store -1 in *ERROR_FLAG.) */
7064 static struct arglist *
7065 read_token_list (pfile, error_flag)
7069 struct arglist *token_ptrs = 0;
7074 FORWARD (1); /* Skip '(' */
7076 /* Loop over the assertion value tokens. */
7079 struct arglist *temp;
7080 long name_written = CPP_WRITTEN (pfile);
7081 int eofp = 0; int c;
7083 cpp_skip_hspace (pfile);
7087 /* Find the end of the token. */
7090 CPP_PUTC (pfile, c);
7098 CPP_PUTC (pfile, c);
7100 else if (c == '"' || c == '\'')
7103 cpp_get_token (pfile);
7109 while (c != EOF && ! is_space[c] && c != '(' && c != ')'
7110 && c != '"' && c != '\'')
7112 CPP_PUTC (pfile, c);
7115 if (c != EOF) FORWARD(-1);
7118 length = CPP_WRITTEN (pfile) - name_written;
7119 temp = (struct arglist *)
7120 xmalloc (sizeof (struct arglist) + length + 1);
7121 temp->name = (U_CHAR *) (temp + 1);
7122 bcopy ((char *) (pfile->token_buffer + name_written),
7123 (char *) temp->name, length);
7124 temp->name[length] = 0;
7125 temp->next = token_ptrs;
7127 temp->length = length;
7129 CPP_ADJUST_WRITTEN (pfile, -length); /* pop */
7131 if (c == EOF || c == '\n')
7134 "unterminated token sequence following `#' operator");
7139 /* We accumulated the names in reverse order.
7140 Now reverse them to get the proper order. */
7141 return reverse_token_list (token_ptrs);
7145 free_token_list (tokens)
7146 struct arglist *tokens;
7149 struct arglist *next = tokens->next;
7150 free (tokens->name);
7156 /* Get the file-mode and data size of the file open on FD
7157 and store them in *MODE_POINTER and *SIZE_POINTER. */
7160 file_size_and_mode (fd, mode_pointer, size_pointer)
7163 long int *size_pointer;
7167 if (fstat (fd, &sbuf) < 0) return (-1);
7168 if (mode_pointer) *mode_pointer = sbuf.st_mode;
7169 if (size_pointer) *size_pointer = sbuf.st_size;
7173 /* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
7174 retrying if necessary. Return a negative value if an error occurs,
7175 otherwise return the actual number of bytes read,
7176 which must be LEN unless end-of-file was reached. */
7179 safe_read (desc, ptr, len)
7186 int nchars = read (desc, ptr, left);
7207 unsigned size = strlen (input);
7208 char *output = xmalloc (size + 1);
7209 strcpy (output, input);
7213 /* Initialize PMARK to remember the current position of PFILE. */
7215 parse_set_mark (pmark, pfile)
7216 struct parse_marker *pmark;
7219 cpp_buffer *pbuf = CPP_BUFFER (pfile);
7220 pmark->next = pbuf->marks;
7221 pbuf->marks = pmark;
7223 pmark->position = pbuf->cur - pbuf->buf;
7226 /* Cleanup PMARK - we no longer need it. */
7228 parse_clear_mark (pmark)
7229 struct parse_marker *pmark;
7231 struct parse_marker **pp = &pmark->buf->marks;
7232 for (; ; pp = &(*pp)->next) {
7233 if (*pp == NULL) fatal ("internal error", "in parse_set_mark");
7234 if (*pp == pmark) break;
7239 /* Backup the current position of PFILE to that saved in PMARK. */
7242 parse_goto_mark (pmark, pfile)
7243 struct parse_marker *pmark;
7246 cpp_buffer *pbuf = CPP_BUFFER (pfile);
7247 if (pbuf != pmark->buf)
7248 fatal ("internal error %s", "parse_goto_mark");
7249 pbuf->cur = pbuf->buf + pmark->position;
7252 /* Reset PMARK to point to the current position of PFILE. (Same
7253 as parse_clear_mark (PMARK), parse_set_mark (PMARK, PFILE) but faster. */
7256 parse_move_mark (pmark, pfile)
7257 struct parse_marker *pmark;
7260 cpp_buffer *pbuf = CPP_BUFFER (pfile);
7261 if (pbuf != pmark->buf)
7262 fatal ("internal error %s", "parse_move_mark");
7263 pmark->position = pbuf->cur - pbuf->buf;
7267 cpp_read_check_assertion (pfile)
7270 int name_start = CPP_WRITTEN (pfile);
7271 int name_length, name_written;
7273 FORWARD (1); /* Skip '#' */
7274 cpp_skip_hspace (pfile);
7275 parse_name (pfile, GETC ());
7276 name_written = CPP_WRITTEN (pfile);
7277 name_length = name_written - name_start;
7278 cpp_skip_hspace (pfile);
7279 if (CPP_BUF_PEEK (CPP_BUFFER (pfile)) == '(')
7282 struct arglist *token_ptrs = read_token_list (pfile, &error_flag);
7283 result = check_assertion (pfile,
7284 pfile->token_buffer + name_start, name_length,
7288 result = check_assertion (pfile,
7289 pfile->token_buffer + name_start, name_length,
7291 CPP_ADJUST_WRITTEN (pfile, - name_length); /* pop */
7296 cpp_print_file_and_line (pfile)
7299 cpp_buffer *ip = cpp_file_buffer (pfile);
7304 cpp_buf_line_and_col (ip, &line, &col);
7305 cpp_file_line_for_message (pfile, ip->nominal_fname,
7306 line, pfile->show_column ? col : -1);
7311 cpp_error (pfile, msg, arg1, arg2, arg3)
7314 char *arg1, *arg2, *arg3;
7316 cpp_print_containing_files (pfile);
7317 cpp_print_file_and_line (pfile);
7318 cpp_message (pfile, 1, msg, arg1, arg2, arg3);
7321 /* Print error message but don't count it. */
7324 cpp_warning (pfile, msg, arg1, arg2, arg3)
7327 char *arg1, *arg2, *arg3;
7329 if (CPP_OPTIONS (pfile)->inhibit_warnings)
7332 if (CPP_OPTIONS (pfile)->warnings_are_errors)
7335 cpp_print_containing_files (pfile);
7336 cpp_print_file_and_line (pfile);
7337 cpp_message (pfile, 0, msg, arg1, arg2, arg3);
7340 /* Print an error message and maybe count it. */
7343 cpp_pedwarn (pfile, msg, arg1, arg2, arg3)
7346 char *arg1, *arg2, *arg3;
7348 if (CPP_OPTIONS (pfile)->pedantic_errors)
7349 cpp_error (pfile, msg, arg1, arg2, arg3);
7351 cpp_warning (pfile, msg, arg1, arg2, arg3);
7355 cpp_error_with_line (pfile, line, column, msg, arg1, arg2, arg3)
7359 char *arg1, *arg2, *arg3;
7362 cpp_buffer *ip = cpp_file_buffer (pfile);
7364 cpp_print_containing_files (pfile);
7367 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
7369 cpp_message (pfile, 1, msg, arg1, arg2, arg3);
7373 cpp_warning_with_line (pfile, line, column, msg, arg1, arg2, arg3)
7377 char *arg1, *arg2, *arg3;
7382 if (CPP_OPTIONS (pfile)->inhibit_warnings)
7385 if (CPP_OPTIONS (pfile)->warnings_are_errors)
7388 cpp_print_containing_files (pfile);
7390 ip = cpp_file_buffer (pfile);
7393 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
7395 cpp_message (pfile, 0, msg, arg1, arg2, arg3);
7399 cpp_pedwarn_with_line (pfile, line, column, msg, arg1, arg2, arg3)
7403 char *arg1, *arg2, *arg3;
7405 if (CPP_OPTIONS (pfile)->pedantic_errors)
7406 cpp_error_with_line (pfile, column, line, msg, arg1, arg2, arg3);
7408 cpp_warning_with_line (pfile, line, column, msg, arg1, arg2, arg3);
7411 /* Report a warning (or an error if pedantic_errors)
7412 giving specified file name and line number, not current. */
7415 cpp_pedwarn_with_file_and_line (pfile, file, line, msg, arg1, arg2, arg3)
7420 char *arg1, *arg2, *arg3;
7422 if (!CPP_OPTIONS (pfile)->pedantic_errors
7423 && CPP_OPTIONS (pfile)->inhibit_warnings)
7426 cpp_file_line_for_message (pfile, file, line, -1);
7427 cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors,
7428 msg, arg1, arg2, arg3);
7431 /* This defines "errno" properly for VMS, and gives us EACCES. */
7438 #ifndef HAVE_STRERROR
7439 extern int sys_nerr;
7441 extern const char *const sys_errlist[];
7443 extern char *sys_errlist[];
7445 #else /* HAVE_STRERROR */
7449 char *strerror (int,...);
7453 * my_strerror - return the descriptive text associated with an `errno' code.
7457 my_strerror (errnum)
7463 #ifndef HAVE_STRERROR
7464 result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
7466 result = strerror (errnum);
7469 /* VAXCRTL's strerror() takes an optional second argument, which only
7470 matters when the first argument is EVMSERR. However, it's simplest
7471 just to pass it unconditionally. `vaxc$errno' is declared in
7472 <errno.h>, and maintained by the library in parallel with `errno'.
7473 We assume that caller's `errnum' either matches the last setting of
7474 `errno' by the library or else does not have the value `EVMSERR'. */
7476 result = strerror (errnum, vaxc$errno);
7480 result = "undocumented I/O error";
7485 /* Error including a message from `errno'. */
7488 cpp_error_from_errno (pfile, name)
7493 cpp_buffer *ip = cpp_file_buffer (pfile);
7495 cpp_print_containing_files (pfile);
7498 cpp_file_line_for_message (pfile, ip->nominal_fname, ip->lineno, -1);
7500 cpp_message (pfile, 1, "%s: %s", name, my_strerror (errno));
7504 cpp_perror_with_name (pfile, name)
7508 cpp_message (pfile, 1, "%s: %s: %s", progname, name, my_strerror (errno));
7512 * No pre-compiled header file support.
7514 * Possibly different enum token codes for each C/C++ token.
7516 * Should clean up remaining directives to that do_XXX functions
7517 * only take two arguments and all have command_reads_line.
7519 * Find and cleanup remaining uses of static variables,
7521 * Support for trigraphs.
7523 * Support -dM flag (dump_all_macros).
7525 * Support for_lint flag.