X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=help.c;h=407b7a492cd4ac82c8a46bb73baff3b901eef6ce;hp=f01bbea58f9eff5e3e2c4f69b8b3df6954103ee9;hb=916e4872caf252a5850e64f79427b9dd7808435d;hpb=ae0ce4dfcafa0c3820f107c5bfa8bd06e5272b57 diff --git a/help.c b/help.c index f01bbea..407b7a4 100644 --- a/help.c +++ b/help.c @@ -9,23 +9,14 @@ #define HELP_C -#if HAVE_CONFIG_H -# include "config.h" -#endif +#include -#include -#include -#include +#include #include "mutt.h" -#include "mutt_curses.h" +#include "charset.h" #include "keymap.h" #include "pager.h" -#include "mapping.h" - -#include -#include -#include static struct binding_t *help_lookupFunction (int op, int menu) { @@ -48,7 +39,7 @@ static struct binding_t *help_lookupFunction (int op, int menu) return (NULL); } -void mutt_make_help (char *d, size_t dlen, char *txt, int menu, int op) +void mutt_make_help (char *d, ssize_t dlen, char *txt, int menu, int op) { char buf[SHORT_STRING]; @@ -59,11 +50,11 @@ void mutt_make_help (char *d, size_t dlen, char *txt, int menu, int op) d[0] = 0; } -char *mutt_compile_help (char *buf, size_t buflen, int menu, +char *mutt_compile_help (char *buf, ssize_t buflen, int menu, struct mapping_t *items) { int i; - size_t len; + ssize_t len; char *pbuf = buf; for (i = 0; items[i].name && buflen > 2; i++) { @@ -85,29 +76,29 @@ static int print_macro (FILE * f, int maxwidth, const char **macro) int n = maxwidth; wchar_t wc; int w; - size_t k; - size_t len = m_strlen(*macro); + ssize_t k; + ssize_t len = m_strlen(*macro); mbstate_t mbstate1, mbstate2; p_clear(&mbstate1, 1); p_clear(&mbstate2, 1); for (; len && (k = mbrtowc (&wc, *macro, len, &mbstate1)); *macro += k, len -= k) { - if (k == (size_t) (-1) || k == (size_t) (-2)) { - k = (k == (size_t) (-1)) ? 1 : len; - wc = replacement_char (); + if (k == -1 || k == -2) { + k = (k == -1) ? 1 : len; + wc = CharsetReplacement; } /* glibc-2.1.3's wcwidth() returns 1 for unprintable chars! */ - if (IsWPrint (wc) && (w = wcwidth (wc)) >= 0) { + if (iswprint(wc) && (w = wcwidth (wc)) >= 0) { if (w > n) break; n -= w; { char buf[MB_LEN_MAX * 2]; - size_t n1, n2; + ssize_t n1, n2; - if ((n1 = wcrtomb (buf, wc, &mbstate2)) != (size_t) (-1) && - (n2 = wcrtomb (buf + n1, 0, &mbstate2)) != (size_t) (-1)) + if ((n1 = wcrtomb(buf, wc, &mbstate2)) != -1 && + (n2 = wcrtomb(buf + n1, 0, &mbstate2)) != -1) fputs (buf, f); } } @@ -200,7 +191,7 @@ static void format_line (FILE * f, int ismacro, n = COLS - col; if (ismacro >= 0) { - SKIPWS (t3); + t3 = vskipspaces(t3); /* FIXME: this is completely wrong */ if ((n = m_strlen(t3)) > COLS - col) { @@ -281,43 +272,41 @@ static void dump_unbound (FILE * f, void mutt_help (int menu) { - char t[_POSIX_PATH_MAX]; - char buf[SHORT_STRING]; - const char *desc; - FILE *f; - struct binding_t *funcs; - - mutt_mktemp (t); - - funcs = km_get_table (menu); - desc = mutt_getnamebyvalue (menu, Menus); - if (!desc) - desc = _(""); + char tmp[_POSIX_PATH_MAX]; + char buf[SHORT_STRING]; + const char *desc; + FILE *f; + struct binding_t *funcs; + + funcs = km_get_table (menu); + desc = mutt_getnamebyvalue (menu, Menus); + if (!desc) + desc = _(""); + + do { + f = m_tempfile(tmp, sizeof(tmp), NONULL(Tempdir), NULL); + if (!f) { + mutt_perror(tmp); + return; + } - do { - if ((f = safe_fopen (t, "w")) == NULL) { - mutt_perror (t); - return; - } + dump_menu(f, menu); + if (menu != MENU_EDITOR && menu != MENU_PAGER) { + fputs(_("\nGeneric bindings:\n\n"), f); + dump_menu(f, MENU_GENERIC); + } - dump_menu (f, menu); - if (menu != MENU_EDITOR && menu != MENU_PAGER) { - fputs (_("\nGeneric bindings:\n\n"), f); - dump_menu (f, MENU_GENERIC); - } + fputs(_("\nUnbound functions:\n\n"), f); + if (funcs) + dump_unbound(f, funcs, Keymaps[menu], NULL); - fputs (_("\nUnbound functions:\n\n"), f); - if (funcs) - dump_unbound (f, funcs, Keymaps[menu], NULL); - if (menu != MENU_PAGER) - dump_unbound (f, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu]); + if (menu != MENU_PAGER) + dump_unbound (f, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu]); - fclose (f); + m_fclose(&f); - snprintf (buf, sizeof (buf), _("Help for %s"), desc); - } - while - (mutt_do_pager (buf, t, - M_PAGER_RETWINCH | M_PAGER_MARKER | M_PAGER_NSKIP, NULL) - == OP_REFORMAT_WINCH); + snprintf(buf, sizeof (buf), _("Help for %s"), desc); + } while (mutt_do_pager(buf, tmp, + M_PAGER_RETWINCH | M_PAGER_MARKER | M_PAGER_NSKIP, + NULL) == OP_REFORMAT_WINCH); }