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

Comparing ray/src/rt/devcomm.c (file contents):
Revision 1.7 by greg, Wed Nov 1 17:33:03 1989 UTC vs.
Revision 1.18 by greg, Thu May 3 13:17:41 1990 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10   *      10/5/88
11   */
12  
13 < #include <stdio.h>
13 > #include "standard.h"
14  
15 #include <signal.h>
16
15   #include "color.h"
16  
17   #include "driver.h"
# Line 22 | Line 20 | static char SCCSid[] = "$SunId$ LBL";
20   #define DEVPATH         getenv("PATH")  /* device search path */
21   #endif
22  
23 + #ifndef DELAY
24 + #define DELAY           20              /* seconds to wait for response */
25 + #endif
26 +
27   #ifndef BSD
28   #define vfork           fork
29   #endif
30  
29 #ifndef WFLUSH
30 #define WFLUSH          30              /* flush after this many rays */
31 #endif
32
31   extern char     *getpath(), *getenv();
32  
33 < int     onsigio();
33 > static int      comm_close(), comm_clear(), comm_paintr(), comm_errout(),
34 >                comm_getcur(), comm_comout(), comm_comin(), comm_flush();
35  
36 < int     comm_close(), comm_clear(), comm_paintr(), comm_errout(),
38 <                comm_getcur(), comm_comout(), comm_comin();
39 <
40 < struct driver   comm_driver, comm_default = {
36 > struct driver   comm_driver = {
37          comm_close, comm_clear, comm_paintr, comm_getcur,
38 <        comm_comout, comm_comin,
43 <        MAXRES, MAXRES, 0
38 >        comm_comout, comm_comin, comm_flush
39   };
40  
41   FILE    *devin, *devout;
# Line 81 | Line 76 | char   *dname, *id;
76                  goto syserr;
77          if ((devin = fdopen(p2[0], "r")) == NULL)
78                  goto syserr;
79 <        bcopy(&comm_default, &comm_driver, sizeof(comm_driver));
85 <                                                /* verify & get resolution */
79 >                                                /* verify initialization */
80          putw(COM_SENDM, devout);
81          fflush(devout);
82          if (getw(devin) != COM_RECVM)
83                  return(NULL);
84 <        comm_driver.xsiz = getw(devin);
85 <        comm_driver.ysiz = getw(devin);
92 <                                                /* input handling */
93 <        signal(SIGIO, onsigio);
84 >                                                /* get driver parameters */
85 >        getstate();
86                                                  /* set error vectors */
87          cmdvec = comm_comout;
88          if (wrnvec != NULL)
# Line 110 | Line 102 | comm_close()                   /* done with driver */
102          cmdvec = NULL;                          /* reset error vectors */
103          if (wrnvec != NULL)
104                  wrnvec = stderr_v;
113        signal(SIGIO, SIG_DFL);
105          fclose(devout);
106          fclose(devin);
107          while ((pid = wait(0)) != -1 && pid != devchild)
# Line 123 | Line 114 | comm_clear(xres, yres)                         /* clear screen */
114   int     xres, yres;
115   {
116          putc(COM_CLEAR, devout);
117 <        fwrite(&xres, sizeof(xres), 1, devout);
118 <        fwrite(&yres, sizeof(yres), 1, devout);
117 >        putw(xres, devout);
118 >        putw(yres, devout);
119          fflush(devout);
120   }
121  
# Line 134 | Line 125 | comm_paintr(col, xmin, ymin, xmax, ymax)       /* paint a re
125   COLOR   col;
126   int     xmin, ymin, xmax, ymax;
127   {
137        extern long     nrays;          /* number of rays traced */
138        static long     lastflush = 0;  /* ray count at last flush */
139
128          putc(COM_PAINTR, devout);
129 <        fwrite(col, sizeof(COLOR), 1, devout);
130 <        fwrite(&xmin, sizeof(xmin), 1, devout);
131 <        fwrite(&ymin, sizeof(ymin), 1, devout);
132 <        fwrite(&xmax, sizeof(xmax), 1, devout);
133 <        fwrite(&ymax, sizeof(ymax), 1, devout);
146 <        if (nrays - lastflush >= WFLUSH) {
147 <                fflush(devout);
148 <                lastflush = nrays;
149 <        }
129 >        fwrite((char *)col, sizeof(COLOR), 1, devout);
130 >        putw(xmin, devout);
131 >        putw(ymin, devout);
132 >        putw(xmax, devout);
133 >        putw(ymax, devout);
134   }
135  
136  
137 + static
138 + comm_flush()                            /* flush output to driver */
139 + {
140 +        putc(COM_FLUSH, devout);
141 +        fflush(devout);
142 +        if (getc(devin) != COM_FLUSH)
143 +                reply_error("flush");
144 +        getstate();
145 + }
146 +
147 +
148   static int
149   comm_getcur(xp, yp)                     /* get and return cursor position */
150   int     *xp, *yp;
# Line 161 | Line 156 | int    *xp, *yp;
156          if (getc(devin) != COM_GETCUR)
157                  reply_error("getcur");
158          c = getc(devin);
159 <        fread(xp, sizeof(*xp), 1, devin);
160 <        fread(yp, sizeof(*yp), 1, devin);
159 >        *xp = getw(devin);
160 >        *yp = getw(devin);
161          return(c);
162   }
163  
# Line 173 | Line 168 | char   *str;
168   {
169          putc(COM_COMOUT, devout);
170          myputs(str, devout);
171 <        fflush(devout);
171 >        if (str[strlen(str)-1] == '\n')
172 >                fflush(devout);
173   }
174  
175  
176   static
177 < comm_comin(buf)                         /* read string from command line */
177 > comm_comin(buf, prompt)                 /* read string from command line */
178   char    *buf;
179 + char    *prompt;
180   {
181          putc(COM_COMIN, devout);
182 +        if (prompt == NULL)
183 +                putc(0, devout);
184 +        else {
185 +                putc(1, devout);
186 +                myputs(prompt, devout);
187 +        }
188          fflush(devout);
189          if (getc(devin) != COM_COMIN)
190                  reply_error("comin");
191          mygets(buf, devin);
192 <        if (comm_driver.inpready > 0)
190 <                comm_driver.inpready--;
192 >        getstate();
193   }
194  
195  
# Line 236 | Line 238 | char   *routine;
238  
239  
240   static
241 < onsigio()                               /* input ready */
241 > getstate()                              /* get driver state variables */
242   {
243 <        comm_driver.inpready++;
243 >        fread((char *)&comm_driver.pixaspect,
244 >                        sizeof(comm_driver.pixaspect), 1, devin);
245 >        comm_driver.xsiz = getw(devin);
246 >        comm_driver.ysiz = getw(devin);
247 >        comm_driver.inpready = getw(devin);
248   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines