Store the aliases against the entry, so that infocmp can reproduce them.
Handy for creating smaller terminfo databases.
This commit is contained in:
parent
ae95aa4ad1
commit
ae351fab5b
|
@ -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 <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>
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 <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>
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -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 <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>
|
||||
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue