From 2dd6a8044d8ab7c389b8e09f5b8f311c9322e15d Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Fri, 5 Jul 2013 21:19:33 -0400 Subject: [PATCH] Fix inserting multibyte characters from a macro. form_driver() can handle bytes and not wide characters. --- src/cboard.c | 4 ++-- src/input.c | 9 ++++++--- src/input.h | 4 ++-- src/keys.h | 2 +- src/rcfile.c | 2 +- src/tags.c | 7 ++++--- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/cboard.c b/src/cboard.c index eb516d2..ced7ddf 100644 --- a/src/cboard.c +++ b/src/cboard.c @@ -4828,7 +4828,7 @@ void game_loop() * This is needed to detect terminal resizing. */ doupdate(); - if (LINES != LINES_OLD || COLS != COLS_OLD){ + if (LINES != LINES_OLD || COLS != COLS_OLD) { COLS_OLD = COLS; LINES_OLD = LINES; do_window_resize(); @@ -4836,7 +4836,7 @@ void game_loop() /* * Finds the top level window in the window stack so we know what - * window the wgetch()ed key belongs to. + * window the wget_wch()'ed key belongs to. */ if (wins) { for (i = 0; wins[i]; i++); diff --git a/src/input.c b/src/input.c index cdd78d2..7e4b5f6 100644 --- a/src/input.c +++ b/src/input.c @@ -108,8 +108,9 @@ static int get_input(WIN *win) struct input_s *in = win->data; char *tmp; struct input_data_s *data = in->data; - int i; + int i, n; char *prompt = _("Type F1 for help"); + char str[MB_CUR_MAX]; curs_set(1); window_draw_title(win->w, win->title, in->w, CP_INPUT_TITLE, @@ -226,7 +227,9 @@ static int get_input(WIN *win) tmp = (in->buf[0]) ? in->buf : NULL; goto done; default: - form_driver(in->f, (win->c & A_CHARTEXT)); + n = wctomb (str, win->c); + for (i = 0; n != -1 && i < n; i++) + form_driver(in->f, (unsigned char )str[i]); break; } @@ -295,7 +298,7 @@ done: * FIXME form validation is buggy (integers). */ WIN *construct_input(const char *title, const char *init, int lines, int reset, - const char *extra_help, input_func *func, void *arg, int key, + const char *extra_help, input_func *func, void *arg, wint_t key, struct input_data_s *id, int history, int type, ...) { WIN *win; diff --git a/src/input.h b/src/input.h index 3a23483..6ecb0bd 100644 --- a/src/input.h +++ b/src/input.h @@ -54,7 +54,7 @@ struct input_s { char **extra; input_func *func; char *arg; - int c; + wint_t c; void *data; int reset; int hist; @@ -68,7 +68,7 @@ struct input_data_s { }; WIN *construct_input(const char *title, const char *init, int lines, int reset, - const char *extra_help, input_func *func, void *arg, int key, + const char *extra_help, input_func *func, void *arg, wint_t key, struct input_data_s *id, int history, int type, ...); #endif diff --git a/src/keys.h b/src/keys.h index c03eba8..80b18a4 100644 --- a/src/keys.h +++ b/src/keys.h @@ -46,7 +46,7 @@ struct key_s { struct macro_s { wint_t c; - int *keys; + wint_t *keys; int n; int total; int mode; diff --git a/src/rcfile.c b/src/rcfile.c index 8c89e42..aacf67f 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -575,7 +575,7 @@ static void parse_macro(const char *filename, int lines, char *val) while ((c = parse_key(filename, lines, &p)) != 0) { macros[i]->keys = Realloc(macros[i]->keys, (macros[i]->total + 2) * - sizeof(int)); + sizeof(wint_t)); macros[i]->keys[macros[i]->total++] = c; } diff --git a/src/tags.c b/src/tags.c index 2bff266..1e120f3 100644 --- a/src/tags.c +++ b/src/tags.c @@ -282,7 +282,7 @@ static void edit_tag_add_finalize(WIN *w) } static void set_menu_stuff(TAG **t, char *name, char **init, int *type, - int *lines, input_func **func, int *key, char **eprompt, void **arg) + int *lines, input_func **func, wint_t *key, char **eprompt, void **arg) { int n; char *p; @@ -321,7 +321,7 @@ static void edit_tag_value(struct menu_input_s *m) char *name; int type = -1; input_func *func = NULL; - int key = 0; + wint_t key = 0; char *eprompt = NULL; void *arg = NULL; int lines = MAX_PGN_LINE_LEN / INPUT_WIDTH; @@ -347,7 +347,8 @@ static void edit_tag_add_name_finalize(WIN *w) char buf[COLS - 4]; char *init = NULL; char *name; - int key = 0, type = -1; + wint_t key = 0; + int type = -1; input_func *func = NULL; char *eprompt = NULL; int lines = MAX_PGN_LINE_LEN / INPUT_WIDTH; -- 2.11.4.GIT