diff options
author | Anselm R. Garbe <garbeam@gmail.com> | 2007-10-01 15:28:42 +0200 |
---|---|---|
committer | Anselm R. Garbe <garbeam@gmail.com> | 2007-10-01 15:28:42 +0200 |
commit | 8b2f132973f0fc8150ea66debbed057d849b5cfe (patch) | |
tree | 1a2d661230af69ad8bdde849c048b37e9e8df76e /dmenu.c | |
parent | 1c488e6dac6e327ce06685556b1989bd75faf241 (diff) | |
download | dmenu-8b2f132973f0fc8150ea66debbed057d849b5cfe.tar.gz dmenu-8b2f132973f0fc8150ea66debbed057d849b5cfe.tar.bz2 dmenu-8b2f132973f0fc8150ea66debbed057d849b5cfe.zip |
implemented strcasestr for dmenu (I call it cistrstr) for portability issues (cygwin has no strcasestr, oh dear)
Diffstat (limited to 'dmenu.c')
-rw-r--r-- | dmenu.c | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -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); @@ -511,7 +512,7 @@ match(char *pattern) { 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)) + if(!i->matched && cistrstr(i->text, pattern)) j = appenditem(i, j); if(idomatch) for(i = allitems; i; i = i->next) @@ -629,6 +630,29 @@ strcaseido(const char *text, const char *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; |