Add a base-index session option to specify the first index checked when looking

for an index for a new window.
This commit is contained in:
Nicholas Marriott
2009-08-13 20:11:58 +00:00
parent 3026118c70
commit 3ad4de6c8c
11 changed files with 40 additions and 20 deletions

View File

@ -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;