aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/spellfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/spellfile.c')
-rw-r--r--src/nvim/spellfile.c275
1 files changed, 135 insertions, 140 deletions
diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c
index be1373f617..0f8034312e 100644
--- a/src/nvim/spellfile.c
+++ b/src/nvim/spellfile.c
@@ -440,7 +440,7 @@ typedef struct spellinfo_S {
sblock_T *si_blocks; // memory blocks used
long si_blocks_cnt; // memory blocks allocated
- int si_did_emsg; // TRUE when ran out of memory
+ int si_did_emsg; // true when ran out of memory
long si_compress_cnt; // words to add before lowering
// compression limit
@@ -454,7 +454,7 @@ typedef struct spellinfo_S {
int si_ascii; // handling only ASCII words
int si_add; // addition file
- int si_clear_chartab; // when TRUE clear char tables
+ int si_clear_chartab; // when true clear char tables
int si_region; // region mask
vimconv_T si_conv; // for conversion to 'encoding'
int si_memtot; // runtime memory used
@@ -604,7 +604,7 @@ slang_T *spell_load_file(char_u *fname, char_u *lang, slang_T *old_lp, bool sile
lp = slang_alloc(lang);
// Remember the file name, used to reload the file when it's updated.
- lp->sl_fname = vim_strsave(fname);
+ lp->sl_fname = (char *)vim_strsave(fname);
// Check for .add.spl.
lp->sl_add = strstr(path_tail((char *)fname), SPL_FNAME_ADD) != NULL;
@@ -845,12 +845,12 @@ static void tree_count_words(char_u *byts, idx_T *idxs)
} else {
// Do one more byte at this node.
n = arridx[depth] + curi[depth];
- ++curi[depth];
+ curi[depth]++;
c = byts[n];
if (c == 0) {
// End of word, count it.
- ++wordcount[depth];
+ wordcount[depth]++;
// Skip over any other NUL bytes (same word with different
// flags).
@@ -869,12 +869,12 @@ static void tree_count_words(char_u *byts, idx_T *idxs)
}
}
-// Load the .sug files for languages that have one and weren't loaded yet.
+/// Load the .sug files for languages that have one and weren't loaded yet.
void suggest_load_files(void)
{
langp_T *lp;
slang_T *slang;
- char_u *dotp;
+ char *dotp;
FILE *fd;
char_u buf[MAXWLEN];
int i;
@@ -885,7 +885,7 @@ void suggest_load_files(void)
int c;
// Do this for all languages that support sound folding.
- for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {
+ for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; lpi++) {
lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
slang = lp->lp_slang;
if (slang->sl_sugtime != 0 && !slang->sl_sugloaded) {
@@ -894,12 +894,12 @@ void suggest_load_files(void)
// don't try again and again.
slang->sl_sugloaded = true;
- dotp = STRRCHR(slang->sl_fname, '.');
+ dotp = strrchr(slang->sl_fname, '.');
if (dotp == NULL || FNAMECMP(dotp, ".spl") != 0) {
continue;
}
STRCPY(dotp, ".sug");
- fd = os_fopen((char *)slang->sl_fname, "r");
+ fd = os_fopen(slang->sl_fname, "r");
if (fd == NULL) {
goto nextone;
}
@@ -960,7 +960,7 @@ someerror:
// Read all the wordnr lists into the buffer, one NUL terminated
// list per line.
ga_init(&ga, 1, 100);
- for (wordnr = 0; wordnr < wcount; ++wordnr) {
+ for (wordnr = 0; wordnr < wcount; wordnr++) {
ga.ga_len = 0;
for (;;) {
c = getc(fd); // <sugline>
@@ -1142,10 +1142,10 @@ static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first)
}
// Fill the first-index table.
- for (int i = 0; i < 256; ++i) {
+ for (int i = 0; i < 256; i++) {
first[i] = -1;
}
- for (int i = 0; i < gap->ga_len; ++i) {
+ for (int i = 0; i < gap->ga_len; i++) {
ftp = &((fromto_T *)gap->ga_data)[i];
if (first[*ftp->ft_from] == -1) {
first[*ftp->ft_from] = (int16_t)i;
@@ -1200,7 +1200,7 @@ static int read_sal_section(FILE *fd, slang_T *slang)
// Read up to the first special char into sm_lead.
int i = 0;
- for (; i < ccnt; ++i) {
+ for (; i < ccnt; i++) {
c = getc(fd); // <salfrom>
if (vim_strchr("0123456789(-<^$", c) != NULL) {
break;
@@ -1213,7 +1213,7 @@ static int read_sal_section(FILE *fd, slang_T *slang)
// Put (abc) chars in sm_oneof, if any.
if (c == '(') {
smp->sm_oneof = p;
- for (++i; i < ccnt; ++i) {
+ for (++i; i < ccnt; i++) {
c = getc(fd); // <salfrom>
if (c == ')') {
break;
@@ -1299,7 +1299,7 @@ static int read_words_section(FILE *fd, slang_T *lp, int len)
while (done < len) {
// Read one word at a time.
- for (i = 0;; ++i) {
+ for (i = 0;; i++) {
c = getc(fd);
if (c == EOF) {
return SP_TRUNCERROR;
@@ -1597,7 +1597,7 @@ static void set_sal_first(slang_T *lp)
garray_T *gap = &lp->sl_sal;
sfirst = lp->sl_sal_first;
- for (int i = 0; i < 256; ++i) {
+ for (int i = 0; i < 256; i++) {
sfirst[i] = -1;
}
smp = (salitem_T *)gap->ga_data;
@@ -1732,7 +1732,7 @@ static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx
byts[idx++] = (char_u)len;
// Read the byte values, flag/region bytes and shared indexes.
- for (i = 1; i <= len; ++i) {
+ for (i = 1; i <= len; i++) {
c = getc(fd); // <byte>
if (c < 0) {
return SP_TRUNCERROR;
@@ -1795,7 +1795,7 @@ static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx
// Recursively read the children for non-shared siblings.
// Skip the end-of-word ones (zero byte value) and the shared ones (and
// remove SHARED_MASK)
- for (i = 1; i <= len; ++i) {
+ for (i = 1; i <= len; i++) {
if (byts[startidx + i] != 0) {
if (idxs[startidx + i] & SHARED_MASK) {
idxs[startidx + i] &= ~SHARED_MASK;
@@ -1822,13 +1822,13 @@ static void spell_reload_one(char_u *fname, bool added_word)
bool didit = false;
for (slang = first_lang; slang != NULL; slang = slang->sl_next) {
- if (path_full_compare((char *)fname, (char *)slang->sl_fname, false, true) == kEqualFiles) {
+ if (path_full_compare((char *)fname, slang->sl_fname, false, true) == kEqualFiles) {
slang_clear(slang);
if (spell_load_file(fname, NULL, slang, false) == NULL) {
// reloading failed, clear the language
slang_clear(slang);
}
- redraw_all_later(SOME_VALID);
+ redraw_all_later(UPD_SOME_VALID);
didit = true;
}
}
@@ -1863,7 +1863,7 @@ static long compress_added = 500000; // word count
// Sets "sps_flags".
int spell_check_msm(void)
{
- char *p = (char *)p_msm;
+ char *p = p_msm;
long start = 0;
long incr = 0;
long added = 0;
@@ -1924,7 +1924,7 @@ static void spell_clear_flags(wordnode_T *node)
wordnode_T *np;
for (np = node; np != NULL; np = np->wn_sibling) {
- np->wn_u1.index = FALSE;
+ np->wn_u1.index = false;
spell_clear_flags(np->wn_child);
}
}
@@ -1940,7 +1940,7 @@ static void spell_print_node(wordnode_T *node, int depth)
msg((char_u *)line2);
msg((char_u *)line3);
} else {
- node->wn_u1.index = TRUE;
+ node->wn_u1.index = true;
if (node->wn_byte != NUL) {
if (node->wn_child != NULL) {
@@ -2042,7 +2042,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
}
vim_snprintf((char *)IObuff, IOSIZE, _("Reading affix file %s..."), fname);
- spell_message(spin, IObuff);
+ spell_message(spin, (char *)IObuff);
// Only do REP lines when not done in another .aff file already.
do_rep = GA_EMPTY(&spin->si_rep);
@@ -2075,7 +2075,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
// Convert from "SET" to 'encoding' when needed.
xfree(pc);
if (spin->si_conv.vc_type != CONV_NONE) {
- pc = string_convert(&spin->si_conv, rline, NULL);
+ pc = (char_u *)string_convert(&spin->si_conv, (char *)rline, NULL);
if (pc == NULL) {
smsg(_("Conversion failure for word in %s line %d: %s"),
fname, lnum, rline);
@@ -2121,10 +2121,9 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
if (itemcnt > 0) {
if (is_aff_rule(items, itemcnt, "SET", 2) && aff->af_enc == NULL) {
// Setup for conversion from "ENC" to 'encoding'.
- aff->af_enc = enc_canonize(items[1]);
+ aff->af_enc = (char_u *)enc_canonize((char *)items[1]);
if (!spin->si_ascii
- && convert_setup(&spin->si_conv, aff->af_enc,
- p_enc) == FAIL) {
+ && convert_setup(&spin->si_conv, (char *)aff->af_enc, p_enc) == FAIL) {
smsg(_("Conversion in %s not supported: from %s to %s"),
fname, aff->af_enc, p_enc);
}
@@ -2168,9 +2167,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
STRCAT(p, " ");
STRCAT(p, items[1]);
spin->si_info = p;
- } else if (is_aff_rule(items, itemcnt, "MIDWORD", 2)
- && midword == NULL) {
- midword = getroom_save(spin, items[1]);
+ } else if (is_aff_rule(items, itemcnt, "MIDWORD", 2) && midword == NULL) {
+ midword = (char_u *)getroom_save(spin, items[1]);
} else if (is_aff_rule(items, itemcnt, "TRY", 2)) {
// ignored, we look in the tree for what chars may appear
}
@@ -2308,12 +2306,12 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
}
if (i >= gap->ga_len) {
ga_grow(gap, 2);
- ((char **)(gap->ga_data))[gap->ga_len++] = (char *)getroom_save(spin, items[1]);
- ((char **)(gap->ga_data))[gap->ga_len++] = (char *)getroom_save(spin, items[2]);
+ ((char **)(gap->ga_data))[gap->ga_len++] = getroom_save(spin, items[1]);
+ ((char **)(gap->ga_data))[gap->ga_len++] = getroom_save(spin, items[2]);
}
} else if (is_aff_rule(items, itemcnt, "SYLLABLE", 2)
&& syllable == NULL) {
- syllable = getroom_save(spin, items[1]);
+ syllable = (char_u *)getroom_save(spin, items[1]);
} else if (is_aff_rule(items, itemcnt, "NOBREAK", 1)) {
spin->si_nobreak = true;
} else if (is_aff_rule(items, itemcnt, "NOSPLITSUGS", 1)) {
@@ -2446,10 +2444,10 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
aff_entry = getroom(spin, sizeof(*aff_entry), true);
if (STRCMP(items[2], "0") != 0) {
- aff_entry->ae_chop = getroom_save(spin, items[2]);
+ aff_entry->ae_chop = (char_u *)getroom_save(spin, items[2]);
}
if (STRCMP(items[3], "0") != 0) {
- aff_entry->ae_add = getroom_save(spin, items[3]);
+ aff_entry->ae_add = (char_u *)getroom_save(spin, items[3]);
// Recognize flags on the affix: abcd/XYZ
aff_entry->ae_flags = (char_u *)vim_strchr((char *)aff_entry->ae_add, '/');
@@ -2469,7 +2467,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
if (STRCMP(items[4], ".") != 0) {
char_u buf[MAXLINELEN];
- aff_entry->ae_cond = getroom_save(spin, items[4]);
+ aff_entry->ae_cond = (char_u *)getroom_save(spin, items[4]);
if (*items[0] == 'P') {
sprintf((char *)buf, "^%s", items[4]);
} else {
@@ -2518,7 +2516,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
if (aff_entry->ae_cond != NULL) {
char_u buf[MAXLINELEN];
onecap_copy(items[4], buf, true);
- aff_entry->ae_cond = getroom_save(spin, buf);
+ aff_entry->ae_cond = (char_u *)getroom_save(spin, buf);
if (aff_entry->ae_cond != NULL) {
sprintf((char *)buf, "^%s",
aff_entry->ae_cond);
@@ -2548,7 +2546,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
idx = spin->si_prefcond.ga_len;
pp = GA_APPEND_VIA_PTR(char_u *, &spin->si_prefcond);
*pp = (aff_entry->ae_cond == NULL) ?
- NULL : getroom_save(spin, aff_entry->ae_cond);
+ NULL : (char_u *)getroom_save(spin, aff_entry->ae_cond);
}
// Add the prefix to the prefix tree.
@@ -2580,7 +2578,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
// Didn't actually use ah_newID, backup si_newprefID.
if (aff_todo == 0 && !did_postpone_prefix) {
- --spin->si_newprefID;
+ spin->si_newprefID--;
cur_aff->ah_newID = 0;
}
}
@@ -2674,10 +2672,10 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
}
} else if (is_aff_rule(items, itemcnt, "SOFOFROM", 2)
&& sofofrom == NULL) {
- sofofrom = getroom_save(spin, items[1]);
+ sofofrom = (char_u *)getroom_save(spin, items[1]);
} else if (is_aff_rule(items, itemcnt, "SOFOTO", 2)
&& sofoto == NULL) {
- sofoto = getroom_save(spin, items[1]);
+ sofoto = (char_u *)getroom_save(spin, items[1]);
} else if (STRCMP(items[0], "COMMON") == 0) {
int i;
@@ -3043,9 +3041,9 @@ static void add_fromto(spellinfo_T *spin, garray_T *gap, char_u *from, char_u *t
fromto_T *ftp = GA_APPEND_VIA_PTR(fromto_T, gap);
(void)spell_casefold(curwin, from, (int)STRLEN(from), word, MAXWLEN);
- ftp->ft_from = getroom_save(spin, word);
+ ftp->ft_from = (char_u *)getroom_save(spin, word);
(void)spell_casefold(curwin, to, (int)STRLEN(to), word, MAXWLEN);
- ftp->ft_to = getroom_save(spin, word);
+ ftp->ft_to = (char_u *)getroom_save(spin, word);
}
// Converts a boolean argument in a SAL line to true or false;
@@ -3068,7 +3066,7 @@ static void spell_free_aff(afffile_T *aff)
// All this trouble to free the "ae_prog" items...
for (ht = &aff->af_pref;; ht = &aff->af_suff) {
todo = (int)ht->ht_used;
- for (hi = ht->ht_array; todo > 0; ++hi) {
+ for (hi = ht->ht_array; todo > 0; hi++) {
if (!HASHITEM_EMPTY(hi)) {
todo--;
ah = HI2AH(hi);
@@ -3125,7 +3123,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile)
vim_snprintf((char *)IObuff, IOSIZE,
_("Reading dictionary file %s..."), fname);
- spell_message(spin, IObuff);
+ spell_message(spin, (char *)IObuff);
// start with a message for the first line
spin->si_msg_count = 999999;
@@ -3157,7 +3155,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile)
// Convert from "SET" to 'encoding' when needed.
if (spin->si_conv.vc_type != CONV_NONE) {
- pc = string_convert(&spin->si_conv, line, NULL);
+ pc = (char_u *)string_convert(&spin->si_conv, (char *)line, NULL);
if (pc == NULL) {
smsg(_("Conversion failure for word in %s line %d: %s"),
fname, lnum, line);
@@ -3208,7 +3206,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile)
}
// Store the word in the hashtable to be able to find duplicates.
- dw = getroom_save(spin, w);
+ dw = (char_u *)getroom_save(spin, w);
if (dw == NULL) {
retval = FAIL;
xfree(pc);
@@ -3434,7 +3432,7 @@ static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, afff
int use_condit;
todo = (int)ht->ht_used;
- for (hi = ht->ht_array; todo > 0 && retval == OK; ++hi) {
+ for (hi = ht->ht_array; todo > 0 && retval == OK; hi++) {
if (!HASHITEM_EMPTY(hi)) {
todo--;
ah = HI2AH(hi);
@@ -3540,8 +3538,8 @@ static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, afff
// Combine the prefix IDs. Avoid adding the
// same ID twice.
- for (i = 0; i < pfxlen; ++i) {
- for (j = 0; j < use_pfxlen; ++j) {
+ for (i = 0; i < pfxlen; i++) {
+ for (j = 0; j < use_pfxlen; j++) {
if (pfxlist[i] == use_pfxlist[j]) {
break;
}
@@ -3562,9 +3560,8 @@ static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, afff
// Combine the list of compound flags.
// Concatenate them to the prefix IDs list.
// Avoid adding the same ID twice.
- for (i = pfxlen; pfxlist[i] != NUL; ++i) {
- for (j = use_pfxlen;
- use_pfxlist[j] != NUL; ++j) {
+ for (i = pfxlen; pfxlist[i] != NUL; i++) {
+ for (j = use_pfxlen; use_pfxlist[j] != NUL; j++) {
if (pfxlist[i] == use_pfxlist[j]) {
break;
}
@@ -3679,7 +3676,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname)
}
vim_snprintf((char *)IObuff, IOSIZE, _("Reading word file %s..."), fname);
- spell_message(spin, IObuff);
+ spell_message(spin, (char *)IObuff);
// Read all the lines in the file one by one.
while (!vim_fgets(rline, MAXLINELEN, fd) && !got_int) {
@@ -3704,7 +3701,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname)
// Convert from "/encoding={encoding}" to 'encoding' when needed.
xfree(pc);
if (spin->si_conv.vc_type != CONV_NONE) {
- pc = string_convert(&spin->si_conv, rline, NULL);
+ pc = (char_u *)string_convert(&spin->si_conv, (char *)rline, NULL);
if (pc == NULL) {
smsg(_("Conversion failure for word in %s line %ld: %s"),
fname, lnum, rline);
@@ -3726,14 +3723,13 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname)
smsg(_("/encoding= line after word ignored in %s line %ld: %s"),
fname, lnum, line - 1);
} else {
- char_u *enc;
+ char *enc;
// Setup for conversion to 'encoding'.
line += 9;
- enc = enc_canonize(line);
+ enc = enc_canonize((char *)line);
if (!spin->si_ascii
- && convert_setup(&spin->si_conv, enc,
- p_enc) == FAIL) {
+ && convert_setup(&spin->si_conv, enc, p_enc) == FAIL) {
smsg(_("Conversion in %s not supported: from %s to %s"),
fname, line, p_enc);
}
@@ -3824,7 +3820,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname)
if (spin->si_ascii && non_ascii > 0) {
vim_snprintf((char *)IObuff, IOSIZE,
_("Ignored %d words with non-ASCII characters"), non_ascii);
- spell_message(spin, IObuff);
+ spell_message(spin, (char *)IObuff);
}
return retval;
@@ -3858,7 +3854,7 @@ static void *getroom(spellinfo_T *spin, size_t len, bool align)
bl->sb_next = spin->si_blocks;
spin->si_blocks = bl;
bl->sb_used = 0;
- ++spin->si_blocks_cnt;
+ spin->si_blocks_cnt++;
}
p = bl->sb_data + bl->sb_used;
@@ -3867,9 +3863,10 @@ static void *getroom(spellinfo_T *spin, size_t len, bool align)
return p;
}
-// Make a copy of a string into memory allocated with getroom().
-// Returns NULL when out of memory.
-static char_u *getroom_save(spellinfo_T *spin, char_u *s)
+/// Make a copy of a string into memory allocated with getroom().
+///
+/// @return NULL when out of memory.
+static char *getroom_save(spellinfo_T *spin, char_u *s)
{
const size_t s_size = STRLEN(s) + 1;
return memcpy(getroom(spin, s_size, false), s, s_size);
@@ -3897,13 +3894,13 @@ static wordnode_T *wordtree_alloc(spellinfo_T *spin)
/// Return true if "word" contains valid word characters.
/// Control characters and trailing '/' are invalid. Space is OK.
-static bool valid_spell_word(const char_u *word, const char_u *end)
+static bool valid_spell_word(const char *word, const char *end)
{
- if (!utf_valid_string(word, end)) {
+ if (!utf_valid_string((char_u *)word, (char_u *)end)) {
return false;
}
- for (const char_u *p = word; *p != NUL && p < end; p += utfc_ptr2len((const char *)p)) {
- if (*p < ' ' || (p[0] == '/' && p[1] == NUL)) {
+ for (const char *p = word; *p != NUL && p < end; p += utfc_ptr2len(p)) {
+ if ((uint8_t)(*p) < ' ' || (p[0] == '/' && p[1] == NUL)) {
return false;
}
}
@@ -3931,7 +3928,7 @@ static int store_word(spellinfo_T *spin, char_u *word, int flags, int region, co
int res = OK;
// Avoid adding illegal bytes to the word tree.
- if (!valid_spell_word(word, word + len)) {
+ if (!valid_spell_word((char *)word, (char *)word + len)) {
return FAIL;
}
@@ -3945,7 +3942,7 @@ static int store_word(spellinfo_T *spin, char_u *word, int flags, int region, co
break;
}
}
- ++spin->si_foldwcount;
+ spin->si_foldwcount++;
if (res == OK && (ct == WF_KEEPCAP || (flags & WF_KEEPCAP))) {
for (const char_u *p = pfxlist; res == OK; p++) {
@@ -3957,7 +3954,7 @@ static int store_word(spellinfo_T *spin, char_u *word, int flags, int region, co
break;
}
}
- ++spin->si_keepwcount;
+ spin->si_keepwcount++;
}
return res;
}
@@ -3976,12 +3973,12 @@ static int tree_add_word(spellinfo_T *spin, char_u *word, wordnode_T *root, int
int i;
// Add each byte of the word to the tree, including the NUL at the end.
- for (i = 0;; ++i) {
+ for (i = 0;; i++) {
// When there is more than one reference to this node we need to make
// a copy, so that we can modify it. Copy the whole list of siblings
// (we don't optimize for a partly shared list of siblings).
if (node != NULL && node->wn_refs > 1) {
- --node->wn_refs;
+ node->wn_refs--;
copyprev = prev;
for (copyp = node; copyp != NULL; copyp = copyp->wn_sibling) {
// Allocate a new node and copy the info.
@@ -3991,7 +3988,7 @@ static int tree_add_word(spellinfo_T *spin, char_u *word, wordnode_T *root, int
}
np->wn_child = copyp->wn_child;
if (np->wn_child != NULL) {
- ++np->wn_child->wn_refs; // child gets extra ref
+ np->wn_child->wn_refs++; // child gets extra ref
}
np->wn_byte = copyp->wn_byte;
if (np->wn_byte == NUL) {
@@ -4078,7 +4075,7 @@ static int tree_add_word(spellinfo_T *spin, char_u *word, wordnode_T *root, int
#endif
// count nr of words added since last message
- ++spin->si_msg_count;
+ spin->si_msg_count++;
if (spin->si_compress_cnt > 1) {
if (--spin->si_compress_cnt == 1) {
@@ -4173,7 +4170,7 @@ static int deref_wordnode(spellinfo_T *spin, wordnode_T *node)
free_wordnode(spin, np);
cnt++;
}
- ++cnt; // length field
+ cnt++; // length field
}
return cnt;
}
@@ -4185,7 +4182,7 @@ static void free_wordnode(spellinfo_T *spin, wordnode_T *n)
{
n->wn_child = spin->si_first_free;
spin->si_first_free = n;
- ++spin->si_free_count;
+ spin->si_free_count++;
}
// Compress a tree: find tails that are identical and can be shared.
@@ -4216,7 +4213,7 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *n
vim_snprintf((char *)IObuff, IOSIZE,
_("Compressed %s of %ld nodes; %ld (%ld%%) remaining"),
name, tot, tot - n, perc);
- spell_message(spin, IObuff);
+ spell_message(spin, (char *)IObuff);
}
#ifdef SPELL_PRINTTREE
spell_print_tree(root->wn_sibling);
@@ -4264,7 +4261,7 @@ static long node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, lo
// Found one! Now use that child in place of the
// current one. This means the current child and all
// its siblings is unlinked from the tree.
- ++tp->wn_refs;
+ tp->wn_refs++;
compressed += deref_wordnode(spin, child);
np->wn_child = tp;
break;
@@ -4350,14 +4347,15 @@ static int rep_compare(const void *s1, const void *s2)
return STRCMP(p1->ft_from, p2->ft_from);
}
-// Write the Vim .spl file "fname".
-// Return OK/FAIL.
-static int write_vim_spell(spellinfo_T *spin, char_u *fname)
+/// Write the Vim .spl file "fname".
+///
+/// @return OK/FAIL.
+static int write_vim_spell(spellinfo_T *spin, char *fname)
{
int retval = OK;
int regionmask;
- FILE *fd = os_fopen((char *)fname, "w");
+ FILE *fd = os_fopen(fname, "w");
if (fd == NULL) {
semsg(_(e_notopen), fname);
return FAIL;
@@ -4422,7 +4420,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
put_bytes(fd, 1 + 128 + 2 + l, 4); // <sectionlen>
fputc(128, fd); // <charflagslen>
- for (size_t i = 128; i < 256; ++i) {
+ for (size_t i = 128; i < 256; i++) {
flags = 0;
if (spelltab.st_isw[i]) {
flags |= CF_WORD;
@@ -4466,7 +4464,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// round 1: SN_REP section
// round 2: SN_SAL section (unless SN_SOFO is used)
// round 3: SN_REPSAL section
- for (unsigned int round = 1; round <= 3; ++round) {
+ for (unsigned int round = 1; round <= 3; round++) {
garray_T *gap;
if (round == 1) {
gap = &spin->si_rep;
@@ -4500,13 +4498,13 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// Compute the length of what follows.
size_t l = 2; // count <repcount> or <salcount>
assert(gap->ga_len >= 0);
- for (size_t i = 0; i < (size_t)gap->ga_len; ++i) {
+ for (size_t i = 0; i < (size_t)gap->ga_len; i++) {
fromto_T *ftp = &((fromto_T *)gap->ga_data)[i];
l += 1 + STRLEN(ftp->ft_from); // count <*fromlen> and <*from>
l += 1 + STRLEN(ftp->ft_to); // count <*tolen> and <*to>
}
if (round == 2) {
- ++l; // count <salflags>
+ l++; // count <salflags>
}
put_bytes(fd, l, 4); // <sectionlen>
@@ -4525,11 +4523,11 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
}
put_bytes(fd, (uintmax_t)gap->ga_len, 2); // <repcount> or <salcount>
- for (size_t i = 0; i < (size_t)gap->ga_len; ++i) {
+ for (size_t i = 0; i < (size_t)gap->ga_len; i++) {
// <rep> : <repfromlen> <repfrom> <reptolen> <repto>
// <sal> : <salfromlen> <salfrom> <saltolen> <salto>
fromto_T *ftp = &((fromto_T *)gap->ga_data)[i];
- for (unsigned int rr = 1; rr <= 2; ++rr) {
+ for (unsigned int rr = 1; rr <= 2; rr++) {
char_u *p = rr == 1 ? ftp->ft_from : ftp->ft_to;
l = STRLEN(p);
assert(l < INT_MAX);
@@ -4566,13 +4564,13 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// round 1: count the bytes
// round 2: write the bytes
- for (unsigned int round = 1; round <= 2; ++round) {
+ for (unsigned int round = 1; round <= 2; round++) {
size_t todo;
size_t len = 0;
hashitem_T *hi;
todo = spin->si_commonwords.ht_used;
- for (hi = spin->si_commonwords.ht_array; todo > 0; ++hi) {
+ for (hi = spin->si_commonwords.ht_array; todo > 0; hi++) {
if (!HASHITEM_EMPTY(hi)) {
size_t l = STRLEN(hi->hi_key) + 1;
len += l;
@@ -4689,7 +4687,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// <LWORDTREE> <KWORDTREE> <PREFIXTREE>
spin->si_memtot = 0;
- for (unsigned int round = 1; round <= 3; ++round) {
+ for (unsigned int round = 1; round <= 3; round++) {
wordnode_T *tree;
if (round == 1) {
tree = spin->si_foldroot->wn_sibling;
@@ -4878,12 +4876,12 @@ void ex_mkspell(exarg_T *eap)
{
int fcount;
char **fnames;
- char_u *arg = (char_u *)eap->arg;
+ char *arg = eap->arg;
bool ascii = false;
if (STRNCMP(arg, "-ascii", 6) == 0) {
ascii = true;
- arg = (char_u *)skipwhite((char *)arg + 6);
+ arg = skipwhite(arg + 6);
}
// Expand all the remaining arguments (e.g., $VIMRUNTIME).
@@ -4896,7 +4894,7 @@ void ex_mkspell(exarg_T *eap)
// Create the .sug file.
// Uses the soundfold info in "spin".
// Writes the file with the name "wfname", with ".spl" changed to ".sug".
-static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname)
+static void spell_make_sugfile(spellinfo_T *spin, char *wfname)
{
char_u *fname = NULL;
int len;
@@ -4909,14 +4907,14 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname)
// of the code for the soundfolding stuff.
// It might have been done already by spell_reload_one().
for (slang = first_lang; slang != NULL; slang = slang->sl_next) {
- if (path_full_compare((char *)wfname, (char *)slang->sl_fname, false, true)
+ if (path_full_compare(wfname, slang->sl_fname, false, true)
== kEqualFiles) {
break;
}
}
if (slang == NULL) {
- spell_message(spin, (char_u *)_("Reading back spell file..."));
- slang = spell_load_file(wfname, NULL, NULL, false);
+ spell_message(spin, _("Reading back spell file..."));
+ slang = spell_load_file((char_u *)wfname, NULL, NULL, false);
if (slang == NULL) {
return;
}
@@ -4933,7 +4931,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname)
// Go through the trie of good words, soundfold each word and add it to
// the soundfold trie.
- spell_message(spin, (char_u *)_("Performing soundfolding..."));
+ spell_message(spin, _("Performing soundfolding..."));
if (sug_filltree(spin, slang) == FAIL) {
goto theend;
}
@@ -4950,7 +4948,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname)
(int64_t)spin->si_spellbuf->b_ml.ml_line_count);
// Compress the soundfold trie.
- spell_message(spin, (char_u *)_(msg_compressing));
+ spell_message(spin, _(msg_compressing));
wordtree_compress(spin, spin->si_foldroot, "case-folded");
// Write the .sug file.
@@ -5015,7 +5013,7 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang)
} else {
// Do one more byte at this node.
n = arridx[depth] + curi[depth];
- ++curi[depth];
+ curi[depth]++;
c = byts[n];
if (c == 0) {
@@ -5196,7 +5194,7 @@ static void sug_write(spellinfo_T *spin, char_u *fname)
vim_snprintf((char *)IObuff, IOSIZE,
_("Writing suggestion file %s..."), fname);
- spell_message(spin, IObuff);
+ spell_message(spin, (char *)IObuff);
// <SUGHEADER>: <fileID> <versionnr> <timestamp>
if (fwrite(VIMSUGMAGIC, VIMSUGMAGICL, (size_t)1, fd) != 1) { // <fileID>
@@ -5233,7 +5231,7 @@ static void sug_write(spellinfo_T *spin, char_u *fname)
assert(wcount >= 0);
put_bytes(fd, (uintmax_t)wcount, 4); // <sugwcount>
- for (linenr_T lnum = 1; lnum <= wcount; ++lnum) {
+ for (linenr_T lnum = 1; lnum <= wcount; lnum++) {
// <sugline>: <sugnr> ... NUL
char_u *line = ml_get_buf(spin->si_spellbuf, lnum, false);
size_t len = STRLEN(line) + 1;
@@ -5252,7 +5250,7 @@ static void sug_write(spellinfo_T *spin, char_u *fname)
vim_snprintf((char *)IObuff, IOSIZE,
_("Estimated runtime memory use: %d bytes"), spin->si_memtot);
- spell_message(spin, IObuff);
+ spell_message(spin, (char *)IObuff);
theend:
// close the file
@@ -5271,7 +5269,6 @@ theend:
static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool added_word)
{
char_u *fname = NULL;
- char_u *wfname;
char **innames;
int incount;
afffile_T *(afile[MAXREGIONS]);
@@ -5299,7 +5296,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool
innames = &fnames[fcount == 1 ? 0 : 1];
incount = fcount - 1;
- wfname = xmalloc(MAXPATHL);
+ char *wfname = xmalloc(MAXPATHL);
if (fcount >= 1) {
len = (int)STRLEN(fnames[0]);
@@ -5307,42 +5304,42 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool
// For ":mkspell path/en.latin1.add" output file is
// "path/en.latin1.add.spl".
incount = 1;
- vim_snprintf((char *)wfname, MAXPATHL, "%s.spl", fnames[0]);
+ vim_snprintf(wfname, MAXPATHL, "%s.spl", fnames[0]);
} else if (fcount == 1) {
// For ":mkspell path/vim" output file is "path/vim.latin1.spl".
incount = 1;
- vim_snprintf((char *)wfname, MAXPATHL, SPL_FNAME_TMPL,
+ vim_snprintf(wfname, MAXPATHL, SPL_FNAME_TMPL,
fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc());
} else if (len > 4 && STRCMP(fnames[0] + len - 4, ".spl") == 0) {
// Name ends in ".spl", use as the file name.
STRLCPY(wfname, fnames[0], MAXPATHL);
} else {
// Name should be language, make the file name from it.
- vim_snprintf((char *)wfname, MAXPATHL, SPL_FNAME_TMPL,
+ vim_snprintf(wfname, MAXPATHL, SPL_FNAME_TMPL,
fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc());
}
// Check for .ascii.spl.
- if (strstr(path_tail((char *)wfname), SPL_FNAME_ASCII) != NULL) {
+ if (strstr(path_tail(wfname), SPL_FNAME_ASCII) != NULL) {
spin.si_ascii = true;
}
// Check for .add.spl.
- if (strstr(path_tail((char *)wfname), SPL_FNAME_ADD) != NULL) {
+ if (strstr(path_tail(wfname), SPL_FNAME_ADD) != NULL) {
spin.si_add = true;
}
}
if (incount <= 0) {
emsg(_(e_invarg)); // need at least output and input names
- } else if (vim_strchr(path_tail((char *)wfname), '_') != NULL) {
+ } else if (vim_strchr(path_tail(wfname), '_') != NULL) {
emsg(_("E751: Output file name must not have region name"));
} else if (incount > MAXREGIONS) {
semsg(_("E754: Only up to %d regions supported"), MAXREGIONS);
} else {
// Check for overwriting before doing things that may take a lot of
// time.
- if (!over_write && os_path_exists(wfname)) {
+ if (!over_write && os_path_exists((char_u *)wfname)) {
emsg(_(e_exists));
goto theend;
}
@@ -5355,7 +5352,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool
// Init the aff and dic pointers.
// Get the region names if there are more than 2 arguments.
- for (i = 0; i < incount; ++i) {
+ for (i = 0; i < incount; i++) {
afile[i] = NULL;
if (incount > 1) {
@@ -5387,7 +5384,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool
// Read all the .aff and .dic files.
// Text is converted to 'encoding'.
// Words are stored in the case-folded and keep-case trees.
- for (i = 0; i < incount && !error; ++i) {
+ for (i = 0; i < incount && !error; i++) {
spin.si_conv.vc_type = CONV_NONE;
spin.si_region = 1 << i;
@@ -5424,7 +5421,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool
if (!error && !got_int) {
// Combine tails in the tree.
- spell_message(&spin, (char_u *)_(msg_compressing));
+ spell_message(&spin, _(msg_compressing));
wordtree_compress(&spin, spin.si_foldroot, "case-folded");
wordtree_compress(&spin, spin.si_keeproot, "keep-case");
wordtree_compress(&spin, spin.si_prefroot, "prefixes");
@@ -5434,18 +5431,18 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool
// Write the info in the spell file.
vim_snprintf((char *)IObuff, IOSIZE,
_("Writing spell file %s..."), wfname);
- spell_message(&spin, IObuff);
+ spell_message(&spin, (char *)IObuff);
error = write_vim_spell(&spin, wfname) == FAIL;
- spell_message(&spin, (char_u *)_("Done!"));
+ spell_message(&spin, _("Done!"));
vim_snprintf((char *)IObuff, IOSIZE,
_("Estimated runtime memory use: %d bytes"), spin.si_memtot);
- spell_message(&spin, IObuff);
+ spell_message(&spin, (char *)IObuff);
// If the file is loaded need to reload it.
if (!error) {
- spell_reload_one(wfname, added_word);
+ spell_reload_one((char_u *)wfname, added_word);
}
}
@@ -5459,7 +5456,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool
hash_clear_all(&spin.si_commonwords, 0);
// Free the .aff file structures.
- for (i = 0; i < incount; ++i) {
+ for (i = 0; i < incount; i++) {
if (afile[i] != NULL) {
spell_free_aff(afile[i]);
}
@@ -5482,14 +5479,14 @@ theend:
// Display a message for spell file processing when 'verbose' is set or using
// ":mkspell". "str" can be IObuff.
-static void spell_message(const spellinfo_T *spin, char_u *str)
+static void spell_message(const spellinfo_T *spin, char *str)
FUNC_ATTR_NONNULL_ALL
{
if (spin->si_verbose || p_verbose > 2) {
if (!spin->si_verbose) {
verbose_enter();
}
- msg((char *)str);
+ msg(str);
ui_flush();
if (!spin->si_verbose) {
verbose_leave();
@@ -5527,7 +5524,7 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo
int i;
char_u *spf;
- if (!valid_spell_word(word, word + len)) {
+ if (!valid_spell_word((char *)word, (char *)word + len)) {
emsg(_(e_illegal_character_in_word));
return;
}
@@ -5553,7 +5550,7 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo
}
fnamebuf = xmalloc(MAXPATHL);
- for (spf = curwin->w_s->b_p_spf, i = 1; *spf != NUL; i++) {
+ for (spf = (char_u *)curwin->w_s->b_p_spf, i = 1; *spf != NUL; i++) {
copy_option_part((char **)&spf, (char *)fnamebuf, MAXPATHL, ",");
if (i == idx) {
break;
@@ -5667,7 +5664,7 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo
buf_reload(buf, buf->b_orig_mode, false);
}
- redraw_all_later(SOME_VALID);
+ redraw_all_later(UPD_SOME_VALID);
}
xfree(fnamebuf);
}
@@ -5681,14 +5678,14 @@ static void init_spellfile(void)
char_u *rtp;
char_u *lend;
bool aspath = false;
- char_u *lstart = curbuf->b_s.b_p_spl;
+ char_u *lstart = (char_u *)curbuf->b_s.b_p_spl;
if (*curwin->w_s->b_p_spl != NUL && !GA_EMPTY(&curwin->w_s->b_langp)) {
buf = xmalloc(MAXPATHL);
// Find the end of the language name. Exclude the region. If there
// is a path separator remember the start of the tail.
- for (lend = curwin->w_s->b_p_spl; *lend != NUL
+ for (lend = (char_u *)curwin->w_s->b_p_spl; *lend != NUL
&& vim_strchr(",._", *lend) == NULL; lend++) {
if (vim_ispathsep(*lend)) {
aspath = true;
@@ -5698,13 +5695,12 @@ static void init_spellfile(void)
// Loop over all entries in 'runtimepath'. Use the first one where we
// are allowed to write.
- rtp = p_rtp;
+ rtp = (char_u *)p_rtp;
while (*rtp != NUL) {
if (aspath) {
// Use directory of an entry with path, e.g., for
// "/dir/lg.utf-8.spl" use "/dir".
- STRLCPY(buf, curbuf->b_s.b_p_spl,
- lstart - curbuf->b_s.b_p_spl);
+ STRLCPY(buf, curbuf->b_s.b_p_spl, lstart - (char_u *)curbuf->b_s.b_p_spl);
} else {
// Copy the path from 'runtimepath' to buf[].
copy_option_part((char **)&rtp, (char *)buf, MAXPATHL, ",");
@@ -5713,8 +5709,7 @@ static void init_spellfile(void)
// Use the first language name from 'spelllang' and the
// encoding used in the first loaded .spl file.
if (aspath) {
- STRLCPY(buf, curbuf->b_s.b_p_spl,
- lend - curbuf->b_s.b_p_spl + 1);
+ STRLCPY(buf, curbuf->b_s.b_p_spl, lend - (char_u *)curbuf->b_s.b_p_spl + 1);
} else {
// Create the "spell" directory if it doesn't exist yet.
l = (int)STRLEN(buf);
@@ -5728,14 +5723,14 @@ static void init_spellfile(void)
"/%.*s", (int)(lend - lstart), lstart);
}
l = (int)STRLEN(buf);
- fname = LANGP_ENTRY(curwin->w_s->b_langp, 0)
+ fname = (char_u *)LANGP_ENTRY(curwin->w_s->b_langp, 0)
->lp_slang->sl_fname;
vim_snprintf((char *)buf + l, MAXPATHL - (size_t)l, ".%s.add",
((fname != NULL
&& strstr(path_tail((char *)fname), ".ascii.") != NULL)
? "ascii"
: (const char *)spell_enc()));
- set_option_value("spellfile", 0L, (const char *)buf, OPT_LOCAL);
+ set_option_value_give_err("spellfile", 0L, (const char *)buf, OPT_LOCAL);
break;
}
aspath = false;
@@ -5759,7 +5754,7 @@ static void set_spell_charflags(char_u *flags, int cnt, char_u *fol)
clear_spell_chartab(&new_st);
- for (i = 0; i < 128; ++i) {
+ for (i = 0; i < 128; i++) {
if (i < cnt) {
new_st.st_isw[i + 128] = (flags[i] & CF_WORD) != 0;
new_st.st_isu[i + 128] = (flags[i] & CF_UPPER) != 0;
@@ -5783,7 +5778,7 @@ static int set_spell_finish(spelltab_T *new_st)
if (did_set_spelltab) {
// check that it's the same table
- for (i = 0; i < 256; ++i) {
+ for (i = 0; i < 256; i++) {
if (spelltab.st_isw[i] != new_st->st_isw[i]
|| spelltab.st_isu[i] != new_st->st_isu[i]
|| spelltab.st_fold[i] != new_st->st_fold[i]
@@ -5846,7 +5841,7 @@ static void set_map_str(slang_T *lp, char_u *map)
lp->sl_has_map = true;
// Init the array and hash tables empty.
- for (i = 0; i < 256; ++i) {
+ for (i = 0; i < 256; i++) {
lp->sl_map_array[i] = 0;
}
hash_init(&lp->sl_map_hash);