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"; |
18 |
|
|
19 |
|
#include "otypes.h" |
20 |
|
|
21 |
< |
double atof(); |
22 |
< |
double getflt(); |
23 |
< |
long getint(); |
24 |
< |
char *getstr(); |
25 |
< |
OCTREE getfullnode(), gettree(); |
21 |
> |
static double getflt(); |
22 |
> |
static long getint(); |
23 |
> |
static char *getstr(); |
24 |
> |
static int getobj(), octerror(); |
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 |
|
|
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 |
+ |
long m; |
47 |
|
|
48 |
|
if (fname == NULL) { |
49 |
|
infn = "standard input"; |
57 |
|
} |
58 |
|
} |
59 |
|
/* get header */ |
60 |
< |
if (load & IO_INFO) |
61 |
< |
copyheader(infp, stdout); |
58 |
< |
else |
59 |
< |
getheader(infp, NULL); |
60 |
> |
if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : NULL) < 0) |
61 |
> |
octerror(USER, "not an octree"); |
62 |
|
/* check format */ |
63 |
< |
if (getint(2) != OCTMAGIC) |
64 |
< |
octerror(USER, "bad octree"); |
63 |
> |
if ((objsize = getint(2)-OCTMAGIC) <= 0 || |
64 |
> |
objsize > MAXOBJSIZ || objsize > sizeof(long)) |
65 |
> |
octerror(USER, "incompatible octree format"); |
66 |
|
/* get boundaries */ |
67 |
|
if (load & IO_BOUNDS) { |
68 |
|
for (i = 0; i < 3; i++) |
83 |
|
} |
84 |
|
if (load & IO_FILES) |
85 |
|
ofn[nf] = NULL; |
86 |
+ |
/* get number of objects */ |
87 |
+ |
fnobjects = m = getint(objsize); |
88 |
+ |
if (fnobjects != m) |
89 |
+ |
octerror(USER, "too many objects"); |
90 |
|
|
91 |
|
if (load & IO_TREE) { |
92 |
|
/* get the octree */ |
101 |
|
} |
102 |
|
while (getobj() != OVOID) |
103 |
|
; |
104 |
+ |
} else if (load & IO_SCENE) { /* consistency checks */ |
105 |
+ |
/* check object count */ |
106 |
+ |
if (nobjects != objorig+fnobjects) |
107 |
+ |
octerror(USER, "bad object count; octree stale?"); |
108 |
+ |
/* check for non-surfaces */ |
109 |
+ |
if (nonsurfinset(objorig, fnobjects)) |
110 |
+ |
octerror(USER, "non-surface in set; octree stale?"); |
111 |
|
} |
112 |
|
} |
113 |
|
fclose(infp); |
136 |
|
{ |
137 |
|
OBJECT set[MAXSET+1]; |
138 |
|
register int i; |
139 |
+ |
register long m; |
140 |
|
|
141 |
< |
set[0] = getint(sizeof(OBJECT)); |
127 |
< |
if (set[0] > MAXSET) |
141 |
> |
if ((set[0] = getint(objsize)) > MAXSET) |
142 |
|
octerror(USER, "bad set in getfullnode"); |
143 |
< |
for (i = 1; i <= set[0]; i++) |
144 |
< |
set[i] = getint(sizeof(OBJECT)) + objorig; |
143 |
> |
for (i = 1; i <= set[0]; i++) { |
144 |
> |
m = getint(objsize) + objorig; |
145 |
> |
if ((set[i] = m) != m) |
146 |
> |
octerror(USER, "too many objects"); |
147 |
> |
} |
148 |
|
return(fullnode(set)); |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
static long |
153 |
< |
getint(siz) /* get a siz-byte positive integer */ |
153 |
> |
getint(siz) /* get a siz-byte integer */ |
154 |
|
register int siz; |
155 |
|
{ |
156 |
|
register int c; |
157 |
< |
register long r = 0L; |
157 |
> |
register long r; |
158 |
|
|
159 |
< |
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 |
|
|
177 |
|
extern double ldexp(); |
178 |
|
double d; |
179 |
|
|
180 |
< |
d = (double)getint(sizeof(long))/0x7fffffff; |
181 |
< |
return(ldexp(d, (char)getint(1))); /* sign extend */ |
180 |
> |
d = (double)getint(4)/0x7fffffff; |
181 |
> |
return(ldexp(d, (int)getint(1))); |
182 |
|
} |
183 |
|
|
184 |
|
|
213 |
|
char sbuf[MAXSTR]; |
214 |
|
int obj; |
215 |
|
register int i; |
216 |
+ |
register long m; |
217 |
|
register OBJREC *objp; |
218 |
|
|
219 |
|
i = getint(1); |
220 |
< |
if (i & 0x80) |
220 |
> |
if (i == -1) |
221 |
|
return(OVOID); /* terminator */ |
222 |
|
if ((obj = newobject()) == OVOID) |
223 |
|
error(SYSTEM, "out of object space"); |
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 |
247 |
|
if (objp->oargs.iarg == NULL) |
248 |
|
goto memerr; |
249 |
|
for (i = 0; i < objp->oargs.niargs; i++) |
250 |
< |
objp->oargs.iarg[i] = getint(sizeof(long)); |
250 |
> |
objp->oargs.iarg[i] = getint(4); |
251 |
|
} else |
252 |
|
objp->oargs.iarg = NULL; |
253 |
|
#endif |
254 |
|
if (objp->oargs.nfargs = getint(2)) { |
255 |
< |
objp->oargs.farg = (double *)bmalloc |
256 |
< |
(objp->oargs.nfargs*sizeof(double)); |
255 |
> |
objp->oargs.farg = (FLOAT *)bmalloc |
256 |
> |
(objp->oargs.nfargs*sizeof(FLOAT)); |
257 |
|
if (objp->oargs.farg == NULL) |
258 |
|
goto memerr; |
259 |
|
for (i = 0; i < objp->oargs.nfargs; i++) |