diff options
author | 2009-06-24 22:49:56 +0000 | |
---|---|---|
committer | 2009-06-24 22:49:56 +0000 | |
commit | 570a3589dfc6d6844c7d6e79383dd195b6385063 (patch) | |
tree | 341cf8babb16c1746a0b2e95c1d66d82a82c3ed8 /usr.bin/tmux/window.c | |
parent | Add a dedicated function to convert a line into a string and use it to simplify the search window function. (diff) | |
download | wireguard-openbsd-570a3589dfc6d6844c7d6e79383dd195b6385063.tar.xz wireguard-openbsd-570a3589dfc6d6844c7d6e79383dd195b6385063.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.
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 'usr.bin/tmux/window.c')
-rw-r--r-- | usr.bin/tmux/window.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index 1027daa0385..33d44da61be 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/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 <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); } |