tgoto.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1997 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/* Copyright (c) 1979 Regents of the University of California */
#pragma ident "%Z%%M% %I% %E% SMI"
/*LINTLIBRARY*/
#include <string.h>
#include <sys/ttychars.h>
#if 0
static char
#endif
#define MAXRETURNSIZE 64
char *UP;
char *BC;
/*
* Routine to perform cursor addressing.
* CM is a string containing printf type escapes to allow
* cursor addressing. We start out ready to print the destination
* line, and switch each time we print row or column.
*
* %d as in printf
* %2 like %2d
* %3 like %3d
* %. gives %c hacking special case characters
* %+x like %c but adding x first
*
* The codes below affect the state but don't use up a value.
*
* %>xy if value > x add y
* %% gives %
* %B BCD (2 decimal digits encoded in one byte)
* %D Delta Data (backwards bcd)
*
* all other characters are ``self-inserting''.
*/
char *
{
static char result[MAXRETURNSIZE];
static char added[10];
int c;
int oncol = 0;
if (cp == 0) {
/*
* ``We don't do that under BOZO's big top''
*/
return ("OOPS");
}
added[0] = 0;
while ((c = *cp++) != 0) {
if (c != '%') {
*dp++ = (char) c;
continue;
}
switch (c = *cp++) {
#ifdef CM_N
case 'n':
destcol ^= 0140;
destline ^= 0140;
goto setwhich;
#endif
case 'd':
if (which < 10)
goto one;
if (which < 100)
goto two;
/*FALLTHRU*/
case '3':
which %= 100;
/*FALLTHRU*/
case '2':
two:
one:
swap:
continue;
#ifdef CM_GT
case '>':
else
cp++;
continue;
#endif
case '+':
/*FALLTHRU*/
case '.':
/*
* This code is worth scratching your head at for a
* while. The idea is that various weird things can
* happen to nulls, EOT's, tabs, and newlines by the
* tty driver, arpanet, and so on, so we don't send
* them if we can help it.
*
* Tab is taken out to get Ann Arbors to work, otherwise
* when they go to column 9 we increment which is wrong
* because bcd isn't continuous. We should take out
* the rest too, or run the thing through more than
* once until it doesn't make any of these, but that
* would make termlib (and hence pdp-11 ex) bigger,
* and also somewhat slower. This requires all
* programs which use termlib to stty tabs so they
* don't get expanded. They should do this anyway
* because some terminals use ^I for other things,
* like nondestructive space.
*/
/* Assumption: backspace works */
/*
* Loop needed because newline happens
* to be the successor of tab.
*/
do {
which++;
} while (which == '\n');
}
goto swap;
case 'r':
oncol = 1;
goto setwhich;
case 'i':
destcol++;
destline++;
which++;
continue;
case '%':
*dp++ = (char) c;
continue;
#ifdef CM_B
case 'B':
continue;
#endif
#ifdef CM_D
case 'D':
continue;
#endif
default:
goto toohard;
}
}
return (result);
}