--- ray/src/util/ranimate.c 1996/07/10 15:14:59 2.19 +++ ray/src/util/ranimate.c 1998/03/03 19:36:43 2.26 @@ -93,7 +93,7 @@ int silent = 0; /* silent mode? */ int noaction = 0; /* take no action? */ char *remsh; /* remote shell program/script */ -char rendopt[2048] = ""; /* rendering options */ +char rendopt[2048]; /* rendering options */ char rresopt[32]; /* rendering resolution options */ char fresopt[32]; /* filter resolution options */ int pfiltalways; /* always use pfilt? */ @@ -115,7 +115,7 @@ struct pslot *findpslot(); PSERVER *lastpserver; /* last process server with error */ VIEW *getview(); -char *getexp(); +char *getexp(), *dirfile(); extern time_t fdate(), time(); @@ -150,6 +150,8 @@ char *argv[]; cfname = argv[i]; /* load variables */ loadvars(cfname); + /* check variables */ + checkvalues(); /* did we get DIRECTORY? */ checkdir(); /* check status */ @@ -230,7 +232,7 @@ getastat() /* check/set animation status */ } /* assume it is dead */ } - if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */ + if (strcmp(cfname, astat.cfname) && astat.pid != 0) { /* other's */ fprintf(stderr, "%s: unfinished job \"%s\"\n", progname, astat.cfname); return(-1); @@ -448,28 +450,39 @@ char *rfargs; char combuf[256]; register int i; register char *cp; + char *pippt; /* create rad command */ sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY)); sprintf(combuf, "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", rfargs, rendopt+2); cp = combuf; - while (*cp) cp++; /* match unset variables */ + while (*cp) { + if (*cp == '|') pippt = cp; + cp++; + } /* match unset variables */ for (i = 0; mvar[i] >= 0; i++) if (!vdef(mvar[i])) { *cp++ = '|'; strcpy(cp, vnam(mvar[i])); while (*cp) cp++; + pippt = NULL; } - sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); - cp += 11; /* point to file name */ + if (pippt != NULL) + strcpy(pippt, "> /dev/null"); /* nothing to match */ + else { + sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); + cp += 11; /* point to file name */ + } if (system(combuf)) { fprintf(stderr, "%s: error executing rad command:\n\t%s\n", progname, combuf); quit(1); } - loadvars(cp); /* load variables and remove file */ - unlink(cp); + if (pippt == NULL) { /* load variables and remove file */ + loadvars(cp); + unlink(cp); + } } @@ -523,9 +536,7 @@ animate() /* run animation */ quit(1); } /* initialize archive argument list */ - i = 16; - if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i) - i = strlen(vval(ARCHIVE)); + i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132; arcnext = arcfirst = arcargs + i; /* initialize status file */ if (astat.rnext == 0) @@ -629,7 +640,7 @@ filterframes() /* catch up with filtering */ transferframes() /* catch up with picture transfers */ { - char combuf[10240]; + char combuf[10240], *fbase; register char *cp; register int i; @@ -640,12 +651,19 @@ transferframes() /* catch up with picture transfers putastat(); /* update status */ return; } - strcpy(combuf, vval(TRANSFER)); /* start transfer command */ - cp = combuf + strlen(combuf); + strcpy(combuf, "cd "); /* start transfer command */ + fbase = dirfile(cp = combuf+3, vval(BASENAME)); + if (*cp) { + while (*++cp) ; + *cp++ = ';'; *cp++ = ' '; + } else + cp = combuf; + strcpy(cp, vval(TRANSFER)); + while (*cp) cp++; /* make argument list */ for (i = astat.tnext; i < astat.fnext; i++) { *cp++ = ' '; - sprintf(cp, vval(BASENAME), i); + sprintf(cp, fbase, i); while (*cp) cp++; strcpy(cp, ".pic"); cp += 4; @@ -694,7 +712,8 @@ char *vfn; close(open(combuf, O_RDONLY|O_CREAT, 0666)); } /* create command */ - sprintf(combuf, "rpict%s -w0", rendopt); + sprintf(combuf, "rpict%s%s -w0", rendopt, + viewopt(getview(first>1 ? first-1 : 1))); if (vint(INTERP) || atoi(vval(MBLUR))) sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME)); sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d", @@ -786,22 +805,40 @@ archive() /* archive and remove renderings */ { #define RMCOML (sizeof(rmcom)-1) static char rmcom[] = "rm -f"; - register int i; + char basedir[128]; + int dlen, alen; + register int j; if (arcnext == arcfirst) return; /* nothing to do */ + dirfile(basedir, vval(BASENAME)); + dlen = strlen(basedir); if (vdef(ARCHIVE)) { /* run archive command */ - i = strlen(vval(ARCHIVE)); - strncpy(arcfirst-i, vval(ARCHIVE), i); - if (runcom(arcfirst-i)) { + alen = strlen(vval(ARCHIVE)); + if (dlen) { + j = alen + dlen + 5; + strncpy(arcfirst-j, "cd ", 3); + strncpy(arcfirst-j+3, basedir, dlen); + (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; + } else + j = alen; + strncpy(arcfirst-alen, vval(ARCHIVE), alen); + if (runcom(arcfirst-j)) { fprintf(stderr, "%s: error running archive command\n", progname); quit(1); } } + if (dlen) { + j = RMCOML + dlen + 5; + strncpy(arcfirst-j, "cd ", 3); + strncpy(arcfirst-j+3, basedir, dlen); + (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; + } else + j = RMCOML; /* run remove command */ strncpy(arcfirst-RMCOML, rmcom, RMCOML); - runcom(arcfirst-RMCOML); + runcom(arcfirst-j); arcnext = arcfirst; /* reset argument list */ #undef RMCOML } @@ -816,7 +853,7 @@ int rvr; { extern int frecover(); static int iter = 0; - char fnbefore[128], fnafter[128]; + char fnbefore[128], fnafter[128], *fbase; char combuf[1024], fname0[128], fname1[128]; int usepinterp, usepfilt, nora_rgbe; int frseq[2]; @@ -830,6 +867,7 @@ int rvr; /* compute rendered views */ frseq[0] = frame - ((frame-1) % (vint(INTERP)+1)); frseq[1] = frseq[0] + vint(INTERP) + 1; + fbase = dirfile(NULL, vval(BASENAME)); if (frseq[1] > vint(END)) frseq[1] = vint(END); if (frseq[1] == frame) { /* pfilt only */ @@ -839,14 +877,13 @@ int rvr; } else if (frseq[0] == frame) { /* no interpolation needed */ if (!rvr && frame > 1+vint(INTERP)) { /* archive previous */ *arcnext++ = ' '; - sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1); + sprintf(arcnext, fbase, frame-vint(INTERP)-1); while (*arcnext) arcnext++; strcpy(arcnext, ".unf"); arcnext += 4; if (usepinterp || vint(INTERP)) { /* and Z-buf */ *arcnext++ = ' '; - sprintf(arcnext, vval(BASENAME), - frame-vint(INTERP)-1); + sprintf(arcnext, fbase, frame-vint(INTERP)-1); while (*arcnext) arcnext++; strcpy(arcnext, ".zbf"); arcnext += 4; @@ -867,29 +904,31 @@ int rvr; if (rvr == 2 && recover(frseq[1])) /* recover after? */ return(1); if (atoi(vval(MBLUR))) { - FILE *fp; /* motion blurring */ sprintf(fname0, "%s/vw0%c", vval(DIRECTORY), 'a'+(iter%26)); - if ((fp = fopen(fname0, "w")) == NULL) { - perror(fname0); quit(1); - } - fputs(VIEWSTR, fp); - fprintview(vp, fp); - putc('\n', fp); fclose(fp); - if ((vp = getview(frame+1)) == NULL) { - fprintf(stderr, - "%s: unexpected error reading view for frame %d\n", - progname, frame+1); - quit(1); - } sprintf(fname1, "%s/vw1%c", vval(DIRECTORY), 'a'+(iter%26)); - if ((fp = fopen(fname1, "w")) == NULL) { - perror(fname1); quit(1); + if (!noaction) { + FILE *fp; /* motion blurring */ + if ((fp = fopen(fname0, "w")) == NULL) { + perror(fname0); quit(1); + } + fputs(VIEWSTR, fp); + fprintview(vp, fp); + putc('\n', fp); fclose(fp); + if ((vp = getview(frame+1)) == NULL) { + fprintf(stderr, + "%s: unexpected error reading view for frame %d\n", + progname, frame+1); + quit(1); + } + if ((fp = fopen(fname1, "w")) == NULL) { + perror(fname1); quit(1); + } + fputs(VIEWSTR, fp); + fprintview(vp, fp); + putc('\n', fp); fclose(fp); } - fputs(VIEWSTR, fp); - fprintview(vp, fp); - putc('\n', fp); fclose(fp); sprintf(combuf, "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B", *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1", @@ -901,7 +940,7 @@ int rvr; strcat(combuf, viewopt(vp)); if (vbool(RTRACE)) sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'", - rendopt, vval(OCTREE)); + rendopt+1, vval(OCTREE)); if (vdef(PINTERP)) sprintf(combuf+strlen(combuf), " %s", vval(PINTERP)); if (usepfilt) @@ -972,12 +1011,12 @@ int n; } return(NULL); } - if (viewfp == NULL) { /* open file */ + if (viewfp == NULL) { /* open file */ if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) { perror(vval(VIEWFILE)); quit(1); } - } else if (n < viewnum) { /* rewind file */ + } else if (n > 0 && n < viewnum) { /* rewind file */ if (viewnum == 1 && feof(viewfp)) return(&curview); /* just one view */ if (fseek(viewfp, 0L, 0) == EOF) { @@ -987,6 +1026,13 @@ int n; copystruct(&curview, &stdview); viewnum = 0; } + if (n < 0) { /* get next view */ + register int c = getc(viewfp); + if (c == EOF) + return((VIEW *)NULL); /* that's it */ + ungetc(c, viewfp); + n = viewnum + 1; + } while (n > viewnum) { /* scan to desired view */ if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) return(viewnum==1 ? &curview : (VIEW *)NULL); @@ -1000,9 +1046,11 @@ int n; int countviews() /* count views in view file */ { - register int n = 0; + int n; - while (getview(n+1) != NULL) + if (getview(n=1) == NULL) + return(0); + while (getview(-1) != NULL) n++; return(n); } @@ -1304,4 +1352,28 @@ int vc; fprintf(stderr, "%s: bad value for variable '%s'\n", progname, vnam(vc)); quit(1); +} + + +char * +dirfile(df, path) /* separate path into directory and file */ +char *df; +register char *path; +{ + register int i; + int psep; + + for (i = 0, psep = -1; path[i]; i++) + if (path[i] == '/') + psep = i; + if (df != NULL) + if (psep == 0) { + df[0] = '/'; + df[1] = '\0'; + } else if (psep > 0) { + strncpy(df, path, psep); + df[psep] = '\0'; + } else + df[0] = '\0'; + return(path+psep+1); }