ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rad.c
(Generate patch)

Comparing ray/src/util/rad.c (file contents):
Revision 2.86 by greg, Thu Aug 21 07:05:59 2008 UTC vs.
Revision 2.120 by greg, Sun Aug 2 01:32:15 2015 UTC

# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9  
10   #include <ctype.h>
11   #include <time.h>
12 + #include <signal.h>
13  
14   #include "platform.h"
15   #include "rtprocess.h"
# Line 24 | Line 25 | static const char      RCSid[] = "$Id$";
25    #define RENAMECMD "mv"
26    #include <sys/types.h>
27    #include <sys/wait.h>
28 +  #include <signal.h>
29   #endif
30  
31                                  /* variables (alphabetical by name) */
# Line 35 | Line 37 | static const char      RCSid[] = "$Id$";
37   #define INDIRECT        5               /* indirection in lighting */
38   #define MATERIAL        6               /* material files */
39   #define MKILLUM         7               /* mkillum options */
40 < #define OBJECT          8               /* object files */
41 < #define OCONV           9               /* oconv options */
42 < #define OCTREE          10              /* octree file name */
43 < #define OPTFILE         11              /* rendering options file */
44 < #define PENUMBRAS       12              /* shadow penumbras are desired */
45 < #define PFILT           13              /* pfilt options */
46 < #define PICTURE         14              /* picture file root name */
47 < #define QUALITY         15              /* desired rendering quality */
48 < #define RAWFILE         16              /* raw picture file root name */
49 < #define RENDER          17              /* rendering options */
50 < #define REPORT          18              /* report frequency and errfile */
51 < #define RESOLUTION      19              /* maximum picture resolution */
52 < #define SCENE           20              /* scene files */
53 < #define UP              21              /* view up (X, Y or Z) */
54 < #define VARIABILITY     22              /* level of light variability */
55 < #define VIEWS           23              /* view(s) for picture(s) */
56 < #define ZFILE           24              /* distance file root name */
57 < #define ZONE            25              /* simulation zone */
40 > #define MKPMAP          8               /* mkpmap options */
41 > #define OBJECT          9               /* object files */
42 > #define OCONV           10              /* oconv options */
43 > #define OCTREE          11              /* octree file name */
44 > #define OPTFILE         12              /* rendering options file */
45 > #define PCMAP           13              /* caustic photon map */
46 > #define PENUMBRAS       14              /* shadow penumbras are desired */
47 > #define PFILT           15              /* pfilt options */
48 > #define PGMAP           16              /* global photon map */
49 > #define PICTURE         17              /* picture file root name */
50 > #define QUALITY         18              /* desired rendering quality */
51 > #define RAWFILE         19              /* raw picture file root name */
52 > #define RENDER          20              /* rendering options */
53 > #define REPORT          21              /* report frequency and errfile */
54 > #define RESOLUTION      22              /* maximum picture resolution */
55 > #define RPICT           23              /* rpict parameters */
56 > #define RVU             24              /* rvu parameters */
57 > #define SCENE           25              /* scene files */
58 > #define UP              26              /* view up (X, Y or Z) */
59 > #define VARIABILITY     27              /* level of light variability */
60 > #define VIEWS           28              /* view(s) for picture(s) */
61 > #define ZFILE           29              /* distance file root name */
62 > #define ZONE            30              /* simulation zone */
63                                  /* total number of variables */
64 < int NVARS = 26;
64 > int NVARS = 31;
65  
66   VARIABLE        vv[] = {                /* variable-value pairs */
67          {"AMBFILE",     3,      0,      NULL,   onevalue},
# Line 65 | Line 72 | VARIABLE       vv[] = {                /* variable-value pairs */
72          {"INDIRECT",    3,      0,      NULL,   intvalue},
73          {"materials",   3,      0,      NULL,   catvalues},
74          {"mkillum",     3,      0,      NULL,   catvalues},
75 +        {"mkpmap",      3,      0,      NULL,   catvalues},
76          {"objects",     3,      0,      NULL,   catvalues},
77          {"oconv",       3,      0,      NULL,   catvalues},
78          {"OCTREE",      3,      0,      NULL,   onevalue},
79          {"OPTFILE",     3,      0,      NULL,   onevalue},
80 +        {"PCMAP",       2,      0,      NULL,   onevalue},
81          {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
82          {"pfilt",       2,      0,      NULL,   catvalues},
83 +        {"PGMAP",       2,      0,      NULL,   onevalue},
84          {"PICTURE",     3,      0,      NULL,   onevalue},
85          {"QUALITY",     3,      0,      NULL,   qualvalue},
86          {"RAWFILE",     3,      0,      NULL,   onevalue},
87          {"render",      3,      0,      NULL,   catvalues},
88          {"REPORT",      3,      0,      NULL,   onevalue},
89          {"RESOLUTION",  3,      0,      NULL,   onevalue},
90 +        {"rpict",       3,      0,      NULL,   catvalues},
91 +        {"rvu",         3,      0,      NULL,   catvalues},
92          {"scene",       3,      0,      NULL,   catvalues},
93          {"UP",          2,      0,      NULL,   onevalue},
94          {"VARIABILITY", 3,      0,      NULL,   qualvalue},
# Line 103 | Line 115 | time_t oct0date;               /* date of pre-mkillum octree */
115   char    *oct1name;              /* name of post-mkillum octree */
116   time_t  oct1date;               /* date of post-mkillum octree (>= matdate) */
117  
118 + char    *pgmapname;             /* name of global photon map */
119 + time_t  pgmapdate;              /* date of global photon map (>= oct1date) */
120 + char    *pcmapname;             /* name of caustic photon map */
121 + time_t  pcmapdate;              /* date of caustic photon map (>= oct1date) */
122 +
123   int     nowarn = 0;             /* no warnings */
124   int     explicate = 0;          /* explicate variables */
125   int     silent = 0;             /* do work silently */
# Line 112 | Line 129 | int    sayview = 0;            /* print view out */
129   char    *rvdevice = NULL;       /* rvu output device */
130   char    *viewselect = NULL;     /* specific view only */
131  
132 + #define DEF_RPICT_PATH  "rpict"         /* default rpict path */
133 +
134 +                                /* command paths */
135 + char    c_oconv[256] = "oconv";
136 + char    c_mkillum[256] = "mkillum";
137 + char    c_mkpmap[256] = "mkpmap";
138 + char    c_rvu[256] = "rvu";
139 + char    c_rpict[256] = DEF_RPICT_PATH;
140 + char    c_rpiece[] = "rpiece";
141 + char    c_pfilt[256] = "pfilt";
142 +
143   int     overture = 0;           /* overture calculation needed */
144  
145   int     children_running = 0;   /* set negative in children */
# Line 130 | Line 158 | static void checkfiles(void);
158   static void getoctcube(double   org[3], double  *sizp);
159   static void setdefaults(void);
160   static void oconv(void);
161 + static void mkpmap(void);
162   static char * addarg(char       *op, char       *arg);
163   static void oconvopts(char      *oo);
164   static void mkillumopts(char    *mo);
165 + static void mkpmapopts(char     *mo);
166   static void checkambfile(void);
167   static double ambval(void);
168   static void renderopts(char     *op, char       *po);
# Line 151 | Line 181 | static int touch(char  *fn);
181   static int runcom(char  *cs);
182   static int rmfile(char  *fn);
183   static int mvfile(char  *fold, char     *fnew);
184 < static int next_process(void);
184 > static int next_process(int     reserve);
185   static void wait_process(int    all);
186   static void finish_process(void);
187   static void badvalue(int        vc);
# Line 207 | Line 237 | main(
237          if (i >= argc)
238                  goto userr;
239          rifname = argv[i];
210                                /* check command-line options */
211        if ((nprocs > 1) & (viewselect != NULL))
212                nprocs = 1;
240                                  /* assign Radiance root file name */
241          rootname(radname, rifname);
242                                  /* load variable values */
# Line 232 | Line 259 | main(
259                  printvars(stdout);
260                                  /* build octree (and run mkillum) */
261          oconv();
262 +                                /* run mkpmap if indicated */
263 +        mkpmap();
264                                  /* check date on ambient file */
265          checkambfile();
266                                  /* run simulation */
# Line 253 | Line 282 | userr:
282  
283   static void
284   rootname(               /* remove tail from end of fn */
285 <        register char   *rn,
286 <        register char   *fn
285 >        char    *rn,
286 >        char    *fn
287   )
288   {
289          char    *tp, *dp;
# Line 271 | Line 300 | rootname(              /* remove tail from end of fn */
300  
301   static time_t
302   checklast(                      /* check files and find most recent */
303 <        register char   *fnames
303 >        char    *fnames
304   )
305   {
306          char    thisfile[PATH_MAX];
# Line 301 | Line 330 | newfname(              /* create modified file name */
330          int     pred
331   )
332   {
333 <        register char   *cp;
334 <        register int    n;
333 >        char    *cp;
334 >        int     n;
335          int     suffix;
336  
337          n = 0; cp = orig; suffix = -1;          /* suffix position, length */
# Line 324 | Line 353 | newfname(              /* create modified file name */
353   static void
354   checkfiles(void)                        /* check for existence and modified times */
355   {
356 +        char    fntemp[256];
357          time_t  objdate;
358  
359          if (!vdef(OCTREE)) {
# Line 353 | Line 383 | checkfiles(void)                       /* check for existence and modified
383                                  vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
384                  quit(1);
385          }
386 +        if (vdef(PGMAP)) {
387 +                if (!*sskip2(vval(PGMAP),1)) {
388 +                        fprintf(stderr, "%s: '%s' missing # photons argument\n",
389 +                                        progname, vnam(PGMAP));
390 +                        quit(1);
391 +                }
392 +                atos(fntemp, sizeof(fntemp), vval(PGMAP));
393 +                pgmapname = savqstr(fntemp);
394 +                pgmapdate = fdate(pgmapname);
395 +        }
396 +        if (vdef(PCMAP)) {
397 +                if (!*sskip2(vval(PCMAP),1)) {
398 +                        fprintf(stderr, "%s: '%s' missing # photons argument\n",
399 +                                        progname, vnam(PCMAP));
400 +                        quit(1);
401 +                }
402 +                atos(fntemp, sizeof(fntemp), vval(PCMAP));
403 +                pcmapname = savqstr(fntemp);
404 +                pcmapdate = fdate(pcmapname);
405 +        }
406          matdate = checklast(vval(MATERIAL));
407   }      
408  
# Line 367 | Line 417 | getoctcube(            /* get octree bounding cube */
417          double  min[3], max[3];
418          char    buf[1024];
419          FILE    *fp;
420 <        register int    i;
420 >        int     i;
421  
422          if (osiz <= FTINY) {
423                  if (!nprocs && fdate(oct1name) <
# Line 480 | Line 530 | oconv(void)                            /* run oconv and mkillum if necessary *
530                          touch(vval(OCTREE));
531                  else {                          /* build command */
532                          if (vdef(MATERIAL))
533 <                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
534 <                                                vval(MATERIAL), vval(SCENE),
535 <                                                vval(OCTREE));
533 >                                sprintf(combuf, "%s%s %s %s > %s", c_oconv,
534 >                                                ocopts, vval(MATERIAL),
535 >                                                vval(SCENE), vval(OCTREE));
536                          else
537 <                                sprintf(combuf, "oconv%s %s > %s", ocopts,
537 >                                sprintf(combuf, "%s%s %s > %s", c_oconv, ocopts,
538                                                  vval(SCENE), vval(OCTREE));
539                          
540                          if (runcom(combuf)) {           /* run it */
# Line 510 | Line 560 | oconv(void)                            /* run oconv and mkillum if necessary *
560                          touch(oct0name);
561                  else {                          /* build command */
562                          if (octreedate)
563 <                                sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
564 <                                        vval(OCTREE), vval(ILLUM), oct0name);
563 >                                sprintf(combuf, "%s%s -i %s %s > %s", c_oconv,
564 >                                        ocopts, vval(OCTREE),
565 >                                        vval(ILLUM), oct0name);
566                          else if (vdef(MATERIAL))
567 <                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
568 <                                        vval(MATERIAL), vval(ILLUM), oct0name);
518 <                        else
519 <                                sprintf(combuf, "oconv%s %s > %s", ocopts,
567 >                                sprintf(combuf, "%s%s %s %s > %s", c_oconv,
568 >                                        ocopts, vval(MATERIAL),
569                                          vval(ILLUM), oct0name);
570 +                        else
571 +                                sprintf(combuf, "%s%s %s > %s", c_oconv,
572 +                                        ocopts, vval(ILLUM), oct0name);
573                          if (runcom(combuf)) {           /* run it */
574                                  fprintf(stderr,
575                                  "%s: error generating octree\n\t%s removed\n",
# Line 537 | Line 589 | oconv(void)                            /* run oconv and mkillum if necessary *
589          else {
590                  mkillumopts(mkopts);            /* build mkillum command */
591                  mktemp(illumtmp);
592 <                sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
592 >                sprintf(combuf, "%s%s %s \"<\" %s > %s", c_mkillum, mkopts,
593                                  oct0name, vval(ILLUM), illumtmp);
594                  if (runcom(combuf)) {                   /* run it */
595 <                        fprintf(stderr, "%s: error running mkillum\n",
596 <                                        progname);
595 >                        fprintf(stderr, "%s: error running %s\n",
596 >                                        progname, c_mkillum);
597                          unlink(illumtmp);
598                          quit(1);
599                  }
600 +                rmfile(oct0name);
601                                                  /* make octree1 (frozen) */
602                  if (octreedate)
603 <                        sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
604 <                                vval(OCTREE), illumtmp, oct1name);
603 >                        sprintf(combuf, "%s%s -f -i %s %s > %s", c_oconv,
604 >                                ocopts, vval(OCTREE), illumtmp, oct1name);
605                  else if (vdef(MATERIAL))
606 <                        sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
607 <                                vval(MATERIAL), illumtmp, oct1name);
606 >                        sprintf(combuf, "%s%s -f %s %s > %s", c_oconv,
607 >                                ocopts, vval(MATERIAL), illumtmp, oct1name);
608                  else
609 <                        sprintf(combuf, "oconv%s -f %s > %s", ocopts,
609 >                        sprintf(combuf, "%s%s -f %s > %s", c_oconv, ocopts,
610                                  illumtmp, oct1name);
611                  if (runcom(combuf)) {           /* run it */
612                          fprintf(stderr,
# Line 571 | Line 624 | oconv(void)                            /* run oconv and mkillum if necessary *
624   }
625  
626  
627 + static void
628 + mkpmap(void)                    /* run mkpmap if indicated */
629 + {
630 +        char    combuf[2048], *cp;
631 +        time_t  tnow;
632 +                                /* nothing to do? */
633 +        if ((pgmapname == NULL) | (pgmapdate >= oct1date) &&
634 +                        (pcmapname == NULL) | (pcmapdate >= oct1date))
635 +                return;
636 +                                /* just update existing file dates? */
637 +        if (touchonly && (pgmapname == NULL) | (pgmapdate > 0) &&
638 +                        (pcmapname == NULL) | (pcmapdate > 0)) {
639 +                if (pgmapname != NULL)
640 +                        touch(pgmapname);
641 +                if (pcmapname != NULL)
642 +                        touch(pcmapname);
643 +        } else {                /* else need to (re)run pkpmap */
644 +                strcpy(combuf, c_mkpmap);
645 +                for (cp = combuf; *cp; cp++)
646 +                        ;
647 +                mkpmapopts(cp);
648 +                                /* force file overwrite */
649 +                cp = addarg(cp, "-fo+");
650 +                if (vdef(REPORT)) {
651 +                        char    errfile[256];
652 +                        int     n;
653 +                        double  minutes;
654 +                        n = sscanf(vval(REPORT), "%lf %s", &minutes, errfile);
655 +                        if (n == 2)
656 +                                sprintf(cp, " -t %d -e %s", (int)(minutes*60), errfile);
657 +                        else if (n == 1)
658 +                                sprintf(cp, " -t %d", (int)(minutes*60));
659 +                        else
660 +                                badvalue(REPORT);
661 +                }
662 +                if (pgmapname != NULL && pgmapdate < oct1date) {
663 +                        cp = addarg(cp, "-apg");
664 +                        addarg(cp, vval(PGMAP));
665 +                        cp = sskip(sskip(cp));  /* remove any bandwidth */
666 +                        *cp = '\0';
667 +                }
668 +                if (pcmapname != NULL && pcmapdate < oct1date) {
669 +                        cp = addarg(cp, "-apc");
670 +                        addarg(cp, vval(PCMAP));
671 +                        cp = sskip(sskip(cp));  /* remove any bandwidth */
672 +                        *cp = '\0';
673 +                }
674 +                cp = addarg(cp, oct1name);
675 +                if (runcom(combuf)) {
676 +                        fprintf(stderr, "%s: error running %s\n",
677 +                                        progname, c_mkpmap);
678 +                        if (pgmapname != NULL && pgmapdate < oct1date)
679 +                                unlink(pgmapname);
680 +                        if (pcmapname != NULL && pcmapdate < oct1date)
681 +                                unlink(pcmapname);
682 +                        quit(1);
683 +                }
684 +        }
685 +        tnow = time((time_t *)NULL);
686 +        if (pgmapname != NULL)
687 +                pgmapdate = tnow;
688 +        if (pcmapname != NULL)
689 +                pcmapdate = tnow;
690 +        oct1date = tnow;        /* trigger ambient file removal if needed */
691 + }
692 +
693 +
694   static char *
695 < addarg(                         /* add argument and advance pointer */
696 < register char   *op,
697 < register char   *arg
695 > addarg(                         /* append argument and advance pointer */
696 > char    *op,
697 > char    *arg
698   )
699   {
700 +        while (*op)
701 +                op++;
702          *op = ' ';
703          while ( (*++op = *arg++) )
704                  ;
# Line 586 | Line 708 | register char  *arg
708  
709   static void
710   oconvopts(                              /* get oconv options */
711 <        register char   *oo
711 >        char    *oo
712   )
713   {
714          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
715  
716          *oo = '\0';
717 <        if (vdef(OCONV))
718 <                addarg(oo, vval(OCONV));
717 >        if (!vdef(OCONV))
718 >                return;
719 >        if (vval(OCONV)[0] != '-') {
720 >                atos(c_oconv, sizeof(c_oconv), vval(OCONV));
721 >                oo = addarg(oo, sskip2(vval(OCONV), 1));
722 >        } else
723 >                oo = addarg(oo, vval(OCONV));
724   }
725  
726  
# Line 604 | Line 731 | mkillumopts(                           /* get mkillum options */
731   {
732          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
733  
734 <        if (nprocs > 1) {
734 >        if (nprocs > 1)
735                  sprintf(mo, " -n %d", nprocs);
736 <                while (*mo)
610 <                        mo++;
611 <        } else
736 >        else
737                  *mo = '\0';
738 <        if (vdef(MKILLUM))
739 <                addarg(mo, vval(MKILLUM));
738 >        if (!vdef(MKILLUM))
739 >                return;
740 >        if (vval(MKILLUM)[0] != '-') {
741 >                atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM));
742 >                mo = addarg(mo, sskip2(vval(MKILLUM), 1));
743 >        } else
744 >                mo = addarg(mo, vval(MKILLUM));
745   }
746  
747  
748   static void
749 + mkpmapopts(                             /* get mkpmap options */
750 +        char    *mo
751 + )
752 + {
753 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
754 +
755 +        *mo = '\0';
756 +        if (!vdef(MKPMAP))
757 +                return;
758 +        if (vval(MKPMAP)[0] != '-') {
759 +                atos(c_mkpmap, sizeof(c_mkpmap), vval(MKPMAP));
760 +                mo = addarg(mo, sskip2(vval(MKPMAP), 1));
761 +        } else
762 +                mo = addarg(mo, vval(MKPMAP));
763 + }
764 +
765 +
766 + static void
767   checkambfile(void)                      /* check date on ambient file */
768   {
769          time_t  afdate;
# Line 656 | Line 804 | renderopts(                    /* set rendering options */
804          char    *po
805   )
806   {
807 +        char    pmapf[256], *bw;
808 +
809          switch(vscale(QUALITY)) {
810          case LOW:
811                  lowqopts(op, po);
# Line 667 | Line 817 | renderopts(                    /* set rendering options */
817                  hiqopts(op, po);
818                  break;
819          }
820 +        if (vdef(PGMAP)) {
821 +                bw = sskip2(vval(PGMAP), 2);
822 +                atos(pmapf, sizeof(pmapf), vval(PGMAP));
823 +                op = addarg(addarg(op, "-ap"), pmapf);
824 +                if (atoi(bw) > 0) op = addarg(op, bw);
825 +        }
826 +        if (vdef(PCMAP)) {
827 +                bw = sskip2(vval(PCMAP), 2);
828 +                atos(pmapf, sizeof(pmapf), vval(PCMAP));
829 +                op = addarg(addarg(op, "-ap"), pmapf);
830 +                if (atoi(bw) > 0) op = addarg(op, bw);
831 +        }
832 +        if (vdef(RENDER))
833 +                op = addarg(op, vval(RENDER));
834 +        if (rvdevice != NULL) {
835 +                if (vdef(RVU)) {
836 +                        if (vval(RVU)[0] != '-') {
837 +                                atos(c_rvu, sizeof(c_rvu), vval(RVU));
838 +                                po = addarg(po, sskip2(vval(RVU), 1));
839 +                        } else
840 +                                po = addarg(po, vval(RVU));
841 +                }
842 +        } else {
843 +                if (vdef(RPICT)) {
844 +                        if (vval(RPICT)[0] != '-') {
845 +                                atos(c_rpict, sizeof(c_rpict), vval(RPICT));
846 +                                po = addarg(po, sskip2(vval(RPICT), 1));
847 +                        } else
848 +                                po = addarg(po, vval(RPICT));
849 +                }
850 +        }
851   }
852  
853  
854   static void
855   lowqopts(                       /* low quality rendering options */
856 <        register char   *op,
856 >        char    *op,
857          char    *po
858   )
859   {
# Line 713 | Line 894 | lowqopts(                      /* low quality rendering options */
894                  op = addarg(op, "-ds .4");
895          else
896                  op = addarg(op, "-ds 0");
897 <        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
897 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -ss 0 -st .5");
898          if (vdef(AMBFILE)) {
899                  sprintf(op, " -af %s", vval(AMBFILE));
900                  op += strlen(op);
# Line 734 | Line 915 | lowqopts(                      /* low quality rendering options */
915          d = ambval();
916          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
917          op += strlen(op);
918 <        op = addarg(op, "-lr 6 -lw .01");
738 <        if (vdef(RENDER))
739 <                op = addarg(op, vval(RENDER));
918 >        op = addarg(op, "-lr 6 -lw .003");
919   }
920  
921  
922   static void
923   medqopts(                       /* medium quality rendering options */
924 <        register char   *op,
924 >        char    *op,
925          char    *po
926   )
927   {
# Line 787 | Line 966 | medqopts(                      /* medium quality rendering options */
966          }
967          po = addarg(po, "-pt .08");
968          if (vbool(PENUMBRAS))
969 <                op = addarg(op, "-ds .2 -dj .5");
969 >                op = addarg(op, "-ds .2 -dj .9");
970          else
971                  op = addarg(op, "-ds .3");
972 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
972 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss 1 -st .1");
973          if ( (overture = vint(INDIRECT)) ) {
974                  sprintf(op, " -ab %d", overture);
975                  op += strlen(op);
# Line 814 | Line 993 | medqopts(                      /* medium quality rendering options */
993          d = ambval();
994          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
995          op += strlen(op);
996 <        op = addarg(op, "-lr 8 -lw .002");
818 <        if (vdef(RENDER))
819 <                op = addarg(op, vval(RENDER));
996 >        op = addarg(op, "-lr 8 -lw 1e-4");
997   }
998  
999  
1000   static void
1001   hiqopts(                                /* high quality rendering options */
1002 <        register char   *op,
1002 >        char    *op,
1003          char    *po
1004   )
1005   {
# Line 867 | Line 1044 | hiqopts(                               /* high quality rendering options */
1044          }
1045          po = addarg(po, "-pt .04");
1046          if (vbool(PENUMBRAS))
1047 <                op = addarg(op, "-ds .1 -dj .65");
1047 >                op = addarg(op, "-ds .1 -dj .9");
1048          else
1049                  op = addarg(op, "-ds .2");
1050 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
1050 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 16 -st .01");
1051          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
1052          op += strlen(op);
1053          if (vdef(AMBFILE)) {
# Line 892 | Line 1069 | hiqopts(                               /* high quality rendering options */
1069          d = ambval();
1070          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
1071          op += strlen(op);
1072 <        op = addarg(op, "-lr 12 -lw .0005");
896 <        if (vdef(RENDER))
897 <                op = addarg(op, vval(RENDER));
1072 >        op = addarg(op, "-lr 12 -lw 1e-5");
1073   }
1074  
1075  
1076 + #ifdef _WIN32
1077   static void
1078 + setenv(                 /* set an environment variable */
1079 +        char    *vname,
1080 +        char    *value
1081 + )
1082 + {
1083 +        char    *evp;
1084 +
1085 +        evp = bmalloc(strlen(vname)+strlen(value)+2);
1086 +        if (evp == NULL)
1087 +                syserr(progname);
1088 +        sprintf(evp, "%s=%s", vname, value);
1089 +        if (putenv(evp) != 0) {
1090 +                fprintf(stderr, "%s: out of environment space\n", progname);
1091 +                quit(1);
1092 +        }
1093 +        if (!silent)
1094 +                printf("set %s\n", evp);
1095 + }
1096 + #endif
1097 +
1098 +
1099 + static void
1100   xferopts(                               /* transfer options if indicated */
1101          char    *ro
1102   )
1103   {
1104          int     fd, n;
1105 <        register char   *cp;
1105 >        char    *cp;
1106          
1107          n = strlen(ro);
1108          if (n < 2)
# Line 933 | Line 1131 | xferopts(                              /* transfer options if indicated */
1131  
1132   static void
1133   pfiltopts(                              /* get pfilt options */
1134 <        register char   *po
1134 >        char    *po
1135   )
1136   {
1137          *po = '\0';
# Line 949 | Line 1147 | pfiltopts(                             /* get pfilt options */
1147                  po = addarg(po, "-m .25");
1148                  break;
1149          }
1150 <        if (vdef(PFILT))
1151 <                po = addarg(po, vval(PFILT));
1150 >        if (vdef(PFILT)) {
1151 >                if (vval(PFILT)[0] != '-') {
1152 >                        atos(c_pfilt, sizeof(c_pfilt), vval(PFILT));
1153 >                        po = addarg(po, sskip2(vval(PFILT), 1));
1154 >                } else
1155 >                        po = addarg(po, vval(PFILT));
1156 >        }
1157   }
1158  
1159  
1160   static int
1161   matchword(                      /* match white-delimited words */
1162 <        register char   *s1,
1163 <        register char   *s2
1162 >        char    *s1,
1163 >        char    *s2
1164   )
1165   {
1166          while (isspace(*s1)) s1++;
# Line 971 | Line 1174 | matchword(                     /* match white-delimited words */
1174  
1175   static char *
1176   specview(                               /* get proper view spec from vs */
1177 <        register char   *vs
1177 >        char    *vs
1178   )
1179   {
1180          static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
1181                          "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
1182          static char     viewopts[128];
1183 <        register char   *cp;
1183 >        char    *cp;
1184          int     xpos, ypos, zpos, viewtype, upax;
1185 <        register int    i;
1185 >        int     i;
1186          double  cent[3], dim[3], mult, d;
1187  
1188          if (vs == NULL || *vs == '-')
# Line 1039 | Line 1242 | specview(                              /* get proper view spec from vs */
1242                          cent[i] += .5*dim[i];
1243                  }
1244                  mult = vlet(ZONE)=='E' ? 2. : .45 ;
1245 <                sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
1245 >                sprintf(cp, " -vp %.3g %.3g %.3g -vd %.3g %.3g %.3g",
1246                                  cent[0]+xpos*mult*dim[0],
1247                                  cent[1]+ypos*mult*dim[1],
1248                                  cent[2]+zpos*mult*dim[2],
# Line 1071 | Line 1274 | specview(                              /* get proper view spec from vs */
1274                          break;
1275                  case VT_PAR:
1276                          d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
1277 <                        sprintf(cp, " -vh %.2g -vv %.2g", d, d);
1277 >                        sprintf(cp, " -vh %.3g -vv %.3g", d, d);
1278                          cp += strlen(cp);
1279                          break;
1280                  case VT_ANG:
# Line 1087 | Line 1290 | specview(                              /* get proper view spec from vs */
1290                  while (!isspace(*vs))           /* else skip id */
1291                          if (!*vs++)
1292                                  return(NULL);
1293 <                if (upax) {                     /* specify up vector */
1293 >                if (upax) {                     /* prepend up vector */
1294                          strcpy(cp, vup[upax+3]);
1295                          cp += strlen(cp);
1296                  }
# Line 1111 | Line 1314 | getview(                               /* get view n, or NULL if none */
1314          char    *vn             /* returned view name */
1315   )
1316   {
1317 <        register char   *mv;
1317 >        char    *mv;
1318  
1319          if (viewselect != NULL) {               /* command-line selected */
1320                  if (n)                          /* only do one */
1321                          return(NULL);
1322 +                                        
1323 +                if (isint(viewselect)) {        /* view number? */
1324 +                        n = atoi(viewselect)-1;
1325 +                        goto numview;
1326 +                }
1327                  if (viewselect[0] == '-') {     /* already specified */
1328 <                        if (vn != NULL) *vn = '\0';
1328 >                        if (vn != NULL)
1329 >                                strcpy(vn, "0");
1330                          return(viewselect);
1331                  }
1332                  if (vn != NULL) {
# Line 1126 | Line 1335 | getview(                               /* get view n, or NULL if none */
1335                                  ;
1336                          *vn = '\0';
1337                  }
1129                                                /* view number? */
1130                if (isint(viewselect))
1131                        return(specview(nvalue(VIEWS, atoi(viewselect)-1)));
1338                                                  /* check list */
1339                  while ((mv = nvalue(VIEWS, n++)) != NULL)
1340                          if (matchword(viewselect, mv))
1341                                  return(specview(mv));
1342 +
1343                  return(specview(viewselect));   /* standard view? */
1344          }
1345 + numview:
1346          mv = nvalue(VIEWS, n);          /* use view n */
1347 <        if ((vn != NULL) & (mv != NULL)) {
1348 <                register char   *mv2 = mv;
1349 <                if (*mv2 != '-')
1347 >        if ((vn != NULL) & (mv != NULL))
1348 >                if (*mv != '-') {
1349 >                        char    *mv2 = mv;
1350                          while (*mv2 && !isspace(*mv2))
1351                                  *vn++ = *mv2++;
1352 <                *vn = '\0';
1353 <        }
1352 >                        *vn = '\0';
1353 >                } else
1354 >                        sprintf(vn, "%d", n+1);
1355 >
1356          return(specview(mv));
1357   }
1358  
1359  
1360   static int
1361   myprintview(                    /* print out selected view */
1362 <        register char   *vopts,
1362 >        char    *vopts,
1363          FILE    *fp
1364   )
1365   {
1366          VIEW    vwr;
1367          char    buf[128];
1368 <        register char   *cp;
1368 >        char    *cp;
1369   #ifdef _WIN32
1370   /* XXX Should we allow something like this for all platforms? */
1371   /* XXX Or is it still required at all? */
# Line 1196 | Line 1406 | rvu(                           /* run rvu with first view */
1406                  return;
1407          if (sayview)
1408                  myprintview(vw, stdout);
1409 <        sprintf(combuf, "rvu %s%s%s -R %s ", vw, po, opts, rifname);
1409 >        sprintf(combuf, "%s %s%s%s -R %s ", c_rvu, vw, opts, po, rifname);
1410          if (nprocs > 1)
1411                  sprintf(combuf+strlen(combuf), "-n %d ", nprocs);
1412          if (rvdevice != NULL)
# Line 1205 | Line 1415 | rvu(                           /* run rvu with first view */
1415                  sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1416          strcat(combuf, oct1name);
1417          if (runcom(combuf)) {           /* run it */
1418 <                fprintf(stderr, "%s: error running rvu\n", progname);
1418 >                fprintf(stderr, "%s: error running %s\n", progname, c_rvu);
1419                  quit(1);
1420          }
1421   }
1422  
1423  
1424 + static int
1425 + syncf_done(                     /* check if an rpiece sync file is complete */
1426 +        char *sfname
1427 + )
1428 + {
1429 +        FILE    *fp = fopen(sfname, "r");
1430 +        int     todo = 1;
1431 +        int     x, y;
1432 +
1433 +        if (fp == NULL)
1434 +                return(0);
1435 +        if (fscanf(fp, "%d %d", &x, &y) != 2)
1436 +                goto checked;
1437 +        todo = x*y;             /* total number of tiles */
1438 +        if (fscanf(fp, "%d %d", &x, &y) != 2 || (x != 0) | (y != 0))
1439 +                goto checked;
1440 +                                /* XXX assume no redundant tiles */
1441 +        while (fscanf(fp, "%d %d", &x, &y) == 2)
1442 +                if (!--todo)
1443 +                        break;
1444 + checked:
1445 +        fclose(fp);
1446 +        return(!todo);
1447 + }
1448 +
1449 +
1450   static void
1451   rpict(                          /* run rpict and pfilt for each view */
1452          char    *opts,
1453          char    *po
1454   )
1455   {
1456 <        char    combuf[PATH_MAX];
1456 > #define do_rpiece       (sfile[0]!='\0')
1457 >        char    combuf[5*PATH_MAX+512];
1458          char    rawfile[PATH_MAX], picfile[PATH_MAX];
1459          char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1460 <        char    rppopt[128], *pfile = NULL;
1460 >        char    rppopt[32], sfile[PATH_MAX], *pfile = NULL;
1461          char    pfopts[128];
1462          char    vs[32], *vw;
1463          int     vn, mult;
1464          FILE    *fp;
1465          time_t  rfdt, pfdt;
1466 +        int     xres, yres;
1467 +        double  aspect;
1468 +        int     n;
1469                                          /* get pfilt options */
1470          pfiltopts(pfopts);
1471                                          /* get resolution, reporting */
# Line 1240 | Line 1480 | rpict(                         /* run rpict and pfilt for each view */
1480                  mult = 3;
1481                  break;
1482          }
1483 <        {
1484 <                int     xres, yres;
1485 <                double  aspect;
1486 <                int     n;
1487 <                n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1488 <                if (n == 3)
1489 <                        sprintf(res, "-x %d -y %d -pa %.3f",
1490 <                                        mult*xres, mult*yres, aspect);
1491 <                else if (n) {
1492 <                        if (n == 1) yres = xres;
1253 <                        sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1254 <                } else
1255 <                        badvalue(RESOLUTION);
1256 <        }
1483 >        n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1484 >        if (n == 3)
1485 >                sprintf(res, "-x %d -y %d -pa %.3f",
1486 >                                mult*xres, mult*yres, aspect);
1487 >        else if (n) {
1488 >                aspect = 1.;
1489 >                if (n == 1) yres = xres;
1490 >                sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1491 >        } else
1492 >                badvalue(RESOLUTION);
1493          rep[0] = '\0';
1494          if (vdef(REPORT)) {
1495                  double  minutes;
1260                int     n;
1496                  n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
1497                  if (n == 2)
1498                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
# Line 1267 | Line 1502 | rpict(                         /* run rpict and pfilt for each view */
1502                          badvalue(REPORT);
1503          }
1504                                          /* set up parallel rendering */
1505 <        if ((nprocs > 1) & (!vdef(ZFILE))) {
1506 <                strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1507 <                pfile = rppopt+9;
1508 <                if (mktemp(pfile) == NULL)
1505 >        sfile[0] = '\0';
1506 >        if ((nprocs > 1) & !touchonly & !vdef(ZFILE) &&
1507 >                                        getview(0, vs) != NULL) {
1508 >                if (!strcmp(c_rpict, DEF_RPICT_PATH) &&
1509 >                                getview(1, NULL) == NULL) {
1510 >                        sprintf(sfile, "%s_%s_rpsync.txt",
1511 >                                vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE),
1512 >                                        vs);
1513 >                        strcpy(rppopt, "-PP pfXXXXXX");
1514 >                } else {
1515 >                        strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1516 >                }
1517 >                pfile = rppopt + strlen(rppopt) - 8;
1518 >                if (mktemp(pfile) == NULL) {
1519 >                        if (do_rpiece) {
1520 >                                fprintf(stderr, "%s: cannot create\n", pfile);
1521 >                                quit(1);
1522 >                        }
1523                          pfile = NULL;
1524 +                }
1525          }
1526          vn = 0;                                 /* do each view */
1527          while ((vw = getview(vn++, vs)) != NULL) {
1528                  if (sayview)
1529                          myprintview(vw, stdout);
1530 <                if (!vs[0])
1281 <                        sprintf(vs, "%d", vn);
1282 <                sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1530 >                sprintf(picfile, "%s_%s.hdr", vval(PICTURE), vs);
1531                  if (vdef(ZFILE))
1532                          sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1533                  else
# Line 1300 | Line 1548 | rpict(                         /* run rpict and pfilt for each view */
1548                                  touch(picfile);
1549                          continue;
1550                  }
1551 <                if (next_process()) {           /* parallel running? */
1551 >                                                /* parallel running? */
1552 >                if (do_rpiece) {
1553 >                        if (rfdt < oct1date || !fdate(sfile)) {
1554 >                                int     xdiv = 8+nprocs/3, ydiv = 8+nprocs/3;
1555 >                                if (rfdt >= oct1date) {
1556 >                                        fprintf(stderr,
1557 >                "%s: partial output not created with %s\n", rawfile, c_rpiece);
1558 >                                        quit(1);
1559 >                                }
1560 >                                if (rfdt) {     /* start fresh */
1561 >                                        rmfile(rawfile);
1562 >                                        rfdt = 0;
1563 >                                }
1564 >                                if (!silent)
1565 >                                        printf("\techo %d %d > %s\n",
1566 >                                                        xdiv, ydiv, sfile);
1567 >                                if ((fp = fopen(sfile, "w")) == NULL) {
1568 >                                        fprintf(stderr, "%s: cannot create\n",
1569 >                                                        sfile);
1570 >                                        quit(1);
1571 >                                }
1572 >                                fprintf(fp, "%d %d\n", xdiv, ydiv);
1573 >                                fclose(fp);
1574 >                        }
1575 >                } else if (next_process(0)) {
1576                          if (pfile != NULL)
1577 <                                sleep(20);
1577 >                                sleep(10);
1578                          continue;
1579 <                }
1579 >                } else if (!inchild())
1580 >                        pfile = NULL;
1581                  /* XXX Remember to call finish_process() */
1582                                                  /* build rpict command */
1583 <                if (rfdt >= oct1date) {         /* recover */
1584 <                        sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1585 <                                rep, po, opts, zopt, rawfile, oct1name);
1586 <                        if (runcom(combuf))     /* run rpict */
1583 >                if (rfdt >= oct1date) {         /* already in progress */
1584 >                        if (do_rpiece) {
1585 >                                sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s",
1586 >                                                c_rpiece, sfile, rppopt, rep, vw,
1587 >                                                res, opts, po, rawfile, oct1name);
1588 >                                while (next_process(1)) {
1589 >                                        sleep(10);
1590 >                                        combuf[strlen(c_rpiece)+2] = 'F';
1591 >                                }
1592 >                        } else
1593 >                                sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict,
1594 >                                        rep, opts, po, zopt, rawfile, oct1name);
1595 >                        if (runcom(combuf))     /* run rpict/rpiece */
1596                                  goto rperror;
1597                  } else {
1598                          if (overture) {         /* run overture calculation */
1599                                  sprintf(combuf,
1600 <                                "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1601 <                                                rep, vw, opts,
1600 >                                        "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1601 >                                                c_rpict, rep, vw, opts,
1602                                                  oct1name, overfile);
1603 <                                if (runcom(combuf)) {
1604 <                                        fprintf(stderr,
1603 >                                if (!do_rpiece || !next_process(0)) {
1604 >                                        if (runcom(combuf)) {
1605 >                                                fprintf(stderr,
1606                                          "%s: error in overture for view %s\n",
1607 <                                                progname, vs);
1608 <                                        quit(1);
1609 <                                }
1607 >                                                        progname, vs);
1608 >                                                quit(1);
1609 >                                        }
1610   #ifndef NULL_DEVICE
1611 <                                rmfile(overfile);
1611 >                                        rmfile(overfile);
1612   #endif
1613 +                                } else if (do_rpiece)
1614 +                                        sleep(20);
1615                          }
1616 <                        sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1617 <                                        rep, vw, res, po, opts,
1618 <                                        zopt, oct1name, rawfile);
1619 <                        if (pfile != NULL && inchild()) {
1620 <                                                /* rpict persistent mode */
1616 >                        if (do_rpiece) {
1617 >                                sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s",
1618 >                                                c_rpiece, sfile, rppopt, rep, vw,
1619 >                                                res, opts, po, rawfile, oct1name);
1620 >                                while (next_process(1))
1621 >                                        sleep(10);
1622 >                        } else {
1623 >                                sprintf(combuf, "%s%s %s %s%s%s%s %s > %s",
1624 >                                                c_rpict, rep, vw, res, opts, po,
1625 >                                                zopt, oct1name, rawfile);
1626 >                        }
1627 >                        if ((pfile != NULL) & !do_rpiece) {
1628                                  if (!silent)
1629                                          printf("\t%s\n", combuf);
1630                                  fflush(stdout);
1631 <                                sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1632 <                                                rep, rppopt, res, po, opts,
1633 <                                                oct1name, rawfile);
1631 >                                sprintf(combuf, "%s%s %s %s%s%s %s > %s",
1632 >                                                c_rpict, rep, rppopt, res,
1633 >                                                opts, po, oct1name, rawfile);
1634                                  fp = popen(combuf, "w");
1635                                  if (fp == NULL)
1636                                          goto rperror;
1637                                  myprintview(vw, fp);
1638                                  if (pclose(fp))
1639                                          goto rperror;
1640 <                        } else {                /* rpict normal mode */
1641 <                                if (runcom(combuf))
1642 <                                        goto rperror;
1640 >                        } else if (runcom(combuf))
1641 >                                goto rperror;
1642 >                }
1643 >                if (do_rpiece) {                /* need to finish raw, first */
1644 >                        finish_process();
1645 >                        wait_process(1);
1646 >                        if (!syncf_done(sfile)) {
1647 >                                fprintf(stderr,
1648 >                        "%s: %s did not complete rendering of view %s\n",
1649 >                                                progname, c_rpiece, vs);
1650 >                                quit(1);
1651                          }
1652                  }
1653                  if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1654                                                  /* build pfilt command */
1655 <                        if (mult > 1)
1656 <                                sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1657 <                                        pfopts, mult, mult, rawfile, picfile);
1655 >                        if (do_rpiece)
1656 >                                sprintf(combuf,
1657 >                                        "%s%s -x %d -y %d -p %.3f %s > %s",
1658 >                                        c_pfilt, pfopts, xres, yres, aspect,
1659 >                                        rawfile, picfile);
1660 >                        else if (mult > 1)
1661 >                                sprintf(combuf, "%s%s -x /%d -y /%d %s > %s",
1662 >                                        c_pfilt, pfopts, mult, mult,
1663 >                                        rawfile, picfile);
1664                          else
1665 <                                sprintf(combuf, "pfilt%s %s > %s", pfopts,
1666 <                                                rawfile, picfile);
1665 >                                sprintf(combuf, "%s%s %s > %s", c_pfilt,
1666 >                                        pfopts, rawfile, picfile);
1667                          if (runcom(combuf)) {   /* run pfilt */
1668                                  fprintf(stderr,
1669                                  "%s: error filtering view %s\n\t%s removed\n",
# Line 1368 | Line 1674 | rpict(                         /* run rpict and pfilt for each view */
1674                  }
1675                                                  /* remove/rename raw file */
1676                  if (vdef(RAWFILE)) {
1677 <                        sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1677 >                        sprintf(combuf, "%s_%s.hdr", vval(RAWFILE), vs);
1678                          mvfile(rawfile, combuf);
1679                  } else
1680                          rmfile(rawfile);
1681 <                finish_process();               /* exit if child */
1681 >                if (do_rpiece)                  /* done with sync file */
1682 >                        rmfile(sfile);
1683 >                else
1684 >                        finish_process();       /* exit if child */
1685          }
1686          wait_process(1);                /* wait for children to finish */
1687 <        if (pfile != NULL) {            /* clean up rpict persistent mode */
1687 >        if (pfile != NULL) {            /* clean up persistent rpict */
1688                  RT_PID  pid;
1689                  fp = fopen(pfile, "r");
1690                  if (fp != NULL) {
# Line 1389 | Line 1698 | rpict(                         /* run rpict and pfilt for each view */
1698   rperror:
1699          fprintf(stderr, "%s: error rendering view %s\n", progname, vs);
1700          quit(1);
1701 + #undef do_rpiece
1702   }
1703  
1704  
# Line 1401 | Line 1711 | touch(                 /* update a file */
1711                  printf("\ttouch %s\n", fn);
1712          if (!nprocs)
1713                  return(0);
1404 #ifdef notused
1405        if (access(fn, F_OK) == -1)             /* create it */
1406                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1407                        return(-1);
1408 #endif
1714          return(setfdate(fn, time((time_t *)NULL)));
1715   }
1716  
# Line 1453 | Line 1758 | mvfile(                /* move a file */
1758  
1759   #ifdef RHAS_FORK_EXEC
1760   static int
1761 < next_process(void)                      /* fork the next process (max. nprocs) */
1761 > next_process(int reserve)               /* fork the next process */
1762   {
1763          RT_PID  child_pid;
1764  
# Line 1464 | Line 1769 | next_process(void)                     /* fork the next process (max. np
1769                                  progname);
1770                  quit(1);
1771          }
1772 +        if (reserve > 0 && children_running >= nprocs-reserve)
1773 +                return(0);              /* caller holding back process(es) */
1774          if (children_running >= nprocs)
1775                  wait_process(0);        /* wait for someone to finish */
1776          fflush(NULL);                   /* flush output */
1777          child_pid = fork();             /* split process */
1778          if (child_pid == 0) {           /* we're the child */
1779                  children_running = -1;
1780 +                nprocs = 1;
1781                  return(0);
1782          }
1783          if (child_pid > 0) {            /* we're the parent */
# Line 1511 | Line 1819 | wait_process(                  /* wait for process(es) to finish */
1819   }
1820   #else   /* ! RHAS_FORK_EXEC */
1821   static int
1822 < next_process(void)
1822 > next_process(int reserve)
1823   {
1824          return(0);                      /* cannot start new process */
1825   }
# Line 1537 | Line 1845 | finish_process(void)                   /* exit a child process */
1845                  return;                 /* in parent -- noop */
1846          exit(0);
1847   }
1540
1541 #ifdef _WIN32
1542 setenv(vname, value)            /* set an environment variable */
1543 char    *vname, *value;
1544 {
1545        register char   *evp;
1546
1547        evp = bmalloc(strlen(vname)+strlen(value)+2);
1548        if (evp == NULL)
1549                syserr(progname);
1550        sprintf(evp, "%s=%s", vname, value);
1551        if (putenv(evp) != 0) {
1552                fprintf(stderr, "%s: out of environment space\n", progname);
1553                quit(1);
1554        }
1555        if (!silent)
1556                printf("set %s\n", evp);
1557 }
1558 #endif
1848  
1849  
1850   static void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines