From 4c531714ff24d82bf1a85decf0e0c63c5785e686 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Thu, 19 Jan 2023 15:25:56 +0100 Subject: [PATCH] refactor: replace char_u with char 25 (#21838) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- cmake.config/pathdef.c.in | 4 +- src/nvim/debugger.c | 10 +- src/nvim/diff.c | 2 +- src/nvim/edit.c | 4 +- src/nvim/eval.c | 14 +- src/nvim/eval/funcs.c | 16 +-- src/nvim/eval/typval.c | 4 +- src/nvim/eval/typval_encode.c.h | 4 +- src/nvim/eval/userfunc.c | 28 ++-- src/nvim/ex_cmds.c | 12 +- src/nvim/ex_docmd.c | 19 ++- src/nvim/ex_eval.c | 2 +- src/nvim/file_search.c | 22 ++- src/nvim/fileio.c | 21 +-- src/nvim/getchar.c | 14 +- src/nvim/globals.h | 4 +- src/nvim/help.c | 8 +- src/nvim/highlight_group.c | 6 +- src/nvim/insexpand.c | 2 +- src/nvim/keycodes.c | 34 ++--- src/nvim/lua/executor.c | 20 +-- src/nvim/main.c | 4 +- src/nvim/mbyte.c | 85 ++++++------ src/nvim/normal.c | 2 +- src/nvim/ops.c | 5 +- src/nvim/option.c | 22 +-- src/nvim/option_defs.h | 50 +++---- src/nvim/os/env.c | 4 +- src/nvim/os/shell.c | 6 +- src/nvim/path.c | 20 +-- src/nvim/quickfix.c | 8 +- src/nvim/regexp.c | 36 ++--- src/nvim/regexp_bt.c | 230 ++++++++++++++++---------------- src/nvim/regexp_nfa.c | 114 ++++++++-------- src/nvim/search.c | 6 +- src/nvim/spell.c | 2 +- src/nvim/spellfile.c | 4 - src/nvim/strings.c | 18 +-- src/nvim/syntax.c | 4 +- src/nvim/tag.c | 4 +- src/nvim/testing.c | 50 +++---- src/nvim/textobject.c | 4 +- src/nvim/undo.c | 4 +- src/nvim/window.c | 12 +- 44 files changed, 468 insertions(+), 476 deletions(-) diff --git a/cmake.config/pathdef.c.in b/cmake.config/pathdef.c.in index 6a8a2b205a..5d6dfa6b9f 100644 --- a/cmake.config/pathdef.c.in +++ b/cmake.config/pathdef.c.in @@ -4,5 +4,5 @@ char *default_vim_dir = "${CMAKE_INSTALL_FULL_DATAROOTDIR}/nvim"; char *default_vimruntime_dir = ""; char *default_lib_dir = "${CMAKE_INSTALL_FULL_LIBDIR}/nvim"; -char_u *compiled_user = (char_u *)"${USERNAME}"; -char_u *compiled_sys = (char_u *)"${HOSTNAME}"; +char *compiled_user = "${USERNAME}"; +char *compiled_sys = "${HOSTNAME}"; diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c index ad615969ba..f7e70a78ce 100644 --- a/src/nvim/debugger.c +++ b/src/nvim/debugger.c @@ -403,7 +403,7 @@ void ex_debug(exarg_T *eap) debug_break_level = debug_break_level_save; } -static char_u *debug_breakpoint_name = NULL; +static char *debug_breakpoint_name = NULL; static linenr_T debug_breakpoint_lnum; /// When debugging or a breakpoint is set on a skipped command, no debug prompt @@ -412,7 +412,7 @@ static linenr_T debug_breakpoint_lnum; /// a skipped command decides itself that a debug prompt should be displayed, it /// can do so by calling dbg_check_skipped(). static int debug_skipped; -static char_u *debug_skipped_name; +static char *debug_skipped_name; /// Go to debug mode when a breakpoint was encountered or "ex_nesting_level" is /// at or below the break level. But only when the line is actually @@ -426,8 +426,8 @@ void dbg_check_breakpoint(exarg_T *eap) if (!eap->skip) { char *p; // replace K_SNR with "" - if (debug_breakpoint_name[0] == K_SPECIAL - && debug_breakpoint_name[1] == KS_EXTRA + if ((uint8_t)debug_breakpoint_name[0] == K_SPECIAL + && (uint8_t)debug_breakpoint_name[1] == KS_EXTRA && debug_breakpoint_name[2] == KE_SNR) { p = ""; } else { @@ -857,6 +857,6 @@ static linenr_T debuggy_find(bool file, char *fname, linenr_T after, garray_T *g void dbg_breakpoint(char *name, linenr_T lnum) { // We need to check if this line is actually executed in do_one_cmd() - debug_breakpoint_name = (char_u *)name; + debug_breakpoint_name = name; debug_breakpoint_lnum = lnum; } diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 7fbde4f45b..032de561b3 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1218,7 +1218,7 @@ void ex_diffpatch(exarg_T *eap) fullname = FullName_save(eap->arg, false); esc_name = vim_strsave_shellescape(fullname != NULL ? fullname : eap->arg, true, true); #else - esc_name = (char *)vim_strsave_shellescape(eap->arg, true, true); + esc_name = vim_strsave_shellescape(eap->arg, true, true); #endif size_t buflen = strlen(tmp_orig) + strlen(esc_name) + strlen(tmp_new) + 16; buf = xmalloc(buflen); diff --git a/src/nvim/edit.c b/src/nvim/edit.c index bf4563caa1..32c035b028 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -323,7 +323,7 @@ static void insert_enter(InsertState *s) // Get the current length of the redo buffer, those characters have to be // skipped if we want to get to the inserted characters. - s->ptr = (char *)get_inserted(); + s->ptr = get_inserted(); if (s->ptr == NULL) { new_insert_skip = 0; } else { @@ -2303,7 +2303,7 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove) // Save the inserted text for later redo with ^@ and CTRL-A. // Don't do it when "restart_edit" was set and nothing was inserted, // otherwise CTRL-O w and then will clear "last_insert". - ptr = (char *)get_inserted(); + ptr = get_inserted(); if (did_restart_edit == 0 || (ptr != NULL && (int)strlen(ptr) > new_insert_skip)) { xfree(last_insert); diff --git a/src/nvim/eval.c b/src/nvim/eval.c index a9ea298285..45b492be80 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5002,7 +5002,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref) // Don't check an autoload name for existence here. } else if (trans_name != NULL && (is_funcref - ? find_func((char_u *)trans_name) == NULL + ? find_func(trans_name) == NULL : !translated_function_exists((const char *)trans_name))) { semsg(_("E700: Unknown function: %s"), s); } else { @@ -5101,7 +5101,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref) func_ptr_ref(pt->pt_func); xfree(name); } else if (is_funcref) { - pt->pt_func = find_func((char_u *)trans_name); + pt->pt_func = find_func(trans_name); func_ptr_ref(pt->pt_func); xfree(name); } else { @@ -5536,7 +5536,7 @@ bool callback_from_typval(Callback *const callback, const typval_T *const arg) } } else if (nlua_is_table_from_lua(arg)) { // TODO(tjdvries): UnifiedCallback - char *name = (char *)nlua_register_table_as_callable(arg); + char *name = nlua_register_table_as_callable(arg); if (name != NULL) { callback->data.funcref = xstrdup(name); @@ -8299,7 +8299,7 @@ bool eval_has_provider(const char *feat) if (get_var_tv(buf, len, &tv, NULL, false, true) == FAIL) { // Show a hint if Call() is defined but g:loaded_xx_provider is missing. snprintf(buf, sizeof(buf), "provider#%s#Call", name); - if (!!find_func((char_u *)buf) && p_lpl) { + if (!!find_func(buf) && p_lpl) { semsg("provider: %s: missing required variable g:loaded_%s_provider", name, name); } @@ -8314,7 +8314,7 @@ bool eval_has_provider(const char *feat) if (ok) { // Call() must be defined if provider claims to be working. snprintf(buf, sizeof(buf), "provider#%s#Call", name); - if (!find_func((char_u *)buf)) { + if (!find_func(buf)) { semsg("provider: %s: g:loaded_%s_provider=2 but %s is not defined", name, name, buf); ok = false; @@ -8337,10 +8337,10 @@ void eval_fmt_source_name_line(char *buf, size_t bufsize) /// ":checkhealth [plugins]" void ex_checkhealth(exarg_T *eap) { - bool found = !!find_func((char_u *)"health#check"); + bool found = !!find_func("health#check"); if (!found && script_autoload("health#check", sizeof("health#check") - 1, false)) { - found = !!find_func((char_u *)"health#check"); + found = !!find_func("health#check"); } if (!found) { const char *vimruntime_env = os_getenv("VIMRUNTIME"); diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 91ab9f14ff..1b34777a46 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -557,7 +557,7 @@ static void f_call(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) func = partial_name(partial); } else if (nlua_is_table_from_lua(&argvars[0])) { // TODO(tjdevries): UnifiedCallback - func = (char *)nlua_register_table_as_callable(&argvars[0]); + func = nlua_register_table_as_callable(&argvars[0]); owned = true; } else { func = (char *)tv_get_string(&argvars[0]); @@ -1419,7 +1419,7 @@ static void f_diff_hlID(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) hlID = HLF_CHD; // Changed line. } } - rettv->vval.v_number = hlID == (hlf_T)0 ? 0 : (int)(hlID + 1); + rettv->vval.v_number = hlID == (hlf_T)0 ? 0 : (hlID + 1); } /// "empty({expr})" function @@ -1695,7 +1695,7 @@ static void f_exepath(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) #ifdef BACKSLASH_IN_FILENAME if (path != NULL) { - slash_adjust((char_u *)path); + slash_adjust(path); } #endif @@ -1749,7 +1749,7 @@ static void f_expand(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) int options = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND; bool error = false; #ifdef BACKSLASH_IN_FILENAME - char_u *p_csl_save = p_csl; + char *p_csl_save = p_csl; // avoid using 'completeslash' here p_csl = empty_option; @@ -1770,7 +1770,7 @@ static void f_expand(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } size_t len; char *errormsg = NULL; - char *result = (char *)eval_vars((char *)s, (char_u *)s, &len, NULL, &errormsg, NULL, false); + char *result = eval_vars((char *)s, s, &len, NULL, &errormsg, NULL, false); if (p_verbose == 0) { emsg_off--; } else if (errormsg != NULL) { @@ -2022,7 +2022,7 @@ static void f_filewritable(typval_T *argvars, typval_T *rettv, EvalFuncData fptr static void findfilendir(typval_T *argvars, typval_T *rettv, int find_what) { char *fresult = NULL; - char *path = *curbuf->b_p_path == NUL ? (char *)p_path : curbuf->b_p_path; + char *path = *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path; int count = 1; bool first = true; bool error = false; @@ -7827,7 +7827,7 @@ static void f_strftime(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) vimconv_T conv; conv.vc_type = CONV_NONE; - char *enc = (char *)enc_locale(); + char *enc = enc_locale(); convert_setup(&conv, p_enc, enc); if (conv.vc_type != CONV_NONE) { p = string_convert(&conv, p, NULL); @@ -8097,7 +8097,7 @@ static void f_strptime(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) vimconv_T conv = { .vc_type = CONV_NONE, }; - char *enc = (char *)enc_locale(); + char *enc = enc_locale(); convert_setup(&conv, p_enc, enc); if (conv.vc_type != CONV_NONE) { fmt = string_convert(&conv, fmt, NULL); diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index b48aa1372e..9ffc4d4696 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -3007,7 +3007,7 @@ void tv_blob_copy(typval_T *const from, typval_T *const to) (tv)->v_lock = VAR_UNLOCKED; \ } while (0) -static inline int _nothing_conv_func_start(typval_T *const tv, char_u *const fun) +static inline int _nothing_conv_func_start(typval_T *const tv, char *const fun) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_NONNULL_ARG(1) { tv->v_lock = VAR_UNLOCKED; @@ -3019,7 +3019,7 @@ static inline int _nothing_conv_func_start(typval_T *const tv, char_u *const fun return OK; } } else { - func_unref((char *)fun); + func_unref(fun); if ((const char *)fun != tv_empty_string) { xfree(fun); } diff --git a/src/nvim/eval/typval_encode.c.h b/src/nvim/eval/typval_encode.c.h index 6c931d3f88..6d29286a58 100644 --- a/src/nvim/eval/typval_encode.c.h +++ b/src/nvim/eval/typval_encode.c.h @@ -339,7 +339,7 @@ static int _TYPVAL_ENCODE_CONVERT_ONE_VALUE( tv_blob_len(tv->vval.v_blob)); break; case VAR_FUNC: - TYPVAL_ENCODE_CONV_FUNC_START(tv, (char_u *)tv->vval.v_string); + TYPVAL_ENCODE_CONV_FUNC_START(tv, tv->vval.v_string); TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS(tv, 0); TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, -1); TYPVAL_ENCODE_CONV_FUNC_END(tv); @@ -347,7 +347,7 @@ static int _TYPVAL_ENCODE_CONVERT_ONE_VALUE( case VAR_PARTIAL: { partial_T *const pt = tv->vval.v_partial; (void)pt; - TYPVAL_ENCODE_CONV_FUNC_START(tv, (pt == NULL ? NULL : (char_u *)partial_name(pt))); // -V547 + TYPVAL_ENCODE_CONV_FUNC_START(tv, (pt == NULL ? NULL : partial_name(pt))); // -V547 _mp_push(*mpstack, ((MPConvStackVal) { // -V779 .type = kMPConvPartial, .tv = tv, diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 74d9e30a58..22c5b1954d 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -582,9 +582,9 @@ static char *fname_trans_sid(const char *const name, char *const fname_buf, char /// Find a function by name, return pointer to it in ufuncs. /// /// @return NULL for unknown function. -ufunc_T *find_func(const char_u *name) +ufunc_T *find_func(const char *name) { - hashitem_T *hi = hash_find(&func_hashtab, (char *)name); + hashitem_T *hi = hash_find(&func_hashtab, name); if (!HASHITEM_EMPTY(hi)) { return HI2UF(hi); } @@ -1580,7 +1580,7 @@ int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, t } else if (fp != NULL || !builtin_function((const char *)rfname, -1)) { // User defined function. if (fp == NULL) { - fp = find_func((char_u *)rfname); + fp = find_func(rfname); } // Trigger FuncUndefined event, may load the function. @@ -1588,13 +1588,13 @@ int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, t && apply_autocmds(EVENT_FUNCUNDEFINED, rfname, rfname, true, NULL) && !aborting()) { // executed an autocommand, search for the function again - fp = find_func((char_u *)rfname); + fp = find_func(rfname); } // Try loading a package. if (fp == NULL && script_autoload((const char *)rfname, strlen(rfname), true) && !aborting()) { // Loaded a package, search for the function again. - fp = find_func((char_u *)rfname); + fp = find_func(rfname); } if (fp != NULL && (fp->uf_flags & FC_DELETED)) { @@ -2133,7 +2133,7 @@ void ex_function(exarg_T *eap) *p = NUL; } if (!eap->skip && !got_int) { - fp = find_func((char_u *)name); + fp = find_func(name); if (fp != NULL) { list_func_head(fp, !eap->forceit, eap->forceit); for (int j = 0; j < fp->uf_lines.ga_len && !got_int; j++) { @@ -2256,7 +2256,7 @@ void ex_function(exarg_T *eap) if (!eap->skip && !eap->forceit) { if (fudi.fd_dict != NULL && fudi.fd_newkey == NULL) { emsg(_(e_funcdict)); - } else if (name != NULL && find_func((char_u *)name) != NULL) { + } else if (name != NULL && find_func(name) != NULL) { emsg_funcname(e_funcexts, name); } } @@ -2510,7 +2510,7 @@ void ex_function(exarg_T *eap) goto erret; } - fp = find_func((char_u *)name); + fp = find_func(name); if (fp != NULL) { // Function can be replaced with "function!" and when sourcing the // same script again, but only once. @@ -2690,7 +2690,7 @@ bool translated_function_exists(const char *name) if (builtin_function(name, -1)) { return find_internal_func((char *)name) != NULL; } - return find_func((const char_u *)name) != NULL; + return find_func(name) != NULL; } /// Check whether function with the given name exists @@ -2800,7 +2800,7 @@ void ex_delfunction(exarg_T *eap) return; } if (!eap->skip) { - fp = find_func((char_u *)name); + fp = find_func(name); } xfree(name); @@ -2857,7 +2857,7 @@ void func_unref(char *name) return; } - fp = find_func((char_u *)name); + fp = find_func(name); if (fp == NULL && isdigit((uint8_t)(*name))) { #ifdef EXITFREE if (!entered_free_all_mem) { @@ -2898,7 +2898,7 @@ void func_ref(char *name) if (name == NULL || !func_name_refcount(name)) { return; } - fp = find_func((char_u *)name); + fp = find_func(name); if (fp != NULL) { (fp->uf_refcount)++; } else if (isdigit((uint8_t)(*name))) { @@ -3305,7 +3305,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) : rettv->vval.v_partial->pt_name; // Translate "s:func" to the stored function name. fname = fname_trans_sid(fname, fname_buf, &tofree, &error); - fp = find_func((char_u *)fname); + fp = find_func(fname); xfree(tofree); } @@ -3651,7 +3651,7 @@ bool set_ref_in_func(char *name, ufunc_T *fp_in, int copyID) if (fp_in == NULL) { fname = fname_trans_sid(name, fname_buf, &tofree, &error); - fp = find_func((char_u *)fname); + fp = find_func(fname); } if (fp != NULL) { for (fc = fp->uf_scoped; fc != NULL; fc = fc->func->uf_scoped) { diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 6e888d9dcf..437a05f61d 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1348,7 +1348,7 @@ static char *find_pipe(const char *cmd) } if (*p == '"') { inquote = !inquote; - } else if (rem_backslash((const char_u *)p)) { + } else if (rem_backslash(p)) { p++; } } @@ -1420,7 +1420,7 @@ char *make_filter_cmd(char *cmd, char *itmp, char *otmp) #else // For shells that don't understand braces around commands, at least allow // the use of commands in a pipe. - xstrlcpy(buf, (char *)cmd, len); + xstrlcpy(buf, cmd, len); if (itmp != NULL) { // If there is a pipe, we have to put the '<' in front of it. // Don't do this when 'shellquote' is not empty, otherwise the @@ -3351,11 +3351,11 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T which_pat = RE_SEARCH; // use last '/' pattern } pat = ""; // empty search pattern - delimiter = (char_u)(*cmd++); // remember delimiter character + delimiter = (uint8_t)(*cmd++); // remember delimiter character has_second_delim = true; } else { // find the end of the regexp which_pat = RE_LAST; // use last used regexp - delimiter = (char_u)(*cmd++); // remember delimiter character + delimiter = (uint8_t)(*cmd++); // remember delimiter character pat = cmd; // remember start of search pat cmd = skip_regexp_ex(cmd, delimiter, magic_isset(), &eap->arg, NULL, NULL); if (cmd[0] == delimiter) { // end delimiter found @@ -3697,7 +3697,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T msg_putchar('\n'); xfree(prompt); if (resp != NULL) { - typed = (char_u)(*resp); + typed = (uint8_t)(*resp); xfree(resp); } else { // getcmdline_prompt() returns NULL if there is no command line to return. @@ -4704,7 +4704,7 @@ char *skip_vimgrep_pat(char *p, char **s, int *flags) if (s != NULL) { *s = p + 1; } - c = (char_u)(*p); + c = (uint8_t)(*p); p = skip_regexp(p + 1, c, true); if (*p != c) { return NULL; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 08d4065e98..eefb1ae1ce 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -3710,7 +3710,7 @@ char *replace_makeprg(exarg_T *eap, char *arg, char **cmdlinep) if ((eap->cmdidx == CMD_make || eap->cmdidx == CMD_lmake || isgrep) && !grep_internal(eap->cmdidx)) { const char *program = isgrep ? (*curbuf->b_p_gp == NUL ? p_gp : curbuf->b_p_gp) - : (*curbuf->b_p_mp == NUL ? (char *)p_mp : curbuf->b_p_mp); + : (*curbuf->b_p_mp == NUL ? p_mp : curbuf->b_p_mp); arg = skipwhite(arg); @@ -3767,8 +3767,8 @@ int expand_filename(exarg_T *eap, char **cmdlinep, char **errormsgp) // Try to find a match at this position. size_t srclen; int escaped; - char *repl = (char *)eval_vars(p, (char_u *)eap->arg, &srclen, &(eap->do_ecmd_lnum), - errormsgp, &escaped, true); + char *repl = eval_vars(p, eap->arg, &srclen, &(eap->do_ecmd_lnum), + errormsgp, &escaped, true); if (*errormsgp != NULL) { // error detected return FAIL; } @@ -3868,7 +3868,7 @@ int expand_filename(exarg_T *eap, char **cmdlinep, char **errormsgp) backslash_halve(eap->arg); } #else - backslash_halve((char_u *)eap->arg); + backslash_halve(eap->arg); #endif if (has_wildcards) { @@ -6725,8 +6725,8 @@ ssize_t find_cmdline_var(const char *src, size_t *usedlen) /// @return an allocated string if a valid match was found. /// Returns NULL if no match was found. "usedlen" then still contains the /// number of characters to skip. -char_u *eval_vars(char *src, const char_u *srcstart, size_t *usedlen, linenr_T *lnump, - char **errormsg, int *escaped, bool empty_is_error) +char *eval_vars(char *src, const char *srcstart, size_t *usedlen, linenr_T *lnump, char **errormsg, + int *escaped, bool empty_is_error) { char *result; char *resultbuf = NULL; @@ -6750,7 +6750,7 @@ char_u *eval_vars(char *src, const char_u *srcstart, size_t *usedlen, linenr_T * // Skip when preceded with a backslash "\%" and "\#". // Note: In "\\%" the % is also not recognized! - if ((char_u *)src > srcstart && src[-1] == '\\') { + if (src > srcstart && src[-1] == '\\') { *usedlen = 0; STRMOVE(src - 1, (char *)src); // remove backslash return NULL; @@ -6985,7 +6985,7 @@ char_u *eval_vars(char *src, const char_u *srcstart, size_t *usedlen, linenr_T * result = xstrnsave(result, resultlen); } xfree(resultbuf); - return (char_u *)result; + return result; } /// Expand the string in "arg". @@ -7002,8 +7002,7 @@ char *expand_sfile(char *arg) // replace "" with the sourced file name, and do ":" stuff size_t srclen; char *errormsg; - char *repl = (char *)eval_vars(p, (char_u *)result, &srclen, NULL, &errormsg, NULL, - true); + char *repl = eval_vars(p, result, &srclen, NULL, &errormsg, NULL, true); if (errormsg != NULL) { if (*errormsg) { emsg(errormsg); diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index bfbb6f89b5..f76e60f6c5 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -1150,7 +1150,7 @@ void ex_throw(exarg_T *eap) // On error or when an exception is thrown during argument evaluation, do // not throw. if (!eap->skip && value != NULL) { - if (throw_exception((char_u *)value, ET_USER, NULL) == FAIL) { + if (throw_exception(value, ET_USER, NULL) == FAIL) { xfree(value); } else { do_throw(eap->cstack); diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 02a33f8fd3..e236f23895 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -143,7 +143,7 @@ typedef struct ff_visited_list_hdr { // '**' can be expanded to several directory levels. // Set the default maximum depth. -#define FF_MAX_STAR_STAR_EXPAND ((char_u)30) +#define FF_MAX_STAR_STAR_EXPAND 30 // The search context: // ffsc_stack_ptr: the stack for the dirs to search @@ -182,7 +182,7 @@ typedef struct ff_search_ctx_T { # include "file_search.c.generated.h" #endif -static char_u e_pathtoolong[] = N_("E854: path too long for completion"); +static char e_pathtoolong[] = N_("E854: path too long for completion"); /// Initialization routine for vim_findfile(). /// @@ -302,14 +302,12 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i #ifdef BACKSLASH_IN_FILENAME // "c:dir" needs "c:" to be expanded, otherwise use current dir if (*path != NUL && path[1] == ':') { - char_u drive[3]; + char drive[3]; drive[0] = path[0]; drive[1] = ':'; drive[2] = NUL; - if (vim_FullName((const char *)drive, (char *)ff_expand_buffer, MAXPATHL, - true) - == FAIL) { + if (vim_FullName(drive, ff_expand_buffer, MAXPATHL, true) == FAIL) { goto error_return; } path += 2; @@ -504,15 +502,15 @@ error_return: } /// @return the stopdir string. Check that ';' is not escaped. -char_u *vim_findfile_stopdir(char *buf) +char *vim_findfile_stopdir(char *buf) { - char_u *r_ptr = (char_u *)buf; + char *r_ptr = buf; while (*r_ptr != NUL && *r_ptr != ';') { if (r_ptr[0] == '\\' && r_ptr[1] == ';') { // Overwrite the escape char, // use strlen(r_ptr) to move the trailing '\0'. - STRMOVE(r_ptr, (char *)r_ptr + 1); + STRMOVE(r_ptr, r_ptr + 1); r_ptr++; } r_ptr++; @@ -1291,7 +1289,7 @@ char *find_file_in_path(char *ptr, size_t len, int options, int first, char *rel { return find_file_in_path_option(ptr, len, options, first, (*curbuf->b_p_path == NUL - ? (char *)p_path + ? p_path : curbuf->b_p_path), FINDFILE_BOTH, rel_fname, curbuf->b_p_sua); } @@ -1324,7 +1322,7 @@ void free_findfile(void) /// @return an allocated string for the file name. NULL for error. char *find_directory_in_path(char *ptr, size_t len, int options, char *rel_fname) { - return find_file_in_path_option(ptr, len, options, true, (char *)p_cdpath, + return find_file_in_path_option(ptr, len, options, true, p_cdpath, FINDFILE_DIR, rel_fname, ""); } @@ -1469,7 +1467,7 @@ char *find_file_in_path_option(char *ptr, size_t len, int options, int first, ch copy_option_part(&dir, buf, MAXPATHL, " ,"); // get the stopdir string - r_ptr = (char *)vim_findfile_stopdir(buf); + r_ptr = vim_findfile_stopdir(buf); fdip_search_ctx = vim_findfile_init(buf, ff_file_to_find, r_ptr, 100, false, find_what, fdip_search_ctx, false, rel_fname); diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 78fe8a3ab3..c05eb41b6d 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -1114,7 +1114,7 @@ retry: if (size < 2 || curbuf->b_p_bin) { ccname = NULL; } else { - ccname = check_for_bom((char_u *)ptr, size, &blen, + ccname = check_for_bom(ptr, size, &blen, fio_flags == FIO_UCSBOM ? FIO_ALL : get_fio_flags(fenc)); } if (ccname != NULL) { @@ -2473,7 +2473,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en if (!filtering) { filemess(buf, #ifndef UNIX - (char_u *)sfname, + sfname, #else fname, #endif @@ -2517,7 +2517,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en } #else // win32 // Check for a writable device name. - c = fname == NULL ? NODE_OTHER : os_nodetype((char *)fname); + c = fname == NULL ? NODE_OTHER : os_nodetype(fname); if (c == NODE_OTHER) { SET_ERRMSG_NUM("E503", _("is not a file or writable device")); goto fail; @@ -2535,7 +2535,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en goto fail; } if (overwriting) { - os_fileinfo((char *)fname, &file_info_old); + os_fileinfo(fname, &file_info_old); } } #endif // !UNIX @@ -2572,7 +2572,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en // If 'backupskip' is not empty, don't make a backup for some files. dobackup = (p_wb || p_bk || *p_pm != NUL); - if (dobackup && *p_bsk != NUL && match_file_list((char *)p_bsk, sfname, ffname)) { + if (dobackup && *p_bsk != NUL && match_file_list(p_bsk, sfname, ffname)) { dobackup = false; } @@ -4130,8 +4130,9 @@ static int get_fio_flags(const char *name) /// /// @return the name of the encoding and set "*lenp" to the length or, /// NULL when no BOM found. -static char *check_for_bom(const char_u *p, long size, int *lenp, int flags) +static char *check_for_bom(const char *p_in, long size, int *lenp, int flags) { + const uint8_t *p = (const uint8_t *)p_in; char *name = NULL; int len = 2; @@ -4647,7 +4648,7 @@ int vim_rename(const char *from, const char *to) to = from; } #ifndef UNIX // For Unix os_open() already set the permission. - os_setperm((const char *)to, perm); + os_setperm(to, perm); #endif #ifdef HAVE_ACL os_set_acl(to, acl); @@ -5156,11 +5157,11 @@ void write_lnum_adjust(linenr_T offset) #if defined(BACKSLASH_IN_FILENAME) /// Convert all backslashes in fname to forward slashes in-place, /// unless when it looks like a URL. -void forward_slash(char_u *fname) +void forward_slash(char *fname) { - char_u *p; + char *p; - if (path_with_url((const char *)fname)) { + if (path_with_url(fname)) { return; } for (p = fname; *p != NUL; p++) { diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 842b0b10b6..d993d65dc0 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -151,11 +151,11 @@ void free_buff(buffheader_T *buf) /// K_SPECIAL in the returned string is escaped. /// /// @param dozero count == zero is not an error -static char_u *get_buffcont(buffheader_T *buffer, int dozero) +static char *get_buffcont(buffheader_T *buffer, int dozero) { size_t count = 0; - char_u *p = NULL; - char_u *p2; + char *p = NULL; + char *p2; // compute the total length of the string for (const buffblock_T *bp = buffer->bh_first.b_next; @@ -168,7 +168,7 @@ static char_u *get_buffcont(buffheader_T *buffer, int dozero) p2 = p; for (const buffblock_T *bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next) { - for (const char_u *str = (char_u *)bp->b_str; *str;) { + for (const char *str = bp->b_str; *str;) { *p2++ = *str++; } } @@ -185,7 +185,7 @@ char_u *get_recorded(void) char *p; size_t len; - p = (char *)get_buffcont(&recordbuff, true); + p = get_buffcont(&recordbuff, true); free_buff(&recordbuff); // Remove the characters that were added the last time, these must be the @@ -207,7 +207,7 @@ char_u *get_recorded(void) /// Return the contents of the redo buffer as a single string. /// K_SPECIAL in the returned string is escaped. -char_u *get_inserted(void) +char *get_inserted(void) { return get_buffcont(&redobuff, false); } @@ -475,7 +475,7 @@ void saveRedobuff(save_redo_T *save_redo) old_redobuff.bh_first.b_next = NULL; // Make a copy, so that ":normal ." in a function works. - char *const s = (char *)get_buffcont(&save_redo->sr_redobuff, false); + char *const s = get_buffcont(&save_redo->sr_redobuff, false); if (s == NULL) { return; } diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 7da8d12f4b..df4ae05522 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -806,8 +806,8 @@ enum { extern char *default_vim_dir; extern char *default_vimruntime_dir; extern char *default_lib_dir; -extern char_u *compiled_user; -extern char_u *compiled_sys; +extern char *compiled_user; +extern char *compiled_sys; #endif // When a window has a local directory, the absolute path of the global diff --git a/src/nvim/help.c b/src/nvim/help.c index 91fda60859..bbc552fa4c 100644 --- a/src/nvim/help.c +++ b/src/nvim/help.c @@ -555,7 +555,7 @@ int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep // Sort the matches found on the heuristic number that is after the // tag name. qsort((void *)(*matches), (size_t)(*num_matches), - sizeof(char_u *), help_compare); + sizeof(char *), help_compare); // Delete more than TAG_MANY to reduce the size of the listing. while (*num_matches > TAG_MANY) { xfree((*matches)[--*num_matches]); @@ -799,7 +799,7 @@ void fix_help_buffer(void) // The text is utf-8 when a byte // above 127 is found and no // illegal byte sequence is found. - if ((char_u)(*s) >= 0x80 && this_utf != kFalse) { + if ((uint8_t)(*s) >= 0x80 && this_utf != kFalse) { this_utf = kTrue; const int l = utf_ptr2len(s); if (l == 1) { @@ -923,7 +923,7 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool // If using the "++t" argument or generating tags for "$VIMRUNTIME/doc" // add the "help-tags" tag. - ga_init(&ga, (int)sizeof(char_u *), 100); + ga_init(&ga, (int)sizeof(char *), 100); if (add_help_tags || path_full_compare("$VIMRUNTIME/doc", dir, false, true) == kEqualFiles) { size_t s_len = 18 + strlen(tagfname); @@ -948,7 +948,7 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool // Detect utf-8 file by a non-ASCII char in the first line. TriState this_utf8 = kNone; for (s = IObuff; *s != NUL; s++) { - if ((char_u)(*s) >= 0x80) { + if ((uint8_t)(*s) >= 0x80) { this_utf8 = kTrue; const int l = utf_ptr2len(s); if (l == 1) { diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 5f7e41e6e0..5d34b48816 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -1069,7 +1069,7 @@ void do_highlight(const char *line, const bool forceit, const bool init) } memcpy(key, key_start, key_len); key[key_len] = NUL; - vim_strup((char_u *)key); + vim_strup(key); linep = (const char *)skipwhite(linep); if (strcmp(key, "NONE") == 0) { @@ -1793,7 +1793,7 @@ int syn_name2id_len(const char *name, size_t len) // Avoid alloc()/free(), these are slow too. memcpy(name_u, name, len); name_u[len] = '\0'; - vim_strup((char_u *)name_u); + vim_strup(name_u); // map_get(..., int) returns 0 when no key is present, which is // the expected value for missing highlight group. @@ -1906,7 +1906,7 @@ static int syn_add_group(const char *name, size_t len) hlgp->sg_parent = scoped_parent; // will get set to false by caller if settings are added hlgp->sg_cleared = true; - vim_strup((char_u *)hlgp->sg_name_u); + vim_strup(hlgp->sg_name_u); int id = highlight_ga.ga_len; // ID is index plus one diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index a8af8ec966..7f81731b26 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -2951,7 +2951,7 @@ static void get_next_dict_tsr_completion(int compl_type, char *dict, int dict_f) } else { ins_compl_dictionaries(dict != NULL ? dict : (compl_type == CTRL_X_THESAURUS - ? (*curbuf->b_p_tsr == NUL ? (char *)p_tsr : curbuf->b_p_tsr) + ? (*curbuf->b_p_tsr == NUL ? p_tsr : curbuf->b_p_tsr) : (*curbuf->b_p_dict == NUL ? p_dict : curbuf->b_p_dict)), compl_pattern, diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c index 552dec6bf8..e19806e464 100644 --- a/src/nvim/keycodes.c +++ b/src/nvim/keycodes.c @@ -474,7 +474,7 @@ char_u *get_special_key_name(int c, int modifiers) int i, idx; int table_idx; - char_u *s; + char *s; string[0] = '<'; idx = 1; @@ -541,9 +541,9 @@ char_u *get_special_key_name(int c, int modifiers) } else if (vim_isprintc(c)) { string[idx++] = (char_u)c; } else { - s = (char_u *)transchar(c); + s = transchar(c); while (*s) { - string[idx++] = *s++; + string[idx++] = (uint8_t)(*s++); } } } @@ -629,11 +629,11 @@ int find_special_key(const char **const srcp, const size_t src_len, int *const m const int flags, bool *const did_simplify) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1, 3) { - const char_u *last_dash; - const char_u *end_of_name; - const char_u *src; - const char_u *bp; - const char_u *const end = (char_u *)(*srcp) + src_len - 1; + const char *last_dash; + const char *end_of_name; + const char *src; + const char *bp; + const char *const end = *srcp + src_len - 1; const bool in_string = flags & FSK_IN_STRING; int modifiers; int bit; @@ -645,7 +645,7 @@ int find_special_key(const char **const srcp, const size_t src_len, int *const m return 0; } - src = (char_u *)(*srcp); + src = *srcp; if (src[0] != '<') { return 0; } @@ -659,7 +659,7 @@ int find_special_key(const char **const srcp, const size_t src_len, int *const m if (*bp == '-') { last_dash = bp; if (bp + 1 <= end) { - l = utfc_ptr2len_len((char *)bp + 1, (int)(end - bp) + 1); + l = utfc_ptr2len_len(bp + 1, (int)(end - bp) + 1); // Anything accepted, like . // or are not special in strings as " is // the string delimiter. With a backslash it works: @@ -674,7 +674,7 @@ int find_special_key(const char **const srcp, const size_t src_len, int *const m if (end - bp > 3 && bp[0] == 't' && bp[1] == '_') { bp += 3; // skip t_xx, xx may be '-' or '>' } else if (end - bp > 4 && STRNICMP(bp, "char-", 5) == 0) { - vim_str2nr((char *)bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0, true); + vim_str2nr(bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0, true); if (l == 0) { emsg(_(e_invarg)); return 0; @@ -691,7 +691,7 @@ int find_special_key(const char **const srcp, const size_t src_len, int *const m modifiers = 0x0; for (bp = src + 1; bp < last_dash; bp++) { if (*bp != '-') { - bit = name_to_mod_mask(*bp); + bit = name_to_mod_mask((uint8_t)(*bp)); if (bit == 0x0) { break; // Illegal modifier name } @@ -704,7 +704,7 @@ int find_special_key(const char **const srcp, const size_t src_len, int *const m if (STRNICMP(last_dash + 1, "char-", 5) == 0 && ascii_isdigit(last_dash[6])) { // or or - vim_str2nr((char *)last_dash + 6, NULL, &l, STR2NR_ALL, NULL, &n, 0, true); + vim_str2nr(last_dash + 6, NULL, &l, STR2NR_ALL, NULL, &n, 0, true); if (l == 0) { emsg(_(e_invarg)); return 0; @@ -718,12 +718,12 @@ int find_special_key(const char **const srcp, const size_t src_len, int *const m // Special case for a double-quoted string off = l = 2; } else { - l = utfc_ptr2len((char *)last_dash + 1); + l = utfc_ptr2len(last_dash + 1); } if (modifiers != 0 && last_dash[l + 1] == '>') { - key = utf_ptr2char((char *)last_dash + off); + key = utf_ptr2char(last_dash + off); } else { - key = get_special_key_code(last_dash + off); + key = get_special_key_code((char_u *)last_dash + off); if (!(flags & FSK_KEEP_X_KEY)) { key = handle_x_keys(key); } @@ -753,7 +753,7 @@ int find_special_key(const char **const srcp, const size_t src_len, int *const m } *modp = modifiers; - *srcp = (char *)end_of_name; + *srcp = end_of_name; return key; } // else { ELOG("unknown key: '%s'", src); } } diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 7006c1dc4e..5ffd90fddd 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1440,11 +1440,11 @@ int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name) estack_push(ETYPE_SCRIPT, name, 0); garray_T ga; - char_u *line = NULL; + char *line = NULL; - ga_init(&ga, (int)sizeof(char_u *), 10); - while ((line = (char_u *)fgetline(0, cookie, 0, false)) != NULL) { - GA_APPEND(char_u *, &ga, line); + ga_init(&ga, (int)sizeof(char *), 10); + while ((line = fgetline(0, cookie, 0, false)) != NULL) { + GA_APPEND(char *, &ga, line); } char *code = ga_concat_strings_sep(&ga, "\n"); size_t len = strlen(code); @@ -1877,7 +1877,7 @@ int nlua_expand_pat(expand_T *xp, char *pat, int *num_results, char ***results) goto cleanup_array; } - GA_APPEND(char_u *, &result_array, (char_u *)string_to_cstr(v.data.string)); + GA_APPEND(char *, &result_array, string_to_cstr(v.data.string)); } xp->xp_pattern += prefix_len; @@ -1914,7 +1914,7 @@ bool nlua_is_table_from_lua(const typval_T *const arg) } } -char_u *nlua_register_table_as_callable(const typval_T *const arg) +char *nlua_register_table_as_callable(const typval_T *const arg) { LuaRef table_ref = LUA_NOREF; if (arg->v_type == VAR_DICT) { @@ -1950,7 +1950,7 @@ char_u *nlua_register_table_as_callable(const typval_T *const arg) LuaRef func = nlua_ref_global(lstate, -1); - char_u *name = (char_u *)register_luafunc(func); + char *name = register_luafunc(func); lua_pop(lstate, 1); // [] assert(top == lua_gettop(lstate)); @@ -1960,8 +1960,8 @@ char_u *nlua_register_table_as_callable(const typval_T *const arg) void nlua_execute_on_key(int c) { - char_u buf[NUMBUFLEN]; - size_t buf_len = special_to_buf(c, mod_mask, false, buf); + char buf[NUMBUFLEN]; + size_t buf_len = special_to_buf(c, mod_mask, false, (char_u *)buf); lua_State *const lstate = global_lstate; @@ -1977,7 +1977,7 @@ void nlua_execute_on_key(int c) luaL_checktype(lstate, -1, LUA_TFUNCTION); // [ vim, vim._on_key, buf ] - lua_pushlstring(lstate, (const char *)buf, buf_len); + lua_pushlstring(lstate, buf, buf_len); int save_got_int = got_int; got_int = false; // avoid interrupts when the key typed is Ctrl-C diff --git a/src/nvim/main.c b/src/nvim/main.c index 4dfb00f2db..62af56e972 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -765,7 +765,7 @@ void getout(int exitval) // Apply 'titleold'. if (p_title && *p_titleold != NUL) { - ui_call_set_title(cstr_as_string((char *)p_titleold)); + ui_call_set_title(cstr_as_string(p_titleold)); } if (garbage_collect_at_exit) { @@ -1509,7 +1509,7 @@ static void handle_quickfix(mparm_T *paramp) set_string_option_direct("ef", -1, paramp->use_ef, OPT_FREE, SID_CARG); } vim_snprintf(IObuff, IOSIZE, "cfile %s", p_ef); - if (qf_init(NULL, (char *)p_ef, p_efm, true, IObuff, p_menc) < 0) { + if (qf_init(NULL, p_ef, p_efm, true, IObuff, p_menc) < 0) { msg_putchar('\n'); os_exit(3); } diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 63f3b02feb..441bbc4b58 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -406,9 +406,9 @@ int bomb_size(void) } // Remove all BOM from "s" by moving remaining text. -void remove_bom(char_u *s) +void remove_bom(char *s) { - char *p = (char *)s; + char *p = s; while ((p = strchr(p, 0xef)) != NULL) { if ((uint8_t)p[1] == 0xbb && (uint8_t)p[2] == 0xbf) { @@ -566,8 +566,8 @@ size_t mb_string2cells(const char *str) { size_t clen = 0; - for (const char_u *p = (char_u *)str; *p != NUL; p += utfc_ptr2len((char *)p)) { - clen += (size_t)utf_ptr2cells((char *)p); + for (const char *p = str; *p != NUL; p += utfc_ptr2len(p)) { + clen += (size_t)utf_ptr2cells(p); } return clen; @@ -1534,14 +1534,14 @@ void show_utf8(void) { int len; int rlen = 0; - char_u *line; + char *line; int clen; int i; // Get the byte length of the char under the cursor, including composing // characters. - line = (char_u *)get_cursor_pos_ptr(); - len = utfc_ptr2len((char *)line); + line = get_cursor_pos_ptr(); + len = utfc_ptr2len(line); if (len == 0) { msg("NUL"); return; @@ -1555,10 +1555,10 @@ void show_utf8(void) STRCPY(IObuff + rlen, "+ "); rlen += 2; } - clen = utf_ptr2len((char *)line + i); + clen = utf_ptr2len(line + i); } sprintf(IObuff + rlen, "%02x ", // NOLINT(runtime/printf) - (line[i] == NL) ? NUL : line[i]); // NUL is stored as NL + (line[i] == NL) ? NUL : (uint8_t)line[i]); // NUL is stored as NL clen--; rlen += (int)strlen(IObuff + rlen); if (rlen > IOSIZE - 20) { @@ -1884,7 +1884,7 @@ void utf_find_illegal(void) char *p; int len; vimconv_T vimconv; - char_u *tofree = NULL; + char *tofree = NULL; vimconv.vc_type = CONV_NONE; if (enc_canon_props(curbuf->b_p_fenc) & ENC_8BIT) { @@ -1899,11 +1899,11 @@ void utf_find_illegal(void) p = get_cursor_pos_ptr(); if (vimconv.vc_type != CONV_NONE) { xfree(tofree); - tofree = (char_u *)string_convert(&vimconv, p, NULL); + tofree = string_convert(&vimconv, p, NULL); if (tofree == NULL) { break; } - p = (char *)tofree; + p = tofree; } while (*p != NUL) { @@ -1916,7 +1916,7 @@ void utf_find_illegal(void) } else { int l; - len = (int)(p - (char *)tofree); + len = (int)(p - tofree); for (p = get_cursor_pos_ptr(); *p != NUL && len-- > 0; p += l) { l = utf_ptr2len(p); curwin->w_cursor.col += l; @@ -2024,7 +2024,7 @@ char *mb_prevptr(char *line, char *p) /// following composing characters) counts as one. int mb_charlen(const char *str) { - const char_u *p = (char_u *)str; + const char *p = str; int count; if (p == NULL) { @@ -2032,20 +2032,20 @@ int mb_charlen(const char *str) } for (count = 0; *p != NUL; count++) { - p += utfc_ptr2len((char *)p); + p += utfc_ptr2len(p); } return count; } /// Like mb_charlen() but for a string with specified length. -int mb_charlen_len(const char_u *str, int len) +int mb_charlen_len(const char *str, int len) { - const char_u *p = str; + const char *p = str; int count; for (count = 0; *p != NUL && p < str + len; count++) { - p += utfc_ptr2len((char *)p); + p += utfc_ptr2len(p); } return count; @@ -2196,7 +2196,7 @@ static int enc_alias_search(const char *name) // Get the canonicalized encoding of the current locale. // Returns an allocated string when successful, NULL when not. -char_u *enc_locale(void) +char *enc_locale(void) { int i; char buf[50]; @@ -2256,7 +2256,7 @@ enc_locale_copy_enc: buf[i] = NUL; } - return (char_u *)enc_canonize(buf); + return enc_canonize(buf); } #if defined(HAVE_ICONV) @@ -2269,7 +2269,7 @@ void *my_iconv_open(char *to, char *from) { iconv_t fd; # define ICONV_TESTLEN 400 - char_u tobuf[ICONV_TESTLEN]; + char tobuf[ICONV_TESTLEN]; char *p; size_t tolen; static WorkingStatus iconv_working = kUnknown; @@ -2285,7 +2285,7 @@ void *my_iconv_open(char *to, char *from) // because it's wide-spread. The symptoms are that after outputting // the initial shift state the "to" pointer is NULL and conversion // stops for no apparent reason after about 8160 characters. - p = (char *)tobuf; + p = tobuf; tolen = ICONV_TESTLEN; (void)iconv(fd, NULL, NULL, &p, &tolen); if (p == NULL) { @@ -2305,8 +2305,8 @@ void *my_iconv_open(char *to, char *from) // sequence and set "*unconvlenp" to the length of it. // Returns the converted string in allocated memory. NULL for an error. // If resultlenp is not NULL, sets it to the result length in bytes. -static char_u *iconv_string(const vimconv_T *const vcp, const char_u *str, size_t slen, - size_t *unconvlenp, size_t *resultlenp) +static char *iconv_string(const vimconv_T *const vcp, const char *str, size_t slen, + size_t *unconvlenp, size_t *resultlenp) { const char *from; size_t fromlen; @@ -2314,11 +2314,11 @@ static char_u *iconv_string(const vimconv_T *const vcp, const char_u *str, size_ size_t tolen; size_t len = 0; size_t done = 0; - char_u *result = NULL; - char_u *p; + char *result = NULL; + char *p; int l; - from = (char *)str; + from = str; fromlen = slen; for (;;) { if (len == 0 || ICONV_ERRNO == ICONV_E2BIG) { @@ -2333,7 +2333,7 @@ static char_u *iconv_string(const vimconv_T *const vcp, const char_u *str, size_ result = p; } - to = (char *)result + done; + to = result + done; tolen = len - done - 2; // Avoid a warning for systems with a wrong iconv() prototype by // casting the second argument to void *. @@ -2373,11 +2373,11 @@ static char_u *iconv_string(const vimconv_T *const vcp, const char_u *str, size_ break; } // Not enough room or skipping illegal sequence. - done = (size_t)(to - (char *)result); + done = (size_t)(to - result); } if (resultlenp != NULL && result != NULL) { - *resultlenp = (size_t)(to - (char *)result); + *resultlenp = (size_t)(to - result); } return result; } @@ -2474,14 +2474,13 @@ int convert_setup_ext(vimconv_T *vcp, char *from, bool from_unicode_is_utf8, cha /// When something goes wrong, NULL is returned and "*lenp" is unchanged. char *string_convert(const vimconv_T *const vcp, char *ptr, size_t *lenp) { - return (char *)string_convert_ext(vcp, (char_u *)ptr, lenp, NULL); + return string_convert_ext(vcp, ptr, lenp, NULL); } // Like string_convert(), but when "unconvlenp" is not NULL and there are is // an incomplete sequence at the end it is not converted and "*unconvlenp" is // set to the number of remaining bytes. -char_u *string_convert_ext(const vimconv_T *const vcp, char_u *ptr, size_t *lenp, - size_t *unconvlenp) +char *string_convert_ext(const vimconv_T *const vcp, char *ptr, size_t *lenp, size_t *unconvlenp) { char_u *retval = NULL; char_u *d; @@ -2490,12 +2489,12 @@ char_u *string_convert_ext(const vimconv_T *const vcp, char_u *ptr, size_t *lenp size_t len; if (lenp == NULL) { - len = strlen((char *)ptr); + len = strlen(ptr); } else { len = *lenp; } if (len == 0) { - return (char_u *)xstrdup(""); + return xstrdup(""); } switch (vcp->vc_type) { @@ -2503,7 +2502,7 @@ char_u *string_convert_ext(const vimconv_T *const vcp, char_u *ptr, size_t *lenp retval = xmalloc(len * 2 + 1); d = retval; for (size_t i = 0; i < len; i++) { - c = ptr[i]; + c = (uint8_t)ptr[i]; if (c < 0x80) { *d++ = (char_u)c; } else { @@ -2521,7 +2520,7 @@ char_u *string_convert_ext(const vimconv_T *const vcp, char_u *ptr, size_t *lenp retval = xmalloc(len * 3 + 1); d = retval; for (size_t i = 0; i < len; i++) { - c = ptr[i]; + c = (uint8_t)ptr[i]; switch (c) { case 0xa4: c = 0x20ac; break; // euro @@ -2553,11 +2552,11 @@ char_u *string_convert_ext(const vimconv_T *const vcp, char_u *ptr, size_t *lenp retval = xmalloc(len + 1); d = retval; for (size_t i = 0; i < len; i++) { - l = utf_ptr2len_len((char *)ptr + i, (int)(len - i)); + l = utf_ptr2len_len(ptr + i, (int)(len - i)); if (l == 0) { *d++ = NUL; } else if (l == 1) { - uint8_t l_w = utf8len_tab_zero[ptr[i]]; + uint8_t l_w = utf8len_tab_zero[(uint8_t)ptr[i]]; if (l_w == 0) { // Illegal utf-8 byte cannot be converted @@ -2569,9 +2568,9 @@ char_u *string_convert_ext(const vimconv_T *const vcp, char_u *ptr, size_t *lenp *unconvlenp = len - i; break; } - *d++ = ptr[i]; + *d++ = (uint8_t)ptr[i]; } else { - c = utf_ptr2char((char *)ptr + i); + c = utf_ptr2char(ptr + i); if (vcp->vc_type == CONV_TO_LATIN9) { switch (c) { case 0x20ac: @@ -2625,12 +2624,12 @@ char_u *string_convert_ext(const vimconv_T *const vcp, char_u *ptr, size_t *lenp #ifdef HAVE_ICONV case CONV_ICONV: // conversion with vcp->vc_fd - retval = iconv_string(vcp, ptr, len, unconvlenp, lenp); + retval = (char_u *)iconv_string(vcp, ptr, len, unconvlenp, lenp); break; #endif } - return retval; + return (char *)retval; } /// Table set by setcellwidths(). diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 798ea4f990..58a18ca5a8 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3474,7 +3474,7 @@ static void nv_ident(cmdarg_T *cap) // Allocate buffer to put the command in. Inserting backslashes can // double the length of the word. p_kp / curbuf->b_p_kp could be added // and some numbers. - char *kp = *curbuf->b_p_kp == NUL ? (char *)p_kp : curbuf->b_p_kp; // 'keywordprg' + char *kp = *curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp; // 'keywordprg' bool kp_help = (*kp == NUL || strcmp(kp, ":he") == 0 || strcmp(kp, ":help") == 0); if (kp_help && *skipwhite(ptr) == NUL) { emsg(_(e_noident)); // found white space only diff --git a/src/nvim/ops.c b/src/nvim/ops.c index e08cd082d9..ac4116095f 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5222,12 +5222,11 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str, } } else { size_t line_len; - for (const char_u *start = (char_u *)str, *end = (char_u *)str + len; + for (const char *start = str, *end = str + len; start < end + extraline; start += line_len + 1, lnum++) { assert(end - start >= 0); - line_len = (size_t)((char_u *)xmemscan(start, '\n', - (size_t)(end - start)) - start); + line_len = (size_t)((char *)xmemscan(start, '\n', (size_t)(end - start)) - start); if (line_len > maxlen) { maxlen = line_len; } diff --git a/src/nvim/option.c b/src/nvim/option.c index 2bd3dcfe2d..268a1514c8 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -381,12 +381,12 @@ void set_init_1(bool clean_arg) // enc_locale() will try to find the encoding of the current locale. // This will be used when 'default' is used as encoding specifier // in 'fileencodings' - char_u *p = enc_locale(); + char *p = enc_locale(); if (p == NULL) { // use utf-8 as 'default' if locale encoding can't be detected. - p = (char_u *)xmemdupz(S_LEN("utf-8")); + p = xmemdupz(S_LEN("utf-8")); } - fenc_default = (char *)p; + fenc_default = p; #ifdef HAVE_WORKING_LIBINTL // GNU gettext 0.10.37 supports this feature: set the codeset used for @@ -1654,7 +1654,7 @@ static char *option_expand(int opt_idx, char *val) // names. // For 'spellsuggest' expand after "file:". expand_env_esc(val, NameBuff, MAXPATHL, - (char_u **)options[opt_idx].var == &p_tags, false, + (char **)options[opt_idx].var == &p_tags, false, (char_u **)options[opt_idx].var == (char_u **)&p_sps ? "file:" : NULL); if (strcmp(NameBuff, val) == 0) { // they are the same @@ -4034,12 +4034,12 @@ static char_u *get_varp(vimoption_T *p) } /// Get the value of 'equalprg', either the buffer-local one or the global one. -char_u *get_equalprg(void) +char *get_equalprg(void) { if (*curbuf->b_p_ep == NUL) { return p_ep; } - return (char_u *)curbuf->b_p_ep; + return curbuf->b_p_ep; } /// Copy options from one window to another. @@ -4225,7 +4225,7 @@ static void init_buf_opt_idx(void) void buf_copy_options(buf_T *buf, int flags) { int should_copy = true; - char_u *save_p_isk = NULL; // init for GCC + char *save_p_isk = NULL; // init for GCC int did_isk = false; // Skip this when the option defaults have not been set yet. Happens when @@ -4258,7 +4258,7 @@ void buf_copy_options(buf_T *buf, int flags) // (jumping back to a help file with CTRL-T or CTRL-O) bool dont_do_help = ((flags & BCO_NOHELP) && buf->b_help) || buf->b_p_initialized; if (dont_do_help) { // don't free b_p_isk - save_p_isk = (char_u *)buf->b_p_isk; + save_p_isk = buf->b_p_isk; buf->b_p_isk = NULL; } // Always free the allocated strings. If not already initialized, @@ -4453,7 +4453,7 @@ void buf_copy_options(buf_T *buf, int flags) // Don't touch these at all when BCO_NOHELP is used and going from // or to a help buffer. if (dont_do_help) { - buf->b_p_isk = (char *)save_p_isk; + buf->b_p_isk = save_p_isk; if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) { (void)tabstop_set(p_vts, &buf->b_p_vts_array); } else { @@ -4843,7 +4843,7 @@ void ExpandOldSetting(int *num_file, char ***file) // A backslash is required before some characters. This is the reverse of // what happens in do_set(). - char_u *buf = (char_u *)vim_strsave_escaped(var, escape_chars); + char *buf = vim_strsave_escaped(var, escape_chars); #ifdef BACKSLASH_IN_FILENAME // For MS-Windows et al. we don't double backslashes at the start and @@ -4859,7 +4859,7 @@ void ExpandOldSetting(int *num_file, char ***file) } #endif - *file[0] = (char *)buf; + *file[0] = buf; *num_file = 1; } diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index e33e57424b..d190fc5999 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -442,7 +442,7 @@ EXTERN unsigned bo_flags; #define BO_SPELL 0x20000 #define BO_WILD 0x40000 -EXTERN char_u *p_bsk; // 'backupskip' +EXTERN char *p_bsk; // 'backupskip' EXTERN char *p_breakat; // 'breakat' EXTERN char *p_bh; ///< 'bufhidden' EXTERN char *p_bt; ///< 'buftype' @@ -468,7 +468,7 @@ EXTERN long p_columns; // 'columns' EXTERN int p_confirm; // 'confirm' EXTERN char *p_cot; // 'completeopt' #ifdef BACKSLASH_IN_FILENAME -EXTERN char_u *p_csl; // 'completeslash' +EXTERN char *p_csl; // 'completeslash' #endif EXTERN long p_pb; // 'pumblend' EXTERN long p_ph; // 'pumheight' @@ -494,9 +494,9 @@ EXTERN int p_ed; // 'edcompatible' EXTERN char *p_ead; // 'eadirection' EXTERN int p_emoji; // 'emoji' EXTERN int p_ea; // 'equalalways' -EXTERN char_u *p_ep; // 'equalprg' +EXTERN char *p_ep; // 'equalprg' EXTERN int p_eb; // 'errorbells' -EXTERN char_u *p_ef; // 'errorfile' +EXTERN char *p_ef; // 'errorfile' EXTERN char *p_efm; // 'errorformat' EXTERN char *p_gefm; // 'grepformat' EXTERN char *p_gp; // 'grepprg' @@ -531,12 +531,12 @@ EXTERN unsigned fdo_flags; EXTERN char *p_fex; ///< 'formatexpr' EXTERN char *p_flp; ///< 'formatlistpat' EXTERN char *p_fo; ///< 'formatoptions' -EXTERN char_u *p_fp; // 'formatprg' +EXTERN char *p_fp; // 'formatprg' EXTERN int p_fs; // 'fsync' EXTERN int p_gd; // 'gdefault' EXTERN char *p_guicursor; // 'guicursor' -EXTERN char_u *p_guifont; // 'guifont' -EXTERN char_u *p_guifontwide; // 'guifontwide' +EXTERN char *p_guifont; // 'guifont' +EXTERN char *p_guifontwide; // 'guifontwide' EXTERN char *p_hf; // 'helpfile' EXTERN long p_hh; // 'helpheight' EXTERN char *p_hlg; // 'helplang' @@ -568,12 +568,12 @@ EXTERN unsigned jop_flags; #define JOP_STACK 0x01 #define JOP_VIEW 0x02 EXTERN char *p_keymap; ///< 'keymap' -EXTERN char_u *p_kp; // 'keywordprg' +EXTERN char *p_kp; // 'keywordprg' EXTERN char *p_km; // 'keymodel' EXTERN char *p_langmap; // 'langmap' EXTERN int p_lnr; // 'langnoremap' EXTERN int p_lrm; // 'langremap' -EXTERN char_u *p_lm; // 'langmenu' +EXTERN char *p_lm; // 'langmenu' EXTERN long p_lines; // 'lines' EXTERN long p_linespace; // 'linespace' EXTERN int p_lisp; ///< 'lisp' @@ -588,7 +588,7 @@ EXTERN int p_lpl; // 'loadplugins' EXTERN int p_magic; // 'magic' EXTERN char *p_menc; // 'makeencoding' EXTERN char *p_mef; // 'makeef' -EXTERN char_u *p_mp; // 'makeprg' +EXTERN char *p_mp; // 'makeprg' EXTERN char *p_mps; ///< 'matchpairs' EXTERN long p_mat; // 'matchtime' EXTERN long p_mco; // 'maxcombine' @@ -613,13 +613,13 @@ EXTERN long p_mouset; // 'mousetime' EXTERN int p_more; // 'more' EXTERN char *p_nf; ///< 'nrformats' EXTERN char *p_opfunc; // 'operatorfunc' -EXTERN char_u *p_para; // 'paragraphs' +EXTERN char *p_para; // 'paragraphs' EXTERN int p_paste; // 'paste' EXTERN char *p_pt; // 'pastetoggle' EXTERN char *p_pex; // 'patchexpr' EXTERN char *p_pm; // 'patchmode' -EXTERN char_u *p_path; // 'path' -EXTERN char_u *p_cdpath; // 'cdpath' +EXTERN char *p_path; // 'path' +EXTERN char *p_cdpath; // 'cdpath' EXTERN int p_pi; ///< 'preserveindent' EXTERN long p_pyx; // 'pyxversion' EXTERN char *p_qe; ///< 'quoteescape' @@ -673,11 +673,11 @@ EXTERN unsigned ssop_flags; #define SSOP_SKIP_RTP 0x20000 EXTERN char *p_sh; // 'shell' -EXTERN char_u *p_shcf; // 'shellcmdflag' +EXTERN char *p_shcf; // 'shellcmdflag' EXTERN char *p_sp; // 'shellpipe' EXTERN char *p_shq; // 'shellquote' EXTERN char *p_sxq; // 'shellxquote' -EXTERN char_u *p_sxe; // 'shellxescape' +EXTERN char *p_sxe; // 'shellxescape' EXTERN char *p_srr; // 'shellredir' EXTERN int p_stmp; // 'shelltemp' #ifdef BACKSLASH_IN_FILENAME @@ -725,7 +725,7 @@ EXTERN unsigned int spo_flags; EXTERN char *p_sps; // 'spellsuggest' EXTERN int p_spr; // 'splitright' EXTERN int p_sol; // 'startofline' -EXTERN char_u *p_su; // 'suffixes' +EXTERN char *p_su; // 'suffixes' EXTERN char *p_swb; // 'switchbuf' EXTERN unsigned swb_flags; // Keep in sync with p_swb_values in optionstr.c @@ -747,7 +747,7 @@ EXTERN unsigned tc_flags; ///< flags from 'tagcase' #define TC_SMART 0x10 EXTERN long p_tl; ///< 'taglength' EXTERN int p_tr; ///< 'tagrelative' -EXTERN char_u *p_tags; ///< 'tags' +EXTERN char *p_tags; ///< 'tags' EXTERN int p_tgst; ///< 'tagstack' EXTERN int p_tbidi; ///< 'termbidi' EXTERN long p_tw; ///< 'textwidth' @@ -756,13 +756,13 @@ EXTERN int p_timeout; ///< 'timeout' EXTERN long p_tm; ///< 'timeoutlen' EXTERN int p_title; ///< 'title' EXTERN long p_titlelen; ///< 'titlelen' -EXTERN char_u *p_titleold; ///< 'titleold' +EXTERN char *p_titleold; ///< 'titleold' EXTERN char *p_titlestring; ///< 'titlestring' -EXTERN char_u *p_tsr; ///< 'thesaurus' +EXTERN char *p_tsr; ///< 'thesaurus' EXTERN int p_tgc; ///< 'termguicolors' EXTERN int p_ttimeout; ///< 'ttimeout' EXTERN long p_ttm; ///< 'ttimeoutlen' -EXTERN char_u *p_udir; ///< 'undodir' +EXTERN char *p_udir; ///< 'undodir' EXTERN int p_udf; ///< 'undofile' EXTERN long p_ul; ///< 'undolevels' EXTERN long p_ur; ///< 'undoreload' @@ -778,15 +778,15 @@ EXTERN unsigned vop_flags; ///< uses SSOP_ flags EXTERN int p_vb; ///< 'visualbell' EXTERN char *p_ve; ///< 'virtualedit' EXTERN unsigned ve_flags; -#define VE_BLOCK 5U // includes "all" -#define VE_INSERT 6U // includes "all" +#define VE_BLOCK 5U // includes "all" +#define VE_INSERT 6U // includes "all" #define VE_ALL 4U #define VE_ONEMORE 8U -#define VE_NONE 16U // "none" -#define VE_NONEU 32U // "NONE" +#define VE_NONE 16U // "none" +#define VE_NONEU 32U // "NONE" EXTERN long p_verbose; // 'verbose' #ifdef IN_OPTION_C -char_u *p_vfile = (char_u *)""; // used before options are initialized +char *p_vfile = ""; // used before options are initialized #else extern char *p_vfile; // 'verbosefile' #endif diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 7e4710a2f7..0611de14aa 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -689,7 +689,7 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es #else // cannot expand user's home directory, so don't try var = NULL; - tail = (char_u *)""; // for gcc + tail = ""; // for gcc #endif // UNIX } @@ -697,7 +697,7 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es // 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 = xstrdup(var); + char *p = xstrdup(var); if (mustfree) { xfree(var); diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index ac8a141bbe..f1e2c5440f 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -570,7 +570,7 @@ notfound: char **shell_build_argv(const char *cmd, const char *extra_args) FUNC_ATTR_NONNULL_RET { - size_t argc = tokenize(p_sh, NULL) + (cmd ? tokenize((char *)p_shcf, NULL) : 0); + size_t argc = tokenize(p_sh, NULL) + (cmd ? tokenize(p_shcf, NULL) : 0); char **rv = xmalloc((argc + 4) * sizeof(*rv)); // Split 'shell' @@ -581,7 +581,7 @@ char **shell_build_argv(const char *cmd, const char *extra_args) } if (cmd) { - i += tokenize((char *)p_shcf, rv + i); // Split 'shellcmdflag' + i += tokenize(p_shcf, rv + i); // Split 'shellcmdflag' rv[i++] = shell_xescape_xquote(cmd); // Copy (and escape) `cmd`. } @@ -1332,7 +1332,7 @@ static char *shell_xescape_xquote(const char *cmd) const char *ecmd = cmd; if (*p_sxe != NUL && strcmp(p_sxq, "(") == 0) { - ecmd = vim_strsave_escaped_ext(cmd, (char *)p_sxe, '^', false); + ecmd = vim_strsave_escaped_ext(cmd, p_sxe, '^', false); } size_t ncmd_size = strlen(ecmd) + strlen(p_sxq) * 2 + 1; char *ncmd = xmalloc(ncmd_size); diff --git a/src/nvim/path.c b/src/nvim/path.c index 12087d52bd..513f366a27 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -229,7 +229,7 @@ char *get_past_head(const char *path) #ifdef MSWIN // May skip "c:" - if (is_path_head((char_u *)path)) { + if (is_path_head(path)) { retval = path + 2; } #endif @@ -842,7 +842,7 @@ static bool is_unique(char *maybe_unique, garray_T *gap, int i) // expanding each into their equivalent path(s). static void expand_path_option(char *curdir, garray_T *gap) { - char *path_option = *curbuf->b_p_path == NUL ? (char *)p_path : curbuf->b_p_path; + char *path_option = *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path; char *buf = xmalloc(MAXPATHL); while (*path_option != NUL) { @@ -1461,7 +1461,7 @@ void addfile(garray_T *gap, char *f, int flags) #ifdef FNAME_ILLEGAL // if the file/dir contains illegal characters, don't add it - if (strpbrk((char *)f, FNAME_ILLEGAL) != NULL) { + if (strpbrk(f, FNAME_ILLEGAL) != NULL) { return; } #endif @@ -1824,7 +1824,7 @@ int vim_FullName(const char *fname, char *buf, size_t len, bool force) if (strlen(fname) > (len - 1)) { xstrlcpy(buf, fname, len); // truncate #ifdef MSWIN - slash_adjust((char_u *)buf); + slash_adjust(buf); #endif return FAIL; } @@ -1839,7 +1839,7 @@ int vim_FullName(const char *fname, char *buf, size_t len, bool force) xstrlcpy(buf, fname, len); // something failed; use the filename } #ifdef MSWIN - slash_adjust((char_u *)buf); + slash_adjust(buf); #endif return rv; } @@ -1859,7 +1859,7 @@ char *fix_fname(const char *fname) #ifdef UNIX return FullName_save(fname, true); #else - if (!vim_isAbsName((char_u *)fname) + if (!vim_isAbsName((char *)fname) || strstr(fname, "..") != NULL || strstr(fname, "//") != NULL # ifdef BACKSLASH_IN_FILENAME @@ -2124,9 +2124,9 @@ int expand_wildcards_eval(char **pat, int *num_file, char ***file, int flags) if (is_cur_alt_file || *exp_pat == '<') { emsg_off++; - eval_pat = (char *)eval_vars(exp_pat, (char_u *)exp_pat, &usedlen, NULL, &ignored_msg, - NULL, - true); + eval_pat = eval_vars(exp_pat, exp_pat, &usedlen, NULL, &ignored_msg, + NULL, + true); emsg_off--; if (eval_pat != NULL) { star_follows = strcmp(exp_pat + usedlen, "*") == 0; @@ -2241,7 +2241,7 @@ int match_suffix(char *fname) size_t fnamelen = strlen(fname); size_t setsuflen = 0; - for (char *setsuf = (char *)p_su; *setsuf;) { + for (char *setsuf = p_su; *setsuf;) { setsuflen = copy_option_part(&setsuf, suf_buf, MAXSUFLEN, ".,"); if (setsuflen == 0) { char *tail = path_tail(fname); diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 58a7379b63..44daefddc7 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -868,7 +868,7 @@ static int qf_get_nextline(qfstate_T *state) #endif } - remove_bom((char_u *)state->linebuf); + remove_bom(state->linebuf); return QF_OK; } @@ -925,7 +925,7 @@ restofline: // match or no match. fields->valid = true; for (; fmt_ptr != NULL; fmt_ptr = fmt_ptr->next) { - idx = (char_u)fmt_ptr->prefix; + idx = (uint8_t)fmt_ptr->prefix; status = qf_parse_get_fields(linebuf, linelen, fmt_ptr, fields, qfl->qf_multiline, qfl->qf_multiscan, &tail); @@ -5048,8 +5048,8 @@ void ex_cfile(exarg_T *eap) // first error. // :caddfile adds to an existing quickfix list. If there is no // quickfix list then a new list is created. - int res = qf_init(wp, (char *)p_ef, p_efm, (eap->cmdidx != CMD_caddfile - && eap->cmdidx != CMD_laddfile), + int res = qf_init(wp, p_ef, p_efm, (eap->cmdidx != CMD_caddfile + && eap->cmdidx != CMD_laddfile), qf_cmdtitle(*eap->cmdlinep), enc); if (wp != NULL) { qi = GET_LOC_LIST(wp); diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index c2a7dd1011..122f3e2020 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -87,7 +87,7 @@ static int toggle_Magic(int x) #define REGMAGIC 0234 // Utility definitions. -#define UCHARAT(p) ((int)(*(char_u *)(p))) +#define UCHARAT(p) ((int)(*(uint8_t *)(p))) // Used for an error (down from) vim_regcomp(): give the error message, set // rc_did_emsg and return NULL @@ -327,7 +327,7 @@ static int reg_strict; // "[abc" is illegal // uncrustify:off // META[] is used often enough to justify turning it into a table. -static char_u META_flags[] = { +static uint8_t META_flags[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // % & ( ) * + . @@ -677,7 +677,7 @@ static int peekchr(void) // '$' is only magic as the very last char and if it's in front of // either "\|", "\)", "\&", or "\n" if (reg_magic >= MAGIC_OFF) { - char_u *p = (char_u *)regparse + 1; + uint8_t *p = (uint8_t *)regparse + 1; bool is_magic_all = (reg_magic == MAGIC_ALL); // ignore \c \C \m \M \v \V and \Z after '$' @@ -938,7 +938,7 @@ static int read_limits(long *minval, long *maxval) // Sometimes need to save a copy of a line. Since alloc()/free() is very // slow, we keep one allocated piece of memory and only re-allocate it when // it's too small. It's freed in bt_regexec_both() when finished. -static char_u *reg_tofree = NULL; +static uint8_t *reg_tofree = NULL; static unsigned reg_tofreelen; // Structure used to store the execution state of the regex engine. @@ -960,8 +960,8 @@ typedef struct { regmatch_T *reg_match; regmmatch_T *reg_mmatch; - char_u **reg_startp; - char_u **reg_endp; + uint8_t **reg_startp; + uint8_t **reg_endp; lpos_T *reg_startpos; lpos_T *reg_endpos; @@ -973,8 +973,8 @@ typedef struct { // The current match-position is remembered with these variables: linenr_T lnum; ///< line number, relative to first line - char_u *line; ///< start of current line - char_u *input; ///< current input, points into "line" + uint8_t *line; ///< start of current line + uint8_t *input; ///< current input, points into "line" int need_clear_subexpr; ///< subexpressions still need to be cleared int need_clear_zsubexpr; ///< extmatch subexpressions still need to be @@ -1033,8 +1033,8 @@ static char *reg_getline(linenr_T lnum) return ml_get_buf(rex.reg_buf, rex.reg_firstlnum + lnum, false); } -static char_u *reg_startzp[NSUBEXP]; // Workspace to mark beginning -static char_u *reg_endzp[NSUBEXP]; // and end of \z(...\) matches +static uint8_t *reg_startzp[NSUBEXP]; // Workspace to mark beginning +static uint8_t *reg_endzp[NSUBEXP]; // and end of \z(...\) matches static lpos_T reg_startzpos[NSUBEXP]; // idem, beginning pos static lpos_T reg_endzpos[NSUBEXP]; // idem, end pos @@ -1147,7 +1147,7 @@ static bool reg_match_visual(void) } // getvvcol() flushes rex.line, need to get it again - rex.line = (char_u *)reg_getline(rex.lnum); + rex.line = (uint8_t *)reg_getline(rex.lnum); rex.input = rex.line + col; unsigned int cols_u = win_linetabsize(wp, rex.reg_firstlnum + rex.lnum, (char *)rex.line, col); @@ -1219,7 +1219,7 @@ static void cleanup_zsubexpr(void) // Advance rex.lnum, rex.line and rex.input to the next line. static void reg_nextline(void) { - rex.line = (char_u *)reg_getline(++rex.lnum); + rex.line = (uint8_t *)reg_getline(++rex.lnum); rex.input = rex.line; fast_breakcheck(); } @@ -2293,7 +2293,7 @@ static regengine_T nfa_regengine = { static int regexp_engine = 0; #ifdef REGEXP_DEBUG -static char_u regname[][30] = { +static uint8_t regname[][30] = { "AUTOMATIC Regexp Engine", "BACKTRACKING Regexp Engine", "NFA Regexp Engine" @@ -2342,10 +2342,10 @@ regprog_T *vim_regcomp(char *expr_arg, int re_flags) // const int called_emsg_before = called_emsg; if (regexp_engine != BACKTRACKING_ENGINE) { - prog = nfa_regengine.regcomp((char_u *)expr, + prog = nfa_regengine.regcomp((uint8_t *)expr, re_flags + (regexp_engine == AUTOMATIC_ENGINE ? RE_AUTO : 0)); } else { - prog = bt_regengine.regcomp((char_u *)expr, re_flags); + prog = bt_regengine.regcomp((uint8_t *)expr, re_flags); } // Check for error compiling regexp with initial engine. @@ -2370,7 +2370,7 @@ regprog_T *vim_regcomp(char *expr_arg, int re_flags) if (regexp_engine == AUTOMATIC_ENGINE && called_emsg == called_emsg_before) { regexp_engine = BACKTRACKING_ENGINE; report_re_switch(expr); - prog = bt_regengine.regcomp((char_u *)expr, re_flags); + prog = bt_regengine.regcomp((uint8_t *)expr, re_flags); } } @@ -2448,7 +2448,7 @@ static bool vim_regexec_string(regmatch_T *rmp, char *line, colnr_T col, bool nl rex.reg_startpos = NULL; rex.reg_endpos = NULL; - int result = rmp->regprog->engine->regexec_nl(rmp, (char_u *)line, col, nl); + int result = rmp->regprog->engine->regexec_nl(rmp, (uint8_t *)line, col, nl); rmp->regprog->re_in_use = false; // NFA engine aborted because it's very slow, use backtracking engine instead. @@ -2464,7 +2464,7 @@ static bool vim_regexec_string(regmatch_T *rmp, char *line, colnr_T col, bool nl rmp->regprog = vim_regcomp(pat, re_flags); if (rmp->regprog != NULL) { rmp->regprog->re_in_use = true; - result = rmp->regprog->engine->regexec_nl(rmp, (char_u *)line, col, nl); + result = rmp->regprog->engine->regexec_nl(rmp, (uint8_t *)line, col, nl); rmp->regprog->re_in_use = false; } diff --git a/src/nvim/regexp_bt.c b/src/nvim/regexp_bt.c index d8471a7b12..1b32447d77 100644 --- a/src/nvim/regexp_bt.c +++ b/src/nvim/regexp_bt.c @@ -242,17 +242,17 @@ static int prevchr_len; ///< byte length of previous char static int num_complex_braces; ///< Complex \{...} count -static char_u *regcode; ///< Code-emit pointer, or JUST_CALC_SIZE +static uint8_t *regcode; ///< Code-emit pointer, or JUST_CALC_SIZE static long regsize; ///< Code size. static int reg_toolong; ///< true when offset out of range -static char_u had_endbrace[NSUBEXP]; ///< flags, true if end of () found +static uint8_t had_endbrace[NSUBEXP]; ///< flags, true if end of () found static long brace_min[10]; ///< Minimums for complex brace repeats static long brace_max[10]; ///< Maximums for complex brace repeats static int brace_count[10]; ///< Current counts for complex brace repeats static int one_exactly = false; ///< only do one char for EXACTLY // When making changes to classchars also change nfa_classcodes. -static char_u *classchars = (char_u *)".iIkKfFpPsSdDxXoOwWhHaAlLuU"; +static uint8_t *classchars = (uint8_t *)".iIkKfFpPsSdDxXoOwWhHaAlLuU"; static int classcodes[] = { ANY, IDENT, SIDENT, KWORD, SKWORD, FNAME, SFNAME, PRINT, SPRINT, @@ -265,7 +265,7 @@ static int classcodes[] = { // When regcode is set to this value, code is not emitted and size is computed // instead. -#define JUST_CALC_SIZE ((char_u *)-1) +#define JUST_CALC_SIZE ((uint8_t *)-1) // Values for rs_state in regitem_T. typedef enum regstate_E { @@ -290,7 +290,7 @@ typedef enum regstate_E { // Also stores the length of "backpos". typedef struct { union { - char_u *ptr; // rex.input pointer, for single-line regexp + uint8_t *ptr; // rex.input pointer, for single-line regexp lpos_T pos; // rex.input pos, for multi-line regexp } rs_u; int rs_len; @@ -299,7 +299,7 @@ typedef struct { // struct to save start/end pointer/position in for \(\) typedef struct { union { - char_u *ptr; + uint8_t *ptr; lpos_T pos; } se_u; } save_se_T; @@ -320,7 +320,7 @@ typedef struct regbehind_S { typedef struct regitem_S { regstate_T rs_state; // what we are doing, one of RS_ above int16_t rs_no; // submatch nr or BEHIND/NOBEHIND - char_u *rs_scan; // current node in program + uint8_t *rs_scan; // current node in program union { save_se_T sesave; regsave_T regsave; @@ -339,7 +339,7 @@ typedef struct regstar_S { // used to store input position when a BACK was encountered, so that we now if // we made any progress since the last time. typedef struct backpos_S { - char_u *bp_scan; // "scan" where BACK was encountered + uint8_t *bp_scan; // "scan" where BACK was encountered regsave_T bp_pos; // last input position } backpos_T; @@ -411,14 +411,14 @@ static regsave_T behind_pos; // Obtain a second single-byte operand stored after a four bytes operand. #define OPERAND_CMP(p) (p)[7] -static char_u *reg(int paren, int *flagp); +static uint8_t *reg(int paren, int *flagp); #ifdef BT_REGEXP_DUMP -static void regdump(char_u *, bt_regprog_T *); +static void regdump(uint8_t *, bt_regprog_T *); #endif #ifdef REGEXP_DEBUG -static char_u *regprop(char_u *); +static uint8_t *regprop(uint8_t *); static int regnarrate = 0; #endif @@ -428,7 +428,7 @@ static int regnarrate = 0; #endif // Setup to parse the regexp. Used once to get the length and once to do it. -static void regcomp_start(char_u *expr, int re_flags) // see vim_regcomp() +static void regcomp_start(uint8_t *expr, int re_flags) // see vim_regcomp() { initchr((char *)expr); if (re_flags & RE_MAGIC) { @@ -466,7 +466,7 @@ static void regc(int b) if (regcode == JUST_CALC_SIZE) { regsize++; } else { - *regcode++ = (char_u)b; + *regcode++ = (uint8_t)b; } } @@ -1453,15 +1453,15 @@ static void reg_equi_class(int c) // Emit a node. // Return pointer to generated code. -static char_u *regnode(int op) +static uint8_t *regnode(int op) { - char_u *ret; + uint8_t *ret; ret = regcode; if (ret == JUST_CALC_SIZE) { regsize += 3; } else { - *regcode++ = (char_u)op; + *regcode++ = (uint8_t)op; *regcode++ = NUL; // Null "next" pointer. *regcode++ = NUL; } @@ -1469,19 +1469,19 @@ static char_u *regnode(int op) } // Write a four bytes number at "p" and return pointer to the next char. -static char_u *re_put_uint32(char_u *p, uint32_t val) +static uint8_t *re_put_uint32(uint8_t *p, uint32_t val) { - *p++ = (char_u)((val >> 24) & 0377); - *p++ = (char_u)((val >> 16) & 0377); - *p++ = (char_u)((val >> 8) & 0377); - *p++ = (char_u)(val & 0377); + *p++ = (uint8_t)((val >> 24) & 0377); + *p++ = (uint8_t)((val >> 16) & 0377); + *p++ = (uint8_t)((val >> 8) & 0377); + *p++ = (uint8_t)(val & 0377); return p; } // regnext - dig the "next" pointer out of a node // Returns NULL when calculating size, when there is no next item and when // there is an error. -static char_u *regnext(char_u *p) +static uint8_t *regnext(uint8_t *p) FUNC_ATTR_NONNULL_ALL { int offset; @@ -1503,7 +1503,7 @@ static char_u *regnext(char_u *p) } // Set the next-pointer at the end of a node chain. -static void regtail(char_u *p, char_u *val) +static void regtail(uint8_t *p, uint8_t *val) { int offset; @@ -1512,9 +1512,9 @@ static void regtail(char_u *p, char_u *val) } // Find last node. - char_u *scan = p; + uint8_t *scan = p; for (;;) { - char_u *temp = regnext(scan); + uint8_t *temp = regnext(scan); if (temp == NULL) { break; } @@ -1532,13 +1532,13 @@ static void regtail(char_u *p, char_u *val) if (offset > 0xffff) { reg_toolong = true; } else { - *(scan + 1) = (char_u)(((unsigned)offset >> 8) & 0377); - *(scan + 2) = (char_u)(offset & 0377); + *(scan + 1) = (uint8_t)(((unsigned)offset >> 8) & 0377); + *(scan + 2) = (uint8_t)(offset & 0377); } } // Like regtail, on item after a BRANCH; nop if none. -static void regoptail(char_u *p, char_u *val) +static void regoptail(uint8_t *p, uint8_t *val) { // When op is neither BRANCH nor BRACE_COMPLEX0-9, it is "operandless" if (p == NULL || p == JUST_CALC_SIZE @@ -1552,11 +1552,11 @@ static void regoptail(char_u *p, char_u *val) // Insert an operator in front of already-emitted operand // // Means relocating the operand. -static void reginsert(int op, char_u *opnd) +static void reginsert(int op, uint8_t *opnd) { - char_u *src; - char_u *dst; - char_u *place; + uint8_t *src; + uint8_t *dst; + uint8_t *place; if (regcode == JUST_CALC_SIZE) { regsize += 3; @@ -1570,18 +1570,18 @@ static void reginsert(int op, char_u *opnd) } place = opnd; // Op node, where operand used to be. - *place++ = (char_u)op; + *place++ = (uint8_t)op; *place++ = NUL; *place = NUL; } // Insert an operator in front of already-emitted operand. // Add a number to the operator. -static void reginsert_nr(int op, long val, char_u *opnd) +static void reginsert_nr(int op, long val, uint8_t *opnd) { - char_u *src; - char_u *dst; - char_u *place; + uint8_t *src; + uint8_t *dst; + uint8_t *place; if (regcode == JUST_CALC_SIZE) { regsize += 7; @@ -1595,7 +1595,7 @@ static void reginsert_nr(int op, long val, char_u *opnd) } place = opnd; // Op node, where operand used to be. - *place++ = (char_u)op; + *place++ = (uint8_t)op; *place++ = NUL; *place++ = NUL; assert(val >= 0 && (uintmax_t)val <= UINT32_MAX); @@ -1606,11 +1606,11 @@ static void reginsert_nr(int op, long val, char_u *opnd) // The operator has the given limit values as operands. Also set next pointer. // // Means relocating the operand. -static void reginsert_limits(int op, long minval, long maxval, char_u *opnd) +static void reginsert_limits(int op, long minval, long maxval, uint8_t *opnd) { - char_u *src; - char_u *dst; - char_u *place; + uint8_t *src; + uint8_t *dst; + uint8_t *place; if (regcode == JUST_CALC_SIZE) { regsize += 11; @@ -1624,7 +1624,7 @@ static void reginsert_limits(int op, long minval, long maxval, char_u *opnd) } place = opnd; // Op node, where operand used to be. - *place++ = (char_u)op; + *place++ = (uint8_t)op; *place++ = NUL; *place++ = NUL; assert(minval >= 0 && (uintmax_t)minval <= UINT32_MAX); @@ -1641,11 +1641,11 @@ static void reginsert_limits(int op, long minval, long maxval, char_u *opnd) static int seen_endbrace(int refnum) { if (!had_endbrace[refnum]) { - char_u *p; + uint8_t *p; // Trick: check if "@<=" or "@ 0 when next '-' is a range int endc; @@ -2460,11 +2460,11 @@ do_multibyte: // both the endmarker for their branch list and the body of the last branch. // It might seem that this node could be dispensed with entirely, but the // endmarker role is not redundant. -static char_u *regpiece(int *flagp) +static uint8_t *regpiece(int *flagp) { - char_u *ret; + uint8_t *ret; int op; - char_u *next; + uint8_t *next; int flags; long minval; long maxval; @@ -2597,11 +2597,11 @@ static char_u *regpiece(int *flagp) // Parse one alternative of an | or & operator. // Implements the concatenation operator. -static char_u *regconcat(int *flagp) +static uint8_t *regconcat(int *flagp) { - char_u *first = NULL; - char_u *chain = NULL; - char_u *latest; + uint8_t *first = NULL; + uint8_t *chain = NULL; + uint8_t *latest; int flags; int cont = true; @@ -2673,11 +2673,11 @@ static char_u *regconcat(int *flagp) // Parse one alternative of an | operator. // Implements the & operator. -static char_u *regbranch(int *flagp) +static uint8_t *regbranch(int *flagp) { - char_u *ret; - char_u *chain = NULL; - char_u *latest; + uint8_t *ret; + uint8_t *chain = NULL; + uint8_t *latest; int flags; *flagp = WORST | HASNL; // Tentatively. @@ -2722,11 +2722,11 @@ static char_u *regbranch(int *flagp) /// follows makes it hard to avoid. /// /// @param paren REG_NOPAREN, REG_PAREN, REG_NPAREN or REG_ZPAREN -static char_u *reg(int paren, int *flagp) +static uint8_t *reg(int paren, int *flagp) { - char_u *ret; - char_u *br; - char_u *ender; + uint8_t *ret; + uint8_t *br; + uint8_t *ender; int parno = 0; int flags; @@ -2840,10 +2840,10 @@ static char_u *reg(int paren, int *flagp) // Beware that the optimization-preparation code in here knows about some // of the structure of the compiled regexp. // "re_flags": RE_MAGIC and/or RE_STRING. -static regprog_T *bt_regcomp(char_u *expr, int re_flags) +static regprog_T *bt_regcomp(uint8_t *expr, int re_flags) { - char_u *scan; - char_u *longest; + uint8_t *scan; + uint8_t *longest; int len; int flags; @@ -2890,7 +2890,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) r->regflags |= RF_LOOKBH; } // Remember whether this pattern has any \z specials in it. - r->reghasz = (char_u)re_has_z; + r->reghasz = (uint8_t)re_has_z; scan = r->program + 1; // First BRANCH. if (OP(regnext(scan)) == END) { // Only one top-level choice. scan = OPERAND(scan); @@ -2908,7 +2908,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) || OP(scan) == NOTHING || OP(scan) == MOPEN + 0 || OP(scan) == NOPEN || OP(scan) == MCLOSE + 0 || OP(scan) == NCLOSE) { - char_u *regnext_scan = regnext(scan); + uint8_t *regnext_scan = regnext(scan); if (OP(regnext_scan) == EXACTLY) { r->regstart = utf_ptr2char((char *)OPERAND(regnext_scan)); } @@ -3014,7 +3014,7 @@ static void reg_restore(regsave_T *save, garray_T *gap) // only call reg_getline() when the line number changed to save // a bit of time rex.lnum = save->rs_u.pos.lnum; - rex.line = (char_u *)reg_getline(rex.lnum); + rex.line = (uint8_t *)reg_getline(rex.lnum); } rex.input = rex.line + save->rs_u.pos.col; } else { @@ -3057,7 +3057,7 @@ static void save_se_multi(save_se_T *savep, lpos_T *posp) posp->col = (colnr_T)(rex.input - rex.line); } -static void save_se_one(save_se_T *savep, char_u **pp) +static void save_se_one(save_se_T *savep, uint8_t **pp) { savep->se_u.ptr = *pp; *pp = rex.input; @@ -3067,14 +3067,14 @@ static void save_se_one(save_se_T *savep, char_u **pp) /// Advances rex.input (and rex.lnum) to just after the matched chars. /// /// @param maxcount maximum number of matches allowed -static int regrepeat(char_u *p, long maxcount) +static int regrepeat(uint8_t *p, long maxcount) { long count = 0; - char_u *opnd; + uint8_t *opnd; int mask; int testval = 0; - char_u *scan = rex.input; // Make local copy of rex.input for speed. + uint8_t *scan = rex.input; // Make local copy of rex.input for speed. opnd = OPERAND(p); switch (OP(p)) { case ANY: @@ -3431,7 +3431,7 @@ do_class: // Push an item onto the regstack. // Returns pointer to new item. Returns NULL when out of memory. -static regitem_T *regstack_push(regstate_T state, char_u *scan) +static regitem_T *regstack_push(regstate_T state, uint8_t *scan) { regitem_T *rp; @@ -3450,7 +3450,7 @@ static regitem_T *regstack_push(regstate_T state, char_u *scan) } // Pop an item from the regstack. -static void regstack_pop(char_u **scan) +static void regstack_pop(uint8_t **scan) { regitem_T *rp; @@ -3520,9 +3520,9 @@ static void restore_subexpr(regbehind_T *bp) /// just after the last matched character. /// - false when there is no match. Leaves rex.input and rex.lnum in an /// undefined state! -static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) +static bool regmatch(uint8_t *scan, proftime_T *tm, int *timed_out) { - char_u *next; // Next node. + uint8_t *next; // Next node. int op; int c; regitem_T *rp; @@ -3651,7 +3651,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) // Line may have been freed, get it again. if (REG_MULTI) { - rex.line = (char_u *)reg_getline(rex.lnum); + rex.line = (uint8_t *)reg_getline(rex.lnum); rex.input = rex.line + col; } @@ -3965,7 +3965,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) case EXACTLY: { int len; - char_u *opnd; + uint8_t *opnd; opnd = OPERAND(scan); // Inline the first byte, for speed. @@ -4017,7 +4017,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) case MULTIBYTECODE: { int i, len; - const char_u *opnd = OPERAND(scan); + const uint8_t *opnd = OPERAND(scan); // Safety check (just in case 'encoding' was changed since // compiling the program). if ((len = utfc_ptr2len((char *)opnd)) < 2) { @@ -4703,8 +4703,8 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) (colnr_T)strlen((char *)rex.line); } } else { - const char_u *const line = - (char_u *)reg_getline(rp->rs_un.regsave.rs_u.pos.lnum); + const uint8_t *const line = + (uint8_t *)reg_getline(rp->rs_un.regsave.rs_u.pos.lnum); rp->rs_un.regsave.rs_u.pos.col -= utf_head_off((char *)line, @@ -4786,7 +4786,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out) break; } rex.lnum--; - rex.line = (char_u *)reg_getline(rex.lnum); + rex.line = (uint8_t *)reg_getline(rex.lnum); // Just in case regrepeat() didn't count right. if (rex.line == NULL) { break; @@ -4917,13 +4917,13 @@ static long regtry(bt_regprog_T *prog, colnr_T col, proftime_T *tm, int *timed_o && reg_endzpos[i].lnum == reg_startzpos[i].lnum && reg_endzpos[i].col >= reg_startzpos[i].col) { re_extmatch_out->matches[i] = - (char_u *)xstrnsave((char *)reg_getline(reg_startzpos[i].lnum) + reg_startzpos[i].col, - (size_t)(reg_endzpos[i].col - reg_startzpos[i].col)); + (uint8_t *)xstrnsave((char *)reg_getline(reg_startzpos[i].lnum) + reg_startzpos[i].col, + (size_t)(reg_endzpos[i].col - reg_startzpos[i].col)); } } else { if (reg_startzp[i] != NULL && reg_endzp[i] != NULL) { re_extmatch_out->matches[i] = - (char_u *)xstrnsave((char *)reg_startzp[i], (size_t)(reg_endzp[i] - reg_startzp[i])); + (uint8_t *)xstrnsave((char *)reg_startzp[i], (size_t)(reg_endzp[i] - reg_startzp[i])); } } } @@ -4939,10 +4939,10 @@ static long regtry(bt_regprog_T *prog, colnr_T col, proftime_T *tm, int *timed_o /// @param timed_out flag set on timeout or NULL /// /// @return 0 for failure, or number of lines contained in the match. -static long bt_regexec_both(char_u *line, colnr_T startcol, proftime_T *tm, int *timed_out) +static long bt_regexec_both(uint8_t *line, colnr_T startcol, proftime_T *tm, int *timed_out) { bt_regprog_T *prog; - char_u *s; + uint8_t *s; colnr_T col = startcol; long retval = 0L; @@ -4966,13 +4966,13 @@ static long bt_regexec_both(char_u *line, colnr_T startcol, proftime_T *tm, int if (REG_MULTI) { prog = (bt_regprog_T *)rex.reg_mmatch->regprog; - line = (char_u *)reg_getline((linenr_T)0); + line = (uint8_t *)reg_getline((linenr_T)0); rex.reg_startpos = rex.reg_mmatch->startpos; rex.reg_endpos = rex.reg_mmatch->endpos; } else { prog = (bt_regprog_T *)rex.reg_match->regprog; - rex.reg_startp = (char_u **)rex.reg_match->startp; - rex.reg_endp = (char_u **)rex.reg_match->endp; + rex.reg_startp = (uint8_t **)rex.reg_match->startp; + rex.reg_endp = (uint8_t **)rex.reg_match->endp; } // Be paranoid... @@ -5011,14 +5011,14 @@ static long bt_regexec_both(char_u *line, colnr_T startcol, proftime_T *tm, int // This is used very often, esp. for ":global". Use two versions of // the loop to avoid overhead of conditions. if (!rex.reg_ic) { - while ((s = (char_u *)vim_strchr((char *)s, c)) != NULL) { + while ((s = (uint8_t *)vim_strchr((char *)s, c)) != NULL) { if (cstrncmp((char *)s, (char *)prog->regmust, &prog->regmlen) == 0) { break; // Found it. } MB_PTR_ADV(s); } } else { - while ((s = (char_u *)cstrchr((char *)s, c)) != NULL) { + while ((s = (uint8_t *)cstrchr((char *)s, c)) != NULL) { if (cstrncmp((char *)s, (char *)prog->regmust, &prog->regmlen) == 0) { break; // Found it. } @@ -5053,7 +5053,7 @@ static long bt_regexec_both(char_u *line, colnr_T startcol, proftime_T *tm, int while (!got_int) { if (prog->regstart != NUL) { // Skip until the char we know it must start with. - s = (char_u *)cstrchr((char *)rex.line + col, prog->regstart); + s = (uint8_t *)cstrchr((char *)rex.line + col, prog->regstart); if (s == NULL) { retval = 0; break; @@ -5075,7 +5075,7 @@ static long bt_regexec_both(char_u *line, colnr_T startcol, proftime_T *tm, int // if not currently on the first line, get it again if (rex.lnum != 0) { rex.lnum = 0; - rex.line = (char_u *)reg_getline((linenr_T)0); + rex.line = (uint8_t *)reg_getline((linenr_T)0); } if (rex.line[col] == NUL) { break; @@ -5145,7 +5145,7 @@ theend: /// @param col column to start looking for match /// /// @return 0 for failure, number of lines contained in the match otherwise. -static int bt_regexec_nl(regmatch_T *rmp, char_u *line, colnr_T col, bool line_lbr) +static int bt_regexec_nl(regmatch_T *rmp, uint8_t *line, colnr_T col, bool line_lbr) { rex.reg_match = rmp; rex.reg_mmatch = NULL; @@ -5182,7 +5182,7 @@ static long bt_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T } // Compare a number with the operand of RE_LNUM, RE_COL or RE_VCOL. -static int re_num_cmp(uint32_t val, char_u *scan) +static int re_num_cmp(uint32_t val, uint8_t *scan) { uint32_t n = (uint32_t)OPERAND_MIN(scan); @@ -5198,12 +5198,12 @@ static int re_num_cmp(uint32_t val, char_u *scan) #ifdef BT_REGEXP_DUMP // regdump - dump a regexp onto stdout in vaguely comprehensible form -static void regdump(char_u *pattern, bt_regprog_T *r) +static void regdump(uint8_t *pattern, bt_regprog_T *r) { - char_u *s; + uint8_t *s; int op = EXACTLY; // Arbitrary non-END op. - char_u *next; - char_u *end = NULL; + uint8_t *next; + uint8_t *end = NULL; FILE *f; # ifdef BT_REGEXP_LOG @@ -5284,7 +5284,7 @@ static void regdump(char_u *pattern, bt_regprog_T *r) #ifdef REGEXP_DEBUG // regprop - printable representation of opcode -static char_u *regprop(char_u *op) +static uint8_t *regprop(uint8_t *op) { char *p; static char buf[50]; @@ -5656,6 +5656,6 @@ static char_u *regprop(char_u *op) if (p != NULL) { STRCAT(buf, p); } - return (char_u *)buf; + return (uint8_t *)buf; } #endif // REGEXP_DEBUG diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 83a74b6091..93b03f0632 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -244,10 +244,10 @@ static int nfa_classcodes[] = { NFA_UPPER, NFA_NUPPER }; -static char_u e_nul_found[] = N_("E865: (NFA) Regexp end encountered prematurely"); -static char_u e_misplaced[] = N_("E866: (NFA regexp) Misplaced %c"); -static char_u e_ill_char_class[] = N_("E877: (NFA regexp) Invalid character class: %" PRId64); -static char_u e_value_too_large[] = N_("E951: \\% value too large"); +static char e_nul_found[] = N_("E865: (NFA) Regexp end encountered prematurely"); +static char e_misplaced[] = N_("E866: (NFA regexp) Misplaced %c"); +static char e_ill_char_class[] = N_("E877: (NFA regexp) Invalid character class: %" PRId64); +static char e_value_too_large[] = N_("E951: \\% value too large"); // Since the out pointers in the list are always // uninitialized, we use the pointers themselves @@ -276,8 +276,8 @@ typedef struct { colnr_T end_col; } multi[NSUBEXP]; struct linepos { - char_u *start; - char_u *end; + uint8_t *start; + uint8_t *end; } line[NSUBEXP]; } list; colnr_T orig_start_col; // list.multi[0].start_col without \zs @@ -296,7 +296,7 @@ struct nfa_pim_S { regsubs_T subs; // submatch info, only party used union { lpos_T pos; - char_u *ptr; + uint8_t *ptr; } end; // where the match must end }; @@ -354,7 +354,7 @@ static int nfa_ll_index = 0; /// Initialize internal variables before NFA compilation. /// /// @param re_flags @see vim_regcomp() -static void nfa_regcomp_start(char_u *expr, int re_flags) +static void nfa_regcomp_start(uint8_t *expr, int re_flags) { size_t postfix_size; size_t nstate_max; @@ -519,12 +519,12 @@ static int nfa_get_regstart(nfa_state_T *start, int depth) // Figure out if the NFA state list contains just literal text and nothing // else. If so return a string in allocated memory with what must match after // regstart. Otherwise return NULL. -static char_u *nfa_get_match_text(nfa_state_T *start) +static uint8_t *nfa_get_match_text(nfa_state_T *start) { nfa_state_T *p = start; int len = 0; - char_u *ret; - char_u *s; + uint8_t *ret; + uint8_t *s; if (p->c != NFA_MOPEN) { return NULL; // just in case @@ -571,7 +571,7 @@ static void realloc_post_list(void) // to the closing brace. // Keep in mind that 'ignorecase' applies at execution time, thus [a-z] may // need to be interpreted as [a-zA-Z]. -static int nfa_recognize_char_class(char_u *start, char_u *end, int extra_newl) +static int nfa_recognize_char_class(uint8_t *start, uint8_t *end, int extra_newl) { #define CLASS_not 0x80 #define CLASS_af 0x40 @@ -582,7 +582,7 @@ static int nfa_recognize_char_class(char_u *start, char_u *end, int extra_newl) #define CLASS_o9 0x02 #define CLASS_underscore 0x01 - char_u *p; + uint8_t *p; int config = 0; bool newl = extra_newl == true; @@ -1788,9 +1788,9 @@ static int nfa_regatom(void) int equiclass; int collclass; int got_coll_char; - char_u *p; - char_u *endp; - char_u *old_regparse = (char_u *)regparse; + uint8_t *p; + uint8_t *endp; + uint8_t *old_regparse = (uint8_t *)regparse; int extra = 0; int emit_range; int negated; @@ -1873,7 +1873,7 @@ static int nfa_regatom(void) case Magic('L'): case Magic('u'): case Magic('U'): - p = (char_u *)vim_strchr((char *)classchars, no_Magic(c)); + p = (uint8_t *)vim_strchr((char *)classchars, no_Magic(c)); if (p == NULL) { if (extra == NFA_ADD_NL) { semsg(_(e_ill_char_class), (int64_t)c); @@ -1886,7 +1886,7 @@ static int nfa_regatom(void) // When '.' is followed by a composing char ignore the dot, so that // the composing char is matched here. if (c == Magic('.') && utf_iscomposing(peekchr())) { - old_regparse = (char_u *)regparse; + old_regparse = (uint8_t *)regparse; c = getchr(); goto nfa_do_multibyte; } @@ -1932,7 +1932,7 @@ static int nfa_regatom(void) return FAIL; case Magic('~'): { - char_u *lp; + uint8_t *lp; // Previous substitute pattern. // Generated as "\%(pattern\)". @@ -1940,9 +1940,9 @@ static int nfa_regatom(void) emsg(_(e_nopresub)); return FAIL; } - for (lp = (char_u *)reg_prev_sub; *lp != NUL; MB_CPTR_ADV(lp)) { + for (lp = (uint8_t *)reg_prev_sub; *lp != NUL; MB_CPTR_ADV(lp)) { EMIT(utf_ptr2char((char *)lp)); - if (lp != (char_u *)reg_prev_sub) { + if (lp != (uint8_t *)reg_prev_sub) { EMIT(NFA_CONCAT); } } @@ -2217,13 +2217,13 @@ collection: // - character classes NFA_CLASS_* // - ranges, two characters followed by NFA_RANGE. - p = (char_u *)regparse; - endp = (char_u *)skip_anyof((char *)p); + p = (uint8_t *)regparse; + endp = (uint8_t *)skip_anyof((char *)p); if (*endp == ']') { // Try to reverse engineer character classes. For example, // recognize that [0-9] stands for \d and [A-Za-z_] for \h, // and perform the necessary substitutions in the NFA. - int result = nfa_recognize_char_class((char_u *)regparse, endp, extra == NFA_ADD_NL); + int result = nfa_recognize_char_class((uint8_t *)regparse, endp, extra == NFA_ADD_NL); if (result != FAIL) { if (result >= NFA_FIRST_NL && result <= NFA_LAST_NL) { EMIT(result - NFA_ADD_NL); @@ -2255,7 +2255,7 @@ collection: } // Emit the OR branches for each character in the [] emit_range = false; - while ((char_u *)regparse < endp) { + while ((uint8_t *)regparse < endp) { int oldstartc = startc; startc = -1; got_coll_char = false; @@ -2362,7 +2362,7 @@ collection: // accepts "\t", "\e", etc., but only when the 'l' flag in // 'cpoptions' is not included. if (*regparse == '\\' - && (char_u *)regparse + 1 <= endp + && (uint8_t *)regparse + 1 <= endp && (vim_strchr(REGEXP_INRANGE, (uint8_t)regparse[1]) != NULL || (!reg_cpo_lit && vim_strchr(REGEXP_ABBR, (uint8_t)regparse[1]) @@ -2927,7 +2927,7 @@ static int nfa_reg(int paren) } #ifdef REGEXP_DEBUG -static char_u code[50]; +static uint8_t code[50]; static void nfa_set_code(int c) { @@ -3275,11 +3275,11 @@ static void nfa_set_code(int c) } static FILE *log_fd; -static char_u e_log_open_failed[] = +static uint8_t e_log_open_failed[] = N_("Could not open temporary log file for writing, displaying on stderr... "); // Print the postfix notation of the current regexp. -static void nfa_postfix_dump(char_u *expr, int retval) +static void nfa_postfix_dump(uint8_t *expr, int retval) { int *p; FILE *f; @@ -3321,7 +3321,7 @@ static void nfa_print_state(FILE *debugf, nfa_state_T *state) static void nfa_print_state2(FILE *debugf, nfa_state_T *state, garray_T *indent) { - char_u *p; + uint8_t *p; if (state == NULL) { return; @@ -3330,10 +3330,10 @@ static void nfa_print_state2(FILE *debugf, nfa_state_T *state, garray_T *indent) fprintf(debugf, "(%2d)", abs(state->id)); // Output indent - p = (char_u *)indent->ga_data; + p = (uint8_t *)indent->ga_data; if (indent->ga_len >= 3) { int last = indent->ga_len - 3; - char_u save[2]; + uint8_t save[2]; strncpy(save, &p[last], 2); // NOLINT(runtime/printf) memcpy(&p[last], "+-", 2); @@ -3358,9 +3358,9 @@ static void nfa_print_state2(FILE *debugf, nfa_state_T *state, garray_T *indent) // grow indent for state->out indent->ga_len -= 1; if (state->out1) { - ga_concat(indent, (char_u *)"| "); + ga_concat(indent, (uint8_t *)"| "); } else { - ga_concat(indent, (char_u *)" "); + ga_concat(indent, (uint8_t *)" "); } ga_append(indent, NUL); @@ -3368,7 +3368,7 @@ static void nfa_print_state2(FILE *debugf, nfa_state_T *state, garray_T *indent) // replace last part of indent for state->out1 indent->ga_len -= 3; - ga_concat(indent, (char_u *)" "); + ga_concat(indent, (uint8_t *)" "); ga_append(indent, NUL); nfa_print_state2(debugf, state->out1, indent); @@ -4493,8 +4493,8 @@ static bool sub_equal(regsub_T *sub1, regsub_T *sub2) int todo; linenr_T s1; linenr_T s2; - char_u *sp1; - char_u *sp2; + uint8_t *sp1; + uint8_t *sp2; todo = sub1->in_use > sub2->in_use ? sub1->in_use : sub2->in_use; if (REG_MULTI) { @@ -4789,7 +4789,7 @@ static regsubs_T *addstate(nfa_list_T *l, nfa_state_T *state, regsubs_T *subs_ar nfa_thread_T *thread; struct multipos save_multipos; int save_in_use; - char_u *save_ptr; + uint8_t *save_ptr; int i; regsub_T *sub; regsubs_T *subs = subs_arg; @@ -5532,10 +5532,10 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T // bytes if possible. if (state->val <= 0) { if (REG_MULTI) { - rex.line = (char_u *)reg_getline(--rex.lnum); + rex.line = (uint8_t *)reg_getline(--rex.lnum); if (rex.line == NULL) { // can't go before the first line - rex.line = (char_u *)reg_getline(++rex.lnum); + rex.line = (uint8_t *)reg_getline(++rex.lnum); } } rex.input = rex.line; @@ -5543,10 +5543,10 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T if (REG_MULTI && (int)(rex.input - rex.line) < state->val) { // Not enough bytes in this line, go to end of // previous line. - rex.line = (char_u *)reg_getline(--rex.lnum); + rex.line = (uint8_t *)reg_getline(--rex.lnum); if (rex.line == NULL) { // can't go before the first line - rex.line = (char_u *)reg_getline(++rex.lnum); + rex.line = (uint8_t *)reg_getline(++rex.lnum); rex.input = rex.line; } else { rex.input = rex.line + strlen((char *)rex.line); @@ -5605,7 +5605,7 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T // restore position in input text rex.lnum = save_reglnum; if (REG_MULTI) { - rex.line = (char_u *)reg_getline(rex.lnum); + rex.line = (uint8_t *)reg_getline(rex.lnum); } rex.input = rex.line + save_reginput_col; if (result != NFA_TOO_EXPENSIVE) { @@ -5782,7 +5782,7 @@ static int failure_chance(nfa_state_T *state, int depth) // Skip until the char "c" we know a match must start with. static int skip_to_start(int c, colnr_T *colp) { - const char_u *const s = (char_u *)cstrchr((char *)rex.line + *colp, c); + const uint8_t *const s = (uint8_t *)cstrchr((char *)rex.line + *colp, c); if (s == NULL) { return FAIL; } @@ -5793,7 +5793,7 @@ static int skip_to_start(int c, colnr_T *colp) // Check for a match with match_text. // Called after skip_to_start() has found regstart. // Returns zero for no match, 1 for a match. -static long find_match_text(colnr_T *startcol, int regstart, char_u *match_text) +static long find_match_text(colnr_T *startcol, int regstart, uint8_t *match_text) { #define PTR2LEN(x) utf_ptr2len(x) @@ -5802,8 +5802,8 @@ static long find_match_text(colnr_T *startcol, int regstart, char_u *match_text) for (;;) { bool match = true; - char_u *s1 = match_text; - char_u *s2 = rex.line + col + regstart_len; // skip regstart + uint8_t *s1 = match_text; + uint8_t *s2 = rex.line + col + regstart_len; // skip regstart while (*s1) { int c1_len = PTR2LEN((char *)s1); int c1 = utf_ptr2char((char *)s1); @@ -6870,7 +6870,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm // Line may have been freed, get it again. if (REG_MULTI) { - rex.line = (char_u *)reg_getline(rex.lnum); + rex.line = (uint8_t *)reg_getline(rex.lnum); rex.input = rex.line + col; } @@ -7308,15 +7308,15 @@ static long nfa_regtry(nfa_regprog_T *prog, colnr_T col, proftime_T *tm, int *ti && mpos->start_lnum == mpos->end_lnum && mpos->end_col >= mpos->start_col) { re_extmatch_out->matches[i] = - (char_u *)xstrnsave((char *)reg_getline(mpos->start_lnum) + mpos->start_col, - (size_t)(mpos->end_col - mpos->start_col)); + (uint8_t *)xstrnsave((char *)reg_getline(mpos->start_lnum) + mpos->start_col, + (size_t)(mpos->end_col - mpos->start_col)); } } else { struct linepos *lpos = &subs.synt.list.line[i]; if (lpos->start != NULL && lpos->end != NULL) { re_extmatch_out->matches[i] = - (char_u *)xstrnsave((char *)lpos->start, (size_t)(lpos->end - lpos->start)); + (uint8_t *)xstrnsave((char *)lpos->start, (size_t)(lpos->end - lpos->start)); } } } @@ -7335,7 +7335,7 @@ static long nfa_regtry(nfa_regprog_T *prog, colnr_T col, proftime_T *tm, int *ti /// /// @return <= 0 if there is no match and number of lines contained in the /// match otherwise. -static long nfa_regexec_both(char_u *line, colnr_T startcol, proftime_T *tm, int *timed_out) +static long nfa_regexec_both(uint8_t *line, colnr_T startcol, proftime_T *tm, int *timed_out) { nfa_regprog_T *prog; long retval = 0L; @@ -7343,13 +7343,13 @@ static long nfa_regexec_both(char_u *line, colnr_T startcol, proftime_T *tm, int if (REG_MULTI) { prog = (nfa_regprog_T *)rex.reg_mmatch->regprog; - line = (char_u *)reg_getline((linenr_T)0); // relative to the cursor + line = (uint8_t *)reg_getline((linenr_T)0); // relative to the cursor rex.reg_startpos = rex.reg_mmatch->startpos; rex.reg_endpos = rex.reg_mmatch->endpos; } else { prog = (nfa_regprog_T *)rex.reg_match->regprog; - rex.reg_startp = (char_u **)rex.reg_match->startp; - rex.reg_endp = (char_u **)rex.reg_match->endp; + rex.reg_startp = (uint8_t **)rex.reg_match->startp; + rex.reg_endp = (uint8_t **)rex.reg_match->endp; } // Be paranoid... @@ -7464,7 +7464,7 @@ theend: // Compile a regular expression into internal code for the NFA matcher. // Returns the program in allocated space. Returns NULL for an error. -static regprog_T *nfa_regcomp(char_u *expr, int re_flags) +static regprog_T *nfa_regcomp(uint8_t *expr, int re_flags) { nfa_regprog_T *prog = NULL; int *postfix; @@ -7582,7 +7582,7 @@ static void nfa_regfree(regprog_T *prog) /// @param col column to start looking for match /// /// @return <= 0 for failure, number of lines contained in the match otherwise. -static int nfa_regexec_nl(regmatch_T *rmp, char_u *line, colnr_T col, bool line_lbr) +static int nfa_regexec_nl(regmatch_T *rmp, uint8_t *line, colnr_T col, bool line_lbr) { rex.reg_match = rmp; rex.reg_mmatch = NULL; diff --git a/src/nvim/search.c b/src/nvim/search.c index ea62a94f28..12fdfa8f4d 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -3637,9 +3637,9 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool 1L, p_fname); } else { // Use text after match with 'include'. - new_fname = (char *)file_name_in_line(incl_regmatch.endp[0], 0, - FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname, - NULL); + new_fname = file_name_in_line(incl_regmatch.endp[0], 0, + FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname, + NULL); } already_searched = false; if (new_fname != NULL) { diff --git a/src/nvim/spell.c b/src/nvim/spell.c index e4c5779a08..215c546f83 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -664,7 +664,7 @@ static void find_word(matchinf_T *mip, int mode) // For multi-byte chars check character length against // COMPOUNDMIN. if (slang->sl_compminlen > 0 - && mb_charlen_len((char_u *)mip->mi_word + mip->mi_compoff, + && mb_charlen_len(mip->mi_word + mip->mi_compoff, wlen - mip->mi_compoff) < slang->sl_compminlen) { continue; } diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 4725c9aea6..1224e9cb9a 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -270,10 +270,6 @@ #include "nvim/undo.h" #include "nvim/vim.h" -#ifndef UNIX // it's in os/unix_defs.h for Unix -# include -#endif - // Special byte values for . Some are only used in the tree for // postponed prefixes, some only in the other trees. This is a bit messy... enum { diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 53b4d7082b..34b3c38103 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -167,7 +167,7 @@ char *vim_strsave_shellescape(const char *string, bool do_special, bool do_newli // First count the number of extra bytes required. size_t length = strlen(string) + 3; // two quotes and a trailing NUL - for (const char_u *p = (char_u *)string; *p != NUL; MB_PTR_ADV(p)) { + for (const char *p = string; *p != NUL; MB_PTR_ADV(p)) { #ifdef MSWIN if (!p_ssl) { if (*p == '"') { @@ -185,7 +185,7 @@ char *vim_strsave_shellescape(const char *string, bool do_special, bool do_newli length++; // insert backslash } } - if (do_special && find_cmdline_var((char *)p, &l) >= 0) { + if (do_special && find_cmdline_var(p, &l) >= 0) { length++; // insert backslash p += l - 1; } @@ -270,7 +270,7 @@ char *vim_strsave_up(const char *string) char *p1; p1 = xstrdup(string); - vim_strup((char_u *)p1); + vim_strup(p1); return p1; } @@ -280,17 +280,17 @@ char *vim_strnsave_up(const char *string, size_t len) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { char *p1 = xstrnsave(string, len); - vim_strup((char_u *)p1); + vim_strup(p1); return p1; } // ASCII lower-to-upper case translation, language independent. -void vim_strup(char_u *p) +void vim_strup(char *p) FUNC_ATTR_NONNULL_ALL { - char_u c; - while ((c = *p) != NUL) { - *p++ = (char_u)(c < 'a' || c > 'z' ? c : c - 0x20); + uint8_t c; + while ((c = (uint8_t)(*p)) != NUL) { + *p++ = (char)(uint8_t)(c < 'a' || c > 'z' ? c : c - 0x20); } } @@ -313,7 +313,7 @@ char *strcase_save(const char *const orig, bool upper) int l = utf_ptr2len(p); if (c == 0) { // overlong sequence, use only the first byte - c = (char_u)(*p); + c = (uint8_t)(*p); l = 1; } int uc = upper ? mb_toupper(c) : mb_tolower(c); diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 46cd6245a7..edf44b816f 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -1490,8 +1490,8 @@ int get_syntax_attr(const colnr_T col, bool *const can_spell, const bool keep_st static int syn_current_attr(const bool syncing, const bool displaying, bool *const can_spell, const bool keep_state) { - lpos_T endpos; // was: char_u *endp; - lpos_T hl_startpos; // was: int hl_startcol; + lpos_T endpos; + lpos_T hl_startpos; lpos_T hl_endpos; lpos_T eos_pos; // end-of-start match (start region) lpos_T eoe_pos; // end-of-end pattern diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 0d52f73ce7..18c7684584 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -2563,7 +2563,7 @@ 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 = xstrdup((*curbuf->b_p_tags != NUL) ? curbuf->b_p_tags : (char *)p_tags); + tnp->tn_tags = xstrdup((*curbuf->b_p_tags != NUL) ? curbuf->b_p_tags : p_tags); tnp->tn_np = tnp->tn_tags; } @@ -2593,7 +2593,7 @@ int get_tagfname(tagname_T *tnp, int first, char *buf) buf[0] = NUL; (void)copy_option_part(&tnp->tn_np, buf, MAXPATHL - 1, " ,"); - r_ptr = (char *)vim_findfile_stopdir(buf); + r_ptr = vim_findfile_stopdir(buf); // move the filename one char forward and truncate the // filepath with a NUL filename = path_tail(buf); diff --git a/src/nvim/testing.c b/src/nvim/testing.c index e9bad2a0b3..d168e67957 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -68,15 +68,15 @@ static void prepare_assert_error(garray_T *gap) /// Append "p[clen]" to "gap", escaping unprintable characters. /// Changes NL to \n, CR to \r, etc. -static void ga_concat_esc(garray_T *gap, const char_u *p, int clen) +static void ga_concat_esc(garray_T *gap, const char *p, int clen) FUNC_ATTR_NONNULL_ALL { - char_u buf[NUMBUFLEN]; + char buf[NUMBUFLEN]; if (clen > 1) { memmove(buf, p, (size_t)clen); buf[clen] = NUL; - ga_concat(gap, (char *)buf); + ga_concat(gap, buf); } else { switch (*p) { case BS: @@ -94,11 +94,11 @@ static void ga_concat_esc(garray_T *gap, const char_u *p, int clen) case '\\': ga_concat(gap, "\\\\"); break; default: - if (*p < ' ' || *p == 0x7f) { - vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p); - ga_concat(gap, (char *)buf); + if ((uint8_t)(*p) < ' ' || *p == 0x7f) { + vim_snprintf(buf, NUMBUFLEN, "\\x%02x", *p); + ga_concat(gap, buf); } else { - ga_append(gap, (char)(*p)); + ga_append(gap, *p); } break; } @@ -107,21 +107,21 @@ static void ga_concat_esc(garray_T *gap, const char_u *p, int clen) /// Append "str" to "gap", escaping unprintable characters. /// Changes NL to \n, CR to \r, etc. -static void ga_concat_shorten_esc(garray_T *gap, const char_u *str) +static void ga_concat_shorten_esc(garray_T *gap, const char *str) FUNC_ATTR_NONNULL_ARG(1) { - char_u buf[NUMBUFLEN]; + char buf[NUMBUFLEN]; if (str == NULL) { ga_concat(gap, "NULL"); return; } - for (const char_u *p = str; *p != NUL; p++) { + for (const char *p = str; *p != NUL; p++) { int same_len = 1; - const char *s = (char *)p; + const char *s = p; const int c = mb_ptr2char_adv(&s); - const int clen = (int)((char_u *)s - p); + const int clen = (int)(s - p); while (*s != NUL && c == utf_ptr2char(s)) { same_len++; s += clen; @@ -130,10 +130,10 @@ static void ga_concat_shorten_esc(garray_T *gap, const char_u *str) ga_concat(gap, "\\["); ga_concat_esc(gap, p, clen); ga_concat(gap, " occurs "); - vim_snprintf((char *)buf, NUMBUFLEN, "%d", same_len); - ga_concat(gap, (char *)buf); + vim_snprintf(buf, NUMBUFLEN, "%d", same_len); + ga_concat(gap, buf); ga_concat(gap, " times]"); - p = (char_u *)s - 1; + p = s - 1; } else { ga_concat_esc(gap, p, clen); } @@ -141,10 +141,10 @@ static void ga_concat_shorten_esc(garray_T *gap, const char_u *str) } /// Fill "gap" with information about an assert error. -static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_str, +static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char *exp_str, typval_T *exp_tv_arg, typval_T *got_tv_arg, assert_type_T atype) { - char_u *tofree; + char *tofree; typval_T *exp_tv = exp_tv_arg; typval_T *got_tv = got_tv_arg; bool did_copy = false; @@ -154,8 +154,8 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_s && !(opt_msg_tv->v_type == VAR_STRING && (opt_msg_tv->vval.v_string == NULL || *opt_msg_tv->vval.v_string == NUL))) { - tofree = (char_u *)encode_tv2echo(opt_msg_tv, NULL); - ga_concat(gap, (char *)tofree); + tofree = encode_tv2echo(opt_msg_tv, NULL); + ga_concat(gap, tofree); xfree(tofree); ga_concat(gap, ": "); } @@ -218,7 +218,7 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_s } } - tofree = (char_u *)encode_tv2string(exp_tv, NULL); + tofree = encode_tv2string(exp_tv, NULL); ga_concat_shorten_esc(gap, tofree); xfree(tofree); } else { @@ -233,7 +233,7 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_s } else { ga_concat(gap, " but got "); } - tofree = (char_u *)encode_tv2string(got_tv, NULL); + tofree = encode_tv2string(got_tv, NULL); ga_concat_shorten_esc(gap, tofree); xfree(tofree); @@ -306,7 +306,7 @@ static int assert_bool(typval_T *argvars, bool is_true) : kBoolVarFalse)))) { prepare_assert_error(&ga); fill_assert_error(&ga, &argvars[1], - (char_u *)(is_true ? "True" : "False"), + is_true ? "True" : "False", NULL, &argvars[0], ASSERT_OTHER); assert_error(&ga); ga_clear(&ga); @@ -642,8 +642,8 @@ static int assert_inrange(typval_T *argvars) garray_T ga; prepare_assert_error(&ga); if (argvars[3].v_type != VAR_UNKNOWN) { - char_u *const tofree = (char_u *)encode_tv2string(&argvars[3], NULL); - ga_concat(&ga, (char *)tofree); + char *const tofree = encode_tv2string(&argvars[3], NULL); + ga_concat(&ga, tofree); xfree(tofree); } else { char msg[80]; @@ -671,7 +671,7 @@ static int assert_inrange(typval_T *argvars) vim_snprintf(msg, sizeof(msg), "range %" PRIdVARNUMBER " - %" PRIdVARNUMBER ",", lower, upper); // -V576 - fill_assert_error(&ga, &argvars[3], (char_u *)msg, NULL, &argvars[2], + fill_assert_error(&ga, &argvars[3], msg, NULL, &argvars[2], ASSERT_INRANGE); assert_error(&ga); ga_clear(&ga); diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 8d58966f46..8e786c271c 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -273,7 +273,7 @@ bool startPS(linenr_T lnum, int para, bool both) return true; } if (*s == '.' && (inmacro(p_sections, s + 1) - || (!para && inmacro((char *)p_para, s + 1)))) { + || (!para && inmacro(p_para, s + 1)))) { return true; } return false; @@ -1078,7 +1078,7 @@ static bool in_html_tag(bool end_tag) if (inc(&pos) < 0) { return false; } - c = *ml_get_pos(&pos); + c = (uint8_t)(*ml_get_pos(&pos)); if (c == '>') { break; } diff --git a/src/nvim/undo.c b/src/nvim/undo.c index ad16a6eda2..7dd1e9b05d 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -624,7 +624,7 @@ int u_savecommon(buf_T *buf, linenr_T top, linenr_T bot, linenr_T newbot, int re // extra fields for uhp #define UHP_SAVE_NR 1 -static char_u e_not_open[] = N_("E828: Cannot open undo file for writing: %s"); +static char e_not_open[] = N_("E828: Cannot open undo file for writing: %s"); /// Compute the hash for a buffer text into hash[UNDO_HASH_SIZE]. /// @@ -677,7 +677,7 @@ char *u_get_undo_file_name(const char *const buf_ffname, const bool reading) // Loop over 'undodir'. When reading find the first file that exists. // When not reading use the first directory that exists or ".". - char *dirp = (char *)p_udir; + char *dirp = p_udir; while (*dirp != NUL) { size_t dir_len = copy_option_part(&dirp, dir_name, MAXPATHL, ","); if (dir_len == 1 && dir_name[0] == '.') { diff --git a/src/nvim/window.c b/src/nvim/window.c index fdaaeb812e..92d11cef0a 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -6790,17 +6790,17 @@ char *grab_file_name(long count, linenr_T *file_lnum) // FNAME_INCL apply "includeexpr" char *file_name_at_cursor(int options, long count, linenr_T *file_lnum) { - return (char *)file_name_in_line(get_cursor_line_ptr(), - curwin->w_cursor.col, options, count, curbuf->b_ffname, - file_lnum); + return file_name_in_line(get_cursor_line_ptr(), + curwin->w_cursor.col, options, count, curbuf->b_ffname, + file_lnum); } /// @param rel_fname file we are searching relative to /// @param file_lnum line number after the file name /// /// @return the name of the file under or after ptr[col]. Otherwise like file_name_at_cursor(). -char_u *file_name_in_line(char *line, int col, int options, long count, char *rel_fname, - linenr_T *file_lnum) +char *file_name_in_line(char *line, int col, int options, long count, char *rel_fname, + linenr_T *file_lnum) { // search forward for what could be the start of a file name char *ptr = line + col; @@ -6888,7 +6888,7 @@ char_u *file_name_in_line(char *line, int col, int options, long count, char *re } } - return (char_u *)find_file_name_in_path(ptr, len, options, count, rel_fname); + return find_file_name_in_path(ptr, len, options, count, rel_fname); } /// Add or remove a status line from window(s), according to the