--- ray/src/common/caldefn.c 2003/02/22 02:07:21 2.12
+++ ray/src/common/caldefn.c 2003/07/21 22:30:17 2.19
@@ -1,5 +1,5 @@
#ifndef lint
-static const char RCSid[] = "$Id: caldefn.c,v 2.12 2003/02/22 02:07:21 greg Exp $";
+static const char RCSid[] = "$Id: caldefn.c,v 2.19 2003/07/21 22:30:17 schorsch Exp $";
#endif
/*
* Store variable definitions.
@@ -25,69 +25,13 @@ static const char RCSid[] = "$Id: caldefn.c,v 2.12 200
* 2/19/03 Eliminated conditional compiles in favor of esupport extern.
*/
-/* ====================================================================
- * The Radiance Software License, Version 1.0
- *
- * Copyright (c) 1990 - 2002 The Regents of the University of California,
- * through Lawrence Berkeley National Laboratory. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes Radiance software
- * (http://radsite.lbl.gov/)
- * developed by the Lawrence Berkeley National Laboratory
- * (http://www.lbl.gov/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
- * and "The Regents of the University of California" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact radiance@radsite.lbl.gov.
- *
- * 5. Products derived from this software may not be called "Radiance",
- * nor may "Radiance" appear in their name, without prior written
- * permission of Lawrence Berkeley National Laboratory.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of Lawrence Berkeley National Laboratory. For more
- * information on Lawrence Berkeley National Laboratory, please see
- * .
- */
+#include "copyright.h"
#include
-
#include
-
#include
+#include "rterror.h"
#include "calcomp.h"
#ifndef NHASH
@@ -98,7 +42,7 @@ static const char RCSid[] = "$Id: caldefn.c,v 2.12 200
#define newnode() (EPNODE *)ecalloc(1, sizeof(EPNODE))
-static double dvalue();
+static double dvalue(char *name, EPNODE *d);
#define MAXCLOCK (1L<<31) /* clock wrap value */
@@ -121,8 +65,9 @@ EPNODE *curfunc = NULL;
void
-fcompile(fname) /* get definitions from a file */
-char *fname;
+fcompile( /* get definitions from a file */
+ char *fname
+)
{
FILE *fp;
@@ -142,10 +87,11 @@ char *fname;
void
-scompile(str, fn, ln) /* get definitions from a string */
-char *str;
-char *fn;
-int ln;
+scompile( /* get definitions from a string */
+ char *str,
+ char *fn,
+ int ln
+)
{
initstr(str, fn, ln);
while (nextc != EOF)
@@ -154,16 +100,18 @@ int ln;
double
-varvalue(vname) /* return a variable's value */
-char *vname;
+varvalue( /* return a variable's value */
+ char *vname
+)
{
return(dvalue(vname, dlookup(vname)));
}
double
-evariable(ep) /* evaluate a variable */
-EPNODE *ep;
+evariable( /* evaluate a variable */
+ EPNODE *ep
+)
{
register VARDEF *dp = ep->v.ln;
@@ -172,10 +120,11 @@ EPNODE *ep;
void
-varset(vname, assign, val) /* set a variable's value */
-char *vname;
-int assign;
-double val;
+varset( /* set a variable's value */
+ char *vname,
+ int assign,
+ double val
+)
{
char *qname;
register EPNODE *ep1, *ep2;
@@ -207,8 +156,9 @@ double val;
void
-dclear(name) /* delete variable definitions of name */
-char *name;
+dclear( /* delete variable definitions of name */
+ char *name
+)
{
register EPNODE *ep;
@@ -223,8 +173,9 @@ char *name;
void
-dremove(name) /* delete all definitions of name */
-char *name;
+dremove( /* delete all definitions of name */
+ char *name
+)
{
register EPNODE *ep;
@@ -234,8 +185,9 @@ char *name;
int
-vardefined(name) /* return non-zero if variable defined */
-char *name;
+vardefined( /* return non-zero if variable defined */
+ char *name
+)
{
register EPNODE *dp;
@@ -244,8 +196,9 @@ char *name;
char *
-setcontext(ctx) /* set a new context path */
-register char *ctx;
+setcontext( /* set a new context path */
+ register char *ctx
+)
{
register char *cpp;
@@ -276,10 +229,10 @@ register char *ctx;
char *
-pushcontext(ctx) /* push on another context */
-char *ctx;
+pushcontext( /* push on another context */
+ char *ctx
+)
{
- extern char *strncpy(), *strcpy();
char oldcontext[MAXCNTX+1];
register int n;
@@ -296,7 +249,7 @@ char *ctx;
char *
-popcontext() /* pop off top context */
+popcontext(void) /* pop off top context */
{
register char *cp1, *cp2;
@@ -313,11 +266,12 @@ popcontext() /* pop off top context */
char *
-qualname(nam, lvl) /* get qualified name */
-register char *nam;
-int lvl;
+qualname( /* get qualified name */
+ register char *nam,
+ int lvl
+)
{
- static char nambuf[MAXWORD+1];
+ static char nambuf[RMAXWORD+1];
register char *cp = nambuf, *cpp;
/* check for explicit local */
if (*nam == CNTXMARK)
@@ -329,7 +283,7 @@ int lvl;
return(lvl > 0 ? NULL : nam);
/* copy name to static buffer */
while (*nam) {
- if (cp >= nambuf+MAXWORD)
+ if (cp >= nambuf+RMAXWORD)
goto toolong;
*cp++ = *nam++;
}
@@ -348,7 +302,7 @@ int lvl;
;
}
while (*cpp) { /* copy context to static buffer */
- if (cp >= nambuf+MAXWORD)
+ if (cp >= nambuf+RMAXWORD)
goto toolong;
*cp++ = *cpp++;
}
@@ -359,8 +313,9 @@ toolong:
int
-incontext(qn) /* is qualified name in current context? */
-register char *qn;
+incontext( /* is qualified name in current context? */
+ register char *qn
+)
{
if (!context[0]) /* global context accepts all */
return(1);
@@ -371,8 +326,9 @@ register char *qn;
void
-chanout(cs) /* set output channels */
-int (*cs)();
+chanout( /* set output channels */
+ void (*cs)(int n, double v)
+)
{
register EPNODE *ep;
@@ -383,8 +339,9 @@ int (*cs)();
void
-dcleanup(lvl) /* clear definitions (0->vars,1->output,2->consts) */
-int lvl;
+dcleanup( /* clear definitions (0->vars,1->output,2->consts) */
+ int lvl
+)
{
register int i;
register VARDEF *vp;
@@ -392,11 +349,12 @@ int lvl;
/* if context is global, clear all */
for (i = 0; i < NHASH; i++)
for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
- if (incontext(vp->name))
+ if (incontext(vp->name)) {
if (lvl >= 2)
dremove(vp->name);
else
dclear(vp->name);
+ }
if (lvl >= 1) {
for (ep = outchan; ep != NULL; ep = ep->sibling)
epfree(ep);
@@ -406,8 +364,9 @@ int lvl;
EPNODE *
-dlookup(name) /* look up a definition */
-char *name;
+dlookup( /* look up a definition */
+ char *name
+)
{
register VARDEF *vp;
@@ -418,8 +377,9 @@ char *name;
VARDEF *
-varlookup(name) /* look up a variable */
-char *name;
+varlookup( /* look up a variable */
+ char *name
+)
{
int lvl = 0;
register char *qname;
@@ -434,8 +394,9 @@ char *name;
VARDEF *
-varinsert(name) /* get a link to a variable */
-char *name;
+varinsert( /* get a link to a variable */
+ char *name
+)
{
register VARDEF *vp;
int hv;
@@ -459,8 +420,9 @@ char *name;
void
-libupdate(fn) /* update library links */
-char *fn;
+libupdate( /* update library links */
+ char *fn
+)
{
register int i;
register VARDEF *vp;
@@ -473,8 +435,9 @@ char *fn;
void
-varfree(ln) /* release link to variable */
-register VARDEF *ln;
+varfree( /* release link to variable */
+ register VARDEF *ln
+)
{
register VARDEF *vp;
int hv;
@@ -497,7 +460,7 @@ register VARDEF *ln;
EPNODE *
-dfirst() /* return pointer to first definition */
+dfirst(void) /* return pointer to first definition */
{
htndx = 0;
htpos = NULL;
@@ -507,7 +470,7 @@ dfirst() /* return pointer to first definition */
EPNODE *
-dnext() /* return pointer to next definition */
+dnext(void) /* return pointer to next definition */
{
register EPNODE *ep;
register char *nm;
@@ -530,8 +493,9 @@ dnext() /* return pointer to next definition */
EPNODE *
-dpop(name) /* pop a definition */
-char *name;
+dpop( /* pop a definition */
+ char *name
+)
{
register VARDEF *vp;
register EPNODE *dp;
@@ -546,9 +510,10 @@ char *name;
void
-dpush(nm, ep) /* push on a definition */
-char *nm;
-register EPNODE *ep;
+dpush( /* push on a definition */
+ char *nm,
+ register EPNODE *ep
+)
{
register VARDEF *vp;
@@ -559,8 +524,9 @@ register EPNODE *ep;
void
-addchan(sp) /* add an output channel assignment */
-EPNODE *sp;
+addchan( /* add an output channel assignment */
+ EPNODE *sp
+)
{
int ch = sp->v.kid->v.chan;
register EPNODE *ep, *epl;
@@ -589,7 +555,7 @@ EPNODE *sp;
void
-getstatement() /* get next statement */
+getstatement(void) /* get next statement */
{
register EPNODE *ep;
char *qname;
@@ -606,7 +572,7 @@ getstatement() /* get next statement */
} else { /* ordinary definition */
ep = getdefn();
qname = qualname(dname(ep), 0);
- if (esupport&E_REDEFW && (vdef = varlookup(qname)) != NULL)
+ if (esupport&E_REDEFW && (vdef = varlookup(qname)) != NULL) {
if (vdef->def != NULL && epcmp(ep, vdef->def)) {
wputs(qname);
if (vdef->def->type == ':')
@@ -617,6 +583,7 @@ getstatement() /* get next statement */
wputs(qname);
wputs(": definition hides library function\n");
}
+ }
if (ep->type == ':')
dremove(qname);
else
@@ -632,10 +599,11 @@ getstatement() /* get next statement */
EPNODE *
-getdefn() /* A -> SYM = E1 */
- /* SYM : E1 */
- /* FUNC(SYM,..) = E1 */
- /* FUNC(SYM,..) : E1 */
+getdefn(void)
+ /* A -> SYM = E1 */
+ /* SYM : E1 */
+ /* FUNC(SYM,..) = E1 */
+ /* FUNC(SYM,..) : E1 */
{
register EPNODE *ep1, *ep2;
@@ -691,7 +659,7 @@ getdefn() /* A -> SYM = E1 */
EPNODE *
-getchan() /* A -> $N = E1 */
+getchan(void) /* A -> $N = E1 */
{
register EPNODE *ep1, *ep2;
@@ -722,10 +690,8 @@ getchan() /* A -> $N = E1 */
*/
-static double
-dvalue(name, d) /* evaluate a variable */
-char *name;
-EPNODE *d;
+static double /* evaluate a variable */
+dvalue(char *name, EPNODE *d)
{
register EPNODE *ep1, *ep2;