commit 2b27df6733c5ed3157bdff96cf6822b4c67da3bb
parent f012d54a1df0ef30be102fbe578db44cdb2ce072
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Wed, 12 Feb 2020 17:16:27 +0100
tweaks: convert integers to bytes in one place instead of two
Diffstat:
4 files changed, 13 insertions(+), 22 deletions(-)
diff --git a/src/prompt.c b/src/prompt.c
@@ -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. */
diff --git a/src/proto.h b/src/proto.h
@@ -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
diff --git a/src/text.c b/src/text.c
@@ -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
diff --git a/src/winio.c b/src/winio.c
@@ -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