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

Comparing ray/src/common/calfunc.c (file contents):
Revision 2.27 by greg, Mon Sep 27 23:30:53 2021 UTC vs.
Revision 2.32 by greg, Mon Sep 16 17:31:14 2024 UTC

# Line 15 | Line 15 | static const char      RCSid[] = "$Id$";
15   #include  <stdio.h>
16   #include  <string.h>
17   #include  <errno.h>
18 + #include  <stdlib.h>
19   #include  <math.h>
20  
21   #include  "rterror.h"
# Line 22 | Line 23 | static const char      RCSid[] = "$Id$";
23  
24                                  /* bits in argument flag (better be right!) */
25   #define  AFLAGSIZ       (8*sizeof(unsigned long))
26 < #define  ALISTSIZ       8       /* maximum saved argument list */
26 > #define  ALISTSIZ       10      /* maximum saved argument list */
27  
28   typedef struct activation {
29      char  *name;                /* function name */
# Line 50 | Line 51 | static double  l_asin(char *), l_acos(char *), l_atan(
51   static double  l_exp(char *), l_log(char *), l_log10(char *);
52  
53                          /* functions must be listed alphabetically */
54 < static LIBR  library[MAXLIB] = {
54 > static ELIBR  library[MAXLIB] = {
55      { "acos", 1, ':', l_acos },
56      { "asin", 1, ':', l_asin },
57      { "atan", 1, ':', l_atan },
# Line 73 | Line 74 | static LIBR  library[MAXLIB] = {
74  
75   static int  libsize = 18;
76  
77 < #define  resolve(ep)    ((ep)->type==VAR?(ep)->v.ln:argf((ep)->v.chan))
77 > #define  resolve(ep)    ((ep)->type==VAR?(ep)->v.ln:eargf((ep)->v.chan))
78  
79  
80   int
# Line 81 | Line 82 | fundefined(                    /* return # of req'd arguments for funct
82          char  *fname
83   )
84   {
85 <    LIBR  *lp;
85 >    ELIBR  *lp;
86      VARDEF  *vp;
87  
88      if ((vp = varlookup(fname)) != NULL && vp->def != NULL
89                  && vp->def->v.kid->type == FUNC)
90          return(nekids(vp->def->v.kid) - 1);
91 <    lp = vp != NULL ? vp->lib : liblookup(fname);
91 >    lp = vp != NULL ? vp->lib : eliblookup(fname);
92      if (lp == NULL)
93          return(0);
94      return(lp->nargs);
# Line 139 | Line 140 | funset(                                /* set a library function */
140   {
141      int  oldlibsize = libsize;
142      char *cp;
143 <    LIBR  *lp;
143 >    ELIBR  *lp;
144                                                  /* check for context */
145      for (cp = fname; *cp; cp++)
146          ;
# Line 149 | Line 150 | funset(                                /* set a library function */
150          *--cp = '\0';
151          if (cp == fname) return;
152      }
153 <    if ((lp = liblookup(fname)) == NULL) {      /* insert */
153 >    if ((lp = eliblookup(fname)) == NULL) {     /* insert */
154          if (fptr == NULL)
155                  return;                         /* nothing! */
156          if (libsize >= MAXLIB) {
# Line 176 | Line 177 | funset(                                /* set a library function */
177          lp[0].f = fptr;
178      }
179      if (libsize != oldlibsize)
180 <        libupdate(fname);                       /* relink library */
180 >        elibupdate(fname);                      /* relink library */
181   }
182  
183  
# Line 200 | Line 201 | double
201   argument(int n)                 /* return nth argument for active function */
202   {
203      ACTIVATION  *actp = curact;
204 <    EPNODE  *ep = NULL;
204 >    EPNODE  *ep;
205      double  aval;
206  
206    if (!n)                                     /* asking for # arguments? */
207        return((double)nargum());
208
207      if (!actp | (--n < 0)) {
208          eputs("Bad call to argument!\n");
209          quit(1);
# Line 230 | Line 228 | argument(int n)                        /* return nth argument for active fu
228  
229  
230   VARDEF *
231 < argf(int n)                     /* return function def for nth argument */
231 > eargf(int n)                    /* return function def for nth argument */
232   {
233      ACTIVATION  *actp;
234      EPNODE  *ep;
# Line 256 | Line 254 | argf(int n)                    /* return function def for nth argument
254  
255          n = ep->v.chan;                         /* try previous context */
256      }
257 <    eputs("Bad call to argf!\n");
257 >    eputs("Bad call to eargf!\n");
258      quit(1);
259  
260   badarg:
# Line 268 | Line 266 | badarg:
266  
267  
268   char *
269 < argfun(int n)                   /* return function name for nth argument */
269 > eargfun(int n)                  /* return function name for nth argument */
270   {
271 <    return(argf(n)->name);
271 >    return(eargf(n)->name);
272   }
273  
274  
# Line 300 | Line 298 | efunc(EPNODE *ep)                      /* evaluate a function */
298   }
299  
300  
301 < LIBR *
302 < liblookup(char *fname)          /* look up a library function */
301 > double
302 > eargument(                              /* evaluate an argument */
303 >    EPNODE      *ep
304 > )
305   {
306 +    if ((ep->v.chan <= AFLAGSIZ) & curact->an >> (ep->v.chan-1))
307 +        return(curact->ap[ep->v.chan-1]);
308 +
309 +    return(argument(ep->v.chan));
310 + }
311 +
312 +
313 + ELIBR *
314 + eliblookup(char *fname)         /* look up a library function */
315 + {
316      int  upper, lower;
317      int  cm, i;
318  
# Line 334 | Line 344 | libfunc(                               /* execute library function */
344          VARDEF  *vp
345   )
346   {
347 <    LIBR  *lp;
347 >    ELIBR  *lp;
348      double  d;
349      int  lasterrno;
350  
351      if (vp != NULL)
352          lp = vp->lib;
353      else
354 <        lp = liblookup(fname);
354 >        lp = eliblookup(fname);
355      if (lp == NULL) {
356          eputs(fname);
357          eputs(": undefined function\n");
# Line 358 | Line 368 | libfunc(                               /* execute library function */
368              errno = ERANGE;
369      }
370   #endif
371 <    if (errno == EDOM || errno == ERANGE) {
371 >    if ((errno == EDOM) | (errno == ERANGE)) {
372          wputs(fname);
373          if (errno == EDOM)
374                  wputs(": domain error\n");
# Line 396 | Line 406 | l_select(char *nm)     /* return argument #(A1+1) */
406          double  a1 = argument(1);
407          int  n = (int)(a1 + .5);
408  
409 <        if (a1 < -.5 || n >= narg) {
409 >        if ((a1 < -.5) | (n >= narg)) {
410                  errno = EDOM;
411                  return(0.0);
412          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines