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.24 by greg, Fri Mar 5 17:28:46 2010 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  "rtio.h"
36 + #include  "rtmisc.h"
37   #include  "calcomp.h"
38  
39   #ifndef  NHASH
# Line 98 | Line 44 | static const char      RCSid[] = "$Id$";
44  
45   #define  newnode()      (EPNODE *)ecalloc(1, sizeof(EPNODE))
46  
47 < static double  dvalue();
47 > static double  dvalue(char  *name, EPNODE *d);
48  
49   #define  MAXCLOCK       (1L<<31)        /* clock wrap value */
50  
# Line 121 | Line 67 | EPNODE *curfunc = NULL;
67  
68  
69   void
70 < fcompile(fname)                 /* get definitions from a file */
71 < char  *fname;
70 > fcompile(                       /* get definitions from a file */
71 >        char  *fname
72 > )
73   {
74      FILE  *fp;
75  
# Line 142 | Line 89 | char  *fname;
89  
90  
91   void
92 < scompile(str, fn, ln)           /* get definitions from a string */
93 < char  *str;
94 < char  *fn;
95 < int  ln;
92 > scompile(               /* get definitions from a string */
93 >        char  *str,
94 >        char  *fn,
95 >        int  ln
96 > )
97   {
98      initstr(str, fn, ln);
99      while (nextc != EOF)
# Line 154 | Line 102 | int  ln;
102  
103  
104   double
105 < varvalue(vname)                 /* return a variable's value */
106 < char  *vname;
105 > varvalue(                       /* return a variable's value */
106 >        char  *vname
107 > )
108   {
109      return(dvalue(vname, dlookup(vname)));
110   }
111  
112  
113   double
114 < evariable(ep)                   /* evaluate a variable */
115 < EPNODE  *ep;
114 > evariable(                      /* evaluate a variable */
115 >        EPNODE  *ep
116 > )
117   {
118      register VARDEF  *dp = ep->v.ln;
119  
# Line 172 | Line 122 | EPNODE *ep;
122  
123  
124   void
125 < varset(vname, assign, val)      /* set a variable's value */
126 < char  *vname;
127 < int  assign;
128 < double  val;
125 > varset(         /* set a variable's value */
126 >        char  *vname,
127 >        int  assign,
128 >        double  val
129 > )
130   {
131      char  *qname;
132      register EPNODE  *ep1, *ep2;
# Line 207 | Line 158 | double val;
158  
159  
160   void
161 < dclear(name)                    /* delete variable definitions of name */
162 < char  *name;
161 > dclear(                 /* delete variable definitions of name */
162 >        char  *name
163 > )
164   {
165      register EPNODE  *ep;
166  
# Line 223 | Line 175 | char  *name;
175  
176  
177   void
178 < dremove(name)                   /* delete all definitions of name */
179 < char  *name;
178 > dremove(                        /* delete all definitions of name */
179 >        char  *name
180 > )
181   {
182      register EPNODE  *ep;
183  
# Line 234 | Line 187 | char  *name;
187  
188  
189   int
190 < vardefined(name)        /* return non-zero if variable defined */
191 < char  *name;
190 > vardefined(     /* return non-zero if variable defined */
191 >        char  *name
192 > )
193   {
194      register EPNODE  *dp;
195  
# Line 244 | Line 198 | char  *name;
198  
199  
200   char *
201 < setcontext(ctx)                 /* set a new context path */
202 < register char  *ctx;
201 > setcontext(                     /* set a new context path */
202 >        register char  *ctx
203 > )
204   {
205      register char  *cpp;
206  
# Line 276 | Line 231 | register char  *ctx;
231  
232  
233   char *
234 < pushcontext(ctx)                /* push on another context */
235 < char  *ctx;
234 > pushcontext(            /* push on another context */
235 >        char  *ctx
236 > )
237   {
282    extern char  *strncpy(), *strcpy();
238      char  oldcontext[MAXCNTX+1];
239      register int  n;
240  
# Line 296 | Line 251 | char  *ctx;
251  
252  
253   char *
254 < popcontext()                    /* pop off top context */
254 > popcontext(void)                        /* pop off top context */
255   {
256      register char  *cp1, *cp2;
257  
# Line 306 | Line 261 | popcontext()                   /* pop off top context */
261      while (*++cp2 && *cp2 != CNTXMARK)
262          ;
263      cp1 = context;                      /* copy tail to front */
264 <    while (*cp1++ = *cp2++)
264 >    while ( (*cp1++ = *cp2++) )
265          ;
266      return(context);
267   }
268  
269  
270   char *
271 < qualname(nam, lvl)              /* get qualified name */
272 < register char  *nam;
273 < int  lvl;
271 > qualname(               /* get qualified name */
272 >        register char  *nam,
273 >        int  lvl
274 > )
275   {
276 <    static char  nambuf[MAXWORD+1];
276 >    static char  nambuf[RMAXWORD+1];
277      register char  *cp = nambuf, *cpp;
278                                  /* check for explicit local */
279      if (*nam == CNTXMARK)
# Line 329 | Line 285 | int  lvl;
285          return(lvl > 0 ? NULL : nam);
286                                  /* copy name to static buffer */
287      while (*nam) {
288 <        if (cp >= nambuf+MAXWORD)
288 >        if (cp >= nambuf+RMAXWORD)
289                  goto toolong;
290          *cp++ = *nam++;
291      }
# Line 348 | Line 304 | int  lvl;
304              ;
305      }
306      while (*cpp) {              /* copy context to static buffer */
307 <        if (cp >= nambuf+MAXWORD)
307 >        if (cp >= nambuf+RMAXWORD)
308              goto toolong;
309          *cp++ = *cpp++;
310      }
# Line 359 | Line 315 | toolong:
315  
316  
317   int
318 < incontext(qn)                   /* is qualified name in current context? */
319 < register char  *qn;
318 > incontext(                      /* is qualified name in current context? */
319 >        register char  *qn
320 > )
321   {
322      if (!context[0])                    /* global context accepts all */
323          return(1);
# Line 371 | Line 328 | register char  *qn;
328  
329  
330   void
331 < chanout(cs)                     /* set output channels */
332 < int  (*cs)();
331 > chanout(                        /* set output channels */
332 >        void  (*cs)(int n, double v)
333 > )
334   {
335      register EPNODE  *ep;
336  
# Line 383 | Line 341 | int  (*cs)();
341  
342  
343   void
344 < dcleanup(lvl)           /* clear definitions (0->vars,1->output,2->consts) */
345 < int  lvl;
344 > dcleanup(               /* clear definitions (0->vars,1->output,2->consts) */
345 >        int  lvl
346 > )
347   {
348      register int  i;
349      register VARDEF  *vp;
# Line 392 | Line 351 | int  lvl;
351                                  /* if context is global, clear all */
352      for (i = 0; i < NHASH; i++)
353          for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
354 <            if (incontext(vp->name))
354 >            if (incontext(vp->name)) {
355                  if (lvl >= 2)
356                      dremove(vp->name);
357                  else
358                      dclear(vp->name);
359 +            }
360      if (lvl >= 1) {
361          for (ep = outchan; ep != NULL; ep = ep->sibling)
362              epfree(ep);
# Line 406 | Line 366 | int  lvl;
366  
367  
368   EPNODE *
369 < dlookup(name)                   /* look up a definition */
370 < char  *name;
369 > dlookup(                        /* look up a definition */
370 >        char  *name
371 > )
372   {
373      register VARDEF  *vp;
374      
# Line 418 | Line 379 | char  *name;
379  
380  
381   VARDEF *
382 < varlookup(name)                 /* look up a variable */
383 < char  *name;
382 > varlookup(                      /* look up a variable */
383 >        char  *name
384 > )
385   {
386      int  lvl = 0;
387      register char  *qname;
# Line 434 | Line 396 | char  *name;
396  
397  
398   VARDEF *
399 < varinsert(name)                 /* get a link to a variable */
400 < char  *name;
399 > varinsert(                      /* get a link to a variable */
400 >        char  *name
401 > )
402   {
403      register VARDEF  *vp;
404      int  hv;
# Line 459 | Line 422 | char  *name;
422  
423  
424   void
425 < libupdate(fn)                   /* update library links */
426 < char  *fn;
425 > libupdate(                      /* update library links */
426 >        char  *fn
427 > )
428   {
429      register int  i;
430      register VARDEF  *vp;
# Line 473 | Line 437 | char  *fn;
437  
438  
439   void
440 < varfree(ln)                             /* release link to variable */
441 < register VARDEF  *ln;
440 > varfree(                                /* release link to variable */
441 >        register VARDEF  *ln
442 > )
443   {
444      register VARDEF  *vp;
445      int  hv;
# Line 497 | Line 462 | register VARDEF         *ln;
462  
463  
464   EPNODE *
465 < dfirst()                        /* return pointer to first definition */
465 > dfirst(void)                    /* return pointer to first definition */
466   {
467      htndx = 0;
468      htpos = NULL;
# Line 507 | Line 472 | dfirst()                       /* return pointer to first definition */
472  
473  
474   EPNODE *
475 < dnext()                         /* return pointer to next definition */
475 > dnext(void)                             /* return pointer to next definition */
476   {
477      register EPNODE  *ep;
478      register char  *nm;
# Line 530 | Line 495 | dnext()                                /* return pointer to next definition */
495  
496  
497   EPNODE *
498 < dpop(name)                      /* pop a definition */
499 < char  *name;
498 > dpop(                   /* pop a definition */
499 >        char  *name
500 > )
501   {
502      register VARDEF  *vp;
503      register EPNODE  *dp;
# Line 546 | Line 512 | char  *name;
512  
513  
514   void
515 < dpush(nm, ep)                   /* push on a definition */
516 < char  *nm;
517 < register EPNODE  *ep;
515 > dpush(                  /* push on a definition */
516 >        char  *nm,
517 >        register EPNODE  *ep
518 > )
519   {
520      register VARDEF  *vp;
521  
# Line 559 | Line 526 | register EPNODE         *ep;
526  
527  
528   void
529 < addchan(sp)                     /* add an output channel assignment */
530 < EPNODE  *sp;
529 > addchan(                        /* add an output channel assignment */
530 >        EPNODE  *sp
531 > )
532   {
533      int  ch = sp->v.kid->v.chan;
534      register EPNODE  *ep, *epl;
# Line 589 | Line 557 | EPNODE *sp;
557  
558  
559   void
560 < getstatement()                  /* get next statement */
560 > getstatement(void)                      /* get next statement */
561   {
562      register EPNODE  *ep;
563      char  *qname;
# Line 606 | Line 574 | getstatement()                 /* get next statement */
574      } else {                            /* ordinary definition */
575          ep = getdefn();
576          qname = qualname(dname(ep), 0);
577 <        if (esupport&E_REDEFW && (vdef = varlookup(qname)) != NULL)
577 >        if (esupport&E_REDEFW && (vdef = varlookup(qname)) != NULL) {
578              if (vdef->def != NULL && epcmp(ep, vdef->def)) {
579                  wputs(qname);
580                  if (vdef->def->type == ':')
# Line 617 | Line 585 | getstatement()                 /* get next statement */
585                  wputs(qname);
586                  wputs(": definition hides library function\n");
587              }
588 +        }
589          if (ep->type == ':')
590              dremove(qname);
591          else
# Line 632 | Line 601 | getstatement()                 /* get next statement */
601  
602  
603   EPNODE *
604 < getdefn()                       /* A -> SYM = E1 */
605 <                                /*      SYM : E1 */
606 <                                /*      FUNC(SYM,..) = E1 */
607 <                                /*      FUNC(SYM,..) : E1 */
604 > getdefn(void)
605 >        /* A -> SYM = E1 */
606 >        /*      SYM : E1 */
607 >        /*      FUNC(SYM,..) = E1 */
608 >        /*      FUNC(SYM,..) : E1 */
609   {
610      register EPNODE  *ep1, *ep2;
611  
# Line 654 | Line 624 | getdefn()                      /* A -> SYM = E1 */
624          do {
625              scan();
626              if (!isalpha(nextc))
627 <                syntax("illegal variable name");
627 >                syntax("illegal parameter name");
628              ep2 = newnode();
629              ep2->type = SYM;
630              ep2->v.name = savestr(getname());
# Line 677 | Line 647 | getdefn()                      /* A -> SYM = E1 */
647  
648      if (ep1->type == SYM && ep1->sibling->type != NUM) {
649          ep1 = newnode();
650 <        ep1->type = TICK;
650 >        ep1->type = CLKT;
651          ep1->v.tick = 0;
652          addekid(ep2, ep1);
653          ep1 = newnode();
# Line 691 | Line 661 | getdefn()                      /* A -> SYM = E1 */
661  
662  
663   EPNODE *
664 < getchan()                       /* A -> $N = E1 */
664 > getchan(void)                   /* A -> $N = E1 */
665   {
666      register EPNODE  *ep1, *ep2;
667  
# Line 722 | Line 692 | getchan()                      /* A -> $N = E1 */
692   */
693  
694  
695 < static double
696 < dvalue(name, d)                 /* evaluate a variable */
727 < char  *name;
728 < EPNODE  *d;
695 > static double                   /* evaluate a variable */
696 > dvalue(char  *name, EPNODE      *d)
697   {
698      register EPNODE  *ep1, *ep2;
699      
# Line 741 | Line 709 | EPNODE *d;
709      if (eclock >= MAXCLOCK)
710          eclock = 1;                             /* wrap clock counter */
711      if (ep2->v.tick < MAXCLOCK &&
712 <                ep2->v.tick == 0 | ep2->v.tick != eclock) {
712 >                (ep2->v.tick == 0) | (ep2->v.tick != eclock)) {
713          ep2->v.tick = d->type == ':' ? MAXCLOCK : eclock;
714          ep2 = ep2->sibling;
715          ep2->v.num = evalue(ep1);               /* needs new value */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines