home *** CD-ROM | disk | FTP | other *** search
- /*
- * plot(1) clone. This filter implements the commands described in the
- * V7 UNIX manual pages, using the gl graphics library routines.
- *
- * Author: Wietse Venema (wietse@wzv.UUCP)
- *
- * Options: -Tdevice, where device is one of:
- *
- * cga (CGA) cga adapter, low (high) resolution
- * herc (HERC) hercules adapter, page 0 (page 1)
- * ega ega adapter
- * lp matrix printer
- * lj laserjet printer
- *
- * The output device can also be specified with the GLMODE environment
- * variable. See the gl graphics library documentation for details.
- */
-
- #include <stdio.h>
- #include <modes.h>
-
- static void confirm();
-
- /*
- * If the output device is specified on the command line we pass it on to
- * the gl library routines by setting the GLMODE environment variable...
- */
-
- struct Modetab {
- char *modename;
- int modeval;
- };
-
- struct Modetab modetab[] = {
- "cga", CGA_COLOR_MODE, /* cga lo-res */
- "CGA", CGA_HI_RES_MODE, /* cga hi-res */
- "herc", HERC_P0_MODE, /* hercules page 0 */
- "HERC", HERC_P1_MODE, /* hercules page 1 */
- "ega", EGA_COLOR_MODE, /* ega */
- "lp", IBM_PRINTER, /* matrix printer */
- "lj", LJ_PRINTER, /* laserjet printer */
- 0, 0,
- };
-
- /* various shorthands */
-
- #define READ(x) fread((char *) &x, sizeof(x), 1, stdin)
- #define READ2(a,b) READ(a); READ(b)
- #define READ3(a,b,c) READ2(a,b); READ(c)
- #define READ4(a,b,c,d) READ2(a,b); READ2(c,d);
- #define READ6(a,b,c,d,e,f) READ4(a,b,c,d); READ2(e,f);
-
- /*
- * Process the plotfile. The program terminates with a diagnostic
- * in case of unrecognized data.
- */
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- register struct Modetab *mp;
- register int c;
- char buf[BUFSIZ];
- int x, y, x0, y0, x1, y1, x2, y2, r, glmode;
- static char envstring[] = "GLMODE=xxxxxx";
-
- /* process command-line arguments */
-
- while (--argc && *++argv) {
- if (strncmp(*argv, "-T", 2) == 0) {
- for (mp = modetab; mp->modename; mp++) {
- if (strcmp(*argv + 2, mp->modename) == 0) {
- sprintf(envstring, "GLMODE=%d", glmode = mp->modeval);
- putenv(envstring);
- }
- }
- } else {
- fprintf(stderr, "bad argument: %s\n", *argv);
- exit(1);
- }
- }
-
- #ifndef unix
- you may have to select binary mode for stdin
- #endif
-
- /* process the plotfile */
-
- openpl();
-
- while ((c = getchar()) != EOF) {
- switch (c) {
- case 'm': /* move */
- READ2(x, y);
- move(x, y);
- break;
- case 'n': /* cont */
- READ2(x, y);
- cont(x, y);
- break;
- case 'p': /* point */
- READ2(x, y);
- point(x, y);
- break;
- case 'l': /* line */
- READ4(x1, y1, x2, y2);
- line(x1, y1, x2, y2);
- break;
- case 't': /* label */
- {
- register char *p = buf;
-
- while ((c = getchar()) != EOF && c)
- *p++ = c;
- *p = '\0';
- label(buf);
- }
- break;
- case 'a': /* arc */
- READ6(x, y, x0, y0, x1, y1);
- arc(x, y, x0, y0, x1, y1);
- break;
- case 'c': /* circle */
- READ3(x, y, r);
- circle(x, y, r);
- break;
- case 'e': /* erase */
- if (glmode <= MAXVIDEO)
- confirm();
- erase();
- break;
- case 'f': /* linemod */
- gets(buf);
- linemod(buf);
- break;
- case 's': /* space */
- READ4(x0, y0, x1, y1);
- space(x0, y0, x1, y1);
- break;
- default: /* corrupt */
- closepl();
- fprintf(stderr,"corrupted plotfile -- giving up\n");
- exit(1);
- /* NOTREACHED */
- }
- }
-
- if (glmode <= MAXVIDEO)
- confirm();
- closepl();
- exit(0);
- /* NOTREACHED */
- }
-
- /* give them a chance before erase() or closepl() clobber the screen */
-
- static void confirm()
- {
- FILE *fp;
- int c;
-
- if (fp = fopen("/dev/tty", "r")) {
- while ((c = getc(fp)) != EOF && c != '\n');
- fclose(fp);
- }
- }
-