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 1.4 by greg, Wed Mar 22 09:53:46 1989 UTC vs.
Revision 1.14 by greg, Wed Oct 23 11:53:38 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1991 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 < double  atof();
22 < double  getflt();
23 < long  getint();
24 < char  *getstr();
25 < OCTREE  getfullnode(), gettree();
21 > extern double  atof();
22 > static double  getflt();
23 > static long  getint();
24 > static char  *getstr();
25 > static OCTREE  getfullnode(), gettree();
26  
27   static char  *infn;                     /* input file name */
28   static FILE  *infp;                     /* input file stream */
29 + static int  objsize;                    /* size of stored OBJECT's */
30   static OBJECT  objorig;                 /* zeroeth object */
31   static short  otypmap[NUMOTYPE+8];      /* object type map */
32  
# Line 37 | Line 38 | int  load;
38   CUBE  *scene;
39   char  *ofn[];
40   {
41 <        char  sbuf[128];
41 >        extern int  fputs();
42 >        char  sbuf[512];
43          int  nf;
44 +        OBJECT  fnobjects;
45          register int  i;
46          
47          if (fname == NULL) {
# Line 53 | Line 56 | char  *ofn[];
56                  }
57          }
58                                          /* get header */
59 <        if (load & IO_INFO)
60 <                copyheader(infp, stdout);
58 <        else
59 <                getheader(infp, NULL);
59 >        if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : NULL) < 0)
60 >                octerror(USER, "not an octree");
61                                          /* check format */
62 <        if (getint(2) != OCTMAGIC)
63 <                octerror(USER, "bad octree");
62 >        if ((objsize = getint(2)-OCTMAGIC) <= 0 ||
63 >                        objsize > MAXOBJSIZ || objsize > sizeof(long))
64 >                octerror(USER, "incompatible octree format");
65                                          /* get boundaries */
66          if (load & IO_BOUNDS) {
67                  for (i = 0; i < 3; i++)
# Line 80 | Line 82 | char  *ofn[];
82          }
83          if (load & IO_FILES)
84                  ofn[nf] = NULL;
85 +                                        /* get number of objects */
86 +        fnobjects = getint(objsize);
87  
88          if (load & IO_TREE) {
89                                                  /* get the octree */
# Line 94 | Line 98 | char  *ofn[];
98                                  }
99                          while (getobj() != OVOID)
100                                  ;
101 +                } else if (load & IO_SCENE) {           /* consistency checks */
102 +                                                /* check object count */
103 +                        if (nobjects != objorig+fnobjects)
104 +                                octerror(USER, "bad object count; octree stale?");
105 +                                                /* check for non-surfaces */
106 +                        if (nonsurfinset(objorig, fnobjects))
107 +                                octerror(USER, "non-surface in set; octree stale?");
108                  }
109          }
110          fclose(infp);
# Line 122 | Line 133 | getfullnode()                  /* get a set, return fullnode */
133   {
134          OBJECT  set[MAXSET+1];
135          register int  i;
136 +        register long  m;
137  
138 <        set[0] = getint(sizeof(OBJECT));
139 <        if (set[0] > MAXSET)
138 >        m = getint(objsize);
139 >        if (m > MAXSET)
140                  octerror(USER, "bad set in getfullnode");
141 <        for (i = 1; i <= set[0]; i++)
142 <                set[i] = getint(sizeof(OBJECT)) + objorig;
141 >        set[0] = m;
142 >        for (i = 1; i <= set[0]; i++) {
143 >                m = getint(objsize) + objorig;
144 >                if ((OBJECT)m != m)
145 >                        octerror(USER, "too many objects");
146 >                set[i] = m;
147 >        }
148          return(fullnode(set));
149   }      
150  
# Line 139 | Line 156 | register int  siz;
156          register int  c;
157          register long  r;
158  
159 <        c = getc(infp);
160 <        r = c&0x80 ? -1L : 0L;          /* sign extend */
161 <        ungetc(c, infp);
162 <        while (siz--) {
159 >        if ((c = getc(infp)) == EOF)
160 >                goto end_file;
161 >        r = 0x80&c ? -1<<8|c : c;               /* sign extend */
162 >        while (--siz > 0) {
163                  if ((c = getc(infp)) == EOF)
164 <                        octerror(USER, "truncated octree");
164 >                        goto end_file;
165                  r <<= 8;
166                  r |= c;
167          }
168          return(r);
169 + end_file:
170 +        octerror(USER, "truncated octree");
171   }
172  
173  
# Line 159 | Line 178 | getflt()                       /* get a floating point number */
178          double  d;
179  
180          d = (double)getint(4)/0x7fffffff;
181 <        return(ldexp(d, getint(1)));
181 >        return(ldexp(d, (int)getint(1)));
182   }
183          
184  
# Line 194 | Line 213 | getobj()                               /* get next object */
213          char  sbuf[MAXSTR];
214          int  obj;
215          register int  i;
216 +        register long  m;
217          register OBJREC  *objp;
218  
219          i = getint(1);
# Line 204 | Line 224 | getobj()                               /* get next object */
224          objp = objptr(obj);
225          if ((objp->otype = otypmap[i]) < 0)
226                  octerror(USER, "reference to unknown type");
227 <        if ((objp->omod = getint(sizeof(OBJECT))) != OVOID)
228 <                objp->omod += objorig;
227 >        if ((m = getint(objsize)) != OVOID) {
228 >                m += objorig;
229 >                if ((OBJECT)m != m)
230 >                        octerror(USER, "too many objects");
231 >        }
232 >        objp->omod = m;
233          objp->oname = savqstr(getstr(sbuf));
234          if (objp->oargs.nsargs = getint(2)) {
235                  objp->oargs.sarg = (char **)bmalloc

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines