diff options
| -rw-r--r-- | src/nvim/digraph.c | 20 | ||||
| -rw-r--r-- | src/nvim/eval.c | 55 | ||||
| -rw-r--r-- | src/nvim/ex_cmds.c | 13 | ||||
| -rw-r--r-- | src/nvim/ex_cmds2.c | 60 | ||||
| -rw-r--r-- | src/nvim/ex_docmd.c | 10 | ||||
| -rw-r--r-- | src/nvim/fileio.c | 18 | ||||
| -rw-r--r-- | src/nvim/fold.c | 56 | ||||
| -rw-r--r-- | src/nvim/garray.c | 3 | ||||
| -rw-r--r-- | src/nvim/menu.c | 17 | ||||
| -rw-r--r-- | src/nvim/misc1.c | 3 | ||||
| -rw-r--r-- | src/nvim/path.c | 13 | ||||
| -rw-r--r-- | src/nvim/spell.c | 146 | ||||
| -rw-r--r-- | src/nvim/syntax.c | 134 | ||||
| -rw-r--r-- | src/nvim/tag.c | 2 | ||||
| -rw-r--r-- | src/nvim/undo.c | 3 | ||||
| -rw-r--r-- | src/nvim/window.c | 3 | 
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(®match, 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_nested.ga_len; ++i) +  if (recursive) { +    for (int i = 0; i < fp->fd_nested.ga_len; ++i) {        deleteFoldMarkers((fold_T *)fp->fd_nested.ga_data + i, TRUE, -          lnum_off + fp->fd_top); +                        lnum_off + fp->fd_top); +    } +  }    foldDelMarker(fp->fd_top + lnum_off, curwin->w_p_fmr, foldstartmarkerlen);    foldDelMarker(fp->fd_top + lnum_off + fp->fd_len - 1,        foldendmarker, foldendmarkerlen); @@ -2908,11 +2897,8 @@ int put_folds(FILE *fd, win_T *wp)   */  static int put_folds_recurse(FILE *fd, garray_T *gap, linenr_T off)  { -  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++) {      /* Do nested folds first, they will be created closed. */      if (put_folds_recurse(fd, &fp->fd_nested, off + fp->fd_top) == FAIL)        return FAIL; @@ -2933,12 +2919,10 @@ static int put_folds_recurse(FILE *fd, garray_T *gap, linenr_T off)   */  static int put_foldopen_recurse(FILE *fd, win_T *wp, garray_T *gap, linenr_T off)  { -  int i;    int level; -  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++) {      if (fp->fd_flags != FD_LEVEL) {        if (!GA_EMPTY(&fp->fd_nested)) {          /* open nested folds while this fold is open */ diff --git a/src/nvim/garray.c b/src/nvim/garray.c index 14c1b1a767..ac5f9155b1 100644 --- a/src/nvim/garray.c +++ b/src/nvim/garray.c @@ -35,8 +35,7 @@ void ga_clear(garray_T *gap)  /// @param gap  void ga_clear_strings(garray_T *gap)  { -  int i; -  for (i = 0; i < gap->ga_len; ++i) { +  for (int i = 0; i < gap->ga_len; ++i) {      free(((char_u **)(gap->ga_data))[i]);    }    ga_clear(gap); diff --git a/src/nvim/menu.c b/src/nvim/menu.c index f1e305f625..bfafeb0be2 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -1454,7 +1454,6 @@ void ex_menutranslate(exarg_T *eap)  {    char_u              *arg = eap->arg;    menutrans_T         *tp; -  int i;    char_u              *from, *from_noamp, *to;    if (menutrans_ga.ga_itemsize == 0) @@ -1465,7 +1464,7 @@ void ex_menutranslate(exarg_T *eap)     */    if (STRNCMP(arg, "clear", 5) == 0 && ends_excmd(*skipwhite(arg + 5))) {      tp = (menutrans_T *)menutrans_ga.ga_data; -    for (i = 0; i < menutrans_ga.ga_len; ++i) { +    for (int i = 0; i < menutrans_ga.ga_len; ++i) {        free(tp[i].from);        free(tp[i].from_noamp);        free(tp[i].to); @@ -1526,24 +1525,26 @@ static char_u *menu_skip_part(char_u *p)  static char_u *menutrans_lookup(char_u *name, int len)  {    menutrans_T         *tp = (menutrans_T *)menutrans_ga.ga_data; -  int i;    char_u              *dname; -  for (i = 0; i < menutrans_ga.ga_len; ++i) -    if (STRNCMP(name, tp[i].from, len) == 0 && tp[i].from[len] == NUL) +  for (int i = 0; i < menutrans_ga.ga_len; ++i) { +    if (STRNCMP(name, tp[i].from, len) == 0 && tp[i].from[len] == NUL) {        return tp[i].to; +    } +  }    /* Now try again while ignoring '&' characters. */ -  i = name[len]; +  char c = name[len];    name[len] = NUL;    dname = menu_text(name, NULL, NULL); -  name[len] = i; +  name[len] = c;    if (dname != NULL) { -    for (i = 0; i < menutrans_ga.ga_len; ++i) +    for (int i = 0; i < menutrans_ga.ga_len; ++i) {        if (STRCMP(dname, tp[i].from_noamp) == 0) {          free(dname);          return tp[i].to;        } +    }      free(dname);    } diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 6774a578a2..e54936c347 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -3153,12 +3153,11 @@ char_u *get_users(expand_T *xp, int idx)   */  int match_user(char_u *name)  { -  int i;    int n = (int)STRLEN(name);    int result = 0;    init_users(); -  for (i = 0; i < ga_users.ga_len; i++) { +  for (int i = 0; i < ga_users.ga_len; i++) {      if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0)        return 2;       /* full match */      if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0) diff --git a/src/nvim/path.c b/src/nvim/path.c index 3edadeebef..4ada2e7f5b 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -588,13 +588,12 @@ static int find_previous_pathsep(char_u *path, char_u **psep)   */  static int is_unique(char_u *maybe_unique, garray_T *gap, int i)  { -  int j;    int candidate_len;    int other_path_len;    char_u  **other_paths = (char_u **)gap->ga_data;    char_u  *rival; -  for (j = 0; j < gap->ga_len; j++) { +  for (int j = 0; j < gap->ga_len; j++) {      if (j == i)        continue;        /* don't compare it with itself */ @@ -686,12 +685,11 @@ static void expand_path_option(char_u *curdir, garray_T *gap)   */  static char_u *get_path_cutoff(char_u *fname, garray_T *gap)  { -  int i;    int maxlen = 0;    char_u  **path_part = (char_u **)gap->ga_data;    char_u  *cutoff = NULL; -  for (i = 0; i < gap->ga_len; i++) { +  for (int i = 0; i < gap->ga_len; i++) {      int j = 0;      while ((fname[j] == path_part[i][j] @@ -718,7 +716,6 @@ static char_u *get_path_cutoff(char_u *fname, garray_T *gap)   */  static void uniquefy_paths(garray_T *gap, char_u *pattern)  { -  int i;    int len;    char_u      **fnames = (char_u **)gap->ga_data;    int sort_again = FALSE; @@ -760,7 +757,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)    in_curdir = xcalloc(gap->ga_len, sizeof(char_u *)); -  for (i = 0; i < gap->ga_len && !got_int; i++) { +  for (int i = 0; i < gap->ga_len && !got_int; i++) {      char_u      *path = fnames[i];      int is_in_curdir;      char_u      *dir_end = gettail_dir(path); @@ -813,7 +810,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)    }    /* Shorten filenames in /in/current/directory/{filename} */ -  for (i = 0; i < gap->ga_len && !got_int; i++) { +  for (int i = 0; i < gap->ga_len && !got_int; i++) {      char_u *rel_path;      char_u *path = in_curdir[i]; @@ -843,7 +840,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)    free(curdir);    if (in_curdir != NULL) { -    for (i = 0; i < gap->ga_len; i++) +    for (int i = 0; i < gap->ga_len; i++)        free(in_curdir[i]);      free(in_curdir);    } diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 924414c7da..38762b1692 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1573,7 +1573,6 @@ static void find_word(matchinf_T *mip, int mode)          int save_result = mip->mi_result;          char_u  *save_end = mip->mi_end;          langp_T *save_lp = mip->mi_lp; -        int lpi;          // Check that a valid word follows.  If there is one and we          // are compounding, it will set "mi_result", thus we are @@ -1604,7 +1603,7 @@ static void find_word(matchinf_T *mip, int mode)          // For NOBREAK we need to try all NOBREAK languages, at least          // to find the ".add" file(s). -        for (lpi = 0; lpi < mip->mi_win->w_s->b_langp.ga_len; ++lpi) { +        for (int lpi = 0; lpi < mip->mi_win->w_s->b_langp.ga_len; ++lpi) {            if (slang->sl_nobreak) {              mip->mi_lp = LANGP_ENTRY(mip->mi_win->w_s->b_langp, lpi);              if (mip->mi_lp->lp_slang->sl_fidxs == NULL @@ -1702,11 +1701,10 @@ match_checkcompoundpattern (      garray_T *gap      // &sl_comppat  )  { -  int i;    char_u      *p;    int len; -  for (i = 0; i + 1 < gap->ga_len; i += 2) { +  for (int i = 0; i + 1 < gap->ga_len; i += 2) {      p = ((char_u **)gap->ga_data)[i + 1];      if (STRNCMP(ptr + wlen, p, STRLEN(p)) == 0) {        // Second part matches at start of following compound word, now @@ -2382,7 +2380,6 @@ static void slang_clear(slang_T *lp)    garray_T    *gap;    fromto_T    *ftp;    salitem_T   *smp; -  int i;    int round;    free(lp->sl_fbyts); @@ -2414,8 +2411,9 @@ static void slang_clear(slang_T *lp)      // "ga_len" is set to 1 without adding an item for latin1      if (gap->ga_data != NULL)        // SOFOFROM and SOFOTO items: free lists of wide characters. -      for (i = 0; i < gap->ga_len; ++i) +      for (int i = 0; i < gap->ga_len; ++i) {          free(((int **)gap->ga_data)[i]); +      }    } else      // SAL items: free salitem_T items      while (!GA_EMPTY(gap)) { @@ -2429,8 +2427,9 @@ static void slang_clear(slang_T *lp)      }    ga_clear(gap); -  for (i = 0; i < lp->sl_prefixcnt; ++i) +  for (int i = 0; i < lp->sl_prefixcnt; ++i) {      vim_regfree(lp->sl_prefprog[i]); +  }    lp->sl_prefixcnt = 0;    free(lp->sl_prefprog);    lp->sl_prefprog = NULL; @@ -2859,7 +2858,6 @@ static int read_rep_section(FILE *fd, garray_T *gap, short *first)  {    int cnt;    fromto_T    *ftp; -  int i;    cnt = get2c(fd);                                      // <repcount>    if (cnt < 0) @@ -2869,25 +2867,27 @@ static int read_rep_section(FILE *fd, garray_T *gap, short *first)    // <rep> : <repfromlen> <repfrom> <reptolen> <repto>    for (; gap->ga_len < cnt; ++gap->ga_len) { +    int c;      ftp = &((fromto_T *)gap->ga_data)[gap->ga_len]; -    ftp->ft_from = read_cnt_string(fd, 1, &i); -    if (i < 0) -      return i; -    if (i == 0) +    ftp->ft_from = read_cnt_string(fd, 1, &c); +    if (c < 0) +      return c; +    if (c == 0)        return SP_FORMERROR; -    ftp->ft_to = read_cnt_string(fd, 1, &i); -    if (i <= 0) { +    ftp->ft_to = read_cnt_string(fd, 1, &c); +    if (c <= 0) {        free(ftp->ft_from); -      if (i < 0) -        return i; +      if (c < 0) +        return c;        return SP_FORMERROR;      }    }    // Fill the first-index table. -  for (i = 0; i < 256; ++i) +  for (int i = 0; i < 256; ++i) {      first[i] = -1; -  for (i = 0; i < gap->ga_len; ++i) { +  } +  for (int i = 0; i < gap->ga_len; ++i) {      ftp = &((fromto_T *)gap->ga_data)[i];      if (first[*ftp->ft_from] == -1)        first[*ftp->ft_from] = i; @@ -3369,7 +3369,6 @@ static int count_syllables(slang_T *slang, char_u *word)    int skip = FALSE;    char_u      *p;    int len; -  int i;    syl_item_T  *syl;    int c; @@ -3386,7 +3385,7 @@ static int count_syllables(slang_T *slang, char_u *word)      // Find longest match of syllable items.      len = 0; -    for (i = 0; i < slang->sl_syl_items.ga_len; ++i) { +    for (int i = 0; i < slang->sl_syl_items.ga_len; ++i) {        syl = ((syl_item_T *)slang->sl_syl_items.ga_data) + i;        if (syl->sy_len > len            && STRNCMP(p, syl->sy_chars, syl->sy_len) == 0) @@ -3488,16 +3487,16 @@ static int set_sofo(slang_T *lp, char_u *from, char_u *to)  static void set_sal_first(slang_T *lp)  {    salfirst_T  *sfirst; -  int i;    salitem_T   *smp;    int c;    garray_T    *gap = &lp->sl_sal;    sfirst = lp->sl_sal_first; -  for (i = 0; i < 256; ++i) +  for (int i = 0; i < 256; ++i) {      sfirst[i] = -1; +  }    smp = (salitem_T *)gap->ga_data; -  for (i = 0; i < gap->ga_len; ++i) { +  for (int i = 0; i < gap->ga_len; ++i) {      if (has_mbyte)        // Use the lowest byte of the first character.  For latin1 it's        // the character, for other encodings it should differ for most @@ -3719,7 +3718,6 @@ char_u *did_set_spelllang(win_T *wp)    char_u      *use_region = NULL;    int dont_use_region = FALSE;    int nobreak = FALSE; -  int i, j;    langp_T     *lp, *lp2;    static int recursive = FALSE;    char_u      *ret_msg = NULL; @@ -3928,7 +3926,7 @@ char_u *did_set_spelllang(win_T *wp)    // For each language figure out what language to use for sound folding and    // REP items.  If the language doesn't support it itself use another one    // with the same name.  E.g. for "en-math" use "en". -  for (i = 0; i < ga.ga_len; ++i) { +  for (int i = 0; i < ga.ga_len; ++i) {      lp = LANGP_ENTRY(ga, i);      // sound folding @@ -3937,7 +3935,7 @@ char_u *did_set_spelllang(win_T *wp)        lp->lp_sallang = lp->lp_slang;      else        // find first similar language that does sound folding -      for (j = 0; j < ga.ga_len; ++j) { +      for (int j = 0; j < ga.ga_len; ++j) {          lp2 = LANGP_ENTRY(ga, j);          if (!GA_EMPTY(&lp2->lp_slang->sl_sal)              && STRNCMP(lp->lp_slang->sl_name, @@ -3953,7 +3951,7 @@ char_u *did_set_spelllang(win_T *wp)        lp->lp_replang = lp->lp_slang;      else        // find first similar language that has REP items -      for (j = 0; j < ga.ga_len; ++j) { +      for (int j = 0; j < ga.ga_len; ++j) {          lp2 = LANGP_ENTRY(ga, j);          if (!GA_EMPTY(&lp2->lp_slang->sl_rep)              && STRNCMP(lp->lp_slang->sl_name, @@ -6760,7 +6758,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)      // Compute the length of what follows.      l = 2;          // count <repcount> or <salcount> -    for (i = 0; i < gap->ga_len; ++i) { +    for (int i = 0; i < gap->ga_len; ++i) {        ftp = &((fromto_T *)gap->ga_data)[i];        l += 1 + (int)STRLEN(ftp->ft_from);        // count <*fromlen> and <*from>        l += 1 + (int)STRLEN(ftp->ft_to);          // count <*tolen> and <*to> @@ -6781,7 +6779,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)      }      put_bytes(fd, (long_u)gap->ga_len, 2);      // <repcount> or <salcount> -    for (i = 0; i < gap->ga_len; ++i) { +    for (int i = 0; i < gap->ga_len; ++i) {        // <rep> : <repfromlen> <repfrom> <reptolen> <repto>        // <sal> : <salfromlen> <salfrom> <saltolen> <salto>        ftp = &((fromto_T *)gap->ga_data)[i]; @@ -6886,8 +6884,9 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)      putc(0, fd);                                        // <sectionflags>      l = (int)STRLEN(spin->si_compflags); -    for (i = 0; i < spin->si_comppat.ga_len; ++i) +    for (int i = 0; i < spin->si_comppat.ga_len; ++i) {        l += (int)STRLEN(((char_u **)(spin->si_comppat.ga_data))[i]) + 1; +    }      put_bytes(fd, (long_u)(l + 7), 4);                  // <sectionlen>      putc(spin->si_compmax, fd);                         // <compmax> @@ -6897,7 +6896,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)      putc(spin->si_compoptions, fd);                     // <compoptions>      put_bytes(fd, (long_u)spin->si_comppat.ga_len, 2);      // <comppatcount> -    for (i = 0; i < spin->si_comppat.ga_len; ++i) { +    for (int i = 0; i < spin->si_comppat.ga_len; ++i) {        p = ((char_u **)(spin->si_comppat.ga_data))[i];        putc((int)STRLEN(p), fd);                         // <comppatlen>        fwv &= fwrite(p, (size_t)STRLEN(p), (size_t)1, fd); @@ -8296,7 +8295,6 @@ static int spell_iswordp_w(int *p, win_T *wp)  // When "fd" is NULL only count the length of what is written.  static int write_spell_prefcond(FILE *fd, garray_T *gap)  { -  int i;    char_u      *p;    int len;    int totlen; @@ -8307,7 +8305,7 @@ static int write_spell_prefcond(FILE *fd, garray_T *gap)    totlen = 2 + gap->ga_len;   // length of <prefcondcnt> and <condlen> bytes -  for (i = 0; i < gap->ga_len; ++i) { +  for (int i = 0; i < gap->ga_len; ++i) {      // <prefcond> : <condlen> <condstr>      p = ((char_u **)gap->ga_data)[i];      if (p != NULL) { @@ -8426,7 +8424,6 @@ void spell_suggest(int count)    pos_T prev_cursor = curwin->w_cursor;    char_u wcopy[MAXWLEN + 2];    char_u      *p; -  int i;    int c;    suginfo_T sug;    suggest_T   *stp; @@ -8528,7 +8525,7 @@ void spell_suggest(int count)      msg_putchar('\n');      msg_scroll = TRUE; -    for (i = 0; i < sug.su_ga.ga_len; ++i) { +    for (int i = 0; i < sug.su_ga.ga_len; ++i) {        stp = &SUG(sug.su_ga, i);        // The suggested word may replace only part of the bad word, add @@ -8753,7 +8750,6 @@ spell_suggest_list (  )  {    suginfo_T sug; -  int i;    suggest_T   *stp;    char_u      *wcopy; @@ -8762,7 +8758,7 @@ spell_suggest_list (    // Make room in "gap".    ga_init(gap, sizeof(char_u *), sug.su_ga.ga_len + 1);    ga_grow(gap, sug.su_ga.ga_len); -  for (i = 0; i < sug.su_ga.ga_len; ++i) { +  for (int i = 0; i < sug.su_ga.ga_len; ++i) {      stp = &SUG(sug.su_ga, i);      // The suggested word may replace only part of "word", add the not @@ -8800,7 +8796,6 @@ spell_find_suggest (    char_u      *sps_copy;    static int expr_busy = FALSE;    int c; -  int i;    langp_T     *lp;    // Set the info in "*su". @@ -8834,7 +8829,7 @@ spell_find_suggest (    // one in 'spelllang' that supports sound folding.  That's good for when    // using multiple files for one language, it's not that bad when mixing    // languages (e.g., "pl,en"). -  for (i = 0; i < curbuf->b_s.b_langp.ga_len; ++i) { +  for (int i = 0; i < curbuf->b_s.b_langp.ga_len; ++i) {      lp = LANGP_ENTRY(curbuf->b_s.b_langp, i);      if (lp->lp_sallang != NULL) {        su->su_sallang = lp->lp_sallang; @@ -9053,7 +9048,6 @@ static void spell_suggest_intern(suginfo_T *su, int interactive)  static void suggest_load_files(void)  {    langp_T     *lp; -  int lpi;    slang_T     *slang;    char_u      *dotp;    FILE        *fd; @@ -9066,7 +9060,7 @@ static void suggest_load_files(void)    int c;    // Do this for all languages that support sound folding. -  for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { +  for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {      lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);      slang = lp->lp_slang;      if (slang->sl_sugtime != 0 && !slang->sl_sugloaded) { @@ -9222,14 +9216,14 @@ static void tree_count_words(char_u *byts, idx_T *idxs)  // Free the info put in "*su" by spell_find_suggest().  static void spell_find_cleanup(suginfo_T *su)  { -  int i; -    // Free the suggestions. -  for (i = 0; i < su->su_ga.ga_len; ++i) +  for (int i = 0; i < su->su_ga.ga_len; ++i) {      free(SUG(su->su_ga, i).st_word); +  }    ga_clear(&su->su_ga); -  for (i = 0; i < su->su_sga.ga_len; ++i) +  for (int i = 0; i < su->su_sga.ga_len; ++i) {      free(SUG(su->su_sga, i).st_word); +  }    ga_clear(&su->su_sga);    // Free the banned words. @@ -9339,7 +9333,6 @@ static void suggest_try_change(suginfo_T *su)    char_u fword[MAXWLEN];            // copy of the bad word, case-folded    int n;    char_u      *p; -  int lpi;    langp_T     *lp;    // We make a copy of the case-folded bad word, so that we can modify it @@ -9350,7 +9343,7 @@ static void suggest_try_change(suginfo_T *su)    p = su->su_badptr + su->su_badlen;    (void)spell_casefold(p, (int)STRLEN(p), fword + n, MAXWLEN - n); -  for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { +  for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {      lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);      // If reloading a spell file fails it's still in the list but @@ -10802,12 +10795,11 @@ static void score_comp_sal(suginfo_T *su)    suggest_T   *stp;    suggest_T   *sstp;    int score; -  int lpi;    ga_grow(&su->su_sga, su->su_ga.ga_len);    // Use the sound-folding of the first language that supports it. -  for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { +  for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {      lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);      if (!GA_EMPTY(&lp->lp_slang->sl_sal)) {        // soundfold the bad word @@ -10839,8 +10831,6 @@ static void score_comp_sal(suginfo_T *su)  // They are entwined.  static void score_combine(suginfo_T *su)  { -  int i; -  int j;    garray_T ga;    garray_T    *gap;    langp_T     *lp; @@ -10848,18 +10838,17 @@ static void score_combine(suginfo_T *su)    char_u      *p;    char_u badsound[MAXWLEN];    int round; -  int lpi;    slang_T     *slang = NULL;    // Add the alternate score to su_ga. -  for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { +  for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {      lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);      if (!GA_EMPTY(&lp->lp_slang->sl_sal)) {        // soundfold the bad word        slang = lp->lp_slang;        spell_soundfold(slang, su->su_fbadword, TRUE, badsound); -      for (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);          stp->st_altscore = stp_sal_score(stp, su, slang, badsound);          if (stp->st_altscore == SCORE_MAXMAX) @@ -10880,7 +10869,7 @@ static void score_combine(suginfo_T *su)    }    // Add the alternate score to su_sga. -  for (i = 0; i < su->su_sga.ga_len; ++i) { +  for (int i = 0; i < su->su_sga.ga_len; ++i) {      stp = &SUG(su->su_sga, i);      stp->st_altscore = spell_edit_score(slang,          su->su_badword, stp->st_word); @@ -10902,7 +10891,7 @@ static void score_combine(suginfo_T *su)    ga_grow(&ga, su->su_ga.ga_len + su->su_sga.ga_len);    stp = &SUG(ga, 0); -  for (i = 0; i < su->su_ga.ga_len || i < su->su_sga.ga_len; ++i) { +  for (int i = 0; i < su->su_ga.ga_len || i < su->su_sga.ga_len; ++i) {      // round 1: get a suggestion from su_ga      // round 2: get a suggestion from su_sga      for (round = 1; round <= 2; ++round) { @@ -10910,6 +10899,7 @@ static void score_combine(suginfo_T *su)        if (i < gap->ga_len) {          // Don't add a word if it's already there.          p = SUG(*gap, i).st_word; +        int j;          for (j = 0; j < ga.ga_len; ++j)            if (STRCMP(stp[j].st_word, p) == 0)              break; @@ -10926,8 +10916,9 @@ static void score_combine(suginfo_T *su)    // Truncate the list to the number of suggestions that will be displayed.    if (ga.ga_len > su->su_maxcount) { -    for (i = su->su_maxcount; i < ga.ga_len; ++i) +    for (int i = su->su_maxcount; i < ga.ga_len; ++i) {        free(stp[i].st_word); +    }      ga.ga_len = su->su_maxcount;    } @@ -10997,12 +10988,11 @@ static sftword_T dumsft;  static void suggest_try_soundalike_prep(void)  {    langp_T     *lp; -  int lpi;    slang_T     *slang;    // Do this for all languages that support sound folding and for which a    // .sug file has been loaded. -  for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { +  for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {      lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);      slang = lp->lp_slang;      if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) @@ -11017,12 +11007,11 @@ static void suggest_try_soundalike(suginfo_T *su)  {    char_u salword[MAXWLEN];    langp_T     *lp; -  int lpi;    slang_T     *slang;    // Do this for all languages that support sound folding and for which a    // .sug file has been loaded. -  for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { +  for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {      lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);      slang = lp->lp_slang;      if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) { @@ -11041,14 +11030,13 @@ static void suggest_try_soundalike(suginfo_T *su)  static void suggest_try_soundalike_finish(void)  {    langp_T     *lp; -  int lpi;    slang_T     *slang;    int todo;    hashitem_T  *hi;    // Do this for all languages that support sound folding and for which a    // .sug file has been loaded. -  for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { +  for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {      lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);      slang = lp->lp_slang;      if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) { @@ -11475,7 +11463,7 @@ add_suggestion (      // being replaced "thes," -> "these" is a different suggestion from      // "thes" -> "these".      stp = &SUG(*gap, 0); -    for (i = gap->ga_len; --i >= 0; ++stp) +    for (i = gap->ga_len; --i >= 0; ++stp) {        if (stp->st_wordlen == goodlen            && stp->st_orglen == badlen            && STRNCMP(stp->st_word, goodword, goodlen) == 0) { @@ -11512,6 +11500,7 @@ add_suggestion (          }          break;        } +    }    }    if (i < 0) { @@ -11549,13 +11538,12 @@ check_suggestions (  )  {    suggest_T   *stp; -  int i;    char_u longword[MAXWLEN + 1];    int len;    hlf_T attr;    stp = &SUG(*gap, 0); -  for (i = gap->ga_len - 1; i >= 0; --i) { +  for (int i = gap->ga_len - 1; i >= 0; --i) {      // Need to append what follows to check for "the the".      vim_strncpy(longword, stp[i].st_word, MAXWLEN);      len = stp[i].st_wordlen; @@ -11594,11 +11582,11 @@ static void add_banned(suginfo_T *su, char_u *word)  // is slow, thus only done for the final results.  static void rescore_suggestions(suginfo_T *su)  { -  int i; - -  if (su->su_sallang != NULL) -    for (i = 0; i < su->su_ga.ga_len; ++i) +  if (su->su_sallang != NULL) { +    for (int i = 0; i < su->su_ga.ga_len; ++i) {        rescore_one(su, &SUG(su->su_ga, i)); +    } +  }  }  // Recompute the score for one suggestion if sound-folding is possible. @@ -11655,15 +11643,15 @@ cleanup_suggestions (  )  {    suggest_T   *stp = &SUG(*gap, 0); -  int i;    // Sort the list.    qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), sug_compare);    // Truncate the list to the number of suggestions that will be displayed.    if (gap->ga_len > keep) { -    for (i = keep; i < gap->ga_len; ++i) +    for (int i = keep; i < gap->ga_len; ++i) {        free(stp[i].st_word); +    }      gap->ga_len = keep;      return stp[keep - 1].st_score;    } @@ -11676,11 +11664,10 @@ char_u *eval_soundfold(char_u *word)  {    langp_T     *lp;    char_u sound[MAXWLEN]; -  int lpi; -  if (curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) +  if (curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) {      // Use the sound-folding of the first language that supports it. -    for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { +    for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {        lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);        if (!GA_EMPTY(&lp->lp_slang->sl_sal)) {          // soundfold the word @@ -11688,6 +11675,7 @@ char_u *eval_soundfold(char_u *word)          return vim_strsave(sound);        }      } +  }    // No language with sound folding, return word as-is.    return vim_strsave(word); @@ -12916,7 +12904,6 @@ pop:  // ":spellinfo"  void ex_spellinfo(exarg_T *eap)  { -  int lpi;    langp_T     *lp;    char_u      *p; @@ -12924,7 +12911,7 @@ void ex_spellinfo(exarg_T *eap)      return;    msg_start(); -  for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len && !got_int; ++lpi) { +  for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len && !got_int; ++lpi) {      lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);      msg_puts((char_u *)"file: ");      msg_puts(lp->lp_slang->sl_fname); @@ -13002,7 +12989,6 @@ spell_dump_compl (    char_u      *region_names = NULL;         // region names being used    int do_region = TRUE;                     // dump region names and numbers    char_u      *p; -  int lpi;    int dumpflags = dumpflags_arg;    int patlen; @@ -13024,7 +13010,7 @@ spell_dump_compl (    // Find out if we can support regions: All languages must support the same    // regions or none at all. -  for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { +  for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {      lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);      p = lp->lp_slang->sl_regions;      if (p[0] != 0) { @@ -13046,7 +13032,7 @@ spell_dump_compl (      do_region = FALSE;    // Loop over all files loaded for the entries in 'spelllang'. -  for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { +  for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {      lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);      slang = lp->lp_slang;      if (slang->sl_fbyts == NULL)            // reloading failed diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 854e120466..baf8e1c8d3 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -541,17 +541,18 @@ void syntax_start(win_T *wp, linenr_T lnum)   */  static void clear_syn_state(synstate_T *p)  { -  int i;    garray_T    *gap;    if (p->sst_stacksize > SST_FIX_STATES) {      gap = &(p->sst_union.sst_ga); -    for (i = 0; i < gap->ga_len; i++) +    for (int i = 0; i < gap->ga_len; i++) {        unref_extmatch(SYN_STATE_P(gap)[i].bs_extmatch); +    }      ga_clear(gap);    } else { -    for (i = 0; i < p->sst_stacksize; i++) +    for (int i = 0; i < p->sst_stacksize; i++) {        unref_extmatch(p->sst_union.sst_stack[i].bs_extmatch); +    }    }  } @@ -560,12 +561,10 @@ static void clear_syn_state(synstate_T *p)   */  static void clear_current_state(void)  { -  int i; -  stateitem_T *sip; - -  sip = (stateitem_T *)(current_state.ga_data); -  for (i = 0; i < current_state.ga_len; i++) +  stateitem_T *sip = (stateitem_T *)(current_state.ga_data); +  for (int i = 0; i < current_state.ga_len; i++) {      unref_extmatch(sip[i].si_extmatch); +  }    ga_clear(¤t_state);  } @@ -870,13 +869,12 @@ static void syn_start_line(void)  static void syn_update_ends(int startofline)  {    stateitem_T *cur_si; -  int i;    int seen_keepend;    if (startofline) {      /* Check for a match carried over from a previous line with a       * contained region.  The match ends as soon as the region ends. */ -    for (i = 0; i < current_state.ga_len; ++i) { +    for (int i = 0; i < current_state.ga_len; ++i) {        cur_si = &CUR_STATE(i);        if (cur_si->si_idx >= 0            && (SYN_ITEMS(syn_block)[cur_si->si_idx]).sp_type @@ -900,7 +898,7 @@ static void syn_update_ends(int startofline)     * these "keepend" regions as well as contained normal regions.     * Then check for items ending in column 0.     */ -  i = current_state.ga_len - 1; +  int i = current_state.ga_len - 1;    if (keepend_level >= 0)      for (; i > keepend_level; --i)        if (CUR_STATE(i).si_flags & HL_EXTEND) @@ -1362,7 +1360,6 @@ static void load_current_state(synstate_T *from)   */  static int syn_stack_equal(synstate_T *sp)  { -  int i, j;    bufstate_T  *bp;    reg_extmatch_T      *six, *bsx; @@ -1375,6 +1372,7 @@ static int syn_stack_equal(synstate_T *sp)      else        bp = sp->sst_union.sst_stack; +    int i;      for (i = current_state.ga_len; --i >= 0; ) {        /* If the item has another index the state is different. */        if (bp[i].bs_idx != CUR_STATE(i).si_idx) @@ -1389,6 +1387,7 @@ static int syn_stack_equal(synstate_T *sp)           * different. */          if (bsx == NULL || six == NULL)            break; +        int j;          for (j = 0; j < NSUBEXP; ++j) {            /* Check each referenced match string. They must all be             * equal. */ @@ -1617,7 +1616,6 @@ syn_current_attr (    lpos_T eos_pos;               /* end-of-start match (start region) */    lpos_T eoe_pos;               /* end-of-end pattern */    int end_idx;                  /* group ID for end pattern */ -  int idx;    synpat_T    *spp;    stateitem_T *cur_si, *sip = NULL;    int startcol; @@ -1782,7 +1780,7 @@ syn_current_attr (             */            next_match_idx = 0;                   /* no match in this line yet */            next_match_col = MAXCOL; -          for (idx = syn_block->b_syn_patterns.ga_len; --idx >= 0; ) { +          for (int idx = syn_block->b_syn_patterns.ga_len; --idx >= 0; ) {              spp = &(SYN_ITEMS(syn_block)[idx]);              if (       spp->sp_syncing == syncing                         && (displaying || !(spp->sp_flags & HL_DISPLAY)) @@ -2018,7 +2016,7 @@ syn_current_attr (    current_trans_id = 0;    current_flags = 0;    if (cur_si != NULL) { -    for (idx = current_state.ga_len - 1; idx >= 0; --idx) { +    for (int idx = current_state.ga_len - 1; idx >= 0; --idx) {        sip = &CUR_STATE(idx);        if ((current_lnum > sip->si_h_startpos.lnum             || (current_lnum == sip->si_h_startpos.lnum @@ -2126,19 +2124,21 @@ syn_current_attr (   */  static int did_match_already(int idx, garray_T *gap)  { -  int i; - -  for (i = current_state.ga_len; --i >= 0; ) +  for (int i = current_state.ga_len; --i >= 0; ) {      if (CUR_STATE(i).si_m_startcol == (int)current_col          && CUR_STATE(i).si_m_lnum == (int)current_lnum -        && CUR_STATE(i).si_idx == idx) +        && CUR_STATE(i).si_idx == idx) {        return TRUE; +    } +  }    /* Zero-width matches with a nextgroup argument are not put on the syntax     * stack, and can only be matched once anyway. */ -  for (i = gap->ga_len; --i >= 0; ) -    if (((int *)(gap->ga_data))[i] == idx) +  for (int i = gap->ga_len; --i >= 0; ) { +    if (((int *)(gap->ga_data))[i] == idx) {        return TRUE; +    } +  }    return FALSE;  } @@ -3034,8 +3034,6 @@ static void syn_cmd_spell(exarg_T *eap, int syncing)   */  void syntax_clear(synblock_T *block)  { -  int i; -    block->b_syn_error = FALSE;       /* clear previous error */    block->b_syn_ic = FALSE;          /* Use case, by default */    block->b_syn_spell = SYNSPL_DEFAULT;   /* default spell checking */ @@ -3046,13 +3044,15 @@ void syntax_clear(synblock_T *block)    clear_keywtab(&block->b_keywtab_ic);    /* free the syntax patterns */ -  for (i = block->b_syn_patterns.ga_len; --i >= 0; ) +  for (int i = block->b_syn_patterns.ga_len; --i >= 0; ) {      syn_clear_pattern(block, i); +  }    ga_clear(&block->b_syn_patterns);    /* free the syntax clusters */ -  for (i = block->b_syn_clusters.ga_len; --i >= 0; ) +  for (int i = block->b_syn_clusters.ga_len; --i >= 0; ) {      syn_clear_cluster(block, i); +  }    ga_clear(&block->b_syn_clusters);    block->b_spell_cluster_id = 0;    block->b_nospell_cluster_id = 0; @@ -3093,12 +3093,12 @@ void reset_synblock(win_T *wp)   */  static void syntax_sync_clear(void)  { -  int i; -    /* free the syntax patterns */ -  for (i = curwin->w_s->b_syn_patterns.ga_len; --i >= 0; ) -    if (SYN_ITEMS(curwin->w_s)[i].sp_syncing) +  for (int i = curwin->w_s->b_syn_patterns.ga_len; --i >= 0; ) { +    if (SYN_ITEMS(curwin->w_s)[i].sp_syncing) {        syn_remove_pattern(curwin->w_s, i); +    } +  }    curwin->w_s->b_syn_sync_flags = 0;    curwin->w_s->b_syn_sync_minlines = 0; @@ -3232,7 +3232,6 @@ static void syn_cmd_clear(exarg_T *eap, int syncing)  static void syn_clear_one(int id, int syncing)  {    synpat_T    *spp; -  int idx;    /* Clear keywords only when not ":syn sync clear group-name" */    if (!syncing) { @@ -3241,7 +3240,7 @@ static void syn_clear_one(int id, int syncing)    }    /* clear the patterns for "id" */ -  for (idx = curwin->w_s->b_syn_patterns.ga_len; --idx >= 0; ) { +  for (int idx = curwin->w_s->b_syn_patterns.ga_len; --idx >= 0; ) {      spp = &(SYN_ITEMS(curwin->w_s)[idx]);      if (spp->sp_syn.id != id || spp->sp_syncing != syncing)        continue; @@ -3318,7 +3317,6 @@ syn_cmd_list (  )  {    char_u      *arg = eap->arg; -  int id;    char_u      *arg_end;    eap->nextcmd = find_nextcmd(arg); @@ -3361,10 +3359,12 @@ syn_cmd_list (      /*       * No argument: List all group IDs and all syntax clusters.       */ -    for (id = 1; id <= highlight_ga.ga_len && !got_int; ++id) +    for (int id = 1; id <= highlight_ga.ga_len && !got_int; ++id) {        syn_list_one(id, syncing, FALSE); -    for (id = 0; id < curwin->w_s->b_syn_clusters.ga_len && !got_int; ++id) +    } +    for (int id = 0; id < curwin->w_s->b_syn_clusters.ga_len && !got_int; ++id) {        syn_list_cluster(id); +    }    } else {      /*       * List the group IDs and syntax clusters that are in the argument. @@ -3372,13 +3372,13 @@ syn_cmd_list (      while (!ends_excmd(*arg) && !got_int) {        arg_end = skiptowhite(arg);        if (*arg == '@') { -        id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); +        int id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1));          if (id == 0)            EMSG2(_("E392: No such syntax cluster: %s"), arg);          else            syn_list_cluster(id - SYNID_CLUSTER);        } else { -        id = syn_namen2id(arg, (int)(arg_end - arg)); +        int id = syn_namen2id(arg, (int)(arg_end - arg));          if (id == 0)            EMSG2(_(e_nogroup), arg);          else @@ -3432,7 +3432,6 @@ syn_list_one (  )  {    int attr; -  int idx;    int did_header = FALSE;    synpat_T    *spp;    static struct name_list namelist1[] = @@ -3467,7 +3466,7 @@ syn_list_one (    }    /* list the patterns for "id" */ -  for (idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len && !got_int; ++idx) { +  for (int idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len && !got_int; ++idx) {      spp = &(SYN_ITEMS(curwin->w_s)[idx]);      if (spp->sp_syn.id != id || spp->sp_syncing != syncing)        continue; @@ -3904,7 +3903,6 @@ get_syn_options (    int syn_id;    int len;    char        *p; -  int i;    int fidx;    static struct flag {      char    *name; @@ -3948,6 +3946,7 @@ get_syn_options (      for (fidx = sizeof(flagtab) / sizeof(struct flag); --fidx >= 0; ) {        p = flagtab[fidx].name; +      int i;        for (i = 0, len = 0; p[i] != NUL; i += 2, ++len)          if (arg[len] != p[i] && arg[len] != p[i + 1])            break; @@ -4012,6 +4011,7 @@ get_syn_options (            *opt->sync_idx = NONE_IDX;          else {            syn_id = syn_name2id(gname); +          int i;            for (i = curwin->w_s->b_syn_patterns.ga_len; --i >= 0; )              if (SYN_ITEMS(curwin->w_s)[i].sp_syn.id == syn_id                  && SYN_ITEMS(curwin->w_s)[i].sp_type == SPTYPE_START) { @@ -4247,7 +4247,6 @@ syn_cmd_match (    char_u      *rest;    synpat_T item;                /* the item found in the line */    int syn_id; -  int idx;    syn_opt_arg_T syn_opt_arg;    int sync_idx = 0;    int conceal_char = NUL; @@ -4289,7 +4288,7 @@ syn_cmd_match (          /*           * Store the pattern in the syn_items list           */ -        idx = curwin->w_s->b_syn_patterns.ga_len; +        int idx = curwin->w_s->b_syn_patterns.ga_len;          SYN_ITEMS(curwin->w_s)[idx] = item;          SYN_ITEMS(curwin->w_s)[idx].sp_syncing = syncing;          SYN_ITEMS(curwin->w_s)[idx].sp_type = SPTYPE_MATCH; @@ -4367,7 +4366,6 @@ syn_cmd_region (    int not_enough = FALSE;                       /* not enough arguments */    int illegal = FALSE;                          /* illegal arguments */    int success = FALSE; -  int idx;    syn_opt_arg_T syn_opt_arg;    int conceal_char = NUL; @@ -4501,7 +4499,7 @@ syn_cmd_region (          /*           * Store the start/skip/end in the syn_items list           */ -        idx = curwin->w_s->b_syn_patterns.ga_len; +        int idx = curwin->w_s->b_syn_patterns.ga_len;          for (item = ITEM_START; item <= ITEM_END; ++item) {            for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp->pp_next) {              SYN_ITEMS(curwin->w_s)[idx] = *(ppp->pp_synp); @@ -4696,17 +4694,19 @@ static void syn_combine_list(short **clstr1, short **clstr2, int list_op)   */  static int syn_scl_name2id(char_u *name)  { -  int i;    char_u      *name_u;    /* Avoid using stricmp() too much, it's slow on some systems */    name_u = vim_strsave_up(name);    if (name_u == NULL)      return 0; -  for (i = curwin->w_s->b_syn_clusters.ga_len; --i >= 0; ) +  int i; +  for (i = curwin->w_s->b_syn_clusters.ga_len; --i >= 0; ) {      if (SYN_CLSTR(curwin->w_s)[i].scl_name_u != NULL -        && STRCMP(name_u, SYN_CLSTR(curwin->w_s)[i].scl_name_u) == 0) +        && STRCMP(name_u, SYN_CLSTR(curwin->w_s)[i].scl_name_u) == 0) {        break; +    } +  }    free(name_u);    return i < 0 ? 0 : i + SYNID_CLUSTER;  } @@ -4751,8 +4751,6 @@ static int syn_check_cluster(char_u *pp, int len)   */  static int syn_add_cluster(char_u *name)  { -  int len; -    /*     * First call for this growarray: init growing array.     */ @@ -4761,7 +4759,7 @@ static int syn_add_cluster(char_u *name)      curwin->w_s->b_syn_clusters.ga_growsize = 10;    } -  len = curwin->w_s->b_syn_clusters.ga_len; +  int len = curwin->w_s->b_syn_clusters.ga_len;    if (len >= MAX_CLUSTER_ID) {      EMSG((char_u *)_("E848: Too many syntax clusters"));      free(name); @@ -5094,7 +5092,6 @@ get_id_list (    char_u      *name;    regmatch_T regmatch;    int id; -  int i;    int failed = FALSE;    /* @@ -5174,7 +5171,7 @@ get_id_list (            regmatch.rm_ic = TRUE;            id = 0; -          for (i = highlight_ga.ga_len; --i >= 0; ) { +          for (int i = highlight_ga.ga_len; --i >= 0; ) {              if (vim_regexec(®match, HL_TABLE()[i].sg_name,                      (colnr_T)0)) {                if (round == 2) { @@ -5608,15 +5605,16 @@ int syn_get_stack_item(int i)  int syn_get_foldlevel(win_T *wp, long lnum)  {    int level = 0; -  int i;    /* Return quickly when there are no fold items at all. */    if (wp->w_s->b_syn_folditems != 0) {      syntax_start(wp, lnum); -    for (i = 0; i < current_state.ga_len; ++i) -      if (CUR_STATE(i).si_flags & HL_FOLD) +    for (int i = 0; i < current_state.ga_len; ++i) { +      if (CUR_STATE(i).si_flags & HL_FOLD) {          ++level; +      } +    }    }    if (level > wp->w_p_fdn) {      level = wp->w_p_fdn; @@ -5656,14 +5654,13 @@ static void syn_clear_time(syn_time_T *st)   */  static void syntime_clear(void)  { -  int idx;    synpat_T    *spp;    if (!syntax_present(curwin)) {      MSG(_(msg_no_items));      return;    } -  for (idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len; ++idx) { +  for (int idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len; ++idx) {      spp = &(SYN_ITEMS(curwin->w_s)[idx]);      syn_clear_time(&spp->sp_time);    } @@ -5697,7 +5694,6 @@ static int syn_compare_syntime(const void *v1, const void *v2)   */  static void syntime_report(void)  { -  int idx;    synpat_T    *spp;    proftime_T tm;    int len; @@ -5713,7 +5709,7 @@ static void syntime_report(void)    ga_init(&ga, sizeof(time_entry_T), 50);    profile_zero(&total_total); -  for (idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len; ++idx) { +  for (int idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len; ++idx) {      spp = &(SYN_ITEMS(curwin->w_s)[idx]);      if (spp->sp_time.count > 0) {        ga_grow(&ga, 1); @@ -5739,7 +5735,7 @@ static void syntime_report(void)    MSG_PUTS_TITLE(_(            "  TOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME               PATTERN"));    MSG_PUTS("\n"); -  for (idx = 0; idx < ga.ga_len && !got_int; ++idx) { +  for (int idx = 0; idx < ga.ga_len && !got_int; ++idx) {      spp = &(SYN_ITEMS(curwin->w_s)[idx]);      p = ((time_entry_T *)ga.ga_data) + idx; @@ -6103,7 +6099,7 @@ do_highlight (     * If no argument, list current highlighting.     */    if (ends_excmd(*line)) { -    for (i = 1; i <= highlight_ga.ga_len && !got_int; ++i) +    for (int i = 1; i <= highlight_ga.ga_len && !got_int; ++i)        /* TODO: only call when the group has attributes set */        highlight_list_one((int)i);      return; @@ -6213,8 +6209,9 @@ do_highlight (        /*         * Clear all default highlight groups and load the defaults.         */ -      for (idx = 0; idx < highlight_ga.ga_len; ++idx) +      for (int idx = 0; idx < highlight_ga.ga_len; ++idx) {          highlight_clear(idx); +      }        init_highlight(TRUE, TRUE);        highlight_changed();        redraw_later_clear(); @@ -6677,9 +6674,7 @@ do_highlight (  #if defined(EXITFREE) || defined(PROTO)  void free_highlight(void)  { -  int i; - -  for (i = 0; i < highlight_ga.ga_len; ++i) { +  for (int i = 0; i < highlight_ga.ga_len; ++i) {      highlight_clear(i);      free(HL_TABLE()[i].sg_name);      free(HL_TABLE()[i].sg_name_u); @@ -6763,7 +6758,6 @@ static garray_T cterm_attr_table = {0, 0, 0, 0, NULL};   */  static int get_attr_entry(garray_T *table, attrentry_T *aep)  { -  int i;    attrentry_T *taep;    static int recursive = FALSE; @@ -6776,7 +6770,7 @@ static int get_attr_entry(garray_T *table, attrentry_T *aep)    /*     * Try to find an entry with the same specifications.     */ -  for (i = 0; i < table->ga_len; ++i) { +  for (int i = 0; i < table->ga_len; ++i) {      taep = &(((attrentry_T *)table->ga_data)[i]);      if (       aep->ae_attr == taep->ae_attr                 && ( @@ -6817,8 +6811,9 @@ static int get_attr_entry(garray_T *table, attrentry_T *aep)      must_redraw = CLEAR; -    for (i = 0; i < highlight_ga.ga_len; ++i) +    for (int i = 0; i < highlight_ga.ga_len; ++i) {        set_hl_attr(i); +    }      recursive = FALSE;    } @@ -6853,10 +6848,9 @@ static int get_attr_entry(garray_T *table, attrentry_T *aep)   */  void clear_hl_tables(void)  { -  int i;    attrentry_T *taep; -  for (i = 0; i < term_attr_table.ga_len; ++i) { +  for (int i = 0; i < term_attr_table.ga_len; ++i) {      taep = &(((attrentry_T *)term_attr_table.ga_data)[i]);      free(taep->ae_u.term.start);      free(taep->ae_u.term.stop); @@ -7526,7 +7520,7 @@ int highlight_changed(void)      HL_TABLE()[hlcnt + 9].sg_term = highlight_attr[HLF_S];      id_S = hlcnt + 10;    } -  for (i = 0; i < 9; i++) { +  for (int i = 0; i < 9; i++) {      sprintf((char *)userhl, "User%d", i + 1);      id = syn_name2id(userhl);      if (id == 0) { diff --git a/src/nvim/tag.c b/src/nvim/tag.c index dad4dd51ce..3202fff79f 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -1964,7 +1964,7 @@ findtag_end:      matches = NULL;    match_count = 0;    for (mtt = 0; mtt < MT_COUNT; ++mtt) { -    for (i = 0; i < ga_match[mtt].ga_len; ++i) { +    for (int i = 0; i < ga_match[mtt].ga_len; ++i) {        mfp = ((struct match_found **)(ga_match[mtt].ga_data))[i];        if (matches == NULL)          free(mfp); diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 5bc99f4e3e..b7a3601d0f 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -2235,7 +2235,6 @@ void ex_undolist(exarg_T *eap)    int mark;    int nomark;    int changes = 1; -  int i;    /*     * 1: walk the tree to find all leafs, put the info in "ga". @@ -2305,7 +2304,7 @@ void ex_undolist(exarg_T *eap)      msg_start();      msg_puts_attr((char_u *)_("number changes  when               saved"),          hl_attr(HLF_T)); -    for (i = 0; i < ga.ga_len && !got_int; ++i) { +    for (int i = 0; i < ga.ga_len && !got_int; ++i) {        msg_putchar('\n');        if (got_int)          break; diff --git a/src/nvim/window.c b/src/nvim/window.c index e0af0abc51..7134c5f6f3 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -3796,10 +3796,9 @@ void win_size_save(garray_T *gap)  void win_size_restore(garray_T *gap)  {    win_T       *wp; -  int i;    if (win_count() * 2 == gap->ga_len) { -    i = 0; +    int i = 0;      for (wp = firstwin; wp != NULL; wp = wp->w_next) {        frame_setwidth(wp->w_frame, ((int *)gap->ga_data)[i++]);        win_setheight_win(((int *)gap->ga_data)[i++], wp); | 
