aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/spellsuggest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/spellsuggest.c')
-rw-r--r--src/nvim/spellsuggest.c273
1 files changed, 136 insertions, 137 deletions
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;