OSDN Git Service

Jan Hubicka <hubicka@freesoft.cz>
[pf3gnuchains/gcc-fork.git] / gcc / cpplib.c
1 /* CPP Library.
2    Copyright (C) 1986, 87, 89, 92-98, 1999 Free Software Foundation, Inc.
3    Contributed by Per Bothner, 1994-95.
4    Based on CCCP program by Paul Rubin, June 1986
5    Adapted to ANSI C, Richard Stallman, Jan 1987
6
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20
21 #include "config.h"
22 #include "system.h"
23
24 #include "cpplib.h"
25 #include "cpphash.h"
26 #include "intl.h"
27
28 #define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
29 #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
30
31 #define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? CPP_BUFFER (pfile)->cur[N] : EOF)
32 #define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N))
33 #define GETC() CPP_BUF_GET (CPP_BUFFER (pfile))
34 #define PEEKC() CPP_BUF_PEEK (CPP_BUFFER (pfile))
35 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
36    (Note that it is false while we're expanding macro *arguments*.) */
37 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->data != NULL)
38
39 /* Forward declarations.  */
40
41 static const char *my_strerror          PROTO ((int));
42 static void validate_else               PROTO ((cpp_reader *, const char *));
43 static HOST_WIDEST_INT eval_if_expression       PROTO ((cpp_reader *));
44
45 static void conditional_skip            PROTO ((cpp_reader *, int,
46                                                 enum node_type, U_CHAR *));
47 static void skip_if_group               PROTO ((cpp_reader *));
48
49 static void parse_name                  PARAMS ((cpp_reader *, int));
50 static void parse_string                PARAMS ((cpp_reader *, int));
51 static int parse_assertion              PARAMS ((cpp_reader *));
52
53 /* External declarations.  */
54
55 extern HOST_WIDEST_INT cpp_parse_expr PARAMS ((cpp_reader *));
56
57 /* `struct directive' defines one #-directive, including how to handle it.  */
58
59 struct directive {
60   int length;                   /* Length of name */
61   int (*func)                   /* Function to handle directive */
62     PARAMS ((cpp_reader *, const struct directive *));
63   const char *name;             /* Name of directive */
64   enum node_type type;          /* Code which describes which directive.  */
65 };
66
67 /* These functions are declared to return int instead of void since they
68    are going to be placed in a table and some old compilers have trouble with
69    pointers to functions returning void.  */
70
71 static int do_define PARAMS ((cpp_reader *, const struct directive *));
72 static int do_line PARAMS ((cpp_reader *, const struct directive *));
73 static int do_include PARAMS ((cpp_reader *, const struct directive *));
74 static int do_undef PARAMS ((cpp_reader *, const struct directive *));
75 static int do_error PARAMS ((cpp_reader *, const struct directive *));
76 static int do_pragma PARAMS ((cpp_reader *, const struct directive *));
77 static int do_ident PARAMS ((cpp_reader *, const struct directive *));
78 static int do_if PARAMS ((cpp_reader *, const struct directive *));
79 static int do_xifdef PARAMS ((cpp_reader *, const struct directive *));
80 static int do_else PARAMS ((cpp_reader *, const struct directive *));
81 static int do_elif PARAMS ((cpp_reader *, const struct directive *));
82 static int do_endif PARAMS ((cpp_reader *, const struct directive *));
83 #ifdef SCCS_DIRECTIVE
84 static int do_sccs PARAMS ((cpp_reader *, const struct directive *));
85 #endif
86 static int do_assert PARAMS ((cpp_reader *, const struct directive *));
87 static int do_unassert PARAMS ((cpp_reader *, const struct directive *));
88 static int do_warning PARAMS ((cpp_reader *, const struct directive *));
89 static enum cpp_token null_underflow PARAMS ((cpp_reader *));
90 static int null_cleanup PARAMS ((cpp_buffer *, cpp_reader *));
91 static int skip_comment PARAMS ((cpp_reader *, int));
92 static int copy_comment PARAMS ((cpp_reader *, int));
93 static void copy_rest_of_line PARAMS ((cpp_reader *));
94 static int handle_directive PARAMS ((cpp_reader *));
95 static void pass_thru_directive PARAMS ((const U_CHAR *, size_t, cpp_reader *,
96                                          const struct directive *));
97 static enum cpp_token get_directive_token PARAMS ((cpp_reader *));
98 static int read_line_number PARAMS ((cpp_reader *, int *));
99 static void cpp_print_file_and_line PARAMS ((cpp_reader *));
100 static void v_cpp_error PARAMS ((cpp_reader *, const char *, va_list));
101 static void v_cpp_warning PARAMS ((cpp_reader *, const char *, va_list));
102 static void v_cpp_error_with_line PARAMS ((cpp_reader *, int, int,
103                                            const char *, va_list));
104 static void v_cpp_warning_with_line PARAMS ((cpp_reader *, int, int, const char *, va_list));
105 static U_CHAR *detect_if_not_defined PARAMS ((cpp_reader *));
106 static int consider_directive_while_skipping PARAMS ((cpp_reader *, IF_STACK_FRAME *));
107
108 /* Here is the actual list of #-directives.
109    This table is ordered by frequency of occurrence; the numbers
110    at the end are directive counts from all the source code I have
111    lying around (egcs and libc CVS as of 1999-05-18, plus grub-0.5.91,
112    linux-2.2.9, and pcmcia-cs-3.0.9).  */
113
114 static const struct directive directive_table[] = {
115   /* In C89 */
116   {  6, do_define,   "define",       T_DEFINE },        /* 270554 */
117   {  7, do_include,  "include",      T_INCLUDE },       /*  52262 */
118   {  5, do_endif,    "endif",        T_ENDIF },         /*  45855 */
119   {  5, do_xifdef,   "ifdef",        T_IFDEF },         /*  22000 */
120   {  2, do_if,       "if",           T_IF },            /*  18162 */
121   {  4, do_else,     "else",         T_ELSE },          /*   9863 */
122   {  6, do_xifdef,   "ifndef",       T_IFNDEF },        /*   9675 */
123   {  5, do_undef,    "undef",        T_UNDEF },         /*   4837 */
124   {  4, do_line,     "line",         T_LINE },          /*   2465 */
125   {  4, do_elif,     "elif",         T_ELIF },          /*    610 */
126   {  5, do_error,    "error",        T_ERROR },         /*    475 */
127   {  6, do_pragma,   "pragma",       T_PRAGMA },        /*    195 */
128
129   /* Extensions.  All deprecated except #warning and #include_next.  */
130   {  7, do_warning,  "warning",      T_WARNING },       /*     22 - GNU   */
131   { 12, do_include,  "include_next", T_INCLUDE_NEXT },  /*     19 - GNU   */
132   {  5, do_ident,    "ident",        T_IDENT },         /*     11 - SVR4  */
133   {  6, do_include,  "import",       T_IMPORT },        /*      0 - ObjC  */
134   {  6, do_assert,   "assert",       T_ASSERT },        /*      0 - SVR4  */
135   {  8, do_unassert, "unassert",     T_UNASSERT },      /*      0 - SVR4  */
136 #ifdef SCCS_DIRECTIVE
137   {  4, do_sccs,     "sccs",         T_SCCS },          /*      0 - SVR2? */
138 #endif
139   {  -1, 0, "", T_UNUSED }
140 };
141
142 /* Place into PFILE a quoted string representing the string SRC.
143    Caller must reserve enough space in pfile->token_buffer.  */
144
145 void
146 quote_string (pfile, src)
147      cpp_reader *pfile;
148      const char *src;
149 {
150   U_CHAR c;
151
152   CPP_PUTC_Q (pfile, '\"');
153   for (;;)
154     switch ((c = *src++))
155       {
156       default:
157         if (ISPRINT (c))
158           CPP_PUTC_Q (pfile, c);
159         else
160           {
161             sprintf ((char *)CPP_PWRITTEN (pfile), "\\%03o", c);
162             CPP_ADJUST_WRITTEN (pfile, 4);
163           }
164         break;
165
166       case '\"':
167       case '\\':
168         CPP_PUTC_Q (pfile, '\\');
169         CPP_PUTC_Q (pfile, c);
170         break;
171       
172       case '\0':
173         CPP_PUTC_Q (pfile, '\"');
174         CPP_NUL_TERMINATE_Q (pfile);
175         return;
176       }
177 }
178
179 /* Re-allocates PFILE->token_buffer so it will hold at least N more chars.  */
180
181 void
182 cpp_grow_buffer (pfile, n)
183      cpp_reader *pfile;
184      long n;
185 {
186   long old_written = CPP_WRITTEN (pfile);
187   pfile->token_buffer_size = n + 2 * pfile->token_buffer_size;
188   pfile->token_buffer = (U_CHAR *)
189     xrealloc(pfile->token_buffer, pfile->token_buffer_size);
190   CPP_SET_WRITTEN (pfile, old_written);
191 }
192
193 /* Process the string STR as if it appeared as the body of a #define
194    If STR is just an identifier, define it with value 1.
195    If STR has anything after the identifier, then it should
196    be identifier=definition. */
197
198 void
199 cpp_define (pfile, str)
200      cpp_reader *pfile;
201      U_CHAR *str;
202 {
203   U_CHAR *buf, *p;
204   size_t count;
205
206   /* Copy the entire option so we can modify it.  */
207   count = strlen (str) + 3;
208   buf = (U_CHAR *) alloca (count);
209   memcpy (buf, str, count - 2);
210   /* Change the first "=" in the string to a space.  If there is none,
211      tack " 1" on the end. */
212   p = (U_CHAR *) strchr (buf, '=');
213   if (p)
214     {
215       *p = ' ';
216       count -= 2;
217     }
218   else
219       strcpy (&buf[count-3], " 1");
220   
221   if (cpp_push_buffer (pfile, buf, count - 1) != NULL)
222     {
223       do_define (pfile, NULL);
224       cpp_pop_buffer (pfile);
225     }
226 }
227
228 /* Process the string STR as if it appeared as the body of a #assert. */
229 void
230 cpp_assert (pfile, str)
231      cpp_reader *pfile;
232      U_CHAR *str;
233 {
234   if (cpp_push_buffer (pfile, str, strlen (str)) != NULL)
235     {
236       do_assert (pfile, NULL);
237       cpp_pop_buffer (pfile);
238     }
239 }
240
241
242 static enum cpp_token
243 null_underflow (pfile)
244      cpp_reader *pfile ATTRIBUTE_UNUSED;
245 {
246   return CPP_EOF;
247 }
248
249 static int
250 null_cleanup (pbuf, pfile)
251      cpp_buffer *pbuf ATTRIBUTE_UNUSED;
252      cpp_reader *pfile ATTRIBUTE_UNUSED;
253 {
254   return 0;
255 }
256
257 /* Skip a comment - C, C++, or Chill style.  M is the first character
258    of the comment marker.  If this really is a comment, skip to its
259    end and return ' '.  If we hit end-of-file before end-of-comment,
260    return EOF.  If this is not a comment, return M (which will be
261    '/' or '-').  */
262
263 static int
264 skip_comment (pfile, m)
265      cpp_reader *pfile;
266      int m;
267 {
268   if (m == '/' && PEEKC() == '*')
269     {
270       int c, prev_c = -1;
271       long line, col;
272       
273       FORWARD(1);
274       cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col);
275       for (;;)
276         {
277           c = GETC ();
278           if (c == EOF)
279             {
280               cpp_error_with_line (pfile, line, col, "unterminated comment");
281               return EOF;
282             }
283           else if (c == '\n' || c == '\r')
284             /* \r cannot be a macro escape marker here. */
285             CPP_BUMP_LINE (pfile);
286           else if (c == '/' && prev_c == '*')
287             return ' ';
288           else if (c == '*' && prev_c == '/'
289                    && CPP_OPTIONS (pfile)->warn_comments)
290             cpp_warning (pfile, "`/*' within comment");
291
292           prev_c = c;
293         }
294     }
295   else if ((m == '/' && PEEKC() == '/'
296             && CPP_OPTIONS (pfile)->cplusplus_comments)
297            || (m == '-' && PEEKC() == '-'
298                && CPP_OPTIONS (pfile)->chill))
299     {
300       FORWARD(1);
301       for (;;)
302         {
303           int c = GETC ();
304           if (c == EOF)
305             return ' '; /* Allow // to be terminated by EOF.  */
306               if (c == '\n')
307                 {
308                   /* Don't consider final '\n' to be part of comment.  */
309                   FORWARD(-1);
310                   return ' ';
311                 }
312               else if (c == '\r')
313                 /* \r cannot be a macro escape marker here. */
314                 CPP_BUMP_LINE (pfile);
315         }
316     }
317   else
318     return m;
319 }
320
321 /* Identical to skip_comment except that it copies the comment into the
322    token_buffer.  This is used if put_out_comments.  */
323 static int
324 copy_comment (pfile, m)
325      cpp_reader *pfile;
326      int m;
327 {
328   if (m == '/' && PEEKC() == '*')
329     {
330       int c, prev_c = -1;
331       long line, col;
332
333       CPP_PUTC (pfile, '/');
334       CPP_PUTC (pfile, '*');
335       FORWARD(1);
336       cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col);
337       for (;;)
338         {
339           c = GETC ();
340           if (c == EOF)
341             {
342               cpp_error_with_line (pfile, line, col, "unterminated comment");
343               /* We must pretend this was a legitimate comment, so that the
344                  output in token_buffer is not passed back tagged CPP_POP. */
345               return ' ';
346             }
347           else if (c == '\r')
348             {
349               /* \r cannot be a macro escape marker here. */
350               CPP_BUMP_LINE (pfile);
351               continue;
352             }
353
354           CPP_PUTC (pfile, c);
355           if (c == '\n')
356             {
357               pfile->lineno++;
358               CPP_BUMP_LINE (pfile);
359             }
360           else if (c == '/' && prev_c == '*')
361             return ' ';
362           else if (c == '*' && prev_c == '/'
363                    && CPP_OPTIONS (pfile)->warn_comments)
364             cpp_warning (pfile, "`/*' within comment");
365
366           prev_c = c;
367         }
368     }
369   else if ((m == '/' && PEEKC() == '/'
370             && CPP_OPTIONS (pfile)->cplusplus_comments)
371            || (m == '-' && PEEKC() == '-'
372                && CPP_OPTIONS (pfile)->chill))
373     {
374       CPP_PUTC (pfile, m);
375       CPP_PUTC (pfile, m);
376       FORWARD(1);
377       for (;;)
378         {
379           int c = GETC ();
380           if (c == EOF)
381             return ' '; /* Allow line comments to be terminated by EOF. */
382           else if (c == '\n')
383             {
384               /* Don't consider final '\n' to be part of comment.  */
385               FORWARD(-1);
386               return ' ';
387             }
388           else if (c == '\r')
389             /* \r cannot be a macro escape marker here. */
390             CPP_BUMP_LINE (pfile);
391
392           CPP_PUTC (pfile, c);
393         }
394     }
395   else
396     return m;
397 }
398
399
400 /* Skip whitespace \-newline and comments.  Does not macro-expand.  */
401
402 void
403 cpp_skip_hspace (pfile)
404      cpp_reader *pfile;
405 {
406   int c;
407   while (1)
408     {
409       c = GETC();
410       if (c == EOF)
411         return;
412       else if (is_hor_space[c])
413         {
414           if ((c == '\f' || c == '\v') && CPP_PEDANTIC (pfile))
415             cpp_pedwarn (pfile, "%s in preprocessing directive",
416                          c == '\f' ? "formfeed" : "vertical tab");
417         }
418       else if (c == '\r')
419         {
420           /* \r is a backslash-newline marker if !has_escapes, and
421              a deletable-whitespace or no-reexpansion marker otherwise. */
422           if (CPP_BUFFER (pfile)->has_escapes)
423             {
424               if (PEEKC() == ' ')
425                 FORWARD(1);
426               else
427                 break;
428             }
429           else
430             CPP_BUFFER (pfile)->lineno++;
431         }
432       else if (c == '/' || c == '-')
433         {
434           c = skip_comment (pfile, c);
435           if (c == EOF)
436             return;
437           else if (c != ' ')
438             break;
439         }
440       else
441         break;
442     }
443   FORWARD(-1);
444 }
445
446 /* Read the rest of the current line.
447    The line is appended to PFILE's output buffer.  */
448
449 static void
450 copy_rest_of_line (pfile)
451      cpp_reader *pfile;
452 {
453   for (;;)
454     {
455       int c = GETC();
456       switch (c)
457         {
458         case '\n':
459           FORWARD(-1);
460         case EOF:
461           CPP_NUL_TERMINATE (pfile);
462           return;
463
464         case '\r':
465           if (CPP_BUFFER (pfile)->has_escapes)
466             break;
467           else
468             {
469               CPP_BUFFER (pfile)->lineno++;
470               continue;
471             }
472         case '\'':
473         case '\"':
474           parse_string (pfile, c);
475           continue;
476         case '/':
477           if (PEEKC() == '*' && CPP_TRADITIONAL (pfile))
478             {
479               CPP_PUTS (pfile, "/**/", 4);
480               skip_comment (pfile, c);
481               continue;
482             }
483           /* else fall through */
484         case '-':
485           c = skip_comment (pfile, c);
486           break;
487
488         case '\f':
489         case '\v':
490           if (CPP_PEDANTIC (pfile))
491             cpp_pedwarn (pfile, "%s in preprocessing directive",
492                          c == '\f' ? "formfeed" : "vertical tab");
493           break;
494
495         }
496       CPP_PUTC (pfile, c);
497     }
498 }
499
500 /* FIXME: It is almost definitely a performance win to make this do
501    the scan itself.  >75% of calls to copy_r_o_l are from here or
502    skip_if_group, which means the common case is to copy stuff into the
503    token_buffer only to discard it.  */
504 void
505 skip_rest_of_line (pfile)
506      cpp_reader *pfile;
507 {
508   long old = CPP_WRITTEN (pfile);
509   copy_rest_of_line (pfile);
510   CPP_SET_WRITTEN (pfile, old);
511 }
512
513 /* Handle a possible # directive.
514    '#' has already been read.  */
515
516 static int
517 handle_directive (pfile)
518      cpp_reader *pfile;
519 {
520   int c;
521   register const struct directive *kt;
522   int ident_length;
523   U_CHAR *ident;
524   long old_written = CPP_WRITTEN (pfile);
525
526   cpp_skip_hspace (pfile);
527
528   c = PEEKC ();
529   if (c >= '0' && c <= '9')
530     {
531       /* Handle # followed by a line number.  Complain about using that
532          form if we're being pedantic, but not if this is regurgitated
533          input (preprocessed or fed back in by the C++ frontend).  */
534       if (CPP_PEDANTIC (pfile)
535           && ! CPP_PREPROCESSED (pfile)
536           && ! CPP_BUFFER (pfile)->manual_pop)
537         cpp_pedwarn (pfile, "`#' followed by integer");
538       do_line (pfile, NULL);
539       return 1;
540     }
541
542   /* Now find the directive name.  */
543   CPP_PUTC (pfile, '#');
544   parse_name (pfile, GETC());
545   ident = pfile->token_buffer + old_written + 1;
546   ident_length = CPP_PWRITTEN (pfile) - ident;
547   if (ident_length == 0)
548     {
549       /* A line of just `#' becomes blank.  */
550       if (PEEKC() == '\n')
551         return 1;
552       else
553         return 0;
554     }
555
556   /*
557    * Decode the keyword and call the appropriate expansion
558    * routine, after moving the input pointer up to the next line.
559    */
560   for (kt = directive_table; ; kt++)
561     {
562       if (kt->length <= 0)
563         return 0;
564       if (kt->length == ident_length
565           && !strncmp (kt->name, ident, ident_length)) 
566         break;
567     }
568
569   CPP_SET_WRITTEN (pfile, old_written);
570   (*kt->func) (pfile, kt);
571
572   return 1;
573 }
574
575 /* Pass a directive through to the output file.
576    BUF points to the contents of the directive, as a contiguous string.
577    LEN is the length of the string pointed to by BUF.
578    KEYWORD is the keyword-table entry for the directive.  */
579
580 static void
581 pass_thru_directive (buf, len, pfile, keyword)
582      const U_CHAR *buf;
583      size_t len;
584      cpp_reader *pfile;
585      const struct directive *keyword;
586 {
587   register unsigned keyword_length = keyword->length;
588
589   CPP_RESERVE (pfile, 1 + keyword_length + len);
590   CPP_PUTC_Q (pfile, '#');
591   CPP_PUTS_Q (pfile, keyword->name, keyword_length);
592   if (len != 0 && buf[0] != ' ')
593     CPP_PUTC_Q (pfile, ' ');
594   CPP_PUTS_Q (pfile, buf, len);
595 }
596
597 /* Check a purported macro name SYMNAME, and yield its length.
598    ASSERTION is nonzero if this is really for an assertion name.  */
599
600 int
601 check_macro_name (pfile, symname, assertion)
602      cpp_reader *pfile;
603      const U_CHAR *symname;
604      int assertion;
605 {
606   const U_CHAR *p;
607   int sym_length;
608
609   for (p = symname; is_idchar[*p]; p++)
610     ;
611   sym_length = p - symname;
612   if (sym_length == 0
613       || (sym_length == 1 && *symname == 'L' && (*p == '\'' || *p == '"')))
614     cpp_error (pfile,
615                assertion ? "invalid assertion name" : "invalid macro name");
616   else if (!is_idstart[*symname]
617            || (! strncmp (symname, "defined", 7) && sym_length == 7)) {
618     U_CHAR *msg;                        /* what pain...  */
619     msg = (U_CHAR *) alloca (sym_length + 1);
620     bcopy (symname, msg, sym_length);
621     msg[sym_length] = 0;
622     cpp_error (pfile,
623                (assertion
624                 ? "invalid assertion name `%s'"
625                 : "invalid macro name `%s'"),
626                msg);
627   }
628   return sym_length;
629 }
630
631 /* Process a #define command.
632    KEYWORD is the keyword-table entry for #define,
633    or NULL for a "predefined" macro,
634    or the keyword-table entry for #pragma in the case of a #pragma poison.  */
635
636 static int
637 do_define (pfile, keyword)
638      cpp_reader *pfile;
639      const struct directive *keyword;
640 {
641   int hashcode;
642   MACRODEF mdef;
643   HASHNODE *hp;
644   long here;
645   U_CHAR *macro, *buf, *end;
646   enum node_type new_type;
647
648   here = CPP_WRITTEN (pfile);
649   copy_rest_of_line (pfile);
650
651   if (keyword == NULL || keyword->type == T_DEFINE)
652     new_type = T_MACRO;
653   else
654     new_type = T_POISON;
655
656   /* Copy out the line so we can pop the token buffer. */
657   buf = pfile->token_buffer + here;
658   end = CPP_PWRITTEN (pfile);
659   macro = (U_CHAR *) alloca (end - buf + 1);
660   bcopy (buf, macro, end - buf + 1);
661   end = macro + (end - buf);
662
663   CPP_SET_WRITTEN (pfile, here);
664
665   mdef = create_definition (macro, end, pfile, keyword == NULL);
666   if (mdef.defn == 0)
667     return 0;
668
669   hashcode = hashf (mdef.symnam, mdef.symlen, HASHSIZE);
670
671   if ((hp = cpp_lookup (pfile, mdef.symnam, mdef.symlen, hashcode)) != NULL)
672     {
673       int ok = 0;
674       /* Redefining a precompiled key is ok.  */
675       if (hp->type == T_PCSTRING)
676         ok = 1;
677       /* Redefining a poisoned identifier is even worse than `not ok'.  */
678       else if (hp->type == T_POISON)
679         ok = -1;
680       /* Redefining a macro is ok if the definitions are the same.  */
681       else if (hp->type == T_MACRO)
682         ok = ! compare_defs (pfile, mdef.defn, hp->value.defn);
683       /* Redefining a constant is ok with -D.  */
684       else if (hp->type == T_CONST || hp->type == T_STDC)
685         ok = ! CPP_OPTIONS (pfile)->done_initializing;
686       /* Print the warning or error if it's not ok.  */
687       if (ok <= 0)
688         {
689           if (hp->type == T_POISON)
690             cpp_error (pfile, "redefining poisoned `%.*s'", 
691                        mdef.symlen, mdef.symnam);
692           else
693             cpp_pedwarn (pfile, "`%.*s' redefined", mdef.symlen, mdef.symnam);
694           if (hp->type == T_MACRO)
695             cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file,
696                                             hp->value.defn->line,
697                         "this is the location of the previous definition");
698         }
699       if (hp->type != T_POISON)
700         {
701           /* Replace the old definition.  */
702           hp->type = new_type;
703           hp->value.defn = mdef.defn;
704         }
705     }
706   else
707     cpp_install (pfile, mdef.symnam, mdef.symlen, new_type,
708                  (char *) mdef.defn, hashcode);
709
710   if (keyword != NULL && keyword->type == T_DEFINE)
711     {
712       if (CPP_OPTIONS (pfile)->debug_output
713           || CPP_OPTIONS (pfile)->dump_macros == dump_definitions)
714         dump_definition (pfile, mdef);
715       else if (CPP_OPTIONS (pfile)->dump_macros == dump_names)
716         pass_thru_directive (mdef.symnam, mdef.symlen, pfile, keyword);
717     }
718
719   return 0;
720 }
721
722
723 /* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack.
724    If BUFFER != NULL, then use the LENGTH characters in BUFFER
725    as the new input buffer.
726    Return the new buffer, or NULL on failure.  */
727
728 cpp_buffer *
729 cpp_push_buffer (pfile, buffer, length)
730      cpp_reader *pfile;
731      U_CHAR *buffer;
732      long length;
733 {
734   cpp_buffer *buf = CPP_BUFFER (pfile);
735   cpp_buffer *new;
736   if (++pfile->buffer_stack_depth == CPP_STACK_MAX)
737     {
738       cpp_fatal (pfile, "macro or `#include' recursion too deep");
739       return NULL;
740     }
741
742   new = (cpp_buffer *) xcalloc (1, sizeof (cpp_buffer));
743
744   new->if_stack = pfile->if_stack;
745   new->cleanup = null_cleanup;
746   new->underflow = null_underflow;
747   new->buf = new->cur = buffer;
748   new->alimit = new->rlimit = buffer + length;
749   new->prev = buf;
750   new->mark = -1;
751
752   CPP_BUFFER (pfile) = new;
753   return new;
754 }
755
756 cpp_buffer *
757 cpp_pop_buffer (pfile)
758      cpp_reader *pfile;
759 {
760   cpp_buffer *buf = CPP_BUFFER (pfile);
761   (*buf->cleanup) (buf, pfile);
762   CPP_BUFFER (pfile) = CPP_PREV_BUFFER (buf);
763   free (buf);
764   pfile->buffer_stack_depth--;
765   return CPP_BUFFER (pfile);
766 }
767
768 /* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer.
769    Pop the buffer when done.  */
770
771 void
772 cpp_scan_buffer (pfile)
773      cpp_reader *pfile;
774 {
775   cpp_buffer *buffer = CPP_BUFFER (pfile);
776   enum cpp_token token;
777   if (CPP_OPTIONS (pfile)->no_output)
778     {
779       long old_written = CPP_WRITTEN (pfile);
780       /* In no-output mode, we can ignore everything but directives.  */
781       for (;;)
782         {
783           if (! pfile->only_seen_white)
784             skip_rest_of_line (pfile);
785           token = cpp_get_token (pfile);
786           if (token == CPP_EOF) /* Should not happen ...  */
787             break;
788           if (token == CPP_POP && CPP_BUFFER (pfile) == buffer)
789             {
790               if (CPP_PREV_BUFFER (CPP_BUFFER (pfile))
791                   != CPP_NULL_BUFFER (pfile))
792                 cpp_pop_buffer (pfile);
793               break;
794             }
795         }
796       CPP_SET_WRITTEN (pfile, old_written);
797     }
798   else
799     {
800       for (;;)
801         {
802           token = cpp_get_token (pfile);
803           if (token == CPP_EOF) /* Should not happen ...  */
804             break;
805           if (token == CPP_POP && CPP_BUFFER (pfile) == buffer)
806             {
807               if (CPP_PREV_BUFFER (CPP_BUFFER (pfile))
808                   != CPP_NULL_BUFFER (pfile))
809                 cpp_pop_buffer (pfile);
810               break;
811             }
812         }
813     }
814 }
815
816 /*
817  * Rescan a string (which may have escape marks) into pfile's buffer.
818  * Place the result in pfile->token_buffer.
819  *
820  * The input is copied before it is scanned, so it is safe to pass
821  * it something from the token_buffer that will get overwritten
822  * (because it follows CPP_WRITTEN).  This is used by do_include.
823  */
824
825 void
826 cpp_expand_to_buffer (pfile, buf, length)
827      cpp_reader *pfile;
828      const U_CHAR *buf;
829      int length;
830 {
831   register cpp_buffer *ip;
832   U_CHAR *buf1;
833   int save_no_output;
834
835   if (length < 0)
836     {
837       cpp_fatal (pfile, "internal error: length < 0 in cpp_expand_to_buffer");
838       return;
839     }
840
841   /* Set up the input on the input stack.  */
842
843   buf1 = (U_CHAR *) alloca (length + 1);
844   memcpy (buf1, buf, length);
845   buf1[length] = 0;
846
847   ip = cpp_push_buffer (pfile, buf1, length);
848   if (ip == NULL)
849     return;
850   ip->has_escapes = 1;
851
852   /* Scan the input, create the output.  */
853   save_no_output = CPP_OPTIONS (pfile)->no_output;
854   CPP_OPTIONS (pfile)->no_output = 0;
855   cpp_scan_buffer (pfile);
856   CPP_OPTIONS (pfile)->no_output = save_no_output;
857
858   CPP_NUL_TERMINATE (pfile);
859 }
860
861 void
862 cpp_buf_line_and_col (pbuf, linep, colp)
863      register cpp_buffer *pbuf;
864      long *linep, *colp;
865 {
866   if (pbuf)
867     {
868       *linep = pbuf->lineno;
869       if (colp)
870         *colp = pbuf->cur - pbuf->line_base;
871     }
872   else
873     {
874       *linep = 0;
875       if (colp)
876         *colp = 0;
877     }
878 }
879
880 /* Return the cpp_buffer that corresponds to a file (not a macro).  */
881
882 cpp_buffer *
883 cpp_file_buffer (pfile)
884      cpp_reader *pfile;
885 {
886   cpp_buffer *ip = CPP_BUFFER (pfile);
887
888   for ( ; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
889     if (ip->fname != NULL)
890       return ip;
891   return NULL;
892 }
893
894 /*
895  * write out a #line command, for instance, after an #include file.
896  * FILE_CHANGE says whether we are entering a file, leaving, or neither.
897  */
898
899 void
900 output_line_command (pfile, file_change)
901      cpp_reader *pfile;
902      enum file_change_code file_change;
903 {
904   long line;
905   cpp_buffer *ip = CPP_BUFFER (pfile);
906
907   if (ip->fname == NULL)
908     return;
909
910   if (CPP_OPTIONS (pfile)->no_line_commands
911       || CPP_OPTIONS (pfile)->no_output)
912     return;
913
914   cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, NULL);
915
916   /* If the current file has not changed, we omit the #line if it would
917      appear to be a no-op, and we output a few newlines instead
918      if we want to increase the line number by a small amount.
919      We cannot do this if pfile->lineno is zero, because that means we
920      haven't output any line commands yet.  (The very first line command
921      output is a `same_file' command.)  */
922   if (file_change == same_file && pfile->lineno != 0)
923     {
924       if (line == pfile->lineno)
925         return;
926
927       /* If the inherited line number is a little too small,
928          output some newlines instead of a #line command.  */
929       if (line > pfile->lineno && line < pfile->lineno + 8)
930         {
931           CPP_RESERVE (pfile, 20);
932           while (line > pfile->lineno)
933             {
934               CPP_PUTC_Q (pfile, '\n');
935               pfile->lineno++;
936             }
937           return;
938         }
939     }
940
941   CPP_RESERVE (pfile, 4 * strlen (ip->nominal_fname) + 50);
942   CPP_PUTS_Q (pfile, "# ", 2);
943
944   sprintf ((char *) CPP_PWRITTEN (pfile), "%ld ", line);
945   CPP_ADJUST_WRITTEN (pfile, strlen (CPP_PWRITTEN (pfile)));
946
947   quote_string (pfile, ip->nominal_fname); 
948   if (file_change != same_file)
949     {
950       CPP_PUTC_Q (pfile, ' ');
951       CPP_PUTC_Q (pfile, file_change == enter_file ? '1' : '2');
952     }
953   /* Tell cc1 if following text comes from a system header file.  */
954   if (ip->system_header_p)
955     {
956       CPP_PUTC_Q (pfile, ' ');
957       CPP_PUTC_Q (pfile, '3');
958     }
959 #ifndef NO_IMPLICIT_EXTERN_C
960   /* Tell cc1plus if following text should be treated as C.  */
961   if (ip->system_header_p == 2 && CPP_OPTIONS (pfile)->cplusplus)
962     {
963       CPP_PUTC_Q (pfile, ' ');
964       CPP_PUTC_Q (pfile, '4');
965     }
966 #endif
967   CPP_PUTC_Q (pfile, '\n');
968   pfile->lineno = line;
969 }
970
971
972 /* Like cpp_get_token, except that it does not read past end-of-line.
973    Also, horizontal space is skipped, and macros are popped.  */
974
975 static enum cpp_token
976 get_directive_token (pfile)
977      cpp_reader *pfile;
978 {
979   for (;;)
980     {
981       long old_written = CPP_WRITTEN (pfile);
982       enum cpp_token token;
983       cpp_skip_hspace (pfile);
984       if (PEEKC () == '\n')
985           return CPP_VSPACE;
986       token = cpp_get_token (pfile);
987       switch (token)
988       {
989       case CPP_POP:
990           if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
991               return token;
992           /* ... else fall though ...  */
993       case CPP_HSPACE:  case CPP_COMMENT:
994           CPP_SET_WRITTEN (pfile, old_written);
995           break;
996       default:
997           return token;
998       }
999     }
1000 }
1001 \f
1002 /* Handle #include and #import.
1003    This function expects to see "fname" or <fname> on the input.
1004
1005    The input is normally in part of the output_buffer following
1006    CPP_WRITTEN, and will get overwritten by output_line_command.
1007    I.e. in input file specification has been popped by handle_directive.
1008    This is safe.  */
1009
1010 static int
1011 do_include (pfile, keyword)
1012      cpp_reader *pfile;
1013      const struct directive *keyword;
1014 {
1015   int importing = (keyword->type == T_IMPORT);
1016   int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
1017   int angle_brackets = 0;       /* 0 for "...", 1 for <...> */
1018   int before;  /* included before? */
1019   long flen;
1020   unsigned char *ftok;
1021   cpp_buffer *fp;
1022
1023   enum cpp_token token;
1024
1025   /* Chain of dirs to search */
1026   struct include_hash *ihash;
1027   struct file_name_list *search_start;
1028   
1029   long old_written = CPP_WRITTEN (pfile);
1030
1031   int fd;
1032
1033   if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
1034     {
1035       if (importing)
1036         cpp_pedwarn (pfile, "ANSI C does not allow `#import'");
1037       if (skip_dirs)
1038         cpp_pedwarn (pfile, "ANSI C does not allow `#include_next'");
1039     }
1040
1041   if (importing && CPP_OPTIONS (pfile)->warn_import
1042       && !CPP_OPTIONS (pfile)->inhibit_warnings
1043       && !CPP_BUFFER (pfile)->system_header_p && !pfile->import_warning)
1044     {
1045       pfile->import_warning = 1;
1046       cpp_warning (pfile,
1047            "#import is obsolete, use an #ifndef wrapper in the header file");
1048     }
1049
1050   pfile->parsing_include_directive++;
1051   token = get_directive_token (pfile);
1052   pfile->parsing_include_directive--;
1053
1054   if (token == CPP_STRING)
1055     {
1056       if (pfile->token_buffer[old_written] == '<')
1057         angle_brackets = 1;
1058     }
1059 #ifdef VMS
1060   else if (token == CPP_NAME)
1061     {
1062       /* Support '#include xyz' like VAX-C.  It is taken as
1063          '#include <xyz.h>' and generates a warning.  */
1064       cpp_warning (pfile,
1065                "`#include filename' is obsolete, use `#include <filename.h>'");
1066       angle_brackets = 1;
1067
1068       /* Append the missing `.h' to the name. */
1069       CPP_PUTS (pfile, ".h", 2);
1070     }
1071 #endif
1072   else
1073     {
1074       cpp_error (pfile,
1075                  "`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
1076       CPP_SET_WRITTEN (pfile, old_written);
1077       skip_rest_of_line (pfile);
1078       return 0;
1079     }
1080
1081   flen = CPP_WRITTEN (pfile) - old_written;
1082   ftok = (unsigned char *) alloca (flen + 1);
1083   memcpy (ftok, pfile->token_buffer + old_written, flen);
1084   ftok[flen] = '\0';
1085
1086   if (get_directive_token (pfile) != CPP_VSPACE)
1087     {
1088       cpp_error (pfile, "junk at end of `#include'");
1089       skip_rest_of_line (pfile);
1090     }
1091
1092   CPP_SET_WRITTEN (pfile, old_written);
1093
1094   if (flen == 0)
1095     {
1096       cpp_error (pfile, "empty file name in `#%s'", keyword->name);
1097       return 0;
1098     }
1099
1100   if (CPP_OPTIONS (pfile)->dump_includes)
1101     pass_thru_directive (ftok,
1102                          flen
1103 #ifdef VMS
1104           - ((token == CPP_NAME) ? 2 : 0)
1105 #endif
1106                          , pfile, keyword);
1107
1108 #ifdef VMS
1109   if (token == CPP_STRING)
1110 #endif
1111     {
1112       ftok++;
1113       flen -= 2;
1114       ftok[flen] = '\0';
1115     }
1116
1117   search_start = 0;
1118
1119   for (fp = CPP_BUFFER (pfile);
1120        fp != CPP_NULL_BUFFER (pfile);
1121        fp = CPP_PREV_BUFFER (fp))
1122     if (fp->fname != NULL)
1123       break;
1124
1125   if (fp == CPP_NULL_BUFFER (pfile))
1126     {
1127       cpp_fatal (pfile, "cpp internal error: fp == NULL_BUFFER in do_include");
1128       return 0;
1129     }
1130   
1131   /* For #include_next, skip in the search path past the dir in which the
1132      containing file was found.  Treat files specified using an absolute path
1133      as if there are no more directories to search.  Treat the primary source
1134      file like any other included source, but generate a warning.  */
1135   if (skip_dirs && CPP_PREV_BUFFER(fp) != CPP_NULL_BUFFER (pfile))
1136     {
1137       if (fp->ihash->foundhere != ABSOLUTE_PATH)
1138         search_start = fp->ihash->foundhere->next;
1139     }
1140   else
1141     {
1142       if (skip_dirs)
1143         cpp_warning (pfile, "#include_next in primary source file");
1144       
1145       if (angle_brackets)
1146         search_start = CPP_OPTIONS (pfile)->bracket_include;
1147       else
1148         {
1149           if (!CPP_OPTIONS (pfile)->ignore_srcdir)
1150             {
1151               if (fp)
1152                 search_start = fp->actual_dir;
1153             }
1154           else
1155             search_start = CPP_OPTIONS (pfile)->quote_include;
1156         }
1157     }
1158
1159   if (!search_start)
1160     {
1161       cpp_error (pfile, "No include path in which to find %s", ftok);
1162       return 0;
1163     }
1164
1165   fd = find_include_file (pfile, ftok, search_start, &ihash, &before);
1166
1167   if (fd == -2)
1168     return 0;
1169   
1170   if (fd == -1)
1171     {
1172       if (CPP_OPTIONS (pfile)->print_deps_missing_files
1173           && CPP_PRINT_DEPS (pfile) > (angle_brackets ||
1174                                        (pfile->system_include_depth > 0)))
1175         {
1176           if (!angle_brackets)
1177             deps_output (pfile, ftok, ' ');
1178           else
1179             {
1180               char *p;
1181               struct file_name_list *ptr;
1182               /* If requested as a system header, assume it belongs in
1183                  the first system header directory. */
1184               if (CPP_OPTIONS (pfile)->bracket_include)
1185                 ptr = CPP_OPTIONS (pfile)->bracket_include;
1186               else
1187                 ptr = CPP_OPTIONS (pfile)->quote_include;
1188
1189               p = (char *) alloca (strlen (ptr->name)
1190                                    + strlen (ftok) + 2);
1191               if (*ptr->name != '\0')
1192                 {
1193                   strcpy (p, ptr->name);
1194                   strcat (p, "/");
1195                 }
1196               strcat (p, ftok);
1197               deps_output (pfile, p, ' ');
1198             }
1199         }
1200       /* If -M was specified, and this header file won't be added to
1201          the dependency list, then don't count this as an error,
1202          because we can still produce correct output.  Otherwise, we
1203          can't produce correct output, because there may be
1204          dependencies we need inside the missing file, and we don't
1205          know what directory this missing file exists in. */
1206       else if (CPP_PRINT_DEPS (pfile)
1207                && (CPP_PRINT_DEPS (pfile)
1208                    <= (angle_brackets || (pfile->system_include_depth > 0))))
1209         cpp_warning (pfile, "No include path in which to find %s", ftok);
1210       else
1211         cpp_error_from_errno (pfile, ftok);
1212
1213       return 0;
1214     }
1215
1216   /* For -M, add the file to the dependencies on its first inclusion. */
1217   if (!before && (CPP_PRINT_DEPS (pfile)
1218                   > (angle_brackets || (pfile->system_include_depth > 0))))
1219     deps_output (pfile, ihash->name, ' ');
1220
1221   /* Handle -H option.  */
1222   if (CPP_OPTIONS(pfile)->print_include_names)
1223     {
1224       fp = CPP_BUFFER (pfile);
1225       while ((fp = CPP_PREV_BUFFER (fp)) != CPP_NULL_BUFFER (pfile))
1226         putc ('.', stderr);
1227       fprintf (stderr, " %s\n", ihash->name);
1228     }
1229
1230   /* Actually process the file */
1231
1232   if (importing)
1233     ihash->control_macro = "";
1234   
1235   if (cpp_push_buffer (pfile, NULL, 0) == NULL)
1236     {
1237       close (fd);
1238       return 0;
1239     }
1240   
1241   if (angle_brackets)
1242     pfile->system_include_depth++;   /* Decremented in file_cleanup. */
1243
1244   if (finclude (pfile, fd, ihash))
1245     {
1246       output_line_command (pfile, enter_file);
1247       pfile->only_seen_white = 2;
1248     }
1249
1250   return 0;
1251 }
1252
1253 /* Subroutine of do_line.  Read next token from PFILE without adding it to
1254    the output buffer.  If it is a number between 1 and 4, store it in *NUM
1255    and return 1; otherwise, return 0 and complain if we aren't at the end
1256    of the directive.  */
1257
1258 static int
1259 read_line_number (pfile, num)
1260      cpp_reader *pfile;
1261      int *num;
1262 {
1263   long save_written = CPP_WRITTEN (pfile);
1264   U_CHAR *p = pfile->token_buffer + save_written;
1265   enum cpp_token token = get_directive_token (pfile);
1266   CPP_SET_WRITTEN (pfile, save_written);
1267
1268   if (token == CPP_NUMBER && *p >= '1' && *p <= '4' && p[1] == '\0')
1269     {
1270       *num = p[0] - '0';
1271       return 1;
1272     }
1273   else
1274     {
1275       if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP)
1276         cpp_error (pfile, "invalid format `#line' command");
1277       return 0;
1278     }
1279 }
1280
1281 /* Interpret #line command.
1282    Note that the filename string (if any) is treated as if it were an
1283    include filename.  That means no escape handling.  */
1284
1285 static int
1286 do_line (pfile, keyword)
1287      cpp_reader *pfile;
1288      const struct directive *keyword ATTRIBUTE_UNUSED;
1289 {
1290   cpp_buffer *ip = CPP_BUFFER (pfile);
1291   int new_lineno;
1292   long old_written = CPP_WRITTEN (pfile);
1293   enum file_change_code file_change = same_file;
1294   enum cpp_token token;
1295   char *x;
1296
1297   token = get_directive_token (pfile);
1298
1299   if (token != CPP_NUMBER)
1300     {
1301       cpp_error (pfile, "token after `#line' is not an integer");
1302       goto bad_line_directive;
1303     }
1304
1305   new_lineno = strtol (pfile->token_buffer + old_written, &x, 10);
1306   if (x[0] != '\0')
1307     {
1308       cpp_error (pfile, "token after `#line' is not an integer");
1309       goto bad_line_directive;
1310     }      
1311   CPP_SET_WRITTEN (pfile, old_written);
1312
1313   if (CPP_PEDANTIC (pfile) && new_lineno <= 0)
1314     cpp_pedwarn (pfile, "line number out of range in `#line' command");
1315
1316   token = get_directive_token (pfile);
1317
1318   if (token == CPP_STRING)
1319     {
1320       U_CHAR *fname = pfile->token_buffer + old_written + 1;
1321       U_CHAR *end_name = CPP_PWRITTEN (pfile) - 1;
1322       int action_number = 0;
1323
1324       if (read_line_number (pfile, &action_number))
1325         {
1326           if (CPP_PEDANTIC (pfile))
1327             cpp_pedwarn (pfile, "garbage at end of `#line' command");
1328
1329           if (action_number == 1)
1330             {
1331               file_change = enter_file;
1332               read_line_number (pfile, &action_number);
1333             }
1334           else if (action_number == 2)
1335             {
1336               file_change = leave_file;
1337               read_line_number (pfile, &action_number);
1338             }
1339           if (action_number == 3)
1340             {
1341               ip->system_header_p = 1;
1342               read_line_number (pfile, &action_number);
1343             }
1344           if (action_number == 4)
1345             {
1346               ip->system_header_p = 2;
1347               read_line_number (pfile, &action_number);
1348             }
1349         }
1350       
1351       *end_name = '\0';
1352       
1353       if (strcmp (fname, ip->nominal_fname))
1354         {
1355           char *newname, *oldname;
1356           if (!strcmp (fname, ip->fname))
1357             newname = ip->fname;
1358           else if (ip->last_nominal_fname
1359                    && !strcmp (fname, ip->last_nominal_fname))
1360             newname = ip->last_nominal_fname;
1361           else
1362             newname = xstrdup (fname);
1363
1364           oldname = ip->nominal_fname;
1365           ip->nominal_fname = newname;
1366
1367           if (ip->last_nominal_fname
1368               && ip->last_nominal_fname != oldname
1369               && ip->last_nominal_fname != newname
1370               && ip->last_nominal_fname != ip->fname)
1371             free (ip->last_nominal_fname);
1372
1373           if (newname == ip->fname)
1374             ip->last_nominal_fname = NULL;
1375           else
1376             ip->last_nominal_fname = oldname;
1377         } 
1378     }
1379   else if (token != CPP_VSPACE && token != CPP_EOF)
1380     {
1381       cpp_error (pfile, "token after `#line %d' is not a string", new_lineno);
1382       goto bad_line_directive;
1383     }
1384
1385   /* The Newline at the end of this line remains to be processed.
1386      To put the next line at the specified line number,
1387      we must store a line number now that is one less.  */
1388   ip->lineno = new_lineno - 1;
1389   CPP_SET_WRITTEN (pfile, old_written);
1390   output_line_command (pfile, file_change);
1391   return 0;
1392
1393  bad_line_directive:
1394   skip_rest_of_line (pfile);
1395   CPP_SET_WRITTEN (pfile, old_written);
1396   return 0;
1397 }
1398
1399 /* Remove the definition of a symbol from the symbol table.
1400    According to the C standard, it is not an error to undef
1401    something that has no definitions. */
1402 static int
1403 do_undef (pfile, keyword)
1404      cpp_reader *pfile;
1405      const struct directive *keyword;
1406 {
1407   int sym_length;
1408   HASHNODE *hp;
1409   U_CHAR *buf, *name, *limit;
1410   int c;
1411   long here = CPP_WRITTEN (pfile);
1412   enum cpp_token token;
1413
1414   cpp_skip_hspace (pfile);
1415   c = GETC();
1416   if (! is_idstart[c])
1417   {
1418       cpp_error (pfile, "token after #undef is not an identifier");
1419       skip_rest_of_line (pfile);
1420       return 1;
1421   }
1422
1423   parse_name (pfile, c);
1424   buf = pfile->token_buffer + here;
1425   limit = CPP_PWRITTEN(pfile);
1426
1427   /* Copy out the token so we can pop the token buffer. */
1428   name = (U_CHAR *) alloca (limit - buf + 1);
1429   bcopy(buf, name, limit - buf);
1430   name[limit - buf] = '\0';
1431
1432   token = get_directive_token (pfile);
1433   if (token != CPP_VSPACE && token != CPP_POP)
1434   {
1435       cpp_pedwarn (pfile, "junk on line after #undef");
1436       skip_rest_of_line (pfile);
1437   }
1438
1439   CPP_SET_WRITTEN (pfile, here);
1440
1441   sym_length = check_macro_name (pfile, buf, 0);
1442
1443   while ((hp = cpp_lookup (pfile, name, sym_length, -1)) != NULL)
1444     {
1445       /* If we are generating additional info for debugging (with -g) we
1446          need to pass through all effective #undef commands.  */
1447       if (CPP_OPTIONS (pfile)->debug_output && keyword)
1448         pass_thru_directive (name, sym_length, pfile, keyword);
1449       if (hp->type == T_POISON)
1450         cpp_error (pfile, "cannot undefine poisoned `%s'", hp->name);
1451       else 
1452         {
1453           if (hp->type != T_MACRO)
1454             cpp_warning (pfile, "undefining `%s'", hp->name);
1455           delete_macro (hp);
1456         }
1457     }
1458
1459   return 0;
1460 }
1461
1462 /* Wrap do_undef for -U processing. */
1463 void
1464 cpp_undef (pfile, macro)
1465      cpp_reader *pfile;
1466      U_CHAR *macro;
1467 {
1468   if (cpp_push_buffer (pfile, macro, strlen (macro)))
1469     {
1470       do_undef (pfile, NULL);
1471       cpp_pop_buffer (pfile);
1472     }
1473 }
1474
1475 \f
1476 /*
1477  * Report an error detected by the program we are processing.
1478  * Use the text of the line in the error message.
1479  * (We use error because it prints the filename & line#.)
1480  */
1481
1482 static int
1483 do_error (pfile, keyword)
1484      cpp_reader *pfile;
1485      const struct directive *keyword ATTRIBUTE_UNUSED;
1486 {
1487   long here = CPP_WRITTEN (pfile);
1488   U_CHAR *text;
1489   copy_rest_of_line (pfile);
1490   text = pfile->token_buffer + here;
1491   SKIP_WHITE_SPACE(text);
1492
1493   cpp_error (pfile, "#error %s", text);
1494   CPP_SET_WRITTEN (pfile, here);
1495   return 0;
1496 }
1497
1498 /*
1499  * Report a warning detected by the program we are processing.
1500  * Use the text of the line in the warning message, then continue.
1501  */
1502
1503 static int
1504 do_warning (pfile, keyword)
1505      cpp_reader *pfile;
1506      const struct directive *keyword ATTRIBUTE_UNUSED;
1507 {
1508   U_CHAR *text;
1509   long here = CPP_WRITTEN(pfile);
1510   copy_rest_of_line (pfile);
1511   text = pfile->token_buffer + here;
1512   SKIP_WHITE_SPACE(text);
1513
1514   if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
1515     cpp_pedwarn (pfile, "ANSI C does not allow `#warning'");
1516
1517   /* Use `pedwarn' not `warning', because #warning isn't in the C Standard;
1518      if -pedantic-errors is given, #warning should cause an error.  */
1519   cpp_pedwarn (pfile, "#warning %s", text);
1520   CPP_SET_WRITTEN (pfile, here);
1521   return 0;
1522 }
1523
1524 /* Report program identification.
1525    This is not precisely what cccp does with #ident, however I believe
1526    it matches `closely enough' (behavior is identical as long as there
1527    are no macros on the #ident line, which is pathological in my opinion).  */
1528
1529 static int
1530 do_ident (pfile, keyword)
1531      cpp_reader *pfile;
1532      const struct directive *keyword ATTRIBUTE_UNUSED;
1533 {
1534   /* Allow #ident in system headers, since that's not user's fault.  */
1535   if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
1536     cpp_pedwarn (pfile, "ANSI C does not allow `#ident'");
1537
1538   CPP_PUTS (pfile, "#ident ", 7);
1539   cpp_skip_hspace (pfile);
1540   copy_rest_of_line (pfile);
1541
1542   return 0;
1543 }
1544
1545 /* Just check for some recognized pragmas that need validation here,
1546    and leave the text in the token buffer to be output. */
1547
1548 static int
1549 do_pragma (pfile, keyword)
1550      cpp_reader *pfile;
1551      const struct directive *keyword ATTRIBUTE_UNUSED;
1552 {
1553   long here;
1554   U_CHAR *buf;
1555
1556   CPP_PUTS (pfile, "#pragma ", 8);
1557   cpp_skip_hspace (pfile);
1558   
1559   here = CPP_WRITTEN (pfile);
1560   copy_rest_of_line (pfile);
1561   buf = pfile->token_buffer + here;
1562   
1563   if (!strncmp (buf, "once", 4))
1564     {
1565       cpp_buffer *ip = NULL;
1566
1567       /* Allow #pragma once in system headers, since that's not the user's
1568          fault.  */
1569       if (!CPP_BUFFER (pfile)->system_header_p)
1570         cpp_warning (pfile, "`#pragma once' is obsolete");
1571       
1572       for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
1573         {
1574           if (ip == CPP_NULL_BUFFER (pfile))
1575             return 0;
1576           if (ip->fname != NULL)
1577             break;
1578         }
1579
1580       if (CPP_PREV_BUFFER (ip) == CPP_NULL_BUFFER (pfile))
1581         cpp_warning (pfile, "`#pragma once' outside include file");
1582       else
1583         ip->ihash->control_macro = "";  /* never repeat */
1584     }
1585   else if (!strncmp (buf, "implementation", 14))
1586     {
1587       /* Be quiet about `#pragma implementation' for a file only if it hasn't
1588          been included yet.  */
1589       struct include_hash *ptr;
1590       U_CHAR *p = buf + 14, *fname, *fcopy;
1591       SKIP_WHITE_SPACE (p);
1592       if (*p == '\n' || *p != '\"')
1593         return 0;
1594
1595       fname = p + 1;
1596       p = (U_CHAR *) index (fname, '\"');
1597
1598       fcopy = (U_CHAR *) alloca (p - fname + 1);
1599       bcopy (fname, fcopy, p - fname);
1600       fcopy[p-fname] = '\0';
1601
1602       ptr = include_hash (pfile, fcopy, 0);
1603       if (ptr)
1604         cpp_warning (pfile,
1605           "`#pragma implementation' for `%s' appears after file is included",
1606                      fcopy);
1607     }
1608   else if (!strncmp (buf, "poison", 6))
1609     {
1610       /* Poison these symbols so that all subsequent usage produces an
1611          error message.  */
1612       U_CHAR *p = buf + 6;
1613       size_t plen;
1614       U_CHAR *syms;
1615       int writeit;
1616
1617       SKIP_WHITE_SPACE (p);
1618       plen = strlen(p) + 1;
1619
1620       syms = (U_CHAR *) alloca (plen);
1621       memcpy (syms, p, plen);
1622
1623       /* As a rule, don't include #pragma poison commands in output,  
1624          unless the user asks for them.  */
1625       writeit = (CPP_OPTIONS (pfile)->debug_output
1626                  || CPP_OPTIONS (pfile)->dump_macros == dump_definitions
1627                  || CPP_OPTIONS (pfile)->dump_macros == dump_names);
1628
1629       if (writeit)
1630         CPP_SET_WRITTEN (pfile, here);
1631       else
1632         CPP_SET_WRITTEN (pfile, here-8);
1633
1634       if (writeit)
1635         {
1636           CPP_RESERVE (pfile, plen + 7);
1637           CPP_PUTS_Q (pfile, "poison", 7);
1638         }
1639
1640       while (*syms != '\0')
1641         {
1642           U_CHAR *end = syms;
1643           
1644           while (is_idchar[*end])
1645             end++;
1646
1647           if (!is_hor_space[*end] && *end != '\0')
1648             {
1649               cpp_error (pfile, "invalid #pragma poison directive");
1650               return 1;
1651             }
1652
1653           if (cpp_push_buffer (pfile, syms, end - syms) != NULL)
1654             {
1655               do_define (pfile, keyword);
1656               cpp_pop_buffer (pfile);
1657             }
1658           if (writeit)
1659             {
1660               CPP_PUTC_Q (pfile, ' ');
1661               CPP_PUTS_Q (pfile, syms, end - syms);
1662             }
1663           syms = end;
1664           SKIP_WHITE_SPACE (syms);
1665         }
1666     }
1667
1668   return 0;
1669 }
1670
1671 #ifdef SCCS_DIRECTIVE
1672 /* Just ignore #sccs, on systems where we define it at all.  */
1673
1674 static int
1675 do_sccs (pfile, keyword)
1676      cpp_reader *pfile;
1677      const struct directive *keyword ATTRIBUTE_UNUSED;
1678 {
1679   if (CPP_PEDANTIC (pfile))
1680     cpp_pedwarn (pfile, "ANSI C does not allow `#sccs'");
1681   skip_rest_of_line (pfile);
1682   return 0;
1683 }
1684 #endif
1685 \f
1686
1687 /* We've found an `#if' directive.  If the only thing before it in
1688    this file is white space, and if it is of the form
1689    `#if ! defined SYMBOL', then SYMBOL is a possible controlling macro
1690    for inclusion of this file.  (See redundant_include_p in cppfiles.c
1691    for an explanation of controlling macros.)  If so, return a
1692    malloc'd copy of SYMBOL.  Otherwise, return NULL.  */
1693
1694 static U_CHAR *
1695 detect_if_not_defined (pfile)
1696      cpp_reader *pfile;
1697 {
1698   U_CHAR *control_macro = 0;
1699
1700   if (pfile->only_seen_white == 2)
1701     {
1702       char *ident;
1703       enum cpp_token token;
1704       int base_offset;
1705       int token_offset;
1706       int need_rparen = 0;
1707
1708       /* Save state required for restore.  */
1709       pfile->no_macro_expand++;
1710       parse_set_mark (pfile);
1711       base_offset = CPP_WRITTEN (pfile);
1712
1713       /* Look for `!', */
1714       if (get_directive_token (pfile) != CPP_OTHER
1715           || CPP_WRITTEN (pfile) != (size_t) base_offset + 1
1716           || CPP_PWRITTEN (pfile)[-1] != '!')
1717         goto restore;
1718
1719       /* ...then `defined', */
1720       token_offset = CPP_WRITTEN (pfile);
1721       token = get_directive_token (pfile);
1722       if (token != CPP_NAME)
1723         goto restore;
1724       ident = pfile->token_buffer + token_offset;
1725       CPP_NUL_TERMINATE (pfile);
1726       if (strcmp (ident, "defined"))
1727         goto restore;
1728
1729       /* ...then an optional '(' and the name, */
1730       token_offset = CPP_WRITTEN (pfile);
1731       token = get_directive_token (pfile);
1732       if (token == CPP_LPAREN)
1733         {
1734           token_offset = CPP_WRITTEN (pfile);
1735           token = get_directive_token (pfile);
1736           if (token != CPP_NAME)
1737             goto restore;
1738           need_rparen = 1;
1739         }
1740       else if (token != CPP_NAME)
1741         goto restore;
1742
1743       ident = pfile->token_buffer + token_offset;
1744       CPP_NUL_TERMINATE (pfile);
1745
1746       /* ...then the ')', if necessary, */
1747       if ((!need_rparen || get_directive_token (pfile) == CPP_RPAREN)
1748           /* ...and make sure there's nothing else on the line.  */
1749           && get_directive_token (pfile) == CPP_VSPACE)
1750         control_macro = xstrdup (ident);
1751
1752     restore:
1753       CPP_SET_WRITTEN (pfile, base_offset);
1754       pfile->no_macro_expand--;
1755       parse_goto_mark (pfile);
1756     }
1757
1758   return control_macro;
1759 }
1760
1761 /*
1762  * handle #if command by
1763  *   1) inserting special `defined' keyword into the hash table
1764  *      that gets turned into 0 or 1 by special_symbol (thus,
1765  *      if the luser has a symbol called `defined' already, it won't
1766  *      work inside the #if command)
1767  *   2) rescan the input into a temporary output buffer
1768  *   3) pass the output buffer to the yacc parser and collect a value
1769  *   4) clean up the mess left from steps 1 and 2.
1770  *   5) call conditional_skip to skip til the next #endif (etc.),
1771  *      or not, depending on the value from step 3.
1772  */
1773
1774 static int
1775 do_if (pfile, keyword)
1776      cpp_reader *pfile;
1777      const struct directive *keyword ATTRIBUTE_UNUSED;
1778 {
1779   U_CHAR *control_macro = detect_if_not_defined (pfile);
1780   HOST_WIDEST_INT value = eval_if_expression (pfile);
1781   conditional_skip (pfile, value == 0, T_IF, control_macro);
1782   return 0;
1783 }
1784
1785 /*
1786  * handle a #elif directive by not changing  if_stack  either.
1787  * see the comment above do_else.
1788  */
1789
1790 static int
1791 do_elif (pfile, keyword)
1792      cpp_reader *pfile;
1793      const struct directive *keyword ATTRIBUTE_UNUSED;
1794 {
1795   if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
1796     cpp_error (pfile, "`#elif' not within a conditional");
1797     return 0;
1798   } else {
1799     if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
1800       cpp_error (pfile, "`#elif' after `#else'");
1801 #if 0
1802       fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
1803 #endif
1804       if (pfile->if_stack->fname != NULL && CPP_BUFFER (pfile)->fname != NULL
1805           && strcmp (pfile->if_stack->fname,
1806                      CPP_BUFFER (pfile)->nominal_fname) != 0)
1807         fprintf (stderr, ", file %s", pfile->if_stack->fname);
1808       fprintf (stderr, ")\n");
1809     }
1810     pfile->if_stack->type = T_ELIF;
1811   }
1812
1813   if (pfile->if_stack->if_succeeded)
1814     skip_if_group (pfile);
1815   else {
1816     HOST_WIDEST_INT value = eval_if_expression (pfile);
1817     if (value == 0)
1818       skip_if_group (pfile);
1819     else {
1820       ++pfile->if_stack->if_succeeded;  /* continue processing input */
1821       output_line_command (pfile, same_file);
1822     }
1823   }
1824   return 0;
1825 }
1826
1827 /*
1828  * evaluate a #if expression in BUF, of length LENGTH,
1829  * then parse the result as a C expression and return the value as an int.
1830  */
1831
1832 static HOST_WIDEST_INT
1833 eval_if_expression (pfile)
1834      cpp_reader *pfile;
1835 {
1836   HOST_WIDEST_INT value;
1837   long old_written = CPP_WRITTEN (pfile);
1838
1839   pfile->pcp_inside_if = 1;
1840   value = cpp_parse_expr (pfile);
1841   pfile->pcp_inside_if = 0;
1842
1843   CPP_SET_WRITTEN (pfile, old_written); /* Pop */
1844
1845   return value;
1846 }
1847
1848 /*
1849  * routine to handle ifdef/ifndef.  Try to look up the symbol,
1850  * then do or don't skip to the #endif/#else/#elif depending
1851  * on what directive is actually being processed.
1852  */
1853
1854 static int
1855 do_xifdef (pfile, keyword)
1856      cpp_reader *pfile;
1857      const struct directive *keyword;
1858 {
1859   int skip;
1860   cpp_buffer *ip = CPP_BUFFER (pfile);
1861   U_CHAR *ident;
1862   int ident_length;
1863   enum cpp_token token;
1864   int start_of_file = 0;
1865   U_CHAR *control_macro = 0;
1866   int old_written = CPP_WRITTEN (pfile);
1867
1868   /* Detect a #ifndef at start of file (not counting comments).  */
1869   if (ip->fname != 0 && keyword->type == T_IFNDEF)
1870     start_of_file = pfile->only_seen_white == 2;
1871
1872   pfile->no_macro_expand++;
1873   token = get_directive_token (pfile);
1874   pfile->no_macro_expand--;
1875
1876   ident = pfile->token_buffer + old_written;
1877   ident_length = CPP_WRITTEN (pfile) - old_written;
1878   CPP_SET_WRITTEN (pfile, old_written); /* Pop */
1879
1880   if (token == CPP_VSPACE || token == CPP_POP || token == CPP_EOF)
1881     {
1882       skip = (keyword->type == T_IFDEF);
1883       if (! CPP_TRADITIONAL (pfile))
1884         cpp_pedwarn (pfile, "`#%s' with no argument", keyword->name);
1885     }
1886   else if (token == CPP_NAME)
1887     {
1888       HASHNODE *hp = cpp_lookup (pfile, ident, ident_length, -1);
1889       skip = (hp == NULL) ^ (keyword->type == T_IFNDEF);
1890       if (start_of_file && !skip)
1891         {
1892           control_macro = (U_CHAR *) xmalloc (ident_length + 1);
1893           bcopy (ident, control_macro, ident_length + 1);
1894         }
1895       if (hp != NULL && hp->type == T_POISON)
1896         {
1897           cpp_error (pfile, "attempt to use poisoned `%s'", hp->name);
1898           skip = !skip;
1899         }
1900     }
1901   else
1902     {
1903       skip = (keyword->type == T_IFDEF);
1904       if (! CPP_TRADITIONAL (pfile))
1905         cpp_error (pfile, "`#%s' with invalid argument", keyword->name);
1906     }
1907
1908   if (!CPP_TRADITIONAL (pfile))
1909     { int c;
1910       cpp_skip_hspace (pfile);
1911       c = PEEKC ();
1912       if (c != EOF && c != '\n')
1913         cpp_pedwarn (pfile, "garbage at end of `#%s' argument", keyword->name);
1914     }
1915   skip_rest_of_line (pfile);
1916
1917 #if 0
1918     if (pcp_outfile) {
1919       /* Output a precondition for this macro.  */
1920       if (hp && hp->value.defn->predefined)
1921         fprintf (pcp_outfile, "#define %s\n", hp->name);
1922       else {
1923         U_CHAR *cp = buf;
1924         fprintf (pcp_outfile, "#undef ");
1925         while (is_idchar[*cp]) /* Ick! */
1926           fputc (*cp++, pcp_outfile);
1927         putc ('\n', pcp_outfile);
1928       }
1929 #endif
1930
1931   conditional_skip (pfile, skip, T_IF, control_macro);
1932   return 0;
1933 }
1934
1935 /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
1936    If this is a #ifndef starting at the beginning of a file,
1937    CONTROL_MACRO is the macro name tested by the #ifndef.
1938    Otherwise, CONTROL_MACRO is 0.  */
1939
1940 static void
1941 conditional_skip (pfile, skip, type, control_macro)
1942      cpp_reader *pfile;
1943      int skip;
1944      enum node_type type;
1945      U_CHAR *control_macro;
1946 {
1947   IF_STACK_FRAME *temp;
1948
1949   temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
1950   temp->fname = CPP_BUFFER (pfile)->nominal_fname;
1951   temp->lineno = CPP_BUFFER (pfile)->lineno;
1952   temp->next = pfile->if_stack;
1953   temp->control_macro = control_macro;
1954   pfile->if_stack = temp;
1955
1956   pfile->if_stack->type = type;
1957
1958   if (skip != 0) {
1959     skip_if_group (pfile);
1960     return;
1961   } else {
1962     ++pfile->if_stack->if_succeeded;
1963     output_line_command (pfile, same_file);
1964   }
1965 }
1966
1967 /* Subroutine of skip_if_group.  Examine one preprocessing directive and
1968    return 0 if skipping should continue, 1 if it should halt.  Also
1969    adjusts the if_stack as appropriate.
1970    The `#' has been read, but not the identifier. */
1971
1972 static int
1973 consider_directive_while_skipping (pfile, stack)
1974     cpp_reader *pfile;
1975     IF_STACK_FRAME *stack; 
1976 {
1977   long ident_len, ident;
1978   const struct directive *kt;
1979   IF_STACK_FRAME *temp;
1980     
1981   cpp_skip_hspace (pfile);
1982
1983   ident = CPP_WRITTEN (pfile);
1984   parse_name (pfile, GETC());
1985   ident_len = CPP_WRITTEN (pfile) - ident;
1986
1987   CPP_SET_WRITTEN (pfile, ident);
1988
1989   for (kt = directive_table; kt->length >= 0; kt++)
1990     if (kt->length == ident_len
1991         && strncmp (pfile->token_buffer + ident, kt->name, kt->length) == 0)
1992       switch (kt->type)
1993         {
1994         case T_IF:
1995         case T_IFDEF:
1996         case T_IFNDEF:
1997             temp = (IF_STACK_FRAME *) xmalloc (sizeof (IF_STACK_FRAME));
1998             temp->next = pfile->if_stack;
1999             pfile->if_stack = temp;
2000             temp->fname = CPP_BUFFER(pfile)->nominal_fname;
2001             temp->type = kt->type;
2002             return 0;
2003
2004         case T_ELSE:
2005             if (CPP_PEDANTIC (pfile) && pfile->if_stack != stack)
2006               validate_else (pfile, "#else");
2007             /* fall through */
2008         case T_ELIF:
2009             if (pfile->if_stack->type == T_ELSE)
2010               cpp_error (pfile, "`%s' after `#else'", kt->name);
2011             
2012             if (pfile->if_stack == stack)
2013               return 1;
2014             else
2015               {
2016                 pfile->if_stack->type = kt->type;
2017                 return 0;
2018               }
2019
2020             case T_ENDIF:
2021                 if (CPP_PEDANTIC (pfile) && pfile->if_stack != stack)
2022                   validate_else (pfile, "#endif");
2023
2024                 if (pfile->if_stack == stack)
2025                   return 1;
2026                     
2027                 temp = pfile->if_stack;
2028                 pfile->if_stack = temp->next;
2029                 free (temp);
2030                 return 0;
2031
2032             default:
2033                 return 0;
2034             }
2035
2036     /* Don't let erroneous code go by.  */
2037     if (!CPP_OPTIONS (pfile)->lang_asm && CPP_PEDANTIC (pfile))
2038         cpp_pedwarn (pfile, "invalid preprocessor directive name");
2039     return 0;
2040 }
2041
2042 /* skip to #endif, #else, or #elif.  adjust line numbers, etc.
2043  * leaves input ptr at the sharp sign found.
2044  */
2045 static void
2046 skip_if_group (pfile)
2047     cpp_reader *pfile;
2048 {
2049   int c;
2050   IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */
2051   U_CHAR *beg_of_line;
2052   long old_written;
2053
2054   if (CPP_OPTIONS (pfile)->output_conditionals)
2055     {
2056       CPP_PUTS (pfile, "#failed\n", 8);
2057       pfile->lineno++;
2058       output_line_command (pfile, same_file);
2059     }
2060
2061   old_written = CPP_WRITTEN (pfile);
2062   
2063   for (;;)
2064     {
2065       beg_of_line = CPP_BUFFER (pfile)->cur;
2066
2067       if (! CPP_TRADITIONAL (pfile))
2068         cpp_skip_hspace (pfile);
2069       c = GETC();
2070       if (c == '\n')
2071         {
2072           if (CPP_OPTIONS (pfile)->output_conditionals)
2073             CPP_PUTC (pfile, c);
2074           CPP_BUMP_LINE (pfile);
2075           continue;
2076         }
2077       else if (c == '#')
2078         {
2079           if (consider_directive_while_skipping (pfile, save_if_stack))
2080             break;
2081         }
2082       else if (c == EOF)
2083         return;  /* Caller will issue error. */
2084
2085       FORWARD(-1);
2086       if (CPP_OPTIONS (pfile)->output_conditionals)
2087         {
2088           CPP_PUTS (pfile, beg_of_line, CPP_BUFFER (pfile)->cur - beg_of_line);
2089           copy_rest_of_line (pfile);
2090         }
2091       else
2092         {
2093           copy_rest_of_line (pfile);
2094           CPP_SET_WRITTEN (pfile, old_written);  /* discard it */
2095         }
2096
2097       c = GETC();
2098       if (c == EOF)
2099         return;  /* Caller will issue error. */
2100       else
2101         {
2102           /* \n */
2103           if (CPP_OPTIONS (pfile)->output_conditionals)
2104             {
2105               CPP_PUTC (pfile, c);
2106               pfile->lineno++;
2107             }
2108           CPP_BUMP_LINE (pfile);
2109         }
2110     }     
2111
2112   /* Back up to the beginning of this line.  Caller will process the
2113      directive. */
2114   CPP_BUFFER (pfile)->cur = beg_of_line;
2115   pfile->only_seen_white = 1;
2116   if (CPP_OPTIONS (pfile)->output_conditionals)
2117     {
2118       CPP_PUTS (pfile, "#endfailed\n", 11);
2119       pfile->lineno++;
2120     }
2121 }
2122
2123 /*
2124  * handle a #else directive.  Do this by just continuing processing
2125  * without changing  if_stack ;  this is so that the error message
2126  * for missing #endif's etc. will point to the original #if.  It
2127  * is possible that something different would be better.
2128  */
2129
2130 static int
2131 do_else (pfile, keyword)
2132      cpp_reader *pfile;
2133      const struct directive *keyword ATTRIBUTE_UNUSED;
2134 {
2135   cpp_buffer *ip = CPP_BUFFER (pfile);
2136
2137   if (CPP_PEDANTIC (pfile))
2138     validate_else (pfile, "#else");
2139   skip_rest_of_line (pfile);
2140
2141   if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
2142     cpp_error (pfile, "`#else' not within a conditional");
2143     return 0;
2144   } else {
2145     /* #ifndef can't have its special treatment for containing the whole file
2146        if it has a #else clause.  */
2147     pfile->if_stack->control_macro = 0;
2148
2149     if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
2150       cpp_error (pfile, "`#else' after `#else'");
2151       fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
2152       if (strcmp (pfile->if_stack->fname, ip->nominal_fname) != 0)
2153         fprintf (stderr, ", file %s", pfile->if_stack->fname);
2154       fprintf (stderr, ")\n");
2155     }
2156     pfile->if_stack->type = T_ELSE;
2157   }
2158
2159   if (pfile->if_stack->if_succeeded)
2160     skip_if_group (pfile);
2161   else {
2162     ++pfile->if_stack->if_succeeded;    /* continue processing input */
2163     output_line_command (pfile, same_file);
2164   }
2165   return 0;
2166 }
2167
2168 /*
2169  * unstack after #endif command
2170  */
2171
2172 static int
2173 do_endif (pfile, keyword)
2174      cpp_reader *pfile;
2175      const struct directive *keyword ATTRIBUTE_UNUSED;
2176 {
2177   if (CPP_PEDANTIC (pfile))
2178     validate_else (pfile, "#endif");
2179   skip_rest_of_line (pfile);
2180
2181   if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
2182     cpp_error (pfile, "`#endif' not within a conditional");
2183   else
2184     {
2185       IF_STACK_FRAME *temp = pfile->if_stack;
2186       pfile->if_stack = temp->next;
2187       if (temp->control_macro != 0)
2188         {
2189           /* This #endif matched a #ifndef at the start of the file.
2190              See if it is at the end of the file.  */
2191           int c;
2192
2193           parse_set_mark (pfile);
2194
2195           for (;;)
2196             {
2197               cpp_skip_hspace (pfile);
2198               c = GETC ();
2199               if (c != '\n')
2200                 break;
2201             }
2202           parse_goto_mark (pfile);
2203
2204           if (c == EOF)
2205             {
2206               /* This #endif ends a #ifndef
2207                  that contains all of the file (aside from whitespace).
2208                  Arrange not to include the file again
2209                  if the macro that was tested is defined. */
2210               struct cpp_buffer *ip;
2211               for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
2212                 if (ip->fname != NULL)
2213                   break;
2214               ip->ihash->control_macro = (char *) temp->control_macro;
2215             }
2216         }
2217       free (temp);
2218       output_line_command (pfile, same_file);
2219     }
2220   return 0;
2221 }
2222
2223 /* When an #else or #endif is found while skipping failed conditional,
2224    if -pedantic was specified, this is called to warn about text after
2225    the command name.  P points to the first char after the command name.  */
2226
2227 static void
2228 validate_else (pfile, directive)
2229      cpp_reader *pfile;
2230      const char *directive;
2231 {
2232   int c;
2233   cpp_skip_hspace (pfile);
2234   c = PEEKC ();
2235   if (c != EOF && c != '\n')
2236     cpp_pedwarn (pfile,
2237                  "text following `%s' violates ANSI standard", directive);
2238 }
2239
2240 /* Convert T_IF, etc. to a string.   Used in error messages.  */
2241 static const char *
2242 if_directive_name (pfile, ifs)
2243      cpp_reader *pfile;
2244      struct if_stack *ifs;
2245 {
2246   switch (ifs->type)
2247     {
2248     case T_IF:      return "#if";
2249     case T_IFDEF:   return "#ifdef";
2250     case T_IFNDEF:  return "#ifndef";
2251     case T_ELIF:    return "#elif";
2252     case T_ELSE:    return "#else";
2253     default:
2254       cpp_fatal (pfile, "impossible if_stack->type value %d", ifs->type);
2255       return "unknown";
2256     }
2257 }
2258
2259 /* Get the next token, and add it to the text in pfile->token_buffer.
2260    Return the kind of token we got.  */
2261   
2262 enum cpp_token
2263 cpp_get_token (pfile)
2264      cpp_reader *pfile;
2265 {
2266   register int c, c2, c3;
2267   enum cpp_token token;
2268   struct cpp_options *opts = CPP_OPTIONS (pfile);
2269
2270  get_next:
2271   c = GETC();
2272   if (c == EOF)
2273     {
2274     handle_eof:
2275       if (CPP_BUFFER (pfile)->manual_pop)
2276         /* If we've been reading from redirected input, the
2277            frontend will pop the buffer.  */
2278         return CPP_EOF;
2279       else if (CPP_BUFFER (pfile)->seen_eof)
2280         {
2281           if (CPP_PREV_BUFFER (CPP_BUFFER (pfile)) == CPP_NULL_BUFFER (pfile))
2282             return CPP_EOF;
2283
2284           cpp_pop_buffer (pfile);
2285           goto get_next;
2286         }
2287       else
2288         {
2289           cpp_buffer *next_buf = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
2290           struct if_stack *ifs, *nifs;
2291
2292           /* Unwind the conditional stack and generate error messages.  */
2293           for (ifs = pfile->if_stack;
2294                ifs != CPP_BUFFER (pfile)->if_stack;
2295                ifs = nifs)
2296             {
2297               cpp_error_with_line (pfile, ifs->lineno, -1,
2298                                    "unterminated `%s' conditional",
2299                                    if_directive_name (pfile, ifs));
2300
2301               nifs = ifs->next;
2302               free (ifs);
2303             }
2304           pfile->if_stack = ifs;
2305
2306           if (CPP_BUFFER (pfile)->nominal_fname
2307               && next_buf != CPP_NULL_BUFFER (pfile))
2308             {
2309               /* We're about to return from an #include file.
2310                  Emit #line information now (as part of the CPP_POP) result.
2311                  But the #line refers to the file we will pop to.  */
2312               cpp_buffer *cur_buffer = CPP_BUFFER (pfile);
2313               CPP_BUFFER (pfile) = next_buf;
2314               pfile->input_stack_listing_current = 0;
2315               output_line_command (pfile, leave_file);
2316               CPP_BUFFER (pfile) = cur_buffer;
2317             }
2318
2319           CPP_BUFFER (pfile)->seen_eof = 1;
2320           return CPP_POP;
2321         }
2322     }
2323   else
2324     {
2325       switch (c)
2326         {
2327         case '/':
2328           if (PEEKC () == '=')
2329             goto op2;
2330
2331         comment:
2332           if (opts->put_out_comments)
2333             c = copy_comment (pfile, c);
2334           else
2335             c = skip_comment (pfile, c);
2336           if (c == EOF)
2337             goto handle_eof;
2338           else if (c != ' ')
2339             goto randomchar;
2340           
2341           /* Comments are equivalent to spaces.
2342              For -traditional, a comment is equivalent to nothing.  */
2343           if (opts->traditional || opts->put_out_comments)
2344             return CPP_COMMENT;
2345           else
2346             {
2347               CPP_PUTC (pfile, c);
2348               return CPP_HSPACE;
2349             }
2350 #if 0
2351           if (opts->for_lint) {
2352             U_CHAR *argbp;
2353             int cmdlen, arglen;
2354             char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen);
2355             
2356             if (lintcmd != NULL) {
2357               /* I believe it is always safe to emit this newline: */
2358               obp[-1] = '\n';
2359               bcopy ("#pragma lint ", (char *) obp, 13);
2360               obp += 13;
2361               bcopy (lintcmd, (char *) obp, cmdlen);
2362               obp += cmdlen;
2363
2364               if (arglen != 0) {
2365                 *(obp++) = ' ';
2366                 bcopy (argbp, (char *) obp, arglen);
2367                 obp += arglen;
2368               }
2369
2370               /* OK, now bring us back to the state we were in before we entered
2371                  this branch.  We need #line because the newline for the pragma
2372                  could mess things up.  */
2373               output_line_command (pfile, same_file);
2374               *(obp++) = ' ';   /* just in case, if comments are copied thru */
2375               *(obp++) = '/';
2376             }
2377           }
2378 #endif
2379
2380         case '#':
2381 #if 0
2382           /* If this is expanding a macro definition, don't recognize
2383              preprocessor directives.  */
2384           if (ip->macro != 0)
2385             goto randomchar;
2386           /* If this is expand_into_temp_buffer, recognize them
2387              only after an actual newline at this level,
2388              not at the beginning of the input level.  */
2389           if (ip->fname == 0 && beg_of_line == ip->buf)
2390             goto randomchar;
2391           if (ident_length)
2392             goto specialchar;
2393 #endif
2394
2395           if (!pfile->only_seen_white)
2396             goto randomchar;
2397           if (handle_directive (pfile))
2398             return CPP_DIRECTIVE;
2399           pfile->only_seen_white = 0;
2400           return CPP_OTHER;
2401
2402         case '\"':
2403         case '\'':
2404         string:
2405           parse_string (pfile, c);
2406           pfile->only_seen_white = 0;
2407           return c == '\'' ? CPP_CHAR : CPP_STRING;
2408
2409         case '$':
2410           if (!opts->dollars_in_ident)
2411             goto randomchar;
2412           goto letter;
2413
2414         case ':':
2415           if (opts->cplusplus && PEEKC () == ':')
2416             goto op2;
2417           goto randomchar;
2418
2419         case '&':
2420         case '+':
2421         case '|':
2422           c2 = PEEKC ();
2423           if (c2 == c || c2 == '=')
2424             goto op2;
2425           goto randomchar;
2426
2427         case '*':
2428         case '!':
2429         case '%':
2430         case '=':
2431         case '^':
2432           if (PEEKC () == '=')
2433             goto op2;
2434           goto randomchar;
2435
2436         case '-':
2437           c2 = PEEKC ();
2438           if (c2 == '-' && opts->chill)
2439             goto comment;  /* Chill style comment */
2440           if (c2 == '-' || c2 == '=')
2441             goto op2;
2442           if (c2 == '>')
2443             {
2444               if (opts->cplusplus && PEEKN (1) == '*')
2445                 {
2446                   /* In C++, there's a ->* operator.  */
2447                   token = CPP_OTHER;
2448                   pfile->only_seen_white = 0;
2449                   CPP_RESERVE (pfile, 4);
2450                   CPP_PUTC_Q (pfile, c);
2451                   CPP_PUTC_Q (pfile, GETC ());
2452                   CPP_PUTC_Q (pfile, GETC ());
2453                   CPP_NUL_TERMINATE_Q (pfile);
2454                   return token;
2455                 }
2456               goto op2;
2457             }
2458           goto randomchar;
2459
2460         case '<':
2461           if (pfile->parsing_include_directive)
2462             {
2463               for (;;)
2464                 {
2465                   CPP_PUTC (pfile, c);
2466                   if (c == '>')
2467                     break;
2468                   c = GETC ();
2469                   if (c == '\n' || c == EOF)
2470                     {
2471                       cpp_error (pfile,
2472                                  "missing '>' in `#include <FILENAME>'");
2473                       break;
2474                     }
2475                   else if (c == '\r')
2476                     {
2477                       if (!CPP_BUFFER (pfile)->has_escapes)
2478                         {
2479                           /* Backslash newline is replaced by nothing. */
2480                           CPP_ADJUST_WRITTEN (pfile, -1);
2481                           CPP_BUMP_LINE (pfile);
2482                         }
2483                       else
2484                         {
2485                           /* We might conceivably get \r- or \r<space> in
2486                              here.  Just delete 'em. */
2487                           int d = GETC();
2488                           if (d != '-' && d != ' ')
2489                             cpp_fatal (pfile,
2490                                   "internal error: unrecognized escape \\r%c",
2491                                        d);
2492                           CPP_ADJUST_WRITTEN (pfile, -1);
2493                         }                         
2494                     }
2495                 }
2496               return CPP_STRING;
2497             }
2498           /* else fall through */
2499         case '>':
2500           c2 = PEEKC ();
2501           if (c2 == '=')
2502             goto op2;
2503           /* GNU C++ supports MIN and MAX operators <? and >?.  */
2504           if (c2 != c && (!opts->cplusplus || c2 != '?'))
2505             goto randomchar;
2506           FORWARD(1);
2507           CPP_RESERVE (pfile, 4);
2508           CPP_PUTC (pfile, c);
2509           CPP_PUTC (pfile, c2);
2510           c3 = PEEKC ();
2511           if (c3 == '=')
2512             CPP_PUTC_Q (pfile, GETC ());
2513           CPP_NUL_TERMINATE_Q (pfile);
2514           pfile->only_seen_white = 0;
2515           return CPP_OTHER;
2516
2517         case '.':
2518           c2 = PEEKC ();
2519           if (ISDIGIT(c2))
2520             {
2521               CPP_RESERVE(pfile, 2);
2522               CPP_PUTC_Q (pfile, '.');
2523               c = GETC ();
2524               goto number;
2525             }
2526
2527           /* In C++ there's a .* operator.  */
2528           if (opts->cplusplus && c2 == '*')
2529             goto op2;
2530
2531           if (c2 == '.' && PEEKN(1) == '.')
2532             {
2533               CPP_RESERVE(pfile, 4);
2534               CPP_PUTC_Q (pfile, '.');
2535               CPP_PUTC_Q (pfile, '.');
2536               CPP_PUTC_Q (pfile, '.');
2537               FORWARD (2);
2538               CPP_NUL_TERMINATE_Q (pfile);
2539               pfile->only_seen_white = 0;
2540               return CPP_3DOTS;
2541             }
2542           goto randomchar;
2543
2544         op2:
2545           token = CPP_OTHER;
2546           pfile->only_seen_white = 0;
2547           CPP_RESERVE(pfile, 3);
2548           CPP_PUTC_Q (pfile, c);
2549           CPP_PUTC_Q (pfile, GETC ());
2550           CPP_NUL_TERMINATE_Q (pfile);
2551           return token;
2552
2553         case 'L':
2554           c2 = PEEKC ();
2555           if ((c2 == '\'' || c2 == '\"') && !CPP_TRADITIONAL (pfile))
2556             {
2557               CPP_PUTC (pfile, c);
2558               c = GETC ();
2559               goto string;
2560             }
2561           goto letter;
2562
2563         case '0': case '1': case '2': case '3': case '4':
2564         case '5': case '6': case '7': case '8': case '9':
2565         number:
2566           c2  = '.';
2567           for (;;)
2568             {
2569               CPP_RESERVE (pfile, 2);
2570               CPP_PUTC_Q (pfile, c);
2571               c = PEEKC ();
2572               if (c == EOF)
2573                 break;
2574               if (!is_idchar[c] && c != '.'
2575                   && ((c2 != 'e' && c2 != 'E'
2576                        && ((c2 != 'p' && c2 != 'P') || CPP_C89 (pfile)))
2577                       || (c != '+' && c != '-')))
2578                 break;
2579               FORWARD(1);
2580               c2= c;
2581             }
2582           CPP_NUL_TERMINATE_Q (pfile);
2583           pfile->only_seen_white = 0;
2584           return CPP_NUMBER;
2585         case 'b': case 'c': case 'd': case 'h': case 'o':
2586         case 'B': case 'C': case 'D': case 'H': case 'O':
2587           if (opts->chill && PEEKC () == '\'')
2588             {
2589               pfile->only_seen_white = 0;
2590               CPP_RESERVE (pfile, 2);
2591               CPP_PUTC_Q (pfile, c);
2592               CPP_PUTC_Q (pfile, '\'');
2593               FORWARD(1);
2594               for (;;)
2595                 {
2596                   c = GETC();
2597                   if (c == EOF)
2598                     goto chill_number_eof;
2599                   if (!is_idchar[c])
2600                     break;
2601                   CPP_PUTC (pfile, c);
2602                 }
2603               if (c == '\'')
2604                 {
2605                   CPP_RESERVE (pfile, 2);
2606                   CPP_PUTC_Q (pfile, c);
2607                   CPP_NUL_TERMINATE_Q (pfile);
2608                   return CPP_STRING;
2609                 }
2610               else
2611                 {
2612                   FORWARD(-1);
2613                 chill_number_eof:
2614                   CPP_NUL_TERMINATE (pfile);
2615                   return CPP_NUMBER;
2616                 }
2617             }
2618           else
2619             goto letter;
2620         case '_':
2621         case 'a': case 'e': case 'f': case 'g': case 'i': case 'j':
2622         case 'k': case 'l': case 'm': case 'n': case 'p': case 'q':
2623         case 'r': case 's': case 't': case 'u': case 'v': case 'w':
2624         case 'x': case 'y': case 'z':
2625         case 'A': case 'E': case 'F': case 'G': case 'I': case 'J':
2626         case 'K': case 'M': case 'N': case 'P': case 'Q': case 'R':
2627         case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
2628         case 'Y': case 'Z':
2629         letter:
2630           {
2631             HASHNODE *hp;
2632             unsigned char *ident;
2633             int before_name_written = CPP_WRITTEN (pfile);
2634             int ident_len;
2635             parse_name (pfile, c);
2636             pfile->only_seen_white = 0;
2637             if (pfile->no_macro_expand)
2638               return CPP_NAME;
2639             ident = pfile->token_buffer + before_name_written;
2640             ident_len = CPP_PWRITTEN (pfile) - ident;
2641             hp = cpp_lookup (pfile, ident, ident_len, -1);
2642             if (!hp)
2643               return CPP_NAME;
2644             if (hp->type == T_DISABLED)
2645               {
2646                 if (pfile->output_escapes)
2647                   { /* Return "\r-IDENT", followed by '\0'.  */
2648                     int i;
2649                     CPP_RESERVE (pfile, 3);
2650                     ident = pfile->token_buffer + before_name_written;
2651                     CPP_ADJUST_WRITTEN (pfile, 2);
2652                     for (i = ident_len; i >= 0; i--) ident[i+2] = ident[i];
2653                     ident[0] = '\r';
2654                     ident[1] = '-';
2655                   }
2656                 return CPP_NAME;
2657               }
2658
2659             /* If macro wants an arglist, verify that a '(' follows.
2660                first skip all whitespace, copying it to the output
2661                after the macro name.  Then, if there is no '(',
2662                decide this is not a macro call and leave things that way.  */
2663             if (hp->type == T_MACRO && hp->value.defn->nargs >= 0)
2664             {
2665               int is_macro_call, macbuf_whitespace = 0;
2666
2667               parse_set_mark (pfile);
2668               for (;;)
2669                 {
2670                   cpp_skip_hspace (pfile);
2671                   c = PEEKC ();
2672                   is_macro_call = c == '(';
2673                   if (c != EOF)
2674                     {
2675                       if (c != '\n')
2676                         break;
2677                       FORWARD (1);
2678                     }
2679                   else
2680                     {
2681                       if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
2682                         {
2683                           if (CPP_BUFFER (pfile)->mark !=
2684                               (CPP_BUFFER (pfile)->cur
2685                                - CPP_BUFFER (pfile)->buf))
2686                              macbuf_whitespace = 1;
2687
2688                           /* The mark goes away automatically when
2689                              the buffer is popped. */
2690                           cpp_pop_buffer (pfile);
2691                           parse_set_mark (pfile);
2692                         }
2693                       else
2694                         break;
2695                     }
2696                 }
2697               if (!is_macro_call)
2698                 {
2699                   parse_goto_mark (pfile);
2700                   if (macbuf_whitespace)
2701                     CPP_PUTC (pfile, ' ');
2702                 }
2703               else
2704                 parse_clear_mark (pfile);
2705               if (!is_macro_call)
2706                 return CPP_NAME;
2707             }
2708             /* This is now known to be a macro call.
2709                Expand the macro, reading arguments as needed,
2710                and push the expansion on the input stack.  */
2711             macroexpand (pfile, hp);
2712             CPP_SET_WRITTEN (pfile, before_name_written);
2713           }
2714           goto get_next;
2715
2716         case ' ':  case '\t':  case '\v':
2717           for (;;)
2718             {
2719               CPP_PUTC (pfile, c);
2720               c = PEEKC ();
2721               if (c == EOF || !is_hor_space[c])
2722                 break;
2723               FORWARD(1);
2724             }
2725           return CPP_HSPACE;
2726
2727         case '\r':
2728           if (CPP_BUFFER (pfile)->has_escapes)
2729             {
2730               c = GETC ();
2731               if (c == '-')
2732                 {
2733                   if (pfile->output_escapes)
2734                     CPP_PUTS (pfile, "\r-", 2);
2735                   parse_name (pfile, GETC ());
2736                   return CPP_NAME;
2737                 }
2738               else if (c == ' ')
2739                 {
2740                   CPP_RESERVE (pfile, 2);
2741                   if (pfile->output_escapes)
2742                     CPP_PUTC_Q (pfile, '\r');
2743                   CPP_PUTC_Q (pfile, c);
2744                   return CPP_HSPACE;
2745                 }
2746               else
2747                 {
2748                   cpp_fatal (pfile,
2749                              "internal error: unrecognized escape \\r%c", c);
2750                   goto get_next;
2751                 }
2752             }
2753           else
2754             {
2755               /* Backslash newline is ignored. */
2756               CPP_BUMP_LINE (pfile);
2757               goto get_next;
2758             }
2759
2760         case '\n':
2761           CPP_PUTC (pfile, c);
2762           if (pfile->only_seen_white == 0)
2763             pfile->only_seen_white = 1;
2764           CPP_BUMP_LINE (pfile);
2765           if (! CPP_OPTIONS (pfile)->no_line_commands)
2766             {
2767               pfile->lineno++;
2768               if (CPP_BUFFER (pfile)->lineno != pfile->lineno)
2769                 output_line_command (pfile, same_file);
2770             }
2771           return CPP_VSPACE;
2772
2773         case '(': token = CPP_LPAREN;    goto char1;
2774         case ')': token = CPP_RPAREN;    goto char1;
2775         case '{': token = CPP_LBRACE;    goto char1;
2776         case '}': token = CPP_RBRACE;    goto char1;
2777         case ',': token = CPP_COMMA;     goto char1;
2778         case ';': token = CPP_SEMICOLON; goto char1;
2779
2780         randomchar:
2781         default:
2782           token = CPP_OTHER;
2783         char1:
2784           pfile->only_seen_white = 0;
2785           CPP_PUTC (pfile, c);
2786           return token;
2787         }
2788     }
2789 }
2790
2791 /* Like cpp_get_token, but skip spaces and comments.  */
2792
2793 enum cpp_token
2794 cpp_get_non_space_token (pfile)
2795      cpp_reader *pfile;
2796 {
2797   int old_written = CPP_WRITTEN (pfile);
2798   for (;;)
2799     {
2800       enum cpp_token token = cpp_get_token (pfile);
2801       if (token != CPP_COMMENT && token != CPP_POP
2802           && token != CPP_HSPACE && token != CPP_VSPACE)
2803         return token;
2804       CPP_SET_WRITTEN (pfile, old_written);
2805     }
2806 }
2807
2808 /* Parse an identifier starting with C.  */
2809
2810 static void
2811 parse_name (pfile, c)
2812      cpp_reader *pfile;
2813      int c;
2814 {
2815   for (;;)
2816   {
2817       if (! is_idchar[c])
2818       {
2819           FORWARD (-1);
2820           break;
2821       }
2822
2823       if (c == '$' && CPP_PEDANTIC (pfile))
2824         cpp_pedwarn (pfile, "`$' in identifier");
2825
2826       CPP_RESERVE(pfile, 2); /* One more for final NUL.  */
2827       CPP_PUTC_Q (pfile, c);
2828       c = GETC();
2829       if (c == EOF)
2830         break;
2831   }
2832   CPP_NUL_TERMINATE_Q (pfile);
2833   return;
2834 }
2835
2836 /* Parse a string starting with C.  A single quoted string is treated
2837    like a double -- some programs (e.g., troff) are perverse this way.
2838    (However, a single quoted string is not allowed to extend over
2839    multiple lines.)  */
2840 static void
2841 parse_string (pfile, c)
2842      cpp_reader *pfile;
2843      int c;
2844 {
2845   long start_line, start_column;
2846   
2847   cpp_buf_line_and_col (cpp_file_buffer (pfile), &start_line, &start_column);
2848
2849   CPP_PUTC (pfile, c);
2850   while (1)
2851     {
2852       int cc = GETC();
2853       if (cc == EOF)
2854         {
2855           if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
2856             {
2857               /* try harder: this string crosses a macro expansion
2858                  boundary.  This can happen naturally if -traditional.
2859                  Otherwise, only -D can make a macro with an unmatched
2860                  quote.  */
2861               cpp_pop_buffer (pfile);
2862               continue;
2863             }
2864
2865           cpp_error_with_line (pfile, start_line, start_column,
2866                                "unterminated string or character constant");
2867           if (pfile->multiline_string_line != start_line
2868               && pfile->multiline_string_line != 0)
2869             cpp_error_with_line (pfile,
2870                                  pfile->multiline_string_line, -1,
2871                          "possible real start of unterminated constant");
2872           pfile->multiline_string_line = 0;
2873           break;
2874         }
2875       CPP_PUTC (pfile, cc);
2876       switch (cc)
2877         {
2878         case '\n':
2879           CPP_BUMP_LINE (pfile);
2880           pfile->lineno++;
2881           /* Character constants may not extend over multiple lines.
2882              In ANSI, neither may strings.  We accept multiline strings
2883              as an extension.  */
2884           if (c == '\'')
2885             {
2886               cpp_error_with_line (pfile, start_line, start_column,
2887                                    "unterminated character constant");
2888               return;
2889             }
2890           if (CPP_PEDANTIC (pfile) && pfile->multiline_string_line == 0)
2891             {
2892               cpp_pedwarn_with_line (pfile, start_line, start_column,
2893                                      "string constant runs past end of line");
2894             }
2895           if (pfile->multiline_string_line == 0)
2896             pfile->multiline_string_line = start_line;
2897           break;
2898
2899         case '\r':
2900           CPP_ADJUST_WRITTEN (pfile, -1);
2901           if (CPP_BUFFER (pfile)->has_escapes)
2902             {
2903               cpp_fatal (pfile,
2904                          "internal error: \\r escape inside string constant");
2905               FORWARD(1);
2906             }
2907           else
2908             /* Backslash newline is replaced by nothing at all.  */
2909             CPP_BUMP_LINE (pfile);
2910           break;
2911
2912         case '\\':
2913           cc = GETC();
2914           if (cc != EOF)
2915             CPP_PUTC (pfile, cc);
2916           break;
2917
2918         case '\"':
2919         case '\'':
2920           if (cc == c)
2921             return;
2922           break;
2923         }
2924     }
2925 }
2926
2927 /* Read an assertion into the token buffer, converting to
2928    canonical form: `#predicate(a n swe r)'  The next non-whitespace
2929    character to read should be the first letter of the predicate.
2930    Returns 0 for syntax error, 1 for bare predicate, 2 for predicate
2931    with answer (see callers for why). In case of 0, an error has been
2932    printed. */
2933 static int
2934 parse_assertion (pfile)
2935      cpp_reader *pfile;
2936 {
2937   int c, dropwhite;
2938   cpp_skip_hspace (pfile);
2939   c = PEEKC();
2940   if (! is_idstart[c])
2941     {
2942       cpp_error (pfile, "assertion predicate is not an identifier");
2943       return 0;
2944     }
2945   CPP_PUTC(pfile, '#');
2946   FORWARD(1);
2947   parse_name(pfile, c);
2948
2949   c = PEEKC();
2950   if (c != '(')
2951     {
2952       if (is_hor_space[c] || c == '\r')
2953         cpp_skip_hspace (pfile);
2954       c = PEEKC();
2955     }
2956   if (c != '(')
2957     return 1;
2958
2959   CPP_PUTC(pfile, '(');
2960   FORWARD(1);
2961   dropwhite = 1;
2962   while ((c = GETC()) != ')')
2963     {
2964       if (is_hor_space[c])
2965         {
2966           if (! dropwhite)
2967             {
2968               CPP_PUTC(pfile, ' ');
2969               dropwhite = 1;
2970             }
2971         }
2972       else if (c == '\n' || c == EOF)
2973         {
2974           if (c == '\n') FORWARD(-1);
2975           cpp_error (pfile, "un-terminated assertion answer");
2976           return 0;
2977         }
2978       else if (c == '\r')
2979         /* \r cannot be a macro escape here. */
2980         CPP_BUMP_LINE (pfile);
2981       else
2982         {
2983           CPP_PUTC (pfile, c);
2984           dropwhite = 0;
2985         }
2986     }
2987
2988   if (pfile->limit[-1] == ' ')
2989     pfile->limit[-1] = ')';
2990   else if (pfile->limit[-1] == '(')
2991     {
2992       cpp_error (pfile, "empty token sequence in assertion");
2993       return 0;
2994     }
2995   else
2996     CPP_PUTC (pfile, ')');
2997
2998   CPP_NUL_TERMINATE (pfile);
2999   return 2;
3000 }
3001
3002 static int
3003 do_assert (pfile, keyword)
3004      cpp_reader *pfile;
3005      const struct directive *keyword ATTRIBUTE_UNUSED;
3006 {
3007   char *sym;
3008   int ret, c;
3009   HASHNODE *base, *this;
3010   int baselen, thislen;
3011
3012   if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
3013       && !CPP_BUFFER (pfile)->system_header_p)
3014     cpp_pedwarn (pfile, "ANSI C does not allow `#assert'");
3015
3016   cpp_skip_hspace (pfile);
3017   sym = (char *) CPP_PWRITTEN (pfile);  /* remember where it starts */
3018   ret = parse_assertion (pfile);
3019   if (ret == 0)
3020     goto error;
3021   else if (ret == 1)
3022     {
3023       cpp_error (pfile, "missing token-sequence in `#assert'");
3024       goto error;
3025     }
3026
3027   cpp_skip_hspace (pfile);
3028   c = PEEKC();
3029   if (c != EOF && c != '\n')
3030     {
3031       cpp_error (pfile, "junk at end of `#assert'");
3032       goto error;
3033     }
3034
3035   thislen = strlen (sym);
3036   baselen = index (sym, '(') - sym;
3037   this = cpp_lookup (pfile, sym, thislen, -1);
3038   if (this)
3039     {
3040       cpp_warning (pfile, "`%s' re-asserted", sym);
3041       goto error;
3042     }
3043
3044   base = cpp_lookup (pfile, sym, baselen, -1);
3045   if (! base)
3046     base = cpp_install (pfile, sym, baselen, T_ASSERT, 0, -1);
3047   else if (base->type != T_ASSERT)
3048   {
3049     /* Token clash - but with what?! */
3050     cpp_fatal (pfile,
3051                "cpp internal error: base->type != T_ASSERT in do_assert");
3052     goto error;
3053   }
3054
3055   this = cpp_install (pfile, sym, thislen, T_ASSERT,
3056                       (char *)base->value.aschain, -1);
3057   base->value.aschain = this;
3058   
3059   pfile->limit = (unsigned char *) sym; /* Pop */
3060   return 0;
3061
3062  error:
3063   skip_rest_of_line (pfile);
3064   pfile->limit = (unsigned char *) sym; /* Pop */
3065   return 0;
3066 }
3067
3068 static int
3069 do_unassert (pfile, keyword)
3070      cpp_reader *pfile;
3071      const struct directive *keyword ATTRIBUTE_UNUSED;
3072 {
3073   int c, ret;
3074   char *sym;
3075   long baselen, thislen;
3076   HASHNODE *base, *this, *next;
3077   
3078   if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
3079       && !CPP_BUFFER (pfile)->system_header_p)
3080     cpp_pedwarn (pfile, "ANSI C does not allow `#unassert'");
3081
3082   cpp_skip_hspace (pfile);
3083
3084   sym = (char *) CPP_PWRITTEN (pfile);  /* remember where it starts */
3085   ret = parse_assertion (pfile);
3086   if (ret == 0)
3087     goto error;
3088   
3089   cpp_skip_hspace (pfile);
3090   c = PEEKC ();
3091   if (c != EOF && c != '\n')
3092       cpp_error (pfile, "junk at end of `#unassert'");
3093
3094   thislen = strlen (sym);
3095   if (ret == 1)
3096     {
3097       base = cpp_lookup (pfile, sym, thislen, -1);
3098       if (! base)
3099         goto error;  /* It isn't an error to #undef what isn't #defined,
3100                         so it isn't an error to #unassert what isn't
3101                         #asserted either. */
3102       
3103       for (this = base->value.aschain; this; this = next)
3104         {
3105           next = this->value.aschain;
3106           delete_macro (this);
3107         }
3108       delete_macro (base);
3109     }
3110   else
3111     {
3112       baselen = index (sym, '(') - sym;
3113       base = cpp_lookup (pfile, sym, baselen, -1);
3114       if (! base) goto error;
3115       this = cpp_lookup (pfile, sym, thislen, -1);
3116       if (! this) goto error;
3117
3118       next = base;
3119       while (next->value.aschain != this)
3120         next = next->value.aschain;
3121
3122       next->value.aschain = this->value.aschain;
3123       delete_macro (this);
3124
3125       if (base->value.aschain == NULL)
3126         delete_macro (base);  /* Last answer for this predicate deleted. */
3127     }
3128   
3129   pfile->limit = (unsigned char *) sym; /* Pop */
3130   return 0;
3131  error:
3132   skip_rest_of_line (pfile);
3133   pfile->limit = (unsigned char *) sym; /* Pop */
3134   return 0;
3135 }
3136
3137 /* Process STR as if it appeared as the body of an #unassert. */
3138 void
3139 cpp_unassert (pfile, str)
3140      cpp_reader *pfile;
3141      unsigned char *str;
3142 {
3143   if (cpp_push_buffer (pfile, str, strlen (str)) != NULL)
3144     {
3145       do_assert (pfile, NULL);
3146       cpp_pop_buffer (pfile);
3147     }
3148 }  
3149
3150 int
3151 cpp_read_check_assertion (pfile)
3152      cpp_reader *pfile;
3153 {
3154   U_CHAR *name = CPP_PWRITTEN (pfile);
3155   int result;
3156   HASHNODE *hp;
3157   
3158   FORWARD (1);  /* Skip '#' */
3159   cpp_skip_hspace (pfile);
3160   if (! parse_assertion (pfile))
3161     result = 0;
3162   else
3163     {
3164       hp = cpp_lookup (pfile, name, CPP_PWRITTEN (pfile) - name, -1);
3165       result = (hp != 0);
3166     }
3167
3168   pfile->limit = name;
3169   return result;
3170 }
3171
3172 /* Remember the current position of PFILE.  */
3173
3174 void
3175 parse_set_mark (pfile)
3176      cpp_reader *pfile;
3177 {
3178   cpp_buffer *ip = CPP_BUFFER (pfile);
3179   if (ip->mark != -1)
3180       cpp_fatal (pfile,
3181                  "cpp internal error: ip->mark != -1 in parse_set_mark");
3182
3183   ip->mark = ip->cur - ip->buf;
3184 }
3185
3186 /* Clear the current mark - we no longer need it.  */
3187
3188 void
3189 parse_clear_mark (pfile)
3190      cpp_reader *pfile;
3191 {
3192   cpp_buffer *ip = CPP_BUFFER (pfile);
3193   if (ip->mark == -1)
3194       cpp_fatal (pfile,
3195                  "cpp internal error: ip->mark == -1 in parse_clear_mark");
3196
3197   ip->mark = -1;
3198 }
3199
3200 /* Backup the current position of PFILE to that saved in its mark,
3201    and clear the mark.  */
3202
3203 void
3204 parse_goto_mark (pfile)
3205      cpp_reader *pfile;
3206 {
3207   cpp_buffer *ip = CPP_BUFFER (pfile);
3208   if (ip->mark == -1)
3209       cpp_fatal (pfile,
3210                  "cpp internal error: ip->mark == -1 in parse_goto_mark");
3211
3212   ip->cur = ip->buf + ip->mark;
3213   ip->mark = -1;
3214 }
3215
3216 static void
3217 cpp_print_file_and_line (pfile)
3218      cpp_reader *pfile;
3219 {
3220   cpp_buffer *ip = cpp_file_buffer (pfile);
3221
3222   if (ip != NULL)
3223     {
3224       long line, col;
3225       cpp_buf_line_and_col (ip, &line, &col);
3226       cpp_file_line_for_message (pfile, ip->nominal_fname,
3227                                  line, pfile->show_column ? col : -1);
3228     }
3229 }
3230
3231 static void
3232 v_cpp_error (pfile, msgid, ap)
3233   cpp_reader *pfile;
3234   const char *msgid;
3235   va_list ap;
3236 {
3237   cpp_print_containing_files (pfile);
3238   cpp_print_file_and_line (pfile);
3239   v_cpp_message (pfile, 1, msgid, ap);
3240 }
3241
3242 void
3243 cpp_error VPROTO ((cpp_reader * pfile, const char *msgid, ...))
3244 {
3245 #ifndef ANSI_PROTOTYPES
3246   cpp_reader *pfile;
3247   const char *msgid;
3248 #endif
3249   va_list ap;
3250
3251   VA_START(ap, msgid);
3252   
3253 #ifndef ANSI_PROTOTYPES
3254   pfile = va_arg (ap, cpp_reader *);
3255   msgid = va_arg (ap, const char *);
3256 #endif
3257
3258   v_cpp_error (pfile, msgid, ap);
3259   va_end(ap);
3260 }
3261
3262 /* Print error message but don't count it.  */
3263
3264 static void
3265 v_cpp_warning (pfile, msgid, ap)
3266   cpp_reader *pfile;
3267   const char *msgid;
3268   va_list ap;
3269 {
3270   if (CPP_OPTIONS (pfile)->inhibit_warnings)
3271     return;
3272
3273   if (CPP_OPTIONS (pfile)->warnings_are_errors)
3274     pfile->errors++;
3275
3276   cpp_print_containing_files (pfile);
3277   cpp_print_file_and_line (pfile);
3278   v_cpp_message (pfile, 0, msgid, ap);
3279 }
3280
3281 void
3282 cpp_warning VPROTO ((cpp_reader * pfile, const char *msgid, ...))
3283 {
3284 #ifndef ANSI_PROTOTYPES
3285   cpp_reader *pfile;
3286   const char *msgid;
3287 #endif
3288   va_list ap;
3289   
3290   VA_START (ap, msgid);
3291   
3292 #ifndef ANSI_PROTOTYPES
3293   pfile = va_arg (ap, cpp_reader *);
3294   msgid = va_arg (ap, const char *);
3295 #endif
3296
3297   v_cpp_warning (pfile, msgid, ap);
3298   va_end(ap);
3299 }
3300
3301 /* Print an error message and maybe count it.  */
3302
3303 void
3304 cpp_pedwarn VPROTO ((cpp_reader * pfile, const char *msgid, ...))
3305 {
3306 #ifndef ANSI_PROTOTYPES
3307   cpp_reader *pfile;
3308   const char *msgid;
3309 #endif
3310   va_list ap;
3311   
3312   VA_START (ap, msgid);
3313   
3314 #ifndef ANSI_PROTOTYPES
3315   pfile = va_arg (ap, cpp_reader *);
3316   msgid = va_arg (ap, const char *);
3317 #endif
3318
3319   if (CPP_OPTIONS (pfile)->pedantic_errors)
3320     v_cpp_error (pfile, msgid, ap);
3321   else
3322     v_cpp_warning (pfile, msgid, ap);
3323   va_end(ap);
3324 }
3325
3326 static void
3327 v_cpp_error_with_line (pfile, line, column, msgid, ap)
3328   cpp_reader * pfile;
3329   int line;
3330   int column;
3331   const char * msgid;
3332   va_list ap;
3333 {
3334   cpp_buffer *ip = cpp_file_buffer (pfile);
3335
3336   cpp_print_containing_files (pfile);
3337
3338   if (ip != NULL)
3339     cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
3340
3341   v_cpp_message (pfile, 1, msgid, ap);
3342 }
3343
3344 void
3345 cpp_error_with_line VPROTO ((cpp_reader * pfile, int line, int column,
3346                              const char *msgid, ...))
3347 {
3348 #ifndef ANSI_PROTOTYPES
3349   cpp_reader *pfile;
3350   int line;
3351   int column;
3352   const char *msgid;
3353 #endif
3354   va_list ap;
3355   
3356   VA_START (ap, msgid);
3357   
3358 #ifndef ANSI_PROTOTYPES
3359   pfile = va_arg (ap, cpp_reader *);
3360   line = va_arg (ap, int);
3361   column = va_arg (ap, int);
3362   msgid = va_arg (ap, const char *);
3363 #endif
3364
3365   v_cpp_error_with_line(pfile, line, column, msgid, ap);
3366   va_end(ap);
3367 }
3368
3369 static void
3370 v_cpp_warning_with_line (pfile, line, column, msgid, ap)
3371   cpp_reader * pfile;
3372   int line;
3373   int column;
3374   const char *msgid;
3375   va_list ap;
3376 {
3377   cpp_buffer *ip;
3378
3379   if (CPP_OPTIONS (pfile)->inhibit_warnings)
3380     return;
3381
3382   if (CPP_OPTIONS (pfile)->warnings_are_errors)
3383     pfile->errors++;
3384
3385   cpp_print_containing_files (pfile);
3386
3387   ip = cpp_file_buffer (pfile);
3388
3389   if (ip != NULL)
3390     cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
3391
3392   v_cpp_message (pfile, 0, msgid, ap);
3393 }  
3394
3395 void
3396 cpp_warning_with_line VPROTO ((cpp_reader * pfile, int line, int column,
3397                                const char *msgid, ...))
3398 {
3399 #ifndef ANSI_PROTOTYPES
3400   cpp_reader *pfile;
3401   int line;
3402   int column;
3403   const char *msgid;
3404 #endif
3405   va_list ap;
3406   
3407   VA_START (ap, msgid);
3408   
3409 #ifndef ANSI_PROTOTYPES
3410   pfile = va_arg (ap, cpp_reader *);
3411   line = va_arg (ap, int);
3412   column = va_arg (ap, int);
3413   msgid = va_arg (ap, const char *);
3414 #endif
3415
3416   v_cpp_warning_with_line (pfile, line, column, msgid, ap);
3417   va_end(ap);
3418 }
3419
3420 void
3421 cpp_pedwarn_with_line VPROTO ((cpp_reader * pfile, int line, int column,
3422                                const char *msgid, ...))
3423 {
3424 #ifndef ANSI_PROTOTYPES
3425   cpp_reader *pfile;
3426   int line;
3427   int column;
3428   const char *msgid;
3429 #endif
3430   va_list ap;
3431   
3432   VA_START (ap, msgid);
3433   
3434 #ifndef ANSI_PROTOTYPES
3435   pfile = va_arg (ap, cpp_reader *);
3436   line = va_arg (ap, int);
3437   column = va_arg (ap, int);
3438   msgid = va_arg (ap, const char *);
3439 #endif
3440
3441   if (CPP_OPTIONS (pfile)->pedantic_errors)
3442     v_cpp_error_with_line (pfile, column, line, msgid, ap);
3443   else
3444     v_cpp_warning_with_line (pfile, line, column, msgid, ap);
3445   va_end(ap);
3446 }
3447
3448 /* Report a warning (or an error if pedantic_errors)
3449    giving specified file name and line number, not current.  */
3450
3451 void
3452 cpp_pedwarn_with_file_and_line VPROTO ((cpp_reader *pfile, const char *file,
3453                                         int line, const char *msgid, ...))
3454 {
3455 #ifndef ANSI_PROTOTYPES
3456   cpp_reader *pfile;
3457   const char *file;
3458   int line;
3459   const char *msgid;
3460 #endif
3461   va_list ap;
3462   
3463   VA_START (ap, msgid);
3464
3465 #ifndef ANSI_PROTOTYPES
3466   pfile = va_arg (ap, cpp_reader *);
3467   file = va_arg (ap, const char *);
3468   line = va_arg (ap, int);
3469   msgid = va_arg (ap, const char *);
3470 #endif
3471
3472   if (!CPP_OPTIONS (pfile)->pedantic_errors
3473       && CPP_OPTIONS (pfile)->inhibit_warnings)
3474     return;
3475   if (file != NULL)
3476     cpp_file_line_for_message (pfile, file, line, -1);
3477   v_cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors, msgid, ap);
3478   va_end(ap);
3479 }
3480
3481 /* my_strerror - return the descriptive text associated with an
3482    `errno' code.  */
3483
3484 static const char *
3485 my_strerror (errnum)
3486      int errnum;
3487 {
3488   const char *result;
3489
3490 #ifndef VMS
3491 #ifndef HAVE_STRERROR
3492   result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
3493 #else
3494   result = strerror (errnum);
3495 #endif
3496 #else   /* VMS */
3497   /* VAXCRTL's strerror() takes an optional second argument, which only
3498      matters when the first argument is EVMSERR.  However, it's simplest
3499      just to pass it unconditionally.  `vaxc$errno' is declared in
3500      <errno.h>, and maintained by the library in parallel with `errno'.
3501      We assume that caller's `errnum' either matches the last setting of
3502      `errno' by the library or else does not have the value `EVMSERR'.  */
3503
3504   result = strerror (errnum, vaxc$errno);
3505 #endif
3506
3507   if (!result)
3508     result = "errno = ?";
3509
3510   return result;
3511 }
3512
3513 /* Error including a message from `errno'.  */
3514
3515 void
3516 cpp_error_from_errno (pfile, name)
3517      cpp_reader *pfile;
3518      const char *name;
3519 {
3520   cpp_message_from_errno (pfile, 1, name);
3521 }
3522
3523 void
3524 cpp_message_from_errno (pfile, is_error, name)
3525      cpp_reader *pfile;
3526      int is_error;
3527      const char *name;
3528 {
3529   int e = errno;
3530   cpp_buffer *ip = cpp_file_buffer (pfile);
3531
3532   cpp_print_containing_files (pfile);
3533
3534   if (ip != NULL)
3535     cpp_file_line_for_message (pfile, ip->nominal_fname, ip->lineno, -1);
3536
3537   cpp_message (pfile, is_error, "%s: %s", name, my_strerror (e));
3538 }
3539
3540 void
3541 cpp_perror_with_name (pfile, name)
3542      cpp_reader *pfile;
3543      const char *name;
3544 {
3545   cpp_message (pfile, 1, "%s: %s: %s", progname, name, my_strerror (errno));
3546 }
3547
3548 /* TODO:
3549  * No pre-compiled header file support.
3550  *
3551  * Possibly different enum token codes for each C/C++ token.
3552  *
3553  * Find and cleanup remaining uses of static variables,
3554  *
3555  * Support -dM flag (dump_all_macros).
3556  *
3557  * Support for_lint flag.
3558  */