From b3358a90b2c83cdb8cd768f604cc797f5b2b64a4 Mon Sep 17 00:00:00 2001 From: terminx Date: Thu, 15 Jan 2015 06:45:27 +0000 Subject: [PATCH] Fix wildmatch(), resolves errors matching things like "*.zip" with "duke3d.hrp.zip" for example. git-svn-id: https://svn.eduke32.com/eduke32@4922 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/compat.c | 21 ++++++++++++++++----- polymer/eduke32/build/src/kplib.c | 17 ++++++++++++++--- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/polymer/eduke32/build/src/compat.c b/polymer/eduke32/build/src/compat.c index f3f705c67..da7d251ad 100644 --- a/polymer/eduke32/build/src/compat.c +++ b/polymer/eduke32/build/src/compat.c @@ -685,7 +685,6 @@ char *Bstrtolower(char *str) //Brute-force case-insensitive, slash-insensitive, * and ? wildcard matcher -//Given: string i and string j. string j can have wildcards //Returns: 1:matches, 0:doesn't match #ifndef WITHKPLIB extern char toupperlookup[256]; @@ -703,14 +702,26 @@ static int32_t wildmatch(const char *match, const char *wild) return 1; else if (*wild == '*') { - while (*wild == '*') wild++; - if (*wild == '\0') return 1; - while (*match && toupperlookup[*match] != toupperlookup[*wild]) match++; + do { wild++; } while (*wild == '*'); + do + { + if (*wild == '\0') + return 1; + while (*match && toupperlookup[*match] != toupperlookup[*wild]) match++; + if (*match && *(match+1) && toupperlookup[*(match+1)] != toupperlookup[*(wild+1)]) + { + match++; + continue; + } + break; + } + while (1); if (toupperlookup[*match] == toupperlookup[*wild]) continue; } return 0; - } while (1); + } + while (1); } #endif diff --git a/polymer/eduke32/build/src/kplib.c b/polymer/eduke32/build/src/kplib.c index f46552d17..54087e961 100644 --- a/polymer/eduke32/build/src/kplib.c +++ b/polymer/eduke32/build/src/kplib.c @@ -2419,9 +2419,20 @@ int32_t wildmatch(const char *match, const char *wild) return 1; else if (*wild == '*') { - while (*wild == '*') wild++; - if (*wild == '\0') return 1; - while (*match && toupperlookup[*match] != toupperlookup[*wild]) match++; + do { wild++; } while (*wild == '*'); + do + { + if (*wild == '\0') + return 1; + while (*match && toupperlookup[*match] != toupperlookup[*wild]) match++; + if (*match && *(match+1) && toupperlookup[*(match+1)] != toupperlookup[*(wild+1)]) + { + match++; + continue; + } + break; + } + while (1); if (toupperlookup[*match] == toupperlookup[*wild]) continue; }