| 39 |
|
extern char *fgets(), *savestr(); |
| 40 |
|
extern char *emalloc(), *ecalloc(); |
| 41 |
|
extern EPNODE *curfunc; |
| 42 |
< |
extern double efunc(), evariable(), enumber(), euminus(), echannel(); |
| 43 |
< |
extern double eargument(), eadd(), esubtr(), emult(), edivi(), epow(); |
| 44 |
< |
extern double ebotch(); |
| 42 |
> |
extern double efunc(), evariable(); |
| 43 |
> |
static double euminus(), echannel(), eargument(), enumber(); |
| 44 |
> |
static double eadd(), esubtr(), emult(), edivi(), epow(); |
| 45 |
> |
static double ebotch(); |
| 46 |
|
extern int errno; |
| 47 |
|
|
| 48 |
|
int nextc; /* lookahead character */ |
| 85 |
|
epow, |
| 86 |
|
}; |
| 87 |
|
|
| 87 |
– |
static char *infile; /* input file name */ |
| 88 |
|
static FILE *infp; /* input file pointer */ |
| 89 |
|
static char *linbuf; /* line buffer */ |
| 90 |
+ |
static char *infile; /* input file name */ |
| 91 |
+ |
static int lineno; /* input line number */ |
| 92 |
|
static int linepos; /* position in buffer */ |
| 93 |
|
|
| 94 |
|
|
| 98 |
|
{ |
| 99 |
|
EPNODE *ep; |
| 100 |
|
|
| 101 |
< |
initstr(NULL, expr); |
| 101 |
> |
initstr(expr, NULL, 0); |
| 102 |
|
#if defined(VARIABLE) && defined(FUNCTION) |
| 103 |
|
curfunc = NULL; |
| 104 |
|
#endif |
| 293 |
|
} |
| 294 |
|
|
| 295 |
|
|
| 296 |
< |
initfile(file, fp) /* prepare input file */ |
| 295 |
< |
char *file; |
| 296 |
> |
initfile(fp, fn, ln) /* prepare input file */ |
| 297 |
|
FILE *fp; |
| 298 |
+ |
char *fn; |
| 299 |
+ |
int ln; |
| 300 |
|
{ |
| 301 |
|
static char inpbuf[MAXLINE]; |
| 302 |
|
|
| 300 |
– |
infile = file; |
| 303 |
|
infp = fp; |
| 304 |
|
linbuf = inpbuf; |
| 305 |
+ |
infile = fn; |
| 306 |
+ |
lineno = ln; |
| 307 |
|
linepos = 0; |
| 308 |
|
inpbuf[0] = '\0'; |
| 309 |
|
scan(); |
| 310 |
|
} |
| 311 |
|
|
| 312 |
|
|
| 313 |
< |
initstr(file, s) /* prepare input string */ |
| 310 |
< |
char *file; |
| 313 |
> |
initstr(s, fn, ln) /* prepare input string */ |
| 314 |
|
char *s; |
| 315 |
+ |
char *fn; |
| 316 |
+ |
int ln; |
| 317 |
|
{ |
| 313 |
– |
infile = file; |
| 318 |
|
infp = NULL; |
| 319 |
+ |
infile = fn; |
| 320 |
+ |
lineno = ln; |
| 321 |
|
linbuf = s; |
| 322 |
|
linepos = 0; |
| 323 |
|
scan(); |
| 332 |
|
nextc = EOF; |
| 333 |
|
else { |
| 334 |
|
nextc = linbuf[0]; |
| 335 |
+ |
lineno++; |
| 336 |
|
linepos = 1; |
| 337 |
|
} |
| 338 |
|
else |
| 350 |
|
} |
| 351 |
|
|
| 352 |
|
|
| 353 |
+ |
char * |
| 354 |
+ |
ltoa(l) /* convert long to ascii */ |
| 355 |
+ |
long l; |
| 356 |
+ |
{ |
| 357 |
+ |
static char buf[16]; |
| 358 |
+ |
register char *cp; |
| 359 |
+ |
int neg = 0; |
| 360 |
+ |
|
| 361 |
+ |
if (l == 0) |
| 362 |
+ |
return("0"); |
| 363 |
+ |
if (l < 0) { |
| 364 |
+ |
l = -l; |
| 365 |
+ |
neg++; |
| 366 |
+ |
} |
| 367 |
+ |
cp = buf + sizeof(buf); |
| 368 |
+ |
*--cp = '\0'; |
| 369 |
+ |
while (l) { |
| 370 |
+ |
*--cp = l % 10 + '0'; |
| 371 |
+ |
l /= 10; |
| 372 |
+ |
} |
| 373 |
+ |
if (neg) |
| 374 |
+ |
*--cp = '-'; |
| 375 |
+ |
return(cp); |
| 376 |
+ |
} |
| 377 |
+ |
|
| 378 |
+ |
|
| 379 |
|
syntax(err) /* report syntax error and quit */ |
| 380 |
|
char *err; |
| 381 |
|
{ |
| 382 |
|
register int i; |
| 383 |
|
|
| 384 |
|
eputs(linbuf); |
| 385 |
< |
if (linbuf[0] == '\0' || linbuf[strlen(linbuf)-1] != '\n') |
| 385 |
> |
if (linbuf[strlen(linbuf)-1] != '\n') |
| 386 |
|
eputs("\n"); |
| 387 |
|
for (i = 0; i < linepos-1; i++) |
| 388 |
|
eputs(linbuf[i] == '\t' ? "\t" : " "); |
| 389 |
|
eputs("^ "); |
| 390 |
< |
if (infile != NULL) { |
| 391 |
< |
eputs(infile); |
| 390 |
> |
if (infile != NULL || lineno != 0) { |
| 391 |
> |
eputs("\n"); |
| 392 |
> |
if (infile != NULL) eputs(infile); |
| 393 |
> |
if (lineno != 0) { |
| 394 |
> |
eputs(infile != NULL ? ", line " : "line "); |
| 395 |
> |
eputs(ltoa((long)lineno)); |
| 396 |
> |
} |
| 397 |
|
eputs(": "); |
| 398 |
|
} |
| 399 |
|
eputs(err); |
| 555 |
|
getE4() /* E4 -> ADDOP E5 */ |
| 556 |
|
/* E5 */ |
| 557 |
|
{ |
| 558 |
< |
register EPNODE *ep1; |
| 558 |
> |
register EPNODE *ep1, *ep2; |
| 559 |
|
|
| 560 |
|
if (nextc == '-') { |
| 561 |
|
scan(); |
| 562 |
< |
ep1 = newnode(); |
| 563 |
< |
#ifndef RCONST |
| 564 |
< |
if (isdecimal(nextc)) { |
| 565 |
< |
ep1->type = NUM; |
| 528 |
< |
ep1->v.num = -getnum(); |
| 529 |
< |
return(ep1); |
| 562 |
> |
ep2 = getE5(); |
| 563 |
> |
if (ep2->type == NUM) { |
| 564 |
> |
ep2->v.num = -ep2->v.num; |
| 565 |
> |
return(ep2); |
| 566 |
|
} |
| 567 |
< |
#endif |
| 567 |
> |
ep1 = newnode(); |
| 568 |
|
ep1->type = UMINUS; |
| 569 |
< |
addekid(ep1, getE5()); |
| 534 |
< |
#ifdef RCONST |
| 535 |
< |
if (ep1->v.kid->type == NUM) |
| 536 |
< |
ep1 = rconst(ep1); |
| 537 |
< |
#endif |
| 569 |
> |
addekid(ep1, ep2); |
| 570 |
|
return(ep1); |
| 571 |
|
} |
| 572 |
|
if (nextc == '+') |