| 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 "paths.h" |
| 16 |
|
#include "rterror.h" |
| 17 |
|
#include "calcomp.h" |
| 18 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
int |
| 29 |
< |
main(argc, argv) |
| 30 |
< |
int argc; |
| 31 |
< |
char *argv[]; |
| 29 |
> |
main(int argc, char *argv[]) |
| 30 |
|
{ |
| 31 |
< |
char expr[512]; |
| 31 |
> |
char expr[2048]; |
| 32 |
> |
char *epos; |
| 33 |
|
FILE *fp; |
| 34 |
|
int i; |
| 35 |
< |
register char *cp; |
| 35 |
> |
char *cp; |
| 36 |
|
|
| 37 |
|
esupport |= E_VARIABLE|E_INCHAN|E_FUNCTION; |
| 38 |
|
esupport &= ~(E_REDEFW|E_RCONST|E_OUTCHAN); |
| 41 |
|
#endif |
| 42 |
|
varset("PI", ':', 3.14159265358979323846); |
| 43 |
|
|
| 44 |
< |
for (i = 1; i < argc; i++) |
| 45 |
< |
fcompile(argv[i]); |
| 46 |
< |
|
| 44 |
> |
for (i = 1; i < argc; i++) { |
| 45 |
> |
cp = getpath(argv[i], getrlibpath(), 0); |
| 46 |
> |
if (cp == NULL) { |
| 47 |
> |
eputs(argv[0]); |
| 48 |
> |
eputs(": cannot find file '"); |
| 49 |
> |
eputs(argv[i]); |
| 50 |
> |
eputs("'\n"); |
| 51 |
> |
quit(1); |
| 52 |
> |
} |
| 53 |
> |
fcompile(cp); |
| 54 |
> |
} |
| 55 |
|
setjmp(env); |
| 56 |
|
recover = 1; |
| 57 |
|
eclock++; |
| 58 |
|
|
| 59 |
< |
while (fgets(expr, sizeof(expr), stdin) != NULL) { |
| 60 |
< |
for (cp = expr; *cp && *cp != '\n'; cp++) |
| 61 |
< |
; |
| 62 |
< |
*cp = '\0'; |
| 59 |
> |
epos = expr; |
| 60 |
> |
while (fgets(epos, sizeof(expr)-(epos-expr), stdin) != NULL) { |
| 61 |
> |
while (*epos && *epos != '\n') |
| 62 |
> |
epos++; |
| 63 |
> |
if (*epos && epos > expr && epos[-1] == '\\') { |
| 64 |
> |
epos[-1] = ' '; |
| 65 |
> |
continue; /* escaped newline */ |
| 66 |
> |
} |
| 67 |
> |
while (epos > expr && isspace(epos[-1])) |
| 68 |
> |
epos--; /* eliminate end spaces */ |
| 69 |
> |
*epos = '\0'; |
| 70 |
> |
epos = expr; |
| 71 |
|
switch (expr[0]) { |
| 72 |
|
case '\0': |
| 73 |
|
continue; |
| 74 |
|
case '?': |
| 75 |
|
for (cp = expr+1; isspace(*cp); cp++) |
| 76 |
|
; |
| 77 |
+ |
if (*calcontext(NULL)) |
| 78 |
+ |
printf("context is: %s\n", calcontext(NULL)); |
| 79 |
|
if (*cp) |
| 80 |
|
dprint(cp, stdout); |
| 81 |
|
else |
| 103 |
|
eputs("file name required\n"); |
| 104 |
|
continue; |
| 105 |
|
} |
| 106 |
+ |
cp = getpath(cp, getrlibpath(), 0); |
| 107 |
+ |
if (cp == NULL) { |
| 108 |
+ |
eputs("cannot find file\n"); |
| 109 |
+ |
continue; |
| 110 |
+ |
} |
| 111 |
|
fcompile(cp); |
| 112 |
|
eclock++; |
| 113 |
|
continue; |
| 114 |
+ |
case '[': |
| 115 |
+ |
for (cp = expr+1; isspace(*cp); cp++) |
| 116 |
+ |
; |
| 117 |
+ |
if (!isalpha(*cp)) { |
| 118 |
+ |
eputs("context name required\n"); |
| 119 |
+ |
continue; |
| 120 |
+ |
} |
| 121 |
+ |
printf("context now: %s\n", pushcontext(cp)); |
| 122 |
+ |
continue; |
| 123 |
+ |
case ']': |
| 124 |
+ |
cp = popcontext(); |
| 125 |
+ |
if (*cp) |
| 126 |
+ |
printf("context now: %s\n", cp); |
| 127 |
+ |
else |
| 128 |
+ |
printf("at global context\n"); |
| 129 |
+ |
continue; |
| 130 |
|
} |
| 131 |
|
if ((cp = strchr(expr, '=')) != NULL || |
| 132 |
|
(cp = strchr(expr, ':')) != NULL) { |
| 174 |
|
|
| 175 |
|
|
| 176 |
|
void |
| 177 |
< |
eputs(msg) |
| 140 |
< |
char *msg; |
| 177 |
> |
eputs(const char *msg) |
| 178 |
|
{ |
| 179 |
|
fputs(msg, stderr); |
| 180 |
|
} |
| 181 |
|
|
| 182 |
|
|
| 183 |
|
void |
| 184 |
< |
wputs(msg) |
| 148 |
< |
char *msg; |
| 184 |
> |
wputs(const char *msg) |
| 185 |
|
{ |
| 186 |
|
eputs(msg); |
| 187 |
|
} |
| 188 |
|
|
| 189 |
|
|
| 190 |
|
void |
| 191 |
< |
quit(code) |
| 156 |
< |
int code; |
| 191 |
> |
quit(int code) |
| 192 |
|
{ |
| 193 |
|
if (recover) /* a cavalier approach */ |
| 194 |
|
longjmp(env, 1); |