]> diplodocus.org Git - nmh/blobdiff - uip/mhlsbr.c
Added getmymbox function escape.
[nmh] / uip / mhlsbr.c
index 12add6ccca2a793b7fbe5cbb77317a8639684e2d..28d489472125fd0f281e8711711223e43c3e8954 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        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        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)
 
 /*
 #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 },
     { "nocompress",    0,           COMPRESS },
     { "split",         SPLIT,       0 },
     { "nosplit",       0,           SPLIT },
+    { "rtrim",         RTRIM,       0 },
+    { "nortrim",       0,           RTRIM },
     { "addrfield",     ADDRFMT,     DATEFMT },
     { "bell",          BELL,        0 },
     { "nobell",        0,           BELL },
     { "addrfield",     ADDRFMT,     DATEFMT },
     { "bell",          BELL,        0 },
     { "nobell",        0,           BELL },
@@ -775,7 +778,7 @@ evalvar (struct mcomp *c1)
            return 1;
        }
 
            return 1;
        }
 
-       args = (struct arglist *) calloc((size_t) 1, sizeof(struct arglist));
+       args = (struct arglist *) mh_xcalloc ((size_t) 1, sizeof(struct arglist));
 
        if (arglist_tail)
            arglist_tail->a_next = args;
 
        if (arglist_tail)
            arglist_tail->a_next = args;
@@ -1181,7 +1184,7 @@ mcomp_format (struct mcomp *c1, struct mcomp *c2)
 
     (q = &pq)->pq_next = NULL;
     while ((cp = getname (ap))) {
 
     (q = &pq)->pq_next = NULL;
     while ((cp = getname (ap))) {
-       if ((p = (struct pqpair *) calloc ((size_t) 1, sizeof(*p))) == NULL)
+       if ((p = (struct pqpair *) mh_xcalloc ((size_t) 1, sizeof(*p))) == NULL)
            adios (NULL, "unable to allocate pqpair memory");
        else {
            if ((mp = getm (cp, NULL, 0, error, sizeof(error))) == NULL) {
            adios (NULL, "unable to allocate pqpair memory");
        else {
            if ((mp = getm (cp, NULL, 0, error, sizeof(error))) == NULL) {
@@ -1237,7 +1240,7 @@ add_queue (struct mcomp **head, struct mcomp **tail, char *name, char *text, int
 {
     struct mcomp *c1;
 
 {
     struct mcomp *c1;
 
-    if ((c1 = (struct mcomp *) calloc ((size_t) 1, sizeof(*c1))) == NULL)
+    if ((c1 = (struct mcomp *) mh_xcalloc ((size_t) 1, sizeof(*c1))) == NULL)
        adios (NULL, "unable to allocate comp memory");
     else {
        c1->c_flags = flags & ~INIT;
        adios (NULL, "unable to allocate comp memory");
     else {
        c1->c_flags = flags & ~INIT;
@@ -1293,6 +1296,12 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag)
 {
     int count, cchdr;
     char *cp;
 {
     int count, cchdr;
     char *cp;
+    /*
+     * Create a copy of c1->c_text with trailing whitespace
+     * trimmed, for use with blank lines.
+     */
+    char *trimmed_prefix =
+       rtrim (add (c1->c_text ? c1->c_text : c1->c_name, NULL));
 
     cchdr = 0;
     lm = 0;
 
     cchdr = 0;
     lm = 0;
@@ -1308,7 +1317,8 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag)
     onelp = NULL;
 
     if (c1->c_flags & CLEARTEXT) {
     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;
     }
        putstr ("\n", c1->c_flags);
        return;
     }
@@ -1382,21 +1392,33 @@ putcomp (struct mcomp *c1, struct mcomp *c2, int flag)
     count += c1->c_offset;
 
     if ((cp = oneline (c2->c_text, c1->c_flags)))
     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))) {
        lm = count;
        if (flag == BODYCOMP
     if (term == '\n')
        putstr ("\n", c1->c_flags);
     while ((cp = oneline (c2->c_text, c1->c_flags))) {
        lm = count;
        if (flag == BODYCOMP
-               && !(c1->c_flags & NOCOMPONENT))
-           putstr (c1->c_text ? c1->c_text : c1->c_name, c1->c_flags);
-       if (*cp)
-           putstr (cp, c1->c_flags);
+               && !(c1->c_flags & NOCOMPONENT)) {
+           /* Output component, trimming trailing whitespace if there
+              is no text on the line. */
+           if (*cp) {
+               putstr (c1->c_text ? c1->c_text : c1->c_name, c1->c_flags);
+           } else {
+               putstr (trimmed_prefix, c1->c_flags);
+           }
+       }
+       if (*cp) {
+           /* 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);
     }
     if (flag == BODYCOMP && term == '\n')
        c1->c_flags &= ~HDROUTPUT;              /* Buffer ended on a newline */
        if (term == '\n')
            putstr ("\n", c1->c_flags);
     }
     if (flag == BODYCOMP && term == '\n')
        c1->c_flags &= ~HDROUTPUT;              /* Buffer ended on a newline */
+
+    free (trimmed_prefix);
 }
 
 
 }