diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2022-02-08 19:32:25 +0100 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2022-02-08 19:38:23 +0100 |
commit | 3e39c526d28582b0b5606d3e3bb36ee3d271e616 (patch) | |
tree | 7052e43bfcaa5835232c922f9da9232832e5da67 /dmenu.c | |
parent | a9a3836861bd23387b5a51d6f6ac23377e98e26f (diff) |
revert using strcasestr and use a more optimized portable version
... compared to the old cistrstr().
Thanks for the feedback!
Diffstat (limited to 'dmenu.c')
-rw-r--r-- | dmenu.c | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -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 */ |