#define INIT 0x000800 /* initialize component */
#define SPLIT 0x001000 /* split headers (don't concatenate) */
#define NONEWLINE 0x002000 /* don't write trailing newline */
-#define LBITS "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07LEFTADJUST\010COMPRESS\011ADDRFMT\012DATEFMT\013FORMAT\014INIT\015SPLIT\016NONEWLINE"
+#define RTRIM 0x004000 /* trim trailing whitespace */
+#define LBITS "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07LEFTADJUST\010COMPRESS\011ADDRFMT\012DATEFMT\013FORMAT\014INIT\015SPLIT\016NONEWLINE\017RTRIM"
#define GFLAGS (NOCOMPONENT | UPPERCASE | CENTER | LEFTADJUST | COMPRESS | SPLIT)
struct mcomp {
{ "nocompress", 0, COMPRESS },
{ "split", SPLIT, 0 },
{ "nosplit", 0, SPLIT },
+ { "rtrim", RTRIM, 0 },
+ { "nortrim", 0, RTRIM },
{ "addrfield", ADDRFMT, DATEFMT },
{ "datefield", DATEFMT, ADDRFMT },
{ "newline", 0, NONEWLINE },
{
int count, cchdr;
unsigned char *cp;
+ char trimmed_prefix[BUFSIZ];
+ strncpy(trimmed_prefix, c1->c_text ? c1->c_text : c1->c_name, sizeof(trimmed_prefix) - 1);
+ rtrim(trimmed_prefix);
cchdr = 0;
lm = 0;
wid = c1->c_width ? c1->c_width : global.c_width;
onelp = NULL;
if (c1->c_flags & CLEARTEXT) {
- putstr(c1->c_text);
+ putstr((c1->c_flags & RTRIM) ? rtrim(c1->c_text) : c1->c_text);
putstr("\n");
return;
}
for (cp = (c1->c_text ? c1->c_text : c1->c_name); *cp; cp++)
if (islower(*cp))
*cp = toupper(*cp);
- putstr(c1->c_text ? c1->c_text : c1->c_name);
+ if (*c2->c_text && *c2->c_text != '\n' && *c2->c_text != '\r') {
+ putstr(c1->c_text ? c1->c_text : c1->c_name);
+ } else {
+ putstr(trimmed_prefix);
+ }
if (flag != BODYCOMP) {
putstr(": ");
if (!(c1->c_flags & SPLIT))
}
count += c1->c_offset;
- if ((cp = oneline(c2->c_text, c1->c_flags)))
- putstr(cp);
+ if ((cp = oneline(c2->c_text, c1->c_flags))) {
+ putstr((c1->c_flags & RTRIM) ? rtrim(cp) : cp);
+ }
if (term == '\n')
putstr("\n");
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);
+ if (flag == BODYCOMP && !(c1->c_flags & NOCOMPONENT)) {
+ if (*cp) {
+ putstr(c1->c_text ? c1->c_text : c1->c_name);
+ } else {
+ putstr(trimmed_prefix);
+ }
+ }
if (*cp)
- putstr(cp);
+ putstr((c1->c_flags & RTRIM) ? rtrim(cp) : cp);
+
if (term == '\n')
putstr("\n");
}