--- ray/src/common/calfunc.c 1992/11/22 12:11:48 2.6 +++ ray/src/common/calfunc.c 2003/06/07 12:50:20 2.11 @@ -1,25 +1,20 @@ -/* Copyright (c) 1992 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: calfunc.c,v 2.11 2003/06/07 12:50:20 schorsch Exp $"; #endif - /* * calfunc.c - routines for calcomp using functions. * - * The define BIGLIB pulls in a large number of the - * available math routines. - * - * If VARIABLE is not defined, only library functions + * If VARIABLE is not set, only library functions * can be accessed. * - * 4/2/86 + * 2/19/03 Eliminated conditional compiles in favor of esupport extern. */ -#include +#include "copyright.h" +#include +#include #include - #include #include "calcomp.h" @@ -40,18 +35,17 @@ static ACTIVATION *curact = NULL; static double libfunc(); +#ifndef MAXLIB #define MAXLIB 64 /* maximum number of library functions */ +#endif static double l_if(), l_select(), l_rand(); static double l_floor(), l_ceil(); -#ifdef BIGLIB static double l_sqrt(); static double l_sin(), l_cos(), l_tan(); static double l_asin(), l_acos(), l_atan(), l_atan2(); static double l_exp(), l_log(), l_log10(); -#endif -#ifdef BIGLIB /* functions must be listed alphabetically */ static LIBR library[MAXLIB] = { { "acos", 1, ':', l_acos }, @@ -74,47 +68,23 @@ static LIBR library[MAXLIB] = { static int libsize = 16; -#else - /* functions must be listed alphabetically */ -static LIBR library[MAXLIB] = { - { "ceil", 1, ':', l_ceil }, - { "floor", 1, ':', l_floor }, - { "if", 3, ':', l_if }, - { "rand", 1, ':', l_rand }, - { "select", 1, ':', l_select }, -}; - -static int libsize = 5; - -#endif - -extern char *savestr(), *emalloc(); - -extern VARDEF *argf(); - -#ifdef VARIABLE #define resolve(ep) ((ep)->type==VAR?(ep)->v.ln:argf((ep)->v.chan)) -#else -#define resolve(ep) ((ep)->v.ln) -#define varlookup(name) NULL -#endif int fundefined(fname) /* return # of arguments for function */ char *fname; { - LIBR *lp; + register LIBR *lp; register VARDEF *vp; - if ((vp = varlookup(fname)) == NULL || vp->def == NULL - || vp->def->v.kid->type != FUNC) - if ((lp = liblookup(fname)) == NULL) - return(0); - else - return(lp->nargs); - else + if ((vp = varlookup(fname)) != NULL && vp->def != NULL + && vp->def->v.kid->type == FUNC) return(nekids(vp->def->v.kid) - 1); + lp = vp != NULL ? vp->lib : liblookup(fname); + if (lp == NULL) + return(0); + return(lp->nargs); } @@ -149,6 +119,7 @@ double *a; } +void funset(fname, nargs, assign, fptr) /* set a library function */ char *fname; int nargs; @@ -156,8 +127,15 @@ int assign; double (*fptr)(); { int oldlibsize = libsize; + char *cp; register LIBR *lp; - + /* check for context */ + for (cp = fname; *cp; cp++) + ; + if (cp == fname) + return; + if (cp[-1] == CNTXMARK) + *--cp = '\0'; if ((lp = liblookup(fname)) == NULL) { /* insert */ if (libsize >= MAXLIB) { eputs("Too many library functons!\n"); @@ -241,7 +219,6 @@ register int n; } -#ifdef VARIABLE VARDEF * argf(n) /* return function def for nth argument */ int n; @@ -277,6 +254,7 @@ badarg: eputs(actp->name); eputs(": argument not a function\n"); quit(1); + return NULL; /* pro forma return */ } @@ -286,7 +264,6 @@ int n; { return(argf(n)->name); } -#endif double @@ -340,56 +317,6 @@ char *fname; } -#ifndef VARIABLE -static VARDEF *varlist = NULL; /* our list of dummy variables */ - - -VARDEF * -varinsert(vname) /* dummy variable insert */ -char *vname; -{ - register VARDEF *vp; - - vp = (VARDEF *)emalloc(sizeof(VARDEF)); - vp->name = savestr(vname); - vp->nlinks = 1; - vp->def = NULL; - vp->lib = liblookup(vname); - vp->next = varlist; - varlist = vp; - return(vp); -} - - -varfree(vp) /* free dummy variable */ -register VARDEF *vp; -{ - register VARDEF *vp2; - - if (vp == varlist) - varlist = vp->next; - else { - for (vp2 = varlist; vp2->next != vp; vp2 = vp2->next) - ; - vp2->next = vp->next; - } - freestr(vp->name); - efree((char *)vp); -} - - -libupdate(nm) /* update library */ -char *nm; -{ - register VARDEF *vp; - - for (vp = varlist; vp != NULL; vp = vp->next) - vp->lib = liblookup(vp->name); -} -#endif - - - /* * The following routines are for internal use: */ @@ -423,7 +350,7 @@ VARDEF *vp; else if (isinf(d)) errno = ERANGE; #endif - if (errno) { + if (errno == EDOM || errno == ERANGE) { wputs(fname); if (errno == EDOM) wputs(": domain error\n"); @@ -459,7 +386,7 @@ l_select() /* return argument #(A1+1) */ { register int n; - n = argument(1) + .5; + n = (int)(argument(1) + .5); if (n == 0) return(nargum()-1); if (n < 1 || n > nargum()-1) { @@ -497,7 +424,6 @@ l_ceil() /* return smallest integer not less than arg } -#ifdef BIGLIB static double l_sqrt() { @@ -573,4 +499,3 @@ l_log10() { return(log10(argument(1))); } -#endif