12 |
|
#include "rhdisp.h" |
13 |
|
#include "rhdriver.h" |
14 |
|
#include "selcall.h" |
15 |
+ |
#include <ctype.h> |
16 |
|
|
17 |
|
HOLO *hdlist[HDMAX+1]; /* global holodeck list */ |
18 |
|
|
19 |
+ |
char cmdlist[DC_NCMDS][8] = DC_INIT; |
20 |
+ |
|
21 |
|
int imm_mode = 0; /* bundles are being delivered immediately */ |
22 |
|
|
20 |
– |
VIEW dvw; /* our current display view */ |
21 |
– |
|
23 |
|
char *progname; /* global argv[0] */ |
24 |
|
|
25 |
< |
#define RDY_SRV 01 |
25 |
< |
#define RDY_DEV 02 |
25 |
> |
FILE *sstdin, *sstdout; /* server's standard input and output */ |
26 |
|
|
27 |
+ |
#define RDY_SRV 01 |
28 |
+ |
#define RDY_DEV 02 |
29 |
+ |
#define RDY_SIN 04 |
30 |
|
|
31 |
+ |
|
32 |
|
main(argc, argv) |
33 |
|
int argc; |
34 |
|
char *argv[]; |
35 |
|
{ |
36 |
+ |
extern int eputs(); |
37 |
|
int rdy, inp, res = 0, pause = 0; |
38 |
|
|
39 |
|
progname = argv[0]; |
40 |
< |
if (argc != 2) |
40 |
> |
if (argc < 3) |
41 |
|
error(USER, "bad command line arguments"); |
42 |
|
/* open our device */ |
43 |
|
dev_open(argv[1]); |
44 |
+ |
/* open server process i/o */ |
45 |
+ |
sstdout = fdopen(atoi(argv[2]), "w"); |
46 |
+ |
if (argc < 4 || (inp = atoi(argv[3])) < 0) |
47 |
+ |
sstdin = NULL; |
48 |
+ |
else |
49 |
+ |
sstdin = fdopen(inp, "r"); |
50 |
+ |
/* set command error vector */ |
51 |
+ |
erract[COMMAND].pf = eputs; |
52 |
|
/* enter main loop */ |
53 |
|
do { |
54 |
|
rdy = disp_wait(); |
55 |
< |
if (rdy & RDY_DEV) { /* get user input */ |
55 |
> |
if (rdy & RDY_DEV) { /* user input from driver */ |
56 |
|
inp = dev_input(); |
57 |
+ |
if (inp & DEV_PUTVIEW) |
58 |
+ |
printview(); |
59 |
|
if (inp & DEV_NEWVIEW) |
60 |
|
new_view(&odev.v); |
61 |
|
if (inp & DEV_SHUTDOWN) |
71 |
|
pause = 0; |
72 |
|
} |
73 |
|
} |
74 |
< |
if (rdy & RDY_SRV) { /* get server result */ |
74 |
> |
if (rdy & RDY_SIN) /* user input from sstdin */ |
75 |
> |
switch (usr_input()) { |
76 |
> |
case DC_PAUSE: |
77 |
> |
pause = 1; |
78 |
> |
break; |
79 |
> |
case DC_RESUME: |
80 |
> |
serv_request(DR_NOOP, 0, NULL); |
81 |
> |
pause = 0; |
82 |
> |
break; |
83 |
> |
} |
84 |
> |
if (rdy & RDY_SRV) { /* process server result */ |
85 |
|
res = serv_result(); |
86 |
|
if (pause && res != DS_SHUTDOWN) { |
87 |
|
serv_request(DR_ATTEN, 0, NULL); |
106 |
|
/* see if we can avoid select call */ |
107 |
|
if (imm_mode || stdin->_cnt > 0) |
108 |
|
return(RDY_SRV); |
109 |
+ |
if (sstdin != NULL && sstdin->_cnt > 0) |
110 |
+ |
return(RDY_SIN); |
111 |
|
if (dev_flush()) |
112 |
|
return(RDY_DEV); |
113 |
|
/* make the call */ |
116 |
|
FD_SET(0, &errset); |
117 |
|
FD_SET(odev.ifd, &readset); |
118 |
|
FD_SET(odev.ifd, &errset); |
119 |
< |
n = odev.ifd + 1; |
119 |
> |
n = odev.ifd+1; |
120 |
> |
if (sstdin != NULL) { |
121 |
> |
FD_SET(fileno(sstdin), &readset); |
122 |
> |
if (fileno(sstdin) >= n) |
123 |
> |
n = fileno(sstdin) + 1; |
124 |
> |
} |
125 |
|
n = select(n, &readset, NULL, &errset, NULL); |
126 |
|
if (n < 0) { |
127 |
|
if (errno == EINTR) |
133 |
|
flgs |= RDY_SRV; |
134 |
|
if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset)) |
135 |
|
flgs |= RDY_DEV; |
136 |
+ |
if (sstdin != NULL && FD_ISSET(fileno(sstdin), &readset)) |
137 |
+ |
flgs |= RDY_SIN; |
138 |
|
return(flgs); |
139 |
|
} |
140 |
|
|
184 |
|
hdray(ro, rd, hdlist[p->hd], gc, packra(p)[i].r); |
185 |
|
d = hddepth(hdlist[p->hd], packra(p)[i].d); |
186 |
|
VSUM(wp, ro, rd, d); /* might be behind viewpoint */ |
187 |
< |
dev_value(packra(p)[i].v, wp); |
187 |
> |
dev_value(packra(p)[i].v, wp, rd); |
188 |
|
} |
189 |
|
} |
190 |
|
|
194 |
|
{ |
195 |
|
char *err; |
196 |
|
|
197 |
< |
if ((err = setview(v)) != NULL) |
198 |
< |
error(INTERNAL, err); |
199 |
< |
dev_view(v); /* update display driver */ |
200 |
< |
beam_view(&dvw, v); /* update beam list */ |
201 |
< |
copystruct(&dvw, v); /* record new view */ |
197 |
> |
do { |
198 |
> |
if ((err = setview(v)) != NULL) { |
199 |
> |
error(COMMAND, err); |
200 |
> |
return; |
201 |
> |
} |
202 |
> |
if (v->type == VT_PAR) { |
203 |
> |
error(COMMAND, "cannot handle parallel views"); |
204 |
> |
return; |
205 |
> |
} |
206 |
> |
dev_view(v); /* update display driver */ |
207 |
> |
dev_flush(); /* update screen */ |
208 |
> |
} while (!beam_view(v)); /* update beam list */ |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
int |
213 |
+ |
usr_input() /* get user input and process it */ |
214 |
+ |
{ |
215 |
+ |
VIEW vparams; |
216 |
+ |
char cmd[128]; |
217 |
+ |
register char *args; |
218 |
+ |
register int i; |
219 |
+ |
|
220 |
+ |
if (fgets(cmd, sizeof(cmd), sstdin) == NULL) |
221 |
+ |
return(DC_QUIT); |
222 |
+ |
for (args = cmd; *args && !isspace(*args); args++) |
223 |
+ |
; |
224 |
+ |
while (isspace(*args)) |
225 |
+ |
*args++ = '\0'; |
226 |
+ |
if (!*cmd) |
227 |
+ |
return(DC_RESUME); |
228 |
+ |
if (*args && args[i=strlen(args)-1] == '\n') |
229 |
+ |
args[i] = '\0'; |
230 |
+ |
for (i = 0; i < DC_NCMDS; i++) |
231 |
+ |
if (!strcmp(cmd, cmdlist[i])) |
232 |
+ |
break; |
233 |
+ |
if (i >= DC_NCMDS) { |
234 |
+ |
sprintf(errmsg, "unknown command: %s", cmd); |
235 |
+ |
error(COMMAND, errmsg); |
236 |
+ |
return(-1); |
237 |
+ |
} |
238 |
+ |
switch (i) { |
239 |
+ |
case DC_SETVIEW: /* set the view */ |
240 |
+ |
copystruct(&vparams, &odev.v); |
241 |
+ |
if (!sscanview(&vparams, args)) |
242 |
+ |
error(COMMAND, "missing view options"); |
243 |
+ |
else |
244 |
+ |
new_view(&vparams); |
245 |
+ |
break; |
246 |
+ |
case DC_GETVIEW: /* print the current view */ |
247 |
+ |
printview(); |
248 |
+ |
break; |
249 |
+ |
case DC_PAUSE: /* pause the current calculation */ |
250 |
+ |
case DC_RESUME: /* resume the calculation */ |
251 |
+ |
/* handled in main() */ |
252 |
+ |
break; |
253 |
+ |
case DC_QUIT: /* quit request */ |
254 |
+ |
serv_request(DR_SHUTDOWN, 0, NULL); |
255 |
+ |
break; |
256 |
+ |
default: |
257 |
+ |
error(CONSISTENCY, "bad command id in usr_input"); |
258 |
+ |
} |
259 |
+ |
return(i); |
260 |
+ |
} |
261 |
+ |
|
262 |
+ |
|
263 |
+ |
printview() /* print our current view to server stdout */ |
264 |
+ |
{ |
265 |
+ |
fputs(VIEWSTR, sstdout); |
266 |
+ |
fprintview(&odev.v, sstdout); |
267 |
+ |
fputc('\n', sstdout); |
268 |
+ |
fflush(sstdout); |
269 |
+ |
} |
270 |
+ |
|
271 |
+ |
|
272 |
+ |
int |
273 |
|
serv_result() /* get next server result and process it */ |
274 |
|
{ |
275 |
|
static char *buf = NULL; |
306 |
|
case DS_STARTIMM: |
307 |
|
case DS_ENDIMM: |
308 |
|
imm_mode = msg.type==DS_STARTIMM; |
309 |
+ |
if (msg.type == DS_ENDIMM) |
310 |
+ |
dev_flush(); /* update display NOW */ |
311 |
|
/* fall through */ |
312 |
|
case DS_ACKNOW: |
313 |
|
case DS_SHUTDOWN: |