terminfo: Add guards to optionally build parts of libterminfo

Reading from a database is now optional.
Compiling terminfo descriptions (including from $TERMINFO) is now optional.
Compat support is now optional.

This removes 17k on amd64 from the binary size, which allows it to be used
again on space constrained ramdisks.
This commit is contained in:
roy 2020-04-05 12:31:02 +00:00
parent d001b02d00
commit 9e387da605
3 changed files with 43 additions and 10 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.22 2012/03/21 05:37:44 matt Exp $
# $NetBSD: Makefile,v 1.23 2020/04/05 12:31:02 roy Exp $
.include <bsd.own.mk>
@ -10,10 +10,20 @@ WARNS?= 5
CPPFLAGS+= -I${.CURDIR}
SRCS= term.c ti.c setupterm.c curterm.c tparm.c tputs.c
SRCS+= compile.c hash.c
SRCS+= hash.c
INCS= term.h
INCSDIR= /usr/include
# For ramdisks there is no database to read from so remove compat
# and the need to read from them.
# While here, remove the ability to compile terminfo descriptions
# from $TERMINFO as well.
# This means the library requires any terminal needed built into it.
.if !defined(SMALLPROG)
CPPFLAGS+= -DTERMINFO_COMPILE -DTERMINFO_DB -DTERMINFO_COMPAT
SRCS+= compile.c
.endif
COPTS.tparm.c = -Wno-format-nonliteral
MAN= terminfo.3 terminfo.5

View File

@ -1,4 +1,4 @@
/* $NetBSD: compile.c,v 1.24 2020/03/30 02:08:11 roy Exp $ */
/* $NetBSD: compile.c,v 1.25 2020/04/05 12:31:02 roy Exp $ */
/*
* Copyright (c) 2009, 2010, 2011, 2020 The NetBSD Foundation, Inc.
@ -32,7 +32,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: compile.c,v 1.24 2020/03/30 02:08:11 roy Exp $");
__RCSID("$NetBSD: compile.c,v 1.25 2020/04/05 12:31:02 roy Exp $");
#if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
@ -64,6 +64,7 @@ dowarn(int flags, const char *fmt, ...)
}
}
#ifdef TERMINFO_COMPAT
int
_ti_promote(TIC *tic)
{
@ -165,6 +166,7 @@ _ti_promote(TIC *tic)
return error;
}
#endif
char *
_ti_grow_tbuf(TBUF *tbuf, size_t len)
@ -257,6 +259,7 @@ _ti_find_extra(TIC *tic, TBUF *tbuf, const char *code)
char *
_ti_getname(int rtype, const char *orig)
{
#ifdef TERMINFO_COMPAT
const char *delim;
char *name;
const char *verstr;
@ -286,6 +289,9 @@ _ti_getname(int rtype, const char *orig)
memcpy(name, orig, diff);
memcpy(name + diff, verstr, vlen + 1);
return name;
#else
return strdup(orig);
#endif
}
size_t
@ -626,7 +632,11 @@ _ti_compile(char *cap, int flags)
if (tic == NULL)
return NULL;
#ifdef TERMINFO_COMPAT
tic->rtype = TERMINFO_RTYPE_O1; /* will promote if needed */
#else
tic->rtype = TERMINFO_RTYPE;
#endif
buf.buf = NULL;
buf.buflen = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: term.c,v 1.32 2020/03/27 17:39:53 christos Exp $ */
/* $NetBSD: term.c,v 1.33 2020/04/05 12:31:02 roy Exp $ */
/*
* Copyright (c) 2009, 2010, 2011, 2020 The NetBSD Foundation, Inc.
@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: term.c,v 1.32 2020/03/27 17:39:53 christos Exp $");
__RCSID("$NetBSD: term.c,v 1.33 2020/04/05 12:31:02 roy Exp $");
#include <sys/stat.h>
@ -50,7 +50,9 @@ __RCSID("$NetBSD: term.c,v 1.32 2020/03/27 17:39:53 christos Exp $");
*/
#define _PATH_TERMINFO "/usr/share/misc/terminfo"
#ifdef TERMINFO_DB
static char __ti_database[PATH_MAX];
#endif
const char *_ti_database;
/* Include a generated list of pre-compiled terminfo descriptions. */
@ -227,6 +229,7 @@ out:
return -1;
}
#if defined(TERMINFO_DB) || defined(TERMINFO_COMPILE)
static int
_ti_checkname(const char *name, const char *termname, const char *termalias)
{
@ -259,7 +262,9 @@ _ti_checkname(const char *name, const char *termname, const char *termalias)
/* No match. */
return 0;
}
#endif
#ifdef TERMINFO_DB
static int
_ti_dbgetterm(TERMINAL *term, const char *path, const char *name, int flags)
{
@ -339,6 +344,7 @@ _ti_dbgettermp(TERMINAL *term, const char *path, const char *name, int flags)
} while (*path++ == ':');
return e;
}
#endif
static int
_ti_findterm(TERMINAL *term, const char *name, int flags)
@ -352,12 +358,14 @@ _ti_findterm(TERMINAL *term, const char *name, int flags)
_ti_database = NULL;
r = 0;
if ((e = getenv("TERMINFO")) != NULL && *e != '\0') {
if (e[0] == '/')
return _ti_dbgetterm(term, e, name, flags);
}
e = getenv("TERMINFO");
#ifdef TERMINFO_DB
if (e != NULL && *e == '/')
return _ti_dbgetterm(term, e, name, flags);
#endif
c = NULL;
#ifdef TERMINFO_COMPILE
if (e == NULL && (c = getenv("TERMCAP")) != NULL) {
if (*c != '\0' && *c != '/') {
c = strdup(c);
@ -402,7 +410,9 @@ _ti_findterm(TERMINAL *term, const char *name, int flags)
return r;
}
}
#endif
#ifdef TERMINFO_DB
if ((e = getenv("TERMINFO_DIRS")) != NULL)
return _ti_dbgettermp(term, e, name, flags);
@ -414,6 +424,7 @@ _ti_findterm(TERMINAL *term, const char *name, int flags)
}
if (r != 1)
r = _ti_dbgettermp(term, _PATH_TERMINFO, name, flags);
#endif
return r;
}
@ -424,6 +435,7 @@ _ti_getterm(TERMINAL *term, const char *name, int flags)
int r;
size_t i;
const struct compiled_term *t;
#ifdef TERMINFO_COMPAT
char *namev3;
namev3 = _ti_getname(TERMINFO_RTYPE, name);
@ -433,6 +445,7 @@ _ti_getterm(TERMINAL *term, const char *name, int flags)
if (r == 1)
return r;
}
#endif
r = _ti_findterm(term, name, flags);
if (r == 1)