2 * expr.c - expression support functions for cawf(1)
6 * Copyright (c) 1991 Purdue University Research Foundation,
7 * West Lafayette, Indiana 47907. All rights reserved.
9 * Written by Victor A. Abell <abe@mace.cc.purdue.edu>, Purdue
10 * University Computing Center. Not derived from licensed software;
11 * derived from awf(1) by Henry Spencer of the University of Toronto.
13 * Permission is granted to anyone to use this software for any
14 * purpose on any computer system, and to alter it and redistribute
15 * it freely, subject to the following restrictions:
17 * 1. The author is not responsible for any consequences of use of
18 * this software, even if they arise from flaws in it.
20 * 2. The origin of this software must not be misrepresented, either
21 * by explicit claim or by omission. Credits must appear in the
24 * 3. Altered versions must be plainly marked as such, and must not
25 * be misrepresented as being the original software. Credits must
26 * appear in the documentation.
28 * 4. This notice may not be removed or altered.
35 * Asmcode(s, c) - assemble number/name code following backslash-character
36 * definition - e. .g, "\\nPO"
39 unsigned char *Asmcode(unsigned char **s
, unsigned char *c
) {
40 /* pointer to character after '\\' s
41 * code destination (c[3]) c
46 c
[0] = c
[1] = c
[2] = '\0';
47 if ((c
[0] = *s1
) == '(') {
49 if ((c
[0] = *s1
) != '\0') {
59 * Delnum(nx) - delete number
65 unsigned char buf
[MAXLINE
]; /* message buffer */
68 (void) sprintf((char *)buf
, " bad Delnum(%d) index", nx
);
69 Error(FATAL
, LINE
, (char *)buf
, NULL
);
71 while (nx
< (Nnr
- 1)) {
72 Numb
[nx
] = Numb
[nx
+ 1];
80 * Findnum(n, v, e) - find or optionally enter number value
83 int Findnum(unsigned char *n
, int v
, int e
) {
86 * e = 0 = find, don't enter
87 * e = 1 = enter, don't find
89 int cmp
, low
, hi
, mid
; /* binary search controls */
90 unsigned char c
[3]; /* name buffer */
93 c
[1] = (n
[1] == ' ' || n
[1] == '\t') ? '\0' : n
[1];
99 if ((cmp
= strncmp((char *)c
, (char *)Numb
[mid
].nm
, 2)) < 0)
112 Error(FATAL
, LINE
, " out of number registers at ", (char *)c
);
116 for (hi
= Nnr
- 1; hi
>= mid
; hi
--)
117 Numb
[hi
+1] = Numb
[hi
];
120 Numb
[mid
].nm
[0] = c
[0];
121 Numb
[mid
].nm
[1] = c
[1];
128 * Findparms(n) - find parameter registers
131 int Findparms(unsigned char *n
) {
132 /* parameter name n */
133 unsigned char c
[3]; /* character buffer */
134 int i
; /* temporary index */
137 c
[1] = (n
[1] == ' ' || n
[1] == '\t') ? '\0' : n
[1];
139 for (i
= 0; Parms
[i
].nm
[0]; i
++) {
140 if (c
[0] == Parms
[i
].nm
[0] && c
[1] == Parms
[i
].nm
[1])
148 * Findscale(n, v, e) - find and optionally enter scaling factor value
151 int Findscale(int n
, double v
, int e
) {
152 /* scaling factor name n
154 * e = 0 = find, don't enter
155 * e = 1 = enter, don't find
160 for (i
= 0; Scale
[i
].nm
; i
++) {
161 if ((unsigned char )n
== Scale
[i
].nm
)
166 pval
= &Scale
[i
].val
;