ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/xmeta.c
Revision: 1.2
Committed: Mon Oct 27 10:28:59 2003 UTC (21 years, 1 month ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 1.1: +2 -4 lines
Log Message:
Various compatibility fixes.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: xmeta.c,v 1.1 2003/02/22 02:07:26 greg Exp $";
3 #endif
4 /*
5 * Program to output meta-files to X window system.
6 *
7 * cc -o Xmeta Xmeta.c Xplot.o plot.o mfio.o syscalls.o misc.o
8 *
9 * 2/26/86
10 */
11
12 #include "rtprocess.h"
13 #include "meta.h"
14 #include "plot.h"
15
16
17 #define overlap(p,xmn,ymn,xmx,ymx) (ov((p)->xy[XMN],(p)->xy[XMX],xmn,xmx) \
18 &&ov((p)->xy[YMN],(p)->xy[YMX],ymn,ymx))
19
20 #define ov(mn1,mx1,mn2,mx2) ((mn1)<(mx2)&&(mn2)<(mx1))
21
22 #define XCOM "pexpand +OCIsv -P %s"
23
24
25 char *progname;
26
27 static short newpage = TRUE;
28
29 static PLIST recording;
30
31 int maxalloc = 0; /* no limit */
32
33
34
35 main(argc, argv)
36
37 int argc;
38 char **argv;
39
40 {
41 FILE *fp;
42 char *geometry = NULL;
43 short condonly, conditioned;
44 char comargs[500], command[600];
45
46 progname = *argv++;
47 argc--;
48
49 condonly = FALSE;
50 conditioned = FALSE;
51
52 for ( ; argc; argv++, argc--)
53 if (!strcmp(*argv, "-c"))
54 condonly = TRUE;
55 else if (!strcmp(*argv, "-r"))
56 conditioned = TRUE;
57 else if (**argv == '=')
58 geometry = *argv;
59 else
60 break;
61
62 if (conditioned) {
63 init(progname, geometry);
64 if (argc)
65 while (argc) {
66 fp = efopen(*argv, "r");
67 plot(fp);
68 fclose(fp);
69 argv++;
70 argc--;
71 }
72 else
73 plot(stdin);
74 } else {
75 comargs[0] = '\0';
76 while (argc) {
77 strcat(comargs, " ");
78 strcat(comargs, *argv);
79 argv++;
80 argc--;
81 }
82 sprintf(command, XCOM, comargs);
83 if (condonly)
84 return(system(command));
85 else {
86 init(progname, geometry);
87 if ((fp = popen(command, "r")) == NULL)
88 error(SYSTEM, "cannot execute input filter");
89 plot(fp);
90 pclose(fp);
91 }
92 }
93
94 if (!newpage)
95 endpage();
96
97 return(0);
98 }
99
100
101
102
103 plot(infp) /* plot meta-file */
104
105 FILE *infp;
106
107 {
108 PRIMITIVE nextp;
109
110 set(SALL, NULL);
111 do {
112 readp(&nextp, infp);
113 while (isprim(nextp.com)) {
114 doprim(&nextp, 1);
115 readp(&nextp, infp);
116 }
117 doglobal(&nextp, 1);
118 } while (nextp.com != PEOF);
119
120 }
121
122
123
124 replay(xmin, ymin, xmax, ymax) /* play back region */
125 int xmin, ymin, xmax, ymax;
126 {
127 register PRIMITIVE *p;
128
129 unset(SALL);
130 set(SALL, NULL);
131 for (p = recording.ptop; p != NULL; p = p->pnext)
132 if (isprim(p->com)) {
133 if (overlap(p, xmin, ymin, xmax, ymax))
134 doprim(p, 0);
135 } else
136 doglobal(p, 0);
137
138 }
139
140
141
142
143 save(p) /* record primitive */
144 PRIMITIVE *p;
145 {
146 register PRIMITIVE *pnew;
147
148 if ((pnew = palloc()) == NULL)
149 error(SYSTEM, "out of memory in save");
150 mcopy(pnew, p, sizeof(PRIMITIVE));
151 add(pnew, &recording);
152 }
153
154
155
156
157 doglobal(g, sf) /* execute a global command */
158
159 register PRIMITIVE *g;
160 int sf;
161
162 {
163
164 switch (g->com) {
165
166 case PEOF:
167 return;
168
169 case PDRAW:
170 XFlush();
171 break;
172
173 case PEOP:
174 endpage();
175 plfree(&recording);
176 set(SALL, NULL);
177 newpage = TRUE;
178 return;
179
180 case PSET:
181 set(g->arg0, g->args);
182 break;
183
184 case PUNSET:
185 unset(g->arg0);
186 break;
187
188 case PRESET:
189 reset(g->arg0);
190 break;
191
192 default:
193 sprintf(errmsg, "unknown command '%c' in doglobal", g->com);
194 error(WARNING, errmsg);
195 return;
196 }
197 if (sf)
198 save(g);
199
200 }
201
202
203
204
205 doprim(p, sf) /* plot primitive */
206
207 register PRIMITIVE *p;
208 int sf;
209
210 {
211
212 switch (p->com) {
213
214 case PMSTR:
215 printstr(p);
216 break;
217
218 case PLSEG:
219 plotlseg(p);
220 break;
221
222 case PRFILL:
223 fillrect(p);
224 break;
225
226 case PTFILL:
227 filltri(p);
228 break;
229
230 case PPFILL:
231 fillpoly(p);
232 break;
233
234 default:
235 sprintf(errmsg, "unknown command '%c' in doprim", p->com);
236 error(WARNING, errmsg);
237 return;
238 }
239 if (sf) {
240 save(p);
241 newpage = FALSE;
242 }
243
244 }