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.8 by greg, Mon Jan 8 13:37:54 1990 UTC vs.
Revision 2.2 by greg, Thu Mar 19 09:34:02 1992 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"
18  
19 + #include "vfork.h"
20 +
21   #ifndef DEVPATH
22   #define DEVPATH         getenv("PATH")  /* device search path */
23   #endif
24  
25 < #ifndef BSD
26 < #define vfork           fork
25 > #ifndef DELAY
26 > #define DELAY           20              /* seconds to wait for response */
27   #endif
28  
29 < #ifndef WFLUSH
30 < #define WFLUSH          30              /* flush after this many rays */
31 < #endif
29 > static int      comm_close(), comm_clear(), comm_paintr(), comm_errout(),
30 >                comm_getcur(), comm_comout(), comm_comin(), comm_flush();
31  
32 < extern char     *getpath(), *getenv();
34 <
35 < int     onsigio();
36 <
37 < int     comm_close(), comm_clear(), comm_paintr(), comm_errout(),
38 <                comm_getcur(), comm_comout(), comm_comin();
39 <
40 < struct driver   comm_driver, comm_default = {
32 > struct driver   comm_driver = {
33          comm_close, comm_clear, comm_paintr, comm_getcur,
34 <        comm_comout, comm_comin
34 >        comm_comout, comm_comin, comm_flush
35   };
36  
37   FILE    *devin, *devout;
# Line 55 | Line 47 | char   *dname, *id;
47          int     p1[2], p2[2];
48          char    pin[16], pout[16];
49                                                  /* find driver program */
50 <        if ((devname = getpath(dname, DEVPATH, 1)) == NULL) {
50 >        if ((devname = getpath(dname, DEVPATH, X_OK)) == NULL) {
51                  stderr_v(dname);
52                  stderr_v(": not found\n");
53                  return(NULL);
# Line 80 | Line 72 | char   *dname, *id;
72                  goto syserr;
73          if ((devin = fdopen(p2[0], "r")) == NULL)
74                  goto syserr;
75 <        bcopy(&comm_default, &comm_driver, sizeof(comm_driver));
84 <                                                /* verify & get resolution */
75 >                                                /* verify initialization */
76          putw(COM_SENDM, devout);
77          fflush(devout);
78          if (getw(devin) != COM_RECVM)
79                  return(NULL);
80 <        comm_driver.xsiz = getw(devin);
81 <        comm_driver.ysiz = getw(devin);
91 <        fread(comm_driver.pixaspect, sizeof(comm_driver.pixaspect), 1, devin);
92 <                                                /* input handling */
93 <        signal(SIGIO, onsigio);
80 >                                                /* get driver parameters */
81 >        getstate();
82                                                  /* set error vectors */
83          cmdvec = comm_comout;
84          if (wrnvec != NULL)
# Line 110 | Line 98 | comm_close()                   /* done with driver */
98          cmdvec = NULL;                          /* reset error vectors */
99          if (wrnvec != NULL)
100                  wrnvec = stderr_v;
113        signal(SIGIO, SIG_DFL);
101          fclose(devout);
102          fclose(devin);
103          while ((pid = wait(0)) != -1 && pid != devchild)
# Line 134 | Line 121 | comm_paintr(col, xmin, ymin, xmax, ymax)       /* paint a re
121   COLOR   col;
122   int     xmin, ymin, xmax, ymax;
123   {
137        extern long     nrays;          /* number of rays traced */
138        static long     lastflush = 0;  /* ray count at last flush */
139
124          putc(COM_PAINTR, devout);
125 <        fwrite(col, sizeof(COLOR), 1, devout);
125 >        fwrite((char *)col, sizeof(COLOR), 1, devout);
126          putw(xmin, devout);
127          putw(ymin, devout);
128          putw(xmax, devout);
129          putw(ymax, devout);
146        if (nrays - lastflush >= WFLUSH) {
147                fflush(devout);
148                lastflush = nrays;
149        }
130   }
131  
132  
133 + static
134 + comm_flush()                            /* flush output to driver */
135 + {
136 +        putc(COM_FLUSH, devout);
137 +        fflush(devout);
138 +        if (getc(devin) != COM_FLUSH)
139 +                reply_error("flush");
140 +        getstate();
141 + }
142 +
143 +
144   static int
145   comm_getcur(xp, yp)                     /* get and return cursor position */
146   int     *xp, *yp;
# Line 173 | Line 164 | char   *str;
164   {
165          putc(COM_COMOUT, devout);
166          myputs(str, devout);
167 <        fflush(devout);
167 >        if (str[strlen(str)-1] == '\n')
168 >                fflush(devout);
169   }
170  
171  
172   static
173 < comm_comin(buf)                         /* read string from command line */
173 > comm_comin(buf, prompt)                 /* read string from command line */
174   char    *buf;
175 + char    *prompt;
176   {
177          putc(COM_COMIN, devout);
178 +        if (prompt == NULL)
179 +                putc(0, devout);
180 +        else {
181 +                putc(1, devout);
182 +                myputs(prompt, devout);
183 +        }
184          fflush(devout);
185          if (getc(devin) != COM_COMIN)
186                  reply_error("comin");
187          mygets(buf, devin);
188 <        if (comm_driver.inpready > 0)
190 <                comm_driver.inpready--;
188 >        getstate();
189   }
190  
191  
# Line 236 | Line 234 | char   *routine;
234  
235  
236   static
237 < onsigio()                               /* input ready */
237 > getstate()                              /* get driver state variables */
238   {
239 <        comm_driver.inpready++;
239 >        fread((char *)&comm_driver.pixaspect,
240 >                        sizeof(comm_driver.pixaspect), 1, devin);
241 >        comm_driver.xsiz = getw(devin);
242 >        comm_driver.ysiz = getw(devin);
243 >        comm_driver.inpready = getw(devin);
244   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines