On Thu, Oct 20, 2011 at 07:59:42 +0100, Nicholas Marriott wrote:
> Seems fine, but instead of returning (u_int)-1 can we change it to work
> like window_index.

Seems reasonable. Patch attached (applies on top of previous patches).

--Ben
From 75cdc56b9bbe2b5b25fd9374d73006325b04a345 Mon Sep 17 00:00:00 2001
From: Ben Boeckel <maths...@gmail.com>
Date: Thu, 20 Oct 2011 12:03:55 -0400
Subject: [PATCH 5/5] Change window_pane_index to be like window_index

---
 trunk/cmd-respawn-pane.c |    5 ++++-
 trunk/cmd-split-window.c |    3 ++-
 trunk/format.c           |    7 +++++--
 trunk/screen-redraw.c    |    5 +++--
 trunk/status.c           |    5 ++++-
 trunk/tmux.h             |    2 +-
 trunk/window.c           |   21 ++++++---------------
 7 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/trunk/cmd-respawn-pane.c b/trunk/cmd-respawn-pane.c
index 232ef72..d4d67d5 100644
--- a/trunk/cmd-respawn-pane.c
+++ b/trunk/cmd-respawn-pane.c
@@ -50,14 +50,17 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
        struct environ           env;
        const char              *cmd;
        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(wp));
+                   s->name, wl->idx, idx);
                return (-1);
        }
 
diff --git a/trunk/cmd-split-window.c b/trunk/cmd-split-window.c
index 22e6113..258c632 100644
--- a/trunk/cmd-split-window.c
+++ b/trunk/cmd-split-window.c
@@ -139,7 +139,8 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
        environ_free(&env);
 
        if (args_has(args, 'P')) {
-               paneidx = window_pane_index(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/trunk/format.c b/trunk/format.c
index 3acfc3f..0897c95 100644
--- a/trunk/format.c
+++ b/trunk/format.c
@@ -324,7 +324,7 @@ format_window_pane(struct format_tree *ft, struct 
window_pane *wp)
        struct grid             *gd = wp->base.grid;
        struct grid_line        *gl;
        unsigned long long       size;
-       u_int                    i;
+       u_int                    i, idx;
 
        size = 0;
        for (i = 0; i < gd->hsize; i++) {
@@ -334,9 +334,12 @@ format_window_pane(struct format_tree *ft, struct 
window_pane *wp)
        }
        size += gd->hsize * sizeof *gd->linedata;
 
+       if (window_pane_index(wp, &idx) != 0)
+               fatalx("index not found");
+
        format_add(ft, "pane_width", "%u", wp->sx);
        format_add(ft, "pane_height", "%u", wp->sy);
-       format_add(ft, "pane_index", "%u", window_pane_index(wp));
+       format_add(ft, "pane_index", "%u", idx);
        format_add(ft, "pane_title", "%s", wp->base.title);
        format_add(ft, "history_size", "%u", gd->hsize);
        format_add(ft, "history_limit", "%u", gd->hlimit);
diff --git a/trunk/screen-redraw.c b/trunk/screen-redraw.c
index 4ff176e..c9e0542 100644
--- a/trunk/screen-redraw.c
+++ b/trunk/screen-redraw.c
@@ -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(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/trunk/status.c b/trunk/status.c
index 6be1b7e..349e724 100644
--- a/trunk/status.c
+++ b/trunk/status.c
@@ -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(wp));
+                   tmp, sizeof tmp, "%u", idx);
                ptr = tmp;
                goto do_replace;
        case 'S':
diff --git a/trunk/tmux.h b/trunk/tmux.h
index 19b5118..7a85e36 100644
--- a/trunk/tmux.h
+++ b/trunk/tmux.h
@@ -1923,7 +1923,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_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/trunk/window.c b/trunk/window.c
index 3a54ca0..68aaacc 100644
--- a/trunk/window.c
+++ b/trunk/window.c
@@ -483,31 +483,22 @@ window_pane_previous_by_number(struct window *w, struct 
window_pane *wp,
        return (wp);
 }
 
-u_int
-window_pane_index(struct window_pane *wp)
+int
+window_pane_index(struct window_pane *wp, u_int *i)
 {
        struct window           *w = wp->window;
        struct window_pane      *wq;
-       u_int                    n;
        int                      found;
 
-       n = options_get_number(&w->options, "pane-base-index");
-       found = 0;
+       *i = options_get_number(&w->options, "pane-base-index");
        TAILQ_FOREACH(wq, &w->panes, entry) {
                if (wp == wq) {
-                       found = 1;
-                       break;
+                       return (0);
                }
-               n++;
-       }
-
-       if (!found) {
-               if (debug_level > 0)
-                       log_warnx("could not find pane in window");
-               n = (u_int)(-1);
+               (*i)++;
        }
 
-       return (n);
+       return (-1);
 }
 
 u_int
-- 
1.7.6.4

Attachment: pgpvwIzI9zSzR.pgp
Description: PGP signature

------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Ciosco Self-Assessment and learn 
about Cisco certifications, training, and career opportunities. 
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to