ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhdisp.c
(Generate patch)

Comparing ray/src/hd/rhdisp.c (file contents):
Revision 3.9 by gregl, Thu Dec 4 10:54:24 1997 UTC vs.
Revision 3.10 by gregl, Mon Dec 8 18:51:15 1997 UTC

# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ SGI";
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  
23   char    *progname;              /* global argv[0] */
24  
25 < #define RDY_SRV 01
23 < #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)
# Line 54 | Line 71 | char   *argv[];
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);
# Line 79 | Line 106 | disp_wait()                    /* wait for more input */
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 */
# Line 87 | Line 116 | disp_wait()                    /* wait for more input */
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)
# Line 99 | Line 133 | disp_wait()                    /* wait for more input */
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  
# Line 159 | Line 195 | VIEW   *v;
195          char    *err;
196  
197          do {
198 <                if ((err = setview(v)) != NULL)
199 <                        error(INTERNAL, err);
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    cmdno;
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 +        for (cmdno = 0; cmdno < DC_NCMDS; cmdno++)
229 +                if (!strcmp(cmd, cmdlist[cmdno]))
230 +                        break;
231 +        if (cmdno >= DC_NCMDS) {
232 +                sprintf(errmsg, "unknown command: %s", cmd);
233 +                error(COMMAND, errmsg);
234 +                return(-1);
235 +        }
236 +        switch (cmdno) {
237 +        case DC_SETVIEW:                /* set the view */
238 +                copystruct(&vparams, &odev.v);
239 +                if (!sscanview(&vparams, args))
240 +                        error(COMMAND, "missing view options");
241 +                else
242 +                        new_view(&vparams);
243 +                break;
244 +        case DC_GETVIEW:                /* print the current view */
245 +                printview();
246 +                break;
247 +        case DC_PAUSE:                  /* pause the current calculation */
248 +        case DC_RESUME:                 /* resume the calculation */
249 +                /* handled in main() */
250 +                break;
251 +        case DC_QUIT:                   /* quit request */
252 +                serv_request(DR_SHUTDOWN, 0, NULL);
253 +                break;
254 +        default:
255 +                error(CONSISTENCY, "bad command id in usr_input");
256 +        }
257 +        return(cmdno);
258 +                
259 + }
260 +
261 +
262 + printview()                     /* print our current view to server stdout */
263 + {
264 +        fputs(VIEWSTR, sstdout);
265 +        fprintview(&odev.v, sstdout);
266 +        fputc('\n', sstdout);
267 +        fflush(sstdout);
268   }
269  
270  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines