1 /* C Compatible Compiler Preprocessor (CCCP)
2 Copyright (C) 1986, 87, 89, 92, 93, 1994 Free Software Foundation, Inc.
3 Written by Paul Rubin, June 1986
4 Adapted to ANSI C, Richard Stallman, Jan 1987
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 In other words, you are welcome to use, share and improve this program.
21 You are forbidden to forbid anyone else to use, share and improve
22 what you give them. Help stamp out software-hoarding! */
24 typedef unsigned char U_CHAR;
28 #include "../src/config.h"
36 /* The macro EMACS is defined when cpp is distributed as part of Emacs,
37 for the sake of machines with limited C compilers. */
40 #endif /* not EMACS */
42 #ifndef STANDARD_INCLUDE_DIR
43 #define STANDARD_INCLUDE_DIR "/usr/include"
46 #ifndef LOCAL_INCLUDE_DIR
47 #define LOCAL_INCLUDE_DIR "/usr/local/include"
50 #if 0 /* We can't get ptrdiff_t, so I arranged not to need PTR_INT_TYPE. */
52 #define PTR_INT_TYPE ptrdiff_t
54 #define PTR_INT_TYPE long
64 /* By default, colon separates directories in a path. */
65 #ifndef PATH_SEPARATOR
66 #define PATH_SEPARATOR ':'
69 /* In case config.h defines these. */
74 #include <sys/types.h>
82 #include <sys/time.h> /* for __DATE__ and __TIME__ */
83 #include <sys/resource.h>
90 /* This defines "errno" properly for VMS, and gives us EACCES. */
93 /* VMS-specific definitions */
97 #define O_RDONLY 0 /* Open arg for Read/Only */
98 #define O_WRONLY 1 /* Open arg for Write/Only */
99 #define read(fd,buf,size) VMS_read (fd,buf,size)
100 #define write(fd,buf,size) VMS_write (fd,buf,size)
101 #define open(fname,mode,prot) VMS_open (fname,mode,prot)
102 #define fopen(fname,mode) VMS_fopen (fname,mode)
103 #define freopen(fname,mode,ofile) VMS_freopen (fname,mode,ofile)
104 #define strncat(dst,src,cnt) VMS_strncat (dst,src,cnt)
105 static char * VMS_strncat ();
106 static int VMS_read ();
107 static int VMS_write ();
108 static int VMS_open ();
109 static FILE * VMS_fopen ();
110 static FILE * VMS_freopen ();
111 static void hack_vms_include_specification ();
112 typedef struct { unsigned :16, :16, :16; } vms_ino_t;
113 #define ino_t vms_ino_t
114 #define INCLUDE_LEN_FUDGE 10 /* leave room for VMS syntax conversion */
116 #define BSTRING /* VMS/GCC supplies the bstring routines */
117 #endif /* __GNUC__ */
120 extern char *index ();
121 extern char *rindex ();
129 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
130 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
132 /* Find the largest host integer type and set its size and type. */
134 #ifndef HOST_BITS_PER_WIDE_INT
136 #if HOST_BITS_PER_LONG > HOST_BITS_PER_INT
137 #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG
138 #define HOST_WIDE_INT long
140 #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT
141 #define HOST_WIDE_INT int
147 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
151 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
154 /* Define a generic NULL if one hasn't already been defined. */
161 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
162 #define GENERIC_PTR void *
164 #define GENERIC_PTR char *
169 #define NULL_PTR ((GENERIC_PTR)0)
172 #ifndef INCLUDE_LEN_FUDGE
173 #define INCLUDE_LEN_FUDGE 0
176 /* Forward declarations. */
182 /* External declarations. */
184 extern char *getenv ();
185 extern FILE *fdopen ();
186 extern char *version_string;
187 extern struct tm *localtime ();
189 #ifndef HAVE_STRERROR
191 #if defined(bsd4_4) || defined(__NetBSD__)
192 extern const char *const sys_errlist[];
194 extern char *sys_errlist[];
196 #else /* HAVE_STERRROR */
200 char *strerror (int,...);
202 extern int parse_escape ();
203 extern HOST_WIDE_INT parse_c_expression ();
209 /* Forward declarations. */
216 #if defined(USG) || defined(VMS)
224 /* These functions are declared to return int instead of void since they
225 are going to be placed in a table and some old compilers have trouble with
226 pointers to functions returning void. */
228 static int do_define ();
229 static int do_line ();
230 static int do_include ();
231 static int do_undef ();
232 static int do_error ();
233 static int do_pragma ();
234 static int do_ident ();
236 static int do_xifdef ();
237 static int do_else ();
238 static int do_elif ();
239 static int do_endif ();
240 static int do_sccs ();
241 static int do_once ();
242 static int do_assert ();
243 static int do_unassert ();
244 static int do_warning ();
246 static void add_import ();
247 static void append_include_chain ();
248 static void deps_output ();
249 static void make_undef ();
250 static void make_definition ();
251 static void make_assertion ();
252 static void path_include ();
253 static void initialize_builtins ();
254 static void initialize_char_syntax ();
255 static void dump_arg_n ();
256 static void dump_defn_1 ();
257 static void delete_macro ();
258 static void trigraph_pcp ();
259 static void rescan ();
260 static void finclude ();
261 static void validate_else ();
262 static int comp_def_part ();
263 static void error_from_errno ();
264 static void error_with_line ();
266 void pedwarn_with_line ();
267 static void pedwarn_with_file_and_line ();
268 static void fatal ();
270 static void pfatal_with_name ();
271 static void perror_with_name ();
272 static void pipe_closed ();
273 static void print_containing_files ();
274 static int lookup_import ();
275 static int redundant_include_p ();
276 static is_system_include ();
277 static struct file_name_map *read_name_map ();
278 static char *read_filename_string ();
279 static int open_include_file ();
280 static int check_preconditions ();
281 static void pcfinclude ();
282 static void pcstring_used ();
283 static void write_output ();
284 static int check_macro_name ();
285 static int compare_defs ();
286 static int compare_token_lists ();
287 static HOST_WIDE_INT eval_if_expression ();
288 static int discard_comments ();
289 static int change_newlines ();
290 static int line_for_error ();
292 static int file_size_and_mode ();
294 static struct arglist *read_token_list ();
295 static void free_token_list ();
297 static struct hashnode *install ();
298 struct hashnode *lookup ();
300 static struct assertion_hashnode *assertion_install ();
301 static struct assertion_hashnode *assertion_lookup ();
303 static char *xrealloc ();
304 static char *xcalloc ();
305 static char *savestring ();
307 static void delete_assertion ();
308 static void macroexpand ();
309 static void dump_all_macros ();
310 static void conditional_skip ();
311 static void skip_if_group ();
312 static void output_line_command ();
314 /* Last arg to output_line_command. */
315 enum file_change_code {same_file, enter_file, leave_file};
317 static int grow_outbuf ();
318 static int handle_directive ();
319 static void memory_full ();
321 static U_CHAR *macarg1 ();
322 static char *macarg ();
324 static U_CHAR *skip_to_end_of_comment ();
325 static U_CHAR *skip_quoted_string ();
326 static U_CHAR *skip_paren_group ();
327 static char *quote_string ();
329 static char *check_precompiled ();
330 /* static struct macrodef create_definition (); [moved below] */
331 static void dump_single_macro ();
332 static void output_dots ();
334 #ifndef FAILURE_EXIT_CODE
335 #define FAILURE_EXIT_CODE 33 /* gnu cc command understands this */
338 #ifndef SUCCESS_EXIT_CODE
339 #define SUCCESS_EXIT_CODE 0 /* 0 means success on Unix. */
342 /* Name under which this program was invoked. */
344 static char *progname;
346 /* Nonzero means use extra default include directories for C++. */
348 static int cplusplus;
350 /* Nonzero means handle cplusplus style comments */
352 static int cplusplus_comments;
354 /* Nonzero means handle #import, for objective C. */
358 /* Nonzero means this is an assembly file, and allow
359 unknown directives, which could be comments. */
363 /* Current maximum length of directory names in the search path
364 for include files. (Altered as we get more of them.) */
366 static int max_include_len;
368 /* Nonzero means turn NOTREACHED into #pragma NOTREACHED etc */
370 static int for_lint = 0;
372 /* Nonzero means copy comments into the output file. */
374 static int put_out_comments = 0;
376 /* Nonzero means don't process the ANSI trigraph sequences. */
378 static int no_trigraphs = 0;
380 /* Nonzero means print the names of included files rather than
381 the preprocessed output. 1 means just the #include "...",
382 2 means #include <...> as well. */
384 static int print_deps = 0;
386 /* Nonzero if missing .h files in -M output are assumed to be generated
387 files and not errors. */
389 static int print_deps_missing_files = 0;
391 /* Nonzero means print names of header files (-H). */
393 static int print_include_names = 0;
395 /* Nonzero means don't output line number information. */
397 static int no_line_commands;
399 /* Nonzero means output the text in failing conditionals,
400 inside #failed ... #endfailed. */
402 static int output_conditionals;
404 /* dump_only means inhibit output of the preprocessed text
405 and instead output the definitions of all user-defined
406 macros in a form suitable for use as input to cccp.
407 dump_names means pass #define and the macro name through to output.
408 dump_definitions means pass the whole definition (plus #define) through
411 static enum {dump_none, dump_only, dump_names, dump_definitions}
412 dump_macros = dump_none;
414 /* Nonzero means pass all #define and #undef directives which we actually
415 process through to the output stream. This feature is used primarily
416 to allow cc1 to record the #defines and #undefs for the sake of
417 debuggers which understand about preprocessor macros, but it may
418 also be useful with -E to figure out how symbols are defined, and
419 where they are defined. */
420 static int debug_output = 0;
422 /* Nonzero indicates special processing used by the pcp program. The
423 special effects of this mode are:
425 Inhibit all macro expansion, except those inside #if directives.
427 Process #define directives normally, and output their contents
430 Output preconditions to pcp_outfile indicating all the relevant
431 preconditions for use of this file in a later cpp run.
433 static FILE *pcp_outfile;
435 /* Nonzero means we are inside an IF during a -pcp run. In this mode
436 macro expansion is done, and preconditions are output for all macro
437 uses requiring them. */
438 static int pcp_inside_if;
440 /* Nonzero means never to include precompiled files.
441 This is 1 since there's no way now to make precompiled files,
442 so it's not worth testing for them. */
443 static int no_precomp = 1;
445 /* Nonzero means give all the error messages the ANSI standard requires. */
449 /* Nonzero means try to make failure to fit ANSI C an error. */
451 static int pedantic_errors;
453 /* Nonzero means don't print warning messages. -w. */
455 static int inhibit_warnings = 0;
457 /* Nonzero means warn if slash-star appears in a comment. */
459 static int warn_comments;
461 /* Nonzero means warn if a macro argument is (or would be)
462 stringified with -traditional. */
464 static int warn_stringify;
466 /* Nonzero means warn if there are any trigraphs. */
468 static int warn_trigraphs;
470 /* Nonzero means warn if #import is used. */
472 static int warn_import = 1;
474 /* Nonzero means turn warnings into errors. */
476 static int warnings_are_errors;
478 /* Nonzero means try to imitate old fashioned non-ANSI preprocessor. */
482 /* Nonzero causes output not to be done,
483 but directives such as #define that have side effects
486 static int no_output;
488 /* Nonzero means this file was included with a -imacros or -include
489 command line and should not be recorded as an include file. */
491 static int no_record_file;
493 /* Nonzero means that we have finished processing the command line options.
494 This flag is used to decide whether or not to issue certain errors
497 static int done_initializing = 0;
499 /* Line where a newline was first seen in a string constant. */
501 static int multiline_string_line = 0;
503 /* I/O buffer structure.
504 The `fname' field is nonzero for source files and #include files
505 and for the dummy text used for -D and -U.
506 It is zero for rescanning results of macro expansion
507 and for expanding macro arguments. */
508 #define INPUT_STACK_MAX 400
509 static struct file_buf {
511 /* Filename specified with #line command. */
513 /* Record where in the search path this file was found.
514 For #include_next. */
515 struct file_name_list *dir;
520 /* Macro that this level is the expansion of.
521 Included so that we can reenable the macro
522 at the end of this level. */
523 struct hashnode *macro;
524 /* Value of if_stack at start of this file.
525 Used to prohibit unmatched #endif (etc) in an include file. */
526 struct if_stack *if_stack;
527 /* Object to be freed at end of input at this level. */
529 /* True if this is a header file included using <FILENAME>. */
530 char system_header_p;
531 } instack[INPUT_STACK_MAX];
533 static int last_error_tick; /* Incremented each time we print it. */
534 static int input_file_stack_tick; /* Incremented when the status changes. */
536 /* Current nesting level of input sources.
537 `instack[indepth]' is the level currently being read. */
538 static int indepth = -1;
539 #define CHECK_DEPTH(code) \
540 if (indepth >= (INPUT_STACK_MAX - 1)) \
542 error_with_line (line_for_error (instack[indepth].lineno), \
543 "macro or `#include' recursion too deep"); \
547 /* Current depth in #include directives that use <...>. */
548 static int system_include_depth = 0;
550 typedef struct file_buf FILE_BUF;
552 /* The output buffer. Its LENGTH field is the amount of room allocated
553 for the buffer, not the number of chars actually present. To get
554 that, subtract outbuf.buf from outbuf.bufp. */
556 #define OUTBUF_SIZE 10 /* initial size of output buffer */
557 static FILE_BUF outbuf;
559 /* Grow output buffer OBUF points at
560 so it can hold at least NEEDED more chars. */
562 #define check_expand(OBUF, NEEDED) \
563 (((OBUF)->length - ((OBUF)->bufp - (OBUF)->buf) <= (NEEDED)) \
564 ? grow_outbuf ((OBUF), (NEEDED)) : 0)
566 struct file_name_list
568 struct file_name_list *next;
570 /* If the following is nonzero, it is a macro name.
571 Don't include the file again if that macro is defined. */
572 U_CHAR *control_macro;
573 /* If the following is nonzero, it is a C-language system include
575 int c_system_include_path;
576 /* Mapping of file names for this directory. */
577 struct file_name_map *name_map;
578 /* Non-zero if name_map is valid. */
582 /* #include "file" looks in source file dir, then stack. */
583 /* #include <file> just looks in the stack. */
584 /* -I directories are added to the end, then the defaults are added. */
586 static struct default_include {
587 char *fname; /* The name of the directory. */
588 int cplusplus; /* Only look here if we're compiling C++. */
589 int cxx_aware; /* Includes in this directory don't need to
590 be wrapped in extern "C" when compiling
592 } include_defaults_array[]
593 #ifdef INCLUDE_DEFAULTS
597 /* Pick up GNU C++ specific include files. */
598 { GPLUSPLUS_INCLUDE_DIR, 1, 1 },
600 /* This is the dir for fixincludes. Put it just before
601 the files that we fix. */
602 { GCC_INCLUDE_DIR, 0, 0 },
603 /* For cross-compilation, this dir name is generated
604 automatically in Makefile.in. */
605 { CROSS_INCLUDE_DIR, 0, 0 },
606 /* This is another place that the target system's headers might be. */
607 { TOOL_INCLUDE_DIR, 0, 1 },
608 #else /* not CROSS_COMPILE */
609 /* This should be /usr/local/include and should come before
610 the fixincludes-fixed header files. */
611 { LOCAL_INCLUDE_DIR, 0, 1 },
612 /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
613 Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
614 { TOOL_INCLUDE_DIR, 0, 1 },
615 /* This is the dir for fixincludes. Put it just before
616 the files that we fix. */
617 { GCC_INCLUDE_DIR, 0, 0 },
618 /* Some systems have an extra dir of include files. */
619 #ifdef SYSTEM_INCLUDE_DIR
620 { SYSTEM_INCLUDE_DIR, 0, 0 },
622 { STANDARD_INCLUDE_DIR, 0, 0 },
623 #endif /* not CROSS_COMPILE */
626 #endif /* no INCLUDE_DEFAULTS */
628 /* The code looks at the defaults through this pointer, rather than through
629 the constant structure above. This pointer gets changed if an environment
630 variable specifies other defaults. */
631 static struct default_include *include_defaults = include_defaults_array;
633 static struct file_name_list *include = 0; /* First dir to search */
634 /* First dir to search for <file> */
635 /* This is the first element to use for #include <...>.
636 If it is 0, use the entire chain for such includes. */
637 static struct file_name_list *first_bracket_include = 0;
638 /* This is the first element in the chain that corresponds to
639 a directory of system header files. */
640 static struct file_name_list *first_system_include = 0;
641 static struct file_name_list *last_include = 0; /* Last in chain */
643 /* Chain of include directories to put at the end of the other chain. */
644 static struct file_name_list *after_include = 0;
645 static struct file_name_list *last_after_include = 0; /* Last in chain */
647 /* Chain to put at the start of the system include files. */
648 static struct file_name_list *before_system = 0;
649 static struct file_name_list *last_before_system = 0; /* Last in chain */
651 /* List of included files that contained #pragma once. */
652 static struct file_name_list *dont_repeat_files = 0;
654 /* List of other included files.
655 If ->control_macro if nonzero, the file had a #ifndef
656 around the entire contents, and ->control_macro gives the macro name. */
657 static struct file_name_list *all_include_files = 0;
659 /* Directory prefix that should replace `/usr' in the standard
660 include file directories. */
661 static char *include_prefix;
663 /* Global list of strings read in from precompiled files. This list
664 is kept in the order the strings are read in, with new strings being
665 added at the end through stringlist_tailp. We use this list to output
666 the strings at the end of the run.
668 static STRINGDEF *stringlist;
669 static STRINGDEF **stringlist_tailp = &stringlist;
672 /* Structure returned by create_definition */
673 typedef struct macrodef MACRODEF;
676 struct definition *defn;
681 static struct macrodef create_definition ();
684 /* Structure allocated for every #define. For a simple replacement
687 nargs = -1, the `pattern' list is null, and the expansion is just
688 the replacement text. Nargs = 0 means a functionlike macro with no args,
690 #define getchar() getc (stdin) .
691 When there are args, the expansion is the replacement text with the
692 args squashed out, and the reflist is a list describing how to
693 build the output from the input: e.g., "3 chars, then the 1st arg,
694 then 9 chars, then the 3rd arg, then 0 chars, then the 2nd arg".
695 The chars here come from the expansion. Whatever is left of the
696 expansion after the last arg-occurrence is copied after that arg.
697 Note that the reflist can be arbitrarily long---
698 its length depends on the number of times the arguments appear in
699 the replacement text, not how many args there are. Example:
700 #define f(x) x+x+x+x+x+x+x would have replacement text "++++++" and
702 { (0, 1), (1, 1), (1, 1), ..., (1, 1), NULL }
703 where (x, y) means (nchars, argno). */
705 typedef struct definition DEFINITION;
708 int length; /* length of expansion string */
709 int predefined; /* True if the macro was builtin or */
710 /* came from the command line */
712 int line; /* Line number of definition */
713 char *file; /* File of definition */
714 char rest_args; /* Nonzero if last arg. absorbs the rest */
716 struct reflist *next;
717 char stringify; /* nonzero if this arg was preceded by a
719 char raw_before; /* Nonzero if a ## operator before arg. */
720 char raw_after; /* Nonzero if a ## operator after arg. */
721 char rest_args; /* Nonzero if this arg. absorbs the rest */
722 int nchars; /* Number of literal chars to copy before
723 this arg occurrence. */
724 int argno; /* Number of arg to substitute (origin-0) */
727 /* Names of macro args, concatenated in reverse order
728 with comma-space between them.
729 The only use of this is that we warn on redefinition
730 if this differs between the old and new definitions. */
735 /* different kinds of things that can appear in the value field
736 of a hash node. Actually, this may be useless now. */
745 * special extension string that can be added to the last macro argument to
746 * allow it to absorb the "rest" of the arguments when expanded. Ex:
747 * #define wow(a, b...) process (b, a, b)
748 * { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); }
749 * { wow (one, two); } -> { process (two, one, two); }
750 * if this "rest_arg" is used with the concat token '##' and if it is not
751 * supplied then the token attached to with ## will not be outputted. Ex:
752 * #define wow (a, b...) process (b ## , a, ## b)
753 * { wow (1, 2); } -> { process (2, 1, 2); }
754 * { wow (one); } -> { process (one); {
756 static char rest_extension[] = "...";
757 #define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1)
759 /* The structure of a node in the hash table. The hash table
760 has entries for all tokens defined by #define commands (type T_MACRO),
761 plus some special tokens like __LINE__ (these each have their own
762 type, and the appropriate code is run when that type of node is seen.
763 It does not contain control words like "#define", which are recognized
764 by a separate piece of code. */
766 /* different flavors of hash nodes --- also used in keyword table */
768 T_DEFINE = 1, /* the `#define' keyword */
769 T_INCLUDE, /* the `#include' keyword */
770 T_INCLUDE_NEXT, /* the `#include_next' keyword */
771 T_IMPORT, /* the `#import' keyword */
772 T_IFDEF, /* the `#ifdef' keyword */
773 T_IFNDEF, /* the `#ifndef' keyword */
774 T_IF, /* the `#if' keyword */
775 T_ELSE, /* `#else' */
776 T_PRAGMA, /* `#pragma' */
777 T_ELIF, /* `#elif' */
778 T_UNDEF, /* `#undef' */
779 T_LINE, /* `#line' */
780 T_ERROR, /* `#error' */
781 T_WARNING, /* `#warning' */
782 T_ENDIF, /* `#endif' */
783 T_SCCS, /* `#sccs', used on system V. */
784 T_IDENT, /* `#ident', used on system V. */
785 T_ASSERT, /* `#assert', taken from system V. */
786 T_UNASSERT, /* `#unassert', taken from system V. */
787 T_SPECLINE, /* special symbol `__LINE__' */
788 T_DATE, /* `__DATE__' */
789 T_FILE, /* `__FILE__' */
790 T_BASE_FILE, /* `__BASE_FILE__' */
791 T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
792 T_VERSION, /* `__VERSION__' */
793 T_SIZE_TYPE, /* `__SIZE_TYPE__' */
794 T_PTRDIFF_TYPE, /* `__PTRDIFF_TYPE__' */
795 T_WCHAR_TYPE, /* `__WCHAR_TYPE__' */
796 T_USER_LABEL_PREFIX_TYPE, /* `__USER_LABEL_PREFIX__' */
797 T_REGISTER_PREFIX_TYPE, /* `__REGISTER_PREFIX__' */
798 T_TIME, /* `__TIME__' */
799 T_CONST, /* Constant value, used by `__STDC__' */
800 T_MACRO, /* macro defined by `#define' */
801 T_DISABLED, /* macro temporarily turned off for rescan */
802 T_SPEC_DEFINED, /* special `defined' macro for use in #if statements */
803 T_PCSTRING, /* precompiled string (hashval is KEYDEF *) */
804 T_UNUSED /* Used for something not defined. */
808 struct hashnode *next; /* double links for easy deletion */
809 struct hashnode *prev;
810 struct hashnode **bucket_hdr; /* also, a back pointer to this node's hash
811 chain is kept, in case the node is the head
812 of the chain and gets deleted. */
813 enum node_type type; /* type of special token */
814 int length; /* length of token, for quick comparison */
815 U_CHAR *name; /* the actual name */
816 union hashval value; /* pointer to expansion, or whatever */
819 typedef struct hashnode HASHNODE;
821 /* Some definitions for the hash table. The hash function MUST be
822 computed as shown in hashf () below. That is because the rescan
823 loop computes the hash value `on the fly' for most tokens,
824 in order to avoid the overhead of a lot of procedure calls to
825 the hashf () function. Hashf () only exists for the sake of
826 politeness, for use when speed isn't so important. */
828 #define HASHSIZE 1403
829 static HASHNODE *hashtab[HASHSIZE];
830 #define HASHSTEP(old, c) ((old << 2) + c)
831 #define MAKE_POS(v) (v & 0x7fffffff) /* make number positive */
833 /* Symbols to predefine. */
835 #ifdef CPP_PREDEFINES
836 static char *predefs = CPP_PREDEFINES;
838 static char *predefs = "";
841 /* We let tm.h override the types used here, to handle trivial differences
842 such as the choice of unsigned int or long unsigned int for size_t.
843 When machines start needing nontrivial differences in the size type,
844 it would be best to do something here to figure out automatically
845 from other information what type to use. */
847 /* The string value for __SIZE_TYPE__. */
850 #define SIZE_TYPE "long unsigned int"
853 /* The string value for __PTRDIFF_TYPE__. */
856 #define PTRDIFF_TYPE "long int"
859 /* The string value for __WCHAR_TYPE__. */
862 #define WCHAR_TYPE "int"
864 char * wchar_type = WCHAR_TYPE;
867 /* The string value for __USER_LABEL_PREFIX__ */
869 #ifndef USER_LABEL_PREFIX
870 #define USER_LABEL_PREFIX ""
873 /* The string value for __REGISTER_PREFIX__ */
875 #ifndef REGISTER_PREFIX
876 #define REGISTER_PREFIX ""
879 /* In the definition of a #assert name, this structure forms
880 a list of the individual values asserted.
881 Each value is itself a list of "tokens".
882 These are strings that are compared by name. */
884 struct tokenlist_list {
885 struct tokenlist_list *next;
886 struct arglist *tokens;
889 struct assertion_hashnode {
890 struct assertion_hashnode *next; /* double links for easy deletion */
891 struct assertion_hashnode *prev;
892 /* also, a back pointer to this node's hash
893 chain is kept, in case the node is the head
894 of the chain and gets deleted. */
895 struct assertion_hashnode **bucket_hdr;
896 int length; /* length of token, for quick comparison */
897 U_CHAR *name; /* the actual name */
898 /* List of token-sequences. */
899 struct tokenlist_list *value;
902 typedef struct assertion_hashnode ASSERTION_HASHNODE;
904 /* Some definitions for the hash table. The hash function MUST be
905 computed as shown in hashf below. That is because the rescan
906 loop computes the hash value `on the fly' for most tokens,
907 in order to avoid the overhead of a lot of procedure calls to
908 the hashf function. hashf only exists for the sake of
909 politeness, for use when speed isn't so important. */
911 #define ASSERTION_HASHSIZE 37
912 static ASSERTION_HASHNODE *assertion_hashtab[ASSERTION_HASHSIZE];
914 /* Nonzero means inhibit macroexpansion of what seem to be
915 assertion tests, in rescan. For #if. */
916 static int assertions_flag;
918 /* `struct directive' defines one #-directive, including how to handle it. */
921 int length; /* Length of name */
922 int (*func)(); /* Function to handle directive */
923 char *name; /* Name of directive */
924 enum node_type type; /* Code which describes which directive. */
925 char angle_brackets; /* Nonzero => <...> is special. */
926 char traditional_comments; /* Nonzero: keep comments if -traditional. */
927 char pass_thru; /* Copy preprocessed directive to output file. */
930 /* Here is the actual list of #-directives, most-often-used first. */
932 static struct directive directive_table[] = {
933 { 6, do_define, "define", T_DEFINE, 0, 1},
934 { 2, do_if, "if", T_IF},
935 { 5, do_xifdef, "ifdef", T_IFDEF},
936 { 6, do_xifdef, "ifndef", T_IFNDEF},
937 { 5, do_endif, "endif", T_ENDIF},
938 { 4, do_else, "else", T_ELSE},
939 { 4, do_elif, "elif", T_ELIF},
940 { 4, do_line, "line", T_LINE},
941 { 7, do_include, "include", T_INCLUDE, 1},
942 { 12, do_include, "include_next", T_INCLUDE_NEXT, 1},
943 { 6, do_include, "import", T_IMPORT, 1},
944 { 5, do_undef, "undef", T_UNDEF},
945 { 5, do_error, "error", T_ERROR},
946 { 7, do_warning, "warning", T_WARNING},
947 #ifdef SCCS_DIRECTIVE
948 { 4, do_sccs, "sccs", T_SCCS},
950 { 6, do_pragma, "pragma", T_PRAGMA, 0, 0, 1},
951 { 5, do_ident, "ident", T_IDENT},
952 { 6, do_assert, "assert", T_ASSERT},
953 { 8, do_unassert, "unassert", T_UNASSERT},
954 { -1, 0, "", T_UNUSED},
957 /* When a directive handler is called,
958 this points to the # that started the directive. */
959 U_CHAR *directive_start;
961 /* table to tell if char can be part of a C identifier. */
962 U_CHAR is_idchar[256];
963 /* table to tell if char can be first char of a c identifier. */
964 U_CHAR is_idstart[256];
965 /* table to tell if c is horizontal space. */
966 U_CHAR is_hor_space[256];
967 /* table to tell if c is horizontal or vertical space. */
968 static U_CHAR is_space[256];
970 #define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
971 #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
973 static int errors = 0; /* Error counter for exit code */
975 /* Name of output file, for error messages. */
976 static char *out_fname;
978 /* Zero means dollar signs are punctuation.
979 -$ stores 0; -traditional may store 1. Default is 1 for VMS, 0 otherwise.
980 This must be 0 for correct processing of this ANSI C program:
982 #define lose(b) foo (b)
985 static int dollars_in_ident;
986 #ifndef DOLLARS_IN_IDENTIFIERS
987 #define DOLLARS_IN_IDENTIFIERS 1
990 static FILE_BUF expand_to_temp_buffer ();
992 static DEFINITION *collect_expansion ();
994 /* Stack of conditionals currently in progress
995 (including both successful and failing conditionals). */
998 struct if_stack *next; /* for chaining to the next stack frame */
999 char *fname; /* copied from input when frame is made */
1000 int lineno; /* similarly */
1001 int if_succeeded; /* true if a leg of this if-group
1002 has been passed through rescan */
1003 U_CHAR *control_macro; /* For #ifndef at start of file,
1004 this is the macro name tested. */
1005 enum node_type type; /* type of last directive seen in this group */
1007 typedef struct if_stack IF_STACK_FRAME;
1008 static IF_STACK_FRAME *if_stack = NULL;
1010 /* Buffer of -M output. */
1011 static char *deps_buffer;
1013 /* Number of bytes allocated in above. */
1014 static int deps_allocated_size;
1016 /* Number of bytes used. */
1017 static int deps_size;
1019 /* Number of bytes since the last newline. */
1020 static int deps_column;
1022 /* Nonzero means -I- has been seen,
1023 so don't look for #include "foo" the source-file directory. */
1024 static int ignore_srcdir;
1026 /* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
1027 retrying if necessary. Return a negative value if an error occurs,
1028 otherwise return the actual number of bytes read,
1029 which must be LEN unless end-of-file was reached. */
1032 safe_read (desc, ptr, len)
1039 int nchars = read (desc, ptr, left);
1056 /* Write LEN bytes at PTR to descriptor DESC,
1057 retrying if necessary, and treating any real error as fatal. */
1060 safe_write (desc, ptr, len)
1066 int written = write (desc, ptr, len);
1073 pfatal_with_name (out_fname);
1091 char **pend_files = (char **) xmalloc (argc * sizeof (char *));
1092 char **pend_defs = (char **) xmalloc (argc * sizeof (char *));
1093 char **pend_undefs = (char **) xmalloc (argc * sizeof (char *));
1094 char **pend_assertions = (char **) xmalloc (argc * sizeof (char *));
1095 char **pend_includes = (char **) xmalloc (argc * sizeof (char *));
1097 /* Record the option used with each element of pend_assertions.
1098 This is preparation for supporting more than one option for making
1100 char **pend_assertion_options = (char **) xmalloc (argc * sizeof (char *));
1101 int inhibit_predefs = 0;
1102 int no_standard_includes = 0;
1103 int no_standard_cplusplus_includes = 0;
1104 int missing_newline = 0;
1106 /* Non-0 means don't output the preprocessed program. */
1107 int inhibit_output = 0;
1108 /* Non-0 means -v, so print the full set of include dirs. */
1111 /* File name which deps are being written to.
1112 This is 0 if deps are being written to stdout. */
1113 char *deps_file = 0;
1114 /* Fopen file mode to open deps_file with. */
1115 char *deps_mode = "a";
1116 /* Stream on which to print the dependency information. */
1117 FILE *deps_stream = 0;
1118 /* Target-name to write with the dependency information. */
1119 char *deps_target = 0;
1122 /* Get rid of any avoidable limit on stack size. */
1126 /* Set the stack limit huge so that alloca (particularly stringtab
1127 * in dbxread.c) does not fail. */
1128 getrlimit (RLIMIT_STACK, &rlim);
1129 rlim.rlim_cur = rlim.rlim_max;
1130 setrlimit (RLIMIT_STACK, &rlim);
1132 #endif /* RLIMIT_STACK defined */
1135 signal (SIGPIPE, pipe_closed);
1138 p = argv[0] + strlen (argv[0]);
1139 while (p != argv[0] && p[-1] != '/'
1140 #ifdef DIR_SEPARATOR
1141 && p[-1] != DIR_SEPARATOR
1149 /* Remove directories from PROGNAME. */
1152 progname = savestring (argv[0]);
1154 if (!(s = rindex (progname, ']')))
1155 s = rindex (progname, ':');
1157 strcpy (progname, s+1);
1158 if (s = rindex (progname, '.'))
1166 /* Initialize is_idchar to allow $. */
1167 dollars_in_ident = 1;
1168 initialize_char_syntax ();
1169 dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 0;
1171 no_line_commands = 0;
1173 dump_macros = dump_none;
1176 cplusplus_comments = 0;
1178 bzero ((char *) pend_files, argc * sizeof (char *));
1179 bzero ((char *) pend_defs, argc * sizeof (char *));
1180 bzero ((char *) pend_undefs, argc * sizeof (char *));
1181 bzero ((char *) pend_assertions, argc * sizeof (char *));
1182 bzero ((char *) pend_includes, argc * sizeof (char *));
1184 /* Process switches and find input file name. */
1186 for (i = 1; i < argc; i++) {
1187 if (argv[i][0] != '-') {
1188 if (out_fname != NULL)
1189 fatal ("Usage: %s [switches] input output", argv[0]);
1190 else if (in_fname != NULL)
1191 out_fname = argv[i];
1195 switch (argv[i][1]) {
1198 if (!strcmp (argv[i], "-include")) {
1200 fatal ("Filename missing after `-include' option");
1202 pend_includes[i] = argv[i+1], i++;
1204 if (!strcmp (argv[i], "-imacros")) {
1206 fatal ("Filename missing after `-imacros' option");
1208 pend_files[i] = argv[i+1], i++;
1210 if (!strcmp (argv[i], "-iprefix")) {
1212 fatal ("Filename missing after `-iprefix' option");
1214 include_prefix = argv[++i];
1216 if (!strcmp (argv[i], "-ifoutput")) {
1217 output_conditionals = 1;
1219 if (!strcmp (argv[i], "-isystem")) {
1220 struct file_name_list *dirtmp;
1223 fatal ("Filename missing after `-isystem' option");
1225 dirtmp = (struct file_name_list *)
1226 xmalloc (sizeof (struct file_name_list));
1228 dirtmp->control_macro = 0;
1229 dirtmp->c_system_include_path = 1;
1230 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1]) + 1);
1231 strcpy (dirtmp->fname, argv[++i]);
1232 dirtmp->got_name_map = 0;
1234 if (before_system == 0)
1235 before_system = dirtmp;
1237 last_before_system->next = dirtmp;
1238 last_before_system = dirtmp; /* Tail follows the last one */
1240 /* Add directory to end of path for includes,
1241 with the default prefix at the front of its name. */
1242 if (!strcmp (argv[i], "-iwithprefix")) {
1243 struct file_name_list *dirtmp;
1246 if (include_prefix != 0)
1247 prefix = include_prefix;
1249 prefix = savestring (GCC_INCLUDE_DIR);
1250 /* Remove the `include' from /usr/local/lib/gcc.../include. */
1251 if (!strcmp (prefix + strlen (prefix) - 8, "/include"))
1252 prefix[strlen (prefix) - 7] = 0;
1255 dirtmp = (struct file_name_list *)
1256 xmalloc (sizeof (struct file_name_list));
1257 dirtmp->next = 0; /* New one goes on the end */
1258 dirtmp->control_macro = 0;
1259 dirtmp->c_system_include_path = 0;
1261 fatal ("Directory name missing after `-iwithprefix' option");
1263 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1])
1264 + strlen (prefix) + 1);
1265 strcpy (dirtmp->fname, prefix);
1266 strcat (dirtmp->fname, argv[++i]);
1267 dirtmp->got_name_map = 0;
1269 if (after_include == 0)
1270 after_include = dirtmp;
1272 last_after_include->next = dirtmp;
1273 last_after_include = dirtmp; /* Tail follows the last one */
1275 /* Add directory to main path for includes,
1276 with the default prefix at the front of its name. */
1277 if (!strcmp (argv[i], "-iwithprefixbefore")) {
1278 struct file_name_list *dirtmp;
1281 if (include_prefix != 0)
1282 prefix = include_prefix;
1284 prefix = savestring (GCC_INCLUDE_DIR);
1285 /* Remove the `include' from /usr/local/lib/gcc.../include. */
1286 if (!strcmp (prefix + strlen (prefix) - 8, "/include"))
1287 prefix[strlen (prefix) - 7] = 0;
1290 dirtmp = (struct file_name_list *)
1291 xmalloc (sizeof (struct file_name_list));
1292 dirtmp->next = 0; /* New one goes on the end */
1293 dirtmp->control_macro = 0;
1294 dirtmp->c_system_include_path = 0;
1296 fatal ("Directory name missing after `-iwithprefixbefore' option");
1298 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1])
1299 + strlen (prefix) + 1);
1300 strcpy (dirtmp->fname, prefix);
1301 strcat (dirtmp->fname, argv[++i]);
1302 dirtmp->got_name_map = 0;
1304 append_include_chain (dirtmp, dirtmp);
1306 /* Add directory to end of path for includes. */
1307 if (!strcmp (argv[i], "-idirafter")) {
1308 struct file_name_list *dirtmp;
1310 dirtmp = (struct file_name_list *)
1311 xmalloc (sizeof (struct file_name_list));
1312 dirtmp->next = 0; /* New one goes on the end */
1313 dirtmp->control_macro = 0;
1314 dirtmp->c_system_include_path = 0;
1316 fatal ("Directory name missing after `-idirafter' option");
1318 dirtmp->fname = argv[++i];
1319 dirtmp->got_name_map = 0;
1321 if (after_include == 0)
1322 after_include = dirtmp;
1324 last_after_include->next = dirtmp;
1325 last_after_include = dirtmp; /* Tail follows the last one */
1330 if (out_fname != NULL)
1331 fatal ("Output filename specified twice");
1333 fatal ("Filename missing after -o option");
1334 out_fname = argv[++i];
1335 if (!strcmp (out_fname, "-"))
1340 if (!strcmp (argv[i], "-pedantic"))
1342 else if (!strcmp (argv[i], "-pedantic-errors")) {
1344 pedantic_errors = 1;
1345 } else if (!strcmp (argv[i], "-pcp")) {
1348 fatal ("Filename missing after -pcp option");
1349 pcp_fname = argv[++i];
1351 ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
1352 ? fopen (pcp_fname, "w")
1353 : fdopen (dup (fileno (stdout)), "w"));
1354 if (pcp_outfile == 0)
1355 pfatal_with_name (pcp_fname);
1361 if (!strcmp (argv[i], "-traditional")) {
1363 if (dollars_in_ident > 0)
1364 dollars_in_ident = 1;
1365 } else if (!strcmp (argv[i], "-trigraphs")) {
1371 if (! strcmp (argv[i], "-lang-c"))
1372 cplusplus = 0, cplusplus_comments = 0, objc = 0;
1373 if (! strcmp (argv[i], "-lang-c++"))
1374 cplusplus = 1, cplusplus_comments = 1, objc = 0;
1375 if (! strcmp (argv[i], "-lang-c-c++-comments"))
1376 cplusplus = 0, cplusplus_comments = 1, objc = 0;
1377 if (! strcmp (argv[i], "-lang-objc"))
1378 objc = 1, cplusplus = 0, cplusplus_comments = 1;
1379 if (! strcmp (argv[i], "-lang-objc++"))
1380 objc = 1, cplusplus = 1, cplusplus_comments = 1;
1381 if (! strcmp (argv[i], "-lang-asm"))
1383 if (! strcmp (argv[i], "-lint"))
1388 cplusplus = 1, cplusplus_comments = 1;
1392 inhibit_warnings = 1;
1396 if (!strcmp (argv[i], "-Wtrigraphs"))
1398 else if (!strcmp (argv[i], "-Wno-trigraphs"))
1400 else if (!strcmp (argv[i], "-Wcomment"))
1402 else if (!strcmp (argv[i], "-Wno-comment"))
1404 else if (!strcmp (argv[i], "-Wcomments"))
1406 else if (!strcmp (argv[i], "-Wno-comments"))
1408 else if (!strcmp (argv[i], "-Wtraditional"))
1410 else if (!strcmp (argv[i], "-Wno-traditional"))
1412 else if (!strcmp (argv[i], "-Wimport"))
1414 else if (!strcmp (argv[i], "-Wno-import"))
1416 else if (!strcmp (argv[i], "-Werror"))
1417 warnings_are_errors = 1;
1418 else if (!strcmp (argv[i], "-Wno-error"))
1419 warnings_are_errors = 0;
1420 else if (!strcmp (argv[i], "-Wall"))
1428 /* The style of the choices here is a bit mixed.
1429 The chosen scheme is a hybrid of keeping all options in one string
1430 and specifying each option in a separate argument:
1431 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
1432 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
1433 -M[M][G][D file]. This is awkward to handle in specs, and is not
1435 /* ??? -MG must be specified in addition to one of -M or -MM.
1436 This can be relaxed in the future without breaking anything.
1437 The converse isn't true. */
1439 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
1440 if (!strcmp (argv[i], "-MG"))
1442 print_deps_missing_files = 1;
1445 if (!strcmp (argv[i], "-M"))
1447 else if (!strcmp (argv[i], "-MM"))
1449 else if (!strcmp (argv[i], "-MD"))
1451 else if (!strcmp (argv[i], "-MMD"))
1453 /* For -MD and -MMD options, write deps on file named by next arg. */
1454 if (!strcmp (argv[i], "-MD")
1455 || !strcmp (argv[i], "-MMD")) {
1457 fatal ("Filename missing after %s option", argv[i]);
1459 deps_file = argv[i];
1462 /* For -M and -MM, write deps on standard output
1463 and suppress the usual output. */
1464 deps_stream = stdout;
1471 char *p = argv[i] + 2;
1474 /* Arg to -d specifies what parts of macros to dump */
1477 dump_macros = dump_only;
1481 dump_macros = dump_names;
1484 dump_macros = dump_definitions;
1492 if (argv[i][2] == '3')
1497 fprintf (stderr, "GNU CPP version %s", version_string);
1498 #ifdef TARGET_VERSION
1501 fprintf (stderr, "\n");
1506 print_include_names = 1;
1510 if (argv[i][2] != 0)
1511 pend_defs[i] = argv[i] + 2;
1512 else if (i + 1 == argc)
1513 fatal ("Macro name missing after -D option");
1515 i++, pend_defs[i] = argv[i];
1522 if (argv[i][2] != 0)
1524 else if (i + 1 == argc)
1525 fatal ("Assertion missing after -A option");
1529 if (!strcmp (p, "-")) {
1530 /* -A- eliminates all predefined macros and assertions.
1531 Let's include also any that were specified earlier
1532 on the command line. That way we can get rid of any
1533 that were passed automatically in from GCC. */
1535 inhibit_predefs = 1;
1536 for (j = 0; j < i; j++)
1537 pend_defs[j] = pend_assertions[j] = 0;
1539 pend_assertions[i] = p;
1540 pend_assertion_options[i] = "-A";
1545 case 'U': /* JF #undef something */
1546 if (argv[i][2] != 0)
1547 pend_undefs[i] = argv[i] + 2;
1548 else if (i + 1 == argc)
1549 fatal ("Macro name missing after -U option");
1551 pend_undefs[i] = argv[i+1], i++;
1555 put_out_comments = 1;
1558 case 'E': /* -E comes from cc -E; ignore it. */
1562 no_line_commands = 1;
1565 case '$': /* Don't include $ in identifiers. */
1566 dollars_in_ident = 0;
1569 case 'I': /* Add directory to path for includes. */
1571 struct file_name_list *dirtmp;
1573 if (! ignore_srcdir && !strcmp (argv[i] + 2, "-")) {
1575 /* Don't use any preceding -I directories for #include <...>. */
1576 first_bracket_include = 0;
1579 dirtmp = (struct file_name_list *)
1580 xmalloc (sizeof (struct file_name_list));
1581 dirtmp->next = 0; /* New one goes on the end */
1582 dirtmp->control_macro = 0;
1583 dirtmp->c_system_include_path = 0;
1584 if (argv[i][2] != 0)
1585 dirtmp->fname = argv[i] + 2;
1586 else if (i + 1 == argc)
1587 fatal ("Directory name missing after -I option");
1589 dirtmp->fname = argv[++i];
1590 dirtmp->got_name_map = 0;
1591 append_include_chain (dirtmp, dirtmp);
1597 if (!strcmp (argv[i], "-nostdinc"))
1598 /* -nostdinc causes no default include directories.
1599 You must specify all include-file directories with -I. */
1600 no_standard_includes = 1;
1601 else if (!strcmp (argv[i], "-nostdinc++"))
1602 /* -nostdinc++ causes no default C++-specific include directories. */
1603 no_standard_cplusplus_includes = 1;
1604 else if (!strcmp (argv[i], "-noprecomp"))
1609 /* Sun compiler passes undocumented switch "-undef".
1610 Let's assume it means to inhibit the predefined symbols. */
1611 inhibit_predefs = 1;
1614 case '\0': /* JF handle '-' as file name meaning stdin or stdout */
1615 if (in_fname == NULL) {
1618 } else if (out_fname == NULL) {
1621 } /* else fall through into error */
1624 fatal ("Invalid option `%s'", argv[i]);
1629 /* Add dirs from CPATH after dirs from -I. */
1630 /* There seems to be confusion about what CPATH should do,
1631 so for the moment it is not documented. */
1632 /* Some people say that CPATH should replace the standard include dirs,
1633 but that seems pointless: it comes before them, so it overrides them
1636 p = (char *) getenv ("Include");
1638 p = (char *) getenv ("CPATH");
1640 if (p != 0 && ! no_standard_includes)
1643 /* Now that dollars_in_ident is known, initialize is_idchar. */
1644 initialize_char_syntax ();
1646 /* Initialize output buffer */
1648 outbuf.buf = (U_CHAR *) xmalloc (OUTBUF_SIZE);
1649 outbuf.bufp = outbuf.buf;
1650 outbuf.length = OUTBUF_SIZE;
1652 /* Do partial setup of input buffer for the sake of generating
1653 early #line directives (when -g is in effect). */
1655 fp = &instack[++indepth];
1656 if (in_fname == NULL)
1658 fp->nominal_fname = fp->fname = in_fname;
1661 /* In C++, wchar_t is a distinct basic type, and we can expect
1662 __wchar_t to be defined by cc1plus. */
1664 wchar_type = "__wchar_t";
1666 /* Install __LINE__, etc. Must follow initialize_char_syntax
1667 and option processing. */
1668 initialize_builtins (fp, &outbuf);
1670 /* Do standard #defines and assertions
1671 that identify system and machine type. */
1673 if (!inhibit_predefs) {
1674 char *p = (char *) alloca (strlen (predefs) + 1);
1675 strcpy (p, predefs);
1678 while (*p == ' ' || *p == '\t')
1680 /* Handle -D options. */
1681 if (p[0] == '-' && p[1] == 'D') {
1683 while (*p && *p != ' ' && *p != '\t')
1688 output_line_command (fp, &outbuf, 0, same_file);
1689 make_definition (q, &outbuf);
1690 while (*p == ' ' || *p == '\t')
1692 } else if (p[0] == '-' && p[1] == 'A') {
1693 /* Handle -A options (assertions). */
1702 past_name = assertion;
1703 /* Locate end of name. */
1704 while (*past_name && *past_name != ' '
1705 && *past_name != '\t' && *past_name != '(')
1707 /* Locate `(' at start of value. */
1709 while (*value && (*value == ' ' || *value == '\t'))
1711 if (*value++ != '(')
1713 while (*value && (*value == ' ' || *value == '\t'))
1716 /* Locate end of value. */
1717 while (*past_value && *past_value != ' '
1718 && *past_value != '\t' && *past_value != ')')
1720 termination = past_value;
1721 while (*termination && (*termination == ' ' || *termination == '\t'))
1723 if (*termination++ != ')')
1725 if (*termination && *termination != ' ' && *termination != '\t')
1727 /* Temporarily null-terminate the value. */
1728 save_char = *termination;
1729 *termination = '\0';
1730 /* Install the assertion. */
1731 make_assertion ("-A", assertion);
1732 *termination = (char) save_char;
1734 while (*p == ' ' || *p == '\t')
1742 /* Now handle the command line options. */
1744 /* Do -U's, -D's and -A's in the order they were seen. */
1745 for (i = 1; i < argc; i++) {
1746 if (pend_undefs[i]) {
1748 output_line_command (fp, &outbuf, 0, same_file);
1749 make_undef (pend_undefs[i], &outbuf);
1753 output_line_command (fp, &outbuf, 0, same_file);
1754 make_definition (pend_defs[i], &outbuf);
1756 if (pend_assertions[i])
1757 make_assertion (pend_assertion_options[i], pend_assertions[i]);
1760 done_initializing = 1;
1762 { /* read the appropriate environment variable and if it exists
1763 replace include_defaults with the listed path. */
1765 switch ((objc << 1) + cplusplus)
1768 epath = getenv ("C_INCLUDE_PATH");
1771 epath = getenv ("CPLUS_INCLUDE_PATH");
1774 epath = getenv ("OBJC_INCLUDE_PATH");
1777 epath = getenv ("OBJCPLUS_INCLUDE_PATH");
1780 /* If the environment var for this language is set,
1781 add to the default list of include directories. */
1783 char *nstore = (char *) alloca (strlen (epath) + 2);
1785 char *startp, *endp;
1787 for (num_dirs = 1, startp = epath; *startp; startp++)
1788 if (*startp == PATH_SEPARATOR)
1791 = (struct default_include *) xmalloc ((num_dirs
1792 * sizeof (struct default_include))
1793 + sizeof (include_defaults_array));
1794 startp = endp = epath;
1797 /* Handle cases like c:/usr/lib:d:/gcc/lib */
1798 if ((*endp == PATH_SEPARATOR
1799 #if 0 /* Obsolete, now that we use semicolons as the path separator. */
1801 && (endp-startp != 1 || !isalpha (*startp))
1806 strncpy (nstore, startp, endp-startp);
1808 strcpy (nstore, ".");
1810 nstore[endp-startp] = '\0';
1812 include_defaults[num_dirs].fname = savestring (nstore);
1813 include_defaults[num_dirs].cplusplus = cplusplus;
1814 include_defaults[num_dirs].cxx_aware = 1;
1818 endp = startp = endp + 1;
1822 /* Put the usual defaults back in at the end. */
1823 bcopy ((char *) include_defaults_array,
1824 (char *) &include_defaults[num_dirs],
1825 sizeof (include_defaults_array));
1829 append_include_chain (before_system, last_before_system);
1830 first_system_include = before_system;
1832 /* Unless -fnostdinc,
1833 tack on the standard include file dirs to the specified list */
1834 if (!no_standard_includes) {
1835 struct default_include *p = include_defaults;
1836 char *specd_prefix = include_prefix;
1837 char *default_prefix = savestring (GCC_INCLUDE_DIR);
1838 int default_len = 0;
1839 /* Remove the `include' from /usr/local/lib/gcc.../include. */
1840 if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) {
1841 default_len = strlen (default_prefix) - 7;
1842 default_prefix[default_len] = 0;
1844 /* Search "translated" versions of GNU directories.
1845 These have /usr/local/lib/gcc... replaced by specd_prefix. */
1846 if (specd_prefix != 0 && default_len != 0)
1847 for (p = include_defaults; p->fname; p++) {
1848 /* Some standard dirs are only for C++. */
1849 if (!p->cplusplus || (cplusplus && !no_standard_cplusplus_includes)) {
1850 /* Does this dir start with the prefix? */
1851 if (!strncmp (p->fname, default_prefix, default_len)) {
1852 /* Yes; change prefix and add to search list. */
1853 struct file_name_list *new
1854 = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
1855 int this_len = strlen (specd_prefix) + strlen (p->fname) - default_len;
1856 char *str = (char *) xmalloc (this_len + 1);
1857 strcpy (str, specd_prefix);
1858 strcat (str, p->fname + default_len);
1860 new->control_macro = 0;
1861 new->c_system_include_path = !p->cxx_aware;
1862 new->got_name_map = 0;
1863 append_include_chain (new, new);
1864 if (first_system_include == 0)
1865 first_system_include = new;
1869 /* Search ordinary names for GNU include directories. */
1870 for (p = include_defaults; p->fname; p++) {
1871 /* Some standard dirs are only for C++. */
1872 if (!p->cplusplus || (cplusplus && !no_standard_cplusplus_includes)) {
1873 struct file_name_list *new
1874 = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
1875 new->control_macro = 0;
1876 new->c_system_include_path = !p->cxx_aware;
1877 new->fname = p->fname;
1878 new->got_name_map = 0;
1879 append_include_chain (new, new);
1880 if (first_system_include == 0)
1881 first_system_include = new;
1886 /* Tack the after_include chain at the end of the include chain. */
1887 append_include_chain (after_include, last_after_include);
1888 if (first_system_include == 0)
1889 first_system_include = after_include;
1891 /* With -v, print the list of dirs to search. */
1893 struct file_name_list *p;
1894 fprintf (stderr, "#include \"...\" search starts here:\n");
1895 for (p = include; p; p = p->next) {
1896 if (p == first_bracket_include)
1897 fprintf (stderr, "#include <...> search starts here:\n");
1898 fprintf (stderr, " %s\n", p->fname);
1900 fprintf (stderr, "End of search list.\n");
1903 /* Scan the -imacros files before the main input.
1904 Much like #including them, but with no_output set
1905 so that only their macro definitions matter. */
1907 no_output++; no_record_file++;
1908 for (i = 1; i < argc; i++)
1909 if (pend_files[i]) {
1910 int fd = open (pend_files[i], O_RDONLY, 0666);
1912 perror_with_name (pend_files[i]);
1913 return FAILURE_EXIT_CODE;
1915 finclude (fd, pend_files[i], &outbuf, 0, NULL_PTR);
1917 no_output--; no_record_file--;
1919 /* Copy the entire contents of the main input file into
1920 the stacked input buffer previously allocated for it. */
1922 /* JF check for stdin */
1923 if (in_fname == NULL || *in_fname == 0) {
1926 } else if ((f = open (in_fname, O_RDONLY, 0666)) < 0)
1929 /* -MG doesn't select the form of output and must be specified with one of
1930 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
1931 inhibit compilation. */
1932 if (print_deps_missing_files && (print_deps == 0 || !inhibit_output))
1933 fatal ("-MG must be specified with one of -M or -MM");
1935 /* Either of two environment variables can specify output of deps.
1936 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
1937 where OUTPUT_FILE is the file to write deps info to
1938 and DEPS_TARGET is the target to mention in the deps. */
1941 && (getenv ("SUNPRO_DEPENDENCIES") != 0
1942 || getenv ("DEPENDENCIES_OUTPUT") != 0)) {
1943 char *spec = getenv ("DEPENDENCIES_OUTPUT");
1948 spec = getenv ("SUNPRO_DEPENDENCIES");
1955 /* Find the space before the DEPS_TARGET, if there is one. */
1956 /* This should use index. (mrs) */
1957 while (*s != 0 && *s != ' ') s++;
1959 deps_target = s + 1;
1960 output_file = (char *) xmalloc (s - spec + 1);
1961 bcopy (spec, output_file, s - spec);
1962 output_file[s - spec] = 0;
1969 deps_file = output_file;
1973 /* For -M, print the expected object file name
1974 as the target of this Make-rule. */
1976 deps_allocated_size = 200;
1977 deps_buffer = (char *) xmalloc (deps_allocated_size);
1983 deps_output (deps_target, ':');
1984 } else if (*in_fname == 0) {
1985 deps_output ("-", ':');
1990 /* Discard all directory prefixes from filename. */
1991 if ((q = rindex (in_fname, '/')) != NULL
1992 #ifdef DIR_SEPARATOR
1993 && (q = rindex (in_fname, DIR_SEPARATOR)) != NULL
2000 /* Copy remainder to mungable area. */
2001 p = (char *) alloca (strlen(q) + 8);
2004 /* Output P, but remove known suffixes. */
2008 && p[len - 2] == '.'
2009 && index("cCsSm", p[len - 1]))
2012 && p[len - 3] == '.'
2013 && p[len - 2] == 'c'
2014 && p[len - 1] == 'c')
2017 && p[len - 4] == '.'
2018 && p[len - 3] == 'c'
2019 && p[len - 2] == 'x'
2020 && p[len - 1] == 'x')
2023 && p[len - 4] == '.'
2024 && p[len - 3] == 'c'
2025 && p[len - 2] == 'p'
2026 && p[len - 1] == 'p')
2029 /* Supply our own suffix. */
2036 deps_output (p, ':');
2037 deps_output (in_fname, ' ');
2041 file_size_and_mode (f, &st_mode, &st_size);
2042 fp->nominal_fname = fp->fname = in_fname;
2044 fp->system_header_p = 0;
2045 /* JF all this is mine about reading pipes and ttys */
2046 if (! S_ISREG (st_mode)) {
2047 /* Read input from a file that is not a normal disk file.
2048 We cannot preallocate a buffer with the correct size,
2049 so we must read in the file a piece at the time and make it bigger. */
2056 fp->buf = (U_CHAR *) xmalloc (bsize + 2);
2058 cnt = safe_read (f, fp->buf + size, bsize - size);
2059 if (cnt < 0) goto perror; /* error! */
2061 if (size != bsize) break; /* End of file */
2063 fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
2067 /* Read a file whose size we can determine in advance.
2068 For the sake of VMS, st_size is just an upper bound. */
2069 fp->buf = (U_CHAR *) xmalloc (st_size + 2);
2070 fp->length = safe_read (f, fp->buf, st_size);
2071 if (fp->length < 0) goto perror;
2074 fp->if_stack = if_stack;
2076 /* Make sure data ends with a newline. And put a null after it. */
2078 if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n')
2079 /* Backslash-newline at end is not good enough. */
2080 || (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) {
2081 fp->buf[fp->length++] = '\n';
2082 missing_newline = 1;
2084 fp->buf[fp->length] = '\0';
2086 /* Unless inhibited, convert trigraphs in the input. */
2091 /* Now that we know the input file is valid, open the output. */
2093 if (!out_fname || !strcmp (out_fname, ""))
2094 out_fname = "stdout";
2095 else if (! freopen (out_fname, "w", stdout))
2096 pfatal_with_name (out_fname);
2098 output_line_command (fp, &outbuf, 0, same_file);
2100 /* Scan the -include files before the main input. */
2103 for (i = 1; i < argc; i++)
2104 if (pend_includes[i]) {
2105 int fd = open (pend_includes[i], O_RDONLY, 0666);
2107 perror_with_name (pend_includes[i]);
2108 return FAILURE_EXIT_CODE;
2110 finclude (fd, pend_includes[i], &outbuf, 0, NULL_PTR);
2114 /* Scan the input, processing macros and directives. */
2116 rescan (&outbuf, 0);
2118 if (missing_newline)
2121 if (pedantic && missing_newline)
2122 pedwarn ("file does not end in newline");
2124 /* Now we have processed the entire input
2125 Write whichever kind of output has been requested. */
2127 if (dump_macros == dump_only)
2129 else if (! inhibit_output) {
2134 /* Don't actually write the deps file if compilation has failed. */
2136 if (deps_file && ! (deps_stream = fopen (deps_file, deps_mode)))
2137 pfatal_with_name (deps_file);
2138 fputs (deps_buffer, deps_stream);
2139 putc ('\n', deps_stream);
2141 if (ferror (deps_stream) || fclose (deps_stream) != 0)
2142 fatal ("I/O error on output");
2147 if (pcp_outfile && pcp_outfile != stdout
2148 && (ferror (pcp_outfile) || fclose (pcp_outfile) != 0))
2149 fatal ("I/O error on `-pcp' output");
2151 if (ferror (stdout) || fclose (stdout) != 0)
2152 fatal ("I/O error on output");
2155 exit (FAILURE_EXIT_CODE);
2156 exit (SUCCESS_EXIT_CODE);
2159 pfatal_with_name (in_fname);
2163 /* Given a colon-separated list of file names PATH,
2164 add all the names to the search path for include files. */
2178 struct file_name_list *dirtmp;
2180 /* Find the end of this name. */
2181 while (*q != 0 && *q != PATH_SEPARATOR) q++;
2183 /* An empty name in the path stands for the current directory. */
2184 name = (char *) xmalloc (2);
2188 /* Otherwise use the directory that is named. */
2189 name = (char *) xmalloc (q - p + 1);
2190 bcopy (p, name, q - p);
2194 dirtmp = (struct file_name_list *)
2195 xmalloc (sizeof (struct file_name_list));
2196 dirtmp->next = 0; /* New one goes on the end */
2197 dirtmp->control_macro = 0;
2198 dirtmp->c_system_include_path = 0;
2199 dirtmp->fname = name;
2200 dirtmp->got_name_map = 0;
2201 append_include_chain (dirtmp, dirtmp);
2203 /* Advance past this name. */
2207 /* Skip the colon. */
2212 /* Return the address of the first character in S that equals C.
2213 S is an array of length N, possibly containing '\0's, and followed by '\0'.
2214 Return 0 if there is no such character. Assume that C itself is not '\0'.
2215 If we knew we could use memchr, we could just invoke memchr (S, C, N),
2216 but unfortunately memchr isn't autoconfigured yet. */
2225 char *q = index (s, c);
2227 return (U_CHAR *) q;
2239 /* Pre-C-Preprocessor to translate ANSI trigraph idiocy in BUF
2240 before main CCCP processing. Name `pcp' is also in honor of the
2241 drugs the trigraph designers must have been on.
2243 Using an extra pass through the buffer takes a little extra time,
2244 but is infinitely less hairy than trying to handle trigraphs inside
2245 strings, etc. everywhere, and also makes sure that trigraphs are
2246 only translated in the top level of processing. */
2252 register U_CHAR c, *fptr, *bptr, *sptr, *lptr;
2255 fptr = bptr = sptr = buf->buf;
2256 lptr = fptr + buf->length;
2257 while ((sptr = (U_CHAR *) index0 (sptr, '?', lptr - sptr)) != NULL) {
2294 len = sptr - fptr - 2;
2296 /* BSD doc says bcopy () works right for overlapping strings. In ANSI
2297 C, this will be memmove (). */
2298 if (bptr != fptr && len > 0)
2299 bcopy ((char *) fptr, (char *) bptr, len);
2305 len = buf->length - (fptr - buf->buf);
2306 if (bptr != fptr && len > 0)
2307 bcopy ((char *) fptr, (char *) bptr, len);
2308 buf->length -= fptr - bptr;
2309 buf->buf[buf->length] = '\0';
2310 if (warn_trigraphs && fptr != bptr)
2311 warning ("%d trigraph(s) encountered", (fptr - bptr) / 2);
2314 /* Move all backslash-newline pairs out of embarrassing places.
2315 Exchange all such pairs following BP
2316 with any potentially-embarrassing characters that follow them.
2317 Potentially-embarrassing characters are / and *
2318 (because a backslash-newline inside a comment delimiter
2319 would cause it not to be recognized). */
2325 register U_CHAR *p = bp;
2327 /* First count the backslash-newline pairs here. */
2329 while (p[0] == '\\' && p[1] == '\n')
2332 /* What follows the backslash-newlines is not embarrassing. */
2334 if (*p != '/' && *p != '*')
2337 /* Copy all potentially embarrassing characters
2338 that follow the backslash-newline pairs
2339 down to where the pairs originally started. */
2341 while (*p == '*' || *p == '/')
2344 /* Now write the same number of pairs after the embarrassing chars. */
2351 /* Like newline_fix but for use within a directive-name.
2352 Move any backslash-newlines up past any following symbol constituents. */
2355 name_newline_fix (bp)
2358 register U_CHAR *p = bp;
2360 /* First count the backslash-newline pairs here. */
2361 while (p[0] == '\\' && p[1] == '\n')
2364 /* What follows the backslash-newlines is not embarrassing. */
2369 /* Copy all potentially embarrassing characters
2370 that follow the backslash-newline pairs
2371 down to where the pairs originally started. */
2373 while (is_idchar[*p])
2376 /* Now write the same number of pairs after the embarrassing chars. */
2383 /* Look for lint commands in comments.
2385 When we come in here, ibp points into a comment. Limit is as one expects.
2386 scan within the comment -- it should start, after lwsp, with a lint command.
2387 If so that command is returned as a (constant) string.
2389 Upon return, any arg will be pointed to with argstart and will be
2390 arglen long. Note that we don't parse that arg since it will just
2391 be printed out again.
2395 get_lintcmd (ibp, limit, argstart, arglen, cmdlen)
2396 register U_CHAR *ibp;
2397 register U_CHAR *limit;
2398 U_CHAR **argstart; /* point to command arg */
2399 int *arglen, *cmdlen; /* how long they are */
2402 register U_CHAR *numptr; /* temp for arg parsing */
2406 SKIP_WHITE_SPACE (ibp);
2408 if (ibp >= limit) return NULL;
2410 linsize = limit - ibp;
2412 /* Oh, I wish C had lexical functions... hell, I'll just open-code the set */
2413 if ((linsize >= 10) && !strncmp (ibp, "NOTREACHED", 10)) {
2415 return "NOTREACHED";
2417 if ((linsize >= 8) && !strncmp (ibp, "ARGSUSED", 8)) {
2421 if ((linsize >= 11) && !strncmp (ibp, "LINTLIBRARY", 11)) {
2423 return "LINTLIBRARY";
2425 if ((linsize >= 7) && !strncmp (ibp, "VARARGS", 7)) {
2427 ibp += 7; linsize -= 7;
2428 if ((linsize == 0) || ! isdigit (*ibp)) return "VARARGS";
2430 /* OK, read a number */
2431 for (numptr = *argstart = ibp; (numptr < limit) && isdigit (*numptr);
2433 *arglen = numptr - *argstart;
2440 * The main loop of the program.
2442 * Read characters from the input stack, transferring them to the
2445 * Macros are expanded and push levels on the input stack.
2446 * At the end of such a level it is popped off and we keep reading.
2447 * At the end of any other kind of level, we return.
2448 * #-directives are handled, except within macros.
2450 * If OUTPUT_MARKS is nonzero, keep Newline markers found in the input
2451 * and insert them when appropriate. This is set while scanning macro
2452 * arguments before substitution. It is zero when scanning for final output.
2453 * There are three types of Newline markers:
2454 * * Newline - follows a macro name that was not expanded
2455 * because it appeared inside an expansion of the same macro.
2456 * This marker prevents future expansion of that identifier.
2457 * When the input is rescanned into the final output, these are deleted.
2458 * These are also deleted by ## concatenation.
2459 * * Newline Space (or Newline and any other whitespace character)
2460 * stands for a place that tokens must be separated or whitespace
2461 * is otherwise desirable, but where the ANSI standard specifies there
2462 * is no whitespace. This marker turns into a Space (or whichever other
2463 * whitespace char appears in the marker) in the final output,
2464 * but it turns into nothing in an argument that is stringified with #.
2465 * Such stringified arguments are the only place where the ANSI standard
2466 * specifies with precision that whitespace may not appear.
2468 * During this function, IP->bufp is kept cached in IBP for speed of access.
2469 * Likewise, OP->bufp is kept in OBP. Before calling a subroutine
2470 * IBP, IP and OBP must be copied back to memory. IP and IBP are
2471 * copied back with the RECACHE macro. OBP must be copied back from OP->bufp
2472 * explicitly, and before RECACHE, since RECACHE uses OBP.
2476 rescan (op, output_marks)
2480 /* Character being scanned in main loop. */
2483 /* Length of pending accumulated identifier. */
2484 register int ident_length = 0;
2486 /* Hash code of pending accumulated identifier. */
2487 register int hash = 0;
2489 /* Current input level (&instack[indepth]). */
2492 /* Pointer for scanning input. */
2493 register U_CHAR *ibp;
2495 /* Pointer to end of input. End of scan is controlled by LIMIT. */
2496 register U_CHAR *limit;
2498 /* Pointer for storing output. */
2499 register U_CHAR *obp;
2501 /* REDO_CHAR is nonzero if we are processing an identifier
2502 after backing up over the terminating character.
2503 Sometimes we process an identifier without backing up over
2504 the terminating character, if the terminating character
2505 is not special. Backing up is done so that the terminating character
2506 will be dispatched on again once the identifier is dealt with. */
2509 /* 1 if within an identifier inside of which a concatenation
2510 marker (Newline -) has been seen. */
2511 int concatenated = 0;
2513 /* While scanning a comment or a string constant,
2514 this records the line it started on, for error messages. */
2517 /* Record position of last `real' newline. */
2518 U_CHAR *beg_of_line;
2520 /* Pop the innermost input stack level, assuming it is a macro expansion. */
2523 do { ip->macro->type = T_MACRO; \
2524 if (ip->free_ptr) free (ip->free_ptr); \
2525 --indepth; } while (0)
2527 /* Reload `rescan's local variables that describe the current
2528 level of the input stack. */
2531 do { ip = &instack[indepth]; \
2533 limit = ip->buf + ip->length; \
2535 check_expand (op, limit - ibp); \
2537 obp = op->bufp; } while (0)
2539 if (no_output && instack[indepth].fname != 0)
2540 skip_if_group (&instack[indepth], 1, NULL);
2547 /* Our caller must always put a null after the end of
2548 the input at each input stack level. */
2558 if (*ibp == '\n' && !ip->macro) {
2559 /* At the top level, always merge lines ending with backslash-newline,
2560 even in middle of identifier. But do not merge lines in a macro,
2561 since backslash might be followed by a newline-space marker. */
2564 --obp; /* remove backslash from obuf */
2567 /* If ANSI, backslash is just another character outside a string. */
2570 /* Otherwise, backslash suppresses specialness of following char,
2571 so copy it here to prevent the switch from seeing it.
2572 But first get any pending identifier processed. */
2573 if (ident_length > 0)
2580 if (assertions_flag) {
2581 /* Copy #foo (bar lose) without macro expansion. */
2582 SKIP_WHITE_SPACE (ibp);
2583 while (is_idchar[*ibp])
2585 SKIP_WHITE_SPACE (ibp);
2588 skip_paren_group (ip);
2589 bcopy ((char *) ibp, (char *) obp, ip->bufp - ibp);
2590 obp += ip->bufp - ibp;
2595 /* If this is expanding a macro definition, don't recognize
2596 preprocessor directives. */
2599 /* If this is expand_into_temp_buffer, recognize them
2600 only after an actual newline at this level,
2601 not at the beginning of the input level. */
2602 if (ip->fname == 0 && beg_of_line == ip->buf)
2608 /* # keyword: a # must be first nonblank char on the line */
2609 if (beg_of_line == 0)
2614 /* Scan from start of line, skipping whitespace, comments
2615 and backslash-newlines, and see if we reach this #.
2616 If not, this # is not special. */
2618 /* If -traditional, require # to be at beginning of line. */
2621 if (is_hor_space[*bp])
2623 else if (*bp == '\\' && bp[1] == '\n')
2625 else if (*bp == '/' && bp[1] == '*') {
2627 while (!(*bp == '*' && bp[1] == '/'))
2631 /* There is no point in trying to deal with C++ // comments here,
2632 because if there is one, then this # must be part of the
2633 comment and we would never reach here. */
2640 /* This # can start a directive. */
2642 --obp; /* Don't copy the '#' */
2646 if (! handle_directive (ip, op)) {
2650 /* Not a known directive: treat it as ordinary text.
2651 IP, OP, IBP, etc. have not been changed. */
2652 if (no_output && instack[indepth].fname) {
2653 /* If not generating expanded output,
2654 what we do with ordinary text is skip it.
2655 Discard everything until next # directive. */
2656 skip_if_group (&instack[indepth], 1, 0);
2661 ++obp; /* Copy the '#' after all */
2662 /* Don't expand an identifier that could be a macro directive.
2663 (Section 3.8.3 of the ANSI C standard) */
2664 SKIP_WHITE_SPACE (ibp);
2665 if (is_idstart[*ibp])
2668 while (is_idchar[*ibp])
2676 /* A # directive has been successfully processed. */
2677 /* If not generating expanded output, ignore everything until
2678 next # directive. */
2679 if (no_output && instack[indepth].fname)
2680 skip_if_group (&instack[indepth], 1, 0);
2686 case '\"': /* skip quoted string */
2688 /* A single quoted string is treated like a double -- some
2689 programs (e.g., troff) are perverse this way */
2694 start_line = ip->lineno;
2696 /* Skip ahead to a matching quote. */
2700 if (ip->macro != 0) {
2701 /* try harder: this string crosses a macro expansion boundary.
2702 This can happen naturally if -traditional.
2703 Otherwise, only -D can make a macro with an unmatched quote. */
2709 error_with_line (line_for_error (start_line),
2710 "unterminated string or character constant");
2711 error_with_line (multiline_string_line,
2712 "possible real start of unterminated constant");
2713 multiline_string_line = 0;
2722 /* Traditionally, end of line ends a string constant with no error.
2723 So exit the loop and record the new line. */
2729 error_with_line (line_for_error (start_line),
2730 "unterminated character constant");
2733 if (pedantic && multiline_string_line == 0) {
2734 pedwarn_with_line (line_for_error (start_line),
2735 "string constant runs past end of line");
2737 if (multiline_string_line == 0)
2738 multiline_string_line = ip->lineno - 1;
2745 /* Backslash newline is replaced by nothing at all,
2746 but keep the line counts correct. */
2751 /* ANSI stupidly requires that in \\ the second \
2752 is *not* prevented from combining with a newline. */
2753 while (*ibp == '\\' && ibp[1] == '\n') {
2772 if (*ibp == '\\' && ibp[1] == '\n')
2776 && !(cplusplus_comments && *ibp == '/'))
2784 /* C++ style comment... */
2785 start_line = ip->lineno;
2787 --ibp; /* Back over the slash */
2790 /* Comments are equivalent to spaces. */
2791 if (! put_out_comments)
2794 /* must fake up a comment here */
2799 U_CHAR *before_bp = ibp+2;
2801 while (ibp < limit) {
2802 if (ibp[-1] != '\\' && *ibp == '\n') {
2803 if (put_out_comments) {
2804 bcopy ((char *) before_bp, (char *) obp, ibp - before_bp);
2805 obp += ibp - before_bp;
2811 /* Copy the newline into the output buffer, in order to
2812 avoid the pain of a #line every time a multiline comment
2814 if (!put_out_comments)
2825 /* Ordinary C comment. Skip it, optionally copying it to output. */
2827 start_line = ip->lineno;
2829 ++ibp; /* Skip the star. */
2831 /* If this cpp is for lint, we peek inside the comments: */
2835 char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen);
2837 if (lintcmd != NULL) {
2839 check_expand (op, cmdlen + arglen + 14);
2841 /* I believe it is always safe to emit this newline: */
2843 bcopy ("#pragma lint ", (char *) obp, 13);
2845 bcopy (lintcmd, (char *) obp, cmdlen);
2850 bcopy (argbp, (char *) obp, arglen);
2854 /* OK, now bring us back to the state we were in before we entered
2855 this branch. We need #line because the #pragma's newline always
2856 messes up the line count. */
2858 output_line_command (ip, op, 0, same_file);
2859 check_expand (op, limit - ibp + 2);
2865 /* Comments are equivalent to spaces.
2866 Note that we already output the slash; we might not want it.
2867 For -traditional, a comment is equivalent to nothing. */
2868 if (! put_out_comments) {
2878 U_CHAR *before_bp = ibp;
2880 while (ibp < limit) {
2883 if (warn_comments && ibp < limit && *ibp == '*')
2884 warning ("`/*' within comment");
2887 if (*ibp == '\\' && ibp[1] == '\n')
2889 if (ibp >= limit || *ibp == '/')
2894 /* Copy the newline into the output buffer, in order to
2895 avoid the pain of a #line every time a multiline comment
2897 if (!put_out_comments)
2905 error_with_line (line_for_error (start_line),
2906 "unterminated comment");
2909 if (put_out_comments) {
2910 bcopy ((char *) before_bp, (char *) obp, ibp - before_bp);
2911 obp += ibp - before_bp;
2918 if (!dollars_in_ident)
2922 case '0': case '1': case '2': case '3': case '4':
2923 case '5': case '6': case '7': case '8': case '9':
2924 /* If digit is not part of identifier, it starts a number,
2925 which means that following letters are not an identifier.
2926 "0x5" does not refer to an identifier "x5".
2927 So copy all alphanumerics that follow without accumulating
2928 as an identifier. Periods also, for sake of "3.e7". */
2930 if (ident_length == 0) {
2931 while (ibp < limit) {
2932 while (ibp < limit && ibp[0] == '\\' && ibp[1] == '\n') {
2937 /* ".." terminates a preprocessing number. This is useless for C
2938 code but useful for preprocessing other things. */
2939 if (!isalnum (c) && (c != '.' || *ibp == '.') && c != '_') {
2944 /* A sign can be part of a preprocessing number
2945 if it follows an e. */
2946 if (c == 'e' || c == 'E') {
2947 while (ibp < limit && ibp[0] == '\\' && ibp[1] == '\n') {
2951 if (ibp < limit && (*ibp == '+' || *ibp == '-')) {
2953 /* But traditional C does not let the token go past the sign. */
2964 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
2965 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
2966 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
2967 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
2969 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
2970 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
2971 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
2972 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
2976 /* Compute step of hash function, to avoid a proc call on every token */
2977 hash = HASHSTEP (hash, c);
2981 if (ip->fname == 0 && *ibp == '-') {
2982 /* Newline - inhibits expansion of preceding token.
2983 If expanding a macro arg, we keep the newline -.
2984 In final output, it is deleted.
2985 We recognize Newline - in macro bodies and macro args. */
2986 if (! concatenated) {
2991 if (!output_marks) {
2994 /* If expanding a macro arg, keep the newline -. */
3000 /* If reprocessing a macro expansion, newline is a special marker. */
3001 else if (ip->macro != 0) {
3002 /* Newline White is a "funny space" to separate tokens that are
3003 supposed to be separate but without space between.
3004 Here White means any whitespace character.
3005 Newline - marks a recursive macro use that is not
3006 supposed to be expandable. */
3008 if (is_space[*ibp]) {
3009 /* Newline Space does not prevent expansion of preceding token
3010 so expand the preceding token and then come back. */
3011 if (ident_length > 0)
3014 /* If generating final output, newline space makes a space. */
3015 if (!output_marks) {
3017 /* And Newline Newline makes a newline, so count it. */
3018 if (obp[-1] == '\n')
3021 /* If expanding a macro arg, keep the newline space.
3022 If the arg gets stringified, newline space makes nothing. */
3025 } else abort (); /* Newline followed by something random? */
3029 /* If there is a pending identifier, handle it and come back here. */
3030 if (ident_length > 0)
3035 /* Update the line counts and output a #line if necessary. */
3038 if (ip->lineno != op->lineno) {
3040 output_line_command (ip, op, 1, same_file);
3041 check_expand (op, limit - ibp);
3046 /* Come here either after (1) a null character that is part of the input
3047 or (2) at the end of the input, because there is a null there. */
3050 /* Our input really contains a null character. */
3053 /* At end of a macro-expansion level, pop it and read next level. */
3054 if (ip->macro != 0) {
3057 /* If traditional, and we have an identifier that ends here,
3058 process it now, so we get the right error for recursion. */
3059 if (traditional && ident_length
3060 && ! is_idchar[*instack[indepth - 1].bufp]) {
3069 /* If we don't have a pending identifier,
3070 return at end of input. */
3071 if (ident_length == 0) {
3079 /* If we do have a pending identifier, just consider this null
3080 a special character and arrange to dispatch on it again.
3081 The second time, IDENT_LENGTH will be zero so we will return. */
3087 /* Handle the case of a character such as /, ', " or null
3088 seen following an identifier. Back over it so that
3089 after the identifier is processed the special char
3090 will be dispatched on again. */
3100 if (ident_length > 0) {
3101 register HASHNODE *hp;
3103 /* We have just seen an identifier end. If it's a macro, expand it.
3105 IDENT_LENGTH is the length of the identifier
3106 and HASH is its hash code.
3108 The identifier has already been copied to the output,
3109 so if it is a macro we must remove it.
3111 If REDO_CHAR is 0, the char that terminated the identifier
3112 has been skipped in the output and the input.
3113 OBP-IDENT_LENGTH-1 points to the identifier.
3114 If the identifier is a macro, we must back over the terminator.
3116 If REDO_CHAR is 1, the terminating char has already been
3117 backed over. OBP-IDENT_LENGTH points to the identifier. */
3119 if (!pcp_outfile || pcp_inside_if) {
3121 for (hp = hashtab[MAKE_POS (hash) % HASHSIZE]; hp != NULL;
3124 if (hp->length == ident_length) {
3125 int obufp_before_macroname;
3126 int op_lineno_before_macroname;
3127 register int i = ident_length;
3128 register U_CHAR *p = hp->name;
3129 register U_CHAR *q = obp - i;
3135 do { /* All this to avoid a strncmp () */
3140 /* We found a use of a macro name.
3141 see if the context shows it is a macro call. */
3143 /* Back up over terminating character if not already done. */
3149 /* Save this as a displacement from the beginning of the output
3150 buffer. We can not save this as a position in the output
3151 buffer, because it may get realloc'ed by RECACHE. */
3152 obufp_before_macroname = (obp - op->buf) - ident_length;
3153 op_lineno_before_macroname = op->lineno;
3155 if (hp->type == T_PCSTRING) {
3156 pcstring_used (hp); /* Mark the definition of this key
3157 as needed, ensuring that it
3159 break; /* Exit loop, since the key cannot have a
3160 definition any longer. */
3163 /* Record whether the macro is disabled. */
3164 disabled = hp->type == T_DISABLED;
3166 /* This looks like a macro ref, but if the macro was disabled,
3167 just copy its name and put in a marker if requested. */
3171 /* This error check caught useful cases such as
3172 #define foo(x,y) bar (x (y,0), y)
3175 error ("recursive use of macro `%s'", hp->name);
3179 check_expand (op, limit - ibp + 2);
3186 /* If macro wants an arglist, verify that a '(' follows.
3187 first skip all whitespace, copying it to the output
3188 after the macro name. Then, if there is no '(',
3189 decide this is not a macro call and leave things that way. */
3190 if ((hp->type == T_MACRO || hp->type == T_DISABLED)
3191 && hp->value.defn->nargs >= 0)
3193 U_CHAR *old_ibp = ibp;
3194 U_CHAR *old_obp = obp;
3195 int old_iln = ip->lineno;
3196 int old_oln = op->lineno;
3199 /* Scan forward over whitespace, copying it to the output. */
3200 if (ibp == limit && ip->macro != 0) {
3205 old_iln = ip->lineno;
3206 old_oln = op->lineno;
3208 /* A comment: copy it unchanged or discard it. */
3209 else if (*ibp == '/' && ibp+1 != limit && ibp[1] == '*') {
3210 if (put_out_comments) {
3213 } else if (! traditional) {
3217 while (ibp + 1 != limit
3218 && !(ibp[0] == '*' && ibp[1] == '/')) {
3219 /* We need not worry about newline-marks,
3220 since they are never found in comments. */
3222 /* Newline in a file. Count it. */
3226 if (put_out_comments)
3232 if (put_out_comments) {
3237 else if (is_space[*ibp]) {
3239 if (ibp[-1] == '\n') {
3240 if (ip->macro == 0) {
3241 /* Newline in a file. Count it. */
3244 } else if (!output_marks) {
3245 /* A newline mark, and we don't want marks
3246 in the output. If it is newline-hyphen,
3247 discard it entirely. Otherwise, it is
3248 newline-whitechar, so keep the whitechar. */
3258 /* A newline mark; copy both chars to the output. */
3266 /* It isn't a macro call.
3267 Put back the space that we just skipped. */
3270 ip->lineno = old_iln;
3271 op->lineno = old_oln;
3272 /* Exit the for loop. */
3277 /* This is now known to be a macro call.
3278 Discard the macro name from the output,
3279 along with any following whitespace just copied. */
3280 obp = op->buf + obufp_before_macroname;
3281 op->lineno = op_lineno_before_macroname;
3283 /* Prevent accidental token-pasting with a character
3284 before the macro call. */
3285 if (!traditional && obp != op->buf
3286 && (obp[-1] == '-' || obp[1] == '+' || obp[1] == '&'
3287 || obp[-1] == '|' || obp[1] == '<' || obp[1] == '>')) {
3288 /* If we are expanding a macro arg, make a newline marker
3289 to separate the tokens. If we are making real output,
3290 a plain space will do. */
3296 /* Expand the macro, reading arguments as needed,
3297 and push the expansion on the input stack. */
3300 macroexpand (hp, op);
3302 /* Reexamine input stack, since macroexpand has pushed
3303 a new level on it. */
3310 } /* End hash-table-search loop */
3312 ident_length = hash = 0; /* Stop collecting identifier */
3315 } /* End if (ident_length > 0) */
3317 } /* End per-char loop */
3319 /* Come here to return -- but first give an error message
3320 if there was an unterminated successful conditional. */
3322 if (if_stack != ip->if_stack)
3324 char *str = "unknown";
3326 switch (if_stack->type)
3345 error_with_line (line_for_error (if_stack->lineno),
3346 "unterminated `#%s' conditional", str);
3348 if_stack = ip->if_stack;
3352 * Rescan a string into a temporary buffer and return the result
3353 * as a FILE_BUF. Note this function returns a struct, not a pointer.
3355 * OUTPUT_MARKS nonzero means keep Newline markers found in the input
3356 * and insert such markers when appropriate. See `rescan' for details.
3357 * OUTPUT_MARKS is 1 for macroexpanding a macro argument separately
3358 * before substitution; it is 0 for other uses.
3361 expand_to_temp_buffer (buf, limit, output_marks, assertions)
3362 U_CHAR *buf, *limit;
3363 int output_marks, assertions;
3365 register FILE_BUF *ip;
3367 int length = limit - buf;
3369 int odepth = indepth;
3370 int save_assertions_flag = assertions_flag;
3372 assertions_flag = assertions;
3377 /* Set up the input on the input stack. */
3379 buf1 = (U_CHAR *) alloca (length + 1);
3381 register U_CHAR *p1 = buf;
3382 register U_CHAR *p2 = buf1;
3389 /* Set up to receive the output. */
3391 obuf.length = length * 2 + 100; /* Usually enough. Why be stingy? */
3392 obuf.bufp = obuf.buf = (U_CHAR *) xmalloc (obuf.length);
3397 CHECK_DEPTH ({return obuf;});
3401 ip = &instack[indepth];
3403 ip->nominal_fname = 0;
3404 ip->system_header_p = 0;
3407 ip->length = length;
3408 ip->buf = ip->bufp = buf1;
3409 ip->if_stack = if_stack;
3411 ip->lineno = obuf.lineno = 1;
3413 /* Scan the input, create the output. */
3414 rescan (&obuf, output_marks);
3416 /* Pop input stack to original state. */
3419 if (indepth != odepth)
3422 /* Record the output. */
3423 obuf.length = obuf.bufp - obuf.buf;
3425 assertions_flag = save_assertions_flag;
3430 * Process a # directive. Expects IP->bufp to point after the '#', as in
3431 * `#define foo bar'. Passes to the command handler
3432 * (do_define, do_include, etc.): the addresses of the 1st and
3433 * last chars of the command (starting immediately after the #
3434 * keyword), plus op and the keyword table pointer. If the command
3435 * contains comments it is copied into a temporary buffer sans comments
3436 * and the temporary buffer is passed to the command handler instead.
3437 * Likewise for backslash-newlines.
3439 * Returns nonzero if this was a known # directive.
3440 * Otherwise, returns zero, without advancing the input pointer.
3444 handle_directive (ip, op)
3447 register U_CHAR *bp, *cp;
3448 register struct directive *kt;
3449 register int ident_length;
3452 /* Nonzero means we must copy the entire command
3453 to get rid of comments or backslash-newlines. */
3454 int copy_command = 0;
3456 U_CHAR *ident, *after_ident;
3460 /* Record where the directive started. do_xifdef needs this. */
3461 directive_start = bp - 1;
3463 /* Skip whitespace and \-newline. */
3465 if (is_hor_space[*bp]) {
3466 if ((*bp == '\f' || *bp == '\v') && pedantic)
3467 pedwarn ("%s in preprocessing directive",
3468 *bp == '\f' ? "formfeed" : "vertical tab");
3470 } else if (*bp == '/' && (bp[1] == '*'
3471 || (cplusplus_comments && bp[1] == '/'))) {
3473 skip_to_end_of_comment (ip, &ip->lineno, 0);
3475 } else if (*bp == '\\' && bp[1] == '\n') {
3476 bp += 2; ip->lineno++;
3480 /* Now find end of directive name.
3481 If we encounter a backslash-newline, exchange it with any following
3482 symbol-constituents so that we end up with a contiguous name. */
3489 if (*cp == '\\' && cp[1] == '\n')
3490 name_newline_fix (cp);
3496 ident_length = cp - bp;
3500 /* A line of just `#' becomes blank. */
3502 if (ident_length == 0 && *after_ident == '\n') {
3503 ip->bufp = after_ident;
3507 if (ident_length == 0 || !is_idstart[*ident]) {
3509 while (is_idchar[*p]) {
3510 if (*p < '0' || *p > '9')
3514 /* Handle # followed by a line number. */
3515 if (p != ident && !is_idchar[*p]) {
3516 static struct directive line_directive_table[] = {
3517 { 4, do_line, "line", T_LINE},
3520 pedwarn ("`#' followed by integer");
3521 after_ident = ident;
3522 kt = line_directive_table;
3526 /* Avoid error for `###' and similar cases unless -pedantic. */
3528 while (*p == '#' || is_hor_space[*p]) p++;
3530 if (pedantic && !lang_asm)
3531 warning ("invalid preprocessor directive");
3537 error ("invalid preprocessor directive name");
3543 * Decode the keyword and call the appropriate expansion
3544 * routine, after moving the input pointer up to the next line.
3546 for (kt = directive_table; kt->length > 0; kt++) {
3547 if (kt->length == ident_length && !strncmp (kt->name, ident, ident_length)) {
3548 register U_CHAR *buf;
3549 register U_CHAR *limit;
3552 int *already_output;
3554 /* Nonzero means do not delete comments within the directive.
3555 #define needs this when -traditional. */
3560 limit = ip->buf + ip->length;
3563 keep_comments = traditional && kt->traditional_comments;
3564 /* #import is defined only in Objective C, or when on the NeXT. */
3565 if (kt->type == T_IMPORT && !(objc || lookup ("__NeXT__", -1, -1)))
3568 /* Find the end of this command (first newline not backslashed
3569 and not in a string or comment).
3570 Set COPY_COMMAND if the command must be copied
3571 (it contains a backslash-newline or a comment). */
3573 buf = bp = after_ident;
3574 while (bp < limit) {
3575 register U_CHAR c = *bp++;
3583 } else if (traditional)
3590 bp = skip_quoted_string (bp - 1, limit, ip->lineno, &ip->lineno, ©_command, &unterminated);
3591 /* Don't bother calling the directive if we already got an error
3592 message due to unterminated string. Skip everything and pretend
3593 we called the directive. */
3596 /* Traditional preprocessing permits unterminated strings. */
3605 /* <...> is special for #include. */
3607 if (!kt->angle_brackets)
3609 while (bp < limit && *bp != '>' && *bp != '\n') {
3610 if (*bp == '\\' && bp[1] == '\n') {
3620 if (*bp == '\\' && bp[1] == '\n')
3623 || (cplusplus_comments && *bp == '/')) {
3624 U_CHAR *obp = bp - 1;
3626 skip_to_end_of_comment (ip, &ip->lineno, 0);
3628 /* No need to copy the command because of a comment at the end;
3629 just don't include the comment in the directive. */
3630 if (bp == limit || *bp == '\n') {
3634 /* Don't remove the comments if -traditional. */
3635 if (! keep_comments)
3643 pedwarn ("%s in preprocessing directive",
3644 c == '\f' ? "formfeed" : "vertical tab");
3648 --bp; /* Point to the newline */
3656 resume_p = ip->bufp;
3657 /* BP is the end of the directive.
3658 RESUME_P is the next interesting data after the directive.
3659 A comment may come between. */
3661 /* If a directive should be copied through, and -E was given,
3662 pass it through before removing comments. */
3663 if (!no_output && kt->pass_thru && put_out_comments) {
3666 /* Output directive name. */
3667 check_expand (op, kt->length + 2);
3668 /* Make sure # is at the start of a line */
3669 if (op->bufp > op->buf && op->bufp[-1] != '\n') {
3674 bcopy (kt->name, op->bufp, kt->length);
3675 op->bufp += kt->length;
3677 /* Output arguments. */
3679 check_expand (op, len);
3680 bcopy (buf, (char *) op->bufp, len);
3682 /* Take account of any (escaped) newlines just output. */
3684 if (buf[len] == '\n')
3687 already_output = &junk;
3688 } /* Don't we need a newline or #line? */
3691 register U_CHAR *xp = buf;
3692 /* Need to copy entire command into temp buffer before dispatching */
3694 cp = (U_CHAR *) alloca (bp - buf + 5); /* room for cmd plus
3698 /* Copy to the new buffer, deleting comments
3699 and backslash-newlines (and whitespace surrounding the latter). */
3702 register U_CHAR c = *xp++;
3707 abort (); /* A bare newline should never part of the line. */
3710 /* <...> is special for #include. */
3712 if (!kt->angle_brackets)
3714 while (xp < bp && c != '>') {
3716 if (c == '\\' && xp < bp && *xp == '\n')
3727 if (cp != buf && is_space[cp[-1]]) {
3728 while (cp != buf && is_space[cp[-1]]) cp--;
3730 SKIP_WHITE_SPACE (xp);
3731 } else if (is_space[*xp]) {
3733 SKIP_WHITE_SPACE (xp);
3743 register U_CHAR *bp1
3744 = skip_quoted_string (xp - 1, bp, ip->lineno,
3745 NULL_PTR, NULL_PTR, NULL_PTR);
3759 || (cplusplus_comments && *xp == '/')) {
3761 /* If we already copied the command through,
3762 already_output != 0 prevents outputting comment now. */
3763 skip_to_end_of_comment (ip, already_output, 0);
3765 while (xp != ip->bufp)
3767 /* Delete or replace the slash. */
3768 else if (traditional)
3777 /* Null-terminate the copy. */
3783 ip->bufp = resume_p;
3785 /* Some directives should be written out for cc1 to process,
3786 just as if they were not defined. And sometimes we're copying
3787 definitions through. */
3789 if (!no_output && already_output == 0
3791 || (kt->type == T_DEFINE
3792 && (dump_macros == dump_names
3793 || dump_macros == dump_definitions)))) {
3796 /* Output directive name. */
3797 check_expand (op, kt->length + 1);
3799 bcopy (kt->name, (char *) op->bufp, kt->length);
3800 op->bufp += kt->length;
3802 if (kt->pass_thru || dump_macros == dump_definitions) {
3803 /* Output arguments. */
3805 check_expand (op, len);
3806 bcopy (buf, (char *) op->bufp, len);
3808 } else if (kt->type == T_DEFINE && dump_macros == dump_names) {
3811 SKIP_WHITE_SPACE (xp);
3813 while (is_idchar[*xp]) xp++;
3815 check_expand (op, len + 1);
3817 bcopy (yp, op->bufp, len);
3820 } /* Don't we need a newline or #line? */
3822 /* Call the appropriate command handler. buf now points to
3823 either the appropriate place in the input buffer, or to
3824 the temp buffer if it was necessary to make one. cp
3825 points to the first char after the contents of the (possibly
3826 copied) command, in either case. */
3827 (*kt->func) (buf, cp, op, kt);
3828 check_expand (op, ip->length - (ip->bufp - ip->buf));
3834 /* It is deliberate that we don't warn about undefined directives.
3835 That is the responsibility of cc1. */
3842 static struct tm *timebuf;
3844 time_t t = time ((time_t *)0);
3845 timebuf = localtime (&t);
3850 static char *monthnames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
3851 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
3855 * expand things like __FILE__. Place the expansion into the output
3856 * buffer *without* rescanning.
3860 special_symbol (hp, op)
3867 FILE_BUF *ip = NULL;
3870 int paren = 0; /* For special `defined' keyword */
3872 if (pcp_outfile && pcp_inside_if
3873 && hp->type != T_SPEC_DEFINED && hp->type != T_CONST)
3874 error ("Predefined macro `%s' used inside `#if' during precompilation",
3877 for (i = indepth; i >= 0; i--)
3878 if (instack[i].fname != NULL) {
3883 error ("cccp error: not in any file?!");
3884 return; /* the show must go on */
3892 if (hp->type == T_FILE)
3893 string = ip->nominal_fname;
3895 string = instack[0].nominal_fname;
3899 buf = (char *) alloca (3 + 4 * strlen (string));
3900 quote_string (buf, string);
3908 case T_INCLUDE_LEVEL:
3910 for (i = indepth; i >= 0; i--)
3911 if (instack[i].fname != NULL)
3914 buf = (char *) alloca (8); /* Eight bytes ought to be more than enough */
3915 sprintf (buf, "%d", true_indepth - 1);
3919 buf = (char *) alloca (3 + strlen (version_string));
3920 sprintf (buf, "\"%s\"", version_string);
3923 #ifndef NO_BUILTIN_SIZE_TYPE
3929 #ifndef NO_BUILTIN_PTRDIFF_TYPE
3930 case T_PTRDIFF_TYPE:
3939 case T_USER_LABEL_PREFIX_TYPE:
3940 buf = USER_LABEL_PREFIX;
3943 case T_REGISTER_PREFIX_TYPE:
3944 buf = REGISTER_PREFIX;
3948 buf = (char *) alloca (4 * sizeof (int));
3949 sprintf (buf, "%d", hp->value.ival);
3950 if (pcp_inside_if && pcp_outfile)
3951 /* Output a precondition for this macro use */
3952 fprintf (pcp_outfile, "#define %s %d\n", hp->name, hp->value.ival);
3956 buf = (char *) alloca (10);
3957 sprintf (buf, "%d", ip->lineno);
3962 buf = (char *) alloca (20);
3963 timebuf = timestamp ();
3964 if (hp->type == T_DATE)
3965 sprintf (buf, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon],
3966 timebuf->tm_mday, timebuf->tm_year + 1900);
3968 sprintf (buf, "\"%02d:%02d:%02d\"", timebuf->tm_hour, timebuf->tm_min,
3972 case T_SPEC_DEFINED:
3973 buf = " 0 "; /* Assume symbol is not defined */
3974 ip = &instack[indepth];
3975 SKIP_WHITE_SPACE (ip->bufp);
3976 if (*ip->bufp == '(') {
3978 ip->bufp++; /* Skip over the paren */
3979 SKIP_WHITE_SPACE (ip->bufp);
3982 if (!is_idstart[*ip->bufp])
3984 if (hp = lookup (ip->bufp, -1, -1)) {
3985 if (pcp_outfile && pcp_inside_if
3986 && (hp->type == T_CONST
3987 || (hp->type == T_MACRO && hp->value.defn->predefined)))
3988 /* Output a precondition for this macro use. */
3989 fprintf (pcp_outfile, "#define %s\n", hp->name);
3993 if (pcp_outfile && pcp_inside_if) {
3994 /* Output a precondition for this macro use */
3995 U_CHAR *cp = ip->bufp;
3996 fprintf (pcp_outfile, "#undef ");
3997 while (is_idchar[*cp]) /* Ick! */
3998 fputc (*cp++, pcp_outfile);
3999 putc ('\n', pcp_outfile);
4001 while (is_idchar[*ip->bufp])
4003 SKIP_WHITE_SPACE (ip->bufp);
4005 if (*ip->bufp != ')')
4013 error ("`defined' without an identifier");
4017 error ("cccp error: invalid special hash type"); /* time for gdb */
4021 check_expand (op, len);
4022 bcopy (buf, (char *) op->bufp, len);
4029 /* Routines to handle #directives */
4031 /* Handle #include and #import.
4032 This function expects to see "fname" or <fname> on the input. */
4035 do_include (buf, limit, op, keyword)
4036 U_CHAR *buf, *limit;
4038 struct directive *keyword;
4040 int importing = (keyword->type == T_IMPORT);
4041 int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
4042 static int import_warning = 0;
4043 char *fname; /* Dynamically allocated fname buffer */
4046 U_CHAR *fbeg, *fend; /* Beginning and end of fname */
4048 struct file_name_list *search_start = include; /* Chain of dirs to search */
4049 struct file_name_list dsp[1]; /* First in chain, if #include "..." */
4050 struct file_name_list *searchptr = 0;
4053 int f; /* file number */
4055 int retried = 0; /* Have already tried macro
4056 expanding the include line*/
4057 FILE_BUF trybuf; /* It got expanded into here */
4058 int angle_brackets = 0; /* 0 for "...", 1 for <...> */
4063 f= -1; /* JF we iz paranoid! */
4065 if (importing && warn_import && !inhibit_warnings
4066 && !instack[indepth].system_header_p && !import_warning) {
4068 warning ("using `#import' is not recommended");
4069 fprintf (stderr, "The fact that a certain header file need not be processed more than once\n");
4070 fprintf (stderr, "should be indicated in the header file, not where it is used.\n");
4071 fprintf (stderr, "The best way to do this is with a conditional of this form:\n\n");
4072 fprintf (stderr, " #ifndef _FOO_H_INCLUDED\n");
4073 fprintf (stderr, " #define _FOO_H_INCLUDED\n");
4074 fprintf (stderr, " ... <real contents of file> ...\n");
4075 fprintf (stderr, " #endif /* Not _FOO_H_INCLUDED */\n\n");
4076 fprintf (stderr, "Then users can use `#include' any number of times.\n");
4077 fprintf (stderr, "GNU C automatically avoids processing the file more than once\n");
4078 fprintf (stderr, "when it is equipped with such a conditional.\n");
4084 SKIP_WHITE_SPACE (fbeg);
4085 /* Discard trailing whitespace so we can easily see
4086 if we have parsed all the significant chars we were given. */
4087 while (limit != fbeg && is_hor_space[limit[-1]]) limit--;
4093 /* Copy the operand text, concatenating the strings. */
4096 fbeg = (U_CHAR *) alloca (limit - fbeg + 1);
4098 while (fin != limit) {
4099 while (fin != limit && *fin != '\"')
4104 /* If not at the end, there had better be another string. */
4105 /* Skip just horiz space, and don't go past limit. */
4106 while (fin != limit && is_hor_space[*fin]) fin++;
4107 if (fin != limit && *fin == '\"')
4115 /* We have "filename". Figure out directory this source
4116 file is coming from and put it on the front of the list. */
4118 /* If -I- was specified, don't search current dir, only spec'd ones. */
4119 if (ignore_srcdir) break;
4121 for (fp = &instack[indepth]; fp >= instack; fp--)
4126 if ((nam = fp->nominal_fname) != NULL) {
4127 /* Found a named file. Figure out dir of the file,
4128 and put it in front of the search list. */
4129 dsp[0].next = search_start;
4132 ep = rindex (nam, '/');
4134 ep = rindex (nam, ']');
4135 if (ep == NULL) ep = rindex (nam, '>');
4136 if (ep == NULL) ep = rindex (nam, ':');
4137 if (ep != NULL) ep++;
4141 dsp[0].fname = (char *) alloca (n + 1);
4142 strncpy (dsp[0].fname, nam, n);
4143 dsp[0].fname[n] = '\0';
4144 if (n + INCLUDE_LEN_FUDGE > max_include_len)
4145 max_include_len = n + INCLUDE_LEN_FUDGE;
4147 dsp[0].fname = 0; /* Current directory */
4149 dsp[0].got_name_map = 0;
4158 while (fend != limit && *fend != '>') fend++;
4159 if (*fend == '>' && fend + 1 == limit) {
4161 /* If -I-, start with the first -I dir after the -I-. */
4162 if (first_bracket_include)
4163 search_start = first_bracket_include;
4171 * Support '#include xyz' like VAX-C to allow for easy use of all the
4172 * decwindow include files. It defaults to '#include <xyz.h>' (so the
4173 * code from case '<' is repeated here) and generates a warning.
4175 if (isalpha(*(--fbeg))) {
4177 while (fend != limit && (!isspace(*fend))) fend++;
4178 warning ("VAX-C-style include specification found, use '#include <filename.h>' !");
4179 if (fend == limit) {
4181 /* If -I-, start with the first -I dir after the -I-. */
4182 if (first_bracket_include)
4183 search_start = first_bracket_include;
4191 error ("`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
4194 trybuf = expand_to_temp_buffer (buf, limit, 0, 0);
4195 buf = (U_CHAR *) alloca (trybuf.bufp - trybuf.buf + 1);
4196 bcopy ((char *) trybuf.buf, (char *) buf, trybuf.bufp - trybuf.buf);
4197 limit = buf + (trybuf.bufp - trybuf.buf);
4204 /* For #include_next, skip in the search path
4205 past the dir in which the containing file was found. */
4208 for (fp = &instack[indepth]; fp >= instack; fp--)
4209 if (fp->fname != NULL) {
4210 /* fp->dir is null if the containing file was specified
4211 with an absolute file name. In that case, don't skip anything. */
4213 search_start = fp->dir->next;
4222 error ("empty file name in `#%s'", keyword->name);
4226 /* Allocate this permanently, because it gets stored in the definitions
4228 fname = (char *) xmalloc (max_include_len + flen + 4);
4229 /* + 2 above for slash and terminating null. */
4230 /* + 2 added for '.h' on VMS (to support '#include filename') */
4232 /* If specified file name is absolute, just open it. */
4235 strncpy (fname, fbeg, flen);
4237 if (redundant_include_p (fname))
4240 f = lookup_import (fname, NULL_PTR);
4242 f = open_include_file (fname, NULL_PTR);
4244 return 0; /* Already included this file */
4246 /* Search directory path, trying to open the file.
4247 Copy each filename tried into FNAME. */
4249 for (searchptr = search_start; searchptr; searchptr = searchptr->next) {
4250 if (searchptr->fname) {
4251 /* The empty string in a search path is ignored.
4252 This makes it possible to turn off entirely
4253 a standard piece of the list. */
4254 if (searchptr->fname[0] == 0)
4256 strcpy (fname, searchptr->fname);
4257 strcat (fname, "/");
4258 fname[strlen (fname) + flen] = 0;
4262 strncat (fname, fbeg, flen);
4264 /* Change this 1/2 Unix 1/2 VMS file specification into a
4265 full VMS file specification */
4266 if (searchptr->fname && (searchptr->fname[0] != 0)) {
4267 /* Fix up the filename */
4268 hack_vms_include_specification (fname);
4270 /* This is a normal VMS filespec, so use it unchanged. */
4271 strncpy (fname, fbeg, flen);
4273 /* if it's '#include filename', add the missing .h */
4274 if (index(fname,'.')==NULL) {
4275 strcat (fname, ".h");
4280 f = lookup_import (fname, searchptr);
4282 f = open_include_file (fname, searchptr);
4284 return 0; /* Already included this file */
4286 else if (f == -1 && errno == EACCES)
4287 warning ("Header file %s exists, but is not readable", fname);
4289 if (redundant_include_p (fname)) {
4299 /* A file that was not found. */
4301 strncpy (fname, fbeg, flen);
4303 /* If generating dependencies and -MG was specified, we assume missing
4304 files are leaf files, living in the same directory as the source file
4305 or other similar place; these missing files may be generated from
4306 other files and may not exist yet (eg: y.tab.h). */
4307 if (print_deps_missing_files
4308 && print_deps > (angle_brackets || (system_include_depth > 0)))
4310 /* If it was requested as a system header file,
4311 then assume it belongs in the first place to look for such. */
4314 for (searchptr = search_start; searchptr; searchptr = searchptr->next)
4316 if (searchptr->fname)
4320 if (searchptr->fname[0] == 0)
4322 p = xmalloc (strlen (searchptr->fname)
4323 + strlen (fname) + 2);
4324 strcpy (p, searchptr->fname);
4327 deps_output (p, ' ');
4334 /* Otherwise, omit the directory, as if the file existed
4335 in the directory with the source. */
4336 deps_output (fname, ' ');
4339 /* If -M was specified, and this header file won't be added to the
4340 dependency list, then don't count this as an error, because we can
4341 still produce correct output. Otherwise, we can't produce correct
4342 output, because there may be dependencies we need inside the missing
4343 file, and we don't know what directory this missing file exists in. */
4345 && (print_deps <= (angle_brackets || (system_include_depth > 0))))
4346 warning ("No include path in which to find %s", fname);
4347 else if (search_start)
4348 error_from_errno (fname);
4350 error ("No include path in which to find %s", fname);
4354 /* Check to see if this include file is a once-only include file.
4357 struct file_name_list* ptr;
4359 for (ptr = dont_repeat_files; ptr; ptr = ptr->next) {
4360 if (!strcmp (ptr->fname, fname)) {
4362 return 0; /* This file was once'd. */
4366 for (ptr = all_include_files; ptr; ptr = ptr->next) {
4367 if (!strcmp (ptr->fname, fname))
4368 break; /* This file was included before. */
4372 /* This is the first time for this file. */
4373 /* Add it to list of files included. */
4375 ptr = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
4376 ptr->control_macro = 0;
4377 ptr->c_system_include_path = 0;
4378 ptr->next = all_include_files;
4379 all_include_files = ptr;
4380 ptr->fname = savestring (fname);
4381 ptr->got_name_map = 0;
4383 /* For -M, add this file to the dependencies. */
4384 if (print_deps > (angle_brackets || (system_include_depth > 0)))
4385 deps_output (fname, ' ');
4388 /* Handle -H option. */
4389 if (print_include_names) {
4390 output_dots (stderr, indepth);
4391 fprintf (stderr, "%s\n", fname);
4395 system_include_depth++;
4397 /* Actually process the file. */
4398 add_import (f, fname); /* Record file on "seen" list for #import. */
4400 pcftry = (char *) alloca (strlen (fname) + 30);
4408 sprintf (pcftry, "%s%d", fname, pcfnum++);
4410 pcf = open (pcftry, O_RDONLY, 0666);
4416 if (bcmp ((char *) &stat_f.st_ino, (char *) &s.st_ino,
4418 || stat_f.st_dev != s.st_dev)
4420 pcfbuf = check_precompiled (pcf, fname, &pcfbuflimit);
4421 /* Don't need it any more. */
4426 /* Don't need it at all. */
4431 } while (pcf != -1 && !pcfbuf);
4433 /* Actually process the file */
4435 pcfname = xmalloc (strlen (pcftry) + 1);
4436 strcpy (pcfname, pcftry);
4437 pcfinclude (pcfbuf, pcfbuflimit, fname, op);
4440 finclude (f, fname, op, is_system_include (fname), searchptr);
4443 system_include_depth--;
4448 /* Return nonzero if there is no need to include file NAME
4449 because it has already been included and it contains a conditional
4450 to make a repeated include do nothing. */
4453 redundant_include_p (name)
4456 struct file_name_list *l = all_include_files;
4457 for (; l; l = l->next)
4458 if (! strcmp (name, l->fname)
4460 && lookup (l->control_macro, -1, -1))
4465 /* Return nonzero if the given FILENAME is an absolute pathname which
4466 designates a file within one of the known "system" include file
4467 directories. We assume here that if the given FILENAME looks like
4468 it is the name of a file which resides either directly in a "system"
4469 include file directory, or within any subdirectory thereof, then the
4470 given file must be a "system" include file. This function tells us
4471 if we should suppress pedantic errors/warnings for the given FILENAME.
4473 The value is 2 if the file is a C-language system header file
4474 for which C++ should (on most systems) assume `extern "C"'. */
4477 is_system_include (filename)
4478 register char *filename;
4480 struct file_name_list *searchptr;
4482 for (searchptr = first_system_include; searchptr;
4483 searchptr = searchptr->next)
4484 if (searchptr->fname) {
4485 register char *sys_dir = searchptr->fname;
4486 register unsigned length = strlen (sys_dir);
4488 if (! strncmp (sys_dir, filename, length) && filename[length] == '/')
4490 if (searchptr->c_system_include_path)
4499 /* The file_name_map structure holds a mapping of file names for a
4500 particular directory. This mapping is read from the file named
4501 FILE_NAME_MAP_FILE in that directory. Such a file can be used to
4502 map filenames on a file system with severe filename restrictions,
4503 such as DOS. The format of the file name map file is just a series
4504 of lines with two tokens on each line. The first token is the name
4505 to map, and the second token is the actual name to use. */
4507 struct file_name_map
4509 struct file_name_map *map_next;
4514 #define FILE_NAME_MAP_FILE "header.gcc"
4516 /* Read a space delimited string of unlimited length from a stdio
4520 read_filename_string (ch, f)
4528 set = alloc = xmalloc (len + 1);
4532 while ((ch = getc (f)) != EOF && ! is_space[ch])
4534 if (set - alloc == len)
4537 alloc = xrealloc (alloc, len + 1);
4538 set = alloc + len / 2;
4548 /* Read the file name map file for DIRNAME. */
4550 static struct file_name_map *
4551 read_name_map (dirname)
4554 /* This structure holds a linked list of file name maps, one per
4556 struct file_name_map_list
4558 struct file_name_map_list *map_list_next;
4559 char *map_list_name;
4560 struct file_name_map *map_list_map;
4562 static struct file_name_map_list *map_list;
4563 register struct file_name_map_list *map_list_ptr;
4567 for (map_list_ptr = map_list; map_list_ptr;
4568 map_list_ptr = map_list_ptr->map_list_next)
4569 if (! strcmp (map_list_ptr->map_list_name, dirname))
4570 return map_list_ptr->map_list_map;
4572 map_list_ptr = ((struct file_name_map_list *)
4573 xmalloc (sizeof (struct file_name_map_list)));
4574 map_list_ptr->map_list_name = savestring (dirname);
4575 map_list_ptr->map_list_map = NULL;
4577 name = (char *) alloca (strlen (dirname) + strlen (FILE_NAME_MAP_FILE) + 2);
4578 strcpy (name, dirname);
4581 strcat (name, FILE_NAME_MAP_FILE);
4582 f = fopen (name, "r");
4584 map_list_ptr->map_list_map = NULL;
4588 int dirlen = strlen (dirname);
4590 while ((ch = getc (f)) != EOF)
4593 struct file_name_map *ptr;
4597 from = read_filename_string (ch, f);
4598 while ((ch = getc (f)) != EOF && is_hor_space[ch])
4600 to = read_filename_string (ch, f);
4602 ptr = ((struct file_name_map *)
4603 xmalloc (sizeof (struct file_name_map)));
4604 ptr->map_from = from;
4606 /* Make the real filename absolute. */
4611 ptr->map_to = xmalloc (dirlen + strlen (to) + 2);
4612 strcpy (ptr->map_to, dirname);
4613 ptr->map_to[dirlen] = '/';
4614 strcpy (ptr->map_to + dirlen + 1, to);
4618 ptr->map_next = map_list_ptr->map_list_map;
4619 map_list_ptr->map_list_map = ptr;
4621 while ((ch = getc (f)) != '\n')
4628 map_list_ptr->map_list_next = map_list;
4629 map_list = map_list_ptr;
4631 return map_list_ptr->map_list_map;
4634 /* Try to open include file FILENAME. SEARCHPTR is the directory
4635 being tried from the include file search path. This function maps
4636 filenames on file systems based on information read by
4640 open_include_file (filename, searchptr)
4642 struct file_name_list *searchptr;
4644 register struct file_name_map *map;
4645 register char *from;
4648 if (searchptr && ! searchptr->got_name_map)
4650 searchptr->name_map = read_name_map (searchptr->fname
4651 ? searchptr->fname : ".");
4652 searchptr->got_name_map = 1;
4655 /* First check the mapping for the directory we are using. */
4656 if (searchptr && searchptr->name_map)
4659 if (searchptr->fname)
4660 from += strlen (searchptr->fname) + 1;
4661 for (map = searchptr->name_map; map; map = map->map_next)
4663 if (! strcmp (map->map_from, from))
4665 /* Found a match. */
4666 return open (map->map_to, O_RDONLY, 0666);
4671 /* Try to find a mapping file for the particular directory we are
4672 looking in. Thus #include <sys/types.h> will look up sys/types.h
4673 in /usr/include/header.gcc and look up types.h in
4674 /usr/include/sys/header.gcc. */
4675 p = rindex (filename, '/');
4680 && strlen (searchptr->fname) == p - filename
4681 && ! strncmp (searchptr->fname, filename, p - filename))
4683 /* FILENAME is in SEARCHPTR, which we've already checked. */
4684 return open (filename, O_RDONLY, 0666);
4694 dir = (char *) alloca (p - filename + 1);
4695 bcopy (filename, dir, p - filename);
4696 dir[p - filename] = '\0';
4699 for (map = read_name_map (dir); map; map = map->map_next)
4700 if (! strcmp (map->map_from, from))
4701 return open (map->map_to, O_RDONLY, 0666);
4703 return open (filename, O_RDONLY, 0666);
4706 /* Process the contents of include file FNAME, already open on descriptor F,
4708 SYSTEM_HEADER_P is 1 if this file resides in any one of the known
4709 "system" include directories (as decided by the `is_system_include'
4711 DIRPTR is the link in the dir path through which this file was found,
4712 or 0 if the file name was absolute. */
4715 finclude (f, fname, op, system_header_p, dirptr)
4719 int system_header_p;
4720 struct file_name_list *dirptr;
4725 FILE_BUF *fp; /* For input stack frame */
4726 int missing_newline = 0;
4728 CHECK_DEPTH (return;);
4730 if (file_size_and_mode (f, &st_mode, &st_size) < 0)
4732 perror_with_name (fname);
4737 fp = &instack[indepth + 1];
4738 bzero ((char *) fp, sizeof (FILE_BUF));
4739 fp->nominal_fname = fp->fname = fname;
4742 fp->if_stack = if_stack;
4743 fp->system_header_p = system_header_p;
4746 if (S_ISREG (st_mode)) {
4747 fp->buf = (U_CHAR *) xmalloc (st_size + 2);
4750 /* Read the file contents, knowing that st_size is an upper bound
4751 on the number of bytes we can read. */
4752 fp->length = safe_read (f, fp->buf, st_size);
4753 if (fp->length < 0) goto nope;
4755 else if (S_ISDIR (st_mode)) {
4756 error ("directory `%s' specified in #include", fname);
4760 /* Cannot count its file size before reading.
4761 First read the entire file into heap and
4762 copy them into buffer on stack. */
4767 fp->buf = (U_CHAR *) xmalloc (bsize + 2);
4770 i = safe_read (f, fp->buf + st_size, bsize - st_size);
4772 goto nope; /* error! */
4774 if (st_size != bsize)
4775 break; /* End of file */
4777 fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
4780 fp->length = st_size;
4783 if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n')
4784 /* Backslash-newline at end is not good enough. */
4785 || (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) {
4786 fp->buf[fp->length++] = '\n';
4787 missing_newline = 1;
4789 fp->buf[fp->length] = '\0';
4791 /* Close descriptor now, so nesting does not use lots of descriptors. */
4794 /* Must do this before calling trigraph_pcp, so that the correct file name
4795 will be printed in warning messages. */
4798 input_file_stack_tick++;
4803 output_line_command (fp, op, 0, enter_file);
4806 if (missing_newline)
4809 if (pedantic && missing_newline)
4810 pedwarn ("file does not end in newline");
4813 input_file_stack_tick++;
4814 output_line_command (&instack[indepth], op, 0, leave_file);
4820 perror_with_name (fname);
4825 /* Record that inclusion of the file named FILE
4826 should be controlled by the macro named MACRO_NAME.
4827 This means that trying to include the file again
4828 will do something if that macro is defined. */
4831 record_control_macro (file, macro_name)
4835 struct file_name_list *new;
4837 for (new = all_include_files; new; new = new->next) {
4838 if (!strcmp (new->fname, file)) {
4839 new->control_macro = macro_name;
4844 /* If the file is not in all_include_files, something's wrong. */
4848 /* Maintain and search list of included files, for #import. */
4850 #define IMPORT_HASH_SIZE 31
4852 struct import_file {
4856 struct import_file *next;
4859 /* Hash table of files already included with #include or #import. */
4861 static struct import_file *import_hash_table[IMPORT_HASH_SIZE];
4863 /* Hash a file name for import_hash_table. */
4871 while (*f) val += *f++;
4872 return (val%IMPORT_HASH_SIZE);
4875 /* Search for file FILENAME in import_hash_table.
4876 Return -2 if found, either a matching name or a matching inode.
4877 Otherwise, open the file and return a file descriptor if successful
4878 or -1 if unsuccessful. */
4881 lookup_import (filename, searchptr)
4883 struct file_name_list *searchptr;
4885 struct import_file *i;
4891 hashval = import_hash (filename);
4893 /* Attempt to find file in list of already included files */
4894 i = import_hash_table[hashval];
4897 if (!strcmp (filename, i->name))
4898 return -2; /* return found */
4901 /* Open it and try a match on inode/dev */
4902 fd = open_include_file (filename, searchptr);
4906 for (h = 0; h < IMPORT_HASH_SIZE; h++) {
4907 i = import_hash_table[h];
4909 /* Compare the inode and the device.
4910 Supposedly on some systems the inode is not a scalar. */
4911 if (!bcmp ((char *) &i->inode, (char *) &sb.st_ino, sizeof (sb.st_ino))
4912 && i->dev == sb.st_dev) {
4914 return -2; /* return found */
4919 return fd; /* Not found, return open file */
4922 /* Add the file FNAME, open on descriptor FD, to import_hash_table. */
4925 add_import (fd, fname)
4929 struct import_file *i;
4933 hashval = import_hash (fname);
4935 i = (struct import_file *)xmalloc (sizeof (struct import_file));
4936 i->name = (char *)xmalloc (strlen (fname)+1);
4937 strcpy (i->name, fname);
4938 bcopy ((char *) &sb.st_ino, (char *) &i->inode, sizeof (sb.st_ino));
4940 i->next = import_hash_table[hashval];
4941 import_hash_table[hashval] = i;
4944 /* Load the specified precompiled header into core, and verify its
4945 preconditions. PCF indicates the file descriptor to read, which must
4946 be a regular file. FNAME indicates the file name of the original
4947 header. *LIMIT will be set to an address one past the end of the file.
4948 If the preconditions of the file are not satisfied, the buffer is
4949 freed and we return 0. If the preconditions are satisfied, return
4950 the address of the buffer following the preconditions. The buffer, in
4951 this case, should never be freed because various pieces of it will
4952 be referred to until all precompiled strings are output at the end of
4956 check_precompiled (pcf, fname, limit)
4970 if (file_size_and_mode (pcf, &st_mode, &st_size) < 0)
4973 if (S_ISREG (st_mode))
4975 buf = xmalloc (st_size + 2);
4976 length = safe_read (pcf, buf, st_size);
4983 if (length > 0 && buf[length-1] != '\n')
4984 buf[length++] = '\n';
4987 *limit = buf + length;
4989 /* File is in core. Check the preconditions. */
4990 if (!check_preconditions (buf))
4992 for (cp = buf; *cp; cp++)
4995 fprintf (stderr, "Using preinclude %s\n", fname);
5001 fprintf (stderr, "Cannot use preinclude %s\n", fname);
5007 /* PREC (null terminated) points to the preconditions of a
5008 precompiled header. These are a series of #define and #undef
5009 lines which must match the current contents of the hash
5012 check_preconditions (prec)
5019 lineend = (char *) index (prec, '\n');
5021 if (*prec++ != '#') {
5022 error ("Bad format encountered while reading precompiled file");
5025 if (!strncmp (prec, "define", 6)) {
5029 mdef = create_definition (prec, lineend, NULL_PTR);
5034 if ((hp = lookup (mdef.symnam, mdef.symlen, -1)) == NULL
5035 || (hp->type != T_MACRO && hp->type != T_CONST)
5036 || (hp->type == T_MACRO
5037 && !compare_defs (mdef.defn, hp->value.defn)
5038 && (mdef.defn->length != 2
5039 || mdef.defn->expansion[0] != '\n'
5040 || mdef.defn->expansion[1] != ' ')))
5042 } else if (!strncmp (prec, "undef", 5)) {
5047 while (is_hor_space[(U_CHAR) *prec])
5050 while (is_idchar[(U_CHAR) *prec])
5054 if (lookup (name, len, -1))
5057 error ("Bad format encountered while reading precompiled file");
5062 /* They all passed successfully */
5066 /* Process the main body of a precompiled file. BUF points to the
5067 string section of the file, following the preconditions. LIMIT is one
5068 character past the end. NAME is the name of the file being read
5069 in. OP is the main output buffer */
5071 pcfinclude (buf, limit, name, op)
5072 U_CHAR *buf, *limit, *name;
5079 /* First in the file comes 4 bytes indicating the number of strings, */
5080 /* in network byte order. (MSB first). */
5082 nstrings = (nstrings << 8) | *cp++;
5083 nstrings = (nstrings << 8) | *cp++;
5084 nstrings = (nstrings << 8) | *cp++;
5086 /* Looping over each string... */
5087 while (nstrings--) {
5088 U_CHAR *string_start;
5089 U_CHAR *endofthiskey;
5093 /* Each string starts with a STRINGDEF structure (str), followed */
5094 /* by the text of the string (string_start) */
5096 /* First skip to a longword boundary */
5097 /* ??? Why a 4-byte boundary? On all machines? */
5098 /* NOTE: This works correctly even if HOST_WIDE_INT
5099 is narrower than a pointer.
5100 Do not try risky measures here to get another type to use!
5101 Do not include stddef.h--it will fail! */
5102 if ((HOST_WIDE_INT) cp & 3)
5103 cp += 4 - ((HOST_WIDE_INT) cp & 3);
5105 /* Now get the string. */
5106 str = (STRINGDEF *) cp;
5107 string_start = cp += sizeof (STRINGDEF);
5109 for (; *cp; cp++) /* skip the string */
5112 /* We need to macro expand the string here to ensure that the
5113 proper definition environment is in place. If it were only
5114 expanded when we find out it is needed, macros necessary for
5115 its proper expansion might have had their definitions changed. */
5116 tmpbuf = expand_to_temp_buffer (string_start, cp++, 0, 0);
5117 /* Lineno is already set in the precompiled file */
5118 str->contents = tmpbuf.buf;
5119 str->len = tmpbuf.length;
5121 str->filename = name;
5122 str->output_mark = outbuf.bufp - outbuf.buf;
5125 *stringlist_tailp = str;
5126 stringlist_tailp = &str->chain;
5128 /* Next comes a fourbyte number indicating the number of keys */
5129 /* for this string. */
5131 nkeys = (nkeys << 8) | *cp++;
5132 nkeys = (nkeys << 8) | *cp++;
5133 nkeys = (nkeys << 8) | *cp++;
5135 /* If this number is -1, then the string is mandatory. */
5139 /* Otherwise, for each key, */
5140 for (; nkeys--; free (tmpbuf.buf), cp = endofthiskey + 1) {
5141 KEYDEF *kp = (KEYDEF *) cp;
5144 /* It starts with a KEYDEF structure */
5145 cp += sizeof (KEYDEF);
5147 /* Find the end of the key. At the end of this for loop we
5148 advance CP to the start of the next key using this variable. */
5149 endofthiskey = cp + strlen (cp);
5152 /* Expand the key, and enter it into the hash table. */
5153 tmpbuf = expand_to_temp_buffer (cp, endofthiskey, 0, 0);
5154 tmpbuf.bufp = tmpbuf.buf;
5156 while (is_hor_space[*tmpbuf.bufp])
5158 if (!is_idstart[*tmpbuf.bufp]
5159 || tmpbuf.bufp == tmpbuf.buf + tmpbuf.length) {
5164 hp = lookup (tmpbuf.bufp, -1, -1);
5167 install (tmpbuf.bufp, -1, T_PCSTRING, 0, (char *) kp, -1);
5169 else if (hp->type == T_PCSTRING) {
5170 kp->chain = hp->value.keydef;
5171 hp->value.keydef = kp;
5177 /* This output_line_command serves to switch us back to the current
5178 input file in case some of these strings get output (which will
5179 result in line commands for the header file being output). */
5180 output_line_command (&instack[indepth], op, 0, enter_file);
5183 /* Called from rescan when it hits a key for strings. Mark them all */
5184 /* used and clean up. */
5191 for (kp = hp->value.keydef; kp; kp = kp->chain)
5192 kp->str->writeflag = 1;
5196 /* Write the output, interspersing precompiled strings in their */
5197 /* appropriate places. */
5201 STRINGDEF *next_string;
5202 U_CHAR *cur_buf_loc;
5203 int line_command_len = 80;
5204 char *line_command = xmalloc (line_command_len);
5207 /* In each run through the loop, either cur_buf_loc == */
5208 /* next_string_loc, in which case we print a series of strings, or */
5209 /* it is less than next_string_loc, in which case we write some of */
5211 cur_buf_loc = outbuf.buf;
5212 next_string = stringlist;
5214 while (cur_buf_loc < outbuf.bufp || next_string) {
5216 && cur_buf_loc - outbuf.buf == next_string->output_mark) {
5217 if (next_string->writeflag) {
5218 len = 4 * strlen (next_string->filename) + 32;
5219 while (len > line_command_len)
5220 line_command = xrealloc (line_command,
5221 line_command_len *= 2);
5222 sprintf (line_command, "\n# %d ", next_string->lineno);
5223 strcpy (quote_string (line_command + strlen (line_command),
5224 next_string->filename),
5226 safe_write (fileno (stdout), line_command, strlen (line_command));
5227 safe_write (fileno (stdout), next_string->contents, next_string->len);
5229 next_string = next_string->chain;
5233 ? (next_string->output_mark
5234 - (cur_buf_loc - outbuf.buf))
5235 : outbuf.bufp - cur_buf_loc);
5237 safe_write (fileno (stdout), cur_buf_loc, len);
5241 free (line_command);
5244 /* Pass a directive through to the output file.
5245 BUF points to the contents of the directive, as a contiguous string.
5246 LIMIT points to the first character past the end of the directive.
5247 KEYWORD is the keyword-table entry for the directive. */
5250 pass_thru_directive (buf, limit, op, keyword)
5251 U_CHAR *buf, *limit;
5253 struct directive *keyword;
5255 register unsigned keyword_length = keyword->length;
5257 check_expand (op, 1 + keyword_length + (limit - buf));
5259 bcopy (keyword->name, (char *) op->bufp, keyword_length);
5260 op->bufp += keyword_length;
5261 if (limit != buf && buf[0] != ' ')
5263 bcopy ((char *) buf, (char *) op->bufp, limit - buf);
5264 op->bufp += (limit - buf);
5267 /* Count the line we have just made in the output,
5268 to get in sync properly. */
5273 /* The arglist structure is built by do_define to tell
5274 collect_definition where the argument names begin. That
5275 is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist
5276 would contain pointers to the strings x, y, and z.
5277 Collect_definition would then build a DEFINITION node,
5278 with reflist nodes pointing to the places x, y, and z had
5279 appeared. So the arglist is just convenience data passed
5280 between these two routines. It is not kept around after
5281 the current #define has been processed and entered into the
5285 struct arglist *next;
5292 /* Create a DEFINITION node from a #define directive. Arguments are
5293 as for do_define. */
5295 create_definition (buf, limit, op)
5296 U_CHAR *buf, *limit;
5299 U_CHAR *bp; /* temp ptr into input buffer */
5300 U_CHAR *symname; /* remember where symbol name starts */
5301 int sym_length; /* and how long it is */
5302 int line = instack[indepth].lineno;
5303 char *file = instack[indepth].nominal_fname;
5307 int arglengths = 0; /* Accumulate lengths of arg names
5308 plus number of args. */
5313 while (is_hor_space[*bp])
5316 symname = bp; /* remember where it starts */
5317 sym_length = check_macro_name (bp, "macro");
5320 /* Lossage will occur if identifiers or control keywords are broken
5321 across lines using backslash. This is not the right place to take
5325 struct arglist *arg_ptrs = NULL;
5328 bp++; /* skip '(' */
5329 SKIP_WHITE_SPACE (bp);
5331 /* Loop over macro argument names. */
5332 while (*bp != ')') {
5333 struct arglist *temp;
5335 temp = (struct arglist *) alloca (sizeof (struct arglist));
5337 temp->next = arg_ptrs;
5338 temp->argno = argno++;
5339 temp->rest_args = 0;
5343 pedwarn ("another parameter follows `%s'",
5346 if (!is_idstart[*bp])
5347 pedwarn ("invalid character in macro parameter name");
5349 /* Find the end of the arg name. */
5350 while (is_idchar[*bp]) {
5352 /* do we have a "special" rest-args extension here? */
5353 if (limit - bp > REST_EXTENSION_LENGTH &&
5354 strncmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
5356 temp->rest_args = 1;
5360 temp->length = bp - temp->name;
5362 bp += REST_EXTENSION_LENGTH;
5363 arglengths += temp->length + 2;
5364 SKIP_WHITE_SPACE (bp);
5365 if (temp->length == 0 || (*bp != ',' && *bp != ')')) {
5366 error ("badly punctuated parameter list in `#define'");
5371 SKIP_WHITE_SPACE (bp);
5374 error ("unterminated parameter list in `#define'");
5378 struct arglist *otemp;
5380 for (otemp = temp->next; otemp != NULL; otemp = otemp->next)
5381 if (temp->length == otemp->length &&
5382 strncmp (temp->name, otemp->name, temp->length) == 0) {
5385 name = (U_CHAR *) alloca (temp->length + 1);
5386 (void) strncpy (name, temp->name, temp->length);
5387 name[temp->length] = '\0';
5388 error ("duplicate argument name `%s' in `#define'", name);
5394 ++bp; /* skip paren */
5395 /* Skip spaces and tabs if any. */
5396 while (bp < limit && (*bp == ' ' || *bp == '\t'))
5398 /* now everything from bp before limit is the definition. */
5399 defn = collect_expansion (bp, limit, argno, arg_ptrs);
5400 defn->rest_args = rest_args;
5402 /* Now set defn->args.argnames to the result of concatenating
5403 the argument names in reverse order
5404 with comma-space between them. */
5405 defn->args.argnames = (U_CHAR *) xmalloc (arglengths + 1);
5407 struct arglist *temp;
5409 for (temp = arg_ptrs; temp; temp = temp->next) {
5410 bcopy (temp->name, &defn->args.argnames[i], temp->length);
5412 if (temp->next != 0) {
5413 defn->args.argnames[i++] = ',';
5414 defn->args.argnames[i++] = ' ';
5417 defn->args.argnames[i] = 0;
5420 /* Simple expansion or empty definition. */
5426 case '\t': case ' ':
5427 /* Skip spaces and tabs. */
5428 while (++bp < limit && (*bp == ' ' || *bp == '\t'))
5432 case '!': case '"': case '#': case '%': case '&': case '\'':
5433 case ')': case '*': case '+': case ',': case '-': case '.':
5434 case '/': case ':': case ';': case '<': case '=': case '>':
5435 case '?': case '[': case '\\': case ']': case '^': case '{':
5436 case '|': case '}': case '~':
5437 warning ("missing white space after `#define %.*s'",
5438 sym_length, symname);
5442 pedwarn ("missing white space after `#define %.*s'",
5443 sym_length, symname);
5447 /* Now everything from bp before limit is the definition. */
5448 defn = collect_expansion (bp, limit, -1, NULL_PTR);
5449 defn->args.argnames = (U_CHAR *) "";
5455 /* OP is null if this is a predefinition */
5456 defn->predefined = !op;
5458 mdef.symnam = symname;
5459 mdef.symlen = sym_length;
5468 /* Process a #define command.
5469 BUF points to the contents of the #define command, as a contiguous string.
5470 LIMIT points to the first character past the end of the definition.
5471 KEYWORD is the keyword-table entry for #define. */
5474 do_define (buf, limit, op, keyword)
5475 U_CHAR *buf, *limit;
5477 struct directive *keyword;
5482 /* If this is a precompiler run (with -pcp) pass thru #define commands. */
5483 if (pcp_outfile && op)
5484 pass_thru_directive (buf, limit, op, keyword);
5486 mdef = create_definition (buf, limit, op);
5490 hashcode = hashf (mdef.symnam, mdef.symlen, HASHSIZE);
5494 if ((hp = lookup (mdef.symnam, mdef.symlen, hashcode)) != NULL) {
5496 /* Redefining a precompiled key is ok. */
5497 if (hp->type == T_PCSTRING)
5499 /* Redefining a macro is ok if the definitions are the same. */
5500 else if (hp->type == T_MACRO)
5501 ok = ! compare_defs (mdef.defn, hp->value.defn);
5502 /* Redefining a constant is ok with -D. */
5503 else if (hp->type == T_CONST)
5504 ok = ! done_initializing;
5505 /* Print the warning if it's not ok. */
5507 U_CHAR *msg; /* what pain... */
5509 /* If we are passing through #define and #undef directives, do
5510 that for this re-definition now. */
5511 if (debug_output && op)
5512 pass_thru_directive (buf, limit, op, keyword);
5514 msg = (U_CHAR *) alloca (mdef.symlen + 22);
5516 bcopy ((char *) mdef.symnam, (char *) (msg + 1), mdef.symlen);
5517 strcpy ((char *) (msg + mdef.symlen + 1), "' redefined");
5519 if (hp->type == T_MACRO)
5520 pedwarn_with_file_and_line (hp->value.defn->file, hp->value.defn->line,
5521 "this is the location of the previous definition");
5523 /* Replace the old definition. */
5525 hp->value.defn = mdef.defn;
5527 /* If we are passing through #define and #undef directives, do
5528 that for this new definition now. */
5529 if (debug_output && op)
5530 pass_thru_directive (buf, limit, op, keyword);
5531 install (mdef.symnam, mdef.symlen, T_MACRO, 0,
5532 (char *) mdef.defn, hashcode);
5543 /* Check a purported macro name SYMNAME, and yield its length.
5544 USAGE is the kind of name this is intended for. */
5547 check_macro_name (symname, usage)
5554 for (p = symname; is_idchar[*p]; p++)
5556 sym_length = p - symname;
5557 if (sym_length == 0)
5558 error ("invalid %s name", usage);
5559 else if (!is_idstart[*symname]) {
5560 U_CHAR *msg; /* what pain... */
5561 msg = (U_CHAR *) alloca (sym_length + 1);
5562 bcopy ((char *) symname, (char *) msg, sym_length);
5563 msg[sym_length] = 0;
5564 error ("invalid %s name `%s'", usage, msg);
5566 if (! strncmp (symname, "defined", 7) && sym_length == 7)
5567 error ("invalid %s name `defined'", usage);
5573 * return zero if two DEFINITIONs are isomorphic
5576 compare_defs (d1, d2)
5577 DEFINITION *d1, *d2;
5579 register struct reflist *a1, *a2;
5580 register U_CHAR *p1 = d1->expansion;
5581 register U_CHAR *p2 = d2->expansion;
5584 if (d1->nargs != d2->nargs)
5586 if (strcmp ((char *)d1->args.argnames, (char *)d2->args.argnames))
5588 for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2;
5589 a1 = a1->next, a2 = a2->next) {
5590 if (!((a1->nchars == a2->nchars && ! strncmp (p1, p2, a1->nchars))
5591 || ! comp_def_part (first, p1, a1->nchars, p2, a2->nchars, 0))
5592 || a1->argno != a2->argno
5593 || a1->stringify != a2->stringify
5594 || a1->raw_before != a2->raw_before
5595 || a1->raw_after != a2->raw_after)
5603 if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion),
5604 p2, d2->length - (p2 - d2->expansion), 1))
5609 /* Return 1 if two parts of two macro definitions are effectively different.
5610 One of the parts starts at BEG1 and has LEN1 chars;
5611 the other has LEN2 chars at BEG2.
5612 Any sequence of whitespace matches any other sequence of whitespace.
5613 FIRST means these parts are the first of a macro definition;
5614 so ignore leading whitespace entirely.
5615 LAST means these parts are the last of a macro definition;
5616 so ignore trailing whitespace entirely. */
5619 comp_def_part (first, beg1, len1, beg2, len2, last)
5621 U_CHAR *beg1, *beg2;
5625 register U_CHAR *end1 = beg1 + len1;
5626 register U_CHAR *end2 = beg2 + len2;
5628 while (beg1 != end1 && is_space[*beg1]) beg1++;
5629 while (beg2 != end2 && is_space[*beg2]) beg2++;
5632 while (beg1 != end1 && is_space[end1[-1]]) end1--;
5633 while (beg2 != end2 && is_space[end2[-1]]) end2--;
5635 while (beg1 != end1 && beg2 != end2) {
5636 if (is_space[*beg1] && is_space[*beg2]) {
5637 while (beg1 != end1 && is_space[*beg1]) beg1++;
5638 while (beg2 != end2 && is_space[*beg2]) beg2++;
5639 } else if (*beg1 == *beg2) {
5643 return (beg1 != end1) || (beg2 != end2);
5646 /* Read a replacement list for a macro with parameters.
5647 Build the DEFINITION structure.
5648 Reads characters of text starting at BUF until END.
5649 ARGLIST specifies the formal parameters to look for
5650 in the text of the definition; NARGS is the number of args
5651 in that list, or -1 for a macro name that wants no argument list.
5652 MACRONAME is the macro name itself (so we can avoid recursive expansion)
5653 and NAMELEN is its length in characters.
5655 Note that comments and backslash-newlines have already been deleted
5656 from the argument. */
5658 /* Leading and trailing Space, Tab, etc. are converted to markers
5659 Newline Space, Newline Tab, etc.
5660 Newline Space makes a space in the final output
5661 but is discarded if stringified. (Newline Tab is similar but
5662 makes a Tab instead.)
5664 If there is no trailing whitespace, a Newline Space is added at the end
5665 to prevent concatenation that would be contrary to the standard. */
5668 collect_expansion (buf, end, nargs, arglist)
5671 struct arglist *arglist;
5674 register U_CHAR *p, *limit, *lastp, *exp_p;
5675 struct reflist *endpat = NULL;
5676 /* Pointer to first nonspace after last ## seen. */
5678 /* Pointer to first nonspace after last single-# seen. */
5679 U_CHAR *stringify = 0;
5681 int expected_delimiter = '\0';
5683 /* Scan thru the replacement list, ignoring comments and quoted
5684 strings, picking up on the macro calls. It does a linear search
5685 thru the arg list on every potential symbol. Profiling might say
5686 that something smarter should happen. */
5691 /* Find the beginning of the trailing whitespace. */
5692 /* Find end of leading whitespace. */
5695 while (p < limit && is_space[limit[-1]]) limit--;
5696 while (p < limit && is_space[*p]) p++;
5698 /* Allocate space for the text in the macro definition.
5699 Leading and trailing whitespace chars need 2 bytes each.
5700 Each other input char may or may not need 1 byte,
5701 so this is an upper bound.
5702 The extra 2 are for invented trailing newline-marker and final null. */
5703 maxsize = (sizeof (DEFINITION)
5704 + 2 * (end - limit) + 2 * (p - buf)
5706 defn = (DEFINITION *) xcalloc (1, maxsize);
5708 defn->nargs = nargs;
5709 exp_p = defn->expansion = (U_CHAR *) defn + sizeof (DEFINITION);
5714 /* Convert leading whitespace to Newline-markers. */
5715 while (p < limit && is_space[*p]) {
5720 if (limit - p >= 2 && p[0] == '#' && p[1] == '#') {
5721 error ("`##' at start of macro definition");
5725 /* Process the main body of the definition. */
5727 int skipped_arg = 0;
5728 register U_CHAR c = *p++;
5736 if (expected_delimiter != '\0') {
5737 if (c == expected_delimiter)
5738 expected_delimiter = '\0';
5740 expected_delimiter = c;
5744 if (p < limit && expected_delimiter) {
5745 /* In a string, backslash goes through
5746 and makes next char ordinary. */
5752 /* # is ordinary inside a string. */
5753 if (expected_delimiter)
5755 if (p < limit && *p == '#') {
5756 /* ##: concatenate preceding and following tokens. */
5757 /* Take out the first #, discard preceding whitespace. */
5759 while (exp_p > lastp && is_hor_space[exp_p[-1]])
5761 /* Skip the second #. */
5763 /* Discard following whitespace. */
5764 SKIP_WHITE_SPACE (p);
5767 error ("`##' at end of macro definition");
5768 } else if (nargs >= 0) {
5769 /* Single #: stringify following argument ref.
5770 Don't leave the # in the expansion. */
5772 SKIP_WHITE_SPACE (p);
5773 if (p == limit || ! is_idstart[*p])
5774 error ("`#' operator is not followed by a macro argument name");
5781 /* In -traditional mode, recognize arguments inside strings and
5782 and character constants, and ignore special properties of #.
5783 Arguments inside strings are considered "stringified", but no
5784 extra quote marks are supplied. */
5788 if (expected_delimiter != '\0') {
5789 if (c == expected_delimiter)
5790 expected_delimiter = '\0';
5792 expected_delimiter = c;
5796 /* Backslash quotes delimiters and itself, but not macro args. */
5797 if (expected_delimiter != 0 && p < limit
5798 && (*p == expected_delimiter || *p == '\\')) {
5805 if (expected_delimiter != '\0') /* No comments inside strings. */
5808 /* If we find a comment that wasn't removed by handle_directive,
5809 this must be -traditional. So replace the comment with
5813 while (p < limit && !(p[-2] == '*' && p[-1] == '/'))
5816 /* Mark this as a concatenation-point, as if it had been ##. */
5824 /* Handle the start of a symbol. */
5825 if (is_idchar[c] && nargs > 0) {
5826 U_CHAR *id_beg = p - 1;
5830 while (p != limit && is_idchar[*p]) p++;
5831 id_len = p - id_beg;
5833 if (is_idstart[c]) {
5834 register struct arglist *arg;
5836 for (arg = arglist; arg != NULL; arg = arg->next) {
5837 struct reflist *tpat;
5839 if (arg->name[0] == c
5840 && arg->length == id_len
5841 && strncmp (arg->name, id_beg, id_len) == 0) {
5842 if (expected_delimiter && warn_stringify) {
5844 warning ("macro argument `%.*s' is stringified.",
5847 warning ("macro arg `%.*s' would be stringified with -traditional.",
5851 /* If ANSI, don't actually substitute inside a string. */
5852 if (!traditional && expected_delimiter)
5854 /* make a pat node for this arg and append it to the end of
5856 tpat = (struct reflist *) xmalloc (sizeof (struct reflist));
5858 tpat->raw_before = concat == id_beg;
5859 tpat->raw_after = 0;
5860 tpat->rest_args = arg->rest_args;
5861 tpat->stringify = (traditional ? expected_delimiter != '\0'
5862 : stringify == id_beg);
5865 defn->pattern = tpat;
5867 endpat->next = tpat;
5870 tpat->argno = arg->argno;
5871 tpat->nchars = exp_p - lastp;
5873 register U_CHAR *p1 = p;
5874 SKIP_WHITE_SPACE (p1);
5875 if (p1 + 2 <= limit && p1[0] == '#' && p1[1] == '#')
5876 tpat->raw_after = 1;
5878 lastp = exp_p; /* place to start copying from next time */
5885 /* If this was not a macro arg, copy it into the expansion. */
5886 if (! skipped_arg) {
5887 register U_CHAR *lim1 = p;
5891 if (stringify == id_beg)
5892 error ("`#' operator should be followed by a macro argument name");
5897 if (!traditional && expected_delimiter == 0) {
5898 /* There is no trailing whitespace, so invent some in ANSI mode.
5899 But not if "inside a string" (which in ANSI mode
5900 happens only for -D option). */
5907 defn->length = exp_p - defn->expansion;
5909 /* Crash now if we overrun the allocated size. */
5910 if (defn->length + 1 > maxsize)
5914 /* This isn't worth the time it takes. */
5915 /* give back excess storage */
5916 defn->expansion = (U_CHAR *) xrealloc (defn->expansion, defn->length + 1);
5923 do_assert (buf, limit, op, keyword)
5924 U_CHAR *buf, *limit;
5926 struct directive *keyword;
5928 U_CHAR *bp; /* temp ptr into input buffer */
5929 U_CHAR *symname; /* remember where symbol name starts */
5930 int sym_length; /* and how long it is */
5931 struct arglist *tokens = NULL;
5933 if (pedantic && done_initializing && !instack[indepth].system_header_p)
5934 pedwarn ("ANSI C does not allow `#assert'");
5938 while (is_hor_space[*bp])
5941 symname = bp; /* remember where it starts */
5942 sym_length = check_macro_name (bp, "assertion");
5944 /* #define doesn't do this, but we should. */
5945 SKIP_WHITE_SPACE (bp);
5947 /* Lossage will occur if identifiers or control tokens are broken
5948 across lines using backslash. This is not the right place to take
5952 error ("missing token-sequence in `#assert'");
5959 bp++; /* skip '(' */
5960 SKIP_WHITE_SPACE (bp);
5962 tokens = read_token_list (&bp, limit, &error_flag);
5966 error ("empty token-sequence in `#assert'");
5970 ++bp; /* skip paren */
5971 SKIP_WHITE_SPACE (bp);
5974 /* If this name isn't already an assertion name, make it one.
5975 Error if it was already in use in some other way. */
5978 ASSERTION_HASHNODE *hp;
5979 int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE);
5980 struct tokenlist_list *value
5981 = (struct tokenlist_list *) xmalloc (sizeof (struct tokenlist_list));
5983 hp = assertion_lookup (symname, sym_length, hashcode);
5985 if (sym_length == 7 && ! strncmp (symname, "defined", sym_length))
5986 error ("`defined' redefined as assertion");
5987 hp = assertion_install (symname, sym_length, hashcode);
5990 /* Add the spec'd token-sequence to the list of such. */
5991 value->tokens = tokens;
5992 value->next = hp->value;
6000 do_unassert (buf, limit, op, keyword)
6001 U_CHAR *buf, *limit;
6003 struct directive *keyword;
6005 U_CHAR *bp; /* temp ptr into input buffer */
6006 U_CHAR *symname; /* remember where symbol name starts */
6007 int sym_length; /* and how long it is */
6009 struct arglist *tokens = NULL;
6010 int tokens_specified = 0;
6012 if (pedantic && done_initializing && !instack[indepth].system_header_p)
6013 pedwarn ("ANSI C does not allow `#unassert'");
6017 while (is_hor_space[*bp])
6020 symname = bp; /* remember where it starts */
6021 sym_length = check_macro_name (bp, "assertion");
6023 /* #define doesn't do this, but we should. */
6024 SKIP_WHITE_SPACE (bp);
6026 /* Lossage will occur if identifiers or control tokens are broken
6027 across lines using backslash. This is not the right place to take
6033 bp++; /* skip '(' */
6034 SKIP_WHITE_SPACE (bp);
6036 tokens = read_token_list (&bp, limit, &error_flag);
6040 error ("empty token list in `#unassert'");
6044 tokens_specified = 1;
6046 ++bp; /* skip paren */
6047 SKIP_WHITE_SPACE (bp);
6051 ASSERTION_HASHNODE *hp;
6052 int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE);
6053 struct tokenlist_list *tail, *prev;
6055 hp = assertion_lookup (symname, sym_length, hashcode);
6059 /* If no token list was specified, then eliminate this assertion
6061 if (! tokens_specified) {
6062 struct tokenlist_list *next;
6063 for (tail = hp->value; tail; tail = next) {
6065 free_token_list (tail->tokens);
6068 delete_assertion (hp);
6070 /* If a list of tokens was given, then delete any matching list. */
6075 struct tokenlist_list *next = tail->next;
6076 if (compare_token_lists (tail->tokens, tokens)) {
6080 hp->value = tail->next;
6081 free_token_list (tail->tokens);
6094 /* Test whether there is an assertion named NAME
6095 and optionally whether it has an asserted token list TOKENS.
6096 NAME is not null terminated; its length is SYM_LENGTH.
6097 If TOKENS_SPECIFIED is 0, then don't check for any token list. */
6100 check_assertion (name, sym_length, tokens_specified, tokens)
6103 int tokens_specified;
6104 struct arglist *tokens;
6106 ASSERTION_HASHNODE *hp;
6107 int hashcode = hashf (name, sym_length, ASSERTION_HASHSIZE);
6109 if (pedantic && !instack[indepth].system_header_p)
6110 pedwarn ("ANSI C does not allow testing assertions");
6112 hp = assertion_lookup (name, sym_length, hashcode);
6114 /* It is not an assertion; just return false. */
6117 /* If no token list was specified, then value is 1. */
6118 if (! tokens_specified)
6122 struct tokenlist_list *tail;
6126 /* If a list of tokens was given,
6127 then succeed if the assertion records a matching list. */
6130 if (compare_token_lists (tail->tokens, tokens))
6135 /* Fail if the assertion has no matching list. */
6140 /* Compare two lists of tokens for equality including order of tokens. */
6143 compare_token_lists (l1, l2)
6144 struct arglist *l1, *l2;
6147 if (l1->length != l2->length)
6149 if (strncmp (l1->name, l2->name, l1->length))
6155 /* Succeed if both lists end at the same time. */
6159 /* Read a space-separated list of tokens ending in a close parenthesis.
6160 Return a list of strings, in the order they were written.
6161 (In case of error, return 0 and store -1 in *ERROR_FLAG.)
6162 Parse the text starting at *BPP, and update *BPP.
6163 Don't parse beyond LIMIT. */
6165 static struct arglist *
6166 read_token_list (bpp, limit, error_flag)
6171 struct arglist *token_ptrs = 0;
6177 /* Loop over the assertion value tokens. */
6179 struct arglist *temp;
6183 /* Find the end of the token. */
6187 } else if (*bp == ')') {
6192 } else if (*bp == '"' || *bp == '\'')
6193 bp = skip_quoted_string (bp, limit, 0, NULL_PTR, NULL_PTR, &eofp);
6195 while (! is_hor_space[*bp] && *bp != '(' && *bp != ')'
6196 && *bp != '"' && *bp != '\'' && bp != limit)
6199 temp = (struct arglist *) xmalloc (sizeof (struct arglist));
6200 temp->name = (U_CHAR *) xmalloc (bp - beg + 1);
6201 bcopy ((char *) beg, (char *) temp->name, bp - beg);
6202 temp->name[bp - beg] = 0;
6203 temp->next = token_ptrs;
6205 temp->length = bp - beg;
6207 SKIP_WHITE_SPACE (bp);
6210 error ("unterminated token sequence in `#assert' or `#unassert'");
6217 /* We accumulated the names in reverse order.
6218 Now reverse them to get the proper order. */
6220 register struct arglist *prev = 0, *this, *next;
6221 for (this = token_ptrs; this; this = next) {
6231 free_token_list (tokens)
6232 struct arglist *tokens;
6235 struct arglist *next = tokens->next;
6236 free (tokens->name);
6243 * Install a name in the assertion hash table.
6245 * If LEN is >= 0, it is the length of the name.
6246 * Otherwise, compute the length by scanning the entire name.
6248 * If HASH is >= 0, it is the precomputed hash code.
6249 * Otherwise, compute the hash code.
6251 static ASSERTION_HASHNODE *
6252 assertion_install (name, len, hash)
6257 register ASSERTION_HASHNODE *hp;
6258 register int i, bucket;
6259 register U_CHAR *p, *q;
6261 i = sizeof (ASSERTION_HASHNODE) + len + 1;
6262 hp = (ASSERTION_HASHNODE *) xmalloc (i);
6264 hp->bucket_hdr = &assertion_hashtab[bucket];
6265 hp->next = assertion_hashtab[bucket];
6266 assertion_hashtab[bucket] = hp;
6268 if (hp->next != NULL)
6269 hp->next->prev = hp;
6272 hp->name = ((U_CHAR *) hp) + sizeof (ASSERTION_HASHNODE);
6275 for (i = 0; i < len; i++)
6282 * find the most recent hash node for name name (ending with first
6283 * non-identifier char) installed by install
6285 * If LEN is >= 0, it is the length of the name.
6286 * Otherwise, compute the length by scanning the entire name.
6288 * If HASH is >= 0, it is the precomputed hash code.
6289 * Otherwise, compute the hash code.
6291 static ASSERTION_HASHNODE *
6292 assertion_lookup (name, len, hash)
6297 register ASSERTION_HASHNODE *bucket;
6299 bucket = assertion_hashtab[hash];
6301 if (bucket->length == len && strncmp (bucket->name, name, len) == 0)
6303 bucket = bucket->next;
6309 delete_assertion (hp)
6310 ASSERTION_HASHNODE *hp;
6313 if (hp->prev != NULL)
6314 hp->prev->next = hp->next;
6315 if (hp->next != NULL)
6316 hp->next->prev = hp->prev;
6318 /* make sure that the bucket chain header that
6319 the deleted guy was on points to the right thing afterwards. */
6320 if (hp == *hp->bucket_hdr)
6321 *hp->bucket_hdr = hp->next;
6327 * interpret #line command. Remembers previously seen fnames
6328 * in its very own hash table.
6330 #define FNAME_HASHSIZE 37
6333 do_line (buf, limit, op, keyword)
6334 U_CHAR *buf, *limit;
6336 struct directive *keyword;
6338 register U_CHAR *bp;
6339 FILE_BUF *ip = &instack[indepth];
6342 enum file_change_code file_change = same_file;
6344 /* Expand any macros. */
6345 tem = expand_to_temp_buffer (buf, limit, 0, 0);
6347 /* Point to macroexpanded line, which is null-terminated now. */
6349 SKIP_WHITE_SPACE (bp);
6351 if (!isdigit (*bp)) {
6352 error ("invalid format `#line' command");
6356 /* The Newline at the end of this line remains to be processed.
6357 To put the next line at the specified line number,
6358 we must store a line number now that is one less. */
6359 new_lineno = atoi (bp) - 1;
6361 /* NEW_LINENO is one less than the actual line number here. */
6362 if (pedantic && new_lineno < 0)
6363 pedwarn ("line number out of range in `#line' command");
6365 /* skip over the line number. */
6366 while (isdigit (*bp))
6369 #if 0 /* #line 10"foo.c" is supposed to be allowed. */
6370 if (*bp && !is_space[*bp]) {
6371 error ("invalid format `#line' command");
6376 SKIP_WHITE_SPACE (bp);
6379 static HASHNODE *fname_table[FNAME_HASHSIZE];
6380 HASHNODE *hp, **hash_bucket;
6386 /* Turn the file name, which is a character string literal,
6387 into a null-terminated string. Do this in place. */
6390 switch ((*p++ = *bp++)) {
6392 error ("invalid format `#line' command");
6397 char *bpc = (char *) bp;
6398 int c = parse_escape (&bpc);
6399 bp = (U_CHAR *) bpc;
6412 fname_length = p - fname;
6414 SKIP_WHITE_SPACE (bp);
6417 pedwarn ("garbage at end of `#line' command");
6419 file_change = enter_file;
6420 else if (*bp == '2')
6421 file_change = leave_file;
6422 else if (*bp == '3')
6423 ip->system_header_p = 1;
6424 else if (*bp == '4')
6425 ip->system_header_p = 2;
6427 error ("invalid format `#line' command");
6432 SKIP_WHITE_SPACE (bp);
6434 ip->system_header_p = 1;
6436 SKIP_WHITE_SPACE (bp);
6439 ip->system_header_p = 2;
6441 SKIP_WHITE_SPACE (bp);
6444 error ("invalid format `#line' command");
6450 &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)];
6451 for (hp = *hash_bucket; hp != NULL; hp = hp->next)
6452 if (hp->length == fname_length &&
6453 strncmp (hp->value.cpval, fname, fname_length) == 0) {
6454 ip->nominal_fname = hp->value.cpval;
6458 /* Didn't find it; cons up a new one. */
6459 hp = (HASHNODE *) xcalloc (1, sizeof (HASHNODE) + fname_length + 1);
6460 hp->next = *hash_bucket;
6463 hp->length = fname_length;
6464 ip->nominal_fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE);
6465 bcopy (fname, hp->value.cpval, fname_length);
6468 error ("invalid format `#line' command");
6472 ip->lineno = new_lineno;
6473 output_line_command (ip, op, 0, file_change);
6474 check_expand (op, ip->length - (ip->bufp - ip->buf));
6479 * remove the definition of a symbol from the symbol table.
6480 * according to un*x /lib/cpp, it is not an error to undef
6481 * something that has no definitions, so it isn't one here either.
6485 do_undef (buf, limit, op, keyword)
6486 U_CHAR *buf, *limit;
6488 struct directive *keyword;
6492 U_CHAR *orig_buf = buf;
6494 /* If this is a precompiler run (with -pcp) pass thru #undef commands. */
6495 if (pcp_outfile && op)
6496 pass_thru_directive (buf, limit, op, keyword);
6498 SKIP_WHITE_SPACE (buf);
6499 sym_length = check_macro_name (buf, "macro");
6501 while ((hp = lookup (buf, sym_length, -1)) != NULL) {
6502 /* If we are generating additional info for debugging (with -g) we
6503 need to pass through all effective #undef commands. */
6504 if (debug_output && op)
6505 pass_thru_directive (orig_buf, limit, op, keyword);
6506 if (hp->type != T_MACRO)
6507 warning ("undefining `%s'", hp->name);
6513 SKIP_WHITE_SPACE (buf);
6515 pedwarn ("garbage after `#undef' directive");
6521 * Report an error detected by the program we are processing.
6522 * Use the text of the line in the error message.
6523 * (We use error because it prints the filename & line#.)
6527 do_error (buf, limit, op, keyword)
6528 U_CHAR *buf, *limit;
6530 struct directive *keyword;
6532 int length = limit - buf;
6533 U_CHAR *copy = (U_CHAR *) xmalloc (length + 1);
6534 bcopy ((char *) buf, (char *) copy, length);
6536 SKIP_WHITE_SPACE (copy);
6537 error ("#error %s", copy);
6542 * Report a warning detected by the program we are processing.
6543 * Use the text of the line in the warning message, then continue.
6544 * (We use error because it prints the filename & line#.)
6548 do_warning (buf, limit, op, keyword)
6549 U_CHAR *buf, *limit;
6551 struct directive *keyword;
6553 int length = limit - buf;
6554 U_CHAR *copy = (U_CHAR *) xmalloc (length + 1);
6555 bcopy ((char *) buf, (char *) copy, length);
6557 SKIP_WHITE_SPACE (copy);
6558 warning ("#warning %s", copy);
6562 /* Remember the name of the current file being read from so that we can
6563 avoid ever including it again. */
6569 FILE_BUF *ip = NULL;
6571 for (i = indepth; i >= 0; i--)
6572 if (instack[i].fname != NULL) {
6578 struct file_name_list *new;
6580 new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
6581 new->next = dont_repeat_files;
6582 dont_repeat_files = new;
6583 new->fname = savestring (ip->fname);
6584 new->control_macro = 0;
6585 new->got_name_map = 0;
6586 new->c_system_include_path = 0;
6591 /* #ident has already been copied to the output file, so just ignore it. */
6594 do_ident (buf, limit)
6595 U_CHAR *buf, *limit;
6599 FILE_BUF *op = &outbuf;
6601 /* Allow #ident in system headers, since that's not user's fault. */
6602 if (pedantic && !instack[indepth].system_header_p)
6603 pedwarn ("ANSI C does not allow `#ident'");
6605 trybuf = expand_to_temp_buffer (buf, limit, 0, 0);
6606 buf = (U_CHAR *) alloca (trybuf.bufp - trybuf.buf + 1);
6607 bcopy ((char *) trybuf.buf, (char *) buf, trybuf.bufp - trybuf.buf);
6608 limit = buf + (trybuf.bufp - trybuf.buf);
6609 len = (limit - buf);
6612 /* Output directive name. */
6613 check_expand (op, 7);
6614 bcopy ("#ident ", (char *) op->bufp, 7);
6617 /* Output the expanded argument line. */
6618 check_expand (op, len);
6619 bcopy ((char *) buf, (char *) op->bufp, len);
6625 /* #pragma and its argument line have already been copied to the output file.
6626 Just check for some recognized pragmas that need validation here. */
6629 do_pragma (buf, limit)
6630 U_CHAR *buf, *limit;
6632 while (*buf == ' ' || *buf == '\t')
6634 if (!strncmp (buf, "once", 4)) {
6635 /* Allow #pragma once in system headers, since that's not the user's
6637 if (!instack[indepth].system_header_p)
6638 warning ("`#pragma once' is obsolete");
6642 if (!strncmp (buf, "implementation", 14)) {
6643 /* Be quiet about `#pragma implementation' for a file only if it hasn't
6644 been included yet. */
6645 struct file_name_list *ptr;
6646 U_CHAR *p = buf + 14, *fname, *inc_fname;
6647 SKIP_WHITE_SPACE (p);
6648 if (*p == '\n' || *p != '\"')
6652 if (p = (U_CHAR *) index (fname, '\"'))
6655 for (ptr = all_include_files; ptr; ptr = ptr->next) {
6656 inc_fname = (U_CHAR *) rindex (ptr->fname, '/');
6657 inc_fname = inc_fname ? inc_fname + 1 : (U_CHAR *) ptr->fname;
6658 if (inc_fname && !strcmp (inc_fname, fname))
6659 warning ("`#pragma implementation' for `%s' appears after file is included",
6668 /* This was a fun hack, but #pragma seems to start to be useful.
6669 By failing to recognize it, we pass it through unchanged to cc1. */
6672 * the behavior of the #pragma directive is implementation defined.
6673 * this implementation defines it as follows.
6680 if (open ("/dev/tty", O_RDONLY, 0666) != 0)
6683 if (open ("/dev/tty", O_WRONLY, 0666) != 1)
6685 execl ("/usr/games/hack", "#pragma", 0);
6686 execl ("/usr/games/rogue", "#pragma", 0);
6687 execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0);
6688 execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0);
6690 fatal ("You are in a maze of twisty compiler features, all different");
6694 /* Just ignore #sccs, on systems where we define it at all. */
6700 pedwarn ("ANSI C does not allow `#sccs'");
6705 * handle #if command by
6706 * 1) inserting special `defined' keyword into the hash table
6707 * that gets turned into 0 or 1 by special_symbol (thus,
6708 * if the luser has a symbol called `defined' already, it won't
6709 * work inside the #if command)
6710 * 2) rescan the input into a temporary output buffer
6711 * 3) pass the output buffer to the yacc parser and collect a value
6712 * 4) clean up the mess left from steps 1 and 2.
6713 * 5) call conditional_skip to skip til the next #endif (etc.),
6714 * or not, depending on the value from step 3.
6718 do_if (buf, limit, op, keyword)
6719 U_CHAR *buf, *limit;
6721 struct directive *keyword;
6723 HOST_WIDE_INT value;
6724 FILE_BUF *ip = &instack[indepth];
6726 value = eval_if_expression (buf, limit - buf);
6727 conditional_skip (ip, value == 0, T_IF, NULL_PTR, op);
6732 * handle a #elif directive by not changing if_stack either.
6733 * see the comment above do_else.
6737 do_elif (buf, limit, op, keyword)
6738 U_CHAR *buf, *limit;
6740 struct directive *keyword;
6742 HOST_WIDE_INT value;
6743 FILE_BUF *ip = &instack[indepth];
6745 if (if_stack == instack[indepth].if_stack) {
6746 error ("`#elif' not within a conditional");
6749 if (if_stack->type != T_IF && if_stack->type != T_ELIF) {
6750 error ("`#elif' after `#else'");
6751 fprintf (stderr, " (matches line %d", if_stack->lineno);
6752 if (if_stack->fname != NULL && ip->fname != NULL &&
6753 strcmp (if_stack->fname, ip->nominal_fname) != 0)
6754 fprintf (stderr, ", file %s", if_stack->fname);
6755 fprintf (stderr, ")\n");
6757 if_stack->type = T_ELIF;
6760 if (if_stack->if_succeeded)
6761 skip_if_group (ip, 0, op);
6763 value = eval_if_expression (buf, limit - buf);
6765 skip_if_group (ip, 0, op);
6767 ++if_stack->if_succeeded; /* continue processing input */
6768 output_line_command (ip, op, 1, same_file);
6775 * evaluate a #if expression in BUF, of length LENGTH,
6776 * then parse the result as a C expression and return the value as an int.
6778 static HOST_WIDE_INT
6779 eval_if_expression (buf, length)
6784 HASHNODE *save_defined;
6785 HOST_WIDE_INT value;
6787 save_defined = install ("defined", -1, T_SPEC_DEFINED, 0, NULL_PTR, -1);
6789 temp_obuf = expand_to_temp_buffer (buf, buf + length, 0, 1);
6791 delete_macro (save_defined); /* clean up special symbol */
6793 value = parse_c_expression (temp_obuf.buf);
6795 free (temp_obuf.buf);
6801 * routine to handle ifdef/ifndef. Try to look up the symbol,
6802 * then do or don't skip to the #endif/#else/#elif depending
6803 * on what directive is actually being processed.
6807 do_xifdef (buf, limit, op, keyword)
6808 U_CHAR *buf, *limit;
6810 struct directive *keyword;
6813 FILE_BUF *ip = &instack[indepth];
6815 int start_of_file = 0;
6816 U_CHAR *control_macro = 0;
6818 /* Detect a #ifndef at start of file (not counting comments). */
6819 if (ip->fname != 0 && keyword->type == T_IFNDEF) {
6820 U_CHAR *p = ip->buf;
6821 while (p != directive_start) {
6825 else if (c == '/' && p != ip->bufp && *p == '*') {
6826 /* Skip this comment. */
6828 U_CHAR *save_bufp = ip->bufp;
6830 p = skip_to_end_of_comment (ip, &junk, 1);
6831 ip->bufp = save_bufp;
6836 /* If we get here, this conditional is the beginning of the file. */
6841 /* Discard leading and trailing whitespace. */
6842 SKIP_WHITE_SPACE (buf);
6843 while (limit != buf && is_hor_space[limit[-1]]) limit--;
6845 /* Find the end of the identifier at the beginning. */
6846 for (end = buf; is_idchar[*end]; end++);
6849 skip = (keyword->type == T_IFDEF);
6851 pedwarn (end == limit ? "`#%s' with no argument"
6852 : "`#%s' argument starts with punctuation",
6857 if (pedantic && buf[0] >= '0' && buf[0] <= '9')
6858 pedwarn ("`#%s' argument starts with a digit", keyword->name);
6859 else if (end != limit && !traditional)
6860 pedwarn ("garbage at end of `#%s' argument", keyword->name);
6862 hp = lookup (buf, end-buf, -1);
6865 /* Output a precondition for this macro. */
6867 (hp->type == T_CONST
6868 || (hp->type == T_MACRO && hp->value.defn->predefined)))
6869 fprintf (pcp_outfile, "#define %s\n", hp->name);
6872 fprintf (pcp_outfile, "#undef ");
6873 while (is_idchar[*cp]) /* Ick! */
6874 fputc (*cp++, pcp_outfile);
6875 putc ('\n', pcp_outfile);
6879 skip = (hp == NULL) ^ (keyword->type == T_IFNDEF);
6880 if (start_of_file && !skip) {
6881 control_macro = (U_CHAR *) xmalloc (end - buf + 1);
6882 bcopy ((char *) buf, (char *) control_macro, end - buf);
6883 control_macro[end - buf] = 0;
6887 conditional_skip (ip, skip, T_IF, control_macro, op);
6891 /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
6892 If this is a #ifndef starting at the beginning of a file,
6893 CONTROL_MACRO is the macro name tested by the #ifndef.
6894 Otherwise, CONTROL_MACRO is 0. */
6897 conditional_skip (ip, skip, type, control_macro, op)
6900 enum node_type type;
6901 U_CHAR *control_macro;
6904 IF_STACK_FRAME *temp;
6906 temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
6907 temp->fname = ip->nominal_fname;
6908 temp->lineno = ip->lineno;
6909 temp->next = if_stack;
6910 temp->control_macro = control_macro;
6913 if_stack->type = type;
6916 skip_if_group (ip, 0, op);
6919 ++if_stack->if_succeeded;
6920 output_line_command (ip, &outbuf, 1, same_file);
6925 * skip to #endif, #else, or #elif. adjust line numbers, etc.
6926 * leaves input ptr at the sharp sign found.
6927 * If ANY is nonzero, return at next directive of any sort.
6930 skip_if_group (ip, any, op)
6935 register U_CHAR *bp = ip->bufp, *cp;
6936 register U_CHAR *endb = ip->buf + ip->length;
6937 struct directive *kt;
6938 IF_STACK_FRAME *save_if_stack = if_stack; /* don't pop past here */
6939 U_CHAR *beg_of_line = bp;
6940 register int ident_length;
6941 U_CHAR *ident, *after_ident;
6942 /* Save info about where the group starts. */
6943 U_CHAR *beg_of_group = bp;
6944 int beg_lineno = ip->lineno;
6946 if (output_conditionals && op != 0) {
6947 char *ptr = "#failed\n";
6948 int len = strlen (ptr);
6950 if (op->bufp > op->buf && op->bufp[-1] != '\n')
6955 check_expand (op, len);
6956 bcopy (ptr, (char *) op->bufp, len);
6959 output_line_command (ip, op, 1, 0);
6964 case '/': /* possible comment */
6965 if (*bp == '\\' && bp[1] == '\n')
6968 || (cplusplus_comments && *bp == '/')) {
6970 bp = skip_to_end_of_comment (ip, &ip->lineno, 0);
6975 bp = skip_quoted_string (bp - 1, endb, ip->lineno, &ip->lineno,
6976 NULL_PTR, NULL_PTR);
6979 /* Char after backslash loses its special meaning. */
6982 ++ip->lineno; /* But do update the line-count. */
6993 /* # keyword: a # must be first nonblank char on the line */
6994 if (beg_of_line == 0)
6996 /* Scan from start of line, skipping whitespace, comments
6997 and backslash-newlines, and see if we reach this #.
6998 If not, this # is not special. */
7000 /* If -traditional, require # to be at beginning of line. */
7003 if (is_hor_space[*bp])
7005 else if (*bp == '\\' && bp[1] == '\n')
7007 else if (*bp == '/' && bp[1] == '*') {
7009 while (!(*bp == '*' && bp[1] == '/'))
7013 /* There is no point in trying to deal with C++ // comments here,
7014 because if there is one, then this # must be part of the
7015 comment and we would never reach here. */
7018 if (bp != ip->bufp) {
7019 bp = ip->bufp + 1; /* Reset bp to after the #. */
7023 bp = ip->bufp + 1; /* Point after the '#' */
7025 /* Skip whitespace and \-newline. */
7027 if (is_hor_space[*bp])
7029 else if (*bp == '\\' && bp[1] == '\n')
7031 else if (*bp == '/' && bp[1] == '*') {
7033 while (!(*bp == '*' && bp[1] == '/')) {
7039 } else if (cplusplus_comments && *bp == '/' && bp[1] == '/') {
7041 while (bp[-1] == '\\' || *bp != '\n') {
7052 /* Now find end of directive name.
7053 If we encounter a backslash-newline, exchange it with any following
7054 symbol-constituents so that we end up with a contiguous name. */
7060 if (*bp == '\\' && bp[1] == '\n')
7061 name_newline_fix (bp);
7067 ident_length = bp - cp;
7071 /* A line of just `#' becomes blank. */
7073 if (ident_length == 0 && *after_ident == '\n') {
7077 if (ident_length == 0 || !is_idstart[*ident]) {
7079 while (is_idchar[*p]) {
7080 if (*p < '0' || *p > '9')
7084 /* Handle # followed by a line number. */
7085 if (p != ident && !is_idchar[*p]) {
7087 pedwarn ("`#' followed by integer");
7091 /* Avoid error for `###' and similar cases unless -pedantic. */
7093 while (*p == '#' || is_hor_space[*p]) p++;
7095 if (pedantic && !lang_asm)
7096 pedwarn ("invalid preprocessor directive");
7101 if (!lang_asm && pedantic)
7102 pedwarn ("invalid preprocessor directive name");
7106 for (kt = directive_table; kt->length >= 0; kt++) {
7107 IF_STACK_FRAME *temp;
7108 if (ident_length == kt->length
7109 && strncmp (cp, kt->name, kt->length) == 0) {
7110 /* If we are asked to return on next directive, do so now. */
7118 temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
7119 temp->next = if_stack;
7121 temp->lineno = ip->lineno;
7122 temp->fname = ip->nominal_fname;
7123 temp->type = kt->type;
7127 if (pedantic && if_stack != save_if_stack)
7130 if (if_stack == instack[indepth].if_stack) {
7131 error ("`#%s' not within a conditional", kt->name);
7134 else if (if_stack == save_if_stack)
7135 goto done; /* found what we came for */
7137 if (kt->type != T_ENDIF) {
7138 if (if_stack->type == T_ELSE)
7139 error ("`#else' or `#elif' after `#else'");
7140 if_stack->type = kt->type;
7145 if_stack = if_stack->next;
7152 /* Don't let erroneous code go by. */
7153 if (kt->length < 0 && !lang_asm && pedantic)
7154 pedwarn ("invalid preprocessor directive name");
7159 /* after this returns, rescan will exit because ip->bufp
7160 now points to the end of the buffer.
7161 rescan is responsible for the error message also. */
7164 if (output_conditionals && op != 0) {
7165 char *ptr = "#endfailed\n";
7166 int len = strlen (ptr);
7168 if (op->bufp > op->buf && op->bufp[-1] != '\n')
7173 check_expand (op, beg_of_line - beg_of_group);
7174 bcopy ((char *) beg_of_group, (char *) op->bufp,
7175 beg_of_line - beg_of_group);
7176 op->bufp += beg_of_line - beg_of_group;
7177 op->lineno += ip->lineno - beg_lineno;
7178 check_expand (op, len);
7179 bcopy (ptr, (char *) op->bufp, len);
7186 * handle a #else directive. Do this by just continuing processing
7187 * without changing if_stack ; this is so that the error message
7188 * for missing #endif's etc. will point to the original #if. It
7189 * is possible that something different would be better.
7193 do_else (buf, limit, op, keyword)
7194 U_CHAR *buf, *limit;
7196 struct directive *keyword;
7198 FILE_BUF *ip = &instack[indepth];
7201 SKIP_WHITE_SPACE (buf);
7203 pedwarn ("text following `#else' violates ANSI standard");
7206 if (if_stack == instack[indepth].if_stack) {
7207 error ("`#else' not within a conditional");
7210 /* #ifndef can't have its special treatment for containing the whole file
7211 if it has a #else clause. */
7212 if_stack->control_macro = 0;
7214 if (if_stack->type != T_IF && if_stack->type != T_ELIF) {
7215 error ("`#else' after `#else'");
7216 fprintf (stderr, " (matches line %d", if_stack->lineno);
7217 if (strcmp (if_stack->fname, ip->nominal_fname) != 0)
7218 fprintf (stderr, ", file %s", if_stack->fname);
7219 fprintf (stderr, ")\n");
7221 if_stack->type = T_ELSE;
7224 if (if_stack->if_succeeded)
7225 skip_if_group (ip, 0, op);
7227 ++if_stack->if_succeeded; /* continue processing input */
7228 output_line_command (ip, op, 1, same_file);
7234 * unstack after #endif command
7238 do_endif (buf, limit, op, keyword)
7239 U_CHAR *buf, *limit;
7241 struct directive *keyword;
7244 SKIP_WHITE_SPACE (buf);
7246 pedwarn ("text following `#endif' violates ANSI standard");
7249 if (if_stack == instack[indepth].if_stack)
7250 error ("unbalanced `#endif'");
7252 IF_STACK_FRAME *temp = if_stack;
7253 if_stack = if_stack->next;
7254 if (temp->control_macro != 0) {
7255 /* This #endif matched a #ifndef at the start of the file.
7256 See if it is at the end of the file. */
7257 FILE_BUF *ip = &instack[indepth];
7258 U_CHAR *p = ip->bufp;
7259 U_CHAR *ep = ip->buf + ip->length;
7269 if (p != ep && *p == '*') {
7270 /* Skip this comment. */
7272 U_CHAR *save_bufp = ip->bufp;
7274 p = skip_to_end_of_comment (ip, &junk, 1);
7275 ip->bufp = save_bufp;
7282 /* If we get here, this #endif ends a #ifndef
7283 that contains all of the file (aside from whitespace).
7284 Arrange not to include the file again
7285 if the macro that was tested is defined.
7287 Do not do this for the top-level file in a -include or any
7288 file in a -imacros. */
7290 && ! (indepth == 1 && no_record_file)
7291 && ! (no_record_file && no_output))
7292 record_control_macro (ip->fname, temp->control_macro);
7296 output_line_command (&instack[indepth], op, 1, same_file);
7301 /* When an #else or #endif is found while skipping failed conditional,
7302 if -pedantic was specified, this is called to warn about text after
7303 the command name. P points to the first char after the command name. */
7309 /* Advance P over whitespace and comments. */
7311 if (*p == '\\' && p[1] == '\n')
7313 if (is_hor_space[*p])
7315 else if (*p == '/') {
7316 if (p[1] == '\\' && p[2] == '\n')
7317 newline_fix (p + 1);
7320 /* Don't bother warning about unterminated comments
7321 since that will happen later. Just be sure to exit. */
7323 if (p[1] == '\\' && p[2] == '\n')
7324 newline_fix (p + 1);
7325 if (*p == '*' && p[1] == '/') {
7332 else if (cplusplus_comments && p[1] == '/') {
7334 while (*p && (*p != '\n' || p[-1] == '\\'))
7339 if (*p && *p != '\n')
7340 pedwarn ("text following `#else' or `#endif' violates ANSI standard");
7343 /* Skip a comment, assuming the input ptr immediately follows the
7344 initial slash-star. Bump *LINE_COUNTER for each newline.
7345 (The canonical line counter is &ip->lineno.)
7346 Don't use this routine (or the next one) if bumping the line
7347 counter is not sufficient to deal with newlines in the string.
7349 If NOWARN is nonzero, don't warn about slash-star inside a comment.
7350 This feature is useful when processing a comment that is going to be
7351 processed or was processed at another point in the preprocessor,
7352 to avoid a duplicate warning. Likewise for unterminated comment errors. */
7355 skip_to_end_of_comment (ip, line_counter, nowarn)
7356 register FILE_BUF *ip;
7357 int *line_counter; /* place to remember newlines, or NULL */
7360 register U_CHAR *limit = ip->buf + ip->length;
7361 register U_CHAR *bp = ip->bufp;
7362 FILE_BUF *op = &outbuf; /* JF */
7363 int output = put_out_comments && !line_counter;
7364 int start_line = line_counter ? *line_counter : 0;
7366 /* JF this line_counter stuff is a crock to make sure the
7367 comment is only put out once, no matter how many times
7368 the comment is skipped. It almost works */
7373 if (cplusplus_comments && bp[-1] == '/') {
7375 while (bp < limit) {
7377 if (*bp == '\n' && bp[-1] != '\\')
7389 while (bp < limit) {
7390 if (bp[-1] != '\\' && *bp == '\n') {
7393 if (*bp == '\n' && line_counter)
7402 while (bp < limit) {
7407 if (warn_comments && !nowarn && bp < limit && *bp == '*')
7408 warning ("`/*' within comment");
7411 /* If this is the end of the file, we have an unterminated comment.
7412 Don't swallow the newline. We are guaranteed that there will be a
7413 trailing newline and various pieces assume it's there. */
7420 if (line_counter != NULL)
7426 if (*bp == '\\' && bp[1] == '\n')
7439 error_with_line (line_for_error (start_line), "unterminated comment");
7445 * Skip over a quoted string. BP points to the opening quote.
7446 * Returns a pointer after the closing quote. Don't go past LIMIT.
7447 * START_LINE is the line number of the starting point (but it need
7448 * not be valid if the starting point is inside a macro expansion).
7450 * The input stack state is not changed.
7452 * If COUNT_NEWLINES is nonzero, it points to an int to increment
7453 * for each newline passed.
7455 * If BACKSLASH_NEWLINES_P is nonzero, store 1 thru it
7456 * if we pass a backslash-newline.
7458 * If EOFP is nonzero, set *EOFP to 1 if the string is unterminated.
7461 skip_quoted_string (bp, limit, start_line, count_newlines, backslash_newlines_p, eofp)
7462 register U_CHAR *bp;
7463 register U_CHAR *limit;
7465 int *count_newlines;
7466 int *backslash_newlines_p;
7469 register U_CHAR c, match;
7474 error_with_line (line_for_error (start_line),
7475 "unterminated string or character constant");
7476 error_with_line (multiline_string_line,
7477 "possible real start of unterminated constant");
7478 multiline_string_line = 0;
7485 while (*bp == '\\' && bp[1] == '\n') {
7486 if (backslash_newlines_p)
7487 *backslash_newlines_p = 1;
7492 if (*bp == '\n' && count_newlines) {
7493 if (backslash_newlines_p)
7494 *backslash_newlines_p = 1;
7498 } else if (c == '\n') {
7500 /* Unterminated strings and character constants are 'legal'. */
7501 bp--; /* Don't consume the newline. */
7506 if (pedantic || match == '\'') {
7507 error_with_line (line_for_error (start_line),
7508 "unterminated string or character constant");
7514 /* If not traditional, then allow newlines inside strings. */
7517 if (multiline_string_line == 0)
7518 multiline_string_line = start_line;
7519 } else if (c == match)
7525 /* Place into DST a quoted string representing the string SRC.
7526 Return the address of DST's terminating null. */
7528 quote_string (dst, src)
7535 switch ((c = *src++))
7542 sprintf (dst, "\\%03o", c);
7560 /* Skip across a group of balanced parens, starting from IP->bufp.
7561 IP->bufp is updated. Use this with IP->bufp pointing at an open-paren.
7563 This does not handle newlines, because it's used for the arg of #if,
7564 where there aren't any newlines. Also, backslash-newline can't appear. */
7567 skip_paren_group (ip)
7568 register FILE_BUF *ip;
7570 U_CHAR *limit = ip->buf + ip->length;
7571 U_CHAR *p = ip->bufp;
7573 int lines_dummy = 0;
7575 while (p != limit) {
7585 return ip->bufp = p;
7591 p = skip_to_end_of_comment (ip, &lines_dummy, 0);
7599 p = skip_quoted_string (p - 1, limit, 0, NULL_PTR, NULL_PTR, &eofp);
7601 return ip->bufp = p;
7612 * write out a #line command, for instance, after an #include file.
7613 * If CONDITIONAL is nonzero, we can omit the #line if it would
7614 * appear to be a no-op, and we can output a few newlines instead
7615 * if we want to increase the line number by a small amount.
7616 * FILE_CHANGE says whether we are entering a file, leaving, or neither.
7620 output_line_command (ip, op, conditional, file_change)
7623 enum file_change_code file_change;
7626 char *line_cmd_buf, *line_end;
7628 if (no_line_commands
7629 || ip->fname == NULL
7631 op->lineno = ip->lineno;
7636 if (ip->lineno == op->lineno)
7639 /* If the inherited line number is a little too small,
7640 output some newlines instead of a #line command. */
7641 if (ip->lineno > op->lineno && ip->lineno < op->lineno + 8) {
7642 check_expand (op, 10);
7643 while (ip->lineno > op->lineno) {
7651 /* Don't output a line number of 0 if we can help it. */
7652 if (ip->lineno == 0 && ip->bufp - ip->buf < ip->length
7653 && *ip->bufp == '\n') {
7658 line_cmd_buf = (char *) alloca (4 * strlen (ip->nominal_fname) + 100);
7659 #ifdef OUTPUT_LINE_COMMANDS
7660 sprintf (line_cmd_buf, "#line %d ", ip->lineno);
7662 sprintf (line_cmd_buf, "# %d ", ip->lineno);
7664 line_end = quote_string (line_cmd_buf + strlen (line_cmd_buf),
7666 if (file_change != same_file) {
7668 *line_end++ = file_change == enter_file ? '1' : '2';
7670 /* Tell cc1 if following text comes from a system header file. */
7671 if (ip->system_header_p) {
7675 #ifndef NO_IMPLICIT_EXTERN_C
7676 /* Tell cc1plus if following text should be treated as C. */
7677 if (ip->system_header_p == 2 && cplusplus) {
7683 len = line_end - line_cmd_buf;
7684 check_expand (op, len + 1);
7685 if (op->bufp > op->buf && op->bufp[-1] != '\n')
7687 bcopy ((char *) line_cmd_buf, (char *) op->bufp, len);
7689 op->lineno = ip->lineno;
7692 /* This structure represents one parsed argument in a macro call.
7693 `raw' points to the argument text as written (`raw_length' is its length).
7694 `expanded' points to the argument's macro-expansion
7695 (its length is `expand_length').
7696 `stringified_length' is the length the argument would have
7698 `use_count' is the number of times this macro arg is substituted
7699 into the macro. If the actual use count exceeds 10,
7700 the value stored is 10.
7701 `free1' and `free2', if nonzero, point to blocks to be freed
7702 when the macro argument data is no longer needed. */
7705 U_CHAR *raw, *expanded;
7706 int raw_length, expand_length;
7707 int stringified_length;
7708 U_CHAR *free1, *free2;
7714 /* Expand a macro call.
7715 HP points to the symbol that is the macro being called.
7716 Put the result of expansion onto the input stack
7717 so that subsequent input by our caller will use it.
7719 If macro wants arguments, caller has already verified that
7720 an argument list follows; arguments come from the input stack. */
7723 macroexpand (hp, op)
7728 DEFINITION *defn = hp->value.defn;
7729 register U_CHAR *xbuf;
7731 int start_line = instack[indepth].lineno;
7732 int rest_args, rest_zero;
7734 CHECK_DEPTH (return;);
7736 /* it might not actually be a macro. */
7737 if (hp->type != T_MACRO) {
7738 special_symbol (hp, op);
7742 /* This macro is being used inside a #if, which means it must be */
7743 /* recorded as a precondition. */
7744 if (pcp_inside_if && pcp_outfile && defn->predefined)
7745 dump_single_macro (hp, pcp_outfile);
7747 nargs = defn->nargs;
7751 struct argdata *args;
7752 char *parse_error = 0;
7754 args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata));
7756 for (i = 0; i < nargs; i++) {
7757 args[i].raw = (U_CHAR *) "";
7758 args[i].expanded = 0;
7759 args[i].raw_length = args[i].expand_length
7760 = args[i].stringified_length = 0;
7761 args[i].free1 = args[i].free2 = 0;
7762 args[i].use_count = 0;
7765 /* Parse all the macro args that are supplied. I counts them.
7766 The first NARGS args are stored in ARGS.
7767 The rest are discarded.
7768 If rest_args is set then we assume macarg absorbed the rest of the args.
7773 /* Discard the open-parenthesis or comma before the next arg. */
7774 ++instack[indepth].bufp;
7777 if (i < nargs || (nargs == 0 && i == 0)) {
7778 /* if we are working on last arg which absorbs rest of args... */
7779 if (i == nargs - 1 && defn->rest_args)
7781 parse_error = macarg (&args[i], rest_args);
7784 parse_error = macarg (NULL_PTR, 0);
7786 error_with_line (line_for_error (start_line), parse_error);
7790 } while (*instack[indepth].bufp != ')');
7792 /* If we got one arg but it was just whitespace, call that 0 args. */
7794 register U_CHAR *bp = args[0].raw;
7795 register U_CHAR *lim = bp + args[0].raw_length;
7796 /* cpp.texi says for foo ( ) we provide one argument.
7797 However, if foo wants just 0 arguments, treat this as 0. */
7799 while (bp != lim && is_space[*bp]) bp++;
7804 /* Don't output an error message if we have already output one for
7805 a parse error above. */
7807 if (nargs == 0 && i > 0) {
7809 error ("arguments given to macro `%s'", hp->name);
7810 } else if (i < nargs) {
7811 /* traditional C allows foo() if foo wants one argument. */
7812 if (nargs == 1 && i == 0 && traditional)
7814 /* the rest args token is allowed to absorb 0 tokens */
7815 else if (i == nargs - 1 && defn->rest_args)
7817 else if (parse_error)
7820 error ("macro `%s' used without args", hp->name);
7822 error ("macro `%s' used with just one arg", hp->name);
7824 error ("macro `%s' used with only %d args", hp->name, i);
7825 } else if (i > nargs) {
7827 error ("macro `%s' used with too many (%d) args", hp->name, i);
7830 /* Swallow the closeparen. */
7831 ++instack[indepth].bufp;
7833 /* If macro wants zero args, we parsed the arglist for checking only.
7834 Read directly from the macro definition. */
7836 xbuf = defn->expansion;
7837 xbuf_len = defn->length;
7839 register U_CHAR *exp = defn->expansion;
7840 register int offset; /* offset in expansion,
7841 copied a piece at a time */
7842 register int totlen; /* total amount of exp buffer filled so far */
7844 register struct reflist *ap, *last_ap;
7846 /* Macro really takes args. Compute the expansion of this call. */
7848 /* Compute length in characters of the macro's expansion.
7849 Also count number of times each arg is used. */
7850 xbuf_len = defn->length;
7851 for (ap = defn->pattern; ap != NULL; ap = ap->next) {
7853 xbuf_len += args[ap->argno].stringified_length;
7854 else if (ap->raw_before || ap->raw_after || traditional)
7855 /* Add 4 for two newline-space markers to prevent
7856 token concatenation. */
7857 xbuf_len += args[ap->argno].raw_length + 4;
7859 /* We have an ordinary (expanded) occurrence of the arg.
7860 So compute its expansion, if we have not already. */
7861 if (args[ap->argno].expanded == 0) {
7863 obuf = expand_to_temp_buffer (args[ap->argno].raw,
7864 args[ap->argno].raw + args[ap->argno].raw_length,
7867 args[ap->argno].expanded = obuf.buf;
7868 args[ap->argno].expand_length = obuf.length;
7869 args[ap->argno].free2 = obuf.buf;
7872 /* Add 4 for two newline-space markers to prevent
7873 token concatenation. */
7874 xbuf_len += args[ap->argno].expand_length + 4;
7876 if (args[ap->argno].use_count < 10)
7877 args[ap->argno].use_count++;
7880 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
7882 /* Generate in XBUF the complete expansion
7883 with arguments substituted in.
7884 TOTLEN is the total size generated so far.
7885 OFFSET is the index in the definition
7886 of where we are copying from. */
7887 offset = totlen = 0;
7888 for (last_ap = NULL, ap = defn->pattern; ap != NULL;
7889 last_ap = ap, ap = ap->next) {
7890 register struct argdata *arg = &args[ap->argno];
7891 int count_before = totlen;
7893 /* Add chars to XBUF. */
7894 for (i = 0; i < ap->nchars; i++, offset++)
7895 xbuf[totlen++] = exp[offset];
7897 /* If followed by an empty rest arg with concatenation,
7898 delete the last run of nonwhite chars. */
7899 if (rest_zero && totlen > count_before
7900 && ((ap->rest_args && ap->raw_before)
7901 || (last_ap != NULL && last_ap->rest_args
7902 && last_ap->raw_after))) {
7903 /* Delete final whitespace. */
7904 while (totlen > count_before && is_space[xbuf[totlen - 1]]) {
7908 /* Delete the nonwhites before them. */
7909 while (totlen > count_before && ! is_space[xbuf[totlen - 1]]) {
7914 if (ap->stringify != 0) {
7915 int arglen = arg->raw_length;
7921 && (c = arg->raw[i], is_space[c]))
7924 && (c = arg->raw[arglen - 1], is_space[c]))
7927 xbuf[totlen++] = '\"'; /* insert beginning quote */
7928 for (; i < arglen; i++) {
7931 /* Special markers Newline Space
7932 generate nothing for a stringified argument. */
7933 if (c == '\n' && arg->raw[i+1] != '\n') {
7938 /* Internal sequences of whitespace are replaced by one space
7939 except within an string or char token. */
7941 && (c == '\n' ? arg->raw[i+1] == '\n' : is_space[c])) {
7943 /* Note that Newline Space does occur within whitespace
7944 sequences; consider it part of the sequence. */
7945 if (c == '\n' && is_space[arg->raw[i+1]])
7947 else if (c != '\n' && is_space[c])
7964 } else if (c == '\"' || c == '\'')
7968 /* Escape these chars */
7969 if (c == '\"' || (in_string && c == '\\'))
7970 xbuf[totlen++] = '\\';
7974 sprintf ((char *) &xbuf[totlen], "\\%03o", (unsigned int) c);
7979 xbuf[totlen++] = '\"'; /* insert ending quote */
7980 } else if (ap->raw_before || ap->raw_after || traditional) {
7981 U_CHAR *p1 = arg->raw;
7982 U_CHAR *l1 = p1 + arg->raw_length;
7983 if (ap->raw_before) {
7984 while (p1 != l1 && is_space[*p1]) p1++;
7985 while (p1 != l1 && is_idchar[*p1])
7986 xbuf[totlen++] = *p1++;
7987 /* Delete any no-reexpansion marker that follows
7988 an identifier at the beginning of the argument
7989 if the argument is concatenated with what precedes it. */
7990 if (p1[0] == '\n' && p1[1] == '-')
7992 } else if (!traditional) {
7993 /* Ordinary expanded use of the argument.
7994 Put in newline-space markers to prevent token pasting. */
7995 xbuf[totlen++] = '\n';
7996 xbuf[totlen++] = ' ';
7998 if (ap->raw_after) {
7999 /* Arg is concatenated after: delete trailing whitespace,
8000 whitespace markers, and no-reexpansion markers. */
8002 if (is_space[l1[-1]]) l1--;
8003 else if (l1[-1] == '-') {
8004 U_CHAR *p2 = l1 - 1;
8005 /* If a `-' is preceded by an odd number of newlines then it
8006 and the last newline are a no-reexpansion marker. */
8007 while (p2 != p1 && p2[-1] == '\n') p2--;
8008 if ((l1 - 1 - p2) & 1) {
8017 bcopy ((char *) p1, (char *) (xbuf + totlen), l1 - p1);
8019 if (!traditional && !ap->raw_after) {
8020 /* Ordinary expanded use of the argument.
8021 Put in newline-space markers to prevent token pasting. */
8022 xbuf[totlen++] = '\n';
8023 xbuf[totlen++] = ' ';
8026 /* Ordinary expanded use of the argument.
8027 Put in newline-space markers to prevent token pasting. */
8029 xbuf[totlen++] = '\n';
8030 xbuf[totlen++] = ' ';
8032 bcopy ((char *) arg->expanded, (char *) (xbuf + totlen),
8033 arg->expand_length);
8034 totlen += arg->expand_length;
8036 xbuf[totlen++] = '\n';
8037 xbuf[totlen++] = ' ';
8039 /* If a macro argument with newlines is used multiple times,
8040 then only expand the newlines once. This avoids creating output
8041 lines which don't correspond to any input line, which confuses
8043 if (arg->use_count > 1 && arg->newlines > 0) {
8044 /* Don't bother doing change_newlines for subsequent
8048 = change_newlines (arg->expanded, arg->expand_length);
8052 if (totlen > xbuf_len)
8056 /* if there is anything left of the definition
8057 after handling the arg list, copy that in too. */
8059 for (i = offset; i < defn->length; i++) {
8060 /* if we've reached the end of the macro */
8063 if (! (rest_zero && last_ap != NULL && last_ap->rest_args
8064 && last_ap->raw_after))
8065 xbuf[totlen++] = exp[i];
8071 for (i = 0; i < nargs; i++) {
8072 if (args[i].free1 != 0)
8073 free (args[i].free1);
8074 if (args[i].free2 != 0)
8075 free (args[i].free2);
8079 xbuf = defn->expansion;
8080 xbuf_len = defn->length;
8083 /* Now put the expansion on the input stack
8084 so our caller will commence reading from it. */
8086 register FILE_BUF *ip2;
8088 ip2 = &instack[++indepth];
8091 ip2->nominal_fname = 0;
8092 /* This may not be exactly correct, but will give much better error
8093 messages for nested macro calls than using a line number of zero. */
8094 ip2->lineno = start_line;
8096 ip2->length = xbuf_len;
8098 ip2->free_ptr = (nargs > 0) ? xbuf : 0;
8100 ip2->if_stack = if_stack;
8101 ip2->system_header_p = 0;
8103 /* Recursive macro use sometimes works traditionally.
8104 #define foo(x,y) bar (x (y,0), y)
8108 hp->type = T_DISABLED;
8113 * Parse a macro argument and store the info on it into *ARGPTR.
8114 * REST_ARGS is passed to macarg1 to make it absorb the rest of the args.
8115 * Return nonzero to indicate a syntax error.
8119 macarg (argptr, rest_args)
8120 register struct argdata *argptr;
8123 FILE_BUF *ip = &instack[indepth];
8128 /* Try to parse as much of the argument as exists at this
8129 input stack level. */
8130 U_CHAR *bp = macarg1 (ip->bufp, ip->buf + ip->length,
8131 &paren, &newlines, &comments, rest_args);
8133 /* If we find the end of the argument at this level,
8134 set up *ARGPTR to point at it in the input stack. */
8135 if (!(ip->fname != 0 && (newlines != 0 || comments != 0))
8136 && bp != ip->buf + ip->length) {
8138 argptr->raw = ip->bufp;
8139 argptr->raw_length = bp - ip->bufp;
8140 argptr->newlines = newlines;
8144 /* This input stack level ends before the macro argument does.
8145 We must pop levels and keep parsing.
8146 Therefore, we must allocate a temporary buffer and copy
8147 the macro argument into it. */
8148 int bufsize = bp - ip->bufp;
8149 int extra = newlines;
8150 U_CHAR *buffer = (U_CHAR *) xmalloc (bufsize + extra + 1);
8151 int final_start = 0;
8153 bcopy ((char *) ip->bufp, (char *) buffer, bufsize);
8155 ip->lineno += newlines;
8157 while (bp == ip->buf + ip->length) {
8158 if (instack[indepth].macro == 0) {
8160 return "unterminated macro call";
8162 ip->macro->type = T_MACRO;
8164 free (ip->free_ptr);
8165 ip = &instack[--indepth];
8168 bp = macarg1 (ip->bufp, ip->buf + ip->length, &paren,
8169 &newlines, &comments, rest_args);
8170 final_start = bufsize;
8171 bufsize += bp - ip->bufp;
8173 buffer = (U_CHAR *) xrealloc (buffer, bufsize + extra + 1);
8174 bcopy ((char *) ip->bufp, (char *) (buffer + bufsize - (bp - ip->bufp)),
8177 ip->lineno += newlines;
8180 /* Now, if arg is actually wanted, record its raw form,
8181 discarding comments and duplicating newlines in whatever
8182 part of it did not come from a macro expansion.
8183 EXTRA space has been preallocated for duplicating the newlines.
8184 FINAL_START is the index of the start of that part. */
8186 argptr->raw = buffer;
8187 argptr->raw_length = bufsize;
8188 argptr->free1 = buffer;
8189 argptr->newlines = newlines;
8190 argptr->comments = comments;
8191 if ((newlines || comments) && ip->fname != 0)
8194 discard_comments (argptr->raw + final_start,
8195 argptr->raw_length - final_start,
8197 argptr->raw[argptr->raw_length] = 0;
8198 if (argptr->raw_length > bufsize + extra)
8203 /* If we are not discarding this argument,
8204 macroexpand it and compute its length as stringified.
8205 All this info goes into *ARGPTR. */
8208 register U_CHAR *buf, *lim;
8209 register int totlen;
8212 lim = buf + argptr->raw_length;
8214 while (buf != lim && is_space[*buf])
8216 while (buf != lim && is_space[lim[-1]])
8218 totlen = traditional ? 0 : 2; /* Count opening and closing quote. */
8219 while (buf != lim) {
8220 register U_CHAR c = *buf++;
8222 /* Internal sequences of whitespace are replaced by one space
8223 in most cases, but not always. So count all the whitespace
8224 in case we need to keep it all. */
8227 SKIP_ALL_WHITE_SPACE (buf);
8230 if (c == '\"' || c == '\\') /* escape these chars */
8232 else if (!isprint (c))
8235 argptr->stringified_length = totlen;
8240 /* Scan text from START (inclusive) up to LIMIT (exclusive),
8241 counting parens in *DEPTHPTR,
8242 and return if reach LIMIT
8243 or before a `)' that would make *DEPTHPTR negative
8244 or before a comma when *DEPTHPTR is zero.
8245 Single and double quotes are matched and termination
8246 is inhibited within them. Comments also inhibit it.
8247 Value returned is pointer to stopping place.
8249 Increment *NEWLINES each time a newline is passed.
8250 REST_ARGS notifies macarg1 that it should absorb the rest of the args.
8251 Set *COMMENTS to 1 if a comment is seen. */
8254 macarg1 (start, limit, depthptr, newlines, comments, rest_args)
8256 register U_CHAR *limit;
8257 int *depthptr, *newlines, *comments;
8260 register U_CHAR *bp = start;
8262 while (bp < limit) {
8268 if (--(*depthptr) < 0)
8272 /* Traditionally, backslash makes following char not special. */
8273 if (bp + 1 < limit && traditional)
8276 /* But count source lines anyway. */
8285 if (bp[1] == '\\' && bp[2] == '\n')
8286 newline_fix (bp + 1);
8287 if (cplusplus_comments && bp[1] == '/') {
8290 while (bp < limit && (*bp != '\n' || bp[-1] == '\\')) {
8291 if (*bp == '\n') ++*newlines;
8296 if (bp[1] != '*' || bp + 1 >= limit)
8300 while (bp + 1 < limit) {
8302 && bp[1] == '\\' && bp[2] == '\n')
8303 newline_fix (bp + 1);
8304 if (bp[0] == '*' && bp[1] == '/')
8306 if (*bp == '\n') ++*newlines;
8314 for (quotec = *bp++; bp + 1 < limit && *bp != quotec; bp++) {
8319 while (*bp == '\\' && bp[1] == '\n') {
8322 } else if (*bp == '\n') {
8331 /* if we've returned to lowest level and we aren't absorbing all args */
8332 if ((*depthptr) == 0 && rest_args == 0)
8342 /* Discard comments and duplicate newlines
8343 in the string of length LENGTH at START,
8344 except inside of string constants.
8345 The string is copied into itself with its beginning staying fixed.
8347 NEWLINES is the number of newlines that must be duplicated.
8348 We assume that that much extra space is available past the end
8352 discard_comments (start, length, newlines)
8357 register U_CHAR *ibp;
8358 register U_CHAR *obp;
8359 register U_CHAR *limit;
8362 /* If we have newlines to duplicate, copy everything
8363 that many characters up. Then, in the second part,
8364 we will have room to insert the newlines
8366 NEWLINES may actually be too large, because it counts
8367 newlines in string constants, and we don't duplicate those.
8368 But that does no harm. */
8370 ibp = start + length;
8371 obp = ibp + newlines;
8373 while (limit != ibp)
8377 ibp = start + newlines;
8378 limit = start + length + newlines;
8381 while (ibp < limit) {
8382 *obp++ = c = *ibp++;
8385 /* Duplicate the newline. */
8397 if (*ibp == '\\' && ibp[1] == '\n')
8399 /* Delete any comment. */
8400 if (cplusplus_comments && ibp[0] == '/') {
8401 /* Comments are equivalent to spaces. */
8404 while (ibp < limit && (*ibp != '\n' || ibp[-1] == '\\'))
8408 if (ibp[0] != '*' || ibp + 1 >= limit)
8410 /* Comments are equivalent to spaces. */
8413 while (ibp + 1 < limit) {
8415 && ibp[1] == '\\' && ibp[2] == '\n')
8416 newline_fix (ibp + 1);
8417 if (ibp[0] == '*' && ibp[1] == '/')
8426 /* Notice and skip strings, so that we don't
8427 think that comments start inside them,
8428 and so we don't duplicate newlines in them. */
8431 while (ibp < limit) {
8432 *obp++ = c = *ibp++;
8435 if (c == '\n' && quotec == '\'')
8437 if (c == '\\' && ibp < limit) {
8438 while (*ibp == '\\' && ibp[1] == '\n')
8451 /* Turn newlines to spaces in the string of length LENGTH at START,
8452 except inside of string constants.
8453 The string is copied into itself with its beginning staying fixed. */
8456 change_newlines (start, length)
8460 register U_CHAR *ibp;
8461 register U_CHAR *obp;
8462 register U_CHAR *limit;
8466 limit = start + length;
8469 while (ibp < limit) {
8470 *obp++ = c = *ibp++;
8473 /* If this is a NEWLINE NEWLINE, then this is a real newline in the
8474 string. Skip past the newline and its duplicate.
8475 Put a space in the output. */
8486 /* Notice and skip strings, so that we don't delete newlines in them. */
8489 while (ibp < limit) {
8490 *obp++ = c = *ibp++;
8493 if (c == '\n' && quotec == '\'')
8505 * my_strerror - return the descriptive text associated with an `errno' code.
8509 my_strerror (errnum)
8515 #ifndef HAVE_STRERROR
8516 result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
8518 result = strerror (errnum);
8521 /* VAXCRTL's strerror() takes an optional second argument, which only
8522 matters when the first argument is EVMSERR. However, it's simplest
8523 just to pass it unconditionally. `vaxc$errno' is declared in
8524 <errno.h>, and maintained by the library in parallel with `errno'.
8525 We assume that caller's `errnum' either matches the last setting of
8526 `errno' by the library or else does not have the value `EVMSERR'. */
8528 result = strerror (errnum, vaxc$errno);
8532 result = "undocumented I/O error";
8538 * error - print error message and increment count of errors.
8542 error (msg, arg1, arg2, arg3)
8544 char *arg1, *arg2, *arg3;
8547 FILE_BUF *ip = NULL;
8549 print_containing_files ();
8551 for (i = indepth; i >= 0; i--)
8552 if (instack[i].fname != NULL) {
8558 fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno);
8559 fprintf (stderr, msg, arg1, arg2, arg3);
8560 fprintf (stderr, "\n");
8564 /* Error including a message from `errno'. */
8567 error_from_errno (name)
8571 FILE_BUF *ip = NULL;
8573 print_containing_files ();
8575 for (i = indepth; i >= 0; i--)
8576 if (instack[i].fname != NULL) {
8582 fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno);
8584 fprintf (stderr, "%s: %s\n", name, my_strerror (errno));
8589 /* Print error message but don't count it. */
8592 warning (msg, arg1, arg2, arg3)
8594 char *arg1, *arg2, *arg3;
8597 FILE_BUF *ip = NULL;
8599 if (inhibit_warnings)
8602 if (warnings_are_errors)
8605 print_containing_files ();
8607 for (i = indepth; i >= 0; i--)
8608 if (instack[i].fname != NULL) {
8614 fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno);
8615 fprintf (stderr, "warning: ");
8616 fprintf (stderr, msg, arg1, arg2, arg3);
8617 fprintf (stderr, "\n");
8621 error_with_line (line, msg, arg1, arg2, arg3)
8624 char *arg1, *arg2, *arg3;
8627 FILE_BUF *ip = NULL;
8629 print_containing_files ();
8631 for (i = indepth; i >= 0; i--)
8632 if (instack[i].fname != NULL) {
8638 fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
8639 fprintf (stderr, msg, arg1, arg2, arg3);
8640 fprintf (stderr, "\n");
8645 warning_with_line (line, msg, arg1, arg2, arg3)
8648 char *arg1, *arg2, *arg3;
8651 FILE_BUF *ip = NULL;
8653 if (inhibit_warnings)
8656 if (warnings_are_errors)
8659 print_containing_files ();
8661 for (i = indepth; i >= 0; i--)
8662 if (instack[i].fname != NULL) {
8668 fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
8669 fprintf (stderr, "warning: ");
8670 fprintf (stderr, msg, arg1, arg2, arg3);
8671 fprintf (stderr, "\n");
8674 /* print an error message and maybe count it. */
8677 pedwarn (msg, arg1, arg2, arg3)
8679 char *arg1, *arg2, *arg3;
8681 if (pedantic_errors)
8682 error (msg, arg1, arg2, arg3);
8684 warning (msg, arg1, arg2, arg3);
8688 pedwarn_with_line (line, msg, arg1, arg2, arg3)
8691 char *arg1, *arg2, *arg3;
8693 if (pedantic_errors)
8694 error_with_line (line, msg, arg1, arg2, arg3);
8696 warning_with_line (line, msg, arg1, arg2, arg3);
8699 /* Report a warning (or an error if pedantic_errors)
8700 giving specified file name and line number, not current. */
8703 pedwarn_with_file_and_line (file, line, msg, arg1, arg2, arg3)
8707 char *arg1, *arg2, *arg3;
8709 if (!pedantic_errors && inhibit_warnings)
8712 fprintf (stderr, "%s:%d: ", file, line);
8713 if (pedantic_errors)
8715 if (!pedantic_errors)
8716 fprintf (stderr, "warning: ");
8717 fprintf (stderr, msg, arg1, arg2, arg3);
8718 fprintf (stderr, "\n");
8721 /* Print the file names and line numbers of the #include
8722 commands which led to the current file. */
8725 print_containing_files ()
8727 FILE_BUF *ip = NULL;
8731 /* If stack of files hasn't changed since we last printed
8732 this info, don't repeat it. */
8733 if (last_error_tick == input_file_stack_tick)
8736 for (i = indepth; i >= 0; i--)
8737 if (instack[i].fname != NULL) {
8742 /* Give up if we don't find a source file. */
8746 /* Find the other, outer source files. */
8747 for (i--; i >= 0; i--)
8748 if (instack[i].fname != NULL) {
8752 fprintf (stderr, "In file included");
8754 fprintf (stderr, ",\n ");
8757 fprintf (stderr, " from %s:%d", ip->nominal_fname, ip->lineno);
8760 fprintf (stderr, ":\n");
8762 /* Record we have printed the status as of this time. */
8763 last_error_tick = input_file_stack_tick;
8766 /* Return the line at which an error occurred.
8767 The error is not necessarily associated with the current spot
8768 in the input stack, so LINE says where. LINE will have been
8769 copied from ip->lineno for the current input level.
8770 If the current level is for a file, we return LINE.
8771 But if the current level is not for a file, LINE is meaningless.
8772 In that case, we return the lineno of the innermost file. */
8775 line_for_error (line)
8781 for (i = indepth; i >= 0; ) {
8782 if (instack[i].fname != 0)
8787 line1 = instack[i].lineno;
8795 * If OBUF doesn't have NEEDED bytes after OPTR, make it bigger.
8797 * As things stand, nothing is ever placed in the output buffer to be
8798 * removed again except when it's KNOWN to be part of an identifier,
8799 * so flushing and moving down everything left, instead of expanding,
8803 /* You might think void was cleaner for the return type,
8804 but that would get type mismatch in check_expand in strict ANSI. */
8806 grow_outbuf (obuf, needed)
8807 register FILE_BUF *obuf;
8808 register int needed;
8813 if (obuf->length - (obuf->bufp - obuf->buf) > needed)
8816 /* Make it at least twice as big as it is now. */
8818 /* Make it have at least 150% of the free space we will need. */
8819 minsize = (3 * needed) / 2 + (obuf->bufp - obuf->buf);
8820 if (minsize > obuf->length)
8821 obuf->length = minsize;
8823 if ((p = (U_CHAR *) xrealloc (obuf->buf, obuf->length)) == NULL)
8826 obuf->bufp = p + (obuf->bufp - obuf->buf);
8832 /* Symbol table for macro names and special symbols */
8835 * install a name in the main hash table, even if it is already there.
8836 * name stops with first non alphanumeric, except leading '#'.
8837 * caller must check against redefinition if that is desired.
8838 * delete_macro () removes things installed by install () in fifo order.
8839 * this is important because of the `defined' special symbol used
8840 * in #if, and also if pushdef/popdef directives are ever implemented.
8842 * If LEN is >= 0, it is the length of the name.
8843 * Otherwise, compute the length by scanning the entire name.
8845 * If HASH is >= 0, it is the precomputed hash code.
8846 * Otherwise, compute the hash code.
8849 install (name, len, type, ivalue, value, hash)
8852 enum node_type type;
8857 register HASHNODE *hp;
8858 register int i, bucket;
8859 register U_CHAR *p, *q;
8863 while (is_idchar[*p])
8869 hash = hashf (name, len, HASHSIZE);
8871 i = sizeof (HASHNODE) + len + 1;
8872 hp = (HASHNODE *) xmalloc (i);
8874 hp->bucket_hdr = &hashtab[bucket];
8875 hp->next = hashtab[bucket];
8876 hashtab[bucket] = hp;
8878 if (hp->next != NULL)
8879 hp->next->prev = hp;
8882 if (hp->type == T_CONST)
8883 hp->value.ival = ivalue;
8885 hp->value.cpval = value;
8886 hp->name = ((U_CHAR *) hp) + sizeof (HASHNODE);
8889 for (i = 0; i < len; i++)
8896 * find the most recent hash node for name name (ending with first
8897 * non-identifier char) installed by install
8899 * If LEN is >= 0, it is the length of the name.
8900 * Otherwise, compute the length by scanning the entire name.
8902 * If HASH is >= 0, it is the precomputed hash code.
8903 * Otherwise, compute the hash code.
8906 lookup (name, len, hash)
8911 register U_CHAR *bp;
8912 register HASHNODE *bucket;
8915 for (bp = name; is_idchar[*bp]; bp++) ;
8920 hash = hashf (name, len, HASHSIZE);
8922 bucket = hashtab[hash];
8924 if (bucket->length == len && strncmp (bucket->name, name, len) == 0)
8926 bucket = bucket->next;
8932 * Delete a hash node. Some weirdness to free junk from macros.
8933 * More such weirdness will have to be added if you define more hash
8934 * types that need it.
8937 /* Note that the DEFINITION of a macro is removed from the hash table
8938 but its storage is not freed. This would be a storage leak
8939 except that it is not reasonable to keep undefining and redefining
8940 large numbers of macros many times.
8941 In any case, this is necessary, because a macro can be #undef'd
8942 in the middle of reading the arguments to a call to it.
8943 If #undef freed the DEFINITION, that would crash. */
8950 if (hp->prev != NULL)
8951 hp->prev->next = hp->next;
8952 if (hp->next != NULL)
8953 hp->next->prev = hp->prev;
8955 /* make sure that the bucket chain header that
8956 the deleted guy was on points to the right thing afterwards. */
8957 if (hp == *hp->bucket_hdr)
8958 *hp->bucket_hdr = hp->next;
8961 if (hp->type == T_MACRO) {
8962 DEFINITION *d = hp->value.defn;
8963 struct reflist *ap, *nextap;
8965 for (ap = d->pattern; ap != NULL; ap = nextap) {
8976 * return hash function on name. must be compatible with the one
8977 * computed a step at a time, elsewhere
8980 hashf (name, len, hashsize)
8981 register U_CHAR *name;
8988 r = HASHSTEP (r, *name++);
8990 return MAKE_POS (r) % hashsize;
8994 /* Dump the definition of a single macro HP to OF. */
8996 dump_single_macro (hp, of)
8997 register HASHNODE *hp;
9000 register DEFINITION *defn = hp->value.defn;
9006 /* Print the definition of the macro HP. */
9008 fprintf (of, "#define %s", hp->name);
9010 if (defn->nargs >= 0) {
9014 for (i = 0; i < defn->nargs; i++) {
9015 dump_arg_n (defn, i, of);
9016 if (i + 1 < defn->nargs)
9026 for (ap = defn->pattern; ap != NULL; ap = ap->next) {
9027 dump_defn_1 (defn->expansion, offset, ap->nchars, of);
9028 if (ap->nchars != 0)
9030 offset += ap->nchars;
9033 if (ap->raw_before && !concat)
9034 fprintf (of, " ## ");
9036 dump_arg_n (defn, ap->argno, of);
9037 if (ap->raw_after) {
9038 fprintf (of, " ## ");
9042 dump_defn_1 (defn->expansion, offset, defn->length - offset, of);
9046 /* Dump all macro definitions as #defines to stdout. */
9053 for (bucket = 0; bucket < HASHSIZE; bucket++) {
9054 register HASHNODE *hp;
9056 for (hp = hashtab[bucket]; hp; hp= hp->next) {
9057 if (hp->type == T_MACRO)
9058 dump_single_macro (hp, stdout);
9063 /* Output to OF a substring of a macro definition.
9064 BASE is the beginning of the definition.
9065 Output characters START thru LENGTH.
9066 Discard newlines outside of strings, thus
9067 converting funny-space markers to ordinary spaces. */
9070 dump_defn_1 (base, start, length, of)
9076 U_CHAR *p = base + start;
9077 U_CHAR *limit = base + start + length;
9080 if (*p == '\"' || *p =='\'') {
9081 U_CHAR *p1 = skip_quoted_string (p, limit, 0, NULL_PTR,
9082 NULL_PTR, NULL_PTR);
9083 fwrite (p, p1 - p, 1, of);
9093 /* Print the name of argument number ARGNUM of macro definition DEFN
9095 Recall that DEFN->args.argnames contains all the arg names
9096 concatenated in reverse order with comma-space in between. */
9099 dump_arg_n (defn, argnum, of)
9104 register U_CHAR *p = defn->args.argnames;
9105 while (argnum + 1 < defn->nargs) {
9106 p = (U_CHAR *) index (p, ' ') + 1;
9110 while (*p && *p != ',') {
9116 /* Initialize syntactic classifications of characters. */
9119 initialize_char_syntax ()
9124 * Set up is_idchar and is_idstart tables. These should be
9125 * faster than saying (is_alpha (c) || c == '_'), etc.
9126 * Set up these things before calling any routines tthat
9129 for (i = 'a'; i <= 'z'; i++) {
9130 is_idchar[i - 'a' + 'A'] = 1;
9132 is_idstart[i - 'a' + 'A'] = 1;
9135 for (i = '0'; i <= '9'; i++)
9138 is_idstart['_'] = 1;
9139 is_idchar['$'] = dollars_in_ident;
9140 is_idstart['$'] = dollars_in_ident;
9142 /* horizontal space table */
9143 is_hor_space[' '] = 1;
9144 is_hor_space['\t'] = 1;
9145 is_hor_space['\v'] = 1;
9146 is_hor_space['\f'] = 1;
9147 is_hor_space['\r'] = 1;
9157 /* Initialize the built-in macros. */
9160 initialize_builtins (inp, outp)
9164 install ("__LINE__", -1, T_SPECLINE, 0, NULL_PTR, -1);
9165 install ("__DATE__", -1, T_DATE, 0, NULL_PTR, -1);
9166 install ("__FILE__", -1, T_FILE, 0, NULL_PTR, -1);
9167 install ("__BASE_FILE__", -1, T_BASE_FILE, 0, NULL_PTR, -1);
9168 install ("__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL, 0, NULL_PTR, -1);
9169 install ("__VERSION__", -1, T_VERSION, 0, NULL_PTR, -1);
9170 #ifndef NO_BUILTIN_SIZE_TYPE
9171 install ("__SIZE_TYPE__", -1, T_SIZE_TYPE, 0, NULL_PTR, -1);
9173 #ifndef NO_BUILTIN_PTRDIFF_TYPE
9174 install ("__PTRDIFF_TYPE__ ", -1, T_PTRDIFF_TYPE, 0, NULL_PTR, -1);
9176 install ("__WCHAR_TYPE__", -1, T_WCHAR_TYPE, 0, NULL_PTR, -1);
9177 install ("__USER_LABEL_PREFIX__",-1,T_USER_LABEL_PREFIX_TYPE,0,NULL_PTR, -1);
9178 install ("__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE, 0, NULL_PTR, -1);
9179 install ("__TIME__", -1, T_TIME, 0, NULL_PTR, -1);
9181 install ("__STDC__", -1, T_CONST, STDC_VALUE, NULL_PTR, -1);
9183 install ("__OBJC__", -1, T_CONST, 1, NULL_PTR, -1);
9184 /* This is supplied using a -D by the compiler driver
9185 so that it is present only when truly compiling with GNU C. */
9186 /* install ("__GNUC__", -1, T_CONST, 2, NULL_PTR, -1); */
9190 char directive[2048];
9191 register struct directive *dp = &directive_table[0];
9192 struct tm *timebuf = timestamp ();
9194 sprintf (directive, " __BASE_FILE__ \"%s\"\n",
9195 instack[0].nominal_fname);
9196 output_line_command (inp, outp, 0, same_file);
9197 pass_thru_directive (directive, &directive[strlen (directive)], outp, dp);
9199 sprintf (directive, " __VERSION__ \"%s\"\n", version_string);
9200 output_line_command (inp, outp, 0, same_file);
9201 pass_thru_directive (directive, &directive[strlen (directive)], outp, dp);
9203 #ifndef NO_BUILTIN_SIZE_TYPE
9204 sprintf (directive, " __SIZE_TYPE__ %s\n", SIZE_TYPE);
9205 output_line_command (inp, outp, 0, same_file);
9206 pass_thru_directive (directive, &directive[strlen (directive)], outp, dp);
9209 #ifndef NO_BUILTIN_PTRDIFF_TYPE
9210 sprintf (directive, " __PTRDIFF_TYPE__ %s\n", PTRDIFF_TYPE);
9211 output_line_command (inp, outp, 0, same_file);
9212 pass_thru_directive (directive, &directive[strlen (directive)], outp, dp);
9215 sprintf (directive, " __WCHAR_TYPE__ %s\n", wchar_type);
9216 output_line_command (inp, outp, 0, same_file);
9217 pass_thru_directive (directive, &directive[strlen (directive)], outp, dp);
9219 sprintf (directive, " __DATE__ \"%s %2d %4d\"\n",
9220 monthnames[timebuf->tm_mon],
9221 timebuf->tm_mday, timebuf->tm_year + 1900);
9222 output_line_command (inp, outp, 0, same_file);
9223 pass_thru_directive (directive, &directive[strlen (directive)], outp, dp);
9225 sprintf (directive, " __TIME__ \"%02d:%02d:%02d\"\n",
9226 timebuf->tm_hour, timebuf->tm_min, timebuf->tm_sec);
9227 output_line_command (inp, outp, 0, same_file);
9228 pass_thru_directive (directive, &directive[strlen (directive)], outp, dp);
9232 sprintf (directive, " __STDC__ 1");
9233 output_line_command (inp, outp, 0, same_file);
9234 pass_thru_directive (directive, &directive[strlen (directive)],
9239 sprintf (directive, " __OBJC__ 1");
9240 output_line_command (inp, outp, 0, same_file);
9241 pass_thru_directive (directive, &directive[strlen (directive)],
9248 * process a given definition string, for initialization
9249 * If STR is just an identifier, define it with value 1.
9250 * If STR has anything after the identifier, then it should
9251 * be identifier=definition.
9255 make_definition (str, op)
9260 struct directive *kt;
9265 if (!is_idstart[*p]) {
9266 error ("malformed option `-D %s'", str);
9269 while (is_idchar[*++p])
9272 while (is_idchar[*++p] || *p == ',' || is_hor_space[*p])
9275 p = str; /* Error */
9278 buf = (U_CHAR *) alloca (p - buf + 4);
9279 strcpy ((char *)buf, str);
9280 strcat ((char *)buf, " 1");
9281 } else if (*p != '=') {
9282 error ("malformed option `-D %s'", str);
9286 /* Copy the entire option so we can modify it. */
9287 buf = (U_CHAR *) alloca (2 * strlen (str) + 1);
9288 strncpy (buf, str, p - str);
9289 /* Change the = to a space. */
9291 /* Scan for any backslash-newline and remove it. */
9295 if (*p == '\"' || *p == '\'') {
9296 int unterminated = 0;
9297 U_CHAR *p1 = skip_quoted_string (p, p + strlen (p), 0,
9298 NULL_PTR, NULL_PTR, &unterminated);
9302 if (*p == '\\' && p[1] == '\n')
9306 } else if (*p == '\\' && p[1] == '\n')
9308 /* Change newline chars into newline-markers. */
9309 else if (*p == '\n')
9321 ip = &instack[++indepth];
9322 ip->nominal_fname = ip->fname = "*Initialization*";
9324 ip->buf = ip->bufp = buf;
9325 ip->length = strlen (buf);
9329 ip->if_stack = if_stack;
9330 ip->system_header_p = 0;
9332 for (kt = directive_table; kt->type != T_DEFINE; kt++)
9335 /* Pass NULL instead of OP, since this is a "predefined" macro. */
9336 do_define (buf, buf + strlen (buf), NULL_PTR, kt);
9340 /* JF, this does the work for the -U option */
9343 make_undef (str, op)
9348 struct directive *kt;
9350 ip = &instack[++indepth];
9351 ip->nominal_fname = ip->fname = "*undef*";
9353 ip->buf = ip->bufp = str;
9354 ip->length = strlen (str);
9358 ip->if_stack = if_stack;
9359 ip->system_header_p = 0;
9361 for (kt = directive_table; kt->type != T_UNDEF; kt++)
9364 do_undef (str, str + strlen (str), op, kt);
9368 /* Process the string STR as if it appeared as the body of a #assert.
9369 OPTION is the option name for which STR was the argument. */
9372 make_assertion (option, str)
9377 struct directive *kt;
9378 U_CHAR *buf, *p, *q;
9380 /* Copy the entire option so we can modify it. */
9381 buf = (U_CHAR *) alloca (strlen (str) + 1);
9382 strcpy ((char *) buf, str);
9383 /* Scan for any backslash-newline and remove it. */
9386 if (*p == '\\' && p[1] == '\n')
9394 if (!is_idstart[*p]) {
9395 error ("malformed option `%s %s'", option, str);
9398 while (is_idchar[*++p])
9400 while (*p == ' ' || *p == '\t') p++;
9401 if (! (*p == 0 || *p == '(')) {
9402 error ("malformed option `%s %s'", option, str);
9406 ip = &instack[++indepth];
9407 ip->nominal_fname = ip->fname = "*Initialization*";
9409 ip->buf = ip->bufp = buf;
9410 ip->length = strlen (buf);
9414 ip->if_stack = if_stack;
9415 ip->system_header_p = 0;
9417 for (kt = directive_table; kt->type != T_ASSERT; kt++)
9420 /* pass NULL as output ptr to do_define since we KNOW it never
9421 does any output.... */
9422 do_assert (buf, buf + strlen (buf) , NULL_PTR, kt);
9426 /* Append a chain of `struct file_name_list's
9427 to the end of the main include chain.
9428 FIRST is the beginning of the chain to append, and LAST is the end. */
9431 append_include_chain (first, last)
9432 struct file_name_list *first, *last;
9434 struct file_name_list *dir;
9436 if (!first || !last)
9442 last_include->next = first;
9444 if (first_bracket_include == 0)
9445 first_bracket_include = first;
9447 for (dir = first; ; dir = dir->next) {
9448 int len = strlen (dir->fname) + INCLUDE_LEN_FUDGE;
9449 if (len > max_include_len)
9450 max_include_len = len;
9456 last_include = last;
9459 /* Add output to `deps_buffer' for the -M switch.
9460 STRING points to the text to be output.
9461 SPACER is ':' for targets, ' ' for dependencies, zero for text
9462 to be inserted literally. */
9465 deps_output (string, spacer)
9469 int size = strlen (string);
9474 #ifndef MAX_OUTPUT_COLUMNS
9475 #define MAX_OUTPUT_COLUMNS 72
9479 && (deps_column + size) > MAX_OUTPUT_COLUMNS)
9481 deps_output (" \\\n ", 0);
9485 if (deps_size + size + 8 > deps_allocated_size) {
9486 deps_allocated_size = (deps_size + size + 50) * 2;
9487 deps_buffer = (char *) xrealloc (deps_buffer, deps_allocated_size);
9489 if (spacer == ' ' && deps_column > 0)
9490 deps_buffer[deps_size++] = ' ';
9491 bcopy (string, &deps_buffer[deps_size], size);
9493 deps_column += size;
9495 deps_buffer[deps_size++] = ':';
9496 deps_buffer[deps_size] = 0;
9499 #if defined(USG) || defined(VMS)
9505 register unsigned length;
9507 while (length-- > 0)
9512 bcopy (b1, b2, length)
9515 register unsigned length;
9517 while (length-- > 0)
9522 bcmp (b1, b2, length) /* This could be a macro! */
9525 register unsigned length;
9527 while (length-- > 0)
9533 #endif /* not BSTRING */
9534 #endif /* USG or VMS */
9541 fprintf (stderr, "%s: ", progname);
9542 fprintf (stderr, str, arg);
9543 fprintf (stderr, "\n");
9544 exit (FAILURE_EXIT_CODE);
9547 /* More 'friendly' abort that prints the line and file.
9548 config.h can #define abort fancy_abort if you like that sort of thing. */
9553 fatal ("Internal gcc abort.");
9557 perror_with_name (name)
9560 fprintf (stderr, "%s: ", progname);
9561 fprintf (stderr, "%s: %s\n", name, my_strerror (errno));
9566 pfatal_with_name (name)
9569 perror_with_name (name);
9573 exit (FAILURE_EXIT_CODE);
9577 /* Handler for SIGPIPE. */
9581 /* If this is missing, some compilers complain. */
9584 fatal ("output pipe has been closed");
9590 fatal ("Memory exhausted.");
9598 register char *ptr = (char *) malloc (size);
9599 if (ptr != 0) return (ptr);
9606 xrealloc (old, size)
9610 register char *ptr = (char *) realloc (old, size);
9611 if (ptr != 0) return (ptr);
9618 xcalloc (number, size)
9619 unsigned number, size;
9621 register unsigned total = number * size;
9622 register char *ptr = (char *) malloc (total);
9627 /* It's not too long, so loop, zeroing by longs.
9628 It must be safe because malloc values are always well aligned. */
9629 register long *zp = (long *) ptr;
9630 register long *zl = (long *) (ptr + total - 4);
9631 register int i = total - 4;
9650 unsigned size = strlen (input);
9651 char *output = xmalloc (size + 1);
9652 strcpy (output, input);
9656 /* Get the file-mode and data size of the file open on FD
9657 and store them in *MODE_POINTER and *SIZE_POINTER. */
9660 file_size_and_mode (fd, mode_pointer, size_pointer)
9663 long int *size_pointer;
9667 if (fstat (fd, &sbuf) < 0) return (-1);
9668 if (mode_pointer) *mode_pointer = sbuf.st_mode;
9669 if (size_pointer) *size_pointer = sbuf.st_size;
9674 output_dots (fd, depth)
9687 /* Under VMS we need to fix up the "include" specification
9688 filename so that everything following the 1st slash is
9689 changed into its correct VMS file specification. */
9692 hack_vms_include_specification (fname)
9695 register char *cp, *cp1, *cp2;
9696 int f, check_filename_before_returning, no_prefix_seen;
9699 check_filename_before_returning = 0;
9702 /* Ignore leading "./"s */
9703 while (fname[0] == '.' && fname[1] == '/') {
9704 strcpy (fname, fname+2);
9705 no_prefix_seen = 1; /* mark this for later */
9707 /* Look for the boundary between the VMS and UNIX filespecs */
9708 cp = rindex (fname, ']'); /* Look for end of dirspec. */
9709 if (cp == 0) cp = rindex (fname, '>'); /* ... Ditto */
9710 if (cp == 0) cp = rindex (fname, ':'); /* Look for end of devspec. */
9714 cp = index (fname, '/'); /* Look for the "/" */
9718 * Check if we have a vax-c style '#include filename'
9719 * and add the missing .h
9722 if (index(fname,'.') == 0)
9723 strcat(fname, ".h");
9725 if (index(cp,'.') == 0)
9729 cp2 = Local; /* initialize */
9731 /* We are trying to do a number of things here. First of all, we are
9732 trying to hammer the filenames into a standard format, such that later
9733 processing can handle them.
9735 If the file name contains something like [dir.], then it recognizes this
9736 as a root, and strips the ".]". Later processing will add whatever is
9737 needed to get things working properly.
9739 If no device is specified, then the first directory name is taken to be
9740 a device name (or a rooted logical). */
9742 /* See if we found that 1st slash */
9743 if (cp == 0) return; /* Nothing to do!!! */
9744 if (*cp != '/') return; /* Nothing to do!!! */
9745 /* Point to the UNIX filename part (which needs to be fixed!) */
9747 /* If the directory spec is not rooted, we can just copy
9748 the UNIX filename part and we are done */
9749 if (((cp - fname) > 1) && ((cp[-1] == ']') || (cp[-1] == '>'))) {
9750 if (cp[-2] != '.') {
9752 * The VMS part ends in a `]', and the preceding character is not a `.'.
9753 * We strip the `]', and then splice the two parts of the name in the
9754 * usual way. Given the default locations for include files in cccp.c,
9755 * we will only use this code if the user specifies alternate locations
9756 * with the /include (-I) switch on the command line. */
9757 cp -= 1; /* Strip "]" */
9758 cp1--; /* backspace */
9761 * The VMS part has a ".]" at the end, and this will not do. Later
9762 * processing will add a second directory spec, and this would be a syntax
9763 * error. Thus we strip the ".]", and thus merge the directory specs.
9764 * We also backspace cp1, so that it points to a '/'. This inhibits the
9765 * generation of the 000000 root directory spec (which does not belong here
9768 cp -= 2; /* Strip ".]" */
9769 cp1--; }; /* backspace */
9772 /* We drop in here if there is no VMS style directory specification yet.
9773 * If there is no device specification either, we make the first dir a
9774 * device and try that. If we do not do this, then we will be essentially
9775 * searching the users default directory (as if they did a #include "asdf.h").
9777 * Then all we need to do is to push a '[' into the output string. Later
9778 * processing will fill this in, and close the bracket.
9780 if (cp[-1] != ':') *cp2++ = ':'; /* dev not in spec. take first dir */
9781 *cp2++ = '['; /* Open the directory specification */
9784 /* at this point we assume that we have the device spec, and (at least
9785 the opening "[" for a directory specification. We may have directories
9786 specified already */
9788 /* If there are no other slashes then the filename will be
9789 in the "root" directory. Otherwise, we need to add
9790 directory specifications. */
9791 if (index (cp1, '/') == 0) {
9792 /* Just add "000000]" as the directory string */
9793 strcpy (cp2, "000000]");
9794 cp2 += strlen (cp2);
9795 check_filename_before_returning = 1; /* we might need to fool with this later */
9797 /* As long as there are still subdirectories to add, do them. */
9798 while (index (cp1, '/') != 0) {
9799 /* If this token is "." we can ignore it */
9800 if ((cp1[0] == '.') && (cp1[1] == '/')) {
9804 /* Add a subdirectory spec. Do not duplicate "." */
9805 if (cp2[-1] != '.' && cp2[-1] != '[' && cp2[-1] != '<')
9807 /* If this is ".." then the spec becomes "-" */
9808 if ((cp1[0] == '.') && (cp1[1] == '.') && (cp[2] == '/')) {
9809 /* Add "-" and skip the ".." */
9814 /* Copy the subdirectory */
9815 while (*cp1 != '/') *cp2++= *cp1++;
9816 cp1++; /* Skip the "/" */
9818 /* Close the directory specification */
9819 if (cp2[-1] == '.') /* no trailing periods */
9823 /* Now add the filename */
9824 while (*cp1) *cp2++ = *cp1++;
9826 /* Now append it to the original VMS spec. */
9829 /* If we put a [000000] in the filename, try to open it first. If this fails,
9830 remove the [000000], and return that name. This provides flexibility
9831 to the user in that they can use both rooted and non-rooted logical names
9832 to point to the location of the file. */
9834 if (check_filename_before_returning && no_prefix_seen) {
9835 f = open (fname, O_RDONLY, 0666);
9837 /* The file name is OK as it is, so return it as is. */
9841 /* The filename did not work. Try to remove the [000000] from the name,
9843 cp = index (fname, '[');
9844 cp2 = index (fname, ']') + 1;
9845 strcpy (cp, cp2); /* this gets rid of it */
9853 /* These are the read/write replacement routines for
9854 VAX-11 "C". They make read/write behave enough
9855 like their UNIX counterparts that CCCP will work */
9858 read (fd, buf, size)
9863 #undef read /* Get back the REAL read routine */
9865 register int total = 0;
9867 /* Read until the buffer is exhausted */
9869 /* Limit each read to 32KB */
9870 i = (size > (32*1024)) ? (32*1024) : size;
9871 i = read (fd, buf, i);
9873 if (i == 0) return (total);
9876 /* Account for this read */
9885 write (fd, buf, size)
9890 #undef write /* Get back the REAL write routine */
9894 /* Limit individual writes to 32Kb */
9897 j = (i > (32*1024)) ? (32*1024) : i;
9898 if (write (fd, buf, j) < 0) return (-1);
9899 /* Account for the data written */
9906 /* The following wrapper functions supply additional arguments to the VMS
9907 I/O routines to optimize performance with file handling. The arguments
9909 "mbc=16" - Set multi-block count to 16 (use a 8192 byte buffer).
9910 "deq=64" - When extending the file, extend it in chunks of 32Kbytes.
9911 "fop=tef"- Truncate unused portions of file when closing file.
9912 "shr=nil"- Disallow file sharing while file is open.
9916 freopen (fname, type, oldfile)
9921 #undef freopen /* Get back the REAL fopen routine */
9922 if (strcmp (type, "w") == 0)
9923 return freopen (fname, type, oldfile, "mbc=16", "deq=64", "fop=tef", "shr=nil");
9924 return freopen (fname, type, oldfile, "mbc=16");
9932 #undef fopen /* Get back the REAL fopen routine */
9933 if (strcmp (type, "w") == 0)
9934 return fopen (fname, type, "mbc=16", "deq=64", "fop=tef", "shr=nil");
9935 return fopen (fname, type, "mbc=16");
9939 open (fname, flags, prot)
9944 #undef open /* Get back the REAL open routine */
9945 return open (fname, flags, prot, "mbc=16", "deq=64", "fop=tef");
9948 /* Avoid run-time library bug, where copying M out of N+M characters with
9949 N >= 65535 results in VAXCRTL's strncat falling into an infinite loop.
9950 gcc-cpp exercises this particular bug. */
9953 strncat (dst, src, cnt)
9958 register char *d = dst, *s = (char *) src;
9959 register int n = cnt; /* convert to _signed_ type */
9961 while (*d) d++; /* advance to end */
9963 if (!(*d++ = *s++)) break;
9964 if (n < 0) *d = '\0';