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.15 by greg, Tue Mar 6 17:44:37 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();
34  
35   int     comm_close(), comm_clear(), comm_paintr(), comm_errout(),
36 <                comm_getcur(), comm_comout(), comm_comin();
36 >                comm_getcur(), comm_comout(), comm_comin(), comm_flush();
37  
38 < struct driver   comm_driver, comm_default = {
38 > struct driver   comm_driver = {
39          comm_close, comm_clear, comm_paintr, comm_getcur,
40 <        comm_comout, comm_comin,
43 <        MAXRES, MAXRES, 0
40 >        comm_comout, comm_comin, comm_flush
41   };
42  
43   FILE    *devin, *devout;
# Line 49 | Line 46 | int    devchild;
46  
47  
48   struct driver *
49 < comm_init(argv)                 /* set up and execute driver */
50 < char    *argv[];
49 > comm_init(dname, id)                    /* set up and execute driver */
50 > char    *dname, *id;
51   {
52          char    *devname;
53          int     p1[2], p2[2];
54 <
55 <        if ((devname = getpath(argv[0], DEVPATH)) == NULL) {
56 <                stderr_v(argv[0]);
54 >        char    pin[16], pout[16];
55 >                                                /* find driver program */
56 >        if ((devname = getpath(dname, DEVPATH, 1)) == NULL) {
57 >                stderr_v(dname);
58                  stderr_v(": not found\n");
59                  return(NULL);
60          }
61 +                                                /* open communication pipes */
62          if (pipe(p1) == -1 || pipe(p2) == -1)
63                  goto syserr;
64 <        if ((devchild = vfork()) == 0) {
64 >        if ((devchild = vfork()) == 0) {        /* fork driver process */
65                  close(p1[1]);
66                  close(p2[0]);
67 <                if (p1[0] != 0) {
68 <                        dup2(p1[0], 0);
69 <                        close(p1[0]);
70 <                }
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");
67 >                sprintf(pin, "%d", p1[0]);
68 >                sprintf(pout, "%d", p2[1]);
69 >                execl(devname, dname, pin, pout, id, 0);
70 >                perror(devname);
71                  _exit(127);
72          }
73          if (devchild == -1)
# Line 86 | Line 78 | char   *argv[];
78                  goto syserr;
79          if ((devin = fdopen(p2[0], "r")) == NULL)
80                  goto syserr;
81 <        bcopy(&comm_default, &comm_driver, sizeof(comm_driver));
82 <        signal(SIGIO, onsigio);
83 <        cmdvec = comm_comout;                   /* set error vectors */
81 >                                                /* verify initialization */
82 >        putw(COM_SENDM, devout);
83 >        fflush(devout);
84 >        if (getw(devin) != COM_RECVM)
85 >                return(NULL);
86 >                                                /* get driver parameters */
87 >        comm_flush();
88 >                                                /* set error vectors */
89 >        cmdvec = comm_comout;
90          if (wrnvec != NULL)
91                  wrnvec = comm_comout;
92          return(&comm_driver);
93   syserr:
94 <        perror(argv[0]);
94 >        perror(dname);
95          return(NULL);
96   }
97  
# Line 106 | Line 104 | comm_close()                   /* done with driver */
104          cmdvec = NULL;                          /* reset error vectors */
105          if (wrnvec != NULL)
106                  wrnvec = stderr_v;
109        signal(SIGIO, SIG_DFL);
107          fclose(devout);
108          fclose(devin);
109          while ((pid = wait(0)) != -1 && pid != devchild)
# Line 119 | Line 116 | comm_clear(xres, yres)                         /* clear screen */
116   int     xres, yres;
117   {
118          putc(COM_CLEAR, devout);
119 <        fwrite(&xres, sizeof(xres), 1, devout);
120 <        fwrite(&yres, sizeof(yres), 1, devout);
119 >        putw(xres, devout);
120 >        putw(yres, devout);
121          fflush(devout);
122   }
123  
# Line 130 | Line 127 | comm_paintr(col, xmin, ymin, xmax, ymax)       /* paint a re
127   COLOR   col;
128   int     xmin, ymin, xmax, ymax;
129   {
133        extern long     nrays;          /* number of rays traced */
134        static long     lastflush = 0;  /* ray count at last flush */
135
130          putc(COM_PAINTR, devout);
131 <        fwrite(col, sizeof(COLOR), 1, devout);
132 <        fwrite(&xmin, sizeof(xmin), 1, devout);
133 <        fwrite(&ymin, sizeof(ymin), 1, devout);
134 <        fwrite(&xmax, sizeof(xmax), 1, devout);
135 <        fwrite(&ymax, sizeof(ymax), 1, devout);
142 <        if (nrays - lastflush >= WFLUSH) {
143 <                fflush(devout);
144 <                lastflush = nrays;
145 <        }
131 >        fwrite((char *)col, sizeof(COLOR), 1, devout);
132 >        putw(xmin, devout);
133 >        putw(ymin, devout);
134 >        putw(xmax, devout);
135 >        putw(ymax, devout);
136   }
137  
138  
139 + static
140 + comm_flush()                            /* flush output to driver */
141 + {
142 +        putc(COM_FLUSH, devout);
143 +        fflush(devout);
144 +        if (getc(devin) != COM_FLUSH)
145 +                reply_error("flush");
146 +        fread((char *)&comm_driver.pixaspect,
147 +                        sizeof(comm_driver.pixaspect), 1, devin);
148 +        comm_driver.xsiz = getw(devin);
149 +        comm_driver.ysiz = getw(devin);
150 +        comm_driver.inpready = getw(devin);
151 + }
152 +
153 +
154   static int
155   comm_getcur(xp, yp)                     /* get and return cursor position */
156   int     *xp, *yp;
# Line 157 | Line 162 | int    *xp, *yp;
162          if (getc(devin) != COM_GETCUR)
163                  reply_error("getcur");
164          c = getc(devin);
165 <        fread(xp, sizeof(*xp), 1, devin);
166 <        fread(yp, sizeof(*yp), 1, devin);
165 >        *xp = getw(devin);
166 >        *yp = getw(devin);
167          return(c);
168   }
169  
# Line 169 | Line 174 | char   *str;
174   {
175          putc(COM_COMOUT, devout);
176          myputs(str, devout);
172        fflush(devout);
177   }
178  
179  
180   static
181 < comm_comin(buf)                         /* read string from command line */
181 > comm_comin(buf, prompt)                 /* read string from command line */
182   char    *buf;
183 + char    *prompt;
184   {
185          putc(COM_COMIN, devout);
186 +        if (prompt == NULL)
187 +                putc(0, devout);
188 +        else {
189 +                putc(1, devout);
190 +                myputs(prompt, devout);
191 +        }
192          fflush(devout);
193          if (getc(devin) != COM_COMIN)
194                  reply_error("comin");
195          mygets(buf, devin);
196 <        comm_driver.inpready = 0;
196 >        comm_driver.inpready = getw(devin);
197   }
198  
199  
# Line 227 | Line 238 | char   *routine;
238          stderr_v(routine);
239          stderr_v(": driver reply error\n");
240          quit(1);
230 }
231
232
233 static
234 onsigio()                               /* input ready */
235 {
236        comm_driver.inpready++;
241   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines