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.34 by greg, Tue Feb 7 20:28:16 2023 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 80 | Line 78 | fcompile(                      /* get definitions from a file */
78          eputs(": cannot open\n");
79          quit(1);
80      }
81 <    initfile(fp, fname, 0);
81 > #ifdef getc_unlocked                    /* avoid stupid semaphores */
82 >    flockfile(fp);
83 > #endif
84 >   initfile(fp, fname, 0);
85      while (nextc != EOF)
86          getstatement();
87      if (fname != NULL)
88          fclose(fp);
89 + #ifdef getc_unlocked
90 +    else
91 +        funlockfile(fp);
92 + #endif
93   }
94  
95  
# Line 115 | Line 120 | evariable(                     /* evaluate a variable */
120          EPNODE  *ep
121   )
122   {
123 <    register VARDEF  *dp = ep->v.ln;
123 >    VARDEF  *dp = ep->v.ln;
124  
125      return(dvalue(dp->name, dp->def));
126   }
# Line 129 | Line 134 | varset(                /* set a variable's value */
134   )
135   {
136      char  *qname;
137 <    register EPNODE  *ep1, *ep2;
137 >    EPNODE  *ep1, *ep2;
138                                          /* get qualified name */
139      qname = qualname(vname, 0);
140                                          /* check for quick set */
141 <    if ((ep1 = dlookup(qname)) != NULL && ep1->v.kid->type == SYM) {
141 >    if ((ep1 = dlookup(qname)) != NULL && ep1->v.kid->type == SYM &&
142 >                (ep1->type == ':') <= (assign == ':')) {
143          ep2 = ep1->v.kid->sibling;
144          if (ep2->type == NUM) {
145              ep2->v.num = val;
# Line 141 | Line 147 | varset(                /* set a variable's value */
147              return;
148          }
149      }
150 +    if (ep1 != NULL && esupport&E_REDEFW) {
151 +        wputs(qname);
152 +        if (ep1->type == ':')
153 +            wputs(": reset constant expression\n");
154 +        else
155 +            wputs(": reset expression\n");
156 +    }
157                                          /* hand build definition */
158      ep1 = newnode();
159      ep1->type = assign;
# Line 152 | Line 165 | varset(                /* set a variable's value */
165      ep2->type = NUM;
166      ep2->v.num = val;
167      addekid(ep1, ep2);
168 <    dremove(qname);
168 >    if (assign == ':')
169 >        dremove(qname);
170 >    else
171 >        dclear(qname);
172      dpush(qname, ep1);
173   }
174  
# Line 162 | Line 178 | dclear(                        /* delete variable definitions of name */
178          char  *name
179   )
180   {
181 <    register EPNODE  *ep;
181 >    EPNODE  *ep;
182  
183      while ((ep = dpop(name)) != NULL) {
184          if (ep->type == ':') {
# Line 179 | Line 195 | dremove(                       /* delete all definitions of name */
195          char  *name
196   )
197   {
198 <    register EPNODE  *ep;
198 >    EPNODE  *ep;
199  
200      while ((ep = dpop(name)) != NULL)
201          epfree(ep);
# Line 187 | Line 203 | dremove(                       /* delete all definitions of name */
203  
204  
205   int
206 < vardefined(     /* return non-zero if variable defined */
206 > vardefined(     /* return '=' or ':' if variable/constant defined */
207          char  *name
208   )
209   {
210 <    register EPNODE  *dp;
210 >    EPNODE  *dp = dlookup(name);
211  
212 <    return((dp = dlookup(name)) != NULL && dp->v.kid->type == SYM);
212 >    if (dp == NULL || dp->v.kid->type != SYM)
213 >        return(0);
214 >
215 >    return(dp->type);
216   }
217  
218  
219   char *
220 < setcontext(                     /* set a new context path */
221 <        register char  *ctx
220 > calcontext(                     /* set a new context path */
221 >        char  *ctx
222   )
223   {
224 <    register char  *cpp;
224 >    char  *cpp;
225  
226      if (ctx == NULL)
227          return(context);                /* just asking */
# Line 236 | Line 255 | pushcontext(           /* push on another context */
255   )
256   {
257      char  oldcontext[MAXCNTX+1];
258 <    register int  n;
258 >    int  n;
259  
260      strcpy(oldcontext, context);        /* save old context */
261 <    setcontext(ctx);                    /* set new context */
261 >    calcontext(ctx);                    /* set new context */
262      n = strlen(context);                /* tack on old */
263      if (n+strlen(oldcontext) > MAXCNTX) {
264          strncpy(context+n, oldcontext, MAXCNTX-n);
# Line 253 | Line 272 | pushcontext(           /* push on another context */
272   char *
273   popcontext(void)                        /* pop off top context */
274   {
275 <    register char  *cp1, *cp2;
275 >    char  *cp1, *cp2;
276  
277      if (!context[0])                    /* nothing left to pop */
278          return(context);
# Line 269 | Line 288 | popcontext(void)                       /* pop off top context */
288  
289   char *
290   qualname(               /* get qualified name */
291 <        register char  *nam,
291 >        char  *nam,
292          int  lvl
293   )
294   {
295      static char  nambuf[RMAXWORD+1];
296 <    register char  *cp = nambuf, *cpp;
296 >    char  *cp = nambuf, *cpp;
297                                  /* check for explicit local */
298      if (*nam == CNTXMARK)
299          if (lvl > 0)            /* only action is to refuse search */
# Line 316 | Line 335 | toolong:
335  
336   int
337   incontext(                      /* is qualified name in current context? */
338 <        register char  *qn
338 >        char  *qn
339   )
340   {
341      if (!context[0])                    /* global context accepts all */
# Line 332 | Line 351 | chanout(                       /* set output channels */
351          void  (*cs)(int n, double v)
352   )
353   {
354 <    register EPNODE  *ep;
354 >    EPNODE  *ep;
355  
356      for (ep = outchan; ep != NULL; ep = ep->sibling)
357          (*cs)(ep->v.kid->v.chan, evalue(ep->v.kid->sibling));
# Line 345 | Line 364 | dcleanup(              /* clear definitions (0->vars,1->output,2->
364          int  lvl
365   )
366   {
367 <    register int  i;
368 <    register VARDEF  *vp;
369 <    register EPNODE  *ep;
367 >    int  i;
368 >    VARDEF  *vp;
369 >    EPNODE  *ep;
370                                  /* if context is global, clear all */
371      for (i = 0; i < NHASH; i++)
372          for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
# Line 370 | Line 389 | dlookup(                       /* look up a definition */
389          char  *name
390   )
391   {
392 <    register VARDEF  *vp;
392 >    VARDEF  *vp;
393      
394      if ((vp = varlookup(name)) == NULL)
395          return(NULL);
# Line 384 | Line 403 | varlookup(                     /* look up a variable */
403   )
404   {
405      int  lvl = 0;
406 <    register char  *qname;
407 <    register VARDEF  *vp;
406 >    char  *qname;
407 >    VARDEF  *vp;
408                                  /* find most qualified match */
409      while ((qname = qualname(name, lvl++)) != NULL)
410          for (vp = hashtbl[hash(qname)]; vp != NULL; vp = vp->next)
# Line 400 | Line 419 | varinsert(                     /* get a link to a variable */
419          char  *name
420   )
421   {
422 <    register VARDEF  *vp;
422 >    VARDEF  *vp;
423      int  hv;
424      
425      if ((vp = varlookup(name)) != NULL) {
# Line 426 | Line 445 | libupdate(                     /* update library links */
445          char  *fn
446   )
447   {
448 <    register int  i;
449 <    register VARDEF  *vp;
448 >    int  i;
449 >    VARDEF  *vp;
450                                          /* if fn is NULL then relink all */
451      for (i = 0; i < NHASH; i++)
452          for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
453 <            if (vp->lib != NULL || fn == NULL || !strcmp(fn, vp->name))
453 >            if ((vp->lib != NULL) | (fn == NULL) || !strcmp(fn, vp->name))
454                  vp->lib = liblookup(vp->name);
455   }
456  
457  
458   void
459   varfree(                                /* release link to variable */
460 <        register VARDEF  *ln
460 >        VARDEF   *ln
461   )
462   {
463 <    register VARDEF  *vp;
463 >    VARDEF  *vp;
464      int  hv;
465  
466      if (--ln->nlinks > 0)
# Line 474 | Line 493 | dfirst(void)                   /* return pointer to first definition *
493   EPNODE *
494   dnext(void)                             /* return pointer to next definition */
495   {
496 <    register EPNODE  *ep;
497 <    register char  *nm;
496 >    EPNODE  *ep;
497 >    char  *nm;
498  
499      while (htndx < NHASH) {
500          if (htpos == NULL)
# Line 499 | Line 518 | dpop(                  /* pop a definition */
518          char  *name
519   )
520   {
521 <    register VARDEF  *vp;
522 <    register EPNODE  *dp;
521 >    VARDEF  *vp;
522 >    EPNODE  *dp;
523      
524      if ((vp = varlookup(name)) == NULL || vp->def == NULL)
525          return(NULL);
# Line 514 | Line 533 | dpop(                  /* pop a definition */
533   void
534   dpush(                  /* push on a definition */
535          char  *nm,
536 <        register EPNODE  *ep
536 >        EPNODE   *ep
537   )
538   {
539 <    register VARDEF  *vp;
539 >    VARDEF  *vp;
540  
541      vp = varinsert(nm);
542      ep->sibling = vp->def;
# Line 531 | Line 550 | addchan(                       /* add an output channel assignment */
550   )
551   {
552      int  ch = sp->v.kid->v.chan;
553 <    register EPNODE  *ep, *epl;
553 >    EPNODE  *ep, *epl;
554  
555      for (epl = NULL, ep = outchan; ep != NULL; epl = ep, ep = ep->sibling)
556          if (ep->v.kid->v.chan >= ch) {
# Line 559 | Line 578 | addchan(                       /* add an output channel assignment */
578   void
579   getstatement(void)                      /* get next statement */
580   {
581 <    register EPNODE  *ep;
581 >    EPNODE  *ep;
582      char  *qname;
583 <    register VARDEF  *vdef;
583 >    VARDEF  *vdef;
584  
585      if (nextc == ';') {         /* empty statement */
586          scan();
# Line 607 | Line 626 | getdefn(void)
626          /*      FUNC(SYM,..) = E1 */
627          /*      FUNC(SYM,..) : E1 */
628   {
629 <    register EPNODE  *ep1, *ep2;
629 >    EPNODE  *ep1, *ep2;
630  
631 <    if (!isalpha(nextc) && nextc != CNTXMARK)
631 >    if (!isalpha(nextc) & (nextc != CNTXMARK))
632          syntax("illegal variable name");
633  
634      ep1 = newnode();
# Line 624 | Line 643 | getdefn(void)
643          do {
644              scan();
645              if (!isalpha(nextc))
646 <                syntax("illegal variable name");
646 >                syntax("illegal parameter name");
647              ep2 = newnode();
648              ep2->type = SYM;
649              ep2->v.name = savestr(getname());
650 +            if (strchr(ep2->v.name, CNTXMARK) != NULL)
651 +                syntax("illegal parameter name");
652              addekid(ep1, ep2);
653          } while (nextc == ',');
654          if (nextc != ')')
# Line 636 | Line 657 | getdefn(void)
657          curfunc = ep1;
658      }
659  
660 <    if (nextc != '=' && nextc != ':')
660 >    if ((nextc != '=') & (nextc != ':'))
661          syntax("'=' or ':' expected");
662  
663      ep2 = newnode();
# Line 647 | Line 668 | getdefn(void)
668  
669      if (ep1->type == SYM && ep1->sibling->type != NUM) {
670          ep1 = newnode();
671 <        ep1->type = TICK;
671 >        ep1->type = CLKT;
672          ep1->v.tick = 0;
673          addekid(ep2, ep1);
674          ep1 = newnode();
# Line 663 | Line 684 | getdefn(void)
684   EPNODE *
685   getchan(void)                   /* A -> $N = E1 */
686   {
687 <    register EPNODE  *ep1, *ep2;
687 >    EPNODE  *ep1, *ep2;
688  
689      if (nextc != '$')
690          syntax("missing '$'");
# Line 693 | Line 714 | getchan(void)                  /* A -> $N = E1 */
714  
715  
716   static double                   /* evaluate a variable */
717 < dvalue(char  *name, EPNODE      *d)
717 > dvalue(char *name, EPNODE *d)
718   {
719 <    register EPNODE  *ep1, *ep2;
719 >    EPNODE  *ep1, *ep2;
720      
721      if (d == NULL || d->v.kid->type != SYM) {
722          eputs(name);
# Line 705 | Line 726 | dvalue(char  *name, EPNODE     *d)
726      ep1 = d->v.kid->sibling;                    /* get expression */
727      if (ep1->type == NUM)
728          return(ep1->v.num);                     /* return if number */
729 +    if (esupport&E_RCONST && d->type == ':') {
730 +        wputs(name);
731 +        wputs(": assigned non-constant value\n");
732 +    }
733      ep2 = ep1->sibling;                         /* check time */
734      if (eclock >= MAXCLOCK)
735          eclock = 1;                             /* wrap clock counter */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines