Simplify sidebar code
[apps/madmutt.git] / lib-ui / sidebar.c
index 464a5c4..a83505c 100644 (file)
@@ -53,33 +53,33 @@ static void calc_boundaries (void) {
     TopBuffy = 0;
 }
 
-static char *shortened_hierarchy (char *box, int maxlen)
+static char *shortened_hierarchy (char *hbox, int maxlen)
 {
   int dots = 0;
   char *last_dot = NULL;
-  int i, j, len = m_strlen(box);
+  int i, j, len = m_strlen(hbox);
   char *new_box;
 
   if (!SidebarBoundary || !*SidebarBoundary)
-    return (m_strdup(box));
+    return (m_strdup(hbox));
 
   for (i = 0; i < len; ++i) {
-    if (strchr (SidebarBoundary, box[i])) {
+    if (strchr (SidebarBoundary, hbox[i])) {
       ++dots;
-      last_dot = &box[i];
+      last_dot = &hbox[i];
     }
   }
 
   if (last_dot) {
     ++last_dot;
     new_box = p_new(char, maxlen + 1);
-    new_box[0] = box[0];
+    new_box[0] = hbox[0];
     for (i = 1, j = 1; j < maxlen && i < len; ++i) {
-      if (strchr (SidebarBoundary, box[i])) {
-        new_box[j++] = box[i];
+      if (strchr (SidebarBoundary, hbox[i])) {
+        new_box[j++] = hbox[i];
         new_box[j] = 0;
-        if (&box[i + 1] != last_dot || j + m_strlen(last_dot) > maxlen) {
-          new_box[j++] = box[i + 1];
+        if (&hbox[i + 1] != last_dot || j + m_strlen(last_dot) > maxlen) {
+          new_box[j++] = hbox[i + 1];
           new_box[j] = 0;
         } else {
           strcat (&new_box[j], last_dot);
@@ -89,7 +89,7 @@ static char *shortened_hierarchy (char *box, int maxlen)
     }
     return new_box;
   }
-  return m_strdup(box);
+  return m_strdup(hbox);
 }
 
 static const char* sidebar_number_format (char* dest, ssize_t destlen, char op,
@@ -183,7 +183,7 @@ int sidebar_need_count (void) {
  *      0       item was not printed ('cause of $sidebar_newmail_only)
  *      1       item was printed
  */
-int make_sidebar_entry (char* box, int idx, ssize_t len)
+static int make_sidebar_entry (char* sbox, int idx, ssize_t len)
 {
   int shortened = 0, lencnt = 0;
   char no[SHORT_STRING], entry[SHORT_STRING];
@@ -193,8 +193,8 @@ int make_sidebar_entry (char* box, int idx, ssize_t len)
   if (SidebarWidth > COLS)
     SidebarWidth = COLS;
 
-  if (option (OPTSIDEBARNEWMAILONLY) && box && Context && Context->path && 
-      m_strcmp(Context->path, box) && ((BUFFY*) Incoming->data[idx])->new == 0)
+  if (option (OPTSIDEBARNEWMAILONLY) && sbox && Context && Context->path && 
+      m_strcmp(Context->path, sbox) && ((BUFFY*) Incoming->data[idx])->new == 0)
     /* 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) */
@@ -205,32 +205,32 @@ int make_sidebar_entry (char* box, int idx, ssize_t len)
   lencnt = m_strlen(no);
   memset(&entry, ' ', sizeof(entry));
 
-  if (l > 0 && m_strncmp(box, ImapHomeNamespace, l) == 0 && 
-      m_strlen(box) > l)
-    box += l + 1; /* we're trimming the ImapHomeNamespace, the "+ 1" is for the separator */
+  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(box, Maildir, l_m) == 0 && 
-      m_strlen(box) > l_m) {
-    box += l_m;
+  if (l_m > 0 && m_strncmp(sbox, Maildir, l_m) == 0 && 
+      m_strlen(sbox) > l_m) {
+    sbox += l_m;
     if (Maildir[strlen(Maildir)-1]!='/') {
-      box += 1;
+      sbox += 1;
     }
   } else
-    box = basename (box);
+    sbox = basename (sbox);
 
-  if (option (OPTSHORTENHIERARCHY) && m_strlen(box) > len-lencnt-1) {
-    box = shortened_hierarchy (box, 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, box);
+  m_strcpy(entry, len - lencnt, sbox);
   entry[m_strlen(entry)] = ' ';
   memcpy(entry + (len - lencnt), no, lencnt);
 
   addnstr (entry, len);
 
   if (shortened)
-    p_delete(&box);
+    p_delete(&sbox);
 
   return (1);
 }
@@ -256,16 +256,16 @@ void sidebar_set_current (const char* buf) {
 /* fix counters for a context
  * FIXME since ctx must not be of our business, move it elsewhere
  */
-void sidebar_set_buffystats (CONTEXT* Context) {
+void sidebar_set_buffystats (CONTEXT* curContext) {
   int i = 0;
   BUFFY* tmp = NULL;
-  if (!Context || list_empty(Incoming) || (i = buffy_lookup (Context->path)) < 0)
+  if (!curContext || list_empty(Incoming) || (i = buffy_lookup (curContext->path)) < 0)
     return;
-  tmp = (BUFFY*) Incoming->data[i];
-  tmp->new = Context->new;
-  tmp->msg_unread = Context->unread;
-  tmp->msgcount = Context->msgcount;
-  tmp->msg_flagged = Context->flagged;
+  tmp = Incoming->data[i];
+  tmp->new = curContext->new;
+  tmp->msg_unread = curContext->unread;
+  tmp->msgcount = curContext->msgcount;
+  tmp->msg_flagged = curContext->flagged;
 }
 
 void sidebar_draw_frames (void) {
@@ -316,7 +316,7 @@ void sidebar_draw_frames (void) {
 /* actually draws something
  * FIXME this needs some clue when to do it
  */
-int sidebar_draw (int menu) {
+int sidebar_draw (void) {
   int first_line = option (OPTSTATUSONTOP) ? 1 : option (OPTHELP) ? 1 : 0,
       last_line = LINES - 2 + (option (OPTSTATUSONTOP) && !option (OPTHELP) ? 1 : 0),
       i = 0,line;
@@ -412,7 +412,7 @@ static int exist_prev_new () {
   return (-1);
 }
 
-void sidebar_scroll (int op, int menu) {
+void sidebar_scroll (int op) {
   int i = 0;
 
   if (!SidebarWidth || list_empty(Incoming))
@@ -476,5 +476,5 @@ void sidebar_scroll (int op, int menu) {
     return;
   }
   calc_boundaries ();
-  sidebar_draw (menu);
+  sidebar_draw ();
 }