Provide a disabled implentation of tlparm and ti_tlparm for completeness.

This also improves the readability of _ti_tiparm.
This commit is contained in:
roy 2013-01-25 17:28:50 +00:00
parent e7c4a82c5a
commit 40e555b80b
3 changed files with 63 additions and 23 deletions

View File

@ -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 ti_puts(const TERMINAL *, const char *, int,
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

View File

@ -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 @@ always goes to stdout.
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_*

View File

@ -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 @@ __RCSID("$NetBSD: tparm.c,v 1.13 2013/01/25 12:30:05 roy Exp $");
#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 @@ _ti_parm_analyse(const char *str, int *piss, int piss_len)
}
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 @@ _ti_tiparm(TERMINAL *term, const char *str, int va_long, va_list parms)
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 @@ _ti_tiparm(TERMINAL *term, const char *str, int va_long, va_list parms)
} else
params[l].string = va_arg(parms, char *);
} else {
if (va_long)
params[l].num = va_arg(parms, long);
else
if (va_type == VA_CHAR_INT)
params[l].num = (long)va_arg(parms, int);
else
params[l].num = va_arg(parms, long);
}
}
@ -548,7 +552,7 @@ ti_tiparm(TERMINAL *term, const char *str, ...)
_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 @@ tiparm(const char *str, ...)
_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 @@ tlparm(const char *str, ...)
_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 @@ tparm(const char *str,
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);
}