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 1.13 by greg, Mon Aug 5 08:58:52 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 */
# Line 37 | Line 37 | int  load;
37   CUBE  *scene;
38   char  *ofn[];
39   {
40 <        char  sbuf[128];
40 >        extern int  fputs();
41 >        char  sbuf[512];
42          int  nf;
43 +        OBJECT  fnobjects;
44          register int  i;
45          
46          if (fname == NULL) {
# Line 53 | Line 55 | char  *ofn[];
55                  }
56          }
57                                          /* get header */
58 <        if (load & IO_INFO)
59 <                copyheader(infp, stdout);
58 <        else
59 <                getheader(infp, NULL);
58 >        if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : NULL) < 0)
59 >                octerror(USER, "not an octree");
60                                          /* check format */
61          if (getint(2) != OCTMAGIC)
62 <                octerror(USER, "bad octree");
62 >                octerror(USER, "incompatible octree format");
63                                          /* get boundaries */
64          if (load & IO_BOUNDS) {
65                  for (i = 0; i < 3; i++)
# Line 80 | Line 80 | char  *ofn[];
80          }
81          if (load & IO_FILES)
82                  ofn[nf] = NULL;
83 +                                        /* get number of objects */
84 +        fnobjects = getint(sizeof(OBJECT));
85  
86          if (load & IO_TREE) {
87                                                  /* get the octree */
# Line 94 | Line 96 | char  *ofn[];
96                                  }
97                          while (getobj() != OVOID)
98                                  ;
99 +                } else if (load & IO_SCENE) {           /* consistency checks */
100 +                                                /* check object count */
101 +                        if (nobjects != objorig+fnobjects)
102 +                                octerror(USER, "bad object count; octree stale?");
103 +                                                /* check for non-surfaces */
104 +                        if (nonsurfinset(objorig, fnobjects))
105 +                                octerror(USER, "non-surface in set; octree stale?");
106                  }
107          }
108          fclose(infp);
# Line 133 | Line 142 | getfullnode()                  /* get a set, return fullnode */
142  
143  
144   static long
145 < getint(siz)                     /* get a siz-byte positive integer */
145 > getint(siz)                     /* get a siz-byte integer */
146   register int  siz;
147   {
148          register int  c;
149 <        register long  r = 0L;
149 >        register long  r;
150  
151 <        while (siz--) {
151 >        if ((c = getc(infp)) == EOF)
152 >                goto end_file;
153 >        r = 0x80&c ? -1<<8|c : c;               /* sign extend */
154 >        while (--siz > 0) {
155                  if ((c = getc(infp)) == EOF)
156 <                        octerror(USER, "truncated octree");
156 >                        goto end_file;
157                  r <<= 8;
158                  r |= c;
159          }
160          return(r);
161 + end_file:
162 +        octerror(USER, "truncated octree");
163   }
164  
165  
# Line 155 | Line 169 | getflt()                       /* get a floating point number */
169          extern double  ldexp();
170          double  d;
171  
172 <        d = (double)getint(sizeof(long))/0x7fffffff;
173 <        return(ldexp(d, (char)getint(1)));      /* sign extend */
172 >        d = (double)getint(4)/0x7fffffff;
173 >        return(ldexp(d, (int)getint(1)));
174   }
175          
176  
# Line 194 | Line 208 | getobj()                               /* get next object */
208          register OBJREC  *objp;
209  
210          i = getint(1);
211 <        if (i & 0x80)
211 >        if (i == -1)
212                  return(OVOID);          /* terminator */
213          if ((obj = newobject()) == OVOID)
214                  error(SYSTEM, "out of object space");
# Line 220 | Line 234 | getobj()                               /* get next object */
234                  if (objp->oargs.iarg == NULL)
235                          goto memerr;
236                  for (i = 0; i < objp->oargs.niargs; i++)
237 <                        objp->oargs.iarg[i] = getint(sizeof(long));
237 >                        objp->oargs.iarg[i] = getint(4);
238          } else
239                  objp->oargs.iarg = NULL;
240   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines