ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/devmain.c
(Generate patch)

Comparing ray/src/rt/devmain.c (file contents):
Revision 1.1 by greg, Wed Oct 25 15:37:42 1989 UTC vs.
Revision 2.2 by gregl, Tue Nov 11 20:02:59 1997 UTC

# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12   *      10/25/89
13   */
14  
15 < #include <stdio.h>
15 > #include "standard.h"
16  
17 #include <signal.h>
18
17   #include "color.h"
18  
19   #include "driver.h"
20  
23 int     (*wrnvec)(), (*errvec)(), (*cmdvec)();  /* error vectors, unused */
24
21   struct driver   *dev = NULL;                    /* output device */
22  
23   FILE    *devin, *devout;                        /* communications channels */
24  
29 int     notified = 0;                           /* notified parent of input? */
30
25   char    *progname;                              /* driver name */
26  
27 < int     r_clear(), r_paintr(), r_getcur(), r_comout(), r_comin();
27 > int     r_clear(), r_paintr(), r_getcur(), r_comout(), r_comin(), r_flush();
28  
29   int     (*dev_func[NREQUESTS])() = {            /* request handlers */
30                  r_clear, r_paintr,
31 <                r_getcur, r_comout, r_comin
31 >                r_getcur, r_comout,
32 >                r_comin, r_flush
33          };
34  
35  
# Line 47 | Line 42 | char   *argv[];
42                                                  /* set up I/O */
43          progname = argv[0];
44          if (argc < 3) {
45 <                stderr_v("arg count\n");
45 >                eputs("arg count\n");
46                  quit(1);
47          }
48          devin = fdopen(atoi(argv[1]), "r");
49          devout = fdopen(atoi(argv[2]), "w");
50          if (devin == NULL || devout == NULL || getw(devin) != COM_SENDM) {
51 <                stderr_v("connection failure\n");
51 >                eputs("connection failure\n");
52                  quit(1);
53          }
54                                                  /* open device */
55 <        if ((dev = dinit(argv[0], argv[3])) == NULL) {
61 <                stderr_v("initialization failure\n");
55 >        if ((dev = dinit(argv[0], argv[3])) == NULL)
56                  quit(1);
63        }
57          putw(COM_RECVM, devout);                /* verify initialization */
58 <        putw(dev->xsiz, devout);
66 <        putw(dev->ysiz, devout);
58 >        sendstate();
59          fflush(devout);
60                                                  /* loop on requests */
61          while ((com = getc(devin)) != EOF) {
62                  if (com >= NREQUESTS || dev_func[com] == NULL) {
63 <                        stderr_v("invalid request\n");
63 >                        eputs("invalid request\n");
64                          quit(1);
65                  }
66                  (*dev_func[com])();             /* process request */
# Line 101 | Line 93 | r_paintr()                             /* paint a rectangle */
93          COLOR   col;
94          int     xmin, ymin, xmax, ymax;
95  
96 <        fread(col, sizeof(COLOR), 1, devin);
96 >        fread((char *)col, sizeof(COLOR), 1, devin);
97          xmin = getw(devin); ymin = getw(devin);
98          xmax = getw(devin); ymax = getw(devin);
99          (*dev->paintr)(col, xmin, ymin, xmax, ymax);
108                                        /* check for input */
109        if (dev->inpready > notified) {
110                kill(getppid(), SIGIO);
111                notified = dev->inpready;
112        }
100   }
101  
102  
103 + r_flush()                               /* flush output */
104 + {
105 +        if (dev->flush != NULL)
106 +                (*dev->flush)();
107 +        putc(COM_FLUSH, devout);
108 +        sendstate();
109 +        fflush(devout);
110 + }
111 +
112 +
113   r_getcur()                              /* get and return cursor position */
114   {
115          int     c;
# Line 143 | Line 140 | r_comout()                             /* print string to command line */
140  
141   r_comin()                               /* read string from command line */
142   {
143 <        char    buf[256];
143 >        char    buf[256], *prompt;
144 >                                        /* get prompt */
145 >        if (getc(devin)) {
146 >                mygets(buf, devin);
147 >                prompt = buf;
148 >        } else
149 >                prompt = NULL;
150                                          /* get string */
151 <        (*dev->comin)(buf);
151 >        (*dev->comin)(buf, prompt);
152                                          /* reply */
153          putc(COM_COMIN, devout);
154          myputs(buf, devout);
155 +        sendstate();
156          fflush(devout);
153                                        /* reset notify */
154        notified = 0;
157   }
158  
159  
# Line 178 | Line 180 | register FILE  *fp;
180   }
181  
182  
183 < repaint(xmin, ymin, xmax, ymax)         /* repaint section of display */
182 < int     xmin, ymin, xmax, ymax;
183 < {
184 <        stderr_v("repaint called!\n");          /* no can do! */
185 < }
186 <
187 <
188 < stderr_v(s)                             /* put string to stderr */
183 > eputs(s)                                /* put string to stderr */
184   register char  *s;
185   {
186 <        static int  inline = 0;
186 >        static int  midline = 0;
187  
188 <        if (!inline++) {
188 >        if (!*s)
189 >                return;
190 >        if (!midline++) {
191                  fputs(progname, stderr);
192                  fputs(": ", stderr);
193          }
194          fputs(s, stderr);
195 <        if (*s && s[strlen(s)-1] == '\n') {
195 >        if (s[strlen(s)-1] == '\n') {
196                  fflush(stderr);
197 <                inline = 0;
197 >                midline = 0;
198          }
199 + }
200 +
201 +
202 + sendstate()                             /* send driver state variables */
203 + {
204 +        fwrite((char *)&dev->pixaspect, sizeof(dev->pixaspect), 1, devout);
205 +        putw(dev->xsiz, devout);
206 +        putw(dev->ysiz, devout);
207 +        putw(dev->inpready, devout);
208   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines