--- ray/src/hd/rholo.c 2003/10/21 19:19:28 3.62 +++ ray/src/hd/rholo.c 2008/12/04 23:34:00 3.73 @@ -1,23 +1,27 @@ #ifndef lint -static const char RCSid[] = "$Id: rholo.c,v 3.62 2003/10/21 19:19:28 schorsch Exp $"; +static const char RCSid[] = "$Id: rholo.c,v 3.73 2008/12/04 23:34:00 greg Exp $"; #endif /* * Radiance holodeck generation controller */ +#include +#include #include #include #include -#include "rholo.h" #include "platform.h" +#include "rterror.h" +#include "resolu.h" +#include "rholo.h" #include "random.h" #ifndef FRAGWARN #define FRAGWARN 20 /* fragmentation for warning (%) */ #endif #ifndef MAXQTIME -#define MAXQTIME 5 /* target maximum seconds in queue */ +#define MAXQTIME 3 /* target maximum seconds in queue */ #endif /* manual cache flushing frequency */ #ifndef RTFLUSH @@ -65,16 +69,27 @@ char *sigerr[NSIG]; /* signal error messages */ extern int nowarn; /* turn warnings off? */ -extern time_t time(); +static void onsig(int signo); +static void sigdie(int signo, char *msg); +static int resfmode(int fd, int mod); +static void initrholo(void); +static int rholo(void); +static void setdefaults(HDGRID *gp); +static void creatholo(HDGRID *gp); +static gethfunc headline; +static void loadholo(void); +static void rootname(char *rn, char *fn); +static void badvalue(int vc); -main(argc, argv) -int argc; -char *argv[]; +int +main( + int argc, + char *argv[] +) { int i; - initurand(16384); /* initialize urand */ progname = argv[0]; /* get arguments */ for (i = 1; i < argc && argv[i][0] == '-'; i++) switch (argv[i][1]) { @@ -152,12 +167,14 @@ userr: "Usage: %s [-n nprocs][-o disp][-w][-r|-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", progname); quit(1); + return 1; /* pro forma return */ } -void -onsig(signo) /* fatal signal */ -int signo; +static void +onsig( /* fatal signal */ + int signo +) { static int gotsig = 0; @@ -175,9 +192,11 @@ int signo; } -sigdie(signo, msg) /* set fatal signal */ -int signo; -char *msg; +static void +sigdie( /* set fatal signal */ + int signo, + char *msg +) { if (signal(signo, onsig) == SIG_IGN) signal(signo, SIG_IGN); @@ -185,9 +204,11 @@ char *msg; } -int -resfmode(fd, mod) /* restrict open file access mode */ -int fd, mod; +static int +resfmode( /* restrict open file access mode */ + int fd, + int mod +) { struct stat stbuf; /* get original mode */ @@ -205,7 +226,8 @@ int fd, mod; } -initrholo() /* get our holodeck running */ +static void +initrholo(void) /* get our holodeck running */ { extern int global_packet(); register int i; @@ -294,9 +316,10 @@ memerr: } -rholo() /* holodeck main loop */ +static int +rholo(void) /* holodeck main loop */ { - static long nextfragwarn = 100*(1L<<20); + static off_t nextfragwarn = 100L<<20; static int idle = 0; PACKET *pl = NULL, *plend; off_t fsiz; @@ -315,22 +338,25 @@ rholo() /* holodeck main loop */ return(0); /* all done */ fsiz = hdfilen(hdlist[0]->fd); /* check file size */ if (maxdisk > 0 && fsiz >= maxdisk) { - error(WARNING, "file limit exceeded"); + error(USER, "file limit exceeded"); done_rtrace(); return(1); /* comes back */ } #if FRAGWARN - if (fsiz >= nextfragwarn && - (fsiz-hdfiluse(hdlist[0]->fd,0))/(fsiz/100) > FRAGWARN) { - sprintf(errmsg, "holodeck file fragmentation is %.0f%%", - 100.*(fsiz-hdfiluse(hdlist[0]->fd,1))/fsiz); - error(WARNING, errmsg); - nextfragwarn = fsiz + (fsiz>>2); /* decent interval */ + if (fsiz >= nextfragwarn) { + double pctfrag = 100.*(fsiz-hdfiluse(hdlist[0]->fd))/fsiz; + if (pctfrag >= (double)FRAGWARN) { + sprintf(errmsg, "holodeck file fragmentation is %.0f%%", + pctfrag); + error(WARNING, errmsg); + nextfragwarn = fsiz + (fsiz>>2); + } else + nextfragwarn = fsiz + (10L<<20); } #endif t = time(NULL); /* check time */ if (endtime > 0 && t >= endtime) { - error(WARNING, "time limit exceeded"); + error(USER, "time limit exceeded"); done_rtrace(); return(1); /* comes back */ } @@ -363,14 +389,15 @@ rholo() /* holodeck main loop */ } -setdefaults(gp) /* set default values */ -register HDGRID *gp; +static void +setdefaults( /* set default values */ + register HDGRID *gp +) { extern char *atos(); register int i; int n; double len[3], d; - char buf[64]; if (!vdef(SECTION)) { sprintf(errmsg, "%s must be defined", vnam(SECTION)); @@ -420,8 +447,10 @@ register HDGRID *gp; } -creatholo(gp) /* create a holodeck output file */ -HDGRID *gp; +static void +creatholo( /* create a holodeck output file */ + HDGRID *gp +) { extern char VersionID[]; int32 lastloc, nextloc; @@ -459,9 +488,11 @@ HDGRID *gp; } -int -headline(s) /* process information header line */ -char *s; +static int +headline( /* process information header line */ + char *s, + void *p +) { extern char FMTSTR[]; register char *cp; @@ -485,7 +516,8 @@ char *s; } -loadholo() /* start loading a holodeck from fname */ +static void +loadholo(void) /* start loading a holodeck from fname */ { FILE *fp; int fd; @@ -502,9 +534,10 @@ loadholo() /* start loading a holodeck from fname */ error(SYSTEM, errmsg); } if (ncprocs > 0) { - sprintf(errmsg, - "\"%s\" opened read-only; new rays will be discarded", - hdkfile); + sprintf(errmsg, "\"%s\" is read-only", hdkfile); + if (outdev == NULL) + error(USER, errmsg); + strcat(errmsg, "; new rays will be discarded"); error(WARNING, errmsg); force = -1; } @@ -533,8 +566,10 @@ loadholo() /* start loading a holodeck from fname */ } -done_packets(pl) /* handle finished packets */ -PACKET *pl; +extern void +done_packets( /* handle finished packets */ + PACKET *pl +) { static int n2flush = 0; register PACKET *p; @@ -566,8 +601,11 @@ PACKET *pl; } -rootname(rn, fn) /* remove tail from end of fn */ -register char *rn, *fn; +static void +rootname( /* remove tail from end of fn */ + register char *rn, + register char *fn +) { char *tp, *dp; @@ -582,8 +620,10 @@ register char *rn, *fn; } -badvalue(vc) /* report bad variable value and exit */ -int vc; +static void +badvalue( /* report bad variable value and exit */ + int vc +) { sprintf(errmsg, "bad value for variable '%s'", vnam(vc)); error(USER, errmsg); @@ -622,7 +662,7 @@ int ec; if ((ncprocs > 0) & (force >= 0) && vdef(REPORT)) { off_t fsiz, fuse; fsiz = hdfilen(hdlist[0]->fd); - fuse = hdfiluse(hdlist[0]->fd, 1); + fuse = hdfiluse(hdlist[0]->fd); fprintf(stderr, "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n", hdkfile, fsiz/(1024.*1024.),