import libterminfo, terminfo.db and stat command

This commit is contained in:
Vivek Prakash 2011-07-18 15:53:57 +02:00 committed by Ben Gras
parent 49cab1c73c
commit 51e66a47d8
41 changed files with 29803 additions and 5 deletions

View file

@ -12,8 +12,10 @@ SRCS= brac.c ch.c charset.c cmdbuf.c command.c decode.c edit.c \
linenum.c lsystem.c main.c mark.c optfunc.c option.c opttbl.c \
os.c output.c position.c prompt.c screen.c search.c signal.c \
tags.c ttyin.c version.c
#LDADD+= -ltermcap
.if defined(NBSD_LIBC) && (${NBSD_LIBC} != "no")
LDADD+= -ltermcap
DPADD+= ${LIBTERM}
.endif
MLINKS= less.1 more.1 less.1 page.1
LINKS= ${BINDIR}/less ${BINDIR}/more ${BINDIR}/less ${BINDIR}/page

View file

@ -1,3 +1,15 @@
20110716:
To install libterminfo and terminfo database, you need
the new stat:
# cd /usr/src/usr.bin/stat
# make clean install
You must create a directory /usr/share/terminfo for terminfo database
to be installed.
# make -C etc install
Then make clean world as normal.
20110708
* VFS and installed MFSes must be in sync before and after this change *

View file

@ -15,7 +15,7 @@ do
group="`echo $line | awk '{ print $3 }'`"
dir="`echo $line | awk '{ print $4 }'`"
mkdir -p $dir
targetdev="`stat -dev $dir/.`"
targetdev="`stat -f %d $dir/.`"
if [ $targetdev -eq 1 ]
then echo "skipping $dir properties"
else chown $owner $dir

View file

@ -73,6 +73,7 @@
755 root operator /usr/run
755 root operator /usr/share
755 root operator /usr/share/mk
755 root operator /usr/share/terminfo
755 root operator /usr/share/zoneinfo
755 root operator /usr/spool
711 root operator /usr/spool/at

View file

@ -21,7 +21,7 @@ SUBDIR= csu ${LIBCOMPAT_DIR} ${LIBC_DIR} libcurses libdriver libnetdriver \
libddekit
.if defined(NBSD_LIBC) && (${NBSD_LIBC} != "no")
SUBDIR+= libelf libminc libcrypt
SUBDIR+= libelf libminc libcrypt libterminfo
.endif
.if ${COMPILER_TYPE} == "ack"

113
lib/libterminfo/Makefile Normal file
View file

@ -0,0 +1,113 @@
# $NetBSD: Makefile,v 1.12 2010/07/06 05:59:53 mrg Exp $
.if defined(__MINIX)
.include "minix-config.inc"
USE_SHLIBDIR= no
.else
USE_SHLIBDIR= yes
.endif
LIB= terminfo
WARNS= 4
CPPFLAGS+= -I${.CURDIR}
SRCS= term.c ti.c setupterm.c curterm.c tparm.c tputs.c
SRCS+= compile.c hash.c
INCS= term.h
INCSDIR= /usr/include
MAN= terminfo.3 terminfo.5
MLINKS= terminfo.3 setupterm.3 \
terminfo.3 set_curterm.3 terminfo.3 del_curterm.3 \
terminfo.3 tigetnum.3 terminfo.3 tigetflag.3 \
terminfo.3 tigetstr.3 terminfo.3 tparm.3 terminfo.3 tputs.3 \
terminfo.3 putp.3 \
terminfo.3 ti_setupterm.3 terminfo.3 ti_getflag.3 \
terminfo.3 ti_getnum.3 terminfo.3 ti_getstr.3 \
terminfo.3 t_parm.3 terminfo.3 t_vparm.3 \
terminfo.3 ti_puts.3 terminfo.3 ti_putp.3
# Build in termcap emulation
SRCS+= termcap.c
INCS+= termcap.h
MAN+= termcap.3
MLINKS+= termcap.3 tgetent.3 termcap.3 tgetflag.3 termcap.3 tgetnum.3 \
termcap.3 tgetstr.3 termcap.3 tgoto.3
# Generate our string and hash tables
hash:
@echo "Generating terminfo hash"
cd ${.CURDIR} && ${HOST_SH} ./genhash >hash.c
@echo "Generating termcap hash"
cd ${.CURDIR} && ${HOST_SH} ./genthash >termcap_hash.c
# Generate our man pages
terminfo.5: terminfo.5.in term.h termcap_map.c
@echo "Generating terminfo man pages"
cd ${.CURDIR} && ${HOST_SH} ./genman >${.OBJDIR}/$@
CLEANFILES+= terminfo.5
# Allow terminfo descriptions to be compiled into libterminfo
compiled_terms:
@echo "Generating compiled terminfo descriptions"
cd ${.CURDIR} && ${HOST_SH} ./genterms >compiled_terms.c
man: terminfo.5
gen: hash compiled_terms man
.include <bsd.own.mk>
.if !defined(__MINIX)
.include <bsd.shlib.mk>
.endif
.if ${MKLINKLIB} != "no"
SYMLINKS+= libterminfo.a ${LIBDIR}/libtermcap.a
SYMLINKS+= libterminfo.a ${LIBDIR}/libtermlib.a
.endif
.if ${MKPROFILE} != "no"
SYMLINKS+= libterminfo_p.a ${LIBDIR}/libtermcap_p.a
SYMLINKS+= libterminfo_p.a ${LIBDIR}/libtermlib_p.a
.endif
.if ${MKPIC} != "no"
.if ${MKPICINSTALL} != "no"
SYMLINKS+= libterminfo_pic.a ${LIBDIR}/libtermcap_pic.a
SYMLINKS+= libterminfo_pic.a ${LIBDIR}/libtermlib_pic.a
.endif
.if exists(${.CURDIR}/shlib_version)
SYMLINKS+= libterminfo.so.${SHLIB_FULLVERSION} \
${_LIBSODIR}/libtermcap.so.0.6
SYMLINKS+= libterminfo.so.${SHLIB_FULLVERSION} \
${_LIBSODIR}/libtermlib.so.0.6
.if ${_LIBSODIR} != ${LIBDIR}
SYMLINKS+= libterminfo.so.${SHLIB_FULLVERSION} \
${LIBDIR}/libtermcap.so.0.6
SYMLINKS+= libterminfo.so.${SHLIB_FULLVERSION} \
${LIBDIR}/libtermlib.so.0.6
.endif
SYMLINKS+= libterminfo.so.${SHLIB_MAJOR} \
${_LIBSODIR}/libtermcap.so.0
SYMLINKS+= libterminfo.so ${_LIBSODIR}/libtermcap.so
SYMLINKS+= libterminfo.so.${SHLIB_MAJOR} \
${_LIBSODIR}/libtermlib.so.0
SYMLINKS+= libterminfo.so ${_LIBSODIR}/libtermlib.so
.if ${_LIBSODIR} != ${LIBDIR}
SYMLINKS+= libterminfo.so.${SHLIB_MAJOR} \
${LIBDIR}/libtermcap.so.0
SYMLINKS+= libterminfo.so ${LIBDIR}/libtermcap.so
SYMLINKS+= libterminfo.so.${SHLIB_MAJOR} \
${LIBDIR}/libtermlib.so.0
SYMLINKS+= libterminfo.so ${LIBDIR}/libtermlib.so
.endif
.endif # exists shlib_version
.endif # ${MKPIC} != "no"
.include <bsd.lib.mk>

665
lib/libterminfo/compile.c Normal file
View file

@ -0,0 +1,665 @@
/* $NetBSD: compile.c,v 1.4 2010/03/02 14:11:11 roy Exp $ */
/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
*
* 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.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: compile.c,v 1.4 2010/03/02 14:11:11 roy Exp $");
#if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
#endif
#include <assert.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <term_private.h>
#include <term.h>
static void __attribute__((__format__(__printf__, 2, 3)))
dowarn(int flags, const char *fmt, ...)
{
va_list va;
errno = EINVAL;
if (flags & TIC_WARNING) {
va_start(va, fmt);
vwarnx(fmt, va);
va_end(va);
}
}
char *
_ti_grow_tbuf(TBUF *tbuf, size_t len)
{
char *buf;
size_t l;
_DIAGASSERT(tbuf != NULL);
l = tbuf->bufpos + len;
if (l > tbuf->buflen) {
if (tbuf->bufpos == 0)
buf = malloc(l);
else
buf = realloc(tbuf->buf, l);
if (buf == NULL)
return NULL;
tbuf->buf = buf;
tbuf->buflen = l;
}
return tbuf->buf;
}
char *
_ti_find_cap(TBUF *tbuf, char type, short ind)
{
size_t n;
short num;
char *cap;
_DIAGASSERT(tbuf != NULL);
cap = tbuf->buf;
for (n = tbuf->entries; n > 0; n--) {
num = le16dec(cap);
cap += sizeof(uint16_t);
if (num == ind)
return cap;
switch (type) {
case 'f':
cap++;
break;
case 'n':
cap += sizeof(uint16_t);
break;
case 's':
num = le16dec(cap);
cap += sizeof(uint16_t);
cap += num;
break;
}
}
errno = ESRCH;
return NULL;
}
char *
_ti_find_extra(TBUF *tbuf, const char *code)
{
size_t n;
short num;
char *cap;
_DIAGASSERT(tbuf != NULL);
_DIAGASSERT(code != NULL);
cap = tbuf->buf;
for (n = tbuf->entries; n > 0; n--) {
num = le16dec(cap);
cap += sizeof(uint16_t);
if (strcmp(cap, code) == 0)
return cap + num;
cap += num;
switch (*cap++) {
case 'f':
cap++;
break;
case 'n':
cap += sizeof(uint16_t);
break;
case 's':
num = le16dec(cap);
cap += sizeof(uint16_t);
cap += num;
break;
}
}
errno = ESRCH;
return NULL;
}
size_t
_ti_store_extra(TIC *tic, int wrn, char *id, char type, char flag, short num,
char *str, size_t strl, int flags)
{
size_t l;
_DIAGASSERT(tic != NULL);
if (strcmp(id, "use") != 0) {
if (_ti_find_extra(&tic->extras, id) != NULL)
return 0;
if (!(flags & TIC_EXTRA)) {
if (wrn != 0)
dowarn(flags, "%s: %s: unknown capability",
tic->name, id);
return 0;
}
}
l = strlen(id) + 1;
if (l > UINT16_T_MAX) {
dowarn(flags, "%s: %s: cap name is too long", tic->name, id);
return 0;
}
if (!_ti_grow_tbuf(&tic->extras,
l + strl + (sizeof(uint16_t) * 2) + 1))
return 0;
le16enc(tic->extras.buf + tic->extras.bufpos, l);
tic->extras.bufpos += sizeof(uint16_t);
memcpy(tic->extras.buf + tic->extras.bufpos, id, l);
tic->extras.bufpos += l;
tic->extras.buf[tic->extras.bufpos++] = type;
switch (type) {
case 'f':
tic->extras.buf[tic->extras.bufpos++] = flag;
break;
case 'n':
le16enc(tic->extras.buf + tic->extras.bufpos, num);
tic->extras.bufpos += sizeof(uint16_t);
break;
case 's':
le16enc(tic->extras.buf + tic->extras.bufpos, strl);
tic->extras.bufpos += sizeof(uint16_t);
memcpy(tic->extras.buf + tic->extras.bufpos, str, strl);
tic->extras.bufpos += strl;
break;
}
tic->extras.entries++;
return 1;
}
ssize_t
_ti_flatten(uint8_t **buf, const TIC *tic)
{
size_t buflen, len, alen, dlen;
uint8_t *cap;
_DIAGASSERT(buf != NULL);
_DIAGASSERT(tic != NULL);
len = strlen(tic->name) + 1;
if (tic->alias == NULL)
alen = 0;
else
alen = strlen(tic->alias) + 1;
if (tic->desc == NULL)
dlen = 0;
else
dlen = strlen(tic->desc) + 1;
buflen = sizeof(char) +
sizeof(uint16_t) + len +
sizeof(uint16_t) + alen +
sizeof(uint16_t) + dlen +
(sizeof(uint16_t) * 2) + tic->flags.bufpos +
(sizeof(uint16_t) * 2) + tic->nums.bufpos +
(sizeof(uint16_t) * 2) + tic->strs.bufpos +
(sizeof(uint16_t) * 2) + tic->extras.bufpos;
*buf = malloc(buflen);
if (*buf == NULL)
return -1;
cap = *buf;
if (alen == 0 && dlen == 0 && tic->flags.bufpos == 0 &&
tic->nums.bufpos == 0 && tic->strs.bufpos == 0 &&
tic->extras.bufpos == 0)
*cap++ = 0; /* alias */
else
*cap++ = 2; /* version */
le16enc(cap, len);
cap += sizeof(uint16_t);
memcpy(cap, tic->name, len);
cap += len;
le16enc(cap, alen);
cap += sizeof(uint16_t);
if (tic->alias != NULL) {
memcpy(cap, tic->alias, alen);
cap += alen;
}
le16enc(cap, dlen);
cap += sizeof(uint16_t);
if (tic->desc != NULL) {
memcpy(cap, tic->desc, dlen);
cap += dlen;
}
if (tic->flags.entries == 0) {
le16enc(cap, 0);
cap += sizeof(uint16_t);
} else {
le16enc(cap, (tic->flags.bufpos + sizeof(uint16_t)));
cap += sizeof(uint16_t);
le16enc(cap, tic->flags.entries);
cap += sizeof(uint16_t);
memcpy(cap, tic->flags.buf, tic->flags.bufpos);
cap += tic->flags.bufpos;
}
if (tic->nums.entries == 0) {
le16enc(cap, 0);
cap += sizeof(uint16_t);
} else {
le16enc(cap, (tic->nums.bufpos + sizeof(uint16_t)));
cap += sizeof(uint16_t);
le16enc(cap, tic->nums.entries);
cap += sizeof(uint16_t);
memcpy(cap, tic->nums.buf, tic->nums.bufpos);
cap += tic->nums.bufpos;
}
if (tic->strs.entries == 0) {
le16enc(cap, 0);
cap += sizeof(uint16_t);
} else {
le16enc(cap, (tic->strs.bufpos + sizeof(uint16_t)));
cap += sizeof(uint16_t);
le16enc(cap, tic->strs.entries);
cap += sizeof(uint16_t);
memcpy(cap, tic->strs.buf, tic->strs.bufpos);
cap += tic->strs.bufpos;
}
if (tic->extras.entries == 0) {
le16enc(cap, 0);
cap += sizeof(uint16_t);
} else {
le16enc(cap, (tic->extras.bufpos + sizeof(uint16_t)));
cap += sizeof(uint16_t);
le16enc(cap, tic->extras.entries);
cap += sizeof(uint16_t);
memcpy(cap, tic->extras.buf, tic->extras.bufpos);
cap += tic->extras.bufpos;
}
return cap - *buf;
}
static int
encode_string(const char *term, const char *cap, TBUF *tbuf, const char *str,
int flags)
{
int slash, i, num;
char ch, *p, *s, last;
if (_ti_grow_tbuf(tbuf, strlen(str) + 1) == NULL)
return -1;
p = s = tbuf->buf + tbuf->bufpos;
slash = 0;
last = '\0';
/* Convert escape codes */
while ((ch = *str++) != '\0') {
if (slash == 0 && ch == '\\') {
slash = 1;
continue;
}
if (slash == 0) {
if (last != '%' && ch == '^') {
ch = *str++;
if (((unsigned char)ch) >= 128)
dowarn(flags,
"%s: %s: illegal ^ character",
term, cap);
if (ch == '\0')
break;
if (ch == '?')
ch = '\177';
else if ((ch &= 037) == 0)
ch = 128;
}
*p++ = ch;
last = ch;
continue;
}
slash = 0;
if (ch >= '0' && ch <= '7') {
num = ch - '0';
for (i = 0; i < 2; i++) {
if (*str < '0' || *str > '7') {
if (isdigit((unsigned char)*str))
dowarn(flags,
"%s: %s: non octal"
" digit", term, cap);
else
break;
}
num = num * 8 + *str++ - '0';
}
if (num == 0)
num = 0200;
*p++ = (char)num;
continue;
}
switch (ch) {
case 'a':
*p++ = '\a';
break;
case 'b':
*p++ = '\b';
break;
case 'e': /* FALLTHROUGH */
case 'E':
*p++ = '\033';
break;
case 'f':
*p++ = '\014';
break;
case 'l': /* FALLTHROUGH */
case 'n':
*p++ = '\n';
break;
case 'r':
*p++ = '\r';
break;
case 's':
*p++ = ' ';
break;
case 't':
*p++ = '\t';
break;
default:
/* We should warn here */
case '^':
case ',':
case ':':
case '|':
*p++ = ch;
break;
}
last = ch;
}
*p++ = '\0';
tbuf->bufpos += p - s;
return 0;
}
char *
_ti_get_token(char **cap, char sep)
{
char esc, *token;
while (isspace((unsigned char)**cap))
(*cap)++;
if (**cap == '\0')
return NULL;
/* We can't use stresep(3) as ^ we need two escape chars */
esc = '\0';
for (token = *cap;
**cap != '\0' && (esc != '\0' || **cap != sep);
(*cap)++)
{
if (esc == '\0') {
if (**cap == '\\' || **cap == '^')
esc = **cap;
} else {
/* termcap /E/ is valid */
if (sep == ':' && esc == '\\' && **cap == 'E')
esc = 'x';
else
esc = '\0';
}
}
if (**cap != '\0')
*(*cap)++ = '\0';
return token;
}
TIC *
_ti_compile(char *cap, int flags)
{
char *token, *p, *e, *name, *desc, *alias;
signed char flag;
long num;
ssize_t ind;
size_t len;
TBUF buf;
TIC *tic;
_DIAGASSERT(cap != NULL);
name = _ti_get_token(&cap, ',');
if (name == NULL) {
dowarn(flags, "no seperator found: %s", cap);
return NULL;
}
desc = strrchr(name, '|');
if (desc != NULL)
*desc++ = '\0';
alias = strchr(name, '|');
if (alias != NULL)
*alias++ = '\0';
tic = calloc(sizeof(*tic), 1);
if (tic == NULL)
return NULL;
buf.buf = NULL;
buf.buflen = 0;
tic->name = strdup(name);
if (tic->name == NULL)
goto error;
if (alias != NULL && flags & TIC_ALIAS) {
tic->alias = strdup(alias);
if (tic->alias == NULL)
goto error;
}
if (desc != NULL && flags & TIC_DESCRIPTION) {
tic->desc = strdup(desc);
if (tic->desc == NULL)
goto error;
}
for (token = _ti_get_token(&cap, ',');
token != NULL && *token != '\0';
token = _ti_get_token(&cap, ','))
{
/* Skip commented caps */
if (!(flags & TIC_COMMENT) && token[0] == '.')
continue;
/* Obsolete entries */
if (token[0] == 'O' && token[1] == 'T') {
if (!(flags & TIC_EXTRA))
continue;
token += 2;
}
/* str cap */
p = strchr(token, '=');
if (p != NULL) {
*p++ = '\0';
/* Don't use the string if we already have it */
ind = _ti_strindex(token);
if (ind != -1 &&
_ti_find_cap(&tic->strs, 's', ind) != NULL)
continue;
/* Encode the string to our scratch buffer */
buf.bufpos = 0;
if (encode_string(tic->name, token,
&buf, p, flags) == -1)
goto error;
if (buf.bufpos > UINT16_T_MAX) {
dowarn(flags, "%s: %s: string is too long",
tic->name, token);
continue;
}
if (!VALID_STRING(buf.buf)) {
dowarn(flags, "%s: %s: invalid string",
tic->name, token);
continue;
}
if (ind == -1)
_ti_store_extra(tic, 1, token, 's', -1, -2,
buf.buf, buf.bufpos, flags);
else {
if (!_ti_grow_tbuf(&tic->strs,
(sizeof(uint16_t) * 2) + buf.bufpos))
goto error;
le16enc(tic->strs.buf + tic->strs.bufpos, ind);
tic->strs.bufpos += sizeof(uint16_t);
le16enc(tic->strs.buf + tic->strs.bufpos,
buf.bufpos);
tic->strs.bufpos += sizeof(uint16_t);
memcpy(tic->strs.buf + tic->strs.bufpos,
buf.buf, buf.bufpos);
tic->strs.bufpos += buf.bufpos;
tic->strs.entries++;
}
continue;
}
/* num cap */
p = strchr(token, '#');
if (p != NULL) {
*p++ = '\0';
/* Don't use the number if we already have it */
ind = _ti_numindex(token);
if (ind != -1 &&
_ti_find_cap(&tic->nums, 'n', ind) != NULL)
continue;
num = strtol(p, &e, 0);
if (*e != '\0') {
dowarn(flags, "%s: %s: not a number",
tic->name, token);
continue;
}
if (!VALID_NUMERIC(num)) {
dowarn(flags, "%s: %s: number out of range",
tic->name, token);
continue;
}
if (ind == -1)
_ti_store_extra(tic, 1, token, 'n', -1,
num, NULL, 0, flags);
else {
if (_ti_grow_tbuf(&tic->nums,
sizeof(uint16_t) * 2) == NULL)
goto error;
le16enc(tic->nums.buf + tic->nums.bufpos, ind);
tic->nums.bufpos += sizeof(uint16_t);
le16enc(tic->nums.buf + tic->nums.bufpos, num);
tic->nums.bufpos += sizeof(uint16_t);
tic->nums.entries++;
}
continue;
}
flag = 1;
len = strlen(token) - 1;
if (token[len] == '@') {
flag = CANCELLED_BOOLEAN;
token[len] = '\0';
}
ind = _ti_flagindex(token);
if (ind == -1 && flag == CANCELLED_BOOLEAN) {
if ((ind = _ti_numindex(token)) != -1) {
if (_ti_find_cap(&tic->nums, 'n', ind) != NULL)
continue;
if (_ti_grow_tbuf(&tic->nums,
sizeof(uint16_t) * 2) == NULL)
goto error;
le16enc(tic->nums.buf + tic->nums.bufpos, ind);
tic->nums.bufpos += sizeof(uint16_t);
le16enc(tic->nums.buf + tic->nums.bufpos,
CANCELLED_NUMERIC);
tic->nums.bufpos += sizeof(uint16_t);
tic->nums.entries++;
continue;
} else if ((ind = _ti_strindex(token)) != -1) {
if (_ti_find_cap(&tic->strs, 's', ind) != NULL)
continue;
if (_ti_grow_tbuf(&tic->strs,
(sizeof(uint16_t) * 2) + 1) == NULL)
goto error;
le16enc(tic->strs.buf + tic->strs.bufpos, ind);
tic->strs.bufpos += sizeof(uint16_t);
le16enc(tic->strs.buf + tic->strs.bufpos, 0);
tic->strs.bufpos += sizeof(uint16_t);
tic->strs.entries++;
continue;
}
}
if (ind == -1)
_ti_store_extra(tic, 1, token, 'f', flag, 0, NULL, 0,
flags);
else if (_ti_find_cap(&tic->flags, 'f', ind) == NULL) {
if (_ti_grow_tbuf(&tic->flags, sizeof(uint16_t) + 1)
== NULL)
goto error;
le16enc(tic->flags.buf + tic->flags.bufpos, ind);
tic->flags.bufpos += sizeof(uint16_t);
tic->flags.buf[tic->flags.bufpos++] = flag;
tic->flags.entries++;
}
}
free(buf.buf);
return tic;
error:
free(buf.buf);
_ti_freetic(tic);
return NULL;
}
void
_ti_freetic(TIC *tic)
{
if (tic != NULL) {
free(tic->name);
free(tic->alias);
free(tic->desc);
free(tic->flags.buf);
free(tic->nums.buf);
free(tic->strs.buf);
free(tic);
}
}

View file

@ -0,0 +1,520 @@
/* $NetBSD: compiled_terms.c,v 1.1 2010/02/12 12:18:33 roy Exp $ */
/* DO NOT EDIT
* Regenerate by doing `make compiled_terms`
*/
struct compiled_term {
const char *name;
const char *cap;
size_t caplen;
};
const struct compiled_term compiled_terms[] = {
{
"ansi",
"\002\005\000\141\156\163\151\000\000\000\000\000\016\000\004"
"\000\036\000\001\001\000\001\026\000\001\027\000\001\032\000"
"\006\000\016\000\010\000\025\000\003\000\021\000\100\000\004"
"\000\120\000\007\000\010\000\012\000\030\000\142\003\107\000"
"\200\001\013\000\033\133\045\151\045\144\073\045\144\122\000"
"\201\001\005\000\033\133\066\156\000\202\001\023\000\033\133"
"\077\045\133\073\060\061\062\063\064\065\066\067\070\071\135"
"\143\000\203\001\004\000\033\133\143\000\052\001\011\000\033"
"\133\063\071\073\064\071\155\000\132\001\012\000\033\133\064"
"\045\160\061\045\144\155\000\133\001\012\000\033\133\063\045"
"\160\061\045\144\155\000\110\000\005\000\033\133\070\155\000"
"\134\001\126\000\033\133\060\073\061\060\045\077\045\160\061"
"\045\164\073\067\045\073\045\077\045\160\062\045\164\073\064"
"\045\073\045\077\045\160\063\045\164\073\067\045\073\045\077"
"\045\160\064\045\164\073\065\045\073\045\077\045\160\066\045"
"\164\073\061\045\073\045\077\045\160\067\045\164\073\070\045"
"\073\045\077\045\160\071\045\164\073\061\061\045\073\155\000"
"\063\000\005\000\033\133\065\155\000\064\000\005\000\033\133"
"\061\155\000\105\000\005\000\033\133\067\155\000\135\000\006"
"\000\033\133\061\060\155\000\140\000\004\000\033\133\155\000"
"\143\000\004\000\033\133\155\000\125\000\010\000\033\133\060"
"\073\061\060\155\000\103\000\006\000\033\133\061\061\155\000"
"\112\000\005\000\033\133\067\155\000\116\000\005\000\033\133"
"\064\155\000\000\000\077\000\053\020\054\021\055\030\056\031"
"\060\333\140\004\141\261\146\370\147\361\150\260\152\331\153"
"\277\154\332\155\300\156\305\157\176\160\304\161\304\162\304"
"\163\137\164\303\165\264\166\301\167\302\170\263\171\363\172"
"\362\173\343\174\330\175\234\176\376\000\123\000\006\000\033"
"\133\061\060\155\000\061\000\006\000\033\133\061\061\155\000"
"\063\001\011\000\033\133\045\160\061\045\144\104\000\056\001"
"\011\000\033\133\045\160\061\045\144\102\000\065\001\011\000"
"\033\133\045\160\061\045\144\103\000\070\001\011\000\033\133"
"\045\160\061\045\144\101\000\054\001\011\000\033\133\045\160"
"\061\045\144\120\000\055\001\011\000\033\133\045\160\061\045"
"\144\115\000\122\000\011\000\033\133\045\160\061\045\144\130"
"\000\022\000\005\000\033\133\061\113\000\027\000\013\000\033"
"\133\045\151\045\160\061\045\144\107\000\166\001\004\000\033"
"\133\111\000\060\001\011\000\033\133\045\160\061\045\144\100"
"\000\062\001\011\000\033\133\045\160\061\045\144\114\000\061"
"\001\011\000\033\133\045\160\061\045\144\123\000\173\000\002"
"\000\010\000\175\000\004\000\033\133\132\000\326\000\004\000"
"\033\133\104\000\212\000\004\000\033\133\102\000\351\000\004"
"\000\033\133\103\000\015\001\004\000\033\133\101\000\324\000"
"\004\000\033\133\114\000\102\001\005\000\033\133\064\151\000"
"\103\001\005\000\033\133\065\151\000\047\001\005\000\015\033"
"\133\123\000\107\001\024\000\045\160\061\045\143\033\133\045"
"\160\062\045\173\061\175\045\055\045\144\142\000\067\001\011"
"\000\033\133\045\160\061\045\144\124\000\125\001\004\000\033"
"\050\102\000\126\001\004\000\033\051\102\000\127\001\004\000"
"\033\052\102\000\130\001\004\000\033\053\102\000\017\000\005"
"\000\033\133\062\147\000\117\001\013\000\033\133\045\151\045"
"\160\061\045\144\144\000\003\000\002\000\007\000\002\000\004"
"\000\033\133\132\000\021\000\007\000\033\133\110\033\133\112"
"\000\007\000\002\000\015\000\036\000\004\000\033\133\104\000"
"\033\000\004\000\033\133\102\000\041\000\004\000\033\133\103"
"\000\032\000\021\000\033\133\045\151\045\160\061\045\144\073"
"\045\160\062\045\144\110\000\043\000\004\000\033\133\101\000"
"\047\000\004\000\033\133\120\000\050\000\004\000\033\133\115"
"\000\024\000\004\000\033\133\112\000\023\000\004\000\033\133"
"\113\000\034\000\004\000\033\133\110\000\153\001\003\000\033"
"\110\000\166\000\004\000\033\133\114\000\122\001\002\000\012"
"\000\323\000\004\000\033\133\110\000\020\000\002\000\003\000"
"\101\130\000\146\001\003\000\142\163\000\146\001",
942
},
{
"dumb",
"\002\005\000\144\165\155\142\000\000\000\000\000\005\000\001"
"\000\001\000\001\006\000\001\000\004\000\120\000\032\000\004"
"\000\003\000\002\000\007\000\007\000\002\000\015\000\033\000"
"\002\000\012\000\122\001\002\000\012\000\000\000",
57
},
{
"vt100",
"\002\006\000\166\164\061\060\060\000\000\000\000\000\021\000"
"\005\000\001\000\001\036\000\001\027\000\001\011\000\001\044"
"\000\001\022\000\004\000\004\000\120\000\007\000\010\000\012"
"\000\030\000\036\000\003\000\100\003\107\000\000\000\063\000"
"\140\140\141\141\146\146\147\147\152\152\153\153\154\154\155"
"\155\156\156\157\157\160\160\161\161\162\162\163\163\164\164"
"\165\165\166\166\167\167\170\170\171\171\172\172\173\173\174"
"\174\175\175\176\176\000\003\000\002\000\007\000\063\000\011"
"\000\033\133\065\155\044\074\062\076\000\064\000\011\000\033"
"\133\061\155\044\074\062\076\000\021\000\014\000\033\133\110"
"\033\133\112\044\074\065\060\076\000\007\000\002\000\015\000"
"\014\000\021\000\033\133\045\151\045\160\061\045\144\073\045"
"\160\062\045\144\162\000\063\001\011\000\033\133\045\160\061"
"\045\144\104\000\036\000\002\000\010\000\056\001\011\000\033"
"\133\045\160\061\045\144\102\000\033\000\002\000\012\000\065"
"\001\011\000\033\133\045\160\061\045\144\103\000\041\000\010"
"\000\033\133\103\044\074\062\076\000\032\000\025\000\033\133"
"\045\151\045\160\061\045\144\073\045\160\062\045\144\110\044"
"\074\065\076\000\070\001\011\000\033\133\045\160\061\045\144"
"\101\000\043\000\010\000\033\133\101\044\074\062\076\000\024"
"\000\011\000\033\133\112\044\074\065\060\076\000\023\000\010"
"\000\033\133\113\044\074\063\076\000\022\000\011\000\033\133"
"\061\113\044\074\063\076\000\057\000\007\000\033\050\102\033"
"\051\060\000\034\000\004\000\033\133\110\000\166\001\002\000"
"\011\000\153\001\003\000\033\110\000\122\001\002\000\012\000"
"\173\000\002\000\010\000\326\000\004\000\033\117\104\000\212"
"\000\004\000\033\117\102\000\351\000\004\000\033\117\103\000"
"\015\001\004\000\033\117\101\000\021\001\004\000\160\146\061"
"\000\022\001\004\000\160\146\062\000\023\001\004\000\160\146"
"\063\000\024\001\004\000\160\146\064\000\100\001\005\000\033"
"\133\060\151\000\102\001\005\000\033\133\064\151\000\103\001"
"\005\000\033\133\065\151\000\116\001\003\000\033\070\000\105"
"\000\011\000\033\133\067\155\044\074\062\076\000\123\001\007"
"\000\033\115\044\074\065\076\000\123\000\002\000\017\000\124"
"\000\006\000\033\133\077\067\154\000\016\001\010\000\033\133"
"\077\061\154\033\076\000\140\000\010\000\033\133\155\044\074"
"\062\076\000\143\000\010\000\033\133\155\044\074\062\076\000"
"\113\001\034\000\033\076\033\133\077\063\154\033\133\077\064"
"\154\033\133\077\065\154\033\133\077\067\150\033\133\077\070"
"\150\000\120\001\003\000\033\067\000\134\001\114\000\033\133"
"\060\045\077\045\160\061\045\160\066\045\174\045\164\073\061"
"\045\073\045\077\045\160\062\045\164\073\064\045\073\045\077"
"\045\160\061\045\160\063\045\174\045\164\073\067\045\073\045"
"\077\045\160\064\045\164\073\065\045\073\155\045\077\045\160"
"\071\045\164\016\045\145\017\045\073\044\074\062\076\000\125"
"\000\011\000\033\133\155\017\044\074\062\076\000\061\000\002"
"\000\016\000\062\000\006\000\033\133\077\067\150\000\017\001"
"\010\000\033\133\077\061\150\033\075\000\112\000\011\000\033"
"\133\067\155\044\074\062\076\000\116\000\011\000\033\133\064"
"\155\044\074\062\076\000\017\000\005\000\033\133\063\147\000"
"\221\000\004\000\033\117\171\000\233\000\004\000\033\117\170"
"\000\226\000\004\000\033\117\164\000\227\000\004\000\033\117"
"\165\000\230\000\004\000\033\117\166\000\231\000\004\000\033"
"\117\154\000\232\000\004\000\033\117\167\000\215\000\004\000"
"\033\117\115\000\222\000\004\000\033\117\120\000\223\000\004"
"\000\033\117\121\000\224\000\004\000\033\117\122\000\225\000"
"\004\000\033\117\123\000\170\000\004\000\033\117\161\000\171"
"\000\004\000\033\117\163\000\172\000\004\000\033\117\162\000"
"\176\000\004\000\033\117\160\000\177\000\004\000\033\117\156"
"\000\011\000\001\000\003\000\142\163\000\146\001",
897
},
{
"vt220",
"\002\006\000\166\164\062\062\060\000\000\000\000\000\024\000"
"\006\000\001\000\001\036\000\001\026\000\001\027\000\001\011"
"\000\001\044\000\001\022\000\004\000\004\000\120\000\007\000"
"\010\000\012\000\030\000\036\000\003\000\367\003\132\000\000"
"\000\063\000\140\140\141\141\146\146\147\147\152\152\153\153"
"\154\154\155\155\156\156\157\157\160\160\161\161\162\162\163"
"\163\164\164\165\165\166\166\167\167\170\170\171\171\172\172"
"\173\173\174\174\175\175\176\176\000\003\000\002\000\007\000"
"\063\000\005\000\033\133\065\155\000\064\000\005\000\033\133"
"\061\155\000\021\000\007\000\033\133\110\033\133\112\000\007"
"\000\002\000\015\000\014\000\021\000\033\133\045\151\045\160"
"\061\045\144\073\045\160\062\045\144\162\000\063\001\011\000"
"\033\133\045\160\061\045\144\104\000\036\000\002\000\010\000"
"\056\001\011\000\033\133\045\160\061\045\144\102\000\033\000"
"\002\000\012\000\065\001\011\000\033\133\045\160\061\045\144"
"\103\000\041\000\004\000\033\133\103\000\032\000\021\000\033"
"\133\045\151\045\160\061\045\144\073\045\160\062\045\144\110"
"\000\070\001\011\000\033\133\045\160\061\045\144\101\000\043"
"\000\004\000\033\133\101\000\054\001\011\000\033\133\045\160"
"\061\045\144\120\000\047\000\004\000\033\133\120\000\055\001"
"\011\000\033\133\045\160\061\045\144\115\000\050\000\004\000"
"\033\133\115\000\122\000\011\000\033\133\045\160\061\045\144"
"\130\000\024\000\004\000\033\133\112\000\023\000\004\000\033"
"\133\113\000\022\000\005\000\033\133\061\113\000\057\000\004"
"\000\033\051\060\000\150\000\022\000\033\133\077\065\150\044"
"\074\062\060\060\057\076\033\133\077\065\154\000\034\000\004"
"\000\033\133\110\000\166\001\002\000\011\000\153\001\003\000"
"\033\110\000\060\001\011\000\033\133\045\160\061\045\144\100"
"\000\161\000\030\000\057\165\163\162\057\163\150\141\162\145"
"\057\164\141\142\163\145\164\057\166\164\061\060\060\000\062"
"\001\011\000\033\133\045\160\061\045\144\114\000\166\000\004"
"\000\033\133\114\000\122\001\003\000\033\104\000\157\000\026"
"\000\033\133\077\067\150\033\133\076\033\133\077\061\150\033"
"\040\106\033\133\077\064\154\000\173\000\002\000\010\000\326"
"\000\004\000\033\133\104\000\212\000\004\000\033\133\102\000"
"\351\000\004\000\033\133\103\000\015\001\004\000\033\133\101"
"\000\222\000\004\000\033\117\120\000\233\000\006\000\033\133"
"\062\061\176\000\234\000\006\000\033\133\062\063\176\000\235"
"\000\006\000\033\133\062\064\176\000\236\000\006\000\033\133"
"\062\065\176\000\237\000\006\000\033\133\062\066\176\000\242"
"\000\006\000\033\133\063\061\176\000\243\000\006\000\033\133"
"\063\062\176\000\244\000\006\000\033\133\063\063\176\000\223"
"\000\004\000\033\117\121\000\245\000\006\000\033\133\063\064"
"\176\000\224\000\004\000\033\117\122\000\225\000\004\000\033"
"\117\123\000\227\000\006\000\033\133\061\067\176\000\230\000"
"\006\000\033\133\061\070\176\000\231\000\006\000\033\133\061"
"\071\176\000\232\000\006\000\033\133\062\060\176\000\321\000"
"\005\000\033\133\061\176\000\322\000\006\000\033\133\062\070"
"\176\000\324\000\005\000\033\133\062\176\000\335\000\005\000"
"\033\133\066\176\000\340\000\005\000\033\133\065\176\000\343"
"\000\006\000\033\133\062\071\176\000\362\000\005\000\033\133"
"\064\176\000\021\001\004\000\160\146\061\000\022\001\004\000"
"\160\146\062\000\023\001\004\000\160\146\063\000\024\001\004"
"\000\160\146\064\000\100\001\004\000\033\133\151\000\102\001"
"\005\000\033\133\064\151\000\103\001\005\000\033\133\065\151"
"\000\047\001\003\000\033\105\000\116\001\003\000\033\070\000"
"\105\000\005\000\033\133\067\155\000\123\001\003\000\033\115"
"\000\123\000\010\000\033\050\102\044\074\064\076\000\124\000"
"\006\000\033\133\077\067\154\000\131\000\005\000\033\133\064"
"\154\000\140\000\006\000\033\133\062\067\155\000\143\000\006"
"\000\033\133\062\064\155\000\112\001\006\000\033\133\077\063"
"\154\000\120\001\003\000\033\067\000\134\001\113\000\033\133"
"\060\045\077\045\160\066\045\164\073\061\045\073\045\077\045"
"\160\062\045\164\073\064\045\073\045\077\045\160\064\045\164"
"\073\065\045\073\045\077\045\160\061\045\160\063\045\174\045"
"\164\073\067\045\073\155\045\077\045\160\071\045\164\033\050"
"\060\045\145\033\050\102\045\073\044\074\062\076\000\125\000"
"\007\000\033\133\155\033\050\102\000\061\000\010\000\033\050"
"\060\044\074\062\076\000\062\000\006\000\033\133\077\067\150"
"\000\073\000\005\000\033\133\064\150\000\112\000\005\000\033"
"\133\067\155\000\116\000\005\000\033\133\064\155\000\017\000"
"\005\000\033\133\063\147\000\011\000\001\000\003\000\142\163"
"\000\146\001",
1083
},
{
"wsvt25",
"\002\007\000\167\163\166\164\062\065\000\000\000\000\000\027"
"\000\007\000\002\000\001\027\000\001\001\000\001\036\000\001"
"\026\000\001\011\000\001\044\000\001\036\000\007\000\016\000"
"\010\000\004\000\120\000\007\000\010\000\012\000\031\000\025"
"\000\002\000\021\000\100\000\036\000\003\000\064\004\140\000"
"\157\000\013\000\033\133\162\033\133\062\065\073\061\110\000"
"\214\000\005\000\033\133\070\176\000\222\000\006\000\033\133"
"\061\061\176\000\233\000\006\000\033\133\062\061\176\000\234"
"\000\006\000\033\133\062\063\176\000\235\000\006\000\033\133"
"\062\064\176\000\223\000\006\000\033\133\061\062\176\000\224"
"\000\006\000\033\133\061\063\176\000\225\000\006\000\033\133"
"\061\064\176\000\226\000\006\000\033\133\061\065\176\000\227"
"\000\006\000\033\133\061\067\176\000\230\000\006\000\033\133"
"\061\070\176\000\231\000\006\000\033\133\061\071\176\000\232"
"\000\006\000\033\133\062\060\176\000\323\000\005\000\033\133"
"\067\176\000\052\001\004\000\033\133\155\000\132\001\012\000"
"\033\133\064\045\160\061\045\144\155\000\133\001\012\000\033"
"\133\063\045\160\061\045\144\155\000\000\000\063\000\140\140"
"\141\141\146\146\147\147\152\152\153\153\154\154\155\155\156"
"\156\157\157\160\160\161\161\162\162\163\163\164\164\165\165"
"\166\166\167\167\170\170\171\171\172\172\173\173\174\174\175"
"\175\176\176\000\003\000\002\000\007\000\063\000\005\000\033"
"\133\065\155\000\064\000\005\000\033\133\061\155\000\021\000"
"\007\000\033\133\110\033\133\112\000\007\000\002\000\015\000"
"\014\000\021\000\033\133\045\151\045\160\061\045\144\073\045"
"\160\062\045\144\162\000\063\001\011\000\033\133\045\160\061"
"\045\144\104\000\036\000\002\000\010\000\056\001\011\000\033"
"\133\045\160\061\045\144\102\000\033\000\002\000\012\000\065"
"\001\011\000\033\133\045\160\061\045\144\103\000\041\000\004"
"\000\033\133\103\000\032\000\021\000\033\133\045\151\045\160"
"\061\045\144\073\045\160\062\045\144\110\000\070\001\011\000"
"\033\133\045\160\061\045\144\101\000\043\000\004\000\033\133"
"\101\000\054\001\011\000\033\133\045\160\061\045\144\120\000"
"\047\000\004\000\033\133\120\000\055\001\011\000\033\133\045"
"\160\061\045\144\115\000\050\000\004\000\033\133\115\000\122"
"\000\011\000\033\133\045\160\061\045\144\130\000\024\000\004"
"\000\033\133\112\000\023\000\004\000\033\133\113\000\022\000"
"\005\000\033\133\061\113\000\057\000\004\000\033\051\060\000"
"\150\000\022\000\033\133\077\065\150\044\074\062\060\060\057"
"\076\033\133\077\065\154\000\034\000\004\000\033\133\110\000"
"\166\001\002\000\011\000\153\001\003\000\033\110\000\060\001"
"\011\000\033\133\045\160\061\045\144\100\000\161\000\030\000"
"\057\165\163\162\057\163\150\141\162\145\057\164\141\142\163"
"\145\164\057\166\164\061\060\060\000\062\001\011\000\033\133"
"\045\160\061\045\144\114\000\166\000\004\000\033\133\114\000"
"\122\001\003\000\033\104\000\173\000\002\000\010\000\326\000"
"\004\000\033\133\104\000\212\000\004\000\033\133\102\000\351"
"\000\004\000\033\133\103\000\015\001\004\000\033\133\101\000"
"\236\000\006\000\033\133\062\065\176\000\237\000\006\000\033"
"\133\062\066\176\000\242\000\006\000\033\133\063\061\176\000"
"\243\000\006\000\033\133\063\062\176\000\244\000\006\000\033"
"\133\063\063\176\000\245\000\006\000\033\133\063\064\176\000"
"\321\000\005\000\033\133\061\176\000\322\000\006\000\033\133"
"\062\070\176\000\324\000\005\000\033\133\062\176\000\335\000"
"\005\000\033\133\066\176\000\340\000\005\000\033\133\065\176"
"\000\343\000\006\000\033\133\062\071\176\000\362\000\005\000"
"\033\133\064\176\000\021\001\004\000\160\146\061\000\022\001"
"\004\000\160\146\062\000\023\001\004\000\160\146\063\000\024"
"\001\004\000\160\146\064\000\100\001\004\000\033\133\151\000"
"\102\001\005\000\033\133\064\151\000\103\001\005\000\033\133"
"\065\151\000\047\001\003\000\033\105\000\116\001\003\000\033"
"\070\000\105\000\005\000\033\133\067\155\000\123\001\003\000"
"\033\115\000\123\000\010\000\033\050\102\044\074\064\076\000"
"\124\000\006\000\033\133\077\067\154\000\131\000\005\000\033"
"\133\064\154\000\140\000\006\000\033\133\062\067\155\000\143"
"\000\006\000\033\133\062\064\155\000\112\001\006\000\033\133"
"\077\063\154\000\120\001\003\000\033\067\000\134\001\113\000"
"\033\133\060\045\077\045\160\066\045\164\073\061\045\073\045"
"\077\045\160\062\045\164\073\064\045\073\045\077\045\160\064"
"\045\164\073\065\045\073\045\077\045\160\061\045\160\063\045"
"\174\045\164\073\067\045\073\155\045\077\045\160\071\045\164"
"\033\050\060\045\145\033\050\102\045\073\044\074\062\076\000"
"\125\000\007\000\033\133\155\033\050\102\000\061\000\010\000"
"\033\050\060\044\074\062\076\000\062\000\006\000\033\133\077"
"\067\150\000\073\000\005\000\033\133\064\150\000\112\000\005"
"\000\033\133\067\155\000\116\000\005\000\033\133\064\155\000"
"\017\000\005\000\033\133\063\147\000\011\000\001\000\003\000"
"\142\163\000\146\001",
1160
},
{
"xterm",
"\002\006\000\170\164\145\162\155\000\000\000\000\000\032\000"
"\010\000\032\000\001\001\000\001\002\000\001\016\000\001\036"
"\000\001\026\000\001\027\000\001\011\000\001\026\000\005\000"
"\016\000\010\000\004\000\120\000\007\000\010\000\012\000\030"
"\000\021\000\100\000\004\010\247\000\061\001\011\000\033\133"
"\045\160\061\045\144\123\000\360\000\007\000\033\133\063\073"
"\062\176\000\363\000\007\000\033\133\061\073\062\106\000\371"
"\000\007\000\033\133\061\073\062\110\000\372\000\007\000\033"
"\133\062\073\062\176\000\376\000\007\000\033\133\066\073\062"
"\176\000\000\001\007\000\033\133\065\073\062\176\000\172\000"
"\004\000\033\117\105\000\175\000\004\000\033\133\132\000\326"
"\000\004\000\033\117\104\000\212\000\004\000\033\117\102\000"
"\351\000\004\000\033\117\103\000\015\001\004\000\033\117\101"
"\000\214\000\004\000\033\117\106\000\215\000\004\000\033\117"
"\115\000\323\000\004\000\033\117\110\000\324\000\005\000\033"
"\133\062\176\000\332\000\004\000\033\133\115\000\335\000\005"
"\000\033\133\066\176\000\340\000\005\000\033\133\065\176\000"
"\067\001\011\000\033\133\045\160\061\045\144\124\000\222\000"
"\004\000\033\117\120\000\233\000\006\000\033\133\062\061\176"
"\000\234\000\006\000\033\133\062\063\176\000\235\000\006\000"
"\033\133\062\064\176\000\236\000\007\000\033\133\061\073\062"
"\120\000\237\000\007\000\033\133\061\073\062\121\000\240\000"
"\007\000\033\133\061\073\062\122\000\241\000\007\000\033\133"
"\061\073\062\123\000\242\000\010\000\033\133\061\065\073\062"
"\176\000\243\000\010\000\033\133\061\067\073\062\176\000\244"
"\000\010\000\033\133\061\070\073\062\176\000\223\000\004\000"
"\033\117\121\000\245\000\010\000\033\133\061\071\073\062\176"
"\000\246\000\010\000\033\133\062\060\073\062\176\000\247\000"
"\010\000\033\133\062\061\073\062\176\000\250\000\010\000\033"
"\133\062\063\073\062\176\000\251\000\010\000\033\133\062\064"
"\073\062\176\000\252\000\007\000\033\133\061\073\065\120\000"
"\253\000\007\000\033\133\061\073\065\121\000\254\000\007\000"
"\033\133\061\073\065\122\000\255\000\007\000\033\133\061\073"
"\065\123\000\256\000\010\000\033\133\061\065\073\065\176\000"
"\224\000\004\000\033\117\122\000\257\000\010\000\033\133\061"
"\067\073\065\176\000\260\000\010\000\033\133\061\070\073\065"
"\176\000\261\000\010\000\033\133\061\071\073\065\176\000\262"
"\000\010\000\033\133\062\060\073\065\176\000\263\000\010\000"
"\033\133\062\061\073\065\176\000\264\000\010\000\033\133\062"
"\063\073\065\176\000\265\000\010\000\033\133\062\064\073\065"
"\176\000\266\000\007\000\033\133\061\073\066\120\000\267\000"
"\007\000\033\133\061\073\066\121\000\270\000\007\000\033\133"
"\061\073\066\122\000\225\000\004\000\033\117\123\000\271\000"
"\007\000\033\133\061\073\066\123\000\272\000\010\000\033\133"
"\061\065\073\066\176\000\273\000\010\000\033\133\061\067\073"
"\066\176\000\274\000\010\000\033\133\061\070\073\066\176\000"
"\275\000\010\000\033\133\061\071\073\066\176\000\276\000\010"
"\000\033\133\062\060\073\066\176\000\277\000\010\000\033\133"
"\062\061\073\066\176\000\300\000\010\000\033\133\062\063\073"
"\066\176\000\301\000\010\000\033\133\062\064\073\066\176\000"
"\302\000\007\000\033\133\061\073\063\120\000\226\000\006\000"
"\033\133\061\065\176\000\303\000\007\000\033\133\061\073\063"
"\121\000\304\000\007\000\033\133\061\073\063\122\000\305\000"
"\007\000\033\133\061\073\063\123\000\306\000\010\000\033\133"
"\061\065\073\063\176\000\307\000\010\000\033\133\061\067\073"
"\063\176\000\310\000\010\000\033\133\061\070\073\063\176\000"
"\311\000\010\000\033\133\061\071\073\063\176\000\312\000\010"
"\000\033\133\062\060\073\063\176\000\313\000\010\000\033\133"
"\062\061\073\063\176\000\314\000\010\000\033\133\062\063\073"
"\063\176\000\227\000\006\000\033\133\061\067\176\000\315\000"
"\010\000\033\133\062\064\073\063\176\000\316\000\007\000\033"
"\133\061\073\064\120\000\317\000\007\000\033\133\061\073\064"
"\121\000\320\000\007\000\033\133\061\073\064\122\000\230\000"
"\006\000\033\133\061\070\176\000\231\000\006\000\033\133\061"
"\071\176\000\232\000\006\000\033\133\062\060\176\000\373\000"
"\007\000\033\133\061\073\062\104\000\005\001\007\000\033\133"
"\061\073\062\103\000\366\000\007\000\033\133\061\073\062\102"
"\000\002\001\007\000\033\133\061\073\062\101\000\210\000\005"
"\000\033\133\063\176\000\000\000\065\000\140\140\141\141\146"
"\146\147\147\151\151\152\152\153\153\154\154\155\155\156\156"
"\157\157\160\160\161\161\162\162\163\163\164\164\165\165\166"
"\166\167\167\170\170\171\171\172\172\173\173\174\174\175\175"
"\176\176\000\003\000\002\000\007\000\063\000\005\000\033\133"
"\065\155\000\064\000\005\000\033\133\061\155\000\002\000\004"
"\000\033\133\132\000\035\000\007\000\033\133\077\062\065\154"
"\000\021\000\010\000\033\133\110\033\133\062\112\000\040\000"
"\015\000\033\133\077\061\062\154\033\133\077\062\065\150\000"
"\007\000\002\000\015\000\014\000\021\000\033\133\045\151\045"
"\160\061\045\144\073\045\160\062\045\144\162\000\063\001\011"
"\000\033\133\045\160\061\045\144\104\000\036\000\002\000\010"
"\000\056\001\011\000\033\133\045\160\061\045\144\102\000\033"
"\000\002\000\012\000\065\001\011\000\033\133\045\160\061\045"
"\144\103\000\041\000\004\000\033\133\103\000\032\000\021\000"
"\033\133\045\151\045\160\061\045\144\073\045\160\062\045\144"
"\110\000\070\001\011\000\033\133\045\160\061\045\144\101\000"
"\043\000\004\000\033\133\101\000\044\000\012\000\033\133\077"
"\061\062\073\062\065\150\000\054\001\011\000\033\133\045\160"
"\061\045\144\120\000\047\000\004\000\033\133\120\000\055\001"
"\011\000\033\133\045\160\061\045\144\115\000\050\000\004\000"
"\033\133\115\000\122\000\011\000\033\133\045\160\061\045\144"
"\130\000\024\000\004\000\033\133\112\000\023\000\004\000\033"
"\133\113\000\022\000\005\000\033\133\061\113\000\150\000\022"
"\000\033\133\077\065\150\044\074\061\060\060\057\076\033\133"
"\077\065\154\000\034\000\004\000\033\133\110\000\027\000\013"
"\000\033\133\045\151\045\160\061\045\144\107\000\166\001\002"
"\000\011\000\153\001\003\000\033\110\000\060\001\011\000\033"
"\133\045\160\061\045\144\100\000\062\001\011\000\033\133\045"
"\160\061\045\144\114\000\166\000\004\000\033\133\114\000\122"
"\001\002\000\012\000\110\000\005\000\033\133\070\155\000\157"
"\000\022\000\033\133\041\160\033\133\077\063\073\064\154\033"
"\133\064\154\033\076\000\173\000\002\000\010\000\100\001\004"
"\000\033\133\151\000\102\001\005\000\033\133\064\151\000\103"
"\001\005\000\033\133\065\151\000\052\001\011\000\033\133\063"
"\071\073\064\071\155\000\116\001\003\000\033\070\000\105\000"
"\005\000\033\133\067\155\000\123\001\003\000\033\115\000\123"
"\000\004\000\033\050\102\000\124\000\006\000\033\133\077\067"
"\154\000\126\000\011\000\033\133\077\061\060\064\071\154\000"
"\131\000\005\000\033\133\064\154\000\016\001\010\000\033\133"
"\077\061\154\033\076\000\036\001\011\000\033\133\077\061\060"
"\063\064\154\000\140\000\006\000\033\133\062\067\155\000\143"
"\000\006\000\033\133\062\064\155\000\112\001\003\000\033\143"
"\000\113\001\022\000\033\133\041\160\033\133\077\063\073\064"
"\154\033\133\064\154\033\076\000\120\001\003\000\033\067\000"
"\132\001\012\000\033\133\064\045\160\061\045\144\155\000\133"
"\001\012\000\033\133\063\045\160\061\045\144\155\000\135\001"
"\106\000\033\133\064\045\077\045\160\061\045\173\061\175\045"
"\075\045\164\064\045\145\045\160\061\045\173\063\175\045\075"
"\045\164\066\045\145\045\160\061\045\173\064\175\045\075\045"
"\164\061\045\145\045\160\061\045\173\066\175\045\075\045\164"
"\063\045\145\045\160\061\045\144\045\073\155\000\143\001\106"
"\000\033\133\063\045\077\045\160\061\045\173\061\175\045\075"
"\045\164\064\045\145\045\160\061\045\173\063\175\045\075\045"
"\164\066\045\145\045\160\061\045\173\064\175\045\075\045\164"
"\061\045\145\045\160\061\045\173\066\175\045\075\045\164\063"
"\045\145\045\160\061\045\144\045\073\155\000\134\001\122\000"
"\045\077\045\160\071\045\164\033\050\060\045\145\033\050\102"
"\045\073\033\133\060\045\077\045\160\066\045\164\073\061\045"
"\073\045\077\045\160\062\045\164\073\064\045\073\045\077\045"
"\160\061\045\160\063\045\174\045\164\073\067\045\073\045\077"
"\045\160\064\045\164\073\065\045\073\045\077\045\160\067\045"
"\164\073\070\045\073\155\000\125\000\007\000\033\050\102\033"
"\133\155\000\061\000\004\000\033\050\060\000\062\000\006\000"
"\033\133\077\067\150\000\065\000\011\000\033\133\077\061\060"
"\064\071\150\000\073\000\005\000\033\133\064\150\000\017\001"
"\010\000\033\133\077\061\150\033\075\000\037\001\011\000\033"
"\133\077\061\060\063\064\150\000\112\000\005\000\033\133\067"
"\155\000\116\000\005\000\033\133\064\155\000\017\000\005\000"
"\033\133\063\147\000\117\001\013\000\033\133\045\151\045\160"
"\061\045\144\144\000\202\001\010\000\033\133\077\061\073\062"
"\143\000\200\001\013\000\033\133\045\151\045\144\073\045\144"
"\122\000\201\001\005\000\033\133\066\156\000\203\001\004\000"
"\033\133\143\000\272\003\070\000\004\000\153\104\116\000\163"
"\007\000\033\133\061\073\062\102\000\005\000\153\104\116\063"
"\000\163\007\000\033\133\061\073\063\102\000\005\000\153\104"
"\116\064\000\163\007\000\033\133\061\073\064\102\000\005\000"
"\153\104\116\065\000\163\007\000\033\133\061\073\065\102\000"
"\005\000\153\104\116\066\000\163\007\000\033\133\061\073\066"
"\102\000\005\000\153\104\116\067\000\163\007\000\033\133\061"
"\073\067\102\000\006\000\153\114\106\124\063\000\163\007\000"
"\033\133\061\073\063\104\000\006\000\153\114\106\124\064\000"
"\163\007\000\033\133\061\073\064\104\000\006\000\153\114\106"
"\124\065\000\163\007\000\033\133\061\073\065\104\000\006\000"
"\153\114\106\124\066\000\163\007\000\033\133\061\073\066\104"
"\000\006\000\153\114\106\124\067\000\163\007\000\033\133\061"
"\073\067\104\000\006\000\153\122\111\124\063\000\163\007\000"
"\033\133\061\073\063\103\000\006\000\153\122\111\124\064\000"
"\163\007\000\033\133\061\073\064\103\000\006\000\153\122\111"
"\124\065\000\163\007\000\033\133\061\073\065\103\000\006\000"
"\153\122\111\124\066\000\163\007\000\033\133\061\073\066\103"
"\000\006\000\153\122\111\124\067\000\163\007\000\033\133\061"
"\073\067\103\000\004\000\153\125\120\000\163\007\000\033\133"
"\061\073\062\101\000\005\000\153\125\120\063\000\163\007\000"
"\033\133\061\073\063\101\000\005\000\153\125\120\064\000\163"
"\007\000\033\133\061\073\064\101\000\005\000\153\125\120\065"
"\000\163\007\000\033\133\061\073\065\101\000\005\000\153\125"
"\120\066\000\163\007\000\033\133\061\073\066\101\000\005\000"
"\153\125\120\067\000\163\007\000\033\133\061\073\067\101\000"
"\005\000\153\104\103\063\000\163\007\000\033\133\063\073\063"
"\176\000\005\000\153\104\103\064\000\163\007\000\033\133\063"
"\073\064\176\000\005\000\153\104\103\065\000\163\007\000\033"
"\133\063\073\065\176\000\005\000\153\104\103\066\000\163\007"
"\000\033\133\063\073\066\176\000\005\000\153\104\103\067\000"
"\163\007\000\033\133\063\073\067\176\000\006\000\153\105\116"
"\104\063\000\163\007\000\033\133\061\073\063\106\000\006\000"
"\153\105\116\104\064\000\163\007\000\033\133\061\073\064\106"
"\000\006\000\153\105\116\104\065\000\163\007\000\033\133\061"
"\073\065\106\000\006\000\153\105\116\104\066\000\163\007\000"
"\033\133\061\073\066\106\000\006\000\153\105\116\104\067\000"
"\163\007\000\033\133\061\073\067\106\000\006\000\153\110\117"
"\115\063\000\163\007\000\033\133\061\073\063\110\000\006\000"
"\153\110\117\115\064\000\163\007\000\033\133\061\073\064\110"
"\000\006\000\153\110\117\115\065\000\163\007\000\033\133\061"
"\073\065\110\000\006\000\153\110\117\115\066\000\163\007\000"
"\033\133\061\073\066\110\000\006\000\153\110\117\115\067\000"
"\163\007\000\033\133\061\073\067\110\000\005\000\153\111\103"
"\063\000\163\007\000\033\133\062\073\063\176\000\005\000\153"
"\111\103\064\000\163\007\000\033\133\062\073\064\176\000\005"
"\000\153\111\103\065\000\163\007\000\033\133\062\073\065\176"
"\000\005\000\153\111\103\066\000\163\007\000\033\133\062\073"
"\066\176\000\005\000\153\111\103\067\000\163\007\000\033\133"
"\062\073\067\176\000\006\000\153\116\130\124\063\000\163\007"
"\000\033\133\066\073\063\176\000\006\000\153\116\130\124\064"
"\000\163\007\000\033\133\066\073\064\176\000\006\000\153\116"
"\130\124\065\000\163\007\000\033\133\066\073\065\176\000\006"
"\000\153\116\130\124\066\000\163\007\000\033\133\066\073\066"
"\176\000\006\000\153\116\130\124\067\000\163\007\000\033\133"
"\066\073\067\176\000\006\000\153\120\122\126\063\000\163\007"
"\000\033\133\065\073\063\176\000\006\000\153\120\122\126\064"
"\000\163\007\000\033\133\065\073\064\176\000\006\000\153\120"
"\122\126\065\000\163\007\000\033\133\065\073\065\176\000\006"
"\000\153\120\122\126\066\000\163\007\000\033\133\065\073\066"
"\176\000\006\000\153\120\122\126\067\000\163\007\000\033\133"
"\065\073\067\176\000\003\000\142\163\000\146\001\003\000\101"
"\130\000\146\001\005\000\155\145\155\154\000\163\003\000\033"
"\154\000\005\000\155\145\155\165\000\163\003\000\033\155\000",
3075
}
};

95
lib/libterminfo/curterm.c Normal file
View file

@ -0,0 +1,95 @@
/* $NetBSD: curterm.c,v 1.4 2010/02/22 23:05:39 roy Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
*
* 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 <sys/cdefs.h>
__RCSID("$NetBSD: curterm.c,v 1.4 2010/02/22 23:05:39 roy Exp $");
#include <assert.h>
#include <stdlib.h>
#include <term_private.h>
#include <term.h>
#include <termios.h>
#include <stdio.h>
TERMINAL *cur_term;
static const speed_t bauds[] = {
0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 2400, 4800, 9600,
19200, 38400, 57600, 115200, 230400, 460800, 921600
};
void
_ti_setospeed(TERMINAL *term)
{
struct termios termios;
speed_t os;
size_t i;
_DIAGASSERT(term != NULL);
term->_ospeed = 0;
if (tcgetattr(term->fildes, &termios) == 0) {
os = cfgetospeed(&termios);
for (i = 0; i < __arraycount(bauds); i++)
if (bauds[i] == os) {
term->_ospeed = i;
break;
}
}
}
TERMINAL *
set_curterm(TERMINAL *nterm)
{
TERMINAL *oterm;
oterm = cur_term;
cur_term = nterm;
ospeed = 0;
if (cur_term == NULL)
PC = '\0';
else {
if (pad_char == NULL)
PC = '\0';
else
PC = *pad_char;
_ti_setospeed(nterm);
ospeed = nterm->_ospeed;
}
return oterm;
}
int
del_curterm(TERMINAL *oterm)
{
_ti_freeterm(oterm);
return 0;
}

108
lib/libterminfo/genhash Executable file
View file

@ -0,0 +1,108 @@
#!/bin/sh
# $NetBSD: genhash,v 1.7 2010/10/12 12:57:51 christos Exp $
# Copyright (c) 2009 The NetBSD Foundation, Inc.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Roy Marples.
#
# 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.
# Generate string and hash tables for our terminfo strings in term.h
# We don't expose the hash or tables directly, but instead via functions.
# This allows us to freely change how we hash or store our string tables
# in the future.
set -e
: ${TOOL_AWK:=awk}
: ${TOOL_NBPERF:=nbperf}
: ${TOOL_SED:=sed}
TERMH=${1:-term.h}
genent()
{
local name=$1 NAME=$2 len=
# Calculate the maximum word length plus terminator
len=$($TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \
-e 's/.*TICODE_\([^,]*\).*/\1X/' $TERMH | \
$TOOL_AWK \
'BEGIN {L=0} {if (length($1)>L) L=length($1)} END {print L}')
echo
echo "static const char _ti_${name}ids[][${len}] = {"
$TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \
-e 's/.*TICODE_\([^,]*\).*/ "\1",/' $TERMH
echo "};"
echo
$TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \
-e 's/.*TICODE_\([^,]*\).*/\1/' $TERMH | \
$TOOL_NBPERF -sn _ti_${name}hash;
cat <<EOF
const char *
_ti_${name}id(ssize_t idx)
{
if ((size_t)idx > __arraycount(_ti_${name}ids))
return NULL;
return _ti_${name}ids[idx];
}
ssize_t
_ti_${name}index(const char *key)
{
uint32_t idx;
idx = _ti_${name}hash((const unsigned char *)key, strlen(key));
if (idx > __arraycount(_ti_${name}ids) ||
strcmp(key, _ti_${name}ids[idx]) != 0)
return -1;
return idx;
}
EOF
}
cat <<EOF
/* \$NetBSD\$ */
/* DO NOT EDIT
* Automatically generated from term.h */
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
__RCSID("\$NetBSD: genhash,v 1.7 2010/10/12 12:57:51 christos Exp $");
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <term_private.h>
#include <term.h>
EOF
genent flag FLAG
genent num NUM
genent str STR

69
lib/libterminfo/genman Executable file
View file

@ -0,0 +1,69 @@
#!/bin/sh
# $NetBSD: genman,v 1.4 2010/10/12 12:57:51 christos Exp $
# Copyright (c) 2009 The NetBSD Foundation, Inc.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Roy Marples.
#
# 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.
# Generate variable tables for terminfo.5 from our source files.
set -e
: ${TOOL_SED:=sed}
: ${TOOL_SORT:=sort}
TERMM=${1:-terminfo.5.in}
TERMH=${2:-term.h}
TERMC=${3:-termcap_map.c}
gentab()
{
local ti=$1 tc=$2 tab=$3
# Generate a list of long names and codes
$TOOL_SED -n \
-e "s/#define t_\([^(]*\).*>$tab\[TICODE_\([^]]*\).*/\1 \2/p" \
$ti | $TOOL_SORT | while read name code foo; do
cap=$($TOOL_SED -ne "s/.*{ \"\(..\)\", TICODE_$code }.*/\1/p" \
$tc | head -n 1)
echo ".It Li \"$name\" Ta Sy \"\\&$code\" Ta Sy \"\\&$cap\""
done
}
boolcaps=$(gentab $TERMH $TERMC flags)
numcaps=$(gentab $TERMH $TERMC nums)
strcaps=$(gentab $TERMH $TERMC strs)
echo ".\\\"DO NOT EDIT"
echo ".\\\"Automatically generated from termcap.5.in"
echo ".\\\""
while read -r line; do
case "$line" in
"@BOOLCAPS@") echo "$boolcaps";;
"@NUMCAPS@") echo "$numcaps";;
"@STRCAPS@") echo "$strcaps";;
*) echo "$line";;
esac
done <$TERMM

42
lib/libterminfo/genterms Executable file
View file

@ -0,0 +1,42 @@
#!/bin/sh
# $NetBSD: genterms,v 1.3 2010/10/12 12:57:51 christos Exp $
# Copyright (c) 2010 The NetBSD Foundation, Inc.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Roy Marples.
#
# 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.
# Generate compiled terminfo descriptions to embed into libterminfo
set -e
: ${TOOL_TIC:=tic}
: ${NETBSDSRCDIR:=/usr/src}
: ${TERMINFO:=${NETBSDSRCDIR}/share/terminfo/terminfo}
echo "/* \$NetBSD\$ */"
echo "/* DO NOT EDIT"
echo " * Regenerate by doing \`\`make compiled_terms''"
echo " */"
echo
${TOOL_TIC} -Sx ${TERMINFO} ansi dumb vt100 vt220 wsvt25 xterm

62
lib/libterminfo/genthash Executable file
View file

@ -0,0 +1,62 @@
#!/bin/sh
# $NetBSD: genthash,v 1.4 2010/03/03 12:09:49 roy Exp $
# Copyright (c) 2009 The NetBSD Foundation, Inc.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Roy Marples.
#
# 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.
# Generate string and hash tables for our termcap strings in termcap.c
set -e
: ${TOOL_NBPERF:=nbperf}
: ${TOOL_SED:=sed}
TERMCAPC=${1:-termcap_map.c}
cat <<EOF
/* \$NetBSD\$ */
/* DO NOT EDIT
* Automatically generated from termcap.c */
#include <sys/cdefs.h>
__RCSID("\$NetBSD: genthash,v 1.4 2010/03/03 12:09:49 roy Exp $");
#include <stdint.h>
#include <stdlib.h>
#include <term_private.h>
EOF
$TOOL_SED -n -e "1,/_ti_cap_flagids/d" -e '/};/,$d' \
-e 's/.*"\([^"]*\)".*/\1/p' $TERMCAPC | \
$TOOL_NBPERF -s -n _t_flaghash
echo
$TOOL_SED -n -e "1,/_ti_cap_numids/d" -e '/};/,$d' \
-e 's/.*"\([^"]*\)".*/\1/p' $TERMCAPC | \
$TOOL_NBPERF -s -n _t_numhash
echo
$TOOL_SED -n -e "1,/_ti_cap_strids/d" -e '/};/,$d' \
-e 's/.*"\([^"]*\)".*/\1/p' $TERMCAPC | \
$TOOL_NBPERF -s -n _t_strhash

705
lib/libterminfo/hash.c Normal file
View file

@ -0,0 +1,705 @@
/* $NetBSD: hash.c,v 1.4 2010/02/12 10:18:56 roy Exp $ */
/* DO NOT EDIT
* Automatically generated from term.h */
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: hash.c,v 1.4 2010/02/12 10:18:56 roy Exp $");
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <term_private.h>
#include <term.h>
static const char _ti_flagids[][6] = {
"bw",
"am",
"bce",
"ccc",
"xhp",
"xhpa",
"cpix",
"crxm",
"xt",
"xenl",
"eo",
"gn",
"hc",
"chts",
"km",
"daisy",
"hs",
"hls",
"in",
"lpix",
"da",
"db",
"mir",
"msgr",
"nxon",
"xsb",
"npc",
"ndscr",
"nrrmc",
"os",
"mc5i",
"xvpa",
"sam",
"eslok",
"hz",
"ul",
"xon",
};
#include <stdlib.h>
static uint32_t
_ti_flaghash(const void * __restrict key, size_t keylen)
{
static const uint8_t g[75] = {
0x19, 0x08, 0x16, 0x00, 0x00, 0x1e, 0x07, 0x00, 0x1d, 0x00,
0x17, 0x00, 0x0a, 0x17, 0x08, 0x09, 0x11, 0x00, 0x00, 0x0a,
0x00, 0x13, 0x1a, 0x0f, 0x00, 0x00, 0x03, 0x02, 0x00, 0x00,
0x12, 0x0a, 0x00, 0x11, 0x10, 0x09, 0x00, 0x00, 0x00, 0x1b,
0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0d, 0x00, 0x00,
0x00, 0x0d, 0x00, 0x00, 0x04, 0x16, 0x09, 0x00, 0x1a, 0x00,
0x00, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x1c, 0x05, 0x00, 0x00,
};
uint32_t h[3];
mi_vector_hash(key, keylen, 0xd36b2625U, h);
return (g[h[0] % 75] + g[h[1] % 75]) % 37;
}
const char *
_ti_flagid(ssize_t idx)
{
if ((size_t)idx > __arraycount(_ti_flagids))
return NULL;
return _ti_flagids[idx];
}
ssize_t
_ti_flagindex(const char *key)
{
uint32_t idx;
idx = _ti_flaghash((const unsigned char *)key, strlen(key));
if (idx > __arraycount(_ti_flagids) ||
strcmp(key, _ti_flagids[idx]) != 0)
return -1;
return idx;
}
static const char _ti_numids[][7] = {
"bitwin",
"bitype",
"bufsz",
"btns",
"cols",
"spinh",
"spinv",
"it",
"lh",
"lw",
"lines",
"lm",
"ma",
"xmc",
"colors",
"maddr",
"mjump",
"pairs",
"wnum",
"mcs",
"mls",
"ncv",
"nlab",
"npins",
"orc",
"orl",
"orhi",
"orvi",
"pb",
"cps",
"vt",
"widcs",
"wsl",
};
#include <stdlib.h>
static uint32_t
_ti_numhash(const void * __restrict key, size_t keylen)
{
static const uint8_t g[67] = {
0x04, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00,
0x19, 0x00, 0x0d, 0x00, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x00,
0x0b, 0x15, 0x1d, 0x14, 0x00, 0x01, 0x13, 0x1b, 0x14, 0x00,
0x19, 0x00, 0x00, 0x02, 0x14, 0x1a, 0x12, 0x00, 0x00, 0x00,
0x16, 0x05, 0x00, 0x12, 0x04, 0x00, 0x03, 0x00, 0x00, 0x00,
0x19, 0x00, 0x20, 0x00, 0x00, 0x10, 0x17, 0x00, 0x00, 0x0f,
0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
};
uint32_t h[3];
mi_vector_hash(key, keylen, 0x50a11f58U, h);
return (g[h[0] % 67] + g[h[1] % 67]) % 33;
}
const char *
_ti_numid(ssize_t idx)
{
if ((size_t)idx > __arraycount(_ti_numids))
return NULL;
return _ti_numids[idx];
}
ssize_t
_ti_numindex(const char *key)
{
uint32_t idx;
idx = _ti_numhash((const unsigned char *)key, strlen(key));
if (idx > __arraycount(_ti_numids) ||
strcmp(key, _ti_numids[idx]) != 0)
return -1;
return idx;
}
static const char _ti_strids[][9] = {
"acsc",
"scesa",
"cbt",
"bel",
"bicr",
"binel",
"birep",
"cr",
"cpi",
"lpi",
"chr",
"cvr",
"csr",
"rmp",
"csnm",
"tbc",
"mgc",
"clear",
"el1",
"el",
"ed",
"csin",
"colornm",
"hpa",
"cmdch",
"cwin",
"cup",
"cud1",
"home",
"civis",
"cub1",
"mrcup",
"cnorm",
"cuf1",
"ll",
"cuu1",
"cvvis",
"defbi",
"defc",
"dch1",
"dl1",
"devt",
"dial",
"dsl",
"dclk",
"dispc",
"hd",
"enacs",
"endbi",
"smacs",
"smam",
"blink",
"bold",
"smcup",
"smdc",
"dim",
"swidm",
"sdrfq",
"ehhlm",
"smir",
"sitm",
"elhlm",
"slm",
"elohlm",
"smicm",
"snlq",
"snrmq",
"smpch",
"prot",
"rev",
"erhlm",
"smsc",
"invis",
"sshm",
"smso",
"ssubm",
"ssupm",
"ethlm",
"smul",
"sum",
"evhlm",
"smxon",
"ech",
"rmacs",
"rmam",
"sgr0",
"rmcup",
"rmdc",
"rwidm",
"rmir",
"ritm",
"rlm",
"rmicm",
"rmpch",
"rmsc",
"rshm",
"rmso",
"rsubm",
"rsupm",
"rmul",
"rum",
"rmxon",
"pause",
"hook",
"flash",
"ff",
"fsl",
"getm",
"wingo",
"hup",
"is1",
"is2",
"is3",
"if",
"iprog",
"initc",
"initp",
"ich1",
"il1",
"ip",
"ka1",
"ka3",
"kb2",
"kbs",
"kbeg",
"kcbt",
"kc1",
"kc3",
"kcan",
"ktbc",
"kclr",
"kclo",
"kcmd",
"kcpy",
"kcrt",
"kctab",
"kdch1",
"kdl1",
"kcud1",
"krmir",
"kend",
"kent",
"kel",
"ked",
"kext",
"kf0",
"kf1",
"kf2",
"kf3",
"kf4",
"kf5",
"kf6",
"kf7",
"kf8",
"kf9",
"kf10",
"kf11",
"kf12",
"kf13",
"kf14",
"kf15",
"kf16",
"kf17",
"kf18",
"kf19",
"kf20",
"kf21",
"kf22",
"kf23",
"kf24",
"kf25",
"kf26",
"kf27",
"kf28",
"kf29",
"kf30",
"kf31",
"kf32",
"kf33",
"kf34",
"kf35",
"kf36",
"kf37",
"kf38",
"kf39",
"kf40",
"kf41",
"kf42",
"kf43",
"kf44",
"kf45",
"kf46",
"kf47",
"kf48",
"kf49",
"kf50",
"kf51",
"kf52",
"kf53",
"kf54",
"kf55",
"kf56",
"kf57",
"kf58",
"kf59",
"kf60",
"kf61",
"kf62",
"kf63",
"kfnd",
"khlp",
"khome",
"kich1",
"kil1",
"kcub1",
"kll",
"kmrk",
"kmsg",
"kmous",
"kmov",
"knxt",
"knp",
"kopn",
"kopt",
"kpp",
"kprv",
"kprt",
"krdo",
"kref",
"krfr",
"krpl",
"krst",
"kres",
"kcuf1",
"ksav",
"kBEG",
"kCAN",
"kCMD",
"kCPY",
"kCRT",
"kDC",
"kDL",
"kslt",
"kEND",
"kEOL",
"kEXT",
"kind",
"kFND",
"kHLP",
"kHOM",
"kIC",
"kLFT",
"kMSG",
"kMOV",
"kNXT",
"kOPT",
"kPRV",
"kPRT",
"kri",
"kRDO",
"kRPL",
"kRIT",
"kRES",
"kSAV",
"kSPD",
"khts",
"kUND",
"kspd",
"kund",
"kcuu1",
"rmkx",
"smkx",
"lf0",
"lf1",
"lf2",
"lf3",
"lf4",
"lf5",
"lf6",
"lf7",
"lf8",
"lf9",
"lf10",
"fln",
"rmln",
"smln",
"rmm",
"smm",
"mhpa",
"mcud1",
"mcub1",
"mcuf1",
"mvpa",
"mcuu1",
"minfo",
"nel",
"porder",
"oc",
"op",
"pad",
"dch",
"dl",
"cud",
"mcud",
"ich",
"indn",
"il",
"cub",
"mcub",
"cuf",
"mcuf",
"rin",
"cuu",
"mcuu",
"pctrm",
"pfkey",
"pfloc",
"pfxl",
"pfx",
"pln",
"mc0",
"mc5p",
"mc4",
"mc5",
"pulse",
"qdial",
"rmclk",
"rep",
"rfi",
"reqmp",
"rs1",
"rs2",
"rs3",
"rf",
"rc",
"vpa",
"sc",
"scesc",
"ind",
"ri",
"scs",
"s0ds",
"s1ds",
"s2ds",
"s3ds",
"sgr1",
"setab",
"setaf",
"sgr",
"setb",
"smgb",
"smgbp",
"sclk",
"setcolor",
"scp",
"setf",
"smgl",
"smglp",
"smglr",
"slines",
"slength",
"smgr",
"smgrp",
"hts",
"smgtb",
"smgt",
"smgtp",
"wind",
"sbim",
"scsd",
"rbim",
"rcsd",
"subcs",
"supcs",
"ht",
"docr",
"tsl",
"tone",
"u0",
"u1",
"u2",
"u3",
"u4",
"u5",
"u6",
"u7",
"u8",
"u9",
"uc",
"hu",
"wait",
"xoffc",
"xonc",
"zerom",
};
#include <stdlib.h>
static uint32_t
_ti_strhash(const void * __restrict key, size_t keylen)
{
static const uint16_t g[789] = {
0x0000, 0x00cd, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0094,
0x0000, 0x011b, 0x00a0, 0x0094, 0x002f, 0x00aa, 0x0026, 0x004b,
0x0000, 0x0163, 0x0171, 0x0000, 0x0000, 0x0064, 0x0019, 0x0000,
0x009b, 0x0113, 0x00ed, 0x007e, 0x0000, 0x0000, 0x0000, 0x002d,
0x0000, 0x00f4, 0x0000, 0x00cc, 0x00df, 0x0170, 0x0000, 0x0000,
0x0179, 0x0018, 0x0000, 0x013b, 0x0000, 0x0028, 0x0000, 0x0000,
0x00ef, 0x0000, 0x0137, 0x0061, 0x0000, 0x0000, 0x00ce, 0x00df,
0x00f0, 0x001f, 0x0074, 0x0000, 0x0000, 0x008f, 0x0069, 0x0000,
0x0134, 0x0000, 0x00ac, 0x0000, 0x0000, 0x0100, 0x0000, 0x0000,
0x0012, 0x0027, 0x0000, 0x0110, 0x0000, 0x0000, 0x0000, 0x0061,
0x00a7, 0x0000, 0x0061, 0x0000, 0x0000, 0x0096, 0x0000, 0x00e5,
0x0000, 0x00d1, 0x0017, 0x0000, 0x0000, 0x00bc, 0x00d6, 0x0000,
0x0182, 0x00d7, 0x012d, 0x0000, 0x00e2, 0x00b9, 0x0159, 0x0000,
0x001c, 0x00cc, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0031, 0x0106, 0x0087, 0x0157, 0x001d, 0x011a, 0x0119,
0x0000, 0x0000, 0x0000, 0x012b, 0x0000, 0x011b, 0x0000, 0x0154,
0x0000, 0x00ee, 0x00ad, 0x00f8, 0x0066, 0x0000, 0x0010, 0x0000,
0x0064, 0x000e, 0x0052, 0x0000, 0x016a, 0x0000, 0x0148, 0x0000,
0x0000, 0x0000, 0x00a4, 0x0000, 0x0000, 0x016d, 0x000b, 0x0000,
0x0000, 0x0000, 0x0000, 0x0058, 0x0091, 0x0000, 0x0022, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0026, 0x011a, 0x00a4, 0x013a,
0x0000, 0x0000, 0x0000, 0x0000, 0x0086, 0x0000, 0x00c0, 0x011f,
0x0000, 0x0093, 0x0000, 0x0000, 0x0042, 0x0174, 0x0101, 0x0000,
0x0065, 0x0086, 0x0000, 0x0000, 0x00e8, 0x0022, 0x000d, 0x0000,
0x008e, 0x000d, 0x0000, 0x008b, 0x0000, 0x0000, 0x0000, 0x0000,
0x0022, 0x0000, 0x011d, 0x0000, 0x0000, 0x0000, 0x010e, 0x0000,
0x0000, 0x0000, 0x0060, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0014, 0x00b3, 0x0000, 0x002e, 0x0051, 0x0000, 0x0102, 0x008e,
0x012b, 0x0145, 0x004c, 0x0000, 0x001e, 0x00fa, 0x0000, 0x0000,
0x0000, 0x0000, 0x00aa, 0x0000, 0x0000, 0x0000, 0x0103, 0x00a4,
0x003e, 0x0000, 0x0114, 0x0028, 0x005e, 0x015d, 0x00e7, 0x0044,
0x0000, 0x0000, 0x00c6, 0x008f, 0x0000, 0x00eb, 0x0000, 0x0000,
0x0000, 0x0169, 0x0000, 0x0110, 0x0093, 0x0000, 0x012c, 0x0178,
0x0000, 0x0000, 0x0024, 0x0000, 0x0000, 0x0000, 0x0000, 0x0158,
0x004d, 0x009c, 0x0186, 0x009b, 0x0000, 0x0163, 0x007c, 0x0078,
0x0000, 0x0000, 0x0172, 0x00d2, 0x0000, 0x0000, 0x00fc, 0x0000,
0x0000, 0x0000, 0x0133, 0x0104, 0x017e, 0x0162, 0x0050, 0x0000,
0x0023, 0x00c0, 0x0070, 0x0000, 0x0000, 0x0000, 0x0025, 0x0001,
0x0184, 0x0053, 0x0133, 0x0000, 0x0000, 0x0000, 0x0048, 0x0075,
0x0000, 0x00b2, 0x0056, 0x002c, 0x0000, 0x011c, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0166, 0x011b, 0x0000, 0x0039, 0x0020,
0x0000, 0x0000, 0x0000, 0x00dc, 0x0048, 0x0000, 0x0076, 0x0169,
0x00d7, 0x002a, 0x0032, 0x0013, 0x0153, 0x012f, 0x009c, 0x0041,
0x002f, 0x0000, 0x0000, 0x012e, 0x0000, 0x0000, 0x00dd, 0x0000,
0x0138, 0x000b, 0x0030, 0x008d, 0x0000, 0x0000, 0x0000, 0x0000,
0x0039, 0x017a, 0x00c5, 0x0100, 0x0000, 0x0000, 0x005c, 0x001f,
0x0000, 0x0000, 0x0000, 0x0000, 0x0110, 0x003e, 0x00a1, 0x0000,
0x0081, 0x0000, 0x0000, 0x0000, 0x00dd, 0x0142, 0x00c1, 0x0000,
0x0035, 0x0123, 0x0178, 0x00be, 0x015e, 0x0161, 0x0188, 0x0000,
0x0000, 0x0149, 0x0123, 0x0000, 0x0000, 0x0185, 0x0000, 0x0000,
0x0000, 0x004e, 0x0163, 0x0077, 0x00fa, 0x0000, 0x007b, 0x0006,
0x0101, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0158, 0x00d6,
0x00b0, 0x0180, 0x0003, 0x0000, 0x0000, 0x0000, 0x0136, 0x0045,
0x017e, 0x0000, 0x0000, 0x0000, 0x0126, 0x0090, 0x011b, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x017b, 0x0000, 0x0053, 0x0000,
0x005c, 0x0000, 0x0000, 0x0020, 0x0000, 0x0000, 0x007e, 0x014e,
0x0035, 0x00ed, 0x0000, 0x00d1, 0x00d8, 0x0142, 0x0168, 0x000a,
0x00d0, 0x0000, 0x0000, 0x0000, 0x00d9, 0x0000, 0x0000, 0x0087,
0x0000, 0x008a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0112, 0x006c,
0x011d, 0x0177, 0x0000, 0x0000, 0x0000, 0x0000, 0x0024, 0x001e,
0x0177, 0x00c4, 0x0000, 0x0000, 0x0000, 0x0014, 0x00c7, 0x00ae,
0x0042, 0x0180, 0x0075, 0x0000, 0x011c, 0x0064, 0x00a3, 0x00bc,
0x0001, 0x0000, 0x0000, 0x0016, 0x00c3, 0x00e4, 0x0009, 0x0000,
0x0000, 0x006b, 0x013c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00fa, 0x0000, 0x0000, 0x0000, 0x0117, 0x0000, 0x007c, 0x0060,
0x0149, 0x0059, 0x00d4, 0x014e, 0x000a, 0x014f, 0x0000, 0x0000,
0x0000, 0x00b6, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0121,
0x0000, 0x0000, 0x0000, 0x007d, 0x0000, 0x0000, 0x001c, 0x0000,
0x0000, 0x00f9, 0x0000, 0x003b, 0x00ea, 0x0000, 0x00ad, 0x0000,
0x0000, 0x0000, 0x0155, 0x0000, 0x0141, 0x0000, 0x0000, 0x0000,
0x0187, 0x004b, 0x009f, 0x0000, 0x0114, 0x0000, 0x00dd, 0x0000,
0x0066, 0x0000, 0x0136, 0x0135, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x001e, 0x0000, 0x0062, 0x0146, 0x0033, 0x0071, 0x0000,
0x0000, 0x010d, 0x004a, 0x0133, 0x0000, 0x0000, 0x0076, 0x0111,
0x0000, 0x00ba, 0x0000, 0x0000, 0x0000, 0x0038, 0x001d, 0x0158,
0x0072, 0x00a3, 0x0000, 0x008c, 0x0008, 0x0000, 0x0000, 0x0000,
0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x00ea, 0x0000, 0x003f,
0x0000, 0x0000, 0x0000, 0x004c, 0x0000, 0x00f9, 0x0000, 0x0000,
0x0000, 0x0147, 0x0182, 0x008f, 0x0156, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0011, 0x0000, 0x0102, 0x0040, 0x0000, 0x0000,
0x0130, 0x0000, 0x0000, 0x0000, 0x0126, 0x0026, 0x0145, 0x0000,
0x0000, 0x00ab, 0x0000, 0x0175, 0x0113, 0x0117, 0x010f, 0x000f,
0x0000, 0x00e3, 0x012e, 0x0000, 0x0000, 0x00f5, 0x0020, 0x0000,
0x0000, 0x00a8, 0x0000, 0x0000, 0x012a, 0x009f, 0x0085, 0x0000,
0x00b6, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0108,
0x00cb, 0x0000, 0x0000, 0x0000, 0x0053, 0x0000, 0x007f, 0x0000,
0x008c, 0x0113, 0x0000, 0x0000, 0x0156, 0x0169, 0x0000, 0x0009,
0x0000, 0x0073, 0x0000, 0x007e, 0x0000, 0x0000, 0x0000, 0x00eb,
0x0000, 0x0153, 0x0084, 0x0000, 0x0000, 0x0148, 0x0000, 0x0000,
0x011c, 0x0000, 0x00ec, 0x0000, 0x0000, 0x015a, 0x0000, 0x0000,
0x0000, 0x0000, 0x012a, 0x0000, 0x0000, 0x015d, 0x0000, 0x00ae,
0x0000, 0x0000, 0x00db, 0x0000, 0x0000, 0x0000, 0x0000, 0x0101,
0x0067, 0x0000, 0x010c, 0x0000, 0x0032, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0167, 0x0000, 0x00e4, 0x0000, 0x00a2, 0x0000,
0x0067, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0181, 0x0000,
0x015b, 0x0046, 0x0000, 0x0000, 0x0000, 0x00fd, 0x0000, 0x0000,
0x00a8, 0x0000, 0x0008, 0x00a6, 0x00b5, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x006b, 0x0000, 0x0000, 0x00b1, 0x00a2,
0x0000, 0x0000, 0x0000, 0x0166, 0x0000,
};
uint32_t h[3];
mi_vector_hash(key, keylen, 0x8e1051e9U, h);
return (g[h[0] % 789] + g[h[1] % 789]) % 394;
}
const char *
_ti_strid(ssize_t idx)
{
if ((size_t)idx > __arraycount(_ti_strids))
return NULL;
return _ti_strids[idx];
}
ssize_t
_ti_strindex(const char *key)
{
uint32_t idx;
idx = _ti_strhash((const unsigned char *)key, strlen(key));
if (idx > __arraycount(_ti_strids) ||
strcmp(key, _ti_strids[idx]) != 0)
return -1;
return idx;
}

View file

@ -0,0 +1,10 @@
NETBSDSRCDIR= ${MINIXSRCDIR}
NETBSDINCLUDES= /usr/include/
MACHINE_ARCH?= i386
CPPFLAGS+= -D_NETBSD_SOURCE
MKLINKLIB= yes
MKPROFILE= no
MKPIC= no

View file

@ -0,0 +1,25 @@
diff -ru nbsdsrc/src/lib/libterminfo/Makefile lib/libterminfo/Makefile
--- nbsdsrc/src/lib/libterminfo/Makefile
+++ lib/libterminfo/Makefile
@@ -1,6 +1,11 @@
# $NetBSD: Makefile,v 1.12 2010/07/06 05:59:53 mrg Exp $
+.if defined(__MINIX)
+.include "minix-config.inc"
+USE_SHLIBDIR= no
+.else
USE_SHLIBDIR= yes
+.endif
LIB= terminfo
WARNS= 4
@@ -54,7 +59,9 @@
gen: hash compiled_terms man
.include <bsd.own.mk>
+.if !defined(__MINIX)
.include <bsd.shlib.mk>
+.endif
.if ${MKLINKLIB} != "no"
SYMLINKS+= libterminfo.a ${LIBDIR}/libtermcap.a

126
lib/libterminfo/setupterm.c Normal file
View file

@ -0,0 +1,126 @@
/* $NetBSD: setupterm.c,v 1.2 2010/02/11 00:27:09 roy Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
*
* 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 <sys/cdefs.h>
__RCSID("$NetBSD: setupterm.c,v 1.2 2010/02/11 00:27:09 roy Exp $");
#include <assert.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <term_private.h>
#include <term.h>
#define reterr(code, msg) \
do { \
if (errret == NULL) \
errx(EXIT_FAILURE, msg); \
else { \
*errret = code; \
return ERR; \
} \
} while (0 /* CONSTCOND */)
#define reterrarg(code, msg, arg) \
do { \
if (errret == NULL) \
errx(EXIT_FAILURE, msg, arg); \
else { \
*errret = code; \
return ERR; \
} \
} while (0 /* CONSTCOND */)
int
ti_setupterm(TERMINAL **nterm, const char *term, int fildes, int *errret)
{
int error;
_DIAGASSERT(nterm != NULL);
if (term == NULL)
term = getenv("TERM");
if (term == NULL || *term == '\0') {
*nterm = NULL;
reterr(0, "TERM environment variable not set");
}
if (fildes == STDOUT_FILENO && !isatty(fildes))
fildes = STDERR_FILENO;
*nterm = calloc(1, sizeof(**nterm));
if (*nterm == NULL)
reterr(-1, "not enough memory to create terminal structure");
error = _ti_getterm(*nterm, term, 0);
if (error != 1) {
free(*nterm);
*nterm = NULL;
switch (error) {
case -1:
reterr(error, "cannot access the terminfo database");
/* NOTREACHED */
case 0:
reterrarg(error,
"%s: terminal not listed in terminfo datase",
term);
/* NOTREACHED */
default:
reterr(-1, "unknown error");
/* NOTREACHED */
}
}
(*nterm)->fildes = fildes;
_ti_setospeed(*nterm);
if (t_generic_type(*nterm))
reterrarg(0, "%s: generic terminal", term);
if (t_hard_copy(*nterm))
reterrarg(1, "%s: hardcopy terminal", term);
/* POSIX requires 1 for success */
if (errret)
*errret = 1;
return OK;
}
int
setupterm(const char *term, int fildes, int *errret)
{
TERMINAL *nterm;
int ret;
if (errret != NULL)
*errret = ERR;
ret = ti_setupterm(&nterm, term, fildes, errret);
if (nterm != NULL)
set_curterm(nterm);
return ret;
}

View file

@ -0,0 +1,5 @@
# $NetBSD: shlib_version,v 1.1 2010/02/03 15:16:32 roy Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=1
minor=0

418
lib/libterminfo/term.c Normal file
View file

@ -0,0 +1,418 @@
/* $NetBSD: term.c,v 1.11 2010/02/26 00:09:00 roy Exp $ */
/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
*
* 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 <sys/cdefs.h>
__RCSID("$NetBSD: term.c,v 1.11 2010/02/26 00:09:00 roy Exp $");
#include <sys/stat.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <ndbm.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <term_private.h>
#include <term.h>
#define _PATH_TERMINFO "/usr/share/misc/terminfo"
static char database[PATH_MAX];
static char pathbuf[PATH_MAX];
const char *_ti_database;
/* Include a generated list of pre-compiled terminfo descriptions. */
#include "compiled_terms.c"
static int
_ti_readterm(TERMINAL *term, const char *cap, size_t caplen, int flags)
{
uint8_t ver;
uint16_t ind, num;
size_t len;
TERMUSERDEF *ud;
ver = *cap++;
/* Only read version 1 and 2 structures */
if (ver != 1 && ver != 2) {
errno = EINVAL;
return -1;
}
term->flags = calloc(TIFLAGMAX + 1, sizeof(char));
if (term->flags == NULL)
goto err;
term->nums = malloc((TINUMMAX + 1) * sizeof(short));
if (term->nums == NULL)
goto err;
memset(term->nums, (short)-1, (TINUMMAX + 1) * sizeof(short));
term->strs = calloc(TISTRMAX + 1, sizeof(char *));
if (term->strs == NULL)
goto err;
term->_arealen = caplen;
term->_area = malloc(term->_arealen);
if (term->_area == NULL)
goto err;
memcpy(term->_area, cap, term->_arealen);
cap = term->_area;
len = le16dec(cap);
cap += sizeof(uint16_t);
term->name = cap;
cap += len;
if (ver == 1)
term->_alias = NULL;
else {
len = le16dec(cap);
cap += sizeof(uint16_t);
if (len == 0)
term->_alias = NULL;
else {
term->_alias = cap;
cap += len;
}
}
len = le16dec(cap);
cap += sizeof(uint16_t);
if (len == 0)
term->desc = NULL;
else {
term->desc = cap;
cap += len;
}
num = le16dec(cap);
cap += sizeof(uint16_t);
if (num != 0) {
num = le16dec(cap);
cap += sizeof(uint16_t);
for (; num != 0; num--) {
ind = le16dec(cap);
cap += sizeof(uint16_t);
term->flags[ind] = *cap++;
if (flags == 0 && !VALID_BOOLEAN(term->flags[ind]))
term->flags[ind] = 0;
}
}
num = le16dec(cap);
cap += sizeof(uint16_t);
if (num != 0) {
num = le16dec(cap);
cap += sizeof(uint16_t);
for (; num != 0; num--) {
ind = le16dec(cap);
cap += sizeof(uint16_t);
term->nums[ind] = le16dec(cap);
if (flags == 0 && !VALID_NUMERIC(term->nums[ind]))
term->nums[ind] = ABSENT_NUMERIC;
cap += sizeof(uint16_t);
}
}
num = le16dec(cap);
cap += sizeof(uint16_t);
if (num != 0) {
num = le16dec(cap);
cap += sizeof(uint16_t);
for (; num != 0; num--) {
ind = le16dec(cap);
cap += sizeof(uint16_t);
len = le16dec(cap);
cap += sizeof(uint16_t);
if (len > 0)
term->strs[ind] = cap;
else if (flags == 0)
term->strs[ind] = ABSENT_STRING;
else
term->strs[ind] = CANCELLED_STRING;
cap += len;
}
}
num = le16dec(cap);
cap += sizeof(uint16_t);
if (num != 0) {
term->_nuserdefs = le16dec(cap);
term->_userdefs = malloc(sizeof(*term->_userdefs) * num);
cap += sizeof(uint16_t);
for (num = 0; num < term->_nuserdefs; num++) {
ud = &term->_userdefs[num];
len = le16dec(cap);
cap += sizeof(uint16_t);
ud->id = cap;
cap += len;
ud->type = *cap++;
switch (ud->type) {
case 'f':
ud->flag = *cap++;
if (flags == 0 &&
!VALID_BOOLEAN(ud->flag))
ud->flag = 0;
ud->num = ABSENT_NUMERIC;
ud->str = ABSENT_STRING;
break;
case 'n':
ud->flag = ABSENT_BOOLEAN;
ud->num = le16dec(cap);
if (flags == 0 &&
!VALID_NUMERIC(ud->num))
ud->num = ABSENT_NUMERIC;
ud->str = ABSENT_STRING;
cap += sizeof(uint16_t);
break;
case 's':
ud->flag = ABSENT_BOOLEAN;
ud->num = ABSENT_NUMERIC;
len = le16dec(cap);
cap += sizeof(uint16_t);
if (len > 0)
ud->str = cap;
else if (flags == 0)
ud->str = ABSENT_STRING;
else
ud->str = CANCELLED_STRING;
cap += len;
break;
default:
errno = EINVAL;
goto err;
}
}
}
return 1;
err:
_ti_freeterm(term);
return -1;
}
static int
_ti_dbgetterm(TERMINAL *term, const char *path, const char *name, int flags)
{
DBM *db;
datum dt;
char *p;
int r;
db = dbm_open(path, O_RDONLY, 0644);
if (db == NULL)
return -1;
strlcpy(database, path, sizeof(database));
_ti_database = database;
dt.dptr = (void *)__UNCONST(name);
dt.dsize = strlen(name);
dt = dbm_fetch(db, dt);
if (dt.dptr == NULL) {
dbm_close(db);
return 0;
}
for (;;) {
p = (char *)dt.dptr;
if (*p++ != 0) /* not alias */
break;
dt.dsize = le16dec(p) - 1;
p += sizeof(uint16_t);
dt.dptr = p;
dt = dbm_fetch(db, dt);
if (dt.dptr == NULL) {
dbm_close(db);
return 0;
}
}
r = _ti_readterm(term, (char *)dt.dptr, dt.dsize, flags);
dbm_close(db);
return r;
}
static int
_ti_dbgettermp(TERMINAL *term, const char *path, const char *name, int flags)
{
const char *p;
size_t l;
int r, e;
e = -1;
r = 0;
do {
for (p = path; *path != '\0' && *path != ':'; path++)
continue;
l = path - p;
if (l != 0 && l + 1 < sizeof(pathbuf)) {
memcpy(pathbuf, p, l);
pathbuf[l] = '\0';
r = _ti_dbgetterm(term, pathbuf, name, flags);
if (r == 1)
return 1;
if (r == 0)
e = 0;
}
} while (*path++ == ':');
return e;
}
static int
ticcmp(const TIC *tic, const char *name)
{
char *alias, *s;
size_t len, l;
if (strcmp(tic->name, name) == 0)
return 0;
if (tic->alias == NULL)
return -1;
len = strlen(name);
alias = tic->alias;
while (*alias != '\0') {
s = strchr(alias, '|');
if (s == NULL)
l = strlen(alias);
else
l = s - alias;
if (len == l && strncmp(alias, name, l) == 0)
return 0;
if (s == NULL)
break;
alias = s + 1;
}
return 1;
}
static int
_ti_findterm(TERMINAL *term, const char *name, int flags)
{
int r;
char *c, *e, h[PATH_MAX];
TIC *tic;
uint8_t *f;
ssize_t len;
_DIAGASSERT(term != NULL);
_DIAGASSERT(name != NULL);
database[0] = '\0';
_ti_database = NULL;
r = 0;
if ((e = getenv("TERMINFO")) != NULL && *e != '\0')
if (e[0] == '/')
return _ti_dbgetterm(term, e, name, flags);
c = NULL;
if (e == NULL && (c = getenv("TERMCAP")) != NULL) {
if (*c != '\0' && *c != '/') {
c = strdup(c);
if (c != NULL) {
e = captoinfo(c);
free(c);
}
}
}
if (e != NULL) {
if (c == NULL)
e = strdup(e); /* So we don't destroy env */
if (e == NULL)
tic = NULL;
else
tic = _ti_compile(e, TIC_WARNING |
TIC_ALIAS | TIC_DESCRIPTION | TIC_EXTRA);
if (c == NULL && e != NULL)
free(e);
if (tic != NULL && ticcmp(tic, name) == 0) {
len = _ti_flatten(&f, tic);
if (len != -1) {
r = _ti_readterm(term, (char *)f, len, flags);
free(f);
}
}
_ti_freetic(tic);
if (r == 1) {
if (c == NULL)
_ti_database = "$TERMINFO";
else
_ti_database = "$TERMCAP";
return r;
}
}
if ((e = getenv("TERMINFO_DIRS")) != NULL)
return _ti_dbgettermp(term, e, name, flags);
if ((e = getenv("HOME")) != NULL) {
snprintf(h, sizeof(h), "%s/.terminfo", e);
r = _ti_dbgetterm(term, h, name, flags);
}
if (r != 1)
r = _ti_dbgettermp(term, _PATH_TERMINFO, name, flags);
return r;
}
int
_ti_getterm(TERMINAL *term, const char *name, int flags)
{
int r;
size_t i;
const struct compiled_term *t;
r = _ti_findterm(term, name, flags);
if (r == 1)
return r;
for (i = 0; i < __arraycount(compiled_terms); i++) {
t = &compiled_terms[i];
if (strcmp(name, t->name) == 0) {
r = _ti_readterm(term, t->cap, t->caplen, flags);
break;
}
}
return r;
}
void
_ti_freeterm(TERMINAL *term)
{
if (term != NULL) {
free(term->_area);
free(term->strs);
free(term->nums);
free(term->flags);
free(term->_userdefs);
}
}

1520
lib/libterminfo/term.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,154 @@
/* $NetBSD: term_private.h,v 1.8 2010/09/22 06:10:51 roy Exp $ */
/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
*
* 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.
*/
#ifndef _TERM_PRIVATE_H_
#define _TERM_PRIVATE_H_
/* This header should only be used by libterminfo, tic and infocmp. */
/* The terminfo database structure is private to us,
* so it's documented here.
* terminfo defines the largest number as 32767 and the largest
* compiled entry as 4093 bytes long.
* Thus, we store all numbers as uint16_t, including string length.
* All strings are prefixed by length, including the null terminator.
* The largest string length we can handle is 65535 bytes,
* including the null terminator.
* The largest capability block we can handle is 65535 bytes.
* This means that we exceed the current terminfo defined limits.
* The header is version (char), name.
* version 0 is an alias, and the name refers to the real terminfo.
* version 1 capabilities are defined as so:
* description,
* cap length, num flags, index, char,
* cap length, num numbers, index, number,
* cap length, num strings, index, string,
* cap lelngth, num undefined caps, name, type (char), flag, number, string
* The database itself is created using ndbm(3) and the numbers are
* always stored as little endian.
*/
#include <sys/types.h>
#define _TERMINFO
/* We use the same ncurses tic macros so that our data is identical
* when a caller uses the long name macros to access te terminfo data
* directly. */
#define ABSENT_BOOLEAN ((signed char)-1) /* 255 */
#define ABSENT_NUMERIC (-1)
#define ABSENT_STRING (char *)0
#define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */
#define CANCELLED_NUMERIC (-2)
#define CANCELLED_STRING (char *)(-1)
#define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
#define VALID_NUMERIC(s) ((s) >= 0)
#define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
typedef struct {
const char *id;
char type;
char flag;
short num;
const char *str;
} TERMUSERDEF;
typedef struct {
int fildes;
/* We need to expose these so that the macros work */
const char *name;
const char *desc;
signed char *flags;
short *nums;
const char **strs;
/* Storage area for terminfo data */
char *_area;
size_t _arealen;
size_t _nuserdefs;
TERMUSERDEF *_userdefs;
/* So we don't rely on the global ospeed */
short _ospeed;
/* Output buffer for tparm */
char *_buf;
size_t _buflen;
size_t _bufpos;
/* A-Z static variables for tparm */
long _snums[26];
/* aliases of the terminal, | separated */
const char *_alias;
} TERMINAL;
extern const char * _ti_database;
ssize_t _ti_flagindex(const char *);
ssize_t _ti_numindex(const char *);
ssize_t _ti_strindex(const char *);
const char * _ti_flagid(ssize_t);
const char * _ti_numid(ssize_t);
const char * _ti_strid(ssize_t);
int _ti_getterm(TERMINAL *, const char *, int);
void _ti_setospeed(TERMINAL *);
void _ti_freeterm(TERMINAL *);
/* libterminfo can compile terminfo strings too */
#define TIC_WARNING (1 << 0)
#define TIC_DESCRIPTION (1 << 1)
#define TIC_ALIAS (1 << 2)
#define TIC_COMMENT (1 << 3)
#define TIC_EXTRA (1 << 4)
#define UINT16_T_MAX 0xffff
typedef struct {
char *buf;
size_t buflen;
size_t bufpos;
size_t entries;
} TBUF;
typedef struct {
char *name;
char *alias;
char *desc;
TBUF flags;
TBUF nums;
TBUF strs;
TBUF extras;
} TIC;
char *_ti_grow_tbuf(TBUF *, size_t);
char *_ti_get_token(char **, char);
char *_ti_find_cap(TBUF *, char, short);
char *_ti_find_extra(TBUF *, const char *);
size_t _ti_store_extra(TIC *, int, char *, char, char, short,
char *, size_t, int);
TIC *_ti_compile(char *, int);
ssize_t _ti_flatten(uint8_t **, const TIC *);
void _ti_freetic(TIC *);
#endif

144
lib/libterminfo/termcap.3 Normal file
View file

@ -0,0 +1,144 @@
.\" $NetBSD: termcap.3,v 1.4 2010/02/04 09:12:55 wiz Exp $
.\"
.\" Copyright (c) 2009 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Roy Marples.
.\"
.\" 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
.\"
.Dd December 7, 2009
.Dt TERMCAP 3
.Os
.Sh NAME
.Nm tgetent ,
.Nm tgetnum ,
.Nm tgetflag ,
.Nm tgetstr ,
.Nm tgoto ,
.Nm tputs
.Nd terminal independent operation routines
.Sh LIBRARY
.Lb libtermcap
.Sh SYNOPSIS
.In termcap.h
.Vt char PC ;
.Vt char *BC ;
.Vt char *UP ;
.Ft int
.Fn tgetent "char *bp" "const char *name"
.Ft int
.Fn tgetnum "const char *id"
.Ft int
.Fn tgetflag "const char *id"
.Ft char *
.Fn tgetstr "const char *id" "char **area"
.Ft char *
.Fn tgoto "const char *cm" "int destcol" "int destline"
.Sh DESCRIPTION
These functions extract and use capabilities from a terminal capability
database.
They exist as wrappers around equivalent
.Xr terminfo 3
functions, which new code should use.
These are low level routines; see
.Xr curses 3
for a higher level package.
.Pp
The
.Fn tgetent
function calls
.Fn setupterm
and configures
.Va PC ,
.Va UP
and
.Va BC .
Only
.Va PC
is actually used internally.
The
.Fn tgetent
function returns \-1 if none of the
.Nm terminfo
data base files could be opened,
0 if the terminal name given does not match an entry,
and 1 if all goes well.
The
.Fa bp
argument is not used.
.Pp
The
.Fn tgetnum
function gets the numeric value of the capability
.Fa id ,
returning \-1 if it is not given for the terminal.
The
.Fn tgetflag
function returns 1 if the specified capability is present in the terminal's
entry, 0 if it is not.
The
.Fn tgetstr
function returns the string value of the capability
.Fa id .
This is a
.Xr terminfo 5
string and not a
.Nm termcap
string;
as such it should only be processed by
.Fn tgoto .
The
.Fn tgetstr
function returns
.Dv NULL
if the capability was not found.
The
.Fa area
argument is unused.
.Pp
The
.Fn tgoto
function returns a cursor addressing string decoded from
.Fa cm
to go to column
.Fa destcol
in line
.Fa destline .
.Sh SEE ALSO
.Xr terminfo 3 ,
.Xr terminfo 5
.Sh HISTORY
.Nm termcap
first appeared in 4.0BSD.
.Nx 1.5
introduced some
.Nm termcap
.Fn t_*
extensions which were removed in
.Nx 6.0
when
.Xr terminfo 3
was introduced.
.Sh AUTHORS
.An Roy Marples Aq roy@NetBSD.org

457
lib/libterminfo/termcap.c Normal file
View file

@ -0,0 +1,457 @@
/* $NetBSD: termcap.c,v 1.10 2010/10/12 12:49:27 christos Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
*
* 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 <sys/cdefs.h>
__RCSID("$NetBSD: termcap.c,v 1.10 2010/10/12 12:49:27 christos Exp $");
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <stdint.h>
#include <string.h>
#include <term_private.h>
#include <term.h>
#include <termcap.h>
#include <unistd.h>
#include <stdio.h>
#include "termcap_map.c"
#include "termcap_hash.c"
char *UP;
char *BC;
/* ARGSUSED */
int
tgetent(__unused char *bp, const char *name)
{
int errret;
static TERMINAL *last = NULL;
_DIAGASSERT(name != NULL);
/* Free the old term */
if (last != NULL) {
del_curterm(last);
last = NULL;
}
errret = -1;
if (setupterm(name, STDOUT_FILENO, &errret) != 0)
return errret;
last = cur_term;
if (pad_char != NULL)
PC = pad_char[0];
UP = __UNCONST(cursor_up);
BC = __UNCONST(cursor_left);
return 1;
}
int
tgetflag(const char *id)
{
uint32_t ind;
size_t i;
TERMUSERDEF *ud;
_DIAGASSERT(id != NULL);
if (cur_term == NULL)
return 0;
ind = _t_flaghash((const unsigned char *)id, strlen(id));
if (ind <= __arraycount(_ti_cap_flagids)) {
if (strcmp(id, _ti_cap_flagids[ind].id) == 0)
return cur_term->flags[_ti_cap_flagids[ind].ti];
}
for (i = 0; i < cur_term->_nuserdefs; i++) {
ud = &cur_term->_userdefs[i];
if (ud->type == 'f' && strcmp(ud->id, id) == 0)
return ud->flag;
}
return 0;
}
int
tgetnum(const char *id)
{
uint32_t ind;
size_t i;
TERMUSERDEF *ud;
const TENTRY *te;
_DIAGASSERT(id != NULL);
if (cur_term == NULL)
return -1;
ind = _t_numhash((const unsigned char *)id, strlen(id));
if (ind <= __arraycount(_ti_cap_numids)) {
te = &_ti_cap_numids[ind];
if (strcmp(id, te->id) == 0) {
if (!VALID_NUMERIC(cur_term->nums[te->ti]))
return ABSENT_NUMERIC;
return cur_term->nums[te->ti];
}
}
for (i = 0; i < cur_term->_nuserdefs; i++) {
ud = &cur_term->_userdefs[i];
if (ud->type == 'n' && strcmp(ud->id, id) == 0) {
if (!VALID_NUMERIC(ud->num))
return ABSENT_NUMERIC;
return ud->num;
}
}
return -1;
}
char *
tgetstr(const char *id, char **area)
{
uint32_t ind;
size_t i;
TERMUSERDEF *ud;
const char *str;
_DIAGASSERT(id != NULL);
if (cur_term == NULL)
return NULL;
str = NULL;
ind = _t_strhash((const unsigned char *)id, strlen(id));
if (ind <= __arraycount(_ti_cap_strids)) {
if (strcmp(id, _ti_cap_strids[ind].id) == 0) {
str = cur_term->strs[_ti_cap_strids[ind].ti];
if (str == NULL)
return NULL;
}
}
if (str != NULL)
for (i = 0; i < cur_term->_nuserdefs; i++) {
ud = &cur_term->_userdefs[i];
if (ud->type == 's' && strcmp(ud->id, id) == 0)
str = ud->str;
}
/* XXX: FXIXME
* We should fix sgr0(me) as it has a slightly different meaning
* for termcap. */
if (str != NULL && area != NULL && *area != NULL) {
char *s;
s = *area;
strcpy(*area, str);
*area += strlen(*area) + 1;
return s;
}
return __UNCONST(str);
}
char *
tgoto(const char *cm, int destcol, int destline)
{
_DIAGASSERT(cm != NULL);
return vtparm(cm, destline, destcol);
}
static const char *
flagname(const char *key)
{
uint32_t idx;
idx = _t_flaghash((const unsigned char *)key, strlen(key));
if (idx <= __arraycount(_ti_cap_flagids) &&
strcmp(key, _ti_cap_flagids[idx].id) == 0)
return _ti_flagid(_ti_cap_flagids[idx].ti);
return key;
}
static const char *
numname(const char *key)
{
uint32_t idx;
idx = _t_numhash((const unsigned char *)key, strlen(key));
if (idx <= __arraycount(_ti_cap_numids) &&
strcmp(key, _ti_cap_numids[idx].id) == 0)
return _ti_numid(_ti_cap_numids[idx].ti);
return key;
}
static const char *
strname(const char *key)
{
uint32_t idx;
idx = _t_strhash((const unsigned char *)key, strlen(key));
if (idx <= __arraycount(_ti_cap_strids) &&
strcmp(key, _ti_cap_strids[idx].id) == 0)
return _ti_strid(_ti_cap_strids[idx].ti);
if (strcmp(key, "tc") == 0)
return "use";
return key;
}
/* We don't currently map %> %B %D
* That means no conversion for regent100, hz1500, act4, act5, mime terms. */
static char *
strval(const char *val)
{
char *info, *ip, c;
const char *ps, *pe;
int p;
size_t len, l;
len = 1024; /* no single string should be bigger */
info = ip = malloc(len);
if (info == NULL)
return 0;
/* Move the = */
*ip++ = *val++;
/* Set ps and pe to point to the start and end of the padding */
if (isdigit((unsigned char)*val)) {
for (ps = pe = val;
isdigit((unsigned char)*val) || *val == '.';
val++)
pe++;
if (*val == '*') {
val++;
pe++;
}
} else
ps = pe = NULL;
l = 0;
p = 1;
for (; *val != '\0'; val++) {
if (l + 2 > len)
goto elen;
if (*val != '%') {
if (*val == ',') {
if (l + 3 > len)
goto elen;
*ip++ = '\\';
l++;
}
*ip++ = *val;
l++;
continue;
}
switch (c = *(++val)) {
case 'd':
if (l + 6 > len)
goto elen;
*ip++ = '%';
*ip++ = 'p';
*ip++ = '0' + p;
*ip++ = '%';
*ip++ = 'd';
l += 5;
/* FALLTHROUGH */
case 'r':
p = 3 - p;
break;
default:
/* Hope it matches a terminfo command. */
*ip++ = '%';
*ip++ = c;
l += 2;
break;
}
}
/* \E\ is valid termcap.
* We need to escape the final \ for terminfo. */
if (l > 2 && info[l - 1] == '\\' &&
(info[l - 2] != '\\' && info[l - 2] != '^'))
{
if (l + 1 > len)
goto elen;
*ip++ = '\\';
}
/* Add our padding at the end. */
if (ps != NULL) {
size_t n = pe - ps;
if (l + n + 4 > len)
goto elen;
*ip++ = '$';
*ip++ = '<';
strncpy(ip, ps, n);
ip += n;
*ip++ = '/';
*ip++ = '>';
}
*ip = '\0';
return info;
elen:
free(info);
errno = ENOMEM;
return NULL;
}
typedef struct {
const char *name;
const char *cap;
} DEF_INFO;
static DEF_INFO def_infos[] = {
{ "bel", "^G" },
{ "cr", "^M" },
{ "cud1", "^J" },
{ "ht", "^I" },
{ "ind", "^J" },
{ "kbs", "^H" },
{ "kcub1", "^H" },
{ "kcud1", "^J" },
{ "nel", "^M^J" }
};
char *
captoinfo(char *cap)
{
char *info, *ip, *token, *val, *p, tok[3];
const char *name;
size_t len, lp, nl, vl, rl;
int defs[__arraycount(def_infos)], fv;
_DIAGASSERT(cap != NULL);
len = strlen(cap) * 2;
len += __arraycount(def_infos) * (5 + 4 + 3); /* reserve for defs */
info = ip = malloc(len);
if (info == NULL)
return NULL;
memset(defs, 0, sizeof(defs));
lp = 0;
tok[2] = '\0';
for (token = _ti_get_token(&cap, ':');
token != NULL;
token = _ti_get_token(&cap, ':'))
{
if (token[0] == '\0')
continue;
name = token;
val = p = NULL;
fv = nl = 0;
if (token[1] != '\0') {
tok[0] = token[0];
tok[1] = token[1];
nl = 1;
if (token[2] == '\0') {
name = flagname(tok);
val = NULL;
} else if (token[2] == '#') {
name = numname(tok);
val = token + 2;
} else if (token[2] == '=') {
name = strname(tok);
val = strval(token + 2);
fv = 1;
} else
nl = 0;
}
/* If not matched we may need to convert padding still. */
if (nl == 0) {
p = strchr(name, '=');
if (p != NULL) {
val = strval(p);
*p = '\0';
fv = 1;
}
}
/* See if this sets a default. */
for (nl = 0; nl < __arraycount(def_infos); nl++) {
if (strcmp(name, def_infos[nl].name) == 0) {
defs[nl] = 1;
break;
}
}
nl = strlen(name);
if (val == NULL)
vl = 0;
else
vl = strlen(val);
rl = nl + vl + 3; /* , \0 */
if (lp + rl > len) {
if (rl < 256)
len += 256;
else
len += rl;
p = realloc(info, len);
if (p == NULL)
return NULL;
info = p;
}
if (ip != info) {
*ip++ = ',';
*ip++ = ' ';
}
strcpy(ip, name);
ip += nl;
if (val != NULL) {
strcpy(ip, val);
ip += vl;
if (fv == 1)
free(val);
}
}
/* Add any defaults not set above. */
for (nl = 0; nl < __arraycount(def_infos); nl++) {
if (defs[nl] == 0) {
*ip++ = ',';
*ip++ = ' ';
strcpy(ip, def_infos[nl].name);
ip += strlen(def_infos[nl].name);
*ip++ = '=';
strcpy(ip, def_infos[nl].cap);
ip += strlen(def_infos[nl].cap);
}
}
*ip = '\0';
return info;
}

57
lib/libterminfo/termcap.h Normal file
View file

@ -0,0 +1,57 @@
/* $NetBSD: termcap.h,v 1.1 2010/02/03 15:16:32 roy Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
*
* 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.
*/
#ifndef _TERMCAP_H_
#define _TERMCAP_H_
#include <sys/cdefs.h>
__BEGIN_DECLS
#ifndef _TERM_H
/* Output functions.
* These are still valid for terminfo. */
int putp(const char *);
int tputs(const char *, int, int (*)(int));
extern short ospeed;
extern char PC;
#endif
extern char *BC;
extern char *UP;
int tgetent(char *, const char *);
char * tgetstr(const char *, char **);
int tgetflag(const char *);
int tgetnum(const char *);
char * tgoto(const char *, int, int);
__END_DECLS
#endif

View file

