when adding to the keystroke buffer, filter out bad keystrokes with one

pass instead of two


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2177 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-12-08 15:47:38 +00:00
parent 32085a88e8
commit 263240c7c7
1 changed files with 15 additions and 26 deletions

View File

@ -191,30 +191,26 @@ void get_buffer(WINDOW *win)
buffer *clean_key_buffer = NULL; buffer *clean_key_buffer = NULL;
size_t clean_key_buffer_len = 0; size_t clean_key_buffer_len = 0;
/* Change all incomplete or invalid multibyte keystrokes to -1, /* Change all complete and valid multibyte keystrokes to
* and change all complete and valid multibyte keystrokes to * their wide character values, discarding the others. */
* their wide character values. */
for (i = 0; i < key_buffer_len; i++) { for (i = 0; i < key_buffer_len; i++) {
wchar_t wide_key; wchar_t wide_key;
int wide_key_len;
if (!key_buffer[i].key_code) { if (key_buffer[i].key_code) {
if (mbtowc(&wide_key, wide_key_len = 1;
(const char *)&key_buffer[i].key, 1) == -1) wide_key = key_buffer[i].key;
key_buffer[i].key = -1; } else
else wide_key_len = mbtowc(&wide_key,
key_buffer[i].key = wide_key; (const char *)&key_buffer[i].key, 1);
}
}
/* Save all of the non-(-1) keystrokes in another buffer. */ if (wide_key_len != -1) {
for (i = 0; i < key_buffer_len; i++) {
if (key_buffer[i].key != -1) {
clean_key_buffer_len++; clean_key_buffer_len++;
clean_key_buffer = (buffer *)nrealloc(clean_key_buffer, clean_key_buffer = (buffer *)nrealloc(clean_key_buffer,
clean_key_buffer_len * sizeof(buffer)); clean_key_buffer_len * sizeof(buffer));
clean_key_buffer[clean_key_buffer_len - 1].key = clean_key_buffer[clean_key_buffer_len - 1].key =
key_buffer[i].key; wide_key;
clean_key_buffer[clean_key_buffer_len - 1].key_code = clean_key_buffer[clean_key_buffer_len - 1].key_code =
key_buffer[i].key_code; key_buffer[i].key_code;
} }
@ -264,20 +260,13 @@ void unget_input(buffer *input, size_t input_len)
if (!ISSET(NO_UTF8)) { if (!ISSET(NO_UTF8)) {
size_t i; size_t i;
/* Change all invalid wide character values to -1. */ /* Keep all valid wide keystrokes, discarding the others. */
for (i = 0; i < input_len; i++) { for (i = 0; i < input_len; i++) {
char key[MB_LEN_MAX]; char key[MB_LEN_MAX];
int key_len = input[i].key_code ? 1 :
wctomb(key, input[i].key);
if (!input[i].key_code) { if (key_len != -1) {
if (wctomb(key, input[i].key) == -1)
input[i].key = -1;
}
}
/* Save all of the non-(-1) wide characters in another
* buffer. */
for (i = 0; i < input_len; i++) {
if (input[i].key != -1) {
clean_input_len++; clean_input_len++;
clean_input = (buffer *)nrealloc(clean_input, clean_input = (buffer *)nrealloc(clean_input,
clean_input_len * sizeof(buffer)); clean_input_len * sizeof(buffer));