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.10 by greg, Fri Jan 19 00:00:08 1990 UTC vs.
Revision 2.4 by greg, Thu Nov 18 09:42:58 1993 UTC

# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include "standard.h"
14  
15 #include <signal.h>
16
15   #include "color.h"
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 BSD
26 < #define vfork           fork
27 < #endif
25 > static int      comm_close(), comm_clear(), comm_paintr(),
26 >                comm_getcur(), comm_comout(), comm_comin(), comm_flush();
27  
28 < #ifndef WFLUSH
30 < #define WFLUSH          30              /* flush after this many rays */
31 < #endif
32 <
33 < 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 = {
28 > struct driver   comm_driver = {
29          comm_close, comm_clear, comm_paintr, comm_getcur,
30 <        comm_comout, comm_comin
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 +        cmdvec = comm_comout;
51 +        if (wrnvec != NULL)
52 +                wrnvec = 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 55 | 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) {
76 >        if ((devname = getpath(dname, DEVPATH, X_OK)) == NULL) {
77                  stderr_v(dname);
78                  stderr_v(": not found\n");
79                  return(NULL);
# Line 80 | Line 98 | char   *dname, *id;
98                  goto syserr;
99          if ((devin = fdopen(p2[0], "r")) == NULL)
100                  goto syserr;
101 <        copystruct(&comm_driver, &comm_default);
84 <                                                /* verify & get resolution */
85 <        putw(COM_SENDM, devout);
86 <        fflush(devout);
87 <        if (getw(devin) != COM_RECVM)
88 <                return(NULL);
89 <        fread((char *)&comm_driver.pixaspect,
90 <                        sizeof(comm_driver.pixaspect), 1, devin);
91 <        comm_driver.xsiz = getw(devin);
92 <        comm_driver.ysiz = getw(devin);
93 <                                                /* input handling */
94 <        signal(SIGIO, onsigio);
95 <                                                /* set error vectors */
96 <        cmdvec = comm_comout;
97 <        if (wrnvec != NULL)
98 <                wrnvec = comm_comout;
99 <        return(&comm_driver);
101 >        return(final_connect());                /* verify initialization */
102   syserr:
103          perror(dname);
104          return(NULL);
# Line 111 | Line 113 | comm_close()                   /* done with driver */
113          cmdvec = NULL;                          /* reset error vectors */
114          if (wrnvec != NULL)
115                  wrnvec = stderr_v;
114        signal(SIGIO, SIG_DFL);
116          fclose(devout);
117          fclose(devin);
118 +        if (devchild < 0)
119 +                return;
120          while ((pid = wait(0)) != -1 && pid != devchild)
121                  ;
122   }
# Line 135 | Line 138 | comm_paintr(col, xmin, ymin, xmax, ymax)       /* paint a re
138   COLOR   col;
139   int     xmin, ymin, xmax, ymax;
140   {
138        extern long     nrays;          /* number of rays traced */
139        static long     lastflush = 0;  /* ray count at last flush */
140
141          putc(COM_PAINTR, devout);
142          fwrite((char *)col, sizeof(COLOR), 1, devout);
143          putw(xmin, devout);
144          putw(ymin, devout);
145          putw(xmax, devout);
146          putw(ymax, devout);
147        if (nrays - lastflush >= WFLUSH) {
148                fflush(devout);
149                lastflush = nrays;
150        }
147   }
148  
149  
150 + static
151 + comm_flush()                            /* flush output to driver */
152 + {
153 +        putc(COM_FLUSH, devout);
154 +        fflush(devout);
155 +        if (getc(devin) != COM_FLUSH)
156 +                reply_error("flush");
157 +        getstate();
158 + }
159 +
160 +
161   static int
162   comm_getcur(xp, yp)                     /* get and return cursor position */
163   int     *xp, *yp;
# Line 174 | Line 181 | char   *str;
181   {
182          putc(COM_COMOUT, devout);
183          myputs(str, devout);
184 <        fflush(devout);
184 >        if (str[strlen(str)-1] == '\n')
185 >                fflush(devout);
186   }
187  
188  
189   static
190 < comm_comin(buf)                         /* read string from command line */
190 > comm_comin(buf, prompt)                 /* read string from command line */
191   char    *buf;
192 + char    *prompt;
193   {
194          putc(COM_COMIN, devout);
195 +        if (prompt == NULL)
196 +                putc(0, devout);
197 +        else {
198 +                putc(1, devout);
199 +                myputs(prompt, devout);
200 +        }
201          fflush(devout);
202          if (getc(devin) != COM_COMIN)
203                  reply_error("comin");
204          mygets(buf, devin);
205 <        if (comm_driver.inpready > 0)
191 <                comm_driver.inpready--;
205 >        getstate();
206   }
207  
208  
209   static
196 comm_errout(str)                        /* display an error message */
197 char    *str;
198 {
199        comm_comout(str);
200        stderr_v(str);                  /* send to standard error also */
201 }
202
203
204 static
210   mygets(s, fp)                           /* get string from file (with nul) */
211   register char   *s;
212   register FILE   *fp;
# Line 237 | Line 242 | char   *routine;
242  
243  
244   static
245 < onsigio()                               /* input ready */
245 > getstate()                              /* get driver state variables */
246   {
247 <        comm_driver.inpready++;
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