| 9 | 
  | 
 */ | 
| 10 | 
  | 
 | 
| 11 | 
  | 
#include "standard.h" | 
| 12 | 
+ | 
#include <ctype.h> | 
| 13 | 
  | 
#include <sys/types.h> | 
| 14 | 
  | 
#include <sys/stat.h> | 
| 15 | 
  | 
#include "view.h" | 
| 16 | 
  | 
#include "vars.h" | 
| 17 | 
+ | 
#include "netproc.h" | 
| 18 | 
  | 
                                /* input variables */ | 
| 19 | 
  | 
#define HOST            0               /* rendering host machine */ | 
| 20 | 
  | 
#define RENDER          1               /* rendering options */ | 
| 57 | 
  | 
        {"ANIMATE",     2,      0,      NULL,   onevalue}, | 
| 58 | 
  | 
        {"TRANSFER",    2,      0,      NULL,   onevalue}, | 
| 59 | 
  | 
        {"ARCHIVE",     2,      0,      NULL,   onevalue}, | 
| 60 | 
< | 
        {"INTERP",      3,      0,      NULL,   intvalue}, | 
| 61 | 
< | 
        {"OVERSAMP",    2,      0,      NULL,   fltvalue}, | 
| 60 | 
> | 
        {"INTERPOLATE", 3,      0,      NULL,   intvalue}, | 
| 61 | 
> | 
        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue}, | 
| 62 | 
  | 
        {"MBLUR",       2,      0,      NULL,   onevalue}, | 
| 63 | 
  | 
        {"RTRACE",      2,      0,      NULL,   boolvalue}, | 
| 64 | 
  | 
        {"DISKSPACE",   3,      0,      NULL,   fltvalue}, | 
| 89 | 
  | 
char    fresopt[32];            /* filter resolution options */ | 
| 90 | 
  | 
int     pfiltalways;            /* always use pfilt? */ | 
| 91 | 
  | 
 | 
| 92 | 
+ | 
char    arcargs[10240];         /* files to archive */ | 
| 93 | 
+ | 
char    *arcfirst, *arcnext;    /* pointers to first and next argument */ | 
| 94 | 
+ | 
 | 
| 95 | 
+ | 
struct pslot { | 
| 96 | 
+ | 
        int     pid;                    /* process ID (0 if empty) */ | 
| 97 | 
+ | 
        int     fout;                   /* output frame number */ | 
| 98 | 
+ | 
        int     (*rcvf)();              /* recover function */ | 
| 99 | 
+ | 
}       *pslot;                 /* process slots */ | 
| 100 | 
+ | 
int     npslots;                /* number of process slots */ | 
| 101 | 
+ | 
 | 
| 102 | 
+ | 
int     lastpid;                /* ID of last completed background process */ | 
| 103 | 
+ | 
PSERVER *lastpserver;           /* last process server used */ | 
| 104 | 
+ | 
 | 
| 105 | 
+ | 
#define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host) | 
| 106 | 
+ | 
 | 
| 107 | 
+ | 
struct pslot    *findpslot(); | 
| 108 | 
+ | 
 | 
| 109 | 
  | 
VIEW    *getview(); | 
| 110 | 
  | 
char    *getexp(); | 
| 111 | 
  | 
 | 
| 157 | 
  | 
                                                /* print variables */ | 
| 158 | 
  | 
        if (explicate) | 
| 159 | 
  | 
                printvars(stdout); | 
| 160 | 
+ | 
                                                /* set up process servers */ | 
| 161 | 
+ | 
        sethosts(); | 
| 162 | 
  | 
                                                /* run animation */ | 
| 163 | 
  | 
        animate(); | 
| 164 | 
  | 
                                                /* all done */ | 
| 166 | 
  | 
                argv[i] = vval(NEXTANIM);       /* just change input file */ | 
| 167 | 
  | 
                if (!silent) | 
| 168 | 
  | 
                        printargs(argc, argv, stdout); | 
| 169 | 
< | 
                if (!noaction) { | 
| 170 | 
< | 
                        execvp(progname, argv);         /* pass to next */ | 
| 150 | 
< | 
                        quit(1);                        /* shouldn't return */ | 
| 151 | 
< | 
                } | 
| 169 | 
> | 
                execvp(progname, argv);         /* pass to next */ | 
| 170 | 
> | 
                quit(1);                        /* shouldn't return */ | 
| 171 | 
  | 
        } | 
| 172 | 
  | 
        quit(0); | 
| 173 | 
  | 
userr: | 
| 241 | 
  | 
        char    buf[256]; | 
| 242 | 
  | 
        FILE    *fp; | 
| 243 | 
  | 
 | 
| 244 | 
+ | 
        if (noaction) | 
| 245 | 
+ | 
                return; | 
| 246 | 
  | 
        sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME); | 
| 247 | 
  | 
        if ((fp = fopen(buf, "w")) == NULL) { | 
| 248 | 
  | 
                perror(buf); | 
| 284 | 
  | 
{ | 
| 285 | 
  | 
        char    buf[256]; | 
| 286 | 
  | 
 | 
| 287 | 
< | 
        if (vdef(OCTREE) == vdef(ANIMATE)) { | 
| 287 | 
> | 
        if (vdef(ANIMATE)) { | 
| 288 | 
> | 
                vval(OCTREE) = NULL; | 
| 289 | 
> | 
                vdef(OCTREE) = 0; | 
| 290 | 
> | 
        } else if (!vdef(OCTREE)) { | 
| 291 | 
  | 
                fprintf(stderr, "%s: either %s or %s must be defined\n", | 
| 292 | 
  | 
                                progname, vnam(OCTREE), vnam(ANIMATE)); | 
| 293 | 
  | 
                quit(1); | 
| 296 | 
  | 
                fprintf(stderr, "%s: %s undefined\n", progname, vnam(VIEWFILE)); | 
| 297 | 
  | 
                quit(1); | 
| 298 | 
  | 
        } | 
| 299 | 
+ | 
        if (!vdef(HOST)) { | 
| 300 | 
+ | 
                vval(HOST) = LHOSTNAME; | 
| 301 | 
+ | 
                vdef(HOST)++; | 
| 302 | 
+ | 
        } | 
| 303 | 
  | 
        if (!vdef(START)) { | 
| 304 | 
  | 
                vval(START) = "1"; | 
| 305 | 
  | 
                vdef(START)++; | 
| 306 | 
  | 
        } | 
| 307 | 
  | 
        if (!vdef(END)) { | 
| 308 | 
< | 
                sprintf(buf, "%d", countviews()); | 
| 308 | 
> | 
                sprintf(buf, "%d", countviews()+vint(START)-1); | 
| 309 | 
  | 
                vval(END) = savqstr(buf); | 
| 310 | 
  | 
                vdef(END)++; | 
| 311 | 
  | 
        } | 
| 312 | 
+ | 
        if (vint(END) < vint(START)) { | 
| 313 | 
+ | 
                fprintf(stderr, "%s: ending frame less than starting frame\n", | 
| 314 | 
+ | 
                                progname); | 
| 315 | 
+ | 
                quit(1); | 
| 316 | 
+ | 
        } | 
| 317 | 
  | 
        if (!vdef(BASENAME)) { | 
| 318 | 
  | 
                sprintf(buf, "%s/frame%%03d", vval(DIRECTORY)); | 
| 319 | 
  | 
                vval(BASENAME) = savqstr(buf); | 
| 353 | 
  | 
} | 
| 354 | 
  | 
 | 
| 355 | 
  | 
 | 
| 356 | 
< | 
getradfile(rfname)              /* run rad and get needed variables */ | 
| 324 | 
< | 
char    *rfname; | 
| 356 | 
> | 
sethosts()                      /* set up process servers */ | 
| 357 | 
  | 
{ | 
| 358 | 
+ | 
        extern char     *iskip(); | 
| 359 | 
+ | 
        char    buf[256], *dir, *uname; | 
| 360 | 
+ | 
        int     np; | 
| 361 | 
+ | 
        register char   *cp; | 
| 362 | 
+ | 
        int     i; | 
| 363 | 
+ | 
 | 
| 364 | 
+ | 
        npslots = 0; | 
| 365 | 
+ | 
        if (noaction) | 
| 366 | 
+ | 
                return; | 
| 367 | 
+ | 
        for (i = 0; i < vdef(HOST); i++) {      /* add each host */ | 
| 368 | 
+ | 
                dir = uname = NULL; | 
| 369 | 
+ | 
                np = 1; | 
| 370 | 
+ | 
                strcpy(cp=buf, nvalue(HOST, i));        /* copy to buffer */ | 
| 371 | 
+ | 
                cp = sskip(cp);                         /* skip host name */ | 
| 372 | 
+ | 
                while (isspace(*cp)) | 
| 373 | 
+ | 
                        *cp++ = '\0'; | 
| 374 | 
+ | 
                if (*cp) {                              /* has # processes? */ | 
| 375 | 
+ | 
                        np = atoi(cp); | 
| 376 | 
+ | 
                        if ((cp = iskip(cp)) == NULL || (*cp && !isspace(*cp))) | 
| 377 | 
+ | 
                                badvalue(HOST); | 
| 378 | 
+ | 
                        while (isspace(*cp)) | 
| 379 | 
+ | 
                                cp++; | 
| 380 | 
+ | 
                        if (*cp) {                      /* has directory? */ | 
| 381 | 
+ | 
                                dir = cp; | 
| 382 | 
+ | 
                                cp = sskip(cp);                 /* skip dir. */ | 
| 383 | 
+ | 
                                while (isspace(*cp)) | 
| 384 | 
+ | 
                                        *cp++ = '\0'; | 
| 385 | 
+ | 
                                if (*cp) {                      /* has user? */ | 
| 386 | 
+ | 
                                        uname = cp; | 
| 387 | 
+ | 
                                        if (*sskip(cp)) | 
| 388 | 
+ | 
                                                badvalue(HOST); | 
| 389 | 
+ | 
                                } | 
| 390 | 
+ | 
                        } | 
| 391 | 
+ | 
                } | 
| 392 | 
+ | 
                if (addpserver(buf, dir, uname, np) == NULL) { | 
| 393 | 
+ | 
                        if (!nowarn) | 
| 394 | 
+ | 
                                fprintf(stderr, | 
| 395 | 
+ | 
                                        "%s: cannot execute on host \"%s\"\n", | 
| 396 | 
+ | 
                                                progname, buf); | 
| 397 | 
+ | 
                } else | 
| 398 | 
+ | 
                        npslots += np; | 
| 399 | 
+ | 
        } | 
| 400 | 
+ | 
        if (npslots == 0) { | 
| 401 | 
+ | 
                fprintf(stderr, "%s: no working process servers\n", progname); | 
| 402 | 
+ | 
                quit(1); | 
| 403 | 
+ | 
        } | 
| 404 | 
+ | 
        pslot = (struct pslot *)calloc(npslots, sizeof(struct pslot)); | 
| 405 | 
+ | 
        if (pslot == NULL) { | 
| 406 | 
+ | 
                perror("malloc"); | 
| 407 | 
+ | 
                quit(1); | 
| 408 | 
+ | 
        } | 
| 409 | 
+ | 
} | 
| 410 | 
+ | 
 | 
| 411 | 
+ | 
 | 
| 412 | 
+ | 
getradfile(rfargs)              /* run rad and get needed variables */ | 
| 413 | 
+ | 
char    *rfargs; | 
| 414 | 
+ | 
{ | 
| 415 | 
  | 
        static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1}; | 
| 416 | 
  | 
        char    combuf[256]; | 
| 417 | 
  | 
        register int    i; | 
| 420 | 
  | 
        sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY)); | 
| 421 | 
  | 
        sprintf(combuf, | 
| 422 | 
  | 
        "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", | 
| 423 | 
< | 
                        rfname, rendopt+2); | 
| 423 | 
> | 
                        rfargs, rendopt+2); | 
| 424 | 
  | 
        cp = combuf; | 
| 425 | 
  | 
        while (*cp) cp++;               /* match unset variables */ | 
| 426 | 
  | 
        for (i = 0; mvar[i] >= 0; i++) | 
| 432 | 
  | 
        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); | 
| 433 | 
  | 
        cp += 11;                       /* point to file name */ | 
| 434 | 
  | 
        if (system(combuf)) { | 
| 435 | 
< | 
                fprintf(stderr, "%s: bad rad input file \"%s\"\n", | 
| 436 | 
< | 
                                progname, rfname); | 
| 435 | 
> | 
                fprintf(stderr, "%s: error executing rad command:\n\t%s\n", | 
| 436 | 
> | 
                                progname, combuf); | 
| 437 | 
  | 
                quit(1); | 
| 438 | 
  | 
        } | 
| 439 | 
  | 
        loadvars(cp);                   /* load variables and remove file */ | 
| 490 | 
  | 
                                progname); | 
| 491 | 
  | 
                quit(1); | 
| 492 | 
  | 
        } | 
| 493 | 
+ | 
                                        /* initialize archive argument list */ | 
| 494 | 
+ | 
        i = 16; | 
| 495 | 
+ | 
        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i) | 
| 496 | 
+ | 
                i = strlen(vval(ARCHIVE)); | 
| 497 | 
+ | 
        arcnext = arcfirst = arcargs + i; | 
| 498 | 
  | 
                                        /* initialize status file */ | 
| 499 | 
  | 
        if (astat.rnext == 0) | 
| 500 | 
  | 
                astat.rnext = astat.fnext = astat.tnext = vint(START); | 
| 501 | 
  | 
        putastat(); | 
| 502 | 
  | 
                                        /* render in batches */ | 
| 503 | 
< | 
        while (astat.rnext <= vint(END)) { | 
| 503 | 
> | 
        while (astat.tnext <= vint(END)) { | 
| 504 | 
  | 
                renderframes(frames_batch); | 
| 505 | 
  | 
                filterframes(); | 
| 506 | 
  | 
                transferframes(); | 
| 560 | 
  | 
                } | 
| 561 | 
  | 
        } | 
| 562 | 
  | 
        if (vdef(ANIMATE))              /* wait for renderings to finish */ | 
| 563 | 
< | 
                animwait(0); | 
| 563 | 
> | 
                bwait(0); | 
| 564 | 
  | 
        else {                          /* else if walk-through */ | 
| 565 | 
  | 
                fclose(fp);             /* close view file */ | 
| 566 | 
  | 
                walkwait(astat.rnext, lastframe, vfname);       /* walk it */ | 
| 567 | 
  | 
                unlink(vfname);         /* remove view file */ | 
| 568 | 
  | 
        } | 
| 475 | 
– | 
        if (vdef(ARCHIVE))              /* archive results */ | 
| 476 | 
– | 
                archive(astat.rnext, lastframe); | 
| 569 | 
  | 
        astat.rnext = i;                /* update status */ | 
| 570 | 
  | 
        putastat(); | 
| 571 | 
  | 
} | 
| 586 | 
  | 
                                        progname, i); | 
| 587 | 
  | 
                        quit(1); | 
| 588 | 
  | 
                } | 
| 589 | 
< | 
                dofilt(i, vp, getexp(i));               /* filter frame */ | 
| 589 | 
> | 
                dofilt(i, vp, getexp(i), 0);            /* filter frame */ | 
| 590 | 
  | 
        } | 
| 591 | 
< | 
        filtwait(0);                    /* wait for filter processes */ | 
| 591 | 
> | 
        bwait(0);                       /* wait for filter processes */ | 
| 592 | 
> | 
        archive();                      /* archive originals */ | 
| 593 | 
  | 
        astat.fnext = i;                /* update status */ | 
| 594 | 
  | 
        putastat(); | 
| 595 | 
  | 
} | 
| 632 | 
  | 
int     frame; | 
| 633 | 
  | 
VIEW    *vp; | 
| 634 | 
  | 
{ | 
| 635 | 
+ | 
        extern int      recover(); | 
| 636 | 
  | 
        char    combuf[2048]; | 
| 637 | 
  | 
        char    fname[128]; | 
| 638 | 
  | 
 | 
| 640 | 
  | 
        strcat(fname, ".unf"); | 
| 641 | 
  | 
        if (access(fname, F_OK) == 0) | 
| 642 | 
  | 
                return; | 
| 643 | 
< | 
        sprintf(combuf, "%s %d | rpict%s%s %s > %s", vval(ANIMATE), frame, | 
| 643 | 
> | 
        sprintf(combuf, "%s %d | rpict%s%s -w0 %s > %s", vval(ANIMATE), frame, | 
| 644 | 
  | 
                        rendopt, viewopt(vp), rresopt, fname); | 
| 645 | 
< | 
        if (runcom(combuf)) { | 
| 552 | 
< | 
                fprintf(stderr, "%s: error rendering frame %d\n", | 
| 553 | 
< | 
                                progname, frame); | 
| 554 | 
< | 
                quit(1); | 
| 555 | 
< | 
        } | 
| 645 | 
> | 
        bruncom(combuf, frame, recover);        /* run in background */ | 
| 646 | 
  | 
} | 
| 647 | 
  | 
 | 
| 648 | 
  | 
 | 
| 559 | 
– | 
animwait(nwait)                         /* wait for renderings to finish */ | 
| 560 | 
– | 
int     nwait; | 
| 561 | 
– | 
{ | 
| 562 | 
– | 
        /* currently does nothing since parallel rendering not working */ | 
| 563 | 
– | 
} | 
| 564 | 
– | 
 | 
| 565 | 
– | 
 | 
| 649 | 
  | 
walkwait(first, last, vfn)              /* walk-through frames */ | 
| 650 | 
  | 
int     first, last; | 
| 651 | 
  | 
char    *vfn; | 
| 652 | 
  | 
{ | 
| 653 | 
  | 
        char    combuf[2048]; | 
| 654 | 
+ | 
        char    *inspoint; | 
| 655 | 
  | 
        register int    i; | 
| 656 | 
  | 
 | 
| 657 | 
  | 
        if (!noaction && vint(INTERP))          /* create dummy frames */ | 
| 662 | 
  | 
                                close(open(combuf, O_RDONLY|O_CREAT, 0666)); | 
| 663 | 
  | 
                        } | 
| 664 | 
  | 
                                        /* create command */ | 
| 665 | 
< | 
        sprintf(combuf, "rpict%s ", rendopt); | 
| 665 | 
> | 
        sprintf(combuf, "rpict%s -w0", rendopt); | 
| 666 | 
  | 
        if (vint(INTERP) || atoi(vval(MBLUR))) | 
| 667 | 
< | 
                sprintf(combuf+strlen(combuf), "-z %s.zbf ", vval(BASENAME)); | 
| 668 | 
< | 
        sprintf(combuf+strlen(combuf), "-o %s.unf %s -S %d %s < %s", | 
| 669 | 
< | 
                        vval(BASENAME), rresopt, first, vval(OCTREE), vfn); | 
| 670 | 
< | 
        if (runcom(combuf)) { | 
| 671 | 
< | 
                fprintf(stderr, | 
| 672 | 
< | 
                "%s: error rendering walk-through frames %d through %d\n", | 
| 667 | 
> | 
                sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME)); | 
| 668 | 
> | 
        sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d", | 
| 669 | 
> | 
                        vval(BASENAME), rresopt, first); | 
| 670 | 
> | 
        inspoint = combuf + strlen(combuf); | 
| 671 | 
> | 
        sprintf(inspoint, " %s < %s", vval(OCTREE), vfn); | 
| 672 | 
> | 
                                        /* run in parallel */ | 
| 673 | 
> | 
        i = (last-first+1)/(vint(INTERP)+1); | 
| 674 | 
> | 
        if (i < 1) i = 1; | 
| 675 | 
> | 
        if (pruncom(combuf, inspoint, i)) { | 
| 676 | 
> | 
                fprintf(stderr, "%s: error rendering frames %d through %d\n", | 
| 677 | 
  | 
                                progname, first, last); | 
| 678 | 
  | 
                quit(1); | 
| 679 | 
  | 
        } | 
| 687 | 
  | 
} | 
| 688 | 
  | 
 | 
| 689 | 
  | 
 | 
| 690 | 
+ | 
int | 
| 691 | 
  | 
recover(frame)                          /* recover the specified frame */ | 
| 692 | 
  | 
int     frame; | 
| 693 | 
  | 
{ | 
| 694 | 
+ | 
        static int      *rfrm;          /* list of recovered frames */ | 
| 695 | 
+ | 
        static int      nrfrms = 0; | 
| 696 | 
  | 
        char    combuf[2048]; | 
| 697 | 
  | 
        char    fname[128]; | 
| 698 | 
  | 
        register char   *cp; | 
| 699 | 
< | 
 | 
| 699 | 
> | 
        register int    i; | 
| 700 | 
> | 
                                        /* check to see if recovered already */ | 
| 701 | 
> | 
        for (i = nrfrms; i--; ) | 
| 702 | 
> | 
                if (rfrm[i] == frame) | 
| 703 | 
> | 
                        return(0); | 
| 704 | 
> | 
                                        /* build command */ | 
| 705 | 
  | 
        sprintf(fname, vval(BASENAME), frame); | 
| 706 | 
  | 
        if (vdef(ANIMATE)) | 
| 707 | 
< | 
                sprintf(combuf, "%s %d | rpict%s", | 
| 707 | 
> | 
                sprintf(combuf, "%s %d | rpict%s -w0", | 
| 708 | 
  | 
                                vval(ANIMATE), frame, rendopt); | 
| 709 | 
  | 
        else | 
| 710 | 
< | 
                sprintf(combuf, "rpict%s", rendopt); | 
| 710 | 
> | 
                sprintf(combuf, "rpict%s -w0", rendopt); | 
| 711 | 
  | 
        cp = combuf + strlen(combuf); | 
| 712 | 
  | 
        if (vint(INTERP) || atoi(vval(MBLUR))) { | 
| 713 | 
  | 
                sprintf(cp, " -z %s.zbf", fname); | 
| 719 | 
  | 
                *cp++ = ' '; | 
| 720 | 
  | 
                strcpy(cp, vval(OCTREE)); | 
| 721 | 
  | 
        } | 
| 722 | 
< | 
        if (runcom(combuf)) { | 
| 723 | 
< | 
                fprintf(stderr, "%s: error recovering frame %d\n", | 
| 724 | 
< | 
                                progname, frame); | 
| 722 | 
> | 
        if (runcom(combuf))             /* run command */ | 
| 723 | 
> | 
                return(1); | 
| 724 | 
> | 
                                        /* add frame to recovered list */ | 
| 725 | 
> | 
        if (nrfrms) | 
| 726 | 
> | 
                rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int)); | 
| 727 | 
> | 
        else | 
| 728 | 
> | 
                rfrm = (int *)malloc(sizeof(int)); | 
| 729 | 
> | 
        if (rfrm == NULL) { | 
| 730 | 
> | 
                perror("malloc"); | 
| 731 | 
  | 
                quit(1); | 
| 732 | 
  | 
        } | 
| 733 | 
+ | 
        rfrm[nrfrms++] = frame; | 
| 734 | 
+ | 
        return(0); | 
| 735 | 
  | 
} | 
| 736 | 
  | 
 | 
| 737 | 
  | 
 | 
| 738 | 
< | 
archive(first, last)                    /* archive finished renderings */ | 
| 739 | 
< | 
int     first, last; | 
| 738 | 
> | 
int | 
| 739 | 
> | 
frecover(frame)                         /* recover filtered frame */ | 
| 740 | 
> | 
int     frame; | 
| 741 | 
  | 
{ | 
| 742 | 
< | 
        char    combuf[10240]; | 
| 743 | 
< | 
        int     offset; | 
| 744 | 
< | 
        struct stat     stb; | 
| 745 | 
< | 
        register char   *cp; | 
| 742 | 
> | 
        VIEW    *vp; | 
| 743 | 
> | 
        char    *ex; | 
| 744 | 
> | 
 | 
| 745 | 
> | 
        vp = getview(frame); | 
| 746 | 
> | 
        ex = getexp(frame); | 
| 747 | 
> | 
        if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1)) | 
| 748 | 
> | 
                return(1); | 
| 749 | 
> | 
        return(0); | 
| 750 | 
> | 
} | 
| 751 | 
> | 
 | 
| 752 | 
> | 
 | 
| 753 | 
> | 
archive()                       /* archive and remove renderings */ | 
| 754 | 
> | 
{ | 
| 755 | 
> | 
#define RMCOML  (sizeof(rmcom)-1) | 
| 756 | 
> | 
        static char     rmcom[] = "rm -f"; | 
| 757 | 
  | 
        register int    i; | 
| 758 | 
  | 
 | 
| 759 | 
< | 
        strcpy(cp=combuf, vval(ARCHIVE)); | 
| 760 | 
< | 
        while (*cp) cp++; | 
| 761 | 
< | 
        offset = cp - combuf; | 
| 762 | 
< | 
        *cp++ = ' ';                            /* make argument list */ | 
| 763 | 
< | 
        for (i = first; i <= last; i++) { | 
| 764 | 
< | 
                sprintf(cp, vval(BASENAME), i); | 
| 765 | 
< | 
                strcat(cp, ".unf"); | 
| 766 | 
< | 
                if (stat(cp, &stb) == 0 && stb.st_size > 0) {   /* non-zero? */ | 
| 767 | 
< | 
                        while (*cp) cp++; | 
| 652 | 
< | 
                        *cp++ = ' '; | 
| 653 | 
< | 
                        sprintf(cp, vval(BASENAME), i); | 
| 654 | 
< | 
                        strcat(cp, ".zbf"); | 
| 655 | 
< | 
                        if (access(cp, F_OK) == 0) {            /* exists? */ | 
| 656 | 
< | 
                                while (*cp) cp++; | 
| 657 | 
< | 
                                *cp++ = ' '; | 
| 658 | 
< | 
                        } | 
| 759 | 
> | 
        if (arcnext == arcfirst) | 
| 760 | 
> | 
                return;                         /* nothing to do */ | 
| 761 | 
> | 
        if (vdef(ARCHIVE)) {                    /* run archive command */ | 
| 762 | 
> | 
                i = strlen(vval(ARCHIVE)); | 
| 763 | 
> | 
                strncpy(arcfirst-i, vval(ARCHIVE), i); | 
| 764 | 
> | 
                if (runcom(arcfirst-i)) { | 
| 765 | 
> | 
                        fprintf(stderr, "%s: error running archive command\n", | 
| 766 | 
> | 
                                        progname); | 
| 767 | 
> | 
                        quit(1); | 
| 768 | 
  | 
                } | 
| 769 | 
  | 
        } | 
| 770 | 
< | 
        *--cp = '\0'; | 
| 771 | 
< | 
        if (cp <= combuf + offset)              /* no files? */ | 
| 772 | 
< | 
                return; | 
| 773 | 
< | 
        if (runcom(combuf)) {                   /* run archive command */ | 
| 774 | 
< | 
                fprintf(stderr, | 
| 666 | 
< | 
                "%s: error running archive command on frames %d through %d\n", | 
| 667 | 
< | 
                                progname, first, last); | 
| 668 | 
< | 
                quit(1); | 
| 669 | 
< | 
        } | 
| 770 | 
> | 
                                                /* run remove command */ | 
| 771 | 
> | 
        strncpy(arcfirst-RMCOML, rmcom, RMCOML); | 
| 772 | 
> | 
        runcom(arcfirst-RMCOML); | 
| 773 | 
> | 
        arcnext = arcfirst;                     /* reset argument list */ | 
| 774 | 
> | 
#undef RMCOML | 
| 775 | 
  | 
} | 
| 776 | 
  | 
 | 
| 777 | 
  | 
 | 
| 778 | 
< | 
dofilt(frame, vp, ep)                           /* filter frame */ | 
| 778 | 
> | 
int | 
| 779 | 
> | 
dofilt(frame, vp, ep, rvr)                      /* filter frame */ | 
| 780 | 
  | 
int     frame; | 
| 781 | 
  | 
VIEW    *vp; | 
| 782 | 
  | 
char    *ep; | 
| 783 | 
+ | 
int     rvr; | 
| 784 | 
  | 
{ | 
| 785 | 
+ | 
        extern int      frecover(); | 
| 786 | 
+ | 
        static int      iter = 0; | 
| 787 | 
  | 
        char    fnbefore[128], fnafter[128]; | 
| 788 | 
< | 
        char    combuf[1024], fname[128]; | 
| 789 | 
< | 
        int     usepinterp, usepfilt; | 
| 790 | 
< | 
        int     frbefore, frafter, triesleft; | 
| 788 | 
> | 
        char    combuf[1024], fname0[128], fname1[128]; | 
| 789 | 
> | 
        int     usepinterp, usepfilt, nora_rgbe; | 
| 790 | 
> | 
        int     frseq[2]; | 
| 791 | 
  | 
                                                /* check what is needed */ | 
| 792 | 
  | 
        usepinterp = atoi(vval(MBLUR)); | 
| 793 | 
  | 
        usepfilt = pfiltalways | ep==NULL; | 
| 794 | 
+ | 
        if (ep != NULL && !strcmp(ep, "1")) | 
| 795 | 
+ | 
                ep = "+0"; | 
| 796 | 
+ | 
        nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL || | 
| 797 | 
+ | 
                        *ep != '+' || *ep != '-' || !isint(ep); | 
| 798 | 
  | 
                                                /* compute rendered views */ | 
| 799 | 
< | 
        frbefore = frame - ((frame-1) % (vint(INTERP)+1)); | 
| 800 | 
< | 
        frafter = frbefore + vint(INTERP) + 1; | 
| 801 | 
< | 
        if (frafter > vint(END)) | 
| 802 | 
< | 
                frafter = vint(END); | 
| 803 | 
< | 
        if (frafter == frame) {                 /* pfilt only */ | 
| 804 | 
< | 
                frbefore = frafter; | 
| 799 | 
> | 
        frseq[0] = frame - ((frame-1) % (vint(INTERP)+1)); | 
| 800 | 
> | 
        frseq[1] = frseq[0] + vint(INTERP) + 1; | 
| 801 | 
> | 
        if (frseq[1] > vint(END)) | 
| 802 | 
> | 
                frseq[1] = vint(END); | 
| 803 | 
> | 
        if (frseq[1] == frame) {                        /* pfilt only */ | 
| 804 | 
> | 
                frseq[0] = frseq[1]; | 
| 805 | 
  | 
                usepinterp = 0;                 /* update what's needed */ | 
| 806 | 
< | 
                usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1"); | 
| 807 | 
< | 
                triesleft = 2; | 
| 808 | 
< | 
        } else if (frbefore == frame) {         /* no interpolation */ | 
| 809 | 
< | 
                                                /* remove unneeded files */ | 
| 810 | 
< | 
                if (frbefore-vint(INTERP)-1 >= 1) { | 
| 811 | 
< | 
                        sprintf(fname, vval(BASENAME), frbefore-vint(INTERP)-1); | 
| 812 | 
< | 
                        sprintf(combuf, "rm -f %s.unf %s.zbf", fname, fname); | 
| 813 | 
< | 
                        runcom(combuf); | 
| 806 | 
> | 
                usepfilt |= nora_rgbe; | 
| 807 | 
> | 
        } else if (frseq[0] == frame) {         /* no interpolation needed */ | 
| 808 | 
> | 
                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */ | 
| 809 | 
> | 
                        *arcnext++ = ' '; | 
| 810 | 
> | 
                        sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1); | 
| 811 | 
> | 
                        while (*arcnext) arcnext++; | 
| 812 | 
> | 
                        strcpy(arcnext, ".unf"); | 
| 813 | 
> | 
                        arcnext += 4; | 
| 814 | 
> | 
                        if (usepinterp || vint(INTERP)) {       /* and z-buf */ | 
| 815 | 
> | 
                                *arcnext++ = ' '; | 
| 816 | 
> | 
                                sprintf(arcnext, vval(BASENAME), | 
| 817 | 
> | 
                                                frame-vint(INTERP)-1); | 
| 818 | 
> | 
                                while (*arcnext) arcnext++; | 
| 819 | 
> | 
                                strcpy(arcnext, ".zbf"); | 
| 820 | 
> | 
                                arcnext += 4; | 
| 821 | 
> | 
                        } | 
| 822 | 
  | 
                } | 
| 823 | 
< | 
                                                /* update what's needed */ | 
| 824 | 
< | 
                if (usepinterp) | 
| 825 | 
< | 
                        triesleft = 3; | 
| 705 | 
< | 
                else { | 
| 706 | 
< | 
                        usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1"); | 
| 707 | 
< | 
                        triesleft = 2; | 
| 708 | 
< | 
                } | 
| 709 | 
< | 
        } else {                                /* interpolation needed */ | 
| 823 | 
> | 
                if (!usepinterp)                /* update what's needed */ | 
| 824 | 
> | 
                        usepfilt |= nora_rgbe; | 
| 825 | 
> | 
        } else                                  /* interpolation needed */ | 
| 826 | 
  | 
                usepinterp++; | 
| 827 | 
< | 
                triesleft = 3; | 
| 828 | 
< | 
        } | 
| 829 | 
< | 
        if (frafter >= astat.rnext) {           /* next batch unavailable */ | 
| 830 | 
< | 
                frafter = frbefore; | 
| 831 | 
< | 
                if (triesleft > 2) | 
| 832 | 
< | 
                        triesleft = 2; | 
| 833 | 
< | 
        } | 
| 718 | 
< | 
        sprintf(fnbefore, vval(BASENAME), frbefore); | 
| 719 | 
< | 
        sprintf(fnafter, vval(BASENAME), frafter); | 
| 720 | 
< | 
tryit:                                          /* generate command */ | 
| 827 | 
> | 
        if (frseq[1] >= astat.rnext)            /* next batch unavailable */ | 
| 828 | 
> | 
                frseq[1] = frseq[0]; | 
| 829 | 
> | 
        sprintf(fnbefore, vval(BASENAME), frseq[0]); | 
| 830 | 
> | 
        sprintf(fnafter, vval(BASENAME), frseq[1]); | 
| 831 | 
> | 
        if (rvr == 1 && recover(frseq[0]))      /* recover before frame? */ | 
| 832 | 
> | 
                return(1); | 
| 833 | 
> | 
                                                /* generate command */ | 
| 834 | 
  | 
        if (usepinterp) {                       /* using pinterp */ | 
| 835 | 
+ | 
                if (rvr == 2 && recover(frseq[1]))      /* recover after? */ | 
| 836 | 
+ | 
                        return(1); | 
| 837 | 
  | 
                if (atoi(vval(MBLUR))) { | 
| 838 | 
  | 
                        FILE    *fp;            /* motion blurring */ | 
| 839 | 
< | 
                        sprintf(fname, "%s/vw0", vval(DIRECTORY)); | 
| 840 | 
< | 
                        if ((fp = fopen(fname, "w")) == NULL) { | 
| 841 | 
< | 
                                perror(fname); quit(1); | 
| 839 | 
> | 
                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY), | 
| 840 | 
> | 
                                        'a'+(iter%26)); | 
| 841 | 
> | 
                        if ((fp = fopen(fname0, "w")) == NULL) { | 
| 842 | 
> | 
                                perror(fname0); quit(1); | 
| 843 | 
  | 
                        } | 
| 844 | 
  | 
                        fputs(VIEWSTR, fp); | 
| 845 | 
  | 
                        fprintview(vp, fp); | 
| 850 | 
  | 
                                                progname, frame+1); | 
| 851 | 
  | 
                                quit(1); | 
| 852 | 
  | 
                        } | 
| 853 | 
< | 
                        sprintf(fname, "%s/vw1", vval(DIRECTORY)); | 
| 854 | 
< | 
                        if ((fp = fopen(fname, "w")) == NULL) { | 
| 855 | 
< | 
                                perror(fname); quit(1); | 
| 853 | 
> | 
                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY), | 
| 854 | 
> | 
                                        'a'+(iter%26)); | 
| 855 | 
> | 
                        if ((fp = fopen(fname1, "w")) == NULL) { | 
| 856 | 
> | 
                                perror(fname1); quit(1); | 
| 857 | 
  | 
                        } | 
| 858 | 
  | 
                        fputs(VIEWSTR, fp); | 
| 859 | 
  | 
                        fprintview(vp, fp); | 
| 860 | 
  | 
                        putc('\n', fp); fclose(fp); | 
| 861 | 
  | 
                        sprintf(combuf, | 
| 862 | 
< | 
        "(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B", | 
| 863 | 
< | 
                                *sskip(vval(MBLUR)) ? sskip(vval(MBLUR)) : "1", | 
| 864 | 
< | 
                                        atoi(vval(MBLUR)), vval(DIRECTORY), | 
| 865 | 
< | 
                                        vval(DIRECTORY), vval(DIRECTORY), | 
| 866 | 
< | 
                                        vval(DIRECTORY), vval(DIRECTORY)); | 
| 862 | 
> | 
                        "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B", | 
| 863 | 
> | 
                        *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1", | 
| 864 | 
> | 
                                        atoi(vval(MBLUR)), | 
| 865 | 
> | 
                                        fname0, fname1, fname0, fname1); | 
| 866 | 
> | 
                        iter++; | 
| 867 | 
  | 
                } else                          /* no blurring */ | 
| 868 | 
  | 
                        strcpy(combuf, "pinterp"); | 
| 869 | 
  | 
                strcat(combuf, viewopt(vp)); | 
| 870 | 
  | 
                if (vbool(RTRACE)) | 
| 871 | 
< | 
                        sprintf(combuf+strlen(combuf), " -ff -fr '%s %s'", | 
| 871 | 
> | 
                        sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'", | 
| 872 | 
  | 
                                        rendopt, vval(OCTREE)); | 
| 873 | 
  | 
                if (vdef(PINTERP)) | 
| 874 | 
  | 
                        sprintf(combuf+strlen(combuf), " %s", vval(PINTERP)); | 
| 879 | 
  | 
                                        fresopt, ep); | 
| 880 | 
  | 
                sprintf(combuf+strlen(combuf), " %s.unf %s.zbf", | 
| 881 | 
  | 
                                fnbefore, fnbefore); | 
| 882 | 
< | 
                if (frafter != frbefore) | 
| 882 | 
> | 
                if (frseq[1] != frseq[0]) | 
| 883 | 
  | 
                         sprintf(combuf+strlen(combuf), " %s.unf %s.zbf", | 
| 884 | 
  | 
                                        fnafter, fnafter); | 
| 885 | 
  | 
                if (usepfilt) {                 /* also pfilt */ | 
| 895 | 
  | 
                                sprintf(combuf+strlen(combuf), " %s", fresopt); | 
| 896 | 
  | 
                } | 
| 897 | 
  | 
        } else if (usepfilt) {                  /* pfilt only */ | 
| 898 | 
+ | 
                if (rvr == 2) | 
| 899 | 
+ | 
                        return(1); | 
| 900 | 
  | 
                if (vdef(PFILT)) | 
| 901 | 
  | 
                        sprintf(combuf, "pfilt %s", vval(PFILT)); | 
| 902 | 
  | 
                else | 
| 908 | 
  | 
                        sprintf(combuf+strlen(combuf), " %s %s.unf", | 
| 909 | 
  | 
                                        fresopt, fnbefore); | 
| 910 | 
  | 
        } else {                                /* else just check it */ | 
| 911 | 
< | 
                sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore); | 
| 911 | 
> | 
                if (rvr == 2) | 
| 912 | 
> | 
                        return(1); | 
| 913 | 
> | 
                sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore); | 
| 914 | 
  | 
        } | 
| 915 | 
  | 
                                                /* output file name */ | 
| 916 | 
< | 
        sprintf(fname, vval(BASENAME), frame); | 
| 917 | 
< | 
        sprintf(combuf+strlen(combuf), " > %s.pic", fname); | 
| 918 | 
< | 
        if (runcom(combuf))                     /* run filter command */ | 
| 919 | 
< | 
                switch (--triesleft) { | 
| 920 | 
< | 
                case 2:                         /* try to recover frafter */ | 
| 921 | 
< | 
                        recover(frafter); | 
| 801 | 
< | 
                        goto tryit; | 
| 802 | 
< | 
                case 1:                         /* try to recover frbefore */ | 
| 803 | 
< | 
                        recover(frbefore); | 
| 804 | 
< | 
                        goto tryit; | 
| 805 | 
< | 
                default:                        /* we've really failed */ | 
| 806 | 
< | 
                        fprintf(stderr, | 
| 807 | 
< | 
                        "%s: unrecoverable filtering error on frame %d\n", | 
| 808 | 
< | 
                                        progname, frame); | 
| 809 | 
< | 
                        quit(1); | 
| 810 | 
< | 
                } | 
