From: Pierre Habouzit Date: Sat, 2 Dec 2006 22:02:41 +0000 (+0100) Subject: fixes in the sidebar format, was completely braindead. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=27c3007f2cfb52db5a357eaa2a8313a5ab03c93d;p=apps%2Fmadmutt.git fixes in the sidebar format, was completely braindead. Signed-off-by: Pierre Habouzit --- diff --git a/lib-ui/sidebar.c b/lib-ui/sidebar.c index 48e4360..e55537f 100644 --- a/lib-ui/sidebar.c +++ b/lib-ui/sidebar.c @@ -162,13 +162,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, opt ? ifstr : elstr, sidebar_number_format, + data, flags); + return src; } int sidebar_need_count (void) { @@ -198,12 +195,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, NONULL(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) @@ -218,21 +214,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 diff --git a/muttlib.c b/muttlib.c index 9c108b7..876c69c 100644 --- a/muttlib.c +++ b/muttlib.c @@ -333,11 +333,17 @@ ssize_t m_strformat(char *dst, ssize_t dlen, const char *fmt, { ssize_t pos = flags & M_FORMAT_ARROWCURSOR ? 3 : 0; + if (dlen >= 0) + *dst = '\0'; + while (*fmt) { - char ifstring[STRING], elsestring[STRING], prefix[STRING] = ""; int ch; if (*fmt == '%') { + char ifstring[STRING], elsestring[STRING], prefix[STRING]; + + *ifstring = *elsestring = *prefix = '\0'; + if (*++fmt == '%') { pos += m_strputc(dst + pos, dlen - pos, *fmt++); continue; @@ -382,8 +388,6 @@ ssize_t m_strformat(char *dst, ssize_t dlen, const char *fmt, if (!*fmt++) /* move past the trailing `?' */ break; /* bad format */ - } else { - *ifstring = *elsestring = '\0'; } switch (ch) {