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
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.
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]
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 /* Copyright (c) 1979 Regents of the University of California */
32 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include <sys/types.h>
38 #include <sys/ttychars.h>
42 sccsid
[] = "@(#)tgoto.c 1.5 88/02/08 SMI"; /* from UCB 4.1 6/27/83 */
45 #define MAXRETURNSIZE 64
51 * Routine to perform cursor addressing.
52 * CM is a string containing printf type escapes to allow
53 * cursor addressing. We start out ready to print the destination
54 * line, and switch each time we print row or column.
55 * The following escapes are defined for substituting row/column:
60 * %. gives %c hacking special case characters
61 * %+x like %c but adding x first
63 * The codes below affect the state but don't use up a value.
65 * %>xy if value > x add y
66 * %r reverses row/column
67 * %i increments row/column (for one origin indexing)
69 * %B BCD (2 decimal digits encoded in one byte)
70 * %D Delta Data (backwards bcd)
72 * all other characters are ``self-inserting''.
76 tgoto(char *CM
, int destcol
, int destline
)
78 static char result
[MAXRETURNSIZE
];
79 static char added
[10];
89 * ``We don't do that under BOZO's big top''
94 while ((c
= *cp
++) != 0) {
116 *dp
++ = (which
/ 100) | '0';
122 *dp
++ = which
/ 10 | '0';
124 *dp
++ = which
% 10 | '0';
128 which
= oncol
? destcol
: destline
;
146 * This code is worth scratching your head at for a
147 * while. The idea is that various weird things can
148 * happen to nulls, EOT's, tabs, and newlines by the
149 * tty driver, arpanet, and so on, so we don't send
150 * them if we can help it.
152 * Tab is taken out to get Ann Arbors to work, otherwise
153 * when they go to column 9 we increment which is wrong
154 * because bcd isn't continuous. We should take out
155 * the rest too, or run the thing through more than
156 * once until it doesn't make any of these, but that
157 * would make termlib (and hence pdp-11 ex) bigger,
158 * and also somewhat slower. This requires all
159 * programs which use termlib to stty tabs so they
160 * don't get expanded. They should do this anyway
161 * because some terminals use ^I for other things,
162 * like nondestructive space.
164 if (which
== 0 || which
== CTRL('d') || which
== '\n') {
166 /* Assumption: backspace works */
168 * Loop needed because newline happens
169 * to be the successor of tab.
172 (void) strcat(added
, oncol
?
173 (BC
? BC
: "\b") : UP
);
175 } while (which
== '\n');
177 *dp
++ = (char) which
;
196 which
= (which
/10 << 4) + which
%10;
202 which
= which
- 2 * (which
%16);
210 (void) strcpy(dp
, added
);