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.26 by greg, Thu Jul 24 15:41:13 2014 UTC vs.
Revision 2.35 by greg, Tue Sep 26 00:14:02 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 198 | 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 <    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 */
220 > calcontext(                     /* set a new context path */
221          char  *ctx
222   )
223   {
# Line 250 | Line 258 | pushcontext(           /* push on another context */
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 368 | Line 376 | dcleanup(              /* clear definitions (0->vars,1->output,2->
376                  else
377                      dclear(vp->name);
378              }
379 <    if (lvl >= 1) {
380 <        for (ep = outchan; ep != NULL; ep = ep->sibling)
379 >    if (lvl >= 1)
380 >        while (outchan != NULL) {
381 >            ep = outchan;
382 >            outchan = ep->sibling;
383 >            ep->sibling = NULL;
384              epfree(ep);
385 <        outchan = NULL;
375 <    }
385 >        }
386   }
387  
388  
# Line 442 | Line 452 | libupdate(                     /* update library links */
452                                          /* if fn is NULL then relink all */
453      for (i = 0; i < NHASH; i++)
454          for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
455 <            if (vp->lib != NULL || fn == NULL || !strcmp(fn, vp->name))
455 >            if ((vp->lib != NULL) | (fn == NULL) || !strcmp(fn, vp->name))
456                  vp->lib = liblookup(vp->name);
457   }
458  
# Line 468 | Line 478 | varfree(                               /* release link to variable */
478          vp->next = ln->next;
479      }
480      freestr(ln->name);
481 <    efree((char *)ln);
481 >    efree(ln);
482   }
483  
484  
# Line 620 | Line 630 | getdefn(void)
630   {
631      EPNODE  *ep1, *ep2;
632  
633 <    if (!isalpha(nextc) && nextc != CNTXMARK)
633 >    if (!isalpha(nextc) & (nextc != CNTXMARK))
634          syntax("illegal variable name");
635  
636      ep1 = newnode();
# Line 639 | Line 649 | getdefn(void)
649              ep2 = newnode();
650              ep2->type = SYM;
651              ep2->v.name = savestr(getname());
652 +            if (strchr(ep2->v.name, CNTXMARK) != NULL)
653 +                syntax("illegal parameter name");
654              addekid(ep1, ep2);
655          } while (nextc == ',');
656          if (nextc != ')')
# Line 647 | Line 659 | getdefn(void)
659          curfunc = ep1;
660      }
661  
662 <    if (nextc != '=' && nextc != ':')
662 >    if ((nextc != '=') & (nextc != ':'))
663          syntax("'=' or ':' expected");
664  
665      ep2 = newnode();
# Line 704 | Line 716 | getchan(void)                  /* A -> $N = E1 */
716  
717  
718   static double                   /* evaluate a variable */
719 < dvalue(char  *name, EPNODE      *d)
719 > dvalue(char *name, EPNODE *d)
720   {
721      EPNODE  *ep1, *ep2;
722      
# Line 716 | Line 728 | dvalue(char  *name, EPNODE     *d)
728      ep1 = d->v.kid->sibling;                    /* get expression */
729      if (ep1->type == NUM)
730          return(ep1->v.num);                     /* return if number */
731 +    if (esupport&E_RCONST && d->type == ':') {
732 +        wputs(name);
733 +        wputs(": assigned non-constant value\n");
734 +    }
735      ep2 = ep1->sibling;                         /* check time */
736      if (eclock >= MAXCLOCK)
737          eclock = 1;                             /* wrap clock counter */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines