commit 3f367506841bfd8944cc57e3ccf231c41130af5e
parent 711ff51a2e198b5471b9f372127119530f6bef70
Author: parazyd <parazyd@dyne.org>
Date: Sun, 20 May 2018 22:55:30 +0200
Be case-insensitive for inline searching.
Diffstat:
5 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/common.h b/common.h
@@ -26,6 +26,9 @@ struct dir {
#ifdef NEED_ASPRINTF
int asprintf(char **s, const char *fmt, ...);
#endif /* NEED_ASPRINTF */
+#ifdef NEED_STRCASESTR
+char *strcasestr(const char *h, const char *n);
+#endif /* NEED_STRCASESTR */
void die(const char *fmt, ...);
size_t mbsprint(const char *s, size_t len);
const char *typedisplay(char t);
diff --git a/config.mk b/config.mk
@@ -9,5 +9,6 @@ MANDIR = $(PREFIX)/share/man/man1
UI=ti
LIBS=-lcurses
-# Define NEED_ASPRINTF in your cflags is your system doesn't provide asprintf()
-#CFLAGS = -DNEED_ASPRINTF
+# Define NEED_ASPRINTF and/or NEED_STRCASESTR in your cflags if your system does
+# not provide asprintf() or strcasestr(), respectively.
+#CFLAGS = -DNEED_ASPRINTF -DNEED_STRCASESTR
diff --git a/sacc.c b/sacc.c
@@ -62,6 +62,18 @@ asprintf(char **s, const char *fmt, ...)
}
#endif /* NEED_ASPRINTF */
+#ifdef NEED_STRCASESTR
+char *
+strcasestr(const char *h, const char *n)
+{
+ size_t l = strlen(n);
+ for (; *h; h++)
+ if (!strncasecmp(h, n, l))
+ return (char *)h;
+ return 0;
+}
+#endif /* NEED_STRCASESTR */
+
/* print `len' columns of characters. */
size_t
mbsprint(const char *s, size_t len)
diff --git a/ui_ti.c b/ui_ti.c
@@ -392,14 +392,14 @@ searchinline(const char *searchstr, Item *entry, int pos)
if (pos > 0) {
for (i = dir->curline + 1; i < dir->nitems; ++i) {
- if (strstr(dir->items[i].username, searchstr)) {
+ if (strcasestr(dir->items[i].username, searchstr)) {
jumptoline(entry, i, 1);
break;
}
}
} else {
for (i = dir->curline - 1; i > -1; --i) {
- if (strstr(dir->items[i].username, searchstr)) {
+ if (strcasestr(dir->items[i].username, searchstr)) {
jumptoline(entry, i, 1);
break;
}
diff --git a/ui_txt.c b/ui_txt.c
@@ -223,7 +223,7 @@ searchinline(const char *searchstr, Item *entry)
return;
for (i = 0; i < dir->nitems; ++i)
- if (strstr(dir->items[i].username, searchstr))
+ if (strcasestr(dir->items[i].username, searchstr))
printuri(&(dir->items[i]), i + 1);
}