BSD 3 development
[unix-history] / usr / src / cmd / awk / awk.def
CommitLineData
42d6e430
BJ
1#define xfree(a) { if(a!=NULL) yfree(a); a=NULL;}
2#define yfree free
3#ifdef DEBUG
4# define dprintf if(dbg)printf
5#else
6# define dprintf(x1, x2, x3, x4)
7#endif
8typedef double awkfloat;
9
10extern char **FS;
11extern char **RS;
12extern char **ORS;
13extern char **OFS;
14extern char **OFMT;
15extern awkfloat *NR;
16extern awkfloat *NF;
17extern char **FILENAME;
18
19extern char record[];
20extern int dbg;
21extern int lineno;
22extern int errorflag;
23extern int donefld; /* 1 if record broken into fields */
24extern int donerec; /* 1 if record is valid (no fld has changed */
25
26typedef struct val { /* general value during processing */
27 char *nval; /* name, for variables only */
28 char *sval; /* string value */
29 awkfloat fval; /* value as number */
30 unsigned tval; /* type info */
31 struct val *nextval; /* ptr to next if chained */
32} cell;
33extern cell *symtab[];
34cell *setsymtab(), *lookup(), **makesymtab();
35
36extern cell *recloc; /* location of input record */
37extern cell *nrloc; /* NR */
38extern cell *nfloc; /* NF */
39
40#define STR 01 /* string value is valid */
41#define NUM 02 /* number value is valid */
42#define FLD 04 /* FLD means don't free string space */
43#define CON 010 /* this is a constant */
44#define ARR 020 /* this is an array */
45
46awkfloat setfval(), getfval();
47char *setsval(), *getsval();
48char *tostring(), *tokname(), *malloc();
49double log(), sqrt(), exp(), atof();
50
51/* function types */
52#define FLENGTH 1
53#define FSQRT 2
54#define FEXP 3
55#define FLOG 4
56#define FINT 5
57
58typedef struct {
59 char otype;
60 char osub;
61 cell *optr;
62} obj;
63
64#define BOTCH 1
65struct nd {
66 char ntype;
67 char subtype;
68 struct nd *nnext;
69 int nobj;
70 struct nd *narg[BOTCH]; /* C won't take a zero length array */
71};
72typedef struct nd node;
73extern node *winner;
74extern node *nullstat;
75
76/* otypes */
77#define OCELL 0
78#define OEXPR 1
79#define OBOOL 2
80#define OJUMP 3
81
82/* cell subtypes */
83#define CTEMP 4
84#define CNAME 3
85#define CVAR 2
86#define CFLD 1
87#define CCON 0
88
89/* bool subtypes */
90#define BTRUE 1
91#define BFALSE 2
92
93/* jump subtypes */
94#define JEXIT 1
95#define JNEXT 2
96#define JBREAK 3
97#define JCONT 4
98
99/* node types */
100#define NVALUE 1
101#define NSTAT 2
102#define NEXPR 3
103#define NPA2 4
104
105extern obj (*proctab[])();
106extern obj true, false;
107extern int pairstack[], paircnt;
108
109#define cantexec(n) (n->ntype == NVALUE)
110#define notlegal(n) (proctab[n-FIRSTTOKEN]== nullproc)
111#define isexpr(n) (n->ntype == NEXPR)
112#define isjump(n) (n.otype == OJUMP)
113#define isexit(n) (n.otype == OJUMP && n.osub == JEXIT)
114#define isbreak(n) (n.otype == OJUMP && n.osub == JBREAK)
115#define iscont(n) (n.otype == OJUMP && n.osub == JCONT)
116#define isnext(n) (n.otype == OJUMP && n.osub == JNEXT)
117#define isstr(n) (n.optr->tval & STR)
118#define istrue(n) (n.otype == OBOOL && n.osub == BTRUE)
119#define istemp(n) (n.otype == OCELL && n.osub == CTEMP)
120#define isfld(n) (!donefld && n.osub==CFLD && n.otype==OCELL && n.optr->nval==0)
121#define isrec(n) (donefld && n.osub==CFLD && n.otype==OCELL && n.optr->nval!=0)
122obj nullproc();
123obj relop();
124
125#define MAXSYM 16
126#define HAT 0177 /* matches ^ in regular expr */
127 /* watch out for mach dep */