| 7 |
|
|
| 8 |
|
#include "copyright.h" |
| 9 |
|
|
| 10 |
< |
#include "ray.h" |
| 10 |
> |
#include <signal.h> |
| 11 |
|
|
| 12 |
+ |
#include "platform.h" |
| 13 |
+ |
#include "rtprocess.h" /* getpid() */ |
| 14 |
+ |
#include "resolu.h" |
| 15 |
+ |
#include "ray.h" |
| 16 |
|
#include "source.h" |
| 13 |
– |
|
| 17 |
|
#include "ambient.h" |
| 15 |
– |
|
| 18 |
|
#include "random.h" |
| 17 |
– |
|
| 19 |
|
#include "paths.h" |
| 20 |
|
|
| 20 |
– |
#include <sys/types.h> |
| 21 |
– |
|
| 22 |
– |
#include <signal.h> |
| 21 |
|
/* persistent processes define */ |
| 22 |
|
#ifdef F_SETLKW |
| 23 |
|
#define PERSIST 1 /* normal persist */ |
| 26 |
|
#endif |
| 27 |
|
|
| 28 |
|
char *progname; /* argv[0] */ |
| 31 |
– |
|
| 29 |
|
char *octname; /* octree name */ |
| 33 |
– |
|
| 30 |
|
char *sigerr[NSIG]; /* signal error messages */ |
| 35 |
– |
|
| 31 |
|
char *shm_boundary = NULL; /* boundary of shared memory */ |
| 37 |
– |
|
| 32 |
|
char *errfile = NULL; /* error output file */ |
| 33 |
|
|
| 34 |
|
extern char *formstr(); /* string from format */ |
| 45 |
|
extern char *tralist[]; /* list of modifers to trace (or no) */ |
| 46 |
|
extern int traincl; /* include == 1, exclude == 0 */ |
| 47 |
|
|
| 48 |
< |
void onsig(); |
| 55 |
< |
void sigdie(); |
| 56 |
< |
void printdefaults(); |
| 48 |
> |
static int loadflags = ~IO_FILES; /* what to load from octree */ |
| 49 |
|
|
| 50 |
+ |
static void onsig(int signo); |
| 51 |
+ |
static void sigdie(int signo, char *msg); |
| 52 |
+ |
static void printdefaults(void); |
| 53 |
|
|
| 54 |
+ |
|
| 55 |
|
int |
| 56 |
< |
main(argc, argv) |
| 61 |
< |
int argc; |
| 62 |
< |
char *argv[]; |
| 56 |
> |
main(int argc, char *argv[]) |
| 57 |
|
{ |
| 58 |
|
#define check(ol,al) if (argv[i][ol] || \ |
| 59 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
| 65 |
|
case 'n': case 'N': case 'f': case 'F': \ |
| 66 |
|
case '-': case '0': var = 0; break; \ |
| 67 |
|
default: goto badopt; } |
| 74 |
– |
int loadflags = ~IO_FILES; |
| 68 |
|
int persist = 0; |
| 69 |
|
char **tralp; |
| 70 |
|
int duped1; |
| 227 |
|
/* initialize object types */ |
| 228 |
|
initotypes(); |
| 229 |
|
/* initialize urand */ |
| 230 |
< |
initurand(2048); |
| 230 |
> |
if (rand_samp) { |
| 231 |
> |
srandom((long)time(0)); |
| 232 |
> |
initurand(0); |
| 233 |
> |
} else { |
| 234 |
> |
srandom(0L); |
| 235 |
> |
initurand(2048); |
| 236 |
> |
} |
| 237 |
|
/* set up signal handling */ |
| 238 |
|
sigdie(SIGINT, "Interrupt"); |
| 239 |
+ |
#ifdef SIGHUP |
| 240 |
|
sigdie(SIGHUP, "Hangup"); |
| 241 |
+ |
#endif |
| 242 |
|
sigdie(SIGTERM, "Terminate"); |
| 243 |
+ |
#ifdef SIGPIPE |
| 244 |
|
sigdie(SIGPIPE, "Broken pipe"); |
| 245 |
+ |
#endif |
| 246 |
+ |
#ifdef SIGALRM |
| 247 |
|
sigdie(SIGALRM, "Alarm clock"); |
| 248 |
+ |
#endif |
| 249 |
|
#ifdef SIGXCPU |
| 250 |
|
sigdie(SIGXCPU, "CPU limit exceeded"); |
| 251 |
|
sigdie(SIGXFSZ, "File size exceeded"); |
| 279 |
|
openheader(); |
| 280 |
|
} |
| 281 |
|
#endif |
| 277 |
– |
#ifdef MSDOS |
| 282 |
|
if (outform != 'a') |
| 283 |
< |
setmode(fileno(stdout), O_BINARY); |
| 280 |
< |
if (octname == NULL) |
| 281 |
< |
setmode(fileno(stdin), O_BINARY); |
| 282 |
< |
#endif |
| 283 |
> |
SET_FILE_BINARY(stdout); |
| 284 |
|
readoct(octname, loadflags, &thescene, NULL); |
| 285 |
|
nsceneobjs = nobjects; |
| 286 |
|
|
| 309 |
|
while ((rval=fork()) == 0) { /* keep on forkin' */ |
| 310 |
|
pflock(1); |
| 311 |
|
pfhold(); |
| 312 |
+ |
ambsync(); /* load new values */ |
| 313 |
|
} |
| 314 |
|
if (rval < 0) |
| 315 |
|
error(SYSTEM, "cannot fork child for persist function"); |
| 316 |
< |
pfdetach(); /* parent exits */ |
| 316 |
> |
pfdetach(); /* parent will run then exit */ |
| 317 |
|
} |
| 318 |
|
} |
| 319 |
|
runagain: |
| 336 |
|
} |
| 337 |
|
} |
| 338 |
|
if (persist == PCHILD) { /* wait for a signal then go again */ |
| 337 |
– |
close(duped1); /* release output handle */ |
| 339 |
|
pfhold(); |
| 340 |
|
raynum = nrays = 0; /* reinitialize */ |
| 341 |
|
goto runagain; |
| 346 |
|
badopt: |
| 347 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
| 348 |
|
error(USER, errmsg); |
| 349 |
+ |
return 1; /* pro forma return */ |
| 350 |
|
|
| 351 |
|
#undef check |
| 352 |
|
#undef bool |
| 354 |
|
|
| 355 |
|
|
| 356 |
|
void |
| 357 |
< |
wputs(s) /* warning output function */ |
| 358 |
< |
char *s; |
| 357 |
> |
wputs( /* warning output function */ |
| 358 |
> |
char *s |
| 359 |
> |
) |
| 360 |
|
{ |
| 361 |
|
int lasterrno = errno; |
| 362 |
|
eputs(s); |
| 365 |
|
|
| 366 |
|
|
| 367 |
|
void |
| 368 |
< |
eputs(s) /* put string to stderr */ |
| 369 |
< |
register char *s; |
| 368 |
> |
eputs( /* put string to stderr */ |
| 369 |
> |
register char *s |
| 370 |
> |
) |
| 371 |
|
{ |
| 372 |
|
static int midline = 0; |
| 373 |
|
|
| 385 |
|
} |
| 386 |
|
|
| 387 |
|
|
| 388 |
< |
void |
| 389 |
< |
onsig(signo) /* fatal signal */ |
| 390 |
< |
int signo; |
| 388 |
> |
static void |
| 389 |
> |
onsig( /* fatal signal */ |
| 390 |
> |
int signo |
| 391 |
> |
) |
| 392 |
|
{ |
| 393 |
|
static int gotsig = 0; |
| 394 |
|
|
| 395 |
|
if (gotsig++) /* two signals and we're gone! */ |
| 396 |
|
_exit(signo); |
| 397 |
|
|
| 398 |
+ |
#ifdef SIGALRM |
| 399 |
|
alarm(15); /* allow 15 seconds to clean up */ |
| 400 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
| 401 |
+ |
#endif |
| 402 |
|
eputs("signal - "); |
| 403 |
|
eputs(sigerr[signo]); |
| 404 |
|
eputs("\n"); |
| 406 |
|
} |
| 407 |
|
|
| 408 |
|
|
| 409 |
< |
void |
| 410 |
< |
sigdie(signo, msg) /* set fatal signal */ |
| 411 |
< |
int signo; |
| 412 |
< |
char *msg; |
| 409 |
> |
static void |
| 410 |
> |
sigdie( /* set fatal signal */ |
| 411 |
> |
int signo, |
| 412 |
> |
char *msg |
| 413 |
> |
) |
| 414 |
|
{ |
| 415 |
|
if (signal(signo, onsig) == SIG_IGN) |
| 416 |
|
signal(signo, SIG_IGN); |
| 418 |
|
} |
| 419 |
|
|
| 420 |
|
|
| 421 |
< |
void |
| 422 |
< |
printdefaults() /* print default values to stdout */ |
| 421 |
> |
static void |
| 422 |
> |
printdefaults(void) /* print default values to stdout */ |
| 423 |
|
{ |
| 424 |
|
register char *cp; |
| 425 |
|
|
| 426 |
|
if (imm_irrad) |
| 427 |
|
printf("-I+\t\t\t\t# immediate irradiance on\n"); |
| 428 |
< |
printf("-x %-9d\t\t\t# x resolution\n", hresolu); |
| 429 |
< |
printf("-y %-9d\t\t\t# y resolution\n", vresolu); |
| 428 |
> |
printf("-x %-9d\t\t\t# x resolution (flush interval)\n", hresolu); |
| 429 |
> |
printf("-y %-9d\t\t\t# y resolution\n", vresolu); |
| 430 |
|
printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : |
| 431 |
|
"-ld-\t\t\t\t# limit distance off\n"); |
| 432 |
+ |
printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-', |
| 433 |
+ |
loadflags & IO_INFO ? "output" : "no"); |
| 434 |
|
printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", |
| 435 |
|
inform, outform, formstr(inform), formstr(outform)); |
| 436 |
< |
printf("-o%s\t\t\t\t# output", outvals); |
| 436 |
> |
printf("-o%-9s\t\t\t# output", outvals); |
| 437 |
|
for (cp = outvals; *cp; cp++) |
| 438 |
|
switch (*cp) { |
| 439 |
< |
case 't': printf(" trace"); break; |
| 439 |
> |
case 't': case 'T': printf(" trace"); break; |
| 440 |
|
case 'o': printf(" origin"); break; |
| 441 |
|
case 'd': printf(" direction"); break; |
| 442 |
|
case 'v': printf(" value"); break; |
| 443 |
+ |
case 'V': printf(" contribution"); break; |
| 444 |
|
case 'l': printf(" length"); break; |
| 445 |
|
case 'L': printf(" first_length"); break; |
| 446 |
|
case 'p': printf(" point"); break; |
| 448 |
|
case 'N': printf(" unperturbed_normal"); break; |
| 449 |
|
case 's': printf(" surface"); break; |
| 450 |
|
case 'w': printf(" weight"); break; |
| 451 |
+ |
case 'W': printf(" coefficient"); break; |
| 452 |
|
case 'm': printf(" modifier"); break; |
| 453 |
+ |
case 'M': printf(" material"); break; |
| 454 |
+ |
case '-': printf(" stroke"); break; |
| 455 |
|
} |
| 456 |
|
putchar('\n'); |
| 457 |
|
printf(erract[WARNING].pf != NULL ? |