Store the aliases against the entry, so that infocmp can reproduce them.

Handy for creating smaller terminfo databases.
This commit is contained in:
roy 2010-02-05 12:31:56 +00:00
parent ae95aa4ad1
commit ae351fab5b
4 changed files with 47 additions and 12 deletions

View File

@ -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. * Copyright (c) 2009 The NetBSD Foundation, Inc.
@ -28,7 +28,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__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 <sys/stat.h> #include <sys/stat.h>
@ -53,12 +53,14 @@ const char *_ti_database;
static int static int
_ti_readterm(TERMINAL *term, char *cap, size_t caplen, int flags) _ti_readterm(TERMINAL *term, char *cap, size_t caplen, int flags)
{ {
uint8_t ver;
uint16_t ind, num; uint16_t ind, num;
size_t len; size_t len;
TERMUSERDEF *ud; TERMUSERDEF *ud;
/* Only read version 1 structures */ ver = *cap++;
if (*cap++ != 1) { /* Only read version 1 and 2 structures */
if (ver != 1 && ver != 2) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
@ -83,6 +85,18 @@ _ti_readterm(TERMINAL *term, char *cap, size_t caplen, int flags)
cap += sizeof(uint16_t); cap += sizeof(uint16_t);
term->name = cap; term->name = cap;
cap += len; 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); len = le16dec(cap);
cap += sizeof(uint16_t); cap += sizeof(uint16_t);
term->desc = cap; term->desc = cap;

View File

@ -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. * Copyright (c) 2009 The NetBSD Foundation, Inc.
@ -99,6 +99,8 @@ typedef struct terminal {
size_t _bufpos; size_t _bufpos;
/* A-Z static variables for tparm */ /* A-Z static variables for tparm */
long _snums[26]; long _snums[26];
/* aliases of the terminal, | separated */
char *_alias;
} TERMINAL; } TERMINAL;
extern const char * _ti_database; extern const char * _ti_database;

View File

@ -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. * Copyright (c) 2009 The NetBSD Foundation, Inc.
@ -28,7 +28,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__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 <sys/ioctl.h> #include <sys/ioctl.h>
@ -721,6 +721,8 @@ main(int argc, char **argv)
if (uflag == 0) if (uflag == 0)
printf("# Reconstructed from %s.db\n", _ti_database); printf("# Reconstructed from %s.db\n", _ti_database);
printf("%s", t->name); printf("%s", t->name);
if (t->_alias != NULL && *t->_alias != '\0')
printf("|%s", t->_alias);
if (t->desc != NULL && *t->desc != '\0') if (t->desc != NULL && *t->desc != '\0')
printf("|%s", t->desc); printf("|%s", t->desc);
printf(",\n"); printf(",\n");
@ -750,7 +752,7 @@ main(int argc, char **argv)
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
if (Barg == NULL) if (Barg == NULL)
unsetenv("TERMINFO"); unsetenv("TERMINFO");
else else

View File

@ -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. * Copyright (c) 2009 The NetBSD Foundation, Inc.
@ -32,7 +32,7 @@
#endif #endif
#include <sys/cdefs.h> #include <sys/cdefs.h>
__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 <sys/types.h> #include <sys/types.h>
@ -61,6 +61,7 @@ typedef struct tbuf {
typedef struct tic { typedef struct tic {
char *name; char *name;
char *alias;
char *desc; char *desc;
TBUF flags; TBUF flags;
TBUF nums; TBUF nums;
@ -239,7 +240,7 @@ store_extra(TIC *tic, int wrn, char *id, char type, char flag, short num,
static int static int
save_term(DBM *db, TERM *term) save_term(DBM *db, TERM *term)
{ {
size_t buflen, len, dlen; size_t buflen, len, alen, dlen;
char *cap; char *cap;
datum key, value; datum key, value;
TIC *tic; TIC *tic;
@ -247,12 +248,17 @@ save_term(DBM *db, TERM *term)
scratch.bufpos = 0; scratch.bufpos = 0;
tic = &term->tic; tic = &term->tic;
len = strlen(tic->name) + 1; len = strlen(tic->name) + 1;
if (tic->alias == NULL)
alen = 0;
else
alen = strlen(tic->alias) + 1;
if (tic->desc == NULL) if (tic->desc == NULL)
dlen = 0; dlen = 0;
else else
dlen = strlen(tic->desc) + 1; dlen = strlen(tic->desc) + 1;
buflen = sizeof(char) + buflen = sizeof(char) +
sizeof(uint16_t) + len + sizeof(uint16_t) + len +
//sizeof(uint16_t) + alen +
sizeof(uint16_t) + dlen + sizeof(uint16_t) + dlen +
(sizeof(uint16_t) * 2) + tic->flags.bufpos + (sizeof(uint16_t) * 2) + tic->flags.bufpos +
(sizeof(uint16_t) * 2) + tic->nums.bufpos + (sizeof(uint16_t) * 2) + tic->nums.bufpos +
@ -263,12 +269,18 @@ save_term(DBM *db, TERM *term)
if (term->type == 'a') if (term->type == 'a')
*cap++ = 0; *cap++ = 0;
else else
*cap++ = 1; /* version */ *cap++ = 2; /* version */
le16enc(cap, len); le16enc(cap, len);
cap += sizeof(uint16_t); cap += sizeof(uint16_t);
memcpy(cap, tic->name, len); memcpy(cap, tic->name, len);
cap += len; cap += len;
if (term->type != 'a') { 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); le16enc(cap, dlen);
cap += sizeof(uint16_t); cap += sizeof(uint16_t);
if (tic->desc != NULL) { if (tic->desc != NULL) {
@ -506,6 +518,11 @@ process_entry(TBUF *buf)
tic->name = strdup(name); tic->name = strdup(name);
if (tic->name == NULL) if (tic->name == NULL)
err(1, "malloc"); err(1, "malloc");
if (alias != NULL) {
tic->alias = strdup(alias);
if (tic->alias == NULL)
err(1, "malloc");
}
if (desc != NULL) { if (desc != NULL) {
tic->desc = strdup(desc); tic->desc = strdup(desc);
if (tic->desc == NULL) if (tic->desc == NULL)