--- ray/src/common/readoct.c 1989/02/21 14:59:06 1.2 +++ ray/src/common/readoct.c 1990/03/12 10:39:17 1.7 @@ -18,11 +18,11 @@ static char SCCSid[] = "$SunId$ LBL"; #include "otypes.h" -double atof(); -double getflt(); -long getint(); -char *getstr(); -OCTREE getfullnode(), gettree(); +extern double atof(); +static double getflt(); +static long getint(); +static char *getstr(); +static OCTREE getfullnode(), gettree(); static char *infn; /* input file name */ static FILE *infp; /* input file stream */ @@ -59,7 +59,7 @@ char *ofn[]; getheader(infp, NULL); /* check format */ if (getint(2) != OCTMAGIC) - octerror(USER, "bad octree"); + octerror(USER, "invalid octree format"); /* get boundaries */ if (load & IO_BOUNDS) { for (i = 0; i < 3; i++) @@ -133,19 +133,24 @@ getfullnode() /* get a set, return fullnode */ static long -getint(siz) /* get a siz-byte positive integer */ +getint(siz) /* get a siz-byte integer */ register int siz; { register int c; - register long r = 0L; + register long r; - while (siz--) { + if ((c = getc(infp)) == EOF) + goto end_file; + r = 0x80&c ? -1<<8|c : c; /* sign extend */ + while (--siz > 0) { if ((c = getc(infp)) == EOF) - octerror(USER, "truncated octree"); + goto end_file; r <<= 8; r |= c; } return(r); +end_file: + octerror(USER, "truncated octree"); } @@ -155,8 +160,8 @@ getflt() /* get a floating point number */ extern double ldexp(); double d; - d = (double)getint(sizeof(long))/0x7fffffff; - return(ldexp(d, (char)getint(1))); /* sign extend */ + d = (double)getint(4)/0x7fffffff; + return(ldexp(d, getint(1))); } @@ -194,7 +199,7 @@ getobj() /* get next object */ register OBJREC *objp; i = getint(1); - if (i & 0x80) + if (i == -1) return(OVOID); /* terminator */ if ((obj = newobject()) == OVOID) error(SYSTEM, "out of object space"); @@ -220,7 +225,7 @@ getobj() /* get next object */ if (objp->oargs.iarg == NULL) goto memerr; for (i = 0; i < objp->oargs.niargs; i++) - objp->oargs.iarg[i] = getint(sizeof(long)); + objp->oargs.iarg[i] = getint(4); } else objp->oargs.iarg = NULL; #endif