Source-Changes-HG archive

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

[src/trunk]: src/lib/libterminfo Convert padding and give terminfo some defau...



details:   https://anonhg.NetBSD.org/src/rev/77d5b80c9257
branches:  trunk
changeset: 752701:77d5b80c9257
user:      roy <roy%NetBSD.org@localhost>
date:      Thu Mar 04 15:16:39 2010 +0000

description:
Convert padding and give terminfo some default assumptions about termcap.

diffstat:

 lib/libterminfo/termcap.c |  75 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 73 insertions(+), 2 deletions(-)

diffs (145 lines):

diff -r 398b01e9737e -r 77d5b80c9257 lib/libterminfo/termcap.c
--- a/lib/libterminfo/termcap.c Thu Mar 04 15:13:53 2010 +0000
+++ b/lib/libterminfo/termcap.c Thu Mar 04 15:16:39 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: termcap.c,v 1.5 2010/03/02 14:11:11 roy Exp $ */
+/* $NetBSD: termcap.c,v 1.6 2010/03/04 15:16:39 roy Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: termcap.c,v 1.5 2010/03/02 14:11:11 roy Exp $");
+__RCSID("$NetBSD: termcap.c,v 1.6 2010/03/04 15:16:39 roy Exp $");
 
 #include <assert.h>
 #include <ctype.h>
@@ -229,6 +229,7 @@
 strval(const char *val)
 {
        char *info, *ip, c;
+       const char *ps, *pe;
        int p;
        size_t len, l, n;
 
@@ -237,6 +238,22 @@
        if (info == NULL)
                return 0;
 
+       /* Move the = */
+       *ip++ = *val++;
+
+       /* Set ps and pe to point to the start and end of the padding */
+       if (isdigit((unsigned char)*val)) {
+               for (ps = pe = val;
+                    isdigit((unsigned char)*val) || *val == '.';
+                    val++)
+                       pe++;
+               if (*val == '*') {
+                       val++;
+                       pe++;
+               }
+       } else
+               ps = pe  = NULL;
+
        l = 0;
        p = 1;
        for (; *val != '\0'; val++) {
@@ -287,6 +304,19 @@
                *ip++ = '\\';
        }
 
+       /* Add our padding at the end. */
+       if (ps != NULL) {
+               n = pe - ps;
+               if (l + n + 4 > len)
+                       goto elen;
+               *ip++ = '$';
+               *ip++ = '<';
+               strncpy(ip, ps, n);
+               ip += n;
+               *ip++ = '/';
+               *ip++ = '>';
+       }
+
        *ip = '\0';
        return info;
 
@@ -296,20 +326,38 @@
        return NULL;
 }
 
+static struct def_info {
+       const char *name;
+       const char *cap;
+} def_infos[] = {
+       { "bel",        "^G" },
+       { "cr",         "^M" },
+       { "cud1",       "^J" },
+       { "ht",         "^I" },
+       { "ind",        "^J" },
+       { "kbs",        "^H" },
+       { "kcub1",      "^H" },
+       { "kcud1",      "^J" },
+       { "nel",        "^M^J" }
+};
+
 char *
 captoinfo(char *cap)
 {
        char *info, *ip, *token, *val, *p, tok[3];
        const char *name;
        size_t len, lp, nl, vl, rl;
+       int defs[__arraycount(def_infos)];
 
        _DIAGASSERT(cap != NULL);
 
        len = strlen(cap) * 2;
+       len += __arraycount(def_infos) * (5 + 4 + 3); /* reserve for defs */
        info = ip = malloc(len);
        if (info == NULL)
                return NULL;
 
+       memset(defs, 0, sizeof(defs));
        lp = 0;
        tok[2] = '\0';
        for (token = _ti_get_token(&cap, ':');
@@ -334,6 +382,16 @@
                                val = strval(token + 2);
                        }
                }
+
+               /* See if this sets a default. */
+               for (nl = 0; nl < __arraycount(def_infos); nl++) {
+                       if (strcmp(name, def_infos[nl].name) == 0) {
+                               printf ("matched %s\n", name);
+                               defs[nl] = 1;
+                               break;
+                       }
+               }
+
                nl = strlen(name);
                if (val == NULL)
                        vl = 0;
@@ -367,6 +425,19 @@
                }
        }
 
+       /* Add any defaults not set above. */
+       for (nl = 0; nl < __arraycount(def_infos); nl++) {
+               if (defs[nl] == 0) {
+                       *ip++ = ',';
+                       *ip++ = ' ';
+                       strcpy(ip, def_infos[nl].name);
+                       ip += strlen(def_infos[nl].name);
+                       *ip++ = '=';
+                       strcpy(ip, def_infos[nl].cap);
+                       ip += strlen(def_infos[nl].cap);
+               }
+       }
+
        *ip = '\0';
        return info;
 }



Home | Main Index | Thread Index | Old Index