[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.7

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