summaryrefslogtreecommitdiffstats
path: root/window.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2019-06-14 15:51:09 +0100
committerThomas Adam <thomas@xteddy.org>2019-06-14 15:51:09 +0100
commit5e9757b30b8de13028149caa2683a7d76f231790 (patch)
tree5df34efc0213aa839e5ba6ddefa1193309cff383 /window.c
parent4bbf941436765201825c8d675f45b0cb70eb19d3 (diff)
parentd1d3bbb458b50ec455d65774d5c6669546b3b4ca (diff)
Merge branch 'obsd-master'
Diffstat (limited to 'window.c')
-rw-r--r--window.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/window.c b/window.c
index a6e15a34..4c5f7817 100644
--- a/window.c
+++ b/window.c
@@ -22,6 +22,7 @@
#include <errno.h>
#include <fcntl.h>
#include <fnmatch.h>
+#include <regex.h>
#include <signal.h>
#include <stdint.h>
#include <stdlib.h>
@@ -1207,24 +1208,41 @@ window_pane_visible(struct window_pane *wp)
}
u_int
-window_pane_search(struct window_pane *wp, const char *searchstr)
+window_pane_search(struct window_pane *wp, const char *term, int regex,
+ int ignore)
{
struct screen *s = &wp->base;
- char *newsearchstr, *line;
+ regex_t r;
+ char *new = NULL, *line;
u_int i;
+ int flags = 0, found;
- xasprintf(&newsearchstr, "*%s*", searchstr);
+ if (!regex) {
+ if (ignore)
+ flags |= FNM_CASEFOLD;
+ xasprintf(&new, "*%s*", term);
+ } else {
+ if (ignore)
+ flags |= REG_ICASE;
+ if (regcomp(&r, term, flags|REG_EXTENDED) != 0)
+ return (0);
+ }
for (i = 0; i < screen_size_y(s); i++) {
line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
- if (fnmatch(newsearchstr, line, 0) == 0) {
- free(line);
- break;
- }
+ if (!regex)
+ found = (fnmatch(new, line, 0) == 0);
+ else
+ found = (regexec(&r, line, 0, NULL, 0) == 0);
free(line);
+ if (found)
+ break;
}
+ if (!regex)
+ free(new);
+ else
+ regfree(&r);
- free(newsearchstr);
if (i == screen_size_y(s))
return (0);
return (i + 1);