Source-Changes-HG archive

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

[src/trunk]: src/lib/libterm Added new function t_getterm to return the name ...



details:   https://anonhg.NetBSD.org/src/rev/9af17f434404
branches:  trunk
changeset: 485116:9af17f434404
user:      blymn <blymn%NetBSD.org@localhost>
date:      Wed Apr 19 13:41:28 2000 +0000

description:
Added new function t_getterm to return the name string of a termcap
entry since the "new" interface hid this information away.

diffstat:

 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(-)

diffs (147 lines):

diff -r ca85a17a208e -r 9af17f434404 lib/libterm/shlib_version
--- a/lib/libterm/shlib_version Wed Apr 19 09:42:24 2000 +0000
+++ b/lib/libterm/shlib_version Wed Apr 19 13:41:28 2000 +0000
@@ -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 -r ca85a17a208e -r 9af17f434404 lib/libterm/termcap.3
--- a/lib/libterm/termcap.3     Wed Apr 19 09:42:24 2000 +0000
+++ b/lib/libterm/termcap.3     Wed Apr 19 13:41:28 2000 +0000
@@ -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 @@
 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 -r ca85a17a208e -r 9af17f434404 lib/libterm/termcap.c
--- a/lib/libterm/termcap.c     Wed Apr 19 09:42:24 2000 +0000
+++ b/lib/libterm/termcap.c     Wed Apr 19 13:41:28 2000 +0000
@@ -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 @@
        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 @@
        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 -r ca85a17a208e -r 9af17f434404 lib/libterm/termcap.h
--- a/lib/libterm/termcap.h     Wed Apr 19 09:42:24 2000 +0000
+++ b/lib/libterm/termcap.h     Wed Apr 19 13:41:28 2000 +0000
@@ -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_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 *));



Home | Main Index | Thread Index | Old Index