Module Name:    src
Committed By:   christos
Date:           Fri May 13 15:55:59 UTC 2016

Modified Files:
        src/lib/libedit: readline.c

Log Message:
>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.


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/lib/libedit/readline.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libedit/readline.c
diff -u src/lib/libedit/readline.c:1.132 src/lib/libedit/readline.c:1.133
--- src/lib/libedit/readline.c:1.132	Mon May  9 17:27:55 2016
+++ src/lib/libedit/readline.c	Fri May 13 11:55:59 2016
@@ -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 @@ where_history(void)
 		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;

Reply via email to