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