Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libterminfo terminfo: allow _ti_getname to convert from ...
details: https://anonhg.NetBSD.org/src/rev/142205eb01ce
branches: trunk
changeset: 970605:142205eb01ce
user: roy <roy%NetBSD.org@localhost>
date: Sun Mar 29 18:54:57 2020 +0000
description:
terminfo: allow _ti_getname to convert from and to any version
diffstat:
lib/libterminfo/compile.c | 38 +++++++++++++++++++++++++++-----------
lib/libterminfo/term_private.h | 9 ++++++++-
2 files changed, 35 insertions(+), 12 deletions(-)
diffs (85 lines):
diff -r 42ce05b4f3c4 -r 142205eb01ce lib/libterminfo/compile.c
--- a/lib/libterminfo/compile.c Sun Mar 29 18:32:45 2020 +0000
+++ b/lib/libterminfo/compile.c Sun Mar 29 18:54:57 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compile.c,v 1.20 2020/03/28 15:45:56 christos Exp $ */
+/* $NetBSD: compile.c,v 1.21 2020/03/29 18:54:57 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.20 2020/03/28 15:45:56 christos Exp $");
+__RCSID("$NetBSD: compile.c,v 1.21 2020/03/29 18:54:57 roy Exp $");
#if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
@@ -155,18 +155,34 @@
char *
_ti_getname(int rtype, const char *orig)
{
+ const char *delim;
char *name;
+ const char *verstr;
+ size_t diff, vlen;
- if (rtype == TERMINFO_RTYPE) {
- /* , and | are the two print characters now allowed
- * in terminfo aliases or long descriptions.
- * As | is generally used to delimit aliases inside the
- * description, we use a comma. */
- if (asprintf(&name, "%s,v3", orig) < 0)
- name = NULL;
- } else {
- name = strdup(orig);
+ switch (rtype) {
+ case TERMINFO_RTYPE:
+ verstr = TERMINFO_VDELIMSTR "v3";
+ break;
+ case TERMINFO_RTYPE_O1:
+ verstr = "";
+ break;
+ default:
+ errno = EINVAL;
+ return NULL;
}
+
+ delim = orig;
+ while (*delim != '\0' && *delim != TERMINFO_VDELIM)
+ delim++;
+ diff = delim - orig;
+ vlen = strlen(verstr);
+ name = malloc(diff + vlen + 1);
+ if (name == NULL)
+ return NULL;
+
+ memcpy(name, orig, diff);
+ memcpy(name + diff, verstr, vlen + 1);
return name;
}
diff -r 42ce05b4f3c4 -r 142205eb01ce lib/libterminfo/term_private.h
--- a/lib/libterminfo/term_private.h Sun Mar 29 18:32:45 2020 +0000
+++ b/lib/libterminfo/term_private.h Sun Mar 29 18:54:57 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: term_private.h,v 1.16 2020/03/29 18:32:45 roy Exp $ */
+/* $NetBSD: term_private.h,v 1.17 2020/03/29 18:54:57 roy Exp $ */
/*
* Copyright (c) 2009, 2010, 2013, 2020 The NetBSD Foundation, Inc.
@@ -79,6 +79,13 @@
#define TERMINFO_ALIAS 2
#define TERMINFO_RTYPE 3
+/* , and | are the two print characters now allowed
+ * in terminfo aliases or long descriptions.
+ * As | is generally used to delimit aliases inside the
+ * description, we use a comma. */
+#define TERMINFO_VDELIM ','
+#define TERMINFO_VDELIMSTR ","
+
/* We use the same ncurses tic macros so that our data is identical
* when a caller uses the long name macros to access te terminfo data
* directly. */
Home |
Main Index |
Thread Index |
Old Index