Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libterm * Improve the handling of BC and UP in t_goto, t...
details: https://anonhg.NetBSD.org/src/rev/8161f9919b89
branches: trunk
changeset: 487122:8161f9919b89
user: blymn <blymn%NetBSD.org@localhost>
date: Sat Jun 03 07:14:55 2000 +0000
description:
* Improve the handling of BC and UP in t_goto, t_getent now queries
these capabilities and stashes them in "struct tinfo" for t_goto to
use. This makes the t_goto call more efficient and plugs a memory
leak that was present in the original t_goto implementation.
Thanks to Itojun for spotting this one too!
diffstat:
lib/libterm/termcap.c | 36 ++++++++++++++++++++++++++++++++++--
lib/libterm/termcap_private.h | 4 +++-
lib/libterm/tgoto.c | 37 +++++++++----------------------------
3 files changed, 46 insertions(+), 31 deletions(-)
diffs (195 lines):
diff -r cbee1f4c2419 -r 8161f9919b89 lib/libterm/termcap.c
--- a/lib/libterm/termcap.c Sat Jun 03 07:10:31 2000 +0000
+++ b/lib/libterm/termcap.c Sat Jun 03 07:14:55 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: termcap.c,v 1.35 2000/06/02 22:09:01 thorpej Exp $ */
+/* $NetBSD: termcap.c,v 1.36 2000/06/03 07:14:55 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.35 2000/06/02 22:09:01 thorpej Exp $");
+__RCSID("$NetBSD: termcap.c,v 1.36 2000/06/03 07:14:55 blymn Exp $");
#endif
#endif /* not lint */
@@ -81,6 +81,9 @@
int
t_setinfo(struct tinfo **bp, const char *entry)
{
+ char capability[256], *cap_ptr;
+ size_t limit;
+
if ((*bp = malloc(sizeof(struct tinfo))) == NULL)
return -1;
@@ -88,6 +91,14 @@
return -1;
strcpy((*bp)->info, entry);
+
+ cap_ptr = capability;
+ limit = 255;
+ (*bp)->up = t_getstr(*bp, "up", &cap_ptr, &limit);
+ cap_ptr = capability;
+ limit = 255;
+ (*bp)->bc = t_getstr(*bp, "bc", &cap_ptr, &limit);
+
return 0;
}
@@ -107,9 +118,12 @@
char **fname;
char *home;
int i, did_getset;
+ size_t limit;
char pathbuf[PBUFSIZ]; /* holds raw path of filenames */
char *pathvec[PVECSIZ]; /* to point to names in pathbuf */
char *termpath;
+ char capability[256], *cap_ptr;
+
_DIAGASSERT(bp != NULL);
_DIAGASSERT(name != NULL);
@@ -205,6 +219,20 @@
/* no tc reference loop return code in libterm XXX */
if (i == -3)
return (-1);
+
+ /* fill in t_goto capabilities - this prevents memory leaks
+ * and is more efficient than fetching these capabilities
+ * every time t_goto is called.
+ */
+ if (i >= 0) {
+ cap_ptr = capability;
+ limit = 255;
+ (*bp)->up = t_getstr(*bp, "up", &cap_ptr, &limit);
+ cap_ptr = capability;
+ limit = 255;
+ (*bp)->bc = t_getstr(*bp, "bc", &cap_ptr, &limit);
+ }
+
return (i + 1);
}
@@ -454,6 +482,10 @@
{
_DIAGASSERT(info != NULL);
free(info->info);
+ if (info->up != NULL)
+ free(info->up);
+ if (info->bc != NULL)
+ free(info->bc);
free(info);
}
diff -r cbee1f4c2419 -r 8161f9919b89 lib/libterm/termcap_private.h
--- a/lib/libterm/termcap_private.h Sat Jun 03 07:10:31 2000 +0000
+++ b/lib/libterm/termcap_private.h Sat Jun 03 07:14:55 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: termcap_private.h,v 1.1 2000/04/18 14:42:42 blymn Exp $ */
+/* $NetBSD: termcap_private.h,v 1.2 2000/06/03 07:14:55 blymn Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn
@@ -35,6 +35,8 @@
struct tinfo
{
char *info;
+ char *up; /* for use by tgoto */
+ char *bc; /* for use by tgoto */
};
diff -r cbee1f4c2419 -r 8161f9919b89 lib/libterm/tgoto.c
--- a/lib/libterm/tgoto.c Sat Jun 03 07:10:31 2000 +0000
+++ b/lib/libterm/tgoto.c Sat Jun 03 07:14:55 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tgoto.c,v 1.16 2000/06/02 13:13:12 itojun Exp $ */
+/* $NetBSD: tgoto.c,v 1.17 2000/06/03 07:14:55 blymn Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -38,21 +38,22 @@
#if 0
static char sccsid[] = "@(#)tgoto.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: tgoto.c,v 1.16 2000/06/02 13:13:12 itojun Exp $");
+__RCSID("$NetBSD: tgoto.c,v 1.17 2000/06/03 07:14:55 blymn Exp $");
#endif
#endif /* not lint */
#include <errno.h>
#include <string.h>
#include <termcap.h>
+#include <termcap_private.h>
#include <stdlib.h>
#define CTRL(c) ((c) & 037)
#define MAXRETURNSIZE 64
-char *UP;
-char *BC;
+char *UP = NULL;
+char *BC = NULL;
/*
* Routine to perform cursor addressing.
@@ -109,10 +110,7 @@
static char added[10];
const char *cp = CM;
char *dp = buffer;
- char *old_up = UP, *old_bc = BC;
- char new_up[MAXRETURNSIZE], new_bc[MAXRETURNSIZE], *up_ptr, *bc_ptr;
int c;
- size_t count = MAXRETURNSIZE;
int oncol = 0;
int which = destline;
@@ -120,24 +118,15 @@
if (info != NULL)
{
- up_ptr = new_up;
- bc_ptr = new_bc;
- UP = t_getstr(info, "up", &up_ptr, &count);
- count = MAXRETURNSIZE;
- BC = t_getstr(info, "bc", &bc_ptr, &count);
+ if (!UP)
+ UP = info->up;
+ if (!BC)
+ BC = info->bc;
}
if (cp == 0) {
errno = EINVAL;
toohard:
- if (UP != old_up) {
- free(UP);
- UP = old_up;
- }
- if (BC != old_bc) {
- free(BC);
- BC = old_bc;
- }
return -1;
}
added[0] = '\0';
@@ -299,13 +288,5 @@
}
(void)strcpy(dp, added);
- if (UP != old_up) {
- free(UP);
- UP = old_up;
- }
- if (BC != old_bc) {
- free(BC);
- BC = old_bc;
- }
return 0;
}
Home |
Main Index |
Thread Index |
Old Index