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.12 by greg, Sat Feb 22 02:07:21 2003 UTC vs.
Revision 2.21 by schorsch, Mon Oct 27 10:19:31 2003 UTC

# Line 25 | Line 25 | static const char      RCSid[] = "$Id$";
25   *  2/19/03     Eliminated conditional compiles in favor of esupport extern.
26   */
27  
28 < /* ====================================================================
29 < * The Radiance Software License, Version 1.0
30 < *
31 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
32 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
33 < *
34 < * Redistribution and use in source and binary forms, with or without
35 < * modification, are permitted provided that the following conditions
36 < * are met:
37 < *
38 < * 1. Redistributions of source code must retain the above copyright
39 < *         notice, this list of conditions and the following disclaimer.
40 < *
41 < * 2. Redistributions in binary form must reproduce the above copyright
42 < *       notice, this list of conditions and the following disclaimer in
43 < *       the documentation and/or other materials provided with the
44 < *       distribution.
45 < *
46 < * 3. The end-user documentation included with the redistribution,
47 < *           if any, must include the following acknowledgment:
48 < *             "This product includes Radiance software
49 < *                 (http://radsite.lbl.gov/)
50 < *                 developed by the Lawrence Berkeley National Laboratory
51 < *               (http://www.lbl.gov/)."
52 < *       Alternately, this acknowledgment may appear in the software itself,
53 < *       if and wherever such third-party acknowledgments normally appear.
54 < *
55 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
56 < *       and "The Regents of the University of California" must
57 < *       not be used to endorse or promote products derived from this
58 < *       software without prior written permission. For written
59 < *       permission, please contact [email protected].
60 < *
61 < * 5. Products derived from this software may not be called "Radiance",
62 < *       nor may "Radiance" appear in their name, without prior written
63 < *       permission of Lawrence Berkeley National Laboratory.
64 < *
65 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
66 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
67 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
68 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
69 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
70 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
71 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
72 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
73 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
74 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
75 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
76 < * SUCH DAMAGE.
77 < * ====================================================================
78 < *
79 < * This software consists of voluntary contributions made by many
80 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
81 < * information on Lawrence Berkeley National Laboratory, please see
82 < * <http://www.lbl.gov/>.
83 < */
28 > #include "copyright.h"
29  
30   #include  <stdio.h>
86
31   #include  <string.h>
88
32   #include  <ctype.h>
33  
34 + #include  "rterror.h"
35 + #include  "rtmisc.h"
36   #include  "calcomp.h"
37  
38   #ifndef  NHASH
# Line 98 | Line 43 | static const char      RCSid[] = "$Id$";
43  
44   #define  newnode()      (EPNODE *)ecalloc(1, sizeof(EPNODE))
45  
46 < static double  dvalue();
46 > static double  dvalue(char  *name, EPNODE *d);
47  
48   #define  MAXCLOCK       (1L<<31)        /* clock wrap value */
49  
# Line 121 | Line 66 | EPNODE *curfunc = NULL;
66  
67  
68   void
69 < fcompile(fname)                 /* get definitions from a file */
70 < char  *fname;
69 > fcompile(                       /* get definitions from a file */
70 >        char  *fname
71 > )
72   {
73      FILE  *fp;
74  
# Line 142 | Line 88 | char  *fname;
88  
89  
90   void
91 < scompile(str, fn, ln)           /* get definitions from a string */
92 < char  *str;
93 < char  *fn;
94 < int  ln;
91 > scompile(               /* get definitions from a string */
92 >        char  *str,
93 >        char  *fn,
94 >        int  ln
95 > )
96   {
97      initstr(str, fn, ln);
98      while (nextc != EOF)
# Line 154 | Line 101 | int  ln;
101  
102  
103   double
104 < varvalue(vname)                 /* return a variable's value */
105 < char  *vname;
104 > varvalue(                       /* return a variable's value */
105 >        char  *vname
106 > )
107   {
108      return(dvalue(vname, dlookup(vname)));
109   }
110  
111  
112   double
113 < evariable(ep)                   /* evaluate a variable */
114 < EPNODE  *ep;
113 > evariable(                      /* evaluate a variable */
114 >        EPNODE  *ep
115 > )
116   {
117      register VARDEF  *dp = ep->v.ln;
118  
# Line 172 | Line 121 | EPNODE *ep;
121  
122  
123   void
124 < varset(vname, assign, val)      /* set a variable's value */
125 < char  *vname;
126 < int  assign;
127 < double  val;
124 > varset(         /* set a variable's value */
125 >        char  *vname,
126 >        int  assign,
127 >        double  val
128 > )
129   {
130      char  *qname;
131      register EPNODE  *ep1, *ep2;
# Line 207 | Line 157 | double val;
157  
158  
159   void
160 < dclear(name)                    /* delete variable definitions of name */
161 < char  *name;
160 > dclear(                 /* delete variable definitions of name */
161 >        char  *name
162 > )
163   {
164      register EPNODE  *ep;
165  
# Line 223 | Line 174 | char  *name;
174  
175  
176   void
177 < dremove(name)                   /* delete all definitions of name */
178 < char  *name;
177 > dremove(                        /* delete all definitions of name */
178 >        char  *name
179 > )
180   {
181      register EPNODE  *ep;
182  
# Line 234 | Line 186 | char  *name;
186  
187  
188   int
189 < vardefined(name)        /* return non-zero if variable defined */
190 < char  *name;
189 > vardefined(     /* return non-zero if variable defined */
190 >        char  *name
191 > )
192   {
193      register EPNODE  *dp;
194  
# Line 244 | Line 197 | char  *name;
197  
198  
199   char *
200 < setcontext(ctx)                 /* set a new context path */
201 < register char  *ctx;
200 > setcontext(                     /* set a new context path */
201 >        register char  *ctx
202 > )
203   {
204      register char  *cpp;
205  
# Line 276 | Line 230 | register char  *ctx;
230  
231  
232   char *
233 < pushcontext(ctx)                /* push on another context */
234 < char  *ctx;
233 > pushcontext(            /* push on another context */
234 >        char  *ctx
235 > )
236   {
282    extern char  *strncpy(), *strcpy();
237      char  oldcontext[MAXCNTX+1];
238      register int  n;
239  
# Line 296 | Line 250 | char  *ctx;
250  
251  
252   char *
253 < popcontext()                    /* pop off top context */
253 > popcontext(void)                        /* pop off top context */
254   {
255      register char  *cp1, *cp2;
256  
# Line 306 | Line 260 | popcontext()                   /* pop off top context */
260      while (*++cp2 && *cp2 != CNTXMARK)
261          ;
262      cp1 = context;                      /* copy tail to front */
263 <    while (*cp1++ = *cp2++)
263 >    while ( (*cp1++ = *cp2++) )
264          ;
265      return(context);
266   }
267  
268  
269   char *
270 < qualname(nam, lvl)              /* get qualified name */
271 < register char  *nam;
272 < int  lvl;
270 > qualname(               /* get qualified name */
271 >        register char  *nam,
272 >        int  lvl
273 > )
274   {
275 <    static char  nambuf[MAXWORD+1];
275 >    static char  nambuf[RMAXWORD+1];
276      register char  *cp = nambuf, *cpp;
277                                  /* check for explicit local */
278      if (*nam == CNTXMARK)
# Line 329 | Line 284 | int  lvl;
284          return(lvl > 0 ? NULL : nam);
285                                  /* copy name to static buffer */
286      while (*nam) {
287 <        if (cp >= nambuf+MAXWORD)
287 >        if (cp >= nambuf+RMAXWORD)
288                  goto toolong;
289          *cp++ = *nam++;
290      }
# Line 348 | Line 303 | int  lvl;
303              ;
304      }
305      while (*cpp) {              /* copy context to static buffer */
306 <        if (cp >= nambuf+MAXWORD)
306 >        if (cp >= nambuf+RMAXWORD)
307              goto toolong;
308          *cp++ = *cpp++;
309      }
# Line 359 | Line 314 | toolong:
314  
315  
316   int
317 < incontext(qn)                   /* is qualified name in current context? */
318 < register char  *qn;
317 > incontext(                      /* is qualified name in current context? */
318 >        register char  *qn
319 > )
320   {
321      if (!context[0])                    /* global context accepts all */
322          return(1);
# Line 371 | Line 327 | register char  *qn;
327  
328  
329   void
330 < chanout(cs)                     /* set output channels */
331 < int  (*cs)();
330 > chanout(                        /* set output channels */
331 >        void  (*cs)(int n, double v)
332 > )
333   {
334      register EPNODE  *ep;
335  
# Line 383 | Line 340 | int  (*cs)();
340  
341  
342   void
343 < dcleanup(lvl)           /* clear definitions (0->vars,1->output,2->consts) */
344 < int  lvl;
343 > dcleanup(               /* clear definitions (0->vars,1->output,2->consts) */
344 >        int  lvl
345 > )
346   {
347      register int  i;
348      register VARDEF  *vp;
# Line 392 | Line 350 | int  lvl;
350                                  /* if context is global, clear all */
351      for (i = 0; i < NHASH; i++)
352          for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
353 <            if (incontext(vp->name))
353 >            if (incontext(vp->name)) {
354                  if (lvl >= 2)
355                      dremove(vp->name);
356                  else
357                      dclear(vp->name);
358 +            }
359      if (lvl >= 1) {
360          for (ep = outchan; ep != NULL; ep = ep->sibling)
361              epfree(ep);
# Line 406 | Line 365 | int  lvl;
365  
366  
367   EPNODE *
368 < dlookup(name)                   /* look up a definition */
369 < char  *name;
368 > dlookup(                        /* look up a definition */
369 >        char  *name
370 > )
371   {
372      register VARDEF  *vp;
373      
# Line 418 | Line 378 | char  *name;
378  
379  
380   VARDEF *
381 < varlookup(name)                 /* look up a variable */
382 < char  *name;
381 > varlookup(                      /* look up a variable */
382 >        char  *name
383 > )
384   {
385      int  lvl = 0;
386      register char  *qname;
# Line 434 | Line 395 | char  *name;
395  
396  
397   VARDEF *
398 < varinsert(name)                 /* get a link to a variable */
399 < char  *name;
398 > varinsert(                      /* get a link to a variable */
399 >        char  *name
400 > )
401   {
402      register VARDEF  *vp;
403      int  hv;
# Line 459 | Line 421 | char  *name;
421  
422  
423   void
424 < libupdate(fn)                   /* update library links */
425 < char  *fn;
424 > libupdate(                      /* update library links */
425 >        char  *fn
426 > )
427   {
428      register int  i;
429      register VARDEF  *vp;
# Line 473 | Line 436 | char  *fn;
436  
437  
438   void
439 < varfree(ln)                             /* release link to variable */
440 < register VARDEF  *ln;
439 > varfree(                                /* release link to variable */
440 >        register VARDEF  *ln
441 > )
442   {
443      register VARDEF  *vp;
444      int  hv;
# Line 497 | Line 461 | register VARDEF         *ln;
461  
462  
463   EPNODE *
464 < dfirst()                        /* return pointer to first definition */
464 > dfirst(void)                    /* return pointer to first definition */
465   {
466      htndx = 0;
467      htpos = NULL;
# Line 507 | Line 471 | dfirst()                       /* return pointer to first definition */
471  
472  
473   EPNODE *
474 < dnext()                         /* return pointer to next definition */
474 > dnext(void)                             /* return pointer to next definition */
475   {
476      register EPNODE  *ep;
477      register char  *nm;
# Line 530 | Line 494 | dnext()                                /* return pointer to next definition */
494  
495  
496   EPNODE *
497 < dpop(name)                      /* pop a definition */
498 < char  *name;
497 > dpop(                   /* pop a definition */
498 >        char  *name
499 > )
500   {
501      register VARDEF  *vp;
502      register EPNODE  *dp;
# Line 546 | Line 511 | char  *name;
511  
512  
513   void
514 < dpush(nm, ep)                   /* push on a definition */
515 < char  *nm;
516 < register EPNODE  *ep;
514 > dpush(                  /* push on a definition */
515 >        char  *nm,
516 >        register EPNODE  *ep
517 > )
518   {
519      register VARDEF  *vp;
520  
# Line 559 | Line 525 | register EPNODE         *ep;
525  
526  
527   void
528 < addchan(sp)                     /* add an output channel assignment */
529 < EPNODE  *sp;
528 > addchan(                        /* add an output channel assignment */
529 >        EPNODE  *sp
530 > )
531   {
532      int  ch = sp->v.kid->v.chan;
533      register EPNODE  *ep, *epl;
# Line 589 | Line 556 | EPNODE *sp;
556  
557  
558   void
559 < getstatement()                  /* get next statement */
559 > getstatement(void)                      /* get next statement */
560   {
561      register EPNODE  *ep;
562      char  *qname;
# Line 606 | Line 573 | getstatement()                 /* get next statement */
573      } else {                            /* ordinary definition */
574          ep = getdefn();
575          qname = qualname(dname(ep), 0);
576 <        if (esupport&E_REDEFW && (vdef = varlookup(qname)) != NULL)
576 >        if (esupport&E_REDEFW && (vdef = varlookup(qname)) != NULL) {
577              if (vdef->def != NULL && epcmp(ep, vdef->def)) {
578                  wputs(qname);
579                  if (vdef->def->type == ':')
# Line 617 | Line 584 | getstatement()                 /* get next statement */
584                  wputs(qname);
585                  wputs(": definition hides library function\n");
586              }
587 +        }
588          if (ep->type == ':')
589              dremove(qname);
590          else
# Line 632 | Line 600 | getstatement()                 /* get next statement */
600  
601  
602   EPNODE *
603 < getdefn()                       /* A -> SYM = E1 */
604 <                                /*      SYM : E1 */
605 <                                /*      FUNC(SYM,..) = E1 */
606 <                                /*      FUNC(SYM,..) : E1 */
603 > getdefn(void)
604 >        /* A -> SYM = E1 */
605 >        /*      SYM : E1 */
606 >        /*      FUNC(SYM,..) = E1 */
607 >        /*      FUNC(SYM,..) : E1 */
608   {
609      register EPNODE  *ep1, *ep2;
610  
# Line 691 | Line 660 | getdefn()                      /* A -> SYM = E1 */
660  
661  
662   EPNODE *
663 < getchan()                       /* A -> $N = E1 */
663 > getchan(void)                   /* A -> $N = E1 */
664   {
665      register EPNODE  *ep1, *ep2;
666  
# Line 722 | Line 691 | getchan()                      /* A -> $N = E1 */
691   */
692  
693  
694 < static double
695 < dvalue(name, d)                 /* evaluate a variable */
727 < char  *name;
728 < EPNODE  *d;
694 > static double                   /* evaluate a variable */
695 > dvalue(char  *name, EPNODE      *d)
696   {
697      register EPNODE  *ep1, *ep2;
698      
# Line 741 | Line 708 | EPNODE *d;
708      if (eclock >= MAXCLOCK)
709          eclock = 1;                             /* wrap clock counter */
710      if (ep2->v.tick < MAXCLOCK &&
711 <                ep2->v.tick == 0 | ep2->v.tick != eclock) {
711 >                (ep2->v.tick == 0) | (ep2->v.tick != eclock)) {
712          ep2->v.tick = d->type == ':' ? MAXCLOCK : eclock;
713          ep2 = ep2->sibling;
714          ep2->v.num = evalue(ep1);               /* needs new value */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines