diff options
| author | Dundar Goc <gocdundar@gmail.com> | 2022-05-01 11:18:17 +0200 |
|---|---|---|
| committer | Dundar Goc <gocdundar@gmail.com> | 2022-05-03 10:33:40 +0200 |
| commit | b9bdd0f61e5e7365c07aadbc3f796556b6d85fdf (patch) | |
| tree | 807bb0bcb4a551285e7c1f739b1b201d49d58261 /src/nvim/eval.c | |
| parent | 46734cf7c1e5abe8e452354db6914364bfe89f0d (diff) | |
| download | rneovim-b9bdd0f61e5e7365c07aadbc3f796556b6d85fdf.tar.gz rneovim-b9bdd0f61e5e7365c07aadbc3f796556b6d85fdf.tar.bz2 rneovim-b9bdd0f61e5e7365c07aadbc3f796556b6d85fdf.zip | |
refactor: replace char_u variables and functions with char
Work on https://github.com/neovim/neovim/issues/459
Diffstat (limited to 'src/nvim/eval.c')
| -rw-r--r-- | src/nvim/eval.c | 964 |
1 files changed, 475 insertions, 489 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 3023b1e774..b4c3e62ddf 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -73,7 +73,7 @@ static char *e_string_list_or_blob_required = N_("E1098: String, List or Blob re // TODO(ZyX-I): move to eval/executor static char *e_letwrong = N_("E734: Wrong variable type for %s="); -static char_u * const namespace_char = (char_u *)"abglstvw"; +static char * const namespace_char = "abglstvw"; /// Variable used for g: static ScopeDictDictItem globvars_var; @@ -103,7 +103,7 @@ static garray_T ga_scripts = { 0, 0, sizeof(scriptvar_T *), 4, NULL }; static int echo_attr = 0; // attributes used for ":echo" // The names of packages that once were loaded are remembered. -static garray_T ga_loaded = { 0, 0, sizeof(char_u *), 4, NULL }; +static garray_T ga_loaded = { 0, 0, sizeof(char *), 4, NULL }; /* * Info used by a ":for" loop. @@ -115,7 +115,7 @@ typedef struct { list_T *fi_list; // list being used int fi_bi; // index of blob blob_T *fi_blob; // blob being used - char_u *fi_string; // copy of string being used + char *fi_string; // copy of string being used int fi_byte_idx; // byte index in fi_string } forinfo_T; @@ -500,12 +500,12 @@ void eval_clear(void) /// Set an internal variable to a string value. Creates the variable if it does /// not already exist. -void set_internal_string_var(const char *name, char_u *value) +void set_internal_string_var(const char *name, char *value) FUNC_ATTR_NONNULL_ARG(1) { typval_T tv = { .v_type = VAR_STRING, - .vval.v_string = value, + .vval.v_string = (char_u *)value, }; set_var(name, strlen(name), &tv, true); @@ -513,15 +513,15 @@ void set_internal_string_var(const char *name, char_u *value) static lval_T *redir_lval = NULL; static garray_T redir_ga; // Only valid when redir_lval is not NULL. -static char_u *redir_endp = NULL; -static char_u *redir_varname = NULL; +static char *redir_endp = NULL; +static char *redir_varname = NULL; /// Start recording command output to a variable /// /// @param append append to an existing variable /// /// @return OK if successfully completed the setup. FAIL otherwise. -int var_redir_start(char_u *name, int append) +int var_redir_start(char *name, int append) { int save_emsg; int err; @@ -534,7 +534,7 @@ int var_redir_start(char_u *name, int append) } // Make a copy of the name, it is used in redir_lval until redir ends. - redir_varname = vim_strsave(name); + redir_varname = xstrdup(name); redir_lval = xcalloc(1, sizeof(lval_T)); @@ -588,7 +588,7 @@ int var_redir_start(char_u *name, int append) /// :redir => foo /// :let foo /// :redir END -void var_redir_str(char_u *value, int value_len) +void var_redir_str(char *value, int value_len) { int len; @@ -646,7 +646,7 @@ int eval_charconvert(const char *const enc_from, const char *const enc_to, set_vim_var_string(VV_CC_TO, enc_to, -1); set_vim_var_string(VV_FNAME_IN, fname_from, -1); set_vim_var_string(VV_FNAME_OUT, fname_to, -1); - if (eval_to_bool(p_ccv, &err, NULL, false)) { + if (eval_to_bool((char *)p_ccv, &err, NULL, false)) { err = true; } set_vim_var_string(VV_CC_FROM, NULL, -1); @@ -666,7 +666,7 @@ int eval_printexpr(const char *const fname, const char *const args) set_vim_var_string(VV_FNAME_IN, fname, -1); set_vim_var_string(VV_CMDARG, args, -1); - if (eval_to_bool(p_pexpr, &err, NULL, false)) { + if (eval_to_bool((char *)p_pexpr, &err, NULL, false)) { err = true; } set_vim_var_string(VV_FNAME_IN, NULL, -1); @@ -686,7 +686,7 @@ void eval_diff(const char *const origfile, const char *const newfile, const char set_vim_var_string(VV_FNAME_IN, origfile, -1); set_vim_var_string(VV_FNAME_NEW, newfile, -1); set_vim_var_string(VV_FNAME_OUT, outfile, -1); - (void)eval_to_bool(p_dex, &err, NULL, FALSE); + (void)eval_to_bool((char *)p_dex, &err, NULL, false); set_vim_var_string(VV_FNAME_IN, NULL, -1); set_vim_var_string(VV_FNAME_NEW, NULL, -1); set_vim_var_string(VV_FNAME_OUT, NULL, -1); @@ -699,7 +699,7 @@ void eval_patch(const char *const origfile, const char *const difffile, const ch set_vim_var_string(VV_FNAME_IN, origfile, -1); set_vim_var_string(VV_FNAME_DIFF, difffile, -1); set_vim_var_string(VV_FNAME_OUT, outfile, -1); - (void)eval_to_bool(p_pex, &err, NULL, FALSE); + (void)eval_to_bool((char *)p_pex, &err, NULL, false); set_vim_var_string(VV_FNAME_IN, NULL, -1); set_vim_var_string(VV_FNAME_DIFF, NULL, -1); set_vim_var_string(VV_FNAME_OUT, NULL, -1); @@ -711,7 +711,7 @@ void eval_patch(const char *const origfile, const char *const difffile, const ch /// @param skip only parse, don't execute /// /// @return TRUE or FALSE. -int eval_to_bool(char_u *arg, bool *error, char_u **nextcmd, int skip) +int eval_to_bool(char *arg, bool *error, char **nextcmd, int skip) { typval_T tv; bool retval = false; @@ -736,10 +736,10 @@ int eval_to_bool(char_u *arg, bool *error, char_u **nextcmd, int skip) } /// Call eval1() and give an error message if not done at a lower level. -static int eval1_emsg(char_u **arg, typval_T *rettv, bool evaluate) +static int eval1_emsg(char **arg, typval_T *rettv, bool evaluate) FUNC_ATTR_NONNULL_ARG(1, 2) { - const char_u *const start = *arg; + const char *const start = *arg; const int did_emsg_before = did_emsg; const int called_emsg_before = called_emsg; @@ -773,36 +773,36 @@ int eval_expr_typval(const typval_T *expr, typval_T *argv, int argc, typval_T *r funcexe_T funcexe = FUNCEXE_INIT; if (expr->v_type == VAR_FUNC) { - const char_u *const s = expr->vval.v_string; + const char *const s = (char *)expr->vval.v_string; if (s == NULL || *s == NUL) { return FAIL; } funcexe.evaluate = true; - if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) { + if (call_func((char_u *)s, -1, rettv, argc, argv, &funcexe) == FAIL) { return FAIL; } } else if (expr->v_type == VAR_PARTIAL) { partial_T *const partial = expr->vval.v_partial; - const char_u *const s = partial_name(partial); + const char *const s = partial_name(partial); if (s == NULL || *s == NUL) { return FAIL; } funcexe.evaluate = true; funcexe.partial = partial; - if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) { + if (call_func((char_u *)s, -1, rettv, argc, argv, &funcexe) == FAIL) { return FAIL; } } else { char buf[NUMBUFLEN]; - char_u *s = (char_u *)tv_get_string_buf_chk(expr, buf); + char *s = (char *)tv_get_string_buf_chk(expr, buf); if (s == NULL) { return FAIL; } - s = skipwhite(s); + s = (char *)skipwhite((char_u *)s); if (eval1_emsg(&s, rettv, true) == FAIL) { return FAIL; } - if (*skipwhite(s) != NUL) { // check for trailing chars after expr + if (*skipwhite((char_u *)s) != NUL) { // check for trailing chars after expr tv_clear(rettv); semsg(_(e_invexpr2), s); return FAIL; @@ -845,7 +845,7 @@ char *eval_to_string_skip(const char *arg, const char **nextcmd, const bool skip if (skip) { emsg_skip++; } - if (eval0((char_u *)arg, &tv, (char_u **)nextcmd, !skip) == FAIL || skip) { + if (eval0((char *)arg, &tv, (char **)nextcmd, !skip) == FAIL || skip) { retval = NULL; } else { retval = xstrdup(tv_get_string(&tv)); @@ -861,12 +861,12 @@ char *eval_to_string_skip(const char *arg, const char **nextcmd, const bool skip /// Skip over an expression at "*pp". /// /// @return FAIL for an error, OK otherwise. -int skip_expr(char_u **pp) +int skip_expr(char **pp) { typval_T rettv; - *pp = skipwhite(*pp); - return eval1(pp, &rettv, FALSE); + *pp = (char *)skipwhite((char_u *)(*pp)); + return eval1(pp, &rettv, false); } /// Top level evaluation function, returning a string. @@ -875,7 +875,7 @@ int skip_expr(char_u **pp) /// a Float to a String. /// /// @return pointer to allocated memory, or NULL for failure. -char_u *eval_to_string(char_u *arg, char_u **nextcmd, bool convert) +char *eval_to_string(char *arg, char **nextcmd, bool convert) { typval_T tv; char *retval; @@ -904,16 +904,16 @@ char_u *eval_to_string(char_u *arg, char_u **nextcmd, bool convert) tv_clear(&tv); } - return (char_u *)retval; + return retval; } /// Call eval_to_string() without using current local variables and using /// textlock. /// /// @param use_sandbox when TRUE, use the sandbox. -char_u *eval_to_string_safe(char_u *arg, char_u **nextcmd, int use_sandbox) +char *eval_to_string_safe(char *arg, char **nextcmd, int use_sandbox) { - char_u *retval; + char *retval; funccal_entry_T funccal_entry; save_funccal(&funccal_entry); @@ -934,11 +934,11 @@ char_u *eval_to_string_safe(char_u *arg, char_u **nextcmd, int use_sandbox) /// Evaluates "expr" silently. /// /// @return -1 for an error. -varnumber_T eval_to_number(char_u *expr) +varnumber_T eval_to_number(char *expr) { typval_T rettv; varnumber_T retval; - char_u *p = skipwhite(expr); + char *p = (char *)skipwhite((char_u *)expr); ++emsg_off; @@ -957,7 +957,7 @@ varnumber_T eval_to_number(char_u *expr) /// /// @return an allocated typval_T with the result or /// NULL when there is an error. -typval_T *eval_expr(char_u *arg) +typval_T *eval_expr(char *arg) { typval_T *tv = xmalloc(sizeof(*tv)); if (eval0(arg, tv, NULL, true) == FAIL) { @@ -1009,17 +1009,17 @@ void find_win_for_curbuf(void) /// For the "expr:" part of 'spellsuggest'. /// /// @return NULL when there is an error. -list_T *eval_spell_expr(char_u *badword, char_u *expr) +list_T *eval_spell_expr(char *badword, char *expr) { typval_T save_val; typval_T rettv; list_T *list = NULL; - char_u *p = skipwhite(expr); + char *p = (char *)skipwhite((char_u *)expr); // Set "v:val" to the bad word. prepare_vimvar(VV_VAL, &save_val); vimvars[VV_VAL].vv_type = VAR_STRING; - vimvars[VV_VAL].vv_str = badword; + vimvars[VV_VAL].vv_str = (char_u *)badword; if (p_verbose == 0) { ++emsg_off; } @@ -1073,7 +1073,7 @@ int get_spellword(list_T *const list, const char **ret_word) // should have type VAR_UNKNOWN. // // @return OK or FAIL. -int call_vim_function(const char_u *func, int argc, typval_T *argv, typval_T *rettv) +int call_vim_function(const char *func, int argc, typval_T *argv, typval_T *rettv) FUNC_ATTR_NONNULL_ALL { int ret; @@ -1082,7 +1082,7 @@ int call_vim_function(const char_u *func, int argc, typval_T *argv, typval_T *re if (len >= 6 && !memcmp(func, "v:lua.", 6)) { func += 6; - len = check_luafunc_name((const char *)func, false); + len = check_luafunc_name(func, false); if (len == 0) { ret = FAIL; goto fail; @@ -1096,7 +1096,7 @@ int call_vim_function(const char_u *func, int argc, typval_T *argv, typval_T *re funcexe.lastline = curwin->w_cursor.lnum; funcexe.evaluate = true; funcexe.partial = pt; - ret = call_func(func, len, rettv, argc, argv, &funcexe); + ret = call_func((char_u *)func, len, rettv, argc, argv, &funcexe); fail: if (ret == FAIL) { @@ -1112,13 +1112,13 @@ fail: /// @param[in] argv Array with typval_T arguments. /// /// @return -1 when calling function fails, result of function otherwise. -varnumber_T call_func_retnr(const char_u *func, int argc, typval_T *argv) +varnumber_T call_func_retnr(const char *func, int argc, typval_T *argv) FUNC_ATTR_NONNULL_ALL { typval_T rettv; varnumber_T retval; - if (call_vim_function(func, argc, argv, &rettv) == FAIL) { + if (call_vim_function((char *)func, argc, argv, &rettv) == FAIL) { return -1; } retval = tv_get_number_chk(&rettv, NULL); @@ -1138,7 +1138,7 @@ char *call_func_retstr(const char *const func, int argc, typval_T *argv) { typval_T rettv; // All arguments are passed as strings, no conversion to number. - if (call_vim_function((const char_u *)func, argc, argv, &rettv) + if (call_vim_function(func, argc, argv, &rettv) == FAIL) { return NULL; } @@ -1155,13 +1155,13 @@ char *call_func_retstr(const char *const func, int argc, typval_T *argv) /// /// @return [allocated] NULL when calling function fails or return tv is not a /// List, allocated List otherwise. -void *call_func_retlist(const char_u *func, int argc, typval_T *argv) +void *call_func_retlist(const char *func, int argc, typval_T *argv) FUNC_ATTR_NONNULL_ALL { typval_T rettv; // All arguments are passed as strings, no conversion to number. - if (call_vim_function(func, argc, argv, &rettv) == FAIL) { + if (call_vim_function((char *)func, argc, argv, &rettv) == FAIL) { return NULL; } @@ -1212,7 +1212,7 @@ void prof_child_exit(proftime_T *tm) /// Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding /// it in "*cp". Doesn't give error messages. -int eval_foldexpr(char_u *arg, int *cp) +int eval_foldexpr(char *arg, int *cp) { typval_T tv; varnumber_T retval; @@ -1235,11 +1235,11 @@ int eval_foldexpr(char_u *arg, int *cp) } else { // If the result is a string, check if there is a non-digit before // the number. - char_u *s = tv.vval.v_string; + char *s = (char *)tv.vval.v_string; if (!ascii_isdigit(*s) && *s != '-') { - *cp = *s++; + *cp = (char_u)(*s++); } - retval = atol((char *)s); + retval = atol(s); } tv_clear(&tv); } @@ -1273,13 +1273,13 @@ void ex_const(exarg_T *eap) /// indentation in the 'cmd' line) is stripped. /// /// @return a List with {lines} or NULL. -static list_T *heredoc_get(exarg_T *eap, char_u *cmd) +static list_T *heredoc_get(exarg_T *eap, char *cmd) { - char_u *marker; - char_u *p; + char *marker; + char *p; int marker_indent_len = 0; int text_indent_len = 0; - char_u *text_indent = NULL; + char *text_indent = NULL; if (eap->getline == NULL) { emsg(_("E991: cannot use =<< here")); @@ -1287,16 +1287,16 @@ static list_T *heredoc_get(exarg_T *eap, char_u *cmd) } // Check for the optional 'trim' word before the marker - cmd = skipwhite(cmd); + cmd = (char *)skipwhite((char_u *)cmd); if (STRNCMP(cmd, "trim", 4) == 0 && (cmd[4] == NUL || ascii_iswhite(cmd[4]))) { - cmd = skipwhite(cmd + 4); + cmd = (char *)skipwhite((char_u *)cmd + 4); // Trim the indentation from all the lines in the here document. // The amount of indentation trimmed is the same as the indentation of // the first line after the :let command line. To find the end marker // the indent of the :let command line is trimmed. - p = *eap->cmdlinep; + p = (char *)(*eap->cmdlinep); while (ascii_iswhite(*p)) { p++; marker_indent_len++; @@ -1306,9 +1306,9 @@ static list_T *heredoc_get(exarg_T *eap, char_u *cmd) // The marker is the next word. if (*cmd != NUL && *cmd != '"') { - marker = skipwhite(cmd); - p = skiptowhite(marker); - if (*skipwhite(p) != NUL && *skipwhite(p) != '"') { + marker = (char *)skipwhite((char_u *)cmd); + p = (char *)skiptowhite((char_u *)marker); + if (*skipwhite((char_u *)p) != NUL && *skipwhite((char_u *)p) != '"') { emsg(_(e_trailing)); return NULL; } @@ -1327,7 +1327,7 @@ static list_T *heredoc_get(exarg_T *eap, char_u *cmd) int mi = 0; int ti = 0; - char_u *theline = eap->getline(NUL, eap->cookie, 0, false); + char *theline = (char *)eap->getline(NUL, eap->cookie, 0, false); if (theline == NULL) { semsg(_("E990: Missing end marker '%s'"), marker); break; @@ -1351,7 +1351,7 @@ static list_T *heredoc_get(exarg_T *eap, char_u *cmd) p++; text_indent_len++; } - text_indent = vim_strnsave(theline, text_indent_len); + text_indent = xstrnsave(theline, text_indent_len); } // with "trim": skip the indent matching the first line if (text_indent != NULL) { @@ -1362,7 +1362,7 @@ static list_T *heredoc_get(exarg_T *eap, char_u *cmd) } } - tv_list_append_string(l, (char *)(theline + ti), -1); + tv_list_append_string(l, theline + ti, -1); xfree(theline); } xfree(text_indent); @@ -1389,24 +1389,24 @@ void ex_let(exarg_T *eap) static void ex_let_const(exarg_T *eap, const bool is_const) { - char_u *arg = eap->arg; - char_u *expr = NULL; + char *arg = (char *)eap->arg; + char *expr = NULL; typval_T rettv; int i; int var_count = 0; int semicolon = 0; - char_u op[2]; - char_u *argend; - int first = TRUE; + char op[2]; + char *argend; + int first = true; - argend = (char_u *)skip_var_list(arg, &var_count, &semicolon); + argend = (char *)skip_var_list(arg, &var_count, &semicolon); if (argend == NULL) { return; } if (argend > arg && argend[-1] == '.') { // For var.='str'. argend--; } - expr = skipwhite(argend); + expr = (char *)skipwhite((char_u *)argend); if (*expr != '=' && !((vim_strchr((char_u *)"+-*/%.", *expr) != NULL && expr[1] == '=') || STRNCMP(expr, "..=", 3) == 0)) { // ":let" without "=": list variables @@ -1414,7 +1414,7 @@ static void ex_let_const(exarg_T *eap, const bool is_const) emsg(_(e_invarg)); } else if (!ends_excmd(*arg)) { // ":let var1 var2" - arg = (char_u *)list_arg_vars(eap, (const char *)arg, &first); + arg = (char *)list_arg_vars(eap, (const char *)arg, &first); } else if (!eap->skip) { // ":let" list_glob_vars(&first); @@ -1425,7 +1425,7 @@ static void ex_let_const(exarg_T *eap, const bool is_const) list_func_vars(&first); list_vim_vars(&first); } - eap->nextcmd = check_nextcmd(arg); + eap->nextcmd = check_nextcmd((char_u *)arg); } else if (expr[0] == '=' && expr[1] == '<' && expr[2] == '<') { // HERE document list_T *l = heredoc_get(eap, expr + 3); @@ -1434,8 +1434,8 @@ static void ex_let_const(exarg_T *eap, const bool is_const) if (!eap->skip) { op[0] = '='; op[1] = NUL; - (void)ex_let_vars(eap->arg, &rettv, false, semicolon, var_count, - is_const, op); + (void)ex_let_vars((char *)eap->arg, &rettv, false, semicolon, var_count, + is_const, (char *)op); } tv_clear(&rettv); } @@ -1449,23 +1449,23 @@ static void ex_let_const(exarg_T *eap, const bool is_const) expr++; } } - expr = skipwhite(expr + 2); + expr = (char *)skipwhite((char_u *)expr + 2); } else { - expr = skipwhite(expr + 1); + expr = (char *)skipwhite((char_u *)expr + 1); } if (eap->skip) { ++emsg_skip; } - i = eval0(expr, &rettv, &eap->nextcmd, !eap->skip); + i = eval0(expr, &rettv, (char **)&eap->nextcmd, !eap->skip); if (eap->skip) { if (i != FAIL) { tv_clear(&rettv); } emsg_skip--; } else if (i != FAIL) { - (void)ex_let_vars(eap->arg, &rettv, false, semicolon, var_count, - is_const, op); + (void)ex_let_vars((char *)eap->arg, &rettv, false, semicolon, var_count, + is_const, (char *)op); tv_clear(&rettv); } } @@ -1483,10 +1483,10 @@ static void ex_let_const(exarg_T *eap, const bool is_const) /// @param is_const lock variables for :const /// /// @return OK or FAIL; -static int ex_let_vars(char_u *arg_start, typval_T *tv, int copy, int semicolon, int var_count, - int is_const, char_u *op) +static int ex_let_vars(char *arg_start, typval_T *tv, int copy, int semicolon, int var_count, + int is_const, char *op) { - char_u *arg = arg_start; + char *arg = arg_start; typval_T ltv; if (*arg != '[') { @@ -1522,16 +1522,15 @@ static int ex_let_vars(char_u *arg_start, typval_T *tv, int copy, int semicolon, listitem_T *item = tv_list_first(l); size_t rest_len = tv_list_len(l); while (*arg != ']') { - arg = skipwhite(arg + 1); - arg = ex_let_one(arg, TV_LIST_ITEM_TV(item), true, is_const, - (const char_u *)",;]", op); + arg = (char *)skipwhite((char_u *)arg + 1); + arg = ex_let_one(arg, TV_LIST_ITEM_TV(item), true, is_const, ",;]", op); if (arg == NULL) { return FAIL; } rest_len--; item = TV_LIST_ITEM_NEXT(l, item); - arg = skipwhite(arg); + arg = (char *)skipwhite((char_u *)arg); if (*arg == ';') { /* Put the rest of the list (may be empty) in the var after ';'. * Create a new list for this. */ @@ -1546,8 +1545,7 @@ static int ex_let_vars(char_u *arg_start, typval_T *tv, int copy, int semicolon, ltv.vval.v_list = rest_list; tv_list_ref(rest_list); - arg = ex_let_one(skipwhite(arg + 1), <v, false, is_const, (char_u *)"]", - op); + arg = ex_let_one((char *)skipwhite((char_u *)arg + 1), <v, false, is_const, "]", op); tv_clear(<v); if (arg == NULL) { return FAIL; @@ -1568,24 +1566,24 @@ static int ex_let_vars(char_u *arg_start, typval_T *tv, int copy, int semicolon, /// for "[var, var; var]" set "semicolon". /// /// @return NULL for an error. -static const char_u *skip_var_list(const char_u *arg, int *var_count, int *semicolon) +static const char *skip_var_list(const char *arg, int *var_count, int *semicolon) { - const char_u *p; - const char_u *s; + const char *p; + const char *s; if (*arg == '[') { // "[var, var]": find the matching ']'. p = arg; for (;;) { - p = skipwhite(p + 1); // skip whites after '[', ';' or ',' - s = skip_var_one(p); + p = (char *)skipwhite((char_u *)p + 1); // skip whites after '[', ';' or ',' + s = skip_var_one((char *)p); if (s == p) { semsg(_(e_invarg2), p); return NULL; } ++*var_count; - p = skipwhite(s); + p = (char *)skipwhite((char_u *)s); if (*p == ']') { break; } else if (*p == ';') { @@ -1601,19 +1599,19 @@ static const char_u *skip_var_list(const char_u *arg, int *var_count, int *semic } return p + 1; } else { - return skip_var_one(arg); + return skip_var_one((char *)arg); } } /// Skip one (assignable) variable name, including @r, $VAR, &option, d.key, /// l[idx]. -static const char_u *skip_var_one(const char_u *arg) +static const char *skip_var_one(const char *arg) { if (*arg == '@' && arg[1] != NUL) { return arg + 2; } - return find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg, - NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); + return (char *)find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg, + NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); } /// List variables for hashtab "ht" with prefix "prefix". @@ -1696,8 +1694,7 @@ static const char *list_arg_vars(exarg_T *eap, const char *arg, int *first) while (!ends_excmd(*arg) && !got_int) { if (error || eap->skip) { - arg = (const char *)find_name_end((char_u *)arg, NULL, NULL, - FNE_INCL_BR | FNE_CHECK_START); + arg = find_name_end(arg, NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); if (!ascii_iswhite(*arg) && !ends_excmd(*arg)) { emsg_severe = true; emsg(_(e_trailing)); @@ -1727,9 +1724,7 @@ static const char *list_arg_vars(exarg_T *eap, const char *arg, int *first) } else { // handle d.key, l[idx], f(expr) const char *const arg_subsc = arg; - if (handle_subscript(&arg, &tv, true, true, (const char_u *)name, - (const char_u **)&name) - == FAIL) { + if (handle_subscript(&arg, &tv, true, true, name, &name) == FAIL) { error = true; } else { if (arg == arg_subsc && len == 2 && name[1] == ':') { @@ -1790,14 +1785,14 @@ static const char *list_arg_vars(exarg_T *eap, const char *arg, int *first) /// /// @return a pointer to the char just after the var name or NULL in case of /// error. -static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, const bool is_const, - const char_u *const endchars, const char_u *const op) +static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bool is_const, + const char *const endchars, const char *const op) FUNC_ATTR_NONNULL_ARG(1, 2) FUNC_ATTR_WARN_UNUSED_RESULT { - char_u *arg_end = NULL; + char *arg_end = NULL; int len; int opt_flags; - char_u *tofree = NULL; + char *tofree = NULL; /* * ":let $VAR = expr": Set environment variable. @@ -1809,15 +1804,15 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons } // Find the end of the name. arg++; - char *name = (char *)arg; - len = get_env_len((const char_u **)&arg); + char *name = arg; + len = get_env_len((const char **)&arg); if (len == 0) { semsg(_(e_invarg2), name - 1); } else { if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL) { semsg(_(e_letwrong), op); } else if (endchars != NULL - && vim_strchr(endchars, *skipwhite(arg)) == NULL) { + && vim_strchr((char_u *)endchars, *skipwhite((char_u *)arg)) == NULL) { emsg(_(e_letunexp)); } else if (!check_secure()) { const char c1 = name[len]; @@ -1827,7 +1822,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons char *s = vim_getenv(name); if (s != NULL) { - tofree = concat_str((const char_u *)s, (const char_u *)p); + tofree = (char *)concat_str((const char_u *)s, (const char_u *)p); p = (const char *)tofree; xfree(s); } @@ -1860,7 +1855,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons char *const p = (char *)find_option_end((const char **)&arg, &opt_flags); if (p == NULL || (endchars != NULL - && vim_strchr(endchars, *skipwhite((const char_u *)p)) == NULL)) { + && vim_strchr((char_u *)endchars, *skipwhite((const char_u *)p)) == NULL)) { emsg(_(e_letunexp)); } else { int opt_type; @@ -1876,7 +1871,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons s = tv_get_string_chk(tv); // != NULL if number or string. } if (s != NULL && op != NULL && *op != '=') { - opt_type = get_option_value((char *)arg, &numval, (char_u **)&stringval, + opt_type = get_option_value(arg, &numval, (char_u **)&stringval, opt_flags); if ((opt_type == 1 && *op == '.') || (opt_type == 0 && *op != '.')) { @@ -1908,7 +1903,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons if (s != NULL || tv->v_type == VAR_BOOL || tv->v_type == VAR_SPECIAL) { set_option_value((const char *)arg, n, s, opt_flags); - arg_end = (char_u *)p; + arg_end = p; } *p = c1; xfree(stringval); @@ -1923,17 +1918,17 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons if (op != NULL && vim_strchr((char_u *)"+-*/%", *op) != NULL) { semsg(_(e_letwrong), op); } else if (endchars != NULL - && vim_strchr(endchars, *skipwhite(arg + 1)) == NULL) { + && vim_strchr((char_u *)endchars, *skipwhite((char_u *)arg + 1)) == NULL) { emsg(_(e_letunexp)); } else { - char_u *s; + char *s; - char_u *ptofree = NULL; + char *ptofree = NULL; const char *p = tv_get_string_chk(tv); if (p != NULL && op != NULL && *op == '.') { s = get_reg_contents(*arg == '@' ? '"' : *arg, kGRegExprSrc); if (s != NULL) { - ptofree = concat_str(s, (const char_u *)p); + ptofree = (char *)concat_str((char_u *)s, (const char_u *)p); p = (const char *)ptofree; xfree(s); } @@ -1953,12 +1948,12 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons else if (eval_isnamec1(*arg) || *arg == '{') { lval_T lv; - char_u *const p = get_lval(arg, tv, &lv, false, false, 0, FNE_CHECK_START); + char *const p = get_lval(arg, tv, &lv, false, false, 0, FNE_CHECK_START); if (p != NULL && lv.ll_name != NULL) { - if (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL) { + if (endchars != NULL && vim_strchr((char_u *)endchars, *skipwhite((char_u *)p)) == NULL) { emsg(_(e_letunexp)); } else { - set_var_lval(&lv, p, tv, copy, is_const, (const char *)op); + set_var_lval(&lv, p, tv, copy, is_const, op); arg_end = p; } } @@ -1995,8 +1990,8 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, const bool copy, cons /// /// @return A pointer to just after the name, including indexes. Returns NULL /// for a parsing error, but it is still needed to free items in lp. -char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, const bool unlet, - const bool skip, const int flags, const int fne_flags) +char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const bool unlet, + const bool skip, const int flags, const int fne_flags) FUNC_ATTR_NONNULL_ARG(1, 3) { dictitem_T *v; @@ -2013,17 +2008,16 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co if (skip) { // When skipping just find the end of the name. lp->ll_name = (const char *)name; - return (char_u *)find_name_end((const char_u *)name, NULL, NULL, - FNE_INCL_BR | fne_flags); + return (char *)find_name_end(name, NULL, NULL, + FNE_INCL_BR | fne_flags); } // Find the end of the name. - char_u *expr_start; - char_u *expr_end; - char_u *p = (char_u *)find_name_end(name, - (const char_u **)&expr_start, - (const char_u **)&expr_end, - fne_flags); + char *expr_start; + char *expr_end; + char *p = (char *)find_name_end(name, (const char **)&expr_start, + (const char **)&expr_end, + fne_flags); if (expr_start != NULL) { // Don't expand the name when we already know there is an error. if (unlet && !ascii_iswhite(*p) && !ends_excmd(*p) @@ -2032,8 +2026,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co return NULL; } - lp->ll_exp_name = (char *)make_expanded_name(name, expr_start, expr_end, - p); + lp->ll_exp_name = make_expanded_name(name, expr_start, expr_end, p); lp->ll_name = lp->ll_exp_name; if (lp->ll_exp_name == NULL) { // Report an invalid expression in braces, unless the @@ -2092,7 +2085,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co } int len = -1; - char_u *key = NULL; + char *key = NULL; if (*p == '.') { key = p + 1; for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; len++) {} @@ -2105,7 +2098,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co p = key + len; } else { // Get the index [expr] or the first index [expr: ]. - p = skipwhite(p + 1); + p = (char *)skipwhite((char_u *)p + 1); if (*p == ':') { empty1 = true; } else { @@ -2118,7 +2111,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co tv_clear(&var1); return NULL; } - p = skipwhite(p); + p = (char *)skipwhite((char_u *)p); } // Optionally get the second index [ :expr]. @@ -2139,7 +2132,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co tv_clear(&var1); return NULL; } - p = skipwhite(p + 1); + p = (char *)skipwhite((char_u *)p + 1); if (*p == ']') { lp->ll_empty2 = true; } else { @@ -2176,7 +2169,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co if (lp->ll_tv->v_type == VAR_DICT) { if (len == -1) { // "[key]": get key from "var1" - key = (char_u *)tv_get_string(&var1); // is number or string + key = (char *)tv_get_string(&var1); // is number or string } lp->ll_list = NULL; lp->ll_dict = lp->ll_tv->vval.v_dict; @@ -2190,7 +2183,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co int wrong; if (len != -1) { - prevval = key[len]; + prevval = (char_u)key[len]; key[len] = NUL; } else { prevval = 0; // Avoid compiler warning. @@ -2232,9 +2225,9 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co return NULL; } if (len == -1) { - lp->ll_newkey = vim_strsave(key); + lp->ll_newkey = xstrdup(key); } else { - lp->ll_newkey = vim_strnsave(key, len); + lp->ll_newkey = xstrnsave(key, len); } tv_clear(&var1); break; @@ -2361,7 +2354,7 @@ void clear_lval(lval_T *lp) /// @param endp points to just after the parsed name. /// @param op NULL, "+" for "+=", "-" for "-=", "*" for "*=", "/" for "/=", /// "%" for "%=", "." for ".=" or "=" for "=". -static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, const bool is_const, +static void set_var_lval(lval_T *lp, char *endp, typval_T *rettv, int copy, const bool is_const, const char *op) { int cc; @@ -2369,7 +2362,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, co dictitem_T *di; if (lp->ll_tv == NULL) { - cc = *endp; + cc = (char_u)(*endp); *endp = NUL; if (lp->ll_blob != NULL) { if (op != NULL && *op != '=') { @@ -2398,7 +2391,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, co } } else { bool error = false; - const char_u val = tv_get_number_chk(rettv, &error); + const char val = tv_get_number_chk(rettv, &error); if (!error) { garray_T *const gap = &lp->ll_blob->bv_ga; @@ -2551,7 +2544,7 @@ notify: if (watched) { if (oldtv.v_type == VAR_UNKNOWN) { assert(lp->ll_newkey != NULL); - tv_dict_watcher_notify(dict, (char *)lp->ll_newkey, lp->ll_tv, NULL); + tv_dict_watcher_notify(dict, lp->ll_newkey, lp->ll_tv, NULL); } else { dictitem_T *di_ = lp->ll_di; assert(di_->di_key != NULL); @@ -2570,21 +2563,21 @@ notify: /// @param[out] *errp set to TRUE for an error, FALSE otherwise; /// /// @return a pointer that holds the info. Null when there is an error. -void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip) +void *eval_for_line(const char *arg, bool *errp, char **nextcmdp, int skip) { forinfo_T *fi = xcalloc(1, sizeof(forinfo_T)); - const char_u *expr; |