| 916 | 
> | 
        sprintf(fname0, vval(BASENAME), frame); | 
| 917 | 
> | 
        sprintf(combuf+strlen(combuf), " > %s.pic", fname0); | 
| 918 | 
> | 
        if (rvr)                                /* in recovery */ | 
| 919 | 
> | 
                return(runcom(combuf)); | 
| 920 | 
> | 
        bruncom(combuf, frame, frecover);       /* else run in background */ | 
| 921 | 
> | 
        return(0); | 
| 922 | 
  | 
} | 
| 923 | 
  | 
 | 
| 924 | 
  | 
 | 
| 814 | 
– | 
filtwait(nwait)                 /* wait for filtering processes to finish */ | 
| 815 | 
– | 
int     nwait; | 
| 816 | 
– | 
{ | 
| 817 | 
– | 
        /* currently does nothing since parallel filtering not working */ | 
| 818 | 
– | 
} | 
| 819 | 
– | 
 | 
| 820 | 
– | 
 | 
| 925 | 
  | 
VIEW * | 
| 926 | 
  | 
getview(n)                      /* get view number n */ | 
| 927 | 
  | 
int     n; | 
| 946 | 
  | 
                        quit(1); | 
| 947 | 
  | 
                } | 
| 948 | 
  | 
        } else if (n < viewnum) {       /* rewind file */ | 
| 949 | 
+ | 
                if (viewnum == 1 && feof(viewfp)) | 
| 950 | 
+ | 
                        return(&curview);               /* just one view */ | 
| 951 | 
  | 
                if (fseek(viewfp, 0L, 0) == EOF) { | 
| 952 | 
  | 
                        perror(vval(VIEWFILE)); | 
| 953 | 
  | 
                        quit(1); | 
| 957 | 
  | 
        } | 
| 958 | 
  | 
        while (n > viewnum) {           /* scan to desired view */ | 
| 959 | 
  | 
                if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) | 
| 960 | 
< | 
                        return(NULL); | 
| 960 | 
> | 
                        return(viewnum==1 ? &curview : NULL); | 
| 961 | 
  | 
                if (isview(linebuf) && sscanview(&curview, linebuf) > 0) | 
| 962 | 
  | 
                        viewnum++; | 
| 963 | 
  | 
        } | 
| 1043 | 
  | 
} | 
| 1044 | 
  | 
 | 
| 1045 | 
  | 
 | 
| 1046 | 
< | 
runcom(cs)                      /* run command */ | 
| 1046 | 
> | 
struct pslot * | 
| 1047 | 
> | 
findpslot(pid)                  /* find or allocate a process slot */ | 
| 1048 | 
> | 
int     pid; | 
| 1049 | 
> | 
{ | 
| 1050 | 
> | 
        register struct pslot   *psempty = NULL; | 
| 1051 | 
> | 
        register int    i; | 
| 1052 | 
> | 
 | 
| 1053 | 
> | 
        for (i = 0; i < npslots; i++) {         /* look for match */ | 
| 1054 | 
> | 
                if (pslot[i].pid == pid) | 
| 1055 | 
> | 
                        return(pslot+i); | 
| 1056 | 
> | 
                if (psempty == NULL && pslot[i].pid == 0) | 
| 1057 | 
> | 
                        psempty = pslot+i; | 
| 1058 | 
> | 
        } | 
| 1059 | 
> | 
        return(psempty);                /* return emtpy slot (error if NULL) */ | 
| 1060 | 
> | 
} | 
| 1061 | 
> | 
 | 
| 1062 | 
> | 
 | 
| 1063 | 
> | 
int | 
| 1064 | 
> | 
donecom(ps, pn, status)         /* clean up after finished process */ | 
| 1065 | 
> | 
PSERVER *ps; | 
| 1066 | 
> | 
int     pn; | 
| 1067 | 
> | 
int     status; | 
| 1068 | 
> | 
{ | 
| 1069 | 
> | 
        register PROC   *pp; | 
| 1070 | 
> | 
 | 
| 1071 | 
> | 
        pp = ps->proc + pn; | 
| 1072 | 
> | 
        if (pp->elen) {                 /* pass errors */ | 
| 1073 | 
> | 
                if (ps->hostname[0]) | 
| 1074 | 
> | 
                        fprintf(stderr, "%s: ", ps->hostname); | 
| 1075 | 
> | 
                fprintf(stderr, "Error output from: %s\n", pp->com); | 
| 1076 | 
> | 
                fputs(pp->errs, stderr); | 
| 1077 | 
> | 
                fflush(stderr); | 
| 1078 | 
> | 
                if (ps->hostname[0]) | 
| 1079 | 
> | 
                        status = 1;     /* because rsh doesn't return status */ | 
| 1080 | 
> | 
        } | 
| 1081 | 
> | 
        freestr(pp->com);               /* free command string */ | 
| 1082 | 
> | 
        lastpid = pp->pid;              /* record PID for bwait() */ | 
| 1083 | 
> | 
        lastpserver = ps;               /* record server for serverdown() */ | 
| 1084 | 
> | 
        return(status); | 
| 1085 | 
> | 
} | 
| 1086 | 
> | 
 | 
| 1087 | 
> | 
 | 
| 1088 | 
> | 
int | 
| 1089 | 
> | 
serverdown()                    /* check status of last process server */ | 
| 1090 | 
> | 
{ | 
| 1091 | 
> | 
        if (pserverOK(lastpserver))     /* server still up? */ | 
| 1092 | 
> | 
                return(0); | 
| 1093 | 
> | 
        delpserver(lastpserver);        /* else delete it */ | 
| 1094 | 
> | 
        if (pslist == NULL) { | 
| 1095 | 
> | 
                fprintf(stderr, "%s: all process servers are down\n", | 
| 1096 | 
> | 
                                progname); | 
| 1097 | 
> | 
                quit(1); | 
| 1098 | 
> | 
        } | 
| 1099 | 
> | 
        return(1); | 
| 1100 | 
> | 
} | 
| 1101 | 
> | 
 | 
| 1102 | 
> | 
 | 
| 1103 | 
> | 
int | 
| 1104 | 
> | 
bruncom(com, fout, rf)          /* run a command in the background */ | 
| 1105 | 
> | 
char    *com; | 
| 1106 | 
> | 
int     fout; | 
| 1107 | 
> | 
int     (*rf)(); | 
| 1108 | 
> | 
{ | 
| 1109 | 
> | 
        int     pid; | 
| 1110 | 
> | 
        register struct pslot   *psl; | 
| 1111 | 
> | 
 | 
| 1112 | 
> | 
        if (noaction) { | 
| 1113 | 
> | 
                if (!silent) | 
| 1114 | 
> | 
                        printf("\t%s\n", com);  /* echo command */ | 
| 1115 | 
> | 
                return(0); | 
| 1116 | 
> | 
        } | 
| 1117 | 
> | 
                                        /* else start it when we can */ | 
| 1118 | 
> | 
        while ((pid = startjob(NULL, savestr(com), donecom)) == -1) | 
| 1119 | 
> | 
                bwait(1); | 
| 1120 | 
> | 
        if (!silent) {                          /* echo command */ | 
| 1121 | 
> | 
                PSERVER *ps; | 
| 1122 | 
> | 
                int     psn = pid; | 
| 1123 | 
> | 
                ps = findjob(&psn); | 
| 1124 | 
> | 
                printf("\t%s\n", com); | 
| 1125 | 
> | 
                printf("\tProcess started on %s\n", phostname(ps)); | 
| 1126 | 
> | 
                fflush(stdout); | 
| 1127 | 
> | 
        } | 
| 1128 | 
> | 
        psl = findpslot(pid);           /* record info. in appropriate slot */ | 
| 1129 | 
> | 
        psl->pid = pid; | 
| 1130 | 
> | 
        psl->fout = fout; | 
| 1131 | 
> | 
        psl->rcvf = rf; | 
| 1132 | 
> | 
        return(pid); | 
| 1133 | 
> | 
} | 
| 1134 | 
> | 
 | 
| 1135 | 
> | 
 | 
| 1136 | 
> | 
bwait(ncoms)                            /* wait for batch job(s) to finish */ | 
| 1137 | 
> | 
int     ncoms; | 
| 1138 | 
> | 
{ | 
| 1139 | 
> | 
        int     status; | 
| 1140 | 
> | 
        register struct pslot   *psl; | 
| 1141 | 
> | 
 | 
| 1142 | 
> | 
        if (noaction) | 
| 1143 | 
> | 
                return; | 
| 1144 | 
> | 
        while ((status = wait4job(NULL, -1)) != -1) { | 
| 1145 | 
> | 
                psl = findpslot(lastpid); | 
| 1146 | 
> | 
                if (status) {           /* attempt recovery */ | 
| 1147 | 
> | 
                        serverdown();   /* check server */ | 
| 1148 | 
> | 
                        if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) { | 
| 1149 | 
> | 
                                fprintf(stderr, | 
| 1150 | 
> | 
                                        "%s: error rendering frame %d\n", | 
| 1151 | 
> | 
                                                progname, psl->fout); | 
| 1152 | 
> | 
                                quit(1); | 
| 1153 | 
> | 
                        } | 
| 1154 | 
> | 
                } | 
| 1155 | 
> | 
                psl->pid = 0;           /* free process slot */ | 
| 1156 | 
> | 
                if (!--ncoms) | 
| 1157 | 
> | 
                        return;         /* done enough */ | 
| 1158 | 
> | 
        } | 
| 1159 | 
> | 
} | 
| 1160 | 
> | 
 | 
| 1161 | 
> | 
 | 
| 1162 | 
> | 
int | 
| 1163 | 
> | 
pruncom(com, ppins, maxcopies)  /* run a command in parallel over network */ | 
| 1164 | 
> | 
char    *com, *ppins; | 
| 1165 | 
> | 
int     maxcopies; | 
| 1166 | 
> | 
{ | 
| 1167 | 
> | 
        int     retstatus = 0; | 
| 1168 | 
> | 
        int     hostcopies; | 
| 1169 | 
> | 
        char    com1buf[10240], *com1, *endcom1; | 
| 1170 | 
> | 
        int     status; | 
| 1171 | 
> | 
        register PSERVER        *ps; | 
| 1172 | 
> | 
 | 
| 1173 | 
> | 
        if (!silent) | 
| 1174 | 
> | 
                printf("\t%s\n", com);  /* echo command */ | 
| 1175 | 
> | 
        if (noaction) | 
| 1176 | 
> | 
                return(0); | 
| 1177 | 
> | 
        fflush(stdout); | 
| 1178 | 
> | 
                                        /* start jobs on each server */ | 
| 1179 | 
> | 
        for (ps = pslist; ps != NULL; ps = ps->next) { | 
| 1180 | 
> | 
                hostcopies = 0; | 
| 1181 | 
> | 
                if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) { | 
| 1182 | 
> | 
                        strcpy(com1=com1buf, com);      /* build -PP command */ | 
| 1183 | 
> | 
                        sprintf(com1+(ppins-com), " -PP %s/%s.persist", | 
| 1184 | 
> | 
                                        vval(DIRECTORY), phostname(ps)); | 
| 1185 | 
> | 
                        strcat(com1, ppins); | 
| 1186 | 
> | 
                        endcom1 = com1 + strlen(com1); | 
| 1187 | 
> | 
                        sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`", | 
| 1188 | 
> | 
                                        vval(DIRECTORY), phostname(ps)); | 
| 1189 | 
> | 
                } else { | 
| 1190 | 
> | 
                        com1 = com; | 
| 1191 | 
> | 
                        endcom1 = NULL; | 
| 1192 | 
> | 
                } | 
| 1193 | 
> | 
                while (maxcopies > 0 && | 
| 1194 | 
> | 
                                startjob(ps, savestr(com1), donecom) != -1) { | 
| 1195 | 
> | 
                        sleep(10); | 
| 1196 | 
> | 
                        hostcopies++; | 
| 1197 | 
> | 
                        maxcopies--; | 
| 1198 | 
> | 
                        if (endcom1 != NULL) | 
| 1199 | 
> | 
                                *endcom1 = '\0'; | 
| 1200 | 
> | 
                } | 
| 1201 | 
> | 
                if (!silent && hostcopies) { | 
| 1202 | 
> | 
                        if (hostcopies > 1) | 
| 1203 | 
> | 
                                printf("\t%d duplicate processes", hostcopies); | 
| 1204 | 
> | 
                        else | 
| 1205 | 
> | 
                                printf("\tProcess"); | 
| 1206 | 
> | 
                        printf(" started on %s\n", phostname(ps)); | 
| 1207 | 
> | 
                        fflush(stdout); | 
| 1208 | 
> | 
                } | 
| 1209 | 
> | 
        } | 
| 1210 | 
> | 
                                        /* wait for jobs to finish */ | 
| 1211 | 
> | 
        while ((status = wait4job(NULL, -1)) != -1) | 
| 1212 | 
> | 
                if (status) | 
| 1213 | 
> | 
                        retstatus += !serverdown();     /* check server */ | 
| 1214 | 
> | 
        return(retstatus); | 
| 1215 | 
> | 
} | 
| 1216 | 
> | 
 | 
| 1217 | 
> | 
 | 
| 1218 | 
> | 
runcom(cs)                      /* run a command locally and wait for it */ | 
| 1219 | 
  | 
char    *cs; | 
| 1220 | 
  | 
{ | 
| 1221 | 
  | 
        if (!silent)            /* echo it */ |