]> diplodocus.org Git - nmh/commitdiff
An "rtrim" flag has been added to mhl to remove any trailing
authorDavid Levine <levinedl@acm.org>
Mon, 15 Sep 2014 00:14:10 +0000 (19:14 -0500)
committerDavid Levine <levinedl@acm.org>
Mon, 15 Sep 2014 00:14:10 +0000 (19:14 -0500)
whitespace from filtered text lines.  A corresponding "nortrim" flag
has also been added.

docs/pending-release-notes
man/mhl.man
test/mhl/test-mhl-flags
uip/mhlsbr.c

index 1ae7647..ba30e59 100644 (file)
@@ -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
index 824fadd..0d3cd18 100644 (file)
@@ -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)
index 36a7323..b458a31 100755 (executable)
@@ -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" <<EOF
 > 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" <<EOF
+> There are two blank lines below.  And there is a trailing space:
+> And another trailing space:
+>
+>
+EOF
+
+cat >"$MH_TEST_DIR/test.format" <<EOF
+body:component="> ",overflowtext=,overflowoffset=0,rtrim
+EOF
+
+"$mhl" -nomoreproc -form "$MH_TEST_DIR/test.format" `mhpath last` >"$actual"
+check "$expected" "$actual"
+
+
 rm -f "$MH_TEST_DIR/test.format"
 exit $failed
index 8d5202b..8d8fea1 100644 (file)
@@ -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);