vm: include no-caching bits in PTF_ALLFLAGS for flags sanity check.
[minix.git] / commands / awk.old / n.c
blob489d3e5b63756b65d32c73530be04bdcc51da19f
1 /*
2 * a small awk clone
4 * (C) 1989 Saeko Hirabauashi & Kouichi Hirabayashi
6 * Absolutely no warranty. Use this software with your own risk.
8 * Permission to use, copy, modify and distribute this software for any
9 * purpose and without fee is hereby granted, provided that the above
10 * copyright and disclaimer notice.
12 * This program was written to fit into 64K+64K memory of the Minix 1.2.
16 #include <stdio.h>
17 #include "awk.h"
19 NODE *
20 node0(type)
22 NODE *p;
23 char *emalloc();
25 p = (NODE *) emalloc(sizeof(*p) - sizeof(p));
26 p->n_type = type;
27 p->n_next = NULL;
28 return p;
31 NODE *
32 node1(type, arg0) NODE *arg0;
34 NODE *p;
35 char *emalloc();
37 p = (NODE *) emalloc(sizeof(*p));
38 p->n_type = type;
39 p->n_next = NULL;
40 p->n_arg[0] = (NODE *) arg0;
41 return p;
44 NODE *
45 node2(type, arg0, arg1) NODE *arg0, *arg1;
47 NODE *p;
48 char *emalloc();
50 p = (NODE *) emalloc(sizeof(*p) + sizeof(p) * 1);
51 p->n_type = type;
52 p->n_next = NULL;
53 p->n_arg[0] = (NODE *) arg0;
54 p->n_arg[1] = (NODE *) arg1;
55 return p;
58 NODE *
59 node3(type, arg0, arg1, arg2) NODE *arg0, *arg1, *arg2;
61 NODE *p;
62 char *emalloc();
64 p = (NODE *) emalloc(sizeof(*p) + sizeof(p) * 2);
65 p->n_type = type;
66 p->n_next = NULL;
67 p->n_arg[0] = (NODE *) arg0;
68 p->n_arg[1] = (NODE *) arg1;
69 p->n_arg[2] = (NODE *) arg2;
70 return p;
73 NODE *
74 node4(type, arg0, arg1, arg2, arg3) NODE *arg0, *arg1, *arg2, *arg3;
76 NODE *p;
77 char *emalloc();
79 p = (NODE *) emalloc(sizeof(*p) + sizeof(p) * 3);
80 p->n_type = type;
81 p->n_next = NULL;
82 p->n_arg[0] = (NODE *) arg0;
83 p->n_arg[1] = (NODE *) arg1;
84 p->n_arg[2] = (NODE *) arg2;
85 p->n_arg[3] = (NODE *) arg3;
86 return p;
89 CELL *
90 mkcell(type, sval, fval) char *sval; double fval;
92 CELL *p;
93 char *emalloc(), *strsave();
95 p = (CELL *) emalloc(sizeof(*p));
96 p->c_type = type;
97 if (sval == NULL)
98 p->c_sval = NULL;
99 else
100 p->c_sval = strsave(sval);
101 p->c_fval = fval;
102 return p;
105 #ifdef TMPCELL
106 #define MAXTMP 25
108 CELL tmpcell[MAXTMP];
109 #endif
111 CELL *
112 mktmp(type, sval, fval) char *sval; double fval;
114 register int i;
115 char *strsave();
117 #ifdef TMPCELL
118 for (i = 0; i < MAXTMP; i++)
119 if (tmpcell[i].c_type == 0) {
120 tmpcell[i].c_type = type | TMP;
121 tmpcell[i].c_sval = strsave(sval);
122 tmpcell[i].c_fval = fval;
123 return &tmpcell[i];
125 error("formula too complex", (char *) 0);
126 #else
127 return mkcell(type | TMP, sval, fval);
128 #endif
131 c_free(p) CELL *p;
133 if ((p != NULL) && (p->c_type & TMP)) {
134 #ifdef TMPCELL
135 p->c_type = 0;
136 sfree(p->c_sval);
137 p->c_sval = (char *)NULL;
138 p->c_fval = 0.0;
139 #else
140 if (p->c_sval != NULL) {
141 Free(p->c_sval);
142 p->c_sval = NULL;
144 p->c_type = 0;
145 Free(p);
146 p = NULL;
147 #endif