tweaks: optimize for byte-range characters, and shorten some comments

master
Benno Schulenberg 2020-08-05 09:37:22 +02:00
parent f80ce71d13
commit cc6d1d59a6
1 changed files with 10 additions and 10 deletions

View File

@ -930,9 +930,14 @@ int parse_kbinput(WINDOW *win)
} }
if (escapes == 0) { if (escapes == 0) {
/* Most key codes in byte range cannot be special keys. */
if (keycode <= 0xFF && keycode != '\t' && keycode != DEL_CODE)
return keycode;
else
retval = keycode; retval = keycode;
} else if (escapes == 1) { } else if (escapes == 1) {
escapes = 0; escapes = 0;
/* Key codes out of ASCII range cannot form escape sequences. */
if (keycode >= 0x80) { if (keycode >= 0x80) {
#ifndef NANO_TINY #ifndef NANO_TINY
if (keycode == KEY_BACKSPACE) if (keycode == KEY_BACKSPACE)
@ -948,8 +953,6 @@ int parse_kbinput(WINDOW *win)
meta_key = TRUE; meta_key = TRUE;
retval = (shifted_metas) ? keycode : tolower(keycode); retval = (shifted_metas) ? keycode : tolower(keycode);
} else } else
/* One escape followed by a non-escape, and there
* are more codes waiting: escape sequence mode. */
retval = parse_escape_sequence(keycode); retval = parse_escape_sequence(keycode);
} else { } else {
escapes = 0; escapes = 0;
@ -979,21 +982,18 @@ int parse_kbinput(WINDOW *win)
meta_key = TRUE; meta_key = TRUE;
} else if ('0' <= keycode && (keycode <= '2' || } else if ('0' <= keycode && (keycode <= '2' ||
(keycode <= '9' && digit_count > 0))) { (keycode <= '9' && digit_count > 0))) {
/* Two escapes followed by one digit, and no other codes /* Two escapes followed by one digit: byte sequence mode. */
* are waiting: byte sequence mode. If the range of the
* sequence of digits is limited to 2XX, interpret it. */
int byte = assemble_byte_code(keycode); int byte = assemble_byte_code(keycode);
/* If the decimal byte value is not yet complete, /* If the decimal byte value is not yet complete, return nothing. */
* return nothing; otherwise convert it and put the
* obtained byte(s) back into the input buffer. */
if (byte == PROCEED) { if (byte == PROCEED) {
escapes = 2; escapes = 2;
return ERR; return ERR;
} }
#ifdef ENABLE_UTF8 #ifdef ENABLE_UTF8
else if (byte > 0x7F && using_utf8()) { else if (byte > 0x7F && using_utf8()) {
/* Convert the code to the corresponding Unicode. */ /* Convert the code to the corresponding Unicode, and
* put the second byte back into the keyboard buffer. */
if (byte < 0xC0) { if (byte < 0xC0) {
put_back((unsigned char)byte); put_back((unsigned char)byte);
return 0xC2; return 0xC2;