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 1.4 by greg, Tue Apr 23 15:44:39 1991 UTC vs.
Revision 2.3 by greg, Mon May 18 14:15:49 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 22 | Line 22 | static char SCCSid[] = "$SunId$ LBL";
22  
23   #include  "calcomp.h"
24  
25 <
25 >                                /* bits in argument flag (better be right!) */
26 > #define  AFLAGSIZ       (8*sizeof(unsigned long))
27   #define  ALISTSIZ       6       /* maximum saved argument list */
28  
29   typedef struct activation {
# Line 87 | Line 88 | static int  libsize = 5;
88  
89   extern char  *savestr(), *emalloc();
90  
90 extern LIBR  *liblookup();
91
91   extern VARDEF  *argf();
92  
93   #ifdef  VARIABLE
# Line 130 | Line 129 | double  *a;
129      act.name = fname;
130      act.prev = curact;
131      act.ap = a;
132 <    act.an = (1L<<n)-1;
132 >    if (n >= AFLAGSIZ)
133 >        act.an = ~0;
134 >    else
135 >        act.an = (1L<<n)-1;
136      act.fun = NULL;
137      curact = &act;
138  
# Line 153 | Line 155 | double  (*fptr)();
155   {
156      register LIBR  *lp;
157  
158 <    if ((lp = liblookup(fname)) == NULL) {
158 >    if ((lp = liblookup(fname)) == NULL) {      /* insert */
159          if (libsize >= MAXLIB) {
160              eputs("Too many library functons!\n");
161              quit(1);
# Line 168 | Line 170 | double  (*fptr)();
170                  break;
171          libsize++;
172      }
173 <    lp[0].fname = savestr(fname);
174 <    lp[0].nargs = nargs;
175 <    lp[0].atyp = assign;
176 <    lp[0].f = fptr;
173 >    if (fptr == NULL) {                         /* delete */
174 >        while (lp < &library[libsize-1]) {
175 >            lp[0].fname = lp[1].fname;
176 >            lp[0].nargs = lp[1].nargs;
177 >            lp[0].atyp = lp[1].atyp;
178 >            lp[0].f = lp[1].f;
179 >            lp++;
180 >        }
181 >        libsize--;
182 >    } else {                                    /* or assign */
183 >        lp[0].fname = fname;            /* string must be static! */
184 >        lp[0].nargs = nargs;
185 >        lp[0].atyp = assign;
186 >        lp[0].f = fptr;
187 >    }
188 >    libupdate(fname);                   /* relink library */
189   }
190  
191  
# Line 196 | Line 210 | argument(n)                    /* return nth argument for active functi
210   register int  n;
211   {
212      register ACTIVATION  *actp = curact;
213 <    EPNODE  *ep;
213 >    register EPNODE  *ep;
214      double  aval;
215  
216      if (actp == NULL || --n < 0) {
# Line 204 | Line 218 | register int  n;
218          quit(1);
219      }
220                                                  /* already computed? */
221 <    if (1L<<n & actp->an)
221 >    if (n < AFLAGSIZ && 1L<<n & actp->an)
222          return(actp->ap[n]);
223  
224      if (actp->fun == NULL || (ep = ekid(actp->fun, n+1)) == NULL) {
# Line 357 | Line 371 | register VARDEF  *vp;
371   static double
372   libfunc(fname, vp)                      /* execute library function */
373   char  *fname;
374 < register VARDEF  *vp;
374 > VARDEF  *vp;
375   {
376 <    VARDEF  dumdef;
376 >    register LIBR  *lp;
377      double  d;
378      int  lasterrno;
379  
380 <    if (vp == NULL) {
381 <        vp = &dumdef;
382 <        vp->lib = NULL;
383 <    }
384 <    if (((vp->lib == NULL || strcmp(fname, vp->lib->fname)) &&
371 <                                (vp->lib = liblookup(fname)) == NULL) ||
372 <                vp->lib->f == NULL) {
380 >    if (vp != NULL)
381 >        lp = vp->lib;
382 >    else
383 >        lp = liblookup(fname);
384 >    if (lp == NULL) {
385          eputs(fname);
386          eputs(": undefined function\n");
387          quit(1);
388      }
389      lasterrno = errno;
390      errno = 0;
391 <    d = (*vp->lib->f)();
391 >    d = (*lp->f)(lp->fname);
392   #ifdef  IEEE
393 <    if (!finite(d))
394 <        errno = EDOM;
393 >    if (errno == 0)
394 >        if (isnan(d))
395 >            errno = EDOM;
396 >        else if (isinf(d))
397 >            errno = ERANGE;
398   #endif
399      if (errno) {
400          wputs(fname);
401 <        wputs(": bad call\n");
401 >        if (errno == EDOM)
402 >                wputs(": domain error\n");
403 >        else if (errno == ERANGE)
404 >                wputs(": range error\n");
405 >        else
406 >                wputs(": error in call\n");
407          return(0.0);
408      }
409      errno = lasterrno;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines