home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / TOP / USR / SRC / scpp.t.Z / scpp.t / scpp.h < prev    next >
Text File  |  2009-11-06  |  11KB  |  373 lines

  1.  
  2. /*
  3.  * scpp.h - common declarations for the selective C preprocessor, scpp.
  4.  *
  5.  * Copyright (c) 1985 by
  6.  * Tektronix, Incorporated Beaverton, Oregon 97077
  7.  * All rights reserved.
  8.  *
  9.  * Permission is hereby granted for personal, non-commercial
  10.  * reproduction and use of this program, provided that this
  11.  * notice and all copyright notices are included in any copy.
  12.  */
  13.  
  14. typedef    int    void;
  15.  
  16. # define TRUE    1
  17. # define FALSE    0
  18. /* #define rindex strrchr */
  19. /*
  20.  * sawerror - "some error was processed" If true, scpp exits non-zero.
  21.  * Set by the error printout routines, examined when exiting.
  22.  */
  23. #ifdef VARS
  24. int sawerror;
  25. #else
  26. extern int sawerror;
  27. #endif
  28.  
  29. # define BSIZE    512    /*
  30.              * # of bytes per read -- controls how quickly
  31.              * istk[] is consumed.
  32.              */
  33.  
  34. /*
  35.  * PENDSIZ is a tunable parameter -- it is the largest number of characters
  36.  *  which can be waiting to be output.  This number sets a limit on:
  37.  *  1) the longest comment;
  38.  *  2) the largest invocation of a macro with parameters, i.e. the number
  39.  *    of characters between the '(' and the ')'.
  40.  *  3) the longest preprocessor control line, e.g. #define....
  41.  * PENDSIZ also controls the input stack size, ISTK.
  42.  *
  43.  * Pend[] is the pending output buffer.
  44.  *
  45.  * Nxtout points to where within pend[] to put the next token scanned.
  46.  * Nxtout is advanced by questr() and quec(),
  47.  *  the primitives for putting stuff in pend[],
  48.  * and is moved backward by dispose() and outpend(),
  49.  *  the primitives for getting stuff out of pend[].
  50.  *
  51.  * Curtext points to the start of the text within pend[] of
  52.  * the current token.  Set by gtok() and gintok().
  53.  * For anyone who uses gtok() or gintok() to get
  54.  *  a token, the limits of the text of the resultant
  55.  *  token are curtext and nxtout. (be aware that the
  56.  *  text of anything in pend[] may contain imbedded
  57.  *  ATTN bytes.)
  58.  */
  59.  
  60. # define PENDSIZ 8000
  61. # define PENDHIGH 512    /* highwater mark for flushing pend[]    */
  62. #ifdef VARS
  63. char pend[PENDSIZ];
  64. char *nxtout;
  65. char *curtext;
  66. #else
  67. extern char pend[];
  68. extern char *nxtout;
  69. extern char *curtext;
  70. #endif
  71. extern char *dispose();
  72. #define outpend() (nxtout < &pend[PENDHIGH] ? 0 : writepend())
  73.  
  74. /*
  75.  * filestk - the stack containing the state of the current file
  76.  */
  77.  
  78. struct afile {
  79.     int    af_fd;        /* the open file's file-descriptor    */
  80.     char    *af_name;    /* the name of the file (dynamic alloc)    */
  81.     int    af_line;    /* the current line in the file        */
  82.     int    af_raw;        /*
  83.                  * "scanning unprocessed data rather than
  84.                  *  pushed-back data".
  85.                  * Used to count input lines.
  86.                  * Also used to prevent
  87.                  *  interpretation of "#if" expressions whose
  88.                  *  truth or falsehood does not depend on
  89.                  *  interpreting macros (e.g. #if '\377' > 0). 
  90.                  */
  91.     int    af_hide;    /*
  92.                  * "do not output anything for this file."
  93.                  * This file is the result of an uninterpreted
  94.                  * "# include".
  95.                  */
  96. };
  97.  
  98. #define FILESIZ 11    /* max # of include files + 1 (the original file) */
  99. #ifdef VARS
  100. struct afile filestk[FILESIZ];
  101. struct afile *curfile;    /* the current file.  Initially = &filestk[-1]    */
  102. #else
  103. extern struct afile filestk[];
  104. extern struct afile *curfile;
  105. #endif
  106.  
  107. /*
  108.  * ISTKSIZ is the size of the input/pushback stack.
  109.  *  It contains up to one block of data for each pending file plus
  110.  *  one pending token.
  111.  * The input stack grows down from istk[ISTKSIZ - 1].
  112.  *
  113.  * Nxtin points to the next char to read from istk[].
  114.  * Characters are popped from the stack by nxtc()
  115.  * and are pushed back on the stack by unc() and
  116.  * pushmac().
  117.  */
  118.  
  119. # define ISTKSIZ (FILESIZ * BSIZE + PENDSIZ)
  120. #ifdef VARS
  121. char istk[ISTKSIZ];
  122. char *nxtin;
  123. #else
  124. extern char istk[];
  125. extern char *nxtin;
  126. #endif
  127. extern char nxtc();
  128. extern char *pushmac();
  129. #define unc(c) (nxtin-- < &istk[0] ? over() : (*nxtin = c))
  130.  
  131. /*
  132.  * ATTN appears in the input stack to notify nxtc() of some condition,
  133.  *  in the output queue to notify dispose() or outpend() of some condition,
  134.  *  or in the value of a macro to notify gintok() of some condition.
  135.  * ATTN means that the next byte contains a control code.
  136.  * Input control codes are:
  137.  *  AT_EPUSH    - end of pushed-back data.  what follows has not been
  138.  *         scanned before.
  139.  *  AT_EBLK    - end of block.  read another block from the current file.
  140.  * Output control codes are:
  141.  *  AT_OUTOFF    - disable further output.
  142.  *  AT_OUTON    - enable output.
  143.  * Macro value control codes are formal parameter numbers and are not defined.
  144.  *
  145.  * note: to avoid breaking string operations and newline recognition,
  146.  *  do not add an ATTN control code which has a value of '\0', '\\', or '\n'.
  147.  */
  148.  
  149. #define ATTN        '\376'    /* this char must not appear in any file */
  150. #define AT_EPUSH    '\001'
  151. #define AT_EBLK        '\002'
  152.  
  153. #define AT_OUTOFF    '\006'
  154. #define AT_OUTON    '\007'
  155.  
  156. /*
  157.  * Ninterp - number of interpretations.  Incremented each time
  158.  *  gintok() interprets a macro.  Since there is no
  159.  *  overflow detection, ninterp can be used only to
  160.  *  see if some interpretation took place -- not to
  161.  *  count the interpretations (e.g. "oldnint != ninterp"
  162.  *  works, but "cnt = ninterp - oldnint" may fail).
  163.  * Used in conjunction with af_raw to prevent
  164.  *  interpretation of  #if's which are always true
  165.  *  or false without any macro interpretation (e.g.
  166.  *  "#if '\377' > 0").
  167.  */
  168.  
  169. #ifdef VARS
  170. int ninterp;
  171. #else
  172. extern int ninterp;
  173. #endif
  174.  
  175. /*
  176.  * Falsecnt - number of currently false #if's;
  177.  * Hidecnt  - current number of uninterpreted #include's.
  178.  * Collectively, these variables are used to determine when
  179.  *  to enable or disable output.
  180.  */
  181.  
  182. #ifdef VARS
  183. int falsecnt;
  184. int hidecnt;
  185. #else
  186. extern int falsecnt;
  187. extern int hidecnt;
  188. #endif
  189.  
  190. /*
  191.  * ifstk[] contains flags describing the state of all currently active #if's.
  192.  * curif points to the currently active #if within the stack.
  193.  * The stack grows upward, starting at ifstk[-1].
  194.  */
  195.  
  196. #define IF_INIF        '\001'    /* "in the 'if' clause rather than 'else'" */
  197. #define IF_TRUE        '\002'    /* "this if is currently true"           */
  198. #define IF_FALSE    '\004'    /* "this if is currently false"           */
  199.     /* uninterpreted #if statements are neither true nor false.       */
  200. #define IFSIZ    100        /* maximum number of nested #if's       */
  201. #ifdef VARS
  202. char ifstk[IFSIZ];
  203. char *curif;
  204. #else
  205. extern char ifstk[];
  206. extern char *curif;
  207. #endif
  208.  
  209. /*
  210.  * expparse - "currently parsing a #if expression".
  211.  *  Used to prevent interpretation of the macro "defined()" outside
  212.  *  #if expressions.
  213.  */
  214.  
  215. #ifdef VARS
  216. int expparse;
  217. #else
  218. extern int expparse;
  219. #endif
  220.  
  221. /*
  222.  * the next set of definitions are values of parameters to pushfile().
  223.  *  PF_NOLOOK    - the filename was given on the command line.  Don't
  224.  *         search any directories for it.
  225.  *  PF_NODOT    - the include filename was enclosed in '<' and '>'.
  226.  *         Do not search the current directory (dot) for the it.
  227.  *  PF_DOT    - the include filename was enclosed in double-quotes.
  228.  *
  229.  *  PF_HIDE    - the file is not to be interpreted (I.e. is an include file).
  230.  *         Do not output anything while processing this file.
  231.  *  PF_NOHIDE    - the file is to be interpreted.
  232.  */
  233.  
  234. # define PF_NOLOOK    (-1)
  235. # define PF_NODOT    0
  236. # define PF_DOT        1
  237.  
  238. # define PF_HIDE    TRUE
  239. # define PF_NOHIDE    FALSE
  240.  
  241. /*
  242.  * savcom - "save comments and whitespace"
  243.  *  If false, comments and leading and trailing whitespace are removed
  244.  *   from interpreted macro definitions.
  245.  */
  246.  
  247. #ifdef VARS
  248. int savcom;
  249. #else
  250. extern int savcom;
  251. #endif
  252.  
  253. /*
  254.  * catlist - the list of files to process; I.E. the filenames from
  255.  *  the command line.  A zero pointer marks the end of the list.
  256.  * nxtfile - points to the next element of catlist[] to be processed.
  257.  */
  258.  
  259. # define CLSIZ        100
  260. #ifdef VARS
  261. char *catlist[CLSIZ];
  262. char **nxtfile;
  263. #else
  264. extern char *catlist[];
  265. extern char **nxtfile;
  266. #endif
  267.  
  268. /*
  269.  * dirlist - the list of directories to search for an include file.
  270.  *  I.E. all the -I directories from the command line + /usr/include.
  271.  *  (the search of the current directory of the file is handled separately.)
  272.  *  A zero pointer marks the end of the list.
  273.  */
  274.  
  275. #define DLSIZ        100
  276. #ifdef VARS
  277. char *dirlist[DLSIZ];
  278. #else
  279. extern char *dirlist[];
  280. #endif
  281.  
  282. /*
  283.  * The symbol table.  All macros are stored in this table.
  284.  */
  285.  
  286. struct amacro {
  287.     char *am_name;    /*
  288.              * the name of this macro (dynamically allocated).
  289.              * An am_name value of 0 means this slot is empty.
  290.              * All macros to be interpreted are allocated slots
  291.              * before any files are scanned.  #define and #undef
  292.              * do not allocate or free symbol-table slots.
  293.              */
  294.     int am_npar;    /* number of parameters.  -1 == no parameters.    */
  295.     char *am_val;    /*
  296.              * the value (replacement text) of the macro.
  297.              * (dynamically allocated.)
  298.              * An am_val value of 0 means that this macro is not
  299.              * currently defined.
  300.              *
  301.              * am_val points to the null-terminator of the
  302.              * replacement text.  The replacement text is to be
  303.              * read backwards from (am_val - 1) until a null-
  304.              * terminator is found at the other end.
  305.              * An ATTN byte followed (well, preceeded if scanning
  306.              *  forward) by a one-byte integer parameter number
  307.              *  is replaced when expanding this macro by the
  308.              *  corresponding actual parameter.
  309.              * To avoid breaking string operations on val strings,
  310.              * parameter numbers begin at 1 rather than 0
  311.              *
  312.              * A visual example may help:
  313.              *   #define goop(name) hello there name people
  314.              *  results in a sym[] slot containing:
  315.              *
  316.              *  am_name:-------------|
  317.              *             V
  318.              *             goop\0
  319.              *  am_npar: 1
  320.              *  am_val:----------------------------|
  321.              *                       V
  322.              *    \0hello there <1><ATTN> people\0
  323.              */
  324. };
  325.  
  326. #define SYMSIZ    1001
  327. #ifdef VARS
  328. struct amacro sym[SYMSIZ];
  329. #else
  330. extern struct amacro sym[];
  331. #endif
  332.  
  333. extern struct amacro *findmac();
  334. extern char *savtok();
  335. extern int gintok();
  336. extern int gtok();
  337.  
  338. /*
  339.  * magicval - This (uninitialized) character is used to
  340.  *  recognize special macro's (e.g. "defined()").
  341.  * An am_val field of &magicval marks a macro
  342.  *  as special -- it cannot be undef'ed or redefined,
  343.  *  and macro expansion in gintok() recognizes it.
  344.  */
  345.  
  346. #ifdef VARS
  347. char magicval;
  348. #else
  349. extern char magicval;
  350. #endif
  351.  
  352. #define MAXPARMS 40    /* max number of formal parameters to a macro    */
  353.  
  354. /*
  355.  * the keyword structure - one of these describes each preprocessor keyword.
  356.  * see ctrl.c for the keyword array, key[].
  357.  */
  358.  
  359. struct akeyword {
  360.     char *ak_name;        /* name of this keyword (used to set ak_sym) */
  361.     int (*ak_proc)();    /* procedure to interpret this directive     */
  362.     struct amacro *ak_sym;    /*
  363.                  * pointer to the symbol table slot for this
  364.                  * keyword.  Used to recognise the keyword.
  365.                  * All keywords in this list are effectively
  366.                  * "-M"ed when scpp is invoked.  They are
  367.                  * never defined.
  368.                  *   This field is initialized at runtime.
  369.                  */
  370. };
  371. extern struct akeyword *findkey();
  372. extern char *strcpy();
  373.