aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDundar Göc <gocdundar@gmail.com>2022-08-26 23:11:25 +0200
committerdundargoc <gocdundar@gmail.com>2022-09-06 16:44:37 +0200
commit73207cae611a1efb8cd17139e8228772daeb9866 (patch)
treef3efc08ff875266b5abf57f6ef4610450180e516
parent87e037e26cfd53c3c34ac9029a8833023af60a56 (diff)
downloadrneovim-73207cae611a1efb8cd17139e8228772daeb9866.tar.gz
rneovim-73207cae611a1efb8cd17139e8228772daeb9866.tar.bz2
rneovim-73207cae611a1efb8cd17139e8228772daeb9866.zip
refactor: replace char_u with char
Work on https://github.com/neovim/neovim/issues/459
-rw-r--r--src/nvim/api/buffer.c6
-rw-r--r--src/nvim/api/private/helpers.c4
-rw-r--r--src/nvim/arglist.c2
-rw-r--r--src/nvim/autocmd.c2
-rw-r--r--src/nvim/change.c4
-rw-r--r--src/nvim/charset.c4
-rw-r--r--src/nvim/cmdexpand.c81
-rw-r--r--src/nvim/cmdhist.c8
-rw-r--r--src/nvim/cursor.c15
-rw-r--r--src/nvim/diff.c39
-rw-r--r--src/nvim/digraph.c6
-rw-r--r--src/nvim/drawline.c10
-rw-r--r--src/nvim/edit.c68
-rw-r--r--src/nvim/eval.c18
-rw-r--r--src/nvim/eval/funcs.c54
-rw-r--r--src/nvim/eval/typval.c2
-rw-r--r--src/nvim/eval/typval.h15
-rw-r--r--src/nvim/eval/userfunc.c48
-rw-r--r--src/nvim/ex_cmds.c14
-rw-r--r--src/nvim/ex_docmd.c10
-rw-r--r--src/nvim/ex_eval.c2
-rw-r--r--src/nvim/ex_getln.c16
-rw-r--r--src/nvim/file_search.c100
-rw-r--r--src/nvim/fileio.c24
-rw-r--r--src/nvim/fold.c8
-rw-r--r--src/nvim/getchar.c44
-rw-r--r--src/nvim/globals.h2
-rw-r--r--src/nvim/hardcopy.c2
-rw-r--r--src/nvim/help.c15
-rw-r--r--src/nvim/highlight_group.c6
-rw-r--r--src/nvim/if_cscope.c10
-rw-r--r--src/nvim/indent.c8
-rw-r--r--src/nvim/indent_c.c6
-rw-r--r--src/nvim/insexpand.c94
-rw-r--r--src/nvim/lua/converter.c8
-rw-r--r--src/nvim/lua/stdlib.c2
-rw-r--r--src/nvim/lua/treesitter.c2
-rw-r--r--src/nvim/macros.h2
-rw-r--r--src/nvim/mapping.c74
-rw-r--r--src/nvim/mapping.h2
-rw-r--r--src/nvim/mark.c12
-rw-r--r--src/nvim/match.c6
-rw-r--r--src/nvim/mbyte.c32
-rw-r--r--src/nvim/memfile.c12
-rw-r--r--src/nvim/memfile_defs.h2
-rw-r--r--src/nvim/memline.c76
-rw-r--r--src/nvim/mouse.c2
-rw-r--r--src/nvim/normal.c26
-rw-r--r--src/nvim/ops.c54
-rw-r--r--src/nvim/option.c62
-rw-r--r--src/nvim/optionstr.c2
-rw-r--r--src/nvim/os/env.c6
-rw-r--r--src/nvim/os/shell.c10
-rw-r--r--src/nvim/path.c77
-rw-r--r--src/nvim/plines.c4
-rw-r--r--src/nvim/quickfix.c12
-rw-r--r--src/nvim/regexp.c64
-rw-r--r--src/nvim/regexp_bt.c4
-rw-r--r--src/nvim/regexp_defs.h2
-rw-r--r--src/nvim/regexp_nfa.c6
-rw-r--r--src/nvim/screen.c2
-rw-r--r--src/nvim/search.c36
-rw-r--r--src/nvim/shada.c2
-rw-r--r--src/nvim/spell.c30
-rw-r--r--src/nvim/spell_defs.h6
-rw-r--r--src/nvim/spellfile.c143
-rw-r--r--src/nvim/spellsuggest.c32
-rw-r--r--src/nvim/statusline.c22
-rw-r--r--src/nvim/strings.c15
-rw-r--r--src/nvim/syntax.c8
-rw-r--r--src/nvim/tag.c99
-rw-r--r--src/nvim/tag.h2
-rw-r--r--src/nvim/textformat.c28
-rw-r--r--src/nvim/textobject.c4
-rw-r--r--src/nvim/undo.c12
-rw-r--r--test/unit/message_spec.lua2
76 files changed, 868 insertions, 883 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 16f574f46d..6f8cad3e33 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -570,7 +570,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
char *str_at_end = NULL;
// Another call to ml_get_buf() may free the line, so make a copy.
- str_at_start = xstrdup((char *)ml_get_buf(buf, (linenr_T)start_row, false));
+ str_at_start = xstrdup(ml_get_buf(buf, (linenr_T)start_row, false));
size_t len_at_start = strlen(str_at_start);
if (start_col < 0 || (size_t)start_col > len_at_start) {
api_set_error(err, kErrorTypeValidation, "start_col out of bounds");
@@ -578,7 +578,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
}
// Another call to ml_get_buf() may free the line, so make a copy.
- str_at_end = xstrdup((char *)ml_get_buf(buf, (linenr_T)end_row, false));
+ str_at_end = xstrdup(ml_get_buf(buf, (linenr_T)end_row, false));
size_t len_at_end = strlen(str_at_end);
if (end_col < 0 || (size_t)end_col > len_at_end) {
api_set_error(err, kErrorTypeValidation, "end_col out of bounds");
@@ -608,7 +608,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
for (int64_t i = 1; i < end_row - start_row; i++) {
int64_t lnum = start_row + i;
- const char *bufline = (char *)ml_get_buf(buf, (linenr_T)lnum, false);
+ const char *bufline = ml_get_buf(buf, (linenr_T)lnum, false);
old_byte += (bcount_t)(strlen(bufline)) + 1;
}
old_byte += (bcount_t)end_col + 1;
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index ebcf6cca6d..22d2ffbaf1 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -466,7 +466,7 @@ bool buf_collect_lines(buf_T *buf, size_t n, int64_t start, bool replace_nl, Arr
return false;
}
- const char *bufstr = (char *)ml_get_buf(buf, (linenr_T)lnum, false);
+ const char *bufstr = ml_get_buf(buf, (linenr_T)lnum, false);
Object str = STRING_OBJ(cstr_to_string(bufstr));
if (replace_nl) {
@@ -499,7 +499,7 @@ String buf_get_text(buf_T *buf, int64_t lnum, int64_t start_col, int64_t end_col
return rv;
}
- const char *bufstr = (char *)ml_get_buf(buf, (linenr_T)lnum, false);
+ const char *bufstr = ml_get_buf(buf, (linenr_T)lnum, false);
size_t line_length = strlen(bufstr);
start_col = start_col < 0 ? (int64_t)line_length + start_col + 1 : start_col;
diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c
index e6ac1f6247..0000636417 100644
--- a/src/nvim/arglist.c
+++ b/src/nvim/arglist.c
@@ -86,7 +86,7 @@ void alist_expand(int *fnum_list, int fnum_len)
// can't set the options.
p_su = empty_option;
for (int i = 0; i < GARGCOUNT; i++) {
- old_arg_files[i] = vim_strsave(GARGLIST[i].ae_fname);
+ old_arg_files[i] = xstrdup(GARGLIST[i].ae_fname);
}
int old_arg_count = GARGCOUNT;
char **new_arg_files;
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c
index 1c1de214cd..635875b16f 100644
--- a/src/nvim/autocmd.c
+++ b/src/nvim/autocmd.c
@@ -2214,7 +2214,7 @@ bool has_autocmd(event_T event, char *sfname, buf_T *buf)
#ifdef BACKSLASH_IN_FILENAME
// Replace all backslashes with forward slashes. This makes the
// autocommand patterns portable between Unix and Windows.
- sfname = vim_strsave(sfname);
+ sfname = xstrdup(sfname);
forward_slash(sfname);
forward_slash(fname);
#endif
diff --git a/src/nvim/change.c b/src/nvim/change.c
index 5e9edac4f2..f4568fc617 100644
--- a/src/nvim/change.c
+++ b/src/nvim/change.c
@@ -774,7 +774,7 @@ int del_char(bool fixpos)
int del_chars(long count, int fixpos)
{
int bytes = 0;
- char *p = (char *)get_cursor_pos_ptr();
+ char *p = get_cursor_pos_ptr();
for (long i = 0; i < count && *p != NUL; i++) {
int l = utfc_ptr2len(p);
bytes += l;
@@ -1036,7 +1036,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
colnr_T mincol = curwin->w_cursor.col + 1;
// make a copy of the current line so we can mess with it
- char *saved_line = (char *)vim_strsave((char_u *)get_cursor_line_ptr());
+ char *saved_line = xstrdup(get_cursor_line_ptr());
if (State & VREPLACE_FLAG) {
// With MODE_VREPLACE we make a copy of the next line, which we will be
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index 3396e2de41..693ff90179 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -913,7 +913,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en
int ts = (int)wp->w_buffer->b_p_ts;
colnr_T vcol = 0;
- char *line = ptr = (char *)ml_get_buf(wp->w_buffer, pos->lnum, false); // start of the line
+ char *line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); // start of the line
if (pos->col == MAXCOL) {
// continue until the NUL
@@ -1076,7 +1076,7 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *e
colnr_T endadd = 0;
// Cannot put the cursor on part of a wide character.
- char *ptr = (char *)ml_get_buf(wp->w_buffer, pos->lnum, false);
+ char *ptr = ml_get_buf(wp->w_buffer, pos->lnum, false);
if (pos->col < (colnr_T)STRLEN(ptr)) {
int c = utf_ptr2char(ptr + pos->col);
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c
index 30e734b93f..3f624c77f3 100644
--- a/src/nvim/cmdexpand.c
+++ b/src/nvim/cmdexpand.c
@@ -183,7 +183,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape)
if (type == WILD_NEXT || type == WILD_PREV) {
// Get next/previous match for a previous expanded pattern.
- p2 = ExpandOne(xp, NULL, NULL, 0, type);
+ p2 = (char_u *)ExpandOne(xp, NULL, NULL, 0, type);
} else {
// Translate string into pattern and expand it.
p1 = (char_u *)addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context);
@@ -193,8 +193,8 @@ int nextwild(expand_T *xp, int type, int options, bool escape)
| WILD_SILENT
| (escape ? WILD_ESCAPE : 0)
| (p_wic ? WILD_ICASE : 0));
- p2 = ExpandOne(xp, p1, (char_u *)xstrnsave(&ccline->cmdbuff[i], xp->xp_pattern_len),
- use_options, type);
+ p2 = (char_u *)ExpandOne(xp, (char *)p1, xstrnsave(&ccline->cmdbuff[i], xp->xp_pattern_len),
+ use_options, type);
xfree(p1);
// xp->xp_pattern might have been modified by ExpandOne (for example,
@@ -278,7 +278,7 @@ void cmdline_pum_cleanup(CmdlineInfo *cclp)
/// Get the next or prev cmdline completion match. The index of the match is set
/// in "p_findex"
-static char_u *get_next_or_prev_match(int mode, expand_T *xp, int *p_findex, char_u *orig_save)
+static char *get_next_or_prev_match(int mode, expand_T *xp, int *p_findex, char *orig_save)
{
if (xp->xp_numfiles <= 0) {
return NULL;
@@ -318,17 +318,17 @@ static char_u *get_next_or_prev_match(int mode, expand_T *xp, int *p_findex, cha
}
*p_findex = findex;
- return vim_strsave(findex == -1 ? orig_save : (char_u *)xp->xp_files[findex]);
+ return xstrdup(findex == -1 ? orig_save : xp->xp_files[findex]);
}
/// Start the command-line expansion and get the matches.
-static char_u *ExpandOne_start(int mode, expand_T *xp, char_u *str, int options)
+static char *ExpandOne_start(int mode, expand_T *xp, char *str, int options)
{
int non_suf_match; // number without matching suffix
- char_u *ss = NULL;
+ char *ss = NULL;
// Do the expansion.
- if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files, options) == FAIL) {
+ if (ExpandFromContext(xp, (char_u *)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,
@@ -343,7 +343,7 @@ static char_u *ExpandOne_start(int mode, expand_T *xp, char_u *str, int options)
}
} else {
// Escape the matches for use on the command line.
- ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options);
+ ExpandEscape(xp, (char_u *)str, xp->xp_numfiles, xp->xp_files, options);
// Check for matching suffixes in file names.
if (mode != WILD_ALL && mode != WILD_ALL_KEEP
@@ -378,7 +378,7 @@ static char_u *ExpandOne_start(int mode, expand_T *xp, char_u *str, int options)
}
}
if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) {
- ss = vim_strsave((char_u *)xp->xp_files[0]);
+ ss = xstrdup(xp->xp_files[0]);
}
}
}
@@ -458,11 +458,11 @@ static char *find_longest_match(expand_T *xp, int options)
/// The variables xp->xp_context and xp->xp_backslash must have been set!
///
/// @param orig allocated copy of original of expanded string
-char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode)
+char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode)
{
- char_u *ss = NULL;
+ char *ss = NULL;
static int findex;
- static char_u *orig_save = NULL; // kept value of orig
+ static char *orig_save = NULL; // kept value of orig
int orig_saved = false;
int i;
@@ -472,10 +472,11 @@ char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode
}
if (mode == WILD_CANCEL) {
- ss = vim_strsave(orig_save ? orig_save : (char_u *)"");
+ ss = xstrdup(orig_save ? orig_save : "");
} else if (mode == WILD_APPLY) {
- ss = vim_strsave(findex == -1 ? (orig_save ? orig_save : (char_u *)"")
- : (char_u *)xp->xp_files[findex]);
+ ss = xstrdup(findex == -1
+ ? (orig_save ? orig_save : "")
+ : xp->xp_files[findex]);
}
// free old names
@@ -500,7 +501,7 @@ char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode
// Find longest common part
if (mode == WILD_LONGEST && xp->xp_numfiles > 0) {
- ss = (char_u *)find_longest_match(xp, options);
+ ss = find_longest_match(xp, options);
findex = -1; // next p_wc gets first one
}
@@ -1915,7 +1916,7 @@ int expand_cmdline(expand_T *xp, char_u *str, int col, int *matchcount, char ***
}
/// Expand file or directory names.
-static int expand_files_and_dirs(expand_T *xp, char_u *pat, char ***file, int *num_file, int flags,
+static int expand_files_and_dirs(expand_T *xp, char *pat, char ***file, int *num_file, int flags,
int options)
{
bool free_pat = false;
@@ -1923,7 +1924,7 @@ static int expand_files_and_dirs(expand_T *xp, char_u *pat, char ***file, int *n
// for ":set path=" and ":set tags=" halve backslashes for escaped space
if (xp->xp_backslash != XP_BS_NONE) {
free_pat = true;
- pat = vim_strsave(pat);
+ pat = xstrdup(pat);
for (int i = 0; pat[i]; i++) {
if (pat[i] == '\\') {
if (xp->xp_backslash == XP_BS_THREE
@@ -2124,7 +2125,7 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char ***f
if (xp->xp_context == EXPAND_FILES
|| xp->xp_context == EXPAND_DIRECTORIES
|| xp->xp_context == EXPAND_FILES_IN_PATH) {
- return expand_files_and_dirs(xp, pat, file, num_file, flags, options);
+ return expand_files_and_dirs(xp, (char *)pat, file, num_file, flags, options);
}
*file = NULL;
@@ -2142,7 +2143,7 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char ***f
if (xp->xp_context == EXPAND_SHELLCMD) {
*file = NULL;
- expand_shellcmd(pat, num_file, file, flags);
+ expand_shellcmd((char *)pat, num_file, file, flags);
return OK;
}
if (xp->xp_context == EXPAND_OLD_SETTING) {
@@ -2238,18 +2239,18 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, cha
{
int i;
size_t count = 0;
- char_u *str;
+ char *str;
// count the number of matching names
for (i = 0;; i++) {
- str = (char_u *)(*func)(xp, i);
+ str = (*func)(xp, i);
if (str == NULL) { // end of list
break;
}
if (*str == NUL) { // skip empty strings
continue;
}
- if (vim_regexec(regmatch, (char *)str, (colnr_T)0)) {
+ if (vim_regexec(regmatch, str, (colnr_T)0)) {
count++;
}
}
@@ -2263,20 +2264,20 @@ static void ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, cha
// copy the matching names into allocated memory
count = 0;
for (i = 0;; i++) {
- str = (char_u *)(*func)(xp, i);
+ str = (*func)(xp, i);
if (str == NULL) { // End of list.
break;
}
if (*str == NUL) { // Skip empty strings.
continue;
}
- if (vim_regexec(regmatch, (char *)str, (colnr_T)0)) {
+ if (vim_regexec(regmatch, str, (colnr_T)0)) {
if (escaped) {
- str = vim_strsave_escaped(str, (char_u *)" \t\\.");
+ str = (char *)vim_strsave_escaped((char_u *)str, (char_u *)" \t\\.");
} else {
- str = vim_strsave(str);
+ str = xstrdup(str);
}
- (*file)[count++] = (char *)str;
+ (*file)[count++] = str;
if (func == get_menu_names) {
// Test for separator added by get_menu_names().
str += STRLEN(str) - 1;
@@ -2313,22 +2314,22 @@ 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 ***file, int flagsarg)
+static void expand_shellcmd(char *filepat, int *num_file, char ***file, int flagsarg)
FUNC_ATTR_NONNULL_ALL
{
- char_u *pat;
+ char *pat;
int i;
- char_u *path = NULL;
+ char *path = NULL;
garray_T ga;
char *buf = xmalloc(MAXPATHL);
size_t l;
- char_u *s, *e;
+ char *s, *e;
int flags = flagsarg;
int ret;
bool did_curdir = false;
// for ":set path=" and ":set tags=" halve backslashes for escaped space
- pat = vim_strsave(filepat);
+ pat = xstrdup(filepat);
for (i = 0; pat[i]; i++) {
if (pat[i] == '\\' && pat[i + 1] == ' ') {
STRMOVE(pat + i, pat + i + 1);
@@ -2340,14 +2341,14 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char ***file, int fl
bool mustfree = false; // Track memory allocation for *path.
if (pat[0] == '.' && (vim_ispathsep(pat[1])
|| (pat[1] == '.' && vim_ispathsep(pat[2])))) {
- path = (char_u *)".";
+ path = ".";
} else {
// For an absolute name we don't use $PATH.
- if (!path_is_absolute(pat)) {
- path = (char_u *)vim_getenv("PATH");
+ if (!path_is_absolute((char_u *)pat)) {
+ path = vim_getenv("PATH");
}
if (path == NULL) {
- path = (char_u *)"";
+ path = "";
} else {
mustfree = true;
}
@@ -2360,7 +2361,7 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char ***file, int fl
hashtab_T found_ht;
hash_init(&found_ht);
for (s = path;; s = e) {
- e = (char_u *)vim_strchr((char *)s, ENV_SEPCHAR);
+ e = vim_strchr(s, ENV_SEPCHAR);
if (e == NULL) {
e = s + STRLEN(s);
}
@@ -2895,7 +2896,7 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
theend:
pat = (char_u *)addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
- ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP);
+ ExpandOne(&xpc, (char *)pat, NULL, options, WILD_ALL_KEEP);
tv_list_alloc_ret(rettv, xpc.xp_numfiles);
for (int i = 0; i < xpc.xp_numfiles; i++) {
diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c
index 629c47f24a..38353f44b5 100644
--- a/src/nvim/cmdhist.c
+++ b/src/nvim/cmdhist.c
@@ -382,13 +382,13 @@ static int calc_hist_idx(int histype, int num)
/// Get a history entry by its index.
///
/// @param histype may be one of the HIST_ values.
-static char_u *get_history_entry(int histype, int idx)
+static char *get_history_entry(int histype, int idx)
{
idx = calc_hist_idx(histype, idx);
if (idx >= 0) {
- return (char_u *)history[histype][idx].hisstr;
+ return history[histype][idx].hisstr;
} else {
- return (char_u *)"";
+ return "";
}
}
@@ -556,7 +556,7 @@ void f_histget(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
idx = (int)tv_get_number_chk(&argvars[1], NULL);
}
// -1 on type error
- rettv->vval.v_string = (char *)vim_strsave(get_history_entry(type, idx));
+ rettv->vval.v_string = xstrdup(get_history_entry(type, idx));
}
rettv->v_type = VAR_STRING;
}
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c
index 2a3fe9701c..cd651fcf4c 100644
--- a/src/nvim/cursor.c
+++ b/src/nvim/cursor.c
@@ -101,7 +101,7 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a
|| (VIsual_active && *p_sel != 'o')
|| ((get_ve_flags() & VE_ONEMORE) && wcol < MAXCOL);
- char_u *line = ml_get_buf(curbuf, pos->lnum, false);
+ char_u *line = (char_u *)ml_get_buf(curbuf, pos->lnum, false);
if (wcol >= MAXCOL) {
idx = (int)STRLEN(line) - 1 + one_more;
@@ -308,7 +308,7 @@ void check_pos(buf_T *buf, pos_T *pos)
}
if (pos->col > 0) {
- char_u *line = ml_get_buf(buf, pos->lnum, false);
+ char_u *line = (char_u *)ml_get_buf(buf, pos->lnum, false);
colnr_T len = (colnr_T)STRLEN(line);
if (pos->col > len) {
pos->col = len;
@@ -481,7 +481,7 @@ bool leftcol_changed(void)
int gchar_cursor(void)
{
- return utf_ptr2char((char *)get_cursor_pos_ptr());
+ return utf_ptr2char(get_cursor_pos_ptr());
}
/// Write a character at the current cursor position.
@@ -489,18 +489,17 @@ int gchar_cursor(void)
void pchar_cursor(char_u c)
{
*(ml_get_buf(curbuf, curwin->w_cursor.lnum, true)
- + curwin->w_cursor.col) = c;
+ + curwin->w_cursor.col) = (char)c;
}
/// @return pointer to cursor line.
char *get_cursor_line_ptr(void)
{
- return (char *)ml_get_buf(curbuf, curwin->w_cursor.lnum, false);
+ return ml_get_buf(curbuf, curwin->w_cursor.lnum, false);
}
/// @return pointer to cursor position.
-char_u *get_cursor_pos_ptr(void)
+char *get_cursor_pos_ptr(void)
{
- return ml_get_buf(curbuf, curwin->w_cursor.lnum, false) +
- curwin->w_cursor.col;
+ return ml_get_buf(curbuf, curwin->w_cursor.lnum, false) + curwin->w_cursor.col;
}
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index a3046bb7d7..69883966ab 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -573,9 +573,9 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp)
if (dir == BACKWARD) {
off_org = dp->df_count[i_org] - 1;
}
- char *line_org = (char *)vim_strsave(ml_get_buf(tp->tp_diffbuf[i_org],
- dp->df_lnum[i_org] + off_org,
- false));
+ char *line_org = xstrdup(ml_get_buf(tp->tp_diffbuf[i_org],
+ dp->df_lnum[i_org] + off_org,
+ false));
int i_new;
for (i_new = i_org + 1; i_new < DB_COUNT; i_new++) {
@@ -592,9 +592,9 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp)
break;
}
- if (diff_cmp((char_u *)line_org, ml_get_buf(tp->tp_diffbuf[i_new],
- dp->df_lnum[i_new] + off_new,
- false)) != 0) {
+ if (diff_cmp((char_u *)line_org, (char_u *)ml_get_buf(tp->tp_diffbuf[i_new],
+ dp->df_lnum[i_new] + off_new,
+ false)) != 0) {
break;
}
}
@@ -750,7 +750,7 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din)
len = 0;
for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) {
- for (char_u *s = ml_get_buf(buf, lnum, false); *s != NUL;) {
+ for (char_u *s = (char_u *)ml_get_buf(buf, lnum, false); *s != NUL;) {
if (diff_flags & DIFF_ICASE) {
int c;
char cbuf[MB_MAXBYTES + 1];
@@ -824,9 +824,9 @@ static void diff_try_update(diffio_T *dio, int idx_orig, exarg_T *eap)
ga_init(&dio->dio_diff.dout_ga, sizeof(char *), 1000);
} else {
// We need three temp file names.
- dio->dio_orig.din_fname = vim_tempname();
- dio->dio_new.din_fname = vim_tempname();
- dio->dio_diff.dout_fname = vim_tempname();
+ dio->dio_orig.din_fname = (char_u *)vim_tempname();
+ dio->dio_new.din_fname = (char_u *)vim_tempname();
+ dio->dio_diff.dout_fname = (char_u *)vim_tempname();
if (dio->dio_orig.din_fname == NULL
|| dio->dio_new.din_fname == NULL
|| dio->dio_diff.dout_fname == NULL) {
@@ -1178,9 +1178,9 @@ void ex_diffpatch(exarg_T *eap)
// We need two temp file names.
// Name of original temp file.
- char_u *tmp_orig = vim_tempname();
+ char_u *tmp_orig = (char_u *)vim_tempname();
// Name of patched temp file.
- char_u *tmp_new = vim_tempname();
+ char_u *tmp_new = (char_u *)vim_tempname();
if ((tmp_orig == NULL) || (tmp_new == NULL)) {
goto theend;
@@ -1920,11 +1920,11 @@ static bool diff_equal_entry(diff_T *dp, int idx1, int idx2)
}
for (int i = 0; i < dp->df_count[idx1]; i++) {
- char *line = (char *)vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1],
- dp->df_lnum[idx1] + i, false));
+ char *line = xstrdup(ml_get_buf(curtab->tp_diffbuf[idx1],
+ dp->df_lnum[idx1] + i, false));
- int cmp = diff_cmp((char_u *)line, ml_get_buf(curtab->tp_diffbuf[idx2],
- dp->df_lnum[idx2] + i, false));
+ int cmp = diff_cmp((char_u *)line, (char_u *)ml_get_buf(curtab->tp_diffbuf[idx2],
+ dp->df_lnum[idx2] + i, false));
xfree(line);
if (cmp != 0) {
@@ -2290,7 +2290,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
int l;
// Make a copy of the line, the next ml_get() will invalidate it.
- char *line_org = (char *)vim_strsave(ml_get_buf(wp->w_buffer, lnum, false));
+ char *line_org = xstrdup(ml_get_buf(wp->w_buffer, lnum, false));
int idx = diff_buf_idx(wp->w_buffer);
if (idx == DB_COUNT) {
@@ -2322,8 +2322,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
continue;
}
added = false;
- line_new = (char *)ml_get_buf(curtab->tp_diffbuf[i],
- dp->df_lnum[i] + off, false);
+ line_new = ml_get_buf(curtab->tp_diffbuf[i], dp->df_lnum[i] + off, false);
// Search for start of difference
si_org = si_new = 0;
@@ -2718,7 +2717,7 @@ void ex_diffgetput(exarg_T *eap)
if (nr > curtab->tp_diffbuf[idx_from]->b_ml.ml_line_count) {
break;
}
- p = (char *)vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, false));
+ p = xstrdup(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, false));
ml_append(lnum + i - 1, p, 0, false);
xfree(p);
added++;
diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c
index 53b6c66c46..8e31d3feab 100644
--- a/src/nvim/digraph.c
+++ b/src/nvim/digraph.c
@@ -1932,9 +1932,9 @@ void f_digraph_get(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
int code = digraph_get(digraphs[0], digraphs[1], false);
- char_u buf[NUMBUFLEN];
- buf[utf_char2bytes(code, (char *)buf)] = NUL;
- rettv->vval.v_string = (char *)vim_strsave(buf);
+ char buf[NUMBUFLEN];
+ buf[utf_char2bytes(code, buf)] = NUL;
+ rettv->vval.v_string = xstrdup(buf);
}
/// "digraph_getlist()" function
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index 7846510ad9..9de8b9996a 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -689,7 +689,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
// Trick: skip a few chars for C/shell/Vim comments
nextline[SPWORDLEN] = NUL;
if (lnum < wp->w_buffer->b_ml.ml_line_count) {
- line = ml_get_buf(wp->w_buffer, lnum + 1, false);
+ line = (char_u *)ml_get_buf(wp->w_buffer, lnum + 1, false);
spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
}
@@ -866,7 +866,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
line_attr_lowprio_save = line_attr_lowprio;
}
- line = end_fill ? (char_u *)"" : ml_get_buf(wp->w_buffer, lnum, false);
+ line = end_fill ? (char_u *)"" : (char_u *)ml_get_buf(wp->w_buffer, lnum, false);
ptr = line;
if (has_spell && !number_only) {
@@ -1006,7 +1006,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
len = spell_move_to(wp, FORWARD, true, true, &spell_hlf);
// spell_move_to() may call ml_get() and make "line" invalid
- line = ml_get_buf(wp->w_buffer, lnum, false);
+ line = (char_u *)ml_get_buf(wp->w_buffer, lnum, false);
ptr = line + linecol;
if (len == 0 || (int)wp->w_cursor.col > ptr - line) {
@@ -1224,7 +1224,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
c_extra = ' ';
c_final = NUL;
n_extra =
- get_breakindent_win(wp, ml_get_buf(wp->w_buffer, lnum, false));
+ get_breakindent_win(wp, (char_u *)ml_get_buf(wp->w_buffer, lnum, false));
if (row == startrow) {
n_extra -= win_col_off2(wp);
if (n_extra < 0) {
@@ -1676,7 +1676,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
// Need to get the line again, a multi-line regexp may
// have made it invalid.
- line = ml_get_buf(wp->w_buffer, lnum, false);
+ line = (char_u *)ml_get_buf(wp->w_buffer, lnum, false);
ptr = line + v;
if (!attr_pri) {
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index b20fc7d44a..f7a16abfb2 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -1439,21 +1439,21 @@ void edit_putchar(int c, bool highlight)
}
}
-/// Return the effective prompt for the specified buffer.
-char_u *buf_prompt_text(const buf_T *const buf)
+/// @return the effective prompt for the specified buffer.
+char *buf_prompt_text(const buf_T *const buf)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
{
if (buf->b_prompt_text == NULL) {
- return (char_u *)"% ";
+ return "% ";
}
- return (char_u *)buf->b_prompt_text;
+ return buf->b_prompt_text;
}
// Return the effective prompt for the current buffer.
char_u *prompt_text(void)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
{
- return buf_prompt_text(curbuf);
+ return (char_u *)buf_prompt_text(curbuf);
}
// Prepare for prompt mode: Make sure the last line has the prompt text.
@@ -1574,11 +1574,11 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang
int start_col;
colnr_T vc;
colnr_T orig_col = 0; // init for GCC
- char_u *new_line, *orig_line = NULL; // init for GCC
+ char *new_line, *orig_line = NULL; // init for GCC
// MODE_VREPLACE state needs to know what the line was like before changing
if (State & VREPLACE_FLAG) {
- orig_line = vim_strsave((char_u *)get_cursor_line_ptr()); // Deal with NULL below
+ orig_line = xstrdup(get_cursor_line_ptr()); // Deal with NULL below
orig_col = curwin->w_cursor.col;
}
@@ -1733,14 +1733,14 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang
// then put it back again the way we wanted it.
if (State & VREPLACE_FLAG) {
// Save new line
- new_line = vim_strsave((char_u *)get_cursor_line_ptr());
+ new_line = xstrdup(get_cursor_line_ptr());
// We only put back the new line up to the cursor
new_line[curwin->w_cursor.col] = NUL;
int new_col = curwin->w_cursor.col;
// Put back original line
- ml_replace(curwin->w_cursor.lnum, (char *)orig_line, false);
+ ml_replace(curwin->w_cursor.lnum, orig_line, false);
curwin->w_cursor.col = orig_col;
curbuf_splice_pending++;
@@ -1749,7 +1749,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang
backspace_until_column(0);
// Insert new stuff into line again
- ins_bytes((char *)new_line);
+ ins_bytes(new_line);
xfree(new_line);
@@ -1813,7 +1813,7 @@ static bool del_char_after_col(int limit_col)
// composing character.
mb_adjust_cursor();
while (curwin->w_cursor.col < (colnr_T)limit_col) {
- int l = utf_ptr2len((char *)get_cursor_pos_ptr());
+ int l = utf_ptr2len(get_cursor_pos_ptr());
if (l == 0) { // end of line
break;
@@ -2466,7 +2466,7 @@ int oneright(void)
pos_T prevpos = curwin->w_cursor;
// Adjust for multi-wide char (excluding TAB)
- ptr = (char *)get_cursor_pos_ptr();
+ ptr = get_cursor_pos_ptr();
coladvance(getviscol() + ((*ptr != TAB && vim_isprintc(utf_ptr2char(ptr))) ?
ptr2cells(ptr) : 1));
curwin->w_set_curswant = true;
@@ -2475,7 +2475,7 @@ int oneright(void)
|| prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL;
}
- ptr = (char *)get_cursor_pos_ptr();
+ ptr = get_cursor_pos_ptr();
if (*ptr == NUL) {
return FAIL; // already at the very end
}
@@ -2518,7 +2518,7 @@ int oneleft(void)
if (curwin->w_cursor.coladd == 1) {
// Adjust for multi-wide char (not a TAB)
- char *ptr = (char *)get_cursor_pos_ptr();
+ char *ptr = get_cursor_pos_ptr();
if (*ptr != TAB && vim_isprintc(utf_ptr2char(ptr)) && ptr2cells(ptr) > 1) {
curwin->w_cursor.coladd = 0;
}
@@ -2720,19 +2720,19 @@ char_u *get_last_insert(void)
// Returns pointer to allocated memory (must be freed) or NULL.
char_u *get_last_insert_save(void)
{
- char_u *s;
+ char *s;
int len;
if (last_insert == NULL) {
return NULL;
}
- s = vim_strsave(last_insert + last_insert_skip);
+ s = xstrdup((char *)last_insert + last_insert_skip);
len = (int)STRLEN(s);
if (len > 0 && s[len - 1] == ESC) { // remove trailing ESC
s[len - 1] = NUL;
}
- return s;
+ return (char_u *)s;
}
/// Check the word in front of the cursor for an abbreviation.
@@ -2934,7 +2934,7 @@ static void replace_do_bs(int limit_col)
// Get the number of screen cells used by the character we are
// going to delete.
getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL);
- orig_vcols = win_chartabsize(curwin, (char *)get_cursor_pos_ptr(), start_vcol);
+ orig_vcols = win_chartabsize(curwin, get_cursor_pos_ptr(), start_vcol);
}
(void)del_char_after_col(limit_col);
if (l_State & VREPLACE_FLAG) {
@@ -2945,7 +2945,7 @@ static void replace_do_bs(int limit_col)
if (l_State & VREPLACE_FLAG) {
// Get the number of screen cells used by the inserted characters
- p = get_cursor_pos_ptr();
+ p = (char_u *)get_cursor_pos_ptr();
ins_len = (int)STRLEN(p) - orig_len;
vcol = start_vcol;
for (i = 0; i < ins_len; i++) {
@@ -3186,7 +3186,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty)
if (keytyped == (int)p[-1]
|| (icase && keytyped < 256
&& TOLOWER_LOC(keytyped) == TOLOWER_LOC((int)p[-1]))) {
- line = get_cursor_pos_ptr();
+ line = (char_u *)get_cursor_pos_ptr();
assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX);
if ((curwin->w_cursor.col == (colnr_T)(p - look)
|| !vim_iswordc(line[-(p - look) - 1]))
@@ -3880,7 +3880,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
// again when auto-formatting.
if (has_format_option(FO_AUTO)
&& has_format_option(FO_WHITE_PAR)) {
- char_u *ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, true);
+ char_u *ptr = (char_u *)ml_get_buf(curbuf, curwin->w_cursor.lnum, true);
int len;
len = (int)STRLEN(ptr);
@@ -3974,7 +3974,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
// delete characters until we are at or before want_vcol
while (vcol > want_vcol && curwin->w_cursor.col > 0
- && (cc = *(get_cursor_pos_ptr() - 1), ascii_iswhite(cc))) {
+ && (cc = (uint8_t)(*(get_cursor_pos_ptr() - 1)), ascii_iswhite(cc))) {
ins_bs_one(&vcol);
}
@@ -4006,7 +4006,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
// Delete up to starting point, start of line or previous word.
int prev_cclass = 0;
- int cclass = mb_get_class(get_cursor_pos_ptr());
+ int cclass = mb_get_class((char_u *)get_cursor_pos_ptr());
do {
if (!revins_on) { // put cursor on char to be deleted
dec_cursor();
@@ -4014,7 +4014,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
cc = gchar_cursor();
// look multi-byte character class
prev_cclass = cclass;
- cclass = mb_get_class(get_cursor_pos_ptr());
+ cclass = mb_get_class((char_u *)get_cursor_pos_ptr());
if (mode == BACKSPACE_WORD && !ascii_isspace(cc)) { // start of word?
mode = BACKSPACE_WORD_NOT_SPACE;
temp = vim_iswordc(cc);
@@ -4033,7 +4033,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
} else {
const int l_p_deco = p_deco;
if (l_p_deco) {
- (void)utfc_ptr2char((char *)get_cursor_pos_ptr(), cpc);
+ (void)utfc_ptr2char(get_cursor_pos_ptr(), cpc);
}
(void)del_char(false);
// If there are combining characters and 'delcombine' is set
@@ -4286,7 +4286,7 @@ static void ins_right(void)
if (virtual_active()) {
oneright();
} else {
- curwin->w_cursor.col += utfc_ptr2len((char *)get_cursor_pos_ptr());
+ curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr());
}
revins_legal++;
@@ -4507,7 +4507,7 @@ static bool ins_tab(void)
|| get_sts_value() > 0
|| (p_sta && ind))) {
char_u *ptr;
- char_u *saved_line = NULL; // init for GCC
+ char *saved_line = NULL; // init for GCC
pos_T pos;
pos_T fpos;
pos_T *cursor;
@@ -4520,10 +4520,10 @@ static bool ins_tab(void)
if (State & VREPLACE_FLAG) {
pos = curwin->w_cursor;
cursor = &pos;
- saved_line = vim_strsave((char_u *)get_cursor_line_ptr());
- ptr = saved_line + pos.col;
+ saved_line = xstrdup(get_cursor_line_ptr());
+ ptr = (char_u *)saved_line + pos.col;
} else {
- ptr = get_cursor_pos_ptr();
+ ptr = (char_u *)get_cursor_pos_ptr();
cursor = &curwin->w_cursor;
}
@@ -4627,7 +4627,7 @@ static bool ins_tab(void)
// Insert each char in saved_line from changed_col to
// ptr-cursor
- ins_bytes_len((char *)saved_line + change_col, (size_t)(cursor->col - change_col));
+ ins_bytes_len(saved_line + change_col, (size_t)(cursor->col - change_col));
}
}
@@ -4946,13 +4946,13 @@ static char_u *do_insert_char_pre(int c)
textlock++;
set_vim_var_string(VV_CHAR, buf, -1);
- char_u *res = NULL;
+ char *res = NULL;
if (ins_apply_autocmds(EVENT_INSERTCHARPRE)) {
// Get the value of v:char. It may be empty or more than one
// character. Only use it when changed, otherwise continue with the
// original character to avoid breaking autoindent.
if (STRCMP(buf, get_vim_var_str(VV_CHAR)) != 0) {
- res = vim_strsave((char_u *)get_vim_var_str(VV_CHAR));
+ res = xstrdup(get_vim_var_str(VV_CHAR));
}
}
@@ -4962,7 +4962,7 @@ static char_u *do_insert_char_pre(int c)
// Restore the State, it may have been changed.
State = save_State;
- return res;
+ return (char_u *)res;
}
bool get_can_cindent(void)
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 06ee4c8d81..0c41381313 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -3909,7 +3909,7 @@ char *partial_name(partial_T *pt)
FUNC_ATTR_PURE
{
if (pt->pt_name != NULL) {
- return (char *)pt->pt_name;
+ return pt->pt_name;
}
return (char *)pt->pt_func->uf_name;
}
@@ -3924,7 +3924,7 @@ static void partial_free(partial_T *pt)
xfree(pt->pt_argv);
tv_dict_unref(pt->pt_dict);
if (pt->pt_name != NULL) {
- func_unref(pt->pt_name);
+ func_unref((char_u *)pt->pt_name);
xfree(pt->pt_name);
} else {
func_ptr_unref(pt->pt_func);
@@ -4478,7 +4478,7 @@ bool set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, list_stack
// A partial does not have a copyID, because it cannot contain itself.
if (pt != NULL) {
- abort = set_ref_in_func(pt->pt_name, pt->pt_func, copyID);
+ abort = set_ref_in_func((char_u *)pt->pt_name, pt->pt_func, copyID);
if (pt->pt_dict != NULL) {
typval_T dtv;
@@ -4846,7 +4846,7 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map)
break;
}
- vimvars[VV_KEY].vv_str = (char *)vim_strsave(di->di_key);
+ vimvars[VV_KEY].vv_str = xstrdup((char *)di->di_key);
int r = filter_map_one(&di->di_tv, expr, map, &rem);
tv_clear(&vimvars[VV_KEY].vv_tv);
if (r == FAIL || did_emsg) {
@@ -5113,7 +5113,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref)
func_ptr_ref(pt->pt_func);
xfree(name);
} else {
- pt->pt_name = (char_u *)name;
+ pt->pt_name = name;
func_ref((char_u *)name);
}
@@ -6208,7 +6208,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl)
buf_T *buf = buflist_findnr((int)tv->vval.v_number);
if (buf) {
for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) {
- for (char *p = (char *)ml_get_buf(buf, lnum, false); *p != NUL; p++) {
+ for (char *p = ml_get_buf(buf, lnum, false); *p != NUL; p++) {
*len += 1;
}
*len += 1;
@@ -6226,7 +6226,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl)
char *ret = xmalloc((size_t)(*len) + 1);
char *end = ret;
for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) {
- for (char *p = (char *)ml_get_buf(buf, lnum, false); *p != NUL; p++) {
+ for (char *p = ml_get_buf(buf, lnum, false); *p != NUL; p++) {
*end++ = (*p == '\n') ? NUL : *p;
}
*end++ = '\n';
@@ -6275,7 +6275,7 @@ int buf_byteidx_to_charidx(buf_T *buf, linenr_T lnum, int byteidx)
lnum = buf->b_ml.ml_line_count;
}
- char *str = (char *)ml_get_buf(buf, lnum, false);
+ char *str = ml_get_buf(buf, lnum, false);
if (*str == NUL) {
return 0;
@@ -6313,7 +6313,7 @@ int buf_charidx_to_byteidx(buf_T *buf, linenr_T lnum, int charidx)
lnum = buf->b_ml.ml_line_count;
}
- char *str = (char *)ml_get_buf(buf, lnum, false);
+ char *str = ml_get_buf(buf, lnum, false);
// Convert the character offset to a byte offset
char *t = str;
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index 60a6ec6201..408b6e6cb5 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -849,7 +849,7 @@ static void get_col(typval_T *argvars, typval_T *rettv, bool charcol)
// col(".") when the cursor is on the NUL at the end of the line
// because of "coladd" can be seen as an extra column.
if (virtual_active() && fp == &curwin->w_cursor) {
- char *p = (char *)get_cursor_pos_ptr();
+ char *p = get_cursor_pos_ptr();
if (curwin->w_cursor.coladd >=
(colnr_T)win_chartabsize(curwin, p,
curwin->w_virtcol - curwin->w_cursor.coladd)) {
@@ -930,12 +930,12 @@ static void f_chdir(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
// Return the current directory
- char_u *cwd = xmalloc(MAXPATHL);
- if (os_dirname(cwd, MAXPATHL) != FAIL) {
+ char *cwd = xmalloc(MAXPATHL);
+ if (os_dirname((char_u *)cwd, MAXPATHL) != FAIL) {
#ifdef BACKSLASH_IN_FILENAME
slash_adjust(cwd);
#endif
- rettv->vval.v_string = (char *)vim_strsave(cwd);
+ rettv->vval.v_string = xstrdup(cwd);
}
xfree(cwd);
@@ -2016,10 +2016,9 @@ static void f_expand(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
options += WILD_ICASE;
}
if (rettv->v_type == VAR_STRING) {
- rettv->vval.v_string = (char *)ExpandOne(&xpc, (char_u *)s, NULL, options,
- WILD_ALL);
+ rettv->vval.v_string = ExpandOne(&xpc, (char *)s, NULL, options, WILD_ALL);
} else {
- ExpandOne(&xpc, (char_u *)s, NULL, options, WILD_ALL_KEEP);
+ ExpandOne(&xpc, (char *)s, NULL, options, WILD_ALL_KEEP);
tv_list_alloc_ret(rettv, xpc.xp_numfiles);
for (int i = 0; i < xpc.xp_numfiles; i++) {
tv_list_append_string(rettv->vval.v_list,
@@ -2437,7 +2436,7 @@ static void f_get(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
pt = argvars[0].vval.v_partial;
} else {
CLEAR_FIELD(fref_pt);
- fref_pt.pt_name = (char_u *)argvars[0].vval.v_string;
+ fref_pt.pt_name = argvars[0].vval.v_string;
pt = &fref_pt;
}
@@ -2579,9 +2578,8 @@ static void get_buffer_lines(buf_T *buf, linenr_T start, linenr_T end, int retli
}
} else {
rettv->v_type = VAR_STRING;
- rettv->vval.v_string =
- (char *)((start >= 1 && start <= buf->b_ml.ml_line_count)
- ? vim_strsave(ml_get_buf(buf, start, false)) : NULL);
+ rettv->vval.v_string = ((start >= 1 && start <= buf->b_ml.ml_line_count)
+ ? xstrdup(ml_get_buf(buf, start, false)) : NULL);
}
}
@@ -2919,7 +2917,7 @@ static void f_getftime(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
/// "getftype({fname})" function
static void f_getftype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
- char_u *type = NULL;
+ char *type = NULL;
char *t;
const char *fname = tv_get_string(&argvars[0]);
@@ -2945,9 +2943,9 @@ static void f_getftype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
} else {
t = "other";
}
- type = vim_strsave((char_u *)t);
+ type = xstrdup(t);
}
- rettv->vval.v_string = (char *)type;
+ rettv->vval.v_string = type;
}
/// "getjumplist()" function
@@ -3441,11 +3439,11 @@ static void f_glob(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
options += WILD_ICASE;
}
if (rettv->v_type == VAR_STRING) {
- rettv->vval.v_string = (char *)ExpandOne(&xpc, (char_u *)
- tv_get_string(&argvars[0]), NULL, options,
- WILD_ALL);
+ rettv->vval.v_string = ExpandOne(&xpc, (char *)
+ tv_get_string(&argvars[0]), NULL, options,
+ WILD_ALL);
} else {
- ExpandOne(&xpc, (char_u *)tv_get_string(&argvars[0]), NULL, options,
+ ExpandOne(&xpc, (char *)tv_get_string(&argvars[0]), NULL, options,
WILD_ALL_KEEP);
tv_list_alloc_ret(rettv, xpc.xp_numfiles);
for (int i = 0; i < xpc.xp_numfiles; i++) {
@@ -5443,11 +5441,11 @@ static void f_pathshorten(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
rettv->v_type = VAR_STRING;
- const char_u *p = (char_u *)tv_get_string_chk(&argvars[0]);
+ const char *p = tv_get_string_chk(&argvars[0]);
if (p == NULL) {
rettv->vval.v_string = NULL;
} else {
- rettv->vval.v_string = (char *)vim_strsave(p);
+ rettv->vval.v_string = xstrdup(p);
shorten_dir_len((char_u *)rettv->vval.v_string, trim_len);
}
}
@@ -5565,7 +5563,7 @@ static void f_prompt_getprompt(typval_T *argvars, typval_T *rettv, EvalFuncData
return;
}
- rettv->vval.v_string = (char *)vim_strsave(buf_prompt_text(buf));
+ rettv->vval.v_string = xstrdup(buf_prompt_text(buf));
}
/// "prompt_setprompt({buffer}, {text})" function
@@ -7107,7 +7105,7 @@ static void f_screenstring(typval_T *argvars, typval_T *rettv, EvalFuncData fptr
return;
}
- rettv->vval.v_string = (char *)vim_strsave(grid->chars[grid->line_offset[row] + (size_t)col]);
+ rettv->vval.v_string = xstrdup((char *)grid->chars[grid->line_offset[row] + (size_t)col]);
}
/// "search()" function
@@ -8052,7 +8050,7 @@ static void f_spellbadword(typval_T *argvars, typval_T *rettv, EvalFuncData fptr
// Find the start and length of the badly spelled word.
len = spell_move_to(curwin, FORWARD, true, true, &attr);
if (len != 0) {
- word = (char *)get_cursor_pos_ptr();
+ word = get_cursor_pos_ptr();
curwin->w_set_curswant = true;
}
} else if (*curbuf->b_s.b_p_spl != NUL) {
@@ -8740,7 +8738,7 @@ static void f_swapname(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|| buf->b_ml.ml_mfp->mf_fname == NULL) {
rettv->vval.v_string = NULL;
} else {
- rettv->vval.v_string = (char *)vim_strsave(buf->b_ml.ml_mfp->mf_fname);
+ rettv->vval.v_string = xstrdup(buf->b_ml.ml_mfp->mf_fname);
}
}
@@ -9101,7 +9099,7 @@ static void f_taglist(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
static void f_tempname(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
rettv->v_type = VAR_STRING;
- rettv->vval.v_string = (char *)vim_tempname();
+ rettv->vval.v_string = vim_tempname();
}
/// "termopen(cmd[, cwd])" function
@@ -9595,12 +9593,12 @@ static void f_virtcol(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
/// "visualmode()" function
static void f_visualmode(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
- char_u str[2];
+ char str[2];
rettv->v_type = VAR_STRING;
- str[0] = (char_u)curbuf->b_visual_mode_eval;
+ str[0] = (char)curbuf->b_visual_mode_eval;
str[1] = NUL;
- rettv->vval.v_string = (char *)vim_strsave(str);
+ rettv->vval.v_string = xstrdup(str);
// A non-zero number or non-empty string argument: reset mode.
if (non_zero_arg(&argvars[0])) {
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index a409271596..f6b97fe05b 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -2777,7 +2777,7 @@ static void tv_dict_list(typval_T *const tv, typval_T *const rettv, const DictLi
switch (what) {
case kDictListKeys:
tv_item.v_type = VAR_STRING;
- tv_item.vval.v_string = (char *)vim_strsave(di->di_key);
+ tv_item.vval.v_string = xstrdup((char *)di->di_key);
break;
case kDictListValues:
tv_copy(&di->di_tv, &tv_item);
diff --git a/src/nvim/eval/typval.h b/src/nvim/eval/typval.h
index 8177d01f90..cf7b04c8ce 100644
--- a/src/nvim/eval/typval.h
+++ b/src/nvim/eval/typval.h
@@ -360,15 +360,14 @@ struct ufunc {
};
struct partial_S {
- int pt_refcount; ///< Reference count.
- char_u *pt_name; ///< Function name; when NULL use pt_func->name.
- ufunc_T *pt_func; ///< Function pointer; when NULL lookup function with
- ///< pt_name.
- bool pt_auto; ///< When true the partial was created by using dict.member
- ///< in handle_subscript().
- int pt_argc; ///< Number of arguments.
+ int pt_refcount; ///< Reference count.
+ char *pt_name; ///< Function name; when NULL use pt_func->name.
+ ufunc_T *pt_func; ///< Function pointer; when NULL lookup function with pt_name.
+ bool pt_auto; ///< When true the partial was created by using dict.member
+ ///< in handle_subscript().
+ int pt_argc; ///< Number of arguments.
typval_T *pt_argv; ///< Arguments in allocated array.
- dict_T *pt_dict; ///< Dict for "self".
+ dict_T *pt_dict; ///< Dict for "self".
};
/// Structure used for explicit stack while garbage collecting hash tables
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index 3ab66c319f..36bc51179c 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -142,18 +142,18 @@ static int get_function_args(char **argp, char_u endchar, garray_T *newargs, int
any_default = true;
p = skipwhite(p) + 1;
p = skipwhite(p);
- char_u *expr = (char_u *)p;
+ char *expr = p;
if (eval1(&p, &rettv, false) != FAIL) {
ga_grow(default_args, 1);
// trim trailing whitespace
- while (p > (char *)expr && ascii_iswhite(p[-1])) {
+ while (p > expr && ascii_iswhite(p[-1])) {
p--;
}
c = (char_u)(*p);
*p = NUL;
- expr = vim_strsave(expr);
- ((char **)(default_args->ga_data))[default_args->ga_len] = (char *)expr;
+ expr = xstrdup(expr);
+ ((char **)(default_args->ga_data))[default_args->ga_len] = expr;
default_args->ga_len++;
*p = (char)c;
} else {
@@ -1680,7 +1680,7 @@ static void list_func_head(ufunc_T *fp, int indent, bool force)
char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, partial_T **partial)
FUNC_ATTR_NONNULL_ARG(1)
{
- char_u *name = NULL;
+ char *name = NULL;
const char_u *start;
const char_u *end;
int lead;
@@ -1739,7 +1739,7 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa
fdp->fd_di = lv.ll_di;
}
if (lv.ll_tv->v_type == VAR_FUNC && lv.ll_tv->vval.v_string != NULL) {
- name = vim_strsave((char_u *)lv.ll_tv->vval.v_string);
+ name = xstrdup(lv.ll_tv->vval.v_string);
*pp = (char *)end;
} else if (lv.ll_tv->v_type == VAR_PARTIAL
&& lv.ll_tv->vval.v_partial != NULL) {
@@ -1753,7 +1753,7 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa
memcpy(name, end + 1, (size_t)len);
*pp = (char *)end + 1 + len;
} else {
- name = vim_strsave((char_u *)partial_name(lv.ll_tv->vval.v_partial));
+ name = xstrdup(partial_name(lv.ll_tv->vval.v_partial));
*pp = (char *)end;
}
if (partial != NULL) {
@@ -1781,28 +1781,28 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa
// Check if the name is a Funcref. If so, use the value.
if (lv.ll_exp_name != NULL) {
len = (int)strlen(lv.ll_exp_name);
- name = deref_func_name(lv.ll_exp_name, &len, partial,
- flags & TFN_NO_AUTOLOAD);
+ name = (char *)deref_func_name(lv.ll_exp_name, &len, partial,
+ flags & TFN_NO_AUTOLOAD);
if ((const char *)name == lv.ll_exp_name) {
name = NULL;
}
} else if (!(flags & TFN_NO_DEREF)) {
len = (int)(end - (char_u *)(*pp));
- name = deref_func_name((const char *)(*pp), &len, partial,
- flags & TFN_NO_AUTOLOAD);
- if (name == (char_u *)(*pp)) {
+ name = (char *)deref_func_name((const char *)(*pp), &len, partial,
+ flags & TFN_NO_AUTOLOAD);
+ if (name == *pp) {
name = NULL;
}
}
if (name != NULL) {
- name = vim_strsave(name);
+ name = xstrdup(name);
*pp = (char *)end;
if (STRNCMP(name, "<SNR>", 5) == 0) {
// Change "<SNR>" to the byte sequence.
- name[0] = K_SPECIAL;
- name[1] = KS_EXTRA;
+ name[0] = (char)K_SPECIAL;
+ name[1] = (char)KS_EXTRA;
name[2] = KE_SNR;
- memmove(name + 3, name + 5, strlen((char *)name + 5) + 1);
+ memmove(name + 3, name + 5, strlen(name + 5) + 1);
}
goto theend;
}
@@ -1865,8 +1865,8 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa
name = xmalloc((size_t)len + (size_t)lead + 1);
if (!skip && lead > 0) {
- name[0] = K_SPECIAL;
- name[1] = KS_EXTRA;
+ name[0] = (char)K_SPECIAL;
+ name[1] = (char)KS_EXTRA;
name[2] = KE_SNR;
if (sid_buf_len > 0) { // If it's "<SID>"
memcpy(name + 3, sid_buf, sid_buf_len);
@@ -1878,7 +1878,7 @@ char_u *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, pa
theend:
clear_lval(&lv);
- return name;
+ return (char_u *)name;
}
#define MAX_FUNC_NESTING 50
@@ -3104,7 +3104,7 @@ char *get_return_cmd(void *rettv)
STRCPY(IObuff + IOSIZE - 4, "...");
}
xfree(tofree);
- return (char *)vim_strsave(IObuff);
+ return xstrdup((char *)IObuff);
}
/// Get next function line.
@@ -3192,7 +3192,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv)
} else {
fname = rettv->v_type == VAR_FUNC || rettv->v_type == VAR_STRING
? (char_u *)rettv->vval.v_string
- : rettv->vval.v_partial->pt_name;
+ : (char_u *)rettv->vval.v_partial->pt_name;
// Translate "s:func" to the stored function name.
fname = (char_u *)fname_trans_sid((char *)fname, (char *)fname_buf, (char **)&tofree, &error);
fp = find_func(fname);
@@ -3208,7 +3208,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv)
pt->pt_auto = true;
if (rettv->v_type == VAR_FUNC || rettv->v_type == VAR_STRING) {
// Just a function: Take over the function name and use selfdict.
- pt->pt_name = (char_u *)rettv->vval.v_string;
+ pt->pt_name = rettv->vval.v_string;
} else {
partial_T *ret_pt = rettv->vval.v_partial;
int i;
@@ -3217,8 +3217,8 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv)
// args. Can't take over name or args, the partial might
// be referenced elsewhere.
if (ret_pt->pt_name != NULL) {
- pt->pt_name = vim_strsave(ret_pt->pt_name);
- func_ref(pt->pt_name);
+ pt->pt_name = xstrdup(ret_pt->pt_name);
+ func_ref((char_u *)pt->pt_name);
} else {
pt->pt_func = ret_pt->pt_func;
func_ptr_ref(pt->pt_func);
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 8f256728e3..12920d932d 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -118,7 +118,7 @@ void do_ascii(const exarg_T *const eap)
{
char *dig;
int cc[MAX_MCO];
- int c = utfc_ptr2char((char *)get_cursor_pos_ptr(), cc);
+ int c = utfc_ptr2char(get_cursor_pos_ptr(), cc);
if (c == NUL) {
msg("NUL");
return;
@@ -1068,7 +1068,7 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n)
curwin->w_cursor.lnum = n;
while (line1 <= line2) {
- // need to use vim_strsave() because the line will be unlocked within
+ // need to use xstrdup() because the line will be unlocked within
// ml_append()
p = xstrdup(ml_get(line1));
ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, false);
@@ -1305,8 +1305,8 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b
curbuf->b_op_start.lnum = line1;
curbuf->b_op_end.lnum = line2;
curwin->w_cursor.lnum = line2;
- } else if ((do_in && (itmp = (char *)vim_tempname()) == NULL)
- || (do_out && (otmp = (char *)vim_tempname()) == NULL)) {
+ } else if ((do_in && (itmp = vim_tempname()) == NULL)
+ || (do_out && (otmp = vim_tempname()) == NULL)) {
emsg(_(e_notmp));
goto filterend;
}
@@ -3291,7 +3291,7 @@ static bool sub_joining_lines(exarg_T *eap, char *pat, char *sub, char *cmd, boo
if (save) {
if ((cmdmod.cmod_flags & CMOD_KEEPPATTERNS) == 0) {
- save_re_pat(RE_SUBST, (char_u *)pat, p_magic);
+ save_re_pat(RE_SUBST, pat, p_magic);
}
// put pattern in history
add_to_history(HIST_SEARCH, pat, true, NUL);
@@ -3608,7 +3608,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T
sub = xstrdup(sub);
sub_copy = sub;
} else {
- char *newsub = (char *)regtilde((char_u *)sub, p_magic, cmdpreview);
+ char *newsub = regtilde(sub, p_magic, cmdpreview);
if (newsub != sub) {
// newsub was allocated, free it later.
sub_copy = newsub;
@@ -4782,7 +4782,7 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i
if (next_linenr == orig_buf->b_ml.ml_line_count + 1) {
line = "";
} else {
- line = (char *)ml_get_buf(orig_buf, next_linenr, false);
+ line = ml_get_buf(orig_buf, next_linenr, false);
line_size = strlen(line) + (size_t)col_width + 1;
// Reallocate if line not long enough
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 8fb166d2c9..e32eb860ce 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -785,7 +785,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
vim_snprintf((char *)IObuff, IOSIZE,
_("E605: Exception not caught: %s"),
current_exception->value);
- p = (char *)vim_strsave(IObuff);
+ p = xstrdup((char *)IObuff);
break;
case ET_ERROR:
messages = current_exception->messages;
@@ -1300,7 +1300,7 @@ static void parse_register(exarg_T *eap)
// for '=' register: accept the rest of the line as an expression
if (eap->arg[-1] == '=' && eap->arg[0] != NUL) {
if (!eap->skip) {
- set_expr_line(vim_strsave((char_u *)eap->arg));
+ set_expr_line(xstrdup(eap->arg));
}
eap->arg += STRLEN(eap->arg);
}
@@ -3829,7 +3829,7 @@ int expand_filename(exarg_T *eap, char **cmdlinep, char **errormsgp)
if (p_wic) {
options += WILD_ICASE;
}
- p = (char *)ExpandOne(&xpc, (char_u *)eap->arg, NULL, options, WILD_EXPAND_FREE);
+ p = ExpandOne(&xpc, eap->arg, NULL, options, WILD_EXPAND_FREE);
if (p == NULL) {
return FAIL;
}
@@ -5274,7 +5274,7 @@ static void ex_swapname(exarg_T *eap)
if (curbuf->b_ml.ml_mfp == NULL || curbuf->b_ml.ml_mfp->mf_fname == NULL) {
msg(_("No swap file"));
} else {
- msg((char *)curbuf->b_ml.ml_mfp->mf_fname);
+ msg(curbuf->b_ml.ml_mfp->mf_fname);
}
}
@@ -6563,7 +6563,7 @@ static void ex_tag_cmd(exarg_T *eap, char *name)
cmd = DT_LTAG;
}
- do_tag((char_u *)eap->arg, cmd, eap->addr_count > 0 ? (int)eap->line2 : 1,
+ do_tag(eap->arg, cmd, eap->addr_count > 0 ? (int)eap->line2 : 1,
eap->forceit, true);
}
diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c
index 20725b81ee..f40149d07a 100644
--- a/src/nvim/ex_eval.c
+++ b/src/nvim/ex_eval.c
@@ -529,7 +529,7 @@ static void discard_exception(except_T *excp, bool was_finished)
if (p_verbose >= 13 || debug_break_level > 0) {
int save_msg_silent = msg_silent;
- saved_IObuff = (char *)vim_strsave(IObuff);
+ saved_IObuff = xstrdup((char *)IObuff);
if (debug_break_level > 0) {
msg_silent = false; // display messages
} else {
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index da99a03c38..cf95287d61 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -105,7 +105,7 @@ typedef struct command_line_state {
int c;
int gotesc; // true when <ESC> just typed
int do_abbr; // when true check for abbr.
- char_u *lookfor; // string to match
+ char *lookfor; // string to match
int hiscnt; // current history line in use
int save_hiscnt; // history line before attempting
// to jump to next match
@@ -116,7 +116,7 @@ typedef struct command_line_state {
int res;
int save_msg_scroll;
int save_State; // remember State when called
- char_u *save_p_icm;
+ char *save_p_icm;
int some_key_typed; // one of the keys was typed
// mouse drag and release events are ignored, unless they are
// preceded with a mouse down event
@@ -632,7 +632,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init
.ignore_drag_release = true,
};
CommandLineState *s = &state;
- s->save_p_icm = vim_strsave((char_u *)p_icm);
+ s->save_p_icm = xstrdup(p_icm);
init_incsearch_state(&s->is_state);
CmdlineInfo save_ccline;
bool did_save_ccline = false;
@@ -879,7 +879,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init
need_wait_return = false;
}
- set_string_option_direct("icm", -1, (char *)s->save_p_icm, OPT_FREE, SID_NONE);
+ set_string_option_direct("icm", -1, s->save_p_icm, OPT_FREE, SID_NONE);
State = s->save_State;
if (cmdpreview != save_cmdpreview) {
cmdpreview = save_cmdpreview; // restore preview state
@@ -1087,7 +1087,7 @@ static int command_line_execute(VimState *state, int key)
s->c = get_expr_register();
if (s->c == '=') {
textlock++;
- p = get_expr_line();
+ p = (char_u *)get_expr_line();
textlock--;
if (p != NULL) {
@@ -1853,7 +1853,7 @@ static int command_line_handle_key(CommandLineState *s)
// save current command string so it can be restored later
if (s->lookfor == NULL) {
- s->lookfor = vim_strsave((char_u *)ccline.cmdbuff);
+ s->lookfor = xstrdup(ccline.cmdbuff);
s->lookfor[ccline.cmdpos] = NUL;
}
@@ -1870,13 +1870,13 @@ static int command_line_handle_key(CommandLineState *s)
XFREE_CLEAR(ccline.cmdbuff);
s->xpc.xp_context = EXPAND_NOTHING;
if (s->hiscnt == get_hislen()) {
- p = s->lookfor; // back to the old one
+ p = (char_u *)s->lookfor; // back to the old one
} else {
p = (char_u *)get_histentry(s->histype)[s->hiscnt].hisstr;
}
if (s->histype == HIST_SEARCH
- && p != s->lookfor
+ && p != (char_u *)s->lookfor
&& (old_firstc = p[STRLEN(p) + 1]) != s->firstc) {
// Correct for the separator character used when
// adding the history entry vs the one used now.
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index 76a429b5ef..5416be651d 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -69,7 +69,7 @@
#include "nvim/vim.h"
#include "nvim/window.h"
-static char_u *ff_expand_buffer = NULL; // used for expanding filenames
+static char *ff_expand_buffer = NULL; // used for expanding filenames
// type for the directory search stack
typedef struct ff_stack {
@@ -105,7 +105,7 @@ typedef struct ff_visited {
// Visited directories are different if the wildcard string are
// different. So we have to save it.
- char_u *ffv_wc_path;
+ char *ffv_wc_path;
// use FileID for comparison (needed because of links), else use filename.
bool file_id_valid;
@@ -131,7 +131,7 @@ typedef struct ff_visited_list_hdr {
struct ff_visited_list_hdr *ffvl_next;
// the filename the attached visited list is for
- char_u *ffvl_filename;
+ char *ffvl_filename;
ff_visited_T *ffvl_visited_list;
} ff_visited_list_hdr_T;
@@ -259,12 +259,12 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
// Reuse old visited lists. Get the visited list for the given
// filename. If no list for the current filename exists, creates a new
// one.
- search_ctx->ffsc_visited_list = ff_get_visited_list((char_u *)filename,
+ search_ctx->ffsc_visited_list = ff_get_visited_list(filename,
&search_ctx->ffsc_visited_lists_list);
if (search_ctx->ffsc_visited_list == NULL) {
goto error_return;
}
- search_ctx->ffsc_dir_visited_list = ff_get_visited_list((char_u *)filename,
+ search_ctx->ffsc_dir_visited_list = ff_get_visited_list(filename,
&search_ctx->ffsc_dir_visited_lists_list);
if (search_ctx->ffsc_dir_visited_list == NULL) {
goto error_return;
@@ -286,7 +286,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
if (!vim_isAbsName((char_u *)rel_fname) && len + 1 < MAXPATHL) {
// Make the start dir an absolute path name.
STRLCPY(ff_expand_buffer, rel_fname, len + 1);
- search_ctx->ffsc_start_dir = FullName_save((char *)ff_expand_buffer, false);
+ search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, false);
} else {
search_ctx->ffsc_start_dir = xstrnsave(rel_fname, len);
}
@@ -310,11 +310,11 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
path += 2;
} else
#endif
- if (os_dirname(ff_expand_buffer, MAXPATHL) == FAIL) {
+ if (os_dirname((char_u *)ff_expand_buffer, MAXPATHL) == FAIL) {
goto error_return;
}
- search_ctx->ffsc_start_dir = (char *)vim_strsave(ff_expand_buffer);
+ search_ctx->ffsc_start_dir = xstrdup(ff_expand_buffer);
#ifdef BACKSLASH_IN_FILENAME
// A path that starts with "/dir" is relative to the drive, not to the
@@ -396,12 +396,12 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
break;
}
if (STRNCMP(wc_part, "**", 2) == 0) {
- ff_expand_buffer[len++] = (char_u)(*wc_part++);
- ff_expand_buffer[len++] = (char_u)(*wc_part++);
+ ff_expand_buffer[len++] = *wc_part++;
+ ff_expand_buffer[len++] = *wc_part++;
llevel = strtol(wc_part, &errpt, 10);
if (errpt != wc_part && llevel > 0 && llevel < 255) {
- ff_expand_buffer[len++] = (char_u)llevel;
+ ff_expand_buffer[len++] = (char)llevel;
} else if (errpt != wc_part && llevel == 0) {
// restrict is 0 -> remove already added '**'
len -= 2;
@@ -416,11 +416,11 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
goto error_return;
}
} else {
- ff_expand_buffer[len++] = (char_u)(*wc_part++);
+ ff_expand_buffer[len++] = *wc_part++;
}
}
ff_expand_buffer[len] = NUL;
- search_ctx->ffsc_wc_path = (char *)vim_strsave(ff_expand_buffer);
+ search_ctx->ffsc_wc_path = xstrdup(ff_expand_buffer);
} else {
search_ctx->ffsc_fix_path = xstrdup(path);
}
@@ -439,7 +439,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
goto error_return;
}
STRCPY(ff_expand_buffer, search_ctx->ffsc_start_dir);
- add_pathsep((char *)ff_expand_buffer);
+ add_pathsep(ff_expand_buffer);
{
size_t eb_len = STRLEN(ff_expand_buffer);
char_u *buf = xmalloc(eb_len + STRLEN(search_ctx->ffsc_fix_path) + 1);
@@ -448,7 +448,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
STRCPY(buf + eb_len, search_ctx->ffsc_fix_path);
if (os_isdir((char *)buf)) {
STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path);
- add_pathsep((char *)ff_expand_buffer);
+ add_pathsep(ff_expand_buffer);
} else {
char *p = path_tail(search_ctx->ffsc_fix_path);
char *wc_path = NULL;
@@ -464,7 +464,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
goto error_return;
}
STRLCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, eb_len + (size_t)len + 1);
- add_pathsep((char *)ff_expand_buffer);
+ add_pathsep(ff_expand_buffer);
} else {
len = (int)STRLEN(search_ctx->ffsc_fix_path);
}
@@ -484,7 +484,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
xfree(buf);
}
- sptr = ff_create_stack_element(ff_expand_buffer, (char_u *)search_ctx->ffsc_wc_path, level, 0);
+ sptr = ff_create_stack_element(ff_expand_buffer, search_ctx->ffsc_wc_path, level, 0);
ff_push(search_ctx, sptr);
search_ctx->ffsc_file_to_search = xstrdup(filename);
@@ -607,7 +607,7 @@ char_u *vim_findfile(void *search_ctx_arg)
// first time (hence stackp->ff_filearray == NULL)
if (stackp->ffs_filearray == NULL
&& ff_check_visited(&search_ctx->ffsc_dir_visited_list->ffvl_visited_list,
- stackp->ffs_fix_path, stackp->ffs_wc_path) == FAIL) {
+ (char *)stackp->ffs_fix_path, (char *)stackp->ffs_wc_path) == FAIL) {
#ifdef FF_VERBOSE
if (p_verbose >= 5) {
verbose_enter_scroll();
@@ -787,7 +787,7 @@ char_u *vim_findfile(void *search_ctx_arg)
== os_isdir((char *)file_path)))))
#ifndef FF_VERBOSE
&& (ff_check_visited(&search_ctx->ffsc_visited_list->ffvl_visited_list,
- file_path, (char_u *)"") == OK)
+ (char *)file_path, "") == OK)
#endif
) {
#ifdef FF_VERBOSE
@@ -811,10 +811,10 @@ char_u *vim_findfile(void *search_ctx_arg)
if (!path_with_url((char *)file_path)) {
simplify_filename(file_path);
}
- if (os_dirname(ff_expand_buffer, MAXPATHL)
+ if (os_dirname((char_u *)ff_expand_buffer, MAXPATHL)
== OK) {
p = path_shorten_fname(file_path,
- ff_expand_buffer);
+ (char_u *)ff_expand_buffer);
if (p != NULL) {
STRMOVE(file_path, p);
}
@@ -845,8 +845,8 @@ char_u *vim_findfile(void *search_ctx_arg)
continue; // not a directory
}
ff_push(search_ctx,
- ff_create_stack_element((char_u *)stackp->ffs_filearray[i],
- rest_of_wildcards,
+ ff_create_stack_element(stackp->ffs_filearray[i],
+ (char *)rest_of_wildcards,
stackp->ffs_level - 1, 0));
}
}
@@ -867,8 +867,8 @@ char_u *vim_findfile(void *search_ctx_arg)
continue; // not a directory
}
ff_push(search_ctx,
- ff_create_stack_element((char_u *)stackp->ffs_filearray[i],
- stackp->ffs_wc_path, stackp->ffs_level - 1, 1));
+ ff_create_stack_element(stackp->ffs_filearray[i],
+ (char *)stackp->ffs_wc_path, stackp->ffs_level - 1, 1));
}
}
@@ -914,8 +914,8 @@ char_u *vim_findfile(void *search_ctx_arg)
STRCAT(file_path, search_ctx->ffsc_fix_path);
// create a new stack entry
- sptr = ff_create_stack_element(file_path,
- (char_u *)search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0);
+ sptr = ff_create_stack_element((char *)file_path,
+ search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0);
ff_push(search_ctx, sptr);
} else {
break;
@@ -972,7 +972,7 @@ static void ff_free_visited_list(ff_visited_T *vl)
/// @return the already visited list for the given filename. If none is found it
/// allocates a new one.
-static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename,
+static ff_visited_list_hdr_T *ff_get_visited_list(char *filename,
ff_visited_list_hdr_T **list_headp)
{
ff_visited_list_hdr_T *retptr = NULL;
@@ -1009,7 +1009,7 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename,
retptr = xmalloc(sizeof(*retptr));
retptr->ffvl_visited_list = NULL;
- retptr->ffvl_filename = vim_strsave(filename);
+ retptr->ffvl_filename = xstrdup(filename);
retptr->ffvl_next = *list_headp;
*list_headp = retptr;
@@ -1060,7 +1060,7 @@ static bool ff_wc_equal(char_u *s1, char_u *s2)
///
/// @return FAIL if the given file/dir is already in the list or,
/// OK if it is newly added
-static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *wc_path)
+static int ff_check_visited(ff_visited_T **visited_list, char *fname, char *wc_path)
{
ff_visited_T *vp;
bool url = false;
@@ -1068,12 +1068,12 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *
FileID file_id;
// For a URL we only compare the name, otherwise we compare the
// device/inode.
- if (path_with_url((char *)fname)) {
+ if (path_with_url(fname)) {
STRLCPY(ff_expand_buffer, fname, MAXPATHL);
url = true;
} else {
ff_expand_buffer[0] = NUL;
- if (!os_fileid((char *)fname, &file_id)) {
+ if (!os_fileid(fname, &file_id)) {
return FAIL;
}
}
@@ -1084,7 +1084,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *
|| (!url && vp->file_id_valid
&& os_fileid_equal(&(vp->file_id), &file_id))) {
// are the wildcard parts equal
- if (ff_wc_equal(vp->ffv_wc_path, wc_path)) {
+ if (ff_wc_equal((char_u *)vp->ffv_wc_path, (char_u *)wc_path)) {
// already visited
return FAIL;
}
@@ -1104,7 +1104,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *
}
if (wc_path != NULL) {
- vp->ffv_wc_path = vim_strsave(wc_path);
+ vp->ffv_wc_path = xstrdup(wc_path);
} else {
vp->ffv_wc_path = NULL;
}
@@ -1116,7 +1116,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *
}
/// create stack element from given path pieces
-static ff_stack_T *ff_create_stack_element(char_u *fix_part, char_u *wc_part, int level,
+static ff_stack_T *ff_create_stack_element(char *fix_part, char *wc_part, int level,
int star_star_empty)
{
ff_stack_T *new = xmalloc(sizeof(ff_stack_T));
@@ -1131,14 +1131,14 @@ static ff_stack_T *ff_create_stack_element(char_u *fix_part, char_u *wc_part, in
// the following saves NULL pointer checks in vim_findfile
if (fix_part == NULL) {
- fix_part = (char_u *)"";
+ fix_part = "";
}
- new->ffs_fix_path = vim_strsave(fix_part);
+ new->ffs_fix_path = (char_u *)xstrdup(fix_part);
if (wc_part == NULL) {
- wc_part = (char_u *)"";
+ wc_part = "";
}
- new->ffs_wc_path = vim_strsave(wc_part);
+ new->ffs_wc_path = (char_u *)xstrdup(wc_part);
return new;
}
@@ -1292,7 +1292,7 @@ char_u *find_file_in_path(char_u *ptr, size_t len, int options, int first, char_
FINDFILE_BOTH, rel_fname, (char_u *)curbuf->b_p_sua);
}
-static char_u *ff_file_to_find = NULL;
+static char *ff_file_to_find = NULL;
static void *fdip_search_ctx = NULL;
#if defined(EXITFREE)
@@ -1338,7 +1338,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first
static char *dir;
static int did_findfile_init = false;
char_u save_char;
- char_u *file_name = NULL;
+ char *file_name = NULL;
char *buf = NULL;
int rel_to_curdir;
@@ -1359,10 +1359,10 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first
ptr[len] = save_char;
xfree(ff_file_to_find);
- ff_file_to_find = vim_strsave((char_u *)NameBuff);
+ ff_file_to_find = xstrdup(NameBuff);
if (options & FNAME_UNESC) {
// Change all "\ " to " ".
- for (ptr = ff_file_to_find; *ptr != NUL; ptr++) {
+ for (ptr = (char_u *)ff_file_to_find; *ptr != NUL; ptr++) {
if (ptr[0] == '\\' && ptr[1] == ' ') {
memmove(ptr, ptr + 1, STRLEN(ptr));
}
@@ -1376,7 +1376,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first
|| (ff_file_to_find[1] == '.'
&& (ff_file_to_find[2] == NUL
|| vim_ispathsep(ff_file_to_find[2])))));
- if (vim_isAbsName(ff_file_to_find)
+ if (vim_isAbsName((char_u *)ff_file_to_find)
// "..", "../path", "." and "./path": don't use the path_option
|| rel_to_curdir
#if defined(WIN32)
@@ -1390,8 +1390,8 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first
// If this is not a first call, return NULL. We already returned a
// filename on the first call.
if (first == true) {
- if (path_with_url((char *)ff_file_to_find)) {
- file_name = vim_strsave(ff_file_to_find);
+ if (path_with_url(ff_file_to_find)) {
+ file_name = xstrdup(ff_file_to_find);
goto theend;
}
@@ -1420,7 +1420,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first
&& (find_what == FINDFILE_BOTH
|| ((find_what == FINDFILE_DIR)
== os_isdir(NameBuff))))) {
- file_name = vim_strsave((char_u *)NameBuff);
+ file_name = xstrdup(NameBuff);
goto theend;
}
if (*buf == NUL) {
@@ -1444,7 +1444,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first
for (;;) {
if (did_findfile_init) {
- file_name = vim_findfile(fdip_search_ctx);
+ file_name = (char *)vim_findfile(fdip_search_ctx);
if (file_name != NULL) {
break;
}
@@ -1468,7 +1468,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first
// get the stopdir string
r_ptr = vim_findfile_stopdir((char_u *)buf);
- fdip_search_ctx = vim_findfile_init(buf, (char *)ff_file_to_find,
+ fdip_search_ctx = vim_findfile_init(buf, ff_file_to_find,
(char *)r_ptr, 100, false, find_what,
fdip_search_ctx, false, (char *)rel_fname);
if (fdip_search_ctx != NULL) {
@@ -1499,7 +1499,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first
}
theend:
- return file_name;
+ return (char_u *)file_name;
}
void do_autocmd_dirchanged(char *new_dir, CdScope scope, CdCause cause, bool pre)
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index b399885095..0d8eec1023 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -2049,7 +2049,7 @@ static char_u *readfile_charconvert(char_u *fname, char_u *fenc, int *fdp)
char_u *tmpname;
char *errmsg = NULL;
- tmpname = vim_tempname();
+ tmpname = (char_u *)vim_tempname();
if (tmpname == NULL) {
errmsg = _("Can't find temp file for conversion");
} else {
@@ -2697,7 +2697,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en
}
}
- rootname = (char *)get_file_in_dir((char_u *)fname, IObuff);
+ rootname = get_file_in_dir(fname, (char *)IObuff);
if (rootname == NULL) {
some_error = true; // out of memory
goto nobackup;
@@ -2847,7 +2847,7 @@ nobackup:
}
if (backup == NULL) {
- rootname = (char *)get_file_in_dir((char_u *)fname, IObuff);
+ rootname = get_file_in_dir(fname, (char *)IObuff);
if (rootname == NULL) {
backup = NULL;
} else {
@@ -2993,7 +2993,7 @@ nobackup:
// writing, write to a temp file instead and let the conversion
// overwrite the original file.
if (*p_ccv != NUL) {
- wfname = (char *)vim_tempname();
+ wfname = vim_tempname();
if (wfname == NULL) { // Can't write without a tempfile!
SET_ERRMSG(_("E214: Can't find temp file for writing"));
goto restore_backup;
@@ -3170,7 +3170,7 @@ restore_backup:
for (lnum = start; lnum <= end; lnum++) {
// The next while loop is done once for each character written.
// Keep it fast!
- ptr = (char *)ml_get_buf(buf, lnum, false) - 1;
+ ptr = ml_get_buf(buf, lnum, false) - 1;
if (write_undo_file) {
sha256_update(&sha_ctx, (char_u *)ptr + 1, (uint32_t)(STRLEN(ptr + 1) + 1));
}
@@ -4704,13 +4704,13 @@ static int move_lines(buf_T *frombuf, buf_T *tobuf)
buf_T *tbuf = curbuf;
int retval = OK;
linenr_T lnum;
- char_u *p;
+ char *p;
// Copy the lines in "frombuf" to "tobuf".
curbuf = tobuf;
for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; lnum++) {
- p = vim_strsave(ml_get_buf(frombuf, lnum, false));
- if (ml_append(lnum - 1, (char *)p, 0, false) == FAIL) {
+ p = xstrdup(ml_get_buf(frombuf, lnum, false));
+ if (ml_append(lnum - 1, p, 0, false) == FAIL) {
xfree(p);
retval = FAIL;
break;
@@ -5358,7 +5358,7 @@ static bool vim_settempdir(char *tempdir)
///
/// @return pointer to the temp file name or NULL if Nvim can't create
/// temporary directory for its own temporary files.
-char_u *vim_tempname(void)
+char *vim_tempname(void)
{
// Temp filename counter.
static uint64_t temp_count;
@@ -5370,10 +5370,10 @@ char_u *vim_tempname(void)
// There is no need to check if the file exists, because we own the directory
// and nobody else creates a file in it.
- char_u template[TEMP_FILE_PATH_MAXLEN];
- snprintf((char *)template, TEMP_FILE_PATH_MAXLEN,
+ char template[TEMP_FILE_PATH_MAXLEN];
+ snprintf(template, TEMP_FILE_PATH_MAXLEN,
"%s%" PRIu64, tempdir, temp_count++);
- return vim_strsave(template);
+ return xstrdup(template);
}
/// Tries matching a filename with a "pattern" ("prog" is NULL), or use the
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index 0f085df3d0..2e8d282ede 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -1582,7 +1582,7 @@ static void foldAddMarker(buf_T *buf, pos_T pos, const char *marker, size_t mark
linenr_T lnum = pos.lnum;
// Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end
- char *line = (char *)ml_get_buf(buf, lnum, false);
+ char *line = ml_get_buf(buf, lnum, false);
size_t line_len = STRLEN(line);
size_t added = 0;
@@ -1640,7 +1640,7 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char *marker, size_t marker
}
char *cms = buf->b_p_cms;
- char *line = (char *)ml_get_buf(buf, lnum, false);
+ char *line = ml_get_buf(buf, lnum, false);
for (char *p = line; *p != NUL; p++) {
if (STRNCMP(p, marker, markerlen) != 0) {
continue;
@@ -2848,7 +2848,7 @@ static void foldlevelIndent(fline_T *flp)
linenr_T lnum = flp->lnum + flp->off;
buf_T *buf = flp->wp->w_buffer;
- char *s = skipwhite((char *)ml_get_buf(buf, lnum, false));
+ char *s = skipwhite(ml_get_buf(buf, lnum, false));
// empty line or lines starting with a character in 'foldignore': level
// depends on surrounding lines
@@ -3010,7 +3010,7 @@ static void foldlevelMarker(fline_T *flp)
flp->start = 0;
flp->lvl_next = flp->lvl;
- char *s = (char *)ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, false);
+ char *s = ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, false);
while (*s) {
if (*s == cstart
&& STRNCMP(s + 1, startmarker, foldstartmarkerlen - 1) == 0) {
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index e125d88395..0f0e3aece1 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -1708,26 +1708,26 @@ static void getchar_common(typval_T *argvars, typval_T *rettv)
rettv->vval.v_number = n;
if (n != 0 && (IS_SPECIAL(n) || mod_mask != 0)) {
- char_u temp[10]; // modifier: 3, mbyte-char: 6, NUL: 1
+ char temp[10]; // modifier: 3, mbyte-char: 6, NUL: 1
int i = 0;
// Turn a special key into three bytes, plus modifier.
if (mod_mask != 0) {
- temp[i++] = K_SPECIAL;
- temp[i++] = KS_MODIFIER;
- temp[i++] = (char_u)mod_mask;
+ temp[i++] = (char)K_SPECIAL;
+ temp[i++] = (char)KS_MODIFIER;
+ temp[i++] = (char)mod_mask;
}
if (IS_SPECIAL(n)) {
- temp[i++] = K_SPECIAL;
- temp[i++] = (char_u)K_SECOND(n);
- temp[i++] = K_THIRD(n);
+ temp[i++] = (char)K_SPECIAL;
+ temp[i++] = (char)K_SECOND(n);
+ temp[i++] = (char)K_THIRD(n);
} else {
- i += utf_char2bytes((int)n, (char *)temp + i);
+ i += utf_char2bytes((int)n, temp + i);
}
assert(i < 10);
temp[i++] = NUL;
rettv->v_type = VAR_STRING;
- rettv->vval.v_string = (char *)vim_strsave(temp);
+ rettv->vval.v_string = xstrdup(temp);
if (is_mouse_key((int)n)) {
int row = mouse_row;
@@ -2135,7 +2135,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
// complete match
if (keylen >= 0 && keylen <= typebuf.tb_len) {
- char_u *map_str = NULL;
+ char *map_str = NULL;
// Write chars to script file(s).
// Note: :lmap mappings are written *after* being applied. #5658
@@ -2175,8 +2175,8 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
char save_m_expr = mp->m_expr;
int save_m_noremap = mp->m_noremap;
char save_m_silent = mp->m_silent;
- char_u *save_m_keys = NULL; // only saved when needed
- char_u *save_m_str = NULL; // only saved when needed
+ char *save_m_keys = NULL; // only saved when needed
+ char *save_m_str = NULL; // only saved when needed
LuaRef save_m_luaref = mp->m_luaref;
// Handle ":map <expr>": evaluate the {rhs} as an
@@ -2193,9 +2193,9 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
vgetc_busy = 0;
may_garbage_collect = false;
- save_m_keys = vim_strsave(mp->m_keys);
+ save_m_keys = xstrdup((char *)mp->m_keys);
if (save_m_luaref == LUA_NOREF) {
- save_m_str = vim_strsave((char_u *)mp->m_str);
+ save_m_str = xstrdup(mp->m_str);
}
map_str = eval_map_expr(mp, NUL);
@@ -2207,13 +2207,13 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
// If an error was displayed and the expression returns an empty
// string, generate a <Nop> to allow for a redraw.
if (prev_did_emsg != did_emsg && (map_str == NULL || *map_str == NUL)) {
- char_u buf[4];
+ char buf[4];
xfree(map_str);
- buf[0] = K_SPECIAL;
- buf[1] = KS_EXTRA;
+ buf[0] = (char)K_SPECIAL;
+ buf[1] = (char)KS_EXTRA;
buf[2] = KE_IGNORE;
buf[3] = NUL;
- map_str = vim_strsave(buf);
+ map_str = xstrdup(buf);
if (State & MODE_CMDLINE) {
// redraw the command below the error
msg_didout = true;
@@ -2227,7 +2227,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
vgetc_busy = save_vgetc_busy;
may_garbage_collect = save_may_garbage_collect;
} else {
- map_str = (char_u *)mp->m_str;
+ map_str = mp->m_str;
}
// Insert the 'to' part in the typebuf.tb_buf.
@@ -2242,18 +2242,18 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
// If this is a LANGMAP mapping, then we didn't record the keys
// at the start of the function and have to record them now.
if (keylen > typebuf.tb_maplen && (mp->m_mode & MODE_LANGMAP) != 0) {
- gotchars(map_str, STRLEN(map_str));
+ gotchars((char_u *)map_str, STRLEN(map_str));
}
if (save_m_noremap != REMAP_YES) {
noremap = save_m_noremap;
- } else if (STRNCMP(map_str, save_m_keys != NULL ? save_m_keys : mp->m_keys,
+ } else if (STRNCMP(map_str, save_m_keys != NULL ? save_m_keys : (char *)mp->m_keys,
(size_t)keylen) != 0) {
noremap = REMAP_YES;
} else {
noremap = REMAP_SKIP;
}
- i = ins_typebuf((char *)map_str, noremap, 0, true, cmd_silent || save_m_silent);
+ i = ins_typebuf(map_str, noremap, 0, true, cmd_silent || save_m_silent);
if (save_m_expr) {
xfree(map_str);
}
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 060db3b3b1..84c01e0140 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -599,7 +599,7 @@ EXTERN int inhibit_delete_count INIT(= 0);
#define DBCS_DEBUG (-1)
/// Encoding used when 'fencs' is set to "default"
-EXTERN char_u *fenc_default INIT(= NULL);
+EXTERN char *fenc_default INIT(= NULL);
/// "State" is the main state of Vim.
/// There are other variables that modify the state:
diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c
index 85f59f39de..903349dcae 100644
--- a/src/nvim/hardcopy.c
+++ b/src/nvim/hardcopy.c
@@ -2292,7 +2292,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
// If the user didn't specify a file name, use a temp file.
if (psettings->outfile == NULL) {
- prt_ps_file_name = vim_tempname();
+ prt_ps_file_name = (char_u *)vim_tempname();
if (prt_ps_file_name == NULL) {
emsg(_(e_notmp));
return FAIL;
diff --git a/src/nvim/help.c b/src/nvim/help.c
index 245d80489f..235f64744a 100644
--- a/src/nvim/help.c
+++ b/src/nvim/help.c
@@ -180,7 +180,7 @@ void ex_help(exarg_T *eap)
// It is needed for do_tag top open folds under the cursor.
KeyTyped = old_KeyTyped;
- do_tag((char_u *)tag, DT_HELP, 1, false, true);
+ do_tag(tag, DT_HELP, 1, false, true);
// Delete the empty buffer if we're not using it. Careful: autocommands
// may have jumped to another window, check that the buffer is not in a
@@ -658,13 +658,13 @@ void fix_help_buffer(void)
if (!syntax_present(curwin)) {
for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) {
- line = (char *)ml_get_buf(curbuf, lnum, false);
+ line = ml_get_buf(curbuf, lnum, false);
const size_t len = STRLEN(line);
if (in_example && len > 0 && !ascii_iswhite(line[0])) {
// End of example: non-white or '<' in first column.
if (line[0] == '<') {
// blank-out a '<' in the first column
- line = (char *)ml_get_buf(curbuf, lnum, true);
+ line = ml_get_buf(curbuf, lnum, true);
line[0] = ' ';
}
in_example = false;
@@ -672,12 +672,12 @@ void fix_help_buffer(void)
if (!in_example && len > 0) {
if (line[len - 1] == '>' && (len == 1 || line[len - 2] == ' ')) {
// blank-out a '>' in the last column (start of example)
- line = (char *)ml_get_buf(curbuf, lnum, true);
+ line = ml_get_buf(curbuf, lnum, true);
line[len - 1] = ' ';
in_example = true;
} else if (line[len - 1] == '~') {
// blank-out a '~' at the end of line (header marker)
- line = (char *)ml_get_buf(curbuf, lnum, true);
+ line = ml_get_buf(curbuf, lnum, true);
line[len - 1] = ' ';
}
}
@@ -694,7 +694,7 @@ void fix_help_buffer(void)
&& TOLOWER_ASC(fname[7]) == 'x'
&& fname[8] == NUL)) {
for (lnum = 1; lnum < curbuf->b_ml.ml_line_count; lnum++) {
- line = (char *)ml_get_buf(curbuf, lnum, false);
+ line = ml_get_buf(curbuf, lnum, false);
if (strstr(line, "*local-additions*") == NULL) {
continue;
}
@@ -1167,8 +1167,7 @@ void ex_helptags(exarg_T *eap)
} else {
ExpandInit(&xpc);
xpc.xp_context = EXPAND_DIRECTORIES;
- dirname = (char *)ExpandOne(&xpc, (char_u *)eap->arg, NULL,
- WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE);
+ dirname = ExpandOne(&xpc, eap->arg, NULL, WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE);
if (dirname == NULL || !os_isdir(dirname)) {
semsg(_("E150: Not a directory: %s"), eap->arg);
} else {
diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c
index 412fe3509d..7e5fd52243 100644
--- a/src/nvim/highlight_group.c
+++ b/src/nvim/highlight_group.c
@@ -553,12 +553,12 @@ void init_highlight(bool both, bool reset)
// Try finding the color scheme file. Used when a color file was loaded
// and 'background' or 't_Co' is changed.
- char_u *p = get_var_value("g:colors_name");
+ char *p = (char *)get_var_value("g:colors_name");
if (p != NULL) {
// Value of g:colors_name could be freed in load_colors() and make
// p invalid, so copy it.
- char_u *copy_p = vim_strsave(p);
- bool okay = load_colors(copy_p);
+ char *copy_p = xstrdup(p);
+ bool okay = load_colors((char_u *)copy_p);
xfree(copy_p);
if (okay) {
return;
diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c
index 85534ebcff..719899d0b8 100644
--- a/src/nvim/if_cscope.c
+++ b/src/nvim/if_cscope.c
@@ -228,16 +228,16 @@ void ex_cstag(exarg_T *eap)
}
if (cs_check_for_tags()) {
- ret = do_tag((char_u *)eap->arg, DT_JUMP, 0, eap->forceit, false);
+ ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, false);
}
}
} else if (cs_check_for_tags()) {
- ret = do_tag((char_u *)eap->arg, DT_JUMP, 0, eap->forceit, false);
+ ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, false);
}
break;
case 1:
if (cs_check_for_tags()) {
- ret = do_tag((char_u *)eap->arg, DT_JUMP, 0, eap->forceit, false);
+ ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, false);
if (ret == false) {
if (msg_col) {
msg_putchar('\n');
@@ -1003,7 +1003,7 @@ static bool cs_find_common(char *opt, char *pat, int forceit, int verbose, bool
if (qfpos != NULL && *qfpos != '0') {
// Fill error list.
FILE *f;
- char_u *tmp = vim_tempname();
+ char_u *tmp = (char_u *)vim_tempname();
qf_info_T *qi = NULL;
win_T *wp = NULL;
@@ -1053,7 +1053,7 @@ static bool cs_find_common(char *opt, char *pat, int forceit, int verbose, bool
(void)cs_manage_matches(matches, contexts, matched, Store);
- return do_tag((char_u *)pat, DT_CSCOPE, 0, forceit, verbose);
+ return do_tag(pat, DT_CSCOPE, 0, forceit, verbose);
}
}
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index a41a396abc..af5bcd7d2a 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -362,7 +362,7 @@ int get_indent_lnum(linenr_T lnum)
// "buf".
int get_indent_buf(buf_T *buf, linenr_T lnum)
{
- return get_indent_str_vtab((char *)ml_get_buf(buf, lnum, false),
+ return get_indent_str_vtab(ml_get_buf(buf, lnum, false),
curbuf->b_p_ts,
buf->b_p_vts_array,
false);
@@ -874,7 +874,7 @@ bool may_do_si(void)
return curbuf->b_p_si && !curbuf->b_p_cin && *curbuf->b_p_inde == NUL && !p_paste;
}
-// Get indent level from 'indentexpr'.
+/// Get indent level from 'indentexpr'.
int get_expr_indent(void)
{
int indent = -1;
@@ -898,8 +898,8 @@ int get_expr_indent(void)
// Need to make a copy, the 'indentexpr' option could be changed while
// evaluating it.
- char_u *inde_copy = vim_strsave((char_u *)curbuf->b_p_inde);
- indent = (int)eval_to_number((char *)inde_copy);
+ char *inde_copy = xstrdup(curbuf->b_p_inde);
+ indent = (int)eval_to_number(inde_copy);
xfree(inde_copy);
if (use_sandbox) {
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c
index 5941473825..c7f37790b6 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -1838,7 +1838,7 @@ int get_c_indent(void)
int cur_amount = MAXCOL;
colnr_T col;
char_u *theline;
- char_u *linecopy;
+ char *linecopy;
pos_T *trypos;
pos_T *comment_pos;
pos_T *tryposBrace = NULL;
@@ -1893,7 +1893,7 @@ int get_c_indent(void)
// Get a copy of the current contents of the line.
// This is required, because only the most recent line obtained with
// ml_get is valid!
- linecopy = vim_strsave((char_u *)ml_get(cur_curpos.lnum));
+ linecopy = xstrdup(ml_get(cur_curpos.lnum));
// In insert mode and the cursor is on a ')' truncate the line at the
// cursor position. We don't want to line up with the matching '(' when
@@ -1906,7 +1906,7 @@ int get_c_indent(void)
linecopy[curwin->w_cursor.col] = NUL;
}
- theline = (char_u *)skipwhite((char *)linecopy);
+ theline = (char_u *)skipwhite(linecopy);
// move the cursor to the start of the line
diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c
index dce72a2611..686461ce60 100644
--- a/src/nvim/insexpand.c
+++ b/src/nvim/insexpand.c
@@ -132,10 +132,10 @@ typedef struct compl_S compl_T;
struct compl_S {
compl_T *cp_next;
compl_T *cp_prev;
- char_u *cp_str; ///< matched text
- char_u *(cp_text[CPT_COUNT]); ///< text for the menu
+ char *cp_str; ///< matched text
+ char *(cp_text[CPT_COUNT]); ///< text for the menu
typval_T cp_user_data;
- char_u *cp_fname; ///< file containing the match, allocated when
+ char *cp_fname; ///< file containing the match, allocated when
///< cp_flags has CP_FREE_FNAME
int cp_flags; ///< CP_ values
int cp_number; ///< sequence number
@@ -191,7 +191,7 @@ static bool compl_enter_selects = false;
/// When "compl_leader" is not NULL only matches that start with this string
/// are used.
-static char_u *compl_leader = NULL;
+static char *compl_leader = NULL;
static bool compl_get_longest = false; ///< put longest common string in compl_leader
@@ -802,7 +802,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons
if (flags & CP_ORIGINAL_TEXT) {
match->cp_number = 0;
}
- match->cp_str = (char_u *)xstrnsave(str, (size_t)len);
+ match->cp_str = xstrnsave(str, (size_t)len);
// match-fname is:
// - compl_curr_match->cp_fname if it is a string equal to fname.
@@ -814,7 +814,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons
&& STRCMP(fname, compl_curr_match->cp_fname) == 0) {
match->cp_fname = compl_curr_match->cp_fname;
} else if (fname != NULL) {
- match->cp_fname = vim_strsave((char_u *)fname);
+ match->cp_fname = xstrdup(fname);
flags |= CP_FREE_FNAME;
} else {
match->cp_fname = NULL;
@@ -829,9 +829,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons
continue;
}
if (*cptext[i] != NUL) {
- match->cp_text[i] = (cptext_allocated
- ? (char_u *)cptext[i]
- : (char_u *)xstrdup(cptext[i]));
+ match->cp_text[i] = (cptext_allocated ? cptext[i] : xstrdup(cptext[i]));
} else if (cptext_allocated) {
xfree(cptext[i]);
}
@@ -898,11 +896,11 @@ static void ins_compl_longest_match(compl_T *match)
if (compl_leader == NULL) {
// First match, use it as a whole.
- compl_leader = vim_strsave(match->cp_str);
+ compl_leader = xstrdup(match->cp_str);
had_match = (curwin->w_cursor.col > compl_col);
ins_compl_delete();
- ins_bytes((char *)compl_leader + get_compl_len());
+ ins_bytes(compl_leader + get_compl_len());
ins_redraw(false);
// When the match isn't there (to avoid matching itself) remove it
@@ -916,8 +914,8 @@ static void ins_compl_longest_match(compl_T *match)
}
// Reduce the text if this match differs from compl_leader.
- p = compl_leader;
- s = match->cp_str;
+ p = (char_u *)compl_leader;
+ s = (char_u *)match->cp_str;
while (*p != NUL) {
c1 = utf_ptr2char((char *)p);
c2 = utf_ptr2char((char *)s);
@@ -936,7 +934,7 @@ static void ins_compl_longest_match(compl_T *match)
*p = NUL;
had_match = (curwin->w_cursor.col > compl_col);
ins_compl_delete();
- ins_bytes((char *)compl_leader + get_compl_len());
+ ins_bytes(compl_leader + get_compl_len());
ins_redraw(false);
// When the match isn't there (to avoid matching itself) remove it
@@ -1131,7 +1129,7 @@ static int ins_compl_build_pum(void)
do {
if (!match_at_original_text(compl)
&& (compl_leader == NULL
- || ins_compl_equal(compl, compl_leader, (size_t)lead_len))) {
+ || ins_compl_equal(compl, (char_u *)compl_leader, (size_t)lead_len))) {
compl_match_arraysize++;
}
compl = compl->cp_next;
@@ -1156,7 +1154,7 @@ static int ins_compl_build_pum(void)
do {
if (!match_at_original_text(compl)
&& (compl_leader == NULL
- || ins_compl_equal(compl, compl_leader, (size_t)lead_len))) {
+ || ins_compl_equal(compl, (char_u *)compl_leader, (size_t)lead_len))) {
if (!shown_match_ok) {
if (compl == compl_shown_match || did_find_shown_match) {
// This item is the shown match or this is the
@@ -1173,16 +1171,16 @@ static int ins_compl_build_pum(void)
}
if (compl->cp_text[CPT_ABBR] != NULL) {
- compl_match_array[i].pum_text = compl->cp_text[CPT_ABBR];
+ compl_match_array[i].pum_text = (char_u *)compl->cp_text[CPT_ABBR];
} else {
- compl_match_array[i].pum_text = compl->cp_str;
+ compl_match_array[i].pum_text = (char_u *)compl->cp_str;
}
- compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND];
- compl_match_array[i].pum_info = compl->cp_text[CPT_INFO];
+ compl_match_array[i].pum_kind = (char_u *)compl->cp_text[CPT_KIND];
+ compl_match_array[i].pum_info = (char_u *)compl->cp_text[CPT_INFO];
if (compl->cp_text[CPT_MENU] != NULL) {
- compl_match_array[i++].pum_extra = compl->cp_text[CPT_MENU];
+ compl_match_array[i++].pum_extra = (char_u *)compl->cp_text[CPT_MENU];
} else {
- compl_match_array[i++].pum_extra = compl->cp_fname;
+ compl_match_array[i++].pum_extra = (char_u *)compl->cp_fname;
}
}
@@ -1236,8 +1234,8 @@ void ins_compl_show_pum(void)
} else {
// popup menu already exists, only need to find the current item.
for (int i = 0; i < compl_match_arraysize; i++) {
- if (compl_match_array[i].pum_text == compl_shown_match->cp_str
- || compl_match_array[i].pum_text == compl_shown_match->cp_text[CPT_ABBR]) {
+ if (compl_match_array[i].pum_text == (char_u *)compl_shown_match->cp_str
+ || compl_match_array[i].pum_text == (char_u *)compl_shown_match->cp_text[CPT_ABBR]) {
cur = i;
break;
}
@@ -1649,7 +1647,7 @@ int ins_compl_bs(void)
line = get_cursor_line_ptr();
xfree(compl_leader);
- compl_leader = (char_u *)xstrnsave(line + compl_col, (size_t)(p_off - (ptrdiff_t)compl_col));
+ compl_leader = xstrnsave(line + compl_col, (size_t)(p_off - (ptrdiff_t)compl_col));
ins_compl_new_leader();
if (compl_shown_match != NULL) {
@@ -1678,7 +1676,7 @@ static void ins_compl_new_leader(void)
{
ins_compl_del_pum();
ins_compl_delete();
- ins_bytes((char *)compl_leader + get_compl_len());
+ ins_bytes(compl_leader + get_compl_len());
compl_used_match = false;
if (compl_started) {
@@ -1743,8 +1741,8 @@ void ins_compl_addleader(int c)
}
xfree(compl_leader);
- compl_leader = (char_u *)xstrnsave(get_cursor_line_ptr() + compl_col,
- (size_t)(curwin->w_cursor.col - compl_col));
+ compl_leader = xstrnsave(get_cursor_line_ptr() + compl_col,
+ (size_t)(curwin->w_cursor.col - compl_col));
ins_compl_new_leader();
}
@@ -1764,7 +1762,7 @@ static void ins_compl_restart(void)
}
/// Set the first match, the original text.
-static void ins_compl_set_original_text(char_u *str)
+static void ins_compl_set_original_text(char *str)
FUNC_ATTR_NONNULL_ALL
{
// Replace the original text entry.
@@ -1772,11 +1770,11 @@ static void ins_compl_set_original_text(char_u *str)
// be at the last item for backward completion
if (match_at_original_text(compl_first_match)) { // safety check
xfree(compl_first_match->cp_str);
- compl_first_match->cp_str = vim_strsave(str);
+ compl_first_match->cp_str = xstrdup(str);
} else if (compl_first_match->cp_prev != NULL
&& match_at_original_text(compl_first_match->cp_prev)) {
xfree(compl_first_match->cp_prev->cp_str);
- compl_first_match->cp_prev->cp_str = vim_strsave(str);
+ compl_first_match->cp_prev->cp_str = xstrdup(str);
}
}
@@ -1789,7 +1787,7 @@ void ins_compl_addfrommatch(void)
int c;
compl_T *cp;
assert(compl_shown_match != NULL);
- p = compl_shown_match->cp_str;
+ p = (char_u *)compl_shown_match->cp_str;
if ((int)STRLEN(p) <= len) { // the match is too short
// When still at the original match use the first entry that matches
// the leader.
@@ -1801,8 +1799,8 @@ void ins_compl_addfrommatch(void)
for (cp = compl_shown_match->cp_next; cp != NULL
&& !is_first_match(cp); cp = cp->cp_next) {
if (compl_leader == NULL
- || ins_compl_equal(cp, compl_leader, STRLEN(compl_leader))) {
- p = cp->cp_str;
+ || ins_compl_equal(cp, (char_u *)compl_leader, STRLEN(compl_leader))) {
+ p = (char_u *)cp->cp_str;
break;
}
}
@@ -1955,7 +1953,7 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval)
// CTRL-E then don't use the current match.
char_u *ptr;
if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E) {
- ptr = compl_curr_match->cp_str;
+ ptr = (char_u *)compl_curr_match->cp_str;
} else {
ptr = NULL;
}
@@ -2006,7 +2004,7 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval)
ins_compl_delete();
char_u *p = NULL;
if (compl_leader != NULL) {
- p = compl_leader;
+ p = (char_u *)compl_leader;
} else if (compl_first_match != NULL) {
p = (char_u *)compl_orig_text;
}
@@ -2168,7 +2166,7 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg)
if (ptr == NULL) {
if (compl_leader != NULL) {
- ptr = compl_leader;
+ ptr = (char_u *)compl_leader;
} else {
return; // nothing to do
}
@@ -2919,14 +2917,14 @@ static char_u *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_p
bool *cont_s_ipos)
{
*match_len = 0;
- char_u *ptr = ml_get_buf(ins_buf, cur_match_pos->lnum, false) + cur_match_pos->col;
+ char_u *ptr = (char_u *)ml_get_buf(ins_buf, cur_match_pos->lnum, false) + cur_match_pos->col;
int len;
if (ctrl_x_mode_line_or_eval()) {
if (compl_status_adding()) {
if (cur_match_pos->lnum >= ins_buf->b_ml.ml_line_count) {
return NULL;
}
- ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false);
+ ptr = (char_u *)ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false);
if (!p_paste) {
ptr = (char_u *)skipwhite((char *)ptr);
}
@@ -2954,7 +2952,7 @@ static char_u *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_p
// normal command "J" was used. IOSIZE is always greater than
// compl_length, so the next STRNCPY always works -- Acevedo
STRNCPY(IObuff, ptr, len); // NOLINT(runtime/printf)
- ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false);
+ ptr = (char_u *)ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false);
tmp_ptr = ptr = (char_u *)skipwhite((char *)ptr);
// Find start of next word.
tmp_ptr = find_word_start(tmp_ptr);
@@ -3275,7 +3273,7 @@ static int ins_compl_get_exp(pos_T *ini)
static void ins_compl_update_shown_match(void)
{
while (!ins_compl_equal(compl_shown_match,
- compl_leader, STRLEN(compl_leader))
+ (char_u *)compl_leader, STRLEN(compl_leader))
&& compl_shown_match->cp_next != NULL
&& !is_first_match(compl_shown_match->cp_next)) {
compl_shown_match = compl_shown_match->cp_next;
@@ -3284,10 +3282,10 @@ static void ins_compl_update_shown_match(void)
// If we didn't find it searching forward, and compl_shows_dir is
// backward, find the last match.
if (compl_shows_dir_backward()
- && !ins_compl_equal(compl_shown_match, compl_leader, STRLEN(compl_leader))
+ && !ins_compl_equal(compl_shown_match, (char_u *)compl_leader, STRLEN(compl_leader))
&& (compl_shown_match->cp_next == NULL
|| is_first_match(compl_shown_match->cp_next))) {
- while (!ins_compl_equal(compl_shown_match, compl_leader, STRLEN(compl_leader))
+ while (!ins_compl_equal(compl_shown_match, (char_u *)compl_leader, STRLEN(compl_leader))
&& compl_shown_match->cp_prev != NULL
&& !is_first_match(compl_shown_match->cp_prev)) {
compl_shown_match = compl_shown_match->cp_prev;
@@ -3321,7 +3319,7 @@ void ins_compl_delete(void)
/// "in_compl_func" is true when called from complete_check().
void ins_compl_insert(bool in_compl_func)
{
- ins_bytes((char *)compl_shown_match->cp_str + get_compl_len());
+ ins_bytes(compl_shown_match->cp_str + get_compl_len());
compl_used_match = !match_at_original_text(compl_shown_match);
dict_T *dict = ins_compl_dict_alloc(compl_shown_match);
@@ -3346,7 +3344,7 @@ static void ins_compl_show_filename(void)
// the text that fits in "space" between "s" and "e".
char *s;
char *e;
- for (s = e = (char *)compl_shown_match->cp_fname; *e != NUL; MB_PTR_ADV(e)) {
+ for (s = e = compl_shown_match->cp_fname; *e != NUL; MB_PTR_ADV(e)) {
space -= ptr2cells(e);
while (space < 0) {
space += ptr2cells(s);
@@ -3355,7 +3353,7 @@ static void ins_compl_show_filename(void)
}
msg_hist_off = true;
vim_snprintf((char *)IObuff, IOSIZE, "%s %s%s", lead,
- (char_u *)s > compl_shown_match->cp_fname ? "<" : "", s);
+ s > compl_shown_match->cp_fname ? "<" : "", s);
msg((char *)IObuff);
msg_hist_off = false;
redraw_cmdline = false; // don't overwrite!
@@ -3432,7 +3430,7 @@ static int find_next_completion_match(bool allow_get_expansion, int todo, bool a
if (!match_at_original_text(compl_shown_match)
&& compl_leader != NULL
&& !ins_compl_equal(compl_shown_match,
- compl_leader, STRLEN(compl_leader))) {
+ (char_u *)compl_leader, STRLEN(compl_leader))) {
todo++;
} else {
// Remember a matching item.
@@ -3519,7 +3517,7 @@ static int ins_compl_next(bool allow_get_expansion, int count, bool insert_match
if (!compl_get_longest || compl_used_match) {
ins_compl_insert(in_compl_func);
} else {
- ins_bytes((char *)compl_leader + get_compl_len());
+ ins_bytes(compl_leader + get_compl_len());
}
} else {
compl_used_match = false;
diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c
index 49d49f76b9..21dd5139d7 100644
--- a/src/nvim/lua/converter.c
+++ b/src/nvim/lua/converter.c
@@ -388,12 +388,12 @@ nlua_pop_typval_table_processing_end:
LuaCFunctionState *state = xmalloc(sizeof(LuaCFunctionState));
state->lua_callable.func_ref = nlua_ref_global(lstate, -1);
- 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);
cur.tv->v_type = VAR_FUNC;
- cur.tv->vval.v_string = (char *)vim_strsave(name);
+ cur.tv->vval.v_string = xstrdup(name);
break;
}
case LUA_TUSERDATA: {
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c
index 1b874e673a..e3d6a7eec8 100644
--- a/src/nvim/lua/stdlib.c
+++ b/src/nvim/lua/stdlib.c
@@ -111,7 +111,7 @@ static int regex_match_line(lua_State *lstate)
return luaL_error(lstate, "invalid row");
}
- char_u *line = ml_get_buf(buf, rownr + 1, false);
+ char_u *line = (char_u *)ml_get_buf(buf, rownr + 1, false);
size_t len = STRLEN(line);
if (start < 0 || (size_t)start > len) {
diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c
index 65e024b707..971a47f8c9 100644
--- a/src/nvim/lua/treesitter.c
+++ b/src/nvim/lua/treesitter.c
@@ -332,7 +332,7 @@ static const char *input_cb(void *payload, uint32_t byte_index, TSPoint position
*bytes_read = 0;
return "";
}
- char *line = (char *)ml_get_buf(bp, (linenr_T)position.row + 1, false);
+ char *line = ml_get_buf(bp, (linenr_T)position.row + 1, false);
size_t len = STRLEN(line);
if (position.column > len) {
*bytes_read = 0;
diff --git a/src/nvim/macros.h b/src/nvim/macros.h
index b84539852f..1024ca5015 100644
--- a/src/nvim/macros.h
+++ b/src/nvim/macros.h
@@ -54,7 +54,7 @@
#define ASCII_ISALNUM(c) (ASCII_ISALPHA(c) || ascii_isdigit(c))
// Returns empty string if it is NULL.
-#define EMPTY_IF_NULL(x) (char *)((x) ? (x) : (char_u *)"")
+#define EMPTY_IF_NULL(x) ((x) ? (x) : "")
/// Adjust chars in a language according to 'langmap' option.
/// NOTE that there is no noticeable overhead if 'langmap' is not set.
diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c
index 923eea145c..94b432a553 100644
--- a/src/nvim/mapping.c
+++ b/src/nvim/mapping.c
@@ -303,7 +303,7 @@ static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len
// NB: replace_termcodes may produce an empty string even if orig_rhs is non-empty
// (e.g. a single ^V, see :h map-empty-rhs)
mapargs->rhs_is_noop = orig_rhs_len != 0 && mapargs->rhs_len == 0;
- mapargs->rhs = (char_u *)replaced;
+ mapargs->rhs = replaced;
}
} else {
char tmp_buf[64];
@@ -313,7 +313,7 @@ static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len
// stores <lua>ref_no<cr> in map_str
mapargs->rhs_len = (size_t)vim_snprintf(S_LEN(tmp_buf), "%c%c%c%d\r", K_SPECIAL,
(char_u)KS_EXTRA, KE_LUA, rhs_lua);
- mapargs->rhs = vim_strsave((char_u *)tmp_buf);
+ mapargs->rhs = xstrdup(tmp_buf);
}
}
@@ -439,7 +439,7 @@ static int str_to_mapargs(const char_u *strargs, bool is_unmap, MapArguments *ma
/// and "desc" fields are used.
/// "rhs", "rhs_lua", "orig_rhs" fields are cleared if "simplified" is false.
/// @param sid -1 to use current_sctx
-static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, const char_u *keys,
+static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, const char *keys,
MapArguments *args, int noremap, int mode, bool is_abbr, scid_T sid,
linenr_T lnum, bool simplified)
{
@@ -454,8 +454,8 @@ static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table,
}
}
- mp->m_keys = vim_strsave(keys);
- mp->m_str = (char *)args->rhs;
+ mp->m_keys = (uint8_t *)xstrdup(keys);
+ mp->m_str = args->rhs;
mp->m_orig_str = (char *)args->orig_rhs;
mp->m_luaref = args->rhs_lua;
if (!simplified) {
@@ -767,7 +767,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
XFREE_CLEAR(mp->m_str);
XFREE_CLEAR(mp->m_orig_str);
}
- mp->m_str = (char *)args->rhs;
+ mp->m_str = args->rhs;
mp->m_orig_str = (char *)args->orig_rhs;
mp->m_luaref = args->rhs_lua;
if (!keyround1_simplified) {
@@ -846,7 +846,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
}
// Get here when adding a new entry to the maphash[] list or abbrlist.
- map_add(buf, map_table, abbr_table, lhs, args, noremap, mode, is_abbrev,
+ map_add(buf, map_table, abbr_table, (char *)lhs, args, noremap, mode, is_abbrev,
-1, // sid
0, // lnum
keyround1_simplified);
@@ -1265,7 +1265,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char ***file)
int hash;
int count;
int round;
- char_u *p;
+ char *p;
int i;
*num_file = 0; // return values in case of FAIL
@@ -1278,28 +1278,28 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char ***file)
for (i = 0; i < 7; i++) {
if (i == 0) {
- p = (char_u *)"<silent>";
+ p = "<silent>";
} else if (i == 1) {
- p = (char_u *)"<unique>";
+ p = "<unique>";
} else if (i == 2) {
- p = (char_u *)"<script>";
+ p = "<script>";
} else if (i == 3) {
- p = (char_u *)"<expr>";
+ p = "<expr>";
} else if (i == 4 && !expand_buffer) {
- p = (char_u *)"<buffer>";
+ p = "<buffer>";
} else if (i == 5) {
- p = (char_u *)"<nowait>";
+ p = "<nowait>";
} else if (i == 6) {
- p = (char_u *)"<special>";
+ p = "<special>";
} else {
continue;
}
- if (vim_regexec(regmatch, (char *)p, (colnr_T)0)) {
+ if (vim_regexec(regmatch, p, (colnr_T)0)) {
if (round == 1) {
count++;
} else {
- (*file)[count++] = (char *)vim_strsave(p);
+ (*file)[count++] = xstrdup(p);
}
}
}
@@ -1317,12 +1317,12 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char ***file)
}
for (; mp; mp = mp->m_next) {
if (mp->m_mode & expand_mapmodes) {
- p = translate_mapping(mp->m_keys, CPO_TO_CPO_FLAGS);
- if (p != NULL && vim_regexec(regmatch, (char *)p, (colnr_T)0)) {
+ p = (char *)translate_mapping(mp->m_keys, CPO_TO_CPO_FLAGS);
+ if (p != NULL && vim_regexec(regmatch, p, (colnr_T)0)) {
if (round == 1) {
count++;
} else {
- (*file)[count++] = (char *)p;
+ (*file)[count++] = p;
p = NULL;
}
}
@@ -1447,20 +1447,20 @@ bool check_abbr(int c, char_u *ptr, int col, int mincol)
mp->m_next == NULL ? (mp = mp2, mp2 = NULL) :
(mp = mp->m_next)) {
int qlen = mp->m_keylen;
- char_u *q = mp->m_keys;
+ char *q = (char *)mp->m_keys;
int match;
if (strchr((const char *)mp->m_keys, K_SPECIAL) != NULL) {
// Might have K_SPECIAL escaped mp->m_keys.
- q = vim_strsave(mp->m_keys);
- vim_unescape_ks(q);
+ q = xstrdup((char *)mp->m_keys);
+ vim_unescape_ks((char_u *)q);
qlen = (int)STRLEN(q);
}
// find entries with right mode and keys
match = (mp->m_mode & State)
&& qlen == len
&& !STRNCMP(q, ptr, (size_t)len);
- if (q != mp->m_keys) {
+ if (q != (char *)mp->m_keys) {
xfree(q);
}
if (match) {
@@ -1510,7 +1510,7 @@ bool check_abbr(int c, char_u *ptr, int col, int mincol)
(void)ins_typebuf((char *)tb, 1, 0, true, mp->m_silent);
}
if (mp->m_expr) {
- s = eval_map_expr(mp, c);
+ s = (char_u *)eval_map_expr(mp, c);
} else {
s = (char_u *)mp->m_str;
}
@@ -1540,16 +1540,16 @@ bool check_abbr(int c, char_u *ptr, int col, int mincol)
/// special characters.
///
/// @param c NUL or typed character for abbreviation
-char_u *eval_map_expr(mapblock_T *mp, int c)
+char *eval_map_expr(mapblock_T *mp, int c)
{
- char_u *p = NULL;
- char_u *expr = NULL;
+ char *p = NULL;
+ char *expr = NULL;
// Remove escaping of K_SPECIAL, because "str" is in a format to be used as
// typeahead.
if (mp->m_luaref == LUA_NOREF) {
- expr = vim_strsave((char_u *)mp->m_str);
- vim_unescape_ks(expr);
+ expr = xstrdup(mp->m_str);
+ vim_unescape_ks((char_u *)expr);
}
// Forbid changing text or using ":normal" to avoid most of the bad side
@@ -1565,7 +1565,7 @@ char_u *eval_map_expr(mapblock_T *mp, int c)
Array args = ARRAY_DICT_INIT;
Object ret = nlua_call_ref(mp->m_luaref, NULL, args, true, &err);
if (ret.type == kObjectTypeString) {
- p = (char_u *)xstrndup(ret.data.string.data, ret.data.string.size);
+ p = xstrndup(ret.data.string.data, ret.data.string.size);
}
api_free_object(ret);
if (err.type != kErrorTypeNone) {
@@ -1573,7 +1573,7 @@ char_u *eval_map_expr(mapblock_T *mp, int c)
api_clear_error(&err);
}
} else {
- p = (char_u *)eval_to_string((char *)expr, NULL, false);
+ p = eval_to_string(expr, NULL, false);
xfree(expr);
}
textlock--;
@@ -1586,13 +1586,13 @@ char_u *eval_map_expr(mapblock_T *mp, int c)
return NULL;
}
- char_u *res = NULL;
+ char *res = NULL;
if (mp->m_replace_keycodes) {
- replace_termcodes((char *)p, STRLEN(p), (char **)&res, REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS);
+ replace_termcodes(p, STRLEN(p), &res, REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS);
} else {
// Escape K_SPECIAL in the result to be able to use the string as typeahead.
- res = (char_u *)vim_strsave_escape_ks((char *)p);
+ res = vim_strsave_escape_ks(p);
}
xfree(p);
@@ -2204,10 +2204,10 @@ void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
xfree(unmap_args.orig_rhs);
if (lhsrawalt != NULL) {
- map_add(curbuf, map_table, abbr_table, (char_u *)lhsrawalt, &args, noremap, mode, is_abbr,
+ map_add(curbuf, map_table, abbr_table, lhsrawalt, &args, noremap, mode, is_abbr,
sid, lnum, true);
}
- map_add(curbuf, map_table, abbr_table, (char_u *)lhsraw, &args, noremap, mode, is_abbr,
+ map_add(curbuf, map_table, abbr_table, lhsraw, &args, noremap, mode, is_abbr,
sid, lnum, false);
}
diff --git a/src/nvim/mapping.h b/src/nvim/mapping.h
index 7c48c3bce2..182d1a48cb 100644
--- a/src/nvim/mapping.h
+++ b/src/nvim/mapping.h
@@ -35,7 +35,7 @@ struct map_arguments {
char_u alt_lhs[MAXMAPLEN + 1];
size_t alt_lhs_len;
- char_u *rhs; /// The {rhs} of the mapping.
+ char *rhs; /// The {rhs} of the mapping.
size_t rhs_len;
LuaRef rhs_lua; /// lua function as {rhs}
bool rhs_is_noop; /// True when the {rhs} should be <Nop>.
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index 7838986edd..a6d0a68323 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -992,22 +992,22 @@ void ex_delmarks(exarg_T *eap)
void ex_jumps(exarg_T *eap)
{
int i;
- char_u *name;
+ char *name;
cleanup_jumplist(curwin, true);
// Highlight title
msg_puts_title(_("\n jump line col file/text"));
for (i = 0; i < curwin->w_jumplistlen && !got_int; i++) {
if (curwin->w_jumplist[i].fmark.mark.lnum != 0) {
- name = fm_getname(&curwin->w_jumplist[i].fmark, 16);
+ name = (char *)fm_getname(&curwin->w_jumplist[i].fmark, 16);
// Make sure to output the current indicator, even when on an wiped
// out buffer. ":filter" may still skip it.
if (name == NULL && i == curwin->w_jumplistidx) {
- name = vim_strsave((char_u *)"-invalid-");
+ name = xstrdup("-invalid-");
}
// apply :filter /pat/ or file name not available
- if (name == NULL || message_filtered((char *)name)) {
+ if (name == NULL || message_filtered(name)) {
xfree(name);
continue;
}
@@ -1022,7 +1022,7 @@ void ex_jumps(exarg_T *eap)
i > curwin->w_jumplistidx ? i - curwin->w_jumplistidx : curwin->w_jumplistidx - i,
curwin->w_jumplist[i].fmark.mark.lnum, curwin->w_jumplist[i].fmark.mark.col);
msg_outtrans((char *)IObuff);
- msg_outtrans_attr((char *)name,
+ msg_outtrans_attr(name,
curwin->w_jumplist[i].fmark.fnum == curbuf->b_fnum
? HL_ATTR(HLF_D) : 0);
xfree(name);
@@ -1710,7 +1710,7 @@ void mark_mb_adjustpos(buf_T *buf, pos_T *lp)
FUNC_ATTR_NONNULL_ALL
{
if (lp->col > 0 || lp->coladd > 1) {
- const char_u *const p = ml_get_buf(buf, lp->lnum, false);
+ const char_u *const p = (char_u *)ml_get_buf(buf, lp->lnum, false);
if (*p == NUL || (int)STRLEN(p) < lp->col) {
lp->col = 0;
} else {
diff --git a/src/nvim/match.c b/src/nvim/match.c
index b6d700b148..cd8c65cc02 100644
--- a/src/nvim/match.c
+++ b/src/nvim/match.c
@@ -446,7 +446,7 @@ static void next_search_hl(win_T *win, match_T *search_hl, match_T *shl, linenr_
char_u *ml;
matchcol = shl->rm.startpos[0].col;
- ml = ml_get_buf(shl->buf, lnum, false) + matchcol;
+ ml = (char_u *)ml_get_buf(shl->buf, lnum, false) + matchcol;
if (*ml == NUL) {
matchcol++;
shl->lnum = 0;
@@ -613,7 +613,7 @@ bool prepare_search_hl_line(win_T *wp, linenr_T lnum, colnr_T mincol, char_u **l
// Need to get the line again, a multi-line regexp may have made it
// invalid.
- *line = ml_get_buf(wp->w_buffer, lnum, false);
+ *line = (char_u *)ml_get_buf(wp->w_buffer, lnum, false);
if (shl->lnum != 0 && shl->lnum <= lnum) {
if (shl->lnum == lnum) {
@@ -721,7 +721,7 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char_u **line, match
// Need to get the line again, a multi-line regexp
// may have made it invalid.
- *line = ml_get_buf(wp->w_buffer, lnum, false);
+ *line = (char_u *)ml_get_buf(wp->w_buffer, lnum, false);
if (shl->lnum == lnum) {
shl->startcol = shl->rm.startpos[0].col;
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 116a66e773..83b0609052 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -1536,7 +1536,7 @@ void show_utf8(void)
// Get the byte length of the char under the cursor, including composing
// characters.
- line = get_cursor_pos_ptr();
+ line = (char_u *)get_cursor_pos_ptr();
len = utfc_ptr2len((char *)line);
if (len == 0) {
msg("NUL");
@@ -1891,7 +1891,7 @@ void utf_find_illegal(void)
curwin->w_cursor.coladd = 0;
for (;;) {
- p = get_cursor_pos_ptr();
+ p = (char_u *)get_cursor_pos_ptr();
if (vimconv.vc_type != CONV_NONE) {
xfree(tofree);
tofree = (char_u *)string_convert(&vimconv, (char *)p, NULL);
@@ -1908,12 +1908,12 @@ void utf_find_illegal(void)
if (*p >= 0x80 && (len == 1
|| utf_char2len(utf_ptr2char((char *)p)) != len)) {
if (vimconv.vc_type == CONV_NONE) {
- curwin->w_cursor.col += (colnr_T)(p - get_cursor_pos_ptr());
+ curwin->w_cursor.col += (colnr_T)(p - (char_u *)get_cursor_pos_ptr());
} else {
int l;
len = (int)(p - tofree);
- for (p = get_cursor_pos_ptr(); *p != NUL && len-- > 0; p += l) {
+ for (p = (char_u *)get_cursor_pos_ptr(); *p != NUL && len-- > 0; p += l) {
l = utf_ptr2len((char *)p);
curwin->w_cursor.col += l;
}
@@ -1980,7 +1980,7 @@ void mb_check_adjust_col(void *win_)
// Column 0 is always valid.
if (oldcol != 0) {
- char *p = (char *)ml_get_buf(win->w_buffer, win->w_cursor.lnum, false);
+ char *p = ml_get_buf(win->w_buffer, win->w_cursor.lnum, false);
colnr_T len = (colnr_T)STRLEN(p);
// Empty line or invalid column?
@@ -2114,27 +2114,27 @@ char *enc_skip(char *p)
char *enc_canonize(char *enc)
FUNC_ATTR_NONNULL_RET
{
- char_u *p, *s;
+ char *p, *s;
if (STRCMP(enc, "default") == 0) {
// Use the default encoding as found by set_init_1().
- return (char *)vim_strsave(fenc_default);
+ return xstrdup(fenc_default);
}
// copy "enc" to allocated memory, with room for two '-'
- char_u *r = xmalloc(STRLEN(enc) + 3);
+ char *r = xmalloc(STRLEN(enc) + 3);
// Make it all lower case and replace '_' with '-'.
p = r;
- for (s = (char_u *)enc; *s != NUL; s++) {
+ for (s = enc; *s != NUL; s++) {
if (*s == '_') {
*p++ = '-';
} else {
- *p++ = (char_u)TOLOWER_ASC(*s);
+ *p++ = (char)TOLOWER_ASC(*s);
}
}
*p = NUL;
// Skip "2byte-" and "8bit-".
- p = (char_u *)enc_skip((char *)r);
+ p = enc_skip(r);
// Change "microsoft-cp" to "cp". Used in some spell files.
if (STRNCMP(p, "microsoft-cp", 12) == 0) {
@@ -2159,17 +2159,17 @@ char *enc_canonize(char *enc)
}
int i;
- if (enc_canon_search(p) >= 0) {
+ if (enc_canon_search((char_u *)p) >= 0) {
// canonical name can be used unmodified
if (p != r) {
STRMOVE(r, p);
}
- } else if ((i = enc_alias_search(p)) >= 0) {
+ } else if ((i = enc_alias_search((char_u *)p)) >= 0) {
// alias recognized, get canonical name
xfree(r);
- r = vim_strsave((char_u *)enc_canon_table[i].name);
+ r = xstrdup(enc_canon_table[i].name);
}
- return (char *)r;
+ return r;
}
/// Search for an encoding alias of "name".
@@ -2491,7 +2491,7 @@ char_u *string_convert_ext(const vimconv_T *const vcp, char_u *ptr, size_t *lenp
len = *lenp;
}
if (len == 0) {
- return vim_strsave((char_u *)"");
+ return (char_u *)xstrdup("");
}
switch (vcp->vc_type) {
diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c
index 9446aaee4f..bb9be0766e 100644
--- a/src/nvim/memfile.c
+++ b/src/nvim/memfile.c
@@ -170,7 +170,7 @@ void mf_close(memfile_T *mfp, bool del_file)
emsg(_(e_swapclose));
}
if (del_file && mfp->mf_fname != NULL) {
- os_remove((char *)mfp->mf_fname);
+ os_remove(mfp->mf_fname);
}
// free entries in used list
@@ -210,7 +210,7 @@ void mf_close_file(buf_T *buf, bool getlines)
mfp->mf_fd = -1;
if (mfp->mf_fname != NULL) {
- os_remove((char *)mfp->mf_fname); // delete the swap file
+ os_remove(mfp->mf_fname); // delete the swap file
mf_free_fnames(mfp);
}
}
@@ -751,8 +751,8 @@ void mf_free_fnames(memfile_T *mfp)
/// name so we must work out the full path name.
void mf_set_fnames(memfile_T *mfp, char *fname)
{
- mfp->mf_fname = (char_u *)fname;
- mfp->mf_ffname = (char_u *)FullName_save((char *)mfp->mf_fname, false);
+ mfp->mf_fname = fname;
+ mfp->mf_ffname = (char_u *)FullName_save(mfp->mf_fname, false);
}
/// Make name of memfile's swapfile a full path.
@@ -762,7 +762,7 @@ void mf_fullname(memfile_T *mfp)
{
if (mfp != NULL && mfp->mf_fname != NULL && mfp->mf_ffname != NULL) {
xfree(mfp->mf_fname);
- mfp->mf_fname = mfp->mf_ffname;
+ mfp->mf_fname = (char *)mfp->mf_ffname;
mfp->mf_ffname = NULL;
}
}
@@ -789,7 +789,7 @@ static bool mf_do_open(memfile_T *mfp, char *fname, int flags)
/// exist yet. If there is a symbolic link, this is most likely an attack.
FileInfo file_info;
if ((flags & O_CREAT)
- && os_fileinfo_link((char *)mfp->mf_fname, &file_info)) {
+ && os_fileinfo_link(mfp->mf_fname, &file_info)) {
mfp->mf_fd = -1;
emsg(_("E300: Swap file already exists (symlink attack?)"));
} else {
diff --git a/src/nvim/memfile_defs.h b/src/nvim/memfile_defs.h
index 537d3e5f65..d1e8fd0fb4 100644
--- a/src/nvim/memfile_defs.h
+++ b/src/nvim/memfile_defs.h
@@ -88,7 +88,7 @@ typedef struct mf_blocknr_trans_item {
/// A memory file.
typedef struct memfile {
- char_u *mf_fname; /// name of the file
+ char *mf_fname; /// name of the file
char_u *mf_ffname; /// idem, full path
int mf_fd; /// file descriptor
bhdr_T *mf_free_first; /// first block header in free list
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index c5e8e3da07..e6cb1b79fc 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -369,7 +369,7 @@ void ml_setname(buf_T *buf)
if (*dirp == NUL) { // tried all directories, fail
break;
}
- fname = (char_u *)findswapname(buf, &dirp, (char *)mfp->mf_fname, &found_existing_dir);
+ fname = (char_u *)findswapname(buf, &dirp, mfp->mf_fname, &found_existing_dir);
// alloc's fname
if (dirp == NULL) { // out of memory
break;
@@ -391,7 +391,7 @@ void ml_setname(buf_T *buf)
}
// try to rename the swap file
- if (vim_rename(mfp->mf_fname, fname) == 0) {
+ if (vim_rename((char_u *)mfp->mf_fname, fname) == 0) {
success = true;
mf_free_fnames(mfp);
mf_set_fnames(mfp, (char *)fname);
@@ -402,7 +402,7 @@ void ml_setname(buf_T *buf)
}
if (mfp->mf_fd == -1) { // need to (re)open the swap file
- mfp->mf_fd = os_open((char *)mfp->mf_fname, O_RDWR, 0);
+ mfp->mf_fd = os_open(mfp->mf_fname, O_RDWR, 0);
if (mfp->mf_fd < 0) {
// could not (re)open the swap file, what can we do????
emsg(_("E301: Oops, lost the swap file!!!"));
@@ -445,7 +445,7 @@ void ml_open_file(buf_T *buf)
// For a spell buffer use a temp file name.
if (buf->b_spell) {
- fname = vim_tempname();
+ fname = (char_u *)vim_tempname();
if (fname != NULL) {
(void)mf_open_file(mfp, (char *)fname); // consumes fname!
}
@@ -665,7 +665,7 @@ static void set_b0_fname(ZERO_BL *b0p, buf_T *buf)
/// not set.
static void set_b0_dir_flag(ZERO_BL *b0p, buf_T *buf)
{
- if (same_directory(buf->b_ml.ml_mfp->mf_fname, (char_u *)buf->b_ffname)) {
+ if (same_directory((char_u *)buf->b_ml.ml_mfp->mf_fname, (char_u *)buf->b_ffname)) {
b0p->b0_flags |= B0_SAME_DIR;
} else {
b0p->b0_flags &= (uint8_t) ~B0_SAME_DIR;
@@ -765,7 +765,7 @@ void ml_recover(bool checkext)
}
}
// get the swap file name that will be used
- (void)recover_names((char_u *)fname, false, i, (char_u **)&fname_used);
+ (void)recover_names((char_u *)fname, false, i, &fname_used);
}
if (fname_used == NULL) {
goto theend; // user chose invalid number.
@@ -809,7 +809,7 @@ void ml_recover(bool checkext)
if ((hp = mf_get(mfp, 0, 1)) == NULL) {
msg_start();
msg_puts_attr(_("Unable to read block 0 from "), attr | MSG_HIST);
- msg_outtrans_attr((char *)mfp->mf_fname, attr | MSG_HIST);
+ msg_outtrans_attr(mfp->mf_fname, attr | MSG_HIST);
msg_puts_attr(_("\nMaybe no changes were made or Vim did not update the swap file."),
attr | MSG_HIST);
msg_end();
@@ -818,7 +818,7 @@ void ml_recover(bool checkext)
b0p = hp->bh_data;
if (STRNCMP(b0p->b0_version, "VIM 3.0", 7) == 0) {
msg_start();
- msg_outtrans_attr((char *)mfp->mf_fname, MSG_HIST);
+ msg_outtrans_attr(mfp->mf_fname, MSG_HIST);
msg_puts_attr(_(" cannot be used with this version of Vim.\n"),
MSG_HIST);
msg_puts_attr(_("Use Vim version 3.0.\n"), MSG_HIST);
@@ -831,7 +831,7 @@ void ml_recover(bool checkext)
}
if (b0_magic_wrong(b0p)) {
msg_start();
- msg_outtrans_attr((char *)mfp->mf_fname, attr | MSG_HIST);
+ msg_outtrans_attr(mfp->mf_fname, attr | MSG_HIST);
msg_puts_attr(_(" cannot be used on this computer.\n"),
attr | MSG_HIST);
msg_puts_attr(_("The file was created on "), attr | MSG_HIST);
@@ -851,7 +851,7 @@ void ml_recover(bool checkext)
mf_new_page_size(mfp, (unsigned)char_to_long(b0p->b0_page_size));
if (mfp->mf_page_size < previous_page_size) {
msg_start();
- msg_outtrans_attr((char *)mfp->mf_fname, attr | MSG_HIST);
+ msg_outtrans_attr(mfp->mf_fname, attr | MSG_HIST);
msg_puts_attr(_(" has been damaged (page size is smaller than minimum value).\n"),
attr | MSG_HIST);
msg_end();
@@ -880,7 +880,7 @@ void ml_recover(bool checkext)
}
}
- home_replace(NULL, (char *)mfp->mf_fname, (char *)NameBuff, MAXPATHL, true);
+ home_replace(NULL, mfp->mf_fname, (char *)NameBuff, MAXPATHL, true);
smsg(_("Using swap file \"%s\""), NameBuff);
if (buf_spname(curbuf) != NULL) {
@@ -897,7 +897,7 @@ void ml_recover(bool checkext)
mtime = char_to_long(b0p->b0_mtime);
if (curbuf->b_ffname != NULL
&& os_fileinfo(curbuf->b_ffname, &org_file_info)
- && ((os_fileinfo((char *)mfp->mf_fname, &swp_file_info)
+ && ((os_fileinfo(mfp->mf_fname, &swp_file_info)
&& org_file_info.stat.st_mtim.tv_sec
> swp_file_info.stat.st_mtim.tv_sec)
|| org_file_info.stat.st_mtim.tv_sec != mtime)) {
@@ -1186,7 +1186,7 @@ theend:
/// @param list when true, list the swap file names
/// @param nr when non-zero, return nr'th swap file name
/// @param fname_out result when "nr" > 0
-int recover_names(char_u *fname, int list, int nr, char_u **fname_out)
+int recover_names(char_u *fname, int list, int nr, char **fname_out)
{
int num_names;
char *(names[6]);
@@ -1291,7 +1291,7 @@ int recover_names(char_u *fname, int list, int nr, char_u **fname_out)
// remove swapfile name of the current buffer, it must be ignored
if (curbuf->b_ml.ml_mfp != NULL
- && (p = curbuf->b_ml.ml_mfp->mf_fname) != NULL) {
+ && (p = (char_u *)curbuf->b_ml.ml_mfp->mf_fname) != NULL) {
for (int i = 0; i < num_files; i++) {
// Do not expand wildcards, on Windows would try to expand
// "%tmp%" in "%tmp%file"
@@ -1313,7 +1313,7 @@ int recover_names(char_u *fname, int list, int nr, char_u **fname_out)
if (nr > 0) {
file_count += num_files;
if (nr <= file_count) {
- *fname_out = vim_strsave((char_u *)files[nr - 1 + num_files - file_count]);
+ *fname_out = xstrdup(files[nr - 1 + num_files - file_count]);
dirp = ""; // stop searching
}
} else if (list) {
@@ -1713,14 +1713,14 @@ theend:
/// having to check for error everywhere).
char *ml_get(linenr_T lnum)
{
- return (char *)ml_get_buf(curbuf, lnum, false);
+ return ml_get_buf(curbuf, lnum, false);
}
/// @return pointer to position "pos".
char_u *ml_get_pos(const pos_T *pos)
FUNC_ATTR_NONNULL_ALL
{
- return ml_get_buf(curbuf, pos->lnum, false) + pos->col;
+ return (char_u *)ml_get_buf(curbuf, pos->lnum, false) + pos->col;
}
/// @return codepoint at pos. pos must be either valid or have col set to MAXCOL!
@@ -1737,14 +1737,14 @@ int gchar_pos(pos_T *pos)
/// @param will_change true mark the buffer dirty (chars in the line will be changed)
///
/// @return a pointer to a line in a specific buffer
-char_u *ml_get_buf(buf_T *buf, linenr_T lnum, bool will_change)
+char *ml_get_buf(buf_T *buf, linenr_T lnum, bool will_change)
FUNC_ATTR_NONNULL_ALL
{
bhdr_T *hp;
DATA_BL *dp;
- char_u *ptr;
+ char *ptr;
static int recursive = 0;
- static char_u questions[4];
+ static char questions[4];
if (lnum > buf->b_ml.ml_line_count) { // invalid line number
if (recursive == 0) {
@@ -1766,7 +1766,7 @@ errorret:
}
if (buf->b_ml.ml_mfp == NULL) { // there are no lines
- return (char_u *)"";
+ return "";
}
// See if it is the same line as requested last time.
@@ -1795,9 +1795,9 @@ errorret:
dp = hp->bh_data;
- ptr = (char_u *)dp +
+ ptr = (char *)dp +
((dp->db_index[lnum - buf->b_ml.ml_locked_low]) & DB_INDEX_MASK);
- buf->b_ml.ml_line_ptr = ptr;
+ buf->b_ml.ml_line_ptr = (char_u *)ptr;
buf->b_ml.ml_line_lnum = lnum;
buf->b_ml.ml_flags &= ~ML_LINE_DIRTY;
}
@@ -1806,7 +1806,7 @@ errorret:
ml_add_deleted_len_buf(buf, buf->b_ml.ml_line_ptr, -1);
}
- return buf->b_ml.ml_line_ptr;
+ return (char *)buf->b_ml.ml_line_ptr;
}
/// Check if a line that was just obtained by a call to ml_get
@@ -2352,7 +2352,7 @@ int ml_replace_buf(buf_T *buf, linenr_T lnum, char *line, bool copy)
}
if (readlen && kv_size(buf->update_callbacks)) {
- ml_add_deleted_len_buf(buf, ml_get_buf(buf, lnum, false), -1);
+ ml_add_deleted_len_buf(buf, (char_u *)ml_get_buf(buf, lnum, false), -1);
}
buf->b_ml.ml_line_ptr = (char_u *)line;
@@ -3081,7 +3081,7 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name
return NULL;
}
- s = get_file_in_dir(r, dir_name);
+ s = (char_u *)get_file_in_dir((char *)r, (char *)dir_name);
xfree(r);
return s;
}
@@ -3098,30 +3098,30 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name
/// The return value is an allocated string and can be NULL.
///
/// @param dname don't use "dirname", it is a global for Alpha
-char_u *get_file_in_dir(char_u *fname, char_u *dname)
+char *get_file_in_dir(char *fname, char *dname)
{
- char_u *t;
- char_u *tail;
- char_u *retval;
+ char *t;
+ char *tail;
+ char *retval;
int save_char;
- tail = (char_u *)path_tail((char *)fname);
+ tail = path_tail(fname);
if (dname[0] == '.' && dname[1] == NUL) {
- retval = vim_strsave(fname);
+ retval = xstrdup(fname);
} else if (dname[0] == '.' && vim_ispathsep(dname[1])) {
if (tail == fname) { // no path before file name
- retval = (char_u *)concat_fnames((char *)dname + 2, (char *)tail, true);
+ retval = concat_fnames(dname + 2, tail, true);
} else {
- save_char = *tail;
+ save_char = (uint8_t)(*tail);
*tail = NUL;
- t = (char_u *)concat_fnames((char *)fname, (char *)dname + 2, true);
- *tail = (uint8_t)save_char;
- retval = (char_u *)concat_fnames((char *)t, (char *)tail, true);
+ t = concat_fnames(fname, dname + 2, true);
+ *tail = (char)save_char;
+ retval = concat_fnames(t, tail, true);
xfree(t);
}
} else {
- retval = (char_u *)concat_fnames((char *)dname, (char *)tail, true);
+ retval = concat_fnames(dname, tail, true);
}
return retval;
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c
index 90084bde17..7b267d6ce4 100644
--- a/src/nvim/mouse.c
+++ b/src/nvim/mouse.c
@@ -631,7 +631,7 @@ colnr_T vcol2col(win_T *const wp, const linenr_T lnum, const colnr_T vcol)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
// try to advance to the specified column
- char_u *line = ml_get_buf(wp->w_buffer, lnum, false);
+ char_u *line = (char_u *)ml_get_buf(wp->w_buffer, lnum, false);
chartabsize_T cts;
init_chartabsize_arg(&cts, wp, lnum, 0, (char *)line, (char *)line);
while (cts.cts_vcol < vcol && *cts.cts_ptr != NUL) {
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 66038d0c3c..2fe482d8aa 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -629,18 +629,18 @@ static void normal_redraw_mode_message(NormalState *s)
// If need to redraw, and there is a "keep_msg", redraw before the
// delay
if (must_redraw && keep_msg != NULL && !emsg_on_display) {
- char_u *kmsg;
+ char *kmsg;
- kmsg = (char_u *)keep_msg;
+ kmsg = keep_msg;
keep_msg = NULL;
// Showmode() will clear keep_msg, but we want to use it anyway.
// First update w_topline.
setcursor();
update_screen(0);
// now reset it, otherwise it's put in the history again
- keep_msg = (char *)kmsg;
+ keep_msg = kmsg;
- kmsg = vim_strsave((char_u *)keep_msg);
+ kmsg = xstrdup(keep_msg);
msg_attr((const char *)kmsg, keep_msg_attr);
xfree(kmsg);
}
@@ -2180,7 +2180,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
find_start_of_word(&VIsual);
if (*p_sel == 'e' && *get_cursor_pos_ptr() != NUL) {
curwin->w_cursor.col +=
- utfc_ptr2len((char *)get_cursor_pos_ptr());
+ utfc_ptr2len(get_cursor_pos_ptr());
}
find_end_of_word(&curwin->w_cursor);
}
@@ -2416,7 +2416,7 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, char **text
// if i == 0: try to find an identifier
// if i == 1: try to find any non-white text
- char_u *ptr = ml_get_buf(wp->w_buffer, lnum, false);
+ char_u *ptr = (char_u *)ml_get_buf(wp->w_buffer, lnum, false);
for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; i++) {
// 1. skip to start of identifier/text
col = startcol;
@@ -2675,9 +2675,9 @@ void clear_showcmd(void)
if (cursor_bot) {
s = ml_get_pos(&VIsual);
- e = get_cursor_pos_ptr();
+ e = (char_u *)get_cursor_pos_ptr();
} else {
- s = get_cursor_pos_ptr();
+ s = (char_u *)get_cursor_pos_ptr();
e = ml_get_pos(&VIsual);
}
while ((*p_sel != 'e') ? s <= e : s < e) {
@@ -3361,7 +3361,7 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
virtcol -= vim_strsize((char *)get_showbreak_value(curwin));
}
- int c = utf_ptr2char((char *)get_cursor_pos_ptr());
+ int c = utf_ptr2char(get_cursor_pos_ptr());
if (dir == FORWARD && virtcol < curwin->w_curswant
&& (curwin->w_curswant <= (colnr_T)width1)
&& !vim_isprintc(c) && c > 255) {
@@ -4451,7 +4451,7 @@ bool get_visual_text(cmdarg_T *cap, char **pp, size_t *lenp)
static void nv_tagpop(cmdarg_T *cap)
{
if (!checkclearopq(cap->oap)) {
- do_tag((char_u *)"", DT_POP, (int)cap->count1, false, true);
+ do_tag("", DT_POP, (int)cap->count1, false, true);
}
}
@@ -4600,7 +4600,7 @@ static void nv_right(cmdarg_T *cap)
if (virtual_active()) {
oneright();
} else {
- curwin->w_cursor.col += utfc_ptr2len((char *)get_cursor_pos_ptr());
+ curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr());
}
}
}
@@ -4648,7 +4648,7 @@ static void nv_left(cmdarg_T *cap)
// Don't adjust op_end now, otherwise it won't work.
if ((cap->oap->op_type == OP_DELETE || cap->oap->op_type == OP_CHANGE)
&& !LINEEMPTY(curwin->w_cursor.lnum)) {
- char_u *cp = get_cursor_pos_ptr();
+ char_u *cp = (char_u *)get_cursor_pos_ptr();
if (*cp != NUL) {
curwin->w_cursor.col += utfc_ptr2len((char *)cp);
@@ -5360,7 +5360,7 @@ static void nv_replace(cmdarg_T *cap)
}
// Abort if not enough characters to replace.
- ptr = get_cursor_pos_ptr();
+ ptr = (char_u *)get_cursor_pos_ptr();
if (STRLEN(ptr) < (unsigned)cap->count1
|| (mb_charlen(ptr) < cap->count1)) {
clearopbeep(cap->oap);
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 5d505f41a2..10e957287e 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -722,26 +722,26 @@ int get_expr_register(void)
if (*new_line == NUL) { // use previous line
xfree(new_line);
} else {
- set_expr_line(new_line);
+ set_expr_line((char *)new_line);
}
return '=';
}
/// Set the expression for the '=' register.
/// Argument must be an allocated string.
-void set_expr_line(char_u *new_line)
+void set_expr_line(char *new_line)
{
xfree(expr_line);
- expr_line = new_line;
+ expr_line = (char_u *)new_line;
}
/// Get the result of the '=' register expression.
///
/// @return a pointer to allocated memory, or NULL for failure.
-char_u *get_expr_line(void)
+char *get_expr_line(void)
{
- char_u *expr_copy;
- char_u *rv;
+ char *expr_copy;
+ char *rv;
static int nested = 0;
if (expr_line == NULL) {
@@ -750,7 +750,7 @@ char_u *get_expr_line(void)
// Make a copy of the expression, because evaluating it may cause it to be
// changed.
- expr_copy = vim_strsave(expr_line);
+ expr_copy = xstrdup((char *)expr_line);
// When we are invoked recursively limit the evaluation to 10 levels.
// Then return the string as-is.
@@ -759,19 +759,19 @@ char_u *get_expr_line(void)
}
nested++;
- rv = (char_u *)eval_to_string((char *)expr_copy, NULL, true);
+ rv = eval_to_string(expr_copy, NULL, true);
nested--;
xfree(expr_copy);
return rv;
}
/// Get the '=' register expression itself, without evaluating it.
-char_u *get_expr_line_src(void)
+char *get_expr_line_src(void)
{
if (expr_line == NULL) {
return NULL;
}
- return vim_strsave(expr_line);
+ return xstrdup((char *)expr_line);
}
/// @return whether `regname` is a valid name of a yank register.
@@ -1070,11 +1070,11 @@ static char_u *execreg_line_continuation(char **lines, size_t *idx)
}
}
ga_append(&ga, NUL);
- char_u *str = vim_strsave(ga.ga_data);
+ char *str = xstrdup(ga.ga_data);
ga_clear(&ga);
*idx = i;
- return str;
+ return (char_u *)str;
}
/// Execute a yank register: copy it into the stuff buffer
@@ -1130,7 +1130,7 @@ int do_execreg(int regname, int colon, int addcr, int silent)
}
xfree(p);
} else if (regname == '=') {
- p = get_expr_line();
+ p = (char_u *)get_expr_line();
if (p == NULL) {
return FAIL;
}
@@ -1338,7 +1338,7 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg)
return true;
case '=': // result of expression
- *argp = (char *)get_expr_line();
+ *argp = get_expr_line();
*allocated = true;
return true;
@@ -1392,7 +1392,7 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg)
return false;
}
- *argp = (char *)ml_get_buf(curwin->w_buffer, curwin->w_cursor.lnum, false);
+ *argp = ml_get_buf(curwin->w_buffer, curwin->w_cursor.lnum, false);
return true;
case '_': // black hole: always empty
@@ -1801,7 +1801,7 @@ static void mb_adjust_opend(oparg_T *oap)
static inline void pbyte(pos_T lp, int c)
{
assert(c <= UCHAR_MAX);
- *(ml_get_buf(curbuf, lp.lnum, true) + lp.col) = (char_u)c;
+ *(ml_get_buf(curbuf, lp.lnum, true) + lp.col) = (char)c;
if (!curbuf_splice_pending) {
extmark_splice_cols(curbuf, (int)lp.lnum - 1, lp.col, 1, 1, kExtmarkUndo);
}
@@ -1978,7 +1978,7 @@ static int op_replace(oparg_T *oap, int c)
n = gchar_cursor();
if (n != NUL) {
int new_byte_len = utf_char2len(c);
- int old_byte_len = utfc_ptr2len((char *)get_cursor_pos_ptr());
+ int old_byte_len = utfc_ptr2len(get_cursor_pos_ptr());
if (new_byte_len > 1 || old_byte_len > 1) {
// This is slow, but it handles replacing a single-byte
@@ -2199,7 +2199,7 @@ bool swapchar(int op_type, pos_T *pos)
curwin->w_cursor = *pos;
// don't use del_char(), it also removes composing chars
- del_bytes(utf_ptr2len((char *)get_cursor_pos_ptr()), false, false);
+ del_bytes(utf_ptr2len(get_cursor_pos_ptr()), false, false);
ins_char(nc);
curwin->w_cursor = sp;
} else {
@@ -2995,7 +2995,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
// STRLEN(ml_get(curwin->w_cursor.lnum)). With 'virtualedit' and the
// cursor past the end of the line, curwin->w_cursor.coladd is
// incremented instead of curwin->w_cursor.col.
- char_u *cursor_pos = get_cursor_pos_ptr();
+ char_u *cursor_pos = (char_u *)get_cursor_pos_ptr();
bool one_past_line = (*cursor_pos == NUL);
bool eol = false;
if (!one_past_line) {
@@ -3101,7 +3101,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
if (u_save_cursor() == FAIL) {
goto end;
}
- char *p = (char *)get_cursor_pos_ptr();
+ char *p = get_cursor_pos_ptr();
if (dir == FORWARD && *p != NUL) {
MB_PTR_ADV(p);
}
@@ -3210,7 +3210,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
}
// move to start of next multi-byte character
- curwin->w_cursor.col += utfc_ptr2len((char *)get_cursor_pos_ptr());
+ curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr());
col++;
} else {
getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2);
@@ -3393,7 +3393,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
// if type is kMTCharWise, FORWARD is the same as BACKWARD on the next
// char
if (dir == FORWARD && gchar_cursor() != NUL) {
- int bytelen = utfc_ptr2len((char *)get_cursor_pos_ptr());
+ int bytelen = utfc_ptr2len(get_cursor_pos_ptr());
// put it on the next of the multi-byte character.
col += bytelen;
@@ -4853,13 +4853,13 @@ void format_reg_type(MotionType reg_type, colnr_T reg_width, char *buf, size_t b
/// Otherwise just return `s`.
///
/// @return a void * for use in get_reg_contents().
-static void *get_reg_wrap_one_line(char_u *s, int flags)
+static void *get_reg_wrap_one_line(char *s, int flags)
{
if (!(flags & kGRegList)) {
return s;
}
list_T *const list = tv_list_alloc(1);
- tv_list_append_allocated_string(list, (char *)s);
+ tv_list_append_allocated_string(list, s);
return list;
}
@@ -4901,9 +4901,9 @@ void *get_reg_contents(int regname, int flags)
return NULL;
}
if (allocated) {
- return get_reg_wrap_one_line((char_u *)retval, flags);
+ return get_reg_wrap_one_line(retval, flags);
}
- return get_reg_wrap_one_line(vim_strsave((char_u *)retval), flags);
+ return get_reg_wrap_one_line(xstrdup(retval), flags);
}
yankreg_T *reg = get_yank_register(regname, YREG_PASTE);
@@ -5574,7 +5574,7 @@ static Callback opfunc_cb;
/// @return OK or FAIL
int set_operatorfunc_option(void)
{
- return option_set_callback_func((char_u *)p_opfunc, &opfunc_cb);
+ return option_set_callback_func(p_opfunc, &opfunc_cb);
}
#if defined(EXITFREE)
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 12c2888f5c..e54e6080f0 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -420,7 +420,7 @@ void set_init_1(bool clean_arg)
// use utf-8 as 'default' if locale encoding can't be detected.
p = (char_u *)xmemdupz(S_LEN("utf-8"));
}
- fenc_default = p;
+ fenc_default = (char *)p;
#ifdef HAVE_WORKING_LIBINTL
// GNU gettext 0.10.37 supports this feature: set the codeset used for
@@ -1129,9 +1129,9 @@ int do_set(char *arg, int opt_flags)
opt_flags);
} else if (opt_idx >= 0) { // String.
char_u *save_arg = NULL;
- char_u *s = NULL;
+ char *s = NULL;
char_u *oldval = NULL; // previous value if *varp
- char_u *newval;
+ char *newval;
char_u *origval = NULL;
char_u *origval_l = NULL;
char_u *origval_g = NULL;
@@ -1175,24 +1175,24 @@ int do_set(char *arg, int opt_flags)
}
if (nextchar == '&') { // set to default val
- newval = options[opt_idx].def_val;
+ newval = (char *)options[opt_idx].def_val;
// expand environment variables and ~ since the
// default value was already expanded, only
// required when an environment variable was set
// later
if (newval == NULL) {
- newval = (char_u *)empty_option;
+ newval = empty_option;
} else if (!(options[opt_idx].flags & P_NO_DEF_EXP)) {
- s = option_expand(opt_idx, newval);
+ s = (char *)option_expand(opt_idx, (char_u *)newval);
if (s == NULL) {
s = newval;
}
- newval = vim_strsave(s);
+ newval = xstrdup(s);
} else {
- newval = (char_u *)xstrdup((char *)newval);
+ newval = xstrdup(newval);
}
} else if (nextchar == '<') { // set to global val
- newval = vim_strsave(*(char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL));
+ newval = xstrdup(*(char **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL));
} else {
arg++; // jump to after the '=' or ':'
@@ -1212,13 +1212,13 @@ int do_set(char *arg, int opt_flags)
*(char **)varp = empty_option;
break;
case 1:
- *(char_u **)varp = vim_strsave((char_u *)"indent,eol");
+ *(char_u **)varp = (char_u *)xstrdup("indent,eol");
break;
case 2:
- *(char_u **)varp = vim_strsave((char_u *)"indent,eol,start");
+ *(char_u **)varp = (char_u *)xstrdup("indent,eol,start");
break;
case 3:
- *(char_u **)varp = vim_strsave((char_u *)"indent,eol,nostop");
+ *(char_u **)varp = (char_u *)xstrdup("indent,eol,nostop");
break;
}
xfree(oldval);
@@ -1301,7 +1301,7 @@ int do_set(char *arg, int opt_flags)
arg += i;
s += i;
} else {
- *s++ = (uint8_t)(*arg++);
+ *s++ = *arg++;
}
}
*s = NUL;
@@ -1311,7 +1311,7 @@ int do_set(char *arg, int opt_flags)
// comma.
if (!(adding || prepending || removing)
|| (flags & P_COMMA)) {
- s = option_expand(opt_idx, newval);
+ s = (char *)option_expand(opt_idx, (char_u *)newval);
if (s != NULL) {
xfree(newval);
newlen = (unsigned)STRLEN(s) + 1;
@@ -1328,7 +1328,7 @@ int do_set(char *arg, int opt_flags)
i = 0; // init for GCC
if (removing || (flags & P_NODUP)) {
i = (int)STRLEN(newval);
- s = find_dup_item(origval, newval, flags);
+ s = (char *)find_dup_item(origval, (char_u *)newval, flags);
// do not add if already there
if ((adding || prepending) && s != NULL) {
@@ -1340,7 +1340,7 @@ int do_set(char *arg, int opt_flags)
// if no duplicate, move pointer to end of
// original value
if (s == NULL) {
- s = origval + (int)STRLEN(origval);
+ s = (char *)origval + (int)STRLEN(origval);
}
}
@@ -1377,7 +1377,7 @@ int do_set(char *arg, int opt_flags)
if (*s) {
// may need to remove a comma
if (flags & P_COMMA) {
- if (s == origval) {
+ if (s == (char *)origval) {
// include comma after string
if (s[i] == ',') {
i++;
@@ -1388,7 +1388,7 @@ int do_set(char *arg, int opt_flags)
i++;
}
}
- STRMOVE(newval + (s - origval), s + i);
+ STRMOVE(newval + (s - (char *)origval), s + i);
}
}
@@ -1399,14 +1399,14 @@ int do_set(char *arg, int opt_flags)
// 'whichwrap'
if (flags & P_ONECOMMA) {
if (*s != ',' && *(s + 1) == ','
- && vim_strchr((char *)s + 2, *s) != NULL) {
+ && vim_strchr(s + 2, *s) != NULL) {
// Remove the duplicated value and the next comma.
STRMOVE(s, s + 2);
continue;
}
} else {
if ((!(flags & P_COMMA) || *s != ',')
- && vim_strchr((char *)s + 1, *s) != NULL) {
+ && vim_strchr(s + 1, *s) != NULL) {
STRMOVE(s, s + 1);
continue;
}
@@ -1421,7 +1421,7 @@ int do_set(char *arg, int opt_flags)
}
// Set the new value.
- *(char_u **)(varp) = newval;
+ *(char_u **)(varp) = (char_u *)newval;
// origval may be freed by
// did_set_string_option(), make a copy.
@@ -1431,7 +1431,7 @@ int do_set(char *arg, int opt_flags)
// newval (and varp) may become invalid if the
// buffer is closed by autocommands.
- saved_newval = (newval != NULL) ? xstrdup((char *)newval) : 0;
+ saved_newval = (newval != NULL) ? xstrdup(newval) : 0;
{
uint32_t *p = insecure_flag(curwin, opt_idx, opt_flags);
@@ -4451,7 +4451,7 @@ void buf_copy_options(buf_T *buf, int flags)
buf->b_p_cpt = xstrdup(p_cpt);
COPY_OPT_SCTX(buf, BV_CPT);
#ifdef BACKSLASH_IN_FILENAME
- buf->b_p_csl = vim_strsave(p_csl);
+ buf->b_p_csl = xstrdup(p_csl);
COPY_OPT_SCTX(buf, BV_CSL);
#endif
buf->b_p_cfu = xstrdup(p_cfu);
@@ -4826,7 +4826,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi
int num_normal = 0; // Nr of matching non-term-code settings
int match;
int count = 0;
- char_u *str;
+ char *str;
int loop;
static char *(names[]) = { "all" };
int ic = regmatch->rm_ic; // remember the ignore-case flag
@@ -4848,7 +4848,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi
}
}
}
- for (size_t opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
+ for (size_t opt_idx = 0; (str = options[opt_idx].fullname) != NULL;
opt_idx++) {
if (options[opt_idx].var == NULL) {
continue;
@@ -4858,7 +4858,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi
continue;
}
match = false;
- if (vim_regexec(regmatch, (char *)str, (colnr_T)0)
+ if (vim_regexec(regmatch, str, (colnr_T)0)
|| (options[opt_idx].shortname != NULL
&& vim_regexec(regmatch,
options[opt_idx].shortname,
@@ -4870,7 +4870,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi
if (loop == 0) {
num_normal++;
} else {
- (*file)[count++] = (char *)vim_strsave(str);
+ (*file)[count++] = xstrdup(str);
}
}
}
@@ -4881,7 +4881,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi
} else {
return OK;
}
- *file = xmalloc((size_t)(*num_file) * sizeof(char_u *));
+ *file = xmalloc((size_t)(*num_file) * sizeof(char *));
}
}
return OK;
@@ -5230,7 +5230,7 @@ int fill_culopt_flags(char *val, win_T *wp)
/// Set the callback function value for an option that accepts a function name,
/// lambda, et al. (e.g. 'operatorfunc', 'tagfunc', etc.)
/// @return OK if the option is successfully set to a function, otherwise FAIL
-int option_set_callback_func(char_u *optval, Callback *optcb)
+int option_set_callback_func(char *optval, Callback *optcb)
{
if (optval == NULL || *optval == NUL) {
callback_free(optcb);
@@ -5242,7 +5242,7 @@ int option_set_callback_func(char_u *optval, Callback *optcb)
|| (STRNCMP(optval, "function(", 9) == 0)
|| (STRNCMP(optval, "funcref(", 8) == 0)) {
// Lambda expression or a funcref
- tv = eval_expr((char *)optval);
+ tv = eval_expr(optval);
if (tv == NULL) {
return FAIL;
}
@@ -5250,7 +5250,7 @@ int option_set_callback_func(char_u *optval, Callback *optcb)
// treat everything else as a function name string
tv = xcalloc(1, sizeof(*tv));
tv->v_type = VAR_STRING;
- tv->vval.v_string = (char *)vim_strsave(optval);
+ tv->vval.v_string = xstrdup(optval);
}
Callback cb;
diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c
index c226966ef6..8581dae7a3 100644
--- a/src/nvim/optionstr.c
+++ b/src/nvim/optionstr.c
@@ -253,7 +253,7 @@ void check_buf_options(buf_T *buf)
/// Free the string allocated for an option.
/// Checks for the string being empty_option. This may happen if we're out of
-/// memory, vim_strsave() returned NULL, which was replaced by empty_option by
+/// memory, xstrdup() returned NULL, which was replaced by empty_option by
/// check_options().
/// Does NOT check for P_ALLOCED flag!
void free_string_option(char *p)
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index c940c86675..2f2a8c7fdc 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -669,8 +669,8 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo
ExpandInit(&xpc);
xpc.xp_context = EXPAND_FILES;
- var = ExpandOne(&xpc, dst, NULL,
- WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE);
+ var = (char_u *)ExpandOne(&xpc, (char *)dst, NULL,
+ WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE);
mustfree = true;
}
#else
@@ -684,7 +684,7 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo
// If 'shellslash' is set change backslashes to forward slashes.
// Can't use slash_adjust(), p_ssl may be set temporarily.
if (p_ssl && var != NULL && vim_strchr(var, '\\') != NULL) {
- char_u *p = vim_strsave(var);
+ char_u *p = xstrdup(var);
if (mustfree) {
xfree(var);
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index f3b3c1dfbf..25f51f89a9 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -52,11 +52,11 @@ static void save_patterns(int num_pat, char **pat, int *num_file, char ***file)
{
*file = xmalloc((size_t)num_pat * sizeof(char_u *));
for (int i = 0; i < num_pat; i++) {
- char_u *s = vim_strsave((char_u *)pat[i]);
+ char *s = xstrdup(pat[i]);
// Be compatible with expand_filename(): halve the number of
// backslashes.
- backslash_halve((char *)s);
- (*file)[i] = (char *)s;
+ backslash_halve(s);
+ (*file)[i] = s;
}
*num_file = num_pat;
}
@@ -160,7 +160,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in
}
// get a name for the temp file
- if ((tempname = vim_tempname()) == NULL) {
+ if ((tempname = (char_u *)vim_tempname()) == NULL) {
emsg(_(e_notmp));
return FAIL;
}
@@ -746,7 +746,7 @@ char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags, size_t *ret
}
// get a name for the temp file
- char_u *tempname = vim_tempname();
+ char_u *tempname = (char_u *)vim_tempname();
if (tempname == NULL) {
emsg(_(e_notmp));
return NULL;
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 2646b9e75e..accd7badbb 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -829,10 +829,10 @@ static bool is_unique(char_u *maybe_unique, garray_T *gap, int i)
static void expand_path_option(char_u *curdir, garray_T *gap)
{
char_u *path_option = *curbuf->b_p_path == NUL ? p_path : (char_u *)curbuf->b_p_path;
- char_u *buf = xmalloc(MAXPATHL);
+ char *buf = xmalloc(MAXPATHL);
while (*path_option != NUL) {
- copy_option_part((char **)&path_option, (char *)buf, MAXPATHL, " ,");
+ copy_option_part((char **)&path_option, buf, MAXPATHL, " ,");
if (buf[0] == '.' && (buf[1] == NUL || vim_ispathsep(buf[1]))) {
// Relative to current buffer:
@@ -852,12 +852,12 @@ static void expand_path_option(char_u *curdir, garray_T *gap)
STRMOVE(buf + len, buf + 2);
}
memmove(buf, curbuf->b_ffname, len);
- simplify_filename(buf);
+ simplify_filename((char_u *)buf);
} else if (buf[0] == NUL) {
STRCPY(buf, curdir); // relative to current directory
- } else if (path_with_url((char *)buf)) {
+ } else if (path_with_url(buf)) {
continue; // URL can't be used here
- } else if (!path_is_absolute(buf)) {
+ } else if (!path_is_absolute((char_u *)buf)) {
// Expand relative path to their full path equivalent
size_t len = STRLEN(curdir);
if (len + STRLEN(buf) + 3 > MAXPATHL) {
@@ -866,10 +866,10 @@ static void expand_path_option(char_u *curdir, garray_T *gap)
STRMOVE(buf + len + 1, buf);
STRCPY(buf, curdir);
buf[len] = (char_u)PATHSEP;
- simplify_filename(buf);
+ simplify_filename((char_u *)buf);
}
- GA_APPEND(char_u *, gap, vim_strsave(buf));
+ GA_APPEND(char *, gap, xstrdup(buf));
}
xfree(buf);
@@ -919,12 +919,12 @@ static char_u *get_path_cutoff(char_u *fname, garray_T *gap)
// that matches the pattern. Beware, this is at least O(n^2) wrt "gap->ga_len".
static void uniquefy_paths(garray_T *gap, char_u *pattern)
{
- char_u **fnames = (char_u **)gap->ga_data;
+ char **fnames = gap->ga_data;
bool sort_again = false;
regmatch_T regmatch;
garray_T path_ga;
- char_u **in_curdir = NULL;
- char_u *short_name;
+ char **in_curdir = NULL;
+ char *short_name;
ga_remove_duplicate_strings(gap);
ga_init(&path_ga, (int)sizeof(char_u *), 1);
@@ -933,11 +933,11 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
// regex matches anywhere in the path. FIXME: is this valid for all
// possible patterns?
size_t len = STRLEN(pattern);
- char_u *file_pattern = xmalloc(len + 2);
+ char *file_pattern = xmalloc(len + 2);
file_pattern[0] = '*';
file_pattern[1] = NUL;
STRCAT(file_pattern, pattern);
- char *pat = file_pat_to_reg_pat((char *)file_pattern, NULL, NULL, true);
+ char *pat = file_pat_to_reg_pat(file_pattern, NULL, NULL, true);
xfree(file_pattern);
if (pat == NULL) {
return;
@@ -957,21 +957,21 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
in_curdir = xcalloc((size_t)gap->ga_len, sizeof(char_u *));
for (int i = 0; i < gap->ga_len && !got_int; i++) {
- char_u *path = fnames[i];
+ char *path = fnames[i];
int is_in_curdir;
- char_u *dir_end = (char_u *)gettail_dir((const char *)path);
- char_u *pathsep_p;
- char_u *path_cutoff;
+ char *dir_end = (char *)gettail_dir((const char *)path);
+ char *pathsep_p;
+ char *path_cutoff;
len = STRLEN(path);
is_in_curdir = FNAMENCMP(curdir, path, dir_end - path) == 0
&& curdir[dir_end - path] == NUL;
if (is_in_curdir) {
- in_curdir[i] = vim_strsave(path);
+ in_curdir[i] = xstrdup(path);
}
// Shorten the filename while maintaining its uniqueness
- path_cutoff = get_path_cutoff(path, &path_ga);
+ path_cutoff = (char *)get_path_cutoff((char_u *)path, &path_ga);
// Don't assume all files can be reached without path when search
// pattern starts with **/, so only remove path_cutoff
@@ -979,17 +979,17 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
if (pattern[0] == '*' && pattern[1] == '*'
&& vim_ispathsep_nocolon(pattern[2])
&& path_cutoff != NULL
- && vim_regexec(&regmatch, (char *)path_cutoff, (colnr_T)0)
- && is_unique(path_cutoff, gap, i)) {
+ && vim_regexec(&regmatch, path_cutoff, (colnr_T)0)
+ && is_unique((char_u *)path_cutoff, gap, i)) {
sort_again = true;
memmove(path, path_cutoff, STRLEN(path_cutoff) + 1);
} else {
// Here all files can be reached without path, so get shortest
// unique path. We start at the end of the path. */
pathsep_p = path + len - 1;
- while (find_previous_pathsep(path, &pathsep_p)) {
- if (vim_regexec(&regmatch, (char *)pathsep_p + 1, (colnr_T)0)
- && is_unique(pathsep_p + 1, gap, i)
+ while (find_previous_pathsep((char_u *)path, (char_u **)&pathsep_p)) {
+ if (vim_regexec(&regmatch, pathsep_p + 1, (colnr_T)0)
+ && is_unique((char_u *)pathsep_p + 1, gap, i)
&& path_cutoff != NULL && pathsep_p + 1 >= path_cutoff) {
sort_again = true;
memmove(path, pathsep_p + 1, STRLEN(pathsep_p));
@@ -998,7 +998,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
}
}
- if (path_is_absolute(path)) {
+ if (path_is_absolute((char_u *)path)) {
// Last resort: shorten relative to curdir if possible.
// 'possible' means:
// 1. It is under the current directory.
@@ -1009,10 +1009,10 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
// c:\foo\bar\file.txt c:\foo\bar .\file.txt
// /file.txt / /file.txt
// c:\file.txt c:\ .\file.txt
- short_name = path_shorten_fname(path, curdir);
+ short_name = (char *)path_shorten_fname((char_u *)path, curdir);
if (short_name != NULL && short_name > path + 1) {
STRCPY(path, ".");
- add_pathsep((char *)path);
+ add_pathsep(path);
STRMOVE(path + STRLEN(path), short_name);
}
}
@@ -1021,8 +1021,8 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
// Shorten filenames in /in/current/directory/{filename}
for (int i = 0; i < gap->ga_len && !got_int; i++) {
- char_u *rel_path;
- char_u *path = in_curdir[i];
+ char *rel_path;
+ char *path = in_curdir[i];
if (path == NULL) {
continue;
@@ -1030,18 +1030,18 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
// If the {filename} is not unique, change it to ./{filename}.
// Else reduce it to {filename}
- short_name = path_shorten_fname(path, curdir);
+ short_name = (char *)path_shorten_fname((char_u *)path, curdir);
if (short_name == NULL) {
short_name = path;
}
- if (is_unique(short_name, gap, i)) {
+ if (is_unique((char_u *)short_name, gap, i)) {
STRCPY(fnames[i], short_name);
continue;
}
rel_path = xmalloc(STRLEN(short_name) + STRLEN(PATHSEPSTR) + 2);
STRCPY(rel_path, ".");
- add_pathsep((char *)rel_path);
+ add_pathsep(rel_path);
STRCAT(rel_path, short_name);
xfree(fnames[i]);
@@ -2099,11 +2099,11 @@ char_u *path_shorten_fname(char_u *full_path, char_u *dir_name)
/// If FAIL is returned, *num_file and *file are either
/// unchanged or *num_file is set to 0 and *file is set
/// to NULL or points to "".
-int expand_wildcards_eval(char_u **pat, int *num_file, char ***file, int flags)
+int expand_wildcards_eval(char **pat, int *num_file, char ***file, int flags)
{
int ret = FAIL;
- char_u *eval_pat = NULL;
- char *exp_pat = (char *)(*pat);
+ char *eval_pat = NULL;
+ char *exp_pat = *pat;
char *ignored_msg;
size_t usedlen;
const bool is_cur_alt_file = *exp_pat == '%' || *exp_pat == '#';
@@ -2111,12 +2111,13 @@ int expand_wildcards_eval(char_u **pat, int *num_file, char ***file, int flags)
if (is_cur_alt_file || *exp_pat == '<') {
emsg_off++;
- eval_pat = eval_vars((char_u *)exp_pat, (char_u *)exp_pat, &usedlen, NULL, &ignored_msg, NULL,
- true);
+ eval_pat = (char *)eval_vars((char_u *)exp_pat, (char_u *)exp_pat, &usedlen, NULL, &ignored_msg,
+ NULL,
+ true);
emsg_off--;
if (eval_pat != NULL) {
star_follows = strcmp(exp_pat + usedlen, "*") == 0;
- exp_pat = concat_str((char *)eval_pat, exp_pat + usedlen);
+ exp_pat = concat_str(eval_pat, exp_pat + usedlen);
}
}
@@ -2130,7 +2131,7 @@ int expand_wildcards_eval(char_u **pat, int *num_file, char ***file, int flags)
// pattern anyway (without the star) so that this works for remote
// files and non-file buffer names.
*file = xmalloc(sizeof(char *));
- **file = (char *)eval_pat;
+ **file = eval_pat;
eval_pat = NULL;
*num_file = 1;
ret = OK;
diff --git a/src/nvim/plines.c b/src/nvim/plines.c
index 3ba09b45a1..c676dcddbd 100644
--- a/src/nvim/plines.c
+++ b/src/nvim/plines.c
@@ -102,7 +102,7 @@ int plines_win_nofold(win_T *wp, linenr_T lnum)
unsigned int col;
int width;
- s = (char *)ml_get_buf(wp->w_buffer, lnum, false);
+ s = ml_get_buf(wp->w_buffer, lnum, false);
if (*s == NUL) { // empty line
return 1;
}
@@ -144,7 +144,7 @@ int plines_win_col(win_T *wp, linenr_T lnum, long column)
return lines + 1;
}
- char_u *line = ml_get_buf(wp->w_buffer, lnum, false);
+ char_u *line = (char_u *)ml_get_buf(wp->w_buffer, lnum, false);
colnr_T col = 0;
chartabsize_T cts;
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index 86f60cb57e..cd2dd4b89c 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -710,7 +710,7 @@ static int qf_get_next_buf_line(qfstate_T *state)
if (state->buflnum > state->lnumlast) {
return QF_END_OF_INPUT;
}
- char *p_buf = (char *)ml_get_buf(state->buf, state->buflnum, false);
+ char *p_buf = ml_get_buf(state->buf, state->buflnum, false);
state->buflnum += 1;
size_t len = STRLEN(p_buf);
@@ -3832,7 +3832,7 @@ static buf_T *qf_find_buf(qf_info_T *qi)
/// @return OK or FAIL
int qf_process_qftf_option(void)
{
- return option_set_callback_func((char_u *)p_qftf, &qftf_cb);
+ return option_set_callback_func(p_qftf, &qftf_cb);
}
/// Update the w:quickfix_title variable in the quickfix/location list window in
@@ -4317,7 +4317,7 @@ static char *get_mef_name(void)
static int off = 0;
if (*p_mef == NUL) {
- name = (char *)vim_tempname();
+ name = vim_tempname();
if (name == NULL) {
emsg(_(e_notmp));
}
@@ -5153,7 +5153,7 @@ static bool vgr_match_buflines(qf_list_T *qfl, char *fname, buf_T *buf, char *sp
fname,
NULL,
duplicate_name ? 0 : buf->b_fnum,
- (char *)ml_get_buf(buf, regmatch->startpos[0].lnum + lnum, false),
+ ml_get_buf(buf, regmatch->startpos[0].lnum + lnum, false),
regmatch->startpos[0].lnum + lnum,
regmatch->endpos[0].lnum + lnum,
regmatch->startpos[0].col + 1,
@@ -5180,7 +5180,7 @@ static bool vgr_match_buflines(qf_list_T *qfl, char *fname, buf_T *buf, char *sp
}
}
} else {
- char *const str = (char *)ml_get_buf(buf, lnum, false);
+ char *const str = ml_get_buf(buf, lnum, false);
int score;
uint32_t matches[MAX_FUZZY_MATCHES];
const size_t sz = sizeof(matches) / sizeof(matches[0]);
@@ -5260,7 +5260,7 @@ static bool existing_swapfile(const buf_T *buf)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) {
- const char *const fname = (char *)buf->b_ml.ml_mfp->mf_fname;
+ const char *const fname = buf->b_ml.ml_mfp->mf_fname;
const size_t len = STRLEN(fname);
return fname[len - 1] != 'p' || fname[len - 2] != 'w';
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index ffa68c56b2..a94f91d103 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -137,7 +137,7 @@ static int re_multi_type(int c)
return NOT_MULTI;
}
-static char_u *reg_prev_sub = NULL;
+static char *reg_prev_sub = NULL;
/*
* REGEXP_INRANGE contains all characters which are always special in a []
@@ -1040,7 +1040,7 @@ static char_u *reg_getline(linenr_T lnum)
// Must have matched the "\n" in the last line.
return (char_u *)"";
}
- return ml_get_buf(rex.reg_buf, rex.reg_firstlnum + lnum, false);
+ return (char_u *)ml_get_buf(rex.reg_buf, rex.reg_firstlnum + lnum, false);
}
static char_u *reg_startzp[NSUBEXP]; // Workspace to mark beginning
@@ -1523,23 +1523,21 @@ static fptr_T do_Lower(int *d, int c)
return (fptr_T)do_Lower;
}
-/*
- * regtilde(): Replace tildes in the pattern by the old pattern.
- *
- * Short explanation of the tilde: It stands for the previous replacement
- * pattern. If that previous pattern also contains a ~ we should go back a
- * step further... But we insert the previous pattern into the current one
- * and remember that.
- * This still does not handle the case where "magic" changes. So require the
- * user to keep his hands off of "magic".
- *
- * The tildes are parsed once before the first call to vim_regsub().
- */
-char_u *regtilde(char_u *source, int magic, bool preview)
+/// regtilde(): Replace tildes in the pattern by the old pattern.
+///
+/// Short explanation of the tilde: It stands for the previous replacement
+/// pattern. If that previous pattern also contains a ~ we should go back a
+/// step further... But we insert the previous pattern into the current one
+/// and remember that.
+/// This still does not handle the case where "magic" changes. So require the
+/// user to keep his hands off of "magic".
+///
+/// The tildes are parsed once before the first call to vim_regsub().
+char *regtilde(char *source, int magic, bool preview)
{
- char_u *newsub = source;
- char_u *tmpsub;
- char_u *p;
+ char *newsub = source;
+ char *tmpsub;
+ char *p;
int len;
int prevlen;
@@ -1575,7 +1573,7 @@ char_u *regtilde(char_u *source, int magic, bool preview)
if (*p == '\\' && p[1]) { // skip escaped characters
p++;
}
- p += utfc_ptr2len((char *)p) - 1;
+ p += utfc_ptr2len(p) - 1;
}
}
@@ -1584,7 +1582,7 @@ char_u *regtilde(char_u *source, int magic, bool preview)
// Store a copy of newsub in reg_prev_sub. It is always allocated,
// because recursive calls may make the returned string invalid.
xfree(reg_prev_sub);
- reg_prev_sub = vim_strsave(newsub);
+ reg_prev_sub = xstrdup(newsub);
}
return newsub;
@@ -1717,7 +1715,7 @@ int vim_regsub_multi(regmmatch_T *rmp, linenr_T lnum, char_u *source, char_u *de
// When nesting more than a couple levels it's probably a mistake.
#define MAX_REGSUB_NESTING 4
-static char_u *eval_result[MAX_REGSUB_NESTING] = { NULL, NULL, NULL, NULL };
+static char *eval_result[MAX_REGSUB_NESTING] = { NULL, NULL, NULL, NULL };
#if defined(EXITFREE)
void free_resub_eval_result(void)
@@ -1826,21 +1824,21 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, int des
eval_result[nested] = NULL;
} else {
char buf[NUMBUFLEN];
- eval_result[nested] = (char_u *)tv_get_string_buf_chk(&rettv, buf);
+ eval_result[nested] = (char *)tv_get_string_buf_chk(&rettv, buf);
if (eval_result[nested] != NULL) {
- eval_result[nested] = vim_strsave(eval_result[nested]);
+ eval_result[nested] = xstrdup(eval_result[nested]);
}
}
tv_clear(&rettv);
} else {
- eval_result[nested] = (char_u *)eval_to_string((char *)source + 2, NULL, true);
+ eval_result[nested] = eval_to_string((char *)source + 2, NULL, true);
}
nesting--;
if (eval_result[nested] != NULL) {
int had_backslash = false;
- for (s = eval_result[nested]; *s != NUL; MB_PTR_ADV(s)) {
+ for (s = (char_u *)eval_result[nested]; *s != NUL; MB_PTR_ADV(s)) {
// Change NL to CR, so that it becomes a line break,
// unless called from vim_regexec_nl().
// Skip over a backslashed character.
@@ -1862,9 +1860,9 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, int des
}
if (had_backslash && (flags & REGSUB_BACKSLASH)) {
// Backslashes will be consumed, need to double them.
- s = vim_strsave_escaped(eval_result[nested], (char_u *)"\\");
+ s = vim_strsave_escaped((char_u *)eval_result[nested], (char_u *)"\\");
xfree(eval_result[nested]);
- eval_result[nested] = s;
+ eval_result[nested] = (char *)s;
}
dst += STRLEN(eval_result[nested]);
@@ -2466,12 +2464,12 @@ static bool vim_regexec_string(regmatch_T *rmp, char_u *line, colnr_T col, bool
&& result == NFA_TOO_EXPENSIVE) {
int save_p_re = (int)p_re;
int re_flags = (int)rmp->regprog->re_flags;
- char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern);
+ char *pat = xstrdup(((nfa_regprog_T *)rmp->regprog)->pattern);
p_re = BACKTRACKING_ENGINE;
vim_regfree(rmp->regprog);
- report_re_switch(pat);
- rmp->regprog = vim_regcomp((char *)pat, re_flags);
+ report_re_switch((char_u *)pat);
+ rmp->regprog = vim_regcomp(pat, re_flags);
if (rmp->regprog != NULL) {
rmp->regprog->re_in_use = true;
result = rmp->regprog->engine->regexec_nl(rmp, line, col, nl);
@@ -2557,16 +2555,16 @@ long vim_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum,
&& result == NFA_TOO_EXPENSIVE) {
int save_p_re = (int)p_re;
int re_flags = (int)rmp->regprog->re_flags;
- char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern);
+ char *pat = xstrdup(((nfa_regprog_T *)rmp->regprog)->pattern);
p_re = BACKTRACKING_ENGINE;
regprog_T *prev_prog = rmp->regprog;
- report_re_switch(pat);
+ report_re_switch((char_u *)pat);
// checking for \z misuse was already done when compiling for NFA,
// allow all here
reg_do_extmatch = REX_ALL;
- rmp->regprog = vim_regcomp((char *)pat, re_flags);
+ rmp->regprog = vim_regcomp(pat, re_flags);
reg_do_extmatch = 0;
if (rmp->regprog == NULL) {
diff --git a/src/nvim/regexp_bt.c b/src/nvim/regexp_bt.c
index ccf2b60da2..63e4dd5b7e 100644
--- a/src/nvim/regexp_bt.c
+++ b/src/nvim/regexp_bt.c
@@ -1857,14 +1857,14 @@ static char_u *regatom(int *flagp)
char_u *lp;
ret = regnode(EXACTLY);
- lp = reg_prev_sub;
+ lp = (char_u *)reg_prev_sub;
while (*lp != NUL) {
regc(*lp++);
}
regc(NUL);
if (*reg_prev_sub != NUL) {
*flagp |= HASWIDTH;
- if ((lp - reg_prev_sub) == 1) {
+ if ((lp - (char_u *)reg_prev_sub) == 1) {
*flagp |= SIMPLE;
}
}
diff --git a/src/nvim/regexp_defs.h b/src/nvim/regexp_defs.h
index b313dfe877..5d7175b89a 100644
--- a/src/nvim/regexp_defs.h
+++ b/src/nvim/regexp_defs.h
@@ -127,7 +127,7 @@ typedef struct {
int has_zend; // pattern contains \ze
int has_backref; // pattern contains \1 .. \9
int reghasz;
- char_u *pattern;
+ char *pattern;
int nsubexp; // number of ()
int nstate;
nfa_state_T state[1]; // actually longer..
diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c
index 4c1058ba36..ea11398c30 100644
--- a/src/nvim/regexp_nfa.c
+++ b/src/nvim/regexp_nfa.c
@@ -1959,9 +1959,9 @@ static int nfa_regatom(void)
emsg(_(e_nopresub));
return FAIL;
}
- for (lp = reg_prev_sub; *lp != NUL; MB_CPTR_ADV(lp)) {
+ for (lp = (char_u *)reg_prev_sub; *lp != NUL; MB_CPTR_ADV(lp)) {
EMIT(utf_ptr2char((char *)lp));
- if (lp != reg_prev_sub) {
+ if (lp != (char_u *)reg_prev_sub) {
EMIT(NFA_CONCAT);
}
}
@@ -7593,7 +7593,7 @@ static regprog_T *nfa_regcomp(char_u *expr, int re_flags)
#endif
// Remember whether this pattern has any \z specials in it.
prog->reghasz = re_has_z;
- prog->pattern = vim_strsave(expr);
+ prog->pattern = xstrdup((char *)expr);
#ifdef REGEXP_DEBUG
nfa_regengine.expr = NULL;
#endif
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index d268dde845..8e10f2d62d 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -620,7 +620,7 @@ void setcursor_mayforce(bool force)
// With 'rightleft' set and the cursor on a double-wide character,
// position it on the leftmost column.
col = curwin->w_width_inner - curwin->w_wcol
- - ((utf_ptr2cells((char *)get_cursor_pos_ptr()) == 2
+ - ((utf_ptr2cells(get_cursor_pos_ptr()) == 2
&& vim_isprintc(gchar_cursor())) ? 2 : 1);
}
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 490e79ebb0..e2df31c04f 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -175,11 +175,11 @@ int search_regcomp(char_u *pat, int pat_save, int pat_use, int options, regmmatc
if (!(options & SEARCH_KEEP) && (cmdmod.cmod_flags & CMOD_KEEPPATTERNS) == 0) {
// search or global command
if (pat_save == RE_SEARCH || pat_save == RE_BOTH) {
- save_re_pat(RE_SEARCH, pat, magic);
+ save_re_pat(RE_SEARCH, (char *)pat, magic);
}
// substitute or global command
if (pat_save == RE_SUBST || pat_save == RE_BOTH) {
- save_re_pat(RE_SUBST, pat, magic);
+ save_re_pat(RE_SUBST, (char *)pat, magic);
}
}
@@ -198,11 +198,11 @@ char_u *get_search_pat(void)
return mr_pattern;
}
-void save_re_pat(int idx, char_u *pat, int magic)
+void save_re_pat(int idx, char *pat, int magic)
{
- if (spats[idx].pat != pat) {
+ if (spats[idx].pat != (char_u *)pat) {
free_spat(&spats[idx]);
- spats[idx].pat = vim_strsave(pat);
+ spats[idx].pat = (char_u *)xstrdup(pat);
spats[idx].magic = magic;
spats[idx].no_scs = no_smartcase;
spats[idx].timestamp = os_time();
@@ -225,11 +225,11 @@ void save_search_patterns(void)
if (save_level++ == 0) {
saved_spats[0] = spats[0];
if (spats[0].pat != NULL) {
- saved_spats[0].pat = vim_strsave(spats[0].pat);
+ saved_spats[0].pat = (char_u *)xstrdup((char *)spats[0].pat);
}
saved_spats[1] = spats[1];
if (spats[1].pat != NULL) {
- saved_spats[1].pat = vim_strsave(spats[1].pat);
+ saved_spats[1].pat = (char_u *)xstrdup((char *)spats[1].pat);
}
saved_spats_last_idx = last_idx;
saved_spats_no_hlsearch = no_hlsearch;
@@ -296,7 +296,7 @@ void save_last_search_pattern(void)
saved_last_search_spat = spats[RE_SEARCH];
if (spats[RE_SEARCH].pat != NULL) {
- saved_last_search_spat.pat = vim_strsave(spats[RE_SEARCH].pat);
+ saved_last_search_spat.pat = (char_u *)xstrdup((char *)spats[RE_SEARCH].pat);
}
saved_last_idx = last_idx;
saved_no_hlsearch = no_hlsearch;
@@ -474,7 +474,7 @@ void set_last_search_pat(const char_u *s, int idx, int magic, int setlast)
if (spats[idx].pat == NULL) {
saved_spats[idx].pat = NULL;
} else {
- saved_spats[idx].pat = vim_strsave(spats[idx].pat);
+ saved_spats[idx].pat = (char_u *)xstrdup((char *)spats[idx].pat);
}
saved_spats_last_idx = last_idx;
}
@@ -571,7 +571,7 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
&& pos->lnum <= buf->b_ml.ml_line_count
&& pos->col < MAXCOL - 2) {
// Watch out for the "col" being MAXCOL - 2, used in a closed fold.
- ptr = ml_get_buf(buf, pos->lnum, false);
+ ptr = (char_u *)ml_get_buf(buf, pos->lnum, false);
if ((int)STRLEN(ptr) <= pos->col) {
start_char_len = 1;
} else {
@@ -642,7 +642,7 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
if (lnum + matchpos.lnum > buf->b_ml.ml_line_count) {
ptr = (char_u *)"";
} else {
- ptr = ml_get_buf(buf, lnum + matchpos.lnum, false);
+ ptr = (char_u *)ml_get_buf(buf, lnum + matchpos.lnum, false);
}
// Forward search in the first line: match should be after
@@ -711,7 +711,7 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
}
// Need to get the line pointer again, a multi-line search may
// have made it invalid.
- ptr = ml_get_buf(buf, lnum, false);
+ ptr = (char_u *)ml_get_buf(buf, lnum, false);
}
if (!match_ok) {
continue;
@@ -794,7 +794,7 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
}
// Need to get the line pointer again, a
// multi-line search may have made it invalid.
- ptr = ml_get_buf(buf, lnum + matchpos.lnum, false);
+ ptr = (char_u *)ml_get_buf(buf, lnum + matchpos.lnum, false);
}
// If there is only a match after the cursor, skip
@@ -822,7 +822,7 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
} else {
pos->col--;
if (pos->lnum <= buf->b_ml.ml_line_count) {
- ptr = ml_get_buf(buf, pos->lnum, false);
+ ptr = (char_u *)ml_get_buf(buf, pos->lnum, false);
pos->col -= utf_head_off((char *)ptr, (char *)ptr + pos->col);
}
}
@@ -1443,7 +1443,7 @@ int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char_u *pat)
if (start == 0) {
start = pos->lnum;
}
- ptr = ml_get_buf(buf, pos->lnum, false);
+ ptr = (char_u *)ml_get_buf(buf, pos->lnum, false);
p = (char_u *)skipwhite((char *)ptr);
pos->col = (colnr_T)(p - ptr);
@@ -2717,7 +2717,7 @@ static void update_search_stat(int dirc, pos_T *pos, pos_T *cursor_pos, searchst
}
if (done_search) {
xfree(lastpat);
- lastpat = vim_strsave(spats[last_idx].pat);
+ lastpat = (char_u *)xstrdup((char *)spats[last_idx].pat);
chgtick = (int)buf_get_changedtick(curbuf);
lbuf = curbuf;
lastpos = p;
@@ -2827,7 +2827,7 @@ void f_searchcount(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
goto the_end;
}
xfree(spats[last_idx].pat);
- spats[last_idx].pat = vim_strsave(pattern);
+ spats[last_idx].pat = (char_u *)xstrdup((char *)pattern);
}
if (spats[last_idx].pat == NULL || *spats[last_idx].pat == NUL) {
goto the_end; // the previous pattern was never defined
@@ -3103,7 +3103,7 @@ bool fuzzy_match(char_u *const str, const char_u *const pat_arg, const bool matc
*outScore = 0;
- char_u *const save_pat = vim_strsave(pat_arg);
+ char_u *const save_pat = (char_u *)xstrdup((char *)pat_arg);
char_u *pat = save_pat;
char_u *p = pat;
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
index 1a70b77053..312c30e4a9 100644
--- a/src/nvim/shada.c
+++ b/src/nvim/shada.c
@@ -1238,7 +1238,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
// string is close to useless: you can only use it with :& or :~ and
// that’s all because s//~ is not available until the first call to
// regtilde. Vim was not calling this for some reason.
- (void)(char *)regtilde((char_u *)cur_entry.data.sub_string.sub, p_magic, false);
+ (void)regtilde(cur_entry.data.sub_string.sub, p_magic, false);
// Do not free shada entry: its allocated memory was saved above.
break;
case kSDItemHistoryEntry:
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 30e256b37a..7f07d2ff2c 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -194,8 +194,8 @@ int did_set_spelltab;
char *e_format = N_("E759: Format error in spell file");
// Remember what "z?" replaced.
-char_u *repl_from = NULL;
-char_u *repl_to = NULL;
+char *repl_from = NULL;
+char *repl_to = NULL;
/// Main spell-checking function.
/// "ptr" points to a character that could be the start of a word.
@@ -1275,7 +1275,7 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att
decor_spell_nav_start(wp);
while (!got_int) {
- char_u *line = ml_get_buf(wp->w_buffer, lnum, false);
+ char_u *line = (char_u *)ml_get_buf(wp->w_buffer, lnum, false);
len = STRLEN(line);
if (buflen < len + MAXWLEN + 2) {
@@ -1302,7 +1302,7 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att
// Need to get the line again, may have looked at the previous
// one.
- line = ml_get_buf(wp->w_buffer, lnum, false);
+ line = (char_u *)ml_get_buf(wp->w_buffer, lnum, false);
}
// Copy the line into "buf" and append the start of the next line if
@@ -1312,7 +1312,7 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att
STRCPY(buf, line);
if (lnum < wp->w_buffer->b_ml.ml_line_count) {
spell_cat_line(buf + STRLEN(buf),
- ml_get_buf(wp->w_buffer, lnum + 1, false),
+ (char_u *)ml_get_buf(wp->w_buffer, lnum + 1, false),
MAXWLEN);
}
char_u *p = buf + skip;
@@ -1573,15 +1573,15 @@ static void int_wordlist_spl(char_u *fname)
int_wordlist, spell_enc());
}
-// Allocate a new slang_T for language "lang". "lang" can be NULL.
-// Caller must fill "sl_next".
-slang_T *slang_alloc(char_u *lang)
+/// Allocate a new slang_T for language "lang". "lang" can be NULL.
+/// Caller must fill "sl_next".
+slang_T *slang_alloc(char *lang)
FUNC_ATTR_NONNULL_RET
{
slang_T *lp = xcalloc(1, sizeof(slang_T));
if (lang != NULL) {
- lp->sl_name = vim_strsave(lang);
+ lp->sl_name = xstrdup(lang);
}
ga_init(&lp->sl_rep, sizeof(fromto_T), 10);
ga_init(&lp->sl_repsal, sizeof(fromto_T), 10);
@@ -1693,7 +1693,7 @@ void slang_clear_sug(slang_T *lp)
static void spell_load_cb(char *fname, void *cookie)
{
spelload_T *slp = (spelload_T *)cookie;
- slang_T *slang = spell_load_file((char_u *)fname, slp->sl_lang, NULL, false);
+ slang_T *slang = spell_load_file(fname, (char *)slp->sl_lang, NULL, false);
if (slang != NULL) {
// When a previously loaded file has NOBREAK also use it for the
// ".add" files.
@@ -1861,7 +1861,7 @@ char *did_set_spelllang(win_T *wp)
langp_T *lp, *lp2;
static bool recursive = false;
char *ret_msg = NULL;
- char_u *spl_copy;
+ char *spl_copy;
bufref_T bufref;
set_bufref(&bufref, wp->w_buffer);
@@ -1879,12 +1879,12 @@ char *did_set_spelllang(win_T *wp)
// Make a copy of 'spelllang', the SpellFileMissing autocommands may change
// it under our fingers.
- spl_copy = vim_strsave((char_u *)wp->w_s->b_p_spl);
+ spl_copy = xstrdup(wp->w_s->b_p_spl);
wp->w_s->b_cjk = 0;
// Loop over comma separated language names.
- for (splp = (char *)spl_copy; *splp != NUL;) {
+ for (splp = spl_copy; *splp != NUL;) {
// Get one language name.
copy_option_part(&splp, (char *)lang, MAXWLEN, ",");
region = NULL;
@@ -1952,7 +1952,7 @@ char *did_set_spelllang(win_T *wp)
// If not found try loading the language now.
if (slang == NULL) {
if (filename) {
- (void)spell_load_file(lang, lang, NULL, false);
+ (void)spell_load_file((char *)lang, (char *)lang, NULL, false);
} else {
spell_load_lang(lang);
// SpellFileMissing autocommands may do anything, including
@@ -2054,7 +2054,7 @@ char *did_set_spelllang(win_T *wp)
*p = NUL; // truncate at ".encoding.add"
}
}
- slang = spell_load_file(spf_name, lang, NULL, true);
+ slang = spell_load_file((char *)spf_name, (char *)lang, NULL, true);
// If one of the languages has NOBREAK we assume the addition
// files also have this.
diff --git a/src/nvim/spell_defs.h b/src/nvim/spell_defs.h
index 27b9777dc2..2c4aebe420 100644
--- a/src/nvim/spell_defs.h
+++ b/src/nvim/spell_defs.h
@@ -115,7 +115,7 @@ typedef struct slang_S slang_T;
struct slang_S {
slang_T *sl_next; // next language
- char_u *sl_name; // language name "en", "en.rare", "nl", etc.
+ char *sl_name; // language name "en", "en.rare", "nl", etc.
char *sl_fname; // name of .spl file
bool sl_add; // true if it's a .add file.
@@ -252,7 +252,7 @@ typedef struct wordcount_S {
#define MAXWORDCOUNT 0xffff
// Remember what "z?" replaced.
-extern char_u *repl_from;
-extern char_u *repl_to;
+extern char *repl_from;
+extern char *repl_to;
#endif // NVIM_SPELL_DEFS_H
diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c
index 661ca54fad..e6e56d615c 100644
--- a/src/nvim/spellfile.c
+++ b/src/nvim/spellfile.c
@@ -572,10 +572,10 @@ static inline int spell_check_magic_string(FILE *const fd)
/// @param silent no error if file doesn't exist
///
/// @return the slang_T the spell file was loaded into. NULL for error.
-slang_T *spell_load_file(char_u *fname, char_u *lang, slang_T *old_lp, bool silent)
+slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent)
{
FILE *fd;
- char_u *p;
+ char *p;
int n;
int len;
slang_T *lp = NULL;
@@ -583,7 +583,7 @@ slang_T *spell_load_file(char_u *fname, char_u *lang, slang_T *old_lp, bool sile
int res;
bool did_estack_push = false;
- fd = os_fopen((char *)fname, "r");
+ fd = os_fopen(fname, "r");
if (fd == NULL) {
if (!silent) {
semsg(_(e_notopen), fname);
@@ -604,16 +604,16 @@ slang_T *spell_load_file(char_u *fname, char_u *lang, slang_T *old_lp, bool sile
lp = slang_alloc(lang);
// Remember the file name, used to reload the file when it's updated.
- lp->sl_fname = (char *)vim_strsave(fname);
+ lp->sl_fname = xstrdup(fname);
// Check for .add.spl.
- lp->sl_add = strstr(path_tail((char *)fname), SPL_FNAME_ADD) != NULL;
+ lp->sl_add = strstr(path_tail(fname), SPL_FNAME_ADD) != NULL;
} else {
lp = old_lp;
}
// Set sourcing_name, so that error messages mention the file name.
- estack_push(ETYPE_SPELL, (char *)fname, 0);
+ estack_push(ETYPE_SPELL, fname, 0);
did_estack_push = true;
// <HEADER>: <fileID>
@@ -697,11 +697,11 @@ slang_T *spell_load_file(char_u *fname, char_u *lang, slang_T *old_lp, bool sile
break;
case SN_MAP:
- p = READ_STRING(fd, len); // <mapstr>
+ p = (char *)READ_STRING(fd, len); // <mapstr>
if (p == NULL) {
goto endFAIL;
}
- set_map_str(lp, p);
+ set_map_str(lp, (char_u *)p);
xfree(p);
break;
@@ -1824,7 +1824,7 @@ static void spell_reload_one(char_u *fname, bool added_word)
for (slang = first_lang; slang != NULL; slang = slang->sl_next) {
if (path_full_compare((char *)fname, slang->sl_fname, false, true) == kEqualFiles) {
slang_clear(slang);
- if (spell_load_file(fname, NULL, slang, false) == NULL) {
+ if (spell_load_file((char *)fname, NULL, slang, false) == NULL) {
// reloading failed, clear the language
slang_clear(slang);
}
@@ -2005,17 +2005,17 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
char_u *line;
char_u *pc = NULL;
#define MAXITEMCNT 30
- char_u *(items[MAXITEMCNT]);
+ char *(items[MAXITEMCNT]);
int itemcnt;
- char_u *p;
+ char *p;
int lnum = 0;
affheader_T *cur_aff = NULL;
bool did_postpone_prefix = false;
int aff_todo = 0;
hashtab_T *tp;
- char_u *low = NULL;
- char_u *fol = NULL;
- char_u *upp = NULL;
+ char *low = NULL;
+ char *fol = NULL;
+ char *upp = NULL;
int do_rep;
int do_repsal;
int do_sal;
@@ -2090,8 +2090,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
// Split the line up in white separated items. Put a NUL after each
// item.
itemcnt = 0;
- for (p = line;;) {
- while (*p != NUL && *p <= ' ') { // skip white space and CR/NL
+ for (p = (char *)line;;) {
+ while (*p != NUL && (uint8_t)(*p) <= ' ') { // skip white space and CR/NL
p++;
}
if (*p == NUL) {
@@ -2102,12 +2102,12 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
}
items[itemcnt++] = p;
// A few items have arbitrary text argument, don't split them.
- if (itemcnt == 2 && spell_info_item(items[0])) {
- while (*p >= ' ' || *p == TAB) { // skip until CR/NL
+ if (itemcnt == 2 && spell_info_item((char_u *)items[0])) {
+ while ((uint8_t)(*p) >= ' ' || *p == TAB) { // skip until CR/NL
p++;
}
} else {
- while (*p > ' ') { // skip until white space or CR/NL
+ while ((uint8_t)(*p) > ' ') { // skip until white space or CR/NL
p++;
}
}
@@ -2154,7 +2154,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
smsg(_("FLAG after using flags in %s line %d: %s"),
fname, lnum, items[1]);
}
- } else if (spell_info_item(items[0]) && itemcnt > 1) {
+ } else if (spell_info_item((char_u *)items[0]) && itemcnt > 1) {
p = getroom(spin,
(spin->si_info == NULL ? 0 : STRLEN(spin->si_info))
+ STRLEN(items[0])
@@ -2166,9 +2166,9 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
STRCAT(p, items[0]);
STRCAT(p, " ");
STRCAT(p, items[1]);
- spin->si_info = p;
+ spin->si_info = (char_u *)p;
} else if (is_aff_rule(items, itemcnt, "MIDWORD", 2) && midword == NULL) {
- midword = (char_u *)getroom_save(spin, items[1]);
+ midword = (char_u *)getroom_save(spin, (char_u *)items[1]);
} else if (is_aff_rule(items, itemcnt, "TRY", 2)) {
// ignored, we look in the tree for what chars may appear
}
@@ -2176,44 +2176,44 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
else if ((is_aff_rule(items, itemcnt, "RAR", 2)
|| is_aff_rule(items, itemcnt, "RARE", 2))
&& aff->af_rare == 0) {
- aff->af_rare = affitem2flag(aff->af_flagtype, items[1],
+ aff->af_rare = affitem2flag(aff->af_flagtype, (char_u *)items[1],
fname, lnum);
}
// TODO: remove "KEP" later
else if ((is_aff_rule(items, itemcnt, "KEP", 2)
|| is_aff_rule(items, itemcnt, "KEEPCASE", 2))
&& aff->af_keepcase == 0) {
- aff->af_keepcase = affitem2flag(aff->af_flagtype, items[1],
+ aff->af_keepcase = affitem2flag(aff->af_flagtype, (char_u *)items[1],
fname, lnum);
} else if ((is_aff_rule(items, itemcnt, "BAD", 2)
|| is_aff_rule(items, itemcnt, "FORBIDDENWORD", 2))
&& aff->af_bad == 0) {
- aff->af_bad = affitem2flag(aff->af_flagtype, items[1],
+ aff->af_bad = affitem2flag(aff->af_flagtype, (char_u *)items[1],
fname, lnum);
} else if (is_aff_rule(items, itemcnt, "NEEDAFFIX", 2)
&& aff->af_needaffix == 0) {
- aff->af_needaffix = affitem2flag(aff->af_flagtype, items[1],
+ aff->af_needaffix = affitem2flag(aff->af_flagtype, (char_u *)items[1],
fname, lnum);
} else if (is_aff_rule(items, itemcnt, "CIRCUMFIX", 2)
&& aff->af_circumfix == 0) {
- aff->af_circumfix = affitem2flag(aff->af_flagtype, items[1],
+ aff->af_circumfix = affitem2flag(aff->af_flagtype, (char_u *)items[1],
fname, lnum);
} else if (is_aff_rule(items, itemcnt, "NOSUGGEST", 2)
&& aff->af_nosuggest == 0) {
- aff->af_nosuggest = affitem2flag(aff->af_flagtype, items[1],
+ aff->af_nosuggest = affitem2flag(aff->af_flagtype, (char_u *)items[1],
fname, lnum);
} else if ((is_aff_rule(items, itemcnt, "NEEDCOMPOUND", 2)
|| is_aff_rule(items, itemcnt, "ONLYINCOMPOUND", 2))
&& aff->af_needcomp == 0) {
- aff->af_needcomp = affitem2flag(aff->af_flagtype, items[1],
+ aff->af_needcomp = affitem2flag(aff->af_flagtype, (char_u *)items[1],
fname, lnum);
} else if (is_aff_rule(items, itemcnt, "COMPOUNDROOT", 2)
&& aff->af_comproot == 0) {
- aff->af_comproot = affitem2flag(aff->af_flagtype, items[1],
+ aff->af_comproot = affitem2flag(aff->af_flagtype, (char_u *)items[1],
fname, lnum);
} else if (is_aff_rule(items, itemcnt, "COMPOUNDFORBIDFLAG", 2)
&& aff->af_compforbid == 0) {
- aff->af_compforbid = affitem2flag(aff->af_flagtype, items[1],
+ aff->af_compforbid = affitem2flag(aff->af_flagtype, (char_u *)items[1],
fname, lnum);
if (aff->af_pref.ht_used > 0) {
smsg(_("Defining COMPOUNDFORBIDFLAG after PFX item may give wrong results in %s line %d"),
@@ -2221,7 +2221,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
}
} else if (is_aff_rule(items, itemcnt, "COMPOUNDPERMITFLAG", 2)
&& aff->af_comppermit == 0) {
- aff->af_comppermit = affitem2flag(aff->af_flagtype, items[1],
+ aff->af_comppermit = affitem2flag(aff->af_flagtype, (char_u *)items[1],
fname, lnum);
if (aff->af_pref.ht_used > 0) {
smsg(_("Defining COMPOUNDPERMITFLAG after PFX item may give wrong results in %s line %d"),
@@ -2234,7 +2234,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
p = getroom(spin, STRLEN(items[1]) + 2, false);
STRCPY(p, items[1]);
STRCAT(p, "+");
- compflags = p;
+ compflags = (char_u *)p;
} else if (is_aff_rule(items, itemcnt, "COMPOUNDRULES", 2)) {
// We don't use the count, but do check that it's a number and
// not COMPOUNDRULE mistyped.
@@ -2257,7 +2257,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
STRCAT(p, "/");
}
STRCAT(p, items[1]);
- compflags = p;
+ compflags = (char_u *)p;
}
} else if (is_aff_rule(items, itemcnt, "COMPOUNDWORDMAX", 2)
&& compmax == 0) {
@@ -2306,12 +2306,12 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
}
if (i >= gap->ga_len) {
ga_grow(gap, 2);
- ((char **)(gap->ga_data))[gap->ga_len++] = getroom_save(spin, items[1]);
- ((char **)(gap->ga_data))[gap->ga_len++] = getroom_save(spin, items[2]);
+ ((char **)(gap->ga_data))[gap->ga_len++] = getroom_save(spin, (char_u *)items[1]);
+ ((char **)(gap->ga_data))[gap->ga_len++] = getroom_save(spin, (char_u *)items[2]);
}
} else if (is_aff_rule(items, itemcnt, "SYLLABLE", 2)
&& syllable == NULL) {
- syllable = (char_u *)getroom_save(spin, items[1]);
+ syllable = (char_u *)getroom_save(spin, (char_u *)items[1]);
} else if (is_aff_rule(items, itemcnt, "NOBREAK", 1)) {
spin->si_nobreak = true;
} else if (is_aff_rule(items, itemcnt, "NOSPLITSUGS", 1)) {
@@ -2356,7 +2356,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
} else {
// New affix letter.
cur_aff = getroom(spin, sizeof(*cur_aff), true);
- cur_aff->ah_flag = affitem2flag(aff->af_flagtype, items[1],
+ cur_aff->ah_flag = affitem2flag(aff->af_flagtype, (char_u *)items[1],
fname, lnum);
if (cur_aff->ah_flag == 0 || STRLEN(items[1]) >= AH_KEY_LEN) {
break;
@@ -2444,10 +2444,10 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
aff_entry = getroom(spin, sizeof(*aff_entry), true);
if (STRCMP(items[2], "0") != 0) {
- aff_entry->ae_chop = (char_u *)getroom_save(spin, items[2]);
+ aff_entry->ae_chop = (char_u *)getroom_save(spin, (char_u *)items[2]);
}
if (STRCMP(items[3], "0") != 0) {
- aff_entry->ae_add = (char_u *)getroom_save(spin, items[3]);
+ aff_entry->ae_add = (char_u *)getroom_save(spin, (char_u *)items[3]);
// Recognize flags on the affix: abcd/XYZ
aff_entry->ae_flags = (char_u *)vim_strchr((char *)aff_entry->ae_add, '/');
@@ -2467,7 +2467,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
if (STRCMP(items[4], ".") != 0) {
char_u buf[MAXLINELEN];
- aff_entry->ae_cond = (char_u *)getroom_save(spin, items[4]);
+ aff_entry->ae_cond = (char_u *)getroom_save(spin, (char_u *)items[4]);
if (*items[0] == 'P') {
sprintf((char *)buf, "^%s", items[4]);
} else {
@@ -2502,10 +2502,10 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
if (c_up != c
&& (aff_entry->ae_cond == NULL
|| utf_ptr2char((char *)aff_entry->ae_cond) == c)) {
- p = aff_entry->ae_add
+ p = (char *)aff_entry->ae_add
+ STRLEN(aff_entry->ae_add);
MB_PTR_BACK(aff_entry->ae_add, p);
- if (utf_ptr2char((char *)p) == c_up) {
+ if (utf_ptr2char(p) == c_up) {
upper = true;
aff_entry->ae_chop = NULL;
*p = NUL;
@@ -2515,7 +2515,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
// upper-case letter.
if (aff_entry->ae_cond != NULL) {
char_u buf[MAXLINELEN];
- onecap_copy(items[4], buf, true);
+ onecap_copy((char_u *)items[4], buf, true);
aff_entry->ae_cond = (char_u *)getroom_save(spin, buf);
if (aff_entry->ae_cond != NULL) {
sprintf((char *)buf, "^%s",
@@ -2534,10 +2534,9 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
int n;
// Find a previously used condition.
- for (idx = spin->si_prefcond.ga_len - 1; idx >= 0;
- --idx) {
- p = ((char_u **)spin->si_prefcond.ga_data)[idx];
- if (str_equal(p, aff_entry->ae_cond)) {
+ for (idx = spin->si_prefcond.ga_len - 1; idx >= 0; idx--) {
+ p = ((char **)spin->si_prefcond.ga_data)[idx];
+ if (str_equal((char_u *)p, aff_entry->ae_cond)) {
break;
}
}
@@ -2551,9 +2550,9 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
// Add the prefix to the prefix tree.
if (aff_entry->ae_add == NULL) {
- p = (char_u *)"";
+ p = "";
} else {
- p = aff_entry->ae_add;
+ p = (char *)aff_entry->ae_add;
}
// PFX_FLAGS is a negative number, so that
@@ -2571,7 +2570,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
if (aff_entry->ae_compforbid) {
n |= WFP_COMPFORBID;
}
- tree_add_word(spin, p, spin->si_prefroot, n,
+ tree_add_word(spin, (char_u *)p, spin->si_prefroot, n,
idx, cur_aff->ah_newID);
did_postpone_prefix = true;
}
@@ -2584,11 +2583,11 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
}
}
} else if (is_aff_rule(items, itemcnt, "FOL", 2) && fol == NULL) {
- fol = vim_strsave(items[1]);
+ fol = xstrdup(items[1]);
} else if (is_aff_rule(items, itemcnt, "LOW", 2) && low == NULL) {
- low = vim_strsave(items[1]);
+ low = xstrdup(items[1]);
} else if (is_aff_rule(items, itemcnt, "UPP", 2) && upp == NULL) {
- upp = vim_strsave(items[1]);
+ upp = xstrdup(items[1]);
} else if (is_aff_rule(items, itemcnt, "REP", 2)
|| is_aff_rule(items, itemcnt, "REPSAL", 2)) {
// Ignore REP/REPSAL count
@@ -2619,8 +2618,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
}
}
add_fromto(spin, items[0][3] == 'S'
- ? &spin->si_repsal
- : &spin->si_rep, items[1], items[2]);
+ ? &spin->si_repsal
+ : &spin->si_rep, (char_u *)items[1], (char_u *)items[2]);
}
} else if (is_aff_rule(items, itemcnt, "MAP", 2)) {
// MAP item or count
@@ -2640,7 +2639,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
if ((!GA_EMPTY(&spin->si_map)
&& vim_strchr(spin->si_map.ga_data, c)
!= NULL)
- || vim_strchr((char *)p, c) != NULL) {
+ || vim_strchr(p, c) != NULL) {
smsg(_("Duplicate character in MAP in %s line %d"),
fname, lnum);
}
@@ -2658,31 +2657,31 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
// SAL item (sounds-a-like)
// Either one of the known keys or a from-to pair.
if (STRCMP(items[1], "followup") == 0) {
- spin->si_followup = sal_to_bool(items[2]);
+ spin->si_followup = sal_to_bool((char_u *)items[2]);
} else if (STRCMP(items[1], "collapse_result") == 0) {
- spin->si_collapse = sal_to_bool(items[2]);
+ spin->si_collapse = sal_to_bool((char_u *)items[2]);
} else if (STRCMP(items[1], "remove_accents") == 0) {
- spin->si_rem_accents = sal_to_bool(items[2]);
+ spin->si_rem_accents = sal_to_bool((char_u *)items[2]);
} else {
// when "to" is "_" it means empty
- add_fromto(spin, &spin->si_sal, items[1],
+ add_fromto(spin, &spin->si_sal, (char_u *)items[1],
STRCMP(items[2], "_") == 0 ? (char_u *)""
- : items[2]);
+ : (char_u *)items[2]);
}
}
} else if (is_aff_rule(items, itemcnt, "SOFOFROM", 2)
&& sofofrom == NULL) {
- sofofrom = (char_u *)getroom_save(spin, items[1]);
+ sofofrom = (char_u *)getroom_save(spin, (char_u *)items[1]);
} else if (is_aff_rule(items, itemcnt, "SOFOTO", 2)
&& sofoto == NULL) {
- sofoto = (char_u *)getroom_save(spin, items[1]);
+ sofoto = (char_u *)getroom_save(spin, (char_u *)items[1]);
} else if (STRCMP(items[0], "COMMON") == 0) {
int i;
for (i = 1; i < itemcnt; i++) {
if (HASHITEM_EMPTY(hash_find(&spin->si_commonwords, (char *)items[i]))) {
- p = vim_strsave(items[i]);
- hash_add(&spin->si_commonwords, p);
+ p = xstrdup(items[i]);
+ hash_add(&spin->si_commonwords, (char_u *)p);
}
}
} else {
@@ -2773,9 +2772,9 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
return aff;
}
-// Returns true when items[0] equals "rulename", there are "mincount" items or
-// a comment is following after item "mincount".
-static bool is_aff_rule(char_u **items, int itemcnt, char *rulename, int mincount)
+/// @return true when items[0] equals "rulename", there are "mincount" items or
+/// a comment is following after item "mincount".
+static bool is_aff_rule(char **items, int itemcnt, char *rulename, int mincount)
{
return STRCMP(items[0], rulename) == 0
&& (itemcnt == mincount
@@ -4914,7 +4913,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char *wfname)
}
if (slang == NULL) {
spell_message(spin, _("Reading back spell file..."));
- slang = spell_load_file((char_u *)wfname, NULL, NULL, false);
+ slang = spell_load_file(wfname, NULL, NULL, false);
if (slang == NULL) {
return;
}
@@ -5233,7 +5232,7 @@ static void sug_write(spellinfo_T *spin, char_u *fname)
for (linenr_T lnum = 1; lnum <= wcount; lnum++) {
// <sugline>: <sugnr> ... NUL
- char_u *line = ml_get_buf(spin->si_spellbuf, lnum, false);
+ char_u *line = (char_u *)ml_get_buf(spin->si_spellbuf, lnum, false);
size_t len = STRLEN(line) + 1;
if (fwrite(line, len, 1, fd) == 0) {
emsg(_(e_write));
@@ -5531,7 +5530,7 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo
if (idx == 0) { // use internal wordlist
if (int_wordlist == NULL) {
- int_wordlist = vim_tempname();
+ int_wordlist = (char_u *)vim_tempname();
if (int_wordlist == NULL) {
return;
}
diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c
index c07e460ea8..c38fa2b24f 100644
--- a/src/nvim/spellsuggest.c
+++ b/src/nvim/spellsuggest.c
@@ -407,7 +407,7 @@ int spell_check_sps(void)
/// When "count" is non-zero use that suggestion.
void spell_suggest(int count)
{
- char_u *line;
+ char *line;
pos_T prev_cursor = curwin->w_cursor;
char_u wcopy[MAXWLEN + 2];
char_u *p;
@@ -453,10 +453,10 @@ void spell_suggest(int count)
// No bad word or it starts after the cursor: use the word under the
// cursor.
curwin->w_cursor = prev_cursor;
- line = (char_u *)get_cursor_line_ptr();
- p = line + curwin->w_cursor.col;
+ line = get_cursor_line_ptr();
+ p = (char_u *)line + curwin->w_cursor.col;
// Backup to before start of word.
- while (p > line && spell_iswordp_nmw(p, curwin)) {
+ while (p > (char_u *)line && spell_iswordp_nmw(p, curwin)) {
MB_PTR_BACK(line, p);
}
// Forward to start of word.
@@ -468,7 +468,7 @@ void spell_suggest(int count)
beep_flush();
return;
}
- curwin->w_cursor.col = (colnr_T)(p - line);
+ curwin->w_cursor.col = (colnr_T)(p - (char_u *)line);
}
// Get the word and its length.
@@ -477,7 +477,7 @@ void spell_suggest(int count)
need_cap = check_need_cap(curwin->w_cursor.lnum, curwin->w_cursor.col);
// Make a copy of current line since autocommands may free the line.
- line = vim_strsave((char_u *)get_cursor_line_ptr());
+ line = xstrdup(get_cursor_line_ptr());
spell_suggest_timeout = 5000;
// Get the list of suggestions. Limit to 'lines' - 2 or the number in
@@ -487,7 +487,7 @@ void spell_suggest(int count)
} else {
limit = sps_limit;
}
- spell_find_suggest(line + curwin->w_cursor.col, badlen, &sug, limit,
+ spell_find_suggest((char_u *)line + curwin->w_cursor.col, badlen, &sug, limit,
true, need_cap, true);
if (GA_EMPTY(&sug.su_ga)) {
@@ -593,20 +593,20 @@ void spell_suggest(int count)
if (sug.su_badlen > stp->st_orglen) {
// Replacing less than "su_badlen", append the remainder to
// repl_to.
- repl_from = (char_u *)xstrnsave((char *)sug.su_badptr, (size_t)sug.su_badlen);
+ repl_from = xstrnsave((char *)sug.su_badptr, (size_t)sug.su_badlen);
vim_snprintf((char *)IObuff, IOSIZE, "%s%.*s", stp->st_word,
sug.su_badlen - stp->st_orglen,
sug.su_badptr + stp->st_orglen);
- repl_to = vim_strsave(IObuff);
+ repl_to = xstrdup((char *)IObuff);
} else {
// Replacing su_badlen or more, use the whole word.
- repl_from = (char_u *)xstrnsave((char *)sug.su_badptr, (size_t)stp->st_orglen);
- repl_to = vim_strsave((char_u *)stp->st_word);
+ repl_from = xstrnsave((char *)sug.su_badptr, (size_t)stp->st_orglen);
+ repl_to = xstrdup(stp->st_word);
}
// Replace the word.
p = xmalloc(STRLEN(line) - (size_t)stp->st_orglen + (size_t)stp->st_wordlen + 1);
- c = (int)(sug.su_badptr - line);
+ c = (int)(sug.su_badptr - (char_u *)line);
memmove(p, line, (size_t)c);
STRCPY(p + c, stp->st_word);
STRCAT(p, sug.su_badptr + stp->st_orglen);
@@ -678,7 +678,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma
char_u buf[MAXPATHL];
char *p;
bool do_combine = false;
- char_u *sps_copy;
+ char *sps_copy;
static bool expr_busy = false;
int c;
langp_T *lp;
@@ -758,10 +758,10 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma
}
// Make a copy of 'spellsuggest', because the expression may change it.
- sps_copy = vim_strsave((char_u *)p_sps);
+ sps_copy = xstrdup(p_sps);
// Loop over the items in 'spellsuggest'.
- for (p = (char *)sps_copy; *p != NUL;) {
+ for (p = sps_copy; *p != NUL;) {
copy_option_part(&p, (char *)buf, MAXPATHL, ",");
if (STRNCMP(buf, "expr:", 5) == 0) {
@@ -2806,7 +2806,7 @@ static void add_sound_suggest(suginfo_T *su, char_u *goodword, int score, langp_
}
// Go over the list of good words that produce this soundfold word
- nrline = ml_get_buf(slang->sl_sugbuf, (linenr_T)sfwordnr + 1, false);
+ nrline = (char_u *)ml_get_buf(slang->sl_sugbuf, (linenr_T)sfwordnr + 1, false);
orgnr = 0;
while (*nrline != NUL) {
// The wordnr was stored in a minimal nr of bytes as an offset to the
diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c
index 9b441ba0a9..5f686ef96f 100644
--- a/src/nvim/statusline.c
+++ b/src/nvim/statusline.c
@@ -426,7 +426,7 @@ void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler)
int len;
int fillchar;
char buf[MAXPATHL];
- char_u *stl;
+ char *stl;
char *p;
stl_hlrec_t *hltab;
StlClickRecord *tabtab;
@@ -448,14 +448,14 @@ void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler)
// setup environment for the task at hand
if (wp == NULL) {
// Use 'tabline'. Always at the first line of the screen.
- stl = (char_u *)p_tal;
+ stl = p_tal;
row = 0;
fillchar = ' ';
attr = HL_ATTR(HLF_TPF);
maxwidth = Columns;
use_sandbox = was_set_insecurely(wp, "tabline", 0);
} else if (draw_winbar) {
- stl = (char_u *)((*wp->w_p_wbr != NUL) ? wp->w_p_wbr : p_wbr);
+ stl = ((*wp->w_p_wbr != NUL) ? wp->w_p_wbr : p_wbr);
row = -1; // row zero is first row of text
col = 0;
grid = &wp->w_grid;
@@ -491,19 +491,19 @@ void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler)
}
if (draw_ruler) {
- stl = (char_u *)p_ruf;
+ stl = p_ruf;
// advance past any leading group spec - implicit in ru_col
if (*stl == '%') {
if (*++stl == '-') {
stl++;
}
- if (atoi((char *)stl)) {
+ if (atoi(stl)) {
while (ascii_isdigit(*stl)) {
stl++;
}
}
if (*stl++ != '(') {
- stl = (char_u *)p_ruf;
+ stl = p_ruf;
}
}
col = ru_col - (Columns - maxwidth);
@@ -522,9 +522,9 @@ void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler)
use_sandbox = was_set_insecurely(wp, "rulerformat", 0);
} else {
if (*wp->w_p_stl != NUL) {
- stl = (char_u *)wp->w_p_stl;
+ stl = wp->w_p_stl;
} else {
- stl = (char_u *)p_stl;
+ stl = p_stl;
}
use_sandbox = was_set_insecurely(wp, "statusline", *wp->w_p_stl == NUL ? 0 : OPT_LOCAL);
}
@@ -544,9 +544,9 @@ void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler)
// Make a copy, because the statusline may include a function call that
// might change the option value and free the memory.
- stl = vim_strsave(stl);
+ stl = xstrdup(stl);
width =
- build_stl_str_hl(ewp, buf, sizeof(buf), (char *)stl, use_sandbox,
+ build_stl_str_hl(ewp, buf, sizeof(buf), stl, use_sandbox,
fillchar, maxwidth, &hltab, &tabtab);
xfree(stl);
ewp->w_p_crb = p_crb_save;
@@ -711,7 +711,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, int use_san
}
// Get line & check if empty (cursorpos will show "0-1").
- const char *line_ptr = (char *)ml_get_buf(wp->w_buffer, lnum, false);
+ const char *line_ptr = ml_get_buf(wp->w_buffer, lnum, false);
bool empty_line = (*line_ptr == NUL);
// Get the byte value now, in case we need it below. This is more
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index d7a0472cbf..04f9311d7e 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -49,13 +49,6 @@
#include "nvim/vim.h"
#include "nvim/window.h"
-/// Copy "string" into newly allocated memory.
-char_u *vim_strsave(const char_u *string)
- FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
-{
- return (char_u *)xstrdup((char *)string);
-}
-
/// Copy up to `len` bytes of `string` into newly allocated memory and
/// terminate with a NUL. The allocated memory always has size `len + 1`, even
/// when `string` is shorter.
@@ -292,11 +285,11 @@ char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_n
char_u *vim_strsave_up(const char_u *string)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{
- char_u *p1;
+ char *p1;
- p1 = vim_strsave(string);
- vim_strup(p1);
- return p1;
+ p1 = xstrdup((char *)string);
+ vim_strup((char_u *)p1);
+ return (char_u *)p1;
}
/// Like xstrnsave(), but make all characters uppercase.
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index fedd053e88..1daeebd7b9 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -2468,7 +2468,7 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_
break;
}
- line = ml_get_buf(syn_buf, startpos->lnum, false);
+ line = (char_u *)ml_get_buf(syn_buf, startpos->lnum, false);
int line_len = (int)STRLEN(line);
// take care of an empty match or negative offset
@@ -2604,7 +2604,7 @@ static void syn_add_end_off(lpos_T *result, regmmatch_T *regmatch, synpat_T *spp
if (result->lnum > syn_buf->b_ml.ml_line_count) {
col = 0;
} else if (off != 0) {
- base = ml_get_buf(syn_buf, result->lnum, false);
+ base = (char_u *)ml_get_buf(syn_buf, result->lnum, false);
p = base + col;
if (off > 0) {
while (off-- > 0 && *p != NUL) {
@@ -2649,7 +2649,7 @@ static void syn_add_start_off(lpos_T *result, regmmatch_T *regmatch, synpat_T *s
col = (int)STRLEN(ml_get_buf(syn_buf, result->lnum, false));
}
if (off != 0) {
- base = ml_get_buf(syn_buf, result->lnum, false);
+ base = (char_u *)ml_get_buf(syn_buf, result->lnum, false);
p = base + col;
if (off > 0) {
while (off-- && *p != NUL) {
@@ -2668,7 +2668,7 @@ static void syn_add_start_off(lpos_T *result, regmmatch_T *regmatch, synpat_T *s
/// Get current line in syntax buffer.
static char *syn_getcurline(void)
{
- return (char *)ml_get_buf(syn_buf, current_lnum, false);
+ return ml_get_buf(syn_buf, current_lnum, false);
}
// Call vim_regexec() to find a match with "rmp" in "syn_buf".
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index 04154384af..8be752239c 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -96,7 +96,7 @@ static char *mt_names[MT_COUNT/2] =
{ "FSC", "F C", "F ", "FS ", " SC", " C", " ", " S " };
#define NOTAGFILE 99 // return value for jumpto_tag
-static char_u *nofile_fname = NULL; // fname for NOTAGFILE error
+static char *nofile_fname = NULL; // fname for NOTAGFILE error
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "tag.c.generated.h"
@@ -109,7 +109,7 @@ static char_u *recurmsg
static char_u *tfu_inv_ret_msg
= (char_u *)N_("E987: invalid return value from tagfunc");
-static char_u *tagmatchname = NULL; // name of last used tag
+static char *tagmatchname = NULL; // name of last used tag
// Tag for preview window is remembered separately, to avoid messing up the
// normal tagstack.
@@ -142,7 +142,7 @@ static int tfu_in_use = false; // disallow recursive call of tagfunc
/// @param tag tag (pattern) to jump to
/// @param forceit :ta with !
/// @param verbose print "tag not found" message
-bool do_tag(char_u *tag, int type, int count, int forceit, int verbose)
+bool do_tag(char *tag, int type, int count, int forceit, int verbose)
{
taggy_T *tagstack = curwin->w_tagstack;
int tagstackidx = curwin->w_tagstackidx;
@@ -195,7 +195,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose)
}
prev_num_matches = num_matches;
- free_string_option((char *)nofile_fname);
+ free_string_option(nofile_fname);
nofile_fname = NULL;
clearpos(&saved_fmark.mark); // shutup gcc 4.0
@@ -208,7 +208,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose)
new_tag = true;
if (g_do_tagpreview != 0) {
tagstack_clear_entry(&ptag_entry);
- ptag_entry.tagname = (char *)vim_strsave(tag);
+ ptag_entry.tagname = xstrdup(tag);
}
} else {
if (g_do_tagpreview != 0) {
@@ -232,7 +232,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose)
cur_fnum = ptag_entry.cur_fnum;
} else {
tagstack_clear_entry(&ptag_entry);
- ptag_entry.tagname = (char *)vim_strsave(tag);
+ ptag_entry.tagname = xstrdup(tag);
}
} else {
// If the last used entry is not at the top, delete all tag
@@ -252,7 +252,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose)
}
// put the tag name in the tag stack
- tagstack[tagstackidx].tagname = (char *)vim_strsave(tag);
+ tagstack[tagstackidx].tagname = xstrdup(tag);
curwin->w_tagstacklen = tagstacklen;
@@ -419,13 +419,13 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose)
// Repeat searching for tags, when a file has not been found.
for (;;) {
int other_name;
- char_u *name;
+ char *name;
// When desired match not found yet, try to find it (and others).
if (use_tagstack) {
- name = (char_u *)tagstack[tagstackidx].tagname;
+ name = tagstack[tagstackidx].tagname;
} else if (g_do_tagpreview != 0) {
- name = (char_u *)ptag_entry.tagname;
+ name = ptag_entry.tagname;
} else {
name = tag;
}
@@ -435,7 +435,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose)
|| other_name) {
if (other_name) {
xfree(tagmatchname);
- tagmatchname = vim_strsave(name);
+ tagmatchname = xstrdup(name);
}
if (type == DT_SELECT || type == DT_JUMP
@@ -466,7 +466,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose)
flags |= TAG_NO_TAGFUNC;
}
- if (find_tags((char *)name, &new_num_matches, &new_matches, flags,
+ if (find_tags(name, &new_num_matches, &new_matches, flags,
max_num_matches, (char *)buf_ffname) == OK
&& new_num_matches < max_num_matches) {
max_num_matches = MAXCOL; // If less than max_num_matches
@@ -522,7 +522,7 @@ bool do_tag(char_u *tag, int type, int count, int forceit, int verbose)
print_tag_list(new_tag, use_tagstack, num_matches, matches);
ask_for_selection = true;
} else if (type == DT_LTAG) {
- if (add_llist_tags(tag, num_matches, matches) == FAIL) {
+ if (add_llist_tags((char_u *)tag, num_matches, matches) == FAIL) {
goto end_do_tag;
}
@@ -1172,7 +1172,7 @@ static int find_tagfunc_tags(char_u *pat, garray_T *ga, int *match_count, int fl
taglist = rettv.vval.v_list;
TV_LIST_ITER_CONST(taglist, li, {
- char_u *res_name;
+ char *res_name;
char_u *res_fname;
char_u *res_cmd;
char_u *res_kind;
@@ -1200,7 +1200,7 @@ static int find_tagfunc_tags(char_u *pat, garray_T *ga, int *match_count, int fl
len += strlen(tv->vval.v_string) + 1; // Space for "\tVALUE"
if (!STRCMP(dict_key, "name")) {
- res_name = (char_u *)tv->vval.v_string;
+ res_name = tv->vval.v_string;
continue;
}
if (!STRCMP(dict_key, "filename")) {
@@ -1230,10 +1230,10 @@ static int find_tagfunc_tags(char_u *pat, garray_T *ga, int *match_count, int fl
break;
}
- char_u *const mfp = name_only ? vim_strsave(res_name) : xmalloc(len + 2);
+ char *const mfp = name_only ? xstrdup(res_name) : xmalloc(len + 2);
if (!name_only) {
- char_u *p = mfp;
+ char_u *p = (char_u *)mfp;
*p++ = MT_GL_OTH + 1; // mtt
*p++ = TAG_SEP; // no tag file name
@@ -2242,13 +2242,13 @@ static garray_T tag_fnames = GA_EMPTY_INIT_VALUE;
// 'runtimepath' doc directories.
static void found_tagfile_cb(char *fname, void *cookie)
{
- char_u *const tag_fname = vim_strsave((char_u *)fname);
+ char *const tag_fname = xstrdup(fname);
#ifdef BACKSLASH_IN_FILENAME
slash_adjust(tag_fname);
#endif
- simplify_filename(tag_fname);
- GA_APPEND(char_u *, &tag_fnames, tag_fname);
+ simplify_filename((char_u *)tag_fname);
+ GA_APPEND(char *, &tag_fnames, tag_fname);
}
#if defined(EXITFREE)
@@ -2319,8 +2319,8 @@ int get_tagfname(tagname_T *tnp, int first, char *buf)
if (first) {
// Init. We make a copy of 'tags', because autocommands may change
// the value without notifying us.
- tnp->tn_tags = vim_strsave((*curbuf->b_p_tags != NUL) ? (char_u *)curbuf->b_p_tags : p_tags);
- tnp->tn_np = (char *)tnp->tn_tags;
+ tnp->tn_tags = xstrdup((*curbuf->b_p_tags != NUL) ? curbuf->b_p_tags : (char *)p_tags);
+ tnp->tn_np = tnp->tn_tags;
}
// Loop until we have found a file name that can be used.
@@ -2550,7 +2550,8 @@ static char_u *tag_full_fname(tagptrs_T *tagp)
{
int c = *tagp->fname_end;
*tagp->fname_end = NUL;
- char_u *fullname = expand_tag_fname(tagp->fname, tagp->tag_fname, false);
+ char_u *fullname =
+ (char_u *)expand_tag_fname((char *)tagp->fname, (char *)tagp->tag_fname, false);
*tagp->fname_end = (char_u)c;
return fullname;
@@ -2573,7 +2574,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help)
char_u *pbuf; // search pattern buffer
char_u *pbuf_end;
char_u *tofree_fname = NULL;
- char_u *fname;
+ char *fname;
tagptrs_T tagp;
int retval = FAIL;
int getfile_result = GETFILE_UNUSED;
@@ -2596,7 +2597,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help)
// truncate the file name, so it can be used as a string
*tagp.fname_end = NUL;
- fname = tagp.fname;
+ fname = (char *)tagp.fname;
// copy the command to pbuf[], remove trailing CR/NL
str = tagp.command;
@@ -2619,18 +2620,17 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help)
// Expand file name, when needed (for environment variables).
// If 'tagrelative' option set, may change file name.
- fname = expand_tag_fname(fname, tagp.tag_fname, true);
- tofree_fname = fname; // free() it later
+ fname = expand_tag_fname(fname, (char *)tagp.tag_fname, true);
+ tofree_fname = (char_u *)fname; // free() it later
// Check if the file with the tag exists before abandoning the current
// file. Also accept a file name for which there is a matching BufReadCmd
// autocommand event (e.g., http://sys/file).
- if (!os_path_exists((char *)fname)
- && !has_autocmd(EVENT_BUFREADCMD, (char *)fname,
- NULL)) {
+ if (!os_path_exists(fname)
+ && !has_autocmd(EVENT_BUFREADCMD, fname, NULL)) {
retval = NOTAGFILE;
xfree(nofile_fname);
- nofile_fname = vim_strsave(fname);
+ nofile_fname = xstrdup(fname);
goto erret;
}
@@ -2644,8 +2644,8 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help)
// entering it (autocommands) so turn the tag filename
// into a fullpath
if (!curwin->w_p_pvw) {
- full_fname = (char_u *)FullName_save((char *)fname, false);
- fname = full_fname;
+ full_fname = (char_u *)FullName_save(fname, false);
+ fname = (char *)full_fname;
// Make the preview window the current window.
// Open a preview window when needed.
@@ -2656,7 +2656,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help)
// If it was a CTRL-W CTRL-] command split window now. For ":tab tag"
// open a new tab page.
if (postponed_split && (swb_flags & (SWB_USEOPEN | SWB_USETAB))) {
- buf_T *const existing_buf = buflist_findname_exp((char *)fname);
+ buf_T *const existing_buf = buflist_findname_exp(fname);
if (existing_buf != NULL) {
const win_T *wp = NULL;
@@ -2701,7 +2701,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help)
if (getfile_result == GETFILE_UNUSED) {
// Careful: getfile() may trigger autocommands and call jumpto_tag()
// recursively.
- getfile_result = getfile(0, (char *)fname, NULL, true, (linenr_T)0, forceit);
+ getfile_result = getfile(0, fname, NULL, true, (linenr_T)0, forceit);
}
keep_help_flag = false;
@@ -2867,18 +2867,19 @@ erret:
return retval;
}
-// If "expand" is true, expand wildcards in fname.
-// If 'tagrelative' option set, change fname (name of file containing tag)
-// according to tag_fname (name of tag file containing fname).
-// Returns a pointer to allocated memory.
-static char_u *expand_tag_fname(char_u *fname, char_u *const tag_fname, const bool expand)
+/// If "expand" is true, expand wildcards in fname.
+/// If 'tagrelative' option set, change fname (name of file containing tag)
+/// according to tag_fname (name of tag file containing fname).
+///
+/// @return a pointer to allocated memory.
+static char *expand_tag_fname(char *fname, char *const tag_fname, const bool expand)
{
- char_u *p;
- char_u *expanded_fname = NULL;
+ char *p;
+ char *expanded_fname = NULL;
expand_T xpc;
// Expand file name (for environment variables) when needed.
- if (expand && path_has_wildcard((char *)fname)) {
+ if (expand && path_has_wildcard(fname)) {
ExpandInit(&xpc);
xpc.xp_context = EXPAND_FILES;
expanded_fname = ExpandOne(&xpc, fname, NULL,
@@ -2888,18 +2889,18 @@ static char_u *expand_tag_fname(char_u *fname, char_u *const tag_fname, const bo
}
}
- char_u *retval;
+ char *retval;
if ((p_tr || curbuf->b_help)
- && !vim_isAbsName(fname)
- && (p = (char_u *)path_tail((char *)tag_fname)) != tag_fname) {
+ && !vim_isAbsName((char_u *)fname)
+ && (p = path_tail(tag_fname)) != tag_fname) {
retval = xmalloc(MAXPATHL);
STRCPY(retval, tag_fname);
STRLCPY(retval + (p - tag_fname), fname,
MAXPATHL - (p - tag_fname));
// Translate names like "src/a/../b/file.c" into "src/b/file.c".
- simplify_filename(retval);
+ simplify_filename((char_u *)retval);
} else {
- retval = vim_strsave(fname);
+ retval = xstrdup(fname);
}
xfree(expanded_fname);
@@ -2922,7 +2923,7 @@ static int test_for_current(char *fname, char *fname_end, char *tag_fname, char
c = (unsigned char)(*fname_end);
*fname_end = NUL;
}
- char *fullname = (char *)expand_tag_fname((char_u *)fname, (char_u *)tag_fname, true);
+ char *fullname = expand_tag_fname(fname, tag_fname, true);
retval = (path_full_compare(fullname, buf_ffname, true, true) & kEqualFiles);
xfree(fullname);
*fname_end = (char)c;
diff --git a/src/nvim/tag.h b/src/nvim/tag.h
index 0b4039afb6..7f2ef8d6d7 100644
--- a/src/nvim/tag.h
+++ b/src/nvim/tag.h
@@ -34,7 +34,7 @@
// Structure used for get_tagfname().
typedef struct {
- char_u *tn_tags; // value of 'tags' when starting
+ char *tn_tags; // value of 'tags' when starting
char *tn_np; // current position in tn_tags
int tn_did_filefind_init;
int tn_hf_idx;
diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c
index 6e69fb95c8..5c53f84700 100644
--- a/src/nvim/textformat.c
+++ b/src/nvim/textformat.c
@@ -97,7 +97,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on
colnr_T len;
colnr_T virtcol;
int orig_col = 0;
- char_u *saved_text = NULL;
+ char *saved_text = NULL;
colnr_T col;
colnr_T end_col;
bool did_do_comment = false;
@@ -353,7 +353,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on
if (State & VREPLACE_FLAG) {
// In MODE_VREPLACE state, we will backspace over the text to be
// wrapped, so save a copy now to put on the next line.
- saved_text = vim_strsave(get_cursor_pos_ptr());
+ saved_text = xstrdup(get_cursor_pos_ptr());
curwin->w_cursor.col = orig_col;
saved_text[startcol] = NUL;
@@ -425,7 +425,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on
if (State & VREPLACE_FLAG) {
// In MODE_VREPLACE state we have backspaced over the text to be
// moved, now we re-insert it into the new line.
- ins_bytes((char *)saved_text);
+ ins_bytes(saved_text);
xfree(saved_text);
} else {
// Check if cursor is not past the NUL off the line, cindent
@@ -508,13 +508,13 @@ static bool ends_in_white(linenr_T lnum)
/// @param lnum The first line. White-space is ignored.
///
/// @note the whole of 'leader1' must match 'leader2_len' characters from 'leader2'.
-static bool same_leader(linenr_T lnum, int leader1_len, char_u *leader1_flags, int leader2_len,
- char_u *leader2_flags)
+static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int leader2_len,
+ char *leader2_flags)
{
int idx1 = 0, idx2 = 0;
- char_u *p;
- char_u *line1;
- char_u *line2;
+ char *p;
+ char *line1;
+ char *line2;
if (leader1_len == 0) {
return leader2_len == 0;
@@ -552,9 +552,9 @@ static bool same_leader(linenr_T lnum, int leader1_len, char_u *leader1_flags, i
// Get current line and next line, compare the leaders.
// The first line has to be saved, only one line can be locked at a time.
- line1 = vim_strsave((char_u *)ml_get(lnum));
+ line1 = xstrdup(ml_get(lnum));
for (idx1 = 0; ascii_iswhite(line1[idx1]); idx1++) {}
- line2 = (char_u *)ml_get(lnum + 1);
+ line2 = ml_get(lnum + 1);
for (idx2 = 0; idx2 < leader2_len; idx2++) {
if (!ascii_iswhite(line2[idx2])) {
if (line1[idx1++] != line2[idx2]) {
@@ -605,8 +605,8 @@ static bool paragraph_start(linenr_T lnum)
if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) {
return true; // numbered item starts in "lnum".
}
- if (!same_leader(lnum - 1, leader_len, leader_flags,
- next_leader_len, next_leader_flags)) {
+ if (!same_leader(lnum - 1, leader_len, (char *)leader_flags,
+ next_leader_len, (char *)next_leader_flags)) {
return true; // change of comment leader.
}
return false;
@@ -1018,9 +1018,9 @@ void format_lines(linenr_T line_count, bool avoid_fex)
// When the comment leader changes, it's the end of the paragraph.
if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count
|| !same_leader(curwin->w_cursor.lnum,
- leader_len, leader_flags,
+ leader_len, (char *)leader_flags,
next_leader_len,
- next_leader_flags)) {
+ (char *)next_leader_flags)) {
// Special case: If the next line starts with a line comment
// and this line has a line comment after some text, the
// paragraph doesn't really end.
diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c
index 6863b40599..621efa44cf 100644
--- a/src/nvim/textobject.c
+++ b/src/nvim/textobject.c
@@ -1157,7 +1157,7 @@ again:
// Search for matching "</aaa>". First isolate the "aaa".
inc_cursor();
- p = get_cursor_pos_ptr();
+ p = (char_u *)get_cursor_pos_ptr();
for (cp = p;
*cp != NUL && *cp != '>' && !ascii_iswhite(*cp);
MB_PTR_ADV(cp)) {}
@@ -1196,7 +1196,7 @@ again:
}
}
} else {
- char_u *c = get_cursor_pos_ptr();
+ char_u *c = (char_u *)get_cursor_pos_ptr();
// Exclude the '<' of the end tag.
// If the closing tag is on new line, do not decrement cursor, but make
// operation exclusive, so that the linefeed will be selected
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index 5f086df4e9..ab14f4d4ea 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -567,7 +567,7 @@ int u_savecommon(buf_T *buf, linenr_T top, linenr_T bot, linenr_T newbot, int re
u_freeentry(uep, i);
return FAIL;
}
- uep->ue_array[i] = u_save_line_buf(buf, lnum++);
+ uep->ue_array[i] = (char_u *)u_save_line_buf(buf, lnum++);
}
} else {
uep->ue_array = NULL;
@@ -621,7 +621,7 @@ void u_compute_hash(buf_T *buf, char_u *hash)
context_sha256_T ctx;
sha256_start(&ctx);
for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) {
- char_u *p = ml_get_buf(buf, lnum, false);
+ char_u *p = (char_u *)ml_get_buf(buf, lnum, false);
sha256_update(&ctx, p, (uint32_t)(STRLEN(p) + 1));
}
sha256_finish(&ctx, hash);
@@ -2643,7 +2643,7 @@ void ex_undolist(exarg_T *eap)
}
vim_snprintf_add((char *)IObuff, IOSIZE, " %3ld", uhp->uh_save_nr);
}
- GA_APPEND(char_u *, &ga, vim_strsave(IObuff));
+ GA_APPEND(char *, &ga, xstrdup((char *)IObuff));
}
uhp->uh_walk = mark;
@@ -3027,16 +3027,16 @@ void u_blockfree(buf_T *buf)
/// @param lnum the line to copy
static char_u *u_save_line(linenr_T lnum)
{
- return u_save_line_buf(curbuf, lnum);
+ return (char_u *)u_save_line_buf(curbuf, lnum);
}
/// Allocate memory and copy line into it
///
/// @param lnum line to copy
/// @param buf buffer to copy from
-static char_u *u_save_line_buf(buf_T *buf, linenr_T lnum)
+static char *u_save_line_buf(buf_T *buf, linenr_T lnum)
{
- return vim_strsave(ml_get_buf(buf, lnum, false));
+ return xstrdup(ml_get_buf(buf, lnum, false));
}
/// Check if the 'modified' flag is set, or 'ff' has changed (only need to
diff --git a/test/unit/message_spec.lua b/test/unit/message_spec.lua
index 7e92b5c857..549eff6e03 100644
--- a/test/unit/message_spec.lua
+++ b/test/unit/message_spec.lua
@@ -22,7 +22,7 @@ describe('trunc_string', function()
local function test_copy(s, expected, room)
room = room and room or 20
local buf = cimp.xmalloc(ffi.sizeof('char_u') * buflen)
- local str = cimp.vim_strsave(to_cstr(s))
+ local str = cimp.xstrdup(to_cstr(s))
cimp.trunc_string(str, buf, room, buflen)
eq(expected, ffi.string(buf))
cimp.xfree(buf)