tweaks: convert integers to bytes in one place instead of two

master
Benno Schulenberg 2020-02-12 17:16:27 +01:00
parent f012d54a1d
commit 2b27df6733
4 changed files with 13 additions and 22 deletions

View File

@ -310,22 +310,14 @@ void do_statusbar_prev_word(void)
/* Get a verbatim keystroke and insert it into the answer. */
void do_statusbar_verbatim_input(void)
{
int *kbinput;
char *bytes;
size_t count;
kbinput = get_verbatim_kbinput(bottomwin, &count);
bytes = charalloc(count + 1);
for (size_t i = 0; i < count; i++)
bytes[i] = (char)kbinput[i];
bytes[count] = '\0';
bytes = get_verbatim_kbinput(bottomwin, &count);
inject_into_answer(bytes, count);
free(bytes);
free(kbinput);
}
/* Paste the first line of the cutbuffer into the current answer. */

View File

@ -614,7 +614,7 @@ int parse_kbinput(WINDOW *win);
int get_kbinput(WINDOW *win, bool showcursor);
int get_byte_kbinput(int kbinput);
int get_control_kbinput(int kbinput);
int *get_verbatim_kbinput(WINDOW *win, size_t *count);
char *get_verbatim_kbinput(WINDOW *win, size_t *count);
#ifdef ENABLE_MOUSE
int get_mouseinput(int *mouse_row, int *mouse_col, bool allow_shortcuts);
#endif

View File

@ -3131,9 +3131,8 @@ void do_wordlinechar_count(void)
/* Get verbatim input. */
void do_verbatim_input(void)
{
int *kbinput;
size_t count;
char *bytes;
size_t count;
/* TRANSLATORS: This is displayed when the next keystroke will be
* inserted verbatim. */
@ -3141,7 +3140,7 @@ void do_verbatim_input(void)
place_the_cursor();
/* Read in the first one or two bytes of the next keystroke. */
kbinput = get_verbatim_kbinput(edit, &count);
bytes = get_verbatim_kbinput(edit, &count);
/* Unsuppress cursor-position display or blank the status bar. */
if (ISSET(CONSTANT_SHOW))
@ -3149,17 +3148,10 @@ void do_verbatim_input(void)
else
wipe_statusbar();
bytes = charalloc(count + 1);
for (size_t i = 0; i < count; i++)
bytes[i] = (char)kbinput[i];
bytes[count] = '\0';
/* Insert the bytes into the edit buffer. */
inject(bytes, count);
free(bytes);
free(kbinput);
}
#ifdef ENABLE_WORDCOMPLETION

View File

@ -1578,8 +1578,9 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
/* Read in one control code, one character byte, or the leading escapes of
* an escape sequence, and return the resulting number of bytes in count. */
int *get_verbatim_kbinput(WINDOW *win, size_t *count)
char *get_verbatim_kbinput(WINDOW *win, size_t *count)
{
char *bytes = charalloc(3);
int *input;
/* Turn off flow control characters if necessary so that we can type
@ -1611,7 +1612,13 @@ int *get_verbatim_kbinput(WINDOW *win, size_t *count)
keypad(bottomwin, TRUE);
}
return input;
for (size_t i = 0; i < *count; i++)
bytes[i] = (char)input[i];
bytes[*count] = '\0';
free(input);
return bytes;
}
#ifdef ENABLE_MOUSE