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