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.22 by schorsch, Sun Mar 28 20:33:12 2004 UTC vs.
Revision 2.30 by greg, Sat Mar 12 15:50:13 2022 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 187 | Line 196 | dremove(                       /* delete all definitions of name */
196  
197  
198   int
199 < vardefined(     /* return non-zero if variable defined */
199 > vardefined(     /* return '=' or ':' if variable/constant 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);
205 >    if ((dp = dlookup(name)) == NULL || dp->v.kid->type != SYM)
206 >        return(0);
207 >    return(dp->type);
208   }
209  
210  
211   char *
212   setcontext(                     /* set a new context path */
213 <        register char  *ctx
213 >        char  *ctx
214   )
215   {
216 <    register char  *cpp;
216 >    char  *cpp;
217  
218      if (ctx == NULL)
219          return(context);                /* just asking */
# Line 236 | Line 247 | pushcontext(           /* push on another context */
247   )
248   {
249      char  oldcontext[MAXCNTX+1];
250 <    register int  n;
250 >    int  n;
251  
252      strcpy(oldcontext, context);        /* save old context */
253      setcontext(ctx);                    /* set new context */
# Line 253 | Line 264 | pushcontext(           /* push on another context */
264   char *
265   popcontext(void)                        /* pop off top context */
266   {
267 <    register char  *cp1, *cp2;
267 >    char  *cp1, *cp2;
268  
269      if (!context[0])                    /* nothing left to pop */
270          return(context);
# Line 269 | Line 280 | popcontext(void)                       /* pop off top context */
280  
281   char *
282   qualname(               /* get qualified name */
283 <        register char  *nam,
283 >        char  *nam,
284          int  lvl
285   )
286   {
287      static char  nambuf[RMAXWORD+1];
288 <    register char  *cp = nambuf, *cpp;
288 >    char  *cp = nambuf, *cpp;
289                                  /* check for explicit local */
290      if (*nam == CNTXMARK)
291          if (lvl > 0)            /* only action is to refuse search */
# Line 316 | Line 327 | toolong:
327  
328   int
329   incontext(                      /* is qualified name in current context? */
330 <        register char  *qn
330 >        char  *qn
331   )
332   {
333      if (!context[0])                    /* global context accepts all */
# Line 332 | Line 343 | chanout(                       /* set output channels */
343          void  (*cs)(int n, double v)
344   )
345   {
346 <    register EPNODE  *ep;
346 >    EPNODE  *ep;
347  
348      for (ep = outchan; ep != NULL; ep = ep->sibling)
349          (*cs)(ep->v.kid->v.chan, evalue(ep->v.kid->sibling));
# Line 345 | Line 356 | dcleanup(              /* clear definitions (0->vars,1->output,2->
356          int  lvl
357   )
358   {
359 <    register int  i;
360 <    register VARDEF  *vp;
361 <    register EPNODE  *ep;
359 >    int  i;
360 >    VARDEF  *vp;
361 >    EPNODE  *ep;
362                                  /* if context is global, clear all */
363      for (i = 0; i < NHASH; i++)
364          for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
# Line 370 | Line 381 | dlookup(                       /* look up a definition */
381          char  *name
382   )
383   {
384 <    register VARDEF  *vp;
384 >    VARDEF  *vp;
385      
386      if ((vp = varlookup(name)) == NULL)
387          return(NULL);
# Line 384 | Line 395 | varlookup(                     /* look up a variable */
395   )
396   {
397      int  lvl = 0;
398 <    register char  *qname;
399 <    register VARDEF  *vp;
398 >    char  *qname;
399 >    VARDEF  *vp;
400                                  /* find most qualified match */
401      while ((qname = qualname(name, lvl++)) != NULL)
402          for (vp = hashtbl[hash(qname)]; vp != NULL; vp = vp->next)
# Line 400 | Line 411 | varinsert(                     /* get a link to a variable */
411          char  *name
412   )
413   {
414 <    register VARDEF  *vp;
414 >    VARDEF  *vp;
415      int  hv;
416      
417      if ((vp = varlookup(name)) != NULL) {
# Line 426 | Line 437 | libupdate(                     /* update library links */
437          char  *fn
438   )
439   {
440 <    register int  i;
441 <    register VARDEF  *vp;
440 >    int  i;
441 >    VARDEF  *vp;
442                                          /* if fn is NULL then relink all */
443      for (i = 0; i < NHASH; i++)
444          for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
# Line 438 | Line 449 | libupdate(                     /* update library links */
449  
450   void
451   varfree(                                /* release link to variable */
452 <        register VARDEF  *ln
452 >        VARDEF   *ln
453   )
454   {
455 <    register VARDEF  *vp;
455 >    VARDEF  *vp;
456      int  hv;
457  
458      if (--ln->nlinks > 0)
# Line 474 | Line 485 | dfirst(void)                   /* return pointer to first definition *
485   EPNODE *
486   dnext(void)                             /* return pointer to next definition */
487   {
488 <    register EPNODE  *ep;
489 <    register char  *nm;
488 >    EPNODE  *ep;
489 >    char  *nm;
490  
491      while (htndx < NHASH) {
492          if (htpos == NULL)
# Line 499 | Line 510 | dpop(                  /* pop a definition */
510          char  *name
511   )
512   {
513 <    register VARDEF  *vp;
514 <    register EPNODE  *dp;
513 >    VARDEF  *vp;
514 >    EPNODE  *dp;
515      
516      if ((vp = varlookup(name)) == NULL || vp->def == NULL)
517          return(NULL);
# Line 514 | Line 525 | dpop(                  /* pop a definition */
525   void
526   dpush(                  /* push on a definition */
527          char  *nm,
528 <        register EPNODE  *ep
528 >        EPNODE   *ep
529   )
530   {
531 <    register VARDEF  *vp;
531 >    VARDEF  *vp;
532  
533      vp = varinsert(nm);
534      ep->sibling = vp->def;
# Line 531 | Line 542 | addchan(                       /* add an output channel assignment */
542   )
543   {
544      int  ch = sp->v.kid->v.chan;
545 <    register EPNODE  *ep, *epl;
545 >    EPNODE  *ep, *epl;
546  
547      for (epl = NULL, ep = outchan; ep != NULL; epl = ep, ep = ep->sibling)
548          if (ep->v.kid->v.chan >= ch) {
# Line 559 | Line 570 | addchan(                       /* add an output channel assignment */
570   void
571   getstatement(void)                      /* get next statement */
572   {
573 <    register EPNODE  *ep;
573 >    EPNODE  *ep;
574      char  *qname;
575 <    register VARDEF  *vdef;
575 >    VARDEF  *vdef;
576  
577      if (nextc == ';') {         /* empty statement */
578          scan();
# Line 607 | Line 618 | getdefn(void)
618          /*      FUNC(SYM,..) = E1 */
619          /*      FUNC(SYM,..) : E1 */
620   {
621 <    register EPNODE  *ep1, *ep2;
621 >    EPNODE  *ep1, *ep2;
622  
623      if (!isalpha(nextc) && nextc != CNTXMARK)
624          syntax("illegal variable name");
# Line 624 | Line 635 | getdefn(void)
635          do {
636              scan();
637              if (!isalpha(nextc))
638 <                syntax("illegal variable name");
638 >                syntax("illegal parameter name");
639              ep2 = newnode();
640              ep2->type = SYM;
641              ep2->v.name = savestr(getname());
642 +            if (strchr(ep2->v.name, CNTXMARK) != NULL)
643 +                syntax("illegal parameter name");
644              addekid(ep1, ep2);
645          } while (nextc == ',');
646          if (nextc != ')')
# Line 647 | Line 660 | getdefn(void)
660  
661      if (ep1->type == SYM && ep1->sibling->type != NUM) {
662          ep1 = newnode();
663 <        ep1->type = TICK;
663 >        ep1->type = CLKT;
664          ep1->v.tick = 0;
665          addekid(ep2, ep1);
666          ep1 = newnode();
# Line 663 | Line 676 | getdefn(void)
676   EPNODE *
677   getchan(void)                   /* A -> $N = E1 */
678   {
679 <    register EPNODE  *ep1, *ep2;
679 >    EPNODE  *ep1, *ep2;
680  
681      if (nextc != '$')
682          syntax("missing '$'");
# Line 693 | Line 706 | getchan(void)                  /* A -> $N = E1 */
706  
707  
708   static double                   /* evaluate a variable */
709 < dvalue(char  *name, EPNODE      *d)
709 > dvalue(char *name, EPNODE *d)
710   {
711 <    register EPNODE  *ep1, *ep2;
711 >    EPNODE  *ep1, *ep2;
712      
713      if (d == NULL || d->v.kid->type != SYM) {
714          eputs(name);
# Line 705 | Line 718 | dvalue(char  *name, EPNODE     *d)
718      ep1 = d->v.kid->sibling;                    /* get expression */
719      if (ep1->type == NUM)
720          return(ep1->v.num);                     /* return if number */
721 +    if (esupport&E_RCONST && d->type == ':') {
722 +        wputs(name);
723 +        wputs(": assigned non-constant value\n");
724 +    }
725      ep2 = ep1->sibling;                         /* check time */
726      if (eclock >= MAXCLOCK)
727          eclock = 1;                             /* wrap clock counter */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines