[BACK]Return to awk.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / awk

Annotation of src/usr.bin/awk/awk.h, Revision 1.4

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