From 54486d6633079b6d91677878914089727d759984 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 8 Feb 2022 19:32:25 +0100 Subject: revert using strcasestr and use a more optimized portable version ... compared to the old cistrstr(). Thanks for the feedback! --- config.mk | 2 +- dmenu.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/config.mk b/config.mk index bea4e4b..05d5a3e 100644 --- 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 0acd815..5379983 100644 --- 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) { @@ -722,7 +741,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 (!strcmp(argv[i], "-P")) /* is the input a password */ passwd = 1; else if (i + 1 == argc) -- cgit v1.2.3