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.4 by greg, Mon Jul 13 15:36:29 1992 UTC vs.
Revision 2.7 by greg, Mon Sep 21 12:04:17 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 41 | Line 41 | char  *ofn[];
41          extern int  fputs();
42          char  sbuf[512];
43          int  nf;
44 <        OBJECT  fnobjects;
44 >        OBJECT  fnobjects;
45          register int  i;
46          long  m;
47          
# Line 56 | Line 56 | char  *ofn[];
56                          error(SYSTEM, errmsg);
57                  }
58          }
59 + #ifdef MSDOS
60 +        setmode(fileno(infp), O_BINARY);
61 + #endif
62                                          /* get header */
63          if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : NULL) < 0)
64                  octerror(USER, "not an octree");
# Line 88 | Line 91 | char  *ofn[];
91          if (fnobjects != m)
92                  octerror(USER, "too many objects");
93  
94 <        if (load & IO_TREE) {
92 <                                                /* get the octree */
94 >        if (load & IO_TREE)                     /* get the octree */
95                  scene->cutree = gettree();
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\"",
101 <                                                        sbuf);
102 <                                        octerror(WARNING, errmsg);
103 <                                }
104 <                        while (getobj() != OVOID)
105 <                                ;
106 <                    } else {                    /* consistency checks */
107 <                                        /* check object count */
108 <                        if (nobjects != objorig+fnobjects)
109 <                                octerror(USER, "bad object count; octree stale?");
110 <                                        /* check for non-surfaces */
111 <                        if (nonsurfinset(objorig, fnobjects))
112 <                                octerror(USER, "modifier in tree; octree stale?");
113 <                    }
114 <        }
96 >        else if (load & IO_SCENE && nf == 0)
97 >                skiptree();
98 >                
99 >        if (load & IO_SCENE)            /* get the scene */
100 >            if (nf == 0) {
101 >                for (i = 0; *ogetstr(sbuf); i++)
102 >                        if ((otypmap[i] = otype(sbuf)) < 0) {
103 >                                sprintf(errmsg, "unknown type \"%s\"", sbuf);
104 >                                octerror(WARNING, errmsg);
105 >                        }
106 >                while (getobj() != OVOID)
107 >                        ;
108 >            } else {                    /* consistency checks */
109 >                                /* check object count */
110 >                if (nobjects != objorig+fnobjects)
111 >                        octerror(USER, "bad object count; octree stale?");
112 >                                /* check for non-surfaces */
113 >                if (nonsurfinset(objorig, fnobjects))
114 >                        octerror(USER, "modifier in tree; octree stale?");
115 >            }
116          fclose(infp);
117          return(nf);
118   }
# Line 130 | Line 133 | char  *s;
133   static OCTREE
134   getfullnode()                   /* get a set, return fullnode */
135   {
136 <        OBJECT  set[MAXSET+1];
136 >        OBJECT  set[MAXSET+1];
137          register int  i;
138          register long  m;
139  
# Line 163 | Line 166 | static double
166   ogetflt()                       /* get a floating point number */
167   {
168          extern double  getflt();
169 <        double  r;
169 >        double  r;
170  
171          r = getflt(infp);
172          if (feof(infp))
# Line 175 | Line 178 | ogetflt()                      /* get a floating point number */
178   static OCTREE
179   gettree()                       /* get a pre-ordered octree */
180   {
181 <        register OCTREE  ot;
181 >        register OCTREE  ot;
182          register int  i;
183          
184          switch (getc(infp)) {
# Line 198 | Line 201 | gettree()                      /* get a pre-ordered octree */
201  
202  
203   static
204 + skiptree()                              /* skip octree on input */
205 + {
206 +        register int  i;
207 +        
208 +        switch (getc(infp)) {
209 +        case OT_EMPTY:
210 +                return;
211 +        case OT_FULL:
212 +                for (i = ogetint(objsize)*objsize; i-- > 0; )
213 +                        if (getc(infp) == EOF)
214 +                                octerror(USER, "truncated octree");
215 +                return;
216 +        case OT_TREE:
217 +                for (i = 0; i < 8; i++)
218 +                        skiptree();
219 +                return;
220 +        case EOF:
221 +                octerror(USER, "truncated octree");
222 +        default:
223 +                octerror(USER, "damaged octree");
224 +        }
225 + }
226 +
227 +
228 + static
229   getobj()                                /* get next object */
230   {
231          char  sbuf[MAXSTR];
232          int  obj;
233          register int  i;
234          register long  m;
235 <        register OBJREC  *objp;
235 >        register OBJREC  *objp;
236  
237          i = ogetint(1);
238          if (i == -1)
# Line 230 | Line 258 | getobj()                               /* get next object */
258                          objp->oargs.sarg[i] = savestr(ogetstr(sbuf));
259          } else
260                  objp->oargs.sarg = NULL;
261 < #ifdef  IARGS
261 > #ifdef  IARGS
262          if (objp->oargs.niargs = ogetint(2)) {
263                  objp->oargs.iarg = (long *)bmalloc
264                                  (objp->oargs.niargs*sizeof(long));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines