revert using strcasestr and use a more optimized portable version
authorHiltjo Posthuma <hiltjo@codemadness.org>
Tue, 8 Feb 2022 18:32:25 +0000 (19:32 +0100)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Tue, 8 Feb 2022 18:38:23 +0000 (19:38 +0100)
... compared to the old cistrstr().

Thanks for the feedback!

config.mk
dmenu.c

index bea4e4bdeaac2f1f945a76dcb2b947f89f3c9ee2..05d5a3e801e838c6a8a5e02834d63dd880bd66da 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -23,7 +23,7 @@ INCS = -I$(X11INC) -I$(FREETYPEINC)
 LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS)
 
 # flags
-CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_GNU_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS)
+CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS)
 CFLAGS   = -std=c99 -pedantic -Wall -Os $(INCS) $(CPPFLAGS)
 LDFLAGS  = $(LIBS)
 
diff --git a/dmenu.c b/dmenu.c
index d06bea199595abe42b6ede82efb32ff3bfac5013..88d2f1245380095eef66a653ae83aa087ef80ea7 100644 (file)
--- a/dmenu.c
+++ b/dmenu.c
@@ -102,6 +102,25 @@ cleanup(void)
        XCloseDisplay(dpy);
 }
 
+static char *
+cistrstr(const char *h, const char *n)
+
+{
+       size_t i;
+
+       if (!n[0])
+               return (char *)h;
+
+       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;
+}
+
 static int
 drawitem(struct item *item, int x, int y, int w)
 {
@@ -711,7 +730,7 @@ main(int argc, char *argv[])
                        fast = 1;
                else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
                        fstrncmp = strncasecmp;
-                       fstrstr = strcasestr;
+                       fstrstr = cistrstr;
                } else if (i + 1 == argc)
                        usage();
                /* these options take one argument */