From c833debc98ee98928feaa0895d0a6bc882941107 Mon Sep 17 00:00:00 2001 From: blymn Date: Wed, 19 Apr 2000 13:41:28 +0000 Subject: [PATCH] Added new function t_getterm to return the name string of a termcap entry since the "new" interface hid this information away. --- lib/libterm/shlib_version | 4 ++-- lib/libterm/termcap.3 | 28 ++++++++++++++++++++++-- lib/libterm/termcap.c | 45 +++++++++++++++++++++++++++++++++++++-- lib/libterm/termcap.h | 3 ++- 4 files changed, 73 insertions(+), 7 deletions(-) diff --git a/lib/libterm/shlib_version b/lib/libterm/shlib_version index c4197aefe7c6..2200f8f79cee 100644 --- a/lib/libterm/shlib_version +++ b/lib/libterm/shlib_version @@ -1,5 +1,5 @@ -# $NetBSD: shlib_version,v 1.4 1999/08/16 08:34:33 blymn Exp $ +# $NetBSD: shlib_version,v 1.5 2000/04/19 13:41:28 blymn Exp $ # Remember to update distrib/sets/lists/base/shl.* when changing # major=0 -minor=1 +minor=2 diff --git a/lib/libterm/termcap.3 b/lib/libterm/termcap.3 index 416ecb8a1cfe..ce08363da278 100644 --- a/lib/libterm/termcap.3 +++ b/lib/libterm/termcap.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: termcap.3,v 1.16 1999/10/04 23:16:50 lukem Exp $ +.\" $NetBSD: termcap.3,v 1.17 2000/04/19 13:41:28 blymn Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -74,6 +74,8 @@ .Ft char * .Fn t_getstr "struct tinfo *info" "char *id" "char **area" "size_t *limit" .Ft int +.Fn t_getterm "struct tinfo *info" "char **area" "size_t *limit" +.Ft int .Fn t_goto "struct tinfo *info" "char *id" "int destcol" "int destline" "char *buffer" "size_t limit" .Ft int .Fn t_puts "struct tinfo *info" "char *cp" "int affcnt" "void (*outc)(char, void *)" "void *args" @@ -316,7 +318,29 @@ If t_getstr is called with being NULL then the size required to hold the capability string will be returned in .Fa limit -so the caller can allocate enough storage to hold the capability. +so the caller can allocate enough storage to hold the capability. The +function +.Fn t_getterm +returns a copy of the termcap name string of the termcap entry +associated with +.Fa info +in the buffer pointed to by +.Fa area . +.Fn t_getterm +returns 0 on success and -1 on error. On error errno will be set to +EINVAL if the termcap entry in +.Fa info +is malformed or E2BIG if the size of the name exceeds the size +specified by +.Fa limit . +If +.Fa area +is NULL then the size required to hold the terminal name will be +returned in +.Fa limit +allowing sufficient storage to be allocated. If +.Fa limit +is NULL then no bounds checking will be performed. .Pp The .Fn t_goto diff --git a/lib/libterm/termcap.c b/lib/libterm/termcap.c index 1d8434888dfa..80db4db6314a 100644 --- a/lib/libterm/termcap.c +++ b/lib/libterm/termcap.c @@ -1,4 +1,4 @@ -/* $NetBSD: termcap.c,v 1.23 2000/04/18 14:42:42 blymn Exp $ */ +/* $NetBSD: termcap.c,v 1.24 2000/04/19 13:41:28 blymn Exp $ */ /* * Copyright (c) 1980, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: termcap.c,v 1.23 2000/04/18 14:42:42 blymn Exp $"); +__RCSID("$NetBSD: termcap.c,v 1.24 2000/04/19 13:41:28 blymn Exp $"); #endif #endif /* not lint */ @@ -291,6 +291,10 @@ t_getstr(info, id, area, limit) ids[1] = id[1]; ids[2] = '\0'; + if ((ids[0] == 'Z') && (ids[1] == 'Z')) { + /* return info->info address??? */ + } + if ((i = cgetstr(info->info, ids, &s)) < 0) { errno = ENOENT; return NULL; @@ -348,3 +352,40 @@ t_freent(info) free(info->info); free(info); } + +/* + * Get the terminal name string from the termcap entry. + * + */ +int +t_getterm(struct tinfo *info, char **area, size_t *limit) +{ + char *endp; + size_t count; + + if ((endp = index(info->info, ':')) == NULL) { + errno = EINVAL; + return -1; + } + + + count = endp - info->info + 1; + if (area == NULL) { + *limit = count; + return 0; + } else { + if ((limit != NULL) && (count > *limit)) { + errno = E2BIG; + return -1; + } + + strncpy(*area, info->info, count); + (*area)[count] = '\0'; + if (limit != NULL) + *limit -= count; + } + + return 0; +} + + diff --git a/lib/libterm/termcap.h b/lib/libterm/termcap.h index e3f830a43762..e44a3455877f 100644 --- a/lib/libterm/termcap.h +++ b/lib/libterm/termcap.h @@ -1,4 +1,4 @@ -/* $NetBSD: termcap.h,v 1.9 2000/02/20 13:32:52 kleink Exp $ */ +/* $NetBSD: termcap.h,v 1.10 2000/04/19 13:41:29 blymn Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -60,6 +60,7 @@ int t_getent __P((struct tinfo **, const char *)); int t_getnum __P((struct tinfo *, const char *)); int t_getflag __P((struct tinfo *, const char *)); char *t_getstr __P((struct tinfo *, const char *, char **, size_t *)); +int t_getterm(struct tinfo *info, char **area, size_t *limit); int t_goto __P((struct tinfo *, const char *, int, int, char *, size_t)); int t_puts __P((struct tinfo *, const char *, int, void (*)(char, void *), void *));