ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/devmain.c
Revision: 1.10
Committed: Tue Mar 6 17:44:44 1990 UTC (34 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.9: +3 -3 lines
Log Message:
made sundev work with resizing

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     fflush(devout);
61     /* loop on requests */
62     while ((com = getc(devin)) != EOF) {
63     if (com >= NREQUESTS || dev_func[com] == NULL) {
64     stderr_v("invalid request\n");
65     quit(1);
66     }
67     (*dev_func[com])(); /* process request */
68     }
69     quit(0); /* all done, clean up and exit */
70     }
71    
72    
73     quit(code) /* close device and exit */
74     int code;
75     {
76     if (dev != NULL)
77     (*dev->close)();
78     exit(code);
79     }
80    
81    
82     r_clear() /* clear screen */
83     {
84     int xres, yres;
85    
86     xres = getw(devin);
87     yres = getw(devin);
88     (*dev->clear)(xres, yres);
89     }
90    
91    
92     r_paintr() /* paint a rectangle */
93     {
94     COLOR col;
95     int xmin, ymin, xmax, ymax;
96    
97 greg 1.6 fread((char *)col, sizeof(COLOR), 1, devin);
98 greg 1.1 xmin = getw(devin); ymin = getw(devin);
99     xmax = getw(devin); ymax = getw(devin);
100     (*dev->paintr)(col, xmin, ymin, xmax, ymax);
101 greg 1.8 }
102    
103    
104     r_flush() /* flush output */
105     {
106     if (dev->flush != NULL)
107     (*dev->flush)();
108 greg 1.9 putc(COM_FLUSH, devout);
109 greg 1.10 fwrite((char *)&dev->pixaspect, sizeof(dev->pixaspect), 1, devout);
110     putw(dev->xsiz, devout);
111     putw(dev->ysiz, devout);
112 greg 1.9 putw(dev->inpready, devout);
113     fflush(devout);
114 greg 1.1 }
115    
116    
117     r_getcur() /* get and return cursor position */
118     {
119     int c;
120     int x, y;
121     /* get it if we can */
122     if (dev->getcur == NULL) {
123     c = ABORT;
124     x = y = 0;
125     } else
126     c = (*dev->getcur)(&x, &y);
127     /* reply */
128     putc(COM_GETCUR, devout);
129     putc(c, devout);
130     putw(x, devout);
131     putw(y, devout);
132     fflush(devout);
133     }
134    
135    
136     r_comout() /* print string to command line */
137     {
138     char str[256];
139    
140     mygets(str, devin);
141     (*dev->comout)(str);
142     }
143    
144    
145     r_comin() /* read string from command line */
146     {
147 greg 1.7 char buf[256], *prompt;
148     /* get prompt */
149     if (getc(devin)) {
150     mygets(buf, devin);
151     prompt = buf;
152     } else
153     prompt = NULL;
154 greg 1.1 /* get string */
155 greg 1.7 (*dev->comin)(buf, prompt);
156 greg 1.1 /* reply */
157     putc(COM_COMIN, devout);
158     myputs(buf, devout);
159 greg 1.9 putw(dev->inpready, devout);
160 greg 1.1 fflush(devout);
161     }
162    
163    
164     mygets(s, fp) /* get string from file (with nul) */
165     register char *s;
166     register FILE *fp;
167     {
168     register int c;
169    
170     while ((c = getc(fp)) != EOF)
171     if ((*s++ = c) == '\0')
172     return;
173     *s = '\0';
174     }
175    
176    
177     myputs(s, fp) /* put string to file (with nul) */
178     register char *s;
179     register FILE *fp;
180     {
181     do
182     putc(*s, fp);
183     while (*s++);
184     }
185    
186    
187     stderr_v(s) /* put string to stderr */
188     register char *s;
189     {
190     static int inline = 0;
191    
192     if (!inline++) {
193     fputs(progname, stderr);
194     fputs(": ", stderr);
195     }
196     fputs(s, stderr);
197     if (*s && s[strlen(s)-1] == '\n') {
198     fflush(stderr);
199     inline = 0;
200     }
201     }