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

Comparing ray/src/common/readoct.c (file contents):
Revision 2.2 by greg, Thu Dec 19 14:45:45 1991 UTC vs.
Revision 2.5 by greg, Thu Aug 6 09:02:38 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  "otypes.h"
20  
21 < static double  getflt();
22 < static long  getint();
23 < static char  *getstr();
21 > static double  ogetflt();
22 > static long  ogetint();
23 > static char  *ogetstr();
24   static int  getobj(), octerror();
25   static OCTREE  getfullnode(), gettree();
26  
# Line 60 | Line 60 | char  *ofn[];
60          if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : NULL) < 0)
61                  octerror(USER, "not an octree");
62                                          /* check format */
63 <        if ((objsize = getint(2)-OCTMAGIC) <= 0 ||
63 >        if ((objsize = ogetint(2)-OCTMAGIC) <= 0 ||
64                          objsize > MAXOBJSIZ || objsize > sizeof(long))
65                  octerror(USER, "incompatible octree format");
66                                          /* get boundaries */
67          if (load & IO_BOUNDS) {
68                  for (i = 0; i < 3; i++)
69 <                        scene->cuorg[i] = atof(getstr(sbuf));
70 <                scene->cusize = atof(getstr(sbuf));
69 >                        scene->cuorg[i] = atof(ogetstr(sbuf));
70 >                scene->cusize = atof(ogetstr(sbuf));
71          } else {
72                  for (i = 0; i < 4; i++)
73 <                        getstr(sbuf);
73 >                        ogetstr(sbuf);
74          }
75          objorig = nobjects;             /* set object offset */
76          nf = 0;                         /* get object files */
77 <        while (*getstr(sbuf)) {
77 >        while (*ogetstr(sbuf)) {
78                  if (load & IO_SCENE)
79                          readobj(sbuf);
80                  if (load & IO_FILES)
# Line 84 | Line 84 | char  *ofn[];
84          if (load & IO_FILES)
85                  ofn[nf] = NULL;
86                                          /* get number of objects */
87 <        fnobjects = m = getint(objsize);
87 >        fnobjects = m = ogetint(objsize);
88          if (fnobjects != m)
89                  octerror(USER, "too many objects");
90  
91 <        if (load & IO_TREE) {
92 <                                                /* get the octree */
91 >        if (load & IO_TREE)                     /* get the octree */
92                  scene->cutree = gettree();
93 <                                                /* get the scene */
94 <                if (nf == 0 && load & IO_SCENE) {
95 <                        for (i = 0; *getstr(sbuf); i++)
96 <                                if ((otypmap[i] = otype(sbuf)) < 0) {
97 <                                        sprintf(errmsg, "unknown type \"%s\"",
98 <                                                        sbuf);
99 <                                        octerror(WARNING, errmsg);
100 <                                }
101 <                        while (getobj() != OVOID)
102 <                                ;
103 <                } else if (load & IO_SCENE) {           /* consistency checks */
104 <                                                /* check object count */
105 <                        if (nobjects != objorig+fnobjects)
106 <                                octerror(USER, "bad object count; octree stale?");
107 <                                                /* check for non-surfaces */
108 <                        if (nonsurfinset(objorig, fnobjects))
109 <                                octerror(USER, "non-surface in set; octree stale?");
110 <                }
111 <        }
93 >        else if (load & IO_SCENE && nf == 0)
94 >                skiptree();
95 >                
96 >        if (load & IO_SCENE)            /* get the scene */
97 >            if (nf == 0) {
98 >                for (i = 0; *ogetstr(sbuf); i++)
99 >                        if ((otypmap[i] = otype(sbuf)) < 0) {
100 >                                sprintf(errmsg, "unknown type \"%s\"", sbuf);
101 >                                octerror(WARNING, errmsg);
102 >                        }
103 >                while (getobj() != OVOID)
104 >                        ;
105 >            } else {                    /* consistency checks */
106 >                                /* check object count */
107 >                if (nobjects != objorig+fnobjects)
108 >                        octerror(USER, "bad object count; octree stale?");
109 >                                /* check for non-surfaces */
110 >                if (nonsurfinset(objorig, fnobjects))
111 >                        octerror(USER, "modifier in tree; octree stale?");
112 >            }
113          fclose(infp);
114          return(nf);
115   }
116  
117  
118   static char *
119 < getstr(s)                       /* get null-terminated string */
119 > ogetstr(s)                      /* get null-terminated string */
120   char  *s;
121   {
122 <        register char  *cp;
123 <        register int  c;
122 >        extern char  *getstr();
123  
124 <        cp = s;
125 <        while ((c = getc(infp)) != EOF)
126 <                if ((*cp++ = c) == '\0')
128 <                        return(s);
129 <                
130 <        octerror(USER, "truncated octree");
124 >        if (getstr(s, infp) == NULL)
125 >                octerror(USER, "truncated octree");
126 >        return(s);
127   }
128  
129  
# Line 138 | Line 134 | getfullnode()                  /* get a set, return fullnode */
134          register int  i;
135          register long  m;
136  
137 <        if ((set[0] = getint(objsize)) > MAXSET)
137 >        if ((set[0] = ogetint(objsize)) > MAXSET)
138                  octerror(USER, "bad set in getfullnode");
139          for (i = 1; i <= set[0]; i++) {
140 <                m = getint(objsize) + objorig;
140 >                m = ogetint(objsize) + objorig;
141                  if ((set[i] = m) != m)
142                          octerror(USER, "too many objects");
143          }
# Line 150 | Line 146 | getfullnode()                  /* get a set, return fullnode */
146  
147  
148   static long
149 < getint(siz)                     /* get a siz-byte integer */
150 < register int  siz;
149 > ogetint(siz)                    /* get a siz-byte integer */
150 > int  siz;
151   {
152 <        register int  c;
152 >        extern long  getint();
153          register long  r;
154  
155 <        if ((c = getc(infp)) == EOF)
156 <                goto end_file;
157 <        r = 0x80&c ? -1<<8|c : c;               /* sign extend */
162 <        while (--siz > 0) {
163 <                if ((c = getc(infp)) == EOF)
164 <                        goto end_file;
165 <                r <<= 8;
166 <                r |= c;
167 <        }
155 >        r = getint(siz, infp);
156 >        if (feof(infp))
157 >                octerror(USER, "truncated octree");
158          return(r);
169 end_file:
170        octerror(USER, "truncated octree");
159   }
160  
161  
162   static double
163 < getflt()                        /* get a floating point number */
163 > ogetflt()                       /* get a floating point number */
164   {
165 <        extern double  ldexp();
166 <        double  d;
165 >        extern double  getflt();
166 >        double  r;
167  
168 <        d = (double)getint(4)/0x7fffffff;
169 <        return(ldexp(d, (int)getint(1)));
168 >        r = getflt(infp);
169 >        if (feof(infp))
170 >                octerror(USER, "truncated octree");
171 >        return(r);
172   }
173          
174  
# Line 208 | Line 198 | gettree()                      /* get a pre-ordered octree */
198  
199  
200   static
201 + skiptree()                              /* skip octree on input */
202 + {
203 +        register int  i;
204 +        
205 +        switch (getc(infp)) {
206 +        case OT_EMPTY:
207 +                return;
208 +        case OT_FULL:
209 +                for (i = ogetint(objsize); i-- > 0; )
210 +                        ogetint(objsize);
211 +                return;
212 +        case OT_TREE:
213 +                for (i = 0; i < 8; i++)
214 +                        skiptree();
215 +                return;
216 +        case EOF:
217 +                octerror(USER, "truncated octree");
218 +        default:
219 +                octerror(USER, "damaged octree");
220 +        }
221 + }
222 +
223 +
224 + static
225   getobj()                                /* get next object */
226   {
227          char  sbuf[MAXSTR];
# Line 216 | Line 230 | getobj()                               /* get next object */
230          register long  m;
231          register OBJREC  *objp;
232  
233 <        i = getint(1);
233 >        i = ogetint(1);
234          if (i == -1)
235                  return(OVOID);          /* terminator */
236          if ((obj = newobject()) == OVOID)
# Line 224 | Line 238 | getobj()                               /* get next object */
238          objp = objptr(obj);
239          if ((objp->otype = otypmap[i]) < 0)
240                  octerror(USER, "reference to unknown type");
241 <        if ((m = getint(objsize)) != OVOID) {
241 >        if ((m = ogetint(objsize)) != OVOID) {
242                  m += objorig;
243                  if ((OBJECT)m != m)
244                          octerror(USER, "too many objects");
245          }
246          objp->omod = m;
247 <        objp->oname = savqstr(getstr(sbuf));
248 <        if (objp->oargs.nsargs = getint(2)) {
247 >        objp->oname = savqstr(ogetstr(sbuf));
248 >        if (objp->oargs.nsargs = ogetint(2)) {
249                  objp->oargs.sarg = (char **)bmalloc
250                                  (objp->oargs.nsargs*sizeof(char *));
251                  if (objp->oargs.sarg == NULL)
252                          goto memerr;
253                  for (i = 0; i < objp->oargs.nsargs; i++)
254 <                        objp->oargs.sarg[i] = savestr(getstr(sbuf));
254 >                        objp->oargs.sarg[i] = savestr(ogetstr(sbuf));
255          } else
256                  objp->oargs.sarg = NULL;
257   #ifdef  IARGS
258 <        if (objp->oargs.niargs = getint(2)) {
258 >        if (objp->oargs.niargs = ogetint(2)) {
259                  objp->oargs.iarg = (long *)bmalloc
260                                  (objp->oargs.niargs*sizeof(long));
261                  if (objp->oargs.iarg == NULL)
262                          goto memerr;
263                  for (i = 0; i < objp->oargs.niargs; i++)
264 <                        objp->oargs.iarg[i] = getint(4);
264 >                        objp->oargs.iarg[i] = ogetint(4);
265          } else
266                  objp->oargs.iarg = NULL;
267   #endif
268 <        if (objp->oargs.nfargs = getint(2)) {
268 >        if (objp->oargs.nfargs = ogetint(2)) {
269                  objp->oargs.farg = (FLOAT *)bmalloc
270                                  (objp->oargs.nfargs*sizeof(FLOAT));
271                  if (objp->oargs.farg == NULL)
272                          goto memerr;
273                  for (i = 0; i < objp->oargs.nfargs; i++)
274 <                        objp->oargs.farg[i] = getflt();
274 >                        objp->oargs.farg[i] = ogetflt();
275          } else
276                  objp->oargs.farg = NULL;
277                                                  /* initialize */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines