[net.sources] New vplot.c in ar format

torben@arizona.UUCP (07/29/83)

!<arch>
Makefile        428311187   27    36    100644  141       `
CFLAGS = -O

all: vplot

vplot:  vplot.o chrtab.o
	cc -o vplot vplot.o chrtab.o -lm

install:
	install -s vplot /usr/local
clean:
	rm -f *.o

chrtab.c        428311143   27    36    100700  8768      `
char	chrtab[96][16] = {
0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, sp, */
0010,0010,0010,0010,0010,0010,0010,0010,0000,0000,0010,0000,0000,0000,0000,0000, /*, !, */
0024,0024,0024,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ", */
0000,0000,0000,0044,0044,0176,0044,0044,0176,0044,0044,0000,0000,0000,0000,0000, /*, #, */
0000,0010,0010,0010,0076,0101,0100,0076,0001,0101,0076,0010,0010,0000,0000,0000, /*, $, */
0000,0000,0000,0141,0142,0004,0010,0010,0020,0043,0103,0000,0000,0000,0000,0000, /*, %, */
0000,0000,0070,0104,0110,0060,0060,0111,0106,0106,0071,0000,0000,0000,0000,0000, /*, &, */
0004,0010,0020,0040,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ', */
0000,0004,0010,0020,0040,0040,0040,0040,0040,0040,0020,0010,0004,0000,0000,0000, /*, (, */
0000,0040,0020,0010,0004,0004,0004,0004,0004,0004,0010,0020,0040,0000,0000,0000, /*, ), */
0000,0000,0000,0010,0111,0052,0034,0177,0034,0052,0111,0010,0000,0000,0000,0000, /*, *, */
0000,0000,0000,0000,0010,0010,0010,0177,0010,0010,0010,0000,0000,0000,0000,0000, /*, +, */
0000,0000,0000,0000,0000,0000,0000,0000,0000,0030,0030,0010,0020,0000,0000,0000, /*, ,, */
0000,0000,0000,0000,0000,0000,0000,0176,0000,0000,0000,0000,0000,0000,0000,0000, /*, -, */
0000,0000,0000,0000,0000,0000,0000,0000,0000,0030,0030,0000,0000,0000,0000,0000, /*, ., */
0000,0000,0001,0002,0004,0010,0010,0010,0020,0040,0100,0000,0000,0000,0000,0000, /*, /, */
0000,0030,0044,0102,0102,0102,0102,0102,0102,0044,0030,0000,0000,0000,0000,0000, /*, 0, */
0000,0010,0030,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, 1, */
0000,0070,0104,0004,0004,0010,0020,0040,0100,0100,0174,0000,0000,0000,0000,0000, /*, 2, */
0000,0176,0004,0004,0010,0014,0002,0002,0002,0104,0070,0000,0000,0000,0000,0000, /*, 3, */
0000,0004,0014,0024,0044,0104,0176,0004,0004,0004,0004,0000,0000,0000,0000,0000, /*, 4, */
0000,0174,0100,0100,0130,0144,0002,0002,0102,0044,0030,0000,0000,0000,0000,0000, /*, 5, */
0000,0074,0102,0100,0130,0144,0102,0102,0102,0044,0030,0000,0000,0000,0000,0000, /*, 6, */
0000,0176,0004,0004,0010,0010,0020,0020,0040,0040,0040,0000,0000,0000,0000,0000, /*, 7, */
0000,0034,0042,0101,0042,0076,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, 8, */
0000,0034,0042,0101,0101,0101,0043,0036,0004,0010,0020,0040,0000,0000,0000,0000, /*, 9, */
0000,0000,0000,0000,0000,0000,0030,0030,0000,0030,0030,0000,0000,0000,0000,0000, /*, :, */
0000,0000,0000,0000,0000,0000,0030,0030,0000,0030,0030,0020,0040,0000,0000,0000, /*, ;, */
0002,0004,0010,0020,0040,0100,0040,0020,0010,0004,0002,0000,0000,0000,0000,0000, /*, <, */
0000,0000,0000,0000,0177,0000,0177,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, =, */
0100,0040,0020,0010,0004,0002,0004,0010,0020,0040,0100,0000,0000,0000,0000,0000, /*, >, */
0000,0030,0044,0102,0001,0002,0004,0010,0010,0000,0010,0000,0000,0000,0000,0000, /*, ?, */
0000,0074,0102,0101,0115,0123,0121,0121,0121,0111,0046,0000,0000,0000,0000,0000, /*, @, */
0000,0010,0024,0042,0101,0101,0177,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, A, */
0000,0176,0101,0101,0101,0176,0101,0101,0101,0101,0176,0000,0000,0000,0000,0000, /*, B, */
0000,0076,0101,0100,0100,0100,0100,0100,0100,0101,0076,0000,0000,0000,0000,0000, /*, C, */
0000,0176,0101,0101,0101,0101,0101,0101,0101,0101,0176,0000,0000,0000,0000,0000, /*, D, */
0000,0176,0100,0100,0100,0170,0100,0100,0100,0100,0177,0000,0000,0000,0000,0000, /*, E, */
0000,0177,0100,0100,0100,0174,0100,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, F, */
0000,0076,0101,0100,0100,0117,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, G, */
0000,0101,0101,0101,0101,0176,0101,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, H, */
0000,0034,0010,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, I, */
0000,0016,0004,0004,0004,0004,0004,0004,0104,0104,0070,0000,0000,0000,0000,0000, /*, J, */
0000,0101,0102,0104,0110,0120,0160,0110,0104,0102,0101,0000,0000,0000,0000,0000, /*, K, */
0000,0100,0100,0100,0100,0100,0100,0100,0100,0100,0177,0000,0000,0000,0000,0000, /*, L, */
0000,0101,0143,0125,0111,0101,0101,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, M, */
0000,0101,0141,0121,0111,0105,0103,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, N, */
0000,0076,0101,0101,0101,0101,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, O, */
0000,0176,0101,0101,0101,0176,0100,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, P, */
0000,0076,0101,0101,0101,0101,0101,0101,0131,0105,0076,0002,0001,0000,0000,0000, /*, Q, */
0000,0176,0101,0101,0101,0176,0104,0102,0101,0101,0101,0000,0000,0000,0000,0000, /*, R, */
0000,0076,0101,0100,0100,0076,0001,0001,0001,0101,0076,0000,0000,0000,0000,0000, /*, S, */
0000,0177,0010,0010,0010,0010,0010,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, T, */
0000,0101,0101,0101,0101,0101,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, U, */
0000,0101,0101,0101,0101,0101,0101,0101,0042,0024,0010,0000,0000,0000,0000,0000, /*, V, */
0000,0101,0101,0101,0101,0111,0111,0125,0143,0101,0101,0000,0000,0000,0000,0000, /*, W, */
0000,0101,0101,0042,0024,0010,0024,0042,0101,0101,0101,0000,0000,0000,0000,0000, /*, X, */
0000,0101,0042,0024,0010,0010,0010,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, Y, */
0000,0177,0001,0002,0004,0010,0020,0040,0100,0100,0177,0000,0000,0000,0000,0000, /*, Z, */
0000,0034,0020,0020,0020,0020,0020,0020,0020,0020,0020,0034,0000,0000,0000,0000, /*, [, */
0000,0000,0100,0040,0020,0010,0010,0010,0004,0002,0001,0000,0000,0000,0000,0000, /*, , \, */
0000,0070,0010,0010,0010,0010,0010,0010,0010,0010,0010,0070,0000,0000,0000,0000, /*, ], */
0010,0024,0042,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ^, */
0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0377,0000,0000, /*, _, */
0040,0020,0010,0004,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, `, */
0000,0000,0000,0000,0000,0074,0002,0076,0102,0102,0076,0000,0000,0000,0000,0000, /*, a, */
0000,0100,0100,0100,0100,0174,0102,0102,0102,0102,0174,0000,0000,0000,0000,0000, /*, b, */
0000,0000,0000,0000,0000,0074,0102,0100,0100,0102,0074,0000,0000,0000,0000,0000, /*, c, */
0002,0002,0002,0002,0002,0076,0102,0102,0102,0102,0076,0000,0000,0000,0000,0000, /*, d, */
0000,0000,0000,0000,0000,0074,0102,0174,0100,0102,0074,0000,0000,0000,0000,0000, /*, e, */
0000,0016,0020,0020,0020,0176,0020,0020,0020,0020,0020,0000,0000,0000,0000,0000, /*, f, */
0000,0000,0000,0000,0000,0076,0102,0102,0102,0102,0076,0002,0002,0102,0076,0000, /*, g, */
0000,0100,0100,0100,0100,0174,0102,0102,0102,0102,0102,0000,0000,0000,0000,0000, /*, h, */
0000,0000,0000,0010,0000,0030,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, i, */
0000,0000,0000,0010,0000,0030,0010,0010,0010,0010,0010,0010,0010,0050,0020,0000, /*, j, */
0000,0100,0100,0100,0100,0106,0110,0120,0160,0110,0106,0000,0000,0000,0000,0000, /*, k, */
0000,0030,0010,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, l, */
0000,0000,0000,0000,0000,0166,0111,0111,0111,0111,0111,0000,0000,0000,0000,0000, /*, m, */
0000,0000,0000,0000,0100,0174,0102,0102,0102,0102,0102,0000,0000,0000,0000,0000, /*, n, */
0000,0000,0000,0000,0000,0074,0102,0102,0102,0102,0074,0000,0000,0000,0000,0000, /*, o, */
0000,0000,0000,0000,0000,0174,0102,0102,0102,0102,0174,0100,0100,0100,0100,0000, /*, p, */
0000,0000,0000,0000,0000,0076,0102,0102,0102,0102,0076,0002,0002,0002,0002,0000, /*, q, */
0000,0000,0000,0000,0000,0134,0142,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, r, */
0000,0000,0000,0000,0000,0076,0100,0074,0002,0102,0074,0000,0000,0000,0000,0000, /*, s, */
0000,0020,0020,0020,0020,0176,0020,0020,0020,0020,0014,0000,0000,0000,0000,0000, /*, t, */
0000,0000,0000,0000,0000,0102,0102,0102,0102,0102,0075,0000,0000,0000,0000,0000, /*, u, */
0000,0000,0000,0000,0000,0101,0101,0101,0042,0024,0010,0000,0000,0000,0000,0000, /*, v, */
0000,0000,0000,0000,0000,0111,0111,0111,0111,0111,0066,0000,0000,0000,0000,0000, /*, w, */
0000,0000,0000,0000,0000,0102,0044,0030,0030,0044,0102,0000,0000,0000,0000,0000, /*, x, */
0000,0000,0000,0000,0000,0102,0102,0102,0042,0024,0010,0020,0040,0100,0000,0000, /*, y, */
0000,0000,0000,0000,0000,0176,0004,0010,0020,0040,0176,0000,0000,0000,0000,0000, /*, z, */
0000,0014,0020,0020,0020,0020,0040,0020,0020,0020,0020,0014,0000,0000,0000,0000, /*, {, */
0000,0010,0010,0010,0010,0000,0000,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, |, */
0000,0030,0010,0010,0010,0010,0004,0010,0010,0010,0010,0030,0000,0000,0000,0000, /*, }, */
0020,0052,0004,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ~, */
0000,0176,0176,0176,0176,0176,0176,0176,0176,0176,0176,0000,0000,0000,0000,0000, /*, del, */
};
defs.h          428311142   27    36    100644  459       `
#include <math.h>
#include <stdio.h>
#include <signal.h>
#include "vcmd.h"

#define ZERO	'\200'
#define ONE	'\100'
#define TWO	'\040'
#define THREE	'\020'
#define FOUR	'\010'
#define FIVE	'\004'
#define SIX	'\002'
#define SEVEN	'\001'

#define BLACK	'\377'
#define WHITE	'\000'

#define SOLID		-1
#define DOTTED		014
#define SHORTDASHED	034
#define DOTDASHED	054
#define LONGDASHED	074

#define READ	0
#define WRITE	1

#define HEIGHT	1700
#define WIDTH	2112


vcmd.h          428311142   27    36    100750  150       `
#define	VPRINT		0100
#define	VPLOT		0200
#define	VPRINTPLOT	0400

#define VEOT		"\014"

#define	VGETSTATE	(('v'<<8)|0)
#define	VSETSTATE	(('v'<<8)|1)
vplot.c         428311143   27    36    100644  7287      `
#include "defs.h"

#define mapx(x) (xscale*((x) - botx))
#define mapy(y) (yscale*((y) - boty))

#define MAXTRIES	120
#define SLEEPTIME	30

#define PI		3.141592653

extern char	chrtab[96][16];
extern char	*getlogin();
extern char	*ctime();

char		picture[HEIGHT][WIDTH/8];

int		f;		/*Versatec file descriptor*/

int		again = 1;	/*Flag gets set every time an 'e' occurs*/
int		done1 = 0;	/*Flag gets set when picture is dirtied*/

int		lastx = 0;
int		lasty = 0;

int		printcom[] = {VPRINT,0,0};
int		plotcom[]  = {VPLOT,0,0};

double		xscale = 0.99;
double		yscale = 0.99;

main(argc,argv)

char		**argv;
int		argc;

{

   int		onintr();

   if(argc > 1) {
      fprintf(stderr,"Usage: vplot\n");
      exit(1);
      }

   signal(SIGTERM,onintr);
   if(signal(SIGINT,SIG_IGN) != SIG_IGN)
      signal(SIGINT,onintr);

   while(again > 0) {
      if(done1) {
         done1 = 0;
         clearpicture();
         }
      again = 0;
      getpicture();
      putpicture();
      }

}

int onintr()

{

   exit(1);

}

int clearpicture()

{

   int		i,j;

   for(i = 0;i < HEIGHT;i++)
      for(j = 0;j < WIDTH/8;j++)
         picture[i][j] &= WHITE;

   return;

}

int getpicture()

{

        int		x0,y0,x1,y1,x2,y2,botx,boty,topx,topy;

        botx = 0;
        boty = 0;
    	topx = WIDTH - 1;
        topy = HEIGHT - 1;

	for(;;) {x1 = getc(stdin); switch(x1) {

	case 's':
		botx = get2ch(stdin);
		boty = get2ch(stdin);
		topx = get2ch(stdin);
		topy = get2ch(stdin);
                xscale = ((double) (WIDTH - 1))/(topx - botx);
                yscale = ((double) (HEIGHT - 1))/(topy - boty);
		continue;

	case 'l':
		done1 = 1;
		x1 = mapx(get2ch(stdin));
		y1 = mapy(get2ch(stdin));
		lastx = mapx(get2ch(stdin));
		lasty = mapy(get2ch(stdin));
		setseg(x1, y1, lastx, lasty);
		continue;

        case 'c':
		done1 = 1;
		x1 = mapx(get2ch(stdin));
     		y1 = mapy(get2ch(stdin));
		x2 = get2ch(stdin); /*The radius is not scaled*/
   		setcircle(x1,y1,x2);
		continue;

        case 'a':
		done1 = 1;
		x0 = mapx(get2ch(stdin));
		y0 = mapy(get2ch(stdin));
		x1 = mapx(get2ch(stdin));
		y1 = mapy(get2ch(stdin));
		x2 = mapx(get2ch(stdin));
		y2 = mapy(get2ch(stdin));
		setarc(x0,y0,x1,y1,x2,y2);
		continue;

	case 'b':
		done1 = 1;
		x1 = mapx(get2ch(stdin));
		y1 = mapy(get2ch(stdin));
		lastx = mapx(get2ch(stdin));
		lasty = mapy(get2ch(stdin));
		setrect(x1, y1, lastx, lasty);
		continue;

	case 'm':
		lastx = mapx(get2ch(stdin));
		lasty = mapy(get2ch(stdin));
		continue;

	case 't':
		done1 = 1;
		while ((x1 = getc(stdin)) != '\n')
			plotchar(x1);
		continue;

	case 'e':
		if (done1) {
			again++;
			return;
		}
		continue;

	case 'p':
		done1 = 1;
		lastx = mapx(get2ch(stdin));
		lasty = mapy(get2ch(stdin));
		setdot(lastx, lasty);
		setdot(lastx+1, lasty);
		setdot(lastx, lasty+1);
		setdot(lastx+1, lasty+1);
		continue;

	case 'n':
		done1 = 1;
		x1 = mapx(get2ch(stdin));
		y1 = mapy(get2ch(stdin));
		setseg(lastx, lasty, x1, y1);
		lastx = x1;
		lasty = y1;
		continue;

	case 'f':
		get2ch(stdin);
		getc(stdin);
		while((x1=getc(stdin))!='\n')
			if(x1==-1) return;
		continue;

	case -1:
		return;

	default:
		fprintf(stderr,"Vplot unimplemented cmd %c (\\0%o) \n", x1,x1);
		return;
	} }
}

int get2ch(fd)

FILE *fd;

{

	short lo, hi;

        lo = getc(fd);
	hi = (getc(fd)) << 8;

	return(hi|lo);
}

int plotchar(c)
register c;
{
	register j;
	register char *cp;
	int i;

	if (c<' ' || c >0177)
		return;
	cp = chrtab[c-' '];
	for (i = 14; i>=-16; i -= 2) {
		c = *cp++;
		for (j=7; j>=0; --j)
			if ((c>>j)&1) {
				setdot(lastx+6-j*2, lasty+i);
				setdot(lastx+7-j*2, lasty+i);
				setdot(lastx+6-j*2, lasty+i+1);
				setdot(lastx+7-j*2, lasty+i+1);
			}
	}

	lastx += 16;
        return;

}

int putpicture()

{

   int		tries,entry,onintr();

   tries = 0;

   while((entry = creat("/usr/spool/vad/lock",00000)) < 0) {
      if(++tries > MAXTRIES) {
         fprintf(stderr,"Versatec busy for 1hr,check for old lockfiles.\n");
         exit(1);
         }
      sleep(SLEEPTIME);
      }

   if((f = open("/dev/vp0",WRITE)) < 0) {
      fprintf(stderr,"Cannot open Versatec.\n");
      exit(1);
      }

   banner(getlogin());

   ioctl(f,VSETSTATE,plotcom);

   write(f,picture,HEIGHT*WIDTH/8);

   ioctl(f,VSETSTATE,printcom);

   write(f,VEOT,1);

   close(f);
   
   close(entry);

   unlink("/usr/spool/vad/lock");

   system("/usr/lib/vad");

   return;

}

int setdot(m,n)		/*Note that 0<=m<WIDTH and 0<=n<HEIGHT*/

int	m,n;

{

   if(m < 0||m > WIDTH - 1||n < 0||n > HEIGHT - 1)
      return;

   picture[HEIGHT - 1 - n][m/8] |= (01 << (7 - m%8));

   return;

}

int setseg(x0,y0,x1,y1)	/*draw a line segment from (x0,y0) to (x1,y1)*/

int	x0,y0,x1,y1;

{

   int		i,m,n;
   double	delx,dely,length,xinc,yinc;

   delx = x1 - x0;
   dely = y1 - y0;

   if((length = sqrt(delx*delx + dely*dely)) <= 0.0)
      length = 1.0;

   xinc = delx/length;
   yinc = dely/length;

   for(i = 0;i <= length;i++) {

      m = (int) (x0 + i*xinc + 0.5);
      n = (int) (y0 + i*yinc + 0.5);

      if(m < 0||m > WIDTH - 1||n < 0||n > HEIGHT - 1)
         continue;

      picture[HEIGHT - 1 - n][m/8] |= (01 << (7 - m%8));

      }

   return;

}

int setcircle(x0,y0,r)

int		x0,y0,r;

{

   int		m,n;
   double	inc,param;

   if(r <= 0.0)
      r = 1.0;

   inc = 1.0/r;

   for(param = 0.0;param < 2.0*PI;param += inc) {
      
      m = (int) (x0 + r*cos(param) + 0.5);
      n = (int) (y0 + r*sin(param) + 0.5);

      if(m < 0||m > WIDTH - 1||n < 0||n > HEIGHT - 1)
         continue;

      picture[HEIGHT - 1 - n][m/8] |= (01 << (7 - m%8));

      }

}

int setarc(x0,y0,x1,y1,x2,y2)

int		x0,y0,x1,y1,x2,y2;

{

   int		m,n;
   double	inc,r1,r2,theta,phi;

   r1 = sqrt((double)((x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0)));
   r2 = sqrt((double)((x2 - x0)*(x2 - x0) + (y2 - y0)*(y2 - y0)));

   if(r1 <= 0.0 || r2 <= 0.0)
      return;

   inc = 1.0/(2.0*r1);

   if(y1 - y0 >= 0)
      phi = acos((x1 - x0)/r1);
   else
      phi = 2.0*PI - acos((x1 - x0)/r1);

   if(y2 - y0 >= 0)
      theta = acos((x2 - x0)/r2);
   else
      theta = 2.0*PI - acos((x2 - x0)/r2);

   if(theta < phi)
      theta += 2.0*PI;

   for(;phi <= theta;phi += inc) {
      
      m = (int) (x0 + r1*cos(phi) + 0.5);
      n = (int) (y0 + r1*sin(phi) + 0.5);

      if(m < 0||m > WIDTH - 1||n < 0||n > HEIGHT - 1)
         continue;

      picture[HEIGHT - 1 - n][m/8] |= (01 << (7 - m%8));

      }

   return;

}

int setrect(x0,y0,x1,y1)	/*(x0,y0) is lower left corner and (x1,y1)*/
				/*is upper right corner of rectangle.     */
int	x0,y0,x1,y1;

{

   setseg(x0,y0,x0,y1);
   setseg(x0,y1,x1,y1);
   setseg(x1,y1,x1,y0);
   setseg(x1,y0,x0,y0);

   return;

}

int banner(s)
char *s;
{
	long timeb;
	register char *sp;
	register int i, j, t;

	ioctl( f, VSETSTATE, printcom );

	for (i=0; i<16; i++) {
		write( f, "                ", 16 );
		for (sp=s; *sp; sp++) {
			if (*sp<=' '|| *sp >'}')
				continue;
			write( f, "  ", 2 );
			t = chrtab[*sp - ' '][i];
			for (j=7; j>=0; j--)
				if ((t>>j) & 01)
					write( f, sp, 1);
				else
					write( f, " ", 1 );
		}
		write( f, "\n", 1);
	}
	write( f, "\n\n\n\n\n\n\n\n", 8 );
	time(&timeb);
	write( f, "                ", 16 );
	write( f, ctime(&timeb), 26 - 2 );
	write( f, "\014", 1 );
}