[hackers] [dmenu] implemented strcasestr for dmenu (I call it cistrstr) for portability issues (cygwin has no strcasestr, oh dear)

From: Anselm R. Garbe <garbeam_AT_gmail.com>
Date: Mon Oct 01 15:28:31 2007

changeset: 230:f920d35c9ce0
tag: tip
user: Anselm R. Garbe <garbeam_AT_gmail.com>
date: Mon Oct 01 15:28:42 2007 +0200
summary: implemented strcasestr for dmenu (I call it cistrstr) for portability issues (cygwin has no strcasestr, oh dear)

diff -r a274afea9c8e -r f920d35c9ce0 dmenu.c
--- a/dmenu.c Mon Oct 01 11:44:25 2007 +0200
+++ b/dmenu.c Mon Oct 01 15:28:42 2007 +0200
@@ -58,6 +58,7 @@ void run(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
         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;
Received on Mon Oct 01 2007 - 15:28:31 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:58:25 UTC