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.8 by greg, Thu Sep 6 23:32:45 1990 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 22 | Line 22 | 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 54 | Line 58 | char  *ofn[];
58                  }
59          }
60                                          /* get header */
61 <        if (load & IO_INFO)
62 <                copyheader(infp, stdout);
59 <        else
60 <                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, "invalid octree format");
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 82 | Line 85 | char  *ofn[];
85          if (load & IO_FILES)
86                  ofn[nf] = NULL;
87                                          /* get number of objects */
88 <        fnobjects = getint(sizeof(OBJECT));
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 97 | 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);
103                                        /* consistency checks */
104        if (load & IO_SCENE) {
105                                        /* check object count */
106                if (nobjects != objorig+fnobjects)
107                        octerror(USER, "bad object count -- stale octree?");
108                                        /* check for non-surfaces */
109                if (nonsurfinset(objorig, fnobjects))
110                        octerror(USER, "non-surface in set -- stale octree?");
111        }
115          return(nf);
116   }
117  
# Line 134 | 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));
139 <        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  
# Line 173 | Line 179 | getflt()                       /* get a floating point number */
179          double  d;
180  
181          d = (double)getint(4)/0x7fffffff;
182 <        return(ldexp(d, getint(1)));
182 >        return(ldexp(d, (int)getint(1)));
183   }
184          
185  
# Line 208 | 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);
# Line 218 | Line 225 | getobj()                               /* get next object */
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 242 | Line 253 | getobj()                               /* get next object */
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