Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libterminfo terminfo: Add guards to optionally build par...



details:   https://anonhg.NetBSD.org/src/rev/8f0a5ba4e9fb
branches:  trunk
changeset: 1008903:8f0a5ba4e9fb
user:      roy <roy%NetBSD.org@localhost>
date:      Sun Apr 05 12:31:02 2020 +0000

description:
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.

diffstat:

 lib/libterminfo/Makefile  |  14 ++++++++++++--
 lib/libterminfo/compile.c |  14 ++++++++++++--
 lib/libterminfo/term.c    |  25 +++++++++++++++++++------
 3 files changed, 43 insertions(+), 10 deletions(-)

diffs (202 lines):

diff -r 63393a779c9e -r 8f0a5ba4e9fb lib/libterminfo/Makefile
--- a/lib/libterminfo/Makefile  Sun Apr 05 11:19:01 2020 +0000
+++ b/lib/libterminfo/Makefile  Sun Apr 05 12:31:02 2020 +0000
@@ -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 @@
 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
diff -r 63393a779c9e -r 8f0a5ba4e9fb lib/libterminfo/compile.c
--- a/lib/libterminfo/compile.c Sun Apr 05 11:19:01 2020 +0000
+++ b/lib/libterminfo/compile.c Sun Apr 05 12:31:02 2020 +0000
@@ -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 @@
        }
 }
 
+#ifdef TERMINFO_COMPAT
 int
 _ti_promote(TIC *tic)
 {
@@ -165,6 +166,7 @@
 
        return error;
 }
+#endif
 
 char *
 _ti_grow_tbuf(TBUF *tbuf, size_t len)
@@ -257,6 +259,7 @@
 char *
 _ti_getname(int rtype, const char *orig)
 {
+#ifdef TERMINFO_COMPAT
        const char *delim;
        char *name;
        const char *verstr;
@@ -286,6 +289,9 @@
        memcpy(name, orig, diff);
        memcpy(name + diff, verstr, vlen + 1);
        return name;
+#else
+       return strdup(orig);
+#endif
 }
 
 size_t
@@ -626,7 +632,11 @@
        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;
 
diff -r 63393a779c9e -r 8f0a5ba4e9fb lib/libterminfo/term.c
--- a/lib/libterminfo/term.c    Sun Apr 05 11:19:01 2020 +0000
+++ b/lib/libterminfo/term.c    Sun Apr 05 12:31:02 2020 +0000
@@ -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 @@
  */
 #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 @@
        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 @@
        /* 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 @@
        } while (*path++ == ':');
        return e;
 }
+#endif
 
 static int
 _ti_findterm(TERMINAL *term, const char *name, int flags)
@@ -352,12 +358,14 @@
        _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 @@
                        return r;
                }
        }
+#endif
 
+#ifdef TERMINFO_DB
        if ((e = getenv("TERMINFO_DIRS")) != NULL)
                return _ti_dbgettermp(term, e, name, flags);
 
@@ -414,6 +424,7 @@
        }
        if (r != 1)
                r = _ti_dbgettermp(term, _PATH_TERMINFO, name, flags);
+#endif
 
        return r;
 }
@@ -424,6 +435,7 @@
        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 @@
                if (r == 1)
                        return r;
        }
+#endif
 
        r = _ti_findterm(term, name, flags);
        if (r == 1)



Home | Main Index | Thread Index | Old Index