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