more useless and cluttered things.
[apps/madmutt.git] / lib-ui / sidebar.c
index 48e4360..8065e55 100644 (file)
@@ -92,12 +92,14 @@ static char *shortened_hierarchy (char *hbox, int maxlen)
   return m_strdup(hbox);
 }
 
-static const char* sidebar_number_format (char* dest, ssize_t destlen, char op,
-                                          const char* src, const char* fmt,
-                                          const char* ifstr, const char* elstr,
-                                          unsigned long data, format_flag flags) {
+static const char *
+sidebar_number_format(char* dest, ssize_t destlen,
+                      char op, const char* src, const char* fmt,
+                      const char* ifstr, const char* elstr,
+                      anytype data, format_flag flags)
+{
   char tmp[STRING];
-  BUFFY* b = Incoming.arr[data];
+  BUFFY* b = Incoming.arr[data.i];
   int opt = flags & M_FORMAT_OPTIONAL;
   int c = Context && !m_strcmp(Context->path, b->path);
 
@@ -162,13 +164,10 @@ static const char* sidebar_number_format (char* dest, ssize_t destlen, char op,
       break;
   }
 
-  if (opt)
-    m_strformat (dest, destlen, ifstr, sidebar_number_format,
-                       data, M_FORMAT_OPTIONAL);
-  else if (flags & M_FORMAT_OPTIONAL)
-    m_strformat (dest, destlen, elstr, sidebar_number_format,
-                       data, M_FORMAT_OPTIONAL);
-  return (src);
+  if (flags & M_FORMAT_OPTIONAL)
+    m_strformat(dest, destlen, 0, opt ? ifstr : elstr,
+                sidebar_number_format, data, flags);
+  return src;
 }
 
 int sidebar_need_count (void) {
@@ -187,7 +186,6 @@ static int make_sidebar_entry (char* sbox, int idx, ssize_t len)
 {
   int shortened = 0, lencnt = 0;
   char no[STRING], entry[STRING];
-  int l = m_strlen(ImapHomeNamespace);
   int l_m = m_strlen(Maildir);
 
   if (SidebarWidth > COLS)
@@ -198,17 +196,11 @@ static int make_sidebar_entry (char* sbox, int idx, ssize_t len)
     /* if $sidebar_newmail_only is set, don't display the
      * box only if it's not the currently opened
      * (i.e. always display the currently opened) */
-    return (0);
+    return 0;
 
-  m_strformat (no, len, NONULL (SidebarNumberFormat),
-                     sidebar_number_format, idx, M_FORMAT_OPTIONAL);
+  m_strformat(no, len, SidebarWidth, SidebarNumberFormat, sidebar_number_format, idx, 0);
   lencnt = m_strlen(no);
-  memset(&entry, ' ', sizeof(entry));
 
-  if (l > 0 && m_strncmp(sbox, ImapHomeNamespace, l) == 0 && 
-      m_strlen(sbox) > l)
-    sbox += l + 1; /* we're trimming the ImapHomeNamespace, the "+ 1" is for the separator */
-  else
   if (l_m > 0 && m_strncmp(sbox, Maildir, l_m) == 0 && 
       m_strlen(sbox) > l_m) {
     sbox += l_m;
@@ -218,21 +210,19 @@ static int make_sidebar_entry (char* sbox, int idx, ssize_t len)
   } else
     sbox = basename (sbox);
 
-  if (option (OPTSHORTENHIERARCHY) && m_strlen(sbox) > len-lencnt-1) {
+  if (option(OPTSHORTENHIERARCHY) && m_strlen(sbox) > len-lencnt-1) {
     sbox = shortened_hierarchy (sbox, len-lencnt-1);
     shortened = 1;
   }
 
-  m_strcpy(entry, len - lencnt, sbox);
-  entry[m_strlen(entry)] = ' ';
-  memcpy(entry + (len - lencnt), no, lencnt);
-
-  addnstr (entry, len);
+  snprintf(entry, sizeof(entry), "%*s", (int)len, no);
+  memcpy(entry, sbox, MIN(len - 1, m_strlen(sbox)));
+  addnstr(entry, len);
 
   if (shortened)
     p_delete(&sbox);
 
-  return (1);
+  return 1;
 }
 
 /* returns folder name of currently