diff options
author | 2009-08-13 20:11:58 +0000 | |
---|---|---|
committer | 2009-08-13 20:11:58 +0000 | |
commit | bc7e6300cef0ad56396dc4a0373a476cfe3d7ea2 (patch) | |
tree | 41fc950709cece1cebfe45b179e44300f4676463 /usr.bin/tmux/window.c | |
parent | fix ID string; from Alan R. S. Bueno (diff) | |
download | wireguard-openbsd-bc7e6300cef0ad56396dc4a0373a476cfe3d7ea2.tar.xz wireguard-openbsd-bc7e6300cef0ad56396dc4a0373a476cfe3d7ea2.zip |
Add a base-index session option to specify the first index checked when looking
for an index for a new window.
Diffstat (limited to 'usr.bin/tmux/window.c')
-rw-r--r-- | usr.bin/tmux/window.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index d163dbb0c4b..e6809ebea7f 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.21 2009/08/13 19:04:00 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.22 2009/08/13 20:11:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -122,16 +122,20 @@ winlink_find_by_index(struct winlinks *wwl, int idx) } int -winlink_next_index(struct winlinks *wwl) +winlink_next_index(struct winlinks *wwl, int idx) { - u_int i; + int i; - for (i = 0; i < INT_MAX; i++) { + i = idx; + do { if (winlink_find_by_index(wwl, i) == NULL) return (i); - } - - fatalx("no free indexes"); + if (i == INT_MAX) + i = 0; + else + i++; + } while (i != idx); + return (-1); } u_int @@ -152,14 +156,12 @@ winlink_add(struct winlinks *wwl, struct window *w, int idx) { struct winlink *wl; - if (idx == -1) - idx = winlink_next_index(wwl); - else if (winlink_find_by_index(wwl, idx) != NULL) + if (idx < 0) { + if ((idx = winlink_next_index(wwl, -idx - 1)) == -1) + return (NULL); + } else if (winlink_find_by_index(wwl, idx) != NULL) return (NULL); - if (idx < 0) - fatalx("bad index"); - wl = xcalloc(1, sizeof *wl); wl->idx = idx; wl->window = w; |