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.46 by gwlarson, Thu Jan 7 22:05:34 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 RTFLUSH
18 + #define RTFLUSH         0               /* flush one at a time in batch */
19 + #endif
20 + #ifndef FRAGWARN
21 + #define FRAGWARN        20              /* fragmentation for warning (%) */
22 + #endif
23 + #ifndef MAXQTIME
24 + #define MAXQTIME        5               /* target maximum seconds in queue */
25 + #endif
26                          /* the following must be consistent with rholo.h */
27   int     NVARS = NRHVARS;                /* total number of variables */
28  
# Line 22 | Line 30 | VARIABLE       vv[] = RHVINIT;         /* variable-value pairs */
30  
31   char    *progname;              /* our program name */
32   char    *hdkfile;               /* holodeck file name */
33 < char    froot[MAXPATH];         /* root file name */
33 > char    froot[256];             /* root file name */
34  
27 int     nowarn = 0;             /* turn warnings off? */
28
35   int     ncprocs = 0;            /* desired number of compute processes */
36  
37   char    *outdev = NULL;         /* output device name */
38  
39   int     readinp = 0;            /* read commands from stdin */
40  
41 + int     force = 0;              /* allow overwrite of holodeck */
42 +
43   time_t  starttime;              /* time we got started */
44   time_t  endtime;                /* time we should end by */
45   time_t  reporttime;             /* time for next report */
# Line 47 | Line 55 | long   nraysdone = 0L;         /* number of rays done */
55   long    npacksdone = 0L;        /* number of packets done */
56  
57   PACKET  *freepacks;             /* available packets */
58 + int     totqlen;                /* maximum queue length when full */
59  
60   char  *sigerr[NSIG];            /* signal error messages */
61  
62 + extern int      nowarn;         /* turn warnings off? */
63 +
64   extern time_t   time();
65  
66  
# Line 57 | Line 68 | main(argc, argv)
68   int     argc;
69   char    *argv[];
70   {
60        HDGRID  hdg;
71          int     i;
72 <        int     force = 0;
73 <                                                /* mark start time */
64 <        starttime = time(NULL);
65 <        initurand(10240);                       /* initialize urand */
72 >
73 >        initurand(16384);                       /* initialize urand */
74          progname = argv[0];                     /* get arguments */
75          for (i = 1; i < argc && argv[i][0] == '-'; i++)
76                  switch (argv[i][1]) {
# Line 88 | Line 96 | char   *argv[];
96                  default:
97                          goto userr;
98                  }
91                                                /* do we have a job? */
92        if (outdev == NULL && ncprocs <= 0)
93                goto userr;
99                                                  /* get root file name */
100 +        if (i >= argc)
101 +                goto userr;
102          rootname(froot, hdkfile=argv[i++]);
103 <                                                /* load... */
104 <        if (i < argc) {                         /* variables */
105 <                loadvars(argv[i++]);
106 <                                                        /* cmdline settings */
107 <                for ( ; i < argc; i++)
108 <                        if (setvariable(argv[i], matchvar) < 0) {
109 <                                sprintf(errmsg, "unknown variable: %s",
110 <                                                argv[i]);
111 <                                error(USER, errmsg);
112 <                        }
113 <                                                        /* check settings */
114 <                checkvalues();
115 <                                                        /* load RIF if any */
116 <                if (vdef(RIF))
117 <                        getradfile(vval(RIF));
103 >                                                /* load variables? */
104 >        if (i < argc)
105 >                if (argv[i][0] != '-' && argv[i][0] != '+')
106 >                        loadvars(argv[i]);      /* load variables from file */
107 >
108 >        if (i >= argc || argv[i][0] == '+')
109 >                loadholo();                     /* load existing holodeck */
110 >
111 >        while (++i < argc)                      /* get command line settings */
112 >                if (setvariable(argv[i], matchvar) < 0) {
113 >                        sprintf(errmsg, "unknown variable: %s", argv[i]);
114 >                        error(USER, errmsg);
115 >                }
116 >                                                /* check settings */
117 >        checkvalues();
118 >                                                /* load rad input file */
119 >        getradfile();
120 >
121 >        if (hdlist[0] == NULL) {                /* create new holodeck */
122 >                HDGRID  hdg[HDMAX];
123                                                          /* set defaults */
124 <                setdefaults(&hdg);
124 >                setdefaults(hdg);
125                                                          /* holodeck exists? */
126                  if (!force && access(hdkfile, R_OK|W_OK) == 0)
127                          error(USER,
128                                  "holodeck file exists -- use -f to overwrite");
129                                                          /* create holodeck */
130 <                creatholo(&hdg);
131 <        } 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 */
130 >                creatholo(hdg);
131 >        } else                                  /* else just set defaults */
132                  setdefaults(NULL);
128        }
133                                                  /* initialize */
134          initrholo();
135                                                  /* main loop */
# Line 135 | Line 139 | char   *argv[];
139          quit(0);
140   userr:
141          fprintf(stderr,
142 < "Usage: %s {-n nprocs|-o disp} [-w][-f] output.hdk [control.hif [VAR=val ..]]\n",
142 > "Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n",
143                          progname);
144          quit(1);
145   }
# Line 149 | Line 153 | int  signo;
153          if (gotsig++)                   /* two signals and we're gone! */
154                  _exit(signo);
155  
156 <        alarm(30);                      /* allow 30 seconds to clean up */
156 >        alarm(180);                     /* allow 3 minutes to clean up */
157          signal(SIGALRM, SIG_DFL);       /* make certain we do die */
158          eputs("signal - ");
159          eputs(sigerr[signo]);
# Line 177 | Line 181 | int    fd, mod;
181          if (fstat(fd, &stbuf) < 0)
182                  error(SYSTEM, "cannot stat open holodeck file");
183          mod &= stbuf.st_mode;           /* always more restrictive */
184 <        if (mod == stbuf.st_mode)
184 >        if (mod == (stbuf.st_mode & 0777))
185                  return(-1);             /* already set */
186                                          /* else change it */
187          if (fchmod(fd, mod) < 0) {
# Line 204 | Line 208 | initrholo()                    /* get our holodeck running */
208                  maxdisk = 0;
209          else
210                  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.;
211                                                  /* set up memory cache */
212          if (outdev == NULL)
213                  hdcachesize = 0;        /* manual flushing */
# Line 220 | Line 219 | initrholo()                    /* get our holodeck running */
219                  if (*s && freopen(s, "a", stderr) == NULL)
220                          quit(2);
221          }
222 +                                                /* mark the starting time */
223 +        starttime = time(NULL);
224 +                                                /* compute end time */
225 +        if (!vdef(TIME) || vflt(TIME) <= FTINY)
226 +                endtime = 0;
227 +        else
228 +                endtime = starttime + vflt(TIME)*3600. + .5;
229                                                  /* start rtrace */
230          if (ncprocs > 0) {
231 <                i = start_rtrace();
231 >                totqlen = i = start_rtrace();
232                  if (i < 1)
233 <                        error(USER, "cannot start rtrace process");
233 >                        error(USER, "cannot start rtrace process(es)");
234                  if (vdef(REPORT)) {             /* make first report */
235                          printargs(rtargc, rtargv, stderr);
236                          report(0);
# Line 235 | Line 241 | initrholo()                    /* get our holodeck running */
241                          goto memerr;
242                  freepacks[--i].nr = 0;
243                  freepacks[i].next = NULL;
244 <                if (!vbool(OBSTRUCTIONS)) {
244 >                if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) {
245                          freepacks[i].offset = (float *)bmalloc(
246                                          RPACKSIZ*sizeof(float)*(i+1) );
247                          if (freepacks[i].offset == NULL)
# Line 269 | Line 275 | memerr:
275  
276   rholo()                         /* holodeck main loop */
277   {
278 <        static int      idle = 1;
278 >        static long     nextfragwarn = 100*(1L<<20);
279 >        static int      idle = 0;
280          PACKET  *pl = NULL, *plend;
281 +        long    fsiz;
282 +        int     pksiz;
283          register PACKET *p;
284          time_t  t;
285 <        long    l;
286 <
287 <        if (outdev != NULL)             /* check display */
285 >                                        /* check display */
286 >        if (nprocs <= 0)
287 >                idle = 1;
288 >        if (outdev != NULL) {
289                  if (!disp_check(idle))
290 <                        return(0);
291 <                                        /* display only? */
292 <        if (ncprocs <= 0)
293 <                return(1);
294 <                                        /* check file size */
295 <        if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
290 >                        return(0);      /* quit request */
291 >                if (nprocs <= 0)
292 >                        return(1);
293 >        } else if (idle)
294 >                return(0);              /* all done */
295 >        fsiz = hdfilen(hdlist[0]->fd);  /* check file size */
296 >        if (maxdisk > 0 && fsiz >= maxdisk) {
297                  error(WARNING, "file limit exceeded");
298 <                return(0);
298 >                done_rtrace();
299 >                return(1);      /* comes back */
300          }
301 <                                        /* check time */
302 <        if (endtime > 0 || reporttime > 0)
303 <                t = time(NULL);
301 > #if FRAGWARN
302 >        if (fsiz >= nextfragwarn &&
303 >                (fsiz-hdfiluse(hdlist[0]->fd,0))/(fsiz/100) > FRAGWARN) {
304 >                sprintf(errmsg, "holodeck file fragmentation is %.0f%%",
305 >                                100.*(fsiz-hdfiluse(hdlist[0]->fd,1))/fsiz);
306 >                error(WARNING, errmsg);
307 >                nextfragwarn = fsiz + (fsiz>>2);        /* decent interval */
308 >        }
309 > #endif
310 >        t = time(NULL);                 /* check time */
311          if (endtime > 0 && t >= endtime) {
312                  error(WARNING, "time limit exceeded");
313 <                return(0);
313 >                done_rtrace();
314 >                return(1);      /* comes back */
315          }
316          if (reporttime > 0 && t >= reporttime)
317                  report(t);
318 <                                        /* get packets to process */
318 >                                        /* figure out good packet size */
319 > #if MAXQTIME
320 >        pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L));
321 >        if (pksiz < 1)
322 >                pksiz = 1;
323 >        else if (pksiz > RPACKSIZ)
324 > #endif
325 >                pksiz = RPACKSIZ;
326 >        idle = 0;                       /* get packets to process */
327          while (freepacks != NULL) {
328                  p = freepacks; freepacks = p->next; p->next = NULL;
329 <                if (!next_packet(p)) {
329 >                if (!next_packet(p, pksiz)) {
330                          p->next = freepacks; freepacks = p;
331 +                        idle = 1;
332                          break;
333                  }
334                  if (pl == NULL) pl = p;
335                  else plend->next = p;
336                  plend = p;
337          }
338 <        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 */
338 >                                        /* process packets */
339          done_packets(do_packets(pl));
340          return(1);                      /* and continue */
341   }
342  
343  
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
344   setdefaults(gp)                 /* set default values */
345   register HDGRID *gp;
346   {
347          extern char     *atos();
348          register int    i;
349 <        double  len[3], maxlen, d;
349 >        int     n;
350 >        double  len[3], d;
351          char    buf[64];
352  
353          if (!vdef(SECTION)) {
354                  sprintf(errmsg, "%s must be defined", vnam(SECTION));
355                  error(USER, errmsg);
356          }
344        if (vdef(SECTION) > 1) {
345                sprintf(errmsg, "ignoring all but first %s", vnam(SECTION));
346                error(WARNING, errmsg);
347        }
357          if (!vdef(OCTREE)) {
358                  if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL)
359                          error(SYSTEM, "out of memory");
360                  sprintf(vval(OCTREE), "%s.oct", froot);
361                  vdef(OCTREE)++;
362          }
354        if (!vdef(OBSTRUCTIONS)) {
355                vval(OBSTRUCTIONS) = "T";
356                vdef(OBSTRUCTIONS)++;
357        }
363          if (!vdef(VDIST)) {
364                  vval(VDIST) = "F";
365                  vdef(VDIST)++;
366          }
362        if (!vdef(OCCUPANCY)) {
363                vval(OCCUPANCY) = "U";
364                vdef(OCCUPANCY)++;
365        }
367                                  /* append rendering options */
368          if (vdef(RENDER))
369                  rtargc += wordstring(rtargv+rtargc, vval(RENDER));
# Line 370 | Line 371 | register HDGRID        *gp;
371          if (gp == NULL)         /* already initialized? */
372                  return;
373                                  /* set grid parameters */
374 <        gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
375 <        if (sscanf(vval(SECTION),
374 >        for (n = 0; n < vdef(SECTION); n++, gp++) {
375 >                gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
376 >                if (sscanf(nvalue(SECTION, n),
377                  "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd",
378 <                        &gp->orig[0], &gp->orig[1], &gp->orig[2],
379 <                        &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
380 <                        &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
381 <                        &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
382 <                        &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
383 <                badvalue(SECTION);
384 <        maxlen = 0.;
385 <        for (i = 0; i < 3; i++)
386 <                if ((len[i] = VLEN(gp->xv[i])) > maxlen)
387 <                        maxlen = len[i];
388 <        if (!vdef(GRID)) {
389 <                sprintf(buf, "%.4f", maxlen/8.);
390 <                vval(GRID) = savqstr(buf);
391 <                vdef(GRID)++;
378 >                                &gp->orig[0], &gp->orig[1], &gp->orig[2],
379 >                                &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
380 >                                &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
381 >                                &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
382 >                                &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
383 >                        badvalue(SECTION);
384 >                for (i = 0; i < 3; i++)
385 >                        len[i] = VLEN(gp->xv[i]);
386 >                if (!vdef(GRID)) {
387 >                        d = 2/2e5*( len[0]*len[0]*(len[1]*len[1] +
388 >                                        len[2]*len[2] + 4*len[1]*len[2])
389 >                                + len[1]*len[1]*len[2]*(len[2] + 4*len[0])
390 >                                + 4*len[0]*len[1]*len[2]*len[2] );
391 >                        d = sqrt(sqrt(d));
392 >                } else if ((d = vflt(GRID)) <= FTINY)
393 >                        badvalue(GRID);
394 >                for (i = 0; i < 3; i++)
395 >                        if (gp->grid[i] <= 0)
396 >                                gp->grid[i] = len[i]/d + (1.-FTINY);
397          }
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);
398   }
399  
400  
# Line 400 | Line 402 | creatholo(gp)                  /* create a holodeck output file */
402   HDGRID  *gp;
403   {
404          extern char     VersionID[];
405 <        long    endloc = 0;
405 >        int4    lastloc, nextloc;
406 >        int     n;
407          int     fd;
408          FILE    *fp;
409                                          /* open & truncate file */
# Line 414 | Line 417 | HDGRID *gp;
417          printvars(fp);
418          fputformat(HOLOFMT, fp);
419          fputc('\n', fp);
420 <        putw(HOLOMAGIC, fp);            /* put magic number & terminus */
418 <        fwrite(&endloc, sizeof(long), 1, fp);
420 >        putw(HOLOMAGIC, fp);            /* put magic number */
421          fd = dup(fileno(fp));
422          fclose(fp);                     /* flush and close stdio stream */
423 <        hdinit(fd, gp);                 /* allocate and initialize index */
423 >        lastloc = lseek(fd, 0L, 2);
424 >        for (n = vdef(SECTION); n--; gp++) {    /* initialize each section */
425 >                nextloc = 0L;
426 >                write(fd, (char *)&nextloc, sizeof(nextloc));
427 >                hdinit(fd, gp);                 /* writes beam index */
428 >                if (!n)
429 >                        break;
430 >                nextloc = hdfilen(fd);          /* write section pointer */
431 >                if (lseek(fd, (long)lastloc, 0) < 0)
432 >                        error(SYSTEM,
433 >                                "cannot seek on holodeck file in creatholo");
434 >                write(fd, (char *)&nextloc, sizeof(nextloc));
435 >                lseek(fd, (long)(lastloc=nextloc), 0);
436 >        }
437   }
438  
439  
440 + int
441   headline(s)                     /* process information header line */
442   char    *s;
443   {
# Line 435 | Line 451 | char   *s;
451                                          HOLOFMT, hdkfile, FMTSTR, fmt);
452                          error(USER, errmsg);
453                  }
454 <                return;
454 >                return(0);
455          }
456          for (cp = s; *cp; cp++)         /* take off any comments */
457                  if (*cp == '#') {
# Line 443 | Line 459 | char   *s;
459                          break;
460                  }
461          setvariable(s, matchvar);       /* don't flag errors */
462 +        return(0);
463   }
464  
465  
# Line 451 | Line 468 | loadholo()                     /* start loading a holodeck from fname */
468          extern long     ftell();
469          FILE    *fp;
470          int     fd;
471 <        long    fpos;
471 >        int     n;
472 >        int4    nextloc;
473                                          /* open holodeck file */
474          if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
475 <                sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile,
476 <                                ncprocs>0 ? "appending" : "reading");
475 >                sprintf(errmsg, "cannot %s \"%s\"",
476 >                                ncprocs>0 ? "append" : "read", hdkfile);
477                  error(SYSTEM, errmsg);
478          }
479                                          /* load variables from header */
# Line 466 | Line 484 | loadholo()                     /* start loading a holodeck from fname */
484                                  hdkfile);
485                  error(USER, errmsg);
486          }
487 <        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 */
487 >        nextloc = ftell(fp);                    /* get stdio position */
488          fd = dup(fileno(fp));
489          fclose(fp);                             /* done with stdio */
490 <        lseek(fd, fpos, 0);                     /* align system file pointer */
491 <        hdinit(fd, NULL);                       /* allocate and load index */
490 >        for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
491 >                lseek(fd, (long)nextloc, 0);
492 >                read(fd, (char *)&nextloc, sizeof(nextloc));
493 >                hdinit(fd, NULL);
494 >        }
495 >        if (n != vdef(SECTION)) {
496 >                sprintf(errmsg, "number of sections does not match %s setting",
497 >                                vnam(SECTION));
498 >                error(WARNING, errmsg);
499 >        }
500   }
501  
502  
# Line 491 | Line 514 | PACKET *pl;
514                                  p->nr*sizeof(RAYVAL));
515                          if (outdev != NULL)     /* display it */
516                                  disp_packet((PACKHEAD *)p);
517 <                        if (hdcachesize <= 0)   /* manual flushing */
518 <                                n2flush += p->nr;
517 >                        if (hdcachesize <= 0) {
518 > #if RTFLUSH
519 >                                if (outdev == NULL)
520 >                                        hdfreebeam(hdlist[p->hd], p->bi);
521 > #endif
522 >                                n2flush++;
523 >                        }
524                          nraysdone += p->nr;
525                          npacksdone++;
526 +                        p->nr = 0;
527                  }
528 <                p->nr = 0;                      /* push onto free list */
500 <                p->next = freepacks;
528 >                p->next = freepacks;            /* push onto free list */
529                  freepacks = p;
530          }
531 <        if (n2flush > 512*RPACKSIZ*ncprocs) {
532 <                hdflush(NULL);                  /* flush holodeck buffers */
531 > #if MAXQTIME
532 >        if (n2flush > 300/MAXQTIME*totqlen) {
533 > #else
534 >        if (n2flush > 50*totqlen) {
535 > #endif
536 > #if RTFLUSH
537 >                hdsync(NULL, outdev!=NULL);     /* sync beams & directories */
538 > #else
539 >                if (outdev != NULL)
540 >                        hdsync(NULL, 1);
541 >                else
542 >                        hdflush(NULL);
543 > #endif
544                  n2flush = 0;
545          }
546   }
547  
548  
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
549   rootname(rn, fn)                /* remove tail from end of fn */
550   register char   *rn, *fn;
551   {
552          char    *tp, *dp;
553  
554          for (tp = NULL, dp = rn; *rn = *fn++; rn++)
555 <                if (ISDIRSEP(*rn))
555 >                if (*rn == '/')
556                          dp = rn;
557                  else if (*rn == '.')
558                          tp = rn;
# Line 596 | Line 588 | register char  *s;
588   }
589  
590  
599 wputs(s)                        /* put warning string to stderr */
600 char    *s;
601 {
602        if (!nowarn)
603                eputs(s);
604 }
605
606
591   quit(ec)                        /* exit program gracefully */
592   int     ec;
593   {
594          int     status = 0;
595  
596 <        if (hdlist[0] != NULL) {        /* flush holodeck */
597 <                if (ncprocs > 0) {
598 <                        done_packets(flush_queue());
599 <                        status = end_rtrace();  /* close rtrace */
600 <                        hdflush(NULL);
601 <                        if (vdef(REPORT)) {
602 <                                long    fsiz, fuse;
603 <                                report(0);
620 <                                fsiz = hdfilen(hdlist[0]->fd);
621 <                                fuse = hdfiluse(hdlist[0]->fd, 1);
622 <                                fprintf(stderr,
596 >        if (hdlist[0] != NULL) {        /* close holodeck */
597 >                if (nprocs > 0)
598 >                        status = done_rtrace();         /* calls hdsync() */
599 >                if (ncprocs > 0 && vdef(REPORT)) {
600 >                        long    fsiz, fuse;
601 >                        fsiz = hdfilen(hdlist[0]->fd);
602 >                        fuse = hdfiluse(hdlist[0]->fd, 1);
603 >                        fprintf(stderr,
604                          "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n",
605 <                                                hdkfile, fsiz/(1024.*1024.),
606 <                                                100.*(fsiz-fuse)/fsiz);
607 <                        }
627 <                } else
628 <                        hdflush(NULL);
605 >                                        hdkfile, fsiz/(1024.*1024.),
606 >                                        100.*(fsiz-fuse)/fsiz);
607 >                }
608          }
609          if (orig_mode >= 0)             /* reset holodeck access mode */
610                  fchmod(hdlist[0]->fd, orig_mode);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines