| 1 |
greg |
1.1 |
#ifndef lint |
| 2 |
|
|
static const char RCSid[] = "$Id$"; |
| 3 |
|
|
#endif |
| 4 |
|
|
/* |
| 5 |
|
|
* Program to convert meta-files to PostScript. |
| 6 |
|
|
* |
| 7 |
|
|
* 9/23/88 |
| 8 |
|
|
*/ |
| 9 |
|
|
|
| 10 |
|
|
|
| 11 |
|
|
#include "meta.h" |
| 12 |
|
|
|
| 13 |
|
|
#include "plot.h" |
| 14 |
|
|
|
| 15 |
|
|
|
| 16 |
|
|
char *progname; |
| 17 |
|
|
|
| 18 |
|
|
static short newpage = TRUE; |
| 19 |
|
|
|
| 20 |
|
|
|
| 21 |
|
|
|
| 22 |
|
|
main(argc, argv) |
| 23 |
|
|
|
| 24 |
|
|
int argc; |
| 25 |
|
|
char **argv; |
| 26 |
|
|
|
| 27 |
|
|
{ |
| 28 |
|
|
FILE *fp; |
| 29 |
|
|
|
| 30 |
|
|
progname = *argv++; |
| 31 |
|
|
argc--; |
| 32 |
|
|
|
| 33 |
|
|
init(progname); |
| 34 |
|
|
if (argc) |
| 35 |
|
|
while (argc) { |
| 36 |
|
|
fp = efopen(*argv, "r"); |
| 37 |
|
|
plot(fp); |
| 38 |
|
|
fclose(fp); |
| 39 |
|
|
argv++; |
| 40 |
|
|
argc--; |
| 41 |
|
|
} |
| 42 |
|
|
else |
| 43 |
|
|
plot(stdin); |
| 44 |
|
|
|
| 45 |
|
|
if (!newpage) |
| 46 |
|
|
endpage(); |
| 47 |
|
|
|
| 48 |
|
|
done(); |
| 49 |
|
|
return(0); |
| 50 |
|
|
} |
| 51 |
|
|
|
| 52 |
|
|
|
| 53 |
|
|
|
| 54 |
|
|
|
| 55 |
|
|
plot(infp) /* plot meta-file */ |
| 56 |
|
|
|
| 57 |
|
|
FILE *infp; |
| 58 |
|
|
|
| 59 |
|
|
{ |
| 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 |
|
|
|
| 74 |
|
|
doglobal(g) /* execute a global command */ |
| 75 |
|
|
|
| 76 |
|
|
PRIMITIVE *g; |
| 77 |
|
|
|
| 78 |
|
|
{ |
| 79 |
|
|
FILE *fp; |
| 80 |
|
|
|
| 81 |
|
|
switch (g->com) { |
| 82 |
|
|
|
| 83 |
|
|
case PEOF: |
| 84 |
|
|
return(0); |
| 85 |
|
|
|
| 86 |
|
|
case PPAUSE: |
| 87 |
|
|
break; |
| 88 |
|
|
|
| 89 |
|
|
case PINCL: |
| 90 |
|
|
if (g->args == NULL) |
| 91 |
|
|
error(USER, "missing include file name in include"); |
| 92 |
|
|
if (g->arg0 == 2 || (fp = fopen(g->args, "r")) == NULL) |
| 93 |
|
|
if (g->arg0 != 0) |
| 94 |
|
|
fp = mfopen(g->args, "r"); |
| 95 |
|
|
else { |
| 96 |
|
|
sprintf(errmsg, "cannot open user include file \"%s\"", |
| 97 |
|
|
g->args); |
| 98 |
|
|
error(USER, errmsg); |
| 99 |
|
|
} |
| 100 |
|
|
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 |
|
|
|
| 145 |
|
|
doprim(p) /* plot primitive */ |
| 146 |
|
|
|
| 147 |
|
|
PRIMITIVE *p; |
| 148 |
|
|
|
| 149 |
|
|
{ |
| 150 |
|
|
|
| 151 |
|
|
switch (p->com) { |
| 152 |
|
|
|
| 153 |
|
|
case PMSTR: |
| 154 |
|
|
printstr(p); |
| 155 |
|
|
break; |
| 156 |
|
|
|
| 157 |
|
|
case PVSTR: |
| 158 |
|
|
plotvstr(p); |
| 159 |
|
|
break; |
| 160 |
|
|
|
| 161 |
|
|
case PLSEG: |
| 162 |
|
|
plotlseg(p); |
| 163 |
|
|
break; |
| 164 |
|
|
|
| 165 |
|
|
case PRFILL: |
| 166 |
|
|
fillrect(p); |
| 167 |
|
|
break; |
| 168 |
|
|
|
| 169 |
|
|
case PTFILL: |
| 170 |
|
|
filltri(p); |
| 171 |
|
|
break; |
| 172 |
|
|
|
| 173 |
|
|
case PPFILL: |
| 174 |
|
|
fillpoly(p); |
| 175 |
|
|
break; |
| 176 |
|
|
|
| 177 |
|
|
case PSEG: |
| 178 |
|
|
doseg(p); |
| 179 |
|
|
break; |
| 180 |
|
|
|
| 181 |
|
|
default: |
| 182 |
|
|
sprintf(errmsg, "unknown command '%c' in doprim", p->com); |
| 183 |
|
|
error(WARNING, errmsg); |
| 184 |
|
|
return; |
| 185 |
|
|
} |
| 186 |
|
|
newpage = FALSE; |
| 187 |
|
|
|
| 188 |
|
|
} |