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.28 by gregl, Mon Dec 15 20:43:01 1997 UTC vs.
Revision 3.70 by greg, Thu Dec 15 16:47:16 2005 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Radiance holodeck generation controller
6   */
7  
8 < #include "rholo.h"
9 < #include "random.h"
8 > #include <stdio.h>
9 > #include <time.h>
10   #include <signal.h>
14 #include <sys/types.h>
11   #include <sys/stat.h>
12 + #include <string.h>
13  
14 + #include "platform.h"
15 + #include "rterror.h"
16 + #include "resolu.h"
17 + #include "rholo.h"
18 + #include "random.h"
19 +
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 +                                        /* manual cache flushing frequency */
27 + #ifndef RTFLUSH
28 + #if MAXQTIME
29 + #define RTFLUSH         (300/MAXQTIME*totqlen)  /* <= 5 minutes */
30 + #else
31 + #define RTFLUSH         (50*totqlen)            /* just guess */
32 + #endif
33 + #endif
34                          /* the following must be consistent with rholo.h */
35   int     NVARS = NRHVARS;                /* total number of variables */
36  
# Line 23 | Line 40 | char   *progname;              /* our program name */
40   char    *hdkfile;               /* holodeck file name */
41   char    froot[256];             /* root file name */
42  
26 int     nowarn = 0;             /* turn warnings off? */
27
43   int     ncprocs = 0;            /* desired number of compute processes */
44  
45   char    *outdev = NULL;         /* output device name */
46  
47   int     readinp = 0;            /* read commands from stdin */
48  
49 < int     force = 0;              /* allow overwrite of holodeck */
49 > int     force = 0;              /* allow overwrite of holodeck (-1 == read-only) */
50  
51   time_t  starttime;              /* time we got started */
52   time_t  endtime;                /* time we should end by */
53   time_t  reporttime;             /* time for next report */
54  
55 < long    maxdisk;                /* maximum file space (bytes) */
55 > off_t   maxdisk;                /* maximum file space (bytes) */
56  
57   int     rtargc = 1;             /* rtrace command */
58   char    *rtargv[128] = {"rtrace", NULL};
# Line 48 | Line 63 | long   nraysdone = 0L;         /* number of rays done */
63   long    npacksdone = 0L;        /* number of packets done */
64  
65   PACKET  *freepacks;             /* available packets */
66 + int     totqlen;                /* maximum queue length (number of packets) */
67  
68   char  *sigerr[NSIG];            /* signal error messages */
69  
70 < extern time_t   time();
70 > extern int      nowarn;         /* turn warnings off? */
71  
72 + static void onsig(int  signo);
73 + static void sigdie(int  signo, char  *msg);
74 + static int resfmode(int fd, int mod);
75 + static void initrholo(void);
76 + static int rholo(void);
77 + static void setdefaults(HDGRID  *gp);
78 + static void creatholo(HDGRID    *gp);
79 + static gethfunc headline;
80 + static void loadholo(void);
81 + static void rootname(char       *rn, char       *fn);
82 + static void badvalue(int        vc);
83  
84 < main(argc, argv)
85 < int     argc;
86 < char    *argv[];
84 >
85 > int
86 > main(
87 >        int     argc,
88 >        char    *argv[]
89 > )
90   {
61        HDGRID  hdg;
91          int     i;
92 <                                                /* mark start time */
64 <        starttime = time(NULL);
65 <        initurand(16384);                       /* initialize urand */
92 >
93          progname = argv[0];                     /* get arguments */
94          for (i = 1; i < argc && argv[i][0] == '-'; i++)
95                  switch (argv[i][1]) {
# Line 70 | Line 97 | char   *argv[];
97                          nowarn++;
98                          break;
99                  case 'f':                       /* force overwrite */
100 <                        force++;
100 >                        force = 1;
101                          break;
102 +                case 'r':                       /* read-only mode */
103 +                        force = -1;
104 +                        break;
105                  case 'i':                       /* read input from stdin */
106                          readinp++;
107                          break;
# Line 89 | Line 119 | char   *argv[];
119                          goto userr;
120                  }
121                                                  /* get root file name */
122 +        if (i >= argc)
123 +                goto userr;
124          rootname(froot, hdkfile=argv[i++]);
125                                                  /* load variables? */
126          if (i < argc)
# Line 105 | Line 137 | char   *argv[];
137                  }
138                                                  /* check settings */
139          checkvalues();
140 <                                                /* load RIF if any */
140 >                                                /* load rad input file */
141          getradfile();
142  
143          if (hdlist[0] == NULL) {                /* create new holodeck */
144 +                HDGRID  hdg[HDMAX];
145                                                          /* set defaults */
146 <                setdefaults(&hdg);
146 >                setdefaults(hdg);
147 >                                                        /* check read-only */
148 >                if (force < 0)
149 >                        error(USER, "cannot create read-only holodeck");
150                                                          /* holodeck exists? */
151                  if (!force && access(hdkfile, R_OK|W_OK) == 0)
152                          error(USER,
153                                  "holodeck file exists -- use -f to overwrite");
154                                                          /* create holodeck */
155 <                creatholo(&hdg);
155 >                creatholo(hdg);
156          } else                                  /* else just set defaults */
157                  setdefaults(NULL);
158                                                  /* initialize */
# Line 128 | Line 164 | char   *argv[];
164          quit(0);
165   userr:
166          fprintf(stderr,
167 < "Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n",
167 > "Usage: %s [-n nprocs][-o disp][-w][-r|-f] output.hdk [control.hif|+|- [VAR=val ..]]\n",
168                          progname);
169          quit(1);
170 +        return 1; /* pro forma return */
171   }
172  
173  
174 < onsig(signo)                            /* fatal signal */
175 < int  signo;
174 > static void
175 > onsig(                          /* fatal signal */
176 >        int  signo
177 > )
178   {
179          static int  gotsig = 0;
180  
181 <        if (gotsig++)                   /* two signals and we're gone! */
181 >        if (gotsig > 1)                 /* we're going as fast as we can! */
182 >                return;
183 >        if (gotsig++) {                 /* two signals and we split */
184 >                hdsync(NULL, 0);        /* don't leave w/o saying goodbye */
185                  _exit(signo);
186 <
187 <        alarm(60);                      /* allow 60 seconds to clean up */
146 <        signal(SIGALRM, SIG_DFL);       /* make certain we do die */
186 >        }
187 >        alarm(300);                     /* allow 5 minutes to clean up */
188          eputs("signal - ");
189          eputs(sigerr[signo]);
190          eputs("\n");
# Line 151 | Line 192 | int  signo;
192   }
193  
194  
195 < sigdie(signo, msg)                      /* set fatal signal */
196 < int  signo;
197 < char  *msg;
195 > static void
196 > sigdie(                 /* set fatal signal */
197 >        int  signo,
198 >        char  *msg
199 > )
200   {
201          if (signal(signo, onsig) == SIG_IGN)
202                  signal(signo, SIG_IGN);
# Line 161 | Line 204 | char  *msg;
204   }
205  
206  
207 < int
208 < resfmode(fd, mod)               /* restrict open file access mode */
209 < int     fd, mod;
207 > static int
208 > resfmode(               /* restrict open file access mode */
209 >        int     fd,
210 >        int     mod
211 > )
212   {
213          struct stat     stbuf;
214                                          /* get original mode */
215          if (fstat(fd, &stbuf) < 0)
216                  error(SYSTEM, "cannot stat open holodeck file");
217          mod &= stbuf.st_mode;           /* always more restrictive */
218 <        if (mod == stbuf.st_mode)
218 >        if (mod == (stbuf.st_mode & 0777))
219                  return(-1);             /* already set */
220                                          /* else change it */
221          if (fchmod(fd, mod) < 0) {
# Line 181 | Line 226 | int    fd, mod;
226   }
227  
228  
229 < initrholo()                     /* get our holodeck running */
229 > static void
230 > initrholo(void)                 /* get our holodeck running */
231   {
232          extern int      global_packet();
233          register int    i;
# Line 194 | Line 240 | initrholo()                    /* get our holodeck running */
240                  init_global();
241                                                  /* record disk space limit */
242          if (!vdef(DISKSPACE))
243 <                maxdisk = 0;
243 >                maxdisk = ((off_t)1<<(sizeof(off_t)*8-2)) - 1024;
244          else
245                  maxdisk = 1024.*1024.*vflt(DISKSPACE);
200                                                /* record end time */
201        if (!vdef(TIME) || vflt(TIME) <= FTINY)
202                endtime = 0;
203        else
204                endtime = starttime + vflt(TIME)*3600. + .5;
246                                                  /* set up memory cache */
247          if (outdev == NULL)
248 <                hdcachesize = 0;        /* manual flushing */
248 >                hdcachesize = 0;                /* manual flushing */
249          else if (vdef(CACHE))
250                  hdcachesize = 1024.*1024.*vflt(CACHE);
251                                                  /* open report file */
# Line 213 | Line 254 | initrholo()                    /* get our holodeck running */
254                  if (*s && freopen(s, "a", stderr) == NULL)
255                          quit(2);
256          }
257 +                                                /* mark the starting time */
258 +        starttime = time(NULL);
259 +                                                /* compute end time */
260 +        if (!vdef(TIME) || vflt(TIME) <= FTINY)
261 +                endtime = 0;
262 +        else
263 +                endtime = starttime + vflt(TIME)*3600. + .5;
264                                                  /* start rtrace */
265          if (ncprocs > 0) {
266 <                i = start_rtrace();
266 >                totqlen = i = start_rtrace();
267                  if (i < 1)
268                          error(USER, "cannot start rtrace process(es)");
269                  if (vdef(REPORT)) {             /* make first report */
# Line 244 | Line 292 | initrholo()                    /* get our holodeck running */
292          }
293                                          /* set up signal handling */
294          sigdie(SIGINT, "Interrupt");
247        sigdie(SIGHUP, "Hangup");
295          sigdie(SIGTERM, "Terminate");
296 + #ifdef SIGHUP
297 +        sigdie(SIGHUP, "Hangup");
298 + #endif
299 + #ifdef SIGPIPE
300          sigdie(SIGPIPE, "Broken pipe");
301 + #endif
302 + #ifdef SIGALRM
303          sigdie(SIGALRM, "Alarm clock");
304 + #endif
305   #ifdef  SIGXCPU
306          sigdie(SIGXCPU, "CPU limit exceeded");
307 + #endif
308 + #ifdef  SIGXFSZ
309          sigdie(SIGXFSZ, "File size exceeded");
310   #endif
311 <                                                /* protect holodeck file */
312 <        orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444);
311 >                                        /* protect holodeck file */
312 >        orig_mode = resfmode(hdlist[0]->fd, (ncprocs>0) & (force>=0) ? 0 : 0444);
313          return;
314   memerr:
315          error(SYSTEM, "out of memory in initrholo");
316   }
317  
318  
319 < rholo()                         /* holodeck main loop */
319 > static int
320 > rholo(void)                             /* holodeck main loop */
321   {
322 <        static int      idle = 1;
322 >        static long     nextfragwarn = 100L<<20;
323 >        static int      idle = 0;
324          PACKET  *pl = NULL, *plend;
325 +        off_t   fsiz;
326 +        int     pksiz;
327          register PACKET *p;
328          time_t  t;
329 <        long    l;
330 <
271 <        if (outdev != NULL)             /* check display */
272 <                if (!disp_check(idle))
273 <                        return(0);
274 <                                        /* display only? */
275 <        if (nprocs <= 0) {
329 >                                        /* check display */
330 >        if (nprocs <= 0)
331                  idle = 1;
332 <                return(outdev != NULL);
333 <        }
334 <                                        /* check file size */
335 <        if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
336 <                error(WARNING, "file limit exceeded");
332 >        if (outdev != NULL) {
333 >                if (!disp_check(idle))
334 >                        return(0);      /* quit request */
335 >                if (nprocs <= 0)
336 >                        return(1);
337 >        } else if (idle)
338 >                return(0);              /* all done */
339 >        fsiz = hdfilen(hdlist[0]->fd);  /* check file size */
340 >        if (maxdisk > 0 && fsiz >= maxdisk) {
341 >                error(USER, "file limit exceeded");
342                  done_rtrace();
343                  return(1);      /* comes back */
344          }
345 <                                        /* check time */
346 <        if (endtime > 0 || reporttime > 0)
347 <                t = time(NULL);
345 > #if FRAGWARN
346 >        if (fsiz >= nextfragwarn) {
347 >                double  pctfrag = 100.*(fsiz-hdfiluse(hdlist[0]->fd))/fsiz;
348 >                if (pctfrag >= (double)FRAGWARN) {
349 >                        sprintf(errmsg, "holodeck file fragmentation is %.0f%%",
350 >                                        pctfrag);
351 >                        error(WARNING, errmsg);
352 >                        nextfragwarn = fsiz + (fsiz>>2);
353 >                } else
354 >                        nextfragwarn = fsiz + (10L<<20);
355 >        }
356 > #endif
357 >        t = time(NULL);                 /* check time */
358          if (endtime > 0 && t >= endtime) {
359 <                error(WARNING, "time limit exceeded");
359 >                error(USER, "time limit exceeded");
360                  done_rtrace();
361                  return(1);      /* comes back */
362          }
363          if (reporttime > 0 && t >= reporttime)
364                  report(t);
365 +                                        /* figure out good packet size */
366 +        pksiz = RPACKSIZ;
367 + #if MAXQTIME
368 +        if (!chunkycmp) {
369 +                pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L));
370 +                if (pksiz < 1) pksiz = 1;
371 +                else if (pksiz > RPACKSIZ) pksiz = RPACKSIZ;
372 +        }
373 + #endif
374          idle = 0;                       /* get packets to process */
375          while (freepacks != NULL) {
376                  p = freepacks; freepacks = p->next; p->next = NULL;
377 <                if (!next_packet(p)) {
377 >                if (!next_packet(p, pksiz)) {
378                          p->next = freepacks; freepacks = p;
379                          idle = 1;
380                          break;
# Line 310 | Line 389 | rholo()                                /* holodeck main loop */
389   }
390  
391  
392 < setdefaults(gp)                 /* set default values */
393 < register HDGRID *gp;
392 > static void
393 > setdefaults(                    /* set default values */
394 >        register HDGRID *gp
395 > )
396   {
397          extern char     *atos();
398          register int    i;
399 <        double  len[3], maxlen, d;
400 <        char    buf[64];
399 >        int     n;
400 >        double  len[3], d;
401  
402          if (!vdef(SECTION)) {
403                  sprintf(errmsg, "%s must be defined", vnam(SECTION));
404                  error(USER, errmsg);
405          }
325        if (vdef(SECTION) > 1) {
326                sprintf(errmsg, "ignoring all but first %s", vnam(SECTION));
327                error(WARNING, errmsg);
328        }
406          if (!vdef(OCTREE)) {
407                  if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL)
408                          error(SYSTEM, "out of memory");
# Line 343 | Line 420 | register HDGRID        *gp;
420          if (gp == NULL)         /* already initialized? */
421                  return;
422                                  /* set grid parameters */
423 <        gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
424 <        if (sscanf(vval(SECTION),
423 >        for (n = 0; n < vdef(SECTION); n++, gp++) {
424 >                gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
425 >                if (sscanf(nvalue(SECTION, n),
426                  "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd",
427 <                        &gp->orig[0], &gp->orig[1], &gp->orig[2],
428 <                        &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
429 <                        &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
430 <                        &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
431 <                        &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
432 <                badvalue(SECTION);
433 <        maxlen = 0.;
434 <        for (i = 0; i < 3; i++)
435 <                if ((len[i] = VLEN(gp->xv[i])) > maxlen)
436 <                        maxlen = len[i];
437 <        if (!vdef(GRID)) {
438 <                sprintf(buf, "%.4f", maxlen/8.);
439 <                vval(GRID) = savqstr(buf);
440 <                vdef(GRID)++;
427 >                                &gp->orig[0], &gp->orig[1], &gp->orig[2],
428 >                                &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
429 >                                &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
430 >                                &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
431 >                                &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
432 >                        badvalue(SECTION);
433 >                for (i = 0; i < 3; i++)
434 >                        len[i] = VLEN(gp->xv[i]);
435 >                if (!vdef(GRID)) {
436 >                        d = 2/2e5*( len[0]*len[0]*(len[1]*len[1] +
437 >                                        len[2]*len[2] + 4*len[1]*len[2])
438 >                                + len[1]*len[1]*len[2]*(len[2] + 4*len[0])
439 >                                + 4*len[0]*len[1]*len[2]*len[2] );
440 >                        d = sqrt(sqrt(d));
441 >                } else if ((d = vflt(GRID)) <= FTINY)
442 >                        badvalue(GRID);
443 >                for (i = 0; i < 3; i++)
444 >                        if (gp->grid[i] <= 0)
445 >                                gp->grid[i] = len[i]/d + (1.-FTINY);
446          }
364        if ((d = vflt(GRID)) <= FTINY)
365                badvalue(GRID);
366        for (i = 0; i < 3; i++)
367                if (gp->grid[i] <= 0)
368                        gp->grid[i] = len[i]/d + (1.-FTINY);
447   }
448  
449  
450 < creatholo(gp)                   /* create a holodeck output file */
451 < HDGRID  *gp;
450 > static void
451 > creatholo(                      /* create a holodeck output file */
452 >        HDGRID  *gp
453 > )
454   {
455          extern char     VersionID[];
456 <        long    endloc = 0;
456 >        int32   lastloc, nextloc;
457 >        int     n;
458          int     fd;
459          FILE    *fp;
460                                          /* open & truncate file */
# Line 387 | Line 468 | HDGRID *gp;
468          printvars(fp);
469          fputformat(HOLOFMT, fp);
470          fputc('\n', fp);
471 <        putw(HOLOMAGIC, fp);            /* put magic number & terminus */
391 <        fwrite(&endloc, sizeof(long), 1, fp);
471 >        putw(HOLOMAGIC, fp);            /* put magic number */
472          fd = dup(fileno(fp));
473          fclose(fp);                     /* flush and close stdio stream */
474 <        hdinit(fd, gp);                 /* allocate and initialize index */
474 >        lastloc = lseek(fd, (off_t)0, SEEK_END);
475 >        for (n = vdef(SECTION); n--; gp++) {    /* initialize each section */
476 >                nextloc = 0L;
477 >                write(fd, (char *)&nextloc, sizeof(nextloc));
478 >                hdinit(fd, gp);                 /* writes beam index */
479 >                if (!n)
480 >                        break;
481 >                nextloc = hdfilen(fd);          /* write section pointer */
482 >                if (lseek(fd, (off_t)lastloc, SEEK_SET) < 0)
483 >                        error(SYSTEM,
484 >                                "cannot seek on holodeck file in creatholo");
485 >                write(fd, (char *)&nextloc, sizeof(nextloc));
486 >                lseek(fd, (off_t)(lastloc=nextloc), SEEK_SET);
487 >        }
488   }
489  
490  
491 < headline(s)                     /* process information header line */
492 < char    *s;
491 > static int
492 > headline(                       /* process information header line */
493 >        char    *s,
494 >        void    *p
495 > )
496   {
497          extern char     FMTSTR[];
498          register char   *cp;
# Line 408 | Line 504 | char   *s;
504                                          HOLOFMT, hdkfile, FMTSTR, fmt);
505                          error(USER, errmsg);
506                  }
507 <                return;
507 >                return(0);
508          }
509          for (cp = s; *cp; cp++)         /* take off any comments */
510                  if (*cp == '#') {
# Line 416 | Line 512 | char   *s;
512                          break;
513                  }
514          setvariable(s, matchvar);       /* don't flag errors */
515 +        return(0);
516   }
517  
518  
519 < loadholo()                      /* start loading a holodeck from fname */
519 > static void
520 > loadholo(void)                  /* start loading a holodeck from fname */
521   {
424        extern long     ftell();
522          FILE    *fp;
523          int     fd;
524 <        long    fpos;
525 <                                        /* open holodeck file */
526 <        if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
527 <                sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile,
528 <                                ncprocs>0 ? "appending" : "reading");
529 <                error(SYSTEM, errmsg);
524 >        int     n;
525 >        int32   nextloc;
526 >        
527 >        if ((ncprocs > 0) & (force >= 0))
528 >                fp = fopen(hdkfile, "r+");
529 >        else
530 >                fp = NULL;
531 >        if (fp == NULL) {
532 >                if ((fp = fopen(hdkfile, "r")) == NULL) {
533 >                        sprintf(errmsg, "cannot open \"%s\"", hdkfile);
534 >                        error(SYSTEM, errmsg);
535 >                }
536 >                if (ncprocs > 0) {
537 >                        sprintf(errmsg,
538 >                        "\"%s\" opened read-only; new rays will be discarded",
539 >                                        hdkfile);
540 >                        error(WARNING, errmsg);
541 >                        force = -1;
542 >                }
543          }
544                                          /* load variables from header */
545          getheader(fp, headline, NULL);
# Line 439 | Line 549 | loadholo()                     /* start loading a holodeck from fname */
549                                  hdkfile);
550                  error(USER, errmsg);
551          }
552 <        fread(&fpos, sizeof(long), 1, fp);
443 <        if (fpos != 0)
444 <                error(WARNING, "ignoring multiple sections in holodeck file");
445 <        fpos = ftell(fp);                       /* get stdio position */
552 >        nextloc = ftell(fp);                    /* get stdio position */
553          fd = dup(fileno(fp));
554          fclose(fp);                             /* done with stdio */
555 <        lseek(fd, fpos, 0);                     /* align system file pointer */
556 <        hdinit(fd, NULL);                       /* allocate and load index */
555 >        for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
556 >                lseek(fd, (off_t)nextloc, SEEK_SET);
557 >                read(fd, (char *)&nextloc, sizeof(nextloc));
558 >                hdinit(fd, NULL);
559 >        }
560 >        if (n != vdef(SECTION)) {
561 >                sprintf(errmsg, "number of sections does not match %s setting",
562 >                                vnam(SECTION));
563 >                error(WARNING, errmsg);
564 >        }
565   }
566  
567  
568 < done_packets(pl)                /* handle finished packets */
569 < PACKET  *pl;
568 > extern void
569 > done_packets(           /* handle finished packets */
570 >        PACKET  *pl
571 > )
572   {
573          static int      n2flush = 0;
574          register PACKET *p;
# Line 459 | Line 576 | PACKET *pl;
576          while (pl != NULL) {
577                  p = pl; pl = p->next; p->next = NULL;
578                  if (p->nr > 0) {                /* add to holodeck */
579 <                        bcopy((char *)p->ra,
580 <                                (char *)hdnewrays(hdlist[p->hd],p->bi,p->nr),
579 >                        memcpy( (void *)hdnewrays(hdlist[p->hd],p->bi,p->nr),
580 >                                (void *)p->ra,
581                                  p->nr*sizeof(RAYVAL));
582                          if (outdev != NULL)     /* display it */
583                                  disp_packet((PACKHEAD *)p);
584 <                        if (hdcachesize <= 0)   /* manual flushing */
585 <                                n2flush += p->nr;
584 >                        if (hdcachesize <= 0)
585 >                                n2flush++;
586                          nraysdone += p->nr;
587                          npacksdone++;
588 +                        p->nr = 0;
589                  }
590 <                p->nr = 0;                      /* push onto free list */
473 <                p->next = freepacks;
590 >                p->next = freepacks;            /* push onto free list */
591                  freepacks = p;
592          }
593 <        if (n2flush > 512*RPACKSIZ*nprocs) {
594 <                hdflush(NULL);                  /* flush holodeck buffers */
593 >        if (n2flush >= RTFLUSH) {
594 >                if (outdev != NULL)
595 >                        hdsync(NULL, 1);
596 >                else
597 >                        hdflush(NULL);
598                  n2flush = 0;
599          }
600   }
601  
602  
603 < rootname(rn, fn)                /* remove tail from end of fn */
604 < register char   *rn, *fn;
603 > static void
604 > rootname(               /* remove tail from end of fn */
605 >        register char   *rn,
606 >        register char   *fn
607 > )
608   {
609          char    *tp, *dp;
610  
611 <        for (tp = NULL, dp = rn; *rn = *fn++; rn++)
611 >        for (tp = NULL, dp = rn; (*rn = *fn++); rn++) {
612                  if (*rn == '/')
613                          dp = rn;
614                  else if (*rn == '.')
615                          tp = rn;
616 +        }
617          if (tp != NULL && tp > dp)
618                  *tp = '\0';
619   }
620  
621  
622 < badvalue(vc)                    /* report bad variable value and exit */
623 < int     vc;
622 > static void
623 > badvalue(                       /* report bad variable value and exit */
624 >        int     vc
625 > )
626   {
627          sprintf(errmsg, "bad value for variable '%s'", vnam(vc));
628          error(USER, errmsg);
629   }
630  
631  
632 + void
633   eputs(s)                        /* put error message to stderr */
634   register char  *s;
635   {
# Line 522 | Line 649 | register char  *s;
649   }
650  
651  
652 < wputs(s)                        /* put warning string to stderr */
526 < char    *s;
527 < {
528 <        if (!nowarn)
529 <                eputs(s);
530 < }
531 <
532 <
652 > void
653   quit(ec)                        /* exit program gracefully */
654   int     ec;
655   {
# Line 538 | Line 658 | int    ec;
658          if (hdlist[0] != NULL) {        /* close holodeck */
659                  if (nprocs > 0)
660                          status = done_rtrace();         /* calls hdsync() */
661 <                if (ncprocs > 0 && vdef(REPORT)) {
662 <                        long    fsiz, fuse;
661 >                if ((ncprocs > 0) & (force >= 0) && vdef(REPORT)) {
662 >                        off_t   fsiz, fuse;
663                          fsiz = hdfilen(hdlist[0]->fd);
664 <                        fuse = hdfiluse(hdlist[0]->fd, 1);
664 >                        fuse = hdfiluse(hdlist[0]->fd);
665                          fprintf(stderr,
666                          "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n",
667                                          hdkfile, fsiz/(1024.*1024.),

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines