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.8 by greg, Tue Jul 16 14:26:18 1991 UTC vs.
Revision 2.7 by greg, Sun Nov 22 17:29:46 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 20 | Line 20 | static char SCCSid[] = "$SunId$ LBL";
20  
21   #include  <errno.h>
22  
23 + #include  <math.h>
24 +
25   #include  "calcomp.h"
26  
27                                  /* bits in argument flag (better be right!) */
# Line 88 | Line 90 | static int  libsize = 5;
90  
91   extern char  *savestr(), *emalloc();
92  
91 extern LIBR  *liblookup();
92
93   extern VARDEF  *argf();
94  
95   #ifdef  VARIABLE
# Line 104 | Line 104 | int
104   fundefined(fname)               /* return # of arguments for function */
105   char  *fname;
106   {
107 <    LIBR  *lp;
107 >    register LIBR  *lp;
108      register VARDEF  *vp;
109  
110 <    if ((vp = varlookup(fname)) == NULL || vp->def == NULL
111 <                || vp->def->v.kid->type != FUNC)
112 <        if ((lp = liblookup(fname)) == NULL)
113 <            return(0);
114 <        else
115 <            return(lp->nargs);
116 <    else
110 >    if ((vp = varlookup(fname)) != NULL && vp->def != NULL
111 >                && vp->def->v.kid->type == FUNC)
112          return(nekids(vp->def->v.kid) - 1);
113 +    lp = vp != NULL ? vp->lib : liblookup(fname);
114 +    if (lp == NULL)
115 +        return(0);
116 +    return(lp->nargs);
117   }
118  
119  
# Line 155 | Line 154 | int  nargs;
154   int  assign;
155   double  (*fptr)();
156   {
157 +    int  oldlibsize = libsize;
158      register LIBR  *lp;
159  
160 <    if ((lp = liblookup(fname)) == NULL) {
160 >    if ((lp = liblookup(fname)) == NULL) {      /* insert */
161          if (libsize >= MAXLIB) {
162              eputs("Too many library functons!\n");
163              quit(1);
# Line 172 | Line 172 | double  (*fptr)();
172                  break;
173          libsize++;
174      }
175 <    lp[0].fname = fname;                /* must be static! */
176 <    lp[0].nargs = nargs;
177 <    lp[0].atyp = assign;
178 <    lp[0].f = fptr;
175 >    if (fptr == NULL) {                         /* delete */
176 >        while (lp < &library[libsize-1]) {
177 >            lp[0].fname = lp[1].fname;
178 >            lp[0].nargs = lp[1].nargs;
179 >            lp[0].atyp = lp[1].atyp;
180 >            lp[0].f = lp[1].f;
181 >            lp++;
182 >        }
183 >        libsize--;
184 >    } else {                                    /* or assign */
185 >        lp[0].fname = fname;            /* string must be static! */
186 >        lp[0].nargs = nargs;
187 >        lp[0].atyp = assign;
188 >        lp[0].f = fptr;
189 >    }
190 >    if (libsize != oldlibsize)
191 >        libupdate(fname);                       /* relink library */
192   }
193  
194  
# Line 327 | Line 340 | char  *fname;
340  
341  
342   #ifndef  VARIABLE
343 + static VARDEF  *varlist = NULL;         /* our list of dummy variables */
344 +
345 +
346   VARDEF *
347   varinsert(vname)                /* dummy variable insert */
348   char  *vname;
# Line 337 | Line 353 | char  *vname;
353      vp->name = savestr(vname);
354      vp->nlinks = 1;
355      vp->def = NULL;
356 <    vp->lib = NULL;
357 <    vp->next = NULL;
356 >    vp->lib = liblookup(vname);
357 >    vp->next = varlist;
358 >    varlist = vp;
359      return(vp);
360   }
361  
# Line 346 | Line 363 | char  *vname;
363   varfree(vp)                     /* free dummy variable */
364   register VARDEF  *vp;
365   {
366 +    register VARDEF  *vp2;
367 +
368 +    if (vp == varlist)
369 +        varlist = vp->next;
370 +    else {
371 +        for (vp2 = varlist; vp2->next != vp; vp2 = vp2->next)
372 +                ;
373 +        vp2->next = vp->next;
374 +    }
375      freestr(vp->name);
376      efree((char *)vp);
377   }
378 +
379 +
380 + libupdate(nm)                   /* update library */
381 + char  *nm;
382 + {
383 +    register VARDEF  *vp;
384 +
385 +    for (vp = varlist; vp != NULL; vp = vp->next)
386 +        vp->lib = liblookup(vp->name);
387 + }
388   #endif
389  
390  
# Line 361 | Line 397 | register VARDEF  *vp;
397   static double
398   libfunc(fname, vp)                      /* execute library function */
399   char  *fname;
400 < register VARDEF  *vp;
400 > VARDEF  *vp;
401   {
402 <    VARDEF  dumdef;
402 >    register LIBR  *lp;
403      double  d;
404      int  lasterrno;
405  
406 <    if (vp == NULL) {
407 <        vp = &dumdef;
408 <        vp->lib = NULL;
409 <    }
410 <    if (((vp->lib == NULL || strcmp(fname, vp->lib->fname)) &&
375 <                                (vp->lib = liblookup(fname)) == NULL) ||
376 <                vp->lib->f == NULL) {
406 >    if (vp != NULL)
407 >        lp = vp->lib;
408 >    else
409 >        lp = liblookup(fname);
410 >    if (lp == NULL) {
411          eputs(fname);
412          eputs(": undefined function\n");
413          quit(1);
414      }
415      lasterrno = errno;
416      errno = 0;
417 <    d = (*vp->lib->f)(vp->lib->fname);
417 >    d = (*lp->f)(lp->fname);
418   #ifdef  IEEE
419 <    if (!finite(d))
420 <        errno = EDOM;
419 >    if (errno == 0)
420 >        if (isnan(d))
421 >            errno = EDOM;
422 >        else if (isinf(d))
423 >            errno = ERANGE;
424   #endif
425      if (errno) {
426          wputs(fname);
# Line 435 | Line 472 | l_select()             /* return argument #(A1+1) */
472   static double
473   l_rand()                /* random function between 0 and 1 */
474   {
438    extern double  floor();
475      double  x;
476  
477      x = argument(1);
# Line 449 | Line 485 | l_rand()               /* random function between 0 and 1 */
485   static double
486   l_floor()               /* return largest integer not greater than arg1 */
487   {
452    extern double  floor();
453
488      return(floor(argument(1)));
489   }
490  
# Line 458 | Line 492 | l_floor()              /* return largest integer not greater than
492   static double
493   l_ceil()                /* return smallest integer not less than arg1 */
494   {
461    extern double  ceil();
462
495      return(ceil(argument(1)));
496   }
497  
# Line 468 | Line 500 | l_ceil()               /* return smallest integer not less than arg
500   static double
501   l_sqrt()
502   {
471    extern double  sqrt();
472
503      return(sqrt(argument(1)));
504   }
505  
# Line 477 | Line 507 | l_sqrt()
507   static double
508   l_sin()
509   {
480    extern double  sin();
481
510      return(sin(argument(1)));
511   }
512  
# Line 486 | Line 514 | l_sin()
514   static double
515   l_cos()
516   {
489    extern double  cos();
490
517      return(cos(argument(1)));
518   }
519  
# Line 495 | Line 521 | l_cos()
521   static double
522   l_tan()
523   {
498    extern double  tan();
499
524      return(tan(argument(1)));
525   }
526  
# Line 504 | Line 528 | l_tan()
528   static double
529   l_asin()
530   {
507    extern double  asin();
508
531      return(asin(argument(1)));
532   }
533  
# Line 513 | Line 535 | l_asin()
535   static double
536   l_acos()
537   {
516    extern double  acos();
517
538      return(acos(argument(1)));
539   }
540  
# Line 522 | Line 542 | l_acos()
542   static double
543   l_atan()
544   {
525    extern double  atan();
526
545      return(atan(argument(1)));
546   }
547  
# Line 531 | Line 549 | l_atan()
549   static double
550   l_atan2()
551   {
534    extern double  atan2();
535
552      return(atan2(argument(1), argument(2)));
553   }
554  
# Line 540 | Line 556 | l_atan2()
556   static double
557   l_exp()
558   {
543    extern double  exp();
544
559      return(exp(argument(1)));
560   }
561  
# Line 549 | Line 563 | l_exp()
563   static double
564   l_log()
565   {
552    extern double  log();
553
566      return(log(argument(1)));
567   }
568  
# Line 558 | Line 570 | l_log()
570   static double
571   l_log10()
572   {
561    extern double  log10();
562
573      return(log10(argument(1)));
574   }
575   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines