aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@gmail.com>2007-10-01 15:28:42 +0200
committerAnselm R. Garbe <garbeam@gmail.com>2007-10-01 15:28:42 +0200
commit8b2f132973f0fc8150ea66debbed057d849b5cfe (patch)
tree1a2d661230af69ad8bdde849c048b37e9e8df76e
parent1c488e6dac6e327ce06685556b1989bd75faf241 (diff)
implemented strcasestr for dmenu (I call it cistrstr) for portability issues (cygwin has no strcasestr, oh dear)
-rw-r--r--dmenu.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/dmenu.c b/dmenu.c
index b28a548..3256f9c 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -58,6 +58,7 @@ void readstdin(void);
58void run(void); 58void run(void);
59void setup(Bool bottom); 59void setup(Bool bottom);
60int strcaseido(const char *text, const char *pattern); 60int strcaseido(const char *text, const char *pattern);
61char *cistrstr(const char *s, const char *sub);
61unsigned int textnw(const char *text, unsigned int len); 62unsigned int textnw(const char *text, unsigned int len);
62unsigned int textw(const char *text); 63unsigned int textw(const char *text);
63 64
@@ -511,7 +512,7 @@ match(char *pattern) {
511 if(!i->matched && !strncasecmp(pattern, i->text, plen)) 512 if(!i->matched && !strncasecmp(pattern, i->text, plen))
512 j = appenditem(i, j); 513 j = appenditem(i, j);
513 for(i = allitems; i; i = i->next) 514 for(i = allitems; i; i = i->next)
514 if(!i->matched && strcasestr(i->text, pattern)) 515 if(!i->matched && cistrstr(i->text, pattern))
515 j = appenditem(i, j); 516 j = appenditem(i, j);
516 if(idomatch) 517 if(idomatch)
517 for(i = allitems; i; i = i->next) 518 for(i = allitems; i; i = i->next)
@@ -629,6 +630,29 @@ strcaseido(const char *text, const char *pattern) {
629 return !*pattern; 630 return !*pattern;
630} 631}
631 632
633char *
634cistrstr(const char *s, const char *sub) {
635 int c, csub;
636 unsigned int len;
637
638 if(!sub)
639 return (char *)s;
640 if((c = *sub++) != 0) {
641 c = tolower(c);
642 len = strlen(sub);
643 do {
644 do {
645 if((csub = *s++) == 0)
646 return (NULL);
647 }
648 while(tolower(csub) != c);
649 }
650 while(strncasecmp(s, sub, len) != 0);
651 s--;
652 }
653 return (char *)s;
654}
655
632unsigned int 656unsigned int
633textnw(const char *text, unsigned int len) { 657textnw(const char *text, unsigned int len) {
634 XRectangle r; 658 XRectangle r;