X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fmhl.c;h=76d23358588480cd0c6b24ee2b8b83355176a0bc;hb=dbf7c84b34c2d3f87c0c3cb11a04dff2c20b39e5;hp=c089d8e0bab3a6500b0a732d13d1aeb8bb44696a;hpb=04a3dfc70394a517a79340a7d3ecd9c6a23d0bee;p=mmh diff --git a/uip/mhl.c b/uip/mhl.c index c089d8e..76d2335 100644 --- a/uip/mhl.c +++ b/uip/mhl.c @@ -61,6 +61,8 @@ static struct swit switches[] = { { NULL, 0 } }; +char *version=VERSION; + #define NOCOMPONENT 0x000001 /* don't show component name */ #define UPPERCASE 0x000002 /* display in all upper case */ #define CENTER 0x000004 /* center line */ @@ -75,7 +77,8 @@ static struct swit switches[] = { #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 { @@ -146,6 +149,8 @@ static struct triple triples[] = { { "nocompress", 0, COMPRESS }, { "split", SPLIT, 0 }, { "nosplit", 0, SPLIT }, + { "rtrim", RTRIM, 0 }, + { "nortrim", 0, RTRIM }, { "addrfield", ADDRFMT, DATEFMT }, { "datefield", DATEFMT, ADDRFMT }, { "newline", 0, NONEWLINE }, @@ -593,6 +598,34 @@ process(char *fname, int ofilen, int ofilec) c1->c_flags &= ~HDROUTPUT; } +static boolean +simplematch(char *pattern, char *b) +{ + char *match = strrchr(pattern, '*'); + char repl; + boolean ret; + + /* check if pattern ends with a * and is not escaped witch a \ */ + if (!match || match[1] || (match > pattern && match[-1] == '\\')) { + if (!match || match[1]) { + return mh_strcasecmp(pattern, b) == 0; + } + match[0] = '\0'; + match[-1] = '*'; + ret = mh_strcasecmp(pattern, b)==0; + match[-1] = '\\'; + match[0] = '*'; + return ret; + } + + repl = b[match-pattern]; + b[match-pattern] = '\0'; + *match = '\0'; + ret = (mh_strcasecmp(pattern, b) == 0); + b[match-pattern] = repl; + *match = '*'; + return ret; +} static void mhlfile(FILE *fp, char *mname, int ofilen, int ofilec) @@ -621,7 +654,7 @@ mhlfile(FILE *fp, char *mname, int ofilen, int ofilec) switch (state = m_getfld2(state, &f, fp)) { case FLD2: for (ip = ignores; *ip; ip++) - if (mh_strcasecmp(f.name, *ip)==0) { + if (simplematch(*ip, f.name)) { break; } if (*ip) { @@ -882,7 +915,10 @@ putcomp(struct mcomp *c1, struct mcomp *c2, int flag) { 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; @@ -895,7 +931,7 @@ putcomp(struct mcomp *c1, struct mcomp *c2, int flag) 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; } @@ -920,7 +956,11 @@ putcomp(struct mcomp *c1, struct mcomp *c2, int flag) 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)) @@ -968,16 +1008,23 @@ putcomp(struct mcomp *c1, struct mcomp *c2, int flag) } 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"); }