Source-Changes-HG archive

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

[src/trunk]: src/lib/libedit From Bastian Maerkisch, via Igno Schwarze:



details:   https://anonhg.NetBSD.org/src/rev/2a213999d37e
branches:  trunk
changeset: 345225:2a213999d37e
user:      christos <christos%NetBSD.org@localhost>
date:      Fri May 13 15:55:59 2016 +0000

description:
>From Bastian Maerkisch, via Igno Schwarze:

Even though section "2.3.3 Information About the History List"
of the history(3) info(1) manual only says

  -- Function: int where_history (void)
     Returns the offset of the current history element.

which maybe isn't completely clear, a plausible implementation
is that the offset returned is the same offset that can be used
for history_set_pos(), i.e. that it is 0 for the oldest entry
and increases with time, and that's how the GNU implementation
behaves indeed.

The libedit implementation, on the other hand, returns 1 for the
newest entry and increases going back in time.

diffstat:

 lib/libedit/readline.c |  13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diffs (34 lines):

diff -r e1c7782f3034 -r 2a213999d37e lib/libedit/readline.c
--- a/lib/libedit/readline.c    Fri May 13 15:25:57 2016 +0000
+++ b/lib/libedit/readline.c    Fri May 13 15:55:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: readline.c,v 1.132 2016/05/09 21:27:55 christos Exp $  */
+/*     $NetBSD: readline.c,v 1.133 2016/05/13 15:55:59 christos Exp $  */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: readline.c,v 1.132 2016/05/09 21:27:55 christos Exp $");
+__RCSID("$NetBSD: readline.c,v 1.133 2016/05/13 15:55:59 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <sys/types.h>
@@ -1571,9 +1571,12 @@
                return 0;
        curr_num = ev.num;
 
-       (void)history(h, &ev, H_FIRST);
-       off = 1;
-       while (ev.num != curr_num && history(h, &ev, H_NEXT) == 0)
+       /* start from the oldest */
+       (void)history(h, &ev, H_LAST);
+
+       /* position is zero-based */
+       off = 0;
+       while (ev.num != curr_num && history(h, &ev, H_PREV) == 0)
                off++;
 
        return off;



Home | Main Index | Thread Index | Old Index