home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / gnu / gcc-2.5.8-src.lha / src / amiga / gcc-2.5.8 / cccp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-22  |  249.3 KB  |  9,485 lines

  1. /* C Compatible Compiler Preprocessor (CCCP)
  2. Copyright (C) 1986, 1987, 1989, 1992, 1993 Free Software Foundation, Inc.
  3.                     Written by Paul Rubin, June 1986
  4.             Adapted to ANSI C, Richard Stallman, Jan 1987
  5.  
  6. This program is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the
  8. Free Software Foundation; either version 2, or (at your option) any
  9. later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.  In other words, you are welcome to use, share and improve this program.
  21.  You are forbidden to forbid anyone else to use, share and improve
  22.  what you give them.   Help stamp out software-hoarding!  */
  23.  
  24. typedef unsigned char U_CHAR;
  25.  
  26. #ifdef EMACS
  27. #define NO_SHORTNAMES
  28. #include "../src/config.h"
  29. #ifdef open
  30. #undef open
  31. #undef read
  32. #undef write
  33. #endif /* open */
  34. #endif /* EMACS */
  35.  
  36. /* The macro EMACS is defined when cpp is distributed as part of Emacs,
  37.    for the sake of machines with limited C compilers.  */
  38. #ifndef EMACS
  39. #include "config.h"
  40. #endif /* not EMACS */
  41.  
  42. #ifdef amigados
  43. /* Since cpp uses alloca to store all its read files, this is quite deadly
  44.    on a system with non-automatic stackgrowth like amigados, so we better
  45.    turn it off now.  Normally alloca is #defined to __builtin_alloca, so
  46.    undefining it causes an external alloca to be used.
  47.  
  48.    Note that it's not wise to generally inhibit __builtin_alloca, since
  49.    using the generic emulator entitels a serious (!) speed penalty, and
  50.    it's bad enough that we have to live with it in cccp, don't make cc1
  51.    unbearably slow as well... */
  52.  
  53. #undef alloca
  54.  
  55. static int amigados_abs_filename ();
  56. #endif
  57.  
  58. #ifndef STANDARD_INCLUDE_DIR
  59. #define STANDARD_INCLUDE_DIR "/gnu/include"
  60. #endif
  61.  
  62. #ifndef LOCAL_INCLUDE_DIR
  63. #define LOCAL_INCLUDE_DIR "/local/include"
  64. #endif
  65.  
  66. #if 0 /* We can't get ptrdiff_t, so I arranged not to need PTR_INT_TYPE.  */
  67. #ifdef __STDC__
  68. #define PTR_INT_TYPE ptrdiff_t
  69. #else
  70. #define PTR_INT_TYPE long
  71. #endif
  72. #endif /* 0 */
  73.  
  74. #include "pcp.h"
  75.  
  76. #ifndef STDC_VALUE
  77. #define STDC_VALUE 1
  78. #endif
  79.  
  80. /* By default, colon separates directories in a path.  */
  81. #ifndef PATH_SEPARATOR
  82. #define PATH_SEPARATOR ':'
  83. #endif
  84.  
  85. /* In case config.h defines these.  */
  86. #undef bcopy
  87. #undef bzero
  88. #undef bcmp
  89.  
  90. #include <sys/types.h>
  91. #include <sys/stat.h>
  92. #include <ctype.h>
  93. #include <stdio.h>
  94. #include <signal.h>
  95.  
  96. #ifndef VMS
  97. #ifndef USG
  98. #include <sys/time.h>        /* for __DATE__ and __TIME__ */
  99. #include <sys/resource.h>
  100. #else
  101. #include <time.h>
  102. #include <fcntl.h>
  103. #endif /* USG */
  104. #endif /* not VMS */
  105.  
  106. /* This defines "errno" properly for VMS, and gives us EACCES. */
  107. #include <errno.h>
  108.  
  109. /* VMS-specific definitions */
  110. #ifdef VMS
  111. #include <time.h>
  112. #include <perror.h>        /* This defines sys_errlist/sys_nerr properly */
  113. #include <descrip.h>
  114. #define O_RDONLY    0    /* Open arg for Read/Only  */
  115. #define O_WRONLY    1    /* Open arg for Write/Only */
  116. #define read(fd,buf,size)    VMS_read (fd,buf,size)
  117. #define write(fd,buf,size)    VMS_write (fd,buf,size)
  118. #define open(fname,mode,prot)    VMS_open (fname,mode,prot)
  119. #define fopen(fname,mode)    VMS_fopen (fname,mode)
  120. #define freopen(fname,mode,ofile) VMS_freopen (fname,mode,ofile)
  121. #define strncat(dst,src,cnt) VMS_strncat (dst,src,cnt)
  122. static char * VMS_strncat ();
  123. static int VMS_read ();
  124. static int VMS_write ();
  125. static int VMS_open ();
  126. static FILE * VMS_fopen ();
  127. static FILE * VMS_freopen ();
  128. static void hack_vms_include_specification ();
  129. typedef struct { unsigned :16, :16, :16; } vms_ino_t;
  130. #define ino_t vms_ino_t
  131. #define INCLUDE_LEN_FUDGE 10    /* leave room for VMS syntax conversion */
  132. #ifdef __GNUC__
  133. #define BSTRING            /* VMS/GCC supplies the bstring routines */
  134. #endif /* __GNUC__ */
  135. #endif /* VMS */
  136.   
  137. extern char *index ();
  138. extern char *rindex ();
  139.  
  140. #ifndef O_RDONLY
  141. #define O_RDONLY 0
  142. #endif
  143.  
  144. #undef MIN
  145. #undef MAX
  146. #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
  147. #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
  148.  
  149. /* Find the largest host integer type and set its size and type.  */
  150.  
  151. #ifndef HOST_BITS_PER_WIDE_INT
  152.  
  153. #if HOST_BITS_PER_LONG > HOST_BITS_PER_INT
  154. #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG
  155. #define HOST_WIDE_INT long
  156. #else
  157. #define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT
  158. #define HOST_WIDE_INT int
  159. #endif
  160.  
  161. #endif
  162.  
  163. #ifndef S_ISREG
  164. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  165. #endif
  166.  
  167. #ifndef S_ISDIR
  168. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  169. #endif
  170.  
  171. /* Define a generic NULL if one hasn't already been defined.  */
  172.  
  173. #ifndef NULL
  174. #define NULL 0
  175. #endif
  176.  
  177. #ifndef GENERIC_PTR
  178. #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
  179. #define GENERIC_PTR void *
  180. #else
  181. #define GENERIC_PTR char *
  182. #endif
  183. #endif
  184.  
  185. #ifndef NULL_PTR
  186. #define NULL_PTR ((GENERIC_PTR)0)
  187. #endif
  188.  
  189. #ifndef INCLUDE_LEN_FUDGE
  190. #define INCLUDE_LEN_FUDGE 0
  191. #endif
  192.  
  193. /* Forward declarations.  */
  194.  
  195. char *xmalloc ();
  196. void error ();
  197. void warning ();
  198.  
  199. /* External declarations.  */
  200.  
  201. extern char *getenv ();
  202. extern FILE *fdopen ();
  203. extern char *version_string;
  204. extern struct tm *localtime ();
  205. extern int sys_nerr;
  206. #if defined(bsd4_4)
  207. extern const char *const sys_errlist[];
  208. #else
  209. extern char *sys_errlist[];
  210. #endif
  211. extern int parse_escape ();
  212.  
  213. #ifndef errno
  214. extern int errno;
  215. #endif
  216.  
  217. /* Forward declarations.  */
  218.  
  219. struct directive;
  220. struct file_buf;
  221. struct arglist;
  222. struct argdata;
  223.  
  224. #if defined(USG) || defined(VMS)
  225. #ifndef BSTRING
  226. void bcopy ();
  227. void bzero ();
  228. int bcmp ();
  229. #endif
  230. #endif
  231.  
  232. /* These functions are declared to return int instead of void since they
  233.    are going to be placed in a table and some old compilers have trouble with
  234.    pointers to functions returning void.  */
  235.  
  236. static int do_define ();
  237. static int do_line ();
  238. static int do_include ();
  239. static int do_undef ();
  240. static int do_error ();
  241. static int do_pragma ();
  242. static int do_ident ();
  243. static int do_if ();
  244. static int do_xifdef ();
  245. static int do_else ();
  246. static int do_elif ();
  247. static int do_endif ();
  248. static int do_sccs ();
  249. static int do_once ();
  250. static int do_assert ();
  251. static int do_unassert ();
  252. static int do_warning ();
  253.  
  254. static void add_import ();
  255. static void append_include_chain ();
  256. static void deps_output ();
  257. static void make_undef ();
  258. static void make_definition ();
  259. static void make_assertion ();
  260. static void path_include ();
  261. static void initialize_builtins ();
  262. static void initialize_char_syntax ();
  263. static void dump_arg_n ();
  264. static void dump_defn_1 ();
  265. static void delete_macro ();
  266. static void trigraph_pcp ();
  267. static void rescan ();
  268. static void finclude ();
  269. static void validate_else ();
  270. static int comp_def_part ();
  271. static void error_from_errno ();
  272. static void error_with_line ();
  273. void pedwarn ();
  274. void pedwarn_with_line ();
  275. static void pedwarn_with_file_and_line ();
  276. static void fatal ();
  277. void fancy_abort ();
  278. static void pfatal_with_name ();
  279. static void perror_with_name ();
  280. static void pipe_closed ();
  281. static void print_containing_files ();
  282. static int lookup_import ();
  283. static int redundant_include_p ();
  284. static is_system_include ();
  285. static int check_preconditions ();
  286. static void pcfinclude ();
  287. static void pcstring_used ();
  288. static void write_output ();
  289. static int check_macro_name ();
  290. static int compare_defs ();
  291. static int compare_token_lists ();
  292. static int eval_if_expression ();
  293. static int discard_comments ();
  294. static int change_newlines ();
  295. static int line_for_error ();
  296. static int hashf ();
  297. static int file_size_and_mode ();
  298.  
  299. static struct arglist *read_token_list ();
  300. static void free_token_list ();
  301.  
  302. static struct hashnode *install ();
  303. struct hashnode *lookup ();
  304.  
  305. static struct assertion_hashnode *assertion_install ();
  306. static struct assertion_hashnode *assertion_lookup ();
  307.  
  308. static char *xrealloc ();
  309. static char *xcalloc ();
  310. static char *savestring ();
  311.  
  312. static void delete_assertion ();
  313. static void macroexpand ();
  314. static void dump_all_macros ();
  315. static void conditional_skip ();
  316. static void skip_if_group ();
  317. static void output_line_command ();
  318.  
  319. /* Last arg to output_line_command.  */
  320. enum file_change_code {same_file, enter_file, leave_file};
  321.  
  322. static int grow_outbuf ();
  323. static int handle_directive ();
  324. static void memory_full ();
  325.  
  326. static U_CHAR *macarg1 ();
  327. static char *macarg ();
  328.  
  329. static U_CHAR *skip_to_end_of_comment ();
  330. static U_CHAR *skip_quoted_string ();
  331. static U_CHAR *skip_paren_group ();
  332. static char *quote_string ();
  333.  
  334. static char *check_precompiled ();
  335. /* static struct macrodef create_definition ();    [moved below] */
  336. static void dump_single_macro ();
  337. static void output_dots ();
  338.  
  339. #ifndef FAILURE_EXIT_CODE
  340. #define FAILURE_EXIT_CODE 33    /* gnu cc command understands this */
  341. #endif
  342.  
  343. #ifndef SUCCESS_EXIT_CODE
  344. #define SUCCESS_EXIT_CODE 0    /* 0 means success on Unix.  */
  345. #endif
  346.  
  347. /* Name under which this program was invoked.  */
  348.  
  349. static char *progname;
  350.  
  351. /* Nonzero means use extra default include directories for C++.  */
  352.  
  353. static int cplusplus;
  354.  
  355. /* Nonzero means handle cplusplus style comments */
  356.  
  357. static int cplusplus_comments;
  358.  
  359. /* Nonzero means handle #import, for objective C.  */
  360.  
  361. static int objc;
  362.  
  363. /* Nonzero means this is an assembly file, and allow
  364.    unknown directives, which could be comments.  */
  365.  
  366. static int lang_asm;
  367.  
  368. /* Current maximum length of directory names in the search path
  369.    for include files.  (Altered as we get more of them.)  */
  370.  
  371. static int max_include_len;
  372.  
  373. /* Nonzero means turn NOTREACHED into #pragma NOTREACHED etc */
  374.  
  375. static int lint = 0;
  376.  
  377. /* Nonzero means copy comments into the output file.  */
  378.  
  379. static int put_out_comments = 0;
  380.  
  381. /* Nonzero means don't process the ANSI trigraph sequences.  */
  382.  
  383. static int no_trigraphs = 0;
  384.  
  385. /* Nonzero means print the names of included files rather than
  386.    the preprocessed output.  1 means just the #include "...",
  387.    2 means #include <...> as well.  */
  388.  
  389. static int print_deps = 0;
  390.  
  391. /* Nonzero means print names of header files (-H).  */
  392.  
  393. static int print_include_names = 0;
  394.  
  395. /* Nonzero means don't output line number information.  */
  396.  
  397. static int no_line_commands;
  398.  
  399. /* dump_only means inhibit output of the preprocessed text
  400.              and instead output the definitions of all user-defined
  401.              macros in a form suitable for use as input to cccp.
  402.    dump_names means pass #define and the macro name through to output.
  403.    dump_definitions means pass the whole definition (plus #define) through
  404. */
  405.  
  406. static enum {dump_none, dump_only, dump_names, dump_definitions}
  407.      dump_macros = dump_none;
  408.  
  409. /* Nonzero means pass all #define and #undef directives which we actually
  410.    process through to the output stream.  This feature is used primarily
  411.    to allow cc1 to record the #defines and #undefs for the sake of
  412.    debuggers which understand about preprocessor macros, but it may
  413.    also be useful with -E to figure out how symbols are defined, and
  414.    where they are defined.  */
  415. static int debug_output = 0;
  416.  
  417. /* Nonzero indicates special processing used by the pcp program.  The
  418.    special effects of this mode are: 
  419.      
  420.      Inhibit all macro expansion, except those inside #if directives.
  421.  
  422.      Process #define directives normally, and output their contents 
  423.      to the output file.
  424.  
  425.      Output preconditions to pcp_outfile indicating all the relevant
  426.      preconditions for use of this file in a later cpp run.
  427. */
  428. static FILE *pcp_outfile;
  429.  
  430. /* Nonzero means we are inside an IF during a -pcp run.  In this mode
  431.    macro expansion is done, and preconditions are output for all macro
  432.    uses requiring them. */
  433. static int pcp_inside_if;
  434.  
  435. /* Nonzero means never to include precompiled files.
  436.    This is 1 since there's no way now to make precompiled files,
  437.    so it's not worth testing for them.  */
  438. static int no_precomp = 1;
  439.  
  440. /* Nonzero means give all the error messages the ANSI standard requires.  */
  441.  
  442. int pedantic;
  443.  
  444. /* Nonzero means try to make failure to fit ANSI C an error.  */
  445.  
  446. static int pedantic_errors;
  447.  
  448. /* Nonzero means don't print warning messages.  -w.  */
  449.  
  450. static int inhibit_warnings = 0;
  451.  
  452. /* Nonzero means warn if slash-star appears in a comment.  */
  453.  
  454. static int warn_comments;
  455.  
  456. /* Nonzero means warn if a macro argument is (or would be)
  457.    stringified with -traditional.  */
  458.  
  459. static int warn_stringify;
  460.  
  461. /* Nonzero means warn if there are any trigraphs.  */
  462.  
  463. static int warn_trigraphs;
  464.  
  465. /* Nonzero means warn if #import is used.  */
  466.  
  467. static int warn_import = 1;
  468.  
  469. /* Nonzero means turn warnings into errors.  */
  470.  
  471. static int warnings_are_errors;
  472.  
  473. /* Nonzero means try to imitate old fashioned non-ANSI preprocessor.  */
  474.  
  475. int traditional;
  476.  
  477. /* Nonzero causes output not to be done,
  478.    but directives such as #define that have side effects
  479.    are still obeyed.  */
  480.  
  481. static int no_output;
  482.  
  483. /* Nonzero means that we have finished processing the command line options.
  484.    This flag is used to decide whether or not to issue certain errors
  485.    and/or warnings.  */
  486.  
  487. static int done_initializing = 0;
  488.  
  489. /* Line where a newline was first seen in a string constant.  */
  490.  
  491. static int multiline_string_line = 0;
  492.  
  493. /* I/O buffer structure.
  494.    The `fname' field is nonzero for source files and #include files
  495.    and for the dummy text used for -D and -U.
  496.    It is zero for rescanning results of macro expansion
  497.    and for expanding macro arguments.  */
  498. #define INPUT_STACK_MAX 400
  499. static struct file_buf {
  500.   char *fname;
  501.   /* Filename specified with #line command.  */
  502.   char *nominal_fname;
  503.   /* Record where in the search path this file was found.
  504.      For #include_next.  */
  505.   struct file_name_list *dir;
  506.   int lineno;
  507.   int length;
  508.   U_CHAR *buf;
  509.   U_CHAR *bufp;
  510.   /* Macro that this level is the expansion of.
  511.      Included so that we can reenable the macro
  512.      at the end of this level.  */
  513.   struct hashnode *macro;
  514.   /* Value of if_stack at start of this file.
  515.      Used to prohibit unmatched #endif (etc) in an include file.  */
  516.   struct if_stack *if_stack;
  517.   /* Object to be freed at end of input at this level.  */
  518.   U_CHAR *free_ptr;
  519.   /* True if this is a header file included using <FILENAME>.  */
  520.   char system_header_p;
  521. } instack[INPUT_STACK_MAX];
  522.  
  523. static int last_error_tick;       /* Incremented each time we print it.  */
  524. static int input_file_stack_tick;  /* Incremented when the status changes.  */
  525.  
  526. /* Current nesting level of input sources.
  527.    `instack[indepth]' is the level currently being read.  */
  528. static int indepth = -1;
  529. #define CHECK_DEPTH(code) \
  530.   if (indepth >= (INPUT_STACK_MAX - 1))                    \
  531.     {                                    \
  532.       error_with_line (line_for_error (instack[indepth].lineno),    \
  533.                "macro or `#include' recursion too deep");    \
  534.       code;                                \
  535.     }
  536.  
  537. /* Current depth in #include directives that use <...>.  */
  538. static int system_include_depth = 0;
  539.  
  540. typedef struct file_buf FILE_BUF;
  541.  
  542. /* The output buffer.  Its LENGTH field is the amount of room allocated
  543.    for the buffer, not the number of chars actually present.  To get
  544.    that, subtract outbuf.buf from outbuf.bufp. */
  545.  
  546. #define OUTBUF_SIZE 10    /* initial size of output buffer */
  547. static FILE_BUF outbuf;
  548.  
  549. /* Grow output buffer OBUF points at
  550.    so it can hold at least NEEDED more chars.  */
  551.  
  552. #define check_expand(OBUF, NEEDED)  \
  553.   (((OBUF)->length - ((OBUF)->bufp - (OBUF)->buf) <= (NEEDED))   \
  554.    ? grow_outbuf ((OBUF), (NEEDED)) : 0)
  555.  
  556. struct file_name_list
  557.   {
  558.     struct file_name_list *next;
  559.     char *fname;
  560.     /* If the following is nonzero, it is a macro name.
  561.        Don't include the file again if that macro is defined.  */
  562.     U_CHAR *control_macro;
  563.     /* If the following is nonzero, it is a C-language system include
  564.        directory.  */
  565.     int c_system_include_path;
  566.   };
  567.  
  568. /* #include "file" looks in source file dir, then stack. */
  569. /* #include <file> just looks in the stack. */
  570. /* -I directories are added to the end, then the defaults are added. */
  571. static struct default_include { char *fname; int cplusplus; } include_defaults_array[]
  572. #ifdef INCLUDE_DEFAULTS
  573.   = INCLUDE_DEFAULTS;
  574. #else
  575.   = {
  576.     /* Pick up GNU C++ specific include files.  */
  577.     { GPLUSPLUS_INCLUDE_DIR, 1},
  578. #ifdef CROSS_COMPILE
  579.     /* This is the dir for fixincludes.  Put it just before
  580.        the files that we fix.  */
  581.     { GCC_INCLUDE_DIR, 0},
  582.     /* For cross-compilation, this dir name is generated
  583.        automatically in Makefile.in.  */
  584.     { CROSS_INCLUDE_DIR, 0 },
  585.     /* This is another place that the target system's headers might be.  */
  586.     { TOOL_INCLUDE_DIR, 0},
  587. #else /* not CROSS_COMPILE */
  588.     /* This should be /use/local/include and should come before
  589.        the fixincludes-fixed header files.  */
  590.     { LOCAL_INCLUDE_DIR, 0},
  591.     /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
  592.        Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h.  */
  593.     { TOOL_INCLUDE_DIR, 0},
  594.     /* This is the dir for fixincludes.  Put it just before
  595.        the files that we fix.  */
  596.     { GCC_INCLUDE_DIR, 0},
  597.     /* Some systems have an extra dir of include files.  */
  598. #ifdef SYSTEM_INCLUDE_DIR
  599.     { SYSTEM_INCLUDE_DIR, 0},
  600. #endif
  601.     { STANDARD_INCLUDE_DIR, 0},
  602. #endif /* not CROSS_COMPILE */
  603.     { 0, 0}
  604.     };
  605. #endif /* no INCLUDE_DEFAULTS */
  606.  
  607. /* The code looks at the defaults through this pointer, rather than through
  608.    the constant structure above.  This pointer gets changed if an environment
  609.    variable specifies other defaults.  */
  610. static struct default_include *include_defaults = include_defaults_array;
  611.  
  612. static struct file_name_list *include = 0;    /* First dir to search */
  613.     /* First dir to search for <file> */
  614. /* This is the first element to use for #include <...>.
  615.    If it is 0, use the entire chain for such includes.  */
  616. static struct file_name_list *first_bracket_include = 0;
  617. /* This is the first element in the chain that corresponds to
  618.    a directory of system header files.  */
  619. static struct file_name_list *first_system_include = 0;
  620. static struct file_name_list *last_include = 0;    /* Last in chain */
  621.  
  622. /* Chain of include directories to put at the end of the other chain.  */
  623. static struct file_name_list *after_include = 0;
  624. static struct file_name_list *last_after_include = 0;    /* Last in chain */
  625.  
  626. /* List of included files that contained #pragma once.  */
  627. static struct file_name_list *dont_repeat_files = 0;
  628.  
  629. /* List of other included files.
  630.    If ->control_macro if nonzero, the file had a #ifndef
  631.    around the entire contents, and ->control_macro gives the macro name.  */
  632. static struct file_name_list *all_include_files = 0;
  633.  
  634. /* Directory prefix that should replace `/usr' in the standard
  635.    include file directories.  */
  636. static char *include_prefix;
  637.  
  638. /* Global list of strings read in from precompiled files.  This list
  639.    is kept in the order the strings are read in, with new strings being
  640.    added at the end through stringlist_tailp.  We use this list to output
  641.    the strings at the end of the run. 
  642. */
  643. static STRINGDEF *stringlist;
  644. static STRINGDEF **stringlist_tailp = &stringlist;
  645.  
  646.  
  647. /* Structure returned by create_definition */
  648. typedef struct macrodef MACRODEF;
  649. struct macrodef
  650. {
  651.   struct definition *defn;
  652.   U_CHAR *symnam;
  653.   int symlen;
  654. };
  655.  
  656. static struct macrodef create_definition ();
  657.  
  658.  
  659. /* Structure allocated for every #define.  For a simple replacement
  660.    such as
  661.        #define foo bar ,
  662.    nargs = -1, the `pattern' list is null, and the expansion is just
  663.    the replacement text.  Nargs = 0 means a functionlike macro with no args,
  664.    e.g.,
  665.        #define getchar() getc (stdin) .
  666.    When there are args, the expansion is the replacement text with the
  667.    args squashed out, and the reflist is a list describing how to
  668.    build the output from the input: e.g., "3 chars, then the 1st arg,
  669.    then 9 chars, then the 3rd arg, then 0 chars, then the 2nd arg".
  670.    The chars here come from the expansion.  Whatever is left of the
  671.    expansion after the last arg-occurrence is copied after that arg.
  672.    Note that the reflist can be arbitrarily long---
  673.    its length depends on the number of times the arguments appear in
  674.    the replacement text, not how many args there are.  Example:
  675.    #define f(x) x+x+x+x+x+x+x would have replacement text "++++++" and
  676.    pattern list
  677.      { (0, 1), (1, 1), (1, 1), ..., (1, 1), NULL }
  678.    where (x, y) means (nchars, argno). */
  679.  
  680. typedef struct definition DEFINITION;
  681. struct definition {
  682.   int nargs;
  683.   int length;            /* length of expansion string */
  684.   int predefined;        /* True if the macro was builtin or */
  685.                 /* came from the command line */
  686.   U_CHAR *expansion;
  687.   int line;            /* Line number of definition */
  688.   char *file;            /* File of definition */
  689.   char rest_args;        /* Nonzero if last arg. absorbs the rest */
  690.   struct reflist {
  691.     struct reflist *next;
  692.     char stringify;        /* nonzero if this arg was preceded by a
  693.                    # operator. */
  694.     char raw_before;        /* Nonzero if a ## operator before arg. */
  695.     char raw_after;        /* Nonzero if a ## operator after arg. */
  696.     char rest_args;        /* Nonzero if this arg. absorbs the rest */
  697.     int nchars;            /* Number of literal chars to copy before
  698.                    this arg occurrence.  */
  699.     int argno;            /* Number of arg to substitute (origin-0) */
  700.   } *pattern;
  701.   union {
  702.     /* Names of macro args, concatenated in reverse order
  703.        with comma-space between them.
  704.        The only use of this is that we warn on redefinition
  705.        if this differs between the old and new definitions.  */
  706.     U_CHAR *argnames;
  707.   } args;
  708. };
  709.  
  710. /* different kinds of things that can appear in the value field
  711.    of a hash node.  Actually, this may be useless now. */
  712. union hashval {
  713.   int ival;
  714.   char *cpval;
  715.   DEFINITION *defn;
  716.   KEYDEF *keydef;
  717. };
  718.  
  719. /*
  720.  * special extension string that can be added to the last macro argument to 
  721.  * allow it to absorb the "rest" of the arguments when expanded.  Ex:
  722.  *         #define wow(a, b...)        process (b, a, b)
  723.  *        { wow (1, 2, 3); }    ->    { process (2, 3, 1, 2, 3); }
  724.  *        { wow (one, two); }    ->    { process (two, one, two); }
  725.  * if this "rest_arg" is used with the concat token '##' and if it is not
  726.  * supplied then the token attached to with ## will not be outputted.  Ex:
  727.  *         #define wow (a, b...)        process (b ## , a, ## b)
  728.  *        { wow (1, 2); }        ->    { process (2, 1, 2); }
  729.  *        { wow (one); }        ->    { process (one); {
  730.  */
  731. static char rest_extension[] = "...";
  732. #define REST_EXTENSION_LENGTH    (sizeof (rest_extension) - 1)
  733.  
  734. /* The structure of a node in the hash table.  The hash table
  735.    has entries for all tokens defined by #define commands (type T_MACRO),
  736.    plus some special tokens like __LINE__ (these each have their own
  737.    type, and the appropriate code is run when that type of node is seen.
  738.    It does not contain control words like "#define", which are recognized
  739.    by a separate piece of code. */
  740.  
  741. /* different flavors of hash nodes --- also used in keyword table */
  742. enum node_type {
  743.  T_DEFINE = 1,    /* the `#define' keyword */
  744.  T_INCLUDE,    /* the `#include' keyword */
  745.  T_INCLUDE_NEXT, /* the `#include_next' keyword */
  746.  T_IMPORT,      /* the `#import' keyword */
  747.  T_IFDEF,    /* the `#ifdef' keyword */
  748.  T_IFNDEF,    /* the `#ifndef' keyword */
  749.  T_IF,        /* the `#if' keyword */
  750.  T_ELSE,    /* `#else' */
  751.  T_PRAGMA,    /* `#pragma' */
  752.  T_ELIF,    /* `#elif' */
  753.  T_UNDEF,    /* `#undef' */
  754.  T_LINE,    /* `#line' */
  755.  T_ERROR,    /* `#error' */
  756.  T_WARNING,    /* `#warning' */
  757.  T_ENDIF,    /* `#endif' */
  758.  T_SCCS,    /* `#sccs', used on system V.  */
  759.  T_IDENT,    /* `#ident', used on system V.  */
  760.  T_ASSERT,    /* `#assert', taken from system V.  */
  761.  T_UNASSERT,    /* `#unassert', taken from system V.  */
  762.  T_SPECLINE,    /* special symbol `__LINE__' */
  763.  T_DATE,    /* `__DATE__' */
  764.  T_FILE,    /* `__FILE__' */
  765.  T_BASE_FILE,    /* `__BASE_FILE__' */
  766.  T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
  767.  T_VERSION,    /* `__VERSION__' */
  768.  T_SIZE_TYPE,   /* `__SIZE_TYPE__' */
  769.  T_PTRDIFF_TYPE,   /* `__PTRDIFF_TYPE__' */
  770.  T_WCHAR_TYPE,   /* `__WCHAR_TYPE__' */
  771.  T_USER_LABEL_PREFIX_TYPE, /* `__USER_LABEL_PREFIX__' */
  772.  T_REGISTER_PREFIX_TYPE,   /* `__REGISTER_PREFIX__' */
  773.  T_TIME,    /* `__TIME__' */
  774.  T_CONST,    /* Constant value, used by `__STDC__' */
  775.  T_MACRO,    /* macro defined by `#define' */
  776.  T_DISABLED,    /* macro temporarily turned off for rescan */
  777.  T_SPEC_DEFINED, /* special `defined' macro for use in #if statements */
  778.  T_PCSTRING,    /* precompiled string (hashval is KEYDEF *) */
  779.  T_UNUSED    /* Used for something not defined.  */
  780.  };
  781.  
  782. struct hashnode {
  783.   struct hashnode *next;    /* double links for easy deletion */
  784.   struct hashnode *prev;
  785.   struct hashnode **bucket_hdr;    /* also, a back pointer to this node's hash
  786.                    chain is kept, in case the node is the head
  787.                    of the chain and gets deleted. */
  788.   enum node_type type;        /* type of special token */
  789.   int length;            /* length of token, for quick comparison */
  790.   U_CHAR *name;            /* the actual name */
  791.   union hashval value;        /* pointer to expansion, or whatever */
  792. };
  793.  
  794. typedef struct hashnode HASHNODE;
  795.  
  796. /* Some definitions for the hash table.  The hash function MUST be
  797.    computed as shown in hashf () below.  That is because the rescan
  798.    loop computes the hash value `on the fly' for most tokens,
  799.    in order to avoid the overhead of a lot of procedure calls to
  800.    the hashf () function.  Hashf () only exists for the sake of
  801.    politeness, for use when speed isn't so important. */
  802.  
  803. #define HASHSIZE 1403
  804. static HASHNODE *hashtab[HASHSIZE];
  805. #define HASHSTEP(old, c) ((old << 2) + c)
  806. #define MAKE_POS(v) (v & 0x7fffffff) /* make number positive */
  807.  
  808. /* Symbols to predefine.  */
  809.  
  810. #ifdef CPP_PREDEFINES
  811. static char *predefs = CPP_PREDEFINES;
  812. #else
  813. static char *predefs = "";
  814. #endif
  815.  
  816. /* We let tm.h override the types used here, to handle trivial differences
  817.    such as the choice of unsigned int or long unsigned int for size_t.
  818.    When machines start needing nontrivial differences in the size type,
  819.    it would be best to do something here to figure out automatically
  820.    from other information what type to use.  */
  821.  
  822. /* The string value for __size_type__.  */
  823.  
  824. #ifndef SIZE_TYPE
  825. #define SIZE_TYPE "long unsigned int"
  826. #endif
  827.  
  828. /* The string value for __ptrdiff_type__.  */
  829.  
  830. #ifndef PTRDIFF_TYPE
  831. #define PTRDIFF_TYPE "long int"
  832. #endif
  833.  
  834. /* The string value for __wchar_type__.  */
  835.  
  836. #ifndef WCHAR_TYPE
  837. #define WCHAR_TYPE "int"
  838. #endif
  839.  
  840. /* The string value for __USER_LABEL_PREFIX__ */
  841.  
  842. #ifndef USER_LABEL_PREFIX
  843. #define USER_LABEL_PREFIX ""
  844. #endif
  845.  
  846. /* The string value for __REGISTER_PREFIX__ */
  847.  
  848. #ifndef REGISTER_PREFIX
  849. #define REGISTER_PREFIX ""
  850. #endif
  851.  
  852. /* In the definition of a #assert name, this structure forms
  853.    a list of the individual values asserted.
  854.    Each value is itself a list of "tokens".
  855.    These are strings that are compared by name.  */
  856.  
  857. struct tokenlist_list {
  858.   struct tokenlist_list *next;
  859.   struct arglist *tokens;
  860. };
  861.  
  862. struct assertion_hashnode {
  863.   struct assertion_hashnode *next;    /* double links for easy deletion */
  864.   struct assertion_hashnode *prev;
  865.   /* also, a back pointer to this node's hash
  866.      chain is kept, in case the node is the head
  867.      of the chain and gets deleted. */
  868.   struct assertion_hashnode **bucket_hdr;
  869.   int length;            /* length of token, for quick comparison */
  870.   U_CHAR *name;            /* the actual name */
  871.   /* List of token-sequences.  */
  872.   struct tokenlist_list *value;
  873. };
  874.  
  875. typedef struct assertion_hashnode ASSERTION_HASHNODE;
  876.  
  877. /* Some definitions for the hash table.  The hash function MUST be
  878.    computed as shown in hashf below.  That is because the rescan
  879.    loop computes the hash value `on the fly' for most tokens,
  880.    in order to avoid the overhead of a lot of procedure calls to
  881.    the hashf function.  hashf only exists for the sake of
  882.    politeness, for use when speed isn't so important. */
  883.  
  884. #define ASSERTION_HASHSIZE 37
  885. static ASSERTION_HASHNODE *assertion_hashtab[ASSERTION_HASHSIZE];
  886.  
  887. /* Nonzero means inhibit macroexpansion of what seem to be
  888.    assertion tests, in rescan.  For #if.  */
  889. static int assertions_flag;
  890.  
  891. /* `struct directive' defines one #-directive, including how to handle it.  */
  892.  
  893. struct directive {
  894.   int length;            /* Length of name */
  895.   int (*func)();        /* Function to handle directive */
  896.   char *name;            /* Name of directive */
  897.   enum node_type type;        /* Code which describes which directive. */
  898.   char angle_brackets;        /* Nonzero => <...> is special.  */
  899.   char traditional_comments;    /* Nonzero: keep comments if -traditional.  */
  900.   char pass_thru;        /* Copy preprocessed directive to output file.  */
  901. };
  902.  
  903. /* Here is the actual list of #-directives, most-often-used first.  */
  904.  
  905. static struct directive directive_table[] = {
  906.   {  6, do_define, "define", T_DEFINE, 0, 1},
  907.   {  2, do_if, "if", T_IF},
  908.   {  5, do_xifdef, "ifdef", T_IFDEF},
  909.   {  6, do_xifdef, "ifndef", T_IFNDEF},
  910.   {  5, do_endif, "endif", T_ENDIF},
  911.   {  4, do_else, "else", T_ELSE},
  912.   {  4, do_elif, "elif", T_ELIF},
  913.   {  4, do_line, "line", T_LINE},
  914.   {  7, do_include, "include", T_INCLUDE, 1},
  915.   { 12, do_include, "include_next", T_INCLUDE_NEXT, 1},
  916.   {  6, do_include, "import", T_IMPORT, 1},
  917.   {  5, do_undef, "undef", T_UNDEF},
  918.   {  5, do_error, "error", T_ERROR},
  919.   {  7, do_warning, "warning", T_WARNING},
  920. #ifdef SCCS_DIRECTIVE
  921.   {  4, do_sccs, "sccs", T_SCCS},
  922. #endif
  923.   {  6, do_pragma, "pragma", T_PRAGMA, 0, 0, 1},
  924.   {  5, do_ident, "ident", T_IDENT},
  925.   {  6, do_assert, "assert", T_ASSERT},
  926.   {  8, do_unassert, "unassert", T_UNASSERT},
  927.   {  -1, 0, "", T_UNUSED},
  928. };
  929.  
  930. /* When a directive handler is called,
  931.    this points to the # that started the directive.  */
  932. U_CHAR *directive_start;
  933.  
  934. /* table to tell if char can be part of a C identifier. */
  935. U_CHAR is_idchar[256];
  936. /* table to tell if char can be first char of a c identifier. */
  937. U_CHAR is_idstart[256];
  938. /* table to tell if c is horizontal space.  */
  939. U_CHAR is_hor_space[256];
  940. /* table to tell if c is horizontal or vertical space.  */
  941. static U_CHAR is_space[256];
  942.  
  943. #define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
  944. #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
  945.   
  946. static int errors = 0;            /* Error counter for exit code */
  947.  
  948. /* Name of output file, for error messages.  */
  949. static char *out_fname;
  950.  
  951. /* Zero means dollar signs are punctuation.
  952.    -$ stores 0; -traditional may store 1.  Default is 1 for VMS, 0 otherwise.
  953.    This must be 0 for correct processing of this ANSI C program:
  954.     #define foo(a) #a
  955.     #define lose(b) foo (b)
  956.     #define test$
  957.     lose (test)    */
  958. static int dollars_in_ident;
  959. #ifndef DOLLARS_IN_IDENTIFIERS
  960. #define DOLLARS_IN_IDENTIFIERS 1
  961. #endif
  962.  
  963. static FILE_BUF expand_to_temp_buffer ();
  964.  
  965. static DEFINITION *collect_expansion ();
  966.  
  967. /* Stack of conditionals currently in progress
  968.    (including both successful and failing conditionals).  */
  969.  
  970. struct if_stack {
  971.   struct if_stack *next;    /* for chaining to the next stack frame */
  972.   char *fname;        /* copied from input when frame is made */
  973.   int lineno;            /* similarly */
  974.   int if_succeeded;        /* true if a leg of this if-group
  975.                     has been passed through rescan */
  976.   U_CHAR *control_macro;    /* For #ifndef at start of file,
  977.                    this is the macro name tested.  */
  978.   enum node_type type;        /* type of last directive seen in this group */
  979. };
  980. typedef struct if_stack IF_STACK_FRAME;
  981. static IF_STACK_FRAME *if_stack = NULL;
  982.  
  983. /* Buffer of -M output.  */
  984. static char *deps_buffer;
  985.  
  986. /* Number of bytes allocated in above.  */
  987. static int deps_allocated_size;
  988.  
  989. /* Number of bytes used.  */
  990. static int deps_size;
  991.  
  992. /* Number of bytes since the last newline.  */
  993. static int deps_column;
  994.  
  995. /* Nonzero means -I- has been seen,
  996.    so don't look for #include "foo" the source-file directory.  */
  997. static int ignore_srcdir;
  998.  
  999. /* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
  1000.    retrying if necessary.  Return the actual number of bytes read.  */
  1001.  
  1002. static int
  1003. safe_read (desc, ptr, len)
  1004.      int desc;
  1005.      char *ptr;
  1006.      int len;
  1007. {
  1008.   int left = len;
  1009.   while (left > 0) {
  1010.     int nchars = read (desc, ptr, left);
  1011.     if (nchars < 0)
  1012.       {
  1013. #ifdef EINTR
  1014.     if (errno == EINTR)
  1015.       continue;
  1016. #endif
  1017.     return nchars;
  1018.       }
  1019.     if (nchars == 0)
  1020.       break;
  1021.     ptr += nchars;
  1022.     left -= nchars;
  1023.   }
  1024.   return len - left;
  1025. }
  1026.  
  1027. /* Write LEN bytes at PTR to descriptor DESC,
  1028.    retrying if necessary, and treating any real error as fatal.  */
  1029.  
  1030. static void
  1031. safe_write (desc, ptr, len)
  1032.      int desc;
  1033.      char *ptr;
  1034.      int len;
  1035. {
  1036.   while (len > 0) {
  1037.     int written = write (desc, ptr, len);
  1038.     if (written < 0)
  1039.       {
  1040. #ifdef EINTR
  1041.     if (errno == EINTR)
  1042.       continue;
  1043. #endif
  1044.     pfatal_with_name (out_fname);
  1045.       }
  1046.     ptr += written;
  1047.     len -= written;
  1048.   }
  1049. }
  1050.  
  1051. int
  1052. main (argc, argv)
  1053.      int argc;
  1054.      char **argv;
  1055. {
  1056.   int st_mode;
  1057.   long st_size;
  1058.   char *in_fname;
  1059.   char *p;
  1060.   int f, i;
  1061.   FILE_BUF *fp;
  1062.   char **pend_files = (char **) xmalloc (argc * sizeof (char *));
  1063.   char **pend_defs = (char **) xmalloc (argc * sizeof (char *));
  1064.   char **pend_undefs = (char **) xmalloc (argc * sizeof (char *));
  1065.   char **pend_assertions = (char **) xmalloc (argc * sizeof (char *));
  1066.   char **pend_includes = (char **) xmalloc (argc * sizeof (char *));
  1067.  
  1068.   /* Record the option used with each element of pend_assertions.
  1069.      This is preparation for supporting more than one option for making
  1070.      an assertion.  */
  1071.   char **pend_assertion_options = (char **) xmalloc (argc * sizeof (char *));
  1072.   int inhibit_predefs = 0;
  1073.   int no_standard_includes = 0;
  1074.   int no_standard_cplusplus_includes = 0;
  1075.   int missing_newline = 0;
  1076.  
  1077.   /* Non-0 means don't output the preprocessed program.  */
  1078.   int inhibit_output = 0;
  1079.   /* Non-0 means -v, so print the full set of include dirs.  */
  1080.   int verbose = 0;
  1081.  
  1082.   /* File name which deps are being written to.
  1083.      This is 0 if deps are being written to stdout.  */
  1084.   char *deps_file = 0;
  1085.   /* Fopen file mode to open deps_file with.  */
  1086.   char *deps_mode = "a";
  1087.   /* Stream on which to print the dependency information.  */
  1088.   FILE *deps_stream = 0;
  1089.   /* Target-name to write with the dependency information.  */
  1090.   char *deps_target = 0;
  1091.  
  1092. #ifdef RLIMIT_STACK
  1093.   /* Get rid of any avoidable limit on stack size.  */
  1094.   {
  1095.     struct rlimit rlim;
  1096.  
  1097.     /* Set the stack limit huge so that alloca (particularly stringtab
  1098.      * in dbxread.c) does not fail. */
  1099.     getrlimit (RLIMIT_STACK, &rlim);
  1100.     rlim.rlim_cur = rlim.rlim_max;
  1101.     setrlimit (RLIMIT_STACK, &rlim);
  1102.   }
  1103. #endif /* RLIMIT_STACK defined */
  1104.  
  1105. #ifdef SIGPIPE
  1106.   signal (SIGPIPE, pipe_closed);
  1107. #endif
  1108.  
  1109.   p = argv[0] + strlen (argv[0]);
  1110.   while (p != argv[0] && p[-1] != '/') --p;
  1111.   progname = p;
  1112.  
  1113. #ifdef VMS
  1114.   {
  1115.     /* Remove directories from PROGNAME.  */
  1116.     char *s;
  1117.  
  1118.     progname = savestring (argv[0]);
  1119.  
  1120.     if (!(s = rindex (progname, ']')))
  1121.       s = rindex (progname, ':');
  1122.     if (s)
  1123.       strcpy (progname, s+1);
  1124.     if (s = rindex (progname, '.'))
  1125.       *s = '\0';
  1126.   }
  1127. #endif
  1128.  
  1129.   in_fname = NULL;
  1130.   out_fname = NULL;
  1131.  
  1132.   /* Initialize is_idchar to allow $.  */
  1133.   dollars_in_ident = 1;
  1134.   initialize_char_syntax ();
  1135.   dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 0;
  1136.  
  1137.   no_line_commands = 0;
  1138.   no_trigraphs = 1;
  1139.   dump_macros = dump_none;
  1140.   no_output = 0;
  1141.   cplusplus = 0;
  1142.   cplusplus_comments = 0;
  1143.  
  1144.   bzero (pend_files, argc * sizeof (char *));
  1145.   bzero (pend_defs, argc * sizeof (char *));
  1146.   bzero (pend_undefs, argc * sizeof (char *));
  1147.   bzero (pend_assertions, argc * sizeof (char *));
  1148.   bzero (pend_includes, argc * sizeof (char *));
  1149.  
  1150.   /* Process switches and find input file name.  */
  1151.  
  1152.   for (i = 1; i < argc; i++) {
  1153.     if (argv[i][0] != '-') {
  1154.       if (out_fname != NULL)
  1155.     fatal ("Usage: %s [switches] input output", argv[0]);
  1156.       else if (in_fname != NULL)
  1157.     out_fname = argv[i];
  1158.       else
  1159.     in_fname = argv[i];
  1160.     } else {
  1161.       switch (argv[i][1]) {
  1162.  
  1163.       case 'i':
  1164.     if (!strcmp (argv[i], "-include")) {
  1165.       if (i + 1 == argc)
  1166.         fatal ("Filename missing after `-include' option");
  1167.       else
  1168.         pend_includes[i] = argv[i+1], i++;
  1169.     }
  1170.     if (!strcmp (argv[i], "-imacros")) {
  1171.       if (i + 1 == argc)
  1172.         fatal ("Filename missing after `-imacros' option");
  1173.       else
  1174.         pend_files[i] = argv[i+1], i++;
  1175.     }
  1176.     if (!strcmp (argv[i], "-iprefix")) {
  1177.       if (i + 1 == argc)
  1178.         fatal ("Filename missing after `-iprefix' option");
  1179.       else
  1180.         include_prefix = argv[++i];
  1181.     }
  1182.     /* Add directory to end of path for includes,
  1183.        with the default prefix at the front of its name.  */
  1184.     if (!strcmp (argv[i], "-iwithprefix")) {
  1185.       struct file_name_list *dirtmp;
  1186.       char *prefix;
  1187.  
  1188.       if (include_prefix != 0)
  1189.         prefix = include_prefix;
  1190.       else {
  1191.         prefix = savestring (GCC_INCLUDE_DIR);
  1192.         /* Remove the `include' from /usr/local/lib/gcc.../include.  */
  1193.         if (!strcmp (prefix + strlen (prefix) - 8, "/include"))
  1194.           prefix[strlen (prefix) - 7] = 0;
  1195.       }
  1196.  
  1197.       dirtmp = (struct file_name_list *)
  1198.         xmalloc (sizeof (struct file_name_list));
  1199.       dirtmp->next = 0;    /* New one goes on the end */
  1200.       dirtmp->control_macro = 0;
  1201.       dirtmp->c_system_include_path = 0;
  1202.       if (i + 1 == argc)
  1203.         fatal ("Directory name missing after `-iwithprefix' option");
  1204.  
  1205.       dirtmp->fname = (char *) xmalloc (strlen (argv[i+1])
  1206.                         + strlen (prefix) + 1);
  1207.       strcpy (dirtmp->fname, prefix);
  1208.       strcat (dirtmp->fname, argv[++i]);
  1209.  
  1210.       if (after_include == 0)
  1211.         after_include = dirtmp;
  1212.       else
  1213.         last_after_include->next = dirtmp;
  1214.       last_after_include = dirtmp; /* Tail follows the last one */
  1215.     }
  1216.     /* Add directory to main path for includes,
  1217.        with the default prefix at the front of its name.  */
  1218.     if (!strcmp (argv[i], "-iwithprefixbefore")) {
  1219.       struct file_name_list *dirtmp;
  1220.       char *prefix;
  1221.  
  1222.       if (include_prefix != 0)
  1223.         prefix = include_prefix;
  1224.       else {
  1225.         prefix = savestring (GCC_INCLUDE_DIR);
  1226.         /* Remove the `include' from /usr/local/lib/gcc.../include.  */
  1227.         if (!strcmp (prefix + strlen (prefix) - 8, "/include"))
  1228.           prefix[strlen (prefix) - 7] = 0;
  1229.       }
  1230.  
  1231.       dirtmp = (struct file_name_list *)
  1232.         xmalloc (sizeof (struct file_name_list));
  1233.       dirtmp->next = 0;    /* New one goes on the end */
  1234.       dirtmp->control_macro = 0;
  1235.       dirtmp->c_system_include_path = 0;
  1236.       if (i + 1 == argc)
  1237.         fatal ("Directory name missing after `-iwithprefixbefore' option");
  1238.  
  1239.       dirtmp->fname = (char *) xmalloc (strlen (argv[i+1])
  1240.                         + strlen (prefix) + 1);
  1241.       strcpy (dirtmp->fname, prefix);
  1242.       strcat (dirtmp->fname, argv[++i]);
  1243.  
  1244.       append_include_chain (dirtmp, dirtmp);
  1245.     }
  1246.     /* Add directory to end of path for includes.  */
  1247.     if (!strcmp (argv[i], "-idirafter")) {
  1248.       struct file_name_list *dirtmp;
  1249.  
  1250.       dirtmp = (struct file_name_list *)
  1251.         xmalloc (sizeof (struct file_name_list));
  1252.       dirtmp->next = 0;    /* New one goes on the end */
  1253.       dirtmp->control_macro = 0;
  1254.       dirtmp->c_system_include_path = 0;
  1255.       if (i + 1 == argc)
  1256.         fatal ("Directory name missing after `-idirafter' option");
  1257.       else
  1258.         dirtmp->fname = argv[++i];
  1259.  
  1260.       if (after_include == 0)
  1261.         after_include = dirtmp;
  1262.       else
  1263.         last_after_include->next = dirtmp;
  1264.       last_after_include = dirtmp; /* Tail follows the last one */
  1265.     }
  1266.     break;
  1267.  
  1268.       case 'o':
  1269.     if (out_fname != NULL)
  1270.       fatal ("Output filename specified twice");
  1271.     if (i + 1 == argc)
  1272.       fatal ("Filename missing after -o option");
  1273.     out_fname = argv[++i];
  1274.     if (!strcmp (out_fname, "-"))
  1275.       out_fname = "";
  1276.     break;
  1277.  
  1278.       case 'p':
  1279.     if (!strcmp (argv[i], "-pedantic"))
  1280.       pedantic = 1;
  1281.     else if (!strcmp (argv[i], "-pedantic-errors")) {
  1282.       pedantic = 1;
  1283.       pedantic_errors = 1;
  1284.     } else if (!strcmp (argv[i], "-pcp")) {
  1285.       char *pcp_fname = argv[++i];
  1286.       pcp_outfile = 
  1287.         ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
  1288.          ? fopen (pcp_fname, "w")
  1289.          : fdopen (dup (fileno (stdout)), "w"));
  1290.       if (pcp_outfile == 0)
  1291.         pfatal_with_name (pcp_fname);
  1292.       no_precomp = 1;
  1293.     }
  1294.     break;
  1295.  
  1296.       case 't':
  1297.     if (!strcmp (argv[i], "-traditional")) {
  1298.       traditional = 1;
  1299.       if (dollars_in_ident > 0)
  1300.         dollars_in_ident = 1;
  1301.     } else if (!strcmp (argv[i], "-trigraphs")) {
  1302.       no_trigraphs = 0;
  1303.     }
  1304.     break;
  1305.  
  1306.       case 'l':
  1307.     if (! strcmp (argv[i], "-lang-c"))
  1308.       cplusplus = 0, cplusplus_comments = 0, objc = 0;
  1309.     if (! strcmp (argv[i], "-lang-c++"))
  1310.       cplusplus = 1, cplusplus_comments = 1, objc = 0;
  1311.     if (! strcmp (argv[i], "-lang-c-c++-comments"))
  1312.       cplusplus = 0, cplusplus_comments = 1, objc = 0;
  1313.     if (! strcmp (argv[i], "-lang-objc"))
  1314.       objc = 1, cplusplus = 0, cplusplus_comments = 1;
  1315.     if (! strcmp (argv[i], "-lang-objc++"))
  1316.       objc = 1, cplusplus = 1, cplusplus_comments = 1;
  1317.      if (! strcmp (argv[i], "-lang-asm"))
  1318.        lang_asm = 1;
  1319.      if (! strcmp (argv[i], "-lint"))
  1320.        lint = 1;
  1321.     break;
  1322.  
  1323.       case '+':
  1324.     cplusplus = 1, cplusplus_comments = 1;
  1325.     break;
  1326.  
  1327.       case 'w':
  1328.     inhibit_warnings = 1;
  1329.     break;
  1330.  
  1331.       case 'W':
  1332.     if (!strcmp (argv[i], "-Wtrigraphs"))
  1333.       warn_trigraphs = 1;
  1334.     else if (!strcmp (argv[i], "-Wno-trigraphs"))
  1335.       warn_trigraphs = 0;
  1336.     else if (!strcmp (argv[i], "-Wcomment"))
  1337.       warn_comments = 1;
  1338.     else if (!strcmp (argv[i], "-Wno-comment"))
  1339.       warn_comments = 0;
  1340.     else if (!strcmp (argv[i], "-Wcomments"))
  1341.       warn_comments = 1;
  1342.     else if (!strcmp (argv[i], "-Wno-comments"))
  1343.       warn_comments = 0;
  1344.     else if (!strcmp (argv[i], "-Wtraditional"))
  1345.       warn_stringify = 1;
  1346.     else if (!strcmp (argv[i], "-Wno-traditional"))
  1347.       warn_stringify = 0;
  1348.     else if (!strcmp (argv[i], "-Wimport"))
  1349.       warn_import = 1;
  1350.     else if (!strcmp (argv[i], "-Wno-import"))
  1351.       warn_import = 0;
  1352.     else if (!strcmp (argv[i], "-Werror"))
  1353.       warnings_are_errors = 1;
  1354.     else if (!strcmp (argv[i], "-Wno-error"))
  1355.       warnings_are_errors = 0;
  1356.     else if (!strcmp (argv[i], "-Wall"))
  1357.       {
  1358.         warn_trigraphs = 1;
  1359.         warn_comments = 1;
  1360.       }
  1361.     break;
  1362.  
  1363.       case 'M':
  1364.     if (!strcmp (argv[i], "-M"))
  1365.       print_deps = 2;
  1366.     else if (!strcmp (argv[i], "-MM"))
  1367.       print_deps = 1;
  1368.     else if (!strcmp (argv[i], "-MD"))
  1369.       print_deps = 2;
  1370.     else if (!strcmp (argv[i], "-MMD"))
  1371.       print_deps = 1;
  1372.     /* For -MD and -MMD options, write deps on file named by next arg.  */
  1373.     if (!strcmp (argv[i], "-MD")
  1374.         || !strcmp (argv[i], "-MMD")) {
  1375.       i++;
  1376.       deps_file = argv[i];
  1377.       deps_mode = "w";
  1378.     } else {
  1379.       /* For -M and -MM, write deps on standard output
  1380.          and suppress the usual output.  */
  1381.       deps_stream = stdout;
  1382.       inhibit_output = 1;
  1383.     }      
  1384.     break;
  1385.  
  1386.       case 'd':
  1387.     {
  1388.       char *p = argv[i] + 2;
  1389.       char c;
  1390.       while (c = *p++) {
  1391.         /* Arg to -d specifies what parts of macros to dump */
  1392.         switch (c) {
  1393.         case 'M':
  1394.           dump_macros = dump_only;
  1395.           no_output = 1;
  1396.           break;
  1397.         case 'N':
  1398.           dump_macros = dump_names;
  1399.           break;
  1400.         case 'D':
  1401.           dump_macros = dump_definitions;
  1402.           break;
  1403.         }
  1404.       }
  1405.     }
  1406.     break;
  1407.  
  1408.       case 'g':
  1409.     if (argv[i][2] == '3')
  1410.       debug_output = 1;
  1411.     break;
  1412.  
  1413.       case 'v':
  1414.     fprintf (stderr, "GNU CPP version %s", version_string);
  1415. #ifdef TARGET_VERSION
  1416.     TARGET_VERSION;
  1417. #endif
  1418.     fprintf (stderr, "\n");
  1419.     verbose = 1;
  1420.     break;
  1421.  
  1422.       case 'H':
  1423.     print_include_names = 1;
  1424.     break;
  1425.  
  1426.       case 'D':
  1427.     {
  1428.       char *p, *p1;
  1429.  
  1430.       if (argv[i][2] != 0)
  1431.         p = argv[i] + 2;
  1432.       else if (i + 1 == argc)
  1433.         fatal ("Macro name missing after -D option");
  1434.       else
  1435.         p = argv[++i];
  1436.  
  1437.       pend_defs[i] = p;
  1438.     }
  1439.     break;
  1440.  
  1441.       case 'A':
  1442.     {
  1443.       char *p, *p1;
  1444.  
  1445.       if (argv[i][2] != 0)
  1446.         p = argv[i] + 2;
  1447.       else if (i + 1 == argc)
  1448.         fatal ("Assertion missing after -A option");
  1449.       else
  1450.         p = argv[++i];
  1451.  
  1452.       if (!strcmp (p, "-")) {
  1453.         /* -A- eliminates all predefined macros and assertions.
  1454.            Let's include also any that were specified earlier
  1455.            on the command line.  That way we can get rid of any
  1456.            that were passed automatically in from GCC.  */
  1457.         int j;
  1458.         inhibit_predefs = 1;
  1459.         for (j = 0; j < i; j++)
  1460.           pend_defs[j] = pend_assertions[j] = 0;
  1461.       } else {
  1462.         pend_assertions[i] = p;
  1463.         pend_assertion_options[i] = "-A";
  1464.       }
  1465.     }
  1466.     break;
  1467.  
  1468.       case 'U':        /* JF #undef something */
  1469.     if (argv[i][2] != 0)
  1470.       pend_undefs[i] = argv[i] + 2;
  1471.     else if (i + 1 == argc)
  1472.       fatal ("Macro name missing after -U option");
  1473.     else
  1474.       pend_undefs[i] = argv[i+1], i++;
  1475.     break;
  1476.  
  1477.       case 'C':
  1478.     put_out_comments = 1;
  1479.     break;
  1480.  
  1481.       case 'E':            /* -E comes from cc -E; ignore it.  */
  1482.     break;
  1483.  
  1484.       case 'P':
  1485.     no_line_commands = 1;
  1486.     break;
  1487.  
  1488.       case '$':            /* Don't include $ in identifiers.  */
  1489.     dollars_in_ident = 0;
  1490.     break;
  1491.  
  1492.       case 'I':            /* Add directory to path for includes.  */
  1493.     {
  1494.       struct file_name_list *dirtmp;
  1495.  
  1496.       if (! ignore_srcdir && !strcmp (argv[i] + 2, "-")) {
  1497.         ignore_srcdir = 1;
  1498.         /* Don't use any preceding -I directories for #include <...>.  */
  1499.         first_bracket_include = 0;
  1500.       }
  1501.       else {
  1502.         dirtmp = (struct file_name_list *)
  1503.           xmalloc (sizeof (struct file_name_list));
  1504.         dirtmp->next = 0;        /* New one goes on the end */
  1505.         dirtmp->control_macro = 0;
  1506.         dirtmp->c_system_include_path = 0;
  1507.         if (argv[i][2] != 0)
  1508.           dirtmp->fname = argv[i] + 2;
  1509.         else if (i + 1 == argc)
  1510.           fatal ("Directory name missing after -I option");
  1511.         else
  1512.           dirtmp->fname = argv[++i];
  1513.         append_include_chain (dirtmp, dirtmp);
  1514.       }
  1515.     }
  1516.     break;
  1517.  
  1518.       case 'n':
  1519.     if (!strcmp (argv[i], "-nostdinc"))
  1520.       /* -nostdinc causes no default include directories.
  1521.          You must specify all include-file directories with -I.  */
  1522.       no_standard_includes = 1;
  1523.     else if (!strcmp (argv[i], "-nostdinc++"))
  1524.       /* -nostdinc++ causes no default C++-specific include directories. */
  1525.       no_standard_cplusplus_includes = 1;
  1526.     else if (!strcmp (argv[i], "-noprecomp"))
  1527.       no_precomp = 1;
  1528.     break;
  1529.  
  1530.       case 'u':
  1531.     /* Sun compiler passes undocumented switch "-undef".
  1532.        Let's assume it means to inhibit the predefined symbols.  */
  1533.     inhibit_predefs = 1;
  1534.     break;
  1535.  
  1536.       case '\0': /* JF handle '-' as file name meaning stdin or stdout */
  1537.     if (in_fname == NULL) {
  1538.       in_fname = "";
  1539.       break;
  1540.     } else if (out_fname == NULL) {
  1541.       out_fname = "";
  1542.       break;
  1543.     }    /* else fall through into error */
  1544.  
  1545.       default:
  1546.     fatal ("Invalid option `%s'", argv[i]);
  1547.       }
  1548.     }
  1549.   }
  1550.  
  1551.   /* Add dirs from CPATH after dirs from -I.  */
  1552.   /* There seems to be confusion about what CPATH should do,
  1553.      so for the moment it is not documented.  */
  1554.   /* Some people say that CPATH should replace the standard include dirs,
  1555.      but that seems pointless: it comes before them, so it overrides them
  1556.      anyway.  */
  1557.   p = (char *) getenv ("CPATH");
  1558.   if (p != 0 && ! no_standard_includes)
  1559.     path_include (p);
  1560.  
  1561.   /* Now that dollars_in_ident is known, initialize is_idchar.  */
  1562.   initialize_char_syntax ();
  1563.  
  1564.   /* Initialize output buffer */
  1565.  
  1566.   outbuf.buf = (U_CHAR *) xmalloc (OUTBUF_SIZE);
  1567.   outbuf.bufp = outbuf.buf;
  1568.   outbuf.length = OUTBUF_SIZE;
  1569.  
  1570.   /* Do partial setup of input buffer for the sake of generating
  1571.      early #line directives (when -g is in effect).  */
  1572.  
  1573.   fp = &instack[++indepth];
  1574.   if (in_fname == NULL)
  1575.     in_fname = "";
  1576.   fp->nominal_fname = fp->fname = in_fname;
  1577.   fp->lineno = 0;
  1578.  
  1579.   /* Install __LINE__, etc.  Must follow initialize_char_syntax
  1580.      and option processing.  */
  1581.   initialize_builtins (fp, &outbuf);
  1582.  
  1583.   /* Do standard #defines and assertions
  1584.      that identify system and machine type.  */
  1585.  
  1586.   if (!inhibit_predefs) {
  1587.     char *p = (char *) alloca (strlen (predefs) + 1);
  1588.     strcpy (p, predefs);
  1589.     while (*p) {
  1590.       char *q;
  1591.       while (*p == ' ' || *p == '\t')
  1592.     p++;
  1593.       /* Handle -D options.  */ 
  1594.       if (p[0] == '-' && p[1] == 'D') {
  1595.     q = &p[2];
  1596.     while (*p && *p != ' ' && *p != '\t')
  1597.       p++;
  1598.     if (*p != 0)
  1599.       *p++= 0;
  1600.     if (debug_output)
  1601.       output_line_command (fp, &outbuf, 0, same_file);
  1602.     make_definition (q, &outbuf);
  1603.     while (*p == ' ' || *p == '\t')
  1604.       p++;
  1605.       } else if (p[0] == '-' && p[1] == 'A') {
  1606.     /* Handle -A options (assertions).  */ 
  1607.     char *assertion;
  1608.     char *past_name;
  1609.     char *value;
  1610.     char *past_value;
  1611.     char *termination;
  1612.     int save_char;
  1613.  
  1614.     assertion = &p[2];
  1615.     past_name = assertion;
  1616.     /* Locate end of name.  */
  1617.     while (*past_name && *past_name != ' '
  1618.            && *past_name != '\t' && *past_name != '(')
  1619.       past_name++;
  1620.     /* Locate `(' at start of value.  */
  1621.     value = past_name;
  1622.     while (*value && (*value == ' ' || *value == '\t'))
  1623.       value++;
  1624.     if (*value++ != '(')
  1625.       abort ();
  1626.     while (*value && (*value == ' ' || *value == '\t'))
  1627.       value++;
  1628.     past_value = value;
  1629.     /* Locate end of value.  */
  1630.     while (*past_value && *past_value != ' '
  1631.            && *past_value != '\t' && *past_value != ')')
  1632.       past_value++;
  1633.     termination = past_value;
  1634.     while (*termination && (*termination == ' ' || *termination == '\t'))
  1635.       termination++;
  1636.     if (*termination++ != ')')
  1637.       abort ();
  1638.     if (*termination && *termination != ' ' && *termination != '\t')
  1639.       abort ();
  1640.     /* Temporarily null-terminate the value.  */
  1641.     save_char = *termination;
  1642.     *termination = '\0';
  1643.     /* Install the assertion.  */
  1644.     make_assertion ("-A", assertion);
  1645.     *termination = (char) save_char;
  1646.     p = termination;
  1647.     while (*p == ' ' || *p == '\t')
  1648.       p++;
  1649.       } else {
  1650.     abort ();
  1651.       }
  1652.     }
  1653.   }
  1654.  
  1655.   /* Now handle the command line options.  */
  1656.  
  1657.   /* Do -U's, -D's and -A's in the order they were seen.  */
  1658.   for (i = 1; i < argc; i++) {
  1659.     if (pend_undefs[i]) {
  1660.       if (debug_output)
  1661.         output_line_command (fp, &outbuf, 0, same_file);
  1662.       make_undef (pend_undefs[i], &outbuf);
  1663.     }
  1664.     if (pend_defs[i]) {
  1665.       if (debug_output)
  1666.         output_line_command (fp, &outbuf, 0, same_file);
  1667.       make_definition (pend_defs[i], &outbuf);
  1668.     }
  1669.     if (pend_assertions[i])
  1670.       make_assertion (pend_assertion_options[i], pend_assertions[i]);
  1671.   }
  1672.  
  1673.   done_initializing = 1;
  1674.  
  1675.   { /* read the appropriate environment variable and if it exists
  1676.        replace include_defaults with the listed path. */
  1677.     char *epath = 0;
  1678.     switch ((objc << 1) + cplusplus)
  1679.       {
  1680.       case 0:
  1681.     epath = getenv ("C_INCLUDE_PATH");
  1682.     break;
  1683.       case 1:
  1684.     epath = getenv ("CPLUS_INCLUDE_PATH");
  1685.     break;
  1686.       case 2:
  1687.     epath = getenv ("OBJC_INCLUDE_PATH");
  1688.     break;
  1689.       case 3:
  1690.     epath = getenv ("OBJCPLUS_INCLUDE_PATH");
  1691.     break;
  1692.       }
  1693.     /* If the environment var for this language is set,
  1694.        add to the default list of include directories.  */
  1695.     if (epath) {
  1696.       char *nstore = (char *) alloca (strlen (epath) + 2);
  1697.       int num_dirs;
  1698.       char *startp, *endp;
  1699.  
  1700.       for (num_dirs = 1, startp = epath; *startp; startp++)
  1701.     if (*startp == PATH_SEPARATOR)
  1702.       num_dirs++;
  1703.       include_defaults
  1704.     = (struct default_include *) xmalloc ((num_dirs
  1705.                            * sizeof (struct default_include))
  1706.                           + sizeof (include_defaults_array));
  1707.       startp = endp = epath;
  1708.       num_dirs = 0;
  1709.       while (1) {
  1710.         /* Handle cases like c:/usr/lib:d:/gcc/lib */
  1711.         if ((*endp == PATH_SEPARATOR
  1712. #if 0 /* Obsolete, now that we use semicolons as the path separator.  */
  1713. #ifdef __MSDOS__
  1714.          && (endp-startp != 1 || !isalpha (*startp))
  1715. #endif
  1716. #endif
  1717.          )
  1718.             || *endp == 0) {
  1719.       strncpy (nstore, startp, endp-startp);
  1720.       if (endp == startp)
  1721.         strcpy (nstore, ".");
  1722.       else
  1723.         nstore[endp-startp] = '\0';
  1724.  
  1725.       include_defaults[num_dirs].fname = savestring (nstore);
  1726.       include_defaults[num_dirs].cplusplus = cplusplus;
  1727.       num_dirs++;
  1728.       if (*endp == '\0')
  1729.         break;
  1730.       endp = startp = endp + 1;
  1731.     } else
  1732.       endp++;
  1733.       }
  1734.       /* Put the usual defaults back in at the end.  */
  1735.       bcopy (include_defaults_array, &include_defaults[num_dirs],
  1736.          sizeof (include_defaults_array));
  1737.     }
  1738.   }
  1739.  
  1740.   first_system_include = 0;
  1741.   /* Unless -fnostdinc,
  1742.      tack on the standard include file dirs to the specified list */
  1743.   if (!no_standard_includes) {
  1744.     struct default_include *p = include_defaults;
  1745.     char *specd_prefix = include_prefix;
  1746.     char *default_prefix = savestring (GCC_INCLUDE_DIR);
  1747.     int default_len = 0;
  1748.     /* Remove the `include' from /usr/local/lib/gcc.../include.  */
  1749.     if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) {
  1750.       default_len = strlen (default_prefix) - 7;
  1751.       default_prefix[default_len] = 0;
  1752.     }
  1753.     /* Search "translated" versions of GNU directories.
  1754.        These have /usr/local/lib/gcc... replaced by specd_prefix.  */
  1755.     if (specd_prefix != 0 && default_len != 0)
  1756.       for (p = include_defaults; p->fname; p++) {
  1757.     /* Some standard dirs are only for C++.  */
  1758.     if (!p->cplusplus || (cplusplus && !no_standard_cplusplus_includes)) {
  1759.       /* Does this dir start with the prefix?  */
  1760.       if (!strncmp (p->fname, default_prefix, default_len)) {
  1761.         /* Yes; change prefix and add to search list.  */
  1762.         struct file_name_list *new
  1763.           = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
  1764.         int this_len = strlen (specd_prefix) + strlen (p->fname) - default_len;
  1765.         char *str = (char *) xmalloc (this_len + 1);
  1766.         strcpy (str, specd_prefix);
  1767.         strcat (str, p->fname + default_len);
  1768.         new->fname = str;
  1769.         new->control_macro = 0;
  1770.         new->c_system_include_path = !p->cplusplus;
  1771.         append_include_chain (new, new);
  1772.         if (first_system_include == 0)
  1773.           first_system_include = new;
  1774.       }
  1775.     }
  1776.       }
  1777.     /* Search ordinary names for GNU include directories.  */
  1778.     for (p = include_defaults; p->fname; p++) {
  1779.       /* Some standard dirs are only for C++.  */
  1780.       if (!p->cplusplus || (cplusplus && !no_standard_cplusplus_includes)) {
  1781.     struct file_name_list *new
  1782.       = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
  1783.     new->control_macro = 0;
  1784.     new->c_system_include_path = !p->cplusplus;
  1785.     new->fname = p->fname;
  1786.     append_include_chain (new, new);
  1787.     if (first_system_include == 0)
  1788.       first_system_include = new;
  1789.       }
  1790.     }
  1791.   }
  1792.  
  1793.   /* Tack the after_include chain at the end of the include chain.  */
  1794.   append_include_chain (after_include, last_after_include);
  1795.   if (first_system_include == 0)
  1796.     first_system_include = after_include;
  1797.  
  1798.   /* With -v, print the list of dirs to search.  */
  1799.   if (verbose) {
  1800.     struct file_name_list *p;
  1801.     fprintf (stderr, "#include \"...\" search starts here:\n");
  1802.     for (p = include; p; p = p->next) {
  1803.       if (p == first_bracket_include)
  1804.     fprintf (stderr, "#include <...> search starts here:\n");
  1805.       fprintf (stderr, " %s\n", p->fname);
  1806.     }
  1807.     fprintf (stderr, "End of search list.\n");
  1808.   }
  1809.  
  1810.   /* Scan the -imacros files before the main input.
  1811.      Much like #including them, but with no_output set
  1812.      so that only their macro definitions matter.  */
  1813.  
  1814.   no_output++;
  1815.   for (i = 1; i < argc; i++)
  1816.     if (pend_files[i]) {
  1817.       int fd = open (pend_files[i], O_RDONLY, 0666);
  1818.       if (fd < 0) {
  1819.     perror_with_name (pend_files[i]);
  1820.     return FAILURE_EXIT_CODE;
  1821.       }
  1822.       finclude (fd, pend_files[i], &outbuf, 0, NULL_PTR);
  1823.     }
  1824.   no_output--;
  1825.  
  1826.   /* Copy the entire contents of the main input file into
  1827.      the stacked input buffer previously allocated for it.  */
  1828.  
  1829.   /* JF check for stdin */
  1830.   if (in_fname == NULL || *in_fname == 0) {
  1831.     in_fname = "";
  1832.     f = 0;
  1833.   } else if ((f = open (in_fname, O_RDONLY, 0666)) < 0)
  1834.     goto perror;
  1835.  
  1836.   /* Either of two environment variables can specify output of deps.
  1837.      Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
  1838.      where OUTPUT_FILE is the file to write deps info to
  1839.      and DEPS_TARGET is the target to mention in the deps.  */
  1840.  
  1841.   if (print_deps == 0
  1842.       && (getenv ("SUNPRO_DEPENDENCIES") != 0
  1843.       || getenv ("DEPENDENCIES_OUTPUT") != 0)) {
  1844.     char *spec = getenv ("DEPENDENCIES_OUTPUT");
  1845.     char *s;
  1846.     char *output_file;
  1847.  
  1848.     if (spec == 0) {
  1849.       spec = getenv ("SUNPRO_DEPENDENCIES");
  1850.       print_deps = 2;
  1851.     }
  1852.     else
  1853.       print_deps = 1;
  1854.  
  1855.     s = spec;
  1856.     /* Find the space before the DEPS_TARGET, if there is one.  */
  1857.     /* This should use index.  (mrs) */
  1858.     while (*s != 0 && *s != ' ') s++;
  1859.     if (*s != 0) {
  1860.       deps_target = s + 1;
  1861.       output_file = (char *) xmalloc (s - spec + 1);
  1862.       bcopy (spec, output_file, s - spec);
  1863.       output_file[s - spec] = 0;
  1864.     }
  1865.     else {
  1866.       deps_target = 0;
  1867.       output_file = spec;
  1868.     }
  1869.       
  1870.     deps_file = output_file;
  1871.     deps_mode = "a";
  1872.   }
  1873.  
  1874.   /* For -M, print the expected object file name
  1875.      as the target of this Make-rule.  */
  1876.   if (print_deps) {
  1877.     deps_allocated_size = 200;
  1878.     deps_buffer = (char *) xmalloc (deps_allocated_size);
  1879.     deps_buffer[0] = 0;
  1880.     deps_size = 0;
  1881.     deps_column = 0;
  1882.  
  1883.     if (deps_target) {
  1884.       deps_output (deps_target, 0);
  1885.       deps_output (":", 0);
  1886.     } else if (*in_fname == 0)
  1887.       deps_output ("-: ", 0);
  1888.     else {
  1889.       int len;
  1890.       char *p = in_fname;
  1891.       char *p1 = p;
  1892.       /* Discard all directory prefixes from P.  */
  1893. #ifdef FILE_NAME_NONDIRECTORY
  1894.       p = FILE_NAME_NONDIRECTORY (p);
  1895. #else
  1896.       while (*p1) {
  1897.     if (*p1 == '/')
  1898.       p = p1 + 1;
  1899.     p1++;
  1900.       }
  1901. #endif
  1902.       /* Output P, but remove known suffixes.  */
  1903.       len = strlen (p);
  1904.       if (p[len - 2] == '.' && p[len - 1] == 'c')
  1905.     deps_output (p, len - 2);
  1906.       else if (p[len - 2] == '.' && p[len - 1] == 'C')
  1907.     deps_output (p, len - 2);
  1908.       else if (p[len - 3] == '.'
  1909.            && p[len - 2] == 'c'
  1910.            && p[len - 1] == 'c')
  1911.     deps_output (p, len - 3);
  1912.       else if (p[len - 4] == '.'
  1913.            && p[len - 3] == 'c'
  1914.            && p[len - 2] == 'x'
  1915.            && p[len - 1] == 'x')
  1916.     deps_output (p, len - 4);
  1917.       else if (p[len - 2] == '.' && p[len - 1] == 's')
  1918.     deps_output (p, len - 2);
  1919.       else if (p[len - 2] == '.' && p[len - 1] == 'S')
  1920.     deps_output (p, len - 2);
  1921.       else if (p[len - 2] == '.' && p[len - 1] == 'm')
  1922.     deps_output (p, len - 2);
  1923.       else
  1924.     deps_output (p, 0);
  1925.       /* Supply our own suffix.  */
  1926. #ifndef VMS
  1927.       deps_output (".o : ", 0);
  1928. #else
  1929.       deps_output (".obj : ", 0);
  1930. #endif
  1931.       deps_output (in_fname, 0);
  1932.       deps_output (" ", 0);
  1933.     }
  1934.   }
  1935.  
  1936.   file_size_and_mode (f, &st_mode, &st_size);
  1937.   fp->nominal_fname = fp->fname = in_fname;
  1938.   fp->lineno = 1;
  1939.   fp->system_header_p = 0;
  1940.   /* JF all this is mine about reading pipes and ttys */
  1941.   if (! S_ISREG (st_mode)) {
  1942.     /* Read input from a file that is not a normal disk file.
  1943.        We cannot preallocate a buffer with the correct size,
  1944.        so we must read in the file a piece at the time and make it bigger.  */
  1945.     int size;
  1946.     int bsize;
  1947.     int cnt;
  1948.     U_CHAR *bufp;
  1949.  
  1950.     bsize = 2000;
  1951.     size = 0;
  1952.     fp->buf = (U_CHAR *) xmalloc (bsize + 2);
  1953.     bufp = fp->buf;
  1954.     for (;;) {
  1955.       cnt = safe_read (f, bufp, bsize - size);
  1956.       if (cnt < 0) goto perror;    /* error! */
  1957.       if (cnt == 0) break;    /* End of file */
  1958.       size += cnt;
  1959.       bufp += cnt;
  1960.       if (bsize == size) {    /* Buffer is full! */
  1961.         bsize *= 2;
  1962.         fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
  1963.     bufp = fp->buf + size;    /* May have moved */
  1964.       }
  1965.     }
  1966.     fp->length = size;
  1967.   } else {
  1968.     /* Read a file whose size we can determine in advance.
  1969.        For the sake of VMS, st_size is just an upper bound.  */
  1970.     long i;
  1971.     fp->length = 0;
  1972.     fp->buf = (U_CHAR *) xmalloc (st_size + 2);
  1973.  
  1974.     while (st_size > 0) {
  1975.       i = safe_read (f, fp->buf + fp->length, st_size);
  1976.       if (i <= 0) {
  1977.         if (i == 0) break;
  1978.     goto perror;
  1979.       }
  1980.       fp->length += i;
  1981.       st_size -= i;
  1982.     }
  1983.   }
  1984.   fp->bufp = fp->buf;
  1985.   fp->if_stack = if_stack;
  1986.  
  1987.   /* Make sure data ends with a newline.  And put a null after it.  */
  1988.  
  1989.   if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n')
  1990.       /* Backslash-newline at end is not good enough.  */
  1991.       || (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) {
  1992.     fp->buf[fp->length++] = '\n';
  1993.     missing_newline = 1;
  1994.   }
  1995.   fp->buf[fp->length] = '\0';
  1996.  
  1997.   /* Unless inhibited, convert trigraphs in the input.  */
  1998.  
  1999.   if (!no_trigraphs)
  2000.     trigraph_pcp (fp);
  2001.  
  2002.   /* Now that we know the input file is valid, open the output.  */
  2003.  
  2004.   if (!out_fname || !strcmp (out_fname, ""))
  2005.     out_fname = "stdout";
  2006.   else if (! freopen (out_fname, "w", stdout))
  2007.     pfatal_with_name (out_fname);
  2008.  
  2009.   output_line_command (fp, &outbuf, 0, same_file);
  2010.  
  2011.   /* Scan the -include files before the main input.  */
  2012.  
  2013.   for (i = 1; i < argc; i++)
  2014.     if (pend_includes[i]) {
  2015.       int fd = open (pend_includes[i], O_RDONLY, 0666);
  2016.       if (fd < 0) {
  2017.     perror_with_name (pend_includes[i]);
  2018.     return FAILURE_EXIT_CODE;
  2019.       }
  2020.       finclude (fd, pend_includes[i], &outbuf, 0, NULL_PTR);
  2021.     }
  2022.  
  2023.   /* Scan the input, processing macros and directives.  */
  2024.  
  2025.   rescan (&outbuf, 0);
  2026.  
  2027.   if (missing_newline)
  2028.     fp->lineno--;
  2029.  
  2030.   if (pedantic && missing_newline)
  2031.     pedwarn ("file does not end in newline");
  2032.  
  2033.   /* Now we have processed the entire input
  2034.      Write whichever kind of output has been requested.  */
  2035.  
  2036.   if (dump_macros == dump_only)
  2037.     dump_all_macros ();
  2038.   else if (! inhibit_output) {
  2039.     write_output ();
  2040.   }
  2041.  
  2042.   if (print_deps) {
  2043.     /* Don't actually write the deps file if compilation has failed.  */
  2044.     if (errors == 0) {
  2045.       if (deps_file && ! (deps_stream = fopen (deps_file, deps_mode)))
  2046.     pfatal_with_name (deps_file);
  2047.       fputs (deps_buffer, deps_stream);
  2048.       putc ('\n', deps_stream);
  2049.       if (deps_file) {
  2050.     if (ferror (deps_stream) || fclose (deps_stream) != 0)
  2051.       fatal ("I/O error on output");
  2052.       }
  2053.     }
  2054.   }
  2055.  
  2056.   if (pcp_outfile && pcp_outfile != stdout
  2057.       && (ferror (pcp_outfile) || fclose (pcp_outfile) != 0))
  2058.     fatal ("I/O error on `-pcp' output");
  2059.  
  2060.   if (ferror (stdout) || fclose (stdout) != 0)
  2061.     fatal ("I/O error on output");
  2062.  
  2063.   if (errors)
  2064.     exit (FAILURE_EXIT_CODE);
  2065.   exit (SUCCESS_EXIT_CODE);
  2066.  
  2067.  perror:
  2068.   pfatal_with_name (in_fname);
  2069.   return 0;
  2070. }
  2071.  
  2072. /* Given a colon-separated list of file names PATH,
  2073.    add all the names to the search path for include files.  */
  2074.  
  2075. static void
  2076. path_include (path)
  2077.      char *path;
  2078. {
  2079.   char *p;
  2080.  
  2081.   p = path;
  2082.  
  2083.   if (*p)
  2084.     while (1) {
  2085.       char *q = p;
  2086.       char *name;
  2087.       struct file_name_list *dirtmp;
  2088.  
  2089.       /* Find the end of this name.  */
  2090.       while (*q != 0 && *q != PATH_SEPARATOR) q++;
  2091.       if (p == q) {
  2092.     /* An empty name in the path stands for the current directory.  */
  2093.     name = (char *) xmalloc (2);
  2094.     name[0] = '.';
  2095.     name[1] = 0;
  2096.       } else {
  2097.     /* Otherwise use the directory that is named.  */
  2098.     name = (char *) xmalloc (q - p + 1);
  2099.     bcopy (p, name, q - p);
  2100.     name[q - p] = 0;
  2101.       }
  2102.  
  2103.       dirtmp = (struct file_name_list *)
  2104.     xmalloc (sizeof (struct file_name_list));
  2105.       dirtmp->next = 0;        /* New one goes on the end */
  2106.       dirtmp->control_macro = 0;
  2107.       dirtmp->c_system_include_path = 0;
  2108.       dirtmp->fname = name;
  2109.       append_include_chain (dirtmp, dirtmp);
  2110.  
  2111.       /* Advance past this name.  */
  2112.       p = q;
  2113.       if (*p == 0)
  2114.     break;
  2115.       /* Skip the colon.  */
  2116.       p++;
  2117.     }
  2118. }
  2119.  
  2120. /* Pre-C-Preprocessor to translate ANSI trigraph idiocy in BUF
  2121.    before main CCCP processing.  Name `pcp' is also in honor of the
  2122.    drugs the trigraph designers must have been on.
  2123.  
  2124.    Using an extra pass through the buffer takes a little extra time,
  2125.    but is infinitely less hairy than trying to handle trigraphs inside
  2126.    strings, etc. everywhere, and also makes sure that trigraphs are
  2127.    only translated in the top level of processing. */
  2128.  
  2129. static void
  2130. trigraph_pcp (buf)
  2131.      FILE_BUF *buf;
  2132. {
  2133.   register U_CHAR c, *fptr, *bptr, *sptr;
  2134.   int len;
  2135.  
  2136.   fptr = bptr = sptr = buf->buf;
  2137.   while ((sptr = (U_CHAR *) index (sptr, '?')) != NULL) {
  2138.     if (*++sptr != '?')
  2139.       continue;
  2140.     switch (*++sptr) {
  2141.       case '=':
  2142.       c = '#';
  2143.       break;
  2144.     case '(':
  2145.       c = '[';
  2146.       break;
  2147.     case '/':
  2148.       c = '\\';
  2149.       break;
  2150.     case ')':
  2151.       c = ']';
  2152.       break;
  2153.     case '\'':
  2154.       c = '^';
  2155.       break;
  2156.     case '<':
  2157.       c = '{';
  2158.       break;
  2159.     case '!':
  2160.       c = '|';
  2161.       break;
  2162.     case '>':
  2163.       c = '}';
  2164.       break;
  2165.     case '-':
  2166.       c  = '~';
  2167.       break;
  2168.     case '?':
  2169.       sptr--;
  2170.       continue;
  2171.     default:
  2172.       continue;
  2173.     }
  2174.     len = sptr - fptr - 2;
  2175.     if (bptr != fptr && len > 0)
  2176.       bcopy (fptr, bptr, len);    /* BSD doc says bcopy () works right
  2177.                    for overlapping strings.  In ANSI
  2178.                    C, this will be memmove (). */
  2179.     bptr += len;
  2180.     *bptr++ = c;
  2181.     fptr = ++sptr;
  2182.   }
  2183.   len = buf->length - (fptr - buf->buf);
  2184.   if (bptr != fptr && len > 0)
  2185.     bcopy (fptr, bptr, len);
  2186.   buf->length -= fptr - bptr;
  2187.   buf->buf[buf->length] = '\0';
  2188.   if (warn_trigraphs && fptr != bptr)
  2189.     warning ("%d trigraph(s) encountered", (fptr - bptr) / 2);
  2190. }
  2191.  
  2192. /* Move all backslash-newline pairs out of embarrassing places.
  2193.    Exchange all such pairs following BP
  2194.    with any potentially-embarrassing characters that follow them.
  2195.    Potentially-embarrassing characters are / and *
  2196.    (because a backslash-newline inside a comment delimiter
  2197.    would cause it not to be recognized).  */
  2198.  
  2199. static void
  2200. newline_fix (bp)
  2201.      U_CHAR *bp;
  2202. {
  2203.   register U_CHAR *p = bp;
  2204.   register int count = 0;
  2205.  
  2206.   /* First count the backslash-newline pairs here.  */
  2207.  
  2208.   while (1) {
  2209.     if (p[0] == '\\') {
  2210.       if (p[1] == '\n')
  2211.     p += 2, count++;
  2212.       else if (p[1] == '\r' && p[2] == '\n')
  2213.     p += 3, count++;
  2214.       else
  2215.     break;
  2216.     } else
  2217.       break;
  2218.   }
  2219.  
  2220.   /* What follows the backslash-newlines is not embarrassing.  */
  2221.  
  2222.   if (count == 0 || (*p != '/' && *p != '*'))
  2223.     return;
  2224.  
  2225.   /* Copy all potentially embarrassing characters
  2226.      that follow the backslash-newline pairs
  2227.      down to where the pairs originally started.  */
  2228.  
  2229.   while (*p == '*' || *p == '/')
  2230.     *bp++ = *p++;
  2231.  
  2232.   /* Now write the same number of pairs after the embarrassing chars.  */
  2233.   while (count-- > 0) {
  2234.     *bp++ = '\\';
  2235.     *bp++ = '\n';
  2236.   }
  2237. }
  2238.  
  2239. /* Like newline_fix but for use within a directive-name.
  2240.    Move any backslash-newlines up past any following symbol constituents.  */
  2241.  
  2242. static void
  2243. name_newline_fix (bp)
  2244.      U_CHAR *bp;
  2245. {
  2246.   register U_CHAR *p = bp;
  2247.   register int count = 0;
  2248.  
  2249.   /* First count the backslash-newline pairs here.  */
  2250.   while (1) {
  2251.     if (p[0] == '\\') {
  2252.       if (p[1] == '\n')
  2253.     p += 2, count++;
  2254.       else if (p[1] == '\r' && p[2] == '\n')
  2255.     p += 3, count++;
  2256.       else
  2257.     break;
  2258.     } else
  2259.       break;
  2260.   }
  2261.  
  2262.   /* What follows the backslash-newlines is not embarrassing.  */
  2263.  
  2264.   if (count == 0 || !is_idchar[*p])
  2265.     return;
  2266.  
  2267.   /* Copy all potentially embarrassing characters
  2268.      that follow the backslash-newline pairs
  2269.      down to where the pairs originally started.  */
  2270.  
  2271.   while (is_idchar[*p])
  2272.     *bp++ = *p++;
  2273.  
  2274.   /* Now write the same number of pairs after the embarrassing chars.  */
  2275.   while (count-- > 0) {
  2276.     *bp++ = '\\';
  2277.     *bp++ = '\n';
  2278.   }
  2279. }
  2280.  
  2281. /* Look for lint commands in comments.
  2282.  
  2283.    When we come in here, ibp points into a comment.  Limit is as one expects.
  2284.    scan within the comment -- it should start, after lwsp, with a lint command.
  2285.    If so that command is returned as a (constant) string.
  2286.  
  2287.    Upon return, any arg will be pointed to with argstart and will be
  2288.    arglen long.  Note that we don't parse that arg since it will just
  2289.    be printed out again.
  2290. */
  2291.  
  2292. static char *
  2293. get_lintcmd (ibp, limit, argstart, arglen, cmdlen)
  2294.      register U_CHAR *ibp;
  2295.      register U_CHAR *limit;
  2296.      U_CHAR **argstart;        /* point to command arg */
  2297.      int *arglen, *cmdlen;    /* how long they are */
  2298. {
  2299.   long linsize;
  2300.   register U_CHAR *numptr;    /* temp for arg parsing */
  2301.  
  2302.   *arglen = 0;
  2303.  
  2304.   SKIP_WHITE_SPACE (ibp);
  2305.  
  2306.   if (ibp >= limit) return NULL;
  2307.  
  2308.   linsize = limit - ibp;
  2309.   
  2310.   /* Oh, I wish C had lexical functions... hell, I'll just open-code the set */
  2311.   if ((linsize >= 10) && !strncmp (ibp, "NOTREACHED", 10)) {
  2312.     *cmdlen = 10;
  2313.     return "NOTREACHED";
  2314.   }
  2315.   if ((linsize >= 8) && !strncmp (ibp, "ARGSUSED", 8)) {
  2316.     *cmdlen = 8;
  2317.     return "ARGSUSED";
  2318.   }
  2319.   if ((linsize >= 11) && !strncmp (ibp, "LINTLIBRARY", 11)) {
  2320.     *cmdlen = 11;
  2321.     return "LINTLIBRARY";
  2322.   }
  2323.   if ((linsize >= 7) && !strncmp (ibp, "VARARGS", 7)) {
  2324.     *cmdlen = 7;
  2325.     ibp += 7; linsize -= 7;
  2326.     if ((linsize == 0) || ! isdigit (*ibp)) return "VARARGS";
  2327.  
  2328.     /* OK, read a number */
  2329.     for (numptr = *argstart = ibp; (numptr < limit) && isdigit (*numptr);
  2330.      numptr++);
  2331.     *arglen = numptr - *argstart;
  2332.     return "VARARGS";
  2333.   }
  2334.   return NULL;
  2335. }
  2336.  
  2337. /*
  2338.  * The main loop of the program.
  2339.  *
  2340.  * Read characters from the input stack, transferring them to the
  2341.  * output buffer OP.
  2342.  *
  2343.  * Macros are expanded and push levels on the input stack.
  2344.  * At the end of such a level it is popped off and we keep reading.
  2345.  * At the end of any other kind of level, we return.
  2346.  * #-directives are handled, except within macros.
  2347.  *
  2348.  * If OUTPUT_MARKS is nonzero, keep Newline markers found in the input
  2349.  * and insert them when appropriate.  This is set while scanning macro
  2350.  * arguments before substitution.  It is zero when scanning for final output.
  2351.  *   There are three types of Newline markers:
  2352.  *   * Newline -  follows a macro name that was not expanded
  2353.  *     because it appeared inside an expansion of the same macro.
  2354.  *     This marker prevents future expansion of that identifier.
  2355.  *     When the input is rescanned into the final output, these are deleted.
  2356.  *     These are also deleted by ## concatenation.
  2357.  *   * Newline Space (or Newline and any other whitespace character)
  2358.  *     stands for a place that tokens must be separated or whitespace
  2359.  *     is otherwise desirable, but where the ANSI standard specifies there
  2360.  *     is no whitespace.  This marker turns into a Space (or whichever other
  2361.  *     whitespace char appears in the marker) in the final output,
  2362.  *     but it turns into nothing in an argument that is stringified with #.
  2363.  *     Such stringified arguments are the only place where the ANSI standard
  2364.  *     specifies with precision that whitespace may not appear.
  2365.  *
  2366.  * During this function, IP->bufp is kept cached in IBP for speed of access.
  2367.  * Likewise, OP->bufp is kept in OBP.  Before calling a subroutine
  2368.  * IBP, IP and OBP must be copied back to memory.  IP and IBP are
  2369.  * copied back with the RECACHE macro.  OBP must be copied back from OP->bufp
  2370.  * explicitly, and before RECACHE, since RECACHE uses OBP.
  2371.  */
  2372.  
  2373. static void
  2374. rescan (op, output_marks)
  2375.      FILE_BUF *op;
  2376.      int output_marks;
  2377. {
  2378.   /* Character being scanned in main loop.  */
  2379.   register U_CHAR c;
  2380.  
  2381.   /* Length of pending accumulated identifier.  */
  2382.   register int ident_length = 0;
  2383.  
  2384.   /* Hash code of pending accumulated identifier.  */
  2385.   register int hash = 0;
  2386.  
  2387.   /* Current input level (&instack[indepth]).  */
  2388.   FILE_BUF *ip;
  2389.  
  2390.   /* Pointer for scanning input.  */
  2391.   register U_CHAR *ibp;
  2392.  
  2393.   /* Pointer to end of input.  End of scan is controlled by LIMIT.  */
  2394.   register U_CHAR *limit;
  2395.  
  2396.   /* Pointer for storing output.  */
  2397.   register U_CHAR *obp;
  2398.  
  2399.   /* REDO_CHAR is nonzero if we are processing an identifier
  2400.      after backing up over the terminating character.
  2401.      Sometimes we process an identifier without backing up over
  2402.      the terminating character, if the terminating character
  2403.      is not special.  Backing up is done so that the terminating character
  2404.      will be dispatched on again once the identifier is dealt with.  */
  2405.   int redo_char = 0;
  2406.  
  2407.   /* 1 if within an identifier inside of which a concatenation
  2408.      marker (Newline -) has been seen.  */
  2409.   int concatenated = 0;
  2410.  
  2411.   /* While scanning a comment or a string constant,
  2412.      this records the line it started on, for error messages.  */
  2413.   int start_line;
  2414.  
  2415.   /* Record position of last `real' newline.  */
  2416.   U_CHAR *beg_of_line;
  2417.  
  2418. /* Pop the innermost input stack level, assuming it is a macro expansion.  */
  2419.  
  2420. #define POPMACRO \
  2421. do { ip->macro->type = T_MACRO;        \
  2422.      if (ip->free_ptr) free (ip->free_ptr);    \
  2423.      --indepth; } while (0)
  2424.  
  2425. /* Reload `rescan's local variables that describe the current
  2426.    level of the input stack.  */
  2427.  
  2428. #define RECACHE  \
  2429. do { ip = &instack[indepth];        \
  2430.      ibp = ip->bufp;            \
  2431.      limit = ip->buf + ip->length;    \
  2432.      op->bufp = obp;            \
  2433.      check_expand (op, limit - ibp);    \
  2434.      beg_of_line = 0;            \
  2435.      obp = op->bufp; } while (0)
  2436.  
  2437.   if (no_output && instack[indepth].fname != 0)
  2438.     skip_if_group (&instack[indepth], 1);
  2439.  
  2440.   obp = op->bufp;
  2441.   RECACHE;
  2442.  
  2443.   beg_of_line = ibp;
  2444.  
  2445.   /* Our caller must always put a null after the end of
  2446.      the input at each input stack level.  */
  2447.   if (*limit != 0)
  2448.     abort ();
  2449.  
  2450.   while (1) {
  2451.     c = *ibp++;
  2452.     *obp++ = c;
  2453.  
  2454.     switch (c) {
  2455.     case '\\':
  2456.       if (ibp >= limit)
  2457.     break;
  2458.       if (*ibp == '\n') {
  2459.     /* Always merge lines ending with backslash-newline,
  2460.        even in middle of identifier.  */
  2461.     ++ibp;
  2462.     ++ip->lineno;
  2463.     --obp;        /* remove backslash from obuf */
  2464.     break;
  2465.       }
  2466.       /* Otherwise, backslash suppresses specialness of following char,
  2467.      so copy it here to prevent the switch from seeing it.
  2468.      But first get any pending identifier processed.  */
  2469.       if (ident_length > 0)
  2470.     goto specialchar;
  2471.       *obp++ = *ibp++;
  2472.       break;
  2473.  
  2474.     case '#':
  2475.       if (assertions_flag) {
  2476.     /* Copy #foo (bar lose) without macro expansion.  */
  2477.     SKIP_WHITE_SPACE (ibp);
  2478.     while (is_idchar[*ibp])
  2479.       *obp++ = *ibp++;
  2480.     SKIP_WHITE_SPACE (ibp);
  2481.     if (*ibp == '(') {
  2482.       ip->bufp = ibp;
  2483.       skip_paren_group (ip);
  2484.       bcopy (ibp, obp, ip->bufp - ibp);
  2485.       obp += ip->bufp - ibp;
  2486.       ibp = ip->bufp;
  2487.     }
  2488.       }
  2489.  
  2490.       /* If this is expanding a macro definition, don't recognize
  2491.      preprocessor directives.  */
  2492.       if (ip->macro != 0)
  2493.     goto randomchar;
  2494.       /* If this is expand_into_temp_buffer, recognize them
  2495.      only after an actual newline at this level,
  2496.      not at the beginning of the input level.  */
  2497.       if (ip->fname == 0 && beg_of_line == ip->buf)
  2498.     goto randomchar;
  2499.       if (ident_length)
  2500.     goto specialchar;
  2501.  
  2502.       
  2503.       /* # keyword: a # must be first nonblank char on the line */
  2504.       if (beg_of_line == 0)
  2505.     goto randomchar;
  2506.       {
  2507.     U_CHAR *bp;
  2508.  
  2509.     /* Scan from start of line, skipping whitespace, comments
  2510.        and backslash-newlines, and see if we reach this #.
  2511.        If not, this # is not special.  */
  2512.     bp = beg_of_line;
  2513.     /* If -traditional, require # to be at beginning of line.  */
  2514.     if (!traditional)
  2515.       while (1) {
  2516.         if (is_hor_space[*bp])
  2517.           bp++;
  2518.         else if (*bp == '\\' && bp[1] == '\n')
  2519.           bp += 2;
  2520.         else if (*bp == '/' && bp[1] == '*') {
  2521.           bp += 2;
  2522.           while (!(*bp == '*' && bp[1] == '/'))
  2523.         bp++;
  2524.           bp += 2;
  2525.         }
  2526.         else if (cplusplus_comments && *bp == '/' && bp[1] == '/') {
  2527.           bp += 2;
  2528.           while (*bp++ != '\n') ;
  2529.         }
  2530.         else break;
  2531.       }
  2532.     if (bp + 1 != ibp)
  2533.       goto randomchar;
  2534.       }
  2535.  
  2536.       /* This # can start a directive.  */
  2537.  
  2538.       --obp;        /* Don't copy the '#' */
  2539.  
  2540.       ip->bufp = ibp;
  2541.       op->bufp = obp;
  2542.       if (! handle_directive (ip, op)) {
  2543. #ifdef USE_C_ALLOCA
  2544.     alloca (0);
  2545. #endif
  2546.     /* Not a known directive: treat it as ordinary text.
  2547.        IP, OP, IBP, etc. have not been changed.  */
  2548.     if (no_output && instack[indepth].fname) {
  2549.       /* If not generating expanded output,
  2550.          what we do with ordinary text is skip it.
  2551.          Discard everything until next # directive.  */
  2552.       skip_if_group (&instack[indepth], 1);
  2553.       RECACHE;
  2554.       beg_of_line = ibp;
  2555.       break;
  2556.     }
  2557.     ++obp;        /* Copy the '#' after all */
  2558.     /* Don't expand an identifier that could be a macro directive.
  2559.        (Section 3.8.3 of the ANSI C standard)            */
  2560.     SKIP_WHITE_SPACE (ibp);
  2561.     if (is_idstart[*ibp])
  2562.       {
  2563.         *obp++ = *ibp++;
  2564.         while (is_idchar[*ibp])
  2565.           *obp++ = *ibp++;
  2566.       }
  2567.     goto randomchar;
  2568.       }
  2569. #ifdef USE_C_ALLOCA
  2570.       alloca (0);
  2571. #endif
  2572.       /* A # directive has been successfully processed.  */
  2573.       /* If not generating expanded output, ignore everything until
  2574.      next # directive.  */
  2575.       if (no_output && instack[indepth].fname)
  2576.     skip_if_group (&instack[indepth], 1);
  2577.       obp = op->bufp;
  2578.       RECACHE;
  2579.       beg_of_line = ibp;
  2580.       break;
  2581.  
  2582.     case '\"':            /* skip quoted string */
  2583.     case '\'':
  2584.       /* A single quoted string is treated like a double -- some
  2585.      programs (e.g., troff) are perverse this way */
  2586.  
  2587.       if (ident_length)
  2588.     goto specialchar;
  2589.  
  2590.       start_line = ip->lineno;
  2591.  
  2592.       /* Skip ahead to a matching quote.  */
  2593.  
  2594.       while (1) {
  2595.     if (ibp >= limit) {
  2596.       if (ip->macro != 0) {
  2597.         /* try harder: this string crosses a macro expansion boundary.
  2598.            This can happen naturally if -traditional.
  2599.            Otherwise, only -D can make a macro with an unmatched quote.  */
  2600.         POPMACRO;
  2601.         RECACHE;
  2602.         continue;
  2603.       }
  2604.       if (!traditional) {
  2605.         error_with_line (line_for_error (start_line),
  2606.                  "unterminated string or character constant");
  2607.         error_with_line (multiline_string_line,
  2608.                  "possible real start of unterminated constant");
  2609.         multiline_string_line = 0;
  2610.       }
  2611.       break;
  2612.     }
  2613.     *obp++ = *ibp;
  2614.     switch (*ibp++) {
  2615.     case '\n':
  2616.       ++ip->lineno;
  2617.       ++op->lineno;
  2618.       /* Traditionally, end of line ends a string constant with no error.
  2619.          So exit the loop and record the new line.  */
  2620.       if (traditional) {
  2621.         beg_of_line = ibp;
  2622.         goto while2end;
  2623.       }
  2624.       if (c == '\'') {
  2625.         error_with_line (line_for_error (start_line),
  2626.                  "unterminated character constant");
  2627.         goto while2end;
  2628.       }
  2629.       if (pedantic && multiline_string_line == 0) {
  2630.         pedwarn_with_line (line_for_error (start_line),
  2631.                    "string constant runs past end of line");
  2632.       }
  2633.       if (multiline_string_line == 0)
  2634.         multiline_string_line = ip->lineno - 1;
  2635.       break;
  2636.  
  2637.     case '\\':
  2638.       if (ibp >= limit)
  2639.         break;
  2640.       if (*ibp == '\n') {
  2641.         /* Backslash newline is replaced by nothing at all,
  2642.            but keep the line counts correct.  */
  2643.         --obp;
  2644.         ++ibp;
  2645.         ++ip->lineno;
  2646.       } else {
  2647.         /* ANSI stupidly requires that in \\ the second \
  2648.            is *not* prevented from combining with a newline.  */
  2649.         while (*ibp == '\\' && ibp[1] == '\n') {
  2650.           ibp += 2;
  2651.           ++ip->lineno;
  2652.         }
  2653.         *obp++ = *ibp++;
  2654.       }
  2655.       break;
  2656.  
  2657.     case '\"':
  2658.     case '\'':
  2659.       if (ibp[-1] == c)
  2660.         goto while2end;
  2661.       break;
  2662.     }
  2663.       }
  2664.     while2end:
  2665.       break;
  2666.  
  2667.     case '/':
  2668.       if (*ibp == '\\' && ibp[1] == '\n')
  2669.     newline_fix (ibp);
  2670.  
  2671.       if (*ibp != '*'
  2672.       && !(cplusplus_comments && *ibp == '/'))
  2673.     goto randomchar;
  2674.       if (ip->macro != 0)
  2675.     goto randomchar;
  2676.       if (ident_length)
  2677.     goto specialchar;
  2678.  
  2679.       if (*ibp == '/') {
  2680.     /* C++ style comment... */
  2681.     start_line = ip->lineno;
  2682.  
  2683.     --ibp;            /* Back over the slash */
  2684.     --obp;
  2685.  
  2686.     /* Comments are equivalent to spaces. */
  2687.     if (! put_out_comments)
  2688.       *obp++ = ' ';
  2689.     else {
  2690.       /* must fake up a comment here */
  2691.       *obp++ = '/';
  2692.       *obp++ = '/';
  2693.     }
  2694.     {
  2695.       U_CHAR *before_bp = ibp+2;
  2696.  
  2697.       while (ibp < limit) {
  2698.         if (*ibp++ == '\n') {
  2699.           ibp--;
  2700.           if (put_out_comments) {
  2701.         bcopy (before_bp, obp, ibp - before_bp);
  2702.         obp += ibp - before_bp;
  2703.           }
  2704.           break;
  2705.         }
  2706.       }
  2707.       break;
  2708.     }
  2709.       }
  2710.  
  2711.       /* Ordinary C comment.  Skip it, optionally copying it to output.  */
  2712.  
  2713.       start_line = ip->lineno;
  2714.  
  2715.       ++ibp;            /* Skip the star. */
  2716.  
  2717.       /* If this cpp is for lint, we peek inside the comments: */
  2718.       if (lint) {
  2719.     U_CHAR *argbp;
  2720.     int cmdlen, arglen;
  2721.     char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen);
  2722.  
  2723.     if (lintcmd != NULL) {
  2724.       /* I believe it is always safe to emit this newline: */
  2725.       obp[-1] = '\n';
  2726.       bcopy ("#pragma lint ", obp, 13);
  2727.       obp += 13;
  2728.       bcopy (lintcmd, obp, cmdlen);
  2729.       obp += cmdlen;
  2730.  
  2731.       if (arglen != 0) {
  2732.         *(obp++) = ' ';
  2733.         bcopy (argbp, obp, arglen);
  2734.         obp += arglen;
  2735.       }
  2736.  
  2737.       /* OK, now bring us back to the state we were in before we entered
  2738.          this branch.  We need #line b/c the newline for the pragma
  2739.          could fuck things up. */
  2740.       output_line_command (ip, op, 0, same_file);
  2741.       *(obp++) = ' ';    /* just in case, if comments are copied thru */
  2742.       *(obp++) = '/';
  2743.     }
  2744.       }
  2745.  
  2746.       /* Comments are equivalent to spaces.
  2747.      Note that we already output the slash; we might not want it.
  2748.      For -traditional, a comment is equivalent to nothing.  */
  2749.       if (! put_out_comments) {
  2750.     if (traditional)
  2751.       obp--;
  2752.     else
  2753.       obp[-1] = ' ';
  2754.       }
  2755.       else
  2756.     *obp++ = '*';
  2757.  
  2758.       {
  2759.     U_CHAR *before_bp = ibp;
  2760.  
  2761.     while (ibp < limit) {
  2762.       switch (*ibp++) {
  2763.       case '/':
  2764.         if (warn_comments && ibp < limit && *ibp == '*')
  2765.           warning ("`/*' within comment");
  2766.         break;
  2767.       case '*':
  2768.         if (*ibp == '\\' && ibp[1] == '\n')
  2769.           newline_fix (ibp);
  2770.         if (ibp >= limit || *ibp == '/')
  2771.           goto comment_end;
  2772.         break;
  2773.       case '\n':
  2774.         ++ip->lineno;
  2775.         /* Copy the newline into the output buffer, in order to
  2776.            avoid the pain of a #line every time a multiline comment
  2777.            is seen.  */
  2778.         if (!put_out_comments)
  2779.           *obp++ = '\n';
  2780.         ++op->lineno;
  2781.       }
  2782.     }
  2783.       comment_end:
  2784.  
  2785.     if (ibp >= limit)
  2786.       error_with_line (line_for_error (start_line),
  2787.                "unterminated comment");
  2788.     else {
  2789.       ibp++;
  2790.       if (put_out_comments) {
  2791.         bcopy (before_bp, obp, ibp - before_bp);
  2792.         obp += ibp - before_bp;
  2793.       }
  2794.     }
  2795.       }
  2796.       break;
  2797.  
  2798.     case '$':
  2799.       if (!dollars_in_ident)
  2800.     goto randomchar;
  2801.       goto letter;
  2802.  
  2803.     case '0': case '1': case '2': case '3': case '4':
  2804.     case '5': case '6': case '7': case '8': case '9':
  2805.       /* If digit is not part of identifier, it starts a number,
  2806.      which means that following letters are not an identifier.
  2807.      "0x5" does not refer to an identifier "x5".
  2808.      So copy all alphanumerics that follow without accumulating
  2809.      as an identifier.  Periods also, for sake of "3.e7".  */
  2810.  
  2811.       if (ident_length == 0) {
  2812.     while (ibp < limit) {
  2813.       while (ibp < limit && ibp[0] == '\\' && ibp[1] == '\n') {
  2814.         ++ip->lineno;
  2815.         ibp += 2;
  2816.       }
  2817.       c = *ibp++;
  2818.       /* ".." terminates a preprocessing number.  This is useless for C
  2819.          code but useful for preprocessing other things.  */
  2820.       if (!isalnum (c) && (c != '.' || *ibp == '.') && c != '_') {
  2821.         --ibp;
  2822.         break;
  2823.       }
  2824.       *obp++ = c;
  2825.       /* A sign can be part of a preprocessing number
  2826.          if it follows an e.  */
  2827.       if (c == 'e' || c == 'E') {
  2828.         while (ibp < limit && ibp[0] == '\\' && ibp[1] == '\n') {
  2829.           ++ip->lineno;
  2830.           ibp += 2;
  2831.         }
  2832.         if (ibp < limit && (*ibp == '+' || *ibp == '-')) {
  2833.           *obp++ = *ibp++;
  2834.           /* But traditional C does not let the token go past the sign.  */
  2835.           if (traditional)
  2836.         break;
  2837.         }
  2838.       }
  2839.     }
  2840.     break;
  2841.       }
  2842.       /* fall through */
  2843.  
  2844.     case '_':
  2845.     case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
  2846.     case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
  2847.     case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
  2848.     case 's': case 't': case 'u': case 'v': case 'w': case 'x':
  2849.     case 'y': case 'z':
  2850.     case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
  2851.     case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
  2852.     case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
  2853.     case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
  2854.     case 'Y': case 'Z':
  2855.     letter:
  2856.       ident_length++;
  2857.       /* Compute step of hash function, to avoid a proc call on every token */
  2858.       hash = HASHSTEP (hash, c);
  2859.       break;
  2860.  
  2861.     case '\n':
  2862.       if (ip->fname == 0 && *ibp == '-') {
  2863.     /* Newline - inhibits expansion of preceding token.
  2864.        If expanding a macro arg, we keep the newline -.
  2865.        In final output, it is deleted.
  2866.        We recognize Newline - in macro bodies and macro args.  */
  2867.     if (! concatenated) {
  2868.       ident_length = 0;
  2869.       hash = 0;
  2870.     }
  2871.     ibp++;
  2872.     if (!output_marks) {
  2873.       obp--;
  2874.     } else {
  2875.       /* If expanding a macro arg, keep the newline -.  */
  2876.       *obp++ = '-';
  2877.     }
  2878.     break;
  2879.       }
  2880.  
  2881.       /* If reprocessing a macro expansion, newline is a special marker.  */
  2882.       else if (ip->macro != 0) {
  2883.     /* Newline White is a "funny space" to separate tokens that are
  2884.        supposed to be separate but without space between.
  2885.        Here White means any whitespace character.
  2886.        Newline - marks a recursive macro use that is not
  2887.        supposed to be expandable.  */
  2888.  
  2889.     if (is_space[*ibp]) {
  2890.       /* Newline Space does not prevent expansion of preceding token
  2891.          so expand the preceding token and then come back.  */
  2892.       if (ident_length > 0)
  2893.         goto specialchar;
  2894.  
  2895.       /* If generating final output, newline space makes a space.  */
  2896.       if (!output_marks) {
  2897.         obp[-1] = *ibp++;
  2898.         /* And Newline Newline makes a newline, so count it.  */
  2899.         if (obp[-1] == '\n')
  2900.           op->lineno++;
  2901.       } else {
  2902.         /* If expanding a macro arg, keep the newline space.
  2903.            If the arg gets stringified, newline space makes nothing.  */
  2904.         *obp++ = *ibp++;
  2905.       }
  2906.     } else abort ();    /* Newline followed by something random?  */
  2907.     break;
  2908.       }
  2909.  
  2910.       /* If there is a pending identifier, handle it and come back here.  */
  2911.       if (ident_length > 0)
  2912.     goto specialchar;
  2913.  
  2914.       beg_of_line = ibp;
  2915.  
  2916.       /* Update the line counts and output a #line if necessary.  */
  2917.       ++ip->lineno;
  2918.       ++op->lineno;
  2919.       if (ip->lineno != op->lineno) {
  2920.     op->bufp = obp;
  2921.     output_line_command (ip, op, 1, same_file);
  2922.     check_expand (op, ip->length - (ip->bufp - ip->buf));
  2923.     obp = op->bufp;
  2924.       }
  2925.       break;
  2926.  
  2927.       /* Come here either after (1) a null character that is part of the input
  2928.      or (2) at the end of the input, because there is a null there.  */
  2929.     case 0:
  2930.       if (ibp <= limit)
  2931.     /* Our input really contains a null character.  */
  2932.     goto randomchar;
  2933.  
  2934.       /* At end of a macro-expansion level, pop it and read next level.  */
  2935.       if (ip->macro != 0) {
  2936.     obp--;
  2937.     ibp--;
  2938.     /* If traditional, and we have an identifier that ends here,
  2939.        process it now, so we get the right error for recursion.  */
  2940.     if (traditional && ident_length
  2941.         && ! is_idchar[*instack[indepth - 1].bufp]) {
  2942.       redo_char = 1;
  2943.       goto randomchar;
  2944.     }
  2945.     POPMACRO;
  2946.     RECACHE;
  2947.     break;
  2948.       }
  2949.  
  2950.       /* If we don't have a pending identifier,
  2951.      return at end of input.  */
  2952.       if (ident_length == 0) {
  2953.     obp--;
  2954.     ibp--;
  2955.     op->bufp = obp;
  2956.     ip->bufp = ibp;
  2957.     goto ending;
  2958.       }
  2959.  
  2960.       /* If we do have a pending identifier, just consider this null
  2961.      a special character and arrange to dispatch on it again.
  2962.      The second time, IDENT_LENGTH will be zero so we will return.  */
  2963.  
  2964.       /* Fall through */
  2965.  
  2966. specialchar:
  2967.  
  2968.       /* Handle the case of a character such as /, ', " or null
  2969.      seen following an identifier.  Back over it so that
  2970.      after the identifier is processed the special char
  2971.      will be dispatched on again.  */
  2972.  
  2973.       ibp--;
  2974.       obp--;
  2975.       redo_char = 1;
  2976.  
  2977.     default:
  2978.  
  2979. randomchar:
  2980.  
  2981.       if (ident_length > 0) {
  2982.     register HASHNODE *hp;
  2983.  
  2984.     /* We have just seen an identifier end.  If it's a macro, expand it.
  2985.  
  2986.        IDENT_LENGTH is the length of the identifier
  2987.        and HASH is its hash code.
  2988.  
  2989.        The identifier has already been copied to the output,
  2990.        so if it is a macro we must remove it.
  2991.  
  2992.        If REDO_CHAR is 0, the char that terminated the identifier
  2993.        has been skipped in the output and the input.
  2994.        OBP-IDENT_LENGTH-1 points to the identifier.
  2995.        If the identifier is a macro, we must back over the terminator.
  2996.  
  2997.        If REDO_CHAR is 1, the terminating char has already been
  2998.        backed over.  OBP-IDENT_LENGTH points to the identifier.  */
  2999.  
  3000.     if (!pcp_outfile || pcp_inside_if) {
  3001. startagain:
  3002.       for (hp = hashtab[MAKE_POS (hash) % HASHSIZE]; hp != NULL;
  3003.            hp = hp->next) {
  3004.         
  3005.         if (hp->length == ident_length) {
  3006.           int obufp_before_macroname;
  3007.           int op_lineno_before_macroname;
  3008.           register int i = ident_length;
  3009.           register U_CHAR *p = hp->name;
  3010.           register U_CHAR *q = obp - i;
  3011.           int disabled;
  3012.           
  3013.           if (! redo_char)
  3014.         q--;
  3015.           
  3016.           do {        /* All this to avoid a strncmp () */
  3017.         if (*p++ != *q++)
  3018.           goto hashcollision;
  3019.           } while (--i);
  3020.           
  3021.           /* We found a use of a macro name.
  3022.          see if the context shows it is a macro call.  */
  3023.           
  3024.           /* Back up over terminating character if not already done.  */
  3025.           if (! redo_char) {
  3026.         ibp--;
  3027.         obp--;
  3028.           }
  3029.           
  3030.           /* Save this as a displacement from the beginning of the output
  3031.          buffer.  We can not save this as a position in the output
  3032.          buffer, because it may get realloc'ed by RECACHE.  */
  3033.           obufp_before_macroname = (obp - op->buf) - ident_length;
  3034.           op_lineno_before_macroname = op->lineno;
  3035.           
  3036.           if (hp->type == T_PCSTRING) {
  3037.         pcstring_used (hp); /* Mark the definition of this key
  3038.                        as needed, ensuring that it
  3039.                        will be output.  */
  3040.         break;        /* Exit loop, since the key cannot have a
  3041.                    definition any longer.  */
  3042.           }
  3043.  
  3044.           /* Record whether the macro is disabled.  */
  3045.           disabled = hp->type == T_DISABLED;
  3046.           
  3047.           /* This looks like a macro ref, but if the macro was disabled,
  3048.          just copy its name and put in a marker if requested.  */
  3049.           
  3050.           if (disabled) {
  3051. #if 0
  3052.         /* This error check caught useful cases such as
  3053.            #define foo(x,y) bar (x (y,0), y)
  3054.            foo (foo, baz)  */
  3055.         if (traditional)
  3056.           error ("recursive use of macro `%s'", hp->name);
  3057. #endif
  3058.         
  3059.         if (output_marks) {
  3060.           check_expand (op, limit - ibp + 2);
  3061.           *obp++ = '\n';
  3062.           *obp++ = '-';
  3063.         }
  3064.         break;
  3065.           }
  3066.           
  3067.           /* If macro wants an arglist, verify that a '(' follows.
  3068.          first skip all whitespace, copying it to the output
  3069.          after the macro name.  Then, if there is no '(',
  3070.          decide this is not a macro call and leave things that way.  */
  3071.           if ((hp->type == T_MACRO || hp->type == T_DISABLED)
  3072.           && hp->value.defn->nargs >= 0)
  3073.         {
  3074.           U_CHAR *old_ibp = ibp;
  3075.           U_CHAR *old_obp = obp;
  3076.           int old_iln = ip->lineno;
  3077.           int old_oln = op->lineno;
  3078.           
  3079.           while (1) {
  3080.             /* Scan forward over whitespace, copying it to the output.  */
  3081.             if (ibp == limit && ip->macro != 0) {
  3082.               POPMACRO;
  3083.               RECACHE;
  3084.               old_ibp = ibp;
  3085.               old_obp = obp;
  3086.               old_iln = ip->lineno;
  3087.               old_oln = op->lineno;
  3088.             }
  3089.             /* A comment: copy it unchanged or discard it.  */
  3090.             else if (*ibp == '/' && ibp+1 != limit && ibp[1] == '*') {
  3091.               if (put_out_comments) {
  3092.             *obp++ = '/';
  3093.             *obp++ = '*';
  3094.               } else if (! traditional) {
  3095.             *obp++ = ' ';
  3096.               }
  3097.               ibp += 2;
  3098.               while (ibp + 1 != limit
  3099.                  && !(ibp[0] == '*' && ibp[1] == '/')) {
  3100.             /* We need not worry about newline-marks,
  3101.                since they are never found in comments.  */
  3102.             if (*ibp == '\n') {
  3103.               /* Newline in a file.  Count it.  */
  3104.               ++ip->lineno;
  3105.               ++op->lineno;
  3106.             }
  3107.             if (put_out_comments)
  3108.               *obp++ = *ibp++;
  3109.             else
  3110.               ibp++;
  3111.               }
  3112.               ibp += 2;
  3113.               if (put_out_comments) {
  3114.             *obp++ = '*';
  3115.             *obp++ = '/';
  3116.               }
  3117.             }
  3118.             else if (is_space[*ibp]) {
  3119.               *obp++ = *ibp++;
  3120.               if (ibp[-1] == '\n') {
  3121.             if (ip->macro == 0) {
  3122.               /* Newline in a file.  Count it.  */
  3123.               ++ip->lineno;
  3124.               ++op->lineno;
  3125.             } else if (!output_marks) {
  3126.               /* A newline mark, and we don't want marks
  3127.                  in the output.  If it is newline-hyphen,
  3128.                  discard it entirely.  Otherwise, it is
  3129.                  newline-whitechar, so keep the whitechar.  */
  3130.               obp--;
  3131.               if (*ibp == '-')
  3132.                 ibp++;
  3133.               else {
  3134.                 if (*ibp == '\n')
  3135.                   ++op->lineno;
  3136.                 *obp++ = *ibp++;
  3137.               }
  3138.             } else {
  3139.               /* A newline mark; copy both chars to the output.  */
  3140.               *obp++ = *ibp++;
  3141.             }
  3142.               }
  3143.             }
  3144.             else break;
  3145.           }
  3146.           if (*ibp != '(') {
  3147.             /* It isn't a macro call.
  3148.                Put back the space that we just skipped.  */
  3149.             ibp = old_ibp;
  3150.             obp = old_obp;
  3151.             ip->lineno = old_iln;
  3152.             op->lineno = old_oln;
  3153.             /* Exit the for loop.  */
  3154.             break;
  3155.           }
  3156.         }
  3157.           
  3158.           /* This is now known to be a macro call.
  3159.          Discard the macro name from the output,
  3160.          along with any following whitespace just copied.  */
  3161.           obp = op->buf + obufp_before_macroname;
  3162.           op->lineno = op_lineno_before_macroname;
  3163.  
  3164.           /* Prevent accidental token-pasting with a character
  3165.          before the macro call.  */
  3166.           if (!traditional && obp != op->buf
  3167.           && (obp[-1] == '-' || obp[1] == '+' || obp[1] == '&'
  3168.               || obp[-1] == '|' || obp[1] == '<' || obp[1] == '>')) {
  3169.         /* If we are expanding a macro arg, make a newline marker
  3170.            to separate the tokens.  If we are making real output,
  3171.            a plain space will do.  */
  3172.         if (output_marks)
  3173.           *obp++ = '\n';
  3174.         *obp++ = ' ';
  3175.           }
  3176.  
  3177.           /* Expand the macro, reading arguments as needed,
  3178.          and push the expansion on the input stack.  */
  3179.           ip->bufp = ibp;
  3180.           op->bufp = obp;
  3181.           macroexpand (hp, op);
  3182.           
  3183.           /* Reexamine input stack, since macroexpand has pushed
  3184.          a new level on it.  */
  3185.           obp = op->bufp;
  3186.           RECACHE;
  3187.           break;
  3188.         }
  3189. hashcollision:
  3190.         ;
  3191.       }            /* End hash-table-search loop */
  3192.     }
  3193.     ident_length = hash = 0; /* Stop collecting identifier */
  3194.     redo_char = 0;
  3195.     concatenated = 0;
  3196.       }                /* End if (ident_length > 0) */
  3197.     }                /* End switch */
  3198.   }                /* End per-char loop */
  3199.  
  3200.   /* Come here to return -- but first give an error message
  3201.      if there was an unterminated successful conditional.  */
  3202.  ending:
  3203.   if (if_stack != ip->if_stack) {
  3204.     char *str;
  3205.     switch (if_stack->type) {
  3206.     case T_IF:
  3207.       str = "if";
  3208.       break;
  3209.     case T_IFDEF:
  3210.       str = "ifdef";
  3211.       break;
  3212.     case T_IFNDEF:
  3213.       str = "ifndef";
  3214.       break;
  3215.     case T_ELSE:
  3216.       str = "else";
  3217.       break;
  3218.     case T_ELIF:
  3219.       str = "elif";
  3220.       break;
  3221.     }
  3222.     error_with_line (line_for_error (if_stack->lineno),
  3223.              "unterminated `#%s' conditional", str);
  3224.   }
  3225.   if_stack = ip->if_stack;
  3226. }
  3227.  
  3228. /*
  3229.  * Rescan a string into a temporary buffer and return the result
  3230.  * as a FILE_BUF.  Note this function returns a struct, not a pointer.
  3231.  *
  3232.  * OUTPUT_MARKS nonzero means keep Newline markers found in the input
  3233.  * and insert such markers when appropriate.  See `rescan' for details.
  3234.  * OUTPUT_MARKS is 1 for macroexpanding a macro argument separately
  3235.  * before substitution; it is 0 for other uses.
  3236.  */
  3237. static FILE_BUF
  3238. expand_to_temp_buffer (buf, limit, output_marks, assertions)
  3239.      U_CHAR *buf, *limit;
  3240.      int output_marks, assertions;
  3241. {
  3242.   register FILE_BUF *ip;
  3243.   FILE_BUF obuf;
  3244.   int length = limit - buf;
  3245.   U_CHAR *buf1;
  3246.   int odepth = indepth;
  3247.   int save_assertions_flag = assertions_flag;
  3248.  
  3249.   assertions_flag = assertions;
  3250.  
  3251.   if (length < 0)
  3252.     abort ();
  3253.  
  3254.   /* Set up the input on the input stack.  */
  3255.  
  3256.   buf1 = (U_CHAR *) alloca (length + 1);
  3257.   {
  3258.     register U_CHAR *p1 = buf;
  3259.     register U_CHAR *p2 = buf1;
  3260.  
  3261.     while (p1 != limit)
  3262.       *p2++ = *p1++;
  3263.   }
  3264.   buf1[length] = 0;
  3265.  
  3266.   /* Set up to receive the output.  */
  3267.  
  3268.   obuf.length = length * 2 + 100; /* Usually enough.  Why be stingy?  */
  3269.   obuf.bufp = obuf.buf = (U_CHAR *) xmalloc (obuf.length);
  3270.   obuf.fname = 0;
  3271.   obuf.macro = 0;
  3272.   obuf.free_ptr = 0;
  3273.  
  3274.   CHECK_DEPTH ({return obuf;});
  3275.  
  3276.   ++indepth;
  3277.  
  3278.   ip = &instack[indepth];
  3279.   ip->fname = 0;
  3280.   ip->nominal_fname = 0;
  3281.   ip->system_header_p = 0;
  3282.   ip->macro = 0;
  3283.   ip->free_ptr = 0;
  3284.   ip->length = length;
  3285.   ip->buf = ip->bufp = buf1;
  3286.   ip->if_stack = if_stack;
  3287.  
  3288.   ip->lineno = obuf.lineno = 1;
  3289.  
  3290.   /* Scan the input, create the output.  */
  3291.   rescan (&obuf, output_marks);
  3292.  
  3293.   /* Pop input stack to original state.  */
  3294.   --indepth;
  3295.  
  3296.   if (indepth != odepth)
  3297.     abort ();
  3298.  
  3299.   /* Record the output.  */
  3300.   obuf.length = obuf.bufp - obuf.buf;
  3301.  
  3302.   assertions_flag = save_assertions_flag;
  3303.   return obuf;
  3304. }
  3305.  
  3306. /*
  3307.  * Process a # directive.  Expects IP->bufp to point after the '#', as in
  3308.  * `#define foo bar'.  Passes to the command handler
  3309.  * (do_define, do_include, etc.): the addresses of the 1st and
  3310.  * last chars of the command (starting immediately after the #
  3311.  * keyword), plus op and the keyword table pointer.  If the command
  3312.  * contains comments it is copied into a temporary buffer sans comments
  3313.  * and the temporary buffer is passed to the command handler instead.
  3314.  * Likewise for backslash-newlines.
  3315.  *
  3316.  * Returns nonzero if this was a known # directive.
  3317.  * Otherwise, returns zero, without advancing the input pointer.
  3318.  */
  3319.  
  3320. static int
  3321. handle_directive (ip, op)
  3322.      FILE_BUF *ip, *op;
  3323. {
  3324.   register U_CHAR *bp, *cp;
  3325.   register struct directive *kt;
  3326.   register int ident_length;
  3327.   U_CHAR *resume_p;
  3328.  
  3329.   /* Nonzero means we must copy the entire command
  3330.      to get rid of comments or backslash-newlines.  */
  3331.   int copy_command = 0;
  3332.  
  3333.   U_CHAR *ident, *after_ident;
  3334.  
  3335.   bp = ip->bufp;
  3336.  
  3337.   /* Record where the directive started.  do_xifdef needs this.  */
  3338.   directive_start = bp - 1;
  3339.  
  3340.   /* Skip whitespace and \-newline.  */
  3341.   while (1) {
  3342.     if (is_hor_space[*bp]) {
  3343.       if ((*bp == '\f' || *bp == '\v') && pedantic)
  3344.     pedwarn ("%s in preprocessing directive",
  3345.          *bp == '\f' ? "formfeed" : "vertical tab");
  3346.       bp++;
  3347.     } else if (*bp == '/' && bp[1] == '*') {
  3348.       ip->bufp = bp;
  3349.       skip_to_end_of_comment (ip, &ip->lineno, 0);
  3350.       bp = ip->bufp;
  3351.     } else if (*bp == '\\' && bp[1] == '\n') {
  3352.       bp += 2; ip->lineno++;
  3353.     } else break;
  3354.   }
  3355.  
  3356.   /* Now find end of directive name.
  3357.      If we encounter a backslash-newline, exchange it with any following
  3358.      symbol-constituents so that we end up with a contiguous name.  */
  3359.  
  3360.   cp = bp;
  3361.   while (1) {
  3362.     if (is_idchar[*cp])
  3363.       cp++;
  3364.     else {
  3365.       if (*cp == '\\' && cp[1] == '\n')
  3366.     name_newline_fix (cp);
  3367.       if (is_idchar[*cp])
  3368.     cp++;
  3369.       else break;
  3370.     }
  3371.   }
  3372.   ident_length = cp - bp;
  3373.   ident = bp;
  3374.   after_ident = cp;
  3375.  
  3376.   /* A line of just `#' becomes blank.  */
  3377.  
  3378.   if (ident_length == 0 && *after_ident == '\n') {
  3379.     ip->bufp = after_ident;
  3380.     return 1;
  3381.   }
  3382.  
  3383.   if (ident_length == 0 || !is_idstart[*ident]) {
  3384.     U_CHAR *p = ident;
  3385.     while (is_idchar[*p]) {
  3386.       if (*p < '0' || *p > '9')
  3387.     break;
  3388.       p++;
  3389.     }
  3390.     /* Handle # followed by a line number.  */
  3391.     if (p != ident && !is_idchar[*p]) {
  3392.       static struct directive line_directive_table[] = {
  3393.     {  4, do_line, "line", T_LINE},
  3394.       };
  3395.       if (pedantic)
  3396.     pedwarn ("`#' followed by integer");
  3397.       after_ident = ident;
  3398.       kt = line_directive_table;
  3399.       goto old_linenum;
  3400.     }
  3401.  
  3402.     /* Avoid error for `###' and similar cases unless -pedantic.  */
  3403.     if (p == ident) {
  3404.       while (*p == '#' || is_hor_space[*p]) p++;
  3405.       if (*p == '\n') {
  3406.     if (pedantic && !lang_asm)
  3407.       warning ("invalid preprocessor directive");
  3408.     return 0;
  3409.       }
  3410.     }
  3411.  
  3412.     if (!lang_asm)
  3413.       error ("invalid preprocessor directive name");
  3414.  
  3415.     return 0;
  3416.   }
  3417.  
  3418.   /*
  3419.    * Decode the keyword and call the appropriate expansion
  3420.    * routine, after moving the input pointer up to the next line.
  3421.    */
  3422.   for (kt = directive_table; kt->length > 0; kt++) {
  3423.     if (kt->length == ident_length && !strncmp (kt->name, ident, ident_length)) {
  3424.       register U_CHAR *buf;
  3425.       register U_CHAR *limit;
  3426.       int unterminated;
  3427.       int junk;
  3428.       int *already_output;
  3429.  
  3430.       /* Nonzero means do not delete comments within the directive.
  3431.      #define needs this when -traditional.  */
  3432.       int keep_comments;
  3433.  
  3434.     old_linenum:
  3435.  
  3436.       limit = ip->buf + ip->length;
  3437.       unterminated = 0;
  3438.       already_output = 0;
  3439.       keep_comments = traditional && kt->traditional_comments;
  3440.       /* #import is defined only in Objective C, or when on the NeXT.  */
  3441.       if (kt->type == T_IMPORT && !(objc || lookup ("__NeXT__", -1, -1)))
  3442.     break;
  3443.  
  3444.       /* Find the end of this command (first newline not backslashed
  3445.      and not in a string or comment).
  3446.      Set COPY_COMMAND if the command must be copied
  3447.      (it contains a backslash-newline or a comment).  */
  3448.  
  3449.       buf = bp = after_ident;
  3450.       while (bp < limit) {
  3451.     register U_CHAR c = *bp++;
  3452.     switch (c) {
  3453.     case '\\':
  3454.       if (bp < limit) {
  3455.         if (*bp == '\n') {
  3456.           ip->lineno++;
  3457.           copy_command = 1;
  3458.         }
  3459.         bp++;
  3460.       }
  3461.       break;
  3462.  
  3463.     case '\'':
  3464.     case '\"':
  3465.       bp = skip_quoted_string (bp - 1, limit, ip->lineno, &ip->lineno, ©_command, &unterminated);
  3466.       /* Don't bother calling the directive if we already got an error
  3467.          message due to unterminated string.  Skip everything and pretend
  3468.          we called the directive.  */
  3469.       if (unterminated) {
  3470.         if (traditional) {
  3471.           /* Traditional preprocessing permits unterminated strings.  */
  3472.           ip->bufp = bp;
  3473.           goto endloop1;
  3474.         }
  3475.         ip->bufp = bp;
  3476.         return 1;
  3477.       }
  3478.       break;
  3479.  
  3480.       /* <...> is special for #include.  */
  3481.     case '<':
  3482.       if (!kt->angle_brackets)
  3483.         break;
  3484.       while (*bp && *bp != '>') bp++;
  3485.       break;
  3486.  
  3487.     case '/':
  3488.       if (*bp == '\\' && bp[1] == '\n')
  3489.         newline_fix (bp);
  3490.       if (*bp == '*'
  3491.           || (cplusplus_comments && *bp == '/')) {
  3492.         U_CHAR *obp = bp - 1;
  3493.         ip->bufp = bp + 1;
  3494.         skip_to_end_of_comment (ip, &ip->lineno, 0);
  3495.         bp = ip->bufp;
  3496.         /* No need to copy the command because of a comment at the end;
  3497.            just don't include the comment in the directive.  */
  3498.         if (bp == limit || *bp == '\n') {
  3499.           bp = obp;
  3500.           goto endloop1;
  3501.         }
  3502.         /* Don't remove the comments if -traditional.  */
  3503.         if (! keep_comments)
  3504.           copy_command++;
  3505.       }
  3506.       break;
  3507.  
  3508.     case '\f':
  3509.     case '\v':
  3510.       if (pedantic)
  3511.         pedwarn ("%s in preprocessing directive",
  3512.              c == '\f' ? "formfeed" : "vertical tab");
  3513.       break;
  3514.  
  3515.     case '\n':
  3516.       --bp;        /* Point to the newline */
  3517.       ip->bufp = bp;
  3518.       goto endloop1;
  3519.     }
  3520.       }
  3521.       ip->bufp = bp;
  3522.  
  3523.     endloop1:
  3524.       resume_p = ip->bufp;
  3525.       /* BP is the end of the directive.
  3526.      RESUME_P is the next interesting data after the directive.
  3527.      A comment may come between.  */
  3528.  
  3529.       /* If a directive should be copied through, and -E was given,
  3530.      pass it through before removing comments.  */
  3531.       if (!no_output && kt->pass_thru && put_out_comments) {
  3532.         int len;
  3533.  
  3534.     /* Output directive name.  */
  3535.         check_expand (op, kt->length + 2);
  3536.     /* Make sure # is at the start of a line */
  3537.     if (op->bufp > op->buf && op->bufp[-1] != '\n') {
  3538.       op->lineno++;
  3539.       *op->bufp++ = '\n';
  3540.     }
  3541.         *op->bufp++ = '#';
  3542.         bcopy (kt->name, op->bufp, kt->length);
  3543.         op->bufp += kt->length;
  3544.  
  3545.     /* Output arguments.  */
  3546.     len = (bp - buf);
  3547.     check_expand (op, len);
  3548.     bcopy (buf, op->bufp, len);
  3549.     op->bufp += len;
  3550.     /* Take account of any (escaped) newlines just output.  */
  3551.     while (--len >= 0)
  3552.       if (buf[len] == '\n')
  3553.         op->lineno++;
  3554.  
  3555.     already_output = &junk;
  3556.       }                /* Don't we need a newline or #line? */
  3557.  
  3558.       if (copy_command) {
  3559.     register U_CHAR *xp = buf;
  3560.     /* Need to copy entire command into temp buffer before dispatching */
  3561.  
  3562.     cp = (U_CHAR *) alloca (bp - buf + 5); /* room for cmd plus
  3563.                           some slop */
  3564.     buf = cp;
  3565.  
  3566.     /* Copy to the new buffer, deleting comments
  3567.        and backslash-newlines (and whitespace surrounding the latter).  */
  3568.  
  3569.     while (xp < bp) {
  3570.       register U_CHAR c = *xp++;
  3571.       *cp++ = c;
  3572.  
  3573.       switch (c) {
  3574.       case '\n':
  3575.         abort ();  /* A bare newline should never part of the line.  */
  3576.         break;
  3577.  
  3578.         /* <...> is special for #include.  */
  3579.       case '<':
  3580.         if (!kt->angle_brackets)
  3581.           break;
  3582.         while (xp < bp && c != '>') {
  3583.           c = *xp++;
  3584.           if (c == '\\' && xp < bp && *xp == '\n')
  3585.         xp++;
  3586.           else
  3587.         *cp++ = c;
  3588.         }
  3589.         break;
  3590.  
  3591.       case '\\':
  3592.         if (*xp == '\n') {
  3593.           xp++;
  3594.           cp--;
  3595.           if (cp != buf && is_space[cp[-1]]) {
  3596.         while (cp != buf && is_space[cp[-1]]) cp--;
  3597.         cp++;
  3598.         SKIP_WHITE_SPACE (xp);
  3599.           } else if (is_space[*xp]) {
  3600.         *cp++ = *xp++;
  3601.         SKIP_WHITE_SPACE (xp);
  3602.           }
  3603.         } else {
  3604.           *cp++ = *xp++;
  3605.         }
  3606.         break;
  3607.  
  3608.       case '\'':
  3609.       case '\"':
  3610.         {
  3611.           register U_CHAR *bp1
  3612.         = skip_quoted_string (xp - 1, bp, ip->lineno,
  3613.                       NULL_PTR, NULL_PTR, NULL_PTR);
  3614.           while (xp != bp1)
  3615.         if (*xp == '\\') {
  3616.           if (*++xp != '\n')
  3617.             *cp++ = '\\';
  3618.           else
  3619.             xp++;
  3620.         } else
  3621.           *cp++ = *xp++;
  3622.         }
  3623.         break;
  3624.  
  3625.       case '/':
  3626.         if (*xp == '*'
  3627.         || (cplusplus_comments && *xp == '/')) {
  3628.           ip->bufp = xp + 1;
  3629.           /* If we already copied the command through,
  3630.          already_output != 0 prevents outputting comment now.  */
  3631.           skip_to_end_of_comment (ip, already_output, 0);
  3632.           if (keep_comments)
  3633.         while (xp != ip->bufp)
  3634.           *cp++ = *xp++;
  3635.           /* Delete or replace the slash.  */
  3636.           else if (traditional)
  3637.         cp--;
  3638.           else
  3639.         cp[-1] = ' ';
  3640.           xp = ip->bufp;
  3641.         }
  3642.       }
  3643.     }
  3644.  
  3645.     /* Null-terminate the copy.  */
  3646.  
  3647.     *cp = 0;
  3648.       } else
  3649.     cp = bp;
  3650.  
  3651.       ip->bufp = resume_p;
  3652.  
  3653.       /* Some directives should be written out for cc1 to process,
  3654.      just as if they were not defined.  And sometimes we're copying
  3655.      definitions through.  */
  3656.  
  3657.       if (!no_output && already_output == 0
  3658.       && (kt->pass_thru
  3659.           || ((kt->type == T_DEFINE || kt->type == T_UNDEF)
  3660.           && (dump_macros == dump_names
  3661.               || dump_macros == dump_definitions)))) {
  3662.         int len;
  3663.  
  3664.     /* Output directive name.  */
  3665.         check_expand (op, kt->length + 1);
  3666.         *op->bufp++ = '#';
  3667.         bcopy (kt->name, op->bufp, kt->length);
  3668.         op->bufp += kt->length;
  3669.  
  3670.     if (kt->pass_thru || dump_macros == dump_definitions) {
  3671.       /* Output arguments.  */
  3672.       len = (cp - buf);
  3673.       check_expand (op, len);
  3674.       bcopy (buf, op->bufp, len);
  3675.       op->bufp += len;
  3676.     } else if (kt->type == T_DEFINE && dump_macros == dump_names) {
  3677.       U_CHAR *xp = buf;
  3678.       U_CHAR *yp;
  3679.       SKIP_WHITE_SPACE (xp);
  3680.       yp = xp;
  3681.       while (is_idchar[*xp]) xp++;
  3682.       len = (xp - yp);
  3683.       check_expand (op, len + 1);
  3684.       *op->bufp++ = ' ';
  3685.       bcopy (yp, op->bufp, len);
  3686.       op->bufp += len;
  3687.     }
  3688.       }                /* Don't we need a newline or #line? */
  3689.  
  3690.       /* Call the appropriate command handler.  buf now points to
  3691.      either the appropriate place in the input buffer, or to
  3692.      the temp buffer if it was necessary to make one.  cp
  3693.      points to the first char after the contents of the (possibly
  3694.      copied) command, in either case. */
  3695.       (*kt->func) (buf, cp, op, kt);
  3696.       check_expand (op, ip->length - (ip->bufp - ip->buf));
  3697.  
  3698.       return 1;
  3699.     }
  3700.   }
  3701.  
  3702.   /* It is deliberate that we don't warn about undefined directives.
  3703.      That is the responsibility of cc1.  */
  3704.   return 0;
  3705. }
  3706.  
  3707. static struct tm *
  3708. timestamp ()
  3709. {
  3710.   static struct tm *timebuf;
  3711.   if (!timebuf) {
  3712.     time_t t = time (0);
  3713.     timebuf = localtime (&t);
  3714.   }
  3715.   return timebuf;
  3716. }
  3717.  
  3718. static char *monthnames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  3719.                  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
  3720.                 };
  3721.  
  3722. /*
  3723.  * expand things like __FILE__.  Place the expansion into the output
  3724.  * buffer *without* rescanning.
  3725.  */
  3726.  
  3727. static void
  3728. special_symbol (hp, op)
  3729.      HASHNODE *hp;
  3730.      FILE_BUF *op;
  3731. {
  3732.   char *buf;
  3733.   int i, len;
  3734.   int true_indepth;
  3735.   FILE_BUF *ip = NULL;
  3736.   struct tm *timebuf;
  3737.  
  3738.   int paren = 0;        /* For special `defined' keyword */
  3739.  
  3740.   if (pcp_outfile && pcp_inside_if
  3741.       && hp->type != T_SPEC_DEFINED && hp->type != T_CONST)
  3742.     error ("Predefined macro `%s' used inside `#if' during precompilation",
  3743.        hp->name);
  3744.     
  3745.   for (i = indepth; i >= 0; i--)
  3746.     if (instack[i].fname != NULL) {
  3747.       ip = &instack[i];
  3748.       break;
  3749.     }
  3750.   if (ip == NULL) {
  3751.     error ("cccp error: not in any file?!");
  3752.     return;            /* the show must go on */
  3753.   }
  3754.  
  3755.   switch (hp->type) {
  3756.   case T_FILE:
  3757.   case T_BASE_FILE:
  3758.     {
  3759.       char *string;
  3760.       if (hp->type == T_FILE)
  3761.     string = ip->nominal_fname;
  3762.       else
  3763.     string = instack[0].nominal_fname;
  3764.  
  3765.       if (string)
  3766.     {
  3767.       buf = (char *) alloca (3 + 4 * strlen (string));
  3768.       quote_string (buf, string);
  3769.     }
  3770.       else
  3771.     buf = "\"\"";
  3772.  
  3773.       break;
  3774.     }
  3775.  
  3776.   case T_INCLUDE_LEVEL:
  3777.     true_indepth = 0;
  3778.     for (i = indepth; i >= 0; i--)
  3779.       if (instack[i].fname != NULL)
  3780.         true_indepth++;
  3781.  
  3782.     buf = (char *) alloca (8);    /* Eight bytes ought to be more than enough */
  3783.     sprintf (buf, "%d", true_indepth - 1);
  3784.     break;
  3785.  
  3786.   case T_VERSION:
  3787.     buf = (char *) alloca (3 + strlen (version_string));
  3788.     sprintf (buf, "\"%s\"", version_string);
  3789.     break;
  3790.  
  3791. #ifndef NO_BUILTIN_SIZE_TYPE
  3792.   case T_SIZE_TYPE:
  3793.     buf = (char *) alloca (3 + strlen (SIZE_TYPE));
  3794.     sprintf (buf, "%s", SIZE_TYPE);
  3795.     break;
  3796. #endif
  3797.  
  3798. #ifndef NO_BUILTIN_PTRDIFF_TYPE
  3799.   case T_PTRDIFF_TYPE:
  3800.     buf = (char *) alloca (3 + strlen (PTRDIFF_TYPE));
  3801.     sprintf (buf, "%s", PTRDIFF_TYPE);
  3802.     break;
  3803. #endif
  3804.  
  3805.   case T_WCHAR_TYPE:
  3806.     buf = (char *) alloca (3 + strlen (WCHAR_TYPE));
  3807.     sprintf (buf, "%s", WCHAR_TYPE);
  3808.     break;
  3809.  
  3810.   case T_USER_LABEL_PREFIX_TYPE:
  3811.     buf = (char *) alloca (3 + strlen (USER_LABEL_PREFIX));
  3812.     sprintf (buf, "%s", USER_LABEL_PREFIX);
  3813.     break;
  3814.  
  3815.   case T_REGISTER_PREFIX_TYPE:
  3816.     buf = (char *) alloca (3 + strlen (REGISTER_PREFIX));
  3817.     sprintf (buf, "%s", REGISTER_PREFIX);
  3818.     break;
  3819.  
  3820.   case T_CONST:
  3821.     buf = (char *) alloca (4 * sizeof (int));
  3822.     sprintf (buf, "%d", hp->value.ival);
  3823.     if (pcp_inside_if && pcp_outfile)
  3824.       /* Output a precondition for this macro use */
  3825.       fprintf (pcp_outfile, "#define %s %d\n", hp->name, hp->value.ival);
  3826.     break;
  3827.  
  3828.   case T_SPECLINE:
  3829.     buf = (char *) alloca (10);
  3830.     sprintf (buf, "%d", ip->lineno);
  3831.     break;
  3832.  
  3833.   case T_DATE:
  3834.   case T_TIME:
  3835.     buf = (char *) alloca (20);
  3836.     timebuf = timestamp ();
  3837.     if (hp->type == T_DATE)
  3838.       sprintf (buf, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon],
  3839.           timebuf->tm_mday, timebuf->tm_year + 1900);
  3840.     else
  3841.       sprintf (buf, "\"%02d:%02d:%02d\"", timebuf->tm_hour, timebuf->tm_min,
  3842.           timebuf->tm_sec);
  3843.     break;
  3844.  
  3845.   case T_SPEC_DEFINED:
  3846.     buf = " 0 ";        /* Assume symbol is not defined */
  3847.     ip = &instack[indepth];
  3848.     SKIP_WHITE_SPACE (ip->bufp);
  3849.     if (*ip->bufp == '(') {
  3850.       paren++;
  3851.       ip->bufp++;            /* Skip over the paren */
  3852.       SKIP_WHITE_SPACE (ip->bufp);
  3853.     }
  3854.  
  3855.     if (!is_idstart[*ip->bufp])
  3856.       goto oops;
  3857.     if (hp = lookup (ip->bufp, -1, -1)) {
  3858.       if (pcp_outfile && pcp_inside_if
  3859.       && hp->value.defn->predefined)
  3860.     /* Output a precondition for this macro use. */
  3861.     fprintf (pcp_outfile, "#define %s\n", hp->name);
  3862.       buf = " 1 ";
  3863.     }
  3864.     else
  3865.       if (pcp_outfile && pcp_inside_if)    {
  3866.     /* Output a precondition for this macro use */
  3867.     U_CHAR *cp = ip->bufp;
  3868.     fprintf (pcp_outfile, "#undef ");
  3869.     while (is_idchar[*cp]) /* Ick! */
  3870.       fputc (*cp++, pcp_outfile);
  3871.     putc ('\n', pcp_outfile);
  3872.       }
  3873.     while (is_idchar[*ip->bufp])
  3874.       ++ip->bufp;
  3875.     SKIP_WHITE_SPACE (ip->bufp);
  3876.     if (paren) {
  3877.       if (*ip->bufp != ')')
  3878.     goto oops;
  3879.       ++ip->bufp;
  3880.     }
  3881.     break;
  3882.  
  3883. oops:
  3884.  
  3885.     error ("`defined' without an identifier");
  3886.     break;
  3887.  
  3888.   default:
  3889.     error ("cccp error: invalid special hash type"); /* time for gdb */
  3890.     abort ();
  3891.   }
  3892.   len = strlen (buf);
  3893.   check_expand (op, len);
  3894.   bcopy (buf, op->bufp, len);
  3895.   op->bufp += len;
  3896.  
  3897.   return;
  3898. }
  3899.  
  3900.  
  3901. /* Routines to handle #directives */
  3902.  
  3903. /* Handle #include and #import.
  3904.    This function expects to see "fname" or <fname> on the input.  */
  3905.  
  3906. static int
  3907. do_include (buf, limit, op, keyword)
  3908.      U_CHAR *buf, *limit;
  3909.      FILE_BUF *op;
  3910.      struct directive *keyword;
  3911. {
  3912.   int importing = (keyword->type == T_IMPORT);
  3913.   int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
  3914.   static int import_warning = 0;
  3915.   char *fname;        /* Dynamically allocated fname buffer */
  3916.   char *pcftry;
  3917.   char *pcfname;
  3918.   U_CHAR *fbeg, *fend;        /* Beginning and end of fname */
  3919.  
  3920.   struct file_name_list *search_start = include; /* Chain of dirs to search */
  3921.   struct file_name_list dsp[1];    /* First in chain, if #include "..." */
  3922.   struct file_name_list *searchptr = 0;
  3923.   int flen;
  3924.  
  3925.   int f;            /* file number */
  3926.  
  3927.   int retried = 0;        /* Have already tried macro
  3928.                    expanding the include line*/
  3929.   FILE_BUF trybuf;        /* It got expanded into here */
  3930.   int angle_brackets = 0;    /* 0 for "...", 1 for <...> */
  3931.   int pcf = -1;
  3932.   char *pcfbuf;
  3933.   int pcfbuflimit;
  3934.   int pcfnum;
  3935.   f= -1;            /* JF we iz paranoid! */
  3936.  
  3937.   if (importing && warn_import && !inhibit_warnings
  3938.       && !instack[indepth].system_header_p && !import_warning) {
  3939.     import_warning = 1;
  3940.     warning ("using `#import' is not recommended");
  3941.     fprintf (stderr, "The fact that a certain header file need not be processed more than once\n");
  3942.     fprintf (stderr, "should be indicated in the header file, not where it is used.\n");
  3943.     fprintf (stderr, "The best way to do this is with a conditional of this form:\n\n");
  3944.     fprintf (stderr, "  #ifndef _FOO_H_INCLUDED\n");
  3945.     fprintf (stderr, "  #define _FOO_H_INCLUDED\n");
  3946.     fprintf (stderr, "  ... <real contents of file> ...\n");
  3947.     fprintf (stderr, "  #endif /* Not _FOO_H_INCLUDED */\n\n");
  3948.     fprintf (stderr, "Then users can use `#include' any number of times.\n");
  3949.     fprintf (stderr, "GNU C automatically avoids processing the file more than once\n");
  3950.     fprintf (stderr, "when it is equipped with such a conditional.\n");
  3951.   }
  3952.  
  3953. get_filename:
  3954.  
  3955.   fbeg = buf;
  3956.   SKIP_WHITE_SPACE (fbeg);
  3957.   /* Discard trailing whitespace so we can easily see
  3958.      if we have parsed all the significant chars we were given.  */
  3959.   while (limit != fbeg && is_hor_space[limit[-1]]) limit--;
  3960.  
  3961.   switch (*fbeg++) {
  3962.   case '\"':
  3963.     {
  3964.       FILE_BUF *fp;
  3965.       /* Copy the operand text, concatenating the strings.  */
  3966.       {
  3967.     U_CHAR *fin = fbeg;
  3968.     fbeg = (U_CHAR *) alloca (limit - fbeg + 1);
  3969.     fend = fbeg;
  3970.     while (fin != limit) {
  3971.       while (fin != limit && *fin != '\"')
  3972.         *fend++ = *fin++;
  3973.       fin++;
  3974.       if (fin == limit)
  3975.         break;
  3976.       /* If not at the end, there had better be another string.  */
  3977.       /* Skip just horiz space, and don't go past limit.  */
  3978.       while (fin != limit && is_hor_space[*fin]) fin++;
  3979.       if (fin != limit && *fin == '\"')
  3980.         fin++;
  3981.       else
  3982.         goto fail;
  3983.     }
  3984.       }
  3985.       *fend = 0;
  3986.  
  3987.       /* We have "filename".  Figure out directory this source
  3988.      file is coming from and put it on the front of the list. */
  3989.  
  3990.       /* If -I- was specified, don't search current dir, only spec'd ones. */
  3991.       if (ignore_srcdir) break;
  3992.  
  3993.       for (fp = &instack[indepth]; fp >= instack; fp--)
  3994.     {
  3995.       int n;
  3996.       char *ep,*nam;
  3997.  
  3998.       if ((nam = fp->nominal_fname) != NULL) {
  3999.         /* Found a named file.  Figure out dir of the file,
  4000.            and put it in front of the search list.  */
  4001.         dsp[0].next = search_start;
  4002.         search_start = dsp;
  4003. #ifndef VMS
  4004.         ep = rindex (nam, '/');
  4005.  
  4006. #ifdef amigados
  4007.         /* amigados uses unix-style directory-filename separation, but
  4008.            has VMS-style logicals as well */
  4009.  
  4010.         if (ep == NULL) 
  4011.           {
  4012.         ep = rindex (nam, ':');
  4013.         /* a ':' is part of the directory name, a '/' isn't ! */
  4014.             if (ep != NULL) ep++;
  4015.           }
  4016. #endif /* amigados */
  4017. #else                /* VMS */
  4018.         ep = rindex (nam, ']');
  4019.         if (ep == NULL) ep = rindex (nam, '>');
  4020.         if (ep == NULL) ep = rindex (nam, ':');
  4021.         if (ep != NULL) ep++;
  4022. #endif                /* VMS */
  4023.         if (ep != NULL) {
  4024.           n = ep - nam;
  4025.           dsp[0].fname = (char *) alloca (n + 1);
  4026.           strncpy (dsp[0].fname, nam, n);
  4027.           dsp[0].fname[n] = '\0';
  4028.           if (n + INCLUDE_LEN_FUDGE > max_include_len)
  4029.         max_include_len = n + INCLUDE_LEN_FUDGE;
  4030.         } else {
  4031.           dsp[0].fname = 0; /* Current directory */
  4032.         }
  4033.         break;
  4034.       }
  4035.     }
  4036.       break;
  4037.     }
  4038.  
  4039.   case '<':
  4040.     fend = fbeg;
  4041.     while (fend != limit && *fend != '>') fend++;
  4042.     if (*fend == '>' && fend + 1 == limit) {
  4043.       angle_brackets = 1;
  4044.       /* If -I-, start with the first -I dir after the -I-.  */
  4045.       if (first_bracket_include)
  4046.     search_start = first_bracket_include;
  4047.       break;
  4048.     }
  4049.     goto fail;
  4050.  
  4051.   default:
  4052.   fail:
  4053.     if (retried) {
  4054.       error ("`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
  4055.       return 0;
  4056.     } else {
  4057.       trybuf = expand_to_temp_buffer (buf, limit, 0, 0);
  4058.       buf = (U_CHAR *) alloca (trybuf.bufp - trybuf.buf + 1);
  4059.       bcopy (trybuf.buf, buf, trybuf.bufp - trybuf.buf);
  4060.       limit = buf + (trybuf.bufp - trybuf.buf);
  4061.       free (trybuf.buf);
  4062.       retried++;
  4063.       goto get_filename;
  4064.     }
  4065.   }
  4066.  
  4067.   /* For #include_next, skip in the search path
  4068.      past the dir in which the containing file was found.  */
  4069.   if (skip_dirs) {
  4070.     FILE_BUF *fp;
  4071.     for (fp = &instack[indepth]; fp >= instack; fp--)
  4072.       if (fp->fname != NULL) {
  4073.     /* fp->dir is null if the containing file was specified
  4074.        with an absolute file name.  In that case, don't skip anything.  */
  4075.     if (fp->dir)
  4076.       search_start = fp->dir->next;
  4077.     break;
  4078.       }
  4079.   }
  4080.  
  4081.   flen = fend - fbeg;
  4082.  
  4083.   if (flen == 0)
  4084.     {
  4085.       error ("empty file name in `#%s'", keyword->name);
  4086.       return 0;
  4087.     }
  4088.  
  4089.   /* Allocate this permanently, because it gets stored in the definitions
  4090.      of macros.  */
  4091.   fname = (char *) xmalloc (max_include_len + flen + 2);
  4092.   /* + 2 above for slash and terminating null.  */
  4093.  
  4094.   /* If specified file name is absolute, just open it.  */
  4095.  
  4096. #ifndef amigados
  4097.   if (*fbeg == '/') {
  4098. #else
  4099.   if (amigados_abs_filename (fbeg, flen)) {
  4100. #endif
  4101.     strncpy (fname, fbeg, flen);
  4102.     fname[flen] = 0;
  4103.     if (redundant_include_p (fname))
  4104.       return 0;
  4105.     if (importing)
  4106.       f = lookup_import (fname);
  4107.     else
  4108.       f = open (fname, O_RDONLY, 0666);
  4109.     if (f == -2)
  4110.       return 0;        /* Already included this file */
  4111.   } else {
  4112.     /* Search directory path, trying to open the file.
  4113.        Copy each filename tried into FNAME.  */
  4114.  
  4115.     for (searchptr = search_start; searchptr; searchptr = searchptr->next) {
  4116.       if (searchptr->fname) {
  4117.     /* The empty string in a search path is ignored.
  4118.        This makes it possible to turn off entirely
  4119.        a standard piece of the list.  */
  4120.     if (searchptr->fname[0] == 0)
  4121.       continue;
  4122.     strcpy (fname, searchptr->fname);
  4123.  
  4124. #ifdef amigados
  4125.     if (fname[strlen (fname) - 1] != ':')
  4126. #endif
  4127.     strcat (fname, "/");
  4128.     fname[strlen (fname) + flen] = 0;
  4129.       } else {
  4130.     fname[0] = 0;
  4131.       }
  4132.       strncat (fname, fbeg, flen);
  4133. #ifdef VMS
  4134.       /* Change this 1/2 Unix 1/2 VMS file specification into a
  4135.          full VMS file specification */
  4136.       if (searchptr->fname && (searchptr->fname[0] != 0)) {
  4137.     /* Fix up the filename */
  4138.     hack_vms_include_specification (fname);
  4139.       } else {
  4140.           /* This is a normal VMS filespec, so use it unchanged.  */
  4141.     strncpy (fname, fbeg, flen);
  4142.     fname[flen] = 0;
  4143.       }
  4144. #endif /* VMS */
  4145.       if (importing)
  4146.     f = lookup_import (fname);
  4147.       else
  4148.     f = open (fname, O_RDONLY, 0666);
  4149.       if (f == -2)
  4150.     return 0;            /* Already included this file */
  4151. #ifdef EACCES
  4152.       else if (f == -1 && errno == EACCES)
  4153.     warning ("Header file %s exists, but is not readable", fname);
  4154. #endif
  4155.       if (redundant_include_p (fname)) {
  4156.     close (f);
  4157.     return 0;
  4158.       }
  4159.       if (f >= 0)
  4160.     break;
  4161.     }
  4162.   }
  4163.  
  4164.   if (f < 0) {
  4165.     /* A file that was not found.  */
  4166.  
  4167.     strncpy (fname, fbeg, flen);
  4168.     fname[flen] = 0;
  4169.     /* If -M was specified, and this header file won't be added to the
  4170.        dependency list, then don't count this as an error, because we can
  4171.        still produce correct output.  Otherwise, we can't produce correct
  4172.        output, because there may be dependencies we need inside the missing
  4173.        file, and we don't know what directory this missing file exists in.  */
  4174.     if (print_deps
  4175.     && (print_deps <= (angle_brackets || (system_include_depth > 0))))
  4176.       warning ("No include path in which to find %s", fname);
  4177.     else if (search_start)
  4178.       error_from_errno (fname);
  4179.     else
  4180.       error ("No include path in which to find %s", fname);
  4181.   } else {
  4182.     struct stat stat_f;
  4183.  
  4184.     /* Check to see if this include file is a once-only include file.
  4185.        If so, give up.  */
  4186.  
  4187.     struct file_name_list* ptr;
  4188.  
  4189.     for (ptr = dont_repeat_files; ptr; ptr = ptr->next) {
  4190.       if (!strcmp (ptr->fname, fname)) {
  4191.     close (f);
  4192.         return 0;                /* This file was once'd. */
  4193.       }
  4194.     }
  4195.  
  4196.     for (ptr = all_include_files; ptr; ptr = ptr->next) {
  4197.       if (!strcmp (ptr->fname, fname))
  4198.         break;                /* This file was included before. */
  4199.     }
  4200.  
  4201.     if (ptr == 0) {
  4202.       /* This is the first time for this file.  */
  4203.       /* Add it to list of files included.  */
  4204.  
  4205.       ptr = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
  4206.       ptr->control_macro = 0;
  4207.       ptr->c_system_include_path = 0;
  4208.       ptr->next = all_include_files;
  4209.       all_include_files = ptr;
  4210.       ptr->fname = savestring (fname);
  4211.  
  4212.       /* For -M, add this file to the dependencies.  */
  4213.       if (print_deps > (angle_brackets || (system_include_depth > 0))) {
  4214.     deps_output ("", 0);
  4215.     deps_output (fname, 0);
  4216.     deps_output (" ", 0);
  4217.       }
  4218.     }   
  4219.  
  4220.     /* Handle -H option.  */
  4221.     if (print_include_names) {
  4222.       output_dots (stderr, indepth);
  4223.       fprintf (stderr, "%s\n", fname);
  4224.     }
  4225.  
  4226.     if (angle_brackets)
  4227.       system_include_depth++;
  4228.  
  4229.     /* Actually process the file.  */
  4230.     add_import (f, fname);    /* Record file on "seen" list for #import. */
  4231.  
  4232.     pcftry = (char *) alloca (strlen (fname) + 30);
  4233.     pcfbuf = 0;
  4234.     pcfnum = 0;
  4235.  
  4236.     fstat (f, &stat_f);
  4237.  
  4238.     if (!no_precomp)
  4239.       do {
  4240.     sprintf (pcftry, "%s%d", fname, pcfnum++);
  4241.     
  4242.     pcf = open (pcftry, O_RDONLY, 0666);
  4243.     if (pcf != -1)
  4244.       {
  4245.         struct stat s;
  4246.  
  4247.         fstat (pcf, &s);
  4248.         if (bcmp (&stat_f.st_ino, &s.st_ino, sizeof (s.st_ino))
  4249.         || stat_f.st_dev != s.st_dev)
  4250.           {
  4251.         pcfbuf = check_precompiled (pcf, fname, &pcfbuflimit);
  4252.         /* Don't need it any more.  */
  4253.         close (pcf);
  4254.           }
  4255.         else
  4256.           {
  4257.         /* Don't need it at all.  */
  4258.         close (pcf);
  4259.         break;
  4260.           }
  4261.       }
  4262.       } while (pcf != -1 && !pcfbuf);
  4263.     
  4264.     /* Actually process the file */
  4265.     if (pcfbuf) {
  4266.       pcfname = xmalloc (strlen (pcftry) + 1);
  4267.       strcpy (pcfname, pcftry);
  4268.       pcfinclude (pcfbuf, pcfbuflimit, fname, op);
  4269.     }
  4270.     else
  4271.       finclude (f, fname, op, is_system_include (fname), searchptr);
  4272.  
  4273.     if (angle_brackets)
  4274.       system_include_depth--;
  4275.   }
  4276.   return 0;
  4277. }
  4278.  
  4279. /* Return nonzero if there is no need to include file NAME
  4280.    because it has already been included and it contains a conditional
  4281.    to make a repeated include do nothing.  */
  4282.  
  4283. static int
  4284. redundant_include_p (name)
  4285.      char *name;
  4286. {
  4287.   struct file_name_list *l = all_include_files;
  4288.   for (; l; l = l->next)
  4289.     if (! strcmp (name, l->fname)
  4290.     && l->control_macro
  4291.     && lookup (l->control_macro, -1, -1))
  4292.       return 1;
  4293.   return 0;
  4294. }
  4295.  
  4296. /* Return nonzero if the given FILENAME is an absolute pathname which
  4297.    designates a file within one of the known "system" include file
  4298.    directories.  We assume here that if the given FILENAME looks like
  4299.    it is the name of a file which resides either directly in a "system"
  4300.    include file directory, or within any subdirectory thereof, then the
  4301.    given file must be a "system" include file.  This function tells us
  4302.    if we should suppress pedantic errors/warnings for the given FILENAME.
  4303.  
  4304.    The value is 2 if the file is a C-language system header file
  4305.    for which C++ should (on most systems) assume `extern "C"'.  */
  4306.  
  4307. static int
  4308. is_system_include (filename)
  4309.     register char *filename;
  4310. {
  4311.   struct file_name_list *searchptr;
  4312.  
  4313.   for (searchptr = first_system_include; searchptr;
  4314.        searchptr = searchptr->next)
  4315.     if (searchptr->fname) {
  4316.       register char *sys_dir = searchptr->fname;
  4317.       register unsigned length = strlen (sys_dir);
  4318.  
  4319.       if (! strncmp (sys_dir, filename, length) && filename[length] == '/')
  4320.     {
  4321.       if (searchptr->c_system_include_path)
  4322.         return 2;
  4323.       else
  4324.         return 1;
  4325.     }
  4326.     }
  4327.   return 0;
  4328. }
  4329.  
  4330. /* Process the contents of include file FNAME, already open on descriptor F,
  4331.    with output to OP.
  4332.    SYSTEM_HEADER_P is 1 if this file resides in any one of the known
  4333.    "system" include directories (as decided by the `is_system_include'
  4334.    function above).
  4335.    DIRPTR is the link in the dir path through which this file was found,
  4336.    or 0 if the file name was absolute.  */
  4337.  
  4338. static void
  4339. finclude (f, fname, op, system_header_p, dirptr)
  4340.      int f;
  4341.      char *fname;
  4342.      FILE_BUF *op;
  4343.      int system_header_p;
  4344.      struct file_name_list *dirptr;
  4345. {
  4346.   int st_mode;
  4347.   long st_size;
  4348.   long i;
  4349.   FILE_BUF *fp;            /* For input stack frame */
  4350.   int missing_newline = 0;
  4351.  
  4352.   CHECK_DEPTH (return;);
  4353.  
  4354.   if (file_size_and_mode (f, &st_mode, &st_size) < 0)
  4355.     {
  4356.       perror_with_name (fname);
  4357.       close (f);
  4358.       return;
  4359.     }
  4360.  
  4361.   fp = &instack[indepth + 1];
  4362.   bzero (fp, sizeof (FILE_BUF));
  4363.   fp->nominal_fname = fp->fname = fname;
  4364.   fp->length = 0;
  4365.   fp->lineno = 1;
  4366.   fp->if_stack = if_stack;
  4367.   fp->system_header_p = system_header_p;
  4368.   fp->dir = dirptr;
  4369.  
  4370.   if (S_ISREG (st_mode)) {
  4371.     fp->buf = (U_CHAR *) xmalloc (st_size + 2);
  4372.     fp->bufp = fp->buf;
  4373.  
  4374.     /* Read the file contents, knowing that st_size is an upper bound
  4375.        on the number of bytes we can read.  */
  4376.     while (st_size > 0) {
  4377.       i = safe_read (f, fp->buf + fp->length, st_size);
  4378.       if (i <= 0) {
  4379.     if (i == 0) break;
  4380.     goto nope;
  4381.       }
  4382.       fp->length += i;
  4383.       st_size -= i;
  4384.     }
  4385.   }
  4386.   else if (S_ISDIR (st_mode)) {
  4387.     error ("directory `%s' specified in #include", fname);
  4388.     close (f);
  4389.     return;
  4390.   } else {
  4391.     /* Cannot count its file size before reading.
  4392.        First read the entire file into heap and
  4393.        copy them into buffer on stack. */
  4394.  
  4395.     U_CHAR *bufp;
  4396.     U_CHAR *basep;
  4397.     int bsize = 2000;
  4398.  
  4399.     st_size = 0;
  4400.     basep = (U_CHAR *) xmalloc (bsize + 2);
  4401.     fp->buf = basep; /* So it will get freed, on error.  */
  4402.     bufp = basep;
  4403.  
  4404.     for (;;) {
  4405.       i = safe_read (f, bufp, bsize - st_size);
  4406.       if (i < 0)
  4407.     goto nope;      /* error! */
  4408.       if (i == 0)
  4409.     break;    /* End of file */
  4410.       st_size += i;
  4411.       bufp += i;
  4412.       if (bsize == st_size) {    /* Buffer is full! */
  4413.       bsize *= 2;
  4414.       basep = (U_CHAR *) xrealloc (basep, bsize + 2);
  4415.       fp->buf = basep;
  4416.       bufp = basep + st_size;    /* May have moved */
  4417.     }
  4418.     }
  4419.     fp->bufp = fp->buf;
  4420.     fp->length = st_size;
  4421.   }
  4422.  
  4423.   if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n')
  4424.       /* Backslash-newline at end is not good enough.  */
  4425.       || (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) {
  4426.     fp->buf[fp->length++] = '\n';
  4427.     missing_newline = 1;
  4428.   }
  4429.   fp->buf[fp->length] = '\0';
  4430.  
  4431.   /* Close descriptor now, so nesting does not use lots of descriptors.  */
  4432.   close (f);
  4433.  
  4434.   /* Must do this before calling trigraph_pcp, so that the correct file name
  4435.      will be printed in warning messages.  */
  4436.  
  4437.   indepth++;
  4438.   input_file_stack_tick++;
  4439.  
  4440.   if (!no_trigraphs)
  4441.     trigraph_pcp (fp);
  4442.  
  4443.   output_line_command (fp, op, 0, enter_file);
  4444.   rescan (op, 0);
  4445.  
  4446.   if (missing_newline)
  4447.     fp->lineno--;
  4448.  
  4449.   if (pedantic && missing_newline)
  4450.     pedwarn ("file does not end in newline");
  4451.  
  4452.   indepth--;
  4453.   input_file_stack_tick++;
  4454.   output_line_command (&instack[indepth], op, 0, leave_file);
  4455.   free (fp->buf);
  4456.   return;
  4457.  
  4458.  nope:
  4459.  
  4460.   perror_with_name (fname);
  4461.   close (f);
  4462.   free (fp->buf);
  4463. }
  4464.  
  4465. /* Record that inclusion of the file named FILE
  4466.    should be controlled by the macro named MACRO_NAME.
  4467.    This means that trying to include the file again
  4468.    will do something if that macro is defined.  */
  4469.  
  4470. static void
  4471. record_control_macro (file, macro_name)
  4472.      char *file;
  4473.      U_CHAR *macro_name;
  4474. {
  4475.   struct file_name_list *new;
  4476.  
  4477.   for (new = all_include_files; new; new = new->next) {
  4478.     if (!strcmp (new->fname, file)) {
  4479.       new->control_macro = macro_name;
  4480.       return;
  4481.     }
  4482.   }
  4483.  
  4484.   /* If the file is not in all_include_files, something's wrong.  */
  4485.   abort ();
  4486. }
  4487.  
  4488. /* Maintain and search list of included files, for #import.  */
  4489.  
  4490. #define IMPORT_HASH_SIZE 31
  4491.  
  4492. struct import_file {
  4493.   char *name;
  4494.   ino_t inode;
  4495.   dev_t dev;
  4496.   struct import_file *next;
  4497. };
  4498.  
  4499. /* Hash table of files already included with #include or #import.  */
  4500.  
  4501. static struct import_file *import_hash_table[IMPORT_HASH_SIZE];
  4502.  
  4503. /* Hash a file name for import_hash_table.  */
  4504.  
  4505. static int 
  4506. import_hash (f)
  4507.      char *f;
  4508. {
  4509.   int val = 0;
  4510.  
  4511.   while (*f) val += *f++;
  4512.   return (val%IMPORT_HASH_SIZE);
  4513. }
  4514.  
  4515. /* Search for file FILENAME in import_hash_table.
  4516.    Return -2 if found, either a matching name or a matching inode.
  4517.    Otherwise, open the file and return a file descriptor if successful
  4518.    or -1 if unsuccessful.  */
  4519.  
  4520. static int
  4521. lookup_import (filename)
  4522.      char *filename;
  4523. {
  4524.   struct import_file *i;
  4525.   int h;
  4526.   int hashval;
  4527.   struct stat sb;
  4528.   int fd;
  4529.  
  4530.   hashval = import_hash (filename);
  4531.  
  4532.   /* Attempt to find file in list of already included files */
  4533.   i = import_hash_table[hashval];
  4534.  
  4535.   while (i) {
  4536.     if (!strcmp (filename, i->name))
  4537.       return -2;        /* return found */
  4538.     i = i->next;
  4539.   }
  4540.   /* Open it and try a match on inode/dev */
  4541.   fd = open (filename, O_RDONLY, 0666);
  4542.   if (fd < 0)
  4543.     return fd;
  4544.   fstat (fd, &sb);
  4545.   for (h = 0; h < IMPORT_HASH_SIZE; h++) {
  4546.     i = import_hash_table[h];
  4547.     while (i) {
  4548.       /* Compare the inode and the device.
  4549.      Supposedly on some systems the inode is not a scalar.  */
  4550.       if (!bcmp (&i->inode, &sb.st_ino, sizeof (sb.st_ino))
  4551.       && i->dev == sb.st_dev) {
  4552.         close (fd);
  4553.         return -2;        /* return found */
  4554.       }
  4555.       i = i->next;
  4556.     }
  4557.   }
  4558.   return fd;            /* Not found, return open file */
  4559. }
  4560.  
  4561. /* Add the file FNAME, open on descriptor FD, to import_hash_table.  */
  4562.  
  4563. static void
  4564. add_import (fd, fname)
  4565.      int fd;
  4566.      char *fname;
  4567. {
  4568.   struct import_file *i;
  4569.   int hashval;
  4570.   struct stat sb;
  4571.  
  4572.   hashval = import_hash (fname);
  4573.   fstat (fd, &sb);
  4574.   i = (struct import_file *)xmalloc (sizeof (struct import_file));
  4575.   i->name = (char *)xmalloc (strlen (fname)+1);
  4576.   strcpy (i->name, fname);
  4577.   bcopy (&sb.st_ino, &i->inode, sizeof (sb.st_ino));
  4578.   i->dev = sb.st_dev;
  4579.   i->next = import_hash_table[hashval];
  4580.   import_hash_table[hashval] = i;
  4581. }
  4582.  
  4583. /* Load the specified precompiled header into core, and verify its
  4584.    preconditions.  PCF indicates the file descriptor to read, which must
  4585.    be a regular file.  FNAME indicates the file name of the original 
  4586.    header.  *LIMIT will be set to an address one past the end of the file.
  4587.    If the preconditions of the file are not satisfied, the buffer is 
  4588.    freed and we return 0.  If the preconditions are satisfied, return
  4589.    the address of the buffer following the preconditions.  The buffer, in
  4590.    this case, should never be freed because various pieces of it will
  4591.    be referred to until all precompiled strings are output at the end of
  4592.    the run.
  4593. */
  4594. static char *
  4595. check_precompiled (pcf, fname, limit)
  4596.      int pcf;
  4597.      char *fname;
  4598.      char **limit;
  4599. {
  4600.   int st_mode;
  4601.   long st_size;
  4602.   int length = 0;
  4603.   char *buf;
  4604.   char *dollar_loc;
  4605.   int i;
  4606.   char *cp;
  4607.  
  4608.   if (pcp_outfile)
  4609.     return 0;
  4610.   
  4611.   if (file_size_and_mode (pcf, &st_mode, &st_size) < 0)
  4612.     return 0;
  4613.  
  4614.   if (S_ISREG (st_mode))
  4615.     {
  4616.       buf = xmalloc (st_size + 2);
  4617.       while (st_size > 0)
  4618.     {
  4619.       i = safe_read (pcf, buf + length, st_size);
  4620.       if (i < 0)
  4621.         goto nope;
  4622.       if (i == 0)
  4623.         break;
  4624.       length += i;
  4625.       st_size -= i;
  4626.     }      
  4627.     }
  4628.   else
  4629.     abort ();
  4630.     
  4631.   if (length > 0 && buf[length-1] != '\n')
  4632.     buf[length++] = '\n';
  4633.   buf[length] = '\0';
  4634.   
  4635.   *limit = buf + length;
  4636.  
  4637.   /* File is in core.  Check the preconditions. */
  4638.   if (!check_preconditions (buf))
  4639.     goto nope;
  4640.   for (cp = buf; *cp; cp++)
  4641.     ;
  4642. #ifdef DEBUG_PCP
  4643.   fprintf (stderr, "Using preinclude %s\n", fname);
  4644. #endif
  4645.   return cp + 1;
  4646.  
  4647.  nope:
  4648. #ifdef DEBUG_PCP
  4649.   fprintf (stderr, "Cannot use preinclude %s\n", fname);
  4650. #endif
  4651.   free (buf);
  4652.   return 0;
  4653. }
  4654.  
  4655. /* PREC (null terminated) points to the preconditions of a
  4656.    precompiled header.  These are a series of #define and #undef
  4657.    lines which must match the current contents of the hash
  4658.    table.  */
  4659. static int 
  4660. check_preconditions (prec)
  4661.      char *prec;
  4662. {
  4663.   MACRODEF mdef;
  4664.   char *lineend;
  4665.   
  4666.   while (*prec) {
  4667.     lineend = (char *) index (prec, '\n');
  4668.     
  4669.     if (*prec++ != '#') {
  4670.       error ("Bad format encountered while reading precompiled file");
  4671.       return 0;
  4672.     }
  4673.     if (!strncmp (prec, "define", 6)) {
  4674.       HASHNODE *hp;
  4675.       
  4676.       prec += 6;
  4677.       mdef = create_definition (prec, lineend, NULL_PTR);
  4678.  
  4679.       if (mdef.defn == 0)
  4680.     abort ();
  4681.       
  4682.       if ((hp = lookup (mdef.symnam, mdef.symlen, -1)) == NULL
  4683.       || (hp->type != T_MACRO && hp->type != T_CONST)
  4684.       || (hp->type == T_MACRO
  4685.           && !compare_defs (mdef.defn, hp->value.defn)
  4686.           && (mdef.defn->length != 2
  4687.           || mdef.defn->expansion[0] != '\n'
  4688.           || mdef.defn->expansion[1] != ' ')))
  4689.     return 0;
  4690.     } else if (!strncmp (prec, "undef", 5)) {
  4691.       char *name;
  4692.       int len;
  4693.       
  4694.       prec += 5;
  4695.       while (is_hor_space[(U_CHAR) *prec])
  4696.     prec++;
  4697.       name = prec;
  4698.       while (is_idchar[(U_CHAR) *prec])
  4699.     prec++;
  4700.       len = prec - name;
  4701.       
  4702.       if (lookup (name, len, -1))
  4703.     return 0;
  4704.     } else {
  4705.       error ("Bad format encountered while reading precompiled file");
  4706.       return 0;
  4707.     }
  4708.     prec = lineend + 1;
  4709.   }
  4710.   /* They all passed successfully */
  4711.   return 1;
  4712. }
  4713.  
  4714. /* Process the main body of a precompiled file.  BUF points to the
  4715.    string section of the file, following the preconditions.  LIMIT is one
  4716.    character past the end.  NAME is the name of the file being read
  4717.    in.  OP is the main output buffer */
  4718. static void
  4719. pcfinclude (buf, limit, name, op)
  4720.      U_CHAR *buf, *limit, *name;
  4721.      FILE_BUF *op;
  4722. {
  4723.   FILE_BUF tmpbuf;
  4724.   int nstrings;
  4725.   U_CHAR *cp = buf;
  4726.  
  4727.   /* First in the file comes 4 bytes indicating the number of strings, */
  4728.   /* in network byte order. (MSB first).  */
  4729.   nstrings = *cp++;
  4730.   nstrings = (nstrings << 8) | *cp++;
  4731.   nstrings = (nstrings << 8) | *cp++;
  4732.   nstrings = (nstrings << 8) | *cp++;
  4733.   
  4734.   /* Looping over each string... */
  4735.   while (nstrings--) {
  4736.     U_CHAR *string_start;
  4737.     U_CHAR *endofthiskey;
  4738.     STRINGDEF *str;
  4739.     int nkeys;
  4740.     
  4741.     /* Each string starts with a STRINGDEF structure (str), followed */
  4742.     /* by the text of the string (string_start) */
  4743.  
  4744.     /* First skip to a longword boundary */
  4745.     /* ??? Why a 4-byte boundary?  On all machines? */
  4746.     /* NOTE: This works correctly even if HOST_WIDE_INT
  4747.        is narrower than a pointer.
  4748.        Do not try risky measures here to get another type to use!
  4749.        Do not include gstddef.h or stddef.h--either one will fail!  */
  4750.     if ((HOST_WIDE_INT) cp & 3)
  4751.       cp += 4 - ((HOST_WIDE_INT) cp & 3);
  4752.     
  4753.     /* Now get the string. */
  4754.     str = (STRINGDEF *) cp;
  4755.     string_start = cp += sizeof (STRINGDEF);
  4756.     
  4757.     for (; *cp; cp++)        /* skip the string */
  4758.       ;
  4759.     
  4760.     /* We need to macro expand the string here to ensure that the
  4761.        proper definition environment is in place.  If it were only
  4762.        expanded when we find out it is needed, macros necessary for
  4763.        its proper expansion might have had their definitions changed. */
  4764.     tmpbuf = expand_to_temp_buffer (string_start, cp++, 0, 0);
  4765.     /* Lineno is already set in the precompiled file */
  4766.     str->contents = tmpbuf.buf;
  4767.     str->len = tmpbuf.length;
  4768.     str->writeflag = 0;
  4769.     str->filename = name;
  4770.     str->output_mark = outbuf.bufp - outbuf.buf;
  4771.     
  4772.     str->chain = 0;
  4773.     *stringlist_tailp = str;
  4774.     stringlist_tailp = &str->chain;
  4775.     
  4776.     /* Next comes a fourbyte number indicating the number of keys */
  4777.     /* for this string. */
  4778.     nkeys = *cp++;
  4779.     nkeys = (nkeys << 8) | *cp++;
  4780.     nkeys = (nkeys << 8) | *cp++;
  4781.     nkeys = (nkeys << 8) | *cp++;
  4782.  
  4783.     /* If this number is -1, then the string is mandatory. */
  4784.     if (nkeys == -1)
  4785.       str->writeflag = 1;
  4786.     else
  4787.       /* Otherwise, for each key, */
  4788.       for (; nkeys--; free (tmpbuf.buf), cp = endofthiskey + 1) {
  4789.     KEYDEF *kp = (KEYDEF *) cp;
  4790.     HASHNODE *hp;
  4791.     
  4792.     /* It starts with a KEYDEF structure */
  4793.     cp += sizeof (KEYDEF);
  4794.     
  4795.     /* Find the end of the key.  At the end of this for loop we
  4796.        advance CP to the start of the next key using this variable. */
  4797.     endofthiskey = cp + strlen (cp);
  4798.     kp->str = str;
  4799.     
  4800.     /* Expand the key, and enter it into the hash table. */
  4801.     tmpbuf = expand_to_temp_buffer (cp, endofthiskey, 0, 0);
  4802.     tmpbuf.bufp = tmpbuf.buf;
  4803.     
  4804.     while (is_hor_space[*tmpbuf.bufp])
  4805.       tmpbuf.bufp++;
  4806.     if (!is_idstart[*tmpbuf.bufp]
  4807.         || tmpbuf.bufp == tmpbuf.buf + tmpbuf.length) {
  4808.       str->writeflag = 1;
  4809.       continue;
  4810.     }
  4811.         
  4812.     hp = lookup (tmpbuf.bufp, -1, -1);
  4813.     if (hp == NULL) {
  4814.       kp->chain = 0;
  4815.       install (tmpbuf.bufp, -1, T_PCSTRING, 0, (char *) kp, -1);
  4816.     }
  4817.     else if (hp->type == T_PCSTRING) {
  4818.       kp->chain = hp->value.keydef;
  4819.       hp->value.keydef = kp;
  4820.     }
  4821.     else
  4822.       str->writeflag = 1;
  4823.       }
  4824.   }
  4825.   /* This output_line_command serves to switch us back to the current
  4826.      input file in case some of these strings get output (which will 
  4827.      result in line commands for the header file being output). */
  4828.   output_line_command (&instack[indepth], op, 0, enter_file);
  4829. }
  4830.  
  4831. /* Called from rescan when it hits a key for strings.  Mark them all */
  4832.  /* used and clean up. */
  4833. static void
  4834. pcstring_used (hp)
  4835.      HASHNODE *hp;
  4836. {
  4837.   KEYDEF *kp, *tmp;
  4838.   
  4839.   for (kp = hp->value.keydef; kp; kp = kp->chain)
  4840.     kp->str->writeflag = 1;
  4841.   delete_macro (hp);
  4842. }
  4843.  
  4844. /* Write the output, interspersing precompiled strings in their */
  4845.  /* appropriate places. */
  4846. static void
  4847. write_output ()
  4848. {
  4849.   STRINGDEF *next_string;
  4850.   U_CHAR *cur_buf_loc;
  4851.   int line_command_len = 80;
  4852.   char *line_command = xmalloc (line_command_len);
  4853.   int len;
  4854.   int written;
  4855.  
  4856.   /* In each run through the loop, either cur_buf_loc == */
  4857.   /* next_string_loc, in which case we print a series of strings, or */
  4858.   /* it is less than next_string_loc, in which case we write some of */
  4859.   /* the buffer. */
  4860.   cur_buf_loc = outbuf.buf; 
  4861.   next_string = stringlist;
  4862.   
  4863.   while (cur_buf_loc < outbuf.bufp || next_string) {
  4864.     if (next_string
  4865.     && cur_buf_loc - outbuf.buf == next_string->output_mark) {
  4866.       if (next_string->writeflag) {
  4867.     len = 4 * strlen (next_string->filename) + 32;
  4868.     while (len > line_command_len)
  4869.       line_command = xrealloc (line_command, 
  4870.                    line_command_len *= 2);
  4871.     sprintf (line_command, "\n# %d ", next_string->lineno);
  4872.     strcpy (quote_string (line_command + strlen (line_command),
  4873.                       next_string->filename),
  4874.         "\n");
  4875.     safe_write (fileno (stdout), line_command, strlen (line_command));
  4876.     safe_write (fileno (stdout), next_string->contents, next_string->len);
  4877.       }          
  4878.       next_string = next_string->chain;
  4879.     }
  4880.     else {
  4881.       len = (next_string
  4882.          ? (next_string->output_mark 
  4883.         - (cur_buf_loc - outbuf.buf))
  4884.          : outbuf.bufp - cur_buf_loc);
  4885.       
  4886.       safe_write (fileno (stdout), cur_buf_loc, len);
  4887.       cur_buf_loc += len;
  4888.     }
  4889.   }
  4890.   free (line_command);
  4891. }
  4892.  
  4893. /* Pass a directive through to the output file.
  4894.    BUF points to the contents of the directive, as a contiguous string.
  4895.    LIMIT points to the first character past the end of the directive.
  4896.    KEYWORD is the keyword-table entry for the directive.  */
  4897.  
  4898. static void
  4899. pass_thru_directive (buf, limit, op, keyword)
  4900.      U_CHAR *buf, *limit;
  4901.      FILE_BUF *op;
  4902.      struct directive *keyword;
  4903. {
  4904.   register unsigned keyword_length = keyword->length;
  4905.  
  4906.   check_expand (op, 1 + keyword_length + (limit - buf));
  4907.   *op->bufp++ = '#';
  4908.   bcopy (keyword->name, op->bufp, keyword_length);
  4909.   op->bufp += keyword_length;
  4910.   if (limit != buf && buf[0] != ' ')
  4911.     *op->bufp++ = ' ';
  4912.   bcopy (buf, op->bufp, limit - buf);
  4913.   op->bufp += (limit - buf);
  4914. #if 0
  4915.   *op->bufp++ = '\n';
  4916.   /* Count the line we have just made in the output,
  4917.      to get in sync properly.  */
  4918.   op->lineno++;
  4919. #endif
  4920. }
  4921.  
  4922. /* The arglist structure is built by do_define to tell
  4923.    collect_definition where the argument names begin.  That
  4924.    is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist
  4925.    would contain pointers to the strings x, y, and z.
  4926.    Collect_definition would then build a DEFINITION node,
  4927.    with reflist nodes pointing to the places x, y, and z had
  4928.    appeared.  So the arglist is just convenience data passed
  4929.    between these two routines.  It is not kept around after
  4930.    the current #define has been processed and entered into the
  4931.    hash table. */
  4932.  
  4933. struct arglist {
  4934.   struct arglist *next;
  4935.   U_CHAR *name;
  4936.   int length;
  4937.   int argno;
  4938.   char rest_args;
  4939. };
  4940.  
  4941. /* Create a DEFINITION node from a #define directive.  Arguments are 
  4942.    as for do_define. */
  4943. static MACRODEF
  4944. create_definition (buf, limit, op)
  4945.      U_CHAR *buf, *limit;
  4946.      FILE_BUF *op;
  4947. {
  4948.   U_CHAR *bp;            /* temp ptr into input buffer */
  4949.   U_CHAR *symname;        /* remember where symbol name starts */
  4950.   int sym_length;        /* and how long it is */
  4951.   int line = instack[indepth].lineno;
  4952.   char *file = instack[indepth].nominal_fname;
  4953.   int rest_args = 0;
  4954.  
  4955.   DEFINITION *defn;
  4956.   int arglengths = 0;        /* Accumulate lengths of arg names
  4957.                    plus number of args.  */
  4958.   MACRODEF mdef;
  4959.  
  4960.   bp = buf;
  4961.  
  4962.   while (is_hor_space[*bp])
  4963.     bp++;
  4964.  
  4965.   symname = bp;            /* remember where it starts */
  4966.   sym_length = check_macro_name (bp, "macro");
  4967.   bp += sym_length;
  4968.  
  4969.   /* Lossage will occur if identifiers or control keywords are broken
  4970.      across lines using backslash.  This is not the right place to take
  4971.      care of that. */
  4972.  
  4973.   if (*bp == '(') {
  4974.     struct arglist *arg_ptrs = NULL;
  4975.     int argno = 0;
  4976.  
  4977.     bp++;            /* skip '(' */
  4978.     SKIP_WHITE_SPACE (bp);
  4979.  
  4980.     /* Loop over macro argument names.  */
  4981.     while (*bp != ')') {
  4982.       struct arglist *temp;
  4983.  
  4984.       temp = (struct arglist *) alloca (sizeof (struct arglist));
  4985.       temp->name = bp;
  4986.       temp->next = arg_ptrs;
  4987.       temp->argno = argno++;
  4988.       temp->rest_args = 0;
  4989.       arg_ptrs = temp;
  4990.  
  4991.       if (rest_args)
  4992.     pedwarn ("another parameter follows `%s'",
  4993.          rest_extension);
  4994.  
  4995.       if (!is_idstart[*bp])
  4996.     pedwarn ("invalid character in macro parameter name");
  4997.       
  4998.       /* Find the end of the arg name.  */
  4999.       while (is_idchar[*bp]) {
  5000.     bp++;
  5001.     /* do we have a "special" rest-args extension here? */
  5002.     if (limit - bp > REST_EXTENSION_LENGTH &&
  5003.         strncmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
  5004.       rest_args = 1;
  5005.       temp->rest_args = 1;
  5006.       break;
  5007.     }
  5008.       }
  5009.       temp->length = bp - temp->name;
  5010.       if (rest_args == 1)
  5011.     bp += REST_EXTENSION_LENGTH;
  5012.       arglengths += temp->length + 2;
  5013.       SKIP_WHITE_SPACE (bp);
  5014.       if (temp->length == 0 || (*bp != ',' && *bp != ')')) {
  5015.     error ("badly punctuated parameter list in `#define'");
  5016.     goto nope;
  5017.       }
  5018.       if (*bp == ',') {
  5019.     bp++;
  5020.     SKIP_WHITE_SPACE (bp);
  5021.       }
  5022.       if (bp >= limit) {
  5023.     error ("unterminated parameter list in `#define'");
  5024.     goto nope;
  5025.       }
  5026.       {
  5027.     struct arglist *otemp;
  5028.  
  5029.     for (otemp = temp->next; otemp != NULL; otemp = otemp->next)
  5030.       if (temp->length == otemp->length &&
  5031.         strncmp (temp->name, otemp->name, temp->length) == 0) {
  5032.           U_CHAR *name;
  5033.  
  5034.           name = (U_CHAR *) alloca (temp->length + 1);
  5035.           (void) strncpy (name, temp->name, temp->length);
  5036.           name[temp->length] = '\0';
  5037.           error ("duplicate argument name `%s' in `#define'", name);
  5038.           goto nope;
  5039.       }
  5040.       }
  5041.     }
  5042.  
  5043.     ++bp;            /* skip paren */
  5044.     /* Skip exactly one space or tab if any.  */
  5045.     if (bp < limit && (*bp == ' ' || *bp == '\t')) ++bp;
  5046.     /* now everything from bp before limit is the definition. */
  5047.     defn = collect_expansion (bp, limit, argno, arg_ptrs);
  5048.     defn->rest_args = rest_args;
  5049.  
  5050.     /* Now set defn->args.argnames to the result of concatenating
  5051.        the argument names in reverse order
  5052.        with comma-space between them.  */
  5053.     defn->args.argnames = (U_CHAR *) xmalloc (arglengths + 1);
  5054.     {
  5055.       struct arglist *temp;
  5056.       int i = 0;
  5057.       for (temp = arg_ptrs; temp; temp = temp->next) {
  5058.     bcopy (temp->name, &defn->args.argnames[i], temp->length);
  5059.     i += temp->length;
  5060.     if (temp->next != 0) {
  5061.       defn->args.argnames[i++] = ',';
  5062.       defn->args.argnames[i++] = ' ';
  5063.     }
  5064.       }
  5065.       defn->args.argnames[i] = 0;
  5066.     }
  5067.   } else {
  5068.     /* simple expansion or empty definition; gobble it */
  5069.     if (is_hor_space[*bp])
  5070.       ++bp;        /* skip exactly one blank/tab char */
  5071.     /* now everything from bp before limit is the definition. */
  5072.     defn = collect_expansion (bp, limit, -1, NULL_PTR);
  5073.     defn->args.argnames = (U_CHAR *) "";
  5074.   }
  5075.  
  5076.   defn->line = line;
  5077.   defn->file = file;
  5078.  
  5079.   /* OP is null if this is a predefinition */
  5080.   defn->predefined = !op;
  5081.   mdef.defn = defn;
  5082.   mdef.symnam = symname;
  5083.   mdef.symlen = sym_length;
  5084.  
  5085.   return mdef;
  5086.  
  5087.  nope:
  5088.   mdef.defn = 0;
  5089.   return mdef;
  5090. }
  5091.  
  5092. /* Process a #define command.
  5093. BUF points to the contents of the #define command, as a contiguous string.
  5094. LIMIT points to the first character past the end of the definition.
  5095. KEYWORD is the keyword-table entry for #define.  */
  5096.  
  5097. static int
  5098. do_define (buf, limit, op, keyword)
  5099.      U_CHAR *buf, *limit;
  5100.      FILE_BUF *op;
  5101.      struct directive *keyword;
  5102. {
  5103.   int hashcode;
  5104.   MACRODEF mdef;
  5105.  
  5106.   /* If this is a precompiler run (with -pcp) pass thru #define commands.  */
  5107.   if (pcp_outfile && op)
  5108.     pass_thru_directive (buf, limit, op, keyword);
  5109.  
  5110.   mdef = create_definition (buf, limit, op);
  5111.   if (mdef.defn == 0)
  5112.     goto nope;
  5113.  
  5114.   hashcode = hashf (mdef.symnam, mdef.symlen, HASHSIZE);
  5115.  
  5116.   {
  5117.     HASHNODE *hp;
  5118.     if ((hp = lookup (mdef.symnam, mdef.symlen, hashcode)) != NULL) {
  5119.       int ok = 0;
  5120.       /* Redefining a precompiled key is ok.  */
  5121.       if (hp->type == T_PCSTRING)
  5122.     ok = 1;
  5123.       /* Redefining a macro is ok if the definitions are the same.  */
  5124.       else if (hp->type == T_MACRO)
  5125.     ok = ! compare_defs (mdef.defn, hp->value.defn);
  5126.       /* Redefining a constant is ok with -D.  */
  5127.       else if (hp->type == T_CONST)
  5128.         ok = ! done_initializing;
  5129.       /* Print the warning if it's not ok.  */
  5130.       if (!ok) {
  5131.     U_CHAR *msg;        /* what pain... */
  5132.  
  5133.         /* If we are passing through #define and #undef directives, do
  5134.        that for this re-definition now.  */
  5135.         if (debug_output && op)
  5136.       pass_thru_directive (buf, limit, op, keyword);
  5137.  
  5138.     msg = (U_CHAR *) alloca (mdef.symlen + 22);
  5139.     *msg = '`';
  5140.     bcopy (mdef.symnam, msg + 1, mdef.symlen);
  5141.     strcpy ((char *) (msg + mdef.symlen + 1), "' redefined");
  5142.     pedwarn (msg);
  5143.     if (hp->type == T_MACRO)
  5144.       pedwarn_with_file_and_line (hp->value.defn->file, hp->value.defn->line,
  5145.                       "this is the location of the previous definition");
  5146.       }
  5147.       /* Replace the old definition.  */
  5148.       hp->type = T_MACRO;
  5149.       hp->value.defn = mdef.defn;
  5150.     } else {
  5151.       /* If we are passing through #define and #undef directives, do
  5152.      that for this new definition now.  */
  5153.       if (debug_output && op)
  5154.     pass_thru_directive (buf, limit, op, keyword);
  5155.       install (mdef.symnam, mdef.symlen, T_MACRO, 0,
  5156.            (char *) mdef.defn, hashcode);
  5157.     }
  5158.   }
  5159.  
  5160.   return 0;
  5161.  
  5162. nope:
  5163.  
  5164.   return 1;
  5165. }
  5166.  
  5167. /* Check a purported macro name SYMNAME, and yield its length.
  5168.    USAGE is the kind of name this is intended for.  */
  5169.  
  5170. static int
  5171. check_macro_name (symname, usage)
  5172.      U_CHAR *symname;
  5173.      char *usage;
  5174. {
  5175.   U_CHAR *p;
  5176.   int sym_length;
  5177.  
  5178.   for (p = symname; is_idchar[*p]; p++)
  5179.     ;
  5180.   sym_length = p - symname;
  5181.   if (sym_length == 0)
  5182.     error ("invalid %s name", usage);
  5183.   else if (!is_idstart[*symname]) {
  5184.     U_CHAR *msg;            /* what pain... */
  5185.     msg = (U_CHAR *) alloca (sym_length + 1);
  5186.     bcopy (symname, msg, sym_length);
  5187.     msg[sym_length] = 0;
  5188.     error ("invalid %s name `%s'", usage, msg);
  5189.   } else {
  5190.     if (! strncmp (symname, "defined", 7) && sym_length == 7)
  5191.       error ("invalid %s name `defined'", usage);
  5192.   }
  5193.   return sym_length;
  5194. }
  5195.  
  5196. /*
  5197.  * return zero if two DEFINITIONs are isomorphic
  5198.  */
  5199. static int
  5200. compare_defs (d1, d2)
  5201.      DEFINITION *d1, *d2;
  5202. {
  5203.   register struct reflist *a1, *a2;
  5204.   register U_CHAR *p1 = d1->expansion;
  5205.   register U_CHAR *p2 = d2->expansion;
  5206.   int first = 1;
  5207.  
  5208.   if (d1->nargs != d2->nargs)
  5209.     return 1;
  5210.   if (strcmp ((char *)d1->args.argnames, (char *)d2->args.argnames))
  5211.     return 1;
  5212.   for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2;
  5213.        a1 = a1->next, a2 = a2->next) {
  5214.     if (!((a1->nchars == a2->nchars && ! strncmp (p1, p2, a1->nchars))
  5215.       || ! comp_def_part (first, p1, a1->nchars, p2, a2->nchars, 0))
  5216.     || a1->argno != a2->argno
  5217.     || a1->stringify != a2->stringify
  5218.     || a1->raw_before != a2->raw_before
  5219.     || a1->raw_after != a2->raw_after)
  5220.       return 1;
  5221.     first = 0;
  5222.     p1 += a1->nchars;
  5223.     p2 += a2->nchars;
  5224.   }
  5225.   if (a1 != a2)
  5226.     return 1;
  5227.   if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion),
  5228.              p2, d2->length - (p2 - d2->expansion), 1))
  5229.     return 1;
  5230.   return 0;
  5231. }
  5232.  
  5233. /* Return 1 if two parts of two macro definitions are effectively different.
  5234.    One of the parts starts at BEG1 and has LEN1 chars;
  5235.    the other has LEN2 chars at BEG2.
  5236.    Any sequence of whitespace matches any other sequence of whitespace.
  5237.    FIRST means these parts are the first of a macro definition;
  5238.     so ignore leading whitespace entirely.
  5239.    LAST means these parts are the last of a macro definition;
  5240.     so ignore trailing whitespace entirely.  */
  5241.  
  5242. static int
  5243. comp_def_part (first, beg1, len1, beg2, len2, last)
  5244.      int first;
  5245.      U_CHAR *beg1, *beg2;
  5246.      int len1, len2;
  5247.      int last;
  5248. {
  5249.   register U_CHAR *end1 = beg1 + len1;
  5250.   register U_CHAR *end2 = beg2 + len2;
  5251.   if (first) {
  5252.     while (beg1 != end1 && is_space[*beg1]) beg1++;
  5253.     while (beg2 != end2 && is_space[*beg2]) beg2++;
  5254.   }
  5255.   if (last) {
  5256.     while (beg1 != end1 && is_space[end1[-1]]) end1--;
  5257.     while (beg2 != end2 && is_space[end2[-1]]) end2--;
  5258.   }
  5259.   while (beg1 != end1 && beg2 != end2) {
  5260.     if (is_space[*beg1] && is_space[*beg2]) {
  5261.       while (beg1 != end1 && is_space[*beg1]) beg1++;
  5262.       while (beg2 != end2 && is_space[*beg2]) beg2++;
  5263.     } else if (*beg1 == *beg2) {
  5264.       beg1++; beg2++;
  5265.     } else break;
  5266.   }
  5267.   return (beg1 != end1) || (beg2 != end2);
  5268. }
  5269.  
  5270. /* Read a replacement list for a macro with parameters.
  5271.    Build the DEFINITION structure.
  5272.    Reads characters of text starting at BUF until END.
  5273.    ARGLIST specifies the formal parameters to look for
  5274.    in the text of the definition; NARGS is the number of args
  5275.    in that list, or -1 for a macro name that wants no argument list.
  5276.    MACRONAME is the macro name itself (so we can avoid recursive expansion)
  5277.    and NAMELEN is its length in characters.
  5278.    
  5279. Note that comments and backslash-newlines have already been deleted
  5280. from the argument.  */
  5281.  
  5282. /* Leading and trailing Space, Tab, etc. are converted to markers
  5283.    Newline Space, Newline Tab, etc.
  5284.    Newline Space makes a space in the final output
  5285.    but is discarded if stringified.  (Newline Tab is similar but
  5286.    makes a Tab instead.)
  5287.  
  5288.    If there is no trailing whitespace, a Newline Space is added at the end
  5289.    to prevent concatenation that would be contrary to the standard.  */
  5290.  
  5291. static DEFINITION *
  5292. collect_expansion (buf, end, nargs, arglist)
  5293.      U_CHAR *buf, *end;
  5294.      int nargs;
  5295.      struct arglist *arglist;
  5296. {
  5297.   DEFINITION *defn;
  5298.   register U_CHAR *p, *limit, *lastp, *exp_p;
  5299.   struct reflist *endpat = NULL;
  5300.   /* Pointer to first nonspace after last ## seen.  */
  5301.   U_CHAR *concat = 0;
  5302.   /* Pointer to first nonspace after last single-# seen.  */
  5303.   U_CHAR *stringify = 0;
  5304.   int maxsize;
  5305.   int expected_delimiter = '\0';
  5306.  
  5307.   /* Scan thru the replacement list, ignoring comments and quoted
  5308.      strings, picking up on the macro calls.  It does a linear search
  5309.      thru the arg list on every potential symbol.  Profiling might say
  5310.      that something smarter should happen. */
  5311.  
  5312.   if (end < buf)
  5313.     abort ();
  5314.  
  5315.   /* Find the beginning of the trailing whitespace.  */
  5316.   /* Find end of leading whitespace.  */
  5317.   limit = end;
  5318.   p = buf;
  5319.   while (p < limit && is_space[limit[-1]]) limit--;
  5320.   while (p < limit && is_space[*p]) p++;
  5321.  
  5322.   /* Allocate space for the text in the macro definition.
  5323.      Leading and trailing whitespace chars need 2 bytes each.
  5324.      Each other input char may or may not need 1 byte,
  5325.      so this is an upper bound.
  5326.      The extra 2 are for invented trailing newline-marker and final null.  */
  5327.   maxsize = (sizeof (DEFINITION)
  5328.          + 2 * (end - limit) + 2 * (p - buf)
  5329.          + (limit - p) + 3);
  5330.   defn = (DEFINITION *) xcalloc (1, maxsize);
  5331.  
  5332.   defn->nargs = nargs;
  5333.   exp_p = defn->expansion = (U_CHAR *) defn + sizeof (DEFINITION);
  5334.   lastp = exp_p;
  5335.  
  5336.   p = buf;
  5337.  
  5338.   /* Convert leading whitespace to Newline-markers.  */
  5339.   while (p < limit && is_space[*p]) {
  5340.     *exp_p++ = '\n';
  5341.     *exp_p++ = *p++;
  5342.   }
  5343.  
  5344.   if (limit - p >= 2 && p[0] == '#' && p[1] == '#') {
  5345.     error ("`##' at start of macro definition");
  5346.     p += 2;
  5347.   }
  5348.  
  5349.   /* Process the main body of the definition.  */
  5350.   while (p < limit) {
  5351.     int skipped_arg = 0;
  5352.     register U_CHAR c = *p++;
  5353.  
  5354.     *exp_p++ = c;
  5355.  
  5356.     if (!traditional) {
  5357.       switch (c) {
  5358.       case '\'':
  5359.       case '\"':
  5360.         if (expected_delimiter != '\0') {
  5361.           if (c == expected_delimiter)
  5362.             expected_delimiter = '\0';
  5363.         } else
  5364.           expected_delimiter = c;
  5365.     break;
  5366.  
  5367.     /* Special hack: if a \# is written in the #define
  5368.        include a # in the definition.  This is useless for C code
  5369.        but useful for preprocessing other things.  */
  5370.  
  5371.       case '\\':
  5372.     /* \# quotes a # even outside of strings.  */
  5373.     if (p < limit && *p == '#' && !expected_delimiter) {
  5374.       exp_p--;
  5375.       *exp_p++ = *p++;
  5376.     } else if (p < limit && expected_delimiter) {
  5377.       /* In a string, backslash goes through
  5378.          and makes next char ordinary.  */
  5379.       *exp_p++ = *p++;
  5380.     }
  5381.     break;
  5382.  
  5383.       case '#':
  5384.     /* # is ordinary inside a string.  */
  5385.     if (expected_delimiter)
  5386.       break;
  5387.     if (p < limit && *p == '#') {
  5388.       /* ##: concatenate preceding and following tokens.  */
  5389.       /* Take out the first #, discard preceding whitespace.  */
  5390.       exp_p--;
  5391.       while (exp_p > lastp && is_hor_space[exp_p[-1]])
  5392.         --exp_p;
  5393.       /* Skip the second #.  */
  5394.       p++;
  5395.       /* Discard following whitespace.  */
  5396.       SKIP_WHITE_SPACE (p);
  5397.       concat = p;
  5398.       if (p == limit)
  5399.         error ("`##' at end of macro definition");
  5400.     } else if (nargs >= 0) {
  5401.       /* Single #: stringify following argument ref.
  5402.          Don't leave the # in the expansion.  */
  5403.       exp_p--;
  5404.       SKIP_WHITE_SPACE (p);
  5405.       if (p == limit || ! is_idstart[*p])
  5406.         error ("`#' operator is not followed by a macro argument name");
  5407.       else
  5408.         stringify = p;
  5409.     }
  5410.     break;
  5411.       }
  5412.     } else {
  5413.       /* In -traditional mode, recognize arguments inside strings and
  5414.      and character constants, and ignore special properties of #.
  5415.      Arguments inside strings are considered "stringified", but no
  5416.      extra quote marks are supplied.  */
  5417.       switch (c) {
  5418.       case '\'':
  5419.       case '\"':
  5420.     if (expected_delimiter != '\0') {
  5421.       if (c == expected_delimiter)
  5422.         expected_delimiter = '\0';
  5423.     } else
  5424.       expected_delimiter = c;
  5425.     break;
  5426.  
  5427.       case '\\':
  5428.     /* Backslash quotes delimiters and itself, but not macro args.  */
  5429.     if (expected_delimiter != 0 && p < limit
  5430.         && (*p == expected_delimiter || *p == '\\')) {
  5431.       *exp_p++ = *p++;
  5432.       continue;
  5433.     }
  5434.     break;
  5435.  
  5436.       case '/':
  5437.     if (expected_delimiter != '\0') /* No comments inside strings.  */
  5438.       break;
  5439.     if (*p == '*') {
  5440.       /* If we find a comment that wasn't removed by handle_directive,
  5441.          this must be -traditional.  So replace the comment with
  5442.          nothing at all.  */
  5443.       exp_p--;
  5444.       p += 1;
  5445.       while (p < limit && !(p[-2] == '*' && p[-1] == '/'))
  5446.         p++;
  5447. #if 0
  5448.       /* Mark this as a concatenation-point, as if it had been ##.  */
  5449.       concat = p;
  5450. #endif
  5451.     }
  5452.     break;
  5453.       }
  5454.     }
  5455.  
  5456.     /* Handle the start of a symbol.  */
  5457.     if (is_idchar[c] && nargs > 0) {
  5458.       U_CHAR *id_beg = p - 1;
  5459.       int id_len;
  5460.  
  5461.       --exp_p;
  5462.       while (p != limit && is_idchar[*p]) p++;
  5463.       id_len = p - id_beg;
  5464.  
  5465.       if (is_idstart[c]) {
  5466.     register struct arglist *arg;
  5467.  
  5468.     for (arg = arglist; arg != NULL; arg = arg->next) {
  5469.       struct reflist *tpat;
  5470.  
  5471.       if (arg->name[0] == c
  5472.           && arg->length == id_len
  5473.           && strncmp (arg->name, id_beg, id_len) == 0) {
  5474.         if (expected_delimiter && warn_stringify) {
  5475.           if (traditional) {
  5476.         warning ("macro argument `%.*s' is stringified.",
  5477.              id_len, arg->name);
  5478.           } else {
  5479.         warning ("macro arg `%.*s' would be stringified with -traditional.",
  5480.              id_len, arg->name);
  5481.           }
  5482.         }
  5483.         /* If ANSI, don't actually substitute inside a string.  */
  5484.         if (!traditional && expected_delimiter)
  5485.           break;
  5486.         /* make a pat node for this arg and append it to the end of
  5487.            the pat list */
  5488.         tpat = (struct reflist *) xmalloc (sizeof (struct reflist));
  5489.         tpat->next = NULL;
  5490.         tpat->raw_before = concat == id_beg;
  5491.         tpat->raw_after = 0;
  5492.         tpat->rest_args = arg->rest_args;
  5493.         tpat->stringify = (traditional ? expected_delimiter != '\0'
  5494.                    : stringify == id_beg);
  5495.  
  5496.         if (endpat == NULL)
  5497.           defn->pattern = tpat;
  5498.         else
  5499.           endpat->next = tpat;
  5500.         endpat = tpat;
  5501.  
  5502.         tpat->argno = arg->argno;
  5503.         tpat->nchars = exp_p - lastp;
  5504.         {
  5505.           register U_CHAR *p1 = p;
  5506.           SKIP_WHITE_SPACE (p1);
  5507.           if (p1 + 2 <= limit && p1[0] == '#' && p1[1] == '#')
  5508.         tpat->raw_after = 1;
  5509.         }
  5510.         lastp = exp_p;    /* place to start copying from next time */
  5511.         skipped_arg = 1;
  5512.         break;
  5513.       }
  5514.     }
  5515.       }
  5516.  
  5517.       /* If this was not a macro arg, copy it into the expansion.  */
  5518.       if (! skipped_arg) {
  5519.     register U_CHAR *lim1 = p;
  5520.     p = id_beg;
  5521.     while (p != lim1)
  5522.       *exp_p++ = *p++;
  5523.     if (stringify == id_beg)
  5524.       error ("`#' operator should be followed by a macro argument name");
  5525.       }
  5526.     }
  5527.   }
  5528.  
  5529.   if (limit < end) {
  5530.     /* Convert trailing whitespace to Newline-markers.  */
  5531.     while (limit < end && is_space[*limit]) {
  5532.       *exp_p++ = '\n';
  5533.       *exp_p++ = *limit++;
  5534.     }
  5535.   } else if (!traditional && expected_delimiter == 0) {
  5536.     /* There is no trailing whitespace, so invent some in ANSI mode.
  5537.        But not if "inside a string" (which in ANSI mode
  5538.        happens only for -D option).  */
  5539.     *exp_p++ = '\n';
  5540.     *exp_p++ = ' ';
  5541.   }
  5542.  
  5543.   *exp_p = '\0';
  5544.  
  5545.   defn->length = exp_p - defn->expansion;
  5546.  
  5547.   /* Crash now if we overrun the allocated size.  */
  5548.   if (defn->length + 1 > maxsize)
  5549.     abort ();
  5550.  
  5551. #if 0
  5552. /* This isn't worth the time it takes.  */
  5553.   /* give back excess storage */
  5554.   defn->expansion = (U_CHAR *) xrealloc (defn->expansion, defn->length + 1);
  5555. #endif
  5556.  
  5557.   return defn;
  5558. }
  5559.  
  5560. static int
  5561. do_assert (buf, limit, op, keyword)
  5562.      U_CHAR *buf, *limit;
  5563.      FILE_BUF *op;
  5564.      struct directive *keyword;
  5565. {
  5566.   U_CHAR *bp;            /* temp ptr into input buffer */
  5567.   U_CHAR *symname;        /* remember where symbol name starts */
  5568.   int sym_length;        /* and how long it is */
  5569.   struct arglist *tokens = NULL;
  5570.  
  5571.   if (pedantic && done_initializing && !instack[indepth].system_header_p)
  5572.     pedwarn ("ANSI C does not allow `#assert'");
  5573.  
  5574.   bp = buf;
  5575.  
  5576.   while (is_hor_space[*bp])
  5577.     bp++;
  5578.  
  5579.   symname = bp;            /* remember where it starts */
  5580.   sym_length = check_macro_name (bp, "assertion");
  5581.   bp += sym_length;
  5582.   /* #define doesn't do this, but we should.  */
  5583.   SKIP_WHITE_SPACE (bp);
  5584.  
  5585.   /* Lossage will occur if identifiers or control tokens are broken
  5586.      across lines using backslash.  This is not the right place to take
  5587.      care of that. */
  5588.  
  5589.   if (*bp != '(') {
  5590.     error ("missing token-sequence in `#assert'");
  5591.     return 1;
  5592.   }
  5593.  
  5594.   {
  5595.     int error_flag = 0;
  5596.  
  5597.     bp++;            /* skip '(' */
  5598.     SKIP_WHITE_SPACE (bp);
  5599.  
  5600.     tokens = read_token_list (&bp, limit, &error_flag);
  5601.     if (error_flag)
  5602.       return 1;
  5603.     if (tokens == 0) {
  5604.       error ("empty token-sequence in `#assert'");
  5605.       return 1;
  5606.     }
  5607.  
  5608.     ++bp;            /* skip paren */
  5609.     SKIP_WHITE_SPACE (bp);
  5610.   }
  5611.  
  5612.   /* If this name isn't already an assertion name, make it one.
  5613.      Error if it was already in use in some other way.  */
  5614.  
  5615.   {
  5616.     ASSERTION_HASHNODE *hp;
  5617.     int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE);
  5618.     struct tokenlist_list *value
  5619.       = (struct tokenlist_list *) xmalloc (sizeof (struct tokenlist_list));
  5620.  
  5621.     hp = assertion_lookup (symname, sym_length, hashcode);
  5622.     if (hp == NULL) {
  5623.       if (sym_length == 7 && ! strncmp (symname, "defined", sym_length))
  5624.     error ("`defined' redefined as assertion");
  5625.       hp = assertion_install (symname, sym_length, hashcode);
  5626.     }
  5627.  
  5628.     /* Add the spec'd token-sequence to the list of such.  */
  5629.     value->tokens = tokens;
  5630.     value->next = hp->value;
  5631.     hp->value = value;
  5632.   }
  5633.  
  5634.   return 0;
  5635. }
  5636.  
  5637. static int
  5638. do_unassert (buf, limit, op, keyword)
  5639.      U_CHAR *buf, *limit;
  5640.      FILE_BUF *op;
  5641.      struct directive *keyword;
  5642. {
  5643.   U_CHAR *bp;            /* temp ptr into input buffer */
  5644.   U_CHAR *symname;        /* remember where symbol name starts */
  5645.   int sym_length;        /* and how long it is */
  5646.  
  5647.   struct arglist *tokens = NULL;
  5648.   int tokens_specified = 0;
  5649.  
  5650.   if (pedantic && done_initializing && !instack[indepth].system_header_p)
  5651.     pedwarn ("ANSI C does not allow `#unassert'");
  5652.  
  5653.   bp = buf;
  5654.  
  5655.   while (is_hor_space[*bp])
  5656.     bp++;
  5657.  
  5658.   symname = bp;            /* remember where it starts */
  5659.   sym_length = check_macro_name (bp, "assertion");
  5660.   bp += sym_length;
  5661.   /* #define doesn't do this, but we should.  */
  5662.   SKIP_WHITE_SPACE (bp);
  5663.  
  5664.   /* Lossage will occur if identifiers or control tokens are broken
  5665.      across lines using backslash.  This is not the right place to take
  5666.      care of that. */
  5667.  
  5668.   if (*bp == '(') {
  5669.     int error_flag = 0;
  5670.  
  5671.     bp++;            /* skip '(' */
  5672.     SKIP_WHITE_SPACE (bp);
  5673.  
  5674.     tokens = read_token_list (&bp, limit, &error_flag);
  5675.     if (error_flag)
  5676.       return 1;
  5677.     if (tokens == 0) {
  5678.       error ("empty token list in `#unassert'");
  5679.       return 1;
  5680.     }
  5681.  
  5682.     tokens_specified = 1;
  5683.  
  5684.     ++bp;            /* skip paren */
  5685.     SKIP_WHITE_SPACE (bp);
  5686.   }
  5687.  
  5688.   {
  5689.     ASSERTION_HASHNODE *hp;
  5690.     int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE);
  5691.     struct tokenlist_list *tail, *prev;
  5692.  
  5693.     hp = assertion_lookup (symname, sym_length, hashcode);
  5694.     if (hp == NULL)
  5695.       return 1;
  5696.  
  5697.     /* If no token list was specified, then eliminate this assertion
  5698.        entirely.  */
  5699.     if (! tokens_specified) {
  5700.       struct tokenlist_list *next;
  5701.       for (tail = hp->value; tail; tail = next) {
  5702.     next = tail->next;
  5703.     free_token_list (tail->tokens);
  5704.     free (tail);
  5705.       }
  5706.       delete_assertion (hp);
  5707.     } else {
  5708.       /* If a list of tokens was given, then delete any matching list.  */
  5709.  
  5710.       tail = hp->value;
  5711.       prev = 0;
  5712.       while (tail) {
  5713.     struct tokenlist_list *next = tail->next;
  5714.     if (compare_token_lists (tail->tokens, tokens)) {
  5715.       if (prev)
  5716.         prev->next = next;
  5717.       else
  5718.         hp->value = tail->next;
  5719.       free_token_list (tail->tokens);
  5720.       free (tail);
  5721.     } else {
  5722.       prev = tail;
  5723.     }
  5724.     tail = next;
  5725.       }
  5726.     }
  5727.   }
  5728.  
  5729.   return 0;
  5730. }
  5731.  
  5732. /* Test whether there is an assertion named NAME
  5733.    and optionally whether it has an asserted token list TOKENS.
  5734.    NAME is not null terminated; its length is SYM_LENGTH.
  5735.    If TOKENS_SPECIFIED is 0, then don't check for any token list.  */
  5736.  
  5737. int
  5738. check_assertion (name, sym_length, tokens_specified, tokens)
  5739.      U_CHAR *name;
  5740.      int sym_length;
  5741.      int tokens_specified;
  5742.      struct arglist *tokens;
  5743. {
  5744.   ASSERTION_HASHNODE *hp;
  5745.   int hashcode = hashf (name, sym_length, ASSERTION_HASHSIZE);
  5746.  
  5747.   if (pedantic && !instack[indepth].system_header_p)
  5748.     pedwarn ("ANSI C does not allow testing assertions");
  5749.  
  5750.   hp = assertion_lookup (name, sym_length, hashcode);
  5751.   if (hp == NULL)
  5752.     /* It is not an assertion; just return false.  */
  5753.     return 0;
  5754.  
  5755.   /* If no token list was specified, then value is 1.  */
  5756.   if (! tokens_specified)
  5757.     return 1;
  5758.  
  5759.   {
  5760.     struct tokenlist_list *tail;
  5761.  
  5762.     tail = hp->value;
  5763.  
  5764.     /* If a list of tokens was given,
  5765.        then succeed if the assertion records a matching list.  */
  5766.  
  5767.     while (tail) {
  5768.       if (compare_token_lists (tail->tokens, tokens))
  5769.     return 1;
  5770.       tail = tail->next;
  5771.     }
  5772.  
  5773.     /* Fail if the assertion has no matching list.  */
  5774.     return 0;
  5775.   }
  5776. }
  5777.  
  5778. /* Compare two lists of tokens for equality including order of tokens.  */
  5779.  
  5780. static int
  5781. compare_token_lists (l1, l2)
  5782.      struct arglist *l1, *l2;
  5783. {
  5784.   while (l1 && l2) {
  5785.     if (l1->length != l2->length)
  5786.       return 0;
  5787.     if (strncmp (l1->name, l2->name, l1->length))
  5788.       return 0;
  5789.     l1 = l1->next;
  5790.     l2 = l2->next;
  5791.   }
  5792.  
  5793.   /* Succeed if both lists end at the same time.  */
  5794.   return l1 == l2;
  5795. }
  5796.  
  5797. /* Read a space-separated list of tokens ending in a close parenthesis.
  5798.    Return a list of strings, in the order they were written.
  5799.    (In case of error, return 0 and store -1 in *ERROR_FLAG.)
  5800.    Parse the text starting at *BPP, and update *BPP.
  5801.    Don't parse beyond LIMIT.  */
  5802.  
  5803. static struct arglist *
  5804. read_token_list (bpp, limit, error_flag)
  5805.      U_CHAR **bpp;
  5806.      U_CHAR *limit;
  5807.      int *error_flag;
  5808. {
  5809.   struct arglist *token_ptrs = 0;
  5810.   U_CHAR *bp = *bpp;
  5811.   int depth = 1;
  5812.  
  5813.   *error_flag = 0;
  5814.  
  5815.   /* Loop over the assertion value tokens.  */
  5816.   while (depth > 0) {
  5817.     struct arglist *temp;
  5818.     int eofp = 0;
  5819.     U_CHAR *beg = bp;
  5820.  
  5821.     /* Find the end of the token.  */
  5822.     if (*bp == '(') {
  5823.       bp++;
  5824.       depth++;
  5825.     } else if (*bp == ')') {
  5826.       depth--;
  5827.       if (depth == 0)
  5828.     break;
  5829.       bp++;
  5830.     } else if (*bp == '"' || *bp == '\'')
  5831.       bp = skip_quoted_string (bp, limit, 0, NULL_PTR, NULL_PTR, &eofp);
  5832.     else
  5833.       while (! is_hor_space[*bp] && *bp != '(' && *bp != ')'
  5834.          && *bp != '"' && *bp != '\'' && bp != limit)
  5835.     bp++;
  5836.  
  5837.     temp = (struct arglist *) xmalloc (sizeof (struct arglist));
  5838.     temp->name = (U_CHAR *) xmalloc (bp - beg + 1);
  5839.     bcopy (beg, temp->name, bp - beg);
  5840.     temp->name[bp - beg] = 0;
  5841.     temp->next = token_ptrs;
  5842.     token_ptrs = temp;
  5843.     temp->length = bp - beg;
  5844.  
  5845.     SKIP_WHITE_SPACE (bp);
  5846.  
  5847.     if (bp >= limit) {
  5848.       error ("unterminated token sequence in `#assert' or `#unassert'");
  5849.       *error_flag = -1;
  5850.       return 0;
  5851.     }
  5852.   }
  5853.   *bpp = bp;
  5854.  
  5855.   /* We accumulated the names in reverse order.
  5856.      Now reverse them to get the proper order.  */
  5857.   {
  5858.     register struct arglist *prev = 0, *this, *next;
  5859.     for (this = token_ptrs; this; this = next) {
  5860.       next = this->next;
  5861.       this->next = prev;
  5862.       prev = this;
  5863.     }
  5864.     return prev;
  5865.   }
  5866. }
  5867.  
  5868. static void
  5869. free_token_list (tokens)
  5870.      struct arglist *tokens;
  5871. {
  5872.   while (tokens) {
  5873.     struct arglist *next = tokens->next;
  5874.     free (tokens->name);
  5875.     free (tokens);
  5876.     tokens = next;
  5877.   }
  5878. }
  5879.  
  5880. /*
  5881.  * Install a name in the assertion hash table.
  5882.  *
  5883.  * If LEN is >= 0, it is the length of the name.
  5884.  * Otherwise, compute the length by scanning the entire name.
  5885.  *
  5886.  * If HASH is >= 0, it is the precomputed hash code.
  5887.  * Otherwise, compute the hash code.
  5888.  */
  5889. static ASSERTION_HASHNODE *
  5890. assertion_install (name, len, hash)
  5891.      U_CHAR *name;
  5892.      int len;
  5893.      int hash;
  5894. {
  5895.   register ASSERTION_HASHNODE *hp;
  5896.   register int i, bucket;
  5897.   register U_CHAR *p, *q;
  5898.  
  5899.   i = sizeof (ASSERTION_HASHNODE) + len + 1;
  5900.   hp = (ASSERTION_HASHNODE *) xmalloc (i);
  5901.   bucket = hash;
  5902.   hp->bucket_hdr = &assertion_hashtab[bucket];
  5903.   hp->next = assertion_hashtab[bucket];
  5904.   assertion_hashtab[bucket] = hp;
  5905.   hp->prev = NULL;
  5906.   if (hp->next != NULL)
  5907.     hp->next->prev = hp;
  5908.   hp->length = len;
  5909.   hp->value = 0;
  5910.   hp->name = ((U_CHAR *) hp) + sizeof (ASSERTION_HASHNODE);
  5911.   p = hp->name;
  5912.   q = name;
  5913.   for (i = 0; i < len; i++)
  5914.     *p++ = *q++;
  5915.   hp->name[len] = 0;
  5916.   return hp;
  5917. }
  5918.  
  5919. /*
  5920.  * find the most recent hash node for name name (ending with first
  5921.  * non-identifier char) installed by install
  5922.  *
  5923.  * If LEN is >= 0, it is the length of the name.
  5924.  * Otherwise, compute the length by scanning the entire name.
  5925.  *
  5926.  * If HASH is >= 0, it is the precomputed hash code.
  5927.  * Otherwise, compute the hash code.
  5928.  */
  5929. static ASSERTION_HASHNODE *
  5930. assertion_lookup (name, len, hash)
  5931.      U_CHAR *name;
  5932.      int len;
  5933.      int hash;
  5934. {
  5935.   register U_CHAR *bp;
  5936.   register ASSERTION_HASHNODE *bucket;
  5937.  
  5938.   bucket = assertion_hashtab[hash];
  5939.   while (bucket) {
  5940.     if (bucket->length == len && strncmp (bucket->name, name, len) == 0)
  5941.       return bucket;
  5942.     bucket = bucket->next;
  5943.   }
  5944.   return NULL;
  5945. }
  5946.  
  5947. static void
  5948. delete_assertion (hp)
  5949.      ASSERTION_HASHNODE *hp;
  5950. {
  5951.  
  5952.   if (hp->prev != NULL)
  5953.     hp->prev->next = hp->next;
  5954.   if (hp->next != NULL)
  5955.     hp->next->prev = hp->prev;
  5956.  
  5957.   /* make sure that the bucket chain header that
  5958.      the deleted guy was on points to the right thing afterwards. */
  5959.   if (hp == *hp->bucket_hdr)
  5960.     *hp->bucket_hdr = hp->next;
  5961.  
  5962.   free (hp);
  5963. }
  5964.  
  5965. /*
  5966.  * interpret #line command.  Remembers previously seen fnames
  5967.  * in its very own hash table.
  5968.  */
  5969. #define FNAME_HASHSIZE 37
  5970.  
  5971. static int
  5972. do_line (buf, limit, op, keyword)
  5973.      U_CHAR *buf, *limit;
  5974.      FILE_BUF *op;
  5975.      struct directive *keyword;
  5976. {
  5977.   register U_CHAR *bp;
  5978.   FILE_BUF *ip = &instack[indepth];
  5979.   FILE_BUF tem;
  5980.   int new_lineno;
  5981.   enum file_change_code file_change = same_file;
  5982.  
  5983.   /* Expand any macros.  */
  5984.   tem = expand_to_temp_buffer (buf, limit, 0, 0);
  5985.  
  5986.   /* Point to macroexpanded line, which is null-terminated now.  */
  5987.   bp = tem.buf;
  5988.   SKIP_WHITE_SPACE (bp);
  5989.  
  5990.   if (!isdigit (*bp)) {
  5991.     error ("invalid format `#line' command");
  5992.     return 0;
  5993.   }
  5994.  
  5995.   /* The Newline at the end of this line remains to be processed.
  5996.      To put the next line at the specified line number,
  5997.      we must store a line number now that is one less.  */
  5998.   new_lineno = atoi (bp) - 1;
  5999.  
  6000.   /* NEW_LINENO is one less than the actual line number here.  */
  6001.   if (pedantic && new_lineno < 0)
  6002.     pedwarn ("line number out of range in `#line' command");
  6003.  
  6004.   /* skip over the line number.  */
  6005.   while (isdigit (*bp))
  6006.     bp++;
  6007.  
  6008. #if 0 /* #line 10"foo.c" is supposed to be allowed.  */
  6009.   if (*bp && !is_space[*bp]) {
  6010.     error ("invalid format `#line' command");
  6011.     return;
  6012.   }
  6013. #endif
  6014.  
  6015.   SKIP_WHITE_SPACE (bp);
  6016.  
  6017.   if (*bp == '\"') {
  6018.     static HASHNODE *fname_table[FNAME_HASHSIZE];
  6019.     HASHNODE *hp, **hash_bucket;
  6020.     U_CHAR *fname, *p;
  6021.     int fname_length;
  6022.  
  6023.     fname = ++bp;
  6024.  
  6025.     /* Turn the file name, which is a character string literal,
  6026.        into a null-terminated string.  Do this in place.  */
  6027.     p = bp;
  6028.     for (;;)
  6029.       switch ((*p++ = *bp++)) {
  6030.       case '\0':
  6031.     error ("invalid format `#line' command");
  6032.     return 0;
  6033.  
  6034.       case '\\':
  6035.     {
  6036.       char *bpc = (char *) bp;
  6037.       int c = parse_escape (&bpc);
  6038.       bp = (U_CHAR *) bpc;
  6039.       if (c < 0)
  6040.         p--;
  6041.       else
  6042.         p[-1] = c;
  6043.     }
  6044.     break;
  6045.  
  6046.       case '\"':
  6047.     p[-1] = 0;
  6048.     goto fname_done;
  6049.       }
  6050.   fname_done:
  6051.     fname_length = p - fname;
  6052.  
  6053.     SKIP_WHITE_SPACE (bp);
  6054.     if (*bp) {
  6055.       if (pedantic)
  6056.     pedwarn ("garbage at end of `#line' command");
  6057.       if (*bp == '1')
  6058.     file_change = enter_file;
  6059.       else if (*bp == '2')
  6060.     file_change = leave_file;
  6061.       else if (*bp == '3')
  6062.     ip->system_header_p = 1;
  6063.       else if (*bp == '4')
  6064.     ip->system_header_p = 2;
  6065.       else {
  6066.     error ("invalid format `#line' command");
  6067.     return 0;
  6068.       }
  6069.  
  6070.       bp++;
  6071.       SKIP_WHITE_SPACE (bp);
  6072.       if (*bp == '3') {
  6073.     ip->system_header_p = 1;
  6074.     bp++;
  6075.     SKIP_WHITE_SPACE (bp);
  6076.       }
  6077.       if (*bp == '4') {
  6078.     ip->system_header_p = 2;
  6079.     bp++;
  6080.     SKIP_WHITE_SPACE (bp);
  6081.       }
  6082.       if (*bp) {
  6083.     error ("invalid format `#line' command");
  6084.     return 0;
  6085.       }
  6086.     }
  6087.  
  6088.     hash_bucket =
  6089.       &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)];
  6090.     for (hp = *hash_bucket; hp != NULL; hp = hp->next)
  6091.       if (hp->length == fname_length &&
  6092.       strncmp (hp->value.cpval, fname, fname_length) == 0) {
  6093.     ip->nominal_fname = hp->value.cpval;
  6094.     break;
  6095.       }
  6096.     if (hp == 0) {
  6097.       /* Didn't find it; cons up a new one.  */
  6098.       hp = (HASHNODE *) xcalloc (1, sizeof (HASHNODE) + fname_length + 1);
  6099.       hp->next = *hash_bucket;
  6100.       *hash_bucket = hp;
  6101.  
  6102.       hp->length = fname_length;
  6103.       ip->nominal_fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE);
  6104.       bcopy (fname, hp->value.cpval, fname_length);
  6105.     }
  6106.   } else if (*bp) {
  6107.     error ("invalid format `#line' command");
  6108.     return 0;
  6109.   }
  6110.  
  6111.   ip->lineno = new_lineno;
  6112.   output_line_command (ip, op, 0, file_change);
  6113.   check_expand (op, ip->length - (ip->bufp - ip->buf));
  6114.   return 0;
  6115. }
  6116.  
  6117. /*
  6118.  * remove the definition of a symbol from the symbol table.
  6119.  * according to un*x /lib/cpp, it is not an error to undef
  6120.  * something that has no definitions, so it isn't one here either.
  6121.  */
  6122.  
  6123. static int
  6124. do_undef (buf, limit, op, keyword)
  6125.      U_CHAR *buf, *limit;
  6126.      FILE_BUF *op;
  6127.      struct directive *keyword;
  6128. {
  6129.   int sym_length;
  6130.   HASHNODE *hp;
  6131.   U_CHAR *orig_buf = buf;
  6132.  
  6133.   /* If this is a precompiler run (with -pcp) pass thru #undef commands.  */
  6134.   if (pcp_outfile && op)
  6135.     pass_thru_directive (buf, limit, op, keyword);
  6136.  
  6137.   SKIP_WHITE_SPACE (buf);
  6138.   sym_length = check_macro_name (buf, "macro");
  6139.  
  6140.   while ((hp = lookup (buf, sym_length, -1)) != NULL) {
  6141.     /* If we are generating additional info for debugging (with -g) we
  6142.        need to pass through all effective #undef commands.  */
  6143.     if (debug_output && op)
  6144.       pass_thru_directive (orig_buf, limit, op, keyword);
  6145.     if (hp->type != T_MACRO)
  6146.       warning ("undefining `%s'", hp->name);
  6147.     delete_macro (hp);
  6148.   }
  6149.  
  6150.   if (pedantic) {
  6151.     buf += sym_length;
  6152.     SKIP_WHITE_SPACE (buf);
  6153.     if (buf != limit)
  6154.       pedwarn ("garbage after `#undef' directive");
  6155.   }
  6156.   return 0;
  6157. }
  6158.  
  6159. /*
  6160.  * Report a fatal error detected by the program we are processing.
  6161.  * Use the text of the line in the error message, then terminate.
  6162.  * (We use error because it prints the filename & line#.)
  6163.  */
  6164.  
  6165. static int
  6166. do_error (buf, limit, op, keyword)
  6167.      U_CHAR *buf, *limit;
  6168.      FILE_BUF *op;
  6169.      struct directive *keyword;
  6170. {
  6171.   int length = limit - buf;
  6172.   U_CHAR *copy = (U_CHAR *) xmalloc (length + 1);
  6173.   bcopy (buf, copy, length);
  6174.   copy[length] = 0;
  6175.   SKIP_WHITE_SPACE (copy);
  6176.   error ("#error %s", copy);
  6177.   exit (FAILURE_EXIT_CODE);
  6178.   /* NOTREACHED */
  6179.   return 0;
  6180. }
  6181.  
  6182. /*
  6183.  * Report a warning detected by the program we are processing.
  6184.  * Use the text of the line in the warning message, then continue.
  6185.  * (We use error because it prints the filename & line#.)
  6186.  */
  6187.  
  6188. static int
  6189. do_warning (buf, limit, op, keyword)
  6190.      U_CHAR *buf, *limit;
  6191.      FILE_BUF *op;
  6192.      struct directive *keyword;
  6193. {
  6194.   int length = limit - buf;
  6195.   U_CHAR *copy = (U_CHAR *) xmalloc (length + 1);
  6196.   bcopy (buf, copy, length);
  6197.   copy[length] = 0;
  6198.   SKIP_WHITE_SPACE (copy);
  6199.   warning ("#warning %s", copy);
  6200.   return 0;
  6201. }
  6202.  
  6203. /* Remember the name of the current file being read from so that we can
  6204.    avoid ever including it again.  */
  6205.  
  6206. static int
  6207. do_once ()
  6208. {
  6209.   int i;
  6210.   FILE_BUF *ip = NULL;
  6211.  
  6212.   for (i = indepth; i >= 0; i--)
  6213.     if (instack[i].fname != NULL) {
  6214.       ip = &instack[i];
  6215.       break;
  6216.     }
  6217.  
  6218.   if (ip != NULL) {
  6219.     struct file_name_list *new;
  6220.     
  6221.     new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
  6222.     new->next = dont_repeat_files;
  6223.     dont_repeat_files = new;
  6224.     new->fname = savestring (ip->fname);
  6225.     new->control_macro = 0;
  6226.     new->c_system_include_path = 0;
  6227.   }
  6228.   return 0;
  6229. }
  6230.  
  6231. /* #ident has already been copied to the output file, so just ignore it.  */
  6232.  
  6233. static int
  6234. do_ident (buf, limit)
  6235.      U_CHAR *buf, *limit;
  6236. {
  6237.   FILE_BUF trybuf;
  6238.   int len;
  6239.   FILE_BUF *op = &outbuf;
  6240.  
  6241.   /* Allow #ident in system headers, since that's not user's fault.  */
  6242.   if (pedantic && !instack[indepth].system_header_p)
  6243.     pedwarn ("ANSI C does not allow `#ident'");
  6244.  
  6245.   trybuf = expand_to_temp_buffer (buf, limit, 0, 0);
  6246.   buf = (U_CHAR *) alloca (trybuf.bufp - trybuf.buf + 1);
  6247.   bcopy (trybuf.buf, buf, trybuf.bufp - trybuf.buf);
  6248.   limit = buf + (trybuf.bufp - trybuf.buf);
  6249.   len = (limit - buf);
  6250.   free (trybuf.buf);
  6251.  
  6252.   /* Output directive name.  */
  6253.   check_expand (op, 8);
  6254.   bcopy ("#ident ", op->bufp, 7);
  6255.   op->bufp += 7;
  6256.  
  6257.   /* Output the expanded argument line.  */
  6258.   check_expand (op, len);
  6259.   bcopy (buf, op->bufp, len);
  6260.   op->bufp += len;
  6261.  
  6262.   return 0;
  6263. }
  6264.  
  6265. /* #pragma and its argument line have already been copied to the output file.
  6266.    Just check for some recognized pragmas that need validation here.  */
  6267.  
  6268. static int
  6269. do_pragma (buf, limit)
  6270.      U_CHAR *buf, *limit;
  6271. {
  6272.   while (*buf == ' ' || *buf == '\t')
  6273.     buf++;
  6274.   if (!strncmp (buf, "once", 4)) {
  6275.     /* Allow #pragma once in system headers, since that's not the user's
  6276.        fault.  */
  6277.     if (!instack[indepth].system_header_p)
  6278.       warning ("`#pragma once' is obsolete");
  6279.     do_once ();
  6280.   }
  6281.  
  6282.   if (!strncmp (buf, "implementation", 14)) {
  6283.     /* Be quiet about `#pragma implementation' for a file only if it hasn't
  6284.        been included yet.  */
  6285.     struct file_name_list *ptr;
  6286.     U_CHAR *p = buf + 14, *fname, *inc_fname;
  6287.     SKIP_WHITE_SPACE (p);
  6288.     if (*p == '\n' || *p != '\"')
  6289.       return 0;
  6290.  
  6291.     fname = p + 1;
  6292.     if (p = (U_CHAR *) index (fname, '\"'))
  6293.       *p = '\0';
  6294.     
  6295.     for (ptr = all_include_files; ptr; ptr = ptr->next) {
  6296.       inc_fname = (U_CHAR *) rindex (ptr->fname, '/');
  6297.       inc_fname = inc_fname ? inc_fname + 1 : (U_CHAR *) ptr->fname;
  6298.       if (inc_fname && !strcmp (inc_fname, fname))
  6299.     warning ("`#pragma implementation' for `%s' appears after file is included",
  6300.          fname);
  6301.     }
  6302.   }
  6303.  
  6304.   return 0;
  6305. }
  6306.  
  6307. #if 0
  6308. /* This was a fun hack, but #pragma seems to start to be useful.
  6309.    By failing to recognize it, we pass it through unchanged to cc1.  */
  6310.  
  6311. /*
  6312.  * the behavior of the #pragma directive is implementation defined.
  6313.  * this implementation defines it as follows.
  6314.  */
  6315.  
  6316. static int
  6317. do_pragma ()
  6318. {
  6319.   close (0);
  6320.   if (open ("/dev/tty", O_RDONLY, 0666) != 0)
  6321.     goto nope;
  6322.   close (1);
  6323.   if (open ("/dev/tty", O_WRONLY, 0666) != 1)
  6324.     goto nope;
  6325.   execl ("/usr/games/hack", "#pragma", 0);
  6326.   execl ("/usr/games/rogue", "#pragma", 0);
  6327.   execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0);
  6328.   execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0);
  6329. nope:
  6330.   fatal ("You are in a maze of twisty compiler features, all different");
  6331. }
  6332. #endif
  6333.  
  6334. /* Just ignore #sccs, on systems where we define it at all.  */
  6335.  
  6336. static int
  6337. do_sccs ()
  6338. {
  6339.   if (pedantic)
  6340.     pedwarn ("ANSI C does not allow `#sccs'");
  6341.   return 0;
  6342. }
  6343.  
  6344. /*
  6345.  * handle #if command by
  6346.  *   1) inserting special `defined' keyword into the hash table
  6347.  *    that gets turned into 0 or 1 by special_symbol (thus,
  6348.  *    if the luser has a symbol called `defined' already, it won't
  6349.  *      work inside the #if command)
  6350.  *   2) rescan the input into a temporary output buffer
  6351.  *   3) pass the output buffer to the yacc parser and collect a value
  6352.  *   4) clean up the mess left from steps 1 and 2.
  6353.  *   5) call conditional_skip to skip til the next #endif (etc.),
  6354.  *      or not, depending on the value from step 3.
  6355.  */
  6356.  
  6357. static int
  6358. do_if (buf, limit, op, keyword)
  6359.      U_CHAR *buf, *limit;
  6360.      FILE_BUF *op;
  6361.      struct directive *keyword;
  6362. {
  6363.   int value;
  6364.   FILE_BUF *ip = &instack[indepth];
  6365.  
  6366.   value = eval_if_expression (buf, limit - buf);
  6367.   conditional_skip (ip, value == 0, T_IF, NULL_PTR);
  6368.   return 0;
  6369. }
  6370.  
  6371. /*
  6372.  * handle a #elif directive by not changing  if_stack  either.
  6373.  * see the comment above do_else.
  6374.  */
  6375.  
  6376. static int
  6377. do_elif (buf, limit, op, keyword)
  6378.      U_CHAR *buf, *limit;
  6379.      FILE_BUF *op;
  6380.      struct directive *keyword;
  6381. {
  6382.   int value;
  6383.   FILE_BUF *ip = &instack[indepth];
  6384.  
  6385.   if (if_stack == instack[indepth].if_stack) {
  6386.     error ("`#elif' not within a conditional");
  6387.     return 0;
  6388.   } else {
  6389.     if (if_stack->type != T_IF && if_stack->type != T_ELIF) {
  6390.       error ("`#elif' after `#else'");
  6391.       fprintf (stderr, " (matches line %d", if_stack->lineno);
  6392.       if (if_stack->fname != NULL && ip->fname != NULL &&
  6393.       strcmp (if_stack->fname, ip->nominal_fname) != 0)
  6394.     fprintf (stderr, ", file %s", if_stack->fname);
  6395.       fprintf (stderr, ")\n");
  6396.     }
  6397.     if_stack->type = T_ELIF;
  6398.   }
  6399.  
  6400.   if (if_stack->if_succeeded)
  6401.     skip_if_group (ip, 0);
  6402.   else {
  6403.     value = eval_if_expression (buf, limit - buf);
  6404.     if (value == 0)
  6405.       skip_if_group (ip, 0);
  6406.     else {
  6407.       ++if_stack->if_succeeded;    /* continue processing input */
  6408.       output_line_command (ip, op, 1, same_file);
  6409.     }
  6410.   }
  6411.   return 0;
  6412. }
  6413.  
  6414. /*
  6415.  * evaluate a #if expression in BUF, of length LENGTH,
  6416.  * then parse the result as a C expression and return the value as an int.
  6417.  */
  6418. static int
  6419. eval_if_expression (buf, length)
  6420.      U_CHAR *buf;
  6421.      int length;
  6422. {
  6423.   FILE_BUF temp_obuf;
  6424.   HASHNODE *save_defined;
  6425.   int value;
  6426.  
  6427.   save_defined = install ("defined", -1, T_SPEC_DEFINED, 0, 0, -1);
  6428.   pcp_inside_if = 1;
  6429.   temp_obuf = expand_to_temp_buffer (buf, buf + length, 0, 1);
  6430.   pcp_inside_if = 0;
  6431.   delete_macro (save_defined);    /* clean up special symbol */
  6432.  
  6433.   value = parse_c_expression (temp_obuf.buf);
  6434.  
  6435.   free (temp_obuf.buf);
  6436.  
  6437.   return value;
  6438. }
  6439.  
  6440. /*
  6441.  * routine to handle ifdef/ifndef.  Try to look up the symbol,
  6442.  * then do or don't skip to the #endif/#else/#elif depending
  6443.  * on what directive is actually being processed.
  6444.  */
  6445.  
  6446. static int
  6447. do_xifdef (buf, limit, op, keyword)
  6448.      U_CHAR *buf, *limit;
  6449.      FILE_BUF *op;
  6450.      struct directive *keyword;
  6451. {
  6452.   int skip;
  6453.   FILE_BUF *ip = &instack[indepth];
  6454.   U_CHAR *end; 
  6455.   int start_of_file = 0;
  6456.   U_CHAR *control_macro = 0;
  6457.  
  6458.   /* Detect a #ifndef at start of file (not counting comments).  */
  6459.   if (ip->fname != 0 && keyword->type == T_IFNDEF) {
  6460.     U_CHAR *p = ip->buf;
  6461.     while (p != directive_start) {
  6462.       U_CHAR c = *p++;
  6463.       if (is_space[c])
  6464.     ;
  6465.       else if (c == '/' && p != ip->bufp && *p == '*') {
  6466.     /* Skip this comment.  */
  6467.     int junk;
  6468.     U_CHAR *save_bufp = ip->bufp;
  6469.     ip->bufp = p + 1;
  6470.     p = skip_to_end_of_comment (ip, &junk, 1);
  6471.     ip->bufp = save_bufp;
  6472.       } else {
  6473.     goto fail;
  6474.       }
  6475.     }
  6476.     /* If we get here, this conditional is the beginning of the file.  */
  6477.     start_of_file = 1;
  6478.   fail: ;
  6479.   }
  6480.  
  6481.   /* Discard leading and trailing whitespace.  */
  6482.   SKIP_WHITE_SPACE (buf);
  6483.   while (limit != buf && is_hor_space[limit[-1]]) limit--;
  6484.  
  6485.   /* Find the end of the identifier at the beginning.  */
  6486.   for (end = buf; is_idchar[*end]; end++);
  6487.  
  6488.   if (end == buf) {
  6489.     skip = (keyword->type == T_IFDEF);
  6490.     if (! traditional)
  6491.       pedwarn (end == limit ? "`#%s' with no argument"
  6492.            : "`#%s' argument starts with punctuation",
  6493.            keyword->name);
  6494.   } else {
  6495.     HASHNODE *hp;
  6496.  
  6497.     if (pedantic && buf[0] >= '0' && buf[0] <= '9')
  6498.       pedwarn ("`#%s' argument starts with a digit", keyword->name);
  6499.     else if (end != limit && !traditional)
  6500.       pedwarn ("garbage at end of `#%s' argument", keyword->name);
  6501.  
  6502.     hp = lookup (buf, end-buf, -1);
  6503.  
  6504.     if (pcp_outfile) {
  6505.       /* Output a precondition for this macro.  */
  6506.       if (hp && hp->value.defn->predefined)
  6507.     fprintf (pcp_outfile, "#define %s\n", hp->name);
  6508.       else {
  6509.     U_CHAR *cp = buf;
  6510.     fprintf (pcp_outfile, "#undef ");
  6511.     while (is_idchar[*cp]) /* Ick! */
  6512.       fputc (*cp++, pcp_outfile);
  6513.     putc ('\n', pcp_outfile);
  6514.       }
  6515.     }
  6516.  
  6517.     skip = (hp == NULL) ^ (keyword->type == T_IFNDEF);
  6518.     if (start_of_file && !skip) {
  6519.       control_macro = (U_CHAR *) xmalloc (end - buf + 1);
  6520.       bcopy (buf, control_macro, end - buf);
  6521.       control_macro[end - buf] = 0;
  6522.     }
  6523.   }
  6524.   
  6525.   conditional_skip (ip, skip, T_IF, control_macro);
  6526.   return 0;
  6527. }
  6528.  
  6529. /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
  6530.    If this is a #ifndef starting at the beginning of a file,
  6531.    CONTROL_MACRO is the macro name tested by the #ifndef.
  6532.    Otherwise, CONTROL_MACRO is 0.  */
  6533.  
  6534. static void
  6535. conditional_skip (ip, skip, type, control_macro)
  6536.      FILE_BUF *ip;
  6537.      int skip;
  6538.      enum node_type type;
  6539.      U_CHAR *control_macro;
  6540. {
  6541.   IF_STACK_FRAME *temp;
  6542.  
  6543.   temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
  6544.   temp->fname = ip->nominal_fname;
  6545.   temp->lineno = ip->lineno;
  6546.   temp->next = if_stack;
  6547.   temp->control_macro = control_macro;
  6548.   if_stack = temp;
  6549.  
  6550.   if_stack->type = type;
  6551.  
  6552.   if (skip != 0) {
  6553.     skip_if_group (ip, 0);
  6554.     return;
  6555.   } else {
  6556.     ++if_stack->if_succeeded;
  6557.     output_line_command (ip, &outbuf, 1, same_file);
  6558.   }
  6559. }
  6560.  
  6561. /*
  6562.  * skip to #endif, #else, or #elif.  adjust line numbers, etc.
  6563.  * leaves input ptr at the sharp sign found.
  6564.  * If ANY is nonzero, return at next directive of any sort.
  6565.  */
  6566. static void
  6567. skip_if_group (ip, any)
  6568.      FILE_BUF *ip;
  6569.      int any;
  6570. {
  6571.   register U_CHAR *bp = ip->bufp, *cp;
  6572.   register U_CHAR *endb = ip->buf + ip->length;
  6573.   struct directive *kt;
  6574.   IF_STACK_FRAME *save_if_stack = if_stack; /* don't pop past here */
  6575.   U_CHAR *beg_of_line = bp;
  6576.   register int ident_length;
  6577.   U_CHAR *ident, *after_ident;
  6578.  
  6579.   while (bp < endb) {
  6580.     switch (*bp++) {
  6581.     case '/':            /* possible comment */
  6582.       if (*bp == '\\' && bp[1] == '\n')
  6583.     newline_fix (bp);
  6584.       if (*bp == '*'
  6585.       || (cplusplus_comments && *bp == '/')) {
  6586.     ip->bufp = ++bp;
  6587.     bp = skip_to_end_of_comment (ip, &ip->lineno, 0);
  6588.       }
  6589.       break;
  6590.     case '\"':
  6591.     case '\'':
  6592.       bp = skip_quoted_string (bp - 1, endb, ip->lineno, &ip->lineno,
  6593.                    NULL_PTR, NULL_PTR);
  6594.       break;
  6595.     case '\\':
  6596.       /* Char after backslash loses its special meaning.  */
  6597.       if (bp < endb) {
  6598.     if (*bp == '\n')
  6599.       ++ip->lineno;        /* But do update the line-count.  */
  6600.     bp++;
  6601.       }
  6602.       break;
  6603.     case '\n':
  6604.       ++ip->lineno;
  6605.       beg_of_line = bp;
  6606.       break;
  6607.     case '#':
  6608.       ip->bufp = bp - 1;
  6609.  
  6610.       /* # keyword: a # must be first nonblank char on the line */
  6611.       if (beg_of_line == 0)
  6612.     break;
  6613.       /* Scan from start of line, skipping whitespace, comments
  6614.      and backslash-newlines, and see if we reach this #.
  6615.      If not, this # is not special.  */
  6616.       bp = beg_of_line;
  6617.       /* If -traditional, require # to be at beginning of line.  */
  6618.       if (!traditional)
  6619.     while (1) {
  6620.       if (is_hor_space[*bp])
  6621.         bp++;
  6622.       else if (*bp == '\\' && bp[1] == '\n')
  6623.         bp += 2;
  6624.       else if (*bp == '/' && bp[1] == '*') {
  6625.         bp += 2;
  6626.         while (!(*bp == '*' && bp[1] == '/'))
  6627.           bp++;
  6628.         bp += 2;
  6629.       } else if (cplusplus_comments && *bp == '/' && bp[1] == '/') {
  6630.         bp += 2;
  6631.         while (*bp++ != '\n') ;
  6632.       }
  6633.       else break;
  6634.     }
  6635.       if (bp != ip->bufp) {
  6636.     bp = ip->bufp + 1;    /* Reset bp to after the #.  */
  6637.     break;
  6638.       }
  6639.  
  6640.       bp = ip->bufp + 1;    /* Point after the '#' */
  6641.  
  6642.       /* Skip whitespace and \-newline.  */
  6643.       while (1) {
  6644.     if (is_hor_space[*bp])
  6645.       bp++;
  6646.     else if (*bp == '\\' && bp[1] == '\n')
  6647.       bp += 2;
  6648.     else if (*bp == '/' && bp[1] == '*') {
  6649.       bp += 2;
  6650.       while (!(*bp == '*' && bp[1] == '/')) {
  6651.         if (*bp == '\n')
  6652.           ip->lineno++;
  6653.         bp++;
  6654.       }
  6655.       bp += 2;
  6656.     } else if (cplusplus_comments && *bp == '/' && bp[1] == '/') {
  6657.       bp += 2;
  6658.       while (*bp++ != '\n') ;
  6659.         }
  6660.     else break;
  6661.       }
  6662.  
  6663.       cp = bp;
  6664.  
  6665.       /* Now find end of directive name.
  6666.      If we encounter a backslash-newline, exchange it with any following
  6667.      symbol-constituents so that we end up with a contiguous name.  */
  6668.  
  6669.       while (1) {
  6670.     if (is_idchar[*bp])
  6671.       bp++;
  6672.     else {
  6673.       if (*bp == '\\' && bp[1] == '\n')
  6674.         name_newline_fix (bp);
  6675.       if (is_idchar[*bp])
  6676.         bp++;
  6677.       else break;
  6678.     }
  6679.       }
  6680.       ident_length = bp - cp;
  6681.       ident = cp;
  6682.       after_ident = bp;
  6683.  
  6684.       /* A line of just `#' becomes blank.  */
  6685.  
  6686.       if (ident_length == 0 && *after_ident == '\n') {
  6687.     continue;
  6688.       }
  6689.  
  6690.       if (ident_length == 0 || !is_idstart[*ident]) {
  6691.     U_CHAR *p = ident;
  6692.     while (is_idchar[*p]) {
  6693.       if (*p < '0' || *p > '9')
  6694.         break;
  6695.       p++;
  6696.     }
  6697.     /* Handle # followed by a line number.  */
  6698.     if (p != ident && !is_idchar[*p]) {
  6699.       if (pedantic)
  6700.         pedwarn ("`#' followed by integer");
  6701.       continue;
  6702.     }
  6703.  
  6704.     /* Avoid error for `###' and similar cases unless -pedantic.  */
  6705.     if (p == ident) {
  6706.       while (*p == '#' || is_hor_space[*p]) p++;
  6707.       if (*p == '\n') {
  6708.         if (pedantic && !lang_asm)
  6709.           pedwarn ("invalid preprocessor directive");
  6710.         continue;
  6711.       }
  6712.     }
  6713.  
  6714.     if (!lang_asm && pedantic)
  6715.       pedwarn ("invalid preprocessor directive name");
  6716.     continue;
  6717.       }
  6718.  
  6719.       for (kt = directive_table; kt->length >= 0; kt++) {
  6720.     IF_STACK_FRAME *temp;
  6721.     if (ident_length == kt->length
  6722.         && strncmp (cp, kt->name, kt->length) == 0) {
  6723.       /* If we are asked to return on next directive, do so now.  */
  6724.       if (any)
  6725.         return;
  6726.  
  6727.       switch (kt->type) {
  6728.       case T_IF:
  6729.       case T_IFDEF:
  6730.       case T_IFNDEF:
  6731.         temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
  6732.         temp->next = if_stack;
  6733.         if_stack = temp;
  6734.         temp->lineno = ip->lineno;
  6735.         temp->fname = ip->nominal_fname;
  6736.         temp->type = kt->type;
  6737.         break;
  6738.       case T_ELSE:
  6739.       case T_ENDIF:
  6740.         if (pedantic && if_stack != save_if_stack)
  6741.           validate_else (bp);
  6742.       case T_ELIF:
  6743.         if (if_stack == instack[indepth].if_stack) {
  6744.           error ("`#%s' not within a conditional", kt->name);
  6745.           break;
  6746.         }
  6747.         else if (if_stack == save_if_stack)
  6748.           return;        /* found what we came for */
  6749.  
  6750.         if (kt->type != T_ENDIF) {
  6751.           if (if_stack->type == T_ELSE)
  6752.         error ("`#else' or `#elif' after `#else'");
  6753.           if_stack->type = kt->type;
  6754.           break;
  6755.         }
  6756.  
  6757.         temp = if_stack;
  6758.         if_stack = if_stack->next;
  6759.         free (temp);
  6760.         break;
  6761.       }
  6762.       break;
  6763.     }
  6764.       }
  6765.       /* Don't let erroneous code go by.  */
  6766.       if (kt->length < 0 && !lang_asm && pedantic)
  6767.     pedwarn ("invalid preprocessor directive name");
  6768.     }
  6769.   }
  6770.   ip->bufp = bp;
  6771.   /* after this returns, rescan will exit because ip->bufp
  6772.      now points to the end of the buffer.
  6773.      rescan is responsible for the error message also.  */
  6774. }
  6775.  
  6776. /*
  6777.  * handle a #else directive.  Do this by just continuing processing
  6778.  * without changing  if_stack ;  this is so that the error message
  6779.  * for missing #endif's etc. will point to the original #if.  It
  6780.  * is possible that something different would be better.
  6781.  */
  6782.  
  6783. static int
  6784. do_else (buf, limit, op, keyword)
  6785.      U_CHAR *buf, *limit;
  6786.      FILE_BUF *op;
  6787.      struct directive *keyword;
  6788. {
  6789.   FILE_BUF *ip = &instack[indepth];
  6790.  
  6791.   if (pedantic) {
  6792.     SKIP_WHITE_SPACE (buf);
  6793.     if (buf != limit)
  6794.       pedwarn ("text following `#else' violates ANSI standard");
  6795.   }
  6796.  
  6797.   if (if_stack == instack[indepth].if_stack) {
  6798.     error ("`#else' not within a conditional");
  6799.     return 0;
  6800.   } else {
  6801.     /* #ifndef can't have its special treatment for containing the whole file
  6802.        if it has a #else clause.  */
  6803.     if_stack->control_macro = 0;
  6804.  
  6805.     if (if_stack->type != T_IF && if_stack->type != T_ELIF) {
  6806.       error ("`#else' after `#else'");
  6807.       fprintf (stderr, " (matches line %d", if_stack->lineno);
  6808.       if (strcmp (if_stack->fname, ip->nominal_fname) != 0)
  6809.     fprintf (stderr, ", file %s", if_stack->fname);
  6810.       fprintf (stderr, ")\n");
  6811.     }
  6812.     if_stack->type = T_ELSE;
  6813.   }
  6814.  
  6815.   if (if_stack->if_succeeded)
  6816.     skip_if_group (ip, 0);
  6817.   else {
  6818.     ++if_stack->if_succeeded;    /* continue processing input */
  6819.     output_line_command (ip, op, 1, same_file);
  6820.   }
  6821.   return 0;
  6822. }
  6823.  
  6824. /*
  6825.  * unstack after #endif command
  6826.  */
  6827.  
  6828. static int
  6829. do_endif (buf, limit, op, keyword)
  6830.      U_CHAR *buf, *limit;
  6831.      FILE_BUF *op;
  6832.      struct directive *keyword;
  6833. {
  6834.   if (pedantic) {
  6835.     SKIP_WHITE_SPACE (buf);
  6836.     if (buf != limit)
  6837.       pedwarn ("text following `#endif' violates ANSI standard");
  6838.   }
  6839.  
  6840.   if (if_stack == instack[indepth].if_stack)
  6841.     error ("unbalanced `#endif'");
  6842.   else {
  6843.     IF_STACK_FRAME *temp = if_stack;
  6844.     if_stack = if_stack->next;
  6845.     if (temp->control_macro != 0) {
  6846.       /* This #endif matched a #ifndef at the start of the file.
  6847.      See if it is at the end of the file.  */
  6848.       FILE_BUF *ip = &instack[indepth];
  6849.       U_CHAR *p = ip->bufp;
  6850.       U_CHAR *ep = ip->buf + ip->length;
  6851.  
  6852.       while (p != ep) {
  6853.     U_CHAR c = *p++;
  6854.     switch (c) {
  6855.     case ' ':
  6856.     case '\t':
  6857.     case '\n':
  6858.       break;
  6859.     case '/':
  6860.       if (p != ep && *p == '*') {
  6861.         /* Skip this comment.  */
  6862.         int junk;
  6863.         U_CHAR *save_bufp = ip->bufp;
  6864.         ip->bufp = p + 1;
  6865.         p = skip_to_end_of_comment (ip, &junk, 1);
  6866.         ip->bufp = save_bufp;
  6867.       }
  6868.       break;
  6869.     default:
  6870.       goto fail;
  6871.     }
  6872.       }
  6873.       /* If we get here, this #endif ends a #ifndef
  6874.      that contains all of the file (aside from whitespace).
  6875.      Arrange not to include the file again
  6876.      if the macro that was tested is defined.  */
  6877.       if (indepth != 0)
  6878.     record_control_macro (ip->fname, temp->control_macro);
  6879.     fail: ;
  6880.     }
  6881.     free (temp);
  6882.     output_line_command (&instack[indepth], op, 1, same_file);
  6883.   }
  6884.   return 0;
  6885. }
  6886.  
  6887. /* When an #else or #endif is found while skipping failed conditional,
  6888.    if -pedantic was specified, this is called to warn about text after
  6889.    the command name.  P points to the first char after the command name.  */
  6890.  
  6891. static void
  6892. validate_else (p)
  6893.      register U_CHAR *p;
  6894. {
  6895.   /* Advance P over whitespace and comments.  */
  6896.   while (1) {
  6897.     if (*p == '\\' && p[1] == '\n')
  6898.       p += 2;
  6899.     if (is_hor_space[*p])
  6900.       p++;
  6901.     else if (*p == '/') {
  6902.       if (p[1] == '\\' && p[2] == '\n')
  6903.     newline_fix (p + 1);
  6904.       if (p[1] == '*') {
  6905.     p += 2;
  6906.     /* Don't bother warning about unterminated comments
  6907.        since that will happen later.  Just be sure to exit.  */
  6908.     while (*p) {
  6909.       if (p[1] == '\\' && p[2] == '\n')
  6910.         newline_fix (p + 1);
  6911.       if (*p == '*' && p[1] == '/') {
  6912.         p += 2;
  6913.         break;
  6914.       }
  6915.       p++;
  6916.     }
  6917.       }
  6918.       else if (cplusplus_comments && p[1] == '/') {
  6919.     p += 2;
  6920.     while (*p && *p++ != '\n') ;
  6921.       }
  6922.     } else break;
  6923.   }
  6924.   if (*p && *p != '\n')
  6925.     pedwarn ("text following `#else' or `#endif' violates ANSI standard");
  6926. }
  6927.  
  6928. /* Skip a comment, assuming the input ptr immediately follows the
  6929.    initial slash-star.  Bump *LINE_COUNTER for each newline.
  6930.    (The canonical line counter is &ip->lineno.)
  6931.    Don't use this routine (or the next one) if bumping the line
  6932.    counter is not sufficient to deal with newlines in the string.
  6933.  
  6934.    If NOWARN is nonzero, don't warn about slash-star inside a comment.
  6935.    This feature is useful when processing a comment that is going to be
  6936.    processed or was processed at another point in the preprocessor,
  6937.    to avoid a duplicate warning.  */
  6938. static U_CHAR *
  6939. skip_to_end_of_comment (ip, line_counter, nowarn)
  6940.      register FILE_BUF *ip;
  6941.      int *line_counter;        /* place to remember newlines, or NULL */
  6942.      int nowarn;
  6943. {
  6944.   register U_CHAR *limit = ip->buf + ip->length;
  6945.   register U_CHAR *bp = ip->bufp;
  6946.   FILE_BUF *op = &outbuf;    /* JF */
  6947.   int output = put_out_comments && !line_counter;
  6948.  
  6949.     /* JF this line_counter stuff is a crock to make sure the
  6950.        comment is only put out once, no matter how many times
  6951.        the comment is skipped.  It almost works */
  6952.   if (output) {
  6953.     *op->bufp++ = '/';
  6954.     *op->bufp++ = '*';
  6955.   }
  6956.   if (cplusplus_comments && bp[-1] == '/') {
  6957.     if (output) {
  6958.       while (bp < limit)
  6959.     if ((*op->bufp++ = *bp++) == '\n') {
  6960.       bp--;
  6961.       break;
  6962.     }
  6963.       op->bufp[-1] = '*';
  6964.       *op->bufp++ = '/';
  6965.       *op->bufp++ = '\n';
  6966.     } else {
  6967.       while (bp < limit) {
  6968.     if (*bp++ == '\n') {
  6969.       bp--;
  6970.       break;
  6971.     }
  6972.       }
  6973.     }
  6974.     ip->bufp = bp;
  6975.     return bp;
  6976.   }
  6977.   while (bp < limit) {
  6978.     if (output)
  6979.       *op->bufp++ = *bp;
  6980.     switch (*bp++) {
  6981.     case '/':
  6982.       if (warn_comments && !nowarn && bp < limit && *bp == '*')
  6983.     warning ("`/*' within comment");
  6984.       break;
  6985.     case '\n':
  6986.       if (line_counter != NULL)
  6987.     ++*line_counter;
  6988.       if (output)
  6989.     ++op->lineno;
  6990.       break;
  6991.     case '*':
  6992.       if (*bp == '\\' && bp[1] == '\n')
  6993.     newline_fix (bp);
  6994.       if (*bp == '/') {
  6995.         if (output)
  6996.       *op->bufp++ = '/';
  6997.     ip->bufp = ++bp;
  6998.     return bp;
  6999.       }
  7000.       break;
  7001.     }
  7002.   }
  7003.   ip->bufp = bp;
  7004.   return bp;
  7005. }
  7006.  
  7007. /*
  7008.  * Skip over a quoted string.  BP points to the opening quote.
  7009.  * Returns a pointer after the closing quote.  Don't go past LIMIT.
  7010.  * START_LINE is the line number of the starting point (but it need
  7011.  * not be valid if the starting point is inside a macro expansion).
  7012.  *
  7013.  * The input stack state is not changed.
  7014.  *
  7015.  * If COUNT_NEWLINES is nonzero, it points to an int to increment
  7016.  * for each newline passed.
  7017.  *
  7018.  * If BACKSLASH_NEWLINES_P is nonzero, store 1 thru it
  7019.  * if we pass a backslash-newline.
  7020.  *
  7021.  * If EOFP is nonzero, set *EOFP to 1 if the string is unterminated.
  7022.  */
  7023. static U_CHAR *
  7024. skip_quoted_string (bp, limit, start_line, count_newlines, backslash_newlines_p, eofp)
  7025.      register U_CHAR *bp;
  7026.      register U_CHAR *limit;
  7027.      int start_line;
  7028.      int *count_newlines;
  7029.      int *backslash_newlines_p;
  7030.      int *eofp;
  7031. {
  7032.   register U_CHAR c, match;
  7033.  
  7034.   match = *bp++;
  7035.   while (1) {
  7036.     if (bp >= limit) {
  7037.       error_with_line (line_for_error (start_line),
  7038.                "unterminated string or character constant");
  7039.       error_with_line (multiline_string_line,
  7040.                "possible real start of unterminated constant");
  7041.       multiline_string_line = 0;
  7042.       if (eofp)
  7043.     *eofp = 1;
  7044.       break;
  7045.     }
  7046.     c = *bp++;
  7047.     if (c == '\\') {
  7048.       while (*bp == '\\' && bp[1] == '\n') {
  7049.     if (backslash_newlines_p)
  7050.       *backslash_newlines_p = 1;
  7051.     if (count_newlines)
  7052.       ++*count_newlines;
  7053.     bp += 2;
  7054.       }
  7055.       if (*bp == '\n' && count_newlines) {
  7056.     if (backslash_newlines_p)
  7057.       *backslash_newlines_p = 1;
  7058.     ++*count_newlines;
  7059.       }
  7060.       bp++;
  7061.     } else if (c == '\n') {
  7062.       if (traditional) {
  7063.      /* Unterminated strings and character constants are 'legal'.  */
  7064.      bp--;    /* Don't consume the newline. */
  7065.      if (eofp)
  7066.        *eofp = 1;
  7067.      break;
  7068.       }
  7069.       if (pedantic || match == '\'') {
  7070.     error_with_line (line_for_error (start_line),
  7071.              "unterminated string or character constant");
  7072.     bp--;
  7073.     if (eofp)
  7074.       *eofp = 1;
  7075.     break;
  7076.       }
  7077.       /* If not traditional, then allow newlines inside strings.  */
  7078.       if (count_newlines)
  7079.     ++*count_newlines;
  7080.       if (multiline_string_line == 0)
  7081.     multiline_string_line = start_line;
  7082.     } else if (c == match)
  7083.       break;
  7084.   }
  7085.   return bp;
  7086. }
  7087.  
  7088. /* Place into DST a quoted string representing the string SRC.
  7089.    Return the address of DST's terminating null.  */
  7090. static char *
  7091. quote_string (dst, src)
  7092.      char *dst, *src;
  7093. {
  7094.   U_CHAR c;
  7095.  
  7096.   *dst++ = '\"';
  7097.   for (;;)
  7098.     switch ((c = *src++))
  7099.       {
  7100.       default:
  7101.         if (isprint (c))
  7102.       *dst++ = c;
  7103.     else
  7104.       {
  7105.         sprintf (dst, "\\%03o", c);
  7106.         dst += 4;
  7107.       }
  7108.     break;
  7109.  
  7110.       case '\"':
  7111.       case '\\':
  7112.     *dst++ = '\\';
  7113.     *dst++ = c;
  7114.     break;
  7115.       
  7116.       case '\0':
  7117.     *dst++ = '\"';
  7118.     *dst = '\0';
  7119.     return dst;
  7120.       }
  7121. }
  7122.  
  7123. /* Skip across a group of balanced parens, starting from IP->bufp.
  7124.    IP->bufp is updated.  Use this with IP->bufp pointing at an open-paren.
  7125.  
  7126.    This does not handle newlines, because it's used for the arg of #if,
  7127.    where there aren't any newlines.  Also, backslash-newline can't appear.  */
  7128.  
  7129. static U_CHAR *
  7130. skip_paren_group (ip)
  7131.      register FILE_BUF *ip;
  7132. {
  7133.   U_CHAR *limit = ip->buf + ip->length;
  7134.   U_CHAR *p = ip->bufp;
  7135.   int depth = 0;
  7136.   int lines_dummy = 0;
  7137.  
  7138.   while (p != limit) {
  7139.     int c = *p++;
  7140.     switch (c) {
  7141.     case '(':
  7142.       depth++;
  7143.       break;
  7144.  
  7145.     case ')':
  7146.       depth--;
  7147.       if (depth == 0)
  7148.     return ip->bufp = p;
  7149.       break;
  7150.  
  7151.     case '/':
  7152.       if (*p == '*') {
  7153.     ip->bufp = p;
  7154.     p = skip_to_end_of_comment (ip, &lines_dummy, 0);
  7155.     p = ip->bufp;
  7156.       }
  7157.  
  7158.     case '"':
  7159.     case '\'':
  7160.       {
  7161.     int eofp = 0;
  7162.     p = skip_quoted_string (p - 1, limit, 0, NULL_PTR, NULL_PTR, &eofp);
  7163.     if (eofp)
  7164.       return ip->bufp = p;
  7165.       }
  7166.       break;
  7167.     }
  7168.   }
  7169.  
  7170.   ip->bufp = p;
  7171.   return p;
  7172. }
  7173.  
  7174. /*
  7175.  * write out a #line command, for instance, after an #include file.
  7176.  * If CONDITIONAL is nonzero, we can omit the #line if it would
  7177.  * appear to be a no-op, and we can output a few newlines instead
  7178.  * if we want to increase the line number by a small amount.
  7179.  * FILE_CHANGE says whether we are entering a file, leaving, or neither.
  7180.  */
  7181.  
  7182. static void
  7183. output_line_command (ip, op, conditional, file_change)
  7184.      FILE_BUF *ip, *op;
  7185.      int conditional;
  7186.      enum file_change_code file_change;
  7187. {
  7188.   int len;
  7189.   char *line_cmd_buf, *line_end;
  7190.  
  7191.   if (no_line_commands
  7192.       || ip->fname == NULL
  7193.       || no_output) {
  7194.     op->lineno = ip->lineno;
  7195.     return;
  7196.   }
  7197.  
  7198.   if (conditional) {
  7199.     if (ip->lineno == op->lineno)
  7200.       return;
  7201.  
  7202.     /* If the inherited line number is a little too small,
  7203.        output some newlines instead of a #line command.  */
  7204.     if (ip->lineno > op->lineno && ip->lineno < op->lineno + 8) {
  7205.       check_expand (op, 10);
  7206.       while (ip->lineno > op->lineno) {
  7207.     *op->bufp++ = '\n';
  7208.     op->lineno++;
  7209.       }
  7210.       return;
  7211.     }
  7212.   }
  7213.  
  7214.   /* Don't output a line number of 0 if we can help it.  */
  7215.   if (ip->lineno == 0 && ip->bufp - ip->buf < ip->length
  7216.       && *ip->bufp == '\n') {
  7217.     ip->lineno++;
  7218.     ip->bufp++;
  7219.   }
  7220.  
  7221.   line_cmd_buf = (char *) alloca (4 * strlen (ip->nominal_fname) + 100);
  7222. #ifdef OUTPUT_LINE_COMMANDS
  7223.   sprintf (line_cmd_buf, "#line %d ", ip->lineno);
  7224. #else
  7225.   sprintf (line_cmd_buf, "# %d ", ip->lineno);
  7226. #endif
  7227.   line_end = quote_string (line_cmd_buf + strlen (line_cmd_buf),
  7228.                ip->nominal_fname);
  7229.   if (file_change != same_file) {
  7230.     *line_end++ = ' ';
  7231.     *line_end++ = file_change == enter_file ? '1' : '2';
  7232.   }
  7233.   /* Tell cc1 if following text comes from a system header file.  */
  7234.   if (ip->system_header_p) {
  7235.     *line_end++ = ' ';
  7236.     *line_end++ = '3';
  7237.   }
  7238. #ifndef NO_IMPLICIT_EXTERN_C
  7239.   /* Tell cc1plus if following text should be treated as C.  */
  7240.   if (ip->system_header_p == 2 && cplusplus) {
  7241.     *line_end++ = ' ';
  7242.     *line_end++ = '4';
  7243.   }
  7244. #endif
  7245.   *line_end++ = '\n';
  7246.   len = line_end - line_cmd_buf;
  7247.   check_expand (op, len + 1);
  7248.   if (op->bufp > op->buf && op->bufp[-1] != '\n')
  7249.     *op->bufp++ = '\n';
  7250.   bcopy (line_cmd_buf, op->bufp, len);
  7251.   op->bufp += len;
  7252.   op->lineno = ip->lineno;
  7253. }
  7254.  
  7255. /* This structure represents one parsed argument in a macro call.
  7256.    `raw' points to the argument text as written (`raw_length' is its length).
  7257.    `expanded' points to the argument's macro-expansion
  7258.    (its length is `expand_length').
  7259.    `stringified_length' is the length the argument would have
  7260.    if stringified.
  7261.    `use_count' is the number of times this macro arg is substituted
  7262.    into the macro.  If the actual use count exceeds 10, 
  7263.    the value stored is 10.
  7264.    `free1' and `free2', if nonzero, point to blocks to be freed
  7265.    when the macro argument data is no longer needed.  */
  7266.  
  7267. struct argdata {
  7268.   U_CHAR *raw, *expanded;
  7269.   int raw_length, expand_length;
  7270.   int stringified_length;
  7271.   U_CHAR *free1, *free2;
  7272.   char newlines;
  7273.   char comments;
  7274.   char use_count;
  7275. };
  7276.  
  7277. /* Expand a macro call.
  7278.    HP points to the symbol that is the macro being called.
  7279.    Put the result of expansion onto the input stack
  7280.    so that subsequent input by our caller will use it.
  7281.  
  7282.    If macro wants arguments, caller has already verified that
  7283.    an argument list follows; arguments come from the input stack.  */
  7284.  
  7285. static void
  7286. macroexpand (hp, op)
  7287.      HASHNODE *hp;
  7288.      FILE_BUF *op;
  7289. {
  7290.   int nargs;
  7291.   DEFINITION *defn = hp->value.defn;
  7292.   register U_CHAR *xbuf;
  7293.   int xbuf_len;
  7294.   int start_line = instack[indepth].lineno;
  7295.   int rest_args, rest_zero;
  7296.  
  7297.   CHECK_DEPTH (return;);
  7298.  
  7299.   /* it might not actually be a macro.  */
  7300.   if (hp->type != T_MACRO) {
  7301.     special_symbol (hp, op);
  7302.     return;
  7303.   }
  7304.  
  7305.   /* This macro is being used inside a #if, which means it must be */
  7306.   /* recorded as a precondition.  */
  7307.   if (pcp_inside_if && pcp_outfile && defn->predefined)
  7308.     dump_single_macro (hp, pcp_outfile);
  7309.   
  7310.   nargs = defn->nargs;
  7311.  
  7312.   if (nargs >= 0) {
  7313.     register int i;
  7314.     struct argdata *args;
  7315.     char *parse_error = 0;
  7316.  
  7317.     args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata));
  7318.  
  7319.     for (i = 0; i < nargs; i++) {
  7320.       args[i].raw = (U_CHAR *) "";
  7321.       args[i].expanded = 0;
  7322.       args[i].raw_length = args[i].expand_length
  7323.     = args[i].stringified_length = 0;
  7324.       args[i].free1 = args[i].free2 = 0;
  7325.       args[i].use_count = 0;
  7326.     }
  7327.  
  7328.     /* Parse all the macro args that are supplied.  I counts them.
  7329.        The first NARGS args are stored in ARGS.
  7330.        The rest are discarded.
  7331.        If rest_args is set then we assume macarg absorbed the rest of the args.
  7332.        */
  7333.     i = 0;
  7334.     rest_args = 0;
  7335.     do {
  7336.       /* Discard the open-parenthesis or comma before the next arg.  */
  7337.       ++instack[indepth].bufp;
  7338.       if (rest_args)
  7339.     continue;
  7340.       if (i < nargs || (nargs == 0 && i == 0)) {
  7341.     /* if we are working on last arg which absorbs rest of args... */
  7342.     if (i == nargs - 1 && defn->rest_args)
  7343.       rest_args = 1;
  7344.     parse_error = macarg (&args[i], rest_args);
  7345.       }
  7346.       else
  7347.     parse_error = macarg (NULL_PTR, 0);
  7348.       if (parse_error) {
  7349.     error_with_line (line_for_error (start_line), parse_error);
  7350.     break;
  7351.       }
  7352.       i++;
  7353.     } while (*instack[indepth].bufp != ')');
  7354.  
  7355.     /* If we got one arg but it was just whitespace, call that 0 args.  */
  7356.     if (i == 1) {
  7357.       register U_CHAR *bp = args[0].raw;
  7358.       register U_CHAR *lim = bp + args[0].raw_length;
  7359.       /* cpp.texi says for foo ( ) we provide one argument.
  7360.      However, if foo wants just 0 arguments, treat this as 0.  */
  7361.       if (nargs == 0)
  7362.     while (bp != lim && is_space[*bp]) bp++;
  7363.       if (bp == lim)
  7364.     i = 0;
  7365.     }
  7366.  
  7367.     /* Don't output an error message if we have already output one for
  7368.        a parse error above.  */
  7369.     rest_zero = 0;
  7370.     if (nargs == 0 && i > 0) {
  7371.       if (! parse_error)
  7372.     error ("arguments given to macro `%s'", hp->name);
  7373.     } else if (i < nargs) {
  7374.       /* traditional C allows foo() if foo wants one argument.  */
  7375.       if (nargs == 1 && i == 0 && traditional)
  7376.     ;
  7377.       /* the rest args token is allowed to absorb 0 tokens */
  7378.       else if (i == nargs - 1 && defn->rest_args)
  7379.     rest_zero = 1;
  7380.       else if (parse_error)
  7381.     ;
  7382.       else if (i == 0)
  7383.     error ("macro `%s' used without args", hp->name);
  7384.       else if (i == 1)
  7385.     error ("macro `%s' used with just one arg", hp->name);
  7386.       else
  7387.     error ("macro `%s' used with only %d args", hp->name, i);
  7388.     } else if (i > nargs) {
  7389.       if (! parse_error)
  7390.     error ("macro `%s' used with too many (%d) args", hp->name, i);
  7391.     }
  7392.  
  7393.     /* Swallow the closeparen.  */
  7394.     ++instack[indepth].bufp;
  7395.  
  7396.     /* If macro wants zero args, we parsed the arglist for checking only.
  7397.        Read directly from the macro definition.  */
  7398.     if (nargs == 0) {
  7399.       xbuf = defn->expansion;
  7400.       xbuf_len = defn->length;
  7401.     } else {
  7402.       register U_CHAR *exp = defn->expansion;
  7403.       register int offset;    /* offset in expansion,
  7404.                    copied a piece at a time */
  7405.       register int totlen;    /* total amount of exp buffer filled so far */
  7406.  
  7407.       register struct reflist *ap, *last_ap;
  7408.  
  7409.       /* Macro really takes args.  Compute the expansion of this call.  */
  7410.  
  7411.       /* Compute length in characters of the macro's expansion.
  7412.      Also count number of times each arg is used.  */
  7413.       xbuf_len = defn->length;
  7414.       for (ap = defn->pattern; ap != NULL; ap = ap->next) {
  7415.     if (ap->stringify)
  7416.       xbuf_len += args[ap->argno].stringified_length;
  7417.     else if (ap->raw_before || ap->raw_after || traditional)
  7418.       /* Add 4 for two newline-space markers to prevent
  7419.          token concatenation.  */
  7420.       xbuf_len += args[ap->argno].raw_length + 4;
  7421.     else {
  7422.       /* We have an ordinary (expanded) occurrence of the arg.
  7423.          So compute its expansion, if we have not already.  */
  7424.       if (args[ap->argno].expanded == 0) {
  7425.         FILE_BUF obuf;
  7426.         obuf = expand_to_temp_buffer (args[ap->argno].raw,
  7427.                       args[ap->argno].raw + args[ap->argno].raw_length,
  7428.                       1, 0);
  7429.  
  7430.         args[ap->argno].expanded = obuf.buf;
  7431.         args[ap->argno].expand_length = obuf.length;
  7432.         args[ap->argno].free2 = obuf.buf;
  7433.       }
  7434.  
  7435.       /* Add 4 for two newline-space markers to prevent
  7436.          token concatenation.  */
  7437.       xbuf_len += args[ap->argno].expand_length + 4;
  7438.     }
  7439.     if (args[ap->argno].use_count < 10)
  7440.       args[ap->argno].use_count++;
  7441.       }
  7442.  
  7443.       xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
  7444.  
  7445.       /* Generate in XBUF the complete expansion
  7446.      with arguments substituted in.
  7447.      TOTLEN is the total size generated so far.
  7448.      OFFSET is the index in the definition
  7449.      of where we are copying from.  */
  7450.       offset = totlen = 0;
  7451.       for (last_ap = NULL, ap = defn->pattern; ap != NULL;
  7452.        last_ap = ap, ap = ap->next) {
  7453.     register struct argdata *arg = &args[ap->argno];
  7454.     int count_before = totlen;
  7455.  
  7456.     /* Add chars to XBUF.  */
  7457.     for (i = 0; i < ap->nchars; i++, offset++)
  7458.       xbuf[totlen++] = exp[offset];
  7459.  
  7460.     /* If followed by an empty rest arg with concatenation,
  7461.        delete the last run of nonwhite chars.  */
  7462.     if (rest_zero && totlen > count_before
  7463.         && ((ap->rest_args && ap->raw_before)
  7464.         || (last_ap != NULL && last_ap->rest_args
  7465.             && last_ap->raw_after))) {
  7466.       /* Delete final whitespace.  */
  7467.       while (totlen > count_before && is_space[xbuf[totlen - 1]]) {
  7468.         totlen--;
  7469.       }
  7470.  
  7471.       /* Delete the nonwhites before them.  */
  7472.       while (totlen > count_before && ! is_space[xbuf[totlen - 1]]) {
  7473.         totlen--;
  7474.       }
  7475.     }
  7476.  
  7477.     if (ap->stringify != 0) {
  7478.       int arglen = arg->raw_length;
  7479.       int escaped = 0;
  7480.       int in_string = 0;
  7481.       int c;
  7482.       i = 0;
  7483.       while (i < arglen
  7484.          && (c = arg->raw[i], is_space[c]))
  7485.         i++;
  7486.       while (i < arglen
  7487.          && (c = arg->raw[arglen - 1], is_space[c]))
  7488.         arglen--;
  7489.       if (!traditional)
  7490.         xbuf[totlen++] = '\"'; /* insert beginning quote */
  7491.       for (; i < arglen; i++) {
  7492.         c = arg->raw[i];
  7493.  
  7494.         /* Special markers Newline Space
  7495.            generate nothing for a stringified argument.  */
  7496.         if (c == '\n' && arg->raw[i+1] != '\n') {
  7497.           i++;
  7498.           continue;
  7499.         }
  7500.  
  7501.         /* Internal sequences of whitespace are replaced by one space
  7502.            except within an string or char token.  */
  7503.         if (! in_string
  7504.         && (c == '\n' ? arg->raw[i+1] == '\n' : is_space[c])) {
  7505.           while (1) {
  7506.         /* Note that Newline Space does occur within whitespace
  7507.            sequences; consider it part of the sequence.  */
  7508.         if (c == '\n' && is_space[arg->raw[i+1]])
  7509.           i += 2;
  7510.         else if (c != '\n' && is_space[c])
  7511.           i++;
  7512.         else break;
  7513.         c = arg->raw[i];
  7514.           }
  7515.           i--;
  7516.           c = ' ';
  7517.         }
  7518.  
  7519.         if (escaped)
  7520.           escaped = 0;
  7521.         else {
  7522.           if (c == '\\')
  7523.         escaped = 1;
  7524.           if (in_string) {
  7525.         if (c == in_string)
  7526.           in_string = 0;
  7527.           } else if (c == '\"' || c == '\'')
  7528.         in_string = c;
  7529.         }
  7530.  
  7531.         /* Escape these chars */
  7532.         if (c == '\"' || (in_string && c == '\\'))
  7533.           xbuf[totlen++] = '\\';
  7534.         if (isprint (c))
  7535.           xbuf[totlen++] = c;
  7536.         else {
  7537.           sprintf ((char *) &xbuf[totlen], "\\%03o", (unsigned int) c);
  7538.           totlen += 4;
  7539.         }
  7540.       }
  7541.       if (!traditional)
  7542.         xbuf[totlen++] = '\"'; /* insert ending quote */
  7543.     } else if (ap->raw_before || ap->raw_after || traditional) {
  7544.       U_CHAR *p1 = arg->raw;
  7545.       U_CHAR *l1 = p1 + arg->raw_length;
  7546.       if (ap->raw_before) {
  7547.         while (p1 != l1 && is_space[*p1]) p1++;
  7548.         while (p1 != l1 && is_idchar[*p1])
  7549.           xbuf[totlen++] = *p1++;
  7550.         /* Delete any no-reexpansion marker that follows
  7551.            an identifier at the beginning of the argument
  7552.            if the argument is concatenated with what precedes it.  */
  7553.         if (p1[0] == '\n' && p1[1] == '-')
  7554.           p1 += 2;
  7555.       } else if (!traditional) {
  7556.       /* Ordinary expanded use of the argument.
  7557.          Put in newline-space markers to prevent token pasting.  */
  7558.         xbuf[totlen++] = '\n';
  7559.         xbuf[totlen++] = ' ';
  7560.       }
  7561.       if (ap->raw_after) {
  7562.         /* Arg is concatenated after: delete trailing whitespace,
  7563.            whitespace markers, and no-reexpansion markers.  */
  7564.         while (p1 != l1) {
  7565.           if (is_space[l1[-1]]) l1--;
  7566.           else if (l1[-1] == '-') {
  7567.         U_CHAR *p2 = l1 - 1;
  7568.         /* If a `-' is preceded by an odd number of newlines then it
  7569.            and the last newline are a no-reexpansion marker.  */
  7570.         while (p2 != p1 && p2[-1] == '\n') p2--;
  7571.         if ((l1 - 1 - p2) & 1) {
  7572.           l1 -= 2;
  7573.         }
  7574.         else break;
  7575.           }
  7576.           else break;
  7577.         }
  7578.       }
  7579.  
  7580.       bcopy (p1, xbuf + totlen, l1 - p1);
  7581.       totlen += l1 - p1;
  7582.       if (!traditional && !ap->raw_after) {
  7583.         /* Ordinary expanded use of the argument.
  7584.            Put in newline-space markers to prevent token pasting.  */
  7585.         xbuf[totlen++] = '\n';
  7586.         xbuf[totlen++] = ' ';
  7587.       }
  7588.     } else {
  7589.       /* Ordinary expanded use of the argument.
  7590.          Put in newline-space markers to prevent token pasting.  */
  7591.       if (!traditional) {
  7592.         xbuf[totlen++] = '\n';
  7593.         xbuf[totlen++] = ' ';
  7594.       }
  7595.       bcopy (arg->expanded, xbuf + totlen, arg->expand_length);
  7596.       totlen += arg->expand_length;
  7597.       if (!traditional) {
  7598.         xbuf[totlen++] = '\n';
  7599.         xbuf[totlen++] = ' ';
  7600.       }
  7601.       /* If a macro argument with newlines is used multiple times,
  7602.          then only expand the newlines once.  This avoids creating output
  7603.          lines which don't correspond to any input line, which confuses
  7604.          gdb and gcov.  */
  7605.       if (arg->use_count > 1 && arg->newlines > 0) {
  7606.         /* Don't bother doing change_newlines for subsequent
  7607.            uses of arg.  */
  7608.         arg->use_count = 1;
  7609.         arg->expand_length
  7610.           = change_newlines (arg->expanded, arg->expand_length);
  7611.       }
  7612.     }
  7613.  
  7614.     if (totlen > xbuf_len)
  7615.       abort ();
  7616.       }
  7617.  
  7618.       /* if there is anything left of the definition
  7619.      after handling the arg list, copy that in too. */
  7620.  
  7621.       for (i = offset; i < defn->length; i++) {
  7622.     /* if we've reached the end of the macro */
  7623.     if (exp[i] == ')')
  7624.       rest_zero = 0;
  7625.     if (! (rest_zero && last_ap != NULL && last_ap->rest_args
  7626.            && last_ap->raw_after))
  7627.       xbuf[totlen++] = exp[i];
  7628.       }
  7629.  
  7630.       xbuf[totlen] = 0;
  7631.       xbuf_len = totlen;
  7632.  
  7633.       for (i = 0; i < nargs; i++) {
  7634.     if (args[i].free1 != 0)
  7635.       free (args[i].free1);
  7636.     if (args[i].free2 != 0)
  7637.       free (args[i].free2);
  7638.       }
  7639.     }
  7640.   } else {
  7641.     xbuf = defn->expansion;
  7642.     xbuf_len = defn->length;
  7643.   }
  7644.  
  7645.   /* Now put the expansion on the input stack
  7646.      so our caller will commence reading from it.  */
  7647.   {
  7648.     register FILE_BUF *ip2;
  7649.  
  7650.     ip2 = &instack[++indepth];
  7651.  
  7652.     ip2->fname = 0;
  7653.     ip2->nominal_fname = 0;
  7654.     ip2->lineno = 0;
  7655.     ip2->buf = xbuf;
  7656.     ip2->length = xbuf_len;
  7657.     ip2->bufp = xbuf;
  7658.     ip2->free_ptr = (nargs > 0) ? xbuf : 0;
  7659.     ip2->macro = hp;
  7660.     ip2->if_stack = if_stack;
  7661.     ip2->system_header_p = 0;
  7662.  
  7663.     /* Recursive macro use sometimes works traditionally.
  7664.        #define foo(x,y) bar (x (y,0), y)
  7665.        foo (foo, baz)  */
  7666.  
  7667.     if (!traditional)
  7668.       hp->type = T_DISABLED;
  7669.   }
  7670. }
  7671.  
  7672. /*
  7673.  * Parse a macro argument and store the info on it into *ARGPTR.
  7674.  * REST_ARGS is passed to macarg1 to make it absorb the rest of the args.
  7675.  * Return nonzero to indicate a syntax error.
  7676.  */
  7677.  
  7678. static char *
  7679. macarg (argptr, rest_args)
  7680.      register struct argdata *argptr;
  7681.      int rest_args;
  7682. {
  7683.   FILE_BUF *ip = &instack[indepth];
  7684.   int paren = 0;
  7685.   int newlines = 0;
  7686.   int comments = 0;
  7687.  
  7688.   /* Try to parse as much of the argument as exists at this
  7689.      input stack level.  */
  7690.   U_CHAR *bp = macarg1 (ip->bufp, ip->buf + ip->length,
  7691.             &paren, &newlines, &comments, rest_args);
  7692.  
  7693.   /* If we find the end of the argument at this level,
  7694.      set up *ARGPTR to point at it in the input stack.  */
  7695.   if (!(ip->fname != 0 && (newlines != 0 || comments != 0))
  7696.       && bp != ip->buf + ip->length) {
  7697.     if (argptr != 0) {
  7698.       argptr->raw = ip->bufp;
  7699.       argptr->raw_length = bp - ip->bufp;
  7700.       argptr->newlines = newlines;
  7701.     }
  7702.     ip->bufp = bp;
  7703.   } else {
  7704.     /* This input stack level ends before the macro argument does.
  7705.        We must pop levels and keep parsing.
  7706.        Therefore, we must allocate a temporary buffer and copy
  7707.        the macro argument into it.  */
  7708.     int bufsize = bp - ip->bufp;
  7709.     int extra = newlines;
  7710.     U_CHAR *buffer = (U_CHAR *) xmalloc (bufsize + extra + 1);
  7711.     int final_start = 0;
  7712.  
  7713.     bcopy (ip->bufp, buffer, bufsize);
  7714.     ip->bufp = bp;
  7715.     ip->lineno += newlines;
  7716.  
  7717.     while (bp == ip->buf + ip->length) {
  7718.       if (instack[indepth].macro == 0) {
  7719.     free (buffer);
  7720.     return "unterminated macro call";
  7721.       }
  7722.       ip->macro->type = T_MACRO;
  7723.       if (ip->free_ptr)
  7724.     free (ip->free_ptr);
  7725.       ip = &instack[--indepth];
  7726.       newlines = 0;
  7727.       comments = 0;
  7728.       bp = macarg1 (ip->bufp, ip->buf + ip->length, &paren,
  7729.             &newlines, &comments, rest_args);
  7730.       final_start = bufsize;
  7731.       bufsize += bp - ip->bufp;
  7732.       extra += newlines;
  7733.       buffer = (U_CHAR *) xrealloc (buffer, bufsize + extra + 1);
  7734.       bcopy (ip->bufp, buffer + bufsize - (bp - ip->bufp), bp - ip->bufp);
  7735.       ip->bufp = bp;
  7736.       ip->lineno += newlines;
  7737.     }
  7738.  
  7739.     /* Now, if arg is actually wanted, record its raw form,
  7740.        discarding comments and duplicating newlines in whatever
  7741.        part of it did not come from a macro expansion.
  7742.        EXTRA space has been preallocated for duplicating the newlines.
  7743.        FINAL_START is the index of the start of that part.  */
  7744.     if (argptr != 0) {
  7745.       argptr->raw = buffer;
  7746.       argptr->raw_length = bufsize;
  7747.       argptr->free1 = buffer;
  7748.       argptr->newlines = newlines;
  7749.       argptr->comments = comments;
  7750.       if ((newlines || comments) && ip->fname != 0)
  7751.     argptr->raw_length
  7752.       = final_start +
  7753.         discard_comments (argptr->raw + final_start,
  7754.                   argptr->raw_length - final_start,
  7755.                   newlines);
  7756.       argptr->raw[argptr->raw_length] = 0;
  7757.       if (argptr->raw_length > bufsize + extra)
  7758.     abort ();
  7759.     }
  7760.   }
  7761.  
  7762.   /* If we are not discarding this argument,
  7763.      macroexpand it and compute its length as stringified.
  7764.      All this info goes into *ARGPTR.  */
  7765.  
  7766.   if (argptr != 0) {
  7767.     register U_CHAR *buf, *lim;
  7768.     register int totlen;
  7769.  
  7770.     buf = argptr->raw;
  7771.     lim = buf + argptr->raw_length;
  7772.  
  7773.     while (buf != lim && is_space[*buf])
  7774.       buf++;
  7775.     while (buf != lim && is_space[lim[-1]])
  7776.       lim--;
  7777.     totlen = traditional ? 0 : 2;    /* Count opening and closing quote.  */
  7778.     while (buf != lim) {
  7779.       register U_CHAR c = *buf++;
  7780.       totlen++;
  7781.       /* Internal sequences of whitespace are replaced by one space
  7782.      in most cases, but not always.  So count all the whitespace
  7783.      in case we need to keep it all.  */
  7784. #if 0
  7785.       if (is_space[c])
  7786.     SKIP_ALL_WHITE_SPACE (buf);
  7787.       else
  7788. #endif
  7789.       if (c == '\"' || c == '\\') /* escape these chars */
  7790.     totlen++;
  7791.       else if (!isprint (c))
  7792.     totlen += 3;
  7793.     }
  7794.     argptr->stringified_length = totlen;
  7795.   }
  7796.   return 0;
  7797. }
  7798.  
  7799. /* Scan text from START (inclusive) up to LIMIT (exclusive),
  7800.    counting parens in *DEPTHPTR,
  7801.    and return if reach LIMIT
  7802.    or before a `)' that would make *DEPTHPTR negative
  7803.    or before a comma when *DEPTHPTR is zero.
  7804.    Single and double quotes are matched and termination
  7805.    is inhibited within them.  Comments also inhibit it.
  7806.    Value returned is pointer to stopping place.
  7807.  
  7808.    Increment *NEWLINES each time a newline is passed.
  7809.    REST_ARGS notifies macarg1 that it should absorb the rest of the args.
  7810.    Set *COMMENTS to 1 if a comment is seen.  */
  7811.  
  7812. static U_CHAR *
  7813. macarg1 (start, limit, depthptr, newlines, comments, rest_args)
  7814.      U_CHAR *start;
  7815.      register U_CHAR *limit;
  7816.      int *depthptr, *newlines, *comments;
  7817.      int rest_args;
  7818. {
  7819.   register U_CHAR *bp = start;
  7820.  
  7821.   while (bp < limit) {
  7822.     switch (*bp) {
  7823.     case '(':
  7824.       (*depthptr)++;
  7825.       break;
  7826.     case ')':
  7827.       if (--(*depthptr) < 0)
  7828.     return bp;
  7829.       break;
  7830.     case '\\':
  7831.       /* Traditionally, backslash makes following char not special.  */
  7832.       if (bp + 1 < limit && traditional)
  7833.     {
  7834.       bp++;
  7835.       /* But count source lines anyway.  */
  7836.       if (*bp == '\n')
  7837.         ++*newlines;
  7838.     }
  7839.       break;
  7840.     case '\n':
  7841.       ++*newlines;
  7842.       break;
  7843.     case '/':
  7844.       if (bp[1] == '\\' && bp[2] == '\n')
  7845.     newline_fix (bp + 1);
  7846.       if (cplusplus_comments && bp[1] == '/') {
  7847.     *comments = 1;
  7848.     bp += 2;
  7849.     while (bp < limit && *bp++ != '\n') ;
  7850.     ++*newlines;
  7851.     break;
  7852.       }
  7853.       if (bp[1] != '*' || bp + 1 >= limit)
  7854.     break;
  7855.       *comments = 1;
  7856.       bp += 2;
  7857.       while (bp + 1 < limit) {
  7858.     if (bp[0] == '*'
  7859.         && bp[1] == '\\' && bp[2] == '\n')
  7860.       newline_fix (bp + 1);
  7861.     if (bp[0] == '*' && bp[1] == '/')
  7862.       break;
  7863.     if (*bp == '\n') ++*newlines;
  7864.     bp++;
  7865.       }
  7866.       break;
  7867.     case '\'':
  7868.     case '\"':
  7869.       {
  7870.     int quotec;
  7871.     for (quotec = *bp++; bp + 1 < limit && *bp != quotec; bp++) {
  7872.       if (*bp == '\\') {
  7873.         bp++;
  7874.         if (*bp == '\n')
  7875.           ++*newlines;
  7876.         while (*bp == '\\' && bp[1] == '\n') {
  7877.           bp += 2;
  7878.         }
  7879.       } else if (*bp == '\n') {
  7880.         ++*newlines;
  7881.         if (quotec == '\'')
  7882.           break;
  7883.       }
  7884.     }
  7885.       }
  7886.       break;
  7887.     case ',':
  7888.       /* if we've returned to lowest level and we aren't absorbing all args */
  7889.       if ((*depthptr) == 0 && rest_args == 0)
  7890.     return bp;
  7891.       break;
  7892.     }
  7893.     bp++;
  7894.   }
  7895.  
  7896.   return bp;
  7897. }
  7898.  
  7899. /* Discard comments and duplicate newlines
  7900.    in the string of length LENGTH at START,
  7901.    except inside of string constants.
  7902.    The string is copied into itself with its beginning staying fixed.  
  7903.  
  7904.    NEWLINES is the number of newlines that must be duplicated.
  7905.    We assume that that much extra space is available past the end
  7906.    of the string.  */
  7907.  
  7908. static int
  7909. discard_comments (start, length, newlines)
  7910.      U_CHAR *start;
  7911.      int length;
  7912.      int newlines;
  7913. {
  7914.   register U_CHAR *ibp;
  7915.   register U_CHAR *obp;
  7916.   register U_CHAR *limit;
  7917.   register int c;
  7918.  
  7919.   /* If we have newlines to duplicate, copy everything
  7920.      that many characters up.  Then, in the second part,
  7921.      we will have room to insert the newlines
  7922.      while copying down.
  7923.      NEWLINES may actually be too large, because it counts
  7924.      newlines in string constants, and we don't duplicate those.
  7925.      But that does no harm.  */
  7926.   if (newlines > 0) {
  7927.     ibp = start + length;
  7928.     obp = ibp + newlines;
  7929.     limit = start;
  7930.     while (limit != ibp)
  7931.       *--obp = *--ibp;
  7932.   }
  7933.  
  7934.   ibp = start + newlines;
  7935.   limit = start + length + newlines;
  7936.   obp = start;
  7937.  
  7938.   while (ibp < limit) {
  7939.     *obp++ = c = *ibp++;
  7940.     switch (c) {
  7941.     case '\n':
  7942.       /* Duplicate the newline.  */
  7943.       *obp++ = '\n';
  7944.       break;
  7945.  
  7946.     case '\\':
  7947.       if (*ibp == '\n') {
  7948.     obp--;
  7949.     ibp++;
  7950.       }
  7951.       break;
  7952.  
  7953.     case '/':
  7954.       if (*ibp == '\\' && ibp[1] == '\n')
  7955.     newline_fix (ibp);
  7956.       /* Delete any comment.  */
  7957.       if (cplusplus_comments && ibp[0] == '/') {
  7958.     obp--;
  7959.     ibp++;
  7960.     while (ibp < limit && *ibp++ != '\n') ;
  7961.     break;
  7962.       }
  7963.       if (ibp[0] != '*' || ibp + 1 >= limit)
  7964.     break;
  7965.       obp--;
  7966.       ibp++;
  7967.       while (ibp + 1 < limit) {
  7968.     if (ibp[0] == '*'
  7969.         && ibp[1] == '\\' && ibp[2] == '\n')
  7970.       newline_fix (ibp + 1);
  7971.     if (ibp[0] == '*' && ibp[1] == '/')
  7972.       break;
  7973.     ibp++;
  7974.       }
  7975.       ibp += 2;
  7976.       break;
  7977.  
  7978.     case '\'':
  7979.     case '\"':
  7980.       /* Notice and skip strings, so that we don't
  7981.      think that comments start inside them,
  7982.      and so we don't duplicate newlines in them.  */
  7983.       {
  7984.     int quotec = c;
  7985.     while (ibp < limit) {
  7986.       *obp++ = c = *ibp++;
  7987.       if (c == quotec)
  7988.         break;
  7989.       if (c == '\n' && quotec == '\'')
  7990.         break;
  7991.       if (c == '\\' && ibp < limit) {
  7992.         while (*ibp == '\\' && ibp[1] == '\n')
  7993.           ibp += 2;
  7994.         *obp++ = *ibp++;
  7995.       }
  7996.     }
  7997.       }
  7998.       break;
  7999.     }
  8000.   }
  8001.  
  8002.   return obp - start;
  8003. }
  8004.  
  8005. /* Turn newlines to spaces in the string of length LENGTH at START,
  8006.    except inside of string constants.
  8007.    The string is copied into itself with its beginning staying fixed.  */
  8008.  
  8009. static int
  8010. change_newlines (start, length)
  8011.      U_CHAR *start;
  8012.      int length;
  8013. {
  8014.   register U_CHAR *ibp;
  8015.   register U_CHAR *obp;
  8016.   register U_CHAR *limit;
  8017.   register int c;
  8018.  
  8019.   ibp = start;
  8020.   limit = start + length;
  8021.   obp = start;
  8022.  
  8023.   while (ibp < limit) {
  8024.     *obp++ = c = *ibp++;
  8025.     switch (c) {
  8026.     case '\n':
  8027.       /* If this is a NEWLINE NEWLINE, then this is a real newline in the
  8028.      string.  Skip past the newline and its duplicate.
  8029.      Put a space in the output.  */
  8030.       if (*ibp == '\n')
  8031.     {
  8032.       ibp++;
  8033.       obp--;
  8034.       *obp++ = ' ';
  8035.     }
  8036.       break;
  8037.  
  8038.     case '\'':
  8039.     case '\"':
  8040.       /* Notice and skip strings, so that we don't delete newlines in them.  */
  8041.       {
  8042.     int quotec = c;
  8043.     while (ibp < limit) {
  8044.       *obp++ = c = *ibp++;
  8045.       if (c == quotec)
  8046.         break;
  8047.       if (c == '\n' && quotec == '\'')
  8048.         break;
  8049.     }
  8050.       }
  8051.       break;
  8052.     }
  8053.   }
  8054.  
  8055.   return obp - start;
  8056. }
  8057.  
  8058. /*
  8059.  * error - print error message and increment count of errors.
  8060.  */
  8061.  
  8062. void
  8063. error (msg, arg1, arg2, arg3)
  8064.      char *msg;
  8065.      char *arg1, *arg2, *arg3;
  8066. {
  8067.   int i;
  8068.   FILE_BUF *ip = NULL;
  8069.  
  8070.   print_containing_files ();
  8071.  
  8072.   for (i = indepth; i >= 0; i--)
  8073.     if (instack[i].fname != NULL) {
  8074.       ip = &instack[i];
  8075.       break;
  8076.     }
  8077.  
  8078.   if (ip != NULL)
  8079.     fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno);
  8080.   fprintf (stderr, msg, arg1, arg2, arg3);
  8081.   fprintf (stderr, "\n");
  8082.   errors++;
  8083. }
  8084.  
  8085. /* Error including a message from `errno'.  */
  8086.  
  8087. static void
  8088. error_from_errno (name)
  8089.      char *name;
  8090. {
  8091.   int i;
  8092.   FILE_BUF *ip = NULL;
  8093.  
  8094.   print_containing_files ();
  8095.  
  8096.   for (i = indepth; i >= 0; i--)
  8097.     if (instack[i].fname != NULL) {
  8098.       ip = &instack[i];
  8099.       break;
  8100.     }
  8101.  
  8102.   if (ip != NULL)
  8103.     fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno);
  8104.  
  8105.   if (errno < sys_nerr)
  8106.     fprintf (stderr, "%s: %s\n", name, sys_errlist[errno]);
  8107.   else
  8108.     fprintf (stderr, "%s: undocumented I/O error\n", name);
  8109.  
  8110.   errors++;
  8111. }
  8112.  
  8113. /* Print error message but don't count it.  */
  8114.  
  8115. void
  8116. warning (msg, arg1, arg2, arg3)
  8117.      char *msg;
  8118.      char *arg1, *arg2, *arg3;
  8119. {
  8120.   int i;
  8121.   FILE_BUF *ip = NULL;
  8122.  
  8123.   if (inhibit_warnings)
  8124.     return;
  8125.  
  8126.   if (warnings_are_errors)
  8127.     errors++;
  8128.  
  8129.   print_containing_files ();
  8130.  
  8131.   for (i = indepth; i >= 0; i--)
  8132.     if (instack[i].fname != NULL) {
  8133.       ip = &instack[i];
  8134.       break;
  8135.     }
  8136.  
  8137.   if (ip != NULL)
  8138.     fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno);
  8139.   fprintf (stderr, "warning: ");
  8140.   fprintf (stderr, msg, arg1, arg2, arg3);
  8141.   fprintf (stderr, "\n");
  8142. }
  8143.  
  8144. static void
  8145. error_with_line (line, msg, arg1, arg2, arg3)
  8146.      int line;
  8147.      char *msg;
  8148.      char *arg1, *arg2, *arg3;
  8149. {
  8150.   int i;
  8151.   FILE_BUF *ip = NULL;
  8152.  
  8153.   print_containing_files ();
  8154.  
  8155.   for (i = indepth; i >= 0; i--)
  8156.     if (instack[i].fname != NULL) {
  8157.       ip = &instack[i];
  8158.       break;
  8159.     }
  8160.  
  8161.   if (ip != NULL)
  8162.     fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
  8163.   fprintf (stderr, msg, arg1, arg2, arg3);
  8164.   fprintf (stderr, "\n");
  8165.   errors++;
  8166. }
  8167.  
  8168. static void
  8169. warning_with_line (line, msg, arg1, arg2, arg3)
  8170.      int line;
  8171.      char *msg;
  8172.      char *arg1, *arg2, *arg3;
  8173. {
  8174.   int i;
  8175.   FILE_BUF *ip = NULL;
  8176.  
  8177.   if (inhibit_warnings)
  8178.     return;
  8179.  
  8180.   if (warnings_are_errors)
  8181.     errors++;
  8182.  
  8183.   print_containing_files ();
  8184.  
  8185.   for (i = indepth; i >= 0; i--)
  8186.     if (instack[i].fname != NULL) {
  8187.       ip = &instack[i];
  8188.       break;
  8189.     }
  8190.  
  8191.   if (ip != NULL)
  8192.     fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
  8193.   fprintf (stderr, "warning: ");
  8194.   fprintf (stderr, msg, arg1, arg2, arg3);
  8195.   fprintf (stderr, "\n");
  8196. }
  8197.  
  8198. /* print an error message and maybe count it.  */
  8199.  
  8200. void
  8201. pedwarn (msg, arg1, arg2, arg3)
  8202.      char *msg;
  8203.      char *arg1, *arg2, *arg3;
  8204. {
  8205.   if (pedantic_errors)
  8206.     error (msg, arg1, arg2, arg3);
  8207.   else
  8208.     warning (msg, arg1, arg2, arg3);
  8209. }
  8210.  
  8211. void
  8212. pedwarn_with_line (line, msg, arg1, arg2, arg3)
  8213.      int line;
  8214.      char *msg;
  8215.      char *arg1, *arg2, *arg3;
  8216. {
  8217.   if (pedantic_errors)
  8218.     error_with_line (line, msg, arg1, arg2, arg3);
  8219.   else
  8220.     warning_with_line (line, msg, arg1, arg2, arg3);
  8221. }
  8222.  
  8223. /* Report a warning (or an error if pedantic_errors)
  8224.    giving specified file name and line number, not current.  */
  8225.  
  8226. static void
  8227. pedwarn_with_file_and_line (file, line, msg, arg1, arg2, arg3)
  8228.      char *file;
  8229.      int line;
  8230.      char *msg;
  8231.      char *arg1, *arg2, *arg3;
  8232. {
  8233.   int i;
  8234.   if (!pedantic_errors && inhibit_warnings)
  8235.     return;
  8236.   if (file != NULL)
  8237.     fprintf (stderr, "%s:%d: ", file, line);
  8238.   if (pedantic_errors)
  8239.     errors++;
  8240.   if (!pedantic_errors)
  8241.     fprintf (stderr, "warning: ");
  8242.   fprintf (stderr, msg, arg1, arg2, arg3);
  8243.   fprintf (stderr, "\n");
  8244. }
  8245.  
  8246. /* Print the file names and line numbers of the #include
  8247.    commands which led to the current file.  */
  8248.  
  8249. static void
  8250. print_containing_files ()
  8251. {
  8252.   FILE_BUF *ip = NULL;
  8253.   int i;
  8254.   int first = 1;
  8255.  
  8256.   /* If stack of files hasn't changed since we last printed
  8257.      this info, don't repeat it.  */
  8258.   if (last_error_tick == input_file_stack_tick)
  8259.     return;
  8260.  
  8261.   for (i = indepth; i >= 0; i--)
  8262.     if (instack[i].fname != NULL) {
  8263.       ip = &instack[i];
  8264.       break;
  8265.     }
  8266.  
  8267.   /* Give up if we don't find a source file.  */
  8268.   if (ip == NULL)
  8269.     return;
  8270.  
  8271.   /* Find the other, outer source files.  */
  8272.   for (i--; i >= 0; i--)
  8273.     if (instack[i].fname != NULL) {
  8274.       ip = &instack[i];
  8275.       if (first) {
  8276.     first = 0;
  8277.     fprintf (stderr, "In file included");
  8278.       } else {
  8279.     fprintf (stderr, ",\n                ");
  8280.       }
  8281.  
  8282.       fprintf (stderr, " from %s:%d", ip->nominal_fname, ip->lineno);
  8283.     }
  8284.   if (! first)
  8285.     fprintf (stderr, ":\n");
  8286.  
  8287.   /* Record we have printed the status as of this time.  */
  8288.   last_error_tick = input_file_stack_tick;
  8289. }
  8290.  
  8291. /* Return the line at which an error occurred.
  8292.    The error is not necessarily associated with the current spot
  8293.    in the input stack, so LINE says where.  LINE will have been
  8294.    copied from ip->lineno for the current input level.
  8295.    If the current level is for a file, we return LINE.
  8296.    But if the current level is not for a file, LINE is meaningless.
  8297.    In that case, we return the lineno of the innermost file.  */
  8298.  
  8299. static int
  8300. line_for_error (line)
  8301.      int line;
  8302. {
  8303.   int i;
  8304.   int line1 = line;
  8305.  
  8306.   for (i = indepth; i >= 0; ) {
  8307.     if (instack[i].fname != 0)
  8308.       return line1;
  8309.     i--;
  8310.     if (i < 0)
  8311.       return 0;
  8312.     line1 = instack[i].lineno;
  8313.   }
  8314.   abort ();
  8315.   /*NOTREACHED*/
  8316.   return 0;
  8317. }
  8318.  
  8319. /*
  8320.  * If OBUF doesn't have NEEDED bytes after OPTR, make it bigger.
  8321.  *
  8322.  * As things stand, nothing is ever placed in the output buffer to be
  8323.  * removed again except when it's KNOWN to be part of an identifier,
  8324.  * so flushing and moving down everything left, instead of expanding,
  8325.  * should work ok.
  8326.  */
  8327.  
  8328. /* You might think void was cleaner for the return type,
  8329.    but that would get type mismatch in check_expand in strict ANSI.  */
  8330. static int
  8331. grow_outbuf (obuf, needed)
  8332.      register FILE_BUF *obuf;
  8333.      register int needed;
  8334. {
  8335.   register U_CHAR *p;
  8336.   int minsize;
  8337.  
  8338.   if (obuf->length - (obuf->bufp - obuf->buf) > needed)
  8339.     return 0;
  8340.  
  8341.   /* Make it at least twice as big as it is now.  */
  8342.   obuf->length *= 2;
  8343.   /* Make it have at least 150% of the free space we will need.  */
  8344.   minsize = (3 * needed) / 2 + (obuf->bufp - obuf->buf);
  8345.   if (minsize > obuf->length)
  8346.     obuf->length = minsize;
  8347.  
  8348.   if ((p = (U_CHAR *) xrealloc (obuf->buf, obuf->length)) == NULL)
  8349.     memory_full ();
  8350.  
  8351.   obuf->bufp = p + (obuf->bufp - obuf->buf);
  8352.   obuf->buf = p;
  8353.  
  8354.   return 0;
  8355. }
  8356.  
  8357. /* Symbol table for macro names and special symbols */
  8358.  
  8359. /*
  8360.  * install a name in the main hash table, even if it is already there.
  8361.  *   name stops with first non alphanumeric, except leading '#'.
  8362.  * caller must check against redefinition if that is desired.
  8363.  * delete_macro () removes things installed by install () in fifo order.
  8364.  * this is important because of the `defined' special symbol used
  8365.  * in #if, and also if pushdef/popdef directives are ever implemented.
  8366.  *
  8367.  * If LEN is >= 0, it is the length of the name.
  8368.  * Otherwise, compute the length by scanning the entire name.
  8369.  *
  8370.  * If HASH is >= 0, it is the precomputed hash code.
  8371.  * Otherwise, compute the hash code.
  8372.  */
  8373. static HASHNODE *
  8374. install (name, len, type, ivalue, value, hash)
  8375.      U_CHAR *name;
  8376.      int len;
  8377.      enum node_type type;
  8378.      int ivalue;
  8379.      char *value;
  8380.      int hash;
  8381. {
  8382.   register HASHNODE *hp;
  8383.   register int i, bucket;
  8384.   register U_CHAR *p, *q;
  8385.  
  8386.   if (len < 0) {
  8387.     p = name;
  8388.     while (is_idchar[*p])
  8389.       p++;
  8390.     len = p - name;
  8391.   }
  8392.  
  8393.   if (hash < 0)
  8394.     hash = hashf (name, len, HASHSIZE);
  8395.  
  8396.   i = sizeof (HASHNODE) + len + 1;
  8397.   hp = (HASHNODE *) xmalloc (i);
  8398.   bucket = hash;
  8399.   hp->bucket_hdr = &hashtab[bucket];
  8400.   hp->next = hashtab[bucket];
  8401.   hashtab[bucket] = hp;
  8402.   hp->prev = NULL;
  8403.   if (hp->next != NULL)
  8404.     hp->next->prev = hp;
  8405.   hp->type = type;
  8406.   hp->length = len;
  8407.   if (hp->type == T_CONST)
  8408.     hp->value.ival = ivalue;
  8409.   else
  8410.     hp->value.cpval = value;
  8411.   hp->name = ((U_CHAR *) hp) + sizeof (HASHNODE);
  8412.   p = hp->name;
  8413.   q = name;
  8414.   for (i = 0; i < len; i++)
  8415.     *p++ = *q++;
  8416.   hp->name[len] = 0;
  8417.   return hp;
  8418. }
  8419.  
  8420. /*
  8421.  * find the most recent hash node for name name (ending with first
  8422.  * non-identifier char) installed by install
  8423.  *
  8424.  * If LEN is >= 0, it is the length of the name.
  8425.  * Otherwise, compute the length by scanning the entire name.
  8426.  *
  8427.  * If HASH is >= 0, it is the precomputed hash code.
  8428.  * Otherwise, compute the hash code.
  8429.  */
  8430. HASHNODE *
  8431. lookup (name, len, hash)
  8432.      U_CHAR *name;
  8433.      int len;
  8434.      int hash;
  8435. {
  8436.   register U_CHAR *bp;
  8437.   register HASHNODE *bucket;
  8438.  
  8439.   if (len < 0) {
  8440.     for (bp = name; is_idchar[*bp]; bp++) ;
  8441.     len = bp - name;
  8442.   }
  8443.  
  8444.   if (hash < 0)
  8445.     hash = hashf (name, len, HASHSIZE);
  8446.  
  8447.   bucket = hashtab[hash];
  8448.   while (bucket) {
  8449.     if (bucket->length == len && strncmp (bucket->name, name, len) == 0)
  8450.       return bucket;
  8451.     bucket = bucket->next;
  8452.   }
  8453.   return NULL;
  8454. }
  8455.  
  8456. /*
  8457.  * Delete a hash node.  Some weirdness to free junk from macros.
  8458.  * More such weirdness will have to be added if you define more hash
  8459.  * types that need it.
  8460.  */
  8461.  
  8462. /* Note that the DEFINITION of a macro is removed from the hash table
  8463.    but its storage is not freed.  This would be a storage leak
  8464.    except that it is not reasonable to keep undefining and redefining
  8465.    large numbers of macros many times.
  8466.    In any case, this is necessary, because a macro can be #undef'd
  8467.    in the middle of reading the arguments to a call to it.
  8468.    If #undef freed the DEFINITION, that would crash.  */
  8469.  
  8470. static void
  8471. delete_macro (hp)
  8472.      HASHNODE *hp;
  8473. {
  8474.  
  8475.   if (hp->prev != NULL)
  8476.     hp->prev->next = hp->next;
  8477.   if (hp->next != NULL)
  8478.     hp->next->prev = hp->prev;
  8479.  
  8480.   /* make sure that the bucket chain header that
  8481.      the deleted guy was on points to the right thing afterwards. */
  8482.   if (hp == *hp->bucket_hdr)
  8483.     *hp->bucket_hdr = hp->next;
  8484.  
  8485. #if 0
  8486.   if (hp->type == T_MACRO) {
  8487.     DEFINITION *d = hp->value.defn;
  8488.     struct reflist *ap, *nextap;
  8489.  
  8490.     for (ap = d->pattern; ap != NULL; ap = nextap) {
  8491.       nextap = ap->next;
  8492.       free (ap);
  8493.     }
  8494.     free (d);
  8495.   }
  8496. #endif
  8497.   free (hp);
  8498. }
  8499.  
  8500. /*
  8501.  * return hash function on name.  must be compatible with the one
  8502.  * computed a step at a time, elsewhere
  8503.  */
  8504. static int
  8505. hashf (name, len, hashsize)
  8506.      register U_CHAR *name;
  8507.      register int len;
  8508.      int hashsize;
  8509. {
  8510.   register int r = 0;
  8511.  
  8512.   while (len--)
  8513.     r = HASHSTEP (r, *name++);
  8514.  
  8515.   return MAKE_POS (r) % hashsize;
  8516. }
  8517.  
  8518.  
  8519. /* Dump the definition of a single macro HP to OF.  */
  8520. static void
  8521. dump_single_macro (hp, of)
  8522.      register HASHNODE *hp;
  8523.      FILE *of;
  8524. {
  8525.   register DEFINITION *defn = hp->value.defn;
  8526.   struct reflist *ap;
  8527.   int offset;
  8528.   int concat;
  8529.  
  8530.  
  8531.   /* Print the definition of the macro HP.  */
  8532.  
  8533.   fprintf (of, "#define %s", hp->name);
  8534.  
  8535.   if (defn->nargs >= 0) {
  8536.     int i;
  8537.  
  8538.     fprintf (of, "(");
  8539.     for (i = 0; i < defn->nargs; i++) {
  8540.       dump_arg_n (defn, i, of);
  8541.       if (i + 1 < defn->nargs)
  8542.     fprintf (of, ", ");
  8543.     }
  8544.     fprintf (of, ")");
  8545.   }
  8546.  
  8547.   fprintf (of, " ");
  8548.  
  8549.   offset = 0;
  8550.   concat = 0;
  8551.   for (ap = defn->pattern; ap != NULL; ap = ap->next) {
  8552.     dump_defn_1 (defn->expansion, offset, ap->nchars, of);
  8553.     if (ap->nchars != 0)
  8554.       concat = 0;
  8555.     offset += ap->nchars;
  8556.     if (ap->stringify)
  8557.       fprintf (of, " #");
  8558.     if (ap->raw_before && !concat)
  8559.       fprintf (of, " ## ");
  8560.     concat = 0;
  8561.     dump_arg_n (defn, ap->argno, of);
  8562.     if (ap->raw_after) {
  8563.       fprintf (of, " ## ");
  8564.       concat = 1;
  8565.     }
  8566.   }
  8567.   dump_defn_1 (defn->expansion, offset, defn->length - offset, of);
  8568.   fprintf (of, "\n");
  8569. }
  8570.  
  8571. /* Dump all macro definitions as #defines to stdout.  */
  8572.  
  8573. static void
  8574. dump_all_macros ()
  8575. {
  8576.   int bucket;
  8577.  
  8578.   for (bucket = 0; bucket < HASHSIZE; bucket++) {
  8579.     register HASHNODE *hp;
  8580.  
  8581.     for (hp = hashtab[bucket]; hp; hp= hp->next) {
  8582.       if (hp->type == T_MACRO)
  8583.     dump_single_macro (hp, stdout);
  8584.     }
  8585.   }
  8586. }
  8587.  
  8588. /* Output to OF a substring of a macro definition.
  8589.    BASE is the beginning of the definition.
  8590.    Output characters START thru LENGTH.
  8591.    Discard newlines outside of strings, thus
  8592.    converting funny-space markers to ordinary spaces.  */
  8593.  
  8594. static void
  8595. dump_defn_1 (base, start, length, of)
  8596.      U_CHAR *base;
  8597.      int start;
  8598.      int length;
  8599.      FILE *of;
  8600. {
  8601.   U_CHAR *p = base + start;
  8602.   U_CHAR *limit = base + start + length;
  8603.  
  8604.   while (p < limit) {
  8605.     if (*p != '\n')
  8606.       putc (*p, of);
  8607.     else if (*p == '\"' || *p =='\'') {
  8608.       U_CHAR *p1 = skip_quoted_string (p, limit, 0, NULL_PTR,
  8609.                        NULL_PTR, NULL_PTR);
  8610.       fwrite (p, p1 - p, 1, of);
  8611.       p = p1 - 1;
  8612.     }
  8613.     p++;
  8614.   }
  8615. }
  8616.  
  8617. /* Print the name of argument number ARGNUM of macro definition DEFN
  8618.    to OF.
  8619.    Recall that DEFN->args.argnames contains all the arg names
  8620.    concatenated in reverse order with comma-space in between.  */
  8621.  
  8622. static void
  8623. dump_arg_n (defn, argnum, of)
  8624.      DEFINITION *defn;
  8625.      int argnum;
  8626.      FILE *of;
  8627. {
  8628.   register U_CHAR *p = defn->args.argnames;
  8629.   while (argnum + 1 < defn->nargs) {
  8630.     p = (U_CHAR *) index (p, ' ') + 1;
  8631.     argnum++;
  8632.   }
  8633.  
  8634.   while (*p && *p != ',') {
  8635.     putc (*p, of);
  8636.     p++;
  8637.   }
  8638. }
  8639.  
  8640. /* Initialize syntactic classifications of characters.  */
  8641.  
  8642. static void
  8643. initialize_char_syntax ()
  8644. {
  8645.   register int i;
  8646.  
  8647.   /*
  8648.    * Set up is_idchar and is_idstart tables.  These should be
  8649.    * faster than saying (is_alpha (c) || c == '_'), etc.
  8650.    * Set up these things before calling any routines tthat
  8651.    * refer to them.
  8652.    */
  8653.   for (i = 'a'; i <= 'z'; i++) {
  8654.     is_idchar[i - 'a' + 'A'] = 1;
  8655.     is_idchar[i] = 1;
  8656.     is_idstart[i - 'a' + 'A'] = 1;
  8657.     is_idstart[i] = 1;
  8658.   }
  8659.   for (i = '0'; i <= '9'; i++)
  8660.     is_idchar[i] = 1;
  8661.   is_idchar['_'] = 1;
  8662.   is_idstart['_'] = 1;
  8663.   is_idchar['$'] = dollars_in_ident;
  8664.   is_idstart['$'] = dollars_in_ident;
  8665.  
  8666.   /* horizontal space table */
  8667.   is_hor_space[' '] = 1;
  8668.   is_hor_space['\t'] = 1;
  8669.   is_hor_space['\v'] = 1;
  8670.   is_hor_space['\f'] = 1;
  8671.   is_hor_space['\r'] = 1;
  8672.  
  8673.   is_space[' '] = 1;
  8674.   is_space['\t'] = 1;
  8675.   is_space['\v'] = 1;
  8676.   is_space['\f'] = 1;
  8677.   is_space['\n'] = 1;
  8678.   is_space['\r'] = 1;
  8679. }
  8680.  
  8681. /* Initialize the built-in macros.  */
  8682.  
  8683. static void
  8684. initialize_builtins (inp, outp)
  8685.      FILE_BUF *inp;
  8686.      FILE_BUF *outp;
  8687. {
  8688.   install ("__LINE__", -1, T_SPECLINE, 0, 0, -1);
  8689.   install ("__DATE__", -1, T_DATE, 0, 0, -1);
  8690.   install ("__FILE__", -1, T_FILE, 0, 0, -1);
  8691.   install ("__BASE_FILE__", -1, T_BASE_FILE, 0, 0, -1);
  8692.   install ("__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL, 0, 0, -1);
  8693.   install ("__VERSION__", -1, T_VERSION, 0, 0, -1);
  8694. #ifndef NO_BUILTIN_SIZE_TYPE
  8695.   install ("__SIZE_TYPE__", -1, T_SIZE_TYPE, 0, 0, -1);
  8696. #endif
  8697. #ifndef NO_BUILTIN_PTRDIFF_TYPE
  8698.   install ("__PTRDIFF_TYPE__ ", -1, T_PTRDIFF_TYPE, 0, 0, -1);
  8699. #endif
  8700.   install ("__WCHAR_TYPE__", -1, T_WCHAR_TYPE, 0, 0, -1);
  8701.   install ("__USER_LABEL_PREFIX__", -1, T_USER_LABEL_PREFIX_TYPE, 0, 0, -1);
  8702.   install ("__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE, 0, 0, -1);
  8703.   install ("__TIME__", -1, T_TIME, 0, 0, -1);
  8704.   if (!traditional)
  8705.     install ("__STDC__", -1, T_CONST, STDC_VALUE, 0, -1);
  8706.   if (objc)
  8707.     install ("__OBJC__", -1, T_CONST, 1, 0, -1);
  8708. /*  This is supplied using a -D by the compiler driver
  8709.     so that it is present only when truly compiling with GNU C.  */
  8710. /*  install ("__GNUC__", -1, T_CONST, 2, 0, -1);  */
  8711.  
  8712.   if (debug_output)
  8713.     {
  8714.       char directive[2048];
  8715.       register struct directive *dp = &directive_table[0];
  8716.       struct tm *timebuf = timestamp ();
  8717.  
  8718.       sprintf (directive, " __BASE_FILE__ \"%s\"\n",
  8719.            instack[0].nominal_fname);
  8720.       output_line_command (inp, outp, 0, same_file);
  8721.       pass_thru_directive (directive, &directive[strlen (directive)], outp, dp);
  8722.  
  8723.       sprintf (directive, " __VERSION__ \"%s\"\n", version_string);
  8724.       output_line_command (inp, outp, 0, same_file);
  8725.       pass_thru_directive (directive, &directive[strlen (directive)], outp, dp);
  8726.  
  8727. #ifndef NO_BUILTIN_SIZE_TYPE
  8728.       sprintf (directive, " __SIZE_TYPE__ %s\n", SIZE_TYPE);
  8729.       output_line_command (inp, outp, 0, same_file);
  8730.       pass_thru_directive (directive, &directive[strlen (directive)], outp, dp);
  8731. #endif
  8732.  
  8733. #ifndef NO_BUILTIN_PTRDIFF_TYPE
  8734.       sprintf (directive, " __PTRDIFF_TYPE__ %s\n", PTRDIFF_TYPE);
  8735.       output_line_command (inp, outp, 0, same_file);
  8736.       pass_thru_directive (directive, &directive[strlen (directive)], outp, dp);
  8737. #endif
  8738.  
  8739.       sprintf (directive, " __WCHAR_TYPE__ %s\n", WCHAR_TYPE);
  8740.       output_line_command (inp, outp, 0, same_file);
  8741.       pass_thru_directive (directive, &directive[strlen (directive)], outp, dp);
  8742.  
  8743.       sprintf (directive, " __DATE__ \"%s %2d %4d\"\n",
  8744.            monthnames[timebuf->tm_mon],
  8745.            timebuf->tm_mday, timebuf->tm_year + 1900);
  8746.       output_line_command (inp, outp, 0, same_file);
  8747.       pass_thru_directive (directive, &directive[strlen (directive)], outp, dp);
  8748.  
  8749.       sprintf (directive, " __TIME__ \"%02d:%02d:%02d\"\n",
  8750.            timebuf->tm_hour, timebuf->tm_min, timebuf->tm_sec);
  8751.       output_line_command (inp, outp, 0, same_file);
  8752.       pass_thru_directive (directive, &directive[strlen (directive)], outp, dp);
  8753.  
  8754.       if (!traditional)
  8755.     {
  8756.           sprintf (directive, " __STDC__ 1");
  8757.           output_line_command (inp, outp, 0, same_file);
  8758.           pass_thru_directive (directive, &directive[strlen (directive)],
  8759.                    outp, dp);
  8760.     }
  8761.       if (objc)
  8762.     {
  8763.           sprintf (directive, " __OBJC__ 1");
  8764.           output_line_command (inp, outp, 0, same_file);
  8765.           pass_thru_directive (directive, &directive[strlen (directive)],
  8766.                    outp, dp);
  8767.     }
  8768.     }
  8769. }
  8770.  
  8771. /*
  8772.  * process a given definition string, for initialization
  8773.  * If STR is just an identifier, define it with value 1.
  8774.  * If STR has anything after the identifier, then it should
  8775.  * be identifier=definition.
  8776.  */
  8777.  
  8778. static void
  8779. make_definition (str, op)
  8780.      U_CHAR *str;
  8781.      FILE_BUF *op;
  8782. {
  8783.   FILE_BUF *ip;
  8784.   struct directive *kt;
  8785.   U_CHAR *buf, *p;
  8786.  
  8787.   buf = str;
  8788.   p = str;
  8789.   if (!is_idstart[*p]) {
  8790.     error ("malformed option `-D %s'", str);
  8791.     return;
  8792.   }
  8793.   while (is_idchar[*++p])
  8794.     ;
  8795.   if (*p == 0) {
  8796.     buf = (U_CHAR *) alloca (p - buf + 4);
  8797.     strcpy ((char *)buf, str);
  8798.     strcat ((char *)buf, " 1");
  8799.   } else if (*p != '=') {
  8800.     error ("malformed option `-D %s'", str);
  8801.     return;
  8802.   } else {
  8803.     U_CHAR *q;
  8804.     /* Copy the entire option so we can modify it.  */
  8805.     buf = (U_CHAR *) alloca (2 * strlen (str) + 1);
  8806.     strncpy (buf, str, p - str);
  8807.     /* Change the = to a space.  */
  8808.     buf[p - str] = ' ';
  8809.     /* Scan for any backslash-newline and remove it.  */
  8810.     p++;
  8811.     q = &buf[p - str];
  8812.     while (*p) {
  8813.       if (*p == '\\' && p[1] == '\n')
  8814.     p += 2;
  8815.       /* Change newline chars into newline-markers.  */
  8816.       else if (*p == '\n')
  8817.     {
  8818.       *q++ = '\n';
  8819.       *q++ = '\n';
  8820.       p++;
  8821.     }
  8822.       else
  8823.     *q++ = *p++;
  8824.     }
  8825.     *q = 0;
  8826.   }
  8827.   
  8828.   ip = &instack[++indepth];
  8829.   ip->nominal_fname = ip->fname = "*Initialization*";
  8830.  
  8831.   ip->buf = ip->bufp = buf;
  8832.   ip->length = strlen (buf);
  8833.   ip->lineno = 1;
  8834.   ip->macro = 0;
  8835.   ip->free_ptr = 0;
  8836.   ip->if_stack = if_stack;
  8837.   ip->system_header_p = 0;
  8838.  
  8839.   for (kt = directive_table; kt->type != T_DEFINE; kt++)
  8840.     ;
  8841.  
  8842.   /* Pass NULL instead of OP, since this is a "predefined" macro.  */
  8843.   do_define (buf, buf + strlen (buf), NULL, kt);
  8844.   --indepth;
  8845. }
  8846.  
  8847. /* JF, this does the work for the -U option */
  8848.  
  8849. static void
  8850. make_undef (str, op)
  8851.      U_CHAR *str;
  8852.      FILE_BUF *op;
  8853. {
  8854.   FILE_BUF *ip;
  8855.   struct directive *kt;
  8856.  
  8857.   ip = &instack[++indepth];
  8858.   ip->nominal_fname = ip->fname = "*undef*";
  8859.  
  8860.   ip->buf = ip->bufp = str;
  8861.   ip->length = strlen (str);
  8862.   ip->lineno = 1;
  8863.   ip->macro = 0;
  8864.   ip->free_ptr = 0;
  8865.   ip->if_stack = if_stack;
  8866.   ip->system_header_p = 0;
  8867.  
  8868.   for (kt = directive_table; kt->type != T_UNDEF; kt++)
  8869.     ;
  8870.  
  8871.   do_undef (str, str + strlen (str), op, kt);
  8872.   --indepth;
  8873. }
  8874.  
  8875. /* Process the string STR as if it appeared as the body of a #assert.
  8876.    OPTION is the option name for which STR was the argument.  */
  8877.  
  8878. static void
  8879. make_assertion (option, str)
  8880.      char *option;
  8881.      U_CHAR *str;
  8882. {
  8883.   FILE_BUF *ip;
  8884.   struct directive *kt;
  8885.   U_CHAR *buf, *p, *q;
  8886.  
  8887.   /* Copy the entire option so we can modify it.  */
  8888.   buf = (U_CHAR *) alloca (strlen (str) + 1);
  8889.   strcpy ((char *) buf, str);
  8890.   /* Scan for any backslash-newline and remove it.  */
  8891.   p = q = buf;
  8892.   while (*p) {
  8893.     if (*p == '\\' && p[1] == '\n')
  8894.       p += 2;
  8895.     else
  8896.       *q++ = *p++;
  8897.   }
  8898.   *q = 0;
  8899.  
  8900.   p = buf;
  8901.   if (!is_idstart[*p]) {
  8902.     error ("malformed option `%s %s'", option, str);
  8903.     return;
  8904.   }
  8905.   while (is_idchar[*++p])
  8906.     ;
  8907.   while (*p == ' ' || *p == '\t') p++;
  8908.   if (! (*p == 0 || *p == '(')) {
  8909.     error ("malformed option `%s %s'", option, str);
  8910.     return;
  8911.   }
  8912.   
  8913.   ip = &instack[++indepth];
  8914.   ip->nominal_fname = ip->fname = "*Initialization*";
  8915.  
  8916.   ip->buf = ip->bufp = buf;
  8917.   ip->length = strlen (buf);
  8918.   ip->lineno = 1;
  8919.   ip->macro = 0;
  8920.   ip->free_ptr = 0;
  8921.   ip->if_stack = if_stack;
  8922.   ip->system_header_p = 0;
  8923.  
  8924.   for (kt = directive_table; kt->type != T_ASSERT; kt++)
  8925.     ;
  8926.  
  8927.   /* pass NULL as output ptr to do_define since we KNOW it never
  8928.      does any output.... */
  8929.   do_assert (buf, buf + strlen (buf) , NULL_PTR, kt);
  8930.   --indepth;
  8931. }
  8932.  
  8933. /* Append a chain of `struct file_name_list's
  8934.    to the end of the main include chain.
  8935.    FIRST is the beginning of the chain to append, and LAST is the end.  */
  8936.  
  8937. static void
  8938. append_include_chain (first, last)
  8939.      struct file_name_list *first, *last;
  8940. {
  8941.   struct file_name_list *dir;
  8942.  
  8943.   if (!first || !last)
  8944.     return;
  8945.  
  8946.   if (include == 0)
  8947.     include = first;
  8948.   else
  8949.     last_include->next = first;
  8950.  
  8951.   if (first_bracket_include == 0)
  8952.     first_bracket_include = first;
  8953.  
  8954.   for (dir = first; ; dir = dir->next) {
  8955.     int len = strlen (dir->fname) + INCLUDE_LEN_FUDGE;
  8956.     if (len > max_include_len)
  8957.       max_include_len = len;
  8958.     if (dir == last)
  8959.       break;
  8960.   }
  8961.  
  8962.   last->next = NULL;
  8963.   last_include = last;
  8964. }
  8965.  
  8966. /* Add output to `deps_buffer' for the -M switch.
  8967.    STRING points to the text to be output.
  8968.    SIZE is the number of bytes, or 0 meaning output until a null.
  8969.    Outputting the empty string breaks the line if it is long enough.  */
  8970.  
  8971. static void
  8972. deps_output (string, size)
  8973.      char *string;
  8974.      unsigned size;
  8975. {
  8976.   if (size == 0)
  8977.     size = strlen (string);
  8978.  
  8979. #ifndef MAX_OUTPUT_COLUMNS
  8980. #define MAX_OUTPUT_COLUMNS 75
  8981. #endif
  8982.   if (size == 0 && deps_column != 0
  8983.       && size + deps_column > MAX_OUTPUT_COLUMNS) {
  8984.     deps_output ("\\\n  ", 0);
  8985.     deps_column = 0;
  8986.   }
  8987.  
  8988.   if (deps_size + size + 1 > deps_allocated_size) {
  8989.     deps_allocated_size = deps_size + size + 50;
  8990.     deps_allocated_size *= 2;
  8991.     deps_buffer = (char *) xrealloc (deps_buffer, deps_allocated_size);
  8992.   }
  8993.   bcopy (string, &deps_buffer[deps_size], size);
  8994.   deps_size += size;
  8995.   deps_column += size;
  8996.   deps_buffer[deps_size] = 0;
  8997. }
  8998.  
  8999. #if defined(USG) || defined(VMS)
  9000. #ifndef BSTRING
  9001.  
  9002. void
  9003. bzero (b, length)
  9004.      register char *b;
  9005.      register unsigned length;
  9006. {
  9007.   while (length-- > 0)
  9008.     *b++ = 0;
  9009. }
  9010.  
  9011. void
  9012. bcopy (b1, b2, length)
  9013.      register char *b1;
  9014.      register char *b2;
  9015.      register unsigned length;
  9016. {
  9017.   while (length-- > 0)
  9018.     *b2++ = *b1++;
  9019. }
  9020.  
  9021. int
  9022. bcmp (b1, b2, length)    /* This could be a macro! */
  9023.      register char *b1;
  9024.      register char *b2;
  9025.      register unsigned length;
  9026. {
  9027.    while (length-- > 0)
  9028.      if (*b1++ != *b2++)
  9029.        return 1;
  9030.  
  9031.    return 0;
  9032. }
  9033. #endif /* not BSTRING */
  9034. #endif /* USG or VMS */
  9035.  
  9036.  
  9037. static void
  9038. fatal (str, arg)
  9039.      char *str, *arg;
  9040. {
  9041.   fprintf (stderr, "%s: ", progname);
  9042.   fprintf (stderr, str, arg);
  9043.   fprintf (stderr, "\n");
  9044.   exit (FAILURE_EXIT_CODE);
  9045. }
  9046.  
  9047. /* More 'friendly' abort that prints the line and file.
  9048.    config.h can #define abort fancy_abort if you like that sort of thing.  */
  9049.  
  9050. void
  9051. fancy_abort ()
  9052. {
  9053.   fatal ("Internal gcc abort.");
  9054. }
  9055.  
  9056. static void
  9057. perror_with_name (name)
  9058.      char *name;
  9059. {
  9060.   int error = errno;
  9061.  
  9062.   fprintf (stderr, "%s: ", progname);
  9063.   if (error < sys_nerr)
  9064.     fprintf (stderr, "%s: %s\n", name, sys_errlist[error]);
  9065.   else
  9066.     fprintf (stderr, "%s: undocumented I/O error\n", name);
  9067.   errors++;
  9068. }
  9069.  
  9070. static void
  9071. pfatal_with_name (name)
  9072.      char *name;
  9073. {
  9074.   perror_with_name (name);
  9075. #ifdef VMS
  9076.   exit (vaxc$errno);
  9077. #else
  9078.   exit (FAILURE_EXIT_CODE);
  9079. #endif
  9080. }
  9081.  
  9082. /* Handler for SIGPIPE.  */
  9083.  
  9084. static void
  9085. pipe_closed (signo)
  9086.      /* If this is missing, some compilers complain.  */
  9087.      int signo;
  9088. {
  9089.   fatal ("output pipe has been closed");
  9090. }
  9091.  
  9092. static void
  9093. memory_full ()
  9094. {
  9095.   fatal ("Memory exhausted.");
  9096. }
  9097.  
  9098.  
  9099. char *
  9100. xmalloc (size)
  9101.      unsigned size;
  9102. {
  9103.   register char *ptr = (char *) malloc (size);
  9104.   if (ptr != 0) return (ptr);
  9105.   memory_full ();
  9106.   /*NOTREACHED*/
  9107.   return 0;
  9108. }
  9109.  
  9110. static char *
  9111. xrealloc (old, size)
  9112.      char *old;
  9113.      unsigned size;
  9114. {
  9115.   register char *ptr = (char *) realloc (old, size);
  9116.   if (ptr != 0) return (ptr);
  9117.   memory_full ();
  9118.   /*NOTREACHED*/
  9119.   return 0;
  9120. }
  9121.  
  9122. static char *
  9123. xcalloc (number, size)
  9124.      unsigned number, size;
  9125. {
  9126.   register unsigned total = number * size;
  9127.   register char *ptr = (char *) malloc (total);
  9128.   if (ptr != 0) {
  9129.     if (total > 100)
  9130.       bzero (ptr, total);
  9131.     else {
  9132.       /* It's not too long, so loop, zeroing by longs.
  9133.      It must be safe because malloc values are always well aligned.  */
  9134.       register long *zp = (long *) ptr;
  9135.       register long *zl = (long *) (ptr + total - 4);
  9136.       register int i = total - 4;
  9137.       while (zp < zl)
  9138.     *zp++ = 0;
  9139.       if (i < 0)
  9140.     i = 0;
  9141.       while (i < total)
  9142.     ptr[i++] = 0;
  9143.     }
  9144.     return ptr;
  9145.   }
  9146.   memory_full ();
  9147.   /*NOTREACHED*/
  9148.   return 0;
  9149. }
  9150.  
  9151. static char *
  9152. savestring (input)
  9153.      char *input;
  9154. {
  9155.   unsigned size = strlen (input);
  9156.   char *output = xmalloc (size + 1);
  9157.   strcpy (output, input);
  9158.   return output;
  9159. }
  9160.  
  9161. /* Get the file-mode and data size of the file open on FD
  9162.    and store them in *MODE_POINTER and *SIZE_POINTER.  */
  9163.  
  9164. static int
  9165. file_size_and_mode (fd, mode_pointer, size_pointer)
  9166.      int fd;
  9167.      int *mode_pointer;
  9168.      long int *size_pointer;
  9169. {
  9170.   struct stat sbuf;
  9171.  
  9172.   if (fstat (fd, &sbuf) < 0) return (-1);
  9173.   if (mode_pointer) *mode_pointer = sbuf.st_mode;
  9174.   if (size_pointer) *size_pointer = sbuf.st_size;
  9175.   return 0;
  9176. }
  9177.  
  9178. static void
  9179. output_dots (fd, depth)
  9180.      FILE* fd;
  9181.      int depth;
  9182. {
  9183.   while (depth > 0) {
  9184.     putc ('.', fd);
  9185.     depth--;
  9186.   }
  9187. }
  9188.   
  9189.  
  9190. #ifdef VMS
  9191.  
  9192. /* Under VMS we need to fix up the "include" specification
  9193.    filename so that everything following the 1st slash is
  9194.    changed into its correct VMS file specification. */
  9195.  
  9196. static void
  9197. hack_vms_include_specification (fname)
  9198.      char *fname;
  9199. {
  9200.   register char *cp, *cp1, *cp2;
  9201.   int f, check_filename_before_returning, no_prefix_seen;
  9202.   char Local[512];
  9203.  
  9204.   check_filename_before_returning = 0;
  9205.   no_prefix_seen = 0;
  9206.  
  9207.   /* Ignore leading "./"s */
  9208.   while (fname[0] == '.' && fname[1] == '/') {
  9209.     strcpy (fname, fname+2);
  9210.     no_prefix_seen = 1;        /* mark this for later */
  9211.   }
  9212.   /* Look for the boundary between the VMS and UNIX filespecs */
  9213.   cp = rindex (fname, ']');    /* Look for end of dirspec. */
  9214.   if (cp == 0) cp = rindex (fname, '>'); /* ... Ditto            */
  9215.   if (cp == 0) cp = rindex (fname, ':'); /* Look for end of devspec. */
  9216.   if (cp) {
  9217.     cp++;
  9218.   } else {
  9219.     cp = index (fname, '/');    /* Look for the "/" */
  9220.   }
  9221.  
  9222.   cp2 = Local;            /* initialize */
  9223.  
  9224.   /* We are trying to do a number of things here.  First of all, we are
  9225.      trying to hammer the filenames into a standard format, such that later
  9226.      processing can handle them.
  9227.      
  9228.      If the file name contains something like [dir.], then it recognizes this
  9229.      as a root, and strips the ".]".  Later processing will add whatever is
  9230.      needed to get things working properly.
  9231.      
  9232.      If no device is specified, then the first directory name is taken to be
  9233.      a device name (or a rooted logical). */
  9234.  
  9235.   /* See if we found that 1st slash */
  9236.   if (cp == 0) return;        /* Nothing to do!!! */
  9237.   if (*cp != '/') return;    /* Nothing to do!!! */
  9238.   /* Point to the UNIX filename part (which needs to be fixed!) */
  9239.   cp1 = cp+1;
  9240.   /* If the directory spec is not rooted, we can just copy
  9241.      the UNIX filename part and we are done */
  9242.   if (((cp - fname) > 1) && ((cp[-1] == ']') || (cp[-1] == '>'))) {
  9243.     if (cp[-2] != '.') {
  9244.       /*
  9245.        * The VMS part ends in a `]', and the preceding character is not a `.'.
  9246.        * We strip the `]', and then splice the two parts of the name in the
  9247.        * usual way.  Given the default locations for include files in cccp.c,
  9248.        * we will only use this code if the user specifies alternate locations
  9249.        * with the /include (-I) switch on the command line.  */
  9250.       cp -= 1;            /* Strip "]" */
  9251.       cp1--;            /* backspace */
  9252.     } else {
  9253.       /*
  9254.        * The VMS part has a ".]" at the end, and this will not do.  Later
  9255.        * processing will add a second directory spec, and this would be a syntax
  9256.        * error.  Thus we strip the ".]", and thus merge the directory specs.
  9257.        * We also backspace cp1, so that it points to a '/'.  This inhibits the
  9258.        * generation of the 000000 root directory spec (which does not belong here
  9259.        * in this case).
  9260.        */
  9261.       cp -= 2;            /* Strip ".]" */
  9262.       cp1--; };            /* backspace */
  9263.   } else {
  9264.  
  9265.     /* We drop in here if there is no VMS style directory specification yet.
  9266.      * If there is no device specification either, we make the first dir a
  9267.      * device and try that.  If we do not do this, then we will be essentially
  9268.      * searching the users default directory (as if they did a #include "asdf.h").
  9269.      *
  9270.      * Then all we need to do is to push a '[' into the output string. Later
  9271.      * processing will fill this in, and close the bracket.
  9272.      */
  9273.     if (cp[-1] != ':') *cp2++ = ':'; /* dev not in spec.  take first dir */
  9274.     *cp2++ = '[';        /* Open the directory specification */
  9275.   }
  9276.  
  9277.   /* at this point we assume that we have the device spec, and (at least
  9278.      the opening "[" for a directory specification.  We may have directories
  9279.      specified already */
  9280.  
  9281.   /* If there are no other slashes then the filename will be
  9282.      in the "root" directory.  Otherwise, we need to add
  9283.      directory specifications. */
  9284.   if (index (cp1, '/') == 0) {
  9285.     /* Just add "000000]" as the directory string */
  9286.     strcpy (cp2, "000000]");
  9287.     cp2 += strlen (cp2);
  9288.     check_filename_before_returning = 1; /* we might need to fool with this later */
  9289.   } else {
  9290.     /* As long as there are still subdirectories to add, do them. */
  9291.     while (index (cp1, '/') != 0) {
  9292.       /* If this token is "." we can ignore it */
  9293.       if ((cp1[0] == '.') && (cp1[1] == '/')) {
  9294.     cp1 += 2;
  9295.     continue;
  9296.       }
  9297.       /* Add a subdirectory spec. Do not duplicate "." */
  9298.       if (cp2[-1] != '.' && cp2[-1] != '[' && cp2[-1] != '<')
  9299.     *cp2++ = '.';
  9300.       /* If this is ".." then the spec becomes "-" */
  9301.       if ((cp1[0] == '.') && (cp1[1] == '.') && (cp[2] == '/')) {
  9302.     /* Add "-" and skip the ".." */
  9303.     *cp2++ = '-';
  9304.     cp1 += 3;
  9305.     continue;
  9306.       }
  9307.       /* Copy the subdirectory */
  9308.       while (*cp1 != '/') *cp2++= *cp1++;
  9309.       cp1++;            /* Skip the "/" */
  9310.     }
  9311.     /* Close the directory specification */
  9312.     if (cp2[-1] == '.')        /* no trailing periods */
  9313.       cp2--;
  9314.     *cp2++ = ']';
  9315.   }
  9316.   /* Now add the filename */
  9317.   while (*cp1) *cp2++ = *cp1++;
  9318.   *cp2 = 0;
  9319.   /* Now append it to the original VMS spec. */
  9320.   strcpy (cp, Local);
  9321.  
  9322.   /* If we put a [000000] in the filename, try to open it first. If this fails,
  9323.      remove the [000000], and return that name.  This provides flexibility
  9324.      to the user in that they can use both rooted and non-rooted logical names
  9325.      to point to the location of the file.  */
  9326.  
  9327.   if (check_filename_before_returning && no_prefix_seen) {
  9328.     f = open (fname, O_RDONLY, 0666);
  9329.     if (f >= 0) {
  9330.       /* The file name is OK as it is, so return it as is.  */
  9331.       close (f);
  9332.       return;
  9333.     }
  9334.     /* The filename did not work.  Try to remove the [000000] from the name,
  9335.        and return it.  */
  9336.     cp = index (fname, '[');
  9337.     cp2 = index (fname, ']') + 1;
  9338.     strcpy (cp, cp2);        /* this gets rid of it */
  9339.   }
  9340.   return;
  9341. }
  9342. #endif    /* VMS */
  9343.  
  9344. #ifdef    VMS
  9345.  
  9346. /* These are the read/write replacement routines for
  9347.    VAX-11 "C".  They make read/write behave enough
  9348.    like their UNIX counterparts that CCCP will work */
  9349.  
  9350. static int
  9351. read (fd, buf, size)
  9352.      int fd;
  9353.      char *buf;
  9354.      int size;
  9355. {
  9356. #undef    read    /* Get back the REAL read routine */
  9357.   register int i;
  9358.   register int total = 0;
  9359.  
  9360.   /* Read until the buffer is exhausted */
  9361.   while (size > 0) {
  9362.     /* Limit each read to 32KB */
  9363.     i = (size > (32*1024)) ? (32*1024) : size;
  9364.     i = read (fd, buf, i);
  9365.     if (i <= 0) {
  9366.       if (i == 0) return (total);
  9367.       return (i);
  9368.     }
  9369.     /* Account for this read */
  9370.     total += i;
  9371.     buf += i;
  9372.     size -= i;
  9373.   }
  9374.   return (total);
  9375. }
  9376.  
  9377. static int
  9378. write (fd, buf, size)
  9379.      int fd;
  9380.      char *buf;
  9381.      int size;
  9382. {
  9383. #undef    write    /* Get back the REAL write routine */
  9384.   int i;
  9385.   int j;
  9386.  
  9387.   /* Limit individual writes to 32Kb */
  9388.   i = size;
  9389.   while (i > 0) {
  9390.     j = (i > (32*1024)) ? (32*1024) : i;
  9391.     if (write (fd, buf, j) < 0) return (-1);
  9392.     /* Account for the data written */
  9393.     buf += j;
  9394.     i -= j;
  9395.   }
  9396.   return (size);
  9397. }
  9398.  
  9399. /* The following wrapper functions supply additional arguments to the VMS
  9400.    I/O routines to optimize performance with file handling.  The arguments
  9401.    are:
  9402.      "mbc=16" - Set multi-block count to 16 (use a 8192 byte buffer).
  9403.      "deq=64" - When extending the file, extend it in chunks of 32Kbytes.
  9404.      "fop=tef"- Truncate unused portions of file when closing file.
  9405.      "shr=nil"- Disallow file sharing while file is open.
  9406.  */
  9407.  
  9408. static FILE *
  9409. freopen (fname, type, oldfile)
  9410.      char *fname;
  9411.      char *type;
  9412.      FILE *oldfile;
  9413. {
  9414. #undef    freopen    /* Get back the REAL fopen routine */
  9415.   if (strcmp (type, "w") == 0)
  9416.     return freopen (fname, type, oldfile, "mbc=16", "deq=64", "fop=tef", "shr=nil");
  9417.   return freopen (fname, type, oldfile, "mbc=16");
  9418. }
  9419.  
  9420. static FILE *
  9421. fopen (fname, type)
  9422.      char *fname;
  9423.      char *type;
  9424. {
  9425. #undef fopen    /* Get back the REAL fopen routine */
  9426.   if (strcmp (type, "w") == 0)
  9427.     return fopen (fname, type, "mbc=16", "deq=64", "fop=tef", "shr=nil");
  9428.   return fopen (fname, type, "mbc=16");
  9429. }
  9430.  
  9431. static int 
  9432. open (fname, flags, prot)
  9433.      char *fname;
  9434.      int flags;
  9435.      int prot;
  9436. {
  9437. #undef open    /* Get back the REAL open routine */
  9438.   return open (fname, flags, prot, "mbc=16", "deq=64", "fop=tef");
  9439. }
  9440.  
  9441. /* Avoid run-time library bug, where copying M out of N+M characters with
  9442.    N >= 65535 results in VAXCRTL's strncat falling into an infinite loop.
  9443.    gcc-cpp exercises this particular bug.  */
  9444.  
  9445. static char *
  9446. strncat (dst, src, cnt)
  9447.      char *dst;
  9448.      const char *src;
  9449.      unsigned cnt;
  9450. {
  9451.   register char *d = dst, *s = (char *) src;
  9452.   register int n = cnt;    /* convert to _signed_ type */
  9453.  
  9454.   while (*d) d++;    /* advance to end */
  9455.   while (--n >= 0)
  9456.     if (!(*d++ = *s++)) break;
  9457.   if (n < 0) *d = '\0';
  9458.   return dst;
  9459. }
  9460. #endif /* VMS */
  9461.  
  9462.  
  9463. #ifdef amigados
  9464.  
  9465. /* This function returns whether the LEN characters long filename FNAME 
  9466.    is an absolute path specification. */
  9467.  
  9468. static int
  9469. amigados_abs_filename (fname, len)
  9470.      char *fname;
  9471.      int len;
  9472. {
  9473.   /* we're using ixemul.library, which treats `/foo' as `foo:', so 
  9474.      fname[0] is to be considered absolute as well */
  9475.   if (fname[0] == '/')
  9476.     return 1;
  9477.  
  9478.   /* else do an index() on fname, but one which is limited to len characters */
  9479.   while (*fname && *fname != ':' && len) 
  9480.     fname++, len--;
  9481.  
  9482.   return *fname == ':';
  9483. }
  9484. #endif /* amigados */
  9485.