refactor: replace char_u with char

Work on https://github.com/neovim/neovim/issues/459
This commit is contained in:
Dundar Göc
2022-08-26 23:11:25 +02:00
committed by dundargoc
parent 48ca1d4ce8
commit 49e893f296
49 changed files with 742 additions and 776 deletions

View File

@@ -177,7 +177,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape)
ui_flush();
}
i = (int)((char_u *)xp->xp_pattern - ccline->cmdbuff);
i = (int)(xp->xp_pattern - ccline->cmdbuff);
assert(ccline->cmdpos >= i);
xp->xp_pattern_len = (size_t)ccline->cmdpos - (size_t)i;
@@ -186,20 +186,20 @@ int nextwild(expand_T *xp, int type, int options, bool escape)
p2 = ExpandOne(xp, NULL, NULL, 0, type);
} else {
// Translate string into pattern and expand it.
p1 = addstar((char_u *)xp->xp_pattern, xp->xp_pattern_len, xp->xp_context);
p1 = (char_u *)addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context);
const int use_options = (options
| WILD_HOME_REPLACE
| WILD_ADD_SLASH
| WILD_SILENT
| (escape ? WILD_ESCAPE : 0)
| (p_wic ? WILD_ICASE : 0));
p2 = ExpandOne(xp, p1, vim_strnsave(&ccline->cmdbuff[i], xp->xp_pattern_len),
p2 = ExpandOne(xp, p1, (char_u *)xstrnsave(&ccline->cmdbuff[i], xp->xp_pattern_len),
use_options, type);
xfree(p1);
// xp->xp_pattern might have been modified by ExpandOne (for example,
// in lua completion), so recompute the pattern index and length
i = (int)((char_u *)xp->xp_pattern - ccline->cmdbuff);
i = (int)(xp->xp_pattern - ccline->cmdbuff);
xp->xp_pattern_len = (size_t)ccline->cmdpos - (size_t)i;
// Longest match: make sure it is not shorter, happens with :help.
@@ -220,7 +220,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape)
difflen = (int)STRLEN(p2) - (int)(xp->xp_pattern_len);
if (ccline->cmdlen + difflen + 4 > ccline->cmdbufflen) {
realloc_cmdbuff(ccline->cmdlen + difflen + 4);
xp->xp_pattern = (char *)ccline->cmdbuff + i;
xp->xp_pattern = ccline->cmdbuff + i;
}
assert(ccline->cmdpos <= ccline->cmdlen);
memmove(&ccline->cmdbuff[ccline->cmdpos + difflen],
@@ -573,7 +573,7 @@ int showmatches(expand_T *xp, int wildmenu)
if (xp->xp_numfiles == -1) {
set_expand_context(xp);
i = expand_cmdline(xp, ccline->cmdbuff, ccline->cmdpos,
i = expand_cmdline(xp, (char_u *)ccline->cmdbuff, ccline->cmdpos,
&num_files, &files_found);
showtail = expand_showtail(xp);
if (i != EXPAND_OK) {
@@ -602,7 +602,7 @@ int showmatches(expand_T *xp, int wildmenu)
.pum_kind = NULL,
};
}
char_u *endpos = (char_u *)(showtail ? sm_gettail(xp->xp_pattern, true) : xp->xp_pattern);
char *endpos = (showtail ? sm_gettail(xp->xp_pattern, true) : xp->xp_pattern);
if (ui_has(kUICmdline)) {
compl_startcol = (int)(endpos - ccline->cmdbuff);
} else {
@@ -803,13 +803,13 @@ static bool expand_showtail(expand_T *xp)
/// the name into allocated memory and prepend "^".
///
/// @param context EXPAND_FILES etc.
char_u *addstar(char_u *fname, size_t len, int context)
char *addstar(char *fname, size_t len, int context)
FUNC_ATTR_NONNULL_RET
{
char_u *retval;
char *retval;
size_t i, j;
size_t new_len;
char_u *tail;
char *tail;
int ends_in_star;
if (context != EXPAND_FILES
@@ -831,7 +831,7 @@ char_u *addstar(char_u *fname, size_t len, int context)
|| context == EXPAND_PACKADD
|| ((context == EXPAND_TAGS_LISTFILES || context == EXPAND_TAGS)
&& fname[0] == '/')) {
retval = vim_strnsave(fname, len);
retval = xstrnsave(fname, len);
} else {
new_len = len + 2; // +2 for '^' at start, NUL at end
for (i = 0; i < len; i++) {
@@ -901,7 +901,7 @@ char_u *addstar(char_u *fname, size_t len, int context)
// $ could be anywhere in the tail.
// ` could be anywhere in the file name.
// When the name ends in '$' don't add a star, remove the '$'.
tail = (char_u *)path_tail((char *)retval);
tail = path_tail(retval);
ends_in_star = (len > 0 && retval[len - 1] == '*');
#ifndef BACKSLASH_IN_FILENAME
for (ssize_t k = (ssize_t)len - 2; k >= 0; k--) {
@@ -913,8 +913,8 @@ char_u *addstar(char_u *fname, size_t len, int context)
#endif
if ((*retval != '~' || tail != retval)
&& !ends_in_star
&& vim_strchr((char *)tail, '$') == NULL
&& vim_strchr((char *)retval, '`') == NULL) {
&& vim_strchr(tail, '$') == NULL
&& vim_strchr(retval, '`') == NULL) {
retval[len++] = '*';
} else if (len > 0 && retval[len - 1] == '$') {
len--;
@@ -976,7 +976,7 @@ void set_expand_context(expand_T *xp)
xp->xp_context = EXPAND_NOTHING;
return;
}
set_cmd_context(xp, ccline->cmdbuff, ccline->cmdlen, ccline->cmdpos, true);
set_cmd_context(xp, (char_u *)ccline->cmdbuff, ccline->cmdlen, ccline->cmdpos, true);
}
/// Sets the index of a built-in or user defined command "cmd" in eap->cmdidx.
@@ -1850,7 +1850,7 @@ void set_cmd_context(expand_T *xp, char_u *str, int len, int col, int use_ccline
set_context_for_expression(xp, (char *)str, CMD_SIZE);
} else if (use_ccline && ccline->input_fn) {
xp->xp_context = ccline->xp_context;
xp->xp_pattern = (char *)ccline->cmdbuff;
xp->xp_pattern = ccline->cmdbuff;
xp->xp_arg = (char *)ccline->xp_arg;
} else {
while (nextcomm != NULL) {
@@ -1897,7 +1897,7 @@ int expand_cmdline(expand_T *xp, char_u *str, int col, int *matchcount, char ***
// add star to file name, or convert to regexp if not exp. files.
assert((str + col) - (char_u *)xp->xp_pattern >= 0);
xp->xp_pattern_len = (size_t)((str + col) - (char_u *)xp->xp_pattern);
file_str = addstar((char_u *)xp->xp_pattern, xp->xp_pattern_len, xp->xp_context);
file_str = (char_u *)addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context);
if (p_wic) {
options += WILD_ICASE;
@@ -2437,9 +2437,9 @@ static void *call_user_expand_func(user_expand_func_T user_expand_func, expand_T
FUNC_ATTR_NONNULL_ALL
{
CmdlineInfo *const ccline = get_cmdline_info();
char_u keep = 0;
char keep = 0;
typval_T args[4];
char_u *pat = NULL;
char *pat = NULL;
const sctx_T save_current_sctx = current_sctx;
if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) {
@@ -2453,12 +2453,12 @@ static void *call_user_expand_func(user_expand_func_T user_expand_func, expand_T
ccline->cmdbuff[ccline->cmdlen] = 0;
}
pat = vim_strnsave((char_u *)xp->xp_pattern, xp->xp_pattern_len);
pat = xstrnsave(xp->xp_pattern, xp->xp_pattern_len);
args[0].v_type = VAR_STRING;
args[1].v_type = VAR_STRING;
args[2].v_type = VAR_NUMBER;
args[3].v_type = VAR_UNKNOWN;
args[0].vval.v_string = (char *)pat;
args[0].vval.v_string = pat;
args[1].vval.v_string = xp->xp_line;
args[2].vval.v_number = xp->xp_col;
@@ -2478,30 +2478,29 @@ static void *call_user_expand_func(user_expand_func_T user_expand_func, expand_T
/// 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;
char *e;
garray_T ga;
char_u *const retstr = call_user_expand_func((user_expand_func_T)call_func_retstr, xp, num_file,
file);
char *const retstr = call_user_expand_func((user_expand_func_T)call_func_retstr, xp, num_file,
file);
if (retstr == NULL) {
return FAIL;
}
ga_init(&ga, (int)sizeof(char *), 3);
for (char_u *s = retstr; *s != NUL; s = e) {
e = (char_u *)vim_strchr((char *)s, '\n');
for (char *s = retstr; *s != NUL; s = e) {
e = vim_strchr(s, '\n');
if (e == NULL) {
e = s + STRLEN(s);
}
const char_u keep = *e;
const char keep = *e;
*e = NUL;
const bool skip = xp->xp_pattern[0]
&& vim_regexec(regmatch, (char *)s, (colnr_T)0) == 0;
const bool skip = xp->xp_pattern[0] && vim_regexec(regmatch, s, (colnr_T)0) == 0;
*e = keep;
if (!skip) {
GA_APPEND(char_u *, &ga, vim_strnsave(s, (size_t)(e - s)));
GA_APPEND(char *, &ga, xstrnsave(s, (size_t)(e - s)));
}
if (*e != NUL) {
@@ -2662,7 +2661,7 @@ int wildmenu_process_key(CmdlineInfo *cclp, int key, expand_T *xp)
// cursor
int found = false;
int j = (int)((char_u *)xp->xp_pattern - cclp->cmdbuff);
int j = (int)(xp->xp_pattern - cclp->cmdbuff);
int i = 0;
while (--j > 0) {
// check for start of menu name
@@ -2717,9 +2716,9 @@ int wildmenu_process_key(CmdlineInfo *cclp, int key, expand_T *xp)
int found = false;
int j = cclp->cmdpos;
int i = (int)((char_u *)xp->xp_pattern - cclp->cmdbuff);
int i = (int)(xp->xp_pattern - cclp->cmdbuff);
while (--j > i) {
j -= utf_head_off((char *)cclp->cmdbuff, (char *)cclp->cmdbuff + j);
j -= utf_head_off(cclp->cmdbuff, cclp->cmdbuff + j);
if (vim_ispathsep(cclp->cmdbuff[j])) {
found = true;
break;
@@ -2738,9 +2737,9 @@ int wildmenu_process_key(CmdlineInfo *cclp, int key, expand_T *xp)
int found = false;
int j = cclp->cmdpos - 1;
int i = (int)((char_u *)xp->xp_pattern - cclp->cmdbuff);
int i = (int)(xp->xp_pattern - cclp->cmdbuff);
while (--j > i) {
j -= utf_head_off((char *)cclp->cmdbuff, (char *)cclp->cmdbuff + j);
j -= utf_head_off(cclp->cmdbuff, cclp->cmdbuff + j);
if (vim_ispathsep(cclp->cmdbuff[j])
#ifdef BACKSLASH_IN_FILENAME
&& vim_strchr((const char_u *)" *?[{`$%#", cclp->cmdbuff[j + 1])
@@ -2894,7 +2893,7 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
theend:
pat = addstar((char_u *)xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
pat = (char_u *)addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP);
tv_list_alloc_ret(rettv, xpc.xp_numfiles);