--- ray/src/common/calfunc.c 1991/07/16 14:26:18 1.8 +++ ray/src/common/calfunc.c 1992/11/22 12:11:48 2.6 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -20,6 +20,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include +#include + #include "calcomp.h" /* bits in argument flag (better be right!) */ @@ -88,8 +90,6 @@ static int libsize = 5; extern char *savestr(), *emalloc(); -extern LIBR *liblookup(); - extern VARDEF *argf(); #ifdef VARIABLE @@ -155,9 +155,10 @@ int nargs; int assign; double (*fptr)(); { + int oldlibsize = libsize; register LIBR *lp; - if ((lp = liblookup(fname)) == NULL) { + if ((lp = liblookup(fname)) == NULL) { /* insert */ if (libsize >= MAXLIB) { eputs("Too many library functons!\n"); quit(1); @@ -172,10 +173,23 @@ double (*fptr)(); break; libsize++; } - lp[0].fname = fname; /* must be static! */ - lp[0].nargs = nargs; - lp[0].atyp = assign; - lp[0].f = fptr; + if (fptr == NULL) { /* delete */ + while (lp < &library[libsize-1]) { + lp[0].fname = lp[1].fname; + lp[0].nargs = lp[1].nargs; + lp[0].atyp = lp[1].atyp; + lp[0].f = lp[1].f; + lp++; + } + libsize--; + } else { /* or assign */ + lp[0].fname = fname; /* string must be static! */ + lp[0].nargs = nargs; + lp[0].atyp = assign; + lp[0].f = fptr; + } + if (libsize != oldlibsize) + libupdate(fname); /* relink library */ } @@ -327,6 +341,9 @@ char *fname; #ifndef VARIABLE +static VARDEF *varlist = NULL; /* our list of dummy variables */ + + VARDEF * varinsert(vname) /* dummy variable insert */ char *vname; @@ -337,8 +354,9 @@ char *vname; vp->name = savestr(vname); vp->nlinks = 1; vp->def = NULL; - vp->lib = NULL; - vp->next = NULL; + vp->lib = liblookup(vname); + vp->next = varlist; + varlist = vp; return(vp); } @@ -346,9 +364,28 @@ char *vname; 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 @@ -361,29 +398,30 @@ register VARDEF *vp; static double libfunc(fname, vp) /* execute library function */ char *fname; -register VARDEF *vp; +VARDEF *vp; { - VARDEF dumdef; + register LIBR *lp; double d; int lasterrno; - if (vp == NULL) { - vp = &dumdef; - vp->lib = NULL; - } - if (((vp->lib == NULL || strcmp(fname, vp->lib->fname)) && - (vp->lib = liblookup(fname)) == NULL) || - vp->lib->f == NULL) { + if (vp != NULL) + lp = vp->lib; + else + lp = liblookup(fname); + if (lp == NULL) { eputs(fname); eputs(": undefined function\n"); quit(1); } lasterrno = errno; errno = 0; - d = (*vp->lib->f)(vp->lib->fname); + d = (*lp->f)(lp->fname); #ifdef IEEE - if (!finite(d)) - errno = EDOM; + if (errno == 0) + if (isnan(d)) + errno = EDOM; + else if (isinf(d)) + errno = ERANGE; #endif if (errno) { wputs(fname); @@ -435,7 +473,6 @@ l_select() /* return argument #(A1+1) */ static double l_rand() /* random function between 0 and 1 */ { - extern double floor(); double x; x = argument(1); @@ -449,8 +486,6 @@ l_rand() /* random function between 0 and 1 */ static double l_floor() /* return largest integer not greater than arg1 */ { - extern double floor(); - return(floor(argument(1))); } @@ -458,8 +493,6 @@ l_floor() /* return largest integer not greater than static double l_ceil() /* return smallest integer not less than arg1 */ { - extern double ceil(); - return(ceil(argument(1))); } @@ -468,8 +501,6 @@ l_ceil() /* return smallest integer not less than arg static double l_sqrt() { - extern double sqrt(); - return(sqrt(argument(1))); } @@ -477,8 +508,6 @@ l_sqrt() static double l_sin() { - extern double sin(); - return(sin(argument(1))); } @@ -486,8 +515,6 @@ l_sin() static double l_cos() { - extern double cos(); - return(cos(argument(1))); } @@ -495,8 +522,6 @@ l_cos() static double l_tan() { - extern double tan(); - return(tan(argument(1))); } @@ -504,8 +529,6 @@ l_tan() static double l_asin() { - extern double asin(); - return(asin(argument(1))); } @@ -513,8 +536,6 @@ l_asin() static double l_acos() { - extern double acos(); - return(acos(argument(1))); } @@ -522,8 +543,6 @@ l_acos() static double l_atan() { - extern double atan(); - return(atan(argument(1))); } @@ -531,8 +550,6 @@ l_atan() static double l_atan2() { - extern double atan2(); - return(atan2(argument(1), argument(2))); } @@ -540,8 +557,6 @@ l_atan2() static double l_exp() { - extern double exp(); - return(exp(argument(1))); } @@ -549,8 +564,6 @@ l_exp() static double l_log() { - extern double log(); - return(log(argument(1))); } @@ -558,8 +571,6 @@ l_log() static double l_log10() { - extern double log10(); - return(log10(argument(1))); } #endif