PD plot(4) librarys (and hercules driver for interactive 386) part 8 of 9

Roland van Hout hot at integow.uucp
Sun Oct 28 14:58:19 AEST 1990



#!/bin/sh
# This is part 08 of a multipart archive
if touch 2>&1 | fgrep '[-amc]' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= herc/herc.h ==============
echo "x - extracting herc/herc.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > herc/herc.h &&
Xstatic char SCCS_HERCH[] = "%W% %G% %U%";
X/* 
X++++ 
X	herc.h 
X 
X	PURPOSE : Hercules Graphics constants and macros
X
X	AUTHOR  : W. Hatch   
X
X	COMPANY	: Computational Engineering
X		  14504 Greenview Drive Suite 500
X		  Laurel, Maryland 20708
X		  301-470-3839
X		  usrnet: uunet!bts!bill
X
X	DATE	: 2/4/90
X
X	CREDITS : I got useful information from all of the following
X		  sources which I wish to acknowledge and thank.  
X
X		1.) David B. Dotty, "Programmers Guide To The Hercules
X		    Graphics Card", Addison-Wesley, 1988,
X
X		2.) Dan Schechter, "How To Access The Hercules Graphics
X		    Plane", The C Users Journal, August, 1988,
X
X		3.) geb, port (sample Hercules graphics driver)
X		    1988, Reynolds Metals Co., PO Box 1200,
X		    Sheffield, Al. 35660,  (205)-386-9657,
X
X		4.) David T. Lewis, mode.c from gnuplot, 7/13/87,
X
X		5.) Jeffery A. Turner, setmode.c, (Hercules mode set for
X		    Everix), 5/20/87,
X
X		6.) Janet I. Egan and Thomas J. Teixeira, "Writing a Unix
X		    Device Driver", Wiley, 1988,
X
X		7.) "Software Development System Volume I", Microport
X		    V386/3.0e,
X
X		8.) Microport Tech Support System V386 Dos Merge 386
X		    Version 1.1.1U, 12/15/88,
X
X		9.) Microport documentation on Display(7) forwarded
X		    by Bob Courtney, uunet!agc!courtney, August, 1989,
X
X		10.) Cliff Flint, sample Hercules driver code,
X		     uunet!ames!mailrus!umix!clif!clif, April, 1989,
X
X		11.) Machael Gordon and Colon Kelly, hercgraph.asm,
X		     Hercules graphics code for MS-DOS gnuplot,
X		     December, 1986.
X
X---*/ 
X/*
X------------------------------------------------------------------------
X  MODIFICATIONS
XDATE-PROGRAMMER	DESCRIPTION
X------------------------------------------------------------------------
X*/
X#include <sys/types.h>
X#include <sys/dir.h>
X#include <sys/signal.h>
X#include <sys/param.h>
X#include <stdio.h>
X#include <sys/user.h>
X#include <fcntl.h>
X#include <sys/file.h>
X#include <sys/ioctl.h>
X#ifndef IX386
X#include <sys/io_op.h>
X#endif
X/*----------------------------------------------------------------------*/
X/* values returned by driver functions					*/
X/*----------------------------------------------------------------------*/
X#define SUCCESS 0
X#define FAILURE (-1)
X
X/*----------------------------------------------------------------------*/
X/* system constants used by kernel functions				*/
X/*----------------------------------------------------------------------*/
X#define IPC_FLAG	(IPC_CREAT|00666)
X#define PG_P		0x00000001	/* page present bit	*/
X
X/*----------------------------------------------------------------------*/
X/* herc page physical base addresses and sizes in units of 4096 bytes	*/
X/*----------------------------------------------------------------------*/
X#define HERC_TEXT_PAGE	176
X#define	HERC_PAGE_0	176
X#define HERC_PAGE_1	184
X#define	HERC_SIZE	8
X
X/*----------------------------------------------------------------------*/
X/* herc base addresses and sizes in bytes				*/
X/*----------------------------------------------------------------------*/
X#define	HERC_TEXT_BUF	0xB000
X#define HERC_P0_BUF	0xB000
X#define HERC_P1_BUF	0xB800
X
X#define HERC_PAGE_BYTES	32768
X
X/*----------------------------------------------------------------------*/
X/* error message macro							*/
X/*----------------------------------------------------------------------*/
X#define KERROR(a)	printf("ERROR herc: %s\n",a);
X
X/*----------------------------------------------------------------------*/
X/* herc ioctl commands and data structure for ioctl(dev, cmd, arg)	*/
X/*----------------------------------------------------------------------*/
X	/* cmd values */
X#	define	SET_PIXEL	2
X#	define	CLEAR_PIXEL	3
X#	define	REVERSE_PIXEL	4
X#	define	CLEAR_SCREEN_0	5
X#	define	CLEAR_SCREEN_1	6
X#	define	SWITCH_SCREEN_0	7
X#	define	SWITCH_SCREEN_1	8
X
X	/* HERC arg (a data structure) */
X	typedef struct s_hercio {
X		int	cmd;
X		int	phys_x;
X		int	phys_y;
X		} HERC;
X#	define NO_HERC	(HERC *)0
X#	define VALIDHERC(a)	((a) != NO_HERC)
X
X/*----------------------------------------------------------------------*/
X/* ports and byte values to put to ports				*/
X/*----------------------------------------------------------------------*/
X#define CONFIG_SWITCH		0x3bf
X#	define CF_TEXT_ONLY	0	/* default, prevents graphics	*/
X#	define CF_PAGE_0	01	/* enable page 0 only		*/
X#	define CF_PAGE_1	03	/* enable both pages		*/
X
X#define	INDEX_REG_6845		0x3b4	/* 6845 index register		*/
X#define	DATA_REG_6845		0x3b5	/* 6845 data register		*/
X
X#define	DMC_PORT		0x3b8	/* display mode control port	*/
X#	define	DMC_TEXT	00	/* default, text display mode	*/
X#	define	DMC_GRAPHICS	02	/* graphics display mode	*/
X#	define	DMC_OFF_SCREEN	000
X#	define	DMC_ON_SCREEN	010
X#	define	DMC_ON_BLINK	040
X#	define	DMC_OFF_BLINK	000
X#	define	DMC_PAGE_0	000	/* dmc show page 0		*/
X#	define	DMC_PAGE_1	0200	/* dmc show page 1		*/
X
X/* text mode */
X#	define	NORMAL		007
X#	define INTENSITY	010
X#	define	BLANK		000
X#	define UNDERLINE	001
X#	define REVERSE_VIDEO	0160
X#	define BLINK		0200
X
X#define DS_PORT 		0x3ba	/* display status port		*/
X#	define DS_RETRACE	0x80	/* retrace is when bit 7 is 0	*/
X/*----------------------------------------------------------------------*/
X/* graphics memory byte location and bit manipulation			*/
X/*----------------------------------------------------------------------*/
X	/* physical screen dimensions					*/
X	/*--------------------------------------------------------------*/
X#	define	PHYS_X_MIN	0
X#	define	PHYS_X_MAX	719
X#	define  PHYS_Y_MIN	0
X#	define	PHYS_Y_MAX	347
X	/*--------------------------------------------------------------*/
X	/* given x, y coordinates, determine byte offset within screen	*/
X	/* memory							*/
X	/*--------------------------------------------------------------*/
X#	define	BYTE_OFFSET(x,y) (unsigned)(0x2000 * ((y)%4) + \
X			90 * ((y)/4) + (x)/8)
X
X	/*--------------------------------------------------------------*/
X	/* for given x coordinate, generate a byte with the correct 	*/
X	/* bit set							*/
X	/*--------------------------------------------------------------*/
X#	define	X_BIT(x)	(1 << (7-((x)%8)))
X
X	/*--------------------------------------------------------------*/
X	/* set, clear, reverse bit for given x within a given byte	*/
X	/*--------------------------------------------------------------*/
X#	define	SET_BIT(byte,x)	((byte) |= (X_BIT((x))))
X#	define	CLEAR_BIT(byte,x) ((byte) &= (unsigned char)0xff ^ (X_BIT(x)))
X#	define	REVERSE_BIT(byte,x) ((byte) ^= (X_BIT(x) ))
SHAR_EOF
$TOUCH -am 1014123490 herc/herc.h &&
chmod 0644 herc/herc.h ||
echo "restore of herc/herc.h failed"
set `wc -c herc/herc.h`;Wc_c=$1
if test "$Wc_c" != "6396"; then
	echo original size 6396, current size $Wc_c
