ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhdisp.c
Revision: 3.43
Committed: Sat Feb 22 02:07:24 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 3.42: +6 -6 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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