From: Richard Russon Date: Wed, 24 Jul 2019 11:36:16 +0000 (+0100) Subject: window: add new() and free() X-Git-Tag: 2019-10-25~107^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7cb4bab3901cf5d188afa2b014e4ab856090c3d1;p=neomutt window: add new() and free() --- diff --git a/main.c b/main.c index d158f8e84..19eb067fa 100644 --- a/main.c +++ b/main.c @@ -1120,7 +1120,7 @@ int main(int argc, char *argv[], char *envp[]) FREE(&tempfile); } - mutt_window_free(); + mutt_window_free_all(); if (rv != 0) goto main_curses; // TEST36: neomutt -H existing -s test john@example.com -E (cancel sending) @@ -1261,7 +1261,7 @@ main_exit: mutt_buffer_free(&folder); mutt_list_free(&queries); crypto_module_free(); - mutt_window_free(); + mutt_window_free_all(); mutt_buffer_pool_free(); mutt_envlist_free(); mutt_browser_cleanup(); diff --git a/mutt_window.c b/mutt_window.c index 39841ffbd..53e6f2f49 100644 --- a/mutt_window.c +++ b/mutt_window.c @@ -44,6 +44,31 @@ struct MuttWindow *MuttMessageWindow = NULL; /**< Message Window */ struct MuttWindow *MuttSidebarWindow = NULL; /**< Sidebar Window */ #endif +/** + * mutt_window_new - Create a new Window + * @retval ptr New Window + */ +struct MuttWindow *mutt_window_new(void) +{ + struct MuttWindow *win = mutt_mem_calloc(1, sizeof(struct MuttWindow)); + + return win; +} + +/** + * mutt_window_free - Free a Window + * @param ptr Window to free + */ +void mutt_window_free(struct MuttWindow **ptr) +{ + if (!ptr || !*ptr) + return; + + // struct MuttWindow *win = *ptr; + + FREE(ptr); +} + #ifdef USE_SLANG_CURSES /** * vw_printw - Write a formatted string to a Window (function missing from Slang) @@ -102,9 +127,9 @@ void mutt_window_clrtoeol(struct MuttWindow *win) } /** - * mutt_window_free - Free the default Windows + * mutt_window_free_all - Free all the default Windows */ -void mutt_window_free(void) +void mutt_window_free_all(void) { FREE(&MuttHelpWindow); FREE(&MuttIndexWindow); @@ -143,12 +168,12 @@ void mutt_window_getxy(struct MuttWindow *win, int *x, int *y) */ void mutt_window_init(void) { - MuttHelpWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow)); - MuttIndexWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow)); - MuttStatusWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow)); - MuttMessageWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow)); + MuttHelpWindow = mutt_window_new(); + MuttIndexWindow = mutt_window_new(); + MuttStatusWindow = mutt_window_new(); + MuttMessageWindow = mutt_window_new(); #ifdef USE_SIDEBAR - MuttSidebarWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow)); + MuttSidebarWindow = mutt_window_new(); #endif } diff --git a/mutt_window.h b/mutt_window.h index f0502b6a7..f1096acae 100644 --- a/mutt_window.h +++ b/mutt_window.h @@ -48,16 +48,18 @@ extern struct MuttWindow *MuttSidebarWindow; #endif extern struct MuttWindow *MuttStatusWindow; -void mutt_window_clearline(struct MuttWindow *win, int row); -void mutt_window_clrtoeol(struct MuttWindow *win); -void mutt_window_free(void); -void mutt_window_getxy(struct MuttWindow *win, int *x, int *y); -void mutt_window_init(void); -int mutt_window_move(struct MuttWindow *win, int row, int col); -int mutt_window_mvaddstr(struct MuttWindow *win, int row, int col, const char *str); -int mutt_window_mvprintw(struct MuttWindow *win, int row, int col, const char *fmt, ...); -void mutt_window_reflow_message_rows(int mw_rows); -void mutt_window_reflow(void); -int mutt_window_wrap_cols(int width, short wrap); +void mutt_window_clearline (struct MuttWindow *win, int row); +void mutt_window_clrtoeol (struct MuttWindow *win); +void mutt_window_free (struct MuttWindow **ptr); +void mutt_window_free_all (void); +void mutt_window_getxy (struct MuttWindow *win, int *x, int *y); +void mutt_window_init (void); +int mutt_window_move (struct MuttWindow *win, int row, int col); +int mutt_window_mvaddstr (struct MuttWindow *win, int row, int col, const char *str); +int mutt_window_mvprintw (struct MuttWindow *win, int row, int col, const char *fmt, ...); +struct MuttWindow *mutt_window_new (void); +void mutt_window_reflow (void); +void mutt_window_reflow_message_rows(int mw_rows); +int mutt_window_wrap_cols (int width, short wrap); #endif /* MUTT_MUTT_WINDOW_H */ diff --git a/pager.c b/pager.c index ff5d8ff6c..76535a923 100644 --- a/pager.c +++ b/pager.c @@ -2323,10 +2323,10 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P } rd.helpstr = mutt_b2s(helpstr); - rd.index_status_window = mutt_mem_calloc(1, sizeof(struct MuttWindow)); - rd.index_window = mutt_mem_calloc(1, sizeof(struct MuttWindow)); - rd.pager_status_window = mutt_mem_calloc(1, sizeof(struct MuttWindow)); - rd.pager_window = mutt_mem_calloc(1, sizeof(struct MuttWindow)); + rd.index_status_window = mutt_window_new(); + rd.index_window = mutt_window_new(); + rd.pager_status_window = mutt_window_new(); + rd.pager_window = mutt_window_new(); pager_menu = mutt_menu_new(MENU_PAGER); pager_menu->menu_custom_redraw = pager_custom_redraw; @@ -3586,10 +3586,10 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P mutt_menu_destroy(&rd.index); mutt_buffer_free(&helpstr); - FREE(&rd.index_status_window); - FREE(&rd.index_window); - FREE(&rd.pager_status_window); - FREE(&rd.pager_window); + mutt_window_free(&rd.index_status_window); + mutt_window_free(&rd.index_window); + mutt_window_free(&rd.pager_status_window); + mutt_window_free(&rd.pager_window); return (rc != -1) ? rc : 0; }