nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 57c52de99a43d6cdd8c81d7e1987068b5fbdfebd
parent 9067f7a0c786fc733986f70c2b9731e085c759c8
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Mon, 20 Jul 2020 17:04:48 +0200

tweaks: rename a function, and move it to before the one that calls it

Diffstat:
Msrc/prototypes.h | 1-
Msrc/winio.c | 74+++++++++++++++++++++++++++++++++++++-------------------------------------
2 files changed, 37 insertions(+), 38 deletions(-)

diff --git a/src/prototypes.h b/src/prototypes.h @@ -587,7 +587,6 @@ void implant(const char *string); #endif int parse_kbinput(WINDOW *win); int get_kbinput(WINDOW *win, bool showcursor); -int get_byte_kbinput(int kbinput); char *get_verbatim_kbinput(WINDOW *win, size_t *count); #ifdef ENABLE_MOUSE int get_mouseinput(int *mouse_y, int *mouse_x, bool allow_shortcuts); diff --git a/src/winio.c b/src/winio.c @@ -835,6 +835,42 @@ int parse_escape_sequence(int firstbyte) return keycode; } +#define PROCEED -44 + +/* Turn a three-digit decimal number (from 000 to 255) into its corresponding + * byte value. */ +int assemble_byte_code(int kbinput) +{ + static int byte = 0; + + /* 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 (++digit_count) { + case 1: + /* The first digit (the 100's position) is from zero to two. */ + byte = (kbinput - '0') * 100; + return PROCEED; + case 2: + /* The second digit (the 10's position) must be from zero to five + * if the first was two, and may be any decimal value otherwise. */ + if (byte < 200 || kbinput <= '5') { + byte += (kbinput - '0') * 10; + return PROCEED; + } else + return kbinput; + case 3: + /* The third digit (the 1's position) must be from zero to five + * if the first was two and the second was five, and may be any + * decimal value otherwise. */ + if (byte < 250 || kbinput <= '5') { + return (byte + kbinput - '0'); + } else + return kbinput; + } + + return 0; /* FIXME: this suppresses a compilation warning */ +} + /* Translate a normal ASCII character into its corresponding control code. * The following groups of control keystrokes are equivalent: * Ctrl-2 == Ctrl-@ == Ctrl-` == Ctrl-Space @@ -862,8 +898,6 @@ int convert_to_control(int kbinput) return kbinput; } -#define PROCEED -44 - /* Extract one keystroke from the input stream. Translate escape sequences * and possibly keypad codes into their corresponding values. Set meta_key * to TRUE when appropriate. Supported keypad keystrokes are: the arrow keys, @@ -958,7 +992,7 @@ int parse_kbinput(WINDOW *win) /* Two escapes followed by one digit, and no other codes * are waiting: byte sequence mode. If the range of the * byte sequence is limited to 2XX, interpret it. */ - int byte = get_byte_kbinput(keycode); + int byte = assemble_byte_code(keycode); /* If the decimal byte value is complete, convert it and * put the obtained byte(s) back into the input buffer. */ @@ -1315,40 +1349,6 @@ int get_kbinput(WINDOW *win, bool showcursor) return kbinput; } -/* Turn a three-digit decimal number (from 000 to 255) into its corresponding - * byte value. */ -int get_byte_kbinput(int kbinput) -{ - static int byte = 0; - - /* 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 (++digit_count) { - case 1: - /* The first digit (the 100's position) is from zero to two. */ - byte = (kbinput - '0') * 100; - return PROCEED; - case 2: - /* The second digit (the 10's position) must be from zero to five - * if the first was two, and may be any decimal value otherwise. */ - if (byte < 200 || kbinput <= '5') { - byte += (kbinput - '0') * 10; - return PROCEED; - } else - return kbinput; - case 3: - /* The third digit (the 1's position) must be from zero to five - * if the first was two and the second was five, and may be any - * decimal value otherwise. */ - if (byte < 250 || kbinput <= '5') { - return (byte + kbinput - '0'); - } else - return kbinput; - } - - return 0; /* FIXME: this suppresses a compilation warning */ -} - #ifdef ENABLE_UTF8 /* If the character in kbinput is a valid hexadecimal digit, multiply it * by factor and add the result to uni, and return PROCEED to signify okay. */