| 1 | 
< | 
/* Copyright (c) 1995 Regents of the University of California */ | 
| 1 | 
> | 
/* Copyright (c) 1996 Regents of the University of California */ | 
| 2 | 
  | 
 | 
| 3 | 
  | 
#ifndef lint | 
| 4 | 
  | 
static char SCCSid[] = "$SunId$ LBL"; | 
| 93 | 
  | 
int     noaction = 0;           /* take no action? */ | 
| 94 | 
  | 
 | 
| 95 | 
  | 
char    *remsh;                 /* remote shell program/script */ | 
| 96 | 
< | 
char    rendopt[2048] = "";     /* rendering options */ | 
| 96 | 
> | 
char    rendopt[2048];          /* rendering options */ | 
| 97 | 
  | 
char    rresopt[32];            /* rendering resolution options */ | 
| 98 | 
  | 
char    fresopt[32];            /* filter resolution options */ | 
| 99 | 
  | 
int     pfiltalways;            /* always use pfilt? */ | 
| 108 | 
  | 
}       *pslot;                 /* process slots */ | 
| 109 | 
  | 
int     npslots;                /* number of process slots */ | 
| 110 | 
  | 
 | 
| 111 | 
– | 
int     lastpid;                /* ID of last completed background process */ | 
| 112 | 
– | 
PSERVER *lastpserver;           /* last process server used */ | 
| 113 | 
– | 
 | 
| 111 | 
  | 
#define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host) | 
| 112 | 
  | 
 | 
| 113 | 
  | 
struct pslot    *findpslot(); | 
| 114 | 
  | 
 | 
| 115 | 
+ | 
PSERVER *lastpserver;           /* last process server with error */ | 
| 116 | 
+ | 
 | 
| 117 | 
  | 
VIEW    *getview(); | 
| 118 | 
< | 
char    *getexp(); | 
| 118 | 
> | 
char    *getexp(), *dirfile(); | 
| 119 | 
  | 
 | 
| 120 | 
+ | 
extern time_t   fdate(), time(); | 
| 121 | 
  | 
 | 
| 122 | 
+ | 
 | 
| 123 | 
  | 
main(argc, argv) | 
| 124 | 
  | 
int     argc; | 
| 125 | 
  | 
char    *argv[]; | 
| 150 | 
  | 
        cfname = argv[i]; | 
| 151 | 
  | 
                                                /* load variables */ | 
| 152 | 
  | 
        loadvars(cfname); | 
| 153 | 
+ | 
                                                /* check variables */ | 
| 154 | 
+ | 
        checkvalues(); | 
| 155 | 
  | 
                                                /* did we get DIRECTORY? */ | 
| 156 | 
  | 
        checkdir(); | 
| 157 | 
  | 
                                                /* check status */ | 
| 178 | 
  | 
                argv[i] = vval(NEXTANIM);       /* just change input file */ | 
| 179 | 
  | 
                if (!silent) | 
| 180 | 
  | 
                        printargs(argc, argv, stdout); | 
| 181 | 
< | 
                execvp(progname, argv);         /* pass to next */ | 
| 182 | 
< | 
                quit(1);                        /* shouldn't return */ | 
| 181 | 
> | 
                if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL) | 
| 182 | 
> | 
                        fprintf(stderr, "%s: command not found\n", progname); | 
| 183 | 
> | 
                else | 
| 184 | 
> | 
                        execv(progname, argv); | 
| 185 | 
> | 
                quit(1); | 
| 186 | 
  | 
        } | 
| 187 | 
  | 
        quit(0); | 
| 188 | 
  | 
userr: | 
| 193 | 
  | 
 | 
| 194 | 
  | 
getastat()                      /* check/set animation status */ | 
| 195 | 
  | 
{ | 
| 196 | 
< | 
        char    buf[256]; | 
| 196 | 
> | 
        char    sfname[256]; | 
| 197 | 
  | 
        FILE    *fp; | 
| 198 | 
  | 
 | 
| 199 | 
< | 
        sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME); | 
| 200 | 
< | 
        if ((fp = fopen(buf, "r")) == NULL) { | 
| 199 | 
> | 
        sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME); | 
| 200 | 
> | 
        if ((fp = fopen(sfname, "r")) == NULL) { | 
| 201 | 
  | 
                if (errno != ENOENT) { | 
| 202 | 
< | 
                        perror(buf); | 
| 202 | 
> | 
                        perror(sfname); | 
| 203 | 
  | 
                        return(-1); | 
| 204 | 
  | 
                } | 
| 205 | 
  | 
                astat.rnext = astat.fnext = astat.tnext = 0; | 
| 232 | 
  | 
                } | 
| 233 | 
  | 
                /* assume it is dead */ | 
| 234 | 
  | 
        } | 
| 235 | 
< | 
        if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */ | 
| 235 | 
> | 
        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */ | 
| 236 | 
  | 
                fprintf(stderr, "%s: unfinished job \"%s\"\n", | 
| 237 | 
  | 
                                progname, astat.cfname); | 
| 238 | 
  | 
                return(-1); | 
| 239 | 
  | 
        } | 
| 240 | 
+ | 
                                                /* check control file mods. */ | 
| 241 | 
+ | 
        if (!nowarn && fdate(cfname) > fdate(sfname)) | 
| 242 | 
+ | 
                fprintf(stderr, | 
| 243 | 
+ | 
                        "%s: warning - control file modified since last run\n", | 
| 244 | 
+ | 
                                progname); | 
| 245 | 
  | 
setours:                                        /* set our values */ | 
| 246 | 
  | 
        strcpy(astat.host, myhostname()); | 
| 247 | 
  | 
        astat.pid = getpid(); | 
| 249 | 
  | 
        return(0); | 
| 250 | 
  | 
fmterr: | 
| 251 | 
  | 
        fprintf(stderr, "%s: format error in status file \"%s\"\n", | 
| 252 | 
< | 
                        progname, buf); | 
| 252 | 
> | 
                        progname, sfname); | 
| 253 | 
  | 
        fclose(fp); | 
| 254 | 
  | 
        return(-1); | 
| 255 | 
  | 
} | 
| 302 | 
  | 
setdefaults()                   /* set default values */ | 
| 303 | 
  | 
{ | 
| 304 | 
  | 
        extern char     *atos(); | 
| 305 | 
+ | 
        int     decades; | 
| 306 | 
  | 
        char    buf[256]; | 
| 307 | 
  | 
 | 
| 308 | 
  | 
        if (vdef(ANIMATE)) { | 
| 336 | 
  | 
                quit(1); | 
| 337 | 
  | 
        } | 
| 338 | 
  | 
        if (!vdef(BASENAME)) { | 
| 339 | 
< | 
                sprintf(buf, "%s/frame%%03d", vval(DIRECTORY)); | 
| 339 | 
> | 
                decades = (int)log10((double)vint(END)) + 1; | 
| 340 | 
> | 
                if (decades < 3) decades = 3; | 
| 341 | 
> | 
                sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades); | 
| 342 | 
  | 
                vval(BASENAME) = savqstr(buf); | 
| 343 | 
  | 
                vdef(BASENAME)++; | 
| 344 | 
  | 
        } | 
| 450 | 
  | 
        char    combuf[256]; | 
| 451 | 
  | 
        register int    i; | 
| 452 | 
  | 
        register char   *cp; | 
| 453 | 
+ | 
        char    *pippt; | 
| 454 | 
  | 
                                        /* create rad command */ | 
| 455 | 
  | 
        sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY)); | 
| 456 | 
  | 
        sprintf(combuf, | 
| 457 | 
  | 
        "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", | 
| 458 | 
  | 
                        rfargs, rendopt+2); | 
| 459 | 
  | 
        cp = combuf; | 
| 460 | 
< | 
        while (*cp) cp++;               /* match unset variables */ | 
| 460 | 
> | 
        while (*cp) { | 
| 461 | 
> | 
                if (*cp == '|') pippt = cp; | 
| 462 | 
> | 
                cp++; | 
| 463 | 
> | 
        }                               /* match unset variables */ | 
| 464 | 
  | 
        for (i = 0; mvar[i] >= 0; i++) | 
| 465 | 
  | 
                if (!vdef(mvar[i])) { | 
| 466 | 
  | 
                        *cp++ = '|'; | 
| 467 | 
  | 
                        strcpy(cp, vnam(mvar[i])); | 
| 468 | 
  | 
                        while (*cp) cp++; | 
| 469 | 
+ | 
                        pippt = NULL; | 
| 470 | 
  | 
                } | 
| 471 | 
< | 
        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); | 
| 472 | 
< | 
        cp += 11;                       /* point to file name */ | 
| 471 | 
> | 
        if (pippt != NULL) | 
| 472 | 
> | 
                strcpy(pippt, "> /dev/null");   /* nothing to match */ | 
| 473 | 
> | 
        else { | 
| 474 | 
> | 
                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); | 
| 475 | 
> | 
                cp += 11;               /* point to file name */ | 
| 476 | 
> | 
        } | 
| 477 | 
  | 
        if (system(combuf)) { | 
| 478 | 
  | 
                fprintf(stderr, "%s: error executing rad command:\n\t%s\n", | 
| 479 | 
  | 
                                progname, combuf); | 
| 480 | 
  | 
                quit(1); | 
| 481 | 
  | 
        } | 
| 482 | 
< | 
        loadvars(cp);                   /* load variables and remove file */ | 
| 483 | 
< | 
        unlink(cp); | 
| 482 | 
> | 
        if (pippt == NULL) {            /* load variables and remove file */ | 
| 483 | 
> | 
                loadvars(cp); | 
| 484 | 
> | 
                unlink(cp); | 
| 485 | 
> | 
        } | 
| 486 | 
  | 
} | 
| 487 | 
  | 
 | 
| 488 | 
  | 
 | 
| 497 | 
  | 
        i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa); | 
| 498 | 
  | 
        mult = vflt(OVERSAMP); | 
| 499 | 
  | 
        if (i == 3) { | 
| 500 | 
< | 
                sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres), | 
| 500 | 
> | 
                sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres), | 
| 501 | 
  | 
                                (int)(mult*yres), pa); | 
