1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1979 Regents of the University of California */
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
33*7c478bd9Sstevel@tonic-gate
34*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
35*7c478bd9Sstevel@tonic-gate
36*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
37*7c478bd9Sstevel@tonic-gate #include <string.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/ttychars.h>
39*7c478bd9Sstevel@tonic-gate
40*7c478bd9Sstevel@tonic-gate #if 0
41*7c478bd9Sstevel@tonic-gate static char
42*7c478bd9Sstevel@tonic-gate sccsid[] = "@(#)tgoto.c 1.5 88/02/08 SMI"; /* from UCB 4.1 6/27/83 */
43*7c478bd9Sstevel@tonic-gate #endif
44*7c478bd9Sstevel@tonic-gate
45*7c478bd9Sstevel@tonic-gate #define MAXRETURNSIZE 64
46*7c478bd9Sstevel@tonic-gate
47*7c478bd9Sstevel@tonic-gate char *UP;
48*7c478bd9Sstevel@tonic-gate char *BC;
49*7c478bd9Sstevel@tonic-gate
50*7c478bd9Sstevel@tonic-gate /*
51*7c478bd9Sstevel@tonic-gate * Routine to perform cursor addressing.
52*7c478bd9Sstevel@tonic-gate * CM is a string containing printf type escapes to allow
53*7c478bd9Sstevel@tonic-gate * cursor addressing. We start out ready to print the destination
54*7c478bd9Sstevel@tonic-gate * line, and switch each time we print row or column.
55*7c478bd9Sstevel@tonic-gate * The following escapes are defined for substituting row/column:
56*7c478bd9Sstevel@tonic-gate *
57*7c478bd9Sstevel@tonic-gate * %d as in printf
58*7c478bd9Sstevel@tonic-gate * %2 like %2d
59*7c478bd9Sstevel@tonic-gate * %3 like %3d
60*7c478bd9Sstevel@tonic-gate * %. gives %c hacking special case characters
61*7c478bd9Sstevel@tonic-gate * %+x like %c but adding x first
62*7c478bd9Sstevel@tonic-gate *
63*7c478bd9Sstevel@tonic-gate * The codes below affect the state but don't use up a value.
64*7c478bd9Sstevel@tonic-gate *
65*7c478bd9Sstevel@tonic-gate * %>xy if value > x add y
66*7c478bd9Sstevel@tonic-gate * %r reverses row/column
67*7c478bd9Sstevel@tonic-gate * %i increments row/column (for one origin indexing)
68*7c478bd9Sstevel@tonic-gate * %% gives %
69*7c478bd9Sstevel@tonic-gate * %B BCD (2 decimal digits encoded in one byte)
70*7c478bd9Sstevel@tonic-gate * %D Delta Data (backwards bcd)
71*7c478bd9Sstevel@tonic-gate *
72*7c478bd9Sstevel@tonic-gate * all other characters are ``self-inserting''.
73*7c478bd9Sstevel@tonic-gate */
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate char *
tgoto(char * CM,int destcol,int destline)76*7c478bd9Sstevel@tonic-gate tgoto(char *CM, int destcol, int destline)
77*7c478bd9Sstevel@tonic-gate {
78*7c478bd9Sstevel@tonic-gate static char result[MAXRETURNSIZE];
79*7c478bd9Sstevel@tonic-gate static char added[10];
80*7c478bd9Sstevel@tonic-gate char *cp = CM;
81*7c478bd9Sstevel@tonic-gate char *dp = result;
82*7c478bd9Sstevel@tonic-gate int c;
83*7c478bd9Sstevel@tonic-gate int oncol = 0;
84*7c478bd9Sstevel@tonic-gate int which = destline;
85*7c478bd9Sstevel@tonic-gate
86*7c478bd9Sstevel@tonic-gate if (cp == 0) {
87*7c478bd9Sstevel@tonic-gate toohard:
88*7c478bd9Sstevel@tonic-gate /*
89*7c478bd9Sstevel@tonic-gate * ``We don't do that under BOZO's big top''
90*7c478bd9Sstevel@tonic-gate */
91*7c478bd9Sstevel@tonic-gate return ("OOPS");
92*7c478bd9Sstevel@tonic-gate }
93*7c478bd9Sstevel@tonic-gate added[0] = 0;
94*7c478bd9Sstevel@tonic-gate while ((c = *cp++) != 0) {
95*7c478bd9Sstevel@tonic-gate if (c != '%') {
96*7c478bd9Sstevel@tonic-gate *dp++ = (char) c;
97*7c478bd9Sstevel@tonic-gate continue;
98*7c478bd9Sstevel@tonic-gate }
99*7c478bd9Sstevel@tonic-gate switch (c = *cp++) {
100*7c478bd9Sstevel@tonic-gate
101*7c478bd9Sstevel@tonic-gate #ifdef CM_N
102*7c478bd9Sstevel@tonic-gate case 'n':
103*7c478bd9Sstevel@tonic-gate destcol ^= 0140;
104*7c478bd9Sstevel@tonic-gate destline ^= 0140;
105*7c478bd9Sstevel@tonic-gate goto setwhich;
106*7c478bd9Sstevel@tonic-gate #endif
107*7c478bd9Sstevel@tonic-gate
108*7c478bd9Sstevel@tonic-gate case 'd':
109*7c478bd9Sstevel@tonic-gate if (which < 10)
110*7c478bd9Sstevel@tonic-gate goto one;
111*7c478bd9Sstevel@tonic-gate if (which < 100)
112*7c478bd9Sstevel@tonic-gate goto two;
113*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate case '3':
116*7c478bd9Sstevel@tonic-gate *dp++ = (which / 100) | '0';
117*7c478bd9Sstevel@tonic-gate which %= 100;
118*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/
119*7c478bd9Sstevel@tonic-gate
120*7c478bd9Sstevel@tonic-gate case '2':
121*7c478bd9Sstevel@tonic-gate two:
122*7c478bd9Sstevel@tonic-gate *dp++ = which / 10 | '0';
123*7c478bd9Sstevel@tonic-gate one:
124*7c478bd9Sstevel@tonic-gate *dp++ = which % 10 | '0';
125*7c478bd9Sstevel@tonic-gate swap:
126*7c478bd9Sstevel@tonic-gate oncol = 1 - oncol;
127*7c478bd9Sstevel@tonic-gate setwhich:
128*7c478bd9Sstevel@tonic-gate which = oncol ? destcol : destline;
129*7c478bd9Sstevel@tonic-gate continue;
130*7c478bd9Sstevel@tonic-gate
131*7c478bd9Sstevel@tonic-gate #ifdef CM_GT
132*7c478bd9Sstevel@tonic-gate case '>':
133*7c478bd9Sstevel@tonic-gate if (which > *cp++)
134*7c478bd9Sstevel@tonic-gate which += *cp++;
135*7c478bd9Sstevel@tonic-gate else
136*7c478bd9Sstevel@tonic-gate cp++;
137*7c478bd9Sstevel@tonic-gate continue;
138*7c478bd9Sstevel@tonic-gate #endif
139*7c478bd9Sstevel@tonic-gate
140*7c478bd9Sstevel@tonic-gate case '+':
141*7c478bd9Sstevel@tonic-gate which += *cp++;
142*7c478bd9Sstevel@tonic-gate /*FALLTHRU*/
143*7c478bd9Sstevel@tonic-gate
144*7c478bd9Sstevel@tonic-gate case '.':
145*7c478bd9Sstevel@tonic-gate /*
146*7c478bd9Sstevel@tonic-gate * This code is worth scratching your head at for a
147*7c478bd9Sstevel@tonic-gate * while. The idea is that various weird things can
148*7c478bd9Sstevel@tonic-gate * happen to nulls, EOT's, tabs, and newlines by the
149*7c478bd9Sstevel@tonic-gate * tty driver, arpanet, and so on, so we don't send
150*7c478bd9Sstevel@tonic-gate * them if we can help it.
151*7c478bd9Sstevel@tonic-gate *
152*7c478bd9Sstevel@tonic-gate * Tab is taken out to get Ann Arbors to work, otherwise
153*7c478bd9Sstevel@tonic-gate * when they go to column 9 we increment which is wrong
154*7c478bd9Sstevel@tonic-gate * because bcd isn't continuous. We should take out
155*7c478bd9Sstevel@tonic-gate * the rest too, or run the thing through more than
156*7c478bd9Sstevel@tonic-gate * once until it doesn't make any of these, but that
157*7c478bd9Sstevel@tonic-gate * would make termlib (and hence pdp-11 ex) bigger,
158*7c478bd9Sstevel@tonic-gate * and also somewhat slower. This requires all
159*7c478bd9Sstevel@tonic-gate * programs which use termlib to stty tabs so they
160*7c478bd9Sstevel@tonic-gate * don't get expanded. They should do this anyway
161*7c478bd9Sstevel@tonic-gate * because some terminals use ^I for other things,
162*7c478bd9Sstevel@tonic-gate * like nondestructive space.
163*7c478bd9Sstevel@tonic-gate */
164*7c478bd9Sstevel@tonic-gate if (which == 0 || which == CTRL('d') || which == '\n') {
165*7c478bd9Sstevel@tonic-gate if (oncol || UP)
166*7c478bd9Sstevel@tonic-gate /* Assumption: backspace works */
167*7c478bd9Sstevel@tonic-gate /*
168*7c478bd9Sstevel@tonic-gate * Loop needed because newline happens
169*7c478bd9Sstevel@tonic-gate * to be the successor of tab.
170*7c478bd9Sstevel@tonic-gate */
171*7c478bd9Sstevel@tonic-gate do {
172*7c478bd9Sstevel@tonic-gate (void) strcat(added, oncol ?
173*7c478bd9Sstevel@tonic-gate (BC ? BC : "\b") : UP);
174*7c478bd9Sstevel@tonic-gate which++;
175*7c478bd9Sstevel@tonic-gate } while (which == '\n');
176*7c478bd9Sstevel@tonic-gate }
177*7c478bd9Sstevel@tonic-gate *dp++ = (char) which;
178*7c478bd9Sstevel@tonic-gate goto swap;
179*7c478bd9Sstevel@tonic-gate
180*7c478bd9Sstevel@tonic-gate case 'r':
181*7c478bd9Sstevel@tonic-gate oncol = 1;
182*7c478bd9Sstevel@tonic-gate goto setwhich;
183*7c478bd9Sstevel@tonic-gate
184*7c478bd9Sstevel@tonic-gate case 'i':
185*7c478bd9Sstevel@tonic-gate destcol++;
186*7c478bd9Sstevel@tonic-gate destline++;
187*7c478bd9Sstevel@tonic-gate which++;
188*7c478bd9Sstevel@tonic-gate continue;
189*7c478bd9Sstevel@tonic-gate
190*7c478bd9Sstevel@tonic-gate case '%':
191*7c478bd9Sstevel@tonic-gate *dp++ = (char) c;
192*7c478bd9Sstevel@tonic-gate continue;
193*7c478bd9Sstevel@tonic-gate
194*7c478bd9Sstevel@tonic-gate #ifdef CM_B
195*7c478bd9Sstevel@tonic-gate case 'B':
196*7c478bd9Sstevel@tonic-gate which = (which/10 << 4) + which%10;
197*7c478bd9Sstevel@tonic-gate continue;
198*7c478bd9Sstevel@tonic-gate #endif
199*7c478bd9Sstevel@tonic-gate
200*7c478bd9Sstevel@tonic-gate #ifdef CM_D
201*7c478bd9Sstevel@tonic-gate case 'D':
202*7c478bd9Sstevel@tonic-gate which = which - 2 * (which%16);
203*7c478bd9Sstevel@tonic-gate continue;
204*7c478bd9Sstevel@tonic-gate #endif
205*7c478bd9Sstevel@tonic-gate
206*7c478bd9Sstevel@tonic-gate default:
207*7c478bd9Sstevel@tonic-gate goto toohard;
208*7c478bd9Sstevel@tonic-gate }
209*7c478bd9Sstevel@tonic-gate }
210*7c478bd9Sstevel@tonic-gate (void) strcpy(dp, added);
211*7c478bd9Sstevel@tonic-gate return (result);
212*7c478bd9Sstevel@tonic-gate }
213