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.11 by gregl, Wed Nov 19 17:56:47 1997 UTC vs.
Revision 3.37 by gregl, Fri Jan 16 11:45:43 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1997 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# Line 9 | Line 9 | static char SCCSid[] = "$SunId$ SGI";
9   */
10  
11   #include "rholo.h"
12 < #include "paths.h"
12 > #include "random.h"
13 > #include <signal.h>
14   #include <sys/types.h>
15 + #include <sys/stat.h>
16  
17 + #ifndef MAXQTIME
18 + #define MAXQTIME        5               /* target maximum seconds in queue */
19 + #endif
20                          /* the following must be consistent with rholo.h */
21   int     NVARS = NRHVARS;                /* total number of variables */
22  
# Line 19 | Line 24 | VARIABLE       vv[] = RHVINIT;         /* variable-value pairs */
24  
25   char    *progname;              /* our program name */
26   char    *hdkfile;               /* holodeck file name */
27 < char    froot[MAXPATH];         /* root file name */
27 > char    froot[256];             /* root file name */
28  
29   int     nowarn = 0;             /* turn warnings off? */
30  
26 double  expval = 1.;            /* global exposure value */
27
31   int     ncprocs = 0;            /* desired number of compute processes */
32  
33   char    *outdev = NULL;         /* output device name */
34  
35 + int     readinp = 0;            /* read commands from stdin */
36 +
37 + int     force = 0;              /* allow overwrite of holodeck */
38 +
39   time_t  starttime;              /* time we got started */
40   time_t  endtime;                /* time we should end by */
41   time_t  reporttime;             /* time for next report */
# Line 38 | Line 45 | long   maxdisk;                /* maximum file space (bytes) */
45   int     rtargc = 1;             /* rtrace command */
46   char    *rtargv[128] = {"rtrace", NULL};
47  
48 + int     orig_mode = -1;         /* original file mode (-1 if unchanged) */
49 +
50   long    nraysdone = 0L;         /* number of rays done */
51   long    npacksdone = 0L;        /* number of packets done */
52  
53   PACKET  *freepacks;             /* available packets */
54 + int     avgqlen;                /* average queue length when full */
55  
56 + char  *sigerr[NSIG];            /* signal error messages */
57 +
58   extern time_t   time();
59  
60  
# Line 50 | Line 62 | main(argc, argv)
62   int     argc;
63   char    *argv[];
64   {
53        HDGRID  hdg;
65          int     i;
66 <        int     force = 0;
67 <                                                /* mark start time */
57 <        starttime = time(NULL);
66 >
67 >        initurand(16384);                       /* initialize urand */
68          progname = argv[0];                     /* get arguments */
69          for (i = 1; i < argc && argv[i][0] == '-'; i++)
70                  switch (argv[i][1]) {
# Line 64 | Line 74 | char   *argv[];
74                  case 'f':                       /* force overwrite */
75                          force++;
76                          break;
77 +                case 'i':                       /* read input from stdin */
78 +                        readinp++;
79 +                        break;
80                  case 'n':                       /* compute processes */
81                          if (i >= argc-2)
82                                  goto userr;
# Line 77 | Line 90 | char   *argv[];
90                  default:
91                          goto userr;
92                  }
80                                                /* do we have a job? */
81        if (outdev == NULL && ncprocs <= 0)
82                goto userr;
93                                                  /* get root file name */
94 +        if (i >= argc)
95 +                goto userr;
96          rootname(froot, hdkfile=argv[i++]);
97 <                                                /* load... */
98 <        if (i < argc) {                         /* variables */
99 <                loadvars(argv[i++]);
100 <                                                        /* cmdline settings */
101 <                for ( ; i < argc; i++)
102 <                        if (setvariable(argv[i], matchvar) < 0) {
103 <                                sprintf(errmsg, "unknown variable: %s",
104 <                                                argv[i]);
105 <                                error(USER, errmsg);
106 <                        }
107 <                                                        /* check settings */
108 <                checkvalues();
109 <                                                        /* load RIF if any */
110 <                if (vdef(RIF))
111 <                        getradfile(vval(RIF));
97 >                                                /* load variables? */
98 >        if (i < argc)
99 >                if (argv[i][0] != '-' && argv[i][0] != '+')
100 >                        loadvars(argv[i]);      /* load variables from file */
101 >
102 >        if (i >= argc || argv[i][0] == '+')
103 >                loadholo();                     /* load existing holodeck */
104 >
105 >        while (++i < argc)                      /* get command line settings */
106 >                if (setvariable(argv[i], matchvar) < 0) {
107 >                        sprintf(errmsg, "unknown variable: %s", argv[i]);
108 >                        error(USER, errmsg);
109 >                }
110 >                                                /* check settings */
111 >        checkvalues();
112 >                                                /* load rad input file */
113 >        getradfile();
114 >
115 >        if (hdlist[0] == NULL) {                /* create new holodeck */
116 >                HDGRID  hdg[HDMAX];
117                                                          /* set defaults */
118 <                setdefaults(&hdg);
118 >                setdefaults(hdg);
119                                                          /* holodeck exists? */
120                  if (!force && access(hdkfile, R_OK|W_OK) == 0)
121                          error(USER,
122                                  "holodeck file exists -- use -f to overwrite");
123                                                          /* create holodeck */
124 <                creatholo(&hdg);
125 <        } else {                                /* else load holodeck */
126 <                loadholo();
110 <                if (vdef(RIF))                          /* load RIF if any */
111 <                        getradfile(vval(RIF));
112 <        }
124 >                creatholo(hdg);
125 >        } else                                  /* else just set defaults */
126 >                setdefaults(NULL);
127                                                  /* initialize */
128          initrholo();
129 <                                                /* run */
129 >                                                /* main loop */
130          while (rholo())
131                  ;
132                                                  /* done */
133          quit(0);
134   userr:
135          fprintf(stderr,
136 < "Usage: %s {-n nprocs|-o disp} [-w][-f] output.hdk [control.hif [VAR=val ..]]\n",
136 > "Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n",
137                          progname);
138          quit(1);
139   }
140  
141  
142 + onsig(signo)                            /* fatal signal */
143 + int  signo;
144 + {
145 +        static int  gotsig = 0;
146 +
147 +        if (gotsig++)                   /* two signals and we're gone! */
148 +                _exit(signo);
149 +
150 +        alarm(60);                      /* allow 60 seconds to clean up */
151 +        signal(SIGALRM, SIG_DFL);       /* make certain we do die */
152 +        eputs("signal - ");
153 +        eputs(sigerr[signo]);
154 +        eputs("\n");
155 +        quit(3);
156 + }
157 +
158 +
159 + sigdie(signo, msg)                      /* set fatal signal */
160 + int  signo;
161 + char  *msg;
162 + {
163 +        if (signal(signo, onsig) == SIG_IGN)
164 +                signal(signo, SIG_IGN);
165 +        sigerr[signo] = msg;
166 + }
167 +
168 +
169 + int
170 + resfmode(fd, mod)               /* restrict open file access mode */
171 + int     fd, mod;
172 + {
173 +        struct stat     stbuf;
174 +                                        /* get original mode */
175 +        if (fstat(fd, &stbuf) < 0)
176 +                error(SYSTEM, "cannot stat open holodeck file");
177 +        mod &= stbuf.st_mode;           /* always more restrictive */
178 +        if (mod == (stbuf.st_mode & 0777))
179 +                return(-1);             /* already set */
180 +                                        /* else change it */
181 +        if (fchmod(fd, mod) < 0) {
182 +                error(WARNING, "cannot change holodeck file access mode");
183 +                return(-1);
184 +        }
185 +        return(stbuf.st_mode);          /* return original mode */
186 + }
187 +
188 +
189   initrholo()                     /* get our holodeck running */
190   {
191          extern int      global_packet();
192          register int    i;
193 +                                                /* close holodeck on exec() */
194 +        fcntl(hdlist[0]->fd, F_SETFD, FD_CLOEXEC);
195  
196          if (outdev != NULL)                     /* open output device */
197                  disp_open(outdev);
# Line 139 | Line 202 | initrholo()                    /* get our holodeck running */
202                  maxdisk = 0;
203          else
204                  maxdisk = 1024.*1024.*vflt(DISKSPACE);
142                                                /* record end time */
143        if (!vdef(TIME) || vflt(TIME) <= FTINY)
144                endtime = 0;
145        else
146                endtime = starttime + vflt(TIME)*3600.;
205                                                  /* set up memory cache */
206          if (outdev == NULL)
207                  hdcachesize = 0;        /* manual flushing */
# Line 155 | Line 213 | initrholo()                    /* get our holodeck running */
213                  if (*s && freopen(s, "a", stderr) == NULL)
214                          quit(2);
215          }
216 +                                                /* mark the starting time */
217 +        starttime = time(NULL);
218 +                                                /* compute end time */
219 +        if (!vdef(TIME) || vflt(TIME) <= FTINY)
220 +                endtime = 0;
221 +        else
222 +                endtime = starttime + vflt(TIME)*3600. + .5;
223                                                  /* start rtrace */
224          if (ncprocs > 0) {
225                  i = start_rtrace();
226                  if (i < 1)
227 <                        error(USER, "cannot start rtrace process");
227 >                        error(USER, "cannot start rtrace process(es)");
228                  if (vdef(REPORT)) {             /* make first report */
229                          printargs(rtargc, rtargv, stderr);
230                          report(0);
# Line 168 | Line 233 | initrholo()                    /* get our holodeck running */
233                  freepacks = (PACKET *)bmalloc(i*sizeof(PACKET));
234                  if (freepacks == NULL)
235                          goto memerr;
236 +                if (!(avgqlen = i/nprocs))      /* record mean queue length */
237 +                        avgqlen = 1;
238                  freepacks[--i].nr = 0;
239                  freepacks[i].next = NULL;
240 <                if (!vbool(OBSTRUCTIONS)) {
240 >                if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) {
241                          freepacks[i].offset = (float *)bmalloc(
242                                          RPACKSIZ*sizeof(float)*(i+1) );
243                          if (freepacks[i].offset == NULL)
# Line 184 | Line 251 | initrholo()                    /* get our holodeck running */
251                          freepacks[i].next = &freepacks[i+1];
252                  }
253          }
254 +                                        /* set up signal handling */
255 +        sigdie(SIGINT, "Interrupt");
256 +        sigdie(SIGHUP, "Hangup");
257 +        sigdie(SIGTERM, "Terminate");
258 +        sigdie(SIGPIPE, "Broken pipe");
259 +        sigdie(SIGALRM, "Alarm clock");
260 + #ifdef  SIGXCPU
261 +        sigdie(SIGXCPU, "CPU limit exceeded");
262 +        sigdie(SIGXFSZ, "File size exceeded");
263 + #endif
264 +                                                /* protect holodeck file */
265 +        orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444);
266          return;
267   memerr:
268          error(SYSTEM, "out of memory in initrholo");
# Line 192 | Line 271 | memerr:
271  
272   rholo()                         /* holodeck main loop */
273   {
274 <        static int      idle = 1;
274 >        static int      idle = 0;
275          PACKET  *pl = NULL, *plend;
276 +        int     pksiz;
277          register PACKET *p;
278          time_t  t;
279 <        long    l;
280 <
281 <        if (outdev != NULL)             /* check display */
279 >                                        /* check display */
280 >        if (nprocs <= 0)
281 >                idle = 1;
282 >        if (outdev != NULL) {
283                  if (!disp_check(idle))
284 <                        return(0);
285 <                                        /* display only? */
286 <        if (ncprocs <= 0)
287 <                return(1);
284 >                        return(0);      /* quit request */
285 >                if (nprocs <= 0)
286 >                        return(1);
287 >        } else if (idle)
288 >                return(0);              /* all done */
289                                          /* check file size */
290          if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
291                  error(WARNING, "file limit exceeded");
292 <                return(0);
292 >                done_rtrace();
293 >                return(1);      /* comes back */
294          }
295 <                                        /* check time */
213 <        if (endtime > 0 || reporttime > 0)
214 <                t = time(NULL);
295 >        t = time(NULL);                 /* check time */
296          if (endtime > 0 && t >= endtime) {
297                  error(WARNING, "time limit exceeded");
298 <                return(0);
298 >                done_rtrace();
299 >                return(1);      /* comes back */
300          }
301          if (reporttime > 0 && t >= reporttime)
302                  report(t);
303 <                                        /* get packets to process */
303 >                                        /* figure out good packet size */
304 > #if MAXQTIME
305 >        pksiz = nraysdone*MAXQTIME/(avgqlen*(t - starttime + 1L));
306 >        if (pksiz < 1)
307 >                pksiz = 1;
308 >        else if (pksiz > RPACKSIZ)
309 > #endif
310 >                pksiz = RPACKSIZ;
311 >        idle = 0;                       /* get packets to process */
312          while (freepacks != NULL) {
313                  p = freepacks; freepacks = p->next; p->next = NULL;
314 <                if (!next_packet(p)) {
314 >                if (!next_packet(p, pksiz)) {
315                          p->next = freepacks; freepacks = p;
316 +                        idle = 1;
317                          break;
318                  }
319                  if (pl == NULL) pl = p;
320                  else plend->next = p;
321                  plend = p;
322          }
323 <        idle = pl == NULL && freepacks != NULL;
233 <                                        /* are we out of stuff to do? */
234 <        if (idle && outdev == NULL)
235 <                return(0);
236 <                                        /* else process packets */
323 >                                        /* process packets */
324          done_packets(do_packets(pl));
325          return(1);                      /* and continue */
326   }
327  
328  
242 report(t)                       /* report progress so far */
243 time_t  t;
244 {
245        if (t == 0)
246                t = time(NULL);
247        fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n",
248                        progname, npacksdone, nraysdone, (t-starttime)/3600.);
249        fflush(stderr);
250        if (vdef(REPORT))
251                reporttime = t + (time_t)(vflt(REPORT)*60.+.5);
252 }
253
254
329   setdefaults(gp)                 /* set default values */
330   register HDGRID *gp;
331   {
332          extern char     *atos();
333          register int    i;
334 <        double  len[3], maxlen, d;
334 >        int     n;
335 >        double  len[3], d;
336          char    buf[64];
337  
338          if (!vdef(SECTION)) {
339                  sprintf(errmsg, "%s must be defined", vnam(SECTION));
340                  error(USER, errmsg);
341          }
267        if (vdef(SECTION) > 1) {
268                sprintf(errmsg, "ignoring all but first %s", vnam(SECTION));
269                error(WARNING, errmsg);
270        }
271        if (sscanf(vval(SECTION),
272                        "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
273                        &gp->orig[0], &gp->orig[1], &gp->orig[2],
274                        &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
275                        &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
276                        &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2]) != 12)
277                badvalue(SECTION);
278        maxlen = 0.;
279        for (i = 0; i < 3; i++)
280                if ((len[i] = VLEN(gp->xv[i])) > maxlen)
281                        maxlen = len[i];
282        if (!vdef(GRID)) {
283                sprintf(buf, "%.4f", maxlen/8.);
284                vval(GRID) = savqstr(buf);
285                vdef(GRID)++;
286        }
287        if ((d = vflt(GRID)) <= FTINY)
288                badvalue(GRID);
289        for (i = 0; i < 3; i++)
290                gp->grid[i] = len[i]/d + (1.-FTINY);
291        if (!vdef(EXPOSURE)) {
292                sprintf(errmsg, "%s must be defined", vnam(EXPOSURE));
293                error(USER, errmsg);
294        }
295        expval = vval(EXPOSURE)[0] == '-' || vval(EXPOSURE)[0] == '+' ?
296                        pow(2., vflt(EXPOSURE)) : vflt(EXPOSURE);
342          if (!vdef(OCTREE)) {
343                  if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL)
344                          error(SYSTEM, "out of memory");
345                  sprintf(vval(OCTREE), "%s.oct", froot);
346                  vdef(OCTREE)++;
347          }
348 <        if (!vdef(OBSTRUCTIONS)) {
349 <                vval(OBSTRUCTIONS) = "T";
350 <                vdef(OBSTRUCTIONS)++;
348 >        if (!vdef(VDIST)) {
349 >                vval(VDIST) = "F";
350 >                vdef(VDIST)++;
351          }
307        if (!vdef(OCCUPANCY)) {
308                vval(OCCUPANCY) = "U";
309                vdef(OCCUPANCY)++;
310        }
352                                  /* append rendering options */
353          if (vdef(RENDER))
354                  rtargc += wordstring(rtargv+rtargc, vval(RENDER));
355 +        
356 +        if (gp == NULL)         /* already initialized? */
357 +                return;
358 +                                /* set grid parameters */
359 +        for (n = 0; n < vdef(SECTION); n++, gp++) {
360 +                gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
361 +                if (sscanf(nvalue(SECTION, n),
362 +                "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd",
363 +                                &gp->orig[0], &gp->orig[1], &gp->orig[2],
364 +                                &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
365 +                                &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
366 +                                &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
367 +                                &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
368 +                        badvalue(SECTION);
369 +                for (i = 0; i < 3; i++)
370 +                        len[i] = VLEN(gp->xv[i]);
371 +                if (!vdef(GRID)) {
372 +                        d = 2/5e5*( len[0]*len[0]*(len[1]*len[1] +
373 +                                        len[2]*len[2] + 4*len[1]*len[2])
374 +                                + len[1]*len[1]*len[2]*(len[2] + 4*len[0])
375 +                                + 4*len[0]*len[1]*len[2]*len[2] );
376 +                        d = sqrt(sqrt(d));
377 +                } else if ((d = vflt(GRID)) <= FTINY)
378 +                        badvalue(GRID);
379 +                for (i = 0; i < 3; i++)
380 +                        if (gp->grid[i] <= 0)
381 +                                gp->grid[i] = len[i]/d + (1.-FTINY);
382 +        }
383   }
384  
385  
386   creatholo(gp)                   /* create a holodeck output file */
387   HDGRID  *gp;
388   {
389 <        long    endloc = 0;
389 >        extern char     VersionID[];
390 >        int4    lastloc, nextloc;
391 >        int     n;
392          int     fd;
393          FILE    *fp;
394                                          /* open & truncate file */
# Line 327 | Line 398 | HDGRID *gp;
398          }
399                                          /* write information header */
400          newheader("RADIANCE", fp);
401 +        fprintf(fp, "SOFTWARE= %s\n", VersionID);
402          printvars(fp);
403          fputformat(HOLOFMT, fp);
404          fputc('\n', fp);
405 <        putw(HOLOMAGIC, fp);            /* put magic number & terminus */
334 <        fwrite(&endloc, sizeof(long), 1, fp);
405 >        putw(HOLOMAGIC, fp);            /* put magic number */
406          fd = dup(fileno(fp));
407          fclose(fp);                     /* flush and close stdio stream */
408 <        hdinit(fd, gp);                 /* allocate and initialize index */
408 >        lastloc = lseek(fd, 0L, 2);
409 >        for (n = vdef(SECTION); n--; gp++) {    /* initialize each section */
410 >                nextloc = 0L;
411 >                write(fd, (char *)&nextloc, sizeof(nextloc));
412 >                hdinit(fd, gp);                 /* writes beam index */
413 >                if (!n)
414 >                        break;
415 >                nextloc = hdfilen(fd);          /* write section pointer */
416 >                if (lseek(fd, (long)lastloc, 0) < 0)
417 >                        error(SYSTEM,
418 >                                "cannot seek on holodeck file in creatholo");
419 >                write(fd, (char *)&nextloc, sizeof(nextloc));
420 >                lseek(fd, (long)(lastloc=nextloc), 0);
421 >        }
422   }
423  
424  
# Line 367 | Line 451 | loadholo()                     /* start loading a holodeck from fname */
451          extern long     ftell();
452          FILE    *fp;
453          int     fd;
454 <        long    fpos;
454 >        int     n;
455 >        int4    nextloc;
456                                          /* open holodeck file */
457          if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
458                  sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile,
# Line 382 | Line 467 | loadholo()                     /* start loading a holodeck from fname */
467                                  hdkfile);
468                  error(USER, errmsg);
469          }
470 <        fread(&fpos, sizeof(long), 1, fp);
386 <        if (fpos != 0)
387 <                error(WARNING, "ignoring multiple sections in holodeck file");
388 <        fpos = ftell(fp);                       /* get stdio position */
470 >        nextloc = ftell(fp);                    /* get stdio position */
471          fd = dup(fileno(fp));
472          fclose(fp);                             /* done with stdio */
473 <        lseek(fd, fpos, 0);                     /* align system file pointer */
474 <        hdinit(fd, NULL);                       /* allocate and load index */
473 >        for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
474 >                lseek(fd, (long)nextloc, 0);
475 >                read(fd, (char *)&nextloc, sizeof(nextloc));
476 >                hdinit(fd, NULL);
477 >        }
478 >        if (n != vdef(SECTION)) {
479 >                sprintf(errmsg, "number of sections does not match %s setting",
480 >                                vnam(SECTION));
481 >                error(WARNING, errmsg);
482 >        }
483   }
484  
485  
486   done_packets(pl)                /* handle finished packets */
487   PACKET  *pl;
488   {
489 <        static int      nunflushed = 0;
489 >        static int      n2flush = 0;
490          register PACKET *p;
491  
492          while (pl != NULL) {
# Line 407 | Line 497 | PACKET *pl;
497                                  p->nr*sizeof(RAYVAL));
498                          if (outdev != NULL)     /* display it */
499                                  disp_packet((PACKHEAD *)p);
500 <                        else
501 <                                nunflushed += p->nr;
500 >                        if (hdcachesize <= 0)   /* manual flushing */
501 >                                n2flush++;
502                          nraysdone += p->nr;
503                          npacksdone++;
504 +                        p->nr = 0;
505                  }
506 <                p->nr = 0;                      /* push onto free list */
416 <                p->next = freepacks;
506 >                p->next = freepacks;            /* push onto free list */
507                  freepacks = p;
508          }
509 <        if (nunflushed >= 256*RPACKSIZ) {
509 >        if (n2flush > 300/MAXQTIME*avgqlen*nprocs) {
510                  hdflush(NULL);                  /* flush holodeck buffers */
511 <                nunflushed = 0;
511 >                n2flush = 0;
512          }
513   }
514  
515  
426 getradfile(rfargs)              /* run rad and get needed variables */
427 char    *rfargs;
428 {
429        static short    mvar[] = {OCTREE,EXPOSURE,-1};
430        static char     tf1[] = TEMPLATE;
431        char    tf2[64];
432        char    combuf[256];
433        char    *pippt;
434        register int    i;
435        register char   *cp;
436                                        /* create rad command */
437        mktemp(tf1);
438        sprintf(tf2, "%s.rif", tf1);
439        sprintf(combuf,
440                "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
441                        rfargs, tf1);
442        cp = combuf;
443        while (*cp){
444                if (*cp == '|') pippt = cp;
445                cp++;
446        }                               /* match unset variables */
447        for (i = 0; mvar[i] >= 0; i++)
448                if (!vdef(mvar[i])) {
449                        *cp++ = '|';
450                        strcpy(cp, vnam(mvar[i]));
451                        while (*cp) cp++;
452                        pippt = NULL;
453                }
454        if (pippt != NULL)
455                strcpy(pippt, "> /dev/null");   /* nothing to match */
456        else
457                sprintf(cp, ")[ \t]*=' > %s", tf2);
458        if (system(combuf)) {
459                error(SYSTEM, "cannot execute rad command");
460                unlink(tf2);                    /* clean up */
461                unlink(tf1);
462                quit(1);
463        }
464        if (pippt == NULL) {
465                loadvars(tf2);                  /* load variables */
466                unlink(tf2);
467        }
468        rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
469        unlink(tf1);                    /* clean up */
470 }
471
472
516   rootname(rn, fn)                /* remove tail from end of fn */
517   register char   *rn, *fn;
518   {
519          char    *tp, *dp;
520  
521          for (tp = NULL, dp = rn; *rn = *fn++; rn++)
522 <                if (ISDIRSEP(*rn))
522 >                if (*rn == '/')
523                          dp = rn;
524                  else if (*rn == '.')
525                          tp = rn;
# Line 525 | Line 568 | int    ec;
568   {
569          int     status = 0;
570  
571 <        if (hdlist[0] != NULL) {        /* flush holodeck */
572 <                if (ncprocs > 0) {
573 <                        done_packets(flush_queue());
574 <                        status = end_rtrace();  /* close rtrace */
575 <                        hdflush(NULL);
576 <                        if (vdef(REPORT)) {
577 <                                long    fsiz, fuse;
578 <                                report(0);
536 <                                fsiz = hdfilen(hdlist[0]->fd);
537 <                                fuse = hdfiluse(hdlist[0]->fd, 1);
538 <                                fprintf(stderr,
571 >        if (hdlist[0] != NULL) {        /* close holodeck */
572 >                if (nprocs > 0)
573 >                        status = done_rtrace();         /* calls hdsync() */
574 >                if (ncprocs > 0 && vdef(REPORT)) {
575 >                        long    fsiz, fuse;
576 >                        fsiz = hdfilen(hdlist[0]->fd);
577 >                        fuse = hdfiluse(hdlist[0]->fd, 1);
578 >                        fprintf(stderr,
579                          "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n",
580 <                                                hdkfile, fsiz/(1024.*1024.),
581 <                                                100.*(fsiz-fuse)/fsiz);
582 <                        }
543 <                } else
544 <                        hdflush(NULL);
580 >                                        hdkfile, fsiz/(1024.*1024.),
581 >                                        100.*(fsiz-fuse)/fsiz);
582 >                }
583          }
584 +        if (orig_mode >= 0)             /* reset holodeck access mode */
585 +                fchmod(hdlist[0]->fd, orig_mode);
586          if (outdev != NULL)             /* close display */
587                  disp_close();
588          exit(ec ? ec : status);         /* exit */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines