ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/readobj.c
(Generate patch)

Comparing ray/src/common/readobj.c (file contents):
Revision 2.8 by greg, Sat Feb 22 02:07:22 2003 UTC vs.
Revision 2.29 by greg, Sat Jun 7 05:09:45 2025 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static const char       RCSid[] = "$Id$";
2 > static const char RCSid[] = "$Id$";
3   #endif
4   /*
5   *  readobj.c - routines for reading in object descriptions.
# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *  External symbols declared in object.h
8   */
9  
10 < /* ====================================================================
11 < * The Radiance Software License, Version 1.0
12 < *
13 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
14 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
15 < *
16 < * Redistribution and use in source and binary forms, with or without
17 < * modification, are permitted provided that the following conditions
18 < * are met:
19 < *
20 < * 1. Redistributions of source code must retain the above copyright
21 < *         notice, this list of conditions and the following disclaimer.
22 < *
23 < * 2. Redistributions in binary form must reproduce the above copyright
24 < *       notice, this list of conditions and the following disclaimer in
25 < *       the documentation and/or other materials provided with the
26 < *       distribution.
27 < *
28 < * 3. The end-user documentation included with the redistribution,
29 < *           if any, must include the following acknowledgment:
30 < *             "This product includes Radiance software
31 < *                 (http://radsite.lbl.gov/)
32 < *                 developed by the Lawrence Berkeley National Laboratory
33 < *               (http://www.lbl.gov/)."
34 < *       Alternately, this acknowledgment may appear in the software itself,
35 < *       if and wherever such third-party acknowledgments normally appear.
36 < *
37 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
38 < *       and "The Regents of the University of California" must
39 < *       not be used to endorse or promote products derived from this
40 < *       software without prior written permission. For written
41 < *       permission, please contact [email protected].
42 < *
43 < * 5. Products derived from this software may not be called "Radiance",
44 < *       nor may "Radiance" appear in their name, without prior written
45 < *       permission of Lawrence Berkeley National Laboratory.
46 < *
47 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
48 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
51 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
54 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
56 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 < * SUCH DAMAGE.
59 < * ====================================================================
60 < *
61 < * This software consists of voluntary contributions made by many
62 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
63 < * information on Lawrence Berkeley National Laboratory, please see
64 < * <http://www.lbl.gov/>.
65 < */
10 > #include "copyright.h"
11  
12 < #include  "standard.h"
12 > #include  <ctype.h>
13 > #include  <string.h>
14 > #include  <stdio.h>
15  
16 + #include  "platform.h"
17 + #include  "standard.h"
18   #include  "object.h"
70
19   #include  "otypes.h"
20  
73 #include  <ctype.h>
21  
22   OBJREC  *objblock[MAXOBJBLK];           /* our objects */
23   OBJECT  nobjects = 0;                   /* # of objects */
24  
25  
26   void
27 < readobj(inpspec)                /* read in an object file or stream */
28 < char  *inpspec;
27 > readobj(                                /* read in an object file or stream */
28 >        char  *inpspec
29 > )
30   {
31          OBJECT  lastobj;
32          FILE  *infp;
33 <        char  buf[1024];
34 <        register int  c;
33 >        char  buf[2048];
34 >        int  c;
35  
36          lastobj = nobjects;
37          if (inpspec == NULL) {
# Line 98 | Line 46 | char  *inpspec;
46                  sprintf(errmsg, "cannot open scene file \"%s\"", inpspec);
47                  error(SYSTEM, errmsg);
48          }
49 + #ifdef getc_unlocked                    /* avoid stupid semaphores */
50 +        flockfile(infp);
51 + #endif
52          while ((c = getc(infp)) != EOF) {
53                  if (isspace(c))
54                          continue;
# Line 112 | Line 63 | char  *inpspec;
63                          getobject(inpspec, infp);
64                  }
65          }
66 <        if (inpspec[0] == '!')
67 <                pclose(infp);
68 <        else
66 >        if (inpspec[0] == '!') {
67 >                if (pclose(infp) != 0) {
68 >                        sprintf(errmsg, "bad status from \"%s\"", inpspec);
69 >                        error(WARNING, errmsg);
70 >                }
71 >        } else if (infp != stdin)
72                  fclose(infp);
73 + #ifdef getc_unlocked
74 +        else
75 +                funlockfile(infp);
76 + #endif
77          if (nobjects == lastobj) {
78                  sprintf(errmsg, "(%s): empty file", inpspec);
79                  error(WARNING, errmsg);
# Line 124 | Line 82 | char  *inpspec;
82  
83  
84   void
85 < getobject(name, fp)                     /* read the next object */
86 < char  *name;
87 < FILE  *fp;
85 > getobject(                              /* read the next object */
86 >        char  *name,
87 >        FILE  *fp
88 > )
89   {
90 + #define OALIAS  -2
91          OBJECT  obj;
92          char  sbuf[MAXSTR];
93          int  rval;
94 <        register OBJREC  *objp;
94 >        OBJREC  *objp;
95  
96          if ((obj = newobject()) == OVOID)
97                  error(SYSTEM, "out of object space");
# Line 139 | Line 99 | FILE  *fp;
99                                          /* get modifier */
100          strcpy(sbuf, "EOF");
101          fgetword(sbuf, MAXSTR, fp);
102 +        if (strchr(sbuf, '\t')) {
103 +                sprintf(errmsg, "(%s): illegal tab in modifier \"%s\"",
104 +                                        name, sbuf);
105 +                error(USER, errmsg);
106 +        }
107          if (!strcmp(sbuf, VOIDID))
108                  objp->omod = OVOID;
109 +        else if (!strcmp(sbuf, ALIASMOD))
110 +                objp->omod = OALIAS;
111          else if ((objp->omod = modifier(sbuf)) == OVOID) {
112                  sprintf(errmsg, "(%s): undefined modifier \"%s\"", name, sbuf);
113                  error(USER, errmsg);
# Line 148 | Line 115 | FILE  *fp;
115                                          /* get type */
116          strcpy(sbuf, "EOF");
117          fgetword(sbuf, MAXSTR, fp);
118 <        if (!strcmp(sbuf, ALIASID))
152 <                objp->otype = -1;
153 <        else if ((objp->otype = otype(sbuf)) < 0) {
118 >        if ((objp->otype = otype(sbuf)) < 0) {
119                  sprintf(errmsg, "(%s): unknown type \"%s\"", name, sbuf);
120                  error(USER, errmsg);
121          }
122                                          /* get identifier */
123          sbuf[0] = '\0';
124          fgetword(sbuf, MAXSTR, fp);
125 +        if (strchr(sbuf, '\t')) {
126 +                sprintf(errmsg, "(%s): illegal tab in identifier \"%s\"",
127 +                                        name, sbuf);
128 +                error(USER, errmsg);
129 +        }
130          objp->oname = savqstr(sbuf);
131                                          /* get arguments */
132 <        if (objp->otype == -1) {
133 <                register OBJECT  alias;
132 >        if (objp->otype == MOD_ALIAS) {
133 >                OBJECT  ref;
134 >                OBJREC  *rfp;
135                  strcpy(sbuf, "EOF");
136                  fgetword(sbuf, MAXSTR, fp);
137 <                if ((alias = modifier(sbuf)) == OVOID) {
138 <                        sprintf(errmsg,
139 <                        "(%s): bad reference \"%s\" for %s \"%s\"",
140 <                                        name, sbuf, ALIASID, objp->oname);
141 <                        error(USER, errmsg);
137 >                if ((ref = modifier(sbuf)) == OVOID) {
138 >                        sprintf(errmsg, "(%s): bad reference \"%s\"",
139 >                                        name, sbuf);
140 >                        objerror(objp, USER, errmsg);
141 >                }                       /* skip pass-thru aliases */
142 >                while ((rfp=objptr(ref))->otype == MOD_ALIAS &&
143 >                                !rfp->oargs.nsargs & (rfp->omod != OVOID))
144 >                        ref = rfp->omod;
145 >
146 >                if ((objp->omod == OALIAS) | (objp->omod == rfp->omod)) {
147 >                        objp->omod = ref;
148 >                } else {
149 >                        objp->oargs.sarg = (char **)malloc(sizeof(char *));
150 >                        if (objp->oargs.sarg == NULL)
151 >                                error(SYSTEM, "out of memory in getobject");
152 >                        objp->oargs.nsargs = 1;
153 >                        objp->oargs.sarg[0] = savestr(sbuf);
154                  }
172                objp->otype = objptr(alias)->otype;
173                copystruct(&objp->oargs, &objptr(alias)->oargs);
155          } else if ((rval = readfargs(&objp->oargs, fp)) == 0) {
156                  sprintf(errmsg, "(%s): bad arguments", name);
157                  objerror(objp, USER, errmsg);
# Line 178 | Line 159 | FILE  *fp;
159                  sprintf(errmsg, "(%s): error reading scene", name);
160                  error(SYSTEM, errmsg);
161          }
162 +        if (objp->omod == OALIAS) {
163 +                sprintf(errmsg, "(%s): inappropriate use of '%s' modifier",
164 +                                name, ALIASMOD);
165 +                objerror(objp, USER, errmsg);
166 +        }
167                                          /* initialize */
168          objp->os = NULL;
169  
170          insertobject(obj);              /* add to global structure */
171 + #undef OALIAS
172   }
173  
174  
175 < int
176 < newobject()                             /* get a new object */
175 > OBJECT
176 > newobject(void)                         /* get a new object */
177   {
178 <        register int  i;
178 >        int  i;
179  
180          if ((nobjects & (OBJBLKSIZ-1)) == 0) {  /* new block */
181                  errno = 0;
# Line 203 | Line 190 | newobject()                            /* get a new object */
190   }
191  
192   void
193 < freeobjects(firstobj, nobjs)            /* free a range of objects */
194 < OBJECT  firstobj, nobjs;
193 > freeobjects(                            /* free a range of objects */
194 >        int firstobj,
195 >        int nobjs
196 > )
197   {
198 <        register int  obj;
198 >        int  obj;
199                                          /* check bounds */
200          if (firstobj < 0)
201                  return;
# Line 216 | Line 205 | OBJECT  firstobj, nobjs;
205                  return;
206                                          /* clear objects */
207          for (obj = firstobj+nobjs; obj-- > firstobj; ) {
208 <                register OBJREC  *o = objptr(obj);
208 >                OBJREC  *o = objptr(obj);
209                  free_os(o);             /* free client memory */
210                  freeqstr(o->oname);
211                  freefargs(&o->oargs);
212 <                bzero(o, sizeof(OBJREC));
212 >                memset((void *)o, '\0', sizeof(OBJREC));
213          }
225        clearobjndx();
214                                          /* free objects off end */
215          for (obj = nobjects; obj-- > 0; )
216                  if (objptr(obj)->oname != NULL)
217                          break;
218 <        ++obj;
218 >        if (++obj >= nobjects)
219 >                return;
220          while (nobjects > obj)          /* free empty end blocks */
221                  if ((--nobjects & (OBJBLKSIZ-1)) == 0) {
222                          int     i = nobjects >> OBJBLKSHFT;
223                          free((void *)objblock[i]);
224                          objblock[i] = NULL;
225                  }
226 +        truncobjndx();                  /* truncate modifier look-up */
227   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines