summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/window.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2019-06-13 19:46:00 +0000
committernicm <nicm@openbsd.org>2019-06-13 19:46:00 +0000
commitda6434566ed3fc91cdd8deb51016b6d92cb61e34 (patch)
treeba3d238c0fb9c6387ac48a369db9b8a009cecf3a /usr.bin/tmux/window.c
parentsu(I) goes back all the way to v1: (diff)
downloadwireguard-openbsd-da6434566ed3fc91cdd8deb51016b6d92cb61e34.tar.xz
wireguard-openbsd-da6434566ed3fc91cdd8deb51016b6d92cb61e34.zip
Add regular expression support for the format search, match and
substitute modifiers.
Diffstat (limited to 'usr.bin/tmux/window.c')
-rw-r--r--usr.bin/tmux/window.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index 75401cc183b..103c6e30c13 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.231 2019/06/09 06:50:24 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.232 2019/06/13 19:46:00 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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>
@@ -1206,24 +1207,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);