home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume16 / nethack31 / part02 < prev    next >
Internet Message Format  |  1993-02-01  |  60KB

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