aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c2086
1 files changed, 1054 insertions, 1032 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 2736e9a14f..1a9af639a3 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -20,12 +20,12 @@
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/edit.h"
-#include "nvim/eval/userfunc.h"
#include "nvim/eval.h"
#include "nvim/eval/encode.h"
#include "nvim/eval/executor.h"
#include "nvim/eval/gc.h"
#include "nvim/eval/typval.h"
+#include "nvim/eval/userfunc.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
@@ -66,7 +66,7 @@ static char *e_dictrange = N_("E719: Cannot use [:] with a Dictionary");
static char *e_illvar = N_("E461: Illegal variable name: %s");
static char *e_cannot_mod = N_("E995: Cannot modify existing variable");
static char *e_nowhitespace
- = N_("E274: No white space allowed before parenthesis");
+ = N_("E274: No white space allowed before parenthesis");
static char *e_invalwindow = N_("E957: Invalid window number");
static char *e_lock_unlock = N_("E940: Cannot lock or unlock variable %s");
static char *e_write2 = N_("E80: Error while writing: %s");
@@ -97,7 +97,7 @@ typedef struct {
dict_T sv_dict;
} scriptvar_T;
-static garray_T ga_scripts = {0, 0, sizeof(scriptvar_T *), 4, NULL};
+static garray_T ga_scripts = { 0, 0, sizeof(scriptvar_T *), 4, NULL };
#define SCRIPT_SV(id) (((scriptvar_T **)ga_scripts.ga_data)[(id) - 1])
#define SCRIPT_VARS(id) (SCRIPT_SV(id)->sv_dict.dv_hashtab)
@@ -113,7 +113,7 @@ typedef struct {
int fi_semicolon; // TRUE if ending in '; var]'
int fi_varcount; // nr of variables in the list
listwatch_T fi_lw; // keep an eye on the item used.
- list_T *fi_list; // list being used
+ list_T *fi_list; // list being used
int fi_bi; // index of blob
blob_T *fi_blob; // blob being used
} forinfo_T;
@@ -139,7 +139,7 @@ typedef struct {
// The reason to use this table anyway is for very quick access to the
// variables with the VV_ defines.
static struct vimvar {
- char *vv_name; ///< Name of the variable, without v:.
+ char *vv_name; ///< Name of the variable, without v:.
TV_DICTITEM_STRUCT(17) vv_di; ///< Value and name for key (max 16 chars).
char vv_flags; ///< Flags: #VV_COMPAT, #VV_RO, #VV_RO_SBX.
} vimvars[] =
@@ -334,7 +334,7 @@ void eval_init(void)
{
vimvars[VV_VERSION].vv_nr = VIM_VERSION_100;
- struct vimvar *p;
+ struct vimvar *p;
init_var_dict(&globvardict, &globvars_var, VAR_DEF_SCOPE);
init_var_dict(&vimvardict, &vimvars_var, VAR_SCOPE);
@@ -346,12 +346,13 @@ void eval_init(void)
p = &vimvars[i];
assert(STRLEN(p->vv_name) <= 16);
STRCPY(p->vv_di.di_key, p->vv_name);
- if (p->vv_flags & VV_RO)
+ if (p->vv_flags & VV_RO) {
p->vv_di.di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
- else if (p->vv_flags & VV_RO_SBX)
+ } else if (p->vv_flags & VV_RO_SBX) {
p->vv_di.di_flags = DI_FLAGS_RO_SBX | DI_FLAGS_FIX;
- else
+ } else {
p->vv_di.di_flags = DI_FLAGS_FIX;
+ }
// add to v: scope dict, unless the value is not always available
if (p->vv_type != VAR_UNKNOWN) {
@@ -424,7 +425,7 @@ void eval_init(void)
#if defined(EXITFREE)
void eval_clear(void)
{
- struct vimvar *p;
+ struct vimvar *p;
for (size_t i = 0; i < ARRAY_SIZE(vimvars); i++) {
p = &vimvars[i];
@@ -451,10 +452,12 @@ void eval_clear(void)
/* Script-local variables. First clear all the variables and in a second
* loop free the scriptvar_T, because a variable in one script might hold
* a reference to the whole scope of another script. */
- for (int i = 1; i <= ga_scripts.ga_len; ++i)
+ for (int i = 1; i <= ga_scripts.ga_len; ++i) {
vars_clear(&SCRIPT_VARS(i));
- for (int i = 1; i <= ga_scripts.ga_len; ++i)
+ }
+ for (int i = 1; i <= ga_scripts.ga_len; ++i) {
xfree(SCRIPT_SV(i));
+ }
ga_clear(&ga_scripts);
// unreferenced lists and dicts
@@ -481,20 +484,16 @@ void set_internal_string_var(const char *name, char_u *value)
set_var(name, strlen(name), &tv, true);
}
-static lval_T *redir_lval = NULL;
+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_u *redir_varname = NULL;
-/*
- * Start recording command output to a variable
- * Returns OK if successfully completed the setup. FAIL otherwise.
- */
-int
-var_redir_start(
- char_u *name,
- int append // append to an existing variable
-)
+/// Start recording command output to a variable
+/// Returns OK if successfully completed the setup. FAIL otherwise.
+///
+/// @param append append to an existing variable
+int var_redir_start(char_u *name, int append)
{
int save_emsg;
int err;
@@ -567,8 +566,9 @@ void var_redir_str(char_u *value, int value_len)
{
int len;
- if (redir_lval == NULL)
+ if (redir_lval == NULL) {
return;
+ }
if (value_len == -1) {
len = (int)STRLEN(value); // Append the entire string
@@ -655,8 +655,7 @@ int eval_printexpr(const char *const fname, const char *const args)
return OK;
}
-void eval_diff(const char *const origfile, const char *const newfile,
- const char *const outfile)
+void eval_diff(const char *const origfile, const char *const newfile, const char *const outfile)
{
bool err = false;
@@ -669,8 +668,7 @@ void eval_diff(const char *const origfile, const char *const newfile,
set_vim_var_string(VV_FNAME_OUT, NULL, -1);
}
-void eval_patch(const char *const origfile, const char *const difffile,
- const char *const outfile)
+void eval_patch(const char *const origfile, const char *const difffile, const char *const outfile)
{
bool err = false;
@@ -683,18 +681,13 @@ void eval_patch(const char *const origfile, const char *const difffile,
set_vim_var_string(VV_FNAME_OUT, NULL, -1);
}
-/*
- * Top level evaluation function, returning a boolean.
- * Sets "error" to TRUE if there was an error.
- * Return TRUE or FALSE.
- */
-int
-eval_to_bool(
- char_u *arg,
- bool *error,
- char_u **nextcmd,
- int skip // only parse, don't execute
-)
+/// Top level evaluation function, returning a boolean.
+/// Sets "error" to TRUE if there was an error.
+///
+/// @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)
{
typval_T tv;
bool retval = false;
@@ -741,8 +734,7 @@ static int eval1_emsg(char_u **arg, typval_T *rettv, bool evaluate)
return ret;
}
-int eval_expr_typval(const typval_T *expr, typval_T *argv,
- int argc, typval_T *rettv)
+int eval_expr_typval(const typval_T *expr, typval_T *argv, int argc, typval_T *rettv)
FUNC_ATTR_NONNULL_ARG(1, 2, 4)
{
funcexe_T funcexe = FUNCEXE_INIT;
@@ -811,8 +803,7 @@ bool eval_expr_to_bool(const typval_T *expr, bool *error)
///
/// @return [allocated] string result of evaluation or NULL in case of error or
/// when skipping.
-char *eval_to_string_skip(const char *arg, const char **nextcmd,
- const bool skip)
+char *eval_to_string_skip(const char *arg, const char **nextcmd, const bool skip)
FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT
{
typval_T tv;
@@ -890,7 +881,7 @@ char_u *eval_to_string(char_u *arg, char_u **nextcmd, bool convert)
*/
char_u *eval_to_string_safe(char_u *arg, char_u **nextcmd, int use_sandbox)
{
- char_u *retval;
+ char_u *retval;
funccal_entry_T funccal_entry;
save_funccal(&funccal_entry);
@@ -916,7 +907,7 @@ varnumber_T eval_to_number(char_u *expr)
{
typval_T rettv;
varnumber_T retval;
- char_u *p = skipwhite(expr);
+ char_u *p = skipwhite(expr);
++emsg_off;
@@ -951,8 +942,9 @@ typval_T *eval_expr(char_u *arg)
void prepare_vimvar(int idx, typval_T *save_tv)
{
*save_tv = vimvars[idx].vv_tv;
- if (vimvars[idx].vv_type == VAR_UNKNOWN)
+ if (vimvars[idx].vv_type == VAR_UNKNOWN) {
hash_add(&vimvarht, vimvars[idx].vv_di.di_key);
+ }
}
/*
@@ -961,7 +953,7 @@ void prepare_vimvar(int idx, typval_T *save_tv)
*/
void restore_vimvar(int idx, typval_T *save_tv)
{
- hashitem_T *hi;
+ hashitem_T *hi;
vimvars[idx].vv_tv = *save_tv;
if (vimvars[idx].vv_type == VAR_UNKNOWN) {
@@ -994,15 +986,16 @@ list_T *eval_spell_expr(char_u *badword, char_u *expr)
{
typval_T save_val;
typval_T rettv;
- list_T *list = NULL;
- char_u *p = skipwhite(expr);
+ list_T *list = NULL;
+ char_u *p = skipwhite(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;
- if (p_verbose == 0)
+ if (p_verbose == 0) {
++emsg_off;
+ }
if (eval1(&p, &rettv, true) == OK) {
if (rettv.v_type != VAR_LIST) {
@@ -1012,8 +1005,9 @@ list_T *eval_spell_expr(char_u *badword, char_u *expr)
}
}
- if (p_verbose == 0)
+ if (p_verbose == 0) {
--emsg_off;
+ }
restore_vimvar(VV_VAL, &save_val);
return list;
@@ -1052,12 +1046,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_u *func, int argc, typval_T *argv, typval_T *rettv)
FUNC_ATTR_NONNULL_ALL
{
int ret;
@@ -1096,8 +1085,7 @@ 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_u *func, int argc, typval_T *argv)
FUNC_ATTR_NONNULL_ALL
{
typval_T rettv;
@@ -1118,8 +1106,7 @@ varnumber_T call_func_retnr(const char_u *func, int argc,
///
/// @return [allocated] NULL when calling function fails, allocated string
/// otherwise.
-char *call_func_retstr(const char *const func, int argc,
- typval_T *argv)
+char *call_func_retstr(const char *const func, int argc, typval_T *argv)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
{
typval_T rettv;
@@ -1159,14 +1146,12 @@ void *call_func_retlist(const char_u *func, int argc, typval_T *argv)
return rettv.vval.v_list;
}
-/*
- * Prepare profiling for entering a child or something else that is not
- * counted for the script/function itself.
- * Should always be called in pair with prof_child_exit().
- */
-void prof_child_enter(
- proftime_T *tm // place to store waittime
-)
+/// Prepare profiling for entering a child or something else that is not
+/// counted for the script/function itself.
+/// Should always be called in pair with prof_child_exit().
+///
+/// @param tm place to store waittime
+void prof_child_enter(proftime_T *tm)
{
funccall_T *fc = get_current_funccal();
@@ -1177,13 +1162,11 @@ void prof_child_enter(
script_prof_save(tm);
}
-/*
- * Take care of time spent in a child.
- * Should always be called after prof_child_enter().
- */
-void prof_child_exit(
- proftime_T *tm // where waittime was stored
-)
+/// Take care of time spent in a child.
+/// Should always be called after prof_child_enter().
+///
+/// @param tm where waittime was stored
+void prof_child_exit(proftime_T *tm)
{
funccall_T *fc = get_current_funccal();
@@ -1211,8 +1194,9 @@ int eval_foldexpr(char_u *arg, int *cp)
int use_sandbox = was_set_insecurely(curwin, (char_u *)"foldexpr", OPT_LOCAL);
++emsg_off;
- if (use_sandbox)
+ if (use_sandbox) {
++sandbox;
+ }
++textlock;
*cp = NUL;
if (eval0(arg, &tv, NULL, true) == FAIL) {
@@ -1235,8 +1219,9 @@ int eval_foldexpr(char_u *arg, int *cp)
tv_clear(&tv);
}
--emsg_off;
- if (use_sandbox)
+ if (use_sandbox) {
--sandbox;
+ }
--textlock;
return (int)retval;
@@ -1262,8 +1247,7 @@ void ex_const(exarg_T *eap)
// marker, then the leading indentation before the lines (matching the
// indentation in the 'cmd' line) is stripped.
// Returns 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_u *cmd)
{
char_u *marker;
char_u *p;
@@ -1327,29 +1311,29 @@ heredoc_get(exarg_T *eap, char_u *cmd)
// marker
if (marker_indent_len > 0
&& STRNCMP(theline, *eap->cmdlinep, marker_indent_len) == 0) {
- mi = marker_indent_len;
+ mi = marker_indent_len;
}
if (STRCMP(marker, theline + mi) == 0) {
xfree(theline);
break;
}
if (text_indent_len == -1 && *theline != NUL) {
- // set the text indent from the first line.
- p = theline;
- text_indent_len = 0;
- while (ascii_iswhite(*p)) {
- p++;
- text_indent_len++;
- }
- text_indent = vim_strnsave(theline, text_indent_len);
+ // set the text indent from the first line.
+ p = theline;
+ text_indent_len = 0;
+ while (ascii_iswhite(*p)) {
+ p++;
+ text_indent_len++;
+ }
+ text_indent = vim_strnsave(theline, text_indent_len);
}
// with "trim": skip the indent matching the first line
if (text_indent != NULL) {
- for (ti = 0; ti < text_indent_len; ti++) {
- if (theline[ti] != text_indent[ti]) {
- break;
- }
+ for (ti = 0; ti < text_indent_len; ti++) {
+ if (theline[ti] != text_indent[ti]) {
+ break;
}
+ }
}
tv_list_append_string(l, (char *)(theline + ti), -1);
@@ -1379,14 +1363,14 @@ 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_u *arg = eap->arg;
+ char_u *expr = NULL;
typval_T rettv;
int i;
int var_count = 0;
int semicolon = 0;
char_u op[2];
- char_u *argend;
+ char_u *argend;
int first = TRUE;
argend = (char_u *)skip_var_list(arg, &var_count, &semicolon);
@@ -1444,8 +1428,9 @@ static void ex_let_const(exarg_T *eap, const bool is_const)
expr = skipwhite(expr + 1);
}
- if (eap->skip)
+ if (eap->skip) {
++emsg_skip;
+ }
i = eval0(expr, &rettv, &eap->nextcmd, !eap->skip);
if (eap->skip) {
if (i != FAIL) {
@@ -1460,21 +1445,20 @@ static void ex_let_const(exarg_T *eap, const bool is_const)
}
}
-/*
- * Assign the typevalue "tv" to the variable or variables at "arg_start".
- * Handles both "var" with any type and "[var, var; var]" with a list type.
- * When "op" is not NULL it points to a string with characters that
- * must appear after the variable(s). Use "+", "-" or "." for add, subtract
- * or concatenate.
- * Returns OK or FAIL;
- */
-static int ex_let_vars(char_u *arg_start,
- typval_T *tv,
- int copy, // copy values from "tv", don't move
- int semicolon, // from skip_var_list()
- int var_count, // from skip_var_list()
- int is_const, // lock variables for :const
- char_u *op)
+/// Assign the typevalue "tv" to the variable or variables at "arg_start".
+/// Handles both "var" with any type and "[var, var; var]" with a list type.
+/// When "op" is not NULL it points to a string with characters that
+/// must appear after the variable(s). Use "+", "-" or "." for add, subtract
+/// or concatenate.
+///
+/// @param copy copy values from "tv", don't move
+/// @param semicolon from skip_var_list()
+/// @param var_count from skip_var_list()
+/// @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)
{
char_u *arg = arg_start;
typval_T ltv;
@@ -1559,8 +1543,7 @@ static int ex_let_vars(char_u *arg_start,
* 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_u *skip_var_list(const char_u *arg, int *var_count, int *semicolon)
{
const char_u *p;
const char_u *s;
@@ -1578,9 +1561,9 @@ static const char_u *skip_var_list(const char_u *arg, int *var_count,
++*var_count;
p = skipwhite(s);
- if (*p == ']')
+ if (*p == ']') {
break;
- else if (*p == ';') {
+ } else if (*p == ';') {
if (*semicolon == 1) {
EMSG(_("E452: Double ; in list of variables"));
return NULL;
@@ -1592,8 +1575,9 @@ static const char_u *skip_var_list(const char_u *arg, int *var_count,
}
}
return p + 1;
- } else
+ } else {
return skip_var_one(arg);
+ }
}
/*
@@ -1602,21 +1586,21 @@ static const char_u *skip_var_list(const char_u *arg, int *var_count,
*/
static const char_u *skip_var_one(const char_u *arg)
{
- if (*arg == '@' && arg[1] != NUL)
+ 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);
+ NULL, NULL, FNE_INCL_BR | FNE_CHECK_START);
}
/*
* List variables for hashtab "ht" with prefix "prefix".
* If "empty" is TRUE also list NULL strings as empty strings.
*/
-void list_hashtable_vars(hashtab_T *ht, const char *prefix, int empty,
- int *first)
+void list_hashtable_vars(hashtab_T *ht, const char *prefix, int empty, int *first)
{
- hashitem_T *hi;
- dictitem_T *di;
+ hashitem_T *hi;
+ dictitem_T *di;
int todo;
todo = (int)ht->ht_used;
@@ -1740,13 +1724,20 @@ static const char *list_arg_vars(exarg_T *eap, const char *arg, int *first)
} else {
if (arg == arg_subsc && len == 2 && name[1] == ':') {
switch (*name) {
- case 'g': list_glob_vars(first); break;
- case 'b': list_buf_vars(first); break;
- case 'w': list_win_vars(first); break;
- case 't': list_tab_vars(first); break;
- case 'v': list_vim_vars(first); break;
- case 's': list_script_vars(first); break;
- case 'l': list_func_vars(first); break;
+ case 'g':
+ list_glob_vars(first); break;
+ case 'b':
+ list_buf_vars(first); break;
+ case 'w':
+ list_win_vars(first); break;
+ case 't':
+ list_tab_vars(first); break;
+ case 'v':
+ list_vim_vars(first); break;
+ case 's':
+ list_script_vars(first); break;
+ case 'l':
+ list_func_vars(first); break;
default:
EMSG2(_("E738: Can't list variables for %s"), name);
}
@@ -1789,8 +1780,7 @@ 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,
+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)
FUNC_ATTR_NONNULL_ARG(1, 2) FUNC_ATTR_WARN_UNUSED_RESULT
{
@@ -1848,9 +1838,9 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv,
xfree(tofree);
}
}
- // ":let &option = expr": Set option value.
- // ":let &l:option = expr": Set local option value.
- // ":let &g:option = expr": Set global option value.
+ // ":let &option = expr": Set option value.
+ // ":let &l:option = expr": Set local option value.
+ // ":let &g:option = expr": Set global option value.
} else if (*arg == '&') {
if (is_const) {
EMSG(_("E996: Cannot lock an option"));
@@ -1885,11 +1875,16 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv,
} else {
if (opt_type == 1) { // number
switch (*op) {
- case '+': n = numval + n; break;
- case '-': n = numval - n; break;
- case '*': n = numval * n; break;
- case '/': n = num_divide(numval, n); break;
- case '%': n = num_modulus(numval, n); break;
+ case '+':
+ n = numval + n; break;
+ case '-':
+ n = numval - n; break;
+ case '*':
+ n = numval * n; break;
+ case '/':
+ n = num_divide(numval, n); break;
+ case '%':
+ n = num_modulus(numval, n); break;
}
} else if (opt_type == 0 && stringval != NULL) { // string
char *const oldstringval = stringval;
@@ -1908,7 +1903,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv,
*p = c1;
xfree(stringval);
}
- // ":let @r = expr": Set register contents.
+ // ":let @r = expr": Set register contents.
} else if (*arg == '@') {
if (is_const) {
EMSG(_("E996: Cannot lock a register"));
@@ -1921,7 +1916,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv,
&& vim_strchr(endchars, *skipwhite(arg + 1)) == NULL) {
EMSG(_(e_letunexp));
} else {
- char_u *s;
+ char_u *s;
char_u *ptofree = NULL;
const char *p = tv_get_string_chk(tv);
@@ -1958,8 +1953,9 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv,
}
}
clear_lval(&lv);
- } else
+ } else {
EMSG2(_(e_invarg2), arg);
+ }
return arg_end;
}
@@ -1989,16 +1985,15 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv,
///
/// @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_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)
FUNC_ATTR_NONNULL_ARG(1, 3)
{
- dictitem_T *v;
+ dictitem_T *v;
typval_T var1;
typval_T var2;
int empty1 = FALSE;
- listitem_T *ni;
+ listitem_T *ni;
hashtab_T *ht = NULL;
int quiet = flags & GLV_QUIET;
@@ -2080,8 +2075,9 @@ char_u *get_lval(char_u *const name, typval_T *const rettv,
return NULL;
}
if (lp->ll_range) {
- if (!quiet)
+ if (!quiet) {
EMSG(_("E708: [:] must come last"));
+ }
return NULL;
}
@@ -2233,7 +2229,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv,
}
tv_clear(&var1);
break;
- // existing variable, need to check if it can be changed
+ // existing variable, need to check if it can be changed
} else if (!(flags & GLV_READ_ONLY) && var_check_ro(lp->ll_di->di_flags,
(const char *)name,
(size_t)(p - name))) {
@@ -2312,8 +2308,9 @@ char_u *get_lval(char_u *const name, typval_T *const rettv,
if (lp->ll_n2 < 0) {
ni = tv_list_find(lp->ll_list, lp->ll_n2);
if (ni == NULL) {
- if (!quiet)
+ if (!quiet) {
EMSGN(_(e_listidx), lp->ll_n2);
+ }
return NULL;
}
lp->ll_n2 = tv_list_idx_of_item(lp->ll_list, ni);
@@ -2358,12 +2355,12 @@ void clear_lval(lval_T *lp)
* "op" is 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, const char *op)
+static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, const bool is_const,
+ const char *op)
{
int cc;
- listitem_T *ri;
- dictitem_T *di;
+ listitem_T *ri;
+ dictitem_T *di;
if (lp->ll_tv == NULL) {
cc = *endp;
@@ -2568,16 +2565,17 @@ notify:
*/
void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip)
{
- forinfo_T *fi = xcalloc(1, sizeof(forinfo_T));
+ forinfo_T *fi = xcalloc(1, sizeof(forinfo_T));
const char_u *expr;
typval_T tv;
- list_T *l;
+ list_T *l;
*errp = true; // Default: there is an error.
expr = skip_var_list(arg, &fi->fi_varcount, &fi->fi_semicolon);
- if (expr == NULL)
+ if (expr == NULL) {
return fi;
+ }
expr = skipwhite(expr);
if (expr[0] != 'i' || expr[1] != 'n' || !ascii_iswhite(expr[2])) {
@@ -2585,8 +2583,9 @@ void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip)
return fi;
}
- if (skip)
+ if (skip) {
++emsg_skip;
+ }
if (eval0(skipwhite(expr + 2), &tv, nextcmdp, !skip) == OK) {
*errp = false;
if (!skip) {
@@ -2619,8 +2618,9 @@ void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip)
}
}
}
- if (skip)
+ if (skip) {
--emsg_skip;
+ }
return fi;
}
@@ -2667,7 +2667,7 @@ bool next_for_item(void *fi_void, char_u *arg)
*/
void free_for_info(void *fi_void)
{
- forinfo_T *fi = (forinfo_T *)fi_void;
+ forinfo_T *fi = (forinfo_T *)fi_void;
if (fi != NULL && fi->fi_list != NULL) {
tv_list_watch_remove(fi->fi_list, &fi->fi_lw);
@@ -2685,7 +2685,7 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx)
{
int got_eq = FALSE;
int c;
- char_u *p;
+ char_u *p;
if (cmdidx == CMD_let || cmdidx == CMD_const) {
xp->xp_context = EXPAND_USER_VARS;
@@ -2700,11 +2700,12 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx)
}
return;
}
- } else
+ } else {
xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS
- : EXPAND_EXPRESSION;
+ : EXPAND_EXPRESSION;
+ }
while ((xp->xp_pattern = vim_strpbrk(arg,
- (char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL) {
+ (char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL) {
c = *xp->xp_pattern;
if (c == '&') {
c = xp->xp_pattern[1];
@@ -2714,9 +2715,9 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx)
? EXPAND_EXPRESSION : EXPAND_NOTHING;
} else if (c != ' ') {
xp->xp_context = EXPAND_SETTINGS;
- if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':')
+ if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':') {
xp->xp_pattern += 2;
-
+ }
}
} else if (c == '$') {
// environment variable
@@ -2750,14 +2751,17 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx)
if (xp->xp_pattern[1] == '|') {
++xp->xp_pattern;
xp->xp_context = EXPAND_EXPRESSION;
- } else
+ } else {
xp->xp_context = EXPAND_COMMANDS;
- } else
+ }
+ } else {
xp->xp_context = EXPAND_EXPRESSION;
- } else
+ }
+ } else {
/* Doesn't look like something valid, expand as an expression
* anyway. */
xp->xp_context = EXPAND_EXPRESSION;
+ }
arg = xp->xp_pattern;
if (*arg != NUL) {
while ((c = *++arg) != NUL && (c == ' ' || c == '\t')) {
@@ -2819,8 +2823,7 @@ void ex_lockvar(exarg_T *eap)
/// @param[in] deep Levels to (un)lock for :(un)lockvar, -1 to (un)lock
/// everything.
/// @param[in] callback Appropriate handler for the command.
-static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep,
- ex_unletlock_callback callback)
+static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep, ex_unletlock_callback callback)
FUNC_ATTR_NONNULL_ALL
{
char_u *arg = argstart;
@@ -2884,8 +2887,7 @@ static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep,
/// @param[in] deep Unused.
///
/// @return OK on success, or FAIL on failure.
-static int do_unlet_var(lval_T *lp, char_u *name_end, exarg_T *eap,
- int deep FUNC_ATTR_UNUSED)
+static int do_unlet_var(lval_T *lp, char_u *name_end, exarg_T *eap, int deep FUNC_ATTR_UNUSED)
FUNC_ATTR_NONNULL_ALL
{
int forceit = eap->forceit;
@@ -2989,7 +2991,7 @@ int do_unlet(const char *const name, const size_t name_len, const bool forceit)
if (ht == &globvarht) {
d = &globvardict;
} else if (ht == &compat_hashtab) {
- d = &vimvardict;
+ d = &vimvardict;
} else {
dictitem_T *const di = find_var_in_ht(ht, *name, "", 0, false);
d = di->di_tv.vval.v_dict;
@@ -3032,8 +3034,9 @@ int do_unlet(const char *const name, const size_t name_len, const bool forceit)
return OK;
}
}
- if (forceit)
+ if (forceit) {
return OK;
+ }
EMSG2(_("E108: No such variable: \"%s\""), name);
return FAIL;
}
@@ -3050,8 +3053,7 @@ int do_unlet(const char *const name, const size_t name_len, const bool forceit)
/// @param[in] deep Levels to (un)lock, -1 to (un)lock everything.
///
/// @return OK on success, or FAIL on failure.
-static int do_lock_var(lval_T *lp, char_u *name_end FUNC_ATTR_UNUSED,
- exarg_T *eap, int deep)
+static int do_lock_var(lval_T *lp, char_u *name_end FUNC_ATTR_UNUSED, exarg_T *eap, int deep)
FUNC_ATTR_NONNULL_ARG(1, 3)
{
bool lock = eap->cmdidx == CMD_lockvar;
@@ -3067,9 +3069,8 @@ static int do_lock_var(lval_T *lp, char_u *name_end FUNC_ATTR_UNUSED,
ret = FAIL;
} else {
// Normal name or expanded name.
- dictitem_T *const di = find_var(
- (const char *)lp->ll_name, lp->ll_name_len, NULL,
- true);
+ dictitem_T *const di = find_var((const char *)lp->ll_name, lp->ll_name_len, NULL,
+ true);
if (di == NULL) {
ret = FAIL;
} else if ((di->di_flags & DI_FLAGS_FIX)
@@ -3089,7 +3090,7 @@ static int do_lock_var(lval_T *lp, char_u *name_end FUNC_ATTR_UNUSED,
}
}
} else if (lp->ll_range) {
- listitem_T *li = lp->ll_li;
+ listitem_T *li = lp->ll_li;
// (un)lock a range of List items.
while (li != NULL && (lp->ll_empty2 || lp->ll_n2 >= lp->ll_n1)) {
@@ -3129,7 +3130,7 @@ void del_menutrans_vars(void)
*/
-static char_u *varnamebuf = NULL;
+static char_u *varnamebuf = NULL;
static size_t varnamebuflen = 0;
/*
@@ -3163,7 +3164,7 @@ char_u *get_user_var_name(expand_T *xp, int idx)
static size_t wdone;
static size_t tdone;
static size_t vidx;
- static hashitem_T *hi;
+ static hashitem_T *hi;
if (idx == 0) {
gdone = bdone = wdone = vidx = 0;
@@ -3172,14 +3173,17 @@ char_u *get_user_var_name(expand_T *xp, int idx)
// Global variables
if (gdone < globvarht.ht_used) {
- if (gdone++ == 0)
+ if (gdone++ == 0) {
hi = globvarht.ht_array;
- else
+ } else {
++hi;
- while (HASHITEM_EMPTY(hi))
+ }
+ while (HASHITEM_EMPTY(hi)) {
++hi;
- if (STRNCMP("g:", xp->xp_pattern, 2) == 0)
+ }
+ if (STRNCMP("g:", xp->xp_pattern, 2) == 0) {
return cat_prefix_varname('g', hi->hi_key);
+ }
return hi->hi_key;
}
@@ -3189,12 +3193,14 @@ char_u *get_user_var_name(expand_T *xp, int idx)
? &prevwin->w_buffer->b_vars->dv_hashtab
: &curbuf->b_vars->dv_hashtab;
if (bdone < ht->ht_used) {
- if (bdone++ == 0)
+ if (bdone++ == 0) {
hi = ht->ht_array;
- else
+ } else {
++hi;
- while (HASHITEM_EMPTY(hi))
+ }
+ while (HASHITEM_EMPTY(hi)) {
++hi;
+ }
return cat_prefix_varname('b', hi->hi_key);
}
@@ -3204,24 +3210,28 @@ char_u *get_user_var_name(expand_T *xp, int idx)
? &prevwin->w_vars->dv_hashtab
: &curwin->w_vars->dv_hashtab;
if (wdone < ht->ht_used) {
- if (wdone++ == 0)
+ if (wdone++ == 0) {
hi = ht->ht_array;
- else
+ } else {
++hi;
- while (HASHITEM_EMPTY(hi))
+ }
+ while (HASHITEM_EMPTY(hi)) {
++hi;
+ }
return cat_prefix_varname('w', hi->hi_key);
}
// t: variables
ht = &curtab->tp_vars->dv_hashtab;
if (tdone < ht->ht_used) {
- if (tdone++ == 0)
+ if (tdone++ == 0) {
hi = ht->ht_array;
- else
+ } else {
++hi;
- while (HASHITEM_EMPTY(hi))
+ }
+ while (HASHITEM_EMPTY(hi)) {
++hi;
+ }
return cat_prefix_varname('t', hi->hi_key);
}
@@ -3265,8 +3275,7 @@ static int pattern_match(char_u *pat, char_u *text, bool ic)
//
/// @return OK or FAIL.
static int eval_func(char_u **const arg, char_u *const name, const int name_len,
- typval_T *const rettv, const bool evaluate,
- typval_T *const basetv)
+ typval_T *const rettv, const bool evaluate, typval_T *const basetv)
FUNC_ATTR_NONNULL_ARG(1, 2, 4)
{
char_u *s = name;
@@ -3334,7 +3343,7 @@ static int eval_func(char_u **const arg, char_u *const name, const int name_len,
int eval0(char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate)
{
int ret;
- char_u *p;
+ char_u *p;
const int did_emsg_before = did_emsg;
const int called_emsg_before = called_emsg;
@@ -3354,8 +3363,9 @@ int eval0(char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate)
}
ret = FAIL;
}
- if (nextcmd != NULL)
+ if (nextcmd != NULL) {
*nextcmd = check_nextcmd(p);
+ }
return ret;
}
@@ -3364,7 +3374,7 @@ int eval0(char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate)
/*
* Handle top level expression:
- * expr2 ? expr1 : expr1
+ * expr2 ? expr1 : expr1
*
* "arg" must point to the first non-white of the expression.
* "arg" is advanced to the next non-white after the recognized expression.
@@ -3381,8 +3391,9 @@ int eval1(char_u **arg, typval_T *rettv, int evaluate)
/*
* Get the first variable.
*/
- if (eval2(arg, rettv, evaluate) == FAIL)
+ if (eval2(arg, rettv, evaluate) == FAIL) {
return FAIL;
+ }
if ((*arg)[0] == '?') {
result = FALSE;
@@ -3427,8 +3438,9 @@ int eval1(char_u **arg, typval_T *rettv, int evaluate)
}
return FAIL;
}
- if (evaluate && !result)
+ if (evaluate && !result) {
*rettv = var2;
+ }
}
return OK;
@@ -3438,7 +3450,7 @@ int eval1(char_u **arg, typval_T *rettv, int evaluate)
/*
* Handle first level expression:
- * expr2 || expr2 || expr2 logical OR
+ * expr2 || expr2 || expr2 logical OR
*
* "arg" must point to the first non-white of the expression.
* "arg" is advanced to the next non-white after the recognized expression.
@@ -3455,8 +3467,9 @@ static int eval2(char_u **arg, typval_T *rettv, int evaluate)
/*
* Get the first variable.
*/
- if (eval3(arg, rettv, evaluate) == FAIL)
+ if (eval3(arg, rettv, evaluate) == FAIL) {
return FAIL;
+ }
/*
* Repeat until there is no following "||".
@@ -3479,8 +3492,9 @@ static int eval2(char_u **arg, typval_T *rettv, int evaluate)
* Get the second variable.
*/
*arg = skipwhite(*arg + 2);
- if (eval3(arg, &var2, evaluate && !result) == FAIL)
+ if (eval3(arg, &var2, evaluate && !result) == FAIL) {
return FAIL;
+ }
/*
* Compute the result.
@@ -3507,7 +3521,7 @@ static int eval2(char_u **arg, typval_T *rettv, int evaluate)
/*
* Handle second level expression:
- * expr3 && expr3 && expr3 logical AND
+ * expr3 && expr3 && expr3 logical AND
*
* "arg" must point to the first non-white of the expression.
* "arg" is advanced to the next non-white after the recognized expression.
@@ -3524,8 +3538,9 @@ static int eval3(char_u **arg, typval_T *rettv, int evaluate)
/*
* Get the first variable.
*/
- if (eval4(arg, rettv, evaluate) == FAIL)
+ if (eval4(arg, rettv, evaluate) == FAIL) {
return FAIL;
+ }
/*
* Repeat until there is no following "&&".
@@ -3548,8 +3563,9 @@ static int eval3(char_u **arg, typval_T *rettv, int evaluate)
* Get the second variable.
*/
*arg = skipwhite(*arg + 2);
- if (eval4(arg, &var2, evaluate && result) == FAIL)
+ if (eval4(arg, &var2, evaluate && result) == FAIL) {
return FAIL;
+ }
/*
* Compute the result.
@@ -3576,16 +3592,16 @@ static int eval3(char_u **arg, typval_T *rettv, int evaluate)
/*
* Handle third level expression:
- * var1 == var2
- * var1 =~ var2
- * var1 != var2
- * var1 !~ var2
- * var1 > var2
- * var1 >= var2
- * var1 < var2
- * var1 <= var2
- * var1 is var2
- * var1 isnot var2
+ * var1 == var2
+ * var1 =~ var2
+ * var1 != var2
+ * var1 !~ var2
+ * var1 > var2
+ * var1 >= var2
+ * var1 < var2
+ * var1 <= var2
+ * var1 is var2
+ * var1 isnot var2
*
* "arg" must point to the first non-white of the expression.
* "arg" is advanced to the next non-white after the recognized expression.
@@ -3595,7 +3611,7 @@ static int eval3(char_u **arg, typval_T *rettv, int evaluate)
static int eval4(char_u **arg, typval_T *rettv, int evaluate)
{
typval_T var2;
- char_u *p;
+ char_u *p;
exprtype_T type = EXPR_UNKNOWN;
int len = 2;
bool ic;
@@ -3603,8 +3619,9 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate)
/*
* Get the first variable.
*/
- if (eval5(arg, rettv, evaluate) == FAIL)
+ if (eval5(arg, rettv, evaluate) == FAIL) {
return FAIL;
+ }
p = *arg;
switch (p[0]) {
@@ -3638,14 +3655,15 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate)
type = EXPR_SEQUAL;
}
break;
- case 'i': if (p[1] == 's') {
+ case 'i':
+ if (p[1] == 's') {
if (p[2] == 'n' && p[3] == 'o' && p[4] == 't') {
len = 5;
}
if (!isalnum(p[len]) && p[len] != '_') {
type = len == 2 ? EXPR_IS : EXPR_ISNOT;
}
- }
+ }
break;
}
@@ -3685,10 +3703,10 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate)
/*
* Handle fourth level expression:
- * + number addition
- * - number subtraction
- * . string concatenation
- * .. string concatenation
+ * + number addition
+ * - number subtraction
+ * . string concatenation
+ * .. string concatenation
*
* "arg" must point to the first non-white of the expression.
* "arg" is advanced to the next non-white after the recognized expression.
@@ -3702,21 +3720,23 @@ static int eval5(char_u **arg, typval_T *rettv, int evaluate)
int op;
varnumber_T n1, n2;
float_T f1 = 0, f2 = 0;
- char_u *p;
+ char_u *p;
/*
* Get the first variable.
*/
- if (eval6(arg, rettv, evaluate, FALSE) == FAIL)
+ if (eval6(arg, rettv, evaluate, FALSE) == FAIL) {
return FAIL;
+ }
/*
* Repeat computing, until no '+', '-' or '.' is following.
*/
for (;; ) {
op = **arg;
- if (op != '+' && op != '-' && op != '.')
+ if (op != '+' && op != '-' && op != '.') {
break;
+ }
if ((op != '+' || (rettv->v_type != VAR_LIST && rettv->v_type != VAR_BLOB))
&& (op == '.' || rettv->v_type != VAR_FLOAT)) {
@@ -3807,8 +3827,9 @@ static int eval5(char_u **arg, typval_T *rettv, int evaluate)
tv_clear(&var2);
return FAIL;
}
- if (var2.v_type == VAR_FLOAT)
+ if (var2.v_type == VAR_FLOAT) {
f1 = n1;
+ }
}
if (var2.v_type == VAR_FLOAT) {
f2 = var2.vval.v_float;
@@ -3820,24 +3841,27 @@ static int eval5(char_u **arg, typval_T *rettv, int evaluate)
tv_clear(&var2);
return FAIL;
}
- if (rettv->v_type == VAR_FLOAT)
+ if (rettv->v_type == VAR_FLOAT) {
f2 = n2;
+ }
}
tv_clear(rettv);
// If there is a float on either side the result is a float.
if (rettv->v_type == VAR_FLOAT || var2.v_type == VAR_FLOAT) {
- if (op == '+')
+ if (op == '+') {
f1 = f1 + f2;
- else
+ } else {
f1 = f1 - f2;
+ }
rettv->v_type = VAR_FLOAT;
rettv->vval.v_float = f1;
} else {
- if (op == '+')
+ if (op == '+') {
n1 = n1 + n2;
- else
+ } else {
n1 = n1 - n2;
+ }
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = n1;
}
@@ -3876,8 +3900,9 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string)
/*
* Get the first variable.
*/
- if (eval7(arg, rettv, evaluate, want_string) == FAIL)
+ if (eval7(arg, rettv, evaluate, want_string) == FAIL) {
return FAIL;
+ }
/*
* Repeat computing, until no '*', '/' or '%' is following.
@@ -3908,8 +3933,9 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string)
* Get the second variable.
*/
*arg = skipwhite(*arg + 1);
- if (eval7(arg, &var2, evaluate, FALSE) == FAIL)
+ if (eval7(arg, &var2, evaluate, FALSE) == FAIL) {
return FAIL;
+ }
if (evaluate) {
if (var2.v_type == VAR_FLOAT) {
@@ -3942,15 +3968,15 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string)
f1 = (f2 == 0
? (
#ifdef NAN
- f1 == 0
+ f1 == 0
? NAN
:
#endif
- (f1 > 0
+ (f1 > 0
? INFINITY
: -INFINITY)
- )
- : f1 / f2);
+ )
+ : f1 / f2);
} else {
EMSG(_("E804: Cannot use '%' with Float"));
return FAIL;
@@ -3976,39 +4002,36 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string)
// TODO(ZyX-I): move to eval/expressions
-// Handle sixth level expression:
-// number number constant
-// 0zFFFFFFFF Blob constant
-// "string" string constant
-// 'string' literal string constant
-// &option-name option value
-// @r register contents
-// identifier variable value
-// function() function call
-// $VAR environment variable
-// (expression) nested expression
-// [expr, expr] List
-// {key: val, key: val} Dictionary
-// #{key: val, key: val} Dictionary with literal keys
-//
-// Also handle:
-// ! in front logical NOT
-// - in front unary minus
-// + in front unary plus (ignored)
-// trailing [] subscript in String or List
-// trailing .name entry in Dictionary
-// trailing ->name() method call
-//
-// "arg" must point to the first non-white of the expression.
-// "arg" is advanced to the next non-white after the recognized expression.
-//
-// Return OK or FAIL.
-static int eval7(
- char_u **arg,
- typval_T *rettv,
- int evaluate,
- int want_string // after "." operator
-)
+/// Handle sixth level expression:
+/// number number constant
+/// 0zFFFFFFFF Blob constant
+/// "string" string constant
+/// 'string' literal string constant
+/// &option-name option value
+/// @r register contents
+/// identifier variable value
+/// function() function call
+/// $VAR environment variable
+/// (expression) nested expression
+/// [expr, expr] List
+/// {key: val, key: val} Dictionary
+/// #{key: val, key: val} Dictionary with literal keys
+///
+/// Also handle:
+/// ! in front logical NOT
+/// - in front unary minus
+/// + in front unary plus (ignored)
+/// trailing [] subscript in String or List
+/// trailing .name entry in Dictionary
+/// trailing ->name() method call
+///
+/// "arg" must point to the first non-white of the expression.
+/// "arg" is advanced to the next non-white after the recognized expression.
+///
+/// @param want_string after "." operator
+///
+/// @return OK or FAIL.
+static int eval7(char_u **arg, typval_T *rettv, int evaluate, int want_string)
{
varnumber_T n;
int len;
@@ -4039,8 +4062,7 @@ static int eval7(
case '6':
case '7':
case '8':
- case '9':
- {
+ case '9': {
char_u *p = skipdigits(*arg + 1);
int get_float = false;
@@ -4070,7 +4092,7 @@ static int eval7(
if (get_float) {
float_T f;
- *arg += string2float((char *) *arg, &f);
+ *arg += string2float((char *)*arg, &f);
if (evaluate) {
rettv->v_type = VAR_FLOAT;
rettv->vval.v_float = f;
@@ -4122,15 +4144,18 @@ static int eval7(
}
// String constant: "string".
- case '"': ret = get_string_tv(arg, rettv, evaluate);
+ case '"':
+ ret = get_string_tv(arg, rettv, evaluate);
break;
// Literal string constant: 'str''ing'.
- case '\'': ret = get_lit_string_tv(arg, rettv, evaluate);
+ case '\'':
+ ret = get_lit_string_tv(arg, rettv, evaluate);
break;
// List: [expr, expr]
- case '[': ret = get_list_tv(arg, rettv, evaluate);
+ case '[':
+ ret = get_list_tv(arg, rettv, evaluate);
break;
// Dictionary: #{key: val, key: val}
@@ -4145,23 +4170,25 @@ static int eval7(
// Lambda: {arg, arg -> expr}
// Dictionary: {'key': val, 'key': val}
- case '{': ret = get_lambda_tv(arg, rettv, evaluate);
- if (ret == NOTDONE) {
- ret = dict_get_tv(arg, rettv, evaluate, false);
- }
+ case '{':
+ ret = get_lambda_tv(arg, rettv, evaluate);
+ if (ret == NOTDONE) {
+ ret = dict_get_tv(arg, rettv, evaluate, false);
+ }
break;
// Option value: &name
- case '&': {
+ case '&':
ret = get_option_tv((const char **)arg, rettv, evaluate);
break;
- }
// Environment variable: $VAR.
- case '$': ret = get_env_tv(arg, rettv, evaluate);
+ case '$':
+ ret = get_env_tv(arg, rettv, evaluate);
break;
// Register contents: @r.
- case '@': ++*arg;
+ case '@':
+ ++*arg;
if (evaluate) {
rettv->v_type = VAR_STRING;
rettv->vval.v_string = get_reg_contents(**arg, kGRegExprSrc);
@@ -4172,7 +4199,8 @@ static int eval7(
break;
// nested expression: (expression).
- case '(': *arg = skipwhite(*arg + 1);
+ case '(':
+ *arg = skipwhite(*arg + 1);
ret = eval1(arg, rettv, evaluate); // recursive!
if (**arg == ')') {
++*arg;
@@ -4183,7 +4211,8 @@ static int eval7(
}
break;
- default: ret = NOTDONE;
+ default:
+ ret = NOTDONE;
break;
}
@@ -4284,11 +4313,8 @@ static int eval7_leader(typval_T *const rettv, const char_u *const start_leader,
/// to the name of the Lua function to call (after the
/// "v:lua." prefix).
/// @return OK on success, FAIL on failure.
-static int call_func_rettv(char_u **const arg,
- typval_T *const rettv,
- const bool evaluate,
- dict_T *const selfdict,
- typval_T *const basetv,
+static int call_func_rettv(char_u **const arg, typval_T *const rettv, const bool evaluate,
+ dict_T *const selfdict, typval_T *const basetv,
const char_u *const lua_funcname)
FUNC_ATTR_NONNULL_ARG(1, 2)
{
@@ -4337,8 +4363,8 @@ static int call_func_rettv(char_u **const arg,
/// @param verbose if true, give error messages.
/// @note "*arg" points to the '-'.
/// @return FAIL or OK. @note "*arg" is advanced to after the ')'.
-static int eval_lambda(char_u **const arg, typval_T *const rettv,
- const bool evaluate, const bool verbose)
+static int eval_lambda(char_u **const arg, typval_T *const rettv, const bool evaluate,
+ const bool verbose)
FUNC_ATTR_NONNULL_ALL
{
// Skip over the ->.
@@ -4375,8 +4401,8 @@ static int eval_lambda(char_u **const arg, typval_T *const rettv,
/// Evaluate "->method()" or "->v:lua.method()".
/// @note "*arg" points to the '-'.
/// @return FAIL or OK. "*arg" is advanced to after the ')'.
-static int eval_method(char_u **const arg, typval_T *const rettv,
- const bool evaluate, const bool verbose)
+static int eval_method(char_u **const arg, typval_T *const rettv, const bool evaluate,
+ const bool verbose)
FUNC_ATTR_NONNULL_ALL
{
// Skip over the ->.
@@ -4445,60 +4471,49 @@ static int eval_method(char_u **const arg, typval_T *const rettv,
// TODO(ZyX-I): move to eval/expressions
-/*
- * Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key".
- * "*arg" points to the '[' or '.'.
- * Returns FAIL or OK. "*arg" is advanced to after the ']'.
- */
-static int
-eval_index(
- char_u **arg,
- typval_T *rettv,
- int evaluate,
- int verbose // give error messages
-)
+/// Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key".
+/// "*arg" points to the '[' or '.'.
+/// Returns FAIL or OK. "*arg" is advanced to after the ']'.
+///
+/// @param verbose give error messages
+static int eval_index(char_u **arg, typval_T *rettv, int evaluate, int verbose)
{
bool empty1 = false;
bool empty2 = false;
long n1, n2 = 0;
ptrdiff_t len = -1;
int range = false;
- char_u *key = NULL;
+ char_u *key = NULL;
switch (rettv->v_type) {
- case VAR_FUNC:
- case VAR_PARTIAL: {
- if (verbose) {
- EMSG(_("E695: Cannot index a Funcref"));
- }
- return FAIL;
- }
- case VAR_FLOAT: {
- if (verbose) {
- EMSG(_(e_float_as_string));
- }
- return FAIL;
+ case VAR_FUNC:
+ case VAR_PARTIAL:
+ if (verbose) {
+ EMSG(_("E695: Cannot index a Funcref"));
}
- case VAR_BOOL:
- case VAR_SPECIAL: {
- if (verbose) {
- EMSG(_("E909: Cannot index a special variable"));
- }
- return FAIL;
+ return FAIL;
+ case VAR_FLOAT:
+ if (verbose) {
+ EMSG(_(e_float_as_string));
}
- case VAR_UNKNOWN: {
- if (evaluate) {
- return FAIL;
- }
- FALLTHROUGH;
+ return FAIL;
+ case VAR_BOOL:
+ case VAR_SPECIAL:
+ if (verbose) {
+ EMSG(_("E909: Cannot index a special variable"));
}
- case VAR_STRING:
- case VAR_NUMBER:
- case VAR_LIST:
- case VAR_DICT:
- case VAR_BLOB: {
- break;
+ return FAIL;
+ case VAR_UNKNOWN:
+ if (evaluate) {
+ return FAIL;
}
+ FALLTHROUGH;
+ case VAR_STRING:
+ case VAR_NUMBER:
+ case VAR_LIST:
+ case VAR_DICT:
+ case VAR_BLOB:
+ break;
}
typval_T var1 = TV_INITIAL_VALUE;
@@ -4508,10 +4523,12 @@ eval_index(
* dict.name
*/
key = *arg + 1;
- for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len)
+ for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) {
;
- if (len == 0)
+ }
+ if (len == 0) {
return FAIL;
+ }
*arg = skipwhite(key + len);
} else {
/*
@@ -4583,180 +4600,177 @@ eval_index(
}
switch (rettv->v_type) {
- case VAR_NUMBER:
- case VAR_STRING: {
- const char *const s = tv_get_string(rettv);
- char *v;
- len = (ptrdiff_t)strlen(s);
- if (range) {
- // The resulting variable is a substring. If the indexes
- // are out of range the result is empty.
+ case VAR_NUMBER:
+ case VAR_STRING: {
+ const char *const s = tv_get_string(rettv);
+ char *v;
+ len = (ptrdiff_t)strlen(s);
+ if (range) {
+ // The resulting variable is a substring. If the indexes
+ // are out of range the result is empty.
+ if (n1 < 0) {
+ n1 = len + n1;
if (n1 < 0) {
- n1 = len + n1;
- if (n1 < 0) {
- n1 = 0;
- }
- }
- if (n2 < 0) {
- n2 = len + n2;
- } else if (n2 >= len) {
- n2 = len;
- }
- if (n1 >= len || n2 < 0 || n1 > n2) {
- v = NULL;
- } else {
- v = xmemdupz(s + n1, (size_t)(n2 - n1 + 1));
+ n1 = 0;
}
+ }
+ if (n2 < 0) {
+ n2 = len + n2;
+ } else if (n2 >= len) {
+ n2 = len;
+ }
+ if (n1 >= len || n2 < 0 || n1 > n2) {
+ v = NULL;
} else {
- // The resulting variable is a string of a single
- // character. If the index is too big or negative the
- // result is empty.
- if (n1 >= len || n1 < 0) {
- v = NULL;
- } else {
- v = xmemdupz(s + n1, 1);
- }
+ v = xmemdupz(s + n1, (size_t)(n2 - n1 + 1));
+ }
+ } else {
+ // The resulting variable is a string of a single
+ // character. If the index is too big or negative the
+ // result is empty.
+ if (n1 >= len || n1 < 0) {
+ v = NULL;
+ } else {
+ v = xmemdupz(s + n1, 1);
}
- tv_clear(rettv);
- rettv->v_type = VAR_STRING;
- rettv->vval.v_string = (char_u *)v;
- break;
}
- case VAR_BLOB: {
- len = tv_blob_len(rettv->vval.v_blob);
- if (range) {
- // The resulting variable is a sub-blob. If the indexes
- // are out of range the result is empty.
+ tv_clear(rettv);
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = (char_u *)v;
+ break;
+ }
+ case VAR_BLOB:
+ len = tv_blob_len(rettv->vval.v_blob);
+ if (range) {
+ // The resulting variable is a sub-blob. If the indexes
+ // are out of range the result is empty.
+ if (n1 < 0) {
+ n1 = len + n1;
if (n1 < 0) {
- n1 = len + n1;
- if (n1 < 0) {
- n1 = 0;
- }
- }
- if (n2 < 0) {
- n2 = len + n2;
- } else if (n2 >= len) {
- n2 = len - 1;
- }
- if (n1 >= len || n2 < 0 || n1 > n2) {
- tv_clear(rettv);
- rettv->v_type = VAR_BLOB;
- rettv->vval.v_blob = NULL;
- } else {
- blob_T *const blob = tv_blob_alloc();
- ga_grow(&blob->bv_ga, n2 - n1 + 1);
- blob->bv_ga.ga_len = n2 - n1 + 1;
- for (long i = n1; i <= n2; i++) {
- tv_blob_set(blob, i - n1, tv_blob_get(rettv->vval.v_blob, i));
- }
- tv_clear(rettv);
- tv_blob_set_ret(rettv, blob);
+ n1 = 0;
}
+ }
+ if (n2 < 0) {
+ n2 = len + n2;
+ } else if (n2 >= len) {
+ n2 = len - 1;
+ }
+ if (n1 >= len || n2 < 0 || n1 > n2) {
+ tv_clear(rettv);
+ rettv->v_type = VAR_BLOB;
+ rettv->vval.v_blob = NULL;
} else {
- // The resulting variable is a byte value.
- // If the index is too big or negative that is an error.
- if (n1 < 0) {
- n1 = len + n1;
- }
- if (n1 < len && n1 >= 0) {
- const int v = (int)tv_blob_get(rettv->vval.v_blob, n1);
- tv_clear(rettv);
- rettv->v_type = VAR_NUMBER;
- rettv->vval.v_number = v;
- } else {
- EMSGN(_(e_blobidx), n1);
+ blob_T *const blob = tv_blob_alloc();
+ ga_grow(&blob->bv_ga, n2 - n1 + 1);
+ blob->bv_ga.ga_len = n2 - n1 + 1;
+ for (long i = n1; i <= n2; i++) {
+ tv_blob_set(blob, i - n1, tv_blob_get(rettv->vval.v_blob, i));
}
+ tv_clear(rettv);
+ tv_blob_set_ret(rettv, blob);
}
- break;
- }
- case VAR_LIST: {
- len = tv_list_len(rettv->vval.v_list);
+ } else {
+ // The resulting variable is a byte value.
+ // If the index is too big or negative that is an error.
if (n1 < 0) {
n1 = len + n1;
}
- if (!empty1 && (n1 < 0 || n1 >= len)) {
- // For a range we allow invalid values and return an empty
- // list. A list index out of range is an error.
- if (!range) {
- if (verbose) {
- EMSGN(_(e_listidx), n1);
- }
- return FAIL;
- }
- n1 = len;
- }
- if (range) {
- list_T *l;
- listitem_T *item;
-
- if (n2 < 0) {
- n2 = len + n2;
- } else if (n2 >= len) {
- n2 = len - 1;
- }
- if (!empty2 && (n2 < 0 || n2 + 1 < n1)) {
- n2 = -1;
- }
- l = tv_list_alloc(n2 - n1 + 1);
- item = tv_list_find(rettv->vval.v_list, n1);
- while (n1++ <= n2) {
- tv_list_append_tv(l, TV_LIST_ITEM_TV(item));
- item = TV_LIST_ITEM_NEXT(rettv->vval.v_list, item);
- }
+ if (n1 < len && n1 >= 0) {
+ const int v = (int)tv_blob_get(rettv->vval.v_blob, n1);
tv_clear(rettv);
- tv_list_set_ret(rettv, l);
+ rettv->v_type = VAR_NUMBER;
+ rettv->vval.v_number = v;
} else {
- tv_copy(TV_LIST_ITEM_TV(tv_list_find(rettv->vval.v_list, n1)), &var1);
- tv_clear(rettv);
- *rettv = var1;
+ EMSGN(_(e_blobidx), n1);
}
- break;
}
- case VAR_DICT: {
- if (range) {
+ break;
+ case VAR_LIST:
+ len = tv_list_len(rettv->vval.v_list);
+ if (n1 < 0) {
+ n1 = len + n1;
+ }
+ if (!empty1 && (n1 < 0 || n1 >= len)) {
+ // For a range we allow invalid values and return an empty
+ // list. A list index out of range is an error.
+ if (!range) {
if (verbose) {
- EMSG(_(e_dictrange));
- }
- if (len == -1) {
- tv_clear(&var1);
+ EMSGN(_(e_listidx), n1);
}
return FAIL;
}
+ n1 = len;
+ }
+ if (range) {
+ list_T *l;
+ listitem_T *item;
- if (len == -1) {
- key = (char_u *)tv_get_string_chk(&var1);
- if (key == NULL) {
- tv_clear(&var1);
- return FAIL;
- }
+ if (n2 < 0) {
+ n2 = len + n2;
+ } else if (n2 >= len) {
+ n2 = len - 1;
}
-
- dictitem_T *const item = tv_dict_find(rettv->vval.v_dict,
- (const char *)key, len);
-
- if (item == NULL && verbose) {
- emsgf(_(e_dictkey), key);
+ if (!empty2 && (n2 < 0 || n2 + 1 < n1)) {
+ n2 = -1;
+ }
+ l = tv_list_alloc(n2 - n1 + 1);
+ item = tv_list_find(rettv->vval.v_list, n1);
+ while (n1++ <= n2) {
+ tv_list_append_tv(l, TV_LIST_ITEM_TV(item));
+ item = TV_LIST_ITEM_NEXT(rettv->vval.v_list, item);
+ }
+ tv_clear(rettv);
+ tv_list_set_ret(rettv, l);
+ } else {
+ tv_copy(TV_LIST_ITEM_TV(tv_list_find(rettv->vval.v_list, n1)), &var1);
+ tv_clear(rettv);
+ *rettv = var1;
+ }
+ break;
+ case VAR_DICT: {
+ if (range) {
+ if (verbose) {
+ EMSG(_(e_dictrange));
}
if (len == -1) {
tv_clear(&var1);
}
- if (item == NULL || tv_is_luafunc(&item->di_tv)) {
+ return FAIL;
+ }
+
+ if (len == -1) {
+ key = (char_u *)tv_get_string_chk(&var1);
+ if (key == NULL) {
+ tv_clear(&var1);
return FAIL;
}
+ }
- tv_copy(&item->di_tv, &var1);
- tv_clear(rettv);
- *rettv = var1;
- break;
+ dictitem_T *const item = tv_dict_find(rettv->vval.v_dict,
+ (const char *)key, len);
+
+ if (item == NULL && verbose) {
+ emsgf(_(e_dictkey), key);
+ }
+ if (len == -1) {
+ tv_clear(&var1);
}
- case VAR_BOOL:
- case VAR_SPECIAL:
- case VAR_FUNC:
- case VAR_FLOAT:
- case VAR_PARTIAL:
- case VAR_UNKNOWN: {
- break; // Not evaluating, skipping over subscript
+ if (item == NULL || tv_is_luafunc(&item->di_tv)) {
+ return FAIL;
}
+
+ tv_copy(&item->di_tv, &var1);
+ tv_clear(rettv);
+ *rettv = var1;
+ break;
+ }
+ case VAR_BOOL:
+ case VAR_SPECIAL:
+ case VAR_FUNC:
+ case VAR_FLOAT:
+ case VAR_PARTIAL:
+ case VAR_UNKNOWN:
+ break; // Not evaluating, skipping over subscript
}
}
@@ -4773,12 +4787,11 @@ eval_index(
/// @param[in] evaluate If not true, rettv is not populated.
///
/// @return OK or FAIL.
-int get_option_tv(const char **const arg, typval_T *const rettv,
- const bool evaluate)
+int get_option_tv(const char **const arg, typval_T *const rettv, const bool evaluate)
FUNC_ATTR_NONNULL_ARG(1)
{
long numval;
- char_u *stringval;
+ char_u *stringval;
int opt_type;
int c;
bool working = (**arg == '+'); // has("+option")
@@ -4809,7 +4822,7 @@ int get_option_tv(const char **const arg, typval_T *const rettv,
EMSG2(_("E113: Unknown option: %s"), *arg);
}
ret = FAIL;
- } else if (rettv != NULL) {
+ } else if (rettv != NULL) {
if (opt_type == -2) { // hidden string option
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
@@ -4823,8 +4836,9 @@ int get_option_tv(const char **const arg, typval_T *const rettv,
rettv->v_type = VAR_STRING;
rettv->vval.v_string = stringval;
}
- } else if (working && (opt_type == -2 || opt_type == -1))
+ } else if (working && (opt_type == -2 || opt_type == -1)) {
ret = FAIL;
+ }
*option_end = c; // put back for error messages
*arg = option_end;
@@ -4838,7 +4852,7 @@ int get_option_tv(const char **const arg, typval_T *const rettv,
*/
static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
{
- char_u *p;
+ char_u *p;
unsigned int extra = 0;
/*
@@ -4880,12 +4894,18 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
for (p = *arg + 1; *p != NUL && *p != '"'; ) {
if (*p == '\\') {
switch (*++p) {
- case 'b': *name++ = BS; ++p; break;
- case 'e': *name++ = ESC; ++p; break;
- case 'f': *name++ = FF; ++p; break;
- case 'n': *name++ = NL; ++p; break;
- case 'r': *name++ = CAR; ++p; break;
- case 't': *name++ = TAB; ++p; break;
+ case 'b':
+ *name++ = BS; ++p; break;
+ case 'e':
+ *name++ = ESC; ++p; break;
+ case 'f':
+ *name++ = FF; ++p; break;
+ case 'n':
+ *name++ = NL; ++p; break;
+ case 'r':
+ *name++ = CAR; ++p; break;
+ case 't':
+ *name++ = TAB; ++p; break;
case 'X': // hex: "\x1", "\x12"
case 'x':
@@ -4926,11 +4946,13 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
case '4':
case '5':
case '6':
- case '7': *name = *p++ - '0';
+ case '7':
+ *name = *p++ - '0';
if (*p >= '0' && *p <= '7') {
*name = (*name << 3) + *p++ - '0';
- if (*p >= '0' && *p <= '7')
+ if (*p >= '0' && *p <= '7') {
*name = (*name << 3) + *p++ - '0';
+ }
}
++name;
break;
@@ -4947,12 +4969,13 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
}
FALLTHROUGH;
- default: MB_COPY_CHAR(p, name);
+ default:
+ MB_COPY_CHAR(p, name);
break;
}
- } else
+ } else {
MB_COPY_CHAR(p, name);
-
+ }
}
*name = NUL;
if (*p != NUL) { // just in case
@@ -4969,8 +4992,8 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
*/
static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate)
{
- char_u *p;
- char_u *str;
+ char_u *p;
+ char_u *str;
int reduce = 0;
/*
@@ -4978,8 +5001,9 @@ static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate)
*/
for (p = *arg + 1; *p != NUL; MB_PTR_ADV(p)) {
if (*p == '\'') {
- if (p[1] != '\'')
+ if (p[1] != '\'') {
break;
+ }
++reduce;
++p;
}
@@ -5005,8 +5029,9 @@ static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate)
for (p = *arg + 1; *p != NUL; ) {
if (*p == '\'') {
- if (p[1] != '\'')
+ if (p[1] != '\'') {
break;
+ }
++p;
}
MB_COPY_CHAR(p, str);
@@ -5059,7 +5084,7 @@ void partial_unref(partial_T *pt)
/// Return OK or FAIL.
static int get_list_tv(char_u **arg, typval_T *rettv, int evaluate)
{
- list_T *l = NULL;
+ list_T *l = NULL;
if (evaluate) {
l = tv_list_alloc(kListLenShouldKnow);
@@ -5103,23 +5128,20 @@ failret:
return OK;
}
-bool func_equal(
- typval_T *tv1,
- typval_T *tv2,
- bool ic // ignore case
-) {
+/// @param ic ignore case
+bool func_equal(typval_T *tv1, typval_T *tv2, bool ic) {
char_u *s1, *s2;
dict_T *d1, *d2;
int a1, a2;
// empty and NULL function name considered the same
s1 = tv1->v_type == VAR_FUNC ? tv1->vval.v_string
- : partial_name(tv1->vval.v_partial);
+ : partial_name(tv1->vval.v_partial);
if (s1 != NULL && *s1 == NUL) {
s1 = NULL;
}
s2 = tv2->v_type == VAR_FUNC ? tv2->vval.v_string
- : partial_name(tv2->vval.v_partial);
+ : partial_name(tv2->vval.v_partial);
if (s2 != NULL && *s2 == NUL) {
s2 = NULL;
}
@@ -5180,9 +5202,9 @@ int get_copyID(void)
* are no longer used. But for composite items it's possible that it becomes
* unused while the reference count is > 0: When there is a recursive
* reference. Example:
- * :let l = [1, 2, 3]
- * :let d = {9: l}
- * :let l[1] = d
+ * :let l = [1, 2, 3]
+ * :let d = {9: l}
+ * :let l[1] = d
*
* Since this is quite unusual we handle this with garbage collection: every
* once in a while find out which lists and dicts are not referenced from any
@@ -5190,7 +5212,7 @@ int get_copyID(void)
*
* Here is a good reference text about garbage collection (refers to Python
* but it applies to all reference-counting mechanisms):
- * http://python.ca/nas/python/gc/
+ * http://python.ca/nas/python/gc/
*/
/// Do garbage collection for lists and dicts.
@@ -5366,8 +5388,7 @@ bool garbage_collect(bool testing)
// This may call us back recursively.
did_free = free_unref_funccal(copyID, testing) || did_free;
} else if (p_verbose > 0) {
- verb_msg(_(
- "Not enough memory to set references, garbage collection aborted!"));
+ verb_msg(_("Not enough memory to set references, garbage collection aborted!"));
}
#undef ABORTING
return did_free;
@@ -5461,8 +5482,7 @@ bool set_ref_in_ht(hashtab_T *ht, int copyID, list_stack_T **list_stack)
// it is added to ht_stack, if it contains a list it is added to
// list_stack.
HASHTAB_ITER(cur_ht, hi, {
- abort = abort || set_ref_in_item(
- &TV_DICT_HI2DI(hi)->di_tv, copyID, &ht_stack, list_stack);
+ abort = abort || set_ref_in_item(&TV_DICT_HI2DI(hi)->di_tv, copyID, &ht_stack, list_stack);
});
}
@@ -5528,87 +5548,85 @@ bool set_ref_in_list(list_T *l, int copyID, ht_stack_T **ht_stack)
/// @param list_stack Used to add lists to be marked. Can be NULL.
///
/// @returns true if setting references failed somehow.
-bool set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack,
- list_stack_T **list_stack)
+bool set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, list_stack_T **list_stack)
FUNC_ATTR_WARN_UNUSED_RESULT
{
bool abort = false;
switch (tv->v_type) {
- case VAR_DICT: {
- dict_T *dd = tv->vval.v_dict;
- if (dd != NULL && dd->dv_copyID != copyID) {
- // Didn't see this dict yet.
- dd->dv_copyID = copyID;
- if (ht_stack == NULL) {
- abort = set_ref_in_ht(&dd->dv_hashtab, copyID, list_stack);
- } else {
- ht_stack_T *const newitem = xmalloc(sizeof(ht_stack_T));
- newitem->ht = &dd->dv_hashtab;
- newitem->prev = *ht_stack;
- *ht_stack = newitem;
- }
+ case VAR_DICT: {
+ dict_T *dd = tv->vval.v_dict;
+ if (dd != NULL && dd->dv_copyID != copyID) {
+ // Didn't see this dict yet.
+ dd->dv_copyID = copyID;
+ if (ht_stack == NULL) {
+ abort = set_ref_in_ht(&dd->dv_hashtab, copyID, list_stack);
+ } else {
+ ht_stack_T *const newitem = xmalloc(sizeof(ht_stack_T));
+ newitem->ht = &dd->dv_hashtab;
+ newitem->prev = *ht_stack;
+ *ht_stack = newitem;
+ }
- QUEUE *w = NULL;
- DictWatcher *watcher = NULL;
- QUEUE_FOREACH(w, &dd->watchers, {
+ QUEUE *w = NULL;
+ DictWatcher *watcher = NULL;
+ QUEUE_FOREACH(w, &dd->watchers, {
watcher = tv_dict_watcher_node_data(w);
set_ref_in_callback(&watcher->callback, copyID, ht_stack, list_stack);
})
- }
- break;
}
+ break;
+ }
- case VAR_LIST: {
- list_T *ll = tv->vval.v_list;
- if (ll != NULL && ll->lv_copyID != copyID) {
- // Didn't see this list yet.
- ll->lv_copyID = copyID;
- if (list_stack == NULL) {
- abort = set_ref_in_list(ll, copyID, ht_stack);
- } else {
- list_stack_T *const newitem = xmalloc(sizeof(list_stack_T));
- newitem->list = ll;
- newitem->prev = *list_stack;
- *list_stack = newitem;
- }
+ case VAR_LIST: {
+ list_T *ll = tv->vval.v_list;
+ if (ll != NULL && ll->lv_copyID != copyID) {
+ // Didn't see this list yet.
+ ll->lv_copyID = copyID;
+ if (list_stack == NULL) {
+ abort = set_ref_in_list(ll, copyID, ht_stack);
+ } else {
+ list_stack_T *const newitem = xmalloc(sizeof(list_stack_T));
+ newitem->list = ll;
+ newitem->prev = *list_stack;
+ *list_stack = newitem;
}
- break;
}
+ break;
+ }
- case VAR_PARTIAL: {
- partial_T *pt = tv->vval.v_partial;
+ case VAR_PARTIAL: {
+ partial_T *pt = tv->vval.v_partial;
- // A partial does not have a copyID, because it cannot contain itself.
- if (pt != NULL) {
- abort = set_ref_in_func(pt->pt_name, pt->pt_func, copyID);
- if (pt->pt_dict != NULL) {
- typval_T dtv;
+ // A partial does not have a copyID, because it cannot contain itself.
+ if (pt != NULL) {
+ abort = set_ref_in_func(pt->pt_name, pt->pt_func, copyID);
+ if (pt->pt_dict != NULL) {
+ typval_T dtv;
- dtv.v_type = VAR_DICT;
- dtv.vval.v_dict = pt->pt_dict;
- abort = abort || set_ref_in_item(&dtv, copyID, ht_stack, list_stack);
- }
+ dtv.v_type = VAR_DICT;
+ dtv.vval.v_dict = pt->pt_dict;
+ abort = abort || set_ref_in_item(&dtv, copyID, ht_stack, list_stack);
+ }
- for (int i = 0; i < pt->pt_argc; i++) {
- abort = abort || set_ref_in_item(&pt->pt_argv[i], copyID,
- ht_stack, list_stack);
- }
+ for (int i = 0; i < pt->pt_argc; i++) {
+ abort = abort || set_ref_in_item(&pt->pt_argv[i], copyID,
+ ht_stack, list_stack);
}
- break;
- }
- case VAR_FUNC:
- abort = set_ref_in_func(tv->vval.v_string, NULL, copyID);
- break;
- case VAR_UNKNOWN:
- case VAR_BOOL:
- case VAR_SPECIAL:
- case VAR_FLOAT:
- case VAR_NUMBER:
- case VAR_STRING:
- case VAR_BLOB: {
- break;
}
+ break;
+ }
+ case VAR_FUNC:
+ abort = set_ref_in_func(tv->vval.v_string, NULL, copyID);
+ break;
+ case VAR_UNKNOWN:
+ case VAR_BOOL:
+ case VAR_SPECIAL:
+ case VAR_FLOAT:
+ case VAR_NUMBER:
+ case VAR_STRING:
+ case VAR_BLOB:
+ break;
}
return abort;
}
@@ -5684,15 +5702,14 @@ static int get_literal_key(char_u **arg, typval_T *tv)
// Allocate a variable for a Dictionary and fill it from "*arg".
// "literal" is true for *{key: val}
// Return OK or FAIL. Returns NOTDONE for {expr}.
-static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate,
- bool literal)
+static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, bool literal)
{
- dict_T *d = NULL;
+ dict_T *d = NULL;
typval_T tvkey;
typval_T tv;
- char_u *key = NULL;
- dictitem_T *item;
- char_u *start = skipwhite(*arg + 1);
+ char_u *key = NULL;
+ dictitem_T *item;
+ char_u *start = skipwhite(*arg + 1);
char buf[NUMBUFLEN];
/*
@@ -5762,8 +5779,9 @@ static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate,
}
tv_clear(&tvkey);
- if (**arg == '}')
+ if (**arg == '}') {
break;
+ }
if (**arg != ',') {
EMSG2(_("E722: Missing comma in Dictionary: %s"), *arg);
goto failret;
@@ -5816,7 +5834,7 @@ size_t string2float(const char *const text, float_T *const ret_value)
return 3;
}
*ret_value = strtod(text, &s);
- return (size_t) (s - text);
+ return (size_t)(s - text);
}
/// Get the value of an environment variable.
@@ -5863,8 +5881,7 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate)
}
/// Get the argument list for a given window
-void get_arglist_as_rettv(aentry_T *arglist, int argcount,
- typval_T *rettv)
+void get_arglist_as_rettv(aentry_T *arglist, int argcount, typval_T *rettv)
{
tv_list_alloc_ret(rettv, argcount);
if (arglist != NULL) {
@@ -5909,21 +5926,28 @@ static void ga_concat_esc(garray_T *gap, const char_u *p, int clen)
ga_concat(gap, buf);
} else {
switch (*p) {
- case BS: ga_concat(gap, (char_u *)"\\b"); break;
- case ESC: ga_concat(gap, (char_u *)"\\e"); break;
- case FF: ga_concat(gap, (char_u *)"\\f"); break;
- case NL: ga_concat(gap, (char_u *)"\\n"); break;
- case TAB: ga_concat(gap, (char_u *)"\\t"); break;
- case CAR: ga_concat(gap, (char_u *)"\\r"); break;
- case '\\': ga_concat(gap, (char_u *)"\\\\"); break;
- default:
- if (*p < ' ') {
- vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p);
- ga_concat(gap, buf);
- } else {
- ga_append(gap, *p);
- }
- break;
+ case BS:
+ ga_concat(gap, (char_u *)"\\b"); break;
+ case ESC:
+ ga_concat(gap, (char_u *)"\\e"); break;
+ case FF:
+ ga_concat(gap, (char_u *)"\\f"); break;
+ case NL:
+ ga_concat(gap, (char_u *)"\\n"); break;
+ case TAB:
+ ga_concat(gap, (char_u *)"\\t"); break;
+ case CAR:
+ ga_concat(gap, (char_u *)"\\r"); break;
+ case '\\':
+ ga_concat(gap, (char_u *)"\\\\"); break;
+ default:
+ if (*p < ' ') {
+ vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p);
+ ga_concat(gap, buf);
+ } else {
+ ga_append(gap, *p);
+ }
+ break;
}
}
}
@@ -5964,8 +5988,7 @@ static void ga_concat_shorten_esc(garray_T *gap, const char_u *str)
}
// Fill "gap" with information about an assert error.
-void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv,
- char_u *exp_str, typval_T *exp_tv,
+void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_str, typval_T *exp_tv,
typval_T *got_tv, assert_type_T atype)
{
char_u *tofree;
@@ -6231,8 +6254,7 @@ int assert_exception(typval_T *argvars)
return 0;
}
-static void assert_append_cmd_or_arg(garray_T *gap, typval_T *argvars,
- const char *cmd)
+static void assert_append_cmd_or_arg(garray_T *gap, typval_T *argvars, const char *cmd)
FUNC_ATTR_NONNULL_ALL
{
if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN) {
@@ -6361,12 +6383,12 @@ win_T * find_win_by_nr_or_id(typval_T *vp)
*/
void filter_map(typval_T *argvars, typval_T *rettv, int map)
{
- typval_T *expr;
- list_T *l = NULL;
- dictitem_T *di;
- hashtab_T *ht;
- hashitem_T *hi;
- dict_T *d = NULL;
+ typval_T *expr;
+ list_T *l = NULL;
+ dictitem_T *di;
+ hashtab_T *ht;
+ hashitem_T *hi;
+ dict_T *d = NULL;
typval_T save_val;
typval_T save_key;
blob_T *b = NULL;
@@ -6543,11 +6565,10 @@ theend:
return retval;
}
-void common_function(typval_T *argvars, typval_T *rettv,
- bool is_funcref, FunPtr fptr)
+void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref, FunPtr fptr)
{
- char_u *s;
- char_u *name;
+ char_u *s;
+ char_u *name;
bool use_string = false;
partial_T *arg_pt = NULL;
char_u *trans_name = NULL;
@@ -6584,7 +6605,7 @@ void common_function(typval_T *argvars, typval_T *rettv,
// Don't check an autoload name for existence here.
} else if (trans_name != NULL
&& (is_funcref ? find_func(trans_name) == NULL
- : !translated_function_exists((const char *)trans_name))) {
+ : !translated_function_exists((const char *)trans_name))) {
emsgf(_("E700: Unknown function: %s"), s);
} else {
int dict_idx = 0;
@@ -6760,8 +6781,7 @@ dict_T *get_buffer_info(buf_T *buf)
/// be NULL, in this case "$" results in zero return.
///
/// @return Line number or 0 in case of error.
-linenr_T tv_get_lnum_buf(const typval_T *const tv,
- const buf_T *const buf)
+linenr_T tv_get_lnum_buf(const typval_T *const tv, const buf_T *const buf)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT
{
if (tv->v_type == VAR_STRING
@@ -6773,8 +6793,7 @@ linenr_T tv_get_lnum_buf(const typval_T *const tv,
return tv_get_number_chk(tv, NULL);
}
-void get_qf_loc_list(int is_qf, win_T *wp, typval_T *what_arg,
- typval_T *rettv)
+void get_qf_loc_list(int is_qf, win_T *wp, typval_T *what_arg, typval_T *rettv)
{
if (what_arg->v_type == VAR_UNKNOWN) {
tv_list_alloc_ret(rettv, kListLenMayKnow);
@@ -6845,12 +6864,10 @@ dict_T *get_win_info(win_T *wp, int16_t tpnr, int16_t winnr)
return dict;
}
-// Find window specified by "vp" in tabpage "tp".
-win_T *
-find_win_by_nr(
- typval_T *vp,
- tabpage_T *tp // NULL for current tab page
-)
+/// Find window specified by "vp" in tabpage "tp".
+///
+/// @param tp NULL for current tab page
+win_T *find_win_by_nr(typval_T *vp, tabpage_T *tp)
{
int nr = (int)tv_get_number_chk(vp, NULL);
@@ -6864,7 +6881,7 @@ find_win_by_nr(
// This method accepts NULL as an alias for curtab.
if (tp == NULL) {
- tp = curtab;
+ tp = curtab;
}
FOR_ALL_WINDOWS_IN_TAB(wp, tp) {
@@ -6905,15 +6922,10 @@ win_T *find_tabwin(typval_T *wvp, typval_T *tvp)
return wp;
}
-/*
- * getwinvar() and gettabwinvar()
- */
-void
-getwinvar(
- typval_T *argvars,
- typval_T *rettv,
- int off // 1 for gettabwinvar()
-)
+/// getwinvar() and gettabwinvar()
+///
+/// @param off 1 for gettabwinvar()
+void getwinvar(typval_T *argvars, typval_T *rettv, int off)
{
win_T *win, *oldcurwin;
dictitem_T *v;
@@ -6984,9 +6996,7 @@ getwinvar(
* prompt. The third argument to f_inputdialog() specifies the value to return
* when the user cancels the prompt.
*/
-void get_user_input(const typval_T *const argvars,
- typval_T *const rettv,
- const bool inputdialog,
+void get_user_input(const typval_T *const argvars, typval_T *const rettv, const bool inputdialog,
const bool secret)
FUNC_ATTR_NONNULL_ALL
{
@@ -7121,8 +7131,7 @@ void get_user_input(const typval_T *const argvars,
/// a dictionary, will give an error if not.
/// @param[out] rettv Location where result will be saved.
/// @param[in] what What to save in rettv.
-void dict_list(typval_T *const tv, typval_T *const rettv,
- const DictListType what)
+void dict_list(typval_T *const tv, typval_T *const rettv, const DictListType what)
{
if (tv->v_type != VAR_DICT) {
EMSG(_(e_dictreq));
@@ -7138,32 +7147,30 @@ void dict_list(typval_T *const tv, typval_T *const rettv,
typval_T tv_item = { .v_lock = VAR_UNLOCKED };
switch (what) {
- case kDictListKeys: {
- tv_item.v_type = VAR_STRING;
- tv_item.vval.v_string = vim_strsave(di->di_key);
- break;
- }
- case kDictListValues: {
- tv_copy(&di->di_tv, &tv_item);
- break;
- }
- case kDictListItems: {
- // items()
- list_T *const sub_l = tv_list_alloc(2);
- tv_item.v_type = VAR_LIST;
- tv_item.vval.v_list = sub_l;
- tv_list_ref(sub_l);
-
- tv_list_append_owned_tv(sub_l, (typval_T) {
+ case kDictListKeys:
+ tv_item.v_type = VAR_STRING;
+ tv_item.vval.v_string = vim_strsave(di->di_key);
+ break;
+ case kDictListValues:
+ tv_copy(&di->di_tv, &tv_item);
+ break;
+ case kDictListItems: {
+ // items()
+ list_T *const sub_l = tv_list_alloc(2);
+ tv_item.v_type = VAR_LIST;
+ tv_item.vval.v_list = sub_l;
+ tv_list_ref(sub_l);
+
+ tv_list_append_owned_tv(sub_l, (typval_T) {
.v_type = VAR_STRING,
.v_lock = VAR_UNLOCKED,
.vval.v_string = (char_u *)xstrdup((const char *)di->di_key),
});
- tv_list_append_tv(sub_l, &di->di_tv);
+ tv_list_append_tv(sub_l, &di->di_tv);
- break;
- }
+ break;
+ }
}
tv_list_append_owned_tv(rettv->vval.v_list, tv_item);
@@ -7244,9 +7251,7 @@ char **tv_to_argv(typval_T *cmd_tv, const char **cmd, bool *executable)
/// @param mp The maphash that contains the mapping information
/// @param buffer_value The "buffer" value
/// @param compatible True for compatible with old maparg() dict
-void mapblock_fill_dict(dict_T *const dict,
- const mapblock_T *const mp,
- long buffer_value,
+void mapblock_fill_dict(dict_T *const dict, const mapblock_T *const mp, long buffer_value,
bool compatible)
FUNC_ATTR_NONNULL_ALL
{
@@ -7284,8 +7289,7 @@ void mapblock_fill_dict(dict_T *const dict,
tv_dict_add_allocated_str(dict, S_LEN("mode"), mapmode);
}
-int matchadd_dict_arg(typval_T *tv, const char **conceal_char,
- win_T **win)
+int matchadd_dict_arg(typval_T *tv, const char **conceal_char, win_T **win)
{
dictitem_T *di;
@@ -7333,18 +7337,18 @@ void screenchar_adjust_grid(ScreenGrid **grid, int *row, int *col)
}
/// Set line or list of lines in buffer "buf".
-void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append,
- const typval_T *lines, typval_T *rettv)
+void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T *lines,
+ typval_T *rettv)
FUNC_ATTR_NONNULL_ARG(4, 5)
{
linenr_T lnum = lnum_arg + (append ? 1 : 0);
const char *line = NULL;
- list_T *l = NULL;
- listitem_T *li = NULL;
+ list_T *l = NULL;
+ listitem_T *li = NULL;
long added = 0;
linenr_T append_lnum;
- buf_T *curbuf_save = NULL;
- win_T *curwin_save = NULL;
+ buf_T *curbuf_save = NULL;
+ win_T *curwin_save = NULL;
const bool is_curbuf = buf == curbuf;
// When using the current buffer ml_mfp will be set if needed. Useful when
@@ -7444,8 +7448,8 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append,
}
if (!is_curbuf) {
- curbuf = curbuf_save;
- curwin = curwin_save;
+ curbuf = curbuf_save;
+ curwin = curwin_save;
}
}
@@ -7470,8 +7474,8 @@ void setwinvar(typval_T *argvars, typval_T *rettv, int off)
typval_T *varp = &argvars[off + 2];
if (win != NULL && varname != NULL && varp != NULL) {
- win_T *save_curwin;
- tabpage_T *save_curtab;
+ win_T *save_curwin;
+ tabpage_T *save_curtab;
bool need_switch_win = tp != curtab || win != curwin;
if (!need_switch_win
|| switch_win(&save_curwin, &save_curtab, win, tp, true) == OK) {
@@ -7539,8 +7543,7 @@ static list_T *string_to_list(const char *str, size_t len, const bool keepempty)
}
// os_system wrapper. Handles 'verbose', :profile, and v:shell_error.
-void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv,
- bool retlist)
+void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, bool retlist)
{
proftime_T wait_time;
bool profiling = do_profiling == PROF_YES;
@@ -7595,14 +7598,14 @@ void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv,
xfree(input);
- set_vim_var_nr(VV_SHELL_ERROR, (long) status);
+ set_vim_var_nr(VV_SHELL_ERROR, (long)status);
if (res == NULL) {
if (retlist) {
// return an empty list when there's no output
tv_list_alloc_ret(rettv, 0);
} else {
- rettv->vval.v_string = (char_u *) xstrdup("");
+ rettv->vval.v_string = (char_u *)xstrdup("");
}
return;
}
@@ -7634,7 +7637,7 @@ void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv,
*d = NUL;
#endif
- rettv->vval.v_string = (char_u *) res;
+ rettv->vval.v_string = (char_u *)res;
}
}
@@ -7687,29 +7690,29 @@ bool callback_from_typval(Callback *const callback, typval_T *const arg)
return true;
}
-bool callback_call(Callback *const callback, const int argcount_in,
- typval_T *const argvars_in, typval_T *const rettv)
+bool callback_call(Callback *const callback, const int argcount_in, typval_T *const argvars_in,
+ typval_T *const rettv)
FUNC_ATTR_NONNULL_ALL
{
partial_T *partial;
char_u *name;
switch (callback->type) {
- case kCallbackFuncref:
- name = callback->data.funcref;
- partial = NULL;
- break;
+ case kCallbackFuncref:
+ name = callback->data.funcref;
+ partial = NULL;
+ break;
- case kCallbackPartial:
- partial = callback->data.partial;
- name = partial_name(partial);
- break;
+ case kCallbackPartial:
+ partial = callback->data.partial;
+ name = partial_name(partial);
+ break;
- case kCallbackNone:
- return false;
- break;
+ case kCallbackNone:
+ return false;
+ break;
- default:
- abort();
+ default:
+ abort();
}
funcexe_T funcexe = FUNCEXE_INIT;
@@ -7720,31 +7723,29 @@ bool callback_call(Callback *const callback, const int argcount_in,
return call_func(name, -1, rettv, argcount_in, argvars_in, &funcexe);
}
-static bool set_ref_in_callback(Callback *callback, int copyID,
- ht_stack_T **ht_stack,
+static bool set_ref_in_callback(Callback *callback, int copyID, ht_stack_T **ht_stack,
list_stack_T **list_stack)
{
typval_T tv;
switch (callback->type) {
- case kCallbackFuncref:
- case kCallbackNone:
- break;
+ case kCallbackFuncref:
+ case kCallbackNone:
+ break;
- case kCallbackPartial:
- tv.v_type = VAR_PARTIAL;
- tv.vval.v_partial = callback->data.partial;
- return set_ref_in_item(&tv, copyID, ht_stack, list_stack);
- break;
+ case kCallbackPartial:
+ tv.v_type = VAR_PARTIAL;
+ tv.vval.v_partial = callback->data.partial;
+ return set_ref_in_item(&tv, copyID, ht_stack, list_stack);
+ break;
- default:
- abort();
+ default:
+ abort();
}
return false;
}
-static bool set_ref_in_callback_reader(CallbackReader *reader, int copyID,
- ht_stack_T **ht_stack,
+static bool set_ref_in_callback_reader(CallbackReader *reader, int copyID, ht_stack_T **ht_stack,
list_stack_T **list_stack)
{
if (set_ref_in_callback(&reader->cb, copyID, ht_stack, list_stack)) {
@@ -7762,7 +7763,7 @@ static bool set_ref_in_callback_reader(CallbackReader *reader, int copyID,
timer_T *find_timer_by_nr(varnumber_T xx)
{
- return pmap_get(uint64_t)(&timers, xx);
+ return pmap_get(uint64_t)(&timers, xx);
}
void add_timer_info(typval_T *rettv, timer_T *timer)
@@ -7851,9 +7852,7 @@ void timer_due_cb(TimeWatcher *tw, void *data)
timer_decref(timer);
}
-uint64_t timer_start(const long timeout,
- const int repeat_count,
- const Callback *const callback)
+uint64_t timer_start(const long timeout, const int repeat_count, const Callback *const callback)
{
timer_T *timer = xmalloc(sizeof *timer);
timer->refcount = 1;
@@ -7924,8 +7923,7 @@ void timer_teardown(void)
/// @param[in] binary Whether to write in binary mode.
///
/// @return true in case of success, false otherwise.
-bool write_list(FileDescriptor *const fp, const list_T *const list,
- const bool binary)
+bool write_list(FileDescriptor *const fp, const list_T *const list, const bool binary)
FUNC_ATTR_NONNULL_ARG(1)
{
int error = 0;
@@ -8123,16 +8121,15 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl)
/// @param[out] ret_fnum Set to fnum for marks.
///
/// @return Pointer to position or NULL in case of error (e.g. invalid type).
-pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum,
- int *const ret_fnum)
+pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret_fnum)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
static pos_T pos;
- pos_T *pp;
+ pos_T *pp;
// Argument can be [lnum, col, coladd].
if (tv->v_type == VAR_LIST) {
- list_T *l;
+ list_T *l;
int len;
bool error = false;
listitem_T *li;
@@ -8350,10 +8347,7 @@ int get_id_len(const char **const arg)
* If the name contains 'magic' {}'s, expand them and return the
* expanded name in an allocated string via 'alias' - caller must free.
*/
-int get_name_len(const char **const arg,
- char **alias,
- bool evaluate,
- bool verbose)
+int get_name_len(const char **const arg, char **alias, bool evaluate, bool verbose)
{
int len;
@@ -8372,8 +8366,8 @@ int get_name_len(const char **const arg,
}
// Find the end of the name; check for {} construction.
- char_u *expr_start;
- char_u *expr_end;
+ char_u *expr_start;
+ char_u *expr_end;
const char *p = (const char *)find_name_end((char_u *)(*arg),
(const char_u **)&expr_start,
(const char_u **)&expr_end,
@@ -8415,8 +8409,8 @@ int get_name_len(const char **const arg,
// "flags" can have FNE_INCL_BR and FNE_CHECK_START.
// Return a pointer to just after the name. Equal to "arg" if there is no
// valid name.
-const char_u *find_name_end(const char_u *arg, const char_u **expr_start,
- const char_u **expr_end, int flags)
+const char_u *find_name_end(const char_u *arg, const char_u **expr_start, const char_u **expr_end,
+ int flags)
{
int mb_nest = 0;
int br_nest = 0;
@@ -8497,24 +8491,25 @@ const char_u *find_name_end(const char_u *arg, const char_u **expr_start,
* Note that this can call itself recursively, to deal with
* constructs like foo{bar}{baz}{bam}
* The four pointer arguments point to "foo{expre}ss{ion}bar"
- * "in_start" ^
- * "expr_start" ^
- * "expr_end" ^
- * "in_end" ^
+ * "in_start" ^
+ * "expr_start" ^
+ * "expr_end" ^
+ * "in_end" ^
*
* Returns a new allocated string, which the caller must free.
* Returns NULL for failure.
*/
-static char_u *make_expanded_name(const char_u *in_start, char_u *expr_start,
- char_u *expr_end, char_u *in_end)
+static char_u *make_expanded_name(const char_u *in_start, char_u *expr_start, char_u *expr_end,
+ char_u *in_end)
{
char_u c1;
- char_u *retval = NULL;
- char_u *temp_result;
- char_u *nextcmd = NULL;
+ char_u *retval = NULL;
+ char_u *temp_result;
+ char_u *nextcmd = NULL;
- if (expr_end == NULL || in_end == NULL)
+ if (expr_end == NULL || in_end == NULL) {
return NULL;
+ }
*expr_start = NUL;
*expr_end = NUL;
c1 = *in_end;
@@ -8541,7 +8536,7 @@ static char_u *make_expanded_name(const char_u *in_start, char_u *expr_start,
if (expr_start != NULL) {
// Further expansion!
temp_result = make_expanded_name(retval, expr_start,
- expr_end, temp_result);
+ expr_end, temp_result);
xfree(retval);
retval = temp_result;
}
@@ -8617,8 +8612,9 @@ void set_vim_var_char(int c)
*/
void set_vcount(long count, long count1, int set_prevcount)
{
- if (set_prevcount)
+ if (set_prevcount) {
vimvars[VV_PREVCOUNT].vv_nr = vimvars[VV_COUNT].vv_nr;
+ }
vimvars[VV_COUNT].vv_nr = count;
vimvars[VV_COUNT1].vv_nr = count1;
}
@@ -8662,17 +8658,16 @@ void set_vim_var_special(const VimVarIndex idx, const SpecialVarValue val)
/// @param[in] val Value to set to. Will be copied.
/// @param[in] len Length of that value or -1 in which case strlen() will be
/// used.
-void set_vim_var_string(const VimVarIndex idx, const char *const val,
- const ptrdiff_t len)
+void set_vim_var_string(const VimVarIndex idx, const char *const val, const ptrdiff_t len)
{
tv_clear(&vimvars[idx].vv_di.di_tv);
vimvars[idx].vv_type = VAR_STRING;
if (val == NULL) {
vimvars[idx].vv_str = NULL;
} else if (len == -1) {
- vimvars[idx].vv_str = (char_u *) xstrdup(val);
+ vimvars[idx].vv_str = (char_u *)xstrdup(val);
} else {
- vimvars[idx].vv_str = (char_u *) xstrndup(val, (size_t) len);
+ vimvars[idx].vv_str = (char_u *)xstrndup(val, (size_t)len);
}
}
@@ -8748,8 +8743,9 @@ void set_reg_var(int c)
*/
char_u *v_exception(char_u *oldval)
{
- if (oldval == NULL)
+ if (oldval == NULL) {
return vimvars[VV_EXCEPTION].vv_str;
+ }
vimvars[VV_EXCEPTION].vv_str = oldval;
return NULL;
@@ -8763,8 +8759,9 @@ char_u *v_exception(char_u *oldval)
*/
char_u *v_throwpoint(char_u *oldval)
{
- if (oldval == NULL)
+ if (oldval == NULL) {
return vimvars[VV_THROWPOINT].vv_str;
+ }
vimvars[VV_THROWPOINT].vv_str = oldval;
return NULL;
@@ -8786,13 +8783,15 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg)
}
size_t len = 0;
- if (eap->force_bin == FORCE_BIN)
+ if (eap->force_bin == FORCE_BIN) {
len = 6;
- else if (eap->force_bin == FORCE_NOBIN)
+ } else if (eap->force_bin == FORCE_NOBIN) {
len = 8;
+ }
- if (eap->read_edit)
+ if (eap->read_edit) {
len += 7;
+ }
if (eap->force_ff != 0) {
len += 10; // " ++ff=unix"
@@ -8807,15 +8806,17 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg)
const size_t newval_len = len + 1;
char_u *newval = xmalloc(newval_len);
- if (eap->force_bin == FORCE_BIN)
+ if (eap->force_bin == FORCE_BIN) {
sprintf((char *)newval, " ++bin");
- else if (eap->force_bin == FORCE_NOBIN)
+ } else if (eap->force_bin == FORCE_NOBIN) {
sprintf((char *)newval, " ++nobin");
- else
+ } else {
*newval = NUL;
+ }
- if (eap->read_edit)
+ if (eap->read_edit) {
STRCAT(newval, " ++edit");
+ }
if (eap->force_ff != 0) {
snprintf((char *)newval + STRLEN(newval), newval_len, " ++ff=%s",
@@ -8838,20 +8839,20 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg)
return oldval;
}
-// Get the value of internal variable "name".
-// Return OK or FAIL. If OK is returned "rettv" must be cleared.
-int get_var_tv(
- const char *name,
- int len, // length of "name"
- typval_T *rettv, // NULL when only checking existence
- dictitem_T **dip, // non-NULL when typval's dict item is needed
- int verbose, // may give error message
- int no_autoload // do not use script autoloading
-)
+/// Get the value of internal variable "name".
+/// Return OK or FAIL. If OK is returned "rettv" must be cleared.
+///
+/// @param len length of "name"
+/// @param rettv NULL when only checking existence
+/// @param dip non-NULL when typval's dict item is needed
+/// @param verbose may give error message
+/// @param no_autoload do not use script autoloading
+int get_var_tv(const char *name, int len, typval_T *rettv, dictitem_T **dip, int verbose,
+ int no_autoload)
{
int ret = OK;
- typval_T *tv = NULL;
- dictitem_T *v;
+ typval_T *tv = NULL;
+ dictitem_T *v;
v = find_var(name, (size_t)len, NULL, no_autoload);
if (v != NULL) {
@@ -8934,15 +8935,13 @@ int check_luafunc_name(const char *const str, const bool paren)
/// - method call: var->method()
///
/// Can all be combined in any order: dict.func(expr)[idx]['func'](expr)->len()
-int
-handle_subscript(
- const char **const arg,
- typval_T *rettv,
- int evaluate, // do more than finding the end
- int verbose, // give error messages
- const char_u *const start_leader, // start of '!' and '-' prefixes
- const char_u **const end_leaderp // end of '!' and '-' prefixes
-)
+///
+/// @param evaluate do more than finding the end
+/// @param verbose give error messages
+/// @param start_leader start of '!' and '-' prefixes
+/// @param end_leaderp end of '!' and '-' prefixes
+int handle_subscript(const char **const arg, typval_T *rettv, int evaluate, int verbose,
+ const char_u *const start_leader, const char_u **const end_leaderp)
{
int ret = OK;
dict_T *selfdict = NULL;
@@ -9005,10 +9004,12 @@ handle_subscript(
tv_dict_unref(selfdict);
if (rettv->v_type == VAR_DICT) {
selfdict = rettv->vval.v_dict;
- if (selfdict != NULL)
+ if (selfdict != NULL) {
++selfdict->dv_refcount;
- } else
+ }
+ } else {
selfdict = NULL;
+ }
if (eval_index((char_u **)arg, rettv, evaluate, verbose) == FAIL) {
tv_clear(rettv);
ret = FAIL;
@@ -9041,8 +9042,8 @@ void set_selfdict(typval_T *const rettv, dict_T *const selfdict)
// Careful: "a:0" variables don't have a name.
// When "htp" is not NULL we are writing to the variable, set "htp" to the
// hashtab_T used.
-dictitem_T *find_var(const char *const name, const size_t name_len,
- hashtab_T **htp, int no_autoload)
+dictitem_T *find_var(const char *const name, const size_t name_len, hashtab_T **htp,
+ int no_autoload)
{
const char *varname;
hashtab_T *const ht = find_var_ht(name, name_len, &varname);
@@ -9076,26 +9077,31 @@ dictitem_T *find_var(const char *const name, const size_t name_len,
///
/// @return pointer to the dictionary item with the found variable or NULL if it
/// was not found.
-dictitem_T *find_var_in_ht(hashtab_T *const ht,
- int htname,
- const char *const varname,
- const size_t varname_len,
- int no_autoload)
+dictitem_T *find_var_in_ht(hashtab_T *const ht, int htname, const char *const varname,
+ const size_t varname_len, int no_autoload)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
- hashitem_T *hi;
+ hashitem_T *hi;
if (varname_len == 0) {
// Must be something like "s:", otherwise "ht" would be NULL.
switch (htname) {
- case 's': return (dictitem_T *)&SCRIPT_SV(current_sctx.sc_sid)->sv_var;
- case 'g': return (dictitem_T *)&globvars_var;
- case 'v': return (dictitem_T *)&vimvars_var;
- case 'b': return (dictitem_T *)&curbuf->b_bufvar;
- case 'w': return (dictitem_T *)&curwin->w_winvar;
- case 't': return (dictitem_T *)&curtab->tp_winvar;
- case 'l': return get_funccal_local_var();
- case 'a': return get_funccal_args_var();
+ case 's':
+ return (dictitem_T *)&SCRIPT_SV(current_sctx.sc_sid)->sv_var;
+ case 'g':
+ return (dictitem_T *)&globvars_var;
+ case 'v':
+ return (dictitem_T *)&vimvars_var;
+ case 'b':
+ return (dictitem_T *)&curbuf->b_bufvar;
+ case 'w':
+ return (dictitem_T *)&curwin->w_winvar;
+ case 't':
+ return (dictitem_T *)&curtab->tp_winvar;
+ case 'l':
+ return get_funccal_local_var();
+ case 'a':
+ return get_funccal_args_var();
}
return NULL;
}
@@ -9130,8 +9136,8 @@ dictitem_T *find_var_in_ht(hashtab_T *const ht,
/// @param[out] d Scope dictionary.
///
/// @return Scope hashtab, NULL if name is not valid.
-static hashtab_T *find_var_ht_dict(const char *name, const size_t name_len,
- const char **varname, dict_T **d)
+static hashtab_T *find_var_ht_dict(const char *name, const size_t name_len, const char **varname,
+ dict_T **d)
{
hashitem_T *hi;
funccall_T *funccal = get_funccal();
@@ -9202,8 +9208,7 @@ end:
/// prefix.
///
/// @return Scope hashtab, NULL if name is not valid.
-hashtab_T *find_var_ht(const char *name, const size_t name_len,
- const char **varname)
+hashtab_T *find_var_ht(const char *name, const size_t name_len, const char **varname)
{
dict_T *d;
return find_var_ht_dict(name, name_len, varname, &d);
@@ -9216,7 +9221,7 @@ hashtab_T *find_var_ht(const char *name, const size_t name_len,
*/
char_u *get_var_value(const char *const name)
{
- dictitem_T *v;
+ dictitem_T *v;
v = find_var(name, strlen(name), NULL, false);
if (v == NULL) {
@@ -9231,7 +9236,7 @@ char_u *get_var_value(const char *const name)
*/
void new_script_vars(scid_T id)
{
- hashtab_T *ht;
+ hashtab_T *ht;
scriptvar_T *sv;
ga_grow(&ga_scripts, (int)(id - ga_scripts.ga_len));
@@ -9241,8 +9246,9 @@ void new_script_vars(scid_T id)
* at its init value. Also reset "v_dict", it's always the same. */
for (int i = 1; i <= ga_scripts.ga_len; ++i) {
ht = &SCRIPT_VARS(i);
- if (ht->ht_mask == HT_INIT_SIZE - 1)
+ if (ht->ht_mask == HT_INIT_SIZE - 1) {
ht->ht_array = ht->ht_smallarray;
+ }
sv = SCRIPT_SV(i);
sv->sv_var.di_tv.vval.v_dict = &sv->sv_dict;
}
@@ -9301,8 +9307,8 @@ void vars_clear(hashtab_T *ht)
void vars_clear_ext(hashtab_T *ht, int free_val)
{
int todo;
- hashitem_T *hi;
- dictitem_T *v;
+ hashitem_T *hi;
+ dictitem_T *v;
hash_lock(ht);
todo = (int)ht->ht_used;
@@ -9332,7 +9338,7 @@ void vars_clear_ext(hashtab_T *ht, int free_val)
*/
static void delete_var(hashtab_T *ht, hashitem_T *hi)
{
- dictitem_T *di = TV_DICT_HI2DI(hi);
+ dictitem_T *di = TV_DICT_HI2DI(hi);
hash_remove(ht, hi);
tv_clear(&di->di_tv);
@@ -9353,9 +9359,8 @@ static void list_one_var(dictitem_T *v, const char *prefix, int *first)
/// @param[in] name_len Length of the name. May be -1, in this case strlen()
/// will be used.
/// @param[in,out] first When true clear rest of screen and set to false.
-static void list_one_var_a(const char *prefix, const char *name,
- const ptrdiff_t name_len, const int type,
- const char *string, int *first)
+static void list_one_var_a(const char *prefix, const char *name, const ptrdiff_t name_len,
+ const int type, const char *string, int *first)
{
// don't use msg() or msg_attr() to avoid overwriting "v:statusmsg"
msg_start();
@@ -9371,14 +9376,17 @@ static void list_one_var_a(const char *prefix, const char *name,
msg_putchar('*');
} else if (type == VAR_LIST) {
msg_putchar('[');
- if (*string == '[')
+ if (*string == '[') {
++string;
+ }
} else if (type == VAR_DICT) {
msg_putchar('{');
- if (*string == '{')
+ if (*string == '{') {
++string;
- } else
+ }
+ } else {
msg_putchar(' ');
+ }
msg_outtrans((char_u *)string);
@@ -9400,8 +9408,7 @@ static void list_one_var_a(const char *prefix, const char *name,
/// @param[in] name_len Length of the variable name.
/// @param tv Variable value.
/// @param[in] copy True if value in tv is to be copied.
-void set_var(const char *name, const size_t name_len, typval_T *const tv,
- const bool copy)
+void set_var(const char *name, const size_t name_len, typval_T *const tv, const bool copy)
FUNC_ATTR_NONNULL_ALL
{
set_var_const(name, name_len, tv, copy, false);
@@ -9417,13 +9424,12 @@ void set_var(const char *name, const size_t name_len, typval_T *const tv,
/// @param tv Variable value.
/// @param[in] copy True if value in tv is to be copied.
/// @param[in] is_const True if value in tv is to be locked.
-static void set_var_const(const char *name, const size_t name_len,
- typval_T *const tv, const bool copy,
- const bool is_const)
+static void set_var_const(const char *name, const size_t name_len, typval_T *const tv,
+ const bool copy, const bool is_const)
FUNC_ATTR_NONNULL_ALL
{
- dictitem_T *v;
- hashtab_T *ht;
+ dictitem_T *v;
+ hashtab_T *ht;
dict_T *dict;
const char *varname;
@@ -9567,8 +9573,7 @@ static void set_var_const(const char *name, const size_t name_len,
///
/// @return True if variable is read-only: either always or in sandbox when
/// sandbox is enabled, false otherwise.
-bool var_check_ro(const int flags, const char *name,
- size_t name_len)
+bool var_check_ro(const int flags, const char *name, size_t name_len)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
const char *error_message = NULL;
@@ -9611,8 +9616,7 @@ bool var_check_ro(const int flags, const char *name,
/// gettext.
///
/// @return True if variable is fixed, false otherwise.
-bool var_check_fixed(const int flags, const char *name,
- size_t name_len)
+bool var_check_fixed(const int flags, const char *name, size_t name_len)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
if (flags & DI_FLAGS_FIX) {
@@ -9696,11 +9700,8 @@ bool valid_varname(const char *varname)
/// a copy with (`copy[0] isnot copy[1]`), with non-zero it
/// will emit a copy with (`copy[0] is copy[1]`) like in the
/// original list. Not used when deep is false.
-int var_item_copy(const vimconv_T *const conv,
- typval_T *const from,
- typval_T *const to,
- const bool deep,
- const int copyID)
+int var_item_copy(const vimconv_T *const conv, typval_T *const from, typval_T *const to,
+ const bool deep, const int copyID)
FUNC_ATTR_NONNULL_ARG(2, 3)
{
static int recurse = 0;
@@ -9732,7 +9733,7 @@ int var_item_copy(const vimconv_T *const conv,
from->vval.v_string,
NULL))
== NULL) {
- to->vval.v_string = (char_u *) xstrdup((char *) from->vval.v_string);
+ to->vval.v_string = (char_u *)xstrdup((char *)from->vval.v_string);
}
}
break;
@@ -9780,21 +9781,22 @@ int var_item_copy(const vimconv_T *const conv,
}
/*
- * ":echo expr1 ..." print each argument separated with a space, add a
- * newline at the end.
- * ":echon expr1 ..." print each argument plain.
+ * ":echo expr1 ..." print each argument separated with a space, add a
+ * newline at the end.
+ * ":echon expr1 ..." print each argument plain.
*/
void ex_echo(exarg_T *eap)
{
- char_u *arg = eap->arg;
+ char_u *arg = eap->arg;
typval_T rettv;
bool atstart = true;
bool need_clear = true;
const int did_emsg_before = did_emsg;
const int called_emsg_before = called_emsg;
- if (eap->skip)
+ if (eap->skip) {
++emsg_skip;
+ }
while (*arg != NUL && *arg != '|' && *arg != '\n' && !got_int) {
// If eval1() causes an error message the text from the command may
// still need to be cleared. E.g., "echo 22,44".
@@ -9865,9 +9867,9 @@ void ex_echohl(exarg_T *eap)
}
/*
- * ":execute expr1 ..." execute the result of an expression.
- * ":echomsg expr1 ..." Print a message
- * ":echoerr expr1 ..." Print an error
+ * ":execute expr1 ..." execute the result of an expression.
+ * ":echomsg expr1 ..." Print a message
+ * ":echoerr expr1 ..." Print an error
* Each gets spaces around each argument and a newline at the end for
* echo commands
*/
@@ -9881,8 +9883,9 @@ void ex_execute(exarg_T *eap)
ga_init(&ga, 1, 80);
- if (eap->skip)
+ if (eap->skip) {
++emsg_skip;
+ }
while (*arg != NUL && *arg != '|' && *arg != '\n') {
ret = eval1_emsg(&arg, &rettv, !eap->skip);
if (ret == FAIL) {
@@ -9928,17 +9931,20 @@ void ex_execute(exarg_T *eap)
save_did_emsg = did_emsg;
msg_ext_set_kind("echoerr");
EMSG((char_u *)ga.ga_data);
- if (!force_abort)
+ if (!force_abort) {
did_emsg = save_did_emsg;
- } else if (eap->cmdidx == CMD_execute)
+ }
+ } else if (eap->cmdidx == CMD_execute) {
do_cmdline((char_u *)ga.ga_data,
- eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE);
+ eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE);
+ }
}
ga_clear(&ga);
- if (eap->skip)
+ if (eap->skip) {
--emsg_skip;
+ }
eap->nextcmd = check_nextcmd(arg);
}
@@ -10016,10 +10022,10 @@ void func_do_profile(ufunc_T *fp)
*/
void func_dump_profile(FILE *fd)
{
- hashitem_T *hi;
+ hashitem_T *hi;
int todo;
- ufunc_T *fp;
- ufunc_T **sorttab;
+ ufunc_T *fp;
+ ufunc_T **sorttab;
int st_len = 0;
todo = (int)func_hashtab.ht_used;
@@ -10045,7 +10051,7 @@ void func_dump_profile(FILE *fd)
bool should_free;
const LastSet last_set = (LastSet){
.script_ctx = fp->uf_script_ctx,
- .channel_id = 0,
+ .channel_id = 0,
};
char_u *p = get_scriptname(last_set, &should_free);
fprintf(fd, " Defined: %s:%" PRIdLINENR "\n",
@@ -10065,10 +10071,11 @@ void func_dump_profile(FILE *fd)
fprintf(fd, "count total (s) self (s)\n");
for (int i = 0; i < fp->uf_lines.ga_len; ++i) {
- if (FUNCLINE(fp, i) == NULL)
+ if (FUNCLINE(fp, i) == NULL) {
continue;
+ }
prof_func_line(fd, fp->uf_tml_count[i],
- &fp->uf_tml_total[i], &fp->uf_tml_self[i], TRUE);
+ &fp->uf_tml_total[i], &fp->uf_tml_self[i], TRUE);
fprintf(fd, "%s\n", FUNCLINE(fp, i));
}
fprintf(fd, "\n");
@@ -10078,65 +10085,58 @@ void func_dump_profile(FILE *fd)
if (st_len > 0) {
qsort((void *)sorttab, (size_t)st_len, sizeof(ufunc_T *),
- prof_total_cmp);
+ prof_total_cmp);
prof_sort_list(fd, sorttab, st_len, "TOTAL", FALSE);
qsort((void *)sorttab, (size_t)st_len, sizeof(ufunc_T *),
- prof_self_cmp);
+ prof_self_cmp);
prof_sort_list(fd, sorttab, st_len, "SELF", TRUE);
}
xfree(sorttab);
}
-static void
-prof_sort_list(
- FILE *fd,
- ufunc_T **sorttab,
- int st_len,
- char *title,
- int prefer_self // when equal print only self time
-)
+/// @param prefer_self when equal print only self time
+static void prof_sort_list(FILE *fd, ufunc_T **sorttab, int st_len, char *title, int prefer_self)
{
int i;
- ufunc_T *fp;
+ ufunc_T *fp;
fprintf(fd, "FUNCTIONS SORTED ON %s TIME\n", title);
fprintf(fd, "count total (s) self (s) function\n");
for (i = 0; i < 20 && i < st_len; ++i) {
fp = sorttab[i];
prof_func_line(fd, fp->uf_tm_count, &fp->uf_tm_total, &fp->uf_tm_self,
- prefer_self);
- if (fp->uf_name[0] == K_SPECIAL)
+ prefer_self);
+ if (fp->uf_name[0] == K_SPECIAL) {
fprintf(fd, " <SNR>%s()\n", fp->uf_name + 3);
- else
+ } else {
fprintf(fd, " %s()\n", fp->uf_name);
+ }
}
fprintf(fd, "\n");
}
-/*
- * Print the count and times for one function or function line.
- */
-static void prof_func_line(
- FILE *fd,
- int count,
- proftime_T *total,
- proftime_T *self,
- int prefer_self // when equal print only self time
-)
+/// Print the count and times for one function or function line.
+///
+/// @param prefer_self when equal print only self time
+static void prof_func_line(FILE *fd, int count, proftime_T *total, proftime_T *self,
+ int prefer_self)
{
if (count > 0) {
fprintf(fd, "%5d ", count);
- if (prefer_self && profile_equal(*total, *self))
+ if (prefer_self && profile_equal(*total, *self)) {
fprintf(fd, " ");
- else
+ } else {
fprintf(fd, "%s ", profile_msg(*total));
- if (!prefer_self && profile_equal(*total, *self))
+ }
+ if (!prefer_self && profile_equal(*total, *self)) {
fprintf(fd, " ");
- else
+ } else {
fprintf(fd, "%s ", profile_msg(*self));
- } else
+ }
+ } else {
fprintf(fd, " ");
+ }
}
/*
@@ -10194,8 +10194,7 @@ char *autoload_name(const char *const name, const size_t name_len)
/// @param[in] reload If true, load script again when already loaded.
///
/// @return true if a package was loaded.
-bool script_autoload(const char *const name, const size_t name_len,
- const bool reload)
+bool script_autoload(const char *const name, const size_t name_len, const bool reload)
{
// If there is no '#' after name[0] there is no package name.
const char *p = memchr(name, AUTOLOAD_CHAR, name_len);
@@ -10242,8 +10241,8 @@ bool script_autoload(const char *const name, const size_t name_len,
*/
void func_line_start(void *cookie)
{
- funccall_T *fcp = (funccall_T *)cookie;
- ufunc_T *fp = fcp->func;
+ funccall_T *fcp = (funccall_T *)cookie;
+ ufunc_T *fp = fcp->func;
if (fp->uf_profiling && sourcing_lnum >= 1
&& sourcing_lnum <= fp->uf_lines.ga_len) {
@@ -10264,11 +10263,12 @@ void func_line_start(void *cookie)
*/
void func_line_exec(void *cookie)
{
- funccall_T *fcp = (funccall_T *)cookie;
- ufunc_T *fp = fcp->func;
+ funccall_T *fcp = (funccall_T *)cookie;
+ ufunc_T *fp = fcp->func;
- if (fp->uf_profiling && fp->uf_tml_idx >= 0)
+ if (fp->uf_profiling && fp->uf_tml_idx >= 0) {
fp->uf_tml_execed = TRUE;
+ }
}
/*
@@ -10276,8 +10276,8 @@ void func_line_exec(void *cookie)
*/
void func_line_end(void *cookie)
{
- funccall_T *fcp = (funccall_T *)cookie;
- ufunc_T *fp = fcp->func;
+ funccall_T *fcp = (funccall_T *)cookie;
+ ufunc_T *fp = fcp->func;
if (fp->uf_profiling && fp->uf_tml_idx >= 0) {
if (fp->uf_tml_execed) {
@@ -10288,7 +10288,7 @@ void func_line_end(void *cookie)
profile_add(fp->uf_tml_total[fp->uf_tml_idx], fp->uf_tml_start);
fp->uf_tml_self[fp->uf_tml_idx] =
profile_self(fp->uf_tml_self[fp->uf_tml_idx], fp->uf_tml_start,
- fp->uf_tml_children);
+ fp->uf_tml_children);
}
fp->uf_tml_idx = -1;
}
@@ -10299,10 +10299,11 @@ static var_flavour_T var_flavour(char_u *varname)
char_u *p = varname;
if (ASCII_ISUPPER(*p)) {
- while (*(++p))
+ while (*(++p)) {
if (ASCII_ISLOWER(*p)) {
return VAR_FLAVOUR_SESSION;
}
+ }
return VAR_FLAVOUR_SHADA;
} else {
return VAR_FLAVOUR_DEFAULT;
@@ -10320,26 +10321,26 @@ static var_flavour_T var_flavour(char_u *varname)
///
/// @return Pointer that needs to be passed to next `var_shada_iter` invocation
/// or NULL to indicate that iteration is over.
-const void *var_shada_iter(const void *const iter, const char **const name,
- typval_T *rettv, var_flavour_T flavour)
+const void *var_shada_iter(const void *const iter, const char **const name, typval_T *rettv,
+ var_flavour_T flavour)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(2, 3)
{
const hashitem_T *hi;
const hashitem_T *hifirst = globvarht.ht_array;
- const size_t hinum = (size_t) globvarht.ht_mask + 1;
+ const size_t hinum = (size_t)globvarht.ht_mask + 1;
*name = NULL;
if (iter == NULL) {
hi = globvarht.ht_array;
- while ((size_t) (hi - hifirst) < hinum
+ while ((size_t)(hi - hifirst) < hinum
&& (HASHITEM_EMPTY(hi)
|| !(var_flavour(hi->hi_key) & flavour))) {
hi++;
}
- if ((size_t) (hi - hifirst) == hinum) {
+ if ((size_t)(hi - hifirst) == hinum) {
return NULL;
}
} else {
- hi = (const hashitem_T *) iter;
+ hi = (const hashitem_T *)iter;
}
*name = (char *)TV_DICT_HI2DI(hi)->di_key;
tv_copy(&TV_DICT_HI2DI(hi)->di_tv, rettv);
@@ -10368,9 +10369,8 @@ int store_session_globals(FILE *fd)
&& var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) {
// Escape special characters with a backslash. Turn a LF and
// CR into \n and \r.
- char_u *const p = vim_strsave_escaped(
- (const char_u *)tv_get_string(&this_var->di_tv),
- (const char_u *)"\\\"\n\r");
+ char_u *const p = vim_strsave_escaped((const char_u *)tv_get_string(&this_var->di_tv),
+ (const char_u *)"\\\"\n\r");
for (char_u *t = p; *t != NUL; t++) {
if (*t == '\n') {
*t = 'n';
@@ -10381,10 +10381,10 @@ int store_session_globals(FILE *fd)
if ((fprintf(fd, "let %s = %c%s%c",
this_var->di_key,
((this_var->di_tv.v_type == VAR_STRING) ? '"'
- : ' '),
+ : ' '),
p,
((this_var->di_tv.v_type == VAR_STRING) ? '"'
- : ' ')) < 0)
+ : ' ')) < 0)
|| put_eol(fd) == FAIL) {
xfree(p);
return FAIL;
@@ -10451,26 +10451,24 @@ void reset_v_option_vars(void)
set_vim_var_string(VV_OPTION_TYPE, NULL, -1);
}
-/*
- * Adjust a filename, according to a string of modifiers.
- * *fnamep must be NUL terminated when called. When returning, the length is
- * determined by *fnamelen.
- * Returns VALID_ flags or -1 for failure.
- * When there is an error, *fnamep is set to NULL.
- */
-int
-modify_fname(
- char_u *src, // string with modifiers
- bool tilde_file, // "~" is a file name, not $HOME
- size_t *usedlen, // characters after src that are used
- char_u **fnamep, // file name so far
- char_u **bufp, // buffer for allocated file name or NULL
- size_t *fnamelen // length of fnamep
-)
+/// Adjust a filename, according to a string of modifiers.
+/// *fnamep must be NUL terminated when called. When returning, the length is
+/// determined by *fnamelen.
+/// Returns VALID_ flags or -1 for failure.
+/// When there is an error, *fnamep is set to NULL.
+///
+/// @param src string with modifiers
+/// @param tilde_file "~" is a file name, not $HOME
+/// @param usedlen characters after src that are used
+/// @param fnamep file name so far
+/// @param bufp buffer for allocated file name or NULL
+/// @param fnamelen length of fnamep
+int modify_fname(char_u *src, bool tilde_file, size_t *usedlen, char_u **fnamep, char_u **bufp,
+ size_t *fnamelen)
{
int valid = 0;
- char_u *tail;
- char_u *s, *p, *pbuf;
+ char_u *tail;
+ char_u *s, *p, *pbuf;
char_u dirname[MAXPATHL];
int c;
int has_fullname = 0;
@@ -10492,13 +10490,13 @@ repeat:
# endif
|| (*fnamep)[1] == NUL)
#endif
- && !(tilde_file && (*fnamep)[1] == NUL)
- ) {
+ && !(tilde_file && (*fnamep)[1] == NUL)) {
*fnamep = expand_env_save(*fnamep);
xfree(*bufp); // free any allocated file name
*bufp = *fnamep;
- if (*fnamep == NULL)
+ if (*fnamep == NULL) {
return -1;
+ }
}
// When "/." or "/.." is used: force expansion to get rid of it.
@@ -10518,8 +10516,9 @@ repeat:
*fnamep = (char_u *)FullName_save((char *)(*fnamep), *p != NUL);
xfree(*bufp); // free any allocated file name
*bufp = *fnamep;
- if (*fnamep == NULL)
+ if (*fnamep == NULL) {
return -1;
+ }
}
// Append a path separator to a directory.
@@ -10528,8 +10527,9 @@ repeat:
*fnamep = vim_strnsave(*fnamep, STRLEN(*fnamep) + 2);
xfree(*bufp); // free any allocated file name
*bufp = *fnamep;
- if (*fnamep == NULL)
+ if (*fnamep == NULL) {
return -1;
+ }
add_pathsep((char *)*fnamep);
}
}
@@ -10546,12 +10546,14 @@ repeat:
pbuf = NULL;
// Need full path first (use expand_env() to remove a "~/")
if (!has_fullname) {
- if (c == '.' && **fnamep == '~')
+ if (c == '.' && **fnamep == '~') {
p = pbuf = expand_env_save(*fnamep);
- else
+ } else {
p = pbuf = (char_u *)FullName_save((char *)*fnamep, FALSE);
- } else
+ }
+ } else {
p = *fnamep;
+ }
has_fullname = 0;
@@ -10678,7 +10680,7 @@ repeat:
&& (src[*usedlen + 1] == 's'
|| (src[*usedlen + 1] == 'g' && src[*usedlen + 2] == 's'))) {
int sep;
- char_u *flags;
+ char_u *flags;
int didit = FALSE;
flags = (char_u *)"";
@@ -10742,17 +10744,16 @@ repeat:
/// When "sub" is NULL "expr" is used, must be a VAR_FUNC or VAR_PARTIAL.
/// "flags" can be "g" to do a global substitute.
/// Returns an allocated string, NULL for error.
-char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub,
- typval_T *expr, char_u *flags)
+char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, typval_T *expr, char_u *flags)
{
int sublen;
regmatch_T regmatch;
int do_all;
- char_u *tail;
- char_u *end;
+ char_u *tail;
+ char_u *end;
garray_T ga;
- char_u *save_cpo;
- char_u *zero_width = NULL;
+ char_u *save_cpo;
+ char_u *zero_width = NULL;
// Make 'cpoptions' empty, so that the 'l' flag doesn't work here
save_cpo = p_cpo;
@@ -10788,7 +10789,7 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub,
// - The text after the match.
sublen = vim_regsub(&regmatch, sub, expr, tail, false, true, false);
ga_grow(&ga, (int)((end - tail) + sublen -
- (regmatch.endp[0] - regmatch.startp[0])));
+ (regmatch.endp[0] - regmatch.startp[0])));
// copy the text up to where the match is
int i = (int)(regmatch.startp[0] - tail);
@@ -10798,14 +10799,17 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub,
+ ga.ga_len + i, true, true, false);
ga.ga_len += i + sublen - 1;
tail = regmatch.endp[0];
- if (*tail == NUL)
+ if (*tail == NUL) {
break;
- if (!do_all)
+ }
+ if (!do_all) {
break;
+ }
}
- if (ga.ga_data != NULL)
+ if (ga.ga_data != NULL) {
STRCPY((char *)ga.ga_data + ga.ga_len, tail);
+ }
vim_regfree(regmatch.regprog);
}
@@ -10825,9 +10829,7 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub,
/// common code for getting job callbacks for jobstart, termopen and rpcstart
///
/// @return true/false on success/failure.
-bool common_job_callbacks(dict_T *vopts,
- CallbackReader *on_stdout,
- CallbackReader *on_stderr,
+bool common_job_callbacks(dict_T *vopts, CallbackReader *on_stdout, CallbackReader *on_stderr,
Callback *on_exit)
{
if (tv_dict_get_callback(vopts, S_LEN("on_stdout"), &on_stdout->cb)
@@ -10888,8 +10890,7 @@ void script_host_eval(char *name, typval_T *argvars, typval_T *rettv)
/// @param discard Clears the value returned by the provider and returns
/// an empty typval_T.
-typval_T eval_call_provider(char *provider, char *method, list_T *arguments,
- bool discard)
+typval_T eval_call_provider(char *provider, char *method, list_T *arguments, bool discard)
{
if (!eval_has_provider(provider)) {
emsgf("E319: No \"%s\" provider found. Run \":checkhealth provider\"",
@@ -11052,59 +11053,59 @@ void ex_checkhealth(exarg_T *eap)
void invoke_prompt_callback(void)
{
- typval_T rettv;
- typval_T argv[2];
- char_u *text;
- char_u *prompt;
- linenr_T lnum = curbuf->b_ml.ml_line_count;
-
- // Add a new line for the prompt before invoking the callback, so that
- // text can always be inserted above the last line.
- ml_append(lnum, (char_u *)"", 0, false);
- curwin->w_cursor.lnum = lnum + 1;
- curwin->w_cursor.col = 0;
-
- if (curbuf->b_prompt_callback.type == kCallbackNone) {
- return;
- }
- text = ml_get(lnum);
- prompt = prompt_text();
- if (STRLEN(text) >= STRLEN(prompt)) {
- text += STRLEN(prompt);
- }
- argv[0].v_type = VAR_STRING;
- argv[0].vval.v_string = vim_strsave(text);
- argv[1].v_type = VAR_UNKNOWN;
+ typval_T rettv;
+ typval_T argv[2];
+ char_u *text;
+ char_u *prompt;
+ linenr_T lnum = curbuf->b_ml.ml_line_count;
+
+ // Add a new line for the prompt before invoking the callback, so that
+ // text can always be inserted above the last line.
+ ml_append(lnum, (char_u *)"", 0, false);
+ curwin->w_cursor.lnum = lnum + 1;
+ curwin->w_cursor.col = 0;
+
+ if (curbuf->b_prompt_callback.type == kCallbackNone) {
+ return;
+ }
+ text = ml_get(lnum);
+ prompt = prompt_text();
+ if (STRLEN(text) >= STRLEN(prompt)) {
+ text += STRLEN(prompt);
+ }
+ argv[0].v_type = VAR_STRING;
+ argv[0].vval.v_string = vim_strsave(text);
+ argv[1].v_type = VAR_UNKNOWN;
- callback_call(&curbuf->b_prompt_callback, 1, argv, &rettv);
- tv_clear(&argv[0]);
- tv_clear(&rettv);
+ callback_call(&curbuf->b_prompt_callback, 1, argv, &rettv);
+ tv_clear(&argv[0]);
+ tv_clear(&rettv);
}
// Return true When the interrupt callback was invoked.
bool invoke_prompt_interrupt(void)
{
- typval_T rettv;
- typval_T argv[1];
+ typval_T rettv;
+ typval_T argv[1];
- if (curbuf->b_prompt_interrupt.type == kCallbackNone) {
- return false;
- }
- argv[0].v_type = VAR_UNKNOWN;
+ if (curbuf->b_prompt_interrupt.type == kCallbackNone) {
+ return false;
+ }
+ argv[0].v_type = VAR_UNKNOWN;
- got_int = false; // don't skip executing commands
- callback_call(&curbuf->b_prompt_interrupt, 0, argv, &rettv);
- tv_clear(&rettv);
- return true;
+ got_int = false; // don't skip executing commands
+ callback_call(&curbuf->b_prompt_interrupt, 0, argv, &rettv);
+ tv_clear(&rettv);
+ return true;
}
-// Compare "typ1" and "typ2". Put the result in "typ1".
-int typval_compare(
- typval_T *typ1, // first operand
- typval_T *typ2, // second operand
- exprtype_T type, // operator
- bool ic // ignore case
-)
+/// Compare "typ1" and "typ2". Put the result in "typ1".
+///
+/// @param typ1 first operand
+/// @param typ2 second operand
+/// @param type operator
+/// @param ic ignore case
+int typval_compare(typval_T *typ1, typval_T *typ2, exprtype_T type, bool ic)
FUNC_ATTR_NONNULL_ALL
{
varnumber_T n1, n2;
@@ -11140,7 +11141,7 @@ int typval_compare(
} else if (typ1->v_type == VAR_LIST || typ2->v_type == VAR_LIST) {
if (type_is) {
n1 = typ1->v_type == typ2->v_type
- && typ1->vval.v_list == typ2->vval.v_list;
+ && typ1->vval.v_list == typ2->vval.v_list;
if (type == EXPR_ISNOT) {
n1 = !n1;
}
@@ -11163,7 +11164,7 @@ int typval_compare(
} else if (typ1->v_type == VAR_DICT || typ2->v_type == VAR_DICT) {
if (type_is) {
n1 = typ1->v_type == typ2->v_type
- && typ1->vval.v_dict == typ2->vval.v_dict;
+ && typ1->vval.v_dict == typ2->vval.v_dict;
if (type == EXPR_ISNOT) {
n1 = !n1;
}
@@ -11218,17 +11219,24 @@ int typval_compare(
const float_T f2 = tv_get_float(typ2);
n1 = false;
switch (type) {
- case EXPR_IS:
- case EXPR_EQUAL: n1 = f1 == f2; break;
- case EXPR_ISNOT:
- case EXPR_NEQUAL: n1 = f1 != f2; break;
- case EXPR_GREATER: n1 = f1 > f2; break;
- case EXPR_GEQUAL: n1 = f1 >= f2; break;
- case EXPR_SMALLER: n1 = f1 < f2; break;
- case EXPR_SEQUAL: n1 = f1 <= f2; break;
- case EXPR_UNKNOWN:
- case EXPR_MATCH:
- case EXPR_NOMATCH: break; // avoid gcc warning
+ case EXPR_IS:
+ case EXPR_EQUAL:
+ n1 = f1 == f2; break;
+ case EXPR_ISNOT:
+ case EXPR_NEQUAL:
+ n1 = f1 != f2; break;
+ case EXPR_GREATER:
+ n1 = f1 > f2; break;
+ case EXPR_GEQUAL:
+ n1 = f1 >= f2; break;
+ case EXPR_SMALLER:
+ n1 = f1 < f2; break;
+ case EXPR_SEQUAL:
+ n1 = f1 <= f2; break;
+ case EXPR_UNKNOWN:
+ case EXPR_MATCH:
+ case EXPR_NOMATCH:
+ break; // avoid gcc warning
}
} else if ((typ1->v_type == VAR_NUMBER || typ2->v_type == VAR_NUMBER)
&& type != EXPR_MATCH && type != EXPR_NOMATCH) {
@@ -11237,17 +11245,24 @@ int typval_compare(
n1 = tv_get_number(typ1);
n2 = tv_get_number(typ2);
switch (type) {
- case EXPR_IS:
- case EXPR_EQUAL: n1 = n1 == n2; break;
- case EXPR_ISNOT:
- case EXPR_NEQUAL: n1 = n1 != n2; break;
- case EXPR_GREATER: n1 = n1 > n2; break;
- case EXPR_GEQUAL: n1 = n1 >= n2; break;
- case EXPR_SMALLER: n1 = n1 < n2; break;
- case EXPR_SEQUAL: n1 = n1 <= n2; break;
- case EXPR_UNKNOWN:
- case EXPR_MATCH:
- case EXPR_NOMATCH: break; // avoid gcc warning
+ case EXPR_IS:
+ case EXPR_EQUAL:
+ n1 = n1 == n2; break;
+ case EXPR_ISNOT:
+ case EXPR_NEQUAL:
+ n1 = n1 != n2; break;
+ case EXPR_GREATER:
+ n1 = n1 > n2; break;
+ case EXPR_GEQUAL:
+ n1 = n1 >= n2; break;
+ case EXPR_SMALLER:
+ n1 = n1 < n2; break;
+ case EXPR_SEQUAL:
+ n1 = n1 <= n2; break;
+ case EXPR_UNKNOWN:
+ case EXPR_MATCH:
+ case EXPR_NOMATCH:
+ break; // avoid gcc warning
}
} else {
char buf1[NUMBUFLEN];
@@ -11262,23 +11277,30 @@ int typval_compare(
}
n1 = false;
switch (type) {
- case EXPR_IS:
- case EXPR_EQUAL: n1 = i == 0; break;
- case EXPR_ISNOT:
- case EXPR_NEQUAL: n1 = i != 0; break;
- case EXPR_GREATER: n1 = i > 0; break;
- case EXPR_GEQUAL: n1 = i >= 0; break;
- case EXPR_SMALLER: n1 = i < 0; break;
- case EXPR_SEQUAL: n1 = i <= 0; break;
-
- case EXPR_MATCH:
- case EXPR_NOMATCH:
- n1 = pattern_match((char_u *)s2, (char_u *)s1, ic);
- if (type == EXPR_NOMATCH) {
- n1 = !n1;
- }
- break;
- case EXPR_UNKNOWN: break; // avoid gcc warning
+ case EXPR_IS:
+ case EXPR_EQUAL:
+ n1 = i == 0; break;
+ case EXPR_ISNOT:
+ case EXPR_NEQUAL:
+ n1 = i != 0; break;
+ case EXPR_GREATER:
+ n1 = i > 0; break;
+ case EXPR_GEQUAL:
+ n1 = i >= 0; break;
+ case EXPR_SMALLER:
+ n1 = i < 0; break;
+ case EXPR_SEQUAL:
+ n1 = i <= 0; break;
+
+ case EXPR_MATCH:
+ case EXPR_NOMATCH:
+ n1 = pattern_match((char_u *)s2, (char_u *)s1, ic);
+ if (type == EXPR_NOMATCH) {
+ n1 = !n1;
+ }
+ break;
+ case EXPR_UNKNOWN:
+ break; // avoid gcc warning
}
}
tv_clear(typ1);