aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2022-02-08 19:32:25 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2022-02-08 19:38:23 +0100
commit3e39c526d28582b0b5606d3e3bb36ee3d271e616 (patch)
tree7052e43bfcaa5835232c922f9da9232832e5da67
parenta9a3836861bd23387b5a51d6f6ac23377e98e26f (diff)
revert using strcasestr and use a more optimized portable version
... compared to the old cistrstr(). Thanks for the feedback!
-rw-r--r--config.mk2
-rw-r--r--dmenu.c21
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)
23LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) 23LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS)
24 24
25# flags 25# flags
26CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_GNU_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS) 26CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS)
27CFLAGS = -std=c99 -pedantic -Wall -Os $(INCS) $(CPPFLAGS) 27CFLAGS = -std=c99 -pedantic -Wall -Os $(INCS) $(CPPFLAGS)
28LDFLAGS = $(LIBS) 28LDFLAGS = $(LIBS)
29 29
diff --git a/dmenu.c b/dmenu.c
index d06bea1..88d2f12 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -102,6 +102,25 @@ cleanup(void)
102 XCloseDisplay(dpy); 102 XCloseDisplay(dpy);
103} 103}
104 104
105static char *
106cistrstr(const char *h, const char *n)
107
108{
109 size_t i;
110
111 if (!n[0])
112 return (char *)h;
113
114 for (; *h; ++h) {
115 for (i = 0; n[i] && tolower((unsigned char)n[i]) ==
116 tolower((unsigned char)h[i]); ++i)
117 ;
118 if (n[i] == '\0')
119 return (char *)h;
120 }
121 return NULL;
122}
123
105static int 124static int
106drawitem(struct item *item, int x, int y, int w) 125drawitem(struct item *item, int x, int y, int w)
107{ 126{
@@ -711,7 +730,7 @@ main(int argc, char *argv[])
711 fast = 1; 730 fast = 1;
712 else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ 731 else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
713 fstrncmp = strncasecmp; 732 fstrncmp = strncasecmp;
714 fstrstr = strcasestr; 733 fstrstr = cistrstr;
715 } else if (i + 1 == argc) 734 } else if (i + 1 == argc)
716 usage(); 735 usage();
717 /* these options take one argument */ 736 /* these options take one argument */