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 | |
parent | 1c488e6dac6e327ce06685556b1989bd75faf241 (diff) |
implemented strcasestr for dmenu (I call it cistrstr) for portability issues (cygwin has no strcasestr, oh dear)
-rw-r--r-- | dmenu.c | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -58,6 +58,7 @@ void readstdin(void); | |||
58 | void run(void); | 58 | void run(void); |
59 | void setup(Bool bottom); | 59 | void setup(Bool bottom); |
60 | int strcaseido(const char *text, const char *pattern); | 60 | int strcaseido(const char *text, const char *pattern); |
61 | char *cistrstr(const char *s, const char *sub); | ||
61 | unsigned int textnw(const char *text, unsigned int len); | 62 | unsigned int textnw(const char *text, unsigned int len); |
62 | unsigned int textw(const char *text); | 63 | unsigned 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 | ||
633 | char * | ||
634 | cistrstr(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 | |||
632 | unsigned int | 656 | unsigned int |
633 | textnw(const char *text, unsigned int len) { | 657 | textnw(const char *text, unsigned int len) { |
634 | XRectangle r; | 658 | XRectangle r; |