8 |
|
*/ |
9 |
|
|
10 |
|
#include <stdlib.h> |
11 |
– |
#include <stdio.h> |
12 |
– |
#include <string.h> |
11 |
|
#include <setjmp.h> |
12 |
|
#include <ctype.h> |
13 |
|
|
14 |
+ |
#include "rtio.h" |
15 |
+ |
#include "rterror.h" |
16 |
|
#include "calcomp.h" |
17 |
|
|
18 |
– |
|
18 |
|
#define MAXRES 100 |
19 |
|
|
20 |
|
double result[MAXRES]; |
21 |
|
int nres = 0; |
22 |
|
|
24 |
– |
#ifndef BSD |
25 |
– |
#define index strchr |
26 |
– |
#endif |
27 |
– |
|
23 |
|
jmp_buf env; |
24 |
|
int recover = 0; |
25 |
|
|
26 |
|
|
27 |
< |
main(argc, argv) |
28 |
< |
int argc; |
34 |
< |
char *argv[]; |
27 |
> |
int |
28 |
> |
main(int argc, char *argv[]) |
29 |
|
{ |
30 |
< |
char expr[512]; |
30 |
> |
char expr[2048]; |
31 |
> |
char *epos; |
32 |
|
FILE *fp; |
33 |
|
int i; |
34 |
< |
register char *cp; |
34 |
> |
char *cp; |
35 |
|
|
36 |
|
esupport |= E_VARIABLE|E_INCHAN|E_FUNCTION; |
37 |
|
esupport &= ~(E_REDEFW|E_RCONST|E_OUTCHAN); |
40 |
|
#endif |
41 |
|
varset("PI", ':', 3.14159265358979323846); |
42 |
|
|
43 |
< |
for (i = 1; i < argc; i++) |
44 |
< |
fcompile(argv[i]); |
45 |
< |
|
43 |
> |
for (i = 1; i < argc; i++) { |
44 |
> |
cp = getpath(argv[i], getrlibpath(), 0); |
45 |
> |
if (cp == NULL) { |
46 |
> |
eputs(argv[0]); |
47 |
> |
eputs(": cannot find file '"); |
48 |
> |
eputs(argv[i]); |
49 |
> |
eputs("'\n"); |
50 |
> |
quit(1); |
51 |
> |
} |
52 |
> |
fcompile(cp); |
53 |
> |
} |
54 |
|
setjmp(env); |
55 |
|
recover = 1; |
56 |
|
eclock++; |
57 |
|
|
58 |
< |
while (fgets(expr, sizeof(expr), stdin) != NULL) { |
59 |
< |
for (cp = expr; *cp && *cp != '\n'; cp++) |
60 |
< |
; |
61 |
< |
*cp = '\0'; |
58 |
> |
epos = expr; |
59 |
> |
while (fgets(epos, sizeof(expr)-(epos-expr), stdin) != NULL) { |
60 |
> |
while (*epos && *epos != '\n') |
61 |
> |
epos++; |
62 |
> |
if (*epos && epos > expr && epos[-1] == '\\') { |
63 |
> |
epos[-1] = ' '; |
64 |
> |
continue; /* escaped newline */ |
65 |
> |
} |
66 |
> |
*epos = '\0'; |
67 |
> |
epos = expr; |
68 |
|
switch (expr[0]) { |
69 |
|
case '\0': |
70 |
|
continue; |
98 |
|
eputs("file name required\n"); |
99 |
|
continue; |
100 |
|
} |
101 |
+ |
cp = getpath(cp, getrlibpath(), 0); |
102 |
+ |
if (cp == NULL) { |
103 |
+ |
eputs("cannot find file\n"); |
104 |
+ |
continue; |
105 |
+ |
} |
106 |
|
fcompile(cp); |
107 |
|
eclock++; |
108 |
|
continue; |
109 |
|
} |
110 |
< |
if ((cp = index(expr, '=')) != NULL || |
111 |
< |
(cp = index(expr, ':')) != NULL) { |
110 |
> |
if ((cp = strchr(expr, '=')) != NULL || |
111 |
> |
(cp = strchr(expr, ':')) != NULL) { |
112 |
|
if (cp[1]) |
113 |
|
scompile(expr, NULL, 0); |
114 |
|
else if (*cp == '=') { |
134 |
|
|
135 |
|
recover = 0; |
136 |
|
quit(0); |
137 |
+ |
return 0; /* pro forma exit */ |
138 |
|
} |
139 |
|
|
140 |
|
|
153 |
|
|
154 |
|
|
155 |
|
void |
156 |
< |
eputs(msg) |
142 |
< |
char *msg; |
156 |
> |
eputs(const char *msg) |
157 |
|
{ |
158 |
|
fputs(msg, stderr); |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
void |
163 |
< |
wputs(msg) |
150 |
< |
char *msg; |
163 |
> |
wputs(const char *msg) |
164 |
|
{ |
165 |
|
eputs(msg); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
void |
170 |
< |
quit(code) |
158 |
< |
int code; |
170 |
> |
quit(int code) |
171 |
|
{ |
172 |
|
if (recover) /* a cavalier approach */ |
173 |
|
longjmp(env, 1); |