From: Kevin McCarthy Date: Fri, 19 Apr 2019 20:14:54 +0000 (-0700) Subject: Add menu dialog helper to add rows. X-Git-Tag: mutt-1-12-rel~52 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=042576039824d005fb500cc05786f48f50886980;p=mutt Add menu dialog helper to add rows. Remove the manual max calculation and dialog row allocation. Add a NONULL check because the helper uses safe_strdup() to add a row. --- diff --git a/menu.c b/menu.c index 320645b2..df798c98 100644 --- 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; diff --git a/mutt_menu.h b/mutt_menu.h index 5ae7de9d..41b0e5f3 100644 --- a/mutt_menu.h +++ b/mutt_menu.h @@ -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);