aboutsummaryrefslogtreecommitdiff
path: root/src/nvim
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-06-06 23:25:13 -0300
committerJustin M. Keyes <justinkz@gmail.com>2014-06-10 14:15:21 -0400
commitf39fd5b4c424cc477a168fbf4eebfe315d23e614 (patch)
treeaf9fd539e39b83bbe47be55d5b76870ff3ffe630 /src/nvim
parenta3214803429e05635cbfbe8b3050a73406da6bc6 (diff)
downloadrneovim-f39fd5b4c424cc477a168fbf4eebfe315d23e614.tar.gz
rneovim-f39fd5b4c424cc477a168fbf4eebfe315d23e614.tar.bz2
rneovim-f39fd5b4c424cc477a168fbf4eebfe315d23e614.zip
Declare garray iterators in the for() scope where possible #819
Diffstat (limited to 'src/nvim')
-rw-r--r--src/nvim/digraph.c20
-rw-r--r--src/nvim/eval.c55
-rw-r--r--src/nvim/ex_cmds.c13
-rw-r--r--src/nvim/ex_cmds2.c60
-rw-r--r--src/nvim/ex_docmd.c10
-rw-r--r--src/nvim/fileio.c18
-rw-r--r--src/nvim/fold.c56
-rw-r--r--src/nvim/garray.c3
-rw-r--r--src/nvim/menu.c17
-rw-r--r--src/nvim/misc1.c3
-rw-r--r--src/nvim/path.c13
-rw-r--r--src/nvim/spell.c146
-rw-r--r--src/nvim/syntax.c134
-rw-r--r--src/nvim/tag.c2
-rw-r--r--src/nvim/undo.c3
-rw-r--r--src/nvim/window.c3
16 files changed, 232 insertions, 324 deletions
diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c
index ee9a2fee5f..a0834e9da9 100644
--- a/src/nvim/digraph.c
+++ b/src/nvim/digraph.c
@@ -1492,8 +1492,7 @@ static int getexactdigraph(int char1, int char2, int meta_char)
// Search user digraphs first.
digr_T *dp = (digr_T *)user_digraphs.ga_data;
- int i;
- for (i = 0; i < user_digraphs.ga_len; ++i) {
+ for (int i = 0; i < user_digraphs.ga_len; ++i) {
if (((int) dp->char1 == char1) && ((int) dp->char2 == char2)) {
retval = dp->result;
break;
@@ -1505,7 +1504,7 @@ static int getexactdigraph(int char1, int char2, int meta_char)
if (retval == 0) {
dp = digraphdefault;
- for (i = 0; dp->char1 != 0; ++i) {
+ for (int i = 0; dp->char1 != 0; ++i) {
if (((int) dp->char1 == char1) && ((int) dp->char2 == char2)) {
retval = dp->result;
break;
@@ -1519,7 +1518,7 @@ static int getexactdigraph(int char1, int char2, int meta_char)
vimconv_T vc;
// Convert the Unicode digraph to 'encoding'.
- i = utf_char2bytes(retval, buf);
+ int i = utf_char2bytes(retval, buf);
retval = 0;
vc.vc_type = CONV_NONE;
@@ -1578,7 +1577,6 @@ int getdigraph(int char1, int char2, int meta_char)
void putdigraph(char_u *str)
{
int char1, char2, n;
- int i;
digr_T *dp;
while (*str != NUL) {
@@ -1610,6 +1608,7 @@ void putdigraph(char_u *str)
// If the digraph already exists, replace the result.
dp = (digr_T *)user_digraphs.ga_data;
+ int i;
for (i = 0; i < user_digraphs.ga_len; ++i) {
if (((int)dp->char1 == char1) && ((int)dp->char2 == char2)) {
dp->result = n;
@@ -1632,14 +1631,13 @@ void putdigraph(char_u *str)
void listdigraphs(void)
{
- int i;
digr_T *dp;
msg_putchar('\n');
dp = digraphdefault;
- for (i = 0; dp->char1 != NUL && !got_int; ++i) {
+ for (int i = 0; dp->char1 != NUL && !got_int; ++i) {
digr_T tmp;
// May need to convert the result to 'encoding'.
@@ -1657,7 +1655,7 @@ void listdigraphs(void)
}
dp = (digr_T *)user_digraphs.ga_data;
- for (i = 0; i < user_digraphs.ga_len && !got_int; ++i) {
+ for (int i = 0; i < user_digraphs.ga_len && !got_int; ++i) {
printdigraph(dp);
ui_breakcheck();
dp++;
@@ -1778,7 +1776,6 @@ void ex_loadkeymap(exarg_T *eap)
#define KMAP_LLEN 200 // max length of "to" and "from" together
char_u buf[KMAP_LLEN + 11];
- int i;
char_u *save_cpo = p_cpo;
if (!getline_equal(eap->getline, eap->cookie, getsourceline)) {
@@ -1830,7 +1827,7 @@ void ex_loadkeymap(exarg_T *eap)
}
// setup ":lnoremap" to map the keys
- for (i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) {
+ for (int i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) {
vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s %s",
((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from,
((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to);
@@ -1847,7 +1844,6 @@ void ex_loadkeymap(exarg_T *eap)
static void keymap_unload(void)
{
char_u buf[KMAP_MAXLEN + 10];
- int i;
char_u *save_cpo = p_cpo;
kmap_T *kp;
@@ -1861,7 +1857,7 @@ static void keymap_unload(void)
// clear the ":lmap"s
kp = (kmap_T *)curbuf->b_kmap_ga.ga_data;
- for (i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) {
+ for (int i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) {
vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from);
(void)do_map(1, buf, LANGMAP, FALSE);
free(kp[i].from);
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index c209f5c4af..4a85761ec7 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -460,10 +460,9 @@ void eval_init(void)
#if defined(EXITFREE) || defined(PROTO)
void eval_clear(void)
{
- int i;
struct vimvar *p;
- for (i = 0; i < VV_LEN; ++i) {
+ for (int i = 0; i < VV_LEN; ++i) {
p = &vimvars[i];
if (p->vv_di.di_tv.v_type == VAR_STRING) {
free(p->vv_str);
@@ -489,9 +488,9 @@ void eval_clear(void)
/* Script-local variables. First clear all the variables and in a second
* loop free the scriptvar_T, because a variable in one script might hold
* a reference to the whole scope of another script. */
- for (i = 1; i <= ga_scripts.ga_len; ++i)
+ for (int i = 1; i <= ga_scripts.ga_len; ++i)
vars_clear(&SCRIPT_VARS(i));
- for (i = 1; i <= ga_scripts.ga_len; ++i)
+ for (int i = 1; i <= ga_scripts.ga_len; ++i)
free(SCRIPT_SV(i));
ga_clear(&ga_scripts);
@@ -1038,14 +1037,13 @@ call_vim_function (
{
long n;
int len;
- int i;
int doesrange;
void *save_funccalp = NULL;
int ret;
typval_T *argvars = xmalloc((argc + 1) * sizeof(typval_T));
- for (i = 0; i < argc; i++) {
+ for (int i = 0; i < argc; i++) {
/* Pass a NULL or empty argument as an empty string */
if (argv[i] == NULL || *argv[i] == NUL) {
argvars[i].v_type = VAR_STRING;
@@ -5292,7 +5290,6 @@ list_join_inner (
garray_T *join_gap /* to keep each list item string */
)
{
- int i;
join_T *p;
int len;
int sumlen = 0;
@@ -5333,7 +5330,7 @@ list_join_inner (
sumlen += (int)STRLEN(sep) * (join_gap->ga_len - 1);
ga_grow(gap, sumlen + 2);
- for (i = 0; i < join_gap->ga_len && !got_int; ++i) {
+ for (int i = 0; i < join_gap->ga_len && !got_int; ++i) {
if (first)
first = FALSE;
else
@@ -5358,7 +5355,6 @@ static int list_join(garray_T *gap, list_T *l, char_u *sep, int echo_style, int
garray_T join_ga;
int retval;
join_T *p;
- int i;
ga_init(&join_ga, (int)sizeof(join_T), l->lv_len);
retval = list_join_inner(gap, l, sep, echo_style, copyID, &join_ga);
@@ -5366,7 +5362,7 @@ static int list_join(garray_T *gap, list_T *l, char_u *sep, int echo_style, int
/* Dispose each item in join_ga. */
if (join_ga.ga_data != NULL) {
p = (join_T *)join_ga.ga_data;
- for (i = 0; i < join_ga.ga_len; ++i) {
+ for (int i = 0; i < join_ga.ga_len; ++i) {
free(p->tofree);
++p;
}
@@ -5405,7 +5401,6 @@ int garbage_collect(void)
int copyID;
buf_T *buf;
win_T *wp;
- int i;
funccall_T *fc, **pfc;
int did_free;
int did_free_funccal = FALSE;
@@ -5435,7 +5430,7 @@ int garbage_collect(void)
}
/* script-local variables */
- for (i = 1; i <= ga_scripts.ga_len; ++i)
+ for (int i = 1; i <= ga_scripts.ga_len; ++i)
set_ref_in_ht(&SCRIPT_VARS(i), copyID);
/* buffer-local variables */
@@ -5464,9 +5459,6 @@ int garbage_collect(void)
/* v: vars */
set_ref_in_ht(&vimvarht, copyID);
-
-
-
/*
* 2. Free lists and dictionaries that are not referenced.
*/
@@ -13394,7 +13386,6 @@ static void f_spellsuggest(typval_T *argvars, typval_T *rettv)
int typeerr = FALSE;
int maxcount;
garray_T ga;
- int i;
listitem_T *li;
int need_capital = FALSE;
@@ -13416,7 +13407,7 @@ static void f_spellsuggest(typval_T *argvars, typval_T *rettv)
spell_suggest_list(&ga, str, maxcount, need_capital, FALSE);
- for (i = 0; i < ga.ga_len; ++i) {
+ for (int i = 0; i < ga.ga_len; ++i) {
str = ((char_u **)ga.ga_data)[i];
li = listitem_alloc();
@@ -15888,7 +15879,6 @@ char_u *get_var_value(char_u *name)
*/
void new_script_vars(scid_T id)
{
- int i;
hashtab_T *ht;
scriptvar_T *sv;
@@ -15897,7 +15887,7 @@ void new_script_vars(scid_T id)
/* Re-allocating ga_data means that an ht_array pointing to
* ht_smallarray becomes invalid. We can recognize this: ht_mask is
* at its init value. Also reset "v_dict", it's always the same. */
- for (i = 1; i <= ga_scripts.ga_len; ++i) {
+ for (int i = 1; i <= ga_scripts.ga_len; ++i) {
ht = &SCRIPT_VARS(i);
if (ht->ht_mask == HT_INIT_SIZE - 1)
ht->ht_array = ht->ht_smallarray;
@@ -16572,8 +16562,6 @@ static char_u *find_option_end(char_u **arg, int *opt_flags)
void ex_function(exarg_T *eap)
{
char_u *theline;
- int i;
- int j;
int c;
int saved_did_emsg;
int saved_wait_return = need_wait_return;
@@ -16704,7 +16692,7 @@ void ex_function(exarg_T *eap)
fp = find_func(name);
if (fp != NULL) {
list_func_head(fp, TRUE);
- for (j = 0; j < fp->uf_lines.ga_len && !got_int; ++j) {
+ for (int j = 0; j < fp->uf_lines.ga_len && !got_int; ++j) {
if (FUNCLINE(fp, j) == NULL)
continue;
msg_putchar('\n');
@@ -16754,10 +16742,7 @@ void ex_function(exarg_T *eap)
arg = fudi.fd_newkey;
if (arg != NULL && (fudi.fd_di == NULL
|| fudi.fd_di->di_tv.v_type != VAR_FUNC)) {
- if (*arg == K_SPECIAL)
- j = 3;
- else
- j = 0;
+ int j = (*arg == K_SPECIAL) ? 3 : 0;
while (arg[j] != NUL && (j == 0 ? eval_isnamec1(arg[j])
: eval_isnamec(arg[j])))
++j;
@@ -16794,7 +16779,7 @@ void ex_function(exarg_T *eap)
arg = vim_strsave(arg);
/* Check for duplicate argument name. */
- for (i = 0; i < newargs.ga_len; ++i)
+ for (int i = 0; i < newargs.ga_len; ++i)
if (STRCMP(((char_u **)(newargs.ga_data))[i], arg) == 0) {
EMSG2(_("E853: Duplicate argument name: %s"), arg);
free(arg);
@@ -17062,7 +17047,7 @@ void ex_function(exarg_T *eap)
char_u *scriptname;
/* Check that the autoload name matches the script name. */
- j = FAIL;
+ int j = FAIL;
if (sourcing_name != NULL) {
scriptname = autoload_name(name);
if (scriptname != NULL) {
@@ -17357,8 +17342,6 @@ static int eval_fname_sid(char_u *p)
*/
static void list_func_head(ufunc_T *fp, int indent)
{
- int j;
-
msg_start();
if (indent)
MSG_PUTS(" ");
@@ -17369,6 +17352,7 @@ static void list_func_head(ufunc_T *fp, int indent)
} else
msg_puts(fp->uf_name);
msg_putchar('(');
+ int j;
for (j = 0; j < fp->uf_args.ga_len; ++j) {
if (j)
MSG_PUTS(", ");
@@ -17522,7 +17506,6 @@ void func_dump_profile(FILE *fd)
hashitem_T *hi;
int todo;
ufunc_T *fp;
- int i;
ufunc_T **sorttab;
int st_len = 0;
@@ -17553,7 +17536,7 @@ void func_dump_profile(FILE *fd)
fprintf(fd, "\n");
fprintf(fd, "count total (s) self (s)\n");
- for (i = 0; i < fp->uf_lines.ga_len; ++i) {
+ for (int i = 0; i < fp->uf_lines.ga_len; ++i) {
if (FUNCLINE(fp, i) == NULL)
continue;
prof_func_line(fd, fp->uf_tml_count[i],
@@ -17906,7 +17889,6 @@ call_user_func (
static int depth = 0;
dictitem_T *v;
int fixvar_idx = 0; /* index in fixvar[] */
- int i;
int ai;
char_u numbuf[NUMBUFLEN];
char_u *name;
@@ -17991,7 +17973,7 @@ call_user_func (
(varnumber_T)firstline);
add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "lastline",
(varnumber_T)lastline);
- for (i = 0; i < argcount; ++i) {
+ for (int i = 0; i < argcount; ++i) {
ai = i - fp->uf_args.ga_len;
if (ai < 0)
/* named argument a:name */
@@ -18050,7 +18032,7 @@ call_user_func (
char_u *s;
msg_puts((char_u *)"(");
- for (i = 0; i < argcount; ++i) {
+ for (int i = 0; i < argcount; ++i) {
if (i > 0)
msg_puts((char_u *)", ");
if (argvars[i].v_type == VAR_NUMBER)
@@ -19021,7 +19003,6 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags)
{
int sublen;
regmatch_T regmatch;
- int i;
int do_all;
char_u *tail;
garray_T ga;
@@ -19064,7 +19045,7 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags)
(regmatch.endp[0] - regmatch.startp[0])));
/* copy the text up to where the match is */
- i = (int)(regmatch.startp[0] - tail);
+ int i = (int)(regmatch.startp[0] - tail);
memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i);
/* add the substituted text */
(void)vim_regsub(&regmatch, sub, (char_u *)ga.ga_data
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 576847c7b9..f9250e8aa1 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -5290,7 +5290,6 @@ void ex_viusage(exarg_T *eap)
void ex_helptags(exarg_T *eap)
{
garray_T ga;
- int i, j;
int len;
char_u lang[2];
expand_T xpc;
@@ -5331,7 +5330,7 @@ void ex_helptags(exarg_T *eap)
/* Go over all files in the directory to find out what languages are
* present. */
ga_init(&ga, 1, 10);
- for (i = 0; i < filecount; ++i) {
+ for (int i = 0; i < filecount; ++i) {
len = (int)STRLEN(files[i]);
if (len > 4) {
if (STRICMP(files[i] + len - 4, ".txt") == 0) {
@@ -5348,6 +5347,7 @@ void ex_helptags(exarg_T *eap)
} else
continue;
+ int j;
/* Did we find this language already? */
for (j = 0; j < ga.ga_len; j += 2)
if (STRNCMP(lang, ((char_u *)ga.ga_data) + j, 2) == 0)
@@ -5364,7 +5364,7 @@ void ex_helptags(exarg_T *eap)
/*
* Loop over the found languages to generate a tags file for each one.
*/
- for (j = 0; j < ga.ga_len; j += 2) {
+ for (int j = 0; j < ga.ga_len; j += 2) {
STRCPY(fname, "tags-xx");
fname[5] = ((char_u *)ga.ga_data)[j];
fname[6] = ((char_u *)ga.ga_data)[j + 1];
@@ -5403,7 +5403,6 @@ helptags_one (
char_u *p1, *p2;
int fi;
char_u *s;
- int i;
char_u *fname;
int dirlen;
int utf8 = MAYBE;
@@ -5547,7 +5546,7 @@ helptags_one (
/*
* Check for duplicates.
*/
- for (i = 1; i < ga.ga_len; ++i) {
+ for (int i = 1; i < ga.ga_len; ++i) {
p1 = ((char_u **)ga.ga_data)[i - 1];
p2 = ((char_u **)ga.ga_data)[i];
while (*p1 == *p2) {
@@ -5571,7 +5570,7 @@ helptags_one (
/*
* Write the tags into the file.
*/
- for (i = 0; i < ga.ga_len; ++i) {
+ for (int i = 0; i < ga.ga_len; ++i) {
s = ((char_u **)ga.ga_data)[i];
if (STRNCMP(s, "help-tags\t", 10) == 0)
/* help-tags entry was added in formatted form */
@@ -5591,7 +5590,7 @@ helptags_one (
if (mix)
got_int = FALSE; /* continue with other languages */
- for (i = 0; i < ga.ga_len; ++i)
+ for (int i = 0; i < ga.ga_len; ++i)
free(((char_u **)ga.ga_data)[i]);
ga_clear(&ga);
fclose(fd_tags); /* there is no check for an error... */
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index b2b37d9c01..1876276e9f 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -557,7 +557,6 @@ void ex_breakdel(exarg_T *eap)
int nr;
int todel = -1;
int del_all = FALSE;
- int i;
linenr_T best_lnum = 0;
garray_T *gap;
@@ -569,7 +568,7 @@ void ex_breakdel(exarg_T *eap)
if (vim_isdigit(*eap->arg)) {
/* ":breakdel {nr}" */
nr = atol((char *)eap->arg);
- for (i = 0; i < gap->ga_len; ++i)
+ for (int i = 0; i < gap->ga_len; ++i)
if (DEBUGGY(gap, i).dbg_nr == nr) {
todel = i;
break;
@@ -582,7 +581,7 @@ void ex_breakdel(exarg_T *eap)
if (dbg_parsearg(eap->arg, gap) == FAIL)
return;
bp = &DEBUGGY(gap, gap->ga_len);
- for (i = 0; i < gap->ga_len; ++i) {
+ for (int i = 0; i < gap->ga_len; ++i) {
bpi = &DEBUGGY(gap, i);
if (bp->dbg_type == bpi->dbg_type
&& STRCMP(bp->dbg_name, bpi->dbg_name) == 0
@@ -625,12 +624,11 @@ void ex_breakdel(exarg_T *eap)
void ex_breaklist(exarg_T *eap)
{
struct debuggy *bp;
- int i;
if (GA_EMPTY(&dbg_breakp))
MSG(_("No breakpoints defined"));
else
- for (i = 0; i < dbg_breakp.ga_len; ++i) {
+ for (int i = 0; i < dbg_breakp.ga_len; ++i) {
bp = &BREAKP(i);
if (bp->dbg_type == DBG_FILE)
home_replace(NULL, bp->dbg_name, NameBuff, MAXPATHL, TRUE);
@@ -683,7 +681,6 @@ debuggy_find (
)
{
struct debuggy *bp;
- int i;
linenr_T lnum = 0;
regmatch_T regmatch;
char_u *name = fname;
@@ -700,7 +697,7 @@ debuggy_find (
STRCPY(name + 5, fname + 3);
}
- for (i = 0; i < gap->ga_len; ++i) {
+ for (int i = 0; i < gap->ga_len; ++i) {
/* Skip entries that are not useful or are for a line that is beyond
* an already found breakpoint. */
bp = &DEBUGGY(gap, i);
@@ -1112,13 +1109,11 @@ void prof_inchar_exit(void)
*/
static void script_dump_profile(FILE *fd)
{
- int id;
scriptitem_T *si;
- int i;
FILE *sfd;
sn_prl_T *pp;
- for (id = 1; id <= script_items.ga_len; ++id) {
+ for (int id = 1; id <= script_items.ga_len; ++id) {
si = &SCRIPT_ITEM(id);
if (si->sn_prof_on) {
fprintf(fd, "SCRIPT %s\n", si->sn_name);
@@ -1135,7 +1130,7 @@ static void script_dump_profile(FILE *fd)
if (sfd == NULL)
fprintf(fd, "Cannot open file!\n");
else {
- for (i = 0; i < si->sn_prl_ga.ga_len; ++i) {
+ for (int i = 0; i < si->sn_prl_ga.ga_len; ++i) {
if (vim_fgets(IObuff, IOSIZE, sfd))
break;
pp = &PRL_ITEM(si, i);
@@ -1579,7 +1574,6 @@ do_arglist (
garray_T new_ga;
int exp_count;
char_u **exp_files;
- int i;
char_u *p;
int match;
@@ -1597,7 +1591,7 @@ do_arglist (
* argument list.
*/
regmatch.rm_ic = p_fic; /* ignore case when 'fileignorecase' is set */
- for (i = 0; i < new_ga.ga_len && !got_int; ++i) {
+ for (int i = 0; i < new_ga.ga_len && !got_int; ++i) {
p = ((char_u **)new_ga.ga_data)[i];
p = file_pat_to_reg_pat(p, NULL, NULL, FALSE);
if (p == NULL)
@@ -1629,7 +1623,7 @@ do_arglist (
}
ga_clear(&new_ga);
} else {
- i = expand_wildcards(new_ga.ga_len, (char_u **)new_ga.ga_data,
+ int i = expand_wildcards(new_ga.ga_len, (char_u **)new_ga.ga_data,
&exp_count, &exp_files, EW_DIR|EW_FILE|EW_ADDSLASH|EW_NOTFOUND);
ga_clear(&new_ga);
if (i == FAIL)
@@ -1714,8 +1708,6 @@ void check_arg_idx(win_T *win)
*/
void ex_args(exarg_T *eap)
{
- int i;
-
if (eap->cmdidx != CMD_args) {
alist_unlink(ALIST(curwin));
if (eap->cmdidx == CMD_argglobal)
@@ -1738,7 +1730,7 @@ void ex_args(exarg_T *eap)
/* Overwrite the command, for a short list there is no scrolling
* required and no wait_return(). */
gotocmdline(TRUE);
- for (i = 0; i < ARGCOUNT; ++i) {
+ for (int i = 0; i < ARGCOUNT; ++i) {
if (i == curwin->w_arg_idx)
msg_putchar('[');
msg_outtrans(alist_name(&ARGLIST[i]));
@@ -1754,7 +1746,7 @@ void ex_args(exarg_T *eap)
* ":argslocal": make a local copy of the global argument list.
*/
ga_grow(gap, GARGCOUNT);
- for (i = 0; i < GARGCOUNT; ++i)
+ for (int i = 0; i < GARGCOUNT; ++i)
if (GARGLIST[i].ae_fname != NULL) {
AARGLIST(curwin->w_alist)[gap->ga_len].ae_fname =
vim_strsave(GARGLIST[i].ae_fname);
@@ -1941,18 +1933,15 @@ void ex_argadd(exarg_T *eap)
*/
void ex_argdelete(exarg_T *eap)
{
- int i;
- int n;
-
if (eap->addr_count > 0) {
/* ":1,4argdel": Delete all arguments in the range. */
if (eap->line2 > ARGCOUNT)
eap->line2 = ARGCOUNT;
- n = eap->line2 - eap->line1 + 1;
+ int n = eap->line2 - eap->line1 + 1;
if (*eap->arg != NUL || n <= 0)
EMSG(_(e_invarg));
else {
- for (i = eap->line1; i <= eap->line2; ++i)
+ for (int i = eap->line1; i <= eap->line2; ++i)
free(ARGLIST[i - 1].ae_fname);
memmove(ARGLIST + eap->line1 - 1, ARGLIST + eap->line2,
(size_t)((ARGCOUNT - eap->line2) * sizeof(aentry_T)));
@@ -2107,8 +2096,6 @@ alist_add_list (
int after /* where to add: 0 = before first one */
)
{
- int i;
-
ga_grow(&ALIST(curwin)->al_ga, count);
{
if (after < 0)
@@ -2118,7 +2105,7 @@ alist_add_list (
if (after < ARGCOUNT)
memmove(&(ARGLIST[after + count]), &(ARGLIST[after]),
(ARGCOUNT - after) * sizeof(aentry_T));
- for (i = 0; i < count; ++i) {
+ for (int i = 0; i < count; ++i) {
ARGLIST[after + i].ae_fname = files[i];
ARGLIST[after + i].ae_fnum = buflist_add(files[i], BLN_LISTED);
}
@@ -2690,9 +2677,7 @@ theend:
*/
void ex_scriptnames(exarg_T *eap)
{
- int i;
-
- for (i = 1; i <= script_items.ga_len && !got_int; ++i)
+ for (int i = 1; i <= script_items.ga_len && !got_int; ++i)
if (SCRIPT_ITEM(i).sn_name != NULL) {
home_replace(NULL, SCRIPT_ITEM(i).sn_name,
NameBuff, MAXPATHL, TRUE);
@@ -2706,11 +2691,11 @@ void ex_scriptnames(exarg_T *eap)
*/
void scriptnames_slash_adjust(void)
{
- int i;
-
- for (i = 1; i <= script_items.ga_len; ++i)
- if (SCRIPT_ITEM(i).sn_name != NULL)
+ for (int i = 1; i <= script_items.ga_len; ++i) {
+ if (SCRIPT_ITEM(i).sn_name != NULL) {
slash_adjust(SCRIPT_ITEM(i).sn_name);
+ }
+ }
}
# endif
@@ -2736,9 +2721,7 @@ char_u *get_scriptname(scid_T id)
# if defined(EXITFREE) || defined(PROTO)
void free_scriptnames(void)
{
- int i;
-
- for (i = script_items.ga_len; i > 0; --i)
+ for (int i = script_items.ga_len; i > 0; --i)
free(SCRIPT_ITEM(i).sn_name);
ga_clear(&script_items);
}
@@ -2809,10 +2792,7 @@ char_u *getsourceline(int c, void *cookie, int indent)
/* Adjust the growsize to the current length to speed up
* concatenating many lines. */
if (ga.ga_len > 400) {
- if (ga.ga_len > 8000)
- ga.ga_growsize = 8000;
- else
- ga.ga_growsize = ga.ga_len;
+ ga.ga_growsize = (ga.ga_len > 8000) ? 8000 : ga.ga_len;
}
ga_concat(&ga, p + 1);
}
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index e8930bd0f6..d95927cfd6 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -4259,7 +4259,6 @@ static struct {
static void uc_list(char_u *name, size_t name_len)
{
- int i, j;
int found = FALSE;
ucmd_T *cmd;
int len;
@@ -4268,6 +4267,7 @@ static void uc_list(char_u *name, size_t name_len)
gap = &curbuf->b_ucmds;
for (;; ) {
+ int i;
for (i = 0; i < gap->ga_len; ++i) {
cmd = USER_CMD_GA(gap, i);
a = (long)cmd->uc_argt;
@@ -4334,7 +4334,7 @@ static void uc_list(char_u *name, size_t name_len)
} while (len < 11);
/* Completion */
- for (j = 0; command_complete[j].expand != 0; ++j)
+ for (int j = 0; command_complete[j].expand != 0; ++j)
if (command_complete[j].expand == cmd->uc_compl) {
STRCPY(IObuff + len, command_complete[j].name);
len += (int)STRLEN(IObuff + len);
@@ -4564,10 +4564,9 @@ void ex_comclear(exarg_T *eap)
*/
void uc_clear(garray_T *gap)
{
- int i;
ucmd_T *cmd;
- for (i = 0; i < gap->ga_len; ++i) {
+ for (int i = 0; i < gap->ga_len; ++i) {
cmd = USER_CMD_GA(gap, i);
free(cmd->uc_name);
free(cmd->uc_rep);
@@ -8481,7 +8480,6 @@ ses_arglist (
unsigned *flagp
)
{
- int i;
char_u *buf = NULL;
char_u *s;
@@ -8491,7 +8489,7 @@ ses_arglist (
if (put_line(fd, "silent! argdel *") == FAIL) {
return FAIL;
}
- for (i = 0; i < gap->ga_len; ++i) {
+ for (int i = 0; i < gap->ga_len; ++i) {
/* NULL file names are skipped (only happens when out of memory). */
s = alist_name(&((aentry_T *)gap->ga_data)[i]);
if (s != NULL) {
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index b3b336073b..f86eae6a48 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -5655,9 +5655,7 @@ void aubuflocal_remove(buf_T *buf)
*/
static int au_new_group(char_u *name)
{
- int i;
-
- i = au_find_group(name);
+ int i = au_find_group(name);
if (i == AUGROUP_ERROR) { /* the group doesn't exist yet, add it */
/* First try using a free entry. */
for (i = 0; i < augroups.ga_len; ++i)
@@ -5694,11 +5692,11 @@ static void au_del_group(char_u *name)
*/
static int au_find_group(char_u *name)
{
- int i;
-
- for (i = 0; i < augroups.ga_len; ++i)
- if (AUGROUP_NAME(i) != NULL && STRCMP(AUGROUP_NAME(i), name) == 0)
+ for (int i = 0; i < augroups.ga_len; ++i) {
+ if (AUGROUP_NAME(i) != NULL && STRCMP(AUGROUP_NAME(i), name) == 0) {
return i;
+ }
+ }
return AUGROUP_ERROR;
}
@@ -5715,8 +5713,6 @@ int au_has_group(char_u *name)
*/
void do_augroup(char_u *arg, int del_group)
{
- int i;
-
if (del_group) {
if (*arg == NUL)
EMSG(_(e_argreq));
@@ -5725,12 +5721,12 @@ void do_augroup(char_u *arg, int del_group)
} else if (STRICMP(arg, "end") == 0) /* ":aug end": back to group 0 */
current_augroup = AUGROUP_DEFAULT;
else if (*arg) { /* ":aug xxx": switch to group xxx */
- i = au_new_group(arg);
+ int i = au_new_group(arg);
if (i != AUGROUP_ERROR)
current_augroup = i;
} else { /* ":aug": list the group names */
msg_start();
- for (i = 0; i < augroups.ga_len; ++i) {
+ for (int i = 0; i < augroups.ga_len; ++i) {
if (AUGROUP_NAME(i) != NULL) {
msg_puts(AUGROUP_NAME(i));
msg_puts((char_u *)" ");
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index e623c388ff..27ae8c979a 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -476,7 +476,6 @@ void newFoldLevel(void)
static void newFoldLevelWin(win_T *wp)
{
fold_T *fp;
- int i;
checkupdate(wp);
if (wp->w_fold_manual) {
@@ -484,7 +483,7 @@ static void newFoldLevelWin(win_T *wp)
* manual open/close will then change the flags to FD_OPEN or
* FD_CLOSED for those folds that don't use 'foldlevel'. */
fp = (fold_T *)wp->w_folds.ga_data;
- for (i = 0; i < wp->w_folds.ga_len; ++i)
+ for (int i = 0; i < wp->w_folds.ga_len; ++i)
fp[i].fd_flags = FD_LEVEL;
wp->w_fold_manual = FALSE;
}
@@ -510,10 +509,9 @@ static int checkCloseRec(garray_T *gap, linenr_T lnum, int level)
{
fold_T *fp;
int retval = FALSE;
- int i;
fp = (fold_T *)gap->ga_data;
- for (i = 0; i < gap->ga_len; ++i) {
+ for (int i = 0; i < gap->ga_len; ++i) {
/* Only manually opened folds may need to be closed. */
if (fp[i].fd_flags == FD_OPEN) {
if (level <= 0 && (lnum < fp[i].fd_top
@@ -1004,7 +1002,6 @@ void foldAdjustCursor(void)
*/
void cloneFoldGrowArray(garray_T *from, garray_T *to)
{
- int i;
fold_T *from_p;
fold_T *to_p;
@@ -1018,7 +1015,7 @@ void cloneFoldGrowArray(garray_T *from, garray_T *to)
from_p = (fold_T *)from->ga_data;
to_p = (fold_T *)to->ga_data;
- for (i = 0; i < from->ga_len; i++) {
+ for (int i = 0; i < from->ga_len; i++) {
to_p->fd_top = from_p->fd_top;
to_p->fd_len = from_p->fd_len;
to_p->fd_flags = from_p->fd_flags;
@@ -1041,7 +1038,6 @@ static int foldFind(garray_T *gap, linenr_T lnum, fold_T **fpp)
{
linenr_T low, high;
fold_T *fp;
- int i;
/*
* Perform a binary search.
@@ -1052,7 +1048,7 @@ static int foldFind(garray_T *gap, linenr_T lnum, fold_T **fpp)
low = 0;
high = gap->ga_len - 1;
while (low <= high) {
- i = (low + high) / 2;
+ int i = (low + high) / 2;
if (fp[i].fd_top > lnum)
/* fold below lnum, adjust high */
high = i - 1;
@@ -1275,11 +1271,10 @@ setManualFoldWin (
*/
static void foldOpenNested(fold_T *fpr)
{
- int i;
fold_T *fp;
fp = (fold_T *)fpr->fd_nested.ga_data;
- for (i = 0; i < fpr->fd_nested.ga_len; ++i) {
+ for (int i = 0; i < fpr->fd_nested.ga_len; ++i) {
foldOpenNested(&fp[i]);
fp[i].fd_flags = FD_OPEN;
}
@@ -1342,9 +1337,7 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive)
*/
void deleteFoldRecurse(garray_T *gap)
{
- int i;
-
- for (i = 0; i < gap->ga_len; ++i)
+ for (int i = 0; i < gap->ga_len; ++i)
deleteFoldRecurse(&(((fold_T *)(gap->ga_data))[i].fd_nested));
ga_clear(gap);
}
@@ -1370,7 +1363,6 @@ void foldMarkAdjust(win_T *wp, linenr_T line1, linenr_T line2, long amount, long
static void foldMarkAdjustRecurse(garray_T *gap, linenr_T line1, linenr_T line2, long amount, long amount_after)
{
fold_T *fp;
- int i;
linenr_T last;
linenr_T top;
@@ -1387,7 +1379,7 @@ static void foldMarkAdjustRecurse(garray_T *gap, linenr_T line1, linenr_T line2,
/*
* Adjust all folds below "line1" that are affected.
*/
- for (i = (int)(fp - (fold_T *)gap->ga_data); i < gap->ga_len; ++i, ++fp) {
+ for (int i = (int)(fp - (fold_T *)gap->ga_data); i < gap->ga_len; ++i, ++fp) {
/*
* Check for these situations:
* 1 2 3
@@ -1468,13 +1460,12 @@ int getDeepestNesting(void)
static int getDeepestNestingRecurse(garray_T *gap)
{
- int i;
int level;
int maxlevel = 0;
fold_T *fp;
fp = (fold_T *)gap->ga_data;
- for (i = 0; i < gap->ga_len; ++i) {
+ for (int i = 0; i < gap->ga_len; ++i) {
level = getDeepestNestingRecurse(&fp[i].fd_nested) + 1;
if (level > maxlevel)
maxlevel = level;
@@ -1561,12 +1552,10 @@ checkSmall (
*/
static void setSmallMaybe(garray_T *gap)
{
- int i;
- fold_T *fp;
-
- fp = (fold_T *)gap->ga_data;
- for (i = 0; i < gap->ga_len; ++i)
+ fold_T *fp = (fold_T *)gap->ga_data;
+ for (int i = 0; i < gap->ga_len; ++i) {
fp[i].fd_small = MAYBE;
+ }
}
/* foldCreateMarkers() {{{2 */
@@ -1632,12 +1621,12 @@ deleteFoldMarkers (
linenr_T lnum_off /* offset for fp->fd_top */
)
{
- int i;
-
- if (recursive)
- for (i = 0; i < fp->fd_neste