=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-find-window.c,v retrieving revision 1.8 retrieving revision 1.9 diff -c -r1.8 -r1.9 *** src/usr.bin/tmux/cmd-find-window.c 2011/01/04 00:42:46 1.8 --- src/usr.bin/tmux/cmd-find-window.c 2012/03/20 17:09:48 1.9 *************** *** 1,4 **** ! /* $OpenBSD: cmd-find-window.c,v 1.8 2011/01/04 00:42:46 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: cmd-find-window.c,v 1.9 2012/03/20 17:09:48 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott *************** *** 29,41 **** int cmd_find_window_exec(struct cmd *, struct cmd_ctx *); void cmd_find_window_callback(void *, int); void cmd_find_window_free(void *); const struct cmd_entry cmd_find_window_entry = { "find-window", "findw", ! "t:", 1, 1, ! CMD_TARGET_WINDOW_USAGE " match-string", 0, NULL, NULL, --- 29,53 ---- int cmd_find_window_exec(struct cmd *, struct cmd_ctx *); + u_int cmd_find_window_match_flags(struct args *); void cmd_find_window_callback(void *, int); void cmd_find_window_free(void *); + /* Flags for determining matching behavior. */ + #define CMD_FIND_WINDOW_BY_TITLE 0x1 + #define CMD_FIND_WINDOW_BY_CONTENT 0x2 + #define CMD_FIND_WINDOW_BY_NAME 0x4 + + #define CMD_FIND_WINDOW_ALL \ + (CMD_FIND_WINDOW_BY_TITLE | \ + CMD_FIND_WINDOW_BY_CONTENT | \ + CMD_FIND_WINDOW_BY_NAME) + + const struct cmd_entry cmd_find_window_entry = { "find-window", "findw", ! "CNt:T", 1, 4, ! "[-CNT] " CMD_TARGET_WINDOW_USAGE " match-string", 0, NULL, NULL, *************** *** 46,51 **** --- 58,83 ---- struct session *session; }; + u_int + cmd_find_window_match_flags(struct args *args) + { + u_int match_flags = 0; + + /* Turn on flags based on the options. */ + if (args_has(args, 'T')) + match_flags |= CMD_FIND_WINDOW_BY_TITLE; + if (args_has(args, 'C')) + match_flags |= CMD_FIND_WINDOW_BY_CONTENT; + if (args_has(args, 'N')) + match_flags |= CMD_FIND_WINDOW_BY_NAME; + + /* If none of the flags were set, default to matching anything. */ + if (match_flags == 0) + match_flags = CMD_FIND_WINDOW_ALL; + + return match_flags; + } + int cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) { *************** *** 58,64 **** ARRAY_DECL(, u_int) list_idx; ARRAY_DECL(, char *) list_ctx; char *str, *sres, *sctx, *searchstr; ! u_int i, line; if (ctx->curclient == NULL) { ctx->error(ctx, "must be run interactively"); --- 90,96 ---- ARRAY_DECL(, u_int) list_idx; ARRAY_DECL(, char *) list_ctx; char *str, *sres, *sctx, *searchstr; ! u_int i, line, match_flags; if (ctx->curclient == NULL) { ctx->error(ctx, "must be run interactively"); *************** *** 69,74 **** --- 101,107 ---- if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) return (-1); + match_flags = cmd_find_window_match_flags(args); str = args->argv[0]; ARRAY_INIT(&list_idx); *************** *** 80,91 **** TAILQ_FOREACH(wp, &wm->window->panes, entry) { i++; ! if (fnmatch(searchstr, wm->window->name, 0) == 0) sctx = xstrdup(""); else { ! sres = window_pane_search(wp, str, &line); if (sres == NULL && ! fnmatch(searchstr, wp->base.title, 0) != 0) continue; if (sres == NULL) { --- 113,137 ---- TAILQ_FOREACH(wp, &wm->window->panes, entry) { i++; ! if ((match_flags & CMD_FIND_WINDOW_BY_NAME) && ! fnmatch(searchstr, wm->window->name, 0) == 0) sctx = xstrdup(""); else { ! sres = NULL; ! if (match_flags & CMD_FIND_WINDOW_BY_CONTENT) { ! sres = window_pane_search( ! wp, str, &line); ! } ! ! /* ! * If match_title isn't set we don't want to ! * bother checking the title, but that also ! * constitutes a failure to match so we still ! * want to abort. ! */ if (sres == NULL && ! (!(match_flags & CMD_FIND_WINDOW_BY_TITLE) || ! fnmatch(searchstr, wp->base.title, 0) != 0)) continue; if (sres == NULL) {