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.105 by greg, Fri Feb 25 06:51:51 2011 UTC vs.
Revision 2.126 by greg, Tue Feb 26 23:31:11 2019 UTC

# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9  
10   #include <ctype.h>
11   #include <time.h>
12 + #include <signal.h>
13  
14   #include "platform.h"
15   #include "rtprocess.h"
# Line 16 | Line 17 | static const char      RCSid[] = "$Id$";
17   #include "paths.h"
18   #include "vars.h"
19  
20 < #ifdef _WIN32
20 > #if defined(_WIN32) || defined(_WIN64)
21    #define DELCMD "del"
22    #define RENAMECMD "rename"
23   #else
# Line 24 | Line 25 | static const char      RCSid[] = "$Id$";
25    #define RENAMECMD "mv"
26    #include <sys/types.h>
27    #include <sys/wait.h>
28 +  #include <signal.h>
29   #endif
30  
31                                  /* variables (alphabetical by name) */
# Line 35 | Line 37 | static const char      RCSid[] = "$Id$";
37   #define INDIRECT        5               /* indirection in lighting */
38   #define MATERIAL        6               /* material files */
39   #define MKILLUM         7               /* mkillum options */
40 < #define OBJECT          8               /* object files */
41 < #define OCONV           9               /* oconv options */
42 < #define OCTREE          10              /* octree file name */
43 < #define OPTFILE         11              /* rendering options file */
44 < #define PENUMBRAS       12              /* shadow penumbras are desired */
45 < #define PFILT           13              /* pfilt options */
46 < #define PICTURE         14              /* picture file root name */
47 < #define QUALITY         15              /* desired rendering quality */
48 < #define RAWFILE         16              /* raw picture file root name */
49 < #define RENDER          17              /* rendering options */
50 < #define REPORT          18              /* report frequency and errfile */
51 < #define RESOLUTION      19              /* maximum picture resolution */
52 < #define RPICT           20              /* rpict parameters */
53 < #define RVU             21              /* rvu parameters */
54 < #define SCENE           22              /* scene files */
55 < #define UP              23              /* view up (X, Y or Z) */
56 < #define VARIABILITY     24              /* level of light variability */
57 < #define VIEWS           25              /* view(s) for picture(s) */
58 < #define ZFILE           26              /* distance file root name */
59 < #define ZONE            27              /* simulation zone */
40 > #define MKPMAP          8               /* mkpmap options */
41 > #define OBJECT          9               /* object files */
42 > #define OCONV           10              /* oconv options */
43 > #define OCTREE          11              /* octree file name */
44 > #define OPTFILE         12              /* rendering options file */
45 > #define PCMAP           13              /* caustic photon map */
46 > #define PENUMBRAS       14              /* shadow penumbras are desired */
47 > #define PFILT           15              /* pfilt options */
48 > #define PGMAP           16              /* global photon map */
49 > #define PICTURE         17              /* picture file root name */
50 > #define QUALITY         18              /* desired rendering quality */
51 > #define RAWFILE         19              /* raw picture file root name */
52 > #define RENDER          20              /* rendering options */
53 > #define REPORT          21              /* report frequency and errfile */
54 > #define RESOLUTION      22              /* maximum picture resolution */
55 > #define RPICT           23              /* rpict parameters */
56 > #define RVU             24              /* rvu parameters */
57 > #define SCENE           25              /* scene files */
58 > #define UP              26              /* view up (X, Y or Z) */
59 > #define VARIABILITY     27              /* level of light variability */
60 > #define VIEWS           28              /* view(s) for picture(s) */
61 > #define ZFILE           29              /* distance file root name */
62 > #define ZONE            30              /* simulation zone */
63                                  /* total number of variables */
64 < int NVARS = 28;
64 > int NVARS = 31;
65  
66   VARIABLE        vv[] = {                /* variable-value pairs */
67          {"AMBFILE",     3,      0,      NULL,   onevalue},
# Line 67 | Line 72 | VARIABLE       vv[] = {                /* variable-value pairs */
72          {"INDIRECT",    3,      0,      NULL,   intvalue},
73          {"materials",   3,      0,      NULL,   catvalues},
74          {"mkillum",     3,      0,      NULL,   catvalues},
75 +        {"mkpmap",      3,      0,      NULL,   catvalues},
76          {"objects",     3,      0,      NULL,   catvalues},
77          {"oconv",       3,      0,      NULL,   catvalues},
78          {"OCTREE",      3,      0,      NULL,   onevalue},
79          {"OPTFILE",     3,      0,      NULL,   onevalue},
80 +        {"PCMAP",       2,      0,      NULL,   onevalue},
81          {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
82          {"pfilt",       2,      0,      NULL,   catvalues},
83 +        {"PGMAP",       2,      0,      NULL,   onevalue},
84          {"PICTURE",     3,      0,      NULL,   onevalue},
85          {"QUALITY",     3,      0,      NULL,   qualvalue},
86          {"RAWFILE",     3,      0,      NULL,   onevalue},
# Line 107 | Line 115 | time_t oct0date;               /* date of pre-mkillum octree */
115   char    *oct1name;              /* name of post-mkillum octree */
116   time_t  oct1date;               /* date of post-mkillum octree (>= matdate) */
117  
118 + char    *pgmapname;             /* name of global photon map */
119 + time_t  pgmapdate;              /* date of global photon map (>= oct1date) */
120 + char    *pcmapname;             /* name of caustic photon map */
121 + time_t  pcmapdate;              /* date of caustic photon map (>= oct1date) */
122 +
123   int     nowarn = 0;             /* no warnings */
124   int     explicate = 0;          /* explicate variables */
125   int     silent = 0;             /* do work silently */
# Line 121 | Line 134 | char   *viewselect = NULL;     /* specific view only */
134                                  /* command paths */
135   char    c_oconv[256] = "oconv";
136   char    c_mkillum[256] = "mkillum";
137 + char    c_mkpmap[256] = "mkpmap";
138   char    c_rvu[256] = "rvu";
139   char    c_rpict[256] = DEF_RPICT_PATH;
140   char    c_rpiece[] = "rpiece";
# Line 144 | Line 158 | static void checkfiles(void);
158   static void getoctcube(double   org[3], double  *sizp);
159   static void setdefaults(void);
160   static void oconv(void);
161 + static void mkpmap(void);
162   static char * addarg(char       *op, char       *arg);
163   static void oconvopts(char      *oo);
164   static void mkillumopts(char    *mo);
165 + static void mkpmapopts(char     *mo);
166   static void checkambfile(void);
167   static double ambval(void);
168   static void renderopts(char     *op, char       *po);
# Line 243 | Line 259 | main(
259                  printvars(stdout);
260                                  /* build octree (and run mkillum) */
261          oconv();
262 +                                /* run mkpmap if indicated */
263 +        mkpmap();
264                                  /* check date on ambient file */
265          checkambfile();
266                                  /* run simulation */
# Line 264 | Line 282 | userr:
282  
283   static void
284   rootname(               /* remove tail from end of fn */
285 <        register char   *rn,
286 <        register char   *fn
285 >        char    *rn,
286 >        char    *fn
287   )
288   {
289          char    *tp, *dp;
# Line 282 | Line 300 | rootname(              /* remove tail from end of fn */
300  
301   static time_t
302   checklast(                      /* check files and find most recent */
303 <        register char   *fnames
303 >        char    *fnames
304   )
305   {
306          char    thisfile[PATH_MAX];
# Line 312 | Line 330 | newfname(              /* create modified file name */
330          int     pred
331   )
332   {
333 <        register char   *cp;
334 <        register int    n;
333 >        char    *cp;
334 >        int     n;
335          int     suffix;
336  
337          n = 0; cp = orig; suffix = -1;          /* suffix position, length */
# Line 335 | Line 353 | newfname(              /* create modified file name */
353   static void
354   checkfiles(void)                        /* check for existence and modified times */
355   {
356 +        char    fntemp[256];
357          time_t  objdate;
358  
359          if (!vdef(OCTREE)) {
# Line 364 | Line 383 | checkfiles(void)                       /* check for existence and modified
383                                  vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
384                  quit(1);
385          }
386 +        if (vdef(PGMAP)) {
387 +                if (!*sskip2(vval(PGMAP),1)) {
388 +                        fprintf(stderr, "%s: '%s' missing # photons argument\n",
389 +                                        progname, vnam(PGMAP));
390 +                        quit(1);
391 +                }
392 +                atos(fntemp, sizeof(fntemp), vval(PGMAP));
393 +                pgmapname = savqstr(fntemp);
394 +                pgmapdate = fdate(pgmapname);
395 +        }
396 +        if (vdef(PCMAP)) {
397 +                if (!*sskip2(vval(PCMAP),1)) {
398 +                        fprintf(stderr, "%s: '%s' missing # photons argument\n",
399 +                                        progname, vnam(PCMAP));
400 +                        quit(1);
401 +                }
402 +                atos(fntemp, sizeof(fntemp), vval(PCMAP));
403 +                pcmapname = savqstr(fntemp);
404 +                pcmapdate = fdate(pcmapname);
405 +        }
406          matdate = checklast(vval(MATERIAL));
407   }      
408  
# Line 378 | Line 417 | getoctcube(            /* get octree bounding cube */
417          double  min[3], max[3];
418          char    buf[1024];
419          FILE    *fp;
420 <        register int    i;
420 >        int     i;
421  
422          if (osiz <= FTINY) {
423                  if (!nprocs && fdate(oct1name) <
# Line 517 | Line 556 | oconv(void)                            /* run oconv and mkillum if necessary *
556                  return;
557                                                  /* make octree0 */
558          if ((oct0date < scenedate) | (oct0date < illumdate)) {
559 <                if (touchonly && oct0date)
560 <                        touch(oct0name);
561 <                else {                          /* build command */
559 >                if (touchonly && (oct0date || oct1date)) {
560 >                        if (oct0date)
561 >                                touch(oct0name);
562 >                } else {                        /* build command */
563                          if (octreedate)
564                                  sprintf(combuf, "%s%s -i %s %s > %s", c_oconv,
565                                          ocopts, vval(OCTREE),
# Line 544 | Line 584 | oconv(void)                            /* run oconv and mkillum if necessary *
584                          oct0date = octreedate;
585                  if (oct0date < illumdate)       /* ditto */
586                          oct0date = illumdate;
587 <                }
587 >        }
588          if (touchonly && oct1date)
589                  touch(oct1name);
590          else {
# Line 558 | Line 598 | oconv(void)                            /* run oconv and mkillum if necessary *
598                          unlink(illumtmp);
599                          quit(1);
600                  }
601 +                rmfile(oct0name);
602                                                  /* make octree1 (frozen) */
603                  if (octreedate)
604                          sprintf(combuf, "%s%s -f -i %s %s > %s", c_oconv,
# Line 584 | Line 625 | oconv(void)                            /* run oconv and mkillum if necessary *
625   }
626  
627  
628 + static void
629 + mkpmap(void)                    /* run mkpmap if indicated */
630 + {
631 +        char    combuf[2048], *cp;
632 +        time_t  tnow;
633 +                                /* nothing to do? */
634 +        if ((pgmapname == NULL) | (pgmapdate >= oct1date) &&
635 +                        (pcmapname == NULL) | (pcmapdate >= oct1date))
636 +                return;
637 +                                /* just update existing file dates? */
638 +        if (touchonly && (pgmapname == NULL) | (pgmapdate > 0) &&
639 +                        (pcmapname == NULL) | (pcmapdate > 0)) {
640 +                if (pgmapname != NULL)
641 +                        touch(pgmapname);
642 +                if (pcmapname != NULL)
643 +                        touch(pcmapname);
644 +        } else {                /* else need to (re)run pkpmap */
645 +                strcpy(combuf, c_mkpmap);
646 +                for (cp = combuf; *cp; cp++)
647 +                        ;
648 +                mkpmapopts(cp);
649 +                                /* force file overwrite */
650 +                cp = addarg(cp, "-fo+");
651 +                if (vdef(REPORT)) {
652 +                        char    errfile[256];
653 +                        int     n;
654 +                        double  minutes;
655 +                        n = sscanf(vval(REPORT), "%lf %s", &minutes, errfile);
656 +                        if (n == 2)
657 +                                sprintf(cp, " -t %d -e %s", (int)(minutes*60), errfile);
658 +                        else if (n == 1)
659 +                                sprintf(cp, " -t %d", (int)(minutes*60));
660 +                        else
661 +                                badvalue(REPORT);
662 +                }
663 +                if (pgmapname != NULL && pgmapdate < oct1date) {
664 +                        cp = addarg(cp, "-apg");
665 +                        addarg(cp, vval(PGMAP));
666 +                        cp = sskip(sskip(cp));  /* remove any bandwidth */
667 +                        *cp = '\0';
668 +                }
669 +                if (pcmapname != NULL && pcmapdate < oct1date) {
670 +                        cp = addarg(cp, "-apc");
671 +                        addarg(cp, vval(PCMAP));
672 +                        cp = sskip(sskip(cp));  /* remove any bandwidth */
673 +                        *cp = '\0';
674 +                }
675 +                cp = addarg(cp, oct1name);
676 +                if (runcom(combuf)) {
677 +                        fprintf(stderr, "%s: error running %s\n",
678 +                                        progname, c_mkpmap);
679 +                        if (pgmapname != NULL && pgmapdate < oct1date)
680 +                                unlink(pgmapname);
681 +                        if (pcmapname != NULL && pcmapdate < oct1date)
682 +                                unlink(pcmapname);
683 +                        quit(1);
684 +                }
685 +        }
686 +        tnow = time((time_t *)NULL);
687 +        if (pgmapname != NULL)
688 +                pgmapdate = tnow;
689 +        if (pcmapname != NULL)
690 +                pcmapdate = tnow;
691 +        oct1date = tnow;        /* trigger ambient file removal if needed */
692 + }
693 +
694 +
695   static char *
696   addarg(                         /* append argument and advance pointer */
697 < register char   *op,
698 < register char   *arg
697 > char    *op,
698 > char    *arg
699   )
700   {
701          while (*op)
# Line 601 | Line 709 | register char  *arg
709  
710   static void
711   oconvopts(                              /* get oconv options */
712 <        register char   *oo
712 >        char    *oo
713   )
714   {
715          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
716  
717          *oo = '\0';
718 <        if (vdef(OCONV))
719 <                if (vval(OCONV)[0] != '-') {
720 <                        atos(c_oconv, sizeof(c_oconv), vval(OCONV));
721 <                        oo = addarg(oo, sskip2(vval(OCONV), 1));
722 <                } else
723 <                        oo = addarg(oo, vval(OCONV));
718 >        if (!vdef(OCONV))
719 >                return;
720 >        if (vval(OCONV)[0] != '-') {
721 >                atos(c_oconv, sizeof(c_oconv), vval(OCONV));
722 >                oo = addarg(oo, sskip2(vval(OCONV), 1));
723 >        } else
724 >                oo = addarg(oo, vval(OCONV));
725   }
726  
727  
# Line 627 | Line 736 | mkillumopts(                           /* get mkillum options */
736                  sprintf(mo, " -n %d", nprocs);
737          else
738                  *mo = '\0';
739 <        if (vdef(MKILLUM))
740 <                if (vval(MKILLUM)[0] != '-') {
741 <                        atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM));
742 <                        mo = addarg(mo, sskip2(vval(MKILLUM), 1));
743 <                } else
744 <                        mo = addarg(mo, vval(MKILLUM));
739 >        if (!vdef(MKILLUM))
740 >                return;
741 >        if (vval(MKILLUM)[0] != '-') {
742 >                atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM));
743 >                mo = addarg(mo, sskip2(vval(MKILLUM), 1));
744 >        } else
745 >                mo = addarg(mo, vval(MKILLUM));
746   }
747  
748  
749   static void
750 + mkpmapopts(                             /* get mkpmap options */
751 +        char    *mo
752 + )
753 + {
754 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
755 +
756 +        if (nprocs > 1)
757 +                sprintf(mo, " -n %d", nprocs);
758 +        else
759 +                *mo = '\0';
760 +        if (!vdef(MKPMAP))
761 +                return;
762 +        if (vval(MKPMAP)[0] != '-') {
763 +                atos(c_mkpmap, sizeof(c_mkpmap), vval(MKPMAP));
764 +                mo = addarg(mo, sskip2(vval(MKPMAP), 1));
765 +        } else
766 +                mo = addarg(mo, vval(MKPMAP));
767 + }
768 +
769 +
770 + static void
771   checkambfile(void)                      /* check date on ambient file */
772   {
773          time_t  afdate;
# Line 677 | Line 808 | renderopts(                    /* set rendering options */
808          char    *po
809   )
810   {
811 +        char    pmapf[256], *bw;
812 +
813 +        if (vdef(PGMAP)) {
814 +                *op = '\0';
815 +                bw = sskip2(vval(PGMAP), 2);
816 +                atos(pmapf, sizeof(pmapf), vval(PGMAP));
817 +                op = addarg(addarg(op, "-ap"), pmapf);
818 +                if (atoi(bw) > 0) op = addarg(op, bw);
819 +        }
820          switch(vscale(QUALITY)) {
821          case LOW:
822                  lowqopts(op, po);
# Line 688 | Line 828 | renderopts(                    /* set rendering options */
828                  hiqopts(op, po);
829                  break;
830          }
831 +        if (vdef(PCMAP)) {
832 +                bw = sskip2(vval(PCMAP), 2);
833 +                atos(pmapf, sizeof(pmapf), vval(PCMAP));
834 +                op = addarg(addarg(op, "-ap"), pmapf);
835 +                if (atoi(bw) > 0) op = addarg(op, bw);
836 +        }
837          if (vdef(RENDER))
838                  op = addarg(op, vval(RENDER));
839          if (rvdevice != NULL) {
840 <                if (vdef(RVU))
840 >                if (vdef(RVU)) {
841                          if (vval(RVU)[0] != '-') {
842                                  atos(c_rvu, sizeof(c_rvu), vval(RVU));
843                                  po = addarg(po, sskip2(vval(RVU), 1));
844                          } else
845                                  po = addarg(po, vval(RVU));
846 +                }
847          } else {
848 <                if (vdef(RPICT))
848 >                if (vdef(RPICT)) {
849                          if (vval(RPICT)[0] != '-') {
850                                  atos(c_rpict, sizeof(c_rpict), vval(RPICT));
851                                  po = addarg(po, sskip2(vval(RPICT), 1));
852                          } else
853                                  po = addarg(po, vval(RPICT));
854 +                }
855          }
856   }
857  
858  
859   static void
860   lowqopts(                       /* low quality rendering options */
861 <        register char   *op,
861 >        char    *op,
862          char    *po
863   )
864   {
# Line 778 | Line 926 | lowqopts(                      /* low quality rendering options */
926  
927   static void
928   medqopts(                       /* medium quality rendering options */
929 <        register char   *op,
929 >        char    *op,
930          char    *po
931   )
932   {
# Line 856 | Line 1004 | medqopts(                      /* medium quality rendering options */
1004  
1005   static void
1006   hiqopts(                                /* high quality rendering options */
1007 <        register char   *op,
1007 >        char    *op,
1008          char    *po
1009   )
1010   {
# Line 930 | Line 1078 | hiqopts(                               /* high quality rendering options */
1078   }
1079  
1080  
1081 + #if defined(_WIN32) || defined(_WIN64)
1082   static void
1083 + setenv(                 /* set an environment variable */
1084 +        char    *vname,
1085 +        char    *value
1086 + )
1087 + {
1088 +        char    *evp;
1089 +
1090 +        evp = bmalloc(strlen(vname)+strlen(value)+2);
1091 +        if (evp == NULL)
1092 +                syserr(progname);
1093 +        sprintf(evp, "%s=%s", vname, value);
1094 +        if (putenv(evp) != 0) {
1095 +                fprintf(stderr, "%s: out of environment space\n", progname);
1096 +                quit(1);
1097 +        }
1098 +        if (!silent)
1099 +                printf("set %s\n", evp);
1100 + }
1101 + #endif
1102 +
1103 +
1104 + static void
1105   xferopts(                               /* transfer options if indicated */
1106          char    *ro
1107   )
1108   {
1109          int     fd, n;
1110 <        register char   *cp;
1110 >        char    *cp;
1111          
1112          n = strlen(ro);
1113          if (n < 2)
# Line 954 | Line 1125 | xferopts(                              /* transfer options if indicated */
1125                          syserr(vval(OPTFILE));
1126                  sprintf(ro, " @%s", vval(OPTFILE));
1127          }
1128 < #ifdef _WIN32
1128 > #if defined(_WIN32) || defined(_WIN64)
1129          else if (n > 50) {
1130                  setenv("ROPT", ro+1);
1131                  strcpy(ro, " $ROPT");
# Line 965 | Line 1136 | xferopts(                              /* transfer options if indicated */
1136  
1137   static void
1138   pfiltopts(                              /* get pfilt options */
1139 <        register char   *po
1139 >        char    *po
1140   )
1141   {
1142          *po = '\0';
# Line 981 | Line 1152 | pfiltopts(                             /* get pfilt options */
1152                  po = addarg(po, "-m .25");
1153                  break;
1154          }
1155 <        if (vdef(PFILT))
1155 >        if (vdef(PFILT)) {
1156                  if (vval(PFILT)[0] != '-') {
1157                          atos(c_pfilt, sizeof(c_pfilt), vval(PFILT));
1158                          po = addarg(po, sskip2(vval(PFILT), 1));
1159                  } else
1160                          po = addarg(po, vval(PFILT));
1161 +        }
1162   }
1163  
1164  
1165   static int
1166   matchword(                      /* match white-delimited words */
1167 <        register char   *s1,
1168 <        register char   *s2
1167 >        char    *s1,
1168 >        char    *s2
1169   )
1170   {
1171          while (isspace(*s1)) s1++;
# Line 1007 | Line 1179 | matchword(                     /* match white-delimited words */
1179  
1180   static char *
1181   specview(                               /* get proper view spec from vs */
1182 <        register char   *vs
1182 >        char    *vs
1183   )
1184   {
1185          static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
1186                          "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
1187          static char     viewopts[128];
1188 <        register char   *cp;
1188 >        char    *cp;
1189          int     xpos, ypos, zpos, viewtype, upax;
1190 <        register int    i;
1190 >        int     i;
1191          double  cent[3], dim[3], mult, d;
1192  
1193          if (vs == NULL || *vs == '-')
# Line 1075 | Line 1247 | specview(                              /* get proper view spec from vs */
1247                          cent[i] += .5*dim[i];
1248                  }
1249                  mult = vlet(ZONE)=='E' ? 2. : .45 ;
1250 <                sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
1250 >                sprintf(cp, " -vp %.3g %.3g %.3g -vd %.3g %.3g %.3g",
1251                                  cent[0]+xpos*mult*dim[0],
1252                                  cent[1]+ypos*mult*dim[1],
1253                                  cent[2]+zpos*mult*dim[2],
# Line 1107 | Line 1279 | specview(                              /* get proper view spec from vs */
1279                          break;
1280                  case VT_PAR:
1281                          d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
1282 <                        sprintf(cp, " -vh %.2g -vv %.2g", d, d);
1282 >                        sprintf(cp, " -vh %.3g -vv %.3g", d, d);
1283                          cp += strlen(cp);
1284                          break;
1285                  case VT_ANG:
# Line 1131 | Line 1303 | specview(                              /* get proper view spec from vs */
1303          if (cp == viewopts)             /* append any additional options */
1304                  vs++;           /* skip prefixed space if unneeded */
1305          strcpy(cp, vs);
1306 < #ifdef _WIN32
1306 > #if defined(_WIN32) || defined(_WIN64)
1307          if (strlen(viewopts) > 40) {
1308                  setenv("VIEW", viewopts);
1309                  return("$VIEW");
# Line 1147 | Line 1319 | getview(                               /* get view n, or NULL if none */
1319          char    *vn             /* returned view name */
1320   )
1321   {
1322 <        register char   *mv;
1322 >        char    *mv;
1323  
1324          if (viewselect != NULL) {               /* command-line selected */
1325                  if (n)                          /* only do one */
# Line 1177 | Line 1349 | getview(                               /* get view n, or NULL if none */
1349          }
1350   numview:
1351          mv = nvalue(VIEWS, n);          /* use view n */
1352 <        if ((vn != NULL) & (mv != NULL))
1352 >        if ((vn != NULL) & (mv != NULL)) {
1353                  if (*mv != '-') {
1354 <                        register char   *mv2 = mv;
1354 >                        char    *mv2 = mv;
1355                          while (*mv2 && !isspace(*mv2))
1356                                  *vn++ = *mv2++;
1357                          *vn = '\0';
1358                  } else
1359                          sprintf(vn, "%d", n+1);
1360 <
1360 >        }
1361          return(specview(mv));
1362   }
1363  
1364  
1365   static int
1366   myprintview(                    /* print out selected view */
1367 <        register char   *vopts,
1367 >        char    *vopts,
1368          FILE    *fp
1369   )
1370   {
1371          VIEW    vwr;
1372          char    buf[128];
1373 <        register char   *cp;
1374 < #ifdef _WIN32
1373 >        char    *cp;
1374 > #if defined(_WIN32) || defined(_WIN64)
1375   /* XXX Should we allow something like this for all platforms? */
1376   /* XXX Or is it still required at all? */
1377   again:
1378   #endif
1379          if (vopts == NULL)
1380                  return(-1);
1381 < #ifdef _WIN32
1381 > #if defined(_WIN32) || defined(_WIN64)
1382          if (vopts[0] == '$') {
1383                  vopts = getenv(vopts+1);
1384                  goto again;
# Line 1254 | Line 1426 | rvu(                           /* run rvu with first view */
1426   }
1427  
1428  
1429 + static int
1430 + syncf_done(                     /* check if an rpiece sync file is complete */
1431 +        char *sfname
1432 + )
1433 + {
1434 +        FILE    *fp = fopen(sfname, "r");
1435 +        int     todo = 1;
1436 +        int     x, y;
1437 +
1438 +        if (fp == NULL)
1439 +                return(0);
1440 +        if (fscanf(fp, "%d %d", &x, &y) != 2)
1441 +                goto checked;
1442 +        todo = x*y;             /* total number of tiles */
1443 +        if (fscanf(fp, "%d %d", &x, &y) != 2 || (x != 0) | (y != 0))
1444 +                goto checked;
1445 +                                /* XXX assume no redundant tiles */
1446 +        while (fscanf(fp, "%d %d", &x, &y) == 2)
1447 +                if (!--todo)
1448 +                        break;
1449 + checked:
1450 +        fclose(fp);
1451 +        return(!todo);
1452 + }
1453 +
1454 +
1455   static void
1456   rpict(                          /* run rpict and pfilt for each view */
1457          char    *opts,
# Line 1327 | Line 1525 | rpict(                         /* run rpict and pfilt for each view */
1525                                  fprintf(stderr, "%s: cannot create\n", pfile);
1526                                  quit(1);
1527                          }
1528 +                        pfile[-5] = '\0';
1529                          pfile = NULL;
1530                  }
1531          }
# Line 1361 | Line 1560 | rpict(                         /* run rpict and pfilt for each view */
1560                                  int     xdiv = 8+nprocs/3, ydiv = 8+nprocs/3;
1561                                  if (rfdt >= oct1date) {
1562                                          fprintf(stderr,
1563 <                "%s: partial output not created with rpiece\n", rawfile);
1563 >                "%s: partial output not created with %s\n", rawfile, c_rpiece);
1564                                          quit(1);
1565                                  }
1566                                  if (rfdt) {     /* start fresh */
# Line 1450 | Line 1649 | rpict(                         /* run rpict and pfilt for each view */
1649                  if (do_rpiece) {                /* need to finish raw, first */
1650                          finish_process();
1651                          wait_process(1);
1652 <                        /* XXX should check sync file to see if really done? */
1652 >                        if (!syncf_done(sfile)) {
1653 >                                fprintf(stderr,
1654 >                        "%s: %s did not complete rendering of view %s\n",
1655 >                                                progname, c_rpiece, vs);
1656 >                                quit(1);
1657 >                        }
1658                  }
1659                  if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1660                                                  /* build pfilt command */
# Line 1647 | Line 1851 | finish_process(void)                   /* exit a child process */
1851                  return;                 /* in parent -- noop */
1852          exit(0);
1853   }
1650
1651 #ifdef _WIN32
1652 setenv(vname, value)            /* set an environment variable */
1653 char    *vname, *value;
1654 {
1655        register char   *evp;
1656
1657        evp = bmalloc(strlen(vname)+strlen(value)+2);
1658        if (evp == NULL)
1659                syserr(progname);
1660        sprintf(evp, "%s=%s", vname, value);
1661        if (putenv(evp) != 0) {
1662                fprintf(stderr, "%s: out of environment space\n", progname);
1663                quit(1);
1664        }
1665        if (!silent)
1666                printf("set %s\n", evp);
1667 }
1668 #endif
1854  
1855  
1856   static void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines