initial checkin

This commit is contained in:
gdr 1997-09-30 06:24:04 +00:00
parent d5a9505472
commit c6b6448216
12 changed files with 2087 additions and 0 deletions

27
lib/libtermcap/Makefile Normal file
View File

@ -0,0 +1,27 @@
# @(#)Makefile 8.1 (Berkeley) 6/4/93
LIB= termcap
SHLIB_MAJOR= 2
SHLIB_MINOR= 1
CFLAGS+=-DCM_N -DCM_GT -DCM_B -DCM_D -I${.CURDIR}
SRCS= termcap.c tgoto.c tputs.c tparm.c tospeed.c
MAN3= termcap.3
MLINKS= termcap.3 tgetent.3 termcap.3 tgetflag.3 termcap.3 tgetnum.3 \
termcap.3 tgetstr.3 termcap.3 tgoto.3 termcap.3 tputs.3 \
termcap.3 tparm.3
LINKS= ${LIBDIR}/libtermcap.a ${LIBDIR}/libtermlib.a
.if !defined(NOPIC)
LINKS+= ${SHLIBDIR}/libtermcap.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
${SHLIBDIR}/libtermlib.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
.endif
.if !defined(NOPROFILE)
LINKS+= ${LIBDIR}/libtermcap_p.a ${LIBDIR}/libtermlib_p.a
.endif
beforeinstall:
-cd ${.CURDIR}; cmp -s termcap.h ${DESTDIR}/usr/include/termcap.h || \
${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 444 termcap.h \
${DESTDIR}/usr/include
.include <bsd.lib.mk>

63
lib/libtermcap/TEST/tc1.c Normal file
View File

@ -0,0 +1,63 @@
/*-
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)tc1.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint */
/*
* tc1 [term]
* dummy program to test termlib.
* gets entry, counts it, and prints it.
*/
#include <stdio.h>
char buf[1024];
char *getenv();
main(argc, argv) char **argv; {
char *p;
int rc;
if (argc < 2)
p = getenv("TERM");
else
p = argv[1];
rc = tgetent(buf,p);
printf("tgetent returns %d, len=%d, text=\n'%s'\n",rc,strlen(buf),buf);
}

90
lib/libtermcap/TEST/tc2.c Normal file
View File

@ -0,0 +1,90 @@
/*-
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)tc2.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint */
/*
* tc2 [term]
* Dummy program to test out termlib.
* Commands are "tcc\n" where t is type (s for string, f for flag,
* or n for number) and cc is the name of the capability.
*/
#include <stdio.h>
char buf[1024];
char *getenv(), *tgetstr();
main(argc, argv) char **argv; {
char *p, *q;
int rc;
char b[3], c;
char area[200];
if (argc < 2)
p = getenv("TERM");
else
p = argv[1];
rc = tgetent(buf,p);
for (;;) {
c = getchar();
if (c < 0)
exit(0);
b[0] = getchar();
if (b[0] < ' ')
exit(0);
b[1] = getchar();
b[2] = 0;
getchar();
switch(c) {
case 'f':
printf("%s: %d\n",b,tgetflag(b));
break;
case 'n':
printf("%s: %d\n",b,tgetnum(b));
break;
case 's':
q = area;
printf("%s: %s\n",b,tgetstr(b,&q));
break;
default:
exit(0);
}
}
}

112
lib/libtermcap/TEST/tc3.c Normal file
View File

@ -0,0 +1,112 @@
/*-
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)tc3.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint */
/*
* tc3 [term]
* Dummy program to test out termlib. Input two numbers (row and col)
* and it prints out the tgoto string generated.
*/
#include <stdio.h>
char buf[1024];
char *getenv(), *tgetstr();
char *rdchar();
char *tgoto();
char *CM;
char cmbuff[30];
char *x;
char *UP;
char *tgout;
main(argc, argv) char **argv; {
char *p;
int rc;
int row, col;
if (argc < 2)
p = getenv("TERM");
else
p = argv[1];
rc = tgetent(buf,p);
x = cmbuff;
UP = tgetstr("up", &x);
printf("UP = %x = ", UP); pr(UP); printf("\n");
if (UP && *UP==0)
UP = 0;
CM = tgetstr("cm", &x);
printf("CM = "); pr(CM); printf("\n");
for (;;) {
if (scanf("%d %d", &row, &col) < 2)
exit(0);
tgout = tgoto(CM, col, row);
pr(tgout);
printf("\n");
}
}
pr(p)
register char *p;
{
for (; *p; p++)
printf("%s", rdchar(*p));
}
/*
* rdchar() returns a readable representation of an ASCII character
* using ^ for control, ' for meta.
*/
#include <ctype.h>
char *rdchar(c)
char c;
{
static char ret[4];
register char *p = ret;
if ((c&0377) > 0177)
*p++ = '\'';
c &= 0177;
if (!isprint(c))
*p++ = '^';
*p++ = (isprint(c) ? c : c^0100);
*p = 0;
return (ret);
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)pathnames.h 8.1 (Berkeley) 6/4/93
*/
#define _PATH_DEF ".termcap /usr/share/misc/termcap"

292
lib/libtermcap/termcap.3 Normal file
View File

@ -0,0 +1,292 @@
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)termcap.3 8.2 (Berkeley) 12/11/93
.\"
.TH TERMCAP 3 "September 1997" GNO "Library Routines"
.SH NAME
.BR tgetent ,
.BR tgetnum ,
.BR tgetflag ,
.BR tgetstr ,
.BR tgoto ,
.BR tputs ,
.BR tparm ,
.BR _set_ospeed
\- terminal independent operation routines
.SH SYNOPSIS
#include <termcap.h>
.sp 1
char
.BR PC ;
.br
.RB "char *" BC ;
.br
.RB "char *" UP ;
.br
short
.BR ospeed ;
.sp 1
int \fBtgetent\fR (char *\fIbp\fR, const char *\fIname\fR);
.br
int \fBtgetnum\fR (const char *\fIid\fR);
.br
int \fBtgetflag\fR (const char *\fIid\fR);
.br
char *\fBtgetstr\fR (const char *\fIid\fR, char **\fIarea\fR);
.br
char *\fBtgoto\fR (const char *\fIcm\fR, int \fIdestcol\fR, int \fIdestline\fR);
.br
int \fBtputs\fR (const char *\fIcp\fR, int \fIaffcnt\fR, int (*\fIoutc\fR)(int));
.br
char *\fBtparm\fR (const char *\fIcp\fR, ...);
.br
void \fB_set_ospeed\fR (long \fIspeed\fR);
.SH DESCRIPTION
These functions extract and use capabilities from a terminal capability data
base, usually
.BR /usr/share/misc/termcap ,
the format of which is described in
.BR termcap (5).
These are low level routines;
see
.BR curses (3)
for a higher level package.
.LP
The
.BR tgetent
function
extracts the entry for terminal
.I name
into the buffer at
.IR bp .
The
.I bp
argument
should be a character buffer of size
1024 and must be retained through all subsequent calls to
.BR tgetnum ,
.BR tgetflag ,
and
.BR tgetstr .
The
.BR tgetent
function
returns \-1 if none of the
.BR termcap
data base files could be opened,
0 if the terminal name given does not have an entry, and 1 if all goes well.
It will look in the environment for a
.BR TERMCAP
variable.
If found, and the value does not begin with a slash,
and the terminal type
.I name
is the same as the environment string
.BR TERM ,
the
.BR TERMCAP
string is used instead of reading a
.BR termcap
file.
If it does begin with a slash, the string is used as a path name
of the
.BR termcap
file to search.
If
.BR TERMCAP
does not begin with a slash and
.I name
is different from
.BR TERM ,
.BR tgetent
searches the files
.BR $HOME/.termcap
and
.BR /usr/share/misc/termcap ,
in that order, unless the environment variable
.BR TERMPATH
exists,
in which case it specifies a list of file pathnames
(separated by spaces or colons) to be searched instead.
Whenever multiple files are searched and a
.B tc
field occurs in the requested entry, the entry it names must be found
in the same file or one of the succeeding files.
This can speed up entry into programs that call
.BR tgetent ,
as well as help debug new terminal descriptions
or make one for your terminal if you can't write the file
.BR /usr/share/misc/termcap .
.LP
The
.BR tgetnum
function
gets the numeric value of capability
.IR id ,
returning \-1 if it is not given for the terminal.
The
.BR tgetflag
function
returns 1 if the specified capability is present in
the terminal's entry, 0 if it is not.
The
.BR tgetstr
function
returns the string value of the capability
.IR id ,
places it in the buffer at
.IR area ,
and advances the
.I area
pointer.
It decodes the abbreviations for this field described in
.BR termcap (5),
except for cursor addressing and padding information.
The
.BR tgetstr
function
returns
.BR NULL
if the capability was not found.
.LP
The
.BR tgoto
function
returns a cursor addressing string decoded from
.I cm
to go to column
.I destcol
in line
.IR destline .
It uses the external variables
.B UP
(from the
.B up
capability)
and
.B BC
(if
.B bc
is given rather than
.BR bs )
if necessary to avoid placing
.B \en ,
.BR ^D
or
.BR ^@
in
the returned string.
(Programs which call
.BR tgoto
should be sure to turn off the
.BR XTABS
bit(s),
since
.BR tgoto
may now output a tab.
Note that programs using termcap should in general turn off
.BR XTABS
anyway since some terminals use control-I for other functions,
such as nondestructive space.)
If a
.BR %
sequence is given which is not understood, then
.BR tgoto
returns
.BR OOPS .
.LP
The
.BR tputs
function
decodes the leading padding information of the string
.IR cp ,
.I affcnt
gives the number of lines affected by the operation, or 1 if this is
not applicable,
.I outc
is a routine which is called with each character in turn.
The external variable
.IR ospeed
should contain the output speed of the terminal as encoded by
.BR stty (3).
The
.BR _set_ospeed
functions converts any (not exactly matched only) numeric speed to
.BR stty (3)
encoded speed and set
.IR ospeed
variable.
The external variable
.IR PC
should contain a pad character to be used (from the
.B pc
capability)
if a null
.B ^@
is inappropriate.
.LP
The
.BR tparm
function
instantiates the string
.I cp
with given parameters.
A pointer is returned which points to
the result of
.I cp
with the parameters applied.
If a
.B %
sequence is given which is not understood, then
.BR tparm
returns
.BR OOPS .
.SH FILES
.RS
.IP \fB/usr/lib/libtermcap.a\fR
The
.BR ltermcap
library (also known as
.BR ltermlib ).
.IP \fB/usr/share/misc/termcap\fR
standard terminal capability data base
.IP \fB$HOME/.termcap\fR
user's terminal capability data base
.RE
.SH SEE ALSO
.BR ex (1),
.BR curses (3),
.BR termcap (5)
.SH HISTORY
The
.BR termcap
functions appeared in 4.0BSD.

263
lib/libtermcap/termcap.c Normal file
View File

@ -0,0 +1,263 @@
/*
* Copyright (c) 1980, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint */
#define PBUFSIZ 512 /* max length of filename path */
#define PVECSIZ 32 /* max number of names in path */
#define TBUFSIZ 1024 /* max length of tgetent buffer */
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <termios.h>
#include "termcap.h"
#include "pathnames.h"
extern void __set_ospeed(speed_t speed);
/*
* termcap - routines for dealing with the terminal capability data base
*
* BUG: Should use a "last" pointer in tbuf, so that searching
* for capabilities alphabetically would not be a n**2/2
* process when large numbers of capabilities are given.
* Note: If we add a last pointer now we will screw up the
* tc capability. We really should compile termcap.
*
* Essentially all the work here is scanning and decoding escapes
* in string capabilities. We don't use stdio because the editor
* doesn't, and because living w/o it is not hard.
*/
static char *tbuf; /* termcap buffer */
/*
* Get an entry for terminal name in buffer bp from the termcap file.
*/
int
tgetent(char *bp, const char *name)
{
register char *p;
register char *cp;
char *dummy;
char **fname;
char *home;
int i;
char pathbuf[PBUFSIZ]; /* holds raw path of filenames */
char *pathvec[PVECSIZ]; /* to point to names in pathbuf */
char **pvec; /* holds usable tail of path vector */
char *termpath;
struct termios tty;
dummy = NULL;
fname = pathvec;
pvec = pathvec;
tbuf = bp;
p = pathbuf;
cp = getenv("TERMCAP");
/*
* TERMCAP can have one of two things in it. It can be the
* name of a file to use instead of /etc/termcap. In this
* case it better start with a "/". Or it can be an entry to
* use so we don't have to read the file. In this case it
* has to already have the newlines crunched out. If TERMCAP
* does not hold a file name then a path of names is searched
* instead. The path is found in the TERMPATH variable, or
* becomes "$HOME/.termcap /etc/termcap" if no TERMPATH exists.
*/
if (!cp || *cp != '/') { /* no TERMCAP or it holds an entry */
if (termpath = getenv("TERMPATH"))
strncpy(pathbuf, termpath, PBUFSIZ);
else {
if (home = getenv("HOME")) { /* set up default */
p += strlen(home); /* path, looking in */
strcpy(pathbuf, home); /* $HOME first */
*p++ = '/';
} /* if no $HOME look in current directory */
strncpy(p, _PATH_DEF, PBUFSIZ - (p - pathbuf));
}
}
else /* user-defined name in TERMCAP */
strncpy(pathbuf, cp, PBUFSIZ); /* still can be tokenized */
*fname++ = pathbuf; /* tokenize path into vector of names */
while (*++p)
if (*p == ' ' || *p == ':') {
*p = '\0';
while (*++p)
if (*p != ' ' && *p != ':')
break;
if (*p == '\0')
break;
*fname++ = p;
if (fname >= pathvec + PVECSIZ) {
fname--;
break;
}
}
*fname = (char *) 0; /* mark end of vector */
if (cp && *cp && *cp != '/')
if (cgetset(cp) < 0)
return(-2);
i = cgetent(&dummy, pathvec, (char *)name);
if (i == 0) {
char *pd, *ps, *tok, *s, *tcs;
size_t len;
pd = bp;
ps = dummy;
if ((tok = strchr(ps, ':')) == NULL) {
len = strlen(ps);
if (len >= TBUFSIZ)
i = -1;
else
strcpy(pd, ps);
goto done;
}
len = tok - ps + 1;
if (pd + len + 1 - bp >= TBUFSIZ) {
i = -1;
goto done;
}
memcpy(pd, ps, len);
ps += len;
pd += len;
*pd = '\0';
tcs = pd - 1;
for (;;) {
while ((tok = strsep(&ps, ":")) != NULL &&
(*tok == '\0' || *tok == '\\' || !isgraph(*tok)))
;
if (tok == NULL)
break;
for (s = tcs; s != NULL && s[1] != '\0'; s = strchr(s, ':')) {
s++;
if (s[0] == tok[0] && s[1] == tok[1])
goto skip_it;
}
len = strlen(tok);
if (pd + len + 1 - bp >= TBUFSIZ) {
i = -1;
break;
}
memcpy(pd, tok, len);
pd += len;
*pd++ = ':';
*pd = '\0';
skip_it: ;
}
}
done:
if ( i == 0
&& ( tcgetattr(STDERR_FILENO, &tty) != -1
|| tcgetattr(STDOUT_FILENO, &tty) != -1
)
)
__set_ospeed(cfgetospeed(&tty));
if (dummy)
free(dummy);
/* no tc reference loop return code in libterm XXX */
if (i == -3)
return(-1);
return(i + 1);
}
/*
* Return the (numeric) option id.
* Numeric options look like
* li#80
* i.e. the option string is separated from the numeric value by
* a # character. If the option is not found we return -1.
* Note that we handle octal numbers beginning with 0.
*/
int
tgetnum(const char *id)
{
long num;
if (cgetnum(tbuf, (char *)id, &num) == 0)
return(num);
else
return(-1);
}
/*
* Handle a flag option.
* Flag options are given "naked", i.e. followed by a : or the end
* of the buffer. Return 1 if we find the option, or 0 if it is
* not given.
*/
int
tgetflag(const char *id)
{
return(cgetcap(tbuf, (char *)id, ':') != NULL);
}
/*
* Get a string valued option.
* These are given as
* cl=^Z
* Much decoding is done on the strings, and the strings are
* placed in area, which is a ref parameter which is updated.
* No checking on area overflow.
*/
char *
tgetstr(const char *id, char **area)
{
char ids[3];
char *s;
int i;
/*
* XXX
* This is for all the boneheaded programs that relied on tgetstr
* to look only at the first 2 characters of the string passed...
*/
*ids = *id;
ids[1] = id[1];
ids[2] = '\0';
if ((i = cgetstr(tbuf, ids, &s)) < 0)
return NULL;
strcpy(*area, s);
*area += i + 1;
return(s);
}

51
lib/libtermcap/termcap.h Normal file
View File

@ -0,0 +1,51 @@
/*
* Copyright (C) 1994,1995 by Andrey A. Chernov, Moscow, Russia.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* $Id: termcap.h,v 1.1 1997/09/30 06:23:55 gdr Exp $ */
#ifndef _TERMCAP_H_
#define _TERMCAP_H_
#include <sys/cdefs.h>
__BEGIN_DECLS
extern char PC, *UP, *BC;
extern short ospeed;
extern int tgetent __P((char *, const char *));
extern int tgetflag __P((const char *));
extern int tgetnum __P((const char *));
extern char *tgetstr __P((const char *, char **));
extern int tputs __P((const char *, int, int (*)(int)));
extern char *tgoto __P((const char *, int, int));
extern char *tparm __P((const char *, ...));
__END_DECLS
#endif /* _TERMCAP_H_ */

207
lib/libtermcap/tgoto.c Normal file
View File

@ -0,0 +1,207 @@
/*
* Copyright (c) 1980, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static char sccsid[] = "@(#)tgoto.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint */
#include "termcap.h"
#define CTRL(c) ((c) & 037)
#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.
* The following escapes are defined for substituting row/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
* %r reverses row/column
* %i increments row/column (for one origin indexing)
* %% gives %
* %B BCD (2 decimal digits encoded in one byte)
* %D Delta Data (backwards bcd)
*
* all other characters are ``self-inserting''.
*/
char *
tgoto(const char *CM, int destcol, int destline)
{
static char result[MAXRETURNSIZE];
static char added[10];
const char *cp = CM;
register char *dp = result;
register int c;
int oncol = 0;
register int which = destline;
if (cp == 0) {
toohard:
/*
* ``We don't do that under BOZO's big top''
*/
return ("OOPS");
}
added[0] = 0;
while (c = *cp++) {
if (c != '%') {
*dp++ = 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;
/* fall into... */
case '3':
*dp++ = (which / 100) | '0';
which %= 100;
/* fall into... */
case '2':
two:
*dp++ = which / 10 | '0';
one:
*dp++ = which % 10 | '0';
swap:
oncol = 1 - oncol;
setwhich:
which = oncol ? destcol : destline;
continue;
#ifdef CM_GT
case '>':
if (which > *cp++)
which += *cp++;
else
cp++;
continue;
#endif
case '+':
which += *cp++;
/* fall into... */
case '.':
casedot:
/*
* 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.
*/
if (which == 0 || which == CTRL('d') || /* which == '\t' || */ which == '\n') {
if (oncol || UP) /* Assumption: backspace works */
/*
* Loop needed because newline happens
* to be the successor of tab.
*/
do {
strcat(added, oncol ? (BC ? BC : "\b") : UP);
which++;
} while (which == '\n');
}
*dp++ = which;
goto swap;
case 'r':
oncol = 1;
goto setwhich;
case 'i':
destcol++;
destline++;
which++;
continue;
case '%':
*dp++ = c;
continue;
#ifdef CM_B
case 'B':
which = (which/10 << 4) + which%10;
continue;
#endif
#ifdef CM_D
case 'D':
which = which - 2 * (which%16);
continue;
#endif
default:
goto toohard;
}
}
strcpy(dp, added);
return (result);
}

72
lib/libtermcap/tospeed.c Normal file
View File

@ -0,0 +1,72 @@
/*
* Copyright (C) 1995 by Andrey A. Chernov, Moscow, Russia.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <termios.h>
#include "termcap.h"
static struct stable {
speed_t speed;
short code;
} table[] = {
{B115200,17},
{B57600, 16},
{B38400, 15},
{B19200, 14},
{B9600, 13},
{B4800, 12},
{B2400, 11},
{B1800, 10},
{B1200, 9},
{B600, 8},
{B300, 7},
{B200, 6},
{B150, 5},
{B134, 4},
{B110, 3},
{B75, 2},
{B50, 1},
{B0, 0},
{-1, -1}
};
void __set_ospeed(speed_t speed)
{
struct stable *stable;
if (speed == B0) {
ospeed = 0;
return;
}
for (stable = table; stable->speed > B0; stable++) {
/* nearest one, rounded down */
if (stable->speed <= speed) {
ospeed = stable->code;
return;
}
}
ospeed = 1; /* 50, min and not hangup */
}

753
lib/libtermcap/tparm.c Normal file
View File

@ -0,0 +1,753 @@
/*
* tparm.c
*
* By Ross Ridge
* Public Domain
* 92/02/01 07:30:36
*
*/
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "termcap.h"
#ifdef USE_SCCS_IDS
static const char SCCSid[] = "@(#) mytinfo tparm.c 3.2 92/02/01 public domain, By Ross Ridge";
#endif
#ifndef MAX_PUSHED
#define MAX_PUSHED 32
#endif
#define ARG 1
#define NUM 2
#define INTEGER 1
#define STRING 2
#define MAX_LINE 640
typedef void* anyptr;
typedef struct stack_str {
int type;
int argnum;
int value;
} stack;
static stack S[MAX_PUSHED];
static stack vars['z'-'a'+1];
static int pos = 0;
static struct arg_str {
int type;
int integer;
char *string;
} arg_list[10];
static int argcnt;
static va_list tparm_args;
static int
pusharg(arg)
int arg; {
if (pos == MAX_PUSHED)
return 1;
S[pos].type = ARG;
S[pos++].argnum = arg;
return 0;
}
static int
pushnum(num)
int num; {
if (pos == MAX_PUSHED)
return 1;
S[pos].type = NUM;
S[pos++].value = num;
return 0;
}
/* VARARGS2 */
static int
getarg(argnum, type, p)
int argnum, type;
anyptr p; {
while (argcnt < argnum) {
arg_list[argcnt].type = INTEGER;
arg_list[argcnt++].integer = (int) va_arg(tparm_args, int);
}
if (argcnt > argnum) {
if (arg_list[argnum].type != type)
return 1;
else if (type == STRING)
*(char **)p = arg_list[argnum].string;
else
*(int *)p = arg_list[argnum].integer;
} else {
arg_list[argcnt].type = type;
if (type == STRING)
*(char **)p = arg_list[argcnt++].string
= (char *) va_arg(tparm_args, char *);
else
*(int *)p = arg_list[argcnt++].integer = (int) va_arg(tparm_args, int);
}
return 0;
}
static int
popstring(str)
char **str; {
if (pos-- == 0)
return 1;
if (S[pos].type != ARG)
return 1;
return(getarg(S[pos].argnum, STRING, (anyptr) str));
}
static int
popnum(num)
int *num; {
if (pos-- == 0)
return 1;
switch (S[pos].type) {
case ARG:
return (getarg(S[pos].argnum, INTEGER, (anyptr) num));
case NUM:
*num = S[pos].value;
return 0;
}
return 1;
}
static int
cvtchar(sp, c)
register char *sp, *c; {
switch(*sp) {
case '\\':
switch(*++sp) {
case '\'':
case '$':
case '\\':
case '%':
*c = *sp;
return 2;
case '\0':
*c = '\\';
return 1;
case '0':
if (sp[1] == '0' && sp[2] == '0') {
*c = '\0';
return 4;
}
*c = '\200'; /* '\0' ???? */
return 2;
default:
*c = *sp;
return 2;
}
default:
*c = *sp;
return 1;
}
}
static int termcap;
/* sigh... this has got to be the ugliest code I've ever written.
Trying to handle everything has its cost, I guess.
It actually isn't to hard to figure out if a given % code is supposed
to be interpeted with its termcap or terminfo meaning since almost
all terminfo codes are invalid unless something has been pushed on
the stack and termcap strings will never push things on the stack
(%p isn't used by termcap). So where we have a choice we make the
decision by wether or not somthing has been pushed on the stack.
The static variable termcap keeps track of this; it starts out set
to 1 and is incremented as each argument processed by a termcap % code,
however if something is pushed on the stack it's set to 0 and the
rest of the % codes are interpeted as terminfo % codes. Another way
of putting it is that if termcap equals one we haven't decided either
way yet, if it equals zero we're looking for terminfo codes, and if
its greater than 1 we're looking for termcap codes.
Terminfo % codes:
%% output a '%'
%[[:][-+# ][width][.precision]][doxXs]
output pop according to the printf format
%c output pop as a char
%'c' push character constant c.
%{n} push decimal constant n.
%p[1-9] push paramter [1-9]
%g[a-z] push variable [a-z]
%P[a-z] put pop in variable [a-z]
%l push the length of pop (a string)
%+ add pop to pop and push the result
%- subtract pop from pop and push the result
%* multiply pop and pop and push the result
%& bitwise and pop and pop and push the result
%| bitwise or pop and pop and push the result
%^ bitwise xor pop and pop and push the result
%~ push the bitwise not of pop
%= compare if pop and pop are equal and push the result
%> compare if pop is less than pop and push the result
%< compare if pop is greater than pop and push the result
%A logical and pop and pop and push the result
%O logical or pop and pop and push the result
%! push the logical not of pop
%? condition %t if_true [%e if_false] %;
if condtion evaulates as true then evaluate if_true,
else evaluate if_false. elseif's can be done:
%? cond %t true [%e cond2 %t true2] ... [%e condN %t trueN] [%e false] %;
%i add one to parameters 1 and 2. (ANSI)
Termcap Codes:
%% output a %
%. output parameter as a character
%d output parameter as a decimal number
%2 output parameter in printf format %02d
%3 output parameter in printf format %03d
%+x add the character x to parameter and output it as a character
(UW) %-x subtract parameter FROM the character x and output it as a char
(UW) %ax add the character x to parameter
(GNU) %a[+*-/=][cp]x
GNU arithmetic.
(UW) %sx subtract parameter FROM the character x
%>xy if parameter > character x then add character y to parameter
%B convert to BCD (parameter = (parameter/10)*16 + parameter%16)
%D Delta Data encode (parameter = parameter - 2*(paramter%16))
%i increment the first two parameters by one
%n xor the first two parameters by 0140
(GNU) %m xor the first two parameters by 0177
%r swap the first two parameters
(GNU) %b backup to previous parameter
(GNU) %f skip this parameter
Note the two definitions of %a, the GNU defintion is used if the characters
after the 'a' are valid, otherwise the UW definition is used.
(GNU) used by GNU Emacs termcap libraries
(UW) used by the University of Waterloo (MFCF) termcap libraries
*/
char *tparm(const char *str, ...) {
static char OOPS[] = "OOPS";
static char buf[MAX_LINE];
register const char *sp;
register char *dp;
register char *fmt;
char conv_char