From e540053eb332ab6b58430562c06b40f1b326e220 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 14 Feb 2016 12:03:47 +0000 Subject: [PATCH] Renaming and condensing some stuff, and correcting the main comment, because 'allow_cntrls == FALSE' meant that controls were being filtered. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5644 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 2 ++ src/prompt.c | 51 +++++++++++++++++++-------------------------------- src/proto.h | 4 ++-- 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 50ca3010..dc9be08b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ 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. + * src/prompt.c (do_statusbar_output): Rename and condense some stuff, + and correct the main comment: filtering means allow_cntrls==FALSE. 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 da96fb75..6c63c0c9 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -120,11 +120,9 @@ 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. */ - do_statusbar_output(kbinput, kbinput_len, &dummy, FALSE); + do_statusbar_output(kbinput, kbinput_len, TRUE, NULL); /* Empty the input buffer. */ kbinput_len = 0; @@ -165,8 +163,8 @@ int do_statusbar_input(bool *ran_func, bool *finished, * prompt, disable verbatim input. */ if (!ISSET(RESTRICTED) || currmenu != MWRITEFILE || openfile->filename[0] == '\0') { - bool got_enter; - /* Whether we got the Enter key. */ + bool got_enter = FALSE; + /* Whether we got the Enter key. */ do_statusbar_verbatim_input(&got_enter); @@ -242,44 +240,37 @@ int do_statusbar_mouse(void) } #endif -/* The user typed output_len multibyte characters. Add them to the - * 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(int *the_input, size_t output_len, bool - *got_enter, bool allow_cntrls) +/* The user typed input_len multibyte characters. Add them to the + * statusbar prompt, setting got_enter to TRUE if we get a newline, + * and filtering out ASCII control characters if filtering is TRUE. */ +void do_statusbar_output(int *the_input, size_t input_len, + bool filtering, bool *got_enter) { size_t answer_len, i; - char *output = charalloc(output_len + 1); + char *output = charalloc(input_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++) + for (i = 0; i < input_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 - * properly. */ - if (allow_cntrls) { - /* Null to newline, if needed. */ + while (i < input_len) { + /* When not filtering, convert nulls and stop at a newline. */ + if (!filtering) { if (output[i] == '\0') output[i] = '\n'; - /* Newline to Enter, if needed. */ else if (output[i] == '\n') { - /* Set got_enter to TRUE to indicate that we got the - * Enter key, put back the rest of the characters in - * output so that they can be parsed and output again, - * and get out. */ + /* Put back the rest of the characters for reparsing, + * indicate that we got the Enter key and get out. */ + unparse_kbinput(output + i, input_len - i); *got_enter = TRUE; - unparse_kbinput(output + i, output_len - i); return; } } @@ -289,10 +280,8 @@ void do_statusbar_output(int *the_input, size_t output_len, bool i += char_buf_len; - /* If allow_cntrls is FALSE, filter out an ASCII control - * character. */ - if (!allow_cntrls && is_ascii_cntrl_char(*(output + i - - char_buf_len))) + /* When filtering, skip any ASCII control character. */ + if (filtering && is_ascii_cntrl_char(*(output + i - char_buf_len))) continue; /* More dangerousness fun. =) */ @@ -454,14 +443,12 @@ void do_statusbar_verbatim_input(bool *got_enter) int *kbinput; size_t kbinput_len; - *got_enter = FALSE; - /* Read in all the verbatim characters. */ kbinput = get_verbatim_kbinput(bottomwin, &kbinput_len); /* Display all the verbatim characters at once, not filtering out * control characters. */ - do_statusbar_output(kbinput, kbinput_len, got_enter, TRUE); + do_statusbar_output(kbinput, kbinput_len, FALSE, got_enter); } /* Return the placewewant associated with statusbar_x, i.e. the diff --git a/src/proto.h b/src/proto.h index 790589f5..cd23b2e4 100644 --- a/src/proto.h +++ b/src/proto.h @@ -517,8 +517,8 @@ int do_statusbar_input(bool *ran_func, bool *finished, #ifndef DISABLE_MOUSE int do_statusbar_mouse(void); #endif -void do_statusbar_output(int *the_input, size_t output_len, bool - *got_enter, bool allow_cntrls); +void do_statusbar_output(int *the_input, size_t input_len, + bool filtering, bool *got_enter); void do_statusbar_home(void); void do_statusbar_end(void); void do_statusbar_left(void); -- 2.39.5