From 1eeaaac6bdcad962c41bf975a32078cc4a0e578c Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sat, 2 Dec 2006 21:04:02 +0100 Subject: [PATCH] mutt_FormatString -> m_strformat (will soon end up into the str lib \o/) some tiny reworks, stylish issues. Signed-off-by: Pierre Habouzit --- alias.c | 2 +- browser.c | 12 ++++++------ compose.c | 4 ++-- lib-crypt/crypt-gpgme.c | 6 +++--- lib-crypt/pgpinvoke.c | 6 +++--- lib-crypt/pgpkey.c | 6 +++--- lib-crypt/smime.c | 6 +++--- lib-mx/compress.c | 2 +- lib-ui/hdrline.c | 6 +++--- lib-ui/sidebar.c | 6 +++--- lib-ui/status.c | 2 +- mutt.h | 2 +- muttlib.c | 29 +++++++++++++---------------- nntp/newsrc.c | 2 +- protos.h | 2 +- recvattach.c | 6 +++--- remailer.c | 6 +++--- sendlib.c | 2 +- 18 files changed, 52 insertions(+), 55 deletions(-) diff --git a/alias.c b/alias.c index 84eda4d..201cb0e 100644 --- a/alias.c +++ b/alias.c @@ -515,7 +515,7 @@ static const format_t *alias_format_str (char *dest, size_t destlen, char op, static void alias_entry (char *s, ssize_t slen, MUTTMENU * m, int num) { - mutt_FormatString (s, slen, NONULL (AliasFmt), (format_t *)alias_format_str, + m_strformat (s, slen, NONULL (AliasFmt), (format_t *)alias_format_str, (unsigned long)((alias_t **)m->data)[num], M_FORMAT_ARROWCURSOR); } diff --git a/browser.c b/browser.c index fd92753..47c4b3f 100644 --- a/browser.c +++ b/browser.c @@ -301,9 +301,9 @@ static const char *folder_format_str (char *dest, ssize_t destlen, char op, } if (optional) - mutt_FormatString (dest, destlen, ifstring, folder_format_str, data, 0); + m_strformat (dest, destlen, ifstring, folder_format_str, data, 0); else if (flags & M_FORMAT_OPTIONAL) - mutt_FormatString (dest, destlen, elsestring, folder_format_str, data, 0); + m_strformat (dest, destlen, elsestring, folder_format_str, data, 0); return (src); } @@ -350,10 +350,10 @@ static const char *newsgroup_format_str (char *dest, ssize_t destlen, char op, case 's': if (flags & M_FORMAT_OPTIONAL) { if (folder->ff->nd->unread != 0) - mutt_FormatString (dest, destlen, ifstring, newsgroup_format_str, + m_strformat (dest, destlen, ifstring, newsgroup_format_str, data, flags); else - mutt_FormatString (dest, destlen, elsestring, newsgroup_format_str, + m_strformat (dest, destlen, elsestring, newsgroup_format_str, data, flags); } else if (Context && Context->data == folder->ff->nd) { @@ -645,11 +645,11 @@ static void folder_entry (char *s, ssize_t slen, MUTTMENU * menu, int num) #ifdef USE_NNTP if (option (OPTNEWS)) - mutt_FormatString (s, slen, NONULL (GroupFormat), newsgroup_format_str, + m_strformat (s, slen, NONULL (GroupFormat), newsgroup_format_str, (unsigned long) &folder, M_FORMAT_ARROWCURSOR); else #endif - mutt_FormatString (s, slen, NONULL (FolderFormat), folder_format_str, + m_strformat (s, slen, NONULL (FolderFormat), folder_format_str, (unsigned long) &folder, M_FORMAT_ARROWCURSOR); } diff --git a/compose.c b/compose.c index ec7ac1b..860d643 100644 --- a/compose.c +++ b/compose.c @@ -114,7 +114,7 @@ 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; - mutt_FormatString (b, w, NONULL (AttachFormat), mutt_attach_fmt, + m_strformat (b, w, NONULL (AttachFormat), mutt_attach_fmt, (unsigned long) (((ATTACHPTR **) menu->data)[num]), M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR); } @@ -461,7 +461,7 @@ static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu, const char *p) { int w=(COLS-SW)>buflen?buflen:(COLS-SW); - mutt_FormatString (buf, w, p, compose_format_str, + m_strformat (buf, w, p, compose_format_str, (unsigned long) menu, 0); } diff --git a/lib-crypt/crypt-gpgme.c b/lib-crypt/crypt-gpgme.c index e295042..700f9d3 100644 --- a/lib-crypt/crypt-gpgme.c +++ b/lib-crypt/crypt-gpgme.c @@ -2309,9 +2309,9 @@ crypt_entry_fmt (char *dest, ssize_t destlen, char op, } if (optional) - mutt_FormatString (dest, destlen, ifstring, mutt_attach_fmt, data, 0); + m_strformat (dest, destlen, ifstring, mutt_attach_fmt, data, 0); else if (flags & M_FORMAT_OPTIONAL) - mutt_FormatString (dest, destlen, elsestring, mutt_attach_fmt, data, 0); + m_strformat (dest, destlen, elsestring, mutt_attach_fmt, data, 0); return (src); } @@ -2324,7 +2324,7 @@ static void crypt_entry (char *s, ssize_t l, MUTTMENU * menu, int num) entry.key = key_table[num]; entry.num = num + 1; - mutt_FormatString (s, l, NONULL (PgpEntryFormat), crypt_entry_fmt, + m_strformat (s, l, NONULL (PgpEntryFormat), crypt_entry_fmt, (unsigned long) &entry, M_FORMAT_ARROWCURSOR); } diff --git a/lib-crypt/pgpinvoke.c b/lib-crypt/pgpinvoke.c index 10878d3..312f59e 100644 --- a/lib-crypt/pgpinvoke.c +++ b/lib-crypt/pgpinvoke.c @@ -108,10 +108,10 @@ _mutt_fmt_pgp_command(char *dest, ssize_t destlen, } if (optional) - mutt_FormatString (dest, destlen, ifstring, _mutt_fmt_pgp_command, data, + m_strformat (dest, destlen, ifstring, _mutt_fmt_pgp_command, data, 0); else if (flags & M_FORMAT_OPTIONAL) - mutt_FormatString (dest, destlen, elsestring, _mutt_fmt_pgp_command, data, + m_strformat (dest, destlen, elsestring, _mutt_fmt_pgp_command, data, 0); return (src); @@ -121,7 +121,7 @@ static void mutt_pgp_command(char *d, ssize_t dlen, struct pgp_command_context *cctx, const char *fmt) { - mutt_FormatString (d, dlen, NONULL (fmt), _mutt_fmt_pgp_command, + m_strformat (d, dlen, NONULL (fmt), _mutt_fmt_pgp_command, (unsigned long) cctx, 0); } diff --git a/lib-crypt/pgpkey.c b/lib-crypt/pgpkey.c index e5d1796..c0a06f2 100644 --- a/lib-crypt/pgpkey.c +++ b/lib-crypt/pgpkey.c @@ -236,9 +236,9 @@ pgp_entry_fmt (char *dest, ssize_t destlen, char op, } if (optional) - mutt_FormatString (dest, destlen, ifstring, mutt_attach_fmt, data, 0); + m_strformat (dest, destlen, ifstring, mutt_attach_fmt, data, 0); else if (flags & M_FORMAT_OPTIONAL) - mutt_FormatString (dest, destlen, elsestring, mutt_attach_fmt, data, 0); + m_strformat (dest, destlen, elsestring, mutt_attach_fmt, data, 0); return (src); } @@ -250,7 +250,7 @@ static void pgp_entry (char *s, ssize_t l, MUTTMENU * menu, int num) entry.uid = KeyTable[num]; entry.num = num + 1; - mutt_FormatString (s, l, NONULL (PgpEntryFormat), pgp_entry_fmt, + m_strformat (s, l, NONULL (PgpEntryFormat), pgp_entry_fmt, (unsigned long) &entry, M_FORMAT_ARROWCURSOR); } diff --git a/lib-crypt/smime.c b/lib-crypt/smime.c index 4a4f89c..555c8e9 100644 --- a/lib-crypt/smime.c +++ b/lib-crypt/smime.c @@ -219,10 +219,10 @@ _mutt_fmt_smime_command (char *dest, ssize_t destlen, char op, } if (optional) - mutt_FormatString (dest, destlen, ifstring, _mutt_fmt_smime_command, + m_strformat (dest, destlen, ifstring, _mutt_fmt_smime_command, data, 0); else if (flags & M_FORMAT_OPTIONAL) - mutt_FormatString (dest, destlen, elsestring, _mutt_fmt_smime_command, + m_strformat (dest, destlen, elsestring, _mutt_fmt_smime_command, data, 0); return (src); @@ -234,7 +234,7 @@ static void mutt_smime_command (char *d, ssize_t dlen, struct smime_command_context *cctx, const char *fmt) { - mutt_FormatString (d, dlen, NONULL (fmt), _mutt_fmt_smime_command, + m_strformat (d, dlen, NONULL (fmt), _mutt_fmt_smime_command, (unsigned long) cctx, 0); } diff --git a/lib-mx/compress.c b/lib-mx/compress.c index 52978ac..37090fb 100644 --- a/lib-mx/compress.c +++ b/lib-mx/compress.c @@ -171,7 +171,7 @@ static char *get_compression_cmd (const char *cmd, const CONTEXT * ctx) { char expanded[_POSIX_PATH_MAX]; - mutt_FormatString (expanded, sizeof (expanded), cmd, + m_strformat (expanded, sizeof (expanded), cmd, compresshook_format_str, (unsigned long) ctx, 0); return m_strdup(expanded); } diff --git a/lib-ui/hdrline.c b/lib-ui/hdrline.c index 09e77da..6a4f7ea 100644 --- a/lib-ui/hdrline.c +++ b/lib-ui/hdrline.c @@ -707,10 +707,10 @@ static const char *hdr_format_str (char *dest, } if (optional) - mutt_FormatString (dest, destlen, ifstring, hdr_format_str, + m_strformat (dest, destlen, ifstring, hdr_format_str, (unsigned long) hfi, flags); else if (flags & M_FORMAT_OPTIONAL) - mutt_FormatString (dest, destlen, elsestring, hdr_format_str, + m_strformat (dest, destlen, elsestring, hdr_format_str, (unsigned long) hfi, flags); return (src); @@ -727,6 +727,6 @@ _mutt_make_string (char *dest, ssize_t destlen, const char *s, CONTEXT * ctx, hfi.hdr = hdr; hfi.ctx = ctx; - mutt_FormatString (dest, destlen, s, hdr_format_str, (unsigned long) &hfi, + m_strformat (dest, destlen, s, hdr_format_str, (unsigned long) &hfi, flags); } diff --git a/lib-ui/sidebar.c b/lib-ui/sidebar.c index 3a17817..48e4360 100644 --- a/lib-ui/sidebar.c +++ b/lib-ui/sidebar.c @@ -163,10 +163,10 @@ static const char* sidebar_number_format (char* dest, ssize_t destlen, char op, } if (opt) - mutt_FormatString (dest, destlen, ifstr, sidebar_number_format, + m_strformat (dest, destlen, ifstr, sidebar_number_format, data, M_FORMAT_OPTIONAL); else if (flags & M_FORMAT_OPTIONAL) - mutt_FormatString (dest, destlen, elstr, sidebar_number_format, + m_strformat (dest, destlen, elstr, sidebar_number_format, data, M_FORMAT_OPTIONAL); return (src); } @@ -200,7 +200,7 @@ static int make_sidebar_entry (char* sbox, int idx, ssize_t len) * (i.e. always display the currently opened) */ return (0); - mutt_FormatString (no, len, NONULL (SidebarNumberFormat), + m_strformat (no, len, NONULL (SidebarNumberFormat), sidebar_number_format, idx, M_FORMAT_OPTIONAL); lencnt = m_strlen(no); memset(&entry, ' ', sizeof(entry)); diff --git a/lib-ui/status.c b/lib-ui/status.c index b2b3835..3da31d9 100644 --- a/lib-ui/status.c +++ b/lib-ui/status.c @@ -293,7 +293,7 @@ void menu_status_line (char* buf, ssize_t len, MUTTMENU* menu, const char* p) { * only to not wrap past end of screen */ int width = COLS - SW; - mutt_FormatString (buf, (width >= len ? len : (width + 1)), + m_strformat (buf, (width >= len ? len : (width + 1)), p, status_format_str, (unsigned long) menu, 0); } diff --git a/mutt.h b/mutt.h index 15af96a..ae133c9 100644 --- a/mutt.h +++ b/mutt.h @@ -30,7 +30,7 @@ typedef struct { int op; /* function op */ } event_t; -/* flags for mutt_FormatString() */ +/* flags for m_strformat() */ typedef enum { M_FORMAT_FORCESUBJ = (1 << 0), /* print the subject even if unchanged */ M_FORMAT_TREE = (1 << 1), /* draw the thread tree */ diff --git a/muttlib.c b/muttlib.c index e56bbcd..f185e12 100644 --- a/muttlib.c +++ b/muttlib.c @@ -328,20 +328,18 @@ void mutt_safe_path(char *s, ssize_t l, address_t *a) } } -ssize_t -mutt_FormatString(char *dst, ssize_t dlen, const char *fmt, - format_t *callback, unsigned long data, format_flag flags) +ssize_t m_strformat(char *dst, ssize_t dlen, const char *fmt, + format_t *callback, unsigned long data, format_flag flags) { ssize_t pos = (flags & M_FORMAT_ARROWCURSOR && option (OPTARROWCURSOR)) ? 3 : 0; while (*fmt) { - char ifstring[STRING] = "", elsestring[STRING] = "", prefix[STRING] = ""; + char ifstring[STRING], elsestring[STRING], prefix[STRING] = ""; int ch; if (*fmt == '%') { if (*++fmt == '%') { - pos += m_strputc(dst + pos, dlen - pos, '%'); - fmt++; + pos += m_strputc(dst + pos, dlen - pos, *fmt++); continue; } @@ -384,6 +382,8 @@ mutt_FormatString(char *dst, ssize_t dlen, const char *fmt, if (!*fmt++) /* move past the trailing `?' */ break; /* bad format */ + } else { + *ifstring = *elsestring = '\0'; } switch (ch) { @@ -396,12 +396,9 @@ mutt_FormatString(char *dst, ssize_t dlen, const char *fmt, ch = *fmt++; /* pad char */ if (COLS - SW > col) { - ssize_t wid; - - mutt_FormatString(buf, sizeof(buf), fmt, callback, data, flags); - wid = mutt_strwidth(buf); - - pos += m_strpad(dst + pos, dlen - pos, ch, COLS - SW - col - wid); + m_strformat(buf, sizeof(buf), fmt, callback, data, flags); + pos += m_strpad(dst + pos, dlen - pos, ch, + COLS - SW - col - mutt_strwidth(buf)); pos += m_strcpy(dst + pos, dlen - pos, buf); } return pos; /* skip rest of input */ @@ -440,22 +437,22 @@ mutt_FormatString(char *dst, ssize_t dlen, const char *fmt, } pos += m_strcpy(dst + pos, dlen - pos, buf); - continue; + break; } + continue; } if (*fmt == '\\') { if (!*++fmt) break; - switch (*fmt) { + switch ((ch = *fmt++)) { case 'n': pos += m_strputc(dst + pos, dlen - pos, '\n'); break; case 't': pos += m_strputc(dst + pos, dlen - pos, '\t'); break; case 'r': pos += m_strputc(dst + pos, dlen - pos, '\r'); break; case 'f': pos += m_strputc(dst + pos, dlen - pos, '\f'); break; case 'v': pos += m_strputc(dst + pos, dlen - pos, '\v'); break; - default: pos += m_strputc(dst + pos, dlen - pos, *fmt); break; + default: pos += m_strputc(dst + pos, dlen - pos, ch); break; } - fmt++; } else { ssize_t len = strcspn(fmt, "%\\"); diff --git a/nntp/newsrc.c b/nntp/newsrc.c index 178594e..2c95d8b 100644 --- a/nntp/newsrc.c +++ b/nntp/newsrc.c @@ -344,7 +344,7 @@ NNTP_SERVER *mutt_select_newsserver (char *server) if (!conn) return NULL; - mutt_FormatString (file, sizeof (file), NONULL (NewsRc), nntp_format_str, 0, + m_strformat (file, sizeof (file), NONULL (NewsRc), nntp_format_str, 0, 0); mutt_expand_path (file, sizeof (file)); diff --git a/protos.h b/protos.h index a989214..2dc73ef 100644 --- a/protos.h +++ b/protos.h @@ -18,7 +18,7 @@ typedef const char *format_t (char *, ssize_t, char, const char *, const char *, const char *, const char *, unsigned long, format_flag); -ssize_t mutt_FormatString(char *, ssize_t, const char *, format_t *, +ssize_t m_strformat(char *, ssize_t, const char *, format_t *, unsigned long, format_flag); void set_quadoption (int, int); diff --git a/recvattach.c b/recvattach.c index 1e0af26..50d3601 100644 --- a/recvattach.c +++ b/recvattach.c @@ -313,16 +313,16 @@ const char *mutt_attach_fmt (char *dest, } if (optional) - mutt_FormatString (dest, destlen, ifstring, mutt_attach_fmt, data, 0); + m_strformat (dest, destlen, ifstring, mutt_attach_fmt, data, 0); else if (flags & M_FORMAT_OPTIONAL) - mutt_FormatString (dest, destlen, elsestring, mutt_attach_fmt, data, 0); + m_strformat (dest, destlen, elsestring, mutt_attach_fmt, data, 0); return (src); } static void attach_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) { int w=(COLS-SW)>blen?blen:(COLS-SW); - mutt_FormatString (b, w, NONULL (AttachFormat), mutt_attach_fmt, + m_strformat (b, w, NONULL (AttachFormat), mutt_attach_fmt, (unsigned long) (((ATTACHPTR **) menu->data)[num]), M_FORMAT_ARROWCURSOR); } diff --git a/remailer.c b/remailer.c index 7d1dceb..40f5bba 100644 --- a/remailer.c +++ b/remailer.c @@ -388,9 +388,9 @@ static const char *mix_entry_fmt (char *dest, } if (optional) - mutt_FormatString (dest, destlen, ifstring, mutt_attach_fmt, data, 0); + m_strformat (dest, destlen, ifstring, mutt_attach_fmt, data, 0); else if (flags & M_FORMAT_OPTIONAL) - mutt_FormatString (dest, destlen, elsestring, mutt_attach_fmt, data, 0); + m_strformat (dest, destlen, elsestring, mutt_attach_fmt, data, 0); return (src); } @@ -401,7 +401,7 @@ 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); - mutt_FormatString (b, w, NONULL (MixEntryFormat), mix_entry_fmt, + m_strformat (b, w, NONULL (MixEntryFormat), mix_entry_fmt, (unsigned long) type2_list[num], M_FORMAT_ARROWCURSOR); } diff --git a/sendlib.c b/sendlib.c index e863656..c7e8bfd 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]; - mutt_FormatString (cmd, sizeof (cmd), NONULL (Inews), nntp_format_str, 0, + m_strformat (cmd, sizeof (cmd), NONULL (Inews), nntp_format_str, 0, 0); if (m_strisempty(cmd)) { i = nntp_post (msg); -- 2.20.1