X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dmenu.c;h=3256f9c59e0090302e42187ed98620c3919bfe57;hb=d8688f7a4fe734b827cac3c156cae0db5aa4d740;hp=a4fca09c9bd8edbd3ab8aae524885ed865381f7a;hpb=6514b07ad24e9066252c418cdec1d6ccae570cf6;p=dmenu.git diff --git a/dmenu.c b/dmenu.c index a4fca09..3256f9c 100644 --- a/dmenu.c +++ b/dmenu.c @@ -58,6 +58,7 @@ void readstdin(void); void run(void); void setup(Bool bottom); int strcaseido(const char *text, const char *pattern); +char *cistrstr(const char *s, const char *sub); unsigned int textnw(const char *text, unsigned int len); unsigned int textw(const char *text); @@ -507,20 +508,16 @@ match(char *pattern) { nitem = 0; for(i = allitems; i; i=i->next) i->matched = False; - for(i = allitems; i; i = i->next) if(!i->matched && !strncasecmp(pattern, i->text, plen)) j = appenditem(i, j); - - for (i = allitems; i; i = i->next) - if(!i->matched && strcasestr(i->text, pattern)) + for(i = allitems; i; i = i->next) + if(!i->matched && cistrstr(i->text, pattern)) j = appenditem(i, j); - if(idomatch) - for (i = allitems; i; i = i->next) + for(i = allitems; i; i = i->next) if(!i->matched && strcaseido(i->text, pattern)) j = appenditem(i, j); - curr = prev = next = sel = item; calcoffsets(); } @@ -628,11 +625,34 @@ setup(Bool bottom) { int strcaseido(const char *text, const char *pattern) { for(; *text && *pattern; text++) - if (tolower(*text) == tolower(*pattern)) + if(tolower((int)*text) == tolower((int)*pattern)) pattern++; return !*pattern; } +char * +cistrstr(const char *s, const char *sub) { + int c, csub; + unsigned int len; + + if(!sub) + return (char *)s; + if((c = *sub++) != 0) { + c = tolower(c); + len = strlen(sub); + do { + do { + if((csub = *s++) == 0) + return (NULL); + } + while(tolower(csub) != c); + } + while(strncasecmp(s, sub, len) != 0); + s--; + } + return (char *)s; +} + unsigned int textnw(const char *text, unsigned int len) { XRectangle r;