]> gcc.gnu.org Git - gcc.git/blame - gcc/cpplib.c
(default_conversion): Add bitfield promotions.
[gcc.git] / gcc / cpplib.c
CommitLineData
7f2935c7 1/* CPP Library.
9c906e81 2 Copyright (C) 1986, 87, 89, 92-5, 1996 Free Software Foundation, Inc.
7f2935c7
PB
3 Written by Per Bothner, 1994-95.
4 Based on CCCP program by by Paul Rubin, June 1986
5 Adapted to ANSI C, Richard Stallman, Jan 1987
6
7This program is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by the
9Free Software Foundation; either version 2, or (at your option) any
10later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
940d9d63 19Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7f2935c7
PB
20
21 In other words, you are welcome to use, share and improve this program.
22 You are forbidden to forbid anyone else to use, share and improve
23 what you give them. Help stamp out software-hoarding! */
24
25#ifdef EMACS
26#define NO_SHORTNAMES
27#include "../src/config.h"
28#ifdef open
29#undef open
30#undef read
31#undef write
32#endif /* open */
33#endif /* EMACS */
34
35/* The macro EMACS is defined when cpp is distributed as part of Emacs,
36 for the sake of machines with limited C compilers. */
37#ifndef EMACS
38#include "config.h"
39#endif /* not EMACS */
40
41#ifndef STANDARD_INCLUDE_DIR
42#define STANDARD_INCLUDE_DIR "/usr/include"
43#endif
44
45#ifndef LOCAL_INCLUDE_DIR
46#define LOCAL_INCLUDE_DIR "/usr/local/include"
47#endif
48
49#if 0 /* We can't get ptrdiff_t, so I arranged not to need PTR_INT_TYPE. */
50#ifdef __STDC__
51#define PTR_INT_TYPE ptrdiff_t
52#else
53#define PTR_INT_TYPE long
54#endif
55#endif /* 0 */
56
57#include "cpplib.h"
58#include "cpphash.h"
59
60#ifndef STDC_VALUE
61#define STDC_VALUE 1
62#endif
63
64/* By default, colon separates directories in a path. */
65#ifndef PATH_SEPARATOR
66#define PATH_SEPARATOR ':'
67#endif
68
7f2935c7
PB
69#include <ctype.h>
70#include <stdio.h>
71#include <signal.h>
72#ifdef __STDC__
7f2935c7
PB
73#include <stdlib.h>
74#endif
75
76#ifndef VMS
77#ifndef USG
78#include <sys/time.h> /* for __DATE__ and __TIME__ */
79#include <sys/resource.h>
80#else
7f2935c7
PB
81#include <sys/times.h>
82#include <time.h>
83#include <fcntl.h>
84#endif /* USG */
85#endif /* not VMS */
86
87/* This defines "errno" properly for VMS, and gives us EACCES. */
88#include <errno.h>
89
90extern char *index ();
91extern char *rindex ();
92
93#ifndef O_RDONLY
94#define O_RDONLY 0
95#endif
96
97#undef MIN
98#undef MAX
99#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
100#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
101
102/* Find the largest host integer type and set its size and type. */
103
104#ifndef HOST_BITS_PER_WIDE_INT
105
106#if HOST_BITS_PER_LONG > HOST_BITS_PER_INT
107#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG
108#define HOST_WIDE_INT long
109#else
110#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT
111#define HOST_WIDE_INT int
112#endif
113
114#endif
115
116#ifndef S_ISREG
117#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
118#endif
119
120#ifndef S_ISDIR
121#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
122#endif
123
124/* Define a generic NULL if one hasn't already been defined. */
125
126#ifndef NULL
127#define NULL 0
128#endif
129
130#ifndef GENERIC_PTR
131#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
132#define GENERIC_PTR void *
133#else
134#define GENERIC_PTR char *
135#endif
136#endif
137
138#ifndef NULL_PTR
139#define NULL_PTR ((GENERIC_PTR)0)
140#endif
141
142#ifndef INCLUDE_LEN_FUDGE
143#define INCLUDE_LEN_FUDGE 0
144#endif
145
146/* Symbols to predefine. */
147
148#ifdef CPP_PREDEFINES
149static char *predefs = CPP_PREDEFINES;
150#else
151static char *predefs = "";
152#endif
153\f
154/* We let tm.h override the types used here, to handle trivial differences
155 such as the choice of unsigned int or long unsigned int for size_t.
156 When machines start needing nontrivial differences in the size type,
157 it would be best to do something here to figure out automatically
158 from other information what type to use. */
159
160/* The string value for __SIZE_TYPE__. */
161
162#ifndef SIZE_TYPE
163#define SIZE_TYPE "long unsigned int"
164#endif
165
166/* The string value for __PTRDIFF_TYPE__. */
167
168#ifndef PTRDIFF_TYPE
169#define PTRDIFF_TYPE "long int"
170#endif
171
172/* The string value for __WCHAR_TYPE__. */
173
174#ifndef WCHAR_TYPE
175#define WCHAR_TYPE "int"
176#endif
177#define CPP_WCHAR_TYPE(PFILE) \
178 (CPP_OPTIONS (PFILE)->cplusplus ? "__wchar_t" : WCHAR_TYPE)
179
180/* The string value for __USER_LABEL_PREFIX__ */
181
182#ifndef USER_LABEL_PREFIX
183#define USER_LABEL_PREFIX ""
184#endif
185
186/* The string value for __REGISTER_PREFIX__ */
187
188#ifndef REGISTER_PREFIX
189#define REGISTER_PREFIX ""
190#endif
191\f
192/* In the definition of a #assert name, this structure forms
193 a list of the individual values asserted.
194 Each value is itself a list of "tokens".
195 These are strings that are compared by name. */
196
197struct tokenlist_list {
198 struct tokenlist_list *next;
199 struct arglist *tokens;
200};
201
202struct assertion_hashnode {
203 struct assertion_hashnode *next; /* double links for easy deletion */
204 struct assertion_hashnode *prev;
205 /* also, a back pointer to this node's hash
206 chain is kept, in case the node is the head
207 of the chain and gets deleted. */
208 struct assertion_hashnode **bucket_hdr;
209 int length; /* length of token, for quick comparison */
210 U_CHAR *name; /* the actual name */
211 /* List of token-sequences. */
212 struct tokenlist_list *value;
213};
214\f
215#define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
216#define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
217
218#define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? CPP_BUFFER (pfile)->cur[N] : EOF)
219#define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N))
220#define GETC() CPP_BUF_GET (CPP_BUFFER (pfile))
221#define PEEKC() CPP_BUF_PEEK (CPP_BUFFER (pfile))
222/* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
223 (Note that it is false while we're expanding marco *arguments*.) */
224#define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->cleanup == macro_cleanup)
225
226/* Move all backslash-newline pairs out of embarrassing places.
227 Exchange all such pairs following BP
228 with any potentially-embarrassing characters that follow them.
229 Potentially-embarrassing characters are / and *
230 (because a backslash-newline inside a comment delimiter
231 would cause it not to be recognized). */
232
233#define NEWLINE_FIX \
234 do {while (PEEKC() == '\\' && PEEKN(1) == '\n') FORWARD(2); } while(0)
235
236/* Same, but assume we've already read the potential '\\' into C. */
237#define NEWLINE_FIX1(C) do { \
238 while ((C) == '\\' && PEEKC() == '\n') { FORWARD(1); (C) = GETC(); }\
239 } while(0)
240
7f2935c7
PB
241struct cpp_pending {
242 struct cpp_pending *next;
243 char *cmd;
244 char *arg;
245};
246
247/* Forward declarations. */
248
249extern char *xmalloc ();
250
251static void add_import ();
252static void append_include_chain ();
253static void make_undef ();
7f2935c7
PB
254static void make_assertion ();
255static void path_include ();
256static void initialize_builtins ();
257static void initialize_char_syntax ();
258static void dump_arg_n ();
259static void dump_defn_1 ();
260extern void delete_macro ();
261static void trigraph_pcp ();
262static int finclude ();
263static void validate_else ();
264static int comp_def_part ();
e2f79f3c 265#ifdef abort
7f2935c7 266extern void fancy_abort ();
e2f79f3c 267#endif
7f2935c7
PB
268static void pipe_closed ();
269static void print_containing_files ();
270static int lookup_import ();
271static int redundant_include_p ();
272static is_system_include ();
273static struct file_name_map *read_name_map ();
274static char *read_filename_string ();
275static int open_include_file ();
276static int check_preconditions ();
277static void pcfinclude ();
278static void pcstring_used ();
279static int check_macro_name ();
280static int compare_defs ();
281static int compare_token_lists ();
6be492ab 282static HOST_WIDE_INT eval_if_expression ();
7f2935c7 283static int change_newlines ();
7f2935c7
PB
284extern int hashf ();
285static int file_size_and_mode ();
286static struct arglist *read_token_list ();
287static void free_token_list ();
288static int safe_read ();
289static void push_macro_expansion PARAMS ((cpp_reader *,
290 U_CHAR*, int, HASHNODE*));
22bbceaf 291static struct cpp_pending *nreverse_pending PARAMS ((struct cpp_pending*));
7f2935c7 292extern char *xrealloc ();
e2f79f3c 293static char *xcalloc ();
7f2935c7
PB
294static char *savestring ();
295
296static void conditional_skip ();
297static void skip_if_group ();
298
299/* Last arg to output_line_command. */
300enum file_change_code {same_file, enter_file, leave_file};
301
302/* External declarations. */
303
6be492ab
PB
304extern HOST_WIDE_INT cpp_parse_expr PARAMS ((cpp_reader*));
305
7f2935c7
PB
306extern char *getenv ();
307extern FILE *fdopen ();
308extern char *version_string;
309extern struct tm *localtime ();
310
311/* These functions are declared to return int instead of void since they
312 are going to be placed in a table and some old compilers have trouble with
313 pointers to functions returning void. */
314
315static int do_define ();
316static int do_line ();
317static int do_include ();
318static int do_undef ();
319static int do_error ();
320static int do_pragma ();
321static int do_ident ();
322static int do_if ();
323static int do_xifdef ();
324static int do_else ();
325static int do_elif ();
326static int do_endif ();
327static int do_sccs ();
328static int do_once ();
329static int do_assert ();
330static int do_unassert ();
331static int do_warning ();
332\f
333struct file_name_list
334 {
335 struct file_name_list *next;
336 char *fname;
337 /* If the following is nonzero, it is a macro name.
338 Don't include the file again if that macro is defined. */
339 U_CHAR *control_macro;
340 /* If the following is nonzero, it is a C-language system include
341 directory. */
342 int c_system_include_path;
343 /* Mapping of file names for this directory. */
344 struct file_name_map *name_map;
345 /* Non-zero if name_map is valid. */
346 int got_name_map;
347 };
348
6bac1e64
PB
349/* If a buffer's dir field is SELF_DIR_DUMMY, it means the file was found
350 via the same directory as the file that #included it. */
351#define SELF_DIR_DUMMY ((struct file_name_list*)(~0))
352
7f2935c7
PB
353/* #include "file" looks in source file dir, then stack. */
354/* #include <file> just looks in the stack. */
355/* -I directories are added to the end, then the defaults are added. */
356/* The */
357static struct default_include {
358 char *fname; /* The name of the directory. */
359 int cplusplus; /* Only look here if we're compiling C++. */
360 int cxx_aware; /* Includes in this directory don't need to
361 be wrapped in extern "C" when compiling
362 C++. */
363} include_defaults_array[]
364#ifdef INCLUDE_DEFAULTS
365 = INCLUDE_DEFAULTS;
366#else
367 = {
368 /* Pick up GNU C++ specific include files. */
369 { GPLUSPLUS_INCLUDE_DIR, 1, 1 },
9c906e81 370 { OLD_GPLUSPLUS_INCLUDE_DIR, 1, 1 },
7f2935c7
PB
371#ifdef CROSS_COMPILE
372 /* This is the dir for fixincludes. Put it just before
373 the files that we fix. */
374 { GCC_INCLUDE_DIR, 0, 0 },
375 /* For cross-compilation, this dir name is generated
376 automatically in Makefile.in. */
377 { CROSS_INCLUDE_DIR, 0, 0 },
378 /* This is another place that the target system's headers might be. */
379 { TOOL_INCLUDE_DIR, 0, 1 },
380#else /* not CROSS_COMPILE */
381 /* This should be /usr/local/include and should come before
382 the fixincludes-fixed header files. */
383 { LOCAL_INCLUDE_DIR, 0, 1 },
384 /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
385 Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
386 { TOOL_INCLUDE_DIR, 0, 1 },
387 /* This is the dir for fixincludes. Put it just before
388 the files that we fix. */
389 { GCC_INCLUDE_DIR, 0, 0 },
390 /* Some systems have an extra dir of include files. */
391#ifdef SYSTEM_INCLUDE_DIR
392 { SYSTEM_INCLUDE_DIR, 0, 0 },
393#endif
394 { STANDARD_INCLUDE_DIR, 0, 0 },
395#endif /* not CROSS_COMPILE */
396 { 0, 0, 0 }
397 };
398#endif /* no INCLUDE_DEFAULTS */
399
400/* `struct directive' defines one #-directive, including how to handle it. */
401
402struct directive {
403 int length; /* Length of name */
404 int (*func)(); /* Function to handle directive */
405 char *name; /* Name of directive */
406 enum node_type type; /* Code which describes which directive. */
407 char command_reads_line; /* One if rest of line is read by func. */
408 char traditional_comments; /* Nonzero: keep comments if -traditional. */
409 char pass_thru; /* Copy preprocessed directive to output file.*/
410};
411
412/* Here is the actual list of #-directives, most-often-used first.
413 The initialize_builtins function assumes #define is the very first. */
414
415static struct directive directive_table[] = {
416 { 6, do_define, "define", T_DEFINE, 0, 1},
417 { 5, do_xifdef, "ifdef", T_IFDEF, 1},
418 { 6, do_xifdef, "ifndef", T_IFNDEF, 1},
419 { 7, do_include, "include", T_INCLUDE, 1},
420 { 12, do_include, "include_next", T_INCLUDE_NEXT, 1},
421 { 6, do_include, "import", T_IMPORT, 1},
422 { 5, do_endif, "endif", T_ENDIF, 1},
423 { 4, do_else, "else", T_ELSE, 1},
424 { 2, do_if, "if", T_IF, 1},
425 { 4, do_elif, "elif", T_ELIF, 1},
426 { 5, do_undef, "undef", T_UNDEF},
427 { 5, do_error, "error", T_ERROR},
428 { 7, do_warning, "warning", T_WARNING},
429 { 6, do_pragma, "pragma", T_PRAGMA, 0, 0, 1},
430 { 4, do_line, "line", T_LINE, 1},
431 { 5, do_ident, "ident", T_IDENT, 1, 0, 1},
432#ifdef SCCS_DIRECTIVE
433 { 4, do_sccs, "sccs", T_SCCS},
434#endif
435 { 6, do_assert, "assert", T_ASSERT, 1},
436 { 8, do_unassert, "unassert", T_UNASSERT, 1},
437 { -1, 0, "", T_UNUSED},
438};
439\f
440/* table to tell if char can be part of a C identifier. */
441U_CHAR is_idchar[256];
442/* table to tell if char can be first char of a c identifier. */
443U_CHAR is_idstart[256];
444/* table to tell if c is horizontal space. */
445U_CHAR is_hor_space[256];
446/* table to tell if c is horizontal or vertical space. */
447static U_CHAR is_space[256];
448
449/* Initialize syntactic classifications of characters. */
450
451static void
452initialize_char_syntax (opts)
453 struct cpp_options *opts;
454{
455 register int i;
456
457 /*
458 * Set up is_idchar and is_idstart tables. These should be
459 * faster than saying (is_alpha (c) || c == '_'), etc.
460 * Set up these things before calling any routines tthat
461 * refer to them.
462 */
463 for (i = 'a'; i <= 'z'; i++) {
464 is_idchar[i - 'a' + 'A'] = 1;
465 is_idchar[i] = 1;
466 is_idstart[i - 'a' + 'A'] = 1;
467 is_idstart[i] = 1;
468 }
469 for (i = '0'; i <= '9'; i++)
470 is_idchar[i] = 1;
471 is_idchar['_'] = 1;
472 is_idstart['_'] = 1;
473 is_idchar['$'] = opts->dollars_in_ident;
474 is_idstart['$'] = opts->dollars_in_ident;
475
476 /* horizontal space table */
477 is_hor_space[' '] = 1;
478 is_hor_space['\t'] = 1;
479 is_hor_space['\v'] = 1;
480 is_hor_space['\f'] = 1;
481 is_hor_space['\r'] = 1;
482
483 is_space[' '] = 1;
484 is_space['\t'] = 1;
485 is_space['\v'] = 1;
486 is_space['\f'] = 1;
487 is_space['\n'] = 1;
488 is_space['\r'] = 1;
489}
490
7f2935c7
PB
491
492/* Place into PFILE a quoted string representing the string SRC.
493 Caller must reserve enough space in pfile->token_buffer. */
494static void
495quote_string (pfile, src)
496 cpp_reader *pfile;
497 char *src;
498{
499 U_CHAR c;
500
501 CPP_PUTC_Q (pfile, '\"');
502 for (;;)
503 switch ((c = *src++))
504 {
505 default:
506 if (isprint (c))
507 CPP_PUTC_Q (pfile, c);
508 else
509 {
510 sprintf (CPP_PWRITTEN (pfile), "\\%03o", c);
511 CPP_ADJUST_WRITTEN (pfile, 4);
512 }
513 break;
514
515 case '\"':
516 case '\\':
517 CPP_PUTC_Q (pfile, '\\');
518 CPP_PUTC_Q (pfile, c);
519 break;
520
521 case '\0':
522 CPP_PUTC_Q (pfile, '\"');
523 CPP_NUL_TERMINATE_Q (pfile);
524 return;
525 }
526}
527
d013f05e 528/* Re-allocates PFILE->token_buffer so it will hold at least N more chars. */
7f2935c7
PB
529
530void
531cpp_grow_buffer (pfile, n)
532 cpp_reader *pfile;
533 long n;
534{
535 long old_written = CPP_WRITTEN (pfile);
536 pfile->token_buffer_size = n + 2 * pfile->token_buffer_size;
0e45ccbd 537 pfile->token_buffer = (U_CHAR*)
7f2935c7
PB
538 xrealloc(pfile->token_buffer, pfile->token_buffer_size);
539 CPP_SET_WRITTEN (pfile, old_written);
540}
541
542\f
543/*
544 * process a given definition string, for initialization
545 * If STR is just an identifier, define it with value 1.
546 * If STR has anything after the identifier, then it should
547 * be identifier=definition.
548 */
549
b13b05f6
PB
550void
551cpp_define (pfile, str)
7f2935c7
PB
552 cpp_reader *pfile;
553 U_CHAR *str;
554{
555 U_CHAR *buf, *p;
556
557 buf = str;
558 p = str;
559 if (!is_idstart[*p])
560 {
561 cpp_error (pfile, "malformed option `-D %s'", str);
562 return;
563 }
564 while (is_idchar[*++p])
565 ;
566 if (*p == 0)
567 {
568 buf = (U_CHAR *) alloca (p - buf + 4);
569 strcpy ((char *)buf, str);
570 strcat ((char *)buf, " 1");
571 }
572 else if (*p != '=')
573 {
574 cpp_error (pfile, "malformed option `-D %s'", str);
575 return;
576 }
577 else
578 {
579 U_CHAR *q;
580 /* Copy the entire option so we can modify it. */
581 buf = (U_CHAR *) alloca (2 * strlen (str) + 1);
582 strncpy (buf, str, p - str);
583 /* Change the = to a space. */
584 buf[p - str] = ' ';
585 /* Scan for any backslash-newline and remove it. */
586 p++;
587 q = &buf[p - str];
588 while (*p)
589 {
590 if (*p == '\\' && p[1] == '\n')
591 p += 2;
592 else
593 *q++ = *p++;
594 }
595 *q = 0;
596 }
597
598 do_define (pfile, NULL, buf, buf + strlen (buf));
599}
600\f
601/* Process the string STR as if it appeared as the body of a #assert.
602 OPTION is the option name for which STR was the argument. */
603
604static void
605make_assertion (pfile, option, str)
606 cpp_reader *pfile;
607 char *option;
608 U_CHAR *str;
609{
7f2935c7
PB
610 struct directive *kt;
611 U_CHAR *buf, *p, *q;
612
613 /* Copy the entire option so we can modify it. */
614 buf = (U_CHAR *) alloca (strlen (str) + 1);
615 strcpy ((char *) buf, str);
616 /* Scan for any backslash-newline and remove it. */
617 p = q = buf;
618 while (*p) {
619#if 0
620 if (*p == '\\' && p[1] == '\n')
621 p += 2;
622 else
623#endif
624 *q++ = *p++;
625 }
626 *q = 0;
627
628 p = buf;
629 if (!is_idstart[*p]) {
630 cpp_error (pfile, "malformed option `%s %s'", option, str);
631 return;
632 }
633 while (is_idchar[*++p])
634 ;
635 while (*p == ' ' || *p == '\t') p++;
636 if (! (*p == 0 || *p == '(')) {
637 cpp_error (pfile, "malformed option `%s %s'", option, str);
638 return;
639 }
640
e2f79f3c
PB
641 if (cpp_push_buffer (pfile, buf, strlen (buf)) != NULL)
642 {
643 do_assert (pfile, NULL, NULL, NULL);
644 cpp_pop_buffer (pfile);
645 }
7f2935c7
PB
646}
647\f
648/* Append a chain of `struct file_name_list's
649 to the end of the main include chain.
650 FIRST is the beginning of the chain to append, and LAST is the end. */
651
652static void
653append_include_chain (pfile, first, last)
654 cpp_reader *pfile;
655 struct file_name_list *first, *last;
656{
657 struct cpp_options *opts = CPP_OPTIONS (pfile);
658 struct file_name_list *dir;
659
660 if (!first || !last)
661 return;
662
663 if (opts->include == 0)
664 opts->include = first;
665 else
666 opts->last_include->next = first;
667
668 if (opts->first_bracket_include == 0)
669 opts->first_bracket_include = first;
670
671 for (dir = first; ; dir = dir->next) {
672 int len = strlen (dir->fname) + INCLUDE_LEN_FUDGE;
673 if (len > pfile->max_include_len)
674 pfile->max_include_len = len;
675 if (dir == last)
676 break;
677 }
678
679 last->next = NULL;
680 opts->last_include = last;
681}
682\f
683/* Add output to `deps_buffer' for the -M switch.
684 STRING points to the text to be output.
685 SPACER is ':' for targets, ' ' for dependencies, zero for text
686 to be inserted literally. */
687
688static void
689deps_output (pfile, string, spacer)
690 cpp_reader *pfile;
691 char *string;
692 int spacer;
693{
694 int size = strlen (string);
695
696 if (size == 0)
697 return;
698
699#ifndef MAX_OUTPUT_COLUMNS
700#define MAX_OUTPUT_COLUMNS 72
701#endif
702 if (spacer
703 && pfile->deps_column > 0
704 && (pfile->deps_column + size) > MAX_OUTPUT_COLUMNS)
705 {
706 deps_output (pfile, " \\\n ", 0);
707 pfile->deps_column = 0;
708 }
709
710 if (pfile->deps_size + size + 8 > pfile->deps_allocated_size)
711 {
712 pfile->deps_allocated_size = (pfile->deps_size + size + 50) * 2;
713 pfile->deps_buffer = (char *) xrealloc (pfile->deps_buffer,
714 pfile->deps_allocated_size);
715 }
716 if (spacer == ' ' && pfile->deps_column > 0)
717 pfile->deps_buffer[pfile->deps_size++] = ' ';
718 bcopy (string, &pfile->deps_buffer[pfile->deps_size], size);
719 pfile->deps_size += size;
720 pfile->deps_column += size;
721 if (spacer == ':')
722 pfile->deps_buffer[pfile->deps_size++] = ':';
723 pfile->deps_buffer[pfile->deps_size] = 0;
724}
725\f
726/* Given a colon-separated list of file names PATH,
727 add all the names to the search path for include files. */
728
729static void
730path_include (pfile, path)
731 cpp_reader *pfile;
732 char *path;
733{
734 char *p;
735
736 p = path;
737
738 if (*p)
739 while (1) {
740 char *q = p;
741 char *name;
742 struct file_name_list *dirtmp;
743
744 /* Find the end of this name. */
745 while (*q != 0 && *q != PATH_SEPARATOR) q++;
746 if (p == q) {
747 /* An empty name in the path stands for the current directory. */
748 name = (char *) xmalloc (2);
749 name[0] = '.';
750 name[1] = 0;
751 } else {
752 /* Otherwise use the directory that is named. */
753 name = (char *) xmalloc (q - p + 1);
754 bcopy (p, name, q - p);
755 name[q - p] = 0;
756 }
757
758 dirtmp = (struct file_name_list *)
759 xmalloc (sizeof (struct file_name_list));
760 dirtmp->next = 0; /* New one goes on the end */
761 dirtmp->control_macro = 0;
762 dirtmp->c_system_include_path = 0;
763 dirtmp->fname = name;
764 dirtmp->got_name_map = 0;
765 append_include_chain (pfile, dirtmp, dirtmp);
766
767 /* Advance past this name. */
768 p = q;
769 if (*p == 0)
770 break;
771 /* Skip the colon. */
772 p++;
773 }
774}
775\f
776void
a94c94be
PB
777cpp_options_init (opts)
778 cpp_options *opts;
7f2935c7 779{
5f972d0c 780 bzero ((char *) opts, sizeof *opts);
7f2935c7
PB
781 opts->in_fname = NULL;
782 opts->out_fname = NULL;
783
784 /* Initialize is_idchar to allow $. */
785 opts->dollars_in_ident = 1;
786 initialize_char_syntax (opts);
787 opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 0;
788
789 opts->no_line_commands = 0;
790 opts->no_trigraphs = 1;
791 opts->put_out_comments = 0;
792 opts->print_include_names = 0;
793 opts->dump_macros = dump_none;
794 opts->no_output = 0;
795 opts->cplusplus = 0;
796 opts->cplusplus_comments = 0;
797
798 opts->verbose = 0;
799 opts->objc = 0;
800 opts->lang_asm = 0;
801 opts->for_lint = 0;
802 opts->chill = 0;
803 opts->pedantic_errors = 0;
804 opts->inhibit_warnings = 0;
805 opts->warn_comments = 0;
806 opts->warn_import = 1;
807 opts->warnings_are_errors = 0;
808}
809
810enum cpp_token
811null_underflow (pfile)
812 cpp_reader *pfile;
813{
814 return CPP_EOF;
815}
816
817int
818null_cleanup (pbuf, pfile)
819 cpp_buffer *pbuf;
820 cpp_reader *pfile;
821{
822 return 0;
823}
824
825int
826macro_cleanup (pbuf, pfile)
827 cpp_buffer *pbuf;
828 cpp_reader *pfile;
829{
830 HASHNODE *macro = (HASHNODE*)pbuf->data;
831 if (macro->type == T_DISABLED)
832 macro->type = T_MACRO;
833 if (macro->type != T_MACRO || pbuf->buf != macro->value.defn->expansion)
834 free (pbuf->buf);
835 return 0;
836}
837
838int
839file_cleanup (pbuf, pfile)
840 cpp_buffer *pbuf;
841 cpp_reader *pfile;
842{
782331f4
PB
843 if (pbuf->buf)
844 {
845 free (pbuf->buf);
846 pbuf->buf = 0;
847 }
7f2935c7
PB
848 return 0;
849}
850
7f2935c7
PB
851/* Assuming we have read '/'.
852 If this is the start of a comment (followed by '*' or '/'),
853 skip to the end of the comment, and return ' '.
854 Return EOF if we reached the end of file before the end of the comment.
855 If not the start of a comment, return '/'. */
856
857static int
858skip_comment (pfile, linep)
859 cpp_reader *pfile;
860 long *linep;
861{
d1b680c6 862 int c = 0;
7f2935c7
PB
863 while (PEEKC() == '\\' && PEEKN(1) == '\n')
864 {
865 if (linep)
866 (*linep)++;
867 FORWARD(2);
868 }
869 if (PEEKC() == '*')
870 {
871 FORWARD(1);
872 for (;;)
873 {
874 int prev_c = c;
875 c = GETC ();
876 if (c == EOF)
877 return EOF;
878 while (c == '\\' && PEEKC() == '\n')
879 {
880 if (linep)
881 (*linep)++;
882 FORWARD(1), c = GETC();
883 }
884 if (prev_c == '*' && c == '/')
885 return ' ';
886 if (c == '\n' && linep)
887 (*linep)++;
888 }
889 }
890 else if (PEEKC() == '/' && CPP_OPTIONS (pfile)->cplusplus_comments)
891 {
892 FORWARD(1);
893 for (;;)
894 {
895 c = GETC ();
896 if (c == EOF)
897 return ' '; /* Allow // to be terminated by EOF. */
898 while (c == '\\' && PEEKC() == '\n')
899 {
900 FORWARD(1);
901 c = GETC();
902 if (linep)
903 (*linep)++;
904 }
905 if (c == '\n')
906 {
907 /* Don't consider final '\n' to be part of comment. */
908 FORWARD(-1);
909 return ' ';
910 }
911 }
912 }
913 else
914 return '/';
915}
916
917/* Skip whitespace \-newline and comments. Does not macro-expand. */
918void
919cpp_skip_hspace (pfile)
920 cpp_reader *pfile;
921{
922 while (1)
923 {
924 int c = PEEKC();
925 if (c == EOF)
926 return; /* FIXME */
927 if (is_hor_space[c])
928 {
929 if ((c == '\f' || c == '\v') && CPP_PEDANTIC (pfile))
930 cpp_pedwarn (pfile, "%s in preprocessing directive",
931 c == '\f' ? "formfeed" : "vertical tab");
932 FORWARD(1);
933 }
934 else if (c == '/')
935 {
936 FORWARD (1);
937 c = skip_comment (pfile, NULL);
938 if (c == '/')
939 FORWARD(-1);
940 if (c == EOF || c == '/')
941 return;
942 }
943 else if (c == '\\' && PEEKN(1) == '\n') {
944 FORWARD(2);
945 }
782331f4
PB
946 else if (c == '@' && CPP_BUFFER (pfile)->has_escapes
947 && is_hor_space[PEEKN(1)])
948 FORWARD(2);
7f2935c7
PB
949 else return;
950 }
951}
952
953/* Read the rest of the current line.
954 The line is appended to PFILE's output buffer. */
955
e2f79f3c 956static void
7f2935c7
PB
957copy_rest_of_line (pfile)
958 cpp_reader *pfile;
959{
960 struct cpp_options *opts = CPP_OPTIONS (pfile);
961 for (;;)
962 {
963 int c = GETC();
964 int nextc;
965 switch (c)
966 {
967 case EOF:
968 goto end_directive;
969 case '\\':
970 if (PEEKC() == '\n')
971 {
972 FORWARD (1);
973 continue;
974 }
975 case '\'':
976 case '\"':
977 goto scan_directive_token;
978 break;
979 case '/':
980 nextc = PEEKC();
981 if (nextc == '*' || (opts->cplusplus_comments && nextc == '*'))
982 goto scan_directive_token;
983 break;
984 case '\f':
985 case '\v':
986 if (CPP_PEDANTIC (pfile))
987 cpp_pedwarn (pfile, "%s in preprocessing directive",
988 c == '\f' ? "formfeed" : "vertical tab");
989 break;
990
991 case '\n':
992 FORWARD(-1);
993 goto end_directive;
994 scan_directive_token:
995 FORWARD(-1);
996 cpp_get_token (pfile);
997 continue;
998 }
999 CPP_PUTC (pfile, c);
1000 }
1001 end_directive: ;
1002 CPP_NUL_TERMINATE (pfile);
1003}
1004
1005void
1006skip_rest_of_line (pfile)
1007 cpp_reader *pfile;
1008{
1009 long old = CPP_WRITTEN (pfile);
1010 copy_rest_of_line (pfile);
1011 CPP_SET_WRITTEN (pfile, old);
1012}
1013
1014/* Handle a possible # directive.
1015 '#' has already been read. */
1016
1017int
1018handle_directive (pfile)
1019 cpp_reader *pfile;
1020{ int c;
1021 register struct directive *kt;
1022 int ident_length;
1023 long after_ident;
1024 U_CHAR *ident, *line_end;
1025 long old_written = CPP_WRITTEN (pfile);
1026
1027 cpp_skip_hspace (pfile);
1028
1029 c = PEEKC ();
1030 if (c >= '0' && c <= '9')
1031 {
1032 /* Handle # followed by a line number. */
1033 if (CPP_PEDANTIC (pfile))
1034 cpp_pedwarn (pfile, "`#' followed by integer");
1035 do_line (pfile, NULL);
1036 goto done_a_directive;
1037 }
1038
1039 /* Now find the directive name. */
1040 CPP_PUTC (pfile, '#');
1041 parse_name (pfile, GETC());
1042 ident = pfile->token_buffer + old_written + 1;
1043 ident_length = CPP_PWRITTEN (pfile) - ident;
1044 if (ident_length == 0 && PEEKC() == '\n')
1045 {
1046 /* A line of just `#' becomes blank. */
1047 goto done_a_directive;
1048 }
1049
1050#if 0
1051 if (ident_length == 0 || !is_idstart[*ident]) {
1052 U_CHAR *p = ident;
1053 while (is_idchar[*p]) {
1054 if (*p < '0' || *p > '9')
1055 break;
1056 p++;
1057 }
1058 /* Avoid error for `###' and similar cases unless -pedantic. */
1059 if (p == ident) {
1060 while (*p == '#' || is_hor_space[*p]) p++;
1061 if (*p == '\n') {
1062 if (pedantic && !lang_asm)
1063 cpp_warning (pfile, "invalid preprocessor directive");
1064 return 0;
1065 }
1066 }
1067
1068 if (!lang_asm)
1069 cpp_error (pfile, "invalid preprocessor directive name");
1070
1071 return 0;
1072 }
1073#endif
1074 /*
1075 * Decode the keyword and call the appropriate expansion
1076 * routine, after moving the input pointer up to the next line.
1077 */
1078 for (kt = directive_table; ; kt++) {
1079 if (kt->length <= 0)
1080 goto not_a_directive;
1081 if (kt->length == ident_length && !strncmp (kt->name, ident, ident_length))
1082 break;
1083 }
1084
d1b680c6
PE
1085 if (kt->command_reads_line)
1086 after_ident = 0;
1087 else
7f2935c7
PB
1088 {
1089 /* Nonzero means do not delete comments within the directive.
1090 #define needs this when -traditional. */
1091 int comments = CPP_TRADITIONAL (pfile) && kt->traditional_comments;
1092 int save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
1093 CPP_OPTIONS (pfile)->put_out_comments = comments;
1094 after_ident = CPP_WRITTEN (pfile);
1095 copy_rest_of_line (pfile);
1096 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
1097 }
1098
1099 /* For #pragma and #define, we may want to pass through the directive.
1100 Other directives may create output, but we don't want the directive
1101 itself out, so we pop it now. For example #include may write a #line
1102 command (see comment in do_include), and conditionals may emit
1103 #failed ... #endfailed stuff. But note that popping the buffer
1104 means the parameters to kt->func may point after pfile->limit
1105 so these parameters are invalid as soon as something gets appended
1106 to the token_buffer. */
1107
1108 line_end = CPP_PWRITTEN (pfile);
1109 if (!kt->pass_thru && kt->type != T_DEFINE)
1110 CPP_SET_WRITTEN (pfile, old_written);
1111
1112 (*kt->func) (pfile, kt, pfile->token_buffer + after_ident, line_end);
1113 if (kt->pass_thru
1114 || (kt->type == T_DEFINE
1115 && CPP_OPTIONS (pfile)->dump_macros == dump_definitions))
1116 {
1117 /* Just leave the entire #define in the output stack. */
1118 }
1119 else if (kt->type == T_DEFINE
1120 && CPP_OPTIONS (pfile)->dump_macros == dump_names)
1121 {
1122 U_CHAR *p = pfile->token_buffer + old_written + 7; /* Skip "#define". */
1123 SKIP_WHITE_SPACE (p);
1124 while (is_idchar[*p]) p++;
1125 pfile->limit = p;
1126 CPP_PUTC (pfile, '\n');
1127 }
1128 else if (kt->type == T_DEFINE)
1129 CPP_SET_WRITTEN (pfile, old_written);
1130 done_a_directive:
1131 return 1;
1132
1133 not_a_directive:
1134 return 0;
1135}
1136
1137/* Pass a directive through to the output file.
1138 BUF points to the contents of the directive, as a contiguous string.
1139 LIMIT points to the first character past the end of the directive.
1140 KEYWORD is the keyword-table entry for the directive. */
1141
1142static void
1143pass_thru_directive (buf, limit, pfile, keyword)
1144 U_CHAR *buf, *limit;
1145 cpp_reader *pfile;
1146 struct directive *keyword;
1147{
1148 register unsigned keyword_length = keyword->length;
1149
1150 CPP_RESERVE (pfile, 1 + keyword_length + (limit - buf));
1151 CPP_PUTC_Q (pfile, '#');
1152 CPP_PUTS_Q (pfile, keyword->name, keyword_length);
1153 if (limit != buf && buf[0] != ' ')
1154 CPP_PUTC_Q (pfile, ' ');
1155 CPP_PUTS_Q (pfile, buf, limit - buf);
1156#if 0
1157 CPP_PUTS_Q (pfile, '\n');
1158 /* Count the line we have just made in the output,
1159 to get in sync properly. */
1160 pfile->lineno++;
1161#endif
1162}
1163\f
1164/* The arglist structure is built by do_define to tell
1165 collect_definition where the argument names begin. That
1166 is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist
1167 would contain pointers to the strings x, y, and z.
1168 Collect_definition would then build a DEFINITION node,
1169 with reflist nodes pointing to the places x, y, and z had
1170 appeared. So the arglist is just convenience data passed
1171 between these two routines. It is not kept around after
1172 the current #define has been processed and entered into the
1173 hash table. */
1174
1175struct arglist {
1176 struct arglist *next;
1177 U_CHAR *name;
1178 int length;
1179 int argno;
1180 char rest_args;
1181};
1182
1183/* Read a replacement list for a macro with parameters.
1184 Build the DEFINITION structure.
1185 Reads characters of text starting at BUF until END.
1186 ARGLIST specifies the formal parameters to look for
1187 in the text of the definition; NARGS is the number of args
1188 in that list, or -1 for a macro name that wants no argument list.
1189 MACRONAME is the macro name itself (so we can avoid recursive expansion)
1190 and NAMELEN is its length in characters.
1191
782331f4
PB
1192 Note that comments, backslash-newlines, and leading white space
1193 have already been deleted from the argument. */
7f2935c7
PB
1194
1195static DEFINITION *
782331f4 1196collect_expansion (pfile, buf, limit, nargs, arglist)
7f2935c7 1197 cpp_reader *pfile;
782331f4 1198 U_CHAR *buf, *limit;
7f2935c7
PB
1199 int nargs;
1200 struct arglist *arglist;
1201{
1202 DEFINITION *defn;
782331f4 1203 register U_CHAR *p, *lastp, *exp_p;
7f2935c7
PB
1204 struct reflist *endpat = NULL;
1205 /* Pointer to first nonspace after last ## seen. */
1206 U_CHAR *concat = 0;
1207 /* Pointer to first nonspace after last single-# seen. */
1208 U_CHAR *stringify = 0;
1209 int maxsize;
1210 int expected_delimiter = '\0';
1211
1212 /* Scan thru the replacement list, ignoring comments and quoted
1213 strings, picking up on the macro calls. It does a linear search
1214 thru the arg list on every potential symbol. Profiling might say
1215 that something smarter should happen. */
1216
782331f4 1217 if (limit < buf)
7f2935c7
PB
1218 abort ();
1219
1220 /* Find the beginning of the trailing whitespace. */
7f2935c7
PB
1221 p = buf;
1222 while (p < limit && is_space[limit[-1]]) limit--;
7f2935c7
PB
1223
1224 /* Allocate space for the text in the macro definition.
1225 Leading and trailing whitespace chars need 2 bytes each.
1226 Each other input char may or may not need 1 byte,
782331f4
PB
1227 so this is an upper bound. The extra 5 are for invented
1228 leading and trailing newline-marker and final null. */
7f2935c7 1229 maxsize = (sizeof (DEFINITION)
782331f4
PB
1230 + (limit - p) + 5);
1231 /* Occurrences of '@' get doubled, so allocate extra space for them. */
1232 while (p < limit)
1233 if (*p++ == '@')
1234 maxsize++;
7f2935c7
PB
1235 defn = (DEFINITION *) xcalloc (1, maxsize);
1236
1237 defn->nargs = nargs;
1238 exp_p = defn->expansion = (U_CHAR *) defn + sizeof (DEFINITION);
1239 lastp = exp_p;
1240
1241 p = buf;
1242
782331f4
PB
1243 /* Add one initial space escape-marker to prevent accidental
1244 token-pasting (often removed by macroexpand). */
1245 *exp_p++ = '@';
7f2935c7
PB
1246 *exp_p++ = ' ';
1247
1248 if (limit - p >= 2 && p[0] == '#' && p[1] == '#') {
1249 cpp_error (pfile, "`##' at start of macro definition");
1250 p += 2;
1251 }
1252
1253 /* Process the main body of the definition. */
1254 while (p < limit) {
1255 int skipped_arg = 0;
1256 register U_CHAR c = *p++;
1257
1258 *exp_p++ = c;
1259
1260 if (!CPP_TRADITIONAL (pfile)) {
1261 switch (c) {
1262 case '\'':
1263 case '\"':
1264 if (expected_delimiter != '\0') {
1265 if (c == expected_delimiter)
1266 expected_delimiter = '\0';
1267 } else
1268 expected_delimiter = c;
1269 break;
1270
7f2935c7 1271 case '\\':
782331f4 1272 if (p < limit && expected_delimiter) {
7f2935c7
PB
1273 /* In a string, backslash goes through
1274 and makes next char ordinary. */
1275 *exp_p++ = *p++;
1276 }
1277 break;
1278
1279 case '@':
a2baccf6
PB
1280 /* An '@' in a string or character constant stands for itself,
1281 and does not need to be escaped. */
1282 if (!expected_delimiter)
1283 *exp_p++ = c;
7f2935c7
PB
1284 break;
1285
1286 case '#':
1287 /* # is ordinary inside a string. */
1288 if (expected_delimiter)
1289 break;
1290 if (p < limit && *p == '#') {
1291 /* ##: concatenate preceding and following tokens. */
1292 /* Take out the first #, discard preceding whitespace. */
1293 exp_p--;
1294 while (exp_p > lastp && is_hor_space[exp_p[-1]])
1295 --exp_p;
1296 /* Skip the second #. */
1297 p++;
1298 /* Discard following whitespace. */
1299 SKIP_WHITE_SPACE (p);
1300 concat = p;
1301 if (p == limit)
1302 cpp_error (pfile, "`##' at end of macro definition");
1303 } else if (nargs >= 0) {
1304 /* Single #: stringify following argument ref.
1305 Don't leave the # in the expansion. */
1306 exp_p--;
1307 SKIP_WHITE_SPACE (p);
1308 if (p == limit || ! is_idstart[*p])
1309 cpp_error (pfile,
1310 "`#' operator is not followed by a macro argument name");
1311 else
1312 stringify = p;
1313 }
1314 break;
1315 }
1316 } else {
1317 /* In -traditional mode, recognize arguments inside strings and
1318 and character constants, and ignore special properties of #.
1319 Arguments inside strings are considered "stringified", but no
1320 extra quote marks are supplied. */
1321 switch (c) {
1322 case '\'':
1323 case '\"':
1324 if (expected_delimiter != '\0') {
1325 if (c == expected_delimiter)
1326 expected_delimiter = '\0';
1327 } else
1328 expected_delimiter = c;
1329 break;
1330
1331 case '\\':
1332 /* Backslash quotes delimiters and itself, but not macro args. */
1333 if (expected_delimiter != 0 && p < limit
1334 && (*p == expected_delimiter || *p == '\\')) {
1335 *exp_p++ = *p++;
1336 continue;
1337 }
1338 break;
1339
1340 case '/':
1341 if (expected_delimiter != '\0') /* No comments inside strings. */
1342 break;
1343 if (*p == '*') {
1344 /* If we find a comment that wasn't removed by handle_directive,
1345 this must be -traditional. So replace the comment with
1346 nothing at all. */
1347 exp_p--;
1348 p += 1;
1349 while (p < limit && !(p[-2] == '*' && p[-1] == '/'))
1350 p++;
1351#if 0
1352 /* Mark this as a concatenation-point, as if it had been ##. */
1353 concat = p;
1354#endif
1355 }
1356 break;
1357 }
1358 }
1359
1360 /* Handle the start of a symbol. */
1361 if (is_idchar[c] && nargs > 0) {
1362 U_CHAR *id_beg = p - 1;
1363 int id_len;
1364
1365 --exp_p;
1366 while (p != limit && is_idchar[*p]) p++;
1367 id_len = p - id_beg;
1368
1369 if (is_idstart[c]) {
1370 register struct arglist *arg;
1371
1372 for (arg = arglist; arg != NULL; arg = arg->next) {
1373 struct reflist *tpat;
1374
1375 if (arg->name[0] == c
1376 && arg->length == id_len
1377 && strncmp (arg->name, id_beg, id_len) == 0) {
1378 if (expected_delimiter && CPP_OPTIONS (pfile)->warn_stringify) {
1379 if (CPP_TRADITIONAL (pfile)) {
1380 cpp_warning (pfile, "macro argument `%.*s' is stringified.",
1381 id_len, arg->name);
1382 } else {
1383 cpp_warning (pfile,
1384 "macro arg `%.*s' would be stringified with -traditional.",
1385 id_len, arg->name);
1386 }
1387 }
1388 /* If ANSI, don't actually substitute inside a string. */
1389 if (!CPP_TRADITIONAL (pfile) && expected_delimiter)
1390 break;
1391 /* make a pat node for this arg and append it to the end of
1392 the pat list */
1393 tpat = (struct reflist *) xmalloc (sizeof (struct reflist));
1394 tpat->next = NULL;
1395 tpat->raw_before = concat == id_beg;
1396 tpat->raw_after = 0;
1397 tpat->rest_args = arg->rest_args;
1398 tpat->stringify = (CPP_TRADITIONAL (pfile)
1399 ? expected_delimiter != '\0'
1400 : stringify == id_beg);
1401
1402 if (endpat == NULL)
1403 defn->pattern = tpat;
1404 else
1405 endpat->next = tpat;
1406 endpat = tpat;
1407
1408 tpat->argno = arg->argno;
1409 tpat->nchars = exp_p - lastp;
1410 {
1411 register U_CHAR *p1 = p;
1412 SKIP_WHITE_SPACE (p1);
1413 if (p1 + 2 <= limit && p1[0] == '#' && p1[1] == '#')
1414 tpat->raw_after = 1;
1415 }
1416 lastp = exp_p; /* place to start copying from next time */
1417 skipped_arg = 1;
1418 break;
1419 }
1420 }
1421 }
1422
1423 /* If this was not a macro arg, copy it into the expansion. */
1424 if (! skipped_arg) {
1425 register U_CHAR *lim1 = p;
1426 p = id_beg;
1427 while (p != lim1)
1428 *exp_p++ = *p++;
1429 if (stringify == id_beg)
1430 cpp_error (pfile,
1431 "`#' operator should be followed by a macro argument name");
1432 }
1433 }
1434 }
1435
782331f4
PB
1436 if (!CPP_TRADITIONAL (pfile) && expected_delimiter == 0)
1437 {
1438 /* If ANSI, put in a "@ " marker to prevent token pasting.
1439 But not if "inside a string" (which in ANSI mode
1440 happens only for -D option). */
1441 *exp_p++ = '@';
1442 *exp_p++ = ' ';
7f2935c7 1443 }
7f2935c7
PB
1444
1445 *exp_p = '\0';
1446
1447 defn->length = exp_p - defn->expansion;
1448
1449 /* Crash now if we overrun the allocated size. */
1450 if (defn->length + 1 > maxsize)
1451 abort ();
1452
1453#if 0
1454/* This isn't worth the time it takes. */
1455 /* give back excess storage */
1456 defn->expansion = (U_CHAR *) xrealloc (defn->expansion, defn->length + 1);
1457#endif
1458
1459 return defn;
1460}
1461
1462/*
1463 * special extension string that can be added to the last macro argument to
1464 * allow it to absorb the "rest" of the arguments when expanded. Ex:
1465 * #define wow(a, b...) process (b, a, b)
1466 * { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); }
1467 * { wow (one, two); } -> { process (two, one, two); }
1468 * if this "rest_arg" is used with the concat token '##' and if it is not
1469 * supplied then the token attached to with ## will not be outputted. Ex:
1470 * #define wow (a, b...) process (b ## , a, ## b)
1471 * { wow (1, 2); } -> { process (2, 1, 2); }
1472 * { wow (one); } -> { process (one); {
1473 */
1474static char rest_extension[] = "...";
1475#define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1)
1476
1477/* Create a DEFINITION node from a #define directive. Arguments are
1478 as for do_define. */
1479static MACRODEF
1480create_definition (buf, limit, pfile, predefinition)
1481 U_CHAR *buf, *limit;
1482 cpp_reader *pfile;
1483 int predefinition;
1484{
1485 U_CHAR *bp; /* temp ptr into input buffer */
1486 U_CHAR *symname; /* remember where symbol name starts */
1487 int sym_length; /* and how long it is */
1488 int rest_args = 0;
1489 long line, col;
1490 char *file = CPP_BUFFER (pfile) ? CPP_BUFFER (pfile)->nominal_fname : "";
1491 DEFINITION *defn;
1492 int arglengths = 0; /* Accumulate lengths of arg names
1493 plus number of args. */
1494 MACRODEF mdef;
1495 cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col);
1496
1497 bp = buf;
1498
1499 while (is_hor_space[*bp])
1500 bp++;
1501
1502 symname = bp; /* remember where it starts */
1503
1504 sym_length = check_macro_name (pfile, bp, "macro");
1505 bp += sym_length;
1506
1507 /* Lossage will occur if identifiers or control keywords are broken
1508 across lines using backslash. This is not the right place to take
1509 care of that. */
1510
1511 if (*bp == '(') {
1512 struct arglist *arg_ptrs = NULL;
1513 int argno = 0;
1514
1515 bp++; /* skip '(' */
1516 SKIP_WHITE_SPACE (bp);
1517
1518 /* Loop over macro argument names. */
1519 while (*bp != ')') {
1520 struct arglist *temp;
1521
1522 temp = (struct arglist *) alloca (sizeof (struct arglist));
1523 temp->name = bp;
1524 temp->next = arg_ptrs;
1525 temp->argno = argno++;
1526 temp->rest_args = 0;
1527 arg_ptrs = temp;
1528
1529 if (rest_args)
1530 cpp_pedwarn (pfile, "another parameter follows `%s'", rest_extension);
1531
1532 if (!is_idstart[*bp])
1533 cpp_pedwarn (pfile, "invalid character in macro parameter name");
1534
1535 /* Find the end of the arg name. */
1536 while (is_idchar[*bp]) {
1537 bp++;
1538 /* do we have a "special" rest-args extension here? */
1539 if (limit - bp > REST_EXTENSION_LENGTH &&
1540 strncmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
1541 rest_args = 1;
1542 temp->rest_args = 1;
1543 break;
1544 }
1545 }
1546 temp->length = bp - temp->name;
1547 if (rest_args == 1)
1548 bp += REST_EXTENSION_LENGTH;
1549 arglengths += temp->length + 2;
1550 SKIP_WHITE_SPACE (bp);
1551 if (temp->length == 0 || (*bp != ',' && *bp != ')')) {
1552 cpp_error (pfile, "badly punctuated parameter list in `#define'");
1553 goto nope;
1554 }
1555 if (*bp == ',') {
1556 bp++;
1557 SKIP_WHITE_SPACE (bp);
1558 }
1559 if (bp >= limit) {
1560 cpp_error (pfile, "unterminated parameter list in `#define'");
1561 goto nope;
1562 }
1563 {
1564 struct arglist *otemp;
1565
1566 for (otemp = temp->next; otemp != NULL; otemp = otemp->next)
1567 if (temp->length == otemp->length &&
1568 strncmp (temp->name, otemp->name, temp->length) == 0) {
1569 U_CHAR *name;
1570
1571 name = (U_CHAR *) alloca (temp->length + 1);
1572 (void) strncpy (name, temp->name, temp->length);
1573 name[temp->length] = '\0';
1574 cpp_error (pfile,
1575 "duplicate argument name `%s' in `#define'", name);
1576 goto nope;
1577 }
1578 }
1579 }
1580
1581 ++bp; /* skip paren */
782331f4 1582 SKIP_WHITE_SPACE (bp);
7f2935c7
PB
1583 /* now everything from bp before limit is the definition. */
1584 defn = collect_expansion (pfile, bp, limit, argno, arg_ptrs);
1585 defn->rest_args = rest_args;
1586
1587 /* Now set defn->args.argnames to the result of concatenating
1588 the argument names in reverse order
1589 with comma-space between them. */
1590 defn->args.argnames = (U_CHAR *) xmalloc (arglengths + 1);
1591 {
1592 struct arglist *temp;
1593 int i = 0;
1594 for (temp = arg_ptrs; temp; temp = temp->next) {
1595 bcopy (temp->name, &defn->args.argnames[i], temp->length);
1596 i += temp->length;
1597 if (temp->next != 0) {
1598 defn->args.argnames[i++] = ',';
1599 defn->args.argnames[i++] = ' ';
1600 }
1601 }
1602 defn->args.argnames[i] = 0;
1603 }
1604 } else {
6be492ab
PB
1605 /* Simple expansion or empty definition. */
1606
1607 if (bp < limit)
1608 {
1609 if (is_hor_space[*bp]) {
1610 bp++;
1611 SKIP_WHITE_SPACE (bp);
1612 } else {
1613 switch (*bp) {
1614 case '!': case '"': case '#': case '%': case '&': case '\'':
1615 case ')': case '*': case '+': case ',': case '-': case '.':
1616 case '/': case ':': case ';': case '<': case '=': case '>':
1617 case '?': case '[': case '\\': case ']': case '^': case '{':
1618 case '|': case '}': case '~':
1619 cpp_warning (pfile, "missing white space after `#define %.*s'",
1620 sym_length, symname);
1621 break;
1622
1623 default:
1624 cpp_pedwarn (pfile, "missing white space after `#define %.*s'",
1625 sym_length, symname);
1626 break;
1627 }
1628 }
1629 }
7f2935c7
PB
1630 /* now everything from bp before limit is the definition. */
1631 defn = collect_expansion (pfile, bp, limit, -1, NULL_PTR);
1632 defn->args.argnames = (U_CHAR *) "";
1633 }
1634
1635 defn->line = line;
1636 defn->file = file;
1637
1638 /* OP is null if this is a predefinition */
1639 defn->predefined = predefinition;
1640 mdef.defn = defn;
1641 mdef.symnam = symname;
1642 mdef.symlen = sym_length;
1643
1644 return mdef;
1645
1646 nope:
1647 mdef.defn = 0;
1648 return mdef;
1649}
1650
1651/* Check a purported macro name SYMNAME, and yield its length.
1652 USAGE is the kind of name this is intended for. */
1653
1654static int
1655check_macro_name (pfile, symname, usage)
1656 cpp_reader *pfile;
1657 U_CHAR *symname;
1658 char *usage;
1659{
1660 U_CHAR *p;
1661 int sym_length;
1662
1663 for (p = symname; is_idchar[*p]; p++)
1664 ;
1665 sym_length = p - symname;
1666 if (sym_length == 0)
1667 cpp_error (pfile, "invalid %s name", usage);
1668 else if (!is_idstart[*symname]) {
1669 U_CHAR *msg; /* what pain... */
1670 msg = (U_CHAR *) alloca (sym_length + 1);
1671 bcopy (symname, msg, sym_length);
1672 msg[sym_length] = 0;
1673 cpp_error (pfile, "invalid %s name `%s'", usage, msg);
1674 } else {
1675 if (! strncmp (symname, "defined", 7) && sym_length == 7)
1676 cpp_error (pfile, "invalid %s name `defined'", usage);
1677 }
1678 return sym_length;
1679}
1680
1681/*
1682 * return zero if two DEFINITIONs are isomorphic
1683 */
1684static int
1685compare_defs (d1, d2)
1686 DEFINITION *d1, *d2;
1687{
1688 register struct reflist *a1, *a2;
1689 register U_CHAR *p1 = d1->expansion;
1690 register U_CHAR *p2 = d2->expansion;
1691 int first = 1;
1692
1693 if (d1->nargs != d2->nargs)
1694 return 1;
1695 if (strcmp ((char *)d1->args.argnames, (char *)d2->args.argnames))
1696 return 1;
1697 for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2;
1698 a1 = a1->next, a2 = a2->next) {
1699 if (!((a1->nchars == a2->nchars && ! strncmp (p1, p2, a1->nchars))
1700 || ! comp_def_part (first, p1, a1->nchars, p2, a2->nchars, 0))
1701 || a1->argno != a2->argno
1702 || a1->stringify != a2->stringify
1703 || a1->raw_before != a2->raw_before
1704 || a1->raw_after != a2->raw_after)
1705 return 1;
1706 first = 0;
1707 p1 += a1->nchars;
1708 p2 += a2->nchars;
1709 }
1710 if (a1 != a2)
1711 return 1;
1712 if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion),
1713 p2, d2->length - (p2 - d2->expansion), 1))
1714 return 1;
1715 return 0;
1716}
1717
1718/* Return 1 if two parts of two macro definitions are effectively different.
1719 One of the parts starts at BEG1 and has LEN1 chars;
1720 the other has LEN2 chars at BEG2.
1721 Any sequence of whitespace matches any other sequence of whitespace.
1722 FIRST means these parts are the first of a macro definition;
1723 so ignore leading whitespace entirely.
1724 LAST means these parts are the last of a macro definition;
1725 so ignore trailing whitespace entirely. */
1726
1727static int
1728comp_def_part (first, beg1, len1, beg2, len2, last)
1729 int first;
1730 U_CHAR *beg1, *beg2;
1731 int len1, len2;
1732 int last;
1733{
1734 register U_CHAR *end1 = beg1 + len1;
1735 register U_CHAR *end2 = beg2 + len2;
1736 if (first) {
1737 while (beg1 != end1 && is_space[*beg1]) beg1++;
1738 while (beg2 != end2 && is_space[*beg2]) beg2++;
1739 }
1740 if (last) {
1741 while (beg1 != end1 && is_space[end1[-1]]) end1--;
1742 while (beg2 != end2 && is_space[end2[-1]]) end2--;
1743 }
1744 while (beg1 != end1 && beg2 != end2) {
1745 if (is_space[*beg1] && is_space[*beg2]) {
1746 while (beg1 != end1 && is_space[*beg1]) beg1++;
1747 while (beg2 != end2 && is_space[*beg2]) beg2++;
1748 } else if (*beg1 == *beg2) {
1749 beg1++; beg2++;
1750 } else break;
1751 }
1752 return (beg1 != end1) || (beg2 != end2);
1753}
1754
1755/* Process a #define command.
1756BUF points to the contents of the #define command, as a contiguous string.
1757LIMIT points to the first character past the end of the definition.
1758KEYWORD is the keyword-table entry for #define,
1759or NULL for a "predefined" macro. */
1760
1761static int
1762do_define (pfile, keyword, buf, limit)
1763 cpp_reader *pfile;
1764 struct directive *keyword;
1765 U_CHAR *buf, *limit;
1766{
1767 int hashcode;
1768 MACRODEF mdef;
1769 HASHNODE *hp;
1770
1771#if 0
1772 /* If this is a precompiler run (with -pcp) pass thru #define commands. */
1773 if (pcp_outfile && keyword)
1774 pass_thru_directive (buf, limit, pfile, keyword);
1775#endif
1776
1777 mdef = create_definition (buf, limit, pfile, keyword == NULL);
1778 if (mdef.defn == 0)
1779 goto nope;
1780
1781 hashcode = hashf (mdef.symnam, mdef.symlen, HASHSIZE);
1782
1783 if ((hp = cpp_lookup (pfile, mdef.symnam, mdef.symlen, hashcode)) != NULL)
1784 {
1785 int ok = 0;
1786 /* Redefining a precompiled key is ok. */
1787 if (hp->type == T_PCSTRING)
1788 ok = 1;
1789 /* Redefining a macro is ok if the definitions are the same. */
1790 else if (hp->type == T_MACRO)
1791 ok = ! compare_defs (mdef.defn, hp->value.defn);
1792 /* Redefining a constant is ok with -D. */
1793 else if (hp->type == T_CONST)
1794 ok = ! CPP_OPTIONS (pfile)->done_initializing;
1795 /* Print the warning if it's not ok. */
1796 if (!ok)
1797 {
1798 U_CHAR *msg; /* what pain... */
1799
1800 /* If we are passing through #define and #undef directives, do
1801 that for this re-definition now. */
1802 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1803 pass_thru_directive (buf, limit, pfile, keyword);
1804
1805 msg = (U_CHAR *) alloca (mdef.symlen + 22);
1806 *msg = '`';
1807 bcopy (mdef.symnam, msg + 1, mdef.symlen);
1808 strcpy ((char *) (msg + mdef.symlen + 1), "' redefined");
1809 cpp_pedwarn (pfile, msg);
1810 if (hp->type == T_MACRO)
1811 cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file, hp->value.defn->line,
1812 "this is the location of the previous definition");
1813 }
1814 /* Replace the old definition. */
1815 hp->type = T_MACRO;
1816 hp->value.defn = mdef.defn;
1817 }
1818 else
1819 {
1820 /* If we are passing through #define and #undef directives, do
1821 that for this new definition now. */
1822 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1823 pass_thru_directive (buf, limit, pfile, keyword);
1824 install (mdef.symnam, mdef.symlen, T_MACRO, 0,
1825 (char *) mdef.defn, hashcode);
1826 }
1827
1828 return 0;
1829
1830nope:
1831
1832 return 1;
1833}
1834
1835/* This structure represents one parsed argument in a macro call.
1836 `raw' points to the argument text as written (`raw_length' is its length).
1837 `expanded' points to the argument's macro-expansion
1838 (its length is `expand_length').
1839 `stringified_length' is the length the argument would have
1840 if stringified.
1841 `use_count' is the number of times this macro arg is substituted
1842 into the macro. If the actual use count exceeds 10,
1843 the value stored is 10. */
1844
1845/* raw and expanded are relative to ARG_BASE */
1846#define ARG_BASE ((pfile)->token_buffer)
1847
1848struct argdata {
1849 /* Strings relative to pfile->token_buffer */
1850 long raw, expanded, stringified;
1851 int raw_length, expand_length;
1852 int stringified_length;
1853 char newlines;
7f2935c7
PB
1854 char use_count;
1855};
1856
d013f05e
PB
1857/* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack.
1858 If BUFFER != NULL, then use the LENGTH characters in BUFFER
1859 as the new input buffer.
1860 Return the new buffer, or NULL on failure. */
1861
7f2935c7
PB
1862cpp_buffer*
1863cpp_push_buffer (pfile, buffer, length)
1864 cpp_reader *pfile;
1865 U_CHAR *buffer;
1866 long length;
1867{
22bbceaf 1868 register cpp_buffer *buf = CPP_BUFFER (pfile);
7f2935c7 1869 if (buf == pfile->buffer_stack)
e2f79f3c
PB
1870 {
1871 cpp_fatal (pfile, "%s: macro or `#include' recursion too deep",
1872 buf->fname);
1873 return NULL;
1874 }
22bbceaf 1875 buf--;
7f2935c7
PB
1876 bzero ((char *) buf, sizeof (cpp_buffer));
1877 CPP_BUFFER (pfile) = buf;
7f2935c7
PB
1878 buf->if_stack = pfile->if_stack;
1879 buf->cleanup = null_cleanup;
1880 buf->underflow = null_underflow;
1881 buf->buf = buf->cur = buffer;
1882 buf->alimit = buf->rlimit = buffer + length;
1883
1884 return buf;
1885}
1886
1887cpp_buffer*
1888cpp_pop_buffer (pfile)
1889 cpp_reader *pfile;
1890{
1891 cpp_buffer *buf = CPP_BUFFER (pfile);
7f2935c7
PB
1892 (*buf->cleanup) (buf, pfile);
1893 return ++CPP_BUFFER (pfile);
7f2935c7
PB
1894}
1895
1896/* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer.
1897 Pop the buffer when done. */
1898
1899void
1900cpp_scan_buffer (pfile)
1901 cpp_reader *pfile;
1902{
1903 cpp_buffer *buffer = CPP_BUFFER (pfile);
1904 for (;;)
1905 {
1906 enum cpp_token token = cpp_get_token (pfile);
1907 if (token == CPP_EOF) /* Should not happen ... */
1908 break;
1909 if (token == CPP_POP && CPP_BUFFER (pfile) == buffer)
1910 {
1911 cpp_pop_buffer (pfile);
1912 break;
1913 }
1914 }
1915}
1916
1917/*
782331f4 1918 * Rescan a string (which may have escape marks) into pfile's buffer.
7f2935c7
PB
1919 * Place the result in pfile->token_buffer.
1920 *
1921 * The input is copied before it is scanned, so it is safe to pass
1922 * it something from the token_buffer that will get overwritten
1923 * (because it follows CPP_WRITTEN). This is used by do_include.
7f2935c7
PB
1924 */
1925
782331f4 1926static void
7f2935c7
PB
1927cpp_expand_to_buffer (pfile, buf, length)
1928 cpp_reader *pfile;
1929 U_CHAR *buf;
1930 int length;
1931{
1932 register cpp_buffer *ip;
1933 cpp_buffer obuf;
1934 U_CHAR *limit = buf + length;
1935 U_CHAR *buf1;
1936#if 0
1937 int odepth = indepth;
1938#endif
1939
1940 if (length < 0)
1941 abort ();
1942
1943 /* Set up the input on the input stack. */
1944
1945 buf1 = (U_CHAR *) alloca (length + 1);
1946 {
1947 register U_CHAR *p1 = buf;
1948 register U_CHAR *p2 = buf1;
1949
1950 while (p1 != limit)
1951 *p2++ = *p1++;
1952 }
1953 buf1[length] = 0;
1954
1955 ip = cpp_push_buffer (pfile, buf1, length);
e2f79f3c
PB
1956 if (ip == NULL)
1957 return;
782331f4 1958 ip->has_escapes = 1;
7f2935c7
PB
1959#if 0
1960 ip->lineno = obuf.lineno = 1;
1961#endif
1962
1963 /* Scan the input, create the output. */
1964 cpp_scan_buffer (pfile);
1965
1966#if 0
1967 if (indepth != odepth)
1968 abort ();
1969#endif
1970
1971 CPP_NUL_TERMINATE (pfile);
1972}
1973
1974\f
1975static void
1976adjust_position (buf, limit, linep, colp)
1977 U_CHAR *buf;
1978 U_CHAR *limit;
1979 long *linep;
1980 long *colp;
1981{
1982 while (buf < limit)
1983 {
1984 U_CHAR ch = *buf++;
1985 if (ch == '\n')
1986 (*linep)++, (*colp) = 1;
1987 else
1988 (*colp)++;
1989 }
1990}
1991
1992/* Move line_base forward, updating lineno and colno. */
1993
1994static void
1995update_position (pbuf)
1996 register cpp_buffer *pbuf;
1997{
1998 unsigned char *old_pos = pbuf->buf + pbuf->line_base;
1999 unsigned char *new_pos = pbuf->cur;
2000 register struct parse_marker *mark;
2001 for (mark = pbuf->marks; mark != NULL; mark = mark->next)
2002 {
2003 if (pbuf->buf + mark->position < new_pos)
2004 new_pos = pbuf->buf + mark->position;
2005 }
2006 pbuf->line_base += new_pos - old_pos;
2007 adjust_position (old_pos, new_pos, &pbuf->lineno, &pbuf->colno);
2008}
2009
2010void
2011cpp_buf_line_and_col (pbuf, linep, colp)
2012 register cpp_buffer *pbuf;
2013 long *linep, *colp;
2014{
2015 long dummy;
2016 if (colp == NULL)
2017 colp = &dummy;
2018 if (pbuf)
2019 {
2020 *linep = pbuf->lineno;
2021 *colp = pbuf->colno;
2022 adjust_position (pbuf->buf + pbuf->line_base, pbuf->cur, linep, colp);
2023 }
2024 else
2025 {
2026 *linep = 0;
2027 *colp = 0;
2028 }
2029}
2030
2031/* Return the cpp_buffer that corresponds to a file (not a macro). */
2032
2033cpp_buffer*
2034cpp_file_buffer (pfile)
2035 cpp_reader *pfile;
2036{
22bbceaf 2037 cpp_buffer *ip = CPP_BUFFER (pfile);
7f2935c7 2038
22bbceaf 2039 for ( ; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
7f2935c7
PB
2040 if (ip->fname != NULL)
2041 return ip;
2042 return NULL;
2043}
2044
2045static long
2046count_newlines (buf, limit)
2047 register U_CHAR *buf;
2048 register U_CHAR *limit;
2049{
2050 register long count = 0;
2051 while (buf < limit)
2052 {
2053 U_CHAR ch = *buf++;
2054 if (ch == '\n')
2055 count++;
2056 }
2057 return count;
2058}
2059
2060/*
2061 * write out a #line command, for instance, after an #include file.
2062 * If CONDITIONAL is nonzero, we can omit the #line if it would
2063 * appear to be a no-op, and we can output a few newlines instead
2064 * if we want to increase the line number by a small amount.
2065 * FILE_CHANGE says whether we are entering a file, leaving, or neither.
2066 */
2067
2068static void
2069output_line_command (pfile, conditional, file_change)
2070 cpp_reader *pfile;
2071 int conditional;
2072 enum file_change_code file_change;
2073{
2074 int len;
2075 char *line_cmd_buf, *line_end;
2076 long line, col;
2077 cpp_buffer *ip = CPP_BUFFER (pfile);
2078
e2f79f3c 2079 if (ip->fname == NULL)
7f2935c7 2080 return;
7f2935c7
PB
2081
2082 update_position (ip);
e2f79f3c
PB
2083
2084 if (CPP_OPTIONS (pfile)->no_line_commands
2085 || CPP_OPTIONS (pfile)->no_output)
2086 return;
2087
7f2935c7
PB
2088 line = CPP_BUFFER (pfile)->lineno;
2089 col = CPP_BUFFER (pfile)->colno;
2090 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
2091
a8259c76
RK
2092 if (CPP_OPTIONS (pfile)->no_line_commands)
2093 return;
2094
7f2935c7
PB
2095 if (conditional) {
2096 if (line == pfile->lineno)
2097 return;
2098
2099 /* If the inherited line number is a little too small,
2100 output some newlines instead of a #line command. */
2101 if (line > pfile->lineno && line < pfile->lineno + 8) {
2102 CPP_RESERVE (pfile, 20);
2103 while (line > pfile->lineno) {
2104 CPP_PUTC_Q (pfile, '\n');
2105 pfile->lineno++;
2106 }
2107 return;
2108 }
2109 }
2110
2111#if 0
2112 /* Don't output a line number of 0 if we can help it. */
2113 if (ip->lineno == 0 && ip->bufp - ip->buf < ip->length
2114 && *ip->bufp == '\n') {
2115 ip->lineno++;
2116 ip->bufp++;
2117 }
2118#endif
2119
2120 CPP_RESERVE (pfile, 4 * strlen (ip->nominal_fname) + 50);
2121 {
2122#ifdef OUTPUT_LINE_COMMANDS
2123 static char sharp_line[] = "#line ";
2124#else
2125 static char sharp_line[] = "# ";
2126#endif
2127 CPP_PUTS_Q (pfile, sharp_line, sizeof(sharp_line)-1);
2128 }
2129
2130 sprintf (CPP_PWRITTEN (pfile), "%d ", line);
2131 CPP_ADJUST_WRITTEN (pfile, strlen (CPP_PWRITTEN (pfile)));
2132
2133 quote_string (pfile, ip->nominal_fname);
2134 if (file_change != same_file) {
2135 CPP_PUTC_Q (pfile, ' ');
2136 CPP_PUTC_Q (pfile, file_change == enter_file ? '1' : '2');
2137 }
2138 /* Tell cc1 if following text comes from a system header file. */
2139 if (ip->system_header_p) {
2140 CPP_PUTC_Q (pfile, ' ');
2141 CPP_PUTC_Q (pfile, '3');
2142 }
2143#ifndef NO_IMPLICIT_EXTERN_C
2144 /* Tell cc1plus if following text should be treated as C. */
2145 if (ip->system_header_p == 2 && CPP_OPTIONS (pfile)->cplusplus) {
2146 CPP_PUTC_Q (pfile, ' ');
2147 CPP_PUTC_Q (pfile, '4');
2148 }
2149#endif
2150 CPP_PUTC_Q (pfile, '\n');
2151 pfile->lineno = line;
2152}
2153\f
2154/*
782331f4 2155 * Parse a macro argument and append the info on PFILE's token_buffer.
7f2935c7
PB
2156 * REST_ARGS means to absorb the rest of the args.
2157 * Return nonzero to indicate a syntax error.
2158 */
2159
2160static enum cpp_token
2161macarg (pfile, rest_args)
2162 cpp_reader *pfile;
2163 int rest_args;
2164{
2165 int paren = 0;
2166 enum cpp_token token;
2167 long arg_start = CPP_WRITTEN (pfile);
2168 char save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
2169 CPP_OPTIONS (pfile)->put_out_comments = 0;
2170
2171 /* Try to parse as much of the argument as exists at this
2172 input stack level. */
2173 pfile->no_macro_expand++;
2174 for (;;)
2175 {
2176 token = cpp_get_token (pfile);
2177 switch (token)
2178 {
2179 case CPP_EOF:
2180 goto done;
2181 case CPP_POP:
2182 /* If we've hit end of file, it's an error (reported by caller).
2183 Ditto if it's the end of cpp_expand_to_buffer text.
2184 If we've hit end of macro, just continue. */
2185 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
2186 goto done;
2187 break;
2188 case CPP_LPAREN:
2189 paren++;
2190 break;
2191 case CPP_RPAREN:
2192 if (--paren < 0)
2193 goto found;
2194 break;
2195 case CPP_COMMA:
2196 /* if we've returned to lowest level and
2197 we aren't absorbing all args */
2198 if (paren == 0 && rest_args == 0)
2199 goto found;
2200 break;
2201 found:
2202 /* Remove ',' or ')' from argument buffer. */
2203 CPP_ADJUST_WRITTEN (pfile, -1);
2204 goto done;
2205 default: ;
2206 }
2207 }
2208
2209 done:
2210 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
2211 pfile->no_macro_expand--;
2212
2213 return token;
2214}
2215\f
2216/* Turn newlines to spaces in the string of length LENGTH at START,
2217 except inside of string constants.
2218 The string is copied into itself with its beginning staying fixed. */
2219
2220static int
2221change_newlines (start, length)
2222 U_CHAR *start;
2223 int length;
2224{
2225 register U_CHAR *ibp;
2226 register U_CHAR *obp;
2227 register U_CHAR *limit;
2228 register int c;
2229
2230 ibp = start;
2231 limit = start + length;
2232 obp = start;
2233
2234 while (ibp < limit) {
2235 *obp++ = c = *ibp++;
2236 switch (c) {
2237
2238 case '\'':
2239 case '\"':
2240 /* Notice and skip strings, so that we don't delete newlines in them. */
2241 {
2242 int quotec = c;
2243 while (ibp < limit) {
2244 *obp++ = c = *ibp++;
2245 if (c == quotec)
2246 break;
2247 if (c == '\n' && quotec == '\'')
2248 break;
2249 }
2250 }
2251 break;
2252 }
2253 }
2254
2255 return obp - start;
2256}
2257
2258\f
2259static struct tm *
2260timestamp (pfile)
2261 cpp_reader *pfile;
2262{
2263 if (!pfile->timebuf) {
2264 time_t t = time ((time_t *)0);
2265 pfile->timebuf = localtime (&t);
2266 }
2267 return pfile->timebuf;
2268}
2269
2270static char *monthnames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
2271 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
2272 };
2273
2274/*
2275 * expand things like __FILE__. Place the expansion into the output
2276 * buffer *without* rescanning.
2277 */
2278
2279static void
2280special_symbol (hp, pfile)
2281 HASHNODE *hp;
2282 cpp_reader *pfile;
2283{
2284 char *buf;
2285 int i, len;
2286 int true_indepth;
2287 cpp_buffer *ip = NULL;
2288 struct tm *timebuf;
2289
2290 int paren = 0; /* For special `defined' keyword */
2291
2292#if 0
2293 if (pcp_outfile && pcp_inside_if
2294 && hp->type != T_SPEC_DEFINED && hp->type != T_CONST)
2295 cpp_error (pfile,
2296 "Predefined macro `%s' used inside `#if' during precompilation",
2297 hp->name);
2298#endif
2299
2300 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
2301 {
d013f05e 2302 if (ip == CPP_NULL_BUFFER (pfile))
7f2935c7
PB
2303 {
2304 cpp_error (pfile, "cccp error: not in any file?!");
2305 return; /* the show must go on */
2306 }
2307 if (ip->fname != NULL)
2308 break;
2309 }
2310
2311 switch (hp->type)
2312 {
2313 case T_FILE:
2314 case T_BASE_FILE:
2315 {
2316 char *string;
2317 if (hp->type == T_BASE_FILE)
2318 {
d013f05e 2319 while (CPP_PREV_BUFFER (ip) != CPP_NULL_BUFFER (pfile))
7f2935c7
PB
2320 ip = CPP_PREV_BUFFER (ip);
2321 }
2322 string = ip->nominal_fname;
2323
2324 if (!string)
2325 string = "";
2326 CPP_RESERVE (pfile, 3 + 4 * strlen (string));
2327 quote_string (pfile, string);
2328 return;
2329 }
2330
2331 case T_INCLUDE_LEVEL:
2332 true_indepth = 0;
d013f05e
PB
2333 ip = CPP_BUFFER (pfile);
2334 for (; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
7f2935c7
PB
2335 if (ip->fname != NULL)
2336 true_indepth++;
2337
2338 buf = (char *) alloca (8); /* Eight bytes ought to be more than enough */
2339 sprintf (buf, "%d", true_indepth - 1);
2340 break;
2341
2342 case T_VERSION:
2343 buf = (char *) alloca (3 + strlen (version_string));
2344 sprintf (buf, "\"%s\"", version_string);
2345 break;
2346
2347#ifndef NO_BUILTIN_SIZE_TYPE
2348 case T_SIZE_TYPE:
2349 buf = SIZE_TYPE;
2350 break;
2351#endif
2352
2353#ifndef NO_BUILTIN_PTRDIFF_TYPE
2354 case T_PTRDIFF_TYPE:
2355 buf = PTRDIFF_TYPE;
2356 break;
2357#endif
2358
2359 case T_WCHAR_TYPE:
2360 buf = CPP_WCHAR_TYPE (pfile);
2361 break;
2362
2363 case T_USER_LABEL_PREFIX_TYPE:
2364 buf = USER_LABEL_PREFIX;
2365 break;
2366
2367 case T_REGISTER_PREFIX_TYPE:
2368 buf = REGISTER_PREFIX;
2369 break;
2370
2371 case T_CONST:
2372 buf = (char *) alloca (4 * sizeof (int));
2373 sprintf (buf, "%d", hp->value.ival);
2374#if 0
2375 if (pcp_inside_if && pcp_outfile)
2376 /* Output a precondition for this macro use */
2377 fprintf (pcp_outfile, "#define %s %d\n", hp->name, hp->value.ival);
2378#endif
2379 break;
2380
2381 case T_SPECLINE:
2382 {
b13b05f6
PB
2383 long line = ip->lineno;
2384 long col = ip->colno;
7f2935c7
PB
2385 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
2386
2387 buf = (char *) alloca (10);
2388 sprintf (buf, "%d", line);
2389 }
2390 break;
2391
2392 case T_DATE:
2393 case T_TIME:
2394 buf = (char *) alloca (20);
2395 timebuf = timestamp (pfile);
2396 if (hp->type == T_DATE)
2397 sprintf (buf, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon],
2398 timebuf->tm_mday, timebuf->tm_year + 1900);
2399 else
2400 sprintf (buf, "\"%02d:%02d:%02d\"", timebuf->tm_hour, timebuf->tm_min,
2401 timebuf->tm_sec);
2402 break;
2403
2404 case T_SPEC_DEFINED:
2405 buf = " 0 "; /* Assume symbol is not defined */
2406 ip = CPP_BUFFER (pfile);
2407 SKIP_WHITE_SPACE (ip->cur);
2408 if (*ip->cur == '(')
2409 {
2410 paren++;
2411 ip->cur++; /* Skip over the paren */
2412 SKIP_WHITE_SPACE (ip->cur);
2413 }
2414
2415 if (!is_idstart[*ip->cur])
2416 goto oops;
2417 if (hp = cpp_lookup (pfile, ip->cur, -1, -1))
2418 {
2419#if 0
2420 if (pcp_outfile && pcp_inside_if
2421 && (hp->type == T_CONST
2422 || (hp->type == T_MACRO && hp->value.defn->predefined)))
2423 /* Output a precondition for this macro use. */
2424 fprintf (pcp_outfile, "#define %s\n", hp->name);
2425#endif
2426 buf = " 1 ";
2427 }
2428#if 0
2429 else
2430 if (pcp_outfile && pcp_inside_if)
2431 {
2432 /* Output a precondition for this macro use */
2433 U_CHAR *cp = ip->bufp;
2434 fprintf (pcp_outfile, "#undef ");
2435 while (is_idchar[*cp]) /* Ick! */
2436 fputc (*cp++, pcp_outfile);
2437 putc ('\n', pcp_outfile);
2438 }
2439#endif
2440 while (is_idchar[*ip->cur])
2441 ++ip->cur;
2442 SKIP_WHITE_SPACE (ip->cur);
2443 if (paren)
2444 {
2445 if (*ip->cur != ')')
2446 goto oops;
2447 ++ip->cur;
2448 }
2449 break;
2450
2451 oops:
2452
2453 cpp_error (pfile, "`defined' without an identifier");
2454 break;
2455
2456 default:
2457 cpp_error (pfile, "cccp error: invalid special hash type"); /* time for gdb */
2458 abort ();
2459 }
2460 len = strlen (buf);
2461 CPP_RESERVE (pfile, len + 1);
2462 CPP_PUTS_Q (pfile, buf, len);
2463 CPP_NUL_TERMINATE_Q (pfile);
2464
2465 return;
2466}
2467
d013f05e
PB
2468/* Write out a #define command for the special named MACRO_NAME
2469 to PFILE's token_buffer. */
2470
2471static void
2472dump_special_to_buffer (pfile, macro_name)
2473 cpp_reader *pfile;
2474 char *macro_name;
2475{
2476 static char define_directive[] = "#define ";
2477 int macro_name_length = strlen (macro_name);
2478 output_line_command (pfile, 0, same_file);
2479 CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length);
2480 CPP_PUTS_Q (pfile, define_directive, sizeof(define_directive)-1);
2481 CPP_PUTS_Q (pfile, macro_name, macro_name_length);
2482 CPP_PUTC_Q (pfile, ' ');
2483 cpp_expand_to_buffer (pfile, macro_name, macro_name_length);
2484 CPP_PUTC (pfile, '\n');
2485}
2486
7f2935c7
PB
2487/* Initialize the built-in macros. */
2488
2489static void
2490initialize_builtins (pfile)
2491 cpp_reader *pfile;
2492{
2493 install ("__LINE__", -1, T_SPECLINE, 0, 0, -1);
2494 install ("__DATE__", -1, T_DATE, 0, 0, -1);
2495 install ("__FILE__", -1, T_FILE, 0, 0, -1);
2496 install ("__BASE_FILE__", -1, T_BASE_FILE, 0, 0, -1);
2497 install ("__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL, 0, 0, -1);
2498 install ("__VERSION__", -1, T_VERSION, 0, 0, -1);
2499#ifndef NO_BUILTIN_SIZE_TYPE
2500 install ("__SIZE_TYPE__", -1, T_SIZE_TYPE, 0, 0, -1);
2501#endif
2502#ifndef NO_BUILTIN_PTRDIFF_TYPE
2503 install ("__PTRDIFF_TYPE__ ", -1, T_PTRDIFF_TYPE, 0, 0, -1);
2504#endif
2505 install ("__WCHAR_TYPE__", -1, T_WCHAR_TYPE, 0, 0, -1);
2506 install ("__USER_LABEL_PREFIX__", -1, T_USER_LABEL_PREFIX_TYPE, 0, 0, -1);
2507 install ("__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE, 0, 0, -1);
2508 install ("__TIME__", -1, T_TIME, 0, 0, -1);
2509 if (!CPP_TRADITIONAL (pfile))
2510 install ("__STDC__", -1, T_CONST, STDC_VALUE, 0, -1);
2511 if (CPP_OPTIONS (pfile)->objc)
2512 install ("__OBJC__", -1, T_CONST, 1, 0, -1);
2513/* This is supplied using a -D by the compiler driver
2514 so that it is present only when truly compiling with GNU C. */
2515/* install ("__GNUC__", -1, T_CONST, 2, 0, -1); */
2516
2517 if (CPP_OPTIONS (pfile)->debug_output)
2518 {
d013f05e
PB
2519 dump_special_to_buffer (pfile, "__BASE_FILE__");
2520 dump_special_to_buffer (pfile, "__VERSION__");
7f2935c7 2521#ifndef NO_BUILTIN_SIZE_TYPE
d013f05e 2522 dump_special_to_buffer (pfile, "__SIZE_TYPE__");
7f2935c7 2523#endif
7f2935c7 2524#ifndef NO_BUILTIN_PTRDIFF_TYPE
d013f05e 2525 dump_special_to_buffer (pfile, "__PTRDIFF_TYPE__");
7f2935c7 2526#endif
d013f05e
PB
2527 dump_special_to_buffer (pfile, "__WCHAR_TYPE__");
2528 dump_special_to_buffer (pfile, "__DATE__");
2529 dump_special_to_buffer (pfile, "__TIME__");
7f2935c7 2530 if (!CPP_TRADITIONAL (pfile))
d013f05e 2531 dump_special_to_buffer (pfile, "__STDC__");
7f2935c7 2532 if (CPP_OPTIONS (pfile)->objc)
d013f05e 2533 dump_special_to_buffer (pfile, "__OBJC__");
7f2935c7
PB
2534 }
2535}
2536\f
2537/* Return 1 iff a token ending in C1 followed directly by a token C2
2538 could cause mis-tokenization. */
2539
2540static int
2541unsafe_chars (c1, c2)
2542 int c1, c2;
2543{
2544 switch (c1)
2545 {
2546 case '+': case '-':
2547 if (c2 == c1 || c2 == '=')
2548 return 1;
2549 goto letter;
2550 case '.':
2551 case '0': case '1': case '2': case '3': case '4':
2552 case '5': case '6': case '7': case '8': case '9':
2553 case 'e': case 'E':
2554 if (c2 == '-' || c2 == '+')
2555 return 1; /* could extend a pre-processing number */
2556 goto letter;
2557 case 'L':
2558 if (c2 == '\'' || c2 == '\"')
2559 return 1; /* Could turn into L"xxx" or L'xxx'. */
2560 goto letter;
2561 letter:
2562 case '_':
2563 case 'a': case 'b': case 'c': case 'd': case 'f':
2564 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
2565 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
2566 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
2567 case 'y': case 'z':
2568 case 'A': case 'B': case 'C': case 'D': case 'F':
2569 case 'G': case 'H': case 'I': case 'J': case 'K':
2570 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
2571 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
2572 case 'Y': case 'Z':
2573 /* We're in the middle of either a name or a pre-processing number. */
2574 return (is_idchar[c2] || c2 == '.');
2575 case '<': case '>': case '!': case '%': case '#': case ':':
2576 case '^': case '&': case '|': case '*': case '/': case '=':
2577 return (c2 == c1 || c2 == '=');
2578 }
2579 return 0;
2580}
2581
2582/* Expand a macro call.
2583 HP points to the symbol that is the macro being called.
2584 Put the result of expansion onto the input stack
2585 so that subsequent input by our caller will use it.
2586
2587 If macro wants arguments, caller has already verified that
2588 an argument list follows; arguments come from the input stack. */
2589
2590static void
2591macroexpand (pfile, hp)
2592 cpp_reader *pfile;
2593 HASHNODE *hp;
2594{
2595 int nargs;
2596 DEFINITION *defn = hp->value.defn;
2597 register U_CHAR *xbuf;
3232050c 2598 long start_line, start_column;
7f2935c7
PB
2599 int xbuf_len;
2600 struct argdata *args;
2601 long old_written = CPP_WRITTEN (pfile);
2602#if 0
2603 int start_line = instack[indepth].lineno;
2604#endif
2605 int rest_args, rest_zero;
2606 register int i;
2607
2608#if 0
2609 CHECK_DEPTH (return;);
2610#endif
2611
2612#if 0
2613 /* This macro is being used inside a #if, which means it must be */
2614 /* recorded as a precondition. */
2615 if (pcp_inside_if && pcp_outfile && defn->predefined)
2616 dump_single_macro (hp, pcp_outfile);
2617#endif
2618
782331f4 2619 pfile->output_escapes++;
3232050c 2620 cpp_buf_line_and_col (cpp_file_buffer (pfile), &start_line, &start_column);
e8037d57 2621
7f2935c7
PB
2622 nargs = defn->nargs;
2623
2624 if (nargs >= 0)
2625 {
7f2935c7
PB
2626 enum cpp_token token;
2627
2628 args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata));
2629
2630 for (i = 0; i < nargs; i++)
2631 {
2632 args[i].raw = args[i].expanded = 0;
2633 args[i].raw_length = 0;
2634 args[i].expand_length = args[i].stringified_length = -1;
2635 args[i].use_count = 0;
2636 }
2637
2638 /* Parse all the macro args that are supplied. I counts them.
2639 The first NARGS args are stored in ARGS.
2640 The rest are discarded. If rest_args is set then we assume
2641 macarg absorbed the rest of the args. */
2642 i = 0;
2643 rest_args = 0;
2644 rest_args = 0;
2645 FORWARD(1); /* Discard the open-parenthesis before the first arg. */
2646 do
2647 {
2648 if (rest_args)
2649 continue;
2650 if (i < nargs || (nargs == 0 && i == 0))
2651 {
2652 /* if we are working on last arg which absorbs rest of args... */
2653 if (i == nargs - 1 && defn->rest_args)
2654 rest_args = 1;
2655 args[i].raw = CPP_WRITTEN (pfile);
2656 token = macarg (pfile, rest_args);
2657 args[i].raw_length = CPP_WRITTEN (pfile) - args[i].raw;
2658 args[i].newlines = 0; /* FIXME */
2659 }
2660 else
2661 token = macarg (pfile, 0);
2662 if (token == CPP_EOF || token == CPP_POP)
2663 {
3232050c 2664 cpp_error_with_line (pfile, start_line, start_column,
e8037d57
PB
2665 "unterminated macro call");
2666 return;
7f2935c7
PB
2667 }
2668 i++;
2669 } while (token == CPP_COMMA);
2670
2671 /* If we got one arg but it was just whitespace, call that 0 args. */
2672 if (i == 1)
2673 {
2674 register U_CHAR *bp = ARG_BASE + args[0].raw;
2675 register U_CHAR *lim = bp + args[0].raw_length;
2676 /* cpp.texi says for foo ( ) we provide one argument.
2677 However, if foo wants just 0 arguments, treat this as 0. */
2678 if (nargs == 0)
2679 while (bp != lim && is_space[*bp]) bp++;
2680 if (bp == lim)
2681 i = 0;
2682 }
2683
2684 /* Don't output an error message if we have already output one for
2685 a parse error above. */
2686 rest_zero = 0;
2687 if (nargs == 0 && i > 0)
2688 {
e8037d57 2689 cpp_error (pfile, "arguments given to macro `%s'", hp->name);
7f2935c7
PB
2690 }
2691 else if (i < nargs)
2692 {
2693 /* traditional C allows foo() if foo wants one argument. */
2694 if (nargs == 1 && i == 0 && CPP_TRADITIONAL (pfile))
2695 ;
2696 /* the rest args token is allowed to absorb 0 tokens */
2697 else if (i == nargs - 1 && defn->rest_args)
2698 rest_zero = 1;
7f2935c7
PB
2699 else if (i == 0)
2700 cpp_error (pfile, "macro `%s' used without args", hp->name);
2701 else if (i == 1)
2702 cpp_error (pfile, "macro `%s' used with just one arg", hp->name);
2703 else
2704 cpp_error (pfile, "macro `%s' used with only %d args",
2705 hp->name, i);
2706 }
2707 else if (i > nargs)
2708 {
e8037d57
PB
2709 cpp_error (pfile,
2710 "macro `%s' used with too many (%d) args", hp->name, i);
7f2935c7
PB
2711 }
2712 }
2713
2714 /* If macro wants zero args, we parsed the arglist for checking only.
2715 Read directly from the macro definition. */
2716 if (nargs <= 0)
2717 {
2718 xbuf = defn->expansion;
2719 xbuf_len = defn->length;
2720 }
2721 else
2722 {
2723 register U_CHAR *exp = defn->expansion;
2724 register int offset; /* offset in expansion,
2725 copied a piece at a time */
2726 register int totlen; /* total amount of exp buffer filled so far */
2727
2728 register struct reflist *ap, *last_ap;
2729
2730 /* Macro really takes args. Compute the expansion of this call. */
2731
2732 /* Compute length in characters of the macro's expansion.
2733 Also count number of times each arg is used. */
2734 xbuf_len = defn->length;
2735 for (ap = defn->pattern; ap != NULL; ap = ap->next)
2736 {
2737 if (ap->stringify)
2738 {
2739 register struct argdata *arg = &args[ap->argno];
2740 /* Stringify it it hasn't already been */
2741 if (arg->stringified_length < 0)
2742 {
2743 int arglen = arg->raw_length;
2744 int escaped = 0;
2745 int in_string = 0;
2746 int c;
2747 /* Initially need_space is -1. Otherwise, 1 means the
2748 previous character was a space, but we suppressed it;
2749 0 means the previous character was a non-space. */
2750 int need_space = -1;
2751 i = 0;
2752 arg->stringified = CPP_WRITTEN (pfile);
2753 if (!CPP_TRADITIONAL (pfile))
2754 CPP_PUTC (pfile, '\"'); /* insert beginning quote */
2755 for (; i < arglen; i++)
2756 {
2757 c = (ARG_BASE + arg->raw)[i];
2758
2759 if (! in_string)
2760 {
2761 /* Internal sequences of whitespace are replaced by
2762 one space except within an string or char token.*/
2763 if (is_space[c])
2764 {
782331f4
PB
2765 if (CPP_WRITTEN (pfile) > arg->stringified
2766 && (CPP_PWRITTEN (pfile))[-1] == '@')
2767 {
2768 /* "@ " escape markers are removed */
2769 CPP_ADJUST_WRITTEN (pfile, -1);
2770 continue;
2771 }
7f2935c7
PB
2772 if (need_space == 0)
2773 need_space = 1;
2774 continue;
2775 }
2776 else if (need_space > 0)
2777 CPP_PUTC (pfile, ' ');
2778 need_space = 0;
2779 }
2780
2781 if (escaped)
2782 escaped = 0;
2783 else
2784 {
2785 if (c == '\\')
2786 escaped = 1;
2787 if (in_string)
2788 {
2789 if (c == in_string)
2790 in_string = 0;
2791 }
2792 else if (c == '\"' || c == '\'')
2793 in_string = c;
2794 }
2795
2796 /* Escape these chars */
2797 if (c == '\"' || (in_string && c == '\\'))
2798 CPP_PUTC (pfile, '\\');
2799 if (isprint (c))
2800 CPP_PUTC (pfile, c);
2801 else
2802 {
2803 CPP_RESERVE (pfile, 4);
2804 sprintf (CPP_PWRITTEN (pfile), "\\%03o",
2805 (unsigned int) c);
2806 CPP_ADJUST_WRITTEN (pfile, 4);
2807 }
2808 }
2809 if (!CPP_TRADITIONAL (pfile))
2810 CPP_PUTC (pfile, '\"'); /* insert ending quote */
2811 arg->stringified_length
2812 = CPP_WRITTEN (pfile) - arg->stringified;
2813 }
2814 xbuf_len += args[ap->argno].stringified_length;
2815 }
2816 else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
2817 /* Add 4 for two newline-space markers to prevent
2818 token concatenation. */
2819 xbuf_len += args[ap->argno].raw_length + 4;
2820 else
2821 {
2822 /* We have an ordinary (expanded) occurrence of the arg.
2823 So compute its expansion, if we have not already. */
2824 if (args[ap->argno].expand_length < 0)
2825 {
2826 args[ap->argno].expanded = CPP_WRITTEN (pfile);
7f2935c7
PB
2827 cpp_expand_to_buffer (pfile,
2828 ARG_BASE + args[ap->argno].raw,
2829 args[ap->argno].raw_length);
2830
7f2935c7
PB
2831 args[ap->argno].expand_length
2832 = CPP_WRITTEN (pfile) - args[ap->argno].expanded;
2833 }
2834
2835 /* Add 4 for two newline-space markers to prevent
2836 token concatenation. */
2837 xbuf_len += args[ap->argno].expand_length + 4;
2838 }
2839 if (args[ap->argno].use_count < 10)
2840 args[ap->argno].use_count++;
2841 }
2842
2843 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
2844
2845 /* Generate in XBUF the complete expansion
2846 with arguments substituted in.
2847 TOTLEN is the total size generated so far.
2848 OFFSET is the index in the definition
2849 of where we are copying from. */
2850 offset = totlen = 0;
2851 for (last_ap = NULL, ap = defn->pattern; ap != NULL;
2852 last_ap = ap, ap = ap->next)
2853 {
2854 register struct argdata *arg = &args[ap->argno];
2855 int count_before = totlen;
2856
2857 /* Add chars to XBUF. */
2858 for (i = 0; i < ap->nchars; i++, offset++)
2859 xbuf[totlen++] = exp[offset];
2860
2861 /* If followed by an empty rest arg with concatenation,
2862 delete the last run of nonwhite chars. */
2863 if (rest_zero && totlen > count_before
2864 && ((ap->rest_args && ap->raw_before)
2865 || (last_ap != NULL && last_ap->rest_args
2866 && last_ap->raw_after)))
2867 {
2868 /* Delete final whitespace. */
2869 while (totlen > count_before && is_space[xbuf[totlen - 1]])
2870 totlen--;
2871
2872 /* Delete the nonwhites before them. */
2873 while (totlen > count_before && ! is_space[xbuf[totlen - 1]])
2874 totlen--;
2875 }
2876
2877 if (ap->stringify != 0)
2878 {
2879 bcopy (ARG_BASE + arg->stringified,
2880 xbuf + totlen, arg->stringified_length);
2881 totlen += arg->stringified_length;
2882 }
2883 else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
2884 {
2885 U_CHAR *p1 = ARG_BASE + arg->raw;
2886 U_CHAR *l1 = p1 + arg->raw_length;
2887 if (ap->raw_before)
2888 {
2889 while (p1 != l1 && is_space[*p1]) p1++;
2890 while (p1 != l1 && is_idchar[*p1])
2891 xbuf[totlen++] = *p1++;
2892 }
2893 if (ap->raw_after)
2894 {
2895 /* Arg is concatenated after: delete trailing whitespace,
2896 whitespace markers, and no-reexpansion markers. */
2897 while (p1 != l1)
2898 {
2899 if (is_space[l1[-1]]) l1--;
2900 else if (l1[-1] == '-')
2901 {
2902 U_CHAR *p2 = l1 - 1;
2903 /* If a `-' is preceded by an odd number of newlines then it
2904 and the last newline are a no-reexpansion marker. */
2905 while (p2 != p1 && p2[-1] == '\n') p2--;
2906 if ((l1 - 1 - p2) & 1) {
2907 l1 -= 2;
2908 }
2909 else break;
2910 }
2911 else break;
2912 }
2913 }
2914
2915 bcopy (p1, xbuf + totlen, l1 - p1);
2916 totlen += l1 - p1;
2917 }
2918 else
2919 {
2920 U_CHAR *expanded = ARG_BASE + arg->expanded;
2921 if (!ap->raw_before && totlen > 0 && arg->expand_length
2922 && !CPP_TRADITIONAL(pfile)
2923 && unsafe_chars (xbuf[totlen-1], expanded[0]))
782331f4
PB
2924 {
2925 xbuf[totlen++] = '@';
2926 xbuf[totlen++] = ' ';
2927 }
7f2935c7
PB
2928
2929 bcopy (expanded, xbuf + totlen, arg->expand_length);
2930 totlen += arg->expand_length;
2931
2932 if (!ap->raw_after && totlen > 0 && offset < defn->length
2933 && !CPP_TRADITIONAL(pfile)
2934 && unsafe_chars (xbuf[totlen-1], exp[offset]))
782331f4
PB
2935 {
2936 xbuf[totlen++] = '@';
2937 xbuf[totlen++] = ' ';
2938 }
7f2935c7
PB
2939
2940 /* If a macro argument with newlines is used multiple times,
2941 then only expand the newlines once. This avoids creating
2942 output lines which don't correspond to any input line,
2943 which confuses gdb and gcov. */
2944 if (arg->use_count > 1 && arg->newlines > 0)
2945 {
2946 /* Don't bother doing change_newlines for subsequent
2947 uses of arg. */
2948 arg->use_count = 1;
2949 arg->expand_length
2950 = change_newlines (expanded, arg->expand_length);
2951 }
2952 }
2953
2954 if (totlen > xbuf_len)
2955 abort ();
2956 }
2957
2958 /* if there is anything left of the definition
2959 after handling the arg list, copy that in too. */
2960
2961 for (i = offset; i < defn->length; i++)
2962 {
2963 /* if we've reached the end of the macro */
2964 if (exp[i] == ')')
2965 rest_zero = 0;
2966 if (! (rest_zero && last_ap != NULL && last_ap->rest_args
2967 && last_ap->raw_after))
2968 xbuf[totlen++] = exp[i];
2969 }
2970
2971 xbuf[totlen] = 0;
2972 xbuf_len = totlen;
2973
2974 }
2975
782331f4
PB
2976 pfile->output_escapes--;
2977
7f2935c7
PB
2978 /* Now put the expansion on the input stack
2979 so our caller will commence reading from it. */
2980 push_macro_expansion (pfile, xbuf, xbuf_len, hp);
2981 CPP_BUFFER (pfile)->has_escapes = 1;
2982
2983 /* Pop the space we've used in the token_buffer for argument expansion. */
2984 CPP_SET_WRITTEN (pfile, old_written);
2985
2986 /* Recursive macro use sometimes works traditionally.
2987 #define foo(x,y) bar (x (y,0), y)
2988 foo (foo, baz) */
2989
2990 if (!CPP_TRADITIONAL (pfile))
2991 hp->type = T_DISABLED;
2992}
2993
2994static void
2995push_macro_expansion (pfile, xbuf, xbuf_len, hp)
2996 cpp_reader *pfile;
2997 register U_CHAR *xbuf;
2998 int xbuf_len;
2999 HASHNODE *hp;
3000{
3001 register cpp_buffer *mbuf = cpp_push_buffer (pfile, xbuf, xbuf_len);
e2f79f3c
PB
3002 if (mbuf == NULL)
3003 return;
7f2935c7
PB
3004 mbuf->cleanup = macro_cleanup;
3005 mbuf->data = hp;
3006
782331f4 3007 /* The first chars of the expansion should be a "@ " added by
7f2935c7
PB
3008 collect_expansion. This is to prevent accidental token-pasting
3009 between the text preceding the macro invocation, and the macro
3010 expansion text.
3011
3012 We would like to avoid adding unneeded spaces (for the sake of
3013 tools that use cpp, such as imake). In some common cases we can
3014 tell that it is safe to omit the space.
3015
3016 The character before the macro invocation cannot have been an
3017 idchar (or else it would have been pasted with the idchars of
3018 the macro name). Therefore, if the first non-space character
3019 of the expansion is an idchar, we do not need the extra space
3020 to prevent token pasting.
3021
3022 Also, we don't need the extra space if the first char is '(',
3023 or some other (less common) characters. */
3024
782331f4
PB
3025 if (xbuf[0] == '@' && xbuf[1] == ' '
3026 && (is_idchar[xbuf[2]] || xbuf[2] == '(' || xbuf[2] == '\''
3027 || xbuf[2] == '\"'))
3028 mbuf->cur += 2;
7f2935c7
PB
3029}
3030\f
3031/* Like cpp_get_token, except that it does not read past end-of-line.
3032 Also, horizontal space is skipped, and macros are popped. */
3033
3034static enum cpp_token
3035get_directive_token (pfile)
3036 cpp_reader *pfile;
3037{
3038 for (;;)
3039 {
3040 long old_written = CPP_WRITTEN (pfile);
3041 enum cpp_token token;
3042 cpp_skip_hspace (pfile);
3043 if (PEEKC () == '\n')
3044 return CPP_VSPACE;
3045 token = cpp_get_token (pfile);
3046 switch (token)
3047 {
3048 case CPP_POP:
3049 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
3050 return token;
3051 /* ... else fall though ... */
3052 case CPP_HSPACE: case CPP_COMMENT:
3053 CPP_SET_WRITTEN (pfile, old_written);
3054 break;
3055 default:
3056 return token;
3057 }
3058 }
3059}
3060\f
3061/* Handle #include and #import.
3062 This function expects to see "fname" or <fname> on the input.
3063
3064 The input is normally in part of the output_buffer following
ddd5a7c1 3065 CPP_WRITTEN, and will get overwritten by output_line_command.
7f2935c7
PB
3066 I.e. in input file specification has been popped by handle_directive.
3067 This is safe. */
3068
3069static int
3070do_include (pfile, keyword, unused1, unused2)
3071 cpp_reader *pfile;
3072 struct directive *keyword;
3073 U_CHAR *unused1, *unused2;
3074{
3075 int importing = (keyword->type == T_IMPORT);
3076 int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
3077 char *fname; /* Dynamically allocated fname buffer */
3078 char *pcftry;
3079 char *pcfname;
3080 U_CHAR *fbeg, *fend; /* Beginning and end of fname */
3081 enum cpp_token token;
3082
3083 /* Chain of dirs to search */
3084 struct file_name_list *search_start = CPP_OPTIONS (pfile)->include;
3085 struct file_name_list dsp[1]; /* First in chain, if #include "..." */
3086 struct file_name_list *searchptr = 0;
3087 long old_written = CPP_WRITTEN (pfile);
3088
3089 int flen;
3090
3091 int f; /* file number */
3092
3093 int retried = 0; /* Have already tried macro
3094 expanding the include line*/
3095 int angle_brackets = 0; /* 0 for "...", 1 for <...> */
3096 int pcf = -1;
3097 char *pcfbuf;
6be492ab 3098 char *pcfbuflimit;
7f2935c7
PB
3099 int pcfnum;
3100 f= -1; /* JF we iz paranoid! */
3101
3102 if (importing && CPP_OPTIONS (pfile)->warn_import
3103 && !CPP_OPTIONS (pfile)->inhibit_warnings
3104 && !CPP_BUFFER (pfile)->system_header_p && !pfile->import_warning)
3105 {
3106 pfile->import_warning = 1;
3107 cpp_warning (pfile, "using `#import' is not recommended");
3108 fprintf (stderr, "The fact that a certain header file need not be processed more than once\n");
3109 fprintf (stderr, "should be indicated in the header file, not where it is used.\n");
3110 fprintf (stderr, "The best way to do this is with a conditional of this form:\n\n");
3111 fprintf (stderr, " #ifndef _FOO_H_INCLUDED\n");
3112 fprintf (stderr, " #define _FOO_H_INCLUDED\n");
3113 fprintf (stderr, " ... <real contents of file> ...\n");
3114 fprintf (stderr, " #endif /* Not _FOO_H_INCLUDED */\n\n");
3115 fprintf (stderr, "Then users can use `#include' any number of times.\n");
3116 fprintf (stderr, "GNU C automatically avoids processing the file more than once\n");
3117 fprintf (stderr, "when it is equipped with such a conditional.\n");
3118 }
3119
3120 pfile->parsing_include_directive++;
3121 token = get_directive_token (pfile);
3122 pfile->parsing_include_directive--;
3123
3124 if (token == CPP_STRING)
3125 {
3126 /* FIXME - check no trailing garbage */
3127 fbeg = pfile->token_buffer + old_written + 1;
3128 fend = CPP_PWRITTEN (pfile) - 1;
3129 if (fbeg[-1] == '<')
3130 {
3131 angle_brackets = 1;
3132 /* If -I-, start with the first -I dir after the -I-. */
3133 if (CPP_OPTIONS (pfile)->first_bracket_include)
3134 search_start = CPP_OPTIONS (pfile)->first_bracket_include;
3135 }
3136 /* If -I- was specified, don't search current dir, only spec'd ones. */
3137 else if (! CPP_OPTIONS (pfile)->ignore_srcdir)
3138 {
d013f05e 3139 cpp_buffer *fp = CPP_BUFFER (pfile);
7f2935c7
PB
3140 /* We have "filename". Figure out directory this source
3141 file is coming from and put it on the front of the list. */
3142
d013f05e 3143 for ( ; fp != CPP_NULL_BUFFER (pfile); fp = CPP_PREV_BUFFER (fp))
7f2935c7
PB
3144 {
3145 int n;
3146 char *ep,*nam;
3147
3148 if ((nam = fp->nominal_fname) != NULL)
3149 {
3150 /* Found a named file. Figure out dir of the file,
3151 and put it in front of the search list. */
3152 dsp[0].next = search_start;
3153 search_start = dsp;
3154#ifndef VMS
3155 ep = rindex (nam, '/');
3156#else /* VMS */
3157 ep = rindex (nam, ']');
3158 if (ep == NULL) ep = rindex (nam, '>');
3159 if (ep == NULL) ep = rindex (nam, ':');
3160 if (ep != NULL) ep++;
3161#endif /* VMS */
3162 if (ep != NULL)
3163 {
3164 n = ep - nam;
3165 dsp[0].fname = (char *) alloca (n + 1);
3166 strncpy (dsp[0].fname, nam, n);
3167 dsp[0].fname[n] = '\0';
3168 if (n + INCLUDE_LEN_FUDGE > pfile->max_include_len)
3169 pfile->max_include_len = n + INCLUDE_LEN_FUDGE;
3170 }
3171 else
3172 {
3173 dsp[0].fname = 0; /* Current directory */
3174 }
3175 dsp[0].got_name_map = 0;
3176 break;
3177 }
3178 }
3179 }
3180 }
3181#ifdef VMS
3182 else if (token == CPP_NAME)
3183 {
3184 /*
3185 * Support '#include xyz' like VAX-C to allow for easy use of all the
3186 * decwindow include files. It defaults to '#include <xyz.h>' (so the
3187 * code from case '<' is repeated here) and generates a warning.
3188 */
3189 cpp_warning (pfile,
3190 "VAX-C-style include specification found, use '#include <filename.h>' !");
3191 angle_brackets = 1;
3192 /* If -I-, start with the first -I dir after the -I-. */
3193 if (CPP_OPTIONS (pfile)->first_bracket_include)
3194 search_start = CPP_OPTIONS (pfile)->first_bracket_include;
3195 fbeg = pfile->token_buffer + old_written;
3196 fend = CPP_PWRITTEN (pfile);
3197 }
3198#endif
3199 else
3200 {
3201 cpp_error (pfile,
3202 "`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
3203 CPP_SET_WRITTEN (pfile, old_written);
3204 skip_rest_of_line (pfile);
3205 return 0;
3206 }
3207
3208 *fend = 0;
3209
3210 token = get_directive_token (pfile);
3211 if (token != CPP_VSPACE)
3212 {
3213 cpp_error (pfile, "junk at end of `#include'");
3214 while (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP)
3215 token = get_directive_token (pfile);
3216 }
3217
3218 /* For #include_next, skip in the search path
3219 past the dir in which the containing file was found. */
3220 if (skip_dirs)
3221 {
d013f05e
PB
3222 cpp_buffer *fp = CPP_BUFFER (pfile);
3223 for (; fp != CPP_NULL_BUFFER (pfile); fp = CPP_PREV_BUFFER (fp))
7f2935c7
PB
3224 if (fp->fname != NULL)
3225 {
3226 /* fp->dir is null if the containing file was specified with
3227 an absolute file name. In that case, don't skip anything. */
6bac1e64
PB
3228 if (fp->dir == SELF_DIR_DUMMY)
3229 search_start = CPP_OPTIONS (pfile)->include;
3230 else if (fp->dir)
7f2935c7
PB
3231 search_start = fp->dir->next;
3232 break;
3233 }
3234 }
3235
3236 CPP_SET_WRITTEN (pfile, old_written);
3237
3238 flen = fend - fbeg;
3239
3240 if (flen == 0)
3241 {
3242 cpp_error (pfile, "empty file name in `#%s'", keyword->name);
3243 return 0;
3244 }
3245
3246 /* Allocate this permanently, because it gets stored in the definitions
3247 of macros. */
3248 fname = (char *) xmalloc (pfile->max_include_len + flen + 4);
3249 /* + 2 above for slash and terminating null. */
3250 /* + 2 added for '.h' on VMS (to support '#include filename') */
3251
3252 /* If specified file name is absolute, just open it. */
3253
3254 if (*fbeg == '/') {
3255 strncpy (fname, fbeg, flen);
3256 fname[flen] = 0;
3257 if (redundant_include_p (pfile, fname))
3258 return 0;
3259 if (importing)
3260 f = lookup_import (pfile, fname, NULL_PTR);
3261 else
782331f4 3262 f = open_include_file (pfile, fname, NULL_PTR);
7f2935c7
PB
3263 if (f == -2)
3264 return 0; /* Already included this file */
3265 } else {
3266 /* Search directory path, trying to open the file.
3267 Copy each filename tried into FNAME. */
3268
3269 for (searchptr = search_start; searchptr; searchptr = searchptr->next) {
3270 if (searchptr->fname) {
3271 /* The empty string in a search path is ignored.
3272 This makes it possible to turn off entirely
3273 a standard piece of the list. */
3274 if (searchptr->fname[0] == 0)
3275 continue;
3276 strcpy (fname, searchptr->fname);
3277 strcat (fname, "/");
3278 fname[strlen (fname) + flen] = 0;
3279 } else {
3280 fname[0] = 0;
3281 }
3282 strncat (fname, fbeg, flen);
3283#ifdef VMS
3284 /* Change this 1/2 Unix 1/2 VMS file specification into a
3285 full VMS file specification */
3286 if (searchptr->fname && (searchptr->fname[0] != 0)) {
3287 /* Fix up the filename */
3288 hack_vms_include_specification (fname);
3289 } else {
3290 /* This is a normal VMS filespec, so use it unchanged. */
3291 strncpy (fname, fbeg, flen);
3292 fname[flen] = 0;
3293 /* if it's '#include filename', add the missing .h */
3294 if (index(fname,'.')==NULL) {
3295 strcat (fname, ".h");
3296 }
3297 }
3298#endif /* VMS */
6be492ab
PB
3299 /* ??? There are currently 3 separate mechanisms for avoiding processing
3300 of redundant include files: #import, #pragma once, and
3301 redundant_include_p. It would be nice if they were unified. */
3302 if (redundant_include_p (pfile, fname))
3303 return 0;
7f2935c7
PB
3304 if (importing)
3305 f = lookup_import (pfile, fname, searchptr);
3306 else
782331f4 3307 f = open_include_file (pfile, fname, searchptr);
7f2935c7
PB
3308 if (f == -2)
3309 return 0; /* Already included this file */
3310#ifdef EACCES
3311 else if (f == -1 && errno == EACCES)
3312 cpp_warning (pfile, "Header file %s exists, but is not readable",
3313 fname);
3314#endif
7f2935c7
PB
3315 if (f >= 0)
3316 break;
3317 }
3318 }
3319
3320 if (f < 0)
3321 {
3322 /* A file that was not found. */
3323 strncpy (fname, fbeg, flen);
3324 fname[flen] = 0;
3325 /* If generating dependencies and -MG was specified, we assume missing
3326 files are leaf files, living in the same directory as the source file
3327 or other similar place; these missing files may be generated from
3328 other files and may not exist yet (eg: y.tab.h). */
3329
3330 if (CPP_OPTIONS(pfile)->print_deps_missing_files
3331 && CPP_PRINT_DEPS (pfile)
3332 > (angle_brackets || (pfile->system_include_depth > 0)))
3333 {
3334 /* If it was requested as a system header file,
3335 then assume it belongs in the first place to look for such. */
3336 if (angle_brackets)
3337 {
3338 for (searchptr = search_start; searchptr;
3339 searchptr = searchptr->next)
3340 {
3341 if (searchptr->fname)
3342 {
3343 char *p;
3344
3345 if (searchptr->fname[0] == 0)
3346 continue;
e8037d57
PB
3347 p = (char *) alloca (strlen (searchptr->fname)
3348 + strlen (fname) + 2);
7f2935c7
PB
3349 strcpy (p, searchptr->fname);
3350 strcat (p, "/");
3351 strcat (p, fname);
3352 deps_output (pfile, p, ' ');
3353 break;
3354 }
3355 }
3356 }
3357 else
3358 {
3359 /* Otherwise, omit the directory, as if the file existed
3360 in the directory with the source. */
3361 deps_output (pfile, fname, ' ');
3362 }
3363 }
3364 /* If -M was specified, and this header file won't be added to the
3365 dependency list, then don't count this as an error, because we can
3366 still produce correct output. Otherwise, we can't produce correct
3367 output, because there may be dependencies we need inside the missing
3368 file, and we don't know what directory this missing file exists in.*/
3369 else if (CPP_PRINT_DEPS (pfile)
3370 && (CPP_PRINT_DEPS (pfile)
3371 <= (angle_brackets || (pfile->system_include_depth > 0))))
3372 cpp_warning (pfile, "No include path in which to find %s", fname);
3373 else if (search_start)
3374 cpp_error_from_errno (pfile, fname);
3375 else
3376 cpp_error (pfile, "No include path in which to find %s", fname);
3377 }
3378 else {
7f2935c7
PB
3379 /* Check to see if this include file is a once-only include file.
3380 If so, give up. */
3381
3382 struct file_name_list* ptr;
3383
3384 for (ptr = pfile->dont_repeat_files; ptr; ptr = ptr->next) {
3385 if (!strcmp (ptr->fname, fname)) {
3386 close (f);
3387 return 0; /* This file was once'd. */
3388 }
3389 }
3390
3391 for (ptr = pfile->all_include_files; ptr; ptr = ptr->next) {
3392 if (!strcmp (ptr->fname, fname))
3393 break; /* This file was included before. */
3394 }
3395
3396 if (ptr == 0) {
3397 /* This is the first time for this file. */
3398 /* Add it to list of files included. */
3399
3400 ptr = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
3401 ptr->control_macro = 0;
3402 ptr->c_system_include_path = 0;
3403 ptr->next = pfile->all_include_files;
3404 pfile->all_include_files = ptr;
3405 ptr->fname = savestring (fname);
3406 ptr->got_name_map = 0;
3407
3408 /* For -M, add this file to the dependencies. */
3409 if (CPP_PRINT_DEPS (pfile)
3410 > (angle_brackets || (pfile->system_include_depth > 0)))
3411 deps_output (pfile, fname, ' ');
3412 }
3413
3414 /* Handle -H option. */
3415 if (CPP_OPTIONS(pfile)->print_include_names)
3416 {
3417 cpp_buffer *buf = CPP_BUFFER (pfile);
d013f05e 3418 while ((buf = CPP_PREV_BUFFER (buf)) != CPP_NULL_BUFFER (pfile))
7f2935c7
PB
3419 putc ('.', stderr);
3420 fprintf (stderr, "%s\n", fname);
3421 }
3422
3423 if (angle_brackets)
3424 pfile->system_include_depth++;
3425
3426 /* Actually process the file. */
3427
3428 /* Record file on "seen" list for #import. */
3429 add_import (pfile, f, fname);
3430
3431 pcftry = (char *) alloca (strlen (fname) + 30);
3432 pcfbuf = 0;
3433 pcfnum = 0;
3434
7f2935c7
PB
3435#if 0
3436 if (!no_precomp)
6be492ab
PB
3437 {
3438 struct stat stat_f;
3439
3440 fstat (f, &stat_f);
3441
3442 do {
3443 sprintf (pcftry, "%s%d", fname, pcfnum++);
3444
3445 pcf = open (pcftry, O_RDONLY, 0666);
3446 if (pcf != -1)
3447 {
3448 struct stat s;
3449
3450 fstat (pcf, &s);
3451 if (bcmp ((char *) &stat_f.st_ino, (char *) &s.st_ino,
3452 sizeof (s.st_ino))
3453 || stat_f.st_dev != s.st_dev)
3454 {
3455 pcfbuf = check_precompiled (pcf, fname, &pcfbuflimit);
3456 /* Don't need it any more. */
3457 close (pcf);
3458 }
3459 else
3460 {
3461 /* Don't need it at all. */
3462 close (pcf);
3463 break;
3464 }
3465 }
3466 } while (pcf != -1 && !pcfbuf);
3467 }
7f2935c7
PB
3468#endif
3469
3470 /* Actually process the file */
e2f79f3c
PB
3471 if (cpp_push_buffer (pfile, NULL, 0) == NULL)
3472 return 0;
7f2935c7 3473 if (finclude (pfile, f, fname, is_system_include (pfile, fname),
6bac1e64 3474 searchptr != dsp ? searchptr : SELF_DIR_DUMMY))
7f2935c7
PB
3475 {
3476 output_line_command (pfile, 0, enter_file);
3477 pfile->only_seen_white = 2;
3478 }
3479
3480 if (angle_brackets)
3481 pfile->system_include_depth--;
3482 }
3483 return 0;
3484}
3485
3486/* Return nonzero if there is no need to include file NAME
3487 because it has already been included and it contains a conditional
3488 to make a repeated include do nothing. */
3489
3490static int
3491redundant_include_p (pfile, name)
3492 cpp_reader *pfile;
3493 char *name;
3494{
3495 struct file_name_list *l = pfile->all_include_files;
3496 for (; l; l = l->next)
3497 if (! strcmp (name, l->fname)
3498 && l->control_macro
3499 && cpp_lookup (pfile, l->control_macro, -1, -1))
3500 return 1;
3501 return 0;
3502}
3503
3504/* Return nonzero if the given FILENAME is an absolute pathname which
3505 designates a file within one of the known "system" include file
3506 directories. We assume here that if the given FILENAME looks like
3507 it is the name of a file which resides either directly in a "system"
3508 include file directory, or within any subdirectory thereof, then the
3509 given file must be a "system" include file. This function tells us
3510 if we should suppress pedantic errors/warnings for the given FILENAME.
3511
3512 The value is 2 if the file is a C-language system header file
3513 for which C++ should (on most systems) assume `extern "C"'. */
3514
3515static int
3516is_system_include (pfile, filename)
3517 cpp_reader *pfile;
3518 register char *filename;
3519{
3520 struct file_name_list *searchptr;
3521
3522 for (searchptr = CPP_OPTIONS (pfile)->first_system_include; searchptr;
3523 searchptr = searchptr->next)
3524 if (searchptr->fname) {
3525 register char *sys_dir = searchptr->fname;
3526 register unsigned length = strlen (sys_dir);
3527
3528 if (! strncmp (sys_dir, filename, length) && filename[length] == '/')
3529 {
3530 if (searchptr->c_system_include_path)
3531 return 2;
3532 else
3533 return 1;
3534 }
3535 }
3536 return 0;
3537}
3538
3539\f
3540/*
3541 * Install a name in the assertion hash table.
3542 *
3543 * If LEN is >= 0, it is the length of the name.
3544 * Otherwise, compute the length by scanning the entire name.
3545 *
3546 * If HASH is >= 0, it is the precomputed hash code.
3547 * Otherwise, compute the hash code.
3548 */
3549static ASSERTION_HASHNODE *
3550assertion_install (pfile, name, len, hash)
3551 cpp_reader *pfile;
3552 U_CHAR *name;
3553 int len;
3554 int hash;
3555{
3556 register ASSERTION_HASHNODE *hp;
3557 register int i, bucket;
3558 register U_CHAR *p, *q;
3559
3560 i = sizeof (ASSERTION_HASHNODE) + len + 1;
3561 hp = (ASSERTION_HASHNODE *) xmalloc (i);
3562 bucket = hash;
3563 hp->bucket_hdr = &pfile->assertion_hashtab[bucket];
3564 hp->next = pfile->assertion_hashtab[bucket];
3565 pfile->assertion_hashtab[bucket] = hp;
3566 hp->prev = NULL;
3567 if (hp->next != NULL)
3568 hp->next->prev = hp;
3569 hp->length = len;
3570 hp->value = 0;
3571 hp->name = ((U_CHAR *) hp) + sizeof (ASSERTION_HASHNODE);
3572 p = hp->name;
3573 q = name;
3574 for (i = 0; i < len; i++)
3575 *p++ = *q++;
3576 hp->name[len] = 0;
3577 return hp;
3578}
3579/*
3580 * find the most recent hash node for name name (ending with first
3581 * non-identifier char) installed by install
3582 *
3583 * If LEN is >= 0, it is the length of the name.
3584 * Otherwise, compute the length by scanning the entire name.
3585 *
3586 * If HASH is >= 0, it is the precomputed hash code.
3587 * Otherwise, compute the hash code.
3588 */
3589
3590static ASSERTION_HASHNODE *
3591assertion_lookup (pfile, name, len, hash)
3592 cpp_reader *pfile;
3593 U_CHAR *name;
3594 int len;
3595 int hash;
3596{
3597 register ASSERTION_HASHNODE *bucket;
3598
3599 bucket = pfile->assertion_hashtab[hash];
3600 while (bucket) {
3601 if (bucket->length == len && strncmp (bucket->name, name, len) == 0)
3602 return bucket;
3603 bucket = bucket->next;
3604 }
3605 return NULL;
3606}
3607
3608static void
3609delete_assertion (hp)
3610 ASSERTION_HASHNODE *hp;
3611{
782331f4 3612 struct tokenlist_list *tail;
7f2935c7
PB
3613 if (hp->prev != NULL)
3614 hp->prev->next = hp->next;
3615 if (hp->next != NULL)
3616 hp->next->prev = hp->prev;
3617
782331f4
PB
3618 for (tail = hp->value; tail; )
3619 {
3620 struct tokenlist_list *next = tail->next;
3621 free_token_list (tail->tokens);
3622 free (tail);
3623 tail = next;
3624 }
3625
7f2935c7
PB
3626 /* make sure that the bucket chain header that
3627 the deleted guy was on points to the right thing afterwards. */
3628 if (hp == *hp->bucket_hdr)
3629 *hp->bucket_hdr = hp->next;
3630
3631 free (hp);
3632}
3633\f
3634/* Convert a character string literal into a nul-terminated string.
3635 The input string is [IN ... LIMIT).
3636 The result is placed in RESULT. RESULT can be the same as IN.
3637 The value returned in the end of the string written to RESULT,
3638 or NULL on error. */
3639
3640static U_CHAR*
3641convert_string (pfile, result, in, limit, handle_escapes)
3642 cpp_reader *pfile;
3643 register U_CHAR *result, *in, *limit;
3644 int handle_escapes;
3645{
3646 U_CHAR c;
3647 c = *in++;
3648 if (c != '\"')
3649 return NULL;
3650 while (in < limit)
3651 {
3652 U_CHAR c = *in++;
3653 switch (c)
3654 {
3655 case '\0':
3656 return NULL;
3657 case '\"':
3658 limit = in;
3659 break;
3660 case '\\':
3661 if (handle_escapes)
3662 {
3663 char *bpc = (char *) in;
3664 int i = (U_CHAR) cpp_parse_escape (pfile, &bpc);
3665 in = (U_CHAR *) bpc;
3666 if (i >= 0)
3667 *result++ = (U_CHAR)c;
3668 break;
3669 }
3670 /* else fall through */
3671 default:
3672 *result++ = c;
3673 }
3674 }
3675 *result = 0;
3676 return result;
3677}
3678
3679/*
3680 * interpret #line command. Remembers previously seen fnames
3681 * in its very own hash table.
3682 */
3683#define FNAME_HASHSIZE 37
3684
3685static int
3686do_line (pfile, keyword)
3687 cpp_reader *pfile;
3688 struct directive *keyword;
3689{
3690 cpp_buffer *ip = CPP_BUFFER (pfile);
3691 int new_lineno;
3692 long old_written = CPP_WRITTEN (pfile);
3693 enum file_change_code file_change = same_file;
3694 enum cpp_token token;
3695 int i;
3696
3697 token = get_directive_token (pfile);
3698
3699 if (token != CPP_NUMBER
3700 || !isdigit(pfile->token_buffer[old_written]))
3701 {
3702 cpp_error (pfile, "invalid format `#line' command");
3703 goto bad_line_directive;
3704 }
3705
3706 /* The Newline at the end of this line remains to be processed.
3707 To put the next line at the specified line number,
3708 we must store a line number now that is one less. */
3709 new_lineno = atoi (pfile->token_buffer + old_written) - 1;
3710 CPP_SET_WRITTEN (pfile, old_written);
3711
3712 /* NEW_LINENO is one less than the actual line number here. */
3713 if (CPP_PEDANTIC (pfile) && new_lineno < 0)
3714 cpp_pedwarn (pfile, "line number out of range in `#line' command");
3715
3716#if 0 /* #line 10"foo.c" is supposed to be allowed. */
3717 if (PEEKC() && !is_space[PEEKC()]) {
3718 cpp_error (pfile, "invalid format `#line' command");
3719 goto bad_line_directive;
3720 }
3721#endif
3722
3723 token = get_directive_token (pfile);
3724
3725 if (token == CPP_STRING) {
3726 U_CHAR *fname = pfile->token_buffer + old_written;
3727 U_CHAR *end_name;
3728 static HASHNODE *fname_table[FNAME_HASHSIZE];
3729 HASHNODE *hp, **hash_bucket;
3730 U_CHAR *p;
3731 long num_start;
3732 int fname_length;
3733
3734 /* Turn the file name, which is a character string literal,
3735 into a null-terminated string. Do this in place. */
3736 end_name = convert_string (pfile, fname, fname, CPP_PWRITTEN (pfile), 1);
3737 if (end_name == NULL)
3738 {
3739 cpp_error (pfile, "invalid format `#line' command");
3740 goto bad_line_directive;
3741 }
3742
3743 fname_length = end_name - fname;
3744
3745 num_start = CPP_WRITTEN (pfile);
3746 token = get_directive_token (pfile);
3747 if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP) {
3748 p = pfile->token_buffer + num_start;
3749 if (CPP_PEDANTIC (pfile))
3750 cpp_pedwarn (pfile, "garbage at end of `#line' command");
3751
3752 if (token != CPP_NUMBER || *p < '0' || *p > '4' || p[1] != '\0')
3753 {
3754 cpp_error (pfile, "invalid format `#line' command");
3755 goto bad_line_directive;
3756 }
3757 if (*p == '1')
3758 file_change = enter_file;
3759 else if (*p == 2)
3760 file_change = leave_file;
3761 else if (*p == 3)
3762 ip->system_header_p = 1;
3763 else /* if (*p == 4) */
3764 ip->system_header_p = 2;
3765
3766 CPP_SET_WRITTEN (pfile, num_start);
3767 token = get_directive_token (pfile);
3768 p = pfile->token_buffer + num_start;
3769 if (token == CPP_NUMBER && p[1] == '\0' && (*p == '3' || *p== '4')) {
3770 ip->system_header_p = *p == 3 ? 1 : 2;
3771 token = get_directive_token (pfile);
3772 }
3773 if (token != CPP_VSPACE) {
3774 cpp_error (pfile, "invalid format `#line' command");
3775 goto bad_line_directive;
3776 }
3777 }
3778
3779 hash_bucket =
3780 &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)];
3781 for (hp = *hash_bucket; hp != NULL; hp = hp->next)
3782 if (hp->length == fname_length &&
3783 strncmp (hp->value.cpval, fname, fname_length) == 0) {
3784 ip->nominal_fname = hp->value.cpval;
3785 break;
3786 }
3787 if (hp == 0) {
3788 /* Didn't find it; cons up a new one. */
3789 hp = (HASHNODE *) xcalloc (1, sizeof (HASHNODE) + fname_length + 1);
3790 hp->next = *hash_bucket;
3791 *hash_bucket = hp;
3792
3793 hp->length = fname_length;
3794 ip->nominal_fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE);
3795 bcopy (fname, hp->value.cpval, fname_length);
3796 }
3797 }
3798 else if (token != CPP_VSPACE && token != CPP_EOF) {
3799 cpp_error (pfile, "invalid format `#line' command");
3800 goto bad_line_directive;
3801 }
3802
3803 ip->lineno = new_lineno;
3804 bad_line_directive:
3805 skip_rest_of_line (pfile);
3806 CPP_SET_WRITTEN (pfile, old_written);
3807 output_line_command (pfile, 0, file_change);
3808 return 0;
3809}
3810
3811/*
3812 * remove the definition of a symbol from the symbol table.
3813 * according to un*x /lib/cpp, it is not an error to undef
3814 * something that has no definitions, so it isn't one here either.
3815 */
3816
3817static int
3818do_undef (pfile, keyword, buf, limit)
3819 cpp_reader *pfile;
3820 struct directive *keyword;
3821 U_CHAR *buf, *limit;
3822{
3823 int sym_length;
3824 HASHNODE *hp;
3825 U_CHAR *orig_buf = buf;
3826
3827#if 0
3828 /* If this is a precompiler run (with -pcp) pass thru #undef commands. */
3829 if (pcp_outfile && keyword)
3830 pass_thru_directive (buf, limit, pfile, keyword);
3831#endif
3832
3833 SKIP_WHITE_SPACE (buf);
3834 sym_length = check_macro_name (pfile, buf, "macro");
3835
3836 while ((hp = cpp_lookup (pfile, buf, sym_length, -1)) != NULL)
3837 {
3838 /* If we are generating additional info for debugging (with -g) we
3839 need to pass through all effective #undef commands. */
3840 if (CPP_OPTIONS (pfile)->debug_output && keyword)
3841 pass_thru_directive (orig_buf, limit, pfile, keyword);
3842 if (hp->type != T_MACRO)
3843 cpp_warning (pfile, "undefining `%s'", hp->name);
3844 delete_macro (hp);
3845 }
3846
3847 if (CPP_PEDANTIC (pfile)) {
3848 buf += sym_length;
3849 SKIP_WHITE_SPACE (buf);
3850 if (buf != limit)
3851 cpp_pedwarn (pfile, "garbage after `#undef' directive");
3852 }
3853 return 0;
3854}
3855\f
3856/*
3857 * Report an error detected by the program we are processing.
3858 * Use the text of the line in the error message.
3859 * (We use error because it prints the filename & line#.)
3860 */
3861
3862static int
3863do_error (pfile, keyword, buf, limit)
3864 cpp_reader *pfile;
3865 struct directive *keyword;
3866 U_CHAR *buf, *limit;
3867{
3868 int length = limit - buf;
3869 U_CHAR *copy = (U_CHAR *) xmalloc (length + 1);
3870 bcopy (buf, copy, length);
3871 copy[length] = 0;
3872 SKIP_WHITE_SPACE (copy);
3873 cpp_error (pfile, "#error %s", copy);
3874 return 0;
3875}
3876
3877/*
3878 * Report a warning detected by the program we are processing.
3879 * Use the text of the line in the warning message, then continue.
3880 * (We use error because it prints the filename & line#.)
3881 */
3882
3883static int
3884do_warning (pfile, keyword, buf, limit)
3885 cpp_reader *pfile;
3886 struct directive *keyword;
3887 U_CHAR *buf, *limit;
3888{
3889 int length = limit - buf;
3890 U_CHAR *copy = (U_CHAR *) xmalloc (length + 1);
3891 bcopy (buf, copy, length);
3892 copy[length] = 0;
3893 SKIP_WHITE_SPACE (copy);
3894 cpp_warning (pfile, "#warning %s", copy);
3895 return 0;
3896}
3897
3898/* Remember the name of the current file being read from so that we can
3899 avoid ever including it again. */
3900
3901static int
3902do_once (pfile)
3903 cpp_reader *pfile;
3904{
3905 cpp_buffer *ip = NULL;
3906 struct file_name_list *new;
3907
3908 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
3909 {
d013f05e 3910 if (ip == CPP_NULL_BUFFER (pfile))
7f2935c7
PB
3911 return 0;
3912 if (ip->fname != NULL)
3913 break;
3914 }
3915
3916
3917 new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
3918 new->next = pfile->dont_repeat_files;
3919 pfile->dont_repeat_files = new;
3920 new->fname = savestring (ip->fname);
3921 new->control_macro = 0;
3922 new->got_name_map = 0;
3923 new->c_system_include_path = 0;
3924
3925 return 0;
3926}
3927
3928/* #ident has already been copied to the output file, so just ignore it. */
3929
3930static int
3931do_ident (pfile, keyword, buf, limit)
3932 cpp_reader *pfile;
3933 struct directive *keyword;
3934 U_CHAR *buf, *limit;
3935{
3936/* long old_written = CPP_WRITTEN (pfile);*/
3937 int len;
3938
3939 /* Allow #ident in system headers, since that's not user's fault. */
3940 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
3941 cpp_pedwarn (pfile, "ANSI C does not allow `#ident'");
3942
3943 /* Leave rest of line to be read by later calls to cpp_get_token. */
3944
3945 return 0;
3946}
3947
3948/* #pragma and its argument line have already been copied to the output file.
3949 Just check for some recognized pragmas that need validation here. */
3950
3951static int
3952do_pragma (pfile, keyword, buf, limit)
3953 cpp_reader *pfile;
3954 struct directive *keyword;
3955 U_CHAR *buf, *limit;
3956{
3957 while (*buf == ' ' || *buf == '\t')
3958 buf++;
3959 if (!strncmp (buf, "once", 4)) {
3960 /* Allow #pragma once in system headers, since that's not the user's
3961 fault. */
3962 if (!CPP_BUFFER (pfile)->system_header_p)
3963 cpp_warning (pfile, "`#pragma once' is obsolete");
3964 do_once (pfile);
3965 }
3966
3967 if (!strncmp (buf, "implementation", 14)) {
3968 /* Be quiet about `#pragma implementation' for a file only if it hasn't
3969 been included yet. */
3970 struct file_name_list *ptr;
3971 U_CHAR *p = buf + 14, *fname, *inc_fname;
3972 int fname_len;
3973 SKIP_WHITE_SPACE (p);
3974 if (*p == '\n' || *p != '\"')
3975 return 0;
3976
3977 fname = p + 1;
3978 p = (U_CHAR *) index (fname, '\"');
3979 fname_len = p != NULL ? p - fname : strlen (fname);
3980
3981 for (ptr = pfile->all_include_files; ptr; ptr = ptr->next) {
3982 inc_fname = (U_CHAR *) rindex (ptr->fname, '/');
3983 inc_fname = inc_fname ? inc_fname + 1 : (U_CHAR *) ptr->fname;
3984 if (inc_fname && !strncmp (inc_fname, fname, fname_len))
3985 cpp_warning (pfile,
3986 "`#pragma implementation' for `%s' appears after file is included",
3987 fname);
3988 }
3989 }
3990
3991 return 0;
3992}
3993
3994#if 0
3995/* This was a fun hack, but #pragma seems to start to be useful.
3996 By failing to recognize it, we pass it through unchanged to cc1. */
3997
3998/*
3999 * the behavior of the #pragma directive is implementation defined.
4000 * this implementation defines it as follows.
4001 */
4002
4003static int
4004do_pragma ()
4005{
4006 close (0);
4007 if (open ("/dev/tty", O_RDONLY, 0666) != 0)
4008 goto nope;
4009 close (1);
4010 if (open ("/dev/tty", O_WRONLY, 0666) != 1)
4011 goto nope;
4012 execl ("/usr/games/hack", "#pragma", 0);
4013 execl ("/usr/games/rogue", "#pragma", 0);
4014 execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0);
4015 execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0);
4016nope:
4017 fatal ("You are in a maze of twisty compiler features, all different");
4018}
4019#endif
4020
4021/* Just ignore #sccs, on systems where we define it at all. */
4022
4023static int
4024do_sccs (pfile, keyword, buf, limit)
4025 cpp_reader *pfile;
4026 struct directive *keyword;
4027 U_CHAR *buf, *limit;
4028{
4029 if (CPP_PEDANTIC (pfile))
4030 cpp_pedwarn (pfile, "ANSI C does not allow `#sccs'");
4031 return 0;
4032}
4033\f
4034/*
4035 * handle #if command by
4036 * 1) inserting special `defined' keyword into the hash table
4037 * that gets turned into 0 or 1 by special_symbol (thus,
4038 * if the luser has a symbol called `defined' already, it won't
4039 * work inside the #if command)
4040 * 2) rescan the input into a temporary output buffer
4041 * 3) pass the output buffer to the yacc parser and collect a value
4042 * 4) clean up the mess left from steps 1 and 2.
4043 * 5) call conditional_skip to skip til the next #endif (etc.),
4044 * or not, depending on the value from step 3.
4045 */
4046
4047static int
4048do_if (pfile, keyword, buf, limit)
4049 cpp_reader *pfile;
4050 struct directive *keyword;
4051 U_CHAR *buf, *limit;
4052{
6be492ab 4053 HOST_WIDE_INT value = eval_if_expression (pfile, buf, limit - buf);
7f2935c7
PB
4054 conditional_skip (pfile, value == 0, T_IF, NULL_PTR);
4055 return 0;
4056}
4057
4058/*
4059 * handle a #elif directive by not changing if_stack either.
4060 * see the comment above do_else.
4061 */
4062
4063static int
4064do_elif (pfile, keyword, buf, limit)
4065 cpp_reader *pfile;
4066 struct directive *keyword;
4067 U_CHAR *buf, *limit;
4068{
7f2935c7
PB
4069 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
4070 cpp_error (pfile, "`#elif' not within a conditional");
4071 return 0;
4072 } else {
4073 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
4074 cpp_error (pfile, "`#elif' after `#else'");
4075#if 0
4076 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
4077#endif
4078 if (pfile->if_stack->fname != NULL && CPP_BUFFER (pfile)->fname != NULL
4079 && strcmp (pfile->if_stack->fname,
4080 CPP_BUFFER (pfile)->nominal_fname) != 0)
4081 fprintf (stderr, ", file %s", pfile->if_stack->fname);
4082 fprintf (stderr, ")\n");
4083 }
4084 pfile->if_stack->type = T_ELIF;
4085 }
4086
4087 if (pfile->if_stack->if_succeeded)
4088 skip_if_group (pfile, 0);
4089 else {
6be492ab 4090 HOST_WIDE_INT value = eval_if_expression (pfile, buf, limit - buf);
7f2935c7
PB
4091 if (value == 0)
4092 skip_if_group (pfile, 0);
4093 else {
4094 ++pfile->if_stack->if_succeeded; /* continue processing input */
4095 output_line_command (pfile, 1, same_file);
4096 }
4097 }
4098 return 0;
4099}
4100
4101/*
4102 * evaluate a #if expression in BUF, of length LENGTH,
4103 * then parse the result as a C expression and return the value as an int.
4104 */
6be492ab 4105static HOST_WIDE_INT
7f2935c7
PB
4106eval_if_expression (pfile, buf, length)
4107 cpp_reader *pfile;
4108 U_CHAR *buf;
4109 int length;
4110{
4111 HASHNODE *save_defined;
6be492ab 4112 HOST_WIDE_INT value;
7f2935c7
PB
4113 long old_written = CPP_WRITTEN (pfile);
4114
4115 save_defined = install ("defined", -1, T_SPEC_DEFINED, 0, 0, -1);
4116 pfile->pcp_inside_if = 1;
4117
4118 value = cpp_parse_expr (pfile);
4119 pfile->pcp_inside_if = 0;
4120 delete_macro (save_defined); /* clean up special symbol */
4121
4122 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
4123
4124 return value;
4125}
4126
4127/*
4128 * routine to handle ifdef/ifndef. Try to look up the symbol,
4129 * then do or don't skip to the #endif/#else/#elif depending
4130 * on what directive is actually being processed.
4131 */
4132
4133static int
4134do_xifdef (pfile, keyword, unused1, unused2)
4135 cpp_reader *pfile;
4136 struct directive *keyword;
4137 U_CHAR *unused1, *unused2;
4138{
4139 int skip;
4140 cpp_buffer *ip = CPP_BUFFER (pfile);
4141 U_CHAR* ident;
4142 int ident_length;
4143 enum cpp_token token;
4144 int start_of_file = 0;
4145 U_CHAR *control_macro = 0;
4146 int old_written = CPP_WRITTEN (pfile);
4147
4148 /* Detect a #ifndef at start of file (not counting comments). */
4149 if (ip->fname != 0 && keyword->type == T_IFNDEF)
4150 start_of_file = pfile->only_seen_white == 2;
4151
4152 pfile->no_macro_expand++;
4153 token = get_directive_token (pfile);
4154 pfile->no_macro_expand--;
4155
4156 ident = pfile->token_buffer + old_written;
4157 ident_length = CPP_WRITTEN (pfile) - old_written;
4158 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
4159
4160 if (token == CPP_VSPACE || token == CPP_POP || token == CPP_EOF)
4161 {
4162 skip = (keyword->type == T_IFDEF);
4163 if (! CPP_TRADITIONAL (pfile))
4164 cpp_pedwarn (pfile, "`#%s' with no argument", keyword->name);
4165 }
4166 else if (token == CPP_NAME)
4167 {
4168 HASHNODE *hp = cpp_lookup (pfile, ident, ident_length, -1);
4169 skip = (hp == NULL) ^ (keyword->type == T_IFNDEF);
4170 if (start_of_file && !skip)
4171 {
4172 control_macro = (U_CHAR *) xmalloc (ident_length + 1);
4173 bcopy (ident, control_macro, ident_length + 1);
4174 }
4175 }
4176 else
4177 {
4178 skip = (keyword->type == T_IFDEF);
4179 if (! CPP_TRADITIONAL (pfile))
4180 cpp_error (pfile, "`#%s' with invalid argument", keyword->name);
4181 }
4182
4183 if (!CPP_TRADITIONAL (pfile))
4184 { int c;
4185 cpp_skip_hspace (pfile);
4186 c = PEEKC ();
4187 if (c != EOF && c != '\n')
4188 cpp_pedwarn (pfile, "garbage at end of `#%s' argument", keyword->name);
4189 }
4190 skip_rest_of_line (pfile);
4191
4192#if 0
4193 if (pcp_outfile) {
4194 /* Output a precondition for this macro. */
4195 if (hp && hp->value.defn->predefined)
4196 fprintf (pcp_outfile, "#define %s\n", hp->name);
4197 else {
4198 U_CHAR *cp = buf;
4199 fprintf (pcp_outfile, "#undef ");
4200 while (is_idchar[*cp]) /* Ick! */
4201 fputc (*cp++, pcp_outfile);
4202 putc ('\n', pcp_outfile);
4203 }
4204#endif
4205
4206 conditional_skip (pfile, skip, T_IF, control_macro);
4207 return 0;
4208}
4209
4210/* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
4211 If this is a #ifndef starting at the beginning of a file,
4212 CONTROL_MACRO is the macro name tested by the #ifndef.
4213 Otherwise, CONTROL_MACRO is 0. */
4214
4215static void
4216conditional_skip (pfile, skip, type, control_macro)
4217 cpp_reader *pfile;
4218 int skip;
4219 enum node_type type;
4220 U_CHAR *control_macro;
4221{
4222 IF_STACK_FRAME *temp;
4223
4224 temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
4225 temp->fname = CPP_BUFFER (pfile)->nominal_fname;
4226#if 0
4227 temp->lineno = CPP_BUFFER (pfile)->lineno;
4228#endif
4229 temp->next = pfile->if_stack;
4230 temp->control_macro = control_macro;
4231 pfile->if_stack = temp;
4232
4233 pfile->if_stack->type = type;
4234
4235 if (skip != 0) {
4236 skip_if_group (pfile, 0);
4237 return;
4238 } else {
4239 ++pfile->if_stack->if_succeeded;
4240 output_line_command (pfile, 1, same_file);
4241 }
4242}
4243
4244/*
4245 * skip to #endif, #else, or #elif. adjust line numbers, etc.
4246 * leaves input ptr at the sharp sign found.
4247 * If ANY is nonzero, return at next directive of any sort.
4248 */
4249static void
4250skip_if_group (pfile, any)
4251 cpp_reader *pfile;
4252 int any;
4253{
4254 int c;
4255 int at_beg_of_line = 1;
4256 struct directive *kt;
4257 IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */
4258#if 0
4259 U_CHAR *beg_of_line = bp;
4260#endif
4261 register int ident_length;
4262 U_CHAR *ident, *after_ident;
4263 struct parse_marker line_start_mark;
4264
4265 parse_set_mark (&line_start_mark, pfile);
4266
4267 if (CPP_OPTIONS (pfile)->output_conditionals) {
4268 static char failed[] = "#failed\n";
4269 CPP_PUTS (pfile, failed, sizeof(failed)-1);
4270 pfile->lineno++;
4271 output_line_command (pfile, 1, same_file);
4272 }
4273
4274 beg_of_line:
4275 if (CPP_OPTIONS (pfile)->output_conditionals)
4276 {
4277 cpp_buffer *pbuf = CPP_BUFFER (pfile);
4278 U_CHAR *start_line = pbuf->buf + line_start_mark.position;
4279 CPP_PUTS (pfile, start_line, pbuf->cur - start_line);
4280 }
4281 parse_move_mark (&line_start_mark, pfile);
4282 if (!CPP_TRADITIONAL (pfile))
4283 cpp_skip_hspace (pfile);
4284 c = GETC();
4285 if (c == '#')
4286 {
4287 int old_written = CPP_WRITTEN (pfile);
4288 cpp_skip_hspace (pfile);
4289
4290 parse_name (pfile, GETC());
4291 ident_length = CPP_WRITTEN (pfile) - old_written;
4292 ident = pfile->token_buffer + old_written;
4293 pfile->limit = ident;
4294#if 0
4295 if (ident_length == 0)
4296 goto not_a_directive;
4297
4298 /* Handle # followed by a line number. */
4299
4300 /* Avoid error for `###' and similar cases unless -pedantic. */
4301#endif
4302
4303 for (kt = directive_table; kt->length >= 0; kt++)
4304 {
4305 IF_STACK_FRAME *temp;
4306 if (ident_length == kt->length
4307 && strncmp (ident, kt->name, kt->length) == 0)
4308 {
4309 /* If we are asked to return on next directive, do so now. */
4310 if (any)
4311 goto done;
4312
4313 switch (kt->type)
4314 {
4315 case T_IF:
4316 case T_IFDEF:
4317 case T_IFNDEF:
4318 temp
4319 = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
4320 temp->next = pfile->if_stack;
4321 pfile->if_stack = temp;
4322#if 0
4323 temp->lineno = CPP_BUFFER(pfile)->lineno;
4324#endif
4325 temp->fname = CPP_BUFFER(pfile)->nominal_fname;
4326 temp->type = kt->type;
4327 break;
4328 case T_ELSE:
4329 case T_ENDIF:
4330 if (CPP_PEDANTIC (pfile) && pfile->if_stack != save_if_stack)
4331 validate_else (pfile,
4332 kt->type == T_ELSE ? "#else" : "#endif");
4333 case T_ELIF:
4334 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
4335 {
4336 cpp_error (pfile,
4337 "`#%s' not within a conditional", kt->name);
4338 break;
4339 }
4340 else if (pfile->if_stack == save_if_stack)
4341 goto done; /* found what we came for */
4342
4343 if (kt->type != T_ENDIF)
4344 {
4345 if (pfile->if_stack->type == T_ELSE)
4346 cpp_error (pfile, "`#else' or `#elif' after `#else'");
4347 pfile->if_stack->type = kt->type;
4348 break;
4349 }
4350
4351 temp = pfile->if_stack;
4352 pfile->if_stack = temp->next;
4353 free (temp);
4354 break;
4355 default: ;
4356 }
4357 break;
4358 }
4359 /* Don't let erroneous code go by. */
4360 if (kt->length < 0 && !CPP_OPTIONS (pfile)->lang_asm
4361 && CPP_PEDANTIC (pfile))
4362 cpp_pedwarn (pfile, "invalid preprocessor directive name");
4363 }
4364 c = GETC ();
4365 }
4366 /* We're in the middle of a line. Skip the rest of it. */
4367 for (;;) {
4368 switch (c)
4369 {
3232050c 4370 long old;
7f2935c7
PB
4371 case EOF:
4372 goto done;
4373 case '/': /* possible comment */
4374 c = skip_comment (pfile, NULL);
4375 if (c == EOF)
4376 goto done;
4377 break;
4378 case '\"':
4379 case '\'':
3232050c
PB
4380 FORWARD(-1);
4381 old = CPP_WRITTEN (pfile);
4382 cpp_get_token (pfile);
4383 CPP_SET_WRITTEN (pfile, old);
7f2935c7
PB
4384 break;
4385 case '\\':
4386 /* Char after backslash loses its special meaning. */
4387 if (PEEKC() == '\n')
4388 FORWARD (1);
4389 break;
4390 case '\n':
4391 goto beg_of_line;
4392 break;
4393 }
4394 c = GETC ();
4395 }
4396 done:
4397 if (CPP_OPTIONS (pfile)->output_conditionals) {
4398 static char end_failed[] = "#endfailed\n";
4399 CPP_PUTS (pfile, end_failed, sizeof(end_failed)-1);
4400 pfile->lineno++;
4401 }
4402 pfile->only_seen_white = 1;
4403 parse_goto_mark (&line_start_mark, pfile);
4404 parse_clear_mark (&line_start_mark);
4405}
4406
4407/*
4408 * handle a #else directive. Do this by just continuing processing
4409 * without changing if_stack ; this is so that the error message
4410 * for missing #endif's etc. will point to the original #if. It
4411 * is possible that something different would be better.
4412 */
4413
4414static int
4415do_else (pfile, keyword, buf, limit)
4416 cpp_reader *pfile;
4417 struct directive *keyword;
4418 U_CHAR *buf, *limit;
4419{
4420 cpp_buffer *ip = CPP_BUFFER (pfile);
4421
4422 if (CPP_PEDANTIC (pfile))
4423 validate_else (pfile, "#else");
4424 skip_rest_of_line (pfile);
4425
4426 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
4427 cpp_error (pfile, "`#else' not within a conditional");
4428 return 0;
4429 } else {
4430 /* #ifndef can't have its special treatment for containing the whole file
4431 if it has a #else clause. */
4432 pfile->if_stack->control_macro = 0;
4433
4434 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
4435 cpp_error (pfile, "`#else' after `#else'");
4436 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
4437 if (strcmp (pfile->if_stack->fname, ip->nominal_fname) != 0)
4438 fprintf (stderr, ", file %s", pfile->if_stack->fname);
4439 fprintf (stderr, ")\n");
4440 }
4441 pfile->if_stack->type = T_ELSE;
4442 }
4443
4444 if (pfile->if_stack->if_succeeded)
4445 skip_if_group (pfile, 0);
4446 else {
4447 ++pfile->if_stack->if_succeeded; /* continue processing input */
4448 output_line_command (pfile, 1, same_file);
4449 }
4450 return 0;
4451}
4452
4453/*
4454 * unstack after #endif command
4455 */
4456
4457static int
4458do_endif (pfile, keyword, buf, limit)
4459 cpp_reader *pfile;
4460 struct directive *keyword;
4461 U_CHAR *buf, *limit;
4462{
4463 if (CPP_PEDANTIC (pfile))
4464 validate_else (pfile, "#endif");
4465 skip_rest_of_line (pfile);
4466
4467 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
4468 cpp_error (pfile, "unbalanced `#endif'");
4469 else
4470 {
4471 IF_STACK_FRAME *temp = pfile->if_stack;
4472 pfile->if_stack = temp->next;
4473 if (temp->control_macro != 0)
4474 {
4475 /* This #endif matched a #ifndef at the start of the file.
4476 See if it is at the end of the file. */
4477 struct parse_marker start_mark;
4478 int c;
4479
4480 parse_set_mark (&start_mark, pfile);
4481
4482 for (;;)
4483 {
4484 cpp_skip_hspace (pfile);
4485 c = GETC ();
4486 if (c != '\n')
4487 break;
4488 }
4489 parse_goto_mark (&start_mark, pfile);
4490 parse_clear_mark (&start_mark);
4491
4492 if (c == EOF)
4493 {
4494 /* If we get here, this #endif ends a #ifndef
4495 that contains all of the file (aside from whitespace).
4496 Arrange not to include the file again
4497 if the macro that was tested is defined.
4498
4499 Do not do this for the top-level file in a -include or any
4500 file in a -imacros. */
4501#if 0
4502FIXME!
4503 if (indepth != 0
4504 && ! (indepth == 1 && pfile->no_record_file)
4505 && ! (pfile->no_record_file && no_output))
4506#endif
4507 {
4508 struct file_name_list *ifile = pfile->all_include_files;
4509
4510 for ( ; ifile != NULL; ifile = ifile->next)
4511 {
4512 if (!strcmp (ifile->fname, CPP_BUFFER (pfile)->fname))
4513 {
4514 ifile->control_macro = temp->control_macro;
4515 break;
4516 }
4517 }
4518 }
4519 }
4520 }
4521 free (temp);
4522 output_line_command (pfile, 1, same_file);
4523 }
4524 return 0;
4525}
4526
4527/* When an #else or #endif is found while skipping failed conditional,
4528 if -pedantic was specified, this is called to warn about text after
4529 the command name. P points to the first char after the command name. */
4530
4531static void
4532validate_else (pfile, directive)
4533 cpp_reader *pfile;
4534 char *directive;
4535{
4536 int c;
4537 cpp_skip_hspace (pfile);
4538 c = PEEKC ();
4539 if (c != EOF && c != '\n')
4540 cpp_pedwarn (pfile,
4541 "text following `%s' violates ANSI standard", directive);
4542}
4543
22bbceaf 4544/* Get the next token, and add it to the text in pfile->token_buffer.
7f2935c7
PB
4545 Return the kind of token we got. */
4546
4547
4548enum cpp_token
4549cpp_get_token (pfile)
4550 cpp_reader *pfile;
4551{
4552 register int c, c2, c3;
4553 long old_written;
3232050c 4554 long start_line, start_column;
7f2935c7
PB
4555 enum cpp_token token;
4556 struct cpp_options *opts = CPP_OPTIONS (pfile);
4557 CPP_BUFFER (pfile)->prev = CPP_BUFFER (pfile)->cur;
4558 get_next:
4559 c = GETC();
4560 if (c == EOF)
4561 {
4562 handle_eof:
4563 if (CPP_BUFFER (pfile)->seen_eof)
4564 {
4565 if (cpp_pop_buffer (pfile) != CPP_NULL_BUFFER (pfile))
4566 goto get_next;
4567 else
4568 return CPP_EOF;
4569 }
4570 else
4571 {
4572 cpp_buffer *next_buf
4573 = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
4574 CPP_BUFFER (pfile)->seen_eof = 1;
d013f05e
PB
4575 if (CPP_BUFFER (pfile)->nominal_fname
4576 && next_buf != CPP_NULL_BUFFER (pfile))
7f2935c7
PB
4577 {
4578 /* We're about to return from an #include file.
ddd5a7c1 4579 Emit #line information now (as part of the CPP_POP) result.
7f2935c7
PB
4580 But the #line refers to the file we will pop to. */
4581 cpp_buffer *cur_buffer = CPP_BUFFER (pfile);
4582 CPP_BUFFER (pfile) = next_buf;
4583 pfile->input_stack_listing_current = 0;
4584 output_line_command (pfile, 0, leave_file);
4585 CPP_BUFFER (pfile) = cur_buffer;
4586 }
4587 return CPP_POP;
4588 }
4589 }
4590 else
4591 {
4592 switch (c)
4593 {
4594 long newlines;
4595 struct parse_marker start_mark;
4596 case '/':
4597 if (PEEKC () == '=')
4598 goto op2;
4599 if (opts->put_out_comments)
4600 parse_set_mark (&start_mark, pfile);
4601 newlines = 0;
3232050c
PB
4602 cpp_buf_line_and_col (cpp_file_buffer (pfile),
4603 &start_line, &start_column);
7f2935c7
PB
4604 c = skip_comment (pfile, &newlines);
4605 if (opts->put_out_comments && (c == '/' || c == EOF))
4606 parse_clear_mark (&start_mark);
4607 if (c == '/')
4608 goto randomchar;
4609 if (c == EOF)
4610 {
3232050c 4611 cpp_error_with_line (pfile, start_line, start_column,
7f2935c7
PB
4612 "unterminated comment");
4613 goto handle_eof;
4614 }
4615 c = '/'; /* Initial letter of comment. */
4616 return_comment:
4617 /* Comments are equivalent to spaces.
4618 For -traditional, a comment is equivalent to nothing. */
4619 if (opts->put_out_comments)
4620 {
4621 cpp_buffer *pbuf = CPP_BUFFER (pfile);
4622 long dummy;
4623 U_CHAR *start = pbuf->buf + start_mark.position;
4624 int len = pbuf->cur - start;
4625 CPP_RESERVE(pfile, 1 + len);
4626 CPP_PUTC_Q (pfile, c);
4627 CPP_PUTS_Q (pfile, start, len);
4628 pfile->lineno += newlines;
4629 parse_clear_mark (&start_mark);
4630 return CPP_COMMENT;
4631 }
4632 else if (CPP_TRADITIONAL (pfile))
355142da
PB
4633 {
4634 return CPP_COMMENT;
4635 }
7f2935c7
PB
4636 else
4637 {
4638#if 0
4639 /* This may not work if cpp_get_token is called recursively,
4640 since many places look for horizontal space. */
4641 if (newlines)
4642 {
4643 /* Copy the newlines into the output buffer, in order to
4644 avoid the pain of a #line every time a multiline comment
4645 is seen. */
4646 CPP_RESERVE(pfile, newlines);
4647 while (--newlines >= 0)
4648 {
4649 CPP_PUTC_Q (pfile, '\n');
4650 pfile->lineno++;
4651 }
4652 return CPP_VSPACE;
4653 }
4654#endif
4655 CPP_RESERVE(pfile, 1);
4656 CPP_PUTC_Q (pfile, ' ');
4657 return CPP_HSPACE;
4658 }
7f2935c7 4659#if 0
782331f4 4660 if (opts->for_lint) {
7f2935c7
PB
4661 U_CHAR *argbp;
4662 int cmdlen, arglen;
4663 char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen);
4664
4665 if (lintcmd != NULL) {
4666 /* I believe it is always safe to emit this newline: */
4667 obp[-1] = '\n';
4668 bcopy ("#pragma lint ", (char *) obp, 13);
4669 obp += 13;
4670 bcopy (lintcmd, (char *) obp, cmdlen);
4671 obp += cmdlen;
4672
4673 if (arglen != 0) {
4674 *(obp++) = ' ';
4675 bcopy (argbp, (char *) obp, arglen);
4676 obp += arglen;
4677 }
4678
4679 /* OK, now bring us back to the state we were in before we entered
4680 this branch. We need #line b/c the newline for the pragma
4681 could fuck things up. */
4682 output_line_command (pfile, 0, same_file);
4683 *(obp++) = ' '; /* just in case, if comments are copied thru */
4684 *(obp++) = '/';
4685 }
7f2935c7 4686 }
782331f4 4687#endif
7f2935c7
PB
4688
4689 case '#':
4690#if 0
4691 /* If this is expanding a macro definition, don't recognize
4692 preprocessor directives. */
4693 if (ip->macro != 0)
4694 goto randomchar;
4695 /* If this is expand_into_temp_buffer, recognize them
4696 only after an actual newline at this level,
4697 not at the beginning of the input level. */
4698 if (ip->fname == 0 && beg_of_line == ip->buf)
4699 goto randomchar;
4700 if (ident_length)
4701 goto specialchar;
4702#endif
4703
4704 if (!pfile->only_seen_white)
4705 goto randomchar;
4706 if (handle_directive (pfile))
4707 return CPP_DIRECTIVE;
4708 pfile->only_seen_white = 0;
4709 return CPP_OTHER;
4710
4711 case '\"':
4712 case '\'':
4713 /* A single quoted string is treated like a double -- some
4714 programs (e.g., troff) are perverse this way */
3232050c
PB
4715 cpp_buf_line_and_col (cpp_file_buffer (pfile),
4716 &start_line, &start_column);
7f2935c7
PB
4717 old_written = CPP_WRITTEN (pfile);
4718 string:
4719 CPP_PUTC (pfile, c);
4720 while (1)
4721 {
4722 int cc = GETC();
4723 if (cc == EOF)
4724 {
4725 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
4726 {
4727 /* try harder: this string crosses a macro expansion
4728 boundary. This can happen naturally if -traditional.
4729 Otherwise, only -D can make a macro with an unmatched
4730 quote. */
4731 cpp_buffer *next_buf
4732 = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
4733 (*CPP_BUFFER (pfile)->cleanup)
4734 (CPP_BUFFER (pfile), pfile);
4735 CPP_BUFFER (pfile) = next_buf;
4736 continue;
4737 }
7f2935c7
PB
4738 if (!CPP_TRADITIONAL (pfile))
4739 {
3232050c 4740 cpp_error_with_line (pfile, start_line, start_column,
7f2935c7 4741 "unterminated string or character constant");
3232050c
PB
4742 if (pfile->multiline_string_line != start_line
4743 && pfile->multiline_string_line != 0)
4744 cpp_error_with_line (pfile,
4745 pfile->multiline_string_line, -1,
4746 "possible real start of unterminated constant");
4747 pfile->multiline_string_line = 0;
7f2935c7 4748 }
7f2935c7
PB
4749 break;
4750 }
4751 CPP_PUTC (pfile, cc);
4752 switch (cc)
4753 {
4754 case '\n':
4755 /* Traditionally, end of line ends a string constant with
4756 no error. So exit the loop and record the new line. */
4757 if (CPP_TRADITIONAL (pfile))
4758 goto while2end;
7f2935c7
PB
4759 if (c == '\'')
4760 {
3232050c 4761 cpp_error_with_line (pfile, start_line, start_column,
e8037d57 4762 "unterminated character constant");
7f2935c7
PB
4763 goto while2end;
4764 }
3232050c
PB
4765 if (CPP_PEDANTIC (pfile)
4766 && pfile->multiline_string_line == 0)
7f2935c7 4767 {
3232050c 4768 cpp_pedwarn_with_line (pfile, start_line, start_column,
7f2935c7
PB
4769 "string constant runs past end of line");
4770 }
3232050c
PB
4771 if (pfile->multiline_string_line == 0)
4772 pfile->multiline_string_line = start_line;
7f2935c7
PB
4773 break;
4774
4775 case '\\':
4776 cc = GETC();
4777 if (cc == '\n')
4778 {
4779 /* Backslash newline is replaced by nothing at all. */
4780 CPP_ADJUST_WRITTEN (pfile, -1);
4781 pfile->lineno++;
4782 }
4783 else
4784 {
4785 /* ANSI stupidly requires that in \\ the second \
4786 is *not* prevented from combining with a newline. */
4787 NEWLINE_FIX1(cc);
4788 if (cc != EOF)
4789 CPP_PUTC (pfile, cc);
4790 }
4791 break;
4792
4793 case '\"':
4794 case '\'':
4795 if (cc == c)
4796 goto while2end;
4797 break;
4798 }
4799 }
4800 while2end:
4801 pfile->lineno += count_newlines (pfile->token_buffer + old_written,
4802 CPP_PWRITTEN (pfile));
4803 pfile->only_seen_white = 0;
4804 return c == '\'' ? CPP_CHAR : CPP_STRING;
4805
4806 case '$':
4807 if (!opts->dollars_in_ident)
4808 goto randomchar;
4809 goto letter;
4810
4811 case ':':
4812 if (opts->cplusplus && PEEKC () == ':')
4813 goto op2;
4814 goto randomchar;
4815
4816 case '&':
4817 case '+':
4818 case '|':
4819 NEWLINE_FIX;
4820 c2 = PEEKC ();
4821 if (c2 == c || c2 == '=')
4822 goto op2;
4823 goto randomchar;
4824
4825 case '*':
4826 case '!':
4827 case '%':
4828 case '=':
4829 case '^':
4830 NEWLINE_FIX;
4831 if (PEEKC () == '=')
4832 goto op2;
4833 goto randomchar;
4834
4835 case '-':
4836 NEWLINE_FIX;
4837 c2 = PEEKC ();
4838 if (c2 == '-' && opts->chill)
4839 {
4840 /* Chill style comment */
4841 if (opts->put_out_comments)
4842 parse_set_mark (&start_mark, pfile);
4843 FORWARD(1); /* Skip second '-'. */
4844 for (;;)
4845 {
4846 c = GETC ();
4847 if (c == EOF)
4848 break;
4849 if (c == '\n')
4850 {
4851 /* Don't consider final '\n' to be part of comment. */
4852 FORWARD(-1);
4853 break;
4854 }
4855 }
4856 c = '-';
4857 goto return_comment;
4858 }
4859 if (c2 == '-' || c2 == '=' || c2 == '>')
4860 goto op2;
4861 goto randomchar;
4862
4863 case '<':
4864 if (pfile->parsing_include_directive)
4865 {
4866 for (;;)
4867 {
4868 CPP_PUTC (pfile, c);
4869 if (c == '>')
4870 break;
4871 c = GETC ();
4872 NEWLINE_FIX1 (c);
4873 if (c == '\n' || c == EOF)
4874 {
4875 cpp_error (pfile,
4876 "missing '>' in `#include <FILENAME>'");
4877 break;
4878 }
4879 }
4880 return CPP_STRING;
4881 }
4882 /* else fall through */
4883 case '>':
4884 NEWLINE_FIX;
4885 c2 = PEEKC ();
4886 if (c2 == '=')
4887 goto op2;
4888 if (c2 != c)
4889 goto randomchar;
4890 FORWARD(1);
4891 CPP_RESERVE (pfile, 4);
4892 CPP_PUTC (pfile, c);
4893 CPP_PUTC (pfile, c2);
4894 NEWLINE_FIX;
4895 c3 = PEEKC ();
4896 if (c3 == '=')
4897 CPP_PUTC_Q (pfile, GETC ());
4898 CPP_NUL_TERMINATE_Q (pfile);
4899 pfile->only_seen_white = 0;
4900 return CPP_OTHER;
4901
4902 case '@':
4903 if (CPP_BUFFER (pfile)->has_escapes)
4904 {
4905 c = GETC ();
4906 if (c == '-')
4907 {
4908 if (pfile->output_escapes)
4909 CPP_PUTS (pfile, "@-", 2);
4910 parse_name (pfile, GETC ());
4911 return CPP_NAME;
4912 }
782331f4
PB
4913 else if (is_space [c])
4914 {
4915 CPP_RESERVE (pfile, 2);
4916 if (pfile->output_escapes)
4917 CPP_PUTC_Q (pfile, '@');
4918 CPP_PUTC_Q (pfile, c);
4919 return CPP_HSPACE;
4920 }
7f2935c7
PB
4921 }
4922 if (pfile->output_escapes)
4923 {
4924 CPP_PUTS (pfile, "@@", 2);
4925 return CPP_OTHER;
4926 }
4927 goto randomchar;
4928
4929 case '.':
4930 NEWLINE_FIX;
4931 c2 = PEEKC ();
4932 if (isdigit(c2))
4933 {
4934 CPP_RESERVE(pfile, 2);
4935 CPP_PUTC_Q (pfile, '.');
4936 c = GETC ();
4937 goto number;
4938 }
4939 /* FIXME - misses the case "..\\\n." */
4940 if (c2 == '.' && PEEKN(1) == '.')
4941 {
4942 CPP_RESERVE(pfile, 4);
4943 CPP_PUTC_Q (pfile, '.');
4944 CPP_PUTC_Q (pfile, '.');
4945 CPP_PUTC_Q (pfile, '.');
4946 FORWARD (2);
4947 CPP_NUL_TERMINATE_Q (pfile);
4948 pfile->only_seen_white = 0;
4949 return CPP_3DOTS;
4950 }
4951 goto randomchar;
4952
4953 op2:
4954 token = CPP_OTHER;
4955 pfile->only_seen_white = 0;
4956 op2any:
4957 CPP_RESERVE(pfile, 3);
4958 CPP_PUTC_Q (pfile, c);
4959 CPP_PUTC_Q (pfile, GETC ());
4960 CPP_NUL_TERMINATE_Q (pfile);
4961 return token;
4962
4963 case 'L':
4964 NEWLINE_FIX;
4965 c2 = PEEKC ();
4966 if ((c2 == '\'' || c2 == '\"') && !CPP_TRADITIONAL (pfile))
4967 {
4968 CPP_PUTC (pfile, c);
4969 c = GETC ();
4970 goto string;
4971 }
4972 goto letter;
4973
4974 case '0': case '1': case '2': case '3': case '4':
4975 case '5': case '6': case '7': case '8': case '9':
4976 number:
4977 c2 = '.';
4978 for (;;)
4979 {
4980 CPP_RESERVE (pfile, 2);
4981 CPP_PUTC_Q (pfile, c);
4982 NEWLINE_FIX;
4983 c = PEEKC ();
4984 if (c == EOF)
4985 break;
4986 if (!is_idchar[c] && c != '.'
4987 && ((c2 != 'e' && c2 != 'E') || (c != '+' && c != '-')))
4988 break;
4989 FORWARD(1);
4990 c2= c;
4991 }
4992 CPP_NUL_TERMINATE_Q (pfile);
4993 pfile->only_seen_white = 0;
4994 return CPP_NUMBER;
4995 case 'b': case 'c': case 'd': case 'h': case 'o':
4996 case 'B': case 'C': case 'D': case 'H': case 'O':
4997 if (opts->chill && PEEKC () == '\'')
4998 {
4999 pfile->only_seen_white = 0;
5000 CPP_RESERVE (pfile, 2);
5001 CPP_PUTC_Q (pfile, c);
5002 CPP_PUTC_Q (pfile, '\'');
5003 FORWARD(1);
5004 for (;;)
5005 {
5006 c = GETC();
5007 if (c == EOF)
5008 goto chill_number_eof;
5009 if (!is_idchar[c])
5010 {
5011 if (c == '\\' && PEEKC() == '\n')
5012 {
5013 FORWARD(2);
5014 continue;
5015 }
5016 break;
5017 }
5018 CPP_PUTC (pfile, c);
5019 }
5020 if (c == '\'')
5021 {
5022 CPP_RESERVE (pfile, 2);
5023 CPP_PUTC_Q (pfile, c);
5024 CPP_NUL_TERMINATE_Q (pfile);
5025 return CPP_STRING;
5026 }
5027 else
5028 {
5029 FORWARD(-1);
5030 chill_number_eof:
5031 CPP_NUL_TERMINATE (pfile);
5032 return CPP_NUMBER;
5033 }
5034 }
5035 else
5036 goto letter;
5037 case '_':
5038 case 'a': case 'e': case 'f': case 'g': case 'i': case 'j':
5039 case 'k': case 'l': case 'm': case 'n': case 'p': case 'q':
5040 case 'r': case 's': case 't': case 'u': case 'v': case 'w':
5041 case 'x': case 'y': case 'z':
5042 case 'A': case 'E': case 'F': case 'G': case 'I': case 'J':
5043 case 'K': case 'M': case 'N': case 'P': case 'Q': case 'R':
5044 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
5045 case 'Y': case 'Z':
5046 letter:
5047 {
5048 HASHNODE *hp;
5049 unsigned char *ident;
5050 int before_name_written = CPP_WRITTEN (pfile);
5051 int ident_len;
5052 parse_name (pfile, c);
5053 pfile->only_seen_white = 0;
5054 if (pfile->no_macro_expand)
5055 return CPP_NAME;
5056 ident = pfile->token_buffer + before_name_written;
5057 ident_len = CPP_PWRITTEN (pfile) - ident;
5058 hp = cpp_lookup (pfile, ident, ident_len, -1);
5059 if (!hp)
5060 return CPP_NAME;
5061 if (hp->type == T_DISABLED)
5062 {
5063 if (pfile->output_escapes)
5064 { /* Return "@-IDENT", followed by '\0'. */
5065 int i;
5066 CPP_RESERVE (pfile, 3);
5067 ident = pfile->token_buffer + before_name_written;
5068 CPP_ADJUST_WRITTEN (pfile, 2);
5069 for (i = ident_len; i >= 0; i--) ident[i+2] = ident[i];
5070 ident[0] = '@';
5071 ident[1] = '-';
5072 }
5073 return CPP_NAME;
5074 }
5075
5076 /* If macro wants an arglist, verify that a '(' follows.
5077 first skip all whitespace, copying it to the output
5078 after the macro name. Then, if there is no '(',
5079 decide this is not a macro call and leave things that way. */
5080 if (hp->type == T_MACRO && hp->value.defn->nargs >= 0)
5081 {
5082 struct parse_marker macro_mark;
5083 int is_macro_call;
5084 while (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
5085 {
5086 cpp_buffer *next_buf;
5087 cpp_skip_hspace (pfile);
5088 if (PEEKC () != EOF)
5089 break;
5090 next_buf = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
5091 (*CPP_BUFFER (pfile)->cleanup) (CPP_BUFFER (pfile), pfile);
5092 CPP_BUFFER (pfile) = next_buf;
5093 }
5094 parse_set_mark (&macro_mark, pfile);
5095 for (;;)
5096 {
5097 cpp_skip_hspace (pfile);
5098 c = PEEKC ();
5099 is_macro_call = c == '(';
5100 if (c != '\n')
5101 break;
5102 FORWARD (1);
5103 }
5104 if (!is_macro_call)
5105 parse_goto_mark (&macro_mark, pfile);
5106 parse_clear_mark (&macro_mark);
5107 if (!is_macro_call)
5108 return CPP_NAME;
5109 }
5110 /* This is now known to be a macro call. */
5111
5112 /* it might not actually be a macro. */
5113 if (hp->type != T_MACRO) {
5114 int xbuf_len; U_CHAR *xbuf;
5115 CPP_SET_WRITTEN (pfile, before_name_written);
5116 special_symbol (hp, pfile);
5117 xbuf_len = CPP_WRITTEN (pfile) - before_name_written;
5118 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
5119 CPP_SET_WRITTEN (pfile, before_name_written);
5120 bcopy (CPP_PWRITTEN (pfile), xbuf, xbuf_len + 1);
5121 push_macro_expansion (pfile, xbuf, xbuf_len, hp);
5122 }
5123 else
5124 {
5125 /* Expand the macro, reading arguments as needed,
5126 and push the expansion on the input stack. */
5127 macroexpand (pfile, hp);
5128 CPP_SET_WRITTEN (pfile, before_name_written);
5129 }
5130
782331f4 5131 /* An extra "@ " is added to the end of a macro expansion
7f2935c7
PB
5132 to prevent accidental token pasting. We prefer to avoid
5133 unneeded extra spaces (for the sake of cpp-using tools like
5134 imake). Here we remove the space if it is safe to do so. */
782331f4
PB
5135 if (pfile->buffer->rlimit - pfile->buffer->cur >= 3
5136 && pfile->buffer->rlimit[-2] == '@'
b13b05f6 5137 && pfile->buffer->rlimit[-1] == ' ')
7f2935c7 5138 {
782331f4 5139 int c1 = pfile->buffer->rlimit[-3];
7f2935c7
PB
5140 int c2 = CPP_BUF_PEEK (CPP_PREV_BUFFER (CPP_BUFFER (pfile)));
5141 if (c2 == EOF || ! unsafe_chars (c1, c2))
782331f4 5142 pfile->buffer->rlimit -= 2;
7f2935c7 5143 }
7f2935c7 5144 }
782331f4 5145 goto get_next;
7f2935c7
PB
5146
5147 case ' ': case '\t': case '\v': case '\r':
5148 for (;;)
5149 {
5150 CPP_PUTC (pfile, c);
5151 c = PEEKC ();
5152 if (c == EOF || !is_hor_space[c])
5153 break;
5154 FORWARD(1);
5155 }
5156 return CPP_HSPACE;
5157
5158 case '\\':
5159 c2 = PEEKC ();
5160 if (c2 != '\n')
5161 goto randomchar;
5162 token = CPP_HSPACE;
5163 goto op2any;
5164
5165 case '\n':
5166 CPP_PUTC (pfile, c);
5167 if (pfile->only_seen_white == 0)
5168 pfile->only_seen_white = 1;
5169 pfile->lineno++;
5170 output_line_command (pfile, 1, same_file);
5171 return CPP_VSPACE;
5172
5173 case '(': token = CPP_LPAREN; goto char1;
5174 case ')': token = CPP_RPAREN; goto char1;
5175 case '{': token = CPP_LBRACE; goto char1;
5176 case '}': token = CPP_RBRACE; goto char1;
5177 case ',': token = CPP_COMMA; goto char1;
5178 case ';': token = CPP_SEMICOLON; goto char1;
5179
5180 randomchar:
5181 default:
5182 token = CPP_OTHER;
5183 char1:
5184 pfile->only_seen_white = 0;
5185 CPP_PUTC (pfile, c);
5186 return token;
5187 }
5188 }
5189}
5190
5191/* Like cpp_get_token, but skip spaces and comments. */
5192enum cpp_token
5193cpp_get_non_space_token (pfile)
5194 cpp_reader *pfile;
5195{
5196 int old_written = CPP_WRITTEN (pfile);
5197 for (;;)
5198 {
5199 enum cpp_token token = cpp_get_token (pfile);
5200 if (token != CPP_COMMENT && token != CPP_POP
5201 && token != CPP_HSPACE && token != CPP_VSPACE)
5202 return token;
5203 CPP_SET_WRITTEN (pfile, old_written);
5204 }
5205}
5206
5207/* Parse an identifier starting with C. */
5208
5209int
5210parse_name (pfile, c)
5211 cpp_reader *pfile; int c;
5212{
5213 for (;;)
5214 {
5215 if (! is_idchar[c])
5216 {
5217 if (c == '\\' && PEEKC() == '\n')
5218 {
5219 FORWARD(2);
5220 continue;
5221 }
5222 FORWARD (-1);
5223 break;
5224 }
5225
5226 CPP_RESERVE(pfile, 2); /* One more for final NUL. */
5227 CPP_PUTC_Q (pfile, c);
5228 c = GETC();
5229 if (c == EOF)
5230 break;
5231 }
5232 CPP_NUL_TERMINATE_Q (pfile);
5233 return 1;
5234}
5235
5236\f
5237/* Maintain and search list of included files, for #import. */
5238
5239/* Hash a file name for import_hash_table. */
5240
5241static int
5242import_hash (f)
5243 char *f;
5244{
5245 int val = 0;
5246
5247 while (*f) val += *f++;
5248 return (val%IMPORT_HASH_SIZE);
5249}
5250
5251/* Search for file FILENAME in import_hash_table.
5252 Return -2 if found, either a matching name or a matching inode.
5253 Otherwise, open the file and return a file descriptor if successful
5254 or -1 if unsuccessful. */
5255
5256static int
5257lookup_import (pfile, filename, searchptr)
782331f4 5258 cpp_reader *pfile;
7f2935c7
PB
5259 char *filename;
5260 struct file_name_list *searchptr;
5261{
5262 struct import_file *i;
5263 int h;
5264 int hashval;
5265 struct stat sb;
5266 int fd;
5267
5268 hashval = import_hash (filename);
5269
5270 /* Attempt to find file in list of already included files */
5271 i = pfile->import_hash_table[hashval];
5272
5273 while (i) {
5274 if (!strcmp (filename, i->name))
5275 return -2; /* return found */
5276 i = i->next;
5277 }
5278 /* Open it and try a match on inode/dev */
782331f4 5279 fd = open_include_file (pfile, filename, searchptr);
7f2935c7
PB
5280 if (fd < 0)
5281 return fd;
5282 fstat (fd, &sb);
5283 for (h = 0; h < IMPORT_HASH_SIZE; h++) {
5284 i = pfile->import_hash_table[h];
5285 while (i) {
5286 /* Compare the inode and the device.
5287 Supposedly on some systems the inode is not a scalar. */
5f972d0c 5288 if (!bcmp ((char *) &i->inode, (char *) &sb.st_ino, sizeof (sb.st_ino))
7f2935c7
PB
5289 && i->dev == sb.st_dev) {
5290 close (fd);
5291 return -2; /* return found */
5292 }
5293 i = i->next;
5294 }
5295 }
5296 return fd; /* Not found, return open file */
5297}
5298
5299/* Add the file FNAME, open on descriptor FD, to import_hash_table. */
5300
5301static void
5302add_import (pfile, fd, fname)
5303 cpp_reader *pfile;
5304 int fd;
5305 char *fname;
5306{
5307 struct import_file *i;
5308 int hashval;
5309 struct stat sb;
5310
5311 hashval = import_hash (fname);
5312 fstat (fd, &sb);
5313 i = (struct import_file *)xmalloc (sizeof (struct import_file));
5314 i->name = (char *)xmalloc (strlen (fname)+1);
5315 strcpy (i->name, fname);
5f972d0c 5316 bcopy ((char *) &sb.st_ino, (char *) &i->inode, sizeof (sb.st_ino));
7f2935c7
PB
5317 i->dev = sb.st_dev;
5318 i->next = pfile->import_hash_table[hashval];
5319 pfile->import_hash_table[hashval] = i;
5320}
5321\f
5322/* The file_name_map structure holds a mapping of file names for a
5323 particular directory. This mapping is read from the file named
5324 FILE_NAME_MAP_FILE in that directory. Such a file can be used to
5325 map filenames on a file system with severe filename restrictions,
5326 such as DOS. The format of the file name map file is just a series
5327 of lines with two tokens on each line. The first token is the name
5328 to map, and the second token is the actual name to use. */
5329
5330struct file_name_map
5331{
5332 struct file_name_map *map_next;
5333 char *map_from;
5334 char *map_to;
5335};
5336
5337#define FILE_NAME_MAP_FILE "header.gcc"
5338
5339/* Read a space delimited string of unlimited length from a stdio
5340 file. */
5341
5342static char *
5343read_filename_string (ch, f)
5344 int ch;
5345 FILE *f;
5346{
5347 char *alloc, *set;
5348 int len;
5349
5350 len = 20;
5351 set = alloc = xmalloc (len + 1);
5352 if (! is_space[ch])
5353 {
5354 *set++ = ch;
5355 while ((ch = getc (f)) != EOF && ! is_space[ch])
5356 {
5357 if (set - alloc == len)
5358 {
5359 len *= 2;
5360 alloc = xrealloc (alloc, len + 1);
5361 set = alloc + len / 2;
5362 }
5363 *set++ = ch;
5364 }
5365 }
5366 *set = '\0';
5367 ungetc (ch, f);
5368 return alloc;
5369}
5370
782331f4
PB
5371/* This structure holds a linked list of file name maps, one per directory. */
5372struct file_name_map_list
5373{
5374 struct file_name_map_list *map_list_next;
5375 char *map_list_name;
5376 struct file_name_map *map_list_map;
5377};
5378
7f2935c7
PB
5379/* Read the file name map file for DIRNAME. */
5380
5381static struct file_name_map *
782331f4
PB
5382read_name_map (pfile, dirname)
5383 cpp_reader *pfile;
7f2935c7
PB
5384 char *dirname;
5385{
7f2935c7
PB
5386 register struct file_name_map_list *map_list_ptr;
5387 char *name;
5388 FILE *f;
5389
782331f4 5390 for (map_list_ptr = CPP_OPTIONS (pfile)->map_list; map_list_ptr;
7f2935c7
PB
5391 map_list_ptr = map_list_ptr->map_list_next)
5392 if (! strcmp (map_list_ptr->map_list_name, dirname))
5393 return map_list_ptr->map_list_map;
5394
5395 map_list_ptr = ((struct file_name_map_list *)
5396 xmalloc (sizeof (struct file_name_map_list)));
5397 map_list_ptr->map_list_name = savestring (dirname);
5398 map_list_ptr->map_list_map = NULL;
5399
5400 name = (char *) alloca (strlen (dirname) + strlen (FILE_NAME_MAP_FILE) + 2);
5401 strcpy (name, dirname);
5402 if (*dirname)
5403 strcat (name, "/");
5404 strcat (name, FILE_NAME_MAP_FILE);
5405 f = fopen (name, "r");
5406 if (!f)
5407 map_list_ptr->map_list_map = NULL;
5408 else
5409 {
5410 int ch;
5411 int dirlen = strlen (dirname);
5412
5413 while ((ch = getc (f)) != EOF)
5414 {
5415 char *from, *to;
5416 struct file_name_map *ptr;
5417
5418 if (is_space[ch])
5419 continue;
5420 from = read_filename_string (ch, f);
5421 while ((ch = getc (f)) != EOF && is_hor_space[ch])
5422 ;
5423 to = read_filename_string (ch, f);
5424
5425 ptr = ((struct file_name_map *)
5426 xmalloc (sizeof (struct file_name_map)));
5427 ptr->map_from = from;
5428
5429 /* Make the real filename absolute. */
5430 if (*to == '/')
5431 ptr->map_to = to;
5432 else
5433 {
5434 ptr->map_to = xmalloc (dirlen + strlen (to) + 2);
5435 strcpy (ptr->map_to, dirname);
5436 ptr->map_to[dirlen] = '/';
5437 strcpy (ptr->map_to + dirlen + 1, to);
5438 free (to);
5439 }
5440
5441 ptr->map_next = map_list_ptr->map_list_map;
5442 map_list_ptr->map_list_map = ptr;
5443
5444 while ((ch = getc (f)) != '\n')
5445 if (ch == EOF)
5446 break;
5447 }
5448 fclose (f);
5449 }
5450
782331f4
PB
5451 map_list_ptr->map_list_next = CPP_OPTIONS (pfile)->map_list;
5452 CPP_OPTIONS (pfile)->map_list = map_list_ptr;
7f2935c7
PB
5453
5454 return map_list_ptr->map_list_map;
5455}
5456
5457/* Try to open include file FILENAME. SEARCHPTR is the directory
5458 being tried from the include file search path. This function maps
5459 filenames on file systems based on information read by
5460 read_name_map. */
5461
5462static int
782331f4
PB
5463open_include_file (pfile, filename, searchptr)
5464 cpp_reader *pfile;
7f2935c7
PB
5465 char *filename;
5466 struct file_name_list *searchptr;
5467{
5468 register struct file_name_map *map;
5469 register char *from;
5470 char *p, *dir;
5471
5472 if (searchptr && ! searchptr->got_name_map)
5473 {
782331f4
PB
5474 searchptr->name_map = read_name_map (pfile,
5475 searchptr->fname
7f2935c7
PB
5476 ? searchptr->fname : ".");
5477 searchptr->got_name_map = 1;
5478 }
5479
5480 /* First check the mapping for the directory we are using. */
5481 if (searchptr && searchptr->name_map)
5482 {
5483 from = filename;
5484 if (searchptr->fname)
5485 from += strlen (searchptr->fname) + 1;
5486 for (map = searchptr->name_map; map; map = map->map_next)
5487 {
5488 if (! strcmp (map->map_from, from))
5489 {
5490 /* Found a match. */
5491 return open (map->map_to, O_RDONLY, 0666);
5492 }
5493 }
5494 }
5495
5496 /* Try to find a mapping file for the particular directory we are
5497 looking in. Thus #include <sys/types.h> will look up sys/types.h
5498 in /usr/include/header.gcc and look up types.h in
5499 /usr/include/sys/header.gcc. */
5500 p = rindex (filename, '/');
5501 if (! p)
5502 p = filename;
5503 if (searchptr
5504 && searchptr->fname
5505 && strlen (searchptr->fname) == p - filename
5506 && ! strncmp (searchptr->fname, filename, p - filename))
5507 {
5508 /* FILENAME is in SEARCHPTR, which we've already checked. */
5509 return open (filename, O_RDONLY, 0666);
5510 }
5511
5512 if (p == filename)
5513 {
5514 dir = ".";
5515 from = filename;
5516 }
5517 else
5518 {
5519 dir = (char *) alloca (p - filename + 1);
5520 bcopy (filename, dir, p - filename);
5521 dir[p - filename] = '\0';
5522 from = p + 1;
5523 }
782331f4 5524 for (map = read_name_map (pfile, dir); map; map = map->map_next)
7f2935c7
PB
5525 if (! strcmp (map->map_from, from))
5526 return open (map->map_to, O_RDONLY, 0666);
5527
5528 return open (filename, O_RDONLY, 0666);
5529}
5530
5531/* Process the contents of include file FNAME, already open on descriptor F,
5532 with output to OP.
5533 SYSTEM_HEADER_P is 1 if this file resides in any one of the known
5534 "system" include directories (as decided by the `is_system_include'
5535 function above).
5536 DIRPTR is the link in the dir path through which this file was found,
6bac1e64 5537 or 0 if the file name was absolute or via the current directory.
22bbceaf
PB
5538 Return 1 on success, 0 on failure.
5539
5540 The caller is responsible for the cpp_push_buffer. */
7f2935c7
PB
5541
5542static int
5543finclude (pfile, f, fname, system_header_p, dirptr)
5544 cpp_reader *pfile;
5545 int f;
5546 char *fname;
5547 int system_header_p;
5548 struct file_name_list *dirptr;
5549{
5550 int st_mode;
5551 long st_size;
5552 long i;
5553 int length;
5554 cpp_buffer *fp; /* For input stack frame */
5555 int missing_newline = 0;
5556
7f2935c7
PB
5557 if (file_size_and_mode (f, &st_mode, &st_size) < 0)
5558 {
5559 cpp_perror_with_name (pfile, fname);
5560 close (f);
22bbceaf 5561 cpp_pop_buffer (pfile);
7f2935c7
PB
5562 return 0;
5563 }
5564
22bbceaf 5565 fp = CPP_BUFFER (pfile);
7f2935c7
PB
5566 fp->nominal_fname = fp->fname = fname;
5567#if 0
5568 fp->length = 0;
5569#endif
5570 fp->dir = dirptr;
5571 fp->system_header_p = system_header_p;
5572 fp->lineno = 1;
5573 fp->colno = 1;
5574 fp->cleanup = file_cleanup;
5575
5576 if (S_ISREG (st_mode)) {
5577 fp->buf = (U_CHAR *) xmalloc (st_size + 2);
5578 fp->alimit = fp->buf + st_size + 2;
5579 fp->cur = fp->buf;
5580
5581 /* Read the file contents, knowing that st_size is an upper bound
5582 on the number of bytes we can read. */
5583 length = safe_read (f, fp->buf, st_size);
5584 fp->rlimit = fp->buf + length;
5585 if (length < 0) goto nope;
5586 }
5587 else if (S_ISDIR (st_mode)) {
5588 cpp_error (pfile, "directory `%s' specified in #include", fname);
5589 close (f);
5590 return 0;
5591 } else {
5592 /* Cannot count its file size before reading.
5593 First read the entire file into heap and
5594 copy them into buffer on stack. */
5595
5596 int bsize = 2000;
5597
5598 st_size = 0;
5599 fp->buf = (U_CHAR *) xmalloc (bsize + 2);
5600
5601 for (;;) {
5602 i = safe_read (f, fp->buf + st_size, bsize - st_size);
5603 if (i < 0)
5604 goto nope; /* error! */
5605 st_size += i;
5606 if (st_size != bsize)
5607 break; /* End of file */
5608 bsize *= 2;
5609 fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
5610 }
a5827481 5611 fp->cur = fp->buf;
7f2935c7
PB
5612 length = st_size;
5613 }
5614
5615 if ((length > 0 && fp->buf[length - 1] != '\n')
5616 /* Backslash-newline at end is not good enough. */
5617 || (length > 1 && fp->buf[length - 2] == '\\')) {
5618 fp->buf[length++] = '\n';
5619#if 0
5620 missing_newline = 1;
5621#endif
5622 }
5623 fp->buf[length] = '\0';
5624 fp->rlimit = fp->buf + length;
5625
5626 /* Close descriptor now, so nesting does not use lots of descriptors. */
5627 close (f);
5628
5629 /* Must do this before calling trigraph_pcp, so that the correct file name
5630 will be printed in warning messages. */
5631
5632 pfile->input_stack_listing_current = 0;
5633
5634#if 0
5635 if (!no_trigraphs)
5636 trigraph_pcp (fp);
5637#endif
5638
5639#if 0
5640 rescan (op, 0);
5641
5642 if (missing_newline)
5643 fp->lineno--;
5644
5645 if (CPP_PEDANTIC (pfile) && missing_newline)
5646 pedwarn ("file does not end in newline");
5647
5648 indepth--;
5649 input_file_stack_tick++;
5650 free (fp->buf);
5651#endif
5652 return 1;
5653
5654 nope:
5655
5656 cpp_perror_with_name (pfile, fname);
5657 close (f);
5658 free (fp->buf);
5659 return 1;
5660}
5661
a94c94be
PB
5662/* This is called after options have been processed.
5663 * Check options for consistency, and setup for processing input
5664 * from the file named FNAME. (Use standard input if FNAME==NULL.)
5665 * Return 1 on succes, 0 on failure.
5666 */
5667
7f2935c7 5668int
a94c94be 5669cpp_start_read (pfile, fname)
7f2935c7
PB
5670 cpp_reader *pfile;
5671 char *fname;
5672{
5673 struct cpp_options *opts = CPP_OPTIONS (pfile);
5674 struct cpp_pending *pend;
5675 char *p;
5676 int f;
22bbceaf 5677 cpp_buffer *fp;
7f2935c7
PB
5678
5679 /* The code looks at the defaults through this pointer, rather than through
5680 the constant structure above. This pointer gets changed if an environment
5681 variable specifies other defaults. */
5682 struct default_include *include_defaults = include_defaults_array;
5683
5684 /* Add dirs from CPATH after dirs from -I. */
5685 /* There seems to be confusion about what CPATH should do,
5686 so for the moment it is not documented. */
5687 /* Some people say that CPATH should replace the standard include dirs,
5688 but that seems pointless: it comes before them, so it overrides them
5689 anyway. */
5690 p = (char *) getenv ("CPATH");
5691 if (p != 0 && ! opts->no_standard_includes)
5692 path_include (pfile, p);
5693
5694 /* Now that dollars_in_ident is known, initialize is_idchar. */
5695 initialize_char_syntax (opts);
5696
7f2935c7
PB
5697 /* Do partial setup of input buffer for the sake of generating
5698 early #line directives (when -g is in effect). */
22bbceaf 5699 fp = cpp_push_buffer (pfile, NULL, 0);
e2f79f3c
PB
5700 if (!fp)
5701 return 0;
22bbceaf
PB
5702 if (opts->in_fname == NULL)
5703 opts->in_fname = "";
5704 fp->nominal_fname = fp->fname = opts->in_fname;
7f2935c7 5705 fp->lineno = 0;
7f2935c7
PB
5706
5707 /* Install __LINE__, etc. Must follow initialize_char_syntax
5708 and option processing. */
5709 initialize_builtins (pfile);
5710
5711 /* Do standard #defines and assertions
5712 that identify system and machine type. */
5713
5714 if (!opts->inhibit_predefs) {
5715 char *p = (char *) alloca (strlen (predefs) + 1);
5716 strcpy (p, predefs);
5717 while (*p) {
5718 char *q;
5719 while (*p == ' ' || *p == '\t')
5720 p++;
5721 /* Handle -D options. */
5722 if (p[0] == '-' && p[1] == 'D') {
5723 q = &p[2];
5724 while (*p && *p != ' ' && *p != '\t')
5725 p++;
5726 if (*p != 0)
5727 *p++= 0;
5728 if (opts->debug_output)
5729 output_line_command (pfile, 0, same_file);
b13b05f6 5730 cpp_define (pfile, q);
7f2935c7
PB
5731 while (*p == ' ' || *p == '\t')
5732 p++;
5733 } else if (p[0] == '-' && p[1] == 'A') {
5734 /* Handle -A options (assertions). */
5735 char *assertion;
5736 char *past_name;
5737 char *value;
5738 char *past_value;
5739 char *termination;
5740 int save_char;
5741
5742 assertion = &p[2];
5743 past_name = assertion;
5744 /* Locate end of name. */
5745 while (*past_name && *past_name != ' '
5746 && *past_name != '\t' && *past_name != '(')
5747 past_name++;
5748 /* Locate `(' at start of value. */
5749 value = past_name;
5750 while (*value && (*value == ' ' || *value == '\t'))
5751 value++;
5752 if (*value++ != '(')
5753 abort ();
5754 while (*value && (*value == ' ' || *value == '\t'))
5755 value++;
5756 past_value = value;
5757 /* Locate end of value. */
5758 while (*past_value && *past_value != ' '
5759 && *past_value != '\t' && *past_value != ')')
5760 past_value++;
5761 termination = past_value;
5762 while (*termination && (*termination == ' ' || *termination == '\t'))
5763 termination++;
5764 if (*termination++ != ')')
5765 abort ();
5766 if (*termination && *termination != ' ' && *termination != '\t')
5767 abort ();
5768 /* Temporarily null-terminate the value. */
5769 save_char = *termination;
5770 *termination = '\0';
5771 /* Install the assertion. */
5772 make_assertion (pfile, "-A", assertion);
5773 *termination = (char) save_char;
5774 p = termination;
5775 while (*p == ' ' || *p == '\t')
5776 p++;
5777 } else {
5778 abort ();
5779 }
5780 }
5781 }
5782
5783 /* Now handle the command line options. */
5784
5785 /* Do -U's, -D's and -A's in the order they were seen. */
5786 /* First reverse the list. */
22bbceaf 5787 opts->pending = nreverse_pending (opts->pending);
7f2935c7 5788
22bbceaf
PB
5789 for (pend = opts->pending; pend; pend = pend->next)
5790 {
5791 if (pend->cmd != NULL && pend->cmd[0] == '-')
5792 {
5793 switch (pend->cmd[1])
5794 {
5795 case 'U':
5796 if (opts->debug_output)
5797 output_line_command (pfile, 0, same_file);
5798 do_undef (pfile, NULL, pend->arg, pend->arg + strlen (pend->arg));
5799 break;
5800 case 'D':
5801 if (opts->debug_output)
5802 output_line_command (pfile, 0, same_file);
b13b05f6 5803 cpp_define (pfile, pend->arg);
22bbceaf
PB
5804 break;
5805 case 'A':
5806 make_assertion (pfile, "-A", pend->arg);
5807 break;
5808 }
5809 }
5810 }
7f2935c7
PB
5811
5812 opts->done_initializing = 1;
5813
5814 { /* read the appropriate environment variable and if it exists
5815 replace include_defaults with the listed path. */
5816 char *epath = 0;
5817 switch ((opts->objc << 1) + opts->cplusplus)
5818 {
5819 case 0:
5820 epath = getenv ("C_INCLUDE_PATH");
5821 break;
5822 case 1:
5823 epath = getenv ("CPLUS_INCLUDE_PATH");
5824 break;
5825 case 2:
5826 epath = getenv ("OBJC_INCLUDE_PATH");
5827 break;
5828 case 3:
5829 epath = getenv ("OBJCPLUS_INCLUDE_PATH");
5830 break;
5831 }
5832 /* If the environment var for this language is set,
5833 add to the default list of include directories. */
5834 if (epath) {
5835 char *nstore = (char *) alloca (strlen (epath) + 2);
5836 int num_dirs;
5837 char *startp, *endp;
5838
5839 for (num_dirs = 1, startp = epath; *startp; startp++)
5840 if (*startp == PATH_SEPARATOR)
5841 num_dirs++;
5842 include_defaults
5843 = (struct default_include *) xmalloc ((num_dirs
5844 * sizeof (struct default_include))
5845 + sizeof (include_defaults_array));
5846 startp = endp = epath;
5847 num_dirs = 0;
5848 while (1) {
5849 /* Handle cases like c:/usr/lib:d:/gcc/lib */
5850 if ((*endp == PATH_SEPARATOR)
5851 || *endp == 0) {
5852 strncpy (nstore, startp, endp-startp);
5853 if (endp == startp)
5854 strcpy (nstore, ".");
5855 else
5856 nstore[endp-startp] = '\0';
5857
5858 include_defaults[num_dirs].fname = savestring (nstore);
5859 include_defaults[num_dirs].cplusplus = opts->cplusplus;
5860 include_defaults[num_dirs].cxx_aware = 1;
5861 num_dirs++;
5862 if (*endp == '\0')
5863 break;
5864 endp = startp = endp + 1;
5865 } else
5866 endp++;
5867 }
5868 /* Put the usual defaults back in at the end. */
5f972d0c
RK
5869 bcopy ((char *) include_defaults_array,
5870 (char *) &include_defaults[num_dirs],
7f2935c7
PB
5871 sizeof (include_defaults_array));
5872 }
5873 }
5874
5875 append_include_chain (pfile, opts->before_system, opts->last_before_system);
5876 opts->first_system_include = opts->before_system;
5877
5878 /* Unless -fnostdinc,
5879 tack on the standard include file dirs to the specified list */
5880 if (!opts->no_standard_includes) {
5881 struct default_include *p = include_defaults;
5882 char *specd_prefix = opts->include_prefix;
5883 char *default_prefix = savestring (GCC_INCLUDE_DIR);
5884 int default_len = 0;
5885 /* Remove the `include' from /usr/local/lib/gcc.../include. */
5886 if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) {
5887 default_len = strlen (default_prefix) - 7;
5888 default_prefix[default_len] = 0;
5889 }
5890 /* Search "translated" versions of GNU directories.
5891 These have /usr/local/lib/gcc... replaced by specd_prefix. */
5892 if (specd_prefix != 0 && default_len != 0)
5893 for (p = include_defaults; p->fname; p++) {
5894 /* Some standard dirs are only for C++. */
5895 if (!p->cplusplus
5896 || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
5897 /* Does this dir start with the prefix? */
5898 if (!strncmp (p->fname, default_prefix, default_len)) {
5899 /* Yes; change prefix and add to search list. */
5900 struct file_name_list *new
5901 = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
5902 int this_len = strlen (specd_prefix) + strlen (p->fname) - default_len;
5903 char *str = (char *) xmalloc (this_len + 1);
5904 strcpy (str, specd_prefix);
5905 strcat (str, p->fname + default_len);
5906 new->fname = str;
5907 new->control_macro = 0;
5908 new->c_system_include_path = !p->cxx_aware;
5909 new->got_name_map = 0;
5910 append_include_chain (pfile, new, new);
5911 if (opts->first_system_include == 0)
5912 opts->first_system_include = new;
5913 }
5914 }
5915 }
5916 /* Search ordinary names for GNU include directories. */
5917 for (p = include_defaults; p->fname; p++) {
5918 /* Some standard dirs are only for C++. */
5919 if (!p->cplusplus
5920 || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
5921 struct file_name_list *new
5922 = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
5923 new->control_macro = 0;
5924 new->c_system_include_path = !p->cxx_aware;
5925 new->fname = p->fname;
5926 new->got_name_map = 0;
5927 append_include_chain (pfile, new, new);
5928 if (opts->first_system_include == 0)
5929 opts->first_system_include = new;
5930 }
5931 }
5932 }
5933
5934 /* Tack the after_include chain at the end of the include chain. */
5935 append_include_chain (pfile, opts->after_include, opts->last_after_include);
5936 if (opts->first_system_include == 0)
5937 opts->first_system_include = opts->after_include;
5938
5939 /* With -v, print the list of dirs to search. */
5940 if (opts->verbose) {
5941 struct file_name_list *p;
5942 fprintf (stderr, "#include \"...\" search starts here:\n");
5943 for (p = opts->include; p; p = p->next) {
5944 if (p == opts->first_bracket_include)
5945 fprintf (stderr, "#include <...> search starts here:\n");
5946 fprintf (stderr, " %s\n", p->fname);
5947 }
5948 fprintf (stderr, "End of search list.\n");
5949 }
5950
5951 /* Scan the -imacros files before the main input.
5952 Much like #including them, but with no_output set
5953 so that only their macro definitions matter. */
5954
5955 opts->no_output++; pfile->no_record_file++;
5956 for (pend = opts->pending; pend; pend = pend->next)
5957 {
5958 if (pend->cmd != NULL && strcmp (pend->cmd, "-imacros") == 0)
5959 {
5960 int fd = open (pend->arg, O_RDONLY, 0666);
5961 if (fd < 0)
5962 {
5963 cpp_perror_with_name (pfile, pend->arg);
a94c94be 5964 return 0;
7f2935c7 5965 }
e2f79f3c
PB
5966 if (!cpp_push_buffer (pfile, NULL, 0))
5967 return 0;
7f2935c7
PB
5968 finclude (pfile, fd, pend->arg, 0, NULL_PTR);
5969 cpp_scan_buffer (pfile);
5970 }
5971 }
5972 opts->no_output--; pfile->no_record_file--;
5973
5974 /* Copy the entire contents of the main input file into
5975 the stacked input buffer previously allocated for it. */
5976 if (fname == NULL || *fname == 0) {
5977 fname = "";
5978 f = 0;
5979 } else if ((f = open (fname, O_RDONLY, 0666)) < 0)
5980 cpp_pfatal_with_name (pfile, fname);
5981
5982 /* -MG doesn't select the form of output and must be specified with one of
5983 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
5984 inhibit compilation. */
5985 if (opts->print_deps_missing_files
5986 && (opts->print_deps == 0 || !opts->no_output))
a94c94be
PB
5987 {
5988 cpp_fatal (pfile, "-MG must be specified with one of -M or -MM");
5989 return 0;
5990 }
7f2935c7
PB
5991
5992 /* Either of two environment variables can specify output of deps.
5993 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
5994 where OUTPUT_FILE is the file to write deps info to
5995 and DEPS_TARGET is the target to mention in the deps. */
5996
5997 if (opts->print_deps == 0
5998 && (getenv ("SUNPRO_DEPENDENCIES") != 0
5999 || getenv ("DEPENDENCIES_OUTPUT") != 0)) {
6000 char *spec = getenv ("DEPENDENCIES_OUTPUT");
6001 char *s;
6002 char *output_file;
6003
6004 if (spec == 0)
6005 {
6006 spec = getenv ("SUNPRO_DEPENDENCIES");
6007 opts->print_deps = 2;
6008 }
6009 else
6010 opts->print_deps = 1;
6011
6012 s = spec;
6013 /* Find the space before the DEPS_TARGET, if there is one. */
6014 /* This should use index. (mrs) */
6015 while (*s != 0 && *s != ' ') s++;
6016 if (*s != 0)
6017 {
6018 opts->deps_target = s + 1;
6019 output_file = (char *) xmalloc (s - spec + 1);
6020 bcopy (spec, output_file, s - spec);
6021 output_file[s - spec] = 0;
6022 }
6023 else
6024 {
6025 opts->deps_target = 0;
6026 output_file = spec;
6027 }
6028
6029 opts->deps_file = output_file;
6030 opts->print_deps_append = 1;
6031 }
6032
6033 /* For -M, print the expected object file name
6034 as the target of this Make-rule. */
6035 if (opts->print_deps)
6036 {
6037 pfile->deps_allocated_size = 200;
6038 pfile->deps_buffer = (char *) xmalloc (pfile->deps_allocated_size);
6039 pfile->deps_buffer[0] = 0;
6040 pfile->deps_size = 0;
6041 pfile->deps_column = 0;
6042
6043 if (opts->deps_target)
6044 deps_output (pfile, opts->deps_target, ':');
6045 else if (*opts->in_fname == 0)
6046 deps_output (pfile, "-", ':');
6047 else
6048 {
6049 char *p, *q;
6050 int len;
6051
6052 /* Discard all directory prefixes from filename. */
6053 if ((q = rindex (opts->in_fname, '/')) != NULL
6054#ifdef DIR_SEPARATOR
6055 && (q = rindex (opts->in_fname, DIR_SEPARATOR)) != NULL
6056#endif
6057 )
6058 ++q;
6059 else
6060 q = opts->in_fname;
6061
6062 /* Copy remainder to mungable area. */
6063 p = (char *) alloca (strlen(q) + 8);
6064 strcpy (p, q);
6065
6066 /* Output P, but remove known suffixes. */
6067 len = strlen (p);
6068 q = p + len;
6069 if (len >= 2
6070 && p[len - 2] == '.'
6071 && index("cCsSm", p[len - 1]))
6072 q = p + (len - 2);
6073 else if (len >= 3
6074 && p[len - 3] == '.'
6075 && p[len - 2] == 'c'
6076 && p[len - 1] == 'c')
6077 q = p + (len - 3);
6078 else if (len >= 4
6079 && p[len - 4] == '.'
6080 && p[len - 3] == 'c'
6081 && p[len - 2] == 'x'
6082 && p[len - 1] == 'x')
6083 q = p + (len - 4);
6084 else if (len >= 4
6085 && p[len - 4] == '.'
6086 && p[len - 3] == 'c'
6087 && p[len - 2] == 'p'
6088 && p[len - 1] == 'p')
6089 q = p + (len - 4);
6090
6091 /* Supply our own suffix. */
6092#ifndef VMS
6093 strcpy (q, ".o");
6094#else
6095 strcpy (q, ".obj");
6096#endif
6097
6098 deps_output (pfile, p, ':');
6099 deps_output (pfile, opts->in_fname, ' ');
6100 }
6101 }
6102
6103#if 0
6104 /* Make sure data ends with a newline. And put a null after it. */
6105
6106 if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n')
6107 /* Backslash-newline at end is not good enough. */
6108 || (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) {
6109 fp->buf[fp->length++] = '\n';
6110 missing_newline = 1;
6111 }
6112 fp->buf[fp->length] = '\0';
6113
6114 /* Unless inhibited, convert trigraphs in the input. */
6115
6116 if (!no_trigraphs)
6117 trigraph_pcp (fp);
6118#endif
6119
22bbceaf
PB
6120 /* Scan the -include files before the main input.
6121 We push these in reverse order, so that the first one is handled first. */
7f2935c7
PB
6122
6123 pfile->no_record_file++;
22bbceaf 6124 opts->pending = nreverse_pending (opts->pending);
7f2935c7
PB
6125 for (pend = opts->pending; pend; pend = pend->next)
6126 {
6127 if (pend->cmd != NULL && strcmp (pend->cmd, "-include") == 0)
6128 {
6129 int fd = open (pend->arg, O_RDONLY, 0666);
6130 if (fd < 0)
6131 {
6132 cpp_perror_with_name (pfile, pend->arg);
a94c94be 6133 return 0;
7f2935c7 6134 }
e2f79f3c
PB
6135 if (!cpp_push_buffer (pfile, NULL, 0))
6136 return 0;
7f2935c7 6137 finclude (pfile, fd, pend->arg, 0, NULL_PTR);
7f2935c7
PB
6138 }
6139 }
6140 pfile->no_record_file--;
6141
6142 /* Free the pending list. */
6143 for (pend = opts->pending; pend; )
6144 {
6145 struct cpp_pending *next = pend->next;
6146 free (pend);
6147 pend = next;
6148 }
6149 opts->pending = NULL;
6150
6151#if 0
6152 /* Scan the input, processing macros and directives. */
6153
6154 rescan (&outbuf, 0);
6155
6156 if (missing_newline)
6157 fp->lineno--;
6158
6159 if (CPP_PEDANTIC (pfile) && missing_newline)
6160 pedwarn ("file does not end in newline");
6161
6162#endif
6bac1e64 6163 if (finclude (pfile, f, fname, 0, NULL_PTR))
7f2935c7 6164 output_line_command (pfile, 0, same_file);
a94c94be 6165 return 1;
7f2935c7
PB
6166}
6167
6168void
a94c94be 6169cpp_reader_init (pfile)
7f2935c7
PB
6170 cpp_reader *pfile;
6171{
5f972d0c 6172 bzero ((char *) pfile, sizeof (cpp_reader));
7f2935c7
PB
6173 pfile->get_token = cpp_get_token;
6174
6175 pfile->token_buffer_size = 200;
0e45ccbd 6176 pfile->token_buffer = (U_CHAR*)xmalloc (pfile->token_buffer_size);
7f2935c7
PB
6177 CPP_SET_WRITTEN (pfile, 0);
6178
6179 pfile->system_include_depth = 0;
6180 pfile->dont_repeat_files = 0;
6181 pfile->all_include_files = 0;
6182 pfile->max_include_len = 0;
6183 pfile->timebuf = NULL;
6184 pfile->only_seen_white = 1;
6185 pfile->buffer = CPP_NULL_BUFFER(pfile);
6186}
6187
22bbceaf
PB
6188static struct cpp_pending *
6189nreverse_pending (list)
6190 struct cpp_pending *list;
6191
6192{
6193 register struct cpp_pending *prev = 0, *next, *pend;
6194 for (pend = list; pend; pend = next)
6195 {
6196 next = pend->next;
6197 pend->next = prev;
6198 prev = pend;
6199 }
6200 return prev;
6201}
6202
7f2935c7
PB
6203static void
6204push_pending (pfile, cmd, arg)
6205 cpp_reader *pfile;
6206 char *cmd;
6207 char *arg;
6208{
6209 struct cpp_pending *pend
6210 = (struct cpp_pending*)xmalloc (sizeof (struct cpp_pending));
6211 pend->cmd = cmd;
6212 pend->arg = arg;
6213 pend->next = CPP_OPTIONS (pfile)->pending;
6214 CPP_OPTIONS (pfile)->pending = pend;
6215}
6216
6217/* Handle command-line options in (argc, argv).
6218 Can be called multiple times, to handle multiple sets of options.
6219 Returns if an unrecognized option is seen.
6220 Returns number of handled arguments. */
6221
6222int
6223cpp_handle_options (pfile, argc, argv)
6224 cpp_reader *pfile;
6225 int argc;
6226 char **argv;
6227{
6228 int i;
6229 struct cpp_options *opts = CPP_OPTIONS (pfile);
6230 for (i = 0; i < argc; i++) {
6231 if (argv[i][0] != '-') {
6232 if (opts->out_fname != NULL)
a94c94be
PB
6233 {
6234 cpp_fatal (pfile, "Usage: %s [switches] input output", argv[0]);
6235 return argc;
6236 }
7f2935c7
PB
6237 else if (opts->in_fname != NULL)
6238 opts->out_fname = argv[i];
6239 else
6240 opts->in_fname = argv[i];
6241 } else {
6242 switch (argv[i][1]) {
6243
a94c94be
PB
6244 missing_filename:
6245 cpp_fatal (pfile, "Filename missing after `%s' option", argv[i]);
6246 return argc;
6247 missing_dirname:
6248 cpp_fatal (pfile, "Directory name missing after `%s' option", argv[i]);
6249 return argc;
6250
7f2935c7
PB
6251 case 'i':
6252 if (!strcmp (argv[i], "-include")
6253 || !strcmp (argv[i], "-imacros")) {
6254 if (i + 1 == argc)
a94c94be 6255 goto missing_filename;
7f2935c7
PB
6256 else
6257 push_pending (pfile, argv[i], argv[i+1]), i++;
6258 }
6259 if (!strcmp (argv[i], "-iprefix")) {
6260 if (i + 1 == argc)
a94c94be 6261 goto missing_filename;
7f2935c7
PB
6262 else
6263 opts->include_prefix = argv[++i];
6264 }
6265 if (!strcmp (argv[i], "-ifoutput")) {
6266 opts->output_conditionals = 1;
6267 }
6268 if (!strcmp (argv[i], "-isystem")) {
6269 struct file_name_list *dirtmp;
6270
6271 if (i + 1 == argc)
a94c94be 6272 goto missing_filename;
7f2935c7
PB
6273
6274 dirtmp = (struct file_name_list *)
6275 xmalloc (sizeof (struct file_name_list));
6276 dirtmp->next = 0;
6277 dirtmp->control_macro = 0;
6278 dirtmp->c_system_include_path = 1;
6279 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1]) + 1);
6280 strcpy (dirtmp->fname, argv[++i]);
6281 dirtmp->got_name_map = 0;
6282
6283 if (opts->before_system == 0)
6284 opts->before_system = dirtmp;
6285 else
6286 opts->last_before_system->next = dirtmp;
6287 opts->last_before_system = dirtmp; /* Tail follows the last one */
6288 }
6289 /* Add directory to end of path for includes,
6290 with the default prefix at the front of its name. */
6291 if (!strcmp (argv[i], "-iwithprefix")) {
6292 struct file_name_list *dirtmp;
6293 char *prefix;
6294
6295 if (opts->include_prefix != 0)
6296 prefix = opts->include_prefix;
6297 else {
6298 prefix = savestring (GCC_INCLUDE_DIR);
6299 /* Remove the `include' from /usr/local/lib/gcc.../include. */
6300 if (!strcmp (prefix + strlen (prefix) - 8, "/include"))
6301 prefix[strlen (prefix) - 7] = 0;
6302 }
6303
6304 dirtmp = (struct file_name_list *)
6305 xmalloc (sizeof (struct file_name_list));
6306 dirtmp->next = 0; /* New one goes on the end */
6307 dirtmp->control_macro = 0;
6308 dirtmp->c_system_include_path = 0;
6309 if (i + 1 == argc)
a94c94be 6310 goto missing_dirname;
7f2935c7
PB
6311
6312 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1])
6313 + strlen (prefix) + 1);
6314 strcpy (dirtmp->fname, prefix);
6315 strcat (dirtmp->fname, argv[++i]);
6316 dirtmp->got_name_map = 0;
6317
6318 if (opts->after_include == 0)
6319 opts->after_include = dirtmp;
6320 else
6321 opts->last_after_include->next = dirtmp;
6322 opts->last_after_include = dirtmp; /* Tail follows the last one */
6323 }
6324 /* Add directory to main path for includes,
6325 with the default prefix at the front of its name. */
6326 if (!strcmp (argv[i], "-iwithprefixbefore")) {
6327 struct file_name_list *dirtmp;
6328 char *prefix;
6329
6330 if (opts->include_prefix != 0)
6331 prefix = opts->include_prefix;
6332 else {
6333 prefix = savestring (GCC_INCLUDE_DIR);
6334 /* Remove the `include' from /usr/local/lib/gcc.../include. */
6335 if (!strcmp (prefix + strlen (prefix) - 8, "/include"))
6336 prefix[strlen (prefix) - 7] = 0;
6337 }
6338
6339 dirtmp = (struct file_name_list *)
6340 xmalloc (sizeof (struct file_name_list));
6341 dirtmp->next = 0; /* New one goes on the end */
6342 dirtmp->control_macro = 0;
6343 dirtmp->c_system_include_path = 0;
6344 if (i + 1 == argc)
a94c94be 6345 goto missing_dirname;
7f2935c7
PB
6346
6347 dirtmp->fname = (char *) xmalloc (strlen (argv[i+1])
6348 + strlen (prefix) + 1);
6349 strcpy (dirtmp->fname, prefix);
6350 strcat (dirtmp->fname, argv[++i]);
6351 dirtmp->got_name_map = 0;
6352
6353 append_include_chain (pfile, dirtmp, dirtmp);
6354 }
6355 /* Add directory to end of path for includes. */
6356 if (!strcmp (argv[i], "-idirafter")) {
6357 struct file_name_list *dirtmp;
6358
6359 dirtmp = (struct file_name_list *)
6360 xmalloc (sizeof (struct file_name_list));
6361 dirtmp->next = 0; /* New one goes on the end */
6362 dirtmp->control_macro = 0;
6363 dirtmp->c_system_include_path = 0;
6364 if (i + 1 == argc)
a94c94be 6365 goto missing_dirname;
7f2935c7
PB
6366 else
6367 dirtmp->fname = argv[++i];
6368 dirtmp->got_name_map = 0;
6369
6370 if (opts->after_include == 0)
6371 opts->after_include = dirtmp;
6372 else
6373 opts->last_after_include->next = dirtmp;
6374 opts->last_after_include = dirtmp; /* Tail follows the last one */
6375 }
6376 break;
6377
6378 case 'o':
6379 if (opts->out_fname != NULL)
a94c94be
PB
6380 {
6381 cpp_fatal (pfile, "Output filename specified twice");
6382 return argc;
6383 }
7f2935c7 6384 if (i + 1 == argc)
a94c94be 6385 goto missing_filename;
7f2935c7
PB
6386 opts->out_fname = argv[++i];
6387 if (!strcmp (opts->out_fname, "-"))
6388 opts->out_fname = "";
6389 break;
6390
6391 case 'p':
6392 if (!strcmp (argv[i], "-pedantic"))
6393 CPP_PEDANTIC (pfile) = 1;
6394 else if (!strcmp (argv[i], "-pedantic-errors")) {
6395 CPP_PEDANTIC (pfile) = 1;
6396 opts->pedantic_errors = 1;
6397 }
6398#if 0
6399 else if (!strcmp (argv[i], "-pcp")) {
6400 char *pcp_fname = argv[++i];
6401 pcp_outfile =
6402 ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
6403 ? fopen (pcp_fname, "w")
6404 : fdopen (dup (fileno (stdout)), "w"));
6405 if (pcp_outfile == 0)
6406 cpp_pfatal_with_name (pfile, pcp_fname);
6407 no_precomp = 1;
6408 }
6409#endif
6410 break;
6411
6412 case 't':
6413 if (!strcmp (argv[i], "-traditional")) {
6414 opts->traditional = 1;
6415 if (opts->dollars_in_ident > 0)
6416 opts->dollars_in_ident = 1;
6417 } else if (!strcmp (argv[i], "-trigraphs")) {
6418 if (!opts->chill)
6419 opts->no_trigraphs = 0;
6420 }
6421 break;
6422
6423 case 'l':
6424 if (! strcmp (argv[i], "-lang-c"))
6425 opts->cplusplus = 0, opts->cplusplus_comments = 0, opts->objc = 0;
6426 if (! strcmp (argv[i], "-lang-c++"))
6427 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->objc = 0;
6428 if (! strcmp (argv[i], "-lang-c-c++-comments"))
6429 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->objc = 0;
6430 if (! strcmp (argv[i], "-lang-objc"))
6431 opts->objc = 1, opts->cplusplus = 0, opts->cplusplus_comments = 1;
6432 if (! strcmp (argv[i], "-lang-objc++"))
6433 opts->objc = 1, opts->cplusplus = 1, opts->cplusplus_comments = 1;
6434 if (! strcmp (argv[i], "-lang-asm"))
6435 opts->lang_asm = 1;
6436 if (! strcmp (argv[i], "-lint"))
6437 opts->for_lint = 1;
6438 if (! strcmp (argv[i], "-lang-chill"))
6439 opts->objc = 0, opts->cplusplus = 0, opts->chill = 1,
6440 opts->traditional = 1, opts->no_trigraphs = 1;
6441 break;
6442
6443 case '+':
6444 opts->cplusplus = 1, opts->cplusplus_comments = 1;
6445 break;
6446
6447 case 'w':
6448 opts->inhibit_warnings = 1;
6449 break;
6450
6451 case 'W':
6452 if (!strcmp (argv[i], "-Wtrigraphs"))
6453 opts->warn_trigraphs = 1;
6454 else if (!strcmp (argv[i], "-Wno-trigraphs"))
6455 opts->warn_trigraphs = 0;
6456 else if (!strcmp (argv[i], "-Wcomment"))
6457 opts->warn_comments = 1;
6458 else if (!strcmp (argv[i], "-Wno-comment"))
6459 opts->warn_comments = 0;
6460 else if (!strcmp (argv[i], "-Wcomments"))
6461 opts->warn_comments = 1;
6462 else if (!strcmp (argv[i], "-Wno-comments"))
6463 opts->warn_comments = 0;
6464 else if (!strcmp (argv[i], "-Wtraditional"))
6465 opts->warn_stringify = 1;
6466 else if (!strcmp (argv[i], "-Wno-traditional"))
6467 opts->warn_stringify = 0;
6468 else if (!strcmp (argv[i], "-Wimport"))
6469 opts->warn_import = 1;
6470 else if (!strcmp (argv[i], "-Wno-import"))
6471 opts->warn_import = 0;
6472 else if (!strcmp (argv[i], "-Werror"))
6473 opts->warnings_are_errors = 1;
6474 else if (!strcmp (argv[i], "-Wno-error"))
6475 opts->warnings_are_errors = 0;
6476 else if (!strcmp (argv[i], "-Wall"))
6477 {
6478 opts->warn_trigraphs = 1;
6479 opts->warn_comments = 1;
6480 }
6481 break;
6482
6483 case 'M':
6484 /* The style of the choices here is a bit mixed.
6485 The chosen scheme is a hybrid of keeping all options in one string
6486 and specifying each option in a separate argument:
6487 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
6488 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
6489 -M[M][G][D file]. This is awkward to handle in specs, and is not
6490 as extensible. */
6491 /* ??? -MG must be specified in addition to one of -M or -MM.
6492 This can be relaxed in the future without breaking anything.
6493 The converse isn't true. */
6494
6495 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
6496 if (!strcmp (argv[i], "-MG"))
6497 {
6498 opts->print_deps_missing_files = 1;
6499 break;
6500 }
6501 if (!strcmp (argv[i], "-M"))
6502 opts->print_deps = 2;
6503 else if (!strcmp (argv[i], "-MM"))
6504 opts->print_deps = 1;
6505 else if (!strcmp (argv[i], "-MD"))
6506 opts->print_deps = 2;
6507 else if (!strcmp (argv[i], "-MMD"))
6508 opts->print_deps = 1;
6509 /* For -MD and -MMD options, write deps on file named by next arg. */
6510 if (!strcmp (argv[i], "-MD") || !strcmp (argv[i], "-MMD"))
6511 {
6512 if (i+1 == argc)
a94c94be 6513 goto missing_filename;
7f2935c7
PB
6514 opts->deps_file = argv[++i];
6515 }
6516 else
6517 {
6518 /* For -M and -MM, write deps on standard output
6519 and suppress the usual output. */
6520 opts->no_output = 1;
6521 }
6522 break;
6523
6524 case 'd':
6525 {
6526 char *p = argv[i] + 2;
6527 char c;
6528 while ((c = *p++) != 0) {
6529 /* Arg to -d specifies what parts of macros to dump */
6530 switch (c) {
6531 case 'M':
6532 opts->dump_macros = dump_only;
6533 opts->no_output = 1;
6534 break;
6535 case 'N':
6536 opts->dump_macros = dump_names;
6537 break;
6538 case 'D':
6539 opts->dump_macros = dump_definitions;
6540 break;
6541 }
6542 }
6543 }
6544 break;
6545
6546 case 'g':
6547 if (argv[i][2] == '3')
6548 opts->debug_output = 1;
6549 break;
6550
6551 case 'v':
6552 fprintf (stderr, "GNU CPP version %s", version_string);
6553#ifdef TARGET_VERSION
6554 TARGET_VERSION;
6555#endif
6556 fprintf (stderr, "\n");
6557 opts->verbose = 1;
6558 break;
6559
6560 case 'H':
6561 opts->print_include_names = 1;
6562 break;
6563
6564 case 'D':
6565 if (argv[i][2] != 0)
6566 push_pending (pfile, "-D", argv[i] + 2);
6567 else if (i + 1 == argc)
a94c94be
PB
6568 {
6569 cpp_fatal (pfile, "Macro name missing after -D option");
6570 return argc;
6571 }
7f2935c7
PB
6572 else
6573 i++, push_pending (pfile, "-D", argv[i]);
6574 break;
6575
6576 case 'A':
6577 {
6578 char *p;
6579
6580 if (argv[i][2] != 0)
6581 p = argv[i] + 2;
6582 else if (i + 1 == argc)
a94c94be
PB
6583 {
6584 cpp_fatal (pfile, "Assertion missing after -A option");
6585 return argc;
6586 }
7f2935c7
PB
6587 else
6588 p = argv[++i];
6589
6590 if (!strcmp (p, "-")) {
6591 struct cpp_pending **ptr;
6592 /* -A- eliminates all predefined macros and assertions.
6593 Let's include also any that were specified earlier
6594 on the command line. That way we can get rid of any
6595 that were passed automatically in from GCC. */
6596 int j;
6597 opts->inhibit_predefs = 1;
6598 for (ptr = &opts->pending; *ptr != NULL; )
6599 {
6600 struct cpp_pending *pend = *ptr;
6601 if (pend->cmd && pend->cmd[0] == '-'
6602 && (pend->cmd[1] == 'D' || pend->cmd[1] == 'A'))
6603 {
6604 *ptr = pend->next;
6605 free (pend);
6606 }
6607 else
6608 ptr = &pend->next;
6609 }
6610 } else {
6611 push_pending (pfile, "-A", p);
6612 }
6613 }
6614 break;
6615
6616 case 'U': /* JF #undef something */
6617 if (argv[i][2] != 0)
6618 push_pending (pfile, "-U", argv[i] + 2);
6619 else if (i + 1 == argc)
a94c94be
PB
6620 {
6621 cpp_fatal (pfile, "Macro name missing after -U option", NULL);
6622 return argc;
6623 }
7f2935c7
PB
6624 else
6625 push_pending (pfile, "-U", argv[i+1]), i++;
6626 break;
6627
6628 case 'C':
6629 opts->put_out_comments = 1;
6630 break;
6631
6632 case 'E': /* -E comes from cc -E; ignore it. */
6633 break;
6634
6635 case 'P':
6636 opts->no_line_commands = 1;
6637 break;
6638
6639 case '$': /* Don't include $ in identifiers. */
6640 opts->dollars_in_ident = 0;
6641 break;
6642
6643 case 'I': /* Add directory to path for includes. */
6644 {
6645 struct file_name_list *dirtmp;
6646
6647 if (! CPP_OPTIONS(pfile)->ignore_srcdir
6648 && !strcmp (argv[i] + 2, "-")) {
6649 CPP_OPTIONS (pfile)->ignore_srcdir = 1;
6650 /* Don't use any preceding -I directories for #include <...>. */
6651 CPP_OPTIONS (pfile)->first_bracket_include = 0;
6652 }
6653 else {
6654 dirtmp = (struct file_name_list *)
6655 xmalloc (sizeof (struct file_name_list));
6656 dirtmp->next = 0; /* New one goes on the end */
6657 dirtmp->control_macro = 0;
6658 dirtmp->c_system_include_path = 0;
6659 if (argv[i][2] != 0)
6660 dirtmp->fname = argv[i] + 2;
6661 else if (i + 1 == argc)
a94c94be 6662 goto missing_dirname;
7f2935c7
PB
6663 else
6664 dirtmp->fname = argv[++i];
6665 dirtmp->got_name_map = 0;
6666 append_include_chain (pfile, dirtmp, dirtmp);
6667 }
6668 }
6669 break;
6670
6671 case 'n':
6672 if (!strcmp (argv[i], "-nostdinc"))
6673 /* -nostdinc causes no default include directories.
6674 You must specify all include-file directories with -I. */
6675 opts->no_standard_includes = 1;
6676 else if (!strcmp (argv[i], "-nostdinc++"))
6677 /* -nostdinc++ causes no default C++-specific include directories. */
6678 opts->no_standard_cplusplus_includes = 1;
6679#if 0
6680 else if (!strcmp (argv[i], "-noprecomp"))
6681 no_precomp = 1;
6682#endif
6683 break;
6684
6685 case 'u':
6686 /* Sun compiler passes undocumented switch "-undef".
6687 Let's assume it means to inhibit the predefined symbols. */
6688 opts->inhibit_predefs = 1;
6689 break;
6690
6691 case '\0': /* JF handle '-' as file name meaning stdin or stdout */
6692 if (opts->in_fname == NULL) {
6693 opts->in_fname = "";
6694 break;
6695 } else if (opts->out_fname == NULL) {
6696 opts->out_fname = "";
6697 break;
6698 } /* else fall through into error */
6699
6700 default:
6701 return i;
6702 }
6703 }
6704 }
6705 return i;
6706}
6707\f
6708void
6709cpp_finish (pfile)
6710 cpp_reader *pfile;
6711{
6712 struct cpp_options *opts = CPP_OPTIONS (pfile);
6713
6714 if (opts->print_deps)
6715 {
6716 /* Stream on which to print the dependency information. */
6717 FILE *deps_stream;
6718
6719 /* Don't actually write the deps file if compilation has failed. */
6720 if (pfile->errors == 0)
6721 {
6722 char *deps_mode = opts->print_deps_append ? "a" : "w";
6723 if (opts->deps_file == 0)
6724 deps_stream = stdout;
6725 else if ((deps_stream = fopen (opts->deps_file, deps_mode)) == 0)
6726 cpp_pfatal_with_name (pfile, opts->deps_file);
6727 fputs (pfile->deps_buffer, deps_stream);
6728 putc ('\n', deps_stream);
6729 if (opts->deps_file)
6730 {
6731 if (ferror (deps_stream) || fclose (deps_stream) != 0)
a94c94be 6732 cpp_fatal (pfile, "I/O error on output");
7f2935c7
PB
6733 }
6734 }
6735 }
6736}
782331f4 6737
d013f05e
PB
6738/* Free resources used by PFILE.
6739 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
782331f4
PB
6740
6741void
6742cpp_cleanup (pfile)
6743 cpp_reader *pfile;
6744{
6745 int i;
6746 while ( CPP_BUFFER (pfile) != CPP_NULL_BUFFER (pfile))
6747 cpp_pop_buffer (pfile);
6748
6749 if (pfile->token_buffer)
6750 {
6751 free (pfile->token_buffer);
6752 pfile->token_buffer = NULL;
6753 }
6754
6755 if (pfile->deps_buffer)
6756 {
6757 free (pfile->deps_buffer);
6758 pfile->deps_buffer = NULL;
6759 pfile->deps_allocated_size = 0;
6760 }
6761
6762 while (pfile->if_stack)
6763 {
6764 IF_STACK_FRAME *temp = pfile->if_stack;
6765 pfile->if_stack = temp->next;
6766 free (temp);
6767 }
6768
6769 while (pfile->dont_repeat_files)
6770 {
6771 struct file_name_list *temp = pfile->dont_repeat_files;
6772 pfile->dont_repeat_files = temp->next;
6773 free (temp->fname);
6774 free (temp);
6775 }
6776
6777 while (pfile->all_include_files)
6778 {
6779 struct file_name_list *temp = pfile->all_include_files;
6780 pfile->all_include_files = temp->next;
6781 free (temp->fname);
6782 free (temp);
6783 }
6784
6785 for (i = IMPORT_HASH_SIZE; --i >= 0; )
6786 {
6787 register struct import_file *imp = pfile->import_hash_table[i];
6788 while (imp)
6789 {
6790 struct import_file *next = imp->next;
6791 free (imp->name);
6792 free (imp);
6793 imp = next;
6794 }
6795 pfile->import_hash_table[i] = 0;
6796 }
6797
6798 for (i = ASSERTION_HASHSIZE; --i >= 0; )
6799 {
6800 while (pfile->assertion_hashtab[i])
6801 delete_assertion (pfile->assertion_hashtab[i]);
6802 }
6803
6804 cpp_hash_cleanup (pfile);
6805}
7f2935c7
PB
6806\f
6807static int
6808do_assert (pfile, keyword, buf, limit)
6809 cpp_reader *pfile;
6810 struct directive *keyword;
6811 U_CHAR *buf, *limit;
6812{
6813 long symstart; /* remember where symbol name starts */
6814 int c;
6815 int sym_length; /* and how long it is */
6816 struct arglist *tokens = NULL;
6817
6818 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
6819 && !CPP_BUFFER (pfile)->system_header_p)
6820 cpp_pedwarn (pfile, "ANSI C does not allow `#assert'");
6821
6822 cpp_skip_hspace (pfile);
6823 symstart = CPP_WRITTEN (pfile); /* remember where it starts */
6824 parse_name (pfile, GETC());
6825 sym_length = check_macro_name (pfile, pfile->token_buffer + symstart,
6826 "assertion");
6827
6828 cpp_skip_hspace (pfile);
6829 if (PEEKC() != '(') {
6830 cpp_error (pfile, "missing token-sequence in `#assert'");
6831 goto error;
6832 }
6833
6834 {
6835 int error_flag = 0;
6836 tokens = read_token_list (pfile, &error_flag);
6837 if (error_flag)
6838 goto error;
6839 if (tokens == 0) {
6840 cpp_error (pfile, "empty token-sequence in `#assert'");
6841 goto error;
6842 }
6843 cpp_skip_hspace (pfile);
6844 c = PEEKC ();
6845 if (c != EOF && c != '\n')
6846 cpp_pedwarn (pfile, "junk at end of `#assert'");
6847 skip_rest_of_line (pfile);
6848 }
6849
6850 /* If this name isn't already an assertion name, make it one.
6851 Error if it was already in use in some other way. */
6852
6853 {
6854 ASSERTION_HASHNODE *hp;
6855 U_CHAR *symname = pfile->token_buffer + symstart;
6856 int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE);
6857 struct tokenlist_list *value
6858 = (struct tokenlist_list *) xmalloc (sizeof (struct tokenlist_list));
6859
6860 hp = assertion_lookup (pfile, symname, sym_length, hashcode);
6861 if (hp == NULL) {
6862 if (sym_length == 7 && ! strncmp (symname, "defined", sym_length))
6863 cpp_error (pfile, "`defined' redefined as assertion");
6864 hp = assertion_install (pfile, symname, sym_length, hashcode);
6865 }
6866
6867 /* Add the spec'd token-sequence to the list of such. */
6868 value->tokens = tokens;
6869 value->next = hp->value;
6870 hp->value = value;
6871 }
6872 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6873 return 0;
6874 error:
6875 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6876 skip_rest_of_line (pfile);
6877 return 1;
6878}
6879\f
6880static int
6881do_unassert (pfile, keyword, buf, limit)
6882 cpp_reader *pfile;
6883 struct directive *keyword;
6884 U_CHAR *buf, *limit;
6885{
6886 long symstart; /* remember where symbol name starts */
6887 int sym_length; /* and how long it is */
6888 int c;
6889
6890 struct arglist *tokens = NULL;
6891 int tokens_specified = 0;
6892
6893 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
6894 && !CPP_BUFFER (pfile)->system_header_p)
6895 cpp_pedwarn (pfile, "ANSI C does not allow `#unassert'");
6896
6897 cpp_skip_hspace (pfile);
6898
6899 symstart = CPP_WRITTEN (pfile); /* remember where it starts */
6900 parse_name (pfile, GETC());
6901 sym_length = check_macro_name (pfile, pfile->token_buffer + symstart,
6902 "assertion");
6903
6904 cpp_skip_hspace (pfile);
6905 if (PEEKC() == '(') {
6906 int error_flag = 0;
6907
6908 tokens = read_token_list (pfile, &error_flag);
6909 if (error_flag)
6910 goto error;
6911 if (tokens == 0) {
6912 cpp_error (pfile, "empty token list in `#unassert'");
6913 goto error;
6914 }
6915
6916 tokens_specified = 1;
6917 }
6918
6919 cpp_skip_hspace (pfile);
6920 c = PEEKC ();
6921 if (c != EOF && c != '\n')
6922 cpp_error (pfile, "junk at end of `#unassert'");
6923 skip_rest_of_line (pfile);
6924
6925 {
6926 ASSERTION_HASHNODE *hp;
6927 U_CHAR *symname = pfile->token_buffer + symstart;
6928 int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE);
6929 struct tokenlist_list *tail, *prev;
6930
6931 hp = assertion_lookup (pfile, symname, sym_length, hashcode);
6932 if (hp == NULL)
6933 return 1;
6934
6935 /* If no token list was specified, then eliminate this assertion
6936 entirely. */
782331f4 6937 if (! tokens_specified)
7f2935c7 6938 delete_assertion (hp);
782331f4 6939 else {
7f2935c7
PB
6940 /* If a list of tokens was given, then delete any matching list. */
6941
6942 tail = hp->value;
6943 prev = 0;
6944 while (tail) {
6945 struct tokenlist_list *next = tail->next;
6946 if (compare_token_lists (tail->tokens, tokens)) {
6947 if (prev)
6948 prev->next = next;
6949 else
6950 hp->value = tail->next;
6951 free_token_list (tail->tokens);
6952 free (tail);
6953 } else {
6954 prev = tail;
6955 }
6956 tail = next;
6957 }
6958 }
6959 }
6960
6961 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6962 return 0;
6963 error:
6964 CPP_SET_WRITTEN (pfile, symstart); /* Pop */
6965 skip_rest_of_line (pfile);
6966 return 1;
6967}
6968\f
6969/* Test whether there is an assertion named NAME
6970 and optionally whether it has an asserted token list TOKENS.
6971 NAME is not null terminated; its length is SYM_LENGTH.
6972 If TOKENS_SPECIFIED is 0, then don't check for any token list. */
6973
6974int
6975check_assertion (pfile, name, sym_length, tokens_specified, tokens)
6976 cpp_reader *pfile;
6977 U_CHAR *name;
6978 int sym_length;
6979 int tokens_specified;
6980 struct arglist *tokens;
6981{
6982 ASSERTION_HASHNODE *hp;
6983 int hashcode = hashf (name, sym_length, ASSERTION_HASHSIZE);
6984
6985 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
6986 cpp_pedwarn (pfile, "ANSI C does not allow testing assertions");
6987
6988 hp = assertion_lookup (pfile, name, sym_length, hashcode);
6989 if (hp == NULL)
6990 /* It is not an assertion; just return false. */
6991 return 0;
6992
6993 /* If no token list was specified, then value is 1. */
6994 if (! tokens_specified)
6995 return 1;
6996
6997 {
6998 struct tokenlist_list *tail;
6999
7000 tail = hp->value;
7001
7002 /* If a list of tokens was given,
7003 then succeed if the assertion records a matching list. */
7004
7005 while (tail) {
7006 if (compare_token_lists (tail->tokens, tokens))
7007 return 1;
7008 tail = tail->next;
7009 }
7010
7011 /* Fail if the assertion has no matching list. */
7012 return 0;
7013 }
7014}
7015
7016/* Compare two lists of tokens for equality including order of tokens. */
7017
7018static int
7019compare_token_lists (l1, l2)
7020 struct arglist *l1, *l2;
7021{
7022 while (l1 && l2) {
7023 if (l1->length != l2->length)
7024 return 0;
7025 if (strncmp (l1->name, l2->name, l1->length))
7026 return 0;
7027 l1 = l1->next;
7028 l2 = l2->next;
7029 }
7030
7031 /* Succeed if both lists end at the same time. */
7032 return l1 == l2;
7033}
7034\f
7035struct arglist *
7036reverse_token_list (tokens)
7037 struct arglist *tokens;
7038{
7039 register struct arglist *prev = 0, *this, *next;
7040 for (this = tokens; this; this = next)
7041 {
7042 next = this->next;
7043 this->next = prev;
7044 prev = this;
7045 }
7046 return prev;
7047}
7048
7049/* Read a space-separated list of tokens ending in a close parenthesis.
7050 Return a list of strings, in the order they were written.
7051 (In case of error, return 0 and store -1 in *ERROR_FLAG.) */
7052
7053static struct arglist *
7054read_token_list (pfile, error_flag)
7055 cpp_reader *pfile;
7056 int *error_flag;
7057{
7058 struct arglist *token_ptrs = 0;
7059 int depth = 1;
7060 int length;
7061
7062 *error_flag = 0;
7063 FORWARD (1); /* Skip '(' */
7064
7065 /* Loop over the assertion value tokens. */
7066 while (depth > 0)
7067 {
7068 struct arglist *temp;
7069 long name_written = CPP_WRITTEN (pfile);
7070 int eofp = 0; int c;
7071
7072 cpp_skip_hspace (pfile);
7073
7074 c = GETC ();
7075
7076 /* Find the end of the token. */
7077 if (c == '(')
7078 {
7079 CPP_PUTC (pfile, c);
7080 depth++;
7081 }
7082 else if (c == ')')
7083 {
7084 depth--;
7085 if (depth == 0)
7086 break;
7087 CPP_PUTC (pfile, c);
7088 }
7089 else if (c == '"' || c == '\'')
7090 {
7091 FORWARD(-1);
7092 cpp_get_token (pfile);
7093 }
7094 else if (c == '\n')
7095 break;
7096 else
7097 {
7098 while (c != EOF && ! is_space[c] && c != '(' && c != ')'
7099 && c != '"' && c != '\'')
7100 {
7101 CPP_PUTC (pfile, c);
7102 c = GETC();
7103 }
7104 if (c != EOF) FORWARD(-1);
7105 }
7106
7107 length = CPP_WRITTEN (pfile) - name_written;
7108 temp = (struct arglist *)
7109 xmalloc (sizeof (struct arglist) + length + 1);
7110 temp->name = (U_CHAR *) (temp + 1);
7111 bcopy ((char *) (pfile->token_buffer + name_written),
7112 (char *) temp->name, length);
7113 temp->name[length] = 0;
7114 temp->next = token_ptrs;
7115 token_ptrs = temp;
7116 temp->length = length;
7117
7118 CPP_ADJUST_WRITTEN (pfile, -length); /* pop */
7119
7120 if (c == EOF || c == '\n')
7121 { /* FIXME */
7122 cpp_error (pfile,
7123 "unterminated token sequence following `#' operator");
7124 return 0;
7125 }
7126 }
7127
7128 /* We accumulated the names in reverse order.
7129 Now reverse them to get the proper order. */
7130 return reverse_token_list (token_ptrs);
7131}
7132
7133static void
7134free_token_list (tokens)
7135 struct arglist *tokens;
7136{
7137 while (tokens) {
7138 struct arglist *next = tokens->next;
7139 free (tokens->name);
7140 free (tokens);
7141 tokens = next;
7142 }
7143}
7144\f
7145/* Get the file-mode and data size of the file open on FD
7146 and store them in *MODE_POINTER and *SIZE_POINTER. */
7147
7148static int
7149file_size_and_mode (fd, mode_pointer, size_pointer)
7150 int fd;
7151 int *mode_pointer;
7152 long int *size_pointer;
7153{
7154 struct stat sbuf;
7155
7156 if (fstat (fd, &sbuf) < 0) return (-1);
7157 if (mode_pointer) *mode_pointer = sbuf.st_mode;
7158 if (size_pointer) *size_pointer = sbuf.st_size;
7159 return 0;
7160}
7161
7162/* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
7163 retrying if necessary. Return a negative value if an error occurs,
7164 otherwise return the actual number of bytes read,
7165 which must be LEN unless end-of-file was reached. */
7166
7167static int
7168safe_read (desc, ptr, len)
7169 int desc;
7170 char *ptr;
7171 int len;
7172{
7173 int left = len;
7174 while (left > 0) {
7175 int nchars = read (desc, ptr, left);
7176 if (nchars < 0)
7177 {
7178#ifdef EINTR
7179 if (errno == EINTR)
7180 continue;
7181#endif
7182 return nchars;
7183 }
7184 if (nchars == 0)
7185 break;
7186 ptr += nchars;
7187 left -= nchars;
7188 }
7189 return len - left;
7190}
7191
e2f79f3c
PB
7192static char *
7193xcalloc (number, size)
7194 unsigned number, size;
7195{
7196 register unsigned total = number * size;
7197 register char *ptr = (char *) xmalloc (total);
7198 bzero (ptr, total);
7199 return ptr;
7200}
7201
7f2935c7
PB
7202static char *
7203savestring (input)
7204 char *input;
7205{
7206 unsigned size = strlen (input);
7207 char *output = xmalloc (size + 1);
7208 strcpy (output, input);
7209 return output;
7210}
7211\f
7f2935c7
PB
7212/* Initialize PMARK to remember the current position of PFILE. */
7213void
7214parse_set_mark (pmark, pfile)
7215 struct parse_marker *pmark;
7216 cpp_reader *pfile;
7217{
7218 cpp_buffer *pbuf = CPP_BUFFER (pfile);
7219 pmark->next = pbuf->marks;
7220 pbuf->marks = pmark;
7221 pmark->buf = pbuf;
7222 pmark->position = pbuf->cur - pbuf->buf;
7223}
7224
7225/* Cleanup PMARK - we no longer need it. */
7226void
7227parse_clear_mark (pmark)
7228 struct parse_marker *pmark;
7229{
7230 struct parse_marker **pp = &pmark->buf->marks;
7231 for (; ; pp = &(*pp)->next) {
e2f79f3c 7232 if (*pp == NULL) abort ();
7f2935c7
PB
7233 if (*pp == pmark) break;
7234 }
7235 *pp = pmark->next;
7236}
7237
7238/* Backup the current position of PFILE to that saved in PMARK. */
7239
7240void
7241parse_goto_mark (pmark, pfile)
7242 struct parse_marker *pmark;
7243 cpp_reader *pfile;
7244{
7245 cpp_buffer *pbuf = CPP_BUFFER (pfile);
7246 if (pbuf != pmark->buf)
a94c94be 7247 cpp_fatal (pfile, "internal error %s", "parse_goto_mark");
7f2935c7
PB
7248 pbuf->cur = pbuf->buf + pmark->position;
7249}
7250
7251/* Reset PMARK to point to the current position of PFILE. (Same
7252 as parse_clear_mark (PMARK), parse_set_mark (PMARK, PFILE) but faster. */
7253
7254void
7255parse_move_mark (pmark, pfile)
7256 struct parse_marker *pmark;
7257 cpp_reader *pfile;
7258{
7259 cpp_buffer *pbuf = CPP_BUFFER (pfile);
7260 if (pbuf != pmark->buf)
a94c94be 7261 cpp_fatal (pfile, "internal error %s", "parse_move_mark");
7f2935c7
PB
7262 pmark->position = pbuf->cur - pbuf->buf;
7263}
7264
7265int
7266cpp_read_check_assertion (pfile)
7267 cpp_reader *pfile;
7268{
7269 int name_start = CPP_WRITTEN (pfile);
7270 int name_length, name_written;
7271 int result;
7272 FORWARD (1); /* Skip '#' */
7273 cpp_skip_hspace (pfile);
7274 parse_name (pfile, GETC ());
7275 name_written = CPP_WRITTEN (pfile);
7276 name_length = name_written - name_start;
7277 cpp_skip_hspace (pfile);
7278 if (CPP_BUF_PEEK (CPP_BUFFER (pfile)) == '(')
7279 {
7280 int error_flag;
7281 struct arglist *token_ptrs = read_token_list (pfile, &error_flag);
7282 result = check_assertion (pfile,
7283 pfile->token_buffer + name_start, name_length,
7284 1, token_ptrs);
7285 }
7286 else
7287 result = check_assertion (pfile,
7288 pfile->token_buffer + name_start, name_length,
7289 0, NULL_PTR);
7290 CPP_ADJUST_WRITTEN (pfile, - name_length); /* pop */
7291 return result;
7292}
355142da
PB
7293\f
7294void
7295cpp_print_file_and_line (pfile)
7296 cpp_reader *pfile;
7297{
7298 cpp_buffer *ip = cpp_file_buffer (pfile);
7299
7300 if (ip != NULL)
7301 {
7302 long line, col;
7303 cpp_buf_line_and_col (ip, &line, &col);
7304 cpp_file_line_for_message (pfile, ip->nominal_fname,
7305 line, pfile->show_column ? col : -1);
7306 }
7307}
7308
7309void
7310cpp_error (pfile, msg, arg1, arg2, arg3)
7311 cpp_reader *pfile;
7312 char *msg;
7313 char *arg1, *arg2, *arg3;
7314{
7315 cpp_print_containing_files (pfile);
7316 cpp_print_file_and_line (pfile);
7317 cpp_message (pfile, 1, msg, arg1, arg2, arg3);
7318}
7319
7320/* Print error message but don't count it. */
7321
7322void
7323cpp_warning (pfile, msg, arg1, arg2, arg3)
7324 cpp_reader *pfile;
7325 char *msg;
7326 char *arg1, *arg2, *arg3;
7327{
7328 if (CPP_OPTIONS (pfile)->inhibit_warnings)
7329 return;
7330
7331 if (CPP_OPTIONS (pfile)->warnings_are_errors)
7332 pfile->errors++;
7333
7334 cpp_print_containing_files (pfile);
7335 cpp_print_file_and_line (pfile);
7336 cpp_message (pfile, 0, msg, arg1, arg2, arg3);
7337}
7338
7339/* Print an error message and maybe count it. */
7340
7341void
7342cpp_pedwarn (pfile, msg, arg1, arg2, arg3)
7343 cpp_reader *pfile;
7344 char *msg;
7345 char *arg1, *arg2, *arg3;
7346{
7347 if (CPP_OPTIONS (pfile)->pedantic_errors)
7348 cpp_error (pfile, msg, arg1, arg2, arg3);
7349 else
7350 cpp_warning (pfile, msg, arg1, arg2, arg3);
7351}
7352
7353void
3232050c 7354cpp_error_with_line (pfile, line, column, msg, arg1, arg2, arg3)
355142da 7355 cpp_reader *pfile;
3232050c 7356 int line, column;
355142da
PB
7357 char *msg;
7358 char *arg1, *arg2, *arg3;
7359{
7360 int i;
7361 cpp_buffer *ip = cpp_file_buffer (pfile);
7362
7363 cpp_print_containing_files (pfile);
7364
7365 if (ip != NULL)
3232050c 7366 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
355142da
PB
7367
7368 cpp_message (pfile, 1, msg, arg1, arg2, arg3);
7369}
7370
3232050c
PB
7371static void
7372cpp_warning_with_line (pfile, line, column, msg, arg1, arg2, arg3)
355142da 7373 cpp_reader *pfile;
3232050c 7374 int line, column;
355142da
PB
7375 char *msg;
7376 char *arg1, *arg2, *arg3;
7377{
7378 int i;
7379 cpp_buffer *ip;
7380
7381 if (CPP_OPTIONS (pfile)->inhibit_warnings)
7382 return;
7383
7384 if (CPP_OPTIONS (pfile)->warnings_are_errors)
7385 pfile->errors++;
7386
7387 cpp_print_containing_files (pfile);
7388
7389 ip = cpp_file_buffer (pfile);
7390
7391 if (ip != NULL)
3232050c 7392 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
355142da
PB
7393
7394 cpp_message (pfile, 0, msg, arg1, arg2, arg3);
7395}
7396
7397void
3232050c 7398cpp_pedwarn_with_line (pfile, line, column, msg, arg1, arg2, arg3)
355142da
PB
7399 cpp_reader *pfile;
7400 int line;
7401 char *msg;
7402 char *arg1, *arg2, *arg3;
7403{
7404 if (CPP_OPTIONS (pfile)->pedantic_errors)
3232050c 7405 cpp_error_with_line (pfile, column, line, msg, arg1, arg2, arg3);
355142da 7406 else
3232050c 7407 cpp_warning_with_line (pfile, line, column, msg, arg1, arg2, arg3);
355142da
PB
7408}
7409
7410/* Report a warning (or an error if pedantic_errors)
7411 giving specified file name and line number, not current. */
7412
7413void
7414cpp_pedwarn_with_file_and_line (pfile, file, line, msg, arg1, arg2, arg3)
7415 cpp_reader *pfile;
7416 char *file;
7417 int line;
7418 char *msg;
7419 char *arg1, *arg2, *arg3;
7420{
7421 if (!CPP_OPTIONS (pfile)->pedantic_errors
7422 && CPP_OPTIONS (pfile)->inhibit_warnings)
7423 return;
7424 if (file != NULL)
7425 cpp_file_line_for_message (pfile, file, line, -1);
7426 cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors,
7427 msg, arg1, arg2, arg3);
7428}
7429
7430/* This defines "errno" properly for VMS, and gives us EACCES. */
7431#include <errno.h>
7432#ifndef errno
7433extern int errno;
7434#endif
7435
7436#ifndef VMS
7437#ifndef HAVE_STRERROR
7438extern int sys_nerr;
7439#if defined(bsd4_4)
7440extern const char *const sys_errlist[];
7441#else
7442extern char *sys_errlist[];
7443#endif
ddd5a7c1 7444#else /* HAVE_STRERROR */
355142da
PB
7445char *strerror ();
7446#endif
7447#else /* VMS */
7448char *strerror (int,...);
7449#endif
7450
7451/*
7452 * my_strerror - return the descriptive text associated with an `errno' code.
7453 */
7454
7455char *
7456my_strerror (errnum)
7457 int errnum;
7458{
7459 char *result;
7460
7461#ifndef VMS
7462#ifndef HAVE_STRERROR
7463 result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
7464#else
7465 result = strerror (errnum);
7466#endif
7467#else /* VMS */
7468 /* VAXCRTL's strerror() takes an optional second argument, which only
7469 matters when the first argument is EVMSERR. However, it's simplest
7470 just to pass it unconditionally. `vaxc$errno' is declared in
7471 <errno.h>, and maintained by the library in parallel with `errno'.
7472 We assume that caller's `errnum' either matches the last setting of
7473 `errno' by the library or else does not have the value `EVMSERR'. */
7474
7475 result = strerror (errnum, vaxc$errno);
7476#endif
7477
7478 if (!result)
7479 result = "undocumented I/O error";
7480
7481 return result;
7482}
7483
7484/* Error including a message from `errno'. */
7485
7486void
7487cpp_error_from_errno (pfile, name)
7488 cpp_reader *pfile;
7489 char *name;
7490{
7491 int i;
7492 cpp_buffer *ip = cpp_file_buffer (pfile);
7493
7494 cpp_print_containing_files (pfile);
7495
7496 if (ip != NULL)
7497 cpp_file_line_for_message (pfile, ip->nominal_fname, ip->lineno, -1);
7498
22bbceaf 7499 cpp_message (pfile, 1, "%s: %s", name, my_strerror (errno));
355142da
PB
7500}
7501
7502void
7503cpp_perror_with_name (pfile, name)
7504 cpp_reader *pfile;
7505 char *name;
7506{
22bbceaf 7507 cpp_message (pfile, 1, "%s: %s: %s", progname, name, my_strerror (errno));
355142da 7508}
7f2935c7
PB
7509
7510/* TODO:
7511 * No pre-compiled header file support.
7512 *
7513 * Possibly different enum token codes for each C/C++ token.
7514 *
7f2935c7
PB
7515 * Should clean up remaining directives to that do_XXX functions
7516 * only take two arguments and all have command_reads_line.
7517 *
7518 * Find and cleanup remaining uses of static variables,
7519 *
7520 * Support for trigraphs.
7521 *
7522 * Support -dM flag (dump_all_macros).
782331f4
PB
7523 *
7524 * Support for_lint flag.
7f2935c7 7525 */
This page took 0.918994 seconds and 5 git commands to generate.