diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 01:11:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 01:11:51 +0000 |
commit | a6f3675fc4e21b3f899286b9a02005368d913f74 (patch) | |
tree | c9bfa92b223783ff03b8e941c3bb0d36c68d3b5e /lib/tty/key.c | |
parent | Releasing progress-linux version 3:4.8.30-1~progress7.99u1. (diff) | |
download | mc-a6f3675fc4e21b3f899286b9a02005368d913f74.tar.xz mc-a6f3675fc4e21b3f899286b9a02005368d913f74.zip |
Merging upstream version 3:4.8.31.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/tty/key.c')
-rw-r--r-- | lib/tty/key.c | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/lib/tty/key.c b/lib/tty/key.c index 5671666..8e7770b 100644 --- a/lib/tty/key.c +++ b/lib/tty/key.c @@ -1,7 +1,7 @@ /* Keyboard support routines. - Copyright (C) 1994-2023 + Copyright (C) 1994-2024 Free Software Foundation, Inc. Written by: @@ -1173,28 +1173,19 @@ getch_with_timeout (unsigned int delay_us) /* --------------------------------------------------------------------------------------------- */ static void -learn_store_key (char *buffer, char **p, int c) +learn_store_key (GString * buffer, int c) { - if (*p - buffer > 253) - return; - if (c == ESC_CHAR) - { - *(*p)++ = '\\'; - *(*p)++ = 'e'; - } + g_string_append (buffer, "\\e"); else if (c < ' ') { - *(*p)++ = '^'; - *(*p)++ = c + 'a' - 1; + g_string_append_c (buffer, '^'); + g_string_append_c (buffer, c + 'a' - 1); } else if (c == '^') - { - *(*p)++ = '^'; - *(*p)++ = '^'; - } + g_string_append (buffer, "^^"); else - *(*p)++ = (char) c; + g_string_append_c (buffer, (char) c); } /* --------------------------------------------------------------------------------------------- */ @@ -2163,14 +2154,15 @@ learn_key (void) fd_set Read_FD_Set; gint64 end_time; int c; - char buffer[256]; - char *p = buffer; + GString *buffer; + + buffer = g_string_sized_new (16); tty_keypad (FALSE); /* disable interpreting keys by ncurses */ c = tty_lowlevel_getch (); while (c == -1) c = tty_lowlevel_getch (); /* Sanity check, should be unnecessary */ - learn_store_key (buffer, &p, c); + learn_store_key (buffer, c); end_time = g_get_monotonic_time () + LEARN_TIMEOUT * MC_USEC_PER_MSEC; @@ -2194,12 +2186,12 @@ learn_key (void) } if (c == -1) break; - learn_store_key (buffer, &p, c); + learn_store_key (buffer, c); } tty_keypad (TRUE); tty_nodelay (FALSE); - *p = '\0'; - return (buffer[0] != '\0' ? g_strdup (buffer) : NULL); + + return g_string_free (buffer, buffer->len == 0); #undef LEARN_TIMEOUT } |