summaryrefslogtreecommitdiff
path: root/lib/libedit
diff options
context:
space:
mode:
authorjdolecek <jdolecek@NetBSD.org>2000-12-31 09:50:32 +0000
committerjdolecek <jdolecek@NetBSD.org>2000-12-31 09:50:32 +0000
commit26ffe99b32ee2fe71ff608a674cb386c2d9a8f66 (patch)
treefffa7b7d37632f7a4fbccea1836d13747bc22b15 /lib/libedit
parent5a3fc2bdaa58b188b1f9ba8491b16be38b8a8e79 (diff)
rl_display_match_list():
* pad entries shorter than 'max' by spaces correctly * fix off-by-one error which caused extra newline to be printed if the list fit exactly to a screen * fix typo in _rl_qsort_string_compare, which caused the list to not be sorted after all
Diffstat (limited to 'lib/libedit')
-rw-r--r--lib/libedit/readline.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/libedit/readline.c b/lib/libedit/readline.c
index 0640bedea30..1f2a32996e7 100644
--- a/lib/libedit/readline.c
+++ b/lib/libedit/readline.c
@@ -1,4 +1,4 @@
-/* $NetBSD: readline.c,v 1.12 2000/12/23 22:02:20 jdolecek Exp $ */
+/* $NetBSD: readline.c,v 1.13 2000/12/31 09:50:32 jdolecek Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: readline.c,v 1.12 2000/12/23 22:02:20 jdolecek Exp $");
+__RCSID("$NetBSD: readline.c,v 1.13 2000/12/31 09:50:32 jdolecek Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@@ -1351,7 +1351,7 @@ _rl_qsort_string_compare(i1, i2)
const void *i1, *i2;
{
const char *s1 = ((const char **)i1)[0];
- const char *s2 = ((const char **)i1)[0];
+ const char *s2 = ((const char **)i2)[0];
return strcasecmp(s1, s2);
}
@@ -1369,23 +1369,26 @@ rl_display_match_list (matches, len, max)
int i, idx, limit, count;
int screenwidth = e->el_term.t_size.h;
- max += 2; /* space between entries */
-
- /* find out how many entries can be put on one line */
- limit = screenwidth / max;
+ /*
+ * Find out how many entries can be put on one line, count
+ * with two spaces between strings.
+ */
+ limit = screenwidth / (max + 2);
if (limit == 0)
limit = 1;
/* how many lines of output */
count = len / limit;
+ if (count * limit < len)
+ count++;
/* Sort the items if they are not already sorted. */
- qsort(matches + 1, len, sizeof(char *), _rl_qsort_string_compare);
+ qsort(&matches[1], len-1, sizeof(char *), _rl_qsort_string_compare);
idx = 1;
- for(; count >= 0; count--) {
+ for(; count > 0; count--) {
for(i=0; i < limit && matches[idx]; i++, idx++)
- fprintf(e->el_outfile, "%s ", matches[idx]);
+ fprintf(e->el_outfile, "%-*s ", max, matches[idx]);
fprintf(e->el_outfile, "\n");
}
}