refactor: replace char_u variables and functions with char

Work on https://github.com/neovim/neovim/issues/459
This commit is contained in:
Dundar Goc
2022-05-04 18:27:22 +02:00
parent 82c7a82c35
commit 9a671e6a24
47 changed files with 569 additions and 576 deletions

View File

@@ -460,7 +460,7 @@ Integer nvim_create_autocmd(uint64_t channel_id, Object event, Dict(create_autoc
cb.data.luaref = api_new_luaref(callback->data.luaref);
} else if (callback->type == kObjectTypeString) {
cb.type = kCallbackFuncref;
cb.data.funcref = (char_u *)string_to_cstr(callback->data.string);
cb.data.funcref = string_to_cstr(callback->data.string);
} else {
api_set_error(err,
kErrorTypeException,

View File

@@ -452,7 +452,7 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ
goto end;
}
if (ml_replace((linenr_T)lnum, (char_u *)lines[i], false) == FAIL) {
if (ml_replace((linenr_T)lnum, lines[i], false) == FAIL) {
api_set_error(err, kErrorTypeException, "Failed to replace line");
goto end;
}
@@ -472,7 +472,7 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ
goto end;
}
if (ml_append((linenr_T)lnum, (char_u *)lines[i], 0, false) == FAIL) {
if (ml_append((linenr_T)lnum, lines[i], 0, false) == FAIL) {
api_set_error(err, kErrorTypeException, "Failed to insert line");
goto end;
}
@@ -692,7 +692,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
goto end;
}
if (ml_replace((linenr_T)lnum, (char_u *)lines[i], false) == FAIL) {
if (ml_replace((linenr_T)lnum, lines[i], false) == FAIL) {
api_set_error(err, kErrorTypeException, "Failed to replace line");
goto end;
}
@@ -710,7 +710,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
goto end;
}
if (ml_append((linenr_T)lnum, (char_u *)lines[i], 0, false) == FAIL) {
if (ml_append((linenr_T)lnum, lines[i], 0, false) == FAIL) {
api_set_error(err, kErrorTypeException, "Failed to insert line");
goto end;
}

View File

@@ -688,8 +688,8 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
}
if (opts->sign_text.type == kObjectTypeString) {
if (!init_sign_text(&decor.sign_text,
(char_u *)opts->sign_text.data.string.data)) {
if (!init_sign_text((char **)&decor.sign_text,
opts->sign_text.data.string.data)) {
api_set_error(err, kErrorTypeValidation, "sign_text is not a valid value");
goto error;
}

View File

@@ -353,9 +353,10 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
case kObjectTypeLuaRef: {
LuaCFunctionState *state = xmalloc(sizeof(LuaCFunctionState));
state->lua_callable.func_ref = api_new_luaref(obj.data.luaref);
char_u *name = register_cfunc(&nlua_CFunction_func_call, &nlua_CFunction_func_free, state);
char *name =
(char *)register_cfunc(&nlua_CFunction_func_call, &nlua_CFunction_func_free, state);
tv->v_type = VAR_FUNC;
tv->vval.v_string = vim_strsave(name);
tv->vval.v_string = xstrdup(name);
break;
}

View File

@@ -634,8 +634,8 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod
}
parsed_args.buffer = !global;
set_maparg_lhs_rhs((char_u *)lhs.data, lhs.size,
(char_u *)rhs.data, rhs.size, lua_funcref,
set_maparg_lhs_rhs(lhs.data, lhs.size,
rhs.data, rhs.size, lua_funcref,
CPO_TO_CPO_FLAGS, &parsed_args);
if (opts != NULL && opts->desc.type == kObjectTypeString) {
parsed_args.desc = string_to_cstr(opts->desc.data.string);
@@ -652,16 +652,16 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod
goto fail_and_free;
}
int mode_val; // integer value of the mapping mode, to be passed to do_map()
char_u *p = (char_u *)((mode.size) ? mode.data : "m");
char *p = (mode.size) ? mode.data : "m";
if (STRNCMP(p, "!", 2) == 0) {
mode_val = get_map_mode(&p, true); // mapmode-ic
mode_val = get_map_mode((char_u **)&p, true); // mapmode-ic
} else {
mode_val = get_map_mode(&p, false);
mode_val = get_map_mode((char_u **)&p, false);
if ((mode_val == VISUAL + SELECTMODE + NORMAL + OP_PENDING)
&& mode.size > 0) {
// get_map_mode() treats unrecognized mode shortnames as ":map".
// This is an error unless the given shortname was empty string "".
api_set_error(err, kErrorTypeValidation, "Invalid mode shortname: \"%s\"", (char *)p);
api_set_error(err, kErrorTypeValidation, "Invalid mode shortname: \"%s\"", p);
goto fail_and_free;
}
}
@@ -1269,7 +1269,7 @@ VirtText parse_virt_text(Array chunks, Error *err, int *width)
}
char *text = transstr(str.size > 0 ? str.data : "", false); // allocates
w += (int)mb_string2cells((char_u *)text);
w += (int)mb_string2cells(text);
kv_push(virt_text, ((VirtTextChunk){ .text = text, .hl_id = hl_id }));
}
@@ -1658,19 +1658,19 @@ sctx_T api_set_sctx(uint64_t channel_id)
// adapted from sign.c:sign_define_init_text.
// TODO(lewis6991): Consider merging
int init_sign_text(char_u **sign_text, char_u *text)
int init_sign_text(char **sign_text, char *text)
{
char_u *s;
char *s;
char_u *endp = text + (int)STRLEN(text);
char *endp = text + (int)STRLEN(text);
// Count cells and check for non-printable chars
int cells = 0;
for (s = text; s < endp; s += utfc_ptr2len(s)) {
if (!vim_isprintc(utf_ptr2char(s))) {
for (s = text; s < endp; s += utfc_ptr2len((char_u *)s)) {
if (!vim_isprintc(utf_ptr2char((char_u *)s))) {
break;
}
cells += utf_ptr2cells(s);
cells += utf_ptr2cells((char_u *)s);
}
// Currently must be empty, one or two display cells
if (s != endp || cells > 2) {
@@ -1683,7 +1683,7 @@ int init_sign_text(char_u **sign_text, char_u *text)
// Allocate one byte more if we need to pad up
// with a space.
size_t len = (size_t)(endp - text + ((cells == 1) ? 1 : 0));
*sign_text = vim_strnsave(text, len);
*sign_text = xstrnsave(text, len);
if (cells == 1) {
STRCPY(*sign_text + len - 1, " ");

View File

@@ -474,7 +474,7 @@ Integer nvim_strwidth(String text, Error *err)
return 0;
}
return (Integer)mb_string2cells((char_u *)text.data);
return (Integer)mb_string2cells(text.data);
}
/// Gets the paths contained in 'runtimepath'.