fi
# ============= herc/test.c ==============
echo "x - extracting herc/test.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > herc/test.c &&
X/*======================================================================*/
X/* test - test features of herc driver					*/
X/* W Hatch 2/17/90							*/
X/*======================================================================*/
X#include <stdio.h>
X#include "herc.h"
X#define delay sleep
X
Xint	hercfd;
Xmain()
X{
X	int i;
X	int j;
X	HERC Herc;
X	char buffer[4];
X	if((hercfd = open("/dev/herc", O_WRONLY)) < 0)
X	{
X		perror("main: open /dev/herc failed");
X		exit(2);
X	}
X	/*--------------------------------------------------------------*/
X	/* test SET_PIXEL with a pattern				*/
X	/*--------------------------------------------------------------*/
X	Herc.cmd = SET_PIXEL;
X	pattern(&Herc);
X	sleep(5);
X	/*--------------------------------------------------------------*/
X	/* test CLEAR_PIXEL by removing test pattern			*/
X	/*--------------------------------------------------------------*/
X	Herc.cmd = CLEAR_PIXEL;
X	pattern(&Herc);
X	sleep(5);
X	/*--------------------------------------------------------------*/
X	/* test REVERSE_PIXEL with same pattern				*/
X	/*--------------------------------------------------------------*/
X	Herc.cmd = REVERSE_PIXEL;
X	pattern(&Herc);
X	sleep(5);
X	pattern(&Herc);
X	sleep(5);
X	close(hercfd);
X	printf("hercfd: %d\n",hercfd);
X	exit(0);
X
X}
Xpattern(Herc)
XHERC *Herc;
X{
X	int i,j;
X	for(j=100; j< 200 ; j++)
X	{
X		for(i=100; i< 110; i++)
X		{
X			Herc->phys_x = j;
X			Herc->phys_y = i;
X			if(write(hercfd, Herc, sizeof(HERC)) < 0)
X			{
X				perror("main: write hercfd failed");
X				exit(2);
X			}
X		}
X		for(i=100; i< 110; i++)
X		{
X			Herc->phys_y = j;
X			Herc->phys_x = i;
X			if(write(hercfd, Herc, sizeof(HERC)) < 0)
X			{
X				perror("main: write hercfd failed");
X				exit(2);
X			}
X		}
X	}
X}
SHAR_EOF
$TOUCH -am 1013182190 herc/test.c &&
chmod 0644 herc/test.c ||
echo "restore of herc/test.c failed"
set `wc -c herc/test.c`;Wc_c=$1
if test "$Wc_c" != "1690"; then
	echo original size 1690, current size $Wc_c
fi
# ============= herc/ix386/n_herc ==============
if test ! -d 'herc/ix386'; then
    echo "x - creating directory herc/ix386"
    mkdir 'herc/ix386'
fi
echo "x - extracting herc/ix386/n_herc (Text)"
sed 's/^X//' << 'SHAR_EOF' > herc/ix386/n_herc &&
Xherc	herc	c	0
SHAR_EOF
$TOUCH -am 1014120790 herc/ix386/n_herc &&
chmod 0644 herc/ix386/n_herc ||
echo "restore of herc/ix386/n_herc failed"
set `wc -c herc/ix386/n_herc`;Wc_c=$1
if test "$Wc_c" != "14"; then
	echo original size 14, current size $Wc_c
fi
# ============= herc/ix386/s_herc ==============
echo "x - extracting herc/ix386/s_herc (Text)"
sed 's/^X//' << 'SHAR_EOF' > herc/ix386/s_herc &&
Xherc	Y	1	0	0	0	0	0	0	0
SHAR_EOF
$TOUCH -am 1014123690 herc/ix386/s_herc &&
chmod 0644 herc/ix386/s_herc ||
echo "restore of herc/ix386/s_herc failed"
set `wc -c herc/ix386/s_herc`;Wc_c=$1
if test "$Wc_c" != "23"; then
	echo original size 23, current size $Wc_c
