/* 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
/*
* Clear an argument list: free all file names and reset it to zero entries.
*/
void
alist_clear(alist_T *al)
{
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;
++global_alist.al_refcount;
}
else
{
curwin->w_alist->al_refcount = 1;
curwin->w_alist->id = ++max_alist_id;
alist_init(curwin->w_alist);
}
}
#if !defined(UNIX) || defined(PROTO)
/*
* Expand the file names in the global argument list.
* If "fnum_list" is not NULL, use "fnum_list[fnum_len]" as a list of buffer
* numbers to be re-used.
*/
void
alist_expand(int *fnum_list, int fnum_len)
{
char_u **old_arg_files;
int old_arg_count;
char_u **new_arg_files;
int new_arg_file_count;
char_u *save_p_su = p_su;
int i;
// Don't use 'suffixes' here. This should work like the shell did the
// expansion. Also, the vimrc file isn't read yet, thus the user
// can't set the options.
p_su = empty_option;
old_arg_files = ALLOC_MULT(char_u *, GARGCOUNT);
if (old_arg_files != NULL)
{
for (i = 0; i < GARGCOUNT; ++i)
old_arg_files[i] = vim_strsave(GARGLIST[i].ae_fname);
old_arg_count =<