| 502 | 
< | 
                sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa); | 
| 502 | 
> | 
                sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa); | 
| 503 | 
  | 
        } else if (i) { | 
| 504 | 
  | 
                if (i == 1) yres = xres; | 
| 505 | 
  | 
                sprintf(rresopt, "-x %d -y %d", (int)(mult*xres), | 
| 527 | 
  | 
                                        /* figure # frames per batch */ | 
| 528 | 
  | 
        d1 = mult*xres*mult*yres*4;             /* space for orig. picture */ | 
| 529 | 
  | 
        if ((i=vint(INTERP)) || atoi(vval(MBLUR))) | 
| 530 | 
< | 
                d1 += mult*xres*mult*yres*4;    /* space for z-buffer */ | 
| 530 | 
> | 
                d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */ | 
| 531 | 
  | 
        d2 = xres*yres*4;                       /* space for final picture */ | 
| 532 | 
  | 
        frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2); | 
| 533 | 
  | 
        if (frames_batch < i+2) { | 
| 536 | 
  | 
                quit(1); | 
| 537 | 
  | 
        } | 
| 538 | 
  | 
                                        /* initialize archive argument list */ | 
| 539 | 
< | 
        i = 16; | 
| 515 | 
< | 
        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i) | 
| 516 | 
< | 
                i = strlen(vval(ARCHIVE)); | 
| 539 | 
> | 
        i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132; | 
| 540 | 
  | 
        arcnext = arcfirst = arcargs + i; | 
| 541 | 
  | 
                                        /* initialize status file */ | 
| 542 | 
  | 
        if (astat.rnext == 0) | 
| 640 | 
  | 
 | 
| 641 | 
  | 
transferframes()                        /* catch up with picture transfers */ | 
| 642 | 
  | 
{ | 
| 643 | 
< | 
        char    combuf[10240]; | 
| 643 | 
> | 
        char    combuf[10240], *fbase; | 
| 644 | 
  | 
        register char   *cp; | 
| 645 | 
  | 
        register int    i; | 
| 646 | 
  | 
 | 
| 651 | 
  | 
                putastat();             /* update status */ | 
| 652 | 
  | 
                return; | 
| 653 | 
  | 
        } | 
| 654 | 
< | 
        strcpy(combuf, vval(TRANSFER)); /* start transfer command */ | 
| 655 | 
< | 
        cp = combuf + strlen(combuf); | 
| 654 | 
> | 
        strcpy(combuf, "cd ");          /* start transfer command */ | 
| 655 | 
> | 
        fbase = dirfile(cp = combuf+3, vval(BASENAME)); | 
| 656 | 
> | 
        if (*cp) { | 
| 657 | 
> | 
                while (*++cp) ; | 
| 658 | 
> | 
                *cp++ = ';'; *cp++ = ' '; | 
| 659 | 
> | 
        } else | 
| 660 | 
> | 
                cp = combuf; | 
| 661 | 
> | 
        strcpy(cp, vval(TRANSFER)); | 
| 662 | 
> | 
        while (*cp) cp++; | 
| 663 | 
  | 
                                        /* make argument list */ | 
| 664 | 
  | 
        for (i = astat.tnext; i < astat.fnext; i++) { | 
| 665 | 
  | 
                *cp++ = ' '; | 
| 666 | 
< | 
                sprintf(cp, vval(BASENAME), i); | 
| 666 | 
> | 
                sprintf(cp, fbase, i); | 
| 667 | 
  | 
                while (*cp) cp++; | 
| 668 | 
  | 
                strcpy(cp, ".pic"); | 
| 669 | 
  | 
                cp += 4; | 
| 712 | 
  | 
                                close(open(combuf, O_RDONLY|O_CREAT, 0666)); | 
| 713 | 
  | 
                        } | 
| 714 | 
  | 
                                        /* create command */ | 
| 715 | 
< | 
        sprintf(combuf, "rpict%s -w0", rendopt); | 
| 715 | 
> | 
        sprintf(combuf, "rpict%s%s -w0", rendopt, | 
| 716 | 
> | 
                        viewopt(getview(first>1 ? first-1 : 1))); | 
| 717 | 
  | 
        if (vint(INTERP) || atoi(vval(MBLUR))) | 
| 718 | 
  | 
                sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME)); | 
| 719 | 
  | 
        sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d", | 
