From d922947834160f356ebdee07af69e33cbe4b6057 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 19 Aug 2021 15:04:39 +0200 Subject: Bump version to 1.34.0 Signed-off-by: Denys Vlasenko --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ea182325d..120661f44 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ VERSION = 1 PATCHLEVEL = 34 SUBLEVEL = 0 -EXTRAVERSION = .git +EXTRAVERSION = NAME = Unnamed # *DOCUMENTATION* -- cgit v1.2.3-55-g6feb From 9d286a0a556fe13be46b7b526035706afdd063f4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 19 Aug 2021 15:06:57 +0200 Subject: Start 1.35.0 development cycle Signed-off-by: Denys Vlasenko --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 120661f44..1216c94a5 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ VERSION = 1 -PATCHLEVEL = 34 +PATCHLEVEL = 35 SUBLEVEL = 0 -EXTRAVERSION = +EXTRAVERSION = .git NAME = Unnamed # *DOCUMENTATION* -- cgit v1.2.3-55-g6feb From 29b53ef03fc7ddd3ba27898d77a900a2f184aa0d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 20 Aug 2021 13:33:50 +0200 Subject: udhcp: fix build breakage on MIPS Signed-off-by: Denys Vlasenko --- networking/udhcp/common.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index 8c678dd32..ca778dab8 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h @@ -304,18 +304,6 @@ void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC; # define log3s(msg) ((void)0) #endif -#if defined(__mips__) -/* - * The 'simple' message functions have a negative impact on the size of the - * DHCP code when compiled for MIPS, so don't use them in this case. - */ -#define bb_simple_info_msg bb_info_msg -#define bb_simple_error_msg bb_error_msg -#define bb_simple_perror_msg_and_die bb_perror_msg_and_die -#undef log1s -#define log1s log1 -#endif - /*** Other shared functions ***/ /* 2nd param is "uint32_t*" */ -- cgit v1.2.3-55-g6feb From f07772f19e29cf44a14c108935afb5668e38fac3 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 19 Aug 2021 16:59:36 +0100 Subject: vi: changes to handling of -c and EXINIT Rewrite handling of command line arguments so any number of -c commands will be processed. Previously only two -c commands were allowed (or one if EXINIT was set). Process commands from EXINIT before the first file is read into memory, as specified by POSIX. function old new delta run_cmds - 77 +77 .rodata 108410 108411 +1 vi_main 305 268 -37 edit_file 816 764 -52 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/2 up/down: 78/-89) Total: -11 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- editors/vi.c | 123 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 65 insertions(+), 58 deletions(-) diff --git a/editors/vi.c b/editors/vi.c index 3e1bd0820..cc4f6bde7 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -201,6 +201,7 @@ // the CRASHME code is unmaintained, and doesn't currently build #define ENABLE_FEATURE_VI_CRASHME 0 +#define IF_FEATURE_VI_CRASHME(...) #if ENABLE_LOCALE_SUPPORT @@ -403,7 +404,7 @@ struct globals { int cindex; // saved character index for up/down motion smallint keep_index; // retain saved character index #if ENABLE_FEATURE_VI_COLON - char *initial_cmds[3]; // currently 2 entries, NULL terminated + llist_t *initial_cmds; #endif // Should be just enough to hold a key sequence, // but CRASHME mode uses it as generated command buffer too @@ -4708,6 +4709,21 @@ static void crash_test() } #endif +#if ENABLE_FEATURE_VI_COLON +static void run_cmds(char *p) +{ + while (p) { + char *q = p; + p = strchr(q, '\n'); + if (p) + while (*p == '\n') + *p++ = '\0'; + if (strlen(q) < MAX_INPUT_LEN) + colon(q); + } +} +#endif + static void edit_file(char *fn) { #if ENABLE_FEATURE_VI_YANKMARK @@ -4778,25 +4794,8 @@ static void edit_file(char *fn) #endif #if ENABLE_FEATURE_VI_COLON - { - char *p, *q; - int n = 0; - - while ((p = initial_cmds[n]) != NULL) { - do { - q = p; - p = strchr(q, '\n'); - if (p) - while (*p == '\n') - *p++ = '\0'; - if (*q) - colon(q); - } while (p); - free(initial_cmds[n]); - initial_cmds[n] = NULL; - n++; - } - } + while (initial_cmds) + run_cmds((char *)llist_pop(&initial_cmds)); #endif redraw(FALSE); // dont force every col re-draw //------This is the main Vi cmd handling loop ----------------------- @@ -4859,10 +4858,29 @@ static void edit_file(char *fn) #undef cur_line } +#define VI_OPTSTR \ + IF_FEATURE_VI_CRASHME("C") \ + IF_FEATURE_VI_COLON("c:*") \ + "Hh" \ + IF_FEATURE_VI_READONLY("R") + +enum { + IF_FEATURE_VI_CRASHME(OPTBIT_C,) + IF_FEATURE_VI_COLON(OPTBIT_c,) + OPTBIT_H, + OPTBIT_h, + IF_FEATURE_VI_READONLY(OPTBIT_R,) + OPT_C = IF_FEATURE_VI_CRASHME( (1 << OPTBIT_C)) + 0, + OPT_c = IF_FEATURE_VI_COLON( (1 << OPTBIT_c)) + 0, + OPT_H = 1 << OPTBIT_H, + OPT_h = 1 << OPTBIT_h, + OPT_R = IF_FEATURE_VI_READONLY( (1 << OPTBIT_R)) + 0, +}; + int vi_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int vi_main(int argc, char **argv) { - int c; + int opts; INIT_G(); @@ -4886,50 +4904,39 @@ int vi_main(int argc, char **argv) // 0: all of our options are disabled by default in vim //vi_setops = 0; - // 1- process EXINIT variable from environment - // 2- if EXINIT is unset process $HOME/.exrc file (not inplemented yet) - // 3- process command line args -#if ENABLE_FEATURE_VI_COLON - { - char *p = getenv("EXINIT"); - if (p && *p) - initial_cmds[0] = xstrndup(p, MAX_INPUT_LEN); - } -#endif - while ((c = getopt(argc, argv, -#if ENABLE_FEATURE_VI_CRASHME - "C" -#endif - "RHh" IF_FEATURE_VI_COLON("c:"))) != -1) { - switch (c) { + opts = getopt32(argv, VI_OPTSTR IF_FEATURE_VI_COLON(, &initial_cmds)); + #if ENABLE_FEATURE_VI_CRASHME - case 'C': - crashme = 1; - break; + if (opts & OPT_C) + crashme = 1; #endif -#if ENABLE_FEATURE_VI_READONLY - case 'R': // Read-only flag - SET_READONLY_MODE(readonly_mode); - break; -#endif -#if ENABLE_FEATURE_VI_COLON - case 'c': // cmd line vi command - if (*optarg) - initial_cmds[initial_cmds[0] != NULL] = xstrndup(optarg, MAX_INPUT_LEN); - break; -#endif - case 'H': - show_help(); - // fall through - default: - bb_show_usage(); - return 1; - } + if (opts & OPT_R) + SET_READONLY_MODE(readonly_mode); + if (opts & OPT_H) + show_help(); + if (opts & (OPT_H | OPT_h)) { + bb_show_usage(); + return 1; } argv += optind; cmdline_filecnt = argc - optind; + // 1- process EXINIT variable from environment + // 2- if EXINIT is unset process $HOME/.exrc file (not implemented yet) + // 3- process command line args +#if ENABLE_FEATURE_VI_COLON + { + const char *exinit = getenv("EXINIT"); + + if (exinit) { + char *cmds = xstrdup(exinit); + init_text_buffer(NULL); + run_cmds(cmds); + free(cmds); + } + } +#endif // "Save cursor, use alternate screen buffer, clear screen" write1(ESC"[?1049h"); // This is the main file handling loop -- cgit v1.2.3-55-g6feb From f9217cd235c2a139ae22cf549c7614724f1fc6cf Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 19 Aug 2021 17:00:17 +0100 Subject: vi: support ~/.exrc Run initialisation commands from ~/.exrc. As with EXINIT these commands are processed before the first file is loaded. Commands starting with double quotes are ignored. This is how comments are often included in .exrc. function old new delta vi_main 268 406 +138 colon 4033 4071 +38 .rodata 108411 108442 +31 packed_usage 34128 34118 -10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 207/-10) Total: 197 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- editors/vi.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/editors/vi.c b/editors/vi.c index cc4f6bde7..e6527e36b 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -7,7 +7,7 @@ */ // //Things To Do: -// $HOME/.exrc and ./.exrc +// ./.exrc // add magic to search /foo.*bar // add :help command // :map macros @@ -185,7 +185,7 @@ //usage:#define vi_full_usage "\n\n" //usage: "Edit FILE\n" //usage: IF_FEATURE_VI_COLON( -//usage: "\n -c CMD Initial command to run ($EXINIT also available)" +//usage: "\n -c CMD Initial command to run ($EXINIT and ~/.exrc also available)" //usage: ) //usage: IF_FEATURE_VI_READONLY( //usage: "\n -R Read-only" @@ -2829,10 +2829,12 @@ static void colon(char *buf) // :! // run then return // - if (!buf[0]) - goto ret; - if (*buf == ':') - buf++; // move past the ':' + while (*buf == ':') + buf++; // move past leading colons + while (isblank(*buf)) + buf++; // move past leading blanks + if (!buf[0] || buf[0] == '"') + goto ret; // ignore empty lines or those starting with '"' li = i = 0; b = e = -1; @@ -4923,14 +4925,37 @@ int vi_main(int argc, char **argv) cmdline_filecnt = argc - optind; // 1- process EXINIT variable from environment - // 2- if EXINIT is unset process $HOME/.exrc file (not implemented yet) + // 2- if EXINIT is unset process $HOME/.exrc file // 3- process command line args #if ENABLE_FEATURE_VI_COLON { const char *exinit = getenv("EXINIT"); + char *cmds = NULL; if (exinit) { - char *cmds = xstrdup(exinit); + cmds = xstrdup(exinit); + } else { + const char *home = getenv("HOME"); + + if (home && *home) { + char *exrc = concat_path_file(home, ".exrc"); + struct stat st; + + // .exrc must belong to and only be writable by user + if (stat(exrc, &st) == 0) { + if ((st.st_mode & (S_IWGRP|S_IWOTH)) == 0 + && st.st_uid == getuid() + ) { + cmds = xmalloc_open_read_close(exrc, NULL); + } else { + status_line_bold(".exrc: permission denied"); + } + } + free(exrc); + } + } + + if (cmds) { init_text_buffer(NULL); run_cmds(cmds); free(cmds); -- cgit v1.2.3-55-g6feb From 38e9c8c95b919e949b1cdd16f05b648a75983f57 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 20 Aug 2021 08:25:07 +0100 Subject: vi: don't right shift empty lines The right shift command ('>') shouldn't affect empty lines. function old new delta do_cmd 4860 4894 +34 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 34/0) Total: 34 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- editors/vi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editors/vi.c b/editors/vi.c index e6527e36b..508477954 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -4092,8 +4092,8 @@ static void do_cmd(int c) #endif } } - } else /* if (c == '>') */ { - // shift right -- add tab or tabstop spaces + } else if (/* c == '>' && */ p != end_line(p)) { + // shift right -- add tab or tabstop spaces on non-empty lines char_insert(p, '\t', allow_undo); } #if ENABLE_FEATURE_VI_UNDO -- cgit v1.2.3-55-g6feb From 62d5a1e56f4022002c5c55e02d7d29e1e68bc236 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 20 Aug 2021 17:58:49 +0200 Subject: tar,smemcap: commonalyze checksumming code for tar header function old new delta chksum_and_xwrite_tar_header - 99 +99 writeheader 280 199 -81 chksum_and_xwrite 102 - -102 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 0/1 up/down: 99/-183) Total: -84 bytes Signed-off-by: Denys Vlasenko --- archival/chksum_and_xwrite_tar_header.c | 35 +++++++++++++++++++++++++++++++++ archival/tar.c | 31 ++--------------------------- include/bb_archive.h | 1 + procps/smemcap.c | 16 +-------------- 4 files changed, 39 insertions(+), 44 deletions(-) create mode 100644 archival/chksum_and_xwrite_tar_header.c diff --git a/archival/chksum_and_xwrite_tar_header.c b/archival/chksum_and_xwrite_tar_header.c new file mode 100644 index 000000000..25934f898 --- /dev/null +++ b/archival/chksum_and_xwrite_tar_header.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2021 Denys Vlasenko + * + * Licensed under GPLv2, see file LICENSE in this source tree. + */ +//kbuild:lib-$(CONFIG_FEATURE_TAR_CREATE) += chksum_and_xwrite_tar_header.o +//kbuild:lib-$(CONFIG_SMEMCAP) += chksum_and_xwrite_tar_header.o + +#include "libbb.h" +#include "bb_archive.h" + +void FAST_FUNC chksum_and_xwrite_tar_header(int fd, struct tar_header_t *hp) +{ + /* POSIX says that checksum is done on unsigned bytes + * (Sun and HP-UX gets it wrong... more details in + * GNU tar source) */ + const unsigned char *cp; + int chksum, size; + + strcpy(hp->magic, "ustar "); + + /* Calculate and store the checksum (the sum of all of the bytes of + * the header). The checksum field must be filled with blanks for the + * calculation. The checksum field is formatted differently from the + * other fields: it has 6 digits, a NUL, then a space -- rather than + * digits, followed by a NUL like the other fields... */ + memset(hp->chksum, ' ', sizeof(hp->chksum)); + cp = (const unsigned char *) hp; + chksum = 0; + size = sizeof(*hp); + do { chksum += *cp++; } while (--size); + sprintf(hp->chksum, "%06o", chksum); + + xwrite(fd, hp, sizeof(*hp)); +} diff --git a/archival/tar.c b/archival/tar.c index 94fb61a29..9de37592e 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -254,32 +254,6 @@ static void putOctal(char *cp, int len, off_t value) } #define PUT_OCTAL(a, b) putOctal((a), sizeof(a), (b)) -static void chksum_and_xwrite(int fd, struct tar_header_t* hp) -{ - /* POSIX says that checksum is done on unsigned bytes - * (Sun and HP-UX gets it wrong... more details in - * GNU tar source) */ - const unsigned char *cp; - int chksum, size; - - strcpy(hp->magic, "ustar "); - - /* Calculate and store the checksum (i.e., the sum of all of the bytes of - * the header). The checksum field must be filled with blanks for the - * calculation. The checksum field is formatted differently from the - * other fields: it has 6 digits, a null, then a space -- rather than - * digits, followed by a null like the other fields... */ - memset(hp->chksum, ' ', sizeof(hp->chksum)); - cp = (const unsigned char *) hp; - chksum = 0; - size = sizeof(*hp); - do { chksum += *cp++; } while (--size); - putOctal(hp->chksum, sizeof(hp->chksum)-1, chksum); - - /* Now write the header out to disk */ - xwrite(fd, hp, sizeof(*hp)); -} - # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS static void writeLongname(int fd, int type, const char *name, int dir) { @@ -310,7 +284,7 @@ static void writeLongname(int fd, int type, const char *name, int dir) /* + dir: account for possible '/' */ PUT_OCTAL(header.size, size); - chksum_and_xwrite(fd, &header); + chksum_and_xwrite_tar_header(fd, &header); /* Write filename[/] and pad the block. */ /* dir=0: writes 'name', pads */ @@ -441,8 +415,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo, header_name, S_ISDIR(statbuf->st_mode)); # endif - /* Now write the header out to disk */ - chksum_and_xwrite(tbInfo->tarFd, &header); + chksum_and_xwrite_tar_header(tbInfo->tarFd, &header); /* Now do the verbose thing (or not) */ if (tbInfo->verboseFlag) { diff --git a/include/bb_archive.h b/include/bb_archive.h index 9b1db5b3e..dc5e55f0a 100644 --- a/include/bb_archive.h +++ b/include/bb_archive.h @@ -167,6 +167,7 @@ typedef struct tar_header_t { /* byte offset */ struct BUG_tar_header { char c[sizeof(tar_header_t) == TAR_BLOCK_SIZE ? 1 : -1]; }; +void chksum_and_xwrite_tar_header(int fd, struct tar_header_t *hp) FAST_FUNC; extern const char cpio_TRAILER[]; diff --git a/procps/smemcap.c b/procps/smemcap.c index 2f8ab192e..2f1897dae 100644 --- a/procps/smemcap.c +++ b/procps/smemcap.c @@ -29,7 +29,6 @@ struct fileblock { static void writeheader(const char *path, struct stat *sb, int type) { struct tar_header_t header; - int i, sum; memset(&header, 0, TAR_BLOCK_SIZE); strcpy(header.name, path); @@ -40,20 +39,7 @@ static void writeheader(const char *path, struct stat *sb, int type) sprintf(header.size, "%o", (unsigned)sb->st_size); sprintf(header.mtime, "%llo", sb->st_mtime & 077777777777LL); header.typeflag = type; - strcpy(header.magic, "ustar "); /* like GNU tar */ - - /* Calculate and store the checksum (the sum of all of the bytes of - * the header). The checksum field must be filled with blanks for the - * calculation. The checksum field is formatted differently from the - * other fields: it has 6 digits, a NUL, then a space -- rather than - * digits, followed by a NUL like the other fields... */ - header.chksum[7] = ' '; - sum = ' ' * 7; - for (i = 0; i < TAR_BLOCK_SIZE; i++) - sum += ((unsigned char*)&header)[i]; - sprintf(header.chksum, "%06o", sum); - - xwrite(STDOUT_FILENO, &header, TAR_BLOCK_SIZE); + chksum_and_xwrite_tar_header(STDOUT_FILENO, &header); } static void archivefile(const char *path) -- cgit v1.2.3-55-g6feb From 4357569fdc7bc482dea0ef0bff57a70e7f06523c Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 21 Aug 2021 09:36:27 +0100 Subject: rev: correct output for long input lines The input buffer is initialised to a reasonable size and extended if necessary. When this happened the offset into the buffer wasn't reset to zero so subsequent lines were appended to the long line. Fix this and add some tests. function old new delta rev_main 377 368 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-9) Total: -9 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- testsuite/rev.tests | 46 ++++++++++++++++++++++++++++++++++++++++++++++ util-linux/rev.c | 1 + 2 files changed, 47 insertions(+) create mode 100755 testsuite/rev.tests diff --git a/testsuite/rev.tests b/testsuite/rev.tests new file mode 100755 index 000000000..dd65dcd3b --- /dev/null +++ b/testsuite/rev.tests @@ -0,0 +1,46 @@ +#!/bin/sh +# Copyright 2021 by Ron Yorston +# Licensed under GPLv2, see file LICENSE in this source tree. + +. ./testing.sh + +# testing "test name" "commands" "expected result" "file input" "stdin" + +testing "rev works" \ + "rev input" \ +"\ +1 enil + +3 enil +" \ + "line 1\n\nline 3\n" \ + "" + +testing "rev file with missing newline" \ + "rev input" \ +"\ +1 enil + +3 enil" \ + "line 1\n\nline 3" \ + "" + +testing "rev file with NUL character" \ + "rev input" \ +"\ +nil +3 enil +" \ + "lin\000e 1\n\nline 3\n" \ + "" + +testing "rev file with long line" \ + "rev input" \ +"\ ++--------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+--------------- +cba +" \ + "---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+--------------+\nabc\n" \ + "" + +exit $FAILCOUNT diff --git a/util-linux/rev.c b/util-linux/rev.c index d439b4da8..63b005c67 100644 --- a/util-linux/rev.c +++ b/util-linux/rev.c @@ -109,6 +109,7 @@ int rev_main(int argc UNUSED_PARAM, char **argv) strrev(buf, strlen(buf)); #endif fputs_stdout(buf); + pos = 0; } fclose(fp); } while (*argv); -- cgit v1.2.3-55-g6feb From 08ad934ac4e341c35497497f4d617a514de524a1 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 21 Aug 2021 14:02:43 +0100 Subject: vi: searches in colon commands should wrap The '/' and '?' search commands wrap to the other end of the buffer if the search target isn't found. When searches are used to specify addresses in colon commands they should do the same. (In traditional vi and vim this behaviour is controlled by the 'wrapscan' option. BusyBox vi doesn't have this option and always uses the default behaviour.) function old new delta colon 4033 4077 +44 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 44/0) Total: 44 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- editors/vi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/editors/vi.c b/editors/vi.c index 508477954..eee5e0ed2 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -2527,8 +2527,13 @@ static char *get_one_address(char *p, int *result) // get colon addr, if present dir = ((unsigned)BACK << 1) | FULL; } q = char_search(q, last_search_pattern + 1, dir); - if (q == NULL) - return NULL; + if (q == NULL) { + // no match, continue from other end of file + q = char_search(dir > 0 ? text : end - 1, + last_search_pattern + 1, dir); + if (q == NULL) + return NULL; + } new_addr = count_lines(text, q); } # endif -- cgit v1.2.3-55-g6feb From 74c4f356aee9c64978a881e5760055d0e3510a6a Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 21 Aug 2021 14:03:55 +0100 Subject: 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 Signed-off-by: Denys Vlasenko --- editors/vi.c | 19 ++----------------- 1 file 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) 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 @@ -1400,14 +1393,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; } -- cgit v1.2.3-55-g6feb