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 */ |
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) { |
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++) |
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 */ |
99 |
|
} |
100 |
|
} |
101 |
|
fclose(infp); |
102 |
+ |
/* consistency checks */ |
103 |
+ |
if (load & IO_SCENE) { |
104 |
+ |
/* check object count */ |
105 |
+ |
if (nobjects != objorig+fnobjects) |
106 |
+ |
octerror(USER, "bad object count; octree stale?"); |
107 |
+ |
/* check for non-surfaces */ |
108 |
+ |
if (nonsurfinset(objorig, fnobjects)) |
109 |
+ |
octerror(USER, "non-surface in set; octree stale?"); |
110 |
+ |
} |
111 |
|
return(nf); |
112 |
|
} |
113 |
|
|
144 |
|
|
145 |
|
|
146 |
|
static long |
147 |
< |
getint(siz) /* get a siz-byte positive integer */ |
147 |
> |
getint(siz) /* get a siz-byte integer */ |
148 |
|
register int siz; |
149 |
|
{ |
150 |
|
register int c; |
151 |
< |
register long r = 0L; |
151 |
> |
register long r; |
152 |
|
|
153 |
< |
while (siz--) { |
153 |
> |
if ((c = getc(infp)) == EOF) |
154 |
> |
goto end_file; |
155 |
> |
r = 0x80&c ? -1<<8|c : c; /* sign extend */ |
156 |
> |
while (--siz > 0) { |
157 |
|
if ((c = getc(infp)) == EOF) |
158 |
< |
octerror(USER, "truncated octree"); |
158 |
> |
goto end_file; |
159 |
|
r <<= 8; |
160 |
|
r |= c; |
161 |
|
} |
162 |
|
return(r); |
163 |
+ |
end_file: |
164 |
+ |
octerror(USER, "truncated octree"); |
165 |
|
} |
166 |
|
|
167 |
|
|
171 |
|
extern double ldexp(); |
172 |
|
double d; |
173 |
|
|
174 |
< |
d = (double)getint(sizeof(long))/0x7fffffff; |
175 |
< |
return(ldexp(d, (char)getint(1))); /* sign extend */ |
174 |
> |
d = (double)getint(4)/0x7fffffff; |
175 |
> |
return(ldexp(d, (int)getint(1))); |
176 |
|
} |
177 |
|
|
178 |
|
|
209 |
|
register int i; |
210 |
|
register OBJREC *objp; |
211 |
|
|
212 |
< |
i = (char)getint(1); /* sign extend */ |
213 |
< |
if (i < 0) |
212 |
> |
i = getint(1); |
213 |
> |
if (i == -1) |
214 |
|
return(OVOID); /* terminator */ |
215 |
|
if ((obj = newobject()) == OVOID) |
216 |
|
error(SYSTEM, "out of object space"); |
236 |
|
if (objp->oargs.iarg == NULL) |
237 |
|
goto memerr; |
238 |
|
for (i = 0; i < objp->oargs.niargs; i++) |
239 |
< |
objp->oargs.iarg[i] = getint(sizeof(long)); |
239 |
> |
objp->oargs.iarg[i] = getint(4); |
240 |
|
} else |
241 |
|
objp->oargs.iarg = NULL; |
242 |
|
#endif |