Use p_new instead of xmalloc()
[apps/madmutt.git] / help.c
diff --git a/help.c b/help.c
index 4bd1b01..1162b23 100644 (file)
--- a/help.c
+++ b/help.c
@@ -9,15 +9,6 @@
 
 #define HELP_C
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <wctype.h>
-#include <wchar.h>
-#include <ctype.h>
-#include <string.h>
-
 #include <lib-lib/lib-lib.h>
 
 #include <lib-ui/curses.h>
@@ -50,7 +41,7 @@ static struct binding_t *help_lookupFunction (int op, int menu)
 
 void mutt_make_help (char *d, ssize_t dlen, char *txt, int menu, int op)
 {
-  char buf[SHORT_STRING];
+  char buf[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)))
@@ -235,7 +226,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) {
@@ -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 = _("<UNKNOWN>");
-
-  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 = _("<UNKNOWN>");
+
+    do {
+        f = m_tempfile(tmp, sizeof(tmp), NONULL(Tempdir), 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_do_pager(buf, tmp,
+                           M_PAGER_RETWINCH | M_PAGER_MARKER | M_PAGER_NSKIP,
+                           NULL) == OP_REFORMAT_WINCH);
 }