fi
# ============= herc/ix386/mdevice ==============
echo "x - extracting herc/ix386/mdevice (Text)"
sed 's/^X//' << 'SHAR_EOF' > herc/ix386/mdevice &&
X
Xherc	ocrwi	iHcr	herc	0	15	1	1	-1
X       you have to add the following line to the file /etc/conf/cf.d/mdevice:
X
X       herc	Iocrwi	iHct	herc	0	15	1	16	-1
X
SHAR_EOF
$TOUCH -am 1014121390 herc/ix386/mdevice &&
chmod 0644 herc/ix386/mdevice ||
echo "restore of herc/ix386/mdevice failed"
set `wc -c herc/ix386/mdevice`;Wc_c=$1
if test "$Wc_c" != "156"; then
	echo original size 156, current size $Wc_c
fi
# ============= herc/ix386/README ==============
echo "x - extracting herc/ix386/README (Text)"
sed 's/^X//' << 'SHAR_EOF' > herc/ix386/README &&
Xcopy s_herc to /etc/conf/sdevice.d/herc
Xcopy n_herc to /etc/conf/node.d/herc
Xadd the first line in mdevice to /etc/conf/cf.d/mdevice
Xcompile the source and copy it to /etc/conf/pack.d/herc/Driver.o
Xof course you will have to create the directory first!
SHAR_EOF
$TOUCH -am 1014194190 herc/ix386/README &&
chmod 0644 herc/ix386/README ||
echo "restore of herc/ix386/README failed"
set `wc -c herc/ix386/README`;Wc_c=$1
if test "$Wc_c" != "253"; then
	echo original size 253, current size $Wc_c
