Switch terminfo(3) to cdb(5).

This commit is contained in:
joerg 2012-06-03 23:19:09 +00:00
parent 1907ec3a61
commit fc67b0cd11
17 changed files with 195 additions and 174 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.cdrom,v 1.6 2011/06/21 21:49:22 joerg Exp $
# $NetBSD: Makefile.cdrom,v 1.7 2012/06/03 23:19:09 joerg Exp $
.include <bsd.own.mk>
@ -53,7 +53,7 @@ CDRUNTIME+= ./usr/mdec
CDRUNTIME+= ./usr/sbin/chroot
CDRUNTIME+= ./usr/sbin/installboot
CDRUNTIME+= ./usr/sbin/wiconfig
CDRUNTIME+= ./usr/share/misc/terminfo.db
CDRUNTIME+= ./usr/share/misc/terminfo.cdb
CDRUNTIME+= ./usr/share/locale
image_md_pre:

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.cdrom,v 1.26 2011/06/21 21:49:23 joerg Exp $
# $NetBSD: Makefile.cdrom,v 1.27 2012/06/03 23:19:09 joerg Exp $
.include <bsd.own.mk>
@ -53,7 +53,7 @@ CDRUNTIME+= ./usr/mdec
CDRUNTIME+= ./usr/sbin/chroot
CDRUNTIME+= ./usr/sbin/installboot
CDRUNTIME+= ./usr/sbin/wiconfig
CDRUNTIME+= ./usr/share/misc/terminfo.db
CDRUNTIME+= ./usr/share/misc/terminfo.cdb
CDRUNTIME+= ./usr/share/locale
image_md_pre:

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.995 2012/06/01 13:19:38 nonaka Exp $
# $NetBSD: mi,v 1.996 2012/06/03 23:19:09 joerg Exp $
#
# Note: Don't delete entries from here - mark them as "obsolete" instead,
# unless otherwise stated below.
@ -3773,7 +3773,8 @@
./usr/share/misc/more.help base-obsolete obsolete
./usr/share/misc/nslookup.help base-obsolete obsolete
./usr/share/misc/terminfo base-terminfo-share share
./usr/share/misc/terminfo.db base-terminfo-share share
./usr/share/misc/terminfo.cdb base-terminfo-share share
./usr/share/misc/terminfo.db base-obsolete obsolete
./usr/share/misc/units.lib base-reference-share share
./usr/share/misc/usb_hid_usages base-reference-share share
./usr/share/misc/vgrindefs.db base-groff-share share

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.471 2012/06/01 10:52:38 skrll Exp $
# $NetBSD: mi,v 1.472 2012/06/03 23:19:10 joerg Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -2510,7 +2510,8 @@
./usr/tests/lib/libcrypt/t_crypt tests-lib-tests
./usr/tests/lib/libcurses tests-lib-tests
./usr/tests/lib/libcurses/.terminfo.db tests-obsolete obsolete
./usr/tests/lib/libcurses/terminfo.db tests-lib-tests atf
./usr/tests/lib/libcurses/terminfo.cdb tests-lib-tests atf
./usr/tests/lib/libcurses/terminfo.db tests-obsolete obsolete
./usr/tests/lib/libcurses/Atffile tests-lib-tests atf
./usr/tests/lib/libcurses/check_files tests-lib-tests
./usr/tests/lib/libcurses/check_files/addch.chk tests-lib-tests atf

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.14 2012/01/15 22:34:34 jmcneill Exp $
# $NetBSD: Makefile,v 1.15 2012/06/03 23:19:10 joerg Exp $
CDBASE= sparc64cd # gives ${CDBASE}.iso
CDRELEASE= true # include $RELEASEDIR/$MACHINE
@ -56,7 +56,7 @@ CDRUNTIME+= ./usr/sbin/chroot
CDRUNTIME+= ./usr/sbin/installboot
CDRUNTIME+= ./usr/sbin/pppd
CDRUNTIME+= ./usr/sbin/wiconfig
CDRUNTIME+= ./usr/share/misc/terminfo.db
CDRUNTIME+= ./usr/share/misc/terminfo.cdb
CDRUNTIME+= ./usr/share/locale
image_md_pre:

View File

@ -1,4 +1,4 @@
# $NetBSD: list,v 1.24 2011/07/03 23:11:34 tron Exp $
# $NetBSD: list,v 1.25 2012/06/03 23:19:10 joerg Exp $
SRCDIRS bin sbin libexec external/bsd/less/bin usr.bin usr.sbin
@ -85,7 +85,7 @@ COPY ${NETBSDSRCDIR}/etc/master.passwd etc/master.passwd
COPY ${NETBSDSRCDIR}/etc/netconfig etc/netconfig
COPY ${DISTRIBDIR}/common/protocols etc/protocols
COPY ${DISTRIBDIR}/common/services etc/services
COPY ${DESTDIR}/usr/share/misc/terminfo.db usr/share/misc/terminfo.db
COPY ${DESTDIR}/usr/share/misc/terminfo.cdb usr/share/misc/terminfo.cdb
# we need the boot block in /usr/mdec + the arch specific extras
COPY ${DESTDIR}/usr/mdec/binstall usr/mdec/binstall 555

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.hash,v 1.4 2011/11/03 07:19:39 joerg Exp $
# $NetBSD: Makefile.hash,v 1.5 2012/06/03 23:19:10 joerg Exp $
SCRIPT_ENV= \
TOOL_AWK=${TOOL_AWK:Q} \
@ -22,6 +22,8 @@ compiled_terms.c: genterms term.h ${NETBSDSRCDIR}/share/terminfo/terminfo
@echo "Generating compiled terminfo descriptions"
${SCRIPT_ENV} ${HOST_SH} ${.ALLSRC} > ${.TARGET}
compiled_terms.c: ${TOOL_TIC}
DPSRCS+= hash.c termcap_hash.c compiled_terms.c
CLEANFILES+= hash.c termcap_hash.c compiled_terms.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: compile.c,v 1.7 2012/06/01 12:08:40 joerg Exp $ */
/* $NetBSD: compile.c,v 1.8 2012/06/03 23:19:10 joerg Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
@ -32,7 +32,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: compile.c,v 1.7 2012/06/01 12:08:40 joerg Exp $");
__RCSID("$NetBSD: compile.c,v 1.8 2012/06/03 23:19:10 joerg Exp $");
#if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
@ -239,12 +239,7 @@ _ti_flatten(uint8_t **buf, const TIC *tic)
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 */
*cap++ = 1;
le16enc(cap, len);
cap += sizeof(uint16_t);
memcpy(cap, tic->name, len);

View File

@ -1,4 +1,4 @@
/* $NetBSD: term.c,v 1.14 2012/06/01 12:02:36 joerg Exp $ */
/* $NetBSD: term.c,v 1.15 2012/06/03 23:19:10 joerg Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
@ -28,16 +28,16 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: term.c,v 1.14 2012/06/01 12:02:36 joerg Exp $");
__RCSID("$NetBSD: term.c,v 1.15 2012/06/03 23:19:10 joerg Exp $");
#include <sys/stat.h>
#include <assert.h>
#include <cdbr.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>
@ -62,8 +62,8 @@ _ti_readterm(TERMINAL *term, const char *cap, size_t caplen, int flags)
TERMUSERDEF *ud;
ver = *cap++;
/* Only read version 1 and 2 structures */
if (ver != 1 && ver != 2) {
/* Only read version 1 structures */
if (ver != 1) {
errno = EINVAL;
return -1;
}
@ -89,17 +89,13 @@ _ti_readterm(TERMINAL *term, const char *cap, size_t caplen, int flags)
cap += sizeof(uint16_t);
term->name = cap;
cap += len;
if (ver == 1)
len = le16dec(cap);
cap += sizeof(uint16_t);
if (len == 0)
term->_alias = NULL;
else {
len = le16dec(cap);
cap += sizeof(uint16_t);
if (len == 0)
term->_alias = NULL;
else {
term->_alias = cap;
cap += len;
}
term->_alias = cap;
cap += len;
}
len = le16dec(cap);
cap += sizeof(uint16_t);
@ -215,41 +211,55 @@ _ti_readterm(TERMINAL *term, const char *cap, size_t caplen, int flags)
static int
_ti_dbgetterm(TERMINAL *term, const char *path, const char *name, int flags)
{
DBM *db;
datum dt;
char *p;
struct cdbr *db;
const void *data;
char *db_name;
const uint8_t *data8;
size_t len, klen;
int r;
db = dbm_open(path, O_RDONLY, 0644);
if (asprintf(&db_name, "%s.cdb", path) < 0)
return -1;
db = cdbr_open(db_name, CDBR_DEFAULT);
free(db_name);
if (db == NULL)
return -1;
klen = strlen(name) + 1;
if (cdbr_find(db, name, klen, &data, &len) == -1)
goto fail;
data8 = data;
if (len == 0)
goto fail;
/* Check for alias first, fall through to processing normal entries. */
if (data8[0] == 2) {
if (klen + 7 >= len || le16dec(data8 + 5) != klen)
goto fail;
if (memcmp(data8 + 7, name, klen))
goto fail;
if (cdbr_get(db, le32dec(data8 + 1), &data, &len))
goto fail;
data8 = data;
if (data8[0] != 1)
goto fail;
} else if (data8[0] != 1)
goto fail;
else if (klen + 3 >= len || le16dec(data8 + 1) != klen)
goto fail;
else if (memcmp(data8 + 3, name, klen))
goto fail;
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);
r = _ti_readterm(term, data, len, flags);
cdbr_close(db);
return r;
fail:
cdbr_close(db);
return 0;
}
static int

View File

@ -1,4 +1,4 @@
/* $NetBSD: term_private.h,v 1.9 2011/10/03 19:18:55 roy Exp $ */
/* $NetBSD: term_private.h,v 1.10 2012/06/03 23:19:10 joerg Exp $ */
/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@ -42,15 +42,22 @@
* 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:
*
* Version 1 capabilities are defined as:
* header byte (always 1)
* name
* 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
* cap length, num undefined caps, name, type (char), flag, number, string
*
* Version 2 entries are aliases and defined as:
* header byte (always 2)
* 32bit id of the corresponding terminal in the file
* name
*
* The database itself is created using cdbw(3) and the numbers are
* always stored as little endian.
*/

View File

@ -1,4 +1,4 @@
.\" $NetBSD: terminfo.5.in,v 1.15 2011/03/10 10:17:19 roy Exp $
.\" $NetBSD: terminfo.5.in,v 1.16 2012/06/03 23:19:10 joerg Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -195,10 +195,10 @@ hts=\eEH, ht=^I,
.Ed
.Ss Fetching Compiled Descriptions
This implementation uses hashed databases managed by
.Xr ndbm 3
.Xr cdb 5
instead of directories.
To maintain compatability with other implementations,
.Pa .db
.Pa .cdb
is appended to each file checked.
.Pp
If the environment variable
@ -237,12 +237,12 @@ 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
.Bl -tag -width /usr/share/misc/terminfo.cdb -compact
.It Pa $HOME/.terminfo.cdb
Database of terminal descriptions for personal use.
.It Pa /usr/share/misc/terminfo
File containing terminal descriptions.
.It Pa /usr/share/misc/terminfo.db
.It Pa /usr/share/misc/terminfo.cdb
Database of terminal descriptions.
.El
.Sh SEE ALSO
@ -250,7 +250,7 @@ Database of terminal descriptions.
.Xr tic 1 ,
.Xr tput 1 ,
.Xr curses 3 ,
.Xr ndbm 3
.Xr cdb 5
.Sh STANDARDS
.Nm
complies with the

View File

@ -1,4 +1,4 @@
.\" $NetBSD: hier.7,v 1.100 2012/04/21 12:27:29 roy Exp $
.\" $NetBSD: hier.7,v 1.101 2012/06/03 23:19:10 joerg Exp $
.\"
.\" Copyright (c) 1990, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@ -29,7 +29,7 @@
.\"
.\" @(#)hier.7 8.5 (Berkeley) 6/1/94
.\"
.Dd April 5, 2012
.Dd June 3, 2012
.Dt HIER 7
.Os
.Sh NAME
@ -569,12 +569,12 @@ macro package
.It Sy misc/
miscellaneous system-wide text files
.Pp
.Bl -tag -width "terminfo.db" -compact
.Bl -tag -width "terminfo.cdb" -compact
.It Sy terminfo
terminal characteristics database;
see
.Xr terminfo 5
.It Sy terminfo.db
.It Sy terminfo.cdb
database form of terminfo file; see
.Xr tic 1
.El

