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.16 by schorsch, Mon Jun 30 14:59:11 2003 UTC vs.
Revision 2.25 by greg, Tue Feb 7 20:28:16 2023 UTC

# Line 13 | Line 13 | static const char RCSid[] = "$Id$";
13   #include  <string.h>
14   #include  <stdio.h>
15  
16 #include  "standard.h"
16   #include  "platform.h"
17 + #include  "paths.h"
18 + #include  "standard.h"
19   #include  "object.h"
20   #include  "otypes.h"
21  
# Line 24 | Line 25 | OBJECT  nobjects = 0;                  /* # of objects */
25  
26  
27   void
28 < readobj(inpspec)                /* read in an object file or stream */
29 < char  *inpspec;
28 > readobj(                                /* read in an object file or stream */
29 >        char  *inpspec
30 > )
31   {
32          OBJECT  lastobj;
33          FILE  *infp;
34 <        char  buf[1024];
35 <        register int  c;
34 >        char  buf[2048];
35 >        int  c;
36  
37          lastobj = nobjects;
38          if (inpspec == NULL) {
# Line 45 | Line 47 | char  *inpspec;
47                  sprintf(errmsg, "cannot open scene file \"%s\"", inpspec);
48                  error(SYSTEM, errmsg);
49          }
50 + #ifdef getc_unlocked                    /* avoid stupid semaphores */
51 +        flockfile(infp);
52 + #endif
53          while ((c = getc(infp)) != EOF) {
54                  if (isspace(c))
55                          continue;
# Line 61 | Line 66 | char  *inpspec;
66          }
67          if (inpspec[0] == '!')
68                  pclose(infp);
69 <        else
69 >        else if (infp != stdin)
70                  fclose(infp);
71 + #ifdef getc_unlocked
72 +        else
73 +                funlockfile(infp);
74 + #endif
75          if (nobjects == lastobj) {
76                  sprintf(errmsg, "(%s): empty file", inpspec);
77                  error(WARNING, errmsg);
# Line 71 | Line 80 | char  *inpspec;
80  
81  
82   void
83 < getobject(name, fp)                     /* read the next object */
84 < char  *name;
85 < FILE  *fp;
83 > getobject(                              /* read the next object */
84 >        char  *name,
85 >        FILE  *fp
86 > )
87   {
88   #define OALIAS  -2
89          OBJECT  obj;
90          char  sbuf[MAXSTR];
91          int  rval;
92 <        register OBJREC  *objp;
92 >        OBJREC  *objp;
93  
94          if ((obj = newobject()) == OVOID)
95                  error(SYSTEM, "out of object space");
# Line 87 | Line 97 | FILE  *fp;
97                                          /* get modifier */
98          strcpy(sbuf, "EOF");
99          fgetword(sbuf, MAXSTR, fp);
100 +        if (strchr(sbuf, '\t')) {
101 +                sprintf(errmsg, "(%s): illegal tab in modifier \"%s\"",
102 +                                        name, sbuf);
103 +                error(USER, errmsg);
104 +        }
105          if (!strcmp(sbuf, VOIDID))
106                  objp->omod = OVOID;
107          else if (!strcmp(sbuf, ALIASMOD))
# Line 105 | Line 120 | FILE  *fp;
120                                          /* get identifier */
121          sbuf[0] = '\0';
122          fgetword(sbuf, MAXSTR, fp);
123 +        if (strchr(sbuf, '\t')) {
124 +                sprintf(errmsg, "(%s): illegal tab in identifier \"%s\"",
125 +                                        name, sbuf);
126 +                error(USER, errmsg);
127 +        }
128          objp->oname = savqstr(sbuf);
129                                          /* get arguments */
130          if (objp->otype == MOD_ALIAS) {
131 <                register OBJECT  alias;
131 >                OBJECT  alias;
132                  strcpy(sbuf, "EOF");
133                  fgetword(sbuf, MAXSTR, fp);
134                  if ((alias = modifier(sbuf)) == OVOID) {
# Line 147 | Line 167 | FILE  *fp;
167  
168  
169   OBJECT
170 < newobject()                             /* get a new object */
170 > newobject(void)                         /* get a new object */
171   {
172 <        register int  i;
172 >        int  i;
173  
174          if ((nobjects & (OBJBLKSIZ-1)) == 0) {  /* new block */
175                  errno = 0;
# Line 164 | Line 184 | newobject()                            /* get a new object */
184   }
185  
186   void
187 < freeobjects(firstobj, nobjs)            /* free a range of objects */
188 < int  firstobj, nobjs;
187 > freeobjects(                            /* free a range of objects */
188 >        int firstobj,
189 >        int nobjs
190 > )
191   {
192 <        register int  obj;
192 >        int  obj;
193                                          /* check bounds */
194          if (firstobj < 0)
195                  return;
# Line 177 | Line 199 | int  firstobj, nobjs;
199                  return;
200                                          /* clear objects */
201          for (obj = firstobj+nobjs; obj-- > firstobj; ) {
202 <                register OBJREC  *o = objptr(obj);
202 >                OBJREC  *o = objptr(obj);
203                  free_os(o);             /* free client memory */
204                  freeqstr(o->oname);
205                  freefargs(&o->oargs);
206                  memset((void *)o, '\0', sizeof(OBJREC));
207          }
186        clearobjndx();
208                                          /* free objects off end */
209          for (obj = nobjects; obj-- > 0; )
210                  if (objptr(obj)->oname != NULL)
211                          break;
212 <        ++obj;
212 >        if (++obj >= nobjects)
213 >                return;
214          while (nobjects > obj)          /* free empty end blocks */
215                  if ((--nobjects & (OBJBLKSIZ-1)) == 0) {
216                          int     i = nobjects >> OBJBLKSHFT;
217                          free((void *)objblock[i]);
218                          objblock[i] = NULL;
219                  }
220 +        truncobjndx();                  /* truncate modifier look-up */
221   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines