| 1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 4 |
> |
static char SCCSid[] = "$SunId$ SGI"; |
| 5 |
|
#endif |
| 6 |
|
|
| 7 |
|
/* |
| 34 |
|
|
| 35 |
|
#define isdecimal(c) (isdigit(c) || (c) == '.') |
| 36 |
|
|
| 37 |
< |
#ifndef atof |
| 38 |
< |
extern double atof(); |
| 39 |
< |
#endif |
| 40 |
< |
extern char *fgets(), *savestr(); |
| 37 |
> |
extern char *savestr(); |
| 38 |
|
extern char *emalloc(), *ecalloc(); |
| 39 |
|
extern EPNODE *curfunc; |
| 40 |
|
extern double efunc(), evariable(); |
| 41 |
< |
static double euminus(), echannel(), eargument(), enumber(); |
| 41 |
> |
static double euminus(), eargument(), enumber(); |
| 42 |
> |
#ifdef INCHAN |
| 43 |
> |
static double echannel(); |
| 44 |
> |
#endif |
| 45 |
|
static double eadd(), esubtr(), emult(), edivi(), epow(); |
| 46 |
|
static double ebotch(); |
| 47 |
|
|
| 48 |
+ |
#ifdef DCL_ATOF |
| 49 |
+ |
extern double atof(); |
| 50 |
+ |
#endif |
| 51 |
+ |
|
| 52 |
|
int nextc; /* lookahead character */ |
| 53 |
|
|
| 54 |
|
double (*eoper[])() = { /* expression operations */ |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
|
| 132 |
+ |
epcmp(ep1, ep2) /* compare two expressions for equivalence */ |
| 133 |
+ |
register EPNODE *ep1, *ep2; |
| 134 |
+ |
{ |
| 135 |
+ |
double d; |
| 136 |
+ |
|
| 137 |
+ |
if (ep1->type != ep2->type) |
| 138 |
+ |
return(1); |
| 139 |
+ |
|
| 140 |
+ |
switch (ep1->type) { |
| 141 |
+ |
|
| 142 |
+ |
case VAR: |
| 143 |
+ |
return(ep1->v.ln != ep2->v.ln); |
| 144 |
+ |
|
| 145 |
+ |
case NUM: |
| 146 |
+ |
if (ep2->v.num == 0) |
| 147 |
+ |
return(ep1->v.num != 0); |
| 148 |
+ |
d = ep1->v.num / ep2->v.num; |
| 149 |
+ |
return(d > 1.000000000001 | d < 0.999999999999); |
| 150 |
+ |
|
| 151 |
+ |
case CHAN: |
| 152 |
+ |
case ARG: |
| 153 |
+ |
return(ep1->v.chan != ep2->v.chan); |
| 154 |
+ |
|
| 155 |
+ |
case '=': |
| 156 |
+ |
case ':': |
| 157 |
+ |
return(epcmp(ep1->v.kid->sibling, ep2->v.kid->sibling)); |
| 158 |
+ |
|
| 159 |
+ |
case TICK: |
| 160 |
+ |
case SYM: /* should never get this one */ |
| 161 |
+ |
return(0); |
| 162 |
+ |
|
| 163 |
+ |
default: |
| 164 |
+ |
ep1 = ep1->v.kid; |
| 165 |
+ |
ep2 = ep2->v.kid; |
| 166 |
+ |
while (ep1 != NULL) { |
| 167 |
+ |
if (ep2 == NULL) |
| 168 |
+ |
return(1); |
| 169 |
+ |
if (epcmp(ep1, ep2)) |
| 170 |
+ |
return(1); |
| 171 |
+ |
ep1 = ep1->sibling; |
| 172 |
+ |
ep2 = ep2->sibling; |
| 173 |
+ |
} |
| 174 |
+ |
return(ep2 != NULL); |
| 175 |
+ |
} |
| 176 |
+ |
} |
| 177 |
+ |
|
| 178 |
+ |
|
| 179 |
|
epfree(epar) /* free a parse tree */ |
| 180 |
|
register EPNODE *epar; |
| 181 |
|
{ |
| 200 |
|
break; |
| 201 |
|
|
| 202 |
|
default: |
| 203 |
< |
for (ep = epar->v.kid; ep != NULL; ep = ep->sibling) |
| 203 |
> |
while ((ep = epar->v.kid) != NULL) { |
| 204 |
> |
epar->v.kid = ep->sibling; |
| 205 |
|
epfree(ep); |
| 206 |
+ |
} |
| 207 |
|
break; |
| 208 |
|
|
| 209 |
|
} |
| 425 |
|
|
| 426 |
|
|
| 427 |
|
char * |
| 428 |
< |
ltoa(l) /* convert long to ascii */ |
| 428 |
> |
long2ascii(l) /* convert long to ascii */ |
| 429 |
|
long l; |
| 430 |
|
{ |
| 431 |
|
static char buf[16]; |
| 459 |
|
if (infile != NULL) eputs(infile); |
| 460 |
|
if (lineno != 0) { |
| 461 |
|
eputs(infile != NULL ? ", line " : "line "); |
| 462 |
< |
eputs(ltoa((long)lineno)); |
| 462 |
> |
eputs(long2ascii((long)lineno)); |
| 463 |
|
} |
| 464 |
|
eputs(":\n"); |
| 465 |
|
} |
| 539 |
|
if (lnext == '.' && i < MAXWORD) { |
| 540 |
|
str[i++] = lnext; |
| 541 |
|
lnext = scan(); |
| 542 |
+ |
if (i == 1 && !isdigit(lnext)) |
| 543 |
+ |
syntax("badly formed number"); |
| 544 |
|
while (isdigit(lnext) && i < MAXWORD) { |
| 545 |
|
str[i++] = lnext; |
| 546 |
|
lnext = scan(); |
| 547 |
|
} |
| 548 |
|
} |
| 549 |
< |
if ((lnext == 'e' || lnext == 'E') && i < MAXWORD) { |
| 549 |
> |
if ((lnext == 'e' | lnext == 'E') && i < MAXWORD) { |
| 550 |
|
str[i++] = lnext; |
| 551 |
|
lnext = scan(); |
| 552 |
< |
if ((lnext == '-' || lnext == '+') && i < MAXWORD) { |
| 552 |
> |
if ((lnext == '-' | lnext == '+') && i < MAXWORD) { |
| 553 |
|
str[i++] = lnext; |
| 554 |
|
lnext = scan(); |
| 555 |
|
} |
| 556 |
+ |
if (!isdigit(lnext)) |
| 557 |
+ |
syntax("missing exponent"); |
| 558 |
|
while (isdigit(lnext) && i < MAXWORD) { |
| 559 |
|
str[i++] = lnext; |
| 560 |
|
lnext = scan(); |