Source-Changes-HG archive

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

[src/trunk]: src/lib/libterminfo Provide a disabled implentation of tlparm an...



details:   https://anonhg.NetBSD.org/src/rev/1b93e51dc1ff
branches:  trunk
changeset: 784331:1b93e51dc1ff
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Jan 25 17:28:50 2013 +0000

description:
Provide a disabled implentation of tlparm and ti_tlparm for completeness.
This also improves the readability of _ti_tiparm.

diffstat:

 lib/libterminfo/term.h     |  12 +++++++-
 lib/libterminfo/terminfo.3 |  11 ++++---
 lib/libterminfo/tparm.c    |  63 ++++++++++++++++++++++++++++++++++-----------
 3 files changed, 63 insertions(+), 23 deletions(-)

diffs (193 lines):

diff -r 9a5f1c332e22 -r 1b93e51dc1ff lib/libterminfo/term.h
--- a/lib/libterminfo/term.h    Fri Jan 25 17:12:33 2013 +0000
+++ b/lib/libterminfo/term.h    Fri Jan 25 17:28:50 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: term.h,v 1.13 2013/01/25 12:52:45 roy Exp $ */
+/* $NetBSD: term.h,v 1.14 2013/01/25 17:28:50 roy Exp $ */
 
 /*
  * Copyright (c) 2009, 2010, 2011, 2013 The NetBSD Foundation, Inc.
@@ -1974,12 +1974,20 @@
     int (*)(int, void *), void *);
 int            ti_putp(const TERMINAL *, const char *);
 
-/* Using tparm can be kunkly, so provide a variadic function */
+/* Using tparm can be kunkly, so provide a variadic function
+ * Numbers have to be passed as int */
 /* This is not standard, but ncurses also provides this */
 char *         tiparm(const char *, ...);
 /* And a thread safe version */
 char *         ti_tiparm(TERMINAL *, const char *, ...);
 
+#ifdef TPARM_TLPARM
+/* Same as the above, but numbers have to be passed as long */
+char *         tlparm(const char *, ...);
+/* And a thread safe version */
+char *         ti_tlparm(TERMINAL *, const char *, ...);
+#endif
+
 /* Default to X/Open tparm, but allow it to be variadic also */
 #ifdef TPARM_VARARGS
 #  define tparm        tiparm
diff -r 9a5f1c332e22 -r 1b93e51dc1ff lib/libterminfo/terminfo.3
--- a/lib/libterminfo/terminfo.3        Fri Jan 25 17:12:33 2013 +0000
+++ b/lib/libterminfo/terminfo.3        Fri Jan 25 17:28:50 2013 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: terminfo.3,v 1.9 2013/01/25 12:30:05 roy Exp $
+.\"    $NetBSD: terminfo.3,v 1.10 2013/01/25 17:28:50 roy Exp $
 .\"
 .\" Copyright (c) 2009, 2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -219,11 +219,12 @@
 The
 .Fn tiparm
 function allows variadic parameters instead of 9 fixed longs.
-Numeric parameters must be integers (int) instead of longs.
-String parameters can be used even if the platform cannot fit a
+Numeric parameters must be passed as
+.Vt int .
+String parameters must be passed as
 .Vt char *
-into a
-.Vt long .
+and works on all platforms, unlike
+.Fn tparm .
 .Pp
 The
 .Fn ti_*
diff -r 9a5f1c332e22 -r 1b93e51dc1ff lib/libterminfo/tparm.c
--- a/lib/libterminfo/tparm.c   Fri Jan 25 17:12:33 2013 +0000
+++ b/lib/libterminfo/tparm.c   Fri Jan 25 17:28:50 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tparm.c,v 1.13 2013/01/25 12:30:05 roy Exp $ */
+/* $NetBSD: tparm.c,v 1.14 2013/01/25 17:28:50 roy Exp $ */
 
 /*
  * Copyright (c) 2009, 2011, 2013 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: tparm.c,v 1.13 2013/01/25 12:30:05 roy Exp $");
+__RCSID("$NetBSD: tparm.c,v 1.14 2013/01/25 17:28:50 roy Exp $");
 #include <sys/param.h>
 
 #include <assert.h>
@@ -44,6 +44,10 @@
 #define LONG_STR_MAX ((CHAR_BIT * sizeof(long)) / 3)
 #define BUFINC 128     /* Size to increament the terminal buffer by */
 
+#define VA_LONG_LONG   1 
+#define VA_CHAR_INT    2
+//#define VA_CHAR_LONG 3
+
 static TERMINAL *dumbterm; /* For non thread safe functions */
 
 typedef struct {
@@ -178,7 +182,7 @@
 }
 
 static char *
-_ti_tiparm(TERMINAL *term, const char *str, int va_long, va_list parms)
+_ti_tiparm(TERMINAL *term, const char *str, int va_type, va_list parms)
 {
        char c, fmt[64], *fp, *ostr;
        long val, val2;
@@ -224,7 +228,7 @@
        memset(&params, 0, sizeof(params));
        for (l = 0; l < max; l++) {
                if (piss[l]) {
-                       if (va_long) {
+                       if (va_type == VA_LONG_LONG) {
                                /* This only works if char * fits into a long
                                 * on this platform. */
                                if (sizeof(char *) <= sizeof(long)/*CONSTCOND*/)
@@ -237,10 +241,10 @@
                        } else
                                params[l].string = va_arg(parms, char *);
                } else {
-                       if (va_long)
+                       if (va_type == VA_CHAR_INT)
+                               params[l].num = (long)va_arg(parms, int);
+                       else
                                params[l].num = va_arg(parms, long);
-                       else
-                               params[l].num = (long)va_arg(parms, int);
                }
        }
 
@@ -548,7 +552,7 @@
        _DIAGASSERT(str != NULL);
 
        va_start(va, str);
-       ret = _ti_tiparm(term, str, 0, va);
+       ret = _ti_tiparm(term, str, VA_CHAR_INT, va);
        va_end(va);
        return ret;
 }
@@ -562,16 +566,28 @@
        _DIAGASSERT(str != NULL);
 
        va_start(va, str);
-       ret = _ti_tiparm(NULL, str, 0, va);
+       ret = _ti_tiparm(NULL, str, VA_CHAR_INT, va);
        va_end(va);
        return ret;
 }
 
-/* Same as tiparm, but accepts long instead of int for the numeric params.
- * Currently there is no need for this to be a public interface and is only
- * consumed by tparm. If we need this to be public, and I really cannot
- * imagine why, then we would need ti_tlparm() as well. */
-static char *
+#ifdef VA_CHAR_LONG
+char *
+ti_tlparm(TERMINAL *term, const char *str, ...)
+{
+       va_list va;
+       char *ret;
+
+       _DIAGASSERT(term != NULL);
+       _DIAGASSERT(str != NULL);
+
+       va_start(va, str);
+       ret = _ti_tiparm(term, str, VA_CHAR_LONG, va);
+       va_end(va);
+       return ret;
+}
+
+char *
 tlparm(const char *str, ...)
 {
        va_list va;
@@ -580,7 +596,22 @@
        _DIAGASSERT(str != NULL);
 
        va_start(va, str);
-       ret = _ti_tiparm(NULL, str, 1, va);
+       ret = _ti_tiparm(NULL, str, VA_CHAR_LONG, va);
+       va_end(va);
+       return ret;
+}
+#endif
+
+static char *
+_tparm(const char *str, ...)
+{
+       va_list va;
+       char *ret;
+       
+       _DIAGASSERT(str != NULL);
+
+       va_start(va, str);
+       ret = _ti_tiparm(NULL, str, VA_LONG_LONG, va);
        va_end(va);
        return ret;
 }
@@ -591,5 +622,5 @@
     long p6, long p7, long p8, long p9)
 {
 
-       return tlparm(str, p1, p2, p3, p4, p5, p6, p7, p8, p9);
+       return _tparm(str, p1, p2, p3, p4, p5, p6, p7, p8, p9);
 }



Home | Main Index | Thread Index | Old Index