diff options
| author | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2022-06-28 11:31:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-28 02:31:54 -0700 |
| commit | 014a88799a1d175ad121c520c9cc5bd0bb2d8813 (patch) | |
| tree | db5d1acdc8ea6fe58f78b1aabc62b3ee5fc7875a /src | |
| parent | 7e1cf6b7642f0ab14656d853d44f4409b2987b9c (diff) | |
| download | rneovim-014a88799a1d175ad121c520c9cc5bd0bb2d8813.tar.gz rneovim-014a88799a1d175ad121c520c9cc5bd0bb2d8813.tar.bz2 rneovim-014a88799a1d175ad121c520c9cc5bd0bb2d8813.zip | |
refactor: replace char_u #18429
Work on https://github.com/neovim/neovim/issues/459
Diffstat (limited to 'src')
55 files changed, 519 insertions, 559 deletions
diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c index 2b2fb446a0..80a5449d29 100644 --- a/src/nvim/api/command.c +++ b/src/nvim/api/command.c @@ -413,7 +413,7 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error // Simply pass the first argument (if it exists) as the arg pointer to `set_cmd_addr_type()` // since it only ever checks the first argument. - set_cmd_addr_type(&ea, argc > 0 ? (char_u *)args[0] : NULL); + set_cmd_addr_type(&ea, argc > 0 ? args[0] : NULL); if (HAS_KEY(cmd->range)) { if (!(ea.argt & EX_RANGE)) { diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index c5881dbc5f..bf3fb04a18 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2109,7 +2109,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * bool highlights = false; if (str.size < 2 || memcmp(str.data, "%!", 2)) { - const char *const errmsg = check_stl_option((char_u *)str.data); + const char *const errmsg = check_stl_option(str.data); if (errmsg) { api_set_error(err, kErrorTypeValidation, "%s", errmsg); return result; diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 69f01afcb6..7301e07a06 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -174,7 +174,7 @@ static void aupat_show(AutoPat *ap, event_T event, int previous_group) } msg_col = 4; - msg_outtrans((char_u *)ap->pat); + msg_outtrans(ap->pat); for (AutoCmd *ac = ap->cmds; ac != NULL; ac = ac->next) { // skip removed commands @@ -195,10 +195,10 @@ static void aupat_show(AutoPat *ap, event_T event, int previous_group) size_t msglen = 100; char *msg = (char *)xmallocz(msglen); snprintf(msg, msglen, "%s [%s]", exec_to_string, ac->desc); - msg_outtrans((char_u *)msg); + msg_outtrans(msg); XFREE_CLEAR(msg); } else { - msg_outtrans((char_u *)exec_to_string); + msg_outtrans(exec_to_string); } XFREE_CLEAR(exec_to_string); if (p_verbose > 0) { @@ -471,7 +471,7 @@ void augroup_del(char *name, bool stupid_legacy_mode) FOR_ALL_AUEVENTS(event) { FOR_ALL_AUPATS_IN_EVENT(event, ap) { if (ap->group == i && ap->pat != NULL) { - give_warning((char_u *)_("W19: Deleting augroup that is still in use"), true); + give_warning(_("W19: Deleting augroup that is still in use"), true); map_put(String, int)(&map_augroup_name_to_id, cstr_as_string(name), AUGROUP_DELETED); augroup_map_del(ap->group, NULL); return; @@ -717,7 +717,7 @@ char *au_event_disable(char *what) } else { STRCAT(new_ei, what); } - set_string_option_direct("ei", -1, (char_u *)new_ei, OPT_FREE, SID_NONE); + set_string_option_direct("ei", -1, new_ei, OPT_FREE, SID_NONE); xfree(new_ei); return save_ei; @@ -726,7 +726,7 @@ char *au_event_disable(char *what) void au_event_restore(char *old_ei) { if (old_ei != NULL) { - set_string_option_direct("ei", -1, (char_u *)old_ei, OPT_FREE, SID_NONE); + set_string_option_direct("ei", -1, old_ei, OPT_FREE, SID_NONE); xfree(old_ei); } } diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 85e34e910d..46adb55746 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -948,7 +948,7 @@ char *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int end int deleted = 0; // number of buffers deleted char *errormsg = NULL; // return value int bnr; // buffer number - char_u *p; + char *p; if (addr_count == 0) { (void)do_buffer(command, DOBUF_CURRENT, FORWARD, 0, forceit); @@ -985,13 +985,12 @@ char *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int end break; } if (!ascii_isdigit(*arg)) { - p = skiptowhite_esc(arg); - bnr = buflist_findpat(arg, p, command == DOBUF_WIPE, - false, false); + p = (char *)skiptowhite_esc(arg); + bnr = buflist_findpat(arg, (char_u *)p, command == DOBUF_WIPE, false, false); if (bnr < 0) { // failed break; } - arg = p; + arg = (char_u *)p; } else { bnr = getdigits_int(&arg, false, 0); } @@ -1679,8 +1678,8 @@ static inline void buf_init_changedtick(buf_T *const buf) /// @return pointer to the buffer buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int flags) { - char_u *ffname = ffname_arg; - char_u *sfname = sfname_arg; + char *ffname = (char *)ffname_arg; + char *sfname = (char *)sfname_arg; buf_T *buf; fname_expand(curbuf, &ffname, &sfname); // will allocate ffname @@ -1690,11 +1689,9 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int fl // We can use inode numbers when the file exists. Works better // for hard links. FileID file_id; - bool file_id_valid = (sfname != NULL - && os_fileid((char *)sfname, &file_id)); + bool file_id_valid = (sfname != NULL && os_fileid(sfname, &file_id)); if (ffname != NULL && !(flags & (BLN_DUMMY | BLN_NEW)) - && (buf = buflist_findname_file_id(ffname, &file_id, - file_id_valid)) != NULL) { + && (buf = buflist_findname_file_id(ffname, &file_id, file_id_valid)) != NULL) { xfree(ffname); if (lnum != 0) { buflist_setfpos(buf, (flags & BLN_NOCURWIN) ? NULL : curwin, @@ -1749,8 +1746,8 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int fl } if (ffname != NULL) { - buf->b_ffname = ffname; - buf->b_sfname = vim_strsave(sfname); + buf->b_ffname = (char_u *)ffname; + buf->b_sfname = vim_strsave((char_u *)sfname); } clear_wininfo(buf); @@ -2045,20 +2042,20 @@ void buflist_getfpos(void) /// @return buffer or NULL if not found buf_T *buflist_findname_exp(char_u *fname) { - char_u *ffname; + char *ffname; buf_T *buf = NULL; // First make the name into a full path name - ffname = (char_u *)FullName_save((char *)fname, + ffname = FullName_save((char *)fname, #ifdef UNIX - // force expansion, get rid of symbolic links - true + // force expansion, get rid of symbolic links + true #else - false + false #endif - ); // NOLINT(whitespace/parens) + ); // NOLINT(whitespace/parens) if (ffname != NULL) { - buf = buflist_findname(ffname); + buf = buflist_findname((char_u *)ffname); xfree(ffname); } return buf; @@ -2073,14 +2070,14 @@ buf_T *buflist_findname(char_u *ffname) { FileID file_id; bool file_id_valid = os_fileid((char *)ffname, &file_id); - return buflist_findname_file_id(ffname, &file_id, file_id_valid); + return buflist_findname_file_id((char *)ffname, &file_id, file_id_valid); } /// Same as buflist_findname(), but pass the FileID structure to avoid /// getting it twice for the same file. /// /// @return buffer or NULL if not found -static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id, bool file_id_valid) +static buf_T *buflist_findname_file_id(char *ffname, FileID *file_id, bool file_id_valid) FUNC_ATTR_PURE { // Start at the last buffer, expect to find a match sooner. @@ -2213,7 +2210,7 @@ int buflist_findpat(const char_u *pattern, const char_u *pattern_end, bool unlis typedef struct { buf_T *buf; - char_u *match; + char *match; } bufmatch_T; /// Compare functions for qsort() below, that compares b_last_used. @@ -2236,9 +2233,9 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) { int count = 0; int round; - char_u *p; + char *p; int attempt; - char_u *patc; + char *patc; bufmatch_T *matches = NULL; *num_file = 0; // return values in case of FAIL @@ -2254,20 +2251,20 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) STRCPY(patc, "\\(^\\|[\\/]\\)"); STRCPY(patc + 11, pat + 1); } else { - patc = pat; + patc = (char *)pat; } // attempt == 0: try match with '\<', match at start of word // attempt == 1: try match without '\<', match anywhere for (attempt = 0; attempt <= 1; attempt++) { - if (attempt > 0 && patc == pat) { + if (attempt > 0 && (char_u *)patc == pat) { break; // there was no anchor, no need to try again } regmatch_T regmatch; - regmatch.regprog = vim_regcomp((char *)patc + attempt * 11, RE_MAGIC); + regmatch.regprog = vim_regcomp(patc + attempt * 11, RE_MAGIC); if (regmatch.regprog == NULL) { - if (patc != pat) { + if ((char_u *)patc != pat) { xfree(patc); } return FAIL; @@ -2294,16 +2291,16 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) count++; } else { if (options & WILD_HOME_REPLACE) { - p = home_replace_save(buf, p); + p = (char *)home_replace_save(buf, (char_u *)p); } else { - p = vim_strsave(p); + p = xstrdup(p); } if (matches != NULL) { matches[count].buf = buf; matches[count].match = p; count++; } else { - (*file)[count++] = p; + (*file)[count++] = (char_u *)p; } } } @@ -2325,7 +2322,7 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) } } - if (patc != pat) { + if ((char_u *)patc != pat) { xfree(patc); } @@ -2337,12 +2334,12 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) // if the current buffer is first in the list, place it at the end if (matches[0].buf == curbuf) { for (int i = 1; i < count; i++) { - (*file)[i - 1] = matches[i].match; + (*file)[i - 1] = (char_u *)matches[i].match; } - (*file)[count - 1] = matches[0].match; + (*file)[count - 1] = (char_u *)matches[0].match; } else { for (int i = 0; i < count; i++) { - (*file)[i] = matches[i].match; + (*file)[i] = (char_u *)matches[i].match; } } xfree(matches); @@ -2355,12 +2352,12 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) /// Check for a match on the file name for buffer "buf" with regprog "prog". /// /// @param ignore_case When true, ignore case. Use 'fic' otherwise. -static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, bool ignore_case) +static char *buflist_match(regmatch_T *rmp, buf_T *buf, bool ignore_case) { // First try the short file name, then the long file name. - char_u *match = fname_match(rmp, buf->b_sfname, ignore_case); + char *match = fname_match(rmp, (char *)buf->b_sfname, ignore_case); if (match == NULL && rmp->regprog != NULL) { - match = fname_match(rmp, buf->b_ffname, ignore_case); + match = fname_match(rmp, (char *)buf->b_ffname, ignore_case); } return match; } @@ -2370,20 +2367,20 @@ static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, bool ignore_case) /// @param ignore_case When true, ignore case. Use 'fileignorecase' otherwise. /// /// @return "name" when there is a match, NULL when not. -static char_u *fname_match(regmatch_T *rmp, char_u *name, bool ignore_case) +static char *fname_match(regmatch_T *rmp, char *name, bool ignore_case) { - char_u *match = NULL; - char_u *p; + char *match = NULL; + char *p; if (name != NULL) { // Ignore case when 'fileignorecase' or the argument is set. rmp->rm_ic = p_fic || ignore_case; - if (vim_regexec(rmp, name, (colnr_T)0)) { + if (vim_regexec(rmp, (char_u *)name, (colnr_T)0)) { match = name; } else if (rmp->regprog != NULL) { // Replace $(HOME) with '~' and try matching again. - p = home_replace_save(NULL, name); - if (vim_regexec(rmp, p, (colnr_T)0)) { + p = (char *)home_replace_save(NULL, (char_u *)name); + if (vim_regexec(rmp, (char_u *)p, (colnr_T)0)) { match = name; } xfree(p); @@ -2658,7 +2655,7 @@ void buflist_list(exarg_T *eap) if (buf_spname(buf) != NULL) { STRLCPY(NameBuff, buf_spname(buf), MAXPATHL); } else { - home_replace(buf, (char_u *)buf->b_fname, NameBuff, MAXPATHL, true); + home_replace(buf, buf->b_fname, (char *)NameBuff, MAXPATHL, true); } if (message_filtered(NameBuff)) { @@ -2688,7 +2685,7 @@ void buflist_list(exarg_T *eap) } // put "line 999" in column 40 or after the file name - i = 40 - vim_strsize(IObuff); + i = 40 - vim_strsize((char *)IObuff); do { IObuff[len++] = ' '; } while (--i > 0 && len < IOSIZE - 18); @@ -2699,7 +2696,7 @@ void buflist_list(exarg_T *eap) buf == curbuf ? (int64_t)curwin->w_cursor.lnum : (int64_t)buflist_findlnum(buf)); } - msg_outtrans(IObuff); + msg_outtrans((char *)IObuff); line_breakcheck(); } @@ -2735,10 +2732,10 @@ int buflist_name_nr(int fnum, char_u **fname, linenr_T *lnum) /// @param message give message when buffer already exists /// /// @return FAIL for failure (file name already in use by other buffer) OK otherwise. -int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message) +int setfname(buf_T *buf, char *ffname_arg, char *sfname_arg, bool message) { - char_u *ffname = ffname_arg; - char_u *sfname = sfname_arg; + char *ffname = ffname_arg; + char *sfname = sfname_arg; buf_T *obuf = NULL; FileID file_id; bool file_id_valid = false; @@ -2760,7 +2757,7 @@ int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message) // If the file name is already used in another buffer: // - if the buffer is loaded, fail // - if the buffer is not loaded, delete it from the list - file_id_valid = os_fileid((char *)ffname, &file_id); + file_id_valid = os_fileid(ffname, &file_id); if (!(buf->b_flags & BF_DUMMY)) { obuf = buflist_findname_file_id(ffname, &file_id, file_id_valid); } @@ -2775,16 +2772,16 @@ int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message) // delete from the list close_buffer(NULL, obuf, DOBUF_WIPE, false, false); } - sfname = vim_strsave(sfname); + sfname = xstrdup(sfname); #ifdef USE_FNAME_CASE - path_fix_case(sfname); // set correct case for short file name + path_fix_case((char_u *)sfname); // set correct case for short file name #endif if (buf->b_sfname != buf->b_ffname) { xfree(buf->b_sfname); } xfree(buf->b_ffname); - buf->b_ffname = ffname; - buf->b_sfname = sfname; + buf->b_ffname = (char_u *)ffname; + buf->b_sfname = (char_u *)sfname; } buf->b_fname = (char *)buf->b_sfname; if (!file_id_valid) { @@ -2814,7 +2811,7 @@ void buf_set_name(int fnum, char_u *name) buf->b_sfname = NULL; // Allocate ffname and expand into full path. Also resolves .lnk // files on Win32. - fname_expand(buf, &buf->b_ffname, &buf->b_sfname); + fname_expand(buf, (char **)&buf->b_ffname, (char **)&buf->b_sfname); buf->b_fname = (char *)buf->b_sfname; } } @@ -2859,16 +2856,16 @@ buf_T *setaltfname(char_u *ffname, char_u *sfname, linenr_T lnum) /// @param errmsg give error message char_u *getaltfname(bool errmsg) { - char_u *fname; + char *fname; linenr_T dummy; - if (buflist_name_nr(0, &fname, &dummy) == FAIL) { + if (buflist_name_nr(0, (char_u **)&fname, &dummy) == FAIL) { if (errmsg) { emsg(_(e_noalt)); } return NULL; } - return fname; + return (char_u *)fname; } /// Add a file name to the buflist and return its number. @@ -2916,7 +2913,7 @@ void buflist_altfpos(win_T *win) bool otherfile(char_u *ffname) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return otherfile_buf(curbuf, ffname, NULL, false); + return otherfile_buf(curbuf, (char *)ffname, NULL, false); } /// Check that "ffname" is not the same file as the file loaded in "buf". @@ -2926,7 +2923,7 @@ bool otherfile(char_u *ffname) /// @param ffname full path name to check /// @param file_id_p information about the file at "ffname". /// @param file_id_valid whether a valid "file_id_p" was passed in. -static bool otherfile_buf(buf_T *buf, char_u *ffname, FileID *file_id_p, bool file_id_valid) +static bool otherfile_buf(buf_T *buf, char *ffname, FileID *file_id_p, bool file_id_valid) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { // no name is different @@ -2941,7 +2938,7 @@ static bool otherfile_buf(buf_T *buf, char_u *ffname, FileID *file_id_p, bool fi // If no struct stat given, get it now if (file_id_p == NULL) { file_id_p = &file_id; - file_id_valid = os_fileid((char *)ffname, file_id_p); + file_id_valid = os_fileid(ffname, file_id_p); } if (!file_id_valid) { // file_id not valid, assume files are different. @@ -2995,7 +2992,7 @@ static bool buf_same_file_id(buf_T *buf, FileID *file_id) /// @param fullname when non-zero print full path void fileinfo(int fullname, int shorthelp, int dont_truncate) { - char_u *name; + char *name; int n; char *p; char *buffer; @@ -3015,11 +3012,11 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate) STRLCPY(p, buf_spname(curbuf), IOSIZE - (p - buffer)); } else { if (!fullname && curbuf->b_fname != NULL) { - name = (char_u *)curbuf->b_fname; + name = curbuf->b_fname; } else { - name = curbuf->b_ffname; + name = (char *)curbuf->b_ffname; } - home_replace(shorthelp ? curbuf : NULL, name, (char_u *)p, + home_replace(shorthelp ? curbuf : NULL, name, p, (size_t)(IOSIZE - (p - buffer)), true); } @@ -3069,7 +3066,7 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate) (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1); } - (void)append_arg_number(curwin, (char_u *)buffer, IOSIZE, !shortmess(SHM_FILE)); + (void)append_arg_number(curwin, buffer, IOSIZE, !shortmess(SHM_FILE)); if (dont_truncate) { // Temporarily set msg_scroll to avoid the message being truncated. @@ -3103,14 +3100,14 @@ void col_print(char_u *buf, size_t buflen, int col, int vcol) } } -static char_u *lasttitle = NULL; -static char_u *lasticon = NULL; +static char *lasttitle = NULL; +static char *lasticon = NULL; /// Put the title name in the title bar and icon of the window. void maketitle(void) { - char_u *title_str = NULL; - char_u *icon_str = NULL; + char *title_str = NULL; + char *icon_str = NULL; int maxlen = 0; int len; int mustset; @@ -3145,14 +3142,13 @@ void maketitle(void) build_stl_str_hl(curwin, buf, sizeof(buf), (char *)p_titlestring, use_sandbox, 0, maxlen, NULL, NULL); - title_str = (char_u *)buf; + title_str = buf; if (called_emsg) { - set_string_option_direct("titlestring", -1, (char_u *)"", - OPT_FREE, SID_ERROR); + set_string_option_direct("titlestring", -1, "", OPT_FREE, SID_ERROR); } called_emsg |= save_called_emsg; } else { - title_str = p_titlestring; + title_str = (char *)p_titlestring; } } else { // Format: "fname + (path) (1 of 2) - VIM". @@ -3195,7 +3191,7 @@ void maketitle(void) // Get path of file, replace home dir with ~. *buf_p++ = ' '; *buf_p++ = '('; - home_replace(curbuf, curbuf->b_ffname, (char_u *)buf_p, + home_replace(curbuf, (char *)curbuf->b_ffname, buf_p, (SPACE_FOR_DIR - (size_t)(buf_p - buf)), true); #ifdef BACKSLASH_IN_FILENAME // Avoid "c:/name" to be reduced to "c". @@ -3232,18 +3228,17 @@ void maketitle(void) *buf_p = NUL; } - append_arg_number(curwin, (char_u *)buf_p, - (int)(SPACE_FOR_ARGNR - (size_t)(buf_p - buf)), false); + append_arg_number(curwin, buf_p, (int)(SPACE_FOR_ARGNR - (size_t)(buf_p - buf)), false); xstrlcat(buf_p, " - NVIM", (sizeof(buf) - (size_t)(buf_p - buf))); if (maxlen > 0) { // Make it shorter by removing a bit in the middle. - if (vim_strsize((char_u *)buf) > maxlen) { + if (vim_strsize(buf) > maxlen) { trunc_string((char_u *)buf, (char_u *)buf, maxlen, sizeof(buf)); } } - title_str = (char_u *)buf; + title_str = buf; #undef SPACE_FOR_FNAME #undef SPACE_FOR_DIR #undef SPACE_FOR_ARGNR @@ -3252,7 +3247,7 @@ void maketitle(void) mustset = value_change(title_str, &lasttitle); if (p_icon) { - icon_str = (char_u *)buf; + icon_str = buf; if (*p_iconstring != NUL) { if (stl_syntax & STL_IN_ICON) { int use_sandbox = false; @@ -3260,34 +3255,33 @@ void maketitle(void) use_sandbox = was_set_insecurely(curwin, "iconstring", 0); called_emsg = false; - build_stl_str_hl(curwin, (char *)icon_str, sizeof(buf), + build_stl_str_hl(curwin, icon_str, sizeof(buf), (char *)p_iconstring, use_sandbox, 0, 0, NULL, NULL); if (called_emsg) { - set_string_option_direct("iconstring", -1, - (char_u *)"", OPT_FREE, SID_ERROR); + set_string_option_direct("iconstring", -1, "", OPT_FREE, SID_ERROR); } called_emsg |= save_called_emsg; } else { - icon_str = p_iconstring; + icon_str = (char *)p_iconstring; } } else { - char_u *buf_p; + char *buf_p; if (buf_spname(curbuf) != NULL) { buf_p = buf_spname(curbuf); } else { // use file name only in icon - buf_p = (char_u *)path_tail((char *)curbuf->b_ffname); + buf_p = path_tail((char *)curbuf->b_ffname); } *icon_str = NUL; // Truncat |