Remove building with NOCRYPTO option
[minix.git] / minix / commands / cawf / expr.c
blobcc3616f40db877ea2087abc9cd6e37e1998aaf90
1 /*
2 * expr.c - expression support functions for cawf(1)
3 */
5 /*
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
22 * documentation.
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.
31 #include "cawf.h"
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
43 unsigned char *s1;
45 s1 = *s + 1;
46 c[0] = c[1] = c[2] = '\0';
47 if ((c[0] = *s1) == '(') {
48 s1++;
49 if ((c[0] = *s1) != '\0') {
50 s1++;
51 c[1] = *s1;
54 return(s1);
59 * Delnum(nx) - delete number
62 void Delnum(int nx) {
63 /* number index nx */
65 unsigned char buf[MAXLINE]; /* message buffer */
67 if (nx >= Nnr) {
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];
73 nx++;
75 Nnr--;
80 * Findnum(n, v, e) - find or optionally enter number value
83 int Findnum(unsigned char *n, int v, int e) {
84 /* register name n
85 * value v
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 */
92 c[0] = n[0];
93 c[1] = (n[1] == ' ' || n[1] == '\t') ? '\0' : n[1];
94 c[2] = '\0';
95 low = mid = 0;
96 hi = Nnr - 1;
97 while (low <= hi) {
98 mid = (low + hi) / 2;
99 if ((cmp = strncmp((char *)c, (char *)Numb[mid].nm, 2)) < 0)
100 hi = mid - 1;
101 else if (cmp > 0)
102 low = mid + 1;
103 else {
104 if (e)
105 Numb[mid].val = v;
106 return(mid);
109 if ( ! e)
110 return(-1);
111 if (Nnr >= MAXNR)
112 Error(FATAL, LINE, " out of number registers at ", (char *)c);
113 if (Nnr) {
114 if (cmp > 0)
115 mid++;
116 for (hi = Nnr - 1; hi >= mid; hi--)
117 Numb[hi+1] = Numb[hi];
119 Nnr++;
120 Numb[mid].nm[0] = c[0];
121 Numb[mid].nm[1] = c[1];
122 Numb[mid].val = v;
123 return(mid);
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 */
136 c[0] = n[0];
137 c[1] = (n[1] == ' ' || n[1] == '\t') ? '\0' : n[1];
138 c[2] = '\0';
139 for (i = 0; Parms[i].nm[0]; i++) {
140 if (c[0] == Parms[i].nm[0] && c[1] == Parms[i].nm[1])
141 return(i);
143 return(-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
153 * value v
154 * e = 0 = find, don't enter
155 * e = 1 = enter, don't find
157 int i;
158 double *pval;
160 for (i = 0; Scale[i].nm; i++) {
161 if ((unsigned char )n == Scale[i].nm)
162 break;
164 if (Scale[i].nm) {
165 if (e) {
166 pval = &Scale[i].val;
167 *pval = v;
169 return(i);
171 return(-1);