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.65 by schorsch, Mon Jun 30 14:59:13 2003 UTC vs.
Revision 2.85 by schorsch, Mon Apr 21 07:31:30 2008 UTC

# Line 8 | Line 8 | static const char      RCSid[] = "$Id$";
8   #include "standard.h"
9  
10   #include <ctype.h>
11 + #include <time.h>
12  
13   #include "platform.h"
14 + #include "rtprocess.h"
15   #include "view.h"
16   #include "paths.h"
17   #include "vars.h"
18  
19 + #ifdef _WIN32
20 +  #define DELCMD "del"
21 +  #define RENAMECMD "rename"
22 + #else
23 +  #define DELCMD "rm -f"
24 +  #define RENAMECMD "mv"
25 +  #include <sys/types.h>
26 +  #include <sys/wait.h>
27 + #endif
28 +
29                                  /* variables (alphabetical by name) */
30   #define AMBFILE         0               /* ambient file name */
31   #define DETAIL          1               /* level of scene detail */
# Line 80 | Line 92 | char   overfile[] = NULL_DEVICE;
92   char    overfile[] = "overture.unf";
93   #endif
94  
83 extern time_t   time();
95  
96   time_t  scenedate;              /* date of latest scene or object file */
97   time_t  octreedate;             /* date of octree */
# Line 96 | Line 107 | int    nowarn = 0;             /* no warnings */
107   int     explicate = 0;          /* explicate variables */
108   int     silent = 0;             /* do work silently */
109   int     touchonly = 0;          /* touch files only */
110 < int     noaction = 0;           /* don't do anything */
110 > int     nprocs = 1;             /* maximum executing processes */
111   int     sayview = 0;            /* print view out */
112 < char    *rvdevice = NULL;       /* rview output device */
112 > char    *rvdevice = NULL;       /* rvu output device */
113   char    *viewselect = NULL;     /* specific view only */
114  
115   int     overture = 0;           /* overture calculation needed */
116  
117 + int     children_running = 0;   /* set negative in children */
118 +
119   char    *progname;              /* global argv[0] */
120   char    *rifname;               /* global rad input file name */
121  
122   char    radname[PATH_MAX];      /* root Radiance file name */
123  
124 + #define inchild()       (children_running < 0)
125  
126 < main(argc, argv)
127 < int     argc;
128 < char    *argv[];
126 > static void rootname(char       *rn, char       *fn);
127 > static time_t checklast(char    *fnames);
128 > static char * newfname(char     *orig, int      pred);
129 > static void checkfiles(void);
130 > static void getoctcube(double   org[3], double  *sizp);
131 > static void setdefaults(void);
132 > static void oconv(void);
133 > static char * addarg(char       *op, char       *arg);
134 > static void oconvopts(char      *oo);
135 > static void mkillumopts(char    *mo);
136 > static void checkambfile(void);
137 > static double ambval(void);
138 > static void renderopts(char     *op, char       *po);
139 > static void lowqopts(char       *op, char       *po);
140 > static void medqopts(char       *op, char       *po);
141 > static void hiqopts(char        *op, char       *po);
142 > static void xferopts(char       *ro);
143 > static void pfiltopts(char      *po);
144 > static int matchword(char       *s1, char       *s2);
145 > static char * specview(char     *vs);
146 > static char * getview(int       n, char *vn);
147 > static int myprintview(char     *vopts, FILE    *fp);
148 > static void rvu(char    *opts, char     *po);
149 > static void rpict(char  *opts, char     *po);
150 > static int touch(char   *fn);
151 > static int runcom(char  *cs);
152 > static int rmfile(char  *fn);
153 > static int mvfile(char  *fold, char     *fnew);
154 > static int next_process(void);
155 > static void wait_process(int    all);
156 > static void finish_process(void);
157 > static void badvalue(int        vc);
158 > static void syserr(char *s);
159 >
160 >
161 > int
162 > main(
163 >        int     argc,
164 >        char    *argv[]
165 > )
166   {
167          char    ropts[512];
168          char    popts[64];
# Line 125 | Line 176 | char   *argv[];
176                          silent++;
177                          break;
178                  case 'n':
179 <                        noaction++;
179 >                        nprocs = 0;
180                          break;
181 +                case 'N':
182 +                        nprocs = atoi(argv[++i]);
183 +                        if (nprocs < 0)
184 +                                nprocs = 0;
185 +                        break;
186                  case 't':
187                          touchonly++;
188                          break;
# Line 151 | Line 207 | char   *argv[];
207          if (i >= argc)
208                  goto userr;
209          rifname = argv[i];
210 +                                /* check command-line options */
211 +        if ((nprocs > 1) & (viewselect != NULL))
212 +                nprocs = 1;
213                                  /* assign Radiance root file name */
214          rootname(radname, rifname);
215                                  /* load variable values */
# Line 179 | Line 238 | char   *argv[];
238          renderopts(ropts, popts);
239          xferopts(ropts);
240          if (rvdevice != NULL)
241 <                rview(ropts, popts);
241 >                rvu(ropts, popts);
242          else
243                  rpict(ropts, popts);
244          quit(0);
245   userr:
246          fprintf(stderr,
247 < "Usage: %s [-w][-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
247 > "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
248                          progname);
249          quit(1);
250 +        return 1; /* pro forma return */
251   }
252  
253  
254 < rootname(rn, fn)                /* remove tail from end of fn */
255 < register char   *rn, *fn;
254 > static void
255 > rootname(               /* remove tail from end of fn */
256 >        register char   *rn,
257 >        register char   *fn
258 > )
259   {
260          char    *tp, *dp;
261  
262 <        for (tp = NULL, dp = rn; *rn = *fn++; rn++)
262 >        for (tp = NULL, dp = rn; (*rn = *fn++); rn++)
263                  if (ISDIRSEP(*rn))
264                          dp = rn;
265                  else if (*rn == '.')
# Line 206 | Line 269 | register char  *rn, *fn;
269   }
270  
271  
272 < time_t
273 < checklast(fnames)                       /* check files and find most recent */
274 < register char   *fnames;
272 > static time_t
273 > checklast(                      /* check files and find most recent */
274 >        register char   *fnames
275 > )
276   {
277          char    thisfile[PATH_MAX];
278          time_t  thisdate, lastdate = 0;
# Line 217 | Line 281 | register char  *fnames;
281                  return(0);
282          while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) {
283                  if (thisfile[0] == '!' ||
284 <                                (thisfile[0] == '\\' && thisfile[1] == '!'))
284 >                                (thisfile[0] == '\\' && thisfile[1] == '!')) {
285 >                        if (!lastdate)
286 >                                lastdate = 1;
287                          continue;
288 +                }
289                  if (!(thisdate = fdate(thisfile)))
290                          syserr(thisfile);
291                  if (thisdate > lastdate)
# Line 228 | Line 295 | register char  *fnames;
295   }
296  
297  
298 < char *
299 < newfname(orig, pred)            /* create modified file name */
300 < char    *orig;
301 < int     pred;
298 > static char *
299 > newfname(               /* create modified file name */
300 >        char    *orig,
301 >        int     pred
302 > )
303   {
304          register char   *cp;
305          register int    n;
# Line 253 | Line 321 | int    pred;
321   }
322  
323  
324 < checkfiles()                    /* check for existence and modified times */
324 > static void
325 > checkfiles(void)                        /* check for existence and modified times */
326   {
327          time_t  objdate;
328  
# Line 288 | Line 357 | checkfiles()                   /* check for existence and modified tim
357   }      
358  
359  
360 < getoctcube(org, sizp)           /* get octree bounding cube */
361 < double  org[3], *sizp;
360 > static void
361 > getoctcube(             /* get octree bounding cube */
362 >        double  org[3],
363 >        double  *sizp
364 > )
365   {
294        extern FILE     *popen();
366          static double   oorg[3], osiz = 0.;
367          double  min[3], max[3];
368          char    buf[1024];
369          FILE    *fp;
370          register int    i;
371  
372 <        if (osiz <= FTINY)
373 <                if (noaction && fdate(oct1name) <
372 >        if (osiz <= FTINY) {
373 >                if (!nprocs && fdate(oct1name) <
374                                  (scenedate>illumdate?scenedate:illumdate)) {
375                                                          /* run getbbox */
376                          sprintf(buf, "getbbox -w -h %s",
# Line 334 | Line 405 | double org[3], *sizp;
405                          }
406                          pclose(fp);
407                  }
408 +        }
409          org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
410   }
411  
412  
413 < setdefaults()                   /* set default values for unassigned var's */
413 > static void
414 > setdefaults(void)                       /* set default values for unassigned var's */
415   {
416          double  org[3], lim[3], size;
417          char    buf[128];
# Line 395 | Line 468 | setdefaults()                  /* set default values for unassigned v
468   }
469  
470  
471 < oconv()                         /* run oconv and mkillum if necessary */
471 > static void
472 > oconv(void)                             /* run oconv and mkillum if necessary */
473   {
474          static char     illumtmp[] = "ilXXXXXX";
475 <        char    combuf[PATH_MAX], ocopts[64], mkopts[64];
475 >        char    combuf[PATH_MAX], ocopts[64], mkopts[1024];
476  
477          oconvopts(ocopts);              /* get options */
478          if (octreedate < scenedate) {   /* check date on original octree */
# Line 427 | Line 501 | oconv()                                /* run oconv and mkillum if necessary */
501          }
502          if (oct1name == vval(OCTREE))           /* no mkillum? */
503                  oct1date = octreedate > matdate ? octreedate : matdate;
504 <        if (oct1date >= octreedate & oct1date >= matdate
505 <                        & oct1date >= illumdate)        /* all done */
504 >        if ((oct1date >= octreedate) & (oct1date >= matdate)
505 >                        & (oct1date >= illumdate))      /* all done */
506                  return;
507                                                  /* make octree0 */
508 <        if (oct0date < scenedate | oct0date < illumdate) {
508 >        if ((oct0date < scenedate) | (oct0date < illumdate)) {
509                  if (touchonly && oct0date)
510                          touch(oct0name);
511                  else {                          /* build command */
# Line 497 | Line 571 | oconv()                                /* run oconv and mkillum if necessary */
571   }
572  
573  
574 < char *
575 < addarg(op, arg)                         /* add argument and advance pointer */
576 < register char   *op, *arg;
574 > static char *
575 > addarg(                         /* add argument and advance pointer */
576 > register char   *op,
577 > register char   *arg
578 > )
579   {
580          *op = ' ';
581 <        while (*++op = *arg++)
581 >        while ( (*++op = *arg++) )
582                  ;
583          return(op);
584   }
585  
586  
587 < oconvopts(oo)                           /* get oconv options */
588 < register char   *oo;
587 > static void
588 > oconvopts(                              /* get oconv options */
589 >        register char   *oo
590 > )
591   {
592          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
593  
# Line 519 | Line 597 | register char  *oo;
597   }
598  
599  
600 < mkillumopts(mo)                         /* get mkillum options */
601 < register char   *mo;
600 > static void
601 > mkillumopts(                            /* get mkillum options */
602 >        char    *mo
603 > )
604   {
605          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
606  
607 <        *mo = '\0';
607 >        if (nprocs > 1) {
608 >                sprintf(mo, " -n %d", nprocs);
609 >                while (*mo)
610 >                        mo++;
611 >        } else
612 >                *mo = '\0';
613          if (vdef(MKILLUM))
614                  addarg(mo, vval(MKILLUM));
615   }
616  
617  
618 < checkambfile()                  /* check date on ambient file */
618 > static void
619 > checkambfile(void)                      /* check date on ambient file */
620   {
621          time_t  afdate;
622  
# Line 538 | Line 624 | checkambfile()                 /* check date on ambient file */
624                  return;
625          if (!(afdate = fdate(vval(AMBFILE))))
626                  return;
627 <        if (oct1date > afdate)
627 >        if (oct1date > afdate) {
628                  if (touchonly)
629                          touch(vval(AMBFILE));
630                  else
631                          rmfile(vval(AMBFILE));
632 +        }
633   }
634  
635  
636 < double
637 < ambval()                                /* compute ambient value */
636 > static double
637 > ambval(void)                            /* compute ambient value */
638   {
639          if (vdef(EXPOSURE)) {
640                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
# Line 559 | Line 646 | ambval()                               /* compute ambient value */
646          if (vlet(ZONE) == 'I')
647                  return(.01);
648          badvalue(ZONE);
649 +        return 0; /* pro forma return */
650   }
651  
652  
653 < renderopts(op, po)                      /* set rendering options */
654 < char    *op, *po;
653 > static void
654 > renderopts(                     /* set rendering options */
655 >        char    *op,
656 >        char    *po
657 > )
658   {
659          switch(vscale(QUALITY)) {
660          case LOW:
# Line 579 | Line 670 | char   *op, *po;
670   }
671  
672  
673 < lowqopts(op, po)                        /* low quality rendering options */
674 < register char   *op;
675 < char    *po;
673 > static void
674 > lowqopts(                       /* low quality rendering options */
675 >        register char   *op,
676 >        char    *po
677 > )
678   {
679          double  d, org[3], siz[3];
680  
# Line 591 | Line 684 | char   *po;
684                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
685                  badvalue(ZONE);
686          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
687 <        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
687 >        if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY))
688                  badvalue(ZONE);
689          getoctcube(org, &d);
690          d *= 3./(siz[0]+siz[1]+siz[2]);
# Line 599 | Line 692 | char   *po;
692          case LOW:
693                  po = addarg(po, "-ps 16");
694                  op = addarg(op, "-dp 64");
695 <                sprintf(op, " -ar %d", (int)(4*d));
695 >                sprintf(op, " -ar %d", (int)(8*d));
696                  op += strlen(op);
697                  break;
698          case MEDIUM:
699                  po = addarg(po, "-ps 8");
700                  op = addarg(op, "-dp 128");
701 <                sprintf(op, " -ar %d", (int)(8*d));
701 >                sprintf(op, " -ar %d", (int)(16*d));
702                  op += strlen(op);
703                  break;
704          case HIGH:
705                  po = addarg(po, "-ps 4");
706                  op = addarg(op, "-dp 256");
707 <                sprintf(op, " -ar %d", (int)(16*d));
707 >                sprintf(op, " -ar %d", (int)(32*d));
708                  op += strlen(op);
709                  break;
710          }
# Line 628 | Line 721 | char   *po;
721                  overture = 0;
722          switch (vscale(VARIABILITY)) {
723          case LOW:
724 <                op = addarg(op, "-aa .4 -ad 64");
724 >                op = addarg(op, "-aa .3 -ad 256");
725                  break;
726          case MEDIUM:
727 <                op = addarg(op, "-aa .3 -ad 128");
727 >                op = addarg(op, "-aa .25 -ad 512");
728                  break;
729          case HIGH:
730 <                op = addarg(op, "-aa .25 -ad 256");
730 >                op = addarg(op, "-aa .2 -ad 1024");
731                  break;
732          }
733          op = addarg(op, "-as 0");
734          d = ambval();
735          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
736          op += strlen(op);
737 <        op = addarg(op, "-lr 3 -lw .02");
737 >        op = addarg(op, "-lr 6 -lw .01");
738          if (vdef(RENDER))
739                  op = addarg(op, vval(RENDER));
740   }
741  
742  
743 < medqopts(op, po)                        /* medium quality rendering options */
744 < register char   *op;
745 < char    *po;
743 > static void
744 > medqopts(                       /* medium quality rendering options */
745 >        register char   *op,
746 >        char    *po
747 > )
748   {
749          double  d, org[3], siz[3], asz;
750  
# Line 659 | Line 754 | char   *po;
754                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
755                  badvalue(ZONE);
756          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
757 <        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
757 >        if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY))
758                  badvalue(ZONE);
759          getoctcube(org, &d);
760          asz = (siz[0]+siz[1]+siz[2])/3.;
# Line 668 | Line 763 | char   *po;
763          case LOW:
764                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
765                  op = addarg(op, "-dp 256");
766 <                sprintf(op, " -ar %d", (int)(8*d));
766 >                sprintf(op, " -ar %d", (int)(16*d));
767                  op += strlen(op);
768                  sprintf(op, " -ms %.2g", asz/20.);
769                  op += strlen(op);
# Line 676 | Line 771 | char   *po;
771          case MEDIUM:
772                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
773                  op = addarg(op, "-dp 512");
774 <                sprintf(op, " -ar %d", (int)(16*d));
774 >                sprintf(op, " -ar %d", (int)(32*d));
775                  op += strlen(op);
776                  sprintf(op, " -ms %.2g", asz/40.);
777                  op += strlen(op);
# Line 684 | Line 779 | char   *po;
779          case HIGH:
780                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
781                  op = addarg(op, "-dp 1024");
782 <                sprintf(op, " -ar %d", (int)(32*d));
782 >                sprintf(op, " -ar %d", (int)(64*d));
783                  op += strlen(op);
784                  sprintf(op, " -ms %.2g", asz/80.);
785                  op += strlen(op);
# Line 696 | Line 791 | char   *po;
791          else
792                  op = addarg(op, "-ds .3");
793          op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
794 <        if (overture = vint(INDIRECT)) {
794 >        if ( (overture = vint(INDIRECT)) ) {
795                  sprintf(op, " -ab %d", overture);
796                  op += strlen(op);
797          }
# Line 707 | Line 802 | char   *po;
802                  overture = 0;
803          switch (vscale(VARIABILITY)) {
804          case LOW:
805 <                op = addarg(op, "-aa .25 -ad 196 -as 0");
805 >                op = addarg(op, "-aa .2 -ad 329 -as 42");
806                  break;
807          case MEDIUM:
808 <                op = addarg(op, "-aa .2 -ad 400 -as 64");
808 >                op = addarg(op, "-aa .15 -ad 800 -as 128");
809                  break;
810          case HIGH:
811 <                op = addarg(op, "-aa .15 -ad 768 -as 196");
811 >                op = addarg(op, "-aa .1 -ad 1536 -as 392");
812                  break;
813          }
814          d = ambval();
815          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
816          op += strlen(op);
817 <        op = addarg(op, "-lr 6 -lw .002");
817 >        op = addarg(op, "-lr 8 -lw .002");
818          if (vdef(RENDER))
819                  op = addarg(op, vval(RENDER));
820   }
821  
822  
823 < hiqopts(op, po)                         /* high quality rendering options */
824 < register char   *op;
825 < char    *po;
823 > static void
824 > hiqopts(                                /* high quality rendering options */
825 >        register char   *op,
826 >        char    *po
827 > )
828   {
829          double  d, org[3], siz[3], asz;
830  
# Line 737 | Line 834 | char   *po;
834                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
835                  badvalue(ZONE);
836          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
837 <        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
837 >        if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY))
838                  badvalue(ZONE);
839          getoctcube(org, &d);
840          asz = (siz[0]+siz[1]+siz[2])/3.;
# Line 746 | Line 843 | char   *po;
843          case LOW:
844                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
845                  op = addarg(op, "-dp 1024");
846 <                sprintf(op, " -ar %d", (int)(16*d));
846 >                sprintf(op, " -ar %d", (int)(32*d));
847                  op += strlen(op);
848                  sprintf(op, " -ms %.2g", asz/40.);
849                  op += strlen(op);
# Line 754 | Line 851 | char   *po;
851          case MEDIUM:
852                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
853                  op = addarg(op, "-dp 2048");
854 <                sprintf(op, " -ar %d", (int)(32*d));
854 >                sprintf(op, " -ar %d", (int)(64*d));
855                  op += strlen(op);
856                  sprintf(op, " -ms %.2g", asz/80.);
857                  op += strlen(op);
# Line 762 | Line 859 | char   *po;
859          case HIGH:
860                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
861                  op = addarg(op, "-dp 4096");
862 <                sprintf(op, " -ar %d", (int)(64*d));
862 >                sprintf(op, " -ar %d", (int)(128*d));
863                  op += strlen(op);
864                  sprintf(op, " -ms %.2g", asz/160.);
865                  op += strlen(op);
# Line 783 | Line 880 | char   *po;
880                  overture = 0;
881          switch (vscale(VARIABILITY)) {
882          case LOW:
883 <                op = addarg(op, "-aa .15 -ad 256 -as 0");
883 >                op = addarg(op, "-aa .125 -ad 512 -as 64");
884                  break;
885          case MEDIUM:
886 <                op = addarg(op, "-aa .125 -ad 512 -as 256");
886 >                op = addarg(op, "-aa .1 -ad 1536 -as 768");
887                  break;
888          case HIGH:
889 <                op = addarg(op, "-aa .08 -ad 1024 -as 512");
889 >                op = addarg(op, "-aa .075 -ad 4096 -as 2048");
890                  break;
891          }
892          d = ambval();
# Line 801 | Line 898 | char   *po;
898   }
899  
900  
901 < xferopts(ro)                            /* transfer options if indicated */
902 < char    *ro;
901 > static void
902 > xferopts(                               /* transfer options if indicated */
903 >        char    *ro
904 > )
905   {
906          int     fd, n;
907          register char   *cp;
# Line 832 | Line 931 | char   *ro;
931   }
932  
933  
934 < pfiltopts(po)                           /* get pfilt options */
935 < register char   *po;
934 > static void
935 > pfiltopts(                              /* get pfilt options */
936 >        register char   *po
937 > )
938   {
939          *po = '\0';
940          if (vdef(EXPOSURE)) {
# Line 853 | Line 954 | register char  *po;
954   }
955  
956  
957 < matchword(s1, s2)                       /* match white-delimited words */
958 < register char   *s1, *s2;
957 > static int
958 > matchword(                      /* match white-delimited words */
959 >        register char   *s1,
960 >        register char   *s2
961 > )
962   {
963          while (isspace(*s1)) s1++;
964          while (isspace(*s2)) s2++;
# Line 865 | Line 969 | register char  *s1, *s2;
969   }
970  
971  
972 < char *
973 < specview(vs)                            /* get proper view spec from vs */
974 < register char   *vs;
972 > static char *
973 > specview(                               /* get proper view spec from vs */
974 >        register char   *vs
975 > )
976   {
977          static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
978                          "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
# Line 885 | Line 990 | register char  *vs;
990                          upax = 1-'X'+UPPER(vval(UP)[1]);
991                  else
992                          upax = 1-'X'+vlet(UP);
993 <                if (upax < 1 | upax > 3)
993 >                if ((upax < 1) | (upax > 3))
994                          badvalue(UP);
995                  if (vval(UP)[0] == '-')
996                          upax = -upax;
# Line 907 | Line 1012 | register char  *vs;
1012          } else if (*vs == 'z') {
1013                  zpos = -1; vs++;
1014          }
1015 <        viewtype = 'v';
1016 <        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h' | *vs == 'c')
1015 >        switch (*vs) {
1016 >        case VT_PER:
1017 >        case VT_PAR:
1018 >        case VT_ANG:
1019 >        case VT_HEM:
1020 >        case VT_PLS:
1021 >        case VT_CYL:
1022                  viewtype = *vs++;
1023 +                break;
1024 +        default:
1025 +                viewtype = VT_PER;
1026 +                break;
1027 +        }
1028          cp = viewopts;
1029          if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
1030                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
# Line 951 | Line 1066 | register char  *vs;
1066                  }
1067                  cp = addarg(cp, vup[upax+3]);
1068                  switch (viewtype) {
1069 <                case 'v':
1069 >                case VT_PER:
1070                          cp = addarg(cp, "-vh 45 -vv 45");
1071                          break;
1072 <                case 'l':
1072 >                case VT_PAR:
1073                          d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
1074                          sprintf(cp, " -vh %.2g -vv %.2g", d, d);
1075                          cp += strlen(cp);
1076                          break;
1077 <                case 'a':
1078 <                case 'h':
1077 >                case VT_ANG:
1078 >                case VT_HEM:
1079 >                case VT_PLS:
1080                          cp = addarg(cp, "-vh 180 -vv 180");
1081                          break;
1082 <                case 'c':
1082 >                case VT_CYL:
1083                          cp = addarg(cp, "-vh 180 -vv 90");
1084                          break;
1085                  }
# Line 989 | Line 1105 | register char  *vs;
1105   }
1106  
1107  
1108 < char *
1109 < getview(n, vn)                          /* get view n, or NULL if none */
1110 < int     n;
1111 < char    *vn;            /* returned view name */
1108 > static char *
1109 > getview(                                /* get view n, or NULL if none */
1110 >        int     n,
1111 >        char    *vn             /* returned view name */
1112 > )
1113   {
1114          register char   *mv;
1115  
# Line 1019 | Line 1136 | char   *vn;            /* returned view name */
1136                  return(specview(viewselect));   /* standard view? */
1137          }
1138          mv = nvalue(VIEWS, n);          /* use view n */
1139 <        if (vn != NULL & mv != NULL) {
1139 >        if ((vn != NULL) & (mv != NULL)) {
1140                  register char   *mv2 = mv;
1141                  if (*mv2 != '-')
1142                          while (*mv2 && !isspace(*mv2))
# Line 1030 | Line 1147 | char   *vn;            /* returned view name */
1147   }
1148  
1149  
1150 < printview(vopts)                        /* print out selected view */
1151 < register char   *vopts;
1150 > static int
1151 > myprintview(                    /* print out selected view */
1152 >        register char   *vopts,
1153 >        FILE    *fp
1154 > )
1155   {
1156          VIEW    vwr;
1157          char    buf[128];
1158          register char   *cp;
1159 + #ifdef _WIN32
1160 + /* XXX Should we allow something like this for all platforms? */
1161 + /* XXX Or is it still required at all? */
1162   again:
1163 + #endif
1164          if (vopts == NULL)
1165                  return(-1);
1166   #ifdef _WIN32
# Line 1045 | Line 1169 | again:
1169                  goto again;
1170          }
1171   #endif
1172 <        copystruct(&vwr, &stdview);
1172 >        vwr = stdview;
1173          sscanview(&vwr, cp=vopts);              /* set initial options */
1174          while ((cp = strstr(cp, "-vf ")) != NULL &&
1175                          *atos(buf, sizeof(buf), cp += 4)) {
1176                  viewfile(buf, &vwr, NULL);      /* load -vf file */
1177                  sscanview(&vwr, cp);            /* reset tail */
1178          }
1179 <        fputs(VIEWSTR, stdout);
1180 <        fprintview(&vwr, stdout);               /* print full spec. */
1181 <        fputc('\n', stdout);
1179 >        fputs(VIEWSTR, fp);
1180 >        fprintview(&vwr, fp);                   /* print full spec. */
1181 >        fputc('\n', fp);
1182          return(0);
1183   }
1184  
1185  
1186 < rview(opts, po)                         /* run rview with first view */
1187 < char    *opts, *po;
1186 > static void
1187 > rvu(                            /* run rvu with first view */
1188 >        char    *opts,
1189 >        char    *po
1190 > )
1191   {
1192          char    *vw;
1193          char    combuf[PATH_MAX];
# Line 1068 | Line 1195 | char   *opts, *po;
1195          if (touchonly || (vw = getview(0, NULL)) == NULL)
1196                  return;
1197          if (sayview)
1198 <                printview(vw);
1199 <        sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1198 >                myprintview(vw, stdout);
1199 >        sprintf(combuf, "rvu %s%s%s -R %s ", vw, po, opts, rifname);
1200          if (rvdevice != NULL)
1201                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1202          if (vdef(EXPOSURE))
1203                  sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1204          strcat(combuf, oct1name);
1205          if (runcom(combuf)) {           /* run it */
1206 <                fprintf(stderr, "%s: error running rview\n", progname);
1206 >                fprintf(stderr, "%s: error running rvu\n", progname);
1207                  quit(1);
1208          }
1209   }
1210  
1211  
1212 < rpict(opts, po)                         /* run rpict and pfilt for each view */
1213 < char    *opts, *po;
1212 > static void
1213 > rpict(                          /* run rpict and pfilt for each view */
1214 >        char    *opts,
1215 >        char    *po
1216 > )
1217   {
1218          char    combuf[PATH_MAX];
1219          char    rawfile[PATH_MAX], picfile[PATH_MAX];
1220          char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1221 +        char    rppopt[128], *pfile = NULL;
1222          char    pfopts[128];
1223          char    vs[32], *vw;
1224          int     vn, mult;
1225 +        FILE    *fp;
1226          time_t  rfdt, pfdt;
1227                                          /* get pfilt options */
1228          pfiltopts(pfopts);
# Line 1132 | Line 1264 | char   *opts, *po;
1264                  else
1265                          badvalue(REPORT);
1266          }
1267 <                                        /* do each view */
1268 <        vn = 0;
1267 >                                        /* set up parallel rendering */
1268 >        if ((nprocs > 1) & (!vdef(ZFILE))) {
1269 >                strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1270 >                pfile = rppopt+9;
1271 >                if (mktemp(pfile) == NULL)
1272 >                        pfile = NULL;
1273 >        }
1274 >        vn = 0;                                 /* do each view */
1275          while ((vw = getview(vn++, vs)) != NULL) {
1276                  if (sayview)
1277 <                        printview(vw);
1277 >                        myprintview(vw, stdout);
1278                  if (!vs[0])
1279                          sprintf(vs, "%d", vn);
1280                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
# Line 1160 | Line 1298 | char   *opts, *po;
1298                                  touch(picfile);
1299                          continue;
1300                  }
1301 +                if (next_process()) {           /* parallel running? */
1302 +                        if (pfile != NULL)
1303 +                                sleep(20);
1304 +                        continue;
1305 +                }
1306 +                /* XXX Remember to call finish_process() */
1307                                                  /* build rpict command */
1308 <                if (rfdt >= oct1date)           /* recover */
1308 >                if (rfdt >= oct1date) {         /* recover */
1309                          sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1310                                  rep, po, opts, zopt, rawfile, oct1name);
1311 <                else {
1311 >                        if (runcom(combuf))     /* run rpict */
1312 >                                goto rperror;
1313 >                } else {
1314                          if (overture) {         /* run overture calculation */
1315                                  sprintf(combuf,
1316                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
# Line 1181 | Line 1327 | char   *opts, *po;
1327   #endif
1328                          }
1329                          sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1330 <                                        rep, vw, res, po, opts, zopt,
1331 <                                        oct1name, rawfile);
1330 >                                        rep, vw, res, po, opts,
1331 >                                        zopt, oct1name, rawfile);
1332 >                        if (pfile != NULL && inchild()) {
1333 >                                                /* rpict persistent mode */
1334 >                                if (!silent)
1335 >                                        printf("\t%s\n", combuf);
1336 >                                fflush(stdout);
1337 >                                sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1338 >                                                rep, rppopt, res, po, opts,
1339 >                                                oct1name, rawfile);
1340 >                                fp = popen(combuf, "w");
1341 >                                if (fp == NULL)
1342 >                                        goto rperror;
1343 >                                myprintview(vw, fp);
1344 >                                if (pclose(fp))
1345 >                                        goto rperror;
1346 >                        } else {                /* rpict normal mode */
1347 >                                if (runcom(combuf))
1348 >                                        goto rperror;
1349 >                        }
1350                  }
1187                if (runcom(combuf)) {           /* run rpict */
1188                        fprintf(stderr, "%s: error rendering view %s\n",
1189                                        progname, vs);
1190                        quit(1);
1191                }
1351                  if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1352                                                  /* build pfilt command */
1353                          if (mult > 1)
# Line 1197 | Line 1356 | char   *opts, *po;
1356                          else
1357                                  sprintf(combuf, "pfilt%s %s > %s", pfopts,
1358                                                  rawfile, picfile);
1359 <                        if (runcom(combuf)) {           /* run pfilt */
1359 >                        if (runcom(combuf)) {   /* run pfilt */
1360                                  fprintf(stderr,
1361                                  "%s: error filtering view %s\n\t%s removed\n",
1362                                                  progname, vs, picfile);
# Line 1211 | Line 1370 | char   *opts, *po;
1370                          mvfile(rawfile, combuf);
1371                  } else
1372                          rmfile(rawfile);
1373 +                finish_process();               /* exit if child */
1374          }
1375 +        wait_process(1);                /* wait for children to finish */
1376 +        if (pfile != NULL) {            /* clean up rpict persistent mode */
1377 +                RT_PID  pid;
1378 +                fp = fopen(pfile, "r");
1379 +                if (fp != NULL) {
1380 +                        if (fscanf(fp, "%*s %d", &pid) != 1 ||
1381 +                                        kill(pid, 1) < 0)
1382 +                                unlink(pfile);
1383 +                        fclose(fp);
1384 +                }
1385 +        }
1386 +        return;
1387 + rperror:
1388 +        fprintf(stderr, "%s: error rendering view %s\n", progname, vs);
1389 +        quit(1);
1390   }
1391  
1392  
1393 < touch(fn)                       /* update a file */
1394 < char    *fn;
1393 > static int
1394 > touch(                  /* update a file */
1395 >        char    *fn
1396 > )
1397   {
1398          if (!silent)
1399                  printf("\ttouch %s\n", fn);
1400 <        if (noaction)
1400 >        if (!nprocs)
1401                  return(0);
1402   #ifdef notused
1403          if (access(fn, F_OK) == -1)             /* create it */
# Line 1231 | Line 1408 | char   *fn;
1408   }
1409  
1410  
1411 < runcom(cs)                      /* run command */
1412 < char    *cs;
1411 > static int
1412 > runcom(                 /* run command */
1413 >        char    *cs
1414 > )
1415   {
1416          if (!silent)            /* echo it */
1417                  printf("\t%s\n", cs);
1418 <        if (noaction)
1418 >        if (!nprocs)
1419                  return(0);
1420 <        fflush(stdout);         /* flush output and pass to shell */
1420 >        fflush(NULL);           /* flush output and pass to shell */
1421          return(system(cs));
1422   }
1423  
1424  
1425 < rmfile(fn)                      /* remove a file */
1426 < char    *fn;
1425 > static int
1426 > rmfile(                 /* remove a file */
1427 >        char    *fn
1428 > )
1429   {
1430          if (!silent)
1431 < #ifdef _WIN32
1432 <                printf("\tdel %s\n", fn);
1252 < #else
1253 <                printf("\trm -f %s\n", fn);
1254 < #endif
1255 <        if (noaction)
1431 >                printf("\t%s %s\n", DELCMD, fn);
1432 >        if (!nprocs)
1433                  return(0);
1434          return(unlink(fn));
1435   }
1436  
1437  
1438 < mvfile(fold, fnew)              /* move a file */
1439 < char    *fold, *fnew;
1438 > static int
1439 > mvfile(         /* move a file */
1440 >        char    *fold,
1441 >        char    *fnew
1442 > )
1443   {
1444          if (!silent)
1445 < #ifdef _WIN32
1446 <                printf("\trename %s %s\n", fold, fnew);
1267 < #else
1268 <                printf("\tmv %s %s\n", fold, fnew);
1269 < #endif
1270 <        if (noaction)
1445 >                printf("\t%s %s %s\n", RENAMECMD, fold, fnew);
1446 >        if (!nprocs)
1447                  return(0);
1448          return(rename(fold, fnew));
1449   }
1450  
1451  
1452 + #ifdef RHAS_FORK_EXEC
1453 + static int
1454 + next_process(void)                      /* fork the next process (max. nprocs) */
1455 + {
1456 +        RT_PID  child_pid;
1457 +
1458 +        if (nprocs <= 1)
1459 +                return(0);              /* it's us or no one */
1460 +        if (inchild()) {
1461 +                fprintf(stderr, "%s: internal error 1 in next_process()\n",
1462 +                                progname);
1463 +                quit(1);
1464 +        }
1465 +        if (children_running >= nprocs)
1466 +                wait_process(0);        /* wait for someone to finish */
1467 +        fflush(NULL);                   /* flush output */
1468 +        child_pid = fork();             /* split process */
1469 +        if (child_pid == 0) {           /* we're the child */
1470 +                children_running = -1;
1471 +                return(0);
1472 +        }
1473 +        if (child_pid > 0) {            /* we're the parent */
1474 +                ++children_running;
1475 +                return(1);
1476 +        }
1477 +        fprintf(stderr, "%s: warning -- fork() failed\n", progname);
1478 +        return(0);
1479 + }
1480 +
1481 + static void
1482 + wait_process(                   /* wait for process(es) to finish */
1483 +        int     all
1484 + )
1485 + {
1486 +        int     ourstatus = 0, status;
1487 +        RT_PID  pid;
1488 +
1489 +        if (all)
1490 +                all = children_running;
1491 +        else if (children_running > 0)
1492 +                all = 1;
1493 +        while (all-- > 0) {
1494 +                pid = wait(&status);
1495 +                if (pid < 0)
1496 +                        syserr(progname);
1497 +                status = status>>8 & 0xff;
1498 +                --children_running;
1499 +                if (status != 0) {      /* child's problem is our problem */
1500 +                        if ((ourstatus == 0) & (children_running > 0))
1501 +                                fprintf(stderr, "%s: waiting for remaining processes\n",
1502 +                                                progname);
1503 +                        ourstatus = status;
1504 +                        all = children_running;
1505 +                }
1506 +        }
1507 +        if (ourstatus != 0)
1508 +                quit(ourstatus);        /* bad status from child */
1509 + }
1510 + #else   /* ! RHAS_FORK_EXEC */
1511 + static int
1512 + next_process(void)
1513 + {
1514 +        return(0);                      /* cannot start new process */
1515 + }
1516 + static void
1517 + wait_process(all)
1518 + int     all;
1519 + {
1520 +        (void)all;                      /* no one to wait for */
1521 + }
1522 + int
1523 + kill(pid, sig) /* win|unix_process.c should also wait and kill */
1524 + RT_PID pid;
1525 + int sig;
1526 + {
1527 +        return 0;
1528 + }
1529 + #endif  /* ! RHAS_FORK_EXEC */
1530 +
1531 + static void
1532 + finish_process(void)                    /* exit a child process */
1533 + {
1534 +        if (!inchild())
1535 +                return;                 /* in parent -- noop */
1536 +        exit(0);
1537 + }
1538 +
1539   #ifdef _WIN32
1540   setenv(vname, value)            /* set an environment variable */
1541   char    *vname, *value;
# Line 1293 | Line 1556 | char   *vname, *value;
1556   #endif
1557  
1558  
1559 < badvalue(vc)                    /* report bad variable value and exit */
1560 < int     vc;
1559 > static void
1560 > badvalue(                       /* report bad variable value and exit */
1561 >        int     vc
1562 > )
1563   {
1564          fprintf(stderr, "%s: bad value for variable '%s'\n",
1565                          progname, vnam(vc));
# Line 1302 | Line 1567 | int    vc;
1567   }
1568  
1569  
1570 < syserr(s)                       /* report a system error and exit */
1571 < char    *s;
1570 > static void
1571 > syserr(                 /* report a system error and exit */
1572 >        char    *s
1573 > )
1574   {
1575          perror(s);
1576          quit(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines