--- ray/src/meta/xmeta.c 2003/11/17 02:21:53 1.3 +++ ray/src/meta/xmeta.c 2007/11/21 18:51:05 1.5 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: xmeta.c,v 1.3 2003/11/17 02:21:53 greg Exp $"; +static const char RCSid[] = "$Id: xmeta.c,v 1.5 2007/11/21 18:51:05 greg Exp $"; #endif /* * Program to output meta-files to X window system. @@ -10,9 +10,11 @@ static const char RCSid[] = "$Id: xmeta.c,v 1.3 2003/1 */ #include "rtprocess.h" +#include "string.h" #include "meta.h" #include "plot.h" +extern void init(char *name, char *geom); #define overlap(p,xmn,ymn,xmx,ymx) (ov((p)->xy[XMN],(p)->xy[XMX],xmn,xmx) \ &&ov((p)->xy[YMN],(p)->xy[YMX],ymn,ymx)) @@ -30,117 +32,10 @@ static PLIST recording; int maxalloc = 0; /* no limit */ +extern void pXFlush(void); -main(argc, argv) - -int argc; -char **argv; - -{ - FILE *fp; - char *geometry = NULL; - short condonly, conditioned; - char comargs[500], command[600]; - - progname = *argv++; - argc--; - - condonly = FALSE; - conditioned = FALSE; - - for ( ; argc; argv++, argc--) - if (!strcmp(*argv, "-c")) - condonly = TRUE; - else if (!strcmp(*argv, "-r")) - conditioned = TRUE; - else if (**argv == '=') - geometry = *argv; - else - break; - - if (conditioned) { - init(progname, geometry); - if (argc) - while (argc) { - fp = efopen(*argv, "r"); - plot(fp); - fclose(fp); - argv++; - argc--; - } - else - plot(stdin); - } else { - comargs[0] = '\0'; - while (argc) { - strcat(comargs, " "); - strcat(comargs, *argv); - argv++; - argc--; - } - sprintf(command, XCOM, comargs); - if (condonly) - return(system(command)); - else { - init(progname, geometry); - if ((fp = popen(command, "r")) == NULL) - error(SYSTEM, "cannot execute input filter"); - plot(fp); - pclose(fp); - } - } - - if (!newpage) - endpage(); - - return(0); - } - - - - void -plot(infp) /* plot meta-file */ - -FILE *infp; - -{ - PRIMITIVE nextp; - - set(SALL, NULL); - do { - readp(&nextp, infp); - while (isprim(nextp.com)) { - doprim(&nextp, 1); - readp(&nextp, infp); - } - doglobal(&nextp, 1); - } while (nextp.com != PEOF); - -} - - - -replay(xmin, ymin, xmax, ymax) /* play back region */ -int xmin, ymin, xmax, ymax; -{ - register PRIMITIVE *p; - - unset(SALL); - set(SALL, NULL); - for (p = recording.ptop; p != NULL; p = p->pnext) - if (isprim(p->com)) { - if (overlap(p, xmin, ymin, xmax, ymax)) - doprim(p, 0); - } else - doglobal(p, 0); - -} - - - - save(p) /* record primitive */ PRIMITIVE *p; { @@ -153,13 +48,10 @@ PRIMITIVE *p; } - - +void doglobal(g, sf) /* execute a global command */ - register PRIMITIVE *g; int sf; - { switch (g->com) { @@ -168,7 +60,7 @@ int sf; return; case PDRAW: - XFlush(); + pXFlush(); break; case PEOP: @@ -201,13 +93,10 @@ int sf; } - - +void doprim(p, sf) /* plot primitive */ - register PRIMITIVE *p; int sf; - { switch (p->com) { @@ -243,3 +132,105 @@ int sf; } } + + +void +plot(infp) /* plot meta-file */ +FILE *infp; +{ + PRIMITIVE nextp; + + set(SALL, NULL); + do { + readp(&nextp, infp); + while (isprim(nextp.com)) { + doprim(&nextp, 1); + readp(&nextp, infp); + } + doglobal(&nextp, 1); + } while (nextp.com != PEOF); + +} + + +void +replay(xmin, ymin, xmax, ymax) /* play back region */ +int xmin, ymin, xmax, ymax; +{ + register PRIMITIVE *p; + + unset(SALL); + set(SALL, NULL); + for (p = recording.ptop; p != NULL; p = p->pnext) + if (isprim(p->com)) { + if (overlap(p, xmin, ymin, xmax, ymax)) + doprim(p, 0); + } else + doglobal(p, 0); + +} + + +int +main(argc, argv) +int argc; +char **argv; +{ + FILE *fp; + char *geometry = NULL; + short condonly, conditioned; + char comargs[500], command[600]; + + progname = *argv++; + argc--; + + condonly = FALSE; + conditioned = FALSE; + + for ( ; argc; argv++, argc--) + if (!strcmp(*argv, "-c")) + condonly = TRUE; + else if (!strcmp(*argv, "-r")) + conditioned = TRUE; + else if (**argv == '=') + geometry = *argv; + else + break; + + if (conditioned) { + init(progname, geometry); + if (argc) + while (argc) { + fp = efopen(*argv, "r"); + plot(fp); + fclose(fp); + argv++; + argc--; + } + else + plot(stdin); + } else { + comargs[0] = '\0'; + while (argc) { + strcat(comargs, " "); + strcat(comargs, *argv); + argv++; + argc--; + } + sprintf(command, XCOM, comargs); + if (condonly) + return(system(command)); + else { + init(progname, geometry); + if ((fp = popen(command, "r")) == NULL) + error(SYSTEM, "cannot execute input filter"); + plot(fp); + pclose(fp); + } + } + + if (!newpage) + endpage(); + + return(0); + }