mirror of
https://github.com/tmux/tmux.git
synced 2025-09-02 05:21:10 +00:00
Add regular expression support for the format search, match and
substitute modifiers.
This commit is contained in:
34
window.c
34
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);
|
||||
|
Reference in New Issue
Block a user