| 805 | 
  | 
{ | 
| 806 | 
  | 
#define RMCOML  (sizeof(rmcom)-1) | 
| 807 | 
  | 
        static char     rmcom[] = "rm -f"; | 
| 808 | 
< | 
        register int    i; | 
| 808 | 
> | 
        char    basedir[128]; | 
| 809 | 
> | 
        int     dlen, alen; | 
| 810 | 
> | 
        register int    j; | 
| 811 | 
  | 
 | 
| 812 | 
  | 
        if (arcnext == arcfirst) | 
| 813 | 
  | 
                return;                         /* nothing to do */ | 
| 814 | 
+ | 
        dirfile(basedir, vval(BASENAME)); | 
| 815 | 
+ | 
        dlen = strlen(basedir); | 
| 816 | 
  | 
        if (vdef(ARCHIVE)) {                    /* run archive command */ | 
| 817 | 
< | 
                i = strlen(vval(ARCHIVE)); | 
| 818 | 
< | 
                strncpy(arcfirst-i, vval(ARCHIVE), i); | 
| 819 | 
< | 
                if (runcom(arcfirst-i)) { | 
| 817 | 
> | 
                alen = strlen(vval(ARCHIVE)); | 
| 818 | 
> | 
                if (dlen) { | 
| 819 | 
> | 
                        j = alen + dlen + 5; | 
| 820 | 
> | 
                        strncpy(arcfirst-j, "cd ", 3); | 
| 821 | 
> | 
                        strncpy(arcfirst-j+3, basedir, dlen); | 
| 822 | 
> | 
                        (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; | 
| 823 | 
> | 
                } else | 
| 824 | 
> | 
                        j = alen; | 
| 825 | 
> | 
                strncpy(arcfirst-alen, vval(ARCHIVE), alen); | 
| 826 | 
> | 
                if (runcom(arcfirst-j)) { | 
| 827 | 
  | 
                        fprintf(stderr, "%s: error running archive command\n", | 
| 828 | 
  | 
                                        progname); | 
| 829 | 
  | 
                        quit(1); | 
| 830 | 
  | 
                } | 
| 831 | 
  | 
        } | 
| 832 | 
+ | 
        if (dlen) { | 
| 833 | 
+ | 
                j = RMCOML + dlen + 5; | 
| 834 | 
+ | 
                strncpy(arcfirst-j, "cd ", 3); | 
| 835 | 
+ | 
                strncpy(arcfirst-j+3, basedir, dlen); | 
| 836 | 
+ | 
                (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; | 
| 837 | 
+ | 
        } else | 
| 838 | 
+ | 
                j = RMCOML; | 
| 839 | 
  | 
                                                /* run remove command */ | 
| 840 | 
  | 
        strncpy(arcfirst-RMCOML, rmcom, RMCOML); | 
| 841 | 
< | 
        runcom(arcfirst-RMCOML); | 
| 841 | 
> | 
        runcom(arcfirst-j); | 
| 842 | 
  | 
        arcnext = arcfirst;                     /* reset argument list */ | 
| 843 | 
  | 
#undef RMCOML | 
| 844 | 
  | 
} | 
| 853 | 
  | 
{ | 
| 854 | 
  | 
        extern int      frecover(); | 
| 855 | 
  | 
        static int      iter = 0; | 
| 856 | 
< | 
        char    fnbefore[128], fnafter[128]; | 
| 856 | 
> | 
        char    fnbefore[128], fnafter[128], *fbase; | 
| 857 | 
  | 
        char    combuf[1024], fname0[128], fname1[128]; | 
| 858 | 
  | 
        int     usepinterp, usepfilt, nora_rgbe; | 
| 859 | 
  | 
        int     frseq[2]; | 
| 867 | 
  | 
                                                /* compute rendered views */ | 
| 868 | 
  | 
        frseq[0] = frame - ((frame-1) % (vint(INTERP)+1)); | 
| 869 | 
  | 
        frseq[1] = frseq[0] + vint(INTERP) + 1; | 
| 870 | 
+ | 
        fbase = dirfile(NULL, vval(BASENAME)); | 
| 871 | 
  | 
        if (frseq[1] > vint(END)) | 
| 872 | 
  | 
                frseq[1] = vint(END); | 
| 873 | 
  | 
        if (frseq[1] == frame) {                        /* pfilt only */ | 
| 877 | 
  | 
        } else if (frseq[0] == frame) {         /* no interpolation needed */ | 
| 878 | 
  | 
                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */ | 
| 879 | 
  | 
                        *arcnext++ = ' '; | 
| 880 | 
< | 
                        sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1); | 
| 880 | 
> | 
                        sprintf(arcnext, fbase, frame-vint(INTERP)-1); | 
| 881 | 
  | 
                        while (*arcnext) arcnext++; | 
| 882 | 
  | 
                        strcpy(arcnext, ".unf"); | 
| 883 | 
  | 
                        arcnext += 4; | 
| 884 | 
< | 
                        if (usepinterp || vint(INTERP)) {       /* and z-buf */ | 
| 884 | 
> | 
                        if (usepinterp || vint(INTERP)) {       /* and Z-buf */ | 
| 885 | 
  | 
                                *arcnext++ = ' '; | 
| 886 | 
< | 
                                sprintf(arcnext, vval(BASENAME), | 
| 837 | 
< | 
                                                frame-vint(INTERP)-1); | 
| 886 | 
> | 
                                sprintf(arcnext, fbase, frame-vint(INTERP)-1); | 
| 887 | 
  | 
                                while (*arcnext) arcnext++; | 
| 888 | 
  | 
                                strcpy(arcnext, ".zbf"); | 
| 889 | 
  | 
                                arcnext += 4; | 
| 904 | 
  | 
                if (rvr == 2 && recover(frseq[1]))      /* recover after? */ | 
| 905 | 
  | 
                        return(1); | 
| 906 | 
  | 
                if (atoi(vval(MBLUR))) { | 
| 858 | 
– | 
                        FILE    *fp;            /* motion blurring */ | 
| 907 | 
  | 
                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY), | 
| 908 | 
  | 
                                        'a'+(iter%26)); | 
| 861 | 
– | 
                        if ((fp = fopen(fname0, "w")) == NULL) { | 
| 862 | 
– | 
                                perror(fname0); quit(1); | 
| 863 | 
– | 
                        } | 
| 864 | 
– | 
                        fputs(VIEWSTR, fp); | 
| 865 | 
– | 
                        fprintview(vp, fp); | 
| 866 | 
– | 
                        putc('\n', fp); fclose(fp); | 
| 867 | 
– | 
                        if ((vp = getview(frame+1)) == NULL) { | 
| 868 | 
– | 
                                fprintf(stderr, | 
| 869 | 
– | 
                        "%s: unexpected error reading view for frame %d\n", | 
| 870 | 
– | 
                                                progname, frame+1); | 
| 871 | 
– | 
                                quit(1); | 
| 872 | 
– | 
                        } | 
| 909 | 
  | 
                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY), | 
| 910 | 
  | 
                                        'a'+(iter%26)); | 
| 911 | 
< | 
                        if ((fp = fopen(fname1, "w")) == NULL) { | 
| 912 | 
< | 
                                perror(fname1); quit(1); | 
| 911 | 
> | 
                        if (!noaction) { | 
| 912 | 
> | 
                                FILE    *fp;            /* motion blurring */ | 
| 913 | 
> | 
                                if ((fp = fopen(fname0, "w")) == NULL) { | 
| 914 | 
> | 
                                        perror(fname0); quit(1); | 
| 915 | 
> | 
                                } | 
| 916 | 
> | 
                                fputs(VIEWSTR, fp); | 
| 917 | 
> | 
                                fprintview(vp, fp); | 
| 918 | 
> | 
                                putc('\n', fp); fclose(fp); | 
| 919 | 
> | 
                                if ((vp = getview(frame+1)) == NULL) { | 
| 920 | 
> | 
                                        fprintf(stderr, | 
| 921 | 
> | 
                        "%s: unexpected error reading view for frame %d\n", | 
| 922 | 
> | 
                                                        progname, frame+1); | 
| 923 | 
> | 
                                        quit(1); | 
| 924 | 
> | 
                                } | 
| 925 | 
> | 
                                if ((fp = fopen(fname1, "w")) == NULL) { | 
| 926 | 
> | 
                                        perror(fname1); quit(1); | 
| 927 | 
> | 
                                } | 
| 928 | 
> | 
                                fputs(VIEWSTR, fp); | 
| 929 | 
> | 
                                fprintview(vp, fp); | 
| 930 | 
> | 
                                putc('\n', fp); fclose(fp); | 
| 931 | 
  | 
                        } | 
| 878 | 
– | 
                        fputs(VIEWSTR, fp); | 
| 879 | 
– | 
                        fprintview(vp, fp); | 
| 880 | 
– | 
                        putc('\n', fp); fclose(fp); | 
| 932 | 
  | 
                        sprintf(combuf, | 
| 933 | 
  | 
                        "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B", | 
| 934 | 
  | 
                        *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1", | 
| 940 | 
  | 
                strcat(combuf, viewopt(vp)); | 
| 941 | 
  | 
                if (vbool(RTRACE)) | 
| 942 | 
  | 
                        sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'", | 
| 943 | 
< | 
                                        rendopt, vval(OCTREE)); | 
| 943 | 
> | 
                                        rendopt+1, vval(OCTREE)); | 
| 944 | 
  | 
                if (vdef(PINTERP)) | 
| 945 | 
  | 
                        sprintf(combuf+strlen(combuf), " %s", vval(PINTERP)); | 
| 946 | 
  | 
                if (usepfilt) | 
| 1011 | 
  | 
                } | 
| 1012 | 
  | 
                return(NULL); | 
| 1013 | 
  | 
        } | 
| 1014 | 
< | 
        if (viewfp == NULL) {           /* open file */ | 
| 1014 | 
> | 
        if (viewfp == NULL) {                   /* open file */ | 
| 1015 | 
  | 
                if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) { | 
| 1016 | 
  | 
                        perror(vval(VIEWFILE)); | 
| 1017 | 
  | 
                        quit(1); | 
| 1018 | 
  | 
                } | 
| 1019 | 
< | 
        } else if (n < viewnum) {       /* rewind file */ | 
| 1019 | 
> | 
        } else if (n > 0 && n < viewnum) {      /* rewind file */ | 
| 1020 | 
  | 
                if (viewnum == 1 && feof(viewfp)) | 
| 1021 | 
  | 
                        return(&curview);               /* just one view */ | 
| 1022 | 
  | 
                if (fseek(viewfp, 0L, 0) == EOF) { | 
| 1026 | 
  | 
                copystruct(&curview, &stdview); | 
| 1027 | 
  | 
                viewnum = 0; | 
| 1028 | 
  | 
        } | 
| 1029 | 
+ | 
        if (n < 0) {                            /* get next view */ | 
| 1030 | 
+ | 
                register int    c = getc(viewfp); | 
| 1031 | 
+ | 
                if (c == EOF) | 
| 1032 | 
+ | 
                        return((VIEW *)NULL);           /* that's it */ | 
| 1033 | 
+ | 
                ungetc(c, viewfp); | 
| 1034 | 
+ | 
                n = viewnum + 1; | 
| 1035 | 
+ | 
        } | 
| 1036 | 
  | 
        while (n > viewnum) {           /* scan to desired view */ | 
| 1037 | 
  | 
                if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) | 
| 1038 | 
< | 
                        return(viewnum==1 ? &curview : NULL); | 
| 1038 | 
> | 
                        return(viewnum==1 ? &curview : (VIEW *)NULL); | 
| 1039 | 
  | 
                if (isview(linebuf) && sscanview(&curview, linebuf) > 0) | 
| 1040 | 
  | 
                        viewnum++; | 
| 1041 | 
  | 
        } | 
| 1046 | 
  | 
int | 
| 1047 | 
  | 
countviews()                    /* count views in view file */ | 
| 1048 | 
  | 
{ | 
| 1049 | 
< | 
        register int    n = 0; | 
| 1049 | 
> | 
        int     n; | 
| 1050 | 
  | 
 | 
| 1051 | 
< | 
        while (getview(n+1) != NULL) | 
| 1051 | 
> | 
        if (getview(n=1) == NULL) | 
| 1052 | 
> | 
                return(0); | 
| 1053 | 
> | 
        while (getview(-1) != NULL) | 
| 1054 | 
  | 
                n++; | 
| 1055 | 
  | 
        return(n); | 
| 1056 | 
  | 
} | 
| 1070 | 
  | 
        if (n == 0) {                           /* signal to close file */ | 
| 1071 | 
  | 
                if (expfp != NULL) { | 
| 1072 | 
  | 
                        fclose(expfp); | 
| 1073 | 
+ | 
                        free((char *)exppos); | 
| 1074 | 
  | 
                        expfp = NULL; | 
| 1075 | 
  | 
                } | 
| 1076 | 
  | 
                return(NULL); | 
| 1077 | 
< | 
        } | 
| 1077 | 
> | 
        } else if (n > vint(END))               /* request past end (error?) */ | 
| 1078 | 
> | 
                return(NULL); | 
| 1079 | 
  | 
        if (!vdef(EXPOSURE))                    /* no setting (auto) */ | 
| 1080 | 
  | 
                return(NULL); | 
| 1081 | 
  | 
        if (isflt(vval(EXPOSURE)))              /* always the same */ | 
| 1113 | 
  | 
                } | 
| 1114 | 
  | 
                curfrm++; | 
| 1115 | 
  | 
                cp = fskip(expval);                     /* check format */ | 
| 1116 | 
< | 
                if (cp == NULL || *cp != '\n') { | 
| 1116 | 
> | 
                if (cp != NULL) | 
| 1117 | 
> | 
                        while (isspace(*cp)) | 
| 1118 | 
> | 
                                *cp++ = '\0'; | 
| 1119 | 
> | 
                if (cp == NULL || *cp) { | 
| 1120 | 
  | 
                        fprintf(stderr, | 
| 1121 | 
  | 
                                "%s: exposure format error on line %d\n", | 
| 1122 | 
  | 
                                        vval(EXPOSURE), curfrm); | 
| 1123 | 
  | 
                        quit(1); | 
| 1124 | 
  | 
                } | 
| 1060 | 
– | 
                *cp = '\0'; | 
| 1125 | 
  | 
        } | 
| 1126 | 
  | 
        return(expval);                         /* return value */ | 
| 1127 | 
  | 
} | 
| 1151 | 
  | 
int     status; | 
| 1152 | 
  | 
{ | 
| 1153 | 
  | 
        register PROC   *pp; | 
| 1154 | 
+ | 
        register struct pslot   *psl; | 
| 1155 | 
  | 
 | 
| 1156 | 
  | 
        pp = ps->proc + pn; | 
| 1157 | 
  | 
        if (pp->elen) {                 /* pass errors */ | 
| 1163 | 
  | 
                if (ps->hostname[0]) | 
| 1164 | 
  | 
                        status = 1;     /* because rsh doesn't return status */ | 
| 1165 | 
  | 
        } | 
| 1166 | 
+ | 
        lastpserver = NULL; | 
| 1167 | 
+ | 
        psl = findpslot(pp->pid);       /* check for bruncom() slot */ | 
| 1168 | 
+ | 
        if (psl->pid) { | 
| 1169 | 
+ | 
                if (status) { | 
| 1170 | 
+ | 
                        if (psl->rcvf != NULL)  /* attempt recovery */ | 
| 1171 | 
+ | 
                                status = (*psl->rcvf)(psl->fout); | 
| 1172 | 
+ | 
                        if (status) { | 
| 1173 | 
+ | 
                                fprintf(stderr, | 
| 1174 | 
+ | 
                                        "%s: error rendering frame %d\n", | 
| 1175 | 
+ | 
                                                progname, psl->fout); | 
| 1176 | 
+ | 
                                quit(1); | 
| 1177 | 
+ | 
                        } | 
| 1178 | 
+ | 
                        lastpserver = ps; | 
| 1179 | 
+ | 
                } | 
| 1180 | 
+ | 
                psl->pid = 0;                   /* free process slot */ | 
| 1181 | 
+ | 
        } else if (status) | 
| 1182 | 
+ | 
                lastpserver = ps; | 
| 1183 | 
  | 
        freestr(pp->com);               /* free command string */ | 
| 1102 | 
– | 
        lastpid = pp->pid;              /* record PID for bwait() */ | 
| 1103 | 
– | 
        lastpserver = ps;               /* record server for serverdown() */ | 
| 1184 | 
  | 
        return(status); | 
| 1185 | 
  | 
} | 
| 1186 | 
  | 
 | 
