home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 243_01 / cppdef.h < prev    next >
C/C++ Source or Header  |  1990-05-14  |  15KB  |  509 lines

  1. /*
  2. **    name:        cppdef.h
  3. **    purpose:    Define operating environment
  4. **
  5. **    Roberto Artigas Jr
  6. **    P.O. Box 281415
  7. **    Memphis, TN 38168-1415
  8. **    home: 901-762-6092
  9. **    work: 901-373-4738
  10. **
  11. **    Get to run under OS/2.
  12. **    Used C/2 version 1.10 under OS/2 E 1.1
  13. **    Used the -AL -W2 flags to compile everything
  14. **    --------------------------------------------
  15. **    I am sure that there are some individuals that will
  16. **    complain as to what I did here to resolve all warnings
  17. **    and errors encountered when I compiled with the above
  18. **    flags. However, that is why you get source. If you
  19. **    find a nicer way to do something then change the
  20. **    source, compile, debug and let the rest of the world
  21. **    know what you did.
  22. */
  23. #define    CMP    0
  24. #define    DOS    0
  25. #define    OS2    1
  26. #include    <ctype.h>
  27. #include    <stdio.h>
  28.  
  29. #if    DOS || OS2
  30. #include    <stdlib.h>
  31. #include    <string.h>
  32. #endif
  33.  
  34. /*
  35. **    Function prototypes
  36. */
  37. void    cerror();
  38. void    cfatal();
  39. void    cwarn();
  40. void    cierror();
  41. void    ciwarn();
  42. void    skipnl();
  43. void    scanid();
  44. void    scannumber();
  45. void    save();
  46. void    trigraph();
  47. void    unget();
  48. void    ungetstring();
  49. void    addfile();
  50. void    setincdirs();
  51. void    initdefines();
  52. int    skipws();
  53. int    macroid();
  54. int    catenate();
  55. int    scanstring();
  56. char    *savestring();
  57. char    *getmem();
  58. int    get();
  59. int    cget();
  60. void    expand();
  61. void    dodefine();
  62. void    checkparm();
  63. void    doundef();
  64. void    textput();
  65. void    charput();
  66. int    eval();
  67. int    evalchar();
  68. int    evalnum();
  69. int    evalone();
  70. int    evallex();
  71. int    dosizeof();
  72. int    openfile();
  73. void    stparmscan();
  74. int    isformal();
  75. int    expcollect();
  76. int    hasdirectory();
  77. int    dooptions();
  78. int    control();
  79. void    output();
  80.  
  81.  
  82.  
  83. /*
  84.  *                 S y s t e m   D e p e n d e n t
  85.  *              D e f i n i t i o n s    f o r   C P P
  86.  *
  87.  * Definitions in this file may be edited to configure CPP for particular
  88.  * host operating systems and target configurations.
  89.  *
  90.  * NOTE: cpp assumes it is compiled by a compiler that supports macros
  91.  * with arguments.  If this is not the case (as for Decus C), #define
  92.  * nomacarg -- and provide function equivalents for all macros.
  93.  *
  94.  * cpp also assumes the host and target implement the Ascii character set.
  95.  * If this is not the case, you will have to do some editing here and there.
  96.  */
  97.  
  98. /*
  99.  * This redundant definition of TRUE and FALSE works around
  100.  * a limitation of Decus C.
  101.  */
  102. #ifndef TRUE
  103. #define TRUE                    1
  104. #define FALSE                   0
  105. #endif
  106.  
  107. /*
  108.  * Define the HOST operating system.  This is needed so that
  109.  * cpp can use appropriate filename conventions.
  110.  */
  111. #define SYS_UNKNOWN             0
  112. #define SYS_UNIX                1
  113. #define SYS_VMS                 2
  114. #define SYS_RSX                 3
  115. #define SYS_RT11                4
  116. #define SYS_LATTICE             5
  117. #define SYS_ONYX                6
  118. #define SYS_68000               7
  119. #define    SYS_MSDOS        8
  120.  
  121. #ifndef HOST
  122. #ifdef  unix
  123. #define HOST                    SYS_UNIX
  124. #else
  125. #ifdef  vms
  126. #define HOST                    SYS_VMS
  127. #else
  128. #ifdef  rsx
  129. #define HOST                    SYS_RSX
  130. #else
  131. #ifdef  rt11
  132. #define HOST                    SYS_RT11
  133. #else
  134. #ifdef    MSDOS
  135. #define    HOST            SYS_MSDOS
  136. #endif
  137. #endif
  138. #endif
  139. #endif
  140. #endif
  141. #endif
  142.  
  143. #ifndef HOST
  144. #define HOST                    SYS_UNKNOWN
  145. #endif
  146.  
  147. /*
  148.  * We assume that the target is the same as the host system
  149.  */
  150. #ifndef TARGET
  151. #define TARGET                  HOST
  152. #endif
  153.  
  154. /*
  155.  * In order to predefine machine-dependent constants,
  156.  * several strings are defined here:
  157.  *
  158.  * MACHINE      defines the target cpu (by name)
  159.  * SYSTEM       defines the target operating system
  160.  * COMPILER     defines the target compiler
  161.  *
  162.  *      The above may be #defined as "" if they are not wanted.
  163.  *      They should not be #defined as NULL.
  164.  *
  165.  * LINE_PREFIX  defines the # output line prefix, if not "line"
  166.  *              This should be defined as "" if cpp is to replace
  167.  *              the "standard" C pre-processor.
  168.  *
  169.  * FILE_LOCAL   marks functions which are referenced only in the
  170.  *              file they reside.  Some C compilers allow these
  171.  *              to be marked "static" even though they are referenced
  172.  *              by "extern" statements elsewhere.
  173.  *
  174.  * OK_DOLLAR    Should be set TRUE if $ is a valid alphabetic character
  175.  *              in identifiers (default), or zero if $ is invalid.
  176.  *              Default is TRUE.
  177.  *
  178.  * OK_CONCAT    Should be set as follows:
  179.  *              CON_FALSE       ## has no significance to cpp (needed for
  180.  *                              systems that have to preprocess asm source).
  181.  *              CON_NOEXPAND    ## concatenates tokens per the Draft Standard.
  182.  *                              The concatenated token is not macro-expanded.
  183.  *              CON_EXPAND      ## concatenates tokens per the Draft Standard.
  184.  *                              The concatenated token is macro-expanded.
  185.  *
  186.  * OK_DATE      Predefines the compilation date if set TRUE.
  187.  *              Not permitted by the Nov. 12, 1984 Draft Standard.
  188.  *
  189.  * OK_IF_JUNK   Should be set TRUE to allow text after #else and
  190.  *              #endif.  This is needed for compatiblity with old
  191.  *              preprocessors, but is forbidden by the Draft Standard.
  192.  *
  193.  * OK_TRIGRAPH  Enable trigraph substitution, whereby ??= -> # etc.
  194.  * TFLAG_INIT   Initial value for the -t option.  If TRUE, -t
  195.  *              disables trigraphs, if FALSE, -t enables them.
  196.  *
  197.  * OLD_PREPROCESSOR Forces several parameters to a state consistant
  198.  *              with the Reiser cpp preprocessor.
  199.  * S_CHAR etc.  Define the sizeof the basic TARGET machine word types.
  200.  *              By default, sizes are set to the values for the HOST
  201.  *              computer.  If this is inappropriate, see the code in
  202.  *              cpp3.c for details on what to change.  Also, if you
  203.  *              have a machine where sizeof (signed int) differs from
  204.  *              sizeof (unsigned int), you will have to edit code and
  205.  *              tables in cpp3.c (and extend the -S option definition.)
  206.  *
  207.  * CPP_LIBRARY  May be defined if you have a site-specific include directory
  208.  *              which is to be searched *before* the operating-system
  209.  *              specific directories.
  210.  */
  211.  
  212. #if TARGET == SYS_MSDOS
  213. /*
  214.  *     Here we assume that the operating system is MS-DOS and the
  215.  * target processor is an Intel 8086.   I8086 and MSDOS are defined
  216.  * as they would be with the Lattice or Microsoft (3.x) preprocessor.
  217.  *
  218.  *     The memory-model-specific defines are all predefined here and
  219.  * must be undefined later when the memory model is actually chosen,
  220.  * for example when the '-M' option is processed...
  221.  */
  222.  
  223. #define    MACHINE            "I8086", "LPTR", "SPTR", "I8086S",    \
  224.                 "I8086P", "I8086D", "I8086L",        \
  225.                 "M_I86", "M_I86SM", "M_I86MM", "M_I86LM"
  226.  
  227. #define    SYSTEM            "MSDOS"
  228.  
  229. #endif
  230.  
  231. #if TARGET == SYS_LATTICE
  232. /*
  233.  * We assume the operating system is pcdos for the IBM-PC.
  234.  * We also assume the small model (just like the PDP-11)
  235.  */
  236. #define MACHINE                 "i8086"
  237. #define SYSTEM                  "pcdos"
  238. #endif
  239.  
  240. #if TARGET == SYS_ONYX
  241. #define MACHINE                 "z8000"
  242. #define SYSTEM                  "unix"
  243. #endif
  244.  
  245. #if TARGET == SYS_VMS
  246. #define MACHINE                 "vax"
  247. #define SYSTEM                  "vms"
  248. #define COMPILER                "vax11c"
  249. #endif
  250.  
  251. #if TARGET == SYS_RSX
  252. #define MACHINE                 "pdp11"
  253. #define SYSTEM                  "rsx"
  254. #define COMPILER                "decus"
  255. #endif
  256.  
  257. #if TARGET == SYS_RT11
  258. #define MACHINE                 "pdp11"
  259. #define SYSTEM                  "rt11"
  260. #define COMPILER                "decus"
  261. #endif
  262.  
  263. #if TARGET == SYS_68000
  264. /*
  265.  * All these machine designators have been seen in various systems.
  266.  * Warning -- compilers differ as to sizeof (int).  cpp3 assumes that
  267.  * sizeof (int) == 2
  268.  */
  269. #define MACHINE                 "M68000", "m68000", "m68k", "mc68000"
  270. #define SYSTEM                  "unix"
  271. #endif
  272.  
  273. #if     TARGET == SYS_UNIX
  274. #define SYSTEM                  "unix"
  275. #ifdef  pdp11
  276. #define MACHINE                 "pdp11"
  277. #endif
  278. #ifdef  vax
  279. #define MACHINE                 "vax"
  280. #endif
  281. #endif
  282.  
  283. /*
  284.  * defaults
  285.  */
  286.  
  287. #ifndef MSG_PREFIX
  288. #define MSG_PREFIX              "cpp: "
  289. #endif
  290.  
  291. #ifndef LINE_PREFIX
  292. #ifdef  decus
  293. #define LINE_PREFIX             ""
  294. #else
  295. #define LINE_PREFIX             "line"
  296. #endif
  297. #endif
  298.  
  299.  
  300. /*
  301.  * OLD_PREPROCESSOR forces the definition of several compilation
  302.  * options to values compatible with the Reiser preprocessor.
  303.  */
  304.  
  305. #ifndef OLD_PREPROCESSOR
  306. #define OLD_PREPROCESSOR        FALSE
  307. #endif
  308.  
  309. #if     OLD_PREPROCESSOR
  310. #define OK_DOLLAR               FALSE
  311. #define OK_CONCAT               CON_FALSE
  312. #define OK_IF_JUNK              TRUE
  313. #define COMMENT_INVISIBLE       TRUE
  314. #define STRING_FORMAL           TRUE
  315. #define OK_TRIGRAPH             FALSE
  316. #endif
  317.  
  318. /*
  319.  * RECURSION_LIMIT may be set to -1 to disable the macro recursion test.
  320.  */
  321. #ifndef RECURSION_LIMIT
  322. #define RECURSION_LIMIT 1000
  323. #endif
  324.  
  325. /*
  326.  * BITS_CHAR may be defined to set the number of bits per character.
  327.  * it is needed only for multi-byte character constants.
  328.  */
  329. #ifndef BITS_CHAR
  330. #define BITS_CHAR               8
  331. #endif
  332.  
  333. /*
  334.  * BIG_ENDIAN is set TRUE on machines (such as the IBM 360 series)
  335.  * where 'ab' stores 'a' in the high-bits and 'b' in the low-bits.
  336.  * It is set FALSE on machines (such as the PDP-11 and Vax-11)
  337.  * where 'ab' stores 'a' in the low-bits and 'b' in the high-bits.
  338.  * (Or is it the other way around?) -- Warning: BIG_ENDIAN code is untested.
  339.  */
  340. #ifndef BIG_ENDIAN
  341. #define BIG_ENDIAN              FALSE
  342. #endif
  343.  
  344. /*
  345.  * COMMENT_INVISIBLE may be defined to allow "old-style" comment
  346.  * processing, whereby the comment becomes a zero-length token
  347.  * delimiter.  This permitted tokens to be concatenated in macro
  348.  * expansions.  This was removed from the Draft Ansi Standard.
  349.  */
  350. #ifndef COMMENT_INVISIBLE
  351. #define COMMENT_INVISIBLE       FALSE
  352. #endif
  353.  
  354. /*
  355.  * STRING_FORMAL may be defined to allow recognition of macro parameters
  356.  * anywhere in replacement strings.  This was removed from the Draft Ansi
  357.  * Standard and a limited recognition capability added.
  358.  *
  359.  * Note: some preliminary code has been commented out by
  360.  * statements of the form #if 0 && STRING_FORMAL.  This
  361.  * is for maintenence reasons only: see comments in cpp4.c
  362.  */
  363. #ifndef STRING_FORMAL
  364. #define STRING_FORMAL           FALSE
  365. #endif
  366.  
  367. /*
  368.  * OK_DOLLAR enables use of $ as a valid "letter" in identifiers.
  369.  * This is a permitted extension to the Ansi Standard and is required
  370.  * for e.g., VMS, RSX-11M, etc.   It should be set FALSE if cpp is
  371.  * used to preprocess assembler source on Unix systems.  OLD_PREPROCESSOR
  372.  * sets OK_DOLLAR FALSE for that reason.
  373.  */
  374. #ifndef OK_DOLLAR
  375. #define OK_DOLLAR               TRUE
  376. #endif
  377.  
  378. /*
  379.  * OK_CONCAT enables (one possible implementation of) token concatenation.
  380.  * If cpp is used to preprocess Unix assembler source, this should be
  381.  * set 0 as the concatenation character, #, is used by the assembler.
  382.  */
  383. #define CON_FALSE               0
  384. #define CON_NOEXPAND            1
  385. #define CON_EXPAND              2
  386. #ifndef OK_CONCAT
  387. #define OK_CONCAT               CON_NOEXPAND
  388. #endif
  389.  
  390. /*
  391.  * OK_IF_JUNK permits commentary after #else and #endif statements.
  392.  */
  393. #ifndef OK_IF_JUNK
  394. #define OK_IF_JUNK      TRUE
  395. #endif
  396.  
  397. /*
  398.  * OK_DATE may be enabled to predefine today's date as a string
  399.  * at the start of each compilation.  This is apparently not permitted
  400.  * by the Draft Ansi Standard.
  401.  */
  402. #ifndef OK_DATE
  403. #define OK_DATE         TRUE
  404. #endif
  405.  
  406. /*
  407.  * OK_TRIGRAPH permits replacement of ??<something> on input text
  408.  * as per the Draft Standard.  TFLAG_INIT is the initial state
  409.  * of the trigraph substitution compiler option.
  410.  */
  411. #ifndef OK_TRIGRAPH
  412. #define OK_TRIGRAPH     TRUE
  413. #endif
  414. #ifndef TFLAG_INIT
  415. #define TFLAG_INIT      TRUE
  416. #endif
  417.  
  418.  
  419.  
  420. /*
  421.  * Some common definitions.
  422.  */
  423.  
  424. #ifndef DEBUG
  425. #define DEBUG                   TRUE                    /* Temp */
  426. #endif
  427. /*#define    DEBUG_EVAL */
  428.  
  429. #if    DEBUG
  430. void    dumpunget();
  431. void    dumpadef();
  432. void    dumpdef();
  433. void    dumpstring();
  434. void    dumpparm();
  435. #endif
  436.  
  437.  
  438. /*
  439.  * The following definitions are used to allocate memory for
  440.  * work buffers.  In general, they should not be modified
  441.  * by implementors.
  442.  *
  443.  * NMACPARS     The maximum number of #define parameters (31 per Standard)
  444.  *              NOTE: (NMACPARS * 2) must be <= 255.
  445.  * IDMAX        The longest identifier, 31 per Ansi Standard
  446.  * NBUFF        Input buffer size
  447.  * NWORK        Work buffer size -- the longest macro
  448.  *              must fit here after expansion.
  449.  * NEXP         The nesting depth of #if expressions
  450.  * NINCLUDE     The number of directories that may be specified
  451.  *              on a per-system basis, or by the -I option.
  452.  * BLK_NEST     The number of nested #if's permitted.
  453.  */
  454.  
  455. #define IDMAX                    31
  456. #define NMACPARS                 31
  457. #define NBUFF                   512
  458. #define NWORK                   512
  459. #define NEXP                    128
  460. #define NINCLUDE                 27
  461. #define NPARMWORK               (NWORK * 2)
  462. #define BLK_NEST                32
  463.  
  464. /*
  465.  * Some special constants.  These may need to be changed if cpp
  466.  * is ported to a wierd machine.
  467.  *
  468.  * NOTE: if cpp is run on a non-ascii machine, ALERT and VT may
  469.  * need to be changed.  They are used to implement the proposed
  470.  * ANSI standard C control characters '\a' and '\v' only.
  471.  * DEL is used to tag macro tokens to prevent #define foo foo
  472.  * from looping.  Note that we don't try to prevent more elaborate
  473.  * #define loops from occurring.
  474.  */
  475.  
  476. #ifndef ALERT
  477. #define ALERT                   '\007'          /* '\a' is "Bell"       */
  478. #endif
  479.  
  480. #ifndef VT
  481. #define VT                      '\013'          /* Vertical Tab CTRL/K  */
  482. #endif
  483.  
  484.  
  485. #ifndef FILE_LOCAL
  486. #ifdef  decus
  487. #define FILE_LOCAL              static
  488. #else
  489. #ifdef  vax11c
  490. #define FILE_LOCAL              static
  491. #else
  492. #define FILE_LOCAL                              /* Others are global    */
  493. #endif
  494. #endif
  495. #endif
  496.  
  497.  
  498. /* ms_dos_model
  499. **
  500. **        Used to indicate to the main() routine what memory model
  501. **     has been chosen.   Main uses this information to determine what
  502. **    predefined strings should be deleted.
  503. */
  504.  
  505. #if    HOST == SYS_MSDOS
  506. extern char ms_dos_model;
  507. #endif
  508.  
  509.