X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=help.c;h=30bcbde56e879e7f88270a594cfa40f476ae2ccb;hp=c0bf22c6cab5f2feacc0f61447badeaf2a830b6c;hb=88d239144bf6f50ca1eda6db7742281f0ad0f97f;hpb=c25bc063f35aaad6938c2022dae7a283346c2769 diff --git a/help.c b/help.c index c0bf22c..30bcbde 100644 --- a/help.c +++ b/help.c @@ -9,22 +9,14 @@ #define HELP_C -#if HAVE_CONFIG_H -# include "config.h" -#endif +#include -#include "lib/intl.h" -#include "lib/str.h" +#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) { @@ -35,48 +27,16 @@ static struct binding_t *help_lookupFunction (int op, int menu) /* first look in the generic map for the function */ for (i = 0; OpGeneric[i].name; i++) if (OpGeneric[i].op == op) - return (&OpGeneric[i]); + return &OpGeneric[i]; } if ((map = km_get_table (menu))) { for (i = 0; map[i].name; i++) if (map[i].op == op) - return (&map[i]); + return &map[i]; } - return (NULL); -} - -void mutt_make_help (char *d, size_t dlen, char *txt, int menu, int op) -{ - char buf[SHORT_STRING]; - - if (km_expand_key (buf, sizeof (buf), km_find_func (menu, op)) || - km_expand_key (buf, sizeof (buf), km_find_func (MENU_GENERIC, op))) - snprintf (d, dlen, "%s:%s", buf, txt); - else - d[0] = 0; -} - -char *mutt_compile_help (char *buf, size_t buflen, int menu, - struct mapping_t *items) -{ - int i; - size_t len; - char *pbuf = buf; - - for (i = 0; items[i].name && buflen > 2; i++) { - if (i) { - *pbuf++ = ' '; - *pbuf++ = ' '; - buflen -= 2; - } - mutt_make_help (pbuf, buflen, _(items[i].name), menu, items[i].value); - len = str_len (pbuf); - pbuf += len; - buflen -= len; - } - return buf; + return NULL; } static int print_macro (FILE * f, int maxwidth, const char **macro) @@ -84,29 +44,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 = str_len (*macro); + ssize_t k; + ssize_t len = m_strlen(*macro); mbstate_t mbstate1, mbstate2; - memset (&mbstate1, 0, sizeof (mbstate1)); - memset (&mbstate2, 0, sizeof (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); } } @@ -132,7 +92,7 @@ static int print_macro (FILE * f, int maxwidth, const char **macro) fprintf (f, "?"); } } - return (maxwidth - n); + return maxwidth - n; } static int pad (FILE * f, int col, int i) @@ -142,14 +102,14 @@ static int pad (FILE * f, int col, int i) if (col < i) { snprintf (fmt, sizeof (fmt), "%%-%ds", i - col); fprintf (f, fmt, ""); - return (i); + return i; } fputc (' ', f); - return (col + 1); + return col + 1; } -static void format_line (FILE * f, int ismacro, - const char *t1, const char *t2, const char *t3) +static void help_format_line (FILE * f, int ismacro, + const char *t1, const char *t2, const char *t3) { int col; int col_a, col_b; @@ -158,28 +118,25 @@ static void format_line (FILE * f, int ismacro, fputs (t1, f); - /* don't try to press string into one line with less than 40 characters. - The double paranthesis avoid a gcc warning, sigh ... */ - if ((split = COLS < 40)) { + /* don't try to press string into one line with less than 40 characters. */ + if ((split = getmaxx(main_w) < 40)) { col_a = col = 0; col_b = LONG_STRING; fputc ('\n', f); } else { - col_a = COLS > 83 ? (COLS - 32) >> 2 : 12; - col_b = COLS > 49 ? (COLS - 10) >> 1 : 19; - col = pad (f, str_len (t1), col_a); + col_a = getmaxx(main_w) > 83 ? (getmaxx(main_w) - 32) >> 2 : 12; + col_b = getmaxx(main_w) > 49 ? (getmaxx(main_w) - 10) >> 1 : 19; + col = pad (f, m_strlen(t1), col_a); } if (ismacro > 0) { - if (!str_cmp (Pager, "builtin")) - fputs ("_\010", f); - fputs ("M ", f); + fputs ("_\010M ", f); col += 2; if (!split) { col += print_macro (f, col_b - col - 4, &t2); - if (str_len (t2) > col_b - col) + if (m_strlen(t2) > col_b - col) t2 = "..."; } } @@ -196,14 +153,14 @@ static void format_line (FILE * f, int ismacro, } else { while (*t3) { - n = COLS - col; + n = getmaxx(main_w) - col; if (ismacro >= 0) { - SKIPWS (t3); + t3 = vskipspaces(t3); /* FIXME: this is completely wrong */ - if ((n = str_len (t3)) > COLS - col) { - n = COLS - col; + if ((n = m_strlen(t3)) > getmaxx(main_w) - col) { + n = getmaxx(main_w) - col; for (col_a = n; col_a > 0 && t3[col_a] != ' '; col_a--); if (col_a) n = col_a; @@ -213,15 +170,9 @@ static void format_line (FILE * f, int ismacro, print_macro (f, n, &t3); if (*t3) { - if (str_cmp (Pager, "builtin")) { - fputc ('\n', f); - n = 0; - } - else { - n += col - COLS; - if (option (OPTMARKERS)) - ++n; - } + n += col - getmaxx(main_w); + if (option (OPTMARKERS)) + ++n; col = pad (f, n, col_b); } } @@ -234,7 +185,7 @@ static void dump_menu (FILE * f, int menu) { struct keymap_t *map; struct binding_t *b; - char buf[SHORT_STRING]; + char buf[STRING]; /* browse through the keymap table */ for (map = Keymaps[menu]; map; map = map->next) { @@ -243,13 +194,13 @@ static void dump_menu (FILE * f, int menu) if (map->op == OP_MACRO) { if (map->descr == NULL) - format_line (f, -1, buf, "macro", map->macro); + help_format_line (f, -1, buf, "macro", map->macro); else - format_line (f, 1, buf, map->macro, map->descr); + help_format_line (f, 1, buf, map->macro, map->descr); } else { b = help_lookupFunction (map->op, menu); - format_line (f, 0, buf, b ? b->name : "UNKNOWN", + help_format_line (f, 0, buf, b ? b->name : "UNKNOWN", b ? _(HelpStrings[b->op]) : _("ERROR: please report this bug")); } @@ -274,49 +225,49 @@ static void dump_unbound (FILE * f, for (i = 0; funcs[i].name; i++) { if (!is_bound (map, funcs[i].op) && (!aux || !is_bound (aux, funcs[i].op))) - format_line (f, 0, funcs[i].name, "", _(HelpStrings[funcs[i].op])); + help_format_line (f, 0, funcs[i].name, "", _(HelpStrings[funcs[i].op])); } } 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 = _(""); - - do { - if ((f = safe_fopen (t, "w")) == NULL) { - mutt_perror (t); - return; - } + char tmp[_POSIX_PATH_MAX]; + char buf[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(mod_core.tmpdir), NULL); + if (!f) { + mutt_perror(tmp); + 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); - if (menu != MENU_PAGER) - dump_unbound (f, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu]); + fputs(_("\nUnbound functions:\n\n"), f); + if (funcs) + dump_unbound(f, funcs, Keymaps[menu], NULL); - fclose (f); + if (menu != MENU_PAGER) + dump_unbound (f, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu]); - 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); + m_fclose(&f); + + snprintf(buf, sizeof (buf), _("Help for %s"), desc); + } while (mutt_pager(buf, tmp, + M_PAGER_RETWINCH | M_PAGER_MARKER | M_PAGER_NSKIP, + NULL) == OP_REFORMAT_WINCH); } + +#undef HELP_C