Ticket #2988: When an unknown key is pressed, it is interpreted as garbage.

keyboard input: simplify code, no logic changes

This change slightly simplifies and rearranges the code
in get_key_code(), reduces indentation levels there,
adds a few comments. The logic remains the same.

This is a preparatory patch for subsequent changes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Denys Vlasenko 2013-05-20 15:34:21 +03:00 committed by Slava Zanko
parent f09b3198ec
commit 77cfaf03cb

View File

@ -2,7 +2,7 @@
Keyboard support routines.
Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006, 2007, 2009, 2010, 2011
2005, 2006, 2007, 2009, 2010, 2011, 2013
The Free Software Foundation, Inc.
Written by:
@ -10,6 +10,8 @@
Janne Kukonlehto, 1994, 1995
Jakub Jelinek, 1995
Norbert Warmuth, 1997
Denys Vlasenko <vda.linux@googlemail.com>, 2013
Slava Zanko <slavazanko@gmail.com>, 2013
This file is part of the Midnight Commander.
@ -1747,7 +1749,7 @@ get_key_code (int no_delay)
int d;
d = *pending_keys++;
while (d == ESC_CHAR && *pending_keys != '\0')
while (d == ESC_CHAR)
d = ALT (*pending_keys++);
if (*pending_keys == '\0')
@ -1828,12 +1830,22 @@ get_key_code (int no_delay)
this = keys->child;
}
}
while (this != NULL)
{
if (c == this->ch)
{
if (this->child)
if (!this->child)
{
/* We got a complete match, return and reset search */
int code;
pending_keys = seq_append = NULL;
code = this->code;
this = NULL;
return correct_key_code (code);
}
/* No match yet, but it may be a prefix for a valid seq */
if (!push_char (c))
{
pending_keys = seq_buffer;
@ -1846,12 +1858,6 @@ get_key_code (int no_delay)
if (no_delay)
{
GET_TIME (esctime);
if (this == NULL)
{
/* Shouldn't happen */
fputs ("Internal error\n", stderr);
exit (EXIT_FAILURE);
}
goto nodelay_try_again;
}
esctime.tv_sec = -1;
@ -1862,31 +1868,22 @@ get_key_code (int no_delay)
this = NULL;
return ESC_CHAR;
}
continue;
}
else
{
if (no_delay)
goto nodelay_try_again;
c = tty_lowlevel_getch ();
continue;
}
}
else
{
/* We got a complete match, return and reset search */
int code;
pending_keys = seq_append = NULL;
code = this->code;
this = NULL;
return correct_key_code (code);
}
}
else
{
/* c != this->ch. Try other keys with this prefix */
if (this->next != NULL)
this = this->next;
else
{
this = this->next;
continue;
}
/* No match found. Is it one of our ESC <key> specials? */
if ((parent != NULL) && (parent->action == MCKEY_ESCAPE))
{
/* Convert escape-digits to F-keys */
@ -1901,15 +1898,14 @@ get_key_code (int no_delay)
this = NULL;
return correct_key_code (c);
}
/* Did not find a match or {c} was changed in the if above,
so we have to return everything we had skipped
*/
/* Unknown sequence. Maybe a prefix of a longer one. Save it. */
push_char (c);
pending_keys = seq_buffer;
goto pend_send;
}
}
}
} /* while (this != NULL) */
this = NULL;
return correct_key_code (c);
}