ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/caldefn.c
(Generate patch)

Comparing ray/src/common/caldefn.c (file contents):
Revision 2.23 by greg, Thu May 1 16:42:05 2008 UTC vs.
Revision 2.28 by greg, Thu Apr 2 18:00:34 2020 UTC

# Line 27 | Line 27 | static const char      RCSid[] = "$Id$";
27  
28   #include "copyright.h"
29  
30 #include  <stdio.h>
31 #include  <string.h>
30   #include  <ctype.h>
31  
32   #include  "rterror.h"
# Line 115 | Line 113 | evariable(                     /* evaluate a variable */
113          EPNODE  *ep
114   )
115   {
116 <    register VARDEF  *dp = ep->v.ln;
116 >    VARDEF  *dp = ep->v.ln;
117  
118      return(dvalue(dp->name, dp->def));
119   }
# Line 129 | Line 127 | varset(                /* set a variable's value */
127   )
128   {
129      char  *qname;
130 <    register EPNODE  *ep1, *ep2;
130 >    EPNODE  *ep1, *ep2;
131                                          /* get qualified name */
132      qname = qualname(vname, 0);
133                                          /* check for quick set */
134 <    if ((ep1 = dlookup(qname)) != NULL && ep1->v.kid->type == SYM) {
134 >    if ((ep1 = dlookup(qname)) != NULL && ep1->v.kid->type == SYM &&
135 >                (ep1->type == ':') <= (assign == ':')) {
136          ep2 = ep1->v.kid->sibling;
137          if (ep2->type == NUM) {
138              ep2->v.num = val;
# Line 141 | Line 140 | varset(                /* set a variable's value */
140              return;
141          }
142      }
143 +    if (ep1 != NULL && esupport&E_REDEFW) {
144 +        wputs(qname);
145 +        if (ep1->type == ':')
146 +            wputs(": reset constant expression\n");
147 +        else
148 +            wputs(": reset expression\n");
149 +    }
150                                          /* hand build definition */
151      ep1 = newnode();
152      ep1->type = assign;
# Line 152 | Line 158 | varset(                /* set a variable's value */
158      ep2->type = NUM;
159      ep2->v.num = val;
160      addekid(ep1, ep2);
161 <    dremove(qname);
161 >    if (assign == ':')
162 >        dremove(qname);
163 >    else
164 >        dclear(qname);
165      dpush(qname, ep1);
166   }
167  
# Line 162 | Line 171 | dclear(                        /* delete variable definitions of name */
171          char  *name
172   )
173   {
174 <    register EPNODE  *ep;
174 >    EPNODE  *ep;
175  
176      while ((ep = dpop(name)) != NULL) {
177          if (ep->type == ':') {
# Line 179 | Line 188 | dremove(                       /* delete all definitions of name */
188          char  *name
189   )
190   {
191 <    register EPNODE  *ep;
191 >    EPNODE  *ep;
192  
193      while ((ep = dpop(name)) != NULL)
194          epfree(ep);
# Line 191 | Line 200 | vardefined(    /* return non-zero if variable defined */
200          char  *name
201   )
202   {
203 <    register EPNODE  *dp;
203 >    EPNODE  *dp;
204  
205      return((dp = dlookup(name)) != NULL && dp->v.kid->type == SYM);
206   }
# Line 199 | Line 208 | vardefined(    /* return non-zero if variable defined */
208  
209   char *
210   setcontext(                     /* set a new context path */
211 <        register char  *ctx
211 >        char  *ctx
212   )
213   {
214 <    register char  *cpp;
214 >    char  *cpp;
215  
216      if (ctx == NULL)
217          return(context);                /* just asking */
# Line 236 | Line 245 | pushcontext(           /* push on another context */
245   )
246   {
247      char  oldcontext[MAXCNTX+1];
248 <    register int  n;
248 >    int  n;
249  
250      strcpy(oldcontext, context);        /* save old context */
251      setcontext(ctx);                    /* set new context */
# Line 253 | Line 262 | pushcontext(           /* push on another context */
262   char *
263   popcontext(void)                        /* pop off top context */
264   {
265 <    register char  *cp1, *cp2;
265 >    char  *cp1, *cp2;
266  
267      if (!context[0])                    /* nothing left to pop */
268          return(context);
# Line 269 | Line 278 | popcontext(void)                       /* pop off top context */
278  
279   char *
280   qualname(               /* get qualified name */
281 <        register char  *nam,
281 >        char  *nam,
282          int  lvl
283   )
284   {
285      static char  nambuf[RMAXWORD+1];
286 <    register char  *cp = nambuf, *cpp;
286 >    char  *cp = nambuf, *cpp;
287                                  /* check for explicit local */
288      if (*nam == CNTXMARK)
289          if (lvl > 0)            /* only action is to refuse search */
# Line 316 | Line 325 | toolong:
325  
326   int
327   incontext(                      /* is qualified name in current context? */
328 <        register char  *qn
328 >        char  *qn
329   )
330   {
331      if (!context[0])                    /* global context accepts all */
# Line 332 | Line 341 | chanout(                       /* set output channels */
341          void  (*cs)(int n, double v)
342   )
343   {
344 <    register EPNODE  *ep;
344 >    EPNODE  *ep;
345  
346      for (ep = outchan; ep != NULL; ep = ep->sibling)
347          (*cs)(ep->v.kid->v.chan, evalue(ep->v.kid->sibling));
# Line 345 | Line 354 | dcleanup(              /* clear definitions (0->vars,1->output,2->
354          int  lvl
355   )
356   {
357 <    register int  i;
358 <    register VARDEF  *vp;
359 <    register EPNODE  *ep;
357 >    int  i;
358 >    VARDEF  *vp;
359 >    EPNODE  *ep;
360                                  /* if context is global, clear all */
361      for (i = 0; i < NHASH; i++)
362          for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
# Line 370 | Line 379 | dlookup(                       /* look up a definition */
379          char  *name
380   )
381   {
382 <    register VARDEF  *vp;
382 >    VARDEF  *vp;
383      
384      if ((vp = varlookup(name)) == NULL)
385          return(NULL);
# Line 384 | Line 393 | varlookup(                     /* look up a variable */
393   )
394   {
395      int  lvl = 0;
396 <    register char  *qname;
397 <    register VARDEF  *vp;
396 >    char  *qname;
397 >    VARDEF  *vp;
398                                  /* find most qualified match */
399      while ((qname = qualname(name, lvl++)) != NULL)
400          for (vp = hashtbl[hash(qname)]; vp != NULL; vp = vp->next)
# Line 400 | Line 409 | varinsert(                     /* get a link to a variable */
409          char  *name
410   )
411   {
412 <    register VARDEF  *vp;
412 >    VARDEF  *vp;
413      int  hv;
414      
415      if ((vp = varlookup(name)) != NULL) {
# Line 426 | Line 435 | libupdate(                     /* update library links */
435          char  *fn
436   )
437   {
438 <    register int  i;
439 <    register VARDEF  *vp;
438 >    int  i;
439 >    VARDEF  *vp;
440                                          /* if fn is NULL then relink all */
441      for (i = 0; i < NHASH; i++)
442          for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
# Line 438 | Line 447 | libupdate(                     /* update library links */
447  
448   void
449   varfree(                                /* release link to variable */
450 <        register VARDEF  *ln
450 >        VARDEF   *ln
451   )
452   {
453 <    register VARDEF  *vp;
453 >    VARDEF  *vp;
454      int  hv;
455  
456      if (--ln->nlinks > 0)
# Line 474 | Line 483 | dfirst(void)                   /* return pointer to first definition *
483   EPNODE *
484   dnext(void)                             /* return pointer to next definition */
485   {
486 <    register EPNODE  *ep;
487 <    register char  *nm;
486 >    EPNODE  *ep;
487 >    char  *nm;
488  
489      while (htndx < NHASH) {
490          if (htpos == NULL)
# Line 499 | Line 508 | dpop(                  /* pop a definition */
508          char  *name
509   )
510   {
511 <    register VARDEF  *vp;
512 <    register EPNODE  *dp;
511 >    VARDEF  *vp;
512 >    EPNODE  *dp;
513      
514      if ((vp = varlookup(name)) == NULL || vp->def == NULL)
515          return(NULL);
# Line 514 | Line 523 | dpop(                  /* pop a definition */
523   void
524   dpush(                  /* push on a definition */
525          char  *nm,
526 <        register EPNODE  *ep
526 >        EPNODE   *ep
527   )
528   {
529 <    register VARDEF  *vp;
529 >    VARDEF  *vp;
530  
531      vp = varinsert(nm);
532      ep->sibling = vp->def;
# Line 531 | Line 540 | addchan(                       /* add an output channel assignment */
540   )
541   {
542      int  ch = sp->v.kid->v.chan;
543 <    register EPNODE  *ep, *epl;
543 >    EPNODE  *ep, *epl;
544  
545      for (epl = NULL, ep = outchan; ep != NULL; epl = ep, ep = ep->sibling)
546          if (ep->v.kid->v.chan >= ch) {
# Line 559 | Line 568 | addchan(                       /* add an output channel assignment */
568   void
569   getstatement(void)                      /* get next statement */
570   {
571 <    register EPNODE  *ep;
571 >    EPNODE  *ep;
572      char  *qname;
573 <    register VARDEF  *vdef;
573 >    VARDEF  *vdef;
574  
575      if (nextc == ';') {         /* empty statement */
576          scan();
# Line 607 | Line 616 | getdefn(void)
616          /*      FUNC(SYM,..) = E1 */
617          /*      FUNC(SYM,..) : E1 */
618   {
619 <    register EPNODE  *ep1, *ep2;
619 >    EPNODE  *ep1, *ep2;
620  
621      if (!isalpha(nextc) && nextc != CNTXMARK)
622          syntax("illegal variable name");
# Line 624 | Line 633 | getdefn(void)
633          do {
634              scan();
635              if (!isalpha(nextc))
636 <                syntax("illegal variable name");
636 >                syntax("illegal parameter name");
637              ep2 = newnode();
638              ep2->type = SYM;
639              ep2->v.name = savestr(getname());
# Line 663 | Line 672 | getdefn(void)
672   EPNODE *
673   getchan(void)                   /* A -> $N = E1 */
674   {
675 <    register EPNODE  *ep1, *ep2;
675 >    EPNODE  *ep1, *ep2;
676  
677      if (nextc != '$')
678          syntax("missing '$'");
# Line 693 | Line 702 | getchan(void)                  /* A -> $N = E1 */
702  
703  
704   static double                   /* evaluate a variable */
705 < dvalue(char  *name, EPNODE      *d)
705 > dvalue(char *name, EPNODE *d)
706   {
707 <    register EPNODE  *ep1, *ep2;
707 >    EPNODE  *ep1, *ep2;
708      
709      if (d == NULL || d->v.kid->type != SYM) {
710          eputs(name);
# Line 705 | Line 714 | dvalue(char  *name, EPNODE     *d)
714      ep1 = d->v.kid->sibling;                    /* get expression */
715      if (ep1->type == NUM)
716          return(ep1->v.num);                     /* return if number */
717 +    if (esupport&E_RCONST && d->type == ':') {
718 +        wputs(name);
719 +        wputs(": assigned non-constant value\n");
720 +    }
721      ep2 = ep1->sibling;                         /* check time */
722      if (eclock >= MAXCLOCK)
723          eclock = 1;                             /* wrap clock counter */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines