source: trunk/minix/commands/awk/n.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 2.6 KB
RevLine 
[9]1/*
2 * a small awk clone
3 *
4 * (C) 1989 Saeko Hirabauashi & Kouichi Hirabayashi
5 *
6 * Absolutely no warranty. Use this software with your own risk.
7 *
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.
11 *
12 * This program was written to fit into 64K+64K memory of the Minix 1.2.
13 */
14
15
16#include <stdio.h>
17#include "awk.h"
18
19NODE *
20node0(type)
21{
22 NODE *p;
23 char *emalloc();
24
25 p = (NODE *) emalloc(sizeof(*p) - sizeof(p));
26 p->n_type = type;
27 p->n_next = NULL;
28 return p;
29}
30
31NODE *
32node1(type, arg0) NODE *arg0;
33{
34 NODE *p;
35 char *emalloc();
36
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;
42}
43
44NODE *
45node2(type, arg0, arg1) NODE *arg0, *arg1;
46{
47 NODE *p;
48 char *emalloc();
49
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;
56}
57
58NODE *
59node3(type, arg0, arg1, arg2) NODE *arg0, *arg1, *arg2;
60{
61 NODE *p;
62 char *emalloc();
63
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;
71}
72
73NODE *
74node4(type, arg0, arg1, arg2, arg3) NODE *arg0, *arg1, *arg2, *arg3;
75{
76 NODE *p;
77 char *emalloc();
78
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;
87}
88
89CELL *
90mkcell(type, sval, fval) char *sval; double fval;
91{
92 CELL *p;
93 char *emalloc(), *strsave();
94
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;
103}
104
105#ifdef TMPCELL
106#define MAXTMP 25
107
108CELL tmpcell[MAXTMP];
109#endif
110
111CELL *
112mktmp(type, sval, fval) char *sval; double fval;
113{
114 register int i;
115 char *strsave();
116
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];
124 }
125 error("formula too complex", (char *) 0);
126#else
127 return mkcell(type | TMP, sval, fval);
128#endif
129}
130
131c_free(p) CELL *p;
132{
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;
143 }
144 p->c_type = 0;
145 Free(p);
146 p = NULL;
147#endif
148 }
149}
Note: See TracBrowser for help on using the repository browser.