| 1188 | 
  | 
int | 
| 1189 | 
  | 
serverdown()                    /* check status of last process server */ | 
| 1190 | 
  | 
{ | 
| 1191 | 
+ | 
        if (lastpserver == NULL || !lastpserver->hostname[0]) | 
| 1192 | 
+ | 
                return(0); | 
| 1193 | 
  | 
        if (pserverOK(lastpserver))     /* server still up? */ | 
| 1194 | 
  | 
                return(0); | 
| 1195 | 
  | 
        delpserver(lastpserver);        /* else delete it */ | 
| 1216 | 
  | 
                        printf("\t%s\n", com);  /* echo command */ | 
| 1217 | 
  | 
                return(0); | 
| 1218 | 
  | 
        } | 
| 1219 | 
< | 
                                        /* else start it when we can */ | 
| 1220 | 
< | 
        while ((pid = startjob(NULL, savestr(com), donecom)) == -1) | 
| 1219 | 
> | 
        com = savestr(com);             /* else start it when we can */ | 
| 1220 | 
> | 
        while ((pid = startjob(NULL, com, donecom)) == -1) | 
| 1221 | 
  | 
                bwait(1); | 
| 1222 | 
  | 
        if (!silent) {                          /* echo command */ | 
| 1223 | 
  | 
                PSERVER *ps; | 
| 1239 | 
  | 
int     ncoms; | 
| 1240 | 
  | 
{ | 
| 1241 | 
  | 
        int     status; | 
| 1160 | 
– | 
        register struct pslot   *psl; | 
| 1242 | 
  | 
 | 
| 1243 | 
  | 
        if (noaction) | 
| 1244 | 
  | 
                return; | 
| 1245 | 
  | 
        while ((status = wait4job(NULL, -1)) != -1) { | 
| 1246 | 
< | 
                psl = findpslot(lastpid); | 
| 1247 | 
< | 
                if (status) {           /* attempt recovery */ | 
| 1248 | 
< | 
                        serverdown();   /* check server */ | 
| 1168 | 
< | 
                        if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) { | 
| 1169 | 
< | 
                                fprintf(stderr, | 
| 1170 | 
< | 
                                        "%s: error rendering frame %d\n", | 
| 1171 | 
< | 
                                                progname, psl->fout); | 
| 1172 | 
< | 
                                quit(1); | 
| 1173 | 
< | 
                        } | 
| 1174 | 
< | 
                } | 
| 1175 | 
< | 
                psl->pid = 0;           /* free process slot */ | 
| 1176 | 
< | 
                if (!--ncoms) | 
| 1177 | 
< | 
                        return;         /* done enough */ | 
| 1246 | 
> | 
                serverdown();           /* update server status */ | 
| 1247 | 
> | 
                if (--ncoms == 0) | 
| 1248 | 
> | 
                        break;          /* done enough */ | 
| 1249 | 
  | 
        } | 
| 1250 | 
  | 
} | 
| 1251 | 
  | 
 | 
