/* vi:set ts=8 sts=4 sw=4 noet:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* evalwindow.c: Window related builtin functions
*/
#include "vim.h"
#if defined(FEAT_EVAL) || defined(PROTO)
static int
win_getid(typval_T *argvars)
{
int winnr;
win_T *wp;
if (argvars[0].v_type == VAR_UNKNOWN)
return curwin->w_id;
winnr = tv_get_number(&argvars[0]);
if (winnr > 0)
{
if (argvars[1].v_type == VAR_UNKNOWN)
wp = firstwin;
else
{
tabpage_T *tp;
int tabnr = tv_get_number(&argvars[1]);
FOR_ALL_TABPAGES(tp)
if (--tabnr == 0)
break;
if (tp == NULL)
return -1;
if (tp == curtab)
wp = firstwin;
else
wp = tp->tp_firstwin;
}
for ( ; wp != NULL; wp = wp->w_next)
if (--winnr == 0)
return wp->w_id;
}
return 0;
}
static void
win_id2tabwin(typval_T *argvars, list_T *list)
{
win_T *wp;
tabpage_T *tp;
int winnr = 1;
int tabnr = 1;
int id = tv_get_number(&argvars[0]);
FOR_ALL_TABPAGES(tp)
{
FOR_ALL_WINDOWS_IN_TAB(tp, wp)
{
if (wp->w_id == id)
{
list_append_number(list, tabnr);
list_append_number(list, winnr);
return;
}
++winnr;
}
++tabnr;
winnr = 1;
}
list_append_number(list, 0);
list_append_number(list, 0