ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/devmain.c
Revision: 1.12
Committed: Thu Mar 22 20:58:09 1990 UTC (34 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.11: +3 -3 lines
Log Message:
changed "inline" to "midline" for future compiler compatibility

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1989 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * devmain.c - main for independent drivers.
9     *
10     * Redefine your initialization routine to dinit.
11     *
12     * 10/25/89
13     */
14    
15     #include <stdio.h>
16    
17     #include "color.h"
18    
19     #include "driver.h"
20    
21     int (*wrnvec)(), (*errvec)(), (*cmdvec)(); /* error vectors, unused */
22    
23     struct driver *dev = NULL; /* output device */
24    
25     FILE *devin, *devout; /* communications channels */
26    
27     char *progname; /* driver name */
28    
29 greg 1.8 int r_clear(), r_paintr(), r_getcur(), r_comout(), r_comin(), r_flush();
30 greg 1.1
31     int (*dev_func[NREQUESTS])() = { /* request handlers */
32     r_clear, r_paintr,
33 greg 1.8 r_getcur, r_comout,
34     r_comin, r_flush
35 greg 1.1 };
36    
37    
38     main(argc, argv) /* set up communications and main loop */
39     int argc;
40     char *argv[];
41     {
42     extern struct driver *dinit();
43     int com;
44     /* set up I/O */
45     progname = argv[0];
46     if (argc < 3) {
47     stderr_v("arg count\n");
48     quit(1);
49     }
50     devin = fdopen(atoi(argv[1]), "r");
51     devout = fdopen(atoi(argv[2]), "w");
52     if (devin == NULL || devout == NULL || getw(devin) != COM_SENDM) {
53     stderr_v("connection failure\n");
54     quit(1);
55     }
56     /* open device */
57 greg 1.2 if ((dev = dinit(argv[0], argv[3])) == NULL)
58 greg 1.1 quit(1);
59     putw(COM_RECVM, devout); /* verify initialization */
60 greg 1.11 sendstate();
61 greg 1.1 fflush(devout);
62     /* loop on requests */
63     while ((com = getc(devin)) != EOF) {
64     if (com >= NREQUESTS || dev_func[com] == NULL) {
65     stderr_v("invalid request\n");
66     quit(1);
67     }
68     (*dev_func[com])(); /* process request */
69     }
70     quit(0); /* all done, clean up and exit */
71     }
72    
73    
74     quit(code) /* close device and exit */
75     int code;
76     {
77     if (dev != NULL)
78     (*dev->close)();
79     exit(code);
80     }
81    
82    
83     r_clear() /* clear screen */
84     {
85     int xres, yres;
86    
87     xres = getw(devin);
88     yres = getw(devin);
89     (*dev->clear)(xres, yres);
90     }
91    
92    
93     r_paintr() /* paint a rectangle */
94     {
95     COLOR col;
96     int xmin, ymin, xmax, ymax;
97    
98 greg 1.6 fread((char *)col, sizeof(COLOR), 1, devin);
99 greg 1.1 xmin = getw(devin); ymin = getw(devin);
100     xmax = getw(devin); ymax = getw(devin);
101     (*dev->paintr)(col, xmin, ymin, xmax, ymax);
102 greg 1.8 }
103    
104    
105     r_flush() /* flush output */
106     {
107     if (dev->flush != NULL)
108     (*dev->flush)();
109 greg 1.9 putc(COM_FLUSH, devout);
110 greg 1.11 sendstate();
111 greg 1.9 fflush(devout);
112 greg 1.1 }
113    
114    
115     r_getcur() /* get and return cursor position */
116     {
117     int c;
118     int x, y;
119     /* get it if we can */
120     if (dev->getcur == NULL) {
121     c = ABORT;
122     x = y = 0;
123     } else
124     c = (*dev->getcur)(&x, &y);
125     /* reply */
126     putc(COM_GETCUR, devout);
127     putc(c, devout);
128     putw(x, devout);
129     putw(y, devout);
130     fflush(devout);
131     }
132    
133    
134     r_comout() /* print string to command line */
135     {
136     char str[256];
137    
138     mygets(str, devin);
139     (*dev->comout)(str);
140     }
141    
142    
143     r_comin() /* read string from command line */
144     {
145 greg 1.7 char buf[256], *prompt;
146     /* get prompt */
147     if (getc(devin)) {
148     mygets(buf, devin);
149     prompt = buf;
150     } else
151     prompt = NULL;
152 greg 1.1 /* get string */
153 greg 1.7 (*dev->comin)(buf, prompt);
154 greg 1.1 /* reply */
155     putc(COM_COMIN, devout);
156     myputs(buf, devout);
157 greg 1.11 sendstate();
158 greg 1.1 fflush(devout);
159     }
160    
161    
162     mygets(s, fp) /* get string from file (with nul) */
163     register char *s;
164     register FILE *fp;
165     {
166     register int c;
167    
168     while ((c = getc(fp)) != EOF)
169     if ((*s++ = c) == '\0')
170     return;
171     *s = '\0';
172     }
173    
174    
175     myputs(s, fp) /* put string to file (with nul) */
176     register char *s;
177     register FILE *fp;
178     {
179     do
180     putc(*s, fp);
181     while (*s++);
182     }
183    
184    
185     stderr_v(s) /* put string to stderr */
186     register char *s;
187     {
188 greg 1.12 static int midline = 0;
189 greg 1.1
190 greg 1.12 if (!midline++) {
191 greg 1.1 fputs(progname, stderr);
192     fputs(": ", stderr);
193     }
194     fputs(s, stderr);
195     if (*s && s[strlen(s)-1] == '\n') {
196     fflush(stderr);
197 greg 1.12 midline = 0;
198 greg 1.1 }
199 greg 1.11 }
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 greg 1.1 }