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(¤t_grid, ¤t_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 : 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 "" or "" 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, "", 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(®match, curwin, curbuf, lnum, 0, NULL, NULL); + int match = vim_regexec_multi(®match, 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(®match, curwin, curbuf, lnum, 0, NULL, NULL); + int match = vim_regexec_multi(®match, 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, "