fi
# ============= README ==============
echo "x - extracting README (Text)"
sed 's/^X//' << 'SHAR_EOF' > README &&
XThis directory tree contains a collection of PD graphic drivers.
XAll of them support the plot(4) definition of ATT, well they support
Xthem more or less. Most of the drivers don't have bit patterns,
Xcircles and arcs built in. So if you have a lot of time here is 
Xsomething to do!!!
XAlso included is a driver programm for plot. So you can now install
Xa runnable driver in /usr/lib add a line to your /usr/bin/tplot script
Xand with sag -Therc  or any suitable name for the new driver you
Xcan plot an activity graph on you screen or printer.
XThe driver program was written by Wietse Venema and changed for
X386 Unix 3.xxx by Bill Hatch, I made minor changes for the
Xprinterdriver.
XSomething like sag -Thplj could also immediately spool the output
Xto lp if the line in /usr/bin/tplot is appropriate.
XRemember most of this is a collection so other people wrote it,
Xtheir names and e-mail/mail adresses can be found in the corresponding
Xdirectories.
XThe REGIS stuff and the adaption of the hpgl converter to a plot
Xlibrary for (hplj,epson,ibm) is my work, also I optimized the
Xhplj output with cursor adressing.
XThe hpgl converter was posted by the Environmental Defense Fund in
X1988, they have the copyright on this source but allowed me 
Xto repost this!
XOk I know it's a terrible hack, but it works.
XAny changes or ideas or other PD plot librarys to hout at hot.mug.
XAny PD applications that use plot (gnuplot/fchart I already 
Xhave) are welcome too.
XAlso I've build a plot interface for the CGI library of SCO.
XIn the tplot entry you should not forget to set the
Xenvironment variables for your outputdevices for the CGI library.
XXenix doesnot have a tplot or sag programm it has no graphics but
Xthe CGI and no system activity reports, as far as I know.
XSCO Unix should have sag, tplot and system activity data 
Xand the CGI library, but I don't have a SCO Unix yet.
XAlso Included is the hercules driver posted to comp.unix.ix386 some
Xweeks ago, originally it was a driver for uPort 386 unix, I added
Xthe files for Interactive 386 V.3.2.0.2 but it should also work
Xon 2.2.
XThe guy who posted it was Bill Hatch, I didnot find any copyrights
Xso I guess its alright if I repost this with my interactive 
Xchanges.
XAlso included is a plot library for sun 3 workstations from 
XSjoerd Mullenders, Sjoerd has the copyright but it's allowed
Xto redistribute this if you leave the copyright message in.
XThen I have 2 other plotlibs for HPGL 7440 and for a DEC LN03 
Xlaserprinter.
XThe HPGL stuff was written by Dave Trueman and Henry Spencer
Xfrom Toronto. 
XThere was no copyright in the sources so I guess it's ok if I
Xrepost this.
XThe ln03 stuff was copyrighted by Nicolas Christopher from
XColumbia University but it didnot say it was allowed to 
Xredistribute this so it's not included.
XAlso I have a hercules driver for uPort V.2.3 which was posted
Xand copyrighted by Microport so this one is not included as well.
XIf the people who have the rights on the uport and ln03 stuff
Xcould mail me I that they would allow me to repost these 
X2 parts. I would post them in a few weeks.
X
X
SHAR_EOF
$TOUCH -am 1026190890 README &&
chmod 0644 README ||
echo "restore of README failed"
set `wc -c README`;Wc_c=$1
if test "$Wc_c" != "3061"; then
	echo original size 3061, current size $Wc_c
fi
# ============= plot.c ==============
echo "x - extracting plot.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > plot.c &&
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 at 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/* changes to provide compatibility with Microport V386 3.0e
X * W Hatch  uunet!bts!bill
X * 2/18/90
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#ifdef V386		/* 16 bit integers output by uport V386 graph(1) */
X#define	READ(x)			fread((char *) &s_x, sizeof(s_x), 1, stdin);\
X					x=s_x
X#else
X#define	READ(x)			fread((char *) &x, sizeof(x), 1, stdin)
X#endif
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#ifdef V386
X    short int       s_x, s_y, s_x0, s_y0, s_x1, s_y1, s_x2, s_y2, s_r, s_glmode;
X#endif
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#ifdef DBUG
X	fprintf(stderr, "c= %c, c(int)= %d\n",c,c);
X	fflush(stderr);
X#endif
X	switch (c) {
X	case 'm':				/* move */
X	    READ2(x, y);
X#ifdef DBUG
X	    fprintf(stderr, "x: %d, y: %d\n", x, y);
X	    fflush(stderr);
X#endif
X	    move(x, y);
X	    break;
X	case 'n':				/* cont */
X	    READ2(x, y);
X#ifdef DBUG
X	    fprintf(stderr, "x: %d, y: %d\n", x, y);
X	    fflush(stderr);
X#endif
X	    cont(x, y);
X	    break;
X	case 'p':				/* point */
X	    READ2(x, y);
X#ifdef DBUG
X	    fprintf(stderr, "x: %d, y: %d\n", x, y);
X	    fflush(stderr);
X#endif
X	    point(x, y);
X	    break;
X	case 'l':				/* line */
X	    READ4(x1, y1, x2, y2);
X#ifdef DBUG
X	    fprintf(stderr, "x1: %d, y1: %d, x2: %d, y2: %d\n", x1, y1,x2,y2);
X	    fflush(stderr);
X#endif
X	    line(x1, y1, x2, y2);
X	    break;
X	case 't':				/* label */
X	    {
X		register char  *p = buf;
X
X		/********
X		while ((c = getchar()) != EOF && c)
X		    *p++ = c;
X		*p = '\0';
X		weh  2/18/90  --- incoming string is newline terminated
X		********/
X		gets(buf);
X		label(buf);
X	    }
X#ifdef DBUG
X	    fprintf(stderr, "label: %s\n", buf);
X	    fflush(stderr);
X#endif
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#ifdef DBUG
X	    fprintf(stderr, "x0: %d, y0: %d, x1: %d, y1: %d\n", x0, y0,x1,y1);
X	    fflush(stderr);
X#endif
X	    space(x0, y0, x1, y1);
X	    break;
X				/* corrupt */
X	default:
X	    closepl();
X	    fprintf(stderr,"c= %c, %d corrupted plotfile -- giving up\n",c,c);
X	    fflush(stderr);
X	    exit(1);
X	}; /* end switch */
X    } /* end while */
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}
SHAR_EOF
$TOUCH -am 1014123990 plot.c &&
chmod 0644 plot.c ||
echo "restore of plot.c failed"
set `wc -c plot.c`;Wc_c=$1
if test "$Wc_c" != "4963"; then
	echo original size 4963, current size $Wc_c
fi
# ============= lpdriver.c ==============
echo "x - extracting lpdriver.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > lpdriver.c &&
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 at 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/* changes to provide compatibility with Microport V386 3.0e
X * W Hatch  uunet!bts!bill
X * 2/18/90
X */
X/*
Xchanges to get it running on interactive 386
XR.P. van Hout uunet!mcsun!hp4nl!integow!hot!hot
X*/
X
X
X#include "plotlpus.h"
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 */
Xfloat deltx = 4095.0;
Xfloat delty = 4095.0;
X
Xstruct Modetab {
X    char           *modename;
X    int             modeval;
X};
X
Xstruct Modetab  modetab[] = {
X#ifdef bla
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#endif
X    0, 0,
X};
X
X/* various shorthands */
X#ifdef V386		/* 16 bit integers output by uport V386 graph(1) */
X#define	READ(x)			fread((char *) &s_x, sizeof(s_x), 1, stdin);\
X					x=s_x
X#else
X#define	READ(x)			fread((char *) &x, sizeof(x), 1, stdin)
X#endif
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#ifdef V386
X    short int       s_x, s_y, s_x0, s_y0, s_x1, s_y1, s_x2, s_y2, s_r, s_glmode;
X#endif
X    static char     envstring[] = "GLMODE=xxxxxx";
X    int noconfirm;
X	noconfirm = 0;
X    /* process command-line arguments */
X
X	while(argc-- > 1) {
X		if(*argv[1] == '-')
X			switch(argv[1][1]) {
X				case 'l':
X					deltx = atoi(&argv[1][2]) - 1;
X					break;
X				case 'w':
X					delty = atoi(&argv[1][2]) - 1;
X					break;
X				case 's':
X					printer=LASERLOW;
X					break;
X				case 'm':
X					printer=LASERMED;
X					break;
X				case 'h':
X					printer=LASERHIGH;
X					break;
X				case 'i':
X					printer=IBM_PRO;
X					break;
X				case 'e':
X					printer=EPSON;
X					break;
X				}
X
X		argv++;
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#ifdef DBUG
X	fprintf(stderr, "c= %c, c(int)= %d\n",c,c);
X	fflush(stderr);
X#endif
X	switch (c) {
X	case 'm':				/* move */
X	    READ2(x, y);
X#ifdef DBUG
X	    fprintf(stderr, "x: %d, y: %d\n", x, y);
X	    fflush(stderr);
X#endif
X	    move(x, y);
X	    break;
X	case 'n':				/* cont */
X	    READ2(x, y);
X#ifdef DBUG
X	    fprintf(stderr, "x: %d, y: %d\n", x, y);
X	    fflush(stderr);
X#endif
X	    cont(x, y);
X	    break;
X	case 'p':				/* point */
X	    READ2(x, y);
X#ifdef DBUG
X	    fprintf(stderr, "x: %d, y: %d\n", x, y);
X	    fflush(stderr);
X#endif
X	    point(x, y);
X	    break;
X	case 'l':				/* line */
X	    READ4(x1, y1, x2, y2);
X#ifdef DBUG
X	    fprintf(stderr, "x1: %d, y1: %d, x2: %d, y2: %d\n", x1, y1,x2,y2);
X	    fflush(stderr);
X#endif
X	    line(x1, y1, x2, y2);
X	    break;
X	case 't':				/* label */
X	    {
X		register char  *p = buf;
X
X		/********
X		while ((c = getchar()) != EOF && c)
X		    *p++ = c;
X		*p = '\0';
X		weh  2/18/90  --- incoming string is newline terminated
X		********/
X		gets(buf);
X		label(buf);
X	    }
X#ifdef DBUG
X	    fprintf(stderr, "label: %s\n", buf);
X	    fflush(stderr);
X#endif
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		if (!noconfirm) 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#ifdef DBUG
X	    fprintf(stderr, "x0: %d, y0: %d, x1: %d, y1: %d\n", x0, y0,x1,y1);
X	    fflush(stderr);
X#endif
X	    space(x0, y0, x1, y1);
X	    break;
X				/* corrupt */
X	default:
X	    closepl();
X	    fprintf(stderr,"c= %c, %d corrupted plotfile -- giving up\n",c,c);
X	    fflush(stderr);
X	    exit(1);
X	}; /* end switch */
X    } /* end while */
X
X/*    if (glmode <= MAXVIDEO)*/
X	if (!noconfirm) confirm();
X	else sleep(5);
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}
SHAR_EOF
$TOUCH -am 1014221490 lpdriver.c &&
chmod 0644 lpdriver.c ||
echo "restore of lpdriver.c failed"
set `wc -c lpdriver.c`;Wc_c=$1
if test "$Wc_c" != "5349"; then
	echo original size 5349, current size $Wc_c
