Module Name: src Committed By: roy Date: Sun Mar 29 18:54:58 UTC 2020
Modified Files: src/lib/libterminfo: compile.c term_private.h Log Message: terminfo: allow _ti_getname to convert from and to any version To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/lib/libterminfo/compile.c cvs rdiff -u -r1.16 -r1.17 src/lib/libterminfo/term_private.h 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/compile.c diff -u src/lib/libterminfo/compile.c:1.20 src/lib/libterminfo/compile.c:1.21 --- src/lib/libterminfo/compile.c:1.20 Sat Mar 28 15:45:56 2020 +++ src/lib/libterminfo/compile.c Sun Mar 29 18:54:57 2020 @@ -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 @@ _ti_find_extra(TIC *tic, TBUF *tbuf, con 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; } Index: src/lib/libterminfo/term_private.h diff -u src/lib/libterminfo/term_private.h:1.16 src/lib/libterminfo/term_private.h:1.17 --- src/lib/libterminfo/term_private.h:1.16 Sun Mar 29 18:32:45 2020 +++ src/lib/libterminfo/term_private.h Sun Mar 29 18:54:57 2020 @@ -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. */