]> granicus.if.org Git - mutt/commitdiff
Add menu dialog helper to add rows.
authorKevin McCarthy <kevin@8t8.us>
Fri, 19 Apr 2019 20:14:54 +0000 (13:14 -0700)
committerKevin McCarthy <kevin@8t8.us>
Fri, 19 Apr 2019 20:14:54 +0000 (13:14 -0700)
Remove the manual max calculation and dialog row allocation.

Add a NONULL check because the helper uses safe_strdup() to add a row.

menu.c
mutt_menu.h

diff --git a/menu.c b/menu.c
index 320645b200f7f8d8f8ceb89fe4d47589afbb8b9d..df798c989e52d1eaf2c9e5b4b1d59e03e2ae49e3 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -181,7 +181,7 @@ static void menu_make_entry (char *s, int l, MUTTMENU *menu, int i)
 {
   if (menu->dialog)
   {
-    strncpy (s, menu->dialog[i], l);
+    strncpy (s, NONULL (menu->dialog[i]), l);
     menu->current = -1; /* hide menubar */
   }
   else
@@ -741,6 +741,16 @@ void mutt_menuDestroy (MUTTMENU **p)
   FREE (p);            /* __FREE_CHECKED__ */
 }
 
+void mutt_menu_add_dialog_row (MUTTMENU *m, const char *row)
+{
+  if (m->dsize <= m->max)
+  {
+    m->dsize += 10;
+    safe_realloc (&m->dialog, m->dsize * sizeof (char *));
+  }
+  m->dialog[m->max++] = safe_strdup (row);
+}
+
 static MUTTMENU *get_current_menu (void)
 {
   return MenuStackCount ? MenuStack[MenuStackCount - 1] : NULL;
index 5ae7de9d09dbf93c42ecaf62e7f281a517eb451f..41b0e5f39544aca4be23493c96b2fe674207761c 100644 (file)
@@ -64,6 +64,7 @@ typedef struct menu_t
    * prompt keys override movement keys.
    */
   char **dialog;       /* dialog lines themselves */
+  int dsize;            /* number of allocated dialog lines */
   char *prompt;                /* prompt for user, similar to mutt_multi_choice */
   char *keys;          /* keys used in the prompt */
 
@@ -124,6 +125,7 @@ void mutt_ts_icon (char *);
 
 MUTTMENU *mutt_new_menu (int);
 void mutt_menuDestroy (MUTTMENU **);
+void mutt_menu_add_dialog_row (MUTTMENU *, const char *);
 void mutt_push_current_menu (MUTTMENU *);
 void mutt_pop_current_menu (MUTTMENU *);
 void mutt_set_current_menu_redraw (int);