tweaks: rename a variable, and further condense some comments

master
Benno Schulenberg 2018-01-11 12:47:42 +01:00
parent 2c8b99d5e9
commit eb1bf8f927
1 changed files with 15 additions and 17 deletions

View File

@ -40,7 +40,7 @@ static size_t key_buffer_len = 0;
/* The length of the keystroke buffer. */ /* The length of the keystroke buffer. */
static bool solitary = FALSE; static bool solitary = FALSE;
/* Whether an Esc arrived by itself -- not as leader of a sequence. */ /* Whether an Esc arrived by itself -- not as leader of a sequence. */
static int byte_digits = 0; static int digit_count = 0;
/* How many digits of a three-digit character code we've eaten. */ /* How many digits of a three-digit character code we've eaten. */
static bool waiting_mode = TRUE; static bool waiting_mode = TRUE;
/* Whether getting a character will wait for a key to be pressed. */ /* Whether getting a character will wait for a key to be pressed. */
@ -372,8 +372,8 @@ int parse_kbinput(WINDOW *win)
free(kbinput); free(kbinput);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "before parsing: keycode = %d, escapes = %d, byte_digits = %d\n", fprintf(stderr, "before parsing: keycode = %d, escapes = %d, digit_count = %d\n",
keycode, escapes, byte_digits); keycode, escapes, digit_count);
#endif #endif
if (keycode == ERR) if (keycode == ERR)
@ -445,8 +445,8 @@ int parse_kbinput(WINDOW *win)
double_esc = FALSE; double_esc = FALSE;
escapes = 0; escapes = 0;
} else if (key_buffer_len == 0) { } else if (key_buffer_len == 0) {
if ('0' <= keycode && ((keycode <= '2' && byte_digits == 0) || if ('0' <= keycode && ((keycode <= '2' && digit_count == 0) ||
(keycode <= '9' && byte_digits > 0))) { (keycode <= '9' && digit_count > 0))) {
/* Two escapes followed by one or more decimal /* Two escapes followed by one or more decimal
* digits, and there aren't any other codes * digits, and there aren't any other codes
* waiting: byte sequence mode. If the range of the * waiting: byte sequence mode. If the range of the
@ -473,7 +473,7 @@ int parse_kbinput(WINDOW *win)
escapes = 0; escapes = 0;
} }
} else { } else {
if (byte_digits == 0) if (digit_count == 0)
/* Two escapes followed by a non-decimal /* Two escapes followed by a non-decimal
* digit (or a decimal digit that would * digit (or a decimal digit that would
* create a byte sequence greater than 2XX) * create a byte sequence greater than 2XX)
@ -484,7 +484,7 @@ int parse_kbinput(WINDOW *win)
/* An invalid digit in the middle of a byte /* An invalid digit in the middle of a byte
* sequence: reset the byte sequence counter * sequence: reset the byte sequence counter
* and save the code we got as the result. */ * and save the code we got as the result. */
byte_digits = 0; digit_count = 0;
retval = keycode; retval = keycode;
} }
escapes = 0; escapes = 0;
@ -1279,19 +1279,17 @@ int get_byte_kbinput(int kbinput)
/* Check that the given digit is within the allowed range for its position. /* Check that the given digit is within the allowed range for its position.
* If yes, store it. If no, return the digit (or character) itself. */ * If yes, store it. If no, return the digit (or character) itself. */
switch (++byte_digits) { switch (++digit_count) {
case 1: case 1:
/* First digit: This must be from zero to two. Put it in /* The first digit (the 100's position) must be from zero to two. */
* the 100's position of the byte sequence holder. */
if ('0' <= kbinput && kbinput <= '2') if ('0' <= kbinput && kbinput <= '2')
byte = (kbinput - '0') * 100; byte = (kbinput - '0') * 100;
else else
retval = kbinput; retval = kbinput;
break; break;
case 2: case 2:
/* Second digit: This must be from zero to five if the first was /* The second digit (the 10's position) must be from zero to five
* two, and may be any decimal value if the first was zero or one. * if the first was two, and may be any decimal value otherwise. */
* Put it in the 10's position of the byte sequence holder. */
if (('0' <= kbinput && kbinput <= '5') || (byte < 200 && if (('0' <= kbinput && kbinput <= '5') || (byte < 200 &&
'6' <= kbinput && kbinput <= '9')) '6' <= kbinput && kbinput <= '9'))
byte += (kbinput - '0') * 10; byte += (kbinput - '0') * 10;
@ -1299,9 +1297,9 @@ int get_byte_kbinput(int kbinput)
retval = kbinput; retval = kbinput;
break; break;
case 3: case 3:
/* Third digit: Must be from zero to five if the first was two and /* The third digit (the 1's position) must be from zero to five
* the second was five, and may be any decimal value otherwise. * if the first was two and the second was five, and may be any
* Put it in the 1's position of the byte sequence holder. */ * decimal value otherwise. */
if (('0' <= kbinput && kbinput <= '5') || (byte < 250 && if (('0' <= kbinput && kbinput <= '5') || (byte < 250 &&
'6' <= kbinput && kbinput <= '9')) { '6' <= kbinput && kbinput <= '9')) {
byte += kbinput - '0'; byte += kbinput - '0';
@ -1314,7 +1312,7 @@ int get_byte_kbinput(int kbinput)
/* If we have a result, reset the counter and the byte holder. */ /* If we have a result, reset the counter and the byte holder. */
if (retval != ERR) { if (retval != ERR) {
byte_digits = 0; digit_count = 0;
byte = 0; byte = 0;
} }