Commit 2c8b99d5 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

tweaks: condense and rewrap some comments, and reindent two lines

Also drop an old debugging fragment.
No related merge requests found
Showing with 12 additions and 22 deletions
+12 -22
...@@ -1270,13 +1270,15 @@ int parse_escape_sequence(WINDOW *win, int kbinput) ...@@ -1270,13 +1270,15 @@ int parse_escape_sequence(WINDOW *win, int kbinput)
return retval; return retval;
} }
/* Translate a byte sequence: turn a three-digit decimal number (from /* Turn a three-digit decimal number (from 000 to 255) into its corresponding
* 000 to 255) into its corresponding byte value. */ * byte value. */
int get_byte_kbinput(int kbinput) int get_byte_kbinput(int kbinput)
{ {
static int byte = 0; static int byte = 0;
int retval = ERR; int retval = ERR;
/* 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. */
switch (++byte_digits) { switch (++byte_digits) {
case 1: case 1:
/* First digit: This must be from zero to two. Put it in /* First digit: This must be from zero to two. Put it in
...@@ -1284,36 +1286,28 @@ int get_byte_kbinput(int kbinput) ...@@ -1284,36 +1286,28 @@ int get_byte_kbinput(int kbinput)
if ('0' <= kbinput && kbinput <= '2') if ('0' <= kbinput && kbinput <= '2')
byte = (kbinput - '0') * 100; byte = (kbinput - '0') * 100;
else else
/* This isn't the start of a byte sequence. Return this
* character as the result. */
retval = kbinput; retval = kbinput;
break; break;
case 2: case 2:
/* Second digit: This must be from zero to five if the first /* Second digit: This must be from zero to five if the first was
* was two, and may be any decimal value if the first was * two, and may be any decimal value if the first was zero or one.
* zero or one. Put it in the 10's position of the byte * Put it in the 10's position of the byte sequence holder. */
* 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;
else else
/* This isn't the second digit of a byte sequence.
* Return this character as the result. */
retval = kbinput; retval = kbinput;
break; break;
case 3: case 3:
/* Third digit: This must be from zero to five if the first /* Third digit: Must be from zero to five if the first was two and
* was two and the second was five, and may be any decimal * the second was five, and may be any decimal value otherwise.
* value otherwise. Put it in the 1's position of the byte * Put it in the 1's position of the byte sequence holder. */
* sequence holder. */
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';
/* The byte sequence is complete. */ /* The byte sequence is complete. */
retval = byte; retval = byte;
} else } else
/* This isn't the third digit of a byte sequence.
* Return this character as the result. */
retval = kbinput; retval = kbinput;
break; break;
} }
...@@ -1324,10 +1318,6 @@ int get_byte_kbinput(int kbinput) ...@@ -1324,10 +1318,6 @@ int get_byte_kbinput(int kbinput)
byte = 0; byte = 0;
} }
#ifdef DEBUG
fprintf(stderr, "get_byte_kbinput(): kbinput = %d, byte_digits = %d, byte = %d, retval = %d\n", kbinput, byte_digits, byte, retval);
#endif
return retval; return retval;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment