]> granicus.if.org Git - neomutt/commitdiff
window: add new() and free()
authorRichard Russon <rich@flatcap.org>
Wed, 24 Jul 2019 11:36:16 +0000 (12:36 +0100)
committerRichard Russon <rich@flatcap.org>
Tue, 30 Jul 2019 19:20:51 +0000 (20:20 +0100)
main.c
mutt_window.c
mutt_window.h
pager.c

diff --git a/main.c b/main.c
index d158f8e8416dccddca4e9d16136b2c80dda939b8..19eb067fa3162833e061d50ff29b21fcabadcf86 100644 (file)
--- 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();
index 39841ffbd062358ea6c73e541390e75ba101a89b..53e6f2f494caccac93dc0d08664e576af7c9bf01 100644 (file)
@@ -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
 }
 
index f0502b6a722d2277695b071632473c97508c20a1..f1096acaec85b2300a4f5b9e216479c7260ec61e 100644 (file)
@@ -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 ff5d8ff6c8778d9d81991f6b261e31d597d1adb0..76535a9232d3eabc33063ec4c268892b0597e8e8 100644 (file)
--- 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;
 }