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.2 by greg, Thu May 25 19:33:21 1989 UTC vs.
Revision 1.19 by greg, Thu Oct 18 13:33:09 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  
31 < #ifndef WFLUSH
32 < #define WFLUSH          30              /* flush after this many rays */
31 < #endif
31 > static int      comm_close(), comm_clear(), comm_paintr(), comm_errout(),
32 >                comm_getcur(), comm_comout(), comm_comin(), comm_flush();
33  
34 < 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 = {
34 > struct driver   comm_driver = {
35          comm_close, comm_clear, comm_paintr, comm_getcur,
36 <        comm_comout, comm_comin,
43 <        MAXRES, MAXRES, 0
36 >        comm_comout, comm_comin, comm_flush
37   };
38  
39   FILE    *devin, *devout;
# Line 49 | Line 42 | int    devchild;
42  
43  
44   struct driver *
45 < comm_init(argv)                 /* set up and execute driver */
46 < char    *argv[];
45 > comm_init(dname, id)                    /* set up and execute driver */
46 > char    *dname, *id;
47   {
48          char    *devname;
49          int     p1[2], p2[2];
50 <
51 <        if ((devname = getpath(argv[0], DEVPATH)) == NULL) {
52 <                stderr_v(argv[0]);
50 >        char    pin[16], pout[16];
51 >                                                /* find driver program */
52 >        if ((devname = getpath(dname, DEVPATH, X_OK)) == NULL) {
53 >                stderr_v(dname);
54                  stderr_v(": not found\n");
55                  return(NULL);
56          }
57 +                                                /* open communication pipes */
58          if (pipe(p1) == -1 || pipe(p2) == -1)
59                  goto syserr;
60 <        if ((devchild = vfork()) == 0) {
60 >        if ((devchild = vfork()) == 0) {        /* fork driver process */
61                  close(p1[1]);
62                  close(p2[0]);
63 <                if (p1[0] != 0) {
64 <                        dup2(p1[0], 0);
65 <                        close(p1[0]);
66 <                }
72 <                if (p2[1] != 1) {
73 <                        dup2(p2[1], 1);
74 <                        close(p2[1]);
75 <                }
76 <                execv(devname, argv);
77 <                stderr_v(devname);
78 <                stderr_v(": cannot execute\n");
63 >                sprintf(pin, "%d", p1[0]);
64 >                sprintf(pout, "%d", p2[1]);
65 >                execl(devname, dname, pin, pout, id, 0);
66 >                perror(devname);
67                  _exit(127);
68          }
69          if (devchild == -1)
# Line 86 | Line 74 | char   *argv[];
74                  goto syserr;
75          if ((devin = fdopen(p2[0], "r")) == NULL)
76                  goto syserr;
77 <        bcopy(&comm_default, &comm_driver, sizeof(comm_driver));
78 <        signal(SIGIO, onsigio);
79 <        cmdvec = comm_comout;                   /* set error vectors */
77 >                                                /* verify initialization */
78 >        putw(COM_SENDM, devout);
79 >        fflush(devout);
80 >        if (getw(devin) != COM_RECVM)
81 >                return(NULL);
82 >                                                /* get driver parameters */
83 >        getstate();
84 >                                                /* set error vectors */
85 >        cmdvec = comm_comout;
86          if (wrnvec != NULL)
87                  wrnvec = comm_comout;
88          return(&comm_driver);
89   syserr:
90 <        perror(argv[0]);
90 >        perror(dname);
91          return(NULL);
92   }
93  
# Line 106 | Line 100 | comm_close()                   /* done with driver */
100          cmdvec = NULL;                          /* reset error vectors */
101          if (wrnvec != NULL)
102                  wrnvec = stderr_v;
109        signal(SIGIO, SIG_DFL);
103          fclose(devout);
104          fclose(devin);
105          while ((pid = wait(0)) != -1 && pid != devchild)
# Line 119 | Line 112 | comm_clear(xres, yres)                         /* clear screen */
112   int     xres, yres;
113   {
114          putc(COM_CLEAR, devout);
115 <        fwrite(&xres, sizeof(xres), 1, devout);
116 <        fwrite(&yres, sizeof(yres), 1, devout);
115 >        putw(xres, devout);
116 >        putw(yres, devout);
117          fflush(devout);
118   }
119  
# Line 130 | Line 123 | comm_paintr(col, xmin, ymin, xmax, ymax)       /* paint a re
123   COLOR   col;
124   int     xmin, ymin, xmax, ymax;
125   {
133        extern long     nrays;          /* number of rays traced */
134        static long     lastflush = 0;  /* ray count at last flush */
135
126          putc(COM_PAINTR, devout);
127 <        fwrite(col, sizeof(COLOR), 1, devout);
128 <        fwrite(&xmin, sizeof(xmin), 1, devout);
129 <        fwrite(&ymin, sizeof(ymin), 1, devout);
130 <        fwrite(&xmax, sizeof(xmax), 1, devout);
131 <        fwrite(&ymax, sizeof(ymax), 1, devout);
142 <        if (nrays - lastflush >= WFLUSH) {
143 <                fflush(devout);
144 <                lastflush = nrays;
145 <        }
127 >        fwrite((char *)col, sizeof(COLOR), 1, devout);
128 >        putw(xmin, devout);
129 >        putw(ymin, devout);
130 >        putw(xmax, devout);
131 >        putw(ymax, devout);
132   }
133  
134  
135 + static
136 + comm_flush()                            /* flush output to driver */
137 + {
138 +        putc(COM_FLUSH, devout);
139 +        fflush(devout);
140 +        if (getc(devin) != COM_FLUSH)
141 +                reply_error("flush");
142 +        getstate();
143 + }
144 +
145 +
146   static int
147   comm_getcur(xp, yp)                     /* get and return cursor position */
148   int     *xp, *yp;
# Line 157 | Line 154 | int    *xp, *yp;
154          if (getc(devin) != COM_GETCUR)
155                  reply_error("getcur");
156          c = getc(devin);
157 <        fread(xp, sizeof(*xp), 1, devin);
158 <        fread(yp, sizeof(*yp), 1, devin);
157 >        *xp = getw(devin);
158 >        *yp = getw(devin);
159          return(c);
160   }
161  
# Line 169 | Line 166 | char   *str;
166   {
167          putc(COM_COMOUT, devout);
168          myputs(str, devout);
169 +        if (str[strlen(str)-1] == '\n')
170 +                fflush(devout);
171   }
172  
173  
174   static
175 < comm_comin(buf)                         /* read string from command line */
175 > comm_comin(buf, prompt)                 /* read string from command line */
176   char    *buf;
177 + char    *prompt;
178   {
179          putc(COM_COMIN, devout);
180 +        if (prompt == NULL)
181 +                putc(0, devout);
182 +        else {
183 +                putc(1, devout);
184 +                myputs(prompt, devout);
185 +        }
186          fflush(devout);
187          if (getc(devin) != COM_COMIN)
188                  reply_error("comin");
189          mygets(buf, devin);
190 <        comm_driver.inpready = 0;
190 >        getstate();
191   }
192  
193  
# Line 230 | Line 236 | char   *routine;
236  
237  
238   static
239 < onsigio()                               /* input ready */
239 > getstate()                              /* get driver state variables */
240   {
241 <        comm_driver.inpready++;
241 >        fread((char *)&comm_driver.pixaspect,
242 >                        sizeof(comm_driver.pixaspect), 1, devin);
243 >        comm_driver.xsiz = getw(devin);
244 >        comm_driver.ysiz = getw(devin);
245 >        comm_driver.inpready = getw(devin);
246   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines