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"
41 unsigned char **s
; /* pointer to character after '\\' */
42 unsigned char *c
; /* code destination (c[3]) */
47 c
[0] = c
[1] = c
[2] = '\0';
48 if ((c
[0] = *s1
) == '(') {
50 if ((c
[0] = *s1
) != '\0') {
60 * Delnum(nx) - delete number
65 int nx
; /* number index */
67 unsigned char buf
[MAXLINE
]; /* message buffer */
70 (void) sprintf((char *)buf
, " bad Delnum(%d) index", nx
);
71 Error(FATAL
, LINE
, (char *)buf
, NULL
);
73 while (nx
< (Nnr
- 1)) {
74 Numb
[nx
] = Numb
[nx
+ 1];
82 * Findnum(n, v, e) - find or optionally enter number value
86 unsigned char *n
; /* register name */
88 int e
; /* 0 = find, don't enter
89 * 1 = enter, don't find */
91 int cmp
, low
, hi
, mid
; /* binary search controls */
92 unsigned char c
[3]; /* name buffer */
95 c
[1] = (n
[1] == ' ' || n
[1] == '\t') ? '\0' : n
[1];
100 mid
= (low
+ hi
) / 2;
101 if ((cmp
= strncmp((char *)c
, (char *)Numb
[mid
].nm
, 2)) < 0)
114 Error(FATAL
, LINE
, " out of number registers at ", (char *)c
);
118 for (hi
= Nnr
- 1; hi
>= mid
; hi
--)
119 Numb
[hi
+1] = Numb
[hi
];
122 Numb
[mid
].nm
[0] = c
[0];
123 Numb
[mid
].nm
[1] = c
[1];
130 * Findparms(n) - find parameter registers
134 unsigned char *n
; /* parameter name */
136 unsigned char c
[3]; /* character buffer */
137 int i
; /* temporary index */
140 c
[1] = (n
[1] == ' ' || n
[1] == '\t') ? '\0' : n
[1];
142 for (i
= 0; Parms
[i
].nm
[0]; i
++) {
143 if (c
[0] == Parms
[i
].nm
[0] && c
[1] == Parms
[i
].nm
[1])
151 * Findscale(n, v, e) - find and optionally enter scaling factor value
155 int n
; /* scaling factor name */
156 double v
; /* value */
157 int e
; /* 0 = find, don't enter
158 * 1 = enter, don't find */
163 for (i
= 0; Scale
[i
].nm
; i
++) {
164 if ((unsigned char )n
== Scale
[i
].nm
)
169 pval
= &Scale
[i
].val
;