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.15 by greg, Fri Jun 20 00:25:49 2003 UTC vs.
Revision 2.29 by greg, Sat Jun 7 05:09:45 2025 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   #include "copyright.h"
11  
12   #include  <ctype.h>
13 + #include  <string.h>
14   #include  <stdio.h>
14 #include  <stdio.h>
15  
16 #include  "standard.h"
16   #include  "platform.h"
17 + #include  "standard.h"
18   #include  "object.h"
19   #include  "otypes.h"
20  
# Line 24 | Line 24 | 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 45 | 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 59 | 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 71 | 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 87 | 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))
# Line 105 | Line 122 | FILE  *fp;
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 == MOD_ALIAS) {
133 <                register OBJECT  alias;
133 >                OBJECT  ref;
134 >                OBJREC  *rfp;
135                  strcpy(sbuf, "EOF");
136                  fgetword(sbuf, MAXSTR, fp);
137 <                if ((alias = modifier(sbuf)) == OVOID) {
137 >                if ((ref = modifier(sbuf)) == OVOID) {
138                          sprintf(errmsg, "(%s): bad reference \"%s\"",
139                                          name, sbuf);
140                          objerror(objp, USER, errmsg);
141 <                }
142 <                if (objp->omod == OALIAS ||
143 <                                objp->omod == objptr(alias)->omod) {
144 <                        objp->omod = alias;
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)
# Line 147 | Line 173 | FILE  *fp;
173  
174  
175   OBJECT
176 < newobject()                             /* get a new 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 164 | Line 190 | newobject()                            /* get a new object */
190   }
191  
192   void
193 < freeobjects(firstobj, nobjs)            /* free a range of objects */
194 < int  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 177 | Line 205 | int  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((void *)o, sizeof(OBJREC));
212 >                memset((void *)o, '\0', sizeof(OBJREC));
213          }
186        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