2 Copyright (C) 1986, 87, 89, 92-5, 1996 Free Software Foundation, Inc.
3 Written by Per Bothner, 1994-95.
4 Based on CCCP program by by Paul Rubin, June 1986
5 Adapted to ANSI C, Richard Stallman, Jan 1987
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 In other words, you are welcome to use, share and improve this program.
22 You are forbidden to forbid anyone else to use, share and improve
23 what you give them. Help stamp out software-hoarding! */
27 #include "../src/config.h"
35 /* The macro EMACS is defined when cpp is distributed as part of Emacs,
36 for the sake of machines with limited C compilers. */
39 #endif /* not EMACS */
41 #ifndef STANDARD_INCLUDE_DIR
42 #define STANDARD_INCLUDE_DIR "/usr/include"
45 #ifndef LOCAL_INCLUDE_DIR
46 #define LOCAL_INCLUDE_DIR "/usr/local/include"
49 #if 0 /* We can't get ptrdiff_t, so I arranged not to need PTR_INT_TYPE. */
51 #define PTR_INT_TYPE ptrdiff_t
53 #define PTR_INT_TYPE long
64 /* By default, colon separates directories in a path. */
65 #ifndef PATH_SEPARATOR
66 #define PATH_SEPARATOR ':'
78 #include <sys/time.h> /* for __DATE__ and __TIME__ */
79 #include <sys/resource.h>
81 #include <sys/times.h>
87 /* This defines "errno" properly for VMS, and gives us EACCES. */
90 extern char *index ();
91 extern char *rindex ();
99 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
100 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
102 /* Find the largest host integer type and set its size and type. */
104 #ifndef HOST_BITS_PER_WIDE_INT
106 #if HOST_BITS_PER_LONG > HOST_BITS_PER_INT
107 #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG
108 #define HOST_WIDE_INT long
110 #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT
111 #define HOST_WIDE_INT int
117 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
121 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
124 /* Define a generic NULL if one hasn't already been defined. */
131 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
132 #define GENERIC_PTR void *
134 #define GENERIC_PTR char *
139 #define NULL_PTR ((GENERIC_PTR) 0)
142 #ifndef INCLUDE_LEN_FUDGE
143 #define INCLUDE_LEN_FUDGE 0
146 /* Symbols to predefine. */
148 #ifdef CPP_PREDEFINES
149 static char *predefs = CPP_PREDEFINES;
151 static char *predefs = "";
154 /* We let tm.h override the types used here, to handle trivial differences
155 such as the choice of unsigned int or long unsigned int for size_t.
156 When machines start needing nontrivial differences in the size type,
157 it would be best to do something here to figure out automatically
158 from other information what type to use. */
160 /* The string value for __SIZE_TYPE__. */
163 #define SIZE_TYPE "long unsigned int"
166 /* The string value for __PTRDIFF_TYPE__. */
169 #define PTRDIFF_TYPE "long int"
172 /* The string value for __WCHAR_TYPE__. */
175 #define WCHAR_TYPE "int"
177 #define CPP_WCHAR_TYPE(PFILE) \
178 (CPP_OPTIONS (PFILE)->cplusplus ? "__wchar_t" : WCHAR_TYPE)
180 /* The string value for __USER_LABEL_PREFIX__ */
182 #ifndef USER_LABEL_PREFIX
183 #define USER_LABEL_PREFIX ""
186 /* The string value for __REGISTER_PREFIX__ */
188 #ifndef REGISTER_PREFIX
189 #define REGISTER_PREFIX ""
192 /* In the definition of a #assert name, this structure forms
193 a list of the individual values asserted.
194 Each value is itself a list of "tokens".
195 These are strings that are compared by name. */
197 struct tokenlist_list {
198 struct tokenlist_list *next;
199 struct arglist *tokens;
202 struct assertion_hashnode {
203 struct assertion_hashnode *next; /* double links for easy deletion */
204 struct assertion_hashnode *prev;
205 /* also, a back pointer to this node's hash
206 chain is kept, in case the node is the head
207 of the chain and gets deleted. */
208 struct assertion_hashnode **bucket_hdr;
209 int length; /* length of token, for quick comparison */
210 U_CHAR *name; /* the actual name */
211 /* List of token-sequences. */
212 struct tokenlist_list *value;
215 #define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
216 #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
218 #define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? CPP_BUFFER (pfile)->cur[N] : EOF)
219 #define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N))
220 #define GETC() CPP_BUF_GET (CPP_BUFFER (pfile))
221 #define PEEKC() CPP_BUF_PEEK (CPP_BUFFER (pfile))
222 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
223 (Note that it is false while we're expanding marco *arguments*.) */
224 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->cleanup == macro_cleanup)
226 /* Move all backslash-newline pairs out of embarrassing places.
227 Exchange all such pairs following BP
228 with any potentially-embarrassing characters that follow them.
229 Potentially-embarrassing characters are / and *
230 (because a backslash-newline inside a comment delimiter
231 would cause it not to be recognized). */
233 #define NEWLINE_FIX \
234 do {while (PEEKC() == '\\' && PEEKN(1) == '\n') FORWARD(2); } while(0)
236 /* Same, but assume we've already read the potential '\\' into C. */
237 #define NEWLINE_FIX1(C) do { \
238 while ((C) == '\\' && PEEKC() == '\n') { FORWARD(1); (C) = GETC(); }\
242 struct cpp_pending *next;
247 /* Forward declarations. */
249 extern char *xmalloc ();
251 static void add_import ();
252 static void append_include_chain ();
253 static void make_undef ();
254 static void make_assertion ();
255 static void path_include ();
256 static void initialize_builtins ();
257 static void initialize_char_syntax ();
258 static void dump_arg_n ();
259 static void dump_defn_1 ();
260 extern void delete_macro ();
261 static void trigraph_pcp ();
262 static int finclude ();
263 static void validate_else ();
264 static int comp_def_part ();
266 extern void fancy_abort ();
268 static void pipe_closed ();
269 static void print_containing_files ();
270 static int lookup_import ();
271 static int redundant_include_p ();
272 static is_system_include ();
273 static struct file_name_map *read_name_map ();
274 static char *read_filename_string ();
275 static int open_include_file ();
276 static int check_preconditions ();
277 static void pcfinclude ();
278 static void pcstring_used ();
279 static int check_macro_name ();
280 static int compare_defs ();
281 static int compare_token_lists ();
282 static HOST_WIDE_INT eval_if_expression ();
283 static int change_newlines ();
285 static int file_size_and_mode ();
286 static struct arglist *read_token_list ();
287 static void free_token_list ();
288 static int safe_read ();
289 static void push_macro_expansion PARAMS ((cpp_reader *,
290 U_CHAR *, int, HASHNODE *));
291 static struct cpp_pending *nreverse_pending PARAMS ((struct cpp_pending *));
292 extern char *xrealloc ();
293 static char *xcalloc ();
294 static char *savestring ();
296 static void conditional_skip ();
297 static void skip_if_group ();
299 /* Last arg to output_line_command. */
300 enum file_change_code {same_file, enter_file, leave_file};
302 /* External declarations. */
304 extern HOST_WIDE_INT cpp_parse_expr PARAMS ((cpp_reader *));
306 extern char *getenv ();
307 extern FILE *fdopen ();
308 extern char *version_string;
309 extern struct tm *localtime ();
311 /* These functions are declared to return int instead of void since they
312 are going to be placed in a table and some old compilers have trouble with
313 pointers to functions returning void. */
315 static int do_define ();
316 static int do_line ();
317 static int do_include ();
318 static int do_undef ();
319 static int do_error ();
320 static int do_pragma ();
321 static int do_ident ();
323 static int do_xifdef ();
324 static int do_else ();
325 static int do_elif ();
326 static int do_endif ();
327 static int do_sccs ();
328 static int do_once ();
329 static int do_assert ();
330 static int do_unassert ();
331 static int do_warning ();
333 struct file_name_list
335 struct file_name_list *next;
337 /* If the following is nonzero, it is a macro name.
338 Don't include the file again if that macro is defined. */
339 U_CHAR *control_macro;
340 /* If the following is nonzero, it is a C-language system include
342 int c_system_include_path;
343 /* Mapping of file names for this directory. */
344 struct file_name_map *name_map;
345 /* Non-zero if name_map is valid. */
349 /* If a buffer's dir field is SELF_DIR_DUMMY, it means the file was found
350 via the same directory as the file that #included it. */
351 #define SELF_DIR_DUMMY ((struct file_name_list *) (~0))
353 /* #include "file" looks in source file dir, then stack. */
354 /* #include <file> just looks in the stack. */
355 /* -I directories are added to the end, then the defaults are added. */
357 static struct default_include {
358 char *fname; /* The name of the directory. */
359 int cplusplus; /* Only look here if we're compiling C++. */
360 int cxx_aware; /* Includes in this directory don't need to
361 be wrapped in extern "C" when compiling
363 } include_defaults_array[]
364 #ifdef INCLUDE_DEFAULTS
368 /* Pick up GNU C++ specific include files. */
369 { GPLUSPLUS_INCLUDE_DIR, 1, 1 },
370 { OLD_GPLUSPLUS_INCLUDE_DIR, 1, 1 },
372 /* This is the dir for fixincludes. Put it just before
373 the files that we fix. */
374 { GCC_INCLUDE_DIR, 0, 0 },
375 /* For cross-compilation, this dir name is generated
376 automatically in Makefile.in. */
377 { CROSS_INCLUDE_DIR, 0, 0 },
378 /* This is another place that the target system's headers might be. */
379 { TOOL_INCLUDE_DIR, 0, 1 },
380 #else /* not CROSS_COMPILE */
381 /* This should be /usr/local/include and should come before
382 the fixincludes-fixed header files. */
383 { LOCAL_INCLUDE_DIR, 0, 1 },
384 /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
385 Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
386 { TOOL_INCLUDE_DIR, 0, 1 },
387 /* This is the dir for fixincludes. Put it just before
388 the files that we fix. */
389 { GCC_INCLUDE_DIR, 0, 0 },
390 /* Some systems have an extra dir of include files. */
391 #ifdef SYSTEM_INCLUDE_DIR
392 { SYSTEM_INCLUDE_DIR, 0, 0 },
394 { STANDARD_INCLUDE_DIR, 0, 0 },
395 #endif /* not CROSS_COMPILE */
398 #endif /* no INCLUDE_DEFAULTS */
400 /* `struct directive' defines one #-directive, including how to handle it. */
403 int length; /* Length of name */
404 int (*func)(); /* Function to handle directive */
405 char *name; /* Name of directive */
406 enum node_type type; /* Code which describes which directive. */
407 char command_reads_line; /* One if rest of line is read by func. */
408 char traditional_comments; /* Nonzero: keep comments if -traditional. */
409 char pass_thru; /* Copy preprocessed directive to output file.*/
412 /* Here is the actual list of #-directives, most-often-used first.
413 The initialize_builtins function assumes #define is the very first. */
415 static struct directive directive_table[] = {
416 { 6, do_define, "define", T_DEFINE, 0, 1},
417 { 5, do_xifdef, "ifdef", T_IFDEF, 1},
418 { 6, do_xifdef, "ifndef", T_IFNDEF, 1},
419 { 7, do_include, "include", T_INCLUDE, 1},
420 { 12, do_include, "include_next", T_INCLUDE_NEXT, 1},
421 { 6, do_include, "import", T_IMPORT, 1},
422 { 5, do_endif, "endif", T_ENDIF, 1},
423 { 4, do_else, "else", T_ELSE, 1},
424 { 2, do_if, "if", T_IF, 1},
425 { 4, do_elif, "elif", T_ELIF, 1},
426 { 5, do_undef, "undef", T_UNDEF},
427 { 5, do_error, "error", T_ERROR},
428 { 7, do_warning, "warning", T_WARNING},
429 { 6, do_pragma, "pragma", T_PRAGMA, 0, 0, 1},
430 { 4, do_line, "line", T_LINE, 1},
431 { 5, do_ident, "ident", T_IDENT, 1, 0, 1},
432 #ifdef SCCS_DIRECTIVE
433 { 4, do_sccs, "sccs", T_SCCS},
435 { 6, do_assert, "assert", T_ASSERT, 1},
436 { 8, do_unassert, "unassert", T_UNASSERT, 1},
437 { -1, 0, "", T_UNUSED},
440 /* table to tell if char can be part of a C identifier. */
441 U_CHAR is_idchar[256];
442 /* table to tell if char can be first char of a c identifier. */
443 U_CHAR is_idstart[256];
444 /* table to tell if c is horizontal space. */
445 U_CHAR is_hor_space[256];
446 /* table to tell if c is horizontal or vertical space. */
447 static U_CHAR is_space[256];
449 /* Initialize syntactic classifications of characters. */
452 initialize_char_syntax (opts)
453 struct cpp_options *opts;
458 * Set up is_idchar and is_idstart tables. These should be
459 * faster than saying (is_alpha (c) || c == '_'), etc.
460 * Set up these things before calling any routines tthat
463 for (i = 'a'; i <= 'z'; i++) {
464 is_idchar[i - 'a' + 'A'] = 1;
466 is_idstart[i - 'a' + 'A'] = 1;
469 for (i = '0'; i <= '9'; i++)
473 is_idchar['$'] = opts->dollars_in_ident;
474 is_idstart['$'] = opts->dollars_in_ident;
476 /* horizontal space table */
477 is_hor_space[' '] = 1;
478 is_hor_space['\t'] = 1;
479 is_hor_space['\v'] = 1;
480 is_hor_space['\f'] = 1;
481 is_hor_space['\r'] = 1;
492 /* Place into PFILE a quoted string representing the string SRC.
493 Caller must reserve enough space in pfile->token_buffer. */
496 quote_string (pfile, src)
502 CPP_PUTC_Q (pfile, '\"');
504 switch ((c = *src++))
508 CPP_PUTC_Q (pfile, c);
511 sprintf (CPP_PWRITTEN (pfile), "\\%03o", c);
512 CPP_ADJUST_WRITTEN (pfile, 4);
518 CPP_PUTC_Q (pfile, '\\');
519 CPP_PUTC_Q (pfile, c);
523 CPP_PUTC_Q (pfile, '\"');
524 CPP_NUL_TERMINATE_Q (pfile);
529 /* Re-allocates PFILE->token_buffer so it will hold at least N more chars. */
532 cpp_grow_buffer (pfile, n)
536 long old_written = CPP_WRITTEN (pfile);
537 pfile->token_buffer_size = n + 2 * pfile->token_buffer_size;
538 pfile->token_buffer = (U_CHAR *)
539 xrealloc(pfile->token_buffer, pfile->token_buffer_size);
540 CPP_SET_WRITTEN (pfile, old_written);
545 * process a given definition string, for initialization
546 * If STR is just an identifier, define it with value 1.
547 * If STR has anything after the identifier, then it should
548 * be identifier=definition.
552 cpp_define (pfile, str)
562 cpp_error (pfile, "malformed option `-D %s'", str);
565 while (is_idchar[*++p])
569 buf = (U_CHAR *) alloca (p - buf + 4);
570 strcpy ((char *)buf, str);
571 strcat ((char *)buf, " 1");
575 cpp_error (pfile, "malformed option `-D %s'", str);
581 /* Copy the entire option so we can modify it. */
582 buf = (U_CHAR *) alloca (2 * strlen (str) + 1);
583 strncpy (buf, str, p - str);
584 /* Change the = to a space. */
586 /* Scan for any backslash-newline and remove it. */
591 if (*p == '\\' && p[1] == '\n')
599 do_define (pfile, NULL, buf, buf + strlen (buf));
602 /* Process the string STR as if it appeared as the body of a #assert.
603 OPTION is the option name for which STR was the argument. */
606 make_assertion (pfile, option, str)
611 struct directive *kt;
614 /* Copy the entire option so we can modify it. */
615 buf = (U_CHAR *) alloca (strlen (str) + 1);
616 strcpy ((char *) buf, str);
617 /* Scan for any backslash-newline and remove it. */
621 if (*p == '\\' && p[1] == '\n')
630 if (!is_idstart[*p]) {
631 cpp_error (pfile, "malformed option `%s %s'", option, str);
634 while (is_idchar[*++p])
636 while (*p == ' ' || *p == '\t') p++;
637 if (! (*p == 0 || *p == '(')) {
638 cpp_error (pfile, "malformed option `%s %s'", option, str);
642 if (cpp_push_buffer (pfile, buf, strlen (buf)) != NULL)
644 do_assert (pfile, NULL, NULL, NULL);
645 cpp_pop_buffer (pfile);
649 /* Append a chain of `struct file_name_list's
650 to the end of the main include chain.
651 FIRST is the beginning of the chain to append, and LAST is the end. */
654 append_include_chain (pfile, first, last)
656 struct file_name_list *first, *last;
658 struct cpp_options *opts = CPP_OPTIONS (pfile);
659 struct file_name_list *dir;
664 if (opts->include == 0)
665 opts->include = first;
667 opts->last_include->next = first;
669 if (opts->first_bracket_include == 0)
670 opts->first_bracket_include = first;
672 for (dir = first; ; dir = dir->next) {
673 int len = strlen (dir->fname) + INCLUDE_LEN_FUDGE;
674 if (len > pfile->max_include_len)
675 pfile->max_include_len = len;
681 opts->last_include = last;
684 /* Add output to `deps_buffer' for the -M switch.
685 STRING points to the text to be output.
686 SPACER is ':' for targets, ' ' for dependencies, zero for text
687 to be inserted literally. */
690 deps_output (pfile, string, spacer)
695 int size = strlen (string);
700 #ifndef MAX_OUTPUT_COLUMNS
701 #define MAX_OUTPUT_COLUMNS 72
704 && pfile->deps_column > 0
705 && (pfile->deps_column + size) > MAX_OUTPUT_COLUMNS)
707 deps_output (pfile, " \\\n ", 0);
708 pfile->deps_column = 0;
711 if (pfile->deps_size + size + 8 > pfile->deps_allocated_size)
713 pfile->deps_allocated_size = (pfile->deps_size + size + 50) * 2;
714 pfile->deps_buffer = (char *) xrealloc (pfile->deps_buffer,
715 pfile->deps_allocated_size);
717 if (spacer == ' ' && pfile->deps_column > 0)
718 pfile->deps_buffer[pfile->deps_size++] = ' ';
719 bcopy (string, &pfile->deps_buffer[pfile->deps_size], size);
720 pfile->deps_size += size;
721 pfile->deps_column += size;
723 pfile->deps_buffer[pfile->deps_size++] = ':';
724 pfile->deps_buffer[pfile->deps_size] = 0;
727 /* Given a colon-separated list of file names PATH,
728 add all the names to the search path for include files. */
731 path_include (pfile, path)
743 struct file_name_list *dirtmp;
745 /* Find the end of this name. */
746 while (*q != 0 && *q != PATH_SEPARATOR) q++;
748 /* An empty name in the path stands for the current directory. */
749 name = (char *) xmalloc (2);
753 /* Otherwise use the directory that is named. */
754 name = (char *) xmalloc (q - p + 1);
755 bcopy (p, name, q - p);
759 dirtmp = (struct file_name_list *)
760 xmalloc (sizeof (struct file_name_list));
761 dirtmp->next = 0; /* New one goes on the end */
762 dirtmp->control_macro = 0;
763 dirtmp->c_system_include_path = 0;
764 dirtmp->fname = name;
765 dirtmp->got_name_map = 0;
766 append_include_chain (pfile, dirtmp, dirtmp);
768 /* Advance past this name. */
772 /* Skip the colon. */
778 cpp_options_init (opts)
781 bzero ((char *) opts, sizeof *opts);
782 opts->in_fname = NULL;
783 opts->out_fname = NULL;
785 /* Initialize is_idchar to allow $. */
786 opts->dollars_in_ident = 1;
787 initialize_char_syntax (opts);
789 opts->no_line_commands = 0;
790 opts->no_trigraphs = 1;
791 opts->put_out_comments = 0;
792 opts->print_include_names = 0;
793 opts->dump_macros = dump_none;
796 opts->cplusplus_comments = 0;
803 opts->pedantic_errors = 0;
804 opts->inhibit_warnings = 0;
805 opts->warn_comments = 0;
806 opts->warn_import = 1;
807 opts->warnings_are_errors = 0;
811 null_underflow (pfile)
818 null_cleanup (pbuf, pfile)
826 macro_cleanup (pbuf, pfile)
830 HASHNODE *macro = (HASHNODE *) pbuf->data;
831 if (macro->type == T_DISABLED)
832 macro->type = T_MACRO;
833 if (macro->type != T_MACRO || pbuf->buf != macro->value.defn->expansion)
839 file_cleanup (pbuf, pfile)
851 /* Assuming we have read '/'.
852 If this is the start of a comment (followed by '*' or '/'),
853 skip to the end of the comment, and return ' '.
854 Return EOF if we reached the end of file before the end of the comment.
855 If not the start of a comment, return '/'. */
858 skip_comment (pfile, linep)
863 while (PEEKC() == '\\' && PEEKN(1) == '\n')
878 while (c == '\\' && PEEKC() == '\n')
882 FORWARD(1), c = GETC();
884 if (prev_c == '*' && c == '/')
886 if (c == '\n' && linep)
890 else if (PEEKC() == '/' && CPP_OPTIONS (pfile)->cplusplus_comments)
897 return ' '; /* Allow // to be terminated by EOF. */
898 while (c == '\\' && PEEKC() == '\n')
907 /* Don't consider final '\n' to be part of comment. */
917 /* Skip whitespace \-newline and comments. Does not macro-expand. */
920 cpp_skip_hspace (pfile)
930 if ((c == '\f' || c == '\v') && CPP_PEDANTIC (pfile))
931 cpp_pedwarn (pfile, "%s in preprocessing directive",
932 c == '\f' ? "formfeed" : "vertical tab");
938 c = skip_comment (pfile, NULL);
941 if (c == EOF || c == '/')
944 else if (c == '\\' && PEEKN(1) == '\n') {
947 else if (c == '@' && CPP_BUFFER (pfile)->has_escapes
948 && is_hor_space[PEEKN(1)])
954 /* Read the rest of the current line.
955 The line is appended to PFILE's output buffer. */
958 copy_rest_of_line (pfile)
961 struct cpp_options *opts = CPP_OPTIONS (pfile);
978 goto scan_directive_token;
982 if (nextc == '*' || (opts->cplusplus_comments && nextc == '*'))
983 goto scan_directive_token;
987 if (CPP_PEDANTIC (pfile))
988 cpp_pedwarn (pfile, "%s in preprocessing directive",
989 c == '\f' ? "formfeed" : "vertical tab");
995 scan_directive_token:
997 cpp_get_token (pfile);
1000 CPP_PUTC (pfile, c);
1003 CPP_NUL_TERMINATE (pfile);
1007 skip_rest_of_line (pfile)
1010 long old = CPP_WRITTEN (pfile);
1011 copy_rest_of_line (pfile);
1012 CPP_SET_WRITTEN (pfile, old);
1015 /* Handle a possible # directive.
1016 '#' has already been read. */
1019 handle_directive (pfile)
1022 register struct directive *kt;
1025 U_CHAR *ident, *line_end;
1026 long old_written = CPP_WRITTEN (pfile);
1028 cpp_skip_hspace (pfile);
1031 if (c >= '0' && c <= '9')
1033 /* Handle # followed by a line number. */
1034 if (CPP_PEDANTIC (pfile))
1035 cpp_pedwarn (pfile, "`#' followed by integer");
1036 do_line (pfile, NULL);
1037 goto done_a_directive;
1040 /* Now find the directive name. */
1041 CPP_PUTC (pfile, '#');
1042 parse_name (pfile, GETC());
1043 ident = pfile->token_buffer + old_written + 1;
1044 ident_length = CPP_PWRITTEN (pfile) - ident;
1045 if (ident_length == 0 && PEEKC() == '\n')
1047 /* A line of just `#' becomes blank. */
1048 goto done_a_directive;
1052 if (ident_length == 0 || !is_idstart[*ident]) {
1054 while (is_idchar[*p]) {
1055 if (*p < '0' || *p > '9')
1059 /* Avoid error for `###' and similar cases unless -pedantic. */
1061 while (*p == '#' || is_hor_space[*p]) p++;
1063 if (pedantic && !lang_asm)
1064 cpp_warning (pfile, "invalid preprocessor directive");
1070 cpp_error (pfile, "invalid preprocessor directive name");
1076 * Decode the keyword and call the appropriate expansion
1077 * routine, after moving the input pointer up to the next line.
1079 for (kt = directive_table; ; kt++) {
1080 if (kt->length <= 0)
1081 goto not_a_directive;
1082 if (kt->length == ident_length && !strncmp (kt->name, ident, ident_length))
1086 if (kt->command_reads_line)
1090 /* Nonzero means do not delete comments within the directive.
1091 #define needs this when -traditional. */
1092 int comments = CPP_TRADITIONAL (pfile) && kt->traditional_comments;
1093 int save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
1094 CPP_OPTIONS (pfile)->put_out_comments = comments;
1095 after_ident = CPP_WRITTEN (pfile);
1096 copy_rest_of_line (pfile);
1097 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
1100 /* For #pragma and #define, we may want to pass through the directive.
1101 Other directives may create output, but we don't want the directive
1102 itself out, so we pop it now. For example #include may write a #line
1103 command (see comment in do_include), and conditionals may emit
1104 #failed ... #endfailed stuff. But note that popping the buffer
1105 means the parameters to kt->func may point after pfile->limit
1106 so these parameters are invalid as soon as something gets appended
1107 to the token_buffer. */
1109 line_end = CPP_PWRITTEN (pfile);
1110 if (!kt->pass_thru && kt->type != T_DEFINE)
1111 CPP_SET_WRITTEN (pfile, old_written);
1113 (*kt->func) (pfile, kt, pfile->token_buffer + after_ident, line_end);
1115 || (kt->type == T_DEFINE
1116 && CPP_OPTIONS (pfile)->dump_macros == dump_definitions))
1118 /* Just leave the entire #define in the output stack. */
1120 else if (kt->type == T_DEFINE
1121 && CPP_OPTIONS (pfile)->dump_macros == dump_names)
1123 U_CHAR *p = pfile->token_buffer + old_written + 7; /* Skip "#define". */
1124 SKIP_WHITE_SPACE (p);
1125 while (is_idchar[*p]) p++;
1127 CPP_PUTC (pfile, '\n');
1129 else if (kt->type == T_DEFINE)
1130 CPP_SET_WRITTEN (pfile, old_written);
1138 /* Pass a directive through to the output file.
1139 BUF points to the contents of the directive, as a contiguous string.
1140 LIMIT points to the first character past the end of the directive.
1141 KEYWORD is the keyword-table entry for the directive. */
1144 pass_thru_directive (buf, limit, pfile, keyword)
1145 U_CHAR *buf, *limit;
1147 struct directive *keyword;
1149 register unsigned keyword_length = keyword->length;
1151 CPP_RESERVE (pfile, 1 + keyword_length + (limit - buf));
1152 CPP_PUTC_Q (pfile, '#');
1153 CPP_PUTS_Q (pfile, keyword->name, keyword_length);
1154 if (limit != buf && buf[0] != ' ')
1155 CPP_PUTC_Q (pfile, ' ');
1156 CPP_PUTS_Q (pfile, buf, limit - buf);
1158 CPP_PUTS_Q (pfile, '\n');
1159 /* Count the line we have just made in the output,
1160 to get in sync properly. */
1165 /* The arglist structure is built by do_define to tell
1166 collect_definition where the argument names begin. That
1167 is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist
1168 would contain pointers to the strings x, y, and z.
1169 Collect_definition would then build a DEFINITION node,
1170 with reflist nodes pointing to the places x, y, and z had
1171 appeared. So the arglist is just convenience data passed
1172 between these two routines. It is not kept around after
1173 the current #define has been processed and entered into the
1177 struct arglist *next;
1184 /* Read a replacement list for a macro with parameters.
1185 Build the DEFINITION structure.
1186 Reads characters of text starting at BUF until END.
1187 ARGLIST specifies the formal parameters to look for
1188 in the text of the definition; NARGS is the number of args
1189 in that list, or -1 for a macro name that wants no argument list.
1190 MACRONAME is the macro name itself (so we can avoid recursive expansion)
1191 and NAMELEN is its length in characters.
1193 Note that comments, backslash-newlines, and leading white space
1194 have already been deleted from the argument. */
1197 collect_expansion (pfile, buf, limit, nargs, arglist)
1199 U_CHAR *buf, *limit;
1201 struct arglist *arglist;
1204 register U_CHAR *p, *lastp, *exp_p;
1205 struct reflist *endpat = NULL;
1206 /* Pointer to first nonspace after last ## seen. */
1208 /* Pointer to first nonspace after last single-# seen. */
1209 U_CHAR *stringify = 0;
1211 int expected_delimiter = '\0';
1213 /* Scan thru the replacement list, ignoring comments and quoted
1214 strings, picking up on the macro calls. It does a linear search
1215 thru the arg list on every potential symbol. Profiling might say
1216 that something smarter should happen. */
1221 /* Find the beginning of the trailing whitespace. */
1223 while (p < limit && is_space[limit[-1]]) limit--;
1225 /* Allocate space for the text in the macro definition.
1226 Leading and trailing whitespace chars need 2 bytes each.
1227 Each other input char may or may not need 1 byte,
1228 so this is an upper bound. The extra 5 are for invented
1229 leading and trailing newline-marker and final null. */
1230 maxsize = (sizeof (DEFINITION)
1232 /* Occurrences of '@' get doubled, so allocate extra space for them. */
1236 defn = (DEFINITION *) xcalloc (1, maxsize);
1238 defn->nargs = nargs;
1239 exp_p = defn->expansion = (U_CHAR *) defn + sizeof (DEFINITION);
1244 /* Add one initial space escape-marker to prevent accidental
1245 token-pasting (often removed by macroexpand). */
1249 if (limit - p >= 2 && p[0] == '#' && p[1] == '#') {
1250 cpp_error (pfile, "`##' at start of macro definition");
1254 /* Process the main body of the definition. */
1256 int skipped_arg = 0;
1257 register U_CHAR c = *p++;
1261 if (!CPP_TRADITIONAL (pfile)) {
1265 if (expected_delimiter != '\0') {
1266 if (c == expected_delimiter)
1267 expected_delimiter = '\0';
1269 expected_delimiter = c;
1273 if (p < limit && expected_delimiter) {
1274 /* In a string, backslash goes through
1275 and makes next char ordinary. */
1281 /* An '@' in a string or character constant stands for itself,
1282 and does not need to be escaped. */
1283 if (!expected_delimiter)
1288 /* # is ordinary inside a string. */
1289 if (expected_delimiter)
1291 if (p < limit && *p == '#') {
1292 /* ##: concatenate preceding and following tokens. */
1293 /* Take out the first #, discard preceding whitespace. */
1295 while (exp_p > lastp && is_hor_space[exp_p[-1]])
1297 /* Skip the second #. */
1299 /* Discard following whitespace. */
1300 SKIP_WHITE_SPACE (p);
1303 cpp_error (pfile, "`##' at end of macro definition");
1304 } else if (nargs >= 0) {
1305 /* Single #: stringify following argument ref.
1306 Don't leave the # in the expansion. */
1308 SKIP_WHITE_SPACE (p);
1309 if (p == limit || ! is_idstart[*p])
1311 "`#' operator is not followed by a macro argument name");
1318 /* In -traditional mode, recognize arguments inside strings and
1319 and character constants, and ignore special properties of #.
1320 Arguments inside strings are considered "stringified", but no
1321 extra quote marks are supplied. */
1325 if (expected_delimiter != '\0') {
1326 if (c == expected_delimiter)
1327 expected_delimiter = '\0';
1329 expected_delimiter = c;
1333 /* Backslash quotes delimiters and itself, but not macro args. */
1334 if (expected_delimiter != 0 && p < limit
1335 && (*p == expected_delimiter || *p == '\\')) {
1342 if (expected_delimiter != '\0') /* No comments inside strings. */
1345 /* If we find a comment that wasn't removed by handle_directive,
1346 this must be -traditional. So replace the comment with
1350 while (p < limit && !(p[-2] == '*' && p[-1] == '/'))
1353 /* Mark this as a concatenation-point, as if it had been ##. */
1361 /* Handle the start of a symbol. */
1362 if (is_idchar[c] && nargs > 0) {
1363 U_CHAR *id_beg = p - 1;
1367 while (p != limit && is_idchar[*p]) p++;
1368 id_len = p - id_beg;
1370 if (is_idstart[c]) {
1371 register struct arglist *arg;
1373 for (arg = arglist; arg != NULL; arg = arg->next) {
1374 struct reflist *tpat;
1376 if (arg->name[0] == c
1377 && arg->length == id_len
1378 && strncmp (arg->name, id_beg, id_len) == 0) {
1379 if (expected_delimiter && CPP_OPTIONS (pfile)->warn_stringify) {
1380 if (CPP_TRADITIONAL (pfile)) {
1381 cpp_warning (pfile, "macro argument `%.*s' is stringified.",
1385 "macro arg `%.*s' would be stringified with -traditional.",
1389 /* If ANSI, don't actually substitute inside a string. */
1390 if (!CPP_TRADITIONAL (pfile) && expected_delimiter)
1392 /* make a pat node for this arg and append it to the end of
1394 tpat = (struct reflist *) xmalloc (sizeof (struct reflist));
1396 tpat->raw_before = concat == id_beg;
1397 tpat->raw_after = 0;
1398 tpat->rest_args = arg->rest_args;
1399 tpat->stringify = (CPP_TRADITIONAL (pfile)
1400 ? expected_delimiter != '\0'
1401 : stringify == id_beg);
1404 defn->pattern = tpat;
1406 endpat->next = tpat;
1409 tpat->argno = arg->argno;
1410 tpat->nchars = exp_p - lastp;
1412 register U_CHAR *p1 = p;
1413 SKIP_WHITE_SPACE (p1);
1414 if (p1 + 2 <= limit && p1[0] == '#' && p1[1] == '#')
1415 tpat->raw_after = 1;
1417 lastp = exp_p; /* place to start copying from next time */
1424 /* If this was not a macro arg, copy it into the expansion. */
1425 if (! skipped_arg) {
1426 register U_CHAR *lim1 = p;
1430 if (stringify == id_beg)
1432 "`#' operator should be followed by a macro argument name");
1437 if (!CPP_TRADITIONAL (pfile) && expected_delimiter == 0)
1439 /* If ANSI, put in a "@ " marker to prevent token pasting.
1440 But not if "inside a string" (which in ANSI mode
1441 happens only for -D option). */
1448 defn->length = exp_p - defn->expansion;
1450 /* Crash now if we overrun the allocated size. */
1451 if (defn->length + 1 > maxsize)
1455 /* This isn't worth the time it takes. */
1456 /* give back excess storage */
1457 defn->expansion = (U_CHAR *) xrealloc (defn->expansion, defn->length + 1);
1464 * special extension string that can be added to the last macro argument to
1465 * allow it to absorb the "rest" of the arguments when expanded. Ex:
1466 * #define wow(a, b...) process (b, a, b)
1467 * { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); }
1468 * { wow (one, two); } -> { process (two, one, two); }
1469 * if this "rest_arg" is used with the concat token '##' and if it is not
1470 * supplied then the token attached to with ## will not be outputted. Ex:
1471 * #define wow (a, b...) process (b ## , a, ## b)
1472 * { wow (1, 2); } -> { process (2, 1, 2); }
1473 * { wow (one); } -> { process (one); {
1475 static char rest_extension[] = "...";
1476 #define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1)
1478 /* Create a DEFINITION node from a #define directive. Arguments are
1479 as for do_define. */
1482 create_definition (buf, limit, pfile, predefinition)
1483 U_CHAR *buf, *limit;
1487 U_CHAR *bp; /* temp ptr into input buffer */
1488 U_CHAR *symname; /* remember where symbol name starts */
1489 int sym_length; /* and how long it is */
1492 char *file = CPP_BUFFER (pfile) ? CPP_BUFFER (pfile)->nominal_fname : "";
1494 int arglengths = 0; /* Accumulate lengths of arg names
1495 plus number of args. */
1497 cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col);
1501 while (is_hor_space[*bp])
1504 symname = bp; /* remember where it starts */
1506 sym_length = check_macro_name (pfile, bp, "macro");
1509 /* Lossage will occur if identifiers or control keywords are broken
1510 across lines using backslash. This is not the right place to take
1514 struct arglist *arg_ptrs = NULL;
1517 bp++; /* skip '(' */
1518 SKIP_WHITE_SPACE (bp);
1520 /* Loop over macro argument names. */
1521 while (*bp != ')') {
1522 struct arglist *temp;
1524 temp = (struct arglist *) alloca (sizeof (struct arglist));
1526 temp->next = arg_ptrs;
1527 temp->argno = argno++;
1528 temp->rest_args = 0;
1532 cpp_pedwarn (pfile, "another parameter follows `%s'", rest_extension);
1534 if (!is_idstart[*bp])
1535 cpp_pedwarn (pfile, "invalid character in macro parameter name");
1537 /* Find the end of the arg name. */
1538 while (is_idchar[*bp]) {
1540 /* do we have a "special" rest-args extension here? */
1541 if (limit - bp > REST_EXTENSION_LENGTH &&
1542 strncmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
1544 temp->rest_args = 1;
1548 temp->length = bp - temp->name;
1550 bp += REST_EXTENSION_LENGTH;
1551 arglengths += temp->length + 2;
1552 SKIP_WHITE_SPACE (bp);
1553 if (temp->length == 0 || (*bp != ',' && *bp != ')')) {
1554 cpp_error (pfile, "badly punctuated parameter list in `#define'");
1559 SKIP_WHITE_SPACE (bp);
1562 cpp_error (pfile, "unterminated parameter list in `#define'");
1566 struct arglist *otemp;
1568 for (otemp = temp->next; otemp != NULL; otemp = otemp->next)
1569 if (temp->length == otemp->length &&
1570 strncmp (temp->name, otemp->name, temp->length) == 0) {
1573 name = (U_CHAR *) alloca (temp->length + 1);
1574 (void) strncpy (name, temp->name, temp->length);
1575 name[temp->length] = '\0';
1577 "duplicate argument name `%s' in `#define'", name);
1583 ++bp; /* skip paren */
1584 SKIP_WHITE_SPACE (bp);
1585 /* now everything from bp before limit is the definition. */
1586 defn = collect_expansion (pfile, bp, limit, argno, arg_ptrs);
1587 defn->rest_args = rest_args;
1589 /* Now set defn->args.argnames to the result of concatenating
1590 the argument names in reverse order
1591 with comma-space between them. */
1592 defn->args.argnames = (U_CHAR *) xmalloc (arglengths + 1);
1594 struct arglist *temp;
1596 for (temp = arg_ptrs; temp; temp = temp->next) {
1597 bcopy (temp->name, &defn->args.argnames[i], temp->length);
1599 if (temp->next != 0) {
1600 defn->args.argnames[i++] = ',';
1601 defn->args.argnames[i++] = ' ';
1604 defn->args.argnames[i] = 0;
1607 /* Simple expansion or empty definition. */
1611 if (is_hor_space[*bp]) {
1613 SKIP_WHITE_SPACE (bp);
1616 case '!': case '"': case '#': case '%': case '&': case '\'':
1617 case ')': case '*': case '+': case ',': case '-': case '.':
1618 case '/': case ':': case ';': case '<': case '=': case '>':
1619 case '?': case '[': case '\\': case ']': case '^': case '{':
1620 case '|': case '}': case '~':
1621 cpp_warning (pfile, "missing white space after `#define %.*s'",
1622 sym_length, symname);
1626 cpp_pedwarn (pfile, "missing white space after `#define %.*s'",
1627 sym_length, symname);
1632 /* now everything from bp before limit is the definition. */
1633 defn = collect_expansion (pfile, bp, limit, -1, NULL_PTR);
1634 defn->args.argnames = (U_CHAR *) "";
1640 /* OP is null if this is a predefinition */
1641 defn->predefined = predefinition;
1643 mdef.symnam = symname;
1644 mdef.symlen = sym_length;
1653 /* Check a purported macro name SYMNAME, and yield its length.
1654 USAGE is the kind of name this is intended for. */
1657 check_macro_name (pfile, symname, usage)
1665 for (p = symname; is_idchar[*p]; p++)
1667 sym_length = p - symname;
1668 if (sym_length == 0)
1669 cpp_error (pfile, "invalid %s name", usage);
1670 else if (!is_idstart[*symname]) {
1671 U_CHAR *msg; /* what pain... */
1672 msg = (U_CHAR *) alloca (sym_length + 1);
1673 bcopy (symname, msg, sym_length);
1674 msg[sym_length] = 0;
1675 cpp_error (pfile, "invalid %s name `%s'", usage, msg);
1677 if (! strncmp (symname, "defined", 7) && sym_length == 7)
1678 cpp_error (pfile, "invalid %s name `defined'", usage);
1683 /* Return zero if two DEFINITIONs are isomorphic. */
1686 compare_defs (d1, d2)
1687 DEFINITION *d1, *d2;
1689 register struct reflist *a1, *a2;
1690 register U_CHAR *p1 = d1->expansion;
1691 register U_CHAR *p2 = d2->expansion;
1694 if (d1->nargs != d2->nargs)
1696 if (strcmp ((char *)d1->args.argnames, (char *)d2->args.argnames))
1698 for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2;
1699 a1 = a1->next, a2 = a2->next) {
1700 if (!((a1->nchars == a2->nchars && ! strncmp (p1, p2, a1->nchars))
1701 || ! comp_def_part (first, p1, a1->nchars, p2, a2->nchars, 0))
1702 || a1->argno != a2->argno
1703 || a1->stringify != a2->stringify
1704 || a1->raw_before != a2->raw_before
1705 || a1->raw_after != a2->raw_after)
1713 if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion),
1714 p2, d2->length - (p2 - d2->expansion), 1))
1719 /* Return 1 if two parts of two macro definitions are effectively different.
1720 One of the parts starts at BEG1 and has LEN1 chars;
1721 the other has LEN2 chars at BEG2.
1722 Any sequence of whitespace matches any other sequence of whitespace.
1723 FIRST means these parts are the first of a macro definition;
1724 so ignore leading whitespace entirely.
1725 LAST means these parts are the last of a macro definition;
1726 so ignore trailing whitespace entirely. */
1729 comp_def_part (first, beg1, len1, beg2, len2, last)
1731 U_CHAR *beg1, *beg2;
1735 register U_CHAR *end1 = beg1 + len1;
1736 register U_CHAR *end2 = beg2 + len2;
1738 while (beg1 != end1 && is_space[*beg1]) beg1++;
1739 while (beg2 != end2 && is_space[*beg2]) beg2++;
1742 while (beg1 != end1 && is_space[end1[-1]]) end1--;
1743 while (beg2 != end2 && is_space[end2[-1]]) end2--;
1745 while (beg1 != end1 && beg2 != end2) {
1746 if (is_space[*beg1] && is_space[*beg2]) {
1747 while (beg1 != end1 && is_space[*beg1]) beg1++;
1748 while (beg2 != end2 && is_space[*beg2]) beg2++;
1749 } else if (*beg1 == *beg2) {
1753 return (beg1 != end1) || (beg2 != end2);
1756 /* Process a #define command.
1757 BUF points to the contents of the #define command, as a contiguous string.
1758 LIMIT points to the first character past the end of the definition.
1759 KEYWORD is the keyword-table entry for #define,
1760 or NULL for a "predefined" macro. */
1763 do_define (pfile, keyword, buf, limit)
1765 struct directive *keyword;
1766 U_CHAR *buf, *limit;
1773 /* If this is a precompiler run (with -pcp) pass thru #define commands. */
1774 if (pcp_outfile && keyword)
1775 pass_thru_directive (buf, limit, pfile, keyword);
1778 mdef = create_definition (buf, limit, pfile, keyword == NULL);
1782 hashcode = hashf (mdef.symnam, mdef.symlen, HASHSIZE);
1784 if ((hp = cpp_lookup (pfile, mdef.symnam, mdef.symlen, hashcode)) != NULL)
1787 /* Redefining a precompiled key is ok. */
1788 if (hp->type == T_PCSTRING)
1790 /* Redefining a macro is ok if the definitions are the same. */
1791 else if (hp->type == T_MACRO)
1792 ok = ! compare_defs (mdef.defn, hp->value.defn);
1793 /* Redefining a constant is ok with -D. */
1794 else if (hp->type == T_CONST)
1795 ok = ! CPP_OPTIONS (pfile)->done_initializing;
1796 /* Print the warning if it's not ok. */
1799 U_CHAR *msg; /* what pain... */
1801 /* If we are passing through #define and #undef directives, do
1802 that for this re-definition now. */
1803 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1804 pass_thru_directive (buf, limit, pfile, keyword);
1806 msg = (U_CHAR *) alloca (mdef.symlen + 22);
1808 bcopy (mdef.symnam, msg + 1, mdef.symlen);
1809 strcpy ((char *) (msg + mdef.symlen + 1), "' redefined");
1810 cpp_pedwarn (pfile, msg);
1811 if (hp->type == T_MACRO)
1812 cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file, hp->value.defn->line,
1813 "this is the location of the previous definition");
1815 /* Replace the old definition. */
1817 hp->value.defn = mdef.defn;
1821 /* If we are passing through #define and #undef directives, do
1822 that for this new definition now. */
1823 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1824 pass_thru_directive (buf, limit, pfile, keyword);
1825 install (mdef.symnam, mdef.symlen, T_MACRO, 0,
1826 (char *) mdef.defn, hashcode);
1836 /* This structure represents one parsed argument in a macro call.
1837 `raw' points to the argument text as written (`raw_length' is its length).
1838 `expanded' points to the argument's macro-expansion
1839 (its length is `expand_length').
1840 `stringified_length' is the length the argument would have
1842 `use_count' is the number of times this macro arg is substituted
1843 into the macro. If the actual use count exceeds 10,
1844 the value stored is 10. */
1846 /* raw and expanded are relative to ARG_BASE */
1847 #define ARG_BASE ((pfile)->token_buffer)
1850 /* Strings relative to pfile->token_buffer */
1851 long raw, expanded, stringified;
1852 int raw_length, expand_length;
1853 int stringified_length;
1858 /* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack.
1859 If BUFFER != NULL, then use the LENGTH characters in BUFFER
1860 as the new input buffer.
1861 Return the new buffer, or NULL on failure. */
1864 cpp_push_buffer (pfile, buffer, length)
1869 register cpp_buffer *buf = CPP_BUFFER (pfile);
1870 if (buf == pfile->buffer_stack)
1872 cpp_fatal (pfile, "%s: macro or `#include' recursion too deep",
1877 bzero ((char *) buf, sizeof (cpp_buffer));
1878 CPP_BUFFER (pfile) = buf;
1879 buf->if_stack = pfile->if_stack;
1880 buf->cleanup = null_cleanup;
1881 buf->underflow = null_underflow;
1882 buf->buf = buf->cur = buffer;
1883 buf->alimit = buf->rlimit = buffer + length;
1889 cpp_pop_buffer (pfile)
1892 cpp_buffer *buf = CPP_BUFFER (pfile);
1893 (*buf->cleanup) (buf, pfile);
1894 return ++CPP_BUFFER (pfile);
1897 /* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer.
1898 Pop the buffer when done. */
1901 cpp_scan_buffer (pfile)
1904 cpp_buffer *buffer = CPP_BUFFER (pfile);
1907 enum cpp_token token = cpp_get_token (pfile);
1908 if (token == CPP_EOF) /* Should not happen ... */
1910 if (token == CPP_POP && CPP_BUFFER (pfile) == buffer)
1912 cpp_pop_buffer (pfile);
1919 * Rescan a string (which may have escape marks) into pfile's buffer.
1920 * Place the result in pfile->token_buffer.
1922 * The input is copied before it is scanned, so it is safe to pass
1923 * it something from the token_buffer that will get overwritten
1924 * (because it follows CPP_WRITTEN). This is used by do_include.
1928 cpp_expand_to_buffer (pfile, buf, length)
1933 register cpp_buffer *ip;
1935 U_CHAR *limit = buf + length;
1938 int odepth = indepth;
1944 /* Set up the input on the input stack. */
1946 buf1 = (U_CHAR *) alloca (length + 1);
1948 register U_CHAR *p1 = buf;
1949 register U_CHAR *p2 = buf1;
1956 ip = cpp_push_buffer (pfile, buf1, length);
1959 ip->has_escapes = 1;
1961 ip->lineno = obuf.lineno = 1;
1964 /* Scan the input, create the output. */
1965 cpp_scan_buffer (pfile);
1968 if (indepth != odepth)
1972 CPP_NUL_TERMINATE (pfile);
1977 adjust_position (buf, limit, linep, colp)
1987 (*linep)++, (*colp) = 1;
1993 /* Move line_base forward, updating lineno and colno. */
1996 update_position (pbuf)
1997 register cpp_buffer *pbuf;
1999 unsigned char *old_pos = pbuf->buf + pbuf->line_base;
2000 unsigned char *new_pos = pbuf->cur;
2001 register struct parse_marker *mark;
2002 for (mark = pbuf->marks; mark != NULL; mark = mark->next)
2004 if (pbuf->buf + mark->position < new_pos)
2005 new_pos = pbuf->buf + mark->position;
2007 pbuf->line_base += new_pos - old_pos;
2008 adjust_position (old_pos, new_pos, &pbuf->lineno, &pbuf->colno);
2012 cpp_buf_line_and_col (pbuf, linep, colp)
2013 register cpp_buffer *pbuf;
2021 *linep = pbuf->lineno;
2022 *colp = pbuf->colno;
2023 adjust_position (pbuf->buf + pbuf->line_base, pbuf->cur, linep, colp);
2032 /* Return the cpp_buffer that corresponds to a file (not a macro). */
2035 cpp_file_buffer (pfile)
2038 cpp_buffer *ip = CPP_BUFFER (pfile);
2040 for ( ; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
2041 if (ip->fname != NULL)
2047 count_newlines (buf, limit)
2048 register U_CHAR *buf;
2049 register U_CHAR *limit;
2051 register long count = 0;
2062 * write out a #line command, for instance, after an #include file.
2063 * If CONDITIONAL is nonzero, we can omit the #line if it would
2064 * appear to be a no-op, and we can output a few newlines instead
2065 * if we want to increase the line number by a small amount.
2066 * FILE_CHANGE says whether we are entering a file, leaving, or neither.
2070 output_line_command (pfile, conditional, file_change)
2073 enum file_change_code file_change;
2076 char *line_cmd_buf, *line_end;
2078 cpp_buffer *ip = CPP_BUFFER (pfile);
2080 if (ip->fname == NULL)
2083 update_position (ip);
2085 if (CPP_OPTIONS (pfile)->no_line_commands
2086 || CPP_OPTIONS (pfile)->no_output)
2089 line = CPP_BUFFER (pfile)->lineno;
2090 col = CPP_BUFFER (pfile)->colno;
2091 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
2093 if (CPP_OPTIONS (pfile)->no_line_commands)
2097 if (line == pfile->lineno)
2100 /* If the inherited line number is a little too small,
2101 output some newlines instead of a #line command. */
2102 if (line > pfile->lineno && line < pfile->lineno + 8) {
2103 CPP_RESERVE (pfile, 20);
2104 while (line > pfile->lineno) {
2105 CPP_PUTC_Q (pfile, '\n');
2113 /* Don't output a line number of 0 if we can help it. */
2114 if (ip->lineno == 0 && ip->bufp - ip->buf < ip->length
2115 && *ip->bufp == '\n') {
2121 CPP_RESERVE (pfile, 4 * strlen (ip->nominal_fname) + 50);
2123 #ifdef OUTPUT_LINE_COMMANDS
2124 static char sharp_line[] = "#line ";
2126 static char sharp_line[] = "# ";
2128 CPP_PUTS_Q (pfile, sharp_line, sizeof(sharp_line)-1);
2131 sprintf (CPP_PWRITTEN (pfile), "%d ", line);
2132 CPP_ADJUST_WRITTEN (pfile, strlen (CPP_PWRITTEN (pfile)));
2134 quote_string (pfile, ip->nominal_fname);
2135 if (file_change != same_file) {
2136 CPP_PUTC_Q (pfile, ' ');
2137 CPP_PUTC_Q (pfile, file_change == enter_file ? '1' : '2');
2139 /* Tell cc1 if following text comes from a system header file. */
2140 if (ip->system_header_p) {
2141 CPP_PUTC_Q (pfile, ' ');
2142 CPP_PUTC_Q (pfile, '3');
2144 #ifndef NO_IMPLICIT_EXTERN_C
2145 /* Tell cc1plus if following text should be treated as C. */
2146 if (ip->system_header_p == 2 && CPP_OPTIONS (pfile)->cplusplus) {
2147 CPP_PUTC_Q (pfile, ' ');
2148 CPP_PUTC_Q (pfile, '4');
2151 CPP_PUTC_Q (pfile, '\n');
2152 pfile->lineno = line;
2156 * Parse a macro argument and append the info on PFILE's token_buffer.
2157 * REST_ARGS means to absorb the rest of the args.
2158 * Return nonzero to indicate a syntax error.
2161 static enum cpp_token
2162 macarg (pfile, rest_args)
2167 enum cpp_token token;
2168 long arg_start = CPP_WRITTEN (pfile);
2169 char save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
2170 CPP_OPTIONS (pfile)->put_out_comments = 0;
2172 /* Try to parse as much of the argument as exists at this
2173 input stack level. */
2174 pfile->no_macro_expand++;
2177 token = cpp_get_token (pfile);
2183 /* If we've hit end of file, it's an error (reported by caller).
2184 Ditto if it's the end of cpp_expand_to_buffer text.
2185 If we've hit end of macro, just continue. */
2186 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
2197 /* if we've returned to lowest level and
2198 we aren't absorbing all args */
2199 if (paren == 0 && rest_args == 0)
2203 /* Remove ',' or ')' from argument buffer. */
2204 CPP_ADJUST_WRITTEN (pfile, -1);
2211 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
2212 pfile->no_macro_expand--;
2217 /* Turn newlines to spaces in the string of length LENGTH at START,
2218 except inside of string constants.
2219 The string is copied into itself with its beginning staying fixed. */
2222 change_newlines (start, length)
2226 register U_CHAR *ibp;
2227 register U_CHAR *obp;
2228 register U_CHAR *limit;
2232 limit = start + length;
2235 while (ibp < limit) {
2236 *obp++ = c = *ibp++;
2241 /* Notice and skip strings, so that we don't delete newlines in them. */
2244 while (ibp < limit) {
2245 *obp++ = c = *ibp++;
2248 if (c == '\n' && quotec == '\'')
2264 if (!pfile->timebuf) {
2265 time_t t = time ((time_t *) 0);
2266 pfile->timebuf = localtime (&t);
2268 return pfile->timebuf;
2271 static char *monthnames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
2272 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
2276 * expand things like __FILE__. Place the expansion into the output
2277 * buffer *without* rescanning.
2281 special_symbol (hp, pfile)
2288 cpp_buffer *ip = NULL;
2291 int paren = 0; /* For special `defined' keyword */
2294 if (pcp_outfile && pcp_inside_if
2295 && hp->type != T_SPEC_DEFINED && hp->type != T_CONST)
2297 "Predefined macro `%s' used inside `#if' during precompilation",
2301 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
2303 if (ip == CPP_NULL_BUFFER (pfile))
2305 cpp_error (pfile, "cccp error: not in any file?!");
2306 return; /* the show must go on */
2308 if (ip->fname != NULL)
2318 if (hp->type == T_BASE_FILE)
2320 while (CPP_PREV_BUFFER (ip) != CPP_NULL_BUFFER (pfile))
2321 ip = CPP_PREV_BUFFER (ip);
2323 string = ip->nominal_fname;
2327 CPP_RESERVE (pfile, 3 + 4 * strlen (string));
2328 quote_string (pfile, string);
2332 case T_INCLUDE_LEVEL:
2334 ip = CPP_BUFFER (pfile);
2335 for (; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
2336 if (ip->fname != NULL)
2339 buf = (char *) alloca (8); /* Eight bytes ought to be more than enough */
2340 sprintf (buf, "%d", true_indepth - 1);
2344 buf = (char *) alloca (3 + strlen (version_string));
2345 sprintf (buf, "\"%s\"", version_string);
2348 #ifndef NO_BUILTIN_SIZE_TYPE
2354 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2355 case T_PTRDIFF_TYPE:
2361 buf = CPP_WCHAR_TYPE (pfile);
2364 case T_USER_LABEL_PREFIX_TYPE:
2365 buf = USER_LABEL_PREFIX;
2368 case T_REGISTER_PREFIX_TYPE:
2369 buf = REGISTER_PREFIX;
2373 buf = (char *) alloca (4 * sizeof (int));
2374 sprintf (buf, "%d", hp->value.ival);
2376 if (pcp_inside_if && pcp_outfile)
2377 /* Output a precondition for this macro use */
2378 fprintf (pcp_outfile, "#define %s %d\n", hp->name, hp->value.ival);
2384 long line = ip->lineno;
2385 long col = ip->colno;
2386 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
2388 buf = (char *) alloca (10);
2389 sprintf (buf, "%d", line);
2395 buf = (char *) alloca (20);
2396 timebuf = timestamp (pfile);
2397 if (hp->type == T_DATE)
2398 sprintf (buf, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon],
2399 timebuf->tm_mday, timebuf->tm_year + 1900);
2401 sprintf (buf, "\"%02d:%02d:%02d\"", timebuf->tm_hour, timebuf->tm_min,
2405 case T_SPEC_DEFINED:
2406 buf = " 0 "; /* Assume symbol is not defined */
2407 ip = CPP_BUFFER (pfile);
2408 SKIP_WHITE_SPACE (ip->cur);
2409 if (*ip->cur == '(')
2412 ip->cur++; /* Skip over the paren */
2413 SKIP_WHITE_SPACE (ip->cur);
2416 if (!is_idstart[*ip->cur])
2418 if (hp = cpp_lookup (pfile, ip->cur, -1, -1))
2421 if (pcp_outfile && pcp_inside_if
2422 && (hp->type == T_CONST
2423 || (hp->type == T_MACRO && hp->value.defn->predefined)))
2424 /* Output a precondition for this macro use. */
2425 fprintf (pcp_outfile, "#define %s\n", hp->name);
2431 if (pcp_outfile && pcp_inside_if)
2433 /* Output a precondition for this macro use */
2434 U_CHAR *cp = ip->bufp;
2435 fprintf (pcp_outfile, "#undef ");
2436 while (is_idchar[*cp]) /* Ick! */
2437 fputc (*cp++, pcp_outfile);
2438 putc ('\n', pcp_outfile);
2441 while (is_idchar[*ip->cur])
2443 SKIP_WHITE_SPACE (ip->cur);
2446 if (*ip->cur != ')')
2454 cpp_error (pfile, "`defined' without an identifier");
2458 cpp_error (pfile, "cccp error: invalid special hash type"); /* time for gdb */
2462 CPP_RESERVE (pfile, len + 1);
2463 CPP_PUTS_Q (pfile, buf, len);
2464 CPP_NUL_TERMINATE_Q (pfile);
2469 /* Write out a #define command for the special named MACRO_NAME
2470 to PFILE's token_buffer. */
2473 dump_special_to_buffer (pfile, macro_name)
2477 static char define_directive[] = "#define ";
2478 int macro_name_length = strlen (macro_name);
2479 output_line_command (pfile, 0, same_file);
2480 CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length);
2481 CPP_PUTS_Q (pfile, define_directive, sizeof(define_directive)-1);
2482 CPP_PUTS_Q (pfile, macro_name, macro_name_length);
2483 CPP_PUTC_Q (pfile, ' ');
2484 cpp_expand_to_buffer (pfile, macro_name, macro_name_length);
2485 CPP_PUTC (pfile, '\n');
2488 /* Initialize the built-in macros. */
2491 initialize_builtins (pfile)
2494 install ("__LINE__", -1, T_SPECLINE, 0, 0, -1);
2495 install ("__DATE__", -1, T_DATE, 0, 0, -1);
2496 install ("__FILE__", -1, T_FILE, 0, 0, -1);
2497 install ("__BASE_FILE__", -1, T_BASE_FILE, 0, 0, -1);
2498 install ("__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL, 0, 0, -1);
2499 install ("__VERSION__", -1, T_VERSION, 0, 0, -1);
2500 #ifndef NO_BUILTIN_SIZE_TYPE
2501 install ("__SIZE_TYPE__", -1, T_SIZE_TYPE, 0, 0, -1);
2503 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2504 install ("__PTRDIFF_TYPE__ ", -1, T_PTRDIFF_TYPE, 0, 0, -1);
2506 install ("__WCHAR_TYPE__", -1, T_WCHAR_TYPE, 0, 0, -1);
2507 install ("__USER_LABEL_PREFIX__", -1, T_USER_LABEL_PREFIX_TYPE, 0, 0, -1);
2508 install ("__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE, 0, 0, -1);
2509 install ("__TIME__", -1, T_TIME, 0, 0, -1);
2510 if (!CPP_TRADITIONAL (pfile))
2511 install ("__STDC__", -1, T_CONST, STDC_VALUE, 0, -1);
2512 if (CPP_OPTIONS (pfile)->objc)
2513 install ("__OBJC__", -1, T_CONST, 1, 0, -1);
2514 /* This is supplied using a -D by the compiler driver
2515 so that it is present only when truly compiling with GNU C. */
2516 /* install ("__GNUC__", -1, T_CONST, 2, 0, -1); */
2518 if (CPP_OPTIONS (pfile)->debug_output)
2520 dump_special_to_buffer (pfile, "__BASE_FILE__");
2521 dump_special_to_buffer (pfile, "__VERSION__");
2522 #ifndef NO_BUILTIN_SIZE_TYPE
2523 dump_special_to_buffer (pfile, "__SIZE_TYPE__");
2525 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2526 dump_special_to_buffer (pfile, "__PTRDIFF_TYPE__");
2528 dump_special_to_buffer (pfile, "__WCHAR_TYPE__");
2529 dump_special_to_buffer (pfile, "__DATE__");
2530 dump_special_to_buffer (pfile, "__TIME__");
2531 if (!CPP_TRADITIONAL (pfile))
2532 dump_special_to_buffer (pfile, "__STDC__");
2533 if (CPP_OPTIONS (pfile)->objc)
2534 dump_special_to_buffer (pfile, "__OBJC__");
2538 /* Return 1 iff a token ending in C1 followed directly by a token C2
2539 could cause mis-tokenization. */
2542 unsafe_chars (c1, c2)
2548 if (c2 == c1 || c2 == '=')
2552 case '0': case '1': case '2': case '3': case '4':
2553 case '5': case '6': case '7': case '8': case '9':
2555 if (c2 == '-' || c2 == '+')
2556 return 1; /* could extend a pre-processing number */
2559 if (c2 == '\'' || c2 == '\"')
2560 return 1; /* Could turn into L"xxx" or L'xxx'. */
2564 case 'a': case 'b': case 'c': case 'd': case 'f':
2565 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
2566 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
2567 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
2569 case 'A': case 'B': case 'C': case 'D': case 'F':
2570 case 'G': case 'H': case 'I': case 'J': case 'K':
2571 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
2572 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
2574 /* We're in the middle of either a name or a pre-processing number. */
2575 return (is_idchar[c2] || c2 == '.');
2576 case '<': case '>': case '!': case '%': case '#': case ':':
2577 case '^': case '&': case '|': case '*': case '/': case '=':
2578 return (c2 == c1 || c2 == '=');
2583 /* Expand a macro call.
2584 HP points to the symbol that is the macro being called.
2585 Put the result of expansion onto the input stack
2586 so that subsequent input by our caller will use it.
2588 If macro wants arguments, caller has already verified that
2589 an argument list follows; arguments come from the input stack. */
2592 macroexpand (pfile, hp)
2597 DEFINITION *defn = hp->value.defn;
2598 register U_CHAR *xbuf;
2599 long start_line, start_column;
2601 struct argdata *args;
2602 long old_written = CPP_WRITTEN (pfile);
2604 int start_line = instack[indepth].lineno;
2606 int rest_args, rest_zero;
2610 CHECK_DEPTH (return;);
2614 /* This macro is being used inside a #if, which means it must be */
2615 /* recorded as a precondition. */
2616 if (pcp_inside_if && pcp_outfile && defn->predefined)
2617 dump_single_macro (hp, pcp_outfile);
2620 pfile->output_escapes++;
2621 cpp_buf_line_and_col (cpp_file_buffer (pfile), &start_line, &start_column);
2623 nargs = defn->nargs;
2627 enum cpp_token token;
2629 args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata));
2631 for (i = 0; i < nargs; i++)
2633 args[i].raw = args[i].expanded = 0;
2634 args[i].raw_length = 0;
2635 args[i].expand_length = args[i].stringified_length = -1;
2636 args[i].use_count = 0;
2639 /* Parse all the macro args that are supplied. I counts them.
2640 The first NARGS args are stored in ARGS.
2641 The rest are discarded. If rest_args is set then we assume
2642 macarg absorbed the rest of the args. */
2646 FORWARD(1); /* Discard the open-parenthesis before the first arg. */
2651 if (i < nargs || (nargs == 0 && i == 0))
2653 /* if we are working on last arg which absorbs rest of args... */
2654 if (i == nargs - 1 && defn->rest_args)
2656 args[i].raw = CPP_WRITTEN (pfile);
2657 token = macarg (pfile, rest_args);
2658 args[i].raw_length = CPP_WRITTEN (pfile) - args[i].raw;
2659 args[i].newlines = 0; /* FIXME */
2662 token = macarg (pfile, 0);
2663 if (token == CPP_EOF || token == CPP_POP)
2665 cpp_error_with_line (pfile, start_line, start_column,
2666 "unterminated macro call");
2670 } while (token == CPP_COMMA);
2672 /* If we got one arg but it was just whitespace, call that 0 args. */
2675 register U_CHAR *bp = ARG_BASE + args[0].raw;
2676 register U_CHAR *lim = bp + args[0].raw_length;
2677 /* cpp.texi says for foo ( ) we provide one argument.
2678 However, if foo wants just 0 arguments, treat this as 0. */
2680 while (bp != lim && is_space[*bp]) bp++;
2685 /* Don't output an error message if we have already output one for
2686 a parse error above. */
2688 if (nargs == 0 && i > 0)
2690 cpp_error (pfile, "arguments given to macro `%s'", hp->name);
2694 /* traditional C allows foo() if foo wants one argument. */
2695 if (nargs == 1 && i == 0 && CPP_TRADITIONAL (pfile))
2697 /* the rest args token is allowed to absorb 0 tokens */
2698 else if (i == nargs - 1 && defn->rest_args)
2701 cpp_error (pfile, "macro `%s' used without args", hp->name);
2703 cpp_error (pfile, "macro `%s' used with just one arg", hp->name);
2705 cpp_error (pfile, "macro `%s' used with only %d args",
2711 "macro `%s' used with too many (%d) args", hp->name, i);
2715 /* If macro wants zero args, we parsed the arglist for checking only.
2716 Read directly from the macro definition. */
2719 xbuf = defn->expansion;
2720 xbuf_len = defn->length;
2724 register U_CHAR *exp = defn->expansion;
2725 register int offset; /* offset in expansion,
2726 copied a piece at a time */
2727 register int totlen; /* total amount of exp buffer filled so far */
2729 register struct reflist *ap, *last_ap;
2731 /* Macro really takes args. Compute the expansion of this call. */
2733 /* Compute length in characters of the macro's expansion.
2734 Also count number of times each arg is used. */
2735 xbuf_len = defn->length;
2736 for (ap = defn->pattern; ap != NULL; ap = ap->next)
2740 register struct argdata *arg = &args[ap->argno];
2741 /* Stringify it it hasn't already been */
2742 if (arg->stringified_length < 0)
2744 int arglen = arg->raw_length;
2748 /* Initially need_space is -1. Otherwise, 1 means the
2749 previous character was a space, but we suppressed it;
2750 0 means the previous character was a non-space. */
2751 int need_space = -1;
2753 arg->stringified = CPP_WRITTEN (pfile);
2754 if (!CPP_TRADITIONAL (pfile))
2755 CPP_PUTC (pfile, '\"'); /* insert beginning quote */
2756 for (; i < arglen; i++)
2758 c = (ARG_BASE + arg->raw)[i];
2762 /* Internal sequences of whitespace are replaced by
2763 one space except within an string or char token.*/
2766 if (CPP_WRITTEN (pfile) > arg->stringified
2767 && (CPP_PWRITTEN (pfile))[-1] == '@')
2769 /* "@ " escape markers are removed */
2770 CPP_ADJUST_WRITTEN (pfile, -1);
2773 if (need_space == 0)
2777 else if (need_space > 0)
2778 CPP_PUTC (pfile, ' ');
2793 else if (c == '\"' || c == '\'')
2797 /* Escape these chars */
2798 if (c == '\"' || (in_string && c == '\\'))
2799 CPP_PUTC (pfile, '\\');
2801 CPP_PUTC (pfile, c);
2804 CPP_RESERVE (pfile, 4);
2805 sprintf (CPP_PWRITTEN (pfile), "\\%03o",
2807 CPP_ADJUST_WRITTEN (pfile, 4);
2810 if (!CPP_TRADITIONAL (pfile))
2811 CPP_PUTC (pfile, '\"'); /* insert ending quote */
2812 arg->stringified_length
2813 = CPP_WRITTEN (pfile) - arg->stringified;
2815 xbuf_len += args[ap->argno].stringified_length;
2817 else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
2818 /* Add 4 for two newline-space markers to prevent
2819 token concatenation. */
2820 xbuf_len += args[ap->argno].raw_length + 4;
2823 /* We have an ordinary (expanded) occurrence of the arg.
2824 So compute its expansion, if we have not already. */
2825 if (args[ap->argno].expand_length < 0)
2827 args[ap->argno].expanded = CPP_WRITTEN (pfile);
2828 cpp_expand_to_buffer (pfile,
2829 ARG_BASE + args[ap->argno].raw,
2830 args[ap->argno].raw_length);
2832 args[ap->argno].expand_length
2833 = CPP_WRITTEN (pfile) - args[ap->argno].expanded;
2836 /* Add 4 for two newline-space markers to prevent
2837 token concatenation. */
2838 xbuf_len += args[ap->argno].expand_length + 4;
2840 if (args[ap->argno].use_count < 10)
2841 args[ap->argno].use_count++;
2844 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
2846 /* Generate in XBUF the complete expansion
2847 with arguments substituted in.
2848 TOTLEN is the total size generated so far.
2849 OFFSET is the index in the definition
2850 of where we are copying from. */
2851 offset = totlen = 0;
2852 for (last_ap = NULL, ap = defn->pattern; ap != NULL;
2853 last_ap = ap, ap = ap->next)
2855 register struct argdata *arg = &args[ap->argno];
2856 int count_before = totlen;
2858 /* Add chars to XBUF. */
2859 for (i = 0; i < ap->nchars; i++, offset++)
2860 xbuf[totlen++] = exp[offset];
2862 /* If followed by an empty rest arg with concatenation,
2863 delete the last run of nonwhite chars. */
2864 if (rest_zero && totlen > count_before
2865 && ((ap->rest_args && ap->raw_before)
2866 || (last_ap != NULL && last_ap->rest_args
2867 && last_ap->raw_after)))
2869 /* Delete final whitespace. */
2870 while (totlen > count_before && is_space[xbuf[totlen - 1]])
2873 /* Delete the nonwhites before them. */
2874 while (totlen > count_before && ! is_space[xbuf[totlen - 1]])
2878 if (ap->stringify != 0)
2880 bcopy (ARG_BASE + arg->stringified,
2881 xbuf + totlen, arg->stringified_length);
2882 totlen += arg->stringified_length;
2884 else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
2886 U_CHAR *p1 = ARG_BASE + arg->raw;
2887 U_CHAR *l1 = p1 + arg->raw_length;
2890 while (p1 != l1 && is_space[*p1]) p1++;
2891 while (p1 != l1 && is_idchar[*p1])
2892 xbuf[totlen++] = *p1++;
2896 /* Arg is concatenated after: delete trailing whitespace,
2897 whitespace markers, and no-reexpansion markers. */
2900 if (is_space[l1[-1]]) l1--;
2901 else if (l1[-1] == '-')
2903 U_CHAR *p2 = l1 - 1;
2904 /* If a `-' is preceded by an odd number of newlines then it
2905 and the last newline are a no-reexpansion marker. */
2906 while (p2 != p1 && p2[-1] == '\n') p2--;
2907 if ((l1 - 1 - p2) & 1) {
2916 bcopy (p1, xbuf + totlen, l1 - p1);
2921 U_CHAR *expanded = ARG_BASE + arg->expanded;
2922 if (!ap->raw_before && totlen > 0 && arg->expand_length
2923 && !CPP_TRADITIONAL(pfile)
2924 && unsafe_chars (xbuf[totlen-1], expanded[0]))
2926 xbuf[totlen++] = '@';
2927 xbuf[totlen++] = ' ';
2930 bcopy (expanded, xbuf + totlen, arg->expand_length);
2931 totlen += arg->expand_length;
2933 if (!ap->raw_after && totlen > 0 && offset < defn->length
2934 && !CPP_TRADITIONAL(pfile)
2935 && unsafe_chars (xbuf[totlen-1], exp[offset]))
2937 xbuf[totlen++] = '@';
2938 xbuf[totlen++] = ' ';
2941 /* If a macro argument with newlines is used multiple times,
2942 then only expand the newlines once. This avoids creating
2943 output lines which don't correspond to any input line,
2944 which confuses gdb and gcov. */
2945 if (arg->use_count > 1 && arg->newlines > 0)
2947 /* Don't bother doing change_newlines for subsequent
2951 = change_newlines (expanded, arg->expand_length);
2955 if (totlen > xbuf_len)
2959 /* if there is anything left of the definition
2960 after handling the arg list, copy that in too. */
2962 for (i = offset; i < defn->length; i++)
2964 /* if we've reached the end of the macro */
2967 if (! (rest_zero && last_ap != NULL && last_ap->rest_args
2968 && last_ap->raw_after))
2969 xbuf[totlen++] = exp[i];
2977 pfile->output_escapes--;
2979 /* Now put the expansion on the input stack
2980 so our caller will commence reading from it. */
2981 push_macro_expansion (pfile, xbuf, xbuf_len, hp);
2982 CPP_BUFFER (pfile)->has_escapes = 1;
2984 /* Pop the space we've used in the token_buffer for argument expansion. */
2985 CPP_SET_WRITTEN (pfile, old_written);
2987 /* Recursive macro use sometimes works traditionally.
2988 #define foo(x,y) bar (x (y,0), y)
2991 if (!CPP_TRADITIONAL (pfile))
2992 hp->type = T_DISABLED;
2996 push_macro_expansion (pfile, xbuf, xbuf_len, hp)
2998 register U_CHAR *xbuf;
3002 register cpp_buffer *mbuf = cpp_push_buffer (pfile, xbuf, xbuf_len);
3005 mbuf->cleanup = macro_cleanup;
3008 /* The first chars of the expansion should be a "@ " added by
3009 collect_expansion. This is to prevent accidental token-pasting
3010 between the text preceding the macro invocation, and the macro
3013 We would like to avoid adding unneeded spaces (for the sake of
3014 tools that use cpp, such as imake). In some common cases we can
3015 tell that it is safe to omit the space.
3017 The character before the macro invocation cannot have been an
3018 idchar (or else it would have been pasted with the idchars of
3019 the macro name). Therefore, if the first non-space character
3020 of the expansion is an idchar, we do not need the extra space
3021 to prevent token pasting.
3023 Also, we don't need the extra space if the first char is '(',
3024 or some other (less common) characters. */
3026 if (xbuf[0] == '@' && xbuf[1] == ' '
3027 && (is_idchar[xbuf[2]] || xbuf[2] == '(' || xbuf[2] == '\''
3028 || xbuf[2] == '\"'))
3032 /* Like cpp_get_token, except that it does not read past end-of-line.
3033 Also, horizontal space is skipped, and macros are popped. */
3035 static enum cpp_token
3036 get_directive_token (pfile)
3041 long old_written = CPP_WRITTEN (pfile);
3042 enum cpp_token token;
3043 cpp_skip_hspace (pfile);
3044 if (PEEKC () == '\n')
3046 token = cpp_get_token (pfile);
3050 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
3052 /* ... else fall though ... */
3053 case CPP_HSPACE: case CPP_COMMENT:
3054 CPP_SET_WRITTEN (pfile, old_written);
3062 /* Handle #include and #import.
3063 This function expects to see "fname" or <fname> on the input.
3065 The input is normally in part of the output_buffer following
3066 CPP_WRITTEN, and will get overwritten by output_line_command.
3067 I.e. in input file specification has been popped by handle_directive.
3071 do_include (pfile, keyword, unused1, unused2)
3073 struct directive *keyword;
3074 U_CHAR *unused1, *unused2;
3076 int importing = (keyword->type == T_IMPORT);
3077 int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
3078 char *fname; /* Dynamically allocated fname buffer */
3081 U_CHAR *fbeg, *fend; /* Beginning and end of fname */
3082 enum cpp_token token;
3084 /* Chain of dirs to search */
3085 struct file_name_list *search_start = CPP_OPTIONS (pfile)->include;
3086 struct file_name_list dsp[1]; /* First in chain, if #include "..." */
3087 struct file_name_list *searchptr = 0;
3088 long old_written = CPP_WRITTEN (pfile);
3092 int f; /* file number */
3094 int retried = 0; /* Have already tried macro
3095 expanding the include line */
3096 int angle_brackets = 0; /* 0 for "...", 1 for <...> */
3101 f= -1; /* JF we iz paranoid! */
3103 if (importing && CPP_OPTIONS (pfile)->warn_import
3104 && !CPP_OPTIONS (pfile)->inhibit_warnings
3105 && !CPP_BUFFER (pfile)->system_header_p && !pfile->import_warning)
3107 pfile->import_warning = 1;
3108 cpp_warning (pfile, "using `#import' is not recommended");
3109 fprintf (stderr, "The fact that a certain header file need not be processed more than once\n");
3110 fprintf (stderr, "should be indicated in the header file, not where it is used.\n");
3111 fprintf (stderr, "The best way to do this is with a conditional of this form:\n\n");
3112 fprintf (stderr, " #ifndef _FOO_H_INCLUDED\n");
3113 fprintf (stderr, " #define _FOO_H_INCLUDED\n");
3114 fprintf (stderr, " ... <real contents of file> ...\n");
3115 fprintf (stderr, " #endif /* Not _FOO_H_INCLUDED */\n\n");
3116 fprintf (stderr, "Then users can use `#include' any number of times.\n");
3117 fprintf (stderr, "GNU C automatically avoids processing the file more than once\n");
3118 fprintf (stderr, "when it is equipped with such a conditional.\n");
3121 pfile->parsing_include_directive++;
3122 token = get_directive_token (pfile);
3123 pfile->parsing_include_directive--;
3125 if (token == CPP_STRING)
3127 /* FIXME - check no trailing garbage */
3128 fbeg = pfile->token_buffer + old_written + 1;
3129 fend = CPP_PWRITTEN (pfile) - 1;
3130 if (fbeg[-1] == '<')
3133 /* If -I-, start with the first -I dir after the -I-. */
3134 if (CPP_OPTIONS (pfile)->first_bracket_include)
3135 search_start = CPP_OPTIONS (pfile)->first_bracket_include;
3137 /* If -I- was specified, don't search current dir, only spec'd ones. */
3138 else if (! CPP_OPTIONS (pfile)->ignore_srcdir)
3140 cpp_buffer *fp = CPP_BUFFER (pfile);
3141 /* We have "filename". Figure out directory this source
3142 file is coming from and put it on the front of the list. */
3144 for ( ; fp != CPP_NULL_BUFFER (pfile); fp = CPP_PREV_BUFFER (fp))
3149 if ((nam = fp->nominal_fname) != NULL)
3151 /* Found a named file. Figure out dir of the file,
3152 and put it in front of the search list. */
3153 dsp[0].next = search_start;
3156 ep = rindex (nam, '/');
3158 ep = rindex (nam, ']');
3159 if (ep == NULL) ep = rindex (nam, '>');
3160 if (ep == NULL) ep = rindex (nam, ':');
3161 if (ep != NULL) ep++;
3166 dsp[0].fname = (char *) alloca (n + 1);
3167 strncpy (dsp[0].fname, nam, n);
3168 dsp[0].fname[n] = '\0';
3169 if (n + INCLUDE_LEN_FUDGE > pfile->max_include_len)
3170 pfile->max_include_len = n + INCLUDE_LEN_FUDGE;
3174 dsp[0].fname = 0; /* Current directory */
3176 dsp[0].got_name_map = 0;
3183 else if (token == CPP_NAME)
3186 * Support '#include xyz' like VAX-C to allow for easy use of all the
3187 * decwindow include files. It defaults to '#include <xyz.h>' (so the
3188 * code from case '<' is repeated here) and generates a warning.
3191 "VAX-C-style include specification found, use '#include <filename.h>' !");
3193 /* If -I-, start with the first -I dir after the -I-. */
3194 if (CPP_OPTIONS (pfile)->first_bracket_include)
3195 search_start = CPP_OPTIONS (pfile)->first_bracket_include;
3196 fbeg = pfile->token_buffer + old_written;
3197 fend = CPP_PWRITTEN (pfile);
3203 "`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
3204 CPP_SET_WRITTEN (pfile, old_written);
3205 skip_rest_of_line (pfile);
3211 token = get_directive_token (pfile);
3212 if (token != CPP_VSPACE)
3214 cpp_error (pfile, "junk at end of `#include'");
3215 while (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP)
3216 token = get_directive_token (pfile);
3219 /* For #include_next, skip in the search path
3220 past the dir in which the containing file was found. */
3223 cpp_buffer *fp = CPP_BUFFER (pfile);
3224 for (; fp != CPP_NULL_BUFFER (pfile); fp = CPP_PREV_BUFFER (fp))
3225 if (fp->fname != NULL)
3227 /* fp->dir is null if the containing file was specified with
3228 an absolute file name. In that case, don't skip anything. */
3229 if (fp->dir == SELF_DIR_DUMMY)
3230 search_start = CPP_OPTIONS (pfile)->include;
3232 search_start = fp->dir->next;
3237 CPP_SET_WRITTEN (pfile, old_written);
3243 cpp_error (pfile, "empty file name in `#%s'", keyword->name);
3247 /* Allocate this permanently, because it gets stored in the definitions
3249 fname = (char *) xmalloc (pfile->max_include_len + flen + 4);
3250 /* + 2 above for slash and terminating null. */
3251 /* + 2 added for '.h' on VMS (to support '#include filename') */
3253 /* If specified file name is absolute, just open it. */
3256 strncpy (fname, fbeg, flen);
3258 if (redundant_include_p (pfile, fname))
3261 f = lookup_import (pfile, fname, NULL_PTR);
3263 f = open_include_file (pfile, fname, NULL_PTR);
3265 return 0; /* Already included this file */
3267 /* Search directory path, trying to open the file.
3268 Copy each filename tried into FNAME. */
3270 for (searchptr = search_start; searchptr; searchptr = searchptr->next) {
3271 if (searchptr->fname) {
3272 /* The empty string in a search path is ignored.
3273 This makes it possible to turn off entirely
3274 a standard piece of the list. */
3275 if (searchptr->fname[0] == 0)
3277 strcpy (fname, searchptr->fname);
3278 strcat (fname, "/");
3279 fname[strlen (fname) + flen] = 0;
3283 strncat (fname, fbeg, flen);
3285 /* Change this 1/2 Unix 1/2 VMS file specification into a
3286 full VMS file specification */
3287 if (searchptr->fname && (searchptr->fname[0] != 0)) {
3288 /* Fix up the filename */
3289 hack_vms_include_specification (fname);
3291 /* This is a normal VMS filespec, so use it unchanged. */
3292 strncpy (fname, fbeg, flen);
3294 /* if it's '#include filename', add the missing .h */
3295 if (index(fname,'.')==NULL) {
3296 strcat (fname, ".h");
3300 /* ??? There are currently 3 separate mechanisms for avoiding processing
3301 of redundant include files: #import, #pragma once, and
3302 redundant_include_p. It would be nice if they were unified. */
3303 if (redundant_include_p (pfile, fname))
3306 f = lookup_import (pfile, fname, searchptr);
3308 f = open_include_file (pfile, fname, searchptr);
3310 return 0; /* Already included this file */
3312 else if (f == -1 && errno == EACCES)
3313 cpp_warning (pfile, "Header file %s exists, but is not readable",
3323 /* A file that was not found. */
3324 strncpy (fname, fbeg, flen);
3326 /* If generating dependencies and -MG was specified, we assume missing
3327 files are leaf files, living in the same directory as the source file
3328 or other similar place; these missing files may be generated from
3329 other files and may not exist yet (eg: y.tab.h). */
3331 if (CPP_OPTIONS(pfile)->print_deps_missing_files
3332 && CPP_PRINT_DEPS (pfile)
3333 > (angle_brackets || (pfile->system_include_depth > 0)))
3335 /* If it was requested as a system header file,
3336 then assume it belongs in the first place to look for such. */
3339 for (searchptr = search_start; searchptr;
3340 searchptr = searchptr->next)
3342 if (searchptr->fname)
3346 if (searchptr->fname[0] == 0)
3348 p = (char *) alloca (strlen (searchptr->fname)
3349 + strlen (fname) + 2);
3350 strcpy (p, searchptr->fname);
3353 deps_output (pfile, p, ' ');
3360 /* Otherwise, omit the directory, as if the file existed
3361 in the directory with the source. */
3362 deps_output (pfile, fname, ' ');
3365 /* If -M was specified, and this header file won't be added to the
3366 dependency list, then don't count this as an error, because we can
3367 still produce correct output. Otherwise, we can't produce correct
3368 output, because there may be dependencies we need inside the missing
3369 file, and we don't know what directory this missing file exists in.*/
3370 else if (CPP_PRINT_DEPS (pfile)
3371 && (CPP_PRINT_DEPS (pfile)
3372 <= (angle_brackets || (pfile->system_include_depth > 0))))
3373 cpp_warning (pfile, "No include path in which to find %s", fname);
3374 else if (search_start)
3375 cpp_error_from_errno (pfile, fname);
3377 cpp_error (pfile, "No include path in which to find %s", fname);
3380 /* Check to see if this include file is a once-only include file.
3383 struct file_name_list *ptr;
3385 for (ptr = pfile->dont_repeat_files; ptr; ptr = ptr->next) {
3386 if (!strcmp (ptr->fname, fname)) {
3388 return 0; /* This file was once'd. */
3392 for (ptr = pfile->all_include_files; ptr; ptr = ptr->next) {
3393 if (!strcmp (ptr->fname, fname))
3394 break; /* This file was included before. */
3398 /* This is the first time for this file. */
3399 /* Add it to list of files included. */
3401 ptr = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
3402 ptr->control_macro = 0;
3403 ptr->c_system_include_path = 0;
3404 ptr->next = pfile->all_include_files;
3405 pfile->all_include_files = ptr;
3406 ptr->fname = savestring (fname);
3407 ptr->got_name_map = 0;
3409 /* For -M, add this file to the dependencies. */
3410 if (CPP_PRINT_DEPS (pfile)
3411 > (angle_brackets || (pfile->system_include_depth > 0)))
3412 deps_output (pfile, fname, ' ');
3415 /* Handle -H option. */
3416 if (CPP_OPTIONS(pfile)->print_include_names)
3418 cpp_buffer *buf = CPP_BUFFER (pfile);
3419 while ((buf = CPP_PREV_BUFFER (buf)) != CPP_NULL_BUFFER (pfile))
3421 fprintf (stderr, "%s\n", fname);
3425 pfile->system_include_depth++;
3427 /* Actually process the file. */
3429 /* Record file on "seen" list for #import. */
3430 add_import (pfile, f, fname);
3432 pcftry = (char *) alloca (strlen (fname) + 30);
3444 sprintf (pcftry, "%s%d", fname, pcfnum++);
3446 pcf = open (pcftry, O_RDONLY, 0666);
3452 if (bcmp ((char *) &stat_f.st_ino, (char *) &s.st_ino,
3454 || stat_f.st_dev != s.st_dev)
3456 pcfbuf = check_precompiled (pcf, fname, &pcfbuflimit);
3457 /* Don't need it any more. */
3462 /* Don't need it at all. */
3467 } while (pcf != -1 && !pcfbuf);
3471 /* Actually process the file */
3472 if (cpp_push_buffer (pfile, NULL, 0) == NULL)
3474 if (finclude (pfile, f, fname, is_system_include (pfile, fname),
3475 searchptr != dsp ? searchptr : SELF_DIR_DUMMY))
3477 output_line_command (pfile, 0, enter_file);
3478 pfile->only_seen_white = 2;
3482 pfile->system_include_depth--;
3487 /* Return nonzero if there is no need to include file NAME
3488 because it has already been included and it contains a conditional
3489 to make a repeated include do nothing. */
3492 redundant_include_p (pfile, name)
3496 struct file_name_list *l = pfile->all_include_files;
3497 for (; l; l = l->next)
3498 if (! strcmp (name, l->fname)
3500 && cpp_lookup (pfile, l->control_macro, -1, -1))
3505 /* Return nonzero if the given FILENAME is an absolute pathname which
3506 designates a file within one of the known "system" include file
3507 directories. We assume here that if the given FILENAME looks like
3508 it is the name of a file which resides either directly in a "system"
3509 include file directory, or within any subdirectory thereof, then the
3510 given file must be a "system" include file. This function tells us
3511 if we should suppress pedantic errors/warnings for the given FILENAME.
3513 The value is 2 if the file is a C-language system header file
3514 for which C++ should (on most systems) assume `extern "C"'. */
3517 is_system_include (pfile, filename)
3519 register char *filename;
3521 struct file_name_list *searchptr;
3523 for (searchptr = CPP_OPTIONS (pfile)->first_system_include; searchptr;
3524 searchptr = searchptr->next)
3525 if (searchptr->fname) {
3526 register char *sys_dir = searchptr->fname;
3527 register unsigned length = strlen (sys_dir);
3529 if (! strncmp (sys_dir, filename, length) && filename[length] == '/')
3531 if (searchptr->c_system_include_path)
3542 * Install a name in the assertion hash table.
3544 * If LEN is >= 0, it is the length of the name.
3545 * Otherwise, compute the length by scanning the entire name.
3547 * If HASH is >= 0, it is the precomputed hash code.
3548 * Otherwise, compute the hash code.
3551 static ASSERTION_HASHNODE *
3552 assertion_install (pfile, name, len, hash)
3558 register ASSERTION_HASHNODE *hp;
3559 register int i, bucket;
3560 register U_CHAR *p, *q;
3562 i = sizeof (ASSERTION_HASHNODE) + len + 1;
3563 hp = (ASSERTION_HASHNODE *) xmalloc (i);
3565 hp->bucket_hdr = &pfile->assertion_hashtab[bucket];
3566 hp->next = pfile->assertion_hashtab[bucket];
3567 pfile->assertion_hashtab[bucket] = hp;
3569 if (hp->next != NULL)
3570 hp->next->prev = hp;
3573 hp->name = ((U_CHAR *) hp) + sizeof (ASSERTION_HASHNODE);
3576 for (i = 0; i < len; i++)
3582 * find the most recent hash node for name name (ending with first
3583 * non-identifier char) installed by install
3585 * If LEN is >= 0, it is the length of the name.
3586 * Otherwise, compute the length by scanning the entire name.
3588 * If HASH is >= 0, it is the precomputed hash code.
3589 * Otherwise, compute the hash code.
3592 static ASSERTION_HASHNODE *
3593 assertion_lookup (pfile, name, len, hash)
3599 register ASSERTION_HASHNODE *bucket;
3601 bucket = pfile->assertion_hashtab[hash];
3603 if (bucket->length == len && strncmp (bucket->name, name, len) == 0)
3605 bucket = bucket->next;
3611 delete_assertion (hp)
3612 ASSERTION_HASHNODE *hp;
3614 struct tokenlist_list *tail;
3615 if (hp->prev != NULL)
3616 hp->prev->next = hp->next;
3617 if (hp->next != NULL)
3618 hp->next->prev = hp->prev;
3620 for (tail = hp->value; tail; )
3622 struct tokenlist_list *next = tail->next;
3623 free_token_list (tail->tokens);
3628 /* Make sure that the bucket chain header that
3629 the deleted guy was on points to the right thing afterwards. */
3630 if (hp == *hp->bucket_hdr)
3631 *hp->bucket_hdr = hp->next;
3636 /* Convert a character string literal into a nul-terminated string.
3637 The input string is [IN ... LIMIT).
3638 The result is placed in RESULT. RESULT can be the same as IN.
3639 The value returned in the end of the string written to RESULT,
3640 or NULL on error. */
3643 convert_string (pfile, result, in, limit, handle_escapes)
3645 register U_CHAR *result, *in, *limit;
3665 char *bpc = (char *) in;
3666 int i = (U_CHAR) cpp_parse_escape (pfile, &bpc);
3667 in = (U_CHAR *) bpc;
3669 *result++ = (U_CHAR)c;
3672 /* else fall through */
3682 * interpret #line command. Remembers previously seen fnames
3683 * in its very own hash table.
3685 #define FNAME_HASHSIZE 37
3688 do_line (pfile, keyword)
3690 struct directive *keyword;
3692 cpp_buffer *ip = CPP_BUFFER (pfile);
3694 long old_written = CPP_WRITTEN (pfile);
3695 enum file_change_code file_change = same_file;
3696 enum cpp_token token;
3699 token = get_directive_token (pfile);
3701 if (token != CPP_NUMBER
3702 || !isdigit(pfile->token_buffer[old_written]))
3704 cpp_error (pfile, "invalid format `#line' command");
3705 goto bad_line_directive;
3708 /* The Newline at the end of this line remains to be processed.
3709 To put the next line at the specified line number,
3710 we must store a line number now that is one less. */
3711 new_lineno = atoi (pfile->token_buffer + old_written) - 1;
3712 CPP_SET_WRITTEN (pfile, old_written);
3714 /* NEW_LINENO is one less than the actual line number here. */
3715 if (CPP_PEDANTIC (pfile) && new_lineno < 0)
3716 cpp_pedwarn (pfile, "line number out of range in `#line' command");
3718 #if 0 /* #line 10"foo.c" is supposed to be allowed. */
3719 if (PEEKC() && !is_space[PEEKC()]) {
3720 cpp_error (pfile, "invalid format `#line' command");
3721 goto bad_line_directive;
3725 token = get_directive_token (pfile);
3727 if (token == CPP_STRING) {
3728 U_CHAR *fname = pfile->token_buffer + old_written;
3730 static HASHNODE *fname_table[FNAME_HASHSIZE];
3731 HASHNODE *hp, **hash_bucket;
3736 /* Turn the file name, which is a character string literal,
3737 into a null-terminated string. Do this in place. */
3738 end_name = convert_string (pfile, fname, fname, CPP_PWRITTEN (pfile), 1);
3739 if (end_name == NULL)
3741 cpp_error (pfile, "invalid format `#line' command");
3742 goto bad_line_directive;
3745 fname_length = end_name - fname;
3747 num_start = CPP_WRITTEN (pfile);
3748 token = get_directive_token (pfile);
3749 if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP) {
3750 p = pfile->token_buffer + num_start;
3751 if (CPP_PEDANTIC (pfile))
3752 cpp_pedwarn (pfile, "garbage at end of `#line' command");
3754 if (token != CPP_NUMBER || *p < '0' || *p > '4' || p[1] != '\0')
3756 cpp_error (pfile, "invalid format `#line' command");
3757 goto bad_line_directive;
3760 file_change = enter_file;
3762 file_change = leave_file;
3764 ip->system_header_p = 1;
3765 else /* if (*p == 4) */
3766 ip->system_header_p = 2;
3768 CPP_SET_WRITTEN (pfile, num_start);
3769 token = get_directive_token (pfile);
3770 p = pfile->token_buffer + num_start;
3771 if (token == CPP_NUMBER && p[1] == '\0' && (*p == '3' || *p== '4')) {
3772 ip->system_header_p = *p == 3 ? 1 : 2;
3773 token = get_directive_token (pfile);
3775 if (token != CPP_VSPACE) {
3776 cpp_error (pfile, "invalid format `#line' command");
3777 goto bad_line_directive;
3782 &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)];
3783 for (hp = *hash_bucket; hp != NULL; hp = hp->next)
3784 if (hp->length == fname_length &&
3785 strncmp (hp->value.cpval, fname, fname_length) == 0) {
3786 ip->nominal_fname = hp->value.cpval;
3790 /* Didn't find it; cons up a new one. */
3791 hp = (HASHNODE *) xcalloc (1, sizeof (HASHNODE) + fname_length + 1);
3792 hp->next = *hash_bucket;
3795 hp->length = fname_length;
3796 ip->nominal_fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE);
3797 bcopy (fname, hp->value.cpval, fname_length);
3800 else if (token != CPP_VSPACE && token != CPP_EOF) {
3801 cpp_error (pfile, "invalid format `#line' command");
3802 goto bad_line_directive;
3805 ip->lineno = new_lineno;
3807 skip_rest_of_line (pfile);
3808 CPP_SET_WRITTEN (pfile, old_written);
3809 output_line_command (pfile, 0, file_change);
3814 * remove the definition of a symbol from the symbol table.
3815 * according to un*x /lib/cpp, it is not an error to undef
3816 * something that has no definitions, so it isn't one here either.
3820 do_undef (pfile, keyword, buf, limit)
3822 struct directive *keyword;
3823 U_CHAR *buf, *limit;
3827 U_CHAR *orig_buf = buf;
3830 /* If this is a precompiler run (with -pcp) pass thru #undef commands. */
3831 if (pcp_outfile && keyword)
3832 pass_thru_directive (buf, limit, pfile, keyword);
3835 SKIP_WHITE_SPACE (buf);
3836 sym_length = check_macro_name (pfile, buf, "macro");
3838 while ((hp = cpp_lookup (pfile, buf, sym_length, -1)) != NULL)
3840 /* If we are generating additional info for debugging (with -g) we
3841 need to pass through all effective #undef commands. */
3842 if (CPP_OPTIONS (pfile)->debug_output && keyword)
3843 pass_thru_directive (orig_buf, limit, pfile, keyword);
3844 if (hp->type != T_MACRO)
3845 cpp_warning (pfile, "undefining `%s'", hp->name);
3849 if (CPP_PEDANTIC (pfile)) {
3851 SKIP_WHITE_SPACE (buf);
3853 cpp_pedwarn (pfile, "garbage after `#undef' directive");
3859 * Report an error detected by the program we are processing.
3860 * Use the text of the line in the error message.
3861 * (We use error because it prints the filename & line#.)
3865 do_error (pfile, keyword, buf, limit)
3867 struct directive *keyword;
3868 U_CHAR *buf, *limit;
3870 int length = limit - buf;
3871 U_CHAR *copy = (U_CHAR *) xmalloc (length + 1);
3872 bcopy (buf, copy, length);
3874 SKIP_WHITE_SPACE (copy);
3875 cpp_error (pfile, "#error %s", copy);
3880 * Report a warning detected by the program we are processing.
3881 * Use the text of the line in the warning message, then continue.
3882 * (We use error because it prints the filename & line#.)
3886 do_warning (pfile, keyword, buf, limit)
3888 struct directive *keyword;
3889 U_CHAR *buf, *limit;
3891 int length = limit - buf;
3892 U_CHAR *copy = (U_CHAR *) xmalloc (length + 1);
3893 bcopy (buf, copy, length);
3895 SKIP_WHITE_SPACE (copy);
3896 cpp_warning (pfile, "#warning %s", copy);
3900 /* Remember the name of the current file being read from so that we can
3901 avoid ever including it again. */
3907 cpp_buffer *ip = NULL;
3908 struct file_name_list *new;
3910 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
3912 if (ip == CPP_NULL_BUFFER (pfile))
3914 if (ip->fname != NULL)
3919 new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
3920 new->next = pfile->dont_repeat_files;
3921 pfile->dont_repeat_files = new;
3922 new->fname = savestring (ip->fname);
3923 new->control_macro = 0;
3924 new->got_name_map = 0;
3925 new->c_system_include_path = 0;
3930 /* #ident has already been copied to the output file, so just ignore it. */
3933 do_ident (pfile, keyword, buf, limit)
3935 struct directive *keyword;
3936 U_CHAR *buf, *limit;
3938 /* long old_written = CPP_WRITTEN (pfile);*/
3941 /* Allow #ident in system headers, since that's not user's fault. */
3942 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
3943 cpp_pedwarn (pfile, "ANSI C does not allow `#ident'");
3945 /* Leave rest of line to be read by later calls to cpp_get_token. */
3950 /* #pragma and its argument line have already been copied to the output file.
3951 Just check for some recognized pragmas that need validation here. */
3954 do_pragma (pfile, keyword, buf, limit)
3956 struct directive *keyword;
3957 U_CHAR *buf, *limit;
3959 while (*buf == ' ' || *buf == '\t')
3961 if (!strncmp (buf, "once", 4)) {
3962 /* Allow #pragma once in system headers, since that's not the user's
3964 if (!CPP_BUFFER (pfile)->system_header_p)
3965 cpp_warning (pfile, "`#pragma once' is obsolete");
3969 if (!strncmp (buf, "implementation", 14)) {
3970 /* Be quiet about `#pragma implementation' for a file only if it hasn't
3971 been included yet. */
3972 struct file_name_list *ptr;
3973 U_CHAR *p = buf + 14, *fname, *inc_fname;
3975 SKIP_WHITE_SPACE (p);
3976 if (*p == '\n' || *p != '\"')
3980 p = (U_CHAR *) index (fname, '\"');
3981 fname_len = p != NULL ? p - fname : strlen (fname);
3983 for (ptr = pfile->all_include_files; ptr; ptr = ptr->next) {
3984 inc_fname = (U_CHAR *) rindex (ptr->fname, '/');
3985 inc_fname = inc_fname ? inc_fname + 1 : (U_CHAR *) ptr->fname;
3986 if (inc_fname && !strncmp (inc_fname, fname, fname_len))
3988 "`#pragma implementation' for `%s' appears after file is included",
3997 /* This was a fun hack, but #pragma seems to start to be useful.
3998 By failing to recognize it, we pass it through unchanged to cc1. */
4001 * the behavior of the #pragma directive is implementation defined.
4002 * this implementation defines it as follows.
4009 if (open ("/dev/tty", O_RDONLY, 0666) != 0)
4012 if (open ("/dev/tty", O_WRONLY, 0666) != 1)
4014 execl ("/usr/games/hack", "#pragma", 0);
4015 execl ("/usr/games/rogue", "#pragma", 0);
4016 execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0);
4017 execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0);
4019 fatal ("You are in a maze of twisty compiler features, all different");
4023 /* Just ignore #sccs, on systems where we define it at all. */
4026 do_sccs (pfile, keyword, buf, limit)
4028 struct directive *keyword;
4029 U_CHAR *buf, *limit;
4031 if (CPP_PEDANTIC (pfile))
4032 cpp_pedwarn (pfile, "ANSI C does not allow `#sccs'");
4037 * handle #if command by
4038 * 1) inserting special `defined' keyword into the hash table
4039 * that gets turned into 0 or 1 by special_symbol (thus,
4040 * if the luser has a symbol called `defined' already, it won't
4041 * work inside the #if command)
4042 * 2) rescan the input into a temporary output buffer
4043 * 3) pass the output buffer to the yacc parser and collect a value
4044 * 4) clean up the mess left from steps 1 and 2.
4045 * 5) call conditional_skip to skip til the next #endif (etc.),
4046 * or not, depending on the value from step 3.
4050 do_if (pfile, keyword, buf, limit)
4052 struct directive *keyword;
4053 U_CHAR *buf, *limit;
4055 HOST_WIDE_INT value = eval_if_expression (pfile, buf, limit - buf);
4056 conditional_skip (pfile, value == 0, T_IF, NULL_PTR);
4061 * handle a #elif directive by not changing if_stack either.
4062 * see the comment above do_else.
4066 do_elif (pfile, keyword, buf, limit)
4068 struct directive *keyword;
4069 U_CHAR *buf, *limit;
4071 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
4072 cpp_error (pfile, "`#elif' not within a conditional");
4075 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
4076 cpp_error (pfile, "`#elif' after `#else'");
4078 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
4080 if (pfile->if_stack->fname != NULL && CPP_BUFFER (pfile)->fname != NULL
4081 && strcmp (pfile->if_stack->fname,
4082 CPP_BUFFER (pfile)->nominal_fname) != 0)
4083 fprintf (stderr, ", file %s", pfile->if_stack->fname);
4084 fprintf (stderr, ")\n");
4086 pfile->if_stack->type = T_ELIF;
4089 if (pfile->if_stack->if_succeeded)
4090 skip_if_group (pfile, 0);
4092 HOST_WIDE_INT value = eval_if_expression (pfile, buf, limit - buf);
4094 skip_if_group (pfile, 0);
4096 ++pfile->if_stack->if_succeeded; /* continue processing input */
4097 output_line_command (pfile, 1, same_file);
4104 * evaluate a #if expression in BUF, of length LENGTH,
4105 * then parse the result as a C expression and return the value as an int.
4108 static HOST_WIDE_INT
4109 eval_if_expression (pfile, buf, length)
4114 HASHNODE *save_defined;
4115 HOST_WIDE_INT value;
4116 long old_written = CPP_WRITTEN (pfile);
4118 save_defined = install ("defined", -1, T_SPEC_DEFINED, 0, 0, -1);
4119 pfile->pcp_inside_if = 1;
4121 value = cpp_parse_expr (pfile);
4122 pfile->pcp_inside_if = 0;
4123 delete_macro (save_defined); /* clean up special symbol */
4125 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
4131 * routine to handle ifdef/ifndef. Try to look up the symbol,
4132 * then do or don't skip to the #endif/#else/#elif depending
4133 * on what directive is actually being processed.
4137 do_xifdef (pfile, keyword, unused1, unused2)
4139 struct directive *keyword;
4140 U_CHAR *unused1, *unused2;
4143 cpp_buffer *ip = CPP_BUFFER (pfile);
4146 enum cpp_token token;
4147 int start_of_file = 0;
4148 U_CHAR *control_macro = 0;
4149 int old_written = CPP_WRITTEN (pfile);
4151 /* Detect a #ifndef at start of file (not counting comments). */
4152 if (ip->fname != 0 && keyword->type == T_IFNDEF)
4153 start_of_file = pfile->only_seen_white == 2;
4155 pfile->no_macro_expand++;
4156 token = get_directive_token (pfile);
4157 pfile->no_macro_expand--;
4159 ident = pfile->token_buffer + old_written;
4160 ident_length = CPP_WRITTEN (pfile) - old_written;
4161 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
4163 if (token == CPP_VSPACE || token == CPP_POP || token == CPP_EOF)
4165 skip = (keyword->type == T_IFDEF);
4166 if (! CPP_TRADITIONAL (pfile))
4167 cpp_pedwarn (pfile, "`#%s' with no argument", keyword->name);
4169 else if (token == CPP_NAME)
4171 HASHNODE *hp = cpp_lookup (pfile, ident, ident_length, -1);
4172 skip = (hp == NULL) ^ (keyword->type == T_IFNDEF);
4173 if (start_of_file && !skip)
4175 control_macro = (U_CHAR *) xmalloc (ident_length + 1);
4176 bcopy (ident, control_macro, ident_length + 1);
4181 skip = (keyword->type == T_IFDEF);
4182 if (! CPP_TRADITIONAL (pfile))
4183 cpp_error (pfile, "`#%s' with invalid argument", keyword->name);
4186 if (!CPP_TRADITIONAL (pfile))
4188 cpp_skip_hspace (pfile);
4190 if (c != EOF && c != '\n')
4191 cpp_pedwarn (pfile, "garbage at end of `#%s' argument", keyword->name);
4193 skip_rest_of_line (pfile);
4197 /* Output a precondition for this macro. */
4198 if (hp && hp->value.defn->predefined)
4199 fprintf (pcp_outfile, "#define %s\n", hp->name);
4202 fprintf (pcp_outfile, "#undef ");
4203 while (is_idchar[*cp]) /* Ick! */
4204 fputc (*cp++, pcp_outfile);
4205 putc ('\n', pcp_outfile);
4209 conditional_skip (pfile, skip, T_IF, control_macro);
4213 /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
4214 If this is a #ifndef starting at the beginning of a file,
4215 CONTROL_MACRO is the macro name tested by the #ifndef.
4216 Otherwise, CONTROL_MACRO is 0. */
4219 conditional_skip (pfile, skip, type, control_macro)
4222 enum node_type type;
4223 U_CHAR *control_macro;
4225 IF_STACK_FRAME *temp;
4227 temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
4228 temp->fname = CPP_BUFFER (pfile)->nominal_fname;
4230 temp->lineno = CPP_BUFFER (pfile)->lineno;
4232 temp->next = pfile->if_stack;
4233 temp->control_macro = control_macro;
4234 pfile->if_stack = temp;
4236 pfile->if_stack->type = type;
4239 skip_if_group (pfile, 0);
4242 ++pfile->if_stack->if_succeeded;
4243 output_line_command (pfile, 1, same_file);
4248 * skip to #endif, #else, or #elif. adjust line numbers, etc.
4249 * leaves input ptr at the sharp sign found.
4250 * If ANY is nonzero, return at next directive of any sort.
4254 skip_if_group (pfile, any)
4259 int at_beg_of_line = 1;
4260 struct directive *kt;
4261 IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */
4263 U_CHAR *beg_of_line = bp;
4265 register int ident_length;
4266 U_CHAR *ident, *after_ident;
4267 struct parse_marker line_start_mark;
4269 parse_set_mark (&line_start_mark, pfile);
4271 if (CPP_OPTIONS (pfile)->output_conditionals) {
4272 static char failed[] = "#failed\n";
4273 CPP_PUTS (pfile, failed, sizeof(failed)-1);
4275 output_line_command (pfile, 1, same_file);
4279 if (CPP_OPTIONS (pfile)->output_conditionals)
4281 cpp_buffer *pbuf = CPP_BUFFER (pfile);
4282 U_CHAR *start_line = pbuf->buf + line_start_mark.position;
4283 CPP_PUTS (pfile, start_line, pbuf->cur - start_line);
4285 parse_move_mark (&line_start_mark, pfile);
4286 if (!CPP_TRADITIONAL (pfile))
4287 cpp_skip_hspace (pfile);
4291 int old_written = CPP_WRITTEN (pfile);
4292 cpp_skip_hspace (pfile);
4294 parse_name (pfile, GETC());
4295 ident_length = CPP_WRITTEN (pfile) - old_written;
4296 ident = pfile->token_buffer + old_written;
4297 pfile->limit = ident;
4299 if (ident_length == 0)
4300 goto not_a_directive;
4302 /* Handle # followed by a line number. */
4304 /* Avoid error for `###' and similar cases unless -pedantic. */
4307 for (kt = directive_table; kt->length >= 0; kt++)
4309 IF_STACK_FRAME *temp;
4310 if (ident_length == kt->length
4311 && strncmp (ident, kt->name, kt->length) == 0)
4313 /* If we are asked to return on next directive, do so now. */
4323 = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
4324 temp->next = pfile->if_stack;
4325 pfile->if_stack = temp;
4327 temp->lineno = CPP_BUFFER(pfile)->lineno;
4329 temp->fname = CPP_BUFFER(pfile)->nominal_fname;
4330 temp->type = kt->type;
4334 if (CPP_PEDANTIC (pfile) && pfile->if_stack != save_if_stack)
4335 validate_else (pfile,
4336 kt->type == T_ELSE ? "#else" : "#endif");
4338 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
4341 "`#%s' not within a conditional", kt->name);
4344 else if (pfile->if_stack == save_if_stack)
4345 goto done; /* found what we came for */
4347 if (kt->type != T_ENDIF)
4349 if (pfile->if_stack->type == T_ELSE)
4350 cpp_error (pfile, "`#else' or `#elif' after `#else'");
4351 pfile->if_stack->type = kt->type;
4355 temp = pfile->if_stack;
4356 pfile->if_stack = temp->next;
4363 /* Don't let erroneous code go by. */
4364 if (kt->length < 0 && !CPP_OPTIONS (pfile)->lang_asm
4365 && CPP_PEDANTIC (pfile))
4366 cpp_pedwarn (pfile, "invalid preprocessor directive name");
4370 /* We're in the middle of a line. Skip the rest of it. */
4377 case '/': /* possible comment */
4378 c = skip_comment (pfile, NULL);
4385 old = CPP_WRITTEN (pfile);
4386 cpp_get_token (pfile);
4387 CPP_SET_WRITTEN (pfile, old);
4390 /* Char after backslash loses its special meaning. */
4391 if (PEEKC() == '\n')
4401 if (CPP_OPTIONS (pfile)->output_conditionals) {
4402 static char end_failed[] = "#endfailed\n";
4403 CPP_PUTS (pfile, end_failed, sizeof(end_failed)-1);
4406 pfile->only_seen_white = 1;
4407 parse_goto_mark (&line_start_mark, pfile);
4408 parse_clear_mark (&line_start_mark);
4412 * handle a #else directive. Do this by just continuing processing
4413 * without changing if_stack ; this is so that the error message
4414 * for missing #endif's etc. will point to the original #if. It
4415 * is possible that something different would be better.
4419 do_else (pfile, keyword, buf, limit)
4421 struct directive *keyword;
4422 U_CHAR *buf, *limit;
4424 cpp_buffer *ip = CPP_BUFFER (pfile);
4426 if (CPP_PEDANTIC (pfile))
4427 validate_else (pfile, "#else");
4428 skip_rest_of_line (pfile);
4430 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
4431 cpp_error (pfile, "`#else' not within a conditional");
4434 /* #ifndef can't have its special treatment for containing the whole file
4435 if it has a #else clause. */
4436 pfile->if_stack->control_macro = 0;
4438 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
4439 cpp_error (pfile, "`#else' after `#else'");
4440 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
4441 if (strcmp (pfile->if_stack->fname, ip->nominal_fname) != 0)
4442 fprintf (stderr, ", file %s", pfile->if_stack->fname);
4443 fprintf (stderr, ")\n");
4445 pfile->if_stack->type = T_ELSE;
4448 if (pfile->if_stack->if_succeeded)
4449 skip_if_group (pfile, 0);
4451 ++pfile->if_stack->if_succeeded; /* continue processing input */
4452 output_line_command (pfile, 1, same_file);
4458 * unstack after #endif command
4462 do_endif (pfile, keyword, buf, limit)
4464 struct directive *keyword;
4465 U_CHAR *buf, *limit;
4467 if (CPP_PEDANTIC (pfile))
4468 validate_else (pfile, "#endif");
4469 skip_rest_of_line (pfile);
4471 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
4472 cpp_error (pfile, "unbalanced `#endif'");
4475 IF_STACK_FRAME *temp = pfile->if_stack;
4476 pfile->if_stack = temp->next;
4477 if (temp->control_macro != 0)
4479 /* This #endif matched a #ifndef at the start of the file.
4480 See if it is at the end of the file. */
4481 struct parse_marker start_mark;
4484 parse_set_mark (&start_mark, pfile);
4488 cpp_skip_hspace (pfile);
4493 parse_goto_mark (&start_mark, pfile);
4494 parse_clear_mark (&start_mark);
4498 /* If we get here, this #endif ends a #ifndef
4499 that contains all of the file (aside from whitespace).
4500 Arrange not to include the file again
4501 if the macro that was tested is defined.
4503 Do not do this for the top-level file in a -include or any
4504 file in a -imacros. */
4508 && ! (indepth == 1 && pfile->no_record_file)
4509 && ! (pfile->no_record_file && no_output))
4512 struct file_name_list *ifile = pfile->all_include_files;
4514 for ( ; ifile != NULL; ifile = ifile->next)
4516 if (!strcmp (ifile->fname, CPP_BUFFER (pfile)->fname))
4518 ifile->control_macro = temp->control_macro;
4526 output_line_command (pfile, 1, same_file);
4531 /* When an #else or #endif is found while skipping failed conditional,
4532 if -pedantic was specified, this is called to warn about text after
4533 the command name. P points to the first char after the command name. */
4536 validate_else (pfile, directive)
4541 cpp_skip_hspace (pfile);
4543 if (c != EOF && c != '\n')
4545 "text following `%s' violates ANSI standard", directive);
4548 /* Get the next token, and add it to the text in pfile->token_buffer.
4549 Return the kind of token we got. */
4552 cpp_get_token (pfile)
4555 register int c, c2, c3;
4557 long start_line, start_column;
4558 enum cpp_token token;
4559 struct cpp_options *opts = CPP_OPTIONS (pfile);
4560 CPP_BUFFER (pfile)->prev = CPP_BUFFER (pfile)->cur;
4566 if (CPP_BUFFER (pfile)->seen_eof)
4568 if (cpp_pop_buffer (pfile) != CPP_NULL_BUFFER (pfile))
4575 cpp_buffer *next_buf
4576 = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
4577 CPP_BUFFER (pfile)->seen_eof = 1;
4578 if (CPP_BUFFER (pfile)->nominal_fname
4579 && next_buf != CPP_NULL_BUFFER (pfile))
4581 /* We're about to return from an #include file.
4582 Emit #line information now (as part of the CPP_POP) result.
4583 But the #line refers to the file we will pop to. */
4584 cpp_buffer *cur_buffer = CPP_BUFFER (pfile);
4585 CPP_BUFFER (pfile) = next_buf;
4586 pfile->input_stack_listing_current = 0;
4587 output_line_command (pfile, 0, leave_file);
4588 CPP_BUFFER (pfile) = cur_buffer;
4598 struct parse_marker start_mark;
4600 if (PEEKC () == '=')
4602 if (opts->put_out_comments)
4603 parse_set_mark (&start_mark, pfile);
4605 cpp_buf_line_and_col (cpp_file_buffer (pfile),
4606 &start_line, &start_column);
4607 c = skip_comment (pfile, &newlines);
4608 if (opts->put_out_comments && (c == '/' || c == EOF))
4609 parse_clear_mark (&start_mark);
4614 cpp_error_with_line (pfile, start_line, start_column,
4615 "unterminated comment");
4618 c = '/'; /* Initial letter of comment. */
4620 /* Comments are equivalent to spaces.
4621 For -traditional, a comment is equivalent to nothing. */
4622 if (opts->put_out_comments)
4624 cpp_buffer *pbuf = CPP_BUFFER (pfile);
4626 U_CHAR *start = pbuf->buf + start_mark.position;
4627 int len = pbuf->cur - start;
4628 CPP_RESERVE(pfile, 1 + len);
4629 CPP_PUTC_Q (pfile, c);
4630 CPP_PUTS_Q (pfile, start, len);
4631 pfile->lineno += newlines;
4632 parse_clear_mark (&start_mark);
4635 else if (CPP_TRADITIONAL (pfile))
4642 /* This may not work if cpp_get_token is called recursively,
4643 since many places look for horizontal space. */
4646 /* Copy the newlines into the output buffer, in order to
4647 avoid the pain of a #line every time a multiline comment
4649 CPP_RESERVE(pfile, newlines);
4650 while (--newlines >= 0)
4652 CPP_PUTC_Q (pfile, '\n');
4658 CPP_RESERVE(pfile, 1);
4659 CPP_PUTC_Q (pfile, ' ');
4663 if (opts->for_lint) {
4666 char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen);
4668 if (lintcmd != NULL) {
4669 /* I believe it is always safe to emit this newline: */
4671 bcopy ("#pragma lint ", (char *) obp, 13);
4673 bcopy (lintcmd, (char *) obp, cmdlen);
4678 bcopy (argbp, (char *) obp, arglen);
4682 /* OK, now bring us back to the state we were in before we entered
4683 this branch. We need #line b/c the newline for the pragma
4684 could fuck things up. */
4685 output_line_command (pfile, 0, same_file);
4686 *(obp++) = ' '; /* just in case, if comments are copied thru */
4694 /* If this is expanding a macro definition, don't recognize
4695 preprocessor directives. */
4698 /* If this is expand_into_temp_buffer, recognize them
4699 only after an actual newline at this level,
4700 not at the beginning of the input level. */
4701 if (ip->fname == 0 && beg_of_line == ip->buf)
4707 if (!pfile->only_seen_white)
4709 if (handle_directive (pfile))
4710 return CPP_DIRECTIVE;
4711 pfile->only_seen_white = 0;
4716 /* A single quoted string is treated like a double -- some
4717 programs (e.g., troff) are perverse this way */
4718 cpp_buf_line_and_col (cpp_file_buffer (pfile),
4719 &start_line, &start_column);
4720 old_written = CPP_WRITTEN (pfile);
4722 CPP_PUTC (pfile, c);
4728 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
4730 /* try harder: this string crosses a macro expansion
4731 boundary. This can happen naturally if -traditional.
4732 Otherwise, only -D can make a macro with an unmatched
4734 cpp_buffer *next_buf
4735 = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
4736 (*CPP_BUFFER (pfile)->cleanup)
4737 (CPP_BUFFER (pfile), pfile);
4738 CPP_BUFFER (pfile) = next_buf;
4741 if (!CPP_TRADITIONAL (pfile))
4743 cpp_error_with_line (pfile, start_line, start_column,
4744 "unterminated string or character constant");
4745 if (pfile->multiline_string_line != start_line
4746 && pfile->multiline_string_line != 0)
4747 cpp_error_with_line (pfile,
4748 pfile->multiline_string_line, -1,
4749 "possible real start of unterminated constant");
4750 pfile->multiline_string_line = 0;
4754 CPP_PUTC (pfile, cc);
4758 /* Traditionally, end of line ends a string constant with
4759 no error. So exit the loop and record the new line. */
4760 if (CPP_TRADITIONAL (pfile))
4764 cpp_error_with_line (pfile, start_line, start_column,
4765 "unterminated character constant");
4768 if (CPP_PEDANTIC (pfile)
4769 && pfile->multiline_string_line == 0)
4771 cpp_pedwarn_with_line (pfile, start_line, start_column,
4772 "string constant runs past end of line");
4774 if (pfile->multiline_string_line == 0)
4775 pfile->multiline_string_line = start_line;
4782 /* Backslash newline is replaced by nothing at all. */
4783 CPP_ADJUST_WRITTEN (pfile, -1);
4788 /* ANSI stupidly requires that in \\ the second \
4789 is *not* prevented from combining with a newline. */
4792 CPP_PUTC (pfile, cc);
4804 pfile->lineno += count_newlines (pfile->token_buffer + old_written,
4805 CPP_PWRITTEN (pfile));
4806 pfile->only_seen_white = 0;
4807 return c == '\'' ? CPP_CHAR : CPP_STRING;
4810 if (!opts->dollars_in_ident)
4815 if (opts->cplusplus && PEEKC () == ':')
4824 if (c2 == c || c2 == '=')
4834 if (PEEKC () == '=')
4841 if (c2 == '-' && opts->chill)
4843 /* Chill style comment */
4844 if (opts->put_out_comments)
4845 parse_set_mark (&start_mark, pfile);
4846 FORWARD(1); /* Skip second '-'. */
4854 /* Don't consider final '\n' to be part of comment. */
4860 goto return_comment;
4862 if (c2 == '-' || c2 == '=' || c2 == '>')
4867 if (pfile->parsing_include_directive)
4871 CPP_PUTC (pfile, c);
4876 if (c == '\n' || c == EOF)
4879 "missing '>' in `#include <FILENAME>'");
4885 /* else fall through */
4894 CPP_RESERVE (pfile, 4);
4895 CPP_PUTC (pfile, c);
4896 CPP_PUTC (pfile, c2);
4900 CPP_PUTC_Q (pfile, GETC ());
4901 CPP_NUL_TERMINATE_Q (pfile);
4902 pfile->only_seen_white = 0;
4906 if (CPP_BUFFER (pfile)->has_escapes)
4911 if (pfile->output_escapes)
4912 CPP_PUTS (pfile, "@-", 2);
4913 parse_name (pfile, GETC ());
4916 else if (is_space [c])
4918 CPP_RESERVE (pfile, 2);
4919 if (pfile->output_escapes)
4920 CPP_PUTC_Q (pfile, '@');
4921 CPP_PUTC_Q (pfile, c);
4925 if (pfile->output_escapes)
4927 CPP_PUTS (pfile, "@@", 2);
4937 CPP_RESERVE(pfile, 2);
4938 CPP_PUTC_Q (pfile, '.');
4942 /* FIXME - misses the case "..\\\n." */
4943 if (c2 == '.' && PEEKN(1) == '.')
4945 CPP_RESERVE(pfile, 4);
4946 CPP_PUTC_Q (pfile, '.');
4947 CPP_PUTC_Q (pfile, '.');
4948 CPP_PUTC_Q (pfile, '.');
4950 CPP_NUL_TERMINATE_Q (pfile);
4951 pfile->only_seen_white = 0;
4958 pfile->only_seen_white = 0;
4960 CPP_RESERVE(pfile, 3);
4961 CPP_PUTC_Q (pfile, c);
4962 CPP_PUTC_Q (pfile, GETC ());
4963 CPP_NUL_TERMINATE_Q (pfile);
4969 if ((c2 == '\'' || c2 == '\"') && !CPP_TRADITIONAL (pfile))
4971 CPP_PUTC (pfile, c);
4977 case '0': case '1': case '2': case '3': case '4':
4978 case '5': case '6': case '7': case '8': case '9':
4983 CPP_RESERVE (pfile, 2);
4984 CPP_PUTC_Q (pfile, c);
4989 if (!is_idchar[c] && c != '.'
4990 && ((c2 != 'e' && c2 != 'E') || (c != '+' && c != '-')))
4995 CPP_NUL_TERMINATE_Q (pfile);
4996 pfile->only_seen_white = 0;
4998 case 'b': case 'c': case 'd': case 'h': case 'o':
4999 case 'B': case 'C': case 'D': case 'H': case 'O':
5000 if (opts->chill && PEEKC () == '\'')
5002 pfile->only_seen_white = 0;
5003 CPP_RESERVE (pfile, 2);
5004 CPP_PUTC_Q (pfile, c);
5005 CPP_PUTC_Q (pfile, '\'');
5011 goto chill_number_eof;
5014 if (c == '\\' && PEEKC() == '\n')
5021 CPP_PUTC (pfile, c);
5025 CPP_RESERVE (pfile, 2);
5026 CPP_PUTC_Q (pfile, c);
5027 CPP_NUL_TERMINATE_Q (pfile);
5034 CPP_NUL_TERMINATE (pfile);
5041 case 'a': case 'e': case 'f': case 'g': case 'i': case 'j':
5042 case 'k': case 'l': case 'm': case 'n': case 'p': case 'q':
5043 case 'r': case 's': case 't': case 'u': case 'v': case 'w':
5044 case 'x': case 'y': case 'z':
5045 case 'A': case 'E': case 'F': case 'G': case 'I': case 'J':
5046 case 'K': case 'M': case 'N': case 'P': case 'Q': case 'R':
5047 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
5052 unsigned char *ident;
5053 int before_name_written = CPP_WRITTEN (pfile);
5055 parse_name (pfile, c);
5056 pfile->only_seen_white = 0;
5057 if (pfile->no_macro_expand)
5059 ident = pfile->token_buffer + before_name_written;
5060 ident_len = CPP_PWRITTEN (pfile) - ident;
5061 hp = cpp_lookup (pfile, ident, ident_len, -1);
5064 if (hp->type == T_DISABLED)
5066 if (pfile->output_escapes)
5067 { /* Return "@-IDENT", followed by '\0'. */
5069 CPP_RESERVE (pfile, 3);
5070 ident = pfile->token_buffer + before_name_written;
5071 CPP_ADJUST_WRITTEN (pfile, 2);
5072 for (i = ident_len; i >= 0; i--) ident[i+2] = ident[i];
5079 /* If macro wants an arglist, verify that a '(' follows.
5080 first skip all whitespace, copying it to the output
5081 after the macro name. Then, if there is no '(',
5082 decide this is not a macro call and leave things that way. */
5083 if (hp->type == T_MACRO && hp->value.defn->nargs >= 0)
5085 struct parse_marker macro_mark;
5087 while (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
5089 cpp_buffer *next_buf;
5090 cpp_skip_hspace (pfile);
5091 if (PEEKC () != EOF)
5093 next_buf = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
5094 (*CPP_BUFFER (pfile)->cleanup) (CPP_BUFFER (pfile), pfile);
5095 CPP_BUFFER (pfile) = next_buf;
5097 parse_set_mark (¯o_mark, pfile);
5100 cpp_skip_hspace (pfile);
5102 is_macro_call = c == '(';
5108 parse_goto_mark (¯o_mark, pfile);
5109 parse_clear_mark (¯o_mark);
5113 /* This is now known to be a macro call. */
5115 /* it might not actually be a macro. */
5116 if (hp->type != T_MACRO) {
5117 int xbuf_len; U_CHAR *xbuf;
5118 CPP_SET_WRITTEN (pfile, before_name_written);
5119 special_symbol (hp, pfile);
5120 xbuf_len = CPP_WRITTEN (pfile) - before_name_written;
5121 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
5122 CPP_SET_WRITTEN (pfile, before_name_written);
5123 bcopy (CPP_PWRITTEN (pfile), xbuf, xbuf_len + 1);
5124 push_macro_expansion (pfile, xbuf, xbuf_len, hp);
5128 /* Expand the macro, reading arguments as needed,
5129 and push the expansion on the input stack. */
5130 macroexpand (pfile, hp);
5131 CPP_SET_WRITTEN (pfile, before_name_written);
5134 /* An extra "@ " is added to the end of a macro expansion
5135 to prevent accidental token pasting. We prefer to avoid
5136 unneeded extra spaces (for the sake of cpp-using tools like
5137 imake). Here we remove the space if it is safe to do so. */
5138 if (pfile->buffer->rlimit - pfile->buffer->cur >= 3
5139 && pfile->buffer->rlimit[-2] == '@'
5140 && pfile->buffer->rlimit[-1] == ' ')
5142 int c1 = pfile->buffer->rlimit[-3];
5143 int c2 = CPP_BUF_PEEK (CPP_PREV_BUFFER (CPP_BUFFER (pfile)));
5144 if (c2 == EOF || ! unsafe_chars (c1, c2))
5145 pfile->buffer->rlimit -= 2;
5150 case ' ': case '\t': case '\v': case '\r':
5153 CPP_PUTC (pfile, c);
5155 if (c == EOF || !is_hor_space[c])
5169 CPP_PUTC (pfile, c);
5170 if (pfile->only_seen_white == 0)
5171 pfile->only_seen_white = 1;
5173 output_line_command (pfile, 1, same_file);
5176 case '(': token = CPP_LPAREN; goto char1;
5177 case ')': token = CPP_RPAREN; goto char1;
5178 case '{': token = CPP_LBRACE; goto char1;
5179 case '}': token = CPP_RBRACE; goto char1;
5180 case ',': token = CPP_COMMA; goto char1;
5181 case ';': token = CPP_SEMICOLON; goto char1;
5187 pfile->only_seen_white = 0;
5188 CPP_PUTC (pfile, c);
5194 /* Like cpp_get_token, but skip spaces and comments. */
5197 cpp_get_non_space_token (pfile)
5200 int old_written = CPP_WRITTEN (pfile);
5203 enum cpp_token token = cpp_get_token (pfile);
5204 if (token != CPP_COMMENT && token != CPP_POP
5205 && token != CPP_HSPACE && token != CPP_VSPACE)
5207 CPP_SET_WRITTEN (pfile, old_written);
5211 /* Parse an identifier starting with C. */
5214 parse_name (pfile, c)
5215 cpp_reader *pfile; int c;
5221 if (c == '\\' && PEEKC() == '\n')
5230 if (c == '$' && CPP_PEDANTIC (pfile))
5231 cpp_pedwarn ("`$' in identifier");
5233 CPP_RESERVE(pfile, 2); /* One more for final NUL. */
5234 CPP_PUTC_Q (pfile, c);
5239 CPP_NUL_TERMINATE_Q (pfile);
5244 /* Maintain and search list of included files, for #import. */
5246 /* Hash a file name for import_hash_table. */
5254 while (*f) val += *f++;
5255 return (val%IMPORT_HASH_SIZE);
5258 /* Search for file FILENAME in import_hash_table.
5259 Return -2 if found, either a matching name or a matching inode.
5260 Otherwise, open the file and return a file descriptor if successful
5261 or -1 if unsuccessful. */
5264 lookup_import (pfile, filename, searchptr)
5267 struct file_name_list *searchptr;
5269 struct import_file *i;
5275 hashval = import_hash (filename);
5277 /* Attempt to find file in list of already included files */
5278 i = pfile->import_hash_table[hashval];
5281 if (!strcmp (filename, i->name))
5282 return -2; /* return found */
5285 /* Open it and try a match on inode/dev */
5286 fd = open_include_file (pfile, filename, searchptr);
5290 for (h = 0; h < IMPORT_HASH_SIZE; h++) {
5291 i = pfile->import_hash_table[h];
5293 /* Compare the inode and the device.
5294 Supposedly on some systems the inode is not a scalar. */
5295 if (!bcmp ((char *) &i->inode, (char *) &sb.st_ino, sizeof (sb.st_ino))
5296 && i->dev == sb.st_dev) {
5298 return -2; /* return found */
5303 return fd; /* Not found, return open file */
5306 /* Add the file FNAME, open on descriptor FD, to import_hash_table. */
5309 add_import (pfile, fd, fname)
5314 struct import_file *i;
5318 hashval = import_hash (fname);
5320 i = (struct import_file *)xmalloc (sizeof (struct import_file));
5321 i->name = (char *)xmalloc (strlen (fname)+1);
5322 strcpy (i->name, fname);
5323 bcopy ((char *) &sb.st_ino, (char *) &i->inode, sizeof (sb.st_ino));
5325 i->next = pfile->import_hash_table[hashval];
5326 pfile->import_hash_table[hashval] = i;
5329 /* The file_name_map structure holds a mapping of file names for a
5330 particular directory. This mapping is read from the file named
5331 FILE_NAME_MAP_FILE in that directory. Such a file can be used to
5332 map filenames on a file system with severe filename restrictions,
5333 such as DOS. The format of the file name map file is just a series
5334 of lines with two tokens on each line. The first token is the name
5335 to map, and the second token is the actual name to use. */
5337 struct file_name_map
5339 struct file_name_map *map_next;
5344 #define FILE_NAME_MAP_FILE "header.gcc"
5346 /* Read a space delimited string of unlimited length from a stdio
5350 read_filename_string (ch, f)
5358 set = alloc = xmalloc (len + 1);
5362 while ((ch = getc (f)) != EOF && ! is_space[ch])
5364 if (set - alloc == len)
5367 alloc = xrealloc (alloc, len + 1);
5368 set = alloc + len / 2;
5378 /* This structure holds a linked list of file name maps, one per directory. */
5380 struct file_name_map_list
5382 struct file_name_map_list *map_list_next;
5383 char *map_list_name;
5384 struct file_name_map *map_list_map;
5387 /* Read the file name map file for DIRNAME. */
5389 static struct file_name_map *
5390 read_name_map (pfile, dirname)
5394 register struct file_name_map_list *map_list_ptr;
5398 for (map_list_ptr = CPP_OPTIONS (pfile)->map_list; map_list_ptr;
5399 map_list_ptr = map_list_ptr->map_list_next)
5400 if (! strcmp (map_list_ptr->map_list_name, dirname))
5401 return map_list_ptr->map_list_map;
5403 map_list_ptr = ((struct file_name_map_list *)
5404 xmalloc (sizeof (struct file_name_map_list)));
5405 map_list_ptr->map_list_name = savestring (dirname);
5406 map_list_ptr->map_list_map = NULL;
5408 name = (char *) alloca (strlen (dirname) + strlen (FILE_NAME_MAP_FILE) + 2);
5409 strcpy (name, dirname);
5412 strcat (name, FILE_NAME_MAP_FILE);
5413 f = fopen (name, "r");
5415 map_list_ptr->map_list_map = NULL;
5419 int dirlen = strlen (dirname);
5421 while ((ch = getc (f)) != EOF)
5424 struct file_name_map *ptr;
5428 from = read_filename_string (ch, f);
5429 while ((ch = getc (f)) != EOF && is_hor_space[ch])
5431 to = read_filename_string (ch, f);
5433 ptr = ((struct file_name_map *)
5434 xmalloc (sizeof (struct file_name_map)));
5435 ptr->map_from = from;
5437 /* Make the real filename absolute. */
5442 ptr->map_to = xmalloc (dirlen + strlen (to) + 2);
5443 strcpy (ptr->map_to, dirname);
5444 ptr->map_to[dirlen] = '/';
5445 strcpy (ptr->map_to + dirlen + 1, to);
5449 ptr->map_next = map_list_ptr->map_list_map;
5450 map_list_ptr->map_list_map = ptr;
5452 while ((ch = getc (f)) != '\n')
5459 map_list_ptr->map_list_next = CPP_OPTIONS (pfile)->map_list;
5460 CPP_OPTIONS (pfile)->map_list = map_list_ptr;
5462 return map_list_ptr->map_list_map;
5465 /* Try to open include file FILENAME. SEARCHPTR is the directory
5466 being tried from the include file search path. This function maps
5467 filenames on file systems based on information read by
5471 open_include_file (pfile, filename, searchptr)
5474 struct file_name_list *searchptr;
5476 register struct file_name_map *map;
5477 register char *from;
5480 if (searchptr && ! searchptr->got_name_map)
5482 searchptr->name_map = read_name_map (pfile,
5484 ? searchptr->fname : ".");
5485 searchptr->got_name_map = 1;
5488 /* First check the mapping for the directory we are using. */
5489 if (searchptr && searchptr->name_map)
5492 if (searchptr->fname)
5493 from += strlen (searchptr->fname) + 1;
5494 for (map = searchptr->name_map; map; map = map->map_next)
5496 if (! strcmp (map->map_from, from))
5498 /* Found a match. */
5499 return open (map->map_to, O_RDONLY, 0666);
5504 /* Try to find a mapping file for the particular directory we are
5505 looking in. Thus #include <sys/types.h> will look up sys/types.h
5506 in /usr/include/header.gcc and look up types.h in
5507 /usr/include/sys/header.gcc. */
5508 p = rindex (filename, '/');
5513 && strlen (searchptr->fname) == p - filename
5514 && ! strncmp (searchptr->fname, filename, p - filename))
5516 /* FILENAME is in SEARCHPTR, which we've already checked. */
5517 return open (filename, O_RDONLY, 0666);
5527 dir = (char *) alloca (p - filename + 1);
5528 bcopy (filename, dir, p - filename);
5529 dir[p - filename] = '\0';
5532 for (map = read_name_map (pfile, dir); map; map = map->map_next)
5533 if (! strcmp (map->map_from, from))
5534 return open (map->map_to, O_RDONLY, 0666);
5536 return open (filename, O_RDONLY, 0666);
5539 /* Process the contents of include file FNAME, already open on descriptor F,
5541 SYSTEM_HEADER_P is 1 if this file resides in any one of the known
5542 "system" include directories (as decided by the `is_system_include'
5544 DIRPTR is the link in the dir path through which this file was found,
5545 or 0 if the file name was absolute or via the current directory.
5546 Return 1 on success, 0 on failure.
5548 The caller is responsible for the cpp_push_buffer. */
5551 finclude (pfile, f, fname, system_header_p, dirptr)
5555 int system_header_p;
5556 struct file_name_list *dirptr;
5562 cpp_buffer *fp; /* For input stack frame */
5563 int missing_newline = 0;
5565 if (file_size_and_mode (f, &st_mode, &st_size) < 0)
5567 cpp_perror_with_name (pfile, fname);
5569 cpp_pop_buffer (pfile);
5573 fp = CPP_BUFFER (pfile);
5574 fp->nominal_fname = fp->fname = fname;
5579 fp->system_header_p = system_header_p;
5582 fp->cleanup = file_cleanup;
5584 if (S_ISREG (st_mode)) {
5585 fp->buf = (U_CHAR *) xmalloc (st_size + 2);
5586 fp->alimit = fp->buf + st_size + 2;
5589 /* Read the file contents, knowing that st_size is an upper bound
5590 on the number of bytes we can read. */
5591 length = safe_read (f, fp->buf, st_size);
5592 fp->rlimit = fp->buf + length;
5593 if (length < 0) goto nope;
5595 else if (S_ISDIR (st_mode)) {
5596 cpp_error (pfile, "directory `%s' specified in #include", fname);
5600 /* Cannot count its file size before reading.
5601 First read the entire file into heap and
5602 copy them into buffer on stack. */
5607 fp->buf = (U_CHAR *) xmalloc (bsize + 2);
5610 i = safe_read (f, fp->buf + st_size, bsize - st_size);
5612 goto nope; /* error! */
5614 if (st_size != bsize)
5615 break; /* End of file */
5617 fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
5623 if ((length > 0 && fp->buf[length - 1] != '\n')
5624 /* Backslash-newline at end is not good enough. */
5625 || (length > 1 && fp->buf[length - 2] == '\\')) {
5626 fp->buf[length++] = '\n';
5628 missing_newline = 1;
5631 fp->buf[length] = '\0';
5632 fp->rlimit = fp->buf + length;
5634 /* Close descriptor now, so nesting does not use lots of descriptors. */
5637 /* Must do this before calling trigraph_pcp, so that the correct file name
5638 will be printed in warning messages. */
5640 pfile->input_stack_listing_current = 0;
5650 if (missing_newline)
5653 if (CPP_PEDANTIC (pfile) && missing_newline)
5654 pedwarn ("file does not end in newline");
5657 input_file_stack_tick++;
5664 cpp_perror_with_name (pfile, fname);
5670 /* This is called after options have been processed.
5671 * Check options for consistency, and setup for processing input
5672 * from the file named FNAME. (Use standard input if FNAME==NULL.)
5673 * Return 1 on succes, 0 on failure.
5677 cpp_start_read (pfile, fname)
5681 struct cpp_options *opts = CPP_OPTIONS (pfile);
5682 struct cpp_pending *pend;
5687 /* The code looks at the defaults through this pointer, rather than through
5688 the constant structure above. This pointer gets changed if an environment
5689 variable specifies other defaults. */
5690 struct default_include *include_defaults = include_defaults_array;
5692 /* Add dirs from CPATH after dirs from -I. */
5693 /* There seems to be confusion about what CPATH should do,
5694 so for the moment it is not documented. */
5695 /* Some people say that CPATH should replace the standard include dirs,
5696 but that seems pointless: it comes before them, so it overrides them
5698 p = (char *) getenv ("CPATH");
5699 if (p != 0 && ! opts->no_standard_includes)
5700 path_include (pfile, p);
5702 /* Now that dollars_in_ident is known, initialize is_idchar. */
5703 initialize_char_syntax (opts);
5705 /* Do partial setup of input buffer for the sake of generating
5706 early #line directives (when -g is in effect). */
5707 fp = cpp_push_buffer (pfile, NULL, 0);
5710 if (opts->in_fname == NULL)
5711 opts->in_fname = "";
5712 fp->nominal_fname = fp->fname = opts->in_fname;
5715 /* Install __LINE__, etc. Must follow initialize_char_syntax
5716 and option processing. */
5717 initialize_builtins (pfile);
5719 /* Do standard #defines and assertions
5720 that identify system and machine type. */
5722 if (!opts->inhibit_predefs) {
5723 char *p = (char *) alloca (strlen (predefs) + 1);
5724 strcpy (p, predefs);
5727 while (*p == ' ' || *p == '\t')
5729 /* Handle -D options. */
5730 if (p[0] == '-' && p[1] == 'D') {
5732 while (*p && *p != ' ' && *p != '\t')
5736 if (opts->debug_output)
5737 output_line_command (pfile, 0, same_file);
5738 cpp_define (pfile, q);
5739 while (*p == ' ' || *p == '\t')
5741 } else if (p[0] == '-' && p[1] == 'A') {
5742 /* Handle -A options (assertions). */
5751 past_name = assertion;
5752 /* Locate end of name. */
5753 while (*past_name && *past_name != ' '
5754 && *past_name != '\t' && *past_name != '(')
5756 /* Locate `(' at start of value. */
5758 while (*value && (*value == ' ' || *value == '\t'))
5760 if (*value++ != '(')
5762 while (*value && (*value == ' ' || *value == '\t'))
5765 /* Locate end of value. */
5766 while (*past_value && *past_value != ' '
5767 && *past_value != '\t' && *past_value != ')')
5769 termination = past_value;
5770 while (*termination && (*termination == ' ' || *termination == '\t'))
5772 if (*termination++ != ')')
5774 if (*termination && *termination != ' ' && *termination != '\t')
5776 /* Temporarily null-terminate the value. */
5777 save_char = *termination;
5778 *termination = '\0';
5779 /* Install the assertion. */
5780 make_assertion (pfile, "-A", assertion);
5781 *termination = (char) save_char;
5783 while (*p == ' ' || *p == '\t')
5791 /* Now handle the command line options. */
5793 /* Do -U's, -D's and -A's in the order they were seen. */
5794 /* First reverse the list. */
5795 opts->pending = nreverse_pending (opts->pending);
5797 for (pend = opts->pending; pend; pend = pend->next)
5799 if (pend->cmd != NULL && pend->cmd[0] == '-')
5801 switch (pend->cmd[1])
5804 if (opts->debug_output)
5805 output_line_command (pfile, 0, same_file);
5806 do_undef (pfile, NULL, pend->arg, pend->arg + strlen (pend->arg));
5809 if (opts->debug_output)
5810 output_line_command (pfile, 0, same_file);
5811 cpp_define (pfile, pend->arg);
5814 make_assertion (pfile, "-A", pend->arg);
5820 opts->done_initializing = 1;
5822 { /* Read the appropriate environment variable and if it exists
5823 replace include_defaults with the listed path. */
5825 switch ((opts->objc << 1) + opts->cplusplus)
5828 epath = getenv ("C_INCLUDE_PATH");
5831 epath = getenv ("CPLUS_INCLUDE_PATH");
5834 epath = getenv ("OBJC_INCLUDE_PATH");
5837 epath = getenv ("OBJCPLUS_INCLUDE_PATH");
5840 /* If the environment var for this language is set,
5841 add to the default list of include directories. */
5843 char *nstore = (char *) alloca (strlen (epath) + 2);
5845 char *startp, *endp;
5847 for (num_dirs = 1, startp = epath; *startp; startp++)
5848 if (*startp == PATH_SEPARATOR)
5851 = (struct default_include *) xmalloc ((num_dirs
5852 * sizeof (struct default_include))
5853 + sizeof (include_defaults_array));
5854 startp = endp = epath;
5857 /* Handle cases like c:/usr/lib:d:/gcc/lib */
5858 if ((*endp == PATH_SEPARATOR)
5860 strncpy (nstore, startp, endp-startp);
5862 strcpy (nstore, ".");
5864 nstore[endp-startp] = '\0';
5866 include_defaults[num_dirs].fname = savestring (nstore);
5867 include_defaults[num_dirs].cplusplus = opts->cplusplus;
5868 include_defaults[num_dirs].cxx_aware = 1;
5872 endp = startp = endp + 1;
5876 /* Put the usual defaults back in at the end. */
5877 bcopy ((char *) include_defaults_array,
5878 (char *) &include_defaults[num_dirs],
5879 sizeof (include_defaults_array));
5883 append_include_chain (pfile, opts->before_system, opts->last_before_system);
5884 opts->first_system_include = opts->before_system;
5886 /* Unless -fnostdinc,
5887 tack on the standard include file dirs to the specified list */
5888 if (!opts->no_standard_includes) {
5889 struct default_include *p = include_defaults;
5890 char *specd_prefix = opts->include_prefix;
5891 char *default_prefix = savestring (GCC_INCLUDE_DIR);
5892 int default_len = 0;
5893 /* Remove the `include' from /usr/local/lib/gcc.../include. */
5894 if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) {
5895 default_len = strlen (default_prefix) - 7;
5896 default_prefix[default_len] = 0;
5898 /* Search "translated" versions of GNU directories.
5899 These have /usr/local/lib/gcc... replaced by specd_prefix. */
5900 if (specd_prefix != 0 && default_len != 0)
5901 for (p = include_defaults; p->fname; p++) {
5902 /* Some standard dirs are only for C++. */
5904 || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
5905 /* Does this dir start with the prefix? */
5906 if (!strncmp (p->fname, default_prefix, default_len)) {
5907 /* Yes; change prefix and add to search list. */
5908 struct file_name_list *new
5909 = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
5910 int this_len = strlen (specd_prefix) + strlen (p->fname) - default_len;
5911 char *str = (char *) xmalloc (this_len + 1);
5912 strcpy (str, specd_prefix);
5913 strcat (str, p->fname + default_len);
5915 new->control_macro = 0;
5916 new->c_system_include_path = !p->cxx_aware;
5917 new->got_name_map = 0;
5918 append_include_chain (pfile, new, new);
5919 if (opts->first_system_include == 0)
5920 opts->first_system_include = new;
5924 /* Search ordinary names for GNU include directories. */
5925 for (p = include_defaults; p->fname; p++) {
5926 /* Some standard dirs are only for C++. */
5928 || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
5929 struct file_name_list *new
5930 = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
5931 new->control_macro = 0;
5932 new->c_system_include_path = !p->cxx_aware;
5933 new->fname = p->fname;
5934 new->got_name_map = 0;
5935 append_include_chain (pfile, new, new);
5936 if (opts->first_system_include == 0)
5937 opts->first_system_include = new;
5942 /* Tack the after_include chain at the end of the include chain. */
5943 append_include_chain (pfile, opts->after_include, opts->last_after_include);
5944 if (opts->first_system_include == 0)
5945 opts->first_system_include = opts->after_include;
5947 /* With -v, print the list of dirs to search. */
5948 if (opts->verbose) {
5949 struct file_name_list *p;
5950 fprintf (stderr, "#include \"...\" search starts here:\n");
5951 for (p = opts->include; p; p = p->next) {
5952 if (p == opts->first_bracket_include)
5953 fprintf (stderr, "#include <...> search starts here:\n");
5954 fprintf (stderr, " %s\n", p->fname);
5956 fprintf (stderr, "End of search list.\n");
5959 /* Scan the -imacros files before the main input.
5960 Much like #including them, but with no_output set
5961 so that only their macro definitions matter. */
5963 opts->no_output++; pfile->no_record_file++;
5964 for (pend = opts->pending; pend; pend = pend->next)
5966 if (pend->cmd != NULL && strcmp (pend->cmd, "-imacros") == 0)
5968 int fd = open (pend->arg, O_RDONLY, 0666);
5971 cpp_perror_with_name (pfile, pend->arg);
5974 if (!cpp_push_buffer (pfile, NULL, 0))
5976 finclude (pfile, fd, pend->arg, 0, NULL_PTR);
5977 cpp_scan_buffer (pfile);
5980 opts->no_output--; pfile->no_record_file--;
5982 /* Copy the entire contents of the main input file into
5983 the stacked input buffer previously allocated for it. */
5984 if (fname == NULL || *fname == 0) {
5987 } else if ((f = open (fname, O_RDONLY, 0666)) < 0)
5988 cpp_pfatal_with_name (pfile, fname);
5990 /* -MG doesn't select the form of output and must be specified with one of
5991 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
5992 inhibit compilation. */
5993 if (opts->print_deps_missing_files
5994 && (opts->print_deps == 0 || !opts->no_output))
5996 cpp_fatal (pfile, "-MG must be specified with one of -M or -MM");
6000 /* Either of two environment variables can specify output of deps.
6001 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
6002 where OUTPUT_FILE is the file to write deps info to
6003 and DEPS_TARGET is the target to mention in the deps. */
6005 if (opts->print_deps == 0
6006 && (getenv ("SUNPRO_DEPENDENCIES") != 0
6007 || getenv ("DEPENDENCIES_OUTPUT") != 0)) {
6008 char *spec = getenv ("DEPENDENCIES_OUTPUT");
6014 spec = getenv ("SUNPRO_DEPENDENCIES");
6015 opts->print_deps = 2;
6018 opts->print_deps = 1;
6021 /* Find the space before the DEPS_TARGET, if there is one. */
6022 /* This should use index. (mrs) */
6023 while (*s != 0 && *s != ' ') s++;
6026 opts->deps_target = s + 1;
6027 output_file = (char *) xmalloc (s - spec + 1);
6028 bcopy (spec, output_file, s - spec);
6029 output_file[s - spec] = 0;
6033 opts->deps_target = 0;
6037 opts->deps_file = output_file;
6038 opts->print_deps_append = 1;
6041 /* For -M, print the expected object file name
6042 as the target of this Make-rule. */
6043 if (opts->print_deps)
6045 pfile->deps_allocated_size = 200;
6046 pfile->deps_buffer = (char *) xmalloc (pfile->deps_allocated_size);
6047 pfile->deps_buffer[0] = 0;
6048 pfile->deps_size = 0;
6049 pfile->deps_column = 0;
6051 if (opts->deps_target)
6052 deps_output (pfile, opts->deps_target, ':');
6053 else if (*opts->in_fname == 0)
6054 deps_output (pfile, "-", ':');
6060 /* Discard all directory prefixes from filename. */
6061 if ((q = rindex (opts->in_fname, '/')) != NULL
6062 #ifdef DIR_SEPARATOR
6063 && (q = rindex (opts->in_fname, DIR_SEPARATOR)) != NULL
6070 /* Copy remainder to mungable area. */
6071 p = (char *) alloca (strlen(q) + 8);
6074 /* Output P, but remove known suffixes. */
6078 && p[len - 2] == '.'
6079 && index("cCsSm", p[len - 1]))
6082 && p[len - 3] == '.'
6083 && p[len - 2] == 'c'
6084 && p[len - 1] == 'c')
6087 && p[len - 4] == '.'
6088 && p[len - 3] == 'c'
6089 && p[len - 2] == 'x'
6090 && p[len - 1] == 'x')
6093 && p[len - 4] == '.'
6094 && p[len - 3] == 'c'
6095 && p[len - 2] == 'p'
6096 && p[len - 1] == 'p')
6099 /* Supply our own suffix. */
6106 deps_output (pfile, p, ':');
6107 deps_output (pfile, opts->in_fname, ' ');
6112 /* Make sure data ends with a newline. And put a null after it. */
6114 if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n')
6115 /* Backslash-newline at end is not good enough. */
6116 || (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) {
6117 fp->buf[fp->length++] = '\n';
6118 missing_newline = 1;
6120 fp->buf[fp->length] = '\0';
6122 /* Unless inhibited, convert trigraphs in the input. */
6128 /* Scan the -include files before the main input.
6129 We push these in reverse order, so that the first one is handled first. */
6131 pfile->no_record_file++;
6132 opts->pending = nreverse_pending (opts->pending);
6133 for (pend = opts->pending; pend; pend = pend->next)
6135 if (pend->cmd != NULL && strcmp (pend->cmd, "-include") == 0)
6137 int fd = open (pend->arg, O_RDONLY, 0666);
6140 cpp_perror_with_name (pfile, pend->arg);
6143 if (!cpp_push_buffer (pfile, NULL, 0))
6145 finclude (pfile, fd, pend->arg, 0, NULL_PTR);
6148 pfile->no_record_file--;
6150 /* Free the pending list. */
6151 for (pend = opts->pending; pend; )
6153 struct cpp_pending *next = pend->next;
6157 opts->pending = NULL;
6160 /* Scan the input, processing macros and directives. */
6162 rescan (&outbuf, 0);
6164 if (missing_newline)
6167 if (CPP_PEDANTIC (pfile) && missing_newline)
6168 pedwarn ("file does not end in newline");
6171 if (finclude (pfile, f, fname, 0, NULL_PTR))
6172 output_line_command (pfile, 0, same_file);
6177 cpp_reader_init (pfile)
6180 bzero ((char *) pfile, sizeof (cpp_reader));
6181 pfile->get_token = cpp_get_token;
6183 pfile->token_buffer_size = 200;
6184 pfile->token_buffer = (U_CHAR *) xmalloc (pfile->token_buffer_size);
6185 CPP_SET_WRITTEN (pfile, 0);
6187 pfile->system_include_depth = 0;
6188 pfile->dont_repeat_files = 0;
6189 pfile->all_include_files = 0;
6190 pfile->max_include_len = 0;
6191 pfile->timebuf = NULL;
6192 pfile->only_seen_white = 1;
6193 pfile->buffer = CPP_NULL_BUFFER(pfile);
6196 static struct cpp_pending *
6197 nreverse_pending (list)
6198 struct cpp_pending *list;
6201 register struct cpp_pending *prev = 0, *next, *pend;
6202 for (pend = list; pend; pend = next)
6212 push_pending (pfile, cmd, arg)
6217 struct cpp_pending *pend
6218 = (struct cpp_pending *) xmalloc (sizeof (struct cpp_pending));
6221 pend->next = CPP_OPTIONS (pfile)->pending;
6222 CPP_OPTIONS (pfile)->pending = pend;
6225 /* Handle command-line options in (argc, argv).
6226 Can be called multiple times, to handle multiple sets of options.
6227 Returns if an unrecognized option is seen.
6228 Returns number of handled arguments. */
6231 cpp_handle_options (pfile, argc, argv)
6237 struct cpp_options *opts = CPP_OPTIONS (pfile);
6238 for (i = 0; i < argc; i++) {
6239 if (argv[i][0] != '-') {
6240 if (opts->out_fname != NULL)
6242 cpp_fatal (pfile, "Usage: %s [switches] input output", argv[0]);
6245 else if (opts->in_fname != NULL)
6246 opts->out_fname = argv[i];
6248 opts->in_fname = argv[i];
6250 switch (argv[i][1]) {
6253 cpp_fatal (pfile, "Filename missing after `%s' option", argv[i]);
6256 cpp_fatal (pfile, "Directory name missing after `%s' option", argv[i]);
6260 if (!strcmp (argv[i], "-include")
6261 || !strcmp (argv[i], "-imacros")) {
6263 goto missing_filename;
6265 push_pending (pfile, argv[i], argv[i+1]), i++;
6267 if (!strcmp (argv[i], "-iprefix")) {
6269 goto missing_filename;
6271 opts->include_prefix = argv[++i];
6273 if (!strcmp (argv[i], "-ifoutput")) {
6274 opts->output_conditionals = 1;
6276 if (!strcmp (argv[i], "-isystem")) {
6277 struct file_name_list *dirtmp;
6280 goto missing_filename;
6282 dirtmp = (struct file_name_list *)
6283 xmalloc (sizeof (struct file_name_list));
6285 dirtmp->control_macro = 0;
6286 dirtmp->c_system_include_path = 1;
6287 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1]) + 1);
6288 strcpy (dirtmp->fname, argv[++i]);
6289 dirtmp->got_name_map = 0;
6291 if (opts->before_system == 0)
6292 opts->before_system = dirtmp;
6294 opts->last_before_system->next = dirtmp;
6295 opts->last_before_system = dirtmp; /* Tail follows the last one */
6297 /* Add directory to end of path for includes,
6298 with the default prefix at the front of its name. */
6299 if (!strcmp (argv[i], "-iwithprefix")) {
6300 struct file_name_list *dirtmp;
6303 if (opts->include_prefix != 0)
6304 prefix = opts->include_prefix;
6306 prefix = savestring (GCC_INCLUDE_DIR);
6307 /* Remove the `include' from /usr/local/lib/gcc.../include. */
6308 if (!strcmp (prefix + strlen (prefix) - 8, "/include"))
6309 prefix[strlen (prefix) - 7] = 0;
6312 dirtmp = (struct file_name_list *)
6313 xmalloc (sizeof (struct file_name_list));
6314 dirtmp->next = 0; /* New one goes on the end */
6315 dirtmp->control_macro = 0;
6316 dirtmp->c_system_include_path = 0;
6318 goto missing_dirname;
6320 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1])
6321 + strlen (prefix) + 1);
6322 strcpy (dirtmp->fname, prefix);
6323 strcat (dirtmp->fname, argv[++i]);
6324 dirtmp->got_name_map = 0;
6326 if (opts->after_include == 0)
6327 opts->after_include = dirtmp;
6329 opts->last_after_include->next = dirtmp;
6330 opts->last_after_include = dirtmp; /* Tail follows the last one */
6332 /* Add directory to main path for includes,
6333 with the default prefix at the front of its name. */
6334 if (!strcmp (argv[i], "-iwithprefixbefore")) {
6335 struct file_name_list *dirtmp;
6338 if (opts->include_prefix != 0)
6339 prefix = opts->include_prefix;
6341 prefix = savestring (GCC_INCLUDE_DIR);
6342 /* Remove the `include' from /usr/local/lib/gcc.../include. */
6343 if (!strcmp (prefix + strlen (prefix) - 8, "/include"))
6344 prefix[strlen (prefix) - 7] = 0;
6347 dirtmp = (struct file_name_list *)
6348 xmalloc (sizeof (struct file_name_list));
6349 dirtmp->next = 0; /* New one goes on the end */
6350 dirtmp->control_macro = 0;
6351 dirtmp->c_system_include_path = 0;
6353 goto missing_dirname;
6355 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1])
6356 + strlen (prefix) + 1);
6357 strcpy (dirtmp->fname, prefix);
6358 strcat (dirtmp->fname, argv[++i]);
6359 dirtmp->got_name_map = 0;
6361 append_include_chain (pfile, dirtmp, dirtmp);
6363 /* Add directory to end of path for includes. */
6364 if (!strcmp (argv[i], "-idirafter")) {
6365 struct file_name_list *dirtmp;
6367 dirtmp = (struct file_name_list *)
6368 xmalloc (sizeof (struct file_name_list));
6369 dirtmp->next = 0; /* New one goes on the end */
6370 dirtmp->control_macro = 0;
6371 dirtmp->c_system_include_path = 0;
6373 goto missing_dirname;
6375 dirtmp->fname = argv[++i];
6376 dirtmp->got_name_map = 0;
6378 if (opts->after_include == 0)
6379 opts->after_include = dirtmp;
6381 opts->last_after_include->next = dirtmp;
6382 opts->last_after_include = dirtmp; /* Tail follows the last one */
6387 if (opts->out_fname != NULL)
6389 cpp_fatal (pfile, "Output filename specified twice");
6393 goto missing_filename;
6394 opts->out_fname = argv[++i];
6395 if (!strcmp (opts->out_fname, "-"))
6396 opts->out_fname = "";
6400 if (!strcmp (argv[i], "-pedantic"))
6401 CPP_PEDANTIC (pfile) = 1;
6402 else if (!strcmp (argv[i], "-pedantic-errors")) {
6403 CPP_PEDANTIC (pfile) = 1;
6404 opts->pedantic_errors = 1;
6407 else if (!strcmp (argv[i], "-pcp")) {
6408 char *pcp_fname = argv[++i];
6410 ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
6411 ? fopen (pcp_fname, "w")
6412 : fdopen (dup (fileno (stdout)), "w"));
6413 if (pcp_outfile == 0)
6414 cpp_pfatal_with_name (pfile, pcp_fname);
6421 if (!strcmp (argv[i], "-traditional")) {
6422 opts->traditional = 1;
6423 } else if (!strcmp (argv[i], "-trigraphs")) {
6425 opts->no_trigraphs = 0;
6430 if (! strcmp (argv[i], "-lang-c"))
6431 opts->cplusplus = 0, opts->cplusplus_comments = 0, opts->objc = 0;
6432 if (! strcmp (argv[i], "-lang-c++"))
6433 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->objc = 0;
6434 if (! strcmp (argv[i], "-lang-c-c++-comments"))
6435 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->objc = 0;
6436 if (! strcmp (argv[i], "-lang-objc"))
6437 opts->objc = 1, opts->cplusplus = 0, opts->cplusplus_comments = 1;
6438 if (! strcmp (argv[i], "-lang-objc++"))
6439 opts->objc = 1, opts->cplusplus = 1, opts->cplusplus_comments = 1;
6440 if (! strcmp (argv[i], "-lang-asm"))
6442 if (! strcmp (argv[i], "-lint"))
6444 if (! strcmp (argv[i], "-lang-chill"))
6445 opts->objc = 0, opts->cplusplus = 0, opts->chill = 1,
6446 opts->traditional = 1, opts->no_trigraphs = 1;
6450 opts->cplusplus = 1, opts->cplusplus_comments = 1;
6454 opts->inhibit_warnings = 1;
6458 if (!strcmp (argv[i], "-Wtrigraphs"))
6459 opts->warn_trigraphs = 1;
6460 else if (!strcmp (argv[i], "-Wno-trigraphs"))
6461 opts->warn_trigraphs = 0;
6462 else if (!strcmp (argv[i], "-Wcomment"))
6463 opts->warn_comments = 1;
6464 else if (!strcmp (argv[i], "-Wno-comment"))
6465 opts->warn_comments = 0;
6466 else if (!strcmp (argv[i], "-Wcomments"))
6467 opts->warn_comments = 1;
6468 else if (!strcmp (argv[i], "-Wno-comments"))
6469 opts->warn_comments = 0;
6470 else if (!strcmp (argv[i], "-Wtraditional"))
6471 opts->warn_stringify = 1;
6472 else if (!strcmp (argv[i], "-Wno-traditional"))
6473 opts->warn_stringify = 0;
6474 else if (!strcmp (argv[i], "-Wimport"))
6475 opts->warn_import = 1;
6476 else if (!strcmp (argv[i], "-Wno-import"))
6477 opts->warn_import = 0;
6478 else if (!strcmp (argv[i], "-Werror"))
6479 opts->warnings_are_errors = 1;
6480 else if (!strcmp (argv[i], "-Wno-error"))
6481 opts->warnings_are_errors = 0;
6482 else if (!strcmp (argv[i], "-Wall"))
6484 opts->warn_trigraphs = 1;
6485 opts->warn_comments = 1;
6490 /* The style of the choices here is a bit mixed.
6491 The chosen scheme is a hybrid of keeping all options in one string
6492 and specifying each option in a separate argument:
6493 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
6494 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
6495 -M[M][G][D file]. This is awkward to handle in specs, and is not
6497 /* ??? -MG must be specified in addition to one of -M or -MM.
6498 This can be relaxed in the future without breaking anything.
6499 The converse isn't true. */
6501 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
6502 if (!strcmp (argv[i], "-MG"))
6504 opts->print_deps_missing_files = 1;
6507 if (!strcmp (argv[i], "-M"))
6508 opts->print_deps = 2;
6509 else if (!strcmp (argv[i], "-MM"))
6510 opts->print_deps = 1;
6511 else if (!strcmp (argv[i], "-MD"))
6512 opts->print_deps = 2;
6513 else if (!strcmp (argv[i], "-MMD"))
6514 opts->print_deps = 1;
6515 /* For -MD and -MMD options, write deps on file named by next arg. */
6516 if (!strcmp (argv[i], "-MD") || !strcmp (argv[i], "-MMD"))
6519 goto missing_filename;
6520 opts->deps_file = argv[++i];
6524 /* For -M and -MM, write deps on standard output
6525 and suppress the usual output. */
6526 opts->no_output = 1;
6532 char *p = argv[i] + 2;
6534 while ((c = *p++) != 0) {
6535 /* Arg to -d specifies what parts of macros to dump */
6538 opts->dump_macros = dump_only;
6539 opts->no_output = 1;
6542 opts->dump_macros = dump_names;
6545 opts->dump_macros = dump_definitions;
6553 if (argv[i][2] == '3')
6554 opts->debug_output = 1;
6558 fprintf (stderr, "GNU CPP version %s", version_string);
6559 #ifdef TARGET_VERSION
6562 fprintf (stderr, "\n");
6567 opts->print_include_names = 1;
6571 if (argv[i][2] != 0)
6572 push_pending (pfile, "-D", argv[i] + 2);
6573 else if (i + 1 == argc)
6575 cpp_fatal (pfile, "Macro name missing after -D option");
6579 i++, push_pending (pfile, "-D", argv[i]);
6586 if (argv[i][2] != 0)
6588 else if (i + 1 == argc)
6590 cpp_fatal (pfile, "Assertion missing after -A option");
6596 if (!strcmp (p, "-")) {
6597 struct cpp_pending **ptr;
6598 /* -A- eliminates all predefined macros and assertions.
6599 Let's include also any that were specified earlier
6600 on the command line. That way we can get rid of any
6601 that were passed automatically in from GCC. */
6603 opts->inhibit_predefs = 1;
6604 for (ptr = &opts->pending; *ptr != NULL; )
6606 struct cpp_pending *pend = *ptr;
6607 if (pend->cmd && pend->cmd[0] == '-'
6608 && (pend->cmd[1] == 'D' || pend->cmd[1] == 'A'))
6617 push_pending (pfile, "-A", p);
6622 case 'U': /* JF #undef something */
6623 if (argv[i][2] != 0)
6624 push_pending (pfile, "-U", argv[i] + 2);
6625 else if (i + 1 == argc)
6627 cpp_fatal (pfile, "Macro name missing after -U option", NULL);
6631 push_pending (pfile, "-U", argv[i+1]), i++;
6635 opts->put_out_comments = 1;
6638 case 'E': /* -E comes from cc -E; ignore it. */
6642 opts->no_line_commands = 1;
6645 case '$': /* Don't include $ in identifiers. */
6646 opts->dollars_in_ident = 0;
6649 case 'I': /* Add directory to path for includes. */
6651 struct file_name_list *dirtmp;
6653 if (! CPP_OPTIONS(pfile)->ignore_srcdir
6654 && !strcmp (argv[i] + 2, "-")) {
6655 CPP_OPTIONS (pfile)->ignore_srcdir = 1;
6656 /* Don't use any preceding -I directories for #include <...>. */
6657 CPP_OPTIONS (pfile)->first_bracket_include = 0;
6660 dirtmp = (struct file_name_list *)
6661 xmalloc (sizeof (struct file_name_list));
6662 dirtmp->next = 0; /* New one goes on the end */
6663 dirtmp->control_macro = 0;
6664 dirtmp->c_system_include_path = 0;
6665 if (argv[i][2] != 0)
6666 dirtmp->fname = argv[i] + 2;
6667 else if (i + 1 == argc)
6668 goto missing_dirname;
6670 dirtmp->fname = argv[++i];
6671 dirtmp->got_name_map = 0;
6672 append_include_chain (pfile, dirtmp, dirtmp);
6678 if (!strcmp (argv[i], "-nostdinc"))
6679 /* -nostdinc causes no default include directories.
6680 You must specify all include-file directories with -I. */
6681 opts->no_standard_includes = 1;
6682 else if (!strcmp (argv[i], "-nostdinc++"))
6683 /* -nostdinc++ causes no default C++-specific include directories. */
6684 opts->no_standard_cplusplus_includes = 1;
6686 else if (!strcmp (argv[i], "-noprecomp"))
6692 /* Sun compiler passes undocumented switch "-undef".
6693 Let's assume it means to inhibit the predefined symbols. */
6694 opts->inhibit_predefs = 1;
6697 case '\0': /* JF handle '-' as file name meaning stdin or stdout */
6698 if (opts->in_fname == NULL) {
6699 opts->in_fname = "";
6701 } else if (opts->out_fname == NULL) {
6702 opts->out_fname = "";
6704 } /* else fall through into error */
6718 struct cpp_options *opts = CPP_OPTIONS (pfile);
6720 if (opts->print_deps)
6722 /* Stream on which to print the dependency information. */
6725 /* Don't actually write the deps file if compilation has failed. */
6726 if (pfile->errors == 0)
6728 char *deps_mode = opts->print_deps_append ? "a" : "w";
6729 if (opts->deps_file == 0)
6730 deps_stream = stdout;
6731 else if ((deps_stream = fopen (opts->deps_file, deps_mode)) == 0)
6732 cpp_pfatal_with_name (pfile, opts->deps_file);
6733 fputs (pfile->deps_buffer, deps_stream);
6734 putc ('\n', deps_stream);
6735 if (opts->deps_file)
6737 if (ferror (deps_stream) || fclose (deps_stream) != 0)
6738 cpp_fatal (pfile, "I/O error on output");
6744 /* Free resources used by PFILE.
6745 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
6752 while ( CPP_BUFFER (pfile) != CPP_NULL_BUFFER (pfile))
6753 cpp_pop_buffer (pfile);
6755 if (pfile->token_buffer)
6757 free (pfile->token_buffer);
6758 pfile->token_buffer = NULL;
6761 if (pfile->deps_buffer)
6763 free (pfile->deps_buffer);
6764 pfile->deps_buffer = NULL;
6765 pfile->deps_allocated_size = 0;
6768 while (pfile->if_stack)
6770 IF_STACK_FRAME *temp = pfile->if_stack;
6771 pfile->if_stack = temp->next;
6775 while (pfile->dont_repeat_files)
6777 struct file_name_list *temp = pfile->dont_repeat_files;
6778 pfile->dont_repeat_files = temp->next;
6783 while (pfile->all_include_files)
6785 struct file_name_list *temp = pfile->all_include_files;
6786 pfile->all_include_files = temp->next;
6791 for (i = IMPORT_HASH_SIZE; --i >= 0; )
6793 register struct import_file *imp = pfile->import_hash_table[i];
6796 struct import_file *next = imp->next;
6801 pfile->import_hash_table[i] = 0;
6804 for (i = ASSERTION_HASHSIZE; --i >= 0; )
6806 while (pfile->assertion_hashtab[i])
6807 delete_assertion (pfile->assertion_hashtab[i]);
6810 cpp_hash_cleanup (pfile);
6814 do_assert (pfile, keyword, buf, limit)
6816 struct directive *keyword;
6817 U_CHAR *buf, *limit;
6819 long symstart; /* remember where symbol name starts */
6821 int sym_length; /* and how long it is */
6822 struct arglist *tokens = NULL;
6824 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
6825 && !CPP_BUFFER (pfile)->system_header_p)
6826 cpp_pedwarn (pfile, "ANSI C does not allow `#assert'");
6828 cpp_skip_hspace (pfile);
6829 symstart = CPP_WRITTEN (pfile); /* remember where it starts */
6830 parse_name (pfile, GETC());
6831 sym_length = check_macro_name (pfile, pfile->token_buffer + symstart,
6834 cpp_skip_hspace (pfile);
6835 if (PEEKC() != '(') {
6836 cpp_error (pfile, "missing token-sequence in `#assert'");
6842 tokens = read_token_list (pfile, &error_flag);
6846 cpp_error (pfile, "empty token-sequence in `#assert'");
6849 cpp_skip_hspace (pfile);
6851 if (c != EOF && c != '\n')
6852 cpp_pedwarn (pfile, "junk at end of `#assert'");
6853 skip_rest_of_line (pfile);
6856 /* If this name isn't already an assertion name, make it one.
6857 Error if it was already in use in some other way. */
6860 ASSERTION_HASHNODE *hp;
6861 U_CHAR *symname = pfile->token_buffer + symstart;
6862 int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE);
6863 struct tokenlist_list *value
6864 = (struct tokenlist_list *) xmalloc (sizeof (struct tokenlist_list));
6866 hp = assertion_lookup (pfile, symname, sym_length, hashcode);
6868 if (sym_length == 7 && ! strncmp (symname, "defined", sym_length))
6869 cpp_error (pfile, "`defined' redefined as assertion");
6870 hp = assertion_install (pfile, symname, sym_length, hashcode);
6873 /* Add the spec'd token-sequence to the list of such. */
6874 value->tokens = tokens;
6875 value->next = hp->value;
6878 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6881 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6882 skip_rest_of_line (pfile);
6887 do_unassert (pfile, keyword, buf, limit)
6889 struct directive *keyword;
6890 U_CHAR *buf, *limit;
6892 long symstart; /* remember where symbol name starts */
6893 int sym_length; /* and how long it is */
6896 struct arglist *tokens = NULL;
6897 int tokens_specified = 0;
6899 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
6900 && !CPP_BUFFER (pfile)->system_header_p)
6901 cpp_pedwarn (pfile, "ANSI C does not allow `#unassert'");
6903 cpp_skip_hspace (pfile);
6905 symstart = CPP_WRITTEN (pfile); /* remember where it starts */
6906 parse_name (pfile, GETC());
6907 sym_length = check_macro_name (pfile, pfile->token_buffer + symstart,
6910 cpp_skip_hspace (pfile);
6911 if (PEEKC() == '(') {
6914 tokens = read_token_list (pfile, &error_flag);
6918 cpp_error (pfile, "empty token list in `#unassert'");
6922 tokens_specified = 1;
6925 cpp_skip_hspace (pfile);
6927 if (c != EOF && c != '\n')
6928 cpp_error (pfile, "junk at end of `#unassert'");
6929 skip_rest_of_line (pfile);
6932 ASSERTION_HASHNODE *hp;
6933 U_CHAR *symname = pfile->token_buffer + symstart;
6934 int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE);
6935 struct tokenlist_list *tail, *prev;
6937 hp = assertion_lookup (pfile, symname, sym_length, hashcode);
6941 /* If no token list was specified, then eliminate this assertion
6943 if (! tokens_specified)
6944 delete_assertion (hp);
6946 /* If a list of tokens was given, then delete any matching list. */
6951 struct tokenlist_list *next = tail->next;
6952 if (compare_token_lists (tail->tokens, tokens)) {
6956 hp->value = tail->next;
6957 free_token_list (tail->tokens);
6967 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6970 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6971 skip_rest_of_line (pfile);
6975 /* Test whether there is an assertion named NAME
6976 and optionally whether it has an asserted token list TOKENS.
6977 NAME is not null terminated; its length is SYM_LENGTH.
6978 If TOKENS_SPECIFIED is 0, then don't check for any token list. */
6981 check_assertion (pfile, name, sym_length, tokens_specified, tokens)
6985 int tokens_specified;
6986 struct arglist *tokens;
6988 ASSERTION_HASHNODE *hp;
6989 int hashcode = hashf (name, sym_length, ASSERTION_HASHSIZE);
6991 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
6992 cpp_pedwarn (pfile, "ANSI C does not allow testing assertions");
6994 hp = assertion_lookup (pfile, name, sym_length, hashcode);
6996 /* It is not an assertion; just return false. */
6999 /* If no token list was specified, then value is 1. */
7000 if (! tokens_specified)
7004 struct tokenlist_list *tail;
7008 /* If a list of tokens was given,
7009 then succeed if the assertion records a matching list. */
7012 if (compare_token_lists (tail->tokens, tokens))
7017 /* Fail if the assertion has no matching list. */
7022 /* Compare two lists of tokens for equality including order of tokens. */
7025 compare_token_lists (l1, l2)
7026 struct arglist *l1, *l2;
7029 if (l1->length != l2->length)
7031 if (strncmp (l1->name, l2->name, l1->length))
7037 /* Succeed if both lists end at the same time. */
7042 reverse_token_list (tokens)
7043 struct arglist *tokens;
7045 register struct arglist *prev = 0, *this, *next;
7046 for (this = tokens; this; this = next)
7055 /* Read a space-separated list of tokens ending in a close parenthesis.
7056 Return a list of strings, in the order they were written.
7057 (In case of error, return 0 and store -1 in *ERROR_FLAG.) */
7059 static struct arglist *
7060 read_token_list (pfile, error_flag)
7064 struct arglist *token_ptrs = 0;
7069 FORWARD (1); /* Skip '(' */
7071 /* Loop over the assertion value tokens. */
7074 struct arglist *temp;
7075 long name_written = CPP_WRITTEN (pfile);
7076 int eofp = 0; int c;
7078 cpp_skip_hspace (pfile);
7082 /* Find the end of the token. */
7085 CPP_PUTC (pfile, c);
7093 CPP_PUTC (pfile, c);
7095 else if (c == '"' || c == '\'')
7098 cpp_get_token (pfile);
7104 while (c != EOF && ! is_space[c] && c != '(' && c != ')'
7105 && c != '"' && c != '\'')
7107 CPP_PUTC (pfile, c);
7110 if (c != EOF) FORWARD(-1);
7113 length = CPP_WRITTEN (pfile) - name_written;
7114 temp = (struct arglist *)
7115 xmalloc (sizeof (struct arglist) + length + 1);
7116 temp->name = (U_CHAR *) (temp + 1);
7117 bcopy ((char *) (pfile->token_buffer + name_written),
7118 (char *) temp->name, length);
7119 temp->name[length] = 0;
7120 temp->next = token_ptrs;
7122 temp->length = length;
7124 CPP_ADJUST_WRITTEN (pfile, -length); /* pop */
7126 if (c == EOF || c == '\n')
7129 "unterminated token sequence following `#' operator");
7134 /* We accumulated the names in reverse order.
7135 Now reverse them to get the proper order. */
7136 return reverse_token_list (token_ptrs);
7140 free_token_list (tokens)
7141 struct arglist *tokens;
7144 struct arglist *next = tokens->next;
7145 free (tokens->name);
7151 /* Get the file-mode and data size of the file open on FD
7152 and store them in *MODE_POINTER and *SIZE_POINTER. */
7155 file_size_and_mode (fd, mode_pointer, size_pointer)
7158 long int *size_pointer;
7162 if (fstat (fd, &sbuf) < 0) return (-1);
7163 if (mode_pointer) *mode_pointer = sbuf.st_mode;
7164 if (size_pointer) *size_pointer = sbuf.st_size;
7168 /* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
7169 retrying if necessary. Return a negative value if an error occurs,
7170 otherwise return the actual number of bytes read,
7171 which must be LEN unless end-of-file was reached. */
7174 safe_read (desc, ptr, len)
7181 int nchars = read (desc, ptr, left);
7199 xcalloc (number, size)
7200 unsigned number, size;
7202 register unsigned total = number * size;
7203 register char *ptr = (char *) xmalloc (total);
7212 unsigned size = strlen (input);
7213 char *output = xmalloc (size + 1);
7214 strcpy (output, input);
7218 /* Initialize PMARK to remember the current position of PFILE. */
7221 parse_set_mark (pmark, pfile)
7222 struct parse_marker *pmark;
7225 cpp_buffer *pbuf = CPP_BUFFER (pfile);
7226 pmark->next = pbuf->marks;
7227 pbuf->marks = pmark;
7229 pmark->position = pbuf->cur - pbuf->buf;
7232 /* Cleanup PMARK - we no longer need it. */
7235 parse_clear_mark (pmark)
7236 struct parse_marker *pmark;
7238 struct parse_marker **pp = &pmark->buf->marks;
7239 for (; ; pp = &(*pp)->next) {
7240 if (*pp == NULL) abort ();
7241 if (*pp == pmark) break;
7246 /* Backup the current position of PFILE to that saved in PMARK. */
7249 parse_goto_mark (pmark, pfile)
7250 struct parse_marker *pmark;
7253 cpp_buffer *pbuf = CPP_BUFFER (pfile);
7254 if (pbuf != pmark->buf)
7255 cpp_fatal (pfile, "internal error %s", "parse_goto_mark");
7256 pbuf->cur = pbuf->buf + pmark->position;
7259 /* Reset PMARK to point to the current position of PFILE. (Same
7260 as parse_clear_mark (PMARK), parse_set_mark (PMARK, PFILE) but faster. */
7263 parse_move_mark (pmark, pfile)
7264 struct parse_marker *pmark;
7267 cpp_buffer *pbuf = CPP_BUFFER (pfile);
7268 if (pbuf != pmark->buf)
7269 cpp_fatal (pfile, "internal error %s", "parse_move_mark");
7270 pmark->position = pbuf->cur - pbuf->buf;
7274 cpp_read_check_assertion (pfile)
7277 int name_start = CPP_WRITTEN (pfile);
7278 int name_length, name_written;
7280 FORWARD (1); /* Skip '#' */
7281 cpp_skip_hspace (pfile);
7282 parse_name (pfile, GETC ());
7283 name_written = CPP_WRITTEN (pfile);
7284 name_length = name_written - name_start;
7285 cpp_skip_hspace (pfile);
7286 if (CPP_BUF_PEEK (CPP_BUFFER (pfile)) == '(')
7289 struct arglist *token_ptrs = read_token_list (pfile, &error_flag);
7290 result = check_assertion (pfile,
7291 pfile->token_buffer + name_start, name_length,
7295 result = check_assertion (pfile,
7296 pfile->token_buffer + name_start, name_length,
7298 CPP_ADJUST_WRITTEN (pfile, - name_length); /* pop */
7303 cpp_print_file_and_line (pfile)
7306 cpp_buffer *ip = cpp_file_buffer (pfile);
7311 cpp_buf_line_and_col (ip, &line, &col);
7312 cpp_file_line_for_message (pfile, ip->nominal_fname,
7313 line, pfile->show_column ? col : -1);
7318 cpp_error (pfile, msg, arg1, arg2, arg3)
7321 char *arg1, *arg2, *arg3;
7323 cpp_print_containing_files (pfile);
7324 cpp_print_file_and_line (pfile);
7325 cpp_message (pfile, 1, msg, arg1, arg2, arg3);
7328 /* Print error message but don't count it. */
7331 cpp_warning (pfile, msg, arg1, arg2, arg3)
7334 char *arg1, *arg2, *arg3;
7336 if (CPP_OPTIONS (pfile)->inhibit_warnings)
7339 if (CPP_OPTIONS (pfile)->warnings_are_errors)
7342 cpp_print_containing_files (pfile);
7343 cpp_print_file_and_line (pfile);
7344 cpp_message (pfile, 0, msg, arg1, arg2, arg3);
7347 /* Print an error message and maybe count it. */
7350 cpp_pedwarn (pfile, msg, arg1, arg2, arg3)
7353 char *arg1, *arg2, *arg3;
7355 if (CPP_OPTIONS (pfile)->pedantic_errors)
7356 cpp_error (pfile, msg, arg1, arg2, arg3);
7358 cpp_warning (pfile, msg, arg1, arg2, arg3);
7362 cpp_error_with_line (pfile, line, column, msg, arg1, arg2, arg3)
7366 char *arg1, *arg2, *arg3;
7369 cpp_buffer *ip = cpp_file_buffer (pfile);
7371 cpp_print_containing_files (pfile);
7374 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
7376 cpp_message (pfile, 1, msg, arg1, arg2, arg3);
7380 cpp_warning_with_line (pfile, line, column, msg, arg1, arg2, arg3)
7384 char *arg1, *arg2, *arg3;
7389 if (CPP_OPTIONS (pfile)->inhibit_warnings)
7392 if (CPP_OPTIONS (pfile)->warnings_are_errors)
7395 cpp_print_containing_files (pfile);
7397 ip = cpp_file_buffer (pfile);
7400 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
7402 cpp_message (pfile, 0, msg, arg1, arg2, arg3);
7406 cpp_pedwarn_with_line (pfile, line, column, msg, arg1, arg2, arg3)
7410 char *arg1, *arg2, *arg3;
7412 if (CPP_OPTIONS (pfile)->pedantic_errors)
7413 cpp_error_with_line (pfile, column, line, msg, arg1, arg2, arg3);
7415 cpp_warning_with_line (pfile, line, column, msg, arg1, arg2, arg3);
7418 /* Report a warning (or an error if pedantic_errors)
7419 giving specified file name and line number, not current. */
7422 cpp_pedwarn_with_file_and_line (pfile, file, line, msg, arg1, arg2, arg3)
7427 char *arg1, *arg2, *arg3;
7429 if (!CPP_OPTIONS (pfile)->pedantic_errors
7430 && CPP_OPTIONS (pfile)->inhibit_warnings)
7433 cpp_file_line_for_message (pfile, file, line, -1);
7434 cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors,
7435 msg, arg1, arg2, arg3);
7438 /* This defines "errno" properly for VMS, and gives us EACCES. */
7445 #ifndef HAVE_STRERROR
7446 extern int sys_nerr;
7448 extern const char *const sys_errlist[];
7450 extern char *sys_errlist[];
7452 #else /* HAVE_STRERROR */
7456 char *strerror (int,...);
7459 /* my_strerror - return the descriptive text associated with an
7463 my_strerror (errnum)
7469 #ifndef HAVE_STRERROR
7470 result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
7472 result = strerror (errnum);
7475 /* VAXCRTL's strerror() takes an optional second argument, which only
7476 matters when the first argument is EVMSERR. However, it's simplest
7477 just to pass it unconditionally. `vaxc$errno' is declared in
7478 <errno.h>, and maintained by the library in parallel with `errno'.
7479 We assume that caller's `errnum' either matches the last setting of
7480 `errno' by the library or else does not have the value `EVMSERR'. */
7482 result = strerror (errnum, vaxc$errno);
7486 result = "undocumented I/O error";
7491 /* Error including a message from `errno'. */
7494 cpp_error_from_errno (pfile, name)
7499 cpp_buffer *ip = cpp_file_buffer (pfile);
7501 cpp_print_containing_files (pfile);
7504 cpp_file_line_for_message (pfile, ip->nominal_fname, ip->lineno, -1);
7506 cpp_message (pfile, 1, "%s: %s", name, my_strerror (errno));
7510 cpp_perror_with_name (pfile, name)
7514 cpp_message (pfile, 1, "%s: %s: %s", progname, name, my_strerror (errno));
7518 * No pre-compiled header file support.
7520 * Possibly different enum token codes for each C/C++ token.
7522 * Should clean up remaining directives to that do_XXX functions
7523 * only take two arguments and all have command_reads_line.
7525 * Find and cleanup remaining uses of static variables,
7527 * Support for trigraphs.
7529 * Support -dM flag (dump_all_macros).
7531 * Support for_lint flag.