]> granicus.if.org Git - neomutt/commitdiff
indent: our functions
authorRichard Russon <rich@flatcap.org>
Mon, 30 Nov 2015 04:25:05 +0000 (04:25 +0000)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 02:37:42 +0000 (03:37 +0100)
NOTE: this patch does NOT make any code changes.
If only adds/removes whitespace.

Use whitespace uniformly across all of our code.

Delete trailing whitespace
Indent with tabs
Function {} to beginning of line
Other {} in compact style
Tidy whitespace around ()'s and maths operators

buffy.c
mh.c
sidebar.c
sidebar.h

diff --git a/buffy.c b/buffy.c
index cb4d80962e02b04b98932070985fc7c20a0c66ad..47933a19f4633d7198e211c29b115cd0ca1b3da9 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -162,47 +162,50 @@ void mutt_buffy_cleanup (const char *buf, struct stat *st)
   }
 }
 
-static int buffy_compare_name(const void *a, const void *b) {
-  const BUFFY *b1 = * (BUFFY * const *) a;
-  const BUFFY *b2 = * (BUFFY * const *) b;
+static int
+buffy_compare_name (const void *a, const void *b)
+{
+       const BUFFY *b1 = *(BUFFY * const *) a;
+       const BUFFY *b2 = *(BUFFY * const *) b;
 
-  return mutt_strcoll(b1->path, b2->path);
+       return mutt_strcoll (b1->path, b2->path);
 }
 
-static BUFFY *buffy_sort(BUFFY *b)
+static BUFFY *
+buffy_sort (BUFFY *b)
 {
-  BUFFY *tmp = b;
-  int buffycount = 0;
-  BUFFY **ary;
-  int i;
+       BUFFY *tmp = b;
+       int buffycount = 0;
+       BUFFY **ary;
+       int i;
 
-  if (!option(OPTSIDEBARSORT))
-    return b;
+       if (!option (OPTSIDEBARSORT))
+               return b;
 
-  for (; tmp != NULL; tmp = tmp->next)
-    buffycount++;
+       for (; tmp != NULL; tmp = tmp->next)
+               buffycount++;
 
-  ary = (BUFFY **) safe_calloc(buffycount, sizeof (*ary));
+       ary = (BUFFY **) safe_calloc (buffycount, sizeof (*ary));
 
-  tmp = b;
-  for (i = 0; tmp != NULL; tmp = tmp->next, i++) {
-    ary[i] = tmp;
-  }
+       tmp = b;
+       for (i = 0; tmp != NULL; tmp = tmp->next, i++) {
+               ary[i] = tmp;
+       }
 
-  qsort(ary, buffycount, sizeof(*ary), buffy_compare_name);
+       qsort (ary, buffycount, sizeof (*ary), buffy_compare_name);
 
-  for (i = 0; i < buffycount - 1; i++) {
-    ary[i]->next = ary[i+1];
-  }
-  ary[buffycount - 1]->next = NULL;
-  for (i = 1; i < buffycount; i++) {
-    ary[i]->prev = ary[i-1];
-  }
-  ary[0]->prev = NULL;
+       for (i = 0; i < buffycount - 1; i++) {
+               ary[i]->next = ary[i+1];
+       }
+       ary[buffycount - 1]->next = NULL;
+       for (i = 1; i < buffycount; i++) {
+               ary[i]->prev = ary[i-1];
+       }
+       ary[0]->prev = NULL;
 
-  tmp = ary[0];
-  free(ary);
-  return tmp;
+       tmp = ary[0];
+       free (ary);
+       return tmp;
 }
 
 BUFFY *mutt_find_mailbox (const char *path)
@@ -411,71 +414,68 @@ static int buffy_maildir_hasnew (BUFFY* mailbox)
 
   return 0;
 }
-  
- /* update message counts for the sidebar */
-void buffy_maildir_update (BUFFY* mailbox)
+
+/* update message counts for the sidebar */
+void
+buffy_maildir_update (BUFFY *mailbox)
 {
- char path[_POSIX_PATH_MAX];
- DIR *dirp;
- struct dirent *de;
- char *p;
-
- if(!option(OPTSIDEBAR))
-     return;
-
- mailbox->msgcount = 0;
- mailbox->msg_unread = 0;
- mailbox->msg_flagged = 0;
-
- snprintf (path, sizeof (path), "%s/new", mailbox->path);
-       
- if ((dirp = opendir (path)) == NULL)
- {   
-   mailbox->magic = 0;
-   return;
- } 
-       
- while ((de = readdir (dirp)) != NULL)
- {
-   if (*de->d_name == '.')
-     continue;
-
-   if (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')) {
-     mailbox->new = 1;
-     mailbox->msgcount++;
-     mailbox->msg_unread++;
-   }
- }
-
- closedir (dirp);
- snprintf (path, sizeof (path), "%s/cur", mailbox->path);
-       
- if ((dirp = opendir (path)) == NULL)
- {   
-  mailbox->magic = 0;
-   return;
- } 
-       
- while ((de = readdir (dirp)) != NULL)
- {
-   if (*de->d_name == '.')
-     continue;
-
-   if (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')) {
-     mailbox->msgcount++;
-     if ((p = strstr (de->d_name, ":2,"))) {
-       if (!strchr (p + 3, 'T')) {
-         if (!strchr (p + 3, 'S'))
-           mailbox->msg_unread++;
-         if (strchr(p + 3, 'F'))
-           mailbox->msg_flagged++;
-       }
-     }
-   }
- }
-
- mailbox->sb_last_checked = time(NULL);
- closedir (dirp);
+       char path[_POSIX_PATH_MAX];
+       DIR *dirp;
+       struct dirent *de;
+       char *p;
+
+       if (!option (OPTSIDEBAR))
+               return;
+
+       mailbox->msgcount    = 0;
+       mailbox->msg_unread  = 0;
+       mailbox->msg_flagged = 0;
+
+       snprintf (path, sizeof (path), "%s/new", mailbox->path);
+
+       if ((dirp = opendir (path)) == NULL) {
+               mailbox->magic = 0;
+               return;
+       }
+
+       while ((de = readdir (dirp)) != NULL) {
+               if (*de->d_name == '.')
+                       continue;
+
+               if (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')) {
+                       mailbox->new = 1;
+                       mailbox->msgcount++;
+                       mailbox->msg_unread++;
+               }
+       }
+
+       closedir (dirp);
+       snprintf (path, sizeof (path), "%s/cur", mailbox->path);
+
+       if ((dirp = opendir (path)) == NULL) {
+               mailbox->magic = 0;
+               return;
+       }
+
+       while ((de = readdir (dirp)) != NULL) {
+               if (*de->d_name == '.')
+                       continue;
+
+               if (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')) {
+                       mailbox->msgcount++;
+                       if ((p = strstr (de->d_name, ":2,"))) {
+                               if (!strchr (p + 3, 'T')) {
+                                       if (!strchr (p + 3, 'S'))
+                                               mailbox->msg_unread++;
+                                       if (strchr (p + 3, 'F'))
+                                               mailbox->msg_flagged++;
+                               }
+                       }
+               }
+       }
+
+       mailbox->sb_last_checked = time (NULL);
+       closedir (dirp);
 }
 
 /* returns 1 if mailbox has new mail */ 
@@ -510,24 +510,24 @@ static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb)
 }
 
 /* update message counts for the sidebar */
-void buffy_mbox_update (BUFFY* mailbox, struct stat *sb)
+void
+buffy_mbox_update (BUFFY *mailbox, struct stat *sb)
 {
-  CONTEXT *ctx = NULL;
-
-  if(!option(OPTSIDEBAR))
-      return;
-  if(mailbox->sb_last_checked > sb->st_mtime && mailbox->msgcount != 0)
-      return; /* no check necessary */
-
-  ctx = mx_open_mailbox(mailbox->path, M_READONLY | M_QUIET | M_NOSORT | M_PEEK, NULL);
-  if(ctx)
-  {
-    mailbox->msgcount = ctx->msgcount;
-    mailbox->msg_unread = ctx->unread;
-    mailbox->msg_flagged = ctx->flagged;
-    mailbox->sb_last_checked = time(NULL);
-    mx_close_mailbox(ctx, 0);
-  }
+       CONTEXT *ctx = NULL;
+
+       if (!option (OPTSIDEBAR))
+               return;
+       if (mailbox->sb_last_checked > sb->st_mtime && mailbox->msgcount != 0)
+               return; /* no check necessary */
+
+       ctx = mx_open_mailbox (mailbox->path, M_READONLY | M_QUIET | M_NOSORT | M_PEEK, NULL);
+       if (ctx) {
+               mailbox->msgcount        = ctx->msgcount;
+               mailbox->msg_unread      = ctx->unread;
+               mailbox->msg_flagged     = ctx->flagged;
+               mailbox->sb_last_checked = time (NULL);
+               mx_close_mailbox (ctx, 0);
+       }
 }
 
 int mutt_buffy_check (int force)
diff --git a/mh.c b/mh.c
index 3121fca583eef3d7dcfb22731ecfdb6e2036ab19..42fe3a7f5f935ddef61e1d0a0d6001da157c4f4c 100644 (file)
--- a/mh.c
+++ b/mh.c
@@ -295,30 +295,33 @@ void mh_buffy(BUFFY *b)
   mhs_free_sequences (&mhs);
 }
 
-void mh_buffy_update (const char *path, int *msgcount, int *msg_unread, int *msg_flagged, time_t *sb_last_checked)
+void
+mh_buffy_update (const char *path, int *msgcount, int *msg_unread, int *msg_flagged, time_t *sb_last_checked)
 {
-  int i;
-  struct mh_sequences mhs;
-  memset (&mhs, 0, sizeof (mhs));
+       int i;
+       struct mh_sequences mhs;
+       memset (&mhs, 0, sizeof (mhs));
 
-  if(!option(OPTSIDEBAR))
-      return;
+       if (!option (OPTSIDEBAR))
+               return;
 
-  if (mh_read_sequences (&mhs, path) < 0)
-    return;
+       if (mh_read_sequences (&mhs, path) < 0)
+               return;
 
-  msgcount = 0;
-  msg_unread = 0;
-  msg_flagged = 0;
-  for (i = 0; i <= mhs.max; i++)
-    msgcount++;
-    if (mhs_check (&mhs, i) & MH_SEQ_UNSEEN) {
-      msg_unread++;
-    }
-    if (mhs_check (&mhs, i) & MH_SEQ_FLAGGED)
-      msg_flagged++;
-  mhs_free_sequences (&mhs);
-  *sb_last_checked = time(NULL);
+       msgcount    = 0;
+       msg_unread  = 0;
+       msg_flagged = 0;
+
+       for (i = 0; i <= mhs.max; i++)
+               msgcount++;
+
+       if (mhs_check (&mhs, i) & MH_SEQ_UNSEEN) {
+               msg_unread++;
+       }
+       if (mhs_check (&mhs, i) & MH_SEQ_FLAGGED)
+               msg_flagged++;
+       mhs_free_sequences (&mhs);
+       *sb_last_checked = time (NULL);
 }
 
 static int mh_mkstemp (CONTEXT * dest, FILE ** fp, char **tgt)
index e62b9460efd32d6e6911a0caa4e9112640902666..122d3d03570f860fb7d0aed4058f06d5b2d13d21 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -1,22 +1,21 @@
 /*
  * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
  * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
- * 
+ *
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
  *     the Free Software Foundation; either version 2 of the License, or
  *     (at your option) any later version.
- * 
+ *
  *     This program is distributed in the hope that it will be useful,
  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *     GNU General Public License for more details.
- * 
+ *
  *     You should have received a copy of the GNU General Public License
  *     along with this program; if not, write to the Free Software
  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
- */ 
-
+ */
 
 #if HAVE_CONFIG_H
 # include "config.h"
@@ -76,272 +75,270 @@ find_prev_new (int wrap)
        return NULL;
 }
 
