From 3496545358da0b95880615ead581c13f91b1b5f9 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sat, 1 Jan 2022 17:58:21 +0100 Subject: mflow: fixed lines were not wrapped, add test suite Reported by ninewise. --- mflow.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'mflow.c') diff --git a/mflow.c b/mflow.c index 1013da5..9bed19d 100644 --- a/mflow.c +++ b/mflow.c @@ -29,28 +29,6 @@ chgquote(int quotes) } } -void -fixed(int quotes, char *line, size_t linelen) -{ - chgquote(quotes); - - if (column && linelen > (size_t)(maxcolumn - column)) { - putchar('\n'); - column = 0; - } - - if (column == 0) { - for (; column < quotes; column++) - putchar('>'); - if (quotes && *line != ' ') - putchar(' '); - } - - fwrite(line, 1, linelen, stdout); - putchar('\n'); - column = 0; -} - void flowed(int quotes, char *line, ssize_t linelen) { @@ -96,6 +74,15 @@ flowed(int quotes, char *line, ssize_t linelen) } } +void +fixed(int quotes, char *line, size_t linelen) +{ + flowed(quotes, line, linelen); + + putchar('\n'); + column = 0; +} + int main(int argc, char *argv[]) { @@ -200,6 +187,11 @@ main(int argc, char *argv[]) if (delsp) line[--rd] = 0; flowed(quotes, line, rd); + } else if (rd == 0) { // empty line is fixed + if (column > 0) + putchar('\n'); + putchar('\n'); + column = 0; } else { if (force && rd > maxcolumn) { flowed(quotes, line, rd); -- cgit 1.4.1