ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhdisp.c
Revision: 3.41
Committed: Mon Mar 8 17:31:49 1999 UTC (25 years, 1 month ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.40: +1 -2 lines
Log Message:
removed unnecessary inclusion of sys/types.h

File Contents

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