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