Source-Changes-HG archive

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

[src/trunk]: src/lib/libterminfo Use _ti_get_token instead of strsep when par...



details:   https://anonhg.NetBSD.org/src/rev/ef0330d3fb10
branches:  trunk
changeset: 752614:ef0330d3fb10
user:      roy <roy%NetBSD.org@localhost>
date:      Tue Mar 02 14:11:11 2010 +0000

description:
Use _ti_get_token instead of strsep when parsing termcap entries.
This allows us to handle \E\ as a valid sequence.

diffstat:

 lib/libterminfo/compile.c      |  34 +++++++++++++++++++---------------
 lib/libterminfo/term_private.h |   3 ++-
 lib/libterminfo/termcap.c      |  22 ++++++++++++++++------
 3 files changed, 37 insertions(+), 22 deletions(-)

diffs (149 lines):

diff -r 90216437d10b -r ef0330d3fb10 lib/libterminfo/compile.c
--- a/lib/libterminfo/compile.c Tue Mar 02 13:27:27 2010 +0000
+++ b/lib/libterminfo/compile.c Tue Mar 02 14:11:11 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compile.c,v 1.3 2010/03/01 01:59:48 dholland Exp $ */
+/* $NetBSD: compile.c,v 1.4 2010/03/02 14:11:11 roy Exp $ */
 
 /*
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: compile.c,v 1.3 2010/03/01 01:59:48 dholland Exp $");
+__RCSID("$NetBSD: compile.c,v 1.4 2010/03/02 14:11:11 roy Exp $");
 
 #if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H
 #include <sys/endian.h>
@@ -413,11 +413,10 @@
        return 0;
 }
 
-static char *
-get_token(char **cap)
+char *
+_ti_get_token(char **cap, char sep)
 {
-       char *token;
-       int esc;
+       char esc, *token;
 
        while (isspace((unsigned char)**cap))
                (*cap)++;
@@ -425,16 +424,21 @@
                return NULL;
 
        /* We can't use stresep(3) as ^ we need two escape chars */
-       esc = 0;
+       esc = '\0';
        for (token = *cap;
-            **cap != '\0' && (esc == 1 || **cap != ',');
+            **cap != '\0' && (esc != '\0' || **cap != sep);
             (*cap)++)
        {
-               if (esc == 0) {
+               if (esc == '\0') {
                        if (**cap == '\\' || **cap == '^')
-                               esc = 1;
-               } else
-                       esc = 0;
+                               esc = **cap;
+               } else {
+                       /* termcap /E/ is valid */
+                       if (sep == ':' && esc == '\\' && **cap == 'E')
+                               esc = 'x';
+                       else
+                               esc = '\0';
+               }
        }
 
        if (**cap != '\0')
@@ -456,7 +460,7 @@
 
        _DIAGASSERT(cap != NULL);       
 
-       name = get_token(&cap);
+       name = _ti_get_token(&cap, ',');
        if (name == NULL) {
                dowarn(flags, "no seperator found: %s", cap);
                return NULL;
@@ -489,9 +493,9 @@
                        goto error;
        }
 
-       for (token = get_token(&cap);
+       for (token = _ti_get_token(&cap, ',');
             token != NULL && *token != '\0';
-            token = get_token(&cap))
+            token = _ti_get_token(&cap, ','))
        {
                /* Skip commented caps */
                if (!(flags & TIC_COMMENT) && token[0] == '.')
diff -r 90216437d10b -r ef0330d3fb10 lib/libterminfo/term_private.h
--- a/lib/libterminfo/term_private.h    Tue Mar 02 13:27:27 2010 +0000
+++ b/lib/libterminfo/term_private.h    Tue Mar 02 14:11:11 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: term_private.h,v 1.6 2010/02/22 23:05:39 roy Exp $ */
+/* $NetBSD: term_private.h,v 1.7 2010/03/02 14:11:11 roy Exp $ */
 
 /*
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -143,6 +143,7 @@
 } TIC;
 
 char *_ti_grow_tbuf(TBUF *, size_t);
+char *_ti_get_token(char **, char);
 char *_ti_find_cap(TBUF *, char,  short);
 char *_ti_find_extra(TBUF *, const char *);
 size_t _ti_store_extra(TIC *, int, char *, char, char, short,
diff -r 90216437d10b -r ef0330d3fb10 lib/libterminfo/termcap.c
--- a/lib/libterminfo/termcap.c Tue Mar 02 13:27:27 2010 +0000
+++ b/lib/libterminfo/termcap.c Tue Mar 02 14:11:11 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: termcap.c,v 1.4 2010/03/01 11:02:31 roy Exp $ */
+/* $NetBSD: termcap.c,v 1.5 2010/03/02 14:11:11 roy Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: termcap.c,v 1.4 2010/03/01 11:02:31 roy Exp $");
+__RCSID("$NetBSD: termcap.c,v 1.5 2010/03/02 14:11:11 roy Exp $");
 
 #include <assert.h>
 #include <ctype.h>
@@ -277,6 +277,16 @@
                }
        }
 
+       /* \E\ is valid termcap.
+        * We need to escape the final \ for terminfo. */
+       if (l > 2 && info[l - 1] == '\\' &&
+           (info[l - 2] != '\\' && info[l - 2] != '^'))
+       {
+               if (l + 1 > len)
+                       goto elen;
+               *ip++ = '\\';
+       }
+
        *ip = '\0';
        return info;
 
@@ -302,10 +312,10 @@
 
        lp = 0;
        tok[2] = '\0';
-       while ((token = strsep(&cap, ":")) != NULL) {
-               /* Trim whitespace */
-               while (isspace((unsigned char)*token))
-                       token++;
+       for (token = _ti_get_token(&cap, ':');
+            token != NULL;
+            token = _ti_get_token(&cap, ':'))
+       {
                if (token[0] == '\0')
                        continue;
                name = token;



Home | Main Index | Thread Index | Old Index