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.1 by greg, Thu Mar 11 09:11:00 1993 UTC vs.
Revision 2.69 by schorsch, Mon Jul 14 20:02:30 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1993 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Executive program for oconv, rpict and pfilt
6   */
7  
8   #include "standard.h"
9 < #include "paths.h"
9 >
10   #include <ctype.h>
11 + #include <time.h>
12  
13 + #include "platform.h"
14 + #include "view.h"
15 + #include "paths.h"
16 + #include "vars.h"
17  
18 < typedef struct {
19 <        char    *name;          /* variable name */
20 <        short   nick;           /* # characters required for nickname */
21 <        short   nass;           /* # assignments made */
22 <        char    *value;         /* assigned value(s) */
23 <        int     (*fixval)();    /* assignment checking function */
24 < } VARIABLE;
18 > #ifdef _WIN32
19 >  #define DELCMD "del"
20 >  #define RENAMECMD "rename"
21 > #else
22 >  #define DELCMD "rm -f"
23 >  #define RENAMECMD "mv"
24 > #endif
25  
26 < int     onevalue(), catvalues();
27 <
28 <                                /* variables */
29 < #define OBJECT          0               /* object files */
30 < #define SCENE           1               /* scene files */
31 < #define MATERIAL        2               /* material files */
32 < #define RENDER          3               /* rendering options */
33 < #define OCONV           4               /* oconv options */
34 < #define PFILT           5               /* pfilt options */
35 < #define VIEW            6               /* view(s) for picture(s) */
36 < #define ZONE            7               /* simulation zone */
37 < #define QUALITY         8               /* desired rendering quality */
38 < #define OCTREE          9               /* octree file name */
39 < #define PICTURE         10              /* picture file name */
40 < #define AMBFILE         11              /* ambient file name */
41 < #define OPTFILE         12              /* rendering options file */
42 < #define EXPOSURE        13              /* picture exposure setting */
43 < #define RESOLUTION      14              /* maximum picture resolution */
44 < #define UP              15              /* view up (X, Y or Z) */
45 < #define INDIRECT        16              /* indirection in lighting */
46 < #define DETAIL          17              /* level of scene detail */
47 < #define PENUMBRAS       18              /* shadow penumbras are desired */
48 < #define VARIABILITY     19              /* level of light variability */
49 < #define REPORT          20              /* report frequency and errfile */
26 >                                /* variables (alphabetical by name) */
27 > #define AMBFILE         0               /* ambient file name */
28 > #define DETAIL          1               /* level of scene detail */
29 > #define EXPOSURE        2               /* picture exposure setting */
30 > #define EYESEP          3               /* interocular distance */
31 > #define ILLUM           4               /* mkillum input files */
32 > #define INDIRECT        5               /* indirection in lighting */
33 > #define MATERIAL        6               /* material files */
34 > #define MKILLUM         7               /* mkillum options */
35 > #define OBJECT          8               /* object files */
36 > #define OCONV           9               /* oconv options */
37 > #define OCTREE          10              /* octree file name */
38 > #define OPTFILE         11              /* rendering options file */
39 > #define PENUMBRAS       12              /* shadow penumbras are desired */
40 > #define PFILT           13              /* pfilt options */
41 > #define PICTURE         14              /* picture file root name */
42 > #define QUALITY         15              /* desired rendering quality */
43 > #define RAWFILE         16              /* raw picture file root name */
44 > #define RENDER          17              /* rendering options */
45 > #define REPORT          18              /* report frequency and errfile */
46 > #define RESOLUTION      19              /* maximum picture resolution */
47 > #define SCENE           20              /* scene files */
48 > #define UP              21              /* view up (X, Y or Z) */
49 > #define VARIABILITY     22              /* level of light variability */
50 > #define VIEWS           23              /* view(s) for picture(s) */
51 > #define ZFILE           24              /* distance file root name */
52 > #define ZONE            25              /* simulation zone */
53                                  /* total number of variables */
54 < #define NVARS           21
54 > int NVARS = 26;
55  
56 < VARIABLE        vv[NVARS] = {           /* variable-value pairs */
57 <        {"objects",     3,      0,      NULL,   catvalues},
58 <        {"scene",       3,      0,      NULL,   catvalues},
56 > VARIABLE        vv[] = {                /* variable-value pairs */
57 >        {"AMBFILE",     3,      0,      NULL,   onevalue},
58 >        {"DETAIL",      3,      0,      NULL,   qualvalue},
59 >        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
60 >        {"EYESEP",      3,      0,      NULL,   fltvalue},
61 >        {"illum",       3,      0,      NULL,   catvalues},
62 >        {"INDIRECT",    3,      0,      NULL,   intvalue},
63          {"materials",   3,      0,      NULL,   catvalues},
64 <        {"render",      3,      0,      NULL,   catvalues},
64 >        {"mkillum",     3,      0,      NULL,   catvalues},
65 >        {"objects",     3,      0,      NULL,   catvalues},
66          {"oconv",       3,      0,      NULL,   catvalues},
57        {"pfilt",       2,      0,      NULL,   catvalues},
58        {"view",        2,      0,      NULL,   NULL},
59        {"ZONE",        2,      0,      NULL,   onevalue},
60        {"QUALITY",     3,      0,      NULL,   onevalue},
67          {"OCTREE",      3,      0,      NULL,   onevalue},
62        {"PICTURE",     3,      0,      NULL,   onevalue},
63        {"AMBFILE",     3,      0,      NULL,   onevalue},
68          {"OPTFILE",     3,      0,      NULL,   onevalue},
69 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
69 >        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
70 >        {"pfilt",       2,      0,      NULL,   catvalues},
71 >        {"PICTURE",     3,      0,      NULL,   onevalue},
72 >        {"QUALITY",     3,      0,      NULL,   qualvalue},
73 >        {"RAWFILE",     3,      0,      NULL,   onevalue},
74 >        {"render",      3,      0,      NULL,   catvalues},
75 >        {"REPORT",      3,      0,      NULL,   onevalue},
76          {"RESOLUTION",  3,      0,      NULL,   onevalue},
77 +        {"scene",       3,      0,      NULL,   catvalues},
78          {"UP",          2,      0,      NULL,   onevalue},
79 <        {"INDIRECT",    3,      0,      NULL,   onevalue},
80 <        {"DETAIL",      3,      0,      NULL,   onevalue},
81 <        {"PENUMBRAS",   3,      0,      NULL,   onevalue},
82 <        {"VARIABILITY", 3,      0,      NULL,   onevalue},
72 <        {"REPORT",      3,      0,      NULL,   onevalue},
79 >        {"VARIABILITY", 3,      0,      NULL,   qualvalue},
80 >        {"view",        2,      0,      NULL,   NULL},
81 >        {"ZFILE",       2,      0,      NULL,   onevalue},
82 >        {"ZONE",        2,      0,      NULL,   onevalue},
83   };
84  
85 < VARIABLE        *matchvar();
86 < char    *nvalue();
87 < int     vscale();
85 >                                /* overture calculation file */
86 > #ifdef NULL_DEVICE
87 > char    overfile[] = NULL_DEVICE;
88 > #else
89 > char    overfile[] = "overture.unf";
90 > #endif
91  
79 #define vnam(vc)        (vv[vc].name)
80 #define vdef(vc)        (vv[vc].nass)
81 #define vval(vc)        (vv[vc].value)
82 #define vint(vc)        atoi(vval(vc))
83 #define vlet(vc)        (vval(vc)[0]&~0x20)
84 #define vbool(vc)       (vlet(vc)=='T')
92  
93 < #define HIGH            2
94 < #define MEDIUM          1
95 < #define LOW             0
93 > time_t  scenedate;              /* date of latest scene or object file */
94 > time_t  octreedate;             /* date of octree */
95 > time_t  matdate;                /* date of latest material file */
96 > time_t  illumdate;              /* date of last illum file */
97  
98 < int     lowqopts(), medqopts(), hiqopts();
99 < int     (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
98 > char    *oct0name;              /* name of pre-mkillum octree */
99 > time_t  oct0date;               /* date of pre-mkillum octree */
100 > char    *oct1name;              /* name of post-mkillum octree */
101 > time_t  oct1date;               /* date of post-mkillum octree (>= matdate) */
102  
103 < #define renderopts      (*setqopts[vscale(QUALITY)])
94 <
95 < extern long     fdate();
96 <
97 < long    scenedate;              /* date of latest scene or object file */
98 < long    octreedate;             /* date of octree */
99 <
103 > int     nowarn = 0;             /* no warnings */
104   int     explicate = 0;          /* explicate variables */
105   int     silent = 0;             /* do work silently */
106 < int     noaction = 0;           /* don't do anything */
106 > int     touchonly = 0;          /* touch files only */
107 > int     nprocs = 1;             /* maximum executing processes */
108 > int     sayview = 0;            /* print view out */
109   char    *rvdevice = NULL;       /* rview output device */
110   char    *viewselect = NULL;     /* specific view only */
111  
112   int     overture = 0;           /* overture calculation needed */
113  
114 + int     children_running = 0;   /* set negative in children */
115 +
116   char    *progname;              /* global argv[0] */
117 + char    *rifname;               /* global rad input file name */
118  
119 < char    radname[MAXPATH];       /* root Radiance file name */
119 > char    radname[PATH_MAX];      /* root Radiance file name */
120  
121 + #define inchild()       (children_running < 0)
122  
123 +
124   main(argc, argv)
125   int     argc;
126   char    *argv[];
127   {
128          char    ropts[512];
129 +        char    popts[64];
130          int     i;
131  
132          progname = argv[0];
# Line 125 | Line 137 | char   *argv[];
137                          silent++;
138                          break;
139                  case 'n':
140 <                        noaction++;
140 >                        nprocs = 0;
141                          break;
142 +                case 'N':
143 +                        nprocs = atoi(argv[++i]);
144 +                        if (nprocs < 0)
145 +                                nprocs = 0;
146 +                        break;
147 +                case 't':
148 +                        touchonly++;
149 +                        break;
150                  case 'e':
151                          explicate++;
152                          break;
153                  case 'o':
154                          rvdevice = argv[++i];
155                          break;
156 +                case 'V':
157 +                        sayview++;
158 +                        break;
159                  case 'v':
160                          viewselect = argv[++i];
161                          break;
162 +                case 'w':
163 +                        nowarn++;
164 +                        break;
165                  default:
166                          goto userr;
167                  }
168          if (i >= argc)
169                  goto userr;
170 +        rifname = argv[i];
171 +                                /* check command-line options */
172 +        if (nprocs > 1 & viewselect != NULL)
173 +                nprocs = 1;
174                                  /* assign Radiance root file name */
175 <        rootname(radname, argv[i]);
175 >        rootname(radname, rifname);
176                                  /* load variable values */
177 <        load(argv[i]);
177 >        loadvars(rifname);
178                                  /* get any additional assignments */
179          for (i++; i < argc; i++)
180 <                setvariable(argv[i]);
180 >                if (setvariable(argv[i], matchvar) < 0) {
181 >                        fprintf(stderr, "%s: unknown variable: %s\n",
182 >                                        progname, argv[i]);
183 >                        quit(1);
184 >                }
185                                  /* check assignments */
186          checkvalues();
187                                  /* check files and dates */
# Line 156 | Line 190 | char   *argv[];
190          setdefaults();
191                                  /* print all values if requested */
192          if (explicate)
193 <                printvals();
194 <                                /* run simulation */
193 >                printvars(stdout);
194 >                                /* build octree (and run mkillum) */
195          oconv();
196 <        renderopts(ropts);
196 >                                /* check date on ambient file */
197 >        checkambfile();
198 >                                /* run simulation */
199 >        renderopts(ropts, popts);
200          xferopts(ropts);
201          if (rvdevice != NULL)
202 <                rview(ropts);
202 >                rview(ropts, popts);
203          else
204 <                rpict(ropts);
205 <        exit(0);
204 >                rpict(ropts, popts);
205 >        quit(0);
206   userr:
207          fprintf(stderr,
208 <        "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
208 > "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
209                          progname);
210 <        exit(1);
210 >        quit(1);
211   }
212  
213  
# Line 189 | Line 226 | register char  *rn, *fn;
226   }
227  
228  
229 < load(rfname)                    /* load Radiance simulation file */
230 < char    *rfname;
229 > time_t
230 > checklast(fnames)                       /* check files and find most recent */
231 > register char   *fnames;
232   {
233 <        FILE    *fp;
234 <        char    buf[256];
197 <        register char   *cp;
233 >        char    thisfile[PATH_MAX];
234 >        time_t  thisdate, lastdate = 0;
235  
236 <        if (rfname == NULL)
237 <                fp = stdin;
238 <        else if ((fp = fopen(rfname, "r")) == NULL) {
239 <                perror(rfname);
240 <                exit(1);
236 >        if (fnames == NULL)
237 >                return(0);
238 >        while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) {
239 >                if (thisfile[0] == '!' ||
240 >                                (thisfile[0] == '\\' && thisfile[1] == '!'))
241 >                        continue;
242 >                if (!(thisdate = fdate(thisfile)))
243 >                        syserr(thisfile);
244 >                if (thisdate > lastdate)
245 >                        lastdate = thisdate;
246          }
247 <        while (fgetline(buf, sizeof(buf), fp) != NULL) {
206 <                for (cp = buf; *cp; cp++) {
207 <                        switch (*cp) {
208 <                        case '\\':
209 <                        case '\n':
210 <                                *cp = ' ';
211 <                                continue;
212 <                        case '#':
213 <                                *cp = '\0';
214 <                                break;
215 <                        }
216 <                        break;
217 <                }
218 <                setvariable(buf);
219 <        }
220 <        fclose(fp);
247 >        return(lastdate);
248   }
249  
250  
224 setvariable(ass)                /* assign variable according to string */
225 register char   *ass;
226 {
227        char    varname[32];
228        register char   *cp;
229        register VARIABLE       *vp;
230        register int    i;
231        int     n;
232
233        while (isspace(*ass))           /* skip leading space */
234                ass++;
235        cp = varname;                   /* extract name */
236        while (cp < varname+sizeof(varname)-1
237                        && *ass && !isspace(*ass) && *ass != '=')
238                *cp++ = *ass++;
239        *cp = '\0';
240        if (!varname[0])
241                return;         /* no variable name! */
242                                        /* trim value */
243        while (isspace(*ass) || *ass == '=')
244                ass++;
245        cp = ass + strlen(ass);
246        do
247                *cp-- = '\0';
248        while (cp >= ass && isspace(*cp));
249        n = cp - ass + 1;
250        if (!n) {
251                fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
252                                progname, varname);
253                return;
254        }
255                                        /* match variable from list */
256        vp = matchvar(varname);
257        if (vp == NULL) {
258                fprintf(stderr, "%s: unknown variable '%s'\n",
259                                progname, varname);
260                exit(1);
261        }
262                                        /* assign new value */
263        cp = vp->value; i = vp->nass;
264        while (i--)
265                while (*cp++)
266                        ;
267        i = cp - vp->value;
268        vp->value = realloc(vp->value, i+n+1);
269        if (vp->value == NULL) {
270                perror(progname);
271                exit(1);
272        }
273        strcpy(vp->value+i, ass);
274        vp->nass++;
275 }
276
277
278 VARIABLE *
279 matchvar(nam)                   /* match a variable by its name */
280 char    *nam;
281 {
282        int     n = strlen(nam);
283        register int    i;
284
285        for (i = 0; i < NVARS; i++)
286                if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n))
287                        return(vv+i);
288        return(NULL);
289 }
290
291
251   char *
252 < nvalue(vp, n)                   /* return nth variable value */
253 < VARIABLE        *vp;
254 < register int    n;
252 > newfname(orig, pred)            /* create modified file name */
253 > char    *orig;
254 > int     pred;
255   {
256          register char   *cp;
257 +        register int    n;
258 +        int     suffix;
259  
260 <        if (vp == NULL || n < 0 || n >= vp->nass)
261 <                return(NULL);
262 <        cp = vp->value;
263 <        while (n--)
264 <                while (*cp++)
265 <                        ;
260 >        n = 0; cp = orig; suffix = -1;          /* suffix position, length */
261 >        while (*cp) {
262 >                if (*cp == '.') suffix = n;
263 >                else if (ISDIRSEP(*cp)) suffix = -1;
264 >                cp++; n++;
265 >        }
266 >        if (suffix == -1) suffix = n;
267 >        if ((cp = bmalloc(n+2)) == NULL)
268 >                syserr(progname);
269 >        strncpy(cp, orig, suffix);
270 >        cp[suffix] = pred;                      /* root name + pred + suffix */
271 >        strcpy(cp+suffix+1, orig+suffix);
272          return(cp);
273   }
274  
275  
309 int
310 vscale(vc)                      /* return scale for variable vc */
311 int     vc;
312 {
313        switch(vlet(vc)) {
314        case 'H':
315                return(HIGH);
316        case 'M':
317                return(MEDIUM);
318        case 'L':
319                return(LOW);
320        }
321        fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n",
322                        progname, vnam(vc), vval(vc));
323        exit(1);
324 }
325
326
327 checkvalues()                   /* check assignments */
328 {
329        register int    i;
330
331        for (i = 0; i < NVARS; i++)
332                if (vv[i].fixval != NULL)
333                        (*vv[i].fixval)(vv+i);
334 }
335
336
337 onevalue(vp)                    /* only one assignment for this variable */
338 register VARIABLE       *vp;
339 {
340        if (vp->nass < 2)
341                return;
342        fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n",
343                        progname, vp->name);
344        while (vp->nass-- > 1)
345                vp->value += strlen(vp->value)+1;
346 }
347
348
349 catvalues(vp)                   /* concatenate variable values */
350 register VARIABLE       *vp;
351 {
352        register char   *cp;
353
354        if (vp->nass < 2)
355                return;
356        for (cp = vp->value; vp->nass > 1; vp->nass--) {
357                while (*cp)
358                        cp++;
359                *cp++ = ' ';
360        }
361 }
362
363
364 long
365 checklast(fnames)                       /* check files and find most recent */
366 register char   *fnames;
367 {
368        char    thisfile[MAXPATH];
369        long    thisdate, lastdate = -1;
370        register char   *cp;
371
372        while (*fnames) {
373                while (isspace(*fnames)) fnames++;
374                cp = thisfile;
375                while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
376                *cp = '\0';
377                if ((thisdate = fdate(thisfile)) < 0) {
378                        perror(thisfile);
379                        exit(1);
380                }
381                if (thisdate > lastdate)
382                        lastdate = thisdate;
383        }
384        return(lastdate);
385 }
386
387
276   checkfiles()                    /* check for existence and modified times */
277   {
278 <        long    objdate;
278 >        time_t  objdate;
279  
280 <        octreedate = vdef(OCTREE) ? fdate(vval(OCTREE)) : -1;
281 <        scenedate = -1;
282 <        if (vdef(SCENE)) {
283 <                scenedate = checklast(vval(SCENE));
284 <                if (vdef(OBJECT)) {
285 <                        objdate = checklast(vval(OBJECT));
286 <                        if (objdate > scenedate)
287 <                                scenedate = objdate;
288 <                }
280 >        if (!vdef(OCTREE)) {
281 >                if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL)
282 >                        syserr(progname);
283 >                sprintf(vval(OCTREE), "%s.oct", radname);
284 >                vdef(OCTREE)++;
285 >        } else if (vval(OCTREE)[0] == '!') {
286 >                fprintf(stderr, "%s: illegal '%s' specification\n",
287 >                                progname, vnam(OCTREE));
288 >                quit(1);
289          }
290 <        if (octreedate < 0 & scenedate < 0) {
291 <                fprintf(stderr, "%s: need scene or octree\n", progname);
292 <                exit(1);
290 >        octreedate = fdate(vval(OCTREE));
291 >        if (vdef(ILLUM)) {              /* illum requires secondary octrees */
292 >                oct0name = newfname(vval(OCTREE), '0');
293 >                oct1name = newfname(vval(OCTREE), '1');
294 >                oct0date = fdate(oct0name);
295 >                oct1date = fdate(oct1name);
296 >        } else
297 >                oct0name = oct1name = vval(OCTREE);
298 >        if ((scenedate = checklast(vval(SCENE))) &&
299 >                        (objdate = checklast(vval(OBJECT))) > scenedate)
300 >                scenedate = objdate;
301 >        illumdate = checklast(vval(ILLUM));
302 >        if (!octreedate & !scenedate & !illumdate) {
303 >                fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
304 >                                vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
305 >                quit(1);
306          }
307 +        matdate = checklast(vval(MATERIAL));
308   }      
309  
310  
311 < setdefaults()                   /* set default values for unassigned var's */
311 > getoctcube(org, sizp)           /* get octree bounding cube */
312 > double  org[3], *sizp;
313   {
314 +        extern FILE     *popen();
315 +        static double   oorg[3], osiz = 0.;
316 +        double  min[3], max[3];
317 +        char    buf[1024];
318          FILE    *fp;
319 <        double  xmin, ymin, zmin, size;
413 <        char    buf[512];
414 <        char    *cp;
319 >        register int    i;
320  
321 <        if (!vdef(OCTREE)) {
322 <                sprintf(buf, "%s.oct", radname);
323 <                vval(OCTREE) = savqstr(buf);
324 <                vdef(OCTREE)++;
325 <        }
326 <        if (!vdef(ZONE)) {
327 <                if (scenedate > octreedate) {
328 <                        sprintf(buf, "getbbox -w -h %s", vval(SCENE));
329 <                        if (!silent) {
330 <                                printf("\t%s\n", buf);
331 <                                fflush(stdout);
321 >        if (osiz <= FTINY)
322 >                if (!nprocs && fdate(oct1name) <
323 >                                (scenedate>illumdate?scenedate:illumdate)) {
324 >                                                        /* run getbbox */
325 >                        sprintf(buf, "getbbox -w -h %s",
326 >                                vdef(SCENE) ? vval(SCENE) : vval(ILLUM));
327 >                        if ((fp = popen(buf, "r")) == NULL)
328 >                                syserr("getbbox");
329 >                        if (fscanf(fp, "%lf %lf %lf %lf %lf %lf",
330 >                                        &min[0], &max[0], &min[1], &max[1],
331 >                                        &min[2], &max[2]) != 6) {
332 >                                fprintf(stderr,
333 >                        "%s: error reading bounding box from getbbox\n",
334 >                                                progname);
335 >                                quit(1);
336                          }
337 <                        if ((fp = popen(buf, "r")) == NULL) {
338 <                                perror("getbbox");
339 <                                exit(1);
340 <                        }
341 <                        buf[0] = 'E'; buf[1] = ' ';
433 <                        fgetline(buf+2, sizeof(buf)-2, fp);
337 >                        for (i = 0; i < 3; i++)
338 >                                if (max[i] - min[i] > osiz)
339 >                                        osiz = max[i] - min[i];
340 >                        for (i = 0; i < 3; i++)
341 >                                oorg[i] = (max[i]+min[i]-osiz)*.5;
342                          pclose(fp);
343 <                } else {
344 <                        sprintf(buf, "getinfo -d < %s", vval(OCTREE));
345 <                        if ((fp = popen(buf, "r")) == NULL) {
346 <                                perror("getinfo");
347 <                                exit(1);
343 >                } else {                                /* from octree */
344 >                        oconv();        /* does nothing if done already */
345 >                        sprintf(buf, "getinfo -d < %s", oct1name);
346 >                        if ((fp = popen(buf, "r")) == NULL)
347 >                                syserr("getinfo");
348 >                        if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
349 >                                        &oorg[2], &osiz) != 4) {
350 >                                fprintf(stderr,
351 >                        "%s: error reading bounding cube from getinfo\n",
352 >                                                progname);
353 >                                quit(1);
354                          }
441                        fscanf(fp, "%lf %lf %lf %lf",
442                                        &xmin, &ymin, &zmin, &size);
443                        sprintf(buf, "E %g %g %g %g %g %g", xmin, xmin+size,
444                                        ymin, ymin+size, zmin, zmin+size);
355                          pclose(fp);
356                  }
357 +        org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
358 + }
359 +
360 +
361 + setdefaults()                   /* set default values for unassigned var's */
362 + {
363 +        double  org[3], lim[3], size;
364 +        char    buf[128];
365 +
366 +        if (!vdef(ZONE)) {
367 +                getoctcube(org, &size);
368 +                sprintf(buf, "E %g %g %g %g %g %g", org[0], org[0]+size,
369 +                                org[1], org[1]+size, org[2], org[2]+size);
370                  vval(ZONE) = savqstr(buf);
371                  vdef(ZONE)++;
372          }
373 <        if (!vdef(UP)) {
374 <                vval(UP) = "Z";
375 <                vdef(UP)++;
373 >        if (!vdef(EYESEP)) {
374 >                if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
375 >                                &org[0], &lim[0], &org[1], &lim[1],
376 >                                &org[2], &lim[2]) != 6)
377 >                        badvalue(ZONE);
378 >                sprintf(buf, "%f",
379 >                        0.01*(lim[0]-org[0]+lim[1]-org[1]+lim[2]-org[2]));
380 >                vval(EYESEP) = savqstr(buf);
381 >                vdef(EYESEP)++;
382          }
383          if (!vdef(INDIRECT)) {
384                  vval(INDIRECT) = "0";
# Line 467 | Line 396 | setdefaults()                  /* set default values for unassigned v
396                  vval(PICTURE) = radname;
397                  vdef(PICTURE)++;
398          }
399 <        if (!vdef(AMBFILE)) {
400 <                sprintf(buf, "%s.amb", radname);
401 <                vval(AMBFILE) = savqstr(buf);
473 <                vdef(AMBFILE)++;
399 >        if (!vdef(VIEWS)) {
400 >                vval(VIEWS) = "X";
401 >                vdef(VIEWS)++;
402          }
475        if (!vdef(VIEW)) {
476                vval(VIEW) = "X";
477                vdef(VIEW)++;
478        }
403          if (!vdef(DETAIL)) {
404                  vval(DETAIL) = "M";
405                  vdef(DETAIL)++;
# Line 491 | Line 415 | setdefaults()                  /* set default values for unassigned v
415   }
416  
417  
418 < printvals()                     /* print variable values */
418 > oconv()                         /* run oconv and mkillum if necessary */
419   {
420 <        register int    i, j;
420 >        static char     illumtmp[] = "ilXXXXXX";
421 >        char    combuf[PATH_MAX], ocopts[64], mkopts[64];
422  
423 <        for (i = 0; i < NVARS; i++)
424 <                for (j = 0; j < vv[i].nass; j++)
425 <                        printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
426 <        fflush(stdout);
427 < }
428 <
429 <
430 < oconv()                         /* run oconv if necessary */
431 < {
432 <        char    combuf[512], ocopts[64];
433 <
434 <        if (octreedate > scenedate)     /* check dates */
435 <                return;
436 <                                        /* build command */
437 <        oconvopts(ocopts);
438 <        sprintf(combuf, "oconv%s %s > %s", ocopts, vval(SCENE), vval(OCTREE));
439 <        if (!silent) {                  /* echo it */
440 <                printf("\t%s\n", combuf);
441 <                fflush(stdout);
423 >        oconvopts(ocopts);              /* get options */
424 >        if (octreedate < scenedate) {   /* check date on original octree */
425 >                if (touchonly && octreedate)
426 >                        touch(vval(OCTREE));
427 >                else {                          /* build command */
428 >                        if (vdef(MATERIAL))
429 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
430 >                                                vval(MATERIAL), vval(SCENE),
431 >                                                vval(OCTREE));
432 >                        else
433 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
434 >                                                vval(SCENE), vval(OCTREE));
435 >                        
436 >                        if (runcom(combuf)) {           /* run it */
437 >                                fprintf(stderr,
438 >                                "%s: error generating octree\n\t%s removed\n",
439 >                                                progname, vval(OCTREE));
440 >                                unlink(vval(OCTREE));
441 >                                quit(1);
442 >                        }
443 >                }
444 >                octreedate = time((time_t *)NULL);
445 >                if (octreedate < scenedate)     /* in case clock is off */
446 >                        octreedate = scenedate;
447          }
448 <        if (noaction)
448 >        if (oct1name == vval(OCTREE))           /* no mkillum? */
449 >                oct1date = octreedate > matdate ? octreedate : matdate;
450 >        if (oct1date >= octreedate & oct1date >= matdate
451 >                        & oct1date >= illumdate)        /* all done */
452                  return;
453 <        if (system(combuf)) {           /* run it */
454 <                fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
455 <                                progname, vval(OCTREE));
456 <                unlink(vval(OCTREE));
457 <                exit(1);
453 >                                                /* make octree0 */
454 >        if (oct0date < scenedate | oct0date < illumdate) {
455 >                if (touchonly && oct0date)
456 >                        touch(oct0name);
457 >                else {                          /* build command */
458 >                        if (octreedate)
459 >                                sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
460 >                                        vval(OCTREE), vval(ILLUM), oct0name);
461 >                        else if (vdef(MATERIAL))
462 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
463 >                                        vval(MATERIAL), vval(ILLUM), oct0name);
464 >                        else
465 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
466 >                                        vval(ILLUM), oct0name);
467 >                        if (runcom(combuf)) {           /* run it */
468 >                                fprintf(stderr,
469 >                                "%s: error generating octree\n\t%s removed\n",
470 >                                                progname, oct0name);
471 >                                unlink(oct0name);
472 >                                quit(1);
473 >                        }
474 >                }
475 >                oct0date = time((time_t *)NULL);
476 >                if (oct0date < octreedate)      /* in case clock is off */
477 >                        oct0date = octreedate;
478 >                if (oct0date < illumdate)       /* ditto */
479 >                        oct0date = illumdate;
480 >                }
481 >        if (touchonly && oct1date)
482 >                touch(oct1name);
483 >        else {
484 >                mkillumopts(mkopts);            /* build mkillum command */
485 >                mktemp(illumtmp);
486 >                sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
487 >                                oct0name, vval(ILLUM), illumtmp);
488 >                if (runcom(combuf)) {                   /* run it */
489 >                        fprintf(stderr, "%s: error running mkillum\n",
490 >                                        progname);
491 >                        unlink(illumtmp);
492 >                        quit(1);
493 >                }
494 >                                                /* make octree1 (frozen) */
495 >                if (octreedate)
496 >                        sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
497 >                                vval(OCTREE), illumtmp, oct1name);
498 >                else if (vdef(MATERIAL))
499 >                        sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
500 >                                vval(MATERIAL), illumtmp, oct1name);
501 >                else
502 >                        sprintf(combuf, "oconv%s -f %s > %s", ocopts,
503 >                                illumtmp, oct1name);
504 >                if (runcom(combuf)) {           /* run it */
505 >                        fprintf(stderr,
506 >                                "%s: error generating octree\n\t%s removed\n",
507 >                                        progname, oct1name);
508 >                        unlink(oct1name);
509 >                        unlink(illumtmp);
510 >                        quit(1);
511 >                }
512 >                rmfile(illumtmp);
513          }
514 +        oct1date = time((time_t *)NULL);
515 +        if (oct1date < oct0date)        /* in case clock is off */
516 +                oct1date = oct0date;
517   }
518  
519  
# Line 538 | Line 529 | register char  *op, *arg;
529  
530  
531   oconvopts(oo)                           /* get oconv options */
532 < char    *oo;
532 > register char   *oo;
533   {
534 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
535 +
536          *oo = '\0';
537          if (vdef(OCONV))
538                  addarg(oo, vval(OCONV));
539   }
540  
541  
542 < lowqopts(ro)                            /* low quality rendering options */
543 < char    *ro;
542 > mkillumopts(mo)                         /* get mkillum options */
543 > register char   *mo;
544   {
545 <        register char   *op = ro;
545 >        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
546  
547 +        *mo = '\0';
548 +        if (vdef(MKILLUM))
549 +                addarg(mo, vval(MKILLUM));
550 + }
551 +
552 +
553 + checkambfile()                  /* check date on ambient file */
554 + {
555 +        time_t  afdate;
556 +
557 +        if (!vdef(AMBFILE))
558 +                return;
559 +        if (!(afdate = fdate(vval(AMBFILE))))
560 +                return;
561 +        if (oct1date > afdate)
562 +                if (touchonly)
563 +                        touch(vval(AMBFILE));
564 +                else
565 +                        rmfile(vval(AMBFILE));
566 + }
567 +
568 +
569 + double
570 + ambval()                                /* compute ambient value */
571 + {
572 +        if (vdef(EXPOSURE)) {
573 +                if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
574 +                        return(.5/pow(2.,vflt(EXPOSURE)));
575 +                return(.5/vflt(EXPOSURE));
576 +        }
577 +        if (vlet(ZONE) == 'E')
578 +                return(10.);
579 +        if (vlet(ZONE) == 'I')
580 +                return(.01);
581 +        badvalue(ZONE);
582 + }
583 +
584 +
585 + renderopts(op, po)                      /* set rendering options */
586 + char    *op, *po;
587 + {
588 +        switch(vscale(QUALITY)) {
589 +        case LOW:
590 +                lowqopts(op, po);
591 +                break;
592 +        case MEDIUM:
593 +                medqopts(op, po);
594 +                break;
595 +        case HIGH:
596 +                hiqopts(op, po);
597 +                break;
598 +        }
599 + }
600 +
601 +
602 + lowqopts(op, po)                        /* low quality rendering options */
603 + register char   *op;
604 + char    *po;
605 + {
606 +        double  d, org[3], siz[3];
607 +
608          *op = '\0';
609 +        *po = '\0';
610 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
611 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
612 +                badvalue(ZONE);
613 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
614 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
615 +                badvalue(ZONE);
616 +        getoctcube(org, &d);
617 +        d *= 3./(siz[0]+siz[1]+siz[2]);
618 +        switch (vscale(DETAIL)) {
619 +        case LOW:
620 +                po = addarg(po, "-ps 16");
621 +                op = addarg(op, "-dp 64");
622 +                sprintf(op, " -ar %d", (int)(4*d));
623 +                op += strlen(op);
624 +                break;
625 +        case MEDIUM:
626 +                po = addarg(po, "-ps 8");
627 +                op = addarg(op, "-dp 128");
628 +                sprintf(op, " -ar %d", (int)(8*d));
629 +                op += strlen(op);
630 +                break;
631 +        case HIGH:
632 +                po = addarg(po, "-ps 4");
633 +                op = addarg(op, "-dp 256");
634 +                sprintf(op, " -ar %d", (int)(16*d));
635 +                op += strlen(op);
636 +                break;
637 +        }
638 +        po = addarg(po, "-pt .16");
639 +        if (vbool(PENUMBRAS))
640 +                op = addarg(op, "-ds .4");
641 +        else
642 +                op = addarg(op, "-ds 0");
643 +        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
644 +        if (vdef(AMBFILE)) {
645 +                sprintf(op, " -af %s", vval(AMBFILE));
646 +                op += strlen(op);
647 +        } else
648 +                overture = 0;
649 +        switch (vscale(VARIABILITY)) {
650 +        case LOW:
651 +                op = addarg(op, "-aa .4 -ad 64");
652 +                break;
653 +        case MEDIUM:
654 +                op = addarg(op, "-aa .3 -ad 128");
655 +                break;
656 +        case HIGH:
657 +                op = addarg(op, "-aa .25 -ad 256");
658 +                break;
659 +        }
660 +        op = addarg(op, "-as 0");
661 +        d = ambval();
662 +        sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
663 +        op += strlen(op);
664 +        op = addarg(op, "-lr 3 -lw .02");
665          if (vdef(RENDER))
666                  op = addarg(op, vval(RENDER));
667   }
668  
669  
670 < medqopts(ro)                            /* medium quality rendering options */
671 < char    *ro;
670 > medqopts(op, po)                        /* medium quality rendering options */
671 > register char   *op;
672 > char    *po;
673   {
674 <        register char   *op = ro;
674 >        double  d, org[3], siz[3], asz;
675  
676          *op = '\0';
677 +        *po = '\0';
678 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
679 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
680 +                badvalue(ZONE);
681 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
682 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
683 +                badvalue(ZONE);
684 +        getoctcube(org, &d);
685 +        asz = (siz[0]+siz[1]+siz[2])/3.;
686 +        d /= asz;
687 +        switch (vscale(DETAIL)) {
688 +        case LOW:
689 +                po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
690 +                op = addarg(op, "-dp 256");
691 +                sprintf(op, " -ar %d", (int)(8*d));
692 +                op += strlen(op);
693 +                sprintf(op, " -ms %.2g", asz/20.);
694 +                op += strlen(op);
695 +                break;
696 +        case MEDIUM:
697 +                po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
698 +                op = addarg(op, "-dp 512");
699 +                sprintf(op, " -ar %d", (int)(16*d));
700 +                op += strlen(op);
701 +                sprintf(op, " -ms %.2g", asz/40.);
702 +                op += strlen(op);
703 +                break;
704 +        case HIGH:
705 +                po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
706 +                op = addarg(op, "-dp 1024");
707 +                sprintf(op, " -ar %d", (int)(32*d));
708 +                op += strlen(op);
709 +                sprintf(op, " -ms %.2g", asz/80.);
710 +                op += strlen(op);
711 +                break;
712 +        }
713 +        po = addarg(po, "-pt .08");
714 +        if (vbool(PENUMBRAS))
715 +                op = addarg(op, "-ds .2 -dj .5");
716 +        else
717 +                op = addarg(op, "-ds .3");
718 +        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
719 +        if (overture = vint(INDIRECT)) {
720 +                sprintf(op, " -ab %d", overture);
721 +                op += strlen(op);
722 +        }
723 +        if (vdef(AMBFILE)) {
724 +                sprintf(op, " -af %s", vval(AMBFILE));
725 +                op += strlen(op);
726 +        } else
727 +                overture = 0;
728 +        switch (vscale(VARIABILITY)) {
729 +        case LOW:
730 +                op = addarg(op, "-aa .25 -ad 196 -as 0");
731 +                break;
732 +        case MEDIUM:
733 +                op = addarg(op, "-aa .2 -ad 400 -as 64");
734 +                break;
735 +        case HIGH:
736 +                op = addarg(op, "-aa .15 -ad 768 -as 196");
737 +                break;
738 +        }
739 +        d = ambval();
740 +        sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
741 +        op += strlen(op);
742 +        op = addarg(op, "-lr 6 -lw .002");
743          if (vdef(RENDER))
744                  op = addarg(op, vval(RENDER));
745   }
746  
747  
748 < hiqopts(ro)                             /* high quality rendering options */
749 < char    *ro;
748 > hiqopts(op, po)                         /* high quality rendering options */
749 > register char   *op;
750 > char    *po;
751   {
752 <        register char   *op = ro;
752 >        double  d, org[3], siz[3], asz;
753  
754          *op = '\0';
755 +        *po = '\0';
756 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
757 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
758 +                badvalue(ZONE);
759 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
760 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
761 +                badvalue(ZONE);
762 +        getoctcube(org, &d);
763 +        asz = (siz[0]+siz[1]+siz[2])/3.;
764 +        d /= asz;
765 +        switch (vscale(DETAIL)) {
766 +        case LOW:
767 +                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
768 +                op = addarg(op, "-dp 1024");
769 +                sprintf(op, " -ar %d", (int)(16*d));
770 +                op += strlen(op);
771 +                sprintf(op, " -ms %.2g", asz/40.);
772 +                op += strlen(op);
773 +                break;
774 +        case MEDIUM:
775 +                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
776 +                op = addarg(op, "-dp 2048");
777 +                sprintf(op, " -ar %d", (int)(32*d));
778 +                op += strlen(op);
779 +                sprintf(op, " -ms %.2g", asz/80.);
780 +                op += strlen(op);
781 +                break;
782 +        case HIGH:
783 +                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
784 +                op = addarg(op, "-dp 4096");
785 +                sprintf(op, " -ar %d", (int)(64*d));
786 +                op += strlen(op);
787 +                sprintf(op, " -ms %.2g", asz/160.);
788 +                op += strlen(op);
789 +                break;
790 +        }
791 +        po = addarg(po, "-pt .04");
792 +        if (vbool(PENUMBRAS))
793 +                op = addarg(op, "-ds .1 -dj .65");
794 +        else
795 +                op = addarg(op, "-ds .2");
796 +        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
797 +        sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
798 +        op += strlen(op);
799 +        if (vdef(AMBFILE)) {
800 +                sprintf(op, " -af %s", vval(AMBFILE));
801 +                op += strlen(op);
802 +        } else
803 +                overture = 0;
804 +        switch (vscale(VARIABILITY)) {
805 +        case LOW:
806 +                op = addarg(op, "-aa .15 -ad 256 -as 0");
807 +                break;
808 +        case MEDIUM:
809 +                op = addarg(op, "-aa .125 -ad 512 -as 256");
810 +                break;
811 +        case HIGH:
812 +                op = addarg(op, "-aa .08 -ad 1024 -as 512");
813 +                break;
814 +        }
815 +        d = ambval();
816 +        sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
817 +        op += strlen(op);
818 +        op = addarg(op, "-lr 12 -lw .0005");
819          if (vdef(RENDER))
820                  op = addarg(op, vval(RENDER));
821   }
# Line 583 | Line 825 | xferopts(ro)                           /* transfer options if indicated */
825   char    *ro;
826   {
827          int     fd, n;
828 +        register char   *cp;
829          
830          n = strlen(ro);
831          if (n < 2)
832                  return;
833          if (vdef(OPTFILE)) {
834 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
835 <                        perror(vval(OPTFILE));
836 <                        exit(1);
837 <                }
838 <                if (write(fd, ro+1, n-1) != n-1) {
839 <                        perror(vval(OPTFILE));
840 <                        exit(1);
841 <                }
842 <                write(fd, "\n", 1);
843 <                close(fd);
844 <                ro[0] = ' ';
602 <                ro[1] = '^';
603 <                strcpy(ro+2, vval(OPTFILE));
834 >                for (cp = ro; cp[1]; cp++)
835 >                        if (isspace(cp[1]) && (cp[2] == '@' ||
836 >                                        (cp[2] == '-' && isalpha(cp[3]))))
837 >                                *cp = '\n';
838 >                        else
839 >                                *cp = cp[1];
840 >                *cp = '\n';
841 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
842 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
843 >                        syserr(vval(OPTFILE));
844 >                sprintf(ro, " @%s", vval(OPTFILE));
845          }
846 < #ifdef MSDOS
846 > #ifdef _WIN32
847          else if (n > 50) {
848 <                register char   *evp = bmalloc(n+6);
608 <                if (evp == NULL) {
609 <                        perror(progname);
610 <                        exit(1);
611 <                }
612 <                strcpy(evp, "ROPT=");
613 <                strcat(evp, ro);
614 <                putenv(evp);
848 >                setenv("ROPT", ro+1);
849                  strcpy(ro, " $ROPT");
850          }
851   #endif
# Line 626 | Line 860 | register char  *po;
860                  po = addarg(po, "-1 -e");
861                  po = addarg(po, vval(EXPOSURE));
862          }
863 <        if (vscale(QUALITY) == HIGH)
864 <                po = addarg(po, "-r .65");
863 >        switch (vscale(QUALITY)) {
864 >        case MEDIUM:
865 >                po = addarg(po, "-r .6");
866 >                break;
867 >        case HIGH:
868 >                po = addarg(po, "-m .25");
869 >                break;
870 >        }
871          if (vdef(PFILT))
872                  po = addarg(po, vval(PFILT));
873   }
# Line 649 | Line 889 | char *
889   specview(vs)                            /* get proper view spec from vs */
890   register char   *vs;
891   {
892 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
893 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
894          static char     viewopts[128];
895          register char   *cp;
896 <        int     xpos, ypos, zpos, viewtype;
897 <        int     exterior;
896 >        int     xpos, ypos, zpos, viewtype, upax;
897 >        register int    i;
898          double  cent[3], dim[3], mult, d;
899  
900          if (vs == NULL || *vs == '-')
901                  return(vs);
902 +        upax = 0;                       /* get the up vector */
903 +        if (vdef(UP)) {
904 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
905 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
906 +                else
907 +                        upax = 1-'X'+vlet(UP);
908 +                if (upax < 1 | upax > 3)
909 +                        badvalue(UP);
910 +                if (vval(UP)[0] == '-')
911 +                        upax = -upax;
912 +        }
913                                          /* check standard view names */
914          xpos = ypos = zpos = 0;
662        viewtype = 0;
915          if (*vs == 'X') {
916                  xpos = 1; vs++;
917          } else if (*vs == 'x') {
# Line 675 | Line 927 | register char  *vs;
927          } else if (*vs == 'z') {
928                  zpos = -1; vs++;
929          }
930 <        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
930 >        viewtype = 'v';
931 >        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h' | *vs == 'c')
932                  viewtype = *vs++;
680        else if (!*vs || isspace(*vs))
681                viewtype = 'v';
933          cp = viewopts;
934 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
934 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
935                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
936                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
937                                  &cent[0], &dim[0], &cent[1], &dim[1],
938 <                                &cent[2], &dim[2]) != 6) {
939 <                        fprintf(stderr, "%s: bad zone specification\n",
940 <                                        progname);
941 <                        exit(1);
938 >                                &cent[2], &dim[2]) != 6)
939 >                        badvalue(ZONE);
940 >                for (i = 0; i < 3; i++) {
941 >                        dim[i] -= cent[i];
942 >                        if (dim[i] <= FTINY)
943 >                                badvalue(ZONE);
944 >                        cent[i] += .5*dim[i];
945                  }
946 <                dim[0] -= cent[0];
693 <                dim[1] -= cent[1];
694 <                dim[2] -= cent[2];
695 <                exterior = vlet(ZONE) == 'E';
696 <                mult = exterior ? 2. : .45 ;
946 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
947                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
948                                  cent[0]+xpos*mult*dim[0],
949                                  cent[1]+ypos*mult*dim[1],
950                                  cent[2]+zpos*mult*dim[2],
951                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
952                  cp += strlen(cp);
953 <                switch (vlet(UP)) {
954 <                case 'Z':
955 <                        if (xpos|ypos) {
956 <                                cp = addarg(cp, "-vu 0 0 1");
957 <                                break;
958 <                        }
959 <                /* fall through */
710 <                case 'Y':
711 <                        if (xpos|zpos) {
712 <                                cp = addarg(cp, "-vu 0 1 0");
713 <                                break;
714 <                        }
715 <                /* fall through */
716 <                case 'X':
717 <                        if (ypos|zpos)
718 <                                cp = addarg(cp, "-vu 1 0 0");
719 <                        else
720 <                                cp = addarg(cp, "-vu 0 0 1");
953 >                                        /* redirect up axis if necessary */
954 >                switch (upax) {
955 >                case 3:                 /* plus or minus Z axis */
956 >                case -3:
957 >                case 0:
958 >                        if (!(xpos|ypos))
959 >                                upax = 2;
960                          break;
961 <                default:
962 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
963 <                                        progname, vnam(UP));
964 <                        exit(1);
961 >                case 2:                 /* plus or minus Y axis */
962 >                case -2:
963 >                        if (!(xpos|zpos))
964 >                                upax = 1;
965 >                        break;
966 >                case 1:                 /* plus or minus X axis */
967 >                case -1:
968 >                        if (!(ypos|zpos))
969 >                                upax = 3;
970 >                        break;
971                  }
972 +                cp = addarg(cp, vup[upax+3]);
973                  switch (viewtype) {
974                  case 'v':
975                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 737 | Line 983 | register char  *vs;
983                  case 'h':
984                          cp = addarg(cp, "-vh 180 -vv 180");
985                          break;
986 +                case 'c':
987 +                        cp = addarg(cp, "-vh 180 -vv 90");
988 +                        break;
989                  }
990 <        } else
991 <                while (*vs && !isspace(*vs))    /* else skip id */
992 <                        vs++;
993 <                                        /* append any additional options */
994 <        while (isspace(*vs)) vs++;
990 >        } else {
991 >                while (!isspace(*vs))           /* else skip id */
992 >                        if (!*vs++)
993 >                                return(NULL);
994 >                if (upax) {                     /* specify up vector */
995 >                        strcpy(cp, vup[upax+3]);
996 >                        cp += strlen(cp);
997 >                }
998 >        }
999 >        if (cp == viewopts)             /* append any additional options */
1000 >                vs++;           /* skip prefixed space if unneeded */
1001          strcpy(cp, vs);
1002 + #ifdef _WIN32
1003 +        if (strlen(viewopts) > 40) {
1004 +                setenv("VIEW", viewopts);
1005 +                return("$VIEW");
1006 +        }
1007 + #endif
1008          return(viewopts);
1009   }
1010  
# Line 751 | Line 1012 | register char  *vs;
1012   char *
1013   getview(n, vn)                          /* get view n, or NULL if none */
1014   int     n;
1015 < char    *vn;
1015 > char    *vn;            /* returned view name */
1016   {
1017          register char   *mv;
1018  
1019 <        if (viewselect != NULL) {
1019 >        if (viewselect != NULL) {               /* command-line selected */
1020                  if (n)                          /* only do one */
1021                          return(NULL);
1022                  if (viewselect[0] == '-') {     /* already specified */
# Line 768 | Line 1029 | char   *vn;
1029                                  ;
1030                          *vn = '\0';
1031                  }
1032 +                                                /* view number? */
1033 +                if (isint(viewselect))
1034 +                        return(specview(nvalue(VIEWS, atoi(viewselect)-1)));
1035                                                  /* check list */
1036 <                while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1036 >                while ((mv = nvalue(VIEWS, n++)) != NULL)
1037                          if (matchword(viewselect, mv))
1038                                  return(specview(mv));
1039                  return(specview(viewselect));   /* standard view? */
1040          }
1041 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
1042 <                if (*mv != '-')
1043 <                        while (*mv && !isspace(*mv))
1044 <                                *vn++ = *mv++;
1041 >        mv = nvalue(VIEWS, n);          /* use view n */
1042 >        if (vn != NULL & mv != NULL) {
1043 >                register char   *mv2 = mv;
1044 >                if (*mv2 != '-')
1045 >                        while (*mv2 && !isspace(*mv2))
1046 >                                *vn++ = *mv2++;
1047                  *vn = '\0';
1048          }
1049 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
1049 >        return(specview(mv));
1050   }
1051  
1052  
1053 < rview(opts)                             /* run rview with first view */
1054 < char    *opts;
1053 > int
1054 > myprintview(vopts, fp)                  /* print out selected view */
1055 > register char   *vopts;
1056 > FILE    *fp;
1057   {
1058 <        char    combuf[512];
1058 >        VIEW    vwr;
1059 >        char    buf[128];
1060 >        register char   *cp;
1061 > again:
1062 >        if (vopts == NULL)
1063 >                return(-1);
1064 > #ifdef _WIN32
1065 >        if (vopts[0] == '$') {
1066 >                vopts = getenv(vopts+1);
1067 >                goto again;
1068 >        }
1069 > #endif
1070 >        copystruct(&vwr, &stdview);
1071 >        sscanview(&vwr, cp=vopts);              /* set initial options */
1072 >        while ((cp = strstr(cp, "-vf ")) != NULL &&
1073 >                        *atos(buf, sizeof(buf), cp += 4)) {
1074 >                viewfile(buf, &vwr, NULL);      /* load -vf file */
1075 >                sscanview(&vwr, cp);            /* reset tail */
1076 >        }
1077 >        fputs(VIEWSTR, fp);
1078 >        fprintview(&vwr, fp);                   /* print full spec. */
1079 >        fputc('\n', fp);
1080 >        return(0);
1081 > }
1082 >
1083 >
1084 > rview(opts, po)                         /* run rview with first view */
1085 > char    *opts, *po;
1086 > {
1087 >        char    *vw;
1088 >        char    combuf[PATH_MAX];
1089                                          /* build command */
1090 <        sprintf(combuf, "rview %s%s ", getview(0, NULL), opts);
1090 >        if (touchonly || (vw = getview(0, NULL)) == NULL)
1091 >                return;
1092 >        if (sayview)
1093 >                myprintview(vw, stdout);
1094 >        sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1095          if (rvdevice != NULL)
1096                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1097 <        strcat(combuf, vval(OCTREE));
1098 <        if (!silent) {                  /* echo it */
1099 <                printf("\t%s\n", combuf);
1100 <                fflush(stdout);
799 <        }
800 <        if (noaction)
801 <                return;
802 <        if (system(combuf)) {           /* run it */
1097 >        if (vdef(EXPOSURE))
1098 >                sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1099 >        strcat(combuf, oct1name);
1100 >        if (runcom(combuf)) {           /* run it */
1101                  fprintf(stderr, "%s: error running rview\n", progname);
1102 <                exit(1);
1102 >                quit(1);
1103          }
1104   }
1105  
1106  
1107 < rpict(opts)                             /* run rpict and pfilt for each view */
1108 < char    *opts;
1107 > rpict(opts, po)                         /* run rpict and pfilt for each view */
1108 > char    *opts, *po;
1109   {
1110 <        char    combuf[512];
1111 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
1112 <        char    pfopts[64];
1110 >        char    combuf[PATH_MAX];
1111 >        char    rawfile[PATH_MAX], picfile[PATH_MAX];
1112 >        char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1113 >        char    rppopt[128], *pfile = NULL;
1114 >        char    pfopts[128];
1115          char    vs[32], *vw;
1116          int     vn, mult;
1117 +        FILE    *fp;
1118 +        time_t  rfdt, pfdt;
1119                                          /* get pfilt options */
1120          pfiltopts(pfopts);
1121                                          /* get resolution, reporting */
1122 <        mult = vscale(QUALITY)+1;
1122 >        switch (vscale(QUALITY)) {
1123 >        case LOW:
1124 >                mult = 1;
1125 >                break;
1126 >        case MEDIUM:
1127 >                mult = 2;
1128 >                break;
1129 >        case HIGH:
1130 >                mult = 3;
1131 >                break;
1132 >        }
1133          {
1134                  int     xres, yres;
1135                  double  aspect;
# Line 829 | Line 1141 | char   *opts;
1141                  else if (n) {
1142                          if (n == 1) yres = xres;
1143                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1144 <                } else {
1145 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
834 <                                        progname, vnam(RESOLUTION));
835 <                        exit(1);
836 <                }
1144 >                } else
1145 >                        badvalue(RESOLUTION);
1146          }
1147          rep[0] = '\0';
1148          if (vdef(REPORT)) {
# Line 844 | Line 1153 | char   *opts;
1153                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1154                  else if (n == 1)
1155                          sprintf(rep, " -t %d", (int)(minutes*60));
1156 <                else {
1157 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
849 <                                        progname, vnam(REPORT));
850 <                        exit(1);
851 <                }
1156 >                else
1157 >                        badvalue(REPORT);
1158          }
1159 <                                        /* do each view */
1160 <        vn = 0;
1159 >                                        /* set up parallel rendering */
1160 >        if (nprocs > 1 & !vdef(ZFILE)) {
1161 >                strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1162 >                pfile = rppopt+9;
1163 >                if (mktemp(pfile) == NULL)
1164 >                        pfile = NULL;
1165 >        }
1166 >        vn = 0;                                 /* do each view */
1167          while ((vw = getview(vn++, vs)) != NULL) {
1168 +                if (sayview)
1169 +                        myprintview(vw, stdout);
1170                  if (!vs[0])
1171                          sprintf(vs, "%d", vn);
1172                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1173 +                if (vdef(ZFILE))
1174 +                        sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1175 +                else
1176 +                        zopt[0] = '\0';
1177                                                  /* check date on picture */
1178 <                if (fdate(picfile) > octreedate)
1178 >                pfdt = fdate(picfile);
1179 >                if (pfdt >= oct1date)
1180                          continue;
1181 +                                                /* get raw file name */
1182 +                sprintf(rawfile, "%s_%s.unf",
1183 +                        vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs);
1184 +                rfdt = fdate(rawfile);
1185 +                if (touchonly) {                /* update times only */
1186 +                        if (rfdt) {
1187 +                                if (rfdt < oct1date)
1188 +                                        touch(rawfile);
1189 +                        } else if (pfdt && pfdt < oct1date)
1190 +                                touch(picfile);
1191 +                        continue;
1192 +                }
1193 +                if (next_process()) {           /* parallel running? */
1194 +                        if (pfile != NULL)
1195 +                                sleep(20);
1196 +                        continue;
1197 +                }
1198 +                /* XXX Remember to call finish_process() */
1199                                                  /* build rpict command */
1200 <                sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1201 <                if (fdate(rawfile) > octreedate)        /* recover */
1202 <                        sprintf(combuf, "rpict%s%s -ro %s %s",
1203 <                                        rep, opts, rawfile, vval(OCTREE));
1204 <                else {
1200 >                if (rfdt >= oct1date) {         /* recover */
1201 >                        sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1202 >                                rep, po, opts, zopt, rawfile, oct1name);
1203 >                        if (runcom(combuf))     /* run rpict */
1204 >                                goto rperror;
1205 >                } else {
1206                          if (overture) {         /* run overture calculation */
1207                                  sprintf(combuf,
1208                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1209                                                  rep, vw, opts,
1210 <                                                vval(OCTREE), rawfile);
1211 <                                if (!silent) {
874 <                                        printf("\t%s\n", combuf);
875 <                                        fflush(stdout);
876 <                                }
877 <                                if (!noaction && system(combuf)) {
1210 >                                                oct1name, overfile);
1211 >                                if (runcom(combuf)) {
1212                                          fprintf(stderr,
1213 <                        "%s: error in overture for view %s\n\t%s removed\n",
1214 <                                                progname, vs, rawfile);
1215 <                                        unlink(rawfile);
882 <                                        exit(1);
1213 >                                        "%s: error in overture for view %s\n",
1214 >                                                progname, vs);
1215 >                                        quit(1);
1216                                  }
1217 + #ifndef NULL_DEVICE
1218 +                                rmfile(overfile);
1219 + #endif
1220                          }
1221 <                        sprintf(combuf, "rpict%s %s %s%s %s > %s",
1222 <                                        rep, vw, res, opts,
1223 <                                        vval(OCTREE), rawfile);
1221 >                        sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1222 >                                        rep, vw, res, po, opts,
1223 >                                        zopt, oct1name, rawfile);
1224 >                        if (pfile != NULL && inchild()) {
1225 >                                                /* rpict persistent mode */
1226 >                                if (!silent)
1227 >                                        printf("\t%s\n", combuf);
1228 >                                sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1229 >                                                rep, rppopt, res, po, opts,
1230 >                                                oct1name, rawfile);
1231 >                                fflush(stdout);
1232 >                                fp = popen(combuf, "w");
1233 >                                if (fp == NULL)
1234 >                                        goto rperror;
1235 >                                myprintview(vw, fp);
1236 >                                if (pclose(fp))
1237 >                                        goto rperror;
1238 >                        } else {                /* rpict normal mode */
1239 >                                if (runcom(combuf))
1240 >                                        goto rperror;
1241 >                        }
1242                  }
1243 <                if (!silent) {                  /* echo rpict command */
890 <                        printf("\t%s\n", combuf);
891 <                        fflush(stdout);
892 <                }
893 <                if (!noaction && system(combuf)) {      /* run rpict */
894 <                        fprintf(stderr, "%s: error rendering view %s\n",
895 <                                        progname, vs);
896 <                        exit(1);
897 <                }
1243 >                if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1244                                                  /* build pfilt command */
1245 <                if (mult > 1)
1246 <                        sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1245 >                        if (mult > 1)
1246 >                                sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1247                                          pfopts, mult, mult, rawfile, picfile);
1248 <                else
1249 <                        sprintf(combuf, "pfilt%s %s > %s", pfopts,
1250 <                                        rawfile, picfile);
1251 <                if (!silent) {                  /* echo pfilt command */
1252 <                        printf("\t%s\n", combuf);
1253 <                        fflush(stdout);
1248 >                        else
1249 >                                sprintf(combuf, "pfilt%s %s > %s", pfopts,
1250 >                                                rawfile, picfile);
1251 >                        if (runcom(combuf)) {   /* run pfilt */
1252 >                                fprintf(stderr,
1253 >                                "%s: error filtering view %s\n\t%s removed\n",
1254 >                                                progname, vs, picfile);
1255 >                                unlink(picfile);
1256 >                                quit(1);
1257 >                        }
1258                  }
1259 <                if (!noaction && system(combuf)) {      /* run pfilt */
1260 <                        fprintf(stderr,
1261 <                        "%s: error filtering view %s\n\t%s removed\n",
1262 <                                        progname, vs, picfile);
1263 <                        unlink(picfile);
1264 <                        exit(1);
1259 >                                                /* remove/rename raw file */
1260 >                if (vdef(RAWFILE)) {
1261 >                        sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1262 >                        mvfile(rawfile, combuf);
1263 >                } else
1264 >                        rmfile(rawfile);
1265 >                finish_process();               /* leave if child */
1266 >        }
1267 >        wait_process(1);                /* wait for children to finish */
1268 >        if (pfile != NULL) {            /* clean up rpict persistent mode */
1269 >                int     pid;
1270 >                fp = fopen(pfile, "r");
1271 >                if (fp != NULL) {
1272 >                        if (fscanf(fp, "%*s %d", &pid) != 1 ||
1273 >                                        kill(pid, 1) == -1)
1274 >                                unlink(pfile);
1275 >                        fclose(fp);
1276                  }
1277 <                                                /* remove raw file */
1278 <                if (!silent)
1279 < #ifdef MSDOS
1280 <                        printf("\tdel %s\n", rawfile);
1281 < #else
1282 <                        printf("\trm %s\n", rawfile);
1277 >        }
1278 >        return;
1279 > rperror:
1280 >        fprintf(stderr, "%s: error rendering view %s\n", progname, vs);
1281 >        quit(1);
1282 > }
1283 >
1284 >
1285 > touch(fn)                       /* update a file */
1286 > char    *fn;
1287 > {
1288 >        if (!silent)
1289 >                printf("\ttouch %s\n", fn);
1290 >        if (!nprocs)
1291 >                return(0);
1292 > #ifdef notused
1293 >        if (access(fn, F_OK) == -1)             /* create it */
1294 >                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1295 >                        return(-1);
1296   #endif
1297 <                if (!noaction)
1298 <                        unlink(rawfile);
1297 >        return(setfdate(fn, time((time_t *)NULL)));
1298 > }
1299 >
1300 >
1301 > runcom(cs)                      /* run command */
1302 > char    *cs;
1303 > {
1304 >        if (!silent)            /* echo it */
1305 >                printf("\t%s\n", cs);
1306 >        if (!nprocs)
1307 >                return(0);
1308 >        fflush(stdout);         /* flush output and pass to shell */
1309 >        return(system(cs));
1310 > }
1311 >
1312 >
1313 > rmfile(fn)                      /* remove a file */
1314 > char    *fn;
1315 > {
1316 >        if (!silent)
1317 >                printf("\t%s %s\n", DELCMD, fn);
1318 >        if (!nprocs)
1319 >                return(0);
1320 >        return(unlink(fn));
1321 > }
1322 >
1323 >
1324 > mvfile(fold, fnew)              /* move a file */
1325 > char    *fold, *fnew;
1326 > {
1327 >        if (!silent)
1328 >                printf("\t%s %s %s\n", RENAMECMD, fold, fnew);
1329 >        if (!nprocs)
1330 >                return(0);
1331 >        return(rename(fold, fnew));
1332 > }
1333 >
1334 >
1335 > #ifdef RHAS_FORK_EXEC
1336 > int
1337 > next_process()                  /* fork the next process (max. nprocs) */
1338 > {
1339 >        int     child_pid;
1340 >
1341 >        if (nprocs <= 1)
1342 >                return(0);              /* it's us or no one */
1343 >        if (inchild()) {
1344 >                fprintf(stderr, "%s: internal error 1 in spawn_process()\n",
1345 >                                progname);
1346 >                quit(1);
1347          }
1348 +        if (children_running >= nprocs)
1349 +                wait_process(0);        /* wait for someone to finish */
1350 +        fflush(stdout);
1351 +        child_pid = fork();             /* split process */
1352 +        if (child_pid == 0) {           /* we're the child */
1353 +                children_running = -1;
1354 +                return(0);
1355 +        }
1356 +        if (child_pid > 0) {            /* we're the parent */
1357 +                ++children_running;
1358 +                return(1);
1359 +        }
1360 +        fprintf(stderr, "%s: warning -- fork() failed\n", progname);
1361 +        return(0);
1362 + }
1363 +
1364 + wait_process(all)                       /* wait for process(es) to finish */
1365 + int     all;
1366 + {
1367 +        int     ourstatus = 0;
1368 +        int     pid, status;
1369 +
1370 +        if (all)
1371 +                all = children_running;
1372 +        else if (children_running > 0)
1373 +                all = 1;
1374 +        while (all-- > 0) {
1375 +                pid = wait(&status);
1376 +                if (pid < 0)
1377 +                        syserr(progname);
1378 +                status = status>>8 & 0xff;
1379 +                --children_running;
1380 +                if (status != 0) {      /* child's problem is our problem */
1381 +                        if (ourstatus == 0 & children_running > 0)
1382 +                                fprintf(stderr, "%s: waiting for remaining processes\n",
1383 +                                                progname);
1384 +                        ourstatus = status;
1385 +                        all = children_running;
1386 +                }
1387 +        }
1388 +        if (ourstatus != 0)
1389 +                quit(ourstatus);        /* bad status from child */
1390 + }
1391 + #else   /* ! RHAS_FORK_EXEC */
1392 + int
1393 + next_process()
1394 + {
1395 +        return(0);                      /* cannot start new process */
1396 + }
1397 + wait_process(all)
1398 + int     all;
1399 + {
1400 +        (void)all;                      /* no one to wait for */
1401 + }
1402 + int
1403 + kill(pid, sig) /* win|unix_process.c should also wait and kill */
1404 + int pid, sig;
1405 + {
1406 +        return 0;
1407 + }
1408 + #endif  /* ! RHAS_FORK_EXEC */
1409 +
1410 + finish_process()                        /* exit a child process */
1411 + {
1412 +        if (!inchild())
1413 +                return;                 /* in parent -- noop */
1414 +        exit(0);
1415 + }
1416 +
1417 + #ifdef _WIN32
1418 + setenv(vname, value)            /* set an environment variable */
1419 + char    *vname, *value;
1420 + {
1421 +        register char   *evp;
1422 +
1423 +        evp = bmalloc(strlen(vname)+strlen(value)+2);
1424 +        if (evp == NULL)
1425 +                syserr(progname);
1426 +        sprintf(evp, "%s=%s", vname, value);
1427 +        if (putenv(evp) != 0) {
1428 +                fprintf(stderr, "%s: out of environment space\n", progname);
1429 +                quit(1);
1430 +        }
1431 +        if (!silent)
1432 +                printf("set %s\n", evp);
1433 + }
1434 + #endif
1435 +
1436 +
1437 + badvalue(vc)                    /* report bad variable value and exit */
1438 + int     vc;
1439 + {
1440 +        fprintf(stderr, "%s: bad value for variable '%s'\n",
1441 +                        progname, vnam(vc));
1442 +        quit(1);
1443 + }
1444 +
1445 +
1446 + syserr(s)                       /* report a system error and exit */
1447 + char    *s;
1448 + {
1449 +        perror(s);
1450 +        quit(1);
1451 + }
1452 +
1453 +
1454 + void
1455 + quit(ec)                        /* exit program */
1456 + int     ec;
1457 + {
1458 +        exit(ec);
1459   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines