[PATCH] vi: code shrink print_literal()
Denys Vlasenko
vda.linux at googlemail.com
Sat Aug 21 22:10:52 UTC 2021
Applied, thank you
On Sat, Aug 21, 2021 at 3:04 PM Ron Yorston <rmy at pobox.com> wrote:
>
> Simplify the function print_literal() which is used to format a
> string that may contain unprintable characters or control
> characters.
>
> - Unprintable characters were being displayed in normal text rather
> than the bold used for the rest of the message. This doesn't seem
> particularly helpful and it upsets the calculation of the width
> of the message in show_status_line(). Use '?' rather than '.' for
> unprintable characters.
>
> - Newlines in the string were displayed as both '^J' and '$', which
> is somewhat redundant.
>
> function old new delta
> not_implemented 199 108 -91
> ------------------------------------------------------------------------------
> (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-91) Total: -91 bytes
>
> Signed-off-by: Ron Yorston <rmy at pobox.com>
> ---
> editors/vi.c | 19 ++-----------------
> 1 file changed, 2 insertions(+), 17 deletions(-)
>
> diff --git a/editors/vi.c b/editors/vi.c
> index 126780175..9877fa19f 100644
> --- a/editors/vi.c
> +++ b/editors/vi.c
> @@ -1376,21 +1376,14 @@ static void print_literal(char *buf, const char *s)
> char *d;
> unsigned char c;
>
> - buf[0] = '\0';
> if (!s[0])
> s = "(NULL)";
>
> d = buf;
> for (; *s; s++) {
> - int c_is_no_print;
> -
> c = *s;
> - c_is_no_print = (c & 0x80) && !Isprint(c);
> - if (c_is_no_print) {
> - strcpy(d, ESC_NORM_TEXT);
> - d += sizeof(ESC_NORM_TEXT)-1;
> - c = '.';
> - }
> + if ((c & 0x80) && !Isprint(c))
> + c = '?';
> if (c < ' ' || c == 0x7f) {
> *d++ = '^';
> c |= '@'; // 0x40
> @@ -1399,14 +1392,6 @@ static void print_literal(char *buf, const char *s)
> }
> *d++ = c;
> *d = '\0';
> - if (c_is_no_print) {
> - strcpy(d, ESC_BOLD_TEXT);
> - d += sizeof(ESC_BOLD_TEXT)-1;
> - }
> - if (*s == '\n') {
> - *d++ = '$';
> - *d = '\0';
> - }
> if (d - buf > MAX_INPUT_LEN - 10) // paranoia
> break;
> }
> --
> 2.31.1
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
More information about the busybox
mailing list