X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=keymap.c;h=580c2a4ab821b8d0e5070b70e292e5b5f459a179;hp=7be686949cefcc70bec4b80b8ed8f482de984667;hb=049b21f53af51ad7259613f5eefaa0f37b1b2167;hpb=f288d1771c814e6104da83e6f0f1761a40de1224 diff --git a/keymap.c b/keymap.c index 7be6869..580c2a4 100644 --- a/keymap.c +++ b/keymap.c @@ -9,12 +9,12 @@ #include -#include +#include #include #include "mutt.h" #include "keymap.h" -#include +#include "crypt.h" #define MUTT_FUNCTIONS_VALUES #include "functions.def" @@ -30,16 +30,8 @@ struct mapping_t Menus[] = { {"postpone", MENU_POST}, {"pgp", MENU_PGP}, {"smime", MENU_SMIME}, - -#ifdef HAVE_GPGME {"key_select_pgp", MENU_KEY_SELECT_PGP}, {"key_select_smime", MENU_KEY_SELECT_SMIME}, -#endif - -#ifdef MIXMASTER - {"mix", MENU_MIX}, -#endif - {"query", MENU_QUERY}, {"generic", MENU_GENERIC}, {NULL, 0} @@ -60,7 +52,7 @@ static struct mapping_t KeyNames[] = { #ifdef KEY_ENTER {"", KEY_ENTER}, #endif - {"", M_ENTER_C}, + {"", '\n'}, {"", '\033'}, {"", '\t'}, {"", ' '}, @@ -90,21 +82,13 @@ static struct keymap_t *allocKeys(int len, keycode_t *keys) static int parse_fkey (const char *s) { - const char *t; int n = 0; - if (s[0] != '<' || ascii_tolower (s[1]) != 'f') + if (s[0] != '<' || ascii_tolower(s[1]) != 'f') return -1; - for (t = s + 2; *t && isdigit ((unsigned char) *t); t++) { - n *= 10; - n += *t - '0'; - } - - if (*t != '>') - return -1; - else - return n; + n = strtol(s + 2, (char **)&s, 10); + return *s == '>' ? n : -1; } /* @@ -113,18 +97,18 @@ static int parse_fkey (const 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; + int n; + + if (*s != '<') + return -1; + n = strtol(s + 1, (char **)&s, 8); + return *s == '>' ? n : -1; } static int parsekeys (const char *str, keycode_t * d, int max) { int n, len = max; - char buff[SHORT_STRING]; + char buff[STRING]; char c; char *s, *t; @@ -162,7 +146,7 @@ static int parsekeys (const char *str, keycode_t * d, int max) len--; } - return (max - len); + return max - len; } /* insert a key sequence into the specified map. the map is sorted by ASCII @@ -317,7 +301,7 @@ static int retry_generic (int menu, keycode_t * keys, int keyslen, mutt_ungetch (lastkey, 0); for (; keyslen; keyslen--) mutt_ungetch (keys[keyslen - 1], 0); - return (km_dokey (MENU_GENERIC)); + return km_dokey (MENU_GENERIC); } if (menu != MENU_EDITOR) { /* probably a good idea to flush input here so we can abort macros */ @@ -341,17 +325,17 @@ int km_dokey (int menu) if (!map) - return (retry_generic (menu, NULL, 0, 0)); + return retry_generic (menu, NULL, 0, 0); for (;;) { /* ncurses doesn't return on resized screen when timeout is set to zero */ if (menu != MENU_EDITOR) - timeout ((Timeout > 0 ? Timeout : 60) * 1000); + wtimeout (main_w, (Timeout > 0 ? Timeout : 60) * 1000); tmp = mutt_getch (); if (menu != MENU_EDITOR) - timeout (-1); /* restore blocking operation */ + wtimeout (main_w, -1); /* restore blocking operation */ LastKey = tmp.ch; if (LastKey == -1) @@ -401,12 +385,12 @@ int km_dokey (int menu) /* Nope. Business as usual */ while (LastKey > map->keys[pos]) { if (pos > map->eq || !map->next) - return (retry_generic (menu, map->keys, pos, LastKey)); + return retry_generic (menu, map->keys, pos, LastKey); map = map->next; } if (LastKey != map->keys[pos]) - return (retry_generic (menu, map->keys, pos, LastKey)); + return retry_generic (menu, map->keys, pos, LastKey); if (++pos == map->len) { @@ -464,7 +448,7 @@ const char *km_keyname(int c) snprintf (buf, sizeof (buf), "%c", (unsigned char) c); else snprintf (buf, sizeof (buf), "\\x%hx", (unsigned short) c); - return (buf); + return buf; } int km_expand_key (char *s, size_t len, struct keymap_t *map) @@ -473,14 +457,14 @@ int km_expand_key (char *s, size_t len, struct keymap_t *map) int p = 0; if (!map) - return (0); + return 0; for (;;) { m_strcpy(s, len, km_keyname(map->keys[p])); len -= (l = m_strlen(s)); if (++p >= map->len || !len) - return (1); + return 1; s += l; } @@ -495,7 +479,7 @@ struct keymap_t *km_find_func (int menu, int func) for (; map; map = map->next) if (map->op == func) break; - return (map); + return map; } void km_init (void) @@ -510,23 +494,10 @@ void km_init (void) create_bindings (OpPost, MENU_POST); create_bindings (OpQuery, MENU_QUERY); create_bindings (OpAlias, MENU_ALIAS); - - create_bindings (OpPgp, MENU_PGP); create_bindings (OpSmime, MENU_SMIME); - -#ifdef CRYPT_BACKEND_GPGME create_bindings (OpPgp, MENU_KEY_SELECT_PGP); create_bindings (OpSmime, MENU_KEY_SELECT_SMIME); -#endif - -#ifdef MIXMASTER - create_bindings (OpMix, MENU_MIX); - - km_bindkey ("", MENU_MIX, OP_GENERIC_SELECT_ENTRY); - km_bindkey ("h", MENU_MIX, OP_MIX_CHAIN_PREV); - km_bindkey ("l", MENU_MIX, OP_MIX_CHAIN_NEXT); -#endif /* bindings for the line editor */ create_bindings (OpEditor, MENU_EDITOR); @@ -611,7 +582,7 @@ void km_init (void) void km_error_key (int menu) { - char buf[SHORT_STRING]; + char buf[STRING]; struct keymap_t *key; if (!(key = km_find_func (menu, OP_HELP))) @@ -647,7 +618,7 @@ int mutt_parse_push (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ } else push_string (buf->data); - return (r); + return r; } /* expects to see: ,,... */ @@ -687,14 +658,14 @@ static char *parse_keymap (int *menu, BUFFER * s, int maxmenus, int *nummenus, m_strcpy(err->data, err->dsize, _("null key sequence")); } else if (MoreArgs (s)) - return (buf.data); + return buf.data; } else { m_strcpy(err->data, err->dsize, _("too few arguments")); } error: p_delete(&buf.data); - return (NULL); + return NULL; } static int @@ -705,9 +676,9 @@ try_bind (char *key, int menu, char *func, struct binding_t *bindings) for (i = 0; bindings[i].name; i++) if (m_strcmp(func, bindings[i].name) == 0) { km_bindkey (key, menu, bindings[i].op); - return (0); + return 0; } - return (-1); + return -1; } struct binding_t *km_get_table (int menu) @@ -733,22 +704,12 @@ struct binding_t *km_get_table (int menu) return OpEditor; case MENU_QUERY: return OpQuery; - case MENU_PGP: return OpPgp; - -#ifdef CRYPT_BACKEND_GPGME case MENU_KEY_SELECT_PGP: return OpPgp; case MENU_KEY_SELECT_SMIME: return OpSmime; -#endif - -#ifdef MIXMASTER - case MENU_MIX: - return OpMix; -#endif - } return NULL; } @@ -759,12 +720,11 @@ int mutt_parse_bind (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ { struct binding_t *bindings = NULL; char *key; - int menu[sizeof (Menus) / sizeof (struct mapping_t) - 1], r = + int menu[countof(Menus) - 1], r = 0, nummenus, i; - if ((key = parse_keymap (menu, s, sizeof (menu) / sizeof (menu[0]), - &nummenus, err)) == NULL) - return (-1); + if (!(key = parse_keymap(menu, s, countof(menu), &nummenus, err))) + return -1; /* function to execute */ mutt_extract_token (buf, s, 0); @@ -794,7 +754,7 @@ int mutt_parse_bind (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ } } p_delete(&key); - return (r); + return r; } /* macro */ @@ -809,7 +769,7 @@ int mutt_parse_macro (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ if ((key = parse_keymap (menu, s, sizeof (menu) / sizeof (menu[0]), &nummenus, err)) == NULL) - return (-1); + return -1; mutt_extract_token (buf, s, M_TOKEN_CONDENSE); /* make sure the macro sequence is not an empty string */ @@ -841,7 +801,7 @@ int mutt_parse_macro (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ } } p_delete(&key); - return (r); + return r; } /* exec function-name */ @@ -855,7 +815,7 @@ int mutt_parse_exec (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ if (!MoreArgs (s)) { m_strcpy(err->data, err->dsize, _("exec: no arguments")); - return (-1); + return -1; } do { @@ -873,7 +833,7 @@ int mutt_parse_exec (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ if (ops[nops] == OP_NULL) { mutt_flushinp (); mutt_error (_("%s: no such function"), function); - return (-1); + return -1; } nops++; } @@ -884,24 +844,3 @@ int mutt_parse_exec (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ return 0; } - -/* - * prompts the user to enter a keystroke, and displays the octal value back - * to the user. - */ -void mutt_what_key (void) -{ - int ch; - - mvprintw (LINES - 1, 0, _("Enter keys (^G to abort): ")); - do { - ch = getch (); - if (ch != ERR && ch != ctrl ('G')) { - mutt_message (_("Char = %s, Octal = %o, Decimal = %d"), - km_keyname (ch), ch, ch); - } - } - while (ch != ERR && ch != ctrl ('G')); - - mutt_flushinp (); -}