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.4 by greg, Fri Jun 2 17:21:24 1989 UTC vs.
Revision 1.16 by greg, Mon Mar 12 11:08:44 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          50              /* 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 49 | Line 44 | int    devchild;
44  
45  
46   struct driver *
47 < comm_init(argv)                 /* set up and execute driver */
48 < char    *argv[];
47 > comm_init(dname, id)                    /* set up and execute driver */
48 > char    *dname, *id;
49   {
50          char    *devname;
51          int     p1[2], p2[2];
52 <
53 <        if ((devname = getpath(argv[0], DEVPATH)) == NULL) {
54 <                stderr_v(argv[0]);
52 >        char    pin[16], pout[16];
53 >                                                /* find driver program */
54 >        if ((devname = getpath(dname, DEVPATH, 1)) == NULL) {
55 >                stderr_v(dname);
56                  stderr_v(": not found\n");
57                  return(NULL);
58          }
59 +                                                /* open communication pipes */
60          if (pipe(p1) == -1 || pipe(p2) == -1)
61                  goto syserr;
62 <        if ((devchild = vfork()) == 0) {
62 >        if ((devchild = vfork()) == 0) {        /* fork driver process */
63                  close(p1[1]);
64                  close(p2[0]);
65 <                if (p1[0] != 0) {
66 <                        dup2(p1[0], 0);
67 <                        close(p1[0]);
68 <                }
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");
65 >                sprintf(pin, "%d", p1[0]);
66 >                sprintf(pout, "%d", p2[1]);
67 >                execl(devname, dname, pin, pout, id, 0);
68 >                perror(devname);
69                  _exit(127);
70          }
71          if (devchild == -1)
# Line 86 | Line 76 | char   *argv[];
76                  goto syserr;
77          if ((devin = fdopen(p2[0], "r")) == NULL)
78                  goto syserr;
79 <        bcopy(&comm_default, &comm_driver, sizeof(comm_driver));
80 <        signal(SIGIO, onsigio);
81 <        cmdvec = comm_comout;                   /* set error vectors */
79 >                                                /* verify initialization */
80 >        putw(COM_SENDM, devout);
81 >        fflush(devout);
82 >        if (getw(devin) != COM_RECVM)
83 >                return(NULL);
84 >                                                /* get driver parameters */
85 >        comm_flush();
86 >                                                /* set error vectors */
87 >        cmdvec = comm_comout;
88          if (wrnvec != NULL)
89                  wrnvec = comm_comout;
90          return(&comm_driver);
91   syserr:
92 <        perror(argv[0]);
92 >        perror(dname);
93          return(NULL);
94   }
95  
# Line 106 | Line 102 | comm_close()                   /* done with driver */
102          cmdvec = NULL;                          /* reset error vectors */
103          if (wrnvec != NULL)
104                  wrnvec = stderr_v;
109        signal(SIGIO, SIG_DFL);
105          fclose(devout);
106          fclose(devin);
107          while ((pid = wait(0)) != -1 && pid != devchild)
# Line 119 | 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 130 | Line 125 | comm_paintr(col, xmin, ymin, xmax, ymax)       /* paint a re
125   COLOR   col;
126   int     xmin, ymin, xmax, ymax;
127   {
133        extern long     nrays;          /* number of rays traced */
134        static long     lastflush = 0;  /* ray count at last flush */
135
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);
142 <        if (nrays - lastflush >= WFLUSH) {
143 <                fflush(devout);
144 <                lastflush = nrays;
145 <        }
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 +        fread((char *)&comm_driver.pixaspect,
145 +                        sizeof(comm_driver.pixaspect), 1, devin);
146 +        comm_driver.xsiz = getw(devin);
147 +        comm_driver.ysiz = getw(devin);
148 +        comm_driver.inpready = getw(devin);
149 + }
150 +
151 +
152   static int
153   comm_getcur(xp, yp)                     /* get and return cursor position */
154   int     *xp, *yp;
# Line 157 | Line 160 | int    *xp, *yp;
160          if (getc(devin) != COM_GETCUR)
161                  reply_error("getcur");
162          c = getc(devin);
163 <        fread(xp, sizeof(*xp), 1, devin);
164 <        fread(yp, sizeof(*yp), 1, devin);
163 >        *xp = getw(devin);
164 >        *yp = getw(devin);
165          return(c);
166   }
167  
# Line 169 | Line 172 | char   *str;
172   {
173          putc(COM_COMOUT, devout);
174          myputs(str, devout);
172        fflush(devout);
175   }
176  
177  
178   static
179 < comm_comin(buf)                         /* read string from command line */
179 > comm_comin(buf, prompt)                 /* read string from command line */
180   char    *buf;
181 + char    *prompt;
182   {
183          putc(COM_COMIN, devout);
184 +        if (prompt == NULL)
185 +                putc(0, devout);
186 +        else {
187 +                putc(1, devout);
188 +                myputs(prompt, devout);
189 +        }
190          fflush(devout);
191          if (getc(devin) != COM_COMIN)
192                  reply_error("comin");
193          mygets(buf, devin);
194 <        comm_driver.inpready = 0;
194 >        comm_driver.inpready = getw(devin);
195   }
196  
197  
# Line 227 | Line 236 | char   *routine;
236          stderr_v(routine);
237          stderr_v(": driver reply error\n");
238          quit(1);
230 }
231
232
233 static
234 onsigio()                               /* input ready */
235 {
236        comm_driver.inpready++;
239   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines