]> granicus.if.org Git - neomutt/commitdiff
refactor: addstr() to mutt_window_addstr()
authorRichard Russon <rich@flatcap.org>
Fri, 27 Sep 2019 14:45:06 +0000 (15:45 +0100)
committerRichard Russon <rich@flatcap.org>
Sat, 28 Sep 2019 02:18:27 +0000 (03:18 +0100)
Encapsulate a curses function to reduce dependencies.

compose.c
curs_lib.c
edit.c
menu.c
mutt_curses.h
mutt_window.c
mutt_window.h
progress.c
remailer.c
sidebar.c

index 5323e12dfa8cfec8e74ee6a53ecc85a29ea535ee..a60d6745d406ecfa82a07ded59884f7a306dac60 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -377,30 +377,30 @@ static void redraw_crypt_lines(struct ComposeRedrawData *rd)
 
   if ((WithCrypto & (APPLICATION_PGP | APPLICATION_SMIME)) == 0)
   {
-    addstr(_("Not supported"));
+    mutt_window_addstr(_("Not supported"));
     return;
   }
 
   if ((e->security & (SEC_ENCRYPT | SEC_SIGN)) == (SEC_ENCRYPT | SEC_SIGN))
   {
     mutt_curses_set_color(MT_COLOR_COMPOSE_SECURITY_BOTH);
-    addstr(_("Sign, Encrypt"));
+    mutt_window_addstr(_("Sign, Encrypt"));
   }
   else if (e->security & SEC_ENCRYPT)
   {
     mutt_curses_set_color(MT_COLOR_COMPOSE_SECURITY_ENCRYPT);
-    addstr(_("Encrypt"));
+    mutt_window_addstr(_("Encrypt"));
   }
   else if (e->security & SEC_SIGN)
   {
     mutt_curses_set_color(MT_COLOR_COMPOSE_SECURITY_SIGN);
-    addstr(_("Sign"));
+    mutt_window_addstr(_("Sign"));
   }
   else
   {
     /* L10N: This refers to the encryption of the email, e.g. "Security: None" */
     mutt_curses_set_color(MT_COLOR_COMPOSE_SECURITY_NONE);
-    addstr(_("None"));
+    mutt_window_addstr(_("None"));
   }
   mutt_curses_set_color(MT_COLOR_NORMAL);
 
@@ -409,16 +409,16 @@ static void redraw_crypt_lines(struct ComposeRedrawData *rd)
     if (((WithCrypto & APPLICATION_PGP) != 0) && (e->security & APPLICATION_PGP))
     {
       if ((e->security & SEC_INLINE))
-        addstr(_(" (inline PGP)"));
+        mutt_window_addstr(_(" (inline PGP)"));
       else
-        addstr(_(" (PGP/MIME)"));
+        mutt_window_addstr(_(" (PGP/MIME)"));
     }
     else if (((WithCrypto & APPLICATION_SMIME) != 0) && (e->security & APPLICATION_SMIME))
-      addstr(_(" (S/MIME)"));
+      mutt_window_addstr(_(" (S/MIME)"));
   }
 
   if (C_CryptOpportunisticEncrypt && (e->security & SEC_OPPENCRYPT))
-    addstr(_(" (OppEnc mode)"));
+    mutt_window_addstr(_(" (OppEnc mode)"));
 
   mutt_window_clrtoeol(rd->win);
   mutt_window_move(rd->win, HDR_CRYPTINFO, 0);
@@ -462,12 +462,12 @@ static void redraw_crypt_lines(struct ComposeRedrawData *rd)
     if (e->security & SEC_AUTOCRYPT)
     {
       mutt_curses_set_color(MT_COLOR_COMPOSE_SECURITY_ENCRYPT);
-      addstr(_("Encrypt"));
+      mutt_window_addstr(_("Encrypt"));
     }
     else
     {
       mutt_curses_set_color(MT_COLOR_COMPOSE_SECURITY_NONE);
-      addstr(_("Off"));
+      mutt_window_addstr(_("Off"));
     }
 
     mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER);
@@ -541,7 +541,7 @@ static void redraw_mix_line(struct ListHead *chain, struct ComposeRedrawData *rd
 
   if (STAILQ_EMPTY(chain))
   {
-    addstr(_("<no chain defined>"));
+    mutt_window_addstr(_("<no chain defined>"));
     mutt_window_clrtoeol(rd->win);
     return;
   }
@@ -557,9 +557,9 @@ static void redraw_mix_line(struct ListHead *chain, struct ComposeRedrawData *rd
     if (c + mutt_str_strlen(t) + 2 >= rd->win->cols)
       break;
 
-    addstr(NONULL(t));
+    mutt_window_addstr(NONULL(t));
     if (STAILQ_NEXT(np, entries))
-      addstr(", ");
+      mutt_window_addstr(", ");
 
     c += mutt_str_strlen(t) + 2;
   }
index 7e2a69680f803a3b39ca80e542f9384cc6668dcb..71426811212cf776b135c36dd1f716fdc72f0160 100644 (file)
@@ -273,7 +273,7 @@ int mutt_get_field_full(const char *field, char *buf, size_t buflen, CompletionF
     }
     mutt_window_clearline(MuttMessageWindow, 0);
     mutt_curses_set_color(MT_COLOR_PROMPT);
-    addstr(field);
+    mutt_window_addstr(field);
     mutt_curses_set_color(MT_COLOR_NORMAL);
     mutt_refresh();
     mutt_window_getxy(MuttMessageWindow, &x, NULL);
@@ -404,7 +404,7 @@ enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
       mutt_window_move(MuttMessageWindow, 0, 0);
       mutt_curses_set_color(MT_COLOR_PROMPT);
       mutt_window_addnstr(msg, trunc_msg_len);
-      addstr(answer_string);
+      mutt_window_addstr(answer_string);
       mutt_curses_set_color(MT_COLOR_NORMAL);
       mutt_window_clrtoeol(MuttMessageWindow);
     }
@@ -458,7 +458,7 @@ enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
 
   if (def != MUTT_ABORT)
   {
-    addstr((char *) ((def == MUTT_YES) ? yes : no));
+    mutt_window_addstr((char *) ((def == MUTT_YES) ? yes : no));
     mutt_refresh();
   }
   else
@@ -668,10 +668,10 @@ int mutt_buffer_enter_fname_full(const char *prompt, struct Buffer *fname,
 
   mutt_curses_set_color(MT_COLOR_PROMPT);
   mutt_window_mvaddstr(MuttMessageWindow, 0, 0, prompt);
-  addstr(_(" ('?' for list): "));
+  mutt_window_addstr(_(" ('?' for list): "));
   mutt_curses_set_color(MT_COLOR_NORMAL);
   if (!mutt_buffer_is_empty(fname))
-    addstr(mutt_b2s(fname));
+    mutt_window_addstr(mutt_b2s(fname));
   mutt_window_clrtoeol(MuttMessageWindow);
   mutt_refresh();
 
@@ -895,7 +895,7 @@ int mutt_multi_choice(const char *prompt, const char *letters)
       }
 
       mutt_curses_set_color(MT_COLOR_PROMPT);
-      addstr(prompt);
+      mutt_window_addstr(prompt);
       mutt_curses_set_color(MT_COLOR_NORMAL);
 
       mutt_window_addch(' ');
@@ -963,7 +963,7 @@ int mutt_addwch(wchar_t wc)
   }
   else
   {
-    return addstr(buf);
+    return mutt_window_addstr(buf);
   }
 }
 
diff --git a/edit.c b/edit.c
index 159785c30a69c39afe50e490325ddedfbd2803c5..5cb870b9bdc53782b862f81512489988b7b7b4ad 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -149,14 +149,14 @@ static char **be_snarf_file(const char *path, char **buf, int *max, int *len, bo
     if (verbose)
     {
       snprintf(tmp, sizeof(tmp), "\"%s\" %lu bytes\n", path, (unsigned long) sb.st_size);
-      addstr(tmp);
+      mutt_window_addstr(tmp);
     }
     mutt_file_fclose(&fp);
   }
   else
   {
     snprintf(tmp, sizeof(tmp), "%s: %s\n", path, strerror(errno));
-    addstr(tmp);
+    mutt_window_addstr(tmp);
   }
   return buf;
 }
@@ -174,7 +174,7 @@ static int be_barf_file(const char *path, char **buf, int buflen)
   FILE *fp = fopen(path, "w");
   if (!fp)
   {
-    addstr(strerror(errno));
+    mutt_window_addstr(strerror(errno));
     mutt_window_addch('\n');
     return -1;
   }
@@ -273,32 +273,32 @@ static void be_print_header(struct Envelope *env)
 
   if (!TAILQ_EMPTY(&env->to))
   {
-    addstr("To: ");
+    mutt_window_addstr("To: ");
     tmp[0] = '\0';
     mutt_addrlist_write(tmp, sizeof(tmp), &env->to, true);
-    addstr(tmp);
+    mutt_window_addstr(tmp);
     mutt_window_addch('\n');
   }
   if (!TAILQ_EMPTY(&env->cc))
   {
-    addstr("Cc: ");
+    mutt_window_addstr("Cc: ");
     tmp[0] = '\0';
     mutt_addrlist_write(tmp, sizeof(tmp), &env->cc, true);
-    addstr(tmp);
+    mutt_window_addstr(tmp);
     mutt_window_addch('\n');
   }
   if (!TAILQ_EMPTY(&env->bcc))
   {
-    addstr("Bcc: ");
+    mutt_window_addstr("Bcc: ");
     tmp[0] = '\0';
     mutt_addrlist_write(tmp, sizeof(tmp), &env->bcc, true);
-    addstr(tmp);
+    mutt_window_addstr(tmp);
     mutt_window_addch('\n');
   }
   if (env->subject)
   {
-    addstr("Subject: ");
-    addstr(env->subject);
+    mutt_window_addstr("Subject: ");
+    mutt_window_addstr(env->subject);
     mutt_window_addch('\n');
   }
   mutt_window_addch('\n');
@@ -315,7 +315,7 @@ static void be_edit_header(struct Envelope *e, bool force)
 
   mutt_window_move(MuttMessageWindow, 0, 0);
 
-  addstr("To: ");
+  mutt_window_addstr("To: ");
   tmp[0] = '\0';
   mutt_addrlist_to_local(&e->to);
   mutt_addrlist_write(tmp, sizeof(tmp), &e->to, false);
