Module Name:    src
Committed By:   roy
Date:           Sun Apr  5 12:31:02 UTC 2020

Modified Files:
        src/lib/libterminfo: Makefile compile.c term.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/libterminfo/Makefile
cvs rdiff -u -r1.24 -r1.25 src/lib/libterminfo/compile.c
cvs rdiff -u -r1.32 -r1.33 src/lib/libterminfo/term.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libterminfo/Makefile
diff -u src/lib/libterminfo/Makefile:1.22 src/lib/libterminfo/Makefile:1.23
--- src/lib/libterminfo/Makefile:1.22	Wed Mar 21 05:37:44 2012
+++ src/lib/libterminfo/Makefile	Sun Apr  5 12:31:02 2020
@@ -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

Index: src/lib/libterminfo/compile.c
diff -u src/lib/libterminfo/compile.c:1.24 src/lib/libterminfo/compile.c:1.25
--- src/lib/libterminfo/compile.c:1.24	Mon Mar 30 02:08:11 2020
+++ src/lib/libterminfo/compile.c	Sun Apr  5 12:31:02 2020
@@ -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, con
 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;
 

Index: src/lib/libterminfo/term.c
diff -u src/lib/libterminfo/term.c:1.32 src/lib/libterminfo/term.c:1.33
--- src/lib/libterminfo/term.c:1.32	Fri Mar 27 17:39:53 2020
+++ src/lib/libterminfo/term.c	Sun Apr  5 12:31:02 2020
@@ -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/
  */
 #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 ch
 	/* 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 cha
 	} 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 
 	_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 
 			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 
 	}
 	if (r != 1)
 		r = _ti_dbgettermp(term, _PATH_TERMINFO, name, flags);
+#endif
 
 	return r;
 }
@@ -424,6 +435,7 @@ _ti_getterm(TERMINAL *term, const char *
 	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 *
 		if (r == 1)
 			return r;
 	}
+#endif
 
 	r = _ti_findterm(term, name, flags);
 	if (r == 1)

Reply via email to