Add end-of-game dumplogs
[aNetHack.git] / sys / unix / cpp1.shr
blobf2b133d45df0f0737cc37037b07814461113adb4
1 # This is a shell archive.  Save it in a file, remove anything before
2 # this line, and then unpack it by entering "sh file".  Note, it may
3 # create directories; files and directories will be owned by you and
4 # have default permissions.
6 # This archive contains:
8 #       makefile.txt
9 #       readme.txt
10 #       cpp.mem
11 #       cpp.h
12 #       cppdef.h
13 #       cpp2.c
15 echo x - makefile.txt
16 sed 's/^X//' >makefile.txt << 'END-of-makefile.txt'
18 X# The redefinition of strchr() and strrchr() are needed for
19 X# Ultrix-32, Unix 4.2 bsd (and maybe some other Unices).
21 XBSDDEFINE = -Dstrchr=index -Dstrrchr=rindex
23 X# On certain systems, such as Unix System III, you may need to define
24 X# $(LINTFLAGS) in the make command line to set system-specific lint flags.
26 X# This Makefile assumes cpp will replace the "standard" preprocessor.
27 X# Delete the reference to -DLINE_PREFIX=\"\" if cpp is used stand-alone.
28 X# LINEFIX is a sed script filter that reinserts #line -- used for testing
29 X# if LINE_PREFIX is set to "".   Note that we must stand on our heads to
30 X# match the # and a line had better not begin with $.  By the way, what
31 X# we really want is
32 X#      LINEFIX = | sed "s/^#/#line/"
34 XCPPDEFINE = -DLINE_PREFIX=\"\"
35 XLINEFIX = | sed "s/^[^ !\"%-~]/&line/"
37 X# Define OLD_PREPROCESSOR non-zero to make a preprocessor which is
38 X# "as compatible as possible" with the standard Unix V7 or Ultrix
39 X# preprocessors.  This is needed to rebuild 4.2bsd, for example, as
40 X# the preprocessor is used to modify assembler code, rather than C.
41 X# This is not recommended for current development.  OLD_PREPROCESSOR
42 X# forces the following definitions:
43 X#   OK_DOLLAR          FALSE   $ is not allowed in variables
44 X#   OK_CONCAT          FALSE   # cannot concatenate tokens
45 X#   COMMENT_INVISIBLE  TRUE    old-style comment concatenation
46 X#   STRING_FORMAL      TRUE    old-style string expansion
48 XOLDDEFINE = -DOLD_PREPROCESSOR=1
50 X# DEFINES collects all -D arguments for cc and lint:
51 X# Change DEFINES = $(BSDDEFINE) $(CPPDEFINE) $(OLDDEFINE)
52 X# for an old-style preprocessor.
54 X# DEFINES = $(BSDDEFINE) $(CPPDEFINE)
55 XDEFINES = $(CPPDEFINE)
57 XCFLAGS = -O $(DEFINES)
60 X# ** compile cpp
62 XSRCS = cpp1.c cpp2.c cpp3.c cpp4.c cpp5.c cpp6.c
63 XOBJS = cpp1.o cpp2.o cpp3.o cpp4.o cpp5.o cpp6.o
64 Xcpp: $(OBJS)
65 X       $(CC) $(CFLAGS) $(OBJS) -o cpp
68 X# ** Test cpp by preprocessing itself, compiling the result,
69 X# ** repeating the process and diff'ing the result.  Note: this
70 X# ** is not a good test of cpp, but a simple verification.
71 X# ** The diff's should not report any changes.
72 X# ** Note that a sed script may be executed for each compile
74 Xtest:
75 X       cpp cpp1.c $(LINEFIX) >old.tmp1.c
76 X       cpp cpp2.c $(LINEFIX) >old.tmp2.c
77 X       cpp cpp3.c $(LINEFIX) >old.tmp3.c
78 X       cpp cpp4.c $(LINEFIX) >old.tmp4.c
79 X       cpp cpp5.c $(LINEFIX) >old.tmp5.c
80 X       cpp cpp6.c $(LINEFIX) >old.tmp6.c
81 X       $(CC) $(CFLAGS) old.tmp[123456].c
82 X       a.out cpp1.c >new.tmp1.c
83 X       a.out cpp2.c >new.tmp2.c
84 X       a.out cpp3.c >new.tmp3.c
85 X       a.out cpp4.c >new.tmp4.c
86 X       a.out cpp5.c >new.tmp5.c
87 X       a.out cpp6.c >new.tmp6.c
88 X       diff old.tmp1.c new.tmp1.c
89 X       diff old.tmp2.c new.tmp2.c
90 X       diff old.tmp3.c new.tmp3.c
91 X       diff old.tmp4.c new.tmp4.c
92 X       diff old.tmp5.c new.tmp5.c
93 X       diff old.tmp6.c new.tmp6.c
94 X       rm a.out old.tmp[123456].* new.tmp[123456].*
97 X# A somewhat more extensive test is provided by the "clock"
98 X# program (which is not distributed).  Substitute your favorite
99 X# macro-rich program here.
101 Xclock: clock.c cpp
102 X       cpp clock.c $(LINEFIX) >temp.cpp.c
103 X       cc temp.cpp.c -lcurses -ltermcap -o clock
104 X       rm temp.cpp.c
107 X# ** Lint the code
110 Xlint:  $(SRCS)
111 X       lint $(LINTFLAGS) $(DEFINES) $(SRCS)
114 X# ** Remove unneeded files
116 Xclean:
117 X       rm -f $(OBJS) cpp
120 X# ** Rebuild the archive files needed to distribute cpp
121 X# ** Uses the Decus C archive utility.
124 Xarchc: archc.c
125 X       $(CC) $(CFLAGS) archc.c -o archc
127 Xarchx: archx.c
128 X       $(CC) $(CFLAGS) archx.c -o archx
130 Xarchive: archc
131 X       archc readme.txt cpp.mem archx.c archc.c cpp.rno makefile.txt \
132 X               cpp*.h >cpp1.arc
133 X       archc cpp1.c cpp2.c cpp3.c >cpp2.arc
134 X       archc cpp4.c cpp5.c cpp6.c >cpp3.arc
137 X# Object module dependencies
140 Xcpp1.o :       cpp1.c cpp.h cppdef.h
142 Xcpp2.o :       cpp2.c cpp.h cppdef.h
144 Xcpp3.o :       cpp3.c cpp.h cppdef.h
146 Xcpp4.o :       cpp4.c cpp.h cppdef.h
148 Xcpp5.o :       cpp5.c cpp.h cppdef.h
150 Xcpp6.o :       cpp6.c cpp.h cppdef.h
153 END-of-makefile.txt
154 echo x - readme.txt
155 sed 's/^X//' >readme.txt << 'END-of-readme.txt'
157 XDecus cpp is a public-domain implementation of the C preprocessor.
158 XIt runs on VMS native (Vax C), VMS compatibilty mode (Decus C),
159 XRSX-11M, RSTS/E, P/OS, and RT11, as well as on several varieties
160 Xof Unix, including Ultrix.  Decus cpp attempts to implement features
161 Xin the Draft ANSI Standard for the C language.  It should be noted,
162 Xhowever, that this standard is under active development:  the current
163 Xdraft of the standard explicitly states that "readers are requested
164 Xnot to specify or claim conformance to this draft."  Thus readers
165 Xand users of Decus cpp should not assume that it conforms to the
166 Xdraft standard, or that it will conform to the actual C language
167 Xstandard.
169 XThese notes describe how to extract the cpp source files, configure it
170 Xfor your needs, and mention a few design decisions that may be of interest
171 Xto maintainers.
173 X                       Installation
175 XBecause the primary development of cpp was not on Unix, it
176 Xis distributed using the Decus C archive program (quite similar
177 Xto the archiver published in Kernighan and Plauger's Software
178 XTools).  To extract the files from the net.sources distribution,
179 Xsave this message as cpp1.arc and the other two distribution
180 Xfiles as cpp2.arc and cpp3.arc.  Then, using your favorite editor,
181 Xlocate the archx.c program, just following the line beginning with
182 X"-h- archx.c" -- the format of the distribution is just:
184 X    -h- readme.txt
185 X      ... this file
186 X    -h- cpp.mem
187 X      ... description of cpp
188 X    -h- archx.c
189 X      ... archx.c program -- extracts archives
190 X    -h- archc.c
191 X      ... archc.c program -- creates archives
193 XCompile archx.c -- it shouldn't require any special editing.
194 XThen run it as follows:
196 X    archx *.arc
198 XYou do not need to remove mail headers from the saved messages.
200 XYou should then read through cppdef.h to make sure the HOST and
201 XTARGET (and other implementation-specific) definitions are set
202 Xcorrectly for your machine, editing them as needed.
204 XYou may then copy makefile.txt to Makefile, editing it as needed
205 Xfor your particular system.  On Unix, cpp should be compiled
206 Xby make without further difficulty.  On other operating systems,
207 Xyou should compile the six source modules, linking them together.
208 XNote that, on Decus C based systems, you must extend the default
209 Xstack allocation.  The Decus C build utility will create the
210 Xappropriate command file.
212 X                       Support Notes
214 XThe USENET distribution kit was designed to keep all submissions around
215 X50,000 bytes:
217 Xcpp1.arc:
218 X       readme.txt      This file
219 X       cpp.mem         Documentation page (see below)
220 X       archx.c         Archive extraction program
221 X       archc.c         Archive construction program
222 X       cpp.rno         Source for cpp.mem (see below)
223 X       makefile.txt    Unix makefile -- copy to Makefile
224 X       cpp.h           Main header file (structure def's and globals)
225 X       cppdef.h        Configuration file (host and target definitions)
227 Xcpp2.arc:
228 X       cpp1.c          Mainline code, documentation master sources
229 X       cpp2.c          most #control processing
230 X       cpp3.c          filename stuff and command line parsing
231 Xcpp3.arc:
232 X       cpp4.c          #define processor
233 X       cpp5.c          #if <expr> processor
234 X       cpp6.c          Support code (symbol table and I/O routines)
235 X       
236 XCpp intentionally does not rely on the presence of a full-scale
237 Xmacro preprocessor, it does require the simple parameter substitution
238 Xpreprocessor capabilities of Unix V6 and Decus C.  If your C
239 Xlanguage lacks full preprocessing, you should make sure "nomacargs"
240 Xis #define'd in cpp.h.  (This is done automatically by the Decus C
241 Xcompiler.)
243 XThe documentation (manual page) for cpp is included as cpp.mem
244 Xand cpp.rno.  Cpp.rno is in Dec Runoff format, built by a Decus C
245 Xutility (getrno) from original source which is embedded in cpp1.c.
246 XTo my knowledge, there is no equivalent program that creates
247 Xthe nroff source appropriate for Unix.
249 XI would be happy to receive fixes to any problems you encounter.
250 XAs I do not maintain distribution kit base-levels, bare-bones
251 Xdiff listings without sufficient context are not very useful.
252 XIt is unlikely that I can find time to help you with other
253 Xdifficulties.
255 X                       Acknowledgements
257 XI received a great deal of help from many people in debugging cpp.
258 XAlan Feuer and Sam Kendall used "state of the art" run-time code
259 Xcheckers to locate several errors.  Ed Keiser found problems when
260 Xcpp was used on machines with different int and pointer sizes.
261 XDave Conroy helped with the initial debugging, while Arthur Olsen
262 Xand George Rosenberg found (and solved) several problems in the
263 Xfirst USENET release.
265 XMartin Minow
266 Xdecvax!minow
268 END-of-readme.txt
269 echo x - cpp.mem
270 sed 's/^X//' >cpp.mem << 'END-of-cpp.mem'
275 X        1.0  C Pre-Processor
279 X                                    *******
280 X                                    * cpp *
281 X                                    *******
285 X        NAME:   cpp -- C Pre-Processor
287 X        SYNOPSIS:
289 X                cpp [-options] [infile [outfile]]
291 X        DESCRIPTION:
293 X                CPP reads a C source file, expands  macros  and  include
294 X                files,  and writes an input file for the C compiler.  If
295 X                no file arguments are given, CPP reads  from  stdin  and
296 X                writes  to  stdout.   If  one file argument is given, it
297 X                will define the input file,  while  two  file  arguments
298 X                define  both  input and output files.  The file name "-"
299 X                is a synonym for stdin or stdout as appropriate.
301 X                The following options are  supported.   Options  may  be
302 X                given in either case.
304 X                -C              If set, source-file comments are written
305 X                                to  the  output  file.   This allows the
306 X                                output of CPP to be used as the input to
307 X                                a  program,  such  as lint, that expects
308 X                                commands embedded in specially-formatted
309 X                                comments.
311 X                -Dname=value    Define the name  as  if  the  programmer
312 X                                wrote
314 X                                    #define name value
316 X                                at the start  of  the  first  file.   If
317 X                                "=value"  is  not  given, a value of "1"
318 X                                will be used.
320 X                                On non-unix systems, all alphabetic text
321 X                                will be forced to upper-case.
323 X                -E              Always return "success" to the operating
324 X                                system,  even  if  errors were detected.
325 X                                Note that some fatal errors, such  as  a
326 X                                missing  #include  file,  will terminate
327 X                                CPP, returning "failure" even if the  -E
328 X                                option is given.
329 X\f                                                                          Page 2
330 X        cpp     C Pre-Processor
333 X                -Idirectory     Add  this  directory  to  the  list   of
334 X                                directories  searched for #include "..."
335 X                                and #include <...> commands.  Note  that
336 X                                there  is  no space between the "-I" and
337 X                                the directory string.  More than one  -I
338 X                                command   is   permitted.   On  non-Unix
339 X                                systems   "directory"   is   forced   to
340 X                                upper-case.
342 X                -N              CPP  normally  predefines  some  symbols
343 X                                defining   the   target   computer   and
344 X                                operating system.  If -N  is  specified,
345 X                                no symbols will be predefined.  If -N -N
346 X                                is  specified,  the   "always   present"
347 X                                symbols,    __LINE__,    __FILE__,   and
348 X                                __DATE__ are not defined.
350 X                -Stext          CPP normally assumes that  the  size  of
351 X                                the  target  computer's  basic  variable
352 X                                types is the same as the size  of  these
353 X                                types  of  the host computer.  (This can
354 X                                be  overridden  when  CPP  is  compiled,
355 X                                however.)  The  -S option allows dynamic
356 X                                respecification of these values.  "text"
357 X                                is  a  string  of  numbers, separated by
358 X                                commas, that  specifies  correct  sizes.
359 X                                The sizes must be specified in the exact
360 X                                order:
362 X                                    char short int long float double
364 X                                If you specify the option as  "-S*text",
365 X                                pointers   to   these   types   will  be
366 X                                specified.   -S*  takes  one  additional
367 X                                argument  for  pointer to function (e.g.
368 X                                int (*)())
370 X                                For   example,    to    specify    sizes
371 X                                appropriate  for  a  PDP-11,  you  would
372 X                                write:
374 X                                       c s i l f d func
375 X                                     -S1,2,2,2,4,8,
376 X                                    -S*2,2,2,2,2,2,2
378 X                                Note that all values must be specified.
380 X                -Uname          Undefine the name as if
382 X                                    #undef name
384 X                                were given.  On non-Unix systems, "name"
385 X                                will be forced to upper-case.
386 X\f                                                                          Page 3
387 X        cpp     C Pre-Processor
390 X                -Xnumber        Enable debugging code.  If no  value  is
391 X                                given,  a value of 1 will be used.  (For
392 X                                maintenence of CPP only.)
395 X        PRE-DEFINED VARIABLES:
397 X                When CPP begins processing, the following variables will
398 X                have been defined (unless the -N option is specified):
400 X                Target computer (as appropriate):
402 X                    pdp11, vax, M68000 m68000 m68k
404 X                Target operating system (as appropriate):
406 X                    rsx, rt11, vms, unix
408 X                Target compiler (as appropriate):
410 X                    decus, vax11c
412 X                The implementor may add definitions to this  list.   The
413 X                default  definitions  match  the  definition of the host
414 X                computer, operating system, and C compiler.
416 X                The following are always available unless undefined  (or
417 X                -N was specified twice):
419 X                    __FILE__    The  input  (or  #include)  file   being
420 X                                compiled (as a quoted string).
422 X                    __LINE__    The line number being compiled.
424 X                    __DATE__    The date and time of  compilation  as  a
425 X                                Unix  ctime  quoted string (the trailing
426 X                                newline is removed).  Thus,
428 X                                    printf("Bug at line %s,", __LINE__);
429 X                                    printf(" source file %s", __FILE__);
430 X                                    printf(" compiled on %s", __DATE__);
433 X        DRAFT PROPOSED ANSI STANDARD CONSIDERATIONS:
435 X                The current  version  of  the  Draft  Proposed  Standard
436 X                explicitly  states  that  "readers  are requested not to
437 X                specify or claim conformance to this draft." Readers and
438 X                users  of  Decus  CPP  should  not assume that Decus CPP
439 X                conforms to the standard, or that it will conform to the
440 X                actual C Language Standard.
442 X                When CPP is itself compiled, many features of the  Draft
443 X                Proposed  Standard  that  are incompatible with existing
444 X\f                                                                          Page 4
445 X        cpp     C Pre-Processor
448 X                preprocessors may be  disabled.   See  the  comments  in
449 X                CPP's source for details.
451 X                The latest version of the Draft  Proposed  Standard  (as
452 X                reflected in Decus CPP) is dated November 12, 1984.
454 X                Comments are removed from the input text.   The  comment
455 X                is  replaced by a single space character.  The -C option
456 X                preserves comments, writing them to the output file.
458 X                The '$' character is considered to be a letter.  This is
459 X                a permitted extension.
461 X                The following new features of C are processed by CPP:
463 X                    #elif expression (#else #if)
464 X                    '\xNNN' (Hexadecimal constant)
465 X                    '\a' (Ascii BELL)
466 X                    '\v' (Ascii Vertical Tab)
467 X                    #if defined NAME 1 if defined, 0 if not
468 X                    #if defined (NAME) 1 if defined, 0 if not
469 X                    #if sizeof (basic type)
470 X                    unary +
471 X                    123U, 123LU Unsigned ints and longs.
472 X                    12.3L Long double numbers
473 X                    token#token Token concatenation
474 X                    #include token Expands to filename
476 X                The Draft Proposed Standard has  extended  C,  adding  a
477 X                constant string concatenation operator, where
479 X                    "foo" "bar"
481 X                is regarded as the single string "foobar".   (This  does
482 X                not  affect  CPP's  processing but does permit a limited
483 X                form of macro argument substitution into strings as will
484 X                be discussed.)
486 X                The Standard Committee plans to add token  concatenation
487 X                to  #define command lines.  One suggested implementation
488 X                is as follows:  the sequence "Token1#Token2" is  treated
489 X                as  if  the programmer wrote "Token1Token2".  This could
490 X                be used as follows:
492 X                    #line 123
493 X                    #define ATLINE foo#__LINE__
495 X                ATLINE would be defined as foo123.
497 X                Note that "Token2" must either have  the  format  of  an
498 X                identifier or be a string of digits.  Thus, the string
500 X                    #define ATLINE foo#1x3
501 X\f                                                                          Page 5
502 X        cpp     C Pre-Processor
505 X                generates two tokens:  "foo1" and "x3".
507 X                If the tokens T1 and T2 are concatenated into  T3,  this
508 X                implementation operates as follows:
510 X                  1. Expand T1 if it is a macro.
511 X                  2. Expand T2 if it is a macro.
512 X                  3. Join the tokens, forming T3.
513 X                  4. Expand T3 if it is a macro.
515 X                A macro formal parameter  will  be  substituted  into  a
516 X                string or character constant if it is the only component
517 X                of that constant:
519 X                    #define VECSIZE 123
520 X                    #define vprint(name, size) \
521 X                      printf("name" "[" "size" "] = {\n")
522 X                      ... vprint(vector, VECSIZE);
524 X                expands (effectively) to
526 X                      vprint("vector[123] = {\n");
528 X                Note that  this  will  be  useful  if  your  C  compiler
529 X                supports  the  new  string concatenation operation noted
530 X                above.  As implemented here, if you write
532 X                    #define string(arg) "arg"
533 X                      ... string("foo") ...
535 X                This implementation generates  "foo",  rather  than  the
536 X                strictly  correct  ""foo"" (which will probably generate
537 X                an error message).  This is, strictly speaking, an error
538 X                in CPP and may be removed from future releases.
540 X        ERROR MESSAGES:
542 X                Many.  CPP prints warning or error messages if  you  try
543 X                to     use     multiple-byte     character     constants
544 X                (non-transportable) if you #undef a symbol that was  not
545 X                defined,  or  if  your  program  has  potentially nested
546 X                comments.
548 X        AUTHOR:
550 X                Martin Minow
552 X        BUGS:
554 X                The #if expression processor uses signed integers  only.
555 X                I.e, #if 0xFFFFu < 0 may be TRUE.
557 END-of-cpp.mem
558 echo x - cpp.h
559 sed 's/^X//' >cpp.h << 'END-of-cpp.h'
562 X *     I n t e r n a l   D e f i n i t i o n s    f o r   C P P
563 X *
564 X * In general, definitions in this file should not be changed.
565 X */
567 X#ifndef        TRUE
568 X#define        TRUE            1
569 X#define        FALSE           0
570 X#endif
571 X#ifndef        EOS
573 X * This is predefined in Decus C
574 X */
575 X#define        EOS             '\0'            /* End of string                */
576 X#endif
577 X#define        EOF_CHAR        0               /* Returned by get() on eof     */
578 X#define NULLST         ((char *) NULL) /* Pointer to nowhere (linted)  */
579 X#define        DEF_NOARGS      (-1)            /* #define foo vs #define foo() */
582 X * The following may need to change if the host system doesn't use ASCII.
583 X */
584 X#define        DEF_MAGIC       0x1D            /* Magic for #defines           */
585 X#define        TOK_SEP         0x1E            /* Token concatenation delim.   */
586 X#define COM_SEP                0x1F            /* Magic comment separator      */
589 X * Note -- in Ascii, the following will map macro formals onto DEL + the
590 X * C1 control character region (decimal 128 .. (128 + PAR_MAC)) which will
591 X * be ok as long as PAR_MAC is less than 33).  Note that the last PAR_MAC
592 X * value is reserved for string substitution.
593 X */
595 X#define        MAC_PARM        0x7F            /* Macro formals start here     */
596 X#if PAR_MAC >= 33
597 X       assertion fails -- PAR_MAC isn't less than 33
598 X#endif
599 X#define        LASTPARM        (PAR_MAC - 1)
602 X * Character type codes.
603 X */
605 X#define        INV             0               /* Invalid, must be zero        */
606 X#define        OP_EOE          INV             /* End of expression            */
607 X#define        DIG             1               /* Digit                        */
608 X#define        LET             2               /* Identifier start             */
609 X#define        FIRST_BINOP     OP_ADD
610 X#define        OP_ADD          3
611 X#define        OP_SUB          4
612 X#define        OP_MUL          5
613 X#define        OP_DIV          6
614 X#define        OP_MOD          7
615 X#define        OP_ASL          8
616 X#define        OP_ASR          9
617 X#define        OP_AND          10              /* &, not &&                    */
618 X#define        OP_OR           11              /* |, not ||                    */
619 X#define        OP_XOR          12
620 X#define        OP_EQ           13
621 X#define        OP_NE           14
622 X#define        OP_LT           15
623 X#define        OP_LE           16
624 X#define        OP_GE           17
625 X#define        OP_GT           18
626 X#define        OP_ANA          19              /* &&                           */
627 X#define        OP_ORO          20              /* ||                           */
628 X#define        OP_QUE          21              /* ?                            */
629 X#define        OP_COL          22              /* :                            */
630 X#define        OP_CMA          23              /* , (relevant?)                */
631 X#define        LAST_BINOP      OP_CMA          /* Last binary operand          */
633 X * The following are unary.
634 X */
635 X#define        FIRST_UNOP      OP_PLU          /* First Unary operand          */
636 X#define        OP_PLU          24              /* + (draft ANSI standard)      */
637 X#define        OP_NEG          25              /* -                            */
638 X#define        OP_COM          26              /* ~                            */
639 X#define        OP_NOT          27              /* !                            */
640 X#define        LAST_UNOP       OP_NOT
641 X#define        OP_LPA          28              /* (                            */
642 X#define        OP_RPA          29              /* )                            */
643 X#define        OP_END          30              /* End of expression marker     */
644 X#define        OP_MAX          (OP_END + 1)    /* Number of operators          */
645 X#define        OP_FAIL         (OP_END + 1)    /* For error returns            */
648 X * The following are for lexical scanning only.
649 X */
651 X#define        QUO             65              /* Both flavors of quotation    */
652 X#define        DOT             66              /* . might start a number       */
653 X#define        SPA             67              /* Space and tab                */
654 X#define        BSH             68              /* Just a backslash             */
655 X#define        END             69              /* EOF                          */
658 X * These bits are set in ifstack[]
659 X */
660 X#define        WAS_COMPILING   1               /* TRUE if compile set at entry */
661 X#define        ELSE_SEEN       2               /* TRUE when #else processed    */
662 X#define        TRUE_SEEN       4               /* TRUE when #if TRUE processed */
665 X * Define bits for the basic types and their adjectives
666 X */
668 X#define        T_CHAR            1
669 X#define        T_INT             2
670 X#define        T_FLOAT           4
671 X#define        T_DOUBLE          8
672 X#define        T_SHORT          16
673 X#define        T_LONG           32
674 X#define        T_SIGNED         64
675 X#define        T_UNSIGNED      128
676 X#define        T_PTR           256             /* Pointer                      */
677 X#define        T_FPTR          512             /* Pointer to functions         */
680 X * The DEFBUF structure stores information about #defined
681 X * macros.  Note that the defbuf->repl information is always
682 X * in malloc storage.
683 X */
685 Xtypedef struct defbuf {
686 X       struct defbuf   *link;          /* Next define in chain */
687 X       char            *repl;          /* -> replacement       */
688 X       int             hash;           /* Symbol table hash    */
689 X       int             nargs;          /* For define(args)     */
690 X       char            name[1];        /* #define name         */
691 X} DEFBUF;
694 X * The FILEINFO structure stores information about open files
695 X * and macros being expanded.
696 X */
698 Xtypedef struct fileinfo {
699 X       char            *bptr;          /* Buffer pointer       */
700 X       int             line;           /* for include or macro */
701 X       FILE            *fp;            /* File if non-null     */
702 X       struct fileinfo *parent;        /* Link to includer     */
703 X       char            *filename;      /* File/macro name      */
704 X       char            *progname;      /* From #line statement */
705 X       unsigned int    unrecur;        /* For macro recursion  */
706 X       char            buffer[1];      /* current input line   */
707 X} FILEINFO;
710 X * The SIZES structure is used to store the values for #if sizeof
711 X */
713 Xtypedef struct sizes {
714 X    short      bits;                   /* If this bit is set,          */
715 X    short      size;                   /* this is the datum size value */
716 X    short      psize;                  /* this is the pointer size     */
717 X} SIZES;
719 X * nomacarg is a built-in #define on Decus C.
720 X */
722 X#ifdef nomacarg
723 X#define        cput            output          /* cput concatenates tokens     */
724 X#else
725 X#if COMMENT_INVISIBLE
726 X#define        cput(c)         { if (c != TOK_SEP && c != COM_SEP) putchar(c); }
727 X#else
728 X#define        cput(c)         { if (c != TOK_SEP) putchar(c); }
729 X#endif
730 X#endif
732 X#ifndef        nomacarg
733 X#define        streq(s1, s2)   (strcmp(s1, s2) == 0)
734 X#endif
737 X * Error codes.  VMS uses system definitions.
738 X * Decus C codes are defined in stdio.h.
739 X * Others are cooked to order.
740 X */
742 X#if HOST == SYS_VMS
743 X#include               <ssdef.h>
744 X#include               <stsdef.h>
745 X#define        IO_NORMAL       (SS$_NORMAL | STS$M_INHIB_MSG)
746 X#define        IO_ERROR        SS$_ABORT
747 X#endif
749 X * Note: IO_NORMAL and IO_ERROR are defined in the Decus C stdio.h file
750 X */
751 X#ifndef        IO_NORMAL
752 X#define        IO_NORMAL       0
753 X#endif
754 X#ifndef        IO_ERROR
755 X#define        IO_ERROR        1
756 X#endif
759 X * Externs
760 X */
762 Xextern int     line;                   /* Current line number          */
763 Xextern int     wrongline;              /* Force #line to cc pass 1     */
764 Xextern char    type[];                 /* Character classifier         */
765 Xextern char    token[IDMAX + 1];       /* Current input token          */
766 Xextern int     instring;               /* TRUE if scanning string      */
767 Xextern int     inmacro;                /* TRUE if scanning #define     */
768 Xextern int     errors;                 /* Error counter                */
769 Xextern int     recursion;              /* Macro depth counter          */
770 Xextern char    ifstack[BLK_NEST];      /* #if information              */
771 X#define        compiling ifstack[0]
772 Xextern char    *ifptr;                 /* -> current ifstack item      */
773 Xextern char    *incdir[NINCLUDE];      /* -i directories               */
774 Xextern char    **incend;               /* -> active end of incdir      */
775 Xextern int     cflag;                  /* -C option (keep comments)    */
776 Xextern int     eflag;                  /* -E option (ignore errors)    */
777 Xextern int     nflag;                  /* -N option (no pre-defines)   */
778 Xextern int     rec_recover;            /* unwind recursive macros      */
779 Xextern char    *preset[];              /* Standard predefined symbols  */
780 Xextern char    *magic[];               /* Magic predefined symbols     */
781 Xextern FILEINFO        *infile;                /* Current input file           */
782 Xextern char    work[NWORK + 1];        /* #define scratch              */
783 Xextern char    *workp;                 /* Free space in work           */
784 X#if    DEBUG
785 Xextern int     debug;                  /* Debug level                  */
786 X#endif
787 Xextern int     keepcomments;           /* Don't remove comments if set */
788 Xextern SIZES   size_table[];           /* For #if sizeof sizes         */
789 Xextern char    *getmem();              /* Get memory or die.           */
790 Xextern DEFBUF  *lookid();              /* Look for a #define'd thing   */
791 Xextern DEFBUF  *defendel();            /* Symbol table enter/delete    */
792 Xextern char    *savestring();          /* Stuff string in malloc mem.  */
793 Xextern char    *strcpy();
794 Xextern char    *strcat();
795 Xextern char    *strrchr();
796 Xextern char    *strchr();
797 Xextern long    time();
798 X/* extern char *sprintf();             /* Lint needs this              */
799 END-of-cpp.h
800 echo x - cppdef.h
801 sed 's/^X//' >cppdef.h << 'END-of-cppdef.h'
803 X *                S y s t e m   D e p e n d e n t
804 X *             D e f i n i t i o n s    f o r   C P P
805 X *
806 X * Definitions in this file may be edited to configure CPP for particular
807 X * host operating systems and target configurations.
808 X *
809 X * NOTE: cpp assumes it is compiled by a compiler that supports macros
810 X * with arguments.  If this is not the case (as for Decus C), #define
811 X * nomacarg -- and provide function equivalents for all macros.
812 X *
813 X * cpp also assumes the host and target implement the Ascii character set.
814 X * If this is not the case, you will have to do some editing here and there.
815 X */
818 X * This redundant definition of TRUE and FALSE works around
819 X * a limitation of Decus C.
820 X */
821 X#ifndef        TRUE
822 X#define        TRUE                    1
823 X#define        FALSE                   0
824 X#endif
827 X * Define the HOST operating system.  This is needed so that
828 X * cpp can use appropriate filename conventions.
829 X */
830 X#define        SYS_UNKNOWN             0
831 X#define        SYS_UNIX                1
832 X#define        SYS_VMS                 2
833 X#define        SYS_RSX                 3
834 X#define        SYS_RT11                4
835 X#define        SYS_LATTICE             5
836 X#define        SYS_ONYX                6
837 X#define        SYS_68000               7
838 X#define SYS_GCOS               8
839 X#define SYS_IBM                        9
840 X#define SYS_OS                 10
841 X#define SYS_TSS                        11
843 X#ifndef        HOST
844 X#ifdef unix
845 X#define        HOST                    SYS_UNIX
846 X#else
847 X#ifdef vms
848 X#define        HOST                    SYS_VMS
849 X#else
850 X#ifdef rsx
851 X#define        HOST                    SYS_RSX
852 X#else
853 X#ifdef rt11
854 X#define        HOST                    SYS_RT11
855 X#else
856 X#ifdef dmert
857 X#define HOST                   SYS_DMERT
858 X#else
859 X#ifdef gcos
860 X#define HOST                   SYS_GCOS
861 X#else
862 X#ifdef ibm
863 X#define HOST                   SYS_IBM
864 X#else
865 X#ifdef os
866 X#define HOST                   SYS_OS
867 X#else
868 X#ifdef tss                     
869 X#define HOST                   SYS_TSS
870 X#endif
871 X#endif
872 X#endif
873 X#endif
874 X#endif
875 X#endif
876 X#endif
877 X#endif
878 X#endif
880 X#ifndef        HOST
881 X#define        HOST                    SYS_UNKNOWN
882 X#endif
885 X * We assume that the target is the same as the host system
886 X */
887 X#ifndef        TARGET
888 X#define        TARGET                  HOST
889 X#endif
892 X * In order to predefine machine-dependent constants,
893 X * several strings are defined here:
894 X *
895 X * MACHINE     defines the target cpu (by name)
896 X * SYSTEM      defines the target operating system
897 X * COMPILER    defines the target compiler
898 X *
899 X *     The above may be #defined as "" if they are not wanted.
900 X *     They should not be #defined as NULL.
901 X *
902 X * LINE_PREFIX defines the # output line prefix, if not "line"
903 X *             This should be defined as "" if cpp is to replace
904 X *             the "standard" C pre-processor.
905 X *
906 X * FILE_LOCAL  marks functions which are referenced only in the
907 X *             file they reside.  Some C compilers allow these
908 X *             to be marked "static" even though they are referenced
909 X *             by "extern" statements elsewhere.
910 X *
911 X * OK_DOLLAR   Should be set TRUE if $ is a valid alphabetic character
912 X *             in identifiers (default), or zero if $ is invalid.
913 X *             Default is TRUE.
914 X *
915 X * OK_CONCAT   Should be set TRUE if # may be used to concatenate
916 X *             tokens in macros (per the Ansi Draft Standard) or
917 X *             FALSE for old-style # processing (needed if cpp is
918 X *             to process assembler source code).
919 X *
920 X * OK_DATE     Predefines the compilation date if set TRUE.
921 X *             Not permitted by the Nov. 12, 1984 Draft Standard.
922 X *
923 X * S_CHAR etc. Define the sizeof the basic TARGET machine word types.
924 X *             By default, sizes are set to the values for the HOST
925 X *             computer.  If this is inappropriate, see the code in
926 X *             cpp3.c for details on what to change.  Also, if you
927 X *             have a machine where sizeof (signed int) differs from
928 X *             sizeof (unsigned int), you will have to edit code and
929 X *             tables in cpp3.c (and extend the -S option definition.)
930 X *
931 X * CPP_LIBRARY May be defined if you have a site-specific include directory
932 X *             which is to be searched *before* the operating-system
933 X *             specific directories.
934 X */
936 X#if TARGET == SYS_LATTICE
938 X * We assume the operating system is pcdos for the IBM-PC.
939 X * We also assume the small model (just like the PDP-11)
940 X */
941 X#define MACHINE                        "i8086"
942 X#define        SYSTEM                  "pcdos"
943 X#endif
945 X#if TARGET == SYS_ONYX
946 X#define        MACHINE                 "z8000"
947 X#define        SYSTEM                  "unix"
948 X#endif
950 X#if TARGET == SYS_VMS
951 X#define        MACHINE                 "vax"
952 X#define        SYSTEM                  "vms"
953 X#define        COMPILER                "vax11c"
954 X#endif
956 X#if TARGET == SYS_RSX
957 X#define        MACHINE                 "pdp11"
958 X#define        SYSTEM                  "rsx"
959 X#define        COMPILER                "decus"
960 X#endif
962 X#if TARGET == SYS_RT11
963 X#define        MACHINE                 "pdp11"
964 X#define        SYSTEM                  "rt11"
965 X#define        COMPILER                "decus"
966 X#endif
968 X#if TARGET == SYS_68000
970 X * All three machine designators have been seen in various systems.
971 X * Warning -- compilers differ as to sizeof (int).  cpp3 assumes that
972 X * sizeof (int) == 2
973 X */
974 X#define        MACHINE                 "M68000", "m68000", "m68k"
975 X#define        SYSTEM                  "unix"
976 X#endif
978 X#if    TARGET == SYS_UNIX
979 X#define        SYSTEM                  "unix"
980 X#ifdef pdp11
981 X#define        MACHINE                 "pdp11"
982 X#endif
983 X#ifdef vax
984 X#define        MACHINE                 "vax"
985 X#endif
986 X#ifdef u370
987 X#define MACHINE                        "u370"
988 X#endif
989 X#ifdef interdata
990 X#define MACHINE                        "interdata"
991 X#endif
992 X#ifdef u3b
993 X#define MACHINE                        "u3b"
994 X#endif
995 X#ifdef u3b5    
996 X#define MACHINE                        "u3b5"
997 X#endif
998 X#ifdef u3b2
999 X#define MACHINE                        "u3b2"
1000 X#endif
1001 X#ifdef u3b20d
1002 X#define MACHINE                        "u3b20d"
1003 X#endif
1004 X#endif
1005 X#endif
1008 X * defaults
1009 X */
1011 X#ifndef MSG_PREFIX
1012 X#define MSG_PREFIX             "cpp: "
1013 X#endif
1015 X#ifndef LINE_PREFIX
1016 X#ifdef decus
1017 X#define        LINE_PREFIX             ""
1018 X#else
1019 X#define LINE_PREFIX            "line"
1020 X#endif
1021 X#endif
1024 X * OLD_PREPROCESSOR forces the definition of OK_DOLLAR, OK_CONCAT,
1025 X * COMMENT_INVISIBLE, and STRING_FORMAL to values appropriate for
1026 X * an old-style preprocessor.
1027 X */
1029 X#ifndef        OLD_PREPROCESSOR
1030 X#define        OLD_PREPROCESSOR        FALSE
1031 X#endif
1033 X#if    OLD_PREPROCESSOR
1034 X#define        OK_DOLLAR               FALSE
1035 X#define        OK_CONCAT               FALSE
1036 X#define        COMMENT_INVISIBLE       TRUE
1037 X#define        STRING_FORMAL           TRUE
1038 X#endif
1041 X * RECURSION_LIMIT may be set to -1 to disable the macro recursion test.
1042 X */
1043 X#ifndef        RECURSION_LIMIT
1044 X#define        RECURSION_LIMIT 1000
1045 X#endif
1048 X * BITS_CHAR may be defined to set the number of bits per character.
1049 X * it is needed only for multi-byte character constants.
1050 X */
1051 X#ifndef        BITS_CHAR
1052 X#define        BITS_CHAR               8
1053 X#endif
1056 X * BIG_ENDIAN is set TRUE on machines (such as the IBM 360 series)
1057 X * where 'ab' stores 'a' in the high-bits and 'b' in the low-bits.
1058 X * It is set FALSE on machines (such as the PDP-11 and Vax-11)
1059 X * where 'ab' stores 'a' in the low-bits and 'b' in the high-bits.
1060 X * (Or is it the other way around?) -- Warning: BIG_ENDIAN code is untested.
1061 X */
1062 X#ifndef        BIG_ENDIAN
1063 X#define        BIG_ENDIAN              FALSE
1064 X#endif
1067 X * COMMENT_INVISIBLE may be defined to allow "old-style" comment
1068 X * processing, whereby the comment becomes a zero-length token
1069 X * delimiter.  This permitted tokens to be concatenated in macro
1070 X * expansions.  This was removed from the Draft Ansi Standard.
1071 X */
1072 X#ifndef        COMMENT_INVISIBLE
1073 X#define        COMMENT_INVISIBLE       FALSE
1074 X#endif
1077 X * STRING_FORMAL may be defined to allow recognition of macro parameters
1078 X * anywhere in replacement strings.  This was removed from the Draft Ansi
1079 X * Standard and a limited recognition capability added.
1080 X */
1081 X#ifndef        STRING_FORMAL
1082 X#define        STRING_FORMAL           FALSE
1083 X#endif
1086 X * OK_DOLLAR enables use of $ as a valid "letter" in identifiers.
1087 X * This is a permitted extension to the Ansi Standard and is required
1088 X * for e.g., VMS, RSX-11M, etc.   It should be set FALSE if cpp is
1089 X * used to preprocess assembler source on Unix systems.  OLD_PREPROCESSOR
1090 X * sets OK_DOLLAR FALSE for that reason.
1091 X */
1092 X#ifndef        OK_DOLLAR
1093 X#define        OK_DOLLAR               TRUE
1094 X#endif
1097 X * OK_CONCAT enables (one possible implementation of) token concatenation.
1098 X * If cpp is used to preprocess Unix assembler source, this should be
1099 X * set FALSE as the concatenation character, #, is used by the assembler.
1100 X */
1101 X#ifndef        OK_CONCAT
1102 X#define        OK_CONCAT               TRUE
1103 X#endif
1106 X * OK_DATE may be enabled to predefine today's date as a string
1107 X * at the start of each compilation.  This is apparently not permitted
1108 X * by the Draft Ansi Standard.
1109 X */
1110 X#ifndef        OK_DATE
1111 X#define        OK_DATE         TRUE
1112 X#endif
1115 X * Some common definitions.
1116 X */
1118 X#ifndef        DEBUG
1119 X#define        DEBUG                   FALSE
1120 X#endif
1123 X * The following definitions are used to allocate memory for
1124 X * work buffers.  In general, they should not be modified
1125 X * by implementors.
1126 X *
1127 X * PAR_MAC     The maximum number of #define parameters (31 per Standard)
1128 X *             Note: we need another one for strings.
1129 X * IDMAX       The longest identifier, 31 per Ansi Standard
1130 X * NBUFF       Input buffer size
1131 X * NWORK       Work buffer size -- the longest macro
1132 X *             must fit here after expansion.
1133 X * NEXP                The nesting depth of #if expressions
1134 X * NINCLUDE    The number of directories that may be specified
1135 X *             on a per-system basis, or by the -I option.
1136 X * BLK_NEST    The number of nested #if's permitted.
1137 X */
1139 X#define        IDMAX                    31
1140 X#define        PAR_MAC            (31 + 1)
1141 X#define        NBUFF                  1024
1142 X#define        NWORK                  1024
1143 X#define        NEXP                    128
1144 X#define        NINCLUDE                  7
1145 X#define        NPARMWORK               (NWORK * 2)
1146 X#define        BLK_NEST                32
1149 X * Some special constants.  These may need to be changed if cpp
1150 X * is ported to a wierd machine.
1151 X *
1152 X * NOTE: if cpp is run on a non-ascii machine, ALERT and VT may
1153 X * need to be changed.  They are used to implement the proposed
1154 X * ANSI standard C control characters '\a' and '\v' only.
1155 X * DEL is used to tag macro tokens to prevent #define foo foo
1156 X * from looping.  Note that we don't try to prevent more elaborate
1157 X * #define loops from occurring.
1158 X */
1160 X#ifndef        ALERT
1161 X#define        ALERT                   '\007'          /* '\a' is "Bell"       */
1162 X#endif
1164 X#ifndef        VT
1165 X#define        VT                      '\013'          /* Vertical Tab CTRL/K  */
1166 X#endif
1169 X#ifndef        FILE_LOCAL
1170 X#ifdef decus
1171 X#define        FILE_LOCAL              static
1172 X#else
1173 X#ifdef vax11c
1174 X#define        FILE_LOCAL              static
1175 X#else
1176 X#define        FILE_LOCAL                              /* Others are global    */
1177 X#endif
1178 X#endif
1179 X#endif
1181 END-of-cppdef.h
1182 echo x - cpp2.c
1183 sed 's/^X//' >cpp2.c << 'END-of-cpp2.c'
1185 X *                             C P P 2 . C
1186 X *
1187 X *                        Process #control lines
1188 X *
1189 X * Edit history
1190 X * 13-Nov-84   MM      Split from cpp1.c
1191 X */
1193 X#include       <stdio.h>
1194 X#include       <ctype.h>
1195 X#include       "cppdef.h"
1196 X#include       "cpp.h"
1197 X#if HOST == SYS_VMS
1199 X * Include the rms stuff.  (We can't just include rms.h as it uses the
1200 X * VaxC-specific library include syntax that Decus CPP doesn't support.
1201 X * By including things by hand, we can CPP ourself.)
1202 X */
1203 X#include       <nam.h>
1204 X#include       <fab.h>
1205 X#include       <rab.h>
1206 X#include       <rmsdef.h>
1207 X#endif
1210 X * Generate (by hand-inspection) a set of unique values for each control
1211 X * operator.  Note that this is not guaranteed to work for non-Ascii
1212 X * machines.  CPP won't compile if there are hash conflicts.
1213 X */
1215 X#define        L_assert        ('a' + ('s' << 1))
1216 X#define        L_define        ('d' + ('f' << 1))
1217 X#define        L_elif          ('e' + ('i' << 1))
1218 X#define        L_else          ('e' + ('s' << 1))
1219 X#define        L_endif         ('e' + ('d' << 1))
1220 X#define L_ident                ('i' + ('e' << 1))
1221 X#define        L_if            ('i' + (EOS << 1))
1222 X#define        L_ifdef         ('i' + ('d' << 1))
1223 X#define        L_ifndef        ('i' + ('n' << 1))
1224 X#define        L_include       ('i' + ('c' << 1))
1225 X#define        L_line          ('l' + ('n' << 1))
1226 X#define        L_nogood        (EOS + (EOS << 1))      /* To catch #i          */
1227 X#define        L_pragma        ('p' + ('a' << 1))
1228 X#define        L_sccs          ('s' + ('c' << 1))
1229 X#define L_undef                ('u' + ('d' << 1))
1230 X#if DEBUG
1231 X#define        L_debug         ('d' + ('b' << 1))      /* #debug               */
1232 X#define        L_nodebug       ('n' + ('d' << 1))      /* #nodebug             */
1233 X#endif
1235 Xint
1236 Xcontrol(counter)
1237 Xint            counter;        /* Pending newline counter              */
1239 X * Process #control lines.  Simple commands are processed inline,
1240 X * while complex commands have their own subroutines.
1241 X *
1242 X * The counter is used to force out a newline before #line, and
1243 X * #pragma commands.  This prevents these commands from ending up at
1244 X * the end of the previous line if cpp is invoked with the -C option.
1245 X */
1247 X       register int            c;
1248 X       register char           *tp;
1249 X       register int            hash;
1250 X       char                    *ep;
1252 X       c = skipws();
1253 X       if (c == '\n' || c == EOF_CHAR)
1254 X           return (counter + 1);
1255 X       if (!isdigit(c))
1256 X           scanid(c);                  /* Get #word to token[]         */
1257 X       else {
1258 X           unget();                    /* Hack -- allow #123 as a      */
1259 X           strcpy(token, "line");      /* synonym for #line 123        */
1260 X       }
1261 X       hash = (token[1] == EOS) ? L_nogood : (token[0] + (token[2] << 1));
1262 X       switch (hash) {
1263 X       case L_assert:  tp = "assert";          break;
1264 X       case L_define:  tp = "define";          break;
1265 X       case L_elif:    tp = "elif";            break;
1266 X       case L_else:    tp = "else";            break;
1267 X       case L_endif:   tp = "endif";           break;
1268 X       case L_ident:   tp = "ident";           break;
1269 X       case L_if:      tp = "if";              break;
1270 X       case L_ifdef:   tp = "ifdef";           break;
1271 X       case L_ifndef:  tp = "ifndef";          break;
1272 X       case L_include: tp = "include";         break;
1273 X       case L_line:    tp = "line";            break;
1274 X       case L_pragma:  tp = "pragma";          break;
1275 X       case L_sccs:    tp = "sccs";            break;
1276 X       case L_undef:   tp = "undef";           break;
1277 X#if DEBUG
1278 X       case L_debug:   tp = "debug";           break;
1279 X       case L_nodebug: tp = "nodebug";         break;
1280 X#endif
1281 X       default:        hash = L_nogood;
1282 X       case L_nogood:  tp = "";                break;
1283 X       }
1284 X       if (!streq(tp, token))
1285 X           hash = L_nogood;
1286 X       /*
1287 X        * hash is set to a unique value corresponding to the
1288 X        * control keyword (or L_nogood if we think it's nonsense).
1289 X        */
1290 X       if (infile->fp == NULL)
1291 X           cwarn("Control line \"%s\" within macro expansion", token);
1292 X       if (!compiling) {                       /* Not compiling now    */
1293 X           switch (hash) {
1294 X           case L_if:                          /* These can't turn     */
1295 X           case L_ifdef:                       /*  compilation on, but */
1296 X           case L_ifndef:                      /*   we must nest #if's */
1297 X               if (++ifptr >= &ifstack[BLK_NEST])
1298 X                   goto if_nest_err;
1299 X               *ifptr = 0;                     /* !WAS_COMPILING       */
1300 X           case L_line:                        /* Many                 */
1301 X           /*
1302 X            * Are pragma's always processed?
1303 X            */
1304 X           case L_ident:
1305 X           case L_sccs:
1306 X           case L_pragma:                      /*  options             */
1307 X           case L_include:                     /*   are uninteresting  */
1308 X           case L_define:                      /*    if we             */
1309 X           case L_undef:                       /*     aren't           */
1310 X           case L_assert:                      /*      compiling.      */
1311 Xdump_line:     skipnl();                       /* Ignore rest of line  */
1312 X               return (counter + 1);
1313 X           }
1314 X       }
1315 X       /*
1316 X        * Make sure that #line and #pragma are output on a fresh line.
1317 X        */
1318 X       if (counter > 0 && (hash == L_line || hash == L_pragma)) {
1319 X           putchar('\n');
1320 X           counter--;
1321 X       }
1322 X       switch (hash) {
1323 X       case L_line:
1324 X           /*
1325 X            * Parse the line to update the line number and "progname"
1326 X            * field and line number for the next input line.
1327 X            * Set wrongline to force it out later.
1328 X            */
1329 X           c = skipws();
1330 X           workp = work;                       /* Save name in work    */
1331 X           while (c != '\n' && c != EOF_CHAR) {
1332 X               save(c);
1333 X               c = get();
1334 X           }
1335 X           unget();
1336 X           save(EOS);
1337 X           /*
1338 X            * Split #line argument into <line-number> and <name>
1339 X            * We subtract 1 as we want the number of the next line.
1340 X            */
1341 X           line = atoi(work) - 1;              /* Reset line number    */
1342 X           for (tp = work; isdigit(*tp) || type[*tp] == SPA; tp++)
1343 X               ;                               /* Skip over digits     */
1344 X           if (*tp != EOS) {                   /* Got a filename, so:  */
1345 X               if (*tp == '"' && (ep = strrchr(tp + 1, '"')) != NULL) {
1346 X                   tp++;                       /* Skip over left quote */
1347 X                   *ep = EOS;                  /* And ignore right one */
1348 X               }
1349 X               if (infile->progname != NULL)   /* Give up the old name */
1350 X                   free(infile->progname);     /* if it's allocated.   */
1351 X               infile->progname = savestring(tp);
1352 X           }
1353 X           wrongline = TRUE;                   /* Force output later   */
1354 X           break;
1356 X       case L_include:
1357 X           doinclude();
1358 X           break;
1360 X       case L_define:
1361 X           dodefine();
1362 X           break;
1364 X       case L_undef:
1365 X           doundef();
1366 X           break;
1368 X       case L_else:
1369 X           if (ifptr == &ifstack[0])
1370 X               goto nest_err;
1371 X           else if ((*ifptr & ELSE_SEEN) != 0)
1372 X               goto else_seen_err;
1373 X           *ifptr |= ELSE_SEEN;
1374 X           if ((*ifptr & WAS_COMPILING) != 0) {
1375 X               if (compiling || (*ifptr & TRUE_SEEN) != 0)
1376 X                   compiling = FALSE;
1377 X               else {
1378 X                   compiling = TRUE;
1379 X               }
1380 X           }
1381 X           break;
1383 X       case L_elif:
1384 X           if (ifptr == &ifstack[0])
1385 X               goto nest_err;
1386 X           else if ((*ifptr & ELSE_SEEN) != 0) {
1387 Xelse_seen_err: cerror("#%s may not follow #else", token);
1388 X               goto dump_line;
1389 X           }
1390 X           if ((*ifptr & (WAS_COMPILING | TRUE_SEEN)) != WAS_COMPILING) {
1391 X               compiling = FALSE;              /* Done compiling stuff */
1392 X               goto dump_line;                 /* Skip this clause     */
1393 X           }
1394 X           doif(L_if);
1395 X           break;
1397 X       case L_if:
1398 X       case L_ifdef:
1399 X       case L_ifndef:
1400 X           if (++ifptr >= &ifstack[BLK_NEST])
1401 Xif_nest_err:   cfatal("Too many nested #%s statements", token);
1402 X           *ifptr = WAS_COMPILING;
1403 X           doif(hash);
1404 X           break;
1406 X       case L_endif:
1407 X           if (ifptr == &ifstack[0]) {
1408 Xnest_err:      cerror("#%s must be in an #if", token);
1409 X               goto dump_line;
1410 X           }
1411 X           if (!compiling && (*ifptr & WAS_COMPILING) != 0)
1412 X               wrongline = TRUE;
1413 X           compiling = ((*ifptr & WAS_COMPILING) != 0);
1414 X           --ifptr;
1415 X           break;
1417 X       case L_assert:
1418 X           if (eval() == 0)
1419 X               cerror("Preprocessor assertion failure", NULLST);
1420 X           break;
1422 X       case L_ident:
1423 X       case L_sccs:
1424 X           goto dump_line;
1425 X           break;
1427 X       case L_pragma:
1428 X           /*
1429 X            * #pragma is provided to pass "options" to later
1430 X            * passes of the compiler.  cpp doesn't have any yet.
1431 X            */
1432 X           printf("#pragma ");
1433 X           while ((c = get()) != '\n' && c != EOF_CHAR)
1434 X               cput(c);
1435 X           unget();
1436 X           break;
1438 X#if DEBUG
1439 X       case L_debug:
1440 X           if (debug == 0)
1441 X               dumpdef("debug set on");
1442 X           debug++;
1443 X           break;
1445 X       case L_nodebug:
1446 X           debug--;
1447 X           break;
1448 X#endif
1450 X       default:
1451 X           /*
1452 X            * Undefined #control keyword.
1453 X            * Note: the correct behavior may be to warn and
1454 X            * pass the line to a subsequent compiler pass.
1455 X            * This would allow #asm or similar extensions.
1456 X            */
1457 X           cerror("Illegal # command \"%s\"", token);
1458 X           break;
1459 X       }
1460 X       if (hash != L_include) {
1461 X#if OLD_PREPROCESSOR || !VERBOSE
1462 X           /*
1463 X            * Ignore the rest of the #control line so you can write
1464 X            *          #if     foo
1465 X            *          #endif  foo
1466 X            */
1467 X           goto dump_line;                     /* Take common exit     */
1468 X#else
1469 X           if (skipws() != '\n') {
1470 X               cwarn("Unexpected text in #control line ignored", NULLST);
1471 X               skipnl();
1472 X           }
1473 X#endif
1474 X       }
1475 X       return (counter + 1);
1478 XFILE_LOCAL
1479 Xdoif(hash)
1480 Xint            hash;
1482 X * Process an #if, #ifdef, or #ifndef.  The latter two are straightforward,
1483 X * while #if needs a subroutine of its own to evaluate the expression.
1484 X *
1485 X * doif() is called only if compiling is TRUE.  If false, compilation
1486 X * is always supressed, so we don't need to evaluate anything.  This
1487 X * supresses unnecessary warnings.
1488 X */
1490 X       register int            c;
1491 X       register int            found;
1493 X       if ((c = skipws()) == '\n' || c == EOF_CHAR) {
1494 X           unget();
1495 X           goto badif;
1496 X       }
1497 X       if (hash == L_if) {
1498 X           unget();
1499 X           found = (eval() != 0);      /* Evaluate expr, != 0 is  TRUE */
1500 X           hash = L_ifdef;             /* #if is now like #ifdef       */
1501 X       }
1502 X       else {
1503 X           if (type[c] != LET)         /* Next non-blank isn't letter  */
1504 X               goto badif;             /* ... is an error              */
1505 X           found = (lookid(c) != NULL); /* Look for it in symbol table */
1506 X       }
1507 X       if (found == (hash == L_ifdef)) {
1508 X           compiling = TRUE;
1509 X           *ifptr |= TRUE_SEEN;
1510 X       }
1511 X       else {
1512 X           compiling = FALSE;
1513 X       }
1514 X       return;
1516 Xbadif: cerror("#if, #ifdef, or #ifndef without an argument", NULLST);
1517 X#if !OLD_PREPROCESSOR
1518 X       skipnl();                               /* Prevent an extra     */
1519 X       unget();                                /* Error message        */
1520 X#endif
1521 X       return;
1524 XFILE_LOCAL
1525 Xdoinclude()
1527 X * Process the #include control line.
1528 X * There are three variations:
1529 X *     #include "file"         search somewhere relative to the
1530 X *                             current source file, if not found,
1531 X *                             treat as #include <file>.
1532 X *     #include <file>         Search in an implementation-dependent
1533 X *                             list of places.
1534 X *     #include token          Expand the token, it must be one of
1535 X *                             "file" or <file>, process as such.
1536 X *
1537 X * Note: the November 12 draft forbids '>' in the #include <file> format.
1538 X * This restriction is unnecessary and not implemented.
1539 X */
1541 X       register int            c;
1542 X       register int            delim;
1543 X#if HOST == SYS_VMS
1544 X       char                    def_filename[NAM$C_MAXRSS + 1];
1545 X#endif
1547 X       delim = macroid(skipws());
1548 X       if (delim != '<' && delim != '"')
1549 X           goto incerr;
1550 X       if (delim == '<')
1551 X           delim = '>';
1552 X       workp = work;
1553 X       instring = TRUE;                /* Accept all characters        */
1554 X       while ((c = get()) != '\n' && c != delim && c != EOF_CHAR)
1555 X           save(c);                    /* Put it away.                 */
1556 X       skipnl(); 
1557 X       /*
1558 X        * The draft is unclear if the following should be done.
1559 X        */
1561 X       while (--workp >= work && (type[*workp] == SPA))
1562 X           ;                           /* Trim blanks from filename    */
1565 X *     if (*workp != delim)
1566 X *         goto incerr; 
1567 X */
1568 X       *(workp + 1) = EOS;                     /* Terminate filename   */
1569 X       instring = FALSE;
1570 X#if HOST == SYS_VMS
1571 X       /*
1572 X        * Assume the default .h filetype.
1573 X        */
1574 X       if (!vmsparse(work, ".H", def_filename)) {
1575 X           perror(work);               /* Oops.                        */
1576 X           goto incerr;
1577 X       }
1578 X       else if (openinclude(def_filename, (delim == '"')))
1579 X           return;
1580 X#else
1581 X       if (openinclude(work, (delim == '"')))
1582 X           return;
1583 X#endif
1584 X       /*
1585 X        * No sense continuing if #include file isn't there.
1586 X        */
1587 X       cfatal("Cannot open include file \"%s\"", work);
1589 Xincerr:        cerror("#include syntax error", NULLST);
1590 X       return;
1593 XFILE_LOCAL int
1594 Xopeninclude(filename, searchlocal)
1595 Xchar           *filename;              /* Input file name              */
1596 Xint            searchlocal;            /* TRUE if #include "file"      */
1598 X * Actually open an include file.  This routine is only called from
1599 X * doinclude() above, but was written as a separate subroutine for
1600 X * programmer convenience.  It searches the list of directories
1601 X * and actually opens the file, linking it into the list of
1602 X * active files.  Returns TRUE if the file was opened, FALSE
1603 X * if openinclude() fails.  No error message is printed.
1604 X */
1606 X       register char           **incptr;
1607 X#if HOST == SYS_VMS
1608 X#if NWORK < (NAM$C_MAXRSS + 1)
1609 X    << error, NWORK isn't greater than NAM$C_MAXRSS >>
1610 X#endif
1611 X#endif
1612 X       char                    tmpname[NWORK]; /* Filename work area   */
1614 X       if (searchlocal) {
1615 X           /*
1616 X            * Look in local directory first
1617 X            */
1618 X#if HOST == SYS_UNIX
1619 X           /*
1620 X            * Try to open filename relative to the directory of the current
1621 X            * source file (as opposed to the current directory). (ARF, SCK).
1622 X            */
1623 X           if (filename[0] != '/'
1624 X            && hasdirectory(infile->filename, tmpname))
1625 X               strcat(tmpname, filename);
1626 X           else {
1627 X               strcpy(tmpname, filename);
1628 X           }
1629 X#else
1630 X           if (!hasdirectory(filename, tmpname)
1631 X            && hasdirectory(infile->filename, tmpname))
1632 X               strcat(tmpname, filename);
1633 X           else {
1634 X               strcpy(tmpname, filename);
1635 X           }
1636 X#endif
1637 X           if (openfile(tmpname))
1638 X               return (TRUE);
1639 X       }
1640 X       /*
1641 X        * Look in any directories specified by -I command line
1642 X        * arguments, then in the builtin search list.
1643 X        */
1644 X       for (incptr = incdir; incptr < incend; incptr++) {
1645 X           if (strlen(*incptr) + strlen(filename) >= (NWORK - 1))
1646 X               cfatal("Filename work buffer overflow", NULLST);
1647 X           else {
1648 X#if HOST == SYS_UNIX
1649 X               if (filename[0] == '/')
1650 X                   strcpy(tmpname, filename);
1651 X               else {
1652 X                   sprintf(tmpname, "%s/%s", *incptr, filename);
1653 X               }
1654 X#else
1655 X               if (!hasdirectory(filename, tmpname))
1656 X                   sprintf(tmpname, "%s%s", *incptr, filename);
1657 X#endif
1658 X               if (openfile(tmpname))
1659 X                   return (TRUE);
1660 X           }
1661 X       }
1662 X       return (FALSE);
1665 XFILE_LOCAL int
1666 Xhasdirectory(source, result)
1667 Xchar           *source;        /* Directory to examine                 */
1668 Xchar           *result;        /* Put directory stuff here             */
1670 X * If a device or directory is found in the source filename string, the
1671 X * node/device/directory part of the string is copied to result and
1672 X * hasdirectory returns TRUE.  Else, nothing is copied and it returns FALSE.
1673 X */
1675 X#if HOST == SYS_UNIX
1676 X       register char           *tp;
1678 X       if ((tp = strrchr(source, '/')) == NULL)
1679 X           return (FALSE);
1680 X       else {
1681 X           strncpy(result, source, tp - source + 1);
1682 X           result[tp - source + 1] = EOS;
1683 X           return (TRUE);
1684 X       }
1685 X#else
1686 X#if HOST == SYS_VMS
1687 X       if (vmsparse(source, NULLST, result)
1688 X        && result[0] != EOS)
1689 X           return (TRUE);
1690 X       else {
1691 X           return (FALSE);
1692 X       }
1693 X#else
1694 X       /*
1695 X        * Random DEC operating system (RSX, RT11, RSTS/E)
1696 X        */
1697 X       register char           *tp;
1699 X       if ((tp = strrchr(source, ']')) == NULL
1700 X        && (tp = strrchr(source, ':')) == NULL)
1701 X           return (FALSE);
1702 X       else {
1703 X           strncpy(result, source, tp - source + 1);
1704 X           result[tp - source + 1] = EOS;
1705 X           return (TRUE);
1706 X       }
1707 X#endif
1708 X#endif
1711 X#if HOST == SYS_VMS
1714 X * EXP_DEV is set if a device was specified, EXP_DIR if a directory
1715 X * is specified.  (Both set indicate a file-logical, but EXP_DEV
1716 X * would be set by itself if you are reading, say, SYS$INPUT:)
1717 X */
1718 X#define DEVDIR (NAM$M_EXP_DEV | NAM$M_EXP_DIR)
1720 XFILE_LOCAL int
1721 Xvmsparse(source, defstring, result)
1722 Xchar           *source;
1723 Xchar           *defstring;     /* non-NULL -> default string.          */
1724 Xchar           *result;        /* Size is at least NAM$C_MAXRSS + 1    */
1726 X * Parse the source string, applying the default (properly, using
1727 X * the system parse routine), storing it in result.
1728 X * TRUE if it parsed, FALSE on error.
1729 X *
1730 X * If defstring is NULL, there are no defaults and result gets
1731 X * (just) the node::[directory] part of the string (possibly "")
1732 X */
1734 X       struct FAB      fab = cc$rms_fab;       /* File access block    */
1735 X       struct NAM      nam = cc$rms_nam;       /* File name block      */
1736 X       char            fullname[NAM$C_MAXRSS + 1];
1737 X       register char   *rp;                    /* Result pointer       */
1739 X       fab.fab$l_nam = &nam;                   /* fab -> nam           */
1740 X       fab.fab$l_fna = source;                 /* Source filename      */
1741 X       fab.fab$b_fns = strlen(source);         /* Size of source       */
1742 X       fab.fab$l_dna = defstring;              /* Default string       */
1743 X       if (defstring != NULLST)
1744 X           fab.fab$b_dns = strlen(defstring);  /* Size of default      */
1745 X       nam.nam$l_esa = fullname;               /* Expanded filename    */
1746 X       nam.nam$b_ess = NAM$C_MAXRSS;           /* Expanded name size   */
1747 X       if (sys$parse(&fab) == RMS$_NORMAL) {   /* Parse away           */
1748 X           fullname[nam.nam$b_esl] = EOS;      /* Terminate string     */
1749 X           result[0] = EOS;                    /* Just in case         */
1750 X           rp = &result[0];
1751 X           /*
1752 X            * Remove stuff added implicitly, accepting node names and
1753 X            * dev:[directory] strings (but not process-permanent files).
1754 X            */
1755 X           if ((nam.nam$l_fnb & NAM$M_PPF) == 0) {
1756 X               if ((nam.nam$l_fnb & NAM$M_NODE) != 0) {
1757 X                   strncpy(result, nam.nam$l_node, nam.nam$b_node);
1758 X                   rp += nam.nam$b_node;
1759 X                   *rp = EOS;
1760 X               }
1761 X               if ((nam.nam$l_fnb & DEVDIR) == DEVDIR) {
1762 X                   strncpy(rp, nam.nam$l_dev, nam.nam$b_dev + nam.nam$b_dir);
1763 X                   rp += nam.nam$b_dev + nam.nam$b_dir;
1764 X                   *rp = EOS;
1765 X               }
1766 X           }
1767 X           if (defstring != NULLST) {
1768 X               strncpy(rp, nam.nam$l_name, nam.nam$b_name + nam.nam$b_type);
1769 X               rp += nam.nam$b_name + nam.nam$b_type;
1770 X               *rp = EOS;
1771 X               if ((nam.nam$l_fnb & NAM$M_EXP_VER) != 0) {
1772 X                   strncpy(rp, nam.nam$l_ver, nam.nam$b_ver);
1773 X                   rp[nam.nam$b_ver] = EOS;
1774 X               }
1775 X           }
1776 X           return (TRUE);
1777 X       }
1778 X       return (FALSE);
1780 X#endif
1782 END-of-cpp2.c
1783 exit