--- ray/src/common/readoct.c 1997/03/07 15:45:26 2.12 +++ 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" @@ -25,7 +22,7 @@ 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 */ @@ -34,8 +31,8 @@ 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[]; @@ -45,14 +42,20 @@ char *ofn[]; 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); } } @@ -91,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(); @@ -113,7 +116,11 @@ char *ofn[]; 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); } @@ -265,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; @@ -275,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; @@ -285,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;