| 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 ogetflt(); |
| 22 |
> |
static long ogetint(); |
| 23 |
> |
static char *ogetstr(); |
| 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, "invalid octree format"); |
| 63 |
> |
if ((objsize = ogetint(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++) |
| 69 |
< |
scene->cuorg[i] = atof(getstr(sbuf)); |
| 70 |
< |
scene->cusize = atof(getstr(sbuf)); |
| 69 |
> |
scene->cuorg[i] = atof(ogetstr(sbuf)); |
| 70 |
> |
scene->cusize = atof(ogetstr(sbuf)); |
| 71 |
|
} else { |
| 72 |
|
for (i = 0; i < 4; i++) |
| 73 |
< |
getstr(sbuf); |
| 73 |
> |
ogetstr(sbuf); |
| 74 |
|
} |
| 75 |
|
objorig = nobjects; /* set object offset */ |
| 76 |
|
nf = 0; /* get object files */ |
| 77 |
< |
while (*getstr(sbuf)) { |
| 77 |
> |
while (*ogetstr(sbuf)) { |
| 78 |
|
if (load & IO_SCENE) |
| 79 |
|
readobj(sbuf); |
| 80 |
|
if (load & IO_FILES) |
| 83 |
|
} |
| 84 |
|
if (load & IO_FILES) |
| 85 |
|
ofn[nf] = NULL; |
| 86 |
+ |
/* get number of objects */ |
| 87 |
+ |
fnobjects = m = ogetint(objsize); |
| 88 |
+ |
if (fnobjects != m) |
| 89 |
+ |
octerror(USER, "too many objects"); |
| 90 |
|
|
| 91 |
|
if (load & IO_TREE) { |
| 92 |
|
/* get the octree */ |
| 93 |
|
scene->cutree = gettree(); |
| 94 |
< |
/* get the scene */ |
| 95 |
< |
if (nf == 0 && load & IO_SCENE) { |
| 96 |
< |
for (i = 0; *getstr(sbuf); i++) |
| 94 |
> |
if (load & IO_SCENE) /* get the scene */ |
| 95 |
> |
if (nf == 0) { |
| 96 |
> |
for (i = 0; *ogetstr(sbuf); i++) |
| 97 |
|
if ((otypmap[i] = otype(sbuf)) < 0) { |
| 98 |
|
sprintf(errmsg, "unknown type \"%s\"", |
| 99 |
|
sbuf); |
| 101 |
|
} |
| 102 |
|
while (getobj() != OVOID) |
| 103 |
|
; |
| 104 |
< |
} |
| 104 |
> |
} else { /* 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, "modifier in tree; octree stale?"); |
| 111 |
> |
} |
| 112 |
|
} |
| 113 |
|
fclose(infp); |
| 114 |
|
return(nf); |
| 116 |
|
|
| 117 |
|
|
| 118 |
|
static char * |
| 119 |
< |
getstr(s) /* get null-terminated string */ |
| 119 |
> |
ogetstr(s) /* get null-terminated string */ |
| 120 |
|
char *s; |
| 121 |
|
{ |
| 122 |
< |
register char *cp; |
| 109 |
< |
register int c; |
| 122 |
> |
extern char *getstr(); |
| 123 |
|
|
| 124 |
< |
cp = s; |
| 125 |
< |
while ((c = getc(infp)) != EOF) |
| 126 |
< |
if ((*cp++ = c) == '\0') |
| 114 |
< |
return(s); |
| 115 |
< |
|
| 116 |
< |
octerror(USER, "truncated octree"); |
| 124 |
> |
if (getstr(s, infp) == NULL) |
| 125 |
> |
octerror(USER, "truncated octree"); |
| 126 |
> |
return(s); |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
|
| 132 |
|
{ |
| 133 |
|
OBJECT set[MAXSET+1]; |
| 134 |
|
register int i; |
| 135 |
+ |
register long m; |
| 136 |
|
|
| 137 |
< |
set[0] = getint(sizeof(OBJECT)); |
| 127 |
< |
if (set[0] > MAXSET) |
| 137 |
> |
if ((set[0] = ogetint(objsize)) > MAXSET) |
| 138 |
|
octerror(USER, "bad set in getfullnode"); |
| 139 |
< |
for (i = 1; i <= set[0]; i++) |
| 140 |
< |
set[i] = getint(sizeof(OBJECT)) + objorig; |
| 139 |
> |
for (i = 1; i <= set[0]; i++) { |
| 140 |
> |
m = ogetint(objsize) + objorig; |
| 141 |
> |
if ((set[i] = m) != m) |
| 142 |
> |
octerror(USER, "too many objects"); |
| 143 |
> |
} |
| 144 |
|
return(fullnode(set)); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
|
| 148 |
|
static long |
| 149 |
< |
getint(siz) /* get a siz-byte integer */ |
| 150 |
< |
register int siz; |
| 149 |
> |
ogetint(siz) /* get a siz-byte integer */ |
| 150 |
> |
int siz; |
| 151 |
|
{ |
| 152 |
< |
register int c; |
| 152 |
> |
extern long getint(); |
| 153 |
|
register long r; |
| 154 |
|
|
| 155 |
< |
if ((c = getc(infp)) == EOF) |
| 156 |
< |
goto end_file; |
| 157 |
< |
r = 0x80&c ? -1<<8|c : c; /* sign extend */ |
| 145 |
< |
while (--siz > 0) { |
| 146 |
< |
if ((c = getc(infp)) == EOF) |
| 147 |
< |
goto end_file; |
| 148 |
< |
r <<= 8; |
| 149 |
< |
r |= c; |
| 150 |
< |
} |
| 155 |
> |
r = getint(siz, infp); |
| 156 |
> |
if (feof(infp)) |
| 157 |
> |
octerror(USER, "truncated octree"); |
| 158 |
|
return(r); |
| 152 |
– |
end_file: |
| 153 |
– |
octerror(USER, "truncated octree"); |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
|
| 162 |
|
static double |
| 163 |
< |
getflt() /* get a floating point number */ |
| 163 |
> |
ogetflt() /* get a floating point number */ |
| 164 |
|
{ |
| 165 |
< |
extern double ldexp(); |
| 166 |
< |
double d; |
| 165 |
> |
extern double getflt(); |
| 166 |
> |
double r; |
| 167 |
|
|
| 168 |
< |
d = (double)getint(4)/0x7fffffff; |
| 169 |
< |
return(ldexp(d, getint(1))); |
| 168 |
> |
r = getflt(infp); |
| 169 |
> |
if (feof(infp)) |
| 170 |
> |
octerror(USER, "truncated octree"); |
| 171 |
> |
return(r); |
| 172 |
|
} |
| 173 |
|
|
| 174 |
|
|
| 203 |
|
char sbuf[MAXSTR]; |
| 204 |
|
int obj; |
| 205 |
|
register int i; |
| 206 |
+ |
register long m; |
| 207 |
|
register OBJREC *objp; |
| 208 |
|
|
| 209 |
< |
i = getint(1); |
| 209 |
> |
i = ogetint(1); |
| 210 |
|
if (i == -1) |
| 211 |
|
return(OVOID); /* terminator */ |
| 212 |
|
if ((obj = newobject()) == OVOID) |
| 214 |
|
objp = objptr(obj); |
| 215 |
|
if ((objp->otype = otypmap[i]) < 0) |
| 216 |
|
octerror(USER, "reference to unknown type"); |
| 217 |
< |
if ((objp->omod = getint(sizeof(OBJECT))) != OVOID) |
| 218 |
< |
objp->omod += objorig; |
| 219 |
< |
objp->oname = savqstr(getstr(sbuf)); |
| 220 |
< |
if (objp->oargs.nsargs = getint(2)) { |
| 217 |
> |
if ((m = ogetint(objsize)) != OVOID) { |
| 218 |
> |
m += objorig; |
| 219 |
> |
if ((OBJECT)m != m) |
| 220 |
> |
octerror(USER, "too many objects"); |
| 221 |
> |
} |
| 222 |
> |
objp->omod = m; |
| 223 |
> |
objp->oname = savqstr(ogetstr(sbuf)); |
| 224 |
> |
if (objp->oargs.nsargs = ogetint(2)) { |
| 225 |
|
objp->oargs.sarg = (char **)bmalloc |
| 226 |
|
(objp->oargs.nsargs*sizeof(char *)); |
| 227 |
|
if (objp->oargs.sarg == NULL) |
| 228 |
|
goto memerr; |
| 229 |
|
for (i = 0; i < objp->oargs.nsargs; i++) |
| 230 |
< |
objp->oargs.sarg[i] = savestr(getstr(sbuf)); |
| 230 |
> |
objp->oargs.sarg[i] = savestr(ogetstr(sbuf)); |
| 231 |
|
} else |
| 232 |
|
objp->oargs.sarg = NULL; |
| 233 |
|
#ifdef IARGS |
| 234 |
< |
if (objp->oargs.niargs = getint(2)) { |
| 234 |
> |
if (objp->oargs.niargs = ogetint(2)) { |
| 235 |
|
objp->oargs.iarg = (long *)bmalloc |
| 236 |
|
(objp->oargs.niargs*sizeof(long)); |
| 237 |
|
if (objp->oargs.iarg == NULL) |
| 238 |
|
goto memerr; |
| 239 |
|
for (i = 0; i < objp->oargs.niargs; i++) |
| 240 |
< |
objp->oargs.iarg[i] = getint(4); |
| 240 |
> |
objp->oargs.iarg[i] = ogetint(4); |
| 241 |
|
} else |
| 242 |
|
objp->oargs.iarg = NULL; |
| 243 |
|
#endif |
| 244 |
< |
if (objp->oargs.nfargs = getint(2)) { |
| 245 |
< |
objp->oargs.farg = (double *)bmalloc |
| 246 |
< |
(objp->oargs.nfargs*sizeof(double)); |
| 244 |
> |
if (objp->oargs.nfargs = ogetint(2)) { |
| 245 |
> |
objp->oargs.farg = (FLOAT *)bmalloc |
| 246 |
> |
(objp->oargs.nfargs*sizeof(FLOAT)); |
| 247 |
|
if (objp->oargs.farg == NULL) |
| 248 |
|
goto memerr; |
| 249 |
|
for (i = 0; i < objp->oargs.nfargs; i++) |
| 250 |
< |
objp->oargs.farg[i] = getflt(); |
| 250 |
> |
objp->oargs.farg[i] = ogetflt(); |
| 251 |
|
} else |
| 252 |
|
objp->oargs.farg = NULL; |
| 253 |
|
/* initialize */ |