xref: /onnv-gate/usr/src/cmd/tplot/vplot.c (revision 335:d26e4323ca82)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <stdio.h>
340Sstevel@tonic-gate #include <signal.h>
350Sstevel@tonic-gate #include <values.h>
360Sstevel@tonic-gate #include <sys/types.h>
370Sstevel@tonic-gate #include <sys/stat.h>
380Sstevel@tonic-gate #include <fcntl.h>
390Sstevel@tonic-gate #include <sgtty.h>
40*335Smuffin #include <stdlib.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #define	NB	88
430Sstevel@tonic-gate #define	BSIZ	512
440Sstevel@tonic-gate #define	mapx(x)	((1536*((x)-botx)/del)+centx)
450Sstevel@tonic-gate #define	mapy(y)	((1536*(del-(y)+boty)/del)-centy)
460Sstevel@tonic-gate #define	SOLID -1
470Sstevel@tonic-gate #define	DOTTED 014
480Sstevel@tonic-gate #define	SHORTDASHED 034
490Sstevel@tonic-gate #define	DOTDASHED 054
500Sstevel@tonic-gate #define	LONGDASHED 074
510Sstevel@tonic-gate #define	SETSTATE	(('v'<<8)+1)
520Sstevel@tonic-gate #define	NEG_MASK  (MAXINT<<(2*BITS(char)))
530Sstevel@tonic-gate #define	MAXCHAR   ((char)~((char)(1<<BITS(char)-1)))
540Sstevel@tonic-gate #define	BUILDINT(ubyte, lbyte)  \
550Sstevel@tonic-gate 	ubyte > MAXCHAR \
560Sstevel@tonic-gate 	? (ubyte << BITS(char))|lbyte|NEG_MASK \
570Sstevel@tonic-gate 	: (ubyte << BITS(char))|lbyte
580Sstevel@tonic-gate 
590Sstevel@tonic-gate int	linmod	= SOLID;
600Sstevel@tonic-gate int	again;
610Sstevel@tonic-gate int	done1;
620Sstevel@tonic-gate extern char	chrtab[][16];
630Sstevel@tonic-gate short	plotcom[] = { 0200, 0, 0, 0 };
640Sstevel@tonic-gate short	eotcom[] = { 0210, 0, 0, 0 };
650Sstevel@tonic-gate char	blocks	[NB][BSIZ];
660Sstevel@tonic-gate short	obuf[264];
670Sstevel@tonic-gate int	lastx;
680Sstevel@tonic-gate int	lasty;
690Sstevel@tonic-gate double	topx	= 1536;
700Sstevel@tonic-gate double	topy	= 1536;
710Sstevel@tonic-gate double	botx	= 0;
720Sstevel@tonic-gate double	boty	= 0;
730Sstevel@tonic-gate int	centx;
740Sstevel@tonic-gate int	centy;
750Sstevel@tonic-gate double	delx	= 1536;
760Sstevel@tonic-gate double	dely	= 1536;
770Sstevel@tonic-gate double	del	= 1536;
780Sstevel@tonic-gate int	bflag;
790Sstevel@tonic-gate int	fflag;
800Sstevel@tonic-gate char	*banname;
810Sstevel@tonic-gate FILE	*vpstr;
820Sstevel@tonic-gate 
830Sstevel@tonic-gate struct	buf {
840Sstevel@tonic-gate 	int	bno;
850Sstevel@tonic-gate 	char	*block;
860Sstevel@tonic-gate };
870Sstevel@tonic-gate struct	buf	bufs[NB];
880Sstevel@tonic-gate 
890Sstevel@tonic-gate int	in, out;
900Sstevel@tonic-gate char picname[] = "/var/tmp/rasterXXXXXX";
910Sstevel@tonic-gate char *picture;
920Sstevel@tonic-gate 
93*335Smuffin void	getpict(void);
94*335Smuffin void	plotch(int);
95*335Smuffin void	putpict(void);
96*335Smuffin void	line(int, int, int, int);
97*335Smuffin void	point(int, int);
98*335Smuffin void	getblk(int);
99*335Smuffin void	onintr(void);
100*335Smuffin 
101*335Smuffin int
main(int argc,char ** argv)102*335Smuffin main(int argc, char **argv)
1030Sstevel@tonic-gate {
104*335Smuffin 	int i;
105*335Smuffin 	int c;
1060Sstevel@tonic-gate 	char *fname;
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "e:b:")) != EOF)
1090Sstevel@tonic-gate 	switch (c) {
1100Sstevel@tonic-gate 		case 'b':
1110Sstevel@tonic-gate 			bflag++;
1120Sstevel@tonic-gate 			banname = optarg;
1130Sstevel@tonic-gate 			break;
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate 		case 'e':
1160Sstevel@tonic-gate 			fname = optarg;
1170Sstevel@tonic-gate 			fflag++;
1180Sstevel@tonic-gate 			break;
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 		case '?':
1210Sstevel@tonic-gate 			fprintf(stderr,
1220Sstevel@tonic-gate 			    "usage: vplot [ -f raster ] [ file ]\n");
1230Sstevel@tonic-gate 			exit(1);
1240Sstevel@tonic-gate 	}
1250Sstevel@tonic-gate 	if (fflag) {
1260Sstevel@tonic-gate 		if ((in = open(fname, O_RDONLY)) < 0) {
1270Sstevel@tonic-gate 			fprintf(stderr, "vplot: cannot open %s\n", fname);
1280Sstevel@tonic-gate 			exit(1);
1290Sstevel@tonic-gate 		}
1300Sstevel@tonic-gate 		putpict();
1310Sstevel@tonic-gate 		exit(0);
1320Sstevel@tonic-gate 	}
1330Sstevel@tonic-gate 	if (optind < argc)
1340Sstevel@tonic-gate 		if (freopen(argv[optind], "r", stdin) == NULL) {
1350Sstevel@tonic-gate 			fprintf(stderr,
1360Sstevel@tonic-gate 			    "vplot: cannot open %s\n", argv[optind]);
1370Sstevel@tonic-gate 			exit(1);
1380Sstevel@tonic-gate 		}
139*335Smuffin 	signal(SIGTERM, (void (*)(int))onintr);
1400Sstevel@tonic-gate 	if (signal(SIGINT, SIG_IGN) != SIG_IGN)
141*335Smuffin 		signal(SIGINT, (void (*)(int))onintr);
1420Sstevel@tonic-gate 	if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
143*335Smuffin 		signal(SIGHUP, (void (*)(int))onintr);
1440Sstevel@tonic-gate another:
1450Sstevel@tonic-gate 	for (i = 0; i < NB; i++) {
1460Sstevel@tonic-gate 		bufs[i].bno = -1;
1470Sstevel@tonic-gate 		bufs[i].block = blocks[i];
1480Sstevel@tonic-gate 	}
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate 	if ((picture = mktemp(picname)) == NULL) {
1510Sstevel@tonic-gate 		fprintf(stderr, "vplot: cannot create unique tmp. file name\n");
1520Sstevel@tonic-gate 		exit(1);
1530Sstevel@tonic-gate 	}
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate 	if ((out = open(picture, (O_WRONLY|O_CREAT|O_TRUNC|O_EXCL),
1560Sstevel@tonic-gate 	    (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH))) == -1) {
1570Sstevel@tonic-gate 		fprintf(stderr, "vplot: cannot open %s\n", picture);
1580Sstevel@tonic-gate 		exit(1);
1590Sstevel@tonic-gate 	}
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 	zseek(out, 32*32);
1620Sstevel@tonic-gate 	write(out, blocks[0], BSIZ);
1630Sstevel@tonic-gate /*
1640Sstevel@tonic-gate  * delete following code when filsys deals properly with
1650Sstevel@tonic-gate  * holes in files
1660Sstevel@tonic-gate  */
1670Sstevel@tonic-gate 	for (i = 0; i < 512; i++)
1680Sstevel@tonic-gate 		blocks[0][i] = 0;
1690Sstevel@tonic-gate 	zseek(out, 0);
1700Sstevel@tonic-gate 	for (i = 0; i < 32*32; i++)
1710Sstevel@tonic-gate 		write(out, blocks[0], 512);
1720Sstevel@tonic-gate 	getpict();
1730Sstevel@tonic-gate 	for (i = 0; i < NB; i++)
1740Sstevel@tonic-gate 		if (bufs[i].bno != -1) {
1750Sstevel@tonic-gate 			zseek(out, bufs[i].bno);
1760Sstevel@tonic-gate 			write(out, bufs[i].block, BSIZ);
1770Sstevel@tonic-gate 		}
1780Sstevel@tonic-gate 	putpict();
1790Sstevel@tonic-gate 	if (again) {
1800Sstevel@tonic-gate 		close(out);
1810Sstevel@tonic-gate 		goto another;
1820Sstevel@tonic-gate 	}
1830Sstevel@tonic-gate 	unlink(picture);
184*335Smuffin 	return (0);
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate 
187*335Smuffin void
getpict(void)188*335Smuffin getpict(void)
1890Sstevel@tonic-gate {
190*335Smuffin 	int x1, y1;
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate 	again = 0;
1930Sstevel@tonic-gate 	for (;;)
1940Sstevel@tonic-gate 	switch (x1 = getc(stdin)) {
1950Sstevel@tonic-gate 	case 's':
1960Sstevel@tonic-gate 		botx = getw(stdin);
1970Sstevel@tonic-gate 		boty = getw(stdin);
1980Sstevel@tonic-gate 		topx = getw(stdin);
1990Sstevel@tonic-gate 		topy = getw(stdin);
2000Sstevel@tonic-gate 		delx = topx-botx;
2010Sstevel@tonic-gate 		dely = topy-boty;
2020Sstevel@tonic-gate 		if (dely/delx > 1536./2048.)
2030Sstevel@tonic-gate 			del = dely;
2040Sstevel@tonic-gate 		else
2050Sstevel@tonic-gate 			del = delx * (1566./2048.);
2060Sstevel@tonic-gate 		centx = 0;
2070Sstevel@tonic-gate 		centx = (2048 - mapx(topx)) / 2;
2080Sstevel@tonic-gate 		centy = 0;
2090Sstevel@tonic-gate 		centy = mapy(topy) / 2;
2100Sstevel@tonic-gate 		continue;
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate 	case 'l':
2130Sstevel@tonic-gate 		done1 |= 01;
2140Sstevel@tonic-gate 		x1 = mapx(getw(stdin));
2150Sstevel@tonic-gate 		y1 = mapy(getw(stdin));
2160Sstevel@tonic-gate 		lastx = mapx(getw(stdin));
2170Sstevel@tonic-gate 		lasty = mapy(getw(stdin));
2180Sstevel@tonic-gate 		line(x1, y1, lastx, lasty);
2190Sstevel@tonic-gate 		continue;
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate 	case 'm':
2220Sstevel@tonic-gate 		lastx = mapx(getw(stdin));
2230Sstevel@tonic-gate 		lasty = mapy(getw(stdin));
2240Sstevel@tonic-gate 		continue;
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 	case 't':
2270Sstevel@tonic-gate 		done1 |= 01;
2280Sstevel@tonic-gate 		while ((x1 = getc(stdin)) != '\n')
2290Sstevel@tonic-gate 			plotch(x1);
2300Sstevel@tonic-gate 		continue;
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate 	case 'e':
2330Sstevel@tonic-gate 		if (done1) {
2340Sstevel@tonic-gate 			again++;
2350Sstevel@tonic-gate 			return;
2360Sstevel@tonic-gate 		}
2370Sstevel@tonic-gate 		continue;
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate 	case 'p':
2400Sstevel@tonic-gate 		done1 |= 01;
2410Sstevel@tonic-gate 		lastx = mapx(getw(stdin));
2420Sstevel@tonic-gate 		lasty = mapy(getw(stdin));
2430Sstevel@tonic-gate 		point(lastx, lasty);
2440Sstevel@tonic-gate 		point(lastx+1, lasty);
2450Sstevel@tonic-gate 		point(lastx, lasty+1);
2460Sstevel@tonic-gate 		point(lastx+1, lasty+1);
2470Sstevel@tonic-gate 		continue;
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate 	case 'n':
2500Sstevel@tonic-gate 		done1 |= 01;
2510Sstevel@tonic-gate 		x1 = mapx(getw(stdin));
2520Sstevel@tonic-gate 		y1 = mapy(getw(stdin));
2530Sstevel@tonic-gate 		line(lastx, lasty, x1, y1);
2540Sstevel@tonic-gate 		lastx = x1;
2550Sstevel@tonic-gate 		lasty = y1;
2560Sstevel@tonic-gate 		continue;
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate 	case 'f':
2590Sstevel@tonic-gate 		getw(stdin);
2600Sstevel@tonic-gate 		getc(stdin);
2610Sstevel@tonic-gate 		switch (getc(stdin)) {
2620Sstevel@tonic-gate 		case 't':
2630Sstevel@tonic-gate 			linmod = DOTTED;
2640Sstevel@tonic-gate 			break;
2650Sstevel@tonic-gate 		default:
2660Sstevel@tonic-gate 		case 'i':
2670Sstevel@tonic-gate 			linmod = SOLID;
2680Sstevel@tonic-gate 			break;
2690Sstevel@tonic-gate 		case 'g':
2700Sstevel@tonic-gate 			linmod = LONGDASHED;
2710Sstevel@tonic-gate 			break;
2720Sstevel@tonic-gate 		case 'r':
2730Sstevel@tonic-gate 			linmod = SHORTDASHED;
2740Sstevel@tonic-gate 			break;
2750Sstevel@tonic-gate 		case 'd':
2760Sstevel@tonic-gate 			linmod = DOTDASHED;
2770Sstevel@tonic-gate 			break;
2780Sstevel@tonic-gate 		}
2790Sstevel@tonic-gate 		while ((x1 = getc(stdin)) != '\n')
2800Sstevel@tonic-gate 			if (x1 == -1)
2810Sstevel@tonic-gate 				return;
2820Sstevel@tonic-gate 		continue;
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate 	case 'd':
2850Sstevel@tonic-gate 		getw(stdin);
2860Sstevel@tonic-gate 		getw(stdin);
2870Sstevel@tonic-gate 		getw(stdin);
2880Sstevel@tonic-gate 		x1 = getw(stdin);
2890Sstevel@tonic-gate 		while (--x1 >= 0)
2900Sstevel@tonic-gate 			getw(stdin);
2910Sstevel@tonic-gate 		continue;
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate 	case -1:
2940Sstevel@tonic-gate 		return;
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate 	default:
2970Sstevel@tonic-gate 		printf("Botch\n");
2980Sstevel@tonic-gate 		return;
2990Sstevel@tonic-gate 	}
3000Sstevel@tonic-gate }
3010Sstevel@tonic-gate 
302*335Smuffin void
plotch(int c)303*335Smuffin plotch(int c)
3040Sstevel@tonic-gate {
305*335Smuffin 	int j;
306*335Smuffin 	char *cp;
3070Sstevel@tonic-gate 	int i;
3080Sstevel@tonic-gate 
3090Sstevel@tonic-gate 	if (c < ' ' || c > 0177)
3100Sstevel@tonic-gate 		return;
3110Sstevel@tonic-gate 	cp = chrtab[c-' '];
3120Sstevel@tonic-gate 	for (i = -16; i < 16; i += 2) {
3130Sstevel@tonic-gate 		c = *cp++;
3140Sstevel@tonic-gate 		for (j = 7; j >= 0; --j)
3150Sstevel@tonic-gate 			if ((c>>j)&1) {
3160Sstevel@tonic-gate 				point(lastx+6-j*2, lasty+i);
3170Sstevel@tonic-gate 				point(lastx+7-j*2, lasty+i);
3180Sstevel@tonic-gate 				point(lastx+6-j*2, lasty+i+1);
3190Sstevel@tonic-gate 				point(lastx+7-j*2, lasty+i+1);
3200Sstevel@tonic-gate 			}
3210Sstevel@tonic-gate 	}
3220Sstevel@tonic-gate 	lastx += 16;
3230Sstevel@tonic-gate }
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate int	f; /* versatec file number */
326*335Smuffin 
327*335Smuffin void
putpict(void)328*335Smuffin putpict(void)
3290Sstevel@tonic-gate {
330*335Smuffin 	int x;
331*335Smuffin 	short *ip, *op;
3320Sstevel@tonic-gate 	int y;
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate 	if (f == 0) {
3350Sstevel@tonic-gate 		f = open("/dev/vp", O_WRONLY);
3360Sstevel@tonic-gate 		if (f < 0) {
3370Sstevel@tonic-gate 			fprintf(stderr, "Cannot open vp\n");
3380Sstevel@tonic-gate 			unlink(picture);
3390Sstevel@tonic-gate 			exit(1);
3400Sstevel@tonic-gate 		}
3410Sstevel@tonic-gate 		vpstr = fdopen(f, "w");
3420Sstevel@tonic-gate 		if (bflag)  {
3430Sstevel@tonic-gate 			banner(vpstr, banname);
3440Sstevel@tonic-gate 			fflush(vpstr);
3450Sstevel@tonic-gate 		}
3460Sstevel@tonic-gate 		ioctl(f, TIOCSETP, plotcom);
3470Sstevel@tonic-gate 	}
3480Sstevel@tonic-gate 	op = obuf;
3490Sstevel@tonic-gate 	lseek(in, 0L, 0);
3500Sstevel@tonic-gate 	for (y = 0; y < 2048; y++) {
3510Sstevel@tonic-gate 		if ((y&077) == 0)
3520Sstevel@tonic-gate 			read(in, blocks[0], 32*BSIZ);
3530Sstevel@tonic-gate 		for (x = 0; x < 32; x++)  {
3540Sstevel@tonic-gate 			ip = (short *)&blocks[x][(y&077)<<3];
3550Sstevel@tonic-gate 			*op++ = *ip++;
3560Sstevel@tonic-gate 			*op++ = *ip++;
3570Sstevel@tonic-gate 			*op++ = *ip++;
3580Sstevel@tonic-gate 			*op++ = *ip++;
3590Sstevel@tonic-gate 		}
3600Sstevel@tonic-gate 		*op++ = 0;
3610Sstevel@tonic-gate 		*op++ = 0;
3620Sstevel@tonic-gate 		*op++ = 0;
3630Sstevel@tonic-gate 		*op++ = 0;
3640Sstevel@tonic-gate 		if (y&1) {
3650Sstevel@tonic-gate 			write(f, (char *)obuf, sizeof (obuf));
3660Sstevel@tonic-gate 			op = obuf;
3670Sstevel@tonic-gate 		}
3680Sstevel@tonic-gate 	}
3690Sstevel@tonic-gate }
3700Sstevel@tonic-gate 
371*335Smuffin void
line(int x0,int y0,int x1,int y1)372*335Smuffin line(int x0, int y0, int x1, int y1)
3730Sstevel@tonic-gate {
3740Sstevel@tonic-gate 	int dx, dy;
3750Sstevel@tonic-gate 	int xinc, yinc;
376*335Smuffin 	int res1;
3770Sstevel@tonic-gate 	int res2;
3780Sstevel@tonic-gate 	int slope;
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate 	xinc = 1;
3810Sstevel@tonic-gate 	yinc = 1;
3820Sstevel@tonic-gate 	if ((dx = x1-x0) < 0) {
3830Sstevel@tonic-gate 		xinc = -1;
3840Sstevel@tonic-gate 		dx = -dx;
3850Sstevel@tonic-gate 	}
3860Sstevel@tonic-gate 	if ((dy = y1-y0) < 0) {
3870Sstevel@tonic-gate 		yinc = -1;
3880Sstevel@tonic-gate 		dy = -dy;
3890Sstevel@tonic-gate 	}
3900Sstevel@tonic-gate 	slope = xinc*yinc;
3910Sstevel@tonic-gate 	res1 = 0;
3920Sstevel@tonic-gate 	res2 = 0;
3930Sstevel@tonic-gate 	if (dx >= dy)
3940Sstevel@tonic-gate 	while (x0 != x1) {
3950Sstevel@tonic-gate 	if ((x0 + slope*y0) & linmod)
3960Sstevel@tonic-gate 	if (((x0>>6) + ((y0&~077)>>1)) == bufs[0].bno)
3970Sstevel@tonic-gate 		bufs[0].block[((y0&077)<<3)+((x0>>3)&07)] |= 1 << (7-(x0&07));
3980Sstevel@tonic-gate 	else
3990Sstevel@tonic-gate 		point(x0, y0);
4000Sstevel@tonic-gate 		if (res1 > res2) {
4010Sstevel@tonic-gate 			res2 += dx - res1;
4020Sstevel@tonic-gate 			res1 = 0;
4030Sstevel@tonic-gate 			y0 += yinc;
4040Sstevel@tonic-gate 		}
4050Sstevel@tonic-gate 		res1 += dy;
4060Sstevel@tonic-gate 		x0 += xinc;
4070Sstevel@tonic-gate 	} else while (y0 != y1) {
4080Sstevel@tonic-gate 	if ((x0 + slope * y0) & linmod)
4090Sstevel@tonic-gate 		if (((x0 >> 6) + ((y0 & ~077) >> 1)) == bufs[0].bno)
4100Sstevel@tonic-gate 			bufs[0].block[((y0 & 077) << 3)+((x0 >> 3) & 07)]
4110Sstevel@tonic-gate 			    |= 1 << (7 - (x0& 07));
4120Sstevel@tonic-gate 	else
4130Sstevel@tonic-gate 		point(x0, y0);
4140Sstevel@tonic-gate 		if (res1 > res2) {
4150Sstevel@tonic-gate 			res2 += dy - res1;
4160Sstevel@tonic-gate 			res1 = 0;
4170Sstevel@tonic-gate 			x0 += xinc;
4180Sstevel@tonic-gate 		}
4190Sstevel@tonic-gate 		res1 += dx;
4200Sstevel@tonic-gate 		y0 += yinc;
4210Sstevel@tonic-gate 	}
4220Sstevel@tonic-gate 	if ((x1+slope*y1)&linmod)
4230Sstevel@tonic-gate 	if (((x1>>6) + ((y1&~077)>>1)) == bufs[0].bno)
4240Sstevel@tonic-gate 		bufs[0].block[((y1&077)<<3)+((x1>>3)&07)] |= 1 << (7-(x1&07));
4250Sstevel@tonic-gate 	else
4260Sstevel@tonic-gate 		point(x1, y1);
4270Sstevel@tonic-gate }
4280Sstevel@tonic-gate 
429*335Smuffin void
point(int x,int y)430*335Smuffin point(int x, int y)
4310Sstevel@tonic-gate {
432*335Smuffin 	int bno;
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate 	bno = ((x&03700)>>6) + ((y&03700)>>1);
4350Sstevel@tonic-gate 	if (bno != bufs[0].bno) {
4360Sstevel@tonic-gate 		if (bno < 0 || bno >= 1024)
4370Sstevel@tonic-gate 			return;
4380Sstevel@tonic-gate 		getblk(bno);
4390Sstevel@tonic-gate 	}
4400Sstevel@tonic-gate 	bufs[0].block[((y&077)<<3)+((x>>3)&07)] |= 1 << (7-(x&07));
4410Sstevel@tonic-gate }
4420Sstevel@tonic-gate 
443*335Smuffin void
getblk(int b)444*335Smuffin getblk(int b)
4450Sstevel@tonic-gate {
446*335Smuffin 	struct buf *bp1, *bp2;
447*335Smuffin 	char *tp;
4480Sstevel@tonic-gate 
4490Sstevel@tonic-gate loop:
4500Sstevel@tonic-gate 	for (bp1 = bufs; bp1 < &bufs[NB]; bp1++) {
4510Sstevel@tonic-gate 		if (bp1->bno == b || bp1->bno == -1) {
4520Sstevel@tonic-gate 			tp = bp1->block;
4530Sstevel@tonic-gate 			for (bp2 = bp1; bp2 > bufs; --bp2) {
4540Sstevel@tonic-gate 				bp2->bno = (bp2-1)->bno;
4550Sstevel@tonic-gate 				bp2->block = (bp2-1)->block;
4560Sstevel@tonic-gate 			}
4570Sstevel@tonic-gate 			bufs[0].bno = b;
4580Sstevel@tonic-gate 			bufs[0].block = tp;
4590Sstevel@tonic-gate 			return;
4600Sstevel@tonic-gate 		}
4610Sstevel@tonic-gate 	}
4620Sstevel@tonic-gate 	zseek(out, bufs[NB-1].bno);
4630Sstevel@tonic-gate 	write(out, bufs[NB-1].block, BSIZ);
4640Sstevel@tonic-gate 	zseek(in, b);
4650Sstevel@tonic-gate 	read(in, bufs[NB-1].block, BSIZ);
4660Sstevel@tonic-gate 	bufs[NB-1].bno = b;
4670Sstevel@tonic-gate 	goto loop;
4680Sstevel@tonic-gate }
4690Sstevel@tonic-gate 
4700Sstevel@tonic-gate void
onintr(void)471*335Smuffin onintr(void)
4720Sstevel@tonic-gate {
4730Sstevel@tonic-gate 	unlink(picture);
4740Sstevel@tonic-gate 	exit(1);
4750Sstevel@tonic-gate }
4760Sstevel@tonic-gate 
477*335Smuffin 
478*335Smuffin int
zseek(int a,int b)479*335Smuffin zseek(int a, int b)
4800Sstevel@tonic-gate {
4810Sstevel@tonic-gate 	return (lseek(a, (long)b*512, 0));
4820Sstevel@tonic-gate }
483