nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 0a31a9aa386a5676286ce9e5ceaa97242a22160a
parent 6747142cd70de69224c3b09a6fd339eb6333e297
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Wed, 12 Feb 2020 11:34:23 +0100

tweaks: make two conditions more direct, and thus elide two functions

Using straightforward comparisons is clearer and faster and shorter.

Again, note that this does not filter out 0x7F (DEL).  But that is
okay, as that code will never be returned from get_kbinput().

Diffstat:
Msrc/chars.c | 13-------------
Msrc/nano.c | 2+-
Msrc/prompt.c | 2+-
Msrc/proto.h | 2--
4 files changed, 2 insertions(+), 17 deletions(-)

diff --git a/src/chars.c b/src/chars.c @@ -56,12 +56,6 @@ char *addstrings(char* str1, size_t len1, char* str2, size_t len2) return str1; } -/* Return TRUE if the value of c is in byte range, and FALSE otherwise. */ -bool is_byte(int c) -{ - return ((unsigned int)c == (unsigned char)c); -} - /* This function is equivalent to isalpha() for multibyte characters. */ bool is_alpha_mbchar(const char *c) { @@ -110,13 +104,6 @@ bool is_blank_mbchar(const char *c) return isblank((unsigned char)*c); } -/* This function is equivalent to iscntrl(), except in that it only - * handles non-high-bit control characters. */ -bool is_ascii_cntrl_char(int c) -{ - return (0 <= c && c < 32); -} - /* This function is equivalent to iscntrl() for multibyte characters, * except in that it also handles multibyte control characters with * their high bits set. */ diff --git a/src/nano.c b/src/nano.c @@ -1531,7 +1531,7 @@ void do_input(void) /* If we got a non-high-bit control key, a meta key sequence, or a * function key, and it's not a shortcut or toggle, throw it out. */ if (shortcut == NULL) { - if (is_ascii_cntrl_char(input) || meta_key || !is_byte(input)) { + if (input < 0x20 || input > 0xFF || meta_key) { unbound_key(input); input = ERR; } diff --git a/src/prompt.c b/src/prompt.c @@ -90,7 +90,7 @@ int do_statusbar_input(bool *finished) /* If we got a non-high-bit control key, a meta key sequence, or a * function key, and it's not a shortcut or toggle, throw it out. */ if (shortcut == NULL) { - if (is_ascii_cntrl_char(input) || meta_key || !is_byte(input)) { + if (input < 0x20 || input > 0xFF || meta_key) { beep(); input = ERR; } diff --git a/src/proto.h b/src/proto.h @@ -204,10 +204,8 @@ void utf8_init(void); bool using_utf8(void); #endif char *addstrings(char* str1, size_t len1, char* str2, size_t len2); -bool is_byte(int c); bool is_alpha_mbchar(const char *c); bool is_blank_mbchar(const char *c); -bool is_ascii_cntrl_char(int c); bool is_cntrl_mbchar(const char *c); bool is_word_mbchar(const char *c, bool allow_punct); char control_mbrep(const char *c, bool isdata);