/* 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.
*/
/*
* arglist.c: functions for dealing with the argument list
*/
#include "vim.h"
#define AL_SET 1
#define AL_ADD 2
#define AL_DEL 3
// This flag is set whenever the argument list is being changed and calling a
// function that might trigger an autocommand.
static int arglist_locked = FALSE;
static int
check_arglist_locked(void)
{
if (arglist_locked)
{
emsg(_(e_cannot_change_arglist_recursively));
return FAIL;
}
return OK;
}
/*
* Clear an argument list: free all file names and reset it to zero entries.
*/
void
alist_clear(alist_T *al)
{
if (check_arglist_locked() == FAIL)
return;
while (--al->al_ga.ga_len >= 0)
vim_free(AARGLIST(al)[al->al_ga.ga_len].ae_fname);
ga_clear(&al->al_ga);
}
/*
* Init an argument list.
*/
void
alist_init(alist_T *al)
{
ga_init2(&al->al_ga, (int)sizeof(aentry_T), 5);
}
/*
* Remove a reference from an argument list.
* Ignored when the argument list is the global one.
* If the argument list is no longer used by any window, free it.
*/
void
alist_unlink(alist_T *al)
{
if (al != &global_alist && --al->al_refcount <= 0)
{
alist_clear(al);
vim_free(al);
}
}
/*
* Create a new argument list and use it for the current window.
*/
void
alist_new(void)
{
curwin->w_alist = ALLOC_ONE(alist_T);
if (curwin->w_alist == NULL)
{
curwin->w_alist = &global_alist;