Added support for space as a sort of wildcard so "foo bar" matches

"FooBar" and "foo.bar"
This commit is contained in:
Bruce Hill 2019-09-22 13:50:39 -07:00
parent e1aaf05b98
commit 6c075036d7

12
ask.c
View File

@ -46,6 +46,10 @@ static int lcs(const char *str, const char *patt, int slen, int plen, int s, int
{ {
if (!patt[p]) return 0; if (!patt[p]) return 0;
if (!str[s]) return -1; if (!str[s]) return -1;
if (patt[p] == ' ') {
if (str[s] == ' ') return lcs(str, patt, slen, plen, s+1, p+1, cache);
else return lcs(str, patt, slen, plen, s, p+1, cache);
}
if (cache[s*plen + p]) return cache[s*plen + p]; if (cache[s*plen + p]) return cache[s*plen + p];
if (!EQ(str[s], patt[p])) return lcs(str, patt, slen, plen, s+1, p, cache); if (!EQ(str[s], patt[p])) return lcs(str, patt, slen, plen, s+1, p, cache);
// Run starting here // Run starting here
@ -62,6 +66,10 @@ static int lcs(const char *str, const char *patt, int slen, int plen, int s, int
static int matches(const char *str, const char *patt) static int matches(const char *str, const char *patt)
{ {
while (*patt) { while (*patt) {
if (*patt == ' ') {
++patt;
continue;
}
while (!EQ(*str, *patt)) { while (!EQ(*str, *patt)) {
if (!*str) return 0; if (!*str) return 0;
++str; ++str;
@ -111,6 +119,10 @@ static int draw_line(FILE *out, const char *option, const char *patt, int cursor
else to_start += len; else to_start += len;
++run; ++run;
++p; ++p;
} else if (patt[p] == ' ') {
run = 0;
++p;
--i;
} else { } else {
run = 0; run = 0;
if (state != dim) { if (state != dim) {