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.18 by greg, Sat Feb 22 02:07:21 2003 UTC vs.
Revision 2.22 by schorsch, Sat Jun 7 12:50:20 2003 UTC

# Line 17 | Line 17 | static const char      RCSid[] = "$Id$";
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  "calcomp.h"
# Line 98 | Line 40 | static double  eadd(), esubtr(), emult(), edivi(), epo
40   static double  ebotch();
41  
42   unsigned int  esupport =                /* what to support */
43 <                E_VARIABLE | E_FUNCTION | E_REDEFW;
43 >                E_VARIABLE | E_FUNCTION ;
44  
45   int  nextc;                             /* lookahead character */
46  
# Line 336 | Line 278 | EPNODE *ep;
278      if (!finite(d))
279          errno = EDOM;
280   #endif
281 <    if (errno) {
281 >    if (errno == EDOM || errno == ERANGE) {
282          wputs("Illegal power\n");
283          return(0.0);
284      }
# Line 350 | Line 292 | EPNODE *ep;
292   {
293      eputs("Bad expression!\n");
294      quit(1);
295 +        return 0.0; /* pro forma return */
296   }
297  
298  
# Line 703 | Line 646 | getE5()                                /* E5 -> (E1) */
646                                  /*       FUNC(E1,..) */
647                                  /*       ARG */
648   {
649 <    int  i;
650 <    char  *nam;
651 <    register EPNODE  *ep1, *ep2;
649 >        int      i;
650 >        char  *nam;
651 >        register EPNODE  *ep1, *ep2;
652  
653 <    if (nextc == '(') {
654 <        scan();
655 <        ep1 = getE1();
656 <        if (nextc != ')')
657 <            syntax("')' expected");
658 <        scan();
659 <        return(ep1);
660 <    }
653 >        if (nextc == '(') {
654 >                scan();
655 >                ep1 = getE1();
656 >                if (nextc != ')')
657 >                        syntax("')' expected");
658 >                scan();
659 >                return(ep1);
660 >        }
661  
662 <    if (esupport&E_INCHAN && nextc == '$') {
663 <        scan();
664 <        ep1 = newnode();
665 <        ep1->type = CHAN;
666 <        ep1->v.chan = getinum();
667 <        return(ep1);
668 <    }
662 >        if (esupport&E_INCHAN && nextc == '$') {
663 >                scan();
664 >                ep1 = newnode();
665 >                ep1->type = CHAN;
666 >                ep1->v.chan = getinum();
667 >                return(ep1);
668 >        }
669  
670 <  if (esupport&(E_VARIABLE|E_FUNCTION) &&
671 <                (isalpha(nextc) || nextc == CNTXMARK)) {
672 <      nam = getname();
673 <      ep1 = NULL;
674 <      if ((esupport&(E_VARIABLE|E_FUNCTION)) == (E_VARIABLE|E_FUNCTION)
675 <                        && curfunc != NULL)
676 <            for (i = 1, ep2 = curfunc->v.kid->sibling;
677 <                                ep2 != NULL; i++, ep2 = ep2->sibling)
678 <                if (!strcmp(ep2->v.name, nam)) {
679 <                    ep1 = newnode();
680 <                    ep1->type = ARG;
681 <                    ep1->v.chan = i;
682 <                    break;
670 >        if (esupport&(E_VARIABLE|E_FUNCTION) &&
671 >                        (isalpha(nextc) || nextc == CNTXMARK)) {
672 >                nam = getname();
673 >                ep1 = NULL;
674 >                if ((esupport&(E_VARIABLE|E_FUNCTION)) == (E_VARIABLE|E_FUNCTION)
675 >                                && curfunc != NULL)
676 >                        for (i = 1, ep2 = curfunc->v.kid->sibling;
677 >                                        ep2 != NULL; i++, ep2 = ep2->sibling)
678 >                                if (!strcmp(ep2->v.name, nam)) {
679 >                                        ep1 = newnode();
680 >                                        ep1->type = ARG;
681 >                                        ep1->v.chan = i;
682 >                                        break;
683 >                                }
684 >                if (ep1 == NULL) {
685 >                        ep1 = newnode();
686 >                        ep1->type = VAR;
687 >                        ep1->v.ln = varinsert(nam);
688                  }
689 <        if (ep1 == NULL) {
690 <            ep1 = newnode();
691 <            ep1->type = VAR;
692 <            ep1->v.ln = varinsert(nam);
689 >                if (esupport&E_FUNCTION && nextc == '(') {
690 >                        ep2 = newnode();
691 >                        ep2->type = FUNC;
692 >                        addekid(ep2, ep1);
693 >                        ep1 = ep2;
694 >                        do {
695 >                                scan();
696 >                                addekid(ep1, getE1());
697 >                        } while (nextc == ',');
698 >                        if (nextc != ')')
699 >                                syntax("')' expected");
700 >                        scan();
701 >                } else if (!(esupport&E_VARIABLE))
702 >                        syntax("'(' expected");
703 >                if (esupport&E_RCONST && isconstvar(ep1))
704 >                        ep1 = rconst(ep1);
705 >                return(ep1);
706          }
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    }
707  
708 <    if (isdecimal(nextc)) {
709 <        ep1 = newnode();
710 <        ep1->type = NUM;
711 <        ep1->v.num = getnum();
712 <        return(ep1);
713 <    }
714 <    syntax("unexpected character");
708 >        if (isdecimal(nextc)) {
709 >                ep1 = newnode();
710 >                ep1->type = NUM;
711 >                ep1->v.num = getnum();
712 >                return(ep1);
713 >        }
714 >        syntax("unexpected character");
715 >        return NULL; /* pro forma return */
716   }
717  
718  
# Line 782 | Line 726 | register EPNODE         *epar;
726      ep->type = NUM;
727      errno = 0;
728      ep->v.num = evalue(epar);
729 <    if (errno)
729 >    if (errno == EDOM || errno == ERANGE)
730          syntax("bad constant expression");
731      epfree(epar);
732  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines