2 Copyright (C) 1986, 87, 89, 92-97, 1998 Free Software Foundation, Inc.
3 Contributed by Per Bothner, 1994-95.
4 Based on CCCP program 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. */
35 #ifdef HAVE_SYS_TIMES_H
36 #include <sys/times.h>
39 #ifdef HAVE_SYS_RESOURCE_H
40 # include <sys/resource.h>
43 #include "gansidecl.h"
47 #ifndef GET_ENVIRONMENT
48 #define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ENV_VALUE = getenv (ENV_NAME)
51 extern char *update_path
PARAMS ((char *, char *));
55 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
56 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
58 /* Find the largest host integer type and set its size and type.
59 Watch out: on some crazy hosts `long' is shorter than `int'. */
63 # include <inttypes.h>
64 # define HOST_WIDE_INT intmax_t
66 # if (HOST_BITS_PER_LONG <= HOST_BITS_PER_INT \
67 && HOST_BITS_PER_LONGLONG <= HOST_BITS_PER_INT)
68 # define HOST_WIDE_INT int
70 # if (HOST_BITS_PER_LONGLONG <= HOST_BITS_PER_LONG \
71 || ! (defined LONG_LONG_MAX || defined LLONG_MAX))
72 # define HOST_WIDE_INT long
74 # define HOST_WIDE_INT long long
81 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
85 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
88 /* By default, colon separates directories in a path. */
89 #ifndef PATH_SEPARATOR
90 #define PATH_SEPARATOR ':'
93 #ifndef STANDARD_INCLUDE_DIR
94 #define STANDARD_INCLUDE_DIR "/usr/include"
96 #ifndef INCLUDE_LEN_FUDGE
97 #define INCLUDE_LEN_FUDGE 0
100 /* Symbols to predefine. */
102 #ifdef CPP_PREDEFINES
103 static char *predefs
= CPP_PREDEFINES
;
105 static char *predefs
= "";
108 /* We let tm.h override the types used here, to handle trivial differences
109 such as the choice of unsigned int or long unsigned int for size_t.
110 When machines start needing nontrivial differences in the size type,
111 it would be best to do something here to figure out automatically
112 from other information what type to use. */
114 /* The string value for __SIZE_TYPE__. */
117 #define SIZE_TYPE "long unsigned int"
120 /* The string value for __PTRDIFF_TYPE__. */
123 #define PTRDIFF_TYPE "long int"
126 /* The string value for __WCHAR_TYPE__. */
129 #define WCHAR_TYPE "int"
131 #define CPP_WCHAR_TYPE(PFILE) \
132 (CPP_OPTIONS (PFILE)->cplusplus ? "__wchar_t" : WCHAR_TYPE)
134 /* The string value for __USER_LABEL_PREFIX__ */
136 #ifndef USER_LABEL_PREFIX
137 #define USER_LABEL_PREFIX ""
140 /* The string value for __REGISTER_PREFIX__ */
142 #ifndef REGISTER_PREFIX
143 #define REGISTER_PREFIX ""
146 /* In the definition of a #assert name, this structure forms
147 a list of the individual values asserted.
148 Each value is itself a list of "tokens".
149 These are strings that are compared by name. */
151 struct tokenlist_list
{
152 struct tokenlist_list
*next
;
153 struct arglist
*tokens
;
156 struct assertion_hashnode
{
157 struct assertion_hashnode
*next
; /* double links for easy deletion */
158 struct assertion_hashnode
*prev
;
159 /* also, a back pointer to this node's hash
160 chain is kept, in case the node is the head
161 of the chain and gets deleted. */
162 struct assertion_hashnode
**bucket_hdr
;
163 int length
; /* length of token, for quick comparison */
164 U_CHAR
*name
; /* the actual name */
165 /* List of token-sequences. */
166 struct tokenlist_list
*value
;
169 #define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
170 #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
172 #define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? CPP_BUFFER (pfile)->cur[N] : EOF)
173 #define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N))
174 #define GETC() CPP_BUF_GET (CPP_BUFFER (pfile))
175 #define PEEKC() CPP_BUF_PEEK (CPP_BUFFER (pfile))
176 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
177 (Note that it is false while we're expanding marco *arguments*.) */
178 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->cleanup == macro_cleanup)
180 /* Move all backslash-newline pairs out of embarrassing places.
181 Exchange all such pairs following BP
182 with any potentially-embarrassing characters that follow them.
183 Potentially-embarrassing characters are / and *
184 (because a backslash-newline inside a comment delimiter
185 would cause it not to be recognized). */
187 #define NEWLINE_FIX \
188 do {while (PEEKC() == '\\' && PEEKN(1) == '\n') FORWARD(2); } while(0)
190 /* Same, but assume we've already read the potential '\\' into C. */
191 #define NEWLINE_FIX1(C) do { \
192 while ((C) == '\\' && PEEKC() == '\n') { FORWARD(1); (C) = GETC(); }\
196 struct cpp_pending
*next
;
201 /* Forward declarations. */
204 extern void cpp_hash_cleanup
PARAMS ((cpp_reader
*));
205 extern void v_cpp_message
PROTO ((cpp_reader
*, int, const char *, va_list));
207 static void add_import
PROTO ((cpp_reader
*, int, char *));
208 static void append_include_chain
PROTO ((cpp_reader
*,
209 struct file_name_list
*,
210 struct file_name_list
*));
211 static void make_assertion
PROTO ((cpp_reader
*, char *, U_CHAR
*));
212 static void path_include
PROTO ((cpp_reader
*, char *));
213 static void initialize_builtins
PROTO ((cpp_reader
*));
214 static void initialize_char_syntax
PROTO ((struct cpp_options
*));
216 static void trigraph_pcp ();
218 static int finclude
PROTO ((cpp_reader
*, int, char *,
219 int, struct file_name_list
*));
220 static void validate_else
PROTO ((cpp_reader
*, char *));
221 static int comp_def_part
PROTO ((int, U_CHAR
*, int, U_CHAR
*,
224 extern void fancy_abort ();
226 static int lookup_import
PROTO ((cpp_reader
*, char *,
227 struct file_name_list
*));
228 static int redundant_include_p
PROTO ((cpp_reader
*, char *));
229 static int is_system_include
PROTO ((cpp_reader
*, char *));
230 static struct file_name_map
*read_name_map
PROTO ((cpp_reader
*, char *));
231 static char *read_filename_string
PROTO ((int, FILE *));
232 static int open_include_file
PROTO ((cpp_reader
*, char *,
233 struct file_name_list
*));
234 static int check_macro_name
PROTO ((cpp_reader
*, U_CHAR
*, char *));
235 static int compare_defs
PROTO ((cpp_reader
*,
236 DEFINITION
*, DEFINITION
*));
237 static int compare_token_lists
PROTO ((struct arglist
*,
239 static HOST_WIDE_INT eval_if_expression
PROTO ((cpp_reader
*, U_CHAR
*, int));
240 static int change_newlines
PROTO ((U_CHAR
*, int));
241 static struct arglist
*read_token_list
PROTO ((cpp_reader
*, int *));
242 static void free_token_list
PROTO ((struct arglist
*));
243 static int safe_read
PROTO ((int, char *, int));
244 static void push_macro_expansion
PARAMS ((cpp_reader
*,
245 U_CHAR
*, int, HASHNODE
*));
246 static struct cpp_pending
*nreverse_pending
PARAMS ((struct cpp_pending
*));
247 extern char *xrealloc ();
248 static char *xcalloc
PROTO ((unsigned, unsigned));
249 static char *savestring
PROTO ((char *));
251 static void conditional_skip
PROTO ((cpp_reader
*, int,
252 enum node_type
, U_CHAR
*));
253 static void skip_if_group
PROTO ((cpp_reader
*, int));
254 static int parse_name
PARAMS ((cpp_reader
*, int));
256 /* Last arg to output_line_command. */
257 enum file_change_code
{same_file
, enter_file
, leave_file
};
259 /* External declarations. */
261 extern HOST_WIDE_INT cpp_parse_expr
PARAMS ((cpp_reader
*));
263 extern char *version_string
;
264 extern struct tm
*localtime ();
266 struct file_name_list
268 struct file_name_list
*next
;
270 /* If the following is nonzero, it is a macro name.
271 Don't include the file again if that macro is defined. */
272 U_CHAR
*control_macro
;
273 /* If the following is nonzero, it is a C-language system include
275 int c_system_include_path
;
276 /* Mapping of file names for this directory. */
277 struct file_name_map
*name_map
;
278 /* Non-zero if name_map is valid. */
282 /* If a buffer's dir field is SELF_DIR_DUMMY, it means the file was found
283 via the same directory as the file that #included it. */
284 #define SELF_DIR_DUMMY ((struct file_name_list *) (~0))
286 /* #include "file" looks in source file dir, then stack. */
287 /* #include <file> just looks in the stack. */
288 /* -I directories are added to the end, then the defaults are added. */
290 static struct default_include
{
291 char *fname
; /* The name of the directory. */
292 char *component
; /* The component containing the directory */
293 int cplusplus
; /* Only look here if we're compiling C++. */
294 int cxx_aware
; /* Includes in this directory don't need to
295 be wrapped in extern "C" when compiling
297 } include_defaults_array
[]
298 #ifdef INCLUDE_DEFAULTS
302 /* Pick up GNU C++ specific include files. */
303 { GPLUSPLUS_INCLUDE_DIR
, "G++", 1, 1 },
304 { OLD_GPLUSPLUS_INCLUDE_DIR
, 0, 1, 1 },
306 /* This is the dir for fixincludes. Put it just before
307 the files that we fix. */
308 { GCC_INCLUDE_DIR
, "GCC", 0, 0 },
309 /* For cross-compilation, this dir name is generated
310 automatically in Makefile.in. */
311 { CROSS_INCLUDE_DIR
, "GCC",0, 0 },
312 #ifdef TOOL_INCLUDE_DIR
313 /* This is another place that the target system's headers might be. */
314 { TOOL_INCLUDE_DIR
, "BINUTILS", 0, 1 },
316 #else /* not CROSS_COMPILE */
317 #ifdef LOCAL_INCLUDE_DIR
318 /* This should be /usr/local/include and should come before
319 the fixincludes-fixed header files. */
320 { LOCAL_INCLUDE_DIR
, 0, 0, 1 },
322 #ifdef TOOL_INCLUDE_DIR
323 /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
324 Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
325 { TOOL_INCLUDE_DIR
, "BINUTILS", 0, 1 },
327 /* This is the dir for fixincludes. Put it just before
328 the files that we fix. */
329 { GCC_INCLUDE_DIR
, "GCC", 0, 0 },
330 /* Some systems have an extra dir of include files. */
331 #ifdef SYSTEM_INCLUDE_DIR
332 { SYSTEM_INCLUDE_DIR
, 0, 0, 0 },
334 #ifndef STANDARD_INCLUDE_COMPONENT
335 #define STANDARD_INCLUDE_COMPONENT 0
337 { STANDARD_INCLUDE_DIR
, STANDARD_INCLUDE_COMPONENT
, 0, 0 },
338 #endif /* not CROSS_COMPILE */
341 #endif /* no INCLUDE_DEFAULTS */
343 /* `struct directive' defines one #-directive, including how to handle it. */
346 int length
; /* Length of name */
347 int (*func
) /* Function to handle directive */
348 PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
349 char *name
; /* Name of directive */
350 enum node_type type
; /* Code which describes which directive. */
351 char command_reads_line
; /* One if rest of line is read by func. */
354 /* These functions are declared to return int instead of void since they
355 are going to be placed in a table and some old compilers have trouble with
356 pointers to functions returning void. */
358 static int do_define
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
359 static int do_line
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
360 static int do_include
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
361 static int do_undef
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
362 static int do_error
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
363 static int do_pragma
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
364 static int do_ident
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
365 static int do_if
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
366 static int do_xifdef
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
367 static int do_else
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
368 static int do_elif
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
369 static int do_endif
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
370 #ifdef SCCS_DIRECTIVE
371 static int do_sccs
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
373 static int do_once
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
374 static int do_assert
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
375 static int do_unassert
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
376 static int do_warning
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
378 #define IS_INCLUDE_DIRECTIVE_TYPE(t) \
379 ((int) T_INCLUDE <= (int) (t) && (int) (t) <= (int) T_IMPORT)
381 /* Here is the actual list of #-directives, most-often-used first.
382 The initialize_builtins function assumes #define is the very first. */
384 static struct directive directive_table
[] = {
385 { 6, do_define
, "define", T_DEFINE
},
386 { 5, do_xifdef
, "ifdef", T_IFDEF
, 1},
387 { 6, do_xifdef
, "ifndef", T_IFNDEF
, 1},
388 { 7, do_include
, "include", T_INCLUDE
, 1},
389 { 12, do_include
, "include_next", T_INCLUDE_NEXT
, 1},
390 { 6, do_include
, "import", T_IMPORT
, 1},
391 { 5, do_endif
, "endif", T_ENDIF
, 1},
392 { 4, do_else
, "else", T_ELSE
, 1},
393 { 2, do_if
, "if", T_IF
, 1},
394 { 4, do_elif
, "elif", T_ELIF
, 1},
395 { 5, do_undef
, "undef", T_UNDEF
},
396 { 5, do_error
, "error", T_ERROR
},
397 { 7, do_warning
, "warning", T_WARNING
},
398 { 6, do_pragma
, "pragma", T_PRAGMA
},
399 { 4, do_line
, "line", T_LINE
, 1},
400 { 5, do_ident
, "ident", T_IDENT
, 1},
401 #ifdef SCCS_DIRECTIVE
402 { 4, do_sccs
, "sccs", T_SCCS
},
404 { 6, do_assert
, "assert", T_ASSERT
, 1},
405 { 8, do_unassert
, "unassert", T_UNASSERT
, 1},
406 { -1, 0, "", T_UNUSED
},
409 /* table to tell if char can be part of a C identifier. */
410 U_CHAR is_idchar
[256];
411 /* table to tell if char can be first char of a c identifier. */
412 U_CHAR is_idstart
[256];
413 /* table to tell if c is horizontal space. */
414 U_CHAR is_hor_space
[256];
415 /* table to tell if c is horizontal or vertical space. */
416 static U_CHAR is_space
[256];
418 /* Initialize syntactic classifications of characters. */
421 initialize_char_syntax (opts
)
422 struct cpp_options
*opts
;
427 * Set up is_idchar and is_idstart tables. These should be
428 * faster than saying (is_alpha (c) || c == '_'), etc.
429 * Set up these things before calling any routines tthat
432 for (i
= 'a'; i
<= 'z'; i
++) {
433 is_idchar
[i
- 'a' + 'A'] = 1;
435 is_idstart
[i
- 'a' + 'A'] = 1;
438 for (i
= '0'; i
<= '9'; i
++)
442 is_idchar
['$'] = opts
->dollars_in_ident
;
443 is_idstart
['$'] = opts
->dollars_in_ident
;
445 /* horizontal space table */
446 is_hor_space
[' '] = 1;
447 is_hor_space
['\t'] = 1;
448 is_hor_space
['\v'] = 1;
449 is_hor_space
['\f'] = 1;
450 is_hor_space
['\r'] = 1;
461 /* Place into PFILE a quoted string representing the string SRC.
462 Caller must reserve enough space in pfile->token_buffer. */
465 quote_string (pfile
, src
)
471 CPP_PUTC_Q (pfile
, '\"');
473 switch ((c
= *src
++))
477 CPP_PUTC_Q (pfile
, c
);
480 sprintf ((char *)CPP_PWRITTEN (pfile
), "\\%03o", c
);
481 CPP_ADJUST_WRITTEN (pfile
, 4);
487 CPP_PUTC_Q (pfile
, '\\');
488 CPP_PUTC_Q (pfile
, c
);
492 CPP_PUTC_Q (pfile
, '\"');
493 CPP_NUL_TERMINATE_Q (pfile
);
498 /* Re-allocates PFILE->token_buffer so it will hold at least N more chars. */
501 cpp_grow_buffer (pfile
, n
)
505 long old_written
= CPP_WRITTEN (pfile
);
506 pfile
->token_buffer_size
= n
+ 2 * pfile
->token_buffer_size
;
507 pfile
->token_buffer
= (U_CHAR
*)
508 xrealloc(pfile
->token_buffer
, pfile
->token_buffer_size
);
509 CPP_SET_WRITTEN (pfile
, old_written
);
514 * process a given definition string, for initialization
515 * If STR is just an identifier, define it with value 1.
516 * If STR has anything after the identifier, then it should
517 * be identifier=definition.
521 cpp_define (pfile
, str
)
531 cpp_error (pfile
, "malformed option `-D %s'", str
);
534 while (is_idchar
[*++p
])
538 buf
= (U_CHAR
*) alloca (p
- buf
+ 4);
539 strcpy ((char *)buf
, str
);
540 strcat ((char *)buf
, " 1");
544 cpp_error (pfile
, "malformed option `-D %s'", str
);
550 /* Copy the entire option so we can modify it. */
551 buf
= (U_CHAR
*) alloca (2 * strlen (str
) + 1);
552 strncpy (buf
, str
, p
- str
);
553 /* Change the = to a space. */
555 /* Scan for any backslash-newline and remove it. */
560 if (*p
== '\\' && p
[1] == '\n')
568 do_define (pfile
, NULL
, buf
, buf
+ strlen (buf
));
571 /* Process the string STR as if it appeared as the body of a #assert.
572 OPTION is the option name for which STR was the argument. */
575 make_assertion (pfile
, option
, str
)
582 /* Copy the entire option so we can modify it. */
583 buf
= (U_CHAR
*) alloca (strlen (str
) + 1);
584 strcpy ((char *) buf
, str
);
585 /* Scan for any backslash-newline and remove it. */
589 if (*p
== '\\' && p
[1] == '\n')
598 if (!is_idstart
[*p
]) {
599 cpp_error (pfile
, "malformed option `%s %s'", option
, str
);
602 while (is_idchar
[*++p
])
604 while (*p
== ' ' || *p
== '\t') p
++;
605 if (! (*p
== 0 || *p
== '(')) {
606 cpp_error (pfile
, "malformed option `%s %s'", option
, str
);
610 if (cpp_push_buffer (pfile
, buf
, strlen (buf
)) != NULL
)
612 do_assert (pfile
, NULL
, NULL
, NULL
);
613 cpp_pop_buffer (pfile
);
617 /* Append a chain of `struct file_name_list's
618 to the end of the main include chain.
619 FIRST is the beginning of the chain to append, and LAST is the end. */
622 append_include_chain (pfile
, first
, last
)
624 struct file_name_list
*first
, *last
;
626 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
627 struct file_name_list
*dir
;
632 if (opts
->include
== 0)
633 opts
->include
= first
;
635 opts
->last_include
->next
= first
;
637 if (opts
->first_bracket_include
== 0)
638 opts
->first_bracket_include
= first
;
640 for (dir
= first
; ; dir
= dir
->next
) {
641 int len
= strlen (dir
->fname
) + INCLUDE_LEN_FUDGE
;
642 if (len
> pfile
->max_include_len
)
643 pfile
->max_include_len
= len
;
649 opts
->last_include
= last
;
652 /* Add output to `deps_buffer' for the -M switch.
653 STRING points to the text to be output.
654 SPACER is ':' for targets, ' ' for dependencies, zero for text
655 to be inserted literally. */
658 deps_output (pfile
, string
, spacer
)
663 int size
= strlen (string
);
668 #ifndef MAX_OUTPUT_COLUMNS
669 #define MAX_OUTPUT_COLUMNS 72
672 && pfile
->deps_column
> 0
673 && (pfile
->deps_column
+ size
) > MAX_OUTPUT_COLUMNS
)
675 deps_output (pfile
, " \\\n ", 0);
676 pfile
->deps_column
= 0;
679 if (pfile
->deps_size
+ size
+ 8 > pfile
->deps_allocated_size
)
681 pfile
->deps_allocated_size
= (pfile
->deps_size
+ size
+ 50) * 2;
682 pfile
->deps_buffer
= (char *) xrealloc (pfile
->deps_buffer
,
683 pfile
->deps_allocated_size
);
685 if (spacer
== ' ' && pfile
->deps_column
> 0)
686 pfile
->deps_buffer
[pfile
->deps_size
++] = ' ';
687 bcopy (string
, &pfile
->deps_buffer
[pfile
->deps_size
], size
);
688 pfile
->deps_size
+= size
;
689 pfile
->deps_column
+= size
;
691 pfile
->deps_buffer
[pfile
->deps_size
++] = ':';
692 pfile
->deps_buffer
[pfile
->deps_size
] = 0;
695 /* Given a colon-separated list of file names PATH,
696 add all the names to the search path for include files. */
699 path_include (pfile
, path
)
711 struct file_name_list
*dirtmp
;
713 /* Find the end of this name. */
714 while (*q
!= 0 && *q
!= PATH_SEPARATOR
) q
++;
716 /* An empty name in the path stands for the current directory. */
717 name
= (char *) xmalloc (2);
721 /* Otherwise use the directory that is named. */
722 name
= (char *) xmalloc (q
- p
+ 1);
723 bcopy (p
, name
, q
- p
);
727 dirtmp
= (struct file_name_list
*)
728 xmalloc (sizeof (struct file_name_list
));
729 dirtmp
->next
= 0; /* New one goes on the end */
730 dirtmp
->control_macro
= 0;
731 dirtmp
->c_system_include_path
= 0;
732 dirtmp
->fname
= name
;
733 dirtmp
->got_name_map
= 0;
734 append_include_chain (pfile
, dirtmp
, dirtmp
);
736 /* Advance past this name. */
740 /* Skip the colon. */
746 cpp_options_init (opts
)
749 bzero ((char *) opts
, sizeof *opts
);
750 opts
->in_fname
= NULL
;
751 opts
->out_fname
= NULL
;
753 /* Initialize is_idchar to allow $. */
754 opts
->dollars_in_ident
= 1;
755 initialize_char_syntax (opts
);
757 opts
->no_line_commands
= 0;
758 opts
->no_trigraphs
= 1;
759 opts
->put_out_comments
= 0;
760 opts
->print_include_names
= 0;
761 opts
->dump_macros
= dump_none
;
765 opts
->cplusplus_comments
= 0;
772 opts
->pedantic_errors
= 0;
773 opts
->inhibit_warnings
= 0;
774 opts
->warn_comments
= 0;
775 opts
->warn_import
= 1;
776 opts
->warnings_are_errors
= 0;
780 null_underflow (pfile
)
781 cpp_reader
*pfile ATTRIBUTE_UNUSED
;
787 null_cleanup (pbuf
, pfile
)
788 cpp_buffer
*pbuf ATTRIBUTE_UNUSED
;
789 cpp_reader
*pfile ATTRIBUTE_UNUSED
;
795 macro_cleanup (pbuf
, pfile
)
797 cpp_reader
*pfile ATTRIBUTE_UNUSED
;
799 HASHNODE
*macro
= (HASHNODE
*) pbuf
->data
;
800 if (macro
->type
== T_DISABLED
)
801 macro
->type
= T_MACRO
;
802 if (macro
->type
!= T_MACRO
|| pbuf
->buf
!= macro
->value
.defn
->expansion
)
808 file_cleanup (pbuf
, pfile
)
810 cpp_reader
*pfile ATTRIBUTE_UNUSED
;
820 /* Assuming we have read '/'.
821 If this is the start of a comment (followed by '*' or '/'),
822 skip to the end of the comment, and return ' '.
823 Return EOF if we reached the end of file before the end of the comment.
824 If not the start of a comment, return '/'. */
827 skip_comment (pfile
, linep
)
832 while (PEEKC() == '\\' && PEEKN(1) == '\n')
847 while (c
== '\\' && PEEKC() == '\n')
851 FORWARD(1), c
= GETC();
853 if (prev_c
== '*' && c
== '/')
855 if (c
== '\n' && linep
)
859 else if (PEEKC() == '/' && CPP_OPTIONS (pfile
)->cplusplus_comments
)
866 return ' '; /* Allow // to be terminated by EOF. */
867 while (c
== '\\' && PEEKC() == '\n')
876 /* Don't consider final '\n' to be part of comment. */
886 /* Skip whitespace \-newline and comments. Does not macro-expand. */
889 cpp_skip_hspace (pfile
)
899 if ((c
== '\f' || c
== '\v') && CPP_PEDANTIC (pfile
))
900 cpp_pedwarn (pfile
, "%s in preprocessing directive",
901 c
== '\f' ? "formfeed" : "vertical tab");
907 c
= skip_comment (pfile
, NULL
);
910 if (c
== EOF
|| c
== '/')
913 else if (c
== '\\' && PEEKN(1) == '\n') {
916 else if (c
== '@' && CPP_BUFFER (pfile
)->has_escapes
917 && is_hor_space
[PEEKN(1)])
923 /* Read the rest of the current line.
924 The line is appended to PFILE's output buffer. */
927 copy_rest_of_line (pfile
)
930 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
947 goto scan_directive_token
;
951 if (nextc
== '*' || (opts
->cplusplus_comments
&& nextc
== '/'))
952 goto scan_directive_token
;
956 if (CPP_PEDANTIC (pfile
))
957 cpp_pedwarn (pfile
, "%s in preprocessing directive",
958 c
== '\f' ? "formfeed" : "vertical tab");
964 scan_directive_token
:
966 cpp_get_token (pfile
);
972 CPP_NUL_TERMINATE (pfile
);
976 skip_rest_of_line (pfile
)
979 long old
= CPP_WRITTEN (pfile
);
980 copy_rest_of_line (pfile
);
981 CPP_SET_WRITTEN (pfile
, old
);
984 /* Handle a possible # directive.
985 '#' has already been read. */
988 handle_directive (pfile
)
991 register struct directive
*kt
;
994 U_CHAR
*ident
, *line_end
;
995 long old_written
= CPP_WRITTEN (pfile
);
997 cpp_skip_hspace (pfile
);
1000 if (c
>= '0' && c
<= '9')
1002 /* Handle # followed by a line number. */
1003 if (CPP_PEDANTIC (pfile
))
1004 cpp_pedwarn (pfile
, "`#' followed by integer");
1005 do_line (pfile
, NULL
, NULL
, NULL
);
1006 goto done_a_directive
;
1009 /* Now find the directive name. */
1010 CPP_PUTC (pfile
, '#');
1011 parse_name (pfile
, GETC());
1012 ident
= pfile
->token_buffer
+ old_written
+ 1;
1013 ident_length
= CPP_PWRITTEN (pfile
) - ident
;
1014 if (ident_length
== 0 && PEEKC() == '\n')
1016 /* A line of just `#' becomes blank. */
1017 goto done_a_directive
;
1021 if (ident_length
== 0 || !is_idstart
[*ident
]) {
1023 while (is_idchar
[*p
]) {
1024 if (*p
< '0' || *p
> '9')
1028 /* Avoid error for `###' and similar cases unless -pedantic. */
1030 while (*p
== '#' || is_hor_space
[*p
]) p
++;
1032 if (pedantic
&& !lang_asm
)
1033 cpp_warning (pfile
, "invalid preprocessor directive");
1039 cpp_error (pfile
, "invalid preprocessor directive name");
1045 * Decode the keyword and call the appropriate expansion
1046 * routine, after moving the input pointer up to the next line.
1048 for (kt
= directive_table
; ; kt
++) {
1049 if (kt
->length
<= 0)
1050 goto not_a_directive
;
1051 if (kt
->length
== ident_length
&& !strncmp (kt
->name
, ident
, ident_length
))
1055 if (kt
->command_reads_line
)
1059 /* Nonzero means do not delete comments within the directive.
1060 #define needs this when -traditional. */
1061 int comments
= CPP_TRADITIONAL (pfile
) && kt
->type
== T_DEFINE
;
1062 int save_put_out_comments
= CPP_OPTIONS (pfile
)->put_out_comments
;
1063 CPP_OPTIONS (pfile
)->put_out_comments
= comments
;
1064 after_ident
= CPP_WRITTEN (pfile
);
1065 copy_rest_of_line (pfile
);
1066 CPP_OPTIONS (pfile
)->put_out_comments
= save_put_out_comments
;
1069 /* We may want to pass through #define, #pragma, and #include.
1070 Other directives may create output, but we don't want the directive
1071 itself out, so we pop it now. For example conditionals may emit
1072 #failed ... #endfailed stuff. But note that popping the buffer
1073 means the parameters to kt->func may point after pfile->limit
1074 so these parameters are invalid as soon as something gets appended
1075 to the token_buffer. */
1077 line_end
= CPP_PWRITTEN (pfile
);
1078 if (! (kt
->type
== T_DEFINE
1079 || kt
->type
== T_PRAGMA
1080 || (IS_INCLUDE_DIRECTIVE_TYPE (kt
->type
)
1081 && CPP_OPTIONS (pfile
)->dump_includes
)))
1082 CPP_SET_WRITTEN (pfile
, old_written
);
1084 (*kt
->func
) (pfile
, kt
, pfile
->token_buffer
+ after_ident
, line_end
);
1086 if (kt
->type
== T_DEFINE
)
1088 if (CPP_OPTIONS (pfile
)->dump_macros
== dump_names
)
1090 /* Skip "#define". */
1091 U_CHAR
*p
= pfile
->token_buffer
+ old_written
+ 7;
1093 SKIP_WHITE_SPACE (p
);
1094 while (is_idchar
[*p
]) p
++;
1096 CPP_PUTC (pfile
, '\n');
1098 else if (CPP_OPTIONS (pfile
)->dump_macros
!= dump_definitions
)
1099 CPP_SET_WRITTEN (pfile
, old_written
);
1109 /* Pass a directive through to the output file.
1110 BUF points to the contents of the directive, as a contiguous string.
1111 LIMIT points to the first character past the end of the directive.
1112 KEYWORD is the keyword-table entry for the directive. */
1115 pass_thru_directive (buf
, limit
, pfile
, keyword
)
1116 U_CHAR
*buf
, *limit
;
1118 struct directive
*keyword
;
1120 register unsigned keyword_length
= keyword
->length
;
1122 CPP_RESERVE (pfile
, 1 + keyword_length
+ (limit
- buf
));
1123 CPP_PUTC_Q (pfile
, '#');
1124 CPP_PUTS_Q (pfile
, keyword
->name
, keyword_length
);
1125 if (limit
!= buf
&& buf
[0] != ' ')
1126 CPP_PUTC_Q (pfile
, ' ');
1127 CPP_PUTS_Q (pfile
, buf
, limit
- buf
);
1129 CPP_PUTS_Q (pfile
, '\n');
1130 /* Count the line we have just made in the output,
1131 to get in sync properly. */
1136 /* The arglist structure is built by do_define to tell
1137 collect_definition where the argument names begin. That
1138 is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist
1139 would contain pointers to the strings x, y, and z.
1140 Collect_definition would then build a DEFINITION node,
1141 with reflist nodes pointing to the places x, y, and z had
1142 appeared. So the arglist is just convenience data passed
1143 between these two routines. It is not kept around after
1144 the current #define has been processed and entered into the
1148 struct arglist
*next
;
1155 /* Read a replacement list for a macro with parameters.
1156 Build the DEFINITION structure.
1157 Reads characters of text starting at BUF until END.
1158 ARGLIST specifies the formal parameters to look for
1159 in the text of the definition; NARGS is the number of args
1160 in that list, or -1 for a macro name that wants no argument list.
1161 MACRONAME is the macro name itself (so we can avoid recursive expansion)
1162 and NAMELEN is its length in characters.
1164 Note that comments, backslash-newlines, and leading white space
1165 have already been deleted from the argument. */
1168 collect_expansion (pfile
, buf
, limit
, nargs
, arglist
)
1170 U_CHAR
*buf
, *limit
;
1172 struct arglist
*arglist
;
1175 register U_CHAR
*p
, *lastp
, *exp_p
;
1176 struct reflist
*endpat
= NULL
;
1177 /* Pointer to first nonspace after last ## seen. */
1179 /* Pointer to first nonspace after last single-# seen. */
1180 U_CHAR
*stringify
= 0;
1182 int expected_delimiter
= '\0';
1184 /* Scan thru the replacement list, ignoring comments and quoted
1185 strings, picking up on the macro calls. It does a linear search
1186 thru the arg list on every potential symbol. Profiling might say
1187 that something smarter should happen. */
1192 /* Find the beginning of the trailing whitespace. */
1194 while (p
< limit
&& is_space
[limit
[-1]]) limit
--;
1196 /* Allocate space for the text in the macro definition.
1197 Leading and trailing whitespace chars need 2 bytes each.
1198 Each other input char may or may not need 1 byte,
1199 so this is an upper bound. The extra 5 are for invented
1200 leading and trailing newline-marker and final null. */
1201 maxsize
= (sizeof (DEFINITION
)
1203 /* Occurrences of '@' get doubled, so allocate extra space for them. */
1207 defn
= (DEFINITION
*) xcalloc (1, maxsize
);
1209 defn
->nargs
= nargs
;
1210 exp_p
= defn
->expansion
= (U_CHAR
*) defn
+ sizeof (DEFINITION
);
1215 /* Add one initial space escape-marker to prevent accidental
1216 token-pasting (often removed by macroexpand). */
1220 if (limit
- p
>= 2 && p
[0] == '#' && p
[1] == '#') {
1221 cpp_error (pfile
, "`##' at start of macro definition");
1225 /* Process the main body of the definition. */
1227 int skipped_arg
= 0;
1228 register U_CHAR c
= *p
++;
1232 if (!CPP_TRADITIONAL (pfile
)) {
1236 if (expected_delimiter
!= '\0') {
1237 if (c
== expected_delimiter
)
1238 expected_delimiter
= '\0';
1240 expected_delimiter
= c
;
1244 if (p
< limit
&& expected_delimiter
) {
1245 /* In a string, backslash goes through
1246 and makes next char ordinary. */
1252 /* An '@' in a string or character constant stands for itself,
1253 and does not need to be escaped. */
1254 if (!expected_delimiter
)
1259 /* # is ordinary inside a string. */
1260 if (expected_delimiter
)
1262 if (p
< limit
&& *p
== '#') {
1263 /* ##: concatenate preceding and following tokens. */
1264 /* Take out the first #, discard preceding whitespace. */
1266 while (exp_p
> lastp
&& is_hor_space
[exp_p
[-1]])
1268 /* Skip the second #. */
1270 /* Discard following whitespace. */
1271 SKIP_WHITE_SPACE (p
);
1274 cpp_error (pfile
, "`##' at end of macro definition");
1275 } else if (nargs
>= 0) {
1276 /* Single #: stringify following argument ref.
1277 Don't leave the # in the expansion. */
1279 SKIP_WHITE_SPACE (p
);
1280 if (p
== limit
|| ! is_idstart
[*p
]
1281 || (*p
== 'L' && p
+ 1 < limit
&& (p
[1] == '\'' || p
[1] == '"')))
1283 "`#' operator is not followed by a macro argument name");
1290 /* In -traditional mode, recognize arguments inside strings and
1291 character constants, and ignore special properties of #.
1292 Arguments inside strings are considered "stringified", but no
1293 extra quote marks are supplied. */
1297 if (expected_delimiter
!= '\0') {
1298 if (c
== expected_delimiter
)
1299 expected_delimiter
= '\0';
1301 expected_delimiter
= c
;
1305 /* Backslash quotes delimiters and itself, but not macro args. */
1306 if (expected_delimiter
!= 0 && p
< limit
1307 && (*p
== expected_delimiter
|| *p
== '\\')) {
1314 if (expected_delimiter
!= '\0') /* No comments inside strings. */
1317 /* If we find a comment that wasn't removed by handle_directive,
1318 this must be -traditional. So replace the comment with
1322 while (p
< limit
&& !(p
[-2] == '*' && p
[-1] == '/'))
1325 /* Mark this as a concatenation-point, as if it had been ##. */
1333 /* Handle the start of a symbol. */
1334 if (is_idchar
[c
] && nargs
> 0) {
1335 U_CHAR
*id_beg
= p
- 1;
1339 while (p
!= limit
&& is_idchar
[*p
]) p
++;
1340 id_len
= p
- id_beg
;
1343 && ! (id_len
== 1 && c
== 'L' && (*p
== '\'' || *p
== '"'))) {
1344 register struct arglist
*arg
;
1346 for (arg
= arglist
; arg
!= NULL
; arg
= arg
->next
) {
1347 struct reflist
*tpat
;
1349 if (arg
->name
[0] == c
1350 && arg
->length
== id_len
1351 && strncmp (arg
->name
, id_beg
, id_len
) == 0) {
1352 if (expected_delimiter
&& CPP_OPTIONS (pfile
)->warn_stringify
) {
1353 if (CPP_TRADITIONAL (pfile
)) {
1354 cpp_warning (pfile
, "macro argument `%.*s' is stringified.",
1358 "macro arg `%.*s' would be stringified with -traditional.",
1362 /* If ANSI, don't actually substitute inside a string. */
1363 if (!CPP_TRADITIONAL (pfile
) && expected_delimiter
)
1365 /* make a pat node for this arg and append it to the end of
1367 tpat
= (struct reflist
*) xmalloc (sizeof (struct reflist
));
1369 tpat
->raw_before
= concat
== id_beg
;
1370 tpat
->raw_after
= 0;
1371 tpat
->rest_args
= arg
->rest_args
;
1372 tpat
->stringify
= (CPP_TRADITIONAL (pfile
)
1373 ? expected_delimiter
!= '\0'
1374 : stringify
== id_beg
);
1377 defn
->pattern
= tpat
;
1379 endpat
->next
= tpat
;
1382 tpat
->argno
= arg
->argno
;
1383 tpat
->nchars
= exp_p
- lastp
;
1385 register U_CHAR
*p1
= p
;
1386 SKIP_WHITE_SPACE (p1
);
1387 if (p1
+ 2 <= limit
&& p1
[0] == '#' && p1
[1] == '#')
1388 tpat
->raw_after
= 1;
1390 lastp
= exp_p
; /* place to start copying from next time */
1397 /* If this was not a macro arg, copy it into the expansion. */
1398 if (! skipped_arg
) {
1399 register U_CHAR
*lim1
= p
;
1403 if (stringify
== id_beg
)
1405 "`#' operator should be followed by a macro argument name");
1410 if (!CPP_TRADITIONAL (pfile
) && expected_delimiter
== 0)
1412 /* If ANSI, put in a "@ " marker to prevent token pasting.
1413 But not if "inside a string" (which in ANSI mode
1414 happens only for -D option). */
1421 defn
->length
= exp_p
- defn
->expansion
;
1423 /* Crash now if we overrun the allocated size. */
1424 if (defn
->length
+ 1 > maxsize
)
1428 /* This isn't worth the time it takes. */
1429 /* give back excess storage */
1430 defn
->expansion
= (U_CHAR
*) xrealloc (defn
->expansion
, defn
->length
+ 1);
1437 * special extension string that can be added to the last macro argument to
1438 * allow it to absorb the "rest" of the arguments when expanded. Ex:
1439 * #define wow(a, b...) process (b, a, b)
1440 * { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); }
1441 * { wow (one, two); } -> { process (two, one, two); }
1442 * if this "rest_arg" is used with the concat token '##' and if it is not
1443 * supplied then the token attached to with ## will not be outputted. Ex:
1444 * #define wow (a, b...) process (b ## , a, ## b)
1445 * { wow (1, 2); } -> { process (2, 1, 2); }
1446 * { wow (one); } -> { process (one); {
1448 static char rest_extension
[] = "...";
1449 #define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1)
1451 /* Create a DEFINITION node from a #define directive. Arguments are
1452 as for do_define. */
1455 create_definition (buf
, limit
, pfile
, predefinition
)
1456 U_CHAR
*buf
, *limit
;
1460 U_CHAR
*bp
; /* temp ptr into input buffer */
1461 U_CHAR
*symname
; /* remember where symbol name starts */
1462 int sym_length
; /* and how long it is */
1465 char *file
= CPP_BUFFER (pfile
) ? CPP_BUFFER (pfile
)->nominal_fname
: "";
1467 int arglengths
= 0; /* Accumulate lengths of arg names
1468 plus number of args. */
1470 cpp_buf_line_and_col (CPP_BUFFER (pfile
), &line
, &col
);
1474 while (is_hor_space
[*bp
])
1477 symname
= bp
; /* remember where it starts */
1479 sym_length
= check_macro_name (pfile
, bp
, "macro");
1482 /* Lossage will occur if identifiers or control keywords are broken
1483 across lines using backslash. This is not the right place to take
1487 struct arglist
*arg_ptrs
= NULL
;
1490 bp
++; /* skip '(' */
1491 SKIP_WHITE_SPACE (bp
);
1493 /* Loop over macro argument names. */
1494 while (*bp
!= ')') {
1495 struct arglist
*temp
;
1497 temp
= (struct arglist
*) alloca (sizeof (struct arglist
));
1499 temp
->next
= arg_ptrs
;
1500 temp
->argno
= argno
++;
1501 temp
->rest_args
= 0;
1505 cpp_pedwarn (pfile
, "another parameter follows `%s'", rest_extension
);
1507 if (!is_idstart
[*bp
])
1508 cpp_pedwarn (pfile
, "invalid character in macro parameter name");
1510 /* Find the end of the arg name. */
1511 while (is_idchar
[*bp
]) {
1513 /* do we have a "special" rest-args extension here? */
1514 if (limit
- bp
> REST_EXTENSION_LENGTH
1515 && strncmp (rest_extension
, bp
, REST_EXTENSION_LENGTH
) == 0) {
1517 temp
->rest_args
= 1;
1521 temp
->length
= bp
- temp
->name
;
1523 bp
+= REST_EXTENSION_LENGTH
;
1524 arglengths
+= temp
->length
+ 2;
1525 SKIP_WHITE_SPACE (bp
);
1526 if (temp
->length
== 0 || (*bp
!= ',' && *bp
!= ')')) {
1527 cpp_error (pfile
, "badly punctuated parameter list in `#define'");
1532 SKIP_WHITE_SPACE (bp
);
1535 cpp_error (pfile
, "unterminated parameter list in `#define'");
1539 struct arglist
*otemp
;
1541 for (otemp
= temp
->next
; otemp
!= NULL
; otemp
= otemp
->next
)
1542 if (temp
->length
== otemp
->length
1543 && strncmp (temp
->name
, otemp
->name
, temp
->length
) == 0) {
1546 name
= (U_CHAR
*) alloca (temp
->length
+ 1);
1547 (void) strncpy (name
, temp
->name
, temp
->length
);
1548 name
[temp
->length
] = '\0';
1550 "duplicate argument name `%s' in `#define'", name
);
1556 ++bp
; /* skip paren */
1557 SKIP_WHITE_SPACE (bp
);
1558 /* now everything from bp before limit is the definition. */
1559 defn
= collect_expansion (pfile
, bp
, limit
, argno
, arg_ptrs
);
1560 defn
->rest_args
= rest_args
;
1562 /* Now set defn->args.argnames to the result of concatenating
1563 the argument names in reverse order
1564 with comma-space between them. */
1565 defn
->args
.argnames
= (U_CHAR
*) xmalloc (arglengths
+ 1);
1567 struct arglist
*temp
;
1569 for (temp
= arg_ptrs
; temp
; temp
= temp
->next
) {
1570 bcopy (temp
->name
, &defn
->args
.argnames
[i
], temp
->length
);
1572 if (temp
->next
!= 0) {
1573 defn
->args
.argnames
[i
++] = ',';
1574 defn
->args
.argnames
[i
++] = ' ';
1577 defn
->args
.argnames
[i
] = 0;
1580 /* Simple expansion or empty definition. */
1584 if (is_hor_space
[*bp
]) {
1586 SKIP_WHITE_SPACE (bp
);
1589 case '!': case '"': case '#': case '%': case '&': case '\'':
1590 case ')': case '*': case '+': case ',': case '-': case '.':
1591 case '/': case ':': case ';': case '<': case '=': case '>':
1592 case '?': case '[': case '\\': case ']': case '^': case '{':
1593 case '|': case '}': case '~':
1594 cpp_warning (pfile
, "missing white space after `#define %.*s'",
1595 sym_length
, symname
);
1599 cpp_pedwarn (pfile
, "missing white space after `#define %.*s'",
1600 sym_length
, symname
);
1605 /* now everything from bp before limit is the definition. */
1606 defn
= collect_expansion (pfile
, bp
, limit
, -1, NULL_PTR
);
1607 defn
->args
.argnames
= (U_CHAR
*) "";
1613 /* OP is null if this is a predefinition */
1614 defn
->predefined
= predefinition
;
1616 mdef
.symnam
= symname
;
1617 mdef
.symlen
= sym_length
;
1626 /* Check a purported macro name SYMNAME, and yield its length.
1627 USAGE is the kind of name this is intended for. */
1630 check_macro_name (pfile
, symname
, usage
)
1638 for (p
= symname
; is_idchar
[*p
]; p
++)
1640 sym_length
= p
- symname
;
1642 || (sym_length
== 1 && *symname
== 'L' && (*p
== '\'' || *p
== '"')))
1643 cpp_error (pfile
, "invalid %s name", usage
);
1644 else if (!is_idstart
[*symname
]) {
1645 U_CHAR
*msg
; /* what pain... */
1646 msg
= (U_CHAR
*) alloca (sym_length
+ 1);
1647 bcopy (symname
, msg
, sym_length
);
1648 msg
[sym_length
] = 0;
1649 cpp_error (pfile
, "invalid %s name `%s'", usage
, msg
);
1651 if (! strncmp (symname
, "defined", 7) && sym_length
== 7)
1652 cpp_error (pfile
, "invalid %s name `defined'", usage
);
1657 /* Return zero if two DEFINITIONs are isomorphic. */
1660 compare_defs (pfile
, d1
, d2
)
1662 DEFINITION
*d1
, *d2
;
1664 register struct reflist
*a1
, *a2
;
1665 register U_CHAR
*p1
= d1
->expansion
;
1666 register U_CHAR
*p2
= d2
->expansion
;
1669 if (d1
->nargs
!= d2
->nargs
)
1671 if (CPP_PEDANTIC (pfile
)
1672 && strcmp ((char *)d1
->args
.argnames
, (char *)d2
->args
.argnames
))
1674 for (a1
= d1
->pattern
, a2
= d2
->pattern
; a1
&& a2
;
1675 a1
= a1
->next
, a2
= a2
->next
) {
1676 if (!((a1
->nchars
== a2
->nchars
&& ! strncmp (p1
, p2
, a1
->nchars
))
1677 || ! comp_def_part (first
, p1
, a1
->nchars
, p2
, a2
->nchars
, 0))
1678 || a1
->argno
!= a2
->argno
1679 || a1
->stringify
!= a2
->stringify
1680 || a1
->raw_before
!= a2
->raw_before
1681 || a1
->raw_after
!= a2
->raw_after
)
1689 if (comp_def_part (first
, p1
, d1
->length
- (p1
- d1
->expansion
),
1690 p2
, d2
->length
- (p2
- d2
->expansion
), 1))
1695 /* Return 1 if two parts of two macro definitions are effectively different.
1696 One of the parts starts at BEG1 and has LEN1 chars;
1697 the other has LEN2 chars at BEG2.
1698 Any sequence of whitespace matches any other sequence of whitespace.
1699 FIRST means these parts are the first of a macro definition;
1700 so ignore leading whitespace entirely.
1701 LAST means these parts are the last of a macro definition;
1702 so ignore trailing whitespace entirely. */
1705 comp_def_part (first
, beg1
, len1
, beg2
, len2
, last
)
1707 U_CHAR
*beg1
, *beg2
;
1711 register U_CHAR
*end1
= beg1
+ len1
;
1712 register U_CHAR
*end2
= beg2
+ len2
;
1714 while (beg1
!= end1
&& is_space
[*beg1
]) beg1
++;
1715 while (beg2
!= end2
&& is_space
[*beg2
]) beg2
++;
1718 while (beg1
!= end1
&& is_space
[end1
[-1]]) end1
--;
1719 while (beg2
!= end2
&& is_space
[end2
[-1]]) end2
--;
1721 while (beg1
!= end1
&& beg2
!= end2
) {
1722 if (is_space
[*beg1
] && is_space
[*beg2
]) {
1723 while (beg1
!= end1
&& is_space
[*beg1
]) beg1
++;
1724 while (beg2
!= end2
&& is_space
[*beg2
]) beg2
++;
1725 } else if (*beg1
== *beg2
) {
1729 return (beg1
!= end1
) || (beg2
!= end2
);
1732 /* Process a #define command.
1733 BUF points to the contents of the #define command, as a contiguous string.
1734 LIMIT points to the first character past the end of the definition.
1735 KEYWORD is the keyword-table entry for #define,
1736 or NULL for a "predefined" macro. */
1739 do_define (pfile
, keyword
, buf
, limit
)
1741 struct directive
*keyword
;
1742 U_CHAR
*buf
, *limit
;
1749 /* If this is a precompiler run (with -pcp) pass thru #define commands. */
1750 if (pcp_outfile
&& keyword
)
1751 pass_thru_directive (buf
, limit
, pfile
, keyword
);
1754 mdef
= create_definition (buf
, limit
, pfile
, keyword
== NULL
);
1758 hashcode
= hashf (mdef
.symnam
, mdef
.symlen
, HASHSIZE
);
1760 if ((hp
= cpp_lookup (pfile
, mdef
.symnam
, mdef
.symlen
, hashcode
)) != NULL
)
1763 /* Redefining a precompiled key is ok. */
1764 if (hp
->type
== T_PCSTRING
)
1766 /* Redefining a macro is ok if the definitions are the same. */
1767 else if (hp
->type
== T_MACRO
)
1768 ok
= ! compare_defs (pfile
, mdef
.defn
, hp
->value
.defn
);
1769 /* Redefining a constant is ok with -D. */
1770 else if (hp
->type
== T_CONST
)
1771 ok
= ! CPP_OPTIONS (pfile
)->done_initializing
;
1772 /* Print the warning if it's not ok. */
1775 U_CHAR
*msg
; /* what pain... */
1777 /* If we are passing through #define and #undef directives, do
1778 that for this re-definition now. */
1779 if (CPP_OPTIONS (pfile
)->debug_output
&& keyword
)
1780 pass_thru_directive (buf
, limit
, pfile
, keyword
);
1782 msg
= (U_CHAR
*) alloca (mdef
.symlen
+ 22);
1784 bcopy (mdef
.symnam
, msg
+ 1, mdef
.symlen
);
1785 strcpy ((char *) (msg
+ mdef
.symlen
+ 1), "' redefined");
1786 cpp_pedwarn (pfile
, msg
);
1787 if (hp
->type
== T_MACRO
)
1788 cpp_pedwarn_with_file_and_line (pfile
, hp
->value
.defn
->file
, hp
->value
.defn
->line
,
1789 "this is the location of the previous definition");
1791 /* Replace the old definition. */
1793 hp
->value
.defn
= mdef
.defn
;
1797 /* If we are passing through #define and #undef directives, do
1798 that for this new definition now. */
1799 if (CPP_OPTIONS (pfile
)->debug_output
&& keyword
)
1800 pass_thru_directive (buf
, limit
, pfile
, keyword
);
1801 install (mdef
.symnam
, mdef
.symlen
, T_MACRO
, 0,
1802 (char *) mdef
.defn
, hashcode
);
1812 /* This structure represents one parsed argument in a macro call.
1813 `raw' points to the argument text as written (`raw_length' is its length).
1814 `expanded' points to the argument's macro-expansion
1815 (its length is `expand_length').
1816 `stringified_length' is the length the argument would have
1818 `use_count' is the number of times this macro arg is substituted
1819 into the macro. If the actual use count exceeds 10,
1820 the value stored is 10. */
1822 /* raw and expanded are relative to ARG_BASE */
1823 #define ARG_BASE ((pfile)->token_buffer)
1826 /* Strings relative to pfile->token_buffer */
1827 long raw
, expanded
, stringified
;
1828 int raw_length
, expand_length
;
1829 int stringified_length
;
1834 /* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack.
1835 If BUFFER != NULL, then use the LENGTH characters in BUFFER
1836 as the new input buffer.
1837 Return the new buffer, or NULL on failure. */
1840 cpp_push_buffer (pfile
, buffer
, length
)
1845 register cpp_buffer
*buf
= CPP_BUFFER (pfile
);
1846 if (buf
== pfile
->buffer_stack
)
1848 cpp_fatal (pfile
, "%s: macro or `#include' recursion too deep",
1853 bzero ((char *) buf
, sizeof (cpp_buffer
));
1854 CPP_BUFFER (pfile
) = buf
;
1855 buf
->if_stack
= pfile
->if_stack
;
1856 buf
->cleanup
= null_cleanup
;
1857 buf
->underflow
= null_underflow
;
1858 buf
->buf
= buf
->cur
= buffer
;
1859 buf
->alimit
= buf
->rlimit
= buffer
+ length
;
1865 cpp_pop_buffer (pfile
)
1868 cpp_buffer
*buf
= CPP_BUFFER (pfile
);
1869 (*buf
->cleanup
) (buf
, pfile
);
1870 return ++CPP_BUFFER (pfile
);
1873 /* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer.
1874 Pop the buffer when done. */
1877 cpp_scan_buffer (pfile
)
1880 cpp_buffer
*buffer
= CPP_BUFFER (pfile
);
1883 enum cpp_token token
= cpp_get_token (pfile
);
1884 if (token
== CPP_EOF
) /* Should not happen ... */
1886 if (token
== CPP_POP
&& CPP_BUFFER (pfile
) == buffer
)
1888 cpp_pop_buffer (pfile
);
1895 * Rescan a string (which may have escape marks) into pfile's buffer.
1896 * Place the result in pfile->token_buffer.
1898 * The input is copied before it is scanned, so it is safe to pass
1899 * it something from the token_buffer that will get overwritten
1900 * (because it follows CPP_WRITTEN). This is used by do_include.
1904 cpp_expand_to_buffer (pfile
, buf
, length
)
1909 register cpp_buffer
*ip
;
1913 U_CHAR
*limit
= buf
+ length
;
1916 int odepth
= indepth
;
1922 /* Set up the input on the input stack. */
1924 buf1
= (U_CHAR
*) alloca (length
+ 1);
1926 register U_CHAR
*p1
= buf
;
1927 register U_CHAR
*p2
= buf1
;
1934 ip
= cpp_push_buffer (pfile
, buf1
, length
);
1937 ip
->has_escapes
= 1;
1939 ip
->lineno
= obuf
.lineno
= 1;
1942 /* Scan the input, create the output. */
1943 cpp_scan_buffer (pfile
);
1946 if (indepth
!= odepth
)
1950 CPP_NUL_TERMINATE (pfile
);
1955 adjust_position (buf
, limit
, linep
, colp
)
1965 (*linep
)++, (*colp
) = 1;
1971 /* Move line_base forward, updating lineno and colno. */
1974 update_position (pbuf
)
1975 register cpp_buffer
*pbuf
;
1977 unsigned char *old_pos
= pbuf
->buf
+ pbuf
->line_base
;
1978 unsigned char *new_pos
= pbuf
->cur
;
1979 register struct parse_marker
*mark
;
1980 for (mark
= pbuf
->marks
; mark
!= NULL
; mark
= mark
->next
)
1982 if (pbuf
->buf
+ mark
->position
< new_pos
)
1983 new_pos
= pbuf
->buf
+ mark
->position
;
1985 pbuf
->line_base
+= new_pos
- old_pos
;
1986 adjust_position (old_pos
, new_pos
, &pbuf
->lineno
, &pbuf
->colno
);
1990 cpp_buf_line_and_col (pbuf
, linep
, colp
)
1991 register cpp_buffer
*pbuf
;
1999 *linep
= pbuf
->lineno
;
2000 *colp
= pbuf
->colno
;
2001 adjust_position (pbuf
->buf
+ pbuf
->line_base
, pbuf
->cur
, linep
, colp
);
2010 /* Return the cpp_buffer that corresponds to a file (not a macro). */
2013 cpp_file_buffer (pfile
)
2016 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
2018 for ( ; ip
!= CPP_NULL_BUFFER (pfile
); ip
= CPP_PREV_BUFFER (ip
))
2019 if (ip
->fname
!= NULL
)
2025 count_newlines (buf
, limit
)
2026 register U_CHAR
*buf
;
2027 register U_CHAR
*limit
;
2029 register long count
= 0;
2040 * write out a #line command, for instance, after an #include file.
2041 * If CONDITIONAL is nonzero, we can omit the #line if it would
2042 * appear to be a no-op, and we can output a few newlines instead
2043 * if we want to increase the line number by a small amount.
2044 * FILE_CHANGE says whether we are entering a file, leaving, or neither.
2048 output_line_command (pfile
, conditional
, file_change
)
2051 enum file_change_code file_change
;
2054 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
2056 if (ip
->fname
== NULL
)
2059 update_position (ip
);
2061 if (CPP_OPTIONS (pfile
)->no_line_commands
2062 || CPP_OPTIONS (pfile
)->no_output
)
2065 line
= CPP_BUFFER (pfile
)->lineno
;
2066 col
= CPP_BUFFER (pfile
)->colno
;
2067 adjust_position (CPP_LINE_BASE (ip
), ip
->cur
, &line
, &col
);
2069 if (CPP_OPTIONS (pfile
)->no_line_commands
)
2073 if (line
== pfile
->lineno
)
2076 /* If the inherited line number is a little too small,
2077 output some newlines instead of a #line command. */
2078 if (line
> pfile
->lineno
&& line
< pfile
->lineno
+ 8) {
2079 CPP_RESERVE (pfile
, 20);
2080 while (line
> pfile
->lineno
) {
2081 CPP_PUTC_Q (pfile
, '\n');
2089 /* Don't output a line number of 0 if we can help it. */
2090 if (ip
->lineno
== 0 && ip
->bufp
- ip
->buf
< ip
->length
2091 && *ip
->bufp
== '\n') {
2097 CPP_RESERVE (pfile
, 4 * strlen (ip
->nominal_fname
) + 50);
2099 #ifdef OUTPUT_LINE_COMMANDS
2100 static char sharp_line
[] = "#line ";
2102 static char sharp_line
[] = "# ";
2104 CPP_PUTS_Q (pfile
, sharp_line
, sizeof(sharp_line
)-1);
2107 sprintf ((char *) CPP_PWRITTEN (pfile
), "%ld ", line
);
2108 CPP_ADJUST_WRITTEN (pfile
, strlen (CPP_PWRITTEN (pfile
)));
2110 quote_string (pfile
, ip
->nominal_fname
);
2111 if (file_change
!= same_file
) {
2112 CPP_PUTC_Q (pfile
, ' ');
2113 CPP_PUTC_Q (pfile
, file_change
== enter_file
? '1' : '2');
2115 /* Tell cc1 if following text comes from a system header file. */
2116 if (ip
->system_header_p
) {
2117 CPP_PUTC_Q (pfile
, ' ');
2118 CPP_PUTC_Q (pfile
, '3');
2120 #ifndef NO_IMPLICIT_EXTERN_C
2121 /* Tell cc1plus if following text should be treated as C. */
2122 if (ip
->system_header_p
== 2 && CPP_OPTIONS (pfile
)->cplusplus
) {
2123 CPP_PUTC_Q (pfile
, ' ');
2124 CPP_PUTC_Q (pfile
, '4');
2127 CPP_PUTC_Q (pfile
, '\n');
2128 pfile
->lineno
= line
;
2132 * Parse a macro argument and append the info on PFILE's token_buffer.
2133 * REST_ARGS means to absorb the rest of the args.
2134 * Return nonzero to indicate a syntax error.
2137 static enum cpp_token
2138 macarg (pfile
, rest_args
)
2143 enum cpp_token token
;
2144 char save_put_out_comments
= CPP_OPTIONS (pfile
)->put_out_comments
;
2145 CPP_OPTIONS (pfile
)->put_out_comments
= 0;
2147 /* Try to parse as much of the argument as exists at this
2148 input stack level. */
2149 pfile
->no_macro_expand
++;
2152 token
= cpp_get_token (pfile
);
2158 /* If we've hit end of file, it's an error (reported by caller).
2159 Ditto if it's the end of cpp_expand_to_buffer text.
2160 If we've hit end of macro, just continue. */
2161 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile
)))
2172 /* if we've returned to lowest level and
2173 we aren't absorbing all args */
2174 if (paren
== 0 && rest_args
== 0)
2178 /* Remove ',' or ')' from argument buffer. */
2179 CPP_ADJUST_WRITTEN (pfile
, -1);
2186 CPP_OPTIONS (pfile
)->put_out_comments
= save_put_out_comments
;
2187 pfile
->no_macro_expand
--;
2192 /* Turn newlines to spaces in the string of length LENGTH at START,
2193 except inside of string constants.
2194 The string is copied into itself with its beginning staying fixed. */
2197 change_newlines (start
, length
)
2201 register U_CHAR
*ibp
;
2202 register U_CHAR
*obp
;
2203 register U_CHAR
*limit
;
2207 limit
= start
+ length
;
2210 while (ibp
< limit
) {
2211 *obp
++ = c
= *ibp
++;
2216 /* Notice and skip strings, so that we don't delete newlines in them. */
2219 while (ibp
< limit
) {
2220 *obp
++ = c
= *ibp
++;
2223 if (c
== '\n' && quotec
== '\'')
2239 if (!pfile
->timebuf
) {
2240 time_t t
= time ((time_t *) 0);
2241 pfile
->timebuf
= localtime (&t
);
2243 return pfile
->timebuf
;
2246 static char *monthnames
[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
2247 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
2251 * expand things like __FILE__. Place the expansion into the output
2252 * buffer *without* rescanning.
2256 special_symbol (hp
, pfile
)
2263 cpp_buffer
*ip
= NULL
;
2266 int paren
= 0; /* For special `defined' keyword */
2269 if (pcp_outfile
&& pcp_inside_if
2270 && hp
->type
!= T_SPEC_DEFINED
&& hp
->type
!= T_CONST
)
2272 "Predefined macro `%s' used inside `#if' during precompilation",
2276 for (ip
= CPP_BUFFER (pfile
); ; ip
= CPP_PREV_BUFFER (ip
))
2278 if (ip
== CPP_NULL_BUFFER (pfile
))
2280 cpp_error (pfile
, "cccp error: not in any file?!");
2281 return; /* the show must go on */
2283 if (ip
->fname
!= NULL
)
2293 if (hp
->type
== T_BASE_FILE
)
2295 while (CPP_PREV_BUFFER (ip
) != CPP_NULL_BUFFER (pfile
))
2296 ip
= CPP_PREV_BUFFER (ip
);
2298 string
= ip
->nominal_fname
;
2302 CPP_RESERVE (pfile
, 3 + 4 * strlen (string
));
2303 quote_string (pfile
, string
);
2307 case T_INCLUDE_LEVEL
:
2309 ip
= CPP_BUFFER (pfile
);
2310 for (; ip
!= CPP_NULL_BUFFER (pfile
); ip
= CPP_PREV_BUFFER (ip
))
2311 if (ip
->fname
!= NULL
)
2314 buf
= (char *) alloca (8); /* Eight bytes ought to be more than enough */
2315 sprintf (buf
, "%d", true_indepth
- 1);
2319 buf
= (char *) alloca (3 + strlen (version_string
));
2320 sprintf (buf
, "\"%s\"", version_string
);
2323 #ifndef NO_BUILTIN_SIZE_TYPE
2329 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2330 case T_PTRDIFF_TYPE
:
2336 buf
= CPP_WCHAR_TYPE (pfile
);
2339 case T_USER_LABEL_PREFIX_TYPE
:
2340 buf
= USER_LABEL_PREFIX
;
2343 case T_REGISTER_PREFIX_TYPE
:
2344 buf
= REGISTER_PREFIX
;
2348 buf
= (char *) alloca (4 * sizeof (int));
2349 sprintf (buf
, "%d", hp
->value
.ival
);
2350 #ifdef STDC_0_IN_SYSTEM_HEADERS
2351 if (ip
->system_header_p
2352 && hp
->length
== 8 && bcmp (hp
->name
, "__STDC__", 8) == 0
2353 && ! cpp_lookup (pfile
, (U_CHAR
*) "__STRICT_ANSI__", -1, -1))
2357 if (pcp_inside_if
&& pcp_outfile
)
2358 /* Output a precondition for this macro use */
2359 fprintf (pcp_outfile
, "#define %s %d\n", hp
->name
, hp
->value
.ival
);
2365 long line
= ip
->lineno
;
2366 long col
= ip
->colno
;
2367 adjust_position (CPP_LINE_BASE (ip
), ip
->cur
, &line
, &col
);
2369 buf
= (char *) alloca (10);
2370 sprintf (buf
, "%ld", line
);
2376 buf
= (char *) alloca (20);
2377 timebuf
= timestamp (pfile
);
2378 if (hp
->type
== T_DATE
)
2379 sprintf (buf
, "\"%s %2d %4d\"", monthnames
[timebuf
->tm_mon
],
2380 timebuf
->tm_mday
, timebuf
->tm_year
+ 1900);
2382 sprintf (buf
, "\"%02d:%02d:%02d\"", timebuf
->tm_hour
, timebuf
->tm_min
,
2386 case T_SPEC_DEFINED
:
2387 buf
= " 0 "; /* Assume symbol is not defined */
2388 ip
= CPP_BUFFER (pfile
);
2389 SKIP_WHITE_SPACE (ip
->cur
);
2390 if (*ip
->cur
== '(')
2393 ip
->cur
++; /* Skip over the paren */
2394 SKIP_WHITE_SPACE (ip
->cur
);
2397 if (!is_idstart
[*ip
->cur
])
2399 if (ip
->cur
[0] == 'L' && (ip
->cur
[1] == '\'' || ip
->cur
[1] == '"'))
2401 if ((hp
= cpp_lookup (pfile
, ip
->cur
, -1, -1)))
2404 if (pcp_outfile
&& pcp_inside_if
2405 && (hp
->type
== T_CONST
2406 || (hp
->type
== T_MACRO
&& hp
->value
.defn
->predefined
)))
2407 /* Output a precondition for this macro use. */
2408 fprintf (pcp_outfile
, "#define %s\n", hp
->name
);
2414 if (pcp_outfile
&& pcp_inside_if
)
2416 /* Output a precondition for this macro use */
2417 U_CHAR
*cp
= ip
->bufp
;
2418 fprintf (pcp_outfile
, "#undef ");
2419 while (is_idchar
[*cp
]) /* Ick! */
2420 fputc (*cp
++, pcp_outfile
);
2421 putc ('\n', pcp_outfile
);
2424 while (is_idchar
[*ip
->cur
])
2426 SKIP_WHITE_SPACE (ip
->cur
);
2429 if (*ip
->cur
!= ')')
2437 cpp_error (pfile
, "`defined' without an identifier");
2441 cpp_error (pfile
, "cccp error: invalid special hash type"); /* time for gdb */
2445 CPP_RESERVE (pfile
, len
+ 1);
2446 CPP_PUTS_Q (pfile
, buf
, len
);
2447 CPP_NUL_TERMINATE_Q (pfile
);
2452 /* Write out a #define command for the special named MACRO_NAME
2453 to PFILE's token_buffer. */
2456 dump_special_to_buffer (pfile
, macro_name
)
2460 static char define_directive
[] = "#define ";
2461 int macro_name_length
= strlen (macro_name
);
2462 output_line_command (pfile
, 0, same_file
);
2463 CPP_RESERVE (pfile
, sizeof(define_directive
) + macro_name_length
);
2464 CPP_PUTS_Q (pfile
, define_directive
, sizeof(define_directive
)-1);
2465 CPP_PUTS_Q (pfile
, macro_name
, macro_name_length
);
2466 CPP_PUTC_Q (pfile
, ' ');
2467 cpp_expand_to_buffer (pfile
, macro_name
, macro_name_length
);
2468 CPP_PUTC (pfile
, '\n');
2471 /* Initialize the built-in macros. */
2474 initialize_builtins (pfile
)
2477 install ((U_CHAR
*)"__LINE__", -1, T_SPECLINE
, 0, 0, -1);
2478 install ((U_CHAR
*)"__DATE__", -1, T_DATE
, 0, 0, -1);
2479 install ((U_CHAR
*)"__FILE__", -1, T_FILE
, 0, 0, -1);
2480 install ((U_CHAR
*)"__BASE_FILE__", -1, T_BASE_FILE
, 0, 0, -1);
2481 install ((U_CHAR
*)"__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL
, 0, 0, -1);
2482 install ((U_CHAR
*)"__VERSION__", -1, T_VERSION
, 0, 0, -1);
2483 #ifndef NO_BUILTIN_SIZE_TYPE
2484 install ((U_CHAR
*)"__SIZE_TYPE__", -1, T_SIZE_TYPE
, 0, 0, -1);
2486 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2487 install ((U_CHAR
*)"__PTRDIFF_TYPE__ ", -1, T_PTRDIFF_TYPE
, 0, 0, -1);
2489 install ((U_CHAR
*)"__WCHAR_TYPE__", -1, T_WCHAR_TYPE
, 0, 0, -1);
2490 install ((U_CHAR
*)"__USER_LABEL_PREFIX__", -1, T_USER_LABEL_PREFIX_TYPE
, 0, 0, -1);
2491 install ((U_CHAR
*)"__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE
, 0, 0, -1);
2492 install ((U_CHAR
*)"__TIME__", -1, T_TIME
, 0, 0, -1);
2493 if (!CPP_TRADITIONAL (pfile
))
2494 install ((U_CHAR
*)"__STDC__", -1, T_CONST
, STDC_VALUE
, 0, -1);
2495 if (CPP_OPTIONS (pfile
)->objc
)
2496 install ((U_CHAR
*)"__OBJC__", -1, T_CONST
, 1, 0, -1);
2497 /* This is supplied using a -D by the compiler driver
2498 so that it is present only when truly compiling with GNU C. */
2499 /* install ("__GNUC__", -1, T_CONST, 2, 0, -1); */
2501 if (CPP_OPTIONS (pfile
)->debug_output
)
2503 dump_special_to_buffer (pfile
, "__BASE_FILE__");
2504 dump_special_to_buffer (pfile
, "__VERSION__");
2505 #ifndef NO_BUILTIN_SIZE_TYPE
2506 dump_special_to_buffer (pfile
, "__SIZE_TYPE__");
2508 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2509 dump_special_to_buffer (pfile
, "__PTRDIFF_TYPE__");
2511 dump_special_to_buffer (pfile
, "__WCHAR_TYPE__");
2512 dump_special_to_buffer (pfile
, "__DATE__");
2513 dump_special_to_buffer (pfile
, "__TIME__");
2514 if (!CPP_TRADITIONAL (pfile
))
2515 dump_special_to_buffer (pfile
, "__STDC__");
2516 if (CPP_OPTIONS (pfile
)->objc
)
2517 dump_special_to_buffer (pfile
, "__OBJC__");
2521 /* Return 1 iff a token ending in C1 followed directly by a token C2
2522 could cause mis-tokenization. */
2525 unsafe_chars (c1
, c2
)
2531 if (c2
== c1
|| c2
== '=')
2535 case '0': case '1': case '2': case '3': case '4':
2536 case '5': case '6': case '7': case '8': case '9':
2537 case 'e': case 'E': case 'p': case 'P':
2538 if (c2
== '-' || c2
== '+')
2539 return 1; /* could extend a pre-processing number */
2542 if (c2
== '\'' || c2
== '\"')
2543 return 1; /* Could turn into L"xxx" or L'xxx'. */
2547 case 'a': case 'b': case 'c': case 'd': case 'f':
2548 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
2549 case 'm': case 'n': case 'o': case 'q': case 'r':
2550 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
2552 case 'A': case 'B': case 'C': case 'D': case 'F':
2553 case 'G': case 'H': case 'I': case 'J': case 'K':
2554 case 'M': case 'N': case 'O': case 'Q': case 'R':
2555 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
2557 /* We're in the middle of either a name or a pre-processing number. */
2558 return (is_idchar
[c2
] || c2
== '.');
2559 case '<': case '>': case '!': case '%': case '#': case ':':
2560 case '^': case '&': case '|': case '*': case '/': case '=':
2561 return (c2
== c1
|| c2
== '=');
2566 /* Expand a macro call.
2567 HP points to the symbol that is the macro being called.
2568 Put the result of expansion onto the input stack
2569 so that subsequent input by our caller will use it.
2571 If macro wants arguments, caller has already verified that
2572 an argument list follows; arguments come from the input stack. */
2575 macroexpand (pfile
, hp
)
2580 DEFINITION
*defn
= hp
->value
.defn
;
2581 register U_CHAR
*xbuf
;
2582 long start_line
, start_column
;
2584 struct argdata
*args
;
2585 long old_written
= CPP_WRITTEN (pfile
);
2587 int start_line
= instack
[indepth
].lineno
;
2589 int rest_args
, rest_zero
;
2593 CHECK_DEPTH (return;);
2597 /* This macro is being used inside a #if, which means it must be */
2598 /* recorded as a precondition. */
2599 if (pcp_inside_if
&& pcp_outfile
&& defn
->predefined
)
2600 dump_single_macro (hp
, pcp_outfile
);
2603 pfile
->output_escapes
++;
2604 cpp_buf_line_and_col (cpp_file_buffer (pfile
), &start_line
, &start_column
);
2606 nargs
= defn
->nargs
;
2610 enum cpp_token token
;
2612 args
= (struct argdata
*) alloca ((nargs
+ 1) * sizeof (struct argdata
));
2614 for (i
= 0; i
< nargs
; i
++)
2616 args
[i
].raw
= args
[i
].expanded
= 0;
2617 args
[i
].raw_length
= 0;
2618 args
[i
].expand_length
= args
[i
].stringified_length
= -1;
2619 args
[i
].use_count
= 0;
2622 /* Parse all the macro args that are supplied. I counts them.
2623 The first NARGS args are stored in ARGS.
2624 The rest are discarded. If rest_args is set then we assume
2625 macarg absorbed the rest of the args. */
2629 FORWARD(1); /* Discard the open-parenthesis before the first arg. */
2634 if (i
< nargs
|| (nargs
== 0 && i
== 0))
2636 /* if we are working on last arg which absorbs rest of args... */
2637 if (i
== nargs
- 1 && defn
->rest_args
)
2639 args
[i
].raw
= CPP_WRITTEN (pfile
);
2640 token
= macarg (pfile
, rest_args
);
2641 args
[i
].raw_length
= CPP_WRITTEN (pfile
) - args
[i
].raw
;
2642 args
[i
].newlines
= 0; /* FIXME */
2645 token
= macarg (pfile
, 0);
2646 if (token
== CPP_EOF
|| token
== CPP_POP
)
2648 cpp_error_with_line (pfile
, start_line
, start_column
,
2649 "unterminated macro call");
2653 } while (token
== CPP_COMMA
);
2655 /* If we got one arg but it was just whitespace, call that 0 args. */
2658 register U_CHAR
*bp
= ARG_BASE
+ args
[0].raw
;
2659 register U_CHAR
*lim
= bp
+ args
[0].raw_length
;
2660 /* cpp.texi says for foo ( ) we provide one argument.
2661 However, if foo wants just 0 arguments, treat this as 0. */
2663 while (bp
!= lim
&& is_space
[*bp
]) bp
++;
2668 /* Don't output an error message if we have already output one for
2669 a parse error above. */
2671 if (nargs
== 0 && i
> 0)
2673 cpp_error (pfile
, "arguments given to macro `%s'", hp
->name
);
2677 /* traditional C allows foo() if foo wants one argument. */
2678 if (nargs
== 1 && i
== 0 && CPP_TRADITIONAL (pfile
))
2680 /* the rest args token is allowed to absorb 0 tokens */
2681 else if (i
== nargs
- 1 && defn
->rest_args
)
2684 cpp_error (pfile
, "macro `%s' used without args", hp
->name
);
2686 cpp_error (pfile
, "macro `%s' used with just one arg", hp
->name
);
2688 cpp_error (pfile
, "macro `%s' used with only %d args",
2694 "macro `%s' used with too many (%d) args", hp
->name
, i
);
2698 /* If macro wants zero args, we parsed the arglist for checking only.
2699 Read directly from the macro definition. */
2702 xbuf
= defn
->expansion
;
2703 xbuf_len
= defn
->length
;
2707 register U_CHAR
*exp
= defn
->expansion
;
2708 register int offset
; /* offset in expansion,
2709 copied a piece at a time */
2710 register int totlen
; /* total amount of exp buffer filled so far */
2712 register struct reflist
*ap
, *last_ap
;
2714 /* Macro really takes args. Compute the expansion of this call. */
2716 /* Compute length in characters of the macro's expansion.
2717 Also count number of times each arg is used. */
2718 xbuf_len
= defn
->length
;
2719 for (ap
= defn
->pattern
; ap
!= NULL
; ap
= ap
->next
)
2723 register struct argdata
*arg
= &args
[ap
->argno
];
2724 /* Stringify if it hasn't already been */
2725 if (arg
->stringified_length
< 0)
2727 int arglen
= arg
->raw_length
;
2731 /* Initially need_space is -1. Otherwise, 1 means the
2732 previous character was a space, but we suppressed it;
2733 0 means the previous character was a non-space. */
2734 int need_space
= -1;
2736 arg
->stringified
= CPP_WRITTEN (pfile
);
2737 if (!CPP_TRADITIONAL (pfile
))
2738 CPP_PUTC (pfile
, '\"'); /* insert beginning quote */
2739 for (; i
< arglen
; i
++)
2741 c
= (ARG_BASE
+ arg
->raw
)[i
];
2745 /* Internal sequences of whitespace are replaced by
2746 one space except within an string or char token.*/
2749 if (CPP_WRITTEN (pfile
) > arg
->stringified
2750 && (CPP_PWRITTEN (pfile
))[-1] == '@')
2752 /* "@ " escape markers are removed */
2753 CPP_ADJUST_WRITTEN (pfile
, -1);
2756 if (need_space
== 0)
2760 else if (need_space
> 0)
2761 CPP_PUTC (pfile
, ' ');
2776 else if (c
== '\"' || c
== '\'')
2780 /* Escape these chars */
2781 if (c
== '\"' || (in_string
&& c
== '\\'))
2782 CPP_PUTC (pfile
, '\\');
2784 CPP_PUTC (pfile
, c
);
2787 CPP_RESERVE (pfile
, 4);
2788 sprintf ((char *)CPP_PWRITTEN (pfile
), "\\%03o",
2790 CPP_ADJUST_WRITTEN (pfile
, 4);
2793 if (!CPP_TRADITIONAL (pfile
))
2794 CPP_PUTC (pfile
, '\"'); /* insert ending quote */
2795 arg
->stringified_length
2796 = CPP_WRITTEN (pfile
) - arg
->stringified
;
2798 xbuf_len
+= args
[ap
->argno
].stringified_length
;
2800 else if (ap
->raw_before
|| ap
->raw_after
|| CPP_TRADITIONAL (pfile
))
2801 /* Add 4 for two newline-space markers to prevent
2802 token concatenation. */
2803 xbuf_len
+= args
[ap
->argno
].raw_length
+ 4;
2806 /* We have an ordinary (expanded) occurrence of the arg.
2807 So compute its expansion, if we have not already. */
2808 if (args
[ap
->argno
].expand_length
< 0)
2810 args
[ap
->argno
].expanded
= CPP_WRITTEN (pfile
);
2811 cpp_expand_to_buffer (pfile
,
2812 ARG_BASE
+ args
[ap
->argno
].raw
,
2813 args
[ap
->argno
].raw_length
);
2815 args
[ap
->argno
].expand_length
2816 = CPP_WRITTEN (pfile
) - args
[ap
->argno
].expanded
;
2819 /* Add 4 for two newline-space markers to prevent
2820 token concatenation. */
2821 xbuf_len
+= args
[ap
->argno
].expand_length
+ 4;
2823 if (args
[ap
->argno
].use_count
< 10)
2824 args
[ap
->argno
].use_count
++;
2827 xbuf
= (U_CHAR
*) xmalloc (xbuf_len
+ 1);
2829 /* Generate in XBUF the complete expansion
2830 with arguments substituted in.
2831 TOTLEN is the total size generated so far.
2832 OFFSET is the index in the definition
2833 of where we are copying from. */
2834 offset
= totlen
= 0;
2835 for (last_ap
= NULL
, ap
= defn
->pattern
; ap
!= NULL
;
2836 last_ap
= ap
, ap
= ap
->next
)
2838 register struct argdata
*arg
= &args
[ap
->argno
];
2839 int count_before
= totlen
;
2841 /* Add chars to XBUF. */
2842 for (i
= 0; i
< ap
->nchars
; i
++, offset
++)
2843 xbuf
[totlen
++] = exp
[offset
];
2845 /* If followed by an empty rest arg with concatenation,
2846 delete the last run of nonwhite chars. */
2847 if (rest_zero
&& totlen
> count_before
2848 && ((ap
->rest_args
&& ap
->raw_before
)
2849 || (last_ap
!= NULL
&& last_ap
->rest_args
2850 && last_ap
->raw_after
)))
2852 /* Delete final whitespace. */
2853 while (totlen
> count_before
&& is_space
[xbuf
[totlen
- 1]])
2856 /* Delete the nonwhites before them. */
2857 while (totlen
> count_before
&& ! is_space
[xbuf
[totlen
- 1]])
2861 if (ap
->stringify
!= 0)
2863 bcopy (ARG_BASE
+ arg
->stringified
,
2864 xbuf
+ totlen
, arg
->stringified_length
);
2865 totlen
+= arg
->stringified_length
;
2867 else if (ap
->raw_before
|| ap
->raw_after
|| CPP_TRADITIONAL (pfile
))
2869 U_CHAR
*p1
= ARG_BASE
+ arg
->raw
;
2870 U_CHAR
*l1
= p1
+ arg
->raw_length
;
2873 while (p1
!= l1
&& is_space
[*p1
]) p1
++;
2874 while (p1
!= l1
&& is_idchar
[*p1
])
2875 xbuf
[totlen
++] = *p1
++;
2876 /* Delete any no-reexpansion marker that follows
2877 an identifier at the beginning of the argument
2878 if the argument is concatenated with what precedes it. */
2879 if (p1
[0] == '@' && p1
[1] == '-')
2884 /* Arg is concatenated after: delete trailing whitespace,
2885 whitespace markers, and no-reexpansion markers. */
2888 if (is_space
[l1
[-1]]) l1
--;
2889 else if (l1
[-1] == '-')
2891 U_CHAR
*p2
= l1
- 1;
2892 /* If a `-' is preceded by an odd number of newlines then it
2893 and the last newline are a no-reexpansion marker. */
2894 while (p2
!= p1
&& p2
[-1] == '\n') p2
--;
2895 if ((l1
- 1 - p2
) & 1) {
2904 bcopy (p1
, xbuf
+ totlen
, l1
- p1
);
2909 U_CHAR
*expanded
= ARG_BASE
+ arg
->expanded
;
2910 if (!ap
->raw_before
&& totlen
> 0 && arg
->expand_length
2911 && !CPP_TRADITIONAL(pfile
)
2912 && unsafe_chars (xbuf
[totlen
-1], expanded
[0]))
2914 xbuf
[totlen
++] = '@';
2915 xbuf
[totlen
++] = ' ';
2918 bcopy (expanded
, xbuf
+ totlen
, arg
->expand_length
);
2919 totlen
+= arg
->expand_length
;
2921 if (!ap
->raw_after
&& totlen
> 0 && offset
< defn
->length
2922 && !CPP_TRADITIONAL(pfile
)
2923 && unsafe_chars (xbuf
[totlen
-1], exp
[offset
]))
2925 xbuf
[totlen
++] = '@';
2926 xbuf
[totlen
++] = ' ';
2929 /* If a macro argument with newlines is used multiple times,
2930 then only expand the newlines once. This avoids creating
2931 output lines which don't correspond to any input line,
2932 which confuses gdb and gcov. */
2933 if (arg
->use_count
> 1 && arg
->newlines
> 0)
2935 /* Don't bother doing change_newlines for subsequent
2939 = change_newlines (expanded
, arg
->expand_length
);
2943 if (totlen
> xbuf_len
)
2947 /* if there is anything left of the definition
2948 after handling the arg list, copy that in too. */
2950 for (i
= offset
; i
< defn
->length
; i
++)
2952 /* if we've reached the end of the macro */
2955 if (! (rest_zero
&& last_ap
!= NULL
&& last_ap
->rest_args
2956 && last_ap
->raw_after
))
2957 xbuf
[totlen
++] = exp
[i
];
2965 pfile
->output_escapes
--;
2967 /* Now put the expansion on the input stack
2968 so our caller will commence reading from it. */
2969 push_macro_expansion (pfile
, xbuf
, xbuf_len
, hp
);
2970 CPP_BUFFER (pfile
)->has_escapes
= 1;
2972 /* Pop the space we've used in the token_buffer for argument expansion. */
2973 CPP_SET_WRITTEN (pfile
, old_written
);
2975 /* Recursive macro use sometimes works traditionally.
2976 #define foo(x,y) bar (x (y,0), y)
2979 if (!CPP_TRADITIONAL (pfile
))
2980 hp
->type
= T_DISABLED
;
2984 push_macro_expansion (pfile
, xbuf
, xbuf_len
, hp
)
2986 register U_CHAR
*xbuf
;
2990 register cpp_buffer
*mbuf
= cpp_push_buffer (pfile
, xbuf
, xbuf_len
);
2993 mbuf
->cleanup
= macro_cleanup
;
2996 /* The first chars of the expansion should be a "@ " added by
2997 collect_expansion. This is to prevent accidental token-pasting
2998 between the text preceding the macro invocation, and the macro
3001 We would like to avoid adding unneeded spaces (for the sake of
3002 tools that use cpp, such as imake). In some common cases we can
3003 tell that it is safe to omit the space.
3005 The character before the macro invocation cannot have been an
3006 idchar (or else it would have been pasted with the idchars of
3007 the macro name). Therefore, if the first non-space character
3008 of the expansion is an idchar, we do not need the extra space
3009 to prevent token pasting.
3011 Also, we don't need the extra space if the first char is '(',
3012 or some other (less common) characters. */
3014 if (xbuf
[0] == '@' && xbuf
[1] == ' '
3015 && (is_idchar
[xbuf
[2]] || xbuf
[2] == '(' || xbuf
[2] == '\''
3016 || xbuf
[2] == '\"'))
3020 /* Like cpp_get_token, except that it does not read past end-of-line.
3021 Also, horizontal space is skipped, and macros are popped. */
3023 static enum cpp_token
3024 get_directive_token (pfile
)
3029 long old_written
= CPP_WRITTEN (pfile
);
3030 enum cpp_token token
;
3031 cpp_skip_hspace (pfile
);
3032 if (PEEKC () == '\n')
3034 token
= cpp_get_token (pfile
);
3038 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile
)))
3040 /* ... else fall though ... */
3041 case CPP_HSPACE
: case CPP_COMMENT
:
3042 CPP_SET_WRITTEN (pfile
, old_written
);
3050 /* Handle #include and #import.
3051 This function expects to see "fname" or <fname> on the input.
3053 The input is normally in part of the output_buffer following
3054 CPP_WRITTEN, and will get overwritten by output_line_command.
3055 I.e. in input file specification has been popped by handle_directive.
3059 do_include (pfile
, keyword
, unused1
, unused2
)
3061 struct directive
*keyword
;
3062 U_CHAR
*unused1 ATTRIBUTE_UNUSED
, *unused2 ATTRIBUTE_UNUSED
;
3064 int importing
= (keyword
->type
== T_IMPORT
);
3065 int skip_dirs
= (keyword
->type
== T_INCLUDE_NEXT
);
3066 char *fname
; /* Dynamically allocated fname buffer */
3068 U_CHAR
*fbeg
, *fend
; /* Beginning and end of fname */
3069 enum cpp_token token
;
3071 /* Chain of dirs to search */
3072 struct file_name_list
*search_start
= CPP_OPTIONS (pfile
)->include
;
3073 struct file_name_list dsp
[1]; /* First in chain, if #include "..." */
3074 struct file_name_list
*searchptr
= 0;
3075 long old_written
= CPP_WRITTEN (pfile
);
3079 int f
; /* file number */
3081 int angle_brackets
= 0; /* 0 for "...", 1 for <...> */
3088 f
= -1; /* JF we iz paranoid! */
3090 if (CPP_PEDANTIC (pfile
) && !CPP_BUFFER (pfile
)->system_header_p
)
3093 cpp_pedwarn (pfile
, "ANSI C does not allow `#import'");
3095 cpp_pedwarn (pfile
, "ANSI C does not allow `#include_next'");
3098 if (importing
&& CPP_OPTIONS (pfile
)->warn_import
3099 && !CPP_OPTIONS (pfile
)->inhibit_warnings
3100 && !CPP_BUFFER (pfile
)->system_header_p
&& !pfile
->import_warning
)
3102 pfile
->import_warning
= 1;
3103 cpp_warning (pfile
, "using `#import' is not recommended");
3104 fprintf (stderr
, "The fact that a certain header file need not be processed more than once\n");
3105 fprintf (stderr
, "should be indicated in the header file, not where it is used.\n");
3106 fprintf (stderr
, "The best way to do this is with a conditional of this form:\n\n");
3107 fprintf (stderr
, " #ifndef _FOO_H_INCLUDED\n");
3108 fprintf (stderr
, " #define _FOO_H_INCLUDED\n");
3109 fprintf (stderr
, " ... <real contents of file> ...\n");
3110 fprintf (stderr
, " #endif /* Not _FOO_H_INCLUDED */\n\n");
3111 fprintf (stderr
, "Then users can use `#include' any number of times.\n");
3112 fprintf (stderr
, "GNU C automatically avoids processing the file more than once\n");
3113 fprintf (stderr
, "when it is equipped with such a conditional.\n");
3116 pfile
->parsing_include_directive
++;
3117 token
= get_directive_token (pfile
);
3118 pfile
->parsing_include_directive
--;
3120 if (token
== CPP_STRING
)
3122 /* FIXME - check no trailing garbage */
3123 fbeg
= pfile
->token_buffer
+ old_written
+ 1;
3124 fend
= CPP_PWRITTEN (pfile
) - 1;
3125 if (fbeg
[-1] == '<')
3128 /* If -I-, start with the first -I dir after the -I-. */
3129 if (CPP_OPTIONS (pfile
)->first_bracket_include
)
3130 search_start
= CPP_OPTIONS (pfile
)->first_bracket_include
;
3132 /* If -I- was specified, don't search current dir, only spec'd ones. */
3133 else if (! CPP_OPTIONS (pfile
)->ignore_srcdir
)
3135 cpp_buffer
*fp
= CPP_BUFFER (pfile
);
3136 /* We have "filename". Figure out directory this source
3137 file is coming from and put it on the front of the list. */
3139 for ( ; fp
!= CPP_NULL_BUFFER (pfile
); fp
= CPP_PREV_BUFFER (fp
))
3144 if ((nam
= fp
->nominal_fname
) != NULL
)
3146 /* Found a named file. Figure out dir of the file,
3147 and put it in front of the search list. */
3148 dsp
[0].next
= search_start
;
3151 ep
= rindex (nam
, '/');
3153 ep
= rindex (nam
, ']');
3154 if (ep
== NULL
) ep
= rindex (nam
, '>');
3155 if (ep
== NULL
) ep
= rindex (nam
, ':');
3156 if (ep
!= NULL
) ep
++;
3161 dsp
[0].fname
= (char *) alloca (n
+ 1);
3162 strncpy (dsp
[0].fname
, nam
, n
);
3163 dsp
[0].fname
[n
] = '\0';
3164 if (n
+ INCLUDE_LEN_FUDGE
> pfile
->max_include_len
)
3165 pfile
->max_include_len
= n
+ INCLUDE_LEN_FUDGE
;
3169 dsp
[0].fname
= 0; /* Current directory */
3171 dsp
[0].got_name_map
= 0;
3178 else if (token
== CPP_NAME
)
3181 * Support '#include xyz' like VAX-C to allow for easy use of all the
3182 * decwindow include files. It defaults to '#include <xyz.h>' (so the
3183 * code from case '<' is repeated here) and generates a warning.
3186 "VAX-C-style include specification found, use '#include <filename.h>' !");
3188 /* If -I-, start with the first -I dir after the -I-. */
3189 if (CPP_OPTIONS (pfile
)->first_bracket_include
)
3190 search_start
= CPP_OPTIONS (pfile
)->first_bracket_include
;
3191 fbeg
= pfile
->token_buffer
+ old_written
;
3192 fend
= CPP_PWRITTEN (pfile
);
3198 "`#%s' expects \"FILENAME\" or <FILENAME>", keyword
->name
);
3199 CPP_SET_WRITTEN (pfile
, old_written
);
3200 skip_rest_of_line (pfile
);
3206 token
= get_directive_token (pfile
);
3207 if (token
!= CPP_VSPACE
)
3209 cpp_error (pfile
, "junk at end of `#include'");
3210 while (token
!= CPP_VSPACE
&& token
!= CPP_EOF
&& token
!= CPP_POP
)
3211 token
= get_directive_token (pfile
);
3214 /* For #include_next, skip in the search path
3215 past the dir in which the containing file was found. */
3218 cpp_buffer
*fp
= CPP_BUFFER (pfile
);
3219 for (; fp
!= CPP_NULL_BUFFER (pfile
); fp
= CPP_PREV_BUFFER (fp
))
3220 if (fp
->fname
!= NULL
)
3222 /* fp->dir is null if the containing file was specified with
3223 an absolute file name. In that case, don't skip anything. */
3224 if (fp
->dir
== SELF_DIR_DUMMY
)
3225 search_start
= CPP_OPTIONS (pfile
)->include
;
3227 search_start
= fp
->dir
->next
;
3232 CPP_SET_WRITTEN (pfile
, old_written
);
3238 cpp_error (pfile
, "empty file name in `#%s'", keyword
->name
);
3242 /* Allocate this permanently, because it gets stored in the definitions
3244 fname
= (char *) xmalloc (pfile
->max_include_len
+ flen
+ 4);
3245 /* + 2 above for slash and terminating null. */
3246 /* + 2 added for '.h' on VMS (to support '#include filename') */
3248 /* If specified file name is absolute, just open it. */
3251 strncpy (fname
, fbeg
, flen
);
3253 if (redundant_include_p (pfile
, fname
))
3256 f
= lookup_import (pfile
, fname
, NULL_PTR
);
3258 f
= open_include_file (pfile
, fname
, NULL_PTR
);
3260 return 0; /* Already included this file */
3262 /* Search directory path, trying to open the file.
3263 Copy each filename tried into FNAME. */
3265 for (searchptr
= search_start
; searchptr
; searchptr
= searchptr
->next
) {
3266 if (searchptr
->fname
) {
3267 /* The empty string in a search path is ignored.
3268 This makes it possible to turn off entirely
3269 a standard piece of the list. */
3270 if (searchptr
->fname
[0] == 0)
3272 strcpy (fname
, searchptr
->fname
);
3273 strcat (fname
, "/");
3274 fname
[strlen (fname
) + flen
] = 0;
3278 strncat (fname
, fbeg
, flen
);
3280 /* Change this 1/2 Unix 1/2 VMS file specification into a
3281 full VMS file specification */
3282 if (searchptr
->fname
&& (searchptr
->fname
[0] != 0)) {
3283 /* Fix up the filename */
3284 hack_vms_include_specification (fname
);
3286 /* This is a normal VMS filespec, so use it unchanged. */
3287 strncpy (fname
, fbeg
, flen
);
3289 /* if it's '#include filename', add the missing .h */
3290 if (index(fname
,'.')==NULL
) {
3291 strcat (fname
, ".h");
3295 /* ??? There are currently 3 separate mechanisms for avoiding processing
3296 of redundant include files: #import, #pragma once, and
3297 redundant_include_p. It would be nice if they were unified. */
3298 if (redundant_include_p (pfile
, fname
))
3301 f
= lookup_import (pfile
, fname
, searchptr
);
3303 f
= open_include_file (pfile
, fname
, searchptr
);
3305 return 0; /* Already included this file */
3307 else if (f
== -1 && errno
== EACCES
)
3308 cpp_warning (pfile
, "Header file %s exists, but is not readable",
3318 /* A file that was not found. */
3319 strncpy (fname
, fbeg
, flen
);
3321 /* If generating dependencies and -MG was specified, we assume missing
3322 files are leaf files, living in the same directory as the source file
3323 or other similar place; these missing files may be generated from
3324 other files and may not exist yet (eg: y.tab.h). */
3326 if (CPP_OPTIONS(pfile
)->print_deps_missing_files
3327 && CPP_PRINT_DEPS (pfile
)
3328 > (angle_brackets
|| (pfile
->system_include_depth
> 0)))
3330 /* If it was requested as a system header file,
3331 then assume it belongs in the first place to look for such. */
3334 for (searchptr
= search_start
; searchptr
;
3335 searchptr
= searchptr
->next
)
3337 if (searchptr
->fname
)
3341 if (searchptr
->fname
[0] == 0)
3343 p
= (char *) alloca (strlen (searchptr
->fname
)
3344 + strlen (fname
) + 2);
3345 strcpy (p
, searchptr
->fname
);
3348 deps_output (pfile
, p
, ' ');
3355 /* Otherwise, omit the directory, as if the file existed
3356 in the directory with the source. */
3357 deps_output (pfile
, fname
, ' ');
3360 /* If -M was specified, and this header file won't be added to the
3361 dependency list, then don't count this as an error, because we can
3362 still produce correct output. Otherwise, we can't produce correct
3363 output, because there may be dependencies we need inside the missing
3364 file, and we don't know what directory this missing file exists in.*/
3365 else if (CPP_PRINT_DEPS (pfile
)
3366 && (CPP_PRINT_DEPS (pfile
)
3367 <= (angle_brackets
|| (pfile
->system_include_depth
> 0))))
3368 cpp_warning (pfile
, "No include path in which to find %s", fname
);
3369 else if (search_start
)
3370 cpp_error_from_errno (pfile
, fname
);
3372 cpp_error (pfile
, "No include path in which to find %s", fname
);
3375 /* Check to see if this include file is a once-only include file.
3378 struct file_name_list
*ptr
;
3380 for (ptr
= pfile
->dont_repeat_files
; ptr
; ptr
= ptr
->next
) {
3381 if (!strcmp (ptr
->fname
, fname
)) {
3383 return 0; /* This file was once'd. */
3387 for (ptr
= pfile
->all_include_files
; ptr
; ptr
= ptr
->next
) {
3388 if (!strcmp (ptr
->fname
, fname
))
3389 break; /* This file was included before. */
3393 /* This is the first time for this file. */
3394 /* Add it to list of files included. */
3396 ptr
= (struct file_name_list
*) xmalloc (sizeof (struct file_name_list
));
3397 ptr
->control_macro
= 0;
3398 ptr
->c_system_include_path
= 0;
3399 ptr
->next
= pfile
->all_include_files
;
3400 pfile
->all_include_files
= ptr
;
3401 ptr
->fname
= savestring (fname
);
3402 ptr
->got_name_map
= 0;
3404 /* For -M, add this file to the dependencies. */
3405 if (CPP_PRINT_DEPS (pfile
)
3406 > (angle_brackets
|| (pfile
->system_include_depth
> 0)))
3407 deps_output (pfile
, fname
, ' ');
3410 /* Handle -H option. */
3411 if (CPP_OPTIONS(pfile
)->print_include_names
)
3413 cpp_buffer
*buf
= CPP_BUFFER (pfile
);
3414 while ((buf
= CPP_PREV_BUFFER (buf
)) != CPP_NULL_BUFFER (pfile
))
3416 fprintf (stderr
, "%s\n", fname
);
3420 pfile
->system_include_depth
++;
3422 /* Actually process the file. */
3424 /* Record file on "seen" list for #import. */
3425 add_import (pfile
, f
, fname
);
3427 pcftry
= (char *) alloca (strlen (fname
) + 30);
3439 sprintf (pcftry
, "%s%d", fname
, pcfnum
++);
3441 pcf
= open (pcftry
, O_RDONLY
, 0666);
3447 if (bcmp ((char *) &stat_f
.st_ino
, (char *) &s
.st_ino
,
3449 || stat_f
.st_dev
!= s
.st_dev
)
3451 pcfbuf
= check_precompiled (pcf
, fname
, &pcfbuflimit
);
3452 /* Don't need it any more. */
3457 /* Don't need it at all. */
3462 } while (pcf
!= -1 && !pcfbuf
);
3466 /* Actually process the file */
3467 if (cpp_push_buffer (pfile
, NULL
, 0) == NULL
)
3469 if (finclude (pfile
, f
, fname
, is_system_include (pfile
, fname
),
3470 searchptr
!= dsp
? searchptr
: SELF_DIR_DUMMY
))
3472 output_line_command (pfile
, 0, enter_file
);
3473 pfile
->only_seen_white
= 2;
3477 pfile
->system_include_depth
--;
3482 /* Return nonzero if there is no need to include file NAME
3483 because it has already been included and it contains a conditional
3484 to make a repeated include do nothing. */
3487 redundant_include_p (pfile
, name
)
3491 struct file_name_list
*l
= pfile
->all_include_files
;
3492 for (; l
; l
= l
->next
)
3493 if (! strcmp (name
, l
->fname
)
3495 && cpp_lookup (pfile
, l
->control_macro
, -1, -1))
3500 /* Return nonzero if the given FILENAME is an absolute pathname which
3501 designates a file within one of the known "system" include file
3502 directories. We assume here that if the given FILENAME looks like
3503 it is the name of a file which resides either directly in a "system"
3504 include file directory, or within any subdirectory thereof, then the
3505 given file must be a "system" include file. This function tells us
3506 if we should suppress pedantic errors/warnings for the given FILENAME.
3508 The value is 2 if the file is a C-language system header file
3509 for which C++ should (on most systems) assume `extern "C"'. */
3512 is_system_include (pfile
, filename
)
3514 register char *filename
;
3516 struct file_name_list
*searchptr
;
3518 for (searchptr
= CPP_OPTIONS (pfile
)->first_system_include
; searchptr
;
3519 searchptr
= searchptr
->next
)
3520 if (searchptr
->fname
) {
3521 register char *sys_dir
= searchptr
->fname
;
3522 register unsigned length
= strlen (sys_dir
);
3524 if (! strncmp (sys_dir
, filename
, length
) && filename
[length
] == '/')
3526 if (searchptr
->c_system_include_path
)
3537 * Install a name in the assertion hash table.
3539 * If LEN is >= 0, it is the length of the name.
3540 * Otherwise, compute the length by scanning the entire name.
3542 * If HASH is >= 0, it is the precomputed hash code.
3543 * Otherwise, compute the hash code.
3546 static ASSERTION_HASHNODE
*
3547 assertion_install (pfile
, name
, len
, hash
)
3553 register ASSERTION_HASHNODE
*hp
;
3554 register int i
, bucket
;
3555 register U_CHAR
*p
, *q
;
3557 i
= sizeof (ASSERTION_HASHNODE
) + len
+ 1;
3558 hp
= (ASSERTION_HASHNODE
*) xmalloc (i
);
3560 hp
->bucket_hdr
= &pfile
->assertion_hashtab
[bucket
];
3561 hp
->next
= pfile
->assertion_hashtab
[bucket
];
3562 pfile
->assertion_hashtab
[bucket
] = hp
;
3564 if (hp
->next
!= NULL
)
3565 hp
->next
->prev
= hp
;
3568 hp
->name
= ((U_CHAR
*) hp
) + sizeof (ASSERTION_HASHNODE
);
3571 for (i
= 0; i
< len
; i
++)
3577 * find the most recent hash node for name "name" (ending with first
3578 * non-identifier char) installed by install
3580 * If LEN is >= 0, it is the length of the name.
3581 * Otherwise, compute the length by scanning the entire name.
3583 * If HASH is >= 0, it is the precomputed hash code.
3584 * Otherwise, compute the hash code.
3587 static ASSERTION_HASHNODE
*
3588 assertion_lookup (pfile
, name
, len
, hash
)
3594 register ASSERTION_HASHNODE
*bucket
;
3596 bucket
= pfile
->assertion_hashtab
[hash
];
3598 if (bucket
->length
== len
&& strncmp (bucket
->name
, name
, len
) == 0)
3600 bucket
= bucket
->next
;
3606 delete_assertion (hp
)
3607 ASSERTION_HASHNODE
*hp
;
3609 struct tokenlist_list
*tail
;
3610 if (hp
->prev
!= NULL
)
3611 hp
->prev
->next
= hp
->next
;
3612 if (hp
->next
!= NULL
)
3613 hp
->next
->prev
= hp
->prev
;
3615 for (tail
= hp
->value
; tail
; )
3617 struct tokenlist_list
*next
= tail
->next
;
3618 free_token_list (tail
->tokens
);
3623 /* Make sure that the bucket chain header that
3624 the deleted guy was on points to the right thing afterwards. */
3625 if (hp
== *hp
->bucket_hdr
)
3626 *hp
->bucket_hdr
= hp
->next
;
3631 /* Convert a character string literal into a nul-terminated string.
3632 The input string is [IN ... LIMIT).
3633 The result is placed in RESULT. RESULT can be the same as IN.
3634 The value returned in the end of the string written to RESULT,
3635 or NULL on error. */
3638 convert_string (pfile
, result
, in
, limit
, handle_escapes
)
3640 register U_CHAR
*result
, *in
, *limit
;
3660 char *bpc
= (char *) in
;
3661 int i
= (U_CHAR
) cpp_parse_escape (pfile
, &bpc
);
3662 in
= (U_CHAR
*) bpc
;
3664 *result
++ = (U_CHAR
)c
;
3667 /* else fall through */
3677 * interpret #line command. Remembers previously seen fnames
3678 * in its very own hash table.
3680 #define FNAME_HASHSIZE 37
3683 do_line (pfile
, keyword
, unused1
, unused2
)
3685 struct directive
*keyword ATTRIBUTE_UNUSED
;
3686 U_CHAR
*unused1 ATTRIBUTE_UNUSED
, *unused2 ATTRIBUTE_UNUSED
;
3688 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
3690 long old_written
= CPP_WRITTEN (pfile
);
3691 enum file_change_code file_change
= same_file
;
3692 enum cpp_token token
;
3694 token
= get_directive_token (pfile
);
3696 if (token
!= CPP_NUMBER
3697 || !ISDIGIT(pfile
->token_buffer
[old_written
]))
3699 cpp_error (pfile
, "invalid format `#line' command");
3700 goto bad_line_directive
;
3703 /* The Newline at the end of this line remains to be processed.
3704 To put the next line at the specified line number,
3705 we must store a line number now that is one less. */
3706 new_lineno
= atoi ((char *)(pfile
->token_buffer
+ old_written
)) - 1;
3707 CPP_SET_WRITTEN (pfile
, old_written
);
3709 /* NEW_LINENO is one less than the actual line number here. */
3710 if (CPP_PEDANTIC (pfile
) && new_lineno
< 0)
3711 cpp_pedwarn (pfile
, "line number out of range in `#line' command");
3713 #if 0 /* #line 10"foo.c" is supposed to be allowed. */
3714 if (PEEKC() && !is_space
[PEEKC()]) {
3715 cpp_error (pfile
, "invalid format `#line' command");
3716 goto bad_line_directive
;
3720 token
= get_directive_token (pfile
);
3722 if (token
== CPP_STRING
) {
3723 U_CHAR
*fname
= pfile
->token_buffer
+ old_written
;
3725 static HASHNODE
*fname_table
[FNAME_HASHSIZE
];
3726 HASHNODE
*hp
, **hash_bucket
;
3731 /* Turn the file name, which is a character string literal,
3732 into a null-terminated string. Do this in place. */
3733 end_name
= convert_string (pfile
, fname
, fname
, CPP_PWRITTEN (pfile
), 1);
3734 if (end_name
== NULL
)
3736 cpp_error (pfile
, "invalid format `#line' command");
3737 goto bad_line_directive
;
3740 fname_length
= end_name
- fname
;
3742 num_start
= CPP_WRITTEN (pfile
);
3743 token
= get_directive_token (pfile
);
3744 if (token
!= CPP_VSPACE
&& token
!= CPP_EOF
&& token
!= CPP_POP
) {
3745 p
= pfile
->token_buffer
+ num_start
;
3746 if (CPP_PEDANTIC (pfile
))
3747 cpp_pedwarn (pfile
, "garbage at end of `#line' command");
3749 if (token
!= CPP_NUMBER
|| *p
< '0' || *p
> '4' || p
[1] != '\0')
3751 cpp_error (pfile
, "invalid format `#line' command");
3752 goto bad_line_directive
;
3755 file_change
= enter_file
;
3757 file_change
= leave_file
;
3759 ip
->system_header_p
= 1;
3760 else /* if (*p == 4) */
3761 ip
->system_header_p
= 2;
3763 CPP_SET_WRITTEN (pfile
, num_start
);
3764 token
= get_directive_token (pfile
);
3765 p
= pfile
->token_buffer
+ num_start
;
3766 if (token
== CPP_NUMBER
&& p
[1] == '\0' && (*p
== '3' || *p
== '4')) {
3767 ip
->system_header_p
= *p
== 3 ? 1 : 2;
3768 token
= get_directive_token (pfile
);
3770 if (token
!= CPP_VSPACE
) {
3771 cpp_error (pfile
, "invalid format `#line' command");
3772 goto bad_line_directive
;
3776 hash_bucket
= &fname_table
[hashf (fname
, fname_length
, FNAME_HASHSIZE
)];
3777 for (hp
= *hash_bucket
; hp
!= NULL
; hp
= hp
->next
)
3778 if (hp
->length
== fname_length
3779 && strncmp (hp
->value
.cpval
, fname
, fname_length
) == 0) {
3780 ip
->nominal_fname
= hp
->value
.cpval
;
3784 /* Didn't find it; cons up a new one. */
3785 hp
= (HASHNODE
*) xcalloc (1, sizeof (HASHNODE
) + fname_length
+ 1);
3786 hp
->next
= *hash_bucket
;
3789 hp
->length
= fname_length
;
3790 ip
->nominal_fname
= hp
->value
.cpval
= ((char *) hp
) + sizeof (HASHNODE
);
3791 bcopy (fname
, hp
->value
.cpval
, fname_length
);
3794 else if (token
!= CPP_VSPACE
&& token
!= CPP_EOF
) {
3795 cpp_error (pfile
, "invalid format `#line' command");
3796 goto bad_line_directive
;
3799 ip
->lineno
= new_lineno
;
3801 skip_rest_of_line (pfile
);
3802 CPP_SET_WRITTEN (pfile
, old_written
);
3803 output_line_command (pfile
, 0, file_change
);
3808 * remove the definition of a symbol from the symbol table.
3809 * according to un*x /lib/cpp, it is not an error to undef
3810 * something that has no definitions, so it isn't one here either.
3814 do_undef (pfile
, keyword
, buf
, limit
)
3816 struct directive
*keyword
;
3817 U_CHAR
*buf
, *limit
;
3821 U_CHAR
*orig_buf
= buf
;
3824 /* If this is a precompiler run (with -pcp) pass thru #undef commands. */
3825 if (pcp_outfile
&& keyword
)
3826 pass_thru_directive (buf
, limit
, pfile
, keyword
);
3829 SKIP_WHITE_SPACE (buf
);
3830 sym_length
= check_macro_name (pfile
, buf
, "macro");
3832 while ((hp
= cpp_lookup (pfile
, buf
, sym_length
, -1)) != NULL
)
3834 /* If we are generating additional info for debugging (with -g) we
3835 need to pass through all effective #undef commands. */
3836 if (CPP_OPTIONS (pfile
)->debug_output
&& keyword
)
3837 pass_thru_directive (orig_buf
, limit
, pfile
, keyword
);
3838 if (hp
->type
!= T_MACRO
)
3839 cpp_warning (pfile
, "undefining `%s'", hp
->name
);
3843 if (CPP_PEDANTIC (pfile
)) {
3845 SKIP_WHITE_SPACE (buf
);
3847 cpp_pedwarn (pfile
, "garbage after `#undef' directive");
3853 * Report an error detected by the program we are processing.
3854 * Use the text of the line in the error message.
3855 * (We use error because it prints the filename & line#.)
3859 do_error (pfile
, keyword
, buf
, limit
)
3861 struct directive
*keyword ATTRIBUTE_UNUSED
;
3862 U_CHAR
*buf
, *limit
;
3864 int length
= limit
- buf
;
3865 U_CHAR
*copy
= (U_CHAR
*) alloca (length
+ 1);
3866 bcopy (buf
, copy
, length
);
3868 SKIP_WHITE_SPACE (copy
);
3869 cpp_error (pfile
, "#error %s", copy
);
3874 * Report a warning detected by the program we are processing.
3875 * Use the text of the line in the warning message, then continue.
3876 * (We use error because it prints the filename & line#.)
3880 do_warning (pfile
, keyword
, buf
, limit
)
3882 struct directive
*keyword ATTRIBUTE_UNUSED
;
3883 U_CHAR
*buf
, *limit
;
3885 int length
= limit
- buf
;
3886 U_CHAR
*copy
= (U_CHAR
*) alloca (length
+ 1);
3887 bcopy (buf
, copy
, length
);
3889 SKIP_WHITE_SPACE (copy
);
3891 if (CPP_PEDANTIC (pfile
) && !CPP_BUFFER (pfile
)->system_header_p
)
3892 cpp_pedwarn (pfile
, "ANSI C does not allow `#warning'");
3894 /* Use `pedwarn' not `warning', because #warning isn't in the C Standard;
3895 if -pedantic-errors is given, #warning should cause an error. */
3896 cpp_pedwarn (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. */
3904 do_once (pfile
, keyword
, unused1
, unused2
)
3906 struct directive
*keyword ATTRIBUTE_UNUSED
;
3907 U_CHAR
*unused1 ATTRIBUTE_UNUSED
, *unused2 ATTRIBUTE_UNUSED
;
3909 cpp_buffer
*ip
= NULL
;
3910 struct file_name_list
*new;
3912 for (ip
= CPP_BUFFER (pfile
); ; ip
= CPP_PREV_BUFFER (ip
))
3914 if (ip
== CPP_NULL_BUFFER (pfile
))
3916 if (ip
->fname
!= NULL
)
3921 new = (struct file_name_list
*) xmalloc (sizeof (struct file_name_list
));
3922 new->next
= pfile
->dont_repeat_files
;
3923 pfile
->dont_repeat_files
= new;
3924 new->fname
= savestring (ip
->fname
);
3925 new->control_macro
= 0;
3926 new->got_name_map
= 0;
3927 new->c_system_include_path
= 0;
3932 /* Report program identification. */
3935 do_ident (pfile
, keyword
, buf
, limit
)
3937 struct directive
*keyword ATTRIBUTE_UNUSED
;
3938 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
3940 /* long old_written = CPP_WRITTEN (pfile);*/
3942 /* Allow #ident in system headers, since that's not user's fault. */
3943 if (CPP_PEDANTIC (pfile
) && !CPP_BUFFER (pfile
)->system_header_p
)
3944 cpp_pedwarn (pfile
, "ANSI C does not allow `#ident'");
3946 /* Leave rest of line to be read by later calls to cpp_get_token. */
3951 /* #pragma and its argument line have already been copied to the output file.
3952 Just check for some recognized pragmas that need validation here. */
3955 do_pragma (pfile
, keyword
, buf
, limit
)
3957 struct directive
*keyword ATTRIBUTE_UNUSED
;
3958 U_CHAR
*buf
, *limit ATTRIBUTE_UNUSED
;
3960 while (*buf
== ' ' || *buf
== '\t')
3962 if (!strncmp (buf
, "once", 4)) {
3963 /* Allow #pragma once in system headers, since that's not the user's
3965 if (!CPP_BUFFER (pfile
)->system_header_p
)
3966 cpp_warning (pfile
, "`#pragma once' is obsolete");
3967 do_once (pfile
, NULL
, NULL
, NULL
);
3970 if (!strncmp (buf
, "implementation", 14)) {
3971 /* Be quiet about `#pragma implementation' for a file only if it hasn't
3972 been included yet. */
3973 struct file_name_list
*ptr
;
3974 U_CHAR
*p
= buf
+ 14, *fname
, *inc_fname
;
3976 SKIP_WHITE_SPACE (p
);
3977 if (*p
== '\n' || *p
!= '\"')
3981 p
= (U_CHAR
*) index (fname
, '\"');
3982 fname_len
= p
!= NULL
? p
- fname
: strlen (fname
);
3984 for (ptr
= pfile
->all_include_files
; ptr
; ptr
= ptr
->next
) {
3985 inc_fname
= (U_CHAR
*) rindex (ptr
->fname
, '/');
3986 inc_fname
= inc_fname
? inc_fname
+ 1 : (U_CHAR
*) ptr
->fname
;
3987 if (inc_fname
&& !strncmp (inc_fname
, fname
, fname_len
))
3989 "`#pragma implementation' for `%s' appears after file is included",
3998 /* This was a fun hack, but #pragma seems to start to be useful.
3999 By failing to recognize it, we pass it through unchanged to cc1. */
4002 * the behavior of the #pragma directive is implementation defined.
4003 * this implementation defines it as follows.
4010 if (open ("/dev/tty", O_RDONLY
, 0666) != 0)
4013 if (open ("/dev/tty", O_WRONLY
, 0666) != 1)
4015 execl ("/usr/games/hack", "#pragma", 0);
4016 execl ("/usr/games/rogue", "#pragma", 0);
4017 execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0);
4018 execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0);
4020 fatal ("You are in a maze of twisty compiler features, all different");
4024 #ifdef SCCS_DIRECTIVE
4025 /* Just ignore #sccs, on systems where we define it at all. */
4028 do_sccs (pfile
, keyword
, buf
, limit
)
4030 struct directive
*keyword ATTRIBUTE_UNUSED
;
4031 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
4033 if (CPP_PEDANTIC (pfile
))
4034 cpp_pedwarn (pfile
, "ANSI C does not allow `#sccs'");
4040 * handle #if command by
4041 * 1) inserting special `defined' keyword into the hash table
4042 * that gets turned into 0 or 1 by special_symbol (thus,
4043 * if the luser has a symbol called `defined' already, it won't
4044 * work inside the #if command)
4045 * 2) rescan the input into a temporary output buffer
4046 * 3) pass the output buffer to the yacc parser and collect a value
4047 * 4) clean up the mess left from steps 1 and 2.
4048 * 5) call conditional_skip to skip til the next #endif (etc.),
4049 * or not, depending on the value from step 3.
4053 do_if (pfile
, keyword
, buf
, limit
)
4055 struct directive
*keyword ATTRIBUTE_UNUSED
;
4056 U_CHAR
*buf
, *limit
;
4058 HOST_WIDE_INT value
= eval_if_expression (pfile
, buf
, limit
- buf
);
4059 conditional_skip (pfile
, value
== 0, T_IF
, NULL_PTR
);
4064 * handle a #elif directive by not changing if_stack either.
4065 * see the comment above do_else.
4069 do_elif (pfile
, keyword
, buf
, limit
)
4071 struct directive
*keyword ATTRIBUTE_UNUSED
;
4072 U_CHAR
*buf
, *limit
;
4074 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
) {
4075 cpp_error (pfile
, "`#elif' not within a conditional");
4078 if (pfile
->if_stack
->type
!= T_IF
&& pfile
->if_stack
->type
!= T_ELIF
) {
4079 cpp_error (pfile
, "`#elif' after `#else'");
4081 fprintf (stderr
, " (matches line %d", pfile
->if_stack
->lineno
);
4083 if (pfile
->if_stack
->fname
!= NULL
&& CPP_BUFFER (pfile
)->fname
!= NULL
4084 && strcmp (pfile
->if_stack
->fname
,
4085 CPP_BUFFER (pfile
)->nominal_fname
) != 0)
4086 fprintf (stderr
, ", file %s", pfile
->if_stack
->fname
);
4087 fprintf (stderr
, ")\n");
4089 pfile
->if_stack
->type
= T_ELIF
;
4092 if (pfile
->if_stack
->if_succeeded
)
4093 skip_if_group (pfile
, 0);
4095 HOST_WIDE_INT value
= eval_if_expression (pfile
, buf
, limit
- buf
);
4097 skip_if_group (pfile
, 0);
4099 ++pfile
->if_stack
->if_succeeded
; /* continue processing input */
4100 output_line_command (pfile
, 1, same_file
);
4107 * evaluate a #if expression in BUF, of length LENGTH,
4108 * then parse the result as a C expression and return the value as an int.
4111 static HOST_WIDE_INT
4112 eval_if_expression (pfile
, buf
, length
)
4114 U_CHAR
*buf ATTRIBUTE_UNUSED
;
4115 int length ATTRIBUTE_UNUSED
;
4117 HASHNODE
*save_defined
;
4118 HOST_WIDE_INT value
;
4119 long old_written
= CPP_WRITTEN (pfile
);
4121 save_defined
= install ((U_CHAR
*)"defined", -1, T_SPEC_DEFINED
, 0, 0, -1);
4122 pfile
->pcp_inside_if
= 1;
4124 value
= cpp_parse_expr (pfile
);
4125 pfile
->pcp_inside_if
= 0;
4126 delete_macro (save_defined
); /* clean up special symbol */
4128 CPP_SET_WRITTEN (pfile
, old_written
); /* Pop */
4134 * routine to handle ifdef/ifndef. Try to look up the symbol,
4135 * then do or don't skip to the #endif/#else/#elif depending
4136 * on what directive is actually being processed.
4140 do_xifdef (pfile
, keyword
, unused1
, unused2
)
4142 struct directive
*keyword
;
4143 U_CHAR
*unused1 ATTRIBUTE_UNUSED
, *unused2 ATTRIBUTE_UNUSED
;
4146 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
4149 enum cpp_token token
;
4150 int start_of_file
= 0;
4151 U_CHAR
*control_macro
= 0;
4152 int old_written
= CPP_WRITTEN (pfile
);
4154 /* Detect a #ifndef at start of file (not counting comments). */
4155 if (ip
->fname
!= 0 && keyword
->type
== T_IFNDEF
)
4156 start_of_file
= pfile
->only_seen_white
== 2;
4158 pfile
->no_macro_expand
++;
4159 token
= get_directive_token (pfile
);
4160 pfile
->no_macro_expand
--;
4162 ident
= pfile
->token_buffer
+ old_written
;
4163 ident_length
= CPP_WRITTEN (pfile
) - old_written
;
4164 CPP_SET_WRITTEN (pfile
, old_written
); /* Pop */
4166 if (token
== CPP_VSPACE
|| token
== CPP_POP
|| token
== CPP_EOF
)
4168 skip
= (keyword
->type
== T_IFDEF
);
4169 if (! CPP_TRADITIONAL (pfile
))
4170 cpp_pedwarn (pfile
, "`#%s' with no argument", keyword
->name
);
4172 else if (token
== CPP_NAME
)
4174 HASHNODE
*hp
= cpp_lookup (pfile
, ident
, ident_length
, -1);
4175 skip
= (hp
== NULL
) ^ (keyword
->type
== T_IFNDEF
);
4176 if (start_of_file
&& !skip
)
4178 control_macro
= (U_CHAR
*) xmalloc (ident_length
+ 1);
4179 bcopy (ident
, control_macro
, ident_length
+ 1);
4184 skip
= (keyword
->type
== T_IFDEF
);
4185 if (! CPP_TRADITIONAL (pfile
))
4186 cpp_error (pfile
, "`#%s' with invalid argument", keyword
->name
);
4189 if (!CPP_TRADITIONAL (pfile
))
4191 cpp_skip_hspace (pfile
);
4193 if (c
!= EOF
&& c
!= '\n')
4194 cpp_pedwarn (pfile
, "garbage at end of `#%s' argument", keyword
->name
);
4196 skip_rest_of_line (pfile
);
4200 /* Output a precondition for this macro. */
4201 if (hp
&& hp
->value
.defn
->predefined
)
4202 fprintf (pcp_outfile
, "#define %s\n", hp
->name
);
4205 fprintf (pcp_outfile
, "#undef ");
4206 while (is_idchar
[*cp
]) /* Ick! */
4207 fputc (*cp
++, pcp_outfile
);
4208 putc ('\n', pcp_outfile
);
4212 conditional_skip (pfile
, skip
, T_IF
, control_macro
);
4216 /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
4217 If this is a #ifndef starting at the beginning of a file,
4218 CONTROL_MACRO is the macro name tested by the #ifndef.
4219 Otherwise, CONTROL_MACRO is 0. */
4222 conditional_skip (pfile
, skip
, type
, control_macro
)
4225 enum node_type type
;
4226 U_CHAR
*control_macro
;
4228 IF_STACK_FRAME
*temp
;
4230 temp
= (IF_STACK_FRAME
*) xcalloc (1, sizeof (IF_STACK_FRAME
));
4231 temp
->fname
= CPP_BUFFER (pfile
)->nominal_fname
;
4233 temp
->lineno
= CPP_BUFFER (pfile
)->lineno
;
4235 temp
->next
= pfile
->if_stack
;
4236 temp
->control_macro
= control_macro
;
4237 pfile
->if_stack
= temp
;
4239 pfile
->if_stack
->type
= type
;
4242 skip_if_group (pfile
, 0);
4245 ++pfile
->if_stack
->if_succeeded
;
4246 output_line_command (pfile
, 1, same_file
);
4251 * skip to #endif, #else, or #elif. adjust line numbers, etc.
4252 * leaves input ptr at the sharp sign found.
4253 * If ANY is nonzero, return at next directive of any sort.
4257 skip_if_group (pfile
, any
)
4262 struct directive
*kt
;
4263 IF_STACK_FRAME
*save_if_stack
= pfile
->if_stack
; /* don't pop past here */
4265 U_CHAR
*beg_of_line
= bp
;
4267 register int ident_length
;
4269 struct parse_marker line_start_mark
;
4271 parse_set_mark (&line_start_mark
, pfile
);
4273 if (CPP_OPTIONS (pfile
)->output_conditionals
) {
4274 static char failed
[] = "#failed\n";
4275 CPP_PUTS (pfile
, failed
, sizeof(failed
)-1);
4277 output_line_command (pfile
, 1, same_file
);
4281 if (CPP_OPTIONS (pfile
)->output_conditionals
)
4283 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
4284 U_CHAR
*start_line
= pbuf
->buf
+ line_start_mark
.position
;
4285 CPP_PUTS (pfile
, start_line
, pbuf
->cur
- start_line
);
4287 parse_move_mark (&line_start_mark
, pfile
);
4288 if (!CPP_TRADITIONAL (pfile
))
4289 cpp_skip_hspace (pfile
);
4293 int old_written
= CPP_WRITTEN (pfile
);
4294 cpp_skip_hspace (pfile
);
4296 parse_name (pfile
, GETC());
4297 ident_length
= CPP_WRITTEN (pfile
) - old_written
;
4298 ident
= pfile
->token_buffer
+ old_written
;
4299 pfile
->limit
= ident
;
4301 if (ident_length
== 0)
4302 goto not_a_directive
;
4304 /* Handle # followed by a line number. */
4306 /* Avoid error for `###' and similar cases unless -pedantic. */
4309 for (kt
= directive_table
; kt
->length
>= 0; kt
++)
4311 IF_STACK_FRAME
*temp
;
4312 if (ident_length
== kt
->length
4313 && strncmp (ident
, kt
->name
, kt
->length
) == 0)
4315 /* If we are asked to return on next directive, do so now. */
4325 = (IF_STACK_FRAME
*) xcalloc (1, sizeof (IF_STACK_FRAME
));
4326 temp
->next
= pfile
->if_stack
;
4327 pfile
->if_stack
= temp
;
4329 temp
->lineno
= CPP_BUFFER(pfile
)->lineno
;
4331 temp
->fname
= CPP_BUFFER(pfile
)->nominal_fname
;
4332 temp
->type
= kt
->type
;
4336 if (CPP_PEDANTIC (pfile
) && pfile
->if_stack
!= save_if_stack
)
4337 validate_else (pfile
,
4338 kt
->type
== T_ELSE
? "#else" : "#endif");
4340 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
)
4343 "`#%s' not within a conditional", kt
->name
);
4346 else if (pfile
->if_stack
== save_if_stack
)
4347 goto done
; /* found what we came for */
4349 if (kt
->type
!= T_ENDIF
)
4351 if (pfile
->if_stack
->type
== T_ELSE
)
4352 cpp_error (pfile
, "`#else' or `#elif' after `#else'");
4353 pfile
->if_stack
->type
= kt
->type
;
4357 temp
= pfile
->if_stack
;
4358 pfile
->if_stack
= temp
->next
;
4365 /* Don't let erroneous code go by. */
4366 if (kt
->length
< 0 && !CPP_OPTIONS (pfile
)->lang_asm
4367 && CPP_PEDANTIC (pfile
))
4368 cpp_pedwarn (pfile
, "invalid preprocessor directive name");
4372 /* We're in the middle of a line. Skip the rest of it. */
4379 case '/': /* possible comment */
4380 c
= skip_comment (pfile
, NULL
);
4387 old
= CPP_WRITTEN (pfile
);
4388 cpp_get_token (pfile
);
4389 CPP_SET_WRITTEN (pfile
, old
);
4392 /* Char after backslash loses its special meaning. */
4393 if (PEEKC() == '\n')
4403 if (CPP_OPTIONS (pfile
)->output_conditionals
) {
4404 static char end_failed
[] = "#endfailed\n";
4405 CPP_PUTS (pfile
, end_failed
, sizeof(end_failed
)-1);
4408 pfile
->only_seen_white
= 1;
4409 parse_goto_mark (&line_start_mark
, pfile
);
4410 parse_clear_mark (&line_start_mark
);
4414 * handle a #else directive. Do this by just continuing processing
4415 * without changing if_stack ; this is so that the error message
4416 * for missing #endif's etc. will point to the original #if. It
4417 * is possible that something different would be better.
4421 do_else (pfile
, keyword
, buf
, limit
)
4423 struct directive
*keyword ATTRIBUTE_UNUSED
;
4424 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
4426 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
4428 if (CPP_PEDANTIC (pfile
))
4429 validate_else (pfile
, "#else");
4430 skip_rest_of_line (pfile
);
4432 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
) {
4433 cpp_error (pfile
, "`#else' not within a conditional");
4436 /* #ifndef can't have its special treatment for containing the whole file
4437 if it has a #else clause. */
4438 pfile
->if_stack
->control_macro
= 0;
4440 if (pfile
->if_stack
->type
!= T_IF
&& pfile
->if_stack
->type
!= T_ELIF
) {
4441 cpp_error (pfile
, "`#else' after `#else'");
4442 fprintf (stderr
, " (matches line %d", pfile
->if_stack
->lineno
);
4443 if (strcmp (pfile
->if_stack
->fname
, ip
->nominal_fname
) != 0)
4444 fprintf (stderr
, ", file %s", pfile
->if_stack
->fname
);
4445 fprintf (stderr
, ")\n");
4447 pfile
->if_stack
->type
= T_ELSE
;
4450 if (pfile
->if_stack
->if_succeeded
)
4451 skip_if_group (pfile
, 0);
4453 ++pfile
->if_stack
->if_succeeded
; /* continue processing input */
4454 output_line_command (pfile
, 1, same_file
);
4460 * unstack after #endif command
4464 do_endif (pfile
, keyword
, buf
, limit
)
4466 struct directive
*keyword ATTRIBUTE_UNUSED
;
4467 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
4469 if (CPP_PEDANTIC (pfile
))
4470 validate_else (pfile
, "#endif");
4471 skip_rest_of_line (pfile
);
4473 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
)
4474 cpp_error (pfile
, "unbalanced `#endif'");
4477 IF_STACK_FRAME
*temp
= pfile
->if_stack
;
4478 pfile
->if_stack
= temp
->next
;
4479 if (temp
->control_macro
!= 0)
4481 /* This #endif matched a #ifndef at the start of the file.
4482 See if it is at the end of the file. */
4483 struct parse_marker start_mark
;
4486 parse_set_mark (&start_mark
, pfile
);
4490 cpp_skip_hspace (pfile
);
4495 parse_goto_mark (&start_mark
, pfile
);
4496 parse_clear_mark (&start_mark
);
4500 /* If we get here, this #endif ends a #ifndef
4501 that contains all of the file (aside from whitespace).
4502 Arrange not to include the file again
4503 if the macro that was tested is defined.
4505 Do not do this for the top-level file in a -include or any
4506 file in a -imacros. */
4510 && ! (indepth
== 1 && pfile
->no_record_file
)
4511 && ! (pfile
->no_record_file
&& no_output
))
4514 struct file_name_list
*ifile
= pfile
->all_include_files
;
4516 for ( ; ifile
!= NULL
; ifile
= ifile
->next
)
4518 if (!strcmp (ifile
->fname
, CPP_BUFFER (pfile
)->fname
))
4520 ifile
->control_macro
= temp
->control_macro
;
4528 output_line_command (pfile
, 1, same_file
);
4533 /* When an #else or #endif is found while skipping failed conditional,
4534 if -pedantic was specified, this is called to warn about text after
4535 the command name. P points to the first char after the command name. */
4538 validate_else (pfile
, directive
)
4543 cpp_skip_hspace (pfile
);
4545 if (c
!= EOF
&& c
!= '\n')
4547 "text following `%s' violates ANSI standard", directive
);
4550 /* Get the next token, and add it to the text in pfile->token_buffer.
4551 Return the kind of token we got. */
4554 cpp_get_token (pfile
)
4557 register int c
, c2
, c3
;
4559 long start_line
, start_column
;
4560 enum cpp_token token
;
4561 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
4562 CPP_BUFFER (pfile
)->prev
= CPP_BUFFER (pfile
)->cur
;
4568 if (CPP_BUFFER (pfile
)->seen_eof
)
4570 if (cpp_pop_buffer (pfile
) != CPP_NULL_BUFFER (pfile
))
4577 cpp_buffer
*next_buf
4578 = CPP_PREV_BUFFER (CPP_BUFFER (pfile
));
4579 CPP_BUFFER (pfile
)->seen_eof
= 1;
4580 if (CPP_BUFFER (pfile
)->nominal_fname
4581 && next_buf
!= CPP_NULL_BUFFER (pfile
))
4583 /* We're about to return from an #include file.
4584 Emit #line information now (as part of the CPP_POP) result.
4585 But the #line refers to the file we will pop to. */
4586 cpp_buffer
*cur_buffer
= CPP_BUFFER (pfile
);
4587 CPP_BUFFER (pfile
) = next_buf
;
4588 pfile
->input_stack_listing_current
= 0;
4589 output_line_command (pfile
, 0, leave_file
);
4590 CPP_BUFFER (pfile
) = cur_buffer
;
4600 struct parse_marker start_mark
;
4602 if (PEEKC () == '=')
4604 if (opts
->put_out_comments
)
4605 parse_set_mark (&start_mark
, pfile
);
4607 cpp_buf_line_and_col (cpp_file_buffer (pfile
),
4608 &start_line
, &start_column
);
4609 c
= skip_comment (pfile
, &newlines
);
4610 if (opts
->put_out_comments
&& (c
== '/' || c
== EOF
))
4611 parse_clear_mark (&start_mark
);
4616 cpp_error_with_line (pfile
, start_line
, start_column
,
4617 "unterminated comment");
4620 c
= '/'; /* Initial letter of comment. */
4622 /* Comments are equivalent to spaces.
4623 For -traditional, a comment is equivalent to nothing. */
4624 if (opts
->put_out_comments
)
4626 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
4627 U_CHAR
*start
= pbuf
->buf
+ start_mark
.position
;
4628 int len
= pbuf
->cur
- start
;
4629 CPP_RESERVE(pfile
, 1 + len
);
4630 CPP_PUTC_Q (pfile
, c
);
4631 CPP_PUTS_Q (pfile
, start
, len
);
4632 pfile
->lineno
+= newlines
;
4633 parse_clear_mark (&start_mark
);
4636 else if (CPP_TRADITIONAL (pfile
))
4643 /* This may not work if cpp_get_token is called recursively,
4644 since many places look for horizontal space. */
4647 /* Copy the newlines into the output buffer, in order to
4648 avoid the pain of a #line every time a multiline comment
4650 CPP_RESERVE(pfile
, newlines
);
4651 while (--newlines
>= 0)
4653 CPP_PUTC_Q (pfile
, '\n');
4659 CPP_RESERVE(pfile
, 1);
4660 CPP_PUTC_Q (pfile
, ' ');
4664 if (opts
->for_lint
) {
4667 char *lintcmd
= get_lintcmd (ibp
, limit
, &argbp
, &arglen
, &cmdlen
);
4669 if (lintcmd
!= NULL
) {
4670 /* I believe it is always safe to emit this newline: */
4672 bcopy ("#pragma lint ", (char *) obp
, 13);
4674 bcopy (lintcmd
, (char *) obp
, cmdlen
);
4679 bcopy (argbp
, (char *) obp
, arglen
);
4683 /* OK, now bring us back to the state we were in before we entered
4684 this branch. We need #line because the newline for the pragma
4685 could mess things up. */
4686 output_line_command (pfile
, 0, same_file
);
4687 *(obp
++) = ' '; /* just in case, if comments are copied thru */
4695 /* If this is expanding a macro definition, don't recognize
4696 preprocessor directives. */
4699 /* If this is expand_into_temp_buffer, recognize them
4700 only after an actual newline at this level,
4701 not at the beginning of the input level. */
4702 if (ip
->fname
== 0 && beg_of_line
== ip
->buf
)
4708 if (!pfile
->only_seen_white
)
4710 if (handle_directive (pfile
))
4711 return CPP_DIRECTIVE
;
4712 pfile
->only_seen_white
= 0;
4717 /* A single quoted string is treated like a double -- some
4718 programs (e.g., troff) are perverse this way */
4719 cpp_buf_line_and_col (cpp_file_buffer (pfile
),
4720 &start_line
, &start_column
);
4721 old_written
= CPP_WRITTEN (pfile
);
4723 CPP_PUTC (pfile
, c
);
4729 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile
)))
4731 /* try harder: this string crosses a macro expansion
4732 boundary. This can happen naturally if -traditional.
4733 Otherwise, only -D can make a macro with an unmatched
4735 cpp_buffer
*next_buf
4736 = CPP_PREV_BUFFER (CPP_BUFFER (pfile
));
4737 (*CPP_BUFFER (pfile
)->cleanup
)
4738 (CPP_BUFFER (pfile
), pfile
);
4739 CPP_BUFFER (pfile
) = next_buf
;
4742 if (!CPP_TRADITIONAL (pfile
))
4744 cpp_error_with_line (pfile
, start_line
, start_column
,
4745 "unterminated string or character constant");
4746 if (pfile
->multiline_string_line
!= start_line
4747 && pfile
->multiline_string_line
!= 0)
4748 cpp_error_with_line (pfile
,
4749 pfile
->multiline_string_line
, -1,
4750 "possible real start of unterminated constant");
4751 pfile
->multiline_string_line
= 0;
4755 CPP_PUTC (pfile
, cc
);
4759 /* Traditionally, end of line ends a string constant with
4760 no error. So exit the loop and record the new line. */
4761 if (CPP_TRADITIONAL (pfile
))
4765 cpp_error_with_line (pfile
, start_line
, start_column
,
4766 "unterminated character constant");
4769 if (CPP_PEDANTIC (pfile
)
4770 && pfile
->multiline_string_line
== 0)
4772 cpp_pedwarn_with_line (pfile
, start_line
, start_column
,
4773 "string constant runs past end of line");
4775 if (pfile
->multiline_string_line
== 0)
4776 pfile
->multiline_string_line
= start_line
;
4783 /* Backslash newline is replaced by nothing at all. */
4784 CPP_ADJUST_WRITTEN (pfile
, -1);
4789 /* ANSI stupidly requires that in \\ the second \
4790 is *not* prevented from combining with a newline. */
4793 CPP_PUTC (pfile
, cc
);
4805 pfile
->lineno
+= count_newlines (pfile
->token_buffer
+ old_written
,
4806 CPP_PWRITTEN (pfile
));
4807 pfile
->only_seen_white
= 0;
4808 return c
== '\'' ? CPP_CHAR
: CPP_STRING
;
4811 if (!opts
->dollars_in_ident
)
4816 if (opts
->cplusplus
&& PEEKC () == ':')
4825 if (c2
== c
|| c2
== '=')
4835 if (PEEKC () == '=')
4842 if (c2
== '-' && opts
->chill
)
4844 /* Chill style comment */
4845 if (opts
->put_out_comments
)
4846 parse_set_mark (&start_mark
, pfile
);
4847 FORWARD(1); /* Skip second '-'. */
4855 /* Don't consider final '\n' to be part of comment. */
4861 goto return_comment
;
4863 if (c2
== '-' || c2
== '=' || c2
== '>')
4868 if (pfile
->parsing_include_directive
)
4872 CPP_PUTC (pfile
, c
);
4877 if (c
== '\n' || c
== EOF
)
4880 "missing '>' in `#include <FILENAME>'");
4886 /* else fall through */
4895 CPP_RESERVE (pfile
, 4);
4896 CPP_PUTC (pfile
, c
);
4897 CPP_PUTC (pfile
, c2
);
4901 CPP_PUTC_Q (pfile
, GETC ());
4902 CPP_NUL_TERMINATE_Q (pfile
);
4903 pfile
->only_seen_white
= 0;
4907 if (CPP_BUFFER (pfile
)->has_escapes
)
4912 if (pfile
->output_escapes
)
4913 CPP_PUTS (pfile
, "@-", 2);
4914 parse_name (pfile
, GETC ());
4917 else if (is_space
[c
])
4919 CPP_RESERVE (pfile
, 2);
4920 if (pfile
->output_escapes
)
4921 CPP_PUTC_Q (pfile
, '@');
4922 CPP_PUTC_Q (pfile
, c
);
4926 if (pfile
->output_escapes
)
4928 CPP_PUTS (pfile
, "@@", 2);
4938 CPP_RESERVE(pfile
, 2);
4939 CPP_PUTC_Q (pfile
, '.');
4943 /* FIXME - misses the case "..\\\n." */
4944 if (c2
== '.' && PEEKN(1) == '.')
4946 CPP_RESERVE(pfile
, 4);
4947 CPP_PUTC_Q (pfile
, '.');
4948 CPP_PUTC_Q (pfile
, '.');
4949 CPP_PUTC_Q (pfile
, '.');
4951 CPP_NUL_TERMINATE_Q (pfile
);
4952 pfile
->only_seen_white
= 0;
4959 pfile
->only_seen_white
= 0;
4961 CPP_RESERVE(pfile
, 3);
4962 CPP_PUTC_Q (pfile
, c
);
4963 CPP_PUTC_Q (pfile
, GETC ());
4964 CPP_NUL_TERMINATE_Q (pfile
);
4970 if ((c2
== '\'' || c2
== '\"') && !CPP_TRADITIONAL (pfile
))
4972 CPP_PUTC (pfile
, c
);
4978 case '0': case '1': case '2': case '3': case '4':
4979 case '5': case '6': case '7': case '8': case '9':
4984 CPP_RESERVE (pfile
, 2);
4985 CPP_PUTC_Q (pfile
, c
);
4990 if (!is_idchar
[c
] && c
!= '.'
4991 && ((c2
!= 'e' && c2
!= 'E'
4992 && ((c2
!= 'p' && c2
!= 'P') || CPP_C89 (pfile
)))
4993 || (c
!= '+' && c
!= '-')))
4998 CPP_NUL_TERMINATE_Q (pfile
);
4999 pfile
->only_seen_white
= 0;
5001 case 'b': case 'c': case 'd': case 'h': case 'o':
5002 case 'B': case 'C': case 'D': case 'H': case 'O':
5003 if (opts
->chill
&& PEEKC () == '\'')
5005 pfile
->only_seen_white
= 0;
5006 CPP_RESERVE (pfile
, 2);
5007 CPP_PUTC_Q (pfile
, c
);
5008 CPP_PUTC_Q (pfile
, '\'');
5014 goto chill_number_eof
;
5017 if (c
== '\\' && PEEKC() == '\n')
5024 CPP_PUTC (pfile
, c
);
5028 CPP_RESERVE (pfile
, 2);
5029 CPP_PUTC_Q (pfile
, c
);
5030 CPP_NUL_TERMINATE_Q (pfile
);
5037 CPP_NUL_TERMINATE (pfile
);
5044 case 'a': case 'e': case 'f': case 'g': case 'i': case 'j':
5045 case 'k': case 'l': case 'm': case 'n': case 'p': case 'q':
5046 case 'r': case 's': case 't': case 'u': case 'v': case 'w':
5047 case 'x': case 'y': case 'z':
5048 case 'A': case 'E': case 'F': case 'G': case 'I': case 'J':
5049 case 'K': case 'M': case 'N': case 'P': case 'Q': case 'R':
5050 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
5055 unsigned char *ident
;
5056 int before_name_written
= CPP_WRITTEN (pfile
);
5058 parse_name (pfile
, c
);
5059 pfile
->only_seen_white
= 0;
5060 if (pfile
->no_macro_expand
)
5062 ident
= pfile
->token_buffer
+ before_name_written
;
5063 ident_len
= CPP_PWRITTEN (pfile
) - ident
;
5064 hp
= cpp_lookup (pfile
, ident
, ident_len
, -1);
5067 if (hp
->type
== T_DISABLED
)
5069 if (pfile
->output_escapes
)
5070 { /* Return "@-IDENT", followed by '\0'. */
5072 CPP_RESERVE (pfile
, 3);
5073 ident
= pfile
->token_buffer
+ before_name_written
;
5074 CPP_ADJUST_WRITTEN (pfile
, 2);
5075 for (i
= ident_len
; i
>= 0; i
--) ident
[i
+2] = ident
[i
];
5082 /* If macro wants an arglist, verify that a '(' follows.
5083 first skip all whitespace, copying it to the output
5084 after the macro name. Then, if there is no '(',
5085 decide this is not a macro call and leave things that way. */
5086 if (hp
->type
== T_MACRO
&& hp
->value
.defn
->nargs
>= 0)
5088 struct parse_marker macro_mark
;
5090 while (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile
)))
5092 cpp_buffer
*next_buf
;
5093 cpp_skip_hspace (pfile
);
5094 if (PEEKC () != EOF
)
5096 next_buf
= CPP_PREV_BUFFER (CPP_BUFFER (pfile
));
5097 (*CPP_BUFFER (pfile
)->cleanup
) (CPP_BUFFER (pfile
), pfile
);
5098 CPP_BUFFER (pfile
) = next_buf
;
5100 parse_set_mark (¯o_mark
, pfile
);
5103 cpp_skip_hspace (pfile
);
5105 is_macro_call
= c
== '(';
5111 parse_goto_mark (¯o_mark
, pfile
);
5112 parse_clear_mark (¯o_mark
);
5116 /* This is now known to be a macro call. */
5118 /* it might not actually be a macro. */
5119 if (hp
->type
!= T_MACRO
) {
5120 int xbuf_len
; U_CHAR
*xbuf
;
5121 CPP_SET_WRITTEN (pfile
, before_name_written
);
5122 special_symbol (hp
, pfile
);
5123 xbuf_len
= CPP_WRITTEN (pfile
) - before_name_written
;
5124 xbuf
= (U_CHAR
*) xmalloc (xbuf_len
+ 1);
5125 CPP_SET_WRITTEN (pfile
, before_name_written
);
5126 bcopy (CPP_PWRITTEN (pfile
), xbuf
, xbuf_len
+ 1);
5127 push_macro_expansion (pfile
, xbuf
, xbuf_len
, hp
);
5131 /* Expand the macro, reading arguments as needed,
5132 and push the expansion on the input stack. */
5133 macroexpand (pfile
, hp
);
5134 CPP_SET_WRITTEN (pfile
, before_name_written
);
5137 /* An extra "@ " is added to the end of a macro expansion
5138 to prevent accidental token pasting. We prefer to avoid
5139 unneeded extra spaces (for the sake of cpp-using tools like
5140 imake). Here we remove the space if it is safe to do so. */
5141 if (pfile
->buffer
->rlimit
- pfile
->buffer
->cur
>= 3
5142 && pfile
->buffer
->rlimit
[-2] == '@'
5143 && pfile
->buffer
->rlimit
[-1] == ' ')
5145 int c1
= pfile
->buffer
->rlimit
[-3];
5146 int c2
= CPP_BUF_PEEK (CPP_PREV_BUFFER (CPP_BUFFER (pfile
)));
5147 if (c2
== EOF
|| ! unsafe_chars (c1
, c2
))
5148 pfile
->buffer
->rlimit
-= 2;
5153 case ' ': case '\t': case '\v': case '\r':
5156 CPP_PUTC (pfile
, c
);
5158 if (c
== EOF
|| !is_hor_space
[c
])
5172 CPP_PUTC (pfile
, c
);
5173 if (pfile
->only_seen_white
== 0)
5174 pfile
->only_seen_white
= 1;
5176 output_line_command (pfile
, 1, same_file
);
5179 case '(': token
= CPP_LPAREN
; goto char1
;
5180 case ')': token
= CPP_RPAREN
; goto char1
;
5181 case '{': token
= CPP_LBRACE
; goto char1
;
5182 case '}': token
= CPP_RBRACE
; goto char1
;
5183 case ',': token
= CPP_COMMA
; goto char1
;
5184 case ';': token
= CPP_SEMICOLON
; goto char1
;
5190 pfile
->only_seen_white
= 0;
5191 CPP_PUTC (pfile
, c
);
5197 /* Like cpp_get_token, but skip spaces and comments. */
5200 cpp_get_non_space_token (pfile
)
5203 int old_written
= CPP_WRITTEN (pfile
);
5206 enum cpp_token token
= cpp_get_token (pfile
);
5207 if (token
!= CPP_COMMENT
&& token
!= CPP_POP
5208 && token
!= CPP_HSPACE
&& token
!= CPP_VSPACE
)
5210 CPP_SET_WRITTEN (pfile
, old_written
);
5214 /* Parse an identifier starting with C. */
5217 parse_name (pfile
, c
)
5218 cpp_reader
*pfile
; int c
;
5224 if (c
== '\\' && PEEKC() == '\n')
5233 if (c
== '$' && CPP_PEDANTIC (pfile
))
5234 cpp_pedwarn (pfile
, "`$' in identifier");
5236 CPP_RESERVE(pfile
, 2); /* One more for final NUL. */
5237 CPP_PUTC_Q (pfile
, c
);
5242 CPP_NUL_TERMINATE_Q (pfile
);
5247 /* Maintain and search list of included files, for #import. */
5249 /* Hash a file name for import_hash_table. */
5257 while (*f
) val
+= *f
++;
5258 return (val
%IMPORT_HASH_SIZE
);
5261 /* Search for file FILENAME in import_hash_table.
5262 Return -2 if found, either a matching name or a matching inode.
5263 Otherwise, open the file and return a file descriptor if successful
5264 or -1 if unsuccessful. */
5267 lookup_import (pfile
, filename
, searchptr
)
5270 struct file_name_list
*searchptr
;
5272 struct import_file
*i
;
5278 hashval
= import_hash (filename
);
5280 /* Attempt to find file in list of already included files */
5281 i
= pfile
->import_hash_table
[hashval
];
5284 if (!strcmp (filename
, i
->name
))
5285 return -2; /* return found */
5288 /* Open it and try a match on inode/dev */
5289 fd
= open_include_file (pfile
, filename
, searchptr
);
5293 for (h
= 0; h
< IMPORT_HASH_SIZE
; h
++) {
5294 i
= pfile
->import_hash_table
[h
];
5296 /* Compare the inode and the device.
5297 Supposedly on some systems the inode is not a scalar. */
5298 if (!bcmp ((char *) &i
->inode
, (char *) &sb
.st_ino
, sizeof (sb
.st_ino
))
5299 && i
->dev
== sb
.st_dev
) {
5301 return -2; /* return found */
5306 return fd
; /* Not found, return open file */
5309 /* Add the file FNAME, open on descriptor FD, to import_hash_table. */
5312 add_import (pfile
, fd
, fname
)
5317 struct import_file
*i
;
5321 hashval
= import_hash (fname
);
5323 i
= (struct import_file
*)xmalloc (sizeof (struct import_file
));
5324 i
->name
= (char *)xmalloc (strlen (fname
)+1);
5325 strcpy (i
->name
, fname
);
5326 bcopy ((char *) &sb
.st_ino
, (char *) &i
->inode
, sizeof (sb
.st_ino
));
5328 i
->next
= pfile
->import_hash_table
[hashval
];
5329 pfile
->import_hash_table
[hashval
] = i
;
5332 /* The file_name_map structure holds a mapping of file names for a
5333 particular directory. This mapping is read from the file named
5334 FILE_NAME_MAP_FILE in that directory. Such a file can be used to
5335 map filenames on a file system with severe filename restrictions,
5336 such as DOS. The format of the file name map file is just a series
5337 of lines with two tokens on each line. The first token is the name
5338 to map, and the second token is the actual name to use. */
5340 struct file_name_map
5342 struct file_name_map
*map_next
;
5347 #define FILE_NAME_MAP_FILE "header.gcc"
5349 /* Read a space delimited string of unlimited length from a stdio
5353 read_filename_string (ch
, f
)
5361 set
= alloc
= xmalloc (len
+ 1);
5365 while ((ch
= getc (f
)) != EOF
&& ! is_space
[ch
])
5367 if (set
- alloc
== len
)
5370 alloc
= xrealloc (alloc
, len
+ 1);
5371 set
= alloc
+ len
/ 2;
5381 /* This structure holds a linked list of file name maps, one per directory. */
5383 struct file_name_map_list
5385 struct file_name_map_list
*map_list_next
;
5386 char *map_list_name
;
5387 struct file_name_map
*map_list_map
;
5390 /* Read the file name map file for DIRNAME. */
5392 static struct file_name_map
*
5393 read_name_map (pfile
, dirname
)
5397 register struct file_name_map_list
*map_list_ptr
;
5401 for (map_list_ptr
= CPP_OPTIONS (pfile
)->map_list
; map_list_ptr
;
5402 map_list_ptr
= map_list_ptr
->map_list_next
)
5403 if (! strcmp (map_list_ptr
->map_list_name
, dirname
))
5404 return map_list_ptr
->map_list_map
;
5406 map_list_ptr
= ((struct file_name_map_list
*)
5407 xmalloc (sizeof (struct file_name_map_list
)));
5408 map_list_ptr
->map_list_name
= savestring (dirname
);
5409 map_list_ptr
->map_list_map
= NULL
;
5411 name
= (char *) alloca (strlen (dirname
) + strlen (FILE_NAME_MAP_FILE
) + 2);
5412 strcpy (name
, dirname
);
5415 strcat (name
, FILE_NAME_MAP_FILE
);
5416 f
= fopen (name
, "r");
5418 map_list_ptr
->map_list_map
= NULL
;
5422 int dirlen
= strlen (dirname
);
5424 while ((ch
= getc (f
)) != EOF
)
5427 struct file_name_map
*ptr
;
5431 from
= read_filename_string (ch
, f
);
5432 while ((ch
= getc (f
)) != EOF
&& is_hor_space
[ch
])
5434 to
= read_filename_string (ch
, f
);
5436 ptr
= ((struct file_name_map
*)
5437 xmalloc (sizeof (struct file_name_map
)));
5438 ptr
->map_from
= from
;
5440 /* Make the real filename absolute. */
5445 ptr
->map_to
= xmalloc (dirlen
+ strlen (to
) + 2);
5446 strcpy (ptr
->map_to
, dirname
);
5447 ptr
->map_to
[dirlen
] = '/';
5448 strcpy (ptr
->map_to
+ dirlen
+ 1, to
);
5452 ptr
->map_next
= map_list_ptr
->map_list_map
;
5453 map_list_ptr
->map_list_map
= ptr
;
5455 while ((ch
= getc (f
)) != '\n')
5462 map_list_ptr
->map_list_next
= CPP_OPTIONS (pfile
)->map_list
;
5463 CPP_OPTIONS (pfile
)->map_list
= map_list_ptr
;
5465 return map_list_ptr
->map_list_map
;
5468 /* Try to open include file FILENAME. SEARCHPTR is the directory
5469 being tried from the include file search path. This function maps
5470 filenames on file systems based on information read by
5474 open_include_file (pfile
, filename
, searchptr
)
5477 struct file_name_list
*searchptr
;
5479 if (CPP_OPTIONS (pfile
)->remap
)
5481 register struct file_name_map
*map
;
5482 register char *from
;
5485 if (searchptr
&& ! searchptr
->got_name_map
)
5487 searchptr
->name_map
= read_name_map (pfile
,
5489 ? searchptr
->fname
: ".");
5490 searchptr
->got_name_map
= 1;
5493 /* First check the mapping for the directory we are using. */
5494 if (searchptr
&& searchptr
->name_map
)
5497 if (searchptr
->fname
)
5498 from
+= strlen (searchptr
->fname
) + 1;
5499 for (map
= searchptr
->name_map
; map
; map
= map
->map_next
)
5501 if (! strcmp (map
->map_from
, from
))
5503 /* Found a match. */
5504 return open (map
->map_to
, O_RDONLY
, 0666);
5509 /* Try to find a mapping file for the particular directory we are
5510 looking in. Thus #include <sys/types.h> will look up sys/types.h
5511 in /usr/include/header.gcc and look up types.h in
5512 /usr/include/sys/header.gcc. */
5513 p
= rindex (filename
, '/');
5518 && strlen (searchptr
->fname
) == p
- filename
5519 && ! strncmp (searchptr
->fname
, filename
, p
- filename
))
5521 /* FILENAME is in SEARCHPTR, which we've already checked. */
5522 return open (filename
, O_RDONLY
, 0666);
5532 dir
= (char *) alloca (p
- filename
+ 1);
5533 bcopy (filename
, dir
, p
- filename
);
5534 dir
[p
- filename
] = '\0';
5537 for (map
= read_name_map (pfile
, dir
); map
; map
= map
->map_next
)
5538 if (! strcmp (map
->map_from
, from
))
5539 return open (map
->map_to
, O_RDONLY
, 0666);
5542 return open (filename
, O_RDONLY
, 0666);
5545 /* Process the contents of include file FNAME, already open on descriptor F,
5547 SYSTEM_HEADER_P is 1 if this file resides in any one of the known
5548 "system" include directories (as decided by the `is_system_include'
5550 DIRPTR is the link in the dir path through which this file was found,
5551 or 0 if the file name was absolute or via the current directory.
5552 Return 1 on success, 0 on failure.
5554 The caller is responsible for the cpp_push_buffer. */
5557 finclude (pfile
, f
, fname
, system_header_p
, dirptr
)
5561 int system_header_p
;
5562 struct file_name_list
*dirptr
;
5568 cpp_buffer
*fp
; /* For input stack frame */
5570 int missing_newline
= 0;
5573 if (fstat (f
, &st
) < 0)
5575 cpp_perror_with_name (pfile
, fname
);
5577 cpp_pop_buffer (pfile
);
5581 fp
= CPP_BUFFER (pfile
);
5582 fp
->nominal_fname
= fp
->fname
= fname
;
5587 fp
->system_header_p
= system_header_p
;
5590 fp
->cleanup
= file_cleanup
;
5592 if (S_ISREG (st
.st_mode
)) {
5593 st_size
= (size_t) st
.st_size
;
5594 if (st_size
!= st
.st_size
|| st_size
+ 2 < st_size
) {
5595 cpp_error (pfile
, "file `%s' too large", fname
);
5599 fp
->buf
= (U_CHAR
*) xmalloc (st_size
+ 2);
5600 fp
->alimit
= fp
->buf
+ st_size
+ 2;
5603 /* Read the file contents, knowing that st_size is an upper bound
5604 on the number of bytes we can read. */
5605 length
= safe_read (f
, fp
->buf
, st_size
);
5606 fp
->rlimit
= fp
->buf
+ length
;
5607 if (length
< 0) goto nope
;
5609 else if (S_ISDIR (st
.st_mode
)) {
5610 cpp_error (pfile
, "directory `%s' specified in #include", fname
);
5614 /* Cannot count its file size before reading.
5615 First read the entire file into heap and
5616 copy them into buffer on stack. */
5621 fp
->buf
= (U_CHAR
*) xmalloc (bsize
+ 2);
5624 i
= safe_read (f
, fp
->buf
+ st_size
, bsize
- st_size
);
5626 goto nope
; /* error! */
5628 if (st_size
!= bsize
)
5629 break; /* End of file */
5631 fp
->buf
= (U_CHAR
*) xrealloc (fp
->buf
, bsize
+ 2);
5637 if ((length
> 0 && fp
->buf
[length
- 1] != '\n')
5638 /* Backslash-newline at end is not good enough. */
5639 || (length
> 1 && fp
->buf
[length
- 2] == '\\')) {
5640 fp
->buf
[length
++] = '\n';
5642 missing_newline
= 1;
5645 fp
->buf
[length
] = '\0';
5646 fp
->rlimit
= fp
->buf
+ length
;
5648 /* Close descriptor now, so nesting does not use lots of descriptors. */
5651 /* Must do this before calling trigraph_pcp, so that the correct file name
5652 will be printed in warning messages. */
5654 pfile
->input_stack_listing_current
= 0;
5664 if (missing_newline
)
5667 if (CPP_PEDANTIC (pfile
) && missing_newline
)
5668 pedwarn ("file does not end in newline");
5671 input_file_stack_tick
++;
5678 cpp_perror_with_name (pfile
, fname
);
5684 /* This is called after options have been processed.
5685 * Check options for consistency, and setup for processing input
5686 * from the file named FNAME. (Use standard input if FNAME==NULL.)
5687 * Return 1 on success, 0 on failure.
5691 cpp_start_read (pfile
, fname
)
5695 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
5696 struct cpp_pending
*pend
;
5701 /* The code looks at the defaults through this pointer, rather than through
5702 the constant structure above. This pointer gets changed if an environment
5703 variable specifies other defaults. */
5704 struct default_include
*include_defaults
= include_defaults_array
;
5706 /* Add dirs from CPATH after dirs from -I. */
5707 /* There seems to be confusion about what CPATH should do,
5708 so for the moment it is not documented. */
5709 /* Some people say that CPATH should replace the standard include dirs,
5710 but that seems pointless: it comes before them, so it overrides them
5712 GET_ENVIRONMENT (p
, "CPATH");
5713 if (p
!= 0 && ! opts
->no_standard_includes
)
5714 path_include (pfile
, p
);
5716 /* Now that dollars_in_ident is known, initialize is_idchar. */
5717 initialize_char_syntax (opts
);
5719 /* Do partial setup of input buffer for the sake of generating
5720 early #line directives (when -g is in effect). */
5721 fp
= cpp_push_buffer (pfile
, NULL
, 0);
5724 if (opts
->in_fname
== NULL
)
5725 opts
->in_fname
= "";
5726 fp
->nominal_fname
= fp
->fname
= opts
->in_fname
;
5729 /* Install __LINE__, etc. Must follow initialize_char_syntax
5730 and option processing. */
5731 initialize_builtins (pfile
);
5733 /* Do standard #defines and assertions
5734 that identify system and machine type. */
5736 if (!opts
->inhibit_predefs
) {
5737 char *p
= (char *) alloca (strlen (predefs
) + 1);
5738 strcpy (p
, predefs
);
5741 while (*p
== ' ' || *p
== '\t')
5743 /* Handle -D options. */
5744 if (p
[0] == '-' && p
[1] == 'D') {
5746 while (*p
&& *p
!= ' ' && *p
!= '\t')
5750 if (opts
->debug_output
)
5751 output_line_command (pfile
, 0, same_file
);
5752 cpp_define (pfile
, q
);
5753 while (*p
== ' ' || *p
== '\t')
5755 } else if (p
[0] == '-' && p
[1] == 'A') {
5756 /* Handle -A options (assertions). */
5765 past_name
= assertion
;
5766 /* Locate end of name. */
5767 while (*past_name
&& *past_name
!= ' '
5768 && *past_name
!= '\t' && *past_name
!= '(')
5770 /* Locate `(' at start of value. */
5772 while (*value
&& (*value
== ' ' || *value
== '\t'))
5774 if (*value
++ != '(')
5776 while (*value
&& (*value
== ' ' || *value
== '\t'))
5779 /* Locate end of value. */
5780 while (*past_value
&& *past_value
!= ' '
5781 && *past_value
!= '\t' && *past_value
!= ')')
5783 termination
= past_value
;
5784 while (*termination
&& (*termination
== ' ' || *termination
== '\t'))
5786 if (*termination
++ != ')')
5788 if (*termination
&& *termination
!= ' ' && *termination
!= '\t')
5790 /* Temporarily null-terminate the value. */
5791 save_char
= *termination
;
5792 *termination
= '\0';
5793 /* Install the assertion. */
5794 make_assertion (pfile
, "-A", assertion
);
5795 *termination
= (char) save_char
;
5797 while (*p
== ' ' || *p
== '\t')
5805 /* Now handle the command line options. */
5807 /* Do -U's, -D's and -A's in the order they were seen. */
5808 /* First reverse the list. */
5809 opts
->pending
= nreverse_pending (opts
->pending
);
5811 for (pend
= opts
->pending
; pend
; pend
= pend
->next
)
5813 if (pend
->cmd
!= NULL
&& pend
->cmd
[0] == '-')
5815 switch (pend
->cmd
[1])
5818 if (opts
->debug_output
)
5819 output_line_command (pfile
, 0, same_file
);
5820 do_undef (pfile
, NULL
, pend
->arg
, pend
->arg
+ strlen (pend
->arg
));
5823 if (opts
->debug_output
)
5824 output_line_command (pfile
, 0, same_file
);
5825 cpp_define (pfile
, pend
->arg
);
5828 make_assertion (pfile
, "-A", pend
->arg
);
5834 opts
->done_initializing
= 1;
5836 { /* Read the appropriate environment variable and if it exists
5837 replace include_defaults with the listed path. */
5839 switch ((opts
->objc
<< 1) + opts
->cplusplus
)
5842 GET_ENVIRONMENT (epath
, "C_INCLUDE_PATH");
5845 GET_ENVIRONMENT (epath
, "CPLUS_INCLUDE_PATH");
5848 GET_ENVIRONMENT (epath
, "OBJC_INCLUDE_PATH");
5851 GET_ENVIRONMENT (epath
, "OBJCPLUS_INCLUDE_PATH");
5854 /* If the environment var for this language is set,
5855 add to the default list of include directories. */
5857 char *nstore
= (char *) alloca (strlen (epath
) + 2);
5859 char *startp
, *endp
;
5861 for (num_dirs
= 1, startp
= epath
; *startp
; startp
++)
5862 if (*startp
== PATH_SEPARATOR
)
5865 = (struct default_include
*) xmalloc ((num_dirs
5866 * sizeof (struct default_include
))
5867 + sizeof (include_defaults_array
));
5868 startp
= endp
= epath
;
5871 /* Handle cases like c:/usr/lib:d:/gcc/lib */
5872 if ((*endp
== PATH_SEPARATOR
)
5874 strncpy (nstore
, startp
, endp
-startp
);
5876 strcpy (nstore
, ".");
5878 nstore
[endp
-startp
] = '\0';
5880 include_defaults
[num_dirs
].fname
= savestring (nstore
);
5881 include_defaults
[num_dirs
].component
= 0;
5882 include_defaults
[num_dirs
].cplusplus
= opts
->cplusplus
;
5883 include_defaults
[num_dirs
].cxx_aware
= 1;
5887 endp
= startp
= endp
+ 1;
5891 /* Put the usual defaults back in at the end. */
5892 bcopy ((char *) include_defaults_array
,
5893 (char *) &include_defaults
[num_dirs
],
5894 sizeof (include_defaults_array
));
5898 append_include_chain (pfile
, opts
->before_system
, opts
->last_before_system
);
5899 opts
->first_system_include
= opts
->before_system
;
5901 /* Unless -fnostdinc,
5902 tack on the standard include file dirs to the specified list */
5903 if (!opts
->no_standard_includes
) {
5904 struct default_include
*p
= include_defaults
;
5905 char *specd_prefix
= opts
->include_prefix
;
5906 char *default_prefix
= savestring (GCC_INCLUDE_DIR
);
5907 int default_len
= 0;
5908 /* Remove the `include' from /usr/local/lib/gcc.../include. */
5909 if (!strcmp (default_prefix
+ strlen (default_prefix
) - 8, "/include")) {
5910 default_len
= strlen (default_prefix
) - 7;
5911 default_prefix
[default_len
] = 0;
5913 /* Search "translated" versions of GNU directories.
5914 These have /usr/local/lib/gcc... replaced by specd_prefix. */
5915 if (specd_prefix
!= 0 && default_len
!= 0)
5916 for (p
= include_defaults
; p
->fname
; p
++) {
5917 /* Some standard dirs are only for C++. */
5919 || (opts
->cplusplus
&& !opts
->no_standard_cplusplus_includes
)) {
5920 /* Does this dir start with the prefix? */
5921 if (!strncmp (p
->fname
, default_prefix
, default_len
)) {
5922 /* Yes; change prefix and add to search list. */
5923 struct file_name_list
*new
5924 = (struct file_name_list
*) xmalloc (sizeof (struct file_name_list
));
5925 int this_len
= strlen (specd_prefix
) + strlen (p
->fname
) - default_len
;
5926 char *str
= (char *) xmalloc (this_len
+ 1);
5927 strcpy (str
, specd_prefix
);
5928 strcat (str
, p
->fname
+ default_len
);
5930 new->control_macro
= 0;
5931 new->c_system_include_path
= !p
->cxx_aware
;
5932 new->got_name_map
= 0;
5933 append_include_chain (pfile
, new, new);
5934 if (opts
->first_system_include
== 0)
5935 opts
->first_system_include
= new;
5939 /* Search ordinary names for GNU include directories. */
5940 for (p
= include_defaults
; p
->fname
; p
++) {
5941 /* Some standard dirs are only for C++. */
5943 || (opts
->cplusplus
&& !opts
->no_standard_cplusplus_includes
)) {
5944 struct file_name_list
*new
5945 = (struct file_name_list
*) xmalloc (sizeof (struct file_name_list
));
5946 new->control_macro
= 0;
5947 new->c_system_include_path
= !p
->cxx_aware
;
5948 new->fname
= update_path (p
->fname
, p
->component
);
5949 new->got_name_map
= 0;
5950 append_include_chain (pfile
, new, new);
5951 if (opts
->first_system_include
== 0)
5952 opts
->first_system_include
= new;
5957 /* Tack the after_include chain at the end of the include chain. */
5958 append_include_chain (pfile
, opts
->after_include
, opts
->last_after_include
);
5959 if (opts
->first_system_include
== 0)
5960 opts
->first_system_include
= opts
->after_include
;
5962 /* With -v, print the list of dirs to search. */
5963 if (opts
->verbose
) {
5964 struct file_name_list
*p
;
5965 fprintf (stderr
, "#include \"...\" search starts here:\n");
5966 for (p
= opts
->include
; p
; p
= p
->next
) {
5967 if (p
== opts
->first_bracket_include
)
5968 fprintf (stderr
, "#include <...> search starts here:\n");
5969 fprintf (stderr
, " %s\n", p
->fname
);
5971 fprintf (stderr
, "End of search list.\n");
5974 /* Scan the -imacros files before the main input.
5975 Much like #including them, but with no_output set
5976 so that only their macro definitions matter. */
5978 opts
->no_output
++; pfile
->no_record_file
++;
5979 for (pend
= opts
->pending
; pend
; pend
= pend
->next
)
5981 if (pend
->cmd
!= NULL
&& strcmp (pend
->cmd
, "-imacros") == 0)
5983 int fd
= open (pend
->arg
, O_RDONLY
, 0666);
5986 cpp_perror_with_name (pfile
, pend
->arg
);
5989 if (!cpp_push_buffer (pfile
, NULL
, 0))
5991 finclude (pfile
, fd
, pend
->arg
, 0, NULL_PTR
);
5992 cpp_scan_buffer (pfile
);
5995 opts
->no_output
--; pfile
->no_record_file
--;
5997 /* Copy the entire contents of the main input file into
5998 the stacked input buffer previously allocated for it. */
5999 if (fname
== NULL
|| *fname
== 0) {
6002 } else if ((f
= open (fname
, O_RDONLY
, 0666)) < 0)
6003 cpp_pfatal_with_name (pfile
, fname
);
6005 /* -MG doesn't select the form of output and must be specified with one of
6006 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
6007 inhibit compilation. */
6008 if (opts
->print_deps_missing_files
6009 && (opts
->print_deps
== 0 || !opts
->no_output
))
6011 cpp_fatal (pfile
, "-MG must be specified with one of -M or -MM");
6015 /* Either of two environment variables can specify output of deps.
6016 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
6017 where OUTPUT_FILE is the file to write deps info to
6018 and DEPS_TARGET is the target to mention in the deps. */
6020 if (opts
->print_deps
== 0
6021 && (getenv ("SUNPRO_DEPENDENCIES") != 0
6022 || getenv ("DEPENDENCIES_OUTPUT") != 0)) {
6023 char *spec
= getenv ("DEPENDENCIES_OUTPUT");
6029 spec
= getenv ("SUNPRO_DEPENDENCIES");
6030 opts
->print_deps
= 2;
6033 opts
->print_deps
= 1;
6036 /* Find the space before the DEPS_TARGET, if there is one. */
6037 /* This should use index. (mrs) */
6038 while (*s
!= 0 && *s
!= ' ') s
++;
6041 opts
->deps_target
= s
+ 1;
6042 output_file
= (char *) xmalloc (s
- spec
+ 1);
6043 bcopy (spec
, output_file
, s
- spec
);
6044 output_file
[s
- spec
] = 0;
6048 opts
->deps_target
= 0;
6052 opts
->deps_file
= output_file
;
6053 opts
->print_deps_append
= 1;
6056 /* For -M, print the expected object file name
6057 as the target of this Make-rule. */
6058 if (opts
->print_deps
)
6060 pfile
->deps_allocated_size
= 200;
6061 pfile
->deps_buffer
= (char *) xmalloc (pfile
->deps_allocated_size
);
6062 pfile
->deps_buffer
[0] = 0;
6063 pfile
->deps_size
= 0;
6064 pfile
->deps_column
= 0;
6066 if (opts
->deps_target
)
6067 deps_output (pfile
, opts
->deps_target
, ':');
6068 else if (*opts
->in_fname
== 0)
6069 deps_output (pfile
, "-", ':');
6074 static char *known_suffixes
[] = { ".c", ".C", ".s", ".S", ".m",
6075 ".cc", ".cxx", ".cpp", ".cp",
6079 /* Discard all directory prefixes from filename. */
6080 if ((q
= rindex (opts
->in_fname
, '/')) != NULL
6081 #ifdef DIR_SEPARATOR
6082 && (q
= rindex (opts
->in_fname
, DIR_SEPARATOR
)) != NULL
6089 /* Copy remainder to mungable area. */
6090 p
= (char *) alloca (strlen(q
) + 8);
6093 /* Output P, but remove known suffixes. */
6096 /* Point to the filename suffix. */
6097 r
= rindex (p
, '.');
6098 /* Compare against the known suffixes. */
6100 while (known_suffixes
[x
] != 0)
6102 if (strncmp (known_suffixes
[x
], r
, q
- r
) == 0)
6104 /* Make q point to the bit we're going to overwrite
6105 with an object suffix. */
6112 /* Supply our own suffix. */
6119 deps_output (pfile
, p
, ':');
6120 deps_output (pfile
, opts
->in_fname
, ' ');
6125 /* Make sure data ends with a newline. And put a null after it. */
6127 if ((fp
->length
> 0 && fp
->buf
[fp
->length
- 1] != '\n')
6128 /* Backslash-newline at end is not good enough. */
6129 || (fp
->length
> 1 && fp
->buf
[fp
->length
- 2] == '\\')) {
6130 fp
->buf
[fp
->length
++] = '\n';
6131 missing_newline
= 1;
6133 fp
->buf
[fp
->length
] = '\0';
6135 /* Unless inhibited, convert trigraphs in the input. */
6141 /* Scan the -include files before the main input.
6142 We push these in reverse order, so that the first one is handled first. */
6144 pfile
->no_record_file
++;
6145 opts
->pending
= nreverse_pending (opts
->pending
);
6146 for (pend
= opts
->pending
; pend
; pend
= pend
->next
)
6148 if (pend
->cmd
!= NULL
&& strcmp (pend
->cmd
, "-include") == 0)
6150 int fd
= open (pend
->arg
, O_RDONLY
, 0666);
6153 cpp_perror_with_name (pfile
, pend
->arg
);
6156 if (!cpp_push_buffer (pfile
, NULL
, 0))
6158 finclude (pfile
, fd
, pend
->arg
, 0, NULL_PTR
);
6161 pfile
->no_record_file
--;
6163 /* Free the pending list. */
6164 for (pend
= opts
->pending
; pend
; )
6166 struct cpp_pending
*next
= pend
->next
;
6170 opts
->pending
= NULL
;
6173 /* Scan the input, processing macros and directives. */
6175 rescan (&outbuf
, 0);
6177 if (missing_newline
)
6180 if (CPP_PEDANTIC (pfile
) && missing_newline
)
6181 pedwarn ("file does not end in newline");
6184 if (finclude (pfile
, f
, fname
, 0, NULL_PTR
))
6185 output_line_command (pfile
, 0, same_file
);
6190 cpp_reader_init (pfile
)
6193 bzero ((char *) pfile
, sizeof (cpp_reader
));
6194 pfile
->get_token
= cpp_get_token
;
6196 pfile
->token_buffer_size
= 200;
6197 pfile
->token_buffer
= (U_CHAR
*) xmalloc (pfile
->token_buffer_size
);
6198 CPP_SET_WRITTEN (pfile
, 0);
6200 pfile
->system_include_depth
= 0;
6201 pfile
->dont_repeat_files
= 0;
6202 pfile
->all_include_files
= 0;
6203 pfile
->max_include_len
= 0;
6204 pfile
->timebuf
= NULL
;
6205 pfile
->only_seen_white
= 1;
6206 pfile
->buffer
= CPP_NULL_BUFFER(pfile
);
6209 static struct cpp_pending
*
6210 nreverse_pending (list
)
6211 struct cpp_pending
*list
;
6214 register struct cpp_pending
*prev
= 0, *next
, *pend
;
6215 for (pend
= list
; pend
; pend
= next
)
6225 push_pending (pfile
, cmd
, arg
)
6230 struct cpp_pending
*pend
6231 = (struct cpp_pending
*) xmalloc (sizeof (struct cpp_pending
));
6234 pend
->next
= CPP_OPTIONS (pfile
)->pending
;
6235 CPP_OPTIONS (pfile
)->pending
= pend
;
6238 /* Handle command-line options in (argc, argv).
6239 Can be called multiple times, to handle multiple sets of options.
6240 Returns if an unrecognized option is seen.
6241 Returns number of handled arguments. */
6244 cpp_handle_options (pfile
, argc
, argv
)
6250 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
6251 for (i
= 0; i
< argc
; i
++) {
6252 if (argv
[i
][0] != '-') {
6253 if (opts
->out_fname
!= NULL
)
6255 cpp_fatal (pfile
, "Usage: %s [switches] input output", argv
[0]);
6258 else if (opts
->in_fname
!= NULL
)
6259 opts
->out_fname
= argv
[i
];
6261 opts
->in_fname
= argv
[i
];
6263 switch (argv
[i
][1]) {
6266 cpp_fatal (pfile
, "Filename missing after `%s' option", argv
[i
]);
6269 cpp_fatal (pfile
, "Directory name missing after `%s' option", argv
[i
]);
6273 if (!strcmp (argv
[i
], "-include")
6274 || !strcmp (argv
[i
], "-imacros")) {
6276 goto missing_filename
;
6278 push_pending (pfile
, argv
[i
], argv
[i
+1]), i
++;
6280 if (!strcmp (argv
[i
], "-iprefix")) {
6282 goto missing_filename
;
6284 opts
->include_prefix
= argv
[++i
];
6286 if (!strcmp (argv
[i
], "-ifoutput")) {
6287 opts
->output_conditionals
= 1;
6289 if (!strcmp (argv
[i
], "-isystem")) {
6290 struct file_name_list
*dirtmp
;
6293 goto missing_filename
;
6295 dirtmp
= (struct file_name_list
*)
6296 xmalloc (sizeof (struct file_name_list
));
6298 dirtmp
->control_macro
= 0;
6299 dirtmp
->c_system_include_path
= 1;
6300 dirtmp
->fname
= (char *) xmalloc (strlen (argv
[i
+1]) + 1);
6301 strcpy (dirtmp
->fname
, argv
[++i
]);
6302 dirtmp
->got_name_map
= 0;
6304 if (opts
->before_system
== 0)
6305 opts
->before_system
= dirtmp
;
6307 opts
->last_before_system
->next
= dirtmp
;
6308 opts
->last_before_system
= dirtmp
; /* Tail follows the last one */
6310 /* Add directory to end of path for includes,
6311 with the default prefix at the front of its name. */
6312 if (!strcmp (argv
[i
], "-iwithprefix")) {
6313 struct file_name_list
*dirtmp
;
6316 if (opts
->include_prefix
!= 0)
6317 prefix
= opts
->include_prefix
;
6319 prefix
= savestring (GCC_INCLUDE_DIR
);
6320 /* Remove the `include' from /usr/local/lib/gcc.../include. */
6321 if (!strcmp (prefix
+ strlen (prefix
) - 8, "/include"))
6322 prefix
[strlen (prefix
) - 7] = 0;
6325 dirtmp
= (struct file_name_list
*)
6326 xmalloc (sizeof (struct file_name_list
));
6327 dirtmp
->next
= 0; /* New one goes on the end */
6328 dirtmp
->control_macro
= 0;
6329 dirtmp
->c_system_include_path
= 0;
6331 goto missing_dirname
;
6333 dirtmp
->fname
= (char *) xmalloc (strlen (argv
[i
+1])
6334 + strlen (prefix
) + 1);
6335 strcpy (dirtmp
->fname
, prefix
);
6336 strcat (dirtmp
->fname
, argv
[++i
]);
6337 dirtmp
->got_name_map
= 0;
6339 if (opts
->after_include
== 0)
6340 opts
->after_include
= dirtmp
;
6342 opts
->last_after_include
->next
= dirtmp
;
6343 opts
->last_after_include
= dirtmp
; /* Tail follows the last one */
6345 /* Add directory to main path for includes,
6346 with the default prefix at the front of its name. */
6347 if (!strcmp (argv
[i
], "-iwithprefixbefore")) {
6348 struct file_name_list
*dirtmp
;
6351 if (opts
->include_prefix
!= 0)
6352 prefix
= opts
->include_prefix
;
6354 prefix
= savestring (GCC_INCLUDE_DIR
);
6355 /* Remove the `include' from /usr/local/lib/gcc.../include. */
6356 if (!strcmp (prefix
+ strlen (prefix
) - 8, "/include"))
6357 prefix
[strlen (prefix
) - 7] = 0;
6360 dirtmp
= (struct file_name_list
*)
6361 xmalloc (sizeof (struct file_name_list
));
6362 dirtmp
->next
= 0; /* New one goes on the end */
6363 dirtmp
->control_macro
= 0;
6364 dirtmp
->c_system_include_path
= 0;
6366 goto missing_dirname
;
6368 dirtmp
->fname
= (char *) xmalloc (strlen (argv
[i
+1])
6369 + strlen (prefix
) + 1);
6370 strcpy (dirtmp
->fname
, prefix
);
6371 strcat (dirtmp
->fname
, argv
[++i
]);
6372 dirtmp
->got_name_map
= 0;
6374 append_include_chain (pfile
, dirtmp
, dirtmp
);
6376 /* Add directory to end of path for includes. */
6377 if (!strcmp (argv
[i
], "-idirafter")) {
6378 struct file_name_list
*dirtmp
;
6380 dirtmp
= (struct file_name_list
*)
6381 xmalloc (sizeof (struct file_name_list
));
6382 dirtmp
->next
= 0; /* New one goes on the end */
6383 dirtmp
->control_macro
= 0;
6384 dirtmp
->c_system_include_path
= 0;
6386 goto missing_dirname
;
6388 dirtmp
->fname
= argv
[++i
];
6389 dirtmp
->got_name_map
= 0;
6391 if (opts
->after_include
== 0)
6392 opts
->after_include
= dirtmp
;
6394 opts
->last_after_include
->next
= dirtmp
;
6395 opts
->last_after_include
= dirtmp
; /* Tail follows the last one */
6400 if (opts
->out_fname
!= NULL
)
6402 cpp_fatal (pfile
, "Output filename specified twice");
6406 goto missing_filename
;
6407 opts
->out_fname
= argv
[++i
];
6408 if (!strcmp (opts
->out_fname
, "-"))
6409 opts
->out_fname
= "";
6413 if (!strcmp (argv
[i
], "-pedantic"))
6414 CPP_PEDANTIC (pfile
) = 1;
6415 else if (!strcmp (argv
[i
], "-pedantic-errors")) {
6416 CPP_PEDANTIC (pfile
) = 1;
6417 opts
->pedantic_errors
= 1;
6420 else if (!strcmp (argv
[i
], "-pcp")) {
6421 char *pcp_fname
= argv
[++i
];
6422 pcp_outfile
= ((pcp_fname
[0] != '-' || pcp_fname
[1] != '\0')
6423 ? fopen (pcp_fname
, "w")
6424 : fdopen (dup (fileno (stdout
)), "w"));
6425 if (pcp_outfile
== 0)
6426 cpp_pfatal_with_name (pfile
, pcp_fname
);
6433 if (!strcmp (argv
[i
], "-traditional")) {
6434 opts
->traditional
= 1;
6435 } else if (!strcmp (argv
[i
], "-trigraphs")) {
6437 opts
->no_trigraphs
= 0;
6442 if (! strcmp (argv
[i
], "-lang-c"))
6443 opts
->cplusplus
= 0, opts
->cplusplus_comments
= 1, opts
->c89
= 0,
6445 if (! strcmp (argv
[i
], "-lang-c89"))
6446 opts
->cplusplus
= 0, opts
->cplusplus_comments
= 0, opts
->c89
= 1,
6448 if (! strcmp (argv
[i
], "-lang-c++"))
6449 opts
->cplusplus
= 1, opts
->cplusplus_comments
= 1, opts
->c89
= 0,
6451 if (! strcmp (argv
[i
], "-lang-objc"))
6452 opts
->cplusplus
= 0, opts
->cplusplus_comments
= 1, opts
->c89
= 0,
6454 if (! strcmp (argv
[i
], "-lang-objc++"))
6455 opts
->cplusplus
= 1, opts
->cplusplus_comments
= 1, opts
->c89
= 0,
6457 if (! strcmp (argv
[i
], "-lang-asm"))
6459 if (! strcmp (argv
[i
], "-lint"))
6461 if (! strcmp (argv
[i
], "-lang-chill"))
6462 opts
->objc
= 0, opts
->cplusplus
= 0, opts
->chill
= 1,
6463 opts
->traditional
= 1, opts
->no_trigraphs
= 1;
6467 opts
->cplusplus
= 1, opts
->cplusplus_comments
= 1;
6471 opts
->inhibit_warnings
= 1;
6475 if (!strcmp (argv
[i
], "-Wtrigraphs"))
6476 opts
->warn_trigraphs
= 1;
6477 else if (!strcmp (argv
[i
], "-Wno-trigraphs"))
6478 opts
->warn_trigraphs
= 0;
6479 else if (!strcmp (argv
[i
], "-Wcomment"))
6480 opts
->warn_comments
= 1;
6481 else if (!strcmp (argv
[i
], "-Wno-comment"))
6482 opts
->warn_comments
= 0;
6483 else if (!strcmp (argv
[i
], "-Wcomments"))
6484 opts
->warn_comments
= 1;
6485 else if (!strcmp (argv
[i
], "-Wno-comments"))
6486 opts
->warn_comments
= 0;
6487 else if (!strcmp (argv
[i
], "-Wtraditional"))
6488 opts
->warn_stringify
= 1;
6489 else if (!strcmp (argv
[i
], "-Wno-traditional"))
6490 opts
->warn_stringify
= 0;
6491 else if (!strcmp (argv
[i
], "-Wundef"))
6492 opts
->warn_undef
= 1;
6493 else if (!strcmp (argv
[i
], "-Wno-undef"))
6494 opts
->warn_undef
= 0;
6495 else if (!strcmp (argv
[i
], "-Wimport"))
6496 opts
->warn_import
= 1;
6497 else if (!strcmp (argv
[i
], "-Wno-import"))
6498 opts
->warn_import
= 0;
6499 else if (!strcmp (argv
[i
], "-Werror"))
6500 opts
->warnings_are_errors
= 1;
6501 else if (!strcmp (argv
[i
], "-Wno-error"))
6502 opts
->warnings_are_errors
= 0;
6503 else if (!strcmp (argv
[i
], "-Wall"))
6505 opts
->warn_trigraphs
= 1;
6506 opts
->warn_comments
= 1;
6511 /* The style of the choices here is a bit mixed.
6512 The chosen scheme is a hybrid of keeping all options in one string
6513 and specifying each option in a separate argument:
6514 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
6515 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
6516 -M[M][G][D file]. This is awkward to handle in specs, and is not
6518 /* ??? -MG must be specified in addition to one of -M or -MM.
6519 This can be relaxed in the future without breaking anything.
6520 The converse isn't true. */
6522 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
6523 if (!strcmp (argv
[i
], "-MG"))
6525 opts
->print_deps_missing_files
= 1;
6528 if (!strcmp (argv
[i
], "-M"))
6529 opts
->print_deps
= 2;
6530 else if (!strcmp (argv
[i
], "-MM"))
6531 opts
->print_deps
= 1;
6532 else if (!strcmp (argv
[i
], "-MD"))
6533 opts
->print_deps
= 2;
6534 else if (!strcmp (argv
[i
], "-MMD"))
6535 opts
->print_deps
= 1;
6536 /* For -MD and -MMD options, write deps on file named by next arg. */
6537 if (!strcmp (argv
[i
], "-MD") || !strcmp (argv
[i
], "-MMD"))
6540 goto missing_filename
;
6541 opts
->deps_file
= argv
[++i
];
6545 /* For -M and -MM, write deps on standard output
6546 and suppress the usual output. */
6547 opts
->no_output
= 1;
6553 char *p
= argv
[i
] + 2;
6555 while ((c
= *p
++) != 0) {
6556 /* Arg to -d specifies what parts of macros to dump */
6559 opts
->dump_macros
= dump_only
;
6560 opts
->no_output
= 1;
6563 opts
->dump_macros
= dump_names
;
6566 opts
->dump_macros
= dump_definitions
;
6569 opts
->dump_includes
= 1;
6577 if (argv
[i
][2] == '3')
6578 opts
->debug_output
= 1;
6582 fprintf (stderr
, "GNU CPP version %s", version_string
);
6583 #ifdef TARGET_VERSION
6586 fprintf (stderr
, "\n");
6591 opts
->print_include_names
= 1;
6595 if (argv
[i
][2] != 0)
6596 push_pending (pfile
, "-D", argv
[i
] + 2);
6597 else if (i
+ 1 == argc
)
6599 cpp_fatal (pfile
, "Macro name missing after -D option");
6603 i
++, push_pending (pfile
, "-D", argv
[i
]);
6610 if (argv
[i
][2] != 0)
6612 else if (i
+ 1 == argc
)
6614 cpp_fatal (pfile
, "Assertion missing after -A option");
6620 if (!strcmp (p
, "-")) {
6621 struct cpp_pending
**ptr
;
6622 /* -A- eliminates all predefined macros and assertions.
6623 Let's include also any that were specified earlier
6624 on the command line. That way we can get rid of any
6625 that were passed automatically in from GCC. */
6626 opts
->inhibit_predefs
= 1;
6627 for (ptr
= &opts
->pending
; *ptr
!= NULL
; )
6629 struct cpp_pending
*pend
= *ptr
;
6630 if (pend
->cmd
&& pend
->cmd
[0] == '-'
6631 && (pend
->cmd
[1] == 'D' || pend
->cmd
[1] == 'A'))
6640 push_pending (pfile
, "-A", p
);
6645 case 'U': /* JF #undef something */
6646 if (argv
[i
][2] != 0)
6647 push_pending (pfile
, "-U", argv
[i
] + 2);
6648 else if (i
+ 1 == argc
)
6650 cpp_fatal (pfile
, "Macro name missing after -U option");
6654 push_pending (pfile
, "-U", argv
[i
+1]), i
++;
6658 opts
->put_out_comments
= 1;
6661 case 'E': /* -E comes from cc -E; ignore it. */
6665 opts
->no_line_commands
= 1;
6668 case '$': /* Don't include $ in identifiers. */
6669 opts
->dollars_in_ident
= 0;
6672 case 'I': /* Add directory to path for includes. */
6674 struct file_name_list
*dirtmp
;
6676 if (! CPP_OPTIONS(pfile
)->ignore_srcdir
6677 && !strcmp (argv
[i
] + 2, "-")) {
6678 CPP_OPTIONS (pfile
)->ignore_srcdir
= 1;
6679 /* Don't use any preceding -I directories for #include <...>. */
6680 CPP_OPTIONS (pfile
)->first_bracket_include
= 0;
6683 dirtmp
= (struct file_name_list
*)
6684 xmalloc (sizeof (struct file_name_list
));
6685 dirtmp
->next
= 0; /* New one goes on the end */
6686 dirtmp
->control_macro
= 0;
6687 dirtmp
->c_system_include_path
= 0;
6688 if (argv
[i
][2] != 0)
6689 dirtmp
->fname
= argv
[i
] + 2;
6690 else if (i
+ 1 == argc
)
6691 goto missing_dirname
;
6693 dirtmp
->fname
= argv
[++i
];
6694 dirtmp
->got_name_map
= 0;
6695 append_include_chain (pfile
, dirtmp
, dirtmp
);
6701 if (!strcmp (argv
[i
], "-nostdinc"))
6702 /* -nostdinc causes no default include directories.
6703 You must specify all include-file directories with -I. */
6704 opts
->no_standard_includes
= 1;
6705 else if (!strcmp (argv
[i
], "-nostdinc++"))
6706 /* -nostdinc++ causes no default C++-specific include directories. */
6707 opts
->no_standard_cplusplus_includes
= 1;
6709 else if (!strcmp (argv
[i
], "-noprecomp"))
6715 if (!strcmp (argv
[i
], "-remap"))
6720 /* Sun compiler passes undocumented switch "-undef".
6721 Let's assume it means to inhibit the predefined symbols. */
6722 opts
->inhibit_predefs
= 1;
6725 case '\0': /* JF handle '-' as file name meaning stdin or stdout */
6726 if (opts
->in_fname
== NULL
) {
6727 opts
->in_fname
= "";
6729 } else if (opts
->out_fname
== NULL
) {
6730 opts
->out_fname
= "";
6732 } /* else fall through into error */
6746 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
6748 if (opts
->print_deps
)
6750 /* Stream on which to print the dependency information. */
6753 /* Don't actually write the deps file if compilation has failed. */
6754 if (pfile
->errors
== 0)
6756 char *deps_mode
= opts
->print_deps_append
? "a" : "w";
6757 if (opts
->deps_file
== 0)
6758 deps_stream
= stdout
;
6759 else if ((deps_stream
= fopen (opts
->deps_file
, deps_mode
)) == 0)
6760 cpp_pfatal_with_name (pfile
, opts
->deps_file
);
6761 fputs (pfile
->deps_buffer
, deps_stream
);
6762 putc ('\n', deps_stream
);
6763 if (opts
->deps_file
)
6765 if (ferror (deps_stream
) || fclose (deps_stream
) != 0)
6766 cpp_fatal (pfile
, "I/O error on output");
6772 /* Free resources used by PFILE.
6773 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
6780 while ( CPP_BUFFER (pfile
) != CPP_NULL_BUFFER (pfile
))
6781 cpp_pop_buffer (pfile
);
6783 if (pfile
->token_buffer
)
6785 free (pfile
->token_buffer
);
6786 pfile
->token_buffer
= NULL
;
6789 if (pfile
->deps_buffer
)
6791 free (pfile
->deps_buffer
);
6792 pfile
->deps_buffer
= NULL
;
6793 pfile
->deps_allocated_size
= 0;
6796 while (pfile
->if_stack
)
6798 IF_STACK_FRAME
*temp
= pfile
->if_stack
;
6799 pfile
->if_stack
= temp
->next
;
6803 while (pfile
->dont_repeat_files
)
6805 struct file_name_list
*temp
= pfile
->dont_repeat_files
;
6806 pfile
->dont_repeat_files
= temp
->next
;
6811 while (pfile
->all_include_files
)
6813 struct file_name_list
*temp
= pfile
->all_include_files
;
6814 pfile
->all_include_files
= temp
->next
;
6819 for (i
= IMPORT_HASH_SIZE
; --i
>= 0; )
6821 register struct import_file
*imp
= pfile
->import_hash_table
[i
];
6824 struct import_file
*next
= imp
->next
;
6829 pfile
->import_hash_table
[i
] = 0;
6832 for (i
= ASSERTION_HASHSIZE
; --i
>= 0; )
6834 while (pfile
->assertion_hashtab
[i
])
6835 delete_assertion (pfile
->assertion_hashtab
[i
]);
6838 cpp_hash_cleanup (pfile
);
6842 do_assert (pfile
, keyword
, buf
, limit
)
6844 struct directive
*keyword ATTRIBUTE_UNUSED
;
6845 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
6847 long symstart
; /* remember where symbol name starts */
6849 int sym_length
; /* and how long it is */
6850 struct arglist
*tokens
= NULL
;
6852 if (CPP_PEDANTIC (pfile
) && CPP_OPTIONS (pfile
)->done_initializing
6853 && !CPP_BUFFER (pfile
)->system_header_p
)
6854 cpp_pedwarn (pfile
, "ANSI C does not allow `#assert'");
6856 cpp_skip_hspace (pfile
);
6857 symstart
= CPP_WRITTEN (pfile
); /* remember where it starts */
6858 parse_name (pfile
, GETC());
6859 sym_length
= check_macro_name (pfile
, pfile
->token_buffer
+ symstart
,
6862 cpp_skip_hspace (pfile
);
6863 if (PEEKC() != '(') {
6864 cpp_error (pfile
, "missing token-sequence in `#assert'");
6870 tokens
= read_token_list (pfile
, &error_flag
);
6874 cpp_error (pfile
, "empty token-sequence in `#assert'");
6877 cpp_skip_hspace (pfile
);
6879 if (c
!= EOF
&& c
!= '\n')
6880 cpp_pedwarn (pfile
, "junk at end of `#assert'");
6881 skip_rest_of_line (pfile
);
6884 /* If this name isn't already an assertion name, make it one.
6885 Error if it was already in use in some other way. */
6888 ASSERTION_HASHNODE
*hp
;
6889 U_CHAR
*symname
= pfile
->token_buffer
+ symstart
;
6890 int hashcode
= hashf (symname
, sym_length
, ASSERTION_HASHSIZE
);
6891 struct tokenlist_list
*value
6892 = (struct tokenlist_list
*) xmalloc (sizeof (struct tokenlist_list
));
6894 hp
= assertion_lookup (pfile
, symname
, sym_length
, hashcode
);
6896 if (sym_length
== 7 && ! strncmp (symname
, "defined", sym_length
))
6897 cpp_error (pfile
, "`defined' redefined as assertion");
6898 hp
= assertion_install (pfile
, symname
, sym_length
, hashcode
);
6901 /* Add the spec'd token-sequence to the list of such. */
6902 value
->tokens
= tokens
;
6903 value
->next
= hp
->value
;
6906 CPP_SET_WRITTEN (pfile
, symstart
); /* Pop */
6909 CPP_SET_WRITTEN (pfile
, symstart
); /* Pop */
6910 skip_rest_of_line (pfile
);
6915 do_unassert (pfile
, keyword
, buf
, limit
)
6917 struct directive
*keyword ATTRIBUTE_UNUSED
;
6918 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
6920 long symstart
; /* remember where symbol name starts */
6921 int sym_length
; /* and how long it is */
6924 struct arglist
*tokens
= NULL
;
6925 int tokens_specified
= 0;
6927 if (CPP_PEDANTIC (pfile
) && CPP_OPTIONS (pfile
)->done_initializing
6928 && !CPP_BUFFER (pfile
)->system_header_p
)
6929 cpp_pedwarn (pfile
, "ANSI C does not allow `#unassert'");
6931 cpp_skip_hspace (pfile
);
6933 symstart
= CPP_WRITTEN (pfile
); /* remember where it starts */
6934 parse_name (pfile
, GETC());
6935 sym_length
= check_macro_name (pfile
, pfile
->token_buffer
+ symstart
,
6938 cpp_skip_hspace (pfile
);
6939 if (PEEKC() == '(') {
6942 tokens
= read_token_list (pfile
, &error_flag
);
6946 cpp_error (pfile
, "empty token list in `#unassert'");
6950 tokens_specified
= 1;
6953 cpp_skip_hspace (pfile
);
6955 if (c
!= EOF
&& c
!= '\n')
6956 cpp_error (pfile
, "junk at end of `#unassert'");
6957 skip_rest_of_line (pfile
);
6960 ASSERTION_HASHNODE
*hp
;
6961 U_CHAR
*symname
= pfile
->token_buffer
+ symstart
;
6962 int hashcode
= hashf (symname
, sym_length
, ASSERTION_HASHSIZE
);
6963 struct tokenlist_list
*tail
, *prev
;
6965 hp
= assertion_lookup (pfile
, symname
, sym_length
, hashcode
);
6969 /* If no token list was specified, then eliminate this assertion
6971 if (! tokens_specified
)
6972 delete_assertion (hp
);
6974 /* If a list of tokens was given, then delete any matching list. */
6979 struct tokenlist_list
*next
= tail
->next
;
6980 if (compare_token_lists (tail
->tokens
, tokens
)) {
6984 hp
->value
= tail
->next
;
6985 free_token_list (tail
->tokens
);
6995 CPP_SET_WRITTEN (pfile
, symstart
); /* Pop */
6998 CPP_SET_WRITTEN (pfile
, symstart
); /* Pop */
6999 skip_rest_of_line (pfile
);
7003 /* Test whether there is an assertion named NAME
7004 and optionally whether it has an asserted token list TOKENS.
7005 NAME is not null terminated; its length is SYM_LENGTH.
7006 If TOKENS_SPECIFIED is 0, then don't check for any token list. */
7009 check_assertion (pfile
, name
, sym_length
, tokens_specified
, tokens
)
7013 int tokens_specified
;
7014 struct arglist
*tokens
;
7016 ASSERTION_HASHNODE
*hp
;
7017 int hashcode
= hashf (name
, sym_length
, ASSERTION_HASHSIZE
);
7019 if (CPP_PEDANTIC (pfile
) && !CPP_BUFFER (pfile
)->system_header_p
)
7020 cpp_pedwarn (pfile
, "ANSI C does not allow testing assertions");
7022 hp
= assertion_lookup (pfile
, name
, sym_length
, hashcode
);
7024 /* It is not an assertion; just return false. */
7027 /* If no token list was specified, then value is 1. */
7028 if (! tokens_specified
)
7032 struct tokenlist_list
*tail
;
7036 /* If a list of tokens was given,
7037 then succeed if the assertion records a matching list. */
7040 if (compare_token_lists (tail
->tokens
, tokens
))
7045 /* Fail if the assertion has no matching list. */
7050 /* Compare two lists of tokens for equality including order of tokens. */
7053 compare_token_lists (l1
, l2
)
7054 struct arglist
*l1
, *l2
;
7057 if (l1
->length
!= l2
->length
)
7059 if (strncmp (l1
->name
, l2
->name
, l1
->length
))
7065 /* Succeed if both lists end at the same time. */
7070 reverse_token_list (tokens
)
7071 struct arglist
*tokens
;
7073 register struct arglist
*prev
= 0, *this, *next
;
7074 for (this = tokens
; this; this = next
)
7083 /* Read a space-separated list of tokens ending in a close parenthesis.
7084 Return a list of strings, in the order they were written.
7085 (In case of error, return 0 and store -1 in *ERROR_FLAG.) */
7087 static struct arglist
*
7088 read_token_list (pfile
, error_flag
)
7092 struct arglist
*token_ptrs
= 0;
7097 FORWARD (1); /* Skip '(' */
7099 /* Loop over the assertion value tokens. */
7102 struct arglist
*temp
;
7103 long name_written
= CPP_WRITTEN (pfile
);
7106 cpp_skip_hspace (pfile
);
7110 /* Find the end of the token. */
7113 CPP_PUTC (pfile
, c
);
7121 CPP_PUTC (pfile
, c
);
7123 else if (c
== '"' || c
== '\'')
7126 cpp_get_token (pfile
);
7132 while (c
!= EOF
&& ! is_space
[c
] && c
!= '(' && c
!= ')'
7133 && c
!= '"' && c
!= '\'')
7135 CPP_PUTC (pfile
, c
);
7138 if (c
!= EOF
) FORWARD(-1);
7141 length
= CPP_WRITTEN (pfile
) - name_written
;
7142 temp
= (struct arglist
*)
7143 xmalloc (sizeof (struct arglist
) + length
+ 1);
7144 temp
->name
= (U_CHAR
*) (temp
+ 1);
7145 bcopy ((char *) (pfile
->token_buffer
+ name_written
),
7146 (char *) temp
->name
, length
);
7147 temp
->name
[length
] = 0;
7148 temp
->next
= token_ptrs
;
7150 temp
->length
= length
;
7152 CPP_ADJUST_WRITTEN (pfile
, -length
); /* pop */
7154 if (c
== EOF
|| c
== '\n')
7157 "unterminated token sequence following `#' operator");
7162 /* We accumulated the names in reverse order.
7163 Now reverse them to get the proper order. */
7164 return reverse_token_list (token_ptrs
);
7168 free_token_list (tokens
)
7169 struct arglist
*tokens
;
7172 struct arglist
*next
= tokens
->next
;
7173 free (tokens
->name
);
7179 /* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
7180 retrying if necessary. If MAX_READ_LEN is defined, read at most
7181 that bytes at a time. Return a negative value if an error occurs,
7182 otherwise return the actual number of bytes read,
7183 which must be LEN unless end-of-file was reached. */
7186 safe_read (desc
, ptr
, len
)
7191 int left
, rcount
, nchars
;
7197 if (rcount
> MAX_READ_LEN
)
7198 rcount
= MAX_READ_LEN
;
7200 nchars
= read (desc
, ptr
, rcount
);
7218 xcalloc (number
, size
)
7219 unsigned number
, size
;
7221 register unsigned total
= number
* size
;
7222 register char *ptr
= (char *) xmalloc (total
);
7231 unsigned size
= strlen (input
);
7232 char *output
= xmalloc (size
+ 1);
7233 strcpy (output
, input
);
7237 /* Initialize PMARK to remember the current position of PFILE. */
7240 parse_set_mark (pmark
, pfile
)
7241 struct parse_marker
*pmark
;
7244 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
7245 pmark
->next
= pbuf
->marks
;
7246 pbuf
->marks
= pmark
;
7248 pmark
->position
= pbuf
->cur
- pbuf
->buf
;
7251 /* Cleanup PMARK - we no longer need it. */
7254 parse_clear_mark (pmark
)
7255 struct parse_marker
*pmark
;
7257 struct parse_marker
**pp
= &pmark
->buf
->marks
;
7258 for (; ; pp
= &(*pp
)->next
) {
7259 if (*pp
== NULL
) abort ();
7260 if (*pp
== pmark
) break;
7265 /* Backup the current position of PFILE to that saved in PMARK. */
7268 parse_goto_mark (pmark
, pfile
)
7269 struct parse_marker
*pmark
;
7272 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
7273 if (pbuf
!= pmark
->buf
)
7274 cpp_fatal (pfile
, "internal error %s", "parse_goto_mark");
7275 pbuf
->cur
= pbuf
->buf
+ pmark
->position
;
7278 /* Reset PMARK to point to the current position of PFILE. (Same
7279 as parse_clear_mark (PMARK), parse_set_mark (PMARK, PFILE) but faster. */
7282 parse_move_mark (pmark
, pfile
)
7283 struct parse_marker
*pmark
;
7286 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
7287 if (pbuf
!= pmark
->buf
)
7288 cpp_fatal (pfile
, "internal error %s", "parse_move_mark");
7289 pmark
->position
= pbuf
->cur
- pbuf
->buf
;
7293 cpp_read_check_assertion (pfile
)
7296 int name_start
= CPP_WRITTEN (pfile
);
7297 int name_length
, name_written
;
7299 FORWARD (1); /* Skip '#' */
7300 cpp_skip_hspace (pfile
);
7301 parse_name (pfile
, GETC ());
7302 name_written
= CPP_WRITTEN (pfile
);
7303 name_length
= name_written
- name_start
;
7304 cpp_skip_hspace (pfile
);
7305 if (CPP_BUF_PEEK (CPP_BUFFER (pfile
)) == '(')
7308 struct arglist
*token_ptrs
= read_token_list (pfile
, &error_flag
);
7309 result
= check_assertion (pfile
,
7310 pfile
->token_buffer
+ name_start
, name_length
,
7314 result
= check_assertion (pfile
,
7315 pfile
->token_buffer
+ name_start
, name_length
,
7317 CPP_ADJUST_WRITTEN (pfile
, - name_length
); /* pop */
7322 cpp_print_file_and_line (pfile
)
7325 cpp_buffer
*ip
= cpp_file_buffer (pfile
);
7330 cpp_buf_line_and_col (ip
, &line
, &col
);
7331 cpp_file_line_for_message (pfile
, ip
->nominal_fname
,
7332 line
, pfile
->show_column
? col
: -1);
7337 v_cpp_error (pfile
, msg
, ap
)
7342 cpp_print_containing_files (pfile
);
7343 cpp_print_file_and_line (pfile
);
7344 v_cpp_message (pfile
, 1, msg
, ap
);
7348 cpp_error
VPROTO ((cpp_reader
* pfile
, const char *msg
, ...))
7359 pfile
= va_arg (ap
, cpp_reader
*);
7360 msg
= va_arg (ap
, const char *);
7363 v_cpp_error (pfile
, msg
, ap
);
7367 /* Print error message but don't count it. */
7370 v_cpp_warning (pfile
, msg
, ap
)
7375 if (CPP_OPTIONS (pfile
)->inhibit_warnings
)
7378 if (CPP_OPTIONS (pfile
)->warnings_are_errors
)
7381 cpp_print_containing_files (pfile
);
7382 cpp_print_file_and_line (pfile
);
7383 v_cpp_message (pfile
, 0, msg
, ap
);
7387 cpp_warning
VPROTO ((cpp_reader
* pfile
, const char *msg
, ...))
7398 pfile
= va_arg (ap
, cpp_reader
*);
7399 msg
= va_arg (ap
, const char *);
7402 v_cpp_warning (pfile
, msg
, ap
);
7406 /* Print an error message and maybe count it. */
7409 cpp_pedwarn
VPROTO ((cpp_reader
* pfile
, const char *msg
, ...))
7420 pfile
= va_arg (ap
, cpp_reader
*);
7421 msg
= va_arg (ap
, const char *);
7424 if (CPP_OPTIONS (pfile
)->pedantic_errors
)
7425 v_cpp_error (pfile
, msg
, ap
);
7427 v_cpp_warning (pfile
, msg
, ap
);
7432 v_cpp_error_with_line (pfile
, line
, column
, msg
, ap
)
7439 cpp_buffer
*ip
= cpp_file_buffer (pfile
);
7441 cpp_print_containing_files (pfile
);
7444 cpp_file_line_for_message (pfile
, ip
->nominal_fname
, line
, column
);
7446 v_cpp_message (pfile
, 1, msg
, ap
);
7450 cpp_error_with_line
VPROTO ((cpp_reader
* pfile
, int line
, int column
, const char *msg
, ...))
7463 pfile
= va_arg (ap
, cpp_reader
*);
7464 line
= va_arg (ap
, int);
7465 column
= va_arg (ap
, int);
7466 msg
= va_arg (ap
, const char *);
7469 v_cpp_error_with_line(pfile
, line
, column
, msg
, ap
);
7474 v_cpp_warning_with_line (pfile
, line
, column
, msg
, ap
)
7483 if (CPP_OPTIONS (pfile
)->inhibit_warnings
)
7486 if (CPP_OPTIONS (pfile
)->warnings_are_errors
)
7489 cpp_print_containing_files (pfile
);
7491 ip
= cpp_file_buffer (pfile
);
7494 cpp_file_line_for_message (pfile
, ip
->nominal_fname
, line
, column
);
7496 v_cpp_message (pfile
, 0, msg
, ap
);
7501 cpp_warning_with_line
VPROTO ((cpp_reader
* pfile
, int line
, int column
, const char *msg
, ...))
7514 pfile
= va_arg (ap
, cpp_reader
*);
7515 line
= va_arg (ap
, int);
7516 column
= va_arg (ap
, int);
7517 msg
= va_arg (ap
, const char *);
7520 v_cpp_warning_with_line (pfile
, line
, column
, msg
, ap
);
7526 cpp_pedwarn_with_line
VPROTO ((cpp_reader
* pfile
, int line
, int column
, const char *msg
, ...))
7539 pfile
= va_arg (ap
, cpp_reader
*);
7540 line
= va_arg (ap
, int);
7541 column
= va_arg (ap
, int);
7542 msg
= va_arg (ap
, const char *);
7545 if (CPP_OPTIONS (pfile
)->pedantic_errors
)
7546 v_cpp_error_with_line (pfile
, column
, line
, msg
, ap
);
7548 v_cpp_warning_with_line (pfile
, line
, column
, msg
, ap
);
7552 /* Report a warning (or an error if pedantic_errors)
7553 giving specified file name and line number, not current. */
7556 cpp_pedwarn_with_file_and_line
VPROTO ((cpp_reader
*pfile
, char *file
, int line
, const char *msg
, ...))
7569 pfile
= va_arg (ap
, cpp_reader
*);
7570 file
= va_arg (ap
, char *);
7571 line
= va_arg (ap
, int);
7572 msg
= va_arg (ap
, const char *);
7575 if (!CPP_OPTIONS (pfile
)->pedantic_errors
7576 && CPP_OPTIONS (pfile
)->inhibit_warnings
)
7579 cpp_file_line_for_message (pfile
, file
, line
, -1);
7580 v_cpp_message (pfile
, CPP_OPTIONS (pfile
)->pedantic_errors
, msg
, ap
);
7585 #ifndef HAVE_STRERROR
7586 extern int sys_nerr
;
7587 extern char *sys_errlist
[];
7588 #else /* HAVE_STRERROR */
7592 char *strerror (int,...);
7595 /* my_strerror - return the descriptive text associated with an
7599 my_strerror (errnum
)
7605 #ifndef HAVE_STRERROR
7606 result
= (char *) ((errnum
< sys_nerr
) ? sys_errlist
[errnum
] : 0);
7608 result
= strerror (errnum
);
7611 /* VAXCRTL's strerror() takes an optional second argument, which only
7612 matters when the first argument is EVMSERR. However, it's simplest
7613 just to pass it unconditionally. `vaxc$errno' is declared in
7614 <errno.h>, and maintained by the library in parallel with `errno'.
7615 We assume that caller's `errnum' either matches the last setting of
7616 `errno' by the library or else does not have the value `EVMSERR'. */
7618 result
= strerror (errnum
, vaxc$errno
);
7622 result
= "undocumented I/O error";
7627 /* Error including a message from `errno'. */
7630 cpp_error_from_errno (pfile
, name
)
7635 cpp_buffer
*ip
= cpp_file_buffer (pfile
);
7637 cpp_print_containing_files (pfile
);
7640 cpp_file_line_for_message (pfile
, ip
->nominal_fname
, ip
->lineno
, -1);
7642 cpp_message (pfile
, 1, "%s: %s", name
, my_strerror (e
));
7646 cpp_perror_with_name (pfile
, name
)
7650 cpp_message (pfile
, 1, "%s: %s: %s", progname
, name
, my_strerror (errno
));
7654 * No pre-compiled header file support.
7656 * Possibly different enum token codes for each C/C++ token.
7658 * Should clean up remaining directives to that do_XXX functions
7659 * only take two arguments and all have command_reads_line.
7661 * Find and cleanup remaining uses of static variables,
7663 * Support for trigraphs.
7665 * Support -dM flag (dump_all_macros).
7667 * Support for_lint flag.