| 1257 | 
  | 
{ | 
| 1258 | 
  | 
        int     retstatus = 0; | 
| 1259 | 
  | 
        int     hostcopies; | 
| 1260 | 
< | 
        char    com1buf[10240], *com1, *endcom1; | 
| 1260 | 
> | 
        char    buf[10240], *com1, *s; | 
| 1261 | 
  | 
        int     status; | 
| 1262 | 
+ | 
        int     pfd; | 
| 1263 | 
+ | 
        register int    n; | 
| 1264 | 
  | 
        register PSERVER        *ps; | 
| 1265 | 
  | 
 | 
| 1266 | 
  | 
        if (!silent) | 
| 1272 | 
  | 
        for (ps = pslist; ps != NULL; ps = ps->next) { | 
| 1273 | 
  | 
                hostcopies = 0; | 
| 1274 | 
  | 
                if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) { | 
| 1275 | 
< | 
                        strcpy(com1=com1buf, com);      /* build -PP command */ | 
| 1275 | 
> | 
                        strcpy(com1=buf, com);  /* build -PP command */ | 
| 1276 | 
  | 
                        sprintf(com1+(ppins-com), " -PP %s/%s.persist", | 
| 1277 | 
  | 
                                        vval(DIRECTORY), phostname(ps)); | 
| 1278 | 
  | 
                        strcat(com1, ppins); | 
| 1279 | 
< | 
                        endcom1 = com1 + strlen(com1); | 
| 1207 | 
< | 
                        sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`", | 
| 1208 | 
< | 
                                        vval(DIRECTORY), phostname(ps)); | 
| 1209 | 
< | 
                } else { | 
| 1279 | 
> | 
                } else | 
| 1280 | 
  | 
                        com1 = com; | 
| 1281 | 
< | 
                        endcom1 = NULL; | 
| 1281 | 
> | 
                while (maxcopies > 0) { | 
| 1282 | 
> | 
                        s = savestr(com1); | 
| 1283 | 
> | 
                        if (startjob(ps, s, donecom) != -1) { | 
| 1284 | 
> | 
                                sleep(20); | 
| 1285 | 
> | 
                                hostcopies++; | 
| 1286 | 
> | 
                                maxcopies--; | 
| 1287 | 
> | 
                        } else { | 
| 1288 | 
> | 
                                freestr(s); | 
| 1289 | 
> | 
                                break; | 
| 1290 | 
> | 
                        } | 
| 1291 | 
  | 
                } | 
| 1213 | 
– | 
                while (maxcopies > 0 && | 
| 1214 | 
– | 
                                startjob(ps, savestr(com1), donecom) != -1) { | 
| 1215 | 
– | 
                        sleep(10); | 
| 1216 | 
– | 
                        hostcopies++; | 
| 1217 | 
– | 
                        maxcopies--; | 
| 1218 | 
– | 
                        if (endcom1 != NULL) | 
| 1219 | 
– | 
                                *endcom1 = '\0'; | 
| 1220 | 
– | 
                } | 
| 1292 | 
  | 
                if (!silent && hostcopies) { | 
| 1293 | 
  | 
                        if (hostcopies > 1) | 
| 1294 | 
  | 
                                printf("\t%d duplicate processes", hostcopies); | 
| 1300 | 
  | 
        } | 
| 1301 | 
  | 
                                        /* wait for jobs to finish */ | 
| 1302 | 
  | 
        while ((status = wait4job(NULL, -1)) != -1) | 
| 1303 | 
< | 
                if (status) | 
| 1304 | 
< | 
                        retstatus += !serverdown();     /* check server */ | 
| 1303 | 
> | 
                retstatus += status && !serverdown(); | 
| 1304 | 
> | 
                                        /* terminate parallel rpict's */ | 
| 1305 | 
> | 
        for (ps = pslist; ps != NULL; ps = ps->next) { | 
| 1306 | 
> | 
                sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps)); | 
| 1307 | 
> | 
                if ((pfd = open(buf, O_RDONLY)) >= 0) { | 
| 1308 | 
> | 
                        n = read(pfd, buf, sizeof(buf)-1);      /* get PID */ | 
| 1309 | 
> | 
                        buf[n] = '\0'; | 
| 1310 | 
> | 
                        close(pfd); | 
| 1311 | 
> | 
                        for (n = 0; buf[n] && !isspace(buf[n]); n++) | 
| 1312 | 
> | 
                                ; | 
| 1313 | 
> | 
                                                                /* terminate */ | 
| 1314 | 
> | 
                        sprintf(buf, "kill -ALRM %d", atoi(buf+n)); | 
| 1315 | 
> | 
                        wait4job(ps, startjob(ps, buf, NULL)); | 
| 1316 | 
> | 
                } | 
| 1317 | 
> | 
        } | 
| 1318 | 
  | 
        return(retstatus); | 
| 1319 | 
  | 
} | 
| 1320 | 
  | 
 | 
| 1352 | 
  | 
        fprintf(stderr, "%s: bad value for variable '%s'\n", | 
| 1353 | 
  | 
                        progname, vnam(vc)); | 
| 1354 | 
  | 
        quit(1); | 
| 1355 | 
+ | 
} | 
| 1356 | 
+ | 
 | 
| 1357 | 
+ | 
 | 
| 1358 | 
+ | 
char * | 
| 1359 | 
+ | 
dirfile(df, path)               /* separate path into directory and file */ | 
| 1360 | 
+ | 
char    *df; | 
| 1361 | 
+ | 
register char   *path; | 
| 1362 | 
+ | 
{ | 
| 1363 | 
+ | 
        register int    i; | 
| 1364 | 
+ | 
        int     psep; | 
| 1365 | 
+ | 
 | 
| 1366 | 
+ | 
        for (i = 0, psep = -1; path[i]; i++) | 
| 1367 | 
+ | 
                if (path[i] == '/') | 
| 1368 | 
+ | 
                        psep = i; | 
| 1369 | 
+ | 
        if (df != NULL) | 
| 1370 | 
+ | 
                if (psep == 0) { | 
| 1371 | 
+ | 
                        df[0] = '/'; | 
| 1372 | 
+ | 
                        df[1] = '\0'; | 
| 1373 | 
+ | 
                } else if (psep > 0) { | 
| 1374 | 
+ | 
                        strncpy(df, path, psep); | 
| 1375 | 
+ | 
                        df[psep] = '\0'; | 
| 1376 | 
+ | 
                } else | 
| 1377 | 
+ | 
                        df[0] = '\0'; | 
| 1378 | 
+ | 
        return(path+psep+1); | 
| 1379 | 
  | 
} |