xref: /onnv-gate/usr/src/lib/libplot/t300/common/subr.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate 
26*0Sstevel@tonic-gate /*
27*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28*0Sstevel@tonic-gate  * Use is subject to license terms.
29*0Sstevel@tonic-gate  */
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.3	*/
32*0Sstevel@tonic-gate /*LINTLIBRARY*/
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #include <signal.h>
35*0Sstevel@tonic-gate #include <stdio.h>
36*0Sstevel@tonic-gate #include <unistd.h>
37*0Sstevel@tonic-gate #include <stdlib.h>
38*0Sstevel@tonic-gate #include <plot.h>
39*0Sstevel@tonic-gate #include "con.h"
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate short
xconv(short xp)42*0Sstevel@tonic-gate xconv(short xp)
43*0Sstevel@tonic-gate {
44*0Sstevel@tonic-gate 	/*
45*0Sstevel@tonic-gate 	 * x position input is -2047 to +2047,
46*0Sstevel@tonic-gate 	 * output must be 0 to PAGSIZ*HORZRES
47*0Sstevel@tonic-gate 	 */
48*0Sstevel@tonic-gate 	xp += 2048;
49*0Sstevel@tonic-gate 	/* the computation is newx = xp*(PAGSIZ*HORZRES)/4096 */
50*0Sstevel@tonic-gate 	return (short)(xoffset + xp / xscale);
51*0Sstevel@tonic-gate }
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate short
yconv(short yp)54*0Sstevel@tonic-gate yconv(short yp)
55*0Sstevel@tonic-gate {
56*0Sstevel@tonic-gate 	/* see description of xconv */
57*0Sstevel@tonic-gate 	yp += 2048;
58*0Sstevel@tonic-gate 	return (short)(yp / yscale);
59*0Sstevel@tonic-gate }
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate void
inplot(void)62*0Sstevel@tonic-gate inplot(void)
63*0Sstevel@tonic-gate {
64*0Sstevel@tonic-gate 	spew(ACK);
65*0Sstevel@tonic-gate }
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate void
outplot(void)68*0Sstevel@tonic-gate outplot(void)
69*0Sstevel@tonic-gate {
70*0Sstevel@tonic-gate 	spew(ESC);
71*0Sstevel@tonic-gate 	spew(ACK);
72*0Sstevel@tonic-gate 	(void) fflush(stdout);
73*0Sstevel@tonic-gate }
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate void
spew(char ch)76*0Sstevel@tonic-gate spew(char ch)
77*0Sstevel@tonic-gate {
78*0Sstevel@tonic-gate 	if (ch == UP)
79*0Sstevel@tonic-gate 		(void) putc(ESC, stdout);
80*0Sstevel@tonic-gate 	(void) putc(ch, stdout);
81*0Sstevel@tonic-gate }
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate void
tobotleft(void)84*0Sstevel@tonic-gate tobotleft(void)
85*0Sstevel@tonic-gate {
86*0Sstevel@tonic-gate 	move(-2048, -2048);
87*0Sstevel@tonic-gate }
88*0Sstevel@tonic-gate 
89*0Sstevel@tonic-gate void
reset(void)90*0Sstevel@tonic-gate reset(void)
91*0Sstevel@tonic-gate {
92*0Sstevel@tonic-gate 	(void) signal(SIGINT, SIG_IGN);
93*0Sstevel@tonic-gate 	spew(BEL);
94*0Sstevel@tonic-gate 	(void) fflush(stdout);
95*0Sstevel@tonic-gate 	(void) ioctl(OUTF, TCSETAW, &ITTY);
96*0Sstevel@tonic-gate 	_exit(0);
97*0Sstevel@tonic-gate }
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate float
dist2(int x1,int y1,int x2,int y2)100*0Sstevel@tonic-gate dist2(int x1, int y1, int x2, int y2)
101*0Sstevel@tonic-gate {
102*0Sstevel@tonic-gate 	float t, v;
103*0Sstevel@tonic-gate 	t = x2 - x1;
104*0Sstevel@tonic-gate 	v = y1 - y2;
105*0Sstevel@tonic-gate 	return (t*t+v*v);
106*0Sstevel@tonic-gate }
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate void
swap(int * pa,int * pb)109*0Sstevel@tonic-gate swap(int *pa, int *pb)
110*0Sstevel@tonic-gate {
111*0Sstevel@tonic-gate 	int t;
112*0Sstevel@tonic-gate 	t = *pa;
113*0Sstevel@tonic-gate 	*pa = *pb;
114*0Sstevel@tonic-gate 	*pb = t;
115*0Sstevel@tonic-gate }
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate void
movep(short xg,short yg)118*0Sstevel@tonic-gate movep(short xg, short yg)
119*0Sstevel@tonic-gate {
120*0Sstevel@tonic-gate 	short i;
121*0Sstevel@tonic-gate 	char ch;
122*0Sstevel@tonic-gate 	if ((xg == xnow) && (yg == ynow))
123*0Sstevel@tonic-gate 		return;
124*0Sstevel@tonic-gate 	/* if we need to go to left margin, just CR */
125*0Sstevel@tonic-gate 	if (xg < (xnow / 2)) {
126*0Sstevel@tonic-gate 		spew(CR);
127*0Sstevel@tonic-gate 		xnow = 0;
128*0Sstevel@tonic-gate 	}
129*0Sstevel@tonic-gate 	i = (short)((xg - xnow) / HORZRES);
130*0Sstevel@tonic-gate 	if (xnow < xg)
131*0Sstevel@tonic-gate 		ch = RIGHT;
132*0Sstevel@tonic-gate 	else
133*0Sstevel@tonic-gate 		ch = LEFT;
134*0Sstevel@tonic-gate 	xnow += i * HORZRES;
135*0Sstevel@tonic-gate 	i = abs(i);
136*0Sstevel@tonic-gate 	while (i--)
137*0Sstevel@tonic-gate 		spew(ch);
138*0Sstevel@tonic-gate 	i = abs(xg-xnow);
139*0Sstevel@tonic-gate 	inplot();
140*0Sstevel@tonic-gate 	while (i--)
141*0Sstevel@tonic-gate 		spew(ch);
142*0Sstevel@tonic-gate 	outplot();
143*0Sstevel@tonic-gate 	i = (short)((yg - ynow) / VERTRES);
144*0Sstevel@tonic-gate 	if (ynow < yg)
145*0Sstevel@tonic-gate 		ch = UP;
146*0Sstevel@tonic-gate 	else ch = DOWN;
147*0Sstevel@tonic-gate 	ynow += i * VERTRES;
148*0Sstevel@tonic-gate 	i = abs(i);
149*0Sstevel@tonic-gate 	while (i--)
150*0Sstevel@tonic-gate 		spew(ch);
151*0Sstevel@tonic-gate 	i = abs(yg - ynow);
152*0Sstevel@tonic-gate 	inplot();
153*0Sstevel@tonic-gate 	while (i--)
154*0Sstevel@tonic-gate 		spew(ch);
155*0Sstevel@tonic-gate 	outplot();
156*0Sstevel@tonic-gate 	xnow = xg;
157*0Sstevel@tonic-gate 	ynow = yg;
158*0Sstevel@tonic-gate }
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate int
xsc(short xi)161*0Sstevel@tonic-gate xsc(short xi)
162*0Sstevel@tonic-gate {
163*0Sstevel@tonic-gate 	short xa;
164*0Sstevel@tonic-gate 	xa = (short)((xi - obotx) * scalex + botx);
165*0Sstevel@tonic-gate 	return (xa);
166*0Sstevel@tonic-gate }
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate int
ysc(short yi)169*0Sstevel@tonic-gate ysc(short yi)
170*0Sstevel@tonic-gate {
171*0Sstevel@tonic-gate 	short ya;
172*0Sstevel@tonic-gate 	ya = (short)((yi - oboty) * scaley + boty);
173*0Sstevel@tonic-gate 	return (ya);
174*0Sstevel@tonic-gate }
175