fi
# ============= makefile ==============
echo "x - extracting makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > makefile &&
XCFLAGS=-O -DV386
XCC=gcc
X
Xall: therc tplotlp tReGIS thpgl tsun tCGI
X
Xtherc:
X	$(CC) $(CFLAGS) driver.c -o therc -lherc -lm
X
Xtplotlp:
X	$(CC) $(CFLAGS) lpdriver.c -o tplotlp -lplotlp -lm
X
XtReGIS:
X	$(CC) $(CFLAGS) driver.c -o tReGIS -lReGIS -lm
X
XtCGI:
X	$(CC) $(CFLAGS) driver.c -o tCGI -lcgi -lm
X
Xthpgl:
X	$(CC) $(CFLAGS) driver.c -o thpgl -lhpgl -lm
X
Xtsun:
X	$(CC) $(CFLAGS) driver.c -o tsun -lsun -lm
X
Xinstall: therc tplotlp tReGIS tln03 tCGI thpgl tsun
X	cp therc /usr/lib
X	cp tplotlp /usr/lib
X	cp tReGIS /usr/lib
X	cp tln03 /usr/lib
X	cp tCGI /usr/lib
X	cp thpgl /usr/lib
X	cp tsun /usr/lib
X
SHAR_EOF
$TOUCH -am 1026194490 makefile &&
chmod 0644 makefile ||
echo "restore of makefile failed"
set `wc -c makefile`;Wc_c=$1
if test "$Wc_c" != "584"; then
	echo original size 584, current size $Wc_c
fi
echo "End of part 8, continue with part 9"
exit 0



-- 
UUCP: ..!uunet!mcsun!hp4nl!integow!hot	or  hot at integow.UUCP or hot at hot.mug
Roland van Hout, Sr. software engineer, Integrity software consultants, 
         Pelmolenlaan 16, 3447 GW Woerden, Netherlands,
            tel +31 3480-30131, fax +31 3480-30182



More information about the Alt.sources mailing list