ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/calexpr.c
(Generate patch)

Comparing ray/src/common/calexpr.c (file contents):
Revision 2.21 by greg, Mon Jun 2 18:13:54 2003 UTC vs.
Revision 2.24 by schorsch, Thu Jul 17 09:21:29 2003 UTC

# Line 20 | Line 20 | static const char      RCSid[] = "$Id$";
20   #include "copyright.h"
21  
22   #include  <stdio.h>
23 <
23 > #include  <string.h>
24   #include  <ctype.h>
25
25   #include  <errno.h>
27
26   #include  <math.h>
29
27   #include  <stdlib.h>
28  
29 + #include  "rterror.h"
30   #include  "calcomp.h"
31  
32   #define  MAXLINE        256             /* maximum line length */
# Line 37 | Line 35 | static const char      RCSid[] = "$Id$";
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 ;
# Line 295 | Line 295 | EPNODE *ep;
295   {
296      eputs("Bad expression!\n");
297      quit(1);
298 +        return 0.0; /* pro forma return */
299   }
300  
301  
# Line 475 | Line 476 | EPNODE *ekid;
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 */
# Line 508 | Line 509 | double
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          }
# Line 648 | Line 649 | getE5()                                /* E5 -> (E1) */
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          }
691        if (esupport&E_FUNCTION && nextc == '(') {
692            ep2 = newnode();
693            ep2->type = FUNC;
694            addekid(ep2, ep1);
695            ep1 = ep2;
696            do {
697                scan();
698                addekid(ep1, getE1());
699            } while (nextc == ',');
700            if (nextc != ')')
701                syntax("')' expected");
702            scan();
703        } else if (!(esupport&E_VARIABLE))
704            syntax("'(' expected");
705        if (esupport&E_RCONST && isconstvar(ep1))
706            ep1 = rconst(ep1);
707        return(ep1);
708    }
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines