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

Comparing ray/src/rt/devmain.c (file contents):
Revision 1.3 by greg, Wed Nov 1 16:12:22 1989 UTC vs.
Revision 1.10 by greg, Tue Mar 6 17:44:44 1990 UTC

# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include <stdio.h>
16  
17 #include <signal.h>
18
17   #include "color.h"
18  
19   #include "driver.h"
20  
21   int     (*wrnvec)(), (*errvec)(), (*cmdvec)();  /* error vectors, unused */
22  
25 long    nrays = 0;                              /* fake it */
26
23   struct driver   *dev = NULL;                    /* output device */
24  
25   FILE    *devin, *devout;                        /* communications channels */
26  
31 int     notified = 0;                           /* notified parent of input? */
32
27   char    *progname;                              /* driver name */
28  
29 < int     r_clear(), r_paintr(), r_getcur(), r_comout(), r_comin(), r_mycomin();
29 > int     r_clear(), r_paintr(), r_getcur(), r_comout(), r_comin(), r_flush();
30  
31   int     (*dev_func[NREQUESTS])() = {            /* request handlers */
32                  r_clear, r_paintr,
33 <                r_getcur, r_comout, r_comin
33 >                r_getcur, r_comout,
34 >                r_comin, r_flush
35          };
36  
42 char    mybuf[512] = "";
37  
44 char    *mybufp();
45
46
38   main(argc, argv)                /* set up communications and main loop */
39   int     argc;
40   char    *argv[];
# Line 66 | Line 57 | char   *argv[];
57          if ((dev = dinit(argv[0], argv[3])) == NULL)
58                  quit(1);
59          putw(COM_RECVM, devout);                /* verify initialization */
69        putw(dev->xsiz, devout);
70        putw(dev->ysiz, devout);
60          fflush(devout);
61                                                  /* loop on requests */
62          while ((com = getc(devin)) != EOF) {
# Line 105 | Line 94 | r_paintr()                             /* paint a rectangle */
94          COLOR   col;
95          int     xmin, ymin, xmax, ymax;
96  
97 <        nrays += 5;                     /* pretend */
109 <        fread(col, sizeof(COLOR), 1, devin);
97 >        fread((char *)col, sizeof(COLOR), 1, devin);
98          xmin = getw(devin); ymin = getw(devin);
99          xmax = getw(devin); ymax = getw(devin);
100          (*dev->paintr)(col, xmin, ymin, xmax, ymax);
113                                        /* check for input */
114        if (!notified && dev->inpready > 0) {
115                notified = 1;
116                kill(getppid(), SIGIO);
117        }
101   }
102  
103  
104 + r_flush()                               /* flush output */
105 + {
106 +        if (dev->flush != NULL)
107 +                (*dev->flush)();
108 +        putc(COM_FLUSH, devout);
109 +        fwrite((char *)&dev->pixaspect, sizeof(dev->pixaspect), 1, devout);
110 +        putw(dev->xsiz, devout);
111 +        putw(dev->ysiz, devout);
112 +        putw(dev->inpready, devout);
113 +        fflush(devout);
114 + }
115 +
116 +
117   r_getcur()                              /* get and return cursor position */
118   {
119          int     c;
# Line 148 | Line 144 | r_comout()                             /* print string to command line */
144  
145   r_comin()                               /* read string from command line */
146   {
147 <        char    buf[256];
147 >        char    buf[256], *prompt;
148 >                                        /* get prompt */
149 >        if (getc(devin)) {
150 >                mygets(buf, devin);
151 >                prompt = buf;
152 >        } else
153 >                prompt = NULL;
154                                          /* get string */
155 <        (*dev->comin)(buf);
155 >        (*dev->comin)(buf, prompt);
156                                          /* reply */
157          putc(COM_COMIN, devout);
158          myputs(buf, devout);
159 +        putw(dev->inpready, devout);
160          fflush(devout);
158                                        /* reset notify */
159        notified = 0;
161   }
162  
163  
# Line 183 | Line 184 | register FILE  *fp;
184   }
185  
186  
186 r_mycomin()                             /* get command from my buffer */
187 {
188        register char   *cp;
189                                                /* get next command */
190        for (cp = mybuf; *cp != '\n'; cp++)
191                ;
192        *cp++ = '\0';
193        (*dev->comout)(mybuf);                  /* echo my command */
194                                                /* send it as reply */
195        putc(COM_COMIN, devout);
196        myputs(mybuf, devout);
197        fflush(devout);
198                                                /* get next command */
199        (*dev->comout)("\n");
200        strcpy(mybuf, cp);
201        if (mybuf[0])
202                kill(getppid(), SIGIO);                 /* signal more */
203        else
204                dev_func[COM_COMIN] = r_comin;          /* else reset */
205 }
206
207
187   stderr_v(s)                             /* put string to stderr */
188   register char  *s;
189   {
# Line 219 | Line 198 | register char  *s;
198                  fflush(stderr);
199                  inline = 0;
200          }
222 }
223
224
225 char *
226 mybufp()                                /* return buffer for my command */
227 {
228        if (dev_func[COM_COMIN] != r_mycomin) {
229                dev_func[COM_COMIN] = r_mycomin;
230                kill(getppid(), SIGIO);
231        }
232        return(mybuf+strlen(mybuf));
233 }
234
235
236 repaint(xmin, ymin, xmax, ymax)         /* repaint section of display */
237 int     xmin, ymin, xmax, ymax;
238 {
239        sprintf(mybufp(), "repaint %d %d %d %d\n",
240                        xmin, ymin, xmax, ymax);
201   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines