--- ray/src/hd/rholo.c 1997/10/31 11:44:09 3.2 +++ ray/src/hd/rholo.c 1997/11/10 18:05:24 3.8 @@ -33,6 +33,8 @@ 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) */ + int rtargc = 1; /* rtrace command */ char *rtargv[128] = {"rtrace", NULL}; @@ -51,7 +53,8 @@ char *argv[]; HDGRID hdg; int i; int force = 0; - + /* mark start time */ + starttime = time(NULL); progname = argv[0]; /* get arguments */ for (i = 1; i < argc && argv[i][0] == '-'; i++) switch (argv[i][1]) { @@ -102,8 +105,11 @@ char *argv[]; "holodeck file exists -- use -f to overwrite"); /* create holodeck */ creatholo(&hdg); - } else /* else load holodeck */ + } else { /* else load holodeck */ loadholo(); + if (vdef(RIF)) /* load RIF if any */ + getradfile(vval(RIF)); + } /* initialize */ initrholo(); /* run */ @@ -123,19 +129,26 @@ initrholo() /* get our holodeck running */ { extern int global_packet(); register int i; - /* check output device */ - if (outdev != NULL) - open_display(outdev); + + if (outdev != NULL) /* open output device */ + disp_open(outdev); else if (ncprocs > 0) /* else use global ray feed */ init_global(); - /* record the time */ - starttime = time(NULL); + /* record disk space limit */ + if (!vdef(DISKSPACE)) + maxdisk = 0; + else + maxdisk = 1024.*1024.*vflt(DISKSPACE)); + /* record end time */ if (!vdef(TIME) || vflt(TIME) <= FTINY) endtime = 0; else endtime = starttime + vflt(TIME)*3600.; /* set up memory cache */ - hdcachesize = 1024.*1024.*vflt(CACHE); + if (outdev == NULL) + hdcachesize = 0; /* manual flushing */ + else if (vdef(CACHE)) + hdcachesize = 1024.*1024.*vflt(CACHE); /* open report file */ if (vdef(REPORT)) { register char *s = sskip2(vval(REPORT), 1); @@ -184,22 +197,26 @@ rholo() /* holodeck main loop */ register PACKET *p; time_t t; long l; - /* check display */ - if (outdev != NULL && !disp_check(idle)) - return(0); + + if (outdev != NULL) /* check display */ + if (!disp_check(idle)) + return(0); /* display only? */ if (ncprocs <= 0) return(1); /* check file size */ - if ((l = 1024.*1024.*vflt(DISKSPACE)) > 0 && - hdfiluse(hdlist[0]->fd, 0) + hdmemuse(0) >= l) + if (maxdisk > 0 && hdfiluse(hdlist[0]->fd,0)+hdmemuse(0) >= maxdisk) { + error(WARNING, "file limit exceeded"); return(0); + } /* check time */ - if (endtime > 0 || vdef(REPORT)) + if (endtime > 0 || reporttime > 0) t = time(NULL); - if (endtime > 0 && t >= endtime) + if (endtime > 0 && t >= endtime) { + error(WARNING, "time limit exceeded"); return(0); - if (vdef(REPORT) && t >= reporttime) + } + if (reporttime > 0 && t >= reporttime) report(t); /* get packets to process */ while (freepacks != NULL) { @@ -230,7 +247,8 @@ time_t t; fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n", progname, npacksdone, nraysdone, (t-starttime)/3600.); fflush(stderr); - reporttime = t + (time_t)(vflt(REPORT)*60.); + if (vdef(REPORT)) + reporttime = t + (time_t)(vflt(REPORT)*60.+.5); } @@ -282,22 +300,6 @@ register HDGRID *gp; sprintf(vval(OCTREE), "%s.oct", froot); vdef(OCTREE)++; } - if (!vdef(DISKSPACE)) { - sprintf(errmsg, - "no %s setting, assuming 100 Mbytes available", - vnam(DISKSPACE)); - error(WARNING, errmsg); - vval(DISKSPACE) = "100"; - vdef(DISKSPACE)++; - } - if (!vdef(CACHE)) { - sprintf(errmsg, - "no %s setting, assuming 10 Mbytes available", - vnam(CACHE)); - error(WARNING, errmsg); - vval(CACHE) = "10"; - vdef(CACHE)++; - } if (!vdef(OBSTRUCTIONS)) { vval(OBSTRUCTIONS) = "T"; vdef(OBSTRUCTIONS)++; @@ -363,9 +365,10 @@ loadholo() /* start loading a holodeck from fname */ { FILE *fp; long endloc; - /* open input file */ - if ((fp = fopen(hdkfile, "r+")) == NULL) { - sprintf(errmsg, "cannot open \"%s\" for appending", hdkfile); + /* open holodeck file */ + if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { + sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, + ncprocs>0 ? "appending" : "reading"); error(SYSTEM, errmsg); } /* load variables from header */ @@ -388,6 +391,7 @@ loadholo() /* start loading a holodeck from fname */ done_packets(pl) /* handle finished packets */ PACKET *pl; { + static int nunflushed = 0; register PACKET *p; while (pl != NULL) { @@ -397,14 +401,20 @@ PACKET *pl; (char *)hdnewrays(hdlist[p->hd],p->bi,p->nr), p->nr*sizeof(RAYVAL)); if (outdev != NULL) /* display it */ - disp_packet(p); + disp_packet((PACKHEAD *)p); + else + nunflushed += p->nr; + nraysdone += p->nr; + npacksdone++; } - nraysdone += p->nr; - npacksdone++; p->nr = 0; /* push onto free list */ p->next = freepacks; freepacks = p; } + if (nunflushed >= 256*RPACKSIZ) { + hdflush(NULL); /* flush holodeck buffers */ + nunflushed = 0; + } } @@ -415,6 +425,7 @@ char *rfargs; static char tf1[] = TEMPLATE; char tf2[64]; char combuf[256]; + char *pippt; register int i; register char *cp; /* create rad command */ @@ -424,24 +435,33 @@ char *rfargs; "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", rfargs, tf1); cp = combuf; - while (*cp) cp++; /* match unset variables */ + while (*cp){ + if (*cp == '|') pippt = cp; + cp++; + } /* match unset variables */ for (i = 0; mvar[i] >= 0; i++) if (!vdef(mvar[i])) { *cp++ = '|'; strcpy(cp, vnam(mvar[i])); while (*cp) cp++; + pippt = NULL; } - sprintf(cp, ")[ \t]*=' > %s", tf2); + if (pippt != NULL) + strcpy(pippt, "> /dev/null"); /* nothing to match */ + else + sprintf(cp, ")[ \t]*=' > %s", tf2); if (system(combuf)) { error(SYSTEM, "cannot execute rad command"); unlink(tf2); /* clean up */ unlink(tf1); quit(1); } - loadvars(tf2); /* load variables */ + if (pippt == NULL) { + loadvars(tf2); /* load variables */ + unlink(tf2); + } rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ - unlink(tf2); /* clean up */ - unlink(tf1); + unlink(tf1); /* clean up */ } @@ -500,6 +520,8 @@ int ec; { int status = 0; + if (outdev != NULL) /* close display */ + disp_close(); if (hdlist[0] != NULL) { /* flush holodeck */ if (ncprocs > 0) { done_packets(flush_queue()); @@ -511,7 +533,7 @@ int ec; fsiz = lseek(hdlist[0]->fd, 0L, 2); fuse = hdfiluse(hdlist[0]->fd, 1); fprintf(stderr, - "%s: %.1f Mbyte holodeck file, %.2f%% fragmentation\n", + "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n", hdkfile, fsiz/(1024.*1024.), 100.*(fsiz-fuse)/fsiz); }