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.15 by greg, Tue Mar 6 17:44:37 1990 UTC vs.
Revision 2.3 by greg, Mon Apr 5 15:16:47 1993 UTC

# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
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 DELAY
24 < #define DELAY           20              /* seconds to wait for response */
25 < #endif
26 <
27 < #ifndef BSD
28 < #define vfork           fork
29 < #endif
30 <
31 < extern char     *getpath(), *getenv();
32 <
33 < int     onsigio();
34 <
35 < int     comm_close(), comm_clear(), comm_paintr(), comm_errout(),
25 > static int      comm_close(), comm_clear(), comm_paintr(),
26                  comm_getcur(), comm_comout(), comm_comin(), comm_flush();
27  
28   struct driver   comm_driver = {
# Line 45 | Line 35 | FILE   *devin, *devout;
35   int     devchild;
36  
37  
38 + static struct driver *
39 + final_connect()                         /* verify and initialize connection */
40 + {
41 +        putw(COM_SENDM, devout);
42 +        fflush(devout);
43 +        if (getw(devin) != COM_RECVM)
44 +                return(NULL);
45 +                                                /* get driver parameters */
46 +        getstate();
47 +                                                /* set error vectors */
48 +        cmdvec = comm_comout;
49 +        if (wrnvec != NULL)
50 +                wrnvec = comm_comout;
51 +        return(&comm_driver);
52 + }
53 +
54 +
55   struct driver *
56 + slave_init(dname, id)                   /* run rview in slave mode */
57 + char    *dname, *id;
58 + {
59 +        devchild = -1;                          /* we're the slave here */
60 +        devout = stdout;                        /* use standard input */
61 +        devin = stdin;                          /* and standard output */
62 +        return(final_connect());                /* verify initialization */
63 + }
64 +
65 +
66 + struct driver *
67   comm_init(dname, id)                    /* set up and execute driver */
68   char    *dname, *id;
69   {
# Line 53 | Line 71 | char   *dname, *id;
71          int     p1[2], p2[2];
72          char    pin[16], pout[16];
73                                                  /* find driver program */
74 <        if ((devname = getpath(dname, DEVPATH, 1)) == NULL) {
74 >        if ((devname = getpath(dname, DEVPATH, X_OK)) == NULL) {
75                  stderr_v(dname);
76                  stderr_v(": not found\n");
77                  return(NULL);
# Line 78 | Line 96 | char   *dname, *id;
96                  goto syserr;
97          if ((devin = fdopen(p2[0], "r")) == NULL)
98                  goto syserr;
99 <                                                /* 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);
99 >        return(final_connect());                /* verify initialization */
100   syserr:
101          perror(dname);
102          return(NULL);
# Line 106 | Line 113 | comm_close()                   /* done with driver */
113                  wrnvec = stderr_v;
114          fclose(devout);
115          fclose(devin);
116 +        if (devchild < 0)
117 +                return;
118          while ((pid = wait(0)) != -1 && pid != devchild)
119                  ;
120   }
# Line 143 | Line 152 | comm_flush()                           /* flush output to driver */
152          fflush(devout);
153          if (getc(devin) != COM_FLUSH)
154                  reply_error("flush");
155 <        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);
155 >        getstate();
156   }
157  
158  
# Line 174 | Line 179 | char   *str;
179   {
180          putc(COM_COMOUT, devout);
181          myputs(str, devout);
182 +        if (str[strlen(str)-1] == '\n')
183 +                fflush(devout);
184   }
185  
186  
# Line 193 | Line 200 | char   *prompt;
200          if (getc(devin) != COM_COMIN)
201                  reply_error("comin");
202          mygets(buf, devin);
203 <        comm_driver.inpready = getw(devin);
203 >        getstate();
204   }
205  
206  
207   static
201 comm_errout(str)                        /* display an error message */
202 char    *str;
203 {
204        comm_comout(str);
205        stderr_v(str);                  /* send to standard error also */
206 }
207
208
209 static
208   mygets(s, fp)                           /* get string from file (with nul) */
209   register char   *s;
210   register FILE   *fp;
# Line 238 | Line 236 | char   *routine;
236          stderr_v(routine);
237          stderr_v(": driver reply error\n");
238          quit(1);
239 + }
240 +
241 +
242 + static
243 + getstate()                              /* get driver state variables */
244 + {
245 +        fread((char *)&comm_driver.pixaspect,
246 +                        sizeof(comm_driver.pixaspect), 1, devin);
247 +        comm_driver.xsiz = getw(devin);
248 +        comm_driver.ysiz = getw(devin);
249 +        comm_driver.inpready = getw(devin);
250   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines