ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/impress.c
Revision: 1.4
Committed: Sat Nov 15 02:13:37 2003 UTC (20 years, 5 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6P1, rad3R6
Changes since 1.3: +21 -20 lines
Log Message:
Continued ANSIfication, and reduced other compile warnings.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: impress.c,v 1.3 2003/10/27 10:28:59 schorsch Exp $";
3 #endif
4 /*
5 * Program to convert meta-files to imPress format
6 *
7 *
8 * 1/2/86
9 */
10
11
12 #include "rtprocess.h"
13 #include "meta.h"
14 #include "imPcodes.h"
15 #include "imPfuncs.h"
16 #include "plot.h"
17
18
19 #define XCOM "pexpand +OCIsv -P %s"
20
21
22 char *progname;
23
24 FILE *imout;
25
26 static short newpage = TRUE;
27
28 static void doprim(register PRIMITIVE *p);
29 static void doglobal(register PRIMITIVE *g);
30
31
32
33 int
34 main(
35 int argc,
36 char **argv
37 )
38
39 {
40 FILE *fp;
41 short condonly, conditioned;
42 char comargs[200], command[300];
43
44 progname = *argv++;
45 argc--;
46
47 condonly = FALSE;
48 conditioned = FALSE;
49
50 while (argc && **argv == '-') {
51 switch (*(*argv+1)) {
52 case 'c':
53 condonly = TRUE;
54 break;
55 case 'r':
56 conditioned = TRUE;
57 break;
58 default:
59 error(WARNING, "unknown option");
60 break;
61 }
62 argv++;
63 argc--;
64 }
65
66 imInit();
67
68 if (conditioned) {
69 if (argc)
70 while (argc) {
71 fp = efopen(*argv, "r");
72 plot(fp);
73 fclose(fp);
74 argv++;
75 argc--;
76 }
77 else
78 plot(stdin);
79 } else {
80 comargs[0] = '\0';
81 while (argc) {
82 strcat(comargs, " ");
83 strcat(comargs, *argv);
84 argv++;
85 argc--;
86 }
87 sprintf(command, XCOM, comargs);
88 if (condonly)
89 return(system(command));
90 else {
91 if ((fp = popen(command, "r")) == NULL)
92 error(SYSTEM, "cannot execute input filter");
93 plot(fp);
94 pclose(fp);
95 }
96 }
97
98 if (!newpage)
99 imEndPage();
100 imEof();
101
102 return(0);
103 }
104
105
106 void
107 plot( /* plot meta-file */
108 register FILE *infp
109 )
110
111 {
112 PRIMITIVE nextp;
113
114 do {
115 readp(&nextp, infp);
116 while (isprim(nextp.com)) {
117 doprim(&nextp);
118 fargs(&nextp);
119 readp(&nextp, infp);
120 }
121 doglobal(&nextp);
122 fargs(&nextp);
123 } while (nextp.com != PEOF);
124
125 }
126
127
128
129 void
130 doglobal( /* execute a global command */
131 register PRIMITIVE *g
132 )
133
134 {
135 switch (g->com) {
136
137 case PEOF:
138 break;
139
140 case PDRAW:
141 fflush(stdout);
142 break;
143
144 case PEOP:
145 if (!newpage)
146 imEndPage(); /* don't waste paper */
147 newpage = TRUE;
148 break;
149
150 case PSET:
151 set(g->arg0, g->args);
152 break;
153
154 case PUNSET:
155 unset(g->arg0);
156 break;
157
158 case PRESET:
159 reset(g->arg0);
160 break;
161
162 default:
163 sprintf(errmsg, "unknown command '%c' in doglobal", g->com);
164 error(WARNING, errmsg);
165 break;
166 }
167
168 }
169
170
171
172 void
173 doprim( /* plot primitive */
174 register PRIMITIVE *p
175 )
176
177 {
178
179 switch (p->com) {
180
181 case PMSTR:
182 printstr(p);
183 break;
184
185 case PLSEG:
186 plotlseg(p);
187 break;
188
189 case PRFILL:
190 fillrect(p);
191 break;
192
193 case PTFILL:
194 filltri(p);
195 break;
196
197 case PPFILL:
198 fillpoly(p);
199 break;
200
201 default:
202 sprintf(errmsg, "unknown command '%c' in doprim", p->com);
203 error(WARNING, errmsg);
204 return;
205 }
206
207 newpage = FALSE;
208
209 }