From ae351fab5b821304e1dcfa943495f7c30383bd82 Mon Sep 17 00:00:00 2001 From: roy Date: Fri, 5 Feb 2010 12:31:56 +0000 Subject: [PATCH] Store the aliases against the entry, so that infocmp can reproduce them. Handy for creating smaller terminfo databases. --- lib/libterminfo/term.c | 22 ++++++++++++++++++---- lib/libterminfo/term_private.h | 4 +++- usr.bin/infocmp/infocmp.c | 8 +++++--- usr.bin/tic/tic.c | 25 +++++++++++++++++++++---- 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/lib/libterminfo/term.c b/lib/libterminfo/term.c index c29e87718abc..e20ea08ba463 100644 --- a/lib/libterminfo/term.c +++ b/lib/libterminfo/term.c @@ -1,4 +1,4 @@ -/* $NetBSD: term.c,v 1.2 2010/02/05 09:42:21 roy Exp $ */ +/* $NetBSD: term.c,v 1.3 2010/02/05 12:31:56 roy Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ */ #include -__RCSID("$NetBSD: term.c,v 1.2 2010/02/05 09:42:21 roy Exp $"); +__RCSID("$NetBSD: term.c,v 1.3 2010/02/05 12:31:56 roy Exp $"); #include @@ -53,12 +53,14 @@ const char *_ti_database; static int _ti_readterm(TERMINAL *term, char *cap, size_t caplen, int flags) { + uint8_t ver; uint16_t ind, num; size_t len; TERMUSERDEF *ud; - /* Only read version 1 structures */ - if (*cap++ != 1) { + ver = *cap++; + /* Only read version 1 and 2 structures */ + if (ver != 1 && ver != 2) { errno = EINVAL; return -1; } @@ -83,6 +85,18 @@ _ti_readterm(TERMINAL *term, char *cap, size_t caplen, int flags) cap += sizeof(uint16_t); term->name = cap; cap += len; + if (ver == 1) + term->_alias = NULL; + else { + len = le16dec(cap); + cap += sizeof(uint16_t); + if (len == 0) + term->_alias = NULL; + else { + term->_alias = cap; + cap += len; + } + } len = le16dec(cap); cap += sizeof(uint16_t); term->desc = cap; diff --git a/lib/libterminfo/term_private.h b/lib/libterminfo/term_private.h index 16a3fa351242..0489c5ef252a 100644 --- a/lib/libterminfo/term_private.h +++ b/lib/libterminfo/term_private.h @@ -1,4 +1,4 @@ -/* $NetBSD: term_private.h,v 1.2 2010/02/03 18:49:23 snj Exp $ */ +/* $NetBSD: term_private.h,v 1.3 2010/02/05 12:31:56 roy Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -99,6 +99,8 @@ typedef struct terminal { size_t _bufpos; /* A-Z static variables for tparm */ long _snums[26]; + /* aliases of the terminal, | separated */ + char *_alias; } TERMINAL; extern const char * _ti_database; diff --git a/usr.bin/infocmp/infocmp.c b/usr.bin/infocmp/infocmp.c index 2f0ca6a405e0..f3eea1969d5c 100644 --- a/usr.bin/infocmp/infocmp.c +++ b/usr.bin/infocmp/infocmp.c @@ -1,4 +1,4 @@ -/* $NetBSD: infocmp.c,v 1.2 2010/02/05 10:10:04 roy Exp $ */ +/* $NetBSD: infocmp.c,v 1.3 2010/02/05 12:31:56 roy Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ */ #include -__RCSID("$NetBSD: infocmp.c,v 1.2 2010/02/05 10:10:04 roy Exp $"); +__RCSID("$NetBSD: infocmp.c,v 1.3 2010/02/05 12:31:56 roy Exp $"); #include @@ -721,6 +721,8 @@ main(int argc, char **argv) if (uflag == 0) printf("# Reconstructed from %s.db\n", _ti_database); printf("%s", t->name); + if (t->_alias != NULL && *t->_alias != '\0') + printf("|%s", t->_alias); if (t->desc != NULL && *t->desc != '\0') printf("|%s", t->desc); printf(",\n"); @@ -750,7 +752,7 @@ main(int argc, char **argv) } return EXIT_SUCCESS; } - + if (Barg == NULL) unsetenv("TERMINFO"); else diff --git a/usr.bin/tic/tic.c b/usr.bin/tic/tic.c index 4a310b6e79b0..f4974a12e2f6 100644 --- a/usr.bin/tic/tic.c +++ b/usr.bin/tic/tic.c @@ -1,4 +1,4 @@ -/* $NetBSD: tic.c,v 1.1 2010/02/03 15:16:32 roy Exp $ */ +/* $NetBSD: tic.c,v 1.2 2010/02/05 12:31:56 roy Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #endif #include -__RCSID("$NetBSD: tic.c,v 1.1 2010/02/03 15:16:32 roy Exp $"); +__RCSID("$NetBSD: tic.c,v 1.2 2010/02/05 12:31:56 roy Exp $"); #include @@ -61,6 +61,7 @@ typedef struct tbuf { typedef struct tic { char *name; + char *alias; char *desc; TBUF flags; TBUF nums; @@ -239,7 +240,7 @@ store_extra(TIC *tic, int wrn, char *id, char type, char flag, short num, static int save_term(DBM *db, TERM *term) { - size_t buflen, len, dlen; + size_t buflen, len, alen, dlen; char *cap; datum key, value; TIC *tic; @@ -247,12 +248,17 @@ save_term(DBM *db, TERM *term) scratch.bufpos = 0; tic = &term->tic; len = strlen(tic->name) + 1; + if (tic->alias == NULL) + alen = 0; + else + alen = strlen(tic->alias) + 1; if (tic->desc == NULL) dlen = 0; else dlen = strlen(tic->desc) + 1; buflen = sizeof(char) + sizeof(uint16_t) + len + + //sizeof(uint16_t) + alen + sizeof(uint16_t) + dlen + (sizeof(uint16_t) * 2) + tic->flags.bufpos + (sizeof(uint16_t) * 2) + tic->nums.bufpos + @@ -263,12 +269,18 @@ save_term(DBM *db, TERM *term) if (term->type == 'a') *cap++ = 0; else - *cap++ = 1; /* version */ + *cap++ = 2; /* version */ le16enc(cap, len); cap += sizeof(uint16_t); memcpy(cap, tic->name, len); cap += len; if (term->type != 'a') { + le16enc(cap, alen); + cap += sizeof(uint16_t); + if (tic->alias != NULL) { + memcpy(cap, tic->alias, alen); + cap += alen; + } le16enc(cap, dlen); cap += sizeof(uint16_t); if (tic->desc != NULL) { @@ -506,6 +518,11 @@ process_entry(TBUF *buf) tic->name = strdup(name); if (tic->name == NULL) err(1, "malloc"); + if (alias != NULL) { + tic->alias = strdup(alias); + if (tic->alias == NULL) + err(1, "malloc"); + } if (desc != NULL) { tic->desc = strdup(desc); if (tic->desc == NULL)