--- ray/src/hd/rholo.c 1999/03/09 08:51:39 3.50 +++ ray/src/hd/rholo.c 2003/05/29 16:26:22 3.54 @@ -1,9 +1,6 @@ -/* Copyright (c) 1999 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rholo.c,v 3.54 2003/05/29 16:26:22 greg Exp $"; #endif - /* * Radiance holodeck generation controller */ @@ -42,13 +39,13 @@ char *outdev = NULL; /* output device name */ int readinp = 0; /* read commands from stdin */ -int force = 0; /* allow overwrite of holodeck */ +int force = 0; /* allow overwrite of holodeck (-1 == read-only) */ time_t starttime; /* time we got started */ time_t endtime; /* time we should end by */ time_t reporttime; /* time for next report */ -long maxdisk; /* maximum file space (bytes) */ +off_t maxdisk; /* maximum file space (bytes) */ int rtargc = 1; /* rtrace command */ char *rtargv[128] = {"rtrace", NULL}; @@ -82,8 +79,11 @@ char *argv[]; nowarn++; break; case 'f': /* force overwrite */ - force++; + force = 1; break; + case 'r': /* read-only mode */ + force = -1; + break; case 'i': /* read input from stdin */ readinp++; break; @@ -126,6 +126,9 @@ char *argv[]; HDGRID hdg[HDMAX]; /* set defaults */ setdefaults(hdg); + /* check read-only */ + if (force < 0) + error(USER, "cannot create read-only holodeck"); /* holodeck exists? */ if (!force && access(hdkfile, R_OK|W_OK) == 0) error(USER, @@ -143,7 +146,7 @@ char *argv[]; quit(0); userr: fprintf(stderr, -"Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", +"Usage: %s [-n nprocs][-o disp][-w][-r|-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", progname); quit(1); } @@ -211,7 +214,7 @@ initrholo() /* get our holodeck running */ init_global(); /* record disk space limit */ if (!vdef(DISKSPACE)) - maxdisk = 0; + maxdisk = (1L<<(sizeof(off_t)*8-2)) - 1024; else maxdisk = 1024.*1024.*vflt(DISKSPACE); /* set up memory cache */ @@ -272,7 +275,7 @@ initrholo() /* get our holodeck running */ sigdie(SIGXFSZ, "File size exceeded"); #endif /* protect holodeck file */ - orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444); + orig_mode = resfmode(hdlist[0]->fd, ncprocs>0&force>=0 ? 0 : 0444); return; memerr: error(SYSTEM, "out of memory in initrholo"); @@ -284,7 +287,7 @@ rholo() /* holodeck main loop */ static long nextfragwarn = 100*(1L<<20); static int idle = 0; PACKET *pl = NULL, *plend; - long fsiz; + off_t fsiz; int pksiz; register PACKET *p; time_t t; @@ -427,7 +430,7 @@ HDGRID *gp; putw(HOLOMAGIC, fp); /* put magic number */ fd = dup(fileno(fp)); fclose(fp); /* flush and close stdio stream */ - lastloc = lseek(fd, 0L, 2); + lastloc = lseek(fd, (off_t)0L, 2); for (n = vdef(SECTION); n--; gp++) { /* initialize each section */ nextloc = 0L; write(fd, (char *)&nextloc, sizeof(nextloc)); @@ -435,11 +438,11 @@ HDGRID *gp; if (!n) break; nextloc = hdfilen(fd); /* write section pointer */ - if (lseek(fd, (long)lastloc, 0) < 0) + if (lseek(fd, (off_t)lastloc, 0) < 0) error(SYSTEM, "cannot seek on holodeck file in creatholo"); write(fd, (char *)&nextloc, sizeof(nextloc)); - lseek(fd, (long)(lastloc=nextloc), 0); + lseek(fd, (off_t)(lastloc=nextloc), 0); } } @@ -472,16 +475,27 @@ char *s; loadholo() /* start loading a holodeck from fname */ { - extern long ftell(); FILE *fp; int fd; int n; int4 nextloc; - /* open holodeck file */ - if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { - sprintf(errmsg, "cannot %s \"%s\"", - ncprocs>0 ? "append" : "read", hdkfile); - error(SYSTEM, errmsg); + + if (ncprocs > 0 & force >= 0) + fp = fopen(hdkfile, "r+"); + else + fp = NULL; + if (fp == NULL) { + if ((fp = fopen(hdkfile, "r")) == NULL) { + sprintf(errmsg, "cannot open \"%s\"", hdkfile); + error(SYSTEM, errmsg); + } + if (ncprocs > 0) { + sprintf(errmsg, + "\"%s\" opened read-only; new rays will be discarded", + hdkfile); + error(WARNING, errmsg); + force = -1; + } } /* load variables from header */ getheader(fp, headline, NULL); @@ -495,7 +509,7 @@ loadholo() /* start loading a holodeck from fname */ fd = dup(fileno(fp)); fclose(fp); /* done with stdio */ for (n = 0; nextloc > 0L; n++) { /* initialize each section */ - lseek(fd, (long)nextloc, 0); + lseek(fd, (off_t)nextloc, 0); read(fd, (char *)&nextloc, sizeof(nextloc)); hdinit(fd, NULL); } @@ -516,8 +530,8 @@ PACKET *pl; while (pl != NULL) { p = pl; pl = p->next; p->next = NULL; if (p->nr > 0) { /* add to holodeck */ - bcopy((char *)p->ra, - (char *)hdnewrays(hdlist[p->hd],p->bi,p->nr), + bcopy((void *)p->ra, + (void *)hdnewrays(hdlist[p->hd],p->bi,p->nr), p->nr*sizeof(RAYVAL)); if (outdev != NULL) /* display it */ disp_packet((PACKHEAD *)p); @@ -563,6 +577,7 @@ int vc; } +void eputs(s) /* put error message to stderr */ register char *s; { @@ -582,6 +597,7 @@ register char *s; } +void quit(ec) /* exit program gracefully */ int ec; { @@ -590,8 +606,8 @@ int ec; if (hdlist[0] != NULL) { /* close holodeck */ if (nprocs > 0) status = done_rtrace(); /* calls hdsync() */ - if (ncprocs > 0 && vdef(REPORT)) { - long fsiz, fuse; + if (ncprocs > 0 & force >= 0 && vdef(REPORT)) { + off_t fsiz, fuse; fsiz = hdfilen(hdlist[0]->fd); fuse = hdfiluse(hdlist[0]->fd, 1); fprintf(stderr,