1 |
greg |
1.1 |
#ifndef lint |
2 |
schorsch |
1.4 |
static const char RCSid[] = "$Id: psmeta.c,v 1.3 2003/07/21 22:30:18 schorsch Exp $"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Program to convert meta-files to PostScript. |
6 |
|
|
* |
7 |
|
|
* 9/23/88 |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
|
11 |
|
|
#include "meta.h" |
12 |
|
|
#include "plot.h" |
13 |
schorsch |
1.4 |
#include "psplot.h" |
14 |
greg |
1.1 |
|
15 |
|
|
|
16 |
|
|
char *progname; |
17 |
|
|
|
18 |
|
|
static short newpage = TRUE; |
19 |
|
|
|
20 |
schorsch |
1.4 |
static void doprim(PRIMITIVE *p); |
21 |
|
|
static int doglobal(PRIMITIVE *g); |
22 |
greg |
1.1 |
|
23 |
schorsch |
1.4 |
int |
24 |
|
|
main( |
25 |
|
|
int argc, |
26 |
|
|
char **argv |
27 |
|
|
) |
28 |
greg |
1.1 |
{ |
29 |
|
|
FILE *fp; |
30 |
|
|
|
31 |
|
|
progname = *argv++; |
32 |
|
|
argc--; |
33 |
|
|
|
34 |
|
|
init(progname); |
35 |
|
|
if (argc) |
36 |
|
|
while (argc) { |
37 |
|
|
fp = efopen(*argv, "r"); |
38 |
|
|
plot(fp); |
39 |
|
|
fclose(fp); |
40 |
|
|
argv++; |
41 |
|
|
argc--; |
42 |
|
|
} |
43 |
|
|
else |
44 |
|
|
plot(stdin); |
45 |
|
|
|
46 |
|
|
if (!newpage) |
47 |
|
|
endpage(); |
48 |
|
|
|
49 |
|
|
done(); |
50 |
|
|
return(0); |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
schorsch |
1.4 |
void |
56 |
|
|
plot( /* plot meta-file */ |
57 |
|
|
FILE *infp |
58 |
|
|
) |
59 |
greg |
1.1 |
{ |
60 |
|
|
PRIMITIVE nextp; |
61 |
|
|
|
62 |
|
|
do { |
63 |
|
|
readp(&nextp, infp); |
64 |
|
|
while (isprim(nextp.com)) { |
65 |
|
|
doprim(&nextp); |
66 |
|
|
readp(&nextp, infp); |
67 |
|
|
} |
68 |
|
|
} while (doglobal(&nextp)); |
69 |
|
|
|
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
|
73 |
schorsch |
1.4 |
int |
74 |
|
|
doglobal( /* execute a global command */ |
75 |
|
|
PRIMITIVE *g |
76 |
|
|
) |
77 |
greg |
1.1 |
{ |
78 |
schorsch |
1.4 |
FILE *fp = NULL; |
79 |
greg |
1.1 |
|
80 |
|
|
switch (g->com) { |
81 |
|
|
|
82 |
|
|
case PEOF: |
83 |
|
|
return(0); |
84 |
|
|
|
85 |
greg |
1.2 |
case PPAUS: |
86 |
greg |
1.1 |
break; |
87 |
|
|
|
88 |
|
|
case PINCL: |
89 |
|
|
if (g->args == NULL) |
90 |
|
|
error(USER, "missing include file name in include"); |
91 |
schorsch |
1.3 |
if (g->arg0 == 2 || (fp = fopen(g->args, "r")) == NULL) { |
92 |
greg |
1.1 |
if (g->arg0 != 0) |
93 |
|
|
fp = mfopen(g->args, "r"); |
94 |
|
|
else { |
95 |
|
|
sprintf(errmsg, "cannot open user include file \"%s\"", |
96 |
|
|
g->args); |
97 |
|
|
error(USER, errmsg); |
98 |
|
|
} |
99 |
schorsch |
1.3 |
} |
100 |
greg |
1.1 |
plot(fp); |
101 |
|
|
fclose(fp); |
102 |
|
|
break; |
103 |
|
|
|
104 |
|
|
case PDRAW: |
105 |
|
|
fflush(stdout); |
106 |
|
|
break; |
107 |
|
|
|
108 |
|
|
case PEOP: |
109 |
|
|
endpage(); |
110 |
|
|
newpage = TRUE; |
111 |
|
|
break; |
112 |
|
|
|
113 |
|
|
case PSET: |
114 |
|
|
set(g->arg0, g->args); |
115 |
|
|
break; |
116 |
|
|
|
117 |
|
|
case PUNSET: |
118 |
|
|
unset(g->arg0); |
119 |
|
|
break; |
120 |
|
|
|
121 |
|
|
case PRESET: |
122 |
|
|
reset(g->arg0); |
123 |
|
|
break; |
124 |
|
|
|
125 |
|
|
case POPEN: |
126 |
|
|
segopen(g->args); |
127 |
|
|
break; |
128 |
|
|
|
129 |
|
|
case PCLOSE: |
130 |
|
|
segclose(); |
131 |
|
|
break; |
132 |
|
|
|
133 |
|
|
default: |
134 |
|
|
sprintf(errmsg, "unknown command '%c' in doglobal", g->com); |
135 |
|
|
error(WARNING, errmsg); |
136 |
|
|
break; |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
return(1); |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
schorsch |
1.4 |
void |
145 |
|
|
doprim( /* plot primitive */ |
146 |
|
|
PRIMITIVE *p |
147 |
|
|
) |
148 |
greg |
1.1 |
{ |
149 |
|
|
|
150 |
|
|
switch (p->com) { |
151 |
|
|
|
152 |
|
|
case PMSTR: |
153 |
|
|
printstr(p); |
154 |
|
|
break; |
155 |
|
|
|
156 |
|
|
case PVSTR: |
157 |
|
|
plotvstr(p); |
158 |
|
|
break; |
159 |
|
|
|
160 |
|
|
case PLSEG: |
161 |
|
|
plotlseg(p); |
162 |
|
|
break; |
163 |
|
|
|
164 |
|
|
case PRFILL: |
165 |
|
|
fillrect(p); |
166 |
|
|
break; |
167 |
|
|
|
168 |
|
|
case PTFILL: |
169 |
|
|
filltri(p); |
170 |
|
|
break; |
171 |
|
|
|
172 |
|
|
case PPFILL: |
173 |
|
|
fillpoly(p); |
174 |
|
|
break; |
175 |
|
|
|
176 |
|
|
case PSEG: |
177 |
|
|
doseg(p); |
178 |
|
|
break; |
179 |
|
|
|
180 |
|
|
default: |
181 |
|
|
sprintf(errmsg, "unknown command '%c' in doprim", p->com); |
182 |
|
|
error(WARNING, errmsg); |
183 |
|
|
return; |
184 |
|
|
} |
185 |
|
|
newpage = FALSE; |
186 |
schorsch |
1.4 |
} |
187 |
greg |
1.1 |
|