X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/19304f7c526fbe36ba0db2fb80bcaf3bd974d81d..84b9ea1689a8189d41ea4a821a1fd6cc446b9332:/keymap.c diff --git a/keymap.c b/keymap.c index bcc0022..70765b1 100644 --- a/keymap.c +++ b/keymap.c @@ -47,7 +47,7 @@ struct mapping_t Menus[] = { { "postpone", MENU_POST }, { "pgp", MENU_PGP }, { "smime", MENU_SMIME }, -#ifdef HAVE_GPGME +#ifdef CRYPT_BACKEND_GPGME { "key_select_pgp", MENU_KEY_SELECT_PGP }, { "key_select_smime", MENU_KEY_SELECT_SMIME }, #endif @@ -89,6 +89,39 @@ static struct mapping_t KeyNames[] = { #ifdef KEY_NEXT { "", KEY_NEXT }, #endif +#ifdef NCURSES_VERSION + /* extensions supported by ncurses. values are filled in during initialization */ + + /* CTRL+key */ + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + + /* SHIFT+key */ + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + + /* ALT+key */ + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, +#endif /* NCURSES_VERSION */ { NULL, 0 } }; @@ -134,17 +167,19 @@ static int parse_fkey(char *s) */ static int parse_keycode (const char *s) { - if (isdigit ((unsigned char) s[1]) && - isdigit ((unsigned char) s[2]) && - isdigit ((unsigned char) s[3]) && - s[4] == '>') - { - return (s[3] - '0') + (s[2] - '0') * 8 + (s[1] - '0') * 64; - } - return -1; + const char *endChar; + long int result = strtol(s+1, &endChar, 8); + /* allow trailing whitespace, eg. < 1001 > */ + while (ISSPACE(*endChar)) + ++endChar; + /* negative keycodes don't make sense, also detect overflow */ + if (*endChar != '>' || result < 0 || result == LONG_MAX) { + return -1; + } + return result; } -static int parsekeys (char *str, keycode_t *d, int max) +static int parsekeys (const char *str, keycode_t *d, int max) { int n, len = max; char buff[SHORT_STRING]; @@ -573,6 +608,97 @@ struct keymap_t *km_find_func (int menu, int func) return (map); } +#ifdef NCURSES_VERSION +struct extkey { + const char *name; + const char *sym; +}; + +static const struct extkey ExtKeys[] = { + { "", "kUP5" }, + { "", "kUP" }, + { "", "kUP3" }, + + { "", "kDN" }, + { "", "kDN3" }, + { "", "kDN5" }, + + { "", "kRIT5" }, + { "", "kRIT" }, + { "", "kRIT3" }, + + { "", "kLFT" }, + { "", "kLFT3" }, + { "", "kLFT5" }, + + { "", "kHOM" }, + { "", "kHOM3" }, + { "", "kHOM5" }, + + { "", "kEND" }, + { "", "kEND3" }, + { "", "kEND5" }, + + { "", "kNXT" }, + { "", "kNXT3" }, + { "", "kNXT5" }, + + { "", "kPRV" }, + { "", "kPRV3" }, + { "", "kPRV5" }, + + { 0, 0 } +}; + +/* Look up Mutt's name for a key and find the ncurses extended name for it */ +static const char *find_ext_name(const char *key) +{ + int j; + + for (j = 0; ExtKeys[j].name; ++j) + { + if (strcasecmp(key, ExtKeys[j].name) == 0) + return ExtKeys[j].sym; + } + return 0; +} +#endif /* NCURSES_VERSION */ + +/* Determine the keycodes for ncurses extended keys and fill in the KeyNames array. + * + * This function must be called *after* initscr(), or tigetstr() returns -1. This + * creates a bit of a chicken-and-egg problem because km_init() is called prior to + * start_curses(). This means that the default keybindings can't include any of the + * extended keys because they won't be defined until later. + */ +void init_extended_keys(void) +{ +#ifdef NCURSES_VERSION + int j; + + use_extended_names(TRUE); + + for (j = 0; KeyNames[j].name; ++j) + { + if (KeyNames[j].value == -1) + { + const char *keyname = find_ext_name(KeyNames[j].name); + + if (keyname) + { + char *s = tigetstr(keyname); + if (s && (long)(s) != -1) + { + int code = key_defined(s); + if (code > 0) + KeyNames[j].value = code; + } + } + } + } +#endif +} + void km_init (void) { memset (Keymaps, 0, sizeof (struct keymap_t *) * MENU_MAX);