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.4 by greg, Thu May 21 10:29:32 1992 UTC vs.
Revision 2.9 by greg, Tue Feb 25 02:47:21 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  calfunc.c - routines for calcomp using functions.
6   *
7 < *      The define BIGLIB pulls in a large number of the
11 < *  available math routines.
12 < *
13 < *      If VARIABLE is not defined, only library functions
7 > *      If VARIABLE is not set, only library functions
8   *  can be accessed.
9   *
10 < *     4/2/86
10 > *  2/19/03     Eliminated conditional compiles in favor of esupport extern.
11   */
12  
13 + #include "copyright.h"
14 +
15   #include  <stdio.h>
16  
17   #include  <errno.h>
18  
19 + #include  <math.h>
20 +
21   #include  "calcomp.h"
22  
23                                  /* bits in argument flag (better be right!) */
# Line 38 | Line 36 | static ACTIVATION  *curact = NULL;
36  
37   static double  libfunc();
38  
39 + #ifndef  MAXLIB
40   #define  MAXLIB         64      /* maximum number of library functions */
41 + #endif
42  
43   static double  l_if(), l_select(), l_rand();
44   static double  l_floor(), l_ceil();
45 #ifdef  BIGLIB
45   static double  l_sqrt();
46   static double  l_sin(), l_cos(), l_tan();
47   static double  l_asin(), l_acos(), l_atan(), l_atan2();
48   static double  l_exp(), l_log(), l_log10();
50 #endif
49  
52 #ifdef  BIGLIB
50                          /* functions must be listed alphabetically */
51   static LIBR  library[MAXLIB] = {
52      { "acos", 1, ':', l_acos },
# Line 72 | Line 69 | static LIBR  library[MAXLIB] = {
69  
70   static int  libsize = 16;
71  
75 #else
76                        /* functions must be listed alphabetically */
77 static LIBR  library[MAXLIB] = {
78    { "ceil", 1, ':', l_ceil },
79    { "floor", 1, ':', l_floor },
80    { "if", 3, ':', l_if },
81    { "rand", 1, ':', l_rand },
82    { "select", 1, ':', l_select },
83 };
84
85 static int  libsize = 5;
86
87 #endif
88
89 extern char  *savestr(), *emalloc();
90
91 extern VARDEF  *argf();
92
93 #ifdef  VARIABLE
72   #define  resolve(ep)    ((ep)->type==VAR?(ep)->v.ln:argf((ep)->v.chan))
95 #else
96 #define  resolve(ep)    ((ep)->v.ln)
97 #define varlookup(name) NULL
98 #endif
73  
74  
75   int
76   fundefined(fname)               /* return # of arguments for function */
77   char  *fname;
78   {
79 <    LIBR  *lp;
79 >    register LIBR  *lp;
80      register VARDEF  *vp;
81  
82 <    if ((vp = varlookup(fname)) == NULL || vp->def == NULL
83 <                || vp->def->v.kid->type != FUNC)
110 <        if ((lp = liblookup(fname)) == NULL)
111 <            return(0);
112 <        else
113 <            return(lp->nargs);
114 <    else
82 >    if ((vp = varlookup(fname)) != NULL && vp->def != NULL
83 >                && vp->def->v.kid->type == FUNC)
84          return(nekids(vp->def->v.kid) - 1);
85 +    lp = vp != NULL ? vp->lib : liblookup(fname);
86 +    if (lp == NULL)
87 +        return(0);
88 +    return(lp->nargs);
89   }
90  
91  
# Line 147 | Line 120 | double  *a;
120   }
121  
122  
123 + void
124   funset(fname, nargs, assign, fptr)      /* set a library function */
125   char  *fname;
126   int  nargs;
127   int  assign;
128   double  (*fptr)();
129   {
130 +    int  oldlibsize = libsize;
131 +    char *cp;
132      register LIBR  *lp;
133 <
133 >                                                /* check for context */
134 >    for (cp = fname; *cp; cp++)
135 >        ;
136 >    if (cp == fname)
137 >        return;
138 >    if (cp[-1] == CNTXMARK)
139 >        *--cp = '\0';
140      if ((lp = liblookup(fname)) == NULL) {      /* insert */
141          if (libsize >= MAXLIB) {
142              eputs("Too many library functons!\n");
# Line 185 | Line 167 | double  (*fptr)();
167          lp[0].atyp = assign;
168          lp[0].f = fptr;
169      }
170 <    libupdate(fname);                   /* relink library */
170 >    if (libsize != oldlibsize)
171 >        libupdate(fname);                       /* relink library */
172   }
173  
174  
# Line 237 | Line 220 | register int  n;
220   }
221  
222  
240 #ifdef  VARIABLE
223   VARDEF *
224   argf(n)                         /* return function def for nth argument */
225   int  n;
# Line 282 | Line 264 | int  n;
264   {
265      return(argf(n)->name);
266   }
285 #endif
267  
268  
269   double
# Line 336 | Line 317 | char  *fname;
317   }
318  
319  
339 #ifndef  VARIABLE
340 static VARDEF  *varlist = NULL;         /* our list of dummy variables */
341
342
343 VARDEF *
344 varinsert(vname)                /* dummy variable insert */
345 char  *vname;
346 {
347    register VARDEF  *vp;
348
349    vp = (VARDEF *)emalloc(sizeof(VARDEF));
350    vp->name = savestr(vname);
351    vp->nlinks = 1;
352    vp->def = NULL;
353    vp->lib = liblookup(vname);
354    vp->next = varlist;
355    varlist = vp;
356    return(vp);
357 }
358
359
360 varfree(vp)                     /* free dummy variable */
361 register VARDEF  *vp;
362 {
363    register VARDEF  *vp2;
364
365    if (vp == varlist)
366        varlist = vp->next;
367    else {
368        for (vp2 = varlist; vp2->next != vp; vp2 = vp2->next)
369                ;
370        vp2->next = vp->next;
371    }
372    freestr(vp->name);
373    efree((char *)vp);
374 }
375
376
377 libupdate(nm)                   /* update library */
378 char  *nm;
379 {
380    register VARDEF  *vp;
381
382    for (vp = varlist; vp != NULL; vp = vp->next)
383        vp->lib = liblookup(vp->name);
384 }
385 #endif
386
387
388
320   /*
321   *  The following routines are for internal use:
322   */
# Line 469 | Line 400 | l_select()             /* return argument #(A1+1) */
400   static double
401   l_rand()                /* random function between 0 and 1 */
402   {
472    extern double  floor();
403      double  x;
404  
405      x = argument(1);
# Line 483 | Line 413 | l_rand()               /* random function between 0 and 1 */
413   static double
414   l_floor()               /* return largest integer not greater than arg1 */
415   {
486    extern double  floor();
487
416      return(floor(argument(1)));
417   }
418  
# Line 492 | Line 420 | l_floor()              /* return largest integer not greater than
420   static double
421   l_ceil()                /* return smallest integer not less than arg1 */
422   {
495    extern double  ceil();
496
423      return(ceil(argument(1)));
424   }
425  
426  
501 #ifdef  BIGLIB
427   static double
428   l_sqrt()
429   {
505    extern double  sqrt();
506
430      return(sqrt(argument(1)));
431   }
432  
# Line 511 | Line 434 | l_sqrt()
434   static double
435   l_sin()
436   {
514    extern double  sin();
515
437      return(sin(argument(1)));
438   }
439  
# Line 520 | Line 441 | l_sin()
441   static double
442   l_cos()
443   {
523    extern double  cos();
524
444      return(cos(argument(1)));
445   }
446  
# Line 529 | Line 448 | l_cos()
448   static double
449   l_tan()
450   {
532    extern double  tan();
533
451      return(tan(argument(1)));
452   }
453  
# Line 538 | Line 455 | l_tan()
455   static double
456   l_asin()
457   {
541    extern double  asin();
542
458      return(asin(argument(1)));
459   }
460  
# Line 547 | Line 462 | l_asin()
462   static double
463   l_acos()
464   {
550    extern double  acos();
551
465      return(acos(argument(1)));
466   }
467  
# Line 556 | Line 469 | l_acos()
469   static double
470   l_atan()
471   {
559    extern double  atan();
560
472      return(atan(argument(1)));
473   }
474  
# Line 565 | Line 476 | l_atan()
476   static double
477   l_atan2()
478   {
568    extern double  atan2();
569
479      return(atan2(argument(1), argument(2)));
480   }
481  
# Line 574 | Line 483 | l_atan2()
483   static double
484   l_exp()
485   {
577    extern double  exp();
578
486      return(exp(argument(1)));
487   }
488  
# Line 583 | Line 490 | l_exp()
490   static double
491   l_log()
492   {
586    extern double  log();
587
493      return(log(argument(1)));
494   }
495  
# Line 592 | Line 497 | l_log()
497   static double
498   l_log10()
499   {
595    extern double  log10();
596
500      return(log10(argument(1)));
501   }
599 #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines