mem_calloc -> p_new
[apps/madmutt.git] / status.c
index a6ba54b..f95eb32 100644 (file)
--- a/status.c
+++ b/status.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_menu.h"
 #include "mutt_curses.h"
@@ -27,6 +29,8 @@
 #include <ctype.h>
 #include <unistd.h>
 
+#define SW              (option(OPTMBOXPANE)?SidebarWidth:0)
+
 static char *get_sort_str (char *buf, size_t buflen, int method)
 {
   snprintf (buf, buflen, "%s%s%s",
@@ -60,7 +64,8 @@ static const char *status_format_str (char *buf, size_t buflen, char op,
                                       const char *elsestring,
                                       unsigned long data, format_flag flags)
 {
-  char fmt[SHORT_STRING], tmp[SHORT_STRING], *cp, *p;
+  char fmt[SHORT_STRING], tmp[SHORT_STRING];
+  const char *cp, *p;
   int count, optional = (flags & M_FORMAT_OPTIONAL);
   MUTTMENU *menu = (MUTTMENU *) data;
 
@@ -241,7 +246,7 @@ static const char *status_format_str (char *buf, size_t buflen, char op,
 
       if (!StChars)
         buf[0] = 0;
-      else if (i >= mutt_strlen (StChars))
+      else if (i >= str_len (StChars))
         buf[0] = StChars[0];
       else
         buf[0] = StChars[i];
@@ -279,8 +284,7 @@ static const char *status_format_str (char *buf, size_t buflen, char op,
     break;
 
   case 'v':
-    snprintf (fmt, sizeof (fmt), "Mutt-ng %%s");
-    snprintf (buf, buflen, fmt, MUTT_VERSION);
+    strncpy (buf, mutt_make_version (0), buflen);
     break;
 
   case 'V':
@@ -310,9 +314,13 @@ static const char *status_format_str (char *buf, size_t buflen, char op,
   return (src);
 }
 
-void menu_status_line (char *buf, size_t buflen, MUTTMENU * menu,
-                       const char *p)
-{
-  mutt_FormatString (buf, buflen, p, status_format_str, (unsigned long) menu,
-                     0);
+void menu_status_line (char* buf, size_t len, MUTTMENU* menu, const char* p) {
+  /*
+   * if we have enough space for buffer, format lines to $COLS-$SidebarWidth
+   * only to not wrap past end of screen
+   */
+  int width = COLS - SW;
+  mutt_FormatString (buf, (width >= len ? len : (width + 1)),
+                     p, status_format_str,
+                     (unsigned long) menu, 0);
 }