forked from aniani/vim
patch 8.1.1869: code for the argument list is spread out
Problem: Code for the argument list is spread out. Solution: Put argument list code in arglist.c. (Yegappan Lakshmanan, closes #4819)
This commit is contained in:
277
src/ex_docmd.c
277
src/ex_docmd.c
@@ -304,7 +304,6 @@ static void ex_tag_cmd(exarg_T *eap, char_u *name);
|
||||
# define ex_unlockvar ex_ni
|
||||
# define ex_while ex_ni
|
||||
#endif
|
||||
static char_u *arg_all(void);
|
||||
#ifndef FEAT_SESSION
|
||||
# define ex_loadview ex_ni
|
||||
#endif
|
||||
@@ -6137,18 +6136,6 @@ ex_only(exarg_T *eap)
|
||||
close_others(TRUE, eap->forceit);
|
||||
}
|
||||
|
||||
/*
|
||||
* ":all" and ":sall".
|
||||
* Also used for ":tab drop file ..." after setting the argument list.
|
||||
*/
|
||||
void
|
||||
ex_all(exarg_T *eap)
|
||||
{
|
||||
if (eap->addr_count == 0)
|
||||
eap->line2 = 9999;
|
||||
do_arg_all((int)eap->line2, eap->forceit, eap->cmdidx == CMD_drop);
|
||||
}
|
||||
|
||||
static void
|
||||
ex_hide(exarg_T *eap UNUSED)
|
||||
{
|
||||
@@ -6444,200 +6431,6 @@ handle_any_postponed_drop(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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 = GARGCOUNT;
|
||||
if (expand_wildcards(old_arg_count, old_arg_files,
|
||||
&new_arg_file_count, &new_arg_files,
|
||||
EW_FILE|EW_NOTFOUND|EW_ADDSLASH|EW_NOERROR) == OK
|
||||
&& new_arg_file_count > 0)
|
||||
{
|
||||
alist_set(&global_alist, new_arg_file_count, new_arg_files,
|
||||
TRUE, fnum_list, fnum_len);
|
||||
FreeWild(old_arg_count, old_arg_files);
|
||||
}
|
||||
}
|
||||
p_su = save_p_su;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Set the argument list for the current window.
|
||||
* Takes over the allocated files[] and the allocated fnames in it.
|
||||
*/
|
||||
void
|
||||
alist_set(
|
||||
alist_T *al,
|
||||
int count,
|
||||
char_u **files,
|
||||
int use_curbuf,
|
||||
int *fnum_list,
|
||||
int fnum_len)
|
||||
{
|
||||
int i;
|
||||
static int recursive = 0;
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
emsg(_(e_au_recursive));
|
||||
return;
|
||||
}
|
||||
++recursive;
|
||||
|
||||
alist_clear(al);
|
||||
if (ga_grow(&al->al_ga, count) == OK)
|
||||
{
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
if (got_int)
|
||||
{
|
||||
/* When adding many buffers this can take a long time. Allow
|
||||
* interrupting here. */
|
||||
while (i < count)
|
||||
vim_free(files[i++]);
|
||||
break;
|
||||
}
|
||||
|
||||
/* May set buffer name of a buffer previously used for the
|
||||
* argument list, so that it's re-used by alist_add. */
|
||||
if (fnum_list != NULL && i < fnum_len)
|
||||
buf_set_name(fnum_list[i], files[i]);
|
||||
|
||||
alist_add(al, files[i], use_curbuf ? 2 : 1);
|
||||
ui_breakcheck();
|
||||
}
|
||||
vim_free(files);
|
||||
}
|
||||
else
|
||||
FreeWild(count, files);
|
||||
if (al == &global_alist)
|
||||
arg_had_last = FALSE;
|
||||
|
||||
--recursive;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add file "fname" to argument list "al".
|
||||
* "fname" must have been allocated and "al" must have been checked for room.
|
||||
*/
|
||||
void
|
||||
alist_add(
|
||||
alist_T *al,
|
||||
char_u *fname,
|
||||
int set_fnum) /* 1: set buffer number; 2: re-use curbuf */
|
||||
{
|
||||
if (fname == NULL) /* don't add NULL file names */
|
||||
return;
|
||||
#ifdef BACKSLASH_IN_FILENAME
|
||||
slash_adjust(fname);
|
||||
#endif
|
||||
AARGLIST(al)[al->al_ga.ga_len].ae_fname = fname;
|
||||
if (set_fnum > 0)
|
||||
AARGLIST(al)[al->al_ga.ga_len].ae_fnum =
|
||||
buflist_add(fname, BLN_LISTED | (set_fnum == 2 ? BLN_CURBUF : 0));
|
||||
++al->al_ga.ga_len;
|
||||
}
|
||||
|
||||
#if defined(BACKSLASH_IN_FILENAME) || defined(PROTO)
|
||||
/*
|
||||
* Adjust slashes in file names. Called after 'shellslash' was set.
|
||||
*/
|
||||
void
|
||||
alist_slash_adjust(void)
|
||||
{
|
||||
int i;
|
||||
win_T *wp;
|
||||
tabpage_T *tp;
|
||||
|
||||
for (i = 0; i < GARGCOUNT; ++i)
|
||||
if (GARGLIST[i].ae_fname != NULL)
|
||||
slash_adjust(GARGLIST[i].ae_fname);
|
||||
FOR_ALL_TAB_WINDOWS(tp, wp)
|
||||
if (wp->w_alist != &global_alist)
|
||||
for (i = 0; i < WARGCOUNT(wp); ++i)
|
||||
if (WARGLIST(wp)[i].ae_fname != NULL)
|
||||
slash_adjust(WARGLIST(wp)[i].ae_fname);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ":preserve".
|
||||
*/
|
||||
@@ -9284,76 +9077,6 @@ eval_vars(
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Concatenate all files in the argument list, separated by spaces, and return
|
||||
* it in one allocated string.
|
||||
* Spaces and backslashes in the file names are escaped with a backslash.
|
||||
* Returns NULL when out of memory.
|
||||
*/
|
||||
static char_u *
|
||||
arg_all(void)
|
||||
{
|
||||
int len;
|
||||
int idx;
|
||||
char_u *retval = NULL;
|
||||
char_u *p;
|
||||
|
||||
/*
|
||||
* Do this loop two times:
|
||||
* first time: compute the total length
|
||||
* second time: concatenate the names
|
||||
*/
|
||||
for (;;)
|
||||
{
|
||||
len = 0;
|
||||
for (idx = 0; idx < ARGCOUNT; ++idx)
|
||||
{
|
||||
p = alist_name(&ARGLIST[idx]);
|
||||
if (p != NULL)
|
||||
{
|
||||
if (len > 0)
|
||||
{
|
||||
/* insert a space in between names */
|
||||
if (retval != NULL)
|
||||
retval[len] = ' ';
|
||||
++len;
|
||||
}
|
||||
for ( ; *p != NUL; ++p)
|
||||
{
|
||||
if (*p == ' '
|
||||
#ifndef BACKSLASH_IN_FILENAME
|
||||
|| *p == '\\'
|
||||
#endif
|
||||
|| *p == '`')
|
||||
{
|
||||
/* insert a backslash */
|
||||
if (retval != NULL)
|
||||
retval[len] = '\\';
|
||||
++len;
|
||||
}
|
||||
if (retval != NULL)
|
||||
retval[len] = *p;
|
||||
++len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* second time: break here */
|
||||
if (retval != NULL)
|
||||
{
|
||||
retval[len] = NUL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* allocate memory */
|
||||
retval = alloc(len + 1);
|
||||
if (retval == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Expand the <sfile> string in "arg".
|
||||
*
|
||||
|
Reference in New Issue
Block a user