summaryrefslogtreecommitdiffstats
path: root/window.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-06-24 22:49:56 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-06-24 22:49:56 +0000
commit7e796dea035ed7028fc7188e65979725a24ff03d (patch)
tree2320aac0cebb0b6bf561a7d3a004622669ab174d /window.c
parent096cbf2ea558c0f66ee7bdaa8316e85c3e55ee69 (diff)
Change find-window and monitor-content to use fnmatch(3). For convenience and
compatibility, *s are implicitly added at the start and end of the pattern. Also display the line number and the entire line in the results, and lose the nasty section_string function and the now empty util.c file. Initially from Tiago Cunha.
Diffstat (limited to 'window.c')
-rw-r--r--window.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/window.c b/window.c
index 91606f53..834f1248 100644
--- a/window.c
+++ b/window.c
@@ -21,6 +21,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <fnmatch.h>
#include <paths.h>
#include <signal.h>
#include <stdint.h>
@@ -588,23 +589,26 @@ window_pane_mouse(
}
char *
-window_pane_search(struct window_pane *wp, const char *searchstr)
+window_pane_search(struct window_pane *wp, const char *searchstr, u_int *lineno)
{
struct screen *s = &wp->base;
- char *line, *ptr;
+ char *newsearchstr, *line, *msg;
u_int i;
- ptr = NULL;
+ msg = NULL;
+ xasprintf(&newsearchstr, "*%s*", searchstr);
+
for (i = 0; i < screen_size_y(s); i++) {
line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
- log_debug("XXX %s", line);
- if ((ptr = strstr(line, searchstr)) != NULL)
- break;
- xfree(line);
- }
- if (ptr != NULL) {
- ptr = section_string(line, strlen(ptr), ptr - line, 40);
+ if (fnmatch(newsearchstr, line, 0) == 0) {
+ msg = line;
+ if (lineno != NULL)
+ *lineno = i;
+ break;
+ }
xfree(line);
}
- return (ptr);
+
+ xfree(newsearchstr);
+ return (msg);
}