ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/xmeta.c
Revision: 1.5
Committed: Wed Nov 21 18:51:05 2007 UTC (17 years ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad4R2P2, rad5R0, rad5R1, rad4R2, rad4R1, rad4R0, rad3R9, rad4R2P1, rad5R3, HEAD
Changes since 1.4: +2 -1 lines
Log Message:
Fixed implicit declarations

File Contents

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