[comp.sources.misc] v06i082: plot

allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (04/09/89)

Posting-number: Volume 6, Issue 82
Submitted-by: wietse@wzv.UUCP (Wietse Z. Venema)
Archive-name: plot.uport


These files implement UNIX plot(1,3,5) clones on top of the
PC/AT graphics library posted recently in comp.sources.unix
(v18i{059..065}, gl_plot/part{01..07} by dtlewis!lewis).

libplot.a:	library of plot(3) compatible functions that 
		produce files in plot(5) format.

plot:		filter that displays files in plot(5) format
		on a variety of devices (cga, hercules, ega,
		ibm graphics printer, laserjet).

This software was tested under Microport System-V/AT. No change
should be required for other PC UNIX versions (except for some
configuration parameters in the Makefile). Porting to non-UNIX
PC environments should be straightforward.

		Wietse Venema (wietse@wzv.UUCP).

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  README Makefile libplot.c plot.1 plot.c testplot.c
# Wrapped by wietse@wzv on Mon Mar 27 21:22:37 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1053 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XThese files implement UNIX plot(1,3,5) clones on top of the
XPC/AT graphics library posted recently in comp.sources.unix. 
X(v18i{059..065}, gl_plot/part{01..07} by dtlewis!lewis).
X
Xlibplot.a:	library of plot(3) compatible functions that 
X		produce files in plot(5) format.
X
Xplot:		filter that displays files in plot(5) format
X		on a variety of devices (cga, hercules, ega,
X		ibm graphics printer, laserjet).
X
XOptions to the plot program are of the form -Tdevice, where 
Xdevice is one of the following:
X
X	cga (CGA)	cga adapter, low (high) resolution
X	herc (HERC)	hercules adapter, page 0 (page 1)
X	ega		ega adapter
X	lp		matrix printer
X	lj		laserjet printer
X
XAlternatively, one may specify the output device type with the
XGLMODE environment variable (see the gl graphics library docs).
X
XThis software was tested under Microport System-V/AT. No change
Xshould be required for other PC UNIX versions (except for some
Xconfiguration parameters in the Makefile). Porting to non-UNIX
XPC environments should be straightforward.
X
X		Wietse Venema (wietse@wzv.UUCP).
END_OF_FILE
if test 1053 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(783 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# location of directory with gl source (modes.h)
XGLMODES	= $$HOME/net/gl
X
X# gl library memory model
X# GLMODEL	= -Ml	for Microport System-V/AT
X# GLMODEL	= 	for other systems
XGLMODEL	= -Ml
X
X# gl library location
X# GLLIB	= /usr/local/lib/gl.a
XGLLIB	= -L/usr/local/lib -lgl
X
X# end of configurations options
X
XSHELL	= /bin/sh
XCFLAGS	= -g
XFILES	= README Makefile libplot.c plot.1 plot.c testplot.c
X
Xall: plot libplot.a
X
Xplot:	plot.o
X	$(CC) $(GLMODEL) $(CFLAGS) -o plot plot.o $(GLLIB) -lm
X
Xplot.o:	plot.c
X	$(CC) $(GLMODEL) $(CFLAGS) -I$(GLMODES) -c plot.c
X
Xlibplot.a: libplot.o
X	ar rv libplot.a libplot.o
X
Xtestplot: testplot.o libplot.a
X	$(CC) $(CFLAGS) -o testplot testplot.o libplot.a
X
Xshar:	$(FILES)
X	@shar $(FILES)
X
Xclean:
X	rm -f *.o core testplot
X
Xclobber: clean
X	rm -f plot libplot.a
END_OF_FILE
if test 783 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'libplot.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'libplot.c'\"
else
echo shar: Extracting \"'libplot.c'\" \(1301 characters\)
sed "s/^X//" >'libplot.c' <<'END_OF_FILE'
X/*
X * plot(3) clone. Implements the commands described in the the V7 UNIX 
X * manual pages and produces a standard UNIX plotfile. 
X *
X * The resulting plotfile is to be used with the plot(1) command.
X *
X * Author: Wietse Venema (wietse@wzv.UUCP)
X */
X
X#include <stdio.h>
X
X/* some shorthands... */
X
X#define	Write(x)		fwrite((char *) &x, sizeof(x), 1, stdout)
X#define	Write2(a,b)		Write(a); Write(b)
X#define	Write3(a,b,c)		Write2(a,b); Write(c)
X#define	Write4(a,b,c,d)		Write2(a,b); Write2(c,d)
X#define	Write6(a,b,c,d,e,f)	Write4(a,b,c,d); Write2(e,f)
X
Xopenpl()
X{
X#ifndef unix
X    you may have to select binary mode for stdout
X#endif
X}
X
Xmove(x, y)
X{
X    putchar('m');
X    Write2(x, y);
X}
X
Xcont(x, y)
X{
X    putchar('n');
X    Write2(x, y);
X}
X
Xpoint(x, y)
X{
X    putchar('p');
X    Write2(x, y);
X}
X
Xline(x1, y1, x2, y2)
X{
X    putchar('l');
X    Write4(x1, y1, x2, y2);
X}
X
Xlabel(s)
Xchar           *s;
X{
X    putchar('t');
X    fputs(s,stdout);
X    putchar('\0');
X}
X
Xarc(x, y, x0, y0, x1, y1)
X{
X    putchar('a');
X    Write6(x, y, x0, y0, x1, y1);
X}
X
Xcircle(x, y, r)
X{
X    putchar('c');
X    Write3(x, y, r);
X}
X
Xerase()
X{
X    putchar('e');
X}
X
Xlinemod(s)
Xchar           *s;
X{
X    putchar('f');
X    puts(s);
X}
X
Xspace(x0, y0, x1, y1)
X{
X    putchar('s');
X    Write4(x0, y0, x1, y1);
X}
X
Xclosepl()
X{
X    fflush(stdout);
X}
END_OF_FILE
if test 1301 -ne `wc -c <'libplot.c'`; then
    echo shar: \"'libplot.c'\" unpacked with wrong size!
fi
# end of 'libplot.c'
fi
if test -f 'plot.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'plot.1'\"
else
echo shar: Extracting \"'plot.1'\" \(997 characters\)
sed "s/^X//" >'plot.1' <<'END_OF_FILE'
X.TH PLOT 1
X.SH NAME
Xplot -\ display plot files on various output devices
X.SH SYNOPSIS
Xplot [-Tdevice]
X.SH DESCRIPTION
X.ad
XThe plot filter emulates the commands described in the
XV7 UNIX Programmers Manual, using routines provided by 
Xthe gl PC/AT-clone graphics library. The following output 
Xdevices may be specified:
X.TP
Xcga
XCGA graphics adapter, low-resolution mode
X.TP
XCGA
XCGA graphics adapter, high-resolution mode
X.TP
Xherc
XHercules graphics adapter, page 0
X.TP
XHERC
XHercules graphics adapter, page 1
X.TP
Xega
XEGA graphics adapter
X.TP
Xlp
XIBM graphics printer
X.TP
Xlj
XLaserJet printer
X.SH ENVIRONMENT
XGLMODE, default output device type
X.SH SEE ALSO
X.nf
X.na
Xplot(1), plot(3), plot(5) in the UNIX Programmers Manual.
Xgl graphics library documentation.
X.SH DIAGNOSTICS
X.ad
XThe plot filter terminates with a diagnostic if it finds
Xunexpected input.
X.SH AUTHOR
X.nf
X.na
XWietse Venema (wietse@wzv.UUCP)
XMathematics and Computing Science,
XEindhoven University of Technology,
XEindhoven, The Netherlands.
X
END_OF_FILE
if test 997 -ne `wc -c <'plot.1'`; then
    echo shar: \"'plot.1'\" unpacked with wrong size!
fi
# end of 'plot.1'
fi
if test -f 'plot.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'plot.c'\"
else
echo shar: Extracting \"'plot.c'\" \(3816 characters\)
sed "s/^X//" >'plot.c' <<'END_OF_FILE'
X/*
X * plot(1) clone. This filter implements the commands described in the 
X * V7 UNIX manual pages, using the gl graphics library routines.
X *
X * Author: Wietse Venema (wietse@wzv.UUCP)
X *
X * Options: -Tdevice, where device is one of:
X *
X *	cga (CGA)	cga adapter, low (high) resolution
X *	herc (HERC)	hercules adapter, page 0 (page 1)
X *	ega		ega adapter
X *	lp		matrix printer 
X *	lj		laserjet printer
X *
X * The output device can also be specified with the GLMODE environment
X * variable. See the gl graphics library documentation for details.
X */
X
X#include <stdio.h>
X#include <modes.h>
X
Xstatic void     confirm();
X
X/*
X * If the output device is specified on the command line we pass it on to
X * the gl library routines by setting the GLMODE environment variable...
X */
X
Xstruct Modetab {
X    char           *modename;
X    int             modeval;
X};
X
Xstruct Modetab  modetab[] = {
X    "cga",	CGA_COLOR_MODE,		/* cga lo-res */
X    "CGA",	CGA_HI_RES_MODE,	/* cga hi-res */
X    "herc",	HERC_P0_MODE,		/* hercules page 0 */
X    "HERC",	HERC_P1_MODE,		/* hercules page 1 */
X    "ega",	EGA_COLOR_MODE,		/* ega */
X    "lp",	IBM_PRINTER,		/* matrix printer */
X    "lj",	LJ_PRINTER,		/* laserjet printer */
X    0, 0,
X};
X
X/* various shorthands */
X
X#define	READ(x)			fread((char *) &x, sizeof(x), 1, stdin)
X#define	READ2(a,b)		READ(a); READ(b)
X#define	READ3(a,b,c)		READ2(a,b); READ(c)
X#define	READ4(a,b,c,d)		READ2(a,b); READ2(c,d);
X#define	READ6(a,b,c,d,e,f)	READ4(a,b,c,d); READ2(e,f);
X
X/* 
X * Process the plotfile. The program terminates with a diagnostic
X * in case of unrecognized data.
X */
X
Xmain(argc, argv)
Xint             argc;
Xchar          **argv;
X{
X    register struct Modetab *mp;
X    register int    c;
X    char            buf[BUFSIZ];
X    int             x, y, x0, y0, x1, y1, x2, y2, r, glmode;
X    static char     envstring[] = "GLMODE=xxxxxx";
X
X    /* process command-line arguments */
X
X    while (--argc && *++argv) {
X	if (strncmp(*argv, "-T", 2) == 0) {
X	    for (mp = modetab; mp->modename; mp++) {
X		if (strcmp(*argv + 2, mp->modename) == 0) {
X		    sprintf(envstring, "GLMODE=%d", glmode = mp->modeval);
X		    putenv(envstring);
X		}
X	    }
X	} else {
X	    fprintf(stderr, "bad argument: %s\n", *argv);
X	    exit(1);
X	}
X    }
X
X#ifndef	unix
X    you may have to select binary mode for stdin
X#endif
X
X    /* process the plotfile */
X
X    openpl();
X
X    while ((c = getchar()) != EOF) {
X	switch (c) {
X	case 'm':				/* move */
X	    READ2(x, y);
X	    move(x, y);
X	    break;
X	case 'n':				/* cont */
X	    READ2(x, y);
X	    cont(x, y);
X	    break;
X	case 'p':				/* point */
X	    READ2(x, y);
X	    point(x, y);
X	    break;
X	case 'l':				/* line */
X	    READ4(x1, y1, x2, y2);
X	    line(x1, y1, x2, y2);
X	    break;
X	case 't':				/* label */
X	    {
X		register char  *p = buf;
X
X		while ((c = getchar()) != EOF && c)
X		    *p++ = c;
X		*p = '\0';
X		label(buf);
X	    }
X	    break;
X	case 'a':				/* arc */
X	    READ6(x, y, x0, y0, x1, y1);
X	    arc(x, y, x0, y0, x1, y1);
X	    break;
X	case 'c':				/* circle */
X	    READ3(x, y, r);
X	    circle(x, y, r);
X	    break;
X	case 'e':				/* erase */
X	    if (glmode <= MAXVIDEO)
X		confirm();
X	    erase();
X	    break;
X	case 'f':				/* linemod */
X	    gets(buf);
X	    linemod(buf);
X	    break;
X	case 's':				/* space */
X	    READ4(x0, y0, x1, y1);
X	    space(x0, y0, x1, y1);
X	    break;
X	default:				/* corrupt */
X	    closepl();
X	    fprintf(stderr,"corrupted plotfile -- giving up\n");
X	    exit(1);
X	    /* NOTREACHED */
X	}
X    }
X
X    if (glmode <= MAXVIDEO)
X	confirm();
X    closepl();
X    exit(0);
X    /* NOTREACHED */
X}
X
X/* give them a chance before erase() or closepl() clobber the screen */
X
Xstatic void     confirm()
X{
X    FILE           *fp;
X    int             c;
X
X    if (fp = fopen("/dev/tty", "r")) {
X	while ((c = getc(fp)) != EOF && c != '\n');
X	fclose(fp);
X    }
X}
END_OF_FILE
if test 3816 -ne `wc -c <'plot.c'`; then
    echo shar: \"'plot.c'\" unpacked with wrong size!
fi
# end of 'plot.c'
fi
if test -f 'testplot.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'testplot.c'\"
else
echo shar: Extracting \"'testplot.c'\" \(552 characters\)
sed "s/^X//" >'testplot.c' <<'END_OF_FILE'
X/* test program for the UNIX plot clones */
X
X#define	SIZE	100
X
Xmain()
X{
X    register int    i;
X
X    openpl();
X
X    space(0, 0, SIZE, SIZE);
X
X    circle(SIZE / 4, SIZE / 4, SIZE / 4);
X
X    move(1, SIZE - 1);
X
X    cont(SIZE - 1, 1);
X
X    for (i = 1; i < SIZE; i++)
X	point(i, i);
X
X    arc(SIZE-25, SIZE-25, SIZE-25, SIZE, SIZE, SIZE-25);
X
X    linemod("dotted");
X
X    move(10, SIZE - 1);
X
X    label("Testing");
X
X    line(0, 0, 0, SIZE);
X    line(0, SIZE, SIZE, SIZE);
X    line(SIZE, SIZE, SIZE, 0);
X    line(SIZE, 0, 0, 0);
X
X    closepl();
X
X    exit(0);
X}
END_OF_FILE
if test 552 -ne `wc -c <'testplot.c'`; then
    echo shar: \"'testplot.c'\" unpacked with wrong size!
fi
# end of 'testplot.c'
fi
echo shar: End of shell archive.
exit 0
-- 
work:	wswietse@eutrc3.uucp	| Eindhoven University of Technology
work:	wswietse@heitue5.bitnet	| Mathematics and Computing Science
home:	wietse@wzv.uucp		| 5600 MB Eindhoven, The Netherlands