2004-05-29 10:17:37 +00:00
|
|
|
/*
|
|
|
|
|
* Input method handling for QEmacs.
|
2007-12-03 16:10:38 +00:00
|
|
|
*
|
2004-05-29 10:17:37 +00:00
|
|
|
* Copyright (c) 2000 Fabrice Bellard.
|
2017-03-25 18:14:59 +00:00
|
|
|
* Copyright (c) 2002-2017 Charlie Gordon.
|
2004-05-29 10:17:37 +00:00
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library 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
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*/
|
2007-12-03 16:10:38 +00:00
|
|
|
|
2004-05-29 10:17:37 +00:00
|
|
|
#include "qe.h"
|
|
|
|
|
|
2015-09-16 22:18:22 +00:00
|
|
|
static int default_input(qe__unused__ int *match_buf,
|
|
|
|
|
qe__unused__ int match_buf_size,
|
|
|
|
|
qe__unused__ int *match_len_ptr,
|
|
|
|
|
qe__unused__ const u8 *data,
|
|
|
|
|
qe__unused__ const unsigned int *buf,
|
|
|
|
|
qe__unused__ int len)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
|
|
|
|
return INPUTMETHOD_NOMATCH;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-09 23:31:38 +00:00
|
|
|
static int unicode_input(int *match_buf,
|
|
|
|
|
int match_buf_size,
|
2008-01-03 09:51:29 +00:00
|
|
|
int *match_len_ptr,
|
2015-09-16 22:18:22 +00:00
|
|
|
qe__unused__ const u8 *data,
|
2006-12-31 19:34:00 +00:00
|
|
|
const unsigned int *buf, int len)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
|
|
|
|
int i, h, c;
|
|
|
|
|
if (buf[0] != 'x')
|
|
|
|
|
return INPUTMETHOD_NOMATCH;
|
|
|
|
|
|
|
|
|
|
c = 0;
|
|
|
|
|
if (len > 5)
|
|
|
|
|
len = 5;
|
2005-05-11 15:48:31 +00:00
|
|
|
for (i = 1; i < len; i++) {
|
2004-05-29 10:17:37 +00:00
|
|
|
h = to_hex(buf[i]);
|
|
|
|
|
if (h == -1)
|
|
|
|
|
return INPUTMETHOD_NOMATCH;
|
|
|
|
|
c = (c << 4) | h;
|
|
|
|
|
}
|
|
|
|
|
if (len == 5) {
|
|
|
|
|
*match_len_ptr = len;
|
2007-12-09 23:31:38 +00:00
|
|
|
match_buf[0] = c;
|
|
|
|
|
return 1;
|
2004-05-29 10:17:37 +00:00
|
|
|
} else {
|
|
|
|
|
return INPUTMETHOD_MORECHARS;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-03 09:51:29 +00:00
|
|
|
static InputMethod default_input_method = {
|
2006-12-31 19:34:00 +00:00
|
|
|
"default", default_input, NULL, NULL,
|
2004-05-29 10:17:37 +00:00
|
|
|
};
|
|
|
|
|
|
2008-01-03 09:51:29 +00:00
|
|
|
static InputMethod unicode_input_method = {
|
2006-12-31 19:34:00 +00:00
|
|
|
"unicode", unicode_input, NULL, NULL,
|
2004-05-29 10:17:37 +00:00
|
|
|
};
|
|
|
|
|
|
2008-01-03 18:31:24 +00:00
|
|
|
void register_input_method(InputMethod *m)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
2008-01-11 11:29:28 +00:00
|
|
|
QEmacsState *qs = &qe_state;
|
2004-05-29 10:17:37 +00:00
|
|
|
InputMethod **p;
|
2007-12-03 16:10:38 +00:00
|
|
|
|
2008-01-11 11:29:28 +00:00
|
|
|
p = &qs->input_methods;
|
2007-12-03 16:10:38 +00:00
|
|
|
while (*p != NULL) {
|
|
|
|
|
p = &(*p)->next;
|
|
|
|
|
}
|
2004-05-29 10:17:37 +00:00
|
|
|
m->next = NULL;
|
|
|
|
|
*p = m;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-08 03:42:53 +00:00
|
|
|
static void input_completion(CompleteState *cp)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
2008-01-11 11:29:28 +00:00
|
|
|
QEmacsState *qs = cp->s->qe_state;
|
2004-05-29 10:17:37 +00:00
|
|
|
InputMethod *m;
|
|
|
|
|
|
2008-01-11 11:29:28 +00:00
|
|
|
for (m = qs->input_methods; m != NULL; m = m->next) {
|
2008-01-08 03:42:53 +00:00
|
|
|
complete_test(cp, m->name);
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-06 15:28:29 +00:00
|
|
|
static InputMethod *find_input_method(const char *name)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
2008-01-11 11:29:28 +00:00
|
|
|
QEmacsState *qs = &qe_state;
|
2004-05-29 10:17:37 +00:00
|
|
|
InputMethod *m;
|
|
|
|
|
|
2008-01-11 11:29:28 +00:00
|
|
|
for (m = qs->input_methods; m != NULL; m = m->next) {
|
2008-01-08 03:42:53 +00:00
|
|
|
if (strequal(m->name, name))
|
2007-12-06 15:28:29 +00:00
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void do_set_input_method(EditState *s, const char *name)
|
|
|
|
|
{
|
|
|
|
|
InputMethod *m = find_input_method(name);
|
|
|
|
|
|
|
|
|
|
if (m) {
|
|
|
|
|
s->input_method = m;
|
|
|
|
|
s->selected_input_method = m;
|
|
|
|
|
} else {
|
|
|
|
|
put_status(s, "'%s' not found", name);
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void do_switch_input_method(EditState *s)
|
|
|
|
|
{
|
2008-01-11 11:29:28 +00:00
|
|
|
if (s->input_method)
|
2004-05-29 10:17:37 +00:00
|
|
|
s->input_method = NULL;
|
2008-01-11 11:29:28 +00:00
|
|
|
else
|
|
|
|
|
s->input_method = s->selected_input_method;
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void init_input_methods(void)
|
|
|
|
|
{
|
|
|
|
|
register_input_method(&default_input_method);
|
|
|
|
|
register_input_method(&unicode_input_method);
|
|
|
|
|
register_completion("input", input_completion);
|
|
|
|
|
}
|