aboutsummaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authornicm <nicm>2019-06-13 19:46:00 +0000
committernicm <nicm>2019-06-13 19:46:00 +0000
commit3e72e98e3bdf3e814d6d20060247bb5f5dc859bb (patch)
tree8610823f2b11740c8079b86875bda970f901668a /window.c
parent7e6a26cc9d857ffc53fdb2395aa5413ff1865f9e (diff)
downloadrtmux-3e72e98e3bdf3e814d6d20060247bb5f5dc859bb.tar.gz
rtmux-3e72e98e3bdf3e814d6d20060247bb5f5dc859bb.tar.bz2
rtmux-3e72e98e3bdf3e814d6d20060247bb5f5dc859bb.zip
Add regular expression support for the format search, match and
substitute modifiers.
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 781ff30c..e89cf96c 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>
@@ -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);