forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathn.c
More file actions
executable file
·149 lines (130 loc) · 2.63 KB
/
Copy pathn.c
File metadata and controls
executable file
·149 lines (130 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* a small awk clone
*
* (C) 1989 Saeko Hirabauashi & Kouichi Hirabayashi
*
* Absolutely no warranty. Use this software with your own risk.
*
* Permission to use, copy, modify and distribute this software for any
* purpose and without fee is hereby granted, provided that the above
* copyright and disclaimer notice.
*
* This program was written to fit into 64K+64K memory of the Minix 1.2.
*/
#include <stdio.h>
#include "awk.h"
NODE *
node0(type)
{
NODE *p;
char *emalloc();
p = (NODE *) emalloc(sizeof(*p) - sizeof(p));
p->n_type = type;
p->n_next = NULL;
return p;
}
NODE *
node1(type, arg0) NODE *arg0;
{
NODE *p;
char *emalloc();
p = (NODE *) emalloc(sizeof(*p));
p->n_type = type;
p->n_next = NULL;
p->n_arg[0] = (NODE *) arg0;
return p;
}
NODE *
node2(type, arg0, arg1) NODE *arg0, *arg1;
{
NODE *p;
char *emalloc();
p = (NODE *) emalloc(sizeof(*p) + sizeof(p) * 1);
p->n_type = type;
p->n_next = NULL;
p->n_arg[0] = (NODE *) arg0;
p->n_arg[1] = (NODE *) arg1;
return p;
}
NODE *
node3(type, arg0, arg1, arg2) NODE *arg0, *arg1, *arg2;
{
NODE *p;
char *emalloc();
p = (NODE *) emalloc(sizeof(*p) + sizeof(p) * 2);
p->n_type = type;
p->n_next = NULL;
p->n_arg[0] = (NODE *) arg0;
p->n_arg[1] = (NODE *) arg1;
p->n_arg[2] = (NODE *) arg2;
return p;
}
NODE *
node4(type, arg0, arg1, arg2, arg3) NODE *arg0, *arg1, *arg2, *arg3;
{
NODE *p;
char *emalloc();
p = (NODE *) emalloc(sizeof(*p) + sizeof(p) * 3);
p->n_type = type;
p->n_next = NULL;
p->n_arg[0] = (NODE *) arg0;
p->n_arg[1] = (NODE *) arg1;
p->n_arg[2] = (NODE *) arg2;
p->n_arg[3] = (NODE *) arg3;
return p;
}
CELL *
mkcell(type, sval, fval) char *sval; double fval;
{
CELL *p;
char *emalloc(), *strsave();
p = (CELL *) emalloc(sizeof(*p));
p->c_type = type;
if (sval == NULL)
p->c_sval = NULL;
else
p->c_sval = strsave(sval);
p->c_fval = fval;
return p;
}
#ifdef TMPCELL
#define MAXTMP 25
CELL tmpcell[MAXTMP];
#endif
CELL *
mktmp(type, sval, fval) char *sval; double fval;
{
register int i;
char *strsave();
#ifdef TMPCELL
for (i = 0; i < MAXTMP; i++)
if (tmpcell[i].c_type == 0) {
tmpcell[i].c_type = type | TMP;
tmpcell[i].c_sval = strsave(sval);
tmpcell[i].c_fval = fval;
return &tmpcell[i];
}
error("formula too complex", (char *) 0);
#else
return mkcell(type | TMP, sval, fval);
#endif
}
c_free(p) CELL *p;
{
if ((p != NULL) && (p->c_type & TMP)) {
#ifdef TMPCELL
p->c_type = 0;
sfree(p->c_sval);
p->c_sval = (char *)NULL;
p->c_fval = 0.0;
#else
if (p->c_sval != NULL) {
Free(p->c_sval);
p->c_sval = NULL;
}
p->c_type = 0;
Free(p);
p = NULL;
#endif
}
}