* Removed variable names from ansi style prototype
* Add -I. to CPPFLAGS * Added new function t_agetstr which dynamically allocates area buffer.
This commit is contained in:
parent
9f7a44710e
commit
22a94f7041
|
@ -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
|
# @(#)Makefile 8.1 (Berkeley) 6/4/93
|
||||||
|
|
||||||
LIB= termcap
|
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
|
SRCS= termcap.c tgoto.c tputs.c
|
||||||
|
|
||||||
MAN= termcap.3
|
MAN= termcap.3
|
||||||
|
|
|
@ -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
|
# Remember to update distrib/sets/lists/base/shl.* when changing
|
||||||
#
|
#
|
||||||
major=0
|
major=0
|
||||||
minor=2
|
minor=3
|
||||||
|
|
|
@ -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
|
.\" Copyright (c) 1980, 1991, 1993
|
||||||
.\" The Regents of the University of California. All rights reserved.
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
@ -73,6 +73,8 @@
|
||||||
.Fn t_getflag "struct tinfo *info" "char *id"
|
.Fn t_getflag "struct tinfo *info" "char *id"
|
||||||
.Ft char *
|
.Ft char *
|
||||||
.Fn t_getstr "struct tinfo *info" "char *id" "char **area" "size_t *limit"
|
.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
|
.Ft int
|
||||||
.Fn t_getterm "struct tinfo *info" "char **area" "size_t *limit"
|
.Fn t_getterm "struct tinfo *info" "char **area" "size_t *limit"
|
||||||
.Ft int
|
.Ft int
|
||||||
|
@ -293,7 +295,59 @@ When the information pointed to by
|
||||||
is no longer required any storage associated with the object can be
|
is no longer required any storage associated with the object can be
|
||||||
released by calling
|
released by calling
|
||||||
.Fn t_freent .
|
.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
|
.Fn t_getnum
|
||||||
and
|
and
|
||||||
.Fn t_getflag
|
.Fn t_getflag
|
||||||
|
|
|
@ -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
|
* Copyright (c) 1980, 1993
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93";
|
static char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93";
|
||||||
#else
|
#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
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
|
@ -375,6 +375,53 @@ tgetstr(id, area)
|
||||||
return t_getstr(fbuf, ids, area, NULL);
|
return t_getstr(fbuf, ids, area, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
* Free the buffer allocated by t_getent
|
||||||
*
|
*
|
||||||
|
|
|
@ -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
|
* Copyright (c) 1992, 1993
|
||||||
|
@ -60,7 +60,8 @@ int t_getent __P((struct tinfo **, const char *));
|
||||||
int t_getnum __P((struct tinfo *, const char *));
|
int t_getnum __P((struct tinfo *, const char *));
|
||||||
int t_getflag __P((struct tinfo *, const char *));
|
int t_getflag __P((struct tinfo *, const char *));
|
||||||
char *t_getstr __P((struct tinfo *, const char *, char **, size_t *));
|
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_goto __P((struct tinfo *, const char *, int, int, char *, size_t));
|
||||||
int t_puts __P((struct tinfo *, const char *, int,
|
int t_puts __P((struct tinfo *, const char *, int,
|
||||||
void (*)(char, void *), void *));
|
void (*)(char, void *), void *));
|
||||||
|
|
Loading…
Reference in New Issue