refactor: reduce scope of locals as per the style guide 3 (#22221)

refactor: reduce scope of locals as per the style guide
This commit is contained in:
dundargoc 2023-02-12 18:48:49 +01:00 committed by GitHub
parent 2b1c07a1d4
commit 5f72ab77bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 147 additions and 275 deletions

View File

@ -75,7 +75,6 @@ void do_debug(char *cmd)
tasave_T typeaheadbuf;
bool typeahead_saved = false;
int save_ignore_script = 0;
int n;
char *cmdline = NULL;
char *p;
char *tail = NULL;
@ -146,7 +145,7 @@ void do_debug(char *cmd)
}
// don't debug any function call, e.g. from an expression mapping
n = debug_break_level;
int n = debug_break_level;
debug_break_level = -1;
xfree(cmdline);

View File

@ -2652,8 +2652,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
bool added = true;
linenr_T off = lnum - dp->df_lnum[idx];
int i;
for (i = 0; i < DB_COUNT; i++) {
for (int i = 0; i < DB_COUNT; i++) {
if ((curtab->tp_diffbuf[i] != NULL) && (i != idx)) {
// Skip lines that are not in the other change (filler lines).
if (off >= dp->df_count[i]) {

View File

@ -1725,9 +1725,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
// At start of the line we can have a composing char.
// Draw it as a space with a composing char.
if (utf_iscomposing(mb_c)) {
int i;
for (i = MAX_MCO - 1; i > 0; i--) {
for (int i = MAX_MCO - 1; i > 0; i--) {
u8cc[i] = u8cc[i - 1];
}
u8cc[0] = mb_c;
@ -2102,7 +2100,6 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
n_extra = tab_len;
} else {
char *p;
int i;
int saved_nextra = n_extra;
if (vcol_off > 0) {
@ -2131,7 +2128,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
p[len] = NUL;
xfree(p_extra_free);
p_extra_free = p;
for (i = 0; i < tab_len; i++) {
for (int i = 0; i < tab_len; i++) {
if (*p == NUL) {
tab_len = i;
break;
@ -2486,7 +2483,6 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
|| draw_color_col || line_attr_lowprio || line_attr
|| diff_hlf != (hlf_T)0 || has_virttext)) {
int rightmost_vcol = 0;
int i;
if (wp->w_p_cuc) {
rightmost_vcol = wp->w_virtcol;
@ -2494,7 +2490,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
if (draw_color_col) {
// determine rightmost colorcolumn to possibly draw
for (i = 0; color_cols[i] >= 0; i++) {
for (int i = 0; color_cols[i] >= 0; i++) {
if (rightmost_vcol < color_cols[i]) {
rightmost_vcol = color_cols[i];
}

View File

@ -1949,7 +1949,6 @@ void set_context_for_expression(expand_T *xp, char *arg, cmdidx_T cmdidx)
FUNC_ATTR_NONNULL_ALL
{
bool got_eq = false;
int c;
char *p;
if (cmdidx == CMD_let || cmdidx == CMD_const) {
@ -1970,7 +1969,7 @@ void set_context_for_expression(expand_T *xp, char *arg, cmdidx_T cmdidx)
: EXPAND_EXPRESSION;
}
while ((xp->xp_pattern = strpbrk(arg, "\"'+-*/%.=!?~|&$([<>,#")) != NULL) {
c = (uint8_t)(*xp->xp_pattern);
int c = (uint8_t)(*xp->xp_pattern);
if (c == '&') {
c = (uint8_t)xp->xp_pattern[1];
if (c == '&') {
@ -2310,7 +2309,6 @@ int eval0(char *arg, typval_T *rettv, char **nextcmd, int evaluate)
/// @return OK or FAIL.
int eval1(char **arg, typval_T *rettv, int evaluate)
{
bool result;
typval_T var2;
// Get the first variable.
@ -2319,7 +2317,7 @@ int eval1(char **arg, typval_T *rettv, int evaluate)
}
if ((*arg)[0] == '?') {
result = false;
bool result = false;
if (evaluate) {
bool error = false;
@ -2499,7 +2497,6 @@ static int eval4(char **arg, typval_T *rettv, int evaluate)
char *p;
exprtype_T type = EXPR_UNKNOWN;
int len = 2;
bool ic;
// Get the first variable.
if (eval5(arg, rettv, evaluate) == FAIL) {
@ -2552,6 +2549,7 @@ static int eval4(char **arg, typval_T *rettv, int evaluate)
// If there is a comparative operator, use it.
if (type != EXPR_UNKNOWN) {
bool ic;
// extra question mark appended: ignore case
if (p[len] == '?') {
ic = true;
@ -2594,7 +2592,6 @@ static int eval5(char **arg, typval_T *rettv, int evaluate)
{
typval_T var2;
typval_T var3;
int op;
varnumber_T n1, n2;
float_T f1 = 0, f2 = 0;
char *p;
@ -2606,7 +2603,7 @@ static int eval5(char **arg, typval_T *rettv, int evaluate)
// Repeat computing, until no '+', '-' or '.' is following.
for (;;) {
op = (char_u)(**arg);
int op = (char_u)(**arg);
if (op != '+' && op != '-' && op != '.') {
break;
}
@ -3276,7 +3273,6 @@ static int eval_index(char **arg, typval_T *rettv, int evaluate, int verbose)
{
bool empty1 = false;
bool empty2 = false;
int n1, n2 = 0;
ptrdiff_t len = -1;
int range = false;
char *key = NULL;
@ -3373,7 +3369,8 @@ static int eval_index(char **arg, typval_T *rettv, int evaluate, int verbose)
}
if (evaluate) {
n1 = 0;
int n2 = 0;
int n1 = 0;
if (!empty1 && rettv->v_type != VAR_DICT && !tv_is_luafunc(rettv)) {
n1 = (int)tv_get_number(&var1);
tv_clear(&var1);
@ -4784,8 +4781,6 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map)
const char *const arg_errmsg = (map
? N_("map() argument")
: N_("filter() argument"));
int save_did_emsg;
int idx = 0;
// Always return the first argument, also on failure.
tv_copy(&argvars[0], rettv);
@ -4815,12 +4810,13 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map)
// message. Avoid a misleading error message for an empty string that
// was not passed as argument.
if (expr->v_type != VAR_UNKNOWN) {
int idx = 0;
typval_T save_val;
prepare_vimvar(VV_VAL, &save_val);
// We reset "did_emsg" to be able to detect whether an error
// occurred during evaluation of the expression.
save_did_emsg = did_emsg;
int save_did_emsg = did_emsg;
did_emsg = false;
typval_T save_key;
@ -8064,7 +8060,6 @@ repeat:
/// @return an allocated string, NULL for error.
char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, const char *flags)
{
int sublen;
regmatch_T regmatch;
garray_T ga;
char *zero_width = NULL;
@ -8080,6 +8075,7 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, const char
regmatch.rm_ic = p_ic;
regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
if (regmatch.regprog != NULL) {
int sublen;
char *tail = str;
char *end = str + strlen(str);
while (vim_regexec_nl(&regmatch, str, (colnr_T)(tail - str))) {

View File

@ -1154,7 +1154,6 @@ void do_throw(cstack_T *cstack)
{
int inactivate_try = false;
//
// Cleanup and deactivate up to the next surrounding try conditional that
// is not in its finally clause. Normally, do not deactivate the try
// conditional itself, so that its ACTIVE flag can be tested below. But
@ -1162,7 +1161,7 @@ void do_throw(cstack_T *cstack)
// deactivate the try conditional, too, as if the conversion had been done,
// and reset the did_emsg or got_int flag, so this won't happen again at
// the next surrounding try conditional.
//
#ifndef THROW_ON_ERROR_TRUE
if (did_emsg && !THROW_ON_ERROR) {
inactivate_try = true;

View File

@ -661,7 +661,6 @@ static int read_redo(bool init, bool old_redo)
int c;
int n;
char_u buf[MB_MAXBYTES + 1];
int i;
if (init) {
bp = old_redo ? old_redobuff.bh_first.b_next : redobuff.bh_first.b_next;
@ -682,7 +681,7 @@ static int read_redo(bool init, bool old_redo)
} else {
n = 1;
}
for (i = 0;; i++) {
for (int i = 0;; i++) {
if (c == K_SPECIAL) { // special key or escaped K_SPECIAL
c = TO_SPECIAL(p[1], p[2]);
p += 2;
@ -857,7 +856,6 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent)
{
char_u *s1, *s2;
int addlen;
int i;
int val;
int nrm;
@ -947,7 +945,7 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent)
} else {
nrm = noremap;
}
for (i = 0; i < addlen; i++) {
for (int i = 0; i < addlen; i++) {
typebuf.tb_noremap[typebuf.tb_off + i + offset] =
(uint8_t)((--nrm >= 0) ? val : RM_YES);
}
@ -1426,7 +1424,6 @@ int vgetc(void)
} else {
int c2;
int n;
int i;
// number of characters recorded from the last vgetc() call
static size_t last_vgetc_recorded_len = 0;
@ -1552,7 +1549,7 @@ int vgetc(void)
if ((n = MB_BYTE2LEN_CHECK(c)) > 1) {
no_mapping++;
buf[0] = (char_u)c;
for (i = 1; i < n; i++) {
for (int i = 1; i < n; i++) {
buf[i] = (char_u)vgetorpeek(true);
if (buf[i] == K_SPECIAL) {
// Must be a K_SPECIAL - KS_SPECIAL - KE_FILLER sequence,
@ -2904,13 +2901,12 @@ int fix_input_buffer(char *buf, int len)
}
// Reading from script, need to process special bytes
int i;
char_u *p = (char_u *)buf;
// Two characters are special: NUL and K_SPECIAL.
// Replace NUL by K_SPECIAL KS_ZERO KE_FILLER
// Replace K_SPECIAL by K_SPECIAL KS_SPECIAL KE_FILLER
for (i = len; --i >= 0; p++) {
for (int i = len; --i >= 0; p++) {
if (p[0] == NUL
|| (p[0] == K_SPECIAL
&& (i < 2 || p[1] != KS_EXTRA))) {

View File

@ -805,7 +805,6 @@ void grid_assign_handle(ScreenGrid *grid)
/// 'row', 'col' and 'end' are relative to the start of the region.
void grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col, int width)
{
int i;
int j;
unsigned temp;
@ -820,7 +819,7 @@ void grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col,
// Shift line_offset[] line_count down to reflect the inserted lines.
// Clear the inserted lines.
for (i = 0; i < line_count; i++) {
for (int i = 0; i < line_count; i++) {
if (width != grid->cols) {
// need to copy part of a line
j = end - 1 - i;
@ -855,7 +854,6 @@ void grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col,
void grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col, int width)
{
int j;
int i;
unsigned temp;
int row_off = 0;
@ -869,7 +867,7 @@ void grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col,
// Now shift line_offset[] line_count up to reflect the deleted lines.
// Clear the inserted lines.
for (i = 0; i < line_count; i++) {
for (int i = 0; i < line_count; i++) {
if (width != grid->cols) {
// need to copy part of a line
j = row + i;

View File

@ -47,19 +47,14 @@
void ex_help(exarg_T *eap)
{
char *arg;
char *tag;
FILE *helpfd; // file descriptor of help file
int n;
int i;
win_T *wp;
int num_matches;
char **matches;
char *p;
int empty_fnum = 0;
int alt_fnum = 0;
buf_T *buf;
int len;
char *lang;
const bool old_KeyTyped = KeyTyped;
if (eap != NULL) {
@ -88,13 +83,13 @@ void ex_help(exarg_T *eap)
}
// remove trailing blanks
p = arg + strlen(arg) - 1;
char *p = arg + strlen(arg) - 1;
while (p > arg && ascii_iswhite(*p) && p[-1] != '\\') {
*p-- = NUL;
}
// Check for a specified language
lang = check_help_lang(arg);
char *lang = check_help_lang(arg);
// When no argument given go to the index.
if (*arg == NUL) {
@ -102,9 +97,9 @@ void ex_help(exarg_T *eap)
}
// Check if there is a match for the argument.
n = find_help_tags(arg, &num_matches, &matches, eap != NULL && eap->forceit);
int n = find_help_tags(arg, &num_matches, &matches, eap != NULL && eap->forceit);
i = 0;
int i = 0;
if (n != FAIL && lang != NULL) {
// Find first item with the requested language.
for (i = 0; i < num_matches; i++) {
@ -128,7 +123,7 @@ void ex_help(exarg_T *eap)
}
// The first match (in the requested language) is the best match.
tag = xstrdup(matches[i]);
char *tag = xstrdup(matches[i]);
FreeWild(num_matches, matches);
// Re-use an existing help window or open a new one.
@ -259,11 +254,8 @@ char *check_help_lang(char *arg)
int help_heuristic(char *matched_string, int offset, int wrong_case)
FUNC_ATTR_PURE
{
int num_letters;
char *p;
num_letters = 0;
for (p = matched_string; *p; p++) {
int num_letters = 0;
for (char *p = matched_string; *p; p++) {
if (ASCII_ISALNUM(*p)) {
num_letters++;
}
@ -298,11 +290,8 @@ int help_heuristic(char *matched_string, int offset, int wrong_case)
/// that has been put after the tagname by find_tags().
static int help_compare(const void *s1, const void *s2)
{
char *p1;
char *p2;
p1 = *(char **)s1 + strlen(*(char **)s1) + 1;
p2 = *(char **)s2 + strlen(*(char **)s2) + 1;
char *p1 = *(char **)s1 + strlen(*(char **)s1) + 1;
char *p2 = *(char **)s2 + strlen(*(char **)s2) + 1;
// Compare by help heuristic number first.
int cmp = strcmp(p1, p2);
@ -320,8 +309,6 @@ static int help_compare(const void *s1, const void *s2)
/// When "keep_lang" is true try keeping the language of the current buffer.
int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep_lang)
{
int i;
// Specific tags that either have a specific replacement or won't go
// through the generic rules.
static char *(except_tbl[][2]) = {
@ -379,7 +366,7 @@ int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep
// When the string starting with "expr-" and containing '?' and matches
// the table, it is taken literally (but ~ is escaped). Otherwise '?'
// is recognized as a wildcard.
for (i = (int)ARRAY_SIZE(expr_table); --i >= 0;) {
for (int i = (int)ARRAY_SIZE(expr_table); --i >= 0;) {
if (strcmp(arg + 5, expr_table[i]) == 0) {
for (int si = 0, di = 0;; si++) {
if (arg[si] == '~') {
@ -396,7 +383,7 @@ int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep
} else {
// Recognize a few exceptions to the rule. Some strings that contain
// '*'are changed to "star", otherwise '*' is recognized as a wildcard.
for (i = 0; except_tbl[i][0] != NULL; i++) {
for (int i = 0; except_tbl[i][0] != NULL; i++) {
if (strcmp(arg, except_tbl[i][0]) == 0) {
STRCPY(d, except_tbl[i][1]);
break;

View File

@ -637,7 +637,6 @@ int find_special_key(const char **const srcp, const size_t src_len, int *const m
const bool in_string = flags & FSK_IN_STRING;
int modifiers;
int bit;
int key;
uvarnumber_T n;
int l;
@ -685,6 +684,7 @@ 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;
// Which modifiers are given?

View File

@ -616,11 +616,8 @@ fmarkv_T mark_view_make(linenr_T topline, pos_T pos)
/// @return next mark or NULL if no mark is found.
fmark_T *getnextmark(pos_T *startpos, int dir, int begin_line)
{
int i;
fmark_T *result = NULL;
pos_T pos;
pos = *startpos;
pos_T pos = *startpos;
if (dir == BACKWARD && begin_line) {
pos.col = 0;
@ -628,7 +625,7 @@ fmark_T *getnextmark(pos_T *startpos, int dir, int begin_line)
pos.col = MAXCOL;
}
for (i = 0; i < NMARKS; i++) {
for (int i = 0; i < NMARKS; i++) {
if (curbuf->b_namedm[i].mark.lnum > 0) {
if (dir == FORWARD) {
if ((result == NULL || lt(curbuf->b_namedm[i].mark, result->mark))
@ -685,18 +682,17 @@ static void fname2fnum(xfmark_T *fm)
void fmarks_check_names(buf_T *buf)
{
char *name = buf->b_ffname;
int i;
if (buf->b_ffname == NULL) {
return;
}
for (i = 0; i < NGLOBALMARKS; i++) {
for (int i = 0; i < NGLOBALMARKS; i++) {
fmarks_check_one(&namedfm[i], name, buf);
}
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
for (i = 0; i < wp->w_jumplistlen; i++) {
for (int i = 0; i < wp->w_jumplistlen; i++) {
fmarks_check_one(&wp->w_jumplist[i], name, buf);
}
}
@ -820,7 +816,6 @@ static char *mark_line(pos_T *mp, int lead_len)
void ex_marks(exarg_T *eap)
{
char *arg = eap->arg;
int i;
char *name;
pos_T *posp, *startp, *endp;
@ -829,10 +824,10 @@ void ex_marks(exarg_T *eap)
}
show_one_mark('\'', arg, &curwin->w_pcmark, NULL, true);
for (i = 0; i < NMARKS; i++) {
for (int i = 0; i < NMARKS; i++) {
show_one_mark(i + 'a', arg, &curbuf->b_namedm[i].mark, NULL, true);
}
for (i = 0; i < NGLOBALMARKS; i++) {
for (int i = 0; i < NGLOBALMARKS; i++) {
if (namedfm[i].fmark.fnum != 0) {
name = fm_getname(&namedfm[i].fmark, 15);
} else {
@ -918,7 +913,6 @@ void ex_delmarks(exarg_T *eap)
{
char *p;
int from, to;
int i;
int lower;
int digit;
int n;
@ -953,7 +947,7 @@ void ex_delmarks(exarg_T *eap)
from = to = (uint8_t)(*p);
}
for (i = from; i <= to; i++) {
for (int i = from; i <= to; i++) {
if (lower) {
curbuf->b_namedm[i - 'a'].mark.lnum = 0;
} else {
@ -997,13 +991,12 @@ void ex_delmarks(exarg_T *eap)
// print the jumplist
void ex_jumps(exarg_T *eap)
{
int i;
char *name;
cleanup_jumplist(curwin, true);
// Highlight title
msg_puts_title(_("\n jump line col file/text"));
for (i = 0; i < curwin->w_jumplistlen && !got_int; i++) {
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);
@ -1050,13 +1043,12 @@ void ex_clearjumps(exarg_T *eap)
// print the changelist
void ex_changes(exarg_T *eap)
{
int i;
char *name;
// Highlight title
msg_puts_title(_("\nchange line col text"));
for (i = 0; i < curbuf->b_changelistlen && !got_int; i++) {
for (int i = 0; i < curbuf->b_changelistlen && !got_int; i++) {
if (curbuf->b_changelist[i].mark.lnum != 0) {
msg_putchar('\n');
if (got_int) {
@ -1137,7 +1129,6 @@ void mark_adjust_nofold(linenr_T line1, linenr_T line2, linenr_T amount, linenr_
static void mark_adjust_internal(linenr_T line1, linenr_T line2, linenr_T amount,
linenr_T amount_after, bool adjust_folds, ExtmarkOp op)
{
int i;
int fnum = curbuf->b_fnum;
linenr_T *lp;
static pos_T initpos = { 1, 0, 0 };
@ -1148,13 +1139,13 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, linenr_T amount
if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) {
// named marks, lower case and upper case
for (i = 0; i < NMARKS; i++) {
for (int i = 0; i < NMARKS; i++) {
ONE_ADJUST(&(curbuf->b_namedm[i].mark.lnum));
if (namedfm[i].fmark.fnum == fnum) {
ONE_ADJUST_NODEL(&(namedfm[i].fmark.mark.lnum));
}
}
for (i = NMARKS; i < NGLOBALMARKS; i++) {
for (int i = NMARKS; i < NGLOBALMARKS; i++) {
if (namedfm[i].fmark.fnum == fnum) {
ONE_ADJUST_NODEL(&(namedfm[i].fmark.mark.lnum));
}
@ -1172,7 +1163,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, linenr_T amount
}
// list of change positions
for (i = 0; i < curbuf->b_changelistlen; i++) {
for (int i = 0; i < curbuf->b_changelistlen; i++) {
ONE_ADJUST_NODEL(&(curbuf->b_changelist[i].mark.lnum));
}
@ -1216,7 +1207,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, linenr_T amount
if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) {
// Marks in the jumplist. When deleting lines, this may create
// duplicate marks in the jumplist, they will be removed later.
for (i = 0; i < win->w_jumplistlen; i++) {
for (int i = 0; i < win->w_jumplistlen; i++) {
if (win->w_jumplist[i].fmark.fnum == fnum) {
ONE_ADJUST_NODEL(&(win->w_jumplist[i].fmark.mark.lnum));
}
@ -1226,7 +1217,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, linenr_T amount
if (win->w_buffer == curbuf) {
if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) {
// marks in the tag stack
for (i = 0; i < win->w_tagstacklen; i++) {
for (int i = 0; i < win->w_tagstacklen; i++) {
if (win->w_tagstack[i].fmark.fnum == fnum) {
ONE_ADJUST_NODEL(&(win->w_tagstack[i].fmark.mark.lnum));
}
@ -1308,7 +1299,6 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, linenr_T amount
void mark_col_adjust(linenr_T lnum, colnr_T mincol, linenr_T lnum_amount, long col_amount,
int spaces_removed)
{
int i;
int fnum = curbuf->b_fnum;
pos_T *posp;
@ -1316,13 +1306,13 @@ void mark_col_adjust(linenr_T lnum, colnr_T mincol, linenr_T lnum_amount, long c
return; // nothing to do
}
// named marks, lower case and upper case
for (i = 0; i < NMARKS; i++) {
for (int i = 0; i < NMARKS; i++) {
COL_ADJUST(&(curbuf->b_namedm[i].mark));
if (namedfm[i].fmark.fnum == fnum) {
COL_ADJUST(&(namedfm[i].fmark.mark));
}
}
for (i = NMARKS; i < NGLOBALMARKS; i++) {
for (int i = NMARKS; i < NGLOBALMARKS; i++) {
if (namedfm[i].fmark.fnum == fnum) {
COL_ADJUST(&(namedfm[i].fmark.mark));
}
@ -1335,7 +1325,7 @@ void mark_col_adjust(linenr_T lnum, colnr_T mincol, linenr_T lnum_amount, long c
COL_ADJUST(&(curbuf->b_last_change.mark));
// list of change positions
for (i = 0; i < curbuf->b_changelistlen; i++) {
for (int i = 0; i < curbuf->b_changelistlen; i++) {
COL_ADJUST(&(curbuf->b_changelist[i].mark));
}
@ -1355,7 +1345,7 @@ void mark_col_adjust(linenr_T lnum, colnr_T mincol, linenr_T lnum_amount, long c
// Adjust items in all windows related to the current buffer.
FOR_ALL_WINDOWS_IN_TAB(win, curtab) {
// marks in the jumplist
for (i = 0; i < win->w_jumplistlen; i++) {
for (int i = 0; i < win->w_jumplistlen; i++) {
if (win->w_jumplist[i].fmark.fnum == fnum) {
COL_ADJUST(&(win->w_jumplist[i].fmark.mark));
}
@ -1363,7 +1353,7 @@ void mark_col_adjust(linenr_T lnum, colnr_T mincol, linenr_T lnum_amount, long c
if (win->w_buffer == curbuf) {
// marks in the tag stack
for (i = 0; i < win->w_tagstacklen; i++) {
for (int i = 0; i < win->w_tagstacklen; i++) {
if (win->w_tagstack[i].fmark.fnum == fnum) {
COL_ADJUST(&(win->w_tagstack[i].fmark.mark));
}
@ -1456,9 +1446,7 @@ void cleanup_jumplist(win_T *wp, bool loadfiles)
// Copy the jumplist from window "from" to window "to".
void copy_jumplist(win_T *from, win_T *to)
{
int i;
for (i = 0; i < from->w_jumplistlen; i++) {
for (int i = 0; i < from->w_jumplistlen; i++) {
to->w_jumplist[i] = from->w_jumplist[i];
if (from->w_jumplist[i].fname != NULL) {
to->w_jumplist[i].fname = xstrdup(from->w_jumplist[i].fname);
@ -1670,9 +1658,7 @@ bool mark_set_local(const char name, buf_T *const buf, const fmark_T fm, const b
// Free items in the jumplist of window "wp".
void free_jumplist(win_T *wp)
{
int i;
for (i = 0; i < wp->w_jumplistlen; i++) {
for (int i = 0; i < wp->w_jumplistlen; i++) {
free_xfmark(wp->w_jumplist[i]);
}
wp->w_jumplistlen = 0;

View File

@ -847,7 +847,6 @@ int utf_byte2len(int b)
int utf_ptr2len_len(const char *p, int size)
{
int len;
int i;
int m;
len = utf8len_tab[(uint8_t)(*p)];
@ -859,7 +858,7 @@ int utf_ptr2len_len(const char *p, int size)
} else {
m = len;
}
for (i = 1; i < m; i++) {
for (int i = 1; i < m; i++) {
if ((p[i] & 0xc0) != 0x80) {
return 1;
}
@ -1530,7 +1529,6 @@ void show_utf8(void)
int rlen = 0;
char *line;
int clen;
int i;
// Get the byte length of the char under the cursor, including composing
// characters.
@ -1542,7 +1540,7 @@ void show_utf8(void)
}
clen = 0;
for (i = 0; i < len; i++) {
for (int i = 0; i < len; i++) {
if (clen == 0) {
// start of (composing) character, get its length
if (i > 0) {
@ -2171,9 +2169,7 @@ char *enc_canonize(char *enc)
/// Returns -1 when not found.
static int enc_alias_search(const char *name)
{
int i;
for (i = 0; enc_alias_table[i].name != NULL; i++) {
for (int i = 0; enc_alias_table[i].name != NULL; i++) {
if (strcmp(name, enc_alias_table[i].name) == 0) {
return enc_alias_table[i].canon;
}

View File

@ -281,7 +281,6 @@ static int add_menu_path(const char *const menu_path, vimmenu_T *menuarg, const
char *next_name;
char c;
char d;
int i;
int pri_idx = 0;
int old_modes = 0;
int amenu;
@ -411,7 +410,7 @@ static int add_menu_path(const char *const menu_path, vimmenu_T *menuarg, const
p = (call_data == NULL) ? NULL : xstrdup(call_data);
// loop over all modes, may add more than one
for (i = 0; i < MENU_MODES; i++) {
for (int i = 0; i < MENU_MODES; i++) {
if (modes & (1 << i)) {
// free any old menu
free_menu_string(menu, i);
@ -617,10 +616,7 @@ static int remove_menu(vimmenu_T **menup, char *name, int modes, bool silent)
// Free the given menu structure and remove it from the linked list.
static void free_menu(vimmenu_T **menup)
{
int i;
vimmenu_T *menu;
menu = *menup;
vimmenu_T *menu = *menup;
// Don't change *menup until after calling gui_mch_destroy_menu(). The
// MacOS code needs the original structure to properly delete the menu.
@ -630,7 +626,7 @@ static void free_menu(vimmenu_T **menup)
xfree(menu->en_name);
xfree(menu->en_dname);
xfree(menu->actext);
for (i = 0; i < MENU_MODES; i++) {
for (int i = 0; i < MENU_MODES; i++) {
free_menu_string(menu, i);
}
xfree(menu);
@ -640,9 +636,8 @@ static void free_menu(vimmenu_T **menup)
static void free_menu_string(vimmenu_T *menu, int idx)
{
int count = 0;
int i;
for (i = 0; i < MENU_MODES; i++) {
for (int i = 0; i < MENU_MODES; i++) {
if (menu->strings[i] == menu->strings[idx]) {
count++;
}
@ -662,13 +657,11 @@ static void free_menu_string(vimmenu_T *menu, int idx)
/// @see menu_get
static dict_T *menu_get_recursive(const vimmenu_T *menu, int modes)
{
dict_T *dict;
if (!menu || (menu->modes & modes) == 0x0) {
return NULL;
}
dict = tv_dict_alloc();
dict_T *dict = tv_dict_alloc();
tv_dict_add_str(dict, S_LEN("name"), menu->dname);
tv_dict_add_nr(dict, S_LEN("priority"), (int)menu->priority);
tv_dict_add_nr(dict, S_LEN("hidden"), menu_is_hidden(menu->dname));

View File

@ -286,7 +286,6 @@ int do_in_path(char *path, char *name, int flags, DoInRuntimepathCB callback, vo
char *buf = xmallocz(MAXPATHL);
{
char *tail;
int i;
if (p_verbose > 10 && name != NULL) {
verbose_enter();
smsg(_("Searching for \"%s\" in \"%s\""), name, path);
@ -335,7 +334,7 @@ int do_in_path(char *path, char *name, int flags, DoInRuntimepathCB callback, vo
// Expand wildcards, invoke the callback for each match.
if (gen_expand_wildcards(1, &buf, &num_files, &files, ew_flags) == OK) {
for (i = 0; i < num_files; i++) {
for (int i = 0; i < num_files; i++) {
(*callback)(files[i], cookie);
did_one = true;
if (!(flags & DIP_ALL)) {
@ -416,7 +415,6 @@ int do_in_cached_path(char *name, int flags, DoInRuntimepathCB callback, void *c
char *tail;
int num_files;
char **files;
int i;
bool did_one = false;
char buf[MAXPATHL];
@ -469,7 +467,7 @@ int do_in_cached_path(char *name, int flags, DoInRuntimepathCB callback, void *c
// Expand wildcards, invoke the callback for each match.
char *(pat[]) = { buf };
if (gen_expand_wildcards(1, pat, &num_files, &files, ew_flags) == OK) {
for (i = 0; i < num_files; i++) {
for (int i = 0; i < num_files; i++) {
(*callback)(files[i], cookie);
did_one = true;
if (!(flags & DIP_ALL)) {

View File

@ -248,11 +248,8 @@ size_t fill_foldcolumn(char *p, win_T *wp, foldinfo_T foldinfo, linenr_T lnum)
/// Only works for single-byte characters (e.g., numbers).
void rl_mirror(char *str)
{
char *p1, *p2;
char t;
for (p1 = str, p2 = str + strlen(str) - 1; p1 < p2; p1++, p2--) {
t = *p1;
for (char *p1 = str, *p2 = str + strlen(str) - 1; p1 < p2; p1++, p2--) {
char t = *p1;
*p1 = *p2;
*p2 = t;
}
@ -264,9 +261,7 @@ void rl_mirror(char *str)
/// line of the window right of it. If not, then it's a vertical separator.
bool stl_connected(win_T *wp)
{
frame_T *fr;
fr = wp->w_frame;
frame_T *fr = wp->w_frame;
while (fr->fr_parent != NULL) {
if (fr->fr_parent->fr_layout == FR_COL) {
if (fr->fr_next != NULL) {
@ -437,11 +432,7 @@ bool skip_showmode(void)
/// @return the length of the message (0 if no message).
int showmode(void)
{
bool need_clear;
int length = 0;
int do_mode;
int attr;
int sub_attr;
if (ui_has(kUIMessages) && clear_cmdline) {
msg_ext_clear(true);
@ -452,12 +443,13 @@ int showmode(void)
msg_grid_validate();
do_mode = ((p_smd && msg_silent == 0)
&& ((State & MODE_TERMINAL)
|| (State & MODE_INSERT)
|| restart_edit != NUL
|| VIsual_active));
int do_mode = ((p_smd && msg_silent == 0)
&& ((State & MODE_TERMINAL)
|| (State & MODE_INSERT)
|| restart_edit != NUL
|| VIsual_active));
if (do_mode || reg_recording != 0) {
int sub_attr;
if (skip_showmode()) {
return 0; // show mode later
}
@ -468,14 +460,14 @@ int showmode(void)
check_for_delay(false);
// if the cmdline is more than one line high, erase top lines
need_clear = clear_cmdline;
bool need_clear = clear_cmdline;
if (clear_cmdline && cmdline_row < Rows - 1) {
msg_clr_cmdline(); // will reset clear_cmdline
}
// Position on the last line in the window, column 0
msg_pos_mode();
attr = HL_ATTR(HLF_CM); // Highlight mode
int attr = HL_ATTR(HLF_CM); // Highlight mode
// When the screen is too narrow to show the entire mode message,
// avoid scrolling and truncate instead.

View File

@ -136,14 +136,12 @@ typedef struct SearchedFile {
int search_regcomp(char *pat, char **used_pat, int pat_save, int pat_use, int options,
regmmatch_T *regmatch)
{
int magic;
int i;
rc_did_emsg = false;
magic = magic_isset();
int magic = magic_isset();
// If no pattern given, use a previously defined pattern.
if (pat == NULL || *pat == NUL) {
int i;
if (pat_use == RE_LAST) {
i = last_idx;
} else {
@ -557,8 +555,6 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
lpos_T endpos;
lpos_T matchpos;
int loop;
pos_T start_pos;
int at_first_line;
int extra_col;
int start_char_len;
bool match_ok;
@ -611,9 +607,9 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
extra_col = (options & SEARCH_START) ? start_char_len : 0;
}
start_pos = *pos; // remember start pos for detecting no match
pos_T start_pos = *pos; // remember start pos for detecting no match
found = 0; // default: not found
at_first_line = true; // default: start in first line
int at_first_line = true; // default: start in first line
if (pos->lnum == 0) { // correct lnum for when starting in line 0
pos->lnum = 1;
pos->col = 0;
@ -1028,7 +1024,6 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char *pat, long count, i
{
pos_T pos; // position of the last match
char *searchstr;
struct soffset old_off;
int retval; // Return value
char *p;
int64_t c;
@ -1047,7 +1042,7 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char *pat, long count, i
// Save the values for when (options & SEARCH_KEEP) is used.
// (there is no "if ()" around this because gcc wants them initialized)
old_off = spats[0].off;
struct soffset old_off = spats[0].off;
pos = curwin->w_cursor; // start searching at the cursor position
@ -1434,8 +1429,6 @@ end_do_search:
int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char *pat)
{
linenr_T start = 0;
char *ptr;
char *p;
if (buf->b_ml.ml_line_count == 0) {
return FAIL;
@ -1469,8 +1462,8 @@ int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char *pat)
if (start == 0) {
start = pos->lnum;
}
ptr = ml_get_buf(buf, pos->lnum, false);
p = skipwhite(ptr);
char *ptr = ml_get_buf(buf, pos->lnum, false);
char *p = skipwhite(ptr);
pos->col = (colnr_T)(p - ptr);
// when adding lines the matching line may be empty but it is not
@ -1503,9 +1496,6 @@ int searchc(cmdarg_T *cap, int t_cmd)
int c = cap->nchar; // char to search for
int dir = cap->arg; // true for searching forward
long count = cap->count1; // repeat count
int col;
char *p;
int len;
bool stop = true;
if (c != NUL) { // normal search: remember args for repeat
@ -1550,9 +1540,9 @@ int searchc(cmdarg_T *cap, int t_cmd)
cap->oap->inclusive = true;
}
p = get_cursor_line_ptr();
col = curwin->w_cursor.col;
len = (int)strlen(p);
char *p = get_cursor_line_ptr();
int col = curwin->w_cursor.col;
int len = (int)strlen(p);
while (count--) {
for (;;) {
@ -2295,15 +2285,10 @@ int check_linecomment(const char *line)
/// @param c char to show match for
void showmatch(int c)
{
pos_T *lpos, save_cursor;
pos_T mpos;
pos_T *lpos;
colnr_T vcol;
long *so = curwin->w_p_so >= 0 ? &curwin->w_p_so : &p_so;
long *siso = curwin->w_p_siso >= 0 ? &curwin->w_p_siso : &p_siso;
long save_so;
long save_siso;
int save_state;
colnr_T save_dollar_vcol;
char *p;
// Only show match for chars in the 'matchpairs' option.
@ -2345,10 +2330,10 @@ void showmatch(int c)
return;
}
mpos = *lpos; // save the pos, update_screen() may change it
save_cursor = curwin->w_cursor;
save_so = *so;
save_siso = *siso;
pos_T mpos = *lpos; // save the pos, update_screen() may change it
pos_T save_cursor = curwin->w_cursor;
long save_so = *so;
long save_siso = *siso;
// Handle "$" in 'cpo': If the ')' is typed on top of the "$",
// stop displaying the "$".
if (dollar_vcol >= 0 && dollar_vcol == curwin->w_virtcol) {
@ -2357,8 +2342,8 @@ void showmatch(int c)
curwin->w_virtcol++; // do display ')' just before "$"
update_screen(); // show the new char first
save_dollar_vcol = dollar_vcol;
save_state = State;
colnr_T save_dollar_vcol = dollar_vcol;
int save_state = State;
State = MODE_SHOWMATCH;
ui_cursor_shape(); // may show different cursor shape
curwin->w_cursor = mpos; // move to matching char
@ -2531,7 +2516,6 @@ int current_search(long count, bool forward)
static int is_zero_width(char *pattern, int move, pos_T *cur, Direction direction)
{
regmmatch_T regmatch;
int nmatched = 0;
int result = -1;
pos_T pos;
const int called_emsg_before = called_emsg;
@ -2558,6 +2542,7 @@ static int is_zero_width(char *pattern, int move, pos_T *cur, Direction directio
}
if (searchit(curwin, curbuf, &pos, NULL, direction, pattern, 1,
SEARCH_KEEP + flag, RE_SEARCH, NULL) != FAIL) {
int nmatched = 0;
// Zero-width pattern should match somewhere, then we can check if
// start and end are in the same position.
do {
@ -2587,9 +2572,7 @@ static int is_zero_width(char *pattern, int move, pos_T *cur, Direction directio
/// return true if line 'lnum' is empty or has white chars only.
int linewhite(linenr_T lnum)
{
char *p;
p = skipwhite(ml_get(lnum));
char *p = skipwhite(ml_get(lnum));
return *p == NUL;
}
@ -2682,7 +2665,6 @@ static void update_search_stat(int dirc, pos_T *pos, pos_T *cursor_pos, searchst
static int chgtick = 0;
static char *lastpat = NULL;
static buf_T *lbuf = NULL;
proftime_T start;
CLEAR_POINTER(stat);
@ -2722,6 +2704,7 @@ static void update_search_stat(int dirc, pos_T *pos, pos_T *cursor_pos, searchst
&& (dirc == 0 || dirc == '/' ? cur < cnt : cur > 0)) {
cur += dirc == 0 ? 0 : dirc == '/' ? 1 : -1;
} else {
proftime_T start;
bool done_search = false;
pos_T endpos = { 0, 0, 0 };
p_ws = false;
@ -2788,7 +2771,6 @@ void f_searchcount(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
if (argvars[0].v_type != VAR_UNKNOWN) {
dict_T *dict;
dictitem_T *di;
listitem_T *li;
bool error = false;
if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL) {
@ -2834,7 +2816,7 @@ void f_searchcount(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
semsg(_(e_invarg2), "List format should be [lnum, col, off]");
return;
}
li = tv_list_find(di->di_tv.vval.v_list, 0L);
listitem_T *li = tv_list_find(di->di_tv.vval.v_list, 0L);
if (li != NULL) {
pos.lnum = (linenr_T)tv_get_number_chk(TV_LIST_ITEM_TV(li), &error);
if (error) {
@ -4156,8 +4138,6 @@ static void show_pat_in_path(char *line, int type, bool did_show, int action, FI
linenr_T *lnum, long count)
FUNC_ATTR_NONNULL_ARG(1, 6)
{
char *p;
if (did_show) {
msg_putchar('\n'); // cursor below last one
} else if (!msg_silent) {
@ -4167,7 +4147,7 @@ static void show_pat_in_path(char *line, int type, bool did_show, int action, FI
return;
}
for (;;) {
p = line + strlen(line) - 1;
char *p = line + strlen(line) - 1;
if (fp != NULL) {
// We used fgets(), so get rid of newline at end
if (p >= line && *p == '\n') {

View File

@ -897,7 +897,6 @@ void suggest_load_files(void)
char *dotp;
FILE *fd;
char buf[MAXWLEN];
int i;
time_t timestamp;
int wcount;
int wordnr;
@ -925,7 +924,7 @@ void suggest_load_files(void)
}
// <SUGHEADER>: <fileID> <versionnr> <timestamp>
for (i = 0; i < VIMSUGMAGICL; i++) {
for (int i = 0; i < VIMSUGMAGICL; i++) {
buf[i] = (char)getc(fd); // <fileID>
}
if (strncmp(buf, VIMSUGMAGIC, VIMSUGMAGICL) != 0) {
@ -1734,7 +1733,6 @@ static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx
bool prefixtree, int maxprefcondnr)
{
int len;
int i;
int n;
idx_T idx = startidx;
int c2;
@ -1751,7 +1749,7 @@ static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx
byts[idx++] = (char_u)len;
// Read the byte values, flag/region bytes and shared indexes.
for (i = 1; i <= len; i++) {
for (int i = 1; i <= len; i++) {
int c = getc(fd); // <byte>
if (c < 0) {
return SP_TRUNCERROR;
@ -1814,7 +1812,7 @@ static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx
// Recursively read the children for non-shared siblings.
// Skip the end-of-word ones (zero byte value) and the shared ones (and
// remove SHARED_MASK)
for (i = 1; i <= len; i++) {
for (int i = 1; i <= len; i++) {
if (byts[startidx + i] != 0) {
if (idxs[startidx + i] & SHARED_MASK) {
idxs[startidx + i] &= ~SHARED_MASK;
@ -2673,9 +2671,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname)
&& sofoto == NULL) {
sofoto = getroom_save(spin, items[1]);
} else if (strcmp(items[0], "COMMON") == 0) {
int i;
for (i = 1; i < itemcnt; i++) {
for (int i = 1; i < itemcnt; i++) {
if (HASHITEM_EMPTY(hash_find(&spin->si_commonwords, (char *)items[i]))) {
p = xstrdup(items[i]);
hash_add(&spin->si_commonwords, p);
@ -3954,10 +3950,9 @@ static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root
wordnode_T *np;
wordnode_T *copyp, **copyprev;
wordnode_T **prev = NULL;
int i;
// Add each byte of the word to the tree, including the NUL at the end.
for (i = 0;; i++) {
for (int i = 0;; i++) {
// When there is more than one reference to this node we need to make
// a copy, so that we can modify it. Copy the whole list of siblings
// (we don't optimize for a partly shared list of siblings).
@ -5737,13 +5732,12 @@ static void set_spell_charflags(const char_u *flags, int cnt, char *fol)
// We build the new tables here first, so that we can compare with the
// previous one.
spelltab_T new_st;
int i;
char *p = fol;
int c;
clear_spell_chartab(&new_st);
for (i = 0; i < 128; i++) {
for (int i = 0; i < 128; i++) {
if (i < cnt) {
new_st.st_isw[i + 128] = (flags[i] & CF_WORD) != 0;
new_st.st_isu[i + 128] = (flags[i] & CF_UPPER) != 0;
@ -5818,7 +5812,6 @@ static void set_map_str(slang_T *lp, char *map)
{
char *p;
int headc = 0;
int i;
if (*map == NUL) {
lp->sl_has_map = false;
@ -5827,7 +5820,7 @@ static void set_map_str(slang_T *lp, char *map)
lp->sl_has_map = true;
// Init the array and hash tables empty.
for (i = 0; i < 256; i++) {
for (int i = 0; i < 256; i++) {
lp->sl_map_array[i] = 0;
}
hash_init(&lp->sl_map_hash);

View File

@ -2491,7 +2491,6 @@ static void score_comp_sal(suginfo_T *su)
{
langp_T *lp;
char badsound[MAXWLEN];
int i;
suggest_T *stp;
suggest_T *sstp;
int score;
@ -2505,7 +2504,7 @@ static void score_comp_sal(suginfo_T *su)
// soundfold the bad word
spell_soundfold(lp->lp_slang, su->su_fbadword, true, badsound);
for (i = 0; i < su->su_ga.ga_len; i++) {
for (int i = 0; i < su->su_ga.ga_len; i++) {
stp = &SUG(su->su_ga, i);
// Case-fold the suggested word, sound-fold it and compute the

View File

@ -260,23 +260,17 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler)
{
static bool entered = false;
int attr;
int curattr;
int row;
int col = 0;
int maxwidth;
int width;
int n;
int len;
int fillchar;
char buf[MAXPATHL];
char *stl;
char *p;
char *opt_name;
int opt_scope = 0;
stl_hlrec_t *hltab;
StlClickRecord *tabtab;
win_T *ewp;
int p_crb_save;
bool is_stl_global = global_stl_height() > 0;
ScreenGrid *grid = &default_grid;
@ -369,22 +363,22 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler)
// Temporarily reset 'cursorbind', we don't want a side effect from moving
// the cursor away and back.
ewp = wp == NULL ? curwin : wp;
p_crb_save = ewp->w_p_crb;
win_T *ewp = wp == NULL ? curwin : wp;
int p_crb_save = ewp->w_p_crb;
ewp->w_p_crb = false;
// Make a copy, because the statusline may include a function call that
// might change the option value and free the memory.
stl = xstrdup(stl);
width = build_stl_str_hl(ewp, buf, sizeof(buf), stl, opt_name, opt_scope,
fillchar, maxwidth, &hltab, &tabtab, NULL);
int width = build_stl_str_hl(ewp, buf, sizeof(buf), stl, opt_name, opt_scope,
fillchar, maxwidth, &hltab, &tabtab, NULL);
xfree(stl);
ewp->w_p_crb = p_crb_save;
// Make all characters printable.
p = transstr(buf, true);
len = (int)xstrlcpy(buf, p, sizeof(buf));
char *p = transstr(buf, true);
int len = (int)xstrlcpy(buf, p, sizeof(buf));
len = (size_t)len < sizeof(buf) ? len : (int)sizeof(buf) - 1;
xfree(p);
@ -398,7 +392,7 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler)
// Draw each snippet with the specified highlighting.
grid_puts_line_start(grid, row);
curattr = attr;
int curattr = attr;
p = buf;
for (n = 0; hltab[n].start != NULL; n++) {
int textlen = (int)(hltab[n].start - p);
@ -709,21 +703,9 @@ static void ui_ext_tabline_update(void)
/// Draw the tab pages line at the top of the Vim window.
void draw_tabline(void)
{
int tabcount = 0;
int tabwidth = 0;
int col = 0;
int scol = 0;
int attr;
win_T *wp;
win_T *cwp;
int wincount;
int modified;
int c;
int len;
int attr_nosel = HL_ATTR(HLF_TP);
int attr_fill = HL_ATTR(HLF_TPF);
char *p;
int room;
int use_sep_chars = (t_colors < 8);
if (default_grid.chars == NULL) {
@ -748,6 +730,14 @@ void draw_tabline(void)
if (*p_tal != NUL) {
win_redr_custom(NULL, false, false);
} else {
int tabcount = 0;
int tabwidth = 0;
int col = 0;
win_T *cwp;
int wincount;
int c;
int len;
char *p;
FOR_ALL_TABS(tp) {
tabcount++;
}
@ -760,7 +750,7 @@ void draw_tabline(void)
tabwidth = 6;
}
attr = attr_nosel;
int attr = attr_nosel;
tabcount = 0;
FOR_ALL_TABS(tp) {
@ -768,7 +758,7 @@ void draw_tabline(void)
break;
}
scol = col;
int scol = col;
if (tp == curtab) {
cwp = curwin;
@ -791,7 +781,7 @@ void draw_tabline(void)
grid_putchar(&default_grid, ' ', 0, col++, attr);
modified = false;
int modified = false;
for (wincount = 0; wp != NULL; wp = wp->w_next, wincount++) {
if (bufIsChanged(wp->w_buffer)) {
@ -816,7 +806,7 @@ void draw_tabline(void)
grid_putchar(&default_grid, ' ', 0, col++, attr);
}
room = scol - col + tabwidth - 1;
int room = scol - col + tabwidth - 1;
if (room > 0) {
// Get buffer name in NameBuff[]
get_trans_bufname(cwp->w_buffer);

View File

@ -1218,7 +1218,6 @@ static synstate_T *store_current_state(void)
// Copy a state stack from "from" in b_sst_array[] to current_state;
static void load_current_state(synstate_T *from)
{
int i;
bufstate_T *bp;
clear_current_state();
@ -1231,7 +1230,7 @@ static void load_current_state(synstate_T *from)
} else {
bp = from->sst_union.sst_stack;
}
for (i = 0; i < from->sst_stacksize; i++) {
for (int i = 0; i < from->sst_stacksize; i++) {
CUR_STATE(i).si_idx = bp[i].bs_idx;
CUR_STATE(i).si_flags = bp[i].bs_flags;
CUR_STATE(i).si_seqnr = bp[i].bs_seqnr;
@ -3441,9 +3440,7 @@ static void syn_list_one(const int id, const bool syncing, const bool link_only)
static void syn_list_flags(struct name_list *nlist, int flags, int attr)
{
int i;
for (i = 0; nlist[i].flag != 0; i++) {
for (int i = 0; nlist[i].flag != 0; i++) {
if (flags & nlist[i].flag) {
msg_puts_attr(nlist[i].name, attr);
msg_putchar(' ');
@ -4736,17 +4733,15 @@ static void init_syn_patterns(void)
/// @return a pointer to the next argument, or NULL in case of an error.
static char *get_syn_pattern(char *arg, synpat_T *ci)
{
char *end;
int *p;
int idx;
char *cpo_save;
// need at least three chars
if (arg == NULL || arg[0] == NUL || arg[1] == NUL || arg[2] == NUL) {
return NULL;
}
end = skip_regexp(arg + 1, *arg, true);
char *end = skip_regexp(arg + 1, *arg, true);
if (*end != *arg) { // end delimiter not found
semsg(_("E401: Pattern delimiter not found: %s"), arg);
return NULL;
@ -4755,7 +4750,7 @@ static char *get_syn_pattern(char *arg, synpat_T *ci)
ci->sp_pattern = xstrnsave(arg + 1, (size_t)(end - arg) - 1);
// Make 'cpoptions' empty, to avoid the 'l' flag
cpo_save = p_cpo;
char *cpo_save = p_cpo;
p_cpo = empty_option;
ci->sp_prog = vim_regcomp(ci->sp_pattern, RE_MAGIC);
p_cpo = cpo_save;
@ -5145,7 +5140,6 @@ static int in_id_list(stateitem_T *cur_si, int16_t *list, struct sp_syn *ssp, in
{
int retval;
int16_t *scl_list;
int16_t item;
int16_t id = ssp->id;
static int depth = 0;
int r;
@ -5181,7 +5175,7 @@ static int in_id_list(stateitem_T *cur_si, int16_t *list, struct sp_syn *ssp, in
// If the first item is "ALLBUT", return true if "id" is NOT in the
// contains list. We also require that "id" is at the same ":syn include"
// level as the list.
item = *list;
int16_t item = *list;
if (item >= SYNID_ALLBUT && item < SYNID_CLUSTER) {
if (item < SYNID_TOP) {
// ALL or ALLBUT: accept all groups in the same file
@ -5291,9 +5285,6 @@ void ex_syntax(exarg_T *eap)
void ex_ownsyntax(exarg_T *eap)
{
char *old_value;
char *new_value;
if (curwin->w_s == &curwin->w_buffer->b_s) {
curwin->w_s = xcalloc(1, sizeof(synblock_T));
hash_init(&curwin->w_s->b_keywtab);
@ -5309,7 +5300,7 @@ void ex_ownsyntax(exarg_T *eap)
}
// Save value of b:current_syntax.
old_value = get_var_value("b:current_syntax");
char *old_value = get_var_value("b:current_syntax");
if (old_value != NULL) {
old_value = xstrdup(old_value);
}
@ -5318,7 +5309,7 @@ void ex_ownsyntax(exarg_T *eap)
apply_autocmds(EVENT_SYNTAX, eap->arg, curbuf->b_fname, true, curbuf);
// Move value of b:current_syntax to w:current_syntax.
new_value = get_var_value("b:current_syntax");
char *new_value = get_var_value("b:current_syntax");
if (new_value != NULL) {
set_internal_string_var("w:current_syntax", new_value);
}
@ -5483,10 +5474,9 @@ int get_syntax_info(int *seqnrp)
int syn_get_concealed_id(win_T *wp, linenr_T lnum, colnr_T col)
{
int seqnr;
int syntax_flags;
(void)syn_get_id(wp, lnum, col, false, NULL, false);
syntax_flags = get_syntax_info(&seqnr);
int syntax_flags = get_syntax_info(&seqnr);
if (syntax_flags & HL_CONCEAL) {
return seqnr;

View File

@ -795,7 +795,6 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char
{
taggy_T *tagstack = curwin->w_tagstack;
int tagstackidx = curwin->w_tagstackidx;
int i;
char *p;
char *command_end;
tagptrs_T tagp;
@ -821,7 +820,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char
taglen_advance(taglen);
msg_puts_attr(_("file\n"), HL_ATTR(HLF_T));
for (i = 0; i < num_matches && !got_int; i++) {
for (int i = 0; i < num_matches && !got_int; i++) {
parse_match(matches[i], &tagp);
if (!new_tag && (
(g_do_tagpreview != 0
@ -980,7 +979,6 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char
static int add_llist_tags(char *tag, int num_matches, char **matches)
{
char tag_name[128 + 1];
int i;
char *p;
tagptrs_T tagp;
@ -988,7 +986,7 @@ static int add_llist_tags(char *tag, int num_matches, char **matches)
char *cmd = xmalloc(CMDBUFFSIZE + 1);
list_T *list = tv_list_alloc(0);
for (i = 0; i < num_matches; i++) {
for (int i = 0; i < num_matches; i++) {
dict_T *dict;
parse_match(matches[i], &tagp);
@ -1119,7 +1117,6 @@ static void taglen_advance(int l)
// Print the tag stack
void do_tags(exarg_T *eap)
{
int i;
char *name;
taggy_T *tagstack = curwin->w_tagstack;
int tagstackidx = curwin->w_tagstackidx;
@ -1127,7 +1124,7 @@ void do_tags(exarg_T *eap)
// Highlight title
msg_puts_title(_("\n # TO tag FROM line in file/text"));
for (i = 0; i < tagstacklen; i++) {
for (int i = 0; i < tagstacklen; i++) {
if (tagstack[i].tagname != NULL) {
name = fm_getname(&(tagstack[i].fmark), 30);
if (name == NULL) { // file name not available
@ -1731,8 +1728,6 @@ static tagmatch_status_T findtags_parse_line(findtags_state_T *st, tagptrs_T *ta
// 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);
@ -1754,8 +1749,9 @@ static tagmatch_status_T findtags_parse_line(findtags_state_T *st, tagptrs_T *ta
}
if (st->state == TS_BINARY) {
int tagcmp;
// Simplistic check for unsorted tags file.
i = (int)tagpp->tagname[0];
int i = (int)tagpp->tagname[0];
if (margs->sortic) {
i = TOUPPER_ASC(tagpp->tagname[0]);
}
@ -2245,7 +2241,6 @@ static int findtags_copy_matches(findtags_state_T *st, char ***matchesp)
const bool name_only = (st->flags & TAG_NAMES);
char **matches;
int mtt;
int i;
char *mfp;
char *p;
@ -2256,7 +2251,7 @@ static int findtags_copy_matches(findtags_state_T *st, char ***matchesp)
}
st->match_count = 0;
for (mtt = 0; mtt < MT_COUNT; mtt++) {
for (i = 0; i < st->ga_match[mtt].ga_len; i++) {
for (int i = 0; i < st->ga_match[mtt].ga_len; i++) {
mfp = ((char **)(st->ga_match[mtt].ga_data))[i];
if (matches == NULL) {
xfree(mfp);
@ -2731,7 +2726,6 @@ 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
@ -2752,7 +2746,7 @@ static int parse_match(char *lbuf, tagptrs_T *tagp)
break;
}
pc = vim_strchr(p, ':');
char *pc = vim_strchr(p, ':');
pt = vim_strchr(p, '\t');
if (pc == NULL || (pt != NULL && pc > pt)) {
tagp->tagkind = p;
@ -3435,15 +3429,12 @@ static void get_tag_details(taggy_T *tag, dict_T *retdict)
// 'retdict'.
void get_tagstack(win_T *wp, dict_T *retdict)
{
list_T *l;
int i;
tv_dict_add_nr(retdict, S_LEN("length"), wp->w_tagstacklen);
tv_dict_add_nr(retdict, S_LEN("curidx"), wp->w_tagstackidx + 1);
l = tv_list_alloc(2);
list_T *l = tv_list_alloc(2);
tv_dict_add_list(retdict, S_LEN("items"), l);
for (i = 0; i < wp->w_tagstacklen; i++) {
for (int i = 0; i < wp->w_tagstacklen; i++) {
dict_T *d = tv_dict_alloc();
tv_list_append_dict(l, d);
get_tag_details(&wp->w_tagstack[i], d);

View File

@ -633,19 +633,16 @@ static bool paragraph_start(linenr_T lnum)
/// @param prev_line may start in previous line
void auto_format(bool trailblank, bool prev_line)
{
pos_T pos;
colnr_T len;
char *old;
char *new, *pnew;
int wasatend;
int cc;
if (!has_format_option(FO_AUTO)) {
return;
}
pos = curwin->w_cursor;
old = get_cursor_line_ptr();
pos_T pos = curwin->w_cursor;
char *old = get_cursor_line_ptr();
// may remove added space
check_auto_format(false);
@ -655,7 +652,7 @@ void auto_format(bool trailblank, bool prev_line)
// in 'formatoptions' and there is a single character before the cursor.
// Otherwise the line would be broken and when typing another non-white
// next they are not joined back together.
wasatend = (pos.col == (colnr_T)strlen(old));
int wasatend = (pos.col == (colnr_T)strlen(old));
if (*old != NUL && !trailblank && wasatend) {
dec_cursor();
cc = gchar_cursor();
@ -733,18 +730,16 @@ void auto_format(bool trailblank, bool prev_line)
/// @param end_insert true when ending Insert mode
void check_auto_format(bool end_insert)
{
int c = ' ';
int cc;
if (!did_add_space) {
return;
}
cc = gchar_cursor();
int cc = gchar_cursor();
if (!WHITECHAR(cc)) {
// Somehow the space was removed already.
did_add_space = false;
} else {
int c = ' ';
if (!end_insert) {
inc_cursor();
c = gchar_cursor();
@ -886,7 +881,6 @@ void op_formatexpr(oparg_T *oap)
int fex_format(linenr_T lnum, long count, int c)
{
int use_sandbox = was_set_insecurely(curwin, "formatexpr", OPT_LOCAL);
int r;
// Set v:lnum to the first line number and v:count to the number of lines.
// Set v:char to the character to be inserted (can be NUL).
@ -900,7 +894,7 @@ int fex_format(linenr_T lnum, long count, int c)
if (use_sandbox) {
sandbox++;
}
r = (int)eval_to_number(fex);
int r = (int)eval_to_number(fex);
if (use_sandbox) {
sandbox--;
}