diff options
author | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2023-02-11 14:14:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-11 14:14:24 +0100 |
commit | 27177e581902967dcf4f2f426464da1b636ca420 (patch) | |
tree | ba52f1e21ad2c4d4a00dc4af9fa602ae27bb86df | |
parent | 224a3c77caa6fea8299eb3be326fa6ff7300a21b (diff) | |
download | rneovim-27177e581902967dcf4f2f426464da1b636ca420.tar.gz rneovim-27177e581902967dcf4f2f426464da1b636ca420.tar.bz2 rneovim-27177e581902967dcf4f2f426464da1b636ca420.zip |
refactor: reduce scope of locals as per the style guide (#22211)
-rw-r--r-- | src/nvim/cmdexpand.c | 26 | ||||
-rw-r--r-- | src/nvim/drawscreen.c | 5 | ||||
-rw-r--r-- | src/nvim/eval/userfunc.c | 12 | ||||
-rw-r--r-- | src/nvim/eval/vars.c | 16 | ||||
-rw-r--r-- | src/nvim/grid.c | 23 | ||||
-rw-r--r-- | src/nvim/input.c | 6 | ||||
-rw-r--r-- | src/nvim/lua/executor.c | 3 | ||||
-rw-r--r-- | src/nvim/lua/spell.c | 3 | ||||
-rw-r--r-- | src/nvim/main.c | 9 | ||||
-rw-r--r-- | src/nvim/mark.c | 3 | ||||
-rw-r--r-- | src/nvim/match.c | 3 | ||||
-rw-r--r-- | src/nvim/memfile.c | 6 | ||||
-rw-r--r-- | src/nvim/memline.c | 37 | ||||
-rw-r--r-- | src/nvim/menu.c | 6 | ||||
-rw-r--r-- | src/nvim/message.c | 19 | ||||
-rw-r--r-- | src/nvim/move.c | 2 | ||||
-rw-r--r-- | src/nvim/normal.c | 33 | ||||
-rw-r--r-- | src/nvim/option.c | 3 | ||||
-rw-r--r-- | src/nvim/optionstr.c | 3 | ||||
-rw-r--r-- | src/nvim/plines.c | 15 | ||||
-rw-r--r-- | src/nvim/runtime.c | 6 | ||||
-rw-r--r-- | src/nvim/sign.c | 18 | ||||
-rw-r--r-- | src/nvim/spellsuggest.c | 151 | ||||
-rw-r--r-- | src/nvim/tag.c | 49 | ||||
-rw-r--r-- | src/nvim/textobject.c | 37 |
25 files changed, 177 insertions, 317 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 64e5664f1f..97feab2978 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -222,10 +222,8 @@ static void ExpandEscape(expand_T *xp, char *str, int numfiles, char **files, in int nextwild(expand_T *xp, int type, int options, bool escape) { CmdlineInfo *const ccline = get_cmdline_info(); - int i, j; - char *p1; + int i; char *p2; - int difflen; if (xp->xp_numfiles == -1) { set_expand_context(xp); @@ -258,6 +256,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape) // Get next/previous match for a previous expanded pattern. p2 = ExpandOne(xp, NULL, NULL, 0, type); } else { + char *p1; if (cmdline_fuzzy_completion_supported(xp)) { // If fuzzy matching, don't modify the search string p1 = xstrdup(xp->xp_pattern); @@ -282,6 +281,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape) // Longest match: make sure it is not shorter, happens with :help. if (p2 != NULL && type == WILD_LONGEST) { + int j; for (j = 0; (size_t)j < xp->xp_pattern_len; j++) { if (ccline->cmdbuff[i + j] == '*' || ccline->cmdbuff[i + j] == '?') { @@ -295,7 +295,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape) } if (p2 != NULL && !got_int) { - difflen = (int)strlen(p2) - (int)(xp->xp_pattern_len); + int difflen = (int)strlen(p2) - (int)(xp->xp_pattern_len); if (ccline->cmdlen + difflen + 4 > ccline->cmdbufflen) { realloc_cmdbuff(ccline->cmdlen + difflen + 4); xp->xp_pattern = ccline->cmdbuff + i; @@ -454,8 +454,6 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m char *selend = NULL; static int first_match = 0; bool add_left = false; - char *s; - int emenu; int l; if (matches == NULL) { // interrupted completion? @@ -528,10 +526,9 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m selstart_col = clen; } - s = SHOW_MATCH(i); + char *s = SHOW_MATCH(i); // Check for menu separators - replace with '|' - emenu = (xp->xp_context == EXPAND_MENUS - || xp->xp_context == EXPAND_MENUNAMES); + int emenu = (xp->xp_context == EXPAND_MENUS || xp->xp_context == EXPAND_MENUNAMES); if (emenu && menu_is_separator(s)) { STRCPY(buf + len, transchar('|')); l = (int)strlen(buf + len); @@ -847,7 +844,6 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) static int findex; static char *orig_save = NULL; // kept value of orig int orig_saved = false; - int i; // first handle the case of using an old match if (mode == WILD_NEXT || mode == WILD_PREV @@ -900,12 +896,12 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) // TODO(philix): use xstpcpy instead of strcat in a loop (ExpandOne) if (mode == WILD_ALL && xp->xp_numfiles > 0 && !got_int) { size_t len = 0; - for (i = 0; i < xp->xp_numfiles; i++) { + for (int i = 0; i < xp->xp_numfiles; i++) { len += strlen(xp->xp_files[i]) + 1; } ss = xmalloc(len); *ss = NUL; - for (i = 0; i < xp->xp_numfiles; i++) { + for (int i = 0; i < xp->xp_numfiles; i++) { STRCAT(ss, xp->xp_files[i]); if (i != xp->xp_numfiles - 1) { STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); @@ -1375,7 +1371,6 @@ void set_expand_context(expand_T *xp) static const char *set_cmd_index(const char *cmd, exarg_T *eap, expand_T *xp, int *complp) { const char *p = NULL; - size_t len = 0; const bool fuzzy = cmdline_fuzzy_complete(cmd); // Isolate the command and search for it in the command table. @@ -1410,7 +1405,7 @@ static const char *set_cmd_index(const char *cmd, exarg_T *eap, expand_T *xp, in if (p == cmd && vim_strchr("@*!=><&~#", (uint8_t)(*p)) != NULL) { p++; } - len = (size_t)(p - cmd); + size_t len = (size_t)(p - cmd); if (len == 0) { xp->xp_context = EXPAND_UNSUCCESSFUL; @@ -2955,7 +2950,6 @@ static void expand_shellcmd(char *filepat, char ***matches, int *numMatches, int char *path = NULL; garray_T ga; char *buf = xmalloc(MAXPATHL); - size_t l; char *s, *e; int flags = flagsarg; bool did_curdir = false; @@ -3013,7 +3007,7 @@ static void expand_shellcmd(char *filepat, char ***matches, int *numMatches, int flags &= ~EW_DIR; } - l = (size_t)(e - s); + size_t l = (size_t)(e - s); if (l > MAXPATHL - 5) { break; } diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index 04c342e068..2bc335a7e0 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -1620,8 +1620,6 @@ static void win_update(win_T *wp, DecorProviders *providers) && !(dollar_vcol >= 0 && mod_bot == mod_top + 1) && row >= top_end) { int old_rows = 0; - int new_rows = 0; - int xtra_rows; linenr_T l; int i; @@ -1656,6 +1654,7 @@ static void win_update(win_T *wp, DecorProviders *providers) bot_start = 0; bot_scroll_start = 0; } else { + int new_rows = 0; // Able to count old number of rows: Count new window // rows, and may insert/delete lines long j = idx; @@ -1674,7 +1673,7 @@ static void win_update(win_T *wp, DecorProviders *providers) break; } } - xtra_rows = new_rows - old_rows; + int xtra_rows = new_rows - old_rows; if (xtra_rows < 0) { // May scroll text up. If there is not enough // remaining text or scrolling fails, must redraw the diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 2496cbc430..3c4cc34464 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -729,7 +729,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) { - funccall_T **pfc; int i; if (fc == NULL) { @@ -738,7 +737,7 @@ static void funccal_unref(funccall_T *fc, ufunc_T *fp, bool force) fc->fc_refcount--; if (force ? fc->fc_refcount <= 0 : !fc_referenced(fc)) { - for (pfc = &previous_funccal; *pfc != NULL; pfc = &(*pfc)->caller) { + for (funccall_T **pfc = &previous_funccal; *pfc != NULL; pfc = &(*pfc)->caller) { if (fc == *pfc) { *pfc = fc->caller; free_funccal_contents(fc); @@ -3289,7 +3288,6 @@ int func_has_abort(void *cookie) /// Changes "rettv" in-place. void make_partial(dict_T *const selfdict, typval_T *const rettv) { - char *fname; char *tofree = NULL; ufunc_T *fp; char fname_buf[FLEN_FIXED + 1]; @@ -3298,7 +3296,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) if (rettv->v_type == VAR_PARTIAL && rettv->vval.v_partial->pt_func != NULL) { fp = rettv->vval.v_partial->pt_func; } else { - fname = rettv->v_type == VAR_FUNC || rettv->v_type == VAR_STRING + char *fname = rettv->v_type == VAR_FUNC || rettv->v_type == VAR_STRING ? rettv->vval.v_string : rettv->vval.v_partial->pt_name; // Translate "s:func" to the stored function name. @@ -3319,7 +3317,6 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) pt->pt_name = rettv->vval.v_string; } else { partial_T *ret_pt = rettv->vval.v_partial; - int i; // Partial: copy the function name, use selfdict and copy // args. Can't take over name or args, the partial might @@ -3335,7 +3332,7 @@ void make_partial(dict_T *const selfdict, typval_T *const rettv) size_t arg_size = sizeof(typval_T) * (size_t)ret_pt->pt_argc; pt->pt_argv = (typval_T *)xmalloc(arg_size); pt->pt_argc = ret_pt->pt_argc; - for (i = 0; i < pt->pt_argc; i++) { + for (int i = 0; i < pt->pt_argc; i++) { tv_copy(&ret_pt->pt_argv[i], &pt->pt_argv[i]); } } @@ -3641,14 +3638,13 @@ bool set_ref_in_func(char *name, ufunc_T *fp_in, int copyID) int error = FCERR_NONE; char fname_buf[FLEN_FIXED + 1]; char *tofree = NULL; - char *fname; bool abort = false; if (name == NULL && fp_in == NULL) { return false; } if (fp_in == NULL) { - fname = fname_trans_sid(name, fname_buf, &tofree, &error); + char *fname = fname_trans_sid(name, fname_buf, &tofree, &error); fp = find_func(fname); } if (fp != NULL) { diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index 3d9b476863..d80bdc70f6 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -369,12 +369,10 @@ int ex_let_vars(char *arg_start, typval_T *tv, int copy, int semicolon, int var_ /// @return NULL for an error. const char *skip_var_list(const char *arg, int *var_count, int *semicolon) { - const char *p; - const char *s; - if (*arg == '[') { + const char *s; // "[var, var]": find the matching ']'. - p = arg; + const char *p = arg; for (;;) { p = skipwhite(p + 1); // skip whites after '[', ';' or ',' s = skip_var_one((char *)p); @@ -575,7 +573,6 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo FUNC_ATTR_NONNULL_ARG(1, 2) FUNC_ATTR_WARN_UNUSED_RESULT { char *arg_end = NULL; - int len; // ":let $VAR = expr": Set environment variable. if (*arg == '$') { @@ -586,7 +583,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo // Find the end of the name. arg++; char *name = arg; - len = get_env_len((const char **)&arg); + int len = get_env_len((const char **)&arg); if (len == 0) { semsg(_(e_invarg2), name - 1); } else { @@ -722,12 +719,10 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo && vim_strchr(endchars, (uint8_t)(*skipwhite(arg + 1))) == NULL) { emsg(_(e_letunexp)); } else { - char *s; - char *ptofree = NULL; const char *p = tv_get_string_chk(tv); if (p != NULL && op != NULL && *op == '.') { - s = get_reg_contents(*arg == '@' ? '"' : *arg, kGRegExprSrc); + char *s = get_reg_contents(*arg == '@' ? '"' : *arg, kGRegExprSrc); if (s != NULL) { ptofree = concat_str(s, p); p = (const char *)ptofree; @@ -861,10 +856,9 @@ static int do_unlet_var(lval_T *lp, char *name_end, exarg_T *eap, int deep FUNC_ { int forceit = eap->forceit; int ret = OK; - int cc; if (lp->ll_tv == NULL) { - cc = (uint8_t)(*name_end); + int cc = (uint8_t)(*name_end); *name_end = NUL; // Environment variable, normal name or expanded name. diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 46f8a59710..8815ac726a 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -204,15 +204,11 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, int len = textlen; int c; size_t max_off; - int mbyte_blen = 1; - int mbyte_cells = 1; - int u8c = 0; int u8cc[MAX_MCO]; bool clear_next_cell = false; int prev_c = 0; // previous Arabic character int pc, nc, nc1; int pcc[MAX_MCO]; - int need_redraw; bool do_flush = false; grid_adjust(&grid, &row, &col); @@ -249,13 +245,13 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, && *ptr != NUL) { c = (unsigned char)(*ptr); // check if this is the first byte of a multibyte - mbyte_blen = len > 0 + int mbyte_blen = len > 0 ? utfc_ptr2len_len(ptr, (int)((text + len) - ptr)) : utfc_ptr2len(ptr); - u8c = len >= 0 + int u8c = len >= 0 ? utfc_ptr2char_len(ptr, u8cc, (int)((text + len) - ptr)) : utfc_ptr2char(ptr, u8cc); - mbyte_cells = utf_char2cells(u8c); + int mbyte_cells = utf_char2cells(u8c); if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) { // Do Arabic shaping. if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) { @@ -287,11 +283,11 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, schar_T buf; schar_from_cc(buf, u8c, u8cc); - need_redraw = schar_cmp(grid->chars[off], buf) - || (mbyte_cells == 2 && grid->chars[off + 1][0] != 0) - || grid->attrs[off] != attr - || exmode_active - || rdb_flags & RDB_NODELTA; + int need_redraw = schar_cmp(grid->chars[off], buf) + || (mbyte_cells == 2 && grid->chars[off + 1][0] != 0) + || grid->attrs[off] != attr + || exmode_active + || rdb_flags & RDB_NODELTA; if (need_redraw) { // When at the end of the text and overwriting a two-cell @@ -497,7 +493,6 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle size_t max_off_from; size_t max_off_to; int col = 0; - bool redraw_this; // Does character need redraw? bool redraw_next; // redraw_this for next character bool clear_next = false; int char_cells; // 1: normal char @@ -559,7 +554,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle if (col + 1 < endcol) { char_cells = line_off2cells(linebuf_char, off_from, max_off_from); } - redraw_this = redraw_next; + bool redraw_this = redraw_next; // Does character need redraw? redraw_next = grid_char_needs_redraw(grid, off_from + (size_t)char_cells, off_to + (size_t)char_cells, endcol - col - char_cells); diff --git a/src/nvim/input.c b/src/nvim/input.c index 2869155a09..5b9b866778 100644 --- a/src/nvim/input.c +++ b/src/nvim/input.c @@ -88,7 +88,6 @@ int get_keystroke(MultiQueue *events) { char *buf = NULL; int buflen = 150; - int maxlen; int len = 0; int n; int save_mapped_ctrl_c = mapped_ctrl_c; @@ -100,7 +99,7 @@ int get_keystroke(MultiQueue *events) // Leave some room for check_termcode() to insert a key code into (max // 5 chars plus NUL). And fix_input_buffer() can triple the number of // bytes. - maxlen = (buflen - 6 - len) / 3; + int maxlen = (buflen - 6 - len) / 3; if (buf == NULL) { buf = xmalloc((size_t)buflen); } else if (maxlen < 10) { @@ -166,7 +165,6 @@ int get_keystroke(MultiQueue *events) int get_number(int colon, int *mouse_used) { int n = 0; - int c; int typed = 0; if (mouse_used != NULL) { @@ -183,7 +181,7 @@ int get_number(int colon, int *mouse_used) allow_keys++; // no mapping here, but recognize keys for (;;) { ui_cursor_goto(msg_row, msg_col); - c = safe_vgetc(); + int c = safe_vgetc(); if (ascii_isdigit(c)) { n = n * 10 + c - '0'; msg_putchar(c); diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 5fbbb342bf..c8fc76e20d 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1766,13 +1766,12 @@ bool nlua_exec_file(const char *path) StringBuilder sb = KV_INITIAL_VALUE; kv_resize(sb, 64); - ptrdiff_t read_size = -1; // Read all input from stdin, unless interrupted (ctrl-c). while (true) { if (got_int) { // User canceled. return false; } - read_size = file_read(stdin_dup, IObuff, 64); + ptrdiff_t read_size = file_read(stdin_dup, IObuff, 64); if (read_size < 0) { // Error. return false; } diff --git a/src/nvim/lua/spell.c b/src/nvim/lua/spell.c index d510d25e90..78e023c26d 100644 --- a/src/nvim/lua/spell.c +++ b/src/nvim/lua/spell.c @@ -51,7 +51,6 @@ int nlua_spell_check(lua_State *lstate) } hlf_T attr = HLF_COUNT; - size_t len = 0; size_t pos = 0; int capcol = -1; int no_res = 0; @@ -61,7 +60,7 @@ int nlua_spell_check(lua_State *lstate) while (*str != NUL) { attr = HLF_COUNT; - len = spell_check(curwin, (char *)str, &attr, &capcol, false); + size_t len = spell_check(curwin, (char *)str, &attr, &capcol, false); assert(len <= INT_MAX); if (attr != HLF_COUNT) { diff --git a/src/nvim/main.c b/src/nvim/main.c index f36730a8b3..c12de07077 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -920,9 +920,8 @@ static void remote_request(mparm_T *params, int remote_args, char *server_addr, } Array args = ARRAY_DICT_INIT; - String arg_s; for (int t_argc = remote_args; t_argc < argc; t_argc++) { - arg_s = cstr_to_string(argv[t_argc]); + String arg_s = cstr_to_string(argv[t_argc]); ADD(args, STRING_OBJ(arg_s)); } @@ -1620,9 +1619,6 @@ static void open_script_files(mparm_T *parmp) // Also does recovery if "recoverymode" set. static void create_windows(mparm_T *parmp) { - int dorewind; - int done = 0; - // Create the number of windows that was requested. if (parmp->window_count == -1) { // was not set parmp->window_count = 1; @@ -1658,6 +1654,7 @@ static void create_windows(mparm_T *parmp) } do_modelines(0); // do modelines } else { + int done = 0; // Open a buffer for windows that don't have one yet. // Commands in the vimrc might have loaded a file or split the window. // Watch out for autocommands that delete a window. @@ -1665,7 +1662,7 @@ static void create_windows(mparm_T *parmp) // Don't execute Win/Buf Enter/Leave autocommands here autocmd_no_enter++; autocmd_no_leave++; - dorewind = true; + int dorewind = true; while (done++ < 1000) { if (dorewind) { if (parmp->window_layout == WIN_TABS) { diff --git a/src/nvim/mark.c b/src/nvim/mark.c index f1a1f25e6c..0a944da2c4 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -521,11 +521,10 @@ fmark_T *pos_to_mark(buf_T *buf, fmark_T *fmp, pos_T pos) /// @return whether the buffer was switched or not. static MarkMoveRes switch_to_mark_buf(fmark_T *fm, bool pcmark_on_switch) { - bool res; if (fm->fnum != curbuf->b_fnum) { // Switch to another file. int getfile_flag = pcmark_on_switch ? GETF_SETMARK : 0; - res = buflist_getfile(fm->fnum, (linenr_T)1, getfile_flag, false) == OK; + bool res = buflist_getfile(fm->fnum, (linenr_T)1, getfile_flag, false) == OK; return res == true ? kMarkSwitchedBuf : kMarkMoveFailed; } return 0; diff --git a/src/nvim/match.c b/src/nvim/match.c index 6663dfd7ec..93c8a58051 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -419,7 +419,6 @@ static void next_search_hl(win_T *win, match_T *search_hl, match_T *shl, linenr_ colnr_T mincol, matchitem_T *cur) FUNC_ATTR_NONNULL_ARG(2) { - linenr_T l; colnr_T matchcol; long nmatched = 0; const int called_emsg_before = called_emsg; @@ -435,7 +434,7 @@ static void next_search_hl(win_T *win, match_T *search_hl, match_T *shl, linenr_ // 1. If the "lnum" is below a previous match, start a new search. // 2. If the previous match includes "mincol", use it. // 3. Continue after the previous match. - l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; + linenr_T l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; if (lnum > l) { shl->lnum = 0; } else if (lnum < l || shl->rm.endpos[0].col > mincol) { diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 46be9ccea5..118b5d5886 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -603,11 +603,9 @@ static int mf_read(memfile_T *mfp, bhdr_T *hp) static int mf_write(memfile_T *mfp, bhdr_T *hp) { off_T offset; // offset in the file - blocknr_T nr; // block nr which is being written bhdr_T *hp2; unsigned page_size; // number of bytes in a page unsigned page_count; // number of pages written - unsigned size; // number of bytes written if (mfp->mf_fd < 0) { // there is no file, can't write return FAIL; @@ -626,7 +624,7 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp) /// If block 'mf_infile_count' is not in the hash list, it has been /// freed. Fill the space in the file with data from the current block. for (;;) { - nr = hp->bh_bnum; + blocknr_T nr = hp->bh_bnum; // block nr which is being written if (nr > mfp->mf_infile_count) { // beyond end of file nr = mfp->mf_infile_count; hp2 = mf_find_hash(mfp, nr); // NULL caught below @@ -645,7 +643,7 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp) } else { page_count = hp2->bh_page_count; } - size = page_size * page_count; + unsigned size = page_size * page_count; // number of bytes written void *data = (hp2 == NULL) ? hp->bh_data : hp2->bh_data; if ((unsigned)write_eintr(mfp->mf_fd, data, size) != size) { /// Avoid repeating the error message, this mostly happens when the diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 555f21c4fd..ff0a6d7627 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -2022,7 +2022,6 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char *line, colnr_T len, boo int lineadd; blocknr_T bnum_left, bnum_right; linenr_T lnum_left, lnum_right; - int pb_idx; PTR_BL *pp_new; // We are going to allocate a new data block. Depending on the @@ -2156,7 +2155,7 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char *line, colnr_T len, boo // update pointer blocks for the new data block for (stack_idx = buf->b_ml.ml_stack_top - 1; stack_idx >= 0; stack_idx--) { infoptr_T *ip = &(buf->b_ml.ml_stack[stack_idx]); - pb_idx = ip->ip_index; + int pb_idx = ip->ip_index; if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL) { return FAIL; } @@ -3211,7 +3210,6 @@ static int do_swapexists(buf_T *buf, char *fname) static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_existing_dir) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1, 2, 4) { - size_t n; char *buf_fname = buf->b_fname; // Isolate a directory name from *dirp and put it in dir_name. @@ -3224,6 +3222,7 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, bool *found_ char *fname = makeswapname(buf_fname, buf->b_ffname, buf, dir_name); for (;;) { + size_t n; if (fname == NULL) { // must be out of memory break; } @@ -3605,11 +3604,8 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype) linenr_T curline = ml_upd_lastcurline; int curix = ml_upd_lastcurix; - long size; chunksize_T *curchnk; - int rest; bhdr_T *hp; - DATA_BL *dp; if (buf->b_ml.ml_usedchunks == -1 || len == 0) { return; @@ -3655,6 +3651,8 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype) } curchnk->mlcs_totalsize += len; if (updtype == ML_CHNK_ADDLINE) { + int rest; + DATA_BL *dp; curchnk->mlcs_numlines++; // May resize here so we don't have to do it in both cases below @@ -3665,17 +3663,14 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype) } if (buf->b_ml.ml_chunksize[curix].mlcs_numlines >= MLCS_MAXL) { - int count; // number of entries in block - int idx; int text_end; - int linecnt; memmove(buf->b_ml.ml_chunksize + curix + 1, buf->b_ml.ml_chunksize + curix, (size_t)(buf->b_ml.ml_usedchunks - curix) * sizeof(chunksize_T)); // Compute length of first half of lines in the split chunk - size = 0; - linecnt = 0; + long size = 0; + int linecnt = 0; while (curline < buf->b_ml.ml_line_count && linecnt < MLCS_MINL) { if ((hp = ml_find_line(buf, curline, ML_FIND)) == NULL) { @@ -3683,8 +3678,9 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype) return; } dp = hp->bh_data; - count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1; - idx = curline - buf->b_ml.ml_locked_low; + int count + = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1; // number of entries in block + int idx = curline - buf->b_ml.ml_locked_low; curline = buf->b_ml.ml_locked_high + 1; if (idx == 0) { // first line in block, text at the end text_end = (int)dp->db_txt_end; @@ -3793,13 +3789,8 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff) int curix; long size; bhdr_T *hp; - DATA_BL *dp; - int count; // number of entries in block - int idx; - int start_idx; int text_end; long offset; - int len; int ffdos = !no_ff && (get_fileformat(buf) == EOL_DOS); int extra = 0; @@ -3859,9 +3850,11 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff) || (hp = ml_find_line(buf, curline, ML_FIND)) == NULL) { return -1; } - dp = hp->bh_data; - count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1; - start_idx = idx = curline - buf->b_ml.ml_locked_low; + DATA_BL *dp = hp->bh_data; + int count + = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1; // number of entries in block + int idx; + int start_idx = idx = curline - buf->b_ml.ml_locked_low; if (idx == 0) { // first line in block, text at the end text_end = (int)dp->db_txt_end; } else { @@ -3889,7 +3882,7 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff) idx++; } } - len = text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK); + int len = text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK); size += len; if (offset != 0 && size >= offset) { if (size + ffdos == offset) { diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 2a18b08d8d..8ab515bf0e 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -815,7 +815,6 @@ static int show_menus(char *const path_name, int modes) static void show_menus_recursive(vimmenu_T *menu, int modes, int depth) { int i; - int bit; if (menu != NULL && (menu->modes & modes) == 0x0) { return; @@ -838,7 +837,7 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth) } if (menu != NULL && menu->children == NULL) { - for (bit = 0; bit < MENU_MODES; bit++) { + for (int bit = 0; bit < MENU_MODES; bit++) { if ((menu->modes & modes & (1 << bit)) != 0) { msg_putchar('\n'); if (got_int) { // "q" hit for "--more--" @@ -902,7 +901,6 @@ char *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char *arg, bool for char *after_dot; char *p; char *path_name = NULL; - char *name; int unmenu; vimmenu_T *menu; int expand_menus; @@ -963,7 +961,7 @@ char *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char *arg, bool for path_name = xmalloc(path_len); xstrlcpy(path_name, arg, path_len); } - name = path_name; + char *name = path_name; while (name != NULL && *name) { p = menu_name_skip(name); while (menu != NULL) { diff --git a/src/nvim/message.c b/src/nvim/message.c index 88f58ef0df..4904bde095 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -369,14 +369,13 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) char *msg_strtrunc(char *s, int force) { char *buf = NULL; - int len; - int room; // May truncate message to avoid a hit-return prompt if ((!msg_scroll && !need_wait_return && shortmess(SHM_TRUNCALL) && !exmode_active && msg_silent == 0 && !ui_has(kUIMessages)) || force) { - len = vim_strsize(s); + int room; + int len = vim_strsize(s); if (msg_scrolled != 0) { // Use all the columns. room = (Rows - msg_row) * Columns - 1; @@ -1033,7 +1032,6 @@ void ex_messages(void *const eap_p) { const exarg_T *const eap = (const exarg_T *)eap_p; struct msg_hist *p; - int c = 0; if (strcmp(eap->arg, "clear") == 0) { int keep = eap->addr_count == 0 ? 0 : eap->line2; @@ -1052,6 +1050,7 @@ void ex_messages(void *const eap_p) p = first_msg_hist; if (eap->addr_count != 0) { + int c = 0; // Count total messages for (; p != NULL && !got_int; p = p->next) { c++; @@ -1542,7 +1541,6 @@ int msg_outtrans_len_attr(const char *msgstr, int len, int attr) const char *str = msgstr; const char *plain_start = msgstr; char *s; - int mb_l; int c; int save_got_int = got_int; @@ -1565,7 +1563,7 @@ int msg_outtrans_len_attr(const char *msgstr, int len, int attr) // Normal characters are printed several at a time. while (--len >= 0 && !got_int) { // Don't include composing chars after the end. - mb_l = utfc_ptr2len_len(str, len + 1); + int mb_l = utfc_ptr2len_len(str, len + 1); if (mb_l > 1) { c = utf_ptr2char(str); if (vim_isprintc(c)) { @@ -2652,12 +2650,11 @@ void msg_sb_eol(void) static msgchunk_T *disp_sb_line(int row, msgchunk_T *smp) { msgchunk_T *mp = smp; - char *p; for (;;) { msg_row = row; msg_col = mp->sb_msg_col; - p = mp->sb_text; + char *p = mp->sb_text; if (*p == '\n') { // don't display the line break p++; } @@ -2767,7 +2764,6 @@ static int do_more_prompt(int typed_char) int oldState = State; int c; int retval = false; - int toscroll; bool to_redraw = false; msgchunk_T *mp_last = NULL; msgchunk_T *mp; @@ -2809,7 +2805,7 @@ static int do_more_prompt(int typed_char) c = get_keystroke(resize_events); } - toscroll = 0; + int toscroll = 0; switch (c) { case BS: // scroll one line back case K_BS: @@ -3507,7 +3503,6 @@ int do_dialog(int type, char *title, char *message, char *buttons, int dfltbutto { int retval = 0; char *hotkeys; - int c; int i; if (silent_mode // No dialogs in silent mode ("ex -s") @@ -3530,7 +3525,7 @@ int do_dialog(int type, char *title, char *message, char *buttons, int dfltbutto for (;;) { // Get a typed character directly from the user. - c = get_keystroke(NULL); + int c = get_keystroke(NULL); switch (c) { case CAR: // User accepts default option case NL: diff --git a/src/nvim/move.c b/src/nvim/move.c index 3af26b910e..a946633bf6 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -145,7 +145,6 @@ void update_topline(win_T *wp) { linenr_T old_topline; int old_topfill; - bool check_topline = false; bool check_botline = false; long *so_ptr = wp->w_p_so >= 0 ? &wp->w_p_so : &p_so; long save_so = *so_ptr; @@ -189,6 +188,7 @@ void update_topline(win_T *wp) wp->w_viewport_invalid = true; wp->w_scbind_pos = 1; } else { + bool check_topline = false; // If the cursor is above or near the top of the window, scroll the window // to show the line the cursor is in, with 'scrolloff' context. if (wp->w_topline > 1) { diff --git a/src/nvim/normal.c b/src/nvim/normal.c index b88cfb8926..a84d5c73a4 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -401,10 +401,8 @@ void init_normal_cmds(void) /// @return -1 for invalid command. static int find_command(int cmdchar) { - int i; int idx; int top, bot; - int c; // A multi-byte character is never a command. if (cmdchar >= 0x100) { @@ -429,8 +427,8 @@ static int find_command(int cmdchar) top = NV_CMDS_SIZE - 1; idx = -1; while (bot <= top) { - i = (top + bot) / 2; - c = nv_cmds[nv_cmd_idx[i]].cmd_char; + int i = (top + bot) / 2; + int c = nv_cmds[nv_cmd_idx[i]].cmd_char; if (c < 0) { c = -c; } @@ -693,7 +691,6 @@ static void normal_get_additional_char(NormalState *s) int *cp; bool repl = false; // get character for replace mode bool lit = false; // get extra character literally - bool langmap_active = false; // using :lmap mappings int lang; // getting a text character no_mapping++; @@ -729,6 +726,7 @@ static void normal_get_additional_char(NormalState *s) // Get a second or third character. if (cp != NULL) { + bool langmap_active = false; // using :lmap mappings if (repl) { State = MODE_REPLACE; // pretend Replace mode ui_cursor_shape(); // show different cursor shape @@ -1848,7 +1846,6 @@ void clear_showcmd(void) snprintf(showcmd_buf, SHOWCMD_BUFLEN, "%" PRId64, (int64_t)lines); } else { char *s, *e; - int l; int bytes = 0; int chars = 0; @@ -1860,7 +1857,7 @@ void clear_showcmd(void) e = ml_get_pos(&VIsual); } while ((*p_sel != 'e') ? s <= e : s < e) { - l = utfc_ptr2len(s); + int l = utfc_ptr2len(s); if (l == 0) { bytes++; chars++; @@ -2427,7 +2424,6 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist) int linelen = linetabsize(get_cursor_line_ptr()); bool retval = true; bool atend = false; - int n; int col_off1; // margin offset for first screen line int col_off2; // margin offset for wrapped screen line int width1; // text width for first screen line @@ -2446,6 +2442,7 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist) } if (curwin->w_width_inner != 0) { + int n; // Instead of sticking at the last character of the buffer line we // try to stick in the last column of the screen. if (curwin->w_curswant == MAXCOL) { @@ -2793,7 +2790,6 @@ static int nv_zg_zw(cmdarg_T *cap, int nchar) /// Commands that start with "z". static void nv_zet(cmdarg_T *cap) { - int n; colnr_T col; int nchar = cap->nchar; long old_fdl = curwin->w_p_fdl; @@ -2949,7 +2945,7 @@ static void nv_zet(cmdarg_T *cap) } else { getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); } - n = curwin->w_width_inner - curwin_col_off(); + int n = curwin->w_width_inner - curwin_col_off(); if (col + siso < n) { col = 0; } else { @@ -3438,7 +3434,6 @@ static void nv_ident(cmdarg_T *cap) int cmdchar; bool g_cmd; // "g" command bool tag_cmd = false; - char *aux_ptr; if (cap->cmdchar == 'g') { // "g*", "g#", "g]" and "gCTRL-]" cmdchar = cap->nchar; @@ -3542,6 +3537,7 @@ static void nv_ident(cmdarg_T *cap) STRCAT(buf, p); xfree(p); } else { + char *aux_ptr; if (cmdchar == '*') { aux_ptr = (magic_isset() ? "/.*~[^$\\" : "/^$\\"); } else if (cmdchar == '#') { @@ -3653,10 +3649,8 @@ static void nv_tagpop(cmdarg_T *cap) /// Handle scrolling command 'H', 'L' and 'M'. static void nv_scroll(cmdarg_T *cap) { - int used = 0; long n; linenr_T lnum; - int half; cap->oap->motion_type = kMTLineWise; setpcmark(); @@ -3683,11 +3677,12 @@ static void nv_scroll(cmdarg_T *cap) } } else { if (cap->cmdchar == 'M') { + int used = 0; // Don't count filler lines above the window. used -= win_get_fill(curwin, curwin->w_topline) - curwin->w_topfill; validate_botline(curwin); // make sure w_empty_rows is valid - half = (curwin->w_height_inner - curwin->w_empty_rows + 1) / 2; + int half = (curwin->w_height_inner - curwin->w_empty_rows + 1) / 2; for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; n++) { // Count half the number of filler lines to be "below this // line" and half to be "above the next line". @@ -4115,7 +4110,6 @@ static void nv_bracket_block(cmdarg_T *cap, const pos_T *old_pos) pos_T prev_pos; long n; int findc; - int c; if (cap->nchar == '*') { cap->nchar = '/'; @@ -4155,6 +4149,7 @@ static void nv_bracket_block(cmdarg_T *cap, const pos_T *old_pos) // Try finding the '{' or '}' we want to be at. // Also repeat for the given count. if (cap->nchar == 'm' || cap->nchar == 'M') { + int c; // norm is true for "]M" and "[m" int norm = ((findc == '{') == (cap->nchar == 'm')); @@ -4361,7 +4356,6 @@ static void nv_brackets(cmdarg_T *cap) /// Handle Normal mode "%" command. static void nv_percent(cmdarg_T *cap) { - pos_T *pos; linenr_T lnum = curwin->w_cursor.lnum; cap->oap->inclusive = true; @@ -4391,6 +4385,7 @@ static void nv_percent(cmdarg_T *cap) beginline(BL_SOL | BL_FIX); } } else { // "%" : go to matching paren + pos_T *pos; cap->oap->motion_type = kMTCharWise; cap->oap->use_reg_one = true; if ((pos = findmatch(cap->oap, NUL)) == NULL) { @@ -6046,9 +6041,8 @@ static void adjust_for_sel(cmdarg_T *cap) /// @return true when backed up to the previous line. bool unadjust_for_sel(void) { - pos_T *pp; - if (*p_sel == 'e' && !equalpos(VIsual, curwin->w_cursor)) { + pos_T *pp; if (lt(VIsual, curwin->w_cursor)) { pp = &curwin->w_cursor; } else { @@ -6460,7 +6454,6 @@ static void nv_put(cmdarg_T *cap) /// @param fix_indent true for "[p", "[P", "]p" and "]P". static void nv_put_opt(cmdarg_T *cap, bool fix_indent) { - int regname = 0; yankreg_T *savereg = NULL; bool empty = false; bool was_visual = false; @@ -6506,7 +6499,7 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent) // Need to save and restore the registers that the delete // overwrites if the old contents is being put. was_visual = true; - regname = cap->oap->regname; + int regname = cap->oap->regname; bool keep_registers = cap->cmdchar == 'P'; // '+' and '*' could be the same selection bool clipoverwrite = (regname == '+' || regname == '*') && (cb_flags & CB_UNNAMEDMASK); diff --git a/src/nvim/option.c b/src/nvim/option.c index 6c9fd275fa..26466c2869 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4850,10 +4850,9 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, char *fuzzystr, int *numM // loop == 0: count the number of matching options // loop == 1: copy the matching options into allocated memory for (int loop = 0; loop <= 1; loop++) { - int match; regmatch->rm_ic = ic; if (xp->xp_context != EXPAND_BOOL_SETTINGS) { - for (match = 0; match < (int)ARRAY_SIZE(names); + for (int match = 0; match < (int)ARRAY_SIZE(names); match++) { if (match_str(names[match], regmatch, *matches, count, (loop == 0), fuzzy, fuzzystr, fuzmatch)) { diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 7efbeadb2f..5f8514b1a6 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -330,7 +330,6 @@ void set_string_option_direct(const char *name, int opt_idx, const char *val, in int set_sid) { char *s; - char **varp; int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; int idx = opt_idx; @@ -353,7 +352,7 @@ void set_string_option_direct(const char *name, int opt_idx, const char *val, in s = xstrdup(val); { - varp = (char **)get_varp_scope(opt, both ? OPT_LOCAL : opt_flags); + char **varp = (char **)get_varp_scope(opt, both ? OPT_LOCAL : opt_flags); if ((opt_flags & OPT_FREE) && (opt->flags & P_ALLOCED)) { free_string_option(*varp); } diff --git a/src/nvim/plines.c b/src/nvim/plines.c index 5469d94800..a3e5640b18 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -356,14 +356,9 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) char *s = cts->cts_ptr; colnr_T vcol = cts->cts_vcol; - colnr_T col2; colnr_T col_adj = 0; // vcol + screen size of tab - colnr_T colmax; - int added; int mb_added = 0; int numberextra; - char *ps; - int n; cts->cts_cur_text_width = 0; @@ -397,12 +392,12 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) // Count all characters from first non-blank after a blank up to next // non-blank after a blank. numberextra = win_col_off(wp); - col2 = vcol; - colmax = (colnr_T)(wp->w_width_inner - numberextra - col_adj); + colnr_T col2 = vcol; + colnr_T colmax = (colnr_T)(wp->w_width_inner - numberextra - col_adj); if (vcol >= colmax) { colmax += col_adj; - n = colmax + win_col_off2(wp); + int n = colmax + win_col_off2(wp); if (n > 0) { colmax += (((vcol - colmax) / n) + 1) * n - col_adj; @@ -410,7 +405,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) } for (;;) { - ps = s; + char *ps = s; MB_PTR_ADV(s); c = (uint8_t)(*s); @@ -439,7 +434,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) // string at start of line. // Set *headp to the size of what we add. // Do not use 'showbreak' at the NUL after the text. - added = 0; + int added = 0; char *const sbr = c == NUL ? empty_option : get_showbreak_value(wp); if ((*sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && vcol != 0) { colnr_T sbrlen = 0; diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index b071e10cf9..70e1e00623 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -276,10 +276,8 @@ static void source_callback(char *fname, void *cookie) /// return FAIL when no file could be sourced, OK otherwise. int do_in_path(char *path, char *name, int flags, DoInRuntimepathCB callback, void *cookie) { - char *tail; int num_files; char **files; - int i; bool did_one = false; // Make a copy of 'runtimepath'. Invoking the callback may change the @@ -287,6 +285,8 @@ int do_in_path(char *path, char *name, int flags, DoInRuntimepathCB callback, vo char *rtp_copy = xstrdup(path); char *buf = xmallocz(MAXPATHL); { + char *tail; + int i; if (p_verbose > 10 && name != NULL) { verbose_enter(); smsg(_("Searching for \"%s\" in \"%s\""), name, path); @@ -2329,7 +2329,6 @@ char *getsourceline(int c, void *cookie, int indent, bool do_concat) { struct source_cookie *sp = (struct source_cookie *)cookie; char *line; - char *p; // If breakpoints have been added/deleted need to check for it. if (sp->dbg_tick < debug_tick) { @@ -2359,6 +2358,7 @@ char *getsourceline(int c, void *cookie, int indent, bool do_concat) // Only concatenate lines starting with a \ when 'cpoptions' doesn't // contain the 'C' flag. if (line != NULL && do_concat && (vim_strchr(p_cpo, CPO_CONCAT) == NULL)) { + char *p; // compensate for the one line read-ahead sp->sourcing_lnum--; diff --git a/src/nvim/sign.c b/src/nvim/sign.c index a288fa2e9d..d555b8bf4a 100644 --- a/src/nvim/sign.c +++ b/src/nvim/sign.c @@ -153,11 +153,10 @@ static int sign_group_get_next_signid(buf_T *buf, const char *groupname) int id = 1; signgroup_T *group = NULL; sign_entry_T *sign; - hashitem_T *hi; int found = false; if (groupname != NULL) { - hi = hash_find(&sg_table, (char *)groupname); + hashitem_T *hi = hash_find(&sg_table, (char *)groupname); if (HASHITEM_EMPTY(hi)) { return id; } @@ -1198,7 +1197,6 @@ static linenr_T sign_jump(int sign_id, char *sign_group, buf_T *buf) /// ":sign define {name} ..." command static void sign_define_cmd(char *sign_name, char *cmdline) { - char *arg; char *p = cmdline; char *icon = NULL; char *text = NULL; @@ -1210,7 +1208,7 @@ static void sign_define_cmd(char *sign_name, char *cmdline) // set values for a defined sign. for (;;) { - arg = skipwhite(p); + char *arg = skipwhite(p); if (*arg == NUL) { break; } @@ -1585,7 +1583,6 @@ static void sign_getinfo(sign_T *sp, dict_T *retdict) static void sign_getlist(const char *name, list_T *retlist) { sign_T *sp = first_sign; - dict_T *dict; if (name != NULL) { sp = sign_find((char *)name, NULL); @@ -1595,7 +1592,7 @@ static void sign_getlist(const char *name, list_T *retlist) } for (; sp != NULL && !got_int; sp = sp->sn_next) { - dict = tv_dict_alloc(); + dict_T *dict = tv_dict_alloc(); tv_list_append_dict(retlist, dict); sign_getinfo(sp, dict); @@ -1610,11 +1607,10 @@ list_T *get_buffer_signs(buf_T *buf) FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { sign_entry_T *sign; - dict_T *d; list_T *const l = tv_list_alloc(kListLenMayKnow); FOR_ALL_SIGNS_IN_BUF(buf, sign) { - d = sign_get_info(sign); + dict_T *d = sign_get_info(sign); tv_list_append_dict(l, d); } return l; @@ -2055,7 +2051,6 @@ void f_sign_getdefined(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) void f_sign_getplaced(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { buf_T *buf = NULL; - dict_T *dict; dictitem_T *di; linenr_T lnum = 0; int sign_id = 0; @@ -2072,6 +2067,7 @@ void f_sign_getplaced(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } if (argvars[1].v_type != VAR_UNKNOWN) { + dict_T *dict; if (argvars[1].v_type != VAR_DICT || ((dict = argvars[1].vval.v_dict) == NULL)) { emsg(_(e_dictreq)); @@ -2327,8 +2323,6 @@ static void sign_undefine_multiple(list_T *l, list_T *retlist) /// "sign_undefine()" function void f_sign_undefine(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - const char *name; - if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_UNKNOWN) { // Undefine multiple signs tv_list_alloc_ret(rettv, kListLenMayKnow); @@ -2345,7 +2339,7 @@ void f_sign_undefine(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) rettv->vval.v_number = 0; } else { // Free only the specified sign - name = tv_get_string_chk(&argvars[0]); + const char *name = tv_get_string_chk(&argvars[0]); if (name == NULL) { return; } diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index c5efe6e94b..66829c60c9 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -271,7 +271,6 @@ static bool can_be_compound(trystate_T *sp, slang_T *slang, char_u *compflags, i /// @param split word was split, less bonus static int score_wordcount_adj(slang_T *slang, int score, char *word, bool split) { - wordcount_T *wc; int bonus; int newscore; @@ -280,7 +279,7 @@ static int score_wordcount_adj(slang_T *slang, int score, char *word, bool split return score; } - wc = HI2WC(hi); + wordcount_T *wc = HI2WC(hi); if (wc->wc_count < SCORE_THRES2) { bonus = SCORE_COMMON1; } else if (wc->wc_count < SCORE_THRES3) { @@ -306,20 +305,17 @@ static int badword_captype(char *word, char *end) FUNC_ATTR_NONNULL_ALL { int flags = captype(word, end); - int c; - int l, u; - bool first; - char *p; if (!(flags & WF_KEEPCAP)) { return flags; } // Count the number of UPPER and lower case letters. - l = u = 0; - first = false; - for (p = word; p < end; MB_PTR_ADV(p)) { - c = utf_ptr2char(p); + int l= 0; + int u= 0; + bool first = false; + for (char *p = word; p < end; MB_PTR_ADV(p)) { + int c = utf_ptr2char(p); if (SPELL_ISUPPER(c)) { u++; if (p == word) { @@ -355,9 +351,8 @@ static int bytes2offset(char **pp) { char_u *p = (char_u *)(*pp); int nr; - int c; - c = *p++; + int c = *p++; if ((c & 0x80) == 0x00) { // 1 byte nr = c - 1; } else if ((c & 0xc0) == 0x80) { // 2 bytes @@ -392,18 +387,16 @@ static int sps_limit = 9999; ///< max nr of suggestions given /// Sets "sps_flags" and "sps_limit". int spell_check_sps(void) { - char *p; char *s; char buf[MAXPATHL]; - int f; sps_flags = 0; sps_limit = 9999; - for (p = p_sps; *p != NUL;) { + for (char *p = p_sps; *p != NUL;) { copy_option_part(&p, buf, MAXPATHL, ","); - f = 0; + int f = 0; if (ascii_isdigit(*buf)) { s = buf; sps_limit = getdigits_int(&s, true, 0); @@ -451,11 +444,9 @@ void spell_suggest(int count) pos_T prev_cursor = curwin->w_cursor; char wcopy[MAXWLEN + 2]; char *p; - int c; suginfo_T sug; suggest_T *stp; int mouse_used; - int need_cap; int limit; int selected = count; int badlen = 0; @@ -519,7 +510,7 @@ void spell_suggest(int count) // Get the word and its length. // Figure out if the word should be capitalised. - need_cap = check_need_cap(curwin->w_cursor.lnum, curwin->w_cursor.col); + int need_cap = check_need_cap(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()); @@ -651,7 +642,7 @@ void spell_suggest(int count) // Replace the word. p = xmalloc(strlen(line) - (size_t)stp->st_orglen + (size_t)stp->st_wordlen + 1); - c = (int)(sug.su_badptr - line); + int c = (int)(sug.su_badptr - line); memmove(p, line, (size_t)c); STRCPY(p + c, stp->st_word); STRCAT(p, sug.su_badptr + stp->st_orglen); @@ -685,7 +676,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; - suggest_T *stp; char *wcopy; spell_find_suggest(word, 0, &sug, maxcount, false, need_cap, interactive); @@ -694,7 +684,7 @@ void spell_suggest_list(garray_T *gap, char *word, int maxcount, bool need_cap, ga_init(gap, sizeof(char *), sug.su_ga.ga_len + 1); ga_grow(gap, sug.su_ga.ga_len); for (int i = 0; i < sug.su_ga.ga_len; i++) { - stp = &SUG(sug.su_ga, i); + suggest_T *stp = &SUG(sug.su_ga, i); // The suggested word may replace only part of "word", add the not // replaced part. @@ -721,11 +711,8 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc { hlf_T attr = HLF_COUNT; char buf[MAXPATHL]; - char *p; bool do_combine = false; - char *sps_copy; static bool expr_busy = false; - int c; langp_T *lp; bool did_intern = false; @@ -790,7 +777,7 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc // If the word is not capitalised and spell_check() doesn't consider the // word to be bad then it might need to be capitalised. Add a suggestion // for that. - c = utf_ptr2char(su->su_badptr); + int c = utf_ptr2char(su->su_badptr); if (!SPELL_ISUPPER(c) && attr == HLF_COUNT) { make_case_word(su->su_badword, buf, WF_ONECAP); add_suggestion(su, &su->su_ga, buf, su->su_badlen, SCORE_ICASE, @@ -803,10 +790,10 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc } // Make a copy of 'spellsuggest', because the expression may change it. - sps_copy = xstrdup(p_sps); + char *sps_copy = xstrdup(p_sps); // Loop over the items in 'spellsuggest'. - for (p = sps_copy; *p != NUL;) { + for (char *p = sps_copy; *p != NUL;) { copy_option_part(&p, buf, MAXPATHL, ","); if (strncmp(buf, "expr:", 5) == 0) { @@ -845,7 +832,6 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc /// Find suggestions by evaluating expression "expr". static void spell_suggest_expr(suginfo_T *su, char *expr) { - int score; const char *p; // The work is split up in a few parts to avoid having to export @@ -857,7 +843,7 @@ static void spell_suggest_expr(suginfo_T *su, char *expr) TV_LIST_ITER(list, li, { if (TV_LIST_ITEM_TV(li)->v_type == VAR_LIST) { // Get the word and the score from the items. - score = get_spellword(TV_LIST_ITEM_TV(li)->vval.v_list, &p); + int score = get_spellword(TV_LIST_ITEM_TV(li)->vval.v_list, &p); if (score >= 0 && score <= su->su_maxscore) { add_suggestion(su, &su->su_ga, p, su->su_badlen, score, 0, true, su->su_sallang, false); @@ -875,14 +861,12 @@ static void spell_suggest_expr(suginfo_T *su, char *expr) /// Find suggestions in file "fname". Used for "file:" in 'spellsuggest'. static void spell_suggest_file(suginfo_T *su, char *fname) { - FILE *fd; char line[MAXWLEN * 2]; - char *p; int len; char cword[MAXWLEN]; // Open the file. - fd = os_fopen(fname, "r"); + FILE *fd = os_fopen(fname, "r"); if (fd == NULL) { semsg(_(e_notopen), fname); return; @@ -892,7 +876,7 @@ static void spell_suggest_file(suginfo_T *su, char *fname) while (!vim_fgets(line, MAXWLEN * 2, fd) && !got_int) { line_breakcheck(); - p = vim_strchr(line, '/'); + char *p = vim_strchr(line, '/'); if (p == NULL) { continue; // No Tab found, just skip the line. } @@ -1013,7 +997,6 @@ static void spell_find_cleanup(suginfo_T *su) /// Try finding suggestions by recognizing specific situations. static void suggest_try_special(suginfo_T *su) { - char c; char word[MAXWLEN]; // Recognize a word that is repeated: "the the". @@ -1023,7 +1006,7 @@ static void suggest_try_special(suginfo_T *su) if (strlen(p) == len && strncmp(su->su_fbadword, p, len) == 0) { // Include badflags: if the badword is onecap or allcap // use that for the goodword too: "The the" -> "The". - c = su->su_fbadword[len]; + char c = su->su_fbadword[len]; su->su_fbadword[len] = NUL; make_case_word(su->su_fbadword, word, su->su_badflags); su->su_fbadword[len] = c; @@ -1084,16 +1067,14 @@ static void prof_report(char *name) static void suggest_try_change(suginfo_T *su) { char fword[MAXWLEN]; // copy of the bad word, case-folded - int n; - char *p; 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 // chars after the bad word may help. STRCPY(fword, su->su_fbadword); - n = (int)strlen(fword); - p = su->su_badptr + su->su_badlen; + int n = (int)strlen(fword); + char *p = su->su_badptr + su->su_badlen; (void)spell_casefold(curwin, p, (int)strlen(p), fword + n, MAXWLEN - n); // Make sure the resulting text is not longer than the original text. @@ -1165,12 +1146,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // when going deeper but not when coming // back. char_u compflags[MAXWLEN]; // compound flags, one for each word - trystate_T *sp; int newscore; int score; char_u *byts, *fbyts, *pbyts; idx_T *idxs, *fidxs, *pidxs; - int depth; int c, c2, c3; int n = 0; int flags; @@ -1195,8 +1174,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // "tword[]" contains the word collected from nodes in the tree. // "fword[]" the word we are trying to match with (initially the bad // word). - depth = 0; - sp = &stack[0]; + int depth = 0; + trystate_T *sp = &stack[0]; CLEAR_POINTER(sp); // -V1068 sp->ts_curi = 1; @@ -2387,7 +2366,6 @@ static void go_deeper(trystate_T *stack, int depth, int score_add) static void find_keepcap_word(slang_T *slang, char *fword, char *kword) { char uword[MAXWLEN]; // "fword" in upper-case - int depth; idx_T tryidx; // The following arrays are used at each depth in the tree. @@ -2418,7 +2396,7 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword) // Each character needs to be tried both case-folded and upper-case. // All this gets very complicated if we keep in mind that changing case // may change the byte length of a multi-byte character... - depth = 0; + int depth = 0; arridx[0] = 0; round[0] = 0; fwordidx[0] = 0; @@ -2656,16 +2634,14 @@ static void score_combine(suginfo_T *su) /// @param badsound sound-folded badword static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char *badsound) { - char *p; char *pbad; char *pgood; char badsound2[MAXWLEN]; char fword[MAXWLEN]; char goodsound[MAXWLEN]; char goodword[MAXWLEN]; - int lendiff; - lendiff = su->su_badlen - stp->st_orglen; + int lendiff = su->su_badlen - stp->st_orglen; if (lendiff >= 0) { pbad = badsound; } else { @@ -2678,7 +2654,7 @@ static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char *ba // space. if (ascii_iswhite(su->su_badptr[su->su_badlen]) && *skiptowhite(stp->st_word) == NUL) { - for (p = fword; *(p = skiptowhite(p)) != NUL;) { + for (char *p = fword; *(p = skiptowhite(p)) != NUL;) { STRMOVE(p, p + 1); } } @@ -2801,9 +2777,6 @@ static void suggest_try_soundalike_finish(void) static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T *lp) { slang_T *slang = lp->lp_slang; // language for sound folding - int sfwordnr; - char *nrline; - int orgnr; char theword[MAXWLEN]; int i; int wlen; @@ -2813,8 +2786,6 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T int wordcount; int wc; int goodscore; - hash_T hash; - hashitem_T *hi; sftword_T *sft; int bc, gc; int limit; @@ -2823,10 +2794,9 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T // times with different scores. Since the following is quite slow only do // the words that have a better score than before. Use a hashtable to // remember the words that have been done. - hash = hash_hash(goodword); + hash_T hash = hash_hash(goodword); const size_t goodword_len = strlen(goodword); - hi = hash_lookup(&slang->sl_sounddone, (const char *)goodword, goodword_len, - hash); + hashitem_T *hi = hash_lookup(&slang->sl_sounddone, (const char *)goodword, goodword_len, hash); if (HASHITEM_EMPTY(hi)) { sft = xmalloc(offsetof(sftword_T, sft_word) + goodword_len + 1); sft->sft_score = (int16_t)score; @@ -2841,15 +2811,15 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T } // Find the word nr in the soundfold tree. - sfwordnr = soundfold_find(slang, goodword); + int sfwordnr = soundfold_find(slang, goodword); if (sfwordnr < 0) { internal_error("add_sound_suggest()"); return; } // Go over the list of good words that produce this soundfold word - nrline = ml_get_buf(slang->sl_sugbuf, (linenr_T)sfwordnr + 1, false); - orgnr = 0; + char *nrline = ml_get_buf(slang->sl_sugbuf, (linenr_T)sfwordnr + 1, false); + int orgnr = 0; while (*nrline != NUL) { // The wordnr was stored in a minimal nr of bytes as an offset to the // previous wordnr. @@ -2984,24 +2954,20 @@ badword: static int soundfold_find(slang_T *slang, char *word) { idx_T arridx = 0; - int len; int wlen = 0; - int c; char_u *ptr = (char_u *)word; - char_u *byts; - idx_T *idxs; int wordnr = 0; - byts = (char_u *)slang->sl_sbyts; - idxs = slang->sl_sidxs; + char_u *byts = (char_u *)slang->sl_sbyts; + idx_T *idxs = slang->sl_sidxs; for (;;) { // First byte is the number of possible bytes. - len = byts[arridx++]; + int len = byts[arridx++]; // If the first possible byte is a zero the word could end here. // If the word ends we found the word. If not skip the NUL bytes. - c = ptr[wlen]; + int c = ptr[wlen]; if (byts[arridx] == NUL) { if (c == NUL) { break; @@ -3212,19 +3178,17 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i /// @param gap either su_ga or su_sga static void check_suggestions(suginfo_T *su, garray_T *gap) { - suggest_T *stp; char longword[MAXWLEN + 1]; - int len; hlf_T attr; if (gap->ga_len == 0) { return; } - stp = &SUG(*gap, 0); + suggest_T *stp = &SUG(*gap, 0); for (int i = gap->ga_len - 1; i >= 0; i--) { // Need to append what follows to check for "the the". xstrlcpy(longword, stp[i].st_word, MAXWLEN + 1); - len = stp[i].st_wordlen; + int len = stp[i].st_wordlen; xstrlcpy(longword + len, su->su_badptr + stp[i].st_orglen, (size_t)(MAXWLEN - len + 1)); attr = HLF_COUNT; @@ -3243,17 +3207,13 @@ static void check_suggestions(suginfo_T *su, garray_T *gap) /// Add a word to be banned. static void add_banned(suginfo_T *su, char *word) { - char *s; - hash_T hash; - hashitem_T *hi; - - hash = hash_hash(word); + hash_T hash = hash_hash(word); const size_t word_len = strlen(word); - hi = hash_lookup(&su->su_banned, word, word_len, hash); + hashitem_T *hi = hash_lookup(&su->su_banned, word, word_len, hash); if (!HASHITEM_EMPTY(hi)) { // already present return; } - s = xmemdupz(word, word_len); + char *s = xmemdupz(word, word_len); hash_add_item(&su->su_banned, hi, s, hash); } @@ -3273,19 +3233,19 @@ static void rescore_one(suginfo_T *su, suggest_T *stp) { slang_T *slang = stp->st_slang; char sal_badword[MAXWLEN]; - char *p; // Only rescore suggestions that have no sal score yet and do have a // language. if (slang != NULL && !GA_EMPTY(&slang->sl_sal) && !stp->st_had_bonus) { + char_u *p; if (slang == su->su_sallang) { - p = su->su_sal_badword; + p = (char_u *)su->su_sal_badword; } else { spell_soundfold(slang, su->su_fbadword, true, sal_badword); - p = sal_badword; + p = (char_u *)sal_badword; } - stp->st_altscore = stp_sal_score(stp, su, slang, p); + stp->st_altscore = stp_sal_score(stp, su, slang, (char *)p); if (stp->st_altscore == SCORE_MAXMAX) { stp->st_altscore = SCORE_BIG; } @@ -3354,9 +3314,6 @@ static int soundalike_score(char *goodstart, char *badstart) { char *goodsound = goodstart; char *badsound = badstart; - int goodlen; - int badlen; - int n; char *pl, *ps; char *pl2, *ps2; int score = 0; @@ -3389,12 +3346,12 @@ static int soundalike_score(char *goodstart, char *badstart) } } - goodlen = (int)strlen(goodsound); - badlen = (int)strlen(badsound); + int goodlen = (int)strlen(goodsound); + int badlen = (int)strlen(badsound); // Return quickly if the lengths are too different to be fixed by two // changes. - n = goodlen - badlen; + int n = goodlen - badlen; if (n < -2 || n > 2) { return SCORE_MAXMAX; } @@ -3683,25 +3640,21 @@ 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 stackidx; - int bi, gi; int bi2, gi2; int bc, gc; - int score; int score_off; - int minscore; int round; int wbadword[MAXWLEN]; int wgoodword[MAXWLEN]; // Get the characters from the multi-byte strings and put them in an // int array for easy access. - bi = 0; + int bi = 0; for (const char *p = badword; *p != NUL;) { wbadword[bi++] = mb_cptr2char_adv(&p); } wbadword[bi++] = 0; - gi = 0; + int gi = 0; for (const char *p = goodword; *p != NUL;) { wgoodword[gi++] = mb_cptr2char_adv(&p); } @@ -3714,11 +3667,11 @@ static int spell_edit_score_limit_w(slang_T *slang, const char *badword, const c // pushed unto a stack and tried later, some are tried right away. At the // end of the word the score for one alternative is known. The lowest // possible score is stored in "minscore". - stackidx = 0; + int stackidx = 0; bi = 0; gi = 0; - score = 0; - minscore = limit + 1; + int score = 0; + int minscore = limit + 1; for (;;) { // Skip over an equal part, score remains the same. diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 42618e8924..4fecbeebc3 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -979,27 +979,22 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char /// window. static int add_llist_tags(char *tag, int num_matches, char **matches) { - list_T *list; char tag_name[128 + 1]; - char *fname; - char *cmd; int i; char *p; tagptrs_T tagp; - fname = xmalloc(MAXPATHL + 1); - cmd = xmalloc(CMDBUFFSIZE + 1); - list = tv_list_alloc(0); + char *fname = xmalloc(MAXPATHL + 1); + char *cmd = xmalloc(CMDBUFFSIZE + 1); + list_T *list = tv_list_alloc(0); for (i = 0; i < num_matches; i++) { - int len, cmd_len; - long lnum; dict_T *dict; parse_match(matches[i], &tagp); // Save the tag name - len = (int)(tagp.tagname_end - tagp.tagname); + int len = (int)(tagp.tagname_end - tagp.tagname); if (len > 128) { len = 128; } @@ -1016,7 +1011,7 @@ static int add_llist_tags(char *tag, int num_matches, char **matches) // Get the line number or the search pattern used to locate // the tag. - lnum = 0; + long lnum = 0; if (isdigit((uint8_t)(*tagp.command))) { // Line number is used to locate the tag lnum = atol(tagp.command); @@ -1065,7 +1060,7 @@ static int add_llist_tags(char *tag, int num_matches, char **matches) STRCAT(cmd, "\\V"); len += 2; - cmd_len = (int)(cmd_end - cmd_start + 1); + int cmd_len = (int)(cmd_end - cmd_start + 1); if (cmd_len > (CMDBUFFSIZE - 5)) { cmd_len = CMDBUFFSIZE - 5; } @@ -1162,10 +1157,8 @@ void do_tags(exarg_T *eap) // Make sure case is folded to uppercase in comparison (like for 'sort -f') static int tag_strnicmp(char *s1, char *s2, size_t len) { - int i; - while (len > 0) { - i = TOUPPER_ASC((uint8_t)(*s1)) - TOUPPER_ASC((uint8_t)(*s2)); + int i = TOUPPER_ASC((uint8_t)(*s1)) - TOUPPER_ASC((uint8_t)(*s2)); if (i != 0) { return i; // this character different } @@ -1733,14 +1726,13 @@ static tagmatch_status_T findtags_parse_line(findtags_state_T *st, tagptrs_T *ta tagsearch_info_T *sinfo_p) { int status; - int i; - int cmplen; - int tagcmp; // Figure out where the different strings are in this line. // For "normal" tags: Do a quick check if the tag matches. // This speeds up tag searching a lot! if (st->orgpat->headlen) { + int i; + int tagcmp; CLEAR_FIELD(*tagpp); tagpp->tagname = st->lbuf; tagpp->tagname_end = vim_strchr(st->lbuf, TAB); @@ -1751,7 +1743,7 @@ static tagmatch_status_T findtags_parse_line(findtags_state_T *st, tagptrs_T *ta // Skip this line if the length of the tag is different and // there is no regexp, or the tag is too short. - cmplen = (int)(tagpp->tagname_end - tagpp->tagname); + int cmplen = (int)(tagpp->tagname_end - tagpp->tagname); if (p_tl != 0 && cmplen > p_tl) { // adjust for 'taglength' cmplen = (int)p_tl; } @@ -2719,7 +2711,7 @@ static int parse_match(char *lbuf, tagptrs_T *tagp) { int retval; char *p; - char *pc, *pt; + char *pt; tagp->tag_fname = lbuf + 1; lbuf += strlen(tagp->tag_fname) + 2; @@ -2739,6 +2731,7 @@ static int parse_match(char *lbuf, tagptrs_T *tagp) // Try to find a kind field: "kind:<kind>" or just "<kind>" p = tagp->command; if (find_extra(&p) == OK) { + char *pc; tagp->command_end = p; if (p > tagp->command && p[-1] == '|') { tagp->command_end = p - 1; // drop trailing bar @@ -2995,7 +2988,6 @@ static int jumpto_tag(const char *lbuf_arg, int forceit, int keep_help) retval = OK; } else { int found = 1; - char cc; // try again, ignore case now p_ic = true; @@ -3004,7 +2996,7 @@ static int jumpto_tag(const char *lbuf_arg, int forceit, int keep_help) // Failed to find pattern, take a guess: "^func (" found = 2; (void)test_for_static(&tagp); - cc = *tagp.tagname_end; + char cc = *tagp.tagname_end; *tagp.tagname_end = NUL; snprintf(pbuf, LSIZE, "^%s\\s\\*(", tagp.tagname); if (!do_search(NULL, '/', '/', pbuf, (long)1, search_options, NULL)) { @@ -3155,10 +3147,10 @@ static char *expand_tag_fname(char *fname, char *const tag_fname, const bool exp /// file. static int test_for_current(char *fname, char *fname_end, char *tag_fname, char *buf_ffname) { - char c; int retval = false; if (buf_ffname != NULL) { // if the buffer has a name + char c; { c = *fname_end; *fname_end = NUL; @@ -3225,7 +3217,6 @@ static void tagstack_clear_entry(taggy_T *item) /// @param tagnames expand tag names int expand_tags(int tagnames, char *pat, int *num_file, char ***file) { - int i; int extra_flag; char *name_buf; size_t name_buf_size = 100; @@ -3251,7 +3242,7 @@ int expand_tags(int tagnames, char *pat, int *num_file, char ***file) if (ret == OK && !tagnames) { // Reorganize the tags for display and matching as strings of: // "<tagname>\0<kind>\0<filename>\0" - for (i = 0; i < *num_file; i++) { + for (int i = 0; i < *num_file; i++) { size_t len; parse_match((*file)[i], &t_p); @@ -3327,7 +3318,6 @@ int get_tags(list_T *list, char *pat, char *buf_fname) char *full_fname; dict_T *dict; tagptrs_T tp; - bool is_static; ret = find_tags(pat, &num_matches, &matches, TAG_REGEXP | TAG_NOIC, MAXCOL, buf_fname); @@ -3342,7 +3332,7 @@ int get_tags(list_T *list, char *pat, char *buf_fname) (void)parse_result; assert(parse_result == OK); - is_static = test_for_static(&tp); + bool is_static = test_for_static(&tp); // Skip pseudo-tag lines. if (strncmp(tp.tagname, "!_TAG_", 6) == 0) { @@ -3377,7 +3367,7 @@ int get_tags(list_T *list, char *pat, char *buf_fname) // skip "file:" (static tag) p += 4; } else if (!ascii_iswhite(*p)) { - char *s, *n; + char *n; int len; // Add extra field as a dict entry. Fields are @@ -3388,7 +3378,7 @@ int get_tags(list_T *list, char *pat, char *buf_fname) } len = (int)(p - n); if (*p == ':' && len > 0) { - s = ++p; + char *s = ++p; while (*p != NUL && (uint8_t)(*p) >= ' ') { p++; } @@ -3447,7 +3437,6 @@ void get_tagstack(win_T *wp, dict_T *retdict) { list_T *l; int i; - dict_T *d; tv_dict_add_nr(retdict, S_LEN("length"), wp->w_tagstacklen); tv_dict_add_nr(retdict, S_LEN("curidx"), wp->w_tagstackidx + 1); @@ -3455,7 +3444,7 @@ void get_tagstack(win_T *wp, dict_T *retdict) tv_dict_add_list(retdict, S_LEN("items"), l); for (i = 0; i < wp->w_tagstacklen; i++) { - d = tv_dict_alloc(); + dict_T *d = tv_dict_alloc(); tv_list_append_dict(l, d); get_tag_details(&wp->w_tagstack[i], d); } diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 8e786c271c..37f893ecec 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -176,7 +176,6 @@ found: bool findpar(bool *pincl, int dir, long count, int what, bool both) { linenr_T curr; - bool did_skip; // true after separating lines have been skipped bool first; // true on first line linenr_T fold_first; // first line of a closed fold linenr_T fold_last; // last line of a closed fold @@ -186,7 +185,7 @@ bool findpar(bool *pincl, int dir, long count, int what, bool both) curr = curwin->w_cursor.lnum; while (count--) { - did_skip = false; + bool did_skip = false; // true after separating lines have been skipped for (first = true;; first = false) { if (*ml_get(curr) != NUL) { did_skip = true; @@ -324,10 +323,6 @@ static int cls(void) /// @param bigword "W", "E" or "B" int fwd_word(long count, bool bigword, bool eol) { - int sclass; // starting class - int i; - int last_line; - curwin->w_cursor.coladd = 0; cls_bigword = bigword; while (--count >= 0) { @@ -336,12 +331,12 @@ int fwd_word(long count, bool bigword, bool eol) if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) { coladvance(MAXCOL); } - sclass = cls(); + int sclass = cls(); // starting class // We always move at least one character, unless on the last // character in the buffer. - last_line = (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count); - i = inc_cursor(); + int last_line = (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count); + int i = inc_cursor(); if (i == -1 || (i >= 1 && last_line)) { // started at last char in file return FAIL; } @@ -493,13 +488,11 @@ finished: /// @return FAIL if start of the file was reached. int bckend_word(long count, bool bigword, bool eol) { - int sclass; // starting class - int i; - curwin->w_cursor.coladd = 0; cls_bigword = bigword; while (--count >= 0) { - sclass = cls(); + int i; + int sclass = cls(); // starting class if ((i = dec_cursor()) == -1) { return FAIL; } @@ -562,10 +555,8 @@ static void back_in_line(void) static void find_first_blank(pos_T *posp) { - int c; - while (decl(posp) != -1) { - c = gchar_pos(posp); + int c = gchar_pos(posp); if (!ascii_iswhite(c)) { incl(posp); break; @@ -598,7 +589,6 @@ static void findsent_forward(long count, bool at_start_sent) int current_word(oparg_T *oap, long count, bool include, bool bigword) { pos_T start_pos; - pos_T pos; bool inclusive = true; int include_white = false; @@ -703,7 +693,7 @@ int current_word(oparg_T *oap, long count, bool include, bool bigword) // word). Also when "2daw" deletes "word." at the end of the line // (cursor is at start of next line). // But don't delete white space at start of line (indent). - pos = curwin->w_cursor; // save cursor position + pos_T pos = curwin->w_cursor; // save cursor position curwin->w_cursor = start_pos; if (oneleft() == OK) { back_in_line(); @@ -1042,7 +1032,6 @@ static bool in_html_tag(bool end_tag) { char *line = get_cursor_line_ptr(); char *p; - int c; int lc = NUL; pos_T pos; @@ -1078,7 +1067,7 @@ static bool in_html_tag(bool end_tag) if (inc(&pos) < 0) { return false; } - c = (uint8_t)(*ml_get_pos(&pos)); + int c = (uint8_t)(*ml_get_pos(&pos)); if (c == '>') { break; } @@ -1443,10 +1432,8 @@ extend: /// @return column number of "quotechar" or -1 when not found. static int find_next_quote(char *line, int col, int quotechar, char *escape) { - int c; - for (;;) { - c = (uint8_t)line[col]; + int c = (uint8_t)line[col]; if (c == NUL) { return -1; } else if (escape != NULL && vim_strchr(escape, c)) { @@ -1471,12 +1458,10 @@ static int find_next_quote(char *line, int col, int quotechar, char *escape) /// @return the found column or zero. static int find_prev_quote(char *line, int col_start, int quotechar, char *escape) { - int n; - while (col_start > 0) { col_start--; col_start -= utf_head_off(line, line + col_start); - n = 0; + int n = 0; if (escape != NULL) { while (col_start - n > 0 && vim_strchr(escape, (uint8_t)line[col_start - n - 1]) != NULL) { |