diff options
Diffstat (limited to 'src/nvim/runtime.c')
-rw-r--r-- | src/nvim/runtime.c | 516 |
1 files changed, 274 insertions, 242 deletions
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 914b21bb02..24500b80b9 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -5,25 +5,46 @@ /// /// Management of runtime files (including packages) +#include <assert.h> +#include <errno.h> +#include <fcntl.h> +#include <inttypes.h> +#include <stdio.h> +#include <string.h> +#include <uv.h> + +#include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/ascii.h" #include "nvim/autocmd.h" +#include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/cmdexpand.h" #include "nvim/debugger.h" #include "nvim/eval.h" #include "nvim/eval/userfunc.h" -#include "nvim/ex_cmds.h" -#include "nvim/ex_cmds2.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/ex_eval.h" +#include "nvim/getchar.h" +#include "nvim/gettext.h" +#include "nvim/globals.h" #include "nvim/lua/executor.h" +#include "nvim/macros.h" +#include "nvim/map.h" +#include "nvim/mbyte.h" #include "nvim/memline.h" +#include "nvim/memory.h" +#include "nvim/message.h" #include "nvim/option.h" #include "nvim/os/input.h" #include "nvim/os/os.h" +#include "nvim/os/stdpaths_defs.h" +#include "nvim/path.h" #include "nvim/profile.h" #include "nvim/runtime.h" +#include "nvim/strings.h" +#include "nvim/usercmd.h" #include "nvim/vim.h" /// Structure used to store info for each sourced file. @@ -83,8 +104,7 @@ estack_T *estack_push(etype_T type, char *name, linenr_T lnum) void estack_push_ufunc(ufunc_T *ufunc, linenr_T lnum) { estack_T *entry = estack_push(ETYPE_UFUNC, - (char *)(ufunc->uf_name_exp != NULL - ? ufunc->uf_name_exp : ufunc->uf_name), + ufunc->uf_name_exp != NULL ? ufunc->uf_name_exp : ufunc->uf_name, lnum); if (entry != NULL) { entry->es_info.ufunc = ufunc; @@ -100,10 +120,11 @@ void estack_pop(void) } /// Get the current value for <sfile> in allocated memory. -/// @param which ESTACK_SFILE for <sfile> and ESTACK_STACK for <stack>. +/// @param which ESTACK_SFILE for <sfile>, ESTACK_STACK for <stack> or +/// ESTACK_SCRIPT for <script>. char *estack_sfile(estack_arg_T which) { - estack_T *entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1; + const estack_T *entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1; if (which == ESTACK_SFILE && entry->es_type != ETYPE_UFUNC) { if (entry->es_name == NULL) { return NULL; @@ -111,6 +132,26 @@ char *estack_sfile(estack_arg_T which) return xstrdup(entry->es_name); } + // If evaluated in a function or autocommand, return the path of the script + // where it is defined, at script level the current script path is returned + // instead. + if (which == ESTACK_SCRIPT) { + // Walk the stack backwards, starting from the current frame. + for (int idx = exestack.ga_len - 1; idx >= 0; idx--, entry--) { + if (entry->es_type == ETYPE_UFUNC || entry->es_type == ETYPE_AUCMD) { + const sctx_T *const def_ctx = (entry->es_type == ETYPE_UFUNC + ? &entry->es_info.ufunc->uf_script_ctx + : &entry->es_info.aucmd->script_ctx); + return def_ctx->sc_sid > 0 + ? xstrdup((SCRIPT_ITEM(def_ctx->sc_sid).sn_name)) + : NULL; + } else if (entry->es_type == ETYPE_SCRIPT) { + return xstrdup(entry->es_name); + } + } + return NULL; + } + // Give information about each stack entry up to the root. // For a function we compose the call stack, as it was done in the past: // "function One[123]..Two[456]..Three" @@ -171,20 +212,20 @@ void runtime_init(void) void ex_runtime(exarg_T *eap) { char *arg = eap->arg; - char *p = (char *)skiptowhite((char_u *)arg); - ptrdiff_t len = p - arg; + char *p = skiptowhite(arg); + size_t len = (size_t)(p - arg); int flags = eap->forceit ? DIP_ALL : 0; - if (STRNCMP(arg, "START", len) == 0) { + if (strncmp(arg, "START", len) == 0) { flags += DIP_START + DIP_NORTP; arg = skipwhite(arg + len); - } else if (STRNCMP(arg, "OPT", len) == 0) { + } else if (strncmp(arg, "OPT", len) == 0) { flags += DIP_OPT + DIP_NORTP; arg = skipwhite(arg + len); - } else if (STRNCMP(arg, "PACK", len) == 0) { + } else if (strncmp(arg, "PACK", len) == 0) { flags += DIP_START + DIP_OPT + DIP_NORTP; arg = skipwhite(arg + len); - } else if (STRNCMP(arg, "ALL", len) == 0) { + } else if (strncmp(arg, "ALL", len) == 0) { flags += DIP_START + DIP_OPT; arg = skipwhite(arg + len); } @@ -205,9 +246,9 @@ static void source_callback(char *fname, void *cookie) /// When "flags" has DIP_ERR: give an error message if there is no match. /// /// return FAIL when no file could be sourced, OK otherwise. -int do_in_path(char_u *path, char *name, int flags, DoInRuntimepathCB callback, void *cookie) +int do_in_path(char *path, char *name, int flags, DoInRuntimepathCB callback, void *cookie) { - char_u *tail; + char *tail; int num_files; char **files; int i; @@ -215,21 +256,21 @@ int do_in_path(char_u *path, char *name, int flags, DoInRuntimepathCB callback, // Make a copy of 'runtimepath'. Invoking the callback may change the // value. - char_u *rtp_copy = vim_strsave(path); + char *rtp_copy = xstrdup(path); char *buf = xmallocz(MAXPATHL); { if (p_verbose > 10 && name != NULL) { verbose_enter(); - smsg(_("Searching for \"%s\" in \"%s\""), name, (char *)path); + smsg(_("Searching for \"%s\" in \"%s\""), name, path); verbose_leave(); } // Loop over all entries in 'runtimepath'. - char *rtp = (char *)rtp_copy; + char *rtp = rtp_copy; while (*rtp != NUL && ((flags & DIP_ALL) || !did_one)) { // Copy the path from 'runtimepath' to buf[]. copy_option_part(&rtp, buf, MAXPATHL, ","); - size_t buflen = STRLEN(buf); + size_t buflen = strlen(buf); // Skip after or non-after directories. if (flags & (DIP_NOAFTER | DIP_AFTER)) { @@ -244,16 +285,16 @@ int do_in_path(char_u *path, char *name, int flags, DoInRuntimepathCB callback, if (name == NULL) { (*callback)(buf, cookie); did_one = true; - } else if (buflen + STRLEN(name) + 2 < MAXPATHL) { + } else if (buflen + strlen(name) + 2 < MAXPATHL) { add_pathsep(buf); - tail = (char_u *)buf + STRLEN(buf); + tail = buf + strlen(buf); // Loop over all patterns in "name" char *np = name; while (*np != NUL && ((flags & DIP_ALL) || !did_one)) { // Append the pattern from "name" to buf[]. - assert(MAXPATHL >= (tail - (char_u *)buf)); - copy_option_part(&np, (char *)tail, (size_t)(MAXPATHL - (tail - (char_u *)buf)), "\t "); + assert(MAXPATHL >= (tail - buf)); + copy_option_part(&np, tail, (size_t)(MAXPATHL - (tail - buf)), "\t "); if (p_verbose > 10) { verbose_enter(); @@ -322,7 +363,7 @@ RuntimeSearchPath copy_runtime_search_path(const RuntimeSearchPath src) return dst; } -void runtime_search_path_unref(RuntimeSearchPath path, int *ref) +void runtime_search_path_unref(RuntimeSearchPath path, const int *ref) FUNC_ATTR_NONNULL_ALL { if (*ref) { @@ -342,19 +383,19 @@ void runtime_search_path_unref(RuntimeSearchPath path, int *ref) /// When "flags" has DIP_ERR: give an error message if there is no match. /// /// return FAIL when no file could be sourced, OK otherwise. -int do_in_cached_path(char_u *name, int flags, DoInRuntimepathCB callback, void *cookie) +int do_in_cached_path(char *name, int flags, DoInRuntimepathCB callback, void *cookie) { - char_u *tail; + char *tail; int num_files; char **files; int i; bool did_one = false; - char_u buf[MAXPATHL]; + char buf[MAXPATHL]; if (p_verbose > 10 && name != NULL) { verbose_enter(); - smsg(_("Searching for \"%s\" in runtime path"), (char *)name); + smsg(_("Searching for \"%s\" in runtime path"), name); verbose_leave(); } @@ -376,17 +417,17 @@ int do_in_cached_path(char_u *name, int flags, DoInRuntimepathCB callback, void if (name == NULL) { (*callback)(item.path, cookie); - } else if (buflen + STRLEN(name) + 2 < MAXPATHL) { + } else if (buflen + strlen(name) + 2 < MAXPATHL) { STRCPY(buf, item.path); - add_pathsep((char *)buf); - tail = buf + STRLEN(buf); + add_pathsep(buf); + tail = buf + strlen(buf); // Loop over all patterns in "name" - char *np = (char *)name; + char *np = name; while (*np != NUL && ((flags & DIP_ALL) || !did_one)) { // Append the pattern from "name" to buf[]. assert(MAXPATHL >= (tail - buf)); - copy_option_part(&np, (char *)tail, (size_t)(MAXPATHL - (tail - buf)), "\t "); + copy_option_part(&np, tail, (size_t)(MAXPATHL - (tail - buf)), "\t "); if (p_verbose > 10) { verbose_enter(); @@ -398,7 +439,7 @@ int do_in_cached_path(char_u *name, int flags, DoInRuntimepathCB callback, void | (flags & DIP_DIRFILE) ? (EW_DIR|EW_FILE) : 0; // Expand wildcards, invoke the callback for each match. - char *(pat[]) = { (char *)buf }; + char *(pat[]) = { buf }; if (gen_expand_wildcards(1, pat, &num_files, &files, ew_flags) == OK) { for (i = 0; i < num_files; i++) { (*callback)(files[i], cookie); @@ -478,7 +519,7 @@ ArrayOf(String) runtime_get_named_common(bool lua, Array pat, bool all, if (lua) { if (item->has_lua == kNone) { size_t size = (size_t)snprintf(buf, buf_len, "%s/lua/", item->path); - item->has_lua = (size < buf_len && os_isdir((char_u *)buf)); + item->has_lua = (size < buf_len && os_isdir(buf)); } if (item->has_lua == kFalse) { continue; @@ -513,18 +554,18 @@ done: /// If "name" is NULL calls callback for each entry in "path". Cookie is /// passed by reference in this case, setting it to NULL indicates that callback /// has done its job. -int do_in_path_and_pp(char_u *path, char_u *name, int flags, DoInRuntimepathCB callback, - void *cookie) +int do_in_path_and_pp(char *path, char *name, int flags, DoInRuntimepathCB callback, void *cookie) { int done = FAIL; if ((flags & DIP_NORTP) == 0) { - done |= do_in_path(path, (char *)((name && !*name) ? NULL : name), flags, callback, cookie); + done |= do_in_path(path, (name && !*name) ? NULL : name, flags, callback, + cookie); } if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START)) { char *start_dir = "pack/*/start/*/%s%s"; // NOLINT - size_t len = STRLEN(start_dir) + STRLEN(name) + 6; + size_t len = strlen(start_dir) + strlen(name) + 6; char *s = xmallocz(len); // TODO(bfredl): get rid of random allocations char *suffix = (flags & DIP_AFTER) ? "after/" : ""; @@ -535,7 +576,7 @@ int do_in_path_and_pp(char_u *path, char_u *name, int flags, DoInRuntimepathCB c if (done == FAIL || (flags & DIP_ALL)) { start_dir = "start/*/%s%s"; // NOLINT - len = STRLEN(start_dir) + STRLEN(name) + 6; + len = strlen(start_dir) + strlen(name) + 6; s = xmallocz(len); vim_snprintf(s, len, start_dir, suffix, name); @@ -547,7 +588,7 @@ int do_in_path_and_pp(char_u *path, char_u *name, int flags, DoInRuntimepathCB c if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_OPT)) { char *opt_dir = "pack/*/opt/*/%s"; // NOLINT - size_t len = STRLEN(opt_dir) + STRLEN(name); + size_t len = strlen(opt_dir) + strlen(name); char *s = xmallocz(len); vim_snprintf(s, len, opt_dir, name); @@ -557,7 +598,7 @@ int do_in_path_and_pp(char_u *path, char_u *name, int flags, DoInRuntimepathCB c if (done == FAIL || (flags & DIP_ALL)) { opt_dir = "opt/*/%s"; // NOLINT - len = STRLEN(opt_dir) + STRLEN(name); + len = strlen(opt_dir) + strlen(name); s = xmallocz(len); vim_snprintf(s, len, opt_dir, name); @@ -604,18 +645,18 @@ static void expand_rtp_entry(RuntimeSearchPath *search_path, Map(String, handle_ } static void expand_pack_entry(RuntimeSearchPath *search_path, Map(String, handle_T) *rtp_used, - CharVec *after_path, char_u *pack_entry, size_t pack_entry_len) + CharVec *after_path, char *pack_entry, size_t pack_entry_len) { static char buf[MAXPATHL]; char *(start_pat[]) = { "/pack/*/start/*", "/start/*" }; // NOLINT for (int i = 0; i < 2; i++) { - if (pack_entry_len + STRLEN(start_pat[i]) + 1 > sizeof buf) { + if (pack_entry_len + strlen(start_pat[i]) + 1 > sizeof buf) { continue; } - STRLCPY(buf, pack_entry, sizeof buf); - STRLCPY(buf + pack_entry_len, start_pat[i], sizeof buf - pack_entry_len); + xstrlcpy(buf, pack_entry, sizeof buf); + xstrlcpy(buf + pack_entry_len, start_pat[i], sizeof buf - pack_entry_len); expand_rtp_entry(search_path, rtp_used, buf, false); - size_t after_size = STRLEN(buf) + 7; + size_t after_size = strlen(buf) + 7; char *after = xmallocz(after_size); xstrlcpy(after, buf, after_size); xstrlcat(after, "/after", after_size); @@ -630,7 +671,7 @@ static bool path_is_after(char *buf, size_t buflen) // "after" dir in SOME codepaths not not in ALL codepaths. return buflen >= 5 && (!(buflen >= 6) || vim_ispathsep(buf[buflen - 6])) - && STRCMP(buf + buflen - 5, "after") == 0; + && strcmp(buf + buflen - 5, "after") == 0; } RuntimeSearchPath runtime_search_path_build(void) @@ -643,32 +684,32 @@ RuntimeSearchPath runtime_search_path_build(void) RuntimeSearchPath search_path = KV_INITIAL_VALUE; CharVec after_path = KV_INITIAL_VALUE; - static char_u buf[MAXPATHL]; - for (char *entry = (char *)p_pp; *entry != NUL;) { + static char buf[MAXPATHL]; + for (char *entry = p_pp; *entry != NUL;) { char *cur_entry = entry; - copy_option_part(&entry, (char *)buf, MAXPATHL, ","); + copy_option_part(&entry, buf, MAXPATHL, ","); - String the_entry = { .data = cur_entry, .size = STRLEN(buf) }; + String the_entry = { .data = cur_entry, .size = strlen(buf) }; kv_push(pack_entries, the_entry); map_put(String, handle_T)(&pack_used, the_entry, 0); } char *rtp_entry; - for (rtp_entry = (char *)p_rtp; *rtp_entry != NUL;) { + for (rtp_entry = p_rtp; *rtp_entry != NUL;) { char *cur_entry = rtp_entry; - copy_option_part(&rtp_entry, (char *)buf, MAXPATHL, ","); - size_t buflen = STRLEN(buf); + copy_option_part(&rtp_entry, buf, MAXPATHL, ","); + size_t buflen = strlen(buf); - if (path_is_after((char *)buf, buflen)) { + if (path_is_after(buf, buflen)) { rtp_entry = cur_entry; break; } // fact: &rtp entries can contain wild chars - expand_rtp_entry(&search_path, &rtp_used, (char *)buf, false); + expand_rtp_entry(&search_path, &rtp_used, buf, false); - handle_T *h = map_ref(String, handle_T)(&pack_used, cstr_as_string((char *)buf), false); + handle_T *h = map_ref(String, handle_T)(&pack_used, cstr_as_string(buf), false); if (h) { (*h)++; expand_pack_entry(&search_path, &rtp_used, &after_path, buf, buflen); @@ -679,7 +720,7 @@ RuntimeSearchPath runtime_search_path_build(void) String item = kv_A(pack_entries, i); handle_T h = map_get(String, handle_T)(&pack_used, item); if (h == 0) { - expand_pack_entry(&search_path, &rtp_used, &after_path, (char_u *)item.data, item.size); + expand_pack_entry(&search_path, &rtp_used, &after_path, item.data, item.size); } } @@ -691,8 +732,8 @@ RuntimeSearchPath runtime_search_path_build(void) // "after" dirs in rtp for (; *rtp_entry != NUL;) { - copy_option_part(&rtp_entry, (char *)buf, MAXPATHL, ","); - expand_rtp_entry(&search_path, &rtp_used, (char *)buf, path_is_after((char *)buf, STRLEN(buf))); + copy_option_part(&rtp_entry, buf, MAXPATHL, ","); + expand_rtp_entry(&search_path, &rtp_used, buf, path_is_after(buf, strlen(buf))); } // strings are not owned @@ -746,13 +787,13 @@ int do_in_runtimepath(char *name, int flags, DoInRuntimepathCB callback, void *c { int success = FAIL; if (!(flags & DIP_NORTP)) { - success |= do_in_cached_path((name && !*name) ? NULL : (char_u *)name, flags, callback, cookie); + success |= do_in_cached_path((name && !*name) ? NULL : name, flags, callback, cookie); flags = (flags & ~DIP_START) | DIP_NORTP; } // TODO(bfredl): we could integrate disabled OPT dirs into the cached path // which would effectivize ":packadd myoptpack" as well if ((flags & (DIP_START|DIP_OPT)) && (success == FAIL || (flags & DIP_ALL))) { - success |= do_in_path_and_pp(p_rtp, (char_u *)name, flags, callback, cookie); + success |= do_in_path_and_pp(p_rtp, name, flags, callback, cookie); } return success; } @@ -768,7 +809,7 @@ int source_runtime(char *name, int flags) } /// Just like source_runtime(), but use "path" instead of 'runtimepath'. -int source_in_path(char_u *path, char_u *name, int flags) +int source_in_path(char *path, char *name, int flags) { return do_in_path_and_pp(path, name, flags, source_callback, NULL); } @@ -780,29 +821,37 @@ static void source_all_matches(char *pat) int num_files; char **files; - if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) == OK) { - for (int i = 0; i < num_files; i++) { - (void)do_source(files[i], false, DOSO_NONE); - } - FreeWild(num_files, files); + if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) != OK) { + return; } + + for (int i = 0; i < num_files; i++) { + (void)do_source(files[i], false, DOSO_NONE); + } + FreeWild(num_files, files); } /// Add the package directory to 'runtimepath' /// /// @param fname the package path /// @param is_pack whether the added dir is a "pack/*/start/*/" style package -static int add_pack_dir_to_rtp(char_u *fname, bool is_pack) +static int add_pack_dir_to_rtp(char *fname, bool is_pack) { - char_u *p4, *p3, *p2, *p1, *p; - char_u *buf = NULL; + char *p; + char *buf = NULL; char *afterdir = NULL; int retval = FAIL; - p4 = p3 = p2 = p1 = get_past_head(fname); + char *p1 = get_past_head(fname); + char *p2 = p1; + char *p3 = p1; + char *p4 = p1; for (p = p1; *p; MB_PTR_ADV(p)) { if (vim_ispathsep_nocolon(*p)) { - p4 = p3; p3 = p2; p2 = p1; p1 = p; + p4 = p3; + p3 = p2; + p2 = p1; + p1 = p; } } @@ -812,9 +861,9 @@ static int add_pack_dir_to_rtp(char_u *fname, bool is_pack) // // find the part up to "pack" in 'runtimepath' p4++; // append pathsep in order to expand symlink - char_u c = *p4; + char c = *p4; *p4 = NUL; - char *const ffname = fix_fname((char *)fname); + char *const ffname = fix_fname(fname); *p4 = c; if (ffname == NULL) { @@ -833,10 +882,10 @@ static int add_pack_dir_to_rtp(char_u *fname, bool is_pack) for (const char *entry = (const char *)p_rtp; *entry != NUL;) { const char *cur_entry = entry; - copy_option_part((char **)&entry, (char *)buf, MAXPATHL, ","); + copy_option_part((char **)&entry, buf, MAXPATHL, ","); if (insp == NULL) { - add_pathsep((char *)buf); - char *const rtp_ffname = fix_fname((char *)buf); + add_pathsep(buf); + char *const rtp_ffname = fix_fname(buf); if (rtp_ffname == NULL) { goto theend; } @@ -848,7 +897,7 @@ static int add_pack_dir_to_rtp(char_u *fname, bool is_pack) } } - if ((p = (char_u *)strstr((char *)buf, "after")) != NULL + if ((p = strstr(buf, "after")) != NULL && p > buf && vim_ispathsep(p[-1]) && (vim_ispathsep(p[5]) || p[5] == NUL || p[5] == ',')) { @@ -864,18 +913,18 @@ static int add_pack_dir_to_rtp(char_u *fname, bool is_pack) if (insp == NULL) { // Both "fname" and "after" not found, append at the end. - insp = (const char *)p_rtp + STRLEN(p_rtp); + insp = (const char *)p_rtp + strlen(p_rtp); } // check if rtp/pack/name/start/name/after exists - afterdir = concat_fnames((char *)fname, "after", true); + afterdir = concat_fnames(fname, "after", true); size_t afterlen = 0; - if (is_pack ? pack_has_entries((char_u *)afterdir) : os_isdir((char_u *)afterdir)) { + if (is_pack ? pack_has_entries(afterdir) : os_isdir(afterdir)) { afterlen = strlen(afterdir) + 1; // add one for comma } - const size_t oldlen = STRLEN(p_rtp); - const size_t addlen = STRLEN(fname) + 1; // add one for comma + const size_t oldlen = strlen(p_rtp); + const size_t addlen = strlen(fname) + 1; // add one for comma const size_t new_rtp_capacity = oldlen + addlen + afterlen + 1; // add one for NUL ------------------------------------------^ char *const new_rtp = try_malloc(new_rtp_capacity); @@ -923,7 +972,7 @@ static int add_pack_dir_to_rtp(char_u *fname, bool is_pack) xstrlcat(new_rtp, afterdir, new_rtp_capacity); } - set_option_value("rtp", 0L, new_rtp, 0); + set_option_value_give_err("rtp", 0L, new_rtp, 0); xfree(new_rtp); retval = OK; @@ -937,29 +986,29 @@ theend: /// Load scripts in "plugin" directory of the package. /// For opt packages, also load scripts in "ftdetect" (start packages already /// load these from filetype.vim) -static int load_pack_plugin(bool opt, char_u *fname) +static int load_pack_plugin(bool opt, char *fname) { static const char *ftpat = "%s/ftdetect/*.vim"; // NOLINT - char *const ffname = fix_fname((char *)fname); - size_t len = strlen(ffname) + STRLEN(ftpat); - char_u *pat = xmallocz(len); + char *const ffname = fix_fname(fname); + size_t len = strlen(ffname) + strlen(ftpat); + char *pat = xmallocz(len); - vim_snprintf((char *)pat, len, "%s/plugin/**/*.vim", ffname); // NOLINT - source_all_matches((char *)pat); - vim_snprintf((char *)pat, len, "%s/plugin/**/*.lua", ffname); // NOLINT - source_all_matches((char *)pat); + vim_snprintf(pat, len, "%s/plugin/**/*.vim", ffname); // NOLINT + source_all_matches(pat); + vim_snprintf(pat, len, "%s/plugin/**/*.lua", ffname); // NOLINT + source_all_matches(pat); - char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes"); + char *cmd = xstrdup("g:did_load_filetypes"); // If runtime/filetype.vim wasn't loaded yet, the scripts will be // found when it loads. - if (opt && eval_to_number((char *)cmd) > 0) { + if (opt && eval_to_number(cmd) > 0) { do_cmdline_cmd("augroup filetypedetect"); - vim_snprintf((char *)pat, len, ftpat, ffname); - source_all_matches((char *)pat); + vim_snprintf(pat, len, ftpat, ffname); + source_all_matches(pat); vim_snprintf((char *)pat, len, "%s/ftdetect/*.lua", ffname); // NOLINT - source_all_matches((char *)pat); + source_all_matches(pat); do_cmdline_cmd("augroup END"); } xfree(cmd); @@ -974,7 +1023,7 @@ static int APP_ADD_DIR; static int APP_LOAD; static int APP_BOTH; -static void add_pack_plugin(bool opt, char_u *fname, void *cookie) +static void add_pack_plugin(bool opt, char *fname, void *cookie) { if (cookie != &APP_LOAD) { char *buf = xmalloc(MAXPATHL); @@ -983,7 +1032,7 @@ static void add_pack_plugin(bool opt, char_u *fname, void *cookie) const char *p = (const char *)p_rtp; while (*p != NUL) { copy_option_part((char **)&p, buf, MAXPATHL, ","); - if (path_fnamecmp(buf, (char *)fname) == 0) { + if (path_fnamecmp(buf, fname) == 0) { found = true; break; } @@ -1004,12 +1053,12 @@ static void add_pack_plugin(bool opt, char_u *fname, void *cookie) static void add_start_pack_plugin(char *fname, void *cookie) { - add_pack_plugin(false, (char_u *)fname, cookie); + add_pack_plugin(false, fname, cookie); } static void add_opt_pack_plugin(char *fname, void *cookie) { - add_pack_plugin(true, (char_u *)fname, cookie); + add_pack_plugin(true, fname, cookie); } /// Add all packages in the "start" directory to 'runtimepath'. @@ -1018,11 +1067,11 @@ void add_pack_start_dirs(void) do_in_path(p_pp, NULL, DIP_ALL + DIP_DIR, add_pack_start_dir, NULL); } -static bool pack_has_entries(char_u *buf) +static bool pack_has_entries(char *buf) { int num_files; char **files; - char *(pat[]) = { (char *)buf }; + char *(pat[]) = { buf }; if (gen_expand_wildcards(1, pat, &num_files, &files, EW_DIR) == OK) { FreeWild(num_files, files); } @@ -1031,14 +1080,14 @@ static bool pack_has_entries(char_u *buf) static void add_pack_start_dir(char *fname, void *cookie) { - static char_u buf[MAXPATHL]; + static char buf[MAXPATHL]; char *(start_pat[]) = { "/start/*", "/pack/*/start/*" }; // NOLINT for (int i = 0; i < 2; i++) { - if (STRLEN(fname) + STRLEN(start_pat[i]) + 1 > MAXPATHL) { + if (strlen(fname) + strlen(start_pat[i]) + 1 > MAXPATHL) { continue; } - STRLCPY(buf, fname, MAXPATHL); - STRLCAT(buf, start_pat[i], sizeof buf); + xstrlcpy(buf, fname, MAXPATHL); + xstrlcat(buf, start_pat[i], sizeof buf); if (pack_has_entries(buf)) { add_pack_dir_to_rtp(buf, true); } @@ -1072,12 +1121,12 @@ void ex_packloadall(exarg_T *eap) void load_plugins(void) { if (p_lpl) { - char_u *rtp_copy = p_rtp; - char_u *const plugin_pattern_vim = (char_u *)"plugin/**/*.vim"; // NOLINT - char_u *const plugin_pattern_lua = (char_u *)"plugin/**/*.lua"; // NOLINT + char *rtp_copy = p_rtp; + char *const plugin_pattern_vim = "plugin/**/*.vim"; // NOLINT + char *const plugin_pattern_lua = "plugin/**/*.lua"; // NOLINT if (!did_source_packages) { - rtp_copy = vim_strsave(p_rtp); + rtp_copy = xstrdup(p_rtp); add_pack_start_dirs(); } @@ -1094,8 +1143,8 @@ void load_plugins(void) } TIME_MSG("loading packages"); - source_runtime((char *)plugin_pattern_vim, DIP_ALL | DIP_AFTER); - source_runtime((char *)plugin_pattern_lua, DIP_ALL | DIP_AFTER); + source_runtime(plugin_pattern_vim, DIP_ALL | DIP_AFTER); + source_runtime(plugin_pattern_lua, DIP_ALL | DIP_AFTER); TIME_MSG("loading after plugins"); } } @@ -1113,108 +1162,87 @@ void ex_packadd(exarg_T *eap) continue; } - const size_t len = STRLEN(plugpat) + STRLEN(eap->arg) + 5; + const size_t len = strlen(plugpat) + strlen(eap->arg) + 5; char *pat = xmallocz(len); vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg); // The first round don't give a "not found" error, in the second round // only when nothing was found in the first round. - res = do_in_path(p_pp, pat, DIP_ALL + DIP_DIR + (round == 2 && res == FAIL ? DIP_ERR : 0), - round == 1 ? add_start_pack_plugin : add_opt_pack_plugin, - eap->forceit ? &APP_ADD_DIR : &APP_BOTH); + res = + do_in_path(p_pp, pat, DIP_ALL + DIP_DIR + (round == 2 && res == FAIL ? DIP_ERR : 0), + round == 1 ? add_start_pack_plugin : add_opt_pack_plugin, + eap->forceit ? &APP_ADD_DIR : &APP_BOTH); xfree(pat); } } /// Expand color scheme, compiler or filetype names. /// Search from 'runtimepath': -/// 'runtimepath'/{dirnames}/{pat}.vim -/// When "flags" has DIP_START: search also from 'start' of 'packpath': -/// 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim -/// When "flags" has DIP_OPT: search also from 'opt' of 'packpath': -/// 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim -/// When "flags" has DIP_LUA: search also performed for .lua files +/// 'runtimepath'/{dirnames}/{pat}.(vim|lua) +/// When "flags" has DIP_START: search also from "start" of 'packpath': +/// 'packpath'/pack/*/start/*/{dirnames}/{pat}.(vim|lua) +/// When "flags" has DIP_OPT: search also from "opt" of 'packpath': +/// 'packpath'/pack/*/opt/*/{dirnames}/{pat}.(vim|lua) /// "dirnames" is an array with one or more directory names. -int ExpandRTDir(char_u *pat, int flags, int *num_file, char ***file, char *dirnames[]) +int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirnames[]) { *num_file = 0; *file = NULL; - size_t pat_len = STRLEN(pat); + size_t pat_len = strlen(pat); garray_T ga; ga_init(&ga, (int)sizeof(char *), 10); - // TODO(bfredl): this is bullshit, exandpath should not reinvent path logic. + // TODO(bfredl): this is bullshit, expandpath should not reinvent path logic. for (int i = 0; dirnames[i] != NULL; i++) { - size_t size = STRLEN(dirnames[i]) + pat_len + 7; - char_u *s = xmalloc(size); - snprintf((char *)s, size, "%s/%s*.vim", dirnames[i], pat); - globpath((char *)p_rtp, s, &ga, 0); - if (flags & DIP_LUA) { - snprintf((char *)s, size, "%s/%s*.lua", dirnames[i], pat); - globpath((char *)p_rtp, s, &ga, 0); - } + size_t size = strlen(dirnames[i]) + pat_len + 16; + char *s = xmalloc(size); + snprintf(s, size, "%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat); + globpath(p_rtp, s, &ga, 0); xfree(s); } if (flags & DIP_START) { for (int i = 0; dirnames[i] != NULL; i++) { - size_t size = STRLEN(dirnames[i]) + pat_len + 22; - char_u *s = xmalloc(size); - snprintf((char *)s, size, "pack/*/start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT - globpath((char *)p_pp, s, &ga, 0); - if (flags & DIP_LUA) { - snprintf((char *)s, size, "pack/*/start/*/%s/%s*.lua", dirnames[i], pat); // NOLINT - globpath((char *)p_pp, s, &ga, 0); - } + size_t size = strlen(dirnames[i]) + pat_len + 31; + char *s = xmalloc(size); + snprintf(s, size, "pack/*/start/*/%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat); // NOLINT + globpath(p_pp, s, &ga, 0); xfree(s); } for (int i = 0; dirnames[i] != NULL; i++) { - size_t size = STRLEN(dirnames[i]) + pat_len + 22; - char_u *s = xmalloc(size); - snprintf((char *)s, size, "start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT - globpath((char *)p_pp, s, &ga, 0); - if (flags & DIP_LUA) { - snprintf((char *)s, size, "start/*/%s/%s*.lua", dirnames[i], pat); // NOLINT - globpath((char *)p_pp, s, &ga, 0); - } + size_t size = strlen(dirnames[i]) + pat_len + 31; + char *s = xmalloc(size); + snprintf(s, size, "start/*/%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat); // NOLINT + globpath(p_pp, s, &ga, 0); xfree(s); } } if (flags & DIP_OPT) { for (int i = 0; dirnames[i] != NULL; i++) { - size_t size = STRLEN(dirnames[i]) + pat_len + 20; - char_u *s = xmalloc(size); - snprintf((char *)s, size, "pack/*/opt/*/%s/%s*.vim", dirnames[i], pat); // NOLINT - globpath((char *)p_pp, s, &ga, 0); - if (flags & DIP_LUA) { - snprintf((char *)s, size, "pack/*/opt/*/%s/%s*.lua", dirnames[i], pat); // NOLINT - globpath((char *)p_pp, s, &ga, 0); - } + size_t size = strlen(dirnames[i]) + pat_len + 29; + char *s = xmalloc(size); + snprintf(s, size, "pack/*/opt/*/%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat); // NOLINT + globpath(p_pp, s, &ga, 0); xfree(s); } for (int i = 0; dirnames[i] != NULL; i++) { - size_t size = STRLEN(dirnames[i]) + pat_len + 20; - char_u *s = xmalloc(size); - snprintf((char *)s, size, "opt/*/%s/%s*.vim", dirnames[i], pat); // NOLINT - globpath((char *)p_pp, s, &ga, 0); - if (flags & DIP_LUA) { - snprintf((char *)s, size, "opt/*/%s/%s*.lua", dirnames[i], pat); // NOLINT - globpath((char *)p_pp, s, &ga, 0); - } + size_t size = strlen(dirnames[i]) + pat_len + 29; + char *s = xmalloc(size); + snprintf(s, size, "opt/*/%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat); // NOLINT + globpath(p_pp, s, &ga, 0); xfree(s); } } for (int i = 0; i < ga.ga_len; i++) { - char_u *match = ((char_u **)ga.ga_data)[i]; - char_u *s = match; - char_u *e = s + STRLEN(s); + char *match = ((char **)ga.ga_data)[i]; + char *s = match; + char *e = s + strlen(s); if (e - s > 4 && (STRNICMP(e - 4, ".vim", 4) == 0 - || ((flags & DIP_LUA) - && STRNICMP(e - 4, ".lua", 4) == 0))) { + || STRNICMP(e - 4, ".lua", 4) == 0)) { e -= 4; for (s = e; s > match; MB_PTR_BACK(match, s)) { if (vim_ispathsep(*s)) { @@ -1243,27 +1271,27 @@ int ExpandRTDir(char_u *pat, int flags, int *num_file, char ***file, char *dirna /// Expand loadplugin names: /// 'packpath'/pack/ * /opt/{pat} -int ExpandPackAddDir(char_u *pat, int *num_file, char ***file) +int ExpandPackAddDir(char *pat, int *num_file, char ***file) { garray_T ga; *num_file = 0; *file = NULL; - size_t pat_len = STRLEN(pat); + size_t pat_len = strlen(pat); ga_init(&ga, (int)sizeof(char *), 10); size_t buflen = pat_len + 26; - char_u *s = xmalloc(buflen); - snprintf((char *)s, buflen, "pack/*/opt/%s*", pat); // NOLINT - globpath((char *)p_pp, s, &ga, 0); - snprintf((char *)s, buflen, "opt/%s*", pat); // NOLINT - globpath((char *)p_pp, s, &ga, 0); + char *s = xmalloc(buflen); + snprintf(s, buflen, "pack/*/opt/%s*", pat); // NOLINT + globpath(p_pp, s, &ga, 0); + snprintf(s, buflen, "opt/%s*", pat); // NOLINT + globpath(p_pp, s, &ga, 0); xfree(s); for (int i = 0; i < ga.ga_len; i++) { - char_u *match = ((char_u **)ga.ga_data)[i]; - s = (char_u *)path_tail((char *)match); - memmove(match, s, STRLEN(s) + 1); + char *match = ((char **)ga.ga_data)[i]; + s = path_tail(match); + memmove(match, s, strlen(s) + 1); } if (GA_EMPTY(&ga)) { @@ -1423,7 +1451,7 @@ static inline char *add_dir(char *dest, const char *const dir, const size_t dir_ if (!after_pathsep(dest - 1, dest)) { *dest++ = PATHSEP; } -#if defined(WIN32) +#if defined(MSWIN) size_t size = (type == kXDGDataHome ? sizeof("nvim-data") - 1 : NVIM_SIZE); memmove(dest, (type == kXDGDataHome ? "nvim-data" : "nvim"), size); dest += size; @@ -1451,7 +1479,7 @@ char *get_lib_dir(void) // TODO(bfredl): too fragile? Ideally default_lib_dir would be made empty // in an appimage build if (strlen(default_lib_dir) != 0 - && os_isdir((const char_u *)default_lib_dir)) { + && os_isdir(default_lib_dir)) { return xstrdup(default_lib_dir); } @@ -1493,7 +1521,7 @@ char *runtimepath_default(bool clean_arg) if (data_home != NULL) { data_len = strlen(data_home); if (data_len != 0) { -#if defined(WIN32) +#if defined(MSWIN) size_t nvim_size = (sizeof("nvim-data") - 1); #else size_t nvim_size = NVIM_SIZE; @@ -1583,7 +1611,7 @@ static void cmd_source(char *fname, exarg_T *eap) // - after ":argdo", ":windo" or ":bufdo" // - another command follows // - inside a loop - openscript((char_u *)fname, global_busy || listcmd_busy || eap->nextcmd != NULL + openscript(fname, global_busy || listcmd_busy || eap->nextcmd != NULL || eap->cstack->cs_idx >= 0); // ":source" read ex commands @@ -1605,7 +1633,7 @@ void ex_options(exarg_T *eap) bool multi_mods = 0; buf[0] = NUL; - (void)add_win_cmd_modifers(buf, &cmdmod, &multi_mods); + (void)add_win_cmd_modifiers(buf, &cmdmod, &multi_mods); os_setenv("OPTWIN_CMD", buf, 1); cmd_source(SYS_OPTWIN_FILE, NULL); @@ -1636,7 +1664,7 @@ int source_level(void *cookie) /// If possible the handle is closed on exec(). static FILE *fopen_noinh_readbin(char *filename) { -#ifdef WIN32 +#ifdef MSWIN int fd_tmp = os_open(filename, O_RDONLY | O_BINARY | O_NOINHERIT, 0); #else int fd_tmp = os_open(filename, O_RDONLY, 0); @@ -1663,14 +1691,14 @@ static FILE *fopen_noinh_readbin(char *filename) /// /// @return true if this line did begin with a continuation (the next line /// should also be considered, if it exists); false otherwise -static bool concat_continued_line(garray_T *const ga, const int init_growsize, - const char_u *const p, size_t len) +static bool concat_continued_line(garray_T *const ga, const int init_growsize, const char *const p, + size_t len) FUNC_ATTR_NONNULL_ALL { - const char *const line = (char *)skipwhite_len(p, len); - len -= (size_t)((char_u *)line - p); + const char *const line = skipwhite_len((char *)p, len); + len -= (size_t)(line - p); // Skip lines starting with '\" ', concat lines starting with '\' - if (len >= 3 && STRNCMP(line, "\"\\ ", 3) == 0) { + if (len >= 3 && strncmp(line, "\"\\ ", 3) == 0) { return true; } else if (len == 0 || line[0] != '\\') { return false; @@ -1700,19 +1728,19 @@ typedef struct { static char *get_str_line(int c, void *cookie, int indent, bool do_concat) { GetStrLineCookie *p = cookie; - if (STRLEN(p->buf) <= p->offset) { + if (strlen(p->buf) <= p->offset) { return NULL; } const char *line = p->buf + p->offset; - const char *eol = (char *)skip_to_newline((char_u *)line); + const char *eol = skip_to_newline(line); garray_T ga; - ga_init(&ga, sizeof(char_u), 400); + ga_init(&ga, sizeof(char), 400); ga_concat_len(&ga, line, (size_t)(eol - line)); if (do_concat && vim_strchr(p_cpo, CPO_CONCAT) == NULL) { while (eol[0] != NUL) { line = eol + 1; - const char_u *const next_eol = skip_to_newline((char_u *)line); - if (!concat_continued_line(&ga, 400, (char_u *)line, (size_t)(next_eol - (char_u *)line))) { + const char *const next_eol = skip_to_newline(line); + if (!concat_continued_line(&ga, 400, line, (size_t)(next_eol - line))) { break; } eol = (char *)next_eol; @@ -1742,7 +1770,7 @@ scriptitem_T *new_script_item(char *const name, scid_T *const sid_out) SCRIPT_ITEM(script_items.ga_len).sn_name = NULL; SCRIPT_ITEM(script_items.ga_len).sn_prof_on = false; } - SCRIPT_ITEM(sid).sn_name = (char_u *)name; + SCRIPT_ITEM(sid).sn_name = name; new_script_vars(sid); // Allocate the local script variables to use for this script. return &SCRIPT_ITEM(sid); } @@ -1786,7 +1814,7 @@ static void cmd_source_buffer(const exarg_T *const eap) return; } garray_T ga; - ga_init(&ga, sizeof(char_u), 400); + ga_init(&ga, sizeof(char), 400); const linenr_T final_lnum = eap->line2; // Copy the contents to be executed. for (linenr_T curr_lnum = eap->line1; curr_lnum <= final_lnum; curr_lnum++) { @@ -1794,10 +1822,10 @@ static void cmd_source_buffer(const exarg_T *const eap) if (ga.ga_len > 400) { ga_set_growsize(&ga, MIN(ga.ga_len, 8000)); } - ga_concat(&ga, (char *)ml_get(curr_lnum)); + ga_concat(&ga, ml_get(curr_lnum)); ga_append(&ga, NL); } - ((char_u *)ga.ga_data)[ga.ga_len - 1] = NUL; + ((char *)ga.ga_data)[ga.ga_len - 1] = NUL; const GetStrLineCookie cookie = { .buf = ga.ga_data, .offset = 0, @@ -1858,7 +1886,7 @@ int do_source(char *fname, int check_other, int is_vimrc) if (fname_exp == NULL) { return retval; } - if (os_isdir((char_u *)fname_exp)) { + if (os_isdir(fname_exp)) { smsg(_("Cannot source a directory: \"%s\""), fname); goto theend; } @@ -1880,7 +1908,7 @@ int do_source(char *fname, int check_other, int is_vimrc) cookie.fp = fopen_noinh_readbin(fname_exp); if (cookie.fp == NULL && check_other) { - // Try again, replacing file name ".vimrc" by "_vimrc" or vice versa, + // Try again, replacing file name ".nvimrc" by "_nvimrc" or vice versa, // and ".exrc" by "_exrc" or vice versa. p = path_tail(fname_exp); if ((*p == '.' || *p == '_') @@ -1935,7 +1963,7 @@ int do_source(char *fname, int check_other, int is_vimrc) cookie.finished = false; // Check if this script has a breakpoint. - cookie.breakpoint = dbg_find_breakpoint(true, (char_u *)fname_exp, (linenr_T)0); + cookie.breakpoint = dbg_find_breakpoint(true, fname_exp, (linenr_T)0); cookie.fname = fname_exp; cookie.dbg_tick = debug_tick; @@ -1964,7 +1992,7 @@ int do_source(char *fname, int check_other, int is_vimrc) si = get_current_script_id(&fname_exp, ¤t_sctx); // Keep the sourcing name/lnum, for recursive calls. - estack_push(ETYPE_SCRIPT, (char *)si->sn_name, 0); + estack_push(ETYPE_SCRIPT, si->sn_name, 0); if (l_do_profiling == PROF_YES) { bool forceit = false; @@ -1993,11 +2021,11 @@ int do_source(char *fname, int check_other, int is_vimrc) } else { // Read the first line so we can check for a UTF-8 BOM. firstline = (uint8_t *)getsourceline(0, (void *)&cookie, 0, true); - if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef + if (firstline != NULL && strlen((char *)firstline) >= 3 && firstline[0] == 0xef && firstline[1] == 0xbb && firstline[2] == 0xbf) { // Found BOM; setup conversion, skip over BOM and recode the line. - convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc); - p = (char *)string_convert(&cookie.conv, (char_u *)firstline + 3, NULL); + convert_setup(&cookie.conv, "utf-8", p_enc); + p = string_convert(&cookie.conv, (char *)firstline + 3, NULL); if (p == NULL) { p = xstrdup((char *)firstline + 3); } @@ -2036,8 +2064,8 @@ int do_source(char *fname, int check_other, int is_vimrc) } if (l_time_fd != NULL) { - vim_snprintf((char *)IObuff, IOSIZE, "sourcing %s", fname); - time_msg((char *)IObuff, &start_time); + vim_snprintf(IObuff, IOSIZE, "sourcing %s", fname); + time_msg(IObuff, &start_time); time_pop(rel_time); } @@ -2093,14 +2121,14 @@ scriptitem_T *get_current_script_id(char **fnamep, sctx_T *ret_sctx) // - If a script is deleted and another script is written, with a // different name, the inode may be re-used. si = &SCRIPT_ITEM(script_sctx.sc_sid); - if (si->sn_name != NULL && FNAMECMP(si->sn_name, *fnamep) == 0) { + if (si->sn_name != NULL && path_fnamecmp(si->sn_name, *fnamep) == 0) { // Found it! break; } } if (script_sctx.sc_sid == 0) { si = new_script_item(*fnamep, &script_sctx.sc_sid); - *fnamep = xstrdup((char *)si->sn_name); + *fnamep = xstrdup(si->sn_name); } if (ret_sctx != NULL) { *ret_sctx = script_sctx; @@ -2112,12 +2140,17 @@ scriptitem_T *get_current_script_id(char **fnamep, sctx_T *ret_sctx) /// ":scriptnames" void ex_scriptnames(exarg_T *eap) { - if (eap->addr_count > 0) { + if (eap->addr_count > 0 || *eap->arg != NUL) { // :script {scriptId}: edit the script - if (eap->line2 < 1 || eap->line2 > script_items.ga_len) { + if (eap->addr_count > 0 && !SCRIPT_ID_VALID(eap->line2)) { emsg(_(e_invarg)); } else { - eap->arg = (char *)SCRIPT_ITEM(eap->line2).sn_name; + if (eap->addr_count > 0) { + eap->arg = SCRIPT_ITEM(eap->line2).sn_name; + } else { + expand_env(eap->arg, NameBuff, MAXPATHL); + eap->arg = NameBuff; + } do_exedit(eap, NULL); } return; @@ -2125,11 +2158,11 @@ void ex_scriptnames(exarg_T *eap) for (int i = 1; i <= script_items.ga_len && !got_int; i++) { if (SCRIPT_ITEM(i).sn_name != NULL) { - home_replace(NULL, (char *)SCRIPT_ITEM(i).sn_name, (char *)NameBuff, MAXPATHL, true); - vim_snprintf((char *)IObuff, IOSIZE, "%3d: %s", i, NameBuff); + home_replace(NULL, SCRIPT_ITEM(i).sn_name, NameBuff, MAXPATHL, true); + vim_snprintf(IObuff, IOSIZE, "%3d: %s", i, NameBuff); if (!message_filtered(IObuff)) { msg_putchar('\n'); - msg_outtrans((char *)IObuff); + msg_outtrans(IObuff); line_breakcheck(); } } @@ -2151,40 +2184,40 @@ void scriptnames_slash_adjust(void) /// Get a pointer to a script name. Used for ":verbose set". /// Message appended to "Last set from " -char_u *get_scriptname(LastSet last_set, bool *should_free) +char *get_scriptname(LastSet last_set, bool *should_free) { *should_free = false; switch (last_set.script_ctx.sc_sid) { case SID_MODELINE: - return (char_u *)_("modeline"); + return _("modeline"); case SID_CMDARG: - return (char_u *)_("--cmd argument"); + return _("--cmd argument"); case SID_CARG: - return (char_u *)_("-c argument"); + return _("-c argument"); case SID_ENV: - return (char_u *)_("environment variable"); + return _("environment variable"); case SID_ERROR: - return (char_u *)_("error handler"); + return _("error handler"); case SID_WINLAYOUT: - return (char_u *)_("changed window size"); + return _("changed window size"); case SID_LUA: - return (char_u *)_("Lua"); + return _("Lua"); case SID_API_CLIENT: - snprintf((char *)IObuff, IOSIZE, _("API client (channel id %" PRIu64 ")"), last_set.channel_id); + snprintf(IObuff, IOSIZE, _("API client (channel id %" PRIu64 ")"), last_set.channel_id); return IObuff; case SID_STR: - return (char_u *)_("anonymous :source"); + return _("anonymous :source"); default: { - char *const sname = (char *)SCRIPT_ITEM(last_set.script_ctx.sc_sid).sn_name; + char *const sname = SCRIPT_ITEM(last_set.script_ctx.sc_sid).sn_name; if (sname == NULL) { - snprintf((char *)IObuff, IOSIZE, _("anonymous :source (script id %d)"), + snprintf(IObuff, IOSIZE, _("anonymous :source (script id %d)"), last_set.script_ctx.sc_sid); return IObuff; } *should_free = true; - return (char_u *)home_replace_save(NULL, sname); + return home_replace_save(NULL, sname); } } } @@ -2220,7 +2253,7 @@ char *getsourceline(int c, void *cookie, int indent, bool do_concat) // If breakpoints have been added/deleted need to check for it. if (sp->dbg_tick < debug_tick) { - sp->breakpoint = dbg_find_breakpoint(true, (char_u *)sp->fname, SOURCING_LNUM); + sp->breakpoint = dbg_find_breakpoint(true, sp->fname, SOURCING_LNUM); sp->dbg_tick = debug_tick; } if (do_profiling == PROF_YES) { @@ -2259,11 +2292,10 @@ char *getsourceline(int c, void *cookie, int indent, bool do_concat) || (p[0] == '"' && p[1] == '\\' && p[2] == ' '))) { garray_T ga; - ga_init(&ga, (int)sizeof(char_u), 400); + ga_init(&ga, (int)sizeof(char), 400); ga_concat(&ga, line); while (sp->nextline != NULL - && concat_continued_line(&ga, 400, (char_u *)sp->nextline, - STRLEN(sp->nextline))) { + && concat_continued_line(&ga, 400, sp->nextline, strlen(sp->nextline))) { xfree(sp->nextline); sp->nextline = get_one_sourceline(sp); } @@ -2277,7 +2309,7 @@ char *getsourceline(int c, void *cookie, int indent, bool do_concat) char *s; // Convert the encoding of the script line. - s = (char *)string_convert(&sp->conv, (char_u *)line, NULL); + s = string_convert(&sp->conv, line, NULL); if (s != NULL) { xfree(line); line = s; @@ -2286,9 +2318,9 @@ char *getsourceline(int c, void *cookie, int indent, bool do_concat) // Did we encounter a breakpoint? if (sp->breakpoint != 0 && sp->breakpoint <= SOURCING_LNUM) { - dbg_breakpoint((char_u *)sp->fname, SOURCING_LNUM); + dbg_breakpoint(sp->fname, SOURCING_LNUM); // Find next breakpoint. - sp->breakpoint = dbg_find_breakpoint(true, (char_u *)sp->fname, SOURCING_LNUM); + sp->breakpoint = dbg_find_breakpoint(true, sp->fname, SOURCING_LNUM); sp->dbg_tick = debug_tick; } @@ -2326,7 +2358,7 @@ retry: break; } - len = ga.ga_len + (int)STRLEN(buf + ga.ga_len); + len = ga.ga_len + (int)strlen(buf + ga.ga_len); #ifdef USE_CRNL // Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the // CTRL-Z by its own, or after a NL. @@ -2410,14 +2442,14 @@ void ex_scriptencoding(exarg_T *eap) } if (*eap->arg != NUL) { - name = (char *)enc_canonize((char_u *)eap->arg); + name = enc_canonize(eap->arg); } else { name = eap->arg; } // Setup for conversion from the specified encoding to 'encoding'. sp = (struct source_cookie *)getline_cookie(eap->getline, eap->cookie); - convert_setup(&sp->conv, (char_u *)name, p_enc); + convert_setup(&sp->conv, name, p_enc); if (name != eap->arg) { xfree(name); |