add UTF-8 support to unget_kbinput(), and fix a minor memory leak in the

UTF-8 support code in get_kbinput()


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2015 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-10-23 02:47:39 +00:00
parent bf1346f342
commit c59979f067
5 changed files with 38 additions and 12 deletions

View File

@ -53,8 +53,9 @@ CVS code -
- Add a func_key flag to the low-level input functions and the
currently existing high-level input functions, to indicate
extended keypad values. This is needed for UTF-8 support.
Changes to get_kbinput(), get_translated_kbinput(),
get_shortcut(), get_edit_input(), etc. (DLR)
Changes to unget_kbinput(), get_kbinput(),
get_translated_kbinput(), get_shortcut(), get_edit_input(),
etc. (DLR)
- Add a multibuffer mode toggle to the "Execute Command" prompt,
for consistency with the "Read File" prompt. Changes to
do_insertfile() and shortcut_init(). (DLR)

View File

@ -2624,8 +2624,10 @@ char *do_browser(const char *inpath)
if (selected > numents - 1)
selected = numents - 1;
else if (selectedbackup == selected)
unget_kbinput('s', FALSE); /* Unget the 'select' key */
} else { /* Must be clicking a shortcut */
/* Unget the 'select' key */
unget_kbinput('s', FALSE, FALSE);
} else {
/* Must be clicking a shortcut */
int mouse_x, mouse_y;
get_mouseinput(&mouse_x, &mouse_y, TRUE);
}

View File

@ -2671,7 +2671,7 @@ void do_justify(bool full_justify)
edit_refresh();
} else {
placewewant = 0;
unget_kbinput(kbinput, meta_key);
unget_kbinput(kbinput, meta_key, func_key);
}
cutbuffer = cutbuffer_save;

View File

@ -502,7 +502,7 @@ int check_wildcard_match(const char *text, const char *pattern);
#ifndef NANO_SMALL
void reset_kbinput(void);
#endif
void unget_kbinput(int kbinput, bool meta_key);
void unget_kbinput(int kbinput, bool meta_key, bool func_key);
int get_kbinput(WINDOW *win, bool *meta_key, bool *func_key);
int get_translated_kbinput(int kbinput, seq_type *seq
#ifndef NANO_SMALL

View File

@ -104,8 +104,28 @@ void reset_kbinput(void)
/* Put back the input character stored in kbinput. If meta_key is TRUE,
* put back the Escape character after putting back kbinput. */
void unget_kbinput(int kbinput, bool meta_key)
void unget_kbinput(int kbinput, bool meta_key, bool func_key)
{
/* If this character is outside the ASCII range and func_key is
* FALSE, treat it as a wide character and put back its equivalent
* multibyte sequence. */
if (kbinput > 255 && !func_key)
{
int i;
char *s = charalloc(MB_CUR_MAX + 1);
wchar_t wc = (wchar_t)kbinput;
i = wctomb(s, wc);
if (i == -1)
/* This wide character is unrecognized. Send it back. */
ungetch(kbinput);
else {
for (; i > 0; i--)
ungetch(s[i - 1]);
}
free(s);
} else
ungetch(kbinput);
if (meta_key)
ungetch(NANO_CONTROL_3);
@ -181,7 +201,8 @@ int get_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
/* This escape sequence is unrecognized. Send
* it back. */
for (; seq_len > 1; seq_len--)
unget_kbinput(sequence[seq_len - 1], FALSE);
unget_kbinput(sequence[seq_len - 1], FALSE,
FALSE);
retval = sequence[0];
}
}
@ -203,10 +224,12 @@ int get_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
/* This UTF-8 sequence is unrecognized. Send it
* back. */
for (; seq_len > 1; seq_len--)
unget_kbinput(sequence[seq_len - 1], FALSE);
unget_kbinput(sequence[seq_len - 1], FALSE,
FALSE);
retval = sequence[0];
} else
retval = wc;
free(s);
}
free(sequence);
}
@ -1365,9 +1388,9 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
* has, at the very least, an equivalent control key, an
* equivalent primary meta key sequence, or both. */
if (s->ctrlval != NANO_NO_KEY)
unget_kbinput(s->ctrlval, FALSE);
unget_kbinput(s->ctrlval, FALSE, FALSE);
else if (s->metaval != NANO_NO_KEY)
unget_kbinput(s->metaval, TRUE);
unget_kbinput(s->metaval, TRUE, FALSE);
return TRUE;
}