--- ray/src/util/rad.c 1997/03/20 12:50:07 2.53 +++ ray/src/util/rad.c 2004/01/01 19:31:46 2.75 @@ -1,84 +1,95 @@ -/* Copyright (c) 1995 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: rad.c,v 2.75 2004/01/01 19:31:46 greg Exp $"; #endif - /* * Executive program for oconv, rpict and pfilt */ #include "standard.h" + +#include +#include + +#include "platform.h" +#include "rtprocess.h" +#include "view.h" #include "paths.h" #include "vars.h" -#include -#include - /* variables */ -#define OBJECT 0 /* object files */ -#define SCENE 1 /* scene files */ -#define MATERIAL 2 /* material files */ -#define ILLUM 3 /* mkillum input files */ -#define MKILLUM 4 /* mkillum options */ -#define RENDER 5 /* rendering options */ -#define OCONV 6 /* oconv options */ -#define PFILT 7 /* pfilt options */ -#define VIEW 8 /* view(s) for picture(s) */ -#define ZONE 9 /* simulation zone */ -#define QUALITY 10 /* desired rendering quality */ -#define OCTREE 11 /* octree file name */ -#define PICTURE 12 /* picture file root name */ -#define AMBFILE 13 /* ambient file name */ -#define OPTFILE 14 /* rendering options file */ -#define EXPOSURE 15 /* picture exposure setting */ -#define RESOLUTION 16 /* maximum picture resolution */ -#define UP 17 /* view up (X, Y or Z) */ -#define INDIRECT 18 /* indirection in lighting */ -#define DETAIL 19 /* level of scene detail */ -#define PENUMBRAS 20 /* shadow penumbras are desired */ -#define VARIABILITY 21 /* level of light variability */ -#define REPORT 22 /* report frequency and errfile */ -#define RAWFILE 23 /* raw picture file root name */ +#ifdef _WIN32 + #define DELCMD "del" + #define RENAMECMD "rename" +#else + #define DELCMD "rm -f" + #define RENAMECMD "mv" +#endif + + /* variables (alphabetical by name) */ +#define AMBFILE 0 /* ambient file name */ +#define DETAIL 1 /* level of scene detail */ +#define EXPOSURE 2 /* picture exposure setting */ +#define EYESEP 3 /* interocular distance */ +#define ILLUM 4 /* mkillum input files */ +#define INDIRECT 5 /* indirection in lighting */ +#define MATERIAL 6 /* material files */ +#define MKILLUM 7 /* mkillum options */ +#define OBJECT 8 /* object files */ +#define OCONV 9 /* oconv options */ +#define OCTREE 10 /* octree file name */ +#define OPTFILE 11 /* rendering options file */ +#define PENUMBRAS 12 /* shadow penumbras are desired */ +#define PFILT 13 /* pfilt options */ +#define PICTURE 14 /* picture file root name */ +#define QUALITY 15 /* desired rendering quality */ +#define RAWFILE 16 /* raw picture file root name */ +#define RENDER 17 /* rendering options */ +#define REPORT 18 /* report frequency and errfile */ +#define RESOLUTION 19 /* maximum picture resolution */ +#define SCENE 20 /* scene files */ +#define UP 21 /* view up (X, Y or Z) */ +#define VARIABILITY 22 /* level of light variability */ +#define VIEWS 23 /* view(s) for picture(s) */ #define ZFILE 24 /* distance file root name */ +#define ZONE 25 /* simulation zone */ /* total number of variables */ -int NVARS = 25; +int NVARS = 26; VARIABLE vv[] = { /* variable-value pairs */ - {"objects", 3, 0, NULL, catvalues}, - {"scene", 3, 0, NULL, catvalues}, - {"materials", 3, 0, NULL, catvalues}, + {"AMBFILE", 3, 0, NULL, onevalue}, + {"DETAIL", 3, 0, NULL, qualvalue}, + {"EXPOSURE", 3, 0, NULL, fltvalue}, + {"EYESEP", 3, 0, NULL, fltvalue}, {"illum", 3, 0, NULL, catvalues}, + {"INDIRECT", 3, 0, NULL, intvalue}, + {"materials", 3, 0, NULL, catvalues}, {"mkillum", 3, 0, NULL, catvalues}, - {"render", 3, 0, NULL, catvalues}, + {"objects", 3, 0, NULL, catvalues}, {"oconv", 3, 0, NULL, catvalues}, - {"pfilt", 2, 0, NULL, catvalues}, - {"view", 2, 0, NULL, NULL}, - {"ZONE", 2, 0, NULL, onevalue}, - {"QUALITY", 3, 0, NULL, qualvalue}, {"OCTREE", 3, 0, NULL, onevalue}, - {"PICTURE", 3, 0, NULL, onevalue}, - {"AMBFILE", 3, 0, NULL, onevalue}, {"OPTFILE", 3, 0, NULL, onevalue}, - {"EXPOSURE", 3, 0, NULL, fltvalue}, + {"PENUMBRAS", 3, 0, NULL, boolvalue}, + {"pfilt", 2, 0, NULL, catvalues}, + {"PICTURE", 3, 0, NULL, onevalue}, + {"QUALITY", 3, 0, NULL, qualvalue}, + {"RAWFILE", 3, 0, NULL, onevalue}, + {"render", 3, 0, NULL, catvalues}, + {"REPORT", 3, 0, NULL, onevalue}, {"RESOLUTION", 3, 0, NULL, onevalue}, + {"scene", 3, 0, NULL, catvalues}, {"UP", 2, 0, NULL, onevalue}, - {"INDIRECT", 3, 0, NULL, intvalue}, - {"DETAIL", 3, 0, NULL, qualvalue}, - {"PENUMBRAS", 3, 0, NULL, boolvalue}, {"VARIABILITY", 3, 0, NULL, qualvalue}, - {"REPORT", 3, 0, NULL, onevalue}, - {"RAWFILE", 3, 0, NULL, onevalue}, + {"view", 2, 0, NULL, NULL}, {"ZFILE", 2, 0, NULL, onevalue}, + {"ZONE", 2, 0, NULL, onevalue}, }; /* overture calculation file */ -#ifdef NIX -char overfile[] = "overture.unf"; +#ifdef NULL_DEVICE +char overfile[] = NULL_DEVICE; #else -char overfile[] = "/dev/null"; +char overfile[] = "overture.unf"; #endif -extern time_t fdate(), time(); time_t scenedate; /* date of latest scene or object file */ time_t octreedate; /* date of octree */ @@ -94,19 +105,23 @@ int nowarn = 0; /* no warnings */ int explicate = 0; /* explicate variables */ int silent = 0; /* do work silently */ int touchonly = 0; /* touch files only */ -int noaction = 0; /* don't do anything */ +int nprocs = 1; /* maximum executing processes */ int sayview = 0; /* print view out */ -char *rvdevice = NULL; /* rview output device */ +char *rvdevice = NULL; /* rvu output device */ char *viewselect = NULL; /* specific view only */ int overture = 0; /* overture calculation needed */ +int children_running = 0; /* set negative in children */ + char *progname; /* global argv[0] */ char *rifname; /* global rad input file name */ -char radname[MAXPATH]; /* root Radiance file name */ +char radname[PATH_MAX]; /* root Radiance file name */ +#define inchild() (children_running < 0) + main(argc, argv) int argc; char *argv[]; @@ -123,8 +138,13 @@ char *argv[]; silent++; break; case 'n': - noaction++; + nprocs = 0; break; + case 'N': + nprocs = atoi(argv[++i]); + if (nprocs < 0) + nprocs = 0; + break; case 't': touchonly++; break; @@ -149,6 +169,9 @@ char *argv[]; if (i >= argc) goto userr; rifname = argv[i]; + /* check command-line options */ + if ((nprocs > 1) & (viewselect != NULL)) + nprocs = 1; /* assign Radiance root file name */ rootname(radname, rifname); /* load variable values */ @@ -177,13 +200,13 @@ char *argv[]; renderopts(ropts, popts); xferopts(ropts); if (rvdevice != NULL) - rview(ropts, popts); + rvu(ropts, popts); else rpict(ropts, popts); quit(0); userr: fprintf(stderr, -"Usage: %s [-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", +"Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", progname); quit(1); } @@ -194,7 +217,7 @@ register char *rn, *fn; { char *tp, *dp; - for (tp = NULL, dp = rn; *rn = *fn++; rn++) + for (tp = NULL, dp = rn; (*rn = *fn++); rn++) if (ISDIRSEP(*rn)) dp = rn; else if (*rn == '.') @@ -208,18 +231,15 @@ time_t checklast(fnames) /* check files and find most recent */ register char *fnames; { - char thisfile[MAXPATH]; + char thisfile[PATH_MAX]; time_t thisdate, lastdate = 0; - register char *cp; if (fnames == NULL) return(0); - while (*fnames) { - while (isspace(*fnames)) fnames++; - cp = thisfile; - while (*fnames && !isspace(*fnames)) - *cp++ = *fnames++; - *cp = '\0'; + while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) { + if (thisfile[0] == '!' || + (thisfile[0] == '\\' && thisfile[1] == '!')) + continue; if (!(thisdate = fdate(thisfile))) syserr(thisfile); if (thisdate > lastdate) @@ -234,7 +254,6 @@ newfname(orig, pred) /* create modified file name */ char *orig; int pred; { - extern char *rindex(); register char *cp; register int n; int suffix; @@ -264,6 +283,10 @@ checkfiles() /* check for existence and modified tim syserr(progname); sprintf(vval(OCTREE), "%s.oct", radname); vdef(OCTREE)++; + } else if (vval(OCTREE)[0] == '!') { + fprintf(stderr, "%s: illegal '%s' specification\n", + progname, vnam(OCTREE)); + quit(1); } octreedate = fdate(vval(OCTREE)); if (vdef(ILLUM)) { /* illum requires secondary octrees */ @@ -289,15 +312,14 @@ checkfiles() /* check for existence and modified tim getoctcube(org, sizp) /* get octree bounding cube */ double org[3], *sizp; { - extern FILE *popen(); static double oorg[3], osiz = 0.; double min[3], max[3]; char buf[1024]; FILE *fp; register int i; - if (osiz <= FTINY) - if (noaction && fdate(oct1name) < + if (osiz <= FTINY) { + if (!nprocs && fdate(oct1name) < (scenedate>illumdate?scenedate:illumdate)) { /* run getbbox */ sprintf(buf, "getbbox -w -h %s", @@ -332,13 +354,14 @@ double org[3], *sizp; } pclose(fp); } + } org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz; } setdefaults() /* set default values for unassigned var's */ { - double org[3], size; + double org[3], lim[3], size; char buf[128]; if (!vdef(ZONE)) { @@ -348,6 +371,16 @@ setdefaults() /* set default values for unassigned v vval(ZONE) = savqstr(buf); vdef(ZONE)++; } + if (!vdef(EYESEP)) { + if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", + &org[0], &lim[0], &org[1], &lim[1], + &org[2], &lim[2]) != 6) + badvalue(ZONE); + sprintf(buf, "%f", + 0.01*(lim[0]-org[0]+lim[1]-org[1]+lim[2]-org[2])); + vval(EYESEP) = savqstr(buf); + vdef(EYESEP)++; + } if (!vdef(INDIRECT)) { vval(INDIRECT) = "0"; vdef(INDIRECT)++; @@ -364,9 +397,9 @@ setdefaults() /* set default values for unassigned v vval(PICTURE) = radname; vdef(PICTURE)++; } - if (!vdef(VIEW)) { - vval(VIEW) = "X"; - vdef(VIEW)++; + if (!vdef(VIEWS)) { + vval(VIEWS) = "X"; + vdef(VIEWS)++; } if (!vdef(DETAIL)) { vval(DETAIL) = "M"; @@ -386,7 +419,7 @@ setdefaults() /* set default values for unassigned v oconv() /* run oconv and mkillum if necessary */ { static char illumtmp[] = "ilXXXXXX"; - char combuf[1024], ocopts[64], mkopts[64]; + char combuf[PATH_MAX], ocopts[64], mkopts[64]; oconvopts(ocopts); /* get options */ if (octreedate < scenedate) { /* check date on original octree */ @@ -415,11 +448,11 @@ oconv() /* run oconv and mkillum if necessary */ } if (oct1name == vval(OCTREE)) /* no mkillum? */ oct1date = octreedate > matdate ? octreedate : matdate; - if (oct1date >= octreedate & oct1date >= matdate - & oct1date >= illumdate) /* all done */ + if ((oct1date >= octreedate) & (oct1date >= matdate) + & (oct1date >= illumdate)) /* all done */ return; /* make octree0 */ - if (oct0date < scenedate | oct0date < illumdate) { + if ((oct0date < scenedate) | (oct0date < illumdate)) { if (touchonly && oct0date) touch(oct0name); else { /* build command */ @@ -490,7 +523,7 @@ addarg(op, arg) /* add argument and advance pointer register char *op, *arg; { *op = ' '; - while (*++op = *arg++) + while ( (*++op = *arg++) ) ; return(op); } @@ -526,11 +559,12 @@ checkambfile() /* check date on ambient file */ return; if (!(afdate = fdate(vval(AMBFILE)))) return; - if (oct1date > afdate) + if (oct1date > afdate) { if (touchonly) touch(vval(AMBFILE)); else rmfile(vval(AMBFILE)); + } } @@ -579,7 +613,7 @@ char *po; &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) badvalue(ZONE); siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; - if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY) + if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY)) badvalue(ZONE); getoctcube(org, &d); d *= 3./(siz[0]+siz[1]+siz[2]); @@ -587,19 +621,19 @@ char *po; case LOW: po = addarg(po, "-ps 16"); op = addarg(op, "-dp 64"); - sprintf(op, " -ar %d", (int)(4*d)); + sprintf(op, " -ar %d", (int)(8*d)); op += strlen(op); break; case MEDIUM: po = addarg(po, "-ps 8"); op = addarg(op, "-dp 128"); - sprintf(op, " -ar %d", (int)(8*d)); + sprintf(op, " -ar %d", (int)(16*d)); op += strlen(op); break; case HIGH: po = addarg(po, "-ps 4"); op = addarg(op, "-dp 256"); - sprintf(op, " -ar %d", (int)(16*d)); + sprintf(op, " -ar %d", (int)(32*d)); op += strlen(op); break; } @@ -616,20 +650,20 @@ char *po; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aw 128 -aa .4 -ad 64"); + op = addarg(op, "-aa .3 -ad 256"); break; case MEDIUM: - op = addarg(op, "-aw 1024 -aa .3 -ad 128"); + op = addarg(op, "-aa .25 -ad 512"); break; case HIGH: - op = addarg(op, "-aa .25 -ad 256"); + op = addarg(op, "-aa .2 -ad 1024"); break; } op = addarg(op, "-as 0"); d = ambval(); sprintf(op, " -av %.2g %.2g %.2g", d, d, d); op += strlen(op); - op = addarg(op, "-lr 3 -lw .02"); + op = addarg(op, "-lr 6 -lw .01"); if (vdef(RENDER)) op = addarg(op, vval(RENDER)); } @@ -647,7 +681,7 @@ char *po; &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) badvalue(ZONE); siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; - if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY) + if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY)) badvalue(ZONE); getoctcube(org, &d); asz = (siz[0]+siz[1]+siz[2])/3.; @@ -656,7 +690,7 @@ char *po; case LOW: po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8"); op = addarg(op, "-dp 256"); - sprintf(op, " -ar %d", (int)(8*d)); + sprintf(op, " -ar %d", (int)(16*d)); op += strlen(op); sprintf(op, " -ms %.2g", asz/20.); op += strlen(op); @@ -664,7 +698,7 @@ char *po; case MEDIUM: po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6"); op = addarg(op, "-dp 512"); - sprintf(op, " -ar %d", (int)(16*d)); + sprintf(op, " -ar %d", (int)(32*d)); op += strlen(op); sprintf(op, " -ms %.2g", asz/40.); op += strlen(op); @@ -672,7 +706,7 @@ char *po; case HIGH: po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4"); op = addarg(op, "-dp 1024"); - sprintf(op, " -ar %d", (int)(32*d)); + sprintf(op, " -ar %d", (int)(64*d)); op += strlen(op); sprintf(op, " -ms %.2g", asz/80.); op += strlen(op); @@ -684,7 +718,7 @@ char *po; else op = addarg(op, "-ds .3"); op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1"); - if (overture = vint(INDIRECT)) { + if ( (overture = vint(INDIRECT)) ) { sprintf(op, " -ab %d", overture); op += strlen(op); } @@ -695,19 +729,19 @@ char *po; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aw 128 -aa .25 -ad 196 -as 0"); + op = addarg(op, "-aa .2 -ad 329 -as 42"); break; case MEDIUM: - op = addarg(op, "-aw 1024 -aa .2 -ad 400 -as 64"); + op = addarg(op, "-aa .15 -ad 800 -as 128"); break; case HIGH: - op = addarg(op, "-aa .15 -ad 768 -as 196"); + op = addarg(op, "-aa .1 -ad 1536 -as 392"); break; } d = ambval(); sprintf(op, " -av %.2g %.2g %.2g", d, d, d); op += strlen(op); - op = addarg(op, "-lr 6 -lw .002"); + op = addarg(op, "-lr 8 -lw .002"); if (vdef(RENDER)) op = addarg(op, vval(RENDER)); } @@ -725,7 +759,7 @@ char *po; &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) badvalue(ZONE); siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; - if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY) + if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY)) badvalue(ZONE); getoctcube(org, &d); asz = (siz[0]+siz[1]+siz[2])/3.; @@ -734,7 +768,7 @@ char *po; case LOW: po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8"); op = addarg(op, "-dp 1024"); - sprintf(op, " -ar %d", (int)(16*d)); + sprintf(op, " -ar %d", (int)(32*d)); op += strlen(op); sprintf(op, " -ms %.2g", asz/40.); op += strlen(op); @@ -742,7 +776,7 @@ char *po; case MEDIUM: po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5"); op = addarg(op, "-dp 2048"); - sprintf(op, " -ar %d", (int)(32*d)); + sprintf(op, " -ar %d", (int)(64*d)); op += strlen(op); sprintf(op, " -ms %.2g", asz/80.); op += strlen(op); @@ -750,7 +784,7 @@ char *po; case HIGH: po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3"); op = addarg(op, "-dp 4096"); - sprintf(op, " -ar %d", (int)(64*d)); + sprintf(op, " -ar %d", (int)(128*d)); op += strlen(op); sprintf(op, " -ms %.2g", asz/160.); op += strlen(op); @@ -771,13 +805,13 @@ char *po; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aw 128 -aa .15 -ad 256 -as 0"); + op = addarg(op, "-aa .125 -ad 512 -as 64"); break; case MEDIUM: - op = addarg(op, "-aw 1024 -aa .125 -ad 512 -as 256"); + op = addarg(op, "-aa .1 -ad 1536 -as 768"); break; case HIGH: - op = addarg(op, "-aa .08 -ad 1024 -as 512"); + op = addarg(op, "-aa .075 -ad 4096 -as 2048"); break; } d = ambval(); @@ -811,7 +845,7 @@ char *ro; syserr(vval(OPTFILE)); sprintf(ro, " @%s", vval(OPTFILE)); } -#ifdef MSDOS +#ifdef _WIN32 else if (n > 50) { setenv("ROPT", ro+1); strcpy(ro, " $ROPT"); @@ -830,7 +864,7 @@ register char *po; } switch (vscale(QUALITY)) { case MEDIUM: - po = addarg(po, "-r 1"); + po = addarg(po, "-r .6"); break; case HIGH: po = addarg(po, "-m .25"); @@ -873,7 +907,7 @@ register char *vs; upax = 1-'X'+UPPER(vval(UP)[1]); else upax = 1-'X'+vlet(UP); - if (upax < 1 | upax > 3) + if ((upax < 1) | (upax > 3)) badvalue(UP); if (vval(UP)[0] == '-') upax = -upax; @@ -896,7 +930,7 @@ register char *vs; zpos = -1; vs++; } viewtype = 'v'; - if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h' | *vs == 'c') + if((*vs == 'v') | (*vs == 'l') | (*vs == 'a') | (*vs == 'h') | (*vs == 'c')) viewtype = *vs++; cp = viewopts; if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) { /* got one! */ @@ -967,7 +1001,7 @@ register char *vs; if (cp == viewopts) /* append any additional options */ vs++; /* skip prefixed space if unneeded */ strcpy(cp, vs); -#ifdef MSDOS +#ifdef _WIN32 if (strlen(viewopts) > 40) { setenv("VIEW", viewopts); return("$VIEW"); @@ -999,15 +1033,15 @@ char *vn; /* returned view name */ } /* view number? */ if (isint(viewselect)) - return(specview(nvalue(VIEW, atoi(viewselect)-1))); + return(specview(nvalue(VIEWS, atoi(viewselect)-1))); /* check list */ - while ((mv = nvalue(VIEW, n++)) != NULL) + while ((mv = nvalue(VIEWS, n++)) != NULL) if (matchword(viewselect, mv)) return(specview(mv)); return(specview(viewselect)); /* standard view? */ } - mv = nvalue(VIEW, n); /* use view n */ - if (vn != NULL & mv != NULL) { + mv = nvalue(VIEWS, n); /* use view n */ + if ((vn != NULL) & (mv != NULL)) { register char *mv2 = mv; if (*mv2 != '-') while (*mv2 && !isspace(*mv2)) @@ -1018,81 +1052,55 @@ char *vn; /* returned view name */ } -printview(vopts) /* print out selected view */ +int +myprintview(vopts, fp) /* print out selected view */ register char *vopts; +FILE *fp; { - extern char *atos(), *getenv(); - char buf[256]; - FILE *fp; + VIEW vwr; + char buf[128]; register char *cp; - +again: if (vopts == NULL) return(-1); - fputs("VIEW=", stdout); - do { - if (matchword(vopts, "-vf")) { /* expand view file */ - vopts = sskip(vopts); - if (!*atos(buf, sizeof(buf), vopts)) - return(-1); - if ((fp = fopen(buf, "r")) == NULL) - return(-1); - for (buf[sizeof(buf)-2] = '\n'; - fgets(buf, sizeof(buf), fp) != NULL && - buf[0] != '\n'; - buf[sizeof(buf)-2] = '\n') { - if (buf[sizeof(buf)-2] != '\n') { - ungetc(buf[sizeof(buf)-2], fp); - buf[sizeof(buf)-2] = '\0'; - } - if (matchword(buf, "VIEW=") || - matchword(buf, "rview")) { - for (cp = sskip(buf); *cp && *cp != '\n'; cp++) - putchar(*cp); - } - } - fclose(fp); - vopts = sskip(vopts); - } else { - while (isspace(*vopts)) - vopts++; - putchar(' '); -#ifdef MSDOS - if (*vopts == '$') { /* expand env. var. */ - if (!*atos(buf, sizeof(buf), vopts+1)) - return(-1); - if ((cp = getenv(buf)) == NULL) - return(-1); - fputs(cp, stdout); - vopts = sskip(vopts); - } else +#ifdef _WIN32 + if (vopts[0] == '$') { + vopts = getenv(vopts+1); + goto again; + } #endif - while (*vopts && !isspace(*vopts)) - putchar(*vopts++); - } - } while (*vopts++); - putchar('\n'); + vwr = stdview; + sscanview(&vwr, cp=vopts); /* set initial options */ + while ((cp = strstr(cp, "-vf ")) != NULL && + *atos(buf, sizeof(buf), cp += 4)) { + viewfile(buf, &vwr, NULL); /* load -vf file */ + sscanview(&vwr, cp); /* reset tail */ + } + fputs(VIEWSTR, fp); + fprintview(&vwr, fp); /* print full spec. */ + fputc('\n', fp); return(0); } -rview(opts, po) /* run rview with first view */ +rvu(opts, po) /* run rvu with first view */ char *opts, *po; { char *vw; - char combuf[512]; + char combuf[PATH_MAX]; /* build command */ if (touchonly || (vw = getview(0, NULL)) == NULL) return; if (sayview) - printview(vw); - sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname); + myprintview(vw, stdout); + sprintf(combuf, "rvu %s%s%s -R %s ", vw, po, opts, rifname); if (rvdevice != NULL) sprintf(combuf+strlen(combuf), "-o %s ", rvdevice); if (vdef(EXPOSURE)) sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE)); strcat(combuf, oct1name); if (runcom(combuf)) { /* run it */ - fprintf(stderr, "%s: error running rview\n", progname); + fprintf(stderr, "%s: error running rvu\n", progname); quit(1); } } @@ -1101,12 +1109,14 @@ char *opts, *po; rpict(opts, po) /* run rpict and pfilt for each view */ char *opts, *po; { - char combuf[1024]; - char rawfile[MAXPATH], picfile[MAXPATH]; - char zopt[MAXPATH+4], rep[MAXPATH+16], res[32]; + char combuf[PATH_MAX]; + char rawfile[PATH_MAX], picfile[PATH_MAX]; + char zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32]; + char rppopt[128], *pfile = NULL; char pfopts[128]; char vs[32], *vw; int vn, mult; + FILE *fp; time_t rfdt, pfdt; /* get pfilt options */ pfiltopts(pfopts); @@ -1148,11 +1158,17 @@ char *opts, *po; else badvalue(REPORT); } - /* do each view */ - vn = 0; + /* set up parallel rendering */ + if ((nprocs > 1) & (!vdef(ZFILE))) { + strcpy(rppopt, "-S 1 -PP pfXXXXXX"); + pfile = rppopt+9; + if (mktemp(pfile) == NULL) + pfile = NULL; + } + vn = 0; /* do each view */ while ((vw = getview(vn++, vs)) != NULL) { if (sayview) - printview(vw); + myprintview(vw, stdout); if (!vs[0]) sprintf(vs, "%d", vn); sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs); @@ -1176,11 +1192,19 @@ char *opts, *po; touch(picfile); continue; } + if (next_process()) { /* parallel running? */ + if (pfile != NULL) + sleep(20); + continue; + } + /* XXX Remember to call finish_process() */ /* build rpict command */ - if (rfdt >= oct1date) /* recover */ + if (rfdt >= oct1date) { /* recover */ sprintf(combuf, "rpict%s%s%s%s -ro %s %s", rep, po, opts, zopt, rawfile, oct1name); - else { + if (runcom(combuf)) /* run rpict */ + goto rperror; + } else { if (overture) { /* run overture calculation */ sprintf(combuf, "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s", @@ -1192,19 +1216,32 @@ char *opts, *po; progname, vs); quit(1); } -#ifdef NIX +#ifndef NULL_DEVICE rmfile(overfile); #endif } sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s", - rep, vw, res, po, opts, zopt, - oct1name, rawfile); + rep, vw, res, po, opts, + zopt, oct1name, rawfile); + if (pfile != NULL && inchild()) { + /* rpict persistent mode */ + if (!silent) + printf("\t%s\n", combuf); + sprintf(combuf, "rpict%s %s %s%s%s %s > %s", + rep, rppopt, res, po, opts, + oct1name, rawfile); + fflush(stdout); + fp = popen(combuf, "w"); + if (fp == NULL) + goto rperror; + myprintview(vw, fp); + if (pclose(fp)) + goto rperror; + } else { /* rpict normal mode */ + if (runcom(combuf)) + goto rperror; + } } - if (runcom(combuf)) { /* run rpict */ - fprintf(stderr, "%s: error rendering view %s\n", - progname, vs); - quit(1); - } if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) { /* build pfilt command */ if (mult > 1) @@ -1213,7 +1250,7 @@ char *opts, *po; else sprintf(combuf, "pfilt%s %s > %s", pfopts, rawfile, picfile); - if (runcom(combuf)) { /* run pfilt */ + if (runcom(combuf)) { /* run pfilt */ fprintf(stderr, "%s: error filtering view %s\n\t%s removed\n", progname, vs, picfile); @@ -1227,7 +1264,23 @@ char *opts, *po; mvfile(rawfile, combuf); } else rmfile(rawfile); + finish_process(); /* exit if child */ } + wait_process(1); /* wait for children to finish */ + if (pfile != NULL) { /* clean up rpict persistent mode */ + int pid; + fp = fopen(pfile, "r"); + if (fp != NULL) { + if (fscanf(fp, "%*s %d", &pid) != 1 || + kill(pid, 1) < 0) + unlink(pfile); + fclose(fp); + } + } + return; +rperror: + fprintf(stderr, "%s: error rendering view %s\n", progname, vs); + quit(1); } @@ -1236,7 +1289,7 @@ char *fn; { if (!silent) printf("\ttouch %s\n", fn); - if (noaction) + if (!nprocs) return(0); #ifdef notused if (access(fn, F_OK) == -1) /* create it */ @@ -1252,7 +1305,7 @@ char *cs; { if (!silent) /* echo it */ printf("\t%s\n", cs); - if (noaction) + if (!nprocs) return(0); fflush(stdout); /* flush output and pass to shell */ return(system(cs)); @@ -1263,12 +1316,8 @@ rmfile(fn) /* remove a file */ char *fn; { if (!silent) -#ifdef MSDOS - printf("\tdel %s\n", fn); -#else - printf("\trm -f %s\n", fn); -#endif - if (noaction) + printf("\t%s %s\n", DELCMD, fn); + if (!nprocs) return(0); return(unlink(fn)); } @@ -1278,18 +1327,96 @@ mvfile(fold, fnew) /* move a file */ char *fold, *fnew; { if (!silent) -#ifdef MSDOS - printf("\trename %s %s\n", fold, fnew); -#else - printf("\tmv %s %s\n", fold, fnew); -#endif - if (noaction) + printf("\t%s %s %s\n", RENAMECMD, fold, fnew); + if (!nprocs) return(0); return(rename(fold, fnew)); } -#ifdef MSDOS +#ifdef RHAS_FORK_EXEC +int +next_process() /* fork the next process (max. nprocs) */ +{ + int child_pid; + + if (nprocs <= 1) + return(0); /* it's us or no one */ + if (inchild()) { + fprintf(stderr, "%s: internal error 1 in next_process()\n", + progname); + quit(1); + } + if (children_running >= nprocs) + wait_process(0); /* wait for someone to finish */ + fflush(stdout); + child_pid = fork(); /* split process */ + if (child_pid == 0) { /* we're the child */ + children_running = -1; + return(0); + } + if (child_pid > 0) { /* we're the parent */ + ++children_running; + return(1); + } + fprintf(stderr, "%s: warning -- fork() failed\n", progname); + return(0); +} + +wait_process(all) /* wait for process(es) to finish */ +int all; +{ + int ourstatus = 0; + int pid, status; + + if (all) + all = children_running; + else if (children_running > 0) + all = 1; + while (all-- > 0) { + pid = wait(&status); + if (pid < 0) + syserr(progname); + status = status>>8 & 0xff; + --children_running; + if (status != 0) { /* child's problem is our problem */ + if ((ourstatus == 0) & (children_running > 0)) + fprintf(stderr, "%s: waiting for remaining processes\n", + progname); + ourstatus = status; + all = children_running; + } + } + if (ourstatus != 0) + quit(ourstatus); /* bad status from child */ +} +#else /* ! RHAS_FORK_EXEC */ +int +next_process() +{ + return(0); /* cannot start new process */ +} +wait_process(all) +int all; +{ + (void)all; /* no one to wait for */ +} +int +kill(pid, sig) /* win|unix_process.c should also wait and kill */ +int pid, sig; +{ + return 0; +} +#endif /* ! RHAS_FORK_EXEC */ + +finish_process() /* exit a child process */ +{ + if (!inchild()) + return; /* in parent -- noop */ + exit(0); +} + +#ifdef _WIN32 setenv(vname, value) /* set an environment variable */ char *vname, *value; { @@ -1326,6 +1453,7 @@ char *s; } +void quit(ec) /* exit program */ int ec; {