[PATCH 5/5] less: allow use of last column of terminal

Denys Vlasenko vda.linux at googlemail.com
Fri Jul 31 14:44:41 UTC 2015


Applied all five patches, thanks!

Applied a patch on top of them which uses fstat (stat+open are racy),
uses it only when we actually going to count lines,
and (try to) handle regular files even on stdin ("less <FILE" case).



On Fri, Jul 24, 2015 at 3:29 PM, Ron Yorston <rmy at pobox.com> wrote:
> When read_lines tests whether a character will fit on the current
> line it checks the *next* character but in case of overflow doesn't
> display the *current* one.  This results in the last column of the
> terminal never being used.
>
> The test in re_wrap (used when the terminal width changes or line
> numbers are enabled/disabled) is different:  it does allow the use
> of the final column.
>
> function                                             old     new   delta
> read_lines                                           764     770      +6
> ------------------------------------------------------------------------------
> (add/remove: 0/0 grow/shrink: 1/0 up/down: 6/0)                 Total: 6 bytes
>
> Signed-off-by: Ron Yorston <rmy at pobox.com>
> ---
>  miscutils/less.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/miscutils/less.c b/miscutils/less.c
> index f34b817..2ed4139 100644
> --- a/miscutils/less.c
> +++ b/miscutils/less.c
> @@ -512,16 +512,6 @@ static void read_lines(void)
>                                 *--p = '\0';
>                                 continue;
>                         }
> -                       {
> -                               size_t new_last_line_pos = last_line_pos + 1;
> -                               if (c == '\t') {
> -                                       new_last_line_pos += 7;
> -                                       new_last_line_pos &= (~7);
> -                               }
> -                               if ((int)new_last_line_pos >= w)
> -                                       break;
> -                               last_line_pos = new_last_line_pos;
> -                       }
>                         /* ok, we will eat this char */
>                         readpos++;
>                         if (c == '\n') {
> @@ -533,6 +523,16 @@ static void read_lines(void)
>                         if (c == '\0') c = '\n';
>                         *p++ = c;
>                         *p = '\0';
> +                       {
> +                               size_t new_last_line_pos = last_line_pos + 1;
> +                               if (c == '\t') {
> +                                       new_last_line_pos += 7;
> +                                       new_last_line_pos &= (~7);
> +                               }
> +                               if ((int)new_last_line_pos >= w)
> +                                       break;
> +                               last_line_pos = new_last_line_pos;
> +                       }
>                 } /* end of "read chars until we have a line" loop */
>  #if 0
>  //BUG: also triggers on this:
> --
> 2.4.3
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox


More information about the busybox mailing list