Xinqi Bao's Git

drw_text: improve both performance and correctness
[dmenu.git] / dmenu.c
diff --git a/dmenu.c b/dmenu.c
index 98507d9..eca67ac 100644 (file)
--- a/dmenu.c
+++ b/dmenu.c
@@ -103,13 +103,20 @@ cleanup(void)
 }
 
 static char *
-cistrstr(const char *s, const char *sub)
+cistrstr(const char *h, const char *n)
 {
-       size_t len;
+       size_t i;
+
+       if (!n[0])
+               return (char *)h;
 
-       for (len = strlen(sub); *s; s++)
-               if (!strncasecmp(s, sub, len))
-                       return (char *)s;
+       for (; *h; ++h) {
+               for (i = 0; n[i] && tolower((unsigned char)n[i]) ==
+                           tolower((unsigned char)h[i]); ++i)
+                       ;
+               if (n[i] == '\0')
+                       return (char *)h;
+       }
        return NULL;
 }
 
@@ -645,7 +652,7 @@ setup(void)
                /* no focused window is on screen, so use pointer location instead */
                if (mon < 0 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du))
                        for (i = 0; i < n; i++)
-                               if (INTERSECT(x, y, 1, 1, info[i]))
+                               if (INTERSECT(x, y, 1, 1, info[i]) != 0)
                                        break;
 
                x = info[i].x_org;