View File

@ -1,13 +1,13 @@
# $NetBSD: Makefile,v 1.2 2010/02/05 16:34:04 roy Exp $
# $NetBSD: Makefile,v 1.3 2012/06/03 23:19:11 joerg Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/8/93
CLEANFILES= terminfo.db
realall: terminfo.db
FILES=terminfo.db terminfo
CLEANFILES= terminfo.cdb
realall: terminfo.cdb
FILES=terminfo.cdb terminfo
FILESDIR=${BINDIR}/misc
terminfo.db: terminfo
terminfo.cdb: terminfo ${TOOL_TIC}
${_MKTARGET_CREATE}
${TOOL_TIC} -ax -o "${.OBJDIR}/terminfo" "${.CURDIR}/terminfo"
${TOOL_TIC} -ax -o ${.TARGET} "${.CURDIR}/terminfo"
.include <bsd.prog.mk>

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.2 2011/06/17 16:59:51 christos Exp $
# $NetBSD: Makefile,v 1.3 2012/06/03 23:19:11 joerg Exp $
NOMAN= # defined
@ -13,18 +13,18 @@ TERMINFO_DB= terminfo
TERMINFODIR= ${TESTSDIR}
FILESDIR= ${TESTSDIR}
FILES= ${TERMINFO_DB}.db
FILES= ${TERMINFO_DB}.cdb
TESTS_SH= t_curses
HOME= ${TESTDIR}
CLEANFILES+= ${TERMINFO_DB}.db
CLEANFILES+= ${TERMINFO_DB}.cdb
realall: ${TERMINFO_DB}.db
realall: ${TERMINFO_DB}.cdb
${TERMINFO_DB}.db: ${TEST_TERMINFO}
${TOOL_TIC} -o ${TERMINFO_DB} ${.CURDIR}/${TEST_TERMINFO}
${TERMINFO_DB}.cdb: ${TOOL_TIC} ${TEST_TERMINFO}
${TOOL_TIC} -o ${.TARGET} ${.CURDIR}/${TEST_TERMINFO}
.include <bsd.test.mk>
#.include <bsd.subdir.mk>

View File

@ -1,4 +1,4 @@
/* $NetBSD: director.c,v 1.9 2011/10/07 13:39:33 joerg Exp $ */
/* $NetBSD: director.c,v 1.10 2012/06/03 23:19:11 joerg Exp $ */
/*-
* Copyright 2009 Brett Lymn <blymn@NetBSD.org>
@ -103,7 +103,7 @@ usage(void)
"commandfile\n", getprogname());
fprintf(stderr, " where:\n");
fprintf(stderr, " -v enables verbose test output\n");
fprintf(stderr, " -T is a directory containing the terminfo.db "
fprintf(stderr, " -T is a directory containing the terminfo.cdb "
"file, or a file holding the terminfo description n");
fprintf(stderr, " -s is the path to the slave executable\n");
fprintf(stderr, " -t is value to set TERM to for the test\n");
@ -200,11 +200,11 @@ main(int argc, char *argv[])
if (S_ISDIR(st.st_mode)) {
char tinfo[MAXPATHLEN];
int l = snprintf(tinfo, sizeof(tinfo), "%s/%s", termpath,
"terminfo.db");
"terminfo.cdb");
if (stat(tinfo, &st) == -1)
err(1, "Cannot stat `%s'", tinfo);
if (l >= 3)
tinfo[l - 3] = '\0';
if (l >= 4)
tinfo[l - 4] = '\0';
if (setenv("TERMINFO", tinfo, 1) != 0)
err(1, "Failed to set TERMINFO variable");
} else {

View File

@ -1,4 +1,4 @@
.\" $NetBSD: tic.1,v 1.9 2011/11/02 19:21:49 pgoyette Exp $
.\" $NetBSD: tic.1,v 1.10 2012/06/03 23:19:11 joerg 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 11, 2010
.Dd June 3, 2012
.Dt TIC 1
.Os
.Sh NAME
@ -45,7 +45,7 @@ The
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.
The created database path name is the same as the source but with .cdb appended.
.Pp
The following options are available:
.Bl -tag -width Fl
@ -55,9 +55,9 @@ Do not discard commented out capabilities.
Only check for errors, don't write the final database.
.It Fl o Ar file
Write the database to
.Ar file Ns .db
.Ar file
instead of
.Ar source Ns .db .
.Ar source Ns .cdb .
.It Fl S
For
.Ar term1 , term2 , ...

View File

@ -1,4 +1,4 @@
/* $NetBSD: tic.c,v 1.19 2012/06/01 12:08:40 joerg Exp $ */
/* $NetBSD: tic.c,v 1.20 2012/06/03 23:19:11 joerg Exp $ */
/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@ -32,7 +32,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: tic.c,v 1.19 2012/06/01 12:08:40 joerg Exp $");
__RCSID("$NetBSD: tic.c,v 1.20 2012/06/03 23:19:11 joerg Exp $");
#include <sys/types.h>
#include <sys/queue.h>
@ -41,13 +41,13 @@ __RCSID("$NetBSD: tic.c,v 1.19 2012/06/01 12:08:40 joerg Exp $");
#include <sys/endian.h>
#endif
#include <cdbw.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <getopt.h>
#include <limits.h>
#include <fcntl.h>
#include <ndbm.h>
#include <search.h>
#include <stdarg.h>
#include <stdlib.h>
@ -63,26 +63,18 @@ __RCSID("$NetBSD: tic.c,v 1.19 2012/06/01 12:08:40 joerg Exp $");
through the database as the sequential iterator doesn't work
the the data size stored changes N amount which ours will. */
typedef struct term {
SLIST_ENTRY(term) next;
STAILQ_ENTRY(term) next;
char *name;
char type;
TIC *tic;
uint32_t id;
struct term *base_term;
} TERM;
static SLIST_HEAD(, term) terms = SLIST_HEAD_INITIALIZER(terms);
static STAILQ_HEAD(, term) terms = STAILQ_HEAD_INITIALIZER(terms);
static int error_exit;
static int Sflag;
static char *dbname;
static size_t nterm, nalias;
static void
do_unlink(void)
{
if (dbname != NULL)
unlink(dbname);
}
static void __printflike(1, 2)
dowarn(const char *fmt, ...)
{
@ -106,22 +98,32 @@ grow_tbuf(TBUF *tbuf, size_t len)
}
static int
save_term(DBM *db, TERM *term)
save_term(struct cdbw *db, TERM *term)
{
uint8_t *buf;
ssize_t len;
datum key, value;
size_t slen = strlen(term->name) + 1;
if (term->base_term != NULL) {
len = (ssize_t)slen + 7;
buf = emalloc(len);
buf[0] = 2;
le32enc(buf + 1, term->base_term->id);
le16enc(buf + 5, slen);
memcpy(buf + 7, term->name, slen);
if (cdbw_put(db, term->name, slen, buf, len))
err(1, "cdbw_put");
return 0;
}
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");
if (cdbw_put_data(db, buf, len, &term->id))
err(1, "cdbw_put_data");
if (cdbw_put_key(db, term->name, slen, term->id))
err(1, "cdbw_put_key");
free(buf);
return 0;
}
@ -138,20 +140,20 @@ find_term(const char *name)
}
static TERM *
store_term(const char *name, char type)
store_term(const char *name, TERM *base_term)
{
TERM *term;
ENTRY elem;
term = ecalloc(1, sizeof(*term));
term->name = estrdup(name);
term->type = type;
SLIST_INSERT_HEAD(&terms, term, next);
STAILQ_INSERT_TAIL(&terms, term, next);
elem.key = estrdup(name);
elem.data = term;
hsearch(elem, ENTER);
if (type == 'a')
term->base_term = base_term;
if (base_term != NULL)
nalias++;
else
nterm++;
@ -185,7 +187,7 @@ process_entry(TBUF *buf, int flags)
_ti_freetic(tic);
return 0;
}
term = store_term(tic->name, 't');
term = store_term(tic->name, NULL);
term->tic = tic;
/* Create aliased terms */
@ -199,9 +201,7 @@ process_entry(TBUF *buf, int flags)
dowarn("%s: has alias for already assigned"
" term %s", tic->name, p);
} else {
term = store_term(p, 'a');
term->tic = ecalloc(sizeof(*term->tic), 1);
term->tic->name = estrdup(tic->name);
store_term(p, term);
}
p = e;
}
@ -319,8 +319,8 @@ merge_use(int flags)
TERM *term, *uterm;;
skipped = merged = 0;
SLIST_FOREACH(term, &terms, next) {
if (term->type == 'a')
STAILQ_FOREACH(term, &terms, next) {
if (term->base_term != NULL)
continue;
rtic = term->tic;
while ((cap = _ti_find_extra(&rtic->extras, "use")) != NULL) {
@ -334,8 +334,8 @@ merge_use(int flags)
goto remove;
}
uterm = find_term(cap);
if (uterm != NULL && uterm->type == 'a')
uterm = find_term(uterm->tic->name);
if (uterm != NULL && uterm->base_term != NULL)
uterm = uterm->base_term;
if (uterm == NULL) {
dowarn("%s: no use record for %s",
rtic->name, cap);
@ -403,7 +403,7 @@ print_dump(int argc, char **argv)
warnx("%s: no description for terminal", argv[i]);
continue;
}
if (term->type == 'a') {
if (term->base_term != NULL) {
warnx("%s: cannot dump alias", argv[i]);
continue;
}
@ -444,17 +444,46 @@ print_dump(int argc, char **argv)
return n;
}
static void
write_database(const char *dbname)
{
struct cdbw *db;
char *tmp_dbname;
TERM *term;
int fd;
db = cdbw_open();
if (db == NULL)
err(1, "cdbw_open failed");
/* Save the terms */
STAILQ_FOREACH(term, &terms, next)
save_term(db, term);
easprintf(&tmp_dbname, "%s.XXXXXX", dbname);
fd = mkstemp(tmp_dbname);
if (fd == -1)
err(1, "creating temporary database %s failed", tmp_dbname);
if (cdbw_output(db, fd, "NetBSD terminfo", cdbw_stable_seeder))
err(1, "writing temporary database %s failed", tmp_dbname);
if (fchmod(fd, DEFFILEMODE))
err(1, "fchmod failed");
if (close(fd))
err(1, "writing temporary database %s failed", tmp_dbname);
if (rename(tmp_dbname, dbname))
err(1, "renaming %s to %s failed", tmp_dbname, dbname);
free(tmp_dbname);
cdbw_close(db);
}
int
main(int argc, char **argv)
{
int ch, cflag, sflag, flags;
char *source, *p, *buf, *ofile;
char *source, *dbname, *buf, *ofile;
FILE *f;
DBM *db;
size_t buflen;
ssize_t len;
TBUF tbuf;
TERM *term;
cflag = sflag = 0;
ofile = NULL;
@ -495,23 +524,6 @@ main(int argc, char **argv)
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 = emalloc(len + 4); /* For adding .db after open */
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 */
hcreate(HASH_SIZE);
@ -557,28 +569,21 @@ main(int argc, char **argv)
if (cflag)
return error_exit;
/* Save the terms */
SLIST_FOREACH(term, &terms, next)
save_term(db, term);
/* done! */
dbm_close(db);
/* Rename the tmp db to the real one now */
easprintf(&p, "%s.db", ofile);
if (rename(dbname, p) == -1)
err(1, "rename");
free(dbname);
dbname = NULL;
if (ofile == NULL)
easprintf(&dbname, "%s.cdb", source);
else
dbname = ofile;
write_database(dbname);
if (sflag != 0)
fprintf(stderr, "%zu entries and %zu aliases written to %s\n",
nterm, nalias, p);
nterm, nalias, dbname);
#ifdef __VALGRIND__
free(p);
while ((term = SLIST_FIRST(&terms)) != NULL) {
SLIST_REMOVE_HEAD(&terms, next);
if (ofile == NULL)
free(dbname);
while ((term = STAILQ_FIRST(&terms)) != NULL) {
STAILQ_REMOVE_HEAD(&terms, next);
_ti_freetic(term->tic);
free(term->name);
free(term);