aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordundargoc <gocdundar@gmail.com>2023-11-13 23:40:37 +0100
committerdundargoc <33953936+dundargoc@users.noreply.github.com>2023-11-19 15:08:35 +0100
commitac1113ded5f8f09dd99a9894d7a7e795626fb728 (patch)
tree9cf615d03efafe2c44e539cb45f1b3df171b3e85
parent1798a4b5e9f0ae56cd800095f79423fea5cae8ca (diff)
downloadrneovim-ac1113ded5f8f09dd99a9894d7a7e795626fb728.tar.gz
rneovim-ac1113ded5f8f09dd99a9894d7a7e795626fb728.tar.bz2
rneovim-ac1113ded5f8f09dd99a9894d7a7e795626fb728.zip
refactor: follow style guide
- reduce variable scope - prefer initialization over declaration and assignment
-rw-r--r--src/nvim/cmdexpand.c7
-rw-r--r--src/nvim/cmdhist.c3
-rw-r--r--src/nvim/debugger.c5
-rw-r--r--src/nvim/drawline.c3
-rw-r--r--src/nvim/drawscreen.c9
-rw-r--r--src/nvim/edit.c10
-rw-r--r--src/nvim/eval/typval.c13
-rw-r--r--src/nvim/eval/userfunc.c107
-rw-r--r--src/nvim/ex_cmds.c25
-rw-r--r--src/nvim/ex_cmds2.c6
-rw-r--r--src/nvim/ex_docmd.c4
-rw-r--r--src/nvim/ex_getln.c4
-rw-r--r--src/nvim/ex_session.c3
-rw-r--r--src/nvim/getchar.c35
-rw-r--r--src/nvim/help.c11
-rw-r--r--src/nvim/indent.c8
-rw-r--r--src/nvim/insexpand.c75
-rw-r--r--src/nvim/keycodes.c40
-rw-r--r--src/nvim/mark.c30
-rw-r--r--src/nvim/marktree.c5
-rw-r--r--src/nvim/match.c34
-rw-r--r--src/nvim/math.c3
-rw-r--r--src/nvim/mbyte.c16
-rw-r--r--src/nvim/memfile.c6
-rw-r--r--src/nvim/memline.c57
-rw-r--r--src/nvim/menu.c72
-rw-r--r--src/nvim/message.c27
-rw-r--r--src/nvim/mouse.c18
-rw-r--r--src/nvim/move.c8
-rw-r--r--src/nvim/normal.c77
-rw-r--r--src/nvim/ops.c225
-rw-r--r--src/nvim/optionstr.c3
-rw-r--r--src/nvim/path.c18
-rw-r--r--src/nvim/plines.c7
-rw-r--r--src/nvim/popupmenu.c14
-rw-r--r--src/nvim/profile.c26
-rw-r--r--src/nvim/runtime.c13
-rw-r--r--src/nvim/search.c29
-rw-r--r--src/nvim/shada.c3
-rw-r--r--src/nvim/spell.c10
-rw-r--r--src/nvim/spellfile.c374
-rw-r--r--src/nvim/spellsuggest.c210
-rw-r--r--src/nvim/statusline.c16
-rw-r--r--src/nvim/strings.c5
-rw-r--r--src/nvim/syntax.c49
-rw-r--r--src/nvim/tag.c159
-rw-r--r--src/nvim/testing.c7
-rw-r--r--src/nvim/textformat.c12
-rw-r--r--src/nvim/textobject.c61
-rw-r--r--src/nvim/ui_compositor.c5
-rw-r--r--src/nvim/undo.c5
-rw-r--r--src/nvim/version.c10
52 files changed, 713 insertions, 1269 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c
index 487a3ec482..1f97214401 100644
--- a/src/nvim/cmdexpand.c
+++ b/src/nvim/cmdexpand.c
@@ -1198,7 +1198,6 @@ char *addstar(char *fname, size_t len, int context)
FUNC_ATTR_NONNULL_RET
{
char *retval;
- size_t i, j;
if (context != EXPAND_FILES
&& context != EXPAND_FILES_IN_PATH
@@ -1224,7 +1223,7 @@ char *addstar(char *fname, size_t len, int context)
retval = xstrnsave(fname, len);
} else {
size_t new_len = len + 2; // +2 for '^' at start, NUL at end
- for (i = 0; i < len; i++) {
+ for (size_t i = 0; i < len; i++) {
if (fname[i] == '*' || fname[i] == '~') {
new_len++; // '*' needs to be replaced by ".*"
// '~' needs to be replaced by "\~"
@@ -1243,8 +1242,8 @@ char *addstar(char *fname, size_t len, int context)
retval = xmalloc(new_len);
{
retval[0] = '^';
- j = 1;
- for (i = 0; i < len; i++, j++) {
+ size_t j = 1;
+ for (size_t i = 0; i < len; i++, j++) {
// Skip backslash. But why? At least keep it for custom
// expansion.
if (context != EXPAND_USER_DEFINED
diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c
index 1f1d7d2eab..8a68a05ae1 100644
--- a/src/nvim/cmdhist.c
+++ b/src/nvim/cmdhist.c
@@ -451,7 +451,8 @@ static int del_history_entry(int histype, char *str)
regmatch.rm_ic = false; // always match case
bool found = false;
- int i = idx, last = idx;
+ int i = idx;
+ int last = idx;
do {
histentry_T *hisptr = &history[histype][i];
if (hisptr->hisstr == NULL) {
diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c
index 9ab95eaec6..843f8399f0 100644
--- a/src/nvim/debugger.c
+++ b/src/nvim/debugger.c
@@ -650,7 +650,6 @@ static void update_has_expr_breakpoint(void)
/// ":breakdel" and ":profdel".
void ex_breakdel(exarg_T *eap)
{
- struct debuggy *bp, *bpi;
int todel = -1;
bool del_all = false;
linenr_T best_lnum = 0;
@@ -677,9 +676,9 @@ void ex_breakdel(exarg_T *eap)
if (dbg_parsearg(eap->arg, gap) == FAIL) {
return;
}
- bp = &DEBUGGY(gap, gap->ga_len);
+ struct debuggy *bp = &DEBUGGY(gap, gap->ga_len);
for (int i = 0; i < gap->ga_len; i++) {
- bpi = &DEBUGGY(gap, i);
+ struct debuggy *bpi = &DEBUGGY(gap, i);
if (bp->dbg_type == bpi->dbg_type
&& strcmp(bp->dbg_name, bpi->dbg_name) == 0
&& (bp->dbg_lnum == bpi->dbg_lnum
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index 172c72145b..893261079f 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -2961,7 +2961,8 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool number_onl
win_put_linebuf(wp, wlv.row, 0, draw_col, grid->cols, bg_attr, wrap);
if (wrap) {
ScreenGrid *current_grid = grid;
- int current_row = wlv.row, dummy_col = 0; // dummy_col unused
+ int current_row = wlv.row;
+ int dummy_col = 0; // unused
grid_adjust(&current_grid, &current_row, &dummy_col);
// Force a redraw of the first column of the next line.
diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c
index dbcb16cae3..462ce4d64f 100644
--- a/src/nvim/drawscreen.c
+++ b/src/nvim/drawscreen.c
@@ -756,7 +756,8 @@ static void win_redr_border(win_T *wp)
int *attrs = wp->w_float_config.border_attr;
int *adj = wp->w_border_adj;
- int irow = wp->w_height_inner + wp->w_winbar_height, icol = wp->w_width_inner;
+ int irow = wp->w_height_inner + wp->w_winbar_height;
+ int icol = wp->w_width_inner;
if (adj[0]) {
grid_line_start(grid, 0);
@@ -1575,8 +1576,6 @@ static void win_update(win_T *wp, DecorProviders *providers)
}
}
if (mod_top != 0 && hasAnyFolding(wp)) {
- linenr_T lnumt, lnumb;
-
// A change in a line can cause lines above it to become folded or
// unfolded. Find the top most buffer line that may be affected.
// If the line was previously folded and displayed, get the first
@@ -1587,8 +1586,8 @@ static void win_update(win_T *wp, DecorProviders *providers)
// the line below it. If there is no valid entry, use w_topline.
// Find the first valid w_lines[] entry below mod_bot. Set lnumb
// to this line. If there is no valid entry, use MAXLNUM.
- lnumt = wp->w_topline;
- lnumb = MAXLNUM;
+ linenr_T lnumt = wp->w_topline;
+ linenr_T lnumb = MAXLNUM;
for (int i = 0; i < wp->w_lines_valid; i++) {
if (wp->w_lines[i].wl_valid) {
if (wp->w_lines[i].wl_lastlnum < mod_top) {
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index eb5ea2c873..7ad278a7d3 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -1265,7 +1265,7 @@ bool edit(int cmdchar, bool startln, int count)
return false;
}
- InsertState state, *s = &state;
+ InsertState s[1];
memset(s, 0, sizeof(InsertState));
s->state.execute = insert_execute;
s->state.check = insert_check;
@@ -4296,11 +4296,9 @@ static bool ins_tab(void)
if (!curbuf->b_p_et && (tabstop_count(curbuf->b_p_vsts_array) > 0
|| get_sts_value() > 0
|| (p_sta && ind))) {
- int i;
char *ptr;
char *saved_line = NULL; // init for GCC
pos_T pos;
- pos_T fpos;
pos_T *cursor;
colnr_T want_vcol, vcol;
int change_col = -1;
@@ -4324,7 +4322,7 @@ static bool ins_tab(void)
}
// Find first white before the cursor
- fpos = curwin->w_cursor;
+ pos_T fpos = curwin->w_cursor;
while (fpos.col > 0 && ascii_iswhite(ptr[-1])) {
fpos.col--;
ptr--;
@@ -4349,7 +4347,7 @@ static bool ins_tab(void)
// Use as many TABs as possible. Beware of 'breakindent', 'showbreak'
// and 'linebreak' adding extra virtual columns.
while (ascii_iswhite(*ptr)) {
- i = lbr_chartabsize(&cts);
+ int i = lbr_chartabsize(&cts);
if (cts.cts_vcol + i > want_vcol) {
break;
}
@@ -4391,7 +4389,7 @@ static bool ins_tab(void)
fpos.col += repl_off;
// Delete following spaces.
- i = cursor->col - fpos.col;
+ int i = cursor->col - fpos.col;
if (i > 0) {
STRMOVE(ptr, ptr + i);
// correct replace stack.
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 8a38315706..74bde0147d 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -1155,9 +1155,8 @@ static int item_compare(const void *s1, const void *s2, bool keep_zero)
res = sortinfo->item_compare_ic ? STRICMP(p1, p2) : strcmp(p1, p2);
}
} else {
- double n1, n2;
- n1 = strtod(p1, &p1);
- n2 = strtod(p2, &p2);
+ double n1 = strtod(p1, &p1);
+ double n2 = strtod(p2, &p2);
res = n1 == n2 ? 0 : n1 > n2 ? 1 : -1;
}
@@ -1187,8 +1186,6 @@ static int item_compare_not_keeping_zero(const void *s1, const void *s2)
static int item_compare2(const void *s1, const void *s2, bool keep_zero)
{
- ListSortItem *si1, *si2;
- int res;
typval_T rettv;
typval_T argv[3];
const char *func_name;
@@ -1199,8 +1196,8 @@ static int item_compare2(const void *s1, const void *s2, bool keep_zero)
return 0;
}
- si1 = (ListSortItem *)s1;
- si2 = (ListSortItem *)s2;
+ ListSortItem *si1 = (ListSortItem *)s1;
+ ListSortItem *si2 = (ListSortItem *)s2;
if (partial == NULL) {
func_name = sortinfo->item_compare_func;
@@ -1218,7 +1215,7 @@ static int item_compare2(const void *s1, const void *s2, bool keep_zero)
funcexe.fe_evaluate = true;
funcexe.fe_partial = partial;
funcexe.fe_selfdict = sortinfo->item_compare_selfdict;
- res = call_func(func_name, -1, &rettv, 2, argv, &funcexe);
+ int res = call_func(func_name, -1, &rettv, 2, argv, &funcexe);
tv_clear(&argv[0]);
tv_clear(&argv[1]);
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index 959dabafb5..822ac4d16a 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -274,14 +274,13 @@ int get_lambda_tv(char **arg, typval_T *rettv, evalarg_T *evalarg)
ufunc_T *fp = NULL;
partial_T *pt = NULL;
int varargs;
- int ret;
bool *old_eval_lavars = eval_lavars_used;
bool eval_lavars = false;
char *tofree = NULL;
// First, check if this is a lambda expression. "->" must exists.
char *s = skipwhite(*arg + 1);
- ret = get_function_args(&s, '-', NULL, NULL, NULL, true);
+ int ret = get_function_args(&s, '-', NULL, NULL, NULL, true);
if (ret == FAIL || *s != '>') {
return NOTDONE;
}
@@ -794,8 +793,6 @@ static void cleanup_function_call(funccall_T *fc)
/// @param[in] force When true, we are exiting.
static void funccal_unref(funccall_T *fc, ufunc_T *fp, bool force)
{
- int i;
-
if (fc == NULL) {
return;
}
@@ -810,7 +807,7 @@ static void funccal_unref(funccall_T *fc, ufunc_T *fp, bool force)
}
}
}
- for (i = 0; i < fc->fc_ufuncs.ga_len; i++) {
+ for (int i = 0; i < fc->fc_ufuncs.ga_len; i++) {
if (((ufunc_T **)(fc->fc_ufuncs.ga_data))[i] == fp) {
((ufunc_T **)(fc->fc_ufuncs.ga_data))[i] = NULL;
}
@@ -1846,16 +1843,13 @@ char *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, part
FUNC_ATTR_NONNULL_ARG(1)
{
char *name = NULL;
- const char *start;
- const char *end;
- int lead;
int len;
lval_T lv;
if (fdp != NULL) {
CLEAR_POINTER(fdp);
}
- start = *pp;
+ const char *start = *pp;
// Check for hard coded <SNR>: already translated function ID (from a user
// command).
@@ -1867,14 +1861,14 @@ char *trans_function_name(char **pp, bool skip, int flags, funcdict_T *fdp, part
// A name starting with "<SID>" or "<SNR>" is local to a script. But
// don't skip over "s:", get_lval() needs it for "s:dict.func".
- lead = eval_fname_script(start);
+ int lead = eval_fname_script(start);
if (lead > 2) {
start += lead;
}
// Note that TFN_ flags use the same values as GLV_ flags.
- end = get_lval((char *)start, NULL, &lv, false, skip, flags | GLV_READ_ONLY,
- lead > 2 ? 0 : FNE_CHECK_START);
+ const char *end = get_lval((char *)start, NULL, &lv, false, skip, flags | GLV_READ_ONLY,
+ lead > 2 ? 0 : FNE_CHECK_START);
if (end == start) {
if (!skip) {
emsg(_("E129: Function name required"));
@@ -2134,10 +2128,7 @@ void ex_function(exarg_T *eap)
{
char *theline;
char *line_to_free = NULL;
- char c;
bool saved_wait_return = need_wait_return;
- char *name = NULL;
- char *p;
char *arg;
char *line_arg = NULL;
garray_T newargs;
@@ -2147,16 +2138,9 @@ void ex_function(exarg_T *eap)
int flags = 0;
ufunc_T *fp;
bool overwrite = false;
- int indent;
- int nesting;
- dictitem_T *v;
funcdict_T fudi;
static int func_nr = 0; // number for nameless function
- int paren;
hashtab_T *ht;
- hashitem_T *hi;
- linenr_T sourcing_lnum_off;
- linenr_T sourcing_lnum_top;
bool is_heredoc = false;
char *skip_until = NULL;
char *heredoc_trimmed = NULL;
@@ -2174,11 +2158,11 @@ void ex_function(exarg_T *eap)
// ":function /pat": list functions matching pattern.
if (*eap->arg == '/') {
- p = skip_regexp(eap->arg + 1, '/', true);
+ char *p = skip_regexp(eap->arg + 1, '/', true);
if (!eap->skip) {
regmatch_T regmatch;
- c = *p;
+ char c = *p;
*p = NUL;
regmatch.regprog = vim_regcomp(eap->arg + 1, RE_MAGIC);
*p = c;
@@ -2209,9 +2193,9 @@ void ex_function(exarg_T *eap)
// "fudi.fd_di" set, "fudi.fd_newkey" == NULL
// s:func script-local function name
// g:func global function name, same as "func"
- p = eap->arg;
- name = save_function_name(&p, eap->skip, TFN_NO_AUTOLOAD, &fudi);
- paren = (vim_strchr(p, '(') != NULL);
+ char *p = eap->arg;
+ char *name = save_function_name(&p, eap->skip, TFN_NO_AUTOLOAD, &fudi);
+ int paren = (vim_strchr(p, '(') != NULL);
if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip) {
// Return on an invalid expression in braces, unless the expression
// evaluation has been cancelled due to an aborting error, an
@@ -2395,10 +2379,10 @@ void ex_function(exarg_T *eap)
}
// Save the starting line number.
- sourcing_lnum_top = SOURCING_LNUM;
+ linenr_T sourcing_lnum_top = SOURCING_LNUM;
- indent = 2;
- nesting = 0;
+ int indent = 2;
+ int nesting = 0;
while (true) {
if (KeyTyped) {
msg_scroll = true;
@@ -2442,7 +2426,7 @@ void ex_function(exarg_T *eap)
}
// Detect line continuation: SOURCING_LNUM increased more than one.
- sourcing_lnum_off = get_sourced_lnum(eap->getline, eap->cookie);
+ linenr_T sourcing_lnum_off = get_sourced_lnum(eap->getline, eap->cookie);
if (SOURCING_LNUM < sourcing_lnum_off) {
sourcing_lnum_off -= SOURCING_LNUM;
} else {
@@ -2641,7 +2625,7 @@ void ex_function(exarg_T *eap)
// If there are no errors, add the function
if (fudi.fd_dict == NULL) {
- v = find_var(name, strlen(name), &ht, false);
+ dictitem_T *v = find_var(name, strlen(name), &ht, false);
if (v != NULL && v->di_tv.v_type == VAR_FUNC) {
emsg_funcname(N_("E707: Function name conflicts with variable: %s"), name);
goto erret;
@@ -2706,16 +2690,13 @@ void ex_function(exarg_T *eap)
if (fp == NULL) {
if (fudi.fd_dict == NULL && vim_strchr(name, AUTOLOAD_CHAR) != NULL) {
- int slen, plen;
- char *scriptname;
-
// Check that the autoload name matches the script name.
int j = FAIL;
if (SOURCING_NAME != NULL) {
- scriptname = autoload_name(name, strlen(name));
+ char *scriptname = autoload_name(name, strlen(name));
p = vim_strchr(scriptname, '/');
- plen = (int)strlen(p);
- slen = (int)strlen(SOURCING_NAME);
+ int plen = (int)strlen(p);
+ int slen = (int)strlen(SOURCING_NAME);
if (slen > plen && path_fnamecmp(p, SOURCING_NAME + slen - plen) == 0) {
j = OK;
}
@@ -2753,7 +2734,7 @@ void ex_function(exarg_T *eap)
// insert the new function in the function list
set_ufunc_name(fp, name);
if (overwrite) {
- hi = hash_find(&func_hashtab, name);
+ hashitem_T *hi = hash_find(&func_hashtab, name);
hi->hi_key = UF2HIKEY(fp);
} else if (hash_add(&func_hashtab, UF2HIKEY(fp)) == FAIL) {
xfree(fp);
@@ -2862,7 +2843,6 @@ char *get_user_func_name(expand_T *xp, int idx)
static size_t done;
static int changed;
static hashitem_T *hi;
- ufunc_T *fp;
if (idx == 0) {
done = 0;
@@ -2877,7 +2857,7 @@ char *get_user_func_name(expand_T *xp, int idx)
while (HASHITEM_EMPTY(hi)) {
hi++;
}
- fp = HI2UF(hi);
+ ufunc_T *fp = HI2UF(hi);
if ((fp->uf_flags & FC_DICT)
|| strncmp(fp->uf_name, "<lambda>", 8) == 0) {
@@ -2904,12 +2884,10 @@ char *get_user_func_name(expand_T *xp, int idx)
void ex_delfunction(exarg_T *eap)
{
ufunc_T *fp = NULL;
- char *p;
- char *name;
funcdict_T fudi;
- p = eap->arg;
- name = trans_function_name(&p, eap->skip, 0, &fudi, NULL);
+ char *p = eap->arg;
+ char *name = trans_function_name(&p, eap->skip, 0, &fudi, NULL);
xfree(fudi.fd_newkey);
if (name == NULL) {
if (fudi.fd_dict != NULL && !eap->skip) {
@@ -2986,13 +2964,11 @@ void ex_delfunction(exarg_T *eap)
/// becomes zero.
void func_unref(char *name)
{
- ufunc_T *fp = NULL;
-
if (name == NULL || !func_name_refcount(name)) {
return;
}
- fp = find_func(name);
+ ufunc_T *fp = find_func(name);
if (fp == NULL && isdigit((uint8_t)(*name))) {
#ifdef EXITFREE
if (!entered_free_all_mem) {
@@ -3028,12 +3004,10 @@ void func_ptr_unref(ufunc_T *fp)
/// Count a reference to a Function.
void func_ref(char *name)
{
- ufunc_T *fp;
-
if (name == NULL || !func_name_refcount(name)) {
return;
}
- fp = find_func(name);
+ ufunc_T *fp = find_func(name);
if (fp != NULL) {
(fp->uf_refcount)++;
} else if (isdigit((uint8_t)(*name))) {
@@ -3333,10 +3307,6 @@ void invoke_all_defer(void)
void ex_call(exarg_T *eap)
{
char *arg = eap->arg;
- char *startarg;
- char *name;
- char *tofree;
- int len;
bool failed = false;
funcdict_T fudi;
partial_T *partial = NULL;
@@ -3357,7 +3327,7 @@ void ex_call(exarg_T *eap)
return;
}
- tofree = trans_function_name(&arg, false, TFN_INT, &fudi, &partial);
+ char *tofree = trans_function_name(&arg, false, TFN_INT, &fudi, &partial);
if (fudi.fd_newkey != NULL) {
// Still need to give an error message for missing key.
semsg(_(e_dictkey), fudi.fd_newkey);
@@ -3376,13 +3346,13 @@ void ex_call(exarg_T *eap)
// If it is the name of a variable of type VAR_FUNC or VAR_PARTIAL use its
// contents. For VAR_PARTIAL get its partial, unless we already have one
// from trans_function_name().
- len = (int)strlen(tofree);
+ int len = (int)strlen(tofree);
bool found_var = false;
- name = deref_func_name(tofree, &len, partial != NULL ? NULL : &partial, false, &found_var);
+ char *name = deref_func_name(tofree, &len, partial != NULL ? NULL : &partial, false, &found_var);
// Skip white space to allow ":call func ()". Not good, but required for
// backward compatibility.
- startarg = skipwhite(arg);
+ char *startarg = skipwhite(arg);
if (*startarg != '(') {
semsg(_(e_missingparen), eap->arg);
@@ -3435,7 +3405,6 @@ end:
/// false when the return gets pending.
int do_return(exarg_T *eap, int reanimate, int is_cmd, void *rettv)
{
- int idx;
cstack_T *const cstack = eap->cstack;
if (reanimate) {
@@ -3447,7 +3416,7 @@ int do_return(exarg_T *eap, int reanimate, int is_cmd, void *rettv)
// not in its finally clause (which then is to be executed next) is found.
// In this case, make the ":return" pending for execution at the ":endtry".
// Otherwise, return normally.
- idx = cleanup_conditionals(eap->cstack, 0, true);
+ int idx = cleanup_conditionals(eap->cstack, 0, true);
if (idx >= 0) {
cstack->cs_pending[idx] = CSTP_RETURN;
@@ -3531,7 +3500,6 @@ char *get_func_line(int c, void *cookie, int indent, bool do_concat)
funccall_T *fcp = (funccall_T *)cookie;
ufunc_T *fp = fcp->fc_func;
char *retval;
- garray_T *gap; // growarray with function lines
// If breakpoints have been added/deleted need to check for it.
if (fcp->fc_dbg_tick != debug_tick) {
@@ -3542,7 +3510,7 @@ char *get_func_line(int c, void *cookie, int indent, bool do_concat)
func_line_end(cookie);
}
- gap = &fp->uf_lines;
+ garray_T *gap = &fp->uf_lines; // growarray with function lines
if (((fp->uf_flags & FC_ABORT) && did_emsg && !aborted_in_try())
|| fcp->fc_returned) {
retval = NULL;
@@ -3904,15 +3872,11 @@ bool set_ref_in_call_stack(int copyID)
/// Set "copyID" in all functions available by name.
bool set_ref_in_functions(int copyID)
{
- int todo;
- hashitem_T *hi = NULL;
- ufunc_T *fp;
-
- todo = (int)func_hashtab.ht_used;
- for (hi = func_hashtab.ht_array; todo > 0 && !got_int; hi++) {
+ int todo = (int)func_hashtab.ht_used;
+ for (hashitem_T *hi = func_hashtab.ht_array; todo > 0 && !got_int; hi++) {
if (!HASHITEM_EMPTY(hi)) {
todo--;
- fp = HI2UF(hi);
+ ufunc_T *fp = HI2UF(hi);
if (!func_name_refcount(fp->uf_name)
&& set_ref_in_func(NULL, fp, copyID)) {
return true;
@@ -3942,7 +3906,6 @@ bool set_ref_in_func_args(int copyID)
bool set_ref_in_func(char *name, ufunc_T *fp_in, int copyID)
{
ufunc_T *fp = fp_in;
- funccall_T *fc;
int error = FCERR_NONE;
char fname_buf[FLEN_FIXED + 1];
char *tofree = NULL;
@@ -3956,7 +3919,7 @@ bool set_ref_in_func(char *name, ufunc_T *fp_in, int copyID)
fp = find_func(fname);
}
if (fp != NULL) {
- for (fc = fp->uf_scoped; fc != NULL; fc = fc->fc_func->uf_scoped) {
+ for (funccall_T *fc = fp->uf_scoped; fc != NULL; fc = fc->fc_func->uf_scoped) {
abort = abort || set_ref_in_funccal(fc, copyID);
}
}
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index d92be6404b..9a285bfe75 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -431,7 +431,6 @@ static int sort_compare(const void *s1, const void *s2)
void ex_sort(exarg_T *eap)
{
regmatch_T regmatch;
- linenr_T lnum;
int maxlen = 0;
size_t count = (size_t)(eap->line2 - eap->line1) + 1;
size_t i;
@@ -530,7 +529,7 @@ void ex_sort(exarg_T *eap)
// numbers sorting it's the number to sort on. This means the pattern
// matching and number conversion only has to be done once per line.
// Also get the longest line length for allocating "sortbuf".
- for (lnum = eap->line1; lnum <= eap->line2; lnum++) {
+ for (linenr_T lnum = eap->line1; lnum <= eap->line2; lnum++) {
char *s = ml_get(lnum);
int len = (int)strlen(s);
if (maxlen < len) {
@@ -622,7 +621,7 @@ void ex_sort(exarg_T *eap)
bcount_t old_count = 0, new_count = 0;
// Insert the lines in the sorted order below the last one.
- lnum = eap->line2;
+ linenr_T lnum = eap->line2;
for (i = 0; i < count; i++) {
const linenr_T get_lnum = nrs[eap->forceit ? count - i - 1 : i].lnum;
@@ -1610,7 +1609,6 @@ int do_write(exarg_T *eap)
int retval = FAIL;
char *free_fname = NULL;
buf_T *alt_buf = NULL;
- int name_was_missing;
if (not_writing()) { // check 'write' option
return FAIL;
@@ -1742,7 +1740,7 @@ int do_write(exarg_T *eap)
}
}
- name_was_missing = curbuf->b_ffname == NULL;
+ int name_was_missing = curbuf->b_ffname == NULL;
retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2,
eap, eap->append, eap->forceit, true, false);
@@ -2108,11 +2106,9 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum
bufref_T old_curbuf;
char *free_fname = NULL;
int retval = FAIL;
- pos_T orig_pos;
linenr_T topline = 0;
int newcol = -1;
int solcol = -1;
- pos_T *pos;
char *command = NULL;
bool did_get_winopts = false;
int readfile_flags = 0;
@@ -2288,7 +2284,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum
// May jump to last used line number for a loaded buffer or when asked
// for explicitly
if ((oldbuf && newlnum == ECMD_LASTL) || newlnum == ECMD_LAST) {
- pos = &buflist_findfmark(buf)->mark;
+ pos_T *pos = &buflist_findfmark(buf)->mark;
newlnum = pos->lnum;
solcol = pos->col;
}
@@ -2543,7 +2539,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum
// Careful: open_buffer() and apply_autocmds() may change the current
// buffer and window.
- orig_pos = curwin->w_cursor;
+ pos_T orig_pos = curwin->w_cursor;
topline = curwin->w_topline;
if (!oldbuf) { // need to read the file
swap_exists_action = SEA_DIALOG;
@@ -2892,7 +2888,7 @@ void ex_z(exarg_T *eap)
{
int64_t bigness;
int minus = 0;
- linenr_T start, end, curs, i;
+ linenr_T start, end, curs;
linenr_T lnum = eap->line2;
// Vi compatible: ":z!" uses display height, without a count uses
@@ -2993,7 +2989,7 @@ void ex_z(exarg_T *eap)
curs = 1;
}
- for (i = start; i <= end; i++) {
+ for (linenr_T i = start; i <= end; i++) {
if (minus && i == lnum) {
msg_putchar('\n');
@@ -4341,12 +4337,11 @@ void ex_global(exarg_T *eap)
{
linenr_T lnum; // line number according to old situation
int type; // first char of cmd: 'v' or 'g'
- char *cmd; // command argument
+ char *cmd; // command argument
char delim; // delimiter, normally '/'
char *pat;
regmmatch_T regmatch;
- int match;
// When nesting the command works on one line. This allows for
// ":g/found/v/notfound/command".
@@ -4405,7 +4400,7 @@ void ex_global(exarg_T *eap)
if (global_busy) {
lnum = curwin->w_cursor.lnum;
- match = vim_regexec_multi(&regmatch, curwin, curbuf, lnum, 0, NULL, NULL);
+ int match = vim_regexec_multi(&regmatch, curwin, curbuf, lnum, 0, NULL, NULL);
if ((type == 'g' && match) || (type == 'v' && !match)) {
global_exe_one(cmd, lnum);
}
@@ -4414,7 +4409,7 @@ void ex_global(exarg_T *eap)
// pass 1: set marks for each (not) matching line
for (lnum = eap->line1; lnum <= eap->line2 && !got_int; lnum++) {
// a match on this line?
- match = vim_regexec_multi(&regmatch, curwin, curbuf, lnum, 0, NULL, NULL);
+ int match = vim_regexec_multi(&regmatch, curwin, curbuf, lnum, 0, NULL, NULL);
if (regmatch.regprog == NULL) {
break; // re-compiling regprog failed
}
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index a99563bd9c..1353aa2412 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -439,8 +439,6 @@ int buf_write_all(buf_T *buf, int forceit)
/// ":argdo", ":windo", ":bufdo", ":tabdo", ":cdo", ":ldo", ":cfdo" and ":lfdo"
void ex_listdo(exarg_T *eap)
{
- win_T *wp;
- tabpage_T *tp;
char *save_ei = NULL;
// Temporarily override SHM_OVER and SHM_OVERALL to avoid that file
@@ -466,8 +464,8 @@ void ex_listdo(exarg_T *eap)
int next_fnum = 0;
int i = 0;
// start at the eap->line1 argument/window/buffer
- wp = firstwin;
- tp = first_tabpage;
+ win_T *wp = firstwin;
+ tabpage_T *tp = first_tabpage;
switch (eap->cmdidx) {
case CMD_windo:
for (; wp != NULL && i + 1 < eap->line1; wp = wp->w_next) {
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 0ca6e8bedb..7ae7561227 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -833,8 +833,8 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
// Cleanup if "cs_emsg_silent_list" remains.
if (cstack.cs_emsg_silent_list != NULL) {
- eslist_T *elem, *temp;
- for (elem = cstack.cs_emsg_silent_list; elem != NULL; elem = temp) {
+ eslist_T *temp;
+ for (eslist_T *elem = cstack.cs_emsg_silent_list; elem != NULL; elem = temp) {
temp = elem->next;
xfree(elem);
}
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index cae3a65825..005966fa75 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -1501,10 +1501,8 @@ static int command_line_erase_chars(CommandLineState *s)
}
if (ccline.cmdpos > 0) {
- char *p;
-
int j = ccline.cmdpos;
- p = mb_prevptr(ccline.cmdbuff, ccline.cmdbuff + j);
+ char *p = mb_prevptr(ccline.cmdbuff, ccline.cmdbuff + j);
if (s->c == Ctrl_W) {
while (p > ccline.cmdbuff && ascii_isspace(*p)) {
diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c
index aa85696b51..1a36014378 100644
--- a/src/nvim/ex_session.c
+++ b/src/nvim/ex_session.c
@@ -885,7 +885,6 @@ void ex_loadview(exarg_T *eap)
/// - SSOP_SLASH: filenames are written with "/" slash
void ex_mkrc(exarg_T *eap)
{
- FILE *fd;
int view_session = false; // :mkview, :mksession
int using_vdir = false; // using 'viewdir'?
char *viewFile = NULL;
@@ -925,7 +924,7 @@ void ex_mkrc(exarg_T *eap)
vim_mkdir_emsg(p_vdir, 0755);
}
- fd = open_exfile(fname, eap->forceit, WRITEBIN);
+ FILE *fd = open_exfile(fname, eap->forceit, WRITEBIN);
if (fd != NULL) {
int failed = false;
unsigned *flagp;
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index df94822936..8fc480009a 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -145,9 +145,9 @@ static const char e_cmd_mapping_must_end_with_cr_before_second_cmd[]
/// Free and clear a buffer.
static void free_buff(buffheader_T *buf)
{
- buffblock_T *p, *np;
+ buffblock_T *np;
- for (p = buf->bh_first.b_next; p != NULL; p = np) {
+ for (buffblock_T *p = buf->bh_first.b_next; p != NULL; p = np) {
np = p->b_next;
xfree(p);
}
@@ -877,8 +877,6 @@ bool noremap_keys(void)
/// @return FAIL for failure, OK otherwise
int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent)
{
- uint8_t *s1, *s2;
- int addlen;
int val;
int nrm;
@@ -888,7 +886,7 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent)
}
state_no_longer_safe("ins_typebuf()");
- addlen = (int)strlen(str);
+ int addlen = (int)strlen(str);
if (offset == 0 && addlen <= typebuf.tb_off) {
// Easy case: there is room in front of typebuf.tb_buf[typebuf.tb_off]
@@ -914,8 +912,8 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent)
return FAIL;
}
int newlen = typebuf.tb_len + extra;
- s1 = xmalloc((size_t)newlen);
- s2 = xmalloc((size_t)newlen);
+ uint8_t *s1 = xmalloc((size_t)newlen);
+ uint8_t *s2 = xmalloc((size_t)newlen);
typebuf.tb_buflen = newlen;
// copy the old chars, before the insertion point
@@ -2350,10 +2348,6 @@ static int vgetorpeek(bool advance)
// 'ttimeoutlen' for complete key code
int mapdepth = 0; // check for recursive mapping
bool mode_deleted = false; // set when mode has been deleted
- int new_wcol, new_wrow;
- int n;
- int old_wcol, old_wrow;
- int wait_tb_len;
// This function doesn't work very well when called recursively. This may
// happen though, because of:
@@ -2490,8 +2484,8 @@ static int vgetorpeek(bool advance)
// have to redisplay the mode. That the cursor is in the wrong
// place does not matter.
c = 0;
- new_wcol = curwin->w_wcol;
- new_wrow = curwin->w_wrow;
+ int new_wcol = curwin->w_wcol;
+ int new_wrow = curwin->w_wrow;
if (advance
&& typebuf.tb_len == 1
&& typebuf.tb_buf[typebuf.tb_off] == ESC
@@ -2506,8 +2500,8 @@ static int vgetorpeek(bool advance)
mode_deleted = true;
}
validate_cursor();
- old_wcol = curwin->w_wcol;
- old_wrow = curwin->w_wrow;
+ int old_wcol = curwin->w_wcol;
+ int old_wrow = curwin->w_wrow;
// move cursor left, if possible
if (curwin->w_cursor.col != 0) {
@@ -2570,7 +2564,7 @@ static int vgetorpeek(bool advance)
// Allow mapping for just typed characters. When we get here c
// is the number of extra bytes and typebuf.tb_len is 1.
- for (n = 1; n <= c; n++) {
+ for (int n = 1; n <= c; n++) {
typebuf.tb_noremap[typebuf.tb_off + n] = RM_YES;
}
typebuf.tb_len += c;
@@ -2650,8 +2644,8 @@ static int vgetorpeek(bool advance)
showing_partial = true;
}
// need to use the col and row from above here
- old_wcol = curwin->w_wcol;
- old_wrow = curwin->w_wrow;
+ int old_wcol = curwin->w_wcol;
+ int old_wrow = curwin->w_wrow;
curwin->w_wcol = new_wcol;
curwin->w_wrow = new_wrow;
push_showcmd();
@@ -2698,7 +2692,7 @@ static int vgetorpeek(bool advance)
}
}
- wait_tb_len = typebuf.tb_len;
+ int wait_tb_len = typebuf.tb_len;
c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len,
typebuf.tb_buflen - typebuf.tb_off - typebuf.tb_len - 1,
wait_time);
@@ -2924,7 +2918,8 @@ int fix_input_buffer(uint8_t *buf, int len)
char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat)
{
garray_T line_ga;
- int c1 = -1, c2;
+ int c1 = -1;
+ int c2;
int cmod = 0;
bool aborted = false;
diff --git a/src/nvim/help.c b/src/nvim/help.c
index 14dc7b6623..337c34f1de 100644
--- a/src/nvim/help.c
+++ b/src/nvim/help.c
@@ -865,7 +865,6 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool
garray_T ga;
int filecount;
char **files;
- char *p1, *p2;
char *s;
TriState utf8 = kNone;
bool mix = false; // detected mixed encodings
@@ -970,9 +969,9 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool
}
in_example = false;
}
- p1 = vim_strchr(IObuff, '*'); // find first '*'
+ char *p1 = vim_strchr(IObuff, '*'); // find first '*'
while (p1 != NULL) {
- p2 = strchr(p1 + 1, '*'); // Find second '*'.
+ char *p2 = strchr(p1 + 1, '*'); // Find second '*'.
if (p2 != NULL && p2 > p1 + 1) { // Skip "*" and "**".
for (s = p1 + 1; s < p2; s++) {
if (*s == ' ' || *s == '\t' || *s == '|') {
@@ -1019,8 +1018,8 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool
// Check for duplicates.
for (int i = 1; i < ga.ga_len; i++) {
- p1 = ((char **)ga.ga_data)[i - 1];
- p2 = ((char **)ga.ga_data)[i];
+ char *p1 = ((char **)ga.ga_data)[i - 1];
+ char *p2 = ((char **)ga.ga_data)[i];
while (*p1 == *p2) {
if (*p2 == '\t') {
*p2 = NUL;
@@ -1048,7 +1047,7 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool
fputs(s, fd_tags);
} else {
fprintf(fd_tags, "%s\t/" "*", s);
- for (p1 = s; *p1 != '\t'; p1++) {
+ for (char *p1 = s; *p1 != '\t'; p1++) {
// insert backslash before '\\' and '/'
if (*p1 == '\\' || *p1 == '/') {
putc('\\', fd_tags);
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index 89cf374152..6b08239f85 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -1183,15 +1183,15 @@ int get_expr_indent(void)
// I tried to fix the first two issues.
int get_lisp_indent(void)
{
- pos_T *pos, realpos, paren;
+ pos_T *pos;
+ pos_T paren;
int amount;
char *that;
- int vi_lisp;
// Set vi_lisp to use the vi-compatible method.
- vi_lisp = (vim_strchr(p_cpo, CPO_LISP) != NULL);
+ int vi_lisp = (vim_strchr(p_cpo, CPO_LISP) != NULL);
- realpos = curwin->w_cursor;
+ pos_T realpos = curwin->w_cursor;
curwin->w_cursor.col = 0;
if ((pos = findmatch(NULL, '(')) == NULL) {
diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c
index c2bec8b045..e41a2ce47c 100644
--- a/src/nvim/insexpand.c
+++ b/src/nvim/insexpand.c
@@ -908,7 +908,6 @@ static bool ins_compl_equal(compl_T *match, char *str, size_t len)
/// Reduce the longest common string for match "match".
static void ins_compl_longest_match(compl_T *match)
{
- char *p, *s;
int had_match;
if (compl_leader == NULL) {
@@ -931,8 +930,8 @@ static void ins_compl_longest_match(compl_T *match)
}
// Reduce the text if this match differs from compl_leader.
- p = compl_leader;
- s = match->cp_str;
+ char *p = compl_leader;
+ char *s = match->cp_str;
while (*p != NUL) {
int c1 = utf_ptr2char(p);
int c2 = utf_ptr2char(s);
@@ -1293,11 +1292,9 @@ static void ins_compl_dictionaries(char *dict_start, char *pat, int flags, int t
{
char *dict = dict_start;
char *ptr;
- char *buf;
regmatch_T regmatch;
char **files;
int count;
- int save_p_scs;
Direction dir = compl_direction;
if (*dict == NUL) {
@@ -1310,11 +1307,11 @@ static void ins_compl_dictionaries(char *dict_start, char *pat, int flags, int t
}
}
- buf = xmalloc(LSIZE);
+ char *buf = xmalloc(LSIZE);
regmatch.regprog = NULL; // so that we can goto theend
// If 'infercase' is set, don't use 'smartcase' here
- save_p_scs = p_scs;
+ int save_p_scs = p_scs;
if (curbuf->b_p_inf) {
p_scs = false;
}
@@ -1438,11 +1435,7 @@ static void ins_compl_files(int count, char **files, int thesaurus, int flags, r
char *buf, Direction *dir)
FUNC_ATTR_NONNULL_ARG(2, 7)
{
- char *ptr;
- int i;
- int add_r;
-
- for (i = 0; i < count && !got_int && !compl_interrupted; i++) {
+ for (int i = 0; i < count && !got_int && !compl_interrupted; i++) {
FILE *fp = os_fopen(files[i], "r"); // open dictionary file
if (flags != DICT_EXACT && !shortmess(SHM_COMPLETIONSCAN)) {
msg_hist_off = true; // reset in msg_trunc()
@@ -1458,7 +1451,7 @@ static void ins_compl_files(int count, char **files, int thesaurus, int flags, r
// Read dictionary file line by line.
// Check each line for a match.
while (!got_int && !compl_interrupted && !vim_fgets(buf, LSIZE, fp)) {
- ptr = buf;
+ char *ptr = buf;
while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf))) {
ptr = regmatch->startp[0];
if (ctrl_x_mode_line_or_eval()) {
@@ -1466,9 +1459,9 @@ static void ins_compl_files(int count, char **files, int thesaurus, int flags, r
} else {
ptr = find_word_end(ptr);
}
- add_r = ins_compl_add_infercase(regmatch->startp[0],
- (int)(ptr - regmatch->startp[0]),
- p_ic, files[i], *dir, false);
+ int add_r = ins_compl_add_infercase(regmatch->startp[0],
+ (int)(ptr - regmatch->startp[0]),
+ p_ic, files[i], *dir, false);
if (thesaurus) {
// For a thesaurus, add all the words in the line
ptr = buf;
@@ -1526,9 +1519,7 @@ char *find_word_end(char *ptr)
/// @return a pointer to just after the line.
static char *find_line_end(char *ptr)
{
- char *s;
-
- s = ptr + strlen(ptr);
+ char *s = ptr + strlen(ptr);
while (s > ptr && (s[-1] == CAR || s[-1] == NL)) {
s--;
}
@@ -1538,8 +1529,6 @@ static char *find_line_end(char *ptr)
/// Free the list of completions
static void ins_compl_free(void)
{
- compl_T *match;
-
XFREE_CLEAR(compl_pattern);
XFREE_CLEAR(compl_leader);
@@ -1552,7 +1541,7 @@ static void ins_compl_free(void)
compl_curr_match = compl_first_match;
do {
- match = compl_curr_match;
+ compl_T *match = compl_curr_match;
compl_curr_match = compl_curr_match->cp_next;
xfree(match->cp_str);
// several entries may use the same fname, free it just once.
@@ -1799,12 +1788,9 @@ static void ins_compl_set_original_text(char *str)
/// matches.
void ins_compl_addfrommatch(void)
{
- char *p;
int len = (int)curwin->w_cursor.col - (int)compl_col;
- int c;
- compl_T *cp;
assert(compl_shown_match != NULL);
- p = compl_shown_match->cp_str;
+ char *p = compl_shown_match->cp_str;
if ((int)strlen(p) <= len) { // the match is too short
// When still at the original match use the first entry that matches
// the leader.
@@ -1813,7 +1799,7 @@ void ins_compl_addfrommatch(void)
}
p = NULL;
- for (cp = compl_shown_match->cp_next; cp != NULL
+ for (compl_T *cp = compl_shown_match->cp_next; cp != NULL
&& !is_first_match(cp); cp = cp->cp_next) {
if (compl_leader == NULL
|| ins_compl_equal(cp, compl_leader, strlen(compl_leader))) {
@@ -1826,7 +1812,7 @@ void ins_compl_addfrommatch(void)
}
}
p += len;
- c = utf_ptr2char(p);
+ int c = utf_ptr2char(p);
ins_compl_addleader(c);
}
@@ -2356,13 +2342,11 @@ static void expand_by_function(int type, char *base)
{
list_T *matchlist = NULL;
dict_T *matchdict = NULL;
- char *funcname;
- pos_T pos;
typval_T rettv;
const int save_State = State;
assert(curbuf != NULL);
- funcname = get_complete_funcname(type);
+ char *funcname = get_complete_funcname(type);
if (*funcname == NUL) {
return;
}
@@ -2375,7 +2359,7 @@ static void expand_by_function(int type, char *base)
args[0].vval.v_number = 0;
args[1].vval.v_string = base != NULL ? base : "";
- pos = curwin->w_cursor;
+ pos_T pos = curwin->w_cursor;
// Lock the text to avoid weird things from happening. Also disallow
// switching to another window, it should not be needed and may end up in
// Insert mode in another buffer.
@@ -2502,12 +2486,9 @@ static void ins_compl_add_list(list_T *const list)
/// Add completions from a dict.
static void ins_compl_add_dict(dict_T *dict)
{
- dictitem_T *di_refresh;
- dictitem_T *di_words;
-
// Check for optional "refresh" item.
compl_opt_refresh_always = false;
- di_refresh = tv_dict_find(dict, S_LEN("refresh"));
+ dictitem_T *di_refresh = tv_dict_find(dict, S_LEN("refresh"));
if (di_refresh != NULL && di_refresh->di_tv.v_type == VAR_STRING) {
const char *v = di_refresh->di_tv.vval.v_string;
@@ -2517,7 +2498,7 @@ static void ins_compl_add_dict(dict_T *dict)
}
// Add completions from a "words" list.
- di_words = tv_dict_find(dict, S_LEN("words"));
+ dictitem_T *di_words = tv_dict_find(dict, S_LEN("words"));
if (di_words != NULL && di_words->di_tv.v_type == VAR_LIST) {
ins_compl_add_list(di_words->di_tv.vval.v_list);
}
@@ -3345,7 +3326,6 @@ static int ins_compl_get_exp(pos_T *ini)
{
static ins_compl_next_state_T st;
static bool st_cleared = false;
- int i;
int found_new_match;
int type = ctrl_x_mode;
@@ -3436,7 +3416,7 @@ static int ins_compl_get_exp(pos_T *ini)
found_new_match = FAIL;
}
- i = -1; // total of matches, unknown
+ int i = -1; // total of matches, unknown
if (found_new_match == FAIL
|| (ctrl_x_mode_not_default() && !ctrl_x_mode_line_or_eval())) {
i = ins_compl_make_cyclic();
@@ -3486,11 +3466,9 @@ static void ins_compl_update_shown_match(void)
/// Delete the old text being completed.
void ins_compl_delete(void)
{
- int col;
-
// In insert mode: Delete the typed part.
// In replace mode: Put the old characters back, if any.
- col = compl_col + (compl_status_adding() ? compl_length : 0);
+ int col = compl_col + (compl_status_adding() ? compl_length : 0);
if ((int)curwin->w_cursor.col > col) {
if (stop_arrow() == FAIL) {
return;
@@ -4384,13 +4362,8 @@ static void ins_compl_show_statusmsg(void)
/// Returns OK if completion was done, FAIL if something failed.
int ins_complete(int c, bool enable_pum)
{
- int n;
- int save_w_wrow;
- int save_w_leftcol;
- int insert_match;
-
compl_direction = ins_compl_key2dir(c);
- insert_match = ins_compl_use_match(c);
+ int insert_match = ins_compl_use_match(c);
if (!compl_started) {
if (ins_compl_start() == FAIL) {
@@ -4404,9 +4377,9 @@ int ins_complete(int c, bool enable_pum)
compl_shows_dir = compl_direction;
// Find next match (and following matches).
- save_w_wrow = curwin->w_wrow;
- save_w_leftcol = curwin->w_leftcol;
- n = ins_compl_next(true, ins_compl_key2count(c), insert_match, false);
+ int save_w_wrow = curwin->w_wrow;
+ int save_w_leftcol = curwin->w_leftcol;
+ int n = ins_compl_next(true, ins_compl_key2count(c), insert_match, false);
if (n > 1) { // all matches have been found
compl_matches = n;
diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c
index 66ee51f09f..e2fb1fa3ee 100644
--- a/src/nvim/keycodes.c
+++ b/src/nvim/keycodes.c
@@ -467,11 +467,8 @@ char *get_special_key_name(int c, int modifiers)
{
static char string[MAX_KEY_NAME_LEN + 1];
- int i, idx;
- int table_idx;
-
string[0] = '<';
- idx = 1;
+ int idx = 1;
// Key that stands for a normal character.
if (IS_SPECIAL(c) && KEY2TERMCAP0(c) == KS_KEY) {
@@ -481,7 +478,7 @@ char *get_special_key_name(int c, int modifiers)
// Translate shifted special keys into unshifted keys and set modifier.
// Same for CTRL and ALT modifiers.
if (IS_SPECIAL(c)) {
- for (i = 0; modifier_keys_table[i] != 0; i += MOD_KEYS_ENTRY_SIZE) {
+ for (int i = 0; modifier_keys_table[i] != 0; i += MOD_KEYS_ENTRY_SIZE) {
if (KEY2TERMCAP0(c) == (int)modifier_keys_table[i + 1]
&& (int)KEY2TERMCAP1(c) == (int)modifier_keys_table[i + 2]) {
modifiers |= modifier_keys_table[i];
@@ -493,7 +490,7 @@ char *get_special_key_name(int c, int modifiers)
}
// try to find the key in the special key table
- table_idx = find_special_key_in_table(c);
+ int table_idx = find_special_key_in_table(c);
// When not a known special key, and not a printable character, try to
// extract modifiers.
@@ -514,7 +511,7 @@ char *get_special_key_name(int c, int modifiers)
}
// translate the modifier into a string
- for (i = 0; mod_mask_table[i].name != 'A'; i++) {
+ for (int i = 0; mod_mask_table[i].name != 'A'; i++) {
if ((modifiers & mod_mask_table[i].mod_mask)
== mod_mask_table[i].mod_flag) {
string[idx++] = mod_mask_table[i].name;
@@ -623,13 +620,9 @@ int find_special_key(const char **const srcp, const size_t src_len, int *const m
const int flags, bool *const did_simplify)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1, 3)
{
- const char *last_dash;
- const char *end_of_name;
- const char *src;
const char *bp;
const char *const end = *srcp + src_len - 1;
const bool in_string = flags & FSK_IN_STRING;
- int modifiers;
uvarnumber_T n;
int l;
@@ -637,7 +630,7 @@ int find_special_key(const char **const srcp, const size_t src_len, int *const m
return 0;
}
- src = *srcp;
+ const char *src = *srcp;
if (src[0] != '<') {
return 0;
}
@@ -646,7 +639,7 @@ int find_special_key(const char **const srcp, const size_t src_len, int *const m
}
// Find end of modifier list
- last_dash = src;
+ const char *last_dash = src;
for (bp = src + 1; bp <= end && (*bp == '-' || ascii_isident(*bp)); bp++) {
if (*bp == '-') {
last_dash = bp;
@@ -678,10 +671,10 @@ int find_special_key(const char **const srcp, const size_t src_len, int *const m
if (bp <= end && *bp == '>') { // found matching '>'
int key;
- end_of_name = bp + 1;
+ const char *end_of_name = bp + 1;
// Which modifiers are given?
- modifiers = 0x0;
+ int modifiers = 0x0;
for (bp = src + 1; bp < last_dash; bp++) {
if (*bp != '-') {
int bit = name_to_mod_mask((uint8_t)(*bp));
@@ -842,9 +835,7 @@ int get_special_key_code(const char *name)
/// @return which button is down or was released.
int get_mouse_button(int code, bool *is_click, bool *is_drag)
{
- int i;
-
- for (i = 0; mouse_table[i].pseudo_code; i++) {
+ for (int i = 0; mouse_table[i].pseudo_code; i++) {
if (code == mouse_table[i].pseudo_code) {
*is_click = mouse_table[i].is_click;
*is_drag = mouse_table[i].is_drag;
@@ -884,13 +875,10 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co
const int cpo_flags)
FUNC_ATTR_NONNULL_ARG(1, 3)
{
- ssize_t i;
- size_t slen;
char key;
size_t dlen = 0;
const char *src;
const char *const end = from + from_len - 1;
- char *result; // buffer for resulting string
const bool do_backslash = !(cpo_flags & FLAG_CPO_BSLASH); // backslash is a special character
const bool do_special = !(flags & REPTERM_NO_SPECIAL);
@@ -900,7 +888,7 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co
// Allocate space for the translation. Worst case a single character is
// replaced by 6 bytes (shifted special key), plus a NUL at the end.
const size_t buf_len = allocated ? from_len * 6 + 1 : 128;
- result = allocated ? xmalloc(buf_len) : *bufp;
+ char *result = allocated ? xmalloc(buf_len) : *bufp; // buffer for resulting string
src = from;
@@ -931,9 +919,9 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co
}
}
- slen = trans_special(&src, (size_t)(end - src) + 1, result + dlen,
- FSK_KEYCODE | ((flags & REPTERM_NO_SIMPLIFY) ? 0 : FSK_SIMPLIFY),
- true, did_simplify);
+ size_t slen = trans_special(&src, (size_t)(end - src) + 1, result + dlen,
+ FSK_KEYCODE | ((flags & REPTERM_NO_SIMPLIFY) ? 0 : FSK_SIMPLIFY),
+ true, did_simplify);
if (slen) {
dlen += slen;
continue;
@@ -989,7 +977,7 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co
}
// skip multibyte char correctly
- for (i = utfc_ptr2len_len(src, (int)(end - src) + 1); i > 0; i--) {
+ for (ssize_t i = utfc_ptr2len_len(src, (int)(end - src) + 1); i > 0; i--) {
// If the character is K_SPECIAL, replace it with K_SPECIAL
// KS_SPECIAL KE_FILLER.
if (*src == (char)K_SPECIAL) {
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index 356a4326f6..37e7b830cb 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -791,18 +791,17 @@ char *fm_getname(fmark_T *fmark, int lead_len)
/// The returned string has been allocated.
static char *mark_line(pos_T *mp, int lead_len)
{
- char *s, *p;
- int len;
+ char *p;
if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count) {
return xstrdup("-invalid-");
}
assert(Columns >= 0);
// Allow for up to 5 bytes per character.
- s = xstrnsave(skipwhite(ml_get(mp->lnum)), (size_t)Columns * 5);
+ char *s = xstrnsave(skipwhite(ml_get(mp->lnum)), (size_t)Columns * 5);
// Truncate the line to fit it in the window
- len = 0;
+ int len = 0;
for (p = s; *p != NUL; MB_PTR_ADV(p)) {
len += ptr2cells(p);
if (len >= Columns - lead_len) {
@@ -818,7 +817,7 @@ void ex_marks(exarg_T *eap)
{
char *arg = eap->arg;
char *name;
- pos_T *posp, *startp, *endp;
+ pos_T *posp;
if (arg != NULL && *arg == NUL) {
arg = NULL;
@@ -850,8 +849,8 @@ void ex_marks(exarg_T *eap)
show_one_mark('.', arg, &curbuf->b_last_change.mark, NULL, true);
// Show the marks as where they will jump to.
- startp = &curbuf->b_visual.vi_start;
- endp = &curbuf->b_visual.vi_end;
+ pos_T *startp = &curbuf->b_visual.vi_start;
+ pos_T *endp = &curbuf->b_visual.vi_end;
if ((lt(*startp, *endp) || endp->lnum == 0) && startp->lnum != 0) {
posp = startp;
} else {
@@ -912,10 +911,7 @@ static void show_one_mark(int c, char *arg, pos_T *p, char *name_arg, int curren
// ":delmarks[!] [marks]"
void ex_delmarks(exarg_T *eap)
{
- char *p;
int from, to;
- int lower;
- int digit;
int n;
if (*eap->arg == NUL && eap->forceit) {
@@ -928,9 +924,9 @@ void ex_delmarks(exarg_T *eap)
} else {
// clear specified marks only
const Timestamp timestamp = os_time();
- for (p = eap->arg; *p != NUL; p++) {
- lower = ASCII_ISLOWER(*p);
- digit = ascii_isdigit(*p);
+ for (char *p = eap->arg; *p != NUL; p++) {
+ int lower = ASCII_ISLOWER(*p);
+ int digit = ascii_isdigit(*p);
if (lower || digit || ASCII_ISUPPER(*p)) {
if (p[1] == '-') {
// clear range of marks
@@ -998,14 +994,12 @@ void ex_delmarks(exarg_T *eap)
// print the jumplist
void ex_jumps(exarg_T *eap)
{
- char *name;
-
cleanup_jumplist(curwin, true);
// Highlight title
msg_puts_title(_("\n jump line col file/text"));
for (int i = 0; i < curwin->w_jumplistlen && !got_int; i++) {
if (curwin->w_jumplist[i].fmark.mark.lnum != 0) {
- name = fm_getname(&curwin->w_jumplist[i].fmark, 16);
+ char *name = fm_getname(&curwin->w_jumplist[i].fmark, 16);
// Make sure to output the current indicator, even when on an wiped
// out buffer. ":filter" may still skip it.
@@ -1049,8 +1043,6 @@ void ex_clearjumps(exarg_T *eap)
// print the changelist
void ex_changes(exarg_T *eap)
{
- char *name;
-
// Highlight title
msg_puts_title(_("\nchange line col text"));
@@ -1067,7 +1059,7 @@ void ex_changes(exarg_T *eap)
curbuf->b_changelist[i].mark.lnum,
curbuf->b_changelist[i].mark.col);
msg_outtrans(IObuff, 0);
- name = mark_line(&curbuf->b_changelist[i].mark, 17);
+ char *name = mark_line(&curbuf->b_changelist[i].mark, 17);
msg_outtrans(name, HL_ATTR(HLF_D));
xfree(name);
os_breakcheck();
diff --git a/src/nvim/marktree.c b/src/nvim/marktree.c
index 009c293d37..5cc3d3d3ee 100644
--- a/src/nvim/marktree.c
+++ b/src/nvim/marktree.c
@@ -430,11 +430,10 @@ void marktree_put_key(MarkTree *b, MTKey k)
if (!b->root) {
b->root = marktree_alloc_node(b, true);
}
- MTNode *r, *s;
b->n_keys++;
- r = b->root;
+ MTNode *r = b->root;
if (r->n == 2 * T - 1) {
- s = marktree_alloc_node(b, true);
+ MTNode *s = marktree_alloc_node(b, true);
b->root = s; s->level = r->level + 1; s->n = 0;
s->ptr[0] = r;
r->parent = s;
diff --git a/src/nvim/match.c b/src/nvim/match.c
index 0cd0426cff..743dfb9953 100644
--- a/src/nvim/match.c
+++ b/src/nvim/match.c
@@ -55,9 +55,6 @@ static int match_add(win_T *wp, const char *const grp, const char *const pat, in
list_T *pos_list, const char *const conceal_char)
FUNC_ATTR_NONNULL_ARG(1, 2)
{
- matchitem_T *cur;
- matchitem_T *prev;
- matchitem_T *m;
int hlg_id;
regprog_T *regprog = NULL;
int rtype = UPD_SOME_VALID;
@@ -76,7 +73,7 @@ static int match_add(win_T *wp, const char *const grp, const char *const pat, in
id = wp->w_next_match_id++;
} else {
// check the given ID is not already in use
- for (cur = wp->w_match_head; cur != NULL; cur = cur->mit_next) {
+ for (matchitem_T *cur = wp->w_match_head; cur != NULL; cur = cur->mit_next) {
if (cur->mit_id == id) {
semsg(_("E801: ID already taken: %" PRId64), (int64_t)id);
return -1;
@@ -100,7 +97,7 @@ static int match_add(win_T *wp, const char *const grp, const char *const pat, in
}
// Build new match.
- m = xcalloc(1, sizeof(matchitem_T));
+ matchitem_T *m = xcalloc(1, sizeof(matchitem_T));
if (pos_list != NULL) {
m->mit_pos_array = xcalloc((size_t)tv_list_len(pos_list), sizeof(llpos_T));
m->mit_pos_count = tv_list_len(pos_list);
@@ -211,8 +208,8 @@ static int match_add(win_T *wp, const char *const grp, const char *const pat, in
// Insert new match. The match list is in ascending order with regard to
// the match priorities.
- cur = wp->w_match_head;
- prev = cur;
+ matchitem_T *cur = wp->w_match_head;
+ matchitem_T *prev = cur;
while (cur != NULL && prio >= cur->mit_priority) {
prev = cur;
cur = cur->mit_next;
@@ -292,10 +289,8 @@ static int match_delete(win_T *wp, int id, bool perr)
/// Delete all matches in the match list of window 'wp'.
void clear_matches(win_T *wp)
{
- matchitem_T *m;
-
while (wp->w_match_head != NULL) {
- m = wp->w_match_head->mit_next;
+ matchitem_T *m = wp->w_match_head->mit_next;
vim_regfree(wp->w_match_head->mit_match.regprog);
xfree(wp->w_match_head->mit_pattern);
xfree(wp->w_match_head->mit_pos_array);
@@ -517,16 +512,13 @@ static void next_search_hl(win_T *win, match_T *search_hl, match_T *shl, linenr_
void prepare_search_hl(win_T *wp, match_T *search_hl, linenr_T lnum)
FUNC_ATTR_NONNULL_ALL
{
- matchitem_T *cur; // points to the match list
+ matchitem_T *cur = wp->w_match_head; // points to the match list
match_T *shl; // points to search_hl or a match
- bool shl_flag; // flag to indicate whether search_hl
- // has been processed or not
+ bool shl_flag = false; // flag to indicate whether search_hl has been processed or not
// When using a multi-line pattern, start searching at the top
// of the window or just after a closed fold.
// Do this both for search_hl and the match list.
- cur = wp->w_match_head;
- shl_flag = false;
while (cur != NULL || shl_flag == false) {
if (shl_flag == false) {
shl = search_hl;
@@ -806,7 +798,6 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char **line, match_T
bool get_prevcol_hl_flag(win_T *wp, match_T *search_hl, colnr_T curcol)
{
colnr_T prevcol = curcol;
- matchitem_T *cur; // points to the match list
// we're not really at that column when skipping some text
if ((wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) {
@@ -821,7 +812,7 @@ bool get_prevcol_hl_flag(win_T *wp, match_T *search_hl, colnr_T curcol)
&& search_hl->endcol == MAXCOL))) {
return true;
}
- cur = wp->w_match_head;
+ matchitem_T *cur = wp->w_match_head; // points to the match list
while (cur != NULL) {
if (!cur->mit_hl.is_addpos && (prevcol == cur->mit_hl.startcol
|| (prevcol > cur->mit_hl.startcol
@@ -900,7 +891,6 @@ void f_clearmatches(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
/// "getmatches()" function
void f_getmatches(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
- matchitem_T *cur;
win_T *win = get_optional_window(argvars, 0);
tv_list_alloc_ret(rettv, kListLenMayKnow);
@@ -908,7 +898,7 @@ void f_getmatches(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
return;
}
- cur = win->w_match_head;
+ matchitem_T *cur = win->w_match_head;
while (cur != NULL) {
dict_T *dict = tv_dict_alloc();
if (cur->mit_match.regprog == NULL) {
@@ -1185,10 +1175,8 @@ void f_matchdelete(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
/// skipping commands to find the next command.
void ex_match(exarg_T *eap)
{
- char *p;
char *g = NULL;
char *end;
- int c;
int id;
if (eap->line2 <= 3) {
@@ -1209,7 +1197,7 @@ void ex_match(exarg_T *eap)
&& (ascii_iswhite(eap->arg[4]) || ends_excmd(eap->arg[4])))) {
end = eap->arg + 4;
} else {
- p = skiptowhite(eap->arg);
+ char *p = skiptowhite(eap->arg);
if (!eap->skip) {
g = xmemdupz(eap->arg, (size_t)(p - eap->arg));
}
@@ -1233,7 +1221,7 @@ void ex_match(exarg_T *eap)
return;
}
- c = (uint8_t)(*end);
+ int c = (uint8_t)(*end);
*end = NUL;
match_add(curwin, g, p + 1, 10, id, NULL, NULL);
xfree(g);
diff --git a/src/nvim/math.c b/src/nvim/math.c
index d51a3947ae..96ff1bef10 100644
--- a/src/nvim/math.c
+++ b/src/nvim/math.c
@@ -13,10 +13,9 @@
int xfpclassify(double d)
{
uint64_t m;
- int e;
memcpy(&m, &d, sizeof(m));
- e = 0x7ff & (m >> 52);
+ int e = 0x7ff & (m >> 52);
m = 0xfffffffffffffULL & m;
switch (e) {
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 3a13aeddb8..92eddb3cf1 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -1248,7 +1248,7 @@ bool mb_isalpha(int a)
static int utf_strnicmp(const char *s1, const char *s2, size_t n1, size_t n2)
{
- int c1, c2, cdiff;
+ int c1, c2;
char buffer[6];
while (true) {
@@ -1263,7 +1263,7 @@ static int utf_strnicmp(const char *s1, const char *s2, size_t n1, size_t n2)
continue;
}
- cdiff = utf_fold(c1) - utf_fold(c2);
+ int cdiff = utf_fold(c1) - utf_fold(c2);
if (cdiff != 0) {
return cdiff;
}
@@ -1295,7 +1295,7 @@ static int utf_strnicmp(const char *s1, const char *s2, size_t n1, size_t n2)
}
while (n1 > 0 && n2 > 0 && *s1 != NUL && *s2 != NUL) {
- cdiff = (int)((uint8_t)(*s1)) - (int)((uint8_t)(*s2));
+ int cdiff = (int)((uint8_t)(*s1)) - (int)((uint8_t)(*s2));
if (cdiff != 0) {
return cdiff;
}
@@ -1444,11 +1444,11 @@ ssize_t mb_utf_index_to_bytes(const char *s, size_t len, size_t index, bool use_
FUNC_ATTR_NONNULL_ALL
{
size_t count = 0;
- size_t clen, i;
+ size_t clen;
if (index == 0) {
return 0;
}
- for (i = 0; i < len; i += clen) {
+ for (size_t i = 0; i < len; i += clen) {
clen = (size_t)utf_ptr2len_len(s + i, (int)(len - i));
// NB: gets the byte value of invalid sequence bytes.
// we only care whether the char fits in the BMP or not
@@ -1841,8 +1841,6 @@ int utf_cp_head_off(const char *base, const char *p)
void utf_find_illegal(void)
{
pos_T pos = curwin->w_cursor;
- char *p;
- int len;
vimconv_T vimconv;
char *tofree = NULL;
@@ -1856,7 +1854,7 @@ void utf_find_illegal(void)
curwin->w_cursor.coladd = 0;
while (true) {
- p = get_cursor_pos_ptr();
+ char *p = get_cursor_pos_ptr();
if (vimconv.vc_type != CONV_NONE) {
xfree(tofree);
tofree = string_convert(&vimconv, p, NULL);
@@ -1869,7 +1867,7 @@ void utf_find_illegal(void)
while (*p != NUL) {
// Illegal means that there are not enough trail bytes (checked by
// utf_ptr2len()) or too many of them (overlong sequence).
- len = utf_ptr2len(p);
+ int len = utf_ptr2len(p);
if ((uint8_t)(*p) >= 0x80 && (len == 1 || utf_char2len(utf_ptr2char(p)) != len)) {
if (vimconv.vc_type == CONV_NONE) {
curwin->w_cursor.col += (colnr_T)(p - get_cursor_pos_ptr());
diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c
index ae35427666..f30eb38e99 100644
--- a/src/nvim/memfile.c
+++ b/src/nvim/memfile.c
@@ -560,9 +560,7 @@ static int mf_read(memfile_T *mfp, bhdr_T *hp)
/// - Write error in swap file.
static int mf_write(memfile_T *mfp, bhdr_T *hp)
{
- off_T offset; // offset in the file
bhdr_T *hp2;
- unsigned page_size; // number of bytes in a page
unsigned page_count; // number of pages written
if (mfp->mf_fd < 0) { // there is no file, can't write
@@ -575,7 +573,7 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
}
}
- page_size = mfp->mf_page_size;
+ unsigned page_size = mfp->mf_page_size; // number of bytes in a page
/// We don't want gaps in the file. Write the blocks in front of *hp
/// to extend the file.
@@ -591,7 +589,7 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
}
// TODO(elmart): Check (page_size * nr) within off_T bounds.
- offset = (off_T)(page_size * nr);
+ off_T offset = (off_T)(page_size * nr); // offset in the file
if (vim_lseek(mfp->mf_fd, offset, SEEK_SET) != offset) {
PERROR(_("E296: Seek error in swap file write"));
return FAIL;
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index a77e6dc41d..df29d5697a 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -267,8 +267,6 @@ static const char e_warning_pointer_block_corrupted[]
/// @return FAIL for failure, OK otherwise.
int ml_open(buf_T *buf)
{
- bhdr_T *hp = NULL;
-
// init fields in memline struct
buf->b_ml.ml_stack_size = 0; // no stack yet
buf->b_ml.ml_stack = NULL; // no stack yet
@@ -301,7 +299,7 @@ int ml_open(buf_T *buf)
buf->b_ml.ml_line_count = 1;
// fill block0 struct and write page 0
- hp = mf_new(mfp, false, 1);
+ bhdr_T *hp = mf_new(mfp, false, 1);
if (hp->bh_bnum != 0) {
iemsg(_("E298: Didn't get block nr 0?"));
goto error;
@@ -748,14 +746,9 @@ void ml_recover(bool checkext)
memfile_T *mfp = NULL;
char *fname_used = NULL;
bhdr_T *hp = NULL;
- ZeroBlock *b0p;
- int b0_ff;
char *b0_fenc = NULL;
- PointerBlock *pp;
- DataBlock *dp;
infoptr_T *ip;
bool directly;
- char *p;
bool serious_error = true;
int orig_file_status = NOTDONE;
@@ -823,7 +816,7 @@ void ml_recover(bool checkext)
buf->b_ml.ml_flags = 0;
// open the memfile from the old swapfile
- p = xstrdup(fname_used); // save "fname_used" for the message:
+ char *p = xstrdup(fname_used); // save "fname_used" for the message:
// mf_open() will consume "fname_used"!
mfp = mf_open(fname_used, O_RDONLY);
fname_used = p;
@@ -849,7 +842,7 @@ void ml_recover(bool checkext)
msg_end();
goto theend;
}
- b0p = hp->bh_data;
+ ZeroBlock *b0p = hp->bh_data;
if (strncmp(b0p->b0_version, "VIM 3.0", 7) == 0) {
msg_start();
msg_outtrans(mfp->mf_fname, MSG_HIST);
@@ -941,7 +934,7 @@ void ml_recover(bool checkext)
ui_flush();
// Get the 'fileformat' and 'fileencoding' from block zero.
- b0_ff = (b0p->b0_flags & B0_FF_MASK);
+ int b0_ff = (b0p->b0_flags & B0_FF_MASK);
if (b0p->b0_flags & B0_HAS_FENC) {
int fnsize = B0_FNAME_SIZE_NOCRYPT;
@@ -1001,7 +994,7 @@ void ml_recover(bool checkext)
error++;
ml_append(lnum++, _("???MANY LINES MISSING"), 0, true);
} else { // there is a block
- pp = hp->bh_data;
+ PointerBlock *pp = hp->bh_data;
if (pp->pb_id == PTR_ID) { // it is a pointer block
bool ptr_block_error = false;
if (pp->pb_count_max != PB_COUNT_MAX(mfp)) {
@@ -1066,7 +1059,7 @@ void ml_recover(bool checkext)
continue;
}
} else { // not a pointer block
- dp = hp->bh_data;
+ DataBlock *dp = hp->bh_data;
if (dp->db_id != DATA_ID) { // block id wrong
if (bnum == 1) {
semsg(_("E310: Block 1 ID wrong (%s not a .swp file?)"),
@@ -1495,7 +1488,6 @@ void swapfile_dict(const char *fname, dict_T *d)
static time_t swapfile_info(char *fname)
{
assert(fname != NULL);
- int fd;
ZeroBlock b0;
time_t x = (time_t)0;
#ifdef UNIX
@@ -1523,7 +1515,7 @@ static time_t swapfile_info(char *fname)
}
// print the original file name
- fd = os_open(fname, O_RDONLY, 0);
+ int fd = os_open(fname, O_RDONLY, 0);
if (fd >= 0) {
if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0)) {
if (strncmp(b0.b0_version, "VIM 3.0", 7) == 0) {
@@ -2108,11 +2100,8 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char *line, colnr_T len, boo
int lines_moved;
int data_moved = 0; // init to shut up gcc
int total_moved = 0; // init to shut up gcc
- DataBlock *dp_right, *dp_left;
int stack_idx;
bool in_left;
- int lineadd;
- blocknr_T bnum_left, bnum_right;
linenr_T lnum_left, lnum_right;
PointerBlock *pp_new;
@@ -2158,10 +2147,10 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char *line, colnr_T len, boo
line_count_left = line_count;
line_count_right = 0;
}
- dp_right = hp_right->bh_data;
- dp_left = hp_left->bh_data;
- bnum_left = hp_left->bh_bnum;
- bnum_right = hp_right->bh_bnum;
+ DataBlock *dp_right = hp_right->bh_data;
+ DataBlock *dp_left = hp_left->bh_data;
+ blocknr_T bnum_left = hp_left->bh_bnum;
+ blocknr_T bnum_right = hp_right->bh_bnum;
page_count_left = (int)hp_left->bh_page_count;
page_count_right = (int)hp_right->bh_page_count;
@@ -2240,7 +2229,7 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char *line, colnr_T len, boo
// flush the old data block
// set ml_locked_lineadd to 0, because the updating of the
// pointer blocks is done below
- lineadd = buf->b_ml.ml_locked_lineadd;
+ int lineadd = buf->b_ml.ml_locked_lineadd;
buf->b_ml.ml_locked_lineadd = 0;
(void)ml_find_line(buf, 0, ML_FLUSH); // flush data block
@@ -2846,7 +2835,6 @@ static bhdr_T *ml_new_ptr(memfile_T *mfp)
/// @return NULL for failure, pointer to block header otherwise
static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action)
{
- PointerBlock *pp;
bhdr_T *hp;
int top;
@@ -2933,7 +2921,7 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action)
return hp;
}
- pp = (PointerBlock *)(dp); // must be pointer block
+ PointerBlock *pp = (PointerBlock *)(dp); // must be pointer block
if (pp->pb_id != PTR_ID) {
iemsg(_(e_pointer_block_id_wrong));
goto error_block;
@@ -3650,9 +3638,8 @@ static void long_to_char(long n, char *s_in)
static long char_to_long(const char *s_in)
{
const uint8_t *s = (uint8_t *)s_in;
- long retval;
- retval = s[3];
+ long retval = s[3];
retval <<= 8;
retval |= s[2];
retval <<= 8;
@@ -3669,14 +3656,12 @@ static long char_to_long(const char *s_in)
/// - 'fileencoding'
void ml_setflags(buf_T *buf)
{
- ZeroBlock *b0p;
-
if (!buf->b_ml.ml_mfp) {
return;
}
bhdr_T *hp = pmap_get(int64_t)(&buf->b_ml.ml_mfp->mf_hash, 0);
if (hp) {
- b0p = hp->bh_data;
+ ZeroBlock *b0p = hp->bh_data;
b0p->b0_dirty = buf->b_changed ? B0_DIRTY : 0;
b0p->b0_flags = (char)((b0p->b0_flags & ~B0_FF_MASK) | (uint8_t)(get_fileformat(buf) + 1));
add_b0_fenc(b0p, buf);
@@ -3706,7 +3691,6 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, int len, int updtype)
linenr_T curline = ml_upd_lastcurline;
int curix = ml_upd_lastcurix;
- chunksize_T *curchnk;
bhdr_T *hp;
if (buf->b_ml.ml_usedchunks == -1 || len == 0) {
@@ -3745,7 +3729,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, int len, int updtype)
curline += buf->b_ml.ml_chunksize[curix].mlcs_numlines;
curix++;
}
- curchnk = buf->b_ml.ml_chunksize + curix;
+ chunksize_T *curchnk = buf->b_ml.ml_chunksize + curix;
if (updtype == ML_CHNK_DELLINE) {
len = -len;
@@ -3886,9 +3870,6 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, int len, int updtype)
/// @return -1 if information is not available
int ml_find_line_or_offset(buf_T *buf, linenr_T lnum, int *offp, bool no_ff)
{
- linenr_T curline;
- int curix;
- int size;
bhdr_T *hp;
int text_end;
int offset;
@@ -3933,9 +3914,9 @@ int ml_find_line_or_offset(buf_T *buf, linenr_T lnum, int *offp, bool no_ff)
}
// Find the last chunk before the one containing our line. Last chunk is
// special because it will never qualify
- curline = 1;
- curix = 0;
- size = 0;
+ linenr_T curline = 1;
+ int curix = 0;
+ int size = 0;
while (curix < buf->b_ml.ml_usedchunks - 1
&& ((lnum != 0
&& lnum >= curline + buf->b_ml.ml_chunksize[curix].mlcs_numlines)
diff --git a/src/nvim/menu.c b/src/nvim/menu.c
index 9e3fd56c36..b5a92fbb22 100644
--- a/src/nvim/menu.c
+++ b/src/nvim/menu.c
@@ -65,14 +65,11 @@ static vimmenu_T **get_root_menu(const char *const name)
/// @param eap Ex command arguments
void ex_menu(exarg_T *eap)
{
- char *menu_path;
- int modes;
char *map_to; // command mapped to the menu entry
int noremap;
bool silent = false;
int unmenu;
char *map_buf;
- char *arg;
char *p;
int i;
int pri_tab[MENUDEPTH + 1];
@@ -80,8 +77,8 @@ void ex_menu(exarg_T *eap)
// kFalse for "menu disable
vimmenu_T menuarg;
- modes = get_menu_cmd_modes(eap->cmd, eap->forceit, &noremap, &unmenu);
- arg = eap->arg;
+ int modes = get_menu_cmd_modes(eap->cmd, eap->forceit, &noremap, &unmenu);
+ char *arg = eap->arg;
while (true) {
if (strncmp(arg, "<script>", 8) == 0) {
@@ -161,7 +158,7 @@ void ex_menu(exarg_T *eap)
return;
}
- menu_path = arg;
+ char *menu_path = arg;
if (*menu_path == '.') {
semsg(_(e_invarg2), menu_path);
goto theend;
@@ -265,34 +262,25 @@ theend:
static int add_menu_path(const char *const menu_path, vimmenu_T *menuarg, const int *const pri_tab,
const char *const call_data)
{
- char *path_name;
int modes = menuarg->modes;
vimmenu_T *menu = NULL;
- vimmenu_T *parent;
vimmenu_T **lower_pri;
- char *p;
- char *name;
char *dname;
- char *next_name;
- char c;
- char d;
int pri_idx = 0;
int old_modes = 0;
- int amenu;
char *en_name;
- char *map_to = NULL;
// Make a copy so we can stuff around with it, since it could be const
- path_name = xstrdup(menu_path);
+ char *path_name = xstrdup(menu_path);
vimmenu_T **root_menu_ptr = get_root_menu(menu_path);
vimmenu_T **menup = root_menu_ptr;
- parent = NULL;
- name = path_name;
+ vimmenu_T *parent = NULL;
+ char *name = path_name;
while (*name) {
// Get name of this element in the menu hierarchy, and the simplified
// name (without mnemonic and accelerator text).
- next_name = menu_name_skip(name);
- map_to = menutrans_lookup(name, (int)strlen(name));
+ char *next_name = menu_name_skip(name);
+ char *map_to = menutrans_lookup(name, (int)strlen(name));
if (map_to != NULL) {
en_name = name;
name = map_to;
@@ -395,14 +383,14 @@ static int add_menu_path(const char *const menu_path, vimmenu_T *menuarg, const
// Only add system menu items which have not been defined yet.
// First check if this was an ":amenu".
- amenu = ((modes & (MENU_NORMAL_MODE | MENU_INSERT_MODE)) ==
- (MENU_NORMAL_MODE | MENU_INSERT_MODE));
+ int amenu = ((modes & (MENU_NORMAL_MODE | MENU_INSERT_MODE)) ==
+ (MENU_NORMAL_MODE | MENU_INSERT_MODE));
if (sys_menu) {
modes &= ~old_modes;
}
if (menu != NULL && modes) {
- p = (call_data == NULL) ? NULL : xstrdup(call_data);
+ char *p = (call_data == NULL) ? NULL : xstrdup(call_data);
// loop over all modes, may add more than one
for (int i = 0; i < MENU_MODES; i++) {
@@ -412,8 +400,8 @@ static int add_menu_path(const char *const menu_path, vimmenu_T *menuarg, const
// For "amenu", may insert an extra character.
// Don't do this for "<Nop>".
- c = 0;
- d = 0;
+ char c = 0;
+ char d = 0;
if (amenu && call_data != NULL && *call_data != NUL) {
switch (1 << i) {
case MENU_VISUAL_MODE:
@@ -481,13 +469,11 @@ erret:
// Called recursively.
static int menu_enable_recurse(vimmenu_T *menu, char *name, int modes, int enable)
{
- char *p;
-
if (menu == NULL) {
return OK; // Got to bottom of hierarchy
}
// Get name of this element in the menu hierarchy
- p = menu_name_skip(name);
+ char *p = menu_name_skip(name);
// Find the menu
while (menu != NULL) {
@@ -530,14 +516,12 @@ static int menu_enable_recurse(vimmenu_T *menu, char *name, int modes, int enabl
static int remove_menu(vimmenu_T **menup, char *name, int modes, bool silent)
{
vimmenu_T *menu;
- vimmenu_T *child;
- char *p;
if (*menup == NULL) {
return OK; // Got to bottom of hierarchy
}
// Get name of this element in the menu hierarchy
- p = menu_name_skip(name);
+ char *p = menu_name_skip(name);
// Find the menu
while ((menu = *menup) != NULL) {
@@ -591,7 +575,7 @@ static int remove_menu(vimmenu_T **menup, char *name, int modes, bool silent)
// Recalculate modes for menu based on the new updated children
menu->modes &= ~modes;
- child = menu->children;
+ vimmenu_T *child = menu->children;
for (; child != NULL; child = child->next) {
menu->modes |= child->modes;
}
@@ -741,11 +725,9 @@ bool menu_get(char *const path_name, int modes, list_T *list)
/// @return menu if \p name is null, found menu or NULL
static vimmenu_T *find_menu(vimmenu_T *menu, char *name, int modes)
{
- char *p;
-
while (*name) {
// find the end of one dot-separated name and put a NUL at the dot
- p = menu_name_skip(name);
+ char *p = menu_name_skip(name);
while (menu != NULL) {
if (menu_name_equal(name, menu)) {
// Found menu
@@ -887,7 +869,6 @@ char *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char *arg, bool for
char *path_name = NULL;
int unmenu;
vimmenu_T *menu;
- int expand_menus;
xp->xp_context = EXPAND_UNSUCCESSFUL;
@@ -925,7 +906,7 @@ char *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char *arg, bool for
}
// ":popup" only uses menus, not entries
- expand_menus = !((*cmd == 't' && cmd[1] == 'e') || *cmd == 'p');
+ int expand_menus = !((*cmd == 't' && cmd[1] == 'e') || *cmd == 'p');
expand_emenu = (*cmd == 'e');
if (expand_menus && ascii_iswhite(*p)) {
return NULL; // TODO(vim): check for next command?
@@ -1298,11 +1279,10 @@ static char *menu_text(const char *str, int *mnemonic, char **actext)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT
FUNC_ATTR_NONNULL_ARG(1)
{
- char *p;
char *text;
// Locate accelerator text, after the first TAB
- p = vim_strchr(str, TAB);
+ char *p = vim_strchr(str, TAB);
if (p != NULL) {
if (actext != NULL) {
*actext = xstrdup(p + 1);
@@ -1706,7 +1686,6 @@ static garray_T menutrans_ga = GA_EMPTY_INIT_VALUE;
void ex_menutranslate(exarg_T *eap)
{
char *arg = eap->arg;
- char *from, *from_noamp, *to;
if (menutrans_ga.ga_itemsize == 0) {
ga_init(&menutrans_ga, (int)sizeof(menutrans_T), 5);
@@ -1720,16 +1699,16 @@ void ex_menutranslate(exarg_T *eap)
del_menutrans_vars();
} else {
// ":menutrans from to": add translation
- from = arg;
+ char *from = arg;
arg = menu_skip_part(arg);
- to = skipwhite(arg);
+ char *to = skipwhite(arg);
*arg = NUL;
arg = menu_skip_part(to);
if (arg == to) {
emsg(_(e_invarg));
} else {
from = xstrdup(from);
- from_noamp = menu_text(from, NULL, NULL);
+ char *from_noamp = menu_text(from, NULL, NULL);
assert(arg >= to);
to = xmemdupz(to, (size_t)(arg - to));
menu_translate_tab_and_shift(from);
@@ -1761,7 +1740,6 @@ static char *menu_skip_part(char *p)
static char *menutrans_lookup(char *name, int len)
{
menutrans_T *tp = (menutrans_T *)menutrans_ga.ga_data;
- char *dname;
for (int i = 0; i < menutrans_ga.ga_len; i++) {
if (STRNICMP(name, tp[i].from, len) == 0 && tp[i].from[len] == NUL) {
@@ -1772,7 +1750,7 @@ static char *menutrans_lookup(char *name, int len)
// Now try again while ignoring '&' characters.
char c = name[len];
name[len] = NUL;
- dname = menu_text(name, NULL, NULL);
+ char *dname = menu_text(name, NULL, NULL);
name[len] = c;
for (int i = 0; i < menutrans_ga.ga_len; i++) {
if (STRICMP(dname, tp[i].from_noamp) == 0) {
@@ -1788,9 +1766,7 @@ static char *menutrans_lookup(char *name, int len)
// Unescape the name in the translate dictionary table.
static void menu_unescape_name(char *name)
{
- char *p;
-
- for (p = name; *p && *p != '.'; MB_PTR_ADV(p)) {
+ for (char *p = name; *p && *p != '.'; MB_PTR_ADV(p)) {
if (*p == '\\') {
STRMOVE(p, p + 1);
}
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 9e9aa1fcd6..d9f9c26243 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -285,7 +285,6 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline)
FUNC_ATTR_NONNULL_ALL
{
static int entered = 0;
- int retval;
char *buf = NULL;
if (keep && multiline) {
@@ -339,7 +338,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline)
if (need_clear) {
msg_clr_eos();
}
- retval = msg_end();
+ int retval = msg_end();
if (keep && retval && vim_strsize(s) < (Rows - cmdline_row - 1) * Columns + sc_col) {
set_keep_msg(s, 0);
@@ -390,7 +389,6 @@ char *msg_strtrunc(const char *s, int force)
void trunc_string(const char *s, char *buf, int room_in, int buflen)
{
int room = room_in - 3; // "..." takes 3 chars
- int half;
int len = 0;
int e;
int i;
@@ -406,7 +404,7 @@ void trunc_string(const char *s, char *buf, int room_in, int buflen)
if (room_in < 3) {
room = 0;
}
- half = room / 2;
+ int half = room / 2;
// First part: Start of the string.
for (e = 0; len < half && e < buflen; e++) {
@@ -628,7 +626,6 @@ int emsg_not_now(void)
bool emsg_multiline(const char *s, bool multiline)
{
- int attr;
bool ignore = false;
// Skip this if not giving error messages at the moment.
@@ -725,7 +722,7 @@ bool emsg_multiline(const char *s, bool multiline)
}
emsg_on_display = true; // remember there is an error message
- attr = HL_ATTR(HLF_E); // set highlight mode for error messages
+ int attr = HL_ATTR(HLF_E); // set highlight mode for error messages
if (msg_scrolled != 0) {
need_wait_return = true; // needed in case emsg() is called after
} // wait_return() has reset need_wait_return
@@ -898,15 +895,13 @@ void msg_schedule_semsg_multiline(const char *const fmt, ...)
/// @return a pointer to the printed message, if wait_return() not called.
char *msg_trunc(char *s, bool force, int attr)
{
- int n;
-
// Add message to history before truncating.
add_msg_hist(s, -1, attr, false);
char *ts = msg_may_trunc(force, s);
msg_hist_off = true;
- n = msg(ts, attr);
+ int n = msg(ts, attr);
msg_hist_off = false;
if (n) {
@@ -1012,12 +1007,10 @@ static void add_msg_hist_multiattr(const char *s, int len, int attr, bool multil
/// @return FAIL if there are no messages.
int delete_first_msg(void)
{
- struct msg_hist *p;
-
if (msg_hist_len <= 0) {
return FAIL;
}
- p = first_msg_hist;
+ struct msg_hist *p = first_msg_hist;
first_msg_hist = p->next;
if (first_msg_hist == NULL) { // history is becoming empty
assert(msg_hist_len == 1);
@@ -1034,8 +1027,6 @@ int delete_first_msg(void)
void ex_messages(exarg_T *eap)
FUNC_ATTR_NONNULL_ALL
{
- struct msg_hist *p;
-
if (strcmp(eap->arg, "clear") == 0) {
int keep = eap->addr_count == 0 ? 0 : eap->line2;
@@ -1050,7 +1041,7 @@ void ex_messages(exarg_T *eap)
return;
}
- p = first_msg_hist;
+ struct msg_hist *p = first_msg_hist;
if (eap->addr_count != 0) {
int c = 0;
@@ -1132,8 +1123,6 @@ void msg_end_prompt(void)
void wait_return(int redraw)
{
int c;
- int oldState;
- int tmpState;
int had_got_int;
FILE *save_scriptout;
@@ -1167,7 +1156,7 @@ void wait_return(int redraw)
}
redir_off = true; // don't redirect this message
- oldState = State;
+ int oldState = State;
if (quit_more) {
c = CAR; // just pretend CR was hit
quit_more = false;
@@ -1282,7 +1271,7 @@ void wait_return(int redraw)
// If the screen size changed screen_resize() will redraw the screen.
// Otherwise the screen is only redrawn if 'redraw' is set and no ':'
// typed.
- tmpState = State;
+ int tmpState = State;
State = oldState; // restore State before screen_resize()
setmouse();
msg_check();
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c
index 141910f9df..8a48a8928e 100644
--- a/src/nvim/mouse.c
+++ b/src/nvim/mouse.c
@@ -100,15 +100,12 @@ static void find_start_of_word(pos_T *pos)
/// When 'selection' is "exclusive", the position is just after the word.
static void find_end_of_word(pos_T *pos)
{
- char *line;
- int cclass;
-
- line = ml_get(pos->lnum);
+ char *line = ml_get(pos->lnum);
if (*p_sel == 'e' && pos->col > 0) {
pos->col--;
pos->col -= utf_head_off(line, line + pos->col);
}
- cclass = get_mouse_class(line + pos->col);
+ int cclass = get_mouse_class(line + pos->col);
while (line[pos->col] != NUL) {
int col = pos->col + utfc_ptr2len(line + pos->col);
if (get_mouse_class(line + col) != cclass) {
@@ -964,11 +961,10 @@ popupexit:
void ins_mouse(int c)
{
- pos_T tpos;
win_T *old_curwin = curwin;
undisplay_dollar();
- tpos = curwin->w_cursor;
+ pos_T tpos = curwin->w_cursor;
if (do_mouse(NULL, c, BACKWARD, 1, 0)) {
win_T *new_curwin = curwin;
@@ -1183,8 +1179,6 @@ int jump_to_mouse(int flags, bool *inclusive, int which_button)
static int prev_col = -1;
static int did_drag = false; // drag was noticed
- win_T *wp, *old_curwin;
- pos_T old_cursor;
int count;
bool first;
int row = mouse_row;
@@ -1237,15 +1231,15 @@ retnomove:
if (flags & MOUSE_SETPOS) {
goto retnomove; // ugly goto...
}
- old_curwin = curwin;
- old_cursor = curwin->w_cursor;
+ win_T *old_curwin = curwin;
+ pos_T old_cursor = curwin->w_cursor;
if (row < 0 || col < 0) { // check if it makes sense
return IN_UNKNOWN;
}
// find the window where the row is in
- wp = mouse_find_win(&grid, &row, &col);
+ win_T *wp = mouse_find_win(&grid, &row, &col);
if (wp == NULL) {
return IN_UNKNOWN;
}
diff --git a/src/nvim/move.c b/src/nvim/move.c
index b10bdd8ffe..ee6c6101b2 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -1865,7 +1865,6 @@ void set_empty_rows(win_T *wp, int used)
/// This is messy stuff!!!
void scroll_cursor_bot(int min_scroll, int set_topbot)
{
- int used;
lineoff_T loff;
linenr_T old_topline = curwin->w_topline;
int old_skipcol = curwin->w_skipcol;
@@ -1879,7 +1878,7 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
if (set_topbot) {
bool set_skipcol = false;
- used = 0;
+ int used = 0;
curwin->w_botline = cln + 1;
loff.fill = 0;
for (curwin->w_topline = curwin->w_botline;
@@ -1927,7 +1926,7 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
}
// The lines of the cursor line itself are always used.
- used = plines_win_nofill(curwin, cln, true);
+ int used = plines_win_nofill(curwin, cln, true);
int scrolled = 0;
// If the cursor is on or below botline, we will at least scroll by the
@@ -2321,7 +2320,6 @@ void cursor_correct(void)
/// @return FAIL for failure, OK otherwise.
int onepage(Direction dir, int count)
{
- int n;
int retval = OK;
lineoff_T loff;
linenr_T old_topline = curwin->w_topline;
@@ -2420,7 +2418,7 @@ int onepage(Direction dir, int count)
// Find the line just above the new topline to get the right line
// at the bottom of the window.
- n = 0;
+ int n = 0;
while (n <= curwin->w_height_inner && loff.lnum >= 1) {
topline_back(curwin, &loff);
if (loff.height == MAXCOL) {
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 38fdff95d7..c4ced7670d 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -358,11 +358,9 @@ static int nv_max_linear;
/// through the index in nv_cmd_idx[].
static int nv_compare(const void *s1, const void *s2)
{
- int c1, c2;
-
// The commands are sorted on absolute value.
- c1 = nv_cmds[*(const int16_t *)s1].cmd_char;
- c2 = nv_cmds[*(const int16_t *)s2].cmd_char;
+ int c1 = nv_cmds[*(const int16_t *)s1].cmd_char;
+ int c2 = nv_cmds[*(const int16_t *)s2].cmd_char;
if (c1 < 0) {
c1 = -c1;
}
@@ -400,9 +398,6 @@ void init_normal_cmds(void)
/// @return -1 for invalid command.
static int find_command(int cmdchar)
{
- int idx;
- int top, bot;
-
// A multi-byte character is never a command.
if (cmdchar >= 0x100) {
return -1;
@@ -422,9 +417,9 @@ static int find_command(int cmdchar)
}
// Perform a binary search.
- bot = nv_max_linear + 1;
- top = NV_CMDS_SIZE - 1;
- idx = -1;
+ int bot = nv_max_linear + 1;
+ int top = NV_CMDS_SIZE - 1;
+ int idx = -1;
while (bot <= top) {
int i = (top + bot) / 2;
int c = nv_cmds[nv_cmd_idx[i]].cmd_char;
@@ -1994,13 +1989,11 @@ void add_to_showcmd_c(int c)
/// Delete 'len' characters from the end of the shown command.
static void del_from_showcmd(int len)
{
- int old_len;
-
if (!p_sc) {
return;
}
- old_len = (int)strlen(showcmd_buf);
+ int old_len = (int)strlen(showcmd_buf);
if (len > old_len) {
len = old_len;
}
@@ -2140,8 +2133,6 @@ void do_check_scrollbind(bool check)
/// (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>)
void check_scrollbind(linenr_T topline_diff, int leftcol_diff)
{
- bool want_ver;
- bool want_hor;
win_T *old_curwin = curwin;
buf_T *old_curbuf = curbuf;
int old_VIsual_select = VIsual_select;
@@ -2151,9 +2142,9 @@ void check_scrollbind(linenr_T topline_diff, int leftcol_diff)
linenr_T y;
// check 'scrollopt' string for vertical and horizontal scroll options
- want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0);
+ bool want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0);
want_ver |= old_curwin->w_p_diff;
- want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0));
+ bool want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0));
// loop through the scrollbound windows and scroll accordingly
VIsual_select = VIsual_active = 0;
@@ -2334,27 +2325,23 @@ static bool is_ident(const char *line, int offset)
/// @return fail when not found.
bool find_decl(char *ptr, size_t len, bool locally, bool thisblock, int flags_arg)
{
- char *pat;
- pos_T old_pos;
pos_T par_pos;
pos_T found_pos;
bool t;
- bool save_p_ws;
- bool save_p_scs;
bool retval = true;
bool incll;
int searchflags = flags_arg;
size_t patlen = len + 7;
- pat = xmalloc(patlen);
+ char *pat = xmalloc(patlen);
// Put "\V" before the pattern to avoid that the special meaning of "."
// and "~" causes trouble.
assert(patlen <= INT_MAX);
snprintf(pat, patlen, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", (int)len, ptr);
- old_pos = curwin->w_cursor;
- save_p_ws = p_ws;
- save_p_scs = p_scs;
+ pos_T old_pos = curwin->w_cursor;
+ bool save_p_ws = p_ws;
+ bool save_p_scs = p_scs;
p_ws = false; // don't wrap around end of file now
p_scs = false; // don't switch ignorecase off now
@@ -3902,14 +3889,13 @@ static void nv_down(cmdarg_T *cap)
/// Grab the file name under the cursor and edit it.
static void nv_gotofile(cmdarg_T *cap)
{
- char *ptr;
linenr_T lnum = -1;
if (check_text_or_curbuf_locked(cap->oap)) {
return;
}
- ptr = grab_file_name(cap->count1, &lnum);
+ char *ptr = grab_file_name(cap->count1, &lnum);
if (ptr != NULL) {
// do autowrite if necessary
@@ -4206,13 +4192,12 @@ static void nv_bracket_block(cmdarg_T *cap, const pos_T *old_pos)
/// cap->arg is BACKWARD for "[" and FORWARD for "]".
static void nv_brackets(cmdarg_T *cap)
{
- pos_T old_pos; // cursor position before command
int flag;
int n;
cap->oap->motion_type = kMTCharWise;
cap->oap->inclusive = false;
- old_pos = curwin->w_cursor;
+ pos_T old_pos = curwin->w_cursor; // cursor position before command
curwin->w_cursor.coladd = 0; // TODO(Unknown): don't do this for an error.
// "[f" or "]f" : Edit file under the cursor (same as "gf")
@@ -4478,7 +4463,6 @@ static void nv_kundo(cmdarg_T *cap)
/// Handle the "r" command.
static void nv_replace(cmdarg_T *cap)
{
- char *ptr;
int had_ctrl_v;
if (checkclearop(cap->oap)) {
@@ -4541,7 +4525,7 @@ static void nv_replace(cmdarg_T *cap)
}
// Abort if not enough characters to replace.
- ptr = get_cursor_pos_ptr();
+ char *ptr = get_cursor_pos_ptr();
if (strlen(ptr) < (unsigned)cap->count1
|| (mb_charlen(ptr) < cap->count1)) {
clearopbeep(cap->oap);
@@ -4633,11 +4617,10 @@ static void nv_replace(cmdarg_T *cap)
/// 'O': same, but in block mode exchange left and right corners.
static void v_swap_corners(int cmdchar)
{
- pos_T old_cursor;
colnr_T left, right;
if (cmdchar == 'O' && VIsual_mode == Ctrl_V) {
- old_cursor = curwin->w_cursor;
+ pos_T old_cursor = curwin->w_cursor;
getvcols(curwin, &old_cursor, &VIsual, &left, &right);
curwin->w_cursor.lnum = VIsual.lnum;
coladvance(left);
@@ -4667,7 +4650,7 @@ static void v_swap_corners(int cmdchar)
curwin->w_curswant = left;
}
} else {
- old_cursor = curwin->w_cursor;
+ pos_T old_cursor = curwin->w_cursor;
curwin->w_cursor = VIsual;
VIsual = old_cursor;
curwin->w_set_curswant = true;
@@ -4738,8 +4721,6 @@ static void nv_vreplace(cmdarg_T *cap)
/// Swap case for "~" command, when it does not work like an operator.
static void n_swapchar(cmdarg_T *cap)
{
- int n;
- pos_T startpos;
int did_change = 0;
if (checkclearopq(cap->oap)) {
@@ -4757,8 +4738,8 @@ static void n_swapchar(cmdarg_T *cap)
return;
}
- startpos = curwin->w_cursor;
- for (n = cap->count1; n > 0; n--) {
+ pos_T startpos = curwin->w_cursor;
+ for (int n = cap->count1; n > 0; n--) {
did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor);
inc_cursor();
if (gchar_cursor() == NUL) {
@@ -5759,10 +5740,9 @@ static void nv_dot(cmdarg_T *cap)
static void nv_redo_or_register(cmdarg_T *cap)
{
if (VIsual_select && VIsual_active) {
- int reg;
// Get register name
no_mapping++;
- reg = plain_vgetc();
+ int reg = plain_vgetc();
LANGMAP_ADJUST(reg, true);
no_mapping--;
@@ -5822,9 +5802,7 @@ static void nv_tilde(cmdarg_T *cap)
/// The actual work is done by do_pending_operator().
static void nv_operator(cmdarg_T *cap)
{
- int op_type;
-
- op_type = get_op_type(cap->cmdchar, cap->nchar);
+ int op_type = get_op_type(cap->cmdchar, cap->nchar);
if (bt_prompt(curbuf) && op_is_change(op_type)
&& !prompt_curpos_editable()) {
@@ -6130,12 +6108,10 @@ static void nv_normal(cmdarg_T *cap)
/// Don't even beep if we are canceling a command.
static void nv_esc(cmdarg_T *cap)
{
- int no_reason;
-
- no_reason = (cap->oap->op_type == OP_NOP
- && cap->opcount == 0
- && cap->count0 == 0
- && cap->oap->regname == 0);
+ int no_reason = (cap->oap->op_type == OP_NOP
+ && cap->opcount == 0
+ && cap->count0 == 0
+ && cap->oap->regname == 0);
if (cap->arg) { // true for CTRL-C
if (restart_edit == 0 && cmdwin_type == 0 && !VIsual_active && no_reason) {
@@ -6287,7 +6263,6 @@ static void nv_object(cmdarg_T *cap)
{
bool flag;
bool include;
- char *mps_save;
if (cap->cmdchar == 'i') {
include = false; // "ix" = inner object: exclude white space
@@ -6295,7 +6270,7 @@ static void nv_object(cmdarg_T *cap)
include = true; // "ax" = an object: include white space
}
// Make sure (), [], {} and <> are in 'matchpairs'
- mps_save = curbuf->b_p_mps;
+ char *mps_save = curbuf->b_p_mps;
curbuf->b_p_mps = "(:),{:},[:],<:>";
switch (cap->nchar) {
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 9c2b4e7b74..34aa2c80db 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -527,11 +527,10 @@ static void block_insert(oparg_T *oap, char *s, int b_insert, struct block_def *
colnr_T offset; // pointer along new line
size_t s_len = strlen(s);
char *newp, *oldp; // new, old lines
- linenr_T lnum; // loop var
int oldstate = State;
State = MODE_INSERT; // don't want MODE_REPLACE for State
- for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) {
+ for (linenr_T lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) {
block_prep(oap, bdp, lnum, true);
if (bdp->is_short && b_insert) {
continue; // OP_INSERT, line ends before block start
@@ -646,7 +645,6 @@ void op_reindent(oparg_T *oap, Indenter how)
// for each line separately, especially when undoing.
if (u_savecommon(curbuf, start_lnum - 1, start_lnum + oap->line_count,
start_lnum + oap->line_count, false) == OK) {
- char *l;
int amount;
for (i = oap->line_count - 1; i >= 0 && !got_int; i--) {
// it's a slow thing to do, so give feedback so there's no worry
@@ -662,7 +660,7 @@ void op_reindent(oparg_T *oap, Indenter how)
// indented, unless there is only one line.
if (i != oap->line_count - 1 || oap->line_count == 1
|| how != get_lisp_indent) {
- l = skipwhite(get_cursor_line_ptr());
+ char *l = skipwhite(get_cursor_line_ptr());
if (*l == NUL) { // empty or blank line
amount = 0;
} else {
@@ -715,9 +713,7 @@ static char *expr_line = NULL;
/// @return '=' when OK, NUL otherwise.
int get_expr_register(void)
{
- char *new_line;
-
- new_line = getcmdline('=', 0, 0, true);
+ char *new_line = getcmdline('=', 0, 0, true);
if (new_line == NULL) {
return NUL;
}
@@ -742,8 +738,6 @@ void set_expr_line(char *new_line)
/// @return a pointer to allocated memory, or NULL for failure.
char *get_expr_line(void)
{
- char *expr_copy;
- char *rv;
static int nested = 0;
if (expr_line == NULL) {
@@ -752,7 +746,7 @@ char *get_expr_line(void)
// Make a copy of the expression, because evaluating it may cause it to be
// changed.
- expr_copy = xstrdup(expr_line);
+ char *expr_copy = xstrdup(expr_line);
// When we are invoked recursively limit the evaluation to 10 levels.
// Then return the string as-is.
@@ -761,7 +755,7 @@ char *get_expr_line(void)
}
nested++;
- rv = eval_to_string(expr_copy, true);
+ char *rv = eval_to_string(expr_copy, true);
nested--;
xfree(expr_copy);
return rv;
@@ -888,7 +882,6 @@ bool yank_register_mline(int regname)
int do_record(int c)
{
static int regname;
- yankreg_T *old_y_previous;
int retval;
if (reg_recording == 0) {
@@ -942,7 +935,7 @@ int do_record(int c)
} else {
// We don't want to change the default register here, so save and
// restore the current register name.
- old_y_previous = y_previous;
+ yankreg_T *old_y_previous = y_previous;
retval = stuff_yank(regname, p);
@@ -1023,13 +1016,11 @@ static char *execreg_line_continuation(char **lines, size_t *idx)
garray_T ga;
ga_init(&ga, (int)sizeof(char), 400);
- char *p;
-
// search backwards to find the first line of this command.
// Any line not starting with \ or "\ is the start of the
// command.
while (--i > 0) {
- p = skipwhite(lines[i]);
+ char *p = skipwhite(lines[i]);
if (*p != '\\' && (p[0] != '"' || p[1] != '\\' || p[2] != ' ')) {
break;
}
@@ -1039,7 +1030,7 @@ static char *execreg_line_continuation(char **lines, size_t *idx)
// join all the lines
ga_concat(&ga, lines[cmd_start]);
for (size_t j = cmd_start + 1; j <= cmd_end; j++) {
- p = skipwhite(lines[j]);
+ char *p = skipwhite(lines[j]);
if (*p == '\\') {
// Adjust the growsize to the current length to
// speed up concatenating many lines.
@@ -1066,7 +1057,6 @@ static char *execreg_line_continuation(char **lines, size_t *idx)
/// @return FAIL for failure, OK otherwise
int do_execreg(int regname, int colon, int addcr, int silent)
{
- char *p;
int retval = OK;
if (regname == '@') { // repeat previous one
@@ -1095,12 +1085,12 @@ int do_execreg(int regname, int colon, int addcr, int silent)
// don't keep the cmdline containing @:
XFREE_CLEAR(new_last_cmdline);
// Escape all control characters with a CTRL-V
- p = vim_strsave_escaped_ext(last_cmdline,
- "\001\002\003\004\005\006\007"
- "\010\011\012\013\014\015\016\017"
- "\020\021\022\023\024\025\026\027"
- "\030\031\032\033\034\035\036\037",
- Ctrl_V, false);
+ char *p = vim_strsave_escaped_ext(last_cmdline,
+ "\001\002\003\004\005\006\007"
+ "\010\011\012\013\014\015\016\017"
+ "\020\021\022\023\024\025\026\027"
+ "\030\031\032\033\034\035\036\037",
+ Ctrl_V, false);
// When in Visual mode "'<,'>" will be prepended to the command.
// Remove it when it's already there.
if (VIsual_active && strncmp(p, "'<,'>", 5) == 0) {
@@ -1110,14 +1100,14 @@ int do_execreg(int regname, int colon, int addcr, int silent)
}
xfree(p);
} else if (regname == '=') {
- p = get_expr_line();
+ char *p = get_expr_line();
if (p == NULL) {
return FAIL;
}
retval = put_in_typebuf(p, true, colon, silent);
xfree(p);
} else if (regname == '.') { // use last inserted text
- p = get_last_insert_save();
+ char *p = get_last_insert_save();
if (p == NULL) {
emsg(_(e_noinstext));
return FAIL;
@@ -1147,7 +1137,7 @@ int do_execreg(int regname, int colon, int addcr, int silent)
char *str = reg->y_array[i];
bool free_str = false;
if (colon && i > 0) {
- p = skipwhite(str);
+ char *p = skipwhite(str);
if (*p == '\\' || (p[0] == '"' && p[1] == '\\' && p[2] == ' ')) {
str = execreg_line_continuation(reg->y_array, &i);
free_str = true;
@@ -1302,8 +1292,6 @@ int insert_reg(int regname, bool literally_arg)
/// @return true if "regname" is a special register,
bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg)
{
- size_t cnt;
-
*argp = NULL;
*allocated = false;
switch (regname) {
@@ -1360,9 +1348,9 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg)
if (!errmsg) {
return false;
}
- cnt = find_ident_under_cursor(argp, (regname == Ctrl_W
- ? (FIND_IDENT|FIND_STRING)
- : FIND_STRING));
+ size_t cnt = find_ident_under_cursor(argp, (regname == Ctrl_W
+ ? (FIND_IDENT|FIND_STRING)
+ : FIND_STRING));
*argp = cnt ? xmemdupz(*argp, cnt) : NULL;
*allocated = true;
return true;
@@ -1439,10 +1427,7 @@ static void shift_delete_registers(bool y_append)
/// @return FAIL if undo failed, OK otherwise.
int op_delete(oparg_T *oap)
{
- int n;
linenr_T lnum;
- char *ptr;
- char *newp, *oldp;
struct block_def bd = { 0 };
linenr_T old_lcount = curbuf->b_ml.ml_line_count;
@@ -1475,7 +1460,7 @@ int op_delete(oparg_T *oap)
&& oap->line_count > 1
&& oap->motion_force == NUL
&& oap->op_type == OP_DELETE) {
- ptr = ml_get(oap->end.lnum) + oap->end.col;
+ char *ptr = ml_get(oap->end.lnum) + oap->end.col;
if (*ptr != NUL) {
ptr += oap->inclusive;
}
@@ -1572,9 +1557,9 @@ int op_delete(oparg_T *oap)
// "n" == number of chars deleted
// If we delete a TAB, it may be replaced by several characters.
// Thus the number of characters may increase!
- n = bd.textlen - bd.startspaces - bd.endspaces;
- oldp = ml_get(lnum);
- newp = xmalloc(strlen(oldp) - (size_t)n + 1);
+ int n = bd.textlen - bd.startspaces - bd.endspaces;
+ char *oldp = ml_get(lnum);
+ char *newp = xmalloc(strlen(oldp) - (size_t)n + 1);
// copy up to deleted part
memmove(newp, oldp, (size_t)bd.textcol);
// insert spaces
@@ -1685,7 +1670,7 @@ int op_delete(oparg_T *oap)
display_dollar(oap->end.col - !oap->inclusive);
}
- n = oap->end.col - oap->start.col + 1 - !oap->inclusive;
+ int n = oap->end.col - oap->start.col + 1 - !oap->inclusive;
if (virtual_op) {
// fix up things for virtualedit-delete:
@@ -1734,7 +1719,7 @@ int op_delete(oparg_T *oap)
del_lines(oap->line_count - 2, false);
// delete from start of line until op_end
- n = (oap->end.col + 1 - !oap->inclusive);
+ int n = (oap->end.col + 1 - !oap->inclusive);
curwin->w_cursor.col = 0;
(void)del_bytes((colnr_T)n, !virtual_op,
oap->op_type == OP_DELETE && !oap->is_VIsual);
@@ -2043,7 +2028,6 @@ static int op_replace(oparg_T *oap, int c)
/// Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?".
void op_tilde(oparg_T *oap)
{
- pos_T pos;
struct block_def bd;
int did_change = false;
@@ -2052,7 +2036,7 @@ void op_tilde(oparg_T *oap)
return;
}
- pos = oap->start;
+ pos_T pos = oap->start;
if (oap->motion_type == kMTBlockWise) { // Visual block mode
for (; pos.lnum <= oap->end.lnum; pos.lnum++) {
int one_change;
@@ -2204,11 +2188,9 @@ bool swapchar(int op_type, pos_T *pos)
void op_insert(oparg_T *oap, int count1)
{
int pre_textlen = 0;
- char *firstline;
colnr_T ind_pre_col = 0;
int ind_pre_vcol = 0;
struct block_def bd;
- pos_T t1;
// edit() changes this - record it for OP_APPEND
bd.is_MAX = (curwin->w_curswant == MAXCOL);
@@ -2245,7 +2227,7 @@ void op_insert(oparg_T *oap, int count1)
// Get indent information
ind_pre_col = (colnr_T)getwhitecols_curline();
ind_pre_vcol = get_indent();
- firstline = ml_get(oap->start.lnum) + bd.textcol;
+ char *firstline = ml_get(oap->start.lnum) + bd.textcol;
if (oap->op_type == OP_APPEND) {
firstline += bd.textlen;
@@ -2285,7 +2267,7 @@ void op_insert(oparg_T *oap, int count1)
}
}
- t1 = oap->start;
+ pos_T t1 = oap->start;
const pos_T start_insert = curwin->w_cursor;
(void)edit(NUL, false, (linenr_T)count1);
@@ -2376,7 +2358,7 @@ void op_insert(oparg_T *oap, int count1)
// Subsequent calls to ml_get() flush the firstline data - take a
// copy of the required string.
- firstline = ml_get(oap->start.lnum);
+ char *firstline = ml_get(oap->start.lnum);
const size_t len = strlen(firstline);
colnr_T add = bd.textcol;
colnr_T offset = 0; // offset when cursor was moved in insert mode
@@ -2419,7 +2401,6 @@ void op_insert(oparg_T *oap, int count1)
/// @return true if edit() returns because of a CTRL-O command
int op_change(oparg_T *oap)
{
- int retval;
int pre_textlen = 0;
int pre_indent = 0;
char *firstline;
@@ -2468,7 +2449,7 @@ int op_change(oparg_T *oap)
const bool save_finish_op = finish_op;
finish_op = false;
- retval = edit(NUL, false, 1);
+ int retval = edit(NUL, false, 1);
finish_op = save_finish_op;
@@ -2597,13 +2578,9 @@ bool op_yank(oparg_T *oap, bool message)
static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
{
yankreg_T newreg; // new yank register when appending
- char **new_ptr;
- linenr_T lnum; // current line number
MotionType yank_type = oap->motion_type;
size_t yanklines = (size_t)oap->line_count;
linenr_T yankendlnum = oap->end.lnum;
- char *p;
- char *pnew;
struct block_def bd;
yankreg_T *curr = reg; // copy of current register
@@ -2635,7 +2612,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
reg->timestamp = os_time();
size_t y_idx = 0; // index in y_array[]
- lnum = oap->start.lnum;
+ linenr_T lnum = oap->start.lnum; // current line number
if (yank_type == kMTBlockWise) {
// Visual block mode
@@ -2661,7 +2638,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
colnr_T startcol = 0, endcol = MAXCOL;
int is_oneChar = false;
colnr_T cs, ce;
- p = ml_get(lnum);
+ char *p = ml_get(lnum);
bd.startspaces = 0;
bd.endspaces = 0;
@@ -2725,7 +2702,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
if (curr != reg) { // append the new block to the old block
size_t j;
- new_ptr = xmalloc(sizeof(char *) * (curr->y_size + reg->y_size));
+ char **new_ptr = xmalloc(sizeof(char *) * (curr->y_size + reg->y_size));
for (j = 0; j < curr->y_size; j++) {
new_ptr[j] = curr->y_array[j];
}
@@ -2741,8 +2718,8 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
// the new block, unless being Vi compatible.
if (curr->y_type == kMTCharWise
&& vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) {
- pnew = xmalloc(strlen(curr->y_array[curr->y_size - 1])
- + strlen(reg->y_array[0]) + 1);
+ char *pnew = xmalloc(strlen(curr->y_array[curr->y_size - 1])
+ + strlen(reg->y_array[0]) + 1);
STRCPY(pnew, curr->y_array[--j]);
STRCAT(pnew, reg->y_array[0]);
xfree(curr->y_array[j]);
@@ -2902,34 +2879,23 @@ static void do_autocmd_textyankpost(oparg_T *oap, yankreg_T *reg)
/// @param dir BACKWARD for 'P', FORWARD for 'p'
void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
{
- char *ptr;
- char *newp;
- char *oldp;
- int yanklen;
size_t totlen = 0; // init for gcc
linenr_T lnum = 0;
- colnr_T col = 0;
- size_t i; // index in y_array[]
MotionType y_type;
size_t y_size;
- size_t oldlen;
int y_width = 0;
colnr_T vcol = 0;
- int delcount;
int incr = 0;
struct block_def bd;
char **y_array = NULL;
linenr_T nr_lines = 0;
- pos_T new_cursor;
int indent;
int orig_indent = 0; // init for gcc
int indent_diff = 0; // init for gcc
bool first_indent = true;
int lendiff = 0;
- pos_T old_pos;
char *insert_string = NULL;
bool allocated = false;
- int cnt;
const pos_T orig_start = curbuf->b_op_start;
const pos_T orig_end = curbuf->b_op_end;
unsigned cur_ve_flags = get_ve_flags();
@@ -3046,7 +3012,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
// Loop twice: count the number of lines and save them.
while (true) {
y_size = 0;
- ptr = insert_string;
+ char *ptr = insert_string;
while (ptr != NULL) {
if (y_array != NULL) {
y_array[y_size] = ptr;
@@ -3104,11 +3070,11 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
if (dir == FORWARD && *p != NUL) {
MB_PTR_ADV(p);
}
- ptr = xstrdup(p);
+ char *ptr = xstrdup(p);
ml_append(curwin->w_cursor.lnum, ptr, 0, false);
xfree(ptr);
- oldp = get_cursor_line_ptr();
+ char *oldp = get_cursor_line_ptr();
p = oldp + curwin->w_cursor.col;
if (dir == FORWARD && *p != NUL) {
MB_PTR_ADV(p);
@@ -3173,7 +3139,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
goto end;
}
- yanklen = (int)strlen(y_array[0]);
+ int yanklen = (int)strlen(y_array[0]);
if (cur_ve_flags == VE_ALL && y_type == kMTCharWise) {
if (gchar_cursor() == TAB) {
@@ -3194,7 +3160,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
}
lnum = curwin->w_cursor.lnum;
- col = curwin->w_cursor.col;
+ colnr_T col = curwin->w_cursor.col;
// Block mode
if (y_type == kMTBlockWise) {
@@ -3235,7 +3201,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
}
curwin->w_cursor.coladd = 0;
bd.textcol = 0;
- for (i = 0; i < y_size; i++) {
+ for (size_t i = 0; i < y_size; i++) {
int spaces = 0;
char shortline;
// can just be 0 or 1, needed for blockwise paste beyond the current
@@ -3245,7 +3211,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
bd.startspaces = 0;
bd.endspaces = 0;
vcol = 0;
- delcount = 0;
+ int delcount = 0;
// add a new line
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
@@ -3256,8 +3222,8 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
lines_appended = 1;
}
// get the old line and advance to the position to insert at
- oldp = get_cursor_line_ptr();
- oldlen = strlen(oldp);
+ char *oldp = get_cursor_line_ptr();
+ size_t oldlen = strlen(oldp);
chartabsize_T cts;
init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, oldp, oldp);
@@ -3267,7 +3233,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
cts.cts_vcol += incr;
}
vcol = cts.cts_vcol;
- ptr = cts.cts_ptr;
+ char *ptr = cts.cts_ptr;
bd.textcol = (colnr_T)(ptr - oldp);
clear_chartabsize_arg(&cts);
@@ -3318,7 +3284,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
totlen = (size_t)count * (size_t)(yanklen + spaces) + (size_t)bd.startspaces +
(size_t)bd.endspaces;
- newp = xmalloc(totlen + oldlen + 1);
+ char *newp = xmalloc(totlen + oldlen + 1);
// copy part up to cursor to new line
ptr = newp;
@@ -3409,7 +3375,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
// Line mode: BACKWARD is the same as FORWARD on the previous line
lnum--;
}
- new_cursor = curwin->w_cursor;
+ pos_T new_cursor = curwin->w_cursor;
// simple case: insert into one line at a time
if (y_type == kMTCharWise && y_size == 1) {
@@ -3445,8 +3411,8 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
} else {
totlen = (size_t)count * (size_t)yanklen;
do {
- oldp = ml_get(lnum);
- oldlen = strlen(oldp);
+ char *oldp = ml_get(lnum);
+ size_t oldlen = strlen(oldp);
if (lnum > start_lnum) {
pos_T pos = {
.lnum = lnum,
@@ -3461,10 +3427,10 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
lnum++;
continue;
}
- newp = xmalloc(totlen + oldlen + 1);
+ char *newp = xmalloc(totlen + oldlen + 1);
memmove(newp, oldp, (size_t)col);
- ptr = newp + col;
- for (i = 0; i < (size_t)count; i++) {
+ char *ptr = newp + col;
+ for (size_t i = 0; i < (size_t)count; i++) {
memmove(ptr, y_array[0], (size_t)yanklen);
ptr += yanklen;
}
@@ -3506,20 +3472,19 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
}
} else {
linenr_T new_lnum = new_cursor.lnum;
- size_t len;
// Insert at least one line. When y_type is kMTCharWise, break the first
// line in two.
- for (cnt = 1; cnt <= count; cnt++) {
- i = 0;
+ for (int cnt = 1; cnt <= count; cnt++) {
+ size_t i = 0;
if (y_type == kMTCharWise) {
// Split the current line in two at the insert position.
// First insert y_array[size - 1] in front of second line.
// Then append y_array[0] to first line.
lnum = new_cursor.lnum;
- ptr = ml_get(lnum) + col;
+ char *ptr = ml_get(lnum) + col;
totlen = strlen(y_array[y_size - 1]);
- newp = xmalloc((size_t)(strlen(ptr) + totlen + 1));
+ char *newp = xmalloc((size_t)(strlen(ptr) + totlen + 1));
STRCPY(newp, y_array[y_size - 1]);
STRCAT(newp, ptr);
// insert second line
@@ -3527,7 +3492,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
new_lnum++;
xfree(newp);
- oldp = ml_get(lnum);
+ char *oldp = ml_get(lnum);
newp = xmalloc((size_t)col + (size_t)yanklen + 1);
// copy first part of line
memmove(newp, oldp, (size_t)col);
@@ -3549,9 +3514,9 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
lnum++;
nr_lines++;
if (flags & PUT_FIXINDENT) {
- old_pos = curwin->w_cursor;
+ pos_T old_pos = curwin->w_cursor;
curwin->w_cursor.lnum = lnum;
- ptr = ml_get(lnum);
+ char *ptr = ml_get(lnum);
if (cnt == count && i == y_size - 1) {
lendiff = (int)strlen(ptr);
}
@@ -3626,7 +3591,7 @@ error:
// Put the '] mark on the first byte of the last inserted character.
// Correct the length for change in indent.
curbuf->b_op_end.lnum = new_lnum;
- len = strlen(y_array[y_size - 1]);
+ size_t len = strlen(y_array[y_size - 1]);
col = (colnr_T)len - lendiff;
if (col > 1) {
curbuf->b_op_end.col = col - 1;
@@ -3766,7 +3731,6 @@ void ex_display(exarg_T *eap)
char *p;
yankreg_T *yb;
char *arg = eap->arg;
- int clen;
int type;
if (arg != NULL && *arg == NUL) {
@@ -3833,7 +3797,7 @@ void ex_display(exarg_T *eap)
}
for (p = yb->y_array[j];
*p != NUL && (n -= ptr2cells(p)) >= 0; p++) {
- clen = utfc_ptr2len(p);
+ int clen = utfc_ptr2len(p);
msg_outtrans_len(p, clen, 0);
p += clen - 1;
}
@@ -3932,7 +3896,6 @@ static void dis_msg(const char *p, bool skip_esc)
char *skip_comment(char *line, bool process, bool include_space, bool *is_comment)
{
char *comment_flags = NULL;
- int lead_len;
int leader_offset = get_last_leader_offset(line, &comment_flags);
*is_comment = false;
@@ -3955,7 +3918,7 @@ char *skip_comment(char *line, bool process, bool include_space, bool *is_commen
return line;
}
- lead_len = get_leader_len(line, &comment_flags, false, include_space);
+ int lead_len = get_leader_len(line, &comment_flags, false, include_space);
if (lead_len == 0) {
return line;
@@ -3996,14 +3959,10 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
char *curr = NULL;
char *curr_start = NULL;
char *cend;
- char *newp;
- char *spaces; // number of spaces inserted before a line
int endcurr1 = NUL;
int endcurr2 = NUL;
int currsize = 0; // size of the current line
int sumsize = 0; // size of the long new line
- linenr_T t;
- colnr_T col = 0;
int ret = OK;
int *comments = NULL;
int remove_comments = (use_formatoptions == true)
@@ -4018,7 +3977,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
// Allocate an array to store the number of spaces inserted before each
// line. We will use it to pre-compute the length of the new line and the
// proper placement of each original line in the new one.
- spaces = xcalloc(count, 1);
+ char *spaces = xcalloc(count, 1); // number of spaces inserted before a line
if (remove_comments) {
comments = xcalloc(count, sizeof(*comments));
}
@@ -4026,7 +3985,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
// Don't move anything yet, just compute the final line length
// and setup the array of space strings lengths
// This loops forward over joined lines.
- for (t = 0; t < (linenr_T)count; t++) {
+ for (linenr_T t = 0; t < (linenr_T)count; t++) {
curr_start = ml_get(curwin->w_cursor.lnum + t);
curr = curr_start;
if (t == 0 && setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) {
@@ -4098,10 +4057,10 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
}
// store the column position before last line
- col = sumsize - currsize - spaces[count - 1];
+ colnr_T col = sumsize - currsize - spaces[count - 1];
// allocate the space for the new line
- newp = xmalloc((size_t)sumsize + 1);
+ char *newp = xmalloc((size_t)sumsize + 1);
cend = newp + sumsize;
*cend = 0;
@@ -4114,7 +4073,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
curbuf_splice_pending++;
- for (t = (linenr_T)count - 1;; t--) {
+ for (linenr_T t = (linenr_T)count - 1;; t--) {
cend -= currsize;
memmove(cend, curr, (size_t)currsize);
if (spaces[t] > 0) {
@@ -4163,7 +4122,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
// Delete following lines. To do this we move the cursor there
// briefly, and then move it back. After del_lines() the cursor may
// have moved up (last line deleted), so the current lnum is kept in t.
- t = curwin->w_cursor.lnum;
+ linenr_T t = curwin->w_cursor.lnum;
curwin->w_cursor.lnum++;
del_lines((int)count - 1, false);
curwin->w_cursor.lnum = t;
@@ -4227,11 +4186,6 @@ static void restore_lbr(bool lbr_saved)
static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool is_del)
{
int incr = 0;
- char *pend;
- char *pstart;
- char *line;
- char *prev_pstart;
- char *prev_pend;
// Avoid a problem with unwanted linebreaks in block mode.
const bool lbr_saved = reset_lbr();
@@ -4247,8 +4201,8 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
bdp->end_char_vcols = 0;
bdp->start_char_vcols = 0;
- line = ml_get(lnum);
- prev_pstart = line;
+ char *line = ml_get(lnum);
+ char *prev_pstart = line;
chartabsize_T cts;
init_chartabsize_arg(&cts, curwin, lnum, bdp->start_vcol, line, line);
@@ -4267,7 +4221,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
MB_PTR_ADV(cts.cts_ptr);
}
bdp->start_vcol = cts.cts_vcol;
- pstart = cts.cts_ptr;
+ char *pstart = cts.cts_ptr;
clear_chartabsize_arg(&cts);
bdp->start_char_vcols = incr;
@@ -4284,7 +4238,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
if (is_del && bdp->startspaces) {
bdp->startspaces = bdp->start_char_vcols - bdp->startspaces;
}
- pend = pstart;
+ char *pend = pstart;
bdp->end_vcol = bdp->start_vcol;
if (bdp->end_vcol > oap->end_vcol) { // it's all in one character
bdp->is_oneChar = true;
@@ -4306,7 +4260,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
}
} else {
init_chartabsize_arg(&cts, curwin, lnum, bdp->end_vcol, line, pend);
- prev_pend = pend;
+ char *prev_pend = pend;
while (cts.cts_vcol <= oap->end_vcol && *cts.cts_ptr != NUL) {
// Count a tab for what it's worth (if list mode not on)
prev_pend = cts.cts_ptr;
@@ -4358,7 +4312,6 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
/// @param[in] g_cmd Prefixed with `g`.
void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd)
{
- pos_T pos;
struct block_def bd;
ssize_t change_cnt = 0;
linenr_T amount = Prenum1;
@@ -4369,7 +4322,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd)
disable_fold_update++;
if (!VIsual_active) {
- pos = curwin->w_cursor;
+ pos_T pos = curwin->w_cursor;
if (u_save_cursor() == FAIL) {
disable_fold_update--;
return;
@@ -4389,7 +4342,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd)
return;
}
- pos = oap->start;
+ pos_T pos = oap->start;
for (; pos.lnum <= oap->end.lnum; pos.lnum++) {
if (oap->motion_type == kMTBlockWise) {
// Visual block mode
@@ -4466,17 +4419,11 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd)
/// @return true if some character was changed.
int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
{
- int col;
char *buf1 = NULL;
char buf2[NUMBUFLEN];
int pre; // 'X' or 'x': hex; '0': octal; 'B' or 'b': bin
static bool hexupper = false; // 0xABC
uvarnumber_T n;
- uvarnumber_T oldn;
- char *ptr;
- int c;
- int todel;
- int firstdigit;
bool negative = false;
bool was_positive = true;
bool visual = VIsual_active;
@@ -4500,8 +4447,8 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
}
curwin->w_cursor = *pos;
- ptr = ml_get(pos->lnum);
- col = pos->col;
+ char *ptr = ml_get(pos->lnum);
+ int col = pos->col;
if (*ptr == NUL || col + !!save_coladd >= (int)strlen(ptr)) {
goto theend;
@@ -4594,7 +4541,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
}
// If a number was found, and saving for undo works, replace the number.
- firstdigit = (uint8_t)ptr[col];
+ int firstdigit = (uint8_t)ptr[col];
if (!ascii_isdigit(firstdigit) && !(do_alpha && ASCII_ISALPHA(firstdigit))) {
beep_flush();
goto theend;
@@ -4670,7 +4617,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
subtract ^= true;
}
- oldn = n;
+ uvarnumber_T oldn = n;
if (!overflow) { // if number is too big don't add/subtract
n = subtract ? n - (uvarnumber_T)Prenum1
@@ -4717,8 +4664,8 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
curwin->w_cursor.col = col;
startpos = curwin->w_cursor;
did_change = true;
- todel = length;
- c = gchar_cursor();
+ int todel = length;
+ int c = gchar_cursor();
// Don't include the '-' in the length, only the length of the part
// after it is kept the same.
@@ -5311,7 +5258,6 @@ static varnumber_T line_count_info(char *line, varnumber_T *wc, varnumber_T *cc,
/// @param dict when not NULL, store the info there instead of showing it.
void cursor_pos_info(dict_T *dict)
{
- char *p;
char buf1[50];
char buf2[40];
varnumber_T byte_count = 0;
@@ -5334,7 +5280,6 @@ void cursor_pos_info(dict_T *dict)
return;
}
} else {
- linenr_T lnum;
int eol_size;
varnumber_T last_check = 100000;
int line_count_selected = 0;
@@ -5382,7 +5327,7 @@ void cursor_pos_info(dict_T *dict)
line_count_selected = max_pos.lnum - min_pos.lnum + 1;
}
- for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) {
+ for (linenr_T lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) {
// Check for a CTRL-C every 100000 characters.
if (byte_count > last_check) {
os_breakcheck();
@@ -5488,7 +5433,7 @@ void cursor_pos_info(dict_T *dict)
(int64_t)byte_count_cursor, (int64_t)byte_count);
}
} else {
- p = get_cursor_line_ptr();
+ char *p = get_cursor_line_ptr();
validate_virtcol();
col_print(buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1,
(int)curwin->w_virtcol + 1);
@@ -5529,7 +5474,7 @@ void cursor_pos_info(dict_T *dict)
}
if (dict == NULL) {
// Don't shorten this message, the user asked for it.
- p = p_shm;
+ char *p = p_shm;
p_shm = "";
if (p_ch < 1) {
msg_start();
diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c
index bee08940b4..0d36634d9e 100644
--- a/src/nvim/optionstr.c
+++ b/src/nvim/optionstr.c
@@ -294,7 +294,6 @@ static void set_string_option_global(vimoption_T *opt, char **varp)
void set_string_option_direct(const char *name, int opt_idx, const char *val, int opt_flags,
int set_sid)
{
- char *s;
int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
int idx = opt_idx;
@@ -315,7 +314,7 @@ void set_string_option_direct(const char *name, int opt_idx, const char *val, in
assert(opt->var != &p_shada);
- s = xstrdup(val);
+ char *s = xstrdup(val);
{
char **varp = (char **)get_varp_scope(opt, both ? OPT_LOCAL : opt_flags);
if ((opt_flags & OPT_FREE) && (opt->flags & P_ALLOCED)) {
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 1cd663bde4..8ffa334370 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -1500,11 +1500,10 @@ void addfile(garray_T *gap, char *f, int flags)
void simplify_filename(char *filename)
{
int components = 0;
- char *p, *tail, *start;
bool stripping_disabled = false;
bool relative = true;
- p = filename;
+ char *p = filename;
#ifdef BACKSLASH_IN_FILENAME
if (p[0] != NUL && p[1] == ':') { // skip "x:"
p += 2;
@@ -1517,7 +1516,7 @@ void simplify_filename(char *filename)
p++;
} while (vim_ispathsep(*p));
}
- start = p; // remember start after "c:/" or "/" or "///"
+ char *start = p; // remember start after "c:/" or "/" or "///"
do {
// At this point "p" is pointing to the char following a single "/"
@@ -1533,7 +1532,7 @@ void simplify_filename(char *filename)
// and there is no trailing path separator, either strip "/." if
// we are after "start", or strip "." if we are at the beginning
// of an absolute path name.
- tail = p + 1;
+ char *tail = p + 1;
if (p[1] != NUL) {
while (vim_ispathsep(*tail)) {
MB_PTR_ADV(tail);
@@ -1546,7 +1545,7 @@ void simplify_filename(char *filename)
} else if (p[0] == '.' && p[1] == '.'
&& (vim_ispathsep(p[2]) || p[2] == NUL)) {
// Skip to after ".." or "../" or "..///".
- tail = p + 2;
+ char *tail = p + 2;
while (vim_ispathsep(*tail)) {
MB_PTR_ADV(tail);
}
@@ -1981,12 +1980,11 @@ bool same_directory(char *f1, char *f2)
int pathcmp(const char *p, const char *q, int maxlen)
{
int i, j;
- int c1, c2;
const char *s = NULL;
for (i = 0, j = 0; maxlen < 0 || (i < maxlen && j < maxlen);) {
- c1 = utf_ptr2char(p + i);
- c2 = utf_ptr2char(q + j);
+ int c1 = utf_ptr2char(p + i);
+ int c2 = utf_ptr2char(q + j);
// End of "p": check if "q" also ends or just has a slash.
if (c1 == NUL) {
@@ -2028,8 +2026,8 @@ int pathcmp(const char *p, const char *q, int maxlen)
return 0;
}
- c1 = utf_ptr2char(s + i);
- c2 = utf_ptr2char(s + i + utfc_ptr2len(s + i));
+ int c1 = utf_ptr2char(s + i);
+ int c2 = utf_ptr2char(s + i + utfc_ptr2len(s + i));
// ignore a trailing slash, but not "//" or ":/"
if (c2 == NUL
&& i > 0
diff --git a/src/nvim/plines.c b/src/nvim/plines.c
index 07c77a5d72..2e1b36c3dc 100644
--- a/src/nvim/plines.c
+++ b/src/nvim/plines.c
@@ -167,9 +167,7 @@ int lbr_chartabsize(chartabsize_T *cts)
/// @return The number of characters take up on the screen.
int lbr_chartabsize_adv(chartabsize_T *cts)
{
- int retval;
-
- retval = lbr_chartabsize(cts);
+ int retval = lbr_chartabsize(cts);
MB_PTR_ADV(cts->cts_ptr);
return retval;
}
@@ -399,14 +397,13 @@ static int win_nolbr_chartabsize(chartabsize_T *cts, int *headp)
win_T *wp = cts->cts_win;
char *s = cts->cts_ptr;
colnr_T col = cts->cts_vcol;
- int n;
if ((*s == TAB) && (!wp->w_p_list || wp->w_p_lcs_chars.tab1)) {
return tabstop_padding(col,
wp->w_buffer->b_p_ts,
wp->w_buffer->b_p_vts_array);
}
- n = ptr2cells(s);
+ int n = ptr2cells(s);
// Add one cell for a double-width character in the last column of the
// window, displayed with a ">".
diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c
index 4ed5d64c60..a6eb32ecb1 100644
--- a/src/nvim/popupmenu.c
+++ b/src/nvim/popupmenu.c
@@ -420,10 +420,7 @@ void pum_redraw(void)
int row = 0;
int attr_scroll = win_hl_attr(curwin, HLF_PSB);
int attr_thumb = win_hl_attr(curwin, HLF_PST);
- char *s;
char *p = NULL;
- int width;
- int w;
int thumb_pos = 0;
int thumb_height = 1;
int n;
@@ -524,8 +521,8 @@ void pum_redraw(void)
for (int round = 0; round < 3; round++) {
attr = attrs[round];
- width = 0;
- s = NULL;
+ int width = 0;
+ char *s = NULL;
switch (round) {
case 0:
@@ -541,7 +538,7 @@ void pum_redraw(void)
if (s == NULL) {
s = p;
}
- w = ptr2cells(p);
+ int w = ptr2cells(p);
if ((*p == NUL) || (*p == TAB) || (totwidth + w > pum_width)) {
// Display the text that fits or comes before a Tab.
@@ -778,11 +775,10 @@ static bool pum_set_selected(int n, int repeat)
}
if (res == OK) {
- char *p, *e;
linenr_T lnum = 0;
- for (p = pum_array[pum_selected].pum_info; *p != NUL;) {
- e = vim_strchr(p, '\n');
+ for (char *p = pum_array[pum_selected].pum_info; *p != NUL;) {
+ char *e = vim_strchr(p, '\n');
if (e == NULL) {
ml_append(lnum++, p, 0, false);
break;
diff --git a/src/nvim/profile.c b/src/nvim/profile.c
index 80f613c096..fd6c316e38 100644
--- a/src/nvim/profile.c
+++ b/src/nvim/profile.c
@@ -286,11 +286,8 @@ void ex_profile(exarg_T *eap)
{
static proftime_T pause_time;
- char *e;
- int len;
-
- e = skiptowhite(eap->arg);
- len = (int)(e - eap->arg);
+ char *e = skiptowhite(eap->arg);
+ int len = (int)(e - eap->arg);
e = skipwhite(e);
if (len == 5 && strncmp(eap->arg, "start", 5) == 0 && *e != NUL) {
@@ -434,12 +431,10 @@ static void prof_func_line(FILE *fd, int count, const proftime_T *total, const p
/// @param prefer_self when equal print only self time
static void prof_sort_list(FILE *fd, ufunc_T **sorttab, int st_len, char *title, bool prefer_self)
{
- ufunc_T *fp;
-
fprintf(fd, "FUNCTIONS SORTED ON %s TIME\n", title);
fprintf(fd, "count total (s) self (s) function\n");
for (int i = 0; i < 20 && i < st_len; i++) {
- fp = sorttab[i];
+ ufunc_T *fp = sorttab[i];
prof_func_line(fd, fp->uf_tm_count, &fp->uf_tm_total, &fp->uf_tm_self,
prefer_self);
if ((uint8_t)fp->uf_name[0] == K_SPECIAL) {
@@ -593,23 +588,19 @@ void func_line_end(void *cookie)
static void func_dump_profile(FILE *fd)
{
hashtab_T *const functbl = func_tbl_get();
- hashitem_T *hi;
- int todo;
- ufunc_T *fp;
- ufunc_T **sorttab;
int st_len = 0;
- todo = (int)functbl->ht_used;
+ int todo = (int)functbl->ht_used;
if (todo == 0) {
return; // nothing to dump
}
- sorttab = xmalloc(sizeof(ufunc_T *) * (size_t)todo);
+ ufunc_T **sorttab = xmalloc(sizeof(ufunc_T *) * (size_t)todo);
- for (hi = functbl->ht_array; todo > 0; hi++) {
+ for (hashitem_T *hi = functbl->ht_array; todo > 0; hi++) {
if (!HASHITEM_EMPTY(hi)) {
todo--;
- fp = HI2UF(hi);
+ ufunc_T *fp = HI2UF(hi);
if (fp->uf_prof_initialized) {
sorttab[st_len++] = fp;
@@ -713,7 +704,6 @@ void script_prof_restore(const proftime_T *tm)
/// Dump the profiling results for all scripts in file "fd".
static void script_dump_profile(FILE *fd)
{
- FILE *sfd;
sn_prl_T *pp;
for (int id = 1; id <= script_items.ga_len; id++) {
@@ -730,7 +720,7 @@ static void script_dump_profile(FILE *fd)
fprintf(fd, "\n");
fprintf(fd, "count total (s) self (s)\n");
- sfd = os_fopen(si->sn_name, "r");
+ FILE *sfd = os_fopen(si->sn_name, "r");
if (sfd == NULL) {
fprintf(fd, "Cannot open file!\n");
} else {
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index 83c4a68af2..9b8bd90745 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -911,7 +911,6 @@ static int gen_expand_wildcards_and_cb(int num_pat, char **pats, int flags, bool
static int add_pack_dir_to_rtp(char *fname, bool is_pack)
{
char *p;
- char *buf = NULL;
char *afterdir = NULL;
int retval = FAIL;
@@ -946,7 +945,7 @@ static int add_pack_dir_to_rtp(char *fname, bool is_pack)
// Find "ffname" in "p_rtp", ignoring '/' vs '\' differences
// Also stop at the first "after" directory
size_t fname_len = strlen(ffname);
- buf = try_malloc(MAXPATHL);
+ char *buf = try_malloc(MAXPATHL);
if (buf == NULL) {
goto theend;
}
@@ -2029,8 +2028,6 @@ int do_source_str(const char *cmd, const char *traceback_name)
int do_source(char *fname, int check_other, int is_vimrc, int *ret_sid)
{
struct source_cookie cookie;
- char *p;
- char *fname_exp;
uint8_t *firstline = NULL;
int retval = FAIL;
int save_debug_break_level = debug_break_level;
@@ -2038,11 +2035,11 @@ int do_source(char *fname, int check_other, int is_vimrc, int *ret_sid)
proftime_T wait_start;
bool trigger_source_post = false;
- p = expand_env_save(fname);
+ char *p = expand_env_save(fname);
if (p == NULL) {
return retval;
}
- fname_exp = fix_fname(p);
+ char *fname_exp = fix_fname(p);
xfree(p);
if (fname_exp == NULL) {
return retval;
@@ -2746,8 +2743,6 @@ void ex_finish(exarg_T *eap)
/// an extra do_cmdline(). "reanimate" is used in the latter case.
void do_finish(exarg_T *eap, int reanimate)
{
- int idx;
-
if (reanimate) {
((struct source_cookie *)getline_cookie(eap->getline,
eap->cookie))->finished = false;
@@ -2757,7 +2752,7 @@ void do_finish(exarg_T *eap, int reanimate)
// not in its finally clause (which then is to be executed next) is found.
// In this case, make the ":finish" pending for execution at the ":endtry".
// Otherwise, finish normally.
- idx = cleanup_conditionals(eap->cstack, 0, true);
+ int idx = cleanup_conditionals(eap->cstack, 0, true);
if (idx >= 0) {
eap->cstack->cs_pending[idx] = CSTP_FINISH;
report_make_pending(CSTP_FINISH, NULL);
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 6c0616ffb9..144151b714 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -1835,11 +1835,11 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
return NULL;
}
} else if (!cpo_bsl) {
- int col, bslcnt = 0;
+ int bslcnt = 0;
// Set "match_escaped" if there are an odd number of
// backslashes.
- for (col = pos.col; check_prevcol(linep, col, '\\', &col);) {
+ for (int col = pos.col; check_prevcol(linep, col, '\\', &col);) {
bslcnt++;
}
match_escaped = (bslcnt & 1);
@@ -2201,10 +2201,10 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
// quotes when the start is also inside of quotes.
if ((!inquote || start_in_quotes == kTrue)
&& (c == initc || c == findc)) {
- int col, bslcnt = 0;
+ int bslcnt = 0;
if (!cpo_bsl) {
- for (col = pos.col; check_prevcol(linep, col, '\\', &col);) {
+ for (int col = pos.col; check_prevcol(linep, col, '\\', &col);) {
bslcnt++;
}
}
@@ -3552,19 +3552,12 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool
int max_path_depth = 50;
int match_count = 1;
- char *pat;
char *new_fname;
char *curr_fname = curbuf->b_fname;
char *prev_fname = NULL;
- linenr_T lnum;
- int depth;
int depth_displayed; // For type==CHECK_PATH
- int old_files;
int already_searched;
- char *file_line;
- char *line;
char *p;
- char save_char;
bool define_matched;
regmatch_T regmatch;
regmatch_T incl_regmatch;
@@ -3582,14 +3575,14 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool
incl_regmatch.regprog = NULL;
def_regmatch.regprog = NULL;
- file_line = xmalloc(LSIZE);
+ char *file_line = xmalloc(LSIZE);
if (type != CHECK_PATH && type != FIND_DEFINE
// when CONT_SOL is set compare "ptr" with the beginning of the
// line is faster than quote_meta/regcomp/regexec "ptr" -- Acevedo
&& !compl_status_sol()) {
size_t patlen = len + 5;
- pat = xmalloc(patlen);
+ char *pat = xmalloc(patlen);
assert(len <= INT_MAX);
snprintf(pat, patlen, whole ? "\\<%.*s\\>" : "%.*s", (int)len, ptr);
// ignore case according to p_ic, p_scs and pat
@@ -3618,17 +3611,17 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool
def_regmatch.rm_ic = false; // don't ignore case in define pat.
}
files = xcalloc((size_t)max_path_depth, sizeof(SearchedFile));
- old_files = max_path_depth;
- depth = depth_displayed = -1;
+ int old_files = max_path_depth;
+ int depth = depth_displayed = -1;
- lnum = start_lnum;
+ linenr_T lnum = start_lnum;
if (end_lnum > curbuf->b_ml.ml_line_count) {
end_lnum = curbuf->b_ml.ml_line_count;
}
if (lnum > end_lnum) { // do at least one line
lnum = end_lnum;
}
- line = get_line_and_copy(lnum, file_line);
+ char *line = get_line_and_copy(lnum, file_line);
while (true) {
if (incl_regmatch.regprog != NULL
@@ -3739,7 +3732,7 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool
i++;
}
}
- save_char = p[i];
+ char save_char = p[i];
p[i] = NUL;
msg_outtrans(p, HL_ATTR(HLF_D));
p[i] = save_char;
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
index 97d9ae07a5..ae208ad30c 100644
--- a/src/nvim/shada.c
+++ b/src/nvim/shada.c
@@ -3977,12 +3977,11 @@ shada_read_next_item_error:
static bool shada_removable(const char *name)
FUNC_ATTR_WARN_UNUSED_RESULT
{
- char *p;
char part[MAXPATHL + 1];
bool retval = false;
char *new_name = home_replace_save(NULL, name);
- for (p = p_shada; *p;) {
+ for (char *p = p_shada; *p;) {
(void)copy_option_part(&p, part, ARRAY_SIZE(part), ", ");
if (part[0] == 'r') {
home_replace(NULL, part + 1, NameBuff, MAXPATHL, true);
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 5f3bd0ae06..b145e5964a 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -1943,14 +1943,12 @@ char *parse_spelllang(win_T *wp)
int c;
char lang[MAXWLEN + 1];
char spf_name[MAXPATHL];
- int len;
char *p;
int round;
char *spf;
char *use_region = NULL;
bool dont_use_region = false;
bool nobreak = false;
- langp_T *lp, *lp2;
static bool recursive = false;
char *ret_msg = NULL;
char *spl_copy;
@@ -1980,7 +1978,7 @@ char *parse_spelllang(win_T *wp)
// Get one language name.
copy_option_part(&splp, lang, MAXWLEN, ",");
region = NULL;
- len = (int)strlen(lang);
+ int len = (int)strlen(lang);
if (!valid_spelllang(lang)) {
continue;
@@ -2187,7 +2185,7 @@ char *parse_spelllang(win_T *wp)
// REP items. If the language doesn't support it itself use another one
// with the same name. E.g. for "en-math" use "en".
for (int i = 0; i < ga.ga_len; i++) {
- lp = LANGP_ENTRY(ga, i);
+ langp_T *lp = LANGP_ENTRY(ga, i);
// sound folding
if (!GA_EMPTY(&lp->lp_slang->sl_sal)) {
@@ -2196,7 +2194,7 @@ char *parse_spelllang(win_T *wp)
} else {
// find first similar language that does sound folding
for (int j = 0; j < ga.ga_len; j++) {
- lp2 = LANGP_ENTRY(ga, j);
+ langp_T *lp2 = LANGP_ENTRY(ga, j);
if (!GA_EMPTY(&lp2->lp_slang->sl_sal)
&& strncmp(lp->lp_slang->sl_name,
lp2->lp_slang->sl_name, 2) == 0) {
@@ -2213,7 +2211,7 @@ char *parse_spelllang(win_T *wp)
} else {
// find first similar language that has REP items
for (int j = 0; j < ga.ga_len; j++) {
- lp2 = LANGP_ENTRY(ga, j);
+ langp_T *lp2 = LANGP_ENTRY(ga, j);
if (!GA_EMPTY(&lp2->lp_slang->sl_rep)
&& strncmp(lp->lp_slang->sl_name,
lp2->lp_slang->sl_name, 2) == 0) {
diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c
index 67b29e25a4..f83511dda7 100644
--- a/src/nvim/spellfile.c
+++ b/src/nvim/spellfile.c
@@ -594,16 +594,12 @@ static inline int spell_check_magic_string(FILE *const fd)
/// @return the slang_T the spell file was loaded into. NULL for error.
slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent)
{
- FILE *fd;
char *p;
- int n;
- int len;
slang_T *lp = NULL;
- int c = 0;
int res;
bool did_estack_push = false;
- fd = os_fopen(fname, "r");
+ FILE *fd = os_fopen(fname, "r");
if (fd == NULL) {
if (!silent) {
semsg(_(e_notopen), fname);
@@ -650,7 +646,7 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent)
case 0:
break;
}
- c = getc(fd); // <versionnr>
+ int c = getc(fd); // <versionnr>
if (c < VIMSPELLVERSION) {
emsg(_("E771: Old spell file, needs to be updated"));
goto endFAIL;
@@ -662,12 +658,12 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent)
// <SECTIONS>: <section> ... <sectionend>
// <section>: <sectionID> <sectionflags> <sectionlen> (section contents)
while (true) {
- n = getc(fd); // <sectionID> or <sectionend>
+ int n = getc(fd); // <sectionID> or <sectionend>
if (n == SN_END) {
break;
}
c = getc(fd); // <sectionflags>
- len = get4c(fd); // <sectionlen>
+ int len = get4c(fd); // <sectionlen>
if (len < 0) {
goto truncerr;
}
@@ -841,17 +837,14 @@ endOK:
// Returns the total number of words.
static void tree_count_words(const uint8_t *byts, idx_T *idxs)
{
- int depth;
idx_T arridx[MAXWLEN];
int curi[MAXWLEN];
- int c;
- idx_T n;
int wordcount[MAXWLEN];
arridx[0] = 0;
curi[0] = 1;
wordcount[0] = 0;
- depth = 0;
+ int depth = 0;
while (depth >= 0 && !got_int) {
if (curi[depth] > byts[arridx[depth]]) {
// Done all bytes at this node, go up one level.
@@ -864,10 +857,10 @@ static void tree_count_words(const uint8_t *byts, idx_T *idxs)
fast_breakcheck();
} else {
// Do one more byte at this node.
- n = arridx[depth] + curi[depth];
+ idx_T n = arridx[depth] + curi[depth];
curi[depth]++;
- c = byts[n];
+ int c = byts[n];
if (c == 0) {
// End of word, count it.
wordcount[depth]++;
@@ -892,33 +885,25 @@ static void tree_count_words(const uint8_t *byts, idx_T *idxs)
/// Load the .sug files for languages that have one and weren't loaded yet.
void suggest_load_files(void)
{
- langp_T *lp;
- slang_T *slang;
- char *dotp;
- FILE *fd;
char buf[MAXWLEN];
- time_t timestamp;
- int wcount;
- int wordnr;
garray_T ga;
- int c;
// Do this for all languages that support sound folding.
for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; lpi++) {
- lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
- slang = lp->lp_slang;
+ langp_T *lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
+ slang_T *slang = lp->lp_slang;
if (slang->sl_sugtime != 0 && !slang->sl_sugloaded) {
// Change ".spl" to ".sug" and open the file. When the file isn't
// found silently skip it. Do set "sl_sugloaded" so that we
// don't try again and again.
slang->sl_sugloaded = true;
- dotp = strrchr(slang->sl_fname, '.');
+ char *dotp = strrchr(slang->sl_fname, '.');
if (dotp == NULL || path_fnamecmp(dotp, ".spl") != 0) {
continue;
}
STRCPY(dotp, ".sug");
- fd = os_fopen(slang->sl_fname, "r");
+ FILE *fd = os_fopen(slang->sl_fname, "r");
if (fd == NULL) {
goto nextone;
}
@@ -932,7 +917,7 @@ void suggest_load_files(void)
slang->sl_fname);
goto nextone;
}
- c = getc(fd); // <versionnr>
+ int c = getc(fd); // <versionnr>
if (c < VIMSUGVERSION) {
semsg(_("E779: Old .sug file, needs to be updated: %s"),
slang->sl_fname);
@@ -945,7 +930,7 @@ void suggest_load_files(void)
// Check the timestamp, it must be exactly the same as the one in
// the .spl file. Otherwise the word numbers won't match.
- timestamp = get8ctime(fd); // <timestamp>
+ time_t timestamp = get8ctime(fd); // <timestamp>
if (timestamp != slang->sl_sugtime) {
semsg(_("E781: .sug file doesn't match .spl file: %s"),
slang->sl_fname);
@@ -971,7 +956,7 @@ someerror:
slang->sl_sugbuf = open_spellbuf();
// <sugwcount>
- wcount = get4c(fd);
+ int wcount = get4c(fd);
if (wcount < 0) {
goto someerror;
}
@@ -979,7 +964,7 @@ someerror:
// Read all the wordnr lists into the buffer, one NUL terminated
// list per line.
ga_init(&ga, 1, 100);
- for (wordnr = 0; wordnr < wcount; wordnr++) {
+ for (int wordnr = 0; wordnr < wcount; wordnr++) {
ga.ga_len = 0;
while (true) {
c = getc(fd); // <sugline>
@@ -1020,7 +1005,6 @@ nextone:
static char *read_cnt_string(FILE *fd, int cnt_bytes, int *cntp)
{
int cnt = 0;
- char *str;
// read the length bytes, MSB first
for (int i = 0; i < cnt_bytes; i++) {
@@ -1036,7 +1020,7 @@ static char *read_cnt_string(FILE *fd, int cnt_bytes, int *cntp)
if (cnt == 0) {
return NULL; // nothing to read, return NULL
}
- str = read_string(fd, (size_t)cnt);
+ char *str = read_string(fd, (size_t)cnt);
if (str == NULL) {
*cntp = SP_OTHERERROR;
}
@@ -1060,18 +1044,16 @@ static int read_region_section(FILE *fd, slang_T *lp, int len)
// Return SP_*ERROR flags.
static int read_charflags_section(FILE *fd)
{
- char *flags;
- char *fol;
int flagslen, follen;
// <charflagslen> <charflags>
- flags = read_cnt_string(fd, 1, &flagslen);
+ char *flags = read_cnt_string(fd, 1, &flagslen);
if (flagslen < 0) {
return flagslen;
}
// <folcharslen> <folchars>
- fol = read_cnt_string(fd, 2, &follen);
+ char *fol = read_cnt_string(fd, 2, &follen);
if (follen < 0) {
xfree(flags);
return follen;
@@ -1129,10 +1111,9 @@ static int read_prefcond_section(FILE *fd, slang_T *lp)
// Return SP_*ERROR flags.
static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first)
{
- int cnt;
fromto_T *ftp;
- cnt = get2c(fd); // <repcount>
+ int cnt = get2c(fd); // <repcount>
if (cnt < 0) {
return SP_TRUNCERROR;
}
@@ -1177,12 +1158,6 @@ static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first)
// Return SP_*ERROR flags.
static int read_sal_section(FILE *fd, slang_T *slang)
{
- int cnt;
- garray_T *gap;
- salitem_T *smp;
- int ccnt;
- char *p;
-
slang->sl_sofo = false;
const int flags = getc(fd); // <salflags>
@@ -1196,12 +1171,12 @@ static int read_sal_section(FILE *fd, slang_T *slang)
slang->sl_rem_accents = true;
}
- cnt = get2c(fd); // <salcount>
+ int cnt = get2c(fd); // <salcount>
if (cnt < 0) {
return SP_TRUNCERROR;
}
- gap = &slang->sl_sal;
+ garray_T *gap = &slang->sl_sal;
ga_init(gap, sizeof(salitem_T), 10);
ga_grow(gap, cnt + 1);
@@ -1209,12 +1184,12 @@ static int read_sal_section(FILE *fd, slang_T *slang)
for (; gap->ga_len < cnt; gap->ga_len++) {
int c = NUL;
- smp = &((salitem_T *)gap->ga_data)[gap->ga_len];
- ccnt = getc(fd); // <salfromlen>
+ salitem_T *smp = &((salitem_T *)gap->ga_data)[gap->ga_len];
+ int ccnt = getc(fd); // <salfromlen>
if (ccnt < 0) {
return SP_TRUNCERROR;
}
- p = xmalloc((size_t)ccnt + 2);
+ char *p = xmalloc((size_t)ccnt + 2);
smp->sm_lead = p;
// Read up to the first special char into sm_lead.
@@ -1287,8 +1262,8 @@ static int read_sal_section(FILE *fd, slang_T *slang)
if (!GA_EMPTY(gap)) {
// Add one extra entry to mark the end with an empty sm_lead. Avoids
// that we need to check the index every time.
- smp = &((salitem_T *)gap->ga_data)[gap->ga_len];
- p = xmalloc(1);
+ salitem_T *smp = &((salitem_T *)gap->ga_data)[gap->ga_len];
+ char *p = xmalloc(1);
p[0] = NUL;
smp->sm_lead = p;
smp->sm_lead_w = mb_str2wide(smp->sm_lead);
@@ -1313,13 +1288,12 @@ static int read_words_section(FILE *fd, slang_T *lp, int len)
{
int done = 0;
int i;
- int c;
uint8_t word[MAXWLEN];
while (done < len) {
// Read one word at a time.
for (i = 0;; i++) {
- c = getc(fd);
+ int c = getc(fd);
if (c == EOF) {
return SP_TRUNCERROR;
}
@@ -1344,19 +1318,18 @@ static int read_words_section(FILE *fd, slang_T *lp, int len)
static int read_sofo_section(FILE *fd, slang_T *slang)
{
int cnt;
- char *from, *to;
int res;
slang->sl_sofo = true;
// <sofofromlen> <sofofrom>
- from = read_cnt_string(fd, 2, &cnt);
+ char *from = read_cnt_string(fd, 2, &cnt);
if (cnt < 0) {
return cnt;
}
// <sofotolen> <sofoto>
- to = read_cnt_string(fd, 2, &cnt);
+ char *to = read_cnt_string(fd, 2, &cnt);
if (cnt < 0) {
xfree(from);
return cnt;
@@ -1382,15 +1355,13 @@ static int read_sofo_section(FILE *fd, slang_T *slang)
static int read_compound(FILE *fd, slang_T *slang, int len)
{
int todo = len;
- int c;
- int atstart;
int cnt;
if (todo < 2) {
return SP_FORMERROR; // need at least two bytes
}
todo--;
- c = getc(fd); // <compmax>
+ int c = getc(fd); // <compmax>
if (c < 2) {
c = MAXWLEN;
}
@@ -1469,7 +1440,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len)
*pp++ = '\\';
*pp++ = '(';
- atstart = 1;
+ int atstart = 1;
while (todo-- > 0) {
c = getc(fd); // <compflags>
if (c == EOF) {
@@ -1609,15 +1580,13 @@ static int set_sofo(slang_T *lp, const char *from, const char *to)
// Fill the first-index table for "lp".
static void set_sal_first(slang_T *lp)
{
- salfirst_T *sfirst;
- salitem_T *smp;
garray_T *gap = &lp->sl_sal;
- sfirst = lp->sl_sal_first;
+ salfirst_T *sfirst = lp->sl_sal_first;
for (int i = 0; i < 256; i++) {
sfirst[i] = -1;
}
- smp = (salitem_T *)gap->ga_data;
+ salitem_T *smp = (salitem_T *)gap->ga_data;
for (int i = 0; i < gap->ga_len; i++) {
// Use the lowest byte of the first character. For latin1 it's
// the character, for other encodings it should differ for most
@@ -1679,10 +1648,6 @@ static int spell_read_tree(FILE *fd, uint8_t **bytsp, int *bytsp_len, idx_T **id
bool prefixtree, int prefixcnt)
FUNC_ATTR_NONNULL_ARG(1, 2, 4)
{
- int idx;
- uint8_t *bp;
- idx_T *ip;
-
// The tree size was computed when writing the file, so that we can
// allocate it as one long block. <nodecount>
int len = get4c(fd);
@@ -1698,18 +1663,18 @@ static int spell_read_tree(FILE *fd, uint8_t **bytsp, int *bytsp_len, idx_T **id
}
// Allocate the byte array.
- bp = xmalloc((size_t)len);
+ uint8_t *bp = xmalloc((size_t)len);
*bytsp = bp;
if (bytsp_len != NULL) {
*bytsp_len = len;
}
// Allocate the index array.
- ip = xcalloc((size_t)len, sizeof(*ip));
+ idx_T *ip = xcalloc((size_t)len, sizeof(*ip));
*idxsp = ip;
// Recursively read the tree and store it in the array.
- idx = read_tree_node(fd, bp, ip, len, 0, prefixtree, prefixcnt);
+ int idx = read_tree_node(fd, bp, ip, len, 0, prefixtree, prefixcnt);
if (idx < 0) {
return idx;
}
@@ -1732,13 +1697,10 @@ static int spell_read_tree(FILE *fd, uint8_t **bytsp, int *bytsp_len, idx_T **id
static idx_T read_tree_node(FILE *fd, uint8_t *byts, idx_T *idxs, int maxidx, idx_T startidx,
bool prefixtree, int maxprefcondnr)
{
- int len;
- int n;
idx_T idx = startidx;
- int c2;
#define SHARED_MASK 0x8000000
- len = getc(fd); // <siblingcount>
+ int len = getc(fd); // <siblingcount>
if (len <= 0) {
return SP_TRUNCERROR;
}
@@ -1772,7 +1734,7 @@ static idx_T read_tree_node(FILE *fd, uint8_t *byts, idx_T *idxs, int maxidx, id
c |= getc(fd); // <affixID>
- n = get2c(fd); // <prefcondnr>
+ int n = get2c(fd); // <prefcondnr>
if (n >= maxprefcondnr) {
return SP_FORMERROR;
}
@@ -1781,7 +1743,7 @@ static idx_T read_tree_node(FILE *fd, uint8_t *byts, idx_T *idxs, int maxidx, id
// Read flags and optional region and prefix ID. In
// idxs[] the flags go in the low two bytes, region above
// that and prefix ID above the region.
- c2 = c;
+ int c2 = c;
c = getc(fd); // <flags>
if (c2 == BY_FLAGS2) {
c = (getc(fd) << 8) + c; // <flags2>
@@ -1798,7 +1760,7 @@ static idx_T read_tree_node(FILE *fd, uint8_t *byts, idx_T *idxs, int maxidx, id
c = 0;
} else { // c == BY_INDEX
// <nodeidx>
- n = get3c(fd);
+ int n = get3c(fd);
if (n < 0 || n >= maxidx) {
return SP_FORMERROR;
}
@@ -1834,10 +1796,9 @@ static idx_T read_tree_node(FILE *fd, uint8_t *byts, idx_T *idxs, int maxidx, id
/// @param added_word invoked through "zg"
static void spell_reload_one(char *fname, bool added_word)
{
- slang_T *slang;
bool didit = false;
- for (slang = first_lang; slang != NULL; slang = slang->sl_next) {
+ for (slang_T *slang = first_lang; slang != NULL; slang = slang->sl_next) {
if (path_full_compare(fname, slang->sl_fname, false, true) == kEqualFiles) {
slang_clear(slang);
if (spell_load_file(fname, NULL, slang, false) == NULL) {
@@ -1880,15 +1841,12 @@ static int compress_added = 500000; // word count
int spell_check_msm(void)
{
char *p = p_msm;
- int start = 0;
- int incr = 0;
- int added = 0;
if (!ascii_isdigit(*p)) {
return FAIL;
}
// block count = (value * 1024) / SBLOCKSIZE (but avoid overflow)
- start = (getdigits_int(&p, true, 0) * 10) / (SBLOCKSIZE / 102);
+ int start = (getdigits_int(&p, true, 0) * 10) / (SBLOCKSIZE / 102);
if (*p != ',') {
return FAIL;
}
@@ -1896,7 +1854,7 @@ int spell_check_msm(void)
if (!ascii_isdigit(*p)) {
return FAIL;
}
- incr = (getdigits_int(&p, true, 0) * 102) / (SBLOCKSIZE / 10);
+ int incr = (getdigits_int(&p, true, 0) * 102) / (SBLOCKSIZE / 10);
if (*p != ',') {
return FAIL;
}
@@ -1904,7 +1862,7 @@ int spell_check_msm(void)
if (!ascii_isdigit(*p)) {
return FAIL;
}
- added = getdigits_int(&p, true, 0) * 1024;
+ int added = getdigits_int(&p, true, 0) * 1024;
if (*p != NUL) {
return FAIL;
}
@@ -2017,13 +1975,11 @@ static void spell_print_tree(wordnode_T *root)
// Returns an afffile_T, NULL for complete failure.
static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname)
{
- FILE *fd;
char rline[MAXLINELEN];
char *line;
char *pc = NULL;
#define MAXITEMCNT 30
char *(items[MAXITEMCNT]);
- int itemcnt;
char *p;
int lnum = 0;
affheader_T *cur_aff = NULL;
@@ -2033,13 +1989,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname)
char *low = NULL;
char *fol = NULL;
char *upp = NULL;
- int do_rep;
- int do_repsal;
- int do_sal;
- int do_mapline;
bool found_map = false;
hashitem_T *hi;
- int l;
int compminlen = 0; // COMPOUNDMIN value
int compsylmax = 0; // COMPOUNDSYLMAX value
int compoptions = 0; // COMP_ flags
@@ -2052,7 +2003,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname)
char *sofoto = NULL; // SOFOTO value
// Open the file.
- fd = os_fopen(fname, "r");
+ FILE *fd = os_fopen(fname, "r");
if (fd == NULL) {
semsg(_(e_notopen), fname);
return NULL;
@@ -2062,16 +2013,16 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname)
spell_message(spin, IObuff);
// Only do REP lines when not done in another .aff file already.
- do_rep = GA_EMPTY(&spin->si_rep);
+ int do_rep = GA_EMPTY(&spin->si_rep);
// Only do REPSAL lines when not done in another .aff file already.
- do_repsal = GA_EMPTY(&spin->si_repsal);
+ int do_repsal = GA_EMPTY(&spin->si_repsal);
// Only do SAL lines when not done in another .aff file already.
- do_sal = GA_EMPTY(&spin->si_sal);
+ int do_sal = GA_EMPTY(&spin->si_sal);
// Only do MAP lines when not done in another .aff file already.
- do_mapline = GA_EMPTY(&spin->si_map);
+ int do_mapline = GA_EMPTY(&spin->si_map);
// Allocate and init the afffile_T structure.
afffile_T *aff = getroom(spin, sizeof(*aff), true);
@@ -2106,7 +2057,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname)
// Split the line up in white separated items. Put a NUL after each
// item.
- itemcnt = 0;
+ int itemcnt = 0;
for (p = line;;) {
while (*p != NUL && (uint8_t)(*p) <= ' ') { // skip white space and CR/NL
p++;
@@ -2252,7 +2203,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname)
if (compflags != NULL || *skipdigits(items[1]) != NUL) {
// Concatenate this string to previously defined ones,
// using a slash to separate them.
- l = (int)strlen(items[1]) + 1;
+ int l = (int)strlen(items[1]) + 1;
if (compflags != NULL) {
l += (int)strlen(compflags) + 1;
}
@@ -2774,11 +2725,9 @@ static bool is_aff_rule(char **items, int itemcnt, char *rulename, int mincount)
// ae_flags to ae_comppermit and ae_compforbid.
static void aff_process_flags(afffile_T *affile, affentry_T *entry)
{
- char *p;
-
if (entry->ae_flags != NULL
&& (affile->af_compforbid != 0 || affile->af_comppermit != 0)) {
- for (p = entry->ae_flags; *p != NUL;) {
+ for (char *p = entry->ae_flags; *p != NUL;) {
char *prevp = p;
unsigned flag = get_affitem(affile->af_flagtype, &p);
if (flag == affile->af_comppermit || flag == affile->af_compforbid) {
@@ -2870,12 +2819,9 @@ static unsigned get_affitem(int flagtype, char **pp)
/// they fit in one byte.
static void process_compflags(spellinfo_T *spin, afffile_T *aff, char *compflags)
{
- char *prevp;
- unsigned flag;
compitem_T *ci;
int id;
char key[AH_KEY_LEN];
- hashitem_T *hi;
// Make room for the old and the new compflags, concatenated with a / in
// between. Processing it makes it shorter, but we don't know by how
@@ -2898,13 +2844,13 @@ static void process_compflags(spellinfo_T *spin, afffile_T *aff, char *compflags
*tp++ = (uint8_t)(*p++);
} else {
// First get the flag number, also checks validity.
- prevp = p;
- flag = get_affitem(aff->af_flagtype, &p);
+ char *prevp = p;
+ unsigned flag = get_affitem(aff->af_flagtype, &p);
if (flag != 0) {
// Find the flag in the hashtable. If it was used before, use
// the existing ID. Otherwise add a new entry.
xstrlcpy(key, prevp, (size_t)(p - prevp) + 1);
- hi = hash_find(&aff->af_comp, key);
+ hashitem_T *hi = hash_find(&aff->af_comp, key);
if (!HASHITEM_EMPTY(hi)) {
id = HI2CI(hi)->ci_newID;
} else {
@@ -2946,17 +2892,14 @@ static void check_renumber(spellinfo_T *spin)
// Returns true if flag "flag" appears in affix list "afflist".
static bool flag_in_afflist(int flagtype, char *afflist, unsigned flag)
{
- char *p;
- unsigned n;
-
switch (flagtype) {
case AFT_CHAR:
return vim_strchr(afflist, (int)flag) != NULL;
case AFT_CAPLONG:
case AFT_LONG:
- for (p = afflist; *p != NUL;) {
- n = (unsigned)mb_ptr2char_adv((const char **)&p);
+ for (char *p = afflist; *p != NUL;) {
+ unsigned n = (unsigned)mb_ptr2char_adv((const char **)&p);
if ((flagtype == AFT_LONG || (n >= 'A' && n <= 'Z'))
&& *p != NUL) {
n = (unsigned)mb_ptr2char_adv((const char **)&p) + (n << 16);
@@ -2968,10 +2911,10 @@ static bool flag_in_afflist(int flagtype, char *afflist, unsigned flag)
break;
case AFT_NUM:
- for (p = afflist; *p != NUL;) {
+ for (char *p = afflist; *p != NUL;) {
int digits = getdigits_int(&p, true, 0);
assert(digits >= 0);
- n = (unsigned)digits;
+ unsigned n = (unsigned)digits;
if (n == 0) {
n = ZERO_FLAG;
}
@@ -3037,21 +2980,16 @@ static bool sal_to_bool(char *s)
// Free the structure filled by spell_read_aff().
static void spell_free_aff(afffile_T *aff)
{
- hashtab_T *ht;
- hashitem_T *hi;
- affheader_T *ah;
- affentry_T *ae;
-
xfree(aff->af_enc);
// All this trouble to free the "ae_prog" items...
- for (ht = &aff->af_pref;; ht = &aff->af_suff) {
+ for (hashtab_T *ht = &aff->af_pref;; ht = &aff->af_suff) {
int todo = (int)ht->ht_used;
- for (hi = ht->ht_array; todo > 0; hi++) {
+ for (hashitem_T *hi = ht->ht_array; todo > 0; hi++) {
if (!HASHITEM_EMPTY(hi)) {
todo--;
- ah = HI2AH(hi);
- for (ae = ah->ah_first; ae != NULL; ae = ae->ae_next) {
+ affheader_T *ah = HI2AH(hi);
+ for (affentry_T *ae = ah->ah_first; ae != NULL; ae = ae->ae_next) {
vim_regfree(ae->ae_prog);
}
}
@@ -3072,22 +3010,13 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile)
{
hashtab_T ht;
char line[MAXLINELEN];
- char *p;
- char *afflist;
char store_afflist[MAXWLEN];
- int pfxlen;
- bool need_affix;
- char *dw;
char *pc;
char *w;
- int l;
- hash_T hash;
- hashitem_T *hi;
int lnum = 1;
int non_ascii = 0;
int retval = OK;
char message[MAXLINELEN + MAXWLEN];
- int flags;
int duplicate = 0;
Timestamp last_msg_time = 0;
@@ -3124,7 +3053,7 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile)
}
// Remove CR, LF and white space from the end. White space halfway through
// the word is kept to allow multi-word terms like "et al.".
- l = (int)strlen(line);
+ int l = (int)strlen(line);
while (l > 0 && (uint8_t)line[l - 1] <= ' ') {
l--;
}
@@ -3149,8 +3078,8 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile)
// Truncate the word at the "/", set "afflist" to what follows.
// Replace "\/" by "/" and "\\" by "\".
- afflist = NULL;
- for (p = w; *p != NUL; MB_PTR_ADV(p)) {
+ char *afflist = NULL;
+ for (char *p = w; *p != NUL; MB_PTR_ADV(p)) {
if (*p == '\\' && (p[1] == '\\' || p[1] == '/')) {
STRMOVE(p, p + 1);
} else if (*p == '/') {
@@ -3186,15 +3115,15 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile)
}
// Store the word in the hashtable to be able to find duplicates.
- dw = getroom_save(spin, w);
+ char *dw = getroom_save(spin, w);
if (dw == NULL) {
retval = FAIL;
xfree(pc);
break;
}
- hash = hash_hash(dw);
- hi = hash_lookup(&ht, dw, strlen(dw), hash);
+ hash_T hash = hash_hash(dw);
+ hashitem_T *hi = hash_lookup(&ht, dw, strlen(dw), hash);
if (!HASHITEM_EMPTY(hi)) {
if (p_verbose > 0) {
smsg(0, _("Duplicate word in %s line %d: %s"),
@@ -3208,10 +3137,10 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile)
hash_add_item(&ht, hi, dw, hash);
}
- flags = 0;
+ int flags = 0;
store_afflist[0] = NUL;
- pfxlen = 0;
- need_affix = false;
+ int pfxlen = 0;
+ bool need_affix = false;
if (afflist != NULL) {
// Extract flags from the affix list.
flags |= get_affix_flags(affile, afflist);
@@ -3317,9 +3246,7 @@ static int get_affix_flags(afffile_T *affile, char *afflist)
static int get_pfxlist(afffile_T *affile, char *afflist, char *store_afflist)
{
int cnt = 0;
- int id;
char key[AH_KEY_LEN];
- hashitem_T *hi;
for (char *p = afflist; *p != NUL;) {
char *prevp = p;
@@ -3327,9 +3254,9 @@ static int get_pfxlist(afffile_T *affile, char *afflist, char *store_afflist)
// A flag is a postponed prefix flag if it appears in "af_pref"
// and its ID is not zero.
xstrlcpy(key, prevp, (size_t)(p - prevp) + 1);
- hi = hash_find(&affile->af_pref, key);
+ hashitem_T *hi = hash_find(&affile->af_pref, key);
if (!HASHITEM_EMPTY(hi)) {
- id = HI2AH(hi)->ah_newID;
+ int id = HI2AH(hi)->ah_newID;
if (id != 0) {
store_afflist[cnt++] = (char)(uint8_t)id;
}
@@ -3351,14 +3278,13 @@ static void get_compflags(afffile_T *affile, char *afflist, char *store_afflist)
{
int cnt = 0;
char key[AH_KEY_LEN];
- hashitem_T *hi;
for (char *p = afflist; *p != NUL;) {
char *prevp = p;
if (get_affitem(affile->af_flagtype, &p) != 0) {
// A flag is a compound flag if it appears in "af_comp".
xstrlcpy(key, prevp, (size_t)(p - prevp) + 1);
- hi = hash_find(&affile->af_comp, key);
+ hashitem_T *hi = hash_find(&affile->af_comp, key);
if (!HASHITEM_EMPTY(hi)) {
store_afflist[cnt++] = (char)(uint8_t)HI2CI(hi)->ci_newID;
}
@@ -3390,27 +3316,19 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_
hashtab_T *ht, hashtab_T *xht, int condit, int flags, char *pfxlist,
int pfxlen)
{
- hashitem_T *hi;
- affheader_T *ah;
affentry_T *ae;
char newword[MAXWLEN];
int retval = OK;
int j;
- char *p;
- int use_flags;
- char *use_pfxlist;
- int use_pfxlen;
- bool need_affix;
char store_afflist[MAXWLEN];
char pfx_pfxlist[MAXWLEN];
size_t wordlen = strlen(word);
- int use_condit;
int todo = (int)ht->ht_used;
- for (hi = ht->ht_array; todo > 0 && retval == OK; hi++) {
+ for (hashitem_T *hi = ht->ht_array; todo > 0 && retval == OK; hi++) {
if (!HASHITEM_EMPTY(hi)) {
todo--;
- ah = HI2AH(hi);
+ affheader_T *ah = HI2AH(hi);
// Check that the affix combines, if required, and that the word
// supports this affix.
@@ -3449,7 +3367,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_
} else {
xstrlcpy(newword, ae->ae_add, MAXWLEN);
}
- p = word;
+ char *p = word;
if (ae->ae_chop != NULL) {
// Skip chop string.
int i = mb_charlen(ae->ae_chop);
@@ -3463,7 +3381,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_
xstrlcpy(newword, word, MAXWLEN);
if (ae->ae_chop != NULL) {
// Remove chop string.
- p = newword + strlen(newword);
+ char *p = newword + strlen(newword);
int i = mb_charlen(ae->ae_chop);
for (; i > 0; i--) {
MB_PTR_BACK(newword, p);
@@ -3475,11 +3393,11 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_
}
}
- use_flags = flags;
- use_pfxlist = pfxlist;
- use_pfxlen = pfxlen;
- need_affix = false;
- use_condit = condit | CONDIT_COMB | CONDIT_AFF;
+ int use_flags = flags;
+ char *use_pfxlist = pfxlist;
+ int use_pfxlen = pfxlen;
+ bool need_affix = false;
+ int use_condit = condit | CONDIT_COMB | CONDIT_AFF;
if (ae->ae_flags != NULL) {
// Extract flags from the affix list.
use_flags |= get_affix_flags(affile, ae->ae_flags);
@@ -3631,21 +3549,16 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_
// Read a file with a list of words.
static int spell_read_wordfile(spellinfo_T *spin, char *fname)
{
- FILE *fd;
linenr_T lnum = 0;
char rline[MAXLINELEN];
char *line;
char *pc = NULL;
- char *p;
- int l;
int retval = OK;
bool did_word = false;
int non_ascii = 0;
- int flags;
- int regionmask;
// Open the file.
- fd = os_fopen(fname, "r");
+ FILE *fd = os_fopen(fname, "r");
if (fd == NULL) {
semsg(_(e_notopen), fname);
return FAIL;
@@ -3665,7 +3578,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname)
}
// Remove CR, LF and white space from the end.
- l = (int)strlen(rline);
+ int l = (int)strlen(rline);
while (l > 0 && (uint8_t)rline[l - 1] <= ' ') {
l--;
}
@@ -3740,11 +3653,11 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname)
continue;
}
- flags = 0;
- regionmask = spin->si_region;
+ int flags = 0;
+ int regionmask = spin->si_region;
// Check for flags and region after a slash.
- p = vim_strchr(line, '/');
+ char *p = vim_strchr(line, '/');
if (p != NULL) {
*p++ = NUL;
while (*p != NUL) {
@@ -3813,7 +3726,6 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname)
static void *getroom(spellinfo_T *spin, size_t len, bool align)
FUNC_ATTR_NONNULL_RET
{
- char *p;
sblock_T *bl = spin->si_blocks;
assert(len <= SBLOCKSIZE);
@@ -3833,7 +3745,7 @@ static void *getroom(spellinfo_T *spin, size_t len, bool align)
spin->si_blocks_cnt++;
}
- p = bl->sb_data + bl->sb_used;
+ char *p = bl->sb_data + bl->sb_used;
bl->sb_used += (int)len;
return p;
@@ -3851,10 +3763,8 @@ static char *getroom_save(spellinfo_T *spin, char *s)
// Free the list of allocated sblock_T.
static void free_blocks(sblock_T *bl)
{
- sblock_T *next;
-
while (bl != NULL) {
- next = bl->sb_next;
+ sblock_T *next = bl->sb_next;
xfree(bl);
bl = next;
}
@@ -3943,8 +3853,6 @@ static int tree_add_word(spellinfo_T *spin, const char *word, wordnode_T *root,
int region, int affixID)
{
wordnode_T *node = root;
- wordnode_T *np;
- wordnode_T *copyp, **copyprev;
wordnode_T **prev = NULL;
// Add each byte of the word to the tree, including the NUL at the end.
@@ -3954,10 +3862,10 @@ static int tree_add_word(spellinfo_T *spin, const char *word, wordnode_T *root,
// (we don't optimize for a partly shared list of siblings).
if (node != NULL && node->wn_refs > 1) {
node->wn_refs--;
- copyprev = prev;
- for (copyp = node; copyp != NULL; copyp = copyp->wn_sibling) {
+ wordnode_T **copyprev = prev;
+ for (wordnode_T *copyp = node; copyp != NULL; copyp = copyp->wn_sibling) {
// Allocate a new node and copy the info.
- np = get_wordnode(spin);
+ wordnode_T *np = get_wordnode(spin);
if (np == NULL) {
return FAIL;
}
@@ -4012,7 +3920,7 @@ static int tree_add_word(spellinfo_T *spin, const char *word, wordnode_T *root,
|| node->wn_flags != (flags & WN_MASK)
|| node->wn_affixID != affixID))) {
// Allocate a new node.
- np = get_wordnode(spin);
+ wordnode_T *np = get_wordnode(spin);
if (np == NULL) {
return FAIL;
}
@@ -4134,11 +4042,10 @@ static wordnode_T *get_wordnode(spellinfo_T *spin)
static int deref_wordnode(spellinfo_T *spin, wordnode_T *node)
FUNC_ATTR_NONNULL_ALL
{
- wordnode_T *np;
int cnt = 0;
if (--node->wn_refs == 0) {
- for (np = node; np != NULL; np = np->wn_sibling) {
+ for (wordnode_T *np = node; np != NULL; np = np->wn_sibling) {
if (np->wn_child != NULL) {
cnt += deref_wordnode(spin, np->wn_child);
}
@@ -4206,29 +4113,26 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *n
static int node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, int *tot)
FUNC_ATTR_NONNULL_ALL
{
- wordnode_T *np;
wordnode_T *tp;
wordnode_T *child;
- hash_T hash;
- hashitem_T *hi;
int len = 0;
- unsigned nr, n;
+ unsigned n;
int compressed = 0;
// Go through the list of siblings. Compress each child and then try
// finding an identical child to replace it.
// Note that with "child" we mean not just the node that is pointed to,
// but the whole list of siblings of which the child node is the first.
- for (np = node; np != NULL && !got_int; np = np->wn_sibling) {
+ for (wordnode_T *np = node; np != NULL && !got_int; np = np->wn_sibling) {
len++;
if ((child = np->wn_child) != NULL) {
// Compress the child first. This fills hashkey.
compressed += node_compress(spin, child, ht, tot);
// Try to find an identical child.
- hash = hash_hash((char *)child->wn_u1.hashkey);
- hi = hash_lookup(ht, (const char *)child->wn_u1.hashkey,
- strlen((char *)child->wn_u1.hashkey), hash);
+ hash_T hash = hash_hash((char *)child->wn_u1.hashkey);
+ hashitem_T *hi = hash_lookup(ht, (const char *)child->wn_u1.hashkey,
+ strlen((char *)child->wn_u1.hashkey), hash);
if (!HASHITEM_EMPTY(hi)) {
// There are children we encountered before with a hash value
// identical to the current child. Now check if there is one
@@ -4265,8 +4169,8 @@ static int node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, int
// find a lookalike node. This must be done after compressing the sibling
// list, otherwise the hash key would become invalid by the compression.
node->wn_u1.hashkey[0] = (uint8_t)len;
- nr = 0;
- for (np = node; np != NULL; np = np->wn_sibling) {
+ unsigned nr = 0;
+ for (wordnode_T *np = node; np != NULL; np = np->wn_sibling) {
if (np->wn_byte == NUL) {
// end node: use wn_flags, wn_region and wn_affixID
n = (unsigned)(np->wn_flags + (np->wn_region << 8) + (np->wn_affixID << 16));
@@ -4714,10 +4618,8 @@ theend:
// space.
static void clear_node(wordnode_T *node)
{
- wordnode_T *np;
-
if (node != NULL) {
- for (np = node; np != NULL; np = np->wn_sibling) {
+ for (wordnode_T *np = node; np != NULL; np = np->wn_sibling) {
np->wn_u1.index = 0;
np->wn_u2.wnode = NULL;
@@ -4875,7 +4777,6 @@ void ex_mkspell(exarg_T *eap)
static void spell_make_sugfile(spellinfo_T *spin, char *wfname)
{
char *fname = NULL;
- int len;
slang_T *slang;
bool free_slang = false;
@@ -4933,7 +4834,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char *wfname)
// Make the file name by changing ".spl" to ".sug".
fname = xmalloc(MAXPATHL);
xstrlcpy(fname, wfname, MAXPATHL);
- len = (int)strlen(fname);
+ int len = (int)strlen(fname);
fname[len - 2] = 'u';
fname[len - 1] = 'g';
sug_write(spin, fname);
@@ -4950,15 +4851,10 @@ theend:
// Build the soundfold trie for language "slang".
static int sug_filltree(spellinfo_T *spin, slang_T *slang)
{
- uint8_t *byts;
- idx_T *idxs;
- int depth;
idx_T arridx[MAXWLEN];
int curi[MAXWLEN];
char tword[MAXWLEN];
char tsalword[MAXWLEN];
- int c;
- idx_T n;
unsigned words_done = 0;
int wordcount[MAXWLEN];
@@ -4970,8 +4866,8 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang)
// Go through the whole case-folded tree, soundfold each word and put it
// in the trie. Bail out if the tree is empty.
- byts = slang->sl_fbyts;
- idxs = slang->sl_fidxs;
+ uint8_t *byts = slang->sl_fbyts;
+ idx_T *idxs = slang->sl_fidxs;
if (byts == NULL || idxs == NULL) {
return FAIL;
}
@@ -4980,7 +4876,7 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang)
curi[0] = 1;
wordcount[0] = 0;
- depth = 0;
+ int depth = 0;
while (depth >= 0 && !got_int) {
if (curi[depth] > byts[arridx[depth]]) {
// Done all bytes at this node, go up one level.
@@ -4993,10 +4889,10 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang)
line_breakcheck();
} else {
// Do one more byte at this node.
- n = arridx[depth] + curi[depth];
+ idx_T n = arridx[depth] + curi[depth];
curi[depth]++;
- c = byts[n];
+ int c = byts[n];
if (c == 0) {
// Sound-fold the word.
tword[depth] = NUL;
@@ -5073,17 +4969,15 @@ static int sug_maketable(spellinfo_T *spin)
static int sug_filltable(spellinfo_T *spin, wordnode_T *node, int startwordnr, garray_T *gap)
{
int wordnr = startwordnr;
- int nr;
- int prev_nr;
for (wordnode_T *p = node; p != NULL; p = p->wn_sibling) {
if (p->wn_byte == NUL) {
gap->ga_len = 0;
- prev_nr = 0;
+ int prev_nr = 0;
for (wordnode_T *np = p; np != NULL && np->wn_byte == NUL; np = np->wn_sibling) {
ga_grow(gap, 10);
- nr = (np->wn_flags << 16) + (np->wn_region & 0xffff);
+ int nr = (np->wn_flags << 16) + (np->wn_region & 0xffff);
// Compute the offset from the previous nr and store the
// offset in a way that it takes a minimum number of bytes.
// It's a bit like utf-8, but without the need to mark
@@ -5128,16 +5022,14 @@ static int sug_filltable(spellinfo_T *spin, wordnode_T *node, int startwordnr, g
static int offset2bytes(int nr, char *buf_in)
{
uint8_t *buf = (uint8_t *)buf_in;
- int rem;
- int b1, b2, b3, b4;
// Split the number in parts of base 255. We need to avoid NUL bytes.
- b1 = nr % 255 + 1;
- rem = nr / 255;
- b2 = rem % 255 + 1;
+ int b1 = nr % 255 + 1;
+ int rem = nr / 255;
+ int b2 = rem % 255 + 1;
rem = rem / 255;
- b3 = rem % 255 + 1;
- b4 = rem / 255 + 1;
+ int b3 = rem % 255 + 1;
+ int b4 = rem / 255 + 1;
if (b4 > 1 || b3 > 0x1f) { // 4 bytes
buf[0] = (uint8_t)(0xe0 + b4);
@@ -5249,11 +5141,7 @@ theend:
static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool added_word)
{
char *fname = NULL;
- char **innames;
- int incount;
afffile_T *(afile[MAXREGIONS]);
- int i;
- int len;
bool error = false;
spellinfo_T spin;
@@ -5273,13 +5161,13 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool
// default: fnames[0] is output file, following are input files
// When "fcount" is 1 there is only one file.
- innames = &fnames[fcount == 1 ? 0 : 1];
- incount = fcount - 1;
+ char **innames = &fnames[fcount == 1 ? 0 : 1];
+ int incount = fcount - 1;
char *wfname = xmalloc(MAXPATHL);
if (fcount >= 1) {
- len = (int)strlen(fnames[0]);
+ int len = (int)strlen(fnames[0]);
if (fcount == 1 && len > 4 && strcmp(fnames[0] + len - 4, ".add") == 0) {
// For ":mkspell path/en.latin1.add" output file is
// "path/en.latin1.add.spl".
@@ -5332,11 +5220,11 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool
// Init the aff and dic pointers.
// Get the region names if there are more than 2 arguments.
- for (i = 0; i < incount; i++) {
+ for (int i = 0; i < incount; i++) {
afile[i] = NULL;
if (incount > 1) {
- len = (int)strlen(innames[i]);
+ int len = (int)strlen(innames[i]);
if (strlen(path_tail(innames[i])) < 5
|| innames[i][len - 3] != '_') {
semsg(_("E755: Invalid region in %s"), innames[i]);
@@ -5364,7 +5252,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool
// Read all the .aff and .dic files.
// Text is converted to 'encoding'.
// Words are stored in the case-folded and keep-case trees.
- for (i = 0; i < incount && !error; i++) {
+ for (int i = 0; i < incount && !error; i++) {
spin.si_conv.vc_type = CONV_NONE;
spin.si_region = 1 << i;
@@ -5435,7 +5323,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool
hash_clear_all(&spin.si_commonwords, 0);
// Free the .aff file structures.
- for (i = 0; i < incount; i++) {
+ for (int i = 0; i < incount; i++) {
if (afile[i] != NULL) {
spell_free_aff(afile[i]);
}
@@ -5652,10 +5540,7 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo)
// Initialize 'spellfile' for the current buffer.
static void init_spellfile(void)
{
- char *buf;
int l;
- char *fname;
- char *rtp;
char *lend;
bool aspath = false;
char *lstart = curbuf->b_s.b_p_spl;
@@ -5664,7 +5549,7 @@ static void init_spellfile(void)
return;
}
- buf = xmalloc(MAXPATHL);
+ char *buf = xmalloc(MAXPATHL);
// Find the end of the language name. Exclude the region. If there
// is a path separator remember the start of the tail.
@@ -5678,7 +5563,7 @@ static void init_spellfile(void)
// Loop over all entries in 'runtimepath'. Use the first one where we
// are allowed to write.
- rtp = p_rtp;
+ char *rtp = p_rtp;
while (*rtp != NUL) {
if (aspath) {
// Use directory of an entry with path, e.g., for
@@ -5706,8 +5591,8 @@ static void init_spellfile(void)
"/%.*s", (int)(lend - lstart), lstart);
}
l = (int)strlen(buf);
- fname = LANGP_ENTRY(curwin->w_s->b_langp, 0)
- ->lp_slang->sl_fname;
+ char *fname = LANGP_ENTRY(curwin->w_s->b_langp, 0)
+ ->lp_slang->sl_fname;
vim_snprintf(buf + l, MAXPATHL - (size_t)l, ".%s.add",
((fname != NULL
&& strstr(path_tail(fname), ".ascii.") != NULL)
@@ -5732,7 +5617,6 @@ static void set_spell_charflags(const char *flags_in, int cnt, const char *fol)
// previous one.
spelltab_T new_st;
const char *p = fol;
- int c;
clear_spell_chartab(&new_st);
@@ -5743,7 +5627,7 @@ static void set_spell_charflags(const char *flags_in, int cnt, const char *fol)
}
if (*p != NUL) {
- c = mb_ptr2char_adv(&p);
+ int c = mb_ptr2char_adv(&p);
new_st.st_fold[i + 128] = (uint8_t)c;
if (i + 128 != c && new_st.st_isu[i + 128] && c < 256) {
new_st.st_upper[c] = (uint8_t)(i + 128);
diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c
index dab278e383..62508852b3 100644
--- a/src/nvim/spellsuggest.c
+++ b/src/nvim/spellsuggest.c
@@ -384,7 +384,6 @@ static int sps_limit = 9999; ///< max nr of suggestions given
/// Sets "sps_flags" and "sps_limit".
int spell_check_sps(void)
{
- char *s;
char buf[MAXPATHL];
sps_flags = 0;
@@ -395,7 +394,7 @@ int spell_check_sps(void)
int f = 0;
if (ascii_isdigit(*buf)) {
- s = buf;
+ char *s = buf;
sps_limit = getdigits_int(&s, true, 0);
if (*s != NUL && !ascii_isdigit(*s)) {
f = -1;
@@ -438,10 +437,8 @@ int spell_check_sps(void)
/// When "count" is non-zero use that suggestion.
void spell_suggest(int count)
{
- char *line;
pos_T prev_cursor = curwin->w_cursor;
char wcopy[MAXWLEN + 2];
- char *p;
suginfo_T sug;
suggest_T *stp;
int mouse_used;
@@ -477,7 +474,7 @@ void spell_suggest(int count)
badlen++;
end_visual_mode();
// make sure we don't include the NUL at the end of the line
- line = get_cursor_line_ptr();
+ char *line = get_cursor_line_ptr();
if (badlen > (int)strlen(line) - (int)curwin->w_cursor.col) {
badlen = (int)strlen(line) - (int)curwin->w_cursor.col;
}
@@ -487,8 +484,8 @@ void spell_suggest(int count)
// No bad word or it starts after the cursor: use the word under the
// cursor.
curwin->w_cursor = prev_cursor;
- line = get_cursor_line_ptr();
- p = line + curwin->w_cursor.col;
+ char *line = get_cursor_line_ptr();
+ char *p = line + curwin->w_cursor.col;
// Backup to before start of word.
while (p > line && spell_iswordp_nmw(p, curwin)) {
MB_PTR_BACK(line, p);
@@ -511,7 +508,7 @@ void spell_suggest(int count)
int need_cap = check_need_cap(curwin, curwin->w_cursor.lnum, curwin->w_cursor.col);
// Make a copy of current line since autocommands may free the line.
- line = xstrdup(get_cursor_line_ptr());
+ char *line = xstrdup(get_cursor_line_ptr());
spell_suggest_timeout = 5000;
// Get the list of suggestions. Limit to 'lines' - 2 or the number in
@@ -635,7 +632,7 @@ void spell_suggest(int count)
}
// Replace the word.
- p = xmalloc(strlen(line) - (size_t)stp->st_orglen + (size_t)stp->st_wordlen + 1);
+ char *p = xmalloc(strlen(line) - (size_t)stp->st_orglen + (size_t)stp->st_wordlen + 1);
int c = (int)(sug.su_badptr - line);
memmove(p, line, (size_t)c);
STRCPY(p + c, stp->st_word);
@@ -670,7 +667,6 @@ void spell_suggest(int count)
void spell_suggest_list(garray_T *gap, char *word, int maxcount, bool need_cap, bool interactive)
{
suginfo_T sug;
- char *wcopy;
spell_find_suggest(word, 0, &sug, maxcount, false, need_cap, interactive);
@@ -682,7 +678,7 @@ void spell_suggest_list(garray_T *gap, char *word, int maxcount, bool need_cap,
// The suggested word may replace only part of "word", add the not
// replaced part.
- wcopy = xmalloc((size_t)stp->st_wordlen + strlen(sug.su_badptr + stp->st_orglen) + 1);
+ char *wcopy = xmalloc((size_t)stp->st_wordlen + strlen(sug.su_badptr + stp->st_orglen) + 1);
STRCPY(wcopy, stp->st_word);
STRCPY(wcopy + stp->st_wordlen, sug.su_badptr + stp->st_orglen);
((char **)gap->ga_data)[gap->ga_len++] = wcopy;
@@ -707,7 +703,6 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc
char buf[MAXPATHL];
bool do_combine = false;
static bool expr_busy = false;
- langp_T *lp;
bool did_intern = false;
// Set the info in "*su".
@@ -754,7 +749,7 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc
// using multiple files for one language, it's not that bad when mixing
// languages (e.g., "pl,en").
for (int i = 0; i < curbuf->b_s.b_langp.ga_len; i++) {
- lp = LANGP_ENTRY(curbuf->b_s.b_langp, i);
+ langp_T *lp = LANGP_ENTRY(curbuf->b_s.b_langp, i);
if (lp->lp_sallang != NULL) {
su->su_sallang = lp->lp_sallang;
break;
@@ -1061,7 +1056,6 @@ static void prof_report(char *name)
static void suggest_try_change(suginfo_T *su)
{
char fword[MAXWLEN]; // copy of the bad word, case-folded
- langp_T *lp;
// We make a copy of the case-folded bad word, so that we can modify it
// to find matches (esp. REP items). Append some more text, changing
@@ -1078,7 +1072,7 @@ static void suggest_try_change(suginfo_T *su)
}
for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; lpi++) {
- lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
+ langp_T *lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
// If reloading a spell file fails it's still in the list but
// everything has been cleared.
@@ -1140,29 +1134,22 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
// when going deeper but not when coming
// back.
uint8_t compflags[MAXWLEN]; // compound flags, one for each word
- int newscore;
- int score;
uint8_t *byts, *fbyts, *pbyts;
idx_T *idxs, *fidxs, *pidxs;
int c, c2, c3;
int n = 0;
- int flags;
garray_T *gap;
idx_T arridx;
- int len;
- char *p;
- fromto_T *ftp;
- int fl = 0, tl;
+ int fl = 0;
+ int tl;
int repextra = 0; // extra bytes in fword[] from REP item
slang_T *slang = lp->lp_slang;
- int fword_ends;
bool goodword_ends;
#ifdef DEBUG_TRIEWALK
// Stores the name of the change made at each level.
uint8_t changename[MAXWLEN][80];
#endif
int breakcheckcount = 1000;
- bool compound_ok;
// Go through the whole case-fold tree, try changes at each node.
// "tword[]" contains the word collected from nodes in the tree.
@@ -1221,7 +1208,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
// Start of node: Deal with NUL bytes, which means
// tword[] may end here.
arridx = sp->ts_arridx; // current node in the tree
- len = byts[arridx]; // bytes in this node
+ int len = byts[arridx]; // bytes in this node
arridx += sp->ts_curi; // index of current byte
if (sp->ts_prefixdepth == PFD_PREFIXTREE) {
@@ -1241,7 +1228,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
// Set su->su_badflags to the caps type at this position.
// Use the caps type until here for the prefix itself.
n = nofold_len(fword, sp->ts_fidx, su->su_badptr);
- flags = badword_captype(su->su_badptr, su->su_badptr + n);
+ int flags = badword_captype(su->su_badptr, su->su_badptr + n);
su->su_badflags = badword_captype(su->su_badptr + n,
su->su_badptr + su->su_badlen);
#ifdef DEBUG_TRIEWALK
@@ -1277,17 +1264,17 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
// End of word in tree.
sp->ts_curi++; // eat one NUL byte
- flags = (int)idxs[arridx];
+ int flags = (int)idxs[arridx];
// Skip words with the NOSUGGEST flag.
if (flags & WF_NOSUGGEST) {
break;
}
- fword_ends = (fword[sp->ts_fidx] == NUL
- || (soundfold
- ? ascii_iswhite(fword[sp->ts_fidx])
- : !spell_iswordp(fword + sp->ts_fidx, curwin)));
+ int fword_ends = (fword[sp->ts_fidx] == NUL
+ || (soundfold
+ ? ascii_iswhite(fword[sp->ts_fidx])
+ : !spell_iswordp(fword + sp->ts_fidx, curwin)));
tword[sp->ts_twordlen] = NUL;
if (sp->ts_prefixdepth <= PFD_NOTSPECIAL
@@ -1329,8 +1316,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
goodword_ends = true;
}
- p = NULL;
- compound_ok = true;
+ char *p = NULL;
+ bool compound_ok = true;
if (sp->ts_complen > sp->ts_compsplit) {
if (slang->sl_nobreak) {
// There was a word before this word. When there was no
@@ -1343,9 +1330,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
tword + sp->ts_splitoff,
(size_t)(sp->ts_fidx - sp->ts_splitfidx)) == 0) {
preword[sp->ts_prewordlen] = NUL;
- newscore = score_wordcount_adj(slang, sp->ts_score,
- preword + sp->ts_prewordlen,
- sp->ts_prewordlen > 0);
+ int newscore = score_wordcount_adj(slang, sp->ts_score,
+ preword + sp->ts_prewordlen,
+ sp->ts_prewordlen > 0);
// Add the suggestion if the score isn't too bad.
if (newscore <= su->su_maxscore) {
add_suggestion(su, &su->su_ga, preword,
@@ -1448,7 +1435,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
}
}
- newscore = 0;
+ int newscore = 0;
if (!soundfold) { // soundfold words don't have flags
if ((flags & WF_REGION)
&& (((unsigned)flags >> 16) & (unsigned)lp->lp_region) == 0) {
@@ -1499,10 +1486,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
}
// Give a bonus to words seen before.
- score = score_wordcount_adj(slang,
- sp->ts_score + newscore,
- preword + sp->ts_prewordlen,
- sp->ts_prewordlen > 0);
+ int score = score_wordcount_adj(slang,
+ sp->ts_score + newscore,
+ preword + sp->ts_prewordlen,
+ sp->ts_prewordlen > 0);
// Add the suggestion if the score isn't too bad.
if (score <= su->su_maxscore) {
@@ -2260,7 +2247,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
gap = &lp->lp_replang->sl_rep;
}
while (sp->ts_curi < gap->ga_len) {
- ftp = (fromto_T *)gap->ga_data + sp->ts_curi++;
+ fromto_T *ftp = (fromto_T *)gap->ga_data + sp->ts_curi++;
if (*ftp->ft_from != *p) {
// past possible matching entries
sp->ts_curi = (int16_t)gap->ga_len;
@@ -2308,7 +2295,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
} else {
gap = &lp->lp_replang->sl_rep;
}
- ftp = (fromto_T *)gap->ga_data + sp->ts_curi - 1;
+ fromto_T *ftp = (fromto_T *)gap->ga_data + sp->ts_curi - 1;
fl = (int)strlen(ftp->ft_from);
tl = (int)strlen(ftp->ft_to);
p = fword + sp->ts_fidx;
@@ -2369,11 +2356,7 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword)
int uwordidx[MAXWLEN];
int kwordlen[MAXWLEN];
- int flen, ulen;
int l;
- int len;
- int c;
- idx_T lo, hi, m;
char *p;
uint8_t *byts = slang->sl_kbyts; // array with bytes of the words
idx_T *idxs = slang->sl_kidxs; // array with indexes
@@ -2414,8 +2397,8 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword)
} else {
// round[depth] == 1: Try using the folded-case character.
// round[depth] == 2: Try using the upper-case character.
- flen = utf_ptr2len(fword + fwordidx[depth]);
- ulen = utf_ptr2len(uword + uwordidx[depth]);
+ int flen = utf_ptr2len(fword + fwordidx[depth]);
+ int ulen = utf_ptr2len(uword + uwordidx[depth]);
if (round[depth] == 1) {
p = fword + fwordidx[depth];
l = flen;
@@ -2426,12 +2409,12 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword)
for (tryidx = arridx[depth]; l > 0; l--) {
// Perform a binary search in the list of accepted bytes.
- len = byts[tryidx++];
- c = (uint8_t)(*p++);
- lo = tryidx;
- hi = tryidx + len - 1;
+ int len = byts[tryidx++];
+ int c = (uint8_t)(*p++);
+ idx_T lo = tryidx;
+ idx_T hi = tryidx + len - 1;
while (lo < hi) {
- m = (lo + hi) / 2;
+ idx_T m = (lo + hi) / 2;
if (byts[m] > c) {
hi = m - 1;
} else if (byts[m] < c) {
@@ -2483,30 +2466,26 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword)
/// su->su_sga.
static void score_comp_sal(suginfo_T *su)
{
- langp_T *lp;
char badsound[MAXWLEN];
- suggest_T *stp;
- suggest_T *sstp;
- int score;
ga_grow(&su->su_sga, su->su_ga.ga_len);
// Use the sound-folding of the first language that supports it.
for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; lpi++) {
- lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
+ langp_T *lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
if (!GA_EMPTY(&lp->lp_slang->sl_sal)) {
// soundfold the bad word
spell_soundfold(lp->lp_slang, su->su_fbadword, true, badsound);
for (int i = 0; i < su->su_ga.ga_len; i++) {
- stp = &SUG(su->su_ga, i);
+ suggest_T *stp = &SUG(su->su_ga, i);
// Case-fold the suggested word, sound-fold it and compute the
// sound-a-like score.
- score = stp_sal_score(stp, su, lp->lp_slang, badsound);
+ int score = stp_sal_score(stp, su, lp->lp_slang, badsound);
if (score < SCORE_MAXMAX) {
// Add the suggestion.
- sstp = &SUG(su->su_sga, su->su_sga.ga_len);
+ suggest_T *sstp = &SUG(su->su_sga, su->su_sga.ga_len);
sstp->st_word = xstrdup(stp->st_word);
sstp->st_wordlen = stp->st_wordlen;
sstp->st_score = score;
@@ -2525,24 +2504,20 @@ static void score_comp_sal(suginfo_T *su)
static void score_combine(suginfo_T *su)
{
garray_T ga;
- garray_T *gap;
- langp_T *lp;
- suggest_T *stp;
char *p;
char badsound[MAXWLEN];
- int round;
slang_T *slang = NULL;
// Add the alternate score to su_ga.
for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; lpi++) {
- lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
+ langp_T *lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
if (!GA_EMPTY(&lp->lp_slang->sl_sal)) {
// soundfold the bad word
slang = lp->lp_slang;
spell_soundfold(slang, su->su_fbadword, true, badsound);
for (int i = 0; i < su->su_ga.ga_len; i++) {
- stp = &SUG(su->su_ga, i);
+ suggest_T *stp = &SUG(su->su_ga, i);
stp->st_altscore = stp_sal_score(stp, su, slang, badsound);
if (stp->st_altscore == SCORE_MAXMAX) {
stp->st_score = (stp->st_score * 3 + SCORE_BIG) / 4;
@@ -2563,7 +2538,7 @@ static void score_combine(suginfo_T *su)
// Add the alternate score to su_sga.
for (int i = 0; i < su->su_sga.ga_len; i++) {
- stp = &SUG(su->su_sga, i);
+ suggest_T *stp = &SUG(su->su_sga, i);
stp->st_altscore = spell_edit_score(slang, su->su_badword, stp->st_word);
if (stp->st_score == SCORE_MAXMAX) {
stp->st_score = (SCORE_BIG * 7 + stp->st_altscore) / 8;
@@ -2583,12 +2558,12 @@ static void score_combine(suginfo_T *su)
ga_init(&ga, (int)sizeof(suginfo_T), 1);
ga_grow(&ga, su->su_ga.ga_len + su->su_sga.ga_len);
- stp = &SUG(ga, 0);
+ suggest_T *stp = &SUG(ga, 0);
for (int i = 0; i < su->su_ga.ga_len || i < su->su_sga.ga_len; i++) {
// round 1: get a suggestion from su_ga
// round 2: get a suggestion from su_sga
- for (round = 1; round <= 2; round++) {
- gap = round == 1 ? &su->su_ga : &su->su_sga;
+ for (int round = 1; round <= 2; round++) {
+ garray_T *gap = round == 1 ? &su->su_ga : &su->su_sga;
if (i < gap->ga_len) {
// Don't add a word if it's already there.
p = SUG(*gap, i).st_word;
@@ -2687,14 +2662,11 @@ static sftword_T dumsft;
/// Prepare for calling suggest_try_soundalike().
static void suggest_try_soundalike_prep(void)
{
- langp_T *lp;
- slang_T *slang;
-
// Do this for all languages that support sound folding and for which a
// .sug file has been loaded.
for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; lpi++) {
- lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
- slang = lp->lp_slang;
+ langp_T *lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
+ slang_T *slang = lp->lp_slang;
if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) {
// prepare the hashtable used by add_sound_suggest()
hash_init(&slang->sl_sounddone);
@@ -2707,14 +2679,12 @@ static void suggest_try_soundalike_prep(void)
static void suggest_try_soundalike(suginfo_T *su)
{
char salword[MAXWLEN];
- langp_T *lp;
- slang_T *slang;
// Do this for all languages that support sound folding and for which a
// .sug file has been loaded.
for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; lpi++) {
- lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
- slang = lp->lp_slang;
+ langp_T *lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
+ slang_T *slang = lp->lp_slang;
if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) {
// soundfold the bad word
spell_soundfold(slang, su->su_fbadword, true, salword);
@@ -2736,20 +2706,15 @@ static void suggest_try_soundalike(suginfo_T *su)
/// Finish up after calling suggest_try_soundalike().
static void suggest_try_soundalike_finish(void)
{
- langp_T *lp;
- slang_T *slang;
- int todo;
- hashitem_T *hi;
-
// Do this for all languages that support sound folding and for which a
// .sug file has been loaded.
for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; lpi++) {
- lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
- slang = lp->lp_slang;
+ langp_T *lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
+ slang_T *slang = lp->lp_slang;
if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) {
// Free the info about handled words.
- todo = (int)slang->sl_sounddone.ht_used;
- for (hi = slang->sl_sounddone.ht_array; todo > 0; hi++) {
+ int todo = (int)slang->sl_sounddone.ht_used;
+ for (hashitem_T *hi = slang->sl_sounddone.ht_array; todo > 0; hi++) {
if (!HASHITEM_EMPTY(hi)) {
xfree(HI2SFT(hi));
todo--;
@@ -2774,14 +2739,9 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T
int i;
int wlen;
uint8_t *byts;
- idx_T *idxs;
- int n;
- int wordcount;
int wc;
int goodscore;
sftword_T *sft;
- int bc, gc;
- int limit;
// It's very well possible that the same soundfold word is found several
// times with different scores. Since the following is quite slow only do
@@ -2819,11 +2779,11 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T
orgnr += bytes2offset(&nrline);
byts = slang->sl_fbyts;
- idxs = slang->sl_fidxs;
+ idx_T *idxs = slang->sl_fidxs;
// Lookup the word "orgnr" one of the two tries.
- n = 0;
- wordcount = 0;
+ int n = 0;
+ int wordcount = 0;
for (wlen = 0; wlen < MAXWLEN - 3; wlen++) {
i = 1;
if (wordcount == orgnr && byts[n + 1] == NUL) {
@@ -2903,9 +2863,9 @@ badword:
// lower to upper case. Helps for "tath" -> "Kath", which is
// less common than "tath" -> "path". Don't do it when the
// letter is the same, that has already been counted.
- gc = utf_ptr2char(p);
+ int gc = utf_ptr2char(p);
if (SPELL_ISUPPER(gc)) {
- bc = utf_ptr2char(su->su_badword);
+ int bc = utf_ptr2char(su->su_badword);
if (!SPELL_ISUPPER(bc)
&& SPELL_TOFOLD(bc) != SPELL_TOFOLD(gc)) {
goodscore += SCORE_ICASE / 2;
@@ -2919,7 +2879,7 @@ badword:
// MAXSCORE(), because RESCORE() will change the score.
// If the limit is very high then the iterative method is
// inefficient, using an array is quicker.
- limit = MAXSCORE(su->su_sfmaxscore - goodscore, score);
+ int limit = MAXSCORE(su->su_sfmaxscore - goodscore, score);
if (limit > SCORE_LIMITMAX) {
goodscore += spell_edit_score(slang, su->su_badword, p);
} else {
@@ -3020,11 +2980,10 @@ static bool similar_chars(slang_T *slang, int c1, int c2)
{
int m1, m2;
char buf[MB_MAXCHAR + 1];
- hashitem_T *hi;
if (c1 >= 256) {
buf[utf_char2bytes(c1, buf)] = 0;
- hi = hash_find(&slang->sl_map_hash, buf);
+ hashitem_T *hi = hash_find(&slang->sl_map_hash, buf);
if (HASHITEM_EMPTY(hi)) {
m1 = 0;
} else {
@@ -3039,7 +2998,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2)
if (c2 >= 256) {
buf[utf_char2bytes(c2, buf)] = 0;
- hi = hash_find(&slang->sl_map_hash, buf);
+ hashitem_T *hi = hash_find(&slang->sl_map_hash, buf);
if (HASHITEM_EMPTY(hi)) {
m2 = 0;
} else {
@@ -3065,7 +3024,6 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i
{
int goodlen; // len of goodword changed
int badlen; // len of bad word changed
- suggest_T *stp;
suggest_T new_sug;
// Minimize "badlen" for consistency. Avoids that changing "the the" to
@@ -3098,7 +3056,7 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i
// Check if the word is already there. Also check the length that is
// being replaced "thes," -> "these" is a different suggestion from
// "thes" -> "these".
- stp = &SUG(*gap, 0);
+ suggest_T *stp = &SUG(*gap, 0);
for (i = gap->ga_len; --i >= 0; stp++) {
if (stp->st_wordlen == goodlen
&& stp->st_orglen == badlen
@@ -3142,7 +3100,7 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i
if (i < 0) {
// Add a suggestion.
- stp = GA_APPEND_VIA_PTR(suggest_T, gap);
+ suggest_T *stp = GA_APPEND_VIA_PTR(suggest_T, gap);
stp->st_word = xmemdupz(goodword, (size_t)goodlen);
stp->st_wordlen = goodlen;
stp->st_score = score;
@@ -3172,7 +3130,6 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i
static void check_suggestions(suginfo_T *su, garray_T *gap)
{
char longword[MAXWLEN + 1];
- hlf_T attr;
if (gap->ga_len == 0) {
return;
@@ -3184,7 +3141,7 @@ static void check_suggestions(suginfo_T *su, garray_T *gap)
int len = stp[i].st_wordlen;
xstrlcpy(longword + len, su->su_badptr + stp[i].st_orglen,
(size_t)(MAXWLEN - len + 1));
- attr = HLF_COUNT;
+ hlf_T attr = HLF_COUNT;
(void)spell_check(curwin, longword, &attr, NULL, false);
if (attr != HLF_COUNT) {
// Remove this entry.
@@ -3526,11 +3483,6 @@ static int soundalike_score(char *goodstart, char *badstart)
/// support multi-byte characters.
static int spell_edit_score(slang_T *slang, const char *badword, const char *goodword)
{
- int *cnt;
- int j, i;
- int t;
- int bc, gc;
- int pbc, pgc;
int wbadword[MAXWLEN];
int wgoodword[MAXWLEN];
@@ -3554,18 +3506,18 @@ static int spell_edit_score(slang_T *slang, const char *badword, const char *goo
// We use "cnt" as an array: CNT(badword_idx, goodword_idx).
#define CNT(a, b) cnt[(a) + (b) * (badlen + 1)]
- cnt = xmalloc(sizeof(int) * ((size_t)badlen + 1) * ((size_t)goodlen + 1));
+ int *cnt = xmalloc(sizeof(int) * ((size_t)badlen + 1) * ((size_t)goodlen + 1));
CNT(0, 0) = 0;
- for (j = 1; j <= goodlen; j++) {
+ for (int j = 1; j <= goodlen; j++) {
CNT(0, j) = CNT(0, j - 1) + SCORE_INS;
}
- for (i = 1; i <= badlen; i++) {
+ for (int i = 1; i <= badlen; i++) {
CNT(i, 0) = CNT(i - 1, 0) + SCORE_DEL;
- for (j = 1; j <= goodlen; j++) {
- bc = wbadword[i - 1];
- gc = wgoodword[j - 1];
+ for (int j = 1; j <= goodlen; j++) {
+ int bc = wbadword[i - 1];
+ int gc = wgoodword[j - 1];
if (bc == gc) {
CNT(i, j) = CNT(i - 1, j - 1);
} else {
@@ -3584,16 +3536,16 @@ static int spell_edit_score(slang_T *slang, const char *badword, const char *goo
}
if (i > 1 && j > 1) {
- pbc = wbadword[i - 2];
- pgc = wgoodword[j - 2];
+ int pbc = wbadword[i - 2];
+ int pgc = wgoodword[j - 2];
if (bc == pgc && pbc == gc) {
- t = SCORE_SWAP + CNT(i - 2, j - 2);
+ int t = SCORE_SWAP + CNT(i - 2, j - 2);
if (t < CNT(i, j)) {
CNT(i, j) = t;
}
}
}
- t = SCORE_DEL + CNT(i - 1, j);
+ int t = SCORE_DEL + CNT(i - 1, j);
if (t < CNT(i, j)) {
CNT(i, j) = t;
}
@@ -3605,7 +3557,7 @@ static int spell_edit_score(slang_T *slang, const char *badword, const char *goo
}
}
- i = CNT(badlen - 1, goodlen - 1);
+ int i = CNT(badlen - 1, goodlen - 1);
xfree(cnt);
return i;
}
@@ -3633,10 +3585,8 @@ static int spell_edit_score_limit_w(slang_T *slang, const char *badword, const c
int limit)
{
limitscore_T stack[10]; // allow for over 3 * 2 edits
- int bi2, gi2;
int bc, gc;
int score_off;
- int round;
int wbadword[MAXWLEN];
int wgoodword[MAXWLEN];
@@ -3704,15 +3654,15 @@ static int spell_edit_score_limit_w(slang_T *slang, const char *badword, const c
// that may lead to a lower score than "minscore".
// round 0: try deleting a char from badword
// round 1: try inserting a char in badword
- for (round = 0; round <= 1; round++) {
+ for (int round = 0; round <= 1; round++) {
score_off = score + (round == 0 ? SCORE_DEL : SCORE_INS);
if (score_off < minscore) {
if (score_off + SCORE_EDIT_MIN >= minscore) {
// Near the limit, rest of the words must match. We
// can check that right now, no need to push an item
// onto the stack.
- bi2 = bi + 1 - round;
- gi2 = gi + round;
+ int bi2 = bi + 1 - round;
+ int gi2 = gi + round;
while (wgoodword[gi2] == wbadword[bi2]) {
if (wgoodword[gi2] == NUL) {
minscore = score_off;
diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c
index a99313cc4e..aa23d581e1 100644
--- a/src/nvim/statusline.c
+++ b/src/nvim/statusline.c
@@ -59,11 +59,8 @@ typedef enum {
/// If inversion is possible we use it. Else '=' characters are used.
void win_redr_status(win_T *wp)
{
- char *p;
- int len;
int fillchar;
int attr;
- int this_ru_col;
bool is_stl_global = global_stl_height() > 0;
static bool busy = false;
@@ -92,8 +89,8 @@ void win_redr_status(win_T *wp)
const int stl_width = is_stl_global ? Columns : wp->w_width;
get_trans_bufname(wp->w_buffer);
- p = NameBuff;
- len = (int)strlen(p);
+ char *p = NameBuff;
+ int len = (int)strlen(p);
if ((bt_help(wp->w_buffer)
|| wp->w_p_pvw
@@ -119,7 +116,7 @@ void win_redr_status(win_T *wp)
// len += (int)strlen(p + len); // dead assignment
}
- this_ru_col = ru_col - (Columns - stl_width);
+ int this_ru_col = ru_col - (Columns - stl_width);
if (this_ru_col < (stl_width + 1) / 2) {
this_ru_col = (stl_width + 1) / 2;
}
@@ -127,10 +124,10 @@ void win_redr_status(win_T *wp)
p = "<"; // No room for file name!
len = 1;
} else {
- int clen = 0, i;
+ int i;
// Count total number of display cells.
- clen = (int)mb_string2cells(p);
+ int clen = (int)mb_string2cells(p);
// Find first character that will fit.
// Going from start to end is much faster for DBCS.
@@ -295,7 +292,6 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler)
int row;
int col = 0;
int maxwidth;
- int n;
int fillchar;
char buf[MAXPATHL];
char transbuf[MAXPATHL];
@@ -422,7 +418,7 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler)
int curattr = attr;
char *p = buf;
- for (n = 0; hltab[n].start != NULL; n++) {
+ for (int n = 0; hltab[n].start != NULL; n++) {
int textlen = (int)(hltab[n].start - p);
// Make all characters printable.
size_t tsize = transstr_buf(p, textlen, transbuf, sizeof transbuf, true);
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index eb851a4c1b..4dda332b9f 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -2938,11 +2938,10 @@ void f_trim(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
}
- int c1;
if (dir == 0 || dir == 1) {
// Trim leading characters
while (*head != NUL) {
- c1 = utf_ptr2char(head);
+ int c1 = utf_ptr2char(head);
if (mask == NULL) {
if (c1 > ' ' && c1 != 0xa0) {
break;
@@ -2967,7 +2966,7 @@ void f_trim(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
for (; tail > head; tail = prev) {
prev = tail;
MB_PTR_BACK(head, prev);
- c1 = utf_ptr2char(prev);
+ int c1 = utf_ptr2char(prev);
if (mask == NULL) {
if (c1 > ' ' && c1 != 0xa0) {
break;
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index d83d58229f..12b0c8ce9b 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -309,8 +309,8 @@ void syntax_start(win_T *wp, linenr_T lnum)
{
synstate_T *last_valid = NULL;
synstate_T *last_min_valid = NULL;
- synstate_T *sp, *prev = NULL;
- linenr_T parsed_lnum;
+ synstate_T *sp;
+ synstate_T *prev = NULL;
linenr_T first_stored;
int dist;
static varnumber_T changedtick = 0; // remember the last change ID
@@ -425,7 +425,7 @@ void syntax_start(win_T *wp, linenr_T lnum)
if (sp != NULL
&& sp->sst_lnum == current_lnum
&& syn_stack_equal(sp)) {
- parsed_lnum = current_lnum;
+ linenr_T parsed_lnum = current_lnum;
prev = sp;
while (sp != NULL && sp->sst_change_lnum <= parsed_lnum) {
if (sp->sst_lnum <= lnum) {
@@ -907,9 +907,6 @@ void syn_stack_free_all(synblock_T *block)
// Also used to allocate b_sst_array[] for the first time.
static void syn_stack_alloc(void)
{
- synstate_T *to, *from;
- synstate_T *sstp;
-
int len = syn_buf->b_ml.ml_line_count / SST_DIST + Rows * 2;
if (len < SST_MIN_ENTRIES) {
len = SST_MIN_ENTRIES;
@@ -937,12 +934,12 @@ static void syn_stack_alloc(void)
}
assert(len >= 0);
- sstp = xcalloc((size_t)len, sizeof(synstate_T));
+ synstate_T *sstp = xcalloc((size_t)len, sizeof(synstate_T));
- to = sstp - 1;
+ synstate_T *to = sstp - 1;
if (syn_block->b_sst_array != NULL) {
// Move the states from the old array to the new one.
- for (from = syn_block->b_sst_first; from != NULL;
+ for (synstate_T *from = syn_block->b_sst_first; from != NULL;
from = from->sst_next) {
to++;
*to = *from;
@@ -988,16 +985,13 @@ void syn_stack_apply_changes(buf_T *buf)
static void syn_stack_apply_changes_block(synblock_T *block, buf_T *buf)
{
- synstate_T *p, *prev, *np;
- linenr_T n;
-
- prev = NULL;
- for (p = block->b_sst_first; p != NULL;) {
+ synstate_T *prev = NULL;
+ for (synstate_T *p = block->b_sst_first; p != NULL;) {
if (p->sst_lnum + block->b_syn_sync_linebreaks > buf->b_mod_top) {
- n = p->sst_lnum + buf->b_mod_xlines;
+ linenr_T n = p->sst_lnum + buf->b_mod_xlines;
if (n <= buf->b_mod_bot) {
// this state is inside the changed area, remove it
- np = p->sst_next;
+ synstate_T *np = p->sst_next;
if (prev == NULL) {
block->b_sst_first = np;
} else {
@@ -1260,7 +1254,6 @@ static void load_current_state(synstate_T *from)
static bool syn_stack_equal(synstate_T *sp)
{
bufstate_T *bp;
- reg_extmatch_T *six, *bsx;
// First a quick check if the stacks have the same size end nextlist.
if (sp->sst_stacksize != current_state.ga_len
@@ -1286,8 +1279,8 @@ static bool syn_stack_equal(synstate_T *sp)
}
// When the extmatch pointers are different, the strings in them can
// still be the same. Check if the extmatch references are equal.
- bsx = bp[i].bs_extmatch;
- six = CUR_STATE(i).si_extmatch;
+ reg_extmatch_T *bsx = bp[i].bs_extmatch;
+ reg_extmatch_T *six = CUR_STATE(i).si_extmatch;
// If one of the extmatch pointers is NULL the states are different.
if (bsx == NULL || six == NULL) {
break;
@@ -1498,7 +1491,8 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con
lpos_T eos_pos; // end-of-start match (start region)
lpos_T eoe_pos; // end-of-end pattern
int end_idx; // group ID for end pattern
- stateitem_T *cur_si, *sip = NULL;
+ stateitem_T *cur_si;
+ stateitem_T *sip = NULL;
int startcol;
int endcol;
int flags;
@@ -2355,9 +2349,7 @@ static void pop_current_state(void)
static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_endpos, int *flagsp,
lpos_T *end_endpos, int *end_idx, reg_extmatch_T *start_ext)
{
- colnr_T matchcol;
- synpat_T *spp, *spp_skip;
- int start_idx;
+ synpat_T *spp_skip;
int best_idx;
regmmatch_T regmatch;
regmmatch_T best_regmatch; // startpos/endpos of best match
@@ -2374,7 +2366,7 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_
// Check for being called with a START pattern.
// Can happen with a match that continues to the next line, because it
// contained a region.
- spp = &(SYN_ITEMS(syn_block)[idx]);
+ synpat_T *spp = &(SYN_ITEMS(syn_block)[idx]);
if (spp->sp_type != SPTYPE_START) {
*hl_endpos = *startpos;
return;
@@ -2401,8 +2393,8 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_
unref_extmatch(re_extmatch_in);
re_extmatch_in = ref_extmatch(start_ext);
- matchcol = startpos->col; // start looking for a match at sstart
- start_idx = idx; // remember the first END pattern.
+ colnr_T matchcol = startpos->col; // start looking for a match at sstart
+ int start_idx = idx; // remember the first END pattern.
best_regmatch.startpos[0].col = 0; // avoid compiler warning
// use syntax iskeyword option
@@ -3798,7 +3790,6 @@ static char *get_group_name(char *arg, char **name_end)
/// Return NULL for any error;
static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, int skip)
{
- char *gname_start, *gname;
int syn_id;
int len = 0;
char *p;
@@ -3905,12 +3896,12 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i
emsg(_("E393: group[t]here not accepted here"));
return NULL;
}
- gname_start = arg;
+ char *gname_start = arg;
arg = skiptowhite(arg);
if (gname_start == arg) {
return NULL;
}
- gname = xstrnsave(gname_start, (size_t)(arg - gname_start));
+ char *gname = xstrnsave(gname_start, (size_t)(arg - gname_start));
if (strcmp(gname, "NONE") == 0) {
*opt->sync_idx = NONE_IDX;
} else {
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index 198a4c51a1..a3ef7f31b6 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -286,10 +286,7 @@ void do_tag(char *tag, int type, int count, int forceit, int verbose)
int cur_fnum = curbuf->b_fnum;
int oldtagstackidx = tagstackidx;
int prevtagstackidx = tagstackidx;
- int prev_num_matches;
int new_tag = false;
- int i;
- int ic;
int no_regexp = false;
int error_cur_match = 0;
int save_pos = false;
@@ -328,7 +325,7 @@ void do_tag(char *tag, int type, int count, int forceit, int verbose)
use_tfu = 0;
}
- prev_num_matches = num_matches;
+ int prev_num_matches = num_matches;
free_string_option(nofile_fname);
nofile_fname = NULL;
@@ -377,7 +374,7 @@ void do_tag(char *tag, int type, int count, int forceit, int verbose)
if (++tagstacklen > TAGSTACKSIZE) {
tagstacklen = TAGSTACKSIZE;
tagstack_clear_entry(&tagstack[0]);
- for (i = 1; i < tagstacklen; i++) {
+ for (int i = 1; i < tagstacklen; i++) {
tagstack[i - 1] = tagstack[i];
}
tagstackidx--;
@@ -615,19 +612,18 @@ void do_tag(char *tag, int type, int count, int forceit, int verbose)
// to the start. Avoids that the order changes when using
// ":tnext" and jumping to another file.
if (!new_tag && !other_name) {
- int j, k;
int idx = 0;
tagptrs_T tagp, tagp2;
// Find the position of each old match in the new list. Need
// to use parse_match() to find the tag line.
- for (j = 0; j < num_matches; j++) {
+ for (int j = 0; j < num_matches; j++) {
parse_match(matches[j], &tagp);
- for (i = idx; i < new_num_matches; i++) {
+ for (int i = idx; i < new_num_matches; i++) {
parse_match(new_matches[i], &tagp2);
if (strcmp(tagp.tagname, tagp2.tagname) == 0) {
char *p = new_matches[i];
- for (k = i; k > idx; k--) {
+ for (int k = i; k > idx; k--) {
new_matches[k] = new_matches[k - 1];
}
new_matches[idx++] = p;
@@ -666,7 +662,7 @@ void do_tag(char *tag, int type, int count, int forceit, int verbose)
if (ask_for_selection) {
// Ask to select a tag from the list.
- i = prompt_for_number(NULL);
+ int i = prompt_for_number(NULL);
if (i <= 0 || i > num_matches || got_int) {
// no valid choice: don't change anything
if (use_tagstack) {
@@ -719,7 +715,7 @@ void do_tag(char *tag, int type, int count, int forceit, int verbose)
smsg(0, _("File \"%s\" does not exist"), nofile_fname);
}
- ic = (matches[cur_match][0] & MT_IC_OFF);
+ int ic = (matches[cur_match][0] & MT_IC_OFF);
if (type != DT_TAG && type != DT_SELECT && type != DT_JUMP
&& (num_matches > 1 || ic)
&& !skip_msg) {
@@ -749,7 +745,7 @@ void do_tag(char *tag, int type, int count, int forceit, int verbose)
set_vim_var_string(VV_SWAPCOMMAND, IObuff, -1);
// Jump to the desired match.
- i = jumpto_tag(matches[cur_match], forceit, true);
+ int i = jumpto_tag(matches[cur_match], forceit, true);
set_vim_var_string(VV_SWAPCOMMAND, NULL, -1);
@@ -799,16 +795,12 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char
{
taggy_T *tagstack = curwin->w_tagstack;
int tagstackidx = curwin->w_tagstackidx;
- const char *p;
- const char *command_end;
tagptrs_T tagp;
- int taglen;
- int attr;
// Assume that the first match indicates how long the tags can
// be, and align the file names to that.
parse_match(matches[0], &tagp);
- taglen = (int)(tagp.tagname_end - tagp.tagname + 2);
+ int taglen = (int)(tagp.tagname_end - tagp.tagname + 2);
if (taglen < 18) {
taglen = 18;
}
@@ -849,7 +841,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char
// Find out the actual file name. If it is long, truncate
// it and put "..." in the middle
- p = tag_full_fname(&tagp);
+ const char *p = tag_full_fname(&tagp);
if (p != NULL) {
msg_outtrans(p, HL_ATTR(HLF_D));
XFREE_CLEAR(p);
@@ -863,7 +855,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char
msg_advance(15);
// print any extra fields
- command_end = tagp.command_end;
+ const char *command_end = tagp.command_end;
if (command_end != NULL) {
p = command_end + 3;
while (*p && *p != '\r' && *p != '\n') {
@@ -884,7 +876,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char
continue;
}
// print all other extra fields
- attr = HL_ATTR(HLF_CM);
+ int attr = HL_ATTR(HLF_CM);
while (*p && *p != '\r' && *p != '\n') {
if (msg_col + ptr2cells(p) >= Columns) {
msg_putchar('\n');
@@ -980,7 +972,6 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char
static int add_llist_tags(char *tag, int num_matches, char **matches)
{
char tag_name[128 + 1];
- char *p;
tagptrs_T tagp;
char *fname = xmalloc(MAXPATHL + 1);
@@ -1001,7 +992,7 @@ static int add_llist_tags(char *tag, int num_matches, char **matches)
tag_name[len] = NUL;
// Save the tag file name
- p = tag_full_fname(&tagp);
+ char *p = tag_full_fname(&tagp);
if (p == NULL) {
continue;
}
@@ -1015,13 +1006,11 @@ static int add_llist_tags(char *tag, int num_matches, char **matches)
// Line number is used to locate the tag
lnum = atoi(tagp.command);
} else {
- char *cmd_start, *cmd_end;
-
// Search pattern is used to locate the tag
// Locate the end of the command
- cmd_start = tagp.command;
- cmd_end = tagp.command_end;
+ char *cmd_start = tagp.command;
+ char *cmd_end = tagp.command_end;
if (cmd_end == NULL) {
for (p = tagp.command;
*p && *p != '\r' && *p != '\n'; p++) {}
@@ -1118,7 +1107,6 @@ static void taglen_advance(int l)
// Print the tag stack
void do_tags(exarg_T *eap)
{
- char *name;
taggy_T *tagstack = curwin->w_tagstack;
int tagstackidx = curwin->w_tagstackidx;
int tagstacklen = curwin->w_tagstacklen;
@@ -1127,7 +1115,7 @@ void do_tags(exarg_T *eap)
msg_puts_title(_("\n # TO tag FROM line in file/text"));
for (int i = 0; i < tagstacklen; i++) {
if (tagstack[i].tagname != NULL) {
- name = fm_getname(&(tagstack[i].fmark), 30);
+ char *name = fm_getname(&(tagstack[i].fmark), 30);
if (name == NULL) { // file name not available
continue;
}
@@ -1217,10 +1205,7 @@ static void prepare_pats(pat_T *pats, int has_re)
/// @param buf_ffname name of buffer for priority
static int find_tagfunc_tags(char *pat, garray_T *ga, int *match_count, int flags, char *buf_ffname)
{
- pos_T save_pos;
- list_T *taglist;
int ntags = 0;
- int result = FAIL;
typval_T args[4];
typval_T rettv;
char flagString[4];
@@ -1264,8 +1249,8 @@ static int find_tagfunc_tags(char *pat, garray_T *ga, int *match_count, int flag
flags & TAG_INS_COMP ? "i" : "",
flags & TAG_REGEXP ? "r" : "");
- save_pos = curwin->w_cursor;
- result = callback_call(&curbuf->b_tfu_cb, 3, args, &rettv);
+ pos_T save_pos = curwin->w_cursor;
+ int result = callback_call(&curbuf->b_tfu_cb, 3, args, &rettv);
curwin->w_cursor = save_pos; // restore the cursor position
d->dv_refcount--;
@@ -1281,7 +1266,7 @@ static int find_tagfunc_tags(char *pat, garray_T *ga, int *match_count, int flag
emsg(_(e_invalid_return_value_from_tagfunc));
return FAIL;
}
- taglist = rettv.vval.v_list;
+ list_T *taglist = rettv.vval.v_list;
TV_LIST_ITER_CONST(taglist, li, {
char *res_name;
@@ -1544,11 +1529,10 @@ static int findtags_apply_tfu(findtags_state_T *st, char *pat, char *buf_ffname)
static tags_read_status_T findtags_get_next_line(findtags_state_T *st, tagsearch_info_T *sinfo_p)
{
int eof;
- off_T offset;
// For binary search: compute the next offset to use.
if (st->state == TS_BINARY) {
- offset = sinfo_p->low_offset + ((sinfo_p->high_offset - sinfo_p->low_offset) / 2);
+ off_T offset = sinfo_p->low_offset + ((sinfo_p->high_offset - sinfo_p->low_offset) / 2);
if (offset == sinfo_p->curr_offset) {
return TAGS_READ_EOF; // End the binary search without a match.
} else {
@@ -1951,8 +1935,6 @@ static void findtags_add_match(findtags_state_T *st, tagptrs_T *tagpp, findtags_
bool is_current; // file name matches
bool is_static; // current tag line is static
char *mfp;
- char *p;
- char *s;
// Decide in which array to store this match.
is_current = test_for_current(tagpp->fname, tagpp->fname_end,
@@ -1994,7 +1976,7 @@ static void findtags_add_match(findtags_state_T *st, tagptrs_T *tagpp, findtags_
mfp_size = sizeof(char) + len + 10 + ML_EXTRA + 1;
mfp = xmalloc(mfp_size);
- p = mfp;
+ char *p = mfp;
STRCPY(p, tagpp->tagname);
p[len] = '@';
STRCPY(p + len + 1, st->help_lang);
@@ -2045,7 +2027,7 @@ static void findtags_add_match(findtags_state_T *st, tagptrs_T *tagpp, findtags_
// Here <mtt> is the "mtt" value plus 1 to avoid NUL.
len = tag_fname_len + strlen(st->lbuf) + 3;
mfp = xmalloc(sizeof(char) + len + 1);
- p = mfp;
+ char *p = mfp;
p[0] = (char)(mtt + 1);
STRCPY(p + 1, st->tag_fname);
#ifdef BACKSLASH_IN_FILENAME
@@ -2054,7 +2036,7 @@ static void findtags_add_match(findtags_state_T *st, tagptrs_T *tagpp, findtags_
slash_adjust(p + 1);
#endif
p[tag_fname_len + 1] = TAG_SEP;
- s = p + 1 + tag_fname_len + 1;
+ char *s = p + 1 + tag_fname_len + 1;
STRCPY(s, st->lbuf);
}
@@ -2086,7 +2068,6 @@ static void findtags_get_all_tags(findtags_state_T *st, findtags_match_args_T *m
{
tagptrs_T tagp;
tagsearch_info_T search_info;
- int retval;
hash_T hash = 0;
// This is only to avoid a compiler warning for using search_info
@@ -2118,7 +2099,7 @@ static void findtags_get_all_tags(findtags_state_T *st, findtags_match_args_T *m
goto line_read_in;
}
- retval = (int)findtags_get_next_line(st, &search_info);
+ int retval = (int)findtags_get_next_line(st, &search_info);
if (retval == TAGS_READ_IGNORE) {
continue;
}
@@ -2242,9 +2223,6 @@ static int findtags_copy_matches(findtags_state_T *st, char ***matchesp)
{
const bool name_only = (st->flags & TAG_NAMES);
char **matches;
- int mtt;
- char *mfp;
- char *p;
if (st->match_count > 0) {
matches = xmalloc((size_t)st->match_count * sizeof(char *));
@@ -2252,9 +2230,9 @@ static int findtags_copy_matches(findtags_state_T *st, char ***matchesp)
matches = NULL;
}
st->match_count = 0;
- for (mtt = 0; mtt < MT_COUNT; mtt++) {
+ for (int mtt = 0; mtt < MT_COUNT; mtt++) {
for (int i = 0; i < st->ga_match[mtt].ga_len; i++) {
- mfp = ((char **)(st->ga_match[mtt].ga_data))[i];
+ char *mfp = ((char **)(st->ga_match[mtt].ga_data))[i];
if (matches == NULL) {
xfree(mfp);
} else {
@@ -2263,7 +2241,7 @@ static int findtags_copy_matches(findtags_state_T *st, char ***matchesp)
*mfp = (char)(*mfp - 1);
// change the TAG_SEP back to NUL
- for (p = mfp + 1; *p != NUL; p++) {
+ for (char *p = mfp + 1; *p != NUL; p++) {
if (*p == TAG_SEP) {
*p = NUL;
}
@@ -2319,11 +2297,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc
tagname_T tn; // info for get_tagfname()
int first_file; // trying first tag file
int retval = FAIL; // return value
- int round;
-
- int save_emsg_off;
- int help_save;
int i;
char *saved_pat = NULL; // copy of pat[]
@@ -2354,7 +2328,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc
abort();
}
- help_save = curbuf->b_help;
+ int help_save = curbuf->b_help;
findtags_state_init(&st, pat, flags, mincount);
@@ -2379,7 +2353,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc
st.orgpat->len = (int)p_tl;
}
- save_emsg_off = emsg_off;
+ int save_emsg_off = emsg_off;
emsg_off = true; // don't want error for invalid RE here
prepare_pats(st.orgpat, has_re);
emsg_off = save_emsg_off;
@@ -2414,7 +2388,7 @@ int find_tags(char *pat, int *num_matches, char ***matchesp, int flags, int minc
// Only ignore case when TAG_NOIC not used or 'ignorecase' set.
st.orgpat->regmatch.rm_ic = ((p_ic || !noic)
&& (findall || st.orgpat->headlen == 0 || !p_tbs));
- for (round = 1; round <= 2; round++) {
+ for (int round = 1; round <= 2; round++) {
st.linear = (st.orgpat->headlen == 0 || !p_tbs || round == 2);
// Try tag file names from tags option one by one.
@@ -2513,7 +2487,6 @@ void free_tag_stuff(void)
int get_tagfname(tagname_T *tnp, int first, char *buf)
{
char *fname = NULL;
- char *r_ptr;
if (first) {
CLEAR_POINTER(tnp);
@@ -2588,7 +2561,7 @@ int get_tagfname(tagname_T *tnp, int first, char *buf)
buf[0] = NUL;
(void)copy_option_part(&tnp->tn_np, buf, MAXPATHL - 1, " ,");
- r_ptr = vim_findfile_stopdir(buf);
+ char *r_ptr = vim_findfile_stopdir(buf);
// move the filename one char forward and truncate the
// filepath with a NUL
filename = path_tail(buf);
@@ -2630,11 +2603,9 @@ void tagname_free(tagname_T *tnp)
/// @return FAIL if there is a format error in this line, OK otherwise.
static int parse_tag_line(char *lbuf, tagptrs_T *tagp)
{
- char *p;
-
// Isolate the tagname, from lbuf up to the first white
tagp->tagname = lbuf;
- p = vim_strchr(lbuf, TAB);
+ char *p = vim_strchr(lbuf, TAB);
if (p == NULL) {
return FAIL;
}
@@ -2677,10 +2648,8 @@ static int parse_tag_line(char *lbuf, tagptrs_T *tagp)
// Return false if it is not a static tag.
static bool test_for_static(tagptrs_T *tagp)
{
- char *p;
-
// Check for new style static tag ":...<Tab>file:[<Tab>...]"
- p = tagp->command;
+ char *p = tagp->command;
while ((p = vim_strchr(p, '\t')) != NULL) {
p++;
if (strncmp(p, "file:", 5) == 0) {
@@ -2714,15 +2683,11 @@ static size_t matching_line_len(const char *const lbuf)
/// @return OK or FAIL.
static int parse_match(char *lbuf, tagptrs_T *tagp)
{
- int retval;
- char *p;
- char *pt;
-
tagp->tag_fname = lbuf + 1;
lbuf += strlen(tagp->tag_fname) + 2;
// Find search pattern and the file name for non-etags.
- retval = parse_tag_line(lbuf, tagp);
+ int retval = parse_tag_line(lbuf, tagp);
tagp->tagkind = NULL;
tagp->user_data = NULL;
@@ -2734,7 +2699,7 @@ static int parse_match(char *lbuf, tagptrs_T *tagp)
}
// Try to find a kind field: "kind:<kind>" or just "<kind>"
- p = tagp->command;
+ char *p = tagp->command;
if (find_extra(&p) == OK) {
tagp->command_end = p;
if (p > tagp->command && p[-1] == '|') {
@@ -2757,7 +2722,7 @@ static int parse_match(char *lbuf, tagptrs_T *tagp)
}
char *pc = vim_strchr(p, ':');
- pt = vim_strchr(p, '\t');
+ char *pt = vim_strchr(p, '\t');
if (pc == NULL || (pt != NULL && pc > pt)) {
tagp->tagkind = p;
}
@@ -2806,14 +2771,8 @@ static char *tag_full_fname(tagptrs_T *tagp)
/// @return OK for success, NOTAGFILE when file not found, FAIL otherwise.
static int jumpto_tag(const char *lbuf_arg, int forceit, int keep_help)
{
- bool save_p_ws;
- int save_p_scs, save_p_ic;
- linenr_T save_lnum;
- char *str;
- char *pbuf; // search pattern buffer
char *pbuf_end;
char *tofree_fname = NULL;
- char *fname;
tagptrs_T tagp;
int retval = FAIL;
int getfile_result = GETFILE_UNUSED;
@@ -2826,7 +2785,7 @@ static int jumpto_tag(const char *lbuf_arg, int forceit, int keep_help)
char *lbuf = xmalloc(len);
memmove(lbuf, lbuf_arg, len);
- pbuf = xmalloc(LSIZE);
+ char *pbuf = xmalloc(LSIZE); // search pattern buffer
// parse the match line into the tagp structure
if (parse_match(lbuf, &tagp) == FAIL) {
@@ -2836,10 +2795,10 @@ static int jumpto_tag(const char *lbuf_arg, int forceit, int keep_help)
// truncate the file name, so it can be used as a string
*tagp.fname_end = NUL;
- fname = tagp.fname;
+ char *fname = tagp.fname;
// copy the command to pbuf[], remove trailing CR/NL
- str = tagp.command;
+ char *str = tagp.command;
for (pbuf_end = pbuf; *str && *str != '\n' && *str != '\r';) {
*pbuf_end++ = *str++;
if (pbuf_end - pbuf + 1 >= LSIZE) {
@@ -2962,13 +2921,13 @@ static int jumpto_tag(const char *lbuf_arg, int forceit, int keep_help)
str = skip_regexp(pbuf + 1, pbuf[0], false) + 1;
}
if (str > pbuf_end - 1) { // search command with nothing following
- save_p_ws = p_ws;
- save_p_ic = p_ic;
- save_p_scs = p_scs;
+ bool save_p_ws = p_ws;
+ int save_p_ic = p_ic;
+ int save_p_scs = p_scs;
p_ws = true; // need 'wrapscan' for backward searches
p_ic = false; // don't ignore case now
p_scs = false;
- save_lnum = curwin->w_cursor.lnum;
+ linenr_T save_lnum = curwin->w_cursor.lnum;
if (tagp.tagline > 0) {
// start search before line from "line:" field
curwin->w_cursor.lnum = tagp.tagline - 1;
@@ -3210,12 +3169,11 @@ static void tagstack_clear_entry(taggy_T *item)
int expand_tags(int tagnames, char *pat, int *num_file, char ***file)
{
int extra_flag;
- char *name_buf;
size_t name_buf_size = 100;
tagptrs_T t_p;
int ret;
- name_buf = xmalloc(name_buf_size);
+ char *name_buf = xmalloc(name_buf_size);
if (tagnames) {
extra_flag = TAG_NAMES;
@@ -3270,7 +3228,6 @@ static int add_tag_field(dict_T *dict, const char *field_name, const char *start
FUNC_ATTR_NONNULL_ARG(1, 2)
{
int len = 0;
- int retval;
// Check that the field name doesn't exist yet.
if (tv_dict_find(dict, field_name, -1) != NULL) {
@@ -3296,7 +3253,7 @@ static int add_tag_field(dict_T *dict, const char *field_name, const char *start
xstrlcpy(buf, start, (size_t)len + 1);
}
buf[len] = NUL;
- retval = tv_dict_add_str(dict, field_name, strlen(field_name), buf);
+ int retval = tv_dict_add_str(dict, field_name, strlen(field_name), buf);
xfree(buf);
return retval;
}
@@ -3305,19 +3262,16 @@ static int add_tag_field(dict_T *dict, const char *field_name, const char *start
/// as a dictionary. Use "buf_fname" for priority, unless NULL.
int get_tags(list_T *list, char *pat, char *buf_fname)
{
- int num_matches, i, ret;
+ int num_matches;
char **matches;
- char *full_fname;
- dict_T *dict;
tagptrs_T tp;
- ret = find_tags(pat, &num_matches, &matches,
- TAG_REGEXP | TAG_NOIC, MAXCOL, buf_fname);
+ int ret = find_tags(pat, &num_matches, &matches, TAG_REGEXP | TAG_NOIC, MAXCOL, buf_fname);
if (ret != OK || num_matches <= 0) {
return ret;
}
- for (i = 0; i < num_matches; i++) {
+ for (int i = 0; i < num_matches; i++) {
if (parse_match(matches[i], &tp) == FAIL) {
xfree(matches[i]);
continue;
@@ -3331,10 +3285,10 @@ int get_tags(list_T *list, char *pat, char *buf_fname)
continue;
}
- dict = tv_dict_alloc();
+ dict_T *dict = tv_dict_alloc();
tv_list_append_dict(list, dict);
- full_fname = tag_full_fname(&tp);
+ char *full_fname = tag_full_fname(&tp);
if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL
|| add_tag_field(dict, "filename", full_fname, NULL) == FAIL
|| add_tag_field(dict, "cmd", tp.command, tp.command_end) == FAIL
@@ -3400,9 +3354,6 @@ int get_tags(list_T *list, char *pat, char *buf_fname)
// Return information about 'tag' in dict 'retdict'.
static void get_tag_details(taggy_T *tag, dict_T *retdict)
{
- list_T *pos;
- fmark_T *fmark;
-
tv_dict_add_str(retdict, S_LEN("tagname"), tag->tagname);
tv_dict_add_nr(retdict, S_LEN("matchnr"), tag->cur_match + 1);
tv_dict_add_nr(retdict, S_LEN("bufnr"), tag->cur_fnum);
@@ -3410,10 +3361,10 @@ static void get_tag_details(taggy_T *tag, dict_T *retdict)
tv_dict_add_str(retdict, S_LEN("user_data"), tag->user_data);
}
- pos = tv_list_alloc(4);
+ list_T *pos = tv_list_alloc(4);
tv_dict_add_list(retdict, S_LEN("from"), pos);
- fmark = &tag->fmark;
+ fmark_T *fmark = &tag->fmark;
tv_list_append_number(pos,
(varnumber_T)(fmark->fnum != -1 ? fmark->fnum : 0));
tv_list_append_number(pos, (varnumber_T)fmark->mark.lnum);
@@ -3489,20 +3440,18 @@ static void tagstack_push_item(win_T *wp, char *tagname, int cur_fnum, int cur_m
/// Add a list of items to the tag stack in the specified window
static void tagstack_push_items(win_T *wp, list_T *l)
{
- listitem_T *li;
dictitem_T *di;
- dict_T *itemdict;
char *tagname;
pos_T mark;
int fnum;
// Add one entry at a time to the tag stack
- for (li = tv_list_first(l); li != NULL; li = TV_LIST_ITEM_NEXT(l, li)) {
+ for (listitem_T *li = tv_list_first(l); li != NULL; li = TV_LIST_ITEM_NEXT(l, li)) {
if (TV_LIST_ITEM_TV(li)->v_type != VAR_DICT
|| TV_LIST_ITEM_TV(li)->vval.v_dict == NULL) {
continue; // Skip non-dict items
}
- itemdict = TV_LIST_ITEM_TV(li)->vval.v_dict;
+ dict_T *itemdict = TV_LIST_ITEM_TV(li)->vval.v_dict;
// parse 'from' for the cursor position before the tag jump
if ((di = tv_dict_find(itemdict, "from", -1)) == NULL) {
diff --git a/src/nvim/testing.c b/src/nvim/testing.c
index f5609a3fb2..d5bb5171fa 100644
--- a/src/nvim/testing.c
+++ b/src/nvim/testing.c
@@ -153,7 +153,6 @@ static void ga_concat_shorten_esc(garray_T *gap, const char *str)
static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, const char *exp_str,
typval_T *exp_tv_arg, typval_T *got_tv_arg, assert_type_T atype)
{
- char *tofree;
typval_T *exp_tv = exp_tv_arg;
typval_T *got_tv = got_tv_arg;
bool did_copy = false;
@@ -163,7 +162,7 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, const char *e
&& !(opt_msg_tv->v_type == VAR_STRING
&& (opt_msg_tv->vval.v_string == NULL
|| *opt_msg_tv->vval.v_string == NUL))) {
- tofree = encode_tv2echo(opt_msg_tv, NULL);
+ char *tofree = encode_tv2echo(opt_msg_tv, NULL);
ga_concat(gap, tofree);
xfree(tofree);
ga_concat(gap, ": ");
@@ -224,7 +223,7 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, const char *e
}
}
- tofree = encode_tv2string(exp_tv, NULL);
+ char *tofree = encode_tv2string(exp_tv, NULL);
ga_concat_shorten_esc(gap, tofree);
xfree(tofree);
} else {
@@ -245,7 +244,7 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, const char *e
} else {
ga_concat(gap, " but got ");
}
- tofree = encode_tv2string(got_tv, NULL);
+ char *tofree = encode_tv2string(got_tv, NULL);
ga_concat_shorten_esc(gap, tofree);
xfree(tofree);
diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c
index 58037fef36..bf7044c663 100644
--- a/src/nvim/textformat.c
+++ b/src/nvim/textformat.c
@@ -516,9 +516,8 @@ static bool ends_in_white(linenr_T lnum)
static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int leader2_len,
char *leader2_flags)
{
- int idx1 = 0, idx2 = 0;
- char *line1;
- char *line2;
+ int idx1 = 0;
+ int idx2 = 0;
if (leader1_len == 0) {
return leader2_len == 0;
@@ -557,9 +556,9 @@ static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int
// Get current line and next line, compare the leaders.
// The first line has to be saved, only one line can be locked at a time.
- line1 = xstrdup(ml_get(lnum));
+ char *line1 = xstrdup(ml_get(lnum));
for (idx1 = 0; ascii_iswhite(line1[idx1]); idx1++) {}
- line2 = ml_get(lnum + 1);
+ char *line2 = ml_get(lnum + 1);
for (idx2 = 0; idx2 < leader2_len; idx2++) {
if (!ascii_iswhite(line2[idx2])) {
if (line1[idx1++] != line2[idx2]) {
@@ -582,7 +581,6 @@ static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int
/// false when the previous line is in the same paragraph.
static bool paragraph_start(linenr_T lnum)
{
- char *p;
int leader_len = 0; // leader len of current line
char *leader_flags = NULL; // flags for leader of current line
int next_leader_len = 0; // leader len of next line
@@ -591,7 +589,7 @@ static bool paragraph_start(linenr_T lnum)
if (lnum <= 1) {
return true; // start of the file
}
- p = ml_get(lnum - 1);
+ char *p = ml_get(lnum - 1);
if (*p == NUL) {
return true; // after empty line
}
diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c
index 00038c7d6d..a0a33b17a3 100644
--- a/src/nvim/textobject.c
+++ b/src/nvim/textobject.c
@@ -38,12 +38,11 @@
/// text object.
int findsent(Direction dir, int count)
{
- pos_T pos, tpos;
int c;
int (*func)(pos_T *);
bool noskip = false; // do not skip blanks
- pos = curwin->w_cursor;
+ pos_T pos = curwin->w_cursor;
if (dir == FORWARD) {
func = incl;
} else {
@@ -80,7 +79,7 @@ int findsent(Direction dir, int count)
bool found_dot = false;
while (c = gchar_pos(&pos), ascii_iswhite(c)
|| vim_strchr(".!?)]\"'", c) != NULL) {
- tpos = pos;
+ pos_T tpos = pos;
if (decl(&tpos) == -1 || (LINEEMPTY(tpos.lnum) && dir == FORWARD)) {
break;
}
@@ -110,7 +109,7 @@ int findsent(Direction dir, int count)
break;
}
if (c == '.' || c == '!' || c == '?') {
- tpos = pos;
+ pos_T tpos = pos;
do {
if ((c = inc(&tpos)) == -1) {
break;
@@ -888,17 +887,14 @@ extend:
/// @param other ')', '}', etc.
int current_block(oparg_T *oap, int count, bool include, int what, int other)
{
- pos_T old_pos;
pos_T *pos = NULL;
pos_T start_pos;
pos_T *end_pos;
- pos_T old_start, old_end;
- char *save_cpo;
bool sol = false; // '{' at start of line
- old_pos = curwin->w_cursor;
- old_end = curwin->w_cursor; // remember where we started
- old_start = old_end;
+ pos_T old_pos = curwin->w_cursor;
+ pos_T old_end = curwin->w_cursor; // remember where we started
+ pos_T old_start = old_end;
// If we start on '(', '{', ')', '}', etc., use the whole block inclusive.
if (!VIsual_active || equalpos(VIsual, curwin->w_cursor)) {
@@ -925,7 +921,7 @@ int current_block(oparg_T *oap, int count, bool include, int what, int other)
// Put this position in start_pos.
// Ignore quotes here. Keep the "M" flag in 'cpo', as that is what the
// user wants.
- save_cpo = p_cpo;
+ char *save_cpo = p_cpo;
p_cpo = vim_strchr(p_cpo, CPO_MATCHBSL) != NULL ? "%M" : "%";
if ((pos = findmatch(NULL, what)) != NULL) {
while (count-- > 0) {
@@ -1080,13 +1076,7 @@ static bool in_html_tag(bool end_tag)
int current_tagblock(oparg_T *oap, int count_arg, bool include)
{
int count = count_arg;
- pos_T old_pos;
- pos_T start_pos;
- pos_T end_pos;
- pos_T old_start, old_end;
- char *p;
char *cp;
- int len;
bool do_include = include;
bool save_p_ws = p_ws;
int retval = FAIL;
@@ -1094,9 +1084,9 @@ int current_tagblock(oparg_T *oap, int count_arg, bool include)
p_ws = false;
- old_pos = curwin->w_cursor;
- old_end = curwin->w_cursor; // remember where we started
- old_start = old_end;
+ pos_T old_pos = curwin->w_cursor;
+ pos_T old_end = curwin->w_cursor; // remember where we started
+ pos_T old_start = old_end;
if (!VIsual_active || *p_sel == 'e') {
decl(&old_end); // old_end is inclusive
}
@@ -1148,15 +1138,15 @@ again:
goto theend;
}
}
- start_pos = curwin->w_cursor;
+ pos_T start_pos = curwin->w_cursor;
// Search for matching "</aaa>". First isolate the "aaa".
inc_cursor();
- p = get_cursor_pos_ptr();
+ char *p = get_cursor_pos_ptr();
for (cp = p;
*cp != NUL && *cp != '>' && !ascii_iswhite(*cp);
MB_PTR_ADV(cp)) {}
- len = (int)(cp - p);
+ int len = (int)(cp - p);
if (len == 0) {
curwin->w_cursor = old_pos;
goto theend;
@@ -1202,7 +1192,7 @@ again:
dec_cursor();
}
}
- end_pos = curwin->w_cursor;
+ pos_T end_pos = curwin->w_cursor;
if (!do_include) {
// Exclude the start tag.
@@ -1263,22 +1253,15 @@ theend:
/// @param type 'p' for paragraph, 'S' for section
int current_par(oparg_T *oap, int count, bool include, int type)
{
- linenr_T start_lnum;
- linenr_T end_lnum;
- int white_in_front;
int dir;
- int start_is_white;
- int prev_start_is_white;
int retval = OK;
int do_white = false;
- int t;
- int i;
if (type == 'S') { // not implemented yet
return FAIL;
}
- start_lnum = curwin->w_cursor.lnum;
+ linenr_T start_lnum = curwin->w_cursor.lnum;
// When visual area is more than one line: extend it.
if (VIsual_active && start_lnum != VIsual.lnum) {
@@ -1288,17 +1271,17 @@ extend:
} else {
dir = FORWARD;
}
- for (i = count; --i >= 0;) {
+ for (int i = count; --i >= 0;) {
if (start_lnum ==
(dir == BACKWARD ? 1 : curbuf->b_ml.ml_line_count)) {
retval = FAIL;
break;
}
- prev_start_is_white = -1;
- for (t = 0; t < 2; t++) {
+ int prev_start_is_white = -1;
+ for (int t = 0; t < 2; t++) {
start_lnum += dir;
- start_is_white = linewhite(start_lnum);
+ int start_is_white = linewhite(start_lnum);
if (prev_start_is_white == start_is_white) {
start_lnum -= dir;
break;
@@ -1332,7 +1315,7 @@ extend:
}
// First move back to the start_lnum of the paragraph or white lines
- white_in_front = linewhite(start_lnum);
+ int white_in_front = linewhite(start_lnum);
while (start_lnum > 1) {
if (white_in_front) { // stop at first white line
if (!linewhite(start_lnum - 1)) {
@@ -1347,13 +1330,13 @@ extend:
}
// Move past the end of any white lines.
- end_lnum = start_lnum;
+ linenr_T end_lnum = start_lnum;
while (end_lnum <= curbuf->b_ml.ml_line_count && linewhite(end_lnum)) {
end_lnum++;
}
end_lnum--;
- i = count;
+ int i = count;
if (!include && white_in_front) {
i--;
}
diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c
index 2c586e3e22..b1751f32fd 100644
--- a/src/nvim/ui_compositor.c
+++ b/src/nvim/ui_compositor.c
@@ -314,7 +314,6 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag
sattr_T *bg_attrs = &default_grid.attrs[default_grid.line_offset[row]
+ (size_t)startcol];
- int grid_width, grid_height;
while (col < endcol) {
int until = 0;
for (size_t i = 0; i < kv_size(layers); i++) {
@@ -324,8 +323,8 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag
// first check to see if any grids have pending updates to width/height,
// to ensure that we don't accidentally put any characters into `linebuf`
// that have been invalidated.
- grid_width = MIN(g->cols, g->comp_width);
- grid_height = MIN(g->rows, g->comp_height);
+ int grid_width = MIN(g->cols, g->comp_width);
+ int grid_height = MIN(g->rows, g->comp_height);
if (g->comp_row > row || row >= g->comp_row + grid_height
|| g->comp_disabled) {
continue;
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index 99ea5d238c..fa778b6803 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -2931,8 +2931,6 @@ static void u_freebranch(buf_T *buf, u_header_T *uhp, u_header_T **uhpp)
/// @param uhpp if not NULL reset when freeing this header
static void u_freeentries(buf_T *buf, u_header_T *uhp, u_header_T **uhpp)
{
- u_entry_T *uep, *nuep;
-
// Check for pointers to the header that become invalid now.
if (buf->b_u_curhead == uhp) {
buf->b_u_curhead = NULL;
@@ -2944,7 +2942,8 @@ static void u_freeentries(buf_T *buf, u_header_T *uhp, u_header_T **uhpp)
*uhpp = NULL;
}
- for (uep = uhp->uh_entry; uep != NULL; uep = nuep) {
+ u_entry_T *nuep;
+ for (u_entry_T *uep = uhp->uh_entry; uep != NULL; uep = nuep) {
nuep = uep->ue_next;
u_freeentry(uep, uep->ue_size);
}
diff --git a/src/nvim/version.c b/src/nvim/version.c
index abcb9d94d2..0f50fa1ff8 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -2492,14 +2492,13 @@ bool has_nvim_version(const char *const version_str)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
const char *p = version_str;
- int major = 0;
int minor = 0;
int patch = 0;
if (!ascii_isdigit(*p)) {
return false;
}
- major = atoi(p);
+ int major = atoi(p);
p = strchr(p, '.'); // Find the next dot.
if (p) {
@@ -2618,8 +2617,7 @@ void list_in_columns(char **items, int size, int current)
int width = 0;
// Find the length of the longest item, use that + 1 as the column width.
- int i;
- for (i = 0; size < 0 ? items[i] != NULL : i < size; i++) {
+ for (int i = 0; size < 0 ? items[i] != NULL : i < size; i++) {
int l = vim_strsize(items[i]) + (i == current ? 2 : 0);
if (l > width) {
@@ -2631,7 +2629,7 @@ void list_in_columns(char **items, int size, int current)
if (Columns < width) {
// Not enough screen columns - show one per line
- for (i = 0; i < item_count; i++) {
+ for (int i = 0; i < item_count; i++) {
version_msg_wrap(items[i], i == current);
if (msg_col > 0 && i < item_count - 1) {
msg_putchar('\n');
@@ -2647,7 +2645,7 @@ void list_in_columns(char **items, int size, int current)
int cur_row = 1;
// "i" counts columns then rows. "idx" counts rows then columns.
- for (i = 0; !got_int && i < nrow * ncol; i++) {
+ for (int i = 0; !got_int && i < nrow * ncol; i++) {
int idx = (i / ncol) + (i % ncol) * nrow;
if (idx < item_count) {
int last_col = (i + 1) % ncol == 0;