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, 675 Mass Ave, Cambridge, MA 02139, 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 ':'
69 /* In case config.h defines these. */
74 #include <sys/types.h>
86 #include <sys/time.h> /* for __DATE__ and __TIME__ */
87 #include <sys/resource.h>
89 #include <sys/param.h> /* CYGNUS LOCAL: shebs -noquiet */
90 #include <sys/times.h>
96 /* This defines "errno" properly for VMS, and gives us EACCES. */
99 extern char *index ();
100 extern char *rindex ();
108 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
109 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
111 /* Find the largest host integer type and set its size and type. */
113 #ifndef HOST_BITS_PER_WIDE_INT
115 #if HOST_BITS_PER_LONG > HOST_BITS_PER_INT
116 #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG
117 #define HOST_WIDE_INT long
119 #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT
120 #define HOST_WIDE_INT int
126 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
130 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
133 /* Define a generic NULL if one hasn't already been defined. */
140 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
141 #define GENERIC_PTR void *
143 #define GENERIC_PTR char *
148 #define NULL_PTR ((GENERIC_PTR)0)
151 #ifndef INCLUDE_LEN_FUDGE
152 #define INCLUDE_LEN_FUDGE 0
155 /* Symbols to predefine. */
157 #ifdef CPP_PREDEFINES
158 static char *predefs = CPP_PREDEFINES;
160 static char *predefs = "";
163 /* We let tm.h override the types used here, to handle trivial differences
164 such as the choice of unsigned int or long unsigned int for size_t.
165 When machines start needing nontrivial differences in the size type,
166 it would be best to do something here to figure out automatically
167 from other information what type to use. */
169 /* The string value for __SIZE_TYPE__. */
172 #define SIZE_TYPE "long unsigned int"
175 /* The string value for __PTRDIFF_TYPE__. */
178 #define PTRDIFF_TYPE "long int"
181 /* The string value for __WCHAR_TYPE__. */
184 #define WCHAR_TYPE "int"
186 #define CPP_WCHAR_TYPE(PFILE) \
187 (CPP_OPTIONS (PFILE)->cplusplus ? "__wchar_t" : WCHAR_TYPE)
189 /* The string value for __USER_LABEL_PREFIX__ */
191 #ifndef USER_LABEL_PREFIX
192 #define USER_LABEL_PREFIX ""
195 /* The string value for __REGISTER_PREFIX__ */
197 #ifndef REGISTER_PREFIX
198 #define REGISTER_PREFIX ""
201 /* In the definition of a #assert name, this structure forms
202 a list of the individual values asserted.
203 Each value is itself a list of "tokens".
204 These are strings that are compared by name. */
206 struct tokenlist_list {
207 struct tokenlist_list *next;
208 struct arglist *tokens;
211 struct assertion_hashnode {
212 struct assertion_hashnode *next; /* double links for easy deletion */
213 struct assertion_hashnode *prev;
214 /* also, a back pointer to this node's hash
215 chain is kept, in case the node is the head
216 of the chain and gets deleted. */
217 struct assertion_hashnode **bucket_hdr;
218 int length; /* length of token, for quick comparison */
219 U_CHAR *name; /* the actual name */
220 /* List of token-sequences. */
221 struct tokenlist_list *value;
224 #define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
225 #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
227 #define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? CPP_BUFFER (pfile)->cur[N] : EOF)
228 #define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N))
229 #define GETC() CPP_BUF_GET (CPP_BUFFER (pfile))
230 #define PEEKC() CPP_BUF_PEEK (CPP_BUFFER (pfile))
231 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
232 (Note that it is false while we're expanding marco *arguments*.) */
233 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->cleanup == macro_cleanup)
235 /* Move all backslash-newline pairs out of embarrassing places.
236 Exchange all such pairs following BP
237 with any potentially-embarrassing characters that follow them.
238 Potentially-embarrassing characters are / and *
239 (because a backslash-newline inside a comment delimiter
240 would cause it not to be recognized). */
242 #define NEWLINE_FIX \
243 do {while (PEEKC() == '\\' && PEEKN(1) == '\n') FORWARD(2); } while(0)
245 /* Same, but assume we've already read the potential '\\' into C. */
246 #define NEWLINE_FIX1(C) do { \
247 while ((C) == '\\' && PEEKC() == '\n') { FORWARD(1); (C) = GETC(); }\
250 /* Name under which this program was invoked. */
255 struct cpp_pending *next;
260 /* Forward declarations. */
262 extern char *xmalloc ();
264 static void add_import ();
265 static void append_include_chain ();
266 static void make_undef ();
267 static void make_definition ();
268 static void make_assertion ();
269 static void path_include ();
270 static void initialize_builtins ();
271 static void initialize_char_syntax ();
272 static void dump_arg_n ();
273 static void dump_defn_1 ();
274 extern void delete_macro ();
275 static void trigraph_pcp ();
276 static int finclude ();
277 static void validate_else ();
278 static int comp_def_part ();
279 extern void fancy_abort ();
280 static void pipe_closed ();
281 static void print_containing_files ();
282 static int lookup_import ();
283 static int redundant_include_p ();
284 static is_system_include ();
285 static struct file_name_map *read_name_map ();
286 static char *read_filename_string ();
287 static int open_include_file ();
288 static int check_preconditions ();
289 static void pcfinclude ();
290 static void pcstring_used ();
291 static int check_macro_name ();
292 static int compare_defs ();
293 static int compare_token_lists ();
294 static HOST_WIDE_INT eval_if_expression ();
295 static int change_newlines ();
296 static int line_for_error ();
298 static int file_size_and_mode ();
299 static struct arglist *read_token_list ();
300 static void free_token_list ();
301 static int safe_read ();
302 static void push_macro_expansion PARAMS ((cpp_reader *,
303 U_CHAR*, int, HASHNODE*));
304 extern char *xrealloc ();
305 extern char *xcalloc ();
306 static char *savestring ();
308 static void conditional_skip ();
309 static void skip_if_group ();
311 /* Last arg to output_line_command. */
312 enum file_change_code {same_file, enter_file, leave_file};
314 /* External declarations. */
316 extern HOST_WIDE_INT cpp_parse_expr PARAMS ((cpp_reader*));
318 extern char *getenv ();
319 extern FILE *fdopen ();
320 extern char *version_string;
321 extern struct tm *localtime ();
323 /* These functions are declared to return int instead of void since they
324 are going to be placed in a table and some old compilers have trouble with
325 pointers to functions returning void. */
327 static int do_define ();
328 static int do_line ();
329 static int do_include ();
330 static int do_undef ();
331 static int do_error ();
332 static int do_pragma ();
333 static int do_ident ();
335 static int do_xifdef ();
336 static int do_else ();
337 static int do_elif ();
338 static int do_endif ();
339 static int do_sccs ();
340 static int do_once ();
341 static int do_assert ();
342 static int do_unassert ();
343 static int do_warning ();
345 struct file_name_list
347 struct file_name_list *next;
349 /* If the following is nonzero, it is a macro name.
350 Don't include the file again if that macro is defined. */
351 U_CHAR *control_macro;
352 /* If the following is nonzero, it is a C-language system include
354 int c_system_include_path;
355 /* Mapping of file names for this directory. */
356 struct file_name_map *name_map;
357 /* Non-zero if name_map is valid. */
361 /* #include "file" looks in source file dir, then stack. */
362 /* #include <file> just looks in the stack. */
363 /* -I directories are added to the end, then the defaults are added. */
365 static struct default_include {
366 char *fname; /* The name of the directory. */
367 int cplusplus; /* Only look here if we're compiling C++. */
368 int cxx_aware; /* Includes in this directory don't need to
369 be wrapped in extern "C" when compiling
371 } include_defaults_array[]
372 #ifdef INCLUDE_DEFAULTS
376 /* Pick up GNU C++ specific include files. */
377 { GPLUSPLUS_INCLUDE_DIR, 1, 1 },
379 /* This is the dir for fixincludes. Put it just before
380 the files that we fix. */
381 { GCC_INCLUDE_DIR, 0, 0 },
382 /* For cross-compilation, this dir name is generated
383 automatically in Makefile.in. */
384 { CROSS_INCLUDE_DIR, 0, 0 },
385 /* This is another place that the target system's headers might be. */
386 { TOOL_INCLUDE_DIR, 0, 1 },
387 #else /* not CROSS_COMPILE */
388 /* This should be /usr/local/include and should come before
389 the fixincludes-fixed header files. */
390 { LOCAL_INCLUDE_DIR, 0, 1 },
391 /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
392 Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
393 { TOOL_INCLUDE_DIR, 0, 1 },
394 /* This is the dir for fixincludes. Put it just before
395 the files that we fix. */
396 { GCC_INCLUDE_DIR, 0, 0 },
397 /* Some systems have an extra dir of include files. */
398 #ifdef SYSTEM_INCLUDE_DIR
399 { SYSTEM_INCLUDE_DIR, 0, 0 },
401 { STANDARD_INCLUDE_DIR, 0, 0 },
402 #endif /* not CROSS_COMPILE */
405 #endif /* no INCLUDE_DEFAULTS */
407 /* `struct directive' defines one #-directive, including how to handle it. */
410 int length; /* Length of name */
411 int (*func)(); /* Function to handle directive */
412 char *name; /* Name of directive */
413 enum node_type type; /* Code which describes which directive. */
414 char command_reads_line; /* One if rest of line is read by func. */
415 char traditional_comments; /* Nonzero: keep comments if -traditional. */
416 char pass_thru; /* Copy preprocessed directive to output file.*/
419 /* Here is the actual list of #-directives, most-often-used first.
420 The initialize_builtins function assumes #define is the very first. */
422 static struct directive directive_table[] = {
423 { 6, do_define, "define", T_DEFINE, 0, 1},
424 { 5, do_xifdef, "ifdef", T_IFDEF, 1},
425 { 6, do_xifdef, "ifndef", T_IFNDEF, 1},
426 { 7, do_include, "include", T_INCLUDE, 1},
427 { 12, do_include, "include_next", T_INCLUDE_NEXT, 1},
428 { 6, do_include, "import", T_IMPORT, 1},
429 { 5, do_endif, "endif", T_ENDIF, 1},
430 { 4, do_else, "else", T_ELSE, 1},
431 { 2, do_if, "if", T_IF, 1},
432 { 4, do_elif, "elif", T_ELIF, 1},
433 { 5, do_undef, "undef", T_UNDEF},
434 { 5, do_error, "error", T_ERROR},
435 { 7, do_warning, "warning", T_WARNING},
436 { 6, do_pragma, "pragma", T_PRAGMA, 0, 0, 1},
437 { 4, do_line, "line", T_LINE, 1},
438 { 5, do_ident, "ident", T_IDENT, 1, 0, 1},
439 #ifdef SCCS_DIRECTIVE
440 { 4, do_sccs, "sccs", T_SCCS},
442 { 6, do_assert, "assert", T_ASSERT, 1},
443 { 8, do_unassert, "unassert", T_UNASSERT, 1},
444 { -1, 0, "", T_UNUSED},
447 /* table to tell if char can be part of a C identifier. */
448 U_CHAR is_idchar[256];
449 /* table to tell if char can be first char of a c identifier. */
450 U_CHAR is_idstart[256];
451 /* table to tell if c is horizontal space. */
452 U_CHAR is_hor_space[256];
453 /* table to tell if c is horizontal or vertical space. */
454 static U_CHAR is_space[256];
456 /* Initialize syntactic classifications of characters. */
459 initialize_char_syntax (opts)
460 struct cpp_options *opts;
465 * Set up is_idchar and is_idstart tables. These should be
466 * faster than saying (is_alpha (c) || c == '_'), etc.
467 * Set up these things before calling any routines tthat
470 for (i = 'a'; i <= 'z'; i++) {
471 is_idchar[i - 'a' + 'A'] = 1;
473 is_idstart[i - 'a' + 'A'] = 1;
476 for (i = '0'; i <= '9'; i++)
480 is_idchar['$'] = opts->dollars_in_ident;
481 is_idstart['$'] = opts->dollars_in_ident;
483 /* horizontal space table */
484 is_hor_space[' '] = 1;
485 is_hor_space['\t'] = 1;
486 is_hor_space['\v'] = 1;
487 is_hor_space['\f'] = 1;
488 is_hor_space['\r'] = 1;
499 * Skip over a quoted string. BP points to the opening quote.
500 * Returns a pointer after the closing quote. Don't go past LIMIT.
501 * START_LINE is the line number of the starting point (but it need
502 * not be valid if the starting point is inside a macro expansion).
504 * The input stack state is not changed.
507 skip_quoted_string (pfile, first, start_line)
519 cpp_error_with_line (pfile, line_for_error (start_line),
520 "unterminated string or character constant");
522 cpp_error_with_line (pfile, multiline_string_line,
523 "possible real start of unterminated constant");
524 multiline_string_line = 0;
535 if (CPP_TRADITIONAL (pfile))
537 /* Unterminated strings and character constants are 'legal'. */
538 FORWARD(-1); /* Don't consume the newline. */
541 if (CPP_PEDANTIC (pfile) || first == '\'')
543 cpp_error_with_line (pfile, line_for_error (start_line),
544 "unterminated string or character constant");
548 /* If not traditional, then allow newlines inside strings. */
550 if (multiline_string_line == 0)
551 multiline_string_line = start_line;
559 /* Place into PFILE a quoted string representing the string SRC.
560 Caller must reserve enough space in pfile->token_buffer. */
562 quote_string (pfile, src)
568 CPP_PUTC_Q (pfile, '\"');
570 switch ((c = *src++))
574 CPP_PUTC_Q (pfile, c);
577 sprintf (CPP_PWRITTEN (pfile), "\\%03o", c);
578 CPP_ADJUST_WRITTEN (pfile, 4);
584 CPP_PUTC_Q (pfile, '\\');
585 CPP_PUTC_Q (pfile, c);
589 CPP_PUTC_Q (pfile, '\"');
590 CPP_NUL_TERMINATE_Q (pfile);
595 /* Make sure PFILE->token_buffer will hold at least N more chars. */
598 cpp_grow_buffer (pfile, n)
602 long old_written = CPP_WRITTEN (pfile);
603 pfile->token_buffer_size = n + 2 * pfile->token_buffer_size;
604 pfile->token_buffer = (char*)
605 xrealloc(pfile->token_buffer, pfile->token_buffer_size);
606 CPP_SET_WRITTEN (pfile, old_written);
611 * process a given definition string, for initialization
612 * If STR is just an identifier, define it with value 1.
613 * If STR has anything after the identifier, then it should
614 * be identifier=definition.
618 make_definition (pfile, str)
628 cpp_error (pfile, "malformed option `-D %s'", str);
631 while (is_idchar[*++p])
635 buf = (U_CHAR *) alloca (p - buf + 4);
636 strcpy ((char *)buf, str);
637 strcat ((char *)buf, " 1");
641 cpp_error (pfile, "malformed option `-D %s'", str);
647 /* Copy the entire option so we can modify it. */
648 buf = (U_CHAR *) alloca (2 * strlen (str) + 1);
649 strncpy (buf, str, p - str);
650 /* Change the = to a space. */
652 /* Scan for any backslash-newline and remove it. */
657 if (*p == '\\' && p[1] == '\n')
665 do_define (pfile, NULL, buf, buf + strlen (buf));
668 /* Process the string STR as if it appeared as the body of a #assert.
669 OPTION is the option name for which STR was the argument. */
672 make_assertion (pfile, option, str)
678 struct directive *kt;
681 /* Copy the entire option so we can modify it. */
682 buf = (U_CHAR *) alloca (strlen (str) + 1);
683 strcpy ((char *) buf, str);
684 /* Scan for any backslash-newline and remove it. */
688 if (*p == '\\' && p[1] == '\n')
697 if (!is_idstart[*p]) {
698 cpp_error (pfile, "malformed option `%s %s'", option, str);
701 while (is_idchar[*++p])
703 while (*p == ' ' || *p == '\t') p++;
704 if (! (*p == 0 || *p == '(')) {
705 cpp_error (pfile, "malformed option `%s %s'", option, str);
709 ip = cpp_push_buffer (pfile, buf, strlen (buf));
710 do_assert (pfile, NULL, NULL, NULL);
711 cpp_pop_buffer (pfile);
714 /* Append a chain of `struct file_name_list's
715 to the end of the main include chain.
716 FIRST is the beginning of the chain to append, and LAST is the end. */
719 append_include_chain (pfile, first, last)
721 struct file_name_list *first, *last;
723 struct cpp_options *opts = CPP_OPTIONS (pfile);
724 struct file_name_list *dir;
729 if (opts->include == 0)
730 opts->include = first;
732 opts->last_include->next = first;
734 if (opts->first_bracket_include == 0)
735 opts->first_bracket_include = first;
737 for (dir = first; ; dir = dir->next) {
738 int len = strlen (dir->fname) + INCLUDE_LEN_FUDGE;
739 if (len > pfile->max_include_len)
740 pfile->max_include_len = len;
746 opts->last_include = last;
749 /* Add output to `deps_buffer' for the -M switch.
750 STRING points to the text to be output.
751 SPACER is ':' for targets, ' ' for dependencies, zero for text
752 to be inserted literally. */
755 deps_output (pfile, string, spacer)
760 int size = strlen (string);
765 #ifndef MAX_OUTPUT_COLUMNS
766 #define MAX_OUTPUT_COLUMNS 72
769 && pfile->deps_column > 0
770 && (pfile->deps_column + size) > MAX_OUTPUT_COLUMNS)
772 deps_output (pfile, " \\\n ", 0);
773 pfile->deps_column = 0;
776 if (pfile->deps_size + size + 8 > pfile->deps_allocated_size)
778 pfile->deps_allocated_size = (pfile->deps_size + size + 50) * 2;
779 pfile->deps_buffer = (char *) xrealloc (pfile->deps_buffer,
780 pfile->deps_allocated_size);
782 if (spacer == ' ' && pfile->deps_column > 0)
783 pfile->deps_buffer[pfile->deps_size++] = ' ';
784 bcopy (string, &pfile->deps_buffer[pfile->deps_size], size);
785 pfile->deps_size += size;
786 pfile->deps_column += size;
788 pfile->deps_buffer[pfile->deps_size++] = ':';
789 pfile->deps_buffer[pfile->deps_size] = 0;
792 /* Given a colon-separated list of file names PATH,
793 add all the names to the search path for include files. */
796 path_include (pfile, path)
808 struct file_name_list *dirtmp;
810 /* Find the end of this name. */
811 while (*q != 0 && *q != PATH_SEPARATOR) q++;
813 /* An empty name in the path stands for the current directory. */
814 name = (char *) xmalloc (2);
818 /* Otherwise use the directory that is named. */
819 name = (char *) xmalloc (q - p + 1);
820 bcopy (p, name, q - p);
824 dirtmp = (struct file_name_list *)
825 xmalloc (sizeof (struct file_name_list));
826 dirtmp->next = 0; /* New one goes on the end */
827 dirtmp->control_macro = 0;
828 dirtmp->c_system_include_path = 0;
829 dirtmp->fname = name;
830 dirtmp->got_name_map = 0;
831 append_include_chain (pfile, dirtmp, dirtmp);
833 /* Advance past this name. */
837 /* Skip the colon. */
843 init_parse_options (opts)
844 struct cpp_options *opts;
846 bzero (opts, sizeof *opts);
847 opts->in_fname = NULL;
848 opts->out_fname = NULL;
850 /* Initialize is_idchar to allow $. */
851 opts->dollars_in_ident = 1;
852 initialize_char_syntax (opts);
853 opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 0;
855 opts->no_line_commands = 0;
856 opts->no_trigraphs = 1;
857 opts->put_out_comments = 0;
858 opts->print_include_names = 0;
859 opts->dump_macros = dump_none;
862 opts->cplusplus_comments = 0;
869 opts->pedantic_errors = 0;
870 opts->inhibit_warnings = 0;
871 opts->warn_comments = 0;
872 opts->warn_import = 1;
873 opts->warnings_are_errors = 0;
877 null_underflow (pfile)
884 null_cleanup (pbuf, pfile)
892 macro_cleanup (pbuf, pfile)
896 HASHNODE *macro = (HASHNODE*)pbuf->data;
897 if (macro->type == T_DISABLED)
898 macro->type = T_MACRO;
899 if (macro->type != T_MACRO || pbuf->buf != macro->value.defn->expansion)
905 file_cleanup (pbuf, pfile)
919 register U_CHAR *p = bp;
921 /* First count the backslash-newline pairs here. */
923 while (p[0] == '\\' && p[1] == '\n')
926 /* What follows the backslash-newlines is not embarrassing. */
928 if (*p != '/' && *p != '*')
931 /* Copy all potentially embarrassing characters
932 that follow the backslash-newline pairs
933 down to where the pairs originally started. */
935 while (*p == '*' || *p == '/')
938 /* Now write the same number of pairs after the embarrassing chars. */
946 /* Assuming we have read '/'.
947 If this is the start of a comment (followed by '*' or '/'),
948 skip to the end of the comment, and return ' '.
949 Return EOF if we reached the end of file before the end of the comment.
950 If not the start of a comment, return '/'. */
953 skip_comment (pfile, linep)
958 while (PEEKC() == '\\' && PEEKN(1) == '\n')
973 while (c == '\\' && PEEKC() == '\n')
977 FORWARD(1), c = GETC();
979 if (prev_c == '*' && c == '/')
981 if (c == '\n' && linep)
985 else if (PEEKC() == '/' && CPP_OPTIONS (pfile)->cplusplus_comments)
992 return ' '; /* Allow // to be terminated by EOF. */
993 while (c == '\\' && PEEKC() == '\n')
1002 /* Don't consider final '\n' to be part of comment. */
1012 /* Skip whitespace \-newline and comments. Does not macro-expand. */
1014 cpp_skip_hspace (pfile)
1022 if (is_hor_space[c])
1024 if ((c == '\f' || c == '\v') && CPP_PEDANTIC (pfile))
1025 cpp_pedwarn (pfile, "%s in preprocessing directive",
1026 c == '\f' ? "formfeed" : "vertical tab");
1032 c = skip_comment (pfile, NULL);
1035 if (c == EOF || c == '/')
1038 else if (c == '\\' && PEEKN(1) == '\n') {
1045 /* Read the rest of the current line.
1046 The line is appended to PFILE's output buffer. */
1049 copy_rest_of_line (pfile)
1052 struct cpp_options *opts = CPP_OPTIONS (pfile);
1062 if (PEEKC() == '\n')
1069 goto scan_directive_token;
1073 if (nextc == '*' || (opts->cplusplus_comments && nextc == '*'))
1074 goto scan_directive_token;
1078 if (CPP_PEDANTIC (pfile))
1079 cpp_pedwarn (pfile, "%s in preprocessing directive",
1080 c == '\f' ? "formfeed" : "vertical tab");
1086 scan_directive_token:
1088 cpp_get_token (pfile);
1091 CPP_PUTC (pfile, c);
1094 CPP_NUL_TERMINATE (pfile);
1098 skip_rest_of_line (pfile)
1101 long old = CPP_WRITTEN (pfile);
1102 copy_rest_of_line (pfile);
1103 CPP_SET_WRITTEN (pfile, old);
1106 /* Handle a possible # directive.
1107 '#' has already been read. */
1110 handle_directive (pfile)
1113 register struct directive *kt;
1116 U_CHAR *ident, *line_end;
1117 long old_written = CPP_WRITTEN (pfile);
1119 cpp_skip_hspace (pfile);
1122 if (c >= '0' && c <= '9')
1124 /* Handle # followed by a line number. */
1125 if (CPP_PEDANTIC (pfile))
1126 cpp_pedwarn (pfile, "`#' followed by integer");
1127 do_line (pfile, NULL);
1128 goto done_a_directive;
1131 /* Now find the directive name. */
1132 CPP_PUTC (pfile, '#');
1133 parse_name (pfile, GETC());
1134 ident = pfile->token_buffer + old_written + 1;
1135 ident_length = CPP_PWRITTEN (pfile) - ident;
1136 if (ident_length == 0 && PEEKC() == '\n')
1138 /* A line of just `#' becomes blank. */
1139 goto done_a_directive;
1143 if (ident_length == 0 || !is_idstart[*ident]) {
1145 while (is_idchar[*p]) {
1146 if (*p < '0' || *p > '9')
1150 /* Avoid error for `###' and similar cases unless -pedantic. */
1152 while (*p == '#' || is_hor_space[*p]) p++;
1154 if (pedantic && !lang_asm)
1155 cpp_warning (pfile, "invalid preprocessor directive");
1161 cpp_error (pfile, "invalid preprocessor directive name");
1167 * Decode the keyword and call the appropriate expansion
1168 * routine, after moving the input pointer up to the next line.
1170 for (kt = directive_table; ; kt++) {
1171 if (kt->length <= 0)
1172 goto not_a_directive;
1173 if (kt->length == ident_length && !strncmp (kt->name, ident, ident_length))
1177 if (! kt->command_reads_line)
1179 /* Nonzero means do not delete comments within the directive.
1180 #define needs this when -traditional. */
1181 int comments = CPP_TRADITIONAL (pfile) && kt->traditional_comments;
1182 int save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
1183 CPP_OPTIONS (pfile)->put_out_comments = comments;
1184 after_ident = CPP_WRITTEN (pfile);
1185 copy_rest_of_line (pfile);
1186 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
1189 /* For #pragma and #define, we may want to pass through the directive.
1190 Other directives may create output, but we don't want the directive
1191 itself out, so we pop it now. For example #include may write a #line
1192 command (see comment in do_include), and conditionals may emit
1193 #failed ... #endfailed stuff. But note that popping the buffer
1194 means the parameters to kt->func may point after pfile->limit
1195 so these parameters are invalid as soon as something gets appended
1196 to the token_buffer. */
1198 line_end = CPP_PWRITTEN (pfile);
1199 if (!kt->pass_thru && kt->type != T_DEFINE)
1200 CPP_SET_WRITTEN (pfile, old_written);
1202 (*kt->func) (pfile, kt, pfile->token_buffer + after_ident, line_end);
1204 || (kt->type == T_DEFINE
1205 && CPP_OPTIONS (pfile)->dump_macros == dump_definitions))
1207 /* Just leave the entire #define in the output stack. */
1209 else if (kt->type == T_DEFINE
1210 && CPP_OPTIONS (pfile)->dump_macros == dump_names)
1212 U_CHAR *p = pfile->token_buffer + old_written + 7; /* Skip "#define". */
1213 SKIP_WHITE_SPACE (p);
1214 while (is_idchar[*p]) p++;
1216 CPP_PUTC (pfile, '\n');
1218 else if (kt->type == T_DEFINE)
1219 CPP_SET_WRITTEN (pfile, old_written);
1227 /* Pass a directive through to the output file.
1228 BUF points to the contents of the directive, as a contiguous string.
1229 LIMIT points to the first character past the end of the directive.
1230 KEYWORD is the keyword-table entry for the directive. */
1233 pass_thru_directive (buf, limit, pfile, keyword)
1234 U_CHAR *buf, *limit;
1236 struct directive *keyword;
1238 register unsigned keyword_length = keyword->length;
1240 CPP_RESERVE (pfile, 1 + keyword_length + (limit - buf));
1241 CPP_PUTC_Q (pfile, '#');
1242 CPP_PUTS_Q (pfile, keyword->name, keyword_length);
1243 if (limit != buf && buf[0] != ' ')
1244 CPP_PUTC_Q (pfile, ' ');
1245 CPP_PUTS_Q (pfile, buf, limit - buf);
1247 CPP_PUTS_Q (pfile, '\n');
1248 /* Count the line we have just made in the output,
1249 to get in sync properly. */
1254 /* The arglist structure is built by do_define to tell
1255 collect_definition where the argument names begin. That
1256 is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist
1257 would contain pointers to the strings x, y, and z.
1258 Collect_definition would then build a DEFINITION node,
1259 with reflist nodes pointing to the places x, y, and z had
1260 appeared. So the arglist is just convenience data passed
1261 between these two routines. It is not kept around after
1262 the current #define has been processed and entered into the
1266 struct arglist *next;
1273 /* Read a replacement list for a macro with parameters.
1274 Build the DEFINITION structure.
1275 Reads characters of text starting at BUF until END.
1276 ARGLIST specifies the formal parameters to look for
1277 in the text of the definition; NARGS is the number of args
1278 in that list, or -1 for a macro name that wants no argument list.
1279 MACRONAME is the macro name itself (so we can avoid recursive expansion)
1280 and NAMELEN is its length in characters.
1282 Note that comments and backslash-newlines have already been deleted
1283 from the argument. */
1286 collect_expansion (pfile, buf, end, nargs, arglist)
1290 struct arglist *arglist;
1293 register U_CHAR *p, *limit, *lastp, *exp_p;
1294 struct reflist *endpat = NULL;
1295 /* Pointer to first nonspace after last ## seen. */
1297 /* Pointer to first nonspace after last single-# seen. */
1298 U_CHAR *stringify = 0;
1300 int expected_delimiter = '\0';
1302 /* Scan thru the replacement list, ignoring comments and quoted
1303 strings, picking up on the macro calls. It does a linear search
1304 thru the arg list on every potential symbol. Profiling might say
1305 that something smarter should happen. */
1310 /* Find the beginning of the trailing whitespace. */
1311 /* Find end of leading whitespace. */
1314 while (p < limit && is_space[limit[-1]]) limit--;
1315 while (p < limit && is_space[*p]) p++;
1317 /* Allocate space for the text in the macro definition.
1318 Leading and trailing whitespace chars need 2 bytes each.
1319 Each other input char may or may not need 1 byte,
1320 so this is an upper bound.
1321 The extra 2 are for invented trailing newline-marker and final null. */
1322 maxsize = (sizeof (DEFINITION)
1323 + 2 * (end - limit) + 2 * (p - buf)
1325 defn = (DEFINITION *) xcalloc (1, maxsize);
1327 defn->nargs = nargs;
1328 exp_p = defn->expansion = (U_CHAR *) defn + sizeof (DEFINITION);
1333 /* Add one initial space (often removed by macroexpand). */
1336 if (limit - p >= 2 && p[0] == '#' && p[1] == '#') {
1337 cpp_error (pfile, "`##' at start of macro definition");
1341 /* Process the main body of the definition. */
1343 int skipped_arg = 0;
1344 register U_CHAR c = *p++;
1348 if (!CPP_TRADITIONAL (pfile)) {
1352 if (expected_delimiter != '\0') {
1353 if (c == expected_delimiter)
1354 expected_delimiter = '\0';
1356 expected_delimiter = c;
1359 /* Special hack: if a \# is written in the #define
1360 include a # in the definition. This is useless for C code
1361 but useful for preprocessing other things. */
1364 /* \# quotes a # even outside of strings. */
1365 if (p < limit && *p == '#' && !expected_delimiter) {
1368 } else if (p < limit && expected_delimiter) {
1369 /* In a string, backslash goes through
1370 and makes next char ordinary. */
1380 /* # is ordinary inside a string. */
1381 if (expected_delimiter)
1383 if (p < limit && *p == '#') {
1384 /* ##: concatenate preceding and following tokens. */
1385 /* Take out the first #, discard preceding whitespace. */
1387 while (exp_p > lastp && is_hor_space[exp_p[-1]])
1389 /* Skip the second #. */
1391 /* Discard following whitespace. */
1392 SKIP_WHITE_SPACE (p);
1395 cpp_error (pfile, "`##' at end of macro definition");
1396 } else if (nargs >= 0) {
1397 /* Single #: stringify following argument ref.
1398 Don't leave the # in the expansion. */
1400 SKIP_WHITE_SPACE (p);
1401 if (p == limit || ! is_idstart[*p])
1403 "`#' operator is not followed by a macro argument name");
1410 /* In -traditional mode, recognize arguments inside strings and
1411 and character constants, and ignore special properties of #.
1412 Arguments inside strings are considered "stringified", but no
1413 extra quote marks are supplied. */
1417 if (expected_delimiter != '\0') {
1418 if (c == expected_delimiter)
1419 expected_delimiter = '\0';
1421 expected_delimiter = c;
1425 /* Backslash quotes delimiters and itself, but not macro args. */
1426 if (expected_delimiter != 0 && p < limit
1427 && (*p == expected_delimiter || *p == '\\')) {
1434 if (expected_delimiter != '\0') /* No comments inside strings. */
1437 /* If we find a comment that wasn't removed by handle_directive,
1438 this must be -traditional. So replace the comment with
1442 while (p < limit && !(p[-2] == '*' && p[-1] == '/'))
1445 /* Mark this as a concatenation-point, as if it had been ##. */
1453 /* Handle the start of a symbol. */
1454 if (is_idchar[c] && nargs > 0) {
1455 U_CHAR *id_beg = p - 1;
1459 while (p != limit && is_idchar[*p]) p++;
1460 id_len = p - id_beg;
1462 if (is_idstart[c]) {
1463 register struct arglist *arg;
1465 for (arg = arglist; arg != NULL; arg = arg->next) {
1466 struct reflist *tpat;
1468 if (arg->name[0] == c
1469 && arg->length == id_len
1470 && strncmp (arg->name, id_beg, id_len) == 0) {
1471 if (expected_delimiter && CPP_OPTIONS (pfile)->warn_stringify) {
1472 if (CPP_TRADITIONAL (pfile)) {
1473 cpp_warning (pfile, "macro argument `%.*s' is stringified.",
1477 "macro arg `%.*s' would be stringified with -traditional.",
1481 /* If ANSI, don't actually substitute inside a string. */
1482 if (!CPP_TRADITIONAL (pfile) && expected_delimiter)
1484 /* make a pat node for this arg and append it to the end of
1486 tpat = (struct reflist *) xmalloc (sizeof (struct reflist));
1488 tpat->raw_before = concat == id_beg;
1489 tpat->raw_after = 0;
1490 tpat->rest_args = arg->rest_args;
1491 tpat->stringify = (CPP_TRADITIONAL (pfile)
1492 ? expected_delimiter != '\0'
1493 : stringify == id_beg);
1496 defn->pattern = tpat;
1498 endpat->next = tpat;
1501 tpat->argno = arg->argno;
1502 tpat->nchars = exp_p - lastp;
1504 register U_CHAR *p1 = p;
1505 SKIP_WHITE_SPACE (p1);
1506 if (p1 + 2 <= limit && p1[0] == '#' && p1[1] == '#')
1507 tpat->raw_after = 1;
1509 lastp = exp_p; /* place to start copying from next time */
1516 /* If this was not a macro arg, copy it into the expansion. */
1517 if (! skipped_arg) {
1518 register U_CHAR *lim1 = p;
1522 if (stringify == id_beg)
1524 "`#' operator should be followed by a macro argument name");
1530 while (limit < end && is_space[*limit]) {
1531 *exp_p++ = *limit++;
1533 } else if (!CPP_TRADITIONAL (pfile) && expected_delimiter == 0) {
1534 /* There is no trailing whitespace, so invent some in ANSI mode.
1535 But not if "inside a string" (which in ANSI mode
1536 happens only for -D option). */
1542 defn->length = exp_p - defn->expansion;
1544 /* Crash now if we overrun the allocated size. */
1545 if (defn->length + 1 > maxsize)
1549 /* This isn't worth the time it takes. */
1550 /* give back excess storage */
1551 defn->expansion = (U_CHAR *) xrealloc (defn->expansion, defn->length + 1);
1558 * special extension string that can be added to the last macro argument to
1559 * allow it to absorb the "rest" of the arguments when expanded. Ex:
1560 * #define wow(a, b...) process (b, a, b)
1561 * { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); }
1562 * { wow (one, two); } -> { process (two, one, two); }
1563 * if this "rest_arg" is used with the concat token '##' and if it is not
1564 * supplied then the token attached to with ## will not be outputted. Ex:
1565 * #define wow (a, b...) process (b ## , a, ## b)
1566 * { wow (1, 2); } -> { process (2, 1, 2); }
1567 * { wow (one); } -> { process (one); {
1569 static char rest_extension[] = "...";
1570 #define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1)
1572 /* Create a DEFINITION node from a #define directive. Arguments are
1573 as for do_define. */
1575 create_definition (buf, limit, pfile, predefinition)
1576 U_CHAR *buf, *limit;
1580 U_CHAR *bp; /* temp ptr into input buffer */
1581 U_CHAR *symname; /* remember where symbol name starts */
1582 int sym_length; /* and how long it is */
1585 char *file = CPP_BUFFER (pfile) ? CPP_BUFFER (pfile)->nominal_fname : "";
1587 int arglengths = 0; /* Accumulate lengths of arg names
1588 plus number of args. */
1590 cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col);
1594 while (is_hor_space[*bp])
1597 symname = bp; /* remember where it starts */
1599 sym_length = check_macro_name (pfile, bp, "macro");
1602 /* Lossage will occur if identifiers or control keywords are broken
1603 across lines using backslash. This is not the right place to take
1607 struct arglist *arg_ptrs = NULL;
1610 bp++; /* skip '(' */
1611 SKIP_WHITE_SPACE (bp);
1613 /* Loop over macro argument names. */
1614 while (*bp != ')') {
1615 struct arglist *temp;
1617 temp = (struct arglist *) alloca (sizeof (struct arglist));
1619 temp->next = arg_ptrs;
1620 temp->argno = argno++;
1621 temp->rest_args = 0;
1625 cpp_pedwarn (pfile, "another parameter follows `%s'", rest_extension);
1627 if (!is_idstart[*bp])
1628 cpp_pedwarn (pfile, "invalid character in macro parameter name");
1630 /* Find the end of the arg name. */
1631 while (is_idchar[*bp]) {
1633 /* do we have a "special" rest-args extension here? */
1634 if (limit - bp > REST_EXTENSION_LENGTH &&
1635 strncmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
1637 temp->rest_args = 1;
1641 temp->length = bp - temp->name;
1643 bp += REST_EXTENSION_LENGTH;
1644 arglengths += temp->length + 2;
1645 SKIP_WHITE_SPACE (bp);
1646 if (temp->length == 0 || (*bp != ',' && *bp != ')')) {
1647 cpp_error (pfile, "badly punctuated parameter list in `#define'");
1652 SKIP_WHITE_SPACE (bp);
1655 cpp_error (pfile, "unterminated parameter list in `#define'");
1659 struct arglist *otemp;
1661 for (otemp = temp->next; otemp != NULL; otemp = otemp->next)
1662 if (temp->length == otemp->length &&
1663 strncmp (temp->name, otemp->name, temp->length) == 0) {
1666 name = (U_CHAR *) alloca (temp->length + 1);
1667 (void) strncpy (name, temp->name, temp->length);
1668 name[temp->length] = '\0';
1670 "duplicate argument name `%s' in `#define'", name);
1676 ++bp; /* skip paren */
1677 /* Skip exactly one space or tab if any. */
1678 if (bp < limit && (*bp == ' ' || *bp == '\t')) ++bp;
1679 /* now everything from bp before limit is the definition. */
1680 defn = collect_expansion (pfile, bp, limit, argno, arg_ptrs);
1681 defn->rest_args = rest_args;
1683 /* Now set defn->args.argnames to the result of concatenating
1684 the argument names in reverse order
1685 with comma-space between them. */
1686 defn->args.argnames = (U_CHAR *) xmalloc (arglengths + 1);
1688 struct arglist *temp;
1690 for (temp = arg_ptrs; temp; temp = temp->next) {
1691 bcopy (temp->name, &defn->args.argnames[i], temp->length);
1693 if (temp->next != 0) {
1694 defn->args.argnames[i++] = ',';
1695 defn->args.argnames[i++] = ' ';
1698 defn->args.argnames[i] = 0;
1701 /* Simple expansion or empty definition. */
1705 if (is_hor_space[*bp]) {
1707 SKIP_WHITE_SPACE (bp);
1710 case '!': case '"': case '#': case '%': case '&': case '\'':
1711 case ')': case '*': case '+': case ',': case '-': case '.':
1712 case '/': case ':': case ';': case '<': case '=': case '>':
1713 case '?': case '[': case '\\': case ']': case '^': case '{':
1714 case '|': case '}': case '~':
1715 cpp_warning (pfile, "missing white space after `#define %.*s'",
1716 sym_length, symname);
1720 cpp_pedwarn (pfile, "missing white space after `#define %.*s'",
1721 sym_length, symname);
1726 /* now everything from bp before limit is the definition. */
1727 defn = collect_expansion (pfile, bp, limit, -1, NULL_PTR);
1728 defn->args.argnames = (U_CHAR *) "";
1734 /* OP is null if this is a predefinition */
1735 defn->predefined = predefinition;
1737 mdef.symnam = symname;
1738 mdef.symlen = sym_length;
1747 /* Check a purported macro name SYMNAME, and yield its length.
1748 USAGE is the kind of name this is intended for. */
1751 check_macro_name (pfile, symname, usage)
1759 for (p = symname; is_idchar[*p]; p++)
1761 sym_length = p - symname;
1762 if (sym_length == 0)
1763 cpp_error (pfile, "invalid %s name", usage);
1764 else if (!is_idstart[*symname]) {
1765 U_CHAR *msg; /* what pain... */
1766 msg = (U_CHAR *) alloca (sym_length + 1);
1767 bcopy (symname, msg, sym_length);
1768 msg[sym_length] = 0;
1769 cpp_error (pfile, "invalid %s name `%s'", usage, msg);
1771 if (! strncmp (symname, "defined", 7) && sym_length == 7)
1772 cpp_error (pfile, "invalid %s name `defined'", usage);
1778 * return zero if two DEFINITIONs are isomorphic
1781 compare_defs (d1, d2)
1782 DEFINITION *d1, *d2;
1784 register struct reflist *a1, *a2;
1785 register U_CHAR *p1 = d1->expansion;
1786 register U_CHAR *p2 = d2->expansion;
1789 if (d1->nargs != d2->nargs)
1791 if (strcmp ((char *)d1->args.argnames, (char *)d2->args.argnames))
1793 for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2;
1794 a1 = a1->next, a2 = a2->next) {
1795 if (!((a1->nchars == a2->nchars && ! strncmp (p1, p2, a1->nchars))
1796 || ! comp_def_part (first, p1, a1->nchars, p2, a2->nchars, 0))
1797 || a1->argno != a2->argno
1798 || a1->stringify != a2->stringify
1799 || a1->raw_before != a2->raw_before
1800 || a1->raw_after != a2->raw_after)
1808 if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion),
1809 p2, d2->length - (p2 - d2->expansion), 1))
1814 /* Return 1 if two parts of two macro definitions are effectively different.
1815 One of the parts starts at BEG1 and has LEN1 chars;
1816 the other has LEN2 chars at BEG2.
1817 Any sequence of whitespace matches any other sequence of whitespace.
1818 FIRST means these parts are the first of a macro definition;
1819 so ignore leading whitespace entirely.
1820 LAST means these parts are the last of a macro definition;
1821 so ignore trailing whitespace entirely. */
1824 comp_def_part (first, beg1, len1, beg2, len2, last)
1826 U_CHAR *beg1, *beg2;
1830 register U_CHAR *end1 = beg1 + len1;
1831 register U_CHAR *end2 = beg2 + len2;
1833 while (beg1 != end1 && is_space[*beg1]) beg1++;
1834 while (beg2 != end2 && is_space[*beg2]) beg2++;
1837 while (beg1 != end1 && is_space[end1[-1]]) end1--;
1838 while (beg2 != end2 && is_space[end2[-1]]) end2--;
1840 while (beg1 != end1 && beg2 != end2) {
1841 if (is_space[*beg1] && is_space[*beg2]) {
1842 while (beg1 != end1 && is_space[*beg1]) beg1++;
1843 while (beg2 != end2 && is_space[*beg2]) beg2++;
1844 } else if (*beg1 == *beg2) {
1848 return (beg1 != end1) || (beg2 != end2);
1851 /* Process a #define command.
1852 BUF points to the contents of the #define command, as a contiguous string.
1853 LIMIT points to the first character past the end of the definition.
1854 KEYWORD is the keyword-table entry for #define,
1855 or NULL for a "predefined" macro. */
1858 do_define (pfile, keyword, buf, limit)
1860 struct directive *keyword;
1861 U_CHAR *buf, *limit;
1868 /* If this is a precompiler run (with -pcp) pass thru #define commands. */
1869 if (pcp_outfile && keyword)
1870 pass_thru_directive (buf, limit, pfile, keyword);
1873 mdef = create_definition (buf, limit, pfile, keyword == NULL);
1877 hashcode = hashf (mdef.symnam, mdef.symlen, HASHSIZE);
1879 if ((hp = cpp_lookup (pfile, mdef.symnam, mdef.symlen, hashcode)) != NULL)
1882 /* Redefining a precompiled key is ok. */
1883 if (hp->type == T_PCSTRING)
1885 /* Redefining a macro is ok if the definitions are the same. */
1886 else if (hp->type == T_MACRO)
1887 ok = ! compare_defs (mdef.defn, hp->value.defn);
1888 /* Redefining a constant is ok with -D. */
1889 else if (hp->type == T_CONST)
1890 ok = ! CPP_OPTIONS (pfile)->done_initializing;
1891 /* Print the warning if it's not ok. */
1894 U_CHAR *msg; /* what pain... */
1896 /* If we are passing through #define and #undef directives, do
1897 that for this re-definition now. */
1898 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1899 pass_thru_directive (buf, limit, pfile, keyword);
1901 msg = (U_CHAR *) alloca (mdef.symlen + 22);
1903 bcopy (mdef.symnam, msg + 1, mdef.symlen);
1904 strcpy ((char *) (msg + mdef.symlen + 1), "' redefined");
1905 cpp_pedwarn (pfile, msg);
1906 if (hp->type == T_MACRO)
1907 cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file, hp->value.defn->line,
1908 "this is the location of the previous definition");
1910 /* Replace the old definition. */
1912 hp->value.defn = mdef.defn;
1916 /* If we are passing through #define and #undef directives, do
1917 that for this new definition now. */
1918 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1919 pass_thru_directive (buf, limit, pfile, keyword);
1920 install (mdef.symnam, mdef.symlen, T_MACRO, 0,
1921 (char *) mdef.defn, hashcode);
1931 /* This structure represents one parsed argument in a macro call.
1932 `raw' points to the argument text as written (`raw_length' is its length).
1933 `expanded' points to the argument's macro-expansion
1934 (its length is `expand_length').
1935 `stringified_length' is the length the argument would have
1937 `use_count' is the number of times this macro arg is substituted
1938 into the macro. If the actual use count exceeds 10,
1939 the value stored is 10. */
1941 /* raw and expanded are relative to ARG_BASE */
1942 #define ARG_BASE ((pfile)->token_buffer)
1945 /* Strings relative to pfile->token_buffer */
1946 long raw, expanded, stringified;
1947 int raw_length, expand_length;
1948 int stringified_length;
1956 cpp_push_buffer (pfile, buffer, length)
1961 #ifdef STATIC_BUFFERS
1962 register cpp_buffer *buf;
1963 if (buf == pfile->buffer_stack)
1964 fatal ("macro or `#include' recursion too deep");
1965 buf = CPP_BUFFER (pfile) - 1;
1966 bzero ((char *) buf, sizeof (cpp_buffer));
1967 CPP_BUFFER (pfile) = buf;
1969 register cpp_buffer *buf = (cpp_buffer*) xmalloc (sizeof(cpp_buffer));
1970 bzero ((char *) buf, sizeof (cpp_buffer));
1971 CPP_PREV_BUFFER (buf) = CPP_BUFFER (pfile);
1972 CPP_BUFFER (pfile) = buf;
1974 buf->if_stack = pfile->if_stack;
1975 buf->cleanup = null_cleanup;
1976 buf->underflow = null_underflow;
1977 buf->buf = buf->cur = buffer;
1978 buf->alimit = buf->rlimit = buffer + length;
1984 cpp_pop_buffer (pfile)
1987 cpp_buffer *buf = CPP_BUFFER (pfile);
1988 #ifdef STATIC_BUFFERS
1989 (*buf->cleanup) (buf, pfile);
1990 return ++CPP_BUFFER (pfile);
1992 cpp_buffer *next_buf = CPP_PREV_BUFFER (buf);
1993 (*buf->cleanup) (buf, pfile);
1994 CPP_BUFFER (pfile) = next_buf;
2000 /* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer.
2001 Pop the buffer when done. */
2004 cpp_scan_buffer (pfile)
2007 cpp_buffer *buffer = CPP_BUFFER (pfile);
2010 enum cpp_token token = cpp_get_token (pfile);
2011 if (token == CPP_EOF) /* Should not happen ... */
2013 if (token == CPP_POP && CPP_BUFFER (pfile) == buffer)
2015 cpp_pop_buffer (pfile);
2022 * Rescan a string into pfile's buffer.
2023 * Place the result in pfile->token_buffer.
2025 * The input is copied before it is scanned, so it is safe to pass
2026 * it something from the token_buffer that will get overwritten
2027 * (because it follows CPP_WRITTEN). This is used by do_include.
2029 * OUTPUT_MARKS nonzero means keep Newline markers found in the input
2030 * and insert such markers when appropriate. See `rescan' for details.
2031 * OUTPUT_MARKS is 1 for macroexpanding a macro argument separately
2032 * before substitution; it is 0 for other uses.
2036 cpp_expand_to_buffer (pfile, buf, length)
2041 register cpp_buffer *ip;
2043 U_CHAR *limit = buf + length;
2046 int odepth = indepth;
2052 /* Set up the input on the input stack. */
2054 buf1 = (U_CHAR *) alloca (length + 1);
2056 register U_CHAR *p1 = buf;
2057 register U_CHAR *p2 = buf1;
2064 ip = cpp_push_buffer (pfile, buf1, length);
2066 ip->lineno = obuf.lineno = 1;
2069 /* Scan the input, create the output. */
2070 cpp_scan_buffer (pfile);
2073 if (indepth != odepth)
2077 CPP_NUL_TERMINATE (pfile);
2082 adjust_position (buf, limit, linep, colp)
2092 (*linep)++, (*colp) = 1;
2098 /* Move line_base forward, updating lineno and colno. */
2101 update_position (pbuf)
2102 register cpp_buffer *pbuf;
2104 unsigned char *old_pos = pbuf->buf + pbuf->line_base;
2105 unsigned char *new_pos = pbuf->cur;
2106 register struct parse_marker *mark;
2107 for (mark = pbuf->marks; mark != NULL; mark = mark->next)
2109 if (pbuf->buf + mark->position < new_pos)
2110 new_pos = pbuf->buf + mark->position;
2112 pbuf->line_base += new_pos - old_pos;
2113 adjust_position (old_pos, new_pos, &pbuf->lineno, &pbuf->colno);
2117 cpp_buf_line_and_col (pbuf, linep, colp)
2118 register cpp_buffer *pbuf;
2126 *linep = pbuf->lineno;
2127 *colp = pbuf->colno;
2128 adjust_position (pbuf->buf + pbuf->line_base, pbuf->cur, linep, colp);
2137 /* Return the cpp_buffer that corresponds to a file (not a macro). */
2140 cpp_file_buffer (pfile)
2145 for (ip = CPP_BUFFER (pfile); ip != NULL; ip = CPP_PREV_BUFFER (ip))
2146 if (ip->fname != NULL)
2152 count_newlines (buf, limit)
2153 register U_CHAR *buf;
2154 register U_CHAR *limit;
2156 register long count = 0;
2167 * write out a #line command, for instance, after an #include file.
2168 * If CONDITIONAL is nonzero, we can omit the #line if it would
2169 * appear to be a no-op, and we can output a few newlines instead
2170 * if we want to increase the line number by a small amount.
2171 * FILE_CHANGE says whether we are entering a file, leaving, or neither.
2175 output_line_command (pfile, conditional, file_change)
2178 enum file_change_code file_change;
2181 char *line_cmd_buf, *line_end;
2183 cpp_buffer *ip = CPP_BUFFER (pfile);
2185 if (CPP_OPTIONS (pfile)->no_line_commands
2186 || ip->fname == NULL || CPP_OPTIONS (pfile)->no_output) {
2190 update_position (ip);
2191 line = CPP_BUFFER (pfile)->lineno;
2192 col = CPP_BUFFER (pfile)->colno;
2193 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
2196 if (line == pfile->lineno)
2199 /* If the inherited line number is a little too small,
2200 output some newlines instead of a #line command. */
2201 if (line > pfile->lineno && line < pfile->lineno + 8) {
2202 CPP_RESERVE (pfile, 20);
2203 while (line > pfile->lineno) {
2204 CPP_PUTC_Q (pfile, '\n');
2212 /* Don't output a line number of 0 if we can help it. */
2213 if (ip->lineno == 0 && ip->bufp - ip->buf < ip->length
2214 && *ip->bufp == '\n') {
2220 CPP_RESERVE (pfile, 4 * strlen (ip->nominal_fname) + 50);
2222 #ifdef OUTPUT_LINE_COMMANDS
2223 static char sharp_line[] = "#line ";
2225 static char sharp_line[] = "# ";
2227 CPP_PUTS_Q (pfile, sharp_line, sizeof(sharp_line)-1);
2230 sprintf (CPP_PWRITTEN (pfile), "%d ", line);
2231 CPP_ADJUST_WRITTEN (pfile, strlen (CPP_PWRITTEN (pfile)));
2233 quote_string (pfile, ip->nominal_fname);
2234 if (file_change != same_file) {
2235 CPP_PUTC_Q (pfile, ' ');
2236 CPP_PUTC_Q (pfile, file_change == enter_file ? '1' : '2');
2238 /* Tell cc1 if following text comes from a system header file. */
2239 if (ip->system_header_p) {
2240 CPP_PUTC_Q (pfile, ' ');
2241 CPP_PUTC_Q (pfile, '3');
2243 #ifndef NO_IMPLICIT_EXTERN_C
2244 /* Tell cc1plus if following text should be treated as C. */
2245 if (ip->system_header_p == 2 && CPP_OPTIONS (pfile)->cplusplus) {
2246 CPP_PUTC_Q (pfile, ' ');
2247 CPP_PUTC_Q (pfile, '4');
2250 CPP_PUTC_Q (pfile, '\n');
2251 pfile->lineno = line;
2255 * Parse a macro argument and store the info on it into *ARGPTR.
2256 * REST_ARGS means to absorb the rest of the args.
2257 * Return nonzero to indicate a syntax error.
2260 static enum cpp_token
2261 macarg (pfile, rest_args)
2266 enum cpp_token token;
2267 long arg_start = CPP_WRITTEN (pfile);
2268 char save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
2269 CPP_OPTIONS (pfile)->put_out_comments = 0;
2271 /* Try to parse as much of the argument as exists at this
2272 input stack level. */
2273 pfile->no_macro_expand++;
2276 token = cpp_get_token (pfile);
2282 /* If we've hit end of file, it's an error (reported by caller).
2283 Ditto if it's the end of cpp_expand_to_buffer text.
2284 If we've hit end of macro, just continue. */
2285 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
2296 /* if we've returned to lowest level and
2297 we aren't absorbing all args */
2298 if (paren == 0 && rest_args == 0)
2302 /* Remove ',' or ')' from argument buffer. */
2303 CPP_ADJUST_WRITTEN (pfile, -1);
2310 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
2311 pfile->no_macro_expand--;
2316 /* Turn newlines to spaces in the string of length LENGTH at START,
2317 except inside of string constants.
2318 The string is copied into itself with its beginning staying fixed. */
2321 change_newlines (start, length)
2325 register U_CHAR *ibp;
2326 register U_CHAR *obp;
2327 register U_CHAR *limit;
2331 limit = start + length;
2334 while (ibp < limit) {
2335 *obp++ = c = *ibp++;
2340 /* Notice and skip strings, so that we don't delete newlines in them. */
2343 while (ibp < limit) {
2344 *obp++ = c = *ibp++;
2347 if (c == '\n' && quotec == '\'')
2363 if (!pfile->timebuf) {
2364 time_t t = time ((time_t *)0);
2365 pfile->timebuf = localtime (&t);
2367 return pfile->timebuf;
2370 static char *monthnames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
2371 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
2375 * expand things like __FILE__. Place the expansion into the output
2376 * buffer *without* rescanning.
2380 special_symbol (hp, pfile)
2387 cpp_buffer *ip = NULL;
2390 int paren = 0; /* For special `defined' keyword */
2393 if (pcp_outfile && pcp_inside_if
2394 && hp->type != T_SPEC_DEFINED && hp->type != T_CONST)
2396 "Predefined macro `%s' used inside `#if' during precompilation",
2400 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
2404 cpp_error (pfile, "cccp error: not in any file?!");
2405 return; /* the show must go on */
2407 if (ip->fname != NULL)
2417 if (hp->type == T_BASE_FILE)
2419 while (CPP_PREV_BUFFER (ip))
2420 ip = CPP_PREV_BUFFER (ip);
2422 string = ip->nominal_fname;
2426 CPP_RESERVE (pfile, 3 + 4 * strlen (string));
2427 quote_string (pfile, string);
2431 case T_INCLUDE_LEVEL:
2433 for (ip = CPP_BUFFER (pfile); ip != NULL; ip = CPP_PREV_BUFFER (ip))
2434 if (ip->fname != NULL)
2437 buf = (char *) alloca (8); /* Eight bytes ought to be more than enough */
2438 sprintf (buf, "%d", true_indepth - 1);
2442 buf = (char *) alloca (3 + strlen (version_string));
2443 sprintf (buf, "\"%s\"", version_string);
2446 #ifndef NO_BUILTIN_SIZE_TYPE
2452 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2453 case T_PTRDIFF_TYPE:
2459 buf = CPP_WCHAR_TYPE (pfile);
2462 case T_USER_LABEL_PREFIX_TYPE:
2463 buf = USER_LABEL_PREFIX;
2466 case T_REGISTER_PREFIX_TYPE:
2467 buf = REGISTER_PREFIX;
2471 buf = (char *) alloca (4 * sizeof (int));
2472 sprintf (buf, "%d", hp->value.ival);
2474 if (pcp_inside_if && pcp_outfile)
2475 /* Output a precondition for this macro use */
2476 fprintf (pcp_outfile, "#define %s %d\n", hp->name, hp->value.ival);
2482 long line = CPP_BUFFER (pfile)->lineno;
2483 long col = CPP_BUFFER (pfile)->colno;
2484 cpp_buffer *ip = CPP_BUFFER (pfile);
2485 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
2487 buf = (char *) alloca (10);
2488 sprintf (buf, "%d", line);
2494 buf = (char *) alloca (20);
2495 timebuf = timestamp (pfile);
2496 if (hp->type == T_DATE)
2497 sprintf (buf, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon],
2498 timebuf->tm_mday, timebuf->tm_year + 1900);
2500 sprintf (buf, "\"%02d:%02d:%02d\"", timebuf->tm_hour, timebuf->tm_min,
2504 case T_SPEC_DEFINED:
2505 buf = " 0 "; /* Assume symbol is not defined */
2506 ip = CPP_BUFFER (pfile);
2507 SKIP_WHITE_SPACE (ip->cur);
2508 if (*ip->cur == '(')
2511 ip->cur++; /* Skip over the paren */
2512 SKIP_WHITE_SPACE (ip->cur);
2515 if (!is_idstart[*ip->cur])
2517 if (hp = cpp_lookup (pfile, ip->cur, -1, -1))
2520 if (pcp_outfile && pcp_inside_if
2521 && (hp->type == T_CONST
2522 || (hp->type == T_MACRO && hp->value.defn->predefined)))
2523 /* Output a precondition for this macro use. */
2524 fprintf (pcp_outfile, "#define %s\n", hp->name);
2530 if (pcp_outfile && pcp_inside_if)
2532 /* Output a precondition for this macro use */
2533 U_CHAR *cp = ip->bufp;
2534 fprintf (pcp_outfile, "#undef ");
2535 while (is_idchar[*cp]) /* Ick! */
2536 fputc (*cp++, pcp_outfile);
2537 putc ('\n', pcp_outfile);
2540 while (is_idchar[*ip->cur])
2542 SKIP_WHITE_SPACE (ip->cur);
2545 if (*ip->cur != ')')
2553 cpp_error (pfile, "`defined' without an identifier");
2557 cpp_error (pfile, "cccp error: invalid special hash type"); /* time for gdb */
2561 CPP_RESERVE (pfile, len + 1);
2562 CPP_PUTS_Q (pfile, buf, len);
2563 CPP_NUL_TERMINATE_Q (pfile);
2568 /* Initialize the built-in macros. */
2571 initialize_builtins (pfile)
2574 install ("__LINE__", -1, T_SPECLINE, 0, 0, -1);
2575 install ("__DATE__", -1, T_DATE, 0, 0, -1);
2576 install ("__FILE__", -1, T_FILE, 0, 0, -1);
2577 install ("__BASE_FILE__", -1, T_BASE_FILE, 0, 0, -1);
2578 install ("__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL, 0, 0, -1);
2579 install ("__VERSION__", -1, T_VERSION, 0, 0, -1);
2580 #ifndef NO_BUILTIN_SIZE_TYPE
2581 install ("__SIZE_TYPE__", -1, T_SIZE_TYPE, 0, 0, -1);
2583 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2584 install ("__PTRDIFF_TYPE__ ", -1, T_PTRDIFF_TYPE, 0, 0, -1);
2586 install ("__WCHAR_TYPE__", -1, T_WCHAR_TYPE, 0, 0, -1);
2587 install ("__USER_LABEL_PREFIX__", -1, T_USER_LABEL_PREFIX_TYPE, 0, 0, -1);
2588 install ("__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE, 0, 0, -1);
2589 install ("__TIME__", -1, T_TIME, 0, 0, -1);
2590 if (!CPP_TRADITIONAL (pfile))
2591 install ("__STDC__", -1, T_CONST, STDC_VALUE, 0, -1);
2592 if (CPP_OPTIONS (pfile)->objc)
2593 install ("__OBJC__", -1, T_CONST, 1, 0, -1);
2594 /* This is supplied using a -D by the compiler driver
2595 so that it is present only when truly compiling with GNU C. */
2596 /* install ("__GNUC__", -1, T_CONST, 2, 0, -1); */
2598 if (CPP_OPTIONS (pfile)->debug_output)
2600 char directive[2048];
2601 register struct directive *dp = &directive_table[0];
2602 struct tm *timebuf = timestamp ();
2603 cpp_buffer *pbuffer = CPP_BUFFER (pfile);
2605 while (CPP_PREV_BUFFER (pbuffer))
2606 pbuffer = CPP_PREV_BUFFER (pbuffer);
2607 sprintf (directive, " __BASE_FILE__ \"%s\"\n",
2608 pbuffer->nominal_fname);
2609 output_line_command (pfile, 0, same_file);
2610 pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp);
2612 sprintf (directive, " __VERSION__ \"%s\"\n", version_string);
2613 output_line_command (pfile, 0, same_file);
2614 pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp);
2616 #ifndef NO_BUILTIN_SIZE_TYPE
2617 sprintf (directive, " __SIZE_TYPE__ %s\n", SIZE_TYPE);
2618 output_line_command (pfile, 0, same_file);
2619 pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp);
2622 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2623 sprintf (directive, " __PTRDIFF_TYPE__ %s\n", PTRDIFF_TYPE);
2624 output_line_command (pfile, 0, same_file);
2625 pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp);
2628 sprintf (directive, " __WCHAR_TYPE__ %s\n", CPP_WCHAR_TYPE (pfile));
2629 output_line_command (pfile, 0, same_file);
2630 pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp);
2632 sprintf (directive, " __DATE__ \"%s %2d %4d\"\n",
2633 monthnames[timebuf->tm_mon],
2634 timebuf->tm_mday, timebuf->tm_year + 1900);
2635 output_line_command (pfile, 0, same_file);
2636 pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp);
2638 sprintf (directive, " __TIME__ \"%02d:%02d:%02d\"\n",
2639 timebuf->tm_hour, timebuf->tm_min, timebuf->tm_sec);
2640 output_line_command (pfile, 0, same_file);
2641 pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp);
2643 if (!CPP_TRADITIONAL (pfile))
2645 sprintf (directive, " __STDC__ 1");
2646 output_line_command (pfile, 0, same_file);
2647 pass_thru_directive (directive, &directive[strlen (directive)],
2650 if (CPP_OPTIONS (pfile)->objc)
2652 sprintf (directive, " __OBJC__ 1");
2653 output_line_command (pfile, 0, same_file);
2654 pass_thru_directive (directive, &directive[strlen (directive)],
2660 /* Return 1 iff a token ending in C1 followed directly by a token C2
2661 could cause mis-tokenization. */
2664 unsafe_chars (c1, c2)
2670 if (c2 == c1 || c2 == '=')
2674 case '0': case '1': case '2': case '3': case '4':
2675 case '5': case '6': case '7': case '8': case '9':
2677 if (c2 == '-' || c2 == '+')
2678 return 1; /* could extend a pre-processing number */
2681 if (c2 == '\'' || c2 == '\"')
2682 return 1; /* Could turn into L"xxx" or L'xxx'. */
2686 case 'a': case 'b': case 'c': case 'd': case 'f':
2687 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
2688 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
2689 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
2691 case 'A': case 'B': case 'C': case 'D': case 'F':
2692 case 'G': case 'H': case 'I': case 'J': case 'K':
2693 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
2694 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
2696 /* We're in the middle of either a name or a pre-processing number. */
2697 return (is_idchar[c2] || c2 == '.');
2698 case '<': case '>': case '!': case '%': case '#': case ':':
2699 case '^': case '&': case '|': case '*': case '/': case '=':
2700 return (c2 == c1 || c2 == '=');
2705 /* Expand a macro call.
2706 HP points to the symbol that is the macro being called.
2707 Put the result of expansion onto the input stack
2708 so that subsequent input by our caller will use it.
2710 If macro wants arguments, caller has already verified that
2711 an argument list follows; arguments come from the input stack. */
2714 macroexpand (pfile, hp)
2719 DEFINITION *defn = hp->value.defn;
2720 register U_CHAR *xbuf;
2722 struct argdata *args;
2723 long old_written = CPP_WRITTEN (pfile);
2725 int start_line = instack[indepth].lineno;
2727 int rest_args, rest_zero;
2731 CHECK_DEPTH (return;);
2735 /* This macro is being used inside a #if, which means it must be */
2736 /* recorded as a precondition. */
2737 if (pcp_inside_if && pcp_outfile && defn->predefined)
2738 dump_single_macro (hp, pcp_outfile);
2741 nargs = defn->nargs;
2745 char *parse_error = 0;
2746 enum cpp_token token;
2748 args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata));
2750 for (i = 0; i < nargs; i++)
2752 args[i].raw = args[i].expanded = 0;
2753 args[i].raw_length = 0;
2754 args[i].expand_length = args[i].stringified_length = -1;
2755 args[i].use_count = 0;
2758 /* Parse all the macro args that are supplied. I counts them.
2759 The first NARGS args are stored in ARGS.
2760 The rest are discarded. If rest_args is set then we assume
2761 macarg absorbed the rest of the args. */
2765 FORWARD(1); /* Discard the open-parenthesis before the first arg. */
2770 if (i < nargs || (nargs == 0 && i == 0))
2772 /* if we are working on last arg which absorbs rest of args... */
2773 if (i == nargs - 1 && defn->rest_args)
2775 args[i].raw = CPP_WRITTEN (pfile);
2776 token = macarg (pfile, rest_args);
2777 args[i].raw_length = CPP_WRITTEN (pfile) - args[i].raw;
2778 args[i].newlines = 0; /* FIXME */
2781 token = macarg (pfile, 0);
2782 if (token == CPP_EOF || token == CPP_POP)
2784 parse_error = "unterminated macro call";
2786 cpp_error_with_line (pfile, line_for_error (0), parse_error);
2788 cpp_error_with_line (pfile, line_for_error (start_line), parse_error);
2793 } while (token == CPP_COMMA);
2795 /* If we got one arg but it was just whitespace, call that 0 args. */
2798 register U_CHAR *bp = ARG_BASE + args[0].raw;
2799 register U_CHAR *lim = bp + args[0].raw_length;
2800 /* cpp.texi says for foo ( ) we provide one argument.
2801 However, if foo wants just 0 arguments, treat this as 0. */
2803 while (bp != lim && is_space[*bp]) bp++;
2808 /* Don't output an error message if we have already output one for
2809 a parse error above. */
2811 if (nargs == 0 && i > 0)
2814 cpp_error (pfile, "arguments given to macro `%s'", hp->name);
2818 /* traditional C allows foo() if foo wants one argument. */
2819 if (nargs == 1 && i == 0 && CPP_TRADITIONAL (pfile))
2821 /* the rest args token is allowed to absorb 0 tokens */
2822 else if (i == nargs - 1 && defn->rest_args)
2824 else if (parse_error)
2827 cpp_error (pfile, "macro `%s' used without args", hp->name);
2829 cpp_error (pfile, "macro `%s' used with just one arg", hp->name);
2831 cpp_error (pfile, "macro `%s' used with only %d args",
2838 "macro `%s' used with too many (%d) args", hp->name, i);
2842 /* If macro wants zero args, we parsed the arglist for checking only.
2843 Read directly from the macro definition. */
2846 xbuf = defn->expansion;
2847 xbuf_len = defn->length;
2851 register U_CHAR *exp = defn->expansion;
2852 register int offset; /* offset in expansion,
2853 copied a piece at a time */
2854 register int totlen; /* total amount of exp buffer filled so far */
2856 register struct reflist *ap, *last_ap;
2858 /* Macro really takes args. Compute the expansion of this call. */
2860 /* Compute length in characters of the macro's expansion.
2861 Also count number of times each arg is used. */
2862 xbuf_len = defn->length;
2863 for (ap = defn->pattern; ap != NULL; ap = ap->next)
2867 register struct argdata *arg = &args[ap->argno];
2868 /* Stringify it it hasn't already been */
2869 if (arg->stringified_length < 0)
2871 int arglen = arg->raw_length;
2875 /* Initially need_space is -1. Otherwise, 1 means the
2876 previous character was a space, but we suppressed it;
2877 0 means the previous character was a non-space. */
2878 int need_space = -1;
2880 arg->stringified = CPP_WRITTEN (pfile);
2881 if (!CPP_TRADITIONAL (pfile))
2882 CPP_PUTC (pfile, '\"'); /* insert beginning quote */
2883 for (; i < arglen; i++)
2885 c = (ARG_BASE + arg->raw)[i];
2889 /* Internal sequences of whitespace are replaced by
2890 one space except within an string or char token.*/
2893 if (need_space == 0)
2897 else if (need_space > 0)
2898 CPP_PUTC (pfile, ' ');
2913 else if (c == '\"' || c == '\'')
2917 /* Escape these chars */
2918 if (c == '\"' || (in_string && c == '\\'))
2919 CPP_PUTC (pfile, '\\');
2921 CPP_PUTC (pfile, c);
2924 CPP_RESERVE (pfile, 4);
2925 sprintf (CPP_PWRITTEN (pfile), "\\%03o",
2927 CPP_ADJUST_WRITTEN (pfile, 4);
2930 if (!CPP_TRADITIONAL (pfile))
2931 CPP_PUTC (pfile, '\"'); /* insert ending quote */
2932 arg->stringified_length
2933 = CPP_WRITTEN (pfile) - arg->stringified;
2935 xbuf_len += args[ap->argno].stringified_length;
2937 else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
2938 /* Add 4 for two newline-space markers to prevent
2939 token concatenation. */
2940 xbuf_len += args[ap->argno].raw_length + 4;
2943 /* We have an ordinary (expanded) occurrence of the arg.
2944 So compute its expansion, if we have not already. */
2945 if (args[ap->argno].expand_length < 0)
2947 args[ap->argno].expanded = CPP_WRITTEN (pfile);
2948 pfile->output_escapes++;
2949 cpp_expand_to_buffer (pfile,
2950 ARG_BASE + args[ap->argno].raw,
2951 args[ap->argno].raw_length);
2953 pfile->output_escapes--;
2954 args[ap->argno].expand_length
2955 = CPP_WRITTEN (pfile) - args[ap->argno].expanded;
2958 /* Add 4 for two newline-space markers to prevent
2959 token concatenation. */
2960 xbuf_len += args[ap->argno].expand_length + 4;
2962 if (args[ap->argno].use_count < 10)
2963 args[ap->argno].use_count++;
2966 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
2968 /* Generate in XBUF the complete expansion
2969 with arguments substituted in.
2970 TOTLEN is the total size generated so far.
2971 OFFSET is the index in the definition
2972 of where we are copying from. */
2973 offset = totlen = 0;
2974 for (last_ap = NULL, ap = defn->pattern; ap != NULL;
2975 last_ap = ap, ap = ap->next)
2977 register struct argdata *arg = &args[ap->argno];
2978 int count_before = totlen;
2980 /* Add chars to XBUF. */
2981 for (i = 0; i < ap->nchars; i++, offset++)
2982 xbuf[totlen++] = exp[offset];
2984 /* If followed by an empty rest arg with concatenation,
2985 delete the last run of nonwhite chars. */
2986 if (rest_zero && totlen > count_before
2987 && ((ap->rest_args && ap->raw_before)
2988 || (last_ap != NULL && last_ap->rest_args
2989 && last_ap->raw_after)))
2991 /* Delete final whitespace. */
2992 while (totlen > count_before && is_space[xbuf[totlen - 1]])
2995 /* Delete the nonwhites before them. */
2996 while (totlen > count_before && ! is_space[xbuf[totlen - 1]])
3000 if (ap->stringify != 0)
3002 bcopy (ARG_BASE + arg->stringified,
3003 xbuf + totlen, arg->stringified_length);
3004 totlen += arg->stringified_length;
3006 else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
3008 U_CHAR *p1 = ARG_BASE + arg->raw;
3009 U_CHAR *l1 = p1 + arg->raw_length;
3012 while (p1 != l1 && is_space[*p1]) p1++;
3013 while (p1 != l1 && is_idchar[*p1])
3014 xbuf[totlen++] = *p1++;
3018 /* Arg is concatenated after: delete trailing whitespace,
3019 whitespace markers, and no-reexpansion markers. */
3022 if (is_space[l1[-1]]) l1--;
3023 else if (l1[-1] == '-')
3025 U_CHAR *p2 = l1 - 1;
3026 /* If a `-' is preceded by an odd number of newlines then it
3027 and the last newline are a no-reexpansion marker. */
3028 while (p2 != p1 && p2[-1] == '\n') p2--;
3029 if ((l1 - 1 - p2) & 1) {
3038 bcopy (p1, xbuf + totlen, l1 - p1);
3043 U_CHAR *expanded = ARG_BASE + arg->expanded;
3044 if (!ap->raw_before && totlen > 0 && arg->expand_length
3045 && !CPP_TRADITIONAL(pfile)
3046 && unsafe_chars (xbuf[totlen-1], expanded[0]))
3047 xbuf[totlen++] = ' ';
3049 bcopy (expanded, xbuf + totlen, arg->expand_length);
3050 totlen += arg->expand_length;
3052 if (!ap->raw_after && totlen > 0 && offset < defn->length
3053 && !CPP_TRADITIONAL(pfile)
3054 && unsafe_chars (xbuf[totlen-1], exp[offset]))
3055 xbuf[totlen++] = ' ';
3057 /* If a macro argument with newlines is used multiple times,
3058 then only expand the newlines once. This avoids creating
3059 output lines which don't correspond to any input line,
3060 which confuses gdb and gcov. */
3061 if (arg->use_count > 1 && arg->newlines > 0)
3063 /* Don't bother doing change_newlines for subsequent
3067 = change_newlines (expanded, arg->expand_length);
3071 if (totlen > xbuf_len)
3075 /* if there is anything left of the definition
3076 after handling the arg list, copy that in too. */
3078 for (i = offset; i < defn->length; i++)
3080 /* if we've reached the end of the macro */
3083 if (! (rest_zero && last_ap != NULL && last_ap->rest_args
3084 && last_ap->raw_after))
3085 xbuf[totlen++] = exp[i];
3093 /* Now put the expansion on the input stack
3094 so our caller will commence reading from it. */
3095 push_macro_expansion (pfile, xbuf, xbuf_len, hp);
3096 CPP_BUFFER (pfile)->has_escapes = 1;
3098 /* Pop the space we've used in the token_buffer for argument expansion. */
3099 CPP_SET_WRITTEN (pfile, old_written);
3101 /* Recursive macro use sometimes works traditionally.
3102 #define foo(x,y) bar (x (y,0), y)
3105 if (!CPP_TRADITIONAL (pfile))
3106 hp->type = T_DISABLED;
3110 push_macro_expansion (pfile, xbuf, xbuf_len, hp)
3112 register U_CHAR *xbuf;
3116 register cpp_buffer *mbuf = cpp_push_buffer (pfile, xbuf, xbuf_len);
3117 mbuf->cleanup = macro_cleanup;
3120 /* The first char of the expansion should be a ' ' added by
3121 collect_expansion. This is to prevent accidental token-pasting
3122 between the text preceding the macro invocation, and the macro
3125 We would like to avoid adding unneeded spaces (for the sake of
3126 tools that use cpp, such as imake). In some common cases we can
3127 tell that it is safe to omit the space.
3129 The character before the macro invocation cannot have been an
3130 idchar (or else it would have been pasted with the idchars of
3131 the macro name). Therefore, if the first non-space character
3132 of the expansion is an idchar, we do not need the extra space
3133 to prevent token pasting.
3135 Also, we don't need the extra space if the first char is '(',
3136 or some other (less common) characters. */
3139 && (is_idchar[xbuf[1]] || xbuf[1] == '(' || xbuf[1] == '\''
3140 || xbuf[1] == '\"'))
3144 /* Like cpp_get_token, except that it does not read past end-of-line.
3145 Also, horizontal space is skipped, and macros are popped. */
3147 static enum cpp_token
3148 get_directive_token (pfile)
3153 long old_written = CPP_WRITTEN (pfile);
3154 enum cpp_token token;
3155 cpp_skip_hspace (pfile);
3156 if (PEEKC () == '\n')
3158 token = cpp_get_token (pfile);
3162 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
3164 /* ... else fall though ... */
3165 case CPP_HSPACE: case CPP_COMMENT:
3166 CPP_SET_WRITTEN (pfile, old_written);
3174 /* Handle #include and #import.
3175 This function expects to see "fname" or <fname> on the input.
3177 The input is normally in part of the output_buffer following
3178 CPP_WRITTEN, and will get overwriiten by output_line_command.
3179 I.e. in input file specification has been popped by handle_directive.
3183 do_include (pfile, keyword, unused1, unused2)
3185 struct directive *keyword;
3186 U_CHAR *unused1, *unused2;
3188 int importing = (keyword->type == T_IMPORT);
3189 int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
3190 char *fname; /* Dynamically allocated fname buffer */
3193 U_CHAR *fbeg, *fend; /* Beginning and end of fname */
3194 enum cpp_token token;
3196 /* Chain of dirs to search */
3197 struct file_name_list *search_start = CPP_OPTIONS (pfile)->include;
3198 struct file_name_list dsp[1]; /* First in chain, if #include "..." */
3199 struct file_name_list *searchptr = 0;
3200 long old_written = CPP_WRITTEN (pfile);
3204 int f; /* file number */
3206 int retried = 0; /* Have already tried macro
3207 expanding the include line*/
3208 int angle_brackets = 0; /* 0 for "...", 1 for <...> */
3213 f= -1; /* JF we iz paranoid! */
3215 if (importing && CPP_OPTIONS (pfile)->warn_import
3216 && !CPP_OPTIONS (pfile)->inhibit_warnings
3217 && !CPP_BUFFER (pfile)->system_header_p && !pfile->import_warning)
3219 pfile->import_warning = 1;
3220 cpp_warning (pfile, "using `#import' is not recommended");
3221 fprintf (stderr, "The fact that a certain header file need not be processed more than once\n");
3222 fprintf (stderr, "should be indicated in the header file, not where it is used.\n");
3223 fprintf (stderr, "The best way to do this is with a conditional of this form:\n\n");
3224 fprintf (stderr, " #ifndef _FOO_H_INCLUDED\n");
3225 fprintf (stderr, " #define _FOO_H_INCLUDED\n");
3226 fprintf (stderr, " ... <real contents of file> ...\n");
3227 fprintf (stderr, " #endif /* Not _FOO_H_INCLUDED */\n\n");
3228 fprintf (stderr, "Then users can use `#include' any number of times.\n");
3229 fprintf (stderr, "GNU C automatically avoids processing the file more than once\n");
3230 fprintf (stderr, "when it is equipped with such a conditional.\n");
3233 pfile->parsing_include_directive++;
3234 token = get_directive_token (pfile);
3235 pfile->parsing_include_directive--;
3237 if (token == CPP_STRING)
3239 /* FIXME - check no trailing garbage */
3240 fbeg = pfile->token_buffer + old_written + 1;
3241 fend = CPP_PWRITTEN (pfile) - 1;
3242 if (fbeg[-1] == '<')
3245 /* If -I-, start with the first -I dir after the -I-. */
3246 if (CPP_OPTIONS (pfile)->first_bracket_include)
3247 search_start = CPP_OPTIONS (pfile)->first_bracket_include;
3249 /* If -I- was specified, don't search current dir, only spec'd ones. */
3250 else if (! CPP_OPTIONS (pfile)->ignore_srcdir)
3253 /* We have "filename". Figure out directory this source
3254 file is coming from and put it on the front of the list. */
3256 for (fp = CPP_BUFFER (pfile); fp != NULL; fp = CPP_PREV_BUFFER (fp))
3261 if ((nam = fp->nominal_fname) != NULL)
3263 /* Found a named file. Figure out dir of the file,
3264 and put it in front of the search list. */
3265 dsp[0].next = search_start;
3268 ep = rindex (nam, '/');
3270 ep = rindex (nam, ']');
3271 if (ep == NULL) ep = rindex (nam, '>');
3272 if (ep == NULL) ep = rindex (nam, ':');
3273 if (ep != NULL) ep++;
3278 dsp[0].fname = (char *) alloca (n + 1);
3279 strncpy (dsp[0].fname, nam, n);
3280 dsp[0].fname[n] = '\0';
3281 if (n + INCLUDE_LEN_FUDGE > pfile->max_include_len)
3282 pfile->max_include_len = n + INCLUDE_LEN_FUDGE;
3286 dsp[0].fname = 0; /* Current directory */
3288 dsp[0].got_name_map = 0;
3295 else if (token == CPP_NAME)
3298 * Support '#include xyz' like VAX-C to allow for easy use of all the
3299 * decwindow include files. It defaults to '#include <xyz.h>' (so the
3300 * code from case '<' is repeated here) and generates a warning.
3303 "VAX-C-style include specification found, use '#include <filename.h>' !");
3305 /* If -I-, start with the first -I dir after the -I-. */
3306 if (CPP_OPTIONS (pfile)->first_bracket_include)
3307 search_start = CPP_OPTIONS (pfile)->first_bracket_include;
3308 fbeg = pfile->token_buffer + old_written;
3309 fend = CPP_PWRITTEN (pfile);
3315 "`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
3316 CPP_SET_WRITTEN (pfile, old_written);
3317 skip_rest_of_line (pfile);
3323 token = get_directive_token (pfile);
3324 if (token != CPP_VSPACE)
3326 cpp_error (pfile, "junk at end of `#include'");
3327 while (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP)
3328 token = get_directive_token (pfile);
3331 /* For #include_next, skip in the search path
3332 past the dir in which the containing file was found. */
3336 for (fp = CPP_BUFFER (pfile); fp != NULL; fp = CPP_PREV_BUFFER (fp))
3337 if (fp->fname != NULL)
3339 /* fp->dir is null if the containing file was specified with
3340 an absolute file name. In that case, don't skip anything. */
3342 search_start = fp->dir->next;
3347 CPP_SET_WRITTEN (pfile, old_written);
3353 cpp_error (pfile, "empty file name in `#%s'", keyword->name);
3357 /* Allocate this permanently, because it gets stored in the definitions
3359 fname = (char *) xmalloc (pfile->max_include_len + flen + 4);
3360 /* + 2 above for slash and terminating null. */
3361 /* + 2 added for '.h' on VMS (to support '#include filename') */
3363 /* If specified file name is absolute, just open it. */
3366 strncpy (fname, fbeg, flen);
3368 if (redundant_include_p (pfile, fname))
3371 f = lookup_import (pfile, fname, NULL_PTR);
3373 f = open_include_file (fname, NULL_PTR);
3375 return 0; /* Already included this file */
3377 /* Search directory path, trying to open the file.
3378 Copy each filename tried into FNAME. */
3380 for (searchptr = search_start; searchptr; searchptr = searchptr->next) {
3381 if (searchptr->fname) {
3382 /* The empty string in a search path is ignored.
3383 This makes it possible to turn off entirely
3384 a standard piece of the list. */
3385 if (searchptr->fname[0] == 0)
3387 strcpy (fname, searchptr->fname);
3388 strcat (fname, "/");
3389 fname[strlen (fname) + flen] = 0;
3393 strncat (fname, fbeg, flen);
3395 /* Change this 1/2 Unix 1/2 VMS file specification into a
3396 full VMS file specification */
3397 if (searchptr->fname && (searchptr->fname[0] != 0)) {
3398 /* Fix up the filename */
3399 hack_vms_include_specification (fname);
3401 /* This is a normal VMS filespec, so use it unchanged. */
3402 strncpy (fname, fbeg, flen);
3404 /* if it's '#include filename', add the missing .h */
3405 if (index(fname,'.')==NULL) {
3406 strcat (fname, ".h");
3410 /* ??? There are currently 3 separate mechanisms for avoiding processing
3411 of redundant include files: #import, #pragma once, and
3412 redundant_include_p. It would be nice if they were unified. */
3413 if (redundant_include_p (pfile, fname))
3416 f = lookup_import (pfile, fname, searchptr);
3418 f = open_include_file (fname, searchptr);
3420 return 0; /* Already included this file */
3422 else if (f == -1 && errno == EACCES)
3423 cpp_warning (pfile, "Header file %s exists, but is not readable",
3433 /* A file that was not found. */
3434 strncpy (fname, fbeg, flen);
3436 /* If generating dependencies and -MG was specified, we assume missing
3437 files are leaf files, living in the same directory as the source file
3438 or other similar place; these missing files may be generated from
3439 other files and may not exist yet (eg: y.tab.h). */
3441 if (CPP_OPTIONS(pfile)->print_deps_missing_files
3442 && CPP_PRINT_DEPS (pfile)
3443 > (angle_brackets || (pfile->system_include_depth > 0)))
3445 /* If it was requested as a system header file,
3446 then assume it belongs in the first place to look for such. */
3449 for (searchptr = search_start; searchptr;
3450 searchptr = searchptr->next)
3452 if (searchptr->fname)
3456 if (searchptr->fname[0] == 0)
3458 p = xmalloc (strlen (searchptr->fname)
3459 + strlen (fname) + 2);
3460 strcpy (p, searchptr->fname);
3463 deps_output (pfile, p, ' ');
3470 /* Otherwise, omit the directory, as if the file existed
3471 in the directory with the source. */
3472 deps_output (pfile, fname, ' ');
3475 /* If -M was specified, and this header file won't be added to the
3476 dependency list, then don't count this as an error, because we can
3477 still produce correct output. Otherwise, we can't produce correct
3478 output, because there may be dependencies we need inside the missing
3479 file, and we don't know what directory this missing file exists in.*/
3480 else if (CPP_PRINT_DEPS (pfile)
3481 && (CPP_PRINT_DEPS (pfile)
3482 <= (angle_brackets || (pfile->system_include_depth > 0))))
3483 cpp_warning (pfile, "No include path in which to find %s", fname);
3484 else if (search_start)
3485 cpp_error_from_errno (pfile, fname);
3487 cpp_error (pfile, "No include path in which to find %s", fname);
3490 /* Check to see if this include file is a once-only include file.
3493 struct file_name_list* ptr;
3495 for (ptr = pfile->dont_repeat_files; ptr; ptr = ptr->next) {
3496 if (!strcmp (ptr->fname, fname)) {
3498 return 0; /* This file was once'd. */
3502 for (ptr = pfile->all_include_files; ptr; ptr = ptr->next) {
3503 if (!strcmp (ptr->fname, fname))
3504 break; /* This file was included before. */
3508 /* This is the first time for this file. */
3509 /* Add it to list of files included. */
3511 ptr = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
3512 ptr->control_macro = 0;
3513 ptr->c_system_include_path = 0;
3514 ptr->next = pfile->all_include_files;
3515 pfile->all_include_files = ptr;
3516 ptr->fname = savestring (fname);
3517 ptr->got_name_map = 0;
3519 /* For -M, add this file to the dependencies. */
3520 if (CPP_PRINT_DEPS (pfile)
3521 > (angle_brackets || (pfile->system_include_depth > 0)))
3522 deps_output (pfile, fname, ' ');
3525 /* Handle -H option. */
3526 if (CPP_OPTIONS(pfile)->print_include_names)
3528 cpp_buffer *buf = CPP_BUFFER (pfile);
3529 while ((buf = CPP_PREV_BUFFER (buf)) != NULL)
3531 fprintf (stderr, "%s\n", fname);
3535 pfile->system_include_depth++;
3537 /* Actually process the file. */
3539 /* Record file on "seen" list for #import. */
3540 add_import (pfile, f, fname);
3542 pcftry = (char *) alloca (strlen (fname) + 30);
3554 sprintf (pcftry, "%s%d", fname, pcfnum++);
3556 pcf = open (pcftry, O_RDONLY, 0666);
3562 if (bcmp ((char *) &stat_f.st_ino, (char *) &s.st_ino,
3564 || stat_f.st_dev != s.st_dev)
3566 pcfbuf = check_precompiled (pcf, fname, &pcfbuflimit);
3567 /* Don't need it any more. */
3572 /* Don't need it at all. */
3577 } while (pcf != -1 && !pcfbuf);
3581 /* Actually process the file */
3582 if (finclude (pfile, f, fname, is_system_include (pfile, fname),
3585 output_line_command (pfile, 0, enter_file);
3586 pfile->only_seen_white = 2;
3590 pfile->system_include_depth--;
3595 /* Return nonzero if there is no need to include file NAME
3596 because it has already been included and it contains a conditional
3597 to make a repeated include do nothing. */
3600 redundant_include_p (pfile, name)
3604 struct file_name_list *l = pfile->all_include_files;
3605 for (; l; l = l->next)
3606 if (! strcmp (name, l->fname)
3608 && cpp_lookup (pfile, l->control_macro, -1, -1))
3613 /* Return nonzero if the given FILENAME is an absolute pathname which
3614 designates a file within one of the known "system" include file
3615 directories. We assume here that if the given FILENAME looks like
3616 it is the name of a file which resides either directly in a "system"
3617 include file directory, or within any subdirectory thereof, then the
3618 given file must be a "system" include file. This function tells us
3619 if we should suppress pedantic errors/warnings for the given FILENAME.
3621 The value is 2 if the file is a C-language system header file
3622 for which C++ should (on most systems) assume `extern "C"'. */
3625 is_system_include (pfile, filename)
3627 register char *filename;
3629 struct file_name_list *searchptr;
3631 for (searchptr = CPP_OPTIONS (pfile)->first_system_include; searchptr;
3632 searchptr = searchptr->next)
3633 if (searchptr->fname) {
3634 register char *sys_dir = searchptr->fname;
3635 register unsigned length = strlen (sys_dir);
3637 if (! strncmp (sys_dir, filename, length) && filename[length] == '/')
3639 if (searchptr->c_system_include_path)
3650 * Install a name in the assertion hash table.
3652 * If LEN is >= 0, it is the length of the name.
3653 * Otherwise, compute the length by scanning the entire name.
3655 * If HASH is >= 0, it is the precomputed hash code.
3656 * Otherwise, compute the hash code.
3658 static ASSERTION_HASHNODE *
3659 assertion_install (pfile, name, len, hash)
3665 register ASSERTION_HASHNODE *hp;
3666 register int i, bucket;
3667 register U_CHAR *p, *q;
3669 i = sizeof (ASSERTION_HASHNODE) + len + 1;
3670 hp = (ASSERTION_HASHNODE *) xmalloc (i);
3672 hp->bucket_hdr = &pfile->assertion_hashtab[bucket];
3673 hp->next = pfile->assertion_hashtab[bucket];
3674 pfile->assertion_hashtab[bucket] = hp;
3676 if (hp->next != NULL)
3677 hp->next->prev = hp;
3680 hp->name = ((U_CHAR *) hp) + sizeof (ASSERTION_HASHNODE);
3683 for (i = 0; i < len; i++)
3689 * find the most recent hash node for name name (ending with first
3690 * non-identifier char) installed by install
3692 * If LEN is >= 0, it is the length of the name.
3693 * Otherwise, compute the length by scanning the entire name.
3695 * If HASH is >= 0, it is the precomputed hash code.
3696 * Otherwise, compute the hash code.
3699 static ASSERTION_HASHNODE *
3700 assertion_lookup (pfile, name, len, hash)
3706 register ASSERTION_HASHNODE *bucket;
3708 bucket = pfile->assertion_hashtab[hash];
3710 if (bucket->length == len && strncmp (bucket->name, name, len) == 0)
3712 bucket = bucket->next;
3718 delete_assertion (hp)
3719 ASSERTION_HASHNODE *hp;
3722 if (hp->prev != NULL)
3723 hp->prev->next = hp->next;
3724 if (hp->next != NULL)
3725 hp->next->prev = hp->prev;
3727 /* make sure that the bucket chain header that
3728 the deleted guy was on points to the right thing afterwards. */
3729 if (hp == *hp->bucket_hdr)
3730 *hp->bucket_hdr = hp->next;
3735 /* Convert a character string literal into a nul-terminated string.
3736 The input string is [IN ... LIMIT).
3737 The result is placed in RESULT. RESULT can be the same as IN.
3738 The value returned in the end of the string written to RESULT,
3739 or NULL on error. */
3742 convert_string (pfile, result, in, limit, handle_escapes)
3744 register U_CHAR *result, *in, *limit;
3764 char *bpc = (char *) in;
3765 int i = (U_CHAR) cpp_parse_escape (pfile, &bpc);
3766 in = (U_CHAR *) bpc;
3768 *result++ = (U_CHAR)c;
3771 /* else fall through */
3781 * interpret #line command. Remembers previously seen fnames
3782 * in its very own hash table.
3784 #define FNAME_HASHSIZE 37
3787 do_line (pfile, keyword)
3789 struct directive *keyword;
3791 cpp_buffer *ip = CPP_BUFFER (pfile);
3793 long old_written = CPP_WRITTEN (pfile);
3794 enum file_change_code file_change = same_file;
3795 enum cpp_token token;
3798 token = get_directive_token (pfile);
3800 if (token != CPP_NUMBER
3801 || !isdigit(pfile->token_buffer[old_written]))
3803 cpp_error (pfile, "invalid format `#line' command");
3804 goto bad_line_directive;
3807 /* The Newline at the end of this line remains to be processed.
3808 To put the next line at the specified line number,
3809 we must store a line number now that is one less. */
3810 new_lineno = atoi (pfile->token_buffer + old_written) - 1;
3811 CPP_SET_WRITTEN (pfile, old_written);
3813 /* NEW_LINENO is one less than the actual line number here. */
3814 if (CPP_PEDANTIC (pfile) && new_lineno < 0)
3815 cpp_pedwarn (pfile, "line number out of range in `#line' command");
3817 #if 0 /* #line 10"foo.c" is supposed to be allowed. */
3818 if (PEEKC() && !is_space[PEEKC()]) {
3819 cpp_error (pfile, "invalid format `#line' command");
3820 goto bad_line_directive;
3824 token = get_directive_token (pfile);
3826 if (token == CPP_STRING) {
3827 U_CHAR *fname = pfile->token_buffer + old_written;
3829 static HASHNODE *fname_table[FNAME_HASHSIZE];
3830 HASHNODE *hp, **hash_bucket;
3835 /* Turn the file name, which is a character string literal,
3836 into a null-terminated string. Do this in place. */
3837 end_name = convert_string (pfile, fname, fname, CPP_PWRITTEN (pfile), 1);
3838 if (end_name == NULL)
3840 cpp_error (pfile, "invalid format `#line' command");
3841 goto bad_line_directive;
3844 fname_length = end_name - fname;
3846 num_start = CPP_WRITTEN (pfile);
3847 token = get_directive_token (pfile);
3848 if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP) {
3849 p = pfile->token_buffer + num_start;
3850 if (CPP_PEDANTIC (pfile))
3851 cpp_pedwarn (pfile, "garbage at end of `#line' command");
3853 if (token != CPP_NUMBER || *p < '0' || *p > '4' || p[1] != '\0')
3855 cpp_error (pfile, "invalid format `#line' command");
3856 goto bad_line_directive;
3859 file_change = enter_file;
3861 file_change = leave_file;
3863 ip->system_header_p = 1;
3864 else /* if (*p == 4) */
3865 ip->system_header_p = 2;
3867 CPP_SET_WRITTEN (pfile, num_start);
3868 token = get_directive_token (pfile);
3869 p = pfile->token_buffer + num_start;
3870 if (token == CPP_NUMBER && p[1] == '\0' && (*p == '3' || *p== '4')) {
3871 ip->system_header_p = *p == 3 ? 1 : 2;
3872 token = get_directive_token (pfile);
3874 if (token != CPP_VSPACE) {
3875 cpp_error (pfile, "invalid format `#line' command");
3876 goto bad_line_directive;
3881 &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)];
3882 for (hp = *hash_bucket; hp != NULL; hp = hp->next)
3883 if (hp->length == fname_length &&
3884 strncmp (hp->value.cpval, fname, fname_length) == 0) {
3885 ip->nominal_fname = hp->value.cpval;
3889 /* Didn't find it; cons up a new one. */
3890 hp = (HASHNODE *) xcalloc (1, sizeof (HASHNODE) + fname_length + 1);
3891 hp->next = *hash_bucket;
3894 hp->length = fname_length;
3895 ip->nominal_fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE);
3896 bcopy (fname, hp->value.cpval, fname_length);
3899 else if (token != CPP_VSPACE && token != CPP_EOF) {
3900 cpp_error (pfile, "invalid format `#line' command");
3901 goto bad_line_directive;
3904 ip->lineno = new_lineno;
3906 skip_rest_of_line (pfile);
3907 CPP_SET_WRITTEN (pfile, old_written);
3908 output_line_command (pfile, 0, file_change);
3913 * remove the definition of a symbol from the symbol table.
3914 * according to un*x /lib/cpp, it is not an error to undef
3915 * something that has no definitions, so it isn't one here either.
3919 do_undef (pfile, keyword, buf, limit)
3921 struct directive *keyword;
3922 U_CHAR *buf, *limit;
3926 U_CHAR *orig_buf = buf;
3929 /* If this is a precompiler run (with -pcp) pass thru #undef commands. */
3930 if (pcp_outfile && keyword)
3931 pass_thru_directive (buf, limit, pfile, keyword);
3934 SKIP_WHITE_SPACE (buf);
3935 sym_length = check_macro_name (pfile, buf, "macro");
3937 while ((hp = cpp_lookup (pfile, buf, sym_length, -1)) != NULL)
3939 /* If we are generating additional info for debugging (with -g) we
3940 need to pass through all effective #undef commands. */
3941 if (CPP_OPTIONS (pfile)->debug_output && keyword)
3942 pass_thru_directive (orig_buf, limit, pfile, keyword);
3943 if (hp->type != T_MACRO)
3944 cpp_warning (pfile, "undefining `%s'", hp->name);
3948 if (CPP_PEDANTIC (pfile)) {
3950 SKIP_WHITE_SPACE (buf);
3952 cpp_pedwarn (pfile, "garbage after `#undef' directive");
3958 * Report an error detected by the program we are processing.
3959 * Use the text of the line in the error message.
3960 * (We use error because it prints the filename & line#.)
3964 do_error (pfile, keyword, buf, limit)
3966 struct directive *keyword;
3967 U_CHAR *buf, *limit;
3969 int length = limit - buf;
3970 U_CHAR *copy = (U_CHAR *) xmalloc (length + 1);
3971 bcopy (buf, copy, length);
3973 SKIP_WHITE_SPACE (copy);
3974 cpp_error (pfile, "#error %s", copy);
3979 * Report a warning detected by the program we are processing.
3980 * Use the text of the line in the warning message, then continue.
3981 * (We use error because it prints the filename & line#.)
3985 do_warning (pfile, keyword, buf, limit)
3987 struct directive *keyword;
3988 U_CHAR *buf, *limit;
3990 int length = limit - buf;
3991 U_CHAR *copy = (U_CHAR *) xmalloc (length + 1);
3992 bcopy (buf, copy, length);
3994 SKIP_WHITE_SPACE (copy);
3995 cpp_warning (pfile, "#warning %s", copy);
3999 /* Remember the name of the current file being read from so that we can
4000 avoid ever including it again. */
4006 cpp_buffer *ip = NULL;
4007 struct file_name_list *new;
4009 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
4013 if (ip->fname != NULL)
4018 new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
4019 new->next = pfile->dont_repeat_files;
4020 pfile->dont_repeat_files = new;
4021 new->fname = savestring (ip->fname);
4022 new->control_macro = 0;
4023 new->got_name_map = 0;
4024 new->c_system_include_path = 0;
4029 /* #ident has already been copied to the output file, so just ignore it. */
4032 do_ident (pfile, keyword, buf, limit)
4034 struct directive *keyword;
4035 U_CHAR *buf, *limit;
4037 /* long old_written = CPP_WRITTEN (pfile);*/
4040 /* Allow #ident in system headers, since that's not user's fault. */
4041 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
4042 cpp_pedwarn (pfile, "ANSI C does not allow `#ident'");
4044 /* Leave rest of line to be read by later calls to cpp_get_token. */
4049 /* #pragma and its argument line have already been copied to the output file.
4050 Just check for some recognized pragmas that need validation here. */
4053 do_pragma (pfile, keyword, buf, limit)
4055 struct directive *keyword;
4056 U_CHAR *buf, *limit;
4058 while (*buf == ' ' || *buf == '\t')
4060 if (!strncmp (buf, "once", 4)) {
4061 /* Allow #pragma once in system headers, since that's not the user's
4063 if (!CPP_BUFFER (pfile)->system_header_p)
4064 cpp_warning (pfile, "`#pragma once' is obsolete");
4068 if (!strncmp (buf, "implementation", 14)) {
4069 /* Be quiet about `#pragma implementation' for a file only if it hasn't
4070 been included yet. */
4071 struct file_name_list *ptr;
4072 U_CHAR *p = buf + 14, *fname, *inc_fname;
4074 SKIP_WHITE_SPACE (p);
4075 if (*p == '\n' || *p != '\"')
4079 p = (U_CHAR *) index (fname, '\"');
4080 fname_len = p != NULL ? p - fname : strlen (fname);
4082 for (ptr = pfile->all_include_files; ptr; ptr = ptr->next) {
4083 inc_fname = (U_CHAR *) rindex (ptr->fname, '/');
4084 inc_fname = inc_fname ? inc_fname + 1 : (U_CHAR *) ptr->fname;
4085 if (inc_fname && !strncmp (inc_fname, fname, fname_len))
4087 "`#pragma implementation' for `%s' appears after file is included",
4096 /* This was a fun hack, but #pragma seems to start to be useful.
4097 By failing to recognize it, we pass it through unchanged to cc1. */
4100 * the behavior of the #pragma directive is implementation defined.
4101 * this implementation defines it as follows.
4108 if (open ("/dev/tty", O_RDONLY, 0666) != 0)
4111 if (open ("/dev/tty", O_WRONLY, 0666) != 1)
4113 execl ("/usr/games/hack", "#pragma", 0);
4114 execl ("/usr/games/rogue", "#pragma", 0);
4115 execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0);
4116 execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0);
4118 fatal ("You are in a maze of twisty compiler features, all different");
4122 /* Just ignore #sccs, on systems where we define it at all. */
4125 do_sccs (pfile, keyword, buf, limit)
4127 struct directive *keyword;
4128 U_CHAR *buf, *limit;
4130 if (CPP_PEDANTIC (pfile))
4131 cpp_pedwarn (pfile, "ANSI C does not allow `#sccs'");
4136 * handle #if command by
4137 * 1) inserting special `defined' keyword into the hash table
4138 * that gets turned into 0 or 1 by special_symbol (thus,
4139 * if the luser has a symbol called `defined' already, it won't
4140 * work inside the #if command)
4141 * 2) rescan the input into a temporary output buffer
4142 * 3) pass the output buffer to the yacc parser and collect a value
4143 * 4) clean up the mess left from steps 1 and 2.
4144 * 5) call conditional_skip to skip til the next #endif (etc.),
4145 * or not, depending on the value from step 3.
4149 do_if (pfile, keyword, buf, limit)
4151 struct directive *keyword;
4152 U_CHAR *buf, *limit;
4154 HOST_WIDE_INT value = eval_if_expression (pfile, buf, limit - buf);
4155 conditional_skip (pfile, value == 0, T_IF, NULL_PTR);
4160 * handle a #elif directive by not changing if_stack either.
4161 * see the comment above do_else.
4165 do_elif (pfile, keyword, buf, limit)
4167 struct directive *keyword;
4168 U_CHAR *buf, *limit;
4170 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
4171 cpp_error (pfile, "`#elif' not within a conditional");
4174 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
4175 cpp_error (pfile, "`#elif' after `#else'");
4177 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
4179 if (pfile->if_stack->fname != NULL && CPP_BUFFER (pfile)->fname != NULL
4180 && strcmp (pfile->if_stack->fname,
4181 CPP_BUFFER (pfile)->nominal_fname) != 0)
4182 fprintf (stderr, ", file %s", pfile->if_stack->fname);
4183 fprintf (stderr, ")\n");
4185 pfile->if_stack->type = T_ELIF;
4188 if (pfile->if_stack->if_succeeded)
4189 skip_if_group (pfile, 0);
4191 HOST_WIDE_INT value = eval_if_expression (pfile, buf, limit - buf);
4193 skip_if_group (pfile, 0);
4195 ++pfile->if_stack->if_succeeded; /* continue processing input */
4196 output_line_command (pfile, 1, same_file);
4203 * evaluate a #if expression in BUF, of length LENGTH,
4204 * then parse the result as a C expression and return the value as an int.
4206 static HOST_WIDE_INT
4207 eval_if_expression (pfile, buf, length)
4212 HASHNODE *save_defined;
4213 HOST_WIDE_INT value;
4214 long old_written = CPP_WRITTEN (pfile);
4216 save_defined = install ("defined", -1, T_SPEC_DEFINED, 0, 0, -1);
4217 pfile->pcp_inside_if = 1;
4219 value = cpp_parse_expr (pfile);
4220 pfile->pcp_inside_if = 0;
4221 delete_macro (save_defined); /* clean up special symbol */
4223 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
4229 * routine to handle ifdef/ifndef. Try to look up the symbol,
4230 * then do or don't skip to the #endif/#else/#elif depending
4231 * on what directive is actually being processed.
4235 do_xifdef (pfile, keyword, unused1, unused2)
4237 struct directive *keyword;
4238 U_CHAR *unused1, *unused2;
4241 cpp_buffer *ip = CPP_BUFFER (pfile);
4244 enum cpp_token token;
4245 int start_of_file = 0;
4246 U_CHAR *control_macro = 0;
4247 int old_written = CPP_WRITTEN (pfile);
4249 /* Detect a #ifndef at start of file (not counting comments). */
4250 if (ip->fname != 0 && keyword->type == T_IFNDEF)
4251 start_of_file = pfile->only_seen_white == 2;
4253 pfile->no_macro_expand++;
4254 token = get_directive_token (pfile);
4255 pfile->no_macro_expand--;
4257 ident = pfile->token_buffer + old_written;
4258 ident_length = CPP_WRITTEN (pfile) - old_written;
4259 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
4261 if (token == CPP_VSPACE || token == CPP_POP || token == CPP_EOF)
4263 skip = (keyword->type == T_IFDEF);
4264 if (! CPP_TRADITIONAL (pfile))
4265 cpp_pedwarn (pfile, "`#%s' with no argument", keyword->name);
4267 else if (token == CPP_NAME)
4269 HASHNODE *hp = cpp_lookup (pfile, ident, ident_length, -1);
4270 skip = (hp == NULL) ^ (keyword->type == T_IFNDEF);
4271 if (start_of_file && !skip)
4273 control_macro = (U_CHAR *) xmalloc (ident_length + 1);
4274 bcopy (ident, control_macro, ident_length + 1);
4279 skip = (keyword->type == T_IFDEF);
4280 if (! CPP_TRADITIONAL (pfile))
4281 cpp_error (pfile, "`#%s' with invalid argument", keyword->name);
4284 if (!CPP_TRADITIONAL (pfile))
4286 cpp_skip_hspace (pfile);
4288 if (c != EOF && c != '\n')
4289 cpp_pedwarn (pfile, "garbage at end of `#%s' argument", keyword->name);
4291 skip_rest_of_line (pfile);
4295 /* Output a precondition for this macro. */
4296 if (hp && hp->value.defn->predefined)
4297 fprintf (pcp_outfile, "#define %s\n", hp->name);
4300 fprintf (pcp_outfile, "#undef ");
4301 while (is_idchar[*cp]) /* Ick! */
4302 fputc (*cp++, pcp_outfile);
4303 putc ('\n', pcp_outfile);
4307 conditional_skip (pfile, skip, T_IF, control_macro);
4311 /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
4312 If this is a #ifndef starting at the beginning of a file,
4313 CONTROL_MACRO is the macro name tested by the #ifndef.
4314 Otherwise, CONTROL_MACRO is 0. */
4317 conditional_skip (pfile, skip, type, control_macro)
4320 enum node_type type;
4321 U_CHAR *control_macro;
4323 IF_STACK_FRAME *temp;
4325 temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
4326 temp->fname = CPP_BUFFER (pfile)->nominal_fname;
4328 temp->lineno = CPP_BUFFER (pfile)->lineno;
4330 temp->next = pfile->if_stack;
4331 temp->control_macro = control_macro;
4332 pfile->if_stack = temp;
4334 pfile->if_stack->type = type;
4337 skip_if_group (pfile, 0);
4340 ++pfile->if_stack->if_succeeded;
4341 output_line_command (pfile, 1, same_file);
4346 * skip to #endif, #else, or #elif. adjust line numbers, etc.
4347 * leaves input ptr at the sharp sign found.
4348 * If ANY is nonzero, return at next directive of any sort.
4351 skip_if_group (pfile, any)
4356 int at_beg_of_line = 1;
4357 struct directive *kt;
4358 IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */
4360 U_CHAR *beg_of_line = bp;
4362 register int ident_length;
4363 U_CHAR *ident, *after_ident;
4364 struct parse_marker line_start_mark;
4366 parse_set_mark (&line_start_mark, pfile);
4368 if (CPP_OPTIONS (pfile)->output_conditionals) {
4369 static char failed[] = "#failed\n";
4370 CPP_PUTS (pfile, failed, sizeof(failed)-1);
4372 output_line_command (pfile, 1, same_file);
4376 if (CPP_OPTIONS (pfile)->output_conditionals)
4378 cpp_buffer *pbuf = CPP_BUFFER (pfile);
4379 U_CHAR *start_line = pbuf->buf + line_start_mark.position;
4380 CPP_PUTS (pfile, start_line, pbuf->cur - start_line);
4382 parse_move_mark (&line_start_mark, pfile);
4383 if (!CPP_TRADITIONAL (pfile))
4384 cpp_skip_hspace (pfile);
4388 int old_written = CPP_WRITTEN (pfile);
4389 cpp_skip_hspace (pfile);
4391 parse_name (pfile, GETC());
4392 ident_length = CPP_WRITTEN (pfile) - old_written;
4393 ident = pfile->token_buffer + old_written;
4394 pfile->limit = ident;
4396 if (ident_length == 0)
4397 goto not_a_directive;
4399 /* Handle # followed by a line number. */
4401 /* Avoid error for `###' and similar cases unless -pedantic. */
4404 for (kt = directive_table; kt->length >= 0; kt++)
4406 IF_STACK_FRAME *temp;
4407 if (ident_length == kt->length
4408 && strncmp (ident, kt->name, kt->length) == 0)
4410 /* If we are asked to return on next directive, do so now. */
4420 = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
4421 temp->next = pfile->if_stack;
4422 pfile->if_stack = temp;
4424 temp->lineno = CPP_BUFFER(pfile)->lineno;
4426 temp->fname = CPP_BUFFER(pfile)->nominal_fname;
4427 temp->type = kt->type;
4431 if (CPP_PEDANTIC (pfile) && pfile->if_stack != save_if_stack)
4432 validate_else (pfile,
4433 kt->type == T_ELSE ? "#else" : "#endif");
4435 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
4438 "`#%s' not within a conditional", kt->name);
4441 else if (pfile->if_stack == save_if_stack)
4442 goto done; /* found what we came for */
4444 if (kt->type != T_ENDIF)
4446 if (pfile->if_stack->type == T_ELSE)
4447 cpp_error (pfile, "`#else' or `#elif' after `#else'");
4448 pfile->if_stack->type = kt->type;
4452 temp = pfile->if_stack;
4453 pfile->if_stack = temp->next;
4460 /* Don't let erroneous code go by. */
4461 if (kt->length < 0 && !CPP_OPTIONS (pfile)->lang_asm
4462 && CPP_PEDANTIC (pfile))
4463 cpp_pedwarn (pfile, "invalid preprocessor directive name");
4467 /* We're in the middle of a line. Skip the rest of it. */
4473 case '/': /* possible comment */
4474 c = skip_comment (pfile, NULL);
4480 skip_quoted_string (pfile, c, 0 /* FIXME */);
4483 /* Char after backslash loses its special meaning. */
4484 if (PEEKC() == '\n')
4494 if (CPP_OPTIONS (pfile)->output_conditionals) {
4495 static char end_failed[] = "#endfailed\n";
4496 CPP_PUTS (pfile, end_failed, sizeof(end_failed)-1);
4499 pfile->only_seen_white = 1;
4500 parse_goto_mark (&line_start_mark, pfile);
4501 parse_clear_mark (&line_start_mark);
4505 * handle a #else directive. Do this by just continuing processing
4506 * without changing if_stack ; this is so that the error message
4507 * for missing #endif's etc. will point to the original #if. It
4508 * is possible that something different would be better.
4512 do_else (pfile, keyword, buf, limit)
4514 struct directive *keyword;
4515 U_CHAR *buf, *limit;
4517 cpp_buffer *ip = CPP_BUFFER (pfile);
4519 if (CPP_PEDANTIC (pfile))
4520 validate_else (pfile, "#else");
4521 skip_rest_of_line (pfile);
4523 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
4524 cpp_error (pfile, "`#else' not within a conditional");
4527 /* #ifndef can't have its special treatment for containing the whole file
4528 if it has a #else clause. */
4529 pfile->if_stack->control_macro = 0;
4531 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
4532 cpp_error (pfile, "`#else' after `#else'");
4533 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
4534 if (strcmp (pfile->if_stack->fname, ip->nominal_fname) != 0)
4535 fprintf (stderr, ", file %s", pfile->if_stack->fname);
4536 fprintf (stderr, ")\n");
4538 pfile->if_stack->type = T_ELSE;
4541 if (pfile->if_stack->if_succeeded)
4542 skip_if_group (pfile, 0);
4544 ++pfile->if_stack->if_succeeded; /* continue processing input */
4545 output_line_command (pfile, 1, same_file);
4551 * unstack after #endif command
4555 do_endif (pfile, keyword, buf, limit)
4557 struct directive *keyword;
4558 U_CHAR *buf, *limit;
4560 if (CPP_PEDANTIC (pfile))
4561 validate_else (pfile, "#endif");
4562 skip_rest_of_line (pfile);
4564 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
4565 cpp_error (pfile, "unbalanced `#endif'");
4568 IF_STACK_FRAME *temp = pfile->if_stack;
4569 pfile->if_stack = temp->next;
4570 if (temp->control_macro != 0)
4572 /* This #endif matched a #ifndef at the start of the file.
4573 See if it is at the end of the file. */
4574 struct parse_marker start_mark;
4577 parse_set_mark (&start_mark, pfile);
4581 cpp_skip_hspace (pfile);
4586 parse_goto_mark (&start_mark, pfile);
4587 parse_clear_mark (&start_mark);
4591 /* If we get here, this #endif ends a #ifndef
4592 that contains all of the file (aside from whitespace).
4593 Arrange not to include the file again
4594 if the macro that was tested is defined.
4596 Do not do this for the top-level file in a -include or any
4597 file in a -imacros. */
4601 && ! (indepth == 1 && pfile->no_record_file)
4602 && ! (pfile->no_record_file && no_output))
4605 struct file_name_list *ifile = pfile->all_include_files;
4607 for ( ; ifile != NULL; ifile = ifile->next)
4609 if (!strcmp (ifile->fname, CPP_BUFFER (pfile)->fname))
4611 ifile->control_macro = temp->control_macro;
4619 output_line_command (pfile, 1, same_file);
4624 /* When an #else or #endif is found while skipping failed conditional,
4625 if -pedantic was specified, this is called to warn about text after
4626 the command name. P points to the first char after the command name. */
4629 validate_else (pfile, directive)
4634 cpp_skip_hspace (pfile);
4636 if (c != EOF && c != '\n')
4638 "text following `%s' violates ANSI standard", directive);
4641 /* Get the next token, and add it to the tex in pfile->token_buffer.
4642 Return the kind of token we got. */
4646 cpp_get_token (pfile)
4649 register int c, c2, c3;
4651 enum cpp_token token;
4652 struct cpp_options *opts = CPP_OPTIONS (pfile);
4653 CPP_BUFFER (pfile)->prev = CPP_BUFFER (pfile)->cur;
4659 if (CPP_BUFFER (pfile)->seen_eof)
4661 if (cpp_pop_buffer (pfile) != CPP_NULL_BUFFER (pfile))
4668 cpp_buffer *next_buf
4669 = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
4670 CPP_BUFFER (pfile)->seen_eof = 1;
4671 if (CPP_BUFFER (pfile)->nominal_fname && next_buf != 0)
4673 /* We're about to return from an #include file.
4674 Emit #line information now (as part of the CPP_POP) restult.
4675 But the #line refers to the file we will pop to. */
4676 cpp_buffer *cur_buffer = CPP_BUFFER (pfile);
4677 CPP_BUFFER (pfile) = next_buf;
4678 pfile->input_stack_listing_current = 0;
4679 output_line_command (pfile, 0, leave_file);
4680 CPP_BUFFER (pfile) = cur_buffer;
4690 struct parse_marker start_mark;
4692 if (PEEKC () == '=')
4694 if (opts->put_out_comments)
4695 parse_set_mark (&start_mark, pfile);
4697 c = skip_comment (pfile, &newlines);
4698 if (opts->put_out_comments && (c == '/' || c == EOF))
4699 parse_clear_mark (&start_mark);
4704 cpp_error_with_line (pfile, line_for_error (pfile->start_line),
4705 "unterminated comment");
4708 c = '/'; /* Initial letter of comment. */
4710 /* Comments are equivalent to spaces.
4711 For -traditional, a comment is equivalent to nothing. */
4712 if (opts->put_out_comments)
4714 cpp_buffer *pbuf = CPP_BUFFER (pfile);
4716 U_CHAR *start = pbuf->buf + start_mark.position;
4717 int len = pbuf->cur - start;
4718 CPP_RESERVE(pfile, 1 + len);
4719 CPP_PUTC_Q (pfile, c);
4720 CPP_PUTS_Q (pfile, start, len);
4721 pfile->lineno += newlines;
4722 parse_clear_mark (&start_mark);
4725 else if (CPP_TRADITIONAL (pfile))
4732 /* This may not work if cpp_get_token is called recursively,
4733 since many places look for horizontal space. */
4736 /* Copy the newlines into the output buffer, in order to
4737 avoid the pain of a #line every time a multiline comment
4739 CPP_RESERVE(pfile, newlines);
4740 while (--newlines >= 0)
4742 CPP_PUTC_Q (pfile, '\n');
4748 CPP_RESERVE(pfile, 1);
4749 CPP_PUTC_Q (pfile, ' ');
4752 if (opts->for_lint) {
4756 char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen);
4758 if (lintcmd != NULL) {
4759 /* I believe it is always safe to emit this newline: */
4761 bcopy ("#pragma lint ", (char *) obp, 13);
4763 bcopy (lintcmd, (char *) obp, cmdlen);
4768 bcopy (argbp, (char *) obp, arglen);
4772 /* OK, now bring us back to the state we were in before we entered
4773 this branch. We need #line b/c the newline for the pragma
4774 could fuck things up. */
4775 output_line_command (pfile, 0, same_file);
4776 *(obp++) = ' '; /* just in case, if comments are copied thru */
4784 /* If this is expanding a macro definition, don't recognize
4785 preprocessor directives. */
4788 /* If this is expand_into_temp_buffer, recognize them
4789 only after an actual newline at this level,
4790 not at the beginning of the input level. */
4791 if (ip->fname == 0 && beg_of_line == ip->buf)
4797 if (!pfile->only_seen_white)
4799 if (handle_directive (pfile))
4800 return CPP_DIRECTIVE;
4801 pfile->only_seen_white = 0;
4806 /* A single quoted string is treated like a double -- some
4807 programs (e.g., troff) are perverse this way */
4809 start_line = pfile->lineno;
4811 old_written = CPP_WRITTEN (pfile);
4813 CPP_PUTC (pfile, c);
4819 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
4821 /* try harder: this string crosses a macro expansion
4822 boundary. This can happen naturally if -traditional.
4823 Otherwise, only -D can make a macro with an unmatched
4825 cpp_buffer *next_buf
4826 = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
4827 (*CPP_BUFFER (pfile)->cleanup)
4828 (CPP_BUFFER (pfile), pfile);
4829 CPP_BUFFER (pfile) = next_buf;
4833 if (!CPP_TRADITIONAL (pfile))
4835 cpp_error_with_line (pfile, line_for_error (start_line),
4836 "unterminated string or character constant");
4837 cpp_error_with_line (pfile, multiline_string_line,
4838 "possible real start of unterminated constant");
4839 multiline_string_line = 0;
4844 CPP_PUTC (pfile, cc);
4848 /* Traditionally, end of line ends a string constant with
4849 no error. So exit the loop and record the new line. */
4850 if (CPP_TRADITIONAL (pfile))
4855 cpp_error_with_line (pfile, line_for_error (start_line),
4856 "unterminated character constant");
4859 if (CPP_PEDANTIC (pfile) && multiline_string_line == 0)
4861 cpp_pedwarn_with_line (pfile,
4862 line_for_error (start_line),
4863 "string constant runs past end of line");
4865 if (multiline_string_line == 0)
4866 multiline_string_line = ip->lineno - 1;
4874 /* Backslash newline is replaced by nothing at all. */
4875 CPP_ADJUST_WRITTEN (pfile, -1);
4880 /* ANSI stupidly requires that in \\ the second \
4881 is *not* prevented from combining with a newline. */
4884 CPP_PUTC (pfile, cc);
4896 pfile->lineno += count_newlines (pfile->token_buffer + old_written,
4897 CPP_PWRITTEN (pfile));
4898 pfile->only_seen_white = 0;
4899 return c == '\'' ? CPP_CHAR : CPP_STRING;
4902 if (!opts->dollars_in_ident)
4907 if (opts->cplusplus && PEEKC () == ':')
4916 if (c2 == c || c2 == '=')
4926 if (PEEKC () == '=')
4933 if (c2 == '-' && opts->chill)
4935 /* Chill style comment */
4936 if (opts->put_out_comments)
4937 parse_set_mark (&start_mark, pfile);
4938 FORWARD(1); /* Skip second '-'. */
4946 /* Don't consider final '\n' to be part of comment. */
4952 goto return_comment;
4954 if (c2 == '-' || c2 == '=' || c2 == '>')
4959 if (pfile->parsing_include_directive)
4963 CPP_PUTC (pfile, c);
4968 if (c == '\n' || c == EOF)
4971 "missing '>' in `#include <FILENAME>'");
4977 /* else fall through */
4986 CPP_RESERVE (pfile, 4);
4987 CPP_PUTC (pfile, c);
4988 CPP_PUTC (pfile, c2);
4992 CPP_PUTC_Q (pfile, GETC ());
4993 CPP_NUL_TERMINATE_Q (pfile);
4994 pfile->only_seen_white = 0;
4998 if (CPP_BUFFER (pfile)->has_escapes)
5003 if (pfile->output_escapes)
5004 CPP_PUTS (pfile, "@-", 2);
5005 parse_name (pfile, GETC ());
5009 if (pfile->output_escapes)
5011 CPP_PUTS (pfile, "@@", 2);
5021 CPP_RESERVE(pfile, 2);
5022 CPP_PUTC_Q (pfile, '.');
5026 /* FIXME - misses the case "..\\\n." */
5027 if (c2 == '.' && PEEKN(1) == '.')
5029 CPP_RESERVE(pfile, 4);
5030 CPP_PUTC_Q (pfile, '.');
5031 CPP_PUTC_Q (pfile, '.');
5032 CPP_PUTC_Q (pfile, '.');
5034 CPP_NUL_TERMINATE_Q (pfile);
5035 pfile->only_seen_white = 0;
5042 pfile->only_seen_white = 0;
5044 CPP_RESERVE(pfile, 3);
5045 CPP_PUTC_Q (pfile, c);
5046 CPP_PUTC_Q (pfile, GETC ());
5047 CPP_NUL_TERMINATE_Q (pfile);
5053 if ((c2 == '\'' || c2 == '\"') && !CPP_TRADITIONAL (pfile))
5055 CPP_PUTC (pfile, c);
5061 case '0': case '1': case '2': case '3': case '4':
5062 case '5': case '6': case '7': case '8': case '9':
5067 CPP_RESERVE (pfile, 2);
5068 CPP_PUTC_Q (pfile, c);
5073 if (!is_idchar[c] && c != '.'
5074 && ((c2 != 'e' && c2 != 'E') || (c != '+' && c != '-')))
5079 CPP_NUL_TERMINATE_Q (pfile);
5080 pfile->only_seen_white = 0;
5082 case 'b': case 'c': case 'd': case 'h': case 'o':
5083 case 'B': case 'C': case 'D': case 'H': case 'O':
5084 if (opts->chill && PEEKC () == '\'')
5086 pfile->only_seen_white = 0;
5087 CPP_RESERVE (pfile, 2);
5088 CPP_PUTC_Q (pfile, c);
5089 CPP_PUTC_Q (pfile, '\'');
5095 goto chill_number_eof;
5098 if (c == '\\' && PEEKC() == '\n')
5105 CPP_PUTC (pfile, c);
5109 CPP_RESERVE (pfile, 2);
5110 CPP_PUTC_Q (pfile, c);
5111 CPP_NUL_TERMINATE_Q (pfile);
5118 CPP_NUL_TERMINATE (pfile);
5125 case 'a': case 'e': case 'f': case 'g': case 'i': case 'j':
5126 case 'k': case 'l': case 'm': case 'n': case 'p': case 'q':
5127 case 'r': case 's': case 't': case 'u': case 'v': case 'w':
5128 case 'x': case 'y': case 'z':
5129 case 'A': case 'E': case 'F': case 'G': case 'I': case 'J':
5130 case 'K': case 'M': case 'N': case 'P': case 'Q': case 'R':
5131 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
5136 unsigned char *ident;
5137 int before_name_written = CPP_WRITTEN (pfile);
5139 parse_name (pfile, c);
5140 pfile->only_seen_white = 0;
5141 if (pfile->no_macro_expand)
5143 ident = pfile->token_buffer + before_name_written;
5144 ident_len = CPP_PWRITTEN (pfile) - ident;
5145 hp = cpp_lookup (pfile, ident, ident_len, -1);
5148 if (hp->type == T_DISABLED)
5150 if (pfile->output_escapes)
5151 { /* Return "@-IDENT", followed by '\0'. */
5153 CPP_RESERVE (pfile, 3);
5154 ident = pfile->token_buffer + before_name_written;
5155 CPP_ADJUST_WRITTEN (pfile, 2);
5156 for (i = ident_len; i >= 0; i--) ident[i+2] = ident[i];
5163 /* If macro wants an arglist, verify that a '(' follows.
5164 first skip all whitespace, copying it to the output
5165 after the macro name. Then, if there is no '(',
5166 decide this is not a macro call and leave things that way. */
5167 if (hp->type == T_MACRO && hp->value.defn->nargs >= 0)
5169 struct parse_marker macro_mark;
5171 while (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
5173 cpp_buffer *next_buf;
5174 cpp_skip_hspace (pfile);
5175 if (PEEKC () != EOF)
5177 next_buf = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
5178 (*CPP_BUFFER (pfile)->cleanup) (CPP_BUFFER (pfile), pfile);
5179 CPP_BUFFER (pfile) = next_buf;
5181 parse_set_mark (¯o_mark, pfile);
5184 cpp_skip_hspace (pfile);
5186 is_macro_call = c == '(';
5192 parse_goto_mark (¯o_mark, pfile);
5193 parse_clear_mark (¯o_mark);
5197 /* This is now known to be a macro call. */
5199 /* it might not actually be a macro. */
5200 if (hp->type != T_MACRO) {
5201 int xbuf_len; U_CHAR *xbuf;
5202 CPP_SET_WRITTEN (pfile, before_name_written);
5203 special_symbol (hp, pfile);
5204 xbuf_len = CPP_WRITTEN (pfile) - before_name_written;
5205 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
5206 CPP_SET_WRITTEN (pfile, before_name_written);
5207 bcopy (CPP_PWRITTEN (pfile), xbuf, xbuf_len + 1);
5208 push_macro_expansion (pfile, xbuf, xbuf_len, hp);
5212 /* Expand the macro, reading arguments as needed,
5213 and push the expansion on the input stack. */
5214 macroexpand (pfile, hp);
5215 CPP_SET_WRITTEN (pfile, before_name_written);
5218 /* An extra space is added to the end of a macro expansion
5219 to prevent accidental token pasting. We prefer to avoid
5220 unneeded extra spaces (for the sake of cpp-using tools like
5221 imake). Here we remove the space if it is safe to do so. */
5222 if (pfile->buffer->rlimit - pfile->buffer->cur >= 2
5223 && pfile->buffer->cur[-1] == ' ')
5225 int c1 = pfile->buffer->rlimit[-2];
5226 int c2 = CPP_BUF_PEEK (CPP_PREV_BUFFER (CPP_BUFFER (pfile)));
5227 if (c2 == EOF || ! unsafe_chars (c1, c2))
5228 pfile->buffer->rlimit--;
5235 case ' ': case '\t': case '\v': case '\r':
5238 CPP_PUTC (pfile, c);
5240 if (c == EOF || !is_hor_space[c])
5254 CPP_PUTC (pfile, c);
5255 if (pfile->only_seen_white == 0)
5256 pfile->only_seen_white = 1;
5258 output_line_command (pfile, 1, same_file);
5261 case '(': token = CPP_LPAREN; goto char1;
5262 case ')': token = CPP_RPAREN; goto char1;
5263 case '{': token = CPP_LBRACE; goto char1;
5264 case '}': token = CPP_RBRACE; goto char1;
5265 case ',': token = CPP_COMMA; goto char1;
5266 case ';': token = CPP_SEMICOLON; goto char1;
5272 pfile->only_seen_white = 0;
5273 CPP_PUTC (pfile, c);
5279 /* Like cpp_get_token, but skip spaces and comments. */
5281 cpp_get_non_space_token (pfile)
5284 int old_written = CPP_WRITTEN (pfile);
5287 enum cpp_token token = cpp_get_token (pfile);
5288 if (token != CPP_COMMENT && token != CPP_POP
5289 && token != CPP_HSPACE && token != CPP_VSPACE)
5291 CPP_SET_WRITTEN (pfile, old_written);
5295 /* Parse an identifier starting with C. */
5298 parse_name (pfile, c)
5299 cpp_reader *pfile; int c;
5305 if (c == '\\' && PEEKC() == '\n')
5314 CPP_RESERVE(pfile, 2); /* One more for final NUL. */
5315 CPP_PUTC_Q (pfile, c);
5320 CPP_NUL_TERMINATE_Q (pfile);
5325 /* Maintain and search list of included files, for #import. */
5327 /* Hash a file name for import_hash_table. */
5335 while (*f) val += *f++;
5336 return (val%IMPORT_HASH_SIZE);
5339 /* Search for file FILENAME in import_hash_table.
5340 Return -2 if found, either a matching name or a matching inode.
5341 Otherwise, open the file and return a file descriptor if successful
5342 or -1 if unsuccessful. */
5345 lookup_import (pfile, filename, searchptr)
5348 struct file_name_list *searchptr;
5350 struct import_file *i;
5356 hashval = import_hash (filename);
5358 /* Attempt to find file in list of already included files */
5359 i = pfile->import_hash_table[hashval];
5362 if (!strcmp (filename, i->name))
5363 return -2; /* return found */
5366 /* Open it and try a match on inode/dev */
5367 fd = open_include_file (filename, searchptr);
5371 for (h = 0; h < IMPORT_HASH_SIZE; h++) {
5372 i = pfile->import_hash_table[h];
5374 /* Compare the inode and the device.
5375 Supposedly on some systems the inode is not a scalar. */
5376 if (!bcmp (&i->inode, &sb.st_ino, sizeof (sb.st_ino))
5377 && i->dev == sb.st_dev) {
5379 return -2; /* return found */
5384 return fd; /* Not found, return open file */
5387 /* Add the file FNAME, open on descriptor FD, to import_hash_table. */
5390 add_import (pfile, fd, fname)
5395 struct import_file *i;
5399 hashval = import_hash (fname);
5401 i = (struct import_file *)xmalloc (sizeof (struct import_file));
5402 i->name = (char *)xmalloc (strlen (fname)+1);
5403 strcpy (i->name, fname);
5404 bcopy (&sb.st_ino, &i->inode, sizeof (sb.st_ino));
5406 i->next = pfile->import_hash_table[hashval];
5407 pfile->import_hash_table[hashval] = i;
5410 /* The file_name_map structure holds a mapping of file names for a
5411 particular directory. This mapping is read from the file named
5412 FILE_NAME_MAP_FILE in that directory. Such a file can be used to
5413 map filenames on a file system with severe filename restrictions,
5414 such as DOS. The format of the file name map file is just a series
5415 of lines with two tokens on each line. The first token is the name
5416 to map, and the second token is the actual name to use. */
5418 struct file_name_map
5420 struct file_name_map *map_next;
5425 #define FILE_NAME_MAP_FILE "header.gcc"
5427 /* Read a space delimited string of unlimited length from a stdio
5431 read_filename_string (ch, f)
5439 set = alloc = xmalloc (len + 1);
5443 while ((ch = getc (f)) != EOF && ! is_space[ch])
5445 if (set - alloc == len)
5448 alloc = xrealloc (alloc, len + 1);
5449 set = alloc + len / 2;
5459 /* Read the file name map file for DIRNAME. */
5461 static struct file_name_map *
5462 read_name_map (dirname)
5465 /* This structure holds a linked list of file name maps, one per
5467 struct file_name_map_list
5469 struct file_name_map_list *map_list_next;
5470 char *map_list_name;
5471 struct file_name_map *map_list_map;
5473 static struct file_name_map_list *map_list;
5474 register struct file_name_map_list *map_list_ptr;
5478 for (map_list_ptr = map_list; map_list_ptr;
5479 map_list_ptr = map_list_ptr->map_list_next)
5480 if (! strcmp (map_list_ptr->map_list_name, dirname))
5481 return map_list_ptr->map_list_map;
5483 map_list_ptr = ((struct file_name_map_list *)
5484 xmalloc (sizeof (struct file_name_map_list)));
5485 map_list_ptr->map_list_name = savestring (dirname);
5486 map_list_ptr->map_list_map = NULL;
5488 name = (char *) alloca (strlen (dirname) + strlen (FILE_NAME_MAP_FILE) + 2);
5489 strcpy (name, dirname);
5492 strcat (name, FILE_NAME_MAP_FILE);
5493 f = fopen (name, "r");
5495 map_list_ptr->map_list_map = NULL;
5499 int dirlen = strlen (dirname);
5501 while ((ch = getc (f)) != EOF)
5504 struct file_name_map *ptr;
5508 from = read_filename_string (ch, f);
5509 while ((ch = getc (f)) != EOF && is_hor_space[ch])
5511 to = read_filename_string (ch, f);
5513 ptr = ((struct file_name_map *)
5514 xmalloc (sizeof (struct file_name_map)));
5515 ptr->map_from = from;
5517 /* Make the real filename absolute. */
5522 ptr->map_to = xmalloc (dirlen + strlen (to) + 2);
5523 strcpy (ptr->map_to, dirname);
5524 ptr->map_to[dirlen] = '/';
5525 strcpy (ptr->map_to + dirlen + 1, to);
5529 ptr->map_next = map_list_ptr->map_list_map;
5530 map_list_ptr->map_list_map = ptr;
5532 while ((ch = getc (f)) != '\n')
5539 map_list_ptr->map_list_next = map_list;
5540 map_list = map_list_ptr;
5542 return map_list_ptr->map_list_map;
5545 /* Try to open include file FILENAME. SEARCHPTR is the directory
5546 being tried from the include file search path. This function maps
5547 filenames on file systems based on information read by
5551 open_include_file (filename, searchptr)
5553 struct file_name_list *searchptr;
5555 register struct file_name_map *map;
5556 register char *from;
5559 if (searchptr && ! searchptr->got_name_map)
5561 searchptr->name_map = read_name_map (searchptr->fname
5562 ? searchptr->fname : ".");
5563 searchptr->got_name_map = 1;
5566 /* First check the mapping for the directory we are using. */
5567 if (searchptr && searchptr->name_map)
5570 if (searchptr->fname)
5571 from += strlen (searchptr->fname) + 1;
5572 for (map = searchptr->name_map; map; map = map->map_next)
5574 if (! strcmp (map->map_from, from))
5576 /* Found a match. */
5577 return open (map->map_to, O_RDONLY, 0666);
5582 /* Try to find a mapping file for the particular directory we are
5583 looking in. Thus #include <sys/types.h> will look up sys/types.h
5584 in /usr/include/header.gcc and look up types.h in
5585 /usr/include/sys/header.gcc. */
5586 p = rindex (filename, '/');
5591 && strlen (searchptr->fname) == p - filename
5592 && ! strncmp (searchptr->fname, filename, p - filename))
5594 /* FILENAME is in SEARCHPTR, which we've already checked. */
5595 return open (filename, O_RDONLY, 0666);
5605 dir = (char *) alloca (p - filename + 1);
5606 bcopy (filename, dir, p - filename);
5607 dir[p - filename] = '\0';
5610 for (map = read_name_map (dir); map; map = map->map_next)
5611 if (! strcmp (map->map_from, from))
5612 return open (map->map_to, O_RDONLY, 0666);
5614 return open (filename, O_RDONLY, 0666);
5617 /* Process the contents of include file FNAME, already open on descriptor F,
5619 SYSTEM_HEADER_P is 1 if this file resides in any one of the known
5620 "system" include directories (as decided by the `is_system_include'
5622 DIRPTR is the link in the dir path through which this file was found,
5623 or 0 if the file name was absolute.
5624 Return 1 on success, 0 on failure. */
5627 finclude (pfile, f, fname, system_header_p, dirptr)
5631 int system_header_p;
5632 struct file_name_list *dirptr;
5638 cpp_buffer *fp; /* For input stack frame */
5639 int missing_newline = 0;
5642 CHECK_DEPTH (return 0;);
5645 if (file_size_and_mode (f, &st_mode, &st_size) < 0)
5647 cpp_perror_with_name (pfile, fname);
5652 fp = cpp_push_buffer (pfile, NULL, 0);
5653 fp->nominal_fname = fp->fname = fname;
5658 fp->system_header_p = system_header_p;
5661 fp->cleanup = file_cleanup;
5663 if (S_ISREG (st_mode)) {
5664 fp->buf = (U_CHAR *) xmalloc (st_size + 2);
5665 fp->alimit = fp->buf + st_size + 2;
5668 /* Read the file contents, knowing that st_size is an upper bound
5669 on the number of bytes we can read. */
5670 length = safe_read (f, fp->buf, st_size);
5671 fp->rlimit = fp->buf + length;
5672 if (length < 0) goto nope;
5674 else if (S_ISDIR (st_mode)) {
5675 cpp_error (pfile, "directory `%s' specified in #include", fname);
5679 /* Cannot count its file size before reading.
5680 First read the entire file into heap and
5681 copy them into buffer on stack. */
5686 fp->buf = (U_CHAR *) xmalloc (bsize + 2);
5689 i = safe_read (f, fp->buf + st_size, bsize - st_size);
5691 goto nope; /* error! */
5693 if (st_size != bsize)
5694 break; /* End of file */
5696 fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
5701 if ((length > 0 && fp->buf[length - 1] != '\n')
5702 /* Backslash-newline at end is not good enough. */
5703 || (length > 1 && fp->buf[length - 2] == '\\')) {
5704 fp->buf[length++] = '\n';
5706 missing_newline = 1;
5709 fp->buf[length] = '\0';
5710 fp->rlimit = fp->buf + length;
5712 /* Close descriptor now, so nesting does not use lots of descriptors. */
5715 /* Must do this before calling trigraph_pcp, so that the correct file name
5716 will be printed in warning messages. */
5718 pfile->input_stack_listing_current = 0;
5728 if (missing_newline)
5731 if (CPP_PEDANTIC (pfile) && missing_newline)
5732 pedwarn ("file does not end in newline");
5735 input_file_stack_tick++;
5742 cpp_perror_with_name (pfile, fname);
5749 push_parse_file (pfile, fname)
5753 struct cpp_options *opts = CPP_OPTIONS (pfile);
5754 struct cpp_pending *pend;
5758 /* The code looks at the defaults through this pointer, rather than through
5759 the constant structure above. This pointer gets changed if an environment
5760 variable specifies other defaults. */
5761 struct default_include *include_defaults = include_defaults_array;
5763 /* Add dirs from CPATH after dirs from -I. */
5764 /* There seems to be confusion about what CPATH should do,
5765 so for the moment it is not documented. */
5766 /* Some people say that CPATH should replace the standard include dirs,
5767 but that seems pointless: it comes before them, so it overrides them
5769 p = (char *) getenv ("CPATH");
5770 if (p != 0 && ! opts->no_standard_includes)
5771 path_include (pfile, p);
5773 /* Now that dollars_in_ident is known, initialize is_idchar. */
5774 initialize_char_syntax (opts);
5777 /* Do partial setup of input buffer for the sake of generating
5778 early #line directives (when -g is in effect). */
5780 fp = &instack[++indepth];
5781 if (in_fname == NULL)
5783 fp->nominal_fname = fp->fname = in_fname;
5787 /* Install __LINE__, etc. Must follow initialize_char_syntax
5788 and option processing. */
5789 initialize_builtins (pfile);
5791 /* Do standard #defines and assertions
5792 that identify system and machine type. */
5794 if (!opts->inhibit_predefs) {
5795 char *p = (char *) alloca (strlen (predefs) + 1);
5796 strcpy (p, predefs);
5799 while (*p == ' ' || *p == '\t')
5801 /* Handle -D options. */
5802 if (p[0] == '-' && p[1] == 'D') {
5804 while (*p && *p != ' ' && *p != '\t')
5808 if (opts->debug_output)
5809 output_line_command (pfile, 0, same_file);
5810 make_definition (pfile, q);
5811 while (*p == ' ' || *p == '\t')
5813 } else if (p[0] == '-' && p[1] == 'A') {
5814 /* Handle -A options (assertions). */
5823 past_name = assertion;
5824 /* Locate end of name. */
5825 while (*past_name && *past_name != ' '
5826 && *past_name != '\t' && *past_name != '(')
5828 /* Locate `(' at start of value. */
5830 while (*value && (*value == ' ' || *value == '\t'))
5832 if (*value++ != '(')
5834 while (*value && (*value == ' ' || *value == '\t'))
5837 /* Locate end of value. */
5838 while (*past_value && *past_value != ' '
5839 && *past_value != '\t' && *past_value != ')')
5841 termination = past_value;
5842 while (*termination && (*termination == ' ' || *termination == '\t'))
5844 if (*termination++ != ')')
5846 if (*termination && *termination != ' ' && *termination != '\t')
5848 /* Temporarily null-terminate the value. */
5849 save_char = *termination;
5850 *termination = '\0';
5851 /* Install the assertion. */
5852 make_assertion (pfile, "-A", assertion);
5853 *termination = (char) save_char;
5855 while (*p == ' ' || *p == '\t')
5863 /* Now handle the command line options. */
5865 /* Do -U's, -D's and -A's in the order they were seen. */
5866 /* First reverse the list. */
5868 struct cpp_pending *prev = 0, *next;
5869 for (pend = opts->pending; pend; pend = next)
5875 opts->pending = prev;
5877 for (pend = opts->pending; pend; pend = pend->next)
5879 if (pend->cmd != NULL && pend->cmd[0] == '-')
5881 switch (pend->cmd[1])
5884 if (opts->debug_output)
5885 output_line_command (pfile, 0, same_file);
5886 do_undef (pfile, NULL, pend->arg, pend->arg + strlen (pend->arg));
5889 if (opts->debug_output)
5890 output_line_command (pfile, 0, same_file);
5891 make_definition (pfile, pend->arg);
5894 make_assertion (pfile, "-A", pend->arg);
5899 opts->pending = NULL;
5902 opts->done_initializing = 1;
5904 { /* read the appropriate environment variable and if it exists
5905 replace include_defaults with the listed path. */
5907 switch ((opts->objc << 1) + opts->cplusplus)
5910 epath = getenv ("C_INCLUDE_PATH");
5913 epath = getenv ("CPLUS_INCLUDE_PATH");
5916 epath = getenv ("OBJC_INCLUDE_PATH");
5919 epath = getenv ("OBJCPLUS_INCLUDE_PATH");
5922 /* If the environment var for this language is set,
5923 add to the default list of include directories. */
5925 char *nstore = (char *) alloca (strlen (epath) + 2);
5927 char *startp, *endp;
5929 for (num_dirs = 1, startp = epath; *startp; startp++)
5930 if (*startp == PATH_SEPARATOR)
5933 = (struct default_include *) xmalloc ((num_dirs
5934 * sizeof (struct default_include))
5935 + sizeof (include_defaults_array));
5936 startp = endp = epath;
5939 /* Handle cases like c:/usr/lib:d:/gcc/lib */
5940 if ((*endp == PATH_SEPARATOR)
5942 strncpy (nstore, startp, endp-startp);
5944 strcpy (nstore, ".");
5946 nstore[endp-startp] = '\0';
5948 include_defaults[num_dirs].fname = savestring (nstore);
5949 include_defaults[num_dirs].cplusplus = opts->cplusplus;
5950 include_defaults[num_dirs].cxx_aware = 1;
5954 endp = startp = endp + 1;
5958 /* Put the usual defaults back in at the end. */
5959 bcopy (include_defaults_array, &include_defaults[num_dirs],
5960 sizeof (include_defaults_array));
5964 append_include_chain (pfile, opts->before_system, opts->last_before_system);
5965 opts->first_system_include = opts->before_system;
5967 /* Unless -fnostdinc,
5968 tack on the standard include file dirs to the specified list */
5969 if (!opts->no_standard_includes) {
5970 struct default_include *p = include_defaults;
5971 char *specd_prefix = opts->include_prefix;
5972 char *default_prefix = savestring (GCC_INCLUDE_DIR);
5973 int default_len = 0;
5974 /* Remove the `include' from /usr/local/lib/gcc.../include. */
5975 if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) {
5976 default_len = strlen (default_prefix) - 7;
5977 default_prefix[default_len] = 0;
5979 /* Search "translated" versions of GNU directories.
5980 These have /usr/local/lib/gcc... replaced by specd_prefix. */
5981 if (specd_prefix != 0 && default_len != 0)
5982 for (p = include_defaults; p->fname; p++) {
5983 /* Some standard dirs are only for C++. */
5985 || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
5986 /* Does this dir start with the prefix? */
5987 if (!strncmp (p->fname, default_prefix, default_len)) {
5988 /* Yes; change prefix and add to search list. */
5989 struct file_name_list *new
5990 = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
5991 int this_len = strlen (specd_prefix) + strlen (p->fname) - default_len;
5992 char *str = (char *) xmalloc (this_len + 1);
5993 strcpy (str, specd_prefix);
5994 strcat (str, p->fname + default_len);
5996 new->control_macro = 0;
5997 new->c_system_include_path = !p->cxx_aware;
5998 new->got_name_map = 0;
5999 append_include_chain (pfile, new, new);
6000 if (opts->first_system_include == 0)
6001 opts->first_system_include = new;
6005 /* Search ordinary names for GNU include directories. */
6006 for (p = include_defaults; p->fname; p++) {
6007 /* Some standard dirs are only for C++. */
6009 || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
6010 struct file_name_list *new
6011 = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
6012 new->control_macro = 0;
6013 new->c_system_include_path = !p->cxx_aware;
6014 new->fname = p->fname;
6015 new->got_name_map = 0;
6016 append_include_chain (pfile, new, new);
6017 if (opts->first_system_include == 0)
6018 opts->first_system_include = new;
6023 /* Tack the after_include chain at the end of the include chain. */
6024 append_include_chain (pfile, opts->after_include, opts->last_after_include);
6025 if (opts->first_system_include == 0)
6026 opts->first_system_include = opts->after_include;
6028 /* With -v, print the list of dirs to search. */
6029 if (opts->verbose) {
6030 struct file_name_list *p;
6031 fprintf (stderr, "#include \"...\" search starts here:\n");
6032 for (p = opts->include; p; p = p->next) {
6033 if (p == opts->first_bracket_include)
6034 fprintf (stderr, "#include <...> search starts here:\n");
6035 fprintf (stderr, " %s\n", p->fname);
6037 fprintf (stderr, "End of search list.\n");
6040 /* Scan the -imacros files before the main input.
6041 Much like #including them, but with no_output set
6042 so that only their macro definitions matter. */
6044 opts->no_output++; pfile->no_record_file++;
6045 for (pend = opts->pending; pend; pend = pend->next)
6047 if (pend->cmd != NULL && strcmp (pend->cmd, "-imacros") == 0)
6049 int fd = open (pend->arg, O_RDONLY, 0666);
6052 cpp_perror_with_name (pfile, pend->arg);
6053 return FAILURE_EXIT_CODE;
6055 finclude (pfile, fd, pend->arg, 0, NULL_PTR);
6056 cpp_scan_buffer (pfile);
6059 opts->no_output--; pfile->no_record_file--;
6061 /* Copy the entire contents of the main input file into
6062 the stacked input buffer previously allocated for it. */
6063 if (fname == NULL || *fname == 0) {
6066 } else if ((f = open (fname, O_RDONLY, 0666)) < 0)
6067 cpp_pfatal_with_name (pfile, fname);
6069 /* -MG doesn't select the form of output and must be specified with one of
6070 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
6071 inhibit compilation. */
6072 if (opts->print_deps_missing_files
6073 && (opts->print_deps == 0 || !opts->no_output))
6074 fatal (pfile, "-MG must be specified with one of -M or -MM");
6076 /* Either of two environment variables can specify output of deps.
6077 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
6078 where OUTPUT_FILE is the file to write deps info to
6079 and DEPS_TARGET is the target to mention in the deps. */
6081 if (opts->print_deps == 0
6082 && (getenv ("SUNPRO_DEPENDENCIES") != 0
6083 || getenv ("DEPENDENCIES_OUTPUT") != 0)) {
6084 char *spec = getenv ("DEPENDENCIES_OUTPUT");
6090 spec = getenv ("SUNPRO_DEPENDENCIES");
6091 opts->print_deps = 2;
6094 opts->print_deps = 1;
6097 /* Find the space before the DEPS_TARGET, if there is one. */
6098 /* This should use index. (mrs) */
6099 while (*s != 0 && *s != ' ') s++;
6102 opts->deps_target = s + 1;
6103 output_file = (char *) xmalloc (s - spec + 1);
6104 bcopy (spec, output_file, s - spec);
6105 output_file[s - spec] = 0;
6109 opts->deps_target = 0;
6113 opts->deps_file = output_file;
6114 opts->print_deps_append = 1;
6117 /* For -M, print the expected object file name
6118 as the target of this Make-rule. */
6119 if (opts->print_deps)
6121 pfile->deps_allocated_size = 200;
6122 pfile->deps_buffer = (char *) xmalloc (pfile->deps_allocated_size);
6123 pfile->deps_buffer[0] = 0;
6124 pfile->deps_size = 0;
6125 pfile->deps_column = 0;
6127 if (opts->deps_target)
6128 deps_output (pfile, opts->deps_target, ':');
6129 else if (*opts->in_fname == 0)
6130 deps_output (pfile, "-", ':');
6136 /* Discard all directory prefixes from filename. */
6137 if ((q = rindex (opts->in_fname, '/')) != NULL
6138 #ifdef DIR_SEPARATOR
6139 && (q = rindex (opts->in_fname, DIR_SEPARATOR)) != NULL
6146 /* Copy remainder to mungable area. */
6147 p = (char *) alloca (strlen(q) + 8);
6150 /* Output P, but remove known suffixes. */
6154 && p[len - 2] == '.'
6155 && index("cCsSm", p[len - 1]))
6158 && p[len - 3] == '.'
6159 && p[len - 2] == 'c'
6160 && p[len - 1] == 'c')
6163 && p[len - 4] == '.'
6164 && p[len - 3] == 'c'
6165 && p[len - 2] == 'x'
6166 && p[len - 1] == 'x')
6169 && p[len - 4] == '.'
6170 && p[len - 3] == 'c'
6171 && p[len - 2] == 'p'
6172 && p[len - 1] == 'p')
6175 /* Supply our own suffix. */
6182 deps_output (pfile, p, ':');
6183 deps_output (pfile, opts->in_fname, ' ');
6188 /* Make sure data ends with a newline. And put a null after it. */
6190 if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n')
6191 /* Backslash-newline at end is not good enough. */
6192 || (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) {
6193 fp->buf[fp->length++] = '\n';
6194 missing_newline = 1;
6196 fp->buf[fp->length] = '\0';
6198 /* Unless inhibited, convert trigraphs in the input. */
6204 /* Scan the -include files before the main input. */
6206 pfile->no_record_file++;
6207 for (pend = opts->pending; pend; pend = pend->next)
6209 if (pend->cmd != NULL && strcmp (pend->cmd, "-include") == 0)
6211 int fd = open (pend->arg, O_RDONLY, 0666);
6214 cpp_perror_with_name (pfile, pend->arg);
6215 return FAILURE_EXIT_CODE;
6217 finclude (pfile, fd, pend->arg, 0, NULL_PTR);
6218 cpp_scan_buffer (pfile);
6221 pfile->no_record_file--;
6223 /* Free the pending list. */
6224 for (pend = opts->pending; pend; )
6226 struct cpp_pending *next = pend->next;
6230 opts->pending = NULL;
6233 /* Scan the input, processing macros and directives. */
6235 rescan (&outbuf, 0);
6237 if (missing_newline)
6240 if (CPP_PEDANTIC (pfile) && missing_newline)
6241 pedwarn ("file does not end in newline");
6244 if (finclude (pfile, f, fname, 0, 0))
6245 output_line_command (pfile, 0, same_file);
6246 return SUCCESS_EXIT_CODE;
6250 init_parse_file (pfile)
6253 bzero (pfile, sizeof (cpp_reader));
6254 pfile->get_token = cpp_get_token;
6256 pfile->token_buffer_size = 200;
6257 pfile->token_buffer = (char*)xmalloc (pfile->token_buffer_size);
6258 CPP_SET_WRITTEN (pfile, 0);
6260 pfile->system_include_depth = 0;
6261 pfile->dont_repeat_files = 0;
6262 pfile->all_include_files = 0;
6263 pfile->max_include_len = 0;
6264 pfile->timebuf = NULL;
6265 pfile->only_seen_white = 1;
6266 pfile->buffer = CPP_NULL_BUFFER(pfile);
6270 push_pending (pfile, cmd, arg)
6275 struct cpp_pending *pend
6276 = (struct cpp_pending*)xmalloc (sizeof (struct cpp_pending));
6279 pend->next = CPP_OPTIONS (pfile)->pending;
6280 CPP_OPTIONS (pfile)->pending = pend;
6283 /* Handle command-line options in (argc, argv).
6284 Can be called multiple times, to handle multiple sets of options.
6285 Returns if an unrecognized option is seen.
6286 Returns number of handled arguments. */
6289 cpp_handle_options (pfile, argc, argv)
6295 struct cpp_options *opts = CPP_OPTIONS (pfile);
6296 for (i = 0; i < argc; i++) {
6297 if (argv[i][0] != '-') {
6298 if (opts->out_fname != NULL)
6299 fatal ("Usage: %s [switches] input output", argv[0]);
6300 else if (opts->in_fname != NULL)
6301 opts->out_fname = argv[i];
6303 opts->in_fname = argv[i];
6305 switch (argv[i][1]) {
6308 if (!strcmp (argv[i], "-include")
6309 || !strcmp (argv[i], "-imacros")) {
6311 fatal ("Filename missing after `%s' option", argv[i]);
6313 push_pending (pfile, argv[i], argv[i+1]), i++;
6315 if (!strcmp (argv[i], "-iprefix")) {
6317 fatal ("Filename missing after `-iprefix' option");
6319 opts->include_prefix = argv[++i];
6321 if (!strcmp (argv[i], "-ifoutput")) {
6322 opts->output_conditionals = 1;
6324 if (!strcmp (argv[i], "-isystem")) {
6325 struct file_name_list *dirtmp;
6328 fatal ("Filename missing after `-isystem' option");
6330 dirtmp = (struct file_name_list *)
6331 xmalloc (sizeof (struct file_name_list));
6333 dirtmp->control_macro = 0;
6334 dirtmp->c_system_include_path = 1;
6335 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1]) + 1);
6336 strcpy (dirtmp->fname, argv[++i]);
6337 dirtmp->got_name_map = 0;
6339 if (opts->before_system == 0)
6340 opts->before_system = dirtmp;
6342 opts->last_before_system->next = dirtmp;
6343 opts->last_before_system = dirtmp; /* Tail follows the last one */
6345 /* Add directory to end of path for includes,
6346 with the default prefix at the front of its name. */
6347 if (!strcmp (argv[i], "-iwithprefix")) {
6348 struct file_name_list *dirtmp;
6351 if (opts->include_prefix != 0)
6352 prefix = opts->include_prefix;
6354 prefix = savestring (GCC_INCLUDE_DIR);
6355 /* Remove the `include' from /usr/local/lib/gcc.../include. */
6356 if (!strcmp (prefix + strlen (prefix) - 8, "/include"))
6357 prefix[strlen (prefix) - 7] = 0;
6360 dirtmp = (struct file_name_list *)
6361 xmalloc (sizeof (struct file_name_list));
6362 dirtmp->next = 0; /* New one goes on the end */
6363 dirtmp->control_macro = 0;
6364 dirtmp->c_system_include_path = 0;
6366 fatal ("Directory name missing after `-iwithprefix' option");
6368 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1])
6369 + strlen (prefix) + 1);
6370 strcpy (dirtmp->fname, prefix);
6371 strcat (dirtmp->fname, argv[++i]);
6372 dirtmp->got_name_map = 0;
6374 if (opts->after_include == 0)
6375 opts->after_include = dirtmp;
6377 opts->last_after_include->next = dirtmp;
6378 opts->last_after_include = dirtmp; /* Tail follows the last one */
6380 /* Add directory to main path for includes,
6381 with the default prefix at the front of its name. */
6382 if (!strcmp (argv[i], "-iwithprefixbefore")) {
6383 struct file_name_list *dirtmp;
6386 if (opts->include_prefix != 0)
6387 prefix = opts->include_prefix;
6389 prefix = savestring (GCC_INCLUDE_DIR);
6390 /* Remove the `include' from /usr/local/lib/gcc.../include. */
6391 if (!strcmp (prefix + strlen (prefix) - 8, "/include"))
6392 prefix[strlen (prefix) - 7] = 0;
6395 dirtmp = (struct file_name_list *)
6396 xmalloc (sizeof (struct file_name_list));
6397 dirtmp->next = 0; /* New one goes on the end */
6398 dirtmp->control_macro = 0;
6399 dirtmp->c_system_include_path = 0;
6401 fatal ("Directory name missing after `-iwithprefixbefore' option");
6403 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1])
6404 + strlen (prefix) + 1);
6405 strcpy (dirtmp->fname, prefix);
6406 strcat (dirtmp->fname, argv[++i]);
6407 dirtmp->got_name_map = 0;
6409 append_include_chain (pfile, dirtmp, dirtmp);
6411 /* Add directory to end of path for includes. */
6412 if (!strcmp (argv[i], "-idirafter")) {
6413 struct file_name_list *dirtmp;
6415 dirtmp = (struct file_name_list *)
6416 xmalloc (sizeof (struct file_name_list));
6417 dirtmp->next = 0; /* New one goes on the end */
6418 dirtmp->control_macro = 0;
6419 dirtmp->c_system_include_path = 0;
6421 fatal ("Directory name missing after `-idirafter' option");
6423 dirtmp->fname = argv[++i];
6424 dirtmp->got_name_map = 0;
6426 if (opts->after_include == 0)
6427 opts->after_include = dirtmp;
6429 opts->last_after_include->next = dirtmp;
6430 opts->last_after_include = dirtmp; /* Tail follows the last one */
6435 if (opts->out_fname != NULL)
6436 fatal ("Output filename specified twice");
6438 fatal ("Filename missing after -o option");
6439 opts->out_fname = argv[++i];
6440 if (!strcmp (opts->out_fname, "-"))
6441 opts->out_fname = "";
6445 if (!strcmp (argv[i], "-pedantic"))
6446 CPP_PEDANTIC (pfile) = 1;
6447 else if (!strcmp (argv[i], "-pedantic-errors")) {
6448 CPP_PEDANTIC (pfile) = 1;
6449 opts->pedantic_errors = 1;
6452 else if (!strcmp (argv[i], "-pcp")) {
6453 char *pcp_fname = argv[++i];
6455 ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
6456 ? fopen (pcp_fname, "w")
6457 : fdopen (dup (fileno (stdout)), "w"));
6458 if (pcp_outfile == 0)
6459 cpp_pfatal_with_name (pfile, pcp_fname);
6466 if (!strcmp (argv[i], "-traditional")) {
6467 opts->traditional = 1;
6468 if (opts->dollars_in_ident > 0)
6469 opts->dollars_in_ident = 1;
6470 } else if (!strcmp (argv[i], "-trigraphs")) {
6472 opts->no_trigraphs = 0;
6477 if (! strcmp (argv[i], "-lang-c"))
6478 opts->cplusplus = 0, opts->cplusplus_comments = 0, opts->objc = 0;
6479 if (! strcmp (argv[i], "-lang-c++"))
6480 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->objc = 0;
6481 if (! strcmp (argv[i], "-lang-c-c++-comments"))
6482 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->objc = 0;
6483 if (! strcmp (argv[i], "-lang-objc"))
6484 opts->objc = 1, opts->cplusplus = 0, opts->cplusplus_comments = 1;
6485 if (! strcmp (argv[i], "-lang-objc++"))
6486 opts->objc = 1, opts->cplusplus = 1, opts->cplusplus_comments = 1;
6487 if (! strcmp (argv[i], "-lang-asm"))
6489 if (! strcmp (argv[i], "-lint"))
6491 if (! strcmp (argv[i], "-lang-chill"))
6492 opts->objc = 0, opts->cplusplus = 0, opts->chill = 1,
6493 opts->traditional = 1, opts->no_trigraphs = 1;
6497 opts->cplusplus = 1, opts->cplusplus_comments = 1;
6501 opts->inhibit_warnings = 1;
6505 if (!strcmp (argv[i], "-Wtrigraphs"))
6506 opts->warn_trigraphs = 1;
6507 else if (!strcmp (argv[i], "-Wno-trigraphs"))
6508 opts->warn_trigraphs = 0;
6509 else if (!strcmp (argv[i], "-Wcomment"))
6510 opts->warn_comments = 1;
6511 else if (!strcmp (argv[i], "-Wno-comment"))
6512 opts->warn_comments = 0;
6513 else if (!strcmp (argv[i], "-Wcomments"))
6514 opts->warn_comments = 1;
6515 else if (!strcmp (argv[i], "-Wno-comments"))
6516 opts->warn_comments = 0;
6517 else if (!strcmp (argv[i], "-Wtraditional"))
6518 opts->warn_stringify = 1;
6519 else if (!strcmp (argv[i], "-Wno-traditional"))
6520 opts->warn_stringify = 0;
6521 else if (!strcmp (argv[i], "-Wimport"))
6522 opts->warn_import = 1;
6523 else if (!strcmp (argv[i], "-Wno-import"))
6524 opts->warn_import = 0;
6525 else if (!strcmp (argv[i], "-Werror"))
6526 opts->warnings_are_errors = 1;
6527 else if (!strcmp (argv[i], "-Wno-error"))
6528 opts->warnings_are_errors = 0;
6529 else if (!strcmp (argv[i], "-Wall"))
6531 opts->warn_trigraphs = 1;
6532 opts->warn_comments = 1;
6537 /* The style of the choices here is a bit mixed.
6538 The chosen scheme is a hybrid of keeping all options in one string
6539 and specifying each option in a separate argument:
6540 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
6541 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
6542 -M[M][G][D file]. This is awkward to handle in specs, and is not
6544 /* ??? -MG must be specified in addition to one of -M or -MM.
6545 This can be relaxed in the future without breaking anything.
6546 The converse isn't true. */
6548 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
6549 if (!strcmp (argv[i], "-MG"))
6551 opts->print_deps_missing_files = 1;
6554 if (!strcmp (argv[i], "-M"))
6555 opts->print_deps = 2;
6556 else if (!strcmp (argv[i], "-MM"))
6557 opts->print_deps = 1;
6558 else if (!strcmp (argv[i], "-MD"))
6559 opts->print_deps = 2;
6560 else if (!strcmp (argv[i], "-MMD"))
6561 opts->print_deps = 1;
6562 /* For -MD and -MMD options, write deps on file named by next arg. */
6563 if (!strcmp (argv[i], "-MD") || !strcmp (argv[i], "-MMD"))
6566 fatal ("Filename missing after %s option", argv[i]);
6567 opts->deps_file = argv[++i];
6571 /* For -M and -MM, write deps on standard output
6572 and suppress the usual output. */
6573 opts->no_output = 1;
6579 char *p = argv[i] + 2;
6581 while ((c = *p++) != 0) {
6582 /* Arg to -d specifies what parts of macros to dump */
6585 opts->dump_macros = dump_only;
6586 opts->no_output = 1;
6589 opts->dump_macros = dump_names;
6592 opts->dump_macros = dump_definitions;
6600 if (argv[i][2] == '3')
6601 opts->debug_output = 1;
6605 fprintf (stderr, "GNU CPP version %s", version_string);
6606 #ifdef TARGET_VERSION
6609 fprintf (stderr, "\n");
6614 opts->print_include_names = 1;
6618 if (argv[i][2] != 0)
6619 push_pending (pfile, "-D", argv[i] + 2);
6620 else if (i + 1 == argc)
6621 fatal ("Macro name missing after -D option");
6623 i++, push_pending (pfile, "-D", argv[i]);
6630 if (argv[i][2] != 0)
6632 else if (i + 1 == argc)
6633 fatal ("Assertion missing after -A option");
6637 if (!strcmp (p, "-")) {
6638 struct cpp_pending **ptr;
6639 /* -A- eliminates all predefined macros and assertions.
6640 Let's include also any that were specified earlier
6641 on the command line. That way we can get rid of any
6642 that were passed automatically in from GCC. */
6644 opts->inhibit_predefs = 1;
6645 for (ptr = &opts->pending; *ptr != NULL; )
6647 struct cpp_pending *pend = *ptr;
6648 if (pend->cmd && pend->cmd[0] == '-'
6649 && (pend->cmd[1] == 'D' || pend->cmd[1] == 'A'))
6658 push_pending (pfile, "-A", p);
6663 case 'U': /* JF #undef something */
6664 if (argv[i][2] != 0)
6665 push_pending (pfile, "-U", argv[i] + 2);
6666 else if (i + 1 == argc)
6667 fatal ("Macro name missing after -U option");
6669 push_pending (pfile, "-U", argv[i+1]), i++;
6673 opts->put_out_comments = 1;
6676 case 'E': /* -E comes from cc -E; ignore it. */
6680 opts->no_line_commands = 1;
6683 case '$': /* Don't include $ in identifiers. */
6684 opts->dollars_in_ident = 0;
6687 case 'I': /* Add directory to path for includes. */
6689 struct file_name_list *dirtmp;
6691 if (! CPP_OPTIONS(pfile)->ignore_srcdir
6692 && !strcmp (argv[i] + 2, "-")) {
6693 CPP_OPTIONS (pfile)->ignore_srcdir = 1;
6694 /* Don't use any preceding -I directories for #include <...>. */
6695 CPP_OPTIONS (pfile)->first_bracket_include = 0;
6698 dirtmp = (struct file_name_list *)
6699 xmalloc (sizeof (struct file_name_list));
6700 dirtmp->next = 0; /* New one goes on the end */
6701 dirtmp->control_macro = 0;
6702 dirtmp->c_system_include_path = 0;
6703 if (argv[i][2] != 0)
6704 dirtmp->fname = argv[i] + 2;
6705 else if (i + 1 == argc)
6706 fatal ("Directory name missing after -I option");
6708 dirtmp->fname = argv[++i];
6709 dirtmp->got_name_map = 0;
6710 append_include_chain (pfile, dirtmp, dirtmp);
6716 if (!strcmp (argv[i], "-nostdinc"))
6717 /* -nostdinc causes no default include directories.
6718 You must specify all include-file directories with -I. */
6719 opts->no_standard_includes = 1;
6720 else if (!strcmp (argv[i], "-nostdinc++"))
6721 /* -nostdinc++ causes no default C++-specific include directories. */
6722 opts->no_standard_cplusplus_includes = 1;
6724 else if (!strcmp (argv[i], "-noprecomp"))
6730 /* Sun compiler passes undocumented switch "-undef".
6731 Let's assume it means to inhibit the predefined symbols. */
6732 opts->inhibit_predefs = 1;
6735 case '\0': /* JF handle '-' as file name meaning stdin or stdout */
6736 if (opts->in_fname == NULL) {
6737 opts->in_fname = "";
6739 } else if (opts->out_fname == NULL) {
6740 opts->out_fname = "";
6742 } /* else fall through into error */
6756 struct cpp_options *opts = CPP_OPTIONS (pfile);
6758 if (opts->print_deps)
6760 /* Stream on which to print the dependency information. */
6763 /* Don't actually write the deps file if compilation has failed. */
6764 if (pfile->errors == 0)
6766 char *deps_mode = opts->print_deps_append ? "a" : "w";
6767 if (opts->deps_file == 0)
6768 deps_stream = stdout;
6769 else if ((deps_stream = fopen (opts->deps_file, deps_mode)) == 0)
6770 cpp_pfatal_with_name (pfile, opts->deps_file);
6771 fputs (pfile->deps_buffer, deps_stream);
6772 putc ('\n', deps_stream);
6773 if (opts->deps_file)
6775 if (ferror (deps_stream) || fclose (deps_stream) != 0)
6776 fatal ("I/O error on output");
6783 do_assert (pfile, keyword, buf, limit)
6785 struct directive *keyword;
6786 U_CHAR *buf, *limit;
6788 long symstart; /* remember where symbol name starts */
6790 int sym_length; /* and how long it is */
6791 struct arglist *tokens = NULL;
6793 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
6794 && !CPP_BUFFER (pfile)->system_header_p)
6795 cpp_pedwarn (pfile, "ANSI C does not allow `#assert'");
6797 cpp_skip_hspace (pfile);
6798 symstart = CPP_WRITTEN (pfile); /* remember where it starts */
6799 parse_name (pfile, GETC());
6800 sym_length = check_macro_name (pfile, pfile->token_buffer + symstart,
6803 cpp_skip_hspace (pfile);
6804 if (PEEKC() != '(') {
6805 cpp_error (pfile, "missing token-sequence in `#assert'");
6811 tokens = read_token_list (pfile, &error_flag);
6815 cpp_error (pfile, "empty token-sequence in `#assert'");
6818 cpp_skip_hspace (pfile);
6820 if (c != EOF && c != '\n')
6821 cpp_pedwarn (pfile, "junk at end of `#assert'");
6822 skip_rest_of_line (pfile);
6825 /* If this name isn't already an assertion name, make it one.
6826 Error if it was already in use in some other way. */
6829 ASSERTION_HASHNODE *hp;
6830 U_CHAR *symname = pfile->token_buffer + symstart;
6831 int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE);
6832 struct tokenlist_list *value
6833 = (struct tokenlist_list *) xmalloc (sizeof (struct tokenlist_list));
6835 hp = assertion_lookup (pfile, symname, sym_length, hashcode);
6837 if (sym_length == 7 && ! strncmp (symname, "defined", sym_length))
6838 cpp_error (pfile, "`defined' redefined as assertion");
6839 hp = assertion_install (pfile, symname, sym_length, hashcode);
6842 /* Add the spec'd token-sequence to the list of such. */
6843 value->tokens = tokens;
6844 value->next = hp->value;
6847 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6850 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6851 skip_rest_of_line (pfile);
6856 do_unassert (pfile, keyword, buf, limit)
6858 struct directive *keyword;
6859 U_CHAR *buf, *limit;
6861 long symstart; /* remember where symbol name starts */
6862 int sym_length; /* and how long it is */
6865 struct arglist *tokens = NULL;
6866 int tokens_specified = 0;
6868 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
6869 && !CPP_BUFFER (pfile)->system_header_p)
6870 cpp_pedwarn (pfile, "ANSI C does not allow `#unassert'");
6872 cpp_skip_hspace (pfile);
6874 symstart = CPP_WRITTEN (pfile); /* remember where it starts */
6875 parse_name (pfile, GETC());
6876 sym_length = check_macro_name (pfile, pfile->token_buffer + symstart,
6879 cpp_skip_hspace (pfile);
6880 if (PEEKC() == '(') {
6883 tokens = read_token_list (pfile, &error_flag);
6887 cpp_error (pfile, "empty token list in `#unassert'");
6891 tokens_specified = 1;
6894 cpp_skip_hspace (pfile);
6896 if (c != EOF && c != '\n')
6897 cpp_error (pfile, "junk at end of `#unassert'");
6898 skip_rest_of_line (pfile);
6901 ASSERTION_HASHNODE *hp;
6902 U_CHAR *symname = pfile->token_buffer + symstart;
6903 int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE);
6904 struct tokenlist_list *tail, *prev;
6906 hp = assertion_lookup (pfile, symname, sym_length, hashcode);
6910 /* If no token list was specified, then eliminate this assertion
6912 if (! tokens_specified) {
6913 struct tokenlist_list *next;
6914 for (tail = hp->value; tail; tail = next) {
6916 free_token_list (tail->tokens);
6919 delete_assertion (hp);
6921 /* If a list of tokens was given, then delete any matching list. */
6926 struct tokenlist_list *next = tail->next;
6927 if (compare_token_lists (tail->tokens, tokens)) {
6931 hp->value = tail->next;
6932 free_token_list (tail->tokens);
6942 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6945 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6946 skip_rest_of_line (pfile);
6950 /* Test whether there is an assertion named NAME
6951 and optionally whether it has an asserted token list TOKENS.
6952 NAME is not null terminated; its length is SYM_LENGTH.
6953 If TOKENS_SPECIFIED is 0, then don't check for any token list. */
6956 check_assertion (pfile, name, sym_length, tokens_specified, tokens)
6960 int tokens_specified;
6961 struct arglist *tokens;
6963 ASSERTION_HASHNODE *hp;
6964 int hashcode = hashf (name, sym_length, ASSERTION_HASHSIZE);
6966 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
6967 cpp_pedwarn (pfile, "ANSI C does not allow testing assertions");
6969 hp = assertion_lookup (pfile, name, sym_length, hashcode);
6971 /* It is not an assertion; just return false. */
6974 /* If no token list was specified, then value is 1. */
6975 if (! tokens_specified)
6979 struct tokenlist_list *tail;
6983 /* If a list of tokens was given,
6984 then succeed if the assertion records a matching list. */
6987 if (compare_token_lists (tail->tokens, tokens))
6992 /* Fail if the assertion has no matching list. */
6997 /* Compare two lists of tokens for equality including order of tokens. */
7000 compare_token_lists (l1, l2)
7001 struct arglist *l1, *l2;
7004 if (l1->length != l2->length)
7006 if (strncmp (l1->name, l2->name, l1->length))
7012 /* Succeed if both lists end at the same time. */
7017 reverse_token_list (tokens)
7018 struct arglist *tokens;
7020 register struct arglist *prev = 0, *this, *next;
7021 for (this = tokens; this; this = next)
7030 /* Read a space-separated list of tokens ending in a close parenthesis.
7031 Return a list of strings, in the order they were written.
7032 (In case of error, return 0 and store -1 in *ERROR_FLAG.) */
7034 static struct arglist *
7035 read_token_list (pfile, error_flag)
7039 struct arglist *token_ptrs = 0;
7044 FORWARD (1); /* Skip '(' */
7046 /* Loop over the assertion value tokens. */
7049 struct arglist *temp;
7050 long name_written = CPP_WRITTEN (pfile);
7051 int eofp = 0; int c;
7053 cpp_skip_hspace (pfile);
7057 /* Find the end of the token. */
7060 CPP_PUTC (pfile, c);
7068 CPP_PUTC (pfile, c);
7070 else if (c == '"' || c == '\'')
7073 cpp_get_token (pfile);
7079 while (c != EOF && ! is_space[c] && c != '(' && c != ')'
7080 && c != '"' && c != '\'')
7082 CPP_PUTC (pfile, c);
7085 if (c != EOF) FORWARD(-1);
7088 length = CPP_WRITTEN (pfile) - name_written;
7089 temp = (struct arglist *)
7090 xmalloc (sizeof (struct arglist) + length + 1);
7091 temp->name = (U_CHAR *) (temp + 1);
7092 bcopy ((char *) (pfile->token_buffer + name_written),
7093 (char *) temp->name, length);
7094 temp->name[length] = 0;
7095 temp->next = token_ptrs;
7097 temp->length = length;
7099 CPP_ADJUST_WRITTEN (pfile, -length); /* pop */
7101 if (c == EOF || c == '\n')
7104 "unterminated token sequence following `#' operator");
7109 /* We accumulated the names in reverse order.
7110 Now reverse them to get the proper order. */
7111 return reverse_token_list (token_ptrs);
7115 free_token_list (tokens)
7116 struct arglist *tokens;
7119 struct arglist *next = tokens->next;
7120 free (tokens->name);
7126 /* Get the file-mode and data size of the file open on FD
7127 and store them in *MODE_POINTER and *SIZE_POINTER. */
7130 file_size_and_mode (fd, mode_pointer, size_pointer)
7133 long int *size_pointer;
7137 if (fstat (fd, &sbuf) < 0) return (-1);
7138 if (mode_pointer) *mode_pointer = sbuf.st_mode;
7139 if (size_pointer) *size_pointer = sbuf.st_size;
7143 /* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
7144 retrying if necessary. Return a negative value if an error occurs,
7145 otherwise return the actual number of bytes read,
7146 which must be LEN unless end-of-file was reached. */
7149 safe_read (desc, ptr, len)
7156 int nchars = read (desc, ptr, left);
7177 unsigned size = strlen (input);
7178 char *output = xmalloc (size + 1);
7179 strcpy (output, input);
7183 /* Return the line at which an error occurred.
7184 The error is not necessarily associated with the current spot
7185 in the input stack, so LINE says where. LINE will have been
7186 copied from ip->lineno for the current input level.
7187 If the current level is for a file, we return LINE.
7188 But if the current level is not for a file, LINE is meaningless.
7189 In that case, we return the lineno of the innermost file. */
7192 line_for_error (line)
7199 for (i = indepth; i >= 0; ) {
7200 if (instack[i].fname != 0)
7205 line1 = instack[i].lineno;
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, 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, -1);
7369 cpp_message (pfile, 1, msg, arg1, arg2, arg3);
7373 cpp_warning_with_line (pfile, line, 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, -1);
7395 cpp_message (pfile, 0, msg, arg1, arg2, arg3);
7399 cpp_pedwarn_with_line (pfile, line, msg, arg1, arg2, arg3)
7403 char *arg1, *arg2, *arg3;
7405 if (CPP_OPTIONS (pfile)->pedantic_errors)
7406 cpp_error_with_line (pfile, line, msg, arg1, arg2, arg3);
7408 cpp_warning_with_line (pfile, line, 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_STERRROR */
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\n", name, my_strerror (errno));
7504 cpp_perror_with_name (pfile, name)
7508 cpp_message (pfile, 1, "%s: %s: %s\n", progname, name, my_strerror (errno));
7512 * No pre-compiled header file support.
7514 * Possibly different enum token codes for each C/C++ token.
7516 * Better error messages for non-terminated strings and comments.
7518 * Should clean up remaining directives to that do_XXX functions
7519 * only take two arguments and all have command_reads_line.
7521 * Find and cleanup remaining uses of static variables,
7523 * Support for trigraphs.
7525 * Support -dM flag (dump_all_macros).
7527 * -include should be made to return results incrementally.
7528 * (current implementation only works when cpp is used as main program)