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 1.16 by greg, Thu Aug 8 14:38:00 1991 UTC vs.
Revision 2.1 by greg, Tue Nov 12 16:55:27 1991 UTC

# Line 38 | Line 38 | static char SCCSid[] = "$SunId$ LBL";
38  
39   extern char  *ecalloc(), *savestr(), *strcpy();
40  
41 + static int  hash();
42 +
43   static double  dvalue();
44  
45   long  eclock = -1;                      /* value storage timer */
46  
47 < static char  context[MAXWORD];          /* current context path */
47 > static char  context[MAXWORD+1];        /* current context path */
48  
49   static VARDEF  *hashtbl[NHASH];         /* definition list */
50   static int  htndx;                      /* index for */        
# Line 195 | Line 197 | register char  *ctx;
197      if (*ctx != CNTXMARK)
198          *cpp++ = CNTXMARK;              /* make sure there's a mark */
199      do {
200 <        if (cpp >= context+MAXWORD-1) {
201 <            *cpp = '\0';
200 <            wputs(context);
201 <            wputs(": context path too long\n");
202 <            return(NULL);
203 <        }
200 >        if (cpp >= context+MAXWORD)
201 >            break;                      /* just copy what we can */
202          if (isid(*ctx))
203              *cpp++ = *ctx++;
204          else {
# Line 217 | Line 215 | qualname(nam, lvl)             /* get qualified name */
215   register char  *nam;
216   int  lvl;
217   {
218 <    static char  nambuf[MAXWORD];
219 <    register char  *cp = nambuf, *cpp = context;
220 <                                /* check for explicit global */
218 >    static char  nambuf[MAXWORD+1];
219 >    register char  *cp = nambuf, *cpp;
220 >                                /* check for explicit local */
221      if (*nam == CNTXMARK)
222 <        return(lvl > 0 ? NULL : nam+1);
223 <                                /* check for repeat call */
224 <    if (nam == nambuf)
225 <        return(lvl > 0 ? NULL : nambuf);
222 >        if (lvl > 0)            /* only action is to refuse search */
223 >            return(NULL);
224 >        else
225 >            nam++;
226 >    else if (nam == nambuf)     /* check for repeat call */
227 >        return(lvl > 0 ? NULL : nam);
228                                  /* copy name to static buffer */
229      while (*nam) {
230 <        if (cp >= nambuf+MAXWORD-1)
230 >        if (cp >= nambuf+MAXWORD)
231                  goto toolong;
232 <        if ((*cp++ = *nam++) == CNTXMARK)
233 <            cpp = NULL;         /* flag a qualified name */
232 >        *cp++ = *nam++;
233      }
234 <    if (cpp == NULL) {
234 >                                /* check for explicit global */
235 >    if (cp > nambuf && cp[-1] == CNTXMARK) {
236          if (lvl > 0)
237 <            return(NULL);               /* no higher level */
238 <        if (cp[-1] == CNTXMARK) {
239 <            cp--; cpp = context;        /* current context explicitly */
240 <        } else
241 <            cpp = "";                   /* else fully qualified */
242 <    } else                      /* else skip the requested levels */
243 <        while (lvl-- > 0) {
244 <            if (!*cpp)
245 <                return(NULL);   /* return NULL if past global level */
246 <            while (*++cpp && *cpp != CNTXMARK)
247 <                ;
248 <        }
237 >            return(NULL);
238 >        *--cp = '\0';
239 >        return(nambuf);         /* already qualified */
240 >    }
241 >    cpp = context;              /* else skip the requested levels */
242 >    while (lvl-- > 0) {
243 >        if (!*cpp)
244 >            return(NULL);       /* return NULL if past global level */
245 >        while (*++cpp && *cpp != CNTXMARK)
246 >            ;
247 >    }
248      while (*cpp) {              /* copy context to static buffer */
249 <        if (cp >= nambuf+MAXWORD-1)
249 >        if (cp >= nambuf+MAXWORD)
250              goto toolong;
251          *cp++ = *cpp++;
252      }
254    *cp = '\0';
255    return(nambuf);             /* return qualified name */
253   toolong:
254      *cp = '\0';
255 <    eputs(nambuf);
259 <    eputs(": name too long\n");
260 <    quit(1);
255 >    return(nambuf);             /* return qualified name */
256   }
257  
258  
# Line 265 | Line 260 | incontext(qn)                  /* is qualified name in current contex
260   register char  *qn;
261   {
262      while (*qn && *qn != CNTXMARK)      /* find context mark */
263 <        ;
263 >        qn++;
264      return(!strcmp(qn, context));
265   }
266  
# Line 405 | Line 400 | EPNODE *
400   dnext()                         /* return pointer to next definition */
401   {
402      register EPNODE  *ep;
403 +    register char  *nm;
404  
405      while (htndx < NHASH) {
406          if (htpos == NULL)
407                  htpos = hashtbl[htndx++];
408          while (htpos != NULL) {
409              ep = htpos->def;
410 +            nm = htpos->name;
411              htpos = htpos->next;
412 <            if (ep != NULL)
412 >            if (ep != NULL && incontext(nm))
413                  return(ep);
414          }
415      }
# Line 542 | Line 539 | getdefn()                      /* A -> SYM = E1 */
539   {
540      register EPNODE  *ep1, *ep2;
541  
542 <    if (!isalpha(nextc))
542 >    if (!isalpha(nextc) && nextc != CNTXMARK)
543          syntax("illegal variable name");
544  
545      ep1 = newnode();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines