Respect TERMINFO_DIRS and document using an embedded database.

This commit is contained in:
roy 2010-02-11 14:36:09 +00:00
parent 64f418c059
commit b32b792e3b
2 changed files with 52 additions and 31 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: term.c,v 1.7 2010/02/11 13:11:47 roy Exp $ */
/* $NetBSD: term.c,v 1.8 2010/02/11 14:36:09 roy Exp $ */
/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: term.c,v 1.7 2010/02/11 13:11:47 roy Exp $");
__RCSID("$NetBSD: term.c,v 1.8 2010/02/11 14:36:09 roy Exp $");
#include <sys/stat.h>
@ -44,7 +44,7 @@ __RCSID("$NetBSD: term.c,v 1.7 2010/02/11 13:11:47 roy Exp $");
#include <term_private.h>
#include <term.h>
#define TERMINFO_DIRS "/usr/share/misc/terminfo"
#define _PATH_TERMINFO "/usr/share/misc/terminfo"
static char database[PATH_MAX];
static char pathbuf[PATH_MAX];
@ -291,13 +291,11 @@ _ti_dbgettermp(TERMINAL *term, const char *path, const char *name, int flags)
return e;
}
int
_ti_getterm(TERMINAL *term, const char *name, int flags)
static int
_ti_findterm(TERMINAL *term, const char *name, int flags)
{
int r;
char *e, h[PATH_MAX];
size_t i;
const struct compiled_term *t;
_DIAGASSERT(term != NULL);
_DIAGASSERT(name != NULL);
@ -305,19 +303,34 @@ _ti_getterm(TERMINAL *term, const char *name, int flags)
database[0] = '\0';
_ti_database = NULL;
e = getenv("TERMINFO");
if (e != NULL)
return _ti_dbgetterm(term, e, name, flags);
e = getenv("HOME");
if (e != NULL) {
snprintf(h, sizeof(h), "%s/.terminfo", e);
r = _ti_dbgetterm(term, h, name, flags);
if (r == 1)
return 1;
if ((e = getenv("TERMINFO")) != NULL) {
if (e[0] == '/')
return _ti_dbgetterm(term, e, name, flags);
}
r = _ti_dbgettermp(term, TERMINFO_DIRS, name, flags);
if ((e = getenv("TERMINFO_DIRS")) != NULL)
return _ti_dbgettermp(term, e, name, flags);
r = 0;
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 1;
@ -331,7 +344,7 @@ _ti_getterm(TERMINAL *term, const char *name, int flags)
return r;
}
void
_ti_freeterm(TERMINAL *term)
{

View File

@ -1,4 +1,4 @@
.\" $NetBSD: terminfo.5.in,v 1.8 2010/02/11 00:22:41 roy Exp $
.\" $NetBSD: terminfo.5.in,v 1.9 2010/02/11 14:36:09 roy Exp $
.\"
.\" Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd February 5, 2010
.Dd February 11, 2010
.Dt TERMINFO 5
.Os
.Sh NAME
@ -194,25 +194,32 @@ sgr=\eE[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m%?%p9%t016%e017%
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,
.Pa .db
is appended to it and only this database is used.
is available then only this file is searched.
Otherwise
.Nm
will first look for
.Pa $HOME/.terminfo.db ,
.Pa $HOME/.terminfo ,
followed by
.Pa /usr/share/misc/terminfo.db ,
and
.Pa /rescue/terminfo.db .
.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 /rescue/terminfo.db
Small database of terminal descriptions for use when rescuing the system.
.It Pa /usr/share/misc/terminfo
File containing terminal descriptions.
.It Pa /usr/share/misc/terminfo.db
@ -222,7 +229,8 @@ Database of terminal descriptions.
.Xr infocmp 1 ,
.Xr tic 1 ,
.Xr tput 1 ,
.Xr curses 3
.Xr curses 3 ,
.Xr ndbm 3
.Sh STANDARDS
.Nm
complies with the