7 |
|
|
8 |
|
#include "copyright.h" |
9 |
|
|
10 |
< |
#include "ray.h" |
10 |
> |
#include <sys/types.h> |
11 |
> |
#include <signal.h> |
12 |
|
|
13 |
+ |
#include "platform.h" |
14 |
+ |
#include "rtprocess.h" /* getpid() */ |
15 |
+ |
#include "resolu.h" |
16 |
+ |
#include "ray.h" |
17 |
|
#include "source.h" |
13 |
– |
|
18 |
|
#include "ambient.h" |
15 |
– |
|
19 |
|
#include "random.h" |
17 |
– |
|
20 |
|
#include "paths.h" |
21 |
|
|
20 |
– |
#include <sys/types.h> |
21 |
– |
|
22 |
– |
#include <signal.h> |
22 |
|
/* persistent processes define */ |
23 |
|
#ifdef F_SETLKW |
24 |
|
#define PERSIST 1 /* normal persist */ |
27 |
|
#endif |
28 |
|
|
29 |
|
char *progname; /* argv[0] */ |
31 |
– |
|
30 |
|
char *octname; /* octree name */ |
33 |
– |
|
31 |
|
char *sigerr[NSIG]; /* signal error messages */ |
35 |
– |
|
32 |
|
char *shm_boundary = NULL; /* boundary of shared memory */ |
37 |
– |
|
33 |
|
char *errfile = NULL; /* error output file */ |
34 |
|
|
35 |
|
extern char *formstr(); /* string from format */ |
46 |
|
extern char *tralist[]; /* list of modifers to trace (or no) */ |
47 |
|
extern int traincl; /* include == 1, exclude == 0 */ |
48 |
|
|
49 |
< |
void onsig(); |
55 |
< |
void sigdie(); |
56 |
< |
void printdefaults(); |
49 |
> |
static int loadflags = ~IO_FILES; /* what to load from octree */ |
50 |
|
|
51 |
+ |
static void onsig(int signo); |
52 |
+ |
static void sigdie(int signo, char *msg); |
53 |
+ |
static void printdefaults(void); |
54 |
|
|
55 |
+ |
|
56 |
|
int |
57 |
< |
main(argc, argv) |
61 |
< |
int argc; |
62 |
< |
char *argv[]; |
57 |
> |
main(int argc, char *argv[]) |
58 |
|
{ |
59 |
|
#define check(ol,al) if (argv[i][ol] || \ |
60 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
66 |
|
case 'n': case 'N': case 'f': case 'F': \ |
67 |
|
case '-': case '0': var = 0; break; \ |
68 |
|
default: goto badopt; } |
74 |
– |
int loadflags = ~IO_FILES; |
69 |
|
int persist = 0; |
70 |
|
char **tralp; |
71 |
|
int duped1; |
170 |
|
} |
171 |
|
if (argv[i][2] == 'I') { /* file */ |
172 |
|
rval = wordfile(tralp, |
173 |
< |
getpath(argv[++i],getlibpath(),R_OK)); |
173 |
> |
getpath(argv[++i],getrlibpath(),R_OK)); |
174 |
|
if (rval < 0) { |
175 |
|
sprintf(errmsg, |
176 |
|
"cannot open trace include file \"%s\"", |
192 |
|
} |
193 |
|
if (argv[i][2] == 'E') { /* file */ |
194 |
|
rval = wordfile(tralp, |
195 |
< |
getpath(argv[++i],getlibpath(),R_OK)); |
195 |
> |
getpath(argv[++i],getrlibpath(),R_OK)); |
196 |
|
if (rval < 0) { |
197 |
|
sprintf(errmsg, |
198 |
|
"cannot open trace exclude file \"%s\"", |
231 |
|
initurand(2048); |
232 |
|
/* set up signal handling */ |
233 |
|
sigdie(SIGINT, "Interrupt"); |
234 |
+ |
#ifdef SIGHUP |
235 |
|
sigdie(SIGHUP, "Hangup"); |
236 |
+ |
#endif |
237 |
|
sigdie(SIGTERM, "Terminate"); |
238 |
+ |
#ifdef SIGPIPE |
239 |
|
sigdie(SIGPIPE, "Broken pipe"); |
240 |
+ |
#endif |
241 |
+ |
#ifdef SIGALRM |
242 |
|
sigdie(SIGALRM, "Alarm clock"); |
243 |
+ |
#endif |
244 |
|
#ifdef SIGXCPU |
245 |
|
sigdie(SIGXCPU, "CPU limit exceeded"); |
246 |
|
sigdie(SIGXFSZ, "File size exceeded"); |
274 |
|
openheader(); |
275 |
|
} |
276 |
|
#endif |
277 |
– |
#ifdef MSDOS |
277 |
|
if (outform != 'a') |
278 |
< |
setmode(fileno(stdout), O_BINARY); |
280 |
< |
if (octname == NULL) |
281 |
< |
setmode(fileno(stdin), O_BINARY); |
282 |
< |
#endif |
278 |
> |
SET_FILE_BINARY(stdout); |
279 |
|
readoct(octname, loadflags, &thescene, NULL); |
280 |
|
nsceneobjs = nobjects; |
281 |
|
|
341 |
|
badopt: |
342 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
343 |
|
error(USER, errmsg); |
344 |
+ |
return 1; /* pro forma return */ |
345 |
|
|
346 |
|
#undef check |
347 |
|
#undef bool |
349 |
|
|
350 |
|
|
351 |
|
void |
352 |
< |
wputs(s) /* warning output function */ |
353 |
< |
char *s; |
352 |
> |
wputs( /* warning output function */ |
353 |
> |
char *s |
354 |
> |
) |
355 |
|
{ |
356 |
|
int lasterrno = errno; |
357 |
|
eputs(s); |
360 |
|
|
361 |
|
|
362 |
|
void |
363 |
< |
eputs(s) /* put string to stderr */ |
364 |
< |
register char *s; |
363 |
> |
eputs( /* put string to stderr */ |
364 |
> |
register char *s |
365 |
> |
) |
366 |
|
{ |
367 |
|
static int midline = 0; |
368 |
|
|
380 |
|
} |
381 |
|
|
382 |
|
|
383 |
< |
void |
384 |
< |
onsig(signo) /* fatal signal */ |
385 |
< |
int signo; |
383 |
> |
static void |
384 |
> |
onsig( /* fatal signal */ |
385 |
> |
int signo |
386 |
> |
) |
387 |
|
{ |
388 |
|
static int gotsig = 0; |
389 |
|
|
390 |
|
if (gotsig++) /* two signals and we're gone! */ |
391 |
|
_exit(signo); |
392 |
|
|
393 |
+ |
#ifdef SIGALRM |
394 |
|
alarm(15); /* allow 15 seconds to clean up */ |
395 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
396 |
+ |
#endif |
397 |
|
eputs("signal - "); |
398 |
|
eputs(sigerr[signo]); |
399 |
|
eputs("\n"); |
401 |
|
} |
402 |
|
|
403 |
|
|
404 |
< |
void |
405 |
< |
sigdie(signo, msg) /* set fatal signal */ |
406 |
< |
int signo; |
407 |
< |
char *msg; |
404 |
> |
static void |
405 |
> |
sigdie( /* set fatal signal */ |
406 |
> |
int signo, |
407 |
> |
char *msg |
408 |
> |
) |
409 |
|
{ |
410 |
|
if (signal(signo, onsig) == SIG_IGN) |
411 |
|
signal(signo, SIG_IGN); |
413 |
|
} |
414 |
|
|
415 |
|
|
416 |
< |
void |
417 |
< |
printdefaults() /* print default values to stdout */ |
416 |
> |
static void |
417 |
> |
printdefaults(void) /* print default values to stdout */ |
418 |
|
{ |
419 |
|
register char *cp; |
420 |
|
|
421 |
|
if (imm_irrad) |
422 |
|
printf("-I+\t\t\t\t# immediate irradiance on\n"); |
423 |
< |
printf("-x %-9d\t\t\t# x resolution\n", hresolu); |
423 |
> |
printf("-x %-9d\t\t\t# x resolution (flush interval)\n", hresolu); |
424 |
|
printf("-y %-9d\t\t\t# y resolution\n", vresolu); |
425 |
|
printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : |
426 |
|
"-ld-\t\t\t\t# limit distance off\n"); |
427 |
+ |
printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-', |
428 |
+ |
loadflags & IO_INFO ? "output" : "no"); |
429 |
|
printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", |
430 |
|
inform, outform, formstr(inform), formstr(outform)); |
431 |
< |
printf("-o%s\t\t\t\t# output", outvals); |
431 |
> |
printf("-o%-9s\t\t\t# output", outvals); |
432 |
|
for (cp = outvals; *cp; cp++) |
433 |
|
switch (*cp) { |
434 |
< |
case 't': printf(" trace"); break; |
434 |
> |
case 't': case 'T': printf(" trace"); break; |
435 |
|
case 'o': printf(" origin"); break; |
436 |
|
case 'd': printf(" direction"); break; |
437 |
|
case 'v': printf(" value"); break; |
443 |
|
case 's': printf(" surface"); break; |
444 |
|
case 'w': printf(" weight"); break; |
445 |
|
case 'm': printf(" modifier"); break; |
446 |
+ |
case 'M': printf(" material"); break; |
447 |
+ |
case 'W': printf(" contribution"); break; |
448 |
+ |
case '-': printf(" stroke"); break; |
449 |
|
} |
450 |
|
putchar('\n'); |
451 |
|
printf(erract[WARNING].pf != NULL ? |