about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--mflow.c36
-rwxr-xr-xt/4500-mflow.t166
2 files changed, 180 insertions, 22 deletions
diff --git a/mflow.c b/mflow.c
index 1013da5..9bed19d 100644
--- a/mflow.c
+++ b/mflow.c
@@ -30,28 +30,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)
 {
 	chgquote(quotes);
@@ -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);
diff --git a/t/4500-mflow.t b/t/4500-mflow.t
new file mode 100755
index 0000000..879d6d4
--- /dev/null
+++ b/t/4500-mflow.t
@@ -0,0 +1,166 @@
+#!/bin/sh -e
+cd ${0%/*}
+. ./lib.sh
+plan 12
+
+rm -rf test.dir
+mkdir test.dir
+(
+cd test.dir
+
+export PIPE_CONTENTTYPE='text/plain; format=flowed'
+export COLUMNS=80
+
+cat <<! >a
+this 
+is 
+flowed.
+!
+cat <<! >b
+this is flowed.
+!
+check 'simple reflow' 'mflow <a | cmp - b'
+
+cat <<! >a
+this 
+is  
+two spaces.
+!
+cat <<! >b
+this is  two spaces.
+!
+check 'simple space stuffing' 'mflow <a | cmp - b'
+
+cat <<! >a
+this 
+is 
+flowed.
+this is fixed.
+!
+cat <<! >b
+this is flowed.
+this is fixed.
+!
+check 'simple fixed' 'mflow <a | cmp - b'
+
+cat <<! >a
+> this 
+> is 
+> quoted.
+this 
+is 
+unquoted.
+!
+cat <<! >b
+> this is quoted.
+this is unquoted.
+!
+check 'simple quoted' 'mflow <a | cmp - b'
+
+(
+export PIPE_CONTENTTYPE='text/plain; format=flowed; delsp=yes'
+
+cat <<! >a
+> this 
+> is 
+> delsp.
+
+> double  
+> spaced
+!
+cat <<! >b
+> thisisdelsp.
+
+> double spaced
+!
+check 'simple delsp' 'mflow <a | cmp - b'
+)
+
+cat <<! >a
+this 
+is 
+way more than eighty chars which is the terminal width to flow. 
+this 
+is 
+way more than eighty chars which is the terminal width to flow. 
+!
+cat <<! >b
+this is way more than eighty chars which is the terminal width to flow. this is
+way more than eighty chars which is the terminal width to flow. 
+!
+check 'simple wrap' 'mflow <a | cmp - b'
+
+cat <<! >a
+this 
+is 
+way more than eighty chars which is the terminal width to flow. 
+averylongwordcomeshere. 
+this 
+is 
+way more than eighty chars which is the terminal width to flow.
+!
+cat <<! >b
+this is way more than eighty chars which is the terminal width to flow. 
+averylongwordcomeshere. this is way more than eighty chars which is the
+terminal width to flow.
+!
+check 'more complex wrap' 'mflow <a | cmp - b'
+
+cat <<! >a
+foo 
+bar. 
+
+quux.
+!
+cat <<! >b
+foo bar. 
+
+quux.
+!
+check 'space before empty line' 'mflow <a | cmp - b'
+
+cat <<! >a
+Aaaaa bbbbb ccccc ddddd eeeee aaaaa bbbbb ccccc ddddd eeeee 
+aaaaa bbbbb ccccc ddddd eeeee aaaaa bbbbb ccccc ddddd eeeee 
+aaaaa bbbbb ccccc 
+ffffff gggggg hhhhhh iiiiii.
+!
+cat <<! >b
+Aaaaa bbbbb ccccc ddddd eeeee aaaaa bbbbb ccccc ddddd eeeee aaaaa bbbbb ccccc
+ddddd eeeee aaaaa bbbbb ccccc ddddd eeeee aaaaa bbbbb ccccc ffffff gggggg
+hhhhhh iiiiii.
+!
+check 'fixed lines are wrapped too' 'mflow <a | cmp - b'
+
+cat <<! >a
+some 
+wrapped. 
+-- 
+signature
+!
+cat <<! >b
+some wrapped. 
+-- 
+signature
+!
+check 'passes usenet signature marker as is' 'mflow <a | cmp - b'
+
+cat <<! >a
+some regular text being force wrapped because the line is way too long oh no who writes so long lines.
+!
+cat <<! >b
+some regular text being force wrapped because the line is way too long oh no
+who writes so long lines.
+!
+check 'force wrapping' 'mflow -f <a | cmp - b'
+
+cat <<! >a
+> some regular text being force wrapped because the line is way too long oh no who writes so long lines.
+!
+cat <<! >b
+> some regular text being force wrapped because the line is way too long oh no
+> who writes so long lines.
+!
+check 'force wrapping of quoted text' 'mflow -f <a | cmp - b'
+
+)