From: Pierre Habouzit Date: Sun, 3 Dec 2006 12:13:18 +0000 (+0100) Subject: let m_strformat accept NULL formats. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=8a2967d883cee12f0de4c0cdf0cd594ea96e622b;p=apps%2Fmadmutt.git let m_strformat accept NULL formats. Signed-off-by: Pierre Habouzit --- diff --git a/alias.c b/alias.c index ff4a310..18fac2b 100644 --- a/alias.c +++ b/alias.c @@ -515,8 +515,7 @@ alias_format_str(char *dest, ssize_t destlen, char op, const char *src, static void alias_entry (char *s, ssize_t slen, MUTTMENU *m, int num) { - m_strformat(s, slen, NONULL (AliasFmt), alias_format_str, - ((alias_t **)m->data)[num], + m_strformat(s, slen, AliasFmt, alias_format_str, ((alias_t **)m->data)[num], option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0); } diff --git a/browser.c b/browser.c index f8fbb3d..b135b33 100644 --- a/browser.c +++ b/browser.c @@ -300,12 +300,12 @@ static const char *folder_format_str (char *dest, ssize_t destlen, char op, break; } - if (optional) - m_strformat (dest, destlen, ifstr, folder_format_str, data, 0); - else if (flags & M_FORMAT_OPTIONAL) - m_strformat (dest, destlen, elstr, folder_format_str, data, 0); - return (src); + if (flags & M_FORMAT_OPTIONAL) + m_strformat(dest, destlen, optional ? ifstr : elstr, folder_format_str, + data, 0); + + return src; } #ifdef USE_NNTP @@ -644,13 +644,11 @@ static void folder_entry (char *s, ssize_t slen, MUTTMENU * menu, int num) #ifdef USE_NNTP if (option (OPTNEWS)) - m_strformat(s, slen, NONULL (GroupFormat), newsgroup_format_str, - (void*)&folder, + m_strformat(s, slen, GroupFormat, newsgroup_format_str, &folder, option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0); else #endif - m_strformat(s, slen, NONULL (FolderFormat), folder_format_str, - (void *)&folder, + m_strformat(s, slen, FolderFormat, folder_format_str, &folder, option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0); } diff --git a/compose.c b/compose.c index 1b278f4..52907b6 100644 --- a/compose.c +++ b/compose.c @@ -113,10 +113,11 @@ static struct mapping_t ComposeNewsHelp[] = { static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) { - int w=(COLS-SW)>blen?blen:COLS-SW; - m_strformat (b, w, NONULL (AttachFormat), mutt_attach_fmt, - ((ATTACHPTR **)menu->data)[num], - M_FORMAT_STAT_FILE | (option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0)); + int w = MIN(COLS-SW, blen); + + m_strformat(b, w, AttachFormat, mutt_attach_fmt, + ((ATTACHPTR **)menu->data)[num], + M_FORMAT_STAT_FILE | (option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0)); } static void redraw_crypt_lines (HEADER * msg) @@ -460,8 +461,8 @@ static const char *compose_format_str (char *buf, ssize_t buflen, char op, static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu, const char *p) { - int w=(COLS-SW)>buflen?buflen:(COLS-SW); - m_strformat(buf, w, p, compose_format_str, menu, 0); + int w = MIN(COLS - SW, buflen); + m_strformat(buf, w, p, compose_format_str, menu, 0); } /* return values: diff --git a/lib-crypt/crypt-gpgme.c b/lib-crypt/crypt-gpgme.c index 1c6990b..906e56e 100644 --- a/lib-crypt/crypt-gpgme.c +++ b/lib-crypt/crypt-gpgme.c @@ -2308,11 +2308,10 @@ crypt_entry_fmt (char *dest, ssize_t destlen, char op, *dest = '\0'; } - if (optional) - m_strformat (dest, destlen, ifstr, mutt_attach_fmt, data, 0); - else if (flags & M_FORMAT_OPTIONAL) - m_strformat (dest, destlen, elstr, mutt_attach_fmt, data, 0); - return (src); + if (flags & M_FORMAT_OPTIONAL) + m_strformat(dest, destlen, optional ? ifstr: elstr, + mutt_attach_fmt, data, 0); + return src; } /* Used by the display fucntion to format a line. */ @@ -2324,8 +2323,7 @@ static void crypt_entry (char *s, ssize_t l, MUTTMENU * menu, int num) entry.key = key_table[num]; entry.num = num + 1; - m_strformat(s, l, NONULL (PgpEntryFormat), crypt_entry_fmt, - (void*)&entry, + m_strformat(s, l, PgpEntryFormat, crypt_entry_fmt, &entry, option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0); } diff --git a/lib-crypt/pgpinvoke.c b/lib-crypt/pgpinvoke.c index 8feba18..6a6dd02 100644 --- a/lib-crypt/pgpinvoke.c +++ b/lib-crypt/pgpinvoke.c @@ -107,19 +107,18 @@ _mutt_fmt_pgp_command(char *dest, ssize_t destlen, } } - if (optional) - m_strformat(dest, destlen, ifstr, _mutt_fmt_pgp_command, data, 0); - else if (flags & M_FORMAT_OPTIONAL) - m_strformat(dest, destlen, elstr, _mutt_fmt_pgp_command, data, 0); + if (flags & M_FORMAT_OPTIONAL) + m_strformat(dest, destlen, optional ? ifstr : elstr, + _mutt_fmt_pgp_command, data, 0); - return (src); + return src; } static void mutt_pgp_command(char *d, ssize_t dlen, struct pgp_command_context *cctx, const char *fmt) { - m_strformat(d, dlen, NONULL (fmt), _mutt_fmt_pgp_command, cctx, 0); + m_strformat(d, dlen, fmt, _mutt_fmt_pgp_command, cctx, 0); } /* diff --git a/lib-crypt/pgpkey.c b/lib-crypt/pgpkey.c index b1ded7c..87dee7d 100644 --- a/lib-crypt/pgpkey.c +++ b/lib-crypt/pgpkey.c @@ -235,11 +235,10 @@ pgp_entry_fmt (char *dest, ssize_t destlen, char op, *dest = '\0'; } - if (optional) - m_strformat (dest, destlen, ifstr, mutt_attach_fmt, data, 0); - else if (flags & M_FORMAT_OPTIONAL) - m_strformat (dest, destlen, elstr, mutt_attach_fmt, data, 0); - return (src); + if (flags & M_FORMAT_OPTIONAL) + m_strformat(dest, destlen, optional ? ifstr : elstr, + mutt_attach_fmt, data, 0); + return src; } static void pgp_entry (char *s, ssize_t l, MUTTMENU * menu, int num) @@ -250,8 +249,7 @@ static void pgp_entry (char *s, ssize_t l, MUTTMENU * menu, int num) entry.uid = KeyTable[num]; entry.num = num + 1; - m_strformat(s, l, NONULL (PgpEntryFormat), pgp_entry_fmt, - (void*)&entry, + m_strformat(s, l, PgpEntryFormat, pgp_entry_fmt, &entry, option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0); } diff --git a/lib-crypt/smime.c b/lib-crypt/smime.c index 0178d60..33c53b0 100644 --- a/lib-crypt/smime.c +++ b/lib-crypt/smime.c @@ -218,12 +218,11 @@ _mutt_fmt_smime_command (char *dest, ssize_t destlen, char op, break; } - if (optional) - m_strformat(dest, destlen, ifstr, _mutt_fmt_smime_command, data, 0); - else if (flags & M_FORMAT_OPTIONAL) - m_strformat(dest, destlen, elstr, _mutt_fmt_smime_command, data, 0); + if (flags & M_FORMAT_OPTIONAL) + m_strformat(dest, destlen, optional ? ifstr : elstr, + _mutt_fmt_smime_command, data, 0); - return (src); + return src; } @@ -232,7 +231,7 @@ static void mutt_smime_command (char *d, ssize_t dlen, struct smime_command_context *cctx, const char *fmt) { - m_strformat(d, dlen, NONULL (fmt), _mutt_fmt_smime_command, cctx, 0); + m_strformat(d, dlen, fmt, _mutt_fmt_smime_command, cctx, 0); } static pid_t smime_invoke (FILE ** smimein, FILE ** smimeout, diff --git a/lib-mx/compress.c b/lib-mx/compress.c index b9b237c..c92853b 100644 --- a/lib-mx/compress.c +++ b/lib-mx/compress.c @@ -167,13 +167,11 @@ int mutt_test_compress_command (const char *cmd) return (strstr (cmd, "%f") && strstr (cmd, "%t")) ? 0 : -1; } -static char *get_compression_cmd (const char *cmd, const CONTEXT * ctx) +static char *get_compression_cmd(const char *cmd, const CONTEXT * ctx) { - char expanded[_POSIX_PATH_MAX]; - - m_strformat(expanded, sizeof (expanded), cmd, compresshook_format_str, - (void *)ctx, 0); - return m_strdup(expanded); + char buf[_POSIX_PATH_MAX]; + m_strformat(buf, sizeof(buf), cmd, compresshook_format_str, ctx, 0); + return m_strdup(buf); } int mutt_check_mailbox_compressed (CONTEXT * ctx) diff --git a/lib-ui/hdrline.c b/lib-ui/hdrline.c index cb5a5f4..879a67f 100644 --- a/lib-ui/hdrline.c +++ b/lib-ui/hdrline.c @@ -706,12 +706,11 @@ static const char *hdr_format_str (char *dest, break; } - if (optional) - m_strformat(dest, destlen, ifstr, hdr_format_str, data, flags); - else if (flags & M_FORMAT_OPTIONAL) - m_strformat(dest, destlen, elstr, hdr_format_str, data, flags); + if (flags & M_FORMAT_OPTIONAL) + m_strformat(dest, destlen, optional ? ifstr: elstr, + hdr_format_str, data, flags); - return (src); + return src; #undef THREAD_NEW #undef THREAD_OLD } diff --git a/lib-ui/sidebar.c b/lib-ui/sidebar.c index 9dcfce8..7ae1c32 100644 --- a/lib-ui/sidebar.c +++ b/lib-ui/sidebar.c @@ -197,8 +197,7 @@ static int make_sidebar_entry (char* sbox, int idx, ssize_t len) * (i.e. always display the currently opened) */ return 0; - m_strformat(no, len, NONULL(SidebarNumberFormat), sidebar_number_format, - idx, 0); + m_strformat(no, len, SidebarNumberFormat, sidebar_number_format, idx, 0); lencnt = m_strlen(no); if (l > 0 && m_strncmp(sbox, ImapHomeNamespace, l) == 0 && diff --git a/lib-ui/status.c b/lib-ui/status.c index e3dd6e1..3462ffa 100644 --- a/lib-ui/status.c +++ b/lib-ui/status.c @@ -288,11 +288,10 @@ static const char *status_format_str (char *buf, ssize_t buflen, char op, } void menu_status_line (char* buf, ssize_t len, MUTTMENU* menu, const char* p) { - /* - * if we have enough space for buffer, format lines to $COLS-$SidebarWidth - * only to not wrap past end of screen - */ - int width = COLS - SW; - m_strformat(buf, (width >= len ? len : (width + 1)), p, status_format_str, - menu, 0); + /* + * if we have enough space for buffer, format lines to $COLS-$SidebarWidth + * only to not wrap past end of screen + */ + int width = MIN(COLS - SW + 1, len); + m_strformat(buf, width, p, status_format_str, menu, 0); } diff --git a/muttlib.c b/muttlib.c index c0cde0c..f63ad45 100644 --- a/muttlib.c +++ b/muttlib.c @@ -333,8 +333,9 @@ 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'; + m_strpad(dst, dlen, '\0', pos + 1); + if (!fmt) + return; while (*fmt) { int ch; diff --git a/nntp/newsrc.c b/nntp/newsrc.c index d80b21d..306bf68 100644 --- a/nntp/newsrc.c +++ b/nntp/newsrc.c @@ -346,8 +346,8 @@ NNTP_SERVER *mutt_select_newsserver (char *server) if (!conn) return NULL; - m_strformat(file, sizeof(file), NONULL(NewsRc), nntp_format_str, NULL, 0); - mutt_expand_path (file, sizeof (file)); + m_strformat(file, sizeof(file), NewsRc, nntp_format_str, NULL, 0); + mutt_expand_path(file, sizeof(file)); serv = (NNTP_SERVER *) conn->data; if (serv) { diff --git a/recvattach.c b/recvattach.c index 8d94955..1c21de7 100644 --- a/recvattach.c +++ b/recvattach.c @@ -311,19 +311,19 @@ const char *mutt_attach_fmt (char *dest, ssize_t destlen, *dest = 0; } - if (optional) - m_strformat (dest, destlen, ifstr, mutt_attach_fmt, data, 0); - else if (flags & M_FORMAT_OPTIONAL) - m_strformat (dest, destlen, elstr, mutt_attach_fmt, data, 0); - return (src); + if (flags & M_FORMAT_OPTIONAL) + m_strformat(dest, destlen, optional ? ifstr : elstr, + mutt_attach_fmt, data, 0); + return src; } -static void attach_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) +static void attach_entry(char *b, ssize_t blen, MUTTMENU * menu, int num) { - int w=(COLS-SW)>blen?blen:(COLS-SW); - m_strformat (b, w, NONULL (AttachFormat), mutt_attach_fmt, - ((ATTACHPTR **) menu->data)[num], - option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0); + int w = MIN(COLS - SW, blen); + + m_strformat(b, w, AttachFormat, mutt_attach_fmt, + ((ATTACHPTR **) menu->data)[num], + option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0); } int mutt_tag_attach (MUTTMENU * menu, int n, int m) diff --git a/remailer.c b/remailer.c index 4722c1a..a261f1b 100644 --- a/remailer.c +++ b/remailer.c @@ -383,10 +383,9 @@ mix_entry_fmt (char *dest, ssize_t destlen, char op, const char *src, *dest = '\0'; } - if (optional) - m_strformat (dest, destlen, ifstr, mutt_attach_fmt, data, 0); - else if (flags & M_FORMAT_OPTIONAL) - m_strformat (dest, destlen, elstr, mutt_attach_fmt, data, 0); + if (flags & M_FORMAT_OPTIONAL) + m_strformat (dest, destlen, optional ? ifstr : elstr, + mutt_attach_fmt, data, 0); return (src); } @@ -395,10 +394,9 @@ mix_entry_fmt (char *dest, ssize_t destlen, char op, const char *src, static void mix_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) { remailer_t **type2_list = (remailer_t **) menu->data; - int w = (COLS-SW) > blen ? blen : (COLS-SW); - m_strformat(b, w, NONULL (MixEntryFormat), mix_entry_fmt, - type2_list[num], + int w = MIN(COLS - SW, blen); + m_strformat(b, w, MixEntryFormat, mix_entry_fmt, type2_list[num], option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0); } diff --git a/sendlib.c b/sendlib.c index 2c9b534..3bf9c91 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1840,7 +1840,7 @@ static int mutt_invoke_sendmail (address_t * from, /* the sender */ if (option (OPTNEWSSEND)) { char cmd[LONG_STRING]; - m_strformat(cmd, sizeof (cmd), NONULL (Inews), nntp_format_str, 0, 0); + m_strformat(cmd, sizeof(cmd), Inews, nntp_format_str, 0, 0); if (m_strisempty(cmd)) { i = nntp_post (msg); unlink (msg);