diff options
-rw-r--r-- | man/mflow.1 | 18 | ||||
-rw-r--r-- | mflow.c | 30 |
2 files changed, 41 insertions, 7 deletions
diff --git a/man/mflow.1 b/man/mflow.1 index 63a2a23..867beae 100644 --- a/man/mflow.1 +++ b/man/mflow.1 @@ -1,4 +1,4 @@ -.Dd July 26, 2017 +.Dd September 6, 2017 .Dt MFLOW 1 .Os .Sh NAME @@ -6,6 +6,9 @@ .Nd reflow format=flowed plain text mails .Sh SYNOPSIS .Nm +.Op Fl f +.Op Fl q +.Op Fl w Ar width \&< .Ar file .Sh DESCRIPTION @@ -31,6 +34,19 @@ If defined, the environment variable .Ev MAXCOLUMNS specifies the maximum line length. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl f +Force line wrapping of long lines. +.It Fl q +Prefix lines with +.Sq Li \&< . +Can be used multiple times. +.It Fl w Ar width +Set maximum line length to +.Ar width . +.El .Sh EXIT STATUS .Ex -std .Sh SEE ALSO diff --git a/mflow.c b/mflow.c index e608907..68d2629 100644 --- a/mflow.c +++ b/mflow.c @@ -32,7 +32,7 @@ fixed(int quotes, char *line, size_t linelen) { chgquote(quotes); - if (linelen > (size_t)(maxcolumn - column)) { + if (column && linelen > (size_t)(maxcolumn - column)) { putchar('\n'); column = 0; } @@ -93,14 +93,16 @@ flowed(int quotes, char *line, ssize_t linelen) } int -main() +main(int argc, char *argv[]) { char *linebuf = 0; char *line; size_t linelen = 0; - int quotes = 0; + int outer_quotes = 0; + int quotes; int reflow = 1; // re-evaluated on $PIPE_CONTENTTYPE + int force = 0; int delsp = 0; char *ct = getenv("PIPE_CONTENTTYPE"); @@ -133,6 +135,17 @@ main() maxcolumn = m; } + int c; + while ((c = getopt(argc, argv, "f:w:q")) != -1) + switch (c) { + case 'f': force = 1; break; + case 'w': maxcolumn = atoi(optarg); break; + case 'q': outer_quotes++; break; + default: + fprintf(stderr, "Usage: mflow [-f] [-q] [-w MAXCOLUMNS]\n"); + exit(2); + } + while (1) { errno = 0; ssize_t rd = getdelim(&linebuf, &linelen, '\n', stdin); @@ -146,7 +159,7 @@ main() line = linebuf; - if (!reflow) { + if (!reflow && !force) { fwrite(line, 1, rd, stdout); continue; } @@ -156,7 +169,7 @@ main() if (rd > 0 && line[rd-1] == '\r') line[--rd] = 0; - quotes = 0; + quotes = outer_quotes; while (*line == '>') { // measure quote depth line++; quotes++; @@ -180,7 +193,12 @@ main() line[--rd] = 0; flowed(quotes, line, rd); } else { - fixed(quotes, line, rd); + if (force && rd > maxcolumn) { + flowed(quotes, line, rd); + fixed(quotes, "", 0); + } else { + fixed(quotes, line, rd); + } } } |