Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libterm * Removed variable names from ansi style prototype
details: https://anonhg.NetBSD.org/src/rev/61111b4767d4
branches: trunk
changeset: 486373:61111b4767d4
user: blymn <blymn%NetBSD.org@localhost>
date: Sat May 20 13:55:10 2000 +0000
description:
* Removed variable names from ansi style prototype
* Add -I. to CPPFLAGS
* Added new function t_agetstr which dynamically allocates area buffer.
diffstat:
lib/libterm/Makefile | 4 +-
lib/libterm/shlib_version | 4 +-
lib/libterm/termcap.3 | 58 +++++++++++++++++++++++++++++++++++++++++++++-
lib/libterm/termcap.c | 51 +++++++++++++++++++++++++++++++++++++++-
lib/libterm/termcap.h | 5 ++-
5 files changed, 112 insertions(+), 10 deletions(-)
diffs (195 lines):
diff -r 07f290cfa9d3 -r 61111b4767d4 lib/libterm/Makefile
--- a/lib/libterm/Makefile Sat May 20 13:41:33 2000 +0000
+++ b/lib/libterm/Makefile Sat May 20 13:55:10 2000 +0000
@@ -1,8 +1,8 @@
-# $NetBSD: Makefile,v 1.21 1999/08/15 10:59:01 blymn Exp $
+# $NetBSD: Makefile,v 1.22 2000/05/20 13:55:10 blymn Exp $
# @(#)Makefile 8.1 (Berkeley) 6/4/93
LIB= termcap
-CPPFLAGS+=-DCM_N -DCM_GT -DCM_B -DCM_D
+CPPFLAGS+=-I. -DCM_N -DCM_GT -DCM_B -DCM_D
SRCS= termcap.c tgoto.c tputs.c
MAN= termcap.3
diff -r 07f290cfa9d3 -r 61111b4767d4 lib/libterm/shlib_version
--- a/lib/libterm/shlib_version Sat May 20 13:41:33 2000 +0000
+++ b/lib/libterm/shlib_version Sat May 20 13:55:10 2000 +0000
@@ -1,5 +1,5 @@
-# $NetBSD: shlib_version,v 1.5 2000/04/19 13:41:28 blymn Exp $
+# $NetBSD: shlib_version,v 1.6 2000/05/20 13:55:10 blymn Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=0
-minor=2
+minor=3
diff -r 07f290cfa9d3 -r 61111b4767d4 lib/libterm/termcap.3
--- a/lib/libterm/termcap.3 Sat May 20 13:41:33 2000 +0000
+++ b/lib/libterm/termcap.3 Sat May 20 13:55:10 2000 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: termcap.3,v 1.18 2000/05/10 11:13:35 blymn Exp $
+.\" $NetBSD: termcap.3,v 1.19 2000/05/20 13:55:10 blymn Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -73,6 +73,8 @@
.Fn t_getflag "struct tinfo *info" "char *id"
.Ft char *
.Fn t_getstr "struct tinfo *info" "char *id" "char **area" "size_t *limit"
+.Ft char *
+.Fn t_agetstr "struct tinfo *info" "char *id" "char **buffer" "char **area"
.Ft int
.Fn t_getterm "struct tinfo *info" "char **area" "size_t *limit"
.Ft int
@@ -293,7 +295,59 @@
is no longer required any storage associated with the object can be
released by calling
.Fn t_freent .
-The functions
+The function
+.Fn t_agetstr
+performs the same function as
+.Fn t_getstr
+except sufficient memory is first allocated to hold the desired string
+argument before adding it to the buffer. To initialise the buffer for
+.Fn t_agetstr
+the first call must be done with the contents of
+.Fa buffer
+set to NULL. Subsequent calls to
+.Fn t_agetstr
+can pass
+.Fa buffer
+and
+.Fa area
+in unmodified and the requested string argument will be appended to
+the buffer after sufficient memory has been allocated. Modifying either
+.Fa buffer
+or
+.Fa area
+between calls to
+.Fn t_agetstr
+will certainly lead to the function misbehaving. When the storage
+allocated by
+.Fn t_agetstr
+is no longer required it can be freed by passing the pointer contained
+in
+.Fa buffer
+to
+.Fn free .
+If an error occurs within
+.Fn t_agetstr
+a NULL will be returned and
+.Fa buffer
+and
+.Fa area
+will remain unmodified.
+.Em NOTE
+.Fn t_agetstr
+uses
+.Fn realloc
+to reallocate the buffer memory so saving a copy of either
+.Fa buffer
+or
+.Fa area
+for use after subsequent calls to
+.Fn t_agetstr
+is likely to fail. It is best to keep offsets from
+.Fa buffer
+to the desired string and calculate pointer addresses only after all
+the calls to
+.Fn t_agetstr
+have been done. The functions
.Fn t_getnum
and
.Fn t_getflag
diff -r 07f290cfa9d3 -r 61111b4767d4 lib/libterm/termcap.c
--- a/lib/libterm/termcap.c Sat May 20 13:41:33 2000 +0000
+++ b/lib/libterm/termcap.c Sat May 20 13:55:10 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: termcap.c,v 1.29 2000/05/14 01:14:29 lukem Exp $ */
+/* $NetBSD: termcap.c,v 1.30 2000/05/20 13:55:10 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.29 2000/05/14 01:14:29 lukem Exp $");
+__RCSID("$NetBSD: termcap.c,v 1.30 2000/05/20 13:55:10 blymn Exp $");
#endif
#endif /* not lint */
@@ -376,6 +376,53 @@
}
/*
+ * Get a string valued option specified by id and append it to the
+ * given buffer. If bufptr is NULL then a new buffer is allocated, if
+ * bufptr is non-NULL then extend the memory allocation to allow the
+ * new string to be appended to the buffer. The pointer area is
+ * updated to point to the start of the new entry and this address is
+ * also returned to the caller. If the string is not found or a
+ * memory allocation fails then NULL is returned and bufptr and area
+ * are unchanged.
+ */
+char *
+t_agetstr(struct tinfo *info, const char *id, char **bufptr, char **area)
+{
+ size_t new_size, offset;
+ char *new_buf;
+
+ _DIAGASSERT(info != NULL);
+ _DIAGASSERT(id != NULL);
+ _DIAGASSERT(bufptr != NULL);
+ _DIAGASSERT(area != NULL);
+ _DIAGASSERT(size != NULL);
+
+ t_getstr(info, id, NULL, &new_size);
+
+ /* either the string is empty or the capability does not exist. */
+ if (new_size == 0)
+ return NULL;
+
+ /* check if we have a buffer, if not malloc one and fill it in. */
+ if (*bufptr == NULL) {
+ if ((new_buf = (char *) malloc(new_size)) == NULL)
+ return NULL;
+ *bufptr = new_buf;
+ *area = new_buf;
+ } else {
+ offset = *area - *bufptr;
+ if ((new_buf = realloc(*bufptr, offset + new_size)) == NULL)
+ return NULL;
+
+ *bufptr = new_buf;
+ *area = *bufptr + offset; /* we need to do this just in case
+ realloc shifted the buffer. */
+ }
+
+ return t_getstr(info, id, area, NULL);
+}
+
+/*
* Free the buffer allocated by t_getent
*
*/
diff -r 07f290cfa9d3 -r 61111b4767d4 lib/libterm/termcap.h
--- a/lib/libterm/termcap.h Sat May 20 13:41:33 2000 +0000
+++ b/lib/libterm/termcap.h Sat May 20 13:55:10 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: termcap.h,v 1.10 2000/04/19 13:41:29 blymn Exp $ */
+/* $NetBSD: termcap.h,v 1.11 2000/05/20 13:55:11 blymn Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -60,7 +60,8 @@
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);
+char *t_agetstr(struct tinfo *, const char *, char **, char **);
+int t_getterm(struct tinfo *, char **, size_t *);
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