aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-08-21 14:03:55 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2021-08-22 00:09:57 +0200
commit74c4f356aee9c64978a881e5760055d0e3510a6a (patch)
treeaac8d2936542b32caabed72f493d82a53b003369
parent08ad934ac4e341c35497497f4d617a514de524a1 (diff)
downloadbusybox-w32-74c4f356aee9c64978a881e5760055d0e3510a6a.tar.gz
busybox-w32-74c4f356aee9c64978a881e5760055d0e3510a6a.tar.bz2
busybox-w32-74c4f356aee9c64978a881e5760055d0e3510a6a.zip
vi: code shrink print_literal()
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@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/vi.c19
1 files changed, 2 insertions, 17 deletions
diff --git a/editors/vi.c b/editors/vi.c
index eee5e0ed2..e4ba2b2b0 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -1377,21 +1377,14 @@ static void print_literal(char *buf, const char *s)
1377 char *d; 1377 char *d;
1378 unsigned char c; 1378 unsigned char c;
1379 1379
1380 buf[0] = '\0';
1381 if (!s[0]) 1380 if (!s[0])
1382 s = "(NULL)"; 1381 s = "(NULL)";
1383 1382
1384 d = buf; 1383 d = buf;
1385 for (; *s; s++) { 1384 for (; *s; s++) {
1386 int c_is_no_print;
1387
1388 c = *s; 1385 c = *s;
1389 c_is_no_print = (c & 0x80) && !Isprint(c); 1386 if ((c & 0x80) && !Isprint(c))
1390 if (c_is_no_print) { 1387 c = '?';
1391 strcpy(d, ESC_NORM_TEXT);
1392 d += sizeof(ESC_NORM_TEXT)-1;
1393 c = '.';
1394 }
1395 if (c < ' ' || c == 0x7f) { 1388 if (c < ' ' || c == 0x7f) {
1396 *d++ = '^'; 1389 *d++ = '^';
1397 c |= '@'; // 0x40 1390 c |= '@'; // 0x40
@@ -1400,14 +1393,6 @@ static void print_literal(char *buf, const char *s)
1400 } 1393 }
1401 *d++ = c; 1394 *d++ = c;
1402 *d = '\0'; 1395 *d = '\0';
1403 if (c_is_no_print) {
1404 strcpy(d, ESC_BOLD_TEXT);
1405 d += sizeof(ESC_BOLD_TEXT)-1;
1406 }
1407 if (*s == '\n') {
1408 *d++ = '$';
1409 *d = '\0';
1410 }
1411 if (d - buf > MAX_INPUT_LEN - 10) // paranoia 1396 if (d - buf > MAX_INPUT_LEN - 10) // paranoia
1412 break; 1397 break;
1413 } 1398 }