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.37 by greg, Sun Oct 1 18:02:23 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 61 | Line 59 | static EPNODE  *ochpos;                        /* ...dnext */
59   static EPNODE  *outchan;
60  
61   EPNODE  *curfunc = NULL;
64 #define  dname(ep)      ((ep)->v.kid->type == SYM ? \
65                        (ep)->v.kid->v.name : \
66                        (ep)->v.kid->v.kid->v.name)
62  
63  
64   void
# Line 80 | Line 75 | fcompile(                      /* get definitions from a file */
75          eputs(": cannot open\n");
76          quit(1);
77      }
78 <    initfile(fp, fname, 0);
78 > #ifdef getc_unlocked                    /* avoid stupid semaphores */
79 >    flockfile(fp);
80 > #endif
81 >   initfile(fp, fname, 0);
82      while (nextc != EOF)
83          getstatement();
84      if (fname != NULL)
85          fclose(fp);
86 + #ifdef getc_unlocked
87 +    else
88 +        funlockfile(fp);
89 + #endif
90   }
91  
92  
# Line 173 | Line 175 | dclear(                        /* delete variable definitions of name */
175          char  *name
176   )
177   {
178 <    EPNODE  *ep;
178 >    VARDEF  *vp;
179 >    EPNODE  *dp;
180  
181 <    while ((ep = dpop(name)) != NULL) {
182 <        if (ep->type == ':') {
183 <            dpush(name, ep);            /* don't clear constants */
184 <            return;
185 <        }
183 <        epfree(ep);
181 >    while ((vp = varlookup(name)) != NULL &&
182 >                (dp = vp->def) != NULL && dp->type == '=') {
183 >        vp->def = dp->sibling;
184 >        epfree(dp);
185 >        varfree(vp);
186      }
187   }
188  
# Line 198 | Line 200 | dremove(                       /* delete all definitions of name */
200  
201  
202   int
203 < vardefined(     /* return non-zero if variable defined */
203 > vardefined(     /* return '=' or ':' if variable/constant defined */
204          char  *name
205   )
206   {
207 <    EPNODE  *dp;
207 >    EPNODE  *dp = dlookup(name);
208  
209 <    return((dp = dlookup(name)) != NULL && dp->v.kid->type == SYM);
209 >    if (dp == NULL || dp->v.kid->type != SYM)
210 >        return(0);
211 >
212 >    return(dp->type);
213   }
214  
215  
216   char *
217 < setcontext(                     /* set a new context path */
217 > calcontext(                     /* set a new context path */
218          char  *ctx
219   )
220   {
# Line 250 | Line 255 | pushcontext(           /* push on another context */
255      int  n;
256  
257      strcpy(oldcontext, context);        /* save old context */
258 <    setcontext(ctx);                    /* set new context */
258 >    calcontext(ctx);                    /* set new context */
259      n = strlen(context);                /* tack on old */
260      if (n+strlen(oldcontext) > MAXCNTX) {
261          strncpy(context+n, oldcontext, MAXCNTX-n);
# Line 287 | Line 292 | qualname(              /* get qualified name */
292      static char  nambuf[RMAXWORD+1];
293      char  *cp = nambuf, *cpp;
294                                  /* check for explicit local */
295 <    if (*nam == CNTXMARK)
295 >    if (*nam == CNTXMARK) {
296          if (lvl > 0)            /* only action is to refuse search */
297              return(NULL);
298 <        else
299 <            nam++;
295 <    else if (nam == nambuf)     /* check for repeat call */
298 >        nam++;
299 >    } else if (nam == nambuf)   /* check for repeat call */
300          return(lvl > 0 ? NULL : nam);
301                                  /* copy name to static buffer */
302      while (*nam) {
# Line 314 | Line 318 | qualname(              /* get qualified name */
318          while (*++cpp && *cpp != CNTXMARK)
319              ;
320      }
321 <    while (*cpp) {              /* copy context to static buffer */
321 >    while (*cpp) {              /* add remaining context to name */
322          if (cp >= nambuf+RMAXWORD)
323              goto toolong;
324          *cp++ = *cpp++;
# Line 368 | Line 372 | dcleanup(              /* clear definitions (0->vars,1->output,2->
372                  else
373                      dclear(vp->name);
374              }
375 <    if (lvl >= 1) {
376 <        for (ep = outchan; ep != NULL; ep = ep->sibling)
375 >    if (lvl >= 1)
376 >        while (outchan != NULL) {
377 >            ep = outchan;
378 >            outchan = ep->sibling;
379 >            ep->sibling = NULL;
380              epfree(ep);
381 <        outchan = NULL;
375 <    }
381 >        }
382   }
383  
384  
# Line 442 | Line 448 | libupdate(                     /* update library links */
448                                          /* if fn is NULL then relink all */
449      for (i = 0; i < NHASH; i++)
450          for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
451 <            if (vp->lib != NULL || fn == NULL || !strcmp(fn, vp->name))
451 >            if ((vp->lib != NULL) | (fn == NULL) || !strcmp(fn, vp->name))
452                  vp->lib = liblookup(vp->name);
453   }
454  
# Line 468 | Line 474 | varfree(                               /* release link to variable */
474          vp->next = ln->next;
475      }
476      freestr(ln->name);
477 <    efree((char *)ln);
477 >    efree(ln);
478   }
479  
480  
# Line 584 | Line 590 | getstatement(void)                     /* get next statement */
590          addchan(ep);
591      } else {                            /* ordinary definition */
592          ep = getdefn();
593 <        qname = qualname(dname(ep), 0);
593 >        qname = qualname(dfn_name(ep), 0);
594          if (esupport&E_REDEFW && (vdef = varlookup(qname)) != NULL) {
595              if (vdef->def != NULL && epcmp(ep, vdef->def)) {
596                  wputs(qname);
# Line 620 | Line 626 | getdefn(void)
626   {
627      EPNODE  *ep1, *ep2;
628  
629 <    if (!isalpha(nextc) && nextc != CNTXMARK)
629 >    if (!isalpha(nextc) & (nextc != CNTXMARK))
630          syntax("illegal variable name");
631  
632      ep1 = newnode();
# Line 639 | Line 645 | getdefn(void)
645              ep2 = newnode();
646              ep2->type = SYM;
647              ep2->v.name = savestr(getname());
648 +            if (strchr(ep2->v.name, CNTXMARK) != NULL)
649 +                syntax("illegal parameter name");
650              addekid(ep1, ep2);
651          } while (nextc == ',');
652          if (nextc != ')')
# Line 647 | Line 655 | getdefn(void)
655          curfunc = ep1;
656      }
657  
658 <    if (nextc != '=' && nextc != ':')
658 >    if ((nextc != '=') & (nextc != ':'))
659          syntax("'=' or ':' expected");
660  
661      ep2 = newnode();
# Line 704 | Line 712 | getchan(void)                  /* A -> $N = E1 */
712  
713  
714   static double                   /* evaluate a variable */
715 < dvalue(char  *name, EPNODE      *d)
715 > dvalue(char *name, EPNODE *d)
716   {
717      EPNODE  *ep1, *ep2;
718      
# Line 716 | Line 724 | dvalue(char  *name, EPNODE     *d)
724      ep1 = d->v.kid->sibling;                    /* get expression */
725      if (ep1->type == NUM)
726          return(ep1->v.num);                     /* return if number */
727 +    if (esupport&E_RCONST && d->type == ':') {
728 +        wputs(name);
729 +        wputs(": assigned non-constant value\n");
730 +    }
731      ep2 = ep1->sibling;                         /* check time */
732      if (eclock >= MAXCLOCK)
733          eclock = 1;                             /* wrap clock counter */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines