From: David Levine Date: Mon, 15 Sep 2014 00:14:10 +0000 (-0500) Subject: An "rtrim" flag has been added to mhl to remove any trailing X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/1aa8f3e11e6d83ee4806abaa132ab9466f02ca5f?ds=inline An "rtrim" flag has been added to mhl to remove any trailing whitespace from filtered text lines. A corresponding "nortrim" flag has also been added. --- diff --git a/docs/pending-release-notes b/docs/pending-release-notes index 1ae76473..ba30e591 100644 --- a/docs/pending-release-notes +++ b/docs/pending-release-notes @@ -12,6 +12,9 @@ NEW FEATURES buffers. - If a component has trailing whitespace, e.g., body:component="> ", mhl now trims that whitespace off when filtering blank text lines. +- An "rtrim" flag has been added to mhl to remove any trailing + whitespace from filtered text lines. A corresponding "nortrim" flag + has also been added. ----------------- OBSOLETE FEATURES diff --git a/man/mhl.man b/man/mhl.man index 824faddf..0d3cd18a 100644 --- a/man/mhl.man +++ b/man/mhl.man @@ -236,6 +236,8 @@ nocenter flag don't center leftadjust flag strip off leading whitespace on each line of text noleftadjust flag don't leftadjust +rtrim flag trim whitespace at end of text lines +nortrim flag retain whitespace at end of text lines (default) compress flag change newlines in text to spaces nocompress flag don't compress wrap flag Wrap lines that exceed width (default) diff --git a/test/mhl/test-mhl-flags b/test/mhl/test-mhl-flags index 36a73236..b458a31e 100755 --- a/test/mhl/test-mhl-flags +++ b/test/mhl/test-mhl-flags @@ -30,7 +30,8 @@ And another trailing space: EOF -# check that blank lines don't end with whitepace +# check nortrim (default), and that trailing whitespace in a +# component is trimmed when filtering blank lines cat >"$expected" < There are two blank lines below. And there is a trailing space: > And another trailing space: @@ -46,5 +47,21 @@ EOF check "$expected" "$actual" +# check rtrim +cat >"$expected" < There are two blank lines below. And there is a trailing space: +> And another trailing space: +> +> +EOF + +cat >"$MH_TEST_DIR/test.format" <"$actual" +check "$expected" "$actual" + + rm -f "$MH_TEST_DIR/test.format" exit $failed diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 8d5202b5..8d8fea17 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -88,11 +88,12 @@ DEFINE_SWITCH_ARRAY(MHL, mhlswitches); #define DATEFMT 0x000800 /* contains dates */ #define FORMAT 0x001000 /* parse address/date/RFC-2047 field */ #define INIT 0x002000 /* initialize component */ +#define RTRIM 0x004000 /* trim trailing whitespace */ #define SPLIT 0x010000 /* split headers (don't concatenate) */ #define NONEWLINE 0x020000 /* don't write trailing newline */ #define NOWRAP 0x040000 /* Don't wrap lines ever */ #define FMTFILTER 0x080000 /* Filter through format filter */ -#define LBITS "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07CLEARSCR\010LEFTADJUST\011COMPRESS\012ADDRFMT\013BELL\014DATEFMT\015FORMAT\016INIT\021SPLIT\022NONEWLINE\023NOWRAP\024FMTFILTER" +#define LBITS "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07CLEARSCR\010LEFTADJUST\011COMPRESS\012ADDRFMT\013BELL\014DATEFMT\015FORMAT\016INIT\017RTRIM\021SPLIT\022NONEWLINE\023NOWRAP\024FMTFILTER" #define GFLAGS (NOCOMPONENT | UPPERCASE | CENTER | LEFTADJUST | COMPRESS | SPLIT | NOWRAP) /* @@ -221,6 +222,8 @@ static struct triple triples[] = { { "nocompress", 0, COMPRESS }, { "split", SPLIT, 0 }, { "nosplit", 0, SPLIT }, + { "rtrim", RTRIM, 0 }, + { "nortrim", 0, RTRIM }, { "addrfield", ADDRFMT, DATEFMT }, { "bell", BELL, 0 }, { "nobell", 0, BELL }, @@ -1314,7 +1317,8 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag) onelp = NULL; if (c1->c_flags & CLEARTEXT) { - putstr (c1->c_text, c1->c_flags); + putstr (c1->c_flags & RTRIM ? rtrim (c1->c_text) : c1->c_text, + c1->c_flags); putstr ("\n", c1->c_flags); return; } @@ -1388,7 +1392,8 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag) count += c1->c_offset; if ((cp = oneline (c2->c_text, c1->c_flags))) - putstr(cp, c1->c_flags); + /* Output line, trimming trailing whitespace if requested. */ + putstr (c1->c_flags & RTRIM ? rtrim (cp) : cp, c1->c_flags); if (term == '\n') putstr ("\n", c1->c_flags); while ((cp = oneline (c2->c_text, c1->c_flags))) { @@ -1404,7 +1409,8 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag) } } if (*cp) { - putstr (cp, c1->c_flags); + /* Output line, trimming trailing whitespace if requested. */ + putstr (c1->c_flags & RTRIM ? rtrim (cp) : cp, c1->c_flags); } if (term == '\n') putstr ("\n", c1->c_flags);