ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/xmeta.c
Revision: 1.3
Committed: Mon Nov 17 02:21:53 2003 UTC (20 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R7P2, rad3R7P1, rad3R6, rad3R6P1, rad3R8
Changes since 1.2: +3 -2 lines
Log Message:
Unix compile fixes for previous change

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: xmeta.c,v 1.2 2003/10/27 10:28:59 schorsch 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 void
104 plot(infp) /* plot meta-file */
105
106 FILE *infp;
107
108 {
109 PRIMITIVE nextp;
110
111 set(SALL, NULL);
112 do {
113 readp(&nextp, infp);
114 while (isprim(nextp.com)) {
115 doprim(&nextp, 1);
116 readp(&nextp, infp);
117 }
118 doglobal(&nextp, 1);
119 } while (nextp.com != PEOF);
120
121 }
122
123
124
125 replay(xmin, ymin, xmax, ymax) /* play back region */
126 int xmin, ymin, xmax, ymax;
127 {
128 register PRIMITIVE *p;
129
130 unset(SALL);
131 set(SALL, NULL);
132 for (p = recording.ptop; p != NULL; p = p->pnext)
133 if (isprim(p->com)) {
134 if (overlap(p, xmin, ymin, xmax, ymax))
135 doprim(p, 0);
136 } else
137 doglobal(p, 0);
138
139 }
140
141
142
143
144 save(p) /* record primitive */
145 PRIMITIVE *p;
146 {
147 register PRIMITIVE *pnew;
148
149 if ((pnew = palloc()) == NULL)
150 error(SYSTEM, "out of memory in save");
151 mcopy((char *)pnew, (char *)p, sizeof(PRIMITIVE));
152 add(pnew, &recording);
153 }
154
155
156
157
158 doglobal(g, sf) /* execute a global command */
159
160 register PRIMITIVE *g;
161 int sf;
162
163 {
164
165 switch (g->com) {
166
167 case PEOF:
168 return;
169
170 case PDRAW:
171 XFlush();
172 break;
173
174 case PEOP:
175 endpage();
176 plfree(&recording);
177 set(SALL, NULL);
178 newpage = TRUE;
179 return;
180
181 case PSET:
182 set(g->arg0, g->args);
183 break;
184
185 case PUNSET:
186 unset(g->arg0);
187 break;
188
189 case PRESET:
190 reset(g->arg0);
191 break;
192
193 default:
194 sprintf(errmsg, "unknown command '%c' in doglobal", g->com);
195 error(WARNING, errmsg);
196 return;
197 }
198 if (sf)
199 save(g);
200
201 }
202
203
204
205
206 doprim(p, sf) /* plot primitive */
207
208 register PRIMITIVE *p;
209 int sf;
210
211 {
212
213 switch (p->com) {
214
215 case PMSTR:
216 printstr(p);
217 break;
218
219 case PLSEG:
220 plotlseg(p);
221 break;
222
223 case PRFILL:
224 fillrect(p);
225 break;
226
227 case PTFILL:
228 filltri(p);
229 break;
230
231 case PPFILL:
232 fillpoly(p);
233 break;
234
235 default:
236 sprintf(errmsg, "unknown command '%c' in doprim", p->com);
237 error(WARNING, errmsg);
238 return;
239 }
240 if (sf) {
241 save(p);
242 newpage = FALSE;
243 }
244
245 }