From c89293b617b20e1bdceeed290941c45acc457b15 Mon Sep 17 00:00:00 2001 From: Philipp Takacs Date: Mon, 10 Jul 2017 16:34:45 +0200 Subject: [PATCH] mhl implement simple globbing ignores now supports simple globbing --- man/mhl.man1 | 5 +++++ uip/mhl.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/man/mhl.man1 b/man/mhl.man1 index 9785fe2..b6af953 100644 --- a/man/mhl.man1 +++ b/man/mhl.man1 @@ -168,6 +168,11 @@ ignores=component,... .RE .PP specifies a list of components which are never output. +This option supports some simple globbing, +so a '*' at the end of a component will match +for all components which start wich the string. +When you want to match a component which ends with +a '*', you can escape the '*' with a '\\'. .PP The component `MessageName' (case\-insensitive) will output the message file name as a one-line header, similar to diff --git a/uip/mhl.c b/uip/mhl.c index b8213b0..76d2335 100644 --- a/uip/mhl.c +++ b/uip/mhl.c @@ -598,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) @@ -626,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) { -- 1.7.10.4