From eb16f43cf9de67953b8779956a69a73a52cf87b7 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Mon, 27 Sep 2004 01:04:50 +0000 Subject: [PATCH] add a func_key flag to the low-level input functions and the currently existing high-level input functions, to indicate extended keypad values git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1943 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 5 ++++ src/files.c | 5 ++-- src/nano.c | 8 +++---- src/proto.h | 8 +++---- src/winio.c | 68 +++++++++++++++++++++++++++++++---------------------- 5 files changed, 56 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 587c93de..9d331fd2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -49,6 +49,11 @@ CVS code - changes to terminal_init(). (DLR) - Remove redundant include of limits.h from nano.c. nano.c includes nano.h and nano.h includes limits.h. (DLR) + - 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) - files.c: do_insertfile() - Readd the NANO_SMALL #ifdef around the start_again: label to diff --git a/src/files.c b/src/files.c index 14293674..e68449b7 100644 --- a/src/files.c +++ b/src/files.c @@ -2485,7 +2485,7 @@ char *do_browser(const char *inpath) int numents = 0, i = 0, j = 0, longest = 0, abort = 0, col = 0; int selected = 0, editline = 0, width = 0, filecols = 0, lineno = 0; int kbinput = ERR; - bool meta_key; + bool meta_key, func_key; char **filelist = (char **)NULL; #ifndef DISABLE_MOUSE MEVENT mevent; @@ -2808,7 +2808,8 @@ char *do_browser(const char *inpath) } } wrefresh(edit); - } while ((kbinput = get_kbinput(edit, &meta_key)) != NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY); + } while ((kbinput = get_kbinput(edit, &meta_key, &func_key)) != + NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY); curs_set(1); blank_edit(); titlebar(NULL); diff --git a/src/nano.c b/src/nano.c index 56cb4976..f6a2d4e2 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2343,7 +2343,7 @@ void do_justify(bool full_justify) int mark_beginx_save = mark_beginx; #endif int kbinput; - bool meta_key; + bool meta_key, func_key; /* If we're justifying the entire file, start at the beginning. */ if (full_justify) @@ -2604,7 +2604,7 @@ void do_justify(bool full_justify) /* Now get a keystroke and see if it's unjustify; if not, unget the * keystroke and return. */ - kbinput = get_edit_input(&meta_key, FALSE); + kbinput = get_edit_input(&meta_key, &func_key, FALSE); if (!meta_key && kbinput == NANO_UNJUSTIFY_KEY) { /* Restore the justify we just did (ungrateful user!). */ @@ -2998,7 +2998,7 @@ int main(int argc, char **argv) #endif int kbinput; /* Input from keyboard. */ - bool meta_key; + bool meta_key, func_key; #ifdef HAVE_GETOPT_LONG const struct option long_options[] = { {"help", 0, 0, 'h'}, @@ -3496,7 +3496,7 @@ int main(int argc, char **argv) currshortcut = main_list; #endif - kbinput = get_edit_input(&meta_key, TRUE); + kbinput = get_edit_input(&meta_key, &func_key, TRUE); /* Last gasp, stuff that's not in the main lists. */ if (kbinput != ERR && !is_cntrl_char(kbinput)) { diff --git a/src/proto.h b/src/proto.h index 0a006830..fe046097 100644 --- a/src/proto.h +++ b/src/proto.h @@ -499,8 +499,8 @@ int check_wildcard_match(const char *text, const char *pattern); void reset_kbinput(void); #endif void unget_kbinput(int kbinput, bool meta_key); -int get_kbinput(WINDOW *win, bool *meta_key); -int get_translated_kbinput(int kbinput, bool *es +int get_kbinput(WINDOW *win, bool *meta_key, bool *func_key); +int get_translated_kbinput(int kbinput, bool *func_key, bool *es #ifndef NANO_SMALL , bool reset #endif @@ -526,11 +526,11 @@ int get_untranslated_kbinput(int kbinput, size_t position, bool bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts); #endif const shortcut *get_shortcut(const shortcut *s_list, int kbinput, bool - *meta_key); + *meta_key, bool *func_key); #ifndef NANO_SMALL const toggle *get_toggle(int kbinput, bool meta_key); #endif -int get_edit_input(bool *meta_key, bool allow_funcs); +int get_edit_input(bool *meta_key, bool *func_key, bool allow_funcs); #ifndef DISABLE_MOUSE bool get_edit_mouse(void); #endif diff --git a/src/winio.c b/src/winio.c index 67934aa1..d5c0ee3c 100644 --- a/src/winio.c +++ b/src/winio.c @@ -93,7 +93,7 @@ static int statblank = 0; /* Number of keystrokes left after /* Reset all the input routines that rely on character sequences. */ void reset_kbinput(void) { - get_translated_kbinput(0, NULL, TRUE); + get_translated_kbinput(0, NULL, NULL, TRUE); get_ascii_kbinput(0, 0, TRUE); get_untranslated_kbinput(0, 0, FALSE, TRUE); } @@ -111,12 +111,13 @@ void unget_kbinput(int kbinput, bool meta_key) /* Read in a single input character. If it's ignored, swallow it and go * on. Otherwise, try to translate it from ASCII, extended keypad * values, and/or escape sequences. Set meta_key to TRUE when we get a - * meta sequence. Supported extended keypad values consist of [arrow + * meta sequence, and set func_key to TRUE when we get an extended + * keypad sequence. Supported extended keypad values consist of [arrow * key], Ctrl-[arrow key], Shift-[arrow key], Enter, Backspace, the * editing keypad (Insert, Delete, Home, End, PageUp, and PageDown), the * function keypad (F1-F14), and the numeric keypad with NumLock off. * Assume nodelay(win) is FALSE. */ -int get_kbinput(WINDOW *win, bool *meta_key) +int get_kbinput(WINDOW *win, bool *meta_key, bool *func_key) { int kbinput, retval = ERR; bool es; @@ -126,6 +127,7 @@ int get_kbinput(WINDOW *win, bool *meta_key) #endif *meta_key = FALSE; + *func_key = FALSE; while (retval == ERR) { /* Read a character using blocking input, since using @@ -133,7 +135,7 @@ int get_kbinput(WINDOW *win, bool *meta_key) * to get_translated_kbinput(). Continue until we get a * complete sequence. */ kbinput = wgetch(win); - retval = get_translated_kbinput(kbinput, &es + retval = get_translated_kbinput(kbinput, func_key, &es #ifndef NANO_SMALL , FALSE #endif @@ -180,7 +182,7 @@ int get_kbinput(WINDOW *win, bool *meta_key) } #ifdef DEBUG - fprintf(stderr, "get_kbinput(): kbinput = %d, meta_key = %d\n", kbinput, (int)*meta_key); + fprintf(stderr, "get_kbinput(): kbinput = %d, meta_key = %d, func_key = %d\n", kbinput, (int)*meta_key, (int)*func_key); #endif #ifndef NANO_SMALL @@ -191,9 +193,10 @@ int get_kbinput(WINDOW *win, bool *meta_key) } /* Translate acceptable ASCII, extended keypad values, and escape - * sequences into their corresponding key values. Set es to TRUE when - * we get an escape sequence. Assume nodelay(win) is FALSE. */ -int get_translated_kbinput(int kbinput, bool *es + * sequences into their corresponding key values. Set func_key to TRUE + * when we get an extended keypad value, and set es to TRUE when we get + * an escape sequence. Assume nodelay(win) is FALSE. */ +int get_translated_kbinput(int kbinput, bool *func_key, bool *es #ifndef NANO_SMALL , bool reset #endif @@ -211,6 +214,7 @@ int get_translated_kbinput(int kbinput, bool *es } #endif + *func_key = FALSE; *es = FALSE; switch (kbinput) { @@ -420,9 +424,13 @@ int get_translated_kbinput(int kbinput, bool *es } } } + + /* If the result is outside the ASCII range, set func_key to TRUE. */ + if (retval > 255) + *func_key = TRUE; #ifdef DEBUG - fprintf(stderr, "get_translated_kbinput(): kbinput = %d, es = %d, escapes = %d, ascii_digits = %lu, retval = %d\n", kbinput, (int)*es, escapes, (unsigned long)ascii_digits, retval); + fprintf(stderr, "get_translated_kbinput(): kbinput = %d, func_key = %d, es = %d, escapes = %d, ascii_digits = %lu, retval = %d\n", kbinput, (int)*func_key, (int)*es, escapes, (unsigned long)ascii_digits, retval); #endif /* Return the result. */ @@ -1337,7 +1345,7 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts) #endif /* !DISABLE_MOUSE */ const shortcut *get_shortcut(const shortcut *s_list, int kbinput, bool - *meta_key) + *meta_key, bool *func_key) { const shortcut *s = s_list; size_t slen = length_of_list(s_list); @@ -1348,14 +1356,17 @@ const shortcut *get_shortcut(const shortcut *s_list, int kbinput, bool * * 1. The key exists. * 2. The key is a control key in the shortcut list. - * 3. The key is a function key in the shortcut list. - * 4. meta_key is TRUE and the key is a meta sequence. - * 5. meta_key is TRUE and the key is the other meta sequence in - * the shortcut list. */ + * 3. meta_key is TRUE and the key is the primary or + * miscellaneous meta sequence in the shortcut list. + * 4. func_key is TRUE and the key is a function key in the + * shortcut list. */ + if (kbinput != NANO_NO_KEY && ((*meta_key == FALSE && - ((kbinput == s->ctrlval || kbinput == s->funcval))) || - (*meta_key == TRUE && (kbinput == s->metaval || - kbinput == s->miscval)))) { + *func_key == FALSE && kbinput == s->ctrlval) || + (*meta_key == TRUE && *func_key == FALSE && + (kbinput == s->metaval || kbinput == s->miscval)) || + (*meta_key == FALSE && *func_key == TRUE && + kbinput == s->funcval))) { break; } @@ -1364,7 +1375,7 @@ const shortcut *get_shortcut(const shortcut *s_list, int kbinput, bool /* Translate the shortcut to either its control key or its meta key * equivalent. Assume that the shortcut has an equivalent control - * key, meta key, or both. */ + * key, an equivalent primary meta key sequence, or both. */ if (slen > 0) { if (s->ctrlval != NANO_NO_KEY) { *meta_key = FALSE; @@ -1396,7 +1407,7 @@ const toggle *get_toggle(int kbinput, bool meta_key) } #endif /* !NANO_SMALL */ -int get_edit_input(bool *meta_key, bool allow_funcs) +int get_edit_input(bool *meta_key, bool *func_key, bool allow_funcs) { bool keyhandled = FALSE; int kbinput, retval; @@ -1405,7 +1416,7 @@ int get_edit_input(bool *meta_key, bool allow_funcs) const toggle *t; #endif - kbinput = get_kbinput(edit, meta_key); + kbinput = get_kbinput(edit, meta_key, func_key); /* Universal shortcuts. These aren't in any shortcut lists, but we * should handle them anyway. */ @@ -1425,7 +1436,7 @@ int get_edit_input(bool *meta_key, bool allow_funcs) #ifndef DISABLE_MOUSE case KEY_MOUSE: if (get_edit_mouse()) { - kbinput = get_kbinput(edit, meta_key); + kbinput = get_kbinput(edit, meta_key, func_key); break; } else return ERR; @@ -1433,7 +1444,7 @@ int get_edit_input(bool *meta_key, bool allow_funcs) } /* Check for a shortcut in the main list. */ - s = get_shortcut(main_list, kbinput, meta_key); + s = get_shortcut(main_list, kbinput, meta_key, func_key); if (s != NULL) { /* We got a shortcut. Run the shortcut's corresponding function @@ -1755,7 +1766,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def, ) { int kbinput; - bool meta_key; + bool meta_key, func_key; static int x = -1; /* the cursor position in 'answer' */ int xend; @@ -1812,7 +1823,8 @@ int nanogetstr(int allowtabs, const char *buf, const char *def, * to files not specified on the command line. In this case, * disable all keys that would change the text if the filename isn't * blank and we're at the "Write File" prompt. */ - while ((kbinput = get_kbinput(bottomwin, &meta_key)) != NANO_ENTER_KEY) { + while ((kbinput = get_kbinput(bottomwin, &meta_key, &func_key)) != + NANO_ENTER_KEY) { for (t = s; t != NULL; t = t->next) { #ifdef DEBUG fprintf(stderr, "Aha! \'%c\' (%d)\n", kbinput, kbinput); @@ -3112,12 +3124,12 @@ int do_yesno(int all, const char *msg) do { int kbinput; - bool meta_key; + bool meta_key, func_key; #ifndef DISABLE_MOUSE int mouse_x, mouse_y; #endif - kbinput = get_kbinput(edit, &meta_key); + kbinput = get_kbinput(edit, &meta_key, &func_key); if (kbinput == NANO_CANCEL_KEY) ok = -1; @@ -3281,7 +3293,7 @@ void do_help(void) /* no_more means the end of the help text is shown, so don't go * down any more. */ int kbinput = ERR; - bool meta_key; + bool meta_key, func_key; bool old_no_help = ISSET(NO_HELP); #ifndef DISABLE_MOUSE @@ -3377,7 +3389,7 @@ void do_help(void) no_more = (*ptr == '\0'); skip_redisplay: - kbinput = get_kbinput(edit, &meta_key); + kbinput = get_kbinput(edit, &meta_key, &func_key); } while (kbinput != NANO_CANCEL_KEY && kbinput != NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY); -- 2.39.5