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
This commit is contained in:
Benno Schulenberg 2016-02-14 12:03:47 +00:00
parent ef16a2a250
commit e540053eb3
3 changed files with 23 additions and 34 deletions

View File

@ -6,6 +6,8 @@
the internal spell fixer. the internal spell fixer.
* src/prompt.c (do_statusbar_input, do_statusbar_verbatim_input, * src/prompt.c (do_statusbar_input, do_statusbar_verbatim_input,
do_statusbar_output): Do the copying from input to output just once. 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 <bensberg@justemail.net> 2016-02-13 Benno Schulenberg <bensberg@justemail.net>
* src/browser.c (do_browser, browser_refresh): Rebuild the file list * src/browser.c (do_browser, browser_refresh): Rebuild the file list

View File

@ -120,11 +120,9 @@ int do_statusbar_input(bool *ran_func, bool *finished,
* characters in the input buffer if it isn't empty. */ * characters in the input buffer if it isn't empty. */
if (have_shortcut || get_key_buffer_len() == 0) { if (have_shortcut || get_key_buffer_len() == 0) {
if (kbinput != NULL) { if (kbinput != NULL) {
bool dummy;
/* Display all the characters in the input buffer at /* Display all the characters in the input buffer at
* once, filtering out control characters. */ * 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. */ /* Empty the input buffer. */
kbinput_len = 0; kbinput_len = 0;
@ -165,8 +163,8 @@ int do_statusbar_input(bool *ran_func, bool *finished,
* prompt, disable verbatim input. */ * prompt, disable verbatim input. */
if (!ISSET(RESTRICTED) || currmenu != MWRITEFILE || if (!ISSET(RESTRICTED) || currmenu != MWRITEFILE ||
openfile->filename[0] == '\0') { openfile->filename[0] == '\0') {
bool got_enter; bool got_enter = FALSE;
/* Whether we got the Enter key. */ /* Whether we got the Enter key. */
do_statusbar_verbatim_input(&got_enter); do_statusbar_verbatim_input(&got_enter);
@ -242,44 +240,37 @@ int do_statusbar_mouse(void)
} }
#endif #endif
/* The user typed output_len multibyte characters. Add them to the /* The user typed input_len multibyte characters. Add them to the
* statusbar prompt, setting got_enter to TRUE if we get a newline, and * statusbar prompt, setting got_enter to TRUE if we get a newline,
* filtering out all ASCII control characters if allow_cntrls is * and filtering out ASCII control characters if filtering is TRUE. */
* TRUE. */ void do_statusbar_output(int *the_input, size_t input_len,
void do_statusbar_output(int *the_input, size_t output_len, bool bool filtering, bool *got_enter)
*got_enter, bool allow_cntrls)
{ {
size_t answer_len, i; size_t answer_len, i;
char *output = charalloc(output_len + 1); char *output = charalloc(input_len + 1);
char *char_buf = charalloc(mb_cur_max()); char *char_buf = charalloc(mb_cur_max());
int char_buf_len; int char_buf_len;
assert(answer != NULL); assert(answer != NULL);
/* Copy the typed stuff so it can be treated. */ /* 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] = (char)the_input[i];
output[i] = '\0'; output[i] = '\0';
answer_len = strlen(answer); answer_len = strlen(answer);
*got_enter = FALSE;
i = 0; i = 0;
while (i < output_len) { while (i < input_len) {
/* If allow_cntrls is TRUE, convert nulls and newlines /* When not filtering, convert nulls and stop at a newline. */
* properly. */ if (!filtering) {
if (allow_cntrls) {
/* Null to newline, if needed. */
if (output[i] == '\0') if (output[i] == '\0')
output[i] = '\n'; output[i] = '\n';
/* Newline to Enter, if needed. */
else if (output[i] == '\n') { else if (output[i] == '\n') {
/* Set got_enter to TRUE to indicate that we got the /* Put back the rest of the characters for reparsing,
* Enter key, put back the rest of the characters in * indicate that we got the Enter key and get out. */
* output so that they can be parsed and output again, unparse_kbinput(output + i, input_len - i);
* and get out. */
*got_enter = TRUE; *got_enter = TRUE;
unparse_kbinput(output + i, output_len - i);
return; return;
} }
} }
@ -289,10 +280,8 @@ void do_statusbar_output(int *the_input, size_t output_len, bool
i += char_buf_len; i += char_buf_len;
/* If allow_cntrls is FALSE, filter out an ASCII control /* When filtering, skip any ASCII control character. */
* character. */ if (filtering && is_ascii_cntrl_char(*(output + i - char_buf_len)))
if (!allow_cntrls && is_ascii_cntrl_char(*(output + i -
char_buf_len)))
continue; continue;
/* More dangerousness fun. =) */ /* More dangerousness fun. =) */
@ -454,14 +443,12 @@ void do_statusbar_verbatim_input(bool *got_enter)
int *kbinput; int *kbinput;
size_t kbinput_len; size_t kbinput_len;
*got_enter = FALSE;
/* Read in all the verbatim characters. */ /* Read in all the verbatim characters. */
kbinput = get_verbatim_kbinput(bottomwin, &kbinput_len); kbinput = get_verbatim_kbinput(bottomwin, &kbinput_len);
/* Display all the verbatim characters at once, not filtering out /* Display all the verbatim characters at once, not filtering out
* control characters. */ * 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 /* Return the placewewant associated with statusbar_x, i.e. the

View File

@ -517,8 +517,8 @@ int do_statusbar_input(bool *ran_func, bool *finished,
#ifndef DISABLE_MOUSE #ifndef DISABLE_MOUSE
int do_statusbar_mouse(void); int do_statusbar_mouse(void);
#endif #endif
void do_statusbar_output(int *the_input, size_t output_len, bool void do_statusbar_output(int *the_input, size_t input_len,
*got_enter, bool allow_cntrls); bool filtering, bool *got_enter);
void do_statusbar_home(void); void do_statusbar_home(void);
void do_statusbar_end(void); void do_statusbar_end(void);
void do_statusbar_left(void); void do_statusbar_left(void);