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.2 by greg, Tue Feb 21 14:59:06 1989 UTC vs.
Revision 2.1 by greg, Tue Nov 12 16:55:01 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 int  getobj(), octerror();
26 > static OCTREE  getfullnode(), gettree();
27  
28   static char  *infn;                     /* input file name */
29   static FILE  *infp;                     /* input file stream */
30 + static int  objsize;                    /* size of stored OBJECT's */
31   static OBJECT  objorig;                 /* zeroeth object */
32   static short  otypmap[NUMOTYPE+8];      /* object type map */
33  
# Line 37 | Line 39 | int  load;
39   CUBE  *scene;
40   char  *ofn[];
41   {
42 <        char  sbuf[128];
42 >        extern int  fputs();
43 >        char  sbuf[512];
44          int  nf;
45 +        OBJECT  fnobjects;
46          register int  i;
47 +        long  m;
48          
49          if (fname == NULL) {
50                  infn = "standard input";
# Line 53 | Line 58 | char  *ofn[];
58                  }
59          }
60                                          /* get header */
61 <        if (load & IO_INFO)
62 <                copyheader(infp, stdout);
58 <        else
59 <                getheader(infp, NULL);
61 >        if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : NULL) < 0)
62 >                octerror(USER, "not an octree");
63                                          /* check format */
64 <        if (getint(2) != OCTMAGIC)
65 <                octerror(USER, "bad octree");
64 >        if ((objsize = getint(2)-OCTMAGIC) <= 0 ||
65 >                        objsize > MAXOBJSIZ || objsize > sizeof(long))
66 >                octerror(USER, "incompatible octree format");
67                                          /* get boundaries */
68          if (load & IO_BOUNDS) {
69                  for (i = 0; i < 3; i++)
# Line 80 | Line 84 | char  *ofn[];
84          }
85          if (load & IO_FILES)
86                  ofn[nf] = NULL;
87 +                                        /* get number of objects */
88 +        fnobjects = m = getint(objsize);
89 +        if (fnobjects != m)
90 +                octerror(USER, "too many objects");
91  
92          if (load & IO_TREE) {
93                                                  /* get the octree */
# Line 94 | Line 102 | char  *ofn[];
102                                  }
103                          while (getobj() != OVOID)
104                                  ;
105 +                } else if (load & IO_SCENE) {           /* 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, "non-surface in set; octree stale?");
112                  }
113          }
114          fclose(infp);
# Line 122 | Line 137 | getfullnode()                  /* get a set, return fullnode */
137   {
138          OBJECT  set[MAXSET+1];
139          register int  i;
140 +        register long  m;
141  
142 <        set[0] = getint(sizeof(OBJECT));
127 <        if (set[0] > MAXSET)
142 >        if ((set[0] = getint(objsize)) > MAXSET)
143                  octerror(USER, "bad set in getfullnode");
144 <        for (i = 1; i <= set[0]; i++)
145 <                set[i] = getint(sizeof(OBJECT)) + objorig;
144 >        for (i = 1; i <= set[0]; i++) {
145 >                m = getint(objsize) + objorig;
146 >                if ((set[i] = m) != m)
147 >                        octerror(USER, "too many objects");
148 >        }
149          return(fullnode(set));
150   }      
151  
152  
153   static long
154 < getint(siz)                     /* get a siz-byte positive integer */
154 > getint(siz)                     /* get a siz-byte integer */
155   register int  siz;
156   {
157          register int  c;
158 <        register long  r = 0L;
158 >        register long  r;
159  
160 <        while (siz--) {
160 >        if ((c = getc(infp)) == EOF)
161 >                goto end_file;
162 >        r = 0x80&c ? -1<<8|c : c;               /* sign extend */
163 >        while (--siz > 0) {
164                  if ((c = getc(infp)) == EOF)
165 <                        octerror(USER, "truncated octree");
165 >                        goto end_file;
166                  r <<= 8;
167                  r |= c;
168          }
169          return(r);
170 + end_file:
171 +        octerror(USER, "truncated octree");
172   }
173  
174  
# Line 155 | Line 178 | getflt()                       /* get a floating point number */
178          extern double  ldexp();
179          double  d;
180  
181 <        d = (double)getint(sizeof(long))/0x7fffffff;
182 <        return(ldexp(d, (char)getint(1)));      /* sign extend */
181 >        d = (double)getint(4)/0x7fffffff;
182 >        return(ldexp(d, (int)getint(1)));
183   }
184          
185  
# Line 191 | Line 214 | getobj()                               /* get next object */
214          char  sbuf[MAXSTR];
215          int  obj;
216          register int  i;
217 +        register long  m;
218          register OBJREC  *objp;
219  
220          i = getint(1);
221 <        if (i & 0x80)
221 >        if (i == -1)
222                  return(OVOID);          /* terminator */
223          if ((obj = newobject()) == OVOID)
224                  error(SYSTEM, "out of object space");
225          objp = objptr(obj);
226          if ((objp->otype = otypmap[i]) < 0)
227                  octerror(USER, "reference to unknown type");
228 <        if ((objp->omod = getint(sizeof(OBJECT))) != OVOID)
229 <                objp->omod += objorig;
228 >        if ((m = getint(objsize)) != OVOID) {
229 >                m += objorig;
230 >                if ((OBJECT)m != m)
231 >                        octerror(USER, "too many objects");
232 >        }
233 >        objp->omod = m;
234          objp->oname = savqstr(getstr(sbuf));
235          if (objp->oargs.nsargs = getint(2)) {
236                  objp->oargs.sarg = (char **)bmalloc
# Line 220 | Line 248 | getobj()                               /* get next object */
248                  if (objp->oargs.iarg == NULL)
249                          goto memerr;
250                  for (i = 0; i < objp->oargs.niargs; i++)
251 <                        objp->oargs.iarg[i] = getint(sizeof(long));
251 >                        objp->oargs.iarg[i] = getint(4);
252          } else
253                  objp->oargs.iarg = NULL;
254   #endif
255          if (objp->oargs.nfargs = getint(2)) {
256 <                objp->oargs.farg = (double *)bmalloc
257 <                                (objp->oargs.nfargs*sizeof(double));
256 >                objp->oargs.farg = (FLOAT *)bmalloc
257 >                                (objp->oargs.nfargs*sizeof(FLOAT));
258                  if (objp->oargs.farg == NULL)
259                          goto memerr;
260                  for (i = 0; i < objp->oargs.nfargs; i++)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines