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.72 by greg, Wed Sep 24 14:55:54 2003 UTC vs.
Revision 2.93 by greg, Tue May 18 00:01:02 2010 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
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"
# Line 21 | Line 22 | static const char      RCSid[] = "$Id$";
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) */
# Line 44 | Line 47 | static const char      RCSid[] = "$Id$";
47   #define RENDER          17              /* rendering options */
48   #define REPORT          18              /* report frequency and errfile */
49   #define RESOLUTION      19              /* maximum picture resolution */
50 < #define SCENE           20              /* scene files */
51 < #define UP              21              /* view up (X, Y or Z) */
52 < #define VARIABILITY     22              /* level of light variability */
53 < #define VIEWS           23              /* view(s) for picture(s) */
54 < #define ZFILE           24              /* distance file root name */
55 < #define ZONE            25              /* simulation zone */
50 > #define RPICT           20              /* rpict parameters */
51 > #define RVU             21              /* rvu parameters */
52 > #define SCENE           22              /* scene files */
53 > #define UP              23              /* view up (X, Y or Z) */
54 > #define VARIABILITY     24              /* level of light variability */
55 > #define VIEWS           25              /* view(s) for picture(s) */
56 > #define ZFILE           26              /* distance file root name */
57 > #define ZONE            27              /* simulation zone */
58                                  /* total number of variables */
59 < int NVARS = 26;
59 > int NVARS = 28;
60  
61   VARIABLE        vv[] = {                /* variable-value pairs */
62          {"AMBFILE",     3,      0,      NULL,   onevalue},
# Line 74 | Line 79 | VARIABLE       vv[] = {                /* variable-value pairs */
79          {"render",      3,      0,      NULL,   catvalues},
80          {"REPORT",      3,      0,      NULL,   onevalue},
81          {"RESOLUTION",  3,      0,      NULL,   onevalue},
82 +        {"rpict",       3,      0,      NULL,   catvalues},
83 +        {"rvu",         3,      0,      NULL,   catvalues},
84          {"scene",       3,      0,      NULL,   catvalues},
85          {"UP",          2,      0,      NULL,   onevalue},
86          {"VARIABILITY", 3,      0,      NULL,   qualvalue},
# Line 106 | Line 113 | int    silent = 0;             /* do work silently */
113   int     touchonly = 0;          /* touch files only */
114   int     nprocs = 1;             /* maximum executing processes */
115   int     sayview = 0;            /* print view out */
116 < char    *rvdevice = NULL;       /* rview output device */
116 > char    *rvdevice = NULL;       /* rvu output device */
117   char    *viewselect = NULL;     /* specific view only */
118  
119 + #define DEF_RPICT_PATH  "rpict"         /* default rpict path */
120 +
121 +                                /* command paths */
122 + char    c_oconv[256] = "oconv";
123 + char    c_mkillum[256] = "mkillum";
124 + char    c_rvu[256] = "rvu";
125 + char    c_rpict[256] = DEF_RPICT_PATH;
126 + char    c_rpiece[] = "rpiece";
127 + char    c_pfilt[256] = "pfilt";
128 +
129   int     overture = 0;           /* overture calculation needed */
130  
131   int     children_running = 0;   /* set negative in children */
# Line 120 | Line 137 | char   radname[PATH_MAX];      /* root Radiance file name */
137  
138   #define inchild()       (children_running < 0)
139  
140 + static void rootname(char       *rn, char       *fn);
141 + static time_t checklast(char    *fnames);
142 + static char * newfname(char     *orig, int      pred);
143 + static void checkfiles(void);
144 + static void getoctcube(double   org[3], double  *sizp);
145 + static void setdefaults(void);
146 + static void oconv(void);
147 + static char * addarg(char       *op, char       *arg);
148 + static void oconvopts(char      *oo);
149 + static void mkillumopts(char    *mo);
150 + static void checkambfile(void);
151 + static double ambval(void);
152 + static void renderopts(char     *op, char       *po);
153 + static void lowqopts(char       *op, char       *po);
154 + static void medqopts(char       *op, char       *po);
155 + static void hiqopts(char        *op, char       *po);
156 + static void xferopts(char       *ro);
157 + static void pfiltopts(char      *po);
158 + static int matchword(char       *s1, char       *s2);
159 + static char * specview(char     *vs);
160 + static char * getview(int       n, char *vn);
161 + static int myprintview(char     *vopts, FILE    *fp);
162 + static void rvu(char    *opts, char     *po);
163 + static void rpict(char  *opts, char     *po);
164 + static int touch(char   *fn);
165 + static int runcom(char  *cs);
166 + static int rmfile(char  *fn);
167 + static int mvfile(char  *fold, char     *fnew);
168 + static int next_process(void);
169 + static void wait_process(int    all);
170 + static void finish_process(void);
171 + static void badvalue(int        vc);
172 + static void syserr(char *s);
173  
174 < main(argc, argv)
175 < int     argc;
176 < char    *argv[];
174 >
175 > int
176 > main(
177 >        int     argc,
178 >        char    *argv[]
179 > )
180   {
181          char    ropts[512];
182          char    popts[64];
# Line 168 | Line 221 | char   *argv[];
221          if (i >= argc)
222                  goto userr;
223          rifname = argv[i];
171                                /* check command-line options */
172        if ((nprocs > 1) & (viewselect != NULL))
173                nprocs = 1;
224                                  /* assign Radiance root file name */
225          rootname(radname, rifname);
226                                  /* load variable values */
# Line 199 | Line 249 | char   *argv[];
249          renderopts(ropts, popts);
250          xferopts(ropts);
251          if (rvdevice != NULL)
252 <                rview(ropts, popts);
252 >                rvu(ropts, popts);
253          else
254                  rpict(ropts, popts);
255          quit(0);
# Line 208 | Line 258 | userr:
258   "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
259                          progname);
260          quit(1);
261 +        return 1; /* pro forma return */
262   }
263  
264  
265 < rootname(rn, fn)                /* remove tail from end of fn */
266 < register char   *rn, *fn;
265 > static void
266 > rootname(               /* remove tail from end of fn */
267 >        register char   *rn,
268 >        register char   *fn
269 > )
270   {
271          char    *tp, *dp;
272  
# Line 226 | Line 280 | register char  *rn, *fn;
280   }
281  
282  
283 < time_t
284 < checklast(fnames)                       /* check files and find most recent */
285 < register char   *fnames;
283 > static time_t
284 > checklast(                      /* check files and find most recent */
285 >        register char   *fnames
286 > )
287   {
288          char    thisfile[PATH_MAX];
289          time_t  thisdate, lastdate = 0;
# Line 237 | Line 292 | register char  *fnames;
292                  return(0);
293          while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) {
294                  if (thisfile[0] == '!' ||
295 <                                (thisfile[0] == '\\' && thisfile[1] == '!'))
295 >                                (thisfile[0] == '\\' && thisfile[1] == '!')) {
296 >                        if (!lastdate)
297 >                                lastdate = 1;
298                          continue;
299 +                }
300                  if (!(thisdate = fdate(thisfile)))
301                          syserr(thisfile);
302                  if (thisdate > lastdate)
# Line 248 | Line 306 | register char  *fnames;
306   }
307  
308  
309 < char *
310 < newfname(orig, pred)            /* create modified file name */
311 < char    *orig;
312 < int     pred;
309 > static char *
310 > newfname(               /* create modified file name */
311 >        char    *orig,
312 >        int     pred
313 > )
314   {
315          register char   *cp;
316          register int    n;
# Line 273 | Line 332 | int    pred;
332   }
333  
334  
335 < checkfiles()                    /* check for existence and modified times */
335 > static void
336 > checkfiles(void)                        /* check for existence and modified times */
337   {
338          time_t  objdate;
339  
# Line 308 | Line 368 | checkfiles()                   /* check for existence and modified tim
368   }      
369  
370  
371 < getoctcube(org, sizp)           /* get octree bounding cube */
372 < double  org[3], *sizp;
371 > static void
372 > getoctcube(             /* get octree bounding cube */
373 >        double  org[3],
374 >        double  *sizp
375 > )
376   {
314        extern FILE     *popen();
377          static double   oorg[3], osiz = 0.;
378          double  min[3], max[3];
379          char    buf[1024];
# Line 359 | Line 421 | double org[3], *sizp;
421   }
422  
423  
424 < setdefaults()                   /* set default values for unassigned var's */
424 > static void
425 > setdefaults(void)                       /* set default values for unassigned var's */
426   {
427          double  org[3], lim[3], size;
428          char    buf[128];
# Line 416 | Line 479 | setdefaults()                  /* set default values for unassigned v
479   }
480  
481  
482 < oconv()                         /* run oconv and mkillum if necessary */
482 > static void
483 > oconv(void)                             /* run oconv and mkillum if necessary */
484   {
485          static char     illumtmp[] = "ilXXXXXX";
486 <        char    combuf[PATH_MAX], ocopts[64], mkopts[64];
486 >        char    combuf[PATH_MAX], ocopts[64], mkopts[1024];
487  
488          oconvopts(ocopts);              /* get options */
489          if (octreedate < scenedate) {   /* check date on original octree */
# Line 427 | Line 491 | oconv()                                /* run oconv and mkillum if necessary */
491                          touch(vval(OCTREE));
492                  else {                          /* build command */
493                          if (vdef(MATERIAL))
494 <                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
495 <                                                vval(MATERIAL), vval(SCENE),
496 <                                                vval(OCTREE));
494 >                                sprintf(combuf, "%s%s %s %s > %s", c_oconv,
495 >                                                ocopts, vval(MATERIAL),
496 >                                                vval(SCENE), vval(OCTREE));
497                          else
498 <                                sprintf(combuf, "oconv%s %s > %s", ocopts,
498 >                                sprintf(combuf, "%s%s %s > %s", c_oconv, ocopts,
499                                                  vval(SCENE), vval(OCTREE));
500                          
501                          if (runcom(combuf)) {           /* run it */
# Line 457 | Line 521 | oconv()                                /* run oconv and mkillum if necessary */
521                          touch(oct0name);
522                  else {                          /* build command */
523                          if (octreedate)
524 <                                sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
525 <                                        vval(OCTREE), vval(ILLUM), oct0name);
524 >                                sprintf(combuf, "%s%s -i %s %s > %s", c_oconv,
525 >                                        ocopts, vval(OCTREE),
526 >                                        vval(ILLUM), oct0name);
527                          else if (vdef(MATERIAL))
528 <                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
529 <                                        vval(MATERIAL), vval(ILLUM), oct0name);
465 <                        else
466 <                                sprintf(combuf, "oconv%s %s > %s", ocopts,
528 >                                sprintf(combuf, "%s%s %s %s > %s", c_oconv,
529 >                                        ocopts, vval(MATERIAL),
530                                          vval(ILLUM), oct0name);
531 +                        else
532 +                                sprintf(combuf, "%s%s %s > %s", c_oconv,
533 +                                        ocopts, vval(ILLUM), oct0name);
534                          if (runcom(combuf)) {           /* run it */
535                                  fprintf(stderr,
536                                  "%s: error generating octree\n\t%s removed\n",
# Line 484 | Line 550 | oconv()                                /* run oconv and mkillum if necessary */
550          else {
551                  mkillumopts(mkopts);            /* build mkillum command */
552                  mktemp(illumtmp);
553 <                sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
553 >                sprintf(combuf, "%s%s %s \"<\" %s > %s", c_mkillum, mkopts,
554                                  oct0name, vval(ILLUM), illumtmp);
555                  if (runcom(combuf)) {                   /* run it */
556 <                        fprintf(stderr, "%s: error running mkillum\n",
557 <                                        progname);
556 >                        fprintf(stderr, "%s: error running %s\n",
557 >                                        progname, c_mkillum);
558                          unlink(illumtmp);
559                          quit(1);
560                  }
561                                                  /* make octree1 (frozen) */
562                  if (octreedate)
563 <                        sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
564 <                                vval(OCTREE), illumtmp, oct1name);
563 >                        sprintf(combuf, "%s%s -f -i %s %s > %s", c_oconv,
564 >                                ocopts, vval(OCTREE), illumtmp, oct1name);
565                  else if (vdef(MATERIAL))
566 <                        sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
567 <                                vval(MATERIAL), illumtmp, oct1name);
566 >                        sprintf(combuf, "%s%s -f %s %s > %s", c_oconv,
567 >                                ocopts, vval(MATERIAL), illumtmp, oct1name);
568                  else
569 <                        sprintf(combuf, "oconv%s -f %s > %s", ocopts,
569 >                        sprintf(combuf, "%s%s -f %s > %s", c_oconv, ocopts,
570                                  illumtmp, oct1name);
571                  if (runcom(combuf)) {           /* run it */
572                          fprintf(stderr,
# Line 518 | Line 584 | oconv()                                /* run oconv and mkillum if necessary */
584   }
585  
586  
587 < char *
588 < addarg(op, arg)                         /* add argument and advance pointer */
589 < register char   *op, *arg;
587 > static char *
588 > addarg(                         /* append argument and advance pointer */
589 > register char   *op,
590 > register char   *arg
591 > )
592   {
593 +        while (*op)
594 +                op++;
595          *op = ' ';
596          while ( (*++op = *arg++) )
597                  ;
# Line 529 | Line 599 | register char  *op, *arg;
599   }
600  
601  
602 < oconvopts(oo)                           /* get oconv options */
603 < register char   *oo;
602 > static void
603 > oconvopts(                              /* get oconv options */
604 >        register char   *oo
605 > )
606   {
607          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
608  
609          *oo = '\0';
610          if (vdef(OCONV))
611 <                addarg(oo, vval(OCONV));
611 >                if (vval(OCONV)[0] != '-') {
612 >                        atos(c_oconv, sizeof(c_oconv), vval(OCONV));
613 >                        oo = addarg(oo, sskip2(vval(OCONV), 1));
614 >                } else
615 >                        oo = addarg(oo, vval(OCONV));
616   }
617  
618  
619 < mkillumopts(mo)                         /* get mkillum options */
620 < register char   *mo;
619 > static void
620 > mkillumopts(                            /* get mkillum options */
621 >        char    *mo
622 > )
623   {
624          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
625  
626 <        *mo = '\0';
626 >        if (nprocs > 1)
627 >                sprintf(mo, " -n %d", nprocs);
628 >        else
629 >                *mo = '\0';
630          if (vdef(MKILLUM))
631 <                addarg(mo, vval(MKILLUM));
631 >                if (vval(MKILLUM)[0] != '-') {
632 >                        atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM));
633 >                        mo = addarg(mo, sskip2(vval(MKILLUM), 1));
634 >                } else
635 >                        mo = addarg(mo, vval(MKILLUM));
636   }
637  
638  
639 < checkambfile()                  /* check date on ambient file */
639 > static void
640 > checkambfile(void)                      /* check date on ambient file */
641   {
642          time_t  afdate;
643  
# Line 568 | Line 654 | checkambfile()                 /* check date on ambient file */
654   }
655  
656  
657 < double
658 < ambval()                                /* compute ambient value */
657 > static double
658 > ambval(void)                            /* compute ambient value */
659   {
660          if (vdef(EXPOSURE)) {
661                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
# Line 581 | Line 667 | ambval()                               /* compute ambient value */
667          if (vlet(ZONE) == 'I')
668                  return(.01);
669          badvalue(ZONE);
670 +        return 0; /* pro forma return */
671   }
672  
673  
674 < renderopts(op, po)                      /* set rendering options */
675 < char    *op, *po;
674 > static void
675 > renderopts(                     /* set rendering options */
676 >        char    *op,
677 >        char    *po
678 > )
679   {
680          switch(vscale(QUALITY)) {
681          case LOW:
# Line 598 | Line 688 | char   *op, *po;
688                  hiqopts(op, po);
689                  break;
690          }
691 +        if (vdef(RENDER))
692 +                op = addarg(op, vval(RENDER));
693 +        if (rvdevice != NULL) {
694 +                if (vdef(RVU))
695 +                        if (vval(RVU)[0] != '-') {
696 +                                atos(c_rvu, sizeof(c_rvu), vval(RVU));
697 +                                po = addarg(po, sskip2(vval(RVU), 1));
698 +                        } else
699 +                                po = addarg(po, vval(RVU));
700 +        } else {
701 +                if (vdef(RPICT))
702 +                        if (vval(RPICT)[0] != '-') {
703 +                                atos(c_rpict, sizeof(c_rpict), vval(RPICT));
704 +                                po = addarg(po, sskip2(vval(RPICT), 1));
705 +                        } else
706 +                                po = addarg(po, vval(RPICT));
707 +        }
708   }
709  
710  
711 < lowqopts(op, po)                        /* low quality rendering options */
712 < register char   *op;
713 < char    *po;
711 > static void
712 > lowqopts(                       /* low quality rendering options */
713 >        register char   *op,
714 >        char    *po
715 > )
716   {
717          double  d, org[3], siz[3];
718  
# Line 664 | Line 773 | char   *po;
773          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
774          op += strlen(op);
775          op = addarg(op, "-lr 6 -lw .01");
667        if (vdef(RENDER))
668                op = addarg(op, vval(RENDER));
776   }
777  
778  
779 < medqopts(op, po)                        /* medium quality rendering options */
780 < register char   *op;
781 < char    *po;
779 > static void
780 > medqopts(                       /* medium quality rendering options */
781 >        register char   *op,
782 >        char    *po
783 > )
784   {
785          double  d, org[3], siz[3], asz;
786  
# Line 714 | Line 823 | char   *po;
823          }
824          po = addarg(po, "-pt .08");
825          if (vbool(PENUMBRAS))
826 <                op = addarg(op, "-ds .2 -dj .5");
826 >                op = addarg(op, "-ds .2 -dj .9");
827          else
828                  op = addarg(op, "-ds .3");
829          op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
# Line 742 | Line 851 | char   *po;
851          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
852          op += strlen(op);
853          op = addarg(op, "-lr 8 -lw .002");
745        if (vdef(RENDER))
746                op = addarg(op, vval(RENDER));
854   }
855  
856  
857 < hiqopts(op, po)                         /* high quality rendering options */
858 < register char   *op;
859 < char    *po;
857 > static void
858 > hiqopts(                                /* high quality rendering options */
859 >        register char   *op,
860 >        char    *po
861 > )
862   {
863          double  d, org[3], siz[3], asz;
864  
# Line 792 | Line 901 | char   *po;
901          }
902          po = addarg(po, "-pt .04");
903          if (vbool(PENUMBRAS))
904 <                op = addarg(op, "-ds .1 -dj .65");
904 >                op = addarg(op, "-ds .1 -dj .9");
905          else
906                  op = addarg(op, "-ds .2");
907          op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
# Line 818 | Line 927 | char   *po;
927          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
928          op += strlen(op);
929          op = addarg(op, "-lr 12 -lw .0005");
821        if (vdef(RENDER))
822                op = addarg(op, vval(RENDER));
930   }
931  
932  
933 < xferopts(ro)                            /* transfer options if indicated */
934 < char    *ro;
933 > static void
934 > xferopts(                               /* transfer options if indicated */
935 >        char    *ro
936 > )
937   {
938          int     fd, n;
939          register char   *cp;
# Line 854 | Line 963 | char   *ro;
963   }
964  
965  
966 < pfiltopts(po)                           /* get pfilt options */
967 < register char   *po;
966 > static void
967 > pfiltopts(                              /* get pfilt options */
968 >        register char   *po
969 > )
970   {
971          *po = '\0';
972          if (vdef(EXPOSURE)) {
# Line 871 | Line 982 | register char  *po;
982                  break;
983          }
984          if (vdef(PFILT))
985 <                po = addarg(po, vval(PFILT));
985 >                if (vval(PFILT)[0] != '-') {
986 >                        atos(c_pfilt, sizeof(c_pfilt), vval(PFILT));
987 >                        po = addarg(po, sskip2(vval(PFILT), 1));
988 >                } else
989 >                        po = addarg(po, vval(PFILT));
990   }
991  
992  
993 < matchword(s1, s2)                       /* match white-delimited words */
994 < register char   *s1, *s2;
993 > static int
994 > matchword(                      /* match white-delimited words */
995 >        register char   *s1,
996 >        register char   *s2
997 > )
998   {
999          while (isspace(*s1)) s1++;
1000          while (isspace(*s2)) s2++;
# Line 887 | Line 1005 | register char  *s1, *s2;
1005   }
1006  
1007  
1008 < char *
1009 < specview(vs)                            /* get proper view spec from vs */
1010 < register char   *vs;
1008 > static char *
1009 > specview(                               /* get proper view spec from vs */
1010 >        register char   *vs
1011 > )
1012   {
1013          static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
1014                          "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
# Line 929 | Line 1048 | register char  *vs;
1048          } else if (*vs == 'z') {
1049                  zpos = -1; vs++;
1050          }
1051 <        viewtype = 'v';
1052 <        if((*vs == 'v') | (*vs == 'l') | (*vs == 'a') | (*vs == 'h') | (*vs == 'c'))
1051 >        switch (*vs) {
1052 >        case VT_PER:
1053 >        case VT_PAR:
1054 >        case VT_ANG:
1055 >        case VT_HEM:
1056 >        case VT_PLS:
1057 >        case VT_CYL:
1058                  viewtype = *vs++;
1059 +                break;
1060 +        default:
1061 +                viewtype = VT_PER;
1062 +                break;
1063 +        }
1064          cp = viewopts;
1065          if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
1066                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
# Line 973 | Line 1102 | register char  *vs;
1102                  }
1103                  cp = addarg(cp, vup[upax+3]);
1104                  switch (viewtype) {
1105 <                case 'v':
1105 >                case VT_PER:
1106                          cp = addarg(cp, "-vh 45 -vv 45");
1107                          break;
1108 <                case 'l':
1108 >                case VT_PAR:
1109                          d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
1110                          sprintf(cp, " -vh %.2g -vv %.2g", d, d);
1111                          cp += strlen(cp);
1112                          break;
1113 <                case 'a':
1114 <                case 'h':
1113 >                case VT_ANG:
1114 >                case VT_HEM:
1115 >                case VT_PLS:
1116                          cp = addarg(cp, "-vh 180 -vv 180");
1117                          break;
1118 <                case 'c':
1118 >                case VT_CYL:
1119                          cp = addarg(cp, "-vh 180 -vv 90");
1120                          break;
1121                  }
# Line 993 | Line 1123 | register char  *vs;
1123                  while (!isspace(*vs))           /* else skip id */
1124                          if (!*vs++)
1125                                  return(NULL);
1126 <                if (upax) {                     /* specify up vector */
1126 >                if (upax) {                     /* prepend up vector */
1127                          strcpy(cp, vup[upax+3]);
1128                          cp += strlen(cp);
1129                  }
# Line 1011 | Line 1141 | register char  *vs;
1141   }
1142  
1143  
1144 < char *
1145 < getview(n, vn)                          /* get view n, or NULL if none */
1146 < int     n;
1147 < char    *vn;            /* returned view name */
1144 > static char *
1145 > getview(                                /* get view n, or NULL if none */
1146 >        int     n,
1147 >        char    *vn             /* returned view name */
1148 > )
1149   {
1150          register char   *mv;
1151  
1152          if (viewselect != NULL) {               /* command-line selected */
1153                  if (n)                          /* only do one */
1154                          return(NULL);
1155 +                                        
1156 +                if (isint(viewselect)) {        /* view number? */
1157 +                        n = atoi(viewselect)-1;
1158 +                        goto numview;
1159 +                }
1160                  if (viewselect[0] == '-') {     /* already specified */
1161 <                        if (vn != NULL) *vn = '\0';
1161 >                        if (vn != NULL)
1162 >                                strcpy(vn, "0");
1163                          return(viewselect);
1164                  }
1165                  if (vn != NULL) {
# Line 1031 | Line 1168 | char   *vn;            /* returned view name */
1168                                  ;
1169                          *vn = '\0';
1170                  }
1034                                                /* view number? */
1035                if (isint(viewselect))
1036                        return(specview(nvalue(VIEWS, atoi(viewselect)-1)));
1171                                                  /* check list */
1172                  while ((mv = nvalue(VIEWS, n++)) != NULL)
1173                          if (matchword(viewselect, mv))
1174                                  return(specview(mv));
1175 +
1176                  return(specview(viewselect));   /* standard view? */
1177          }
1178 + numview:
1179          mv = nvalue(VIEWS, n);          /* use view n */
1180 <        if ((vn != NULL) & (mv != NULL)) {
1181 <                register char   *mv2 = mv;
1182 <                if (*mv2 != '-')
1180 >        if ((vn != NULL) & (mv != NULL))
1181 >                if (*mv != '-') {
1182 >                        register char   *mv2 = mv;
1183                          while (*mv2 && !isspace(*mv2))
1184                                  *vn++ = *mv2++;
1185 <                *vn = '\0';
1186 <        }
1185 >                        *vn = '\0';
1186 >                } else
1187 >                        sprintf(vn, "%d", n+1);
1188 >
1189          return(specview(mv));
1190   }
1191  
1192  
1193 < int
1194 < myprintview(vopts, fp)                  /* print out selected view */
1195 < register char   *vopts;
1196 < FILE    *fp;
1193 > static int
1194 > myprintview(                    /* print out selected view */
1195 >        register char   *vopts,
1196 >        FILE    *fp
1197 > )
1198   {
1199          VIEW    vwr;
1200          char    buf[128];
1201          register char   *cp;
1202 + #ifdef _WIN32
1203 + /* XXX Should we allow something like this for all platforms? */
1204 + /* XXX Or is it still required at all? */
1205   again:
1206 + #endif
1207          if (vopts == NULL)
1208                  return(-1);
1209   #ifdef _WIN32
# Line 1083 | Line 1226 | again:
1226   }
1227  
1228  
1229 < rview(opts, po)                         /* run rview with first view */
1230 < char    *opts, *po;
1229 > static void
1230 > rvu(                            /* run rvu with first view */
1231 >        char    *opts,
1232 >        char    *po
1233 > )
1234   {
1235          char    *vw;
1236          char    combuf[PATH_MAX];
# Line 1093 | Line 1239 | char   *opts, *po;
1239                  return;
1240          if (sayview)
1241                  myprintview(vw, stdout);
1242 <        sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1242 >        sprintf(combuf, "%s %s%s%s -R %s ", c_rvu, vw, opts, po, rifname);
1243 >        if (nprocs > 1)
1244 >                sprintf(combuf+strlen(combuf), "-n %d ", nprocs);
1245          if (rvdevice != NULL)
1246                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1247          if (vdef(EXPOSURE))
1248                  sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1249          strcat(combuf, oct1name);
1250          if (runcom(combuf)) {           /* run it */
1251 <                fprintf(stderr, "%s: error running rview\n", progname);
1251 >                fprintf(stderr, "%s: error running %s\n", progname, c_rvu);
1252                  quit(1);
1253          }
1254   }
1255  
1256  
1257 < rpict(opts, po)                         /* run rpict and pfilt for each view */
1258 < char    *opts, *po;
1257 > static void
1258 > rpict(                          /* run rpict and pfilt for each view */
1259 >        char    *opts,
1260 >        char    *po
1261 > )
1262   {
1263 <        char    combuf[PATH_MAX];
1263 > #define do_rpiece       (sfile[0]!='\0')
1264 >        char    combuf[4*PATH_MAX+512];
1265          char    rawfile[PATH_MAX], picfile[PATH_MAX];
1266          char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1267 <        char    rppopt[128], *pfile = NULL;
1267 >        char    rppopt[128], sfile[64], *pfile = NULL;
1268          char    pfopts[128];
1269          char    vs[32], *vw;
1270          int     vn, mult;
# Line 1159 | Line 1311 | char   *opts, *po;
1311                          badvalue(REPORT);
1312          }
1313                                          /* set up parallel rendering */
1314 <        if ((nprocs > 1) & (!vdef(ZFILE))) {
1315 <                strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1316 <                pfile = rppopt+9;
1314 >        sfile[0] = '\0';
1315 >        if ((nprocs > 1) & !touchonly & !vdef(ZFILE) &&
1316 >                                        getview(0, vs) != NULL) {
1317 >                if (!strcmp(c_rpict, DEF_RPICT_PATH) &&
1318 >                                getview(1, NULL) == NULL) {
1319 >                        sprintf(sfile, "rpiece_%s.txt", vs);
1320 >                        strcpy(rppopt, "-PP pfXXXXXX");
1321 >                } else {
1322 >                        strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1323 >                }
1324 >                pfile = rppopt + strlen(rppopt) - 8;
1325                  if (mktemp(pfile) == NULL)
1326 <                        pfile = NULL;
1326 >                        if (do_rpiece) {
1327 >                                fprintf(stderr, "%s: cannot create\n", pfile);
1328 >                                quit(1);
1329 >                        } else
1330 >                                pfile = NULL;
1331          }
1332          vn = 0;                                 /* do each view */
1333          while ((vw = getview(vn++, vs)) != NULL) {
1334                  if (sayview)
1335                          myprintview(vw, stdout);
1336 <                if (!vs[0])
1173 <                        sprintf(vs, "%d", vn);
1174 <                sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1336 >                sprintf(picfile, "%s_%s.hdr", vval(PICTURE), vs);
1337                  if (vdef(ZFILE))
1338                          sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1339                  else
# Line 1192 | Line 1354 | char   *opts, *po;
1354                                  touch(picfile);
1355                          continue;
1356                  }
1357 <                if (next_process()) {           /* parallel running? */
1357 >                                                /* parallel running? */
1358 >                if (do_rpiece) {
1359 >                        if (rfdt < oct1date || fdate(sfile) < oct1date) {
1360 >                                rfdt = 0;               /* start fresh */
1361 >                                if ((fp = fopen(sfile, "w")) == NULL) {
1362 >                                        fprintf(stderr, "%s: cannot create\n",
1363 >                                                        sfile);
1364 >                                        quit(1);
1365 >                                }
1366 >                                fprintf(fp, "%d %d\n", 8+nprocs/3, 8+nprocs/3);
1367 >                                fclose(fp);
1368 >                        }
1369 >                } else if (next_process()) {
1370                          if (pfile != NULL)
1371 <                                sleep(20);
1371 >                                sleep(10);
1372                          continue;
1373 <                }
1373 >                } else if (!inchild())
1374 >                        pfile = NULL;
1375                  /* XXX Remember to call finish_process() */
1376                                                  /* build rpict command */
1377 <                if (rfdt >= oct1date) {         /* recover */
1378 <                        sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1379 <                                rep, po, opts, zopt, rawfile, oct1name);
1380 <                        if (runcom(combuf))     /* run rpict */
1377 >                if (rfdt >= oct1date) {         /* already in progress */
1378 >                        if (do_rpiece) {
1379 >                                sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s",
1380 >                                                c_rpiece, sfile, rppopt, rep, vw,
1381 >                                                res, opts, po, rawfile, oct1name);
1382 >                                while (children_running < nprocs-1 &&
1383 >                                                        next_process()) {
1384 >                                        sleep(10);
1385 >                                        combuf[strlen(c_rpiece)+2] = 'F';
1386 >                                }
1387 >                        } else
1388 >                                sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict,
1389 >                                        rep, opts, po, zopt, rawfile, oct1name);
1390 >                        if (runcom(combuf))     /* run rpict/rpiece */
1391                                  goto rperror;
1392                  } else {
1393                          if (overture) {         /* run overture calculation */
1394                                  sprintf(combuf,
1395 <                                "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1396 <                                                rep, vw, opts,
1395 >                                "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1396 >                                                c_rpict, rep, vw, opts,
1397                                                  oct1name, overfile);
1398                                  if (runcom(combuf)) {
1399                                          fprintf(stderr,
# Line 1220 | Line 1405 | char   *opts, *po;
1405                                  rmfile(overfile);
1406   #endif
1407                          }
1408 <                        sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1409 <                                        rep, vw, res, po, opts,
1410 <                                        zopt, oct1name, rawfile);
1411 <                        if (pfile != NULL && inchild()) {
1412 <                                                /* rpict persistent mode */
1408 >                        if (do_rpiece) {
1409 >                                sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s",
1410 >                                                c_rpiece, sfile, rppopt, rep, vw,
1411 >                                                res, opts, po, rawfile, oct1name);
1412 >                                while (children_running < nprocs-1 &&
1413 >                                                        next_process())
1414 >                                        sleep(10);
1415 >                        } else {
1416 >                                sprintf(combuf, "%s%s %s %s%s%s%s %s > %s",
1417 >                                                c_rpict, rep, vw, res, opts, po,
1418 >                                                zopt, oct1name, rawfile);
1419 >                        }
1420 >                        if ((pfile != NULL) & !do_rpiece) {
1421                                  if (!silent)
1422                                          printf("\t%s\n", combuf);
1230                                sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1231                                                rep, rppopt, res, po, opts,
1232                                                oct1name, rawfile);
1423                                  fflush(stdout);
1424 +                                sprintf(combuf, "%s%s %s %s%s%s %s > %s",
1425 +                                                c_rpict, rep, rppopt, res,
1426 +                                                opts, po, oct1name, rawfile);
1427                                  fp = popen(combuf, "w");
1428                                  if (fp == NULL)
1429                                          goto rperror;
1430                                  myprintview(vw, fp);
1431                                  if (pclose(fp))
1432                                          goto rperror;
1433 <                        } else {                /* rpict normal mode */
1434 <                                if (runcom(combuf))
1242 <                                        goto rperror;
1243 <                        }
1433 >                        } else if (runcom(combuf))
1434 >                                goto rperror;
1435                  }
1436 +                if (do_rpiece) {                /* need to finish raw, first */
1437 +                        finish_process();
1438 +                        wait_process(1);
1439 +                        /* XXX should check sync file to see if really done? */
1440 +                }
1441                  if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1442                                                  /* build pfilt command */
1443                          if (mult > 1)
1444 <                                sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1445 <                                        pfopts, mult, mult, rawfile, picfile);
1444 >                                sprintf(combuf, "%s%s -x /%d -y /%d %s > %s",
1445 >                                        c_pfilt, pfopts, mult, mult,
1446 >                                        rawfile, picfile);
1447                          else
1448 <                                sprintf(combuf, "pfilt%s %s > %s", pfopts,
1449 <                                                rawfile, picfile);
1448 >                                sprintf(combuf, "%s%s %s > %s", c_pfilt,
1449 >                                        pfopts, rawfile, picfile);
1450                          if (runcom(combuf)) {   /* run pfilt */
1451                                  fprintf(stderr,
1452                                  "%s: error filtering view %s\n\t%s removed\n",
# Line 1260 | Line 1457 | char   *opts, *po;
1457                  }
1458                                                  /* remove/rename raw file */
1459                  if (vdef(RAWFILE)) {
1460 <                        sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1460 >                        sprintf(combuf, "%s_%s.hdr", vval(RAWFILE), vs);
1461                          mvfile(rawfile, combuf);
1462                  } else
1463                          rmfile(rawfile);
1464 <                finish_process();               /* leave if child */
1464 >                if (do_rpiece)                  /* done with sync file */
1465 >                        rmfile(sfile);
1466 >                else
1467 >                        finish_process();       /* exit if child */
1468          }
1469          wait_process(1);                /* wait for children to finish */
1470          if (pfile != NULL) {            /* clean up rpict persistent mode */
1471 <                int     pid;
1471 >                RT_PID  pid;
1472                  fp = fopen(pfile, "r");
1473                  if (fp != NULL) {
1474                          if (fscanf(fp, "%*s %d", &pid) != 1 ||
1475 <                                        kill(pid, 1) == -1)
1475 >                                        kill(pid, 1) < 0)
1476                                  unlink(pfile);
1477                          fclose(fp);
1478                  }
# Line 1281 | Line 1481 | char   *opts, *po;
1481   rperror:
1482          fprintf(stderr, "%s: error rendering view %s\n", progname, vs);
1483          quit(1);
1484 + #undef do_rpiece
1485   }
1486  
1487  
1488 < touch(fn)                       /* update a file */
1489 < char    *fn;
1488 > static int
1489 > touch(                  /* update a file */
1490 >        char    *fn
1491 > )
1492   {
1493          if (!silent)
1494                  printf("\ttouch %s\n", fn);
# Line 1300 | Line 1503 | char   *fn;
1503   }
1504  
1505  
1506 < runcom(cs)                      /* run command */
1507 < char    *cs;
1506 > static int
1507 > runcom(                 /* run command */
1508 >        char    *cs
1509 > )
1510   {
1511          if (!silent)            /* echo it */
1512                  printf("\t%s\n", cs);
1513          if (!nprocs)
1514                  return(0);
1515 <        fflush(stdout);         /* flush output and pass to shell */
1515 >        fflush(NULL);           /* flush output and pass to shell */
1516          return(system(cs));
1517   }
1518  
1519  
1520 < rmfile(fn)                      /* remove a file */
1521 < char    *fn;
1520 > static int
1521 > rmfile(                 /* remove a file */
1522 >        char    *fn
1523 > )
1524   {
1525          if (!silent)
1526                  printf("\t%s %s\n", DELCMD, fn);
# Line 1323 | Line 1530 | char   *fn;
1530   }
1531  
1532  
1533 < mvfile(fold, fnew)              /* move a file */
1534 < char    *fold, *fnew;
1533 > static int
1534 > mvfile(         /* move a file */
1535 >        char    *fold,
1536 >        char    *fnew
1537 > )
1538   {
1539          if (!silent)
1540                  printf("\t%s %s %s\n", RENAMECMD, fold, fnew);
# Line 1335 | Line 1545 | char   *fold, *fnew;
1545  
1546  
1547   #ifdef RHAS_FORK_EXEC
1548 < int
1549 < next_process()                  /* fork the next process (max. nprocs) */
1548 > static int
1549 > next_process(void)                      /* fork the next process (max. nprocs) */
1550   {
1551 <        int     child_pid;
1551 >        RT_PID  child_pid;
1552  
1553          if (nprocs <= 1)
1554                  return(0);              /* it's us or no one */
1555          if (inchild()) {
1556 <                fprintf(stderr, "%s: internal error 1 in spawn_process()\n",
1556 >                fprintf(stderr, "%s: internal error 1 in next_process()\n",
1557                                  progname);
1558                  quit(1);
1559          }
1560          if (children_running >= nprocs)
1561                  wait_process(0);        /* wait for someone to finish */
1562 <        fflush(stdout);
1562 >        fflush(NULL);                   /* flush output */
1563          child_pid = fork();             /* split process */
1564          if (child_pid == 0) {           /* we're the child */
1565                  children_running = -1;
# Line 1363 | Line 1573 | next_process()                 /* fork the next process (max. nprocs
1573          return(0);
1574   }
1575  
1576 < wait_process(all)                       /* wait for process(es) to finish */
1577 < int     all;
1576 > static void
1577 > wait_process(                   /* wait for process(es) to finish */
1578 >        int     all
1579 > )
1580   {
1581 <        int     ourstatus = 0;
1582 <        int     pid, status;
1581 >        int     ourstatus = 0, status;
1582 >        RT_PID  pid;
1583  
1584          if (all)
1585                  all = children_running;
# Line 1391 | Line 1603 | int    all;
1603                  quit(ourstatus);        /* bad status from child */
1604   }
1605   #else   /* ! RHAS_FORK_EXEC */
1606 < int
1607 < next_process()
1606 > static int
1607 > next_process(void)
1608   {
1609          return(0);                      /* cannot start new process */
1610   }
1611 + static void
1612   wait_process(all)
1613   int     all;
1614   {
# Line 1403 | Line 1616 | int    all;
1616   }
1617   int
1618   kill(pid, sig) /* win|unix_process.c should also wait and kill */
1619 < int pid, sig;
1619 > RT_PID pid;
1620 > int sig;
1621   {
1622          return 0;
1623   }
1624   #endif  /* ! RHAS_FORK_EXEC */
1625  
1626 < finish_process()                        /* exit a child process */
1626 > static void
1627 > finish_process(void)                    /* exit a child process */
1628   {
1629          if (!inchild())
1630                  return;                 /* in parent -- noop */
# Line 1436 | Line 1651 | char   *vname, *value;
1651   #endif
1652  
1653  
1654 < badvalue(vc)                    /* report bad variable value and exit */
1655 < int     vc;
1654 > static void
1655 > badvalue(                       /* report bad variable value and exit */
1656 >        int     vc
1657 > )
1658   {
1659          fprintf(stderr, "%s: bad value for variable '%s'\n",
1660                          progname, vnam(vc));
# Line 1445 | Line 1662 | int    vc;
1662   }
1663  
1664  
1665 < syserr(s)                       /* report a system error and exit */
1666 < char    *s;
1665 > static void
1666 > syserr(                 /* report a system error and exit */
1667 >        char    *s
1668 > )
1669   {
1670          perror(s);
1671          quit(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines