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