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
*));
206 static void add_import
PROTO ((cpp_reader
*, int, char *));
207 static void append_include_chain
PROTO ((cpp_reader
*,
208 struct file_name_list
*,
209 struct file_name_list
*));
210 static void make_assertion
PROTO ((cpp_reader
*, char *, U_CHAR
*));
211 static void path_include
PROTO ((cpp_reader
*, char *));
212 static void initialize_builtins
PROTO ((cpp_reader
*));
213 static void initialize_char_syntax
PROTO ((struct cpp_options
*));
215 static void trigraph_pcp ();
217 static int finclude
PROTO ((cpp_reader
*, int, char *,
218 int, struct file_name_list
*));
219 static void validate_else
PROTO ((cpp_reader
*, char *));
220 static int comp_def_part
PROTO ((int, U_CHAR
*, int, U_CHAR
*,
223 extern void fancy_abort ();
225 static int lookup_import
PROTO ((cpp_reader
*, char *,
226 struct file_name_list
*));
227 static int redundant_include_p
PROTO ((cpp_reader
*, char *));
228 static int is_system_include
PROTO ((cpp_reader
*, char *));
229 static struct file_name_map
*read_name_map
PROTO ((cpp_reader
*, char *));
230 static char *read_filename_string
PROTO ((int, FILE *));
231 static int open_include_file
PROTO ((cpp_reader
*, char *,
232 struct file_name_list
*));
233 static int check_macro_name
PROTO ((cpp_reader
*, U_CHAR
*, char *));
234 static int compare_defs
PROTO ((cpp_reader
*,
235 DEFINITION
*, DEFINITION
*));
236 static int compare_token_lists
PROTO ((struct arglist
*,
238 static HOST_WIDE_INT eval_if_expression
PROTO ((cpp_reader
*, U_CHAR
*, int));
239 static int change_newlines
PROTO ((U_CHAR
*, int));
240 static struct arglist
*read_token_list
PROTO ((cpp_reader
*, int *));
241 static void free_token_list
PROTO ((struct arglist
*));
242 static int safe_read
PROTO ((int, char *, int));
243 static void push_macro_expansion
PARAMS ((cpp_reader
*,
244 U_CHAR
*, int, HASHNODE
*));
245 static struct cpp_pending
*nreverse_pending
PARAMS ((struct cpp_pending
*));
246 extern char *xrealloc ();
247 static char *xcalloc
PROTO ((unsigned, unsigned));
248 static char *savestring
PROTO ((char *));
250 static void conditional_skip
PROTO ((cpp_reader
*, int,
251 enum node_type
, U_CHAR
*));
252 static void skip_if_group
PROTO ((cpp_reader
*, int));
253 static int parse_name
PARAMS ((cpp_reader
*, int));
255 /* Last arg to output_line_command. */
256 enum file_change_code
{same_file
, enter_file
, leave_file
};
258 /* External declarations. */
260 extern HOST_WIDE_INT cpp_parse_expr
PARAMS ((cpp_reader
*));
262 extern char *version_string
;
263 extern struct tm
*localtime ();
265 struct file_name_list
267 struct file_name_list
*next
;
269 /* If the following is nonzero, it is a macro name.
270 Don't include the file again if that macro is defined. */
271 U_CHAR
*control_macro
;
272 /* If the following is nonzero, it is a C-language system include
274 int c_system_include_path
;
275 /* Mapping of file names for this directory. */
276 struct file_name_map
*name_map
;
277 /* Non-zero if name_map is valid. */
281 /* If a buffer's dir field is SELF_DIR_DUMMY, it means the file was found
282 via the same directory as the file that #included it. */
283 #define SELF_DIR_DUMMY ((struct file_name_list *) (~0))
285 /* #include "file" looks in source file dir, then stack. */
286 /* #include <file> just looks in the stack. */
287 /* -I directories are added to the end, then the defaults are added. */
289 static struct default_include
{
290 char *fname
; /* The name of the directory. */
291 char *component
; /* The component containing the directory */
292 int cplusplus
; /* Only look here if we're compiling C++. */
293 int cxx_aware
; /* Includes in this directory don't need to
294 be wrapped in extern "C" when compiling
296 } include_defaults_array
[]
297 #ifdef INCLUDE_DEFAULTS
301 /* Pick up GNU C++ specific include files. */
302 { GPLUSPLUS_INCLUDE_DIR
, "G++", 1, 1 },
303 { OLD_GPLUSPLUS_INCLUDE_DIR
, 0, 1, 1 },
305 /* This is the dir for fixincludes. Put it just before
306 the files that we fix. */
307 { GCC_INCLUDE_DIR
, "GCC", 0, 0 },
308 /* For cross-compilation, this dir name is generated
309 automatically in Makefile.in. */
310 { CROSS_INCLUDE_DIR
, "GCC",0, 0 },
311 #ifdef TOOL_INCLUDE_DIR
312 /* This is another place that the target system's headers might be. */
313 { TOOL_INCLUDE_DIR
, "BINUTILS", 0, 1 },
315 #else /* not CROSS_COMPILE */
316 #ifdef LOCAL_INCLUDE_DIR
317 /* This should be /usr/local/include and should come before
318 the fixincludes-fixed header files. */
319 { LOCAL_INCLUDE_DIR
, 0, 0, 1 },
321 #ifdef TOOL_INCLUDE_DIR
322 /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
323 Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
324 { TOOL_INCLUDE_DIR
, "BINUTILS", 0, 1 },
326 /* This is the dir for fixincludes. Put it just before
327 the files that we fix. */
328 { GCC_INCLUDE_DIR
, "GCC", 0, 0 },
329 /* Some systems have an extra dir of include files. */
330 #ifdef SYSTEM_INCLUDE_DIR
331 { SYSTEM_INCLUDE_DIR
, 0, 0, 0 },
333 #ifndef STANDARD_INCLUDE_COMPONENT
334 #define STANDARD_INCLUDE_COMPONENT 0
336 { STANDARD_INCLUDE_DIR
, STANDARD_INCLUDE_COMPONENT
, 0, 0 },
337 #endif /* not CROSS_COMPILE */
340 #endif /* no INCLUDE_DEFAULTS */
342 /* `struct directive' defines one #-directive, including how to handle it. */
345 int length
; /* Length of name */
346 int (*func
) /* Function to handle directive */
347 PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
348 char *name
; /* Name of directive */
349 enum node_type type
; /* Code which describes which directive. */
350 char command_reads_line
; /* One if rest of line is read by func. */
353 /* These functions are declared to return int instead of void since they
354 are going to be placed in a table and some old compilers have trouble with
355 pointers to functions returning void. */
357 static int do_define
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
358 static int do_line
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
359 static int do_include
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
360 static int do_undef
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
361 static int do_error
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
362 static int do_pragma
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
363 static int do_ident
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
364 static int do_if
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
365 static int do_xifdef
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
366 static int do_else
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
367 static int do_elif
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
368 static int do_endif
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
369 #ifdef SCCS_DIRECTIVE
370 static int do_sccs
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
372 static int do_once
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
373 static int do_assert
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
374 static int do_unassert
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
375 static int do_warning
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
377 #define IS_INCLUDE_DIRECTIVE_TYPE(t) \
378 ((int) T_INCLUDE <= (int) (t) && (int) (t) <= (int) T_IMPORT)
380 /* Here is the actual list of #-directives, most-often-used first.
381 The initialize_builtins function assumes #define is the very first. */
383 static struct directive directive_table
[] = {
384 { 6, do_define
, "define", T_DEFINE
},
385 { 5, do_xifdef
, "ifdef", T_IFDEF
, 1},
386 { 6, do_xifdef
, "ifndef", T_IFNDEF
, 1},
387 { 7, do_include
, "include", T_INCLUDE
, 1},
388 { 12, do_include
, "include_next", T_INCLUDE_NEXT
, 1},
389 { 6, do_include
, "import", T_IMPORT
, 1},
390 { 5, do_endif
, "endif", T_ENDIF
, 1},
391 { 4, do_else
, "else", T_ELSE
, 1},
392 { 2, do_if
, "if", T_IF
, 1},
393 { 4, do_elif
, "elif", T_ELIF
, 1},
394 { 5, do_undef
, "undef", T_UNDEF
},
395 { 5, do_error
, "error", T_ERROR
},
396 { 7, do_warning
, "warning", T_WARNING
},
397 { 6, do_pragma
, "pragma", T_PRAGMA
},
398 { 4, do_line
, "line", T_LINE
, 1},
399 { 5, do_ident
, "ident", T_IDENT
, 1},
400 #ifdef SCCS_DIRECTIVE
401 { 4, do_sccs
, "sccs", T_SCCS
},
403 { 6, do_assert
, "assert", T_ASSERT
, 1},
404 { 8, do_unassert
, "unassert", T_UNASSERT
, 1},
405 { -1, 0, "", T_UNUSED
},
408 /* table to tell if char can be part of a C identifier. */
409 U_CHAR is_idchar
[256];
410 /* table to tell if char can be first char of a c identifier. */
411 U_CHAR is_idstart
[256];
412 /* table to tell if c is horizontal space. */
413 U_CHAR is_hor_space
[256];
414 /* table to tell if c is horizontal or vertical space. */
415 static U_CHAR is_space
[256];
417 /* Initialize syntactic classifications of characters. */
420 initialize_char_syntax (opts
)
421 struct cpp_options
*opts
;
426 * Set up is_idchar and is_idstart tables. These should be
427 * faster than saying (is_alpha (c) || c == '_'), etc.
428 * Set up these things before calling any routines tthat
431 for (i
= 'a'; i
<= 'z'; i
++) {
432 is_idchar
[i
- 'a' + 'A'] = 1;
434 is_idstart
[i
- 'a' + 'A'] = 1;
437 for (i
= '0'; i
<= '9'; i
++)
441 is_idchar
['$'] = opts
->dollars_in_ident
;
442 is_idstart
['$'] = opts
->dollars_in_ident
;
444 /* horizontal space table */
445 is_hor_space
[' '] = 1;
446 is_hor_space
['\t'] = 1;
447 is_hor_space
['\v'] = 1;
448 is_hor_space
['\f'] = 1;
449 is_hor_space
['\r'] = 1;
460 /* Place into PFILE a quoted string representing the string SRC.
461 Caller must reserve enough space in pfile->token_buffer. */
464 quote_string (pfile
, src
)
470 CPP_PUTC_Q (pfile
, '\"');
472 switch ((c
= *src
++))
476 CPP_PUTC_Q (pfile
, c
);
479 sprintf ((char *)CPP_PWRITTEN (pfile
), "\\%03o", c
);
480 CPP_ADJUST_WRITTEN (pfile
, 4);
486 CPP_PUTC_Q (pfile
, '\\');
487 CPP_PUTC_Q (pfile
, c
);
491 CPP_PUTC_Q (pfile
, '\"');
492 CPP_NUL_TERMINATE_Q (pfile
);
497 /* Re-allocates PFILE->token_buffer so it will hold at least N more chars. */
500 cpp_grow_buffer (pfile
, n
)
504 long old_written
= CPP_WRITTEN (pfile
);
505 pfile
->token_buffer_size
= n
+ 2 * pfile
->token_buffer_size
;
506 pfile
->token_buffer
= (U_CHAR
*)
507 xrealloc(pfile
->token_buffer
, pfile
->token_buffer_size
);
508 CPP_SET_WRITTEN (pfile
, old_written
);
513 * process a given definition string, for initialization
514 * If STR is just an identifier, define it with value 1.
515 * If STR has anything after the identifier, then it should
516 * be identifier=definition.
520 cpp_define (pfile
, str
)
530 cpp_error (pfile
, "malformed option `-D %s'", str
);
533 while (is_idchar
[*++p
])
537 buf
= (U_CHAR
*) alloca (p
- buf
+ 4);
538 strcpy ((char *)buf
, str
);
539 strcat ((char *)buf
, " 1");
543 cpp_error (pfile
, "malformed option `-D %s'", str
);
549 /* Copy the entire option so we can modify it. */
550 buf
= (U_CHAR
*) alloca (2 * strlen (str
) + 1);
551 strncpy (buf
, str
, p
- str
);
552 /* Change the = to a space. */
554 /* Scan for any backslash-newline and remove it. */
559 if (*p
== '\\' && p
[1] == '\n')
567 do_define (pfile
, NULL
, buf
, buf
+ strlen (buf
));
570 /* Process the string STR as if it appeared as the body of a #assert.
571 OPTION is the option name for which STR was the argument. */
574 make_assertion (pfile
, option
, str
)
581 /* Copy the entire option so we can modify it. */
582 buf
= (U_CHAR
*) alloca (strlen (str
) + 1);
583 strcpy ((char *) buf
, str
);
584 /* Scan for any backslash-newline and remove it. */
588 if (*p
== '\\' && p
[1] == '\n')
597 if (!is_idstart
[*p
]) {
598 cpp_error (pfile
, "malformed option `%s %s'", option
, str
);
601 while (is_idchar
[*++p
])
603 while (*p
== ' ' || *p
== '\t') p
++;
604 if (! (*p
== 0 || *p
== '(')) {
605 cpp_error (pfile
, "malformed option `%s %s'", option
, str
);
609 if (cpp_push_buffer (pfile
, buf
, strlen (buf
)) != NULL
)
611 do_assert (pfile
, NULL
, NULL
, NULL
);
612 cpp_pop_buffer (pfile
);
616 /* Append a chain of `struct file_name_list's
617 to the end of the main include chain.
618 FIRST is the beginning of the chain to append, and LAST is the end. */
621 append_include_chain (pfile
, first
, last
)
623 struct file_name_list
*first
, *last
;
625 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
626 struct file_name_list
*dir
;
631 if (opts
->include
== 0)
632 opts
->include
= first
;
634 opts
->last_include
->next
= first
;
636 if (opts
->first_bracket_include
== 0)
637 opts
->first_bracket_include
= first
;
639 for (dir
= first
; ; dir
= dir
->next
) {
640 int len
= strlen (dir
->fname
) + INCLUDE_LEN_FUDGE
;
641 if (len
> pfile
->max_include_len
)
642 pfile
->max_include_len
= len
;
648 opts
->last_include
= last
;
651 /* Add output to `deps_buffer' for the -M switch.
652 STRING points to the text to be output.
653 SPACER is ':' for targets, ' ' for dependencies, zero for text
654 to be inserted literally. */
657 deps_output (pfile
, string
, spacer
)
662 int size
= strlen (string
);
667 #ifndef MAX_OUTPUT_COLUMNS
668 #define MAX_OUTPUT_COLUMNS 72
671 && pfile
->deps_column
> 0
672 && (pfile
->deps_column
+ size
) > MAX_OUTPUT_COLUMNS
)
674 deps_output (pfile
, " \\\n ", 0);
675 pfile
->deps_column
= 0;
678 if (pfile
->deps_size
+ size
+ 8 > pfile
->deps_allocated_size
)
680 pfile
->deps_allocated_size
= (pfile
->deps_size
+ size
+ 50) * 2;
681 pfile
->deps_buffer
= (char *) xrealloc (pfile
->deps_buffer
,
682 pfile
->deps_allocated_size
);
684 if (spacer
== ' ' && pfile
->deps_column
> 0)
685 pfile
->deps_buffer
[pfile
->deps_size
++] = ' ';
686 bcopy (string
, &pfile
->deps_buffer
[pfile
->deps_size
], size
);
687 pfile
->deps_size
+= size
;
688 pfile
->deps_column
+= size
;
690 pfile
->deps_buffer
[pfile
->deps_size
++] = ':';
691 pfile
->deps_buffer
[pfile
->deps_size
] = 0;
694 /* Given a colon-separated list of file names PATH,
695 add all the names to the search path for include files. */
698 path_include (pfile
, path
)
710 struct file_name_list
*dirtmp
;
712 /* Find the end of this name. */
713 while (*q
!= 0 && *q
!= PATH_SEPARATOR
) q
++;
715 /* An empty name in the path stands for the current directory. */
716 name
= (char *) xmalloc (2);
720 /* Otherwise use the directory that is named. */
721 name
= (char *) xmalloc (q
- p
+ 1);
722 bcopy (p
, name
, q
- p
);
726 dirtmp
= (struct file_name_list
*)
727 xmalloc (sizeof (struct file_name_list
));
728 dirtmp
->next
= 0; /* New one goes on the end */
729 dirtmp
->control_macro
= 0;
730 dirtmp
->c_system_include_path
= 0;
731 dirtmp
->fname
= name
;
732 dirtmp
->got_name_map
= 0;
733 append_include_chain (pfile
, dirtmp
, dirtmp
);
735 /* Advance past this name. */
739 /* Skip the colon. */
745 cpp_options_init (opts
)
748 bzero ((char *) opts
, sizeof *opts
);
749 opts
->in_fname
= NULL
;
750 opts
->out_fname
= NULL
;
752 /* Initialize is_idchar to allow $. */
753 opts
->dollars_in_ident
= 1;
754 initialize_char_syntax (opts
);
756 opts
->no_line_commands
= 0;
757 opts
->no_trigraphs
= 1;
758 opts
->put_out_comments
= 0;
759 opts
->print_include_names
= 0;
760 opts
->dump_macros
= dump_none
;
764 opts
->cplusplus_comments
= 0;
771 opts
->pedantic_errors
= 0;
772 opts
->inhibit_warnings
= 0;
773 opts
->warn_comments
= 0;
774 opts
->warn_import
= 1;
775 opts
->warnings_are_errors
= 0;
779 null_underflow (pfile
)
780 cpp_reader
*pfile ATTRIBUTE_UNUSED
;
786 null_cleanup (pbuf
, pfile
)
787 cpp_buffer
*pbuf ATTRIBUTE_UNUSED
;
788 cpp_reader
*pfile ATTRIBUTE_UNUSED
;
794 macro_cleanup (pbuf
, pfile
)
796 cpp_reader
*pfile ATTRIBUTE_UNUSED
;
798 HASHNODE
*macro
= (HASHNODE
*) pbuf
->data
;
799 if (macro
->type
== T_DISABLED
)
800 macro
->type
= T_MACRO
;
801 if (macro
->type
!= T_MACRO
|| pbuf
->buf
!= macro
->value
.defn
->expansion
)
807 file_cleanup (pbuf
, pfile
)
809 cpp_reader
*pfile ATTRIBUTE_UNUSED
;
819 /* Assuming we have read '/'.
820 If this is the start of a comment (followed by '*' or '/'),
821 skip to the end of the comment, and return ' '.
822 Return EOF if we reached the end of file before the end of the comment.
823 If not the start of a comment, return '/'. */
826 skip_comment (pfile
, linep
)
831 while (PEEKC() == '\\' && PEEKN(1) == '\n')
846 while (c
== '\\' && PEEKC() == '\n')
850 FORWARD(1), c
= GETC();
852 if (prev_c
== '*' && c
== '/')
854 if (c
== '\n' && linep
)
858 else if (PEEKC() == '/' && CPP_OPTIONS (pfile
)->cplusplus_comments
)
865 return ' '; /* Allow // to be terminated by EOF. */
866 while (c
== '\\' && PEEKC() == '\n')
875 /* Don't consider final '\n' to be part of comment. */
885 /* Skip whitespace \-newline and comments. Does not macro-expand. */
888 cpp_skip_hspace (pfile
)
898 if ((c
== '\f' || c
== '\v') && CPP_PEDANTIC (pfile
))
899 cpp_pedwarn (pfile
, "%s in preprocessing directive",
900 c
== '\f' ? "formfeed" : "vertical tab");
906 c
= skip_comment (pfile
, NULL
);
909 if (c
== EOF
|| c
== '/')
912 else if (c
== '\\' && PEEKN(1) == '\n') {
915 else if (c
== '@' && CPP_BUFFER (pfile
)->has_escapes
916 && is_hor_space
[PEEKN(1)])
922 /* Read the rest of the current line.
923 The line is appended to PFILE's output buffer. */
926 copy_rest_of_line (pfile
)
929 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
946 goto scan_directive_token
;
950 if (nextc
== '*' || (opts
->cplusplus_comments
&& nextc
== '/'))
951 goto scan_directive_token
;
955 if (CPP_PEDANTIC (pfile
))
956 cpp_pedwarn (pfile
, "%s in preprocessing directive",
957 c
== '\f' ? "formfeed" : "vertical tab");
963 scan_directive_token
:
965 cpp_get_token (pfile
);
971 CPP_NUL_TERMINATE (pfile
);
975 skip_rest_of_line (pfile
)
978 long old
= CPP_WRITTEN (pfile
);
979 copy_rest_of_line (pfile
);
980 CPP_SET_WRITTEN (pfile
, old
);
983 /* Handle a possible # directive.
984 '#' has already been read. */
987 handle_directive (pfile
)
990 register struct directive
*kt
;
993 U_CHAR
*ident
, *line_end
;
994 long old_written
= CPP_WRITTEN (pfile
);
996 cpp_skip_hspace (pfile
);
999 if (c
>= '0' && c
<= '9')
1001 /* Handle # followed by a line number. */
1002 if (CPP_PEDANTIC (pfile
))
1003 cpp_pedwarn (pfile
, "`#' followed by integer");
1004 do_line (pfile
, NULL
, NULL
, NULL
);
1005 goto done_a_directive
;
1008 /* Now find the directive name. */
1009 CPP_PUTC (pfile
, '#');
1010 parse_name (pfile
, GETC());
1011 ident
= pfile
->token_buffer
+ old_written
+ 1;
1012 ident_length
= CPP_PWRITTEN (pfile
) - ident
;
1013 if (ident_length
== 0 && PEEKC() == '\n')
1015 /* A line of just `#' becomes blank. */
1016 goto done_a_directive
;
1020 if (ident_length
== 0 || !is_idstart
[*ident
]) {
1022 while (is_idchar
[*p
]) {
1023 if (*p
< '0' || *p
> '9')
1027 /* Avoid error for `###' and similar cases unless -pedantic. */
1029 while (*p
== '#' || is_hor_space
[*p
]) p
++;
1031 if (pedantic
&& !lang_asm
)
1032 cpp_warning (pfile
, "invalid preprocessor directive");
1038 cpp_error (pfile
, "invalid preprocessor directive name");
1044 * Decode the keyword and call the appropriate expansion
1045 * routine, after moving the input pointer up to the next line.
1047 for (kt
= directive_table
; ; kt
++) {
1048 if (kt
->length
<= 0)
1049 goto not_a_directive
;
1050 if (kt
->length
== ident_length
&& !strncmp (kt
->name
, ident
, ident_length
))
1054 if (kt
->command_reads_line
)
1058 /* Nonzero means do not delete comments within the directive.
1059 #define needs this when -traditional. */
1060 int comments
= CPP_TRADITIONAL (pfile
) && kt
->type
== T_DEFINE
;
1061 int save_put_out_comments
= CPP_OPTIONS (pfile
)->put_out_comments
;
1062 CPP_OPTIONS (pfile
)->put_out_comments
= comments
;
1063 after_ident
= CPP_WRITTEN (pfile
);
1064 copy_rest_of_line (pfile
);
1065 CPP_OPTIONS (pfile
)->put_out_comments
= save_put_out_comments
;
1068 /* We may want to pass through #define, #pragma, and #include.
1069 Other directives may create output, but we don't want the directive
1070 itself out, so we pop it now. For example conditionals may emit
1071 #failed ... #endfailed stuff. But note that popping the buffer
1072 means the parameters to kt->func may point after pfile->limit
1073 so these parameters are invalid as soon as something gets appended
1074 to the token_buffer. */
1076 line_end
= CPP_PWRITTEN (pfile
);
1077 if (! (kt
->type
== T_DEFINE
1078 || kt
->type
== T_PRAGMA
1079 || (IS_INCLUDE_DIRECTIVE_TYPE (kt
->type
)
1080 && CPP_OPTIONS (pfile
)->dump_includes
)))
1081 CPP_SET_WRITTEN (pfile
, old_written
);
1083 (*kt
->func
) (pfile
, kt
, pfile
->token_buffer
+ after_ident
, line_end
);
1085 if (kt
->type
== T_DEFINE
)
1087 if (CPP_OPTIONS (pfile
)->dump_macros
== dump_names
)
1089 /* Skip "#define". */
1090 U_CHAR
*p
= pfile
->token_buffer
+ old_written
+ 7;
1092 SKIP_WHITE_SPACE (p
);
1093 while (is_idchar
[*p
]) p
++;
1095 CPP_PUTC (pfile
, '\n');
1097 else if (CPP_OPTIONS (pfile
)->dump_macros
!= dump_definitions
)
1098 CPP_SET_WRITTEN (pfile
, old_written
);
1108 /* Pass a directive through to the output file.
1109 BUF points to the contents of the directive, as a contiguous string.
1110 LIMIT points to the first character past the end of the directive.
1111 KEYWORD is the keyword-table entry for the directive. */
1114 pass_thru_directive (buf
, limit
, pfile
, keyword
)
1115 U_CHAR
*buf
, *limit
;
1117 struct directive
*keyword
;
1119 register unsigned keyword_length
= keyword
->length
;
1121 CPP_RESERVE (pfile
, 1 + keyword_length
+ (limit
- buf
));
1122 CPP_PUTC_Q (pfile
, '#');
1123 CPP_PUTS_Q (pfile
, keyword
->name
, keyword_length
);
1124 if (limit
!= buf
&& buf
[0] != ' ')
1125 CPP_PUTC_Q (pfile
, ' ');
1126 CPP_PUTS_Q (pfile
, buf
, limit
- buf
);
1128 CPP_PUTS_Q (pfile
, '\n');
1129 /* Count the line we have just made in the output,
1130 to get in sync properly. */
1135 /* The arglist structure is built by do_define to tell
1136 collect_definition where the argument names begin. That
1137 is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist
1138 would contain pointers to the strings x, y, and z.
1139 Collect_definition would then build a DEFINITION node,
1140 with reflist nodes pointing to the places x, y, and z had
1141 appeared. So the arglist is just convenience data passed
1142 between these two routines. It is not kept around after
1143 the current #define has been processed and entered into the
1147 struct arglist
*next
;
1154 /* Read a replacement list for a macro with parameters.
1155 Build the DEFINITION structure.
1156 Reads characters of text starting at BUF until END.
1157 ARGLIST specifies the formal parameters to look for
1158 in the text of the definition; NARGS is the number of args
1159 in that list, or -1 for a macro name that wants no argument list.
1160 MACRONAME is the macro name itself (so we can avoid recursive expansion)
1161 and NAMELEN is its length in characters.
1163 Note that comments, backslash-newlines, and leading white space
1164 have already been deleted from the argument. */
1167 collect_expansion (pfile
, buf
, limit
, nargs
, arglist
)
1169 U_CHAR
*buf
, *limit
;
1171 struct arglist
*arglist
;
1174 register U_CHAR
*p
, *lastp
, *exp_p
;
1175 struct reflist
*endpat
= NULL
;
1176 /* Pointer to first nonspace after last ## seen. */
1178 /* Pointer to first nonspace after last single-# seen. */
1179 U_CHAR
*stringify
= 0;
1181 int expected_delimiter
= '\0';
1183 /* Scan thru the replacement list, ignoring comments and quoted
1184 strings, picking up on the macro calls. It does a linear search
1185 thru the arg list on every potential symbol. Profiling might say
1186 that something smarter should happen. */
1191 /* Find the beginning of the trailing whitespace. */
1193 while (p
< limit
&& is_space
[limit
[-1]]) limit
--;
1195 /* Allocate space for the text in the macro definition.
1196 Leading and trailing whitespace chars need 2 bytes each.
1197 Each other input char may or may not need 1 byte,
1198 so this is an upper bound. The extra 5 are for invented
1199 leading and trailing newline-marker and final null. */
1200 maxsize
= (sizeof (DEFINITION
)
1202 /* Occurrences of '@' get doubled, so allocate extra space for them. */
1206 defn
= (DEFINITION
*) xcalloc (1, maxsize
);
1208 defn
->nargs
= nargs
;
1209 exp_p
= defn
->expansion
= (U_CHAR
*) defn
+ sizeof (DEFINITION
);
1214 /* Add one initial space escape-marker to prevent accidental
1215 token-pasting (often removed by macroexpand). */
1219 if (limit
- p
>= 2 && p
[0] == '#' && p
[1] == '#') {
1220 cpp_error (pfile
, "`##' at start of macro definition");
1224 /* Process the main body of the definition. */
1226 int skipped_arg
= 0;
1227 register U_CHAR c
= *p
++;
1231 if (!CPP_TRADITIONAL (pfile
)) {
1235 if (expected_delimiter
!= '\0') {
1236 if (c
== expected_delimiter
)
1237 expected_delimiter
= '\0';
1239 expected_delimiter
= c
;
1243 if (p
< limit
&& expected_delimiter
) {
1244 /* In a string, backslash goes through
1245 and makes next char ordinary. */
1251 /* An '@' in a string or character constant stands for itself,
1252 and does not need to be escaped. */
1253 if (!expected_delimiter
)
1258 /* # is ordinary inside a string. */
1259 if (expected_delimiter
)
1261 if (p
< limit
&& *p
== '#') {
1262 /* ##: concatenate preceding and following tokens. */
1263 /* Take out the first #, discard preceding whitespace. */
1265 while (exp_p
> lastp
&& is_hor_space
[exp_p
[-1]])
1267 /* Skip the second #. */
1269 /* Discard following whitespace. */
1270 SKIP_WHITE_SPACE (p
);
1273 cpp_error (pfile
, "`##' at end of macro definition");
1274 } else if (nargs
>= 0) {
1275 /* Single #: stringify following argument ref.
1276 Don't leave the # in the expansion. */
1278 SKIP_WHITE_SPACE (p
);
1279 if (p
== limit
|| ! is_idstart
[*p
]
1280 || (*p
== 'L' && p
+ 1 < limit
&& (p
[1] == '\'' || p
[1] == '"')))
1282 "`#' operator is not followed by a macro argument name");
1289 /* In -traditional mode, recognize arguments inside strings and
1290 character constants, and ignore special properties of #.
1291 Arguments inside strings are considered "stringified", but no
1292 extra quote marks are supplied. */
1296 if (expected_delimiter
!= '\0') {
1297 if (c
== expected_delimiter
)
1298 expected_delimiter
= '\0';
1300 expected_delimiter
= c
;
1304 /* Backslash quotes delimiters and itself, but not macro args. */
1305 if (expected_delimiter
!= 0 && p
< limit
1306 && (*p
== expected_delimiter
|| *p
== '\\')) {
1313 if (expected_delimiter
!= '\0') /* No comments inside strings. */
1316 /* If we find a comment that wasn't removed by handle_directive,
1317 this must be -traditional. So replace the comment with
1321 while (p
< limit
&& !(p
[-2] == '*' && p
[-1] == '/'))
1324 /* Mark this as a concatenation-point, as if it had been ##. */
1332 /* Handle the start of a symbol. */
1333 if (is_idchar
[c
] && nargs
> 0) {
1334 U_CHAR
*id_beg
= p
- 1;
1338 while (p
!= limit
&& is_idchar
[*p
]) p
++;
1339 id_len
= p
- id_beg
;
1342 && ! (id_len
== 1 && c
== 'L' && (*p
== '\'' || *p
== '"'))) {
1343 register struct arglist
*arg
;
1345 for (arg
= arglist
; arg
!= NULL
; arg
= arg
->next
) {
1346 struct reflist
*tpat
;
1348 if (arg
->name
[0] == c
1349 && arg
->length
== id_len
1350 && strncmp (arg
->name
, id_beg
, id_len
) == 0) {
1351 if (expected_delimiter
&& CPP_OPTIONS (pfile
)->warn_stringify
) {
1352 if (CPP_TRADITIONAL (pfile
)) {
1353 cpp_warning (pfile
, "macro argument `%.*s' is stringified.",
1357 "macro arg `%.*s' would be stringified with -traditional.",
1361 /* If ANSI, don't actually substitute inside a string. */
1362 if (!CPP_TRADITIONAL (pfile
) && expected_delimiter
)
1364 /* make a pat node for this arg and append it to the end of
1366 tpat
= (struct reflist
*) xmalloc (sizeof (struct reflist
));
1368 tpat
->raw_before
= concat
== id_beg
;
1369 tpat
->raw_after
= 0;
1370 tpat
->rest_args
= arg
->rest_args
;
1371 tpat
->stringify
= (CPP_TRADITIONAL (pfile
)
1372 ? expected_delimiter
!= '\0'
1373 : stringify
== id_beg
);
1376 defn
->pattern
= tpat
;
1378 endpat
->next
= tpat
;
1381 tpat
->argno
= arg
->argno
;
1382 tpat
->nchars
= exp_p
- lastp
;
1384 register U_CHAR
*p1
= p
;
1385 SKIP_WHITE_SPACE (p1
);
1386 if (p1
+ 2 <= limit
&& p1
[0] == '#' && p1
[1] == '#')
1387 tpat
->raw_after
= 1;
1389 lastp
= exp_p
; /* place to start copying from next time */
1396 /* If this was not a macro arg, copy it into the expansion. */
1397 if (! skipped_arg
) {
1398 register U_CHAR
*lim1
= p
;
1402 if (stringify
== id_beg
)
1404 "`#' operator should be followed by a macro argument name");
1409 if (!CPP_TRADITIONAL (pfile
) && expected_delimiter
== 0)
1411 /* If ANSI, put in a "@ " marker to prevent token pasting.
1412 But not if "inside a string" (which in ANSI mode
1413 happens only for -D option). */
1420 defn
->length
= exp_p
- defn
->expansion
;
1422 /* Crash now if we overrun the allocated size. */
1423 if (defn
->length
+ 1 > maxsize
)
1427 /* This isn't worth the time it takes. */
1428 /* give back excess storage */
1429 defn
->expansion
= (U_CHAR
*) xrealloc (defn
->expansion
, defn
->length
+ 1);
1436 * special extension string that can be added to the last macro argument to
1437 * allow it to absorb the "rest" of the arguments when expanded. Ex:
1438 * #define wow(a, b...) process (b, a, b)
1439 * { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); }
1440 * { wow (one, two); } -> { process (two, one, two); }
1441 * if this "rest_arg" is used with the concat token '##' and if it is not
1442 * supplied then the token attached to with ## will not be outputted. Ex:
1443 * #define wow (a, b...) process (b ## , a, ## b)
1444 * { wow (1, 2); } -> { process (2, 1, 2); }
1445 * { wow (one); } -> { process (one); {
1447 static char rest_extension
[] = "...";
1448 #define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1)
1450 /* Create a DEFINITION node from a #define directive. Arguments are
1451 as for do_define. */
1454 create_definition (buf
, limit
, pfile
, predefinition
)
1455 U_CHAR
*buf
, *limit
;
1459 U_CHAR
*bp
; /* temp ptr into input buffer */
1460 U_CHAR
*symname
; /* remember where symbol name starts */
1461 int sym_length
; /* and how long it is */
1464 char *file
= CPP_BUFFER (pfile
) ? CPP_BUFFER (pfile
)->nominal_fname
: "";
1466 int arglengths
= 0; /* Accumulate lengths of arg names
1467 plus number of args. */
1469 cpp_buf_line_and_col (CPP_BUFFER (pfile
), &line
, &col
);
1473 while (is_hor_space
[*bp
])
1476 symname
= bp
; /* remember where it starts */
1478 sym_length
= check_macro_name (pfile
, bp
, "macro");
1481 /* Lossage will occur if identifiers or control keywords are broken
1482 across lines using backslash. This is not the right place to take
1486 struct arglist
*arg_ptrs
= NULL
;
1489 bp
++; /* skip '(' */
1490 SKIP_WHITE_SPACE (bp
);
1492 /* Loop over macro argument names. */
1493 while (*bp
!= ')') {
1494 struct arglist
*temp
;
1496 temp
= (struct arglist
*) alloca (sizeof (struct arglist
));
1498 temp
->next
= arg_ptrs
;
1499 temp
->argno
= argno
++;
1500 temp
->rest_args
= 0;
1504 cpp_pedwarn (pfile
, "another parameter follows `%s'", rest_extension
);
1506 if (!is_idstart
[*bp
])
1507 cpp_pedwarn (pfile
, "invalid character in macro parameter name");
1509 /* Find the end of the arg name. */
1510 while (is_idchar
[*bp
]) {
1512 /* do we have a "special" rest-args extension here? */
1513 if (limit
- bp
> REST_EXTENSION_LENGTH
1514 && strncmp (rest_extension
, bp
, REST_EXTENSION_LENGTH
) == 0) {
1516 temp
->rest_args
= 1;
1520 temp
->length
= bp
- temp
->name
;
1522 bp
+= REST_EXTENSION_LENGTH
;
1523 arglengths
+= temp
->length
+ 2;
1524 SKIP_WHITE_SPACE (bp
);
1525 if (temp
->length
== 0 || (*bp
!= ',' && *bp
!= ')')) {
1526 cpp_error (pfile
, "badly punctuated parameter list in `#define'");
1531 SKIP_WHITE_SPACE (bp
);
1534 cpp_error (pfile
, "unterminated parameter list in `#define'");
1538 struct arglist
*otemp
;
1540 for (otemp
= temp
->next
; otemp
!= NULL
; otemp
= otemp
->next
)
1541 if (temp
->length
== otemp
->length
1542 && strncmp (temp
->name
, otemp
->name
, temp
->length
) == 0) {
1545 name
= (U_CHAR
*) alloca (temp
->length
+ 1);
1546 (void) strncpy (name
, temp
->name
, temp
->length
);
1547 name
[temp
->length
] = '\0';
1549 "duplicate argument name `%s' in `#define'", name
);
1555 ++bp
; /* skip paren */
1556 SKIP_WHITE_SPACE (bp
);
1557 /* now everything from bp before limit is the definition. */
1558 defn
= collect_expansion (pfile
, bp
, limit
, argno
, arg_ptrs
);
1559 defn
->rest_args
= rest_args
;
1561 /* Now set defn->args.argnames to the result of concatenating
1562 the argument names in reverse order
1563 with comma-space between them. */
1564 defn
->args
.argnames
= (U_CHAR
*) xmalloc (arglengths
+ 1);
1566 struct arglist
*temp
;
1568 for (temp
= arg_ptrs
; temp
; temp
= temp
->next
) {
1569 bcopy (temp
->name
, &defn
->args
.argnames
[i
], temp
->length
);
1571 if (temp
->next
!= 0) {
1572 defn
->args
.argnames
[i
++] = ',';
1573 defn
->args
.argnames
[i
++] = ' ';
1576 defn
->args
.argnames
[i
] = 0;
1579 /* Simple expansion or empty definition. */
1583 if (is_hor_space
[*bp
]) {
1585 SKIP_WHITE_SPACE (bp
);
1588 case '!': case '"': case '#': case '%': case '&': case '\'':
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 '~':
1593 cpp_warning (pfile
, "missing white space after `#define %.*s'",
1594 sym_length
, symname
);
1598 cpp_pedwarn (pfile
, "missing white space after `#define %.*s'",
1599 sym_length
, symname
);
1604 /* now everything from bp before limit is the definition. */
1605 defn
= collect_expansion (pfile
, bp
, limit
, -1, NULL_PTR
);
1606 defn
->args
.argnames
= (U_CHAR
*) "";
1612 /* OP is null if this is a predefinition */
1613 defn
->predefined
= predefinition
;
1615 mdef
.symnam
= symname
;
1616 mdef
.symlen
= sym_length
;
1625 /* Check a purported macro name SYMNAME, and yield its length.
1626 USAGE is the kind of name this is intended for. */
1629 check_macro_name (pfile
, symname
, usage
)
1637 for (p
= symname
; is_idchar
[*p
]; p
++)
1639 sym_length
= p
- symname
;
1641 || (sym_length
== 1 && *symname
== 'L' && (*p
== '\'' || *p
== '"')))
1642 cpp_error (pfile
, "invalid %s name", usage
);
1643 else if (!is_idstart
[*symname
]) {
1644 U_CHAR
*msg
; /* what pain... */
1645 msg
= (U_CHAR
*) alloca (sym_length
+ 1);
1646 bcopy (symname
, msg
, sym_length
);
1647 msg
[sym_length
] = 0;
1648 cpp_error (pfile
, "invalid %s name `%s'", usage
, msg
);
1650 if (! strncmp (symname
, "defined", 7) && sym_length
== 7)
1651 cpp_error (pfile
, "invalid %s name `defined'", usage
);
1656 /* Return zero if two DEFINITIONs are isomorphic. */
1659 compare_defs (pfile
, d1
, d2
)
1661 DEFINITION
*d1
, *d2
;
1663 register struct reflist
*a1
, *a2
;
1664 register U_CHAR
*p1
= d1
->expansion
;
1665 register U_CHAR
*p2
= d2
->expansion
;
1668 if (d1
->nargs
!= d2
->nargs
)
1670 if (CPP_PEDANTIC (pfile
)
1671 && strcmp ((char *)d1
->args
.argnames
, (char *)d2
->args
.argnames
))
1673 for (a1
= d1
->pattern
, a2
= d2
->pattern
; a1
&& a2
;
1674 a1
= a1
->next
, a2
= a2
->next
) {
1675 if (!((a1
->nchars
== a2
->nchars
&& ! strncmp (p1
, p2
, a1
->nchars
))
1676 || ! comp_def_part (first
, p1
, a1
->nchars
, p2
, a2
->nchars
, 0))
1677 || a1
->argno
!= a2
->argno
1678 || a1
->stringify
!= a2
->stringify
1679 || a1
->raw_before
!= a2
->raw_before
1680 || a1
->raw_after
!= a2
->raw_after
)
1688 if (comp_def_part (first
, p1
, d1
->length
- (p1
- d1
->expansion
),
1689 p2
, d2
->length
- (p2
- d2
->expansion
), 1))
1694 /* Return 1 if two parts of two macro definitions are effectively different.
1695 One of the parts starts at BEG1 and has LEN1 chars;
1696 the other has LEN2 chars at BEG2.
1697 Any sequence of whitespace matches any other sequence of whitespace.
1698 FIRST means these parts are the first of a macro definition;
1699 so ignore leading whitespace entirely.
1700 LAST means these parts are the last of a macro definition;
1701 so ignore trailing whitespace entirely. */
1704 comp_def_part (first
, beg1
, len1
, beg2
, len2
, last
)
1706 U_CHAR
*beg1
, *beg2
;
1710 register U_CHAR
*end1
= beg1
+ len1
;
1711 register U_CHAR
*end2
= beg2
+ len2
;
1713 while (beg1
!= end1
&& is_space
[*beg1
]) beg1
++;
1714 while (beg2
!= end2
&& is_space
[*beg2
]) beg2
++;
1717 while (beg1
!= end1
&& is_space
[end1
[-1]]) end1
--;
1718 while (beg2
!= end2
&& is_space
[end2
[-1]]) end2
--;
1720 while (beg1
!= end1
&& beg2
!= end2
) {
1721 if (is_space
[*beg1
] && is_space
[*beg2
]) {
1722 while (beg1
!= end1
&& is_space
[*beg1
]) beg1
++;
1723 while (beg2
!= end2
&& is_space
[*beg2
]) beg2
++;
1724 } else if (*beg1
== *beg2
) {
1728 return (beg1
!= end1
) || (beg2
!= end2
);
1731 /* Process a #define command.
1732 BUF points to the contents of the #define command, as a contiguous string.
1733 LIMIT points to the first character past the end of the definition.
1734 KEYWORD is the keyword-table entry for #define,
1735 or NULL for a "predefined" macro. */
1738 do_define (pfile
, keyword
, buf
, limit
)
1740 struct directive
*keyword
;
1741 U_CHAR
*buf
, *limit
;
1748 /* If this is a precompiler run (with -pcp) pass thru #define commands. */
1749 if (pcp_outfile
&& keyword
)
1750 pass_thru_directive (buf
, limit
, pfile
, keyword
);
1753 mdef
= create_definition (buf
, limit
, pfile
, keyword
== NULL
);
1757 hashcode
= hashf (mdef
.symnam
, mdef
.symlen
, HASHSIZE
);
1759 if ((hp
= cpp_lookup (pfile
, mdef
.symnam
, mdef
.symlen
, hashcode
)) != NULL
)
1762 /* Redefining a precompiled key is ok. */
1763 if (hp
->type
== T_PCSTRING
)
1765 /* Redefining a macro is ok if the definitions are the same. */
1766 else if (hp
->type
== T_MACRO
)
1767 ok
= ! compare_defs (pfile
, mdef
.defn
, hp
->value
.defn
);
1768 /* Redefining a constant is ok with -D. */
1769 else if (hp
->type
== T_CONST
)
1770 ok
= ! CPP_OPTIONS (pfile
)->done_initializing
;
1771 /* Print the warning if it's not ok. */
1774 U_CHAR
*msg
; /* what pain... */
1776 /* If we are passing through #define and #undef directives, do
1777 that for this re-definition now. */
1778 if (CPP_OPTIONS (pfile
)->debug_output
&& keyword
)
1779 pass_thru_directive (buf
, limit
, pfile
, keyword
);
1781 msg
= (U_CHAR
*) alloca (mdef
.symlen
+ 22);
1783 bcopy (mdef
.symnam
, msg
+ 1, mdef
.symlen
);
1784 strcpy ((char *) (msg
+ mdef
.symlen
+ 1), "' redefined");
1785 cpp_pedwarn (pfile
, msg
);
1786 if (hp
->type
== T_MACRO
)
1787 cpp_pedwarn_with_file_and_line (pfile
, hp
->value
.defn
->file
, hp
->value
.defn
->line
,
1788 "this is the location of the previous definition");
1790 /* Replace the old definition. */
1792 hp
->value
.defn
= mdef
.defn
;
1796 /* If we are passing through #define and #undef directives, do
1797 that for this new definition now. */
1798 if (CPP_OPTIONS (pfile
)->debug_output
&& keyword
)
1799 pass_thru_directive (buf
, limit
, pfile
, keyword
);
1800 install (mdef
.symnam
, mdef
.symlen
, T_MACRO
, 0,
1801 (char *) mdef
.defn
, hashcode
);
1811 /* This structure represents one parsed argument in a macro call.
1812 `raw' points to the argument text as written (`raw_length' is its length).
1813 `expanded' points to the argument's macro-expansion
1814 (its length is `expand_length').
1815 `stringified_length' is the length the argument would have
1817 `use_count' is the number of times this macro arg is substituted
1818 into the macro. If the actual use count exceeds 10,
1819 the value stored is 10. */
1821 /* raw and expanded are relative to ARG_BASE */
1822 #define ARG_BASE ((pfile)->token_buffer)
1825 /* Strings relative to pfile->token_buffer */
1826 long raw
, expanded
, stringified
;
1827 int raw_length
, expand_length
;
1828 int stringified_length
;
1833 /* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack.
1834 If BUFFER != NULL, then use the LENGTH characters in BUFFER
1835 as the new input buffer.
1836 Return the new buffer, or NULL on failure. */
1839 cpp_push_buffer (pfile
, buffer
, length
)
1844 register cpp_buffer
*buf
= CPP_BUFFER (pfile
);
1845 if (buf
== pfile
->buffer_stack
)
1847 cpp_fatal (pfile
, "%s: macro or `#include' recursion too deep",
1852 bzero ((char *) buf
, sizeof (cpp_buffer
));
1853 CPP_BUFFER (pfile
) = buf
;
1854 buf
->if_stack
= pfile
->if_stack
;
1855 buf
->cleanup
= null_cleanup
;
1856 buf
->underflow
= null_underflow
;
1857 buf
->buf
= buf
->cur
= buffer
;
1858 buf
->alimit
= buf
->rlimit
= buffer
+ length
;
1864 cpp_pop_buffer (pfile
)
1867 cpp_buffer
*buf
= CPP_BUFFER (pfile
);
1868 (*buf
->cleanup
) (buf
, pfile
);
1869 return ++CPP_BUFFER (pfile
);
1872 /* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer.
1873 Pop the buffer when done. */
1876 cpp_scan_buffer (pfile
)
1879 cpp_buffer
*buffer
= CPP_BUFFER (pfile
);
1882 enum cpp_token token
= cpp_get_token (pfile
);
1883 if (token
== CPP_EOF
) /* Should not happen ... */
1885 if (token
== CPP_POP
&& CPP_BUFFER (pfile
) == buffer
)
1887 cpp_pop_buffer (pfile
);
1894 * Rescan a string (which may have escape marks) into pfile's buffer.
1895 * Place the result in pfile->token_buffer.
1897 * The input is copied before it is scanned, so it is safe to pass
1898 * it something from the token_buffer that will get overwritten
1899 * (because it follows CPP_WRITTEN). This is used by do_include.
1903 cpp_expand_to_buffer (pfile
, buf
, length
)
1908 register cpp_buffer
*ip
;
1912 U_CHAR
*limit
= buf
+ length
;
1915 int odepth
= indepth
;
1921 /* Set up the input on the input stack. */
1923 buf1
= (U_CHAR
*) alloca (length
+ 1);
1925 register U_CHAR
*p1
= buf
;
1926 register U_CHAR
*p2
= buf1
;
1933 ip
= cpp_push_buffer (pfile
, buf1
, length
);
1936 ip
->has_escapes
= 1;
1938 ip
->lineno
= obuf
.lineno
= 1;
1941 /* Scan the input, create the output. */
1942 cpp_scan_buffer (pfile
);
1945 if (indepth
!= odepth
)
1949 CPP_NUL_TERMINATE (pfile
);
1954 adjust_position (buf
, limit
, linep
, colp
)
1964 (*linep
)++, (*colp
) = 1;
1970 /* Move line_base forward, updating lineno and colno. */
1973 update_position (pbuf
)
1974 register cpp_buffer
*pbuf
;
1976 unsigned char *old_pos
= pbuf
->buf
+ pbuf
->line_base
;
1977 unsigned char *new_pos
= pbuf
->cur
;
1978 register struct parse_marker
*mark
;
1979 for (mark
= pbuf
->marks
; mark
!= NULL
; mark
= mark
->next
)
1981 if (pbuf
->buf
+ mark
->position
< new_pos
)
1982 new_pos
= pbuf
->buf
+ mark
->position
;
1984 pbuf
->line_base
+= new_pos
- old_pos
;
1985 adjust_position (old_pos
, new_pos
, &pbuf
->lineno
, &pbuf
->colno
);
1989 cpp_buf_line_and_col (pbuf
, linep
, colp
)
1990 register cpp_buffer
*pbuf
;
1998 *linep
= pbuf
->lineno
;
1999 *colp
= pbuf
->colno
;
2000 adjust_position (pbuf
->buf
+ pbuf
->line_base
, pbuf
->cur
, linep
, colp
);
2009 /* Return the cpp_buffer that corresponds to a file (not a macro). */
2012 cpp_file_buffer (pfile
)
2015 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
2017 for ( ; ip
!= CPP_NULL_BUFFER (pfile
); ip
= CPP_PREV_BUFFER (ip
))
2018 if (ip
->fname
!= NULL
)
2024 count_newlines (buf
, limit
)
2025 register U_CHAR
*buf
;
2026 register U_CHAR
*limit
;
2028 register long count
= 0;
2039 * write out a #line command, for instance, after an #include file.
2040 * If CONDITIONAL is nonzero, we can omit the #line if it would
2041 * appear to be a no-op, and we can output a few newlines instead
2042 * if we want to increase the line number by a small amount.
2043 * FILE_CHANGE says whether we are entering a file, leaving, or neither.
2047 output_line_command (pfile
, conditional
, file_change
)
2050 enum file_change_code file_change
;
2053 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
2055 if (ip
->fname
== NULL
)
2058 update_position (ip
);
2060 if (CPP_OPTIONS (pfile
)->no_line_commands
2061 || CPP_OPTIONS (pfile
)->no_output
)
2064 line
= CPP_BUFFER (pfile
)->lineno
;
2065 col
= CPP_BUFFER (pfile
)->colno
;
2066 adjust_position (CPP_LINE_BASE (ip
), ip
->cur
, &line
, &col
);
2068 if (CPP_OPTIONS (pfile
)->no_line_commands
)
2072 if (line
== pfile
->lineno
)
2075 /* If the inherited line number is a little too small,
2076 output some newlines instead of a #line command. */
2077 if (line
> pfile
->lineno
&& line
< pfile
->lineno
+ 8) {
2078 CPP_RESERVE (pfile
, 20);
2079 while (line
> pfile
->lineno
) {
2080 CPP_PUTC_Q (pfile
, '\n');
2088 /* Don't output a line number of 0 if we can help it. */
2089 if (ip
->lineno
== 0 && ip
->bufp
- ip
->buf
< ip
->length
2090 && *ip
->bufp
== '\n') {
2096 CPP_RESERVE (pfile
, 4 * strlen (ip
->nominal_fname
) + 50);
2098 #ifdef OUTPUT_LINE_COMMANDS
2099 static char sharp_line
[] = "#line ";
2101 static char sharp_line
[] = "# ";
2103 CPP_PUTS_Q (pfile
, sharp_line
, sizeof(sharp_line
)-1);
2106 sprintf ((char *) CPP_PWRITTEN (pfile
), "%ld ", line
);
2107 CPP_ADJUST_WRITTEN (pfile
, strlen (CPP_PWRITTEN (pfile
)));
2109 quote_string (pfile
, ip
->nominal_fname
);
2110 if (file_change
!= same_file
) {
2111 CPP_PUTC_Q (pfile
, ' ');
2112 CPP_PUTC_Q (pfile
, file_change
== enter_file
? '1' : '2');
2114 /* Tell cc1 if following text comes from a system header file. */
2115 if (ip
->system_header_p
) {
2116 CPP_PUTC_Q (pfile
, ' ');
2117 CPP_PUTC_Q (pfile
, '3');
2119 #ifndef NO_IMPLICIT_EXTERN_C
2120 /* Tell cc1plus if following text should be treated as C. */
2121 if (ip
->system_header_p
== 2 && CPP_OPTIONS (pfile
)->cplusplus
) {
2122 CPP_PUTC_Q (pfile
, ' ');
2123 CPP_PUTC_Q (pfile
, '4');
2126 CPP_PUTC_Q (pfile
, '\n');
2127 pfile
->lineno
= line
;
2131 * Parse a macro argument and append the info on PFILE's token_buffer.
2132 * REST_ARGS means to absorb the rest of the args.
2133 * Return nonzero to indicate a syntax error.
2136 static enum cpp_token
2137 macarg (pfile
, rest_args
)
2142 enum cpp_token token
;
2143 char save_put_out_comments
= CPP_OPTIONS (pfile
)->put_out_comments
;
2144 CPP_OPTIONS (pfile
)->put_out_comments
= 0;
2146 /* Try to parse as much of the argument as exists at this
2147 input stack level. */
2148 pfile
->no_macro_expand
++;
2151 token
= cpp_get_token (pfile
);
2157 /* If we've hit end of file, it's an error (reported by caller).
2158 Ditto if it's the end of cpp_expand_to_buffer text.
2159 If we've hit end of macro, just continue. */
2160 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile
)))
2171 /* if we've returned to lowest level and
2172 we aren't absorbing all args */
2173 if (paren
== 0 && rest_args
== 0)
2177 /* Remove ',' or ')' from argument buffer. */
2178 CPP_ADJUST_WRITTEN (pfile
, -1);
2185 CPP_OPTIONS (pfile
)->put_out_comments
= save_put_out_comments
;
2186 pfile
->no_macro_expand
--;
2191 /* Turn newlines to spaces in the string of length LENGTH at START,
2192 except inside of string constants.
2193 The string is copied into itself with its beginning staying fixed. */
2196 change_newlines (start
, length
)
2200 register U_CHAR
*ibp
;
2201 register U_CHAR
*obp
;
2202 register U_CHAR
*limit
;
2206 limit
= start
+ length
;
2209 while (ibp
< limit
) {
2210 *obp
++ = c
= *ibp
++;
2215 /* Notice and skip strings, so that we don't delete newlines in them. */
2218 while (ibp
< limit
) {
2219 *obp
++ = c
= *ibp
++;
2222 if (c
== '\n' && quotec
== '\'')
2238 if (!pfile
->timebuf
) {
2239 time_t t
= time ((time_t *) 0);
2240 pfile
->timebuf
= localtime (&t
);
2242 return pfile
->timebuf
;
2245 static char *monthnames
[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
2246 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
2250 * expand things like __FILE__. Place the expansion into the output
2251 * buffer *without* rescanning.
2255 special_symbol (hp
, pfile
)
2262 cpp_buffer
*ip
= NULL
;
2265 int paren
= 0; /* For special `defined' keyword */
2268 if (pcp_outfile
&& pcp_inside_if
2269 && hp
->type
!= T_SPEC_DEFINED
&& hp
->type
!= T_CONST
)
2271 "Predefined macro `%s' used inside `#if' during precompilation",
2275 for (ip
= CPP_BUFFER (pfile
); ; ip
= CPP_PREV_BUFFER (ip
))
2277 if (ip
== CPP_NULL_BUFFER (pfile
))
2279 cpp_error (pfile
, "cccp error: not in any file?!");
2280 return; /* the show must go on */
2282 if (ip
->fname
!= NULL
)
2292 if (hp
->type
== T_BASE_FILE
)
2294 while (CPP_PREV_BUFFER (ip
) != CPP_NULL_BUFFER (pfile
))
2295 ip
= CPP_PREV_BUFFER (ip
);
2297 string
= ip
->nominal_fname
;
2301 CPP_RESERVE (pfile
, 3 + 4 * strlen (string
));
2302 quote_string (pfile
, string
);
2306 case T_INCLUDE_LEVEL
:
2308 ip
= CPP_BUFFER (pfile
);
2309 for (; ip
!= CPP_NULL_BUFFER (pfile
); ip
= CPP_PREV_BUFFER (ip
))
2310 if (ip
->fname
!= NULL
)
2313 buf
= (char *) alloca (8); /* Eight bytes ought to be more than enough */
2314 sprintf (buf
, "%d", true_indepth
- 1);
2318 buf
= (char *) alloca (3 + strlen (version_string
));
2319 sprintf (buf
, "\"%s\"", version_string
);
2322 #ifndef NO_BUILTIN_SIZE_TYPE
2328 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2329 case T_PTRDIFF_TYPE
:
2335 buf
= CPP_WCHAR_TYPE (pfile
);
2338 case T_USER_LABEL_PREFIX_TYPE
:
2339 buf
= USER_LABEL_PREFIX
;
2342 case T_REGISTER_PREFIX_TYPE
:
2343 buf
= REGISTER_PREFIX
;
2347 buf
= (char *) alloca (4 * sizeof (int));
2348 sprintf (buf
, "%d", hp
->value
.ival
);
2349 #ifdef STDC_0_IN_SYSTEM_HEADERS
2350 if (ip
->system_header_p
2351 && hp
->length
== 8 && bcmp (hp
->name
, "__STDC__", 8) == 0
2352 && ! cpp_lookup (pfile
, (U_CHAR
*) "__STRICT_ANSI__", -1, -1))
2356 if (pcp_inside_if
&& pcp_outfile
)
2357 /* Output a precondition for this macro use */
2358 fprintf (pcp_outfile
, "#define %s %d\n", hp
->name
, hp
->value
.ival
);
2364 long line
= ip
->lineno
;
2365 long col
= ip
->colno
;
2366 adjust_position (CPP_LINE_BASE (ip
), ip
->cur
, &line
, &col
);
2368 buf
= (char *) alloca (10);
2369 sprintf (buf
, "%ld", line
);
2375 buf
= (char *) alloca (20);
2376 timebuf
= timestamp (pfile
);
2377 if (hp
->type
== T_DATE
)
2378 sprintf (buf
, "\"%s %2d %4d\"", monthnames
[timebuf
->tm_mon
],
2379 timebuf
->tm_mday
, timebuf
->tm_year
+ 1900);
2381 sprintf (buf
, "\"%02d:%02d:%02d\"", timebuf
->tm_hour
, timebuf
->tm_min
,
2385 case T_SPEC_DEFINED
:
2386 buf
= " 0 "; /* Assume symbol is not defined */
2387 ip
= CPP_BUFFER (pfile
);
2388 SKIP_WHITE_SPACE (ip
->cur
);
2389 if (*ip
->cur
== '(')
2392 ip
->cur
++; /* Skip over the paren */
2393 SKIP_WHITE_SPACE (ip
->cur
);
2396 if (!is_idstart
[*ip
->cur
])
2398 if (ip
->cur
[0] == 'L' && (ip
->cur
[1] == '\'' || ip
->cur
[1] == '"'))
2400 if ((hp
= cpp_lookup (pfile
, ip
->cur
, -1, -1)))
2403 if (pcp_outfile
&& pcp_inside_if
2404 && (hp
->type
== T_CONST
2405 || (hp
->type
== T_MACRO
&& hp
->value
.defn
->predefined
)))
2406 /* Output a precondition for this macro use. */
2407 fprintf (pcp_outfile
, "#define %s\n", hp
->name
);
2413 if (pcp_outfile
&& pcp_inside_if
)
2415 /* Output a precondition for this macro use */
2416 U_CHAR
*cp
= ip
->bufp
;
2417 fprintf (pcp_outfile
, "#undef ");
2418 while (is_idchar
[*cp
]) /* Ick! */
2419 fputc (*cp
++, pcp_outfile
);
2420 putc ('\n', pcp_outfile
);
2423 while (is_idchar
[*ip
->cur
])
2425 SKIP_WHITE_SPACE (ip
->cur
);
2428 if (*ip
->cur
!= ')')
2436 cpp_error (pfile
, "`defined' without an identifier");
2440 cpp_error (pfile
, "cccp error: invalid special hash type"); /* time for gdb */
2444 CPP_RESERVE (pfile
, len
+ 1);
2445 CPP_PUTS_Q (pfile
, buf
, len
);
2446 CPP_NUL_TERMINATE_Q (pfile
);
2451 /* Write out a #define command for the special named MACRO_NAME
2452 to PFILE's token_buffer. */
2455 dump_special_to_buffer (pfile
, macro_name
)
2459 static char define_directive
[] = "#define ";
2460 int macro_name_length
= strlen (macro_name
);
2461 output_line_command (pfile
, 0, same_file
);
2462 CPP_RESERVE (pfile
, sizeof(define_directive
) + macro_name_length
);
2463 CPP_PUTS_Q (pfile
, define_directive
, sizeof(define_directive
)-1);
2464 CPP_PUTS_Q (pfile
, macro_name
, macro_name_length
);
2465 CPP_PUTC_Q (pfile
, ' ');
2466 cpp_expand_to_buffer (pfile
, macro_name
, macro_name_length
);
2467 CPP_PUTC (pfile
, '\n');
2470 /* Initialize the built-in macros. */
2473 initialize_builtins (pfile
)
2476 install ((U_CHAR
*)"__LINE__", -1, T_SPECLINE
, 0, 0, -1);
2477 install ((U_CHAR
*)"__DATE__", -1, T_DATE
, 0, 0, -1);
2478 install ((U_CHAR
*)"__FILE__", -1, T_FILE
, 0, 0, -1);
2479 install ((U_CHAR
*)"__BASE_FILE__", -1, T_BASE_FILE
, 0, 0, -1);
2480 install ((U_CHAR
*)"__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL
, 0, 0, -1);
2481 install ((U_CHAR
*)"__VERSION__", -1, T_VERSION
, 0, 0, -1);
2482 #ifndef NO_BUILTIN_SIZE_TYPE
2483 install ((U_CHAR
*)"__SIZE_TYPE__", -1, T_SIZE_TYPE
, 0, 0, -1);
2485 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2486 install ((U_CHAR
*)"__PTRDIFF_TYPE__ ", -1, T_PTRDIFF_TYPE
, 0, 0, -1);
2488 install ((U_CHAR
*)"__WCHAR_TYPE__", -1, T_WCHAR_TYPE
, 0, 0, -1);
2489 install ((U_CHAR
*)"__USER_LABEL_PREFIX__", -1, T_USER_LABEL_PREFIX_TYPE
, 0, 0, -1);
2490 install ((U_CHAR
*)"__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE
, 0, 0, -1);
2491 install ((U_CHAR
*)"__TIME__", -1, T_TIME
, 0, 0, -1);
2492 if (!CPP_TRADITIONAL (pfile
))
2493 install ((U_CHAR
*)"__STDC__", -1, T_CONST
, STDC_VALUE
, 0, -1);
2494 if (CPP_OPTIONS (pfile
)->objc
)
2495 install ((U_CHAR
*)"__OBJC__", -1, T_CONST
, 1, 0, -1);
2496 /* This is supplied using a -D by the compiler driver
2497 so that it is present only when truly compiling with GNU C. */
2498 /* install ("__GNUC__", -1, T_CONST, 2, 0, -1); */
2500 if (CPP_OPTIONS (pfile
)->debug_output
)
2502 dump_special_to_buffer (pfile
, "__BASE_FILE__");
2503 dump_special_to_buffer (pfile
, "__VERSION__");
2504 #ifndef NO_BUILTIN_SIZE_TYPE
2505 dump_special_to_buffer (pfile
, "__SIZE_TYPE__");
2507 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2508 dump_special_to_buffer (pfile
, "__PTRDIFF_TYPE__");
2510 dump_special_to_buffer (pfile
, "__WCHAR_TYPE__");
2511 dump_special_to_buffer (pfile
, "__DATE__");
2512 dump_special_to_buffer (pfile
, "__TIME__");
2513 if (!CPP_TRADITIONAL (pfile
))
2514 dump_special_to_buffer (pfile
, "__STDC__");
2515 if (CPP_OPTIONS (pfile
)->objc
)
2516 dump_special_to_buffer (pfile
, "__OBJC__");
2520 /* Return 1 iff a token ending in C1 followed directly by a token C2
2521 could cause mis-tokenization. */
2524 unsafe_chars (c1
, c2
)
2530 if (c2
== c1
|| c2
== '=')
2534 case '0': case '1': case '2': case '3': case '4':
2535 case '5': case '6': case '7': case '8': case '9':
2536 case 'e': case 'E': case 'p': case 'P':
2537 if (c2
== '-' || c2
== '+')
2538 return 1; /* could extend a pre-processing number */
2541 if (c2
== '\'' || c2
== '\"')
2542 return 1; /* Could turn into L"xxx" or L'xxx'. */
2546 case 'a': case 'b': case 'c': case 'd': case 'f':
2547 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
2548 case 'm': case 'n': case 'o': case 'q': case 'r':
2549 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
2551 case 'A': case 'B': case 'C': case 'D': case 'F':
2552 case 'G': case 'H': case 'I': case 'J': case 'K':
2553 case 'M': case 'N': case 'O': case 'Q': case 'R':
2554 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
2556 /* We're in the middle of either a name or a pre-processing number. */
2557 return (is_idchar
[c2
] || c2
== '.');
2558 case '<': case '>': case '!': case '%': case '#': case ':':
2559 case '^': case '&': case '|': case '*': case '/': case '=':
2560 return (c2
== c1
|| c2
== '=');
2565 /* Expand a macro call.
2566 HP points to the symbol that is the macro being called.
2567 Put the result of expansion onto the input stack
2568 so that subsequent input by our caller will use it.
2570 If macro wants arguments, caller has already verified that
2571 an argument list follows; arguments come from the input stack. */
2574 macroexpand (pfile
, hp
)
2579 DEFINITION
*defn
= hp
->value
.defn
;
2580 register U_CHAR
*xbuf
;
2581 long start_line
, start_column
;
2583 struct argdata
*args
;
2584 long old_written
= CPP_WRITTEN (pfile
);
2586 int start_line
= instack
[indepth
].lineno
;
2588 int rest_args
, rest_zero
;
2592 CHECK_DEPTH (return;);
2596 /* This macro is being used inside a #if, which means it must be */
2597 /* recorded as a precondition. */
2598 if (pcp_inside_if
&& pcp_outfile
&& defn
->predefined
)
2599 dump_single_macro (hp
, pcp_outfile
);
2602 pfile
->output_escapes
++;
2603 cpp_buf_line_and_col (cpp_file_buffer (pfile
), &start_line
, &start_column
);
2605 nargs
= defn
->nargs
;
2609 enum cpp_token token
;
2611 args
= (struct argdata
*) alloca ((nargs
+ 1) * sizeof (struct argdata
));
2613 for (i
= 0; i
< nargs
; i
++)
2615 args
[i
].raw
= args
[i
].expanded
= 0;
2616 args
[i
].raw_length
= 0;
2617 args
[i
].expand_length
= args
[i
].stringified_length
= -1;
2618 args
[i
].use_count
= 0;
2621 /* Parse all the macro args that are supplied. I counts them.
2622 The first NARGS args are stored in ARGS.
2623 The rest are discarded. If rest_args is set then we assume
2624 macarg absorbed the rest of the args. */
2628 FORWARD(1); /* Discard the open-parenthesis before the first arg. */
2633 if (i
< nargs
|| (nargs
== 0 && i
== 0))
2635 /* if we are working on last arg which absorbs rest of args... */
2636 if (i
== nargs
- 1 && defn
->rest_args
)
2638 args
[i
].raw
= CPP_WRITTEN (pfile
);
2639 token
= macarg (pfile
, rest_args
);
2640 args
[i
].raw_length
= CPP_WRITTEN (pfile
) - args
[i
].raw
;
2641 args
[i
].newlines
= 0; /* FIXME */
2644 token
= macarg (pfile
, 0);
2645 if (token
== CPP_EOF
|| token
== CPP_POP
)
2647 cpp_error_with_line (pfile
, start_line
, start_column
,
2648 "unterminated macro call");
2652 } while (token
== CPP_COMMA
);
2654 /* If we got one arg but it was just whitespace, call that 0 args. */
2657 register U_CHAR
*bp
= ARG_BASE
+ args
[0].raw
;
2658 register U_CHAR
*lim
= bp
+ args
[0].raw_length
;
2659 /* cpp.texi says for foo ( ) we provide one argument.
2660 However, if foo wants just 0 arguments, treat this as 0. */
2662 while (bp
!= lim
&& is_space
[*bp
]) bp
++;
2667 /* Don't output an error message if we have already output one for
2668 a parse error above. */
2670 if (nargs
== 0 && i
> 0)
2672 cpp_error (pfile
, "arguments given to macro `%s'", hp
->name
);
2676 /* traditional C allows foo() if foo wants one argument. */
2677 if (nargs
== 1 && i
== 0 && CPP_TRADITIONAL (pfile
))
2679 /* the rest args token is allowed to absorb 0 tokens */
2680 else if (i
== nargs
- 1 && defn
->rest_args
)
2683 cpp_error (pfile
, "macro `%s' used without args", hp
->name
);
2685 cpp_error (pfile
, "macro `%s' used with just one arg", hp
->name
);
2687 cpp_error (pfile
, "macro `%s' used with only %d args",
2693 "macro `%s' used with too many (%d) args", hp
->name
, i
);
2697 /* If macro wants zero args, we parsed the arglist for checking only.
2698 Read directly from the macro definition. */
2701 xbuf
= defn
->expansion
;
2702 xbuf_len
= defn
->length
;
2706 register U_CHAR
*exp
= defn
->expansion
;
2707 register int offset
; /* offset in expansion,
2708 copied a piece at a time */
2709 register int totlen
; /* total amount of exp buffer filled so far */
2711 register struct reflist
*ap
, *last_ap
;
2713 /* Macro really takes args. Compute the expansion of this call. */
2715 /* Compute length in characters of the macro's expansion.
2716 Also count number of times each arg is used. */
2717 xbuf_len
= defn
->length
;
2718 for (ap
= defn
->pattern
; ap
!= NULL
; ap
= ap
->next
)
2722 register struct argdata
*arg
= &args
[ap
->argno
];
2723 /* Stringify if it hasn't already been */
2724 if (arg
->stringified_length
< 0)
2726 int arglen
= arg
->raw_length
;
2730 /* Initially need_space is -1. Otherwise, 1 means the
2731 previous character was a space, but we suppressed it;
2732 0 means the previous character was a non-space. */
2733 int need_space
= -1;
2735 arg
->stringified
= CPP_WRITTEN (pfile
);
2736 if (!CPP_TRADITIONAL (pfile
))
2737 CPP_PUTC (pfile
, '\"'); /* insert beginning quote */
2738 for (; i
< arglen
; i
++)
2740 c
= (ARG_BASE
+ arg
->raw
)[i
];
2744 /* Internal sequences of whitespace are replaced by
2745 one space except within an string or char token.*/
2748 if (CPP_WRITTEN (pfile
) > arg
->stringified
2749 && (CPP_PWRITTEN (pfile
))[-1] == '@')
2751 /* "@ " escape markers are removed */
2752 CPP_ADJUST_WRITTEN (pfile
, -1);
2755 if (need_space
== 0)
2759 else if (need_space
> 0)
2760 CPP_PUTC (pfile
, ' ');
2775 else if (c
== '\"' || c
== '\'')
2779 /* Escape these chars */
2780 if (c
== '\"' || (in_string
&& c
== '\\'))
2781 CPP_PUTC (pfile
, '\\');
2783 CPP_PUTC (pfile
, c
);
2786 CPP_RESERVE (pfile
, 4);
2787 sprintf ((char *)CPP_PWRITTEN (pfile
), "\\%03o",
2789 CPP_ADJUST_WRITTEN (pfile
, 4);
2792 if (!CPP_TRADITIONAL (pfile
))
2793 CPP_PUTC (pfile
, '\"'); /* insert ending quote */
2794 arg
->stringified_length
2795 = CPP_WRITTEN (pfile
) - arg
->stringified
;
2797 xbuf_len
+= args
[ap
->argno
].stringified_length
;
2799 else if (ap
->raw_before
|| ap
->raw_after
|| CPP_TRADITIONAL (pfile
))
2800 /* Add 4 for two newline-space markers to prevent
2801 token concatenation. */
2802 xbuf_len
+= args
[ap
->argno
].raw_length
+ 4;
2805 /* We have an ordinary (expanded) occurrence of the arg.
2806 So compute its expansion, if we have not already. */
2807 if (args
[ap
->argno
].expand_length
< 0)
2809 args
[ap
->argno
].expanded
= CPP_WRITTEN (pfile
);
2810 cpp_expand_to_buffer (pfile
,
2811 ARG_BASE
+ args
[ap
->argno
].raw
,
2812 args
[ap
->argno
].raw_length
);
2814 args
[ap
->argno
].expand_length
2815 = CPP_WRITTEN (pfile
) - args
[ap
->argno
].expanded
;
2818 /* Add 4 for two newline-space markers to prevent
2819 token concatenation. */
2820 xbuf_len
+= args
[ap
->argno
].expand_length
+ 4;
2822 if (args
[ap
->argno
].use_count
< 10)
2823 args
[ap
->argno
].use_count
++;
2826 xbuf
= (U_CHAR
*) xmalloc (xbuf_len
+ 1);
2828 /* Generate in XBUF the complete expansion
2829 with arguments substituted in.
2830 TOTLEN is the total size generated so far.
2831 OFFSET is the index in the definition
2832 of where we are copying from. */
2833 offset
= totlen
= 0;
2834 for (last_ap
= NULL
, ap
= defn
->pattern
; ap
!= NULL
;
2835 last_ap
= ap
, ap
= ap
->next
)
2837 register struct argdata
*arg
= &args
[ap
->argno
];
2838 int count_before
= totlen
;
2840 /* Add chars to XBUF. */
2841 for (i
= 0; i
< ap
->nchars
; i
++, offset
++)
2842 xbuf
[totlen
++] = exp
[offset
];
2844 /* If followed by an empty rest arg with concatenation,
2845 delete the last run of nonwhite chars. */
2846 if (rest_zero
&& totlen
> count_before
2847 && ((ap
->rest_args
&& ap
->raw_before
)
2848 || (last_ap
!= NULL
&& last_ap
->rest_args
2849 && last_ap
->raw_after
)))
2851 /* Delete final whitespace. */
2852 while (totlen
> count_before
&& is_space
[xbuf
[totlen
- 1]])
2855 /* Delete the nonwhites before them. */
2856 while (totlen
> count_before
&& ! is_space
[xbuf
[totlen
- 1]])
2860 if (ap
->stringify
!= 0)
2862 bcopy (ARG_BASE
+ arg
->stringified
,
2863 xbuf
+ totlen
, arg
->stringified_length
);
2864 totlen
+= arg
->stringified_length
;
2866 else if (ap
->raw_before
|| ap
->raw_after
|| CPP_TRADITIONAL (pfile
))
2868 U_CHAR
*p1
= ARG_BASE
+ arg
->raw
;
2869 U_CHAR
*l1
= p1
+ arg
->raw_length
;
2872 while (p1
!= l1
&& is_space
[*p1
]) p1
++;
2873 while (p1
!= l1
&& is_idchar
[*p1
])
2874 xbuf
[totlen
++] = *p1
++;
2875 /* Delete any no-reexpansion marker that follows
2876 an identifier at the beginning of the argument
2877 if the argument is concatenated with what precedes it. */
2878 if (p1
[0] == '@' && p1
[1] == '-')
2883 /* Arg is concatenated after: delete trailing whitespace,
2884 whitespace markers, and no-reexpansion markers. */
2887 if (is_space
[l1
[-1]]) l1
--;
2888 else if (l1
[-1] == '-')
2890 U_CHAR
*p2
= l1
- 1;
2891 /* If a `-' is preceded by an odd number of newlines then it
2892 and the last newline are a no-reexpansion marker. */
2893 while (p2
!= p1
&& p2
[-1] == '\n') p2
--;
2894 if ((l1
- 1 - p2
) & 1) {
2903 bcopy (p1
, xbuf
+ totlen
, l1
- p1
);
2908 U_CHAR
*expanded
= ARG_BASE
+ arg
->expanded
;
2909 if (!ap
->raw_before
&& totlen
> 0 && arg
->expand_length
2910 && !CPP_TRADITIONAL(pfile
)
2911 && unsafe_chars (xbuf
[totlen
-1], expanded
[0]))
2913 xbuf
[totlen
++] = '@';
2914 xbuf
[totlen
++] = ' ';
2917 bcopy (expanded
, xbuf
+ totlen
, arg
->expand_length
);
2918 totlen
+= arg
->expand_length
;
2920 if (!ap
->raw_after
&& totlen
> 0 && offset
< defn
->length
2921 && !CPP_TRADITIONAL(pfile
)
2922 && unsafe_chars (xbuf
[totlen
-1], exp
[offset
]))
2924 xbuf
[totlen
++] = '@';
2925 xbuf
[totlen
++] = ' ';
2928 /* If a macro argument with newlines is used multiple times,
2929 then only expand the newlines once. This avoids creating
2930 output lines which don't correspond to any input line,
2931 which confuses gdb and gcov. */
2932 if (arg
->use_count
> 1 && arg
->newlines
> 0)
2934 /* Don't bother doing change_newlines for subsequent
2938 = change_newlines (expanded
, arg
->expand_length
);
2942 if (totlen
> xbuf_len
)
2946 /* if there is anything left of the definition
2947 after handling the arg list, copy that in too. */
2949 for (i
= offset
; i
< defn
->length
; i
++)
2951 /* if we've reached the end of the macro */
2954 if (! (rest_zero
&& last_ap
!= NULL
&& last_ap
->rest_args
2955 && last_ap
->raw_after
))
2956 xbuf
[totlen
++] = exp
[i
];
2964 pfile
->output_escapes
--;
2966 /* Now put the expansion on the input stack
2967 so our caller will commence reading from it. */
2968 push_macro_expansion (pfile
, xbuf
, xbuf_len
, hp
);
2969 CPP_BUFFER (pfile
)->has_escapes
= 1;
2971 /* Pop the space we've used in the token_buffer for argument expansion. */
2972 CPP_SET_WRITTEN (pfile
, old_written
);
2974 /* Recursive macro use sometimes works traditionally.
2975 #define foo(x,y) bar (x (y,0), y)
2978 if (!CPP_TRADITIONAL (pfile
))
2979 hp
->type
= T_DISABLED
;
2983 push_macro_expansion (pfile
, xbuf
, xbuf_len
, hp
)
2985 register U_CHAR
*xbuf
;
2989 register cpp_buffer
*mbuf
= cpp_push_buffer (pfile
, xbuf
, xbuf_len
);
2992 mbuf
->cleanup
= macro_cleanup
;
2995 /* The first chars of the expansion should be a "@ " added by
2996 collect_expansion. This is to prevent accidental token-pasting
2997 between the text preceding the macro invocation, and the macro
3000 We would like to avoid adding unneeded spaces (for the sake of
3001 tools that use cpp, such as imake). In some common cases we can
3002 tell that it is safe to omit the space.
3004 The character before the macro invocation cannot have been an
3005 idchar (or else it would have been pasted with the idchars of
3006 the macro name). Therefore, if the first non-space character
3007 of the expansion is an idchar, we do not need the extra space
3008 to prevent token pasting.
3010 Also, we don't need the extra space if the first char is '(',
3011 or some other (less common) characters. */
3013 if (xbuf
[0] == '@' && xbuf
[1] == ' '
3014 && (is_idchar
[xbuf
[2]] || xbuf
[2] == '(' || xbuf
[2] == '\''
3015 || xbuf
[2] == '\"'))
3019 /* Like cpp_get_token, except that it does not read past end-of-line.
3020 Also, horizontal space is skipped, and macros are popped. */
3022 static enum cpp_token
3023 get_directive_token (pfile
)
3028 long old_written
= CPP_WRITTEN (pfile
);
3029 enum cpp_token token
;
3030 cpp_skip_hspace (pfile
);
3031 if (PEEKC () == '\n')
3033 token
= cpp_get_token (pfile
);
3037 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile
)))
3039 /* ... else fall though ... */
3040 case CPP_HSPACE
: case CPP_COMMENT
:
3041 CPP_SET_WRITTEN (pfile
, old_written
);
3049 /* Handle #include and #import.
3050 This function expects to see "fname" or <fname> on the input.
3052 The input is normally in part of the output_buffer following
3053 CPP_WRITTEN, and will get overwritten by output_line_command.
3054 I.e. in input file specification has been popped by handle_directive.
3058 do_include (pfile
, keyword
, unused1
, unused2
)
3060 struct directive
*keyword
;
3061 U_CHAR
*unused1 ATTRIBUTE_UNUSED
, *unused2 ATTRIBUTE_UNUSED
;
3063 int importing
= (keyword
->type
== T_IMPORT
);
3064 int skip_dirs
= (keyword
->type
== T_INCLUDE_NEXT
);
3065 char *fname
; /* Dynamically allocated fname buffer */
3067 U_CHAR
*fbeg
, *fend
; /* Beginning and end of fname */
3068 enum cpp_token token
;
3070 /* Chain of dirs to search */
3071 struct file_name_list
*search_start
= CPP_OPTIONS (pfile
)->include
;
3072 struct file_name_list dsp
[1]; /* First in chain, if #include "..." */
3073 struct file_name_list
*searchptr
= 0;
3074 long old_written
= CPP_WRITTEN (pfile
);
3078 int f
; /* file number */
3080 int angle_brackets
= 0; /* 0 for "...", 1 for <...> */
3087 f
= -1; /* JF we iz paranoid! */
3089 if (CPP_PEDANTIC (pfile
) && !CPP_BUFFER (pfile
)->system_header_p
)
3092 cpp_pedwarn (pfile
, "ANSI C does not allow `#import'");
3094 cpp_pedwarn (pfile
, "ANSI C does not allow `#include_next'");
3097 if (importing
&& CPP_OPTIONS (pfile
)->warn_import
3098 && !CPP_OPTIONS (pfile
)->inhibit_warnings
3099 && !CPP_BUFFER (pfile
)->system_header_p
&& !pfile
->import_warning
)
3101 pfile
->import_warning
= 1;
3102 cpp_warning (pfile
, "using `#import' is not recommended");
3103 fprintf (stderr
, "The fact that a certain header file need not be processed more than once\n");
3104 fprintf (stderr
, "should be indicated in the header file, not where it is used.\n");
3105 fprintf (stderr
, "The best way to do this is with a conditional of this form:\n\n");
3106 fprintf (stderr
, " #ifndef _FOO_H_INCLUDED\n");
3107 fprintf (stderr
, " #define _FOO_H_INCLUDED\n");
3108 fprintf (stderr
, " ... <real contents of file> ...\n");
3109 fprintf (stderr
, " #endif /* Not _FOO_H_INCLUDED */\n\n");
3110 fprintf (stderr
, "Then users can use `#include' any number of times.\n");
3111 fprintf (stderr
, "GNU C automatically avoids processing the file more than once\n");
3112 fprintf (stderr
, "when it is equipped with such a conditional.\n");
3115 pfile
->parsing_include_directive
++;
3116 token
= get_directive_token (pfile
);
3117 pfile
->parsing_include_directive
--;
3119 if (token
== CPP_STRING
)
3121 /* FIXME - check no trailing garbage */
3122 fbeg
= pfile
->token_buffer
+ old_written
+ 1;
3123 fend
= CPP_PWRITTEN (pfile
) - 1;
3124 if (fbeg
[-1] == '<')
3127 /* If -I-, start with the first -I dir after the -I-. */
3128 if (CPP_OPTIONS (pfile
)->first_bracket_include
)
3129 search_start
= CPP_OPTIONS (pfile
)->first_bracket_include
;
3131 /* If -I- was specified, don't search current dir, only spec'd ones. */
3132 else if (! CPP_OPTIONS (pfile
)->ignore_srcdir
)
3134 cpp_buffer
*fp
= CPP_BUFFER (pfile
);
3135 /* We have "filename". Figure out directory this source
3136 file is coming from and put it on the front of the list. */
3138 for ( ; fp
!= CPP_NULL_BUFFER (pfile
); fp
= CPP_PREV_BUFFER (fp
))
3143 if ((nam
= fp
->nominal_fname
) != NULL
)
3145 /* Found a named file. Figure out dir of the file,
3146 and put it in front of the search list. */
3147 dsp
[0].next
= search_start
;
3150 ep
= rindex (nam
, '/');
3152 ep
= rindex (nam
, ']');
3153 if (ep
== NULL
) ep
= rindex (nam
, '>');
3154 if (ep
== NULL
) ep
= rindex (nam
, ':');
3155 if (ep
!= NULL
) ep
++;
3160 dsp
[0].fname
= (char *) alloca (n
+ 1);
3161 strncpy (dsp
[0].fname
, nam
, n
);
3162 dsp
[0].fname
[n
] = '\0';
3163 if (n
+ INCLUDE_LEN_FUDGE
> pfile
->max_include_len
)
3164 pfile
->max_include_len
= n
+ INCLUDE_LEN_FUDGE
;
3168 dsp
[0].fname
= 0; /* Current directory */
3170 dsp
[0].got_name_map
= 0;
3177 else if (token
== CPP_NAME
)
3180 * Support '#include xyz' like VAX-C to allow for easy use of all the
3181 * decwindow include files. It defaults to '#include <xyz.h>' (so the
3182 * code from case '<' is repeated here) and generates a warning.
3185 "VAX-C-style include specification found, use '#include <filename.h>' !");
3187 /* If -I-, start with the first -I dir after the -I-. */
3188 if (CPP_OPTIONS (pfile
)->first_bracket_include
)
3189 search_start
= CPP_OPTIONS (pfile
)->first_bracket_include
;
3190 fbeg
= pfile
->token_buffer
+ old_written
;
3191 fend
= CPP_PWRITTEN (pfile
);
3197 "`#%s' expects \"FILENAME\" or <FILENAME>", keyword
->name
);
3198 CPP_SET_WRITTEN (pfile
, old_written
);
3199 skip_rest_of_line (pfile
);
3205 token
= get_directive_token (pfile
);
3206 if (token
!= CPP_VSPACE
)
3208 cpp_error (pfile
, "junk at end of `#include'");
3209 while (token
!= CPP_VSPACE
&& token
!= CPP_EOF
&& token
!= CPP_POP
)
3210 token
= get_directive_token (pfile
);
3213 /* For #include_next, skip in the search path
3214 past the dir in which the containing file was found. */
3217 cpp_buffer
*fp
= CPP_BUFFER (pfile
);
3218 for (; fp
!= CPP_NULL_BUFFER (pfile
); fp
= CPP_PREV_BUFFER (fp
))
3219 if (fp
->fname
!= NULL
)
3221 /* fp->dir is null if the containing file was specified with
3222 an absolute file name. In that case, don't skip anything. */
3223 if (fp
->dir
== SELF_DIR_DUMMY
)
3224 search_start
= CPP_OPTIONS (pfile
)->include
;
3226 search_start
= fp
->dir
->next
;
3231 CPP_SET_WRITTEN (pfile
, old_written
);
3237 cpp_error (pfile
, "empty file name in `#%s'", keyword
->name
);
3241 /* Allocate this permanently, because it gets stored in the definitions
3243 fname
= (char *) xmalloc (pfile
->max_include_len
+ flen
+ 4);
3244 /* + 2 above for slash and terminating null. */
3245 /* + 2 added for '.h' on VMS (to support '#include filename') */
3247 /* If specified file name is absolute, just open it. */
3250 strncpy (fname
, fbeg
, flen
);
3252 if (redundant_include_p (pfile
, fname
))
3255 f
= lookup_import (pfile
, fname
, NULL_PTR
);
3257 f
= open_include_file (pfile
, fname
, NULL_PTR
);
3259 return 0; /* Already included this file */
3261 /* Search directory path, trying to open the file.
3262 Copy each filename tried into FNAME. */
3264 for (searchptr
= search_start
; searchptr
; searchptr
= searchptr
->next
) {
3265 if (searchptr
->fname
) {
3266 /* The empty string in a search path is ignored.
3267 This makes it possible to turn off entirely
3268 a standard piece of the list. */
3269 if (searchptr
->fname
[0] == 0)
3271 strcpy (fname
, searchptr
->fname
);
3272 strcat (fname
, "/");
3273 fname
[strlen (fname
) + flen
] = 0;
3277 strncat (fname
, fbeg
, flen
);
3279 /* Change this 1/2 Unix 1/2 VMS file specification into a
3280 full VMS file specification */
3281 if (searchptr
->fname
&& (searchptr
->fname
[0] != 0)) {
3282 /* Fix up the filename */
3283 hack_vms_include_specification (fname
);
3285 /* This is a normal VMS filespec, so use it unchanged. */
3286 strncpy (fname
, fbeg
, flen
);
3288 /* if it's '#include filename', add the missing .h */
3289 if (index(fname
,'.')==NULL
) {
3290 strcat (fname
, ".h");
3294 /* ??? There are currently 3 separate mechanisms for avoiding processing
3295 of redundant include files: #import, #pragma once, and
3296 redundant_include_p. It would be nice if they were unified. */
3297 if (redundant_include_p (pfile
, fname
))
3300 f
= lookup_import (pfile
, fname
, searchptr
);
3302 f
= open_include_file (pfile
, fname
, searchptr
);
3304 return 0; /* Already included this file */
3306 else if (f
== -1 && errno
== EACCES
)
3307 cpp_warning (pfile
, "Header file %s exists, but is not readable",
3317 /* A file that was not found. */
3318 strncpy (fname
, fbeg
, flen
);
3320 /* If generating dependencies and -MG was specified, we assume missing
3321 files are leaf files, living in the same directory as the source file
3322 or other similar place; these missing files may be generated from
3323 other files and may not exist yet (eg: y.tab.h). */
3325 if (CPP_OPTIONS(pfile
)->print_deps_missing_files
3326 && CPP_PRINT_DEPS (pfile
)
3327 > (angle_brackets
|| (pfile
->system_include_depth
> 0)))
3329 /* If it was requested as a system header file,
3330 then assume it belongs in the first place to look for such. */
3333 for (searchptr
= search_start
; searchptr
;
3334 searchptr
= searchptr
->next
)
3336 if (searchptr
->fname
)
3340 if (searchptr
->fname
[0] == 0)
3342 p
= (char *) alloca (strlen (searchptr
->fname
)
3343 + strlen (fname
) + 2);
3344 strcpy (p
, searchptr
->fname
);
3347 deps_output (pfile
, p
, ' ');
3354 /* Otherwise, omit the directory, as if the file existed
3355 in the directory with the source. */
3356 deps_output (pfile
, fname
, ' ');
3359 /* If -M was specified, and this header file won't be added to the
3360 dependency list, then don't count this as an error, because we can
3361 still produce correct output. Otherwise, we can't produce correct
3362 output, because there may be dependencies we need inside the missing
3363 file, and we don't know what directory this missing file exists in.*/
3364 else if (CPP_PRINT_DEPS (pfile
)
3365 && (CPP_PRINT_DEPS (pfile
)
3366 <= (angle_brackets
|| (pfile
->system_include_depth
> 0))))
3367 cpp_warning (pfile
, "No include path in which to find %s", fname
);
3368 else if (search_start
)
3369 cpp_error_from_errno (pfile
, fname
);
3371 cpp_error (pfile
, "No include path in which to find %s", fname
);
3374 /* Check to see if this include file is a once-only include file.
3377 struct file_name_list
*ptr
;
3379 for (ptr
= pfile
->dont_repeat_files
; ptr
; ptr
= ptr
->next
) {
3380 if (!strcmp (ptr
->fname
, fname
)) {
3382 return 0; /* This file was once'd. */
3386 for (ptr
= pfile
->all_include_files
; ptr
; ptr
= ptr
->next
) {
3387 if (!strcmp (ptr
->fname
, fname
))
3388 break; /* This file was included before. */
3392 /* This is the first time for this file. */
3393 /* Add it to list of files included. */
3395 ptr
= (struct file_name_list
*) xmalloc (sizeof (struct file_name_list
));
3396 ptr
->control_macro
= 0;
3397 ptr
->c_system_include_path
= 0;
3398 ptr
->next
= pfile
->all_include_files
;
3399 pfile
->all_include_files
= ptr
;
3400 ptr
->fname
= savestring (fname
);
3401 ptr
->got_name_map
= 0;
3403 /* For -M, add this file to the dependencies. */
3404 if (CPP_PRINT_DEPS (pfile
)
3405 > (angle_brackets
|| (pfile
->system_include_depth
> 0)))
3406 deps_output (pfile
, fname
, ' ');
3409 /* Handle -H option. */
3410 if (CPP_OPTIONS(pfile
)->print_include_names
)
3412 cpp_buffer
*buf
= CPP_BUFFER (pfile
);
3413 while ((buf
= CPP_PREV_BUFFER (buf
)) != CPP_NULL_BUFFER (pfile
))
3415 fprintf (stderr
, "%s\n", fname
);
3419 pfile
->system_include_depth
++;
3421 /* Actually process the file. */
3423 /* Record file on "seen" list for #import. */
3424 add_import (pfile
, f
, fname
);
3426 pcftry
= (char *) alloca (strlen (fname
) + 30);
3438 sprintf (pcftry
, "%s%d", fname
, pcfnum
++);
3440 pcf
= open (pcftry
, O_RDONLY
, 0666);
3446 if (bcmp ((char *) &stat_f
.st_ino
, (char *) &s
.st_ino
,
3448 || stat_f
.st_dev
!= s
.st_dev
)
3450 pcfbuf
= check_precompiled (pcf
, fname
, &pcfbuflimit
);
3451 /* Don't need it any more. */
3456 /* Don't need it at all. */
3461 } while (pcf
!= -1 && !pcfbuf
);
3465 /* Actually process the file */
3466 if (cpp_push_buffer (pfile
, NULL
, 0) == NULL
)
3468 if (finclude (pfile
, f
, fname
, is_system_include (pfile
, fname
),
3469 searchptr
!= dsp
? searchptr
: SELF_DIR_DUMMY
))
3471 output_line_command (pfile
, 0, enter_file
);
3472 pfile
->only_seen_white
= 2;
3476 pfile
->system_include_depth
--;
3481 /* Return nonzero if there is no need to include file NAME
3482 because it has already been included and it contains a conditional
3483 to make a repeated include do nothing. */
3486 redundant_include_p (pfile
, name
)
3490 struct file_name_list
*l
= pfile
->all_include_files
;
3491 for (; l
; l
= l
->next
)
3492 if (! strcmp (name
, l
->fname
)
3494 && cpp_lookup (pfile
, l
->control_macro
, -1, -1))
3499 /* Return nonzero if the given FILENAME is an absolute pathname which
3500 designates a file within one of the known "system" include file
3501 directories. We assume here that if the given FILENAME looks like
3502 it is the name of a file which resides either directly in a "system"
3503 include file directory, or within any subdirectory thereof, then the
3504 given file must be a "system" include file. This function tells us
3505 if we should suppress pedantic errors/warnings for the given FILENAME.
3507 The value is 2 if the file is a C-language system header file
3508 for which C++ should (on most systems) assume `extern "C"'. */
3511 is_system_include (pfile
, filename
)
3513 register char *filename
;
3515 struct file_name_list
*searchptr
;
3517 for (searchptr
= CPP_OPTIONS (pfile
)->first_system_include
; searchptr
;
3518 searchptr
= searchptr
->next
)
3519 if (searchptr
->fname
) {
3520 register char *sys_dir
= searchptr
->fname
;
3521 register unsigned length
= strlen (sys_dir
);
3523 if (! strncmp (sys_dir
, filename
, length
) && filename
[length
] == '/')
3525 if (searchptr
->c_system_include_path
)
3536 * Install a name in the assertion hash table.
3538 * If LEN is >= 0, it is the length of the name.
3539 * Otherwise, compute the length by scanning the entire name.
3541 * If HASH is >= 0, it is the precomputed hash code.
3542 * Otherwise, compute the hash code.
3545 static ASSERTION_HASHNODE
*
3546 assertion_install (pfile
, name
, len
, hash
)
3552 register ASSERTION_HASHNODE
*hp
;
3553 register int i
, bucket
;
3554 register U_CHAR
*p
, *q
;
3556 i
= sizeof (ASSERTION_HASHNODE
) + len
+ 1;
3557 hp
= (ASSERTION_HASHNODE
*) xmalloc (i
);
3559 hp
->bucket_hdr
= &pfile
->assertion_hashtab
[bucket
];
3560 hp
->next
= pfile
->assertion_hashtab
[bucket
];
3561 pfile
->assertion_hashtab
[bucket
] = hp
;
3563 if (hp
->next
!= NULL
)
3564 hp
->next
->prev
= hp
;
3567 hp
->name
= ((U_CHAR
*) hp
) + sizeof (ASSERTION_HASHNODE
);
3570 for (i
= 0; i
< len
; i
++)
3576 * find the most recent hash node for name "name" (ending with first
3577 * non-identifier char) installed by install
3579 * If LEN is >= 0, it is the length of the name.
3580 * Otherwise, compute the length by scanning the entire name.
3582 * If HASH is >= 0, it is the precomputed hash code.
3583 * Otherwise, compute the hash code.
3586 static ASSERTION_HASHNODE
*
3587 assertion_lookup (pfile
, name
, len
, hash
)
3593 register ASSERTION_HASHNODE
*bucket
;
3595 bucket
= pfile
->assertion_hashtab
[hash
];
3597 if (bucket
->length
== len
&& strncmp (bucket
->name
, name
, len
) == 0)
3599 bucket
= bucket
->next
;
3605 delete_assertion (hp
)
3606 ASSERTION_HASHNODE
*hp
;
3608 struct tokenlist_list
*tail
;
3609 if (hp
->prev
!= NULL
)
3610 hp
->prev
->next
= hp
->next
;
3611 if (hp
->next
!= NULL
)
3612 hp
->next
->prev
= hp
->prev
;
3614 for (tail
= hp
->value
; tail
; )
3616 struct tokenlist_list
*next
= tail
->next
;
3617 free_token_list (tail
->tokens
);
3622 /* Make sure that the bucket chain header that
3623 the deleted guy was on points to the right thing afterwards. */
3624 if (hp
== *hp
->bucket_hdr
)
3625 *hp
->bucket_hdr
= hp
->next
;
3630 /* Convert a character string literal into a nul-terminated string.
3631 The input string is [IN ... LIMIT).
3632 The result is placed in RESULT. RESULT can be the same as IN.
3633 The value returned in the end of the string written to RESULT,
3634 or NULL on error. */
3637 convert_string (pfile
, result
, in
, limit
, handle_escapes
)
3639 register U_CHAR
*result
, *in
, *limit
;
3659 char *bpc
= (char *) in
;
3660 int i
= (U_CHAR
) cpp_parse_escape (pfile
, &bpc
);
3661 in
= (U_CHAR
*) bpc
;
3663 *result
++ = (U_CHAR
)c
;
3666 /* else fall through */
3676 * interpret #line command. Remembers previously seen fnames
3677 * in its very own hash table.
3679 #define FNAME_HASHSIZE 37
3682 do_line (pfile
, keyword
, unused1
, unused2
)
3684 struct directive
*keyword ATTRIBUTE_UNUSED
;
3685 U_CHAR
*unused1 ATTRIBUTE_UNUSED
, *unused2 ATTRIBUTE_UNUSED
;
3687 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
3689 long old_written
= CPP_WRITTEN (pfile
);
3690 enum file_change_code file_change
= same_file
;
3691 enum cpp_token token
;
3693 token
= get_directive_token (pfile
);
3695 if (token
!= CPP_NUMBER
3696 || !ISDIGIT(pfile
->token_buffer
[old_written
]))
3698 cpp_error (pfile
, "invalid format `#line' command");
3699 goto bad_line_directive
;
3702 /* The Newline at the end of this line remains to be processed.
3703 To put the next line at the specified line number,
3704 we must store a line number now that is one less. */
3705 new_lineno
= atoi ((char *)(pfile
->token_buffer
+ old_written
)) - 1;
3706 CPP_SET_WRITTEN (pfile
, old_written
);
3708 /* NEW_LINENO is one less than the actual line number here. */
3709 if (CPP_PEDANTIC (pfile
) && new_lineno
< 0)
3710 cpp_pedwarn (pfile
, "line number out of range in `#line' command");
3712 #if 0 /* #line 10"foo.c" is supposed to be allowed. */
3713 if (PEEKC() && !is_space
[PEEKC()]) {
3714 cpp_error (pfile
, "invalid format `#line' command");
3715 goto bad_line_directive
;
3719 token
= get_directive_token (pfile
);
3721 if (token
== CPP_STRING
) {
3722 U_CHAR
*fname
= pfile
->token_buffer
+ old_written
;
3724 static HASHNODE
*fname_table
[FNAME_HASHSIZE
];
3725 HASHNODE
*hp
, **hash_bucket
;
3730 /* Turn the file name, which is a character string literal,
3731 into a null-terminated string. Do this in place. */
3732 end_name
= convert_string (pfile
, fname
, fname
, CPP_PWRITTEN (pfile
), 1);
3733 if (end_name
== NULL
)
3735 cpp_error (pfile
, "invalid format `#line' command");
3736 goto bad_line_directive
;
3739 fname_length
= end_name
- fname
;
3741 num_start
= CPP_WRITTEN (pfile
);
3742 token
= get_directive_token (pfile
);
3743 if (token
!= CPP_VSPACE
&& token
!= CPP_EOF
&& token
!= CPP_POP
) {
3744 p
= pfile
->token_buffer
+ num_start
;
3745 if (CPP_PEDANTIC (pfile
))
3746 cpp_pedwarn (pfile
, "garbage at end of `#line' command");
3748 if (token
!= CPP_NUMBER
|| *p
< '0' || *p
> '4' || p
[1] != '\0')
3750 cpp_error (pfile
, "invalid format `#line' command");
3751 goto bad_line_directive
;
3754 file_change
= enter_file
;
3756 file_change
= leave_file
;
3758 ip
->system_header_p
= 1;
3759 else /* if (*p == 4) */
3760 ip
->system_header_p
= 2;
3762 CPP_SET_WRITTEN (pfile
, num_start
);
3763 token
= get_directive_token (pfile
);
3764 p
= pfile
->token_buffer
+ num_start
;
3765 if (token
== CPP_NUMBER
&& p
[1] == '\0' && (*p
== '3' || *p
== '4')) {
3766 ip
->system_header_p
= *p
== 3 ? 1 : 2;
3767 token
= get_directive_token (pfile
);
3769 if (token
!= CPP_VSPACE
) {
3770 cpp_error (pfile
, "invalid format `#line' command");
3771 goto bad_line_directive
;
3775 hash_bucket
= &fname_table
[hashf (fname
, fname_length
, FNAME_HASHSIZE
)];
3776 for (hp
= *hash_bucket
; hp
!= NULL
; hp
= hp
->next
)
3777 if (hp
->length
== fname_length
3778 && strncmp (hp
->value
.cpval
, fname
, fname_length
) == 0) {
3779 ip
->nominal_fname
= hp
->value
.cpval
;
3783 /* Didn't find it; cons up a new one. */
3784 hp
= (HASHNODE
*) xcalloc (1, sizeof (HASHNODE
) + fname_length
+ 1);
3785 hp
->next
= *hash_bucket
;
3788 hp
->length
= fname_length
;
3789 ip
->nominal_fname
= hp
->value
.cpval
= ((char *) hp
) + sizeof (HASHNODE
);
3790 bcopy (fname
, hp
->value
.cpval
, fname_length
);
3793 else if (token
!= CPP_VSPACE
&& token
!= CPP_EOF
) {
3794 cpp_error (pfile
, "invalid format `#line' command");
3795 goto bad_line_directive
;
3798 ip
->lineno
= new_lineno
;
3800 skip_rest_of_line (pfile
);
3801 CPP_SET_WRITTEN (pfile
, old_written
);
3802 output_line_command (pfile
, 0, file_change
);
3807 * remove the definition of a symbol from the symbol table.
3808 * according to un*x /lib/cpp, it is not an error to undef
3809 * something that has no definitions, so it isn't one here either.
3813 do_undef (pfile
, keyword
, buf
, limit
)
3815 struct directive
*keyword
;
3816 U_CHAR
*buf
, *limit
;
3820 U_CHAR
*orig_buf
= buf
;
3823 /* If this is a precompiler run (with -pcp) pass thru #undef commands. */
3824 if (pcp_outfile
&& keyword
)
3825 pass_thru_directive (buf
, limit
, pfile
, keyword
);
3828 SKIP_WHITE_SPACE (buf
);
3829 sym_length
= check_macro_name (pfile
, buf
, "macro");
3831 while ((hp
= cpp_lookup (pfile
, buf
, sym_length
, -1)) != NULL
)
3833 /* If we are generating additional info for debugging (with -g) we
3834 need to pass through all effective #undef commands. */
3835 if (CPP_OPTIONS (pfile
)->debug_output
&& keyword
)
3836 pass_thru_directive (orig_buf
, limit
, pfile
, keyword
);
3837 if (hp
->type
!= T_MACRO
)
3838 cpp_warning (pfile
, "undefining `%s'", hp
->name
);
3842 if (CPP_PEDANTIC (pfile
)) {
3844 SKIP_WHITE_SPACE (buf
);
3846 cpp_pedwarn (pfile
, "garbage after `#undef' directive");
3852 * Report an error detected by the program we are processing.
3853 * Use the text of the line in the error message.
3854 * (We use error because it prints the filename & line#.)
3858 do_error (pfile
, keyword
, buf
, limit
)
3860 struct directive
*keyword ATTRIBUTE_UNUSED
;
3861 U_CHAR
*buf
, *limit
;
3863 int length
= limit
- buf
;
3864 U_CHAR
*copy
= (U_CHAR
*) alloca (length
+ 1);
3865 bcopy (buf
, copy
, length
);
3867 SKIP_WHITE_SPACE (copy
);
3868 cpp_error (pfile
, "#error %s", copy
);
3873 * Report a warning detected by the program we are processing.
3874 * Use the text of the line in the warning message, then continue.
3875 * (We use error because it prints the filename & line#.)
3879 do_warning (pfile
, keyword
, buf
, limit
)
3881 struct directive
*keyword ATTRIBUTE_UNUSED
;
3882 U_CHAR
*buf
, *limit
;
3884 int length
= limit
- buf
;
3885 U_CHAR
*copy
= (U_CHAR
*) alloca (length
+ 1);
3886 bcopy (buf
, copy
, length
);
3888 SKIP_WHITE_SPACE (copy
);
3890 if (CPP_PEDANTIC (pfile
) && !CPP_BUFFER (pfile
)->system_header_p
)
3891 cpp_pedwarn (pfile
, "ANSI C does not allow `#warning'");
3893 /* Use `pedwarn' not `warning', because #warning isn't in the C Standard;
3894 if -pedantic-errors is given, #warning should cause an error. */
3895 cpp_pedwarn (pfile
, "#warning %s", copy
);
3899 /* Remember the name of the current file being read from so that we can
3900 avoid ever including it again. */
3903 do_once (pfile
, keyword
, unused1
, unused2
)
3905 struct directive
*keyword ATTRIBUTE_UNUSED
;
3906 U_CHAR
*unused1 ATTRIBUTE_UNUSED
, *unused2 ATTRIBUTE_UNUSED
;
3908 cpp_buffer
*ip
= NULL
;
3909 struct file_name_list
*new;
3911 for (ip
= CPP_BUFFER (pfile
); ; ip
= CPP_PREV_BUFFER (ip
))
3913 if (ip
== CPP_NULL_BUFFER (pfile
))
3915 if (ip
->fname
!= NULL
)
3920 new = (struct file_name_list
*) xmalloc (sizeof (struct file_name_list
));
3921 new->next
= pfile
->dont_repeat_files
;
3922 pfile
->dont_repeat_files
= new;
3923 new->fname
= savestring (ip
->fname
);
3924 new->control_macro
= 0;
3925 new->got_name_map
= 0;
3926 new->c_system_include_path
= 0;
3931 /* Report program identification. */
3934 do_ident (pfile
, keyword
, buf
, limit
)
3936 struct directive
*keyword ATTRIBUTE_UNUSED
;
3937 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
3939 /* long old_written = CPP_WRITTEN (pfile);*/
3941 /* Allow #ident in system headers, since that's not user's fault. */
3942 if (CPP_PEDANTIC (pfile
) && !CPP_BUFFER (pfile
)->system_header_p
)
3943 cpp_pedwarn (pfile
, "ANSI C does not allow `#ident'");
3945 /* Leave rest of line to be read by later calls to cpp_get_token. */
3950 /* #pragma and its argument line have already been copied to the output file.
3951 Just check for some recognized pragmas that need validation here. */
3954 do_pragma (pfile
, keyword
, buf
, limit
)
3956 struct directive
*keyword ATTRIBUTE_UNUSED
;
3957 U_CHAR
*buf
, *limit ATTRIBUTE_UNUSED
;
3959 while (*buf
== ' ' || *buf
== '\t')
3961 if (!strncmp (buf
, "once", 4)) {
3962 /* Allow #pragma once in system headers, since that's not the user's
3964 if (!CPP_BUFFER (pfile
)->system_header_p
)
3965 cpp_warning (pfile
, "`#pragma once' is obsolete");
3966 do_once (pfile
, NULL
, NULL
, NULL
);
3969 if (!strncmp (buf
, "implementation", 14)) {
3970 /* Be quiet about `#pragma implementation' for a file only if it hasn't
3971 been included yet. */
3972 struct file_name_list
*ptr
;
3973 U_CHAR
*p
= buf
+ 14, *fname
, *inc_fname
;
3975 SKIP_WHITE_SPACE (p
);
3976 if (*p
== '\n' || *p
!= '\"')
3980 p
= (U_CHAR
*) index (fname
, '\"');
3981 fname_len
= p
!= NULL
? p
- fname
: strlen (fname
);
3983 for (ptr
= pfile
->all_include_files
; ptr
; ptr
= ptr
->next
) {
3984 inc_fname
= (U_CHAR
*) rindex (ptr
->fname
, '/');
3985 inc_fname
= inc_fname
? inc_fname
+ 1 : (U_CHAR
*) ptr
->fname
;
3986 if (inc_fname
&& !strncmp (inc_fname
, fname
, fname_len
))
3988 "`#pragma implementation' for `%s' appears after file is included",
3997 /* This was a fun hack, but #pragma seems to start to be useful.
3998 By failing to recognize it, we pass it through unchanged to cc1. */
4001 * the behavior of the #pragma directive is implementation defined.
4002 * this implementation defines it as follows.
4009 if (open ("/dev/tty", O_RDONLY
, 0666) != 0)
4012 if (open ("/dev/tty", O_WRONLY
, 0666) != 1)
4014 execl ("/usr/games/hack", "#pragma", 0);
4015 execl ("/usr/games/rogue", "#pragma", 0);
4016 execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0);
4017 execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0);
4019 fatal ("You are in a maze of twisty compiler features, all different");
4023 #ifdef SCCS_DIRECTIVE
4024 /* Just ignore #sccs, on systems where we define it at all. */
4027 do_sccs (pfile
, keyword
, buf
, limit
)
4029 struct directive
*keyword ATTRIBUTE_UNUSED
;
4030 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
4032 if (CPP_PEDANTIC (pfile
))
4033 cpp_pedwarn (pfile
, "ANSI C does not allow `#sccs'");
4039 * handle #if command by
4040 * 1) inserting special `defined' keyword into the hash table
4041 * that gets turned into 0 or 1 by special_symbol (thus,
4042 * if the luser has a symbol called `defined' already, it won't
4043 * work inside the #if command)
4044 * 2) rescan the input into a temporary output buffer
4045 * 3) pass the output buffer to the yacc parser and collect a value
4046 * 4) clean up the mess left from steps 1 and 2.
4047 * 5) call conditional_skip to skip til the next #endif (etc.),
4048 * or not, depending on the value from step 3.
4052 do_if (pfile
, keyword
, buf
, limit
)
4054 struct directive
*keyword ATTRIBUTE_UNUSED
;
4055 U_CHAR
*buf
, *limit
;
4057 HOST_WIDE_INT value
= eval_if_expression (pfile
, buf
, limit
- buf
);
4058 conditional_skip (pfile
, value
== 0, T_IF
, NULL_PTR
);
4063 * handle a #elif directive by not changing if_stack either.
4064 * see the comment above do_else.
4068 do_elif (pfile
, keyword
, buf
, limit
)
4070 struct directive
*keyword ATTRIBUTE_UNUSED
;
4071 U_CHAR
*buf
, *limit
;
4073 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
) {
4074 cpp_error (pfile
, "`#elif' not within a conditional");
4077 if (pfile
->if_stack
->type
!= T_IF
&& pfile
->if_stack
->type
!= T_ELIF
) {
4078 cpp_error (pfile
, "`#elif' after `#else'");
4080 fprintf (stderr
, " (matches line %d", pfile
->if_stack
->lineno
);
4082 if (pfile
->if_stack
->fname
!= NULL
&& CPP_BUFFER (pfile
)->fname
!= NULL
4083 && strcmp (pfile
->if_stack
->fname
,
4084 CPP_BUFFER (pfile
)->nominal_fname
) != 0)
4085 fprintf (stderr
, ", file %s", pfile
->if_stack
->fname
);
4086 fprintf (stderr
, ")\n");
4088 pfile
->if_stack
->type
= T_ELIF
;
4091 if (pfile
->if_stack
->if_succeeded
)
4092 skip_if_group (pfile
, 0);
4094 HOST_WIDE_INT value
= eval_if_expression (pfile
, buf
, limit
- buf
);
4096 skip_if_group (pfile
, 0);
4098 ++pfile
->if_stack
->if_succeeded
; /* continue processing input */
4099 output_line_command (pfile
, 1, same_file
);
4106 * evaluate a #if expression in BUF, of length LENGTH,
4107 * then parse the result as a C expression and return the value as an int.
4110 static HOST_WIDE_INT
4111 eval_if_expression (pfile
, buf
, length
)
4113 U_CHAR
*buf ATTRIBUTE_UNUSED
;
4114 int length ATTRIBUTE_UNUSED
;
4116 HASHNODE
*save_defined
;
4117 HOST_WIDE_INT value
;
4118 long old_written
= CPP_WRITTEN (pfile
);
4120 save_defined
= install ((U_CHAR
*)"defined", -1, T_SPEC_DEFINED
, 0, 0, -1);
4121 pfile
->pcp_inside_if
= 1;
4123 value
= cpp_parse_expr (pfile
);
4124 pfile
->pcp_inside_if
= 0;
4125 delete_macro (save_defined
); /* clean up special symbol */
4127 CPP_SET_WRITTEN (pfile
, old_written
); /* Pop */
4133 * routine to handle ifdef/ifndef. Try to look up the symbol,
4134 * then do or don't skip to the #endif/#else/#elif depending
4135 * on what directive is actually being processed.
4139 do_xifdef (pfile
, keyword
, unused1
, unused2
)
4141 struct directive
*keyword
;
4142 U_CHAR
*unused1 ATTRIBUTE_UNUSED
, *unused2 ATTRIBUTE_UNUSED
;
4145 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
4148 enum cpp_token token
;
4149 int start_of_file
= 0;
4150 U_CHAR
*control_macro
= 0;
4151 int old_written
= CPP_WRITTEN (pfile
);
4153 /* Detect a #ifndef at start of file (not counting comments). */
4154 if (ip
->fname
!= 0 && keyword
->type
== T_IFNDEF
)
4155 start_of_file
= pfile
->only_seen_white
== 2;
4157 pfile
->no_macro_expand
++;
4158 token
= get_directive_token (pfile
);
4159 pfile
->no_macro_expand
--;
4161 ident
= pfile
->token_buffer
+ old_written
;
4162 ident_length
= CPP_WRITTEN (pfile
) - old_written
;
4163 CPP_SET_WRITTEN (pfile
, old_written
); /* Pop */
4165 if (token
== CPP_VSPACE
|| token
== CPP_POP
|| token
== CPP_EOF
)
4167 skip
= (keyword
->type
== T_IFDEF
);
4168 if (! CPP_TRADITIONAL (pfile
))
4169 cpp_pedwarn (pfile
, "`#%s' with no argument", keyword
->name
);
4171 else if (token
== CPP_NAME
)
4173 HASHNODE
*hp
= cpp_lookup (pfile
, ident
, ident_length
, -1);
4174 skip
= (hp
== NULL
) ^ (keyword
->type
== T_IFNDEF
);
4175 if (start_of_file
&& !skip
)
4177 control_macro
= (U_CHAR
*) xmalloc (ident_length
+ 1);
4178 bcopy (ident
, control_macro
, ident_length
+ 1);
4183 skip
= (keyword
->type
== T_IFDEF
);
4184 if (! CPP_TRADITIONAL (pfile
))
4185 cpp_error (pfile
, "`#%s' with invalid argument", keyword
->name
);
4188 if (!CPP_TRADITIONAL (pfile
))
4190 cpp_skip_hspace (pfile
);
4192 if (c
!= EOF
&& c
!= '\n')
4193 cpp_pedwarn (pfile
, "garbage at end of `#%s' argument", keyword
->name
);
4195 skip_rest_of_line (pfile
);
4199 /* Output a precondition for this macro. */
4200 if (hp
&& hp
->value
.defn
->predefined
)
4201 fprintf (pcp_outfile
, "#define %s\n", hp
->name
);
4204 fprintf (pcp_outfile
, "#undef ");
4205 while (is_idchar
[*cp
]) /* Ick! */
4206 fputc (*cp
++, pcp_outfile
);
4207 putc ('\n', pcp_outfile
);
4211 conditional_skip (pfile
, skip
, T_IF
, control_macro
);
4215 /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
4216 If this is a #ifndef starting at the beginning of a file,
4217 CONTROL_MACRO is the macro name tested by the #ifndef.
4218 Otherwise, CONTROL_MACRO is 0. */
4221 conditional_skip (pfile
, skip
, type
, control_macro
)
4224 enum node_type type
;
4225 U_CHAR
*control_macro
;
4227 IF_STACK_FRAME
*temp
;
4229 temp
= (IF_STACK_FRAME
*) xcalloc (1, sizeof (IF_STACK_FRAME
));
4230 temp
->fname
= CPP_BUFFER (pfile
)->nominal_fname
;
4232 temp
->lineno
= CPP_BUFFER (pfile
)->lineno
;
4234 temp
->next
= pfile
->if_stack
;
4235 temp
->control_macro
= control_macro
;
4236 pfile
->if_stack
= temp
;
4238 pfile
->if_stack
->type
= type
;
4241 skip_if_group (pfile
, 0);
4244 ++pfile
->if_stack
->if_succeeded
;
4245 output_line_command (pfile
, 1, same_file
);
4250 * skip to #endif, #else, or #elif. adjust line numbers, etc.
4251 * leaves input ptr at the sharp sign found.
4252 * If ANY is nonzero, return at next directive of any sort.
4256 skip_if_group (pfile
, any
)
4261 struct directive
*kt
;
4262 IF_STACK_FRAME
*save_if_stack
= pfile
->if_stack
; /* don't pop past here */
4264 U_CHAR
*beg_of_line
= bp
;
4266 register int ident_length
;
4268 struct parse_marker line_start_mark
;
4270 parse_set_mark (&line_start_mark
, pfile
);
4272 if (CPP_OPTIONS (pfile
)->output_conditionals
) {
4273 static char failed
[] = "#failed\n";
4274 CPP_PUTS (pfile
, failed
, sizeof(failed
)-1);
4276 output_line_command (pfile
, 1, same_file
);
4280 if (CPP_OPTIONS (pfile
)->output_conditionals
)
4282 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
4283 U_CHAR
*start_line
= pbuf
->buf
+ line_start_mark
.position
;
4284 CPP_PUTS (pfile
, start_line
, pbuf
->cur
- start_line
);
4286 parse_move_mark (&line_start_mark
, pfile
);
4287 if (!CPP_TRADITIONAL (pfile
))
4288 cpp_skip_hspace (pfile
);
4292 int old_written
= CPP_WRITTEN (pfile
);
4293 cpp_skip_hspace (pfile
);
4295 parse_name (pfile
, GETC());
4296 ident_length
= CPP_WRITTEN (pfile
) - old_written
;
4297 ident
= pfile
->token_buffer
+ old_written
;
4298 pfile
->limit
= ident
;
4300 if (ident_length
== 0)
4301 goto not_a_directive
;
4303 /* Handle # followed by a line number. */
4305 /* Avoid error for `###' and similar cases unless -pedantic. */
4308 for (kt
= directive_table
; kt
->length
>= 0; kt
++)
4310 IF_STACK_FRAME
*temp
;
4311 if (ident_length
== kt
->length
4312 && strncmp (ident
, kt
->name
, kt
->length
) == 0)
4314 /* If we are asked to return on next directive, do so now. */
4324 = (IF_STACK_FRAME
*) xcalloc (1, sizeof (IF_STACK_FRAME
));
4325 temp
->next
= pfile
->if_stack
;
4326 pfile
->if_stack
= temp
;
4328 temp
->lineno
= CPP_BUFFER(pfile
)->lineno
;
4330 temp
->fname
= CPP_BUFFER(pfile
)->nominal_fname
;
4331 temp
->type
= kt
->type
;
4335 if (CPP_PEDANTIC (pfile
) && pfile
->if_stack
!= save_if_stack
)
4336 validate_else (pfile
,
4337 kt
->type
== T_ELSE
? "#else" : "#endif");
4339 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
)
4342 "`#%s' not within a conditional", kt
->name
);
4345 else if (pfile
->if_stack
== save_if_stack
)
4346 goto done
; /* found what we came for */
4348 if (kt
->type
!= T_ENDIF
)
4350 if (pfile
->if_stack
->type
== T_ELSE
)
4351 cpp_error (pfile
, "`#else' or `#elif' after `#else'");
4352 pfile
->if_stack
->type
= kt
->type
;
4356 temp
= pfile
->if_stack
;
4357 pfile
->if_stack
= temp
->next
;
4364 /* Don't let erroneous code go by. */
4365 if (kt
->length
< 0 && !CPP_OPTIONS (pfile
)->lang_asm
4366 && CPP_PEDANTIC (pfile
))
4367 cpp_pedwarn (pfile
, "invalid preprocessor directive name");
4371 /* We're in the middle of a line. Skip the rest of it. */
4378 case '/': /* possible comment */
4379 c
= skip_comment (pfile
, NULL
);
4386 old
= CPP_WRITTEN (pfile
);
4387 cpp_get_token (pfile
);
4388 CPP_SET_WRITTEN (pfile
, old
);
4391 /* Char after backslash loses its special meaning. */
4392 if (PEEKC() == '\n')
4402 if (CPP_OPTIONS (pfile
)->output_conditionals
) {
4403 static char end_failed
[] = "#endfailed\n";
4404 CPP_PUTS (pfile
, end_failed
, sizeof(end_failed
)-1);
4407 pfile
->only_seen_white
= 1;
4408 parse_goto_mark (&line_start_mark
, pfile
);
4409 parse_clear_mark (&line_start_mark
);
4413 * handle a #else directive. Do this by just continuing processing
4414 * without changing if_stack ; this is so that the error message
4415 * for missing #endif's etc. will point to the original #if. It
4416 * is possible that something different would be better.
4420 do_else (pfile
, keyword
, buf
, limit
)
4422 struct directive
*keyword ATTRIBUTE_UNUSED
;
4423 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
4425 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
4427 if (CPP_PEDANTIC (pfile
))
4428 validate_else (pfile
, "#else");
4429 skip_rest_of_line (pfile
);
4431 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
) {
4432 cpp_error (pfile
, "`#else' not within a conditional");
4435 /* #ifndef can't have its special treatment for containing the whole file
4436 if it has a #else clause. */
4437 pfile
->if_stack
->control_macro
= 0;
4439 if (pfile
->if_stack
->type
!= T_IF
&& pfile
->if_stack
->type
!= T_ELIF
) {
4440 cpp_error (pfile
, "`#else' after `#else'");
4441 fprintf (stderr
, " (matches line %d", pfile
->if_stack
->lineno
);
4442 if (strcmp (pfile
->if_stack
->fname
, ip
->nominal_fname
) != 0)
4443 fprintf (stderr
, ", file %s", pfile
->if_stack
->fname
);
4444 fprintf (stderr
, ")\n");
4446 pfile
->if_stack
->type
= T_ELSE
;
4449 if (pfile
->if_stack
->if_succeeded
)
4450 skip_if_group (pfile
, 0);
4452 ++pfile
->if_stack
->if_succeeded
; /* continue processing input */
4453 output_line_command (pfile
, 1, same_file
);
4459 * unstack after #endif command
4463 do_endif (pfile
, keyword
, buf
, limit
)
4465 struct directive
*keyword ATTRIBUTE_UNUSED
;
4466 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
4468 if (CPP_PEDANTIC (pfile
))
4469 validate_else (pfile
, "#endif");
4470 skip_rest_of_line (pfile
);
4472 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
)
4473 cpp_error (pfile
, "unbalanced `#endif'");
4476 IF_STACK_FRAME
*temp
= pfile
->if_stack
;
4477 pfile
->if_stack
= temp
->next
;
4478 if (temp
->control_macro
!= 0)
4480 /* This #endif matched a #ifndef at the start of the file.
4481 See if it is at the end of the file. */
4482 struct parse_marker start_mark
;
4485 parse_set_mark (&start_mark
, pfile
);
4489 cpp_skip_hspace (pfile
);
4494 parse_goto_mark (&start_mark
, pfile
);
4495 parse_clear_mark (&start_mark
);
4499 /* If we get here, this #endif ends a #ifndef
4500 that contains all of the file (aside from whitespace).
4501 Arrange not to include the file again
4502 if the macro that was tested is defined.
4504 Do not do this for the top-level file in a -include or any
4505 file in a -imacros. */
4509 && ! (indepth
== 1 && pfile
->no_record_file
)
4510 && ! (pfile
->no_record_file
&& no_output
))
4513 struct file_name_list
*ifile
= pfile
->all_include_files
;
4515 for ( ; ifile
!= NULL
; ifile
= ifile
->next
)
4517 if (!strcmp (ifile
->fname
, CPP_BUFFER (pfile
)->fname
))
4519 ifile
->control_macro
= temp
->control_macro
;
4527 output_line_command (pfile
, 1, same_file
);
4532 /* When an #else or #endif is found while skipping failed conditional,
4533 if -pedantic was specified, this is called to warn about text after
4534 the command name. P points to the first char after the command name. */
4537 validate_else (pfile
, directive
)
4542 cpp_skip_hspace (pfile
);
4544 if (c
!= EOF
&& c
!= '\n')
4546 "text following `%s' violates ANSI standard", directive
);
4549 /* Get the next token, and add it to the text in pfile->token_buffer.
4550 Return the kind of token we got. */
4553 cpp_get_token (pfile
)
4556 register int c
, c2
, c3
;
4558 long start_line
, start_column
;
4559 enum cpp_token token
;
4560 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
4561 CPP_BUFFER (pfile
)->prev
= CPP_BUFFER (pfile
)->cur
;
4567 if (CPP_BUFFER (pfile
)->seen_eof
)
4569 if (cpp_pop_buffer (pfile
) != CPP_NULL_BUFFER (pfile
))
4576 cpp_buffer
*next_buf
4577 = CPP_PREV_BUFFER (CPP_BUFFER (pfile
));
4578 CPP_BUFFER (pfile
)->seen_eof
= 1;
4579 if (CPP_BUFFER (pfile
)->nominal_fname
4580 && next_buf
!= CPP_NULL_BUFFER (pfile
))
4582 /* We're about to return from an #include file.
4583 Emit #line information now (as part of the CPP_POP) result.
4584 But the #line refers to the file we will pop to. */
4585 cpp_buffer
*cur_buffer
= CPP_BUFFER (pfile
);
4586 CPP_BUFFER (pfile
) = next_buf
;
4587 pfile
->input_stack_listing_current
= 0;
4588 output_line_command (pfile
, 0, leave_file
);
4589 CPP_BUFFER (pfile
) = cur_buffer
;
4599 struct parse_marker start_mark
;
4601 if (PEEKC () == '=')
4603 if (opts
->put_out_comments
)
4604 parse_set_mark (&start_mark
, pfile
);
4606 cpp_buf_line_and_col (cpp_file_buffer (pfile
),
4607 &start_line
, &start_column
);
4608 c
= skip_comment (pfile
, &newlines
);
4609 if (opts
->put_out_comments
&& (c
== '/' || c
== EOF
))
4610 parse_clear_mark (&start_mark
);
4615 cpp_error_with_line (pfile
, start_line
, start_column
,
4616 "unterminated comment");
4619 c
= '/'; /* Initial letter of comment. */
4621 /* Comments are equivalent to spaces.
4622 For -traditional, a comment is equivalent to nothing. */
4623 if (opts
->put_out_comments
)
4625 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
4626 U_CHAR
*start
= pbuf
->buf
+ start_mark
.position
;
4627 int len
= pbuf
->cur
- start
;
4628 CPP_RESERVE(pfile
, 1 + len
);
4629 CPP_PUTC_Q (pfile
, c
);
4630 CPP_PUTS_Q (pfile
, start
, len
);
4631 pfile
->lineno
+= newlines
;
4632 parse_clear_mark (&start_mark
);
4635 else if (CPP_TRADITIONAL (pfile
))
4642 /* This may not work if cpp_get_token is called recursively,
4643 since many places look for horizontal space. */
4646 /* Copy the newlines into the output buffer, in order to
4647 avoid the pain of a #line every time a multiline comment
4649 CPP_RESERVE(pfile
, newlines
);
4650 while (--newlines
>= 0)
4652 CPP_PUTC_Q (pfile
, '\n');
4658 CPP_RESERVE(pfile
, 1);
4659 CPP_PUTC_Q (pfile
, ' ');
4663 if (opts
->for_lint
) {
4666 char *lintcmd
= get_lintcmd (ibp
, limit
, &argbp
, &arglen
, &cmdlen
);
4668 if (lintcmd
!= NULL
) {
4669 /* I believe it is always safe to emit this newline: */
4671 bcopy ("#pragma lint ", (char *) obp
, 13);
4673 bcopy (lintcmd
, (char *) obp
, cmdlen
);
4678 bcopy (argbp
, (char *) obp
, arglen
);
4682 /* OK, now bring us back to the state we were in before we entered
4683 this branch. We need #line because the newline for the pragma
4684 could mess things up. */
4685 output_line_command (pfile
, 0, same_file
);
4686 *(obp
++) = ' '; /* just in case, if comments are copied thru */
4694 /* If this is expanding a macro definition, don't recognize
4695 preprocessor directives. */
4698 /* If this is expand_into_temp_buffer, recognize them
4699 only after an actual newline at this level,
4700 not at the beginning of the input level. */
4701 if (ip
->fname
== 0 && beg_of_line
== ip
->buf
)
4707 if (!pfile
->only_seen_white
)
4709 if (handle_directive (pfile
))
4710 return CPP_DIRECTIVE
;
4711 pfile
->only_seen_white
= 0;
4716 /* A single quoted string is treated like a double -- some
4717 programs (e.g., troff) are perverse this way */
4718 cpp_buf_line_and_col (cpp_file_buffer (pfile
),
4719 &start_line
, &start_column
);
4720 old_written
= CPP_WRITTEN (pfile
);
4722 CPP_PUTC (pfile
, c
);
4728 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile
)))
4730 /* try harder: this string crosses a macro expansion
4731 boundary. This can happen naturally if -traditional.
4732 Otherwise, only -D can make a macro with an unmatched
4734 cpp_buffer
*next_buf
4735 = CPP_PREV_BUFFER (CPP_BUFFER (pfile
));
4736 (*CPP_BUFFER (pfile
)->cleanup
)
4737 (CPP_BUFFER (pfile
), pfile
);
4738 CPP_BUFFER (pfile
) = next_buf
;
4741 if (!CPP_TRADITIONAL (pfile
))
4743 cpp_error_with_line (pfile
, start_line
, start_column
,
4744 "unterminated string or character constant");
4745 if (pfile
->multiline_string_line
!= start_line
4746 && pfile
->multiline_string_line
!= 0)
4747 cpp_error_with_line (pfile
,
4748 pfile
->multiline_string_line
, -1,
4749 "possible real start of unterminated constant");
4750 pfile
->multiline_string_line
= 0;
4754 CPP_PUTC (pfile
, cc
);
4758 /* Traditionally, end of line ends a string constant with
4759 no error. So exit the loop and record the new line. */
4760 if (CPP_TRADITIONAL (pfile
))
4764 cpp_error_with_line (pfile
, start_line
, start_column
,
4765 "unterminated character constant");
4768 if (CPP_PEDANTIC (pfile
)
4769 && pfile
->multiline_string_line
== 0)
4771 cpp_pedwarn_with_line (pfile
, start_line
, start_column
,
4772 "string constant runs past end of line");
4774 if (pfile
->multiline_string_line
== 0)
4775 pfile
->multiline_string_line
= start_line
;
4782 /* Backslash newline is replaced by nothing at all. */
4783 CPP_ADJUST_WRITTEN (pfile
, -1);
4788 /* ANSI stupidly requires that in \\ the second \
4789 is *not* prevented from combining with a newline. */
4792 CPP_PUTC (pfile
, cc
);
4804 pfile
->lineno
+= count_newlines (pfile
->token_buffer
+ old_written
,
4805 CPP_PWRITTEN (pfile
));
4806 pfile
->only_seen_white
= 0;
4807 return c
== '\'' ? CPP_CHAR
: CPP_STRING
;
4810 if (!opts
->dollars_in_ident
)
4815 if (opts
->cplusplus
&& PEEKC () == ':')
4824 if (c2
== c
|| c2
== '=')
4834 if (PEEKC () == '=')
4841 if (c2
== '-' && opts
->chill
)
4843 /* Chill style comment */
4844 if (opts
->put_out_comments
)
4845 parse_set_mark (&start_mark
, pfile
);
4846 FORWARD(1); /* Skip second '-'. */
4854 /* Don't consider final '\n' to be part of comment. */
4860 goto return_comment
;
4862 if (c2
== '-' || c2
== '=' || c2
== '>')
4867 if (pfile
->parsing_include_directive
)
4871 CPP_PUTC (pfile
, c
);
4876 if (c
== '\n' || c
== EOF
)
4879 "missing '>' in `#include <FILENAME>'");
4885 /* else fall through */
4894 CPP_RESERVE (pfile
, 4);
4895 CPP_PUTC (pfile
, c
);
4896 CPP_PUTC (pfile
, c2
);
4900 CPP_PUTC_Q (pfile
, GETC ());
4901 CPP_NUL_TERMINATE_Q (pfile
);
4902 pfile
->only_seen_white
= 0;
4906 if (CPP_BUFFER (pfile
)->has_escapes
)
4911 if (pfile
->output_escapes
)
4912 CPP_PUTS (pfile
, "@-", 2);
4913 parse_name (pfile
, GETC ());
4916 else if (is_space
[c
])
4918 CPP_RESERVE (pfile
, 2);
4919 if (pfile
->output_escapes
)
4920 CPP_PUTC_Q (pfile
, '@');
4921 CPP_PUTC_Q (pfile
, c
);
4925 if (pfile
->output_escapes
)
4927 CPP_PUTS (pfile
, "@@", 2);
4937 CPP_RESERVE(pfile
, 2);
4938 CPP_PUTC_Q (pfile
, '.');
4942 /* FIXME - misses the case "..\\\n." */
4943 if (c2
== '.' && PEEKN(1) == '.')
4945 CPP_RESERVE(pfile
, 4);
4946 CPP_PUTC_Q (pfile
, '.');
4947 CPP_PUTC_Q (pfile
, '.');
4948 CPP_PUTC_Q (pfile
, '.');
4950 CPP_NUL_TERMINATE_Q (pfile
);
4951 pfile
->only_seen_white
= 0;
4958 pfile
->only_seen_white
= 0;
4960 CPP_RESERVE(pfile
, 3);
4961 CPP_PUTC_Q (pfile
, c
);
4962 CPP_PUTC_Q (pfile
, GETC ());
4963 CPP_NUL_TERMINATE_Q (pfile
);
4969 if ((c2
== '\'' || c2
== '\"') && !CPP_TRADITIONAL (pfile
))
4971 CPP_PUTC (pfile
, c
);
4977 case '0': case '1': case '2': case '3': case '4':
4978 case '5': case '6': case '7': case '8': case '9':
4983 CPP_RESERVE (pfile
, 2);
4984 CPP_PUTC_Q (pfile
, c
);
4989 if (!is_idchar
[c
] && c
!= '.'
4990 && ((c2
!= 'e' && c2
!= 'E'
4991 && ((c2
!= 'p' && c2
!= 'P') || CPP_C89 (pfile
)))
4992 || (c
!= '+' && c
!= '-')))
4997 CPP_NUL_TERMINATE_Q (pfile
);
4998 pfile
->only_seen_white
= 0;
5000 case 'b': case 'c': case 'd': case 'h': case 'o':
5001 case 'B': case 'C': case 'D': case 'H': case 'O':
5002 if (opts
->chill
&& PEEKC () == '\'')
5004 pfile
->only_seen_white
= 0;
5005 CPP_RESERVE (pfile
, 2);
5006 CPP_PUTC_Q (pfile
, c
);
5007 CPP_PUTC_Q (pfile
, '\'');
5013 goto chill_number_eof
;
5016 if (c
== '\\' && PEEKC() == '\n')
5023 CPP_PUTC (pfile
, c
);
5027 CPP_RESERVE (pfile
, 2);
5028 CPP_PUTC_Q (pfile
, c
);
5029 CPP_NUL_TERMINATE_Q (pfile
);
5036 CPP_NUL_TERMINATE (pfile
);
5043 case 'a': case 'e': case 'f': case 'g': case 'i': case 'j':
5044 case 'k': case 'l': case 'm': case 'n': case 'p': case 'q':
5045 case 'r': case 's': case 't': case 'u': case 'v': case 'w':
5046 case 'x': case 'y': case 'z':
5047 case 'A': case 'E': case 'F': case 'G': case 'I': case 'J':
5048 case 'K': case 'M': case 'N': case 'P': case 'Q': case 'R':
5049 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
5054 unsigned char *ident
;
5055 int before_name_written
= CPP_WRITTEN (pfile
);
5057 parse_name (pfile
, c
);
5058 pfile
->only_seen_white
= 0;
5059 if (pfile
->no_macro_expand
)
5061 ident
= pfile
->token_buffer
+ before_name_written
;
5062 ident_len
= CPP_PWRITTEN (pfile
) - ident
;
5063 hp
= cpp_lookup (pfile
, ident
, ident_len
, -1);
5066 if (hp
->type
== T_DISABLED
)
5068 if (pfile
->output_escapes
)
5069 { /* Return "@-IDENT", followed by '\0'. */
5071 CPP_RESERVE (pfile
, 3);
5072 ident
= pfile
->token_buffer
+ before_name_written
;
5073 CPP_ADJUST_WRITTEN (pfile
, 2);
5074 for (i
= ident_len
; i
>= 0; i
--) ident
[i
+2] = ident
[i
];
5081 /* If macro wants an arglist, verify that a '(' follows.
5082 first skip all whitespace, copying it to the output
5083 after the macro name. Then, if there is no '(',
5084 decide this is not a macro call and leave things that way. */
5085 if (hp
->type
== T_MACRO
&& hp
->value
.defn
->nargs
>= 0)
5087 struct parse_marker macro_mark
;
5089 while (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile
)))
5091 cpp_buffer
*next_buf
;
5092 cpp_skip_hspace (pfile
);
5093 if (PEEKC () != EOF
)
5095 next_buf
= CPP_PREV_BUFFER (CPP_BUFFER (pfile
));
5096 (*CPP_BUFFER (pfile
)->cleanup
) (CPP_BUFFER (pfile
), pfile
);
5097 CPP_BUFFER (pfile
) = next_buf
;
5099 parse_set_mark (¯o_mark
, pfile
);
5102 cpp_skip_hspace (pfile
);
5104 is_macro_call
= c
== '(';
5110 parse_goto_mark (¯o_mark
, pfile
);
5111 parse_clear_mark (¯o_mark
);
5115 /* This is now known to be a macro call. */
5117 /* it might not actually be a macro. */
5118 if (hp
->type
!= T_MACRO
) {
5119 int xbuf_len
; U_CHAR
*xbuf
;
5120 CPP_SET_WRITTEN (pfile
, before_name_written
);
5121 special_symbol (hp
, pfile
);
5122 xbuf_len
= CPP_WRITTEN (pfile
) - before_name_written
;
5123 xbuf
= (U_CHAR
*) xmalloc (xbuf_len
+ 1);
5124 CPP_SET_WRITTEN (pfile
, before_name_written
);
5125 bcopy (CPP_PWRITTEN (pfile
), xbuf
, xbuf_len
+ 1);
5126 push_macro_expansion (pfile
, xbuf
, xbuf_len
, hp
);
5130 /* Expand the macro, reading arguments as needed,
5131 and push the expansion on the input stack. */
5132 macroexpand (pfile
, hp
);
5133 CPP_SET_WRITTEN (pfile
, before_name_written
);
5136 /* An extra "@ " is added to the end of a macro expansion
5137 to prevent accidental token pasting. We prefer to avoid
5138 unneeded extra spaces (for the sake of cpp-using tools like
5139 imake). Here we remove the space if it is safe to do so. */
5140 if (pfile
->buffer
->rlimit
- pfile
->buffer
->cur
>= 3
5141 && pfile
->buffer
->rlimit
[-2] == '@'
5142 && pfile
->buffer
->rlimit
[-1] == ' ')
5144 int c1
= pfile
->buffer
->rlimit
[-3];
5145 int c2
= CPP_BUF_PEEK (CPP_PREV_BUFFER (CPP_BUFFER (pfile
)));
5146 if (c2
== EOF
|| ! unsafe_chars (c1
, c2
))
5147 pfile
->buffer
->rlimit
-= 2;
5152 case ' ': case '\t': case '\v': case '\r':
5155 CPP_PUTC (pfile
, c
);
5157 if (c
== EOF
|| !is_hor_space
[c
])
5171 CPP_PUTC (pfile
, c
);
5172 if (pfile
->only_seen_white
== 0)
5173 pfile
->only_seen_white
= 1;
5175 output_line_command (pfile
, 1, same_file
);
5178 case '(': token
= CPP_LPAREN
; goto char1
;
5179 case ')': token
= CPP_RPAREN
; goto char1
;
5180 case '{': token
= CPP_LBRACE
; goto char1
;
5181 case '}': token
= CPP_RBRACE
; goto char1
;
5182 case ',': token
= CPP_COMMA
; goto char1
;
5183 case ';': token
= CPP_SEMICOLON
; goto char1
;
5189 pfile
->only_seen_white
= 0;
5190 CPP_PUTC (pfile
, c
);
5196 /* Like cpp_get_token, but skip spaces and comments. */
5199 cpp_get_non_space_token (pfile
)
5202 int old_written
= CPP_WRITTEN (pfile
);
5205 enum cpp_token token
= cpp_get_token (pfile
);
5206 if (token
!= CPP_COMMENT
&& token
!= CPP_POP
5207 && token
!= CPP_HSPACE
&& token
!= CPP_VSPACE
)
5209 CPP_SET_WRITTEN (pfile
, old_written
);
5213 /* Parse an identifier starting with C. */
5216 parse_name (pfile
, c
)
5217 cpp_reader
*pfile
; int c
;
5223 if (c
== '\\' && PEEKC() == '\n')
5232 if (c
== '$' && CPP_PEDANTIC (pfile
))
5233 cpp_pedwarn (pfile
, "`$' in identifier");
5235 CPP_RESERVE(pfile
, 2); /* One more for final NUL. */
5236 CPP_PUTC_Q (pfile
, c
);
5241 CPP_NUL_TERMINATE_Q (pfile
);
5246 /* Maintain and search list of included files, for #import. */
5248 /* Hash a file name for import_hash_table. */
5256 while (*f
) val
+= *f
++;
5257 return (val
%IMPORT_HASH_SIZE
);
5260 /* Search for file FILENAME in import_hash_table.
5261 Return -2 if found, either a matching name or a matching inode.
5262 Otherwise, open the file and return a file descriptor if successful
5263 or -1 if unsuccessful. */
5266 lookup_import (pfile
, filename
, searchptr
)
5269 struct file_name_list
*searchptr
;
5271 struct import_file
*i
;
5277 hashval
= import_hash (filename
);
5279 /* Attempt to find file in list of already included files */
5280 i
= pfile
->import_hash_table
[hashval
];
5283 if (!strcmp (filename
, i
->name
))
5284 return -2; /* return found */
5287 /* Open it and try a match on inode/dev */
5288 fd
= open_include_file (pfile
, filename
, searchptr
);
5292 for (h
= 0; h
< IMPORT_HASH_SIZE
; h
++) {
5293 i
= pfile
->import_hash_table
[h
];
5295 /* Compare the inode and the device.
5296 Supposedly on some systems the inode is not a scalar. */
5297 if (!bcmp ((char *) &i
->inode
, (char *) &sb
.st_ino
, sizeof (sb
.st_ino
))
5298 && i
->dev
== sb
.st_dev
) {
5300 return -2; /* return found */
5305 return fd
; /* Not found, return open file */
5308 /* Add the file FNAME, open on descriptor FD, to import_hash_table. */
5311 add_import (pfile
, fd
, fname
)
5316 struct import_file
*i
;
5320 hashval
= import_hash (fname
);
5322 i
= (struct import_file
*)xmalloc (sizeof (struct import_file
));
5323 i
->name
= (char *)xmalloc (strlen (fname
)+1);
5324 strcpy (i
->name
, fname
);
5325 bcopy ((char *) &sb
.st_ino
, (char *) &i
->inode
, sizeof (sb
.st_ino
));
5327 i
->next
= pfile
->import_hash_table
[hashval
];
5328 pfile
->import_hash_table
[hashval
] = i
;
5331 /* The file_name_map structure holds a mapping of file names for a
5332 particular directory. This mapping is read from the file named
5333 FILE_NAME_MAP_FILE in that directory. Such a file can be used to
5334 map filenames on a file system with severe filename restrictions,
5335 such as DOS. The format of the file name map file is just a series
5336 of lines with two tokens on each line. The first token is the name
5337 to map, and the second token is the actual name to use. */
5339 struct file_name_map
5341 struct file_name_map
*map_next
;
5346 #define FILE_NAME_MAP_FILE "header.gcc"
5348 /* Read a space delimited string of unlimited length from a stdio
5352 read_filename_string (ch
, f
)
5360 set
= alloc
= xmalloc (len
+ 1);
5364 while ((ch
= getc (f
)) != EOF
&& ! is_space
[ch
])
5366 if (set
- alloc
== len
)
5369 alloc
= xrealloc (alloc
, len
+ 1);
5370 set
= alloc
+ len
/ 2;
5380 /* This structure holds a linked list of file name maps, one per directory. */
5382 struct file_name_map_list
5384 struct file_name_map_list
*map_list_next
;
5385 char *map_list_name
;
5386 struct file_name_map
*map_list_map
;
5389 /* Read the file name map file for DIRNAME. */
5391 static struct file_name_map
*
5392 read_name_map (pfile
, dirname
)
5396 register struct file_name_map_list
*map_list_ptr
;
5400 for (map_list_ptr
= CPP_OPTIONS (pfile
)->map_list
; map_list_ptr
;
5401 map_list_ptr
= map_list_ptr
->map_list_next
)
5402 if (! strcmp (map_list_ptr
->map_list_name
, dirname
))
5403 return map_list_ptr
->map_list_map
;
5405 map_list_ptr
= ((struct file_name_map_list
*)
5406 xmalloc (sizeof (struct file_name_map_list
)));
5407 map_list_ptr
->map_list_name
= savestring (dirname
);
5408 map_list_ptr
->map_list_map
= NULL
;
5410 name
= (char *) alloca (strlen (dirname
) + strlen (FILE_NAME_MAP_FILE
) + 2);
5411 strcpy (name
, dirname
);
5414 strcat (name
, FILE_NAME_MAP_FILE
);
5415 f
= fopen (name
, "r");
5417 map_list_ptr
->map_list_map
= NULL
;
5421 int dirlen
= strlen (dirname
);
5423 while ((ch
= getc (f
)) != EOF
)
5426 struct file_name_map
*ptr
;
5430 from
= read_filename_string (ch
, f
);
5431 while ((ch
= getc (f
)) != EOF
&& is_hor_space
[ch
])
5433 to
= read_filename_string (ch
, f
);
5435 ptr
= ((struct file_name_map
*)
5436 xmalloc (sizeof (struct file_name_map
)));
5437 ptr
->map_from
= from
;
5439 /* Make the real filename absolute. */
5444 ptr
->map_to
= xmalloc (dirlen
+ strlen (to
) + 2);
5445 strcpy (ptr
->map_to
, dirname
);
5446 ptr
->map_to
[dirlen
] = '/';
5447 strcpy (ptr
->map_to
+ dirlen
+ 1, to
);
5451 ptr
->map_next
= map_list_ptr
->map_list_map
;
5452 map_list_ptr
->map_list_map
= ptr
;
5454 while ((ch
= getc (f
)) != '\n')
5461 map_list_ptr
->map_list_next
= CPP_OPTIONS (pfile
)->map_list
;
5462 CPP_OPTIONS (pfile
)->map_list
= map_list_ptr
;
5464 return map_list_ptr
->map_list_map
;
5467 /* Try to open include file FILENAME. SEARCHPTR is the directory
5468 being tried from the include file search path. This function maps
5469 filenames on file systems based on information read by
5473 open_include_file (pfile
, filename
, searchptr
)
5476 struct file_name_list
*searchptr
;
5478 if (CPP_OPTIONS (pfile
)->remap
)
5480 register struct file_name_map
*map
;
5481 register char *from
;
5484 if (searchptr
&& ! searchptr
->got_name_map
)
5486 searchptr
->name_map
= read_name_map (pfile
,
5488 ? searchptr
->fname
: ".");
5489 searchptr
->got_name_map
= 1;
5492 /* First check the mapping for the directory we are using. */
5493 if (searchptr
&& searchptr
->name_map
)
5496 if (searchptr
->fname
)
5497 from
+= strlen (searchptr
->fname
) + 1;
5498 for (map
= searchptr
->name_map
; map
; map
= map
->map_next
)
5500 if (! strcmp (map
->map_from
, from
))
5502 /* Found a match. */
5503 return open (map
->map_to
, O_RDONLY
, 0666);
5508 /* Try to find a mapping file for the particular directory we are
5509 looking in. Thus #include <sys/types.h> will look up sys/types.h
5510 in /usr/include/header.gcc and look up types.h in
5511 /usr/include/sys/header.gcc. */
5512 p
= rindex (filename
, '/');
5517 && strlen (searchptr
->fname
) == p
- filename
5518 && ! strncmp (searchptr
->fname
, filename
, p
- filename
))
5520 /* FILENAME is in SEARCHPTR, which we've already checked. */
5521 return open (filename
, O_RDONLY
, 0666);
5531 dir
= (char *) alloca (p
- filename
+ 1);
5532 bcopy (filename
, dir
, p
- filename
);
5533 dir
[p
- filename
] = '\0';
5536 for (map
= read_name_map (pfile
, dir
); map
; map
= map
->map_next
)
5537 if (! strcmp (map
->map_from
, from
))
5538 return open (map
->map_to
, O_RDONLY
, 0666);
5541 return open (filename
, O_RDONLY
, 0666);
5544 /* Process the contents of include file FNAME, already open on descriptor F,
5546 SYSTEM_HEADER_P is 1 if this file resides in any one of the known
5547 "system" include directories (as decided by the `is_system_include'
5549 DIRPTR is the link in the dir path through which this file was found,
5550 or 0 if the file name was absolute or via the current directory.
5551 Return 1 on success, 0 on failure.
5553 The caller is responsible for the cpp_push_buffer. */
5556 finclude (pfile
, f
, fname
, system_header_p
, dirptr
)
5560 int system_header_p
;
5561 struct file_name_list
*dirptr
;
5567 cpp_buffer
*fp
; /* For input stack frame */
5569 int missing_newline
= 0;
5572 if (fstat (f
, &st
) < 0)
5574 cpp_perror_with_name (pfile
, fname
);
5576 cpp_pop_buffer (pfile
);
5580 fp
= CPP_BUFFER (pfile
);
5581 fp
->nominal_fname
= fp
->fname
= fname
;
5586 fp
->system_header_p
= system_header_p
;
5589 fp
->cleanup
= file_cleanup
;
5591 if (S_ISREG (st
.st_mode
)) {
5592 st_size
= (size_t) st
.st_size
;
5593 if (st_size
!= st
.st_size
|| st_size
+ 2 < st_size
) {
5594 cpp_error (pfile
, "file `%s' too large", fname
);
5598 fp
->buf
= (U_CHAR
*) xmalloc (st_size
+ 2);
5599 fp
->alimit
= fp
->buf
+ st_size
+ 2;
5602 /* Read the file contents, knowing that st_size is an upper bound
5603 on the number of bytes we can read. */
5604 length
= safe_read (f
, fp
->buf
, st_size
);
5605 fp
->rlimit
= fp
->buf
+ length
;
5606 if (length
< 0) goto nope
;
5608 else if (S_ISDIR (st
.st_mode
)) {
5609 cpp_error (pfile
, "directory `%s' specified in #include", fname
);
5613 /* Cannot count its file size before reading.
5614 First read the entire file into heap and
5615 copy them into buffer on stack. */
5620 fp
->buf
= (U_CHAR
*) xmalloc (bsize
+ 2);
5623 i
= safe_read (f
, fp
->buf
+ st_size
, bsize
- st_size
);
5625 goto nope
; /* error! */
5627 if (st_size
!= bsize
)
5628 break; /* End of file */
5630 fp
->buf
= (U_CHAR
*) xrealloc (fp
->buf
, bsize
+ 2);
5636 if ((length
> 0 && fp
->buf
[length
- 1] != '\n')
5637 /* Backslash-newline at end is not good enough. */
5638 || (length
> 1 && fp
->buf
[length
- 2] == '\\')) {
5639 fp
->buf
[length
++] = '\n';
5641 missing_newline
= 1;
5644 fp
->buf
[length
] = '\0';
5645 fp
->rlimit
= fp
->buf
+ length
;
5647 /* Close descriptor now, so nesting does not use lots of descriptors. */
5650 /* Must do this before calling trigraph_pcp, so that the correct file name
5651 will be printed in warning messages. */
5653 pfile
->input_stack_listing_current
= 0;
5663 if (missing_newline
)
5666 if (CPP_PEDANTIC (pfile
) && missing_newline
)
5667 pedwarn ("file does not end in newline");
5670 input_file_stack_tick
++;
5677 cpp_perror_with_name (pfile
, fname
);
5683 /* This is called after options have been processed.
5684 * Check options for consistency, and setup for processing input
5685 * from the file named FNAME. (Use standard input if FNAME==NULL.)
5686 * Return 1 on success, 0 on failure.
5690 cpp_start_read (pfile
, fname
)
5694 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
5695 struct cpp_pending
*pend
;
5700 /* The code looks at the defaults through this pointer, rather than through
5701 the constant structure above. This pointer gets changed if an environment
5702 variable specifies other defaults. */
5703 struct default_include
*include_defaults
= include_defaults_array
;
5705 /* Add dirs from CPATH after dirs from -I. */
5706 /* There seems to be confusion about what CPATH should do,
5707 so for the moment it is not documented. */
5708 /* Some people say that CPATH should replace the standard include dirs,
5709 but that seems pointless: it comes before them, so it overrides them
5711 GET_ENVIRONMENT (p
, "CPATH");
5712 if (p
!= 0 && ! opts
->no_standard_includes
)
5713 path_include (pfile
, p
);
5715 /* Now that dollars_in_ident is known, initialize is_idchar. */
5716 initialize_char_syntax (opts
);
5718 /* Do partial setup of input buffer for the sake of generating
5719 early #line directives (when -g is in effect). */
5720 fp
= cpp_push_buffer (pfile
, NULL
, 0);
5723 if (opts
->in_fname
== NULL
)
5724 opts
->in_fname
= "";
5725 fp
->nominal_fname
= fp
->fname
= opts
->in_fname
;
5728 /* Install __LINE__, etc. Must follow initialize_char_syntax
5729 and option processing. */
5730 initialize_builtins (pfile
);
5732 /* Do standard #defines and assertions
5733 that identify system and machine type. */
5735 if (!opts
->inhibit_predefs
) {
5736 char *p
= (char *) alloca (strlen (predefs
) + 1);
5737 strcpy (p
, predefs
);
5740 while (*p
== ' ' || *p
== '\t')
5742 /* Handle -D options. */
5743 if (p
[0] == '-' && p
[1] == 'D') {
5745 while (*p
&& *p
!= ' ' && *p
!= '\t')
5749 if (opts
->debug_output
)
5750 output_line_command (pfile
, 0, same_file
);
5751 cpp_define (pfile
, q
);
5752 while (*p
== ' ' || *p
== '\t')
5754 } else if (p
[0] == '-' && p
[1] == 'A') {
5755 /* Handle -A options (assertions). */
5764 past_name
= assertion
;
5765 /* Locate end of name. */
5766 while (*past_name
&& *past_name
!= ' '
5767 && *past_name
!= '\t' && *past_name
!= '(')
5769 /* Locate `(' at start of value. */
5771 while (*value
&& (*value
== ' ' || *value
== '\t'))
5773 if (*value
++ != '(')
5775 while (*value
&& (*value
== ' ' || *value
== '\t'))
5778 /* Locate end of value. */
5779 while (*past_value
&& *past_value
!= ' '
5780 && *past_value
!= '\t' && *past_value
!= ')')
5782 termination
= past_value
;
5783 while (*termination
&& (*termination
== ' ' || *termination
== '\t'))
5785 if (*termination
++ != ')')
5787 if (*termination
&& *termination
!= ' ' && *termination
!= '\t')
5789 /* Temporarily null-terminate the value. */
5790 save_char
= *termination
;
5791 *termination
= '\0';
5792 /* Install the assertion. */
5793 make_assertion (pfile
, "-A", assertion
);
5794 *termination
= (char) save_char
;
5796 while (*p
== ' ' || *p
== '\t')
5804 /* Now handle the command line options. */
5806 /* Do -U's, -D's and -A's in the order they were seen. */
5807 /* First reverse the list. */
5808 opts
->pending
= nreverse_pending (opts
->pending
);
5810 for (pend
= opts
->pending
; pend
; pend
= pend
->next
)
5812 if (pend
->cmd
!= NULL
&& pend
->cmd
[0] == '-')
5814 switch (pend
->cmd
[1])
5817 if (opts
->debug_output
)
5818 output_line_command (pfile
, 0, same_file
);
5819 do_undef (pfile
, NULL
, pend
->arg
, pend
->arg
+ strlen (pend
->arg
));
5822 if (opts
->debug_output
)
5823 output_line_command (pfile
, 0, same_file
);
5824 cpp_define (pfile
, pend
->arg
);
5827 make_assertion (pfile
, "-A", pend
->arg
);
5833 opts
->done_initializing
= 1;
5835 { /* Read the appropriate environment variable and if it exists
5836 replace include_defaults with the listed path. */
5838 switch ((opts
->objc
<< 1) + opts
->cplusplus
)
5841 GET_ENVIRONMENT (epath
, "C_INCLUDE_PATH");
5844 GET_ENVIRONMENT (epath
, "CPLUS_INCLUDE_PATH");
5847 GET_ENVIRONMENT (epath
, "OBJC_INCLUDE_PATH");
5850 GET_ENVIRONMENT (epath
, "OBJCPLUS_INCLUDE_PATH");
5853 /* If the environment var for this language is set,
5854 add to the default list of include directories. */
5856 char *nstore
= (char *) alloca (strlen (epath
) + 2);
5858 char *startp
, *endp
;
5860 for (num_dirs
= 1, startp
= epath
; *startp
; startp
++)
5861 if (*startp
== PATH_SEPARATOR
)
5864 = (struct default_include
*) xmalloc ((num_dirs
5865 * sizeof (struct default_include
))
5866 + sizeof (include_defaults_array
));
5867 startp
= endp
= epath
;
5870 /* Handle cases like c:/usr/lib:d:/gcc/lib */
5871 if ((*endp
== PATH_SEPARATOR
)
5873 strncpy (nstore
, startp
, endp
-startp
);
5875 strcpy (nstore
, ".");
5877 nstore
[endp
-startp
] = '\0';
5879 include_defaults
[num_dirs
].fname
= savestring (nstore
);
5880 include_defaults
[num_dirs
].component
= 0;
5881 include_defaults
[num_dirs
].cplusplus
= opts
->cplusplus
;
5882 include_defaults
[num_dirs
].cxx_aware
= 1;
5886 endp
= startp
= endp
+ 1;
5890 /* Put the usual defaults back in at the end. */
5891 bcopy ((char *) include_defaults_array
,
5892 (char *) &include_defaults
[num_dirs
],
5893 sizeof (include_defaults_array
));
5897 append_include_chain (pfile
, opts
->before_system
, opts
->last_before_system
);
5898 opts
->first_system_include
= opts
->before_system
;
5900 /* Unless -fnostdinc,
5901 tack on the standard include file dirs to the specified list */
5902 if (!opts
->no_standard_includes
) {
5903 struct default_include
*p
= include_defaults
;
5904 char *specd_prefix
= opts
->include_prefix
;
5905 char *default_prefix
= savestring (GCC_INCLUDE_DIR
);
5906 int default_len
= 0;
5907 /* Remove the `include' from /usr/local/lib/gcc.../include. */
5908 if (!strcmp (default_prefix
+ strlen (default_prefix
) - 8, "/include")) {
5909 default_len
= strlen (default_prefix
) - 7;
5910 default_prefix
[default_len
] = 0;
5912 /* Search "translated" versions of GNU directories.
5913 These have /usr/local/lib/gcc... replaced by specd_prefix. */
5914 if (specd_prefix
!= 0 && default_len
!= 0)
5915 for (p
= include_defaults
; p
->fname
; p
++) {
5916 /* Some standard dirs are only for C++. */
5918 || (opts
->cplusplus
&& !opts
->no_standard_cplusplus_includes
)) {
5919 /* Does this dir start with the prefix? */
5920 if (!strncmp (p
->fname
, default_prefix
, default_len
)) {
5921 /* Yes; change prefix and add to search list. */
5922 struct file_name_list
*new
5923 = (struct file_name_list
*) xmalloc (sizeof (struct file_name_list
));
5924 int this_len
= strlen (specd_prefix
) + strlen (p
->fname
) - default_len
;
5925 char *str
= (char *) xmalloc (this_len
+ 1);
5926 strcpy (str
, specd_prefix
);
5927 strcat (str
, p
->fname
+ default_len
);
5929 new->control_macro
= 0;
5930 new->c_system_include_path
= !p
->cxx_aware
;
5931 new->got_name_map
= 0;
5932 append_include_chain (pfile
, new, new);
5933 if (opts
->first_system_include
== 0)
5934 opts
->first_system_include
= new;
5938 /* Search ordinary names for GNU include directories. */
5939 for (p
= include_defaults
; p
->fname
; p
++) {
5940 /* Some standard dirs are only for C++. */
5942 || (opts
->cplusplus
&& !opts
->no_standard_cplusplus_includes
)) {
5943 struct file_name_list
*new
5944 = (struct file_name_list
*) xmalloc (sizeof (struct file_name_list
));
5945 new->control_macro
= 0;
5946 new->c_system_include_path
= !p
->cxx_aware
;
5947 new->fname
= update_path (p
->fname
, p
->component
);
5948 new->got_name_map
= 0;
5949 append_include_chain (pfile
, new, new);
5950 if (opts
->first_system_include
== 0)
5951 opts
->first_system_include
= new;
5956 /* Tack the after_include chain at the end of the include chain. */
5957 append_include_chain (pfile
, opts
->after_include
, opts
->last_after_include
);
5958 if (opts
->first_system_include
== 0)
5959 opts
->first_system_include
= opts
->after_include
;
5961 /* With -v, print the list of dirs to search. */
5962 if (opts
->verbose
) {
5963 struct file_name_list
*p
;
5964 fprintf (stderr
, "#include \"...\" search starts here:\n");
5965 for (p
= opts
->include
; p
; p
= p
->next
) {
5966 if (p
== opts
->first_bracket_include
)
5967 fprintf (stderr
, "#include <...> search starts here:\n");
5968 fprintf (stderr
, " %s\n", p
->fname
);
5970 fprintf (stderr
, "End of search list.\n");
5973 /* Scan the -imacros files before the main input.
5974 Much like #including them, but with no_output set
5975 so that only their macro definitions matter. */
5977 opts
->no_output
++; pfile
->no_record_file
++;
5978 for (pend
= opts
->pending
; pend
; pend
= pend
->next
)
5980 if (pend
->cmd
!= NULL
&& strcmp (pend
->cmd
, "-imacros") == 0)
5982 int fd
= open (pend
->arg
, O_RDONLY
, 0666);
5985 cpp_perror_with_name (pfile
, pend
->arg
);
5988 if (!cpp_push_buffer (pfile
, NULL
, 0))
5990 finclude (pfile
, fd
, pend
->arg
, 0, NULL_PTR
);
5991 cpp_scan_buffer (pfile
);
5994 opts
->no_output
--; pfile
->no_record_file
--;
5996 /* Copy the entire contents of the main input file into
5997 the stacked input buffer previously allocated for it. */
5998 if (fname
== NULL
|| *fname
== 0) {
6001 } else if ((f
= open (fname
, O_RDONLY
, 0666)) < 0)
6002 cpp_pfatal_with_name (pfile
, fname
);
6004 /* -MG doesn't select the form of output and must be specified with one of
6005 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
6006 inhibit compilation. */
6007 if (opts
->print_deps_missing_files
6008 && (opts
->print_deps
== 0 || !opts
->no_output
))
6010 cpp_fatal (pfile
, "-MG must be specified with one of -M or -MM");
6014 /* Either of two environment variables can specify output of deps.
6015 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
6016 where OUTPUT_FILE is the file to write deps info to
6017 and DEPS_TARGET is the target to mention in the deps. */
6019 if (opts
->print_deps
== 0
6020 && (getenv ("SUNPRO_DEPENDENCIES") != 0
6021 || getenv ("DEPENDENCIES_OUTPUT") != 0)) {
6022 char *spec
= getenv ("DEPENDENCIES_OUTPUT");
6028 spec
= getenv ("SUNPRO_DEPENDENCIES");
6029 opts
->print_deps
= 2;
6032 opts
->print_deps
= 1;
6035 /* Find the space before the DEPS_TARGET, if there is one. */
6036 /* This should use index. (mrs) */
6037 while (*s
!= 0 && *s
!= ' ') s
++;
6040 opts
->deps_target
= s
+ 1;
6041 output_file
= (char *) xmalloc (s
- spec
+ 1);
6042 bcopy (spec
, output_file
, s
- spec
);
6043 output_file
[s
- spec
] = 0;
6047 opts
->deps_target
= 0;
6051 opts
->deps_file
= output_file
;
6052 opts
->print_deps_append
= 1;
6055 /* For -M, print the expected object file name
6056 as the target of this Make-rule. */
6057 if (opts
->print_deps
)
6059 pfile
->deps_allocated_size
= 200;
6060 pfile
->deps_buffer
= (char *) xmalloc (pfile
->deps_allocated_size
);
6061 pfile
->deps_buffer
[0] = 0;
6062 pfile
->deps_size
= 0;
6063 pfile
->deps_column
= 0;
6065 if (opts
->deps_target
)
6066 deps_output (pfile
, opts
->deps_target
, ':');
6067 else if (*opts
->in_fname
== 0)
6068 deps_output (pfile
, "-", ':');
6073 static char *known_suffixes
[] = { ".c", ".C", ".s", ".S", ".m",
6074 ".cc", ".cxx", ".cpp", ".cp",
6078 /* Discard all directory prefixes from filename. */
6079 if ((q
= rindex (opts
->in_fname
, '/')) != NULL
6080 #ifdef DIR_SEPARATOR
6081 && (q
= rindex (opts
->in_fname
, DIR_SEPARATOR
)) != NULL
6088 /* Copy remainder to mungable area. */
6089 p
= (char *) alloca (strlen(q
) + 8);
6092 /* Output P, but remove known suffixes. */
6095 /* Point to the filename suffix. */
6096 r
= rindex (p
, '.');
6097 /* Compare against the known suffixes. */
6099 while (known_suffixes
[x
] != 0)
6101 if (strncmp (known_suffixes
[x
], r
, q
- r
) == 0)
6103 /* Make q point to the bit we're going to overwrite
6104 with an object suffix. */
6111 /* Supply our own suffix. */
6118 deps_output (pfile
, p
, ':');
6119 deps_output (pfile
, opts
->in_fname
, ' ');
6124 /* Make sure data ends with a newline. And put a null after it. */
6126 if ((fp
->length
> 0 && fp
->buf
[fp
->length
- 1] != '\n')
6127 /* Backslash-newline at end is not good enough. */
6128 || (fp
->length
> 1 && fp
->buf
[fp
->length
- 2] == '\\')) {
6129 fp
->buf
[fp
->length
++] = '\n';
6130 missing_newline
= 1;
6132 fp
->buf
[fp
->length
] = '\0';
6134 /* Unless inhibited, convert trigraphs in the input. */
6140 /* Scan the -include files before the main input.
6141 We push these in reverse order, so that the first one is handled first. */
6143 pfile
->no_record_file
++;
6144 opts
->pending
= nreverse_pending (opts
->pending
);
6145 for (pend
= opts
->pending
; pend
; pend
= pend
->next
)
6147 if (pend
->cmd
!= NULL
&& strcmp (pend
->cmd
, "-include") == 0)
6149 int fd
= open (pend
->arg
, O_RDONLY
, 0666);
6152 cpp_perror_with_name (pfile
, pend
->arg
);
6155 if (!cpp_push_buffer (pfile
, NULL
, 0))
6157 finclude (pfile
, fd
, pend
->arg
, 0, NULL_PTR
);
6160 pfile
->no_record_file
--;
6162 /* Free the pending list. */
6163 for (pend
= opts
->pending
; pend
; )
6165 struct cpp_pending
*next
= pend
->next
;
6169 opts
->pending
= NULL
;
6172 /* Scan the input, processing macros and directives. */
6174 rescan (&outbuf
, 0);
6176 if (missing_newline
)
6179 if (CPP_PEDANTIC (pfile
) && missing_newline
)
6180 pedwarn ("file does not end in newline");
6183 if (finclude (pfile
, f
, fname
, 0, NULL_PTR
))
6184 output_line_command (pfile
, 0, same_file
);
6189 cpp_reader_init (pfile
)
6192 bzero ((char *) pfile
, sizeof (cpp_reader
));
6193 pfile
->get_token
= cpp_get_token
;
6195 pfile
->token_buffer_size
= 200;
6196 pfile
->token_buffer
= (U_CHAR
*) xmalloc (pfile
->token_buffer_size
);
6197 CPP_SET_WRITTEN (pfile
, 0);
6199 pfile
->system_include_depth
= 0;
6200 pfile
->dont_repeat_files
= 0;
6201 pfile
->all_include_files
= 0;
6202 pfile
->max_include_len
= 0;
6203 pfile
->timebuf
= NULL
;
6204 pfile
->only_seen_white
= 1;
6205 pfile
->buffer
= CPP_NULL_BUFFER(pfile
);
6208 static struct cpp_pending
*
6209 nreverse_pending (list
)
6210 struct cpp_pending
*list
;
6213 register struct cpp_pending
*prev
= 0, *next
, *pend
;
6214 for (pend
= list
; pend
; pend
= next
)
6224 push_pending (pfile
, cmd
, arg
)
6229 struct cpp_pending
*pend
6230 = (struct cpp_pending
*) xmalloc (sizeof (struct cpp_pending
));
6233 pend
->next
= CPP_OPTIONS (pfile
)->pending
;
6234 CPP_OPTIONS (pfile
)->pending
= pend
;
6237 /* Handle one command-line option in (argc, argv).
6238 Can be called multiple times, to handle multiple sets of options.
6239 Returns number of strings consumed. */
6241 cpp_handle_option (pfile
, argc
, argv
)
6246 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
6248 if (argv
[i
][0] != '-') {
6249 if (opts
->out_fname
!= NULL
)
6251 cpp_fatal (pfile
, "Usage: %s [switches] input output", argv
[0]);
6254 else if (opts
->in_fname
!= NULL
)
6255 opts
->out_fname
= argv
[i
];
6257 opts
->in_fname
= argv
[i
];
6259 switch (argv
[i
][1]) {
6262 cpp_fatal (pfile
, "Filename missing after `%s' option", argv
[i
]);
6265 cpp_fatal (pfile
, "Directory name missing after `%s' option", argv
[i
]);
6269 if (!strcmp (argv
[i
], "-include")
6270 || !strcmp (argv
[i
], "-imacros")) {
6272 goto missing_filename
;
6274 push_pending (pfile
, argv
[i
], argv
[i
+1]), i
++;
6276 if (!strcmp (argv
[i
], "-iprefix")) {
6278 goto missing_filename
;
6280 opts
->include_prefix
= argv
[++i
];
6282 if (!strcmp (argv
[i
], "-ifoutput")) {
6283 opts
->output_conditionals
= 1;
6285 if (!strcmp (argv
[i
], "-isystem")) {
6286 struct file_name_list
*dirtmp
;
6289 goto missing_filename
;
6291 dirtmp
= (struct file_name_list
*)
6292 xmalloc (sizeof (struct file_name_list
));
6294 dirtmp
->control_macro
= 0;
6295 dirtmp
->c_system_include_path
= 1;
6296 dirtmp
->fname
= (char *) xmalloc (strlen (argv
[i
+1]) + 1);
6297 strcpy (dirtmp
->fname
, argv
[++i
]);
6298 dirtmp
->got_name_map
= 0;
6300 if (opts
->before_system
== 0)
6301 opts
->before_system
= dirtmp
;
6303 opts
->last_before_system
->next
= dirtmp
;
6304 opts
->last_before_system
= dirtmp
; /* Tail follows the last one */
6306 /* Add directory to end of path for includes,
6307 with the default prefix at the front of its name. */
6308 if (!strcmp (argv
[i
], "-iwithprefix")) {
6309 struct file_name_list
*dirtmp
;
6312 if (opts
->include_prefix
!= 0)
6313 prefix
= opts
->include_prefix
;
6315 prefix
= savestring (GCC_INCLUDE_DIR
);
6316 /* Remove the `include' from /usr/local/lib/gcc.../include. */
6317 if (!strcmp (prefix
+ strlen (prefix
) - 8, "/include"))
6318 prefix
[strlen (prefix
) - 7] = 0;
6321 dirtmp
= (struct file_name_list
*)
6322 xmalloc (sizeof (struct file_name_list
));
6323 dirtmp
->next
= 0; /* New one goes on the end */
6324 dirtmp
->control_macro
= 0;
6325 dirtmp
->c_system_include_path
= 0;
6327 goto missing_dirname
;
6329 dirtmp
->fname
= (char *) xmalloc (strlen (argv
[i
+1])
6330 + strlen (prefix
) + 1);
6331 strcpy (dirtmp
->fname
, prefix
);
6332 strcat (dirtmp
->fname
, argv
[++i
]);
6333 dirtmp
->got_name_map
= 0;
6335 if (opts
->after_include
== 0)
6336 opts
->after_include
= dirtmp
;
6338 opts
->last_after_include
->next
= dirtmp
;
6339 opts
->last_after_include
= dirtmp
; /* Tail follows the last one */
6341 /* Add directory to main path for includes,
6342 with the default prefix at the front of its name. */
6343 if (!strcmp (argv
[i
], "-iwithprefixbefore")) {
6344 struct file_name_list
*dirtmp
;
6347 if (opts
->include_prefix
!= 0)
6348 prefix
= opts
->include_prefix
;
6350 prefix
= savestring (GCC_INCLUDE_DIR
);
6351 /* Remove the `include' from /usr/local/lib/gcc.../include. */
6352 if (!strcmp (prefix
+ strlen (prefix
) - 8, "/include"))
6353 prefix
[strlen (prefix
) - 7] = 0;
6356 dirtmp
= (struct file_name_list
*)
6357 xmalloc (sizeof (struct file_name_list
));
6358 dirtmp
->next
= 0; /* New one goes on the end */
6359 dirtmp
->control_macro
= 0;
6360 dirtmp
->c_system_include_path
= 0;
6362 goto missing_dirname
;
6364 dirtmp
->fname
= (char *) xmalloc (strlen (argv
[i
+1])
6365 + strlen (prefix
) + 1);
6366 strcpy (dirtmp
->fname
, prefix
);
6367 strcat (dirtmp
->fname
, argv
[++i
]);
6368 dirtmp
->got_name_map
= 0;
6370 append_include_chain (pfile
, dirtmp
, dirtmp
);
6372 /* Add directory to end of path for includes. */
6373 if (!strcmp (argv
[i
], "-idirafter")) {
6374 struct file_name_list
*dirtmp
;
6376 dirtmp
= (struct file_name_list
*)
6377 xmalloc (sizeof (struct file_name_list
));
6378 dirtmp
->next
= 0; /* New one goes on the end */
6379 dirtmp
->control_macro
= 0;
6380 dirtmp
->c_system_include_path
= 0;
6382 goto missing_dirname
;
6384 dirtmp
->fname
= argv
[++i
];
6385 dirtmp
->got_name_map
= 0;
6387 if (opts
->after_include
== 0)
6388 opts
->after_include
= dirtmp
;
6390 opts
->last_after_include
->next
= dirtmp
;
6391 opts
->last_after_include
= dirtmp
; /* Tail follows the last one */
6396 if (opts
->out_fname
!= NULL
)
6398 cpp_fatal (pfile
, "Output filename specified twice");
6402 goto missing_filename
;
6403 opts
->out_fname
= argv
[++i
];
6404 if (!strcmp (opts
->out_fname
, "-"))
6405 opts
->out_fname
= "";
6409 if (!strcmp (argv
[i
], "-pedantic"))
6410 CPP_PEDANTIC (pfile
) = 1;
6411 else if (!strcmp (argv
[i
], "-pedantic-errors")) {
6412 CPP_PEDANTIC (pfile
) = 1;
6413 opts
->pedantic_errors
= 1;
6416 else if (!strcmp (argv
[i
], "-pcp")) {
6417 char *pcp_fname
= argv
[++i
];
6418 pcp_outfile
= ((pcp_fname
[0] != '-' || pcp_fname
[1] != '\0')
6419 ? fopen (pcp_fname
, "w")
6420 : fdopen (dup (fileno (stdout
)), "w"));
6421 if (pcp_outfile
== 0)
6422 cpp_pfatal_with_name (pfile
, pcp_fname
);
6429 if (!strcmp (argv
[i
], "-traditional")) {
6430 opts
->traditional
= 1;
6431 } else if (!strcmp (argv
[i
], "-trigraphs")) {
6433 opts
->no_trigraphs
= 0;
6438 if (! strcmp (argv
[i
], "-lang-c"))
6439 opts
->cplusplus
= 0, opts
->cplusplus_comments
= 1, opts
->c89
= 0,
6441 if (! strcmp (argv
[i
], "-lang-c89"))
6442 opts
->cplusplus
= 0, opts
->cplusplus_comments
= 0, opts
->c89
= 1,
6444 if (! strcmp (argv
[i
], "-lang-c++"))
6445 opts
->cplusplus
= 1, opts
->cplusplus_comments
= 1, opts
->c89
= 0,
6447 if (! strcmp (argv
[i
], "-lang-objc"))
6448 opts
->cplusplus
= 0, opts
->cplusplus_comments
= 1, opts
->c89
= 0,
6450 if (! strcmp (argv
[i
], "-lang-objc++"))
6451 opts
->cplusplus
= 1, opts
->cplusplus_comments
= 1, opts
->c89
= 0,
6453 if (! strcmp (argv
[i
], "-lang-asm"))
6455 if (! strcmp (argv
[i
], "-lint"))
6457 if (! strcmp (argv
[i
], "-lang-chill"))
6458 opts
->objc
= 0, opts
->cplusplus
= 0, opts
->chill
= 1,
6459 opts
->traditional
= 1, opts
->no_trigraphs
= 1;
6463 opts
->cplusplus
= 1, opts
->cplusplus_comments
= 1;
6467 opts
->inhibit_warnings
= 1;
6471 if (!strcmp (argv
[i
], "-Wtrigraphs"))
6472 opts
->warn_trigraphs
= 1;
6473 else if (!strcmp (argv
[i
], "-Wno-trigraphs"))
6474 opts
->warn_trigraphs
= 0;
6475 else if (!strcmp (argv
[i
], "-Wcomment"))
6476 opts
->warn_comments
= 1;
6477 else if (!strcmp (argv
[i
], "-Wno-comment"))
6478 opts
->warn_comments
= 0;
6479 else if (!strcmp (argv
[i
], "-Wcomments"))
6480 opts
->warn_comments
= 1;
6481 else if (!strcmp (argv
[i
], "-Wno-comments"))
6482 opts
->warn_comments
= 0;
6483 else if (!strcmp (argv
[i
], "-Wtraditional"))
6484 opts
->warn_stringify
= 1;
6485 else if (!strcmp (argv
[i
], "-Wno-traditional"))
6486 opts
->warn_stringify
= 0;
6487 else if (!strcmp (argv
[i
], "-Wundef"))
6488 opts
->warn_undef
= 1;
6489 else if (!strcmp (argv
[i
], "-Wno-undef"))
6490 opts
->warn_undef
= 0;
6491 else if (!strcmp (argv
[i
], "-Wimport"))
6492 opts
->warn_import
= 1;
6493 else if (!strcmp (argv
[i
], "-Wno-import"))
6494 opts
->warn_import
= 0;
6495 else if (!strcmp (argv
[i
], "-Werror"))
6496 opts
->warnings_are_errors
= 1;
6497 else if (!strcmp (argv
[i
], "-Wno-error"))
6498 opts
->warnings_are_errors
= 0;
6499 else if (!strcmp (argv
[i
], "-Wall"))
6501 opts
->warn_trigraphs
= 1;
6502 opts
->warn_comments
= 1;
6507 /* The style of the choices here is a bit mixed.
6508 The chosen scheme is a hybrid of keeping all options in one string
6509 and specifying each option in a separate argument:
6510 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
6511 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
6512 -M[M][G][D file]. This is awkward to handle in specs, and is not
6514 /* ??? -MG must be specified in addition to one of -M or -MM.
6515 This can be relaxed in the future without breaking anything.
6516 The converse isn't true. */
6518 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
6519 if (!strcmp (argv
[i
], "-MG"))
6521 opts
->print_deps_missing_files
= 1;
6524 if (!strcmp (argv
[i
], "-M"))
6525 opts
->print_deps
= 2;
6526 else if (!strcmp (argv
[i
], "-MM"))
6527 opts
->print_deps
= 1;
6528 else if (!strcmp (argv
[i
], "-MD"))
6529 opts
->print_deps
= 2;
6530 else if (!strcmp (argv
[i
], "-MMD"))
6531 opts
->print_deps
= 1;
6532 /* For -MD and -MMD options, write deps on file named by next arg. */
6533 if (!strcmp (argv
[i
], "-MD") || !strcmp (argv
[i
], "-MMD"))
6536 goto missing_filename
;
6537 opts
->deps_file
= argv
[++i
];
6541 /* For -M and -MM, write deps on standard output
6542 and suppress the usual output. */
6543 opts
->no_output
= 1;
6549 char *p
= argv
[i
] + 2;
6551 while ((c
= *p
++) != 0) {
6552 /* Arg to -d specifies what parts of macros to dump */
6555 opts
->dump_macros
= dump_only
;
6556 opts
->no_output
= 1;
6559 opts
->dump_macros
= dump_names
;
6562 opts
->dump_macros
= dump_definitions
;
6565 opts
->dump_includes
= 1;
6573 if (argv
[i
][2] == '3')
6574 opts
->debug_output
= 1;
6578 fprintf (stderr
, "GNU CPP version %s", version_string
);
6579 #ifdef TARGET_VERSION
6582 fprintf (stderr
, "\n");
6587 opts
->print_include_names
= 1;
6591 if (argv
[i
][2] != 0)
6592 push_pending (pfile
, "-D", argv
[i
] + 2);
6593 else if (i
+ 1 == argc
)
6595 cpp_fatal (pfile
, "Macro name missing after -D option");
6599 i
++, push_pending (pfile
, "-D", argv
[i
]);
6606 if (argv
[i
][2] != 0)
6608 else if (i
+ 1 == argc
)
6610 cpp_fatal (pfile
, "Assertion missing after -A option");
6616 if (!strcmp (p
, "-")) {
6617 struct cpp_pending
**ptr
;
6618 /* -A- eliminates all predefined macros and assertions.
6619 Let's include also any that were specified earlier
6620 on the command line. That way we can get rid of any
6621 that were passed automatically in from GCC. */
6622 opts
->inhibit_predefs
= 1;
6623 for (ptr
= &opts
->pending
; *ptr
!= NULL
; )
6625 struct cpp_pending
*pend
= *ptr
;
6626 if (pend
->cmd
&& pend
->cmd
[0] == '-'
6627 && (pend
->cmd
[1] == 'D' || pend
->cmd
[1] == 'A'))
6636 push_pending (pfile
, "-A", p
);
6641 case 'U': /* JF #undef something */
6642 if (argv
[i
][2] != 0)
6643 push_pending (pfile
, "-U", argv
[i
] + 2);
6644 else if (i
+ 1 == argc
)
6646 cpp_fatal (pfile
, "Macro name missing after -U option", NULL
);
6650 push_pending (pfile
, "-U", argv
[i
+1]), i
++;
6654 opts
->put_out_comments
= 1;
6657 case 'E': /* -E comes from cc -E; ignore it. */
6661 opts
->no_line_commands
= 1;
6664 case '$': /* Don't include $ in identifiers. */
6665 opts
->dollars_in_ident
= 0;
6668 case 'I': /* Add directory to path for includes. */
6670 struct file_name_list
*dirtmp
;
6672 if (! CPP_OPTIONS(pfile
)->ignore_srcdir
6673 && !strcmp (argv
[i
] + 2, "-")) {
6674 CPP_OPTIONS (pfile
)->ignore_srcdir
= 1;
6675 /* Don't use any preceding -I directories for #include <...>. */
6676 CPP_OPTIONS (pfile
)->first_bracket_include
= 0;
6679 dirtmp
= (struct file_name_list
*)
6680 xmalloc (sizeof (struct file_name_list
));
6681 dirtmp
->next
= 0; /* New one goes on the end */
6682 dirtmp
->control_macro
= 0;
6683 dirtmp
->c_system_include_path
= 0;
6684 if (argv
[i
][2] != 0)
6685 dirtmp
->fname
= argv
[i
] + 2;
6686 else if (i
+ 1 == argc
)
6687 goto missing_dirname
;
6689 dirtmp
->fname
= argv
[++i
];
6690 dirtmp
->got_name_map
= 0;
6691 append_include_chain (pfile
, dirtmp
, dirtmp
);
6697 if (!strcmp (argv
[i
], "-nostdinc"))
6698 /* -nostdinc causes no default include directories.
6699 You must specify all include-file directories with -I. */
6700 opts
->no_standard_includes
= 1;
6701 else if (!strcmp (argv
[i
], "-nostdinc++"))
6702 /* -nostdinc++ causes no default C++-specific include directories. */
6703 opts
->no_standard_cplusplus_includes
= 1;
6705 else if (!strcmp (argv
[i
], "-noprecomp"))
6711 if (!strcmp (argv
[i
], "-remap"))
6716 /* Sun compiler passes undocumented switch "-undef".
6717 Let's assume it means to inhibit the predefined symbols. */
6718 opts
->inhibit_predefs
= 1;
6721 case '\0': /* JF handle '-' as file name meaning stdin or stdout */
6722 if (opts
->in_fname
== NULL
) {
6723 opts
->in_fname
= "";
6725 } else if (opts
->out_fname
== NULL
) {
6726 opts
->out_fname
= "";
6728 } /* else fall through into error */
6738 /* Handle command-line options in (argc, argv).
6739 Can be called multiple times, to handle multiple sets of options.
6740 Returns if an unrecognized option is seen.
6741 Returns number of strings consumed. */
6744 cpp_handle_options (pfile
, argc
, argv
)
6750 int strings_processed
;
6751 for (i
= 0; i
< argc
; i
+= strings_processed
)
6753 strings_processed
= cpp_handle_option (pfile
, argc
- i
, argv
+ i
);
6754 if (strings_processed
== 0)
6764 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
6766 if (opts
->print_deps
)
6768 /* Stream on which to print the dependency information. */
6771 /* Don't actually write the deps file if compilation has failed. */
6772 if (pfile
->errors
== 0)
6774 char *deps_mode
= opts
->print_deps_append
? "a" : "w";
6775 if (opts
->deps_file
== 0)
6776 deps_stream
= stdout
;
6777 else if ((deps_stream
= fopen (opts
->deps_file
, deps_mode
)) == 0)
6778 cpp_pfatal_with_name (pfile
, opts
->deps_file
);
6779 fputs (pfile
->deps_buffer
, deps_stream
);
6780 putc ('\n', deps_stream
);
6781 if (opts
->deps_file
)
6783 if (ferror (deps_stream
) || fclose (deps_stream
) != 0)
6784 cpp_fatal (pfile
, "I/O error on output");
6790 /* Free resources used by PFILE.
6791 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
6798 while ( CPP_BUFFER (pfile
) != CPP_NULL_BUFFER (pfile
))
6799 cpp_pop_buffer (pfile
);
6801 if (pfile
->token_buffer
)
6803 free (pfile
->token_buffer
);
6804 pfile
->token_buffer
= NULL
;
6807 if (pfile
->deps_buffer
)
6809 free (pfile
->deps_buffer
);
6810 pfile
->deps_buffer
= NULL
;
6811 pfile
->deps_allocated_size
= 0;
6814 while (pfile
->if_stack
)
6816 IF_STACK_FRAME
*temp
= pfile
->if_stack
;
6817 pfile
->if_stack
= temp
->next
;
6821 while (pfile
->dont_repeat_files
)
6823 struct file_name_list
*temp
= pfile
->dont_repeat_files
;
6824 pfile
->dont_repeat_files
= temp
->next
;
6829 while (pfile
->all_include_files
)
6831 struct file_name_list
*temp
= pfile
->all_include_files
;
6832 pfile
->all_include_files
= temp
->next
;
6837 for (i
= IMPORT_HASH_SIZE
; --i
>= 0; )
6839 register struct import_file
*imp
= pfile
->import_hash_table
[i
];
6842 struct import_file
*next
= imp
->next
;
6847 pfile
->import_hash_table
[i
] = 0;
6850 for (i
= ASSERTION_HASHSIZE
; --i
>= 0; )
6852 while (pfile
->assertion_hashtab
[i
])
6853 delete_assertion (pfile
->assertion_hashtab
[i
]);
6856 cpp_hash_cleanup (pfile
);
6860 do_assert (pfile
, keyword
, buf
, limit
)
6862 struct directive
*keyword ATTRIBUTE_UNUSED
;
6863 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
6865 long symstart
; /* remember where symbol name starts */
6867 int sym_length
; /* and how long it is */
6868 struct arglist
*tokens
= NULL
;
6870 if (CPP_PEDANTIC (pfile
) && CPP_OPTIONS (pfile
)->done_initializing
6871 && !CPP_BUFFER (pfile
)->system_header_p
)
6872 cpp_pedwarn (pfile
, "ANSI C does not allow `#assert'");
6874 cpp_skip_hspace (pfile
);
6875 symstart
= CPP_WRITTEN (pfile
); /* remember where it starts */
6876 parse_name (pfile
, GETC());
6877 sym_length
= check_macro_name (pfile
, pfile
->token_buffer
+ symstart
,
6880 cpp_skip_hspace (pfile
);
6881 if (PEEKC() != '(') {
6882 cpp_error (pfile
, "missing token-sequence in `#assert'");
6888 tokens
= read_token_list (pfile
, &error_flag
);
6892 cpp_error (pfile
, "empty token-sequence in `#assert'");
6895 cpp_skip_hspace (pfile
);
6897 if (c
!= EOF
&& c
!= '\n')
6898 cpp_pedwarn (pfile
, "junk at end of `#assert'");
6899 skip_rest_of_line (pfile
);
6902 /* If this name isn't already an assertion name, make it one.
6903 Error if it was already in use in some other way. */
6906 ASSERTION_HASHNODE
*hp
;
6907 U_CHAR
*symname
= pfile
->token_buffer
+ symstart
;
6908 int hashcode
= hashf (symname
, sym_length
, ASSERTION_HASHSIZE
);
6909 struct tokenlist_list
*value
6910 = (struct tokenlist_list
*) xmalloc (sizeof (struct tokenlist_list
));
6912 hp
= assertion_lookup (pfile
, symname
, sym_length
, hashcode
);
6914 if (sym_length
== 7 && ! strncmp (symname
, "defined", sym_length
))
6915 cpp_error (pfile
, "`defined' redefined as assertion");
6916 hp
= assertion_install (pfile
, symname
, sym_length
, hashcode
);
6919 /* Add the spec'd token-sequence to the list of such. */
6920 value
->tokens
= tokens
;
6921 value
->next
= hp
->value
;
6924 CPP_SET_WRITTEN (pfile
, symstart
); /* Pop */
6927 CPP_SET_WRITTEN (pfile
, symstart
); /* Pop */
6928 skip_rest_of_line (pfile
);
6933 do_unassert (pfile
, keyword
, buf
, limit
)
6935 struct directive
*keyword ATTRIBUTE_UNUSED
;
6936 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
6938 long symstart
; /* remember where symbol name starts */
6939 int sym_length
; /* and how long it is */
6942 struct arglist
*tokens
= NULL
;
6943 int tokens_specified
= 0;
6945 if (CPP_PEDANTIC (pfile
) && CPP_OPTIONS (pfile
)->done_initializing
6946 && !CPP_BUFFER (pfile
)->system_header_p
)
6947 cpp_pedwarn (pfile
, "ANSI C does not allow `#unassert'");
6949 cpp_skip_hspace (pfile
);
6951 symstart
= CPP_WRITTEN (pfile
); /* remember where it starts */
6952 parse_name (pfile
, GETC());
6953 sym_length
= check_macro_name (pfile
, pfile
->token_buffer
+ symstart
,
6956 cpp_skip_hspace (pfile
);
6957 if (PEEKC() == '(') {
6960 tokens
= read_token_list (pfile
, &error_flag
);
6964 cpp_error (pfile
, "empty token list in `#unassert'");
6968 tokens_specified
= 1;
6971 cpp_skip_hspace (pfile
);
6973 if (c
!= EOF
&& c
!= '\n')
6974 cpp_error (pfile
, "junk at end of `#unassert'");
6975 skip_rest_of_line (pfile
);
6978 ASSERTION_HASHNODE
*hp
;
6979 U_CHAR
*symname
= pfile
->token_buffer
+ symstart
;
6980 int hashcode
= hashf (symname
, sym_length
, ASSERTION_HASHSIZE
);
6981 struct tokenlist_list
*tail
, *prev
;
6983 hp
= assertion_lookup (pfile
, symname
, sym_length
, hashcode
);
6987 /* If no token list was specified, then eliminate this assertion
6989 if (! tokens_specified
)
6990 delete_assertion (hp
);
6992 /* If a list of tokens was given, then delete any matching list. */
6997 struct tokenlist_list
*next
= tail
->next
;
6998 if (compare_token_lists (tail
->tokens
, tokens
)) {
7002 hp
->value
= tail
->next
;
7003 free_token_list (tail
->tokens
);
7013 CPP_SET_WRITTEN (pfile
, symstart
); /* Pop */
7016 CPP_SET_WRITTEN (pfile
, symstart
); /* Pop */
7017 skip_rest_of_line (pfile
);
7021 /* Test whether there is an assertion named NAME
7022 and optionally whether it has an asserted token list TOKENS.
7023 NAME is not null terminated; its length is SYM_LENGTH.
7024 If TOKENS_SPECIFIED is 0, then don't check for any token list. */
7027 check_assertion (pfile
, name
, sym_length
, tokens_specified
, tokens
)
7031 int tokens_specified
;
7032 struct arglist
*tokens
;
7034 ASSERTION_HASHNODE
*hp
;
7035 int hashcode
= hashf (name
, sym_length
, ASSERTION_HASHSIZE
);
7037 if (CPP_PEDANTIC (pfile
) && !CPP_BUFFER (pfile
)->system_header_p
)
7038 cpp_pedwarn (pfile
, "ANSI C does not allow testing assertions");
7040 hp
= assertion_lookup (pfile
, name
, sym_length
, hashcode
);
7042 /* It is not an assertion; just return false. */
7045 /* If no token list was specified, then value is 1. */
7046 if (! tokens_specified
)
7050 struct tokenlist_list
*tail
;
7054 /* If a list of tokens was given,
7055 then succeed if the assertion records a matching list. */
7058 if (compare_token_lists (tail
->tokens
, tokens
))
7063 /* Fail if the assertion has no matching list. */
7068 /* Compare two lists of tokens for equality including order of tokens. */
7071 compare_token_lists (l1
, l2
)
7072 struct arglist
*l1
, *l2
;
7075 if (l1
->length
!= l2
->length
)
7077 if (strncmp (l1
->name
, l2
->name
, l1
->length
))
7083 /* Succeed if both lists end at the same time. */
7088 reverse_token_list (tokens
)
7089 struct arglist
*tokens
;
7091 register struct arglist
*prev
= 0, *this, *next
;
7092 for (this = tokens
; this; this = next
)
7101 /* Read a space-separated list of tokens ending in a close parenthesis.
7102 Return a list of strings, in the order they were written.
7103 (In case of error, return 0 and store -1 in *ERROR_FLAG.) */
7105 static struct arglist
*
7106 read_token_list (pfile
, error_flag
)
7110 struct arglist
*token_ptrs
= 0;
7115 FORWARD (1); /* Skip '(' */
7117 /* Loop over the assertion value tokens. */
7120 struct arglist
*temp
;
7121 long name_written
= CPP_WRITTEN (pfile
);
7124 cpp_skip_hspace (pfile
);
7128 /* Find the end of the token. */
7131 CPP_PUTC (pfile
, c
);
7139 CPP_PUTC (pfile
, c
);
7141 else if (c
== '"' || c
== '\'')
7144 cpp_get_token (pfile
);
7150 while (c
!= EOF
&& ! is_space
[c
] && c
!= '(' && c
!= ')'
7151 && c
!= '"' && c
!= '\'')
7153 CPP_PUTC (pfile
, c
);
7156 if (c
!= EOF
) FORWARD(-1);
7159 length
= CPP_WRITTEN (pfile
) - name_written
;
7160 temp
= (struct arglist
*)
7161 xmalloc (sizeof (struct arglist
) + length
+ 1);
7162 temp
->name
= (U_CHAR
*) (temp
+ 1);
7163 bcopy ((char *) (pfile
->token_buffer
+ name_written
),
7164 (char *) temp
->name
, length
);
7165 temp
->name
[length
] = 0;
7166 temp
->next
= token_ptrs
;
7168 temp
->length
= length
;
7170 CPP_ADJUST_WRITTEN (pfile
, -length
); /* pop */
7172 if (c
== EOF
|| c
== '\n')
7175 "unterminated token sequence following `#' operator");
7180 /* We accumulated the names in reverse order.
7181 Now reverse them to get the proper order. */
7182 return reverse_token_list (token_ptrs
);
7186 free_token_list (tokens
)
7187 struct arglist
*tokens
;
7190 struct arglist
*next
= tokens
->next
;
7191 free (tokens
->name
);
7197 /* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
7198 retrying if necessary. If MAX_READ_LEN is defined, read at most
7199 that bytes at a time. Return a negative value if an error occurs,
7200 otherwise return the actual number of bytes read,
7201 which must be LEN unless end-of-file was reached. */
7204 safe_read (desc
, ptr
, len
)
7209 int left
, rcount
, nchars
;
7215 if (rcount
> MAX_READ_LEN
)
7216 rcount
= MAX_READ_LEN
;
7218 nchars
= read (desc
, ptr
, rcount
);
7236 xcalloc (number
, size
)
7237 unsigned number
, size
;
7239 register unsigned total
= number
* size
;
7240 register char *ptr
= (char *) xmalloc (total
);
7249 unsigned size
= strlen (input
);
7250 char *output
= xmalloc (size
+ 1);
7251 strcpy (output
, input
);
7255 /* Initialize PMARK to remember the current position of PFILE. */
7258 parse_set_mark (pmark
, pfile
)
7259 struct parse_marker
*pmark
;
7262 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
7263 pmark
->next
= pbuf
->marks
;
7264 pbuf
->marks
= pmark
;
7266 pmark
->position
= pbuf
->cur
- pbuf
->buf
;
7269 /* Cleanup PMARK - we no longer need it. */
7272 parse_clear_mark (pmark
)
7273 struct parse_marker
*pmark
;
7275 struct parse_marker
**pp
= &pmark
->buf
->marks
;
7276 for (; ; pp
= &(*pp
)->next
) {
7277 if (*pp
== NULL
) abort ();
7278 if (*pp
== pmark
) break;
7283 /* Backup the current position of PFILE to that saved in PMARK. */
7286 parse_goto_mark (pmark
, pfile
)
7287 struct parse_marker
*pmark
;
7290 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
7291 if (pbuf
!= pmark
->buf
)
7292 cpp_fatal (pfile
, "internal error %s", "parse_goto_mark");
7293 pbuf
->cur
= pbuf
->buf
+ pmark
->position
;
7296 /* Reset PMARK to point to the current position of PFILE. (Same
7297 as parse_clear_mark (PMARK), parse_set_mark (PMARK, PFILE) but faster. */
7300 parse_move_mark (pmark
, pfile
)
7301 struct parse_marker
*pmark
;
7304 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
7305 if (pbuf
!= pmark
->buf
)
7306 cpp_fatal (pfile
, "internal error %s", "parse_move_mark");
7307 pmark
->position
= pbuf
->cur
- pbuf
->buf
;
7311 cpp_read_check_assertion (pfile
)
7314 int name_start
= CPP_WRITTEN (pfile
);
7315 int name_length
, name_written
;
7317 FORWARD (1); /* Skip '#' */
7318 cpp_skip_hspace (pfile
);
7319 parse_name (pfile
, GETC ());
7320 name_written
= CPP_WRITTEN (pfile
);
7321 name_length
= name_written
- name_start
;
7322 cpp_skip_hspace (pfile
);
7323 if (CPP_BUF_PEEK (CPP_BUFFER (pfile
)) == '(')
7326 struct arglist
*token_ptrs
= read_token_list (pfile
, &error_flag
);
7327 result
= check_assertion (pfile
,
7328 pfile
->token_buffer
+ name_start
, name_length
,
7332 result
= check_assertion (pfile
,
7333 pfile
->token_buffer
+ name_start
, name_length
,
7335 CPP_ADJUST_WRITTEN (pfile
, - name_length
); /* pop */
7340 cpp_print_file_and_line (pfile
)
7343 cpp_buffer
*ip
= cpp_file_buffer (pfile
);
7348 cpp_buf_line_and_col (ip
, &line
, &col
);
7349 cpp_file_line_for_message (pfile
, ip
->nominal_fname
,
7350 line
, pfile
->show_column
? col
: -1);
7355 v_cpp_error (pfile
, msg
, ap
)
7360 cpp_print_containing_files (pfile
);
7361 cpp_print_file_and_line (pfile
);
7362 v_cpp_message (pfile
, 1, msg
, ap
);
7366 cpp_error
VPROTO ((cpp_reader
* pfile
, const char *msg
, ...))
7377 pfile
= va_arg (ap
, cpp_reader
*);
7378 msg
= va_arg (ap
, const char *);
7381 v_cpp_error (pfile
, msg
, ap
);
7385 /* Print error message but don't count it. */
7388 v_cpp_warning (pfile
, msg
, ap
)
7393 if (CPP_OPTIONS (pfile
)->inhibit_warnings
)
7396 if (CPP_OPTIONS (pfile
)->warnings_are_errors
)
7399 cpp_print_containing_files (pfile
);
7400 cpp_print_file_and_line (pfile
);
7401 v_cpp_message (pfile
, 0, msg
, ap
);
7405 cpp_warning
VPROTO ((cpp_reader
* pfile
, const char *msg
, ...))
7416 pfile
= va_arg (ap
, cpp_reader
*);
7417 msg
= va_arg (ap
, const char *);
7420 v_cpp_warning (pfile
, msg
, ap
);
7424 /* Print an error message and maybe count it. */
7427 cpp_pedwarn
VPROTO ((cpp_reader
* pfile
, const char *msg
, ...))
7438 pfile
= va_arg (ap
, cpp_reader
*);
7439 msg
= va_arg (ap
, const char *);
7442 if (CPP_OPTIONS (pfile
)->pedantic_errors
)
7443 v_cpp_error (pfile
, msg
, ap
);
7445 v_cpp_warning (pfile
, msg
, ap
);
7450 v_cpp_error_with_line (pfile
, line
, column
, msg
, ap
)
7457 cpp_buffer
*ip
= cpp_file_buffer (pfile
);
7459 cpp_print_containing_files (pfile
);
7462 cpp_file_line_for_message (pfile
, ip
->nominal_fname
, line
, column
);
7464 v_cpp_message (pfile
, 1, msg
, ap
);
7468 cpp_error_with_line
VPROTO ((cpp_reader
* pfile
, int line
, int column
, const char *msg
, ...))
7481 pfile
= va_arg (ap
, cpp_reader
*);
7482 line
= va_arg (ap
, int);
7483 column
= va_arg (ap
, int);
7484 msg
= va_arg (ap
, const char *);
7487 v_cpp_error_with_line(pfile
, line
, column
, msg
, ap
);
7492 v_cpp_warning_with_line (pfile
, line
, column
, msg
, ap
)
7501 if (CPP_OPTIONS (pfile
)->inhibit_warnings
)
7504 if (CPP_OPTIONS (pfile
)->warnings_are_errors
)
7507 cpp_print_containing_files (pfile
);
7509 ip
= cpp_file_buffer (pfile
);
7512 cpp_file_line_for_message (pfile
, ip
->nominal_fname
, line
, column
);
7514 v_cpp_message (pfile
, 0, msg
, ap
);
7519 cpp_warning_with_line
VPROTO ((cpp_reader
* pfile
, int line
, int column
, const char *msg
, ...))
7532 pfile
= va_arg (ap
, cpp_reader
*);
7533 line
= va_arg (ap
, int);
7534 column
= va_arg (ap
, int);
7535 msg
= va_arg (ap
, const char *);
7538 v_cpp_warning_with_line (pfile
, line
, column
, msg
, ap
);
7544 cpp_pedwarn_with_line
VPROTO ((cpp_reader
* pfile
, int line
, int column
, const char *msg
, ...))
7557 pfile
= va_arg (ap
, cpp_reader
*);
7558 line
= va_arg (ap
, int);
7559 column
= va_arg (ap
, int);
7560 msg
= va_arg (ap
, const char *);
7563 if (CPP_OPTIONS (pfile
)->pedantic_errors
)
7564 v_cpp_error_with_line (pfile
, column
, line
, msg
, ap
);
7566 v_cpp_warning_with_line (pfile
, line
, column
, msg
, ap
);
7570 /* Report a warning (or an error if pedantic_errors)
7571 giving specified file name and line number, not current. */
7574 cpp_pedwarn_with_file_and_line
VPROTO ((cpp_reader
*pfile
, char *file
, int line
, const char *msg
, ...))
7587 pfile
= va_arg (ap
, cpp_reader
*);
7588 file
= va_arg (ap
, char *);
7589 line
= va_arg (ap
, int);
7590 msg
= va_arg (ap
, const char *);
7593 if (!CPP_OPTIONS (pfile
)->pedantic_errors
7594 && CPP_OPTIONS (pfile
)->inhibit_warnings
)
7597 cpp_file_line_for_message (pfile
, file
, line
, -1);
7598 v_cpp_message (pfile
, CPP_OPTIONS (pfile
)->pedantic_errors
, msg
, ap
);
7603 #ifndef HAVE_STRERROR
7604 extern int sys_nerr
;
7605 extern char *sys_errlist
[];
7606 #else /* HAVE_STRERROR */
7610 char *strerror (int,...);
7613 /* my_strerror - return the descriptive text associated with an
7617 my_strerror (errnum
)
7623 #ifndef HAVE_STRERROR
7624 result
= (char *) ((errnum
< sys_nerr
) ? sys_errlist
[errnum
] : 0);
7626 result
= strerror (errnum
);
7629 /* VAXCRTL's strerror() takes an optional second argument, which only
7630 matters when the first argument is EVMSERR. However, it's simplest
7631 just to pass it unconditionally. `vaxc$errno' is declared in
7632 <errno.h>, and maintained by the library in parallel with `errno'.
7633 We assume that caller's `errnum' either matches the last setting of
7634 `errno' by the library or else does not have the value `EVMSERR'. */
7636 result
= strerror (errnum
, vaxc$errno
);
7640 result
= "undocumented I/O error";
7645 /* Error including a message from `errno'. */
7648 cpp_error_from_errno (pfile
, name
)
7653 cpp_buffer
*ip
= cpp_file_buffer (pfile
);
7655 cpp_print_containing_files (pfile
);
7658 cpp_file_line_for_message (pfile
, ip
->nominal_fname
, ip
->lineno
, -1);
7660 cpp_message (pfile
, 1, "%s: %s", name
, my_strerror (e
));
7664 cpp_perror_with_name (pfile
, name
)
7668 cpp_message (pfile
, 1, "%s: %s: %s", progname
, name
, my_strerror (errno
));
7672 * No pre-compiled header file support.
7674 * Possibly different enum token codes for each C/C++ token.
7676 * Should clean up remaining directives to that do_XXX functions
7677 * only take two arguments and all have command_reads_line.
7679 * Find and cleanup remaining uses of static variables,
7681 * Support for trigraphs.
7683 * Support -dM flag (dump_all_macros).
7685 * Support for_lint flag.