From: David Lawrence Ramsey Date: Thu, 25 May 2006 22:10:27 +0000 (+0000) Subject: remove duplicate escape sequence-interpreting code X-Git-Tag: v1.3.12~114 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=1320d29267b6953608a7ac4e7def4de2e43eeacb;p=nano.git remove duplicate escape sequence-interpreting code git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3566 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 3295fd04..79910ba9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -285,6 +285,9 @@ CVS code - (DLR) - If we get Escape followed by an escape sequence, interpret the escape sequence for consistency. (DLR) + parse_escape_seq_kbinput() + - New function used to interpret escape sequences, formerly part + of parse_kbinput(). (DLR) get_control_kbinput() - Add Ctrl-/ as an alias for Ctrl-_. (DLR, found by Benno Schulenberg) diff --git a/src/proto.h b/src/proto.h index b55e8fa9..8cba71b2 100644 --- a/src/proto.h +++ b/src/proto.h @@ -726,6 +726,7 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key); int get_escape_seq_kbinput(const int *seq, size_t seq_len, bool *ignore_seq); int get_escape_seq_abcd(int kbinput); +int parse_escape_seq_kbinput(int kbinput); int get_byte_kbinput(int kbinput); long get_unicode_kbinput(int kbinput); int get_control_kbinput(int kbinput); diff --git a/src/winio.c b/src/winio.c index f31f823b..526a4166 100644 --- a/src/winio.c +++ b/src/winio.c @@ -520,29 +520,8 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key) if (get_key_buffer_len() == 0) { *meta_key = TRUE; retval = tolower(*kbinput); - } else { - int *seq; - size_t seq_len; - bool ignore_seq; - - /* Put back the non-escape character, get the - * complete escape sequence, translate the - * sequence into its corresponding key value, - * and save that as the result. */ - unget_input(kbinput, 1); - seq_len = get_key_buffer_len(); - seq = get_input(NULL, seq_len); - retval = get_escape_seq_kbinput(seq, seq_len, - &ignore_seq); - - /* If the escape sequence is unrecognized and - * not ignored, throw it out, and indicate this - * on the statusbar. */ - if (retval == ERR && !ignore_seq) - statusbar(_("Unknown Command")); - - free(seq); - } + } else + retval = parse_escape_seq_kbinput(*kbinput); break; case 2: /* Two escapes followed by one or more decimal @@ -619,29 +598,8 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key) byte_digits = 0; retval = *kbinput; } - } else { - int *seq; - size_t seq_len; - bool ignore_seq; - - /* Put back the non-escape character, get the - * complete escape sequence, translate the - * sequence into its corresponding key value, - * and save that as the result. */ - unget_input(kbinput, 1); - seq_len = get_key_buffer_len(); - seq = get_input(NULL, seq_len); - retval = get_escape_seq_kbinput(seq, seq_len, - &ignore_seq); - - /* If the escape sequence is unrecognized and - * not ignored, throw it out, and indicate this - * on the statusbar. */ - if (retval == ERR && !ignore_seq) - statusbar(_("Unknown Command")); - - free(seq); - } + } else + retval = parse_escape_seq_kbinput(*kbinput); break; } } @@ -1194,6 +1152,37 @@ int get_escape_seq_abcd(int kbinput) } } +/* Interpret the escape sequence in the keystroke buffer, the first + * character of which is kbinput. Assume that the keystroke buffer + * isn't empty, and that the initial escape has already been read in. */ +int parse_escape_seq_kbinput(int kbinput) +{ + int retval, *seq; + size_t seq_len; + bool ignore_seq; + + /* Put back the non-escape character, get the complete escape + * sequence, translate the sequence into its corresponding key + * value, and save that as the result. */ + unget_input(&kbinput, 1); + seq_len = get_key_buffer_len(); + seq = get_input(NULL, seq_len); + retval = get_escape_seq_kbinput(seq, seq_len, &ignore_seq); + + /* If the escape sequence is unrecognized and not ignored, throw it + * out, and indicate this on the statusbar. */ + if (retval == ERR && !ignore_seq) + statusbar(_("Unknown Command")); + + free(seq); + +#ifdef DEBUG + fprintf(stderr, "parse_escape_seq_kbinput(): kbinput = %d, seq_len = %lu, ignore_seq = %d, retval = %d\n", *kbinput, (unsigned long)seq_len, (int)ignore_seq, retval); +#endif + + return retval; +} + /* Translate a byte sequence: turn a three-digit decimal number from * 000 to 255 into its corresponding byte value. */ int get_byte_kbinput(int kbinput)