From 837f49c6bf0db1de7b85cb20e2c19a6232717adc Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 29 Mar 2020 14:52:19 +0100 Subject: [PATCH] more: fix moving backwards so that it can reach begining of the file Moving backwards has worked fine until reaching start of file. At that point more printout had one line too much in output causing more seemingly never to be able to reach the start. That is now fixed, with clean ups to skip_backwards() making it less confusing. Signed-off-by: Sami Kerola --- text-utils/more.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/text-utils/more.c b/text-utils/more.c index 4661839142..b4029444fc 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -1444,34 +1444,18 @@ static void execute_editor(struct more_control *ctl, char *cmdbuf, char *filenam static int skip_backwards(struct more_control *ctl, int nlines) { - int retval; - if (nlines == 0) nlines++; - - putchar('\r'); erase_to_col(ctl, 0); - putchar('\n'); - if (ctl->clear_line_ends) - putp(ctl->erase_line); printf(P_("...back %d page", "...back %d pages", nlines), nlines); - if (ctl->clear_line_ends) - putp(ctl->erase_line); putchar('\n'); - - ctl->next_jump = ctl->current_line - ctl->lines_per_screen * (nlines + 1); - if (!ctl->no_scroll) - ctl->next_jump--; + ctl->next_jump = ctl->current_line - (ctl->lines_per_screen * (nlines + 1)) - 1; if (ctl->next_jump < 0) ctl->next_jump = 0; more_fseek(ctl, 0); - ctl->current_line = 0; /* skip_lines() will make current_line correct */ + ctl->current_line = 0; skip_lines(ctl); - if (!ctl->no_scroll) - retval = ctl->lines_per_screen + 1; - else - retval = ctl->lines_per_screen; - return retval; + return ctl->lines_per_screen; } static int skip_forwards(struct more_control *ctl, int nlines, cc_t comchar) -- 2.47.3