ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhdisp.c
Revision: 3.39
Committed: Sun Jan 3 17:49:11 1999 UTC (25 years, 3 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.38: +2 -2 lines
Log Message:
fixed debug reporting of rays recalled/second

File Contents

# User Rev Content
1 gregl 3.23 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2 gregl 3.1
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ SGI";
5     #endif
6    
7     /*
8     * Holodeck display process.
9     */
10    
11     #include "rholo.h"
12     #include "rhdisp.h"
13     #include "rhdriver.h"
14     #include "selcall.h"
15 gregl 3.10 #include <ctype.h>
16 gregl 3.1
17 gregl 3.12 #ifndef VIEWHISTLEN
18 gregl 3.16 #define VIEWHISTLEN 4 /* number of remembered views */
19 gregl 3.12 #endif
20    
21 gwlarson 3.36 #ifndef FSIZDEF
22     #define FSIZDEF 0.125 /* default focus frame size */
23     #endif
24    
25 gregl 3.1 HOLO *hdlist[HDMAX+1]; /* global holodeck list */
26    
27 gwlarson 3.38 char *hdgfn[HDMAX]; /* holodeck section geometry list */
28     char *hdpfn[HDMAX]; /* section portal list */
29 gwlarson 3.37
30 gregl 3.10 char cmdlist[DC_NCMDS][8] = DC_INIT;
31    
32 gregl 3.1 int imm_mode = 0; /* bundles are being delivered immediately */
33    
34 gregl 3.20 int do_outside = 0; /* render from outside sections */
35    
36 gwlarson 3.25 double eyesepdist = 1; /* eye separation distance */
37    
38 gregl 3.1 char *progname; /* global argv[0] */
39    
40 gregl 3.10 FILE *sstdin, *sstdout; /* server's standard input and output */
41 gregl 3.1
42 gregl 3.21 #ifdef DEBUG
43     #include <sys/types.h>
44     extern time_t time();
45     static time_t tmodesw;
46     static time_t timm, tadd;
47     static long nimmrays, naddrays;
48     #endif
49    
50 gregl 3.10 #define RDY_SRV 01
51     #define RDY_DEV 02
52     #define RDY_SIN 04
53 gregl 3.1
54 gregl 3.10
55 gregl 3.1 main(argc, argv)
56     int argc;
57     char *argv[];
58     {
59 gregl 3.10 extern int eputs();
60 gregl 3.3 int rdy, inp, res = 0, pause = 0;
61 gregl 3.1
62     progname = argv[0];
63 gregl 3.10 if (argc < 3)
64 gregl 3.1 error(USER, "bad command line arguments");
65     /* open our device */
66     dev_open(argv[1]);
67 gregl 3.10 /* open server process i/o */
68     sstdout = fdopen(atoi(argv[2]), "w");
69     if (argc < 4 || (inp = atoi(argv[3])) < 0)
70     sstdin = NULL;
71     else
72     sstdin = fdopen(inp, "r");
73     /* set command error vector */
74     erract[COMMAND].pf = eputs;
75 gregl 3.21 #ifdef DEBUG
76     tmodesw = time(NULL);
77     #endif
78 gregl 3.1 /* enter main loop */
79     do {
80     rdy = disp_wait();
81 gregl 3.19 if (rdy & RDY_SRV) { /* process server result */
82     res = serv_result();
83     if (pause && res != DS_SHUTDOWN) {
84     serv_request(DR_ATTEN, 0, NULL);
85     while ((res = serv_result()) != DS_ACKNOW &&
86     res != DS_SHUTDOWN)
87     ;
88     }
89     }
90 gregl 3.10 if (rdy & RDY_DEV) { /* user input from driver */
91 gregl 3.3 inp = dev_input();
92 gregl 3.13 if (inp & DFL(DC_SETVIEW))
93     new_view(&odev.v);
94 gwlarson 3.37 else if (inp & DFL(DC_LASTVIEW))
95     new_view(NULL);
96     if (inp & DFL(DC_REDRAW))
97     imm_mode = beam_sync(1) > 0;
98 gregl 3.13 if (inp & DFL(DC_GETVIEW))
99 gregl 3.10 printview();
100 gwlarson 3.36 if (inp & DFL(DC_FOCUS))
101     set_focus(odev_args);
102 gregl 3.15 if (inp & DFL(DC_KILL)) {
103 gregl 3.14 serv_request(DR_KILL, 0, NULL);
104 gregl 3.15 pause = 0;
105     }
106 gregl 3.14 if (inp & DFL(DC_CLOBBER))
107     serv_request(DR_CLOBBER, 0, NULL);
108 gregl 3.15 if (inp & DFL(DC_RESTART)) {
109 gregl 3.14 serv_request(DR_RESTART, 0, NULL);
110 gregl 3.15 pause = 0;
111     }
112 gwlarson 3.32 if (inp & DFL(DC_RESUME)) {
113     serv_request(DR_NOOP, 0, NULL);
114     pause = 0;
115     }
116     if (inp & DFL(DC_PAUSE))
117     pause = 1;
118 gregl 3.13 if (inp & DFL(DC_QUIT))
119     serv_request(DR_SHUTDOWN, 0, NULL);
120 gregl 3.3 }
121 gwlarson 3.34 if (rdy & RDY_SIN && !imm_mode) /* user input from sstdin */
122 gregl 3.10 switch (usr_input()) {
123     case DC_PAUSE:
124     pause = 1;
125     break;
126     case DC_RESUME:
127     serv_request(DR_NOOP, 0, NULL);
128 gregl 3.15 /* fall through */
129     case DC_KILL:
130     case DC_RESTART:
131 gregl 3.10 pause = 0;
132     break;
133     }
134 gregl 3.1 } while (res != DS_SHUTDOWN);
135 gregl 3.21 #ifdef DEBUG
136     if (timm && nimmrays)
137     fprintf(stderr,
138     "%s: %.1f rays recalled/second (%ld rays total)\n",
139     progname, (double)nimmrays/timm, nimmrays);
140     if (tadd && naddrays)
141     fprintf(stderr,
142     "%s: %.1f rays calculated/second (%ld rays total)\n",
143     progname, (double)naddrays/tadd, naddrays);
144     #endif
145 gregl 3.1 /* all done */
146     quit(0);
147     }
148    
149    
150     int
151     disp_wait() /* wait for more input */
152     {
153     fd_set readset, errset;
154     int flgs;
155     int n;
156     register int i;
157     /* see if we can avoid select call */
158 gwlarson 3.30 flgs = 0; /* flag what's ready already */
159 gregl 3.1 if (imm_mode || stdin->_cnt > 0)
160 gwlarson 3.30 flgs |= RDY_SRV;
161 gregl 3.10 if (sstdin != NULL && sstdin->_cnt > 0)
162 gwlarson 3.30 flgs |= RDY_SIN;
163     if (odev.inpready)
164     flgs |= RDY_DEV;
165     if (flgs) /* got something? */
166     return(flgs);
167     if (dev_flush()) /* else flush output & check keyboard+mouse */
168 gregl 3.4 return(RDY_DEV);
169 gwlarson 3.30 /* if nothing, we need to call select */
170 gregl 3.1 FD_ZERO(&readset); FD_ZERO(&errset);
171     FD_SET(0, &readset);
172     FD_SET(0, &errset);
173     FD_SET(odev.ifd, &readset);
174     FD_SET(odev.ifd, &errset);
175 gregl 3.10 n = odev.ifd+1;
176     if (sstdin != NULL) {
177     FD_SET(fileno(sstdin), &readset);
178 gregl 3.23 FD_SET(fileno(sstdin), &errset);
179 gregl 3.10 if (fileno(sstdin) >= n)
180     n = fileno(sstdin) + 1;
181     }
182 gregl 3.1 n = select(n, &readset, NULL, &errset, NULL);
183     if (n < 0) {
184     if (errno == EINTR)
185     return(0);
186     error(SYSTEM, "select call failure in disp_wait");
187     }
188     if (FD_ISSET(0, &readset) || FD_ISSET(0, &errset))
189 gregl 3.4 flgs |= RDY_SRV;
190 gregl 3.1 if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset))
191 gregl 3.4 flgs |= RDY_DEV;
192 gregl 3.23 if (sstdin != NULL && (FD_ISSET(fileno(sstdin), &readset) ||
193     FD_ISSET(fileno(sstdin), &errset)))
194 gregl 3.10 flgs |= RDY_SIN;
195 gregl 3.1 return(flgs);
196     }
197    
198    
199 gwlarson 3.38 add_holo(hdg, gfn, pfn) /* register a new holodeck section */
200 gregl 3.1 HDGRID *hdg;
201 gwlarson 3.38 char *gfn, *pfn;
202 gregl 3.1 {
203     VIEW nv;
204 gregl 3.20 double d;
205 gregl 3.1 register int hd;
206    
207     for (hd = 0; hd < HDMAX && hdlist[hd] != NULL; hd++)
208     ;
209     if (hd >= HDMAX)
210     error(INTERNAL, "too many holodeck sections in add_holo");
211     hdlist[hd] = (HOLO *)malloc(sizeof(HOLO));
212     if (hdlist[hd] == NULL)
213     error(SYSTEM, "out of memory in add_holo");
214     bcopy((char *)hdg, (char *)hdlist[hd], sizeof(HDGRID));
215     hdcompgrid(hdlist[hd]);
216 gwlarson 3.38 hdgfn[hd] = savestr(gfn);
217     hdpfn[hd] = pfn && *pfn ? savestr(pfn) : (char *)NULL;
218 gregl 3.1 if (hd)
219     return;
220     /* set initial viewpoint */
221     copystruct(&nv, &odev.v);
222     VSUM(nv.vp, hdlist[0]->orig, hdlist[0]->xv[0], 0.5);
223     VSUM(nv.vp, nv.vp, hdlist[0]->xv[1], 0.5);
224     VSUM(nv.vp, nv.vp, hdlist[0]->xv[2], 0.5);
225     fcross(nv.vdir, hdlist[0]->xv[1], hdlist[0]->xv[2]);
226     VCOPY(nv.vup, hdlist[0]->xv[2]);
227 gregl 3.20 if (do_outside) {
228     normalize(nv.vdir);
229     d = VLEN(hdlist[0]->xv[1]);
230     d += VLEN(hdlist[0]->xv[2]);
231     VSUM(nv.vp, nv.vp, nv.vdir, -d);
232     }
233 gregl 3.1 new_view(&nv);
234     }
235    
236    
237     disp_bundle(p) /* display a ray bundle */
238     register PACKHEAD *p;
239     {
240     GCOORD gc[2];
241     FVECT ro, rd, wp;
242     double d;
243     register int i;
244     /* get beam coordinates */
245     if (p->hd < 0 | p->hd >= HDMAX || hdlist[p->hd] == NULL)
246     error(INTERNAL, "bad holodeck number in disp_bundle");
247     if (!hdbcoord(gc, hdlist[p->hd], p->bi))
248     error(INTERNAL, "bad beam index in disp_bundle");
249     /* display each ray */
250     for (i = p->nr; i--; ) {
251     hdray(ro, rd, hdlist[p->hd], gc, packra(p)[i].r);
252     d = hddepth(hdlist[p->hd], packra(p)[i].d);
253 gwlarson 3.29 if (d < .99*FHUGE) {
254     VSUM(wp, ro, rd, d); /* might be behind viewpoint */
255     dev_value(packra(p)[i].v, rd, wp);
256     } else
257     dev_value(packra(p)[i].v, rd, NULL);
258 gregl 3.1 }
259 gregl 3.21 #ifdef DEBUG
260     if (imm_mode) nimmrays += p->nr;
261     else naddrays += p->nr;
262     #endif
263 gregl 3.1 }
264    
265    
266     new_view(v) /* change view parameters */
267 gregl 3.12 register VIEW *v;
268 gregl 3.1 {
269 gregl 3.12 static VIEW viewhist[VIEWHISTLEN];
270     static unsigned nhist;
271 gwlarson 3.24 VIEW *dv;
272 gwlarson 3.37 int i, res[2], *slist;
273 gregl 3.1 char *err;
274 gregl 3.12 /* restore previous view? */
275     if (v == NULL) {
276 gregl 3.16 if (nhist > 1) /* get one before last setting */
277     nhist--;
278     else /* else go to end of list */
279     while (nhist < VIEWHISTLEN && viewhist[nhist].type)
280     nhist++;
281 gregl 3.12 v = viewhist + ((nhist-1)%VIEWHISTLEN);
282 gregl 3.17 } else
283     again:
284     if ((err = setview(v)) != NULL) {
285 gregl 3.12 error(COMMAND, err);
286     return;
287     }
288 gwlarson 3.37 if (!dev_view(v)) /* notify display driver */
289     goto again;
290 gregl 3.12 if (v->type == VT_PAR) {
291     error(COMMAND, "cannot handle parallel views");
292     return;
293     }
294 gwlarson 3.37 beam_init(odev.firstuse); /* compute new beam set */
295     for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) {
296     if ((slist = beam_view(dv, res[0], res[1])) == NULL) {
297 gwlarson 3.24 if (!nhist) {
298     error(COMMAND, "invalid starting view");
299     return;
300     }
301     copystruct(v, viewhist + ((nhist-1)%VIEWHISTLEN));
302 gwlarson 3.37 goto again; /* poss. overloading dev_section()? */
303     }
304     DCHECK(*slist < 0, WARNING, "no visible sections in new_view");
305 gwlarson 3.38 for ( ; *slist >= 0; slist++)
306     dev_section(hdgfn[*slist], hdpfn[*slist]);
307 gwlarson 3.37 }
308 gwlarson 3.38 dev_section(NULL,NULL); /* end section list */
309 gwlarson 3.37 dev_flush(); /* update display */
310 gwlarson 3.34 /* update server */
311 gwlarson 3.37 imm_mode = beam_sync(odev.firstuse) > 0;
312 gregl 3.12 /* record new view */
313     if (v < viewhist || v >= viewhist+VIEWHISTLEN) {
314     copystruct(viewhist + (nhist%VIEWHISTLEN), v);
315     nhist++;
316     }
317 gregl 3.10 }
318    
319    
320 gwlarson 3.36 set_focus(args) /* set focus frame */
321     char *args;
322     {
323     double hcent, vcent, hsiz, vsiz;
324     VIEW *dv, vwfocus;
325     int i, res[2];
326    
327     i = sscanf(args, "%lf %lf %lf %lf", &hcent, &vcent, &hsiz, &vsiz);
328     if (i < 2 || hcent < 0 || hcent > 1 || vcent < 0 || vcent > 1) {
329     beam_init(0); /* restore view */
330     for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
331     beam_view(dv, res[0], res[1]);
332     beam_sync(0); /* update server */
333     return;
334     }
335     if (i < 4 || hsiz <= hcent || hsiz > 1 || vsiz <= vcent || vsiz > 1)
336     hsiz = vsiz = FSIZDEF; /* gave center only */
337     else {
338     hsiz -= hcent; hcent += 0.5*hsiz; /* gave min and max */
339     vsiz -= vcent; vcent += 0.5*vsiz;
340     }
341     beam_init(0); /* add basic views */
342     for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
343     beam_view(dv, res[0]>>4, res[1]>>4);
344     copystruct(&vwfocus, &odev.v); /* add focus view */
345     switch (odev.v.type) {
346     case VT_PER:
347     vwfocus.horiz = 2.*180./PI*atan(
348     hsiz * tan(PI/180./2.*odev.v.horiz) );
349     vwfocus.vert = 2.*180./PI*atan(
350     vsiz * tan(PI/180./2.*odev.v.vert) );
351     break;
352     case VT_PAR:
353     case VT_ANG:
354     vwfocus.horiz = hsiz * odev.v.horiz;
355     vwfocus.vert = vsiz * odev.v.vert;
356     break;
357     case VT_HEM:
358     vwfocus.horiz = 2.*180./PI*asin(
359     hsiz * sin(PI/180./2.*odev.v.horiz) );
360     vwfocus.vert = 2.*180./PI*asin(
361     vsiz * sin(PI/180./2.*odev.v.vert) );
362     break;
363     case VT_CYL:
364     vwfocus.horiz = hsiz * odev.v.horiz;
365     vwfocus.vert = 2.*180./PI*atan(
366     vsiz * tan(PI/180./2.*odev.v.vert) );
367     break;
368     default:
369     error(INTERNAL, "bad view type in set_focus");
370     }
371     vwfocus.hoff = (odev.v.hoff + hcent - 0.5)/hsiz;
372     vwfocus.voff = (odev.v.voff + vcent - 0.5)/vsiz;
373     setview(&vwfocus);
374     beam_view(&vwfocus, (int)(3*odev.hres*hsiz)+100,
375     (int)(3*odev.vres*vsiz)+100);
376     beam_sync(0); /* update server */
377     }
378    
379    
380 gregl 3.10 int
381     usr_input() /* get user input and process it */
382     {
383     VIEW vparams;
384 gregl 3.23 char cmd[256];
385 gregl 3.10 register char *args;
386 gregl 3.11 register int i;
387 gregl 3.10
388 gregl 3.23 if (fgets(cmd, sizeof(cmd), sstdin) == NULL) {
389     fclose(sstdin);
390     sstdin = NULL;
391 gwlarson 3.26 return(-1);
392 gregl 3.23 }
393 gwlarson 3.31 if (*cmd == '\n')
394 gwlarson 3.26 return(DC_RESUME);
395 gregl 3.10 for (args = cmd; *args && !isspace(*args); args++)
396     ;
397     while (isspace(*args))
398     *args++ = '\0';
399 gregl 3.11 if (*args && args[i=strlen(args)-1] == '\n')
400     args[i] = '\0';
401     for (i = 0; i < DC_NCMDS; i++)
402     if (!strcmp(cmd, cmdlist[i]))
403 gregl 3.10 break;
404 gregl 3.11 if (i >= DC_NCMDS) {
405 gwlarson 3.26 dev_auxcom(cmd, args);
406 gregl 3.10 return(-1);
407     }
408 gregl 3.11 switch (i) {
409 gregl 3.10 case DC_SETVIEW: /* set the view */
410     copystruct(&vparams, &odev.v);
411     if (!sscanview(&vparams, args))
412     error(COMMAND, "missing view options");
413     else
414     new_view(&vparams);
415     break;
416     case DC_GETVIEW: /* print the current view */
417     printview();
418 gregl 3.12 break;
419     case DC_LASTVIEW: /* restore previous view */
420     new_view(NULL);
421 gwlarson 3.36 break;
422     case DC_FOCUS: /* set focus frame */
423     set_focus(args);
424 gregl 3.10 break;
425     case DC_PAUSE: /* pause the current calculation */
426     case DC_RESUME: /* resume the calculation */
427     /* handled in main() */
428 gregl 3.13 break;
429     case DC_REDRAW: /* redraw from server */
430 gwlarson 3.24 imm_mode = beam_sync(1) > 0;
431 gregl 3.22 dev_clear();
432 gregl 3.14 break;
433     case DC_KILL: /* kill rtrace process(es) */
434     serv_request(DR_KILL, 0, NULL);
435     break;
436     case DC_CLOBBER: /* clobber holodeck */
437     serv_request(DR_CLOBBER, 0, NULL);
438     break;
439     case DC_RESTART: /* restart rtrace */
440     serv_request(DR_RESTART, 0, NULL);
441 gregl 3.10 break;
442     case DC_QUIT: /* quit request */
443     serv_request(DR_SHUTDOWN, 0, NULL);
444     break;
445     default:
446     error(CONSISTENCY, "bad command id in usr_input");
447     }
448 gregl 3.11 return(i);
449 gregl 3.10 }
450    
451    
452     printview() /* print our current view to server stdout */
453     {
454     fputs(VIEWSTR, sstdout);
455     fprintview(&odev.v, sstdout);
456     fputc('\n', sstdout);
457     fflush(sstdout);
458 gregl 3.1 }
459    
460    
461     int
462     serv_result() /* get next server result and process it */
463     {
464     static char *buf = NULL;
465     static int bufsiz = 0;
466     MSGHEAD msg;
467     int n;
468     /* read message header */
469     if (fread((char *)&msg, sizeof(MSGHEAD), 1, stdin) != 1)
470     goto readerr;
471     if (msg.nbytes > 0) { /* get the message body */
472     if (msg.nbytes > bufsiz) {
473     if (buf == NULL)
474     buf = (char *)malloc(bufsiz=msg.nbytes);
475     else
476     buf = (char *)realloc(buf, bufsiz=msg.nbytes);
477     if (buf == NULL)
478     error(SYSTEM, "out of memory in serv_result");
479     }
480     if (fread(buf, 1, msg.nbytes, stdin) != msg.nbytes)
481     goto readerr;
482     }
483     switch (msg.type) { /* process results */
484     case DS_BUNDLE:
485     if (msg.nbytes < sizeof(PACKHEAD) ||
486     msg.nbytes != packsiz(((PACKHEAD *)buf)->nr))
487     error(INTERNAL, "bad display packet from server");
488     disp_bundle((PACKHEAD *)buf);
489     break;
490     case DS_ADDHOLO:
491 gwlarson 3.38 if (msg.nbytes < sizeof(HDGRID)+2)
492 gregl 3.1 error(INTERNAL, "bad holodeck record from server");
493 gwlarson 3.38 add_holo((HDGRID *)buf, buf+sizeof(HDGRID),
494     buf+sizeof(HDGRID)+strlen(buf+sizeof(HDGRID))+1);
495 gregl 3.20 break;
496     case DS_OUTSECT:
497     do_outside = 1;
498 gwlarson 3.28 goto noargs;
499 gwlarson 3.25 case DS_EYESEP:
500     if (msg.nbytes <= 1 || (eyesepdist = atof(buf)) <= FTINY)
501     error(INTERNAL, "bad eye separation from server");
502 gregl 3.1 break;
503     case DS_STARTIMM:
504     case DS_ENDIMM:
505 gwlarson 3.39 if (!(imm_mode = msg.type==DS_STARTIMM))
506     dev_flush();
507 gregl 3.21 #ifdef DEBUG
508 gwlarson 3.35 {
509 gregl 3.21 time_t tnow = time(NULL);
510 gwlarson 3.35 if (msg.type==DS_STARTIMM) tadd += tnow - tmodesw;
511     else timm += tnow - tmodesw;
512 gregl 3.21 tmodesw = tnow;
513     }
514     #endif
515 gwlarson 3.28 goto noargs;
516 gregl 3.1 case DS_ACKNOW:
517     case DS_SHUTDOWN:
518 gwlarson 3.28 goto noargs;
519 gregl 3.1 default:
520     error(INTERNAL, "unrecognized result from server process");
521     }
522     return(msg.type); /* return message type */
523 gwlarson 3.28 noargs:
524     if (msg.nbytes) {
525     sprintf(errmsg, "unexpected body with server message %d",
526     msg.type);
527     error(INTERNAL, errmsg);
528     }
529     return(msg.type);
530 gregl 3.1 readerr:
531     if (feof(stdin))
532     error(SYSTEM, "server process died");
533     error(SYSTEM, "error reading from server process");
534     }
535    
536    
537     serv_request(type, nbytes, p) /* send a request to the server process */
538     int type, nbytes;
539     char *p;
540     {
541     MSGHEAD msg;
542     int m;
543 gwlarson 3.33 /* consistency checks */
544 gwlarson 3.37 DCHECK(nbytes < 0 || nbytes > 0 & p == NULL,
545     CONSISTENCY, "bad buffer handed to serv_request");
546 gregl 3.1 /* get server's attention for big request */
547     if (nbytes >= BIGREQSIZ-sizeof(MSGHEAD)) {
548     serv_request(DR_ATTEN, 0, NULL);
549     while ((m = serv_result()) != DS_ACKNOW)
550     if (m == DS_SHUTDOWN) /* the bugger quit on us */
551     quit(0);
552     }
553     msg.type = type; /* write and flush the message */
554     msg.nbytes = nbytes;
555     fwrite((char *)&msg, sizeof(MSGHEAD), 1, stdout);
556     if (nbytes > 0)
557     fwrite(p, 1, nbytes, stdout);
558     if (fflush(stdout) < 0)
559     error(SYSTEM, "write error in serv_request");
560 gregl 3.2 }
561    
562    
563     eputs(s) /* put error message to stderr */
564     register char *s;
565     {
566     static int midline = 0;
567    
568     if (!*s)
569     return;
570     if (!midline++) { /* prepend line with program name */
571     fputs(progname, stderr);
572     fputs(": ", stderr);
573     }
574     fputs(s, stderr);
575     if (s[strlen(s)-1] == '\n') {
576     fflush(stderr);
577     midline = 0;
578     }
579 gregl 3.1 }
580    
581    
582     quit(code) /* clean up and exit */
583     int code;
584     {
585 gwlarson 3.38 if (code)
586     exit(code);
587 gregl 3.1 if (odev.v.type)
588     dev_close();
589 gwlarson 3.38 exit(0);
590 gregl 3.1 }