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.
This commit is contained in:
christos 2016-05-13 15:55:59 +00:00
parent 241761204e
commit 4b3392da81

View File

@ -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;