--- ray/src/common/readoct.c 1993/06/07 09:42:16 2.9 +++ ray/src/common/readoct.c 2003/02/25 02:47:21 2.14 @@ -1,15 +1,12 @@ -/* Copyright (c) 1992 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: readoct.c,v 2.14 2003/02/25 02:47:21 greg Exp $"; #endif - /* * readoct.c - routines to read octree information. - * - * 7/30/85 */ +#include "copyright.h" + #include "standard.h" #include "octree.h" @@ -21,37 +18,44 @@ static char SCCSid[] = "$SunId$ LBL"; static double ogetflt(); static long ogetint(); static char *ogetstr(); -static int getobj(), octerror(); +static int nonsurfinset(); +static int getobj(), octerror(), skiptree(); static OCTREE getfullnode(), gettree(); -static char *infn; /* input file name */ +static char *infn; /* input file specification */ static FILE *infp; /* input file stream */ static int objsize; /* size of stored OBJECT's */ static OBJECT objorig; /* zeroeth object */ +static OBJECT fnobjects; /* number of objects in this file */ static short otypmap[NUMOTYPE+8]; /* object type map */ int -readoct(fname, load, scene, ofn) /* read in octree from file */ -char *fname; +readoct(inpspec, load, scene, ofn) /* read in octree file or stream */ +char *inpspec; int load; CUBE *scene; char *ofn[]; { char sbuf[512]; int nf; - OBJECT fnobjects; register int i; long m; - if (fname == NULL) { + if (inpspec == NULL) { infn = "standard input"; infp = stdin; + } else if (inpspec[0] == '!') { + infn = inpspec; + if ((infp = popen(inpspec+1, "r")) == NULL) { + sprintf(errmsg, "cannot execute \"%s\"", inpspec); + error(SYSTEM, errmsg); + } } else { - infn = fname; - if ((infp = fopen(fname, "r")) == NULL) { + infn = inpspec; + if ((infp = fopen(inpspec, "r")) == NULL) { sprintf(errmsg, "cannot open octree file \"%s\"", - fname); + inpspec); error(SYSTEM, errmsg); } } @@ -59,7 +63,7 @@ char *ofn[]; setmode(fileno(infp), O_BINARY); #endif /* get header */ - if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : NULL) < 0) + if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : (FILE *)NULL) < 0) octerror(USER, "not an octree"); /* check format */ if ((objsize = ogetint(2)-OCTMAGIC) <= 0 || @@ -90,7 +94,7 @@ char *ofn[]; if (fnobjects != m) octerror(USER, "too many objects"); - if (load & IO_TREE) /* get the octree */ + if (load & IO_TREE) /* get the octree */ scene->cutree = gettree(); else if (load & IO_SCENE && nf == 0) skiptree(); @@ -109,10 +113,14 @@ char *ofn[]; if (nobjects != objorig+fnobjects) octerror(USER, "bad object count; octree stale?"); /* check for non-surfaces */ - if (nonsurfinset(objorig, fnobjects)) + if (dosets(nonsurfinset)) octerror(USER, "modifier in tree; octree stale?"); } - fclose(infp); + /* close the input */ + if (infn[0] == '!') + pclose(infp); + else + fclose(infp); return(nf); } @@ -199,6 +207,21 @@ gettree() /* get a pre-ordered octree */ } +static int +nonsurfinset(os) /* check set for modifier */ +register OBJECT *os; +{ + register OBJECT s; + register int i; + + for (i = *os; i-- > 0; ) + if ((s = *++os) >= objorig && s < objorig+fnobjects && + ismodifier(objptr(s)->otype)) + return(1); + return(0); +} + + static skiptree() /* skip octree on input */ { @@ -249,7 +272,7 @@ getobj() /* get next object */ objp->omod = m; objp->oname = savqstr(ogetstr(sbuf)); if (objp->oargs.nsargs = ogetint(2)) { - objp->oargs.sarg = (char **)bmalloc + objp->oargs.sarg = (char **)malloc (objp->oargs.nsargs*sizeof(char *)); if (objp->oargs.sarg == NULL) goto memerr; @@ -259,7 +282,7 @@ getobj() /* get next object */ objp->oargs.sarg = NULL; #ifdef IARGS if (objp->oargs.niargs = ogetint(2)) { - objp->oargs.iarg = (long *)bmalloc + objp->oargs.iarg = (long *)malloc (objp->oargs.niargs*sizeof(long)); if (objp->oargs.iarg == NULL) goto memerr; @@ -269,7 +292,7 @@ getobj() /* get next object */ objp->oargs.iarg = NULL; #endif if (objp->oargs.nfargs = ogetint(2)) { - objp->oargs.farg = (FLOAT *)bmalloc + objp->oargs.farg = (FLOAT *)malloc (objp->oargs.nfargs*sizeof(FLOAT)); if (objp->oargs.farg == NULL) goto memerr;