| 17 |
|
* 2/19/03 Eliminated conditional compiles in favor of esupport extern. |
| 18 |
|
*/ |
| 19 |
|
|
| 20 |
< |
/* ==================================================================== |
| 21 |
< |
* The Radiance Software License, Version 1.0 |
| 22 |
< |
* |
| 23 |
< |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
| 24 |
< |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
| 25 |
< |
* |
| 26 |
< |
* Redistribution and use in source and binary forms, with or without |
| 27 |
< |
* modification, are permitted provided that the following conditions |
| 28 |
< |
* are met: |
| 29 |
< |
* |
| 30 |
< |
* 1. Redistributions of source code must retain the above copyright |
| 31 |
< |
* notice, this list of conditions and the following disclaimer. |
| 32 |
< |
* |
| 33 |
< |
* 2. Redistributions in binary form must reproduce the above copyright |
| 34 |
< |
* notice, this list of conditions and the following disclaimer in |
| 35 |
< |
* the documentation and/or other materials provided with the |
| 36 |
< |
* distribution. |
| 37 |
< |
* |
| 38 |
< |
* 3. The end-user documentation included with the redistribution, |
| 39 |
< |
* if any, must include the following acknowledgment: |
| 40 |
< |
* "This product includes Radiance software |
| 41 |
< |
* (http://radsite.lbl.gov/) |
| 42 |
< |
* developed by the Lawrence Berkeley National Laboratory |
| 43 |
< |
* (http://www.lbl.gov/)." |
| 44 |
< |
* Alternately, this acknowledgment may appear in the software itself, |
| 45 |
< |
* if and wherever such third-party acknowledgments normally appear. |
| 46 |
< |
* |
| 47 |
< |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
| 48 |
< |
* and "The Regents of the University of California" must |
| 49 |
< |
* not be used to endorse or promote products derived from this |
| 50 |
< |
* software without prior written permission. For written |
| 51 |
< |
* permission, please contact [email protected]. |
| 52 |
< |
* |
| 53 |
< |
* 5. Products derived from this software may not be called "Radiance", |
| 54 |
< |
* nor may "Radiance" appear in their name, without prior written |
| 55 |
< |
* permission of Lawrence Berkeley National Laboratory. |
| 56 |
< |
* |
| 57 |
< |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
| 58 |
< |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 59 |
< |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 60 |
< |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
| 61 |
< |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 62 |
< |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 63 |
< |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 64 |
< |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 65 |
< |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 66 |
< |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 67 |
< |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 68 |
< |
* SUCH DAMAGE. |
| 69 |
< |
* ==================================================================== |
| 70 |
< |
* |
| 71 |
< |
* This software consists of voluntary contributions made by many |
| 72 |
< |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
| 73 |
< |
* information on Lawrence Berkeley National Laboratory, please see |
| 74 |
< |
* <http://www.lbl.gov/>. |
| 75 |
< |
*/ |
| 20 |
> |
#include "copyright.h" |
| 21 |
|
|
| 22 |
|
#include <stdio.h> |
| 23 |
< |
|
| 23 |
> |
#include <string.h> |
| 24 |
|
#include <ctype.h> |
| 80 |
– |
|
| 25 |
|
#include <errno.h> |
| 82 |
– |
|
| 26 |
|
#include <math.h> |
| 84 |
– |
|
| 27 |
|
#include <stdlib.h> |
| 28 |
|
|
| 29 |
+ |
#include "rterror.h" |
| 30 |
|
#include "calcomp.h" |
| 31 |
|
|
| 32 |
|
#define MAXLINE 256 /* maximum line length */ |
| 35 |
|
|
| 36 |
|
#define isdecimal(c) (isdigit(c) || (c) == '.') |
| 37 |
|
|
| 38 |
< |
static double euminus(), eargument(), enumber(); |
| 39 |
< |
static double echannel(); |
| 40 |
< |
static double eadd(), esubtr(), emult(), edivi(), epow(); |
| 41 |
< |
static double ebotch(); |
| 38 |
> |
static double euminus(EPNODE *), eargument(EPNODE *), enumber(EPNODE *); |
| 39 |
> |
static double echannel(EPNODE *); |
| 40 |
> |
static double eadd(EPNODE *), esubtr(EPNODE *), |
| 41 |
> |
emult(EPNODE *), edivi(EPNODE *), |
| 42 |
> |
epow(EPNODE *); |
| 43 |
> |
static double ebotch(EPNODE *); |
| 44 |
|
|
| 45 |
|
unsigned int esupport = /* what to support */ |
| 46 |
< |
E_VARIABLE | E_FUNCTION | E_REDEFW; |
| 46 |
> |
E_VARIABLE | E_FUNCTION ; |
| 47 |
|
|
| 48 |
|
int nextc; /* lookahead character */ |
| 49 |
|
|
| 281 |
|
if (!finite(d)) |
| 282 |
|
errno = EDOM; |
| 283 |
|
#endif |
| 284 |
< |
if (errno) { |
| 284 |
> |
if (errno == EDOM || errno == ERANGE) { |
| 285 |
|
wputs("Illegal power\n"); |
| 286 |
|
return(0.0); |
| 287 |
|
} |
| 295 |
|
{ |
| 296 |
|
eputs("Bad expression!\n"); |
| 297 |
|
quit(1); |
| 298 |
+ |
return 0.0; /* pro forma return */ |
| 299 |
|
} |
| 300 |
|
|
| 301 |
|
|
| 476 |
|
char * |
| 477 |
|
getname() /* scan an identifier */ |
| 478 |
|
{ |
| 479 |
< |
static char str[MAXWORD+1]; |
| 479 |
> |
static char str[RMAXWORD+1]; |
| 480 |
|
register int i, lnext; |
| 481 |
|
|
| 482 |
|
lnext = nextc; |
| 483 |
< |
for (i = 0; i < MAXWORD && isid(lnext); i++, lnext = scan()) |
| 483 |
> |
for (i = 0; i < RMAXWORD && isid(lnext); i++, lnext = scan()) |
| 484 |
|
str[i] = lnext; |
| 485 |
|
str[i] = '\0'; |
| 486 |
|
while (isid(lnext)) /* skip rest of name */ |
| 509 |
|
getnum() /* scan a positive float */ |
| 510 |
|
{ |
| 511 |
|
register int i, lnext; |
| 512 |
< |
char str[MAXWORD+1]; |
| 512 |
> |
char str[RMAXWORD+1]; |
| 513 |
|
|
| 514 |
|
i = 0; |
| 515 |
|
lnext = nextc; |
| 516 |
< |
while (isdigit(lnext) && i < MAXWORD) { |
| 516 |
> |
while (isdigit(lnext) && i < RMAXWORD) { |
| 517 |
|
str[i++] = lnext; |
| 518 |
|
lnext = scan(); |
| 519 |
|
} |
| 520 |
< |
if (lnext == '.' && i < MAXWORD) { |
| 520 |
> |
if (lnext == '.' && i < RMAXWORD) { |
| 521 |
|
str[i++] = lnext; |
| 522 |
|
lnext = scan(); |
| 523 |
|
if (i == 1 && !isdigit(lnext)) |
| 524 |
|
syntax("badly formed number"); |
| 525 |
< |
while (isdigit(lnext) && i < MAXWORD) { |
| 525 |
> |
while (isdigit(lnext) && i < RMAXWORD) { |
| 526 |
|
str[i++] = lnext; |
| 527 |
|
lnext = scan(); |
| 528 |
|
} |
| 529 |
|
} |
| 530 |
< |
if ((lnext == 'e' | lnext == 'E') && i < MAXWORD) { |
| 530 |
> |
if ((lnext == 'e' | lnext == 'E') && i < RMAXWORD) { |
| 531 |
|
str[i++] = lnext; |
| 532 |
|
lnext = scan(); |
| 533 |
< |
if ((lnext == '-' | lnext == '+') && i < MAXWORD) { |
| 533 |
> |
if ((lnext == '-' | lnext == '+') && i < RMAXWORD) { |
| 534 |
|
str[i++] = lnext; |
| 535 |
|
lnext = scan(); |
| 536 |
|
} |
| 537 |
|
if (!isdigit(lnext)) |
| 538 |
|
syntax("missing exponent"); |
| 539 |
< |
while (isdigit(lnext) && i < MAXWORD) { |
| 539 |
> |
while (isdigit(lnext) && i < RMAXWORD) { |
| 540 |
|
str[i++] = lnext; |
| 541 |
|
lnext = scan(); |
| 542 |
|
} |
| 649 |
|
/* FUNC(E1,..) */ |
| 650 |
|
/* ARG */ |
| 651 |
|
{ |
| 652 |
< |
int i; |
| 653 |
< |
char *nam; |
| 654 |
< |
register EPNODE *ep1, *ep2; |
| 652 |
> |
int i; |
| 653 |
> |
char *nam; |
| 654 |
> |
register EPNODE *ep1, *ep2; |
| 655 |
|
|
| 656 |
< |
if (nextc == '(') { |
| 657 |
< |
scan(); |
| 658 |
< |
ep1 = getE1(); |
| 659 |
< |
if (nextc != ')') |
| 660 |
< |
syntax("')' expected"); |
| 661 |
< |
scan(); |
| 662 |
< |
return(ep1); |
| 663 |
< |
} |
| 656 |
> |
if (nextc == '(') { |
| 657 |
> |
scan(); |
| 658 |
> |
ep1 = getE1(); |
| 659 |
> |
if (nextc != ')') |
| 660 |
> |
syntax("')' expected"); |
| 661 |
> |
scan(); |
| 662 |
> |
return(ep1); |
| 663 |
> |
} |
| 664 |
|
|
| 665 |
< |
if (esupport&E_INCHAN && nextc == '$') { |
| 666 |
< |
scan(); |
| 667 |
< |
ep1 = newnode(); |
| 668 |
< |
ep1->type = CHAN; |
| 669 |
< |
ep1->v.chan = getinum(); |
| 670 |
< |
return(ep1); |
| 671 |
< |
} |
| 665 |
> |
if (esupport&E_INCHAN && nextc == '$') { |
| 666 |
> |
scan(); |
| 667 |
> |
ep1 = newnode(); |
| 668 |
> |
ep1->type = CHAN; |
| 669 |
> |
ep1->v.chan = getinum(); |
| 670 |
> |
return(ep1); |
| 671 |
> |
} |
| 672 |
|
|
| 673 |
< |
if (esupport&(E_VARIABLE|E_FUNCTION) && |
| 674 |
< |
(isalpha(nextc) || nextc == CNTXMARK)) { |
| 675 |
< |
nam = getname(); |
| 676 |
< |
ep1 = NULL; |
| 677 |
< |
if ((esupport&(E_VARIABLE|E_FUNCTION)) == (E_VARIABLE|E_FUNCTION) |
| 678 |
< |
&& curfunc != NULL) |
| 679 |
< |
for (i = 1, ep2 = curfunc->v.kid->sibling; |
| 680 |
< |
ep2 != NULL; i++, ep2 = ep2->sibling) |
| 681 |
< |
if (!strcmp(ep2->v.name, nam)) { |
| 682 |
< |
ep1 = newnode(); |
| 683 |
< |
ep1->type = ARG; |
| 684 |
< |
ep1->v.chan = i; |
| 685 |
< |
break; |
| 673 |
> |
if (esupport&(E_VARIABLE|E_FUNCTION) && |
| 674 |
> |
(isalpha(nextc) || nextc == CNTXMARK)) { |
| 675 |
> |
nam = getname(); |
| 676 |
> |
ep1 = NULL; |
| 677 |
> |
if ((esupport&(E_VARIABLE|E_FUNCTION)) == (E_VARIABLE|E_FUNCTION) |
| 678 |
> |
&& curfunc != NULL) |
| 679 |
> |
for (i = 1, ep2 = curfunc->v.kid->sibling; |
| 680 |
> |
ep2 != NULL; i++, ep2 = ep2->sibling) |
| 681 |
> |
if (!strcmp(ep2->v.name, nam)) { |
| 682 |
> |
ep1 = newnode(); |
| 683 |
> |
ep1->type = ARG; |
| 684 |
> |
ep1->v.chan = i; |
| 685 |
> |
break; |
| 686 |
> |
} |
| 687 |
> |
if (ep1 == NULL) { |
| 688 |
> |
ep1 = newnode(); |
| 689 |
> |
ep1->type = VAR; |
| 690 |
> |
ep1->v.ln = varinsert(nam); |
| 691 |
|
} |
| 692 |
< |
if (ep1 == NULL) { |
| 693 |
< |
ep1 = newnode(); |
| 694 |
< |
ep1->type = VAR; |
| 695 |
< |
ep1->v.ln = varinsert(nam); |
| 692 |
> |
if (esupport&E_FUNCTION && nextc == '(') { |
| 693 |
> |
ep2 = newnode(); |
| 694 |
> |
ep2->type = FUNC; |
| 695 |
> |
addekid(ep2, ep1); |
| 696 |
> |
ep1 = ep2; |
| 697 |
> |
do { |
| 698 |
> |
scan(); |
| 699 |
> |
addekid(ep1, getE1()); |
| 700 |
> |
} while (nextc == ','); |
| 701 |
> |
if (nextc != ')') |
| 702 |
> |
syntax("')' expected"); |
| 703 |
> |
scan(); |
| 704 |
> |
} else if (!(esupport&E_VARIABLE)) |
| 705 |
> |
syntax("'(' expected"); |
| 706 |
> |
if (esupport&E_RCONST && isconstvar(ep1)) |
| 707 |
> |
ep1 = rconst(ep1); |
| 708 |
> |
return(ep1); |
| 709 |
|
} |
| 746 |
– |
if (esupport&E_FUNCTION && nextc == '(') { |
| 747 |
– |
ep2 = newnode(); |
| 748 |
– |
ep2->type = FUNC; |
| 749 |
– |
addekid(ep2, ep1); |
| 750 |
– |
ep1 = ep2; |
| 751 |
– |
do { |
| 752 |
– |
scan(); |
| 753 |
– |
addekid(ep1, getE1()); |
| 754 |
– |
} while (nextc == ','); |
| 755 |
– |
if (nextc != ')') |
| 756 |
– |
syntax("')' expected"); |
| 757 |
– |
scan(); |
| 758 |
– |
} else if (!(esupport&E_VARIABLE)) |
| 759 |
– |
syntax("'(' expected"); |
| 760 |
– |
if (esupport&E_RCONST && isconstvar(ep1)) |
| 761 |
– |
ep1 = rconst(ep1); |
| 762 |
– |
return(ep1); |
| 763 |
– |
} |
| 710 |
|
|
| 711 |
< |
if (isdecimal(nextc)) { |
| 712 |
< |
ep1 = newnode(); |
| 713 |
< |
ep1->type = NUM; |
| 714 |
< |
ep1->v.num = getnum(); |
| 715 |
< |
return(ep1); |
| 716 |
< |
} |
| 717 |
< |
syntax("unexpected character"); |
| 711 |
> |
if (isdecimal(nextc)) { |
| 712 |
> |
ep1 = newnode(); |
| 713 |
> |
ep1->type = NUM; |
| 714 |
> |
ep1->v.num = getnum(); |
| 715 |
> |
return(ep1); |
| 716 |
> |
} |
| 717 |
> |
syntax("unexpected character"); |
| 718 |
> |
return NULL; /* pro forma return */ |
| 719 |
|
} |
| 720 |
|
|
| 721 |
|
|
| 729 |
|
ep->type = NUM; |
| 730 |
|
errno = 0; |
| 731 |
|
ep->v.num = evalue(epar); |
| 732 |
< |
if (errno) |
| 732 |
> |
if (errno == EDOM || errno == ERANGE) |
| 733 |
|
syntax("bad constant expression"); |
| 734 |
|
epfree(epar); |
| 735 |
|
|
| 771 |
|
|
| 772 |
|
if (ep->type != VAR) |
| 773 |
|
return(0); |
| 774 |
< |
if ((dp = ep->v.ln->def) != NULL) |
| 774 |
> |
if ((dp = ep->v.ln->def) != NULL) { |
| 775 |
|
if (dp->v.kid->type == FUNC) |
| 776 |
|
return(dp->type == ':'); |
| 777 |
|
else |
| 778 |
|
return(0); /* don't identify masked library functions */ |
| 779 |
+ |
} |
| 780 |
|
if ((lp = ep->v.ln->lib) != NULL) |
| 781 |
|
return(lp->atyp == ':'); |
| 782 |
|
return(0); |