2002-12-26 01:53:07 +03:00
|
|
|
/* Editor key translation.
|
2002-12-23 13:13:35 +03:00
|
|
|
|
2007-09-25 19:33:35 +04:00
|
|
|
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
|
|
|
2005, 2006, 2007 Free Software Foundation, Inc.
|
2005-02-07 10:31:19 +03:00
|
|
|
|
2002-12-23 13:13:35 +03:00
|
|
|
Authors: 1996, 1997 Paul Sheer
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2005-02-07 10:31:19 +03:00
|
|
|
|
2002-12-23 13:13:35 +03:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-05-27 07:35:10 +04:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
02110-1301, USA.
|
2002-12-23 13:13:35 +03:00
|
|
|
*/
|
|
|
|
|
2009-02-07 00:09:50 +03:00
|
|
|
/** \file
|
|
|
|
* \brief Source: editor key translation
|
|
|
|
*/
|
|
|
|
|
2002-12-23 13:13:35 +03:00
|
|
|
#include <config.h>
|
2005-02-22 20:00:36 +03:00
|
|
|
|
2005-07-20 15:56:30 +04:00
|
|
|
#include <assert.h>
|
2005-02-22 20:00:36 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "../src/global.h"
|
|
|
|
|
2009-06-14 19:18:27 +04:00
|
|
|
#include "edit-impl.h"
|
2002-12-23 13:13:35 +03:00
|
|
|
#include "edit-widget.h" /* edit->macro_i */
|
2009-04-29 17:13:12 +04:00
|
|
|
#include "editcmd_dialogs.h"
|
2009-05-08 14:01:05 +04:00
|
|
|
|
|
|
|
#include "../src/tty/tty.h" /* keys */
|
|
|
|
#include "../src/tty/key.h" /* KEY_M_SHIFT */
|
|
|
|
|
2009-11-07 14:17:38 +03:00
|
|
|
#include "../src/cmddef.h" /* list of commands */
|
|
|
|
#include "../src/keybind.h" /* lookup_keymap_command() */
|
2003-10-29 11:54:22 +03:00
|
|
|
#include "../src/charsets.h" /* convert_from_input_c() */
|
2009-04-16 19:12:33 +04:00
|
|
|
#include "../src/main.h" /* display_codepage */
|
2009-04-17 01:28:02 +04:00
|
|
|
#include "../src/strutil.h" /* str_isutf8 () */
|
2002-12-23 13:13:35 +03:00
|
|
|
|
2002-12-26 01:53:07 +03:00
|
|
|
/*
|
|
|
|
* Translate the keycode into either 'command' or 'char_for_insertion'.
|
2009-07-05 19:04:42 +04:00
|
|
|
* 'command' is one of the editor commands from cmddef.h.
|
2002-12-26 01:53:07 +03:00
|
|
|
*/
|
2002-12-23 13:13:35 +03:00
|
|
|
int
|
2002-12-26 01:53:07 +03:00
|
|
|
edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch)
|
2002-12-23 13:13:35 +03:00
|
|
|
{
|
2009-11-06 14:41:54 +03:00
|
|
|
unsigned long command = (unsigned long) CK_Insert_Char;
|
2002-12-23 13:13:35 +03:00
|
|
|
int char_for_insertion = -1;
|
2009-04-16 19:12:33 +04:00
|
|
|
int c;
|
2002-12-23 13:13:35 +03:00
|
|
|
|
|
|
|
/* an ordinary insertable character */
|
2009-10-23 21:58:01 +04:00
|
|
|
if (x_key < 256) {
|
2009-04-20 09:51:32 +04:00
|
|
|
#ifdef HAVE_CHARSET
|
2009-04-16 19:12:33 +04:00
|
|
|
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';
|
|
|
|
}
|
2002-12-23 13:13:35 +03:00
|
|
|
|
2009-04-18 18:50:05 +04:00
|
|
|
/* input from 8-bit locale */
|
|
|
|
if ( !utf8_display ) {
|
|
|
|
/* source in 8-bit codeset */
|
|
|
|
if (!edit->utf8) {
|
2009-10-19 20:42:18 +04:00
|
|
|
#endif /* HAVE_CHARSET */
|
2009-04-16 19:12:33 +04:00
|
|
|
c = convert_from_input_c (x_key);
|
|
|
|
if (is_printable (c)) {
|
|
|
|
char_for_insertion = c;
|
|
|
|
goto fin;
|
|
|
|
}
|
2009-04-20 09:51:32 +04:00
|
|
|
#ifdef HAVE_CHARSET
|
2009-04-18 18:50:05 +04:00
|
|
|
} else {
|
2009-09-20 23:43:56 +04:00
|
|
|
c = convert_from_input_c (x_key);
|
2009-04-20 13:01:47 +04:00
|
|
|
if (is_printable (c)) {
|
|
|
|
char_for_insertion = convert_from_8bit_to_utf_c2((unsigned char) x_key);
|
|
|
|
goto fin;
|
|
|
|
}
|
2009-04-18 18:50:05 +04:00
|
|
|
}
|
|
|
|
/* UTF-8 locale */
|
|
|
|
} else {
|
|
|
|
/* source in UTF-8 codeset */
|
|
|
|
if ( edit->utf8 ) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
char_for_insertion = x_key;
|
|
|
|
goto fin;
|
|
|
|
} else {
|
|
|
|
edit->charbuf[edit->charpoint]='\0';
|
|
|
|
edit->charpoint = 0;
|
|
|
|
if ( g_unichar_isprint (g_utf8_get_char(edit->charbuf))) {
|
|
|
|
char_for_insertion = x_key;
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 8-bit source */
|
2009-04-16 19:12:33 +04:00
|
|
|
} else {
|
|
|
|
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;
|
2009-04-20 18:46:22 +04:00
|
|
|
char_for_insertion = c;
|
|
|
|
goto fin;
|
2009-04-16 19:12:33 +04:00
|
|
|
}
|
|
|
|
/* unprinteble utf input, skip it */
|
|
|
|
edit->charbuf[0] = '\0';
|
|
|
|
edit->charpoint = 0;
|
|
|
|
}
|
2009-04-13 19:19:06 +04:00
|
|
|
}
|
|
|
|
}
|
2009-10-19 20:42:18 +04:00
|
|
|
#endif /* HAVE_CHARSET */
|
2002-12-23 13:13:35 +03:00
|
|
|
}
|
|
|
|
|
2002-12-26 01:53:07 +03:00
|
|
|
/* Commands specific to the key emulation */
|
2009-10-23 21:58:01 +04:00
|
|
|
if (edit->extmod) {
|
|
|
|
edit->extmod = 0;
|
2009-11-07 14:17:38 +03:00
|
|
|
command = lookup_keymap_command (editor_x_map, x_key);
|
|
|
|
} else
|
|
|
|
command = lookup_keymap_command (editor_map, x_key);
|
|
|
|
|
|
|
|
if (command == CK_Ignore_Key)
|
|
|
|
command = CK_Insert_Char;
|
|
|
|
|
2002-12-23 13:13:35 +03:00
|
|
|
fin:
|
2009-11-06 14:41:54 +03:00
|
|
|
*cmd = (int) command; /* FIXME */
|
2002-12-23 13:13:35 +03:00
|
|
|
*ch = char_for_insertion;
|
|
|
|
|
2009-11-06 14:41:54 +03:00
|
|
|
return (command == (unsigned long) CK_Insert_Char && char_for_insertion == -1) ? 0 : 1;
|
2002-12-23 13:13:35 +03:00
|
|
|
}
|