home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 11 / AUCD11B.iso / LANGUAGES / WraithSet / AwkStuff / 1TSRC / h / awk next >
Text File  |  1999-05-10  |  6KB  |  233 lines

  1. /****************************************************************
  2. Copyright (C) Lucent Technologies 1997
  3. All Rights Reserved
  4.  
  5. Permission to use, copy, modify, and distribute this software and
  6. its documentation for any purpose and without fee is hereby
  7. granted, provided that the above copyright notice appear in all
  8. copies and that both that the copyright notice and this
  9. permission notice and warranty disclaimer appear in supporting
  10. documentation, and that the name Lucent Technologies or any of
  11. its entities not be used in advertising or publicity pertaining
  12. to distribution of the software without specific, written prior
  13. permission.
  14.  
  15. LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  16. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  17. IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
  18. SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  20. IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
  22. THIS SOFTWARE.
  23. ****************************************************************/
  24.  
  25. typedef double    Awkfloat;
  26.  
  27. /* unsigned char is more trouble than it's worth */
  28.  
  29. typedef    unsigned char uschar;
  30.  
  31. #define    xfree(a)    { if ((a) != NULL) { free((char *) a); a = NULL; } }
  32.  
  33. #define    DEBUG
  34. #ifdef    DEBUG
  35.             /* uses have to be doubly parenthesized */
  36. #    define    dprintf(x)    if (dbg) printf x
  37. #else
  38. #    define    dprintf(x)
  39. #endif
  40.  
  41. extern    char    errbuf[];
  42.  
  43. extern int    compile_time;    /* 1 if compiling, 0 if running */
  44. extern int    safe;        /* 0 => unsafe, 1 => safe */
  45.  
  46. #define    RECSIZE    (8 * 1024)    /* sets limit on records, fields, etc., etc. */
  47. extern int    recsize;    /* size of current record, orig RECSIZE */
  48.  
  49. extern char    **FS;
  50. extern char    **RS;
  51. extern char    **ORS;
  52. extern char    **OFS;
  53. extern char    **OFMT;
  54. extern Awkfloat *NR;
  55. extern Awkfloat *FNR;
  56. extern Awkfloat *NF;
  57. extern char    **FILENAME;
  58. extern char    **SUBSEP;
  59. extern Awkfloat *RSTART;
  60. extern Awkfloat *RLENGTH;
  61.  
  62. extern char    *record;    /* points to $0 */
  63. extern int    lineno;        /* line number in awk program */
  64. extern int    errorflag;    /* 1 if error has occurred */
  65. extern int    donefld;    /* 1 if record broken into fields */
  66. extern int    donerec;    /* 1 if record is valid (no fld has changed */
  67. extern char    inputFS[];    /* FS at time of input, for field splitting */
  68.  
  69. extern int    dbg;
  70.  
  71. extern    char    *patbeg;    /* beginning of pattern matched */
  72. extern    int    patlen;        /* length of pattern matched.  set in b.c */
  73.  
  74. /* Cell:  all information about a variable or constant */
  75.  
  76. typedef struct Cell {
  77.     uschar    ctype;        /* OCELL, OBOOL, OJUMP, etc. */
  78.     uschar    csub;        /* CCON, CTEMP, CFLD, etc. */
  79.     char    *nval;        /* name, for variables only */
  80.     char    *sval;        /* string value */
  81.     Awkfloat fval;        /* value as number */
  82.     int     tval;        /* type info: STR|NUM|ARR|FCN|FLD|CON|DONTFREE */
  83.     struct Cell *cnext;    /* ptr to next if chained */
  84. } Cell;
  85.  
  86. typedef struct Array {        /* symbol table array */
  87.     int    nelem;        /* elements in table right now */
  88.     int    size;        /* size of tab */
  89.     Cell    **tab;        /* hash table pointers */
  90. } Array;
  91.  
  92. #define    NSYMTAB    50    /* initial size of a symbol table */
  93. extern Array    *symtab;
  94.  
  95. extern Cell    *nrloc;        /* NR */
  96. extern Cell    *fnrloc;    /* FNR */
  97. extern Cell    *nfloc;        /* NF */
  98. extern Cell    *rstartloc;    /* RSTART */
  99. extern Cell    *rlengthloc;    /* RLENGTH */
  100.  
  101. /* Cell.tval values: */
  102. #define    NUM    01    /* number value is valid */
  103. #define    STR    02    /* string value is valid */
  104. #define DONTFREE 04    /* string space is not freeable */
  105. #define    CON    010    /* this is a constant */
  106. #define    ARR    020    /* this is an array */
  107. #define    FCN    040    /* this is a function name */
  108. #define FLD    0100    /* this is a field $1, $2, ... */
  109. #define    REC    0200    /* this is $0 */
  110.  
  111.  
  112. /* function types */
  113. #define    FLENGTH    1
  114. #define    FSQRT    2
  115. #define    FEXP    3
  116. #define    FLOG    4
  117. #define    FINT    5
  118. #define    FSYSTEM    6
  119. #define    FRAND    7
  120. #define    FSRAND    8
  121. #define    FSIN    9
  122. #define    FCOS    10
  123. #define    FATAN    11
  124. #define    FTOUPPER 12
  125. #define    FTOLOWER 13
  126. #define    FFLUSH    14
  127.  
  128. /* Node:  parse tree is made of nodes, with Cell's at bottom */
  129.  
  130. typedef struct Node {
  131.     int    ntype;
  132.     struct    Node *nnext;
  133.     int    lineno;
  134.     int    nobj;
  135.     struct    Node *narg[1];    /* variable: actual size set by calling malloc */
  136. } Node;
  137.  
  138. #define    NIL    ((Node *) 0)
  139.  
  140. extern Node    *winner;
  141. extern Node    *nullstat;
  142. extern Node    *nullnode;
  143.  
  144. /* ctypes */
  145. #define OCELL    1
  146. #define OBOOL    2
  147. #define OJUMP    3
  148.  
  149. /* Cell subtypes: csub */
  150. #define    CFREE    7
  151. #define CCOPY    6
  152. #define CCON    5
  153. #define CTEMP    4
  154. #define CNAME    3 
  155. #define CVAR    2
  156. #define CFLD    1
  157. #define    CUNK    0
  158.  
  159. /* bool subtypes */
  160. #define BTRUE    11
  161. #define BFALSE    12
  162.  
  163. /* jump subtypes */
  164. #define JEXIT    21
  165. #define JNEXT    22
  166. #define    JBREAK    23
  167. #define    JCONT    24
  168. #define    JRET    25
  169. #define    JNEXTFILE    26
  170.  
  171. /* node types */
  172. #define NVALUE    1
  173. #define NSTAT    2
  174. #define NEXPR    3
  175.  
  176.  
  177. extern    int    pairstack[], paircnt;
  178.  
  179. #define notlegal(n)    (n <= FIRSTTOKEN || n >= LASTTOKEN || proctab[n-FIRSTTOKEN] == nullproc)
  180. #define isvalue(n)    ((n)->ntype == NVALUE)
  181. #define isexpr(n)    ((n)->ntype == NEXPR)
  182. #define isjump(n)    ((n)->ctype == OJUMP)
  183. #define isexit(n)    ((n)->csub == JEXIT)
  184. #define    isbreak(n)    ((n)->csub == JBREAK)
  185. #define    iscont(n)    ((n)->csub == JCONT)
  186. #define    isnext(n)    ((n)->csub == JNEXT)
  187. #define    isnextfile(n)    ((n)->csub == JNEXTFILE)
  188. #define    isret(n)    ((n)->csub == JRET)
  189. #define isrec(n)    ((n)->tval & REC)
  190. #define isfld(n)    ((n)->tval & FLD)
  191. #define isstr(n)    ((n)->tval & STR)
  192. #define isnum(n)    ((n)->tval & NUM)
  193. #define isarr(n)    ((n)->tval & ARR)
  194. #define isfcn(n)    ((n)->tval & FCN)
  195. #define istrue(n)    ((n)->csub == BTRUE)
  196. #define istemp(n)    ((n)->csub == CTEMP)
  197. #define    isargument(n)    ((n)->nobj == ARG)
  198. /* #define freeable(p)    (!((p)->tval & DONTFREE)) */
  199. #define freeable(p)    ( ((p)->tval & (STR|DONTFREE)) == STR )
  200.  
  201. /* structures used by regular expression matching machinery, mostly b.c: */
  202.  
  203. #define NCHARS    (256+1)        /* 256 handles 8-bit chars; 128 does 7-bit */
  204.                 /* watch out in match(), etc. */
  205. #define NSTATES    32
  206.  
  207. typedef struct rrow {
  208.     long    ltype;    /* long avoids pointer warnings on 64-bit */
  209.     union {
  210.         int i;
  211.         Node *np;
  212.         char *up;
  213.     } lval;        /* because Al stores a pointer in it! */
  214.     int    *lfollow;
  215. } rrow;
  216.  
  217. typedef struct fa {
  218.     uschar    gototab[NSTATES][NCHARS];
  219.     uschar    out[NSTATES];
  220.     char    *restr;
  221.     int    *posns[NSTATES];
  222.     int    anchor;
  223.     int    use;
  224.     int    initstat;
  225.     int    curstat;
  226.     int    accept;
  227.     int    reset;
  228.     struct    rrow re[1];    /* variable: actual size set by calling malloc */
  229. } fa;
  230.  
  231.  
  232. #include "proto.h"
  233.