-void calc_boundaries() {
-
-    BUFFY *tmp = Incoming;
+void
+calc_boundaries()
+{
+       BUFFY *tmp = Incoming;
 
-       int count = LINES - 2 - (option(OPTHELP) ? 1 : 0);
+       int count = LINES - 2 - (option (OPTHELP) ? 1 : 0);
 
-       if ( known_lines != LINES ) {
+       if (known_lines != LINES) {
                TopBuffy = BottomBuffy = 0;
                known_lines = LINES;
        }
-       for ( ; tmp->next != 0; tmp = tmp->next )
+       for (; tmp->next != 0; tmp = tmp->next)
                tmp->next->prev = tmp;
 
-       if ( TopBuffy == 0 && BottomBuffy == 0 )
+       if (TopBuffy == 0 && BottomBuffy == 0)
                TopBuffy = Incoming;
-       if ( BottomBuffy == 0 ) {
+       if (BottomBuffy == 0) {
                BottomBuffy = TopBuffy;
-               while ( --count && BottomBuffy->next )
+               while (--count && BottomBuffy->next)
                        BottomBuffy = BottomBuffy->next;
        }
-       else if ( TopBuffy == CurBuffy->next ) {
+       else if (TopBuffy == CurBuffy->next) {
                BottomBuffy = CurBuffy;
                tmp = BottomBuffy;
-               while ( --count && tmp->prev)
+               while (--count && tmp->prev)
                        tmp = tmp->prev;
                TopBuffy = tmp;
        }
-       else if ( BottomBuffy == CurBuffy->prev ) {
+       else if (BottomBuffy == CurBuffy->prev) {
                TopBuffy = CurBuffy;
                tmp = TopBuffy;
-               while ( --count && tmp->next )
+               while (--count && tmp->next)
                        tmp = tmp->next;
                BottomBuffy = tmp;
        }
 }
 
 static const char *
-sidebar_format_str (char *dest,
-                       size_t destlen,
-                       size_t col,
-                       char op,
-                       const char *src,
-                       const char *prefix,
-                       const char *ifstring,
-                       const char *elsestring,
-                       unsigned long data,
-                       format_flag flags)
+sidebar_format_str (char *dest, size_t destlen, size_t col, char op, const char *src,
+       const char *prefix, const char *ifstring, const char *elsestring,
+       unsigned long data, format_flag flags)
 {
-/* casting from unsigned long - srsly?! */
-struct sidebar_entry *sbe = (struct sidebar_entry *) data;
-unsigned int optional;
-char fmt[SHORT_STRING], buf[SHORT_STRING];
-
-optional = flags & M_FORMAT_OPTIONAL;
-
-switch(op) {
-       case 'B':
-               mutt_format_s(dest, destlen, prefix, sbe->box);
-               break;
-
-       case 'F':
-               if(!optional) {
-                       snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
-                       snprintf (dest, destlen, fmt, sbe->flagged);
-               } else if(sbe->flagged == 0) {
-                       optional = 0;
-               }
-               break;
-
-       case 'N':
-               if(!optional) {
-                       snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
-                       snprintf (dest, destlen, fmt, sbe->new);
-               } else if(sbe->new == 0) {
-                       optional = 0;
-               }
-               break;
-
-       case 'S':
-                if(!optional) {
-                   snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
-                   snprintf (dest, destlen, fmt, sbe->size);
-                } else if (sbe->size == 0) {
-                    optional = 0;
-                }
-               break;
-
-       case '!':
-               if(sbe->flagged == 0)
-                       mutt_format_s(dest, destlen, prefix, "");
-               if(sbe->flagged == 1)
-                       mutt_format_s(dest, destlen, prefix, "!");
-               if(sbe->flagged == 2)
-                       mutt_format_s(dest, destlen, prefix, "!!");
-               if(sbe->flagged > 2) {
-                       snprintf (buf, sizeof (buf), "%d!", sbe->flagged);
-                       mutt_format_s(dest, destlen, prefix, buf);
-               }
-               break;
+       /* casting from unsigned long - srsly?! */
+       struct sidebar_entry *sbe = (struct sidebar_entry *) data;
+       unsigned int optional;
+       char fmt[SHORT_STRING], buf[SHORT_STRING];
+
+       optional = flags & M_FORMAT_OPTIONAL;
+
+       switch (op) {
+               case 'B':
+                       mutt_format_s (dest, destlen, prefix, sbe->box);
+                       break;
+
+               case 'F':
+                       if (!optional) {
+                               snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
+                               snprintf (dest, destlen, fmt, sbe->flagged);
+                       } else if (sbe->flagged == 0) {
+                               optional = 0;
+                       }
+                       break;
+
+               case 'N':
+                       if (!optional) {
+                               snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
+                               snprintf (dest, destlen, fmt, sbe->new);
+                       } else if (sbe->new == 0) {
+                               optional = 0;
+                       }
+                       break;
+
+               case 'S':
+                       if (!optional) {
+                               snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
+                               snprintf (dest, destlen, fmt, sbe->size);
+                       } else if (sbe->size == 0) {
+                               optional = 0;
+                       }
+                       break;
+
+               case '!':
+                       if (sbe->flagged == 0)
+                               mutt_format_s (dest, destlen, prefix, "");
+                       if (sbe->flagged == 1)
+                               mutt_format_s (dest, destlen, prefix, "!");
+                       if (sbe->flagged == 2)
+                               mutt_format_s (dest, destlen, prefix, "!!");
+                       if (sbe->flagged > 2) {
+                               snprintf (buf, sizeof (buf), "%d!", sbe->flagged);
+                               mutt_format_s (dest, destlen, prefix, buf);
+                       }
+                       break;
        }
 
-       if(optional)
-               mutt_FormatString (dest, destlen, col, ifstring, sidebar_format_str, (unsigned long) sbe, flags);
+       if (optional)
+               mutt_FormatString (dest, destlen, col, ifstring,   sidebar_format_str, (unsigned long) sbe, flags);
        else if (flags & M_FORMAT_OPTIONAL)
                mutt_FormatString (dest, destlen, col, elsestring, sidebar_format_str, (unsigned long) sbe, flags);
 
        return (src);
 }
 
-static void make_sidebar_entry(char *buf, unsigned int buflen, int width, char *box,
+static void
+make_sidebar_entry (char *buf, unsigned int buflen, int width, char *box,
        unsigned int size, unsigned int new, unsigned int flagged)
 {
-    struct sidebar_entry sbe;
-
-    sbe.new = new;
-    sbe.flagged = flagged;
-    sbe.size = size;
-    strncpy(sbe.box, box, sizeof (sbe.box)-1);
-
-    int box_len = strlen (box);
-    sbe.box[box_len] = '\0';
-
-    /* Temporarily lie about the screen width */
-    int oc = COLS;
-    COLS = width + SidebarWidth;
-    mutt_FormatString (buf, buflen, 0, SidebarFormat, sidebar_format_str, (unsigned long) &sbe, 0);
-    COLS = oc;
-
-    /* Force string to be exactly the right width */
-    int w = mutt_strwidth (buf);
-    int s = strlen (buf);
-    if (w < width) {
-        /* Pad with spaces */
-        memset (buf+s, ' ', width - w);
-        buf[s + width - w] = 0;
-    } else if (w > width) {
-        /* Truncate to fit */
-        int len = mutt_wstr_trunc (buf, buflen, width, NULL);
-        buf[len] = 0;
-    }
+       struct sidebar_entry sbe;
+
+       sbe.new = new;
+       sbe.flagged = flagged;
+       sbe.size = size;
+       strncpy (sbe.box, box, sizeof (sbe.box)-1);
+
+       int box_len = strlen (box);
+       sbe.box[box_len] = '\0';
+
+       /* Temporarily lie about the screen width */
+       int oc = COLS;
+       COLS = width + SidebarWidth;
+       mutt_FormatString (buf, buflen, 0, SidebarFormat, sidebar_format_str, (unsigned long) &sbe, 0);
+       COLS = oc;
+
+       /* Force string to be exactly the right width */
+       int w = mutt_strwidth (buf);
+       int s = strlen (buf);
+       if (w < width) {
+               /* Pad with spaces */
+               memset (buf+s, ' ', width - w);
+               buf[s + width - w] = 0;
+       } else if (w > width) {
+               /* Truncate to fit */
+               int len = mutt_wstr_trunc (buf, buflen, width, NULL);
+               buf[len] = 0;
+       }
 }
 
-int draw_sidebar(int menu) {
-
+int
+draw_sidebar (int menu)
+{
        BUFFY *tmp;
 #ifndef USE_SLANG_CURSES
-        attr_t attrs;
+       attr_t attrs;
 #endif
-        short color_pair;
+       short color_pair;
 
        /* Calculate the width of the delimiter in screen characters */
        wchar_t sd[4];
-       mbstowcs(sd, NONULL(SidebarDelim), 4);
+       mbstowcs (sd, NONULL(SidebarDelim), 4);
        int delim_len = wcwidth (sd[0]);
 
-        static bool initialized = false;
-        static int prev_show_value;
-        static short saveSidebarWidth;
-        int lines = 0;
-        int SidebarHeight;
-        
-        if(option(OPTSTATUSONTOP) || option(OPTHELP))
-                lines++; /* either one will occupy the first line */
-
-        /* initialize first time */
-        if(!initialized) {
-                prev_show_value = option(OPTSIDEBAR);
-                saveSidebarWidth = SidebarWidth;
-                if(!option(OPTSIDEBAR)) SidebarWidth = 0;
-                SidebarLastRefresh = time(NULL);
-                initialized = true;
-        }
-
-        /* save or restore the value SidebarWidth */
-        if(prev_show_value != option(OPTSIDEBAR)) {
-                if(prev_show_value && !option(OPTSIDEBAR)) {
-                        saveSidebarWidth = SidebarWidth;
-                        SidebarWidth = 0;
-                } else if(!prev_show_value && option(OPTSIDEBAR)) {
-                        mutt_buffy_check(1); /* we probably have bad or no numbers */
-                        SidebarWidth = saveSidebarWidth;
-                }
-                prev_show_value = option(OPTSIDEBAR);
-        }
-
-
-/*     if ( SidebarWidth == 0 ) return 0; */
-       if (SidebarWidth > 0 && option (OPTSIDEBAR)
-           && delim_len >= SidebarWidth) {
-         unset_option (OPTSIDEBAR);
-         /* saveSidebarWidth = SidebarWidth; */
-         if (saveSidebarWidth > delim_len) {
-           SidebarWidth = saveSidebarWidth;
-           mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar."));
-           sleep (2);
-         } else {
-           SidebarWidth = 0;
-           mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value."));
-           sleep (4); /* the advise to set a sane value should be seen long enough */
-         }
-         saveSidebarWidth = 0;
-         return (0);
-       }
-
-    if ( SidebarWidth == 0 || !option(OPTSIDEBAR)) {
-      if (SidebarWidth > 0) {
-        saveSidebarWidth = SidebarWidth;
-        SidebarWidth = 0;
-      }
-      unset_option(OPTSIDEBAR);
-      return 0;
-    }
-
-        /* get attributes for divider */
+       static bool initialized = false;
+       static int prev_show_value;
+       static short saveSidebarWidth;
+       int lines = 0;
+       int SidebarHeight;
+
+       if (option (OPTSTATUSONTOP) || option (OPTHELP))
+               lines++; /* either one will occupy the first line */
+
+       /* initialize first time */
+       if (!initialized) {
+               prev_show_value = option (OPTSIDEBAR);
+               saveSidebarWidth = SidebarWidth;
+               if (!option (OPTSIDEBAR))
+                       SidebarWidth = 0;
+               SidebarLastRefresh = time (NULL);
+               initialized = true;
+       }
+
+       /* save or restore the value SidebarWidth */
+       if (prev_show_value != option (OPTSIDEBAR)) {
+               if (prev_show_value && !option (OPTSIDEBAR)) {
+                       saveSidebarWidth = SidebarWidth;
+                       SidebarWidth = 0;
+               } else if (!prev_show_value && option (OPTSIDEBAR)) {
+                       mutt_buffy_check (1); /* we probably have bad or no numbers */
+                       SidebarWidth = saveSidebarWidth;
+               }
+               prev_show_value = option (OPTSIDEBAR);
+       }
+
+
+/*     if (SidebarWidth == 0) return 0; */
+       if (SidebarWidth > 0 && option (OPTSIDEBAR) && delim_len >= SidebarWidth) {
+               unset_option (OPTSIDEBAR);
+               /* saveSidebarWidth = SidebarWidth; */
+               if (saveSidebarWidth > delim_len) {
+                       SidebarWidth = saveSidebarWidth;
+                       mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar."));
+                       sleep (2);
+               } else {
+                       SidebarWidth = 0;
+                       mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value."));
+                       sleep (4); /* the advise to set a sane value should be seen long enough */
+               }
+               saveSidebarWidth = 0;
+               return (0);
+       }
+
+       if (SidebarWidth == 0 || !option (OPTSIDEBAR)) {
+               if (SidebarWidth > 0) {
+                       saveSidebarWidth = SidebarWidth;
+                       SidebarWidth = 0;
+               }
+               unset_option (OPTSIDEBAR);
+               return 0;
+       }
+
+       /* get attributes for divider */
        SETCOLOR(MT_COLOR_STATUS);
 #ifndef USE_SLANG_CURSES
-        attr_get(&attrs, &color_pair, 0);
+       attr_get (&attrs, &color_pair, 0);
 #else
-        color_pair = attr_get();
+       color_pair = attr_get();
 #endif
        SETCOLOR(MT_COLOR_NORMAL);
 
        /* draw the divider */
 
-       SidebarHeight =  LINES - 1;
-       if(option(OPTHELP) || !option(OPTSTATUSONTOP))
+       SidebarHeight = LINES - 1;
+       if (option (OPTHELP) || !option (OPTSTATUSONTOP))
                SidebarHeight--;
 
-       for ( ; lines < SidebarHeight; lines++ ) {
-               move(lines, SidebarWidth - delim_len);
-               addstr(NONULL(SidebarDelim));
+       for (; lines < SidebarHeight; lines++) {
+               move (lines, SidebarWidth - delim_len);
+               addstr (NONULL(SidebarDelim));
 #ifndef USE_SLANG_CURSES
-                mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL);
+               mvchgat (lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL);
 #endif
        }
 
-       if ( Incoming == 0 ) return 0;
-        lines = 0;
-        if(option(OPTSTATUSONTOP) || option(OPTHELP))
-                lines++; /* either one will occupy the first line */
+       if (Incoming == 0)
+               return 0;
+       lines = 0;
+       if (option (OPTSTATUSONTOP) || option (OPTHELP))
+               lines++; /* either one will occupy the first line */
 
-       if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 ) 
-               calc_boundaries(menu);
-       if ( CurBuffy == 0 ) CurBuffy = Incoming;
+       if (known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0)
+               calc_boundaries (menu);
+       if (CurBuffy == 0)
+               CurBuffy = Incoming;
 
        tmp = TopBuffy;
 
        SETCOLOR(MT_COLOR_NORMAL);
 
-       for ( ; tmp && lines < SidebarHeight; tmp = tmp->next ) {
+       for (; tmp && lines < SidebarHeight; tmp = tmp->next) {
                /* make sure the path is either:
                   1.  Containing new mail.
                   2.  The inbox.
                   3.  The current box.
                   4.  Any mailboxes listed in SidebarWhitelist
                */
-               if ( tmp == CurBuffy )
+               if (tmp == CurBuffy)
                        SETCOLOR(MT_COLOR_INDICATOR);
-               else if ( tmp->msg_unread > 0 )
+               else if (tmp->msg_unread > 0)
                        SETCOLOR(MT_COLOR_NEW);
-               else if ( tmp->msg_flagged > 0 )
-                       SETCOLOR(MT_COLOR_FLAGGED);
-               else if ( option(OPTSIDEBARNEWMAILONLY) ) {
-                       if      ( tmp == Incoming ||
-                                       ( Context && ( strcmp(tmp->path, Context->path) == 0 ) ) ||
-                                       mutt_find_list(SidebarWhitelist, tmp->path) )
+               else if (tmp->msg_flagged > 0)
+                       SETCOLOR(MT_COLOR_FLAGGED);
+               else if (option (OPTSIDEBARNEWMAILONLY)) {
+                       if (tmp == Incoming ||
+                                       (Context && (strcmp (tmp->path, Context->path) == 0)) ||
+                                       mutt_find_list (SidebarWhitelist, tmp->path))
                                SETCOLOR(MT_COLOR_NORMAL);
                        else
                                continue;
@@ -349,10 +346,10 @@ int draw_sidebar(int menu) {
                else
                        SETCOLOR(MT_COLOR_NORMAL);
 
-               move( lines, 0 );
-               if ( Context && Context->path &&
-                        (!strcmp(tmp->path, Context->path)||
-                        !strcmp(tmp->realpath, Context->path)) ) {
+               move (lines, 0);
+               if (Context && Context->path &&
+                       (!strcmp (tmp->path, Context->path)||
+                        !strcmp (tmp->realpath, Context->path))) {
                        tmp->msg_unread = Context->unread;
                        tmp->msgcount = Context->msgcount;
                        tmp->msg_flagged = Context->flagged;
@@ -366,9 +363,8 @@ int draw_sidebar(int menu) {
 
                /* check whether Maildir is a prefix of the current folder's path */
                short maildir_is_prefix = 0;
-               if ( (strlen(tmp->path) > maildirlen) &&
-                       (strncmp(Maildir, tmp->path, maildirlen) == 0) )
-                       maildir_is_prefix = 1;
+               if ((strlen (tmp->path) > maildirlen) && (strncmp (Maildir, tmp->path, maildirlen) == 0))
+                       maildir_is_prefix = 1;
                /* calculate depth of current folder and generate its display name with indented spaces */
                int sidebar_folder_depth = 0;
                char *sidebar_folder_name;
@@ -378,8 +374,7 @@ int draw_sidebar(int menu) {
                        sidebar_folder_name = tmp->path;
                        for (i = strlen (sidebar_folder_name) - 2; i >= 0; i--) {
                                if (SidebarDelimChars &&
-                                               strchr (SidebarDelimChars, sidebar_folder_name[i]))
-                               {
+                                               strchr (SidebarDelimChars, sidebar_folder_name[i])) {
                                        sidebar_folder_name += i + 1;
                                        break;
                                }
@@ -391,7 +386,7 @@ int draw_sidebar(int menu) {
                        const char *tmp_folder_name;
                        int lastsep = 0;
                        tmp_folder_name = tmp->path + maildirlen + 1;
-                       for (i = 0; i < strlen(tmp_folder_name) - 1; i++) {
+                       for (i = 0; i < strlen (tmp_folder_name) - 1; i++) {
                                if (SidebarDelimChars &&
                                                strchr (SidebarDelimChars, tmp_folder_name[i]))
                                {
@@ -400,130 +395,143 @@ int draw_sidebar(int menu) {
                                }
                        }
                        if (sidebar_folder_depth > 0) {
-                               if (option(OPTSIDEBARSHORTPATH)) {
-                                       tmp_folder_name += lastsep;  /* basename */
-                               }
-                               sidebar_folder_name = malloc(strlen(tmp_folder_name) + sidebar_folder_depth*strlen (NONULL (SidebarIndentStr)) + 1);
+                               if (option (OPTSIDEBARSHORTPATH)) {
+                                       tmp_folder_name += lastsep;  /* basename */
+                               }
+                               sidebar_folder_name = malloc (strlen (tmp_folder_name) + sidebar_folder_depth*strlen (NONULL(SidebarIndentStr)) + 1);
                                sidebar_folder_name[0]=0;
                                for (i=0; i < sidebar_folder_depth; i++)
-                                       strncat(sidebar_folder_name, NONULL(SidebarIndentStr), strlen(NONULL(SidebarIndentStr)));
-                               strncat(sidebar_folder_name, tmp_folder_name, strlen(tmp_folder_name));
+                                       strncat (sidebar_folder_name, NONULL(SidebarIndentStr), strlen (NONULL(SidebarIndentStr)));
+                               strncat (sidebar_folder_name, tmp_folder_name, strlen (tmp_folder_name));
                        }
                }
                char str[SHORT_STRING];
-               make_sidebar_entry(str, sizeof (str), SidebarWidth - delim_len,
+               make_sidebar_entry (str, sizeof (str), SidebarWidth - delim_len,
                        sidebar_folder_name, tmp->msgcount,
                        tmp->msg_unread, tmp->msg_flagged);
                printw ("%s", str);
                if (sidebar_folder_depth > 0)
-                       free(sidebar_folder_name);
+                       free (sidebar_folder_name);
                lines++;
        }
+
        SETCOLOR(MT_COLOR_NORMAL);
-       for ( ; lines < SidebarHeight; lines++ ) {
+       for (; lines < SidebarHeight; lines++) {
                int i = 0;
-               move( lines, 0 );
-               for ( ; i < SidebarWidth - delim_len; i++ )
-                       addch(' ');
+               move (lines, 0);
+               for (; i < SidebarWidth - delim_len; i++)
+                       addch (' ');
        }
        return 0;
 }
 
-int sidebar_should_refresh()
+int
+sidebar_should_refresh()
 {
-       if (option(OPTSIDEBAR) && SidebarRefresh > 0) {
-               if (time(NULL) - SidebarLastRefresh >= SidebarRefresh)
+       if (option (OPTSIDEBAR) && SidebarRefresh > 0) {
+               if (time (NULL) - SidebarLastRefresh >= SidebarRefresh)
                        return 1;
        }
        return 0;
 }
 
-void scroll_sidebar(int op, int menu)
+void
+scroll_sidebar (int op, int menu)
 {
-        BUFFY *tmp;
-        if(!SidebarWidth) return;
-        if(!CurBuffy) return;
+       BUFFY *tmp;
+       if (!SidebarWidth)
+               return;
+       if (!CurBuffy)
+               return;
 
        switch (op) {
                case OP_SIDEBAR_NEXT:
-                if (!option (OPTSIDEBARNEWMAILONLY)) {
-                       if ( CurBuffy->next == NULL ) return;
-                       CurBuffy = CurBuffy->next;
+                       if (!option (OPTSIDEBARNEWMAILONLY)) {
+                               if (CurBuffy->next == NULL)
+                                       return;
+                               CurBuffy = CurBuffy->next;
+                               break;
+                       }
+               case OP_SIDEBAR_NEXT_NEW:
+                       if ((tmp = find_next_new (option (OPTSIDEBARNEXTNEWWRAP))) == NULL)
+                               return;
+                       else
+                               CurBuffy = tmp;
                        break;
-                }
-                case OP_SIDEBAR_NEXT_NEW:
-                        if ((tmp = find_next_new(option (OPTSIDEBARNEXTNEWWRAP))) == NULL)
-                                return;
-                        else CurBuffy = tmp;
-                        break;
                case OP_SIDEBAR_PREV:
-                 if (!option (OPTSIDEBARNEWMAILONLY)) {
-                       if ( CurBuffy->prev == NULL ) return;
-                       CurBuffy = CurBuffy->prev;
+                       if (!option (OPTSIDEBARNEWMAILONLY)) {
+                               if (CurBuffy->prev == NULL)
+                                       return;
+                               CurBuffy = CurBuffy->prev;
+                               break;
+                       }
+               case OP_SIDEBAR_PREV_NEW:
+                       if ((tmp = find_prev_new (option (OPTSIDEBARNEXTNEWWRAP))) == NULL)
+                               return;
+                       else
+                               CurBuffy = tmp;
                        break;
-                }
-                case OP_SIDEBAR_PREV_NEW:
-                       if ((tmp = find_prev_new(option (OPTSIDEBARNEXTNEWWRAP))) == NULL)
-                               return;
-                       else CurBuffy = tmp;
-                       break;
                case OP_SIDEBAR_SCROLL_UP:
                        CurBuffy = TopBuffy;
-                       if ( CurBuffy != Incoming ) {
-                               calc_boundaries(menu);
+                       if (CurBuffy != Incoming) {
+                               calc_boundaries (menu);
                                CurBuffy = CurBuffy->prev;
                        }
                        break;
                case OP_SIDEBAR_SCROLL_DOWN:
                        CurBuffy = BottomBuffy;
-                       if ( CurBuffy->next ) {
-                               calc_boundaries(menu);
+                       if (CurBuffy->next) {
+                               calc_boundaries (menu);
                                CurBuffy = CurBuffy->next;
                        }
                        break;
                default:
                        return;
        }
-       calc_boundaries(menu);
-       draw_sidebar(menu);
+       calc_boundaries (menu);
+       draw_sidebar (menu);
 }
 
-void set_buffystats(CONTEXT* Context)
+void
+set_buffystats (CONTEXT *Context)
 {
-        BUFFY *tmp = Incoming;
-        while(tmp) {
-                if(Context && (!strcmp(tmp->path, Context->path) ||
-                               !strcmp(tmp->realpath, Context->path))) {
+       BUFFY *tmp = Incoming;
+       while (tmp) {
+               if (Context && (!strcmp (tmp->path, Context->path) ||
+                               !strcmp (tmp->realpath, Context->path))) {
                        tmp->msg_unread = Context->unread;
                        tmp->msgcount = Context->msgcount;
                        tmp->msg_flagged = Context->flagged;
-                        break;
-                }
-                tmp = tmp->next;
-        }
+                       break;
+               }
+               tmp = tmp->next;
+       }
 }
 
-void set_curbuffy(char buf[LONG_STRING])
+void
+set_curbuffy (char buf[LONG_STRING])
 {
-  BUFFY* tmp = CurBuffy = Incoming;
-
-  if (!Incoming)
-    return;
-
-  while(1) {
-    if(!strcmp(tmp->path, buf) || !strcmp(tmp->realpath, buf)) {
-      CurBuffy = tmp;
-      break;
-    }
-
-    if(tmp->next)
-      tmp = tmp->next;
-    else
-      break;
-  }
+       BUFFY* tmp = CurBuffy = Incoming;
+
+       if (!Incoming)
+               return;
+
+       while (1) {
+               if (!strcmp (tmp->path, buf) || !strcmp (tmp->realpath, buf)) {
+                       CurBuffy = tmp;
+                       break;
+               }
+
+               if (tmp->next)
+                       tmp = tmp->next;
+               else
+                       break;
+       }
 }
 
-void sidebar_updated()
+void
+sidebar_updated()
 {
-       SidebarLastRefresh = time(NULL);
+       SidebarLastRefresh = time (NULL);
 }
+
index 7371a14ea9b5f50a7d776c63d8731d6c7104332a..6aa7ed5a93a621462ab4cb24e78f1f41e4c3f115 100644 (file)
--- a/sidebar.h
+++ b/sidebar.h
@@ -1,21 +1,21 @@
 /*
  * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
  * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
- * 
+ *
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
  *     the Free Software Foundation; either version 2 of the License, or
  *     (at your option) any later version.
- * 
+ *
  *     This program is distributed in the hope that it will be useful,
  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *     GNU General Public License for more details.
- * 
+ *
  *     You should have received a copy of the GNU General Public License
  *     along with this program; if not, write to the Free Software
  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
- */ 
+ */
 
 #ifndef SIDEBAR_H
 #define SIDEBAR_H
@@ -28,9 +28,10 @@ struct MBOX_LIST {
 
 /* parameter is whether or not to go to the status line */
 /* used for omitting the last | that covers up the status bar in the index */
-int draw_sidebar(int);
-void scroll_sidebar(int, int);
-void set_buffystats(CONTEXT*);
+int draw_sidebar (int);
+void scroll_sidebar (int, int);
+void set_buffystats (CONTEXT*);
+void set_curbuffy (char*);
 int sidebar_should_refresh();
 void sidebar_updated();