aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-08-09 21:08:49 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-08-09 21:08:49 +0200
commita5c5e22204d54bf80c2ac2277a56db15467ee641 (patch)
treeb512a84218eee6d2ba7505cb56b8e6bf2725c746
parentd779211dc7173d3eb3628930a3f81b5d201919ff (diff)
downloadmblaze-a5c5e22204d54bf80c2ac2277a56db15467ee641.tar.gz
mscan: fix formatting of %f without width, and for %s with width
-rw-r--r--mscan.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/mscan.c b/mscan.c
index 914f219..470a3ea 100644
--- 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':
{