aboutsummaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2009-06-25 16:04:24 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2009-06-25 16:04:24 +0000
commitf7a9eb46fc0c0be659912b0cf9c2e7d7ced86bf9 (patch)
tree045e08db5ffd7da586326ab3f19968a92e2798c4 /window.c
parent853ad681620e9a031f41549a39c78d11b2da8990 (diff)
downloadrtmux-f7a9eb46fc0c0be659912b0cf9c2e7d7ced86bf9.tar.gz
rtmux-f7a9eb46fc0c0be659912b0cf9c2e7d7ced86bf9.tar.bz2
rtmux-f7a9eb46fc0c0be659912b0cf9c2e7d7ced86bf9.zip
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.
Diffstat (limited to 'window.c')
-rw-r--r--window.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/window.c b/window.c
index 568c1342..2093e5c3 100644
--- a/window.c
+++ b/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.4 2009/06/24 22:04:18 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.5 2009/06/24 22:49:56 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -21,6 +21,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <fnmatch.h>
#include <signal.h>
#include <stdint.h>
#include <stdlib.h>
@@ -602,23 +603,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);
}