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.5 by gregl, Tue Nov 11 19:55:03 1997 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 40 | Line 30 | struct driver  comm_driver = {
30          comm_comout, comm_comin, comm_flush
31   };
32  
33 + static int      mygets(), myputs(), reply_error(), getstate();
34 +
35   FILE    *devin, *devout;
36  
37   int     devchild;
38  
39  
40 + static struct driver *
41 + final_connect()                         /* verify and initialize connection */
42 + {
43 +        putw(COM_SENDM, devout);
44 +        fflush(devout);
45 +        if (getw(devin) != COM_RECVM)
46 +                return(NULL);
47 +                                                /* get driver parameters */
48 +        getstate();
49 +                                                /* set error vectors */
50 +        erract[COMMAND].pf = comm_comout;
51 +        if (erract[WARNING].pf != NULL)
52 +                erract[WARNING].pf = comm_comout;
53 +        return(&comm_driver);
54 + }
55 +
56 +
57   struct driver *
58 + slave_init(dname, id)                   /* run rview in slave mode */
59 + char    *dname, *id;
60 + {
61 +        devchild = -1;                          /* we're the slave here */
62 +        devout = stdout;                        /* use standard input */
63 +        devin = stdin;                          /* and standard output */
64 +        return(final_connect());                /* verify initialization */
65 + }
66 +
67 +
68 + struct driver *
69   comm_init(dname, id)                    /* set up and execute driver */
70   char    *dname, *id;
71   {
# Line 53 | Line 73 | char   *dname, *id;
73          int     p1[2], p2[2];
74          char    pin[16], pout[16];
75                                                  /* find driver program */
76 <        if ((devname = getpath(dname, DEVPATH, 1)) == NULL) {
77 <                stderr_v(dname);
78 <                stderr_v(": not found\n");
76 >        if ((devname = getpath(dname, DEVPATH, X_OK)) == NULL) {
77 >                eputs(dname);
78 >                eputs(": not found\n");
79                  return(NULL);
80          }
81                                                  /* open communication pipes */
# Line 78 | Line 98 | char   *dname, *id;
98                  goto syserr;
99          if ((devin = fdopen(p2[0], "r")) == NULL)
100                  goto syserr;
101 <                                                /* 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);
101 >        return(final_connect());                /* verify initialization */
102   syserr:
103          perror(dname);
104          return(NULL);
# Line 101 | Line 110 | comm_close()                   /* done with driver */
110   {
111          int     pid;
112  
113 <        cmdvec = NULL;                          /* reset error vectors */
114 <        if (wrnvec != NULL)
115 <                wrnvec = stderr_v;
113 >        erract[COMMAND].pf = NULL;              /* reset error vectors */
114 >        if (erract[WARNING].pf != NULL)
115 >                erract[WARNING].pf = wputs;
116          fclose(devout);
117          fclose(devin);
118 +        if (devchild < 0)
119 +                return;
120          while ((pid = wait(0)) != -1 && pid != devchild)
121                  ;
122   }
# Line 143 | Line 154 | comm_flush()                           /* flush output to driver */
154          fflush(devout);
155          if (getc(devin) != COM_FLUSH)
156                  reply_error("flush");
157 <        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);
157 >        getstate();
158   }
159  
160  
# Line 174 | Line 181 | char   *str;
181   {
182          putc(COM_COMOUT, devout);
183          myputs(str, devout);
184 +        if (str[strlen(str)-1] == '\n')
185 +                fflush(devout);
186   }
187  
188  
# Line 193 | Line 202 | char   *prompt;
202          if (getc(devin) != COM_COMIN)
203                  reply_error("comin");
204          mygets(buf, devin);
205 <        comm_driver.inpready = getw(devin);
205 >        getstate();
206   }
207  
208  
209   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
210   mygets(s, fp)                           /* get string from file (with nul) */
211   register char   *s;
212   register FILE   *fp;
# Line 235 | Line 235 | static
235   reply_error(routine)                    /* what should we do here? */
236   char    *routine;
237   {
238 <        stderr_v(routine);
239 <        stderr_v(": driver reply error\n");
238 >        eputs(routine);
239 >        eputs(": driver reply error\n");
240          quit(1);
241 + }
242 +
243 +
244 + static
245 + getstate()                              /* get driver state variables */
246 + {
247 +        fread((char *)&comm_driver.pixaspect,
248 +                        sizeof(comm_driver.pixaspect), 1, devin);
249 +        comm_driver.xsiz = getw(devin);
250 +        comm_driver.ysiz = getw(devin);
251 +        comm_driver.inpready = getw(devin);
252   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines