Module Name:    src
Committed By:   roy
Date:           Mon Mar 30 00:09:07 UTC 2020

Modified Files:
        src/lib/libterminfo: compile.c
        src/usr.bin/tic: tic.c

Log Message:
terminfo: v3 records should create v3 aliases


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/libterminfo/compile.c
cvs rdiff -u -r1.39 -r1.40 src/usr.bin/tic/tic.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/compile.c
diff -u src/lib/libterminfo/compile.c:1.22 src/lib/libterminfo/compile.c:1.23
--- src/lib/libterminfo/compile.c:1.22	Sun Mar 29 21:46:22 2020
+++ src/lib/libterminfo/compile.c	Mon Mar 30 00:09:06 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: compile.c,v 1.22 2020/03/29 21:46:22 roy Exp $ */
+/* $NetBSD: compile.c,v 1.23 2020/03/30 00:09:06 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.22 2020/03/29 21:46:22 roy Exp $");
+__RCSID("$NetBSD: compile.c,v 1.23 2020/03/30 00:09:06 roy Exp $");
 
 #if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H
 #include <sys/endian.h>
@@ -67,7 +67,7 @@ dowarn(int flags, const char *fmt, ...)
 int
 _ti_promote(TIC *tic)
 {
-	char *obuf, type, flag;
+	char *obuf, type, flag, *buf, *delim, *name, *nbuf;
 	const char *cap, *code, *str;
 	size_t n, entries, strl;
 	uint16_t ind;
@@ -84,6 +84,28 @@ _ti_promote(TIC *tic)
 	}
 	free(obuf);
 
+	n = 0;
+	obuf = buf = tic->alias;
+	tic->alias = NULL;
+	while (buf != NULL) {
+		delim = strchr(buf, '|');
+		if (delim != NULL)
+			*delim++ = '\0';
+		name = _ti_getname(tic->rtype, buf);
+		strl = strlen(name) + 1;
+		nbuf = realloc(tic->alias, n + strl);
+		if (nbuf == NULL) {
+			free(name);
+			return -1;
+		}
+		tic->alias = nbuf;
+		memcpy(tic->alias + n, name, strl);
+		n += strl;
+		free(name);
+		buf = delim;
+	}
+	free(obuf);
+
 	obuf = tic->nums.buf;
 	cap = obuf;
 	entries = tic->nums.entries;

Index: src/usr.bin/tic/tic.c
diff -u src/usr.bin/tic/tic.c:1.39 src/usr.bin/tic/tic.c:1.40
--- src/usr.bin/tic/tic.c:1.39	Sun Mar 29 21:54:03 2020
+++ src/usr.bin/tic/tic.c	Mon Mar 30 00:09:06 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: tic.c,v 1.39 2020/03/29 21:54:03 roy Exp $ */
+/* $NetBSD: tic.c,v 1.40 2020/03/30 00:09:06 roy Exp $ */
 
 /*
  * Copyright (c) 2009, 2010, 2020 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: tic.c,v 1.39 2020/03/29 21:54:03 roy Exp $");
+__RCSID("$NetBSD: tic.c,v 1.40 2020/03/30 00:09:06 roy Exp $");
 
 #include <sys/types.h>
 #include <sys/queue.h>
@@ -179,10 +179,37 @@ store_term(const char *name, TERM *base_
 	return term;
 }
 
+static void
+alias_terms(TERM *term)
+{
+	char *p, *e, *alias;
+
+	/* Create aliased terms */
+	if (term->tic->alias == NULL)
+		return;
+
+	alias = p = estrdup(term->tic->alias);
+	while (p != NULL && *p != '\0') {
+		e = strchr(p, '|');
+		if (e != NULL)
+			*e++ = '\0';
+		/* No need to lengthcheck the alias because the main
+		 * terminfo description already stores all the aliases
+		 * in the same length field as the alias. */
+		if (find_term(p) != NULL) {
+			dowarn("%s: has alias for already assigned"
+			    " term %s", term->tic->name, p);
+		} else {
+			store_term(p, term);
+		}
+		p = e;
+	}
+	free(alias);
+}
+
 static int
 process_entry(TBUF *buf, int flags)
 {
-	char *p, *e, *alias;
 	TERM *term;
 	TIC *tic;
 	TBUF sbuf = *buf;
@@ -208,27 +235,7 @@ process_entry(TBUF *buf, int flags)
 	}
 	term = store_term(tic->name, NULL);
 	term->tic = tic;
-
-	/* Create aliased terms */
-	if (tic->alias != NULL) {
-		alias = p = estrdup(tic->alias);
-		while (p != NULL && *p != '\0') {
-			e = strchr(p, '|');
-			if (e != NULL)
-				*e++ = '\0';
-			/* No need to lengthcheck the alias because the main
-			 * terminfo description already stores all the aliases
-			 * in the same length field as the alias. */
-			if (find_term(p) != NULL) {
-				dowarn("%s: has alias for already assigned"
-				    " term %s", tic->name, p);
-			} else {
-				store_term(p, term);
-			}
-			p = e;
-		}
-		free(alias);
-	}
+	alias_terms(term);
 
 	if (tic->rtype == TERMINFO_RTYPE)
 		return process_entry(&sbuf, flags | TIC_COMPAT_V1);
@@ -356,6 +363,11 @@ promote(TIC *rtic, TIC *utic)
 	tic->name = _ti_getname(TERMINFO_RTYPE, rtic->name);
 	if (tic->name == NULL)
 		goto err;
+	if (rtic->alias != NULL) {
+		tic->alias = strdup(rtic->alias);
+		if (tic->alias == NULL)
+			goto err;
+	}
 	if (rtic->desc != NULL) {
 		tic->desc = strdup(rtic->desc);
 		if (tic->desc == NULL)
@@ -375,10 +387,12 @@ promote(TIC *rtic, TIC *utic)
 		goto err;
 
 	term = store_term(tic->name, NULL);
-	if (term != NULL) {
-		term->tic = tic;
-		return 0;
-	}
+	if (term == NULL)
+		goto err;
+
+	term->tic = tic;
+	alias_terms(term);
+	return 0;
 
 err:
 	free(tic->flags.buf);
@@ -386,6 +400,7 @@ err:
 	free(tic->strs.buf);
 	free(tic->extras.buf);
 	free(tic->desc);
+	free(tic->alias);
 	free(tic->name);
 	free(tic);
 	return -1;

Reply via email to