nano

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

commit c75a3839da987a43030db745cf897bb96376df82
parent b6a32fbd5f575b2eedcce560ee1a0a0d458fba75
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Wed,  7 Apr 2021 17:08:05 +0200

tweaks: elide a small function that is used just once

Diffstat:
Msrc/chars.c | 15---------------
Msrc/prototypes.h | 1-
Msrc/winio.c | 9+++++----
3 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/src/chars.c b/src/chars.c @@ -251,21 +251,6 @@ bool is_zerowidth(const char *ch) { return (use_utf8 && mbwidth(ch) == 0); } - -/* Convert the given Unicode value to a multibyte character, if possible. - * If the conversion succeeds, return the (dynamically allocated) multibyte - * character and its length. Otherwise, return a length of zero. */ -char *make_mbchar(long code, int *length) -{ - char *mb_char = nmalloc(MAXCHARLEN); - - *length = wctomb(mb_char, (wchar_t)code); - - if (*length < 0) - *length = 0; - - return mb_char; -} #endif /* ENABLE_UTF8 */ /* Return the number of bytes in the character that starts at *pointer. */ diff --git a/src/prototypes.h b/src/prototypes.h @@ -207,7 +207,6 @@ char control_mbrep(const char *c, bool isdata); int mbtowide(wchar_t *wc, const char *c); int mbwidth(const char *c); bool is_zerowidth(const char *ch); -char *make_mbchar(long code, int *length); #endif int char_length(const char *pointer); size_t mbstrlen(const char *pointer); diff --git a/src/winio.c b/src/winio.c @@ -1381,7 +1381,7 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count) * commence Unicode input. Otherwise, put the code back. */ if (using_utf8() && (keycode == '0' || keycode == '1')) { long unicode = assemble_unicode(keycode); - char *multibyte; + char multibyte[MB_CUR_MAX]; reveal_cursor = FALSE; @@ -1411,14 +1411,15 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count) } /* Convert the Unicode value to a multibyte sequence. */ - multibyte = make_mbchar(unicode, (int *)count); + *count = wctomb(multibyte, unicode); + + if (*count > MAXCHARLEN) + *count = 0; /* Change the multibyte character into a series of integers. */ for (size_t i = 0; i < *count; i++) yield[i] = (int)multibyte[i]; - free(multibyte); - return yield; } #endif /* ENABLE_UTF8 */