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.61 by greg, Sat Feb 22 02:07:30 2003 UTC vs.
Revision 2.66 by greg, Thu Jul 3 15:00:19 2003 UTC

# Line 6 | Line 6 | static const char      RCSid[] = "$Id$";
6   */
7  
8   #include "standard.h"
9 +
10 + #include <ctype.h>
11 +
12 + #include "platform.h"
13   #include "view.h"
14   #include "paths.h"
15   #include "vars.h"
12 #include <ctype.h>
16  
17                                  /* variables (alphabetical by name) */
18   #define AMBFILE         0               /* ambient file name */
# Line 71 | Line 74 | VARIABLE       vv[] = {                /* variable-value pairs */
74   };
75  
76                                  /* overture calculation file */
77 < #ifdef NIX
78 < char    overfile[] = "overture.unf";
77 > #ifdef NULL_DEVICE
78 > char    overfile[] = NULL_DEVICE;
79   #else
80 < char    overfile[] = "/dev/null";
80 > char    overfile[] = "overture.unf";
81   #endif
82  
83   extern time_t   time();
# Line 93 | Line 96 | int    nowarn = 0;             /* no warnings */
96   int     explicate = 0;          /* explicate variables */
97   int     silent = 0;             /* do work silently */
98   int     touchonly = 0;          /* touch files only */
99 < int     noaction = 0;           /* don't do anything */
99 > int     nprocs = 1;             /* maximum executing processes */
100   int     sayview = 0;            /* print view out */
101   char    *rvdevice = NULL;       /* rview output device */
102   char    *viewselect = NULL;     /* specific view only */
103  
104   int     overture = 0;           /* overture calculation needed */
105  
106 + int     children_running = 0;   /* set negative in children */
107 +
108   char    *progname;              /* global argv[0] */
109   char    *rifname;               /* global rad input file name */
110  
111 < char    radname[MAXPATH];       /* root Radiance file name */
111 > char    radname[PATH_MAX];      /* root Radiance file name */
112  
113  
114   main(argc, argv)
# Line 122 | Line 127 | char   *argv[];
127                          silent++;
128                          break;
129                  case 'n':
130 <                        noaction++;
130 >                        nprocs = 0;
131                          break;
132 +                case 'N':
133 +                        nprocs = atoi(argv[++i]);
134 +                        if (nprocs < 0)
135 +                                nprocs = 0;
136 +                        break;
137                  case 't':
138                          touchonly++;
139                          break;
# Line 182 | Line 192 | char   *argv[];
192          quit(0);
193   userr:
194          fprintf(stderr,
195 < "Usage: %s [-w][-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
195 > "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
196                          progname);
197          quit(1);
198   }
# Line 207 | Line 217 | time_t
217   checklast(fnames)                       /* check files and find most recent */
218   register char   *fnames;
219   {
220 <        char    thisfile[MAXPATH];
220 >        char    thisfile[PATH_MAX];
221          time_t  thisdate, lastdate = 0;
222  
223          if (fnames == NULL)
224                  return(0);
225 <        while ((fnames = nextword(thisfile, MAXPATH, fnames)) != NULL) {
225 >        while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) {
226                  if (thisfile[0] == '!' ||
227                                  (thisfile[0] == '\\' && thisfile[1] == '!'))
228                          continue;
# Line 230 | Line 240 | newfname(orig, pred)           /* create modified file name */
240   char    *orig;
241   int     pred;
242   {
233        extern char     *rindex();
243          register char   *cp;
244          register int    n;
245          int     suffix;
# Line 297 | Line 306 | double org[3], *sizp;
306          register int    i;
307  
308          if (osiz <= FTINY)
309 <                if (noaction && fdate(oct1name) <
309 >                if (!nprocs && fdate(oct1name) <
310                                  (scenedate>illumdate?scenedate:illumdate)) {
311                                                          /* run getbbox */
312                          sprintf(buf, "getbbox -w -h %s",
# Line 396 | Line 405 | setdefaults()                  /* set default values for unassigned v
405   oconv()                         /* run oconv and mkillum if necessary */
406   {
407          static char     illumtmp[] = "ilXXXXXX";
408 <        char    combuf[1024], ocopts[64], mkopts[64];
408 >        char    combuf[PATH_MAX], ocopts[64], mkopts[64];
409  
410          oconvopts(ocopts);              /* get options */
411          if (octreedate < scenedate) {   /* check date on original octree */
# Line 821 | Line 830 | char   *ro;
830                          syserr(vval(OPTFILE));
831                  sprintf(ro, " @%s", vval(OPTFILE));
832          }
833 < #ifdef MSDOS
833 > #ifdef _WIN32
834          else if (n > 50) {
835                  setenv("ROPT", ro+1);
836                  strcpy(ro, " $ROPT");
# Line 977 | Line 986 | register char  *vs;
986          if (cp == viewopts)             /* append any additional options */
987                  vs++;           /* skip prefixed space if unneeded */
988          strcpy(cp, vs);
989 < #ifdef MSDOS
989 > #ifdef _WIN32
990          if (strlen(viewopts) > 40) {
991                  setenv("VIEW", viewopts);
992                  return("$VIEW");
# Line 1031 | Line 1040 | char   *vn;            /* returned view name */
1040   printview(vopts)                        /* print out selected view */
1041   register char   *vopts;
1042   {
1034        extern char     *strstr(), *atos(), *getenv();
1043          VIEW    vwr;
1044          char    buf[128];
1045          register char   *cp;
1046   again:
1047          if (vopts == NULL)
1048                  return(-1);
1049 < #ifdef MSDOS
1049 > #ifdef _WIN32
1050          if (vopts[0] == '$') {
1051                  vopts = getenv(vopts+1);
1052                  goto again;
# Line 1062 | Line 1070 | rview(opts, po)                                /* run rview with first view */
1070   char    *opts, *po;
1071   {
1072          char    *vw;
1073 <        char    combuf[512];
1073 >        char    combuf[PATH_MAX];
1074                                          /* build command */
1075          if (touchonly || (vw = getview(0, NULL)) == NULL)
1076                  return;
# Line 1084 | Line 1092 | char   *opts, *po;
1092   rpict(opts, po)                         /* run rpict and pfilt for each view */
1093   char    *opts, *po;
1094   {
1095 <        char    combuf[1024];
1096 <        char    rawfile[MAXPATH], picfile[MAXPATH];
1097 <        char    zopt[MAXPATH+4], rep[MAXPATH+16], res[32];
1095 >        char    combuf[PATH_MAX];
1096 >        char    rawfile[PATH_MAX], picfile[PATH_MAX];
1097 >        char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1098          char    pfopts[128];
1099          char    vs[32], *vw;
1100          int     vn, mult;
# Line 1131 | Line 1139 | char   *opts, *po;
1139                  else
1140                          badvalue(REPORT);
1141          }
1142 <                                        /* do each view */
1135 <        vn = 0;
1142 >        vn = 0;                                 /* do each view */
1143          while ((vw = getview(vn++, vs)) != NULL) {
1144                  if (sayview)
1145                          printview(vw);
# Line 1159 | Line 1166 | char   *opts, *po;
1166                                  touch(picfile);
1167                          continue;
1168                  }
1169 +                if (next_process())             /* parallel running? */
1170 +                        continue;
1171 +                /* XXX Remember to call finish_process() */
1172                                                  /* build rpict command */
1173                  if (rfdt >= oct1date)           /* recover */
1174                          sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
# Line 1175 | Line 1185 | char   *opts, *po;
1185                                                  progname, vs);
1186                                          quit(1);
1187                                  }
1188 < #ifdef NIX
1188 > #ifndef NULL_DEVICE
1189                                  rmfile(overfile);
1190   #endif
1191                          }
# Line 1210 | Line 1220 | char   *opts, *po;
1220                          mvfile(rawfile, combuf);
1221                  } else
1222                          rmfile(rawfile);
1223 +                finish_process();               /* leave if child */
1224          }
1225 +        wait_process(1);                /* wait for children to finish */
1226   }
1227  
1228  
# Line 1219 | Line 1231 | char   *fn;
1231   {
1232          if (!silent)
1233                  printf("\ttouch %s\n", fn);
1234 <        if (noaction)
1234 >        if (!nprocs)
1235                  return(0);
1236   #ifdef notused
1237          if (access(fn, F_OK) == -1)             /* create it */
# Line 1235 | Line 1247 | char   *cs;
1247   {
1248          if (!silent)            /* echo it */
1249                  printf("\t%s\n", cs);
1250 <        if (noaction)
1250 >        if (!nprocs)
1251                  return(0);
1252          fflush(stdout);         /* flush output and pass to shell */
1253          return(system(cs));
# Line 1246 | Line 1258 | rmfile(fn)                     /* remove a file */
1258   char    *fn;
1259   {
1260          if (!silent)
1261 < #ifdef MSDOS
1261 > #ifdef _WIN32
1262                  printf("\tdel %s\n", fn);
1263   #else
1264                  printf("\trm -f %s\n", fn);
1265   #endif
1266 <        if (noaction)
1266 >        if (!nprocs)
1267                  return(0);
1268          return(unlink(fn));
1269   }
# Line 1261 | Line 1273 | mvfile(fold, fnew)             /* move a file */
1273   char    *fold, *fnew;
1274   {
1275          if (!silent)
1276 < #ifdef MSDOS
1276 > #ifdef _WIN32
1277                  printf("\trename %s %s\n", fold, fnew);
1278   #else
1279                  printf("\tmv %s %s\n", fold, fnew);
1280   #endif
1281 <        if (noaction)
1281 >        if (!nprocs)
1282                  return(0);
1283          return(rename(fold, fnew));
1284   }
1285  
1286  
1287 < #ifdef MSDOS
1287 > #ifdef RHAS_FORK_EXEC
1288 > int
1289 > next_process()                  /* fork the next process (max. nprocs) */
1290 > {
1291 >        int     child_pid;
1292 >
1293 >        if (nprocs <= 1)
1294 >                return(0);              /* it's us or no one */
1295 >        if (children_running < 0) {
1296 >                fprintf(stderr, "%s: internal error 1 in spawn_process()\n",
1297 >                                progname);
1298 >                quit(1);
1299 >        }
1300 >        if (children_running >= nprocs)
1301 >                wait_process(0);        /* wait for someone to finish */
1302 >        fflush(stdout);
1303 >        child_pid = fork();             /* split process */
1304 >        if (child_pid == 0) {           /* we're the child */
1305 >                children_running = -1;
1306 >                return(0);
1307 >        }
1308 >        if (child_pid > 0) {            /* we're the parent */
1309 >                ++children_running;
1310 >                return(1);
1311 >        }
1312 >        fprintf(stderr, "%s: warning -- fork() failed\n", progname);
1313 >        return(0);
1314 > }
1315 >
1316 > wait_process(all)                       /* wait for process(es) to finish */
1317 > int     all;
1318 > {
1319 >        int     ourstatus = 0;
1320 >        int     pid, status;
1321 >
1322 >        if (all)
1323 >                all = children_running;
1324 >        else if (children_running > 0)
1325 >                all = 1;
1326 >        while (all-- > 0) {
1327 >                pid = wait(&status);
1328 >                if (pid < 0)
1329 >                        syserr(progname);
1330 >                status = status>>8 & 0xff;
1331 >                --children_running;
1332 >                if (status != 0) {      /* child's problem is our problem */
1333 >                        if (ourstatus == 0 & children_running > 0)
1334 >                                fprintf(stderr, "%s: waiting for remaining processes\n",
1335 >                                                progname);
1336 >                        ourstatus = status;
1337 >                        all = children_running;
1338 >                }
1339 >        }
1340 >        if (ourstatus != 0)
1341 >                quit(ourstatus);        /* bad status from child */
1342 > }
1343 > #else   /* ! RHAS_FORK_EXEC */
1344 > int
1345 > next_process()
1346 > {
1347 >        return(0);                      /* cannot start new process */
1348 > }
1349 > wait_process(all)
1350 > int     all;
1351 > {
1352 >        (void)all;                      /* no one to wait for */
1353 > }
1354 > #endif  /* ! RHAS_FORK_EXEC */
1355 >
1356 > finish_process()                        /* exit a child process */
1357 > {
1358 >        if (children_running >= 0)
1359 >                return;                 /* in parent -- noop */
1360 >        exit(0);
1361 > }
1362 >
1363 > #ifdef _WIN32
1364   setenv(vname, value)            /* set an environment variable */
1365   char    *vname, *value;
1366   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines