summaryrefslogtreecommitdiff
path: root/lib/libterm
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2005-05-15 21:10:52 +0000
committerchristos <christos@NetBSD.org>2005-05-15 21:10:52 +0000
commitcf3e6ebd2b16e830ce179dec2805d21165b934bf (patch)
tree1b1ff6ceda12bcf1ba2ae66108d1bda4605c121f /lib/libterm
parentf2b0a44663b3af0b146273553b9ff9276e244e57 (diff)
add t_putws
Diffstat (limited to 'lib/libterm')
-rw-r--r--lib/libterm/Makefile6
-rw-r--r--lib/libterm/shlib_version4
-rw-r--r--lib/libterm/termcap.312
-rw-r--r--lib/libterm/termcap_private.h4
-rw-r--r--lib/libterm/tputs.c18
-rw-r--r--lib/libterm/tputws.c163
6 files changed, 189 insertions, 18 deletions
diff --git a/lib/libterm/Makefile b/lib/libterm/Makefile
index a40e4a5913d..84c6a064c81 100644
--- a/lib/libterm/Makefile
+++ b/lib/libterm/Makefile
@@ -1,18 +1,18 @@
-# $NetBSD: Makefile,v 1.28 2002/09/27 21:37:54 thorpej Exp $
+# $NetBSD: Makefile,v 1.29 2005/05/15 21:11:13 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 6/4/93
USE_SHLIBDIR= yes
LIB= termcap
CPPFLAGS+=-I${.CURDIR} -DCM_N -DCM_GT -DCM_B -DCM_D
-SRCS= termcap.c tgoto.c tputs.c
+SRCS= termcap.c tgoto.c tputs.c tputws.c
MAN= termcap.3
MLINKS= termcap.3 tgetent.3 termcap.3 tgetflag.3 termcap.3 tgetnum.3 \
termcap.3 tgetstr.3 termcap.3 tgoto.3 termcap.3 tputs.3 \
termcap.3 t_getent.3 termcap.3 t_getflag.3 termcap.3 t_getnum.3 \
termcap.3 t_getstr.3 termcap.3 t_goto.3 termcap.3 t_puts.3 \
- termcap.3 t_freent.3
+ termcap.3 t_freent.3 termcap.3 t_putws.3
INCS= termcap.h
INCSDIR=/usr/include
diff --git a/lib/libterm/shlib_version b/lib/libterm/shlib_version
index cb6511197da..9d5be4c2ba7 100644
--- a/lib/libterm/shlib_version
+++ b/lib/libterm/shlib_version
@@ -1,5 +1,5 @@
-# $NetBSD: shlib_version,v 1.8 2001/11/02 18:24:38 christos Exp $
+# $NetBSD: shlib_version,v 1.9 2005/05/15 21:11:13 christos Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=0
-minor=5
+minor=6
diff --git a/lib/libterm/termcap.3 b/lib/libterm/termcap.3
index 8f097c8cf5f..ae0818e3b19 100644
--- a/lib/libterm/termcap.3
+++ b/lib/libterm/termcap.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: termcap.3,v 1.30 2004/04/23 02:58:27 simonb Exp $
+.\" $NetBSD: termcap.3,v 1.31 2005/05/15 21:11:13 christos Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)termcap.3 8.2 (Berkeley) 12/11/93
.\"
-.Dd September 30, 1999
+.Dd May 15, 2005
.Dt TERMCAP 3
.Os
.Sh NAME
@@ -81,6 +81,9 @@
.Fn t_freent "struct tinfo *info"
.Ft int
.Fn t_setinfo "struct tinfo **info" "const char *entry"
+.In wchar.h
+.Ft int
+.Fn t_putws "struct tinfo *info" "const wchar_t *cp" "int affcnt" "void (*outc)(wchar_t, void *)" "void *args"
.Sh DESCRIPTION
These functions extract and use capabilities from a terminal capability data
base, usually
@@ -417,6 +420,11 @@ holds a pointer to the termcap object that was returned by a previous
call, this object will be used to retrieve the
.Sy pc
attribute for the terminal.
+The function
+.Fn t_putws
+is similar to
+.Fn t_puts
+but it operates on a string of wide characters.
The
.Fa outc
function is a pointer to a function that will be called by
diff --git a/lib/libterm/termcap_private.h b/lib/libterm/termcap_private.h
index 85ee84f1756..4d2e256f5e7 100644
--- a/lib/libterm/termcap_private.h
+++ b/lib/libterm/termcap_private.h
@@ -1,4 +1,4 @@
-/* $NetBSD: termcap_private.h,v 1.4 2001/11/02 18:24:20 christos Exp $ */
+/* $NetBSD: termcap_private.h,v 1.5 2005/05/15 21:11:13 christos Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn
@@ -44,3 +44,5 @@ struct tinfo
char *eptr; /* pointer to the end of buffer */
} *tbuf;
};
+#define TMSPC10SIZE 15
+extern const short __tmspc10[TMSPC10SIZE];
diff --git a/lib/libterm/tputs.c b/lib/libterm/tputs.c
index f2cb55a991a..6068ea1c8e3 100644
--- a/lib/libterm/tputs.c
+++ b/lib/libterm/tputs.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tputs.c,v 1.22 2005/02/04 15:52:08 perry Exp $ */
+/* $NetBSD: tputs.c,v 1.23 2005/05/15 21:11:13 christos Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)tputs.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: tputs.c,v 1.22 2005/02/04 15:52:08 perry Exp $");
+__RCSID("$NetBSD: tputs.c,v 1.23 2005/05/15 21:11:13 christos Exp $");
#endif
#endif /* not lint */
@@ -43,6 +43,7 @@ __RCSID("$NetBSD: tputs.c,v 1.22 2005/02/04 15:52:08 perry Exp $");
#include <termcap.h>
#include <stdio.h>
#include <stdlib.h>
+#include "termcap_private.h"
#undef ospeed
/* internal functions */
@@ -53,8 +54,7 @@ int _tputs_convert(const char **, int);
* character for each speed as returned by gtty. Thus since 300
* baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
*/
-static const
-short tmspc10[] = {
+const short __tmspc10[TMSPC10SIZE] = {
0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5
};
@@ -130,8 +130,7 @@ tputs(const char *cp, int affcnt, int (*outc)(int))
*/
if (i == 0)
return;
- if (ospeed <= 0 ||
- (size_t) ospeed >= (sizeof tmspc10 / sizeof tmspc10[0]))
+ if (ospeed <= 0 || ospeed >= TMSPC10SIZE)
return;
/*
@@ -141,7 +140,7 @@ tputs(const char *cp, int affcnt, int (*outc)(int))
* Transmitting pad characters slows many
* terminals down and also loads the system.
*/
- mspc10 = tmspc10[ospeed];
+ mspc10 = __tmspc10[ospeed];
i += mspc10 / 2;
for (i /= mspc10; i > 0; i--)
(void)(*outc)(PC);
@@ -196,8 +195,7 @@ t_puts(struct tinfo *info, const char *cp, int affcnt,
*/
if (i == 0)
return 0;
- if (ospeed <= 0 ||
- (size_t) ospeed >= (sizeof tmspc10 / sizeof tmspc10[0]))
+ if (ospeed <= 0 || ospeed >= TMSPC10SIZE)
return 0;
/*
@@ -207,7 +205,7 @@ t_puts(struct tinfo *info, const char *cp, int affcnt,
* Transmitting pad characters slows many
* terminals down and also loads the system.
*/
- mspc10 = tmspc10[ospeed];
+ mspc10 = __tmspc10[ospeed];
i += mspc10 / 2;
for (i /= mspc10; i > 0; i--)
(*outc)(pad[0], args);
diff --git a/lib/libterm/tputws.c b/lib/libterm/tputws.c
new file mode 100644
index 00000000000..6d5f091b013
--- /dev/null
+++ b/lib/libterm/tputws.c
@@ -0,0 +1,163 @@
+/* $NetBSD: tputws.c,v 1.1 2005/05/15 21:11:13 christos Exp $ */
+
+/*
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)tputs.c 8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: tputws.c,v 1.1 2005/05/15 21:11:13 christos Exp $");
+#endif
+#endif /* not lint */
+
+#include <assert.h>
+#include <wctype.h>
+#include <wchar.h>
+#include <termcap.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "termcap_private.h"
+#undef ospeed
+
+/* internal functions */
+int _tputws_convert(const wchar_t **, int);
+
+/*
+ * The following array gives the number of tens of milliseconds per
+ * character for each speed as returned by gtty. Thus since 300
+ * baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
+ */
+extern short ospeed;
+extern char PC;
+
+int
+_tputws_convert(const wchar_t **ptr, int affcnt)
+{
+ int i = 0;
+
+ _DIAGASSERT(ptr != NULL);
+ _DIAGASSERT(*ptr != NULL);
+
+ /*
+ * Convert the number representing the delay.
+ */
+ if (iswdigit(**ptr)) {
+ do
+ i = i * 10 + *(*ptr)++ - '0';
+ while (iswdigit(**ptr));
+ }
+ i *= 10;
+ if (*(*ptr) == '.') {
+ (*ptr)++;
+ if (iswdigit(**ptr))
+ i += *(*ptr) - '0';
+ /*
+ * Only one digit to the right of the decimal point.
+ */
+ while (iswdigit(**ptr))
+ (*ptr)++;
+ }
+
+ /*
+ * If the delay is followed by a `*', then
+ * multiply by the affected lines count.
+ */
+ if (*(*ptr) == '*')
+ (*ptr)++, i *= affcnt;
+
+ return i;
+}
+
+int
+t_putws(struct tinfo *info, const wchar_t *cp, int affcnt,
+ void (*outc)(wchar_t, void *), void *args)
+{
+ int i = 0;
+ size_t limit;
+ int mspc10;
+ char pad[2], *pptr;
+ char *pc;
+
+ /* XXX: info may be NULL ? */
+ /* cp is handled below */
+ _DIAGASSERT(outc != NULL);
+ _DIAGASSERT(args != NULL);
+
+ if (info != NULL) {
+ /*
+ * if we have info then get the pad char from the
+ * termcap entry if it exists, otherwise use the
+ * default NUL char.
+ */
+ pptr = pad;
+ limit = sizeof(pad);
+ pc = t_getstr(info, "pc", &pptr, &limit);
+ if (pc == NULL)
+ pad[0] = '\0';
+ else
+ free(pc);
+ }
+
+ if (cp == 0)
+ return -1;
+
+ /* scan and convert delay digits (if any) */
+ i = _tputws_convert(&cp, affcnt);
+
+ /*
+ * The guts of the string.
+ */
+ while (*cp)
+ (*outc)(*cp++, args);
+
+ /*
+ * If no delay needed, or output speed is
+ * not comprehensible, then don't try to delay.
+ */
+ if (i == 0)
+ return 0;
+ if (ospeed <= 0 || ospeed >= TMSPC10SIZE)
+ return 0;
+
+ /*
+ * Round up by a half a character frame,
+ * and then do the delay.
+ * Too bad there are no user program accessible programmed delays.
+ * Transmitting pad characters slows many
+ * terminals down and also loads the system.
+ */
+ mspc10 = __tmspc10[ospeed];
+ i += mspc10 / 2;
+ for (i /= mspc10; i > 0; i--)
+ (*outc)(pad[0], args);
+
+ return 0;
+}