@@ -335,13 +335,13 @@ static void be_edit_header(struct Envelope *e, bool force)
   else
   {
     mutt_addrlist_to_intl(&e->to, NULL); /* XXX - IDNA error reporting? */
-    addstr(tmp);
+    mutt_window_addstr(tmp);
   }
   mutt_window_addch('\n');
 
   if (!e->subject || force)
   {
-    addstr("Subject: ");
+    mutt_window_addstr("Subject: ");
     mutt_str_strfcpy(tmp, e->subject ? e->subject : "", sizeof(tmp));
     if (mutt_enter_string(tmp, sizeof(tmp), 9, MUTT_COMP_NO_FLAGS) == 0)
       mutt_str_replace(&e->subject, tmp);
@@ -350,7 +350,7 @@ static void be_edit_header(struct Envelope *e, bool force)
 
   if ((TAILQ_EMPTY(&e->cc) && C_Askcc) || force)
   {
-    addstr("Cc: ");
+    mutt_window_addstr("Cc: ");
     tmp[0] = '\0';
     mutt_addrlist_to_local(&e->cc);
     mutt_addrlist_write(tmp, sizeof(tmp), &e->cc, false);
@@ -371,7 +371,7 @@ static void be_edit_header(struct Envelope *e, bool force)
 
   if (C_Askbcc || force)
   {
-    addstr("Bcc: ");
+    mutt_window_addstr("Bcc: ");
     tmp[0] = '\0';
     mutt_addrlist_to_local(&e->bcc);
     mutt_addrlist_write(tmp, sizeof(tmp), &e->bcc, false);
@@ -412,7 +412,7 @@ int mutt_builtin_editor(const char *path, struct Email *e_new, struct Email *e_c
 
   be_edit_header(e_new->env, false);
 
-  addstr(_("(End message with a . on a line by itself)\n"));
+  mutt_window_addstr(_("(End message with a . on a line by itself)\n"));
 
   buf = be_snarf_file(path, buf, &bufmax, &buflen, false);
 
@@ -439,8 +439,8 @@ int mutt_builtin_editor(const char *path, struct Email *e_new, struct Email *e_c
       switch (tmp[1])
       {
         case '?':
-          addstr(_(EditorHelp1));
-          addstr(_(EditorHelp2));
+          mutt_window_addstr(_(EditorHelp1));
+          mutt_window_addstr(_(EditorHelp2));
           break;
         case 'b':
           mutt_addrlist_parse2(&e_new->env->bcc, p);
@@ -470,19 +470,19 @@ int mutt_builtin_editor(const char *path, struct Email *e_new, struct Email *e_c
                                       (isupper((unsigned char) tmp[1])));
           }
           else
-            addstr(_("No mailbox.\n"));
+            mutt_window_addstr(_("No mailbox.\n"));
           break;
         case 'p':
-          addstr("-----\n");
-          addstr(_("Message contains:\n"));
+          mutt_window_addstr("-----\n");
+          mutt_window_addstr(_("Message contains:\n"));
           be_print_header(e_new->env);
           for (int i = 0; i < buflen; i++)
-            addstr(buf[i]);
+            mutt_window_addstr(buf[i]);
           /* L10N: This entry is shown AFTER the message content,
              not IN the middle of the content.
              So it doesn't mean "(message will continue)"
              but means "(press any key to continue using neomutt)". */
-          addstr(_("(continue)\n"));
+          mutt_window_addstr(_("(continue)\n"));
           break;
         case 'q':
           done = true;
@@ -495,7 +495,7 @@ int mutt_builtin_editor(const char *path, struct Email *e_new, struct Email *e_c
             buf = be_snarf_file(tmp, buf, &bufmax, &buflen, true);
           }
           else
-            addstr(_("missing filename.\n"));
+            mutt_window_addstr(_("missing filename.\n"));
           break;
         case 's':
           mutt_str_replace(&e_new->env->subject, p);
@@ -515,7 +515,7 @@ int mutt_builtin_editor(const char *path, struct Email *e_new, struct Email *e_c
             continue;
           }
           else
-            addstr(_("No lines in message.\n"));
+            mutt_window_addstr(_("No lines in message.\n"));
           break;
 
         case 'e':
@@ -543,7 +543,7 @@ int mutt_builtin_editor(const char *path, struct Email *e_new, struct Email *e_c
 
             buf = be_snarf_file(path, buf, &bufmax, &buflen, false);
 
-            addstr(_("(continue)\n"));
+            mutt_window_addstr(_("(continue)\n"));
           }
           break;
         case 'w':
diff --git a/menu.c b/menu.c
index 6bf1d2ebc6ab77c6887340fb1f7bbdd498894210..d10a78db8558d1d3f94dde7442e64206c516dc10 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -173,7 +173,7 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do
               add_wch(WACS_LLCORNER);
 #else
             else if (CharsetIsUtf8)
-              addstr("\342\224\224"); /* WACS_LLCORNER */
+              mutt_window_addstr("\342\224\224"); /* WACS_LLCORNER */
             else
               mutt_window_addch(ACS_LLCORNER);
 #endif
@@ -186,7 +186,7 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do
               add_wch(WACS_ULCORNER);
 #else
             else if (CharsetIsUtf8)
-              addstr("\342\224\214"); /* WACS_ULCORNER */
+              mutt_window_addstr("\342\224\214"); /* WACS_ULCORNER */
             else
               mutt_window_addch(ACS_ULCORNER);
 #endif
@@ -199,7 +199,7 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do
               add_wch(WACS_LTEE);
 #else
             else if (CharsetIsUtf8)
-              addstr("\342\224\234"); /* WACS_LTEE */
+              mutt_window_addstr("\342\224\234"); /* WACS_LTEE */
             else
               mutt_window_addch(ACS_LTEE);
 #endif
@@ -212,7 +212,7 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do
               add_wch(WACS_HLINE);
 #else
             else if (CharsetIsUtf8)
-              addstr("\342\224\200"); /* WACS_HLINE */
+              mutt_window_addstr("\342\224\200"); /* WACS_HLINE */
             else
               mutt_window_addch(ACS_HLINE);
 #endif
@@ -225,7 +225,7 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do
               add_wch(WACS_VLINE);
 #else
             else if (CharsetIsUtf8)
-              addstr("\342\224\202"); /* WACS_VLINE */
+              mutt_window_addstr("\342\224\202"); /* WACS_VLINE */
             else
               mutt_window_addch(ACS_VLINE);
 #endif
@@ -238,7 +238,7 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do
               add_wch(WACS_TTEE);
 #else
             else if (CharsetIsUtf8)
-              addstr("\342\224\254"); /* WACS_TTEE */
+              mutt_window_addstr("\342\224\254"); /* WACS_TTEE */
             else
               mutt_window_addch(ACS_TTEE);
 #endif
@@ -251,7 +251,7 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do
               add_wch(WACS_BTEE);
 #else
             else if (CharsetIsUtf8)
-              addstr("\342\224\264"); /* WACS_BTEE */
+              mutt_window_addstr("\342\224\264"); /* WACS_BTEE */
             else
               mutt_window_addch(ACS_BTEE);
 #endif
@@ -439,7 +439,7 @@ void menu_redraw_index(struct Menu *menu)
         mutt_curses_set_color(MT_COLOR_INDICATOR);
         if (C_ArrowCursor)
         {
-          addstr("->");
+          mutt_window_addstr("->");
           mutt_curses_set_attr(attr);
           mutt_window_addch(' ');
         }
@@ -447,7 +447,7 @@ void menu_redraw_index(struct Menu *menu)
           do_color = false;
       }
       else if (C_ArrowCursor)
-        addstr("   ");
+        mutt_window_addstr("   ");
 
       print_enriched_string(i, attr, (unsigned char *) buf, do_color);
     }
@@ -486,7 +486,7 @@ void menu_redraw_motion(struct Menu *menu)
   if (C_ArrowCursor)
   {
     /* clear the pointer */
-    addstr("  ");
+    mutt_window_addstr("  ");
 
     if (menu->redraw & REDRAW_MOTION_RESYNC)
     {
@@ -535,7 +535,7 @@ void menu_redraw_current(struct Menu *menu)
   mutt_curses_set_color(MT_COLOR_INDICATOR);
   if (C_ArrowCursor)
   {
-    addstr("->");
+    mutt_window_addstr("->");
     mutt_curses_set_attr(attr);
     mutt_window_addch(' ');
     menu_pad_string(menu, buf, sizeof(buf));
index 8af1918c38adedf512c3f6e01b9f49e10cad1137..7dcbf1024ec258114bead47915a038b47e80c72f 100644 (file)
 
 /* The prototypes for these four functions use "(char*)",
  * whereas the ncurses versions use "(const char*)" */
-#undef addstr
 #undef mvaddnstr
 #undef mvaddstr
 
 /* We redefine the helper macros to hide the compiler warnings */
-#define addstr(x)               waddstr(stdscr, ((char *) x))
 #define mvaddnstr(y, x, str, n) mvwaddnstr(stdscr, (y), (x), ((char *) str), (n))
 #define mvaddstr(y, x, str)     mvwaddstr(stdscr, (y), (x), ((char *) str))
 
index 59fa746053fe3fe2f75bc71b1df12513d16c2971..b1ba9f9463001d0451b7e3fbbe675d731c7eed4d 100644 (file)
@@ -373,3 +373,21 @@ int mutt_window_addnstr(const char *str, int num)
   return addnstr(str, num);
 #endif
 }
+
+/**
+ * mutt_window_addstr - Write a string to a Window
+ * @param str String
+ * @retval  0 Success
+ * @retval -1 Error
+ */
+int mutt_window_addstr(const char *str)
+{
+  if (!str)
+    return -1;
+
+#ifdef USE_SLANG_CURSES
+  return addstr((char *) str);
+#else
+  return addstr(str);
+#endif
+}
index 49eb6d0e47895ebaf8a83a279364fec45d20e215..15da6d73744c8f76879816b06b0b632bae74ecf9 100644 (file)
@@ -60,6 +60,7 @@ int                mutt_window_wrap_cols          (int width, short wrap);
 // Functions for drawing on the Window
 int  mutt_window_addch    (int ch);
 int  mutt_window_addnstr  (const char *str, int num);
+int  mutt_window_addstr   (const char *str);
 void mutt_window_clearline(struct MuttWindow *win, int row);
 void mutt_window_clrtoeol (struct MuttWindow *win);
 int  mutt_window_move     (struct MuttWindow *win, int row, int col);
index 671a4795fe3d7e385c1d187d9e0f4c327ce2abb7..99daffe24fcc65e6644a4e7a4846628ab240a6d8 100644 (file)
@@ -75,7 +75,7 @@ static void message_bar(int percent, const char *fmt, ...)
 
   if (ColorDefs[MT_COLOR_PROGRESS] == 0)
   {
-    addstr(buf2);
+    mutt_window_addstr(buf2);
   }
   else
   {
@@ -83,7 +83,7 @@ static void message_bar(int percent, const char *fmt, ...)
     {
       /* The string fits within the colour bar */
       mutt_curses_set_color(MT_COLOR_PROGRESS);
-      addstr(buf2);
+      mutt_window_addstr(buf2);
       w -= l;
       while (w-- > 0)
       {
@@ -99,10 +99,10 @@ static void message_bar(int percent, const char *fmt, ...)
       char ch = buf2[off];
       buf2[off] = '\0';
       mutt_curses_set_color(MT_COLOR_PROGRESS);
-      addstr(buf2);
+      mutt_window_addstr(buf2);
       buf2[off] = ch;
       mutt_curses_set_color(MT_COLOR_NORMAL);
-      addstr(&buf2[off]);
+      mutt_window_addstr(&buf2[off]);
     }
   }
 
index 8215cdb53f61041b84e9817b2c20846aeedc4540..c2b81ce078aefa680286e6bdf271c64360681c8c 100644 (file)
@@ -340,7 +340,7 @@ static void mix_redraw_ce(struct Remailer **type2_list, struct Coord *coords,
     mutt_curses_set_color(MT_COLOR_NORMAL);
 
     if (i + 1 < chain->cl)
-      addstr(", ");
+      mutt_window_addstr(", ");
   }
 }
 
index e4002fcf839caeb23c35f7cc3dee3a643065d3f3..dd0e90b770c390903333608f81554a7fd82c0c8b 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -758,7 +758,7 @@ static int draw_divider(int num_rows, int num_cols)
     switch (altchar)
     {
       case SB_DIV_USER:
-        addstr(NONULL(C_SidebarDividerChar));
+        mutt_window_addstr(NONULL(C_SidebarDividerChar));
         break;
       case SB_DIV_ASCII:
         mutt_window_addch('|');