diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-11-15 23:19:52 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-11-15 23:19:52 +0000 |
commit | 602f7427acffff822aef52008f38d3af8430a91b (patch) | |
tree | 5f04cc477de4dda8e170133b7a4e919db411910e | |
parent | 83daf11716da1e22d551735ace9d4ee96e00255e (diff) |
Make window_pane_index work the same as window_index, from Ben Boeckel.
-rw-r--r-- | usr.bin/tmux/cmd-respawn-pane.c | 9 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-split-window.c | 5 | ||||
-rw-r--r-- | usr.bin/tmux/screen-redraw.c | 7 | ||||
-rw-r--r-- | usr.bin/tmux/status.c | 7 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 4 | ||||
-rw-r--r-- | usr.bin/tmux/window.c | 20 |
6 files changed, 31 insertions, 21 deletions
diff --git a/usr.bin/tmux/cmd-respawn-pane.c b/usr.bin/tmux/cmd-respawn-pane.c index dd476cbef76..e0e8d64a81f 100644 --- a/usr.bin/tmux/cmd-respawn-pane.c +++ b/usr.bin/tmux/cmd-respawn-pane.c @@ -1,4 +1,4 @@ -/* $Id: cmd-respawn-pane.c,v 1.3 2011/07/09 01:37:00 nicm Exp $ */ +/* $Id: cmd-respawn-pane.c,v 1.4 2011/11/15 23:19:51 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -49,15 +49,18 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx) struct session *s; struct environ env; const char *cmd; - char *cause; + char *cause; + u_int idx; if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL) return (-1); w = wl->window; if (!args_has(self->args, 'k') && wp->fd != -1) { + if (window_pane_index(wp, &idx) != 0) + fatalx("index not found"); ctx->error(ctx, "pane still active: %s:%u.%u", - s->name, wl->idx, window_pane_index(w, wp)); + s->name, wl->idx, idx); return (-1); } diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c index e2f1591c959..05d9815af08 100644 --- a/usr.bin/tmux/cmd-split-window.c +++ b/usr.bin/tmux/cmd-split-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-split-window.c,v 1.24 2011/08/30 09:18:52 nicm Exp $ */ +/* $OpenBSD: cmd-split-window.c,v 1.25 2011/11/15 23:19:51 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -140,7 +140,8 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx) environ_free(&env); if (args_has(args, 'P')) { - paneidx = window_pane_index(wl->window, new_wp); + if (window_pane_index(new_wp, &paneidx) != 0) + fatalx("index not found"); ctx->print(ctx, "%s:%u.%u", s->name, wl->idx, paneidx); } return (0); diff --git a/usr.bin/tmux/screen-redraw.c b/usr.bin/tmux/screen-redraw.c index ae2a7c6d77b..f868401d522 100644 --- a/usr.bin/tmux/screen-redraw.c +++ b/usr.bin/tmux/screen-redraw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen-redraw.c,v 1.18 2011/07/08 21:51:40 nicm Exp $ */ +/* $OpenBSD: screen-redraw.c,v 1.19 2011/11/15 23:19:51 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -264,7 +264,7 @@ screen_redraw_draw_number(struct client *c, struct window_pane *wp) { struct tty *tty = &c->tty; struct session *s = c->session; - struct options *oo = &s->options; + struct options *oo = &s->options; struct window *w = wp->window; struct grid_cell gc; u_int idx, px, py, i, j, xoff, yoff; @@ -272,7 +272,8 @@ screen_redraw_draw_number(struct client *c, struct window_pane *wp) char buf[16], *ptr; size_t len; - idx = window_pane_index(w, wp); + if (window_pane_index(wp, &idx) != 0) + fatalx("index not found"); len = xsnprintf(buf, sizeof buf, "%u", idx); if (wp->sx < len) diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index e1590cfe7ca..b02cf061075 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.79 2011/11/05 09:06:31 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.80 2011/11/15 23:19:51 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -372,6 +372,7 @@ status_replace1(struct client *c, struct session *s, struct winlink *wl, char ch, tmp[256], *ptr, *endptr, *freeptr; size_t ptrlen; long limit; + u_int idx; if (s == NULL) s = c->session; @@ -422,8 +423,10 @@ status_replace1(struct client *c, struct session *s, struct winlink *wl, ptr = tmp; goto do_replace; case 'P': + if (window_pane_index(wp, &idx) != 0) + fatalx("index not found"); xsnprintf( - tmp, sizeof tmp, "%u", window_pane_index(wl->window, wp)); + tmp, sizeof tmp, "%u", idx); ptr = tmp; goto do_replace; case 'S': diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index ccaaaff925b..488e8149fa9 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.297 2011/10/23 10:16:14 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.298 2011/11/15 23:19:51 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1931,7 +1931,7 @@ struct window_pane *window_pane_next_by_number(struct window *, struct window_pane *, u_int); struct window_pane *window_pane_previous_by_number(struct window *, struct window_pane *, u_int); -u_int window_pane_index(struct window *, struct window_pane *); +int window_pane_index(struct window_pane *, u_int *); u_int window_count_panes(struct window *); void window_destroy_panes(struct window *); struct window_pane *window_pane_find_by_id(u_int); diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index f4d0da653c7..bf38fd60311 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.68 2011/09/25 18:53:04 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.69 2011/11/15 23:19:51 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -486,19 +486,21 @@ window_pane_previous_by_number(struct window *w, struct window_pane *wp, return (wp); } -u_int -window_pane_index(struct window *w, struct window_pane *wp) +int +window_pane_index(struct window_pane *wp, u_int *i) { struct window_pane *wq; - u_int n; + struct window *w = wp->window; - n = options_get_number(&w->options, "pane-base-index"); + *i = options_get_number(&w->options, "pane-base-index"); TAILQ_FOREACH(wq, &w->panes, entry) { - if (wp == wq) - break; - n++; + if (wp == wq) { + return (0); + } + (*i)++; } - return (n); + + return (-1); } u_int |