1 |
– |
/* Copyright (c) 1999 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Radiance holodeck generation controller |
6 |
|
*/ |
7 |
|
|
11 |
– |
#include "rholo.h" |
12 |
– |
#include "random.h" |
8 |
|
#include <signal.h> |
14 |
– |
#include <sys/types.h> |
9 |
|
#include <sys/stat.h> |
10 |
+ |
#include <string.h> |
11 |
|
|
12 |
+ |
#include "rholo.h" |
13 |
+ |
#include "random.h" |
14 |
+ |
|
15 |
|
#ifndef FRAGWARN |
16 |
|
#define FRAGWARN 20 /* fragmentation for warning (%) */ |
17 |
|
#endif |
41 |
|
|
42 |
|
int readinp = 0; /* read commands from stdin */ |
43 |
|
|
44 |
< |
int force = 0; /* allow overwrite of holodeck */ |
44 |
> |
int force = 0; /* allow overwrite of holodeck (-1 == read-only) */ |
45 |
|
|
46 |
|
time_t starttime; /* time we got started */ |
47 |
|
time_t endtime; /* time we should end by */ |
48 |
|
time_t reporttime; /* time for next report */ |
49 |
|
|
50 |
< |
long maxdisk; /* maximum file space (bytes) */ |
50 |
> |
off_t maxdisk; /* maximum file space (bytes) */ |
51 |
|
|
52 |
|
int rtargc = 1; /* rtrace command */ |
53 |
|
char *rtargv[128] = {"rtrace", NULL}; |
81 |
|
nowarn++; |
82 |
|
break; |
83 |
|
case 'f': /* force overwrite */ |
84 |
< |
force++; |
84 |
> |
force = 1; |
85 |
|
break; |
86 |
+ |
case 'r': /* read-only mode */ |
87 |
+ |
force = -1; |
88 |
+ |
break; |
89 |
|
case 'i': /* read input from stdin */ |
90 |
|
readinp++; |
91 |
|
break; |
128 |
|
HDGRID hdg[HDMAX]; |
129 |
|
/* set defaults */ |
130 |
|
setdefaults(hdg); |
131 |
+ |
/* check read-only */ |
132 |
+ |
if (force < 0) |
133 |
+ |
error(USER, "cannot create read-only holodeck"); |
134 |
|
/* holodeck exists? */ |
135 |
|
if (!force && access(hdkfile, R_OK|W_OK) == 0) |
136 |
|
error(USER, |
148 |
|
quit(0); |
149 |
|
userr: |
150 |
|
fprintf(stderr, |
151 |
< |
"Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", |
151 |
> |
"Usage: %s [-n nprocs][-o disp][-w][-r|-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", |
152 |
|
progname); |
153 |
|
quit(1); |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
+ |
void |
158 |
|
onsig(signo) /* fatal signal */ |
159 |
|
int signo; |
160 |
|
{ |
217 |
|
init_global(); |
218 |
|
/* record disk space limit */ |
219 |
|
if (!vdef(DISKSPACE)) |
220 |
< |
maxdisk = 0; |
220 |
> |
maxdisk = ((off_t)1<<(sizeof(off_t)*8-2)) - 1024; |
221 |
|
else |
222 |
|
maxdisk = 1024.*1024.*vflt(DISKSPACE); |
223 |
|
/* set up memory cache */ |
224 |
|
if (outdev == NULL) |
225 |
< |
hdcachesize = 0; /* manual flushing */ |
225 |
> |
hdcachesize = 0; /* manual flushing */ |
226 |
|
else if (vdef(CACHE)) |
227 |
|
hdcachesize = 1024.*1024.*vflt(CACHE); |
228 |
|
/* open report file */ |
277 |
|
sigdie(SIGXCPU, "CPU limit exceeded"); |
278 |
|
sigdie(SIGXFSZ, "File size exceeded"); |
279 |
|
#endif |
280 |
< |
/* protect holodeck file */ |
281 |
< |
orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444); |
280 |
> |
/* protect holodeck file */ |
281 |
> |
orig_mode = resfmode(hdlist[0]->fd, (ncprocs>0) & (force>=0) ? 0 : 0444); |
282 |
|
return; |
283 |
|
memerr: |
284 |
|
error(SYSTEM, "out of memory in initrholo"); |
290 |
|
static long nextfragwarn = 100*(1L<<20); |
291 |
|
static int idle = 0; |
292 |
|
PACKET *pl = NULL, *plend; |
293 |
< |
long fsiz; |
293 |
> |
off_t fsiz; |
294 |
|
int pksiz; |
295 |
|
register PACKET *p; |
296 |
|
time_t t; |
415 |
|
HDGRID *gp; |
416 |
|
{ |
417 |
|
extern char VersionID[]; |
418 |
< |
int4 lastloc, nextloc; |
418 |
> |
int32 lastloc, nextloc; |
419 |
|
int n; |
420 |
|
int fd; |
421 |
|
FILE *fp; |
433 |
|
putw(HOLOMAGIC, fp); /* put magic number */ |
434 |
|
fd = dup(fileno(fp)); |
435 |
|
fclose(fp); /* flush and close stdio stream */ |
436 |
< |
lastloc = lseek(fd, 0L, 2); |
436 |
> |
lastloc = lseek(fd, (off_t)0, 2); |
437 |
|
for (n = vdef(SECTION); n--; gp++) { /* initialize each section */ |
438 |
|
nextloc = 0L; |
439 |
|
write(fd, (char *)&nextloc, sizeof(nextloc)); |
441 |
|
if (!n) |
442 |
|
break; |
443 |
|
nextloc = hdfilen(fd); /* write section pointer */ |
444 |
< |
if (lseek(fd, (long)lastloc, 0) < 0) |
444 |
> |
if (lseek(fd, (off_t)lastloc, 0) < 0) |
445 |
|
error(SYSTEM, |
446 |
|
"cannot seek on holodeck file in creatholo"); |
447 |
|
write(fd, (char *)&nextloc, sizeof(nextloc)); |
448 |
< |
lseek(fd, (long)(lastloc=nextloc), 0); |
448 |
> |
lseek(fd, (off_t)(lastloc=nextloc), 0); |
449 |
|
} |
450 |
|
} |
451 |
|
|
478 |
|
|
479 |
|
loadholo() /* start loading a holodeck from fname */ |
480 |
|
{ |
476 |
– |
extern long ftell(); |
481 |
|
FILE *fp; |
482 |
|
int fd; |
483 |
|
int n; |
484 |
< |
int4 nextloc; |
485 |
< |
/* open holodeck file */ |
486 |
< |
if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { |
487 |
< |
sprintf(errmsg, "cannot %s \"%s\"", |
488 |
< |
ncprocs>0 ? "append" : "read", hdkfile); |
489 |
< |
error(SYSTEM, errmsg); |
484 |
> |
int32 nextloc; |
485 |
> |
|
486 |
> |
if ((ncprocs > 0) & (force >= 0)) |
487 |
> |
fp = fopen(hdkfile, "r+"); |
488 |
> |
else |
489 |
> |
fp = NULL; |
490 |
> |
if (fp == NULL) { |
491 |
> |
if ((fp = fopen(hdkfile, "r")) == NULL) { |
492 |
> |
sprintf(errmsg, "cannot open \"%s\"", hdkfile); |
493 |
> |
error(SYSTEM, errmsg); |
494 |
> |
} |
495 |
> |
if (ncprocs > 0) { |
496 |
> |
sprintf(errmsg, |
497 |
> |
"\"%s\" opened read-only; new rays will be discarded", |
498 |
> |
hdkfile); |
499 |
> |
error(WARNING, errmsg); |
500 |
> |
force = -1; |
501 |
> |
} |
502 |
|
} |
503 |
|
/* load variables from header */ |
504 |
|
getheader(fp, headline, NULL); |
512 |
|
fd = dup(fileno(fp)); |
513 |
|
fclose(fp); /* done with stdio */ |
514 |
|
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
515 |
< |
lseek(fd, (long)nextloc, 0); |
515 |
> |
lseek(fd, (off_t)nextloc, 0); |
516 |
|
read(fd, (char *)&nextloc, sizeof(nextloc)); |
517 |
|
hdinit(fd, NULL); |
518 |
|
} |
533 |
|
while (pl != NULL) { |
534 |
|
p = pl; pl = p->next; p->next = NULL; |
535 |
|
if (p->nr > 0) { /* add to holodeck */ |
536 |
< |
bcopy((char *)p->ra, |
537 |
< |
(char *)hdnewrays(hdlist[p->hd],p->bi,p->nr), |
536 |
> |
memcpy( (void *)hdnewrays(hdlist[p->hd],p->bi,p->nr), |
537 |
> |
(void *)p->ra, |
538 |
|
p->nr*sizeof(RAYVAL)); |
539 |
|
if (outdev != NULL) /* display it */ |
540 |
|
disp_packet((PACKHEAD *)p); |
547 |
|
p->next = freepacks; /* push onto free list */ |
548 |
|
freepacks = p; |
549 |
|
} |
550 |
< |
if (n2flush > RTFLUSH) { |
550 |
> |
if (n2flush >= RTFLUSH) { |
551 |
|
if (outdev != NULL) |
552 |
|
hdsync(NULL, 1); |
553 |
|
else |
562 |
|
{ |
563 |
|
char *tp, *dp; |
564 |
|
|
565 |
< |
for (tp = NULL, dp = rn; *rn = *fn++; rn++) |
565 |
> |
for (tp = NULL, dp = rn; (*rn = *fn++); rn++) { |
566 |
|
if (*rn == '/') |
567 |
|
dp = rn; |
568 |
|
else if (*rn == '.') |
569 |
|
tp = rn; |
570 |
+ |
} |
571 |
|
if (tp != NULL && tp > dp) |
572 |
|
*tp = '\0'; |
573 |
|
} |
581 |
|
} |
582 |
|
|
583 |
|
|
584 |
+ |
void |
585 |
|
eputs(s) /* put error message to stderr */ |
586 |
|
register char *s; |
587 |
|
{ |
601 |
|
} |
602 |
|
|
603 |
|
|
604 |
+ |
void |
605 |
|
quit(ec) /* exit program gracefully */ |
606 |
|
int ec; |
607 |
|
{ |
610 |
|
if (hdlist[0] != NULL) { /* close holodeck */ |
611 |
|
if (nprocs > 0) |
612 |
|
status = done_rtrace(); /* calls hdsync() */ |
613 |
< |
if (ncprocs > 0 && vdef(REPORT)) { |
614 |
< |
long fsiz, fuse; |
613 |
> |
if ((ncprocs > 0) & (force >= 0) && vdef(REPORT)) { |
614 |
> |
off_t fsiz, fuse; |
615 |
|
fsiz = hdfilen(hdlist[0]->fd); |
616 |
|
fuse = hdfiluse(hdlist[0]->fd, 1); |
617 |
|
fprintf(stderr, |