add: convert input in utf locale to needle

This commit is contained in:
Ilia Maslakov 2009-04-16 15:12:33 +00:00
parent 8529756be9
commit 2ce1042665
1 changed files with 48 additions and 12 deletions

View File

@ -44,6 +44,7 @@
#include "../src/tty.h" /* keys */
#include "../src/charsets.h" /* convert_from_input_c() */
#include "../src/selcodepage.h" /* do_select_codepage() */
#include "../src/main.h" /* display_codepage */
/*
* Ordinary translations. Note that the keys listed first take priority
@ -191,6 +192,8 @@ edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch)
int char_for_insertion = -1;
int i = 0;
int extmod = 0;
int c;
const edit_key_map_type *key_map = NULL;
switch (edit_key_emulation) {
case EDIT_KEY_EMULATION_NORMAL:
@ -243,23 +246,55 @@ edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch)
/* an ordinary insertable character */
if (x_key < 256 && !extmod) {
if ( edit->charpoint >= 4 ) {
edit->charpoint = 0;
edit->charbuf[edit->charpoint] = '\0';
}
if ( edit->charpoint < 4 ) {
edit->charbuf[edit->charpoint++] = x_key;
edit->charbuf[edit->charpoint] = '\0';
}
if (!edit->utf8) {
int c = convert_from_input_c (x_key);
if (is_printable (c)) {
char_for_insertion = c;
goto fin;
}
} else {
if (edit->charpoint >= MB_LEN_MAX) {
goto fin;
edit->charpoint = 0;
/* input from 8-bit locale */
if ( str_isutf8 (get_codepage_id( display_codepage )) == 1 ) {
c = convert_from_input_c (x_key);
if (is_printable (c)) {
char_for_insertion = c;
goto fin;
}
} else {
edit->charbuf[edit->charpoint + 1] = '\0';
int res = str_is_valid_char (edit->charbuf, edit->charpoint);
if (res < 0) {
if (res != -2) {
edit->charpoint = 0; /* broken multibyte char, skip */
goto fin;
}
/* not finised multibyte input (in meddle multibyte utf-8 char) */
goto fin;
} else {
if ( g_unichar_isprint (g_utf8_get_char(edit->charbuf)) ) {
c = convert_from_utf_to_current ( edit->charbuf );
edit->charbuf[0] = '\0';
edit->charpoint = 0;
if (is_printable (c)) {
char_for_insertion = c;
goto fin;
}
}
/* unprinteble utf input, skip it */
edit->charbuf[0] = '\0';
edit->charpoint = 0;
goto fin;
}
}
edit->charbuf[edit->charpoint] = x_key;
edit->charpoint++;
} else {
int res = str_is_valid_char (edit->charbuf, edit->charpoint);
mc_log("res:%i, edit->charpoint : %i\n",res, edit->charpoint);
if (res < 0) {
if (res != -2) {
edit->charpoint = 0; /* broken multibyte char, skip */
@ -271,6 +306,7 @@ edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch)
edit->charbuf[edit->charpoint]='\0';
edit->charpoint = 0;
if ( g_unichar_isprint (g_utf8_get_char(edit->charbuf))) {
mc_log("input:%s \n", edit->charbuf);
char_for_insertion = x_key;
goto fin;
}