in parse_escape_seq_kbinput(), handle unknown and unignored escape

sequences once instead of handling them twice in parse_kbinput()


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3807 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
David Lawrence Ramsey 2006-07-23 17:54:35 +00:00
parent 19f3bd6546
commit 5370b0cd19
3 changed files with 23 additions and 32 deletions

View File

@ -141,6 +141,9 @@ CVS code -
- If they're defined, translate KEY_SUP into NANO_PREVLINE_KEY - If they're defined, translate KEY_SUP into NANO_PREVLINE_KEY
and KEY_SDOWN into NANO_NEXTLINE_KEY, since they are sometimes and KEY_SDOWN into NANO_NEXTLINE_KEY, since they are sometimes
generated by Shift-Up and Shift-Down. (DLR) generated by Shift-Up and Shift-Down. (DLR)
parse_escape_seq_kbinput()
- Handle unknown and unignored escape sequences once here
instead of twice in parse_kbinput(). (DLR)
display_string() display_string()
- Properly handle buf[start_index]'s being a null terminator. - Properly handle buf[start_index]'s being a null terminator.
(DLR) (DLR)

View File

@ -735,7 +735,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 int get_escape_seq_kbinput(const int *seq, size_t seq_len, bool
*ignore_seq); *ignore_seq);
int get_escape_seq_abcd(int kbinput); int get_escape_seq_abcd(int kbinput);
int parse_escape_seq_kbinput(int kbinput, bool *ignore_seq); int parse_escape_seq_kbinput(WINDOW *win, int kbinput);
int get_byte_kbinput(int kbinput); int get_byte_kbinput(int kbinput);
#ifdef ENABLE_UTF8 #ifdef ENABLE_UTF8
long add_unicode_digit(int kbinput, long factor, long *uni); long add_unicode_digit(int kbinput, long factor, long *uni);

View File

@ -377,18 +377,8 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
* there are other keystrokes waiting: escape * there are other keystrokes waiting: escape
* sequence mode. Interpret the escape * sequence mode. Interpret the escape
* sequence. */ * sequence. */
bool ignore_seq; retval = parse_escape_seq_kbinput(win,
*kbinput);
retval = parse_escape_seq_kbinput(*kbinput,
&ignore_seq);
/* If the escape sequence is unrecognized and
* not ignored, throw it out. */
if (retval == ERR && !ignore_seq) {
if (win == edit)
statusbar(_("Unknown Command"));
beep();
}
} }
break; break;
case 2: case 2:
@ -470,20 +460,10 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
* meta and escape sequence mode. Reset the * meta and escape sequence mode. Reset the
* escape counter, set meta_key to TRUE, and * escape counter, set meta_key to TRUE, and
* interpret the escape sequence. */ * interpret the escape sequence. */
bool ignore_seq;
escapes = 0; escapes = 0;
*meta_key = TRUE; *meta_key = TRUE;
retval = parse_escape_seq_kbinput(*kbinput, retval = parse_escape_seq_kbinput(win,
&ignore_seq); *kbinput);
/* If the escape sequence is unrecognized and
* not ignored, throw it out. */
if (retval == ERR && !ignore_seq) {
if (win == edit)
statusbar(_("Unknown Command"));
beep();
}
} }
break; break;
} }
@ -1196,14 +1176,13 @@ int get_escape_seq_abcd(int kbinput)
} }
/* Interpret the escape sequence in the keystroke buffer, the first /* Interpret the escape sequence in the keystroke buffer, the first
* character of which is kbinput. If we want to ignore the escape * character of which is kbinput. Assume that the keystroke buffer
* sequence, set retval to ERR and ignore_seq to TRUE. Assume that the * isn't empty, and that the initial escape has already been read in. */
* keystroke buffer isn't empty, and that the initial escape has already int parse_escape_seq_kbinput(WINDOW *win, int kbinput)
* been read in. */
int parse_escape_seq_kbinput(int kbinput, bool *ignore_seq)
{ {
int retval, *seq; int retval, *seq;
size_t seq_len; size_t seq_len;
bool ignore_seq;
/* Put back the non-escape character, get the complete escape /* Put back the non-escape character, get the complete escape
* sequence, translate the sequence into its corresponding key * sequence, translate the sequence into its corresponding key
@ -1211,12 +1190,21 @@ int parse_escape_seq_kbinput(int kbinput, bool *ignore_seq)
unget_input(&kbinput, 1); unget_input(&kbinput, 1);
seq_len = get_key_buffer_len(); seq_len = get_key_buffer_len();
seq = get_input(NULL, seq_len); seq = get_input(NULL, seq_len);
retval = get_escape_seq_kbinput(seq, seq_len, ignore_seq); retval = get_escape_seq_kbinput(seq, seq_len, &ignore_seq);
free(seq); free(seq);
/* If we got an unrecognized escape sequence, and it's not ignored,
* throw it out. */
if (retval == ERR && !ignore_seq) {
if (win == edit)
statusbar(_("Unknown Command"));
beep();
}
}
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "parse_escape_seq_kbinput(): kbinput = %d, ignore_seq = %s, seq_len = %lu, retval = %d\n", kbinput, *ignore_seq ? "TRUE" : "FALSE", (unsigned long)seq_len, retval); fprintf(stderr, "parse_escape_seq_kbinput(): kbinput = %d, ignore_seq = %s, seq_len = %lu, retval = %d\n", kbinput, ignore_seq ? "TRUE" : "FALSE", (unsigned long)seq_len, retval);
#endif #endif
return retval; return retval;