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