From: Julien Danjou Date: Fri, 17 Nov 2006 17:17:10 +0000 (+0100) Subject: Simplify sidebar code X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=98cf5779d8184a74541be1bc61d15c5f35efd310;hp=bd5c6e968ae1f29f5819d1e39ec104cc632ad545 Simplify sidebar code - Remove useless argument from sidebar_*() functions - Include some missing header files and declares some functions as static - Rename some var :-/ - Remove a useless argument 'fd' for USE_DOTLOCK Signed-off-by: Julien Danjou Signed-off-by: Pierre Habouzit --- diff --git a/browser.c b/browser.c index 09b85d1..ae9c540 100644 --- a/browser.c +++ b/browser.c @@ -476,7 +476,7 @@ static int examine_directory (MUTTMENU * menu, struct browser_state *state, add_folder (menu, state, data->group, NULL, data->new); #endif } - sidebar_draw (CurrentMenu); + sidebar_draw (); } else #endif /* USE_NNTP */ @@ -542,7 +542,7 @@ static int examine_directory (MUTTMENU * menu, struct browser_state *state, } closedir (dp); } - sidebar_draw (CurrentMenu); + sidebar_draw (); browser_sort (state); return 0; } @@ -570,7 +570,7 @@ static int examine_mailboxes (MUTTMENU * menu, struct browser_state *state) (!option (OPTSHOWONLYUNREAD)|| data->unread)))) add_folder (menu, state, data->group, NULL, data, data->new); } - sidebar_draw (CurrentMenu); + sidebar_draw (); } else #endif diff --git a/buffy.c b/buffy.c index dfadbe8..4018c5f 100644 --- a/buffy.c +++ b/buffy.c @@ -466,7 +466,7 @@ int buffy_check (int force) tmp->has_new = tmp->new > 0; } if (BuffyCount > 0 && force != 2) - sidebar_draw (CurrentMenu); + sidebar_draw (); return (BuffyCount); } @@ -512,7 +512,7 @@ int buffy_list (void) } if (!first) { /* on new mail: redraw sidebar */ - sidebar_draw (CurrentMenu); + sidebar_draw (); mutt_message ("%s", buffylist); return (1); } diff --git a/flags.c b/flags.c index e00dc88..4fe7ce3 100644 --- a/flags.c +++ b/flags.c @@ -266,7 +266,7 @@ void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx) if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged)) h->searched = 0; - sidebar_draw (0); + sidebar_draw (); } void mutt_tag_set_flag (int flag, int bf) diff --git a/lib-ui/complete.c b/lib-ui/complete.c index bb0976c..ded2862 100644 --- a/lib-ui/complete.c +++ b/lib-ui/complete.c @@ -11,6 +11,7 @@ #include "mutt.h" #include "mx.h" +#include "curses.h" #include #ifdef USE_NNTP #include diff --git a/lib-ui/curs_main.c b/lib-ui/curs_main.c index bc868e3..e23764e 100644 --- a/lib-ui/curs_main.c +++ b/lib-ui/curs_main.c @@ -476,7 +476,7 @@ int mutt_index_menu (void) ("Mailbox was externally modified. Flags may be wrong.")); else if (check == M_NEW_MAIL) { /* on new mail: redraw sidebar */ - sidebar_draw (CurrentMenu); + sidebar_draw (); mutt_message (_("New mail in this mailbox.")); if (option (OPTBEEPNEW)) @@ -516,10 +516,10 @@ int mutt_index_menu (void) if (op != -1) mutt_curs_set (0); if (menu->redraw & REDRAW_SIDEBAR) - sidebar_draw (menu->menu); + sidebar_draw (); if (menu->redraw & REDRAW_FULL) { menu_redraw_full (menu); - sidebar_draw (menu->menu); + sidebar_draw (); mutt_show_error (); } @@ -2308,7 +2308,7 @@ int mutt_index_menu (void) case OP_SIDEBAR_PREV: case OP_SIDEBAR_NEXT_NEW: case OP_SIDEBAR_PREV_NEW: - sidebar_scroll (op, menu->menu); + sidebar_scroll (op); break; default: if (menu->menu == MENU_MAIN) diff --git a/lib-ui/enter.c b/lib-ui/enter.c index 7623212..d42c855 100644 --- a/lib-ui/enter.c +++ b/lib-ui/enter.c @@ -115,7 +115,7 @@ static void my_wcstombs (char *dest, ssize_t dlen, const wchar_t * src, } } -size_t my_mbstowcs (wchar_t ** pwbuf, size_t * pwbuflen, size_t i, const char *buf) +static size_t my_mbstowcs (wchar_t ** pwbuf, size_t * pwbuflen, size_t i, const char *buf) { wchar_t wc; mbstate_t st; diff --git a/lib-ui/hdrline.c b/lib-ui/hdrline.c index 25ccce1..1b3f10a 100644 --- a/lib-ui/hdrline.c +++ b/lib-ui/hdrline.c @@ -20,6 +20,7 @@ #include "charset.h" #include #include "mutt_idna.h" +#include "mx.h" int mutt_is_mail_list (address_t * addr) { diff --git a/lib-ui/menu.c b/lib-ui/menu.c index a99646f..aa1501a 100644 --- a/lib-ui/menu.c +++ b/lib-ui/menu.c @@ -136,7 +136,7 @@ static void menu_make_entry (char *s, int l, MUTTMENU * menu, int i) menu->make_entry (s, l, menu, i); } -void menu_pad_string (char *s, size_t n) +static void menu_pad_string (char *s, size_t n) { int shift = option (OPTARROWCURSOR) ? 3 : 0; int cols; @@ -244,8 +244,7 @@ void menu_redraw_index (MUTTMENU * menu) else CLEARLINE_WIN (i - menu->top + menu->offset); } - sidebar_draw (1); -/* sidebar_draw_frames(); */ + sidebar_draw (); menu->redraw = 0; } @@ -346,7 +345,7 @@ void menu_redraw_current (MUTTMENU * menu) menu->redraw &= REDRAW_STATUS; } -void menu_redraw_prompt (MUTTMENU * menu) +static void menu_redraw_prompt (MUTTMENU * menu) { if (menu->dialog) { if (option (OPTMSGERR)) { @@ -459,7 +458,7 @@ void menu_prev_line (MUTTMENU * menu) * halfdown: jumplen == pagelen/2 */ #define DIRECTION ((neg * 2) + 1) -void menu_length_jump (MUTTMENU *menu, int jumplen) { +static void menu_length_jump (MUTTMENU *menu, int jumplen) { int tmp, neg = (jumplen >= 0) ? 0 : -1; int c = MIN (MenuContext, menu->pagelen / 2); @@ -597,7 +596,7 @@ void menu_current_bottom (MUTTMENU * menu) mutt_error _("No entries."); } -void menu_next_entry (MUTTMENU * menu) +static void menu_next_entry (MUTTMENU * menu) { if (menu->current < menu->max - 1) { menu->current++; @@ -607,7 +606,7 @@ void menu_next_entry (MUTTMENU * menu) mutt_error _("You are on the last entry."); } -void menu_prev_entry (MUTTMENU * menu) +static void menu_prev_entry (MUTTMENU * menu) { if (menu->current) { menu->current--; diff --git a/lib-ui/sidebar.c b/lib-ui/sidebar.c index 464a5c4..a83505c 100644 --- a/lib-ui/sidebar.c +++ b/lib-ui/sidebar.c @@ -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 (); } diff --git a/lib-ui/sidebar.h b/lib-ui/sidebar.h index 239366a..ffc53e2 100644 --- a/lib-ui/sidebar.h +++ b/lib-ui/sidebar.h @@ -13,9 +13,9 @@ #include "mutt.h" /* because of CONTEXT :| */ -int sidebar_draw (int); +int sidebar_draw (void); void sidebar_draw_frames (void); -void sidebar_scroll (int, int); +void sidebar_scroll (int); void sidebar_set_buffystats (CONTEXT *); const char* sidebar_get_current (void); void sidebar_set_current (const char*); diff --git a/mx.c b/mx.c index 1d5a750..fde597c 100644 --- a/mx.c +++ b/mx.c @@ -58,7 +58,7 @@ static list2_t* MailboxFormats = NULL; * retry - should retry if unable to lock? */ -static int invoke_dotlock (const char *path, int dummy, int flags, int retry) +static int invoke_dotlock (const char *path, int flags, int retry) { char cmd[LONG_STRING + _POSIX_PATH_MAX]; char f[SHORT_STRING + _POSIX_PATH_MAX]; @@ -82,7 +82,7 @@ static int invoke_dotlock (const char *path, int dummy, int flags, int retry) return mutt_system (cmd); } -static int dotlock_file (const char *path, int fd, int retry) +static int dotlock_file (const char *path, int retry) { int r; int flags = DL_FL_USEPRIV | DL_FL_RETRY; @@ -91,7 +91,7 @@ static int dotlock_file (const char *path, int fd, int retry) retry = 1; retry_lock: - if ((r = invoke_dotlock (path, fd, flags, retry)) == DL_EX_EXIST) { + if ((r = invoke_dotlock (path, flags, retry)) == DL_EX_EXIST) { if (!option (OPTNOCURSES)) { char msg[LONG_STRING]; @@ -111,9 +111,9 @@ retry_lock: return (r == DL_EX_OK ? 0 : -1); } -static int undotlock_file (const char *path, int fd) +static int undotlock_file (const char *path) { - return (invoke_dotlock (path, fd, DL_FL_USEPRIV | DL_FL_UNLOCK, 0) == + return (invoke_dotlock (path, DL_FL_USEPRIV | DL_FL_UNLOCK, 0) == DL_EX_OK ? 0 : -1); } @@ -236,7 +236,7 @@ int mx_lock_file (const char *path, int fd, int excl, int dot, int time_out) #ifdef USE_DOTLOCK if (r == 0 && dot) - r = dotlock_file (path, fd, time_out); + r = dotlock_file (path, time_out); #endif /* USE_DOTLOCK */ if (r == -1) { @@ -274,13 +274,13 @@ int mx_unlock_file (const char *path, int fd, int dot) #ifdef USE_DOTLOCK if (dot) - undotlock_file (path, fd); + undotlock_file (path); #endif return 0; } -void mx_unlink_empty (const char *path) +static void mx_unlink_empty (const char *path) { int fd; @@ -297,7 +297,7 @@ void mx_unlink_empty (const char *path) } #ifdef USE_DOTLOCK - invoke_dotlock (path, fd, DL_FL_UNLINK, 1); + invoke_dotlock (path, DL_FL_UNLINK, 1); #else if (fstat (fd, &sb) == 0 && sb.st_size == 0) unlink (path); @@ -1368,7 +1368,7 @@ int mx_rebuild_cache (void) { if (magic != M_MAILDIR && magic != M_MH && magic != M_IMAP) continue; sidebar_set_current (b->path); - sidebar_draw (CurrentMenu); + sidebar_draw (); if ((ctx = mx_open_mailbox (b->path, M_READONLY | M_NOSORT | M_COUNT, NULL)) != NULL) @@ -1378,7 +1378,7 @@ int mx_rebuild_cache (void) { if (Context && Context->path) sidebar_set_current (Context->path); - sidebar_draw (CurrentMenu); + sidebar_draw (); return (0); #endif diff --git a/nntp/nntp.c b/nntp/nntp.c index 4f3c812..a5deac1 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -1286,7 +1286,7 @@ int nntp_check_newgroups (NNTP_SERVER * serv, int force) if (l->data && ((NNTP_DATA *) l->data)->subscribed) _nntp_check_mailbox (NULL, (NNTP_DATA *) l->data); } - sidebar_draw (CurrentMenu); + sidebar_draw (); } else if (!force) return 0; diff --git a/pager.c b/pager.c index cbdc8fa..b83eaaf 100644 --- a/pager.c +++ b/pager.c @@ -1641,13 +1641,13 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra) } if (redraw & REDRAW_SIDEBAR) - sidebar_draw (MENU_PAGER); + sidebar_draw (); if ((redraw & REDRAW_INDEX) && pager_index) { /* redraw the pager_index indicator, because the * flags for this message might have changed. */ menu_redraw_current (pager_index); - sidebar_draw (MENU_PAGER); + sidebar_draw (); /* print out the pager_index status bar */ menu_status_line (buffer, sizeof (buffer), pager_index, NONULL (Status)); move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), SW); @@ -1659,7 +1659,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra) } /* if we're not using the index, update every time */ if (index == 0) - sidebar_draw (MENU_PAGER); + sidebar_draw (); redraw = 0; @@ -2553,7 +2553,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra) case OP_SIDEBAR_NEXT_NEW: case OP_SIDEBAR_PREV: case OP_SIDEBAR_PREV_NEW: - sidebar_scroll (ch, MENU_PAGER); + sidebar_scroll (ch); break; default: ch = -1;