aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_getln.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/ex_getln.c')
-rw-r--r--src/nvim/ex_getln.c147
1 files changed, 67 insertions, 80 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index a6e8ad433f..6240ac6b37 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -4165,8 +4165,7 @@ char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode
compl_selected = findex;
cmdline_pum_display(false);
} else if (p_wmnu) {
- win_redr_status_matches(xp, xp->xp_numfiles, (char_u **)xp->xp_files,
- findex, cmd_showtail);
+ win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files, findex, cmd_showtail);
}
if (findex == -1) {
return vim_strsave(orig_save);
@@ -4186,7 +4185,7 @@ char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode
// free old names
if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) {
- FreeWild(xp->xp_numfiles, (char_u **)xp->xp_files);
+ FreeWild(xp->xp_numfiles, xp->xp_files);
xp->xp_numfiles = -1;
XFREE_CLEAR(orig_save);
}
@@ -4204,8 +4203,7 @@ char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode
/*
* Do the expansion.
*/
- if (ExpandFromContext(xp, str, &xp->xp_numfiles, (char_u ***)&xp->xp_files,
- options) == FAIL) {
+ if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, options) == FAIL) {
#ifdef FNAME_ILLEGAL
/* Illegal file name has been silently skipped. But when there
* are wildcards, the real problem is that there was no match,
@@ -4221,7 +4219,7 @@ char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode
}
} else {
// Escape the matches for use on the command line.
- ExpandEscape(xp, str, xp->xp_numfiles, (char_u **)xp->xp_files, options);
+ ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options);
/*
* Check for matching suffixes in file names.
@@ -4346,12 +4344,12 @@ void ExpandInit(expand_T *xp)
void ExpandCleanup(expand_T *xp)
{
if (xp->xp_numfiles >= 0) {
- FreeWild(xp->xp_numfiles, (char_u **)xp->xp_files);
+ FreeWild(xp->xp_numfiles, xp->xp_files);
xp->xp_numfiles = -1;
}
}
-void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int options)
+void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char **files, int options)
{
int i;
char_u *p;
@@ -4377,9 +4375,9 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
for (i = 0; i < numfiles; ++i) {
// for ":set path=" we need to escape spaces twice
if (xp->xp_backslash == XP_BS_THREE) {
- p = vim_strsave_escaped(files[i], (char_u *)" ");
+ p = vim_strsave_escaped((char_u *)files[i], (char_u *)" ");
xfree(files[i]);
- files[i] = p;
+ files[i] = (char *)p;
#if defined(BACKSLASH_IN_FILENAME)
p = vim_strsave_escaped(files[i], (char_u *)" ");
xfree(files[i]);
@@ -4393,7 +4391,7 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
xp->xp_shell ? VSE_SHELL : vse_what);
#endif
xfree(files[i]);
- files[i] = p;
+ files[i] = (char *)p;
/* If 'str' starts with "\~", replace "~" at start of
* files[i] with "\~". */
@@ -4413,10 +4411,10 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
* Insert a backslash before characters in a tag name that
* would terminate the ":tag" command.
*/
- for (i = 0; i < numfiles; ++i) {
- p = vim_strsave_escaped(files[i], (char_u *)"\\|\"");
+ for (i = 0; i < numfiles; i++) {
+ p = vim_strsave_escaped((char_u *)files[i], (char_u *)"\\|\"");
xfree(files[i]);
- files[i] = p;
+ files[i] = (char *)p;
}
}
}
@@ -4472,7 +4470,7 @@ char *vim_strsave_fnameescape(const char *const fname, const int what)
// '>' and '+' are special at the start of some commands, e.g. ":edit" and
// ":write". "cd -" has a special meaning.
if (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL)) {
- escape_fname((char_u **)&p);
+ escape_fname(&p);
}
return p;
@@ -4481,28 +4479,26 @@ char *vim_strsave_fnameescape(const char *const fname, const int what)
/*
* Put a backslash before the file name in "pp", which is in allocated memory.
*/
-static void escape_fname(char_u **pp)
+static void escape_fname(char **pp)
{
char_u *p = xmalloc(STRLEN(*pp) + 2);
p[0] = '\\';
STRCPY(p + 1, *pp);
xfree(*pp);
- *pp = p;
+ *pp = (char *)p;
}
-/*
- * For each file name in files[num_files]:
- * If 'orig_pat' starts with "~/", replace the home directory with "~".
- */
-void tilde_replace(char_u *orig_pat, int num_files, char_u **files)
+/// For each file name in files[num_files]:
+/// If 'orig_pat' starts with "~/", replace the home directory with "~".
+void tilde_replace(char_u *orig_pat, int num_files, char **files)
{
char *p;
if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) {
for (int i = 0; i < num_files; i++) {
- p = home_replace_save(NULL, (char *)files[i]);
+ p = home_replace_save(NULL, files[i]);
xfree(files[i]);
- files[i] = (char_u *)p;
+ files[i] = p;
}
}
}
@@ -4523,7 +4519,7 @@ static int showmatches(expand_T *xp, int wildmenu)
#define L_SHOWFILE(m) (showtail \
? sm_gettail(files_found[m], false) : files_found[m])
int num_files;
- char_u **files_found;
+ char **files_found;
int i, j, k;
int maxlen;
int lines;
@@ -4543,7 +4539,7 @@ static int showmatches(expand_T *xp, int wildmenu)
}
} else {
num_files = xp->xp_numfiles;
- files_found = (char_u **)xp->xp_files;
+ files_found = xp->xp_files;
showtail = cmd_showtail;
}
@@ -4558,10 +4554,9 @@ static int showmatches(expand_T *xp, int wildmenu)
compl_match_array = xcalloc((size_t)compl_match_arraysize,
sizeof(pumitem_T));
for (i = 0; i < num_files; i++) {
- compl_match_array[i].pum_text = L_SHOWFILE(i);
+ compl_match_array[i].pum_text = (char_u *)L_SHOWFILE(i);
}
- char_u *endpos = (showtail
- ? sm_gettail((char_u *)xp->xp_pattern, true) : (char_u *)xp->xp_pattern);
+ char_u *endpos = (char_u *)(showtail ? sm_gettail(xp->xp_pattern, true) : xp->xp_pattern);
if (ui_has(kUICmdline)) {
compl_startcol = (int)(endpos - ccline.cmdbuff);
} else {
@@ -4593,10 +4588,10 @@ static int showmatches(expand_T *xp, int wildmenu)
if (!showtail && (xp->xp_context == EXPAND_FILES
|| xp->xp_context == EXPAND_SHELLCMD
|| xp->xp_context == EXPAND_BUFFERS)) {
- home_replace(NULL, (char *)files_found[i], (char *)NameBuff, MAXPATHL, true);
+ home_replace(NULL, files_found[i], (char *)NameBuff, MAXPATHL, true);
j = vim_strsize((char *)NameBuff);
} else {
- j = vim_strsize((char *)L_SHOWFILE(i));
+ j = vim_strsize(L_SHOWFILE(i));
}
if (j > maxlen) {
maxlen = j;
@@ -4629,8 +4624,8 @@ static int showmatches(expand_T *xp, int wildmenu)
lastlen = 999;
for (k = i; k < num_files; k += lines) {
if (xp->xp_context == EXPAND_TAGS_LISTFILES) {
- msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D));
- p = files_found[k] + STRLEN(files_found[k]) + 1;
+ msg_outtrans_attr((char_u *)files_found[k], HL_ATTR(HLF_D));
+ p = (char_u *)files_found[k] + STRLEN(files_found[k]) + 1;
msg_advance(maxlen + 1);
msg_puts((const char *)p);
msg_advance(maxlen + 3);
@@ -4648,8 +4643,8 @@ static int showmatches(expand_T *xp, int wildmenu)
// Expansion was done before and special characters
// were escaped, need to halve backslashes. Also
// $HOME has been replaced with ~/.
- char_u *exp_path = expand_env_save_opt(files_found[k], true);
- char_u *path = exp_path != NULL ? exp_path : files_found[k];
+ char_u *exp_path = expand_env_save_opt((char_u *)files_found[k], true);
+ char_u *path = exp_path != NULL ? exp_path : (char_u *)files_found[k];
char_u *halved_slash = backslash_halve_save(path);
j = os_isdir(halved_slash);
xfree(exp_path);
@@ -4658,17 +4653,17 @@ static int showmatches(expand_T *xp, int wildmenu)
}
} else {
// Expansion was done here, file names are literal.
- j = os_isdir(files_found[k]);
+ j = os_isdir((char_u *)files_found[k]);
}
if (showtail) {
- p = L_SHOWFILE(k);
+ p = (char_u *)L_SHOWFILE(k);
} else {
- home_replace(NULL, (char *)files_found[k], (char *)NameBuff, MAXPATHL, true);
+ home_replace(NULL, files_found[k], (char *)NameBuff, MAXPATHL, true);
p = NameBuff;
}
} else {
- j = FALSE;
- p = L_SHOWFILE(k);
+ j = false;
+ p = (char_u *)L_SHOWFILE(k);
}
lastlen = msg_outtrans_attr(p, j ? attr : 0);
}
@@ -4697,17 +4692,15 @@ static int showmatches(expand_T *xp, int wildmenu)
return EXPAND_OK;
}
-/*
- * Private path_tail for showmatches() (and win_redr_status_matches()):
- * Find tail of file name path, but ignore trailing "/".
- */
-char_u *sm_gettail(char_u *s, bool eager)
+/// Private path_tail for showmatches() (and win_redr_status_matches()):
+/// Find tail of file name path, but ignore trailing "/".
+char *sm_gettail(char *s, bool eager)
{
char_u *p;
- char_u *t = s;
- int had_sep = FALSE;
+ char_u *t = (char_u *)s;
+ int had_sep = false;
- for (p = s; *p != NUL;) {
+ for (p = (char_u *)s; *p != NUL;) {
if (vim_ispathsep(*p)
#ifdef BACKSLASH_IN_FILENAME
&& !rem_backslash(p)
@@ -4724,7 +4717,7 @@ char_u *sm_gettail(char_u *s, bool eager)
}
MB_PTR_ADV(p);
}
- return t;
+ return (char *)t;
}
/*
@@ -5002,7 +4995,7 @@ void set_cmd_context(expand_T *xp, char_u *str, int len, int col, int use_ccline
/// @param col position of cursor
/// @param matchcount return: nr of matches
/// @param matches return: array of pointers to matches
-int expand_cmdline(expand_T *xp, char_u *str, int col, int *matchcount, char_u ***matches)
+int expand_cmdline(expand_T *xp, char_u *str, int col, int *matchcount, char ***matches)
{
char_u *file_str = NULL;
int options = WILD_ADD_SLASH|WILD_SILENT;
@@ -5038,7 +5031,7 @@ int expand_cmdline(expand_T *xp, char_u *str, int col, int *matchcount, char_u *
// Cleanup matches for help tags:
// Remove "@ab" if the top of 'helplang' is "ab" and the language of the first
// tag matches it. Otherwise remove "@en" if "en" is the only language.
-static void cleanup_help_tags(int num_file, char_u **file)
+static void cleanup_help_tags(int num_file, char **file)
{
char_u buf[4];
char_u *p = buf;
@@ -5092,7 +5085,7 @@ typedef char *(*ExpandFunc)(expand_T *, int);
/// Do the expansion based on xp->xp_context and "pat".
///
/// @param options WILD_ flags
-static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char_u ***file, int options)
+static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char ***file, int options)
{
regmatch_T regmatch;
int ret;
@@ -5187,7 +5180,7 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char_u **
/* With an empty argument we would get all the help tags, which is
* very slow. Get matches for "help" instead. */
if (find_help_tags(*pat == NUL ? "help" : (char *)pat,
- num_file, (char ***)file, false) == OK) {
+ num_file, file, false) == OK) {
cleanup_help_tags(*num_file, *file);
return OK;
}
@@ -5204,10 +5197,10 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char_u **
return OK;
}
if (xp->xp_context == EXPAND_BUFFERS) {
- return ExpandBufnames((char *)pat, num_file, (char ***)file, options);
+ return ExpandBufnames((char *)pat, num_file, file, options);
}
if (xp->xp_context == EXPAND_DIFF_BUFFERS) {
- return ExpandBufnames((char *)pat, num_file, (char ***)file, options | BUF_DIFF_FILTER);
+ return ExpandBufnames((char *)pat, num_file, file, options | BUF_DIFF_FILTER);
}
if (xp->xp_context == EXPAND_TAGS
|| xp->xp_context == EXPAND_TAGS_LISTFILES) {
@@ -5215,8 +5208,7 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char_u **
}
if (xp->xp_context == EXPAND_COLORS) {
char *directories[] = { "colors", NULL };
- return ExpandRTDir(pat, DIP_START + DIP_OPT + DIP_LUA, num_file, file,
- directories);
+ return ExpandRTDir(pat, DIP_START + DIP_OPT + DIP_LUA, num_file, file, directories);
}
if (xp->xp_context == EXPAND_COMPILER) {
char *directories[] = { "compiler", NULL };
@@ -5323,8 +5315,7 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char_u **
if (tab[i].ic) {
regmatch.rm_ic = TRUE;
}
- ExpandGeneric(xp, &regmatch, num_file, file, tab[i].func,
- tab[i].escaped);
+ ExpandGeneric(xp, &regmatch, num_file, file, tab[i].func, tab[i].escaped);
ret = OK;
break;
}
@@ -5344,7 +5335,7 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char_u **
/// program. Matching strings are copied into an array, which is returned.
///
/// @param func returns a string from the list
-static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file,
+static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***file,
CompleteListItemGetter func, int escaped)
{
int i;
@@ -5369,7 +5360,7 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, cha
}
assert(count < INT_MAX);
*num_file = (int)count;
- *file = (char_u **)xmalloc(count * sizeof(char_u *));
+ *file = xmalloc(count * sizeof(char_u *));
// copy the matching names into allocated memory
count = 0;
@@ -5387,7 +5378,7 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, cha
} else {
str = vim_strsave(str);
}
- (*file)[count++] = str;
+ (*file)[count++] = (char *)str;
if (func == get_menu_names) {
// Test for separator added by get_menu_names().
str += STRLEN(str) - 1;
@@ -5424,14 +5415,14 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, cha
/// *file will either be set to NULL or point to
/// allocated memory.
/// @param flagsarg is a combination of EW_* flags.
-static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg)
+static void expand_shellcmd(char_u *filepat, int *num_file, char ***file, int flagsarg)
FUNC_ATTR_NONNULL_ALL
{
char_u *pat;
int i;
char_u *path = NULL;
garray_T ga;
- char_u *buf = xmalloc(MAXPATHL);
+ char *buf = xmalloc(MAXPATHL);
size_t l;
char_u *s, *e;
int flags = flagsarg;
@@ -5498,7 +5489,7 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int
break;
}
STRLCPY(buf, s, l + 1);
- add_pathsep((char *)buf);
+ add_pathsep(buf);
l = STRLEN(buf);
STRLCPY(buf + l, pat, MAXPATHL - l);
@@ -5508,7 +5499,7 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int
ga_grow(&ga, *num_file);
{
for (i = 0; i < *num_file; i++) {
- char_u *name = (*file)[i];
+ char_u *name = (char_u *)(*file)[i];
if (STRLEN(name) > l) {
// Check if this name was already found.
@@ -5547,7 +5538,7 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int
/// Call "user_expand_func()" to invoke a user defined Vim script function and
/// return the result (either a string, a List or NULL).
static void *call_user_expand_func(user_expand_func_T user_expand_func, expand_T *xp, int *num_file,
- char_u ***file)
+ char ***file)
FUNC_ATTR_NONNULL_ALL
{
char_u keep = 0;
@@ -5588,10 +5579,8 @@ static void *call_user_expand_func(user_expand_func_T user_expand_func, expand_T
return ret;
}
-/*
- * Expand names with a function defined by the user.
- */
-static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file)
+/// Expand names with a function defined by the user.
+static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***file)
{
char_u *e;
garray_T ga;
@@ -5629,10 +5618,8 @@ static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file,
return OK;
}
-/*
- * Expand names with a list returned by a function defined by the user.
- */
-static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file)
+/// Expand names with a list returned by a function defined by the user.
+static int ExpandUserList(expand_T *xp, int *num_file, char ***file)
{
list_T *const retlist = call_user_expand_func((user_expand_func_T)call_func_retlist, xp, num_file,
file);
@@ -5658,7 +5645,7 @@ static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file)
return OK;
}
-static int ExpandUserLua(expand_T *xp, int *num_file, char_u ***file)
+static int ExpandUserLua(expand_T *xp, int *num_file, char ***file)
{
typval_T rettv;
nlua_call_user_expand_func(xp, &rettv);
@@ -5696,7 +5683,7 @@ static int ExpandUserLua(expand_T *xp, int *num_file, char_u ***file)
/// 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim
/// When "flags" has DIP_LUA: search also performed for .lua files
/// "dirnames" is an array with one or more directory names.
-static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirnames[])
+static int ExpandRTDir(char_u *pat, int flags, int *num_file, char ***file, char *dirnames[])
{
*num_file = 0;
*file = NULL;
@@ -5805,7 +5792,7 @@ static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, ch
/// Expand loadplugin names:
/// 'packpath'/pack/ * /opt/{pat}
-static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file)
+static int ExpandPackAddDir(char_u *pat, int *num_file, char ***file)
{
garray_T ga;
@@ -5859,7 +5846,7 @@ void globpath(char_u *path, char_u *file, garray_T *ga, int expand_options)
add_pathsep((char *)buf);
STRCAT(buf, file); // NOLINT
- char_u **p;
+ char **p;
int num_p = 0;
(void)ExpandFromContext(&xpc, buf, &num_p, &p,
WILD_SILENT | expand_options);
@@ -5870,7 +5857,7 @@ void globpath(char_u *path, char_u *file, garray_T *ga, int expand_options)
ga_grow(ga, num_p);
// take over the pointers and put them in "ga"
for (int i = 0; i < num_p; i++) {
- ((char_u **)ga->ga_data)[ga->ga_len] = p[i];
+ ((char_u **)ga->ga_data)[ga->ga_len] = (char_u *)p[i];
ga->ga_len++;
}
xfree(p);