From 4cc0d6b854b44c0b8466e0a84bbc9e350cda8c4f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 1 Feb 2023 21:53:32 +0800 Subject: vim-patch:9.0.1271: using sizeof() and subtract array size is tricky (#22087) Problem: Using sizeof() and subtract array size is tricky. Solution: Use offsetof() instead. (closes vim/vim#11926) https://github.com/vim/vim/commit/1b438a8228a415720efb5ca1c0503f5467292e8e --- src/nvim/spellsuggest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 22add418a0..54b6f552b5 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -2828,7 +2828,7 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T hi = hash_lookup(&slang->sl_sounddone, (const char *)goodword, goodword_len, hash); if (HASHITEM_EMPTY(hi)) { - sft = xmalloc(sizeof(sftword_T) + goodword_len); + sft = xmalloc(offsetof(sftword_T, sft_word) + goodword_len + 1); sft->sft_score = (int16_t)score; memcpy(sft->sft_word, goodword, goodword_len + 1); hash_add_item(&slang->sl_sounddone, hi, (char *)sft->sft_word, hash); -- cgit From ebd2372f928c6f1cfe823d36aabf479f6930232f Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Thu, 2 Feb 2023 23:56:25 +0100 Subject: refactor: use flexible arrays instead of the length-of-one trick (#22072) The "length-of-one" trick, where the last element of a struct is an array of size 1, but extra size is allocated when calling malloc where it uses more than 1 element in the array, cause problems with some compilers. Some compilers set _FORTIFY_SOURCE=2 by default which incorrectly considers it as an overflow. More information: https://github.com/neovim/neovim/issues/223#issuecomment-1413828554 Using flexible array members allows us to to properly convey to the compiler that its size may be larger than 1. This also enables us to remove lengthy workarounds that are unreliable, as they depend on CMAKE_BUILD_TYPE which isn't defined for multi-config generators. Closes: https://github.com/neovim/neovim/issues/223 --- src/nvim/spellsuggest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 54b6f552b5..0ddf07e3a6 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -2708,7 +2708,7 @@ static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u * /// handled already. typedef struct { int16_t sft_score; ///< lowest score used - char_u sft_word[1]; ///< soundfolded word, actually longer + char_u sft_word[]; ///< soundfolded word } sftword_T; static sftword_T dumsft; -- cgit From 4be6c6cf0ddf5e31d4103cb5df06651ba6f4897b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:05:57 +0100 Subject: refactor: replace char_u with char (#21901) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/spellsuggest.c | 273 ++++++++++++++++++++++++------------------------ 1 file changed, 136 insertions(+), 137 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 0ddf07e3a6..c5efe6e94b 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -74,9 +74,9 @@ typedef struct suginfo_S { char *su_badptr; ///< start of bad word in line int su_badlen; ///< length of detected bad word in line int su_badflags; ///< caps flags for bad word - char_u su_badword[MAXWLEN]; ///< bad word truncated at su_badlen + char su_badword[MAXWLEN]; ///< bad word truncated at su_badlen char su_fbadword[MAXWLEN]; ///< su_badword case-folded - char_u su_sal_badword[MAXWLEN]; ///< su_badword soundfolded + char su_sal_badword[MAXWLEN]; ///< su_badword soundfolded hashtab_T su_banned; ///< table with banned words slang_T *su_sallang; ///< default language for sound folding } suginfo_T; @@ -269,13 +269,13 @@ static bool can_be_compound(trystate_T *sp, slang_T *slang, char_u *compflags, i /// Adjust the score of common words. /// /// @param split word was split, less bonus -static int score_wordcount_adj(slang_T *slang, int score, char_u *word, bool split) +static int score_wordcount_adj(slang_T *slang, int score, char *word, bool split) { wordcount_T *wc; int bonus; int newscore; - hashitem_T *hi = hash_find(&slang->sl_wordcount, (char *)word); + hashitem_T *hi = hash_find(&slang->sl_wordcount, word); if (HASHITEM_EMPTY(hi)) { return score; } @@ -302,14 +302,14 @@ static int score_wordcount_adj(slang_T *slang, int score, char_u *word, bool spl /// Like captype() but for a KEEPCAP word add ONECAP if the word starts with a /// capital. So that make_case_word() can turn WOrd into Word. /// Add ALLCAP for "WOrD". -static int badword_captype(char_u *word, char_u *end) +static int badword_captype(char *word, char *end) FUNC_ATTR_NONNULL_ALL { - int flags = captype((char *)word, (char *)end); + int flags = captype(word, end); int c; int l, u; bool first; - char_u *p; + char *p; if (!(flags & WF_KEEPCAP)) { return flags; @@ -319,7 +319,7 @@ static int badword_captype(char_u *word, char_u *end) l = u = 0; first = false; for (p = word; p < end; MB_PTR_ADV(p)) { - c = utf_ptr2char((char *)p); + c = utf_ptr2char(p); if (SPELL_ISUPPER(c)) { u++; if (p == word) { @@ -351,9 +351,9 @@ static int badword_captype(char_u *word, char_u *end) /// "pp" points to the bytes and is advanced over it. /// /// @return the offset. -static int bytes2offset(char_u **pp) +static int bytes2offset(char **pp) { - char_u *p = *pp; + char_u *p = (char_u *)(*pp); int nr; int c; @@ -374,7 +374,7 @@ static int bytes2offset(char_u **pp) nr = nr * 255 + (*p++ - 1); } - *pp = p; + *pp = (char *)p; return nr; } @@ -401,11 +401,11 @@ int spell_check_sps(void) sps_limit = 9999; for (p = p_sps; *p != NUL;) { - copy_option_part(&p, (char *)buf, MAXPATHL, ","); + copy_option_part(&p, buf, MAXPATHL, ","); f = 0; if (ascii_isdigit(*buf)) { - s = (char *)buf; + s = buf; sps_limit = getdigits_int(&s, true, 0); if (*s != NUL && !ascii_isdigit(*s)) { f = -1; @@ -450,7 +450,7 @@ void spell_suggest(int count) char *line; pos_T prev_cursor = curwin->w_cursor; char wcopy[MAXWLEN + 2]; - char_u *p; + char *p; int c; suginfo_T sug; suggest_T *stp; @@ -499,21 +499,21 @@ void spell_suggest(int count) // cursor. curwin->w_cursor = prev_cursor; line = get_cursor_line_ptr(); - p = (char_u *)line + curwin->w_cursor.col; + p = line + curwin->w_cursor.col; // Backup to before start of word. - while (p > (char_u *)line && spell_iswordp_nmw((char *)p, curwin)) { + while (p > line && spell_iswordp_nmw(p, curwin)) { MB_PTR_BACK(line, p); } // Forward to start of word. - while (*p != NUL && !spell_iswordp_nmw((char *)p, curwin)) { + while (*p != NUL && !spell_iswordp_nmw(p, curwin)) { MB_PTR_ADV(p); } - if (!spell_iswordp_nmw((char *)p, curwin)) { // No word found. + if (!spell_iswordp_nmw(p, curwin)) { // No word found. beep_flush(); return; } - curwin->w_cursor.col = (colnr_T)(p - (char_u *)line); + curwin->w_cursor.col = (colnr_T)(p - line); } // Get the word and its length. @@ -532,7 +532,7 @@ void spell_suggest(int count) } else { limit = sps_limit; } - spell_find_suggest((char_u *)line + curwin->w_cursor.col, badlen, &sug, limit, + spell_find_suggest(line + curwin->w_cursor.col, badlen, &sug, limit, true, need_cap, true); if (GA_EMPTY(&sug.su_ga)) { @@ -659,12 +659,12 @@ void spell_suggest(int count) // For redo we use a change-word command. ResetRedobuff(); AppendToRedobuff("ciw"); - AppendToRedobuffLit((char *)p + c, + AppendToRedobuffLit(p + c, stp->st_wordlen + sug.su_badlen - stp->st_orglen); AppendCharToRedobuff(ESC); // "p" may be freed here - ml_replace(curwin->w_cursor.lnum, (char *)p, false); + ml_replace(curwin->w_cursor.lnum, p, false); curwin->w_cursor.col = c; inserted_bytes(curwin->w_cursor.lnum, c, stp->st_orglen, stp->st_wordlen); @@ -686,12 +686,12 @@ void spell_suggest_list(garray_T *gap, char *word, int maxcount, bool need_cap, { suginfo_T sug; suggest_T *stp; - char_u *wcopy; + char *wcopy; - spell_find_suggest((char_u *)word, 0, &sug, maxcount, false, need_cap, interactive); + spell_find_suggest(word, 0, &sug, maxcount, false, need_cap, interactive); // Make room in "gap". - ga_init(gap, sizeof(char_u *), sug.su_ga.ga_len + 1); + ga_init(gap, sizeof(char *), sug.su_ga.ga_len + 1); ga_grow(gap, sug.su_ga.ga_len); for (int i = 0; i < sug.su_ga.ga_len; i++) { stp = &SUG(sug.su_ga, i); @@ -701,7 +701,7 @@ void spell_suggest_list(garray_T *gap, char *word, int maxcount, bool need_cap, wcopy = xmalloc((size_t)stp->st_wordlen + strlen(sug.su_badptr + stp->st_orglen) + 1); STRCPY(wcopy, stp->st_word); STRCPY(wcopy + stp->st_wordlen, sug.su_badptr + stp->st_orglen); - ((char_u **)gap->ga_data)[gap->ga_len++] = wcopy; + ((char **)gap->ga_data)[gap->ga_len++] = wcopy; } spell_find_cleanup(&sug); @@ -716,7 +716,7 @@ void spell_suggest_list(garray_T *gap, char *word, int maxcount, bool need_cap, /// @param badlen length of bad word or 0 if unknown /// @param banbadword don't include badword in suggestions /// @param need_cap word should start with capital -static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int maxcount, +static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxcount, bool banbadword, bool need_cap, bool interactive) { hlf_T attr = HLF_COUNT; @@ -738,7 +738,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma } hash_init(&su->su_banned); - su->su_badptr = (char *)badptr; + su->su_badptr = badptr; if (badlen != 0) { su->su_badlen = badlen; } else { @@ -752,7 +752,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma if (su->su_badlen >= MAXWLEN) { su->su_badlen = MAXWLEN - 1; // just in case } - xstrlcpy((char *)su->su_badword, su->su_badptr, (size_t)su->su_badlen + 1); + xstrlcpy(su->su_badword, su->su_badptr, (size_t)su->su_badlen + 1); (void)spell_casefold(curwin, su->su_badptr, su->su_badlen, su->su_fbadword, MAXWLEN); @@ -762,8 +762,8 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma su->su_fbadword[su->su_badlen] = NUL; // get caps flags for bad word - su->su_badflags = badword_captype((char_u *)su->su_badptr, - (char_u *)su->su_badptr + su->su_badlen); + su->su_badflags = badword_captype(su->su_badptr, + su->su_badptr + su->su_badlen); if (need_cap) { su->su_badflags |= WF_ONECAP; } @@ -783,8 +783,8 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma // Soundfold the bad word with the default sound folding, so that we don't // have to do this many times. if (su->su_sallang != NULL) { - spell_soundfold(su->su_sallang, (char *)su->su_fbadword, true, - (char *)su->su_sal_badword); + spell_soundfold(su->su_sallang, su->su_fbadword, true, + su->su_sal_badword); } // If the word is not capitalised and spell_check() doesn't consider the @@ -792,14 +792,14 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma // for that. c = utf_ptr2char(su->su_badptr); if (!SPELL_ISUPPER(c) && attr == HLF_COUNT) { - make_case_word((char *)su->su_badword, buf, WF_ONECAP); - add_suggestion(su, &su->su_ga, (char *)buf, su->su_badlen, SCORE_ICASE, + make_case_word(su->su_badword, buf, WF_ONECAP); + add_suggestion(su, &su->su_ga, buf, su->su_badlen, SCORE_ICASE, 0, true, su->su_sallang, false); } // Ban the bad word itself. It may appear in another region. if (banbadword) { - add_banned(su, (char *)su->su_badword); + add_banned(su, su->su_badword); } // Make a copy of 'spellsuggest', because the expression may change it. @@ -807,22 +807,22 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma // Loop over the items in 'spellsuggest'. for (p = sps_copy; *p != NUL;) { - copy_option_part(&p, (char *)buf, MAXPATHL, ","); + copy_option_part(&p, buf, MAXPATHL, ","); if (strncmp(buf, "expr:", 5) == 0) { // Evaluate an expression. Skip this when called recursively, // when using spellsuggest() in the expression. if (!expr_busy) { expr_busy = true; - spell_suggest_expr(su, (char_u *)buf + 5); + spell_suggest_expr(su, buf + 5); expr_busy = false; } } else if (strncmp(buf, "file:", 5) == 0) { // Use list of suggestions in a file. - spell_suggest_file(su, (char_u *)buf + 5); + spell_suggest_file(su, buf + 5); } else if (strncmp(buf, "timeout:", 8) == 0) { // Limit the time searching for suggestions. - spell_suggest_timeout = atol((char *)buf + 8); + spell_suggest_timeout = atol(buf + 8); } else if (!did_intern) { // Use internal method once. spell_suggest_intern(su, interactive); @@ -843,7 +843,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma } /// Find suggestions by evaluating expression "expr". -static void spell_suggest_expr(suginfo_T *su, char_u *expr) +static void spell_suggest_expr(suginfo_T *su, char *expr) { int score; const char *p; @@ -851,7 +851,7 @@ static void spell_suggest_expr(suginfo_T *su, char_u *expr) // The work is split up in a few parts to avoid having to export // suginfo_T. // First evaluate the expression and get the resulting list. - list_T *const list = eval_spell_expr((char *)su->su_badword, (char *)expr); + list_T *const list = eval_spell_expr(su->su_badword, expr); if (list != NULL) { // Loop over the items in the list. TV_LIST_ITER(list, li, { @@ -873,43 +873,43 @@ static void spell_suggest_expr(suginfo_T *su, char_u *expr) } /// Find suggestions in file "fname". Used for "file:" in 'spellsuggest'. -static void spell_suggest_file(suginfo_T *su, char_u *fname) +static void spell_suggest_file(suginfo_T *su, char *fname) { FILE *fd; - char_u line[MAXWLEN * 2]; - char_u *p; + char line[MAXWLEN * 2]; + char *p; int len; - char_u cword[MAXWLEN]; + char cword[MAXWLEN]; // Open the file. - fd = os_fopen((char *)fname, "r"); + fd = os_fopen(fname, "r"); if (fd == NULL) { semsg(_(e_notopen), fname); return; } // Read it line by line. - while (!vim_fgets((char *)line, MAXWLEN * 2, fd) && !got_int) { + while (!vim_fgets(line, MAXWLEN * 2, fd) && !got_int) { line_breakcheck(); - p = (char_u *)vim_strchr((char *)line, '/'); + p = vim_strchr(line, '/'); if (p == NULL) { continue; // No Tab found, just skip the line. } *p++ = NUL; if (STRICMP(su->su_badword, line) == 0) { // Match! Isolate the good word, until CR or NL. - for (len = 0; p[len] >= ' '; len++) {} + for (len = 0; (uint8_t)p[len] >= ' '; len++) {} p[len] = NUL; // If the suggestion doesn't have specific case duplicate the case // of the bad word. - if (captype((char *)p, NULL) == 0) { - make_case_word((char *)p, (char *)cword, su->su_badflags); + if (captype(p, NULL) == 0) { + make_case_word(p, cword, su->su_badflags); p = cword; } - add_suggestion(su, &su->su_ga, (char *)p, su->su_badlen, + add_suggestion(su, &su->su_ga, p, su->su_badlen, SCORE_FILE, 0, true, su->su_sallang, false); } } @@ -1014,23 +1014,23 @@ static void spell_find_cleanup(suginfo_T *su) static void suggest_try_special(suginfo_T *su) { char c; - char_u word[MAXWLEN]; + char word[MAXWLEN]; // Recognize a word that is repeated: "the the". - char *p = skiptowhite((char *)su->su_fbadword); - size_t len = (size_t)(p - (char *)su->su_fbadword); + char *p = skiptowhite(su->su_fbadword); + size_t len = (size_t)(p - su->su_fbadword); p = skipwhite(p); if (strlen(p) == len && strncmp(su->su_fbadword, p, len) == 0) { // Include badflags: if the badword is onecap or allcap // use that for the goodword too: "The the" -> "The". c = su->su_fbadword[len]; su->su_fbadword[len] = NUL; - make_case_word(su->su_fbadword, (char *)word, su->su_badflags); + make_case_word(su->su_fbadword, word, su->su_badflags); su->su_fbadword[len] = c; // Give a soundalike score of 0, compute the score as if deleting one // character. - add_suggestion(su, &su->su_ga, (char *)word, su->su_badlen, + add_suggestion(su, &su->su_ga, word, su->su_badlen, RESCORE(SCORE_REP, 0), 0, true, su->su_sallang, false); } } @@ -1268,9 +1268,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // Set su->su_badflags to the caps type at this position. // Use the caps type until here for the prefix itself. n = nofold_len(fword, sp->ts_fidx, su->su_badptr); - flags = badword_captype((char_u *)su->su_badptr, (char_u *)su->su_badptr + n); - su->su_badflags = badword_captype((char_u *)su->su_badptr + n, - (char_u *)su->su_badptr + su->su_badlen); + flags = badword_captype(su->su_badptr, su->su_badptr + n); + su->su_badflags = badword_captype(su->su_badptr + n, + su->su_badptr + su->su_badlen); #ifdef DEBUG_TRIEWALK sprintf(changename[depth], "prefix"); // NOLINT(runtime/printf) #endif @@ -1371,11 +1371,11 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun (size_t)(sp->ts_fidx - sp->ts_splitfidx)) == 0) { preword[sp->ts_prewordlen] = NUL; newscore = score_wordcount_adj(slang, sp->ts_score, - (char_u *)preword + sp->ts_prewordlen, + preword + sp->ts_prewordlen, sp->ts_prewordlen > 0); // Add the suggestion if the score isn't too bad. if (newscore <= su->su_maxscore) { - add_suggestion(su, &su->su_ga, (char *)preword, + add_suggestion(su, &su->su_ga, preword, sp->ts_splitfidx - repextra, newscore, 0, false, lp->lp_sallang, false); @@ -1437,7 +1437,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun STRCPY(preword + sp->ts_prewordlen, tword + sp->ts_splitoff); } else if (flags & WF_KEEPCAP) { // Must find the word in the keep-case tree. - find_keepcap_word(slang, (char *)tword + sp->ts_splitoff, preword + sp->ts_prewordlen); + find_keepcap_word(slang, tword + sp->ts_splitoff, preword + sp->ts_prewordlen); } else { // Include badflags: If the badword is onecap or allcap // use that for the goodword too. But if the badword is @@ -1465,8 +1465,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun break; } if ((sp->ts_complen == sp->ts_compsplit - && WAS_BANNED(su, (char *)preword + sp->ts_prewordlen)) - || WAS_BANNED(su, (char *)preword)) { + && WAS_BANNED(su, preword + sp->ts_prewordlen)) + || WAS_BANNED(su, preword)) { if (slang->sl_compprog == NULL) { break; } @@ -1528,12 +1528,12 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // Give a bonus to words seen before. score = score_wordcount_adj(slang, sp->ts_score + newscore, - (char_u *)preword + sp->ts_prewordlen, + preword + sp->ts_prewordlen, sp->ts_prewordlen > 0); // Add the suggestion if the score isn't too bad. if (score <= su->su_maxscore) { - add_suggestion(su, &su->su_ga, (char *)preword, + add_suggestion(su, &su->su_ga, preword, sp->ts_fidx - repextra, score, 0, false, lp->lp_sallang, false); @@ -1546,7 +1546,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun preword + sp->ts_prewordlen, c == 0 ? WF_ALLCAP : 0); - add_suggestion(su, &su->su_ga, (char *)preword, + add_suggestion(su, &su->su_ga, preword, sp->ts_fidx - repextra, score + SCORE_ICASE, 0, false, lp->lp_sallang, false); @@ -1647,7 +1647,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // Give a bonus to words seen before. newscore = score_wordcount_adj(slang, newscore, - (char_u *)preword + sp->ts_prewordlen, true); + preword + sp->ts_prewordlen, true); } if (TRY_DEEPER(su, stack, depth, newscore)) { @@ -1715,8 +1715,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // set su->su_badflags to the caps type at this // position n = nofold_len(fword, sp->ts_fidx, su->su_badptr); - su->su_badflags = badword_captype((char_u *)su->su_badptr + n, - (char_u *)su->su_badptr + su->su_badlen); + su->su_badflags = badword_captype(su->su_badptr + n, + su->su_badptr + su->su_badlen); // Restart at top of the tree. sp->ts_arridx = 0; @@ -1843,7 +1843,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // For changing a composing character adjust // the score from SCORE_SUBST to // SCORE_SUBCOMP. - if (utf_iscomposing(utf_ptr2char((char *)tword + sp->ts_twordlen + if (utf_iscomposing(utf_ptr2char(tword + sp->ts_twordlen - sp->ts_tcharlen)) && utf_iscomposing(utf_ptr2char(fword + sp->ts_fcharstart))) { @@ -1851,7 +1851,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun } else if (!soundfold && slang->sl_has_map && similar_chars(slang, - utf_ptr2char((char *)tword + sp->ts_twordlen - + utf_ptr2char(tword + sp->ts_twordlen - sp->ts_tcharlen), utf_ptr2char(fword + sp->ts_fcharstart))) { // For a similar character adjust score from @@ -1860,7 +1860,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun } } else if (sp->ts_isdiff == DIFF_INSERT && sp->ts_twordlen > sp->ts_tcharlen) { - p = (char *)tword + sp->ts_twordlen - sp->ts_tcharlen; + p = tword + sp->ts_twordlen - sp->ts_tcharlen; c = utf_ptr2char(p); if (utf_iscomposing(c)) { // Inserting a composing char doesn't @@ -2310,7 +2310,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun fl = (int)strlen(ftp->ft_from); tl = (int)strlen(ftp->ft_to); if (fl != tl) { - STRMOVE(p + tl, (char *)p + fl); + STRMOVE(p + tl, p + fl); repextra += tl - fl; } memmove(p, ftp->ft_to, (size_t)tl); @@ -2340,7 +2340,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun tl = (int)strlen(ftp->ft_to); p = fword + sp->ts_fidx; if (fl != tl) { - STRMOVE(p + fl, (char *)p + tl); + STRMOVE(p + fl, p + tl); repextra -= tl - fl; } memmove(p, ftp->ft_from, (size_t)fl); @@ -2402,7 +2402,7 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword) int len; int c; idx_T lo, hi, m; - char_u *p; + char *p; char_u *byts = (char_u *)slang->sl_kbyts; // array with bytes of the words idx_T *idxs = slang->sl_kidxs; // array with indexes @@ -2443,19 +2443,19 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword) // round[depth] == 1: Try using the folded-case character. // round[depth] == 2: Try using the upper-case character. flen = utf_ptr2len(fword + fwordidx[depth]); - ulen = utf_ptr2len((char *)uword + uwordidx[depth]); + ulen = utf_ptr2len(uword + uwordidx[depth]); if (round[depth] == 1) { - p = (char_u *)fword + fwordidx[depth]; + p = fword + fwordidx[depth]; l = flen; } else { - p = (char_u *)uword + uwordidx[depth]; + p = uword + uwordidx[depth]; l = ulen; } for (tryidx = arridx[depth]; l > 0; l--) { // Perform a binary search in the list of accepted bytes. len = byts[tryidx++]; - c = *p++; + c = (uint8_t)(*p++); lo = tryidx; hi = tryidx + len - 1; while (lo < hi) { @@ -2512,7 +2512,7 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword) static void score_comp_sal(suginfo_T *su) { langp_T *lp; - char_u badsound[MAXWLEN]; + char badsound[MAXWLEN]; int i; suggest_T *stp; suggest_T *sstp; @@ -2525,7 +2525,7 @@ static void score_comp_sal(suginfo_T *su) lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); if (!GA_EMPTY(&lp->lp_slang->sl_sal)) { // soundfold the bad word - spell_soundfold(lp->lp_slang, (char *)su->su_fbadword, true, (char *)badsound); + spell_soundfold(lp->lp_slang, su->su_fbadword, true, badsound); for (i = 0; i < su->su_ga.ga_len; i++) { stp = &SUG(su->su_ga, i); @@ -2568,11 +2568,11 @@ static void score_combine(suginfo_T *su) if (!GA_EMPTY(&lp->lp_slang->sl_sal)) { // soundfold the bad word slang = lp->lp_slang; - spell_soundfold(slang, (char *)su->su_fbadword, true, badsound); + spell_soundfold(slang, su->su_fbadword, true, badsound); 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, (char_u *)badsound); + stp->st_altscore = stp_sal_score(stp, su, slang, badsound); if (stp->st_altscore == SCORE_MAXMAX) { stp->st_score = (stp->st_score * 3 + SCORE_BIG) / 4; } else { @@ -2593,7 +2593,7 @@ static void score_combine(suginfo_T *su) // Add the alternate score to su_sga. for (int i = 0; i < su->su_sga.ga_len; i++) { stp = &SUG(su->su_sga, i); - stp->st_altscore = spell_edit_score(slang, (char_u *)su->su_badword, (char_u *)stp->st_word); + stp->st_altscore = spell_edit_score(slang, su->su_badword, stp->st_word); if (stp->st_score == SCORE_MAXMAX) { stp->st_score = (SCORE_BIG * 7 + stp->st_altscore) / 8; } else { @@ -2654,14 +2654,14 @@ static void score_combine(suginfo_T *su) /// badword. /// /// @param badsound sound-folded badword -static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u *badsound) +static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char *badsound) { - char_u *p; - char_u *pbad; - char_u *pgood; - char_u badsound2[MAXWLEN]; - char_u fword[MAXWLEN]; - char_u goodsound[MAXWLEN]; + char *p; + char *pbad; + char *pgood; + char badsound2[MAXWLEN]; + char fword[MAXWLEN]; + char goodsound[MAXWLEN]; char goodword[MAXWLEN]; int lendiff; @@ -2670,7 +2670,7 @@ static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u * pbad = badsound; } else { // soundfold the bad word with more characters following - (void)spell_casefold(curwin, su->su_badptr, stp->st_orglen, (char *)fword, MAXWLEN); + (void)spell_casefold(curwin, su->su_badptr, stp->st_orglen, fword, MAXWLEN); // When joining two words the sound often changes a lot. E.g., "t he" // sounds like "t h" while "the" sounds like "@". Avoid that by @@ -2678,12 +2678,12 @@ static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u * // space. if (ascii_iswhite(su->su_badptr[su->su_badlen]) && *skiptowhite(stp->st_word) == NUL) { - for (p = fword; *(p = (char_u *)skiptowhite((char *)p)) != NUL;) { - STRMOVE(p, (char *)p + 1); + for (p = fword; *(p = skiptowhite(p)) != NUL;) { + STRMOVE(p, p + 1); } } - spell_soundfold(slang, (char *)fword, true, (char *)badsound2); + spell_soundfold(slang, fword, true, badsound2); pbad = badsound2; } @@ -2693,15 +2693,15 @@ static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u * STRCPY(goodword, stp->st_word); xstrlcpy(goodword + stp->st_wordlen, su->su_badptr + su->su_badlen - lendiff, (size_t)lendiff + 1); - pgood = (char_u *)goodword; + pgood = goodword; } else { - pgood = (char_u *)stp->st_word; + pgood = stp->st_word; } // Sound-fold the word and compute the score for the difference. - spell_soundfold(slang, (char *)pgood, false, (char *)goodsound); + spell_soundfold(slang, pgood, false, goodsound); - return soundalike_score((char *)goodsound, (char *)pbad); + return soundalike_score(goodsound, pbad); } /// structure used to store soundfolded words that add_sound_suggest() has @@ -2737,7 +2737,7 @@ static void suggest_try_soundalike_prep(void) /// Note: This doesn't support postponed prefixes. static void suggest_try_soundalike(suginfo_T *su) { - char_u salword[MAXWLEN]; + char salword[MAXWLEN]; langp_T *lp; slang_T *slang; @@ -2748,7 +2748,7 @@ static void suggest_try_soundalike(suginfo_T *su) slang = lp->lp_slang; if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) { // soundfold the bad word - spell_soundfold(slang, (char *)su->su_fbadword, true, (char *)salword); + spell_soundfold(slang, su->su_fbadword, true, salword); // try all kinds of inserts/deletes/swaps/etc. // TODO(vim): also soundfold the next words, so that we can try joining @@ -2756,7 +2756,7 @@ static void suggest_try_soundalike(suginfo_T *su) #ifdef SUGGEST_PROFILE prof_init(); #endif - suggest_trie_walk(su, lp, (char *)salword, true); + suggest_trie_walk(su, lp, salword, true); #ifdef SUGGEST_PROFILE prof_report("soundalike"); #endif @@ -2802,9 +2802,9 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T { slang_T *slang = lp->lp_slang; // language for sound folding int sfwordnr; - char_u *nrline; + char *nrline; int orgnr; - char_u theword[MAXWLEN]; + char theword[MAXWLEN]; int i; int wlen; char_u *byts; @@ -2841,14 +2841,14 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T } // Find the word nr in the soundfold tree. - sfwordnr = soundfold_find(slang, (char_u *)goodword); + sfwordnr = soundfold_find(slang, goodword); if (sfwordnr < 0) { internal_error("add_sound_suggest()"); return; } // Go over the list of good words that produce this soundfold word - nrline = (char_u *)ml_get_buf(slang->sl_sugbuf, (linenr_T)sfwordnr + 1, false); + nrline = ml_get_buf(slang->sl_sugbuf, (linenr_T)sfwordnr + 1, false); orgnr = 0; while (*nrline != NUL) { // The wordnr was stored in a minimal nr of bytes as an offset to the @@ -2888,7 +2888,7 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T wordcount += wc; } - theword[wlen] = byts[n + i]; + theword[wlen] = (char)byts[n + i]; n = idxs[n + i]; } badword: @@ -2896,8 +2896,8 @@ badword: // Go over the possible flags and regions. for (; i <= byts[n] && byts[n + i] == NUL; i++) { - char_u cword[MAXWLEN]; - char_u *p; + char cword[MAXWLEN]; + char *p; int flags = (int)idxs[n + i]; // Skip words with the NOSUGGEST flag @@ -2907,13 +2907,13 @@ badword: if (flags & WF_KEEPCAP) { // Must find the word in the keep-case tree. - find_keepcap_word(slang, (char *)theword, (char *)cword); + find_keepcap_word(slang, theword, cword); p = cword; } else { flags |= su->su_badflags; if ((flags & WF_CAPMASK) != 0) { // Need to fix case according to "flags". - make_case_word((char *)theword, (char *)cword, flags); + make_case_word(theword, cword, flags); p = cword; } else { p = theword; @@ -2924,7 +2924,7 @@ badword: if (sps_flags & SPS_DOUBLE) { // Add the suggestion if the score isn't too bad. if (score <= su->su_maxscore) { - add_suggestion(su, &su->su_sga, (char *)p, su->su_badlen, + add_suggestion(su, &su->su_sga, p, su->su_badlen, score, 0, false, slang, false); } } else { @@ -2940,9 +2940,9 @@ badword: // lower to upper case. Helps for "tath" -> "Kath", which is // less common than "tath" -> "path". Don't do it when the // letter is the same, that has already been counted. - gc = utf_ptr2char((char *)p); + gc = utf_ptr2char(p); if (SPELL_ISUPPER(gc)) { - bc = utf_ptr2char((char *)su->su_badword); + bc = utf_ptr2char(su->su_badword); if (!SPELL_ISUPPER(bc) && SPELL_TOFOLD(bc) != SPELL_TOFOLD(gc)) { goodscore += SCORE_ICASE / 2; @@ -2958,10 +2958,9 @@ badword: // inefficient, using an array is quicker. limit = MAXSCORE(su->su_sfmaxscore - goodscore, score); if (limit > SCORE_LIMITMAX) { - goodscore += spell_edit_score(slang, (char_u *)su->su_badword, p); + goodscore += spell_edit_score(slang, su->su_badword, p); } else { - goodscore += spell_edit_score_limit(slang, (char_u *)su->su_badword, - p, limit); + goodscore += spell_edit_score_limit(slang, su->su_badword, p, limit); } // When going over the limit don't bother to do the rest. @@ -2972,7 +2971,7 @@ badword: // Add the suggestion if the score isn't too bad. goodscore = RESCORE(goodscore, score); if (goodscore <= su->su_sfmaxscore) { - add_suggestion(su, &su->su_ga, (char *)p, su->su_badlen, + add_suggestion(su, &su->su_ga, p, su->su_badlen, goodscore, score, true, slang, true); } } @@ -2982,13 +2981,13 @@ badword: } /// Find word "word" in fold-case tree for "slang" and return the word number. -static int soundfold_find(slang_T *slang, char_u *word) +static int soundfold_find(slang_T *slang, char *word) { idx_T arridx = 0; int len; int wlen = 0; int c; - char_u *ptr = word; + char_u *ptr = (char_u *)word; char_u *byts; idx_T *idxs; int wordnr = 0; @@ -3065,7 +3064,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2) hashitem_T *hi; if (c1 >= 256) { - buf[utf_char2bytes(c1, (char *)buf)] = 0; + buf[utf_char2bytes(c1, buf)] = 0; hi = hash_find(&slang->sl_map_hash, buf); if (HASHITEM_EMPTY(hi)) { m1 = 0; @@ -3080,7 +3079,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2) } if (c2 >= 256) { - buf[utf_char2bytes(c2, (char *)buf)] = 0; + buf[utf_char2bytes(c2, buf)] = 0; hi = hash_find(&slang->sl_map_hash, buf); if (HASHITEM_EMPTY(hi)) { m2 = 0; @@ -3244,7 +3243,7 @@ static void check_suggestions(suginfo_T *su, garray_T *gap) /// Add a word to be banned. static void add_banned(suginfo_T *su, char *word) { - char_u *s; + char *s; hash_T hash; hashitem_T *hi; @@ -3255,7 +3254,7 @@ static void add_banned(suginfo_T *su, char *word) return; } s = xmemdupz(word, word_len); - hash_add_item(&su->su_banned, hi, (char *)s, hash); + hash_add_item(&su->su_banned, hi, s, hash); } /// Recompute the score for all suggestions if sound-folding is possible. This @@ -3273,8 +3272,8 @@ static void rescore_suggestions(suginfo_T *su) static void rescore_one(suginfo_T *su, suggest_T *stp) { slang_T *slang = stp->st_slang; - char_u sal_badword[MAXWLEN]; - char_u *p; + char sal_badword[MAXWLEN]; + char *p; // Only rescore suggestions that have no sal score yet and do have a // language. @@ -3282,7 +3281,7 @@ static void rescore_one(suginfo_T *su, suggest_T *stp) if (slang == su->su_sallang) { p = su->su_sal_badword; } else { - spell_soundfold(slang, (char *)su->su_fbadword, true, (char *)sal_badword); + spell_soundfold(slang, su->su_fbadword, true, sal_badword); p = sal_badword; } @@ -3575,7 +3574,7 @@ static int soundalike_score(char *goodstart, char *badstart) /// The implementation of the algorithm comes from Aspell editdist.cpp, /// edit_distance(). It has been converted from C++ to C and modified to /// support multi-byte characters. -static int spell_edit_score(slang_T *slang, const char_u *badword, const char_u *goodword) +static int spell_edit_score(slang_T *slang, const char *badword, const char *goodword) { int *cnt; int j, i; @@ -3592,12 +3591,12 @@ static int spell_edit_score(slang_T *slang, const char_u *badword, const char_u // Get the characters from the multi-byte strings and put them in an // int array for easy access. badlen = 0; - for (const char *p = (char *)badword; *p != NUL;) { + for (const char *p = badword; *p != NUL;) { wbadword[badlen++] = mb_cptr2char_adv(&p); } wbadword[badlen++] = 0; goodlen = 0; - for (const char *p = (char *)goodword; *p != NUL;) { + for (const char *p = goodword; *p != NUL;) { wgoodword[goodlen++] = mb_cptr2char_adv(&p); } wgoodword[goodlen++] = 0; @@ -3673,14 +3672,14 @@ typedef struct { /// This uses a stack for the edits still to be tried. /// The idea comes from Aspell leditdist.cpp. Rewritten in C and added support /// for multi-byte characters. -static int spell_edit_score_limit(slang_T *slang, char_u *badword, char_u *goodword, int limit) +static int spell_edit_score_limit(slang_T *slang, char *badword, char *goodword, int limit) { return spell_edit_score_limit_w(slang, badword, goodword, limit); } /// Multi-byte version of spell_edit_score_limit(). /// Keep it in sync with the above! -static int spell_edit_score_limit_w(slang_T *slang, const char_u *badword, const char_u *goodword, +static int spell_edit_score_limit_w(slang_T *slang, const char *badword, const char *goodword, int limit) { limitscore_T stack[10]; // allow for over 3 * 2 edits @@ -3698,12 +3697,12 @@ static int spell_edit_score_limit_w(slang_T *slang, const char_u *badword, const // Get the characters from the multi-byte strings and put them in an // int array for easy access. bi = 0; - for (const char *p = (char *)badword; *p != NUL;) { + for (const char *p = badword; *p != NUL;) { wbadword[bi++] = mb_cptr2char_adv(&p); } wbadword[bi++] = 0; gi = 0; - for (const char *p = (char *)goodword; *p != NUL;) { + for (const char *p = goodword; *p != NUL;) { wgoodword[gi++] = mb_cptr2char_adv(&p); } wgoodword[gi++] = 0; -- cgit From 27177e581902967dcf4f2f426464da1b636ca420 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 14:14:24 +0100 Subject: refactor: reduce scope of locals as per the style guide (#22211) --- src/nvim/spellsuggest.c | 151 +++++++++++++++++------------------------------- 1 file changed, 52 insertions(+), 99 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index c5efe6e94b..66829c60c9 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -271,7 +271,6 @@ static bool can_be_compound(trystate_T *sp, slang_T *slang, char_u *compflags, i /// @param split word was split, less bonus static int score_wordcount_adj(slang_T *slang, int score, char *word, bool split) { - wordcount_T *wc; int bonus; int newscore; @@ -280,7 +279,7 @@ static int score_wordcount_adj(slang_T *slang, int score, char *word, bool split return score; } - wc = HI2WC(hi); + wordcount_T *wc = HI2WC(hi); if (wc->wc_count < SCORE_THRES2) { bonus = SCORE_COMMON1; } else if (wc->wc_count < SCORE_THRES3) { @@ -306,20 +305,17 @@ static int badword_captype(char *word, char *end) FUNC_ATTR_NONNULL_ALL { int flags = captype(word, end); - int c; - int l, u; - bool first; - char *p; if (!(flags & WF_KEEPCAP)) { return flags; } // Count the number of UPPER and lower case letters. - l = u = 0; - first = false; - for (p = word; p < end; MB_PTR_ADV(p)) { - c = utf_ptr2char(p); + int l= 0; + int u= 0; + bool first = false; + for (char *p = word; p < end; MB_PTR_ADV(p)) { + int c = utf_ptr2char(p); if (SPELL_ISUPPER(c)) { u++; if (p == word) { @@ -355,9 +351,8 @@ static int bytes2offset(char **pp) { char_u *p = (char_u *)(*pp); int nr; - int c; - c = *p++; + int c = *p++; if ((c & 0x80) == 0x00) { // 1 byte nr = c - 1; } else if ((c & 0xc0) == 0x80) { // 2 bytes @@ -392,18 +387,16 @@ static int sps_limit = 9999; ///< max nr of suggestions given /// Sets "sps_flags" and "sps_limit". int spell_check_sps(void) { - char *p; char *s; char buf[MAXPATHL]; - int f; sps_flags = 0; sps_limit = 9999; - for (p = p_sps; *p != NUL;) { + for (char *p = p_sps; *p != NUL;) { copy_option_part(&p, buf, MAXPATHL, ","); - f = 0; + int f = 0; if (ascii_isdigit(*buf)) { s = buf; sps_limit = getdigits_int(&s, true, 0); @@ -451,11 +444,9 @@ void spell_suggest(int count) pos_T prev_cursor = curwin->w_cursor; char wcopy[MAXWLEN + 2]; char *p; - int c; suginfo_T sug; suggest_T *stp; int mouse_used; - int need_cap; int limit; int selected = count; int badlen = 0; @@ -519,7 +510,7 @@ void spell_suggest(int count) // Get the word and its length. // Figure out if the word should be capitalised. - need_cap = check_need_cap(curwin->w_cursor.lnum, curwin->w_cursor.col); + int need_cap = check_need_cap(curwin->w_cursor.lnum, curwin->w_cursor.col); // Make a copy of current line since autocommands may free the line. line = xstrdup(get_cursor_line_ptr()); @@ -651,7 +642,7 @@ void spell_suggest(int count) // Replace the word. p = xmalloc(strlen(line) - (size_t)stp->st_orglen + (size_t)stp->st_wordlen + 1); - c = (int)(sug.su_badptr - line); + int c = (int)(sug.su_badptr - line); memmove(p, line, (size_t)c); STRCPY(p + c, stp->st_word); STRCAT(p, sug.su_badptr + stp->st_orglen); @@ -685,7 +676,6 @@ void spell_suggest(int count) void spell_suggest_list(garray_T *gap, char *word, int maxcount, bool need_cap, bool interactive) { suginfo_T sug; - suggest_T *stp; char *wcopy; spell_find_suggest(word, 0, &sug, maxcount, false, need_cap, interactive); @@ -694,7 +684,7 @@ void spell_suggest_list(garray_T *gap, char *word, int maxcount, bool need_cap, ga_init(gap, sizeof(char *), sug.su_ga.ga_len + 1); ga_grow(gap, sug.su_ga.ga_len); for (int i = 0; i < sug.su_ga.ga_len; i++) { - stp = &SUG(sug.su_ga, i); + suggest_T *stp = &SUG(sug.su_ga, i); // The suggested word may replace only part of "word", add the not // replaced part. @@ -721,11 +711,8 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc { hlf_T attr = HLF_COUNT; char buf[MAXPATHL]; - char *p; bool do_combine = false; - char *sps_copy; static bool expr_busy = false; - int c; langp_T *lp; bool did_intern = false; @@ -790,7 +777,7 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc // If the word is not capitalised and spell_check() doesn't consider the // word to be bad then it might need to be capitalised. Add a suggestion // for that. - c = utf_ptr2char(su->su_badptr); + int c = utf_ptr2char(su->su_badptr); if (!SPELL_ISUPPER(c) && attr == HLF_COUNT) { make_case_word(su->su_badword, buf, WF_ONECAP); add_suggestion(su, &su->su_ga, buf, su->su_badlen, SCORE_ICASE, @@ -803,10 +790,10 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc } // Make a copy of 'spellsuggest', because the expression may change it. - sps_copy = xstrdup(p_sps); + char *sps_copy = xstrdup(p_sps); // Loop over the items in 'spellsuggest'. - for (p = sps_copy; *p != NUL;) { + for (char *p = sps_copy; *p != NUL;) { copy_option_part(&p, buf, MAXPATHL, ","); if (strncmp(buf, "expr:", 5) == 0) { @@ -845,7 +832,6 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc /// Find suggestions by evaluating expression "expr". static void spell_suggest_expr(suginfo_T *su, char *expr) { - int score; const char *p; // The work is split up in a few parts to avoid having to export @@ -857,7 +843,7 @@ static void spell_suggest_expr(suginfo_T *su, char *expr) TV_LIST_ITER(list, li, { if (TV_LIST_ITEM_TV(li)->v_type == VAR_LIST) { // Get the word and the score from the items. - score = get_spellword(TV_LIST_ITEM_TV(li)->vval.v_list, &p); + int score = get_spellword(TV_LIST_ITEM_TV(li)->vval.v_list, &p); if (score >= 0 && score <= su->su_maxscore) { add_suggestion(su, &su->su_ga, p, su->su_badlen, score, 0, true, su->su_sallang, false); @@ -875,14 +861,12 @@ static void spell_suggest_expr(suginfo_T *su, char *expr) /// Find suggestions in file "fname". Used for "file:" in 'spellsuggest'. static void spell_suggest_file(suginfo_T *su, char *fname) { - FILE *fd; char line[MAXWLEN * 2]; - char *p; int len; char cword[MAXWLEN]; // Open the file. - fd = os_fopen(fname, "r"); + FILE *fd = os_fopen(fname, "r"); if (fd == NULL) { semsg(_(e_notopen), fname); return; @@ -892,7 +876,7 @@ static void spell_suggest_file(suginfo_T *su, char *fname) while (!vim_fgets(line, MAXWLEN * 2, fd) && !got_int) { line_breakcheck(); - p = vim_strchr(line, '/'); + char *p = vim_strchr(line, '/'); if (p == NULL) { continue; // No Tab found, just skip the line. } @@ -1013,7 +997,6 @@ static void spell_find_cleanup(suginfo_T *su) /// Try finding suggestions by recognizing specific situations. static void suggest_try_special(suginfo_T *su) { - char c; char word[MAXWLEN]; // Recognize a word that is repeated: "the the". @@ -1023,7 +1006,7 @@ static void suggest_try_special(suginfo_T *su) if (strlen(p) == len && strncmp(su->su_fbadword, p, len) == 0) { // Include badflags: if the badword is onecap or allcap // use that for the goodword too: "The the" -> "The". - c = su->su_fbadword[len]; + char c = su->su_fbadword[len]; su->su_fbadword[len] = NUL; make_case_word(su->su_fbadword, word, su->su_badflags); su->su_fbadword[len] = c; @@ -1084,16 +1067,14 @@ static void prof_report(char *name) static void suggest_try_change(suginfo_T *su) { char fword[MAXWLEN]; // copy of the bad word, case-folded - int n; - char *p; langp_T *lp; // We make a copy of the case-folded bad word, so that we can modify it // to find matches (esp. REP items). Append some more text, changing // chars after the bad word may help. STRCPY(fword, su->su_fbadword); - n = (int)strlen(fword); - p = su->su_badptr + su->su_badlen; + int n = (int)strlen(fword); + char *p = su->su_badptr + su->su_badlen; (void)spell_casefold(curwin, p, (int)strlen(p), fword + n, MAXWLEN - n); // Make sure the resulting text is not longer than the original text. @@ -1165,12 +1146,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // when going deeper but not when coming // back. char_u compflags[MAXWLEN]; // compound flags, one for each word - trystate_T *sp; int newscore; int score; char_u *byts, *fbyts, *pbyts; idx_T *idxs, *fidxs, *pidxs; - int depth; int c, c2, c3; int n = 0; int flags; @@ -1195,8 +1174,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // "tword[]" contains the word collected from nodes in the tree. // "fword[]" the word we are trying to match with (initially the bad // word). - depth = 0; - sp = &stack[0]; + int depth = 0; + trystate_T *sp = &stack[0]; CLEAR_POINTER(sp); // -V1068 sp->ts_curi = 1; @@ -2387,7 +2366,6 @@ static void go_deeper(trystate_T *stack, int depth, int score_add) static void find_keepcap_word(slang_T *slang, char *fword, char *kword) { char uword[MAXWLEN]; // "fword" in upper-case - int depth; idx_T tryidx; // The following arrays are used at each depth in the tree. @@ -2418,7 +2396,7 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword) // Each character needs to be tried both case-folded and upper-case. // All this gets very complicated if we keep in mind that changing case // may change the byte length of a multi-byte character... - depth = 0; + int depth = 0; arridx[0] = 0; round[0] = 0; fwordidx[0] = 0; @@ -2656,16 +2634,14 @@ static void score_combine(suginfo_T *su) /// @param badsound sound-folded badword static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char *badsound) { - char *p; char *pbad; char *pgood; char badsound2[MAXWLEN]; char fword[MAXWLEN]; char goodsound[MAXWLEN]; char goodword[MAXWLEN]; - int lendiff; - lendiff = su->su_badlen - stp->st_orglen; + int lendiff = su->su_badlen - stp->st_orglen; if (lendiff >= 0) { pbad = badsound; } else { @@ -2678,7 +2654,7 @@ static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char *ba // space. if (ascii_iswhite(su->su_badptr[su->su_badlen]) && *skiptowhite(stp->st_word) == NUL) { - for (p = fword; *(p = skiptowhite(p)) != NUL;) { + for (char *p = fword; *(p = skiptowhite(p)) != NUL;) { STRMOVE(p, p + 1); } } @@ -2801,9 +2777,6 @@ static void suggest_try_soundalike_finish(void) static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T *lp) { slang_T *slang = lp->lp_slang; // language for sound folding - int sfwordnr; - char *nrline; - int orgnr; char theword[MAXWLEN]; int i; int wlen; @@ -2813,8 +2786,6 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T int wordcount; int wc; int goodscore; - hash_T hash; - hashitem_T *hi; sftword_T *sft; int bc, gc; int limit; @@ -2823,10 +2794,9 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T // times with different scores. Since the following is quite slow only do // the words that have a better score than before. Use a hashtable to // remember the words that have been done. - hash = hash_hash(goodword); + hash_T hash = hash_hash(goodword); const size_t goodword_len = strlen(goodword); - hi = hash_lookup(&slang->sl_sounddone, (const char *)goodword, goodword_len, - hash); + hashitem_T *hi = hash_lookup(&slang->sl_sounddone, (const char *)goodword, goodword_len, hash); if (HASHITEM_EMPTY(hi)) { sft = xmalloc(offsetof(sftword_T, sft_word) + goodword_len + 1); sft->sft_score = (int16_t)score; @@ -2841,15 +2811,15 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T } // Find the word nr in the soundfold tree. - sfwordnr = soundfold_find(slang, goodword); + int sfwordnr = soundfold_find(slang, goodword); if (sfwordnr < 0) { internal_error("add_sound_suggest()"); return; } // Go over the list of good words that produce this soundfold word - nrline = ml_get_buf(slang->sl_sugbuf, (linenr_T)sfwordnr + 1, false); - orgnr = 0; + char *nrline = ml_get_buf(slang->sl_sugbuf, (linenr_T)sfwordnr + 1, false); + int orgnr = 0; while (*nrline != NUL) { // The wordnr was stored in a minimal nr of bytes as an offset to the // previous wordnr. @@ -2984,24 +2954,20 @@ badword: static int soundfold_find(slang_T *slang, char *word) { idx_T arridx = 0; - int len; int wlen = 0; - int c; char_u *ptr = (char_u *)word; - char_u *byts; - idx_T *idxs; int wordnr = 0; - byts = (char_u *)slang->sl_sbyts; - idxs = slang->sl_sidxs; + char_u *byts = (char_u *)slang->sl_sbyts; + idx_T *idxs = slang->sl_sidxs; for (;;) { // First byte is the number of possible bytes. - len = byts[arridx++]; + int len = byts[arridx++]; // If the first possible byte is a zero the word could end here. // If the word ends we found the word. If not skip the NUL bytes. - c = ptr[wlen]; + int c = ptr[wlen]; if (byts[arridx] == NUL) { if (c == NUL) { break; @@ -3212,19 +3178,17 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i /// @param gap either su_ga or su_sga static void check_suggestions(suginfo_T *su, garray_T *gap) { - suggest_T *stp; char longword[MAXWLEN + 1]; - int len; hlf_T attr; if (gap->ga_len == 0) { return; } - stp = &SUG(*gap, 0); + suggest_T *stp = &SUG(*gap, 0); for (int i = gap->ga_len - 1; i >= 0; i--) { // Need to append what follows to check for "the the". xstrlcpy(longword, stp[i].st_word, MAXWLEN + 1); - len = stp[i].st_wordlen; + int len = stp[i].st_wordlen; xstrlcpy(longword + len, su->su_badptr + stp[i].st_orglen, (size_t)(MAXWLEN - len + 1)); attr = HLF_COUNT; @@ -3243,17 +3207,13 @@ static void check_suggestions(suginfo_T *su, garray_T *gap) /// Add a word to be banned. static void add_banned(suginfo_T *su, char *word) { - char *s; - hash_T hash; - hashitem_T *hi; - - hash = hash_hash(word); + hash_T hash = hash_hash(word); const size_t word_len = strlen(word); - hi = hash_lookup(&su->su_banned, word, word_len, hash); + hashitem_T *hi = hash_lookup(&su->su_banned, word, word_len, hash); if (!HASHITEM_EMPTY(hi)) { // already present return; } - s = xmemdupz(word, word_len); + char *s = xmemdupz(word, word_len); hash_add_item(&su->su_banned, hi, s, hash); } @@ -3273,19 +3233,19 @@ static void rescore_one(suginfo_T *su, suggest_T *stp) { slang_T *slang = stp->st_slang; char sal_badword[MAXWLEN]; - char *p; // Only rescore suggestions that have no sal score yet and do have a // language. if (slang != NULL && !GA_EMPTY(&slang->sl_sal) && !stp->st_had_bonus) { + char_u *p; if (slang == su->su_sallang) { - p = su->su_sal_badword; + p = (char_u *)su->su_sal_badword; } else { spell_soundfold(slang, su->su_fbadword, true, sal_badword); - p = sal_badword; + p = (char_u *)sal_badword; } - stp->st_altscore = stp_sal_score(stp, su, slang, p); + stp->st_altscore = stp_sal_score(stp, su, slang, (char *)p); if (stp->st_altscore == SCORE_MAXMAX) { stp->st_altscore = SCORE_BIG; } @@ -3354,9 +3314,6 @@ static int soundalike_score(char *goodstart, char *badstart) { char *goodsound = goodstart; char *badsound = badstart; - int goodlen; - int badlen; - int n; char *pl, *ps; char *pl2, *ps2; int score = 0; @@ -3389,12 +3346,12 @@ static int soundalike_score(char *goodstart, char *badstart) } } - goodlen = (int)strlen(goodsound); - badlen = (int)strlen(badsound); + int goodlen = (int)strlen(goodsound); + int badlen = (int)strlen(badsound); // Return quickly if the lengths are too different to be fixed by two // changes. - n = goodlen - badlen; + int n = goodlen - badlen; if (n < -2 || n > 2) { return SCORE_MAXMAX; } @@ -3683,25 +3640,21 @@ static int spell_edit_score_limit_w(slang_T *slang, const char *badword, const c int limit) { limitscore_T stack[10]; // allow for over 3 * 2 edits - int stackidx; - int bi, gi; int bi2, gi2; int bc, gc; - int score; int score_off; - int minscore; int round; int wbadword[MAXWLEN]; int wgoodword[MAXWLEN]; // Get the characters from the multi-byte strings and put them in an // int array for easy access. - bi = 0; + int bi = 0; for (const char *p = badword; *p != NUL;) { wbadword[bi++] = mb_cptr2char_adv(&p); } wbadword[bi++] = 0; - gi = 0; + int gi = 0; for (const char *p = goodword; *p != NUL;) { wgoodword[gi++] = mb_cptr2char_adv(&p); } @@ -3714,11 +3667,11 @@ static int spell_edit_score_limit_w(slang_T *slang, const char *badword, const c // pushed unto a stack and tried later, some are tried right away. At the // end of the word the score for one alternative is known. The lowest // possible score is stored in "minscore". - stackidx = 0; + int stackidx = 0; bi = 0; gi = 0; - score = 0; - minscore = limit + 1; + int score = 0; + int minscore = limit + 1; for (;;) { // Skip over an equal part, score remains the same. -- cgit From 5f72ab77bff1f1224be5cbbf9423bdddbc25635c Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 12 Feb 2023 18:48:49 +0100 Subject: refactor: reduce scope of locals as per the style guide 3 (#22221) refactor: reduce scope of locals as per the style guide --- src/nvim/spellsuggest.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 66829c60c9..d176a65228 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -2491,7 +2491,6 @@ static void score_comp_sal(suginfo_T *su) { langp_T *lp; char badsound[MAXWLEN]; - int i; suggest_T *stp; suggest_T *sstp; int score; @@ -2505,7 +2504,7 @@ static void score_comp_sal(suginfo_T *su) // soundfold the bad word spell_soundfold(lp->lp_slang, su->su_fbadword, true, badsound); - for (i = 0; i < su->su_ga.ga_len; i++) { + for (int i = 0; i < su->su_ga.ga_len; i++) { stp = &SUG(su->su_ga, i); // Case-fold the suggested word, sound-fold it and compute the -- cgit From 8ecd129f1ef92aefea506247677f2693c5db9efd Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 27 Feb 2023 22:16:12 +0000 Subject: fix: address -Wmaybe-uninitialized warnings (#22436) --- src/nvim/spellsuggest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index d176a65228..ea2d5e6ff7 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -1209,7 +1209,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // The loop may take an indefinite amount of time. Break out after some // time. - proftime_T time_limit; + proftime_T time_limit = 0; if (spell_suggest_timeout > 0) { time_limit = profile_setlimit(spell_suggest_timeout); } -- cgit From 6cab36e5b7b0d741abe6c5a7c0e20bad30361034 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 4 Mar 2023 13:10:00 +0100 Subject: refactor: replace char_u with char or uint8_t (#22400) Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/spellsuggest.c | 126 ++++++++++++++++++++++++------------------------ 1 file changed, 63 insertions(+), 63 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index ea2d5e6ff7..2823e74c2f 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -189,28 +189,28 @@ typedef enum { /// Struct to keep the state at each level in suggest_try_change(). typedef struct trystate_S { - state_T ts_state; ///< state at this level, STATE_ - int ts_score; ///< score - idx_T ts_arridx; ///< index in tree array, start of node - int16_t ts_curi; ///< index in list of child nodes - char_u ts_fidx; ///< index in fword[], case-folded bad word - char_u ts_fidxtry; ///< ts_fidx at which bytes may be changed - char_u ts_twordlen; ///< valid length of tword[] - char_u ts_prefixdepth; ///< stack depth for end of prefix or - ///< PFD_PREFIXTREE or PFD_NOPREFIX - char_u ts_flags; ///< TSF_ flags - char_u ts_tcharlen; ///< number of bytes in tword character - char_u ts_tcharidx; ///< current byte index in tword character - char_u ts_isdiff; ///< DIFF_ values - char_u ts_fcharstart; ///< index in fword where badword char started - char_u ts_prewordlen; ///< length of word in "preword[]" - char_u ts_splitoff; ///< index in "tword" after last split - char_u ts_splitfidx; ///< "ts_fidx" at word split - char_u ts_complen; ///< nr of compound words used - char_u ts_compsplit; ///< index for "compflags" where word was spit - char_u ts_save_badflags; ///< su_badflags saved here - char_u ts_delidx; ///< index in fword for char that was deleted, - ///< valid when "ts_flags" has TSF_DIDDEL + state_T ts_state; ///< state at this level, STATE_ + int ts_score; ///< score + idx_T ts_arridx; ///< index in tree array, start of node + int16_t ts_curi; ///< index in list of child nodes + uint8_t ts_fidx; ///< index in fword[], case-folded bad word + uint8_t ts_fidxtry; ///< ts_fidx at which bytes may be changed + uint8_t ts_twordlen; ///< valid length of tword[] + uint8_t ts_prefixdepth; ///< stack depth for end of prefix or + ///< PFD_PREFIXTREE or PFD_NOPREFIX + uint8_t ts_flags; ///< TSF_ flags + uint8_t ts_tcharlen; ///< number of bytes in tword character + uint8_t ts_tcharidx; ///< current byte index in tword character + uint8_t ts_isdiff; ///< DIFF_ values + uint8_t ts_fcharstart; ///< index in fword where badword char started + uint8_t ts_prewordlen; ///< length of word in "preword[]" + uint8_t ts_splitoff; ///< index in "tword" after last split + uint8_t ts_splitfidx; ///< "ts_fidx" at word split + uint8_t ts_complen; ///< nr of compound words used + uint8_t ts_compsplit; ///< index for "compflags" where word was spit + uint8_t ts_save_badflags; ///< su_badflags saved here + uint8_t ts_delidx; ///< index in fword for char that was deleted, + ///< valid when "ts_flags" has TSF_DIDDEL } trystate_T; // values for ts_isdiff @@ -243,7 +243,7 @@ static long spell_suggest_timeout = 5000; /// Returns true when the sequence of flags in "compflags" plus "flag" can /// possibly form a valid compounded word. This also checks the COMPOUNDRULE /// lines if they don't contain wildcards. -static bool can_be_compound(trystate_T *sp, slang_T *slang, char_u *compflags, int flag) +static bool can_be_compound(trystate_T *sp, slang_T *slang, uint8_t *compflags, int flag) { // If the flag doesn't appear in sl_compstartflags or sl_compallflags // then it can't possibly compound. @@ -256,7 +256,7 @@ static bool can_be_compound(trystate_T *sp, slang_T *slang, char_u *compflags, i // possibly can form a match with COMPOUNDRULE patterns. This only // makes sense when we have two or more words. if (slang->sl_comprules != NULL && sp->ts_complen > sp->ts_compsplit) { - compflags[sp->ts_complen] = (char_u)flag; + compflags[sp->ts_complen] = (uint8_t)flag; compflags[sp->ts_complen + 1] = NUL; bool v = match_compoundrule(slang, compflags + sp->ts_compsplit); compflags[sp->ts_complen] = NUL; @@ -349,7 +349,7 @@ static int badword_captype(char *word, char *end) /// @return the offset. static int bytes2offset(char **pp) { - char_u *p = (char_u *)(*pp); + uint8_t *p = (uint8_t *)(*pp); int nr; int c = *p++; @@ -1145,10 +1145,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // words and split word. NUL terminated // when going deeper but not when coming // back. - char_u compflags[MAXWLEN]; // compound flags, one for each word + uint8_t compflags[MAXWLEN]; // compound flags, one for each word int newscore; int score; - char_u *byts, *fbyts, *pbyts; + uint8_t *byts, *fbyts, *pbyts; idx_T *idxs, *fidxs, *pidxs; int c, c2, c3; int n = 0; @@ -1165,7 +1165,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun bool goodword_ends; #ifdef DEBUG_TRIEWALK // Stores the name of the change made at each level. - char_u changename[MAXWLEN][80]; + uint8_t changename[MAXWLEN][80]; #endif int breakcheckcount = 1000; bool compound_ok; @@ -1181,7 +1181,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun if (soundfold) { // Going through the soundfold tree. - byts = fbyts = (char_u *)slang->sl_sbyts; + byts = fbyts = (uint8_t *)slang->sl_sbyts; idxs = fidxs = slang->sl_sidxs; pbyts = NULL; pidxs = NULL; @@ -1190,9 +1190,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun } else { // When there are postponed prefixes we need to use these first. At // the end of the prefix we continue in the case-fold tree. - fbyts = (char_u *)slang->sl_fbyts; + fbyts = (uint8_t *)slang->sl_fbyts; fidxs = slang->sl_fidxs; - pbyts = (char_u *)slang->sl_pbyts; + pbyts = (uint8_t *)slang->sl_pbyts; pidxs = slang->sl_pidxs; if (pbyts != NULL) { byts = pbyts; @@ -1239,7 +1239,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun n = (int)sp->ts_state; PROF_STORE(sp->ts_state) sp->ts_state = STATE_ENDNUL; - sp->ts_save_badflags = (char_u)su->su_badflags; + sp->ts_save_badflags = (uint8_t)su->su_badflags; // At end of a prefix or at start of prefixtree: check for // following word. @@ -1256,7 +1256,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun go_deeper(stack, depth, 0); depth++; sp = &stack[depth]; - sp->ts_prefixdepth = (char_u)(depth - 1); + sp->ts_prefixdepth = (uint8_t)(depth - 1); byts = fbyts; idxs = fidxs; sp->ts_arridx = 0; @@ -1266,7 +1266,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun tword[sp->ts_twordlen] = NUL; make_case_word(tword + sp->ts_splitoff, preword + sp->ts_prewordlen, flags); - sp->ts_prewordlen = (char_u)strlen(preword); + sp->ts_prewordlen = (uint8_t)strlen(preword); sp->ts_splitoff = sp->ts_twordlen; } break; @@ -1276,7 +1276,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // Past bytes in node and/or past NUL bytes. PROF_STORE(sp->ts_state) sp->ts_state = STATE_ENDNUL; - sp->ts_save_badflags = (char_u)su->su_badflags; + sp->ts_save_badflags = (uint8_t)su->su_badflags; break; } @@ -1379,7 +1379,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun break; } - compflags[sp->ts_complen] = (char_u)((unsigned)flags >> 24); + compflags[sp->ts_complen] = (uint8_t)((unsigned)flags >> 24); compflags[sp->ts_complen + 1] = NUL; xstrlcpy(preword + sp->ts_prewordlen, tword + sp->ts_splitoff, @@ -1577,7 +1577,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun < slang->sl_compmax) && (can_be_compound(sp, slang, compflags, (int)((unsigned)flags >> 24)))) { try_compound = true; - compflags[sp->ts_complen] = (char_u)((unsigned)flags >> 24); + compflags[sp->ts_complen] = (uint8_t)((unsigned)flags >> 24); compflags[sp->ts_complen + 1] = NUL; } @@ -1596,7 +1596,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun sp->ts_curi--; // do the same NUL again compflags[sp->ts_complen] = NUL; } else { - sp->ts_flags &= (char_u) ~TSF_DIDSPLIT; + sp->ts_flags &= (uint8_t) ~TSF_DIDSPLIT; } if (try_split || try_compound) { @@ -1641,7 +1641,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun } #endif // Save things to be restored at STATE_SPLITUNDO. - sp->ts_save_badflags = (char_u)su->su_badflags; + sp->ts_save_badflags = (uint8_t)su->su_badflags; PROF_STORE(sp->ts_state) sp->ts_state = STATE_SPLITUNDO; @@ -1652,7 +1652,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun if (!try_compound && !fword_ends) { STRCAT(preword, " "); } - sp->ts_prewordlen = (char_u)strlen(preword); + sp->ts_prewordlen = (uint8_t)strlen(preword); sp->ts_splitoff = sp->ts_twordlen; sp->ts_splitfidx = sp->ts_fidx; @@ -1673,12 +1673,12 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun if (fword_ends) { // Copy the skipped character to preword. memmove(preword + sp->ts_prewordlen, fword + sp->ts_fidx, (size_t)l); - sp->ts_prewordlen = (char_u)(sp->ts_prewordlen + l); + sp->ts_prewordlen = (uint8_t)(sp->ts_prewordlen + l); preword[sp->ts_prewordlen] = NUL; } else { sp->ts_score -= SCORE_SPLIT - SCORE_SUBST; } - sp->ts_fidx = (char_u)(sp->ts_fidx + l); + sp->ts_fidx = (uint8_t)(sp->ts_fidx + l); } // When compounding include compound flag in @@ -1803,7 +1803,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // First byte. sp->ts_tcharidx = 0; sp->ts_tcharlen = MB_BYTE2LEN(c); - sp->ts_fcharstart = (char_u)(sp->ts_fidx - 1); + sp->ts_fcharstart = (uint8_t)(sp->ts_fidx - 1); sp->ts_isdiff = (newscore != 0) ? DIFF_YES : DIFF_NONE; } else if (sp->ts_isdiff == DIFF_INSERT && sp->ts_fidx > 0) { @@ -1816,8 +1816,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun if (sp->ts_isdiff == DIFF_YES) { // Correct ts_fidx for the byte length of the // character (we didn't check that before). - sp->ts_fidx = (char_u)(sp->ts_fcharstart - + utfc_ptr2len(fword + sp->ts_fcharstart)); + sp->ts_fidx = (uint8_t)(sp->ts_fcharstart + + utfc_ptr2len(fword + sp->ts_fcharstart)); // For changing a composing character adjust // the score from SCORE_SUBST to @@ -1905,7 +1905,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // results. c = utf_ptr2char(fword + sp->ts_fidx); stack[depth].ts_fidx = - (char_u)(stack[depth].ts_fidx + utfc_ptr2len(fword + sp->ts_fidx)); + (uint8_t)(stack[depth].ts_fidx + utfc_ptr2len(fword + sp->ts_fidx)); if (utf_iscomposing(c)) { stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; } else if (c == utf_ptr2char(fword + stack[depth].ts_fidx)) { @@ -1985,7 +1985,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // There are following bytes for the same character. // We must find all bytes before trying // delete/insert/swap/etc. - sp->ts_tcharlen = (char_u)fl; + sp->ts_tcharlen = (uint8_t)fl; sp->ts_tcharidx = 1; sp->ts_isdiff = DIFF_INSERT; } @@ -2061,7 +2061,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun fl = utf_char2len(c2); memmove(p, p + n, (size_t)fl); utf_char2bytes(c, p + fl); - stack[depth].ts_fidxtry = (char_u)(sp->ts_fidx + n + fl); + stack[depth].ts_fidxtry = (uint8_t)(sp->ts_fidx + n + fl); } else { // If this swap doesn't work then SWAP3 won't either. PROF_STORE(sp->ts_state) @@ -2118,7 +2118,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun memmove(p, p + n + fl, (size_t)tl); utf_char2bytes(c2, p + tl); utf_char2bytes(c, p + fl + tl); - stack[depth].ts_fidxtry = (char_u)(sp->ts_fidx + n + fl + tl); + stack[depth].ts_fidxtry = (uint8_t)(sp->ts_fidx + n + fl + tl); } else { PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; @@ -2166,7 +2166,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun fl += utf_ptr2len(p + n + fl); memmove(p, p + n, (size_t)fl); utf_char2bytes(c, p + fl); - stack[depth].ts_fidxtry = (char_u)(sp->ts_fidx + n + fl); + stack[depth].ts_fidxtry = (uint8_t)(sp->ts_fidx + n + fl); } else { PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; @@ -2203,7 +2203,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun tl = utf_ptr2len(p + n); memmove(p + tl, p, (size_t)n); utf_char2bytes(c, p); - stack[depth].ts_fidxtry = (char_u)(sp->ts_fidx + n + tl); + stack[depth].ts_fidxtry = (uint8_t)(sp->ts_fidx + n + tl); } else { PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; @@ -2293,7 +2293,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun repextra += tl - fl; } memmove(p, ftp->ft_to, (size_t)tl); - stack[depth].ts_fidxtry = (char_u)(sp->ts_fidx + tl); + stack[depth].ts_fidxtry = (uint8_t)(sp->ts_fidx + tl); stack[depth].ts_tcharlen = 0; break; } @@ -2381,7 +2381,7 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword) int c; idx_T lo, hi, m; char *p; - char_u *byts = (char_u *)slang->sl_kbyts; // array with bytes of the words + uint8_t *byts = (uint8_t *)slang->sl_kbyts; // array with bytes of the words idx_T *idxs = slang->sl_kidxs; // array with indexes if (byts == NULL) { @@ -2683,11 +2683,11 @@ static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char *ba /// handled already. typedef struct { int16_t sft_score; ///< lowest score used - char_u sft_word[]; ///< soundfolded word + uint8_t sft_word[]; ///< soundfolded word } sftword_T; static sftword_T dumsft; -#define HIKEY2SFT(p) ((sftword_T *)((p) - (dumsft.sft_word - (char_u *)&dumsft))) +#define HIKEY2SFT(p) ((sftword_T *)((p) - (dumsft.sft_word - (uint8_t *)&dumsft))) #define HI2SFT(hi) HIKEY2SFT((hi)->hi_key) /// Prepare for calling suggest_try_soundalike(). @@ -2779,7 +2779,7 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T char theword[MAXWLEN]; int i; int wlen; - char_u *byts; + uint8_t *byts; idx_T *idxs; int n; int wordcount; @@ -2824,7 +2824,7 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T // previous wordnr. orgnr += bytes2offset(&nrline); - byts = (char_u *)slang->sl_fbyts; + byts = (uint8_t *)slang->sl_fbyts; idxs = slang->sl_fidxs; // Lookup the word "orgnr" one of the two tries. @@ -2954,10 +2954,10 @@ static int soundfold_find(slang_T *slang, char *word) { idx_T arridx = 0; int wlen = 0; - char_u *ptr = (char_u *)word; + uint8_t *ptr = (uint8_t *)word; int wordnr = 0; - char_u *byts = (char_u *)slang->sl_sbyts; + uint8_t *byts = (uint8_t *)slang->sl_sbyts; idx_T *idxs = slang->sl_sidxs; for (;;) { @@ -3236,15 +3236,15 @@ static void rescore_one(suginfo_T *su, suggest_T *stp) // Only rescore suggestions that have no sal score yet and do have a // language. if (slang != NULL && !GA_EMPTY(&slang->sl_sal) && !stp->st_had_bonus) { - char_u *p; + char *p; if (slang == su->su_sallang) { - p = (char_u *)su->su_sal_badword; + p = su->su_sal_badword; } else { spell_soundfold(slang, su->su_fbadword, true, sal_badword); - p = (char_u *)sal_badword; + p = sal_badword; } - stp->st_altscore = stp_sal_score(stp, su, slang, (char *)p); + stp->st_altscore = stp_sal_score(stp, su, slang, p); if (stp->st_altscore == SCORE_MAXMAX) { stp->st_altscore = SCORE_BIG; } -- cgit From dde5ce46b2e3e77efc27394b946ef49ce565cd95 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 4 Mar 2023 21:09:50 +0800 Subject: refactor(spell): use uint8_t for "byts" variables (#22519) Avoid casting back and forth. --- src/nvim/spellsuggest.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 2823e74c2f..2a9b5e1f4e 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -1181,7 +1181,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun if (soundfold) { // Going through the soundfold tree. - byts = fbyts = (uint8_t *)slang->sl_sbyts; + byts = fbyts = slang->sl_sbyts; idxs = fidxs = slang->sl_sidxs; pbyts = NULL; pidxs = NULL; @@ -1190,9 +1190,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun } else { // When there are postponed prefixes we need to use these first. At // the end of the prefix we continue in the case-fold tree. - fbyts = (uint8_t *)slang->sl_fbyts; + fbyts = slang->sl_fbyts; fidxs = slang->sl_fidxs; - pbyts = (uint8_t *)slang->sl_pbyts; + pbyts = slang->sl_pbyts; pidxs = slang->sl_pidxs; if (pbyts != NULL) { byts = pbyts; @@ -2381,7 +2381,7 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword) int c; idx_T lo, hi, m; char *p; - uint8_t *byts = (uint8_t *)slang->sl_kbyts; // array with bytes of the words + uint8_t *byts = slang->sl_kbyts; // array with bytes of the words idx_T *idxs = slang->sl_kidxs; // array with indexes if (byts == NULL) { @@ -2824,7 +2824,7 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T // previous wordnr. orgnr += bytes2offset(&nrline); - byts = (uint8_t *)slang->sl_fbyts; + byts = slang->sl_fbyts; idxs = slang->sl_fidxs; // Lookup the word "orgnr" one of the two tries. @@ -2957,7 +2957,7 @@ static int soundfold_find(slang_T *slang, char *word) uint8_t *ptr = (uint8_t *)word; int wordnr = 0; - uint8_t *byts = (uint8_t *)slang->sl_sbyts; + uint8_t *byts = slang->sl_sbyts; idx_T *idxs = slang->sl_sidxs; for (;;) { -- cgit From d6ecead36406233cc56353dd05f3380f0497630f Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 14 Mar 2023 11:49:46 +0100 Subject: refactor(screen): screen.c delenda est drawscreen.c vs screen.c makes absolutely no sense. The screen exists only to draw upon it, therefore helper functions are distributed randomly between screen.c and the file that does the redrawing. In addition screen.c does a lot of drawing on the screen. It made more sense for vim/vim as our grid.c is their screen.c Not sure if we want to dump all the code for option chars into optionstr.c, so keep these in a optionchar.c for now. --- src/nvim/spellsuggest.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 2a9b5e1f4e..705e215dfa 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -39,7 +39,6 @@ #include "nvim/os/os_defs.h" #include "nvim/pos.h" #include "nvim/profile.h" -#include "nvim/screen.h" #include "nvim/spell.h" #include "nvim/spellfile.h" #include "nvim/spellsuggest.h" @@ -569,7 +568,7 @@ void spell_suggest(int count) } vim_snprintf(IObuff, IOSIZE, "%2d", i + 1); if (cmdmsg_rl) { - rl_mirror(IObuff); + rl_mirror_ascii(IObuff); } msg_puts((const char *)IObuff); @@ -595,7 +594,7 @@ void spell_suggest(int count) } if (cmdmsg_rl) { // Mirror the numbers, but keep the leading space. - rl_mirror(IObuff + 1); + rl_mirror_ascii(IObuff + 1); } msg_advance(30); msg_puts((const char *)IObuff); -- cgit From d5f6176e6dc4b4e12fc5061ca6e87f4af533e46a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Sat, 1 Apr 2023 02:49:51 +0200 Subject: refactor: add const and remove unnecessary casts (#22841) --- src/nvim/spellsuggest.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 705e215dfa..d28460a63d 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -551,7 +551,7 @@ void spell_suggest(int count) vim_snprintf(IObuff, IOSIZE, ":ot \"%.*s\" egnahC", sug.su_badlen, sug.su_badptr); } - msg_puts((const char *)IObuff); + msg_puts(IObuff); msg_clr_eos(); msg_putchar('\n'); @@ -570,16 +570,16 @@ void spell_suggest(int count) if (cmdmsg_rl) { rl_mirror_ascii(IObuff); } - msg_puts((const char *)IObuff); + msg_puts(IObuff); vim_snprintf(IObuff, IOSIZE, " \"%s\"", wcopy); - msg_puts((const char *)IObuff); + msg_puts(IObuff); // The word may replace more than "su_badlen". if (sug.su_badlen < stp->st_orglen) { vim_snprintf(IObuff, IOSIZE, _(" < \"%.*s\""), stp->st_orglen, sug.su_badptr); - msg_puts((const char *)IObuff); + msg_puts(IObuff); } if (p_verbose > 0) { @@ -597,7 +597,7 @@ void spell_suggest(int count) rl_mirror_ascii(IObuff + 1); } msg_advance(30); - msg_puts((const char *)IObuff); + msg_puts(IObuff); } msg_putchar('\n'); } -- cgit From 9408f2dcf7cade2631688300e9b58eed6bc5219a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:40:57 +0200 Subject: refactor: remove redundant const char * casts --- src/nvim/spellsuggest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index d28460a63d..e029d949fd 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -2794,7 +2794,7 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T // remember the words that have been done. hash_T hash = hash_hash(goodword); const size_t goodword_len = strlen(goodword); - hashitem_T *hi = hash_lookup(&slang->sl_sounddone, (const char *)goodword, goodword_len, hash); + hashitem_T *hi = hash_lookup(&slang->sl_sounddone, goodword, goodword_len, hash); if (HASHITEM_EMPTY(hi)) { sft = xmalloc(offsetof(sftword_T, sft_word) + goodword_len + 1); sft->sft_score = (int16_t)score; -- cgit From 3b0df1780e2c8526bda5dead18ee7cc45925caba Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:23:44 +0200 Subject: refactor: uncrustify Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`. --- src/nvim/spellsuggest.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index e029d949fd..bde853fa20 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -1926,7 +1926,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // skip over NUL bytes n = sp->ts_arridx; - for (;;) { + while (true) { if (sp->ts_curi > byts[n]) { // Only NUL bytes at this node, go to next state. PROF_STORE(sp->ts_state) @@ -2959,7 +2959,7 @@ static int soundfold_find(slang_T *slang, char *word) uint8_t *byts = slang->sl_sbyts; idx_T *idxs = slang->sl_sidxs; - for (;;) { + while (true) { // First byte is the number of possible bytes. int len = byts[arridx++]; @@ -3077,7 +3077,7 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i // "thee the" is added next to changing the first "the" the "thee". const char *pgood = goodword + strlen(goodword); char *pbad = su->su_badptr + badlenarg; - for (;;) { + while (true) { goodlen = (int)(pgood - goodword); badlen = (int)(pbad - su->su_badptr); if (goodlen <= 0 || badlen <= 0) { @@ -3671,9 +3671,9 @@ static int spell_edit_score_limit_w(slang_T *slang, const char *badword, const c int score = 0; int minscore = limit + 1; - for (;;) { + while (true) { // Skip over an equal part, score remains the same. - for (;;) { + while (true) { bc = wbadword[bi]; gc = wgoodword[gi]; -- cgit From ff34c91194f9ab9d02808f2880029c38a4655eb5 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 17 Apr 2023 17:23:47 +0100 Subject: vim-patch:9.0.1330: handling new value of an option has a long "else if" chain Problem: Handling new value of an option has a long "else if" chain. Solution: Use a function pointer. (Yegappan Lakshmanan, closes vim/vim#12015) https://github.com/vim/vim/commit/af93691b53f38784efce0b93fe7644c44a7e382e --- src/nvim/spellsuggest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index bde853fa20..84be88be7b 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -453,7 +453,7 @@ void spell_suggest(int count) const int wo_spell_save = curwin->w_p_spell; if (!curwin->w_p_spell) { - did_set_spelllang(curwin); + parse_spelllang(curwin); curwin->w_p_spell = true; } -- cgit From f733595e795cd2b819cb8fd18327cd51f47b2124 Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Fri, 26 May 2023 02:08:18 +0200 Subject: vim-patch:9.0.1578: SpellCap highlight not always updated when needed (#23755) Problem: SpellCap highlight not always updated when needed. Solution: Handle updating line below closed fold and other situations where only part of the window is redrawn. (Luuk van Baal, closes vim/vim#12428, closes vim/vim#12420) https://github.com/vim/vim/commit/2ac6497f0ef186f0e3ba67d7f0a485bfb612bb08 --- src/nvim/spellsuggest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 84be88be7b..1c34c2487f 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -509,7 +509,7 @@ void spell_suggest(int count) // Get the word and its length. // Figure out if the word should be capitalised. - int need_cap = check_need_cap(curwin->w_cursor.lnum, curwin->w_cursor.col); + int need_cap = check_need_cap(curwin, curwin->w_cursor.lnum, curwin->w_cursor.col); // Make a copy of current line since autocommands may free the line. line = xstrdup(get_cursor_line_ptr()); -- cgit From 2493815290c4cb5b1fb97b6d010c10bdf2d47a58 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 30 Jun 2023 21:13:08 +0800 Subject: refactor: fix clang/PVS warnings (#24213) --- src/nvim/spellsuggest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 1c34c2487f..e68a90c982 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -1175,7 +1175,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // word). int depth = 0; trystate_T *sp = &stack[0]; - CLEAR_POINTER(sp); // -V1068 + CLEAR_POINTER(sp); // -V1086 sp->ts_curi = 1; if (soundfold) { -- cgit From cefd774fac76b91f5368833555818c80c992c3b1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 24 Aug 2023 15:14:23 +0200 Subject: refactor(memline): distinguish mutating uses of ml_get_buf() ml_get_buf() takes a third parameters to indicate whether the caller wants to mutate the memline data in place. However the vast majority of the call sites is using this function just to specify a buffer but without any mutation. This makes it harder to grep for the places which actually perform mutation. Solution: Remove the bool param from ml_get_buf(). it now works like ml_get() except for a non-current buffer. Add a new ml_get_buf_mut() function for the mutating use-case, which can be grepped along with the other ml_replace() etc functions which can modify the memline. --- src/nvim/spellsuggest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index e68a90c982..ba389cc070 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -2816,7 +2816,7 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T } // Go over the list of good words that produce this soundfold word - char *nrline = ml_get_buf(slang->sl_sugbuf, (linenr_T)sfwordnr + 1, false); + char *nrline = ml_get_buf(slang->sl_sugbuf, (linenr_T)sfwordnr + 1); int orgnr = 0; while (*nrline != NUL) { // The wordnr was stored in a minimal nr of bytes as an offset to the -- cgit From b85f1dafc7c0a19704135617454f1c66f41202c1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 22:21:17 +0200 Subject: refactor(messages): fold msg_attr into msg problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/spellsuggest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index ba389cc070..4c1873eaca 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -526,7 +526,7 @@ void spell_suggest(int count) true, need_cap, true); if (GA_EMPTY(&sug.su_ga)) { - msg(_("Sorry, no suggestions")); + msg(_("Sorry, no suggestions"), 0); } else if (count > 0) { if (count > sug.su_ga.ga_len) { smsg(_("Sorry, only %" PRId64 " suggestions"), -- cgit From bc13bc154aa574e0bb58a50f2e0ca4570efa57c3 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 29 Sep 2023 16:10:54 +0200 Subject: refactor(message): smsg_attr -> smsg --- src/nvim/spellsuggest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 4c1873eaca..1da61bbb2f 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -529,7 +529,7 @@ void spell_suggest(int count) msg(_("Sorry, no suggestions"), 0); } else if (count > 0) { if (count > sug.su_ga.ga_len) { - smsg(_("Sorry, only %" PRId64 " suggestions"), + smsg(0, _("Sorry, only %" PRId64 " suggestions"), (int64_t)sug.su_ga.ga_len); } } else { @@ -1480,9 +1480,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun int j; // print the stack of changes that brought us here - smsg("------ %s -------", fword); + smsg(0, "------ %s -------", fword); for (j = 0; j < depth; j++) { - smsg("%s", changename[j]); + smsg(0, "%s", changename[j]); } } #endif -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/spellsuggest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 1da61bbb2f..b028cf29ac 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -18,7 +19,6 @@ #include "nvim/cursor.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" -#include "nvim/eval/typval_defs.h" #include "nvim/fileio.h" #include "nvim/garray.h" #include "nvim/getchar.h" -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/spellsuggest.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index b028cf29ac..2ee93b4934 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -34,6 +34,7 @@ #include "nvim/message.h" #include "nvim/normal.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/os/fs.h" #include "nvim/os/input.h" #include "nvim/os/os_defs.h" -- cgit From f06af5e66981095f3244f67d1587ce7e9853eb4c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 08:13:58 +0800 Subject: vim-patch:9.0.1958: cannot complete option values Problem: cannot complete option values Solution: Add completion functions for several options Add cmdline tab-completion for setting string options Add tab-completion for setting string options on the cmdline using `:set=` (along with `:set+=` and `:set-=`). The existing tab completion for setting options currently only works when nothing is typed yet, and it only fills in with the existing value, e.g. when the user does `:set diffopt=` it will be completed to `set diffopt=internal,filler,closeoff` and nothing else. This isn't too useful as a user usually wants auto-complete to suggest all the possible values, such as 'iblank', or 'algorithm:patience'. For set= and set+=, this adds a new optional callback function for each option that can be invoked when doing completion. This allows for each option to have control over how completion works. For example, in 'diffopt', it will suggest the default enumeration, but if `algorithm:` is selected, it will further suggest different algorithm types like 'meyers' and 'patience'. When using set=, the existing option value will be filled in as the first choice to preserve the existing behavior. When using set+= this won't happen as it doesn't make sense. For flag list options (e.g. 'mouse' and 'guioptions'), completion will take into account existing typed values (and in the case of set+=, the existing option value) to make sure it doesn't suggest duplicates. For set-=, there is a new `ExpandSettingSubtract` function which will handle flag list and comma-separated options smartly, by only suggesting values that currently exist in the option. Note that Vim has some existing code that adds special handling for 'filetype', 'syntax', and misc dir options like 'backupdir'. This change preserves them as they already work, instead of converting to the new callback API for each option. closes: vim/vim#13182 https://github.com/vim/vim/commit/900894b09a95398dfc75599e9f0aa2ea25723384 Co-authored-by: Yee Cheng Chin --- src/nvim/spellsuggest.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 2ee93b4934..7b92e69821 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -403,6 +403,7 @@ int spell_check_sps(void) if (*s != NUL && !ascii_isdigit(*s)) { f = -1; } + // Note: Keep this in sync with p_sps_values. } else if (strcmp(buf, "best") == 0) { f = SPS_BEST; } else if (strcmp(buf, "fast") == 0) { -- cgit From 5f03a1eaabfc8de2b3a9c666fcd604763f41e152 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 20 Oct 2023 15:10:33 +0200 Subject: build(lint): remove unnecessary clint.py rules Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py. --- src/nvim/spellsuggest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 7b92e69821..564c4ca12d 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -311,8 +311,8 @@ static int badword_captype(char *word, char *end) } // Count the number of UPPER and lower case letters. - int l= 0; - int u= 0; + int l = 0; + int u = 0; bool first = false; for (char *p = word; p < end; MB_PTR_ADV(p)) { int c = utf_ptr2char(p); -- cgit From 44f0480a22af8f87f8784dac430416cb9913adea Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 31 Oct 2023 21:33:00 +0100 Subject: refactor(grid): implement rightleftcmd as a post-processing step Previously, 'rightleftcmd' was implemented by having all code which would affect msg_col or output screen cells be conditional on `cmdmsg_rl`. This change removes all that and instead implements rightleft as a mirroring post-processing step. --- src/nvim/spellsuggest.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 564c4ca12d..39265718c6 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -537,22 +537,18 @@ void spell_suggest(int count) } else { // When 'rightleft' is set the list is drawn right-left. cmdmsg_rl = curwin->w_p_rl; - if (cmdmsg_rl) { - msg_col = Columns - 1; - } // List the suggestions. msg_start(); msg_row = Rows - 1; // for when 'cmdheight' > 1 lines_left = Rows; // avoid more prompt - vim_snprintf(IObuff, IOSIZE, _("Change \"%.*s\" to:"), - sug.su_badlen, sug.su_badptr); - if (cmdmsg_rl && strncmp(IObuff, "Change", 6) == 0) { + char *fmt = _("Change \"%.*s\" to:"); + if (cmdmsg_rl && strncmp(fmt, "Change", 6) == 0) { // And now the rabbit from the high hat: Avoid showing the // untranslated message rightleft. - vim_snprintf(IObuff, IOSIZE, ":ot \"%.*s\" egnahC", - sug.su_badlen, sug.su_badptr); + fmt = ":ot \"%.*s\" egnahC"; } + vim_snprintf(IObuff, IOSIZE, fmt, sug.su_badlen, sug.su_badptr); msg_puts(IObuff); msg_clr_eos(); msg_putchar('\n'); -- cgit From acc646ad8fc3ef11fcc63b69f3d8484e4a91accd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/spellsuggest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 39265718c6..d1f63e537b 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -234,7 +234,7 @@ enum { PFD_NOTSPECIAL = 0xfd, // highest value that's not special }; -static long spell_suggest_timeout = 5000; +static int spell_suggest_timeout = 5000; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "spellsuggest.c.generated.h" @@ -806,7 +806,7 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc spell_suggest_file(su, buf + 5); } else if (strncmp(buf, "timeout:", 8) == 0) { // Limit the time searching for suggestions. - spell_suggest_timeout = atol(buf + 8); + spell_suggest_timeout = atoi(buf + 8); } else if (!did_intern) { // Use internal method once. spell_suggest_intern(su, interactive); -- cgit From 83db9115af94992a2fb32e927b7349283434ff5d Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 3 Nov 2023 20:25:52 +0100 Subject: refactor(grid): reimplement 'rightleft' as a post-processing step problem: checks for wp->w_p_rl are all over the place, making simple things like "advance column one cell" incredibly complicated. solution: always fill linebuf_char[] using an incrementing counter, and then mirror the buffer as a post-processing step This was "easier" that I first feared, because the stupid but simple workaround for things like keeping linenumbers still left-right, e.g. "mirror them and them mirror them once more" is more or less what vim did already. So let's just keep doing that. --- src/nvim/spellsuggest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index d1f63e537b..938e8cec8f 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -566,7 +566,7 @@ void spell_suggest(int count) } vim_snprintf(IObuff, IOSIZE, "%2d", i + 1); if (cmdmsg_rl) { - rl_mirror_ascii(IObuff); + rl_mirror_ascii(IObuff, NULL); } msg_puts(IObuff); @@ -592,7 +592,7 @@ void spell_suggest(int count) } if (cmdmsg_rl) { // Mirror the numbers, but keep the leading space. - rl_mirror_ascii(IObuff + 1); + rl_mirror_ascii(IObuff + 1, NULL); } msg_advance(30); msg_puts(IObuff); -- cgit From cd63a9addd6e1114c3524fa041ece560550cfe7b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 10 Nov 2023 08:39:21 +0800 Subject: refactor: change some xstrndup() and xstrnsave() to xmemdupz() (#25959) When the given length is exactly the number of bytes to copy, xmemdupz() makes the intention clearer. --- src/nvim/spellsuggest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 938e8cec8f..15ec652859 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -3146,7 +3146,7 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i if (i < 0) { // Add a suggestion. stp = GA_APPEND_VIA_PTR(suggest_T, gap); - stp->st_word = xstrnsave(goodword, (size_t)goodlen); + stp->st_word = xmemdupz(goodword, (size_t)goodlen); stp->st_wordlen = goodlen; stp->st_score = score; stp->st_altscore = altscore; -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/spellsuggest.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 15ec652859..15a58a4434 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // spellsuggest.c: functions for spelling suggestions #include @@ -1173,7 +1170,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // word). int depth = 0; trystate_T *sp = &stack[0]; - CLEAR_POINTER(sp); // -V1086 + CLEAR_POINTER(sp); sp->ts_curi = 1; if (soundfold) { -- cgit From b522cb1ac3fbdf6e68eed5d0b6e1cbeaf3ac2254 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 6 Nov 2023 14:52:27 +0100 Subject: refactor(grid): make screen rendering more multibyte than ever before Problem: buffer text with composing chars are converted from UTF-8 to an array of up to seven UTF-32 values and then converted back to UTF-8 strings. Solution: Convert buffer text directly to UTF-8 based schar_T values. The limit of the text size is now in schar_T bytes, which is currently 31+1 but easily could be raised as it no longer multiplies the size of the entire screen grid when not used, the full size is only required for temporary scratch buffers. Also does some general cleanup to win_line text handling, which was unnecessarily complicated due to multibyte rendering being an "opt-in" feature long ago. Nowadays, a char is just a char, regardless if it consists of one ASCII byte or multiple bytes. --- src/nvim/spellsuggest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 15a58a4434..dab278e383 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -3019,7 +3019,7 @@ static int soundfold_find(slang_T *slang, char *word) static bool similar_chars(slang_T *slang, int c1, int c2) { int m1, m2; - char buf[MB_MAXBYTES + 1]; + char buf[MB_MAXCHAR + 1]; hashitem_T *hi; if (c1 >= 256) { -- cgit From ac1113ded5f8f09dd99a9894d7a7e795626fb728 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 13 Nov 2023 23:40:37 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment --- src/nvim/spellsuggest.c | 210 ++++++++++++++++++------------------------------ 1 file changed, 80 insertions(+), 130 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index dab278e383..62508852b3 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -384,7 +384,6 @@ static int sps_limit = 9999; ///< max nr of suggestions given /// Sets "sps_flags" and "sps_limit". int spell_check_sps(void) { - char *s; char buf[MAXPATHL]; sps_flags = 0; @@ -395,7 +394,7 @@ int spell_check_sps(void) int f = 0; if (ascii_isdigit(*buf)) { - s = buf; + char *s = buf; sps_limit = getdigits_int(&s, true, 0); if (*s != NUL && !ascii_isdigit(*s)) { f = -1; @@ -438,10 +437,8 @@ int spell_check_sps(void) /// When "count" is non-zero use that suggestion. void spell_suggest(int count) { - char *line; pos_T prev_cursor = curwin->w_cursor; char wcopy[MAXWLEN + 2]; - char *p; suginfo_T sug; suggest_T *stp; int mouse_used; @@ -477,7 +474,7 @@ void spell_suggest(int count) badlen++; end_visual_mode(); // make sure we don't include the NUL at the end of the line - line = get_cursor_line_ptr(); + char *line = get_cursor_line_ptr(); if (badlen > (int)strlen(line) - (int)curwin->w_cursor.col) { badlen = (int)strlen(line) - (int)curwin->w_cursor.col; } @@ -487,8 +484,8 @@ void spell_suggest(int count) // No bad word or it starts after the cursor: use the word under the // cursor. curwin->w_cursor = prev_cursor; - line = get_cursor_line_ptr(); - p = line + curwin->w_cursor.col; + char *line = get_cursor_line_ptr(); + char *p = line + curwin->w_cursor.col; // Backup to before start of word. while (p > line && spell_iswordp_nmw(p, curwin)) { MB_PTR_BACK(line, p); @@ -511,7 +508,7 @@ void spell_suggest(int count) int need_cap = check_need_cap(curwin, curwin->w_cursor.lnum, curwin->w_cursor.col); // Make a copy of current line since autocommands may free the line. - line = xstrdup(get_cursor_line_ptr()); + char *line = xstrdup(get_cursor_line_ptr()); spell_suggest_timeout = 5000; // Get the list of suggestions. Limit to 'lines' - 2 or the number in @@ -635,7 +632,7 @@ void spell_suggest(int count) } // Replace the word. - p = xmalloc(strlen(line) - (size_t)stp->st_orglen + (size_t)stp->st_wordlen + 1); + char *p = xmalloc(strlen(line) - (size_t)stp->st_orglen + (size_t)stp->st_wordlen + 1); int c = (int)(sug.su_badptr - line); memmove(p, line, (size_t)c); STRCPY(p + c, stp->st_word); @@ -670,7 +667,6 @@ void spell_suggest(int count) void spell_suggest_list(garray_T *gap, char *word, int maxcount, bool need_cap, bool interactive) { suginfo_T sug; - char *wcopy; spell_find_suggest(word, 0, &sug, maxcount, false, need_cap, interactive); @@ -682,7 +678,7 @@ void spell_suggest_list(garray_T *gap, char *word, int maxcount, bool need_cap, // The suggested word may replace only part of "word", add the not // replaced part. - wcopy = xmalloc((size_t)stp->st_wordlen + strlen(sug.su_badptr + stp->st_orglen) + 1); + char *wcopy = xmalloc((size_t)stp->st_wordlen + strlen(sug.su_badptr + stp->st_orglen) + 1); STRCPY(wcopy, stp->st_word); STRCPY(wcopy + stp->st_wordlen, sug.su_badptr + stp->st_orglen); ((char **)gap->ga_data)[gap->ga_len++] = wcopy; @@ -707,7 +703,6 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc char buf[MAXPATHL]; bool do_combine = false; static bool expr_busy = false; - langp_T *lp; bool did_intern = false; // Set the info in "*su". @@ -754,7 +749,7 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc // using multiple files for one language, it's not that bad when mixing // languages (e.g., "pl,en"). for (int i = 0; i < curbuf->b_s.b_langp.ga_len; i++) { - lp = LANGP_ENTRY(curbuf->b_s.b_langp, i); + langp_T *lp = LANGP_ENTRY(curbuf->b_s.b_langp, i); if (lp->lp_sallang != NULL) { su->su_sallang = lp->lp_sallang; break; @@ -1061,7 +1056,6 @@ static void prof_report(char *name) static void suggest_try_change(suginfo_T *su) { char fword[MAXWLEN]; // copy of the bad word, case-folded - langp_T *lp; // We make a copy of the case-folded bad word, so that we can modify it // to find matches (esp. REP items). Append some more text, changing @@ -1078,7 +1072,7 @@ static void suggest_try_change(suginfo_T *su) } for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; lpi++) { - lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); + langp_T *lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); // If reloading a spell file fails it's still in the list but // everything has been cleared. @@ -1140,29 +1134,22 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // when going deeper but not when coming // back. uint8_t compflags[MAXWLEN]; // compound flags, one for each word - int newscore; - int score; uint8_t *byts, *fbyts, *pbyts; idx_T *idxs, *fidxs, *pidxs; int c, c2, c3; int n = 0; - int flags; garray_T *gap; idx_T arridx; - int len; - char *p; - fromto_T *ftp; - int fl = 0, tl; + int fl = 0; + int tl; int repextra = 0; // extra bytes in fword[] from REP item slang_T *slang = lp->lp_slang; - int fword_ends; bool goodword_ends; #ifdef DEBUG_TRIEWALK // Stores the name of the change made at each level. uint8_t changename[MAXWLEN][80]; #endif int breakcheckcount = 1000; - bool compound_ok; // Go through the whole case-fold tree, try changes at each node. // "tword[]" contains the word collected from nodes in the tree. @@ -1221,7 +1208,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // Start of node: Deal with NUL bytes, which means // tword[] may end here. arridx = sp->ts_arridx; // current node in the tree - len = byts[arridx]; // bytes in this node + int len = byts[arridx]; // bytes in this node arridx += sp->ts_curi; // index of current byte if (sp->ts_prefixdepth == PFD_PREFIXTREE) { @@ -1241,7 +1228,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // Set su->su_badflags to the caps type at this position. // Use the caps type until here for the prefix itself. n = nofold_len(fword, sp->ts_fidx, su->su_badptr); - flags = badword_captype(su->su_badptr, su->su_badptr + n); + int flags = badword_captype(su->su_badptr, su->su_badptr + n); su->su_badflags = badword_captype(su->su_badptr + n, su->su_badptr + su->su_badlen); #ifdef DEBUG_TRIEWALK @@ -1277,17 +1264,17 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun // End of word in tree. sp->ts_curi++; // eat one NUL byte - flags = (int)idxs[arridx]; + int flags = (int)idxs[arridx]; // Skip words with the NOSUGGEST flag. if (flags & WF_NOSUGGEST) { break; } - fword_ends = (fword[sp->ts_fidx] == NUL - || (soundfold - ? ascii_iswhite(fword[sp->ts_fidx]) - : !spell_iswordp(fword + sp->ts_fidx, curwin))); + int fword_ends = (fword[sp->ts_fidx] == NUL + || (soundfold + ? ascii_iswhite(fword[sp->ts_fidx]) + : !spell_iswordp(fword + sp->ts_fidx, curwin))); tword[sp->ts_twordlen] = NUL; if (sp->ts_prefixdepth <= PFD_NOTSPECIAL @@ -1329,8 +1316,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun goodword_ends = true; } - p = NULL; - compound_ok = true; + char *p = NULL; + bool compound_ok = true; if (sp->ts_complen > sp->ts_compsplit) { if (slang->sl_nobreak) { // There was a word before this word. When there was no @@ -1343,9 +1330,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun tword + sp->ts_splitoff, (size_t)(sp->ts_fidx - sp->ts_splitfidx)) == 0) { preword[sp->ts_prewordlen] = NUL; - newscore = score_wordcount_adj(slang, sp->ts_score, - preword + sp->ts_prewordlen, - sp->ts_prewordlen > 0); + int newscore = score_wordcount_adj(slang, sp->ts_score, + preword + sp->ts_prewordlen, + sp->ts_prewordlen > 0); // Add the suggestion if the score isn't too bad. if (newscore <= su->su_maxscore) { add_suggestion(su, &su->su_ga, preword, @@ -1448,7 +1435,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun } } - newscore = 0; + int newscore = 0; if (!soundfold) { // soundfold words don't have flags if ((flags & WF_REGION) && (((unsigned)flags >> 16) & (unsigned)lp->lp_region) == 0) { @@ -1499,10 +1486,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun } // Give a bonus to words seen before. - score = score_wordcount_adj(slang, - sp->ts_score + newscore, - preword + sp->ts_prewordlen, - sp->ts_prewordlen > 0); + int score = score_wordcount_adj(slang, + sp->ts_score + newscore, + preword + sp->ts_prewordlen, + sp->ts_prewordlen > 0); // Add the suggestion if the score isn't too bad. if (score <= su->su_maxscore) { @@ -2260,7 +2247,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun gap = &lp->lp_replang->sl_rep; } while (sp->ts_curi < gap->ga_len) { - ftp = (fromto_T *)gap->ga_data + sp->ts_curi++; + fromto_T *ftp = (fromto_T *)gap->ga_data + sp->ts_curi++; if (*ftp->ft_from != *p) { // past possible matching entries sp->ts_curi = (int16_t)gap->ga_len; @@ -2308,7 +2295,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun } else { gap = &lp->lp_replang->sl_rep; } - ftp = (fromto_T *)gap->ga_data + sp->ts_curi - 1; + fromto_T *ftp = (fromto_T *)gap->ga_data + sp->ts_curi - 1; fl = (int)strlen(ftp->ft_from); tl = (int)strlen(ftp->ft_to); p = fword + sp->ts_fidx; @@ -2369,11 +2356,7 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword) int uwordidx[MAXWLEN]; int kwordlen[MAXWLEN]; - int flen, ulen; int l; - int len; - int c; - idx_T lo, hi, m; char *p; uint8_t *byts = slang->sl_kbyts; // array with bytes of the words idx_T *idxs = slang->sl_kidxs; // array with indexes @@ -2414,8 +2397,8 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword) } else { // round[depth] == 1: Try using the folded-case character. // round[depth] == 2: Try using the upper-case character. - flen = utf_ptr2len(fword + fwordidx[depth]); - ulen = utf_ptr2len(uword + uwordidx[depth]); + int flen = utf_ptr2len(fword + fwordidx[depth]); + int ulen = utf_ptr2len(uword + uwordidx[depth]); if (round[depth] == 1) { p = fword + fwordidx[depth]; l = flen; @@ -2426,12 +2409,12 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword) for (tryidx = arridx[depth]; l > 0; l--) { // Perform a binary search in the list of accepted bytes. - len = byts[tryidx++]; - c = (uint8_t)(*p++); - lo = tryidx; - hi = tryidx + len - 1; + int len = byts[tryidx++]; + int c = (uint8_t)(*p++); + idx_T lo = tryidx; + idx_T hi = tryidx + len - 1; while (lo < hi) { - m = (lo + hi) / 2; + idx_T m = (lo + hi) / 2; if (byts[m] > c) { hi = m - 1; } else if (byts[m] < c) { @@ -2483,30 +2466,26 @@ static void find_keepcap_word(slang_T *slang, char *fword, char *kword) /// su->su_sga. static void score_comp_sal(suginfo_T *su) { - langp_T *lp; char badsound[MAXWLEN]; - suggest_T *stp; - suggest_T *sstp; - int score; ga_grow(&su->su_sga, su->su_ga.ga_len); // Use the sound-folding of the first language that supports it. for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; lpi++) { - lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); + langp_T *lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); if (!GA_EMPTY(&lp->lp_slang->sl_sal)) { // soundfold the bad word spell_soundfold(lp->lp_slang, su->su_fbadword, true, badsound); for (int i = 0; i < su->su_ga.ga_len; i++) { - stp = &SUG(su->su_ga, i); + suggest_T *stp = &SUG(su->su_ga, i); // Case-fold the suggested word, sound-fold it and compute the // sound-a-like score. - score = stp_sal_score(stp, su, lp->lp_slang, badsound); + int score = stp_sal_score(stp, su, lp->lp_slang, badsound); if (score < SCORE_MAXMAX) { // Add the suggestion. - sstp = &SUG(su->su_sga, su->su_sga.ga_len); + suggest_T *sstp = &SUG(su->su_sga, su->su_sga.ga_len); sstp->st_word = xstrdup(stp->st_word); sstp->st_wordlen = stp->st_wordlen; sstp->st_score = score; @@ -2525,24 +2504,20 @@ static void score_comp_sal(suginfo_T *su) static void score_combine(suginfo_T *su) { garray_T ga; - garray_T *gap; - langp_T *lp; - suggest_T *stp; char *p; char badsound[MAXWLEN]; - int round; slang_T *slang = NULL; // Add the alternate score to su_ga. for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; lpi++) { - lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); + langp_T *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 (int i = 0; i < su->su_ga.ga_len; i++) { - stp = &SUG(su->su_ga, i); + suggest_T *stp = &SUG(su->su_ga, i); stp->st_altscore = stp_sal_score(stp, su, slang, badsound); if (stp->st_altscore == SCORE_MAXMAX) { stp->st_score = (stp->st_score * 3 + SCORE_BIG) / 4; @@ -2563,7 +2538,7 @@ static void score_combine(suginfo_T *su) // Add the alternate score to su_sga. for (int i = 0; i < su->su_sga.ga_len; i++) { - stp = &SUG(su->su_sga, i); + suggest_T *stp = &SUG(su->su_sga, i); stp->st_altscore = spell_edit_score(slang, su->su_badword, stp->st_word); if (stp->st_score == SCORE_MAXMAX) { stp->st_score = (SCORE_BIG * 7 + stp->st_altscore) / 8; @@ -2583,12 +2558,12 @@ static void score_combine(suginfo_T *su) ga_init(&ga, (int)sizeof(suginfo_T), 1); ga_grow(&ga, su->su_ga.ga_len + su->su_sga.ga_len); - stp = &SUG(ga, 0); + suggest_T *stp = &SUG(ga, 0); 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++) { - gap = round == 1 ? &su->su_ga : &su->su_sga; + for (int round = 1; round <= 2; round++) { + garray_T *gap = round == 1 ? &su->su_ga : &su->su_sga; if (i < gap->ga_len) { // Don't add a word if it's already there. p = SUG(*gap, i).st_word; @@ -2687,14 +2662,11 @@ static sftword_T dumsft; /// Prepare for calling suggest_try_soundalike(). static void suggest_try_soundalike_prep(void) { - langp_T *lp; - slang_T *slang; - // Do this for all languages that support sound folding and for which a // .sug file has been loaded. 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; + langp_T *lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); + slang_T *slang = lp->lp_slang; if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) { // prepare the hashtable used by add_sound_suggest() hash_init(&slang->sl_sounddone); @@ -2707,14 +2679,12 @@ static void suggest_try_soundalike_prep(void) static void suggest_try_soundalike(suginfo_T *su) { char salword[MAXWLEN]; - langp_T *lp; - slang_T *slang; // Do this for all languages that support sound folding and for which a // .sug file has been loaded. 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; + langp_T *lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); + slang_T *slang = lp->lp_slang; if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) { // soundfold the bad word spell_soundfold(slang, su->su_fbadword, true, salword); @@ -2736,20 +2706,15 @@ static void suggest_try_soundalike(suginfo_T *su) /// Finish up after calling suggest_try_soundalike(). static void suggest_try_soundalike_finish(void) { - langp_T *lp; - 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 (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; + langp_T *lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); + slang_T *slang = lp->lp_slang; if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) { // Free the info about handled words. - todo = (int)slang->sl_sounddone.ht_used; - for (hi = slang->sl_sounddone.ht_array; todo > 0; hi++) { + int todo = (int)slang->sl_sounddone.ht_used; + for (hashitem_T *hi = slang->sl_sounddone.ht_array; todo > 0; hi++) { if (!HASHITEM_EMPTY(hi)) { xfree(HI2SFT(hi)); todo--; @@ -2774,14 +2739,9 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T int i; int wlen; uint8_t *byts; - idx_T *idxs; - int n; - int wordcount; int wc; int goodscore; sftword_T *sft; - int bc, gc; - int limit; // It's very well possible that the same soundfold word is found several // times with different scores. Since the following is quite slow only do @@ -2819,11 +2779,11 @@ static void add_sound_suggest(suginfo_T *su, char *goodword, int score, langp_T orgnr += bytes2offset(&nrline); byts = slang->sl_fbyts; - idxs = slang->sl_fidxs; + idx_T *idxs = slang->sl_fidxs; // Lookup the word "orgnr" one of the two tries. - n = 0; - wordcount = 0; + int n = 0; + int wordcount = 0; for (wlen = 0; wlen < MAXWLEN - 3; wlen++) { i = 1; if (wordcount == orgnr && byts[n + 1] == NUL) { @@ -2903,9 +2863,9 @@ badword: // lower to upper case. Helps for "tath" -> "Kath", which is // less common than "tath" -> "path". Don't do it when the // letter is the same, that has already been counted. - gc = utf_ptr2char(p); + int gc = utf_ptr2char(p); if (SPELL_ISUPPER(gc)) { - bc = utf_ptr2char(su->su_badword); + int bc = utf_ptr2char(su->su_badword); if (!SPELL_ISUPPER(bc) && SPELL_TOFOLD(bc) != SPELL_TOFOLD(gc)) { goodscore += SCORE_ICASE / 2; @@ -2919,7 +2879,7 @@ badword: // MAXSCORE(), because RESCORE() will change the score. // If the limit is very high then the iterative method is // inefficient, using an array is quicker. - limit = MAXSCORE(su->su_sfmaxscore - goodscore, score); + int limit = MAXSCORE(su->su_sfmaxscore - goodscore, score); if (limit > SCORE_LIMITMAX) { goodscore += spell_edit_score(slang, su->su_badword, p); } else { @@ -3020,11 +2980,10 @@ static bool similar_chars(slang_T *slang, int c1, int c2) { int m1, m2; char buf[MB_MAXCHAR + 1]; - hashitem_T *hi; if (c1 >= 256) { buf[utf_char2bytes(c1, buf)] = 0; - hi = hash_find(&slang->sl_map_hash, buf); + hashitem_T *hi = hash_find(&slang->sl_map_hash, buf); if (HASHITEM_EMPTY(hi)) { m1 = 0; } else { @@ -3039,7 +2998,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2) if (c2 >= 256) { buf[utf_char2bytes(c2, buf)] = 0; - hi = hash_find(&slang->sl_map_hash, buf); + hashitem_T *hi = hash_find(&slang->sl_map_hash, buf); if (HASHITEM_EMPTY(hi)) { m2 = 0; } else { @@ -3065,7 +3024,6 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i { int goodlen; // len of goodword changed int badlen; // len of bad word changed - suggest_T *stp; suggest_T new_sug; // Minimize "badlen" for consistency. Avoids that changing "the the" to @@ -3098,7 +3056,7 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i // Check if the word is already there. Also check the length that is // being replaced "thes," -> "these" is a different suggestion from // "thes" -> "these". - stp = &SUG(*gap, 0); + suggest_T *stp = &SUG(*gap, 0); for (i = gap->ga_len; --i >= 0; stp++) { if (stp->st_wordlen == goodlen && stp->st_orglen == badlen @@ -3142,7 +3100,7 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i if (i < 0) { // Add a suggestion. - stp = GA_APPEND_VIA_PTR(suggest_T, gap); + suggest_T *stp = GA_APPEND_VIA_PTR(suggest_T, gap); stp->st_word = xmemdupz(goodword, (size_t)goodlen); stp->st_wordlen = goodlen; stp->st_score = score; @@ -3172,7 +3130,6 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i static void check_suggestions(suginfo_T *su, garray_T *gap) { char longword[MAXWLEN + 1]; - hlf_T attr; if (gap->ga_len == 0) { return; @@ -3184,7 +3141,7 @@ static void check_suggestions(suginfo_T *su, garray_T *gap) int len = stp[i].st_wordlen; xstrlcpy(longword + len, su->su_badptr + stp[i].st_orglen, (size_t)(MAXWLEN - len + 1)); - attr = HLF_COUNT; + hlf_T attr = HLF_COUNT; (void)spell_check(curwin, longword, &attr, NULL, false); if (attr != HLF_COUNT) { // Remove this entry. @@ -3526,11 +3483,6 @@ static int soundalike_score(char *goodstart, char *badstart) /// support multi-byte characters. static int spell_edit_score(slang_T *slang, const char *badword, const char *goodword) { - int *cnt; - int j, i; - int t; - int bc, gc; - int pbc, pgc; int wbadword[MAXWLEN]; int wgoodword[MAXWLEN]; @@ -3554,18 +3506,18 @@ static int spell_edit_score(slang_T *slang, const char *badword, const char *goo // We use "cnt" as an array: CNT(badword_idx, goodword_idx). #define CNT(a, b) cnt[(a) + (b) * (badlen + 1)] - cnt = xmalloc(sizeof(int) * ((size_t)badlen + 1) * ((size_t)goodlen + 1)); + int *cnt = xmalloc(sizeof(int) * ((size_t)badlen + 1) * ((size_t)goodlen + 1)); CNT(0, 0) = 0; - for (j = 1; j <= goodlen; j++) { + for (int j = 1; j <= goodlen; j++) { CNT(0, j) = CNT(0, j - 1) + SCORE_INS; } - for (i = 1; i <= badlen; i++) { + for (int i = 1; i <= badlen; i++) { CNT(i, 0) = CNT(i - 1, 0) + SCORE_DEL; - for (j = 1; j <= goodlen; j++) { - bc = wbadword[i - 1]; - gc = wgoodword[j - 1]; + for (int j = 1; j <= goodlen; j++) { + int bc = wbadword[i - 1]; + int gc = wgoodword[j - 1]; if (bc == gc) { CNT(i, j) = CNT(i - 1, j - 1); } else { @@ -3584,16 +3536,16 @@ static int spell_edit_score(slang_T *slang, const char *badword, const char *goo } if (i > 1 && j > 1) { - pbc = wbadword[i - 2]; - pgc = wgoodword[j - 2]; + int pbc = wbadword[i - 2]; + int pgc = wgoodword[j - 2]; if (bc == pgc && pbc == gc) { - t = SCORE_SWAP + CNT(i - 2, j - 2); + int t = SCORE_SWAP + CNT(i - 2, j - 2); if (t < CNT(i, j)) { CNT(i, j) = t; } } } - t = SCORE_DEL + CNT(i - 1, j); + int t = SCORE_DEL + CNT(i - 1, j); if (t < CNT(i, j)) { CNT(i, j) = t; } @@ -3605,7 +3557,7 @@ static int spell_edit_score(slang_T *slang, const char *badword, const char *goo } } - i = CNT(badlen - 1, goodlen - 1); + int i = CNT(badlen - 1, goodlen - 1); xfree(cnt); return i; } @@ -3633,10 +3585,8 @@ static int spell_edit_score_limit_w(slang_T *slang, const char *badword, const c int limit) { limitscore_T stack[10]; // allow for over 3 * 2 edits - int bi2, gi2; int bc, gc; int score_off; - int round; int wbadword[MAXWLEN]; int wgoodword[MAXWLEN]; @@ -3704,15 +3654,15 @@ static int spell_edit_score_limit_w(slang_T *slang, const char *badword, const c // that may lead to a lower score than "minscore". // round 0: try deleting a char from badword // round 1: try inserting a char in badword - for (round = 0; round <= 1; round++) { + for (int round = 0; round <= 1; round++) { score_off = score + (round == 0 ? SCORE_DEL : SCORE_INS); if (score_off < minscore) { if (score_off + SCORE_EDIT_MIN >= minscore) { // Near the limit, rest of the words must match. We // can check that right now, no need to push an item // onto the stack. - bi2 = bi + 1 - round; - gi2 = gi + round; + int bi2 = bi + 1 - round; + int gi2 = gi + round; while (wgoodword[gi2] == wbadword[bi2]) { if (wgoodword[gi2] == NUL) { minscore = score_off; -- cgit From 6361806aa28edca55ad3316a58bc3e936df9c0eb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 26 Nov 2023 22:58:52 +0800 Subject: refactor: move garray_T to garray_defs.h (#26227) --- src/nvim/spellsuggest.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 62508852b3..48c7c7e4a8 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -18,6 +18,7 @@ #include "nvim/eval/typval.h" #include "nvim/fileio.h" #include "nvim/garray.h" +#include "nvim/garray_defs.h" #include "nvim/getchar.h" #include "nvim/gettext.h" #include "nvim/globals.h" -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/spellsuggest.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 48c7c7e4a8..98feb6e5d3 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -17,6 +17,7 @@ #include "nvim/eval.h" #include "nvim/eval/typval.h" #include "nvim/fileio.h" +#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/garray_defs.h" #include "nvim/getchar.h" -- cgit From f4aedbae4cb1f206f5b7c6142697b71dd473059b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:39:38 +0100 Subject: build(IWYU): fix includes for undo_defs.h --- src/nvim/spellsuggest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 98feb6e5d3..589f828c46 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -37,7 +37,7 @@ #include "nvim/os/fs.h" #include "nvim/os/input.h" #include "nvim/os/os_defs.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/profile.h" #include "nvim/spell.h" #include "nvim/spellfile.h" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/spellsuggest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 589f828c46..1852f75432 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -43,7 +43,7 @@ #include "nvim/spellfile.h" #include "nvim/spellsuggest.h" #include "nvim/strings.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/vim.h" -- cgit From 1a8f60c7d2699826b51f23b040b83b1d96a14930 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 28 Nov 2023 10:47:22 +0800 Subject: refactor: move hashtab types to hashtab_defs.h (#26262) --- src/nvim/spellsuggest.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 1852f75432..af9f4db45a 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -3141,8 +3141,7 @@ static void check_suggestions(suginfo_T *su, garray_T *gap) // Need to append what follows to check for "the the". xstrlcpy(longword, stp[i].st_word, MAXWLEN + 1); int len = stp[i].st_wordlen; - xstrlcpy(longword + len, su->su_badptr + stp[i].st_orglen, - (size_t)(MAXWLEN - len + 1)); + xstrlcpy(longword + len, su->su_badptr + stp[i].st_orglen, MAXWLEN + 1 - (size_t)len); hlf_T attr = HLF_COUNT; (void)spell_check(curwin, longword, &attr, NULL, false); if (attr != HLF_COUNT) { -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/spellsuggest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index af9f4db45a..0a48e613ed 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -9,7 +9,7 @@ #include #include -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/buffer_defs.h" #include "nvim/change.h" #include "nvim/charset.h" @@ -26,7 +26,7 @@ #include "nvim/hashtab.h" #include "nvim/highlight_defs.h" #include "nvim/input.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mbyte.h" #include "nvim/memline.h" #include "nvim/memory.h" @@ -46,7 +46,7 @@ #include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/undo.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" // Use this to adjust the score after finding suggestions, based on the // suggested word sounding like the bad word. This is much faster than doing -- cgit From 64b53b71ba5d804b2c8cf186be68931b2621f53c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 12:10:42 +0800 Subject: refactor(IWYU): create normal_defs.h (#26293) --- src/nvim/spellsuggest.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/spellsuggest.c') diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 0a48e613ed..d9dd28527e 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -36,7 +36,6 @@ #include "nvim/option_vars.h" #include "nvim/os/fs.h" #include "nvim/os/input.h" -#include "nvim/os/os_defs.h" #include "nvim/pos_defs.h" #include "nvim/profile.h" #include "nvim/spell.h" -- cgit