1 |
< |
/* Copyright (c) 1999 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1999 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
42 |
|
|
43 |
|
int readinp = 0; /* read commands from stdin */ |
44 |
|
|
45 |
< |
int force = 0; /* allow overwrite of holodeck */ |
45 |
> |
int force = 0; /* allow overwrite of holodeck (-1 == read-only) */ |
46 |
|
|
47 |
|
time_t starttime; /* time we got started */ |
48 |
|
time_t endtime; /* time we should end by */ |
82 |
|
nowarn++; |
83 |
|
break; |
84 |
|
case 'f': /* force overwrite */ |
85 |
< |
force++; |
85 |
> |
force = 1; |
86 |
|
break; |
87 |
+ |
case 'r': /* read-only mode */ |
88 |
+ |
force = -1; |
89 |
+ |
break; |
90 |
|
case 'i': /* read input from stdin */ |
91 |
|
readinp++; |
92 |
|
break; |
129 |
|
HDGRID hdg[HDMAX]; |
130 |
|
/* set defaults */ |
131 |
|
setdefaults(hdg); |
132 |
+ |
/* check read-only */ |
133 |
+ |
if (force < 0) |
134 |
+ |
error(USER, "cannot create read-only holodeck"); |
135 |
|
/* holodeck exists? */ |
136 |
|
if (!force && access(hdkfile, R_OK|W_OK) == 0) |
137 |
|
error(USER, |
149 |
|
quit(0); |
150 |
|
userr: |
151 |
|
fprintf(stderr, |
152 |
< |
"Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", |
152 |
> |
"Usage: %s [-n nprocs][-o disp][-w][-r|-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", |
153 |
|
progname); |
154 |
|
quit(1); |
155 |
|
} |
483 |
|
int fd; |
484 |
|
int n; |
485 |
|
int4 nextloc; |
486 |
< |
/* open holodeck file */ |
487 |
< |
if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { |
488 |
< |
sprintf(errmsg, "cannot %s \"%s\"", |
489 |
< |
ncprocs>0 ? "append" : "read", hdkfile); |
490 |
< |
error(SYSTEM, errmsg); |
486 |
> |
|
487 |
> |
if (ncprocs > 0 & force >= 0) |
488 |
> |
fp = fopen(hdkfile, "r+"); |
489 |
> |
else |
490 |
> |
fp = NULL; |
491 |
> |
if (fp == NULL) { |
492 |
> |
if ((fp = fopen(hdkfile, "r")) == NULL) { |
493 |
> |
sprintf(errmsg, "cannot open \"%s\"", hdkfile); |
494 |
> |
error(SYSTEM, errmsg); |
495 |
> |
} |
496 |
> |
if (ncprocs > 0) { |
497 |
> |
sprintf(errmsg, |
498 |
> |
"\"%s\" opened read-only; new rays will be discarded", |
499 |
> |
hdkfile); |
500 |
> |
error(WARNING, errmsg); |
501 |
> |
force = -1; |
502 |
> |
} |
503 |
|
} |
504 |
|
/* load variables from header */ |
505 |
|
getheader(fp, headline, NULL); |
608 |
|
if (hdlist[0] != NULL) { /* close holodeck */ |
609 |
|
if (nprocs > 0) |
610 |
|
status = done_rtrace(); /* calls hdsync() */ |
611 |
< |
if (ncprocs > 0 && vdef(REPORT)) { |
611 |
> |
if (ncprocs > 0 & force >= 0 && vdef(REPORT)) { |
612 |
|
long fsiz, fuse; |
613 |
|
fsiz = hdfilen(hdlist[0]->fd); |
614 |
|
fuse = hdfiluse(hdlist[0]->fd, 1); |