ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo.c
(Generate patch)

Comparing ray/src/hd/rholo.c (file contents):
Revision 3.17 by gregl, Mon Dec 8 18:51:15 1997 UTC vs.
Revision 3.49 by gwlarson, Wed Feb 10 16:24:07 1999 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1997 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1999 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ SGI";
10  
11   #include "rholo.h"
12   #include "random.h"
13 #include "paths.h"
13   #include <signal.h>
14   #include <sys/types.h>
15   #include <sys/stat.h>
16  
17 + #ifndef FRAGWARN
18 + #define FRAGWARN        20              /* fragmentation for warning (%) */
19 + #endif
20 + #ifndef MAXQTIME
21 + #define MAXQTIME        5               /* target maximum seconds in queue */
22 + #endif
23 +                                        /* manual cache flushing frequency */
24 + #ifndef RTFLUSH
25 + #if MAXQTIME
26 + #define RTFLUSH         (300/MAXQTIME*totqlen)  /* <= 5 minutes */
27 + #else
28 + #define RTFLUSH         (50*totqlen)            /* just guess */
29 + #endif
30 + #endif
31                          /* the following must be consistent with rholo.h */
32   int     NVARS = NRHVARS;                /* total number of variables */
33  
# Line 22 | Line 35 | VARIABLE       vv[] = RHVINIT;         /* variable-value pairs */
35  
36   char    *progname;              /* our program name */
37   char    *hdkfile;               /* holodeck file name */
38 < char    froot[MAXPATH];         /* root file name */
38 > char    froot[256];             /* root file name */
39  
27 int     nowarn = 0;             /* turn warnings off? */
28
40   int     ncprocs = 0;            /* desired number of compute processes */
41  
42   char    *outdev = NULL;         /* output device name */
43  
44   int     readinp = 0;            /* read commands from stdin */
45  
46 + int     force = 0;              /* allow overwrite of holodeck */
47 +
48   time_t  starttime;              /* time we got started */
49   time_t  endtime;                /* time we should end by */
50   time_t  reporttime;             /* time for next report */
# Line 47 | Line 60 | long   nraysdone = 0L;         /* number of rays done */
60   long    npacksdone = 0L;        /* number of packets done */
61  
62   PACKET  *freepacks;             /* available packets */
63 + int     totqlen;                /* maximum queue length (number of packets) */
64  
65   char  *sigerr[NSIG];            /* signal error messages */
66  
67 + extern int      nowarn;         /* turn warnings off? */
68 +
69   extern time_t   time();
70  
71  
# Line 57 | Line 73 | main(argc, argv)
73   int     argc;
74   char    *argv[];
75   {
60        HDGRID  hdg;
76          int     i;
77 <        int     force = 0;
78 <                                                /* mark start time */
64 <        starttime = time(NULL);
65 <        initurand(10240);                       /* initialize urand */
77 >
78 >        initurand(16384);                       /* initialize urand */
79          progname = argv[0];                     /* get arguments */
80          for (i = 1; i < argc && argv[i][0] == '-'; i++)
81                  switch (argv[i][1]) {
# Line 88 | Line 101 | char   *argv[];
101                  default:
102                          goto userr;
103                  }
91                                                /* do we have a job? */
92        if (outdev == NULL && ncprocs <= 0)
93                goto userr;
104                                                  /* get root file name */
105 +        if (i >= argc)
106 +                goto userr;
107          rootname(froot, hdkfile=argv[i++]);
108 <                                                /* load... */
109 <        if (i < argc) {                         /* variables */
110 <                loadvars(argv[i++]);
111 <                                                        /* cmdline settings */
112 <                for ( ; i < argc; i++)
113 <                        if (setvariable(argv[i], matchvar) < 0) {
114 <                                sprintf(errmsg, "unknown variable: %s",
115 <                                                argv[i]);
116 <                                error(USER, errmsg);
117 <                        }
118 <                                                        /* check settings */
119 <                checkvalues();
120 <                                                        /* load RIF if any */
121 <                if (vdef(RIF))
122 <                        getradfile(vval(RIF));
108 >                                                /* load variables? */
109 >        if (i < argc)
110 >                if (argv[i][0] != '-' && argv[i][0] != '+')
111 >                        loadvars(argv[i]);      /* load variables from file */
112 >
113 >        if (i >= argc || argv[i][0] == '+')
114 >                loadholo();                     /* load existing holodeck */
115 >
116 >        while (++i < argc)                      /* get command line settings */
117 >                if (setvariable(argv[i], matchvar) < 0) {
118 >                        sprintf(errmsg, "unknown variable: %s", argv[i]);
119 >                        error(USER, errmsg);
120 >                }
121 >                                                /* check settings */
122 >        checkvalues();
123 >                                                /* load rad input file */
124 >        getradfile();
125 >
126 >        if (hdlist[0] == NULL) {                /* create new holodeck */
127 >                HDGRID  hdg[HDMAX];
128                                                          /* set defaults */
129 <                setdefaults(&hdg);
129 >                setdefaults(hdg);
130                                                          /* holodeck exists? */
131                  if (!force && access(hdkfile, R_OK|W_OK) == 0)
132                          error(USER,
133                                  "holodeck file exists -- use -f to overwrite");
134                                                          /* create holodeck */
135 <                creatholo(&hdg);
136 <        } else {                                /* else load holodeck */
120 <                loadholo();
121 <                                                        /* check settings */
122 <                checkvalues();
123 <                                                        /* load RIF if any */
124 <                if (vdef(RIF))
125 <                        getradfile(vval(RIF));
126 <                                                        /* set defaults */
135 >                creatholo(hdg);
136 >        } else                                  /* else just set defaults */
137                  setdefaults(NULL);
128        }
138                                                  /* initialize */
139          initrholo();
140                                                  /* main loop */
# Line 135 | Line 144 | char   *argv[];
144          quit(0);
145   userr:
146          fprintf(stderr,
147 < "Usage: %s {-n nprocs|-o disp} [-w][-f] output.hdk [control.hif [VAR=val ..]]\n",
147 > "Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n",
148                          progname);
149          quit(1);
150   }
# Line 146 | Line 155 | int  signo;
155   {
156          static int  gotsig = 0;
157  
158 <        if (gotsig++)                   /* two signals and we're gone! */
158 >        if (gotsig > 1)                 /* we're going as fast as we can! */
159 >                return;
160 >        if (gotsig++) {                 /* two signals and we split */
161 >                hdsync(NULL, 0);        /* don't leave w/o saying goodbye */
162                  _exit(signo);
163 <
164 <        alarm(30);                      /* allow 30 seconds to clean up */
153 <        signal(SIGALRM, SIG_DFL);       /* make certain we do die */
163 >        }
164 >        alarm(300);                     /* allow 5 minutes to clean up */
165          eputs("signal - ");
166          eputs(sigerr[signo]);
167          eputs("\n");
# Line 177 | Line 188 | int    fd, mod;
188          if (fstat(fd, &stbuf) < 0)
189                  error(SYSTEM, "cannot stat open holodeck file");
190          mod &= stbuf.st_mode;           /* always more restrictive */
191 <        if (mod == stbuf.st_mode)
191 >        if (mod == (stbuf.st_mode & 0777))
192                  return(-1);             /* already set */
193                                          /* else change it */
194          if (fchmod(fd, mod) < 0) {
# Line 204 | Line 215 | initrholo()                    /* get our holodeck running */
215                  maxdisk = 0;
216          else
217                  maxdisk = 1024.*1024.*vflt(DISKSPACE);
207                                                /* record end time */
208        if (!vdef(TIME) || vflt(TIME) <= FTINY)
209                endtime = 0;
210        else
211                endtime = starttime + vflt(TIME)*3600.;
218                                                  /* set up memory cache */
219          if (outdev == NULL)
220                  hdcachesize = 0;        /* manual flushing */
# Line 220 | Line 226 | initrholo()                    /* get our holodeck running */
226                  if (*s && freopen(s, "a", stderr) == NULL)
227                          quit(2);
228          }
229 +                                                /* mark the starting time */
230 +        starttime = time(NULL);
231 +                                                /* compute end time */
232 +        if (!vdef(TIME) || vflt(TIME) <= FTINY)
233 +                endtime = 0;
234 +        else
235 +                endtime = starttime + vflt(TIME)*3600. + .5;
236                                                  /* start rtrace */
237          if (ncprocs > 0) {
238 <                i = start_rtrace();
238 >                totqlen = i = start_rtrace();
239                  if (i < 1)
240 <                        error(USER, "cannot start rtrace process");
240 >                        error(USER, "cannot start rtrace process(es)");
241                  if (vdef(REPORT)) {             /* make first report */
242                          printargs(rtargc, rtargv, stderr);
243                          report(0);
# Line 235 | Line 248 | initrholo()                    /* get our holodeck running */
248                          goto memerr;
249                  freepacks[--i].nr = 0;
250                  freepacks[i].next = NULL;
251 <                if (!vbool(OBSTRUCTIONS)) {
251 >                if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) {
252                          freepacks[i].offset = (float *)bmalloc(
253                                          RPACKSIZ*sizeof(float)*(i+1) );
254                          if (freepacks[i].offset == NULL)
# Line 269 | Line 282 | memerr:
282  
283   rholo()                         /* holodeck main loop */
284   {
285 <        static int      idle = 1;
285 >        static long     nextfragwarn = 100*(1L<<20);
286 >        static int      idle = 0;
287          PACKET  *pl = NULL, *plend;
288 +        long    fsiz;
289 +        int     pksiz;
290          register PACKET *p;
291          time_t  t;
292 <        long    l;
293 <
294 <        if (outdev != NULL)             /* check display */
292 >                                        /* check display */
293 >        if (nprocs <= 0)
294 >                idle = 1;
295 >        if (outdev != NULL) {
296                  if (!disp_check(idle))
297 <                        return(0);
298 <                                        /* display only? */
299 <        if (ncprocs <= 0)
300 <                return(1);
301 <                                        /* check file size */
302 <        if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
297 >                        return(0);      /* quit request */
298 >                if (nprocs <= 0)
299 >                        return(1);
300 >        } else if (idle)
301 >                return(0);              /* all done */
302 >        fsiz = hdfilen(hdlist[0]->fd);  /* check file size */
303 >        if (maxdisk > 0 && fsiz >= maxdisk) {
304                  error(WARNING, "file limit exceeded");
305 <                return(0);
305 >                done_rtrace();
306 >                return(1);      /* comes back */
307          }
308 <                                        /* check time */
309 <        if (endtime > 0 || reporttime > 0)
310 <                t = time(NULL);
308 > #if FRAGWARN
309 >        if (fsiz >= nextfragwarn &&
310 >                (fsiz-hdfiluse(hdlist[0]->fd,0))/(fsiz/100) > FRAGWARN) {
311 >                sprintf(errmsg, "holodeck file fragmentation is %.0f%%",
312 >                                100.*(fsiz-hdfiluse(hdlist[0]->fd,1))/fsiz);
313 >                error(WARNING, errmsg);
314 >                nextfragwarn = fsiz + (fsiz>>2);        /* decent interval */
315 >        }
316 > #endif
317 >        t = time(NULL);                 /* check time */
318          if (endtime > 0 && t >= endtime) {
319                  error(WARNING, "time limit exceeded");
320 <                return(0);
320 >                done_rtrace();
321 >                return(1);      /* comes back */
322          }
323          if (reporttime > 0 && t >= reporttime)
324                  report(t);
325 <                                        /* get packets to process */
325 >                                        /* figure out good packet size */
326 >        pksiz = RPACKSIZ;
327 > #if MAXQTIME
328 >        if (!chunkycmp) {
329 >                pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L));
330 >                if (pksiz < 1) pksiz = 1;
331 >                else if (pksiz > RPACKSIZ) pksiz = RPACKSIZ;
332 >        }
333 > #endif
334 >        idle = 0;                       /* get packets to process */
335          while (freepacks != NULL) {
336                  p = freepacks; freepacks = p->next; p->next = NULL;
337 <                if (!next_packet(p)) {
337 >                if (!next_packet(p, pksiz)) {
338                          p->next = freepacks; freepacks = p;
339 +                        idle = 1;
340                          break;
341                  }
342                  if (pl == NULL) pl = p;
343                  else plend->next = p;
344                  plend = p;
345          }
346 <        idle = pl == NULL && freepacks != NULL;
310 <                                        /* are we out of stuff to do? */
311 <        if (idle && outdev == NULL)
312 <                return(0);
313 <                                        /* else process packets */
346 >                                        /* process packets */
347          done_packets(do_packets(pl));
348          return(1);                      /* and continue */
349   }
350  
351  
319 report(t)                       /* report progress so far */
320 time_t  t;
321 {
322        if (t == 0)
323                t = time(NULL);
324        fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n",
325                        progname, npacksdone, nraysdone, (t-starttime)/3600.);
326        fflush(stderr);
327        if (vdef(REPORT))
328                reporttime = t + (time_t)(vflt(REPORT)*60.+.5);
329 }
330
331
352   setdefaults(gp)                 /* set default values */
353   register HDGRID *gp;
354   {
355          extern char     *atos();
356          register int    i;
357 <        double  len[3], maxlen, d;
357 >        int     n;
358 >        double  len[3], d;
359          char    buf[64];
360  
361          if (!vdef(SECTION)) {
362                  sprintf(errmsg, "%s must be defined", vnam(SECTION));
363                  error(USER, errmsg);
364          }
344        if (vdef(SECTION) > 1) {
345                sprintf(errmsg, "ignoring all but first %s", vnam(SECTION));
346                error(WARNING, errmsg);
347        }
365          if (!vdef(OCTREE)) {
366                  if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL)
367                          error(SYSTEM, "out of memory");
368                  sprintf(vval(OCTREE), "%s.oct", froot);
369                  vdef(OCTREE)++;
370          }
354        if (!vdef(OBSTRUCTIONS)) {
355                vval(OBSTRUCTIONS) = "T";
356                vdef(OBSTRUCTIONS)++;
357        }
371          if (!vdef(VDIST)) {
372                  vval(VDIST) = "F";
373                  vdef(VDIST)++;
374          }
362        if (!vdef(OCCUPANCY)) {
363                vval(OCCUPANCY) = "U";
364                vdef(OCCUPANCY)++;
365        }
375                                  /* append rendering options */
376          if (vdef(RENDER))
377                  rtargc += wordstring(rtargv+rtargc, vval(RENDER));
# Line 370 | Line 379 | register HDGRID        *gp;
379          if (gp == NULL)         /* already initialized? */
380                  return;
381                                  /* set grid parameters */
382 <        gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
383 <        if (sscanf(vval(SECTION),
382 >        for (n = 0; n < vdef(SECTION); n++, gp++) {
383 >                gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
384 >                if (sscanf(nvalue(SECTION, n),
385                  "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd",
386 <                        &gp->orig[0], &gp->orig[1], &gp->orig[2],
387 <                        &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
388 <                        &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
389 <                        &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
390 <                        &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
391 <                badvalue(SECTION);
392 <        maxlen = 0.;
393 <        for (i = 0; i < 3; i++)
394 <                if ((len[i] = VLEN(gp->xv[i])) > maxlen)
395 <                        maxlen = len[i];
396 <        if (!vdef(GRID)) {
397 <                sprintf(buf, "%.4f", maxlen/8.);
398 <                vval(GRID) = savqstr(buf);
399 <                vdef(GRID)++;
386 >                                &gp->orig[0], &gp->orig[1], &gp->orig[2],
387 >                                &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
388 >                                &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
389 >                                &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
390 >                                &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
391 >                        badvalue(SECTION);
392 >                for (i = 0; i < 3; i++)
393 >                        len[i] = VLEN(gp->xv[i]);
394 >                if (!vdef(GRID)) {
395 >                        d = 2/2e5*( len[0]*len[0]*(len[1]*len[1] +
396 >                                        len[2]*len[2] + 4*len[1]*len[2])
397 >                                + len[1]*len[1]*len[2]*(len[2] + 4*len[0])
398 >                                + 4*len[0]*len[1]*len[2]*len[2] );
399 >                        d = sqrt(sqrt(d));
400 >                } else if ((d = vflt(GRID)) <= FTINY)
401 >                        badvalue(GRID);
402 >                for (i = 0; i < 3; i++)
403 >                        if (gp->grid[i] <= 0)
404 >                                gp->grid[i] = len[i]/d + (1.-FTINY);
405          }
391        if ((d = vflt(GRID)) <= FTINY)
392                badvalue(GRID);
393        for (i = 0; i < 3; i++)
394                if (gp->grid[i] <= 0)
395                        gp->grid[i] = len[i]/d + (1.-FTINY);
406   }
407  
408  
# Line 400 | Line 410 | creatholo(gp)                  /* create a holodeck output file */
410   HDGRID  *gp;
411   {
412          extern char     VersionID[];
413 <        long    endloc = 0;
413 >        int4    lastloc, nextloc;
414 >        int     n;
415          int     fd;
416          FILE    *fp;
417                                          /* open & truncate file */
# Line 414 | Line 425 | HDGRID *gp;
425          printvars(fp);
426          fputformat(HOLOFMT, fp);
427          fputc('\n', fp);
428 <        putw(HOLOMAGIC, fp);            /* put magic number & terminus */
418 <        fwrite(&endloc, sizeof(long), 1, fp);
428 >        putw(HOLOMAGIC, fp);            /* put magic number */
429          fd = dup(fileno(fp));
430          fclose(fp);                     /* flush and close stdio stream */
431 <        hdinit(fd, gp);                 /* allocate and initialize index */
431 >        lastloc = lseek(fd, 0L, 2);
432 >        for (n = vdef(SECTION); n--; gp++) {    /* initialize each section */
433 >                nextloc = 0L;
434 >                write(fd, (char *)&nextloc, sizeof(nextloc));
435 >                hdinit(fd, gp);                 /* writes beam index */
436 >                if (!n)
437 >                        break;
438 >                nextloc = hdfilen(fd);          /* write section pointer */
439 >                if (lseek(fd, (long)lastloc, 0) < 0)
440 >                        error(SYSTEM,
441 >                                "cannot seek on holodeck file in creatholo");
442 >                write(fd, (char *)&nextloc, sizeof(nextloc));
443 >                lseek(fd, (long)(lastloc=nextloc), 0);
444 >        }
445   }
446  
447  
448 + int
449   headline(s)                     /* process information header line */
450   char    *s;
451   {
# Line 435 | Line 459 | char   *s;
459                                          HOLOFMT, hdkfile, FMTSTR, fmt);
460                          error(USER, errmsg);
461                  }
462 <                return;
462 >                return(0);
463          }
464          for (cp = s; *cp; cp++)         /* take off any comments */
465                  if (*cp == '#') {
# Line 443 | Line 467 | char   *s;
467                          break;
468                  }
469          setvariable(s, matchvar);       /* don't flag errors */
470 +        return(0);
471   }
472  
473  
# Line 451 | Line 476 | loadholo()                     /* start loading a holodeck from fname */
476          extern long     ftell();
477          FILE    *fp;
478          int     fd;
479 <        long    fpos;
479 >        int     n;
480 >        int4    nextloc;
481                                          /* open holodeck file */
482          if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
483 <                sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile,
484 <                                ncprocs>0 ? "appending" : "reading");
483 >                sprintf(errmsg, "cannot %s \"%s\"",
484 >                                ncprocs>0 ? "append" : "read", hdkfile);
485                  error(SYSTEM, errmsg);
486          }
487                                          /* load variables from header */
# Line 466 | Line 492 | loadholo()                     /* start loading a holodeck from fname */
492                                  hdkfile);
493                  error(USER, errmsg);
494          }
495 <        fread(&fpos, sizeof(long), 1, fp);
470 <        if (fpos != 0)
471 <                error(WARNING, "ignoring multiple sections in holodeck file");
472 <        fpos = ftell(fp);                       /* get stdio position */
495 >        nextloc = ftell(fp);                    /* get stdio position */
496          fd = dup(fileno(fp));
497          fclose(fp);                             /* done with stdio */
498 <        lseek(fd, fpos, 0);                     /* align system file pointer */
499 <        hdinit(fd, NULL);                       /* allocate and load index */
498 >        for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
499 >                lseek(fd, (long)nextloc, 0);
500 >                read(fd, (char *)&nextloc, sizeof(nextloc));
501 >                hdinit(fd, NULL);
502 >        }
503 >        if (n != vdef(SECTION)) {
504 >                sprintf(errmsg, "number of sections does not match %s setting",
505 >                                vnam(SECTION));
506 >                error(WARNING, errmsg);
507 >        }
508   }
509  
510  
# Line 491 | Line 522 | PACKET *pl;
522                                  p->nr*sizeof(RAYVAL));
523                          if (outdev != NULL)     /* display it */
524                                  disp_packet((PACKHEAD *)p);
525 <                        if (hdcachesize <= 0)   /* manual flushing */
526 <                                n2flush += p->nr;
525 >                        if (hdcachesize <= 0)
526 >                                n2flush++;
527                          nraysdone += p->nr;
528                          npacksdone++;
529 +                        p->nr = 0;
530                  }
531 <                p->nr = 0;                      /* push onto free list */
500 <                p->next = freepacks;
531 >                p->next = freepacks;            /* push onto free list */
532                  freepacks = p;
533          }
534 <        if (n2flush > 512*RPACKSIZ*ncprocs) {
535 <                hdflush(NULL);                  /* flush holodeck buffers */
534 >        if (n2flush > RTFLUSH) {
535 >                if (outdev != NULL)
536 >                        hdsync(NULL, 1);
537 >                else
538 >                        hdflush(NULL);
539                  n2flush = 0;
540          }
541   }
542  
543  
510 getradfile(rfargs)              /* run rad and get needed variables */
511 char    *rfargs;
512 {
513        static short    mvar[] = {OCTREE,-1};
514        static char     tf1[] = TEMPLATE;
515        char    tf2[64];
516        char    combuf[256];
517        char    *pippt;
518        register int    i;
519        register char   *cp;
520                                        /* create rad command */
521        mktemp(tf1);
522        sprintf(tf2, "%s.rif", tf1);
523        sprintf(combuf,
524                "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
525                        rfargs, tf1);
526        cp = combuf;
527        while (*cp){
528                if (*cp == '|') pippt = cp;
529                cp++;
530        }                               /* match unset variables */
531        for (i = 0; mvar[i] >= 0; i++)
532                if (!vdef(mvar[i])) {
533                        *cp++ = '|';
534                        strcpy(cp, vnam(mvar[i]));
535                        while (*cp) cp++;
536                        pippt = NULL;
537                }
538        if (pippt != NULL)
539                strcpy(pippt, "> /dev/null");   /* nothing to match */
540        else
541                sprintf(cp, ")[ \t]*=' > %s", tf2);
542        if (system(combuf)) {
543                error(SYSTEM, "cannot execute rad command");
544                unlink(tf2);                    /* clean up */
545                unlink(tf1);
546                quit(1);
547        }
548        if (pippt == NULL) {
549                loadvars(tf2);                  /* load variables */
550                unlink(tf2);
551        }
552        rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
553        unlink(tf1);                    /* clean up */
554 }
555
556
544   rootname(rn, fn)                /* remove tail from end of fn */
545   register char   *rn, *fn;
546   {
547          char    *tp, *dp;
548  
549          for (tp = NULL, dp = rn; *rn = *fn++; rn++)
550 <                if (ISDIRSEP(*rn))
550 >                if (*rn == '/')
551                          dp = rn;
552                  else if (*rn == '.')
553                          tp = rn;
# Line 596 | Line 583 | register char  *s;
583   }
584  
585  
599 wputs(s)                        /* put warning string to stderr */
600 char    *s;
601 {
602        if (!nowarn)
603                eputs(s);
604 }
605
606
586   quit(ec)                        /* exit program gracefully */
587   int     ec;
588   {
589          int     status = 0;
590  
591 <        if (hdlist[0] != NULL) {        /* flush holodeck */
592 <                if (ncprocs > 0) {
593 <                        done_packets(flush_queue());
594 <                        status = end_rtrace();  /* close rtrace */
595 <                        hdflush(NULL);
596 <                        if (vdef(REPORT)) {
597 <                                long    fsiz, fuse;
598 <                                report(0);
620 <                                fsiz = hdfilen(hdlist[0]->fd);
621 <                                fuse = hdfiluse(hdlist[0]->fd, 1);
622 <                                fprintf(stderr,
591 >        if (hdlist[0] != NULL) {        /* close holodeck */
592 >                if (nprocs > 0)
593 >                        status = done_rtrace();         /* calls hdsync() */
594 >                if (ncprocs > 0 && vdef(REPORT)) {
595 >                        long    fsiz, fuse;
596 >                        fsiz = hdfilen(hdlist[0]->fd);
597 >                        fuse = hdfiluse(hdlist[0]->fd, 1);
598 >                        fprintf(stderr,
599                          "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n",
600 <                                                hdkfile, fsiz/(1024.*1024.),
601 <                                                100.*(fsiz-fuse)/fsiz);
602 <                        }
627 <                } else
628 <                        hdflush(NULL);
600 >                                        hdkfile, fsiz/(1024.*1024.),
601 >                                        100.*(fsiz-fuse)/fsiz);
602 >                }
603          }
604          if (orig_mode >= 0)             /* reset holodeck access mode */
605                  fchmod(hdlist[0]->fd, orig_mode);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines