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"
32 /*LINTLIBRARY*/
33
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <signal.h>
37 #include <unistd.h>
38 #include <plot.h>
39 #include "con.h"
40
41 int xnow, ynow, OUTF;
42
43 int
xconv(int xp)44 xconv(int xp)
45 {
46 /*
47 * x position input is -2047 to +2047,
48 * output must be 0 to PAGSIZ*HORZRES
49 */
50 xp += 2048;
51 /* the computation is newx = xp*(PAGSIZ*HORZRES)/4096 */
52 return (xoffset + xp / xscale);
53 }
54
55 int
yconv(int yp)56 yconv(int yp)
57 {
58 /* see description of xconv */
59 yp += 2048;
60 return (yp / yscale);
61 }
62
63 void
inplot(void)64 inplot(void)
65 {
66 spew(ESC);
67 spew(PLOTIN);
68 }
69
70 void
outplot(void)71 outplot(void)
72 {
73 spew(ESC);
74 spew(PLOTOUT);
75 (void) fflush(stdout);
76 }
77
78 void
spew(char ch)79 spew(char ch)
80 {
81 if (ch == UP) {
82 (void) putc(ESC, stdout);
83 ch = DOWN;
84 }
85 (void) putc(ch, stdout);
86 }
87
88 void
tobotleft(void)89 tobotleft(void)
90 {
91 move(-2048, -2048);
92 }
93
94 void
reset(void)95 reset(void)
96 {
97 (void) signal(SIGINT, SIG_IGN);
98 outplot();
99 (void) ioctl(OUTF, TCSETAW, &ITTY);
100 _exit(0);
101 }
102
103 float
dist2(int x1,int y1,int x2,int y2)104 dist2(int x1, int y1, int x2, int y2)
105 {
106 float t, v;
107 t = x2 - x1;
108 v = y1 - y2;
109 return (t * t + v * v);
110 }
111
112 void
swap(int * pa,int * pb)113 swap(int *pa, int *pb)
114 {
115 int t;
116 t = *pa;
117 *pa = *pb;
118 *pb = t;
119 }
120
121 void
movep(int xg,int yg)122 movep(int xg, int yg)
123 {
124 int i;
125 char ch;
126 if ((xg == xnow) && (yg == ynow))
127 return;
128 /* if we need to go to left margin, just CR */
129 if (xg < xnow / 2) {
130 spew(CR);
131 xnow = 0;
132 }
133 i = (int)((xg - xnow) / HORZRES);
134 if (xnow < xg)
135 ch = RIGHT;
136 else ch = LEFT;
137 xnow += i * HORZRES;
138 i = abs(i);
139 while (i--)
140 spew(ch);
141 i = abs(xg - xnow);
142 inplot();
143 while (i--)
144 spew(ch);
145 outplot();
146 i = (int)((yg - ynow) / VERTRES);
147 if (ynow < yg)
148 ch = UP;
149 else ch = DOWN;
150 ynow += i * VERTRES;
151 i = abs(i);
152 while (i--)
153 spew(ch);
154 i = abs(yg - ynow);
155 inplot();
156 while (i--)
157 spew(ch);
158 outplot();
159 xnow = xg; ynow = yg;
160 }
161
162 int
xsc(int xi)163 xsc(int xi)
164 {
165 int xa;
166 xa = (int)((xi - obotx) * scalex + botx);
167 return (xa);
168 }
169
170 int
ysc(int yi)171 ysc(int yi)
172 {
173 int ya;
174 ya = (int)((yi - oboty) *scaley +boty);
175 return (ya);
176 }
177