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.23 by greg, Sat May 4 00:36:58 2019 UTC vs.
Revision 2.29 by greg, Sat Jun 7 05:09:45 2025 UTC

# Line 14 | Line 14 | static const char RCSid[] = "$Id$";
14   #include  <stdio.h>
15  
16   #include  "platform.h"
17 #include  "paths.h"
17   #include  "standard.h"
18   #include  "object.h"
19   #include  "otypes.h"
# Line 47 | Line 46 | readobj(                               /* read in an object file or stream */
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 61 | Line 63 | readobj(                               /* read in an object file or stream */
63                          getobject(inpspec, infp);
64                  }
65          }
66 <        if (inpspec[0] == '!')
67 <                pclose(infp);
68 <        else if (infp != stdin)
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 121 | Line 130 | getobject(                             /* read the next object */
130          objp->oname = savqstr(sbuf);
131                                          /* get arguments */
132          if (objp->otype == MOD_ALIAS) {
133 <                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 198 | Line 211 | freeobjects(                           /* free a range of objects */
211                  freefargs(&o->oargs);
212                  memset((void *)o, '\0', sizeof(OBJREC));
213          }
201        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