--- ray/src/hd/rholo4.c 1999/08/05 13:51:21 3.27 +++ ray/src/hd/rholo4.c 2020/02/28 05:18:49 3.39 @@ -1,16 +1,15 @@ -/* Copyright (c) 1999 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rholo4.c,v 3.39 2020/02/28 05:18:49 greg Exp $"; #endif - /* * Holodeck display process communication */ #include "rholo.h" #include "rhdisp.h" +#include "rtprocess.h" #include +#include #ifndef HDSUF #define HDSUF ".hdi" @@ -24,20 +23,25 @@ static char SCCSid[] = "$SunId$ SGI"; #endif static int inp_flags; -static int dpd[3]; +static SUBPROC dpd = SP_INACTIVE; static FILE *dpout; +static void disp_flush(void); +static void disp_result(int type, int nbytes, char *p); -disp_open(dname) /* open the named display driver */ -char *dname; + +void +disp_open( /* open the named display driver */ + char *dname +) { char buf[sizeof(HDGRID)+512], fd0[8], fd1[8], *cmd[5], *sfn; int i, n, len; if (!strcmp(dname, SLAVENAME)) { - dpd[0] = 0; /* read from stdin */ + dpd.r = 0; /* read from stdin */ dpout = stdout; /* write to stdout */ - dpd[2] = -1; /* we're the slave process */ + dpd.flags = 0; /* we're the slave procees */ } else { /* get full display program name */ #ifdef DEVPATH @@ -55,17 +59,17 @@ char *dname; cmd[0] = buf; cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0; cmd[4] = NULL; - i = open_process(dpd, cmd); + i = open_process(&dpd, cmd); if (i <= 0) error(USER, "cannot start display process"); - if ((dpout = fdopen(dpd[1], "w")) == NULL) + if ((dpout = fdopen(dpd.w, "w")) == NULL) error(SYSTEM, "problem opening display pipe"); /* close dup'ed stdin and stdout */ if (readinp) close(atoi(fd0)); close(atoi(fd1)); } - dpd[1] = -1; /* causes ignored error in close_process() */ + dpd.w = -1; /* causes ignored error in close_process() */ inp_flags = 0; /* check if outside */ if (vdef(OBSTRUCTIONS) && vbool(OBSTRUCTIONS)) @@ -77,7 +81,7 @@ char *dname; } /* write out hologram grids & octrees */ for (i = 0; hdlist[i] != NULL; i++) { - bcopy((char *)hdlist[i], buf, sizeof(HDGRID)); + memcpy(buf, (void *)hdlist[i], sizeof(HDGRID)); len = sizeof(HDGRID); n = vdef(GEOMETRY); sfn = inr), (char *)p); } -disp_check(block) /* check display process */ -int block; +int +disp_check( /* check display process */ + int block +) { MSGHEAD msg; int n; @@ -115,17 +123,17 @@ int block; /* check read blocking */ if (block != (inp_flags == 0)) { inp_flags = block ? 0 : FNONBLK; - if (fcntl(dpd[0], F_SETFL, inp_flags) < 0) + if (fcntl(dpd.r, F_SETFL, inp_flags) < 0) goto fcntlerr; } /* read message header */ - n = read(dpd[0], (char *)&msg, sizeof(MSGHEAD)); + n = read(dpd.r, (char *)&msg, sizeof(MSGHEAD)); if (n != sizeof(MSGHEAD)) { if (n >= 0) { dpout = NULL; error(USER, "display process died"); } - if (errno != EAGAIN & errno != EINTR) + if ((errno != EAGAIN) & (errno != EINTR)) goto readerr; return(2); /* acceptable failure */ } @@ -135,9 +143,9 @@ int block; buf = (char *)malloc(msg.nbytes); if (buf == NULL) error(SYSTEM, "out of memory in disp_check"); - if (inp_flags != 0 && fcntl(dpd[0], F_SETFL, inp_flags=0) < 0) + if (inp_flags != 0 && fcntl(dpd.r, F_SETFL, inp_flags=0) < 0) goto fcntlerr; - if (readbuf(dpd[0], buf, msg.nbytes) != msg.nbytes) + if (readbuf(dpd.r, buf, msg.nbytes) != msg.nbytes) goto readerr; } switch (msg.type) { /* take appropriate action */ @@ -187,7 +195,7 @@ int block; case DR_VIEWPOINT: /* set target eye position */ if (msg.nbytes != sizeof(VIEWPOINT)) error(INTERNAL, "bad DR_VIEWPOINT from display process"); - copystruct(&myeye, (VIEWPOINT *)buf); + myeye = *((VIEWPOINT *)buf); break; case DR_ATTEN: /* block for priority request */ if (msg.nbytes) @@ -216,7 +224,7 @@ int block; case DR_CLOBBER: /* clobber holodeck */ if (msg.nbytes) error(INTERNAL, "bad DR_CLOBBER from display process"); - if (force <= 0 | ncprocs <= 0) + if ((force <= 0) | (ncprocs <= 0)) error(WARNING, "request to clobber holodeck denied"); else { error(WARNING, "clobbering holodeck contents"); @@ -239,27 +247,30 @@ fcntlerr: error(SYSTEM, "cannot change display blocking mode"); readerr: error(SYSTEM, "error reading from display process"); + return -1; /* pro forma return */ } int -disp_close() /* close our display process */ +disp_close(void) /* close our display process */ { - int rval; - if (dpout == NULL) return(-1); myeye.rng = 0; disp_result(DS_SHUTDOWN, 0, NULL); fclose(dpout); dpout = NULL; - return(dpd[2]<0 ? 0 : close_process(dpd)); + return(dpd.flags&PF_RUNNING ? close_process(&dpd) : 0); + } -disp_result(type, nbytes, p) /* queue result message to display process */ -int type, nbytes; -char *p; +static void +disp_result( /* queue result message to display process */ + int type, + int nbytes, + char *p +) { MSGHEAD msg; /* consistency checks */ @@ -271,13 +282,14 @@ char *p; return; msg.type = type; msg.nbytes = nbytes; - fwrite((char *)&msg, sizeof(MSGHEAD), 1, dpout); + putbinary(&msg, sizeof(MSGHEAD), 1, dpout); if (nbytes > 0) - fwrite(p, 1, nbytes, dpout); + putbinary(p, 1, nbytes, dpout); } -disp_flush() /* flush output to display */ +static void +disp_flush(void) /* flush output to display */ { if (fflush(dpout) < 0) error(SYSTEM, "error writing to the display process");