@ -0,0 +1,163 @@
/* $NetBSD: termcap_hash.c,v 1.3 2010/02/12 10:18:56 roy Exp $ */
/* DO NOT EDIT
* Automatically generated from termcap.c */
#include <sys/cdefs.h>
__RCSID("$NetBSD: termcap_hash.c,v 1.3 2010/02/12 10:18:56 roy Exp $");
#include <stdint.h>
#include <stdlib.h>
#include <term_private.h>
#include <stdlib.h>
static uint32_t
_t_flaghash(const void * __restrict key, size_t keylen)
{
static const uint8_t g[75] = {
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x08, 0x00, 0x00, 0x19,
0x24, 0x0a, 0x00, 0x14, 0x20, 0x1d, 0x0e, 0x0d, 0x00, 0x0d,
0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x1a, 0x00,
0x12, 0x00, 0x16, 0x00, 0x1d, 0x00, 0x00, 0x11, 0x00, 0x00,
0x00, 0x17, 0x0e, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x10, 0x00,
0x00, 0x1f, 0x02, 0x00, 0x00, 0x00, 0x0c, 0x13, 0x00, 0x23,
0x00, 0x1f, 0x00, 0x00, 0x05, 0x00, 0x00, 0x15, 0x1d, 0x00,
0x09, 0x00, 0x0f, 0x1b, 0x01,
};
uint32_t h[3];
mi_vector_hash(key, keylen, 0x5a53bb7cU, h);
return (g[h[0] % 75] + g[h[1] % 75]) % 37;
}
#include <stdlib.h>
static uint32_t
_t_numhash(const void * __restrict key, size_t keylen)
{
static const uint8_t g[67] = {
0x03, 0x0e, 0x17, 0x01, 0x10, 0x00, 0x00, 0x00, 0x1e, 0x00,
0x10, 0x00, 0x05, 0x13, 0x00, 0x00, 0x17, 0x00, 0x06, 0x18,
0x03, 0x00, 0x00, 0x09, 0x18, 0x00, 0x07, 0x00, 0x00, 0x0c,
0x14, 0x03, 0x01, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
0x00, 0x1e, 0x00, 0x1d, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04,
0x17, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x0e, 0x0e,
0x00, 0x0e, 0x00, 0x00, 0x00, 0x12, 0x00,
};
uint32_t h[3];
mi_vector_hash(key, keylen, 0x6452f8e6U, h);
return (g[h[0] % 67] + g[h[1] % 67]) % 33;
}
#include <stdlib.h>
static uint32_t
_t_strhash(const void * __restrict key, size_t keylen)
{
static const uint16_t g[789] = {
0x0047, 0x015c, 0x002c, 0x00b5, 0x0000, 0x0000, 0x00ea, 0x0000,
0x0000, 0x0127, 0x0000, 0x00a7, 0x00c0, 0x00ee, 0x0000, 0x0049,
0x0000, 0x0000, 0x0000, 0x004a, 0x0136, 0x0000, 0x0140, 0x0000,
0x0016, 0x0123, 0x002f, 0x00e7, 0x0000, 0x0000, 0x0000, 0x0042,
0x0000, 0x00ee, 0x0000, 0x0000, 0x001c, 0x0009, 0x008b, 0x0000,
0x0002, 0x012d, 0x0000, 0x0000, 0x001f, 0x0000, 0x0000, 0x0000,
0x00c0, 0x0000, 0x0000, 0x0034, 0x004d, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x00de, 0x0152, 0x0000, 0x00d9, 0x00dc,
0x00c5, 0x0096, 0x0001, 0x0058, 0x010e, 0x00ba, 0x0000, 0x0000,
0x0021, 0x0000, 0x0000, 0x00f0, 0x0000, 0x0000, 0x00c6, 0x0000,
0x0094, 0x008d, 0x0021, 0x0000, 0x0000, 0x00b8, 0x0060, 0x0000,
0x000e, 0x0000, 0x0000, 0x003a, 0x0026, 0x0089, 0x003f, 0x0145,
0x0050, 0x0000, 0x0000, 0x0170, 0x00f0, 0x0000, 0x0000, 0x0000,
0x00b1, 0x007d, 0x0045, 0x00de, 0x006d, 0x0092, 0x0000, 0x0177,
0x0049, 0x0000, 0x0000, 0x017a, 0x0000, 0x00e1, 0x0023, 0x0000,
0x0000, 0x0000, 0x0096, 0x0098, 0x0000, 0x0000, 0x0000, 0x0000,
0x0176, 0x0089, 0x00fd, 0x0000, 0x0000, 0x00e5, 0x0000, 0x0000,
0x0170, 0x0000, 0x014b, 0x0022, 0x0075, 0x0000, 0x0000, 0x0000,
0x0170, 0x0015, 0x014f, 0x012e, 0x0041, 0x010c, 0x0159, 0x00c1,
0x0000, 0x0000, 0x0000, 0x0000, 0x0147, 0x0011, 0x0045, 0x0150,
0x0000, 0x0000, 0x0000, 0x0000, 0x003e, 0x0000, 0x0000, 0x0168,
0x00fe, 0x0000, 0x0000, 0x00b2, 0x0000, 0x007a, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0079, 0x0000, 0x0031, 0x015e, 0x0024,
0x0090, 0x0000, 0x0000, 0x0000, 0x005b, 0x0000, 0x00eb, 0x0000,
0x0142, 0x0091, 0x016f, 0x0180, 0x00a8, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x00e2, 0x0075, 0x0000, 0x0000,
0x0000, 0x0000, 0x0050, 0x016d, 0x00f5, 0x0018, 0x006d, 0x0059,
0x00bb, 0x0048, 0x0000, 0x0000, 0x0000, 0x0000, 0x00ec, 0x0130,
0x0054, 0x0067, 0x0000, 0x0000, 0x0000, 0x016e, 0x0072, 0x0154,
0x0000, 0x0000, 0x0000, 0x012d, 0x00a5, 0x007c, 0x0000, 0x0036,
0x0071, 0x0000, 0x0080, 0x0000, 0x00ba, 0x0000, 0x00e5, 0x0064,
0x0173, 0x006c, 0x0043, 0x00ab, 0x0152, 0x0082, 0x0000, 0x0172,
0x0000, 0x0000, 0x0000, 0x0000, 0x0172, 0x010a, 0x0000, 0x003e,
0x015b, 0x0000, 0x00dd, 0x0088, 0x0000, 0x003e, 0x0152, 0x006a,
0x0000, 0x0000, 0x0000, 0x0169, 0x0076, 0x008e, 0x000a, 0x009b,
0x0000, 0x0000, 0x0033, 0x014e, 0x0000, 0x0000, 0x0145, 0x0041,
0x00bd, 0x012f, 0x0177, 0x0053, 0x0031, 0x0054, 0x0000, 0x0000,
0x0000, 0x0105, 0x0000, 0x0000, 0x0000, 0x0000, 0x011b, 0x00b6,
0x00c7, 0x00b4, 0x0000, 0x0000, 0x0112, 0x009b, 0x0000, 0x0000,
0x00cd, 0x0000, 0x0052, 0x0094, 0x005d, 0x00f7, 0x00f5, 0x011a,
0x0000, 0x0000, 0x00ed, 0x0000, 0x00c2, 0x0000, 0x0000, 0x0000,
0x011b, 0x0000, 0x0000, 0x0000, 0x0124, 0x0064, 0x0000, 0x0000,
0x0045, 0x0063, 0x0131, 0x0170, 0x0000, 0x0090, 0x0000, 0x0000,
0x0000, 0x015d, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0023, 0x0146, 0x00ec, 0x0017, 0x0000, 0x0000, 0x0029, 0x0000,
0x0181, 0x0000, 0x0000, 0x00a0, 0x0000, 0x015e, 0x0043, 0x0000,
0x00f8, 0x0037, 0x0000, 0x0110, 0x0000, 0x0147, 0x0000, 0x009f,
0x006f, 0x0000, 0x0140, 0x008c, 0x0000, 0x0169, 0x0000, 0x0061,
0x005c, 0x0000, 0x0185, 0x0000, 0x0000, 0x0000, 0x001e, 0x0000,
0x0000, 0x0042, 0x0111, 0x0181, 0x0000, 0x006e, 0x0000, 0x0000,
0x0058, 0x0041, 0x0000, 0x0000, 0x0000, 0x0035, 0x0048, 0x00d9,
0x0000, 0x0000, 0x0000, 0x0166, 0x0033, 0x0000, 0x00f1, 0x0022,
0x00eb, 0x0110, 0x0000, 0x0000, 0x00ad, 0x0113, 0x015d, 0x0000,
0x012e, 0x0000, 0x0000, 0x0000, 0x0136, 0x0000, 0x0189, 0x0000,
0x0000, 0x00ce, 0x015a, 0x000b, 0x006f, 0x0000, 0x00a0, 0x0000,
0x0000, 0x0112, 0x017a, 0x0000, 0x0000, 0x0040, 0x0138, 0x008b,
0x007e, 0x0187, 0x0140, 0x00c2, 0x0000, 0x0061, 0x0000, 0x0155,
0x0000, 0x0000, 0x0117, 0x0000, 0x00c5, 0x0000, 0x0000, 0x00a0,
0x0000, 0x00e1, 0x0000, 0x0000, 0x0128, 0x0000, 0x0000, 0x0000,
0x0188, 0x0000, 0x005f, 0x0000, 0x0133, 0x0044, 0x0000, 0x0000,
0x0000, 0x0077, 0x0123, 0x0000, 0x010a, 0x005e, 0x0011, 0x00e2,
0x0000, 0x004c, 0x0000, 0x004d, 0x0000, 0x0000, 0x0000, 0x0088,
0x007a, 0x00fa, 0x0000, 0x004e, 0x0146, 0x0000, 0x006e, 0x0000,
0x0000, 0x0000, 0x009a, 0x0000, 0x007b, 0x0000, 0x00ee, 0x0086,
0x0000, 0x0000, 0x00ee, 0x0037, 0x0169, 0x0000, 0x0000, 0x00b5,
0x0000, 0x0164, 0x0000, 0x00d0, 0x005d, 0x0000, 0x0139, 0x0078,
0x00c4, 0x0000, 0x0127, 0x0062, 0x0124, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x009e, 0x00cc, 0x0000, 0x00f4, 0x0007,
0x0158, 0x0051, 0x0000, 0x0000, 0x0168, 0x0000, 0x00fe, 0x0009,
0x0141, 0x0000, 0x0154, 0x00ba, 0x0000, 0x00af, 0x016e, 0x0000,
0x00b0, 0x00ed, 0x0000, 0x0000, 0x0000, 0x012a, 0x0000, 0x0000,
0x0077, 0x0169, 0x0028, 0x0000, 0x0000, 0x0180, 0x0000, 0x013f,
0x0000, 0x017e, 0x0000, 0x0000, 0x0000, 0x0024, 0x0000, 0x0000,
0x0118, 0x0000, 0x0000, 0x0098, 0x0000, 0x016b, 0x0000, 0x0000,
0x0000, 0x0000, 0x0122, 0x0000, 0x0000, 0x0000, 0x0014, 0x0000,
0x0000, 0x0000, 0x0000, 0x002f, 0x016d, 0x00d3, 0x017e, 0x0000,
0x0000, 0x0052, 0x0172, 0x014b, 0x0141, 0x0000, 0x0000, 0x00c8,
0x0000, 0x0000, 0x0128, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x00b0, 0x0057, 0x0000, 0x0000, 0x0000,
0x0000, 0x0033, 0x0000, 0x0000, 0x0000, 0x00af, 0x00d4, 0x0000,
0x0000, 0x0000, 0x014a, 0x0038, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0137, 0x0000, 0x0000, 0x0018, 0x0000, 0x0004, 0x014d,
0x0020, 0x001c, 0x0000, 0x0000, 0x0000, 0x0160, 0x00f0, 0x013e,
0x0000, 0x0000, 0x0000, 0x00ca, 0x002a, 0x0000, 0x0000, 0x014b,
0x0047, 0x0000, 0x0000, 0x0122, 0x00bc, 0x002a, 0x0000, 0x006b,
0x0000, 0x0000, 0x0000, 0x0000, 0x0099, 0x00f0, 0x0000, 0x0000,
0x0000, 0x0000, 0x0027, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0070, 0x0000, 0x0000, 0x0000, 0x000f, 0x0000,
0x0009, 0x0061, 0x003f, 0x0135, 0x0000, 0x0123, 0x0181, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0115, 0x0059, 0x00a4, 0x0010,
0x0000, 0x0000, 0x0000, 0x0156, 0x0014, 0x0000, 0x0000, 0x0000,
0x0040, 0x00e5, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000,
0x0003, 0x010b, 0x0046, 0x012f, 0x0000, 0x0000, 0x0000, 0x0000,
0x004b, 0x0000, 0x002b, 0x0000, 0x0000, 0x0139, 0x00e8, 0x0000,
0x0154, 0x0000, 0x0000, 0x0000, 0x0000, 0x005a, 0x0000, 0x00e2,
0x0022, 0x00bd, 0x00a3, 0x00cb, 0x0144, 0x0143, 0x00f6, 0x0000,
0x0026, 0x012b, 0x0000, 0x0053, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0012, 0x0172, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x00b4, 0x0136,
};
uint32_t h[3];
mi_vector_hash(key, keylen, 0x9090e0f1U, h);
return (g[h[0] % 789] + g[h[1] % 789]) % 394;
}

View file

@ -0,0 +1,511 @@
/* $NetBSD: termcap_map.c,v 1.3 2010/09/22 06:10:51 roy Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
*
* 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 <sys/cdefs.h>
__RCSID("$NetBSD: termcap_map.c,v 1.3 2010/09/22 06:10:51 roy Exp $");
typedef struct {
const char id[3];
int ti;
} TENTRY;
static const TENTRY _ti_cap_flagids[] = {
{ "bw", TICODE_bw },
{ "am", TICODE_am },
{ "ut", TICODE_bce },
{ "cc", TICODE_ccc },
{ "xs", TICODE_xhp },
{ "YA", TICODE_xhpa },
{ "YF", TICODE_cpix },
{ "YB", TICODE_crxm },
{ "xt", TICODE_xt },
{ "xn", TICODE_xenl },
{ "eo", TICODE_eo },
{ "gn", TICODE_gn },
{ "hc", TICODE_hc },
{ "HC", TICODE_chts },
{ "km", TICODE_km },
{ "YC", TICODE_daisy },
{ "hs", TICODE_hs },
{ "hl", TICODE_hls },
{ "in", TICODE_in },
{ "YG", TICODE_lpix },
{ "da", TICODE_da },
{ "db", TICODE_db },
{ "mi", TICODE_mir },
{ "ms", TICODE_msgr },
{ "nx", TICODE_nxon },
{ "xb", TICODE_xsb },
{ "NP", TICODE_npc },
{ "ND", TICODE_ndscr },
{ "NR", TICODE_nrrmc },
{ "os", TICODE_os } ,
{ "5i", TICODE_mc5i },
{ "YD", TICODE_xvpa },
{ "YE", TICODE_sam },
{ "es", TICODE_eslok },
{ "hz", TICODE_hz },
{ "ul", TICODE_ul },
{ "xo", TICODE_xon }
};
static const TENTRY _ti_cap_numids[] = {
{ "Yo", TICODE_bitwin },
{ "Yp", TICODE_bitype },
{ "Ya", TICODE_bufsz },
{ "BT", TICODE_btns },
{ "co", TICODE_cols },
{ "Yc", TICODE_spinh },
{ "Yb", TICODE_spinv },
{ "it", TICODE_it },
{ "lh", TICODE_lh },
{ "lw", TICODE_lw },
{ "li", TICODE_lines },
{ "lm", TICODE_lm },
{ "ma", TICODE_ma },
{ "sg", TICODE_xmc },
{ "Co", TICODE_colors },
{ "Yd", TICODE_maddr },
{ "Ye", TICODE_mjump },
{ "pa", TICODE_pairs },
{ "MW", TICODE_wnum },
{ "Yf", TICODE_mcs },
{ "Yg", TICODE_mls },
{ "NC", TICODE_ncv },
{ "Nl", TICODE_nlab },
{ "Yh", TICODE_npins },
{ "Yi", TICODE_orc },
{ "Yj", TICODE_orl },
{ "Yk", TICODE_orhi },
{ "Yl", TICODE_orvi },
{ "pb", TICODE_pb },
{ "Ym", TICODE_cps },
{ "vt", TICODE_vt },
{ "Yn", TICODE_widcs },
{ "ws", TICODE_wsl }
};
static const TENTRY _ti_cap_strids[] = {
{ "ac", TICODE_acsc },
{ "S8", TICODE_scesa },
{ "bt", TICODE_cbt },
{ "bl", TICODE_bel },
{ "Yv", TICODE_bicr },
{ "Zz", TICODE_binel },
{ "Xy", TICODE_birep },
{ "cr", TICODE_cr },
{ "ZA", TICODE_cpi },
{ "ZB", TICODE_lpi },
{ "ZC", TICODE_chr },
{ "ZD", TICODE_cvr },
{ "cs", TICODE_csr },
{ "rP", TICODE_rmp },
{ "Zy", TICODE_csnm },
{ "ct", TICODE_tbc },
{ "MC", TICODE_mgc },
{ "cl", TICODE_clear },
{ "cb", TICODE_el1 },
{ "ce", TICODE_el },
{ "cd", TICODE_ed },
{ "ci", TICODE_csin },
{ "Yw", TICODE_colornm },
{ "ch", TICODE_hpa },
{ "CC", TICODE_cmdch },
{ "cm", TICODE_cup },
{ "do", TICODE_cud1 },
{ "ho", TICODE_home },
{ "vi", TICODE_civis },
{ "le", TICODE_cub1 },
{ "CM", TICODE_mrcup },
{ "ve", TICODE_cnorm },
{ "nd", TICODE_cuf1 },
{ "ll", TICODE_ll },
{ "up", TICODE_cuu1 },
{ "vs", TICODE_cvvis },
{ "Yx", TICODE_defbi },
{ "ZE", TICODE_defc },
{ "dc", TICODE_dch1 },
{ "dl", TICODE_dl1 },
{ "dv", TICODE_devt },
{ "DI", TICODE_dial },
{ "ds", TICODE_dsl },
{ "DK", TICODE_dclk },
{ "S1", TICODE_dispc },
{ "hd", TICODE_hd },
{ "eA", TICODE_enacs },
{ "Yy", TICODE_endbi },
{ "as", TICODE_smacs },
{ "SA", TICODE_smam },
{ "mb", TICODE_blink },
{ "md", TICODE_bold },
{ "ti", TICODE_smcup },
{ "dm", TICODE_smdc },
{ "mh", TICODE_dim },
{ "ZF", TICODE_swidm },
{ "ZG", TICODE_sdrfq },
{ "Xh", TICODE_ehhlm },
{ "im", TICODE_smir },
{ "ZH", TICODE_sitm },
{ "Xl", TICODE_elhlm },
{ "ZI", TICODE_slm },
{ "Xo", TICODE_elohlm },
{ "ZJ", TICODE_smicm },
{ "ZK", TICODE_snlq },
{ "ZL", TICODE_snrmq },
{ "S2", TICODE_smpch },
{ "mp", TICODE_prot },
{ "mr", TICODE_rev },
{ "Xr", TICODE_erhlm },
{ "S4", TICODE_smsc },
{ "mk", TICODE_invis },
{ "ZM", TICODE_sshm },
{ "so", TICODE_smso },
{ "ZN", TICODE_ssubm },
{ "ZO", TICODE_ssupm },
{ "Xt", TICODE_ethlm },
{ "us", TICODE_smul },
{ "ZP", TICODE_sum },
{ "Xv", TICODE_evhlm },
{ "SX", TICODE_smxon },
{ "ec", TICODE_ech },
{ "ae", TICODE_rmacs },
{ "RA", TICODE_rmam },
{ "me", TICODE_sgr0 },
{ "te", TICODE_rmcup },
{ "ed", TICODE_rmdc },
{ "ZQ", TICODE_rwidm },
{ "ei", TICODE_rmir },
{ "ZR", TICODE_ritm },
{ "ZS", TICODE_rlm },
{ "ZT", TICODE_rmicm },
{ "S3", TICODE_rmpch },
{ "S5", TICODE_rmsc },
{ "ZU", TICODE_rshm },
{ "se", TICODE_rmso },
{ "ZV", TICODE_rsubm },
{ "ZW", TICODE_rsupm },
{ "ue", TICODE_rmul },
{ "ZX", TICODE_rum },
{ "RX", TICODE_rmxon },
{ "PA", TICODE_pause },
{ "fh", TICODE_hook },
{ "vb", TICODE_flash },
{ "ff", TICODE_ff },
{ "fs", TICODE_fsl },
{ "Gm", TICODE_getm },
{ "WG", TICODE_wingo },
{ "HU", TICODE_hup },
{ "i1", TICODE_is1 },
{ "i2", TICODE_is2 },
{ "i3", TICODE_is3 },
{ "is", TICODE_is2 },
{ "if", TICODE_if },
{ "iP", TICODE_iprog },
{ "Ic", TICODE_initc },
{ "Ip", TICODE_initp },
{ "ic", TICODE_ich1 },
{ "al", TICODE_il1 },
{ "ip", TICODE_ip },
{ "K1", TICODE_ka1 },
{ "K3", TICODE_ka3 },
{ "K2", TICODE_kb2 },
{ "kb", TICODE_kbs },
{ "kB", TICODE_kcbt },
{ "K4", TICODE_kc1 },
{ "K5", TICODE_kc3 },
{ "ka", TICODE_ktbc },
{ "kC", TICODE_kclr },
{ "kt", TICODE_kctab },
{ "kD", TICODE_kdch1 },
{ "kL", TICODE_kdl1 },
{ "kd", TICODE_kcud1 },
{ "kM", TICODE_krmir },
{ "kE", TICODE_kel },
{ "kS", TICODE_ked },
{ "k0", TICODE_kf0 },
{ "k1", TICODE_kf1 },
{ "k2", TICODE_kf2 },
{ "k3", TICODE_kf3 },
{ "k4", TICODE_kf4 },
{ "k5", TICODE_kf5 },
{ "k6", TICODE_kf6 },
{ "k7", TICODE_kf7 },
{ "k8", TICODE_kf8 },
{ "k9", TICODE_kf9 },
{ "k;", TICODE_kf10 },
{ "F1", TICODE_kf11 },
{ "F2", TICODE_kf12 },
{ "F3", TICODE_kf13 },
{ "F4", TICODE_kf14 },
{ "F5", TICODE_kf15 },
{ "F6", TICODE_kf16 },
{ "F7", TICODE_kf17 },
{ "F8", TICODE_kf18 },
{ "F9", TICODE_kf19 },
{ "FA", TICODE_kf20 },
{ "FB", TICODE_kf21 },
{ "FC", TICODE_kf22 },
{ "FD", TICODE_kf23 },
{ "FE", TICODE_kf24 },
{ "FF", TICODE_kf25 },
{ "FG", TICODE_kf26 },
{ "FH", TICODE_kf27 },
{ "FI", TICODE_kf28 },
{ "FJ", TICODE_kf29 },
{ "FK", TICODE_kf30 },
{ "FL", TICODE_kf31 },
{ "FM", TICODE_kf32 },
{ "FN", TICODE_kf33 },
{ "FO", TICODE_kf34 },
{ "FP", TICODE_kf35 },
{ "FQ", TICODE_kf36 },
{ "FR", TICODE_kf37 },
{ "FS", TICODE_kf38 },
{ "FT", TICODE_kf39 },
{ "FU", TICODE_kf40 },
{ "FV", TICODE_kf41 },
{ "FW", TICODE_kf42 },
{ "FX", TICODE_kf43 },
{ "FY", TICODE_kf44 },
{ "FZ", TICODE_kf45 },
{ "Fa", TICODE_kf46 },
{ "Fb", TICODE_kf47 },
{ "Fc", TICODE_kf48 },
{ "Fd", TICODE_kf49 },
{ "Fe", TICODE_kf50 },
{ "Ff", TICODE_kf51 },
{ "Fg", TICODE_kf52 },
{ "Fh", TICODE_kf53 },
{ "Fi", TICODE_kf54 },
{ "Fj", TICODE_kf55 },
{ "Fk", TICODE_kf56 },
{ "Fl", TICODE_kf57 },
{ "Fm", TICODE_kf58 },
{ "Fn", TICODE_kf59 },
{ "Fo", TICODE_kf60 },
{ "Fp", TICODE_kf61 },
{ "Fq", TICODE_kf62 },
{ "Fr", TICODE_kf63 },
{ "%1", TICODE_khlp },
{ "kh", TICODE_khome },
{ "kI", TICODE_kich1 },
{ "kA", TICODE_kil1 },
{ "kl", TICODE_kcub1 },
{ "kH", TICODE_kll },
{ "%2", TICODE_kmrk },
{ "%3", TICODE_kmsg },
{ "Km", TICODE_kmous },
{ "%4", TICODE_kmov },
{ "%5", TICODE_knxt },
{ "kN", TICODE_knp },
{ "%6", TICODE_kopn },
{ "%7", TICODE_kopt },
{ "kP", TICODE_kpp },
{ "%8", TICODE_kprv },
{ "%9", TICODE_kprt },
{ "%0", TICODE_krdo },
{ "&1", TICODE_kref },
{ "&2", TICODE_krfr },
{ "&3", TICODE_krpl },
{ "&4", TICODE_krst },
{ "&5", TICODE_kres },
{ "kr", TICODE_kcuf1 },
{ "&6", TICODE_ksav },
{ "&9", TICODE_kBEG },
{ "&0", TICODE_kCAN },
{ "*1", TICODE_kCMD },
{ "*2", TICODE_kCPY },
{ "*3", TICODE_kCRT },
{ "*4", TICODE_kDC },
{ "*5", TICODE_kDL },
{ "*6", TICODE_kslt },
{ "*7", TICODE_kEND },
{ "*8", TICODE_kEOL },
{ "*9", TICODE_kEXT },
{ "kF", TICODE_kind },
{ "*0", TICODE_kFND },
{ "#1", TICODE_kHLP },
{ "#2", TICODE_kHOM },
{ "#3", TICODE_kIC },
{ "#4", TICODE_kLFT },
{ "%a", TICODE_kMSG },
{ "%b", TICODE_kMOV },
{ "%c", TICODE_kNXT },
{ "%d", TICODE_kOPT },
{ "%e", TICODE_kPRV },
{ "%f", TICODE_kPRT },
{ "kR", TICODE_kri },
{ "%g", TICODE_kRDO },
{ "%h", TICODE_kRPL },
{ "%i", TICODE_kRIT },
{ "%j", TICODE_kRES },
{ "!1", TICODE_kSAV },
{ "!2", TICODE_kSPD },
{ "kT", TICODE_khts },
{ "!3", TICODE_kUND },
{ "&7", TICODE_kspd },
{ "&8", TICODE_kund },
{ "ku", TICODE_kcuu1 },
{ "ke", TICODE_rmkx },
{ "ks", TICODE_smkx },
{ "l0", TICODE_lf0 },
{ "l1", TICODE_lf1 },
{ "l2", TICODE_lf2 },
{ "l3", TICODE_lf3 },
{ "l4", TICODE_lf4 },
{ "l5", TICODE_lf5 },
{ "l6", TICODE_lf6 },
{ "l7", TICODE_lf7 },
{ "l8", TICODE_lf8 },
{ "l9", TICODE_lf9 },
{ "la", TICODE_lf10 },
{ "Lf", TICODE_fln },
{ "LF", TICODE_rmln },
{ "LO", TICODE_smln },
{ "mo", TICODE_rmm },
{ "mm", TICODE_smm },
{ "ZY", TICODE_mhpa },
{ "ZZ", TICODE_mcud1 },
{ "Za", TICODE_mcub1 },
{ "Zb", TICODE_mcuf1 },
{ "Zc", TICODE_mvpa },
{ "Zd", TICODE_mcuu1 },
{ "Mi", TICODE_minfo },
{ "nw", TICODE_nel },
{ "Ze", TICODE_porder },
{ "oc", TICODE_oc },
{ "op", TICODE_op },
{ "pc", TICODE_pad },
{ "DC", TICODE_dch },
{ "DL", TICODE_dl },
{ "DO", TICODE_cud },
{ "Zf", TICODE_mcud },
{ "IC", TICODE_ich },
{ "SF", TICODE_indn },
{ "AL", TICODE_il },
{ "LE", TICODE_cub },
{ "Zg", TICODE_mcub },
{ "RI", TICODE_cuf },
{ "Zh", TICODE_mcuf },
{ "SR", TICODE_rin },
{ "UP", TICODE_cuu },
{ "Zi", TICODE_mcuu },
{ "S6", TICODE_pctrm },
{ "pk", TICODE_pfkey },
{ "pl", TICODE_pfloc },
{ "xl", TICODE_pfxl },
{ "px", TICODE_pfx },
{ "pn", TICODE_pln },
{ "ps", TICODE_mc0 },
{ "pO", TICODE_mc5p },
{ "pf", TICODE_mc4 },
{ "po", TICODE_mc5 },
{ "PU", TICODE_pulse },
{ "QD", TICODE_qdial },
{ "RC", TICODE_rmclk },
{ "rp", TICODE_rep },
{ "RF", TICODE_rfi },
{ "RQ", TICODE_reqmp },
{ "r1", TICODE_rs1 },
{ "r2", TICODE_rs2 },
{ "r3", TICODE_rs3 },
{ "rf", TICODE_rf },
{ "rc", TICODE_rc },
{ "cv", TICODE_vpa },
{ "sc", TICODE_sc },
{ "S7", TICODE_scesc },
{ "sf", TICODE_ind },
{ "sr", TICODE_ri },
{ "Zj", TICODE_scs },
{ "s0", TICODE_s0ds },
{ "s1", TICODE_s1ds },
{ "s2", TICODE_s2ds },
{ "s3", TICODE_s3ds },
{ "sA", TICODE_sgr1 },
{ "AB", TICODE_setab },
{ "AF", TICODE_setaf },
{ "sa", TICODE_sgr },
{ "Sb", TICODE_setb },
{ "Zk", TICODE_smgb },
{ "Zl", TICODE_smgbp },
{ "SC", TICODE_sclk },
{ "Yz", TICODE_slines },
{ "sL", TICODE_slength },
{ "sp", TICODE_scp },
{ "Sf", TICODE_setf },
{ "ML", TICODE_smgl }, /* We should fallback to TICODE_smglr */
{ "Zm", TICODE_smglp },
{ "YZ", TICODE_slines },
{ "YI", TICODE_slength },
{ "MR", TICODE_smgr },
{ "Zn", TICODE_smgrp },
{ "st", TICODE_hts },
{ "MT", TICODE_smgtb },
{ "Zo", TICODE_smgt },
{ "Zp", TICODE_smgtp },
{ "wi", TICODE_wind },
{ "Zq", TICODE_sbim },
{ "Zr", TICODE_scsd },
{ "Zs", TICODE_rbim },
{ "Zt", TICODE_rcsd },
{ "Zu", TICODE_subcs },
{ "Zv", TICODE_supcs },
{ "ta", TICODE_ht },
{ "Zw", TICODE_docr },
{ "ts", TICODE_tsl },
{ "TO", TICODE_tone },
{ "u0", TICODE_u0 },
{ "u1", TICODE_u1 },
{ "u2", TICODE_u2 },
{ "u3", TICODE_u3 },
{ "u4", TICODE_u4 },
{ "u5", TICODE_u5 },
{ "u6", TICODE_u6 },
{ "u7", TICODE_u7 },
{ "u8", TICODE_u8 },
{ "u9", TICODE_u9 },
{ "uc", TICODE_uc },
{ "hu", TICODE_hu },
{ "WA", TICODE_wait },
{ "XF", TICODE_xoffc },
{ "XN", TICODE_xonc },
{ "Zx", TICODE_zerom },
/* NetBSD extensions */
{ "@0", TICODE_kfnd },
{ "@1", TICODE_kbeg },
{ "@2", TICODE_kcan },
{ "@3", TICODE_kclo },
{ "@4", TICODE_kcmd },
{ "@5", TICODE_kcpy },
{ "@6", TICODE_kcrt },
{ "@7", TICODE_kend },
{ "@8", TICODE_kent },
{ "@9", TICODE_kext },
};

228
lib/libterminfo/terminfo.3 Normal file
View file

@ -0,0 +1,228 @@
.\" $NetBSD: terminfo.3,v 1.4 2010/02/04 09:12:56 wiz Exp $
.\"
.\" Copyright (c) 2009 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Roy Marples.
.\"
.\" 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
.\"
.Dd December 7, 2009
.Dt TERMINFO 3
.Os
.Sh NAME
.Nm setupterm ,
.Nm set_curterm ,
.Nm del_curterm ,
.Nm tigetflag ,
.Nm tigetnum ,
.Nm tigetstr ,
.Nm tparm ,
.Nm tputs ,
.Nm putp
.Nd terminal independent operation routines
.Sh LIBRARY
.Lb libterminfo
.Sh SYNOPSIS
.In term.h
.Vt char PC ;
.Vt short ospeed ;
.Vt TERMINAL *cur_term ;
.Ft int
.Fn setupterm "const char *name" "int fildes" "int *errret"
.Ft TERMINAL *
.Fn set_curterm "TERMINAL *term"
.Ft int
.Fn del_curterm "TERMINAL *term"
.Ft int
.Fn tigetnum "const char *id"
.Ft int
.Fn tigetflag "const char *id"
.Ft char *
.Fn tigetstr "const char *id"
.Ft char *
.Fn tparm "const char *cm" "long p1" "long p2" "long p3" "long p4" "long p5" "long p6" "long p7" "long p8" "long p9"
.Ft int
.Fn tputs "const char *cp" "int affcnt" "int (*outc)(int)"
.Ft int
.Fn putp "const char *cp"
.Ft int
.Fn ti_setupterm "TERMINAL **" "const char *name" "int fildes" "int *error"
.Ft int
.Fn ti_getflag "const TERMINAL *" "const char *id"
.Ft int
.Fn ti_getnum "const TERMINAL *" "const char *id"
.Ft const char *
.Fn ti_getstr "const TERMINAL *" "const char *id"
.Ft char *
.Fn t_parm "const TERMINAL *" "const char *cm" "long p1" "long p2" "long p3" "long p4" "long p5" "long p6" "long p7" "long p8" "long p9"
.Ft char *
.Fn t_parm "const char *cm" "..."
.Ft char *
.Fn t_vparm "TERMINAL *" "const char *cm" "..."
.Ft int
.Fn ti_puts "const TERMINAL *term" "const char *str" "int affcnt" "int (*outc)(int, void *)"
.Ft int
.Fn ti_putp "const TERMINAL *term" "const char *str"
.Sh DESCRIPTION
These functions extract and use capabilities from a terminal capability
database, usually
.Pa /usr/share/misc/terminfo ,
the format of which is described in
.Xr terminfo 5 .
These are low level routines;
see
.Xr curses 3
for a higher level package.
.Pp
The
.Fn setupterm
function extracts the entry for terminal
.Fa name
and then calls
.Fn set_curterm
to set
.Va cur_term
to it.
If
.Fa name
is
.Dv NULL
then it is replaced by the environment variable
.Ev TERM .
The
.Fn setupterm
function returns 0 on success and \-1 on error.
.Va errret
is set to \-1 if the
.Nm terminfo
database could not be opened,
0 if the terminal could not be found in the database, and
1 if all went well.
.Pp
The
.Fn set_curterm
function sets the variable
.Va cur_term
to
.Va nterm
and makes all of the
.Nm terminfo
boolean, numeric and string variables use the values from
.Va nterm .
The global variables
.Va PC
and
.Va ospeed
are then set.
The old value of
.Va cur_term
is returned.
The
.Fn del_curterm
function frees space pointed to by
.Va oterm .
.Pp
The
.Fn tigetflag
function gets the boolean value of capability
.Va id ,
returning \-1 if it is not a valid capability.
The
.Fn tigetnum
function gets the numeric value of the capability
.Va id ,
returning \-2 if it is not a valid capability.
The
.Fn tigetstr
function returns the string value of the capability
.Va id ,
returning (char *)-1 if it is not a valid capability.
.Pp
The
.Fn tparm
function returns a string decoded from
.Va cm
with the parameters
.Va p1
\&...
.Va p9
applied.
Some capabilities require string parameters and only platforms that can fit
a
.Vt char *
pointer inside a
.Vt long
can use them.
The string encoding and parameter application is described in
.Xr terminfo 5 .
.Pp
The
.Fn tputs
function applies padding information to the string
.Va cp ;
.Va affcnt
gives the number of lines affected by the operation,
or 1 if this is not applicable;
.Va outc
is a function which is called by each character in turn.
The external variable
.Va ospeed
controls how many padding characters are sent in relation to the terminal
speed.
The
.Fn putp
function calls tputs(str, 1, putchar).
The output from
.Fn putp
always goes to stdout.
.Ss NetBSD Extensions To Terminfo
The
.Fn vtparm
function allows variadic parameters instead of 9 fixed longs.
Numeric parameters must be longs.
String parameters can be used even if the platform cannot fit a
.Vt char *
into a
.Vt long .
.Pp
The
.Fn ti_*
functions correspond to the standard
.Fn t*
functions but take an additional
.Ft TERMINAL *
parameter so that the terminal can be specified instead of assuming
.Va cur_term .
These functions use private variables to the
.Ft TERMINAL
instead of the global variables, such as
.Va PC
and
.Va ospeed .
.Sh SEE ALSO
.Xr ex 1 ,
.Xr curses 3 ,
.Xr terminfo 5
.Sh AUTHORS
.An Roy Marples Aq roy@NetBSD.org

View file

