X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fmhl.c;h=76d23358588480cd0c6b24ee2b8b83355176a0bc;hb=c89293b617b20e1bdceeed290941c45acc457b15;hp=a84703b8ba6404ba999fd5f59228b508a96a7a9d;hpb=6e4f8128fe078a3e54f5c92d27c31acc7b8f9fd8;p=mmh diff --git a/uip/mhl.c b/uip/mhl.c index a84703b..76d2335 100644 --- a/uip/mhl.c +++ b/uip/mhl.c @@ -77,7 +77,8 @@ char *version=VERSION; #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 { @@ -148,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 }, @@ -595,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) @@ -623,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) { @@ -884,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; @@ -897,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; } @@ -922,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)) @@ -970,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"); }