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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
/*
* expr.c - expression support functions for cawf(1)
*/
/*
* Copyright (c) 1991 Purdue University Research Foundation,
* West Lafayette, Indiana 47907. All rights reserved.
*
* Written by Victor A. Abell <abe@mace.cc.purdue.edu>, Purdue
* University Computing Center. Not derived from licensed software;
* derived from awf(1) by Henry Spencer of the University of Toronto.
*
* Permission is granted to anyone to use this software for any
* purpose on any computer system, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The author is not responsible for any consequences of use of
* this software, even if they arise from flaws in it.
*
* 2. The origin of this software must not be misrepresented, either
* by explicit claim or by omission. Credits must appear in the
* documentation.
*
* 3. Altered versions must be plainly marked as such, and must not
* be misrepresented as being the original software. Credits must
* appear in the documentation.
*
* 4. This notice may not be removed or altered.
*/
#include "cawf.h"
/*
* Asmcode(s, c) - assemble number/name code following backslash-character
* definition - e. .g, "\\nPO"
*/
unsigned char *Asmcode(unsigned char **s, unsigned char *c) {
/* pointer to character after '\\' s
* code destination (c[3]) c
*/
unsigned char *s1;
s1 = *s + 1;
c[0] = c[1] = c[2] = '\0';
if ((c[0] = *s1) == '(') {
s1++;
if ((c[0] = *s1) != '\0') {
s1++;
c[1] = *s1;
}
}
return(s1);
}
/*
* Delnum(nx) - delete number
*/
void Delnum(int nx) {
/* number index nx */
unsigned char buf[MAXLINE]; /* message buffer */
if (nx >= Nnr) {
(void) sprintf((char *)buf, " bad Delnum(%d) index", nx);
Error(FATAL, LINE, (char *)buf, NULL);
}
while (nx < (Nnr - 1)) {
Numb[nx] = Numb[nx + 1];
nx++;
}
Nnr--;
}
/*
* Findnum(n, v, e) - find or optionally enter number value
*/
int Findnum(unsigned char *n, int v, int e) {
/* register name n
* value v
* e = 0 = find, don't enter
* e = 1 = enter, don't find
*/
int cmp, low, hi, mid; /* binary search controls */
unsigned char c[3]; /* name buffer */
c[0] = n[0];
c[1] = (n[1] == ' ' || n[1] == '\t') ? '\0' : n[1];
c[2] = '\0';
low = mid = 0;
hi = Nnr - 1;
while (low <= hi) {
mid = (low + hi) / 2;
if ((cmp = strncmp((char *)c, (char *)Numb[mid].nm, 2)) < 0)
hi = mid - 1;
else if (cmp > 0)
low = mid + 1;
else {
if (e)
Numb[mid].val = v;
return(mid);
}
}
if ( ! e)
return(-1);
if (Nnr >= MAXNR)
Error(FATAL, LINE, " out of number registers at ", (char *)c);
if (Nnr) {
if (cmp > 0)
mid++;
for (hi = Nnr - 1; hi >= mid; hi--)
Numb[hi+1] = Numb[hi];
}
Nnr++;
Numb[mid].nm[0] = c[0];
Numb[mid].nm[1] = c[1];
Numb[mid].val = v;
return(mid);
}
/*
* Findparms(n) - find parameter registers
*/
int Findparms(unsigned char *n) {
/* parameter name n */
unsigned char c[3]; /* character buffer */
int i; /* temporary index */
c[0] = n[0];
c[1] = (n[1] == ' ' || n[1] == '\t') ? '\0' : n[1];
c[2] = '\0';
for (i = 0; Parms[i].nm[0]; i++) {
if (c[0] == Parms[i].nm[0] && c[1] == Parms[i].nm[1])
return(i);
}
return(-1);
}
/*
* Findscale(n, v, e) - find and optionally enter scaling factor value
*/
int Findscale(int n, double v, int e) {
/* scaling factor name n
* value v
* e = 0 = find, don't enter
* e = 1 = enter, don't find
*/
int i;
double *pval;
for (i = 0; Scale[i].nm; i++) {
if ((unsigned char )n == Scale[i].nm)
break;
}
if (Scale[i].nm) {
if (e) {
pval = &Scale[i].val;
*pval = v;
}
return(i);
}
return(-1);
}
|