@ -0,0 +1,267 @@
.\" $NetBSD: terminfo.5.in,v 1.14 2010/02/26 07:03:49 wiz Exp $
.\"
.\" Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Roy Marples.
.\"
.\" 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
.\"
.Dd February 26, 2010
.Dt TERMINFO 5
.Os
.Sh NAME
.Nm terminfo
.Nd terminal capability definition
.Sh DESCRIPTION
.Nm
describes the capabilities of terminals, used by programs such as
.Xr vi 1 ,
.Xr rogue 6
and libraries such as
.Xr curses 3 .
The
.Nm
source described here needs to be compiled with
.Xr tic 1
to be of any use.
.Pp
Entries in
.Nm
consist of a number of comma separated fields.
White space after each comma is ignored.
Embedded commas must be escaped by using a backslash.
Lines beginning with
.Sq #
in the first column are treated as comments.
Blank lines are ignored.
.Pp
The header line must begin in column one and end with a comma.
Inside the header line are terminal name and aliases,
separated by vertical bars, the last one being the long
description of the terminal.
.Pp
Capability lines then follow, starting on column two and ending with a comma.
Each capability is listed by its name, followed by its value if applicable.
Booleans have no values, numeric values are prefixed by
.Sq #
and strings are prefixed by
.Sq = .
Numbers can range from 0 to 32767 and string values can be up to 1000
characters long.
This implementation supports strings upto 32767 characters long, including the
.Dv NUL
terminator.
.Pp
Some escapes are available for strings - both
.Sy \eE
and
.Sy \ee
map to the
.Dv ESC
character,
.Sy ^X
maps to a control-X for any appropriate X, and the sequences
.Sy \en ,
.Sy \er ,
.Sy \et ,
.Sy \eb
and
.Sy \ef
map to linefeed, return, tab, backspace, and formfeed respectively.
Any character can be escaped in octal, such as
.Sy \e072 .
If you need to encode a
.Dv NUL
character, it should be escaped as
.Sy \e200 .
.Pp
A delay in milliseconds may appear anywhere in a string capability,
prefixed with a dollar sign and enclosed by angled brackets, such as
.Sy $\*[Lt]5\*[Gt] .
.Ss String Parameters
String capabilities sometimes require parameters.
Normally this just involves replacing the parameter with a supplied
variable; however, there are cases where the variable needs to be manipulated
or used in conditional expressions.
A stack is also provided for simple pop and push operations.
.Pp
The below % encodings have the following meanings:
.Bl -tag -width %P[a-z]
.It Sy %%
outputs %
.It Sy %[[:]flags][width[.precision]][doxXs]
flags are
.Dq [-+#] .
Prefix with
.Sq \&:
to avoid interpreting
.Dq %-
as an operator.
.It Sy %c
pop a parameter and print the character representation of it.
.It Sy %s
pop a parameter and print the string representation of it.
.It Sy %p[1-9]
push the parameter [1-9].
.It Sy %P[a-z]
pop a parameter and push it to dynamic variable [a-z].
.It Sy %g[a-z]
push the dynamic variable [a-z].
.It Sy %P[A-Z]
pop a parameter and push it to static variable [a-z].
.It Sy %g[A-Z]
push the dynamic variable [A-Z].
.Pp
Static variables persist over
.Fn tparm
whereas dynamic variables do not.
.It Sy %'c'
char constant c.
.It Sy %{nn}
integer constant nn.
.It Sy %l
push the string length of the previously popped parameter.
.It Sy %+ Sy %- Sy %* Sy %/ Sy %m
arithmetic: pop two parameters and push the result.
.It Sy %& Sy %| Sy %^
bit operations: pop two parameters and push the result.
.It Sy %! Sy %~
unary operations: pop two parameters and push the result.
.It Sy %i
add 1 to parameters 1 and 2.
.It Sy %? Va expr Sy %t Ic then Sy %e Ic else Sy %;
If expr equates to zero then control passes to the optional else part.
.El
.Ss Boolean Capabilities
.Bl -column "enter_near_quality_letter" "setcolor" "TC"
.It Sy "Long name" Ta Sy "Code" Ta Sy "TC"
@BOOLCAPS@
.El
.Ss Numeric Capabilities
.Bl -column "enter_near_quality_letter" "setcolor" "TC"
.It Sy "Long name" Ta Sy "Code" Ta Sy "TC"
@NUMCAPS@
.El
.Ss String Capabilities
.Bl -column "enter_near_quality_letter" "setcolor" "TC"
.It Sy "Long name" Ta Sy "Code" Ta Sy "TC"
@STRCAPS@
.El
.Ss A Sample Entry
.Bd -literal
vt100\||dec vt100 (w/advanced video),
am, xenl, msgr, mc5i, xon,
cols#80, it#8, lines#24, vt#3,
acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, bel=^G,
cr=^M, csr=\eE[%i%p1%d;%p2%dr, tbc=\eE[3g, clear=\eE[H\eE[J$\*[Lt]50\*[Gt],
el1=\eE[1K$\*[Lt]3\*[Gt], el=\eE[K$\*[Lt]3\*[Gt], ed=\eE[J$\*[Lt]50\*[Gt],
cup=\eE[%i%p1%d;%p2%dH$\*[Lt]5\*[Gt], cud1=^J, home=\eE[H, cub1=^H,
cuf1=\eE[C$\*[Lt]2\*[Gt], cuu1=\eE[A$\*[Lt]2\*[Gt], enacs=\eE(B\eE)0, smacs=^N,
smam=\eE[?7h, blink=\eE[5m$\*[Lt]2\*[Gt], bold=\eE[1m$\*[Lt]2\*[Gt], rev=\eE[7m$\*[Lt]2\*[Gt],
smso=\eE[7m$\*[Lt]2\*[Gt], smul=\eE[4m$\*[Lt]2\*[Gt], rmacs=^O, rmam=\eE[?7l,
sgr0=\eE[m017$\*[Lt]2\*[Gt], rmso=\eE[m$\*[Lt]2\*[Gt], rmul=\eE[m$\*[Lt]2\*[Gt], ka1=\eEOq,
ka3=\eEOs, kb2=\eEOr, kbs=^H, kc1=\eEOp, kc3=\eEOn, kcud1=\eEOB,
kent=\eEOM, kf0=\eEOy, kf1=\eEOP, kf2=\eEOQ, kf3=\eEOR, kf4=\eEOS,
kf5=\eEOt, kf6=\eEOu, kf7=\eEOv, kf8=\eEOl, kf9=\eEOw, kf10=\eEOx,
kcub1=\eEOD, kcuf1=\eEOC, kcuu1=\eEOA, rmkx=\eE[?1l\eE\*[Gt],
smkx=\eE[?1h\eE=, lf1=pf1, lf2=pf2, lf3=pf3, lf4=pf4,
cud=\eE[%p1%dB, cub=\eE[%p1%dD, cuf=\eE[%p1%dC, cuu=\eE[%p1%dA,
mc0=\eE[0i, mc4=\eE[4i, mc5=\eE[5i,
rs2=\eE\*[Gt]\eE[?3l\eE[?4l\eE[?5l\eE[?7h\eE[?8h, rc=\eE8, sc=\eE7,
ind=^J, ri=\eEM$\*[Lt]5\*[Gt],
sgr=\eE[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m%?%p9%t016%e017%;$\*[Lt]2\*[Gt],
hts=\eEH, ht=^I,
.Ed
.Ss Fetching Compiled Descriptions
This implementation uses hashed databases managed by
.Xr ndbm 3
instead of directories.
To maintain compatability with other implementations,
.Pa .db
is appended to each file checked.
.Pp
If the environment variable
.Ev TERMINFO
is available, does not begin with
.Pq Sq / ,
can be compiled with the above rules and whose name matches
.Ev TERM
then it is used.
.Pp
If the environment variable
.Ev TERMCAP
is available and does not begin with a slash
.Pq Sq /
then it will be translated into
terminfo and compiled as above.
If its name matches
.Ev TERM
then it is used.
.Pp
If the environment variable
.Ev TERMINFO
is available and begins with a slash
.Pq Sq /
then only this file is searched.
Otherwise
.Nm
will first look for
.Pa $HOME/.terminfo ,
followed by
.Pa /usr/share/misc/terminfo
unless
.Ev TERMINFO_DIRS
is available.
If a matching description is not found then a small embedded database is
searched, which currently holds descriptions for ansi, dumb, vt100, vt220,
wsvt25, and xterm.
.Sh FILES
.Bl -tag -width /usr/share/misc/terminfo.db -compact
.It Pa $HOME/.terminfo.db
Database of terminal descriptions for personal use.
.It Pa /usr/share/misc/terminfo
File containing terminal descriptions.
.It Pa /usr/share/misc/terminfo.db
Database of terminal descriptions.
.El
.Sh SEE ALSO
.Xr infocmp 1 ,
.Xr tic 1 ,
.Xr tput 1 ,
.Xr curses 3 ,
.Xr ndbm 3
.Sh STANDARDS
.Nm
complies with the
.St -xcurses4.2
standard.
.Pp
Extensions to the standard are noted in
.Xr tic 1 .
.Sh AUTHORS
.An Roy Marples Aq roy@NetBSD.org
.Sh BUGS
The
.Ev TERMCAP
capabilities %\*[Gt], %B and %D are not converted into terminfo capabilities.

135
lib/libterminfo/ti.c Normal file
View file

@ -0,0 +1,135 @@
/* $NetBSD: ti.c,v 1.2 2010/02/04 09:46:26 roy Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
*
* This id is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
*
* 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 id 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 <sys/cdefs.h>
__RCSID("$NetBSD: ti.c,v 1.2 2010/02/04 09:46:26 roy Exp $");
#include <assert.h>
#include <string.h>
#include <term_private.h>
#include <term.h>
int
ti_getflag(const TERMINAL *term, const char *id)
{
ssize_t ind;
size_t i;
TERMUSERDEF *ud;
_DIAGASSERT(term != NULL);
_DIAGASSERT(id != NULL);
ind = _ti_flagindex(id);
if (ind != -1)
return term->flags[ind];
for (i = 0; i < term->_nuserdefs; i++) {
ud = &term->_userdefs[i];
if (ud->type == 'f' && strcmp(ud->id, id) == 0)
return ud->flag;
}
return ABSENT_BOOLEAN;
}
int
tigetflag(const char *id)
{
_DIAGASSERT(id != NULL);
if (cur_term != NULL)
return ti_getflag(cur_term, id);
return ABSENT_BOOLEAN;
}
int
ti_getnum(const TERMINAL *term, const char *id)
{
ssize_t ind;
size_t i;
TERMUSERDEF *ud;
_DIAGASSERT(term != NULL);
_DIAGASSERT(id != NULL);
ind = _ti_numindex(id);
if (ind != -1) {
if (!VALID_NUMERIC(term->nums[ind]))
return ABSENT_NUMERIC;
return term->nums[ind];
}
for (i = 0; i < term->_nuserdefs; i++) {
ud = &term->_userdefs[i];
if (ud->type == 'n' && strcmp(ud->id, id) == 0) {
if (!VALID_NUMERIC(ud->num))
return ABSENT_NUMERIC;
return ud->num;
}
}
return CANCELLED_NUMERIC;
}
int
tigetnum(const char *id)
{
_DIAGASSERT(id != NULL);
if (cur_term != NULL)
return ti_getnum(cur_term, id);
return CANCELLED_NUMERIC;
}
const char *
ti_getstr(const TERMINAL *term, const char *id)
{
ssize_t ind;
size_t i;
TERMUSERDEF *ud;
_DIAGASSERT(term != NULL);
_DIAGASSERT(id != NULL);
ind = _ti_strindex(id);
if (ind != -1)
return term->strs[ind];
for (i = 0; i < term->_nuserdefs; i++) {
ud = &term->_userdefs[i];
if (ud->type == 's' && strcmp(ud->id, id) == 0)
return ud->str;
}
return (const char *)CANCELLED_STRING;
}
char *
tigetstr(const char *id)
{
_DIAGASSERT(id != NULL);
if (cur_term != NULL)
return __UNCONST(ti_getstr(cur_term, id));
return (char *)CANCELLED_STRING;
}

553
lib/libterminfo/tparm.c Normal file
View file

@ -0,0 +1,553 @@
/* $NetBSD: tparm.c,v 1.2 2010/09/22 06:10:51 roy Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
*
* 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 <sys/cdefs.h>
__RCSID("$NetBSD: tparm.c,v 1.2 2010/09/22 06:10:51 roy Exp $");
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <term_private.h>
#include <term.h>
static TERMINAL *dumbterm; /* For non thread safe functions */
typedef struct {
long nums[20];
char *strings[20];
size_t offset;
} TPSTACK;
typedef struct {
long num;
char *string;
} TPVAR;
static int
push(long num, char *string, TPSTACK *stack)
{
if (stack->offset > sizeof(stack->nums)) {
errno = E2BIG;
return -1;
}
stack->nums[stack->offset] = num;
stack->strings[stack->offset] = string;
stack->offset++;
return 0;
}
static int
pop(long *num, char **string, TPSTACK *stack)
{
if (stack->offset == 0) {
errno = E2BIG;
return -1;
}
stack->offset--;
if (num)
*num = stack->nums[stack->offset];
if (string)
*string = stack->strings[stack->offset];
return 0;
}
static char *
checkbuf(TERMINAL *term, size_t len)
{
char *buf;
if (term->_bufpos + len >= term->_buflen) {
len = term->_buflen + BUFSIZ;
buf = realloc(term->_buf, len);
if (buf == NULL)
return 0;
term->_buf = buf;
term->_buflen = len;
}
return term->_buf;
}
static size_t
ochar(TERMINAL *term, int c)
{
if (c == 0)
c = 0200;
/* Check we have space and a terminator */
if (checkbuf(term, 2) == NULL)
return 0;
term->_buf[term->_bufpos++] = (char)c;
return 1;
}
static size_t
onum(TERMINAL *term, const char *fmt, long num, int len)
{
size_t l;
/* Assume we never have natural number longer than 64 chars */
if (len < 64)
len = 64;
if (checkbuf(term, (size_t)len + 1) == NULL)
return 0;
l = sprintf(term->_buf + term->_bufpos, fmt, num);
term->_bufpos += l;
return l;
}
static char *
_ti_vtparm(TERMINAL *term, const char *str, va_list parms)
{
const char *sp;
char c, fmt[64], *fp, *ostr;
long val, val2;
long dnums[26]; /* dynamic variables a-z, not preserved */
size_t l, max;
TPSTACK stack;
TPVAR params[9];
int done, dot, minus, width, precision, olen;
int piss[9]; /* Parameter IS String - piss ;) */
if (str == NULL)
return NULL;
/*
If not passed a terminal, malloc a dummy one.
This means we can preserve buffers and variables per terminal and
still work with non thread safe functions (which sadly are still the
norm and standard).
*/
if (term == NULL) {
if (dumbterm == NULL) {
dumbterm = malloc(sizeof(*dumbterm));
if (dumbterm == NULL)
return NULL;
dumbterm->_buflen = 0;
}
term = dumbterm;
}
term->_bufpos = 0;
/* Ensure we have an initial buffer */
if (term->_buflen == 0) {
term->_buf = malloc(BUFSIZ);
if (term->_buf == NULL)
return NULL;
term->_buflen = BUFSIZ;
}
/*
Make a first pass through the string so we can work out
which parameters are longs and which are char *.
Basically we only use char * if %p[1-9] is followed by %l or %s.
*/
memset(&piss, 0, sizeof(piss));
max = 0;
sp = str;
while ((c = *sp++) != '\0') {
if (c != '%')
continue;
c = *sp++;
if (c == '\0')
break;
if (c != 'p')
continue;
c = *sp++;
if (c < '1' || c > '9') {
errno = EINVAL;
return NULL;
}
l = c - '0';
if (l > max)
max = l;
if (*sp != '%')
continue;
/* Skip formatting */
sp++;
while (*sp == '.' || *sp == '#' || *sp == ' ' || *sp == ':' ||
*sp == '-' || isdigit((unsigned char)*sp))
sp++;
if (*sp == 'l' || *sp == 's')
piss[l - 1] = 1;
}
/* Put our parameters into variables */
memset(&params, 0, sizeof(params));
for (l = 0; l < max; l++) {
if (piss[l] == 0)
params[l].num = va_arg(parms, long);
else
params[l].string = va_arg(parms, char *);
}
term->_bufpos = 0;
memset(&stack, 0, sizeof(stack));
while ((c = *str++) != '\0') {
if (c != '%' || (c = *str++) == '%') {
if (c == '\0')
break;
if (ochar(term, c) == 0)
return NULL;
continue;
}
/* Handle formatting. */
fp = fmt;
*fp++ = '%';
done = dot = minus = width = precision = 0;
val = 0;
while (done == 0 && (size_t)(fp - fmt) < sizeof(fmt)) {
switch (c) {
case 'c': /* FALLTHROUGH */
case 'd': /* FALLTHROUGH */
case 'o': /* FALLTHROUGH */
case 'x': /* FALLTHROUGH */
case 'X': /* FALLTHROUGH */
case 's':
*fp++ = c;
done = 1;
break;
case '#': /* FALLTHROUGH */
case ' ':
*fp++ = c;
break;
case '.':
*fp++ = c;
if (dot == 0) {
dot = 1;
width = val;
} else
done = 2;
val = 0;
break;
case ':':
minus = 1;
break;
case '-':
if (minus)
*fp++ = c;
else
done = 1;
break;
default:
if (isdigit((unsigned char)c)) {
val = (val * 10) + (c - '0');
if (val > 10000)
done = 2;
else
*fp++ = c;
} else
done = 1;
}
if (done == 0)
c = *str++;
}
if (done == 2) {
/* Found an error in the format */
fp = fmt + 1;
*fp = *str;
olen = 0;
} else {
if (dot == 0)
width = val;
else
precision = val;
olen = (width > precision) ? width : precision;
}
*fp++ = '\0';
/* Handle commands */
switch (c) {
case 'c':
if (pop(&val, NULL, &stack))
return NULL;
if (ochar(term, (unsigned char)val) == 0)
return NULL;
break;
case 's':
if (pop(NULL, &ostr, &stack))
return NULL;
if (ostr != NULL) {
l = strlen(ostr);
if (l < (size_t)olen)
l = olen;
if (checkbuf(term, (size_t)(l + 1)) == NULL)
return NULL;
l = sprintf(term->_buf + term->_bufpos,
fmt, ostr);
term->_bufpos += l;
}
break;
case 'l':
if (pop(NULL, &ostr, &stack))
return NULL;
if (ostr == NULL)
l = 0;
else
l = strlen(ostr);
if (onum(term, "%d", (long)l, 0) == 0)
return NULL;
break;
case 'd': /* FALLTHROUGH */
case 'o': /* FALLTHROUGH */
case 'x': /* FALLTHROUGH */
case 'X':
if (pop(&val, NULL, &stack))
return NULL;
if (onum(term, fmt, val, olen) == 0)
return NULL;
break;
case 'p':
if (*str < '1' || *str > '9') {
errno = EINVAL;
return NULL;
}
l = *str++ - '1';
if (push(params[l].num, params[l].string, &stack))
return NULL;
break;
case 'P':
if (pop(&val, NULL, &stack))
return NULL;
str++;
if (*str >= 'a' && *str <= 'z')
dnums[*str - 'a'] = val;
else if (*str >= 'A' && *str <= 'Z')
term->_snums[*str - 'A'] = val;
break;
case 'g':
str++;
if (*str >= 'a' && *str <= 'z') {
if (push(dnums[*str - 'a'], NULL, &stack))
return NULL;
} else if (*str >= 'A' && *str <= 'Z') {
if (push(term->_snums[*str - 'A'],
NULL, &stack))
return NULL;
}
break;
case 'i':
if (piss[0] == 0)
params[0].num++;
if (piss[1] == 0)
params[1].num++;
break;
case '\'':
if (push((long)(unsigned char)*str++, NULL, &stack))
return NULL;
while (*str != '\0' && *str != '\'')
str++;
if (*str == '\'')
str++;
break;
case '{':
val = 0;
for (str++; isdigit((unsigned char)*str); str++)
val = (val * 10) + (*str - '0');
if (push(val, NULL, &stack))
return NULL;
while (*str != '\0' && *str != '}')
str++;
if (*str == '}')
str++;
break;
case '+': /* FALLTHROUGH */
case '-': /* FALLTHROUGH */
case '*': /* FALLTHROUGH */
case '/': /* FALLTHROUGH */
case 'm': /* FALLTHROUGH */
case 'A': /* FALLTHROUGH */
case 'O': /* FALLTHROUGH */
case '&': /* FALLTHROUGH */
case '|': /* FALLTHROUGH */
case '^': /* FALLTHROUGH */
case '=': /* FALLTHROUGH */
case '<': /* FALLTHROUGH */
case '>':
if (pop(&val, NULL, &stack) ||
pop(&val2, NULL, &stack))
return NULL;
switch (c) {
case '+':
val = val + val2;
break;
case '-':
val = val2 - val;
break;
case '*':
val = val * val2;
break;
case '/':
val = val ? val2 / val : 0;
break;
case 'm':
val = val ? val2 % val : 0;
break;
case 'A':
val = val && val2;
break;
case 'O':
val = val || val2;
break;
case '&':
val = val & val2;
break;
case '|':
val = val | val2;
break;
case '^':
val = val ^ val2;
break;
case '=':
val = val == val2;
break;
case '<':
val = val2 < val;
break;
case '>':
val = val2 > val;
break;
}
if (push(val, NULL, &stack))
return NULL;
break;
case '!':
case '~':
if (pop(&val, NULL, &stack))
return NULL;
switch (*str) {
case '!':
val = !val;
break;
case '~':
val = ~val;
break;
}
if (push(val, NULL, &stack))
return NULL;
break;
case '?': /* if */
break;
case 't': /* then */
if (pop(&val, NULL, &stack))
return NULL;
if (val != 0) {
l = 0;
for (; *str != '\0'; str++) {
if (*str != '%')
continue;
str++;
if (*str == '?')
l++;
else if (*str == ';') {
if (l > 0)
l--;
else
break;
} else if (*str == 'e' && l == 0)
break;
}
}
break;
case 'e': /* else */
l = 0;
for (; *str != '\0'; str++) {
if (*str != '%')
continue;
str++;
if (*str == '?')
l++;
else if (*str == ';') {
if (l > 0)
l--;
else
break;
}
}
break;
case ';': /* fi */
break;
}
}
term->_buf[term->_bufpos] = '\0';
return term->_buf;
}
char *
t_vparm(TERMINAL *term, const char *str, ...)
{
va_list va;
char *ret;
_DIAGASSERT(term != NULL);
_DIAGASSERT(str != NULL);
va_start(va, str);
ret = _ti_vtparm(term, str, va);
va_end(va);
return ret;
}
char *
vtparm(const char *str, ...)
{
va_list va;
char *ret;
_DIAGASSERT(str != NULL);
va_start(va, str);
ret = _ti_vtparm(NULL, str, va);
va_end(va);
return ret;
}
char *
t_parm(TERMINAL *term, const char *str,
long p1, long p2, long p3, long p4, long p5,
long p6, long p7, long p8, long p9)
{
_DIAGASSERT(term != NULL);
_DIAGASSERT(str != NULL);
return t_vparm(term, str, p1, p2, p3, p4, p5, p6, p7, p8, p9);
}
char *
tparm(const char *str,
long p1, long p2, long p3, long p4, long p5,
long p6, long p7, long p8, long p9)
{
_DIAGASSERT(str != NULL);
return t_vparm(NULL, str, p1, p2, p3, p4, p5, p6, p7, p8, p9);
}

178
lib/libterminfo/tputs.c Normal file
View file

@ -0,0 +1,178 @@
/* $NetBSD: tputs.c,v 1.2 2010/02/12 10:36:07 martin Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
*
* 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 <sys/cdefs.h>
__RCSID("$NetBSD: tputs.c,v 1.2 2010/02/12 10:36:07 martin Exp $");
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <term_private.h>
#include <term.h>
/*
* The following array gives the number of tens of milliseconds per
* character for each speed as returned by gtty. Thus since 300
* baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
*/
static const short tmspc10[] = {
0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5
};
short ospeed;
char PC;
static int
_ti_calcdelay(const char **str, int affcnt, int *mand)
{
int i;
i = 0;
/* Convert the delay */
while (isdigit(*(const unsigned char *)*str))
i = i * 10 + *(*str)++ - '0';
i *= 10;
if (*(*str) == '.') {
(*str)++;
if (isdigit(*(const unsigned char *)*str))
i += *(*str) - '0';
while (isdigit(*(const unsigned char *)*str))
(*str)++;
}
if (*(*str) == '*') {
(*str)++;
i *= affcnt;
} else if (*(*str) == '/') {
(*str)++;
if (mand != NULL)
*mand = 1;
}
return i;
}
static void
_ti_outputdelay(int delay, short os, char pc,
int (*outc)(int, void *), void *args)
{
int mspc10;
if (delay < 1 || os < 1 || (size_t)os >= __arraycount(tmspc10))
return;
mspc10 = tmspc10[os];
delay += mspc10 / 2;
for (delay /= mspc10; delay > 0; delay--)
outc(pc, args);
}
static int
_ti_puts(int dodelay, int os, int pc,
const char *str, int affcnt, int (*outc)(int, void *), void *args)
{
int taildelay, delay, mand;
if (str == NULL)
return OK;
taildelay = _ti_calcdelay(&str, affcnt, NULL);
/* Output the string with embedded delays */
for (; *str != '\0'; str++) {
if (str[0] != '$' ||
str[1] != '<' ||
!(isdigit((const unsigned char)str[2]) || str[2] == '.') ||
strchr(str + 3, '>') == NULL)
{
outc(*str, args);
} else {
str += 2;
mand = 0;
delay = _ti_calcdelay(&str, affcnt, &mand);
if (dodelay != 0 || mand != 0)
_ti_outputdelay(delay, os, pc, outc, args);
}
}
/* Delay if needed */
if (dodelay)
_ti_outputdelay(taildelay, os, pc, outc, args);
return OK;
}
int
ti_puts(const TERMINAL *term, const char *str, int affcnt,
int (*outc)(int, void *), void *args)
{
int dodelay;
char pc;
_DIAGASSERT(term != NULL);
_DIAGASSERT(str != NULL);
_DIAGASSERT(outc != NULL);
dodelay = (str == t_bell(term) ||
str == t_flash_screen(term) ||
(t_xon_xoff(term) == 0 && t_padding_baud_rate(term) != 0));
if (t_pad_char(term) == NULL)
pc = '\0';
else
pc = *t_pad_char(term);
return _ti_puts(dodelay, term->_ospeed, pc,
str, affcnt, outc, args);
}
int
ti_putp(const TERMINAL *term, const char *str)
{
_DIAGASSERT(term != NULL);
_DIAGASSERT(str != NULL);
return ti_puts(term, str, 1, (int (*)(int, void *))putchar, NULL);
}
int
tputs(const char *str, int affcnt, int (*outc)(int))
{
_DIAGASSERT(str != NULL);
_DIAGASSERT(outc != NULL);
return _ti_puts(1, ospeed, PC, str, affcnt,
(int (*)(int, void *))outc, NULL);
}
int
putp(const char *str)
{
_DIAGASSERT(str != NULL);
return tputs(str, 1, putchar);
}

View file

@ -1,5 +1,5 @@
.include <bsd.own.mk>
SUBDIR= mk zoneinfo
SUBDIR= mk terminfo zoneinfo
.include <bsd.subdir.mk>

19
share/terminfo/Makefile Normal file
View file

@ -0,0 +1,19 @@
# $NetBSD: Makefile,v 1.2 2010/02/05 16:34:04 roy Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/8/93
CLEANFILES= terminfo.db
realall: terminfo.db
FILES=terminfo.db terminfo
.if defined(__MINIX)
FILESDIR=/usr/share/terminfo
TOOL_TIC=/usr/bin/tic
.else
FILESDIR=${BINDIR}/misc
.endif
terminfo.db: terminfo
${_MKTARGET_CREATE}
${TOOL_TIC} -ax -o "${.OBJDIR}/terminfo" "${.CURDIR}/terminfo"
.include <bsd.prog.mk>

View file

@ -0,0 +1,20 @@
diff -ru nbsdsrc/src/share/terminfo/Makefile share/terminfo/Makefile
--- nbsdsrc/src/share/terminfo/Makefile
+++ share/terminfo/Makefile
@@ -1,10 +1,16 @@
# $NetBSD: Makefile,v 1.2 2010/02/05 16:34:04 roy Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/8/93
+
CLEANFILES= terminfo.db
realall: terminfo.db
FILES=terminfo.db terminfo
+.if defined(__MINIX)
+FILESDIR=/usr/share/terminfo
+TOOL_TIC=/usr/bin/tic
+.else
FILESDIR=${BINDIR}/misc
+.endif
terminfo.db: terminfo
${_MKTARGET_CREATE}

21717
share/terminfo/terminfo Normal file

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,9 @@ common/lib/libc src/common/lib/libc
lib/nbsd_libc src/lib/libc
lib/nbsd_libm src/lib/libm
lib/libcrypt src/lib/libcrypt
lib/libterminfo src/lib/libterminfo
nbsd_include src/include
usr.bin/m4 src/usr.bin/m4
usr.bin/indent src/usr.bin/indent
usr.bin/stat src/usr.bin/stat
usr.bin/tic src/usr.bin/tic

View file

@ -3,7 +3,7 @@
.include <bsd.own.mk>
# NetBSD imports
SUBDIR= indent m4 mkimage stat
SUBDIR= indent m4 mkimage stat tic
# Non-NetBSD imports
SUBDIR+= ministat

13
usr.bin/tic/Makefile Normal file
View file

@ -0,0 +1,13 @@
# $NetBSD: Makefile,v 1.1 2010/02/03 15:16:32 roy Exp $
PROG= tic
WARNS= 4
CPPFLAGS+= -I${.CURDIR}/../../lib/libterminfo
.ifndef HOSTPROG
LDADD+= -lterminfo
DPADD+= ${LIBTERMINFO}
.endif
.include <bsd.prog.mk>

View file

105
usr.bin/tic/tic.1 Normal file
View file

@ -0,0 +1,105 @@
.\" $NetBSD: tic.1,v 1.8 2010/02/11 13:44:14 wiz Exp $
.\"
.\" Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Roy Marples.
.\"
.\" 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
.\"
.Dd February 11, 2010
.Dt TIC 1
.Os
.Sh NAME
.Nm tic
.Nd terminfo compiler
.Sh SYNOPSIS
.Nm tic
.Op Fl acSsx
.Op Fl o Ar file
.Ar source
.Op Ar term1 term2 ...
.Sh DESCRIPTION
The
.Nm
utility compiles
.Xr terminfo 5
source into a database for use by other programs.
The created database path name is the same as the source but with .db appended.
.Pp
The following options are available:
.Bl -tag -width Fl
.It Fl a
Do not discard commented out capabilities.
.It Fl c
Only check for errors, don't write the final database.
.It Fl o Ar file
Write the database to
.Ar file Ns .db
instead of
.Ar source Ns .db .
.It Fl S
For
.Ar term1 , term2 , ...
output a C structure containing name, compiled description, and compiled size.
This can be used to embed terminal descriptons into a program.
.It Fl s
Display the number of terminal descritions written to the database.
.It Fl x
Include non standard capabilities defined in the
.Ar source .
.El
.Ss Extensions To Terminfo
When
.Nm
discovers a
.Sy use Ns = Ns Va term
capability, the terminal description for
.Va term
is merged in.
Capabilities do not overwrite previously disovered ones and capabilities
ending with @ are marked as absent so the terminal does not inherit the
capability from
.Sy use Ns d
terminals.
.Sh EXIT STATUS
.Ex -std tic
.Sh EXAMPLES
To maintain your private terminfo definitions, if the system supplied
ones do not support your terminal:
.Bd -literal -offset indent
.Ic tic ~/.terminfo
.Ed
.Sh SEE ALSO
.Xr infocmp 1 ,
.Xr tput 1 ,
.Xr curses 3 ,
.Xr terminfo 5
.Sh STANDARDS
The
.Nm
utility works with terminfo files that conform to the
.St -xcurses4.2
standard.
.Sh AUTHORS
.An Roy Marples Aq roy@NetBSD.org

577
usr.bin/tic/tic.c Normal file
View file

@ -0,0 +1,577 @@
/* $NetBSD: tic.c,v 1.10 2010/02/22 23:05:39 roy Exp $ */
/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
*
* 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.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: tic.c,v 1.10 2010/02/22 23:05:39 roy Exp $");
#include <sys/types.h>
#if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
#endif
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <getopt.h>
#include <limits.h>
#include <fcntl.h>
#include <ndbm.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <term_private.h>
#include <term.h>
/* We store the full list of terminals we have instead of iterating
through the database as the sequential iterator doesn't work
the the data size stored changes N amount which ours will. */
typedef struct term {
struct term *next;
char *name;
char type;
TIC *tic;
} TERM;
static TERM *terms;
static int error_exit;
static int Sflag;
static char *dbname;
static void
do_unlink(void)
{
if (dbname != NULL)
unlink(dbname);
}
static void __attribute__((__format__(__printf__, 1, 2)))
dowarn(const char *fmt, ...)
{
va_list va;
error_exit = 1;
va_start(va, fmt);
vwarnx(fmt, va);
va_end(va);
}
static char *
grow_tbuf(TBUF *tbuf, size_t len)
{
char *buf;
buf = _ti_grow_tbuf(tbuf, len);
if (buf == NULL)
err(1, "_ti_grow_tbuf");
return buf;
}
static int
save_term(DBM *db, TERM *term)
{
uint8_t *buf;
ssize_t len;
datum key, value;
len = _ti_flatten(&buf, term->tic);
if (len == -1)
return -1;
key.dptr = term->name;
key.dsize = strlen(term->name);
value.dptr = buf;
value.dsize = len;
if (dbm_store(db, key, value, DBM_REPLACE) == -1)
err(1, "dbm_store");
free(buf);
return 0;
}
static TERM *
find_term(const char *name)
{
TERM *term;
for (term = terms; term != NULL; term = term->next)
if (strcmp(term->name, name) == 0)
return term;
return NULL;
}
static TERM *
store_term(const char *name, char type)
{
TERM *term;
term = calloc(1, sizeof(*term));
if (term == NULL)
errx(1, "malloc");
term->name = strdup(name);
term->type = type;
if (term->name == NULL)
errx(1, "malloc");
term->next = terms;
terms = term;
return term;
}
static int
process_entry(TBUF *buf, int flags)
{
char *p, *e, *alias;
TERM *term;
TIC *tic;
if (buf->bufpos == 0)
return 0;
/* Terminate the string */
buf->buf[buf->bufpos - 1] = '\0';
/* First rewind the buffer for new entries */
buf->bufpos = 0;
if (isspace((unsigned char)*buf->buf))
return 0;
tic = _ti_compile(buf->buf, flags);
if (tic == NULL)
return 0;
if (find_term(tic->name) != NULL) {
dowarn("%s: duplicate entry", tic->name);
_ti_freetic(tic);
return 0;
}
term = store_term(tic->name, 't');
term->tic = tic;
/* Create aliased terms */
if (tic->alias != NULL) {
alias = p = strdup(tic->alias);
while (p != NULL && *p != '\0') {
e = strchr(p, '|');
if (e != NULL)
*e++ = '\0';
if (find_term(p) != NULL) {
dowarn("%s: has alias for already assigned"
" term %s", tic->name, p);
} else {
term = store_term(p, 'a');
term->tic = calloc(sizeof(*term->tic), 1);
if (term->tic == NULL)
err(1, "malloc");
term->tic->name = strdup(tic->name);
if (term->tic->name == NULL)
err(1, "malloc");
}
p = e;
}
}
return 0;
}
static void
merge(TIC *rtic, TIC *utic, int flags)
{
char *cap, flag, *code, type, *str;
short ind, num;
size_t n;
cap = utic->flags.buf;
for (n = utic->flags.entries; n > 0; n--) {
ind = le16dec(cap);
cap += sizeof(uint16_t);
flag = *cap++;
if (VALID_BOOLEAN(flag) &&
_ti_find_cap(&rtic->flags, 'f', ind) == NULL)
{
_ti_grow_tbuf(&rtic->flags, sizeof(uint16_t) + 1);
le16enc(rtic->flags.buf + rtic->flags.bufpos, ind);
rtic->flags.bufpos += sizeof(uint16_t);
rtic->flags.buf[rtic->flags.bufpos++] = flag;
rtic->flags.entries++;
}
}
cap = utic->nums.buf;
for (n = utic->nums.entries; n > 0; n--) {
ind = le16dec(cap);
cap += sizeof(uint16_t);
num = le16dec(cap);
cap += sizeof(uint16_t);
if (VALID_NUMERIC(num) &&
_ti_find_cap(&rtic->nums, 'n', ind) == NULL)
{
grow_tbuf(&rtic->nums, sizeof(uint16_t) * 2);
le16enc(rtic->nums.buf + rtic->nums.bufpos, ind);
rtic->nums.bufpos += sizeof(uint16_t);
le16enc(rtic->nums.buf + rtic->nums.bufpos, num);
rtic->nums.bufpos += sizeof(uint16_t);
rtic->nums.entries++;
}
}
cap = utic->strs.buf;
for (n = utic->strs.entries; n > 0; n--) {
ind = le16dec(cap);
cap += sizeof(uint16_t);
num = le16dec(cap);
cap += sizeof(uint16_t);
if (num > 0 &&
_ti_find_cap(&rtic->strs, 's', ind) == NULL)
{
grow_tbuf(&rtic->strs, (sizeof(uint16_t) * 2) + num);
le16enc(rtic->strs.buf + rtic->strs.bufpos, ind);
rtic->strs.bufpos += sizeof(uint16_t);
le16enc(rtic->strs.buf + rtic->strs.bufpos, num);
rtic->strs.bufpos += sizeof(uint16_t);
memcpy(rtic->strs.buf + rtic->strs.bufpos,
cap, num);
rtic->strs.bufpos += num;
rtic->strs.entries++;
}
cap += num;
}
cap = utic->extras.buf;
for (n = utic->extras.entries; n > 0; n--) {
num = le16dec(cap);
cap += sizeof(uint16_t);
code = cap;
cap += num;
type = *cap++;
flag = 0;
str = NULL;
switch (type) {
case 'f':
flag = *cap++;
if (!VALID_BOOLEAN(flag))
continue;
break;
case 'n':
num = le16dec(cap);
cap += sizeof(uint16_t);
if (!VALID_NUMERIC(num))
continue;
break;
case 's':
num = le16dec(cap);
cap += sizeof(uint16_t);
str = cap;
cap += num;
if (num == 0)
continue;
break;
}
_ti_store_extra(rtic, 0, code, type, flag, num, str, num,
flags);
}
}
static size_t
merge_use(int flags)
{
size_t skipped, merged, memn;
char *cap, *scap;
uint16_t num;
TIC *rtic, *utic;
TERM *term, *uterm;;
skipped = merged = 0;
for (term = terms; term != NULL; term = term->next) {
if (term->type == 'a')
continue;
rtic = term->tic;
while ((cap = _ti_find_extra(&rtic->extras, "use")) != NULL) {
if (*cap++ != 's') {
dowarn("%s: use is not string", rtic->name);
break;
}
cap += sizeof(uint16_t);
if (strcmp(rtic->name, cap) == 0) {
dowarn("%s: uses itself", rtic->name);
goto remove;
}
uterm = find_term(cap);
if (uterm != NULL && uterm->type == 'a')
uterm = find_term(uterm->tic->name);
if (uterm == NULL) {
dowarn("%s: no use record for %s",
rtic->name, cap);
goto remove;
}
utic = uterm->tic;
if (strcmp(utic->name, rtic->name) == 0) {
dowarn("%s: uses itself", rtic->name);
goto remove;
}
if (_ti_find_extra(&utic->extras, "use") != NULL) {
skipped++;
break;
}
cap = _ti_find_extra(&rtic->extras, "use");
merge(rtic, utic, flags);
remove:
/* The pointers may have changed, find the use again */
cap = _ti_find_extra(&rtic->extras, "use");
if (cap == NULL)
dowarn("%s: use no longer exists - impossible",
rtic->name);
else {
scap = cap - (4 + sizeof(uint16_t));
cap++;
num = le16dec(cap);
cap += sizeof(uint16_t) + num;
memn = rtic->extras.bufpos -
(cap - rtic->extras.buf);
memcpy(scap, cap, memn);
rtic->extras.bufpos -= cap - scap;
cap = scap;
rtic->extras.entries--;
merged++;
}
}
}
if (merged == 0 && skipped != 0)
dowarn("circular use detected");
return merged;
}
static int
print_dump(int argc, char **argv)
{
TERM *term;
uint8_t *buf;
int i, n;
size_t j, col;
ssize_t len;
printf("struct compiled_term {\n");
printf("\tconst char *name;\n");
printf("\tconst char *cap;\n");
printf("\tsize_t caplen;\n");
printf("};\n\n");
printf("const struct compiled_term compiled_terms[] = {\n");
n = 0;
for (i = 0; i < argc; i++) {
term = find_term(argv[i]);
if (term == NULL) {
warnx("%s: no description for terminal", argv[i]);
continue;
}
if (term->type == 'a') {
warnx("%s: cannot dump alias", argv[i]);
continue;
}
/* Don't compile the aliases in, save space */
free(term->tic->alias);
term->tic->alias = NULL;
len = _ti_flatten(&buf, term->tic);
if (len == 0 || len == -1)
continue;
printf("\t{\n");
printf("\t\t\"%s\",\n", argv[i]);
n++;
for (j = 0, col = 0; j < (size_t)len; j++) {
if (col == 0) {
printf("\t\t\"");
col = 16;
}
col += printf("\\%03o", (uint8_t)buf[j]);
if (col > 75) {
printf("\"%s\n",
j + 1 == (size_t)len ? "," : "");
col = 0;
}
}
if (col != 0)
printf("\",\n");
printf("\t\t%zu\n", len);
printf("\t}");
if (i + 1 < argc)
printf(",");
printf("\n");
free(buf);
}
printf("};\n");
return n;
}
int
main(int argc, char **argv)
{
int ch, cflag, sflag, flags;
char *source, *p, *buf, *ofile;
FILE *f;
DBM *db;
size_t len, buflen, nterm, nalias;
TBUF tbuf;
TERM *term;
cflag = sflag = 0;
ofile = NULL;
flags = TIC_ALIAS | TIC_DESCRIPTION | TIC_WARNING;
while ((ch = getopt(argc, argv, "Saco:sx")) != -1)
switch (ch) {
case 'S':
Sflag = 1;
/* We still compile aliases so that use= works.
* However, it's removed before we flatten to save space. */
flags &= ~TIC_DESCRIPTION;
break;
case 'a':
flags |= TIC_COMMENT;
break;
case 'c':
cflag = 1;
break;
case 'o':
ofile = optarg;
break;
case 's':
sflag = 1;
break;
case 'x':
flags |= TIC_EXTRA;
break;
case '?': /* FALLTHROUGH */
default:
fprintf(stderr, "usage: %s [-acSsx] [-o file] source\n",
getprogname());
return EXIT_FAILURE;
}
if (optind == argc)
errx(1, "No source file given");
source = argv[optind++];
f = fopen(source, "r");
if (f == NULL)
err(1, "fopen: %s", source);
if (!cflag && !Sflag) {
if (ofile == NULL)
ofile = source;
len = strlen(ofile) + 9;
dbname = malloc(len + 4); /* For adding .db after open */
if (dbname == NULL)
err(1, "malloc");
snprintf(dbname, len, "%s.tmp", ofile);
db = dbm_open(dbname, O_CREAT | O_RDWR | O_TRUNC, DEFFILEMODE);
if (db == NULL)
err(1, "dbopen: %s", source);
p = dbname + strlen(dbname);
*p++ = '.';
*p++ = 'd';
*p++ = 'b';
*p++ = '\0';
atexit(do_unlink);
} else
db = NULL; /* satisfy gcc warning */
tbuf.buflen = tbuf.bufpos = 0;
while ((buf = fgetln(f, &buflen)) != NULL) {
/* Skip comments */
if (*buf == '#')
continue;
if (buf[buflen - 1] != '\n') {
process_entry(&tbuf, flags);
dowarn("last line is not a comment"
" and does not end with a newline");
continue;
}
/*
If the first char is space not a space then we have a
new entry, so process it.
*/
if (!isspace((unsigned char)*buf) && tbuf.bufpos != 0)
process_entry(&tbuf, flags);
/* Grow the buffer if needed */
grow_tbuf(&tbuf, buflen);
/* Append the string */
memcpy(tbuf.buf + tbuf.bufpos, buf, buflen);
tbuf.bufpos += buflen;
}
/* Process the last entry if not done already */
process_entry(&tbuf, flags);
/* Merge use entries until we have merged all we can */
while (merge_use(flags) != 0)
;
if (Sflag) {
print_dump(argc - optind, argv + optind);
return error_exit;
}
if (cflag)
return error_exit;
/* Save the terms */
nterm = nalias = 0;
for (term = terms; term != NULL; term = term->next) {
save_term(db, term);
if (term->type == 'a')
nalias++;
else
nterm++;
}
/* done! */
dbm_close(db);
/* Rename the tmp db to the real one now */
len = strlen(ofile) + 4;
p = malloc(len);
if (p == NULL)
err(1, "malloc");
snprintf(p, len, "%s.db", ofile);
if (rename(dbname, p) == -1)
err(1, "rename");
free(dbname);
dbname = NULL;
if (sflag != 0)
fprintf(stderr, "%zu entries and %zu aliases written to %s\n",
nterm, nalias, p);
return EXIT_SUCCESS;
}