Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Store the aliases against the entry, so that infocmp can rep...



details:   https://anonhg.NetBSD.org/src/rev/ca86518c69e1
branches:  trunk
changeset: 751478:ca86518c69e1
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Feb 05 12:31:56 2010 +0000

description:
Store the aliases against the entry, so that infocmp can reproduce them.
Handy for creating smaller terminfo databases.

diffstat:

 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(-)

diffs (193 lines):

diff -r b7e9f68f0b58 -r ca86518c69e1 lib/libterminfo/term.c
--- a/lib/libterminfo/term.c    Fri Feb 05 12:13:36 2010 +0000
+++ b/lib/libterminfo/term.c    Fri Feb 05 12:31:56 2010 +0000
@@ -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 @@
 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 @@
        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 -r b7e9f68f0b58 -r ca86518c69e1 lib/libterminfo/term_private.h
--- a/lib/libterminfo/term_private.h    Fri Feb 05 12:13:36 2010 +0000
+++ b/lib/libterminfo/term_private.h    Fri Feb 05 12:31:56 2010 +0000
@@ -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 @@
        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 -r b7e9f68f0b58 -r ca86518c69e1 usr.bin/infocmp/infocmp.c
--- a/usr.bin/infocmp/infocmp.c Fri Feb 05 12:13:36 2010 +0000
+++ b/usr.bin/infocmp/infocmp.c Fri Feb 05 12:31:56 2010 +0000
@@ -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 @@
                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 @@
                }
                return EXIT_SUCCESS;
        }
-               
+
        if (Barg == NULL)
                unsetenv("TERMINFO");
        else
diff -r b7e9f68f0b58 -r ca86518c69e1 usr.bin/tic/tic.c
--- a/usr.bin/tic/tic.c Fri Feb 05 12:13:36 2010 +0000
+++ b/usr.bin/tic/tic.c Fri Feb 05 12:31:56 2010 +0000
@@ -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 tic {
        char *name;
+       char *alias;
        char *desc;
        TBUF flags;
        TBUF nums;
@@ -239,7 +240,7 @@
 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 @@
        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 @@
        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 @@
        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)



Home | Main Index | Thread Index | Old Index