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.7 by greg, Sun Nov 22 17:29:46 1992 UTC vs.
Revision 2.10 by greg, Wed Mar 5 16:16:52 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 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>
# Line 40 | 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();
47 #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();
52 #endif
49  
54 #ifdef  BIGLIB
50                          /* functions must be listed alphabetically */
51   static LIBR  library[MAXLIB] = {
52      { "acos", 1, ':', l_acos },
# Line 74 | Line 69 | static LIBR  library[MAXLIB] = {
69  
70   static int  libsize = 16;
71  
77 #else
78                        /* functions must be listed alphabetically */
79 static LIBR  library[MAXLIB] = {
80    { "ceil", 1, ':', l_ceil },
81    { "floor", 1, ':', l_floor },
82    { "if", 3, ':', l_if },
83    { "rand", 1, ':', l_rand },
84    { "select", 1, ':', l_select },
85 };
86
87 static int  libsize = 5;
88
89 #endif
90
91 extern char  *savestr(), *emalloc();
92
93 extern VARDEF  *argf();
94
95 #ifdef  VARIABLE
72   #define  resolve(ep)    ((ep)->type==VAR?(ep)->v.ln:argf((ep)->v.chan))
97 #else
98 #define  resolve(ep)    ((ep)->v.ln)
99 #define varlookup(name) NULL
100 #endif
73  
74  
75   int
# Line 148 | 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;
# Line 155 | Line 128 | 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 240 | Line 220 | register int  n;
220   }
221  
222  
243 #ifdef  VARIABLE
223   VARDEF *
224   argf(n)                         /* return function def for nth argument */
225   int  n;
# Line 285 | Line 264 | int  n;
264   {
265      return(argf(n)->name);
266   }
288 #endif
267  
268  
269   double
# Line 339 | Line 317 | char  *fname;
317   }
318  
319  
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;
349 {
350    register VARDEF  *vp;
351
352    vp = (VARDEF *)emalloc(sizeof(VARDEF));
353    vp->name = savestr(vname);
354    vp->nlinks = 1;
355    vp->def = NULL;
356    vp->lib = liblookup(vname);
357    vp->next = varlist;
358    varlist = vp;
359    return(vp);
360 }
361
362
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
391
320   /*
321   *  The following routines are for internal use:
322   */
# Line 422 | Line 350 | VARDEF  *vp;
350          else if (isinf(d))
351              errno = ERANGE;
352   #endif
353 <    if (errno) {
353 >    if (errno == EDOM || errno == ERANGE) {
354          wputs(fname);
355          if (errno == EDOM)
356                  wputs(": domain error\n");
# Line 496 | Line 424 | l_ceil()               /* return smallest integer not less than arg
424   }
425  
426  
499 #ifdef  BIGLIB
427   static double
428   l_sqrt()
429   {
# Line 572 | Line 499 | l_log10()
499   {
500      return(log10(argument(1)));
501   }
575 #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines