From: Benno Schulenberg Date: Sun, 14 Feb 2016 11:16:54 +0000 (+0000) Subject: Doing the copying of typed stuff from input to output just once. X-Git-Tag: v2.5.3~37 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=ef16a2a250e090eeb4e50cfd5d415c4846087607;p=nano.git Doing the copying of typed stuff from input to output just once. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5643 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 39ac4bc1..50ca3010 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ them centered when found offscreen. This fixes Savannah bug #47127. * src/text.c (do_int_spell_fix): Restore the above behavior also for the internal spell fixer. + * src/prompt.c (do_statusbar_input, do_statusbar_verbatim_input, + do_statusbar_output): Do the copying from input to output just once. 2016-02-13 Benno Schulenberg * src/browser.c (do_browser, browser_refresh): Rebuild the file list diff --git a/src/prompt.c b/src/prompt.c index 13d913c7..da96fb75 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -120,20 +120,11 @@ int do_statusbar_input(bool *ran_func, bool *finished, * characters in the input buffer if it isn't empty. */ if (have_shortcut || get_key_buffer_len() == 0) { if (kbinput != NULL) { + bool dummy; + /* Display all the characters in the input buffer at * once, filtering out control characters. */ - char *output = charalloc(kbinput_len + 1); - size_t i; - bool got_enter; - /* Whether we got the Enter key. */ - - for (i = 0; i < kbinput_len; i++) - output[i] = (char)kbinput[i]; - output[i] = '\0'; - - do_statusbar_output(output, kbinput_len, &got_enter, FALSE); - - free(output); + do_statusbar_output(kbinput, kbinput_len, &dummy, FALSE); /* Empty the input buffer. */ kbinput_len = 0; @@ -255,17 +246,24 @@ int do_statusbar_mouse(void) * statusbar prompt, setting got_enter to TRUE if we get a newline, and * filtering out all ASCII control characters if allow_cntrls is * TRUE. */ -void do_statusbar_output(char *output, size_t output_len, bool +void do_statusbar_output(int *the_input, size_t output_len, bool *got_enter, bool allow_cntrls) { - size_t answer_len, i = 0; + size_t answer_len, i; + char *output = charalloc(output_len + 1); char *char_buf = charalloc(mb_cur_max()); int char_buf_len; assert(answer != NULL); + /* Copy the typed stuff so it can be treated. */ + for (i = 0; i < output_len; i++) + output[i] = (char)the_input[i]; + output[i] = '\0'; + answer_len = strlen(answer); *got_enter = FALSE; + i = 0; while (i < output_len) { /* If allow_cntrls is TRUE, convert nulls and newlines @@ -311,6 +309,7 @@ void do_statusbar_output(char *output, size_t output_len, bool } free(char_buf); + free(output); statusbar_pww = statusbar_xplustabs(); @@ -453,8 +452,7 @@ void do_statusbar_prev_word(void) void do_statusbar_verbatim_input(bool *got_enter) { int *kbinput; - size_t kbinput_len, i; - char *output; + size_t kbinput_len; *got_enter = FALSE; @@ -463,15 +461,7 @@ void do_statusbar_verbatim_input(bool *got_enter) /* Display all the verbatim characters at once, not filtering out * control characters. */ - output = charalloc(kbinput_len + 1); - - for (i = 0; i < kbinput_len; i++) - output[i] = (char)kbinput[i]; - output[i] = '\0'; - - do_statusbar_output(output, kbinput_len, got_enter, TRUE); - - free(output); + do_statusbar_output(kbinput, kbinput_len, got_enter, TRUE); } /* Return the placewewant associated with statusbar_x, i.e. the diff --git a/src/proto.h b/src/proto.h index 3a3c481e..790589f5 100644 --- a/src/proto.h +++ b/src/proto.h @@ -517,7 +517,7 @@ int do_statusbar_input(bool *ran_func, bool *finished, #ifndef DISABLE_MOUSE int do_statusbar_mouse(void); #endif -void do_statusbar_output(char *output, size_t output_len, bool +void do_statusbar_output(int *the_input, size_t output_len, bool *got_enter, bool allow_cntrls); void do_statusbar_home(void); void do_statusbar_end(void);