home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sources / games / 310 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  58.4 KB

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