home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / c / cpp.lha / cpp.h < prev    next >
C/C++ Source or Header  |  1991-08-05  |  13KB  |  334 lines

  1. /*
  2.  
  3.  
  4.  Copyright (C) 1990 Texas Instruments Incorporated.
  5.  
  6.  Permission is granted to any individual or institution to use, copy, modify,
  7.  and distribute this software, provided that this complete copyright and
  8.  permission notice is maintained, intact, in all copies and supporting
  9.  documentation.
  10.  
  11.  Texas Instruments Incorporated provides this software "as is" without
  12.  express or implied warranty.
  13.  
  14.  
  15.  *      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
  16.  *
  17.  * In general, definitions in this file should not be changed.
  18.  *
  19.  * Change History:
  20.  * 19-Jan-90  DKM   Added support for MVS and EBCDIC character set
  21.  * 25-Jun-91  GPD   Added support for Pyramid.
  22.  *
  23.  * 29-Jul-91  PB    Added support for AmigaOS (SAS/C)
  24.  */
  25.  
  26. #include "cppdef.h"
  27.  
  28. #ifndef toupper
  29. #define toupper(c) ((c) + ('A' - 'a'))
  30. #endif /* no toupper */
  31. #ifndef tolower
  32. #define tolower(c) ((c) + ('a' - 'A'))
  33. #endif /* no tolower */
  34.  
  35. #ifndef TRUE
  36. #define TRUE            1
  37. #define FALSE           0
  38. #endif
  39. #ifndef EOS
  40. /*
  41.  * This is predefined in Decus C
  42.  */
  43. #define EOS             '\0'            /* End of string                */
  44. #endif
  45. #define EOF_CHAR        0               /* Returned by get() on eof     */
  46. #define NULLST          ((char *) NULL) /* Pointer to nowhere (linted)  */
  47. #define DEF_NOARGS      (-1)            /* #define foo vs #define foo() */
  48. #define DEF_BUILTIN     (-2)            /* Builtin defines              */
  49.  
  50. /*
  51.  * Non_display characters used for special markers.
  52.  *   The location of these is different in EBCDIC because the location
  53.  *   of the MAC_PARM table had be moved to start at char 1C.
  54.  */
  55. #if CHARSET == EBCDIC
  56. #define DEF_MAGIC       0x19            /* Magic for #defines           */
  57. #define TOK_SEP         0x1A            /* Token concatenation delim.   */
  58. #define COM_SEP         0x1B            /* Magic comment separator      */
  59. #else
  60. #define DEF_MAGIC       0x1D            /* Magic for #defines           */
  61. #define TOK_SEP         0x1E            /* Token concatenation delim.   */
  62. #define COM_SEP         0x1F            /* Magic comment separator      */
  63. #endif
  64.  
  65. /*
  66.  * Note -- in Ascii, the following will map macro formals onto DEL + the
  67.  * C1 control character region (decimal 128 .. (128 + PAR_MAC)) which will
  68.  * be ok as long as PAR_MAC is less than 33).  Note that the last PAR_MAC
  69.  * value is reserved for string substitution.
  70.  *
  71.  * For EBCDIC, map macro formals x1C (decimal 28 + PAR_MAC) which
  72.  * also is OK as long as PAR_MAC is less than 33.  Note that this does
  73.  * overlap the code for BEL (decimal 47).  That means that you cannot
  74.  * use the  BEL char, ie '\a' in a #define macro.
  75.  */
  76. #if CHARSET == EBCDIC
  77. # define MAC_PARM        0x1C      /* Start at EBCDIC char x1C  */
  78. #else
  79. # define MAC_PARM        0x7F      /* Macro formals start here  */
  80. #endif
  81.  
  82. #if PAR_MAC >= 33
  83.         assertion fails -- PAR_MAC isn't less than 33
  84. #endif
  85. #define LASTPARM        (PAR_MAC - 1)
  86.  
  87. /*
  88.  * Character type codes.
  89.  */
  90.  
  91. #define INV             0               /* Invalid, must be zero        */
  92. #define OP_EOE          INV             /* End of expression            */
  93. #define DIG             1               /* Digit                        */
  94. #define LET             2               /* Identifier start             */
  95. #define FIRST_BINOP     OP_ADD
  96. #define OP_ADD          3
  97. #define OP_SUB          4
  98. #define OP_MUL          5
  99. #define OP_DIV          6
  100. #define OP_MOD          7
  101. #define OP_ASL          8
  102. #define OP_ASR          9
  103. #define OP_AND          10              /* &, not &&                    */
  104. #define OP_OR           11              /* |, not ||                    */
  105. #define OP_XOR          12
  106. #define OP_EQ           13
  107. #define OP_NE           14
  108. #define OP_LT           15
  109. #define OP_LE           16
  110. #define OP_GE           17
  111. #define OP_GT           18
  112. #define OP_ANA          19              /* &&                           */
  113. #define OP_ORO          20              /* ||                           */
  114. #define OP_QUE          21              /* ?                            */
  115. #define OP_COL          22              /* :                            */
  116. #define OP_CMA          23              /* , (relevant?)                */
  117. #define LAST_BINOP      OP_CMA          /* Last binary operand          */
  118. /*
  119.  * The following are unary.
  120.  */
  121. #define FIRST_UNOP      OP_PLU          /* First Unary operand          */
  122. #define OP_PLU          24              /* + (draft ANSI standard)      */
  123. #define OP_NEG          25              /* -                            */
  124. #define OP_COM          26              /* ~                            */
  125. #define OP_NOT          27              /* !                            */
  126. #define LAST_UNOP       OP_NOT
  127. #define OP_LPA          28              /* (                            */
  128. #define OP_RPA          29              /* )                            */
  129. #define OP_END          30              /* End of expression marker     */
  130. #define OP_MAX          (OP_END + 1)    /* Number of operators          */
  131. #define OP_FAIL         (OP_END + 1)    /* For error returns            */
  132.  
  133. /*
  134.  * The following are for lexical scanning only.
  135.  */
  136.  
  137. #define QUO             65              /* Both flavors of quotation    */
  138. #define DOT             66              /* . might start a number       */
  139. #define SPA             67              /* Space and tab                */
  140. #define BSH             68              /* Just a backslash             */
  141. #define END             69              /* EOF                          */
  142.  
  143. /*
  144.  * These bits are set in ifstack[]
  145.  */
  146. #define WAS_COMPILING   1               /* TRUE if compile set at entry */
  147. #define ELSE_SEEN       2               /* TRUE when #else processed    */
  148. #define TRUE_SEEN       4               /* TRUE when #if TRUE processed */
  149.  
  150. /*
  151.  * Define bits for the basic types and their adjectives
  152.  */
  153.  
  154. #define T_CHAR            1
  155. #define T_INT             2
  156. #define T_FLOAT           4
  157. #define T_DOUBLE          8
  158. #define T_SHORT          16
  159. #define T_LONG           32
  160. #define T_SIGNED         64
  161. #define T_UNSIGNED      128
  162. #define T_PTR           256             /* Pointer                      */
  163. #define T_FPTR          512             /* Pointer to functions         */
  164.  
  165. /*
  166.  * The DEFBUF structure stores information about #defined
  167.  * macros.  Note that the defbuf->repl information is always
  168.  * in malloc storage.
  169.  */
  170.  
  171. typedef struct defbuf {
  172.         struct defbuf   *link;          /* Next define in chain */
  173.         void (*expander)();             /* pointer to expander function */
  174.         char            *repl;          /* -> replacement       */
  175.         int             hash;           /* Symbol table hash    */
  176.         int             nargs;          /* For define(args)     */
  177.         char            name[1];        /* #define name         */
  178. } DEFBUF;
  179.  
  180. /*
  181.  * The FILEINFO structure stores information about open files
  182.  * and macros being expanded.
  183.  */
  184. /* WARNING: This structure is duplicated in defmacio.h */
  185. typedef struct fileinfo {
  186.         char            *bptr;          /* Buffer pointer       */
  187.         int             line;           /* for include or macro */
  188.         FILE            *fp;            /* File if non-null     */
  189.         struct fileinfo *parent;        /* Link to includer     */
  190.         char            *filename;      /* File/macro name      */
  191.         char            *progname;      /* From #line statement */
  192.         unsigned int    unrecur;        /* For macro recursion  */
  193.         char*           buffer;         /* current input line   */
  194. } FILEINFO;
  195.  
  196. /*
  197.  * The SIZES structure is used to store the values for #if sizeof
  198.  */
  199.  
  200. typedef struct sizes {
  201.     short       bits;                   /* If this bit is set,          */
  202.     short       size;                   /* this is the datum size value */
  203.     short       psize;                  /* this is the pointer size     */
  204. } SIZES;
  205. /*
  206.  * nomacarg is a built-in #define on Decus C.
  207.  */
  208.  
  209. #ifdef  nomacarg
  210. #define cput            output          /* cput concatenates tokens     */
  211. #else
  212. #if COMMENT_INVISIBLE
  213. #define cput(c)         { if (c != TOK_SEP && c != COM_SEP) putchar(c); }
  214. #else
  215. #define cput(c)         { if (c != TOK_SEP) putchar(c); }
  216. #endif
  217. #endif
  218.  
  219. #ifndef nomacarg
  220. #define streq(s1, s2)   (strcmp(s1, s2) == 0)
  221. #endif
  222.  
  223. /*
  224.  * Error codes.  VMS uses system definitions.
  225.  * Decus C codes are defined in stdio.h.
  226.  * Others are cooked to order.
  227.  */
  228.  
  229. #ifdef vms
  230. #include                <ssdef.h>
  231. #include                <stsdef.h>
  232. #define IO_NORMAL       (SS$_NORMAL | STS$M_INHIB_MSG)
  233. #define IO_ERROR        SS$_ABORT
  234. #endif
  235.  
  236. /*
  237.  * File access calls for OS2.
  238.  */
  239.  
  240. #if (HOST == SYS_OS2 || HOST == SYS_XENIX || HOST == SYS_VMS || HOST == SYS_AMIGA)
  241. #define F_OK            0       /* does file exist */
  242. #define X_OK            1       /* is it executable by caller */
  243. #define W_OK            2       /* writable by caller */
  244. #define R_OK            4       /* readable by caller */
  245. #endif
  246.  
  247. /* MVS headers already define F_OK, W_OK, and R_OK.
  248.  * X_OK is not supported on MVS -- but we define it here
  249.  * to be the same as R_OK for cpp7.
  250.  */
  251. #if HOST == SYS_MVS
  252. #ifndef X_OK
  253. #define X_OK            R_OK    /* X_OK same as R_OK on MVS */
  254. #endif
  255. #endif
  256.  
  257. /*
  258.  * Note: IO_NORMAL and IO_ERROR are defined in the Decus C stdio.h file
  259.  */
  260. #ifndef IO_NORMAL
  261. #define IO_NORMAL       0
  262. #endif
  263. #ifndef IO_ERROR
  264. #define IO_ERROR        1
  265. #endif
  266.  
  267. /*
  268.  * Externs
  269.  */
  270.  
  271. extern int      line;                   /* Current line number          */
  272. extern int      wrongline;              /* Force #line to cc pass 1     */
  273. extern int      wrongfile;              /* Force #line to cc pass 1     */
  274. extern char     type[];                 /* Character classifier         */
  275. extern char     *tokenbuf;              /* Current input token          */
  276. extern int      tokenbsize;             /* Current size allocated in tokenbuf
  277.                                            (not counting 1 byte for zero) */
  278. extern int      instring;               /* TRUE if scanning string      */
  279. extern int      inmacro;                /* TRUE if scanning #define     */
  280. extern int      errors;                 /* Error counter                */
  281. extern DEFBUF   *macro;                 /* Catches start of infinite macro */
  282. extern int      recursion;              /* Macro depth counter          */
  283. extern char     ifstack[BLK_NEST];      /* #if information              */
  284. #define compiling ifstack[0]
  285. extern char     *ifptr;                 /* -> current ifstack item      */
  286. extern char     *incdir[NINCLUDE];      /* -i directories               */
  287. extern char     **incend;               /* -> active end of incdir      */
  288. extern int      cflag;                  /* -C option (keep comments)    */
  289. extern int      eflag;                  /* -E option (ignore errors)    */
  290. extern int      nflag;                  /* -N option (no pre-defines)   */
  291. extern int      yflag;                  /* -Y option (alt stdincl)      */
  292. extern int      rec_recover;            /* unwind recursive macros      */
  293. extern char     *preset[];              /* Standard predefined symbols  */
  294. extern char     *magic[];               /* Magic predefined symbols     */
  295. extern FILEINFO *infile;                /* Current input file           */
  296. extern char     *altincl;               /* Alternate std include dir    */
  297. extern char     work[NWORK + 1];        /* #define scratch              */
  298. extern char     *workp;                 /* Free space in work           */
  299. extern int      debug;                  /* Debug level                  */
  300. extern int      keepcomments;           /* Don't remove comments if set */
  301. extern SIZES    size_table[];           /* For #if sizeof sizes         */
  302. extern char     *getmem();              /* Get memory or die.           */
  303. extern char     *incmem();              /* Increase size of block or die.  */
  304. extern DEFBUF   *lookid();              /* Look for a #define'd thing   */
  305. extern DEFBUF   *defendel();            /* Symbol table enter/delete    */
  306. extern char     *savestring();          /* Stuff string in malloc mem.  */
  307. extern char     *strcpy();
  308. extern char     *strcat();
  309. #if pyr
  310. #define strchr index
  311. #define strrchr rindex
  312. #endif
  313. extern char     *strrchr();
  314. extern char     *strchr();
  315.  
  316. #if HOST != SYS_MVS
  317. extern long     time();
  318. #endif
  319.  
  320. #if (HOST != SYS_OS2 && HOST != SYS_XENIX && HOST != SYS_MVS && HOST != SYS_AIX && HOST != SYS_AMIGA)
  321. #if defined(sun) || (!defined(i386) && !defined(unix))
  322. extern char     *sprintf();             /* Lint needs this              */
  323. #endif
  324. #endif
  325.  
  326. typedef int (*internal_expander) ();
  327.  
  328. struct expander_pair {
  329.   char* name;
  330.   internal_expander function;
  331. };
  332.  
  333. extern struct expander_pair internal_macros[]; /* defines internal macro expanders */
  334.