mblaze

Unix utilities to deal with Maildir - my mirror
git clone https://pi.duncano.de/git/mblaze.git
Log | Files | Refs | README | COPYING

commit a5c5e22204d54bf80c2ac2277a56db15467ee641
parent d779211dc7173d3eb3628930a3f81b5d201919ff
Author: Christian Neukirchen <chneukirchen@gmail.com>
Date:   Tue,  9 Aug 2016 21:08:49 +0200

mscan: fix formatting of %f without width, and for %s with width

Diffstat:
mscan.c | 25+++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/mscan.c b/mscan.c @@ -32,9 +32,11 @@ static int curyday; static char default_fflag[] = "%c%u%r %-3n %10d %17f %t %2i%s"; static char *fflag = default_fflag; -void +int u8putstr(FILE *out, char *s, ssize_t l, int pad) { + ssize_t ol = l; + while (*s && l > 0) { if (*s == '\t') *s = ' '; @@ -58,6 +60,10 @@ u8putstr(FILE *out, char *s, ssize_t l, int pad) if (pad) while (l-- > 0) putc(' ', out); + + if (l < 0) + l = 0; + return ol - l; } int @@ -350,8 +356,12 @@ oneline(char *file) fmt_date(msg, w, Iflag || *f == 'D')); break; case 'f': - u8putstr(stdout, fmt_from(msg), w ? w : 16, 1); - wleft -= w > 0 ? w : -w; + if (w) + wleft -= u8putstr(stdout, + fmt_from(msg), w, 1); + else + wleft -= u8putstr(stdout, + fmt_from(msg), wleft, 0); break; case 'i': { @@ -370,9 +380,12 @@ oneline(char *file) } break; case 's': - if (!w) w = wleft; - u8putstr(stdout, fmt_subject(msg, file), wleft, 0); - wleft -= w; + if (w) + wleft -= u8putstr(stdout, + fmt_subject(msg, file), w, 1); + else + wleft -= u8putstr(stdout, + fmt_subject(msg, file), wleft, 0); break; case 'b': {