version 1.7, 2010/12/20 00:03:55 |
version 1.8, 2011/01/04 00:42:46 |
|
|
|
|
const struct cmd_entry cmd_find_window_entry = { |
const struct cmd_entry cmd_find_window_entry = { |
"find-window", "findw", |
"find-window", "findw", |
|
"t:", 1, 1, |
CMD_TARGET_WINDOW_USAGE " match-string", |
CMD_TARGET_WINDOW_USAGE " match-string", |
CMD_ARG1, "", |
0, |
cmd_target_init, |
NULL, |
cmd_target_parse, |
NULL, |
cmd_find_window_exec, |
cmd_find_window_exec |
cmd_target_free, |
|
cmd_target_print |
|
}; |
}; |
|
|
struct cmd_find_window_data { |
struct cmd_find_window_data { |
|
|
int |
int |
cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) |
cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) |
{ |
{ |
struct cmd_target_data *data = self->data; |
struct args *args = self->args; |
struct cmd_find_window_data *cdata; |
struct cmd_find_window_data *cdata; |
struct session *s; |
struct session *s; |
struct winlink *wl, *wm; |
struct winlink *wl, *wm; |
|
|
struct window_pane *wp; |
struct window_pane *wp; |
ARRAY_DECL(, u_int) list_idx; |
ARRAY_DECL(, u_int) list_idx; |
ARRAY_DECL(, char *) list_ctx; |
ARRAY_DECL(, char *) list_ctx; |
char *sres, *sctx, *searchstr; |
char *str, *sres, *sctx, *searchstr; |
u_int i, line; |
u_int i, line; |
|
|
if (ctx->curclient == NULL) { |
if (ctx->curclient == NULL) { |
|
|
} |
} |
s = ctx->curclient->session; |
s = ctx->curclient->session; |
|
|
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) |
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) |
return (-1); |
return (-1); |
|
|
|
str = args->argv[0]; |
|
|
ARRAY_INIT(&list_idx); |
ARRAY_INIT(&list_idx); |
ARRAY_INIT(&list_ctx); |
ARRAY_INIT(&list_ctx); |
|
|
xasprintf(&searchstr, "*%s*", data->arg); |
xasprintf(&searchstr, "*%s*", str); |
RB_FOREACH(wm, winlinks, &s->windows) { |
RB_FOREACH(wm, winlinks, &s->windows) { |
i = 0; |
i = 0; |
TAILQ_FOREACH(wp, &wm->window->panes, entry) { |
TAILQ_FOREACH(wp, &wm->window->panes, entry) { |
|
|
if (fnmatch(searchstr, wm->window->name, 0) == 0) |
if (fnmatch(searchstr, wm->window->name, 0) == 0) |
sctx = xstrdup(""); |
sctx = xstrdup(""); |
else { |
else { |
sres = window_pane_search(wp, data->arg, &line); |
sres = window_pane_search(wp, str, &line); |
if (sres == NULL && |
if (sres == NULL && |
fnmatch(searchstr, wp->base.title, 0) != 0) |
fnmatch(searchstr, wp->base.title, 0) != 0) |
continue; |
continue; |
|
|
xfree(searchstr); |
xfree(searchstr); |
|
|
if (ARRAY_LENGTH(&list_idx) == 0) { |
if (ARRAY_LENGTH(&list_idx) == 0) { |
ctx->error(ctx, "no windows matching: %s", data->arg); |
ctx->error(ctx, "no windows matching: %s", str); |
ARRAY_FREE(&list_idx); |
ARRAY_FREE(&list_idx); |
ARRAY_FREE(&list_ctx); |
ARRAY_FREE(&list_ctx); |
return (-1); |
return (-1); |