diff options
Diffstat (limited to 'src/nvim/spellfile.c')
-rw-r--r-- | src/nvim/spellfile.c | 1015 |
1 files changed, 513 insertions, 502 deletions
diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 611c43e85e..44414ca1a5 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -226,82 +226,101 @@ // stored as an offset to the previous number in as // few bytes as possible, see offset2bytes()) -#include <stdint.h> +#include <assert.h> +#include <ctype.h> +#include <inttypes.h> +#include <limits.h> +#include <stdbool.h> #include <stdio.h> -#include <wctype.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include "auto/config.h" #include "nvim/arglist.h" #include "nvim/ascii.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/drawscreen.h" -#include "nvim/ex_cmds2.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/fileio.h" +#include "nvim/garray.h" +#include "nvim/gettext.h" +#include "nvim/globals.h" +#include "nvim/hashtab.h" +#include "nvim/macros.h" +#include "nvim/mbyte.h" #include "nvim/memline.h" #include "nvim/memory.h" +#include "nvim/message.h" #include "nvim/option.h" #include "nvim/os/input.h" #include "nvim/os/os.h" +#include "nvim/os/time.h" #include "nvim/path.h" +#include "nvim/pos.h" #include "nvim/regexp.h" #include "nvim/runtime.h" #include "nvim/spell.h" #include "nvim/spell_defs.h" #include "nvim/spellfile.h" +#include "nvim/strings.h" +#include "nvim/types.h" #include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/vim.h" -#ifndef UNIX // it's in os/unix_defs.h for Unix -# include <time.h> // for time_t -#endif - // Special byte values for <byte>. Some are only used in the tree for // postponed prefixes, some only in the other trees. This is a bit messy... -#define BY_NOFLAGS 0 // end of word without flags or region; for - // postponed prefix: no <pflags> -#define BY_INDEX 1 // child is shared, index follows -#define BY_FLAGS 2 // end of word, <flags> byte follows; for - // postponed prefix: <pflags> follows -#define BY_FLAGS2 3 // end of word, <flags> and <flags2> bytes - // follow; never used in prefix tree -#define BY_SPECIAL BY_FLAGS2 // highest special byte value +enum { + BY_NOFLAGS = 0, // end of word without flags or region; for postponed prefix: no <pflags> + BY_INDEX = 1, // child is shared, index follows + BY_FLAGS = 2, // end of word, <flags> byte follows; for postponed prefix: <pflags> follows + BY_FLAGS2 = 3, // end of word, <flags> and <flags2> bytes follow; never used in prefix tree + BY_SPECIAL = BY_FLAGS2, // highest special byte value +}; #define ZERO_FLAG 65009 // used when flag is zero: "0" // Flags used in .spl file for soundsalike flags. -#define SAL_F0LLOWUP 1 -#define SAL_COLLAPSE 2 -#define SAL_REM_ACCENTS 4 +enum { + SAL_F0LLOWUP = 1, + SAL_COLLAPSE = 2, + SAL_REM_ACCENTS = 4, +}; #define VIMSPELLMAGIC "VIMspell" // string at start of Vim spell file #define VIMSPELLMAGICL (sizeof(VIMSPELLMAGIC) - 1) #define VIMSPELLVERSION 50 // Section IDs. Only renumber them when VIMSPELLVERSION changes! -#define SN_REGION 0 // <regionname> section -#define SN_CHARFLAGS 1 // charflags section -#define SN_MIDWORD 2 // <midword> section -#define SN_PREFCOND 3 // <prefcond> section -#define SN_REP 4 // REP items section -#define SN_SAL 5 // SAL items section -#define SN_SOFO 6 // soundfolding section -#define SN_MAP 7 // MAP items section -#define SN_COMPOUND 8 // compound words section -#define SN_SYLLABLE 9 // syllable section -#define SN_NOBREAK 10 // NOBREAK section -#define SN_SUGFILE 11 // timestamp for .sug file -#define SN_REPSAL 12 // REPSAL items section -#define SN_WORDS 13 // common words -#define SN_NOSPLITSUGS 14 // don't split word for suggestions -#define SN_INFO 15 // info section -#define SN_NOCOMPOUNDSUGS 16 // don't compound for suggestions -#define SN_END 255 // end of sections +enum { + SN_REGION = 0, // <regionname> section + SN_CHARFLAGS = 1, // charflags section + SN_MIDWORD = 2, // <midword> section + SN_PREFCOND = 3, // <prefcond> section + SN_REP = 4, // REP items section + SN_SAL = 5, // SAL items section + SN_SOFO = 6, // soundfolding section + SN_MAP = 7, // MAP items section + SN_COMPOUND = 8, // compound words section + SN_SYLLABLE = 9, // syllable section + SN_NOBREAK = 10, // NOBREAK section + SN_SUGFILE = 11, // timestamp for .sug file + SN_REPSAL = 12, // REPSAL items section + SN_WORDS = 13, // common words + SN_NOSPLITSUGS = 14, // don't split word for suggestions + SN_INFO = 15, // info section + SN_NOCOMPOUNDSUGS = 16, // don't compound for suggestions + SN_END = 255, // end of sections +}; #define SNF_REQUIRED 1 // <sectionflags>: required section -#define CF_WORD 0x01 -#define CF_UPPER 0x02 +enum { + CF_WORD = 0x01, + CF_UPPER = 0x02, +}; static char *e_spell_trunc = N_("E758: Truncated spell file"); static char *e_illegal_character_in_word = N_("E1280: Illegal character in word"); @@ -313,7 +332,7 @@ static char *msg_compressing = N_("Compressing word tree..."); // and .dic file. // Main structure to store the contents of a ".aff" file. typedef struct afffile_S { - char_u *af_enc; // "SET", normalized, alloc'ed string or NULL + char *af_enc; // "SET", normalized, alloc'ed string or NULL int af_flagtype; // AFT_CHAR, AFT_LONG, AFT_NUM or AFT_CAPLONG unsigned af_rare; // RARE ID for rare word unsigned af_keepcase; // KEEPCASE ID for keep-case word @@ -341,12 +360,12 @@ typedef struct afffile_S { typedef struct affentry_S affentry_T; // Affix entry from ".aff" file. Used for prefixes and suffixes. struct affentry_S { - affentry_T *ae_next; // next affix with same name/number - char_u *ae_chop; // text to chop off basic word (can be NULL) - char_u *ae_add; // text to add to basic word (can be NULL) - char_u *ae_flags; // flags on the affix (can be NULL) - char_u *ae_cond; // condition (NULL for ".") - regprog_T *ae_prog; // regexp program for ae_cond or NULL + affentry_T *ae_next; // next affix with same name/number + char *ae_chop; // text to chop off basic word (can be NULL) + char *ae_add; // text to add to basic word (can be NULL) + char *ae_flags; // flags on the affix (can be NULL) + char *ae_cond; // condition (NULL for ".") + regprog_T *ae_prog; // regexp program for ae_cond or NULL char ae_compforbid; // COMPOUNDFORBIDFLAG found char ae_comppermit; // COMPOUNDPERMITFLAG found }; @@ -415,7 +434,7 @@ struct wordnode_S { // "wn_region" the LSW of the wordnr. char_u wn_affixID; // supported/required prefix ID or 0 uint16_t wn_flags; // WF_ flags - short wn_region; // region mask + int16_t wn_region; // region mask #ifdef SPELL_PRINTTREE int wn_nr; // sequence nr for printing @@ -460,7 +479,7 @@ typedef struct spellinfo_S { int si_memtot; // runtime memory used int si_verbose; // verbose messages int si_msg_count; // number of words added since last message - char_u *si_info; // info text chars or NULL + char *si_info; // info text chars or NULL int si_region_count; // number of regions supported (1 when there // are no regions) char_u si_region_name[MAXREGIONS * 2 + 1]; @@ -470,8 +489,8 @@ typedef struct spellinfo_S { garray_T si_rep; // list of fromto_T entries from REP lines garray_T si_repsal; // list of fromto_T entries from REPSAL lines garray_T si_sal; // list of fromto_T entries from SAL lines - char_u *si_sofofr; // SOFOFROM text - char_u *si_sofoto; // SOFOTO text + char *si_sofofr; // SOFOFROM text + char *si_sofoto; // SOFOTO text int si_nosugfile; // NOSUGFILE item found int si_nosplitsugs; // NOSPLITSUGS item found int si_nocompoundsugs; // NOCOMPOUNDSUGS item found @@ -481,16 +500,16 @@ typedef struct spellinfo_S { time_t si_sugtime; // timestamp for .sug file int si_rem_accents; // soundsalike: remove accents garray_T si_map; // MAP info concatenated - char_u *si_midword; // MIDWORD chars or NULL + char *si_midword; // MIDWORD chars or NULL int si_compmax; // max nr of words for compounding int si_compminlen; // minimal length for compounding int si_compsylmax; // max nr of syllables for compounding int si_compoptions; // COMP_ flags garray_T si_comppat; // CHECKCOMPOUNDPATTERN items, each stored as // a string - char_u *si_compflags; // flags used for compounding + char *si_compflags; // flags used for compounding char_u si_nobreak; // NOBREAK - char_u *si_syllable; // syllable string + char *si_syllable; // syllable string garray_T si_prefcond; // table with conditions for postponed // prefixes, each stored as a string int si_newprefID; // current value for ah_newID @@ -552,7 +571,7 @@ static inline int spell_check_magic_string(FILE *const fd) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE { char buf[VIMSPELLMAGICL]; - SPELL_READ_BYTES(buf, VIMSPELLMAGICL, fd,; ); + SPELL_READ_BYTES(buf, VIMSPELLMAGICL, fd,; ); // NOLINT(whitespace/parens) if (memcmp(buf, VIMSPELLMAGIC, VIMSPELLMAGICL) != 0) { return SP_FORMERROR; } @@ -701,7 +720,7 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent) if (p == NULL) { goto endFAIL; } - set_map_str(lp, (char_u *)p); + set_map_str(lp, p); xfree(p); break; @@ -819,7 +838,7 @@ endOK: // Fill in the wordcount fields for a trie. // Returns the total number of words. -static void tree_count_words(char_u *byts, idx_T *idxs) +static void tree_count_words(const char_u *byts, idx_T *idxs) { int depth; idx_T arridx[MAXWLEN]; @@ -876,7 +895,7 @@ void suggest_load_files(void) slang_T *slang; char *dotp; FILE *fd; - char_u buf[MAXWLEN]; + char buf[MAXWLEN]; int i; time_t timestamp; int wcount; @@ -906,9 +925,9 @@ void suggest_load_files(void) // <SUGHEADER>: <fileID> <versionnr> <timestamp> for (i = 0; i < VIMSUGMAGICL; i++) { - buf[i] = (char_u)getc(fd); // <fileID> + buf[i] = (char)getc(fd); // <fileID> } - if (STRNCMP(buf, VIMSUGMAGIC, VIMSUGMAGICL) != 0) { + if (strncmp(buf, VIMSUGMAGIC, VIMSUGMAGICL) != 0) { semsg(_("E778: This does not look like a .sug file: %s"), slang->sl_fname); goto nextone; @@ -981,8 +1000,8 @@ someerror: // Need to put word counts in the word tries, so that we can find // a word by its number. - tree_count_words(slang->sl_fbyts, slang->sl_fidxs); - tree_count_words(slang->sl_sbyts, slang->sl_sidxs); + tree_count_words((char_u *)slang->sl_fbyts, slang->sl_fidxs); + tree_count_words((char_u *)slang->sl_sbyts, slang->sl_sidxs); nextone: if (fd != NULL) { @@ -1031,7 +1050,7 @@ static int read_region_section(FILE *fd, slang_T *lp, int len) if (len > MAXREGIONS * 2) { return SP_FORMERROR; } - SPELL_READ_NONNUL_BYTES((char *)lp->sl_regions, (size_t)len, fd,; ); + SPELL_READ_NONNUL_BYTES(lp->sl_regions, (size_t)len, fd,; ); // NOLINT(whitespace/parens) lp->sl_regions[len] = NUL; return 0; } @@ -1041,12 +1060,12 @@ static int read_region_section(FILE *fd, slang_T *lp, int len) // Return SP_*ERROR flags. static int read_charflags_section(FILE *fd) { - char_u *flags; + char *flags; char_u *fol; int flagslen, follen; // <charflagslen> <charflags> - flags = read_cnt_string(fd, 1, &flagslen); + flags = (char *)read_cnt_string(fd, 1, &flagslen); if (flagslen < 0) { return flagslen; } @@ -1060,7 +1079,7 @@ static int read_charflags_section(FILE *fd) // Set the word-char flags and fill SPELL_ISUPPER() table. if (flags != NULL && fol != NULL) { - set_spell_charflags(flags, flagslen, fol); + set_spell_charflags((char_u *)flags, flagslen, (char *)fol); } xfree(flags); @@ -1098,7 +1117,7 @@ static int read_prefcond_section(FILE *fd, slang_T *lp) if (n > 0) { char buf[MAXWLEN + 1]; buf[0] = '^'; // always match at one position only - SPELL_READ_NONNUL_BYTES(buf + 1, (size_t)n, fd,; ); + SPELL_READ_NONNUL_BYTES(buf + 1, (size_t)n, fd,; ); // NOLINT(whitespace/parens) buf[n + 1] = NUL; lp->sl_prefprog[i] = vim_regcomp(buf, RE_MAGIC | RE_STRING); } @@ -1121,17 +1140,17 @@ static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first) ga_grow(gap, cnt); // <rep> : <repfromlen> <repfrom> <reptolen> <repto> - for (; gap->ga_len < cnt; ++gap->ga_len) { + for (; gap->ga_len < cnt; gap->ga_len++) { int c; ftp = &((fromto_T *)gap->ga_data)[gap->ga_len]; - ftp->ft_from = read_cnt_string(fd, 1, &c); + ftp->ft_from = (char *)read_cnt_string(fd, 1, &c); if (c < 0) { return c; } if (c == 0) { return SP_FORMERROR; } - ftp->ft_to = read_cnt_string(fd, 1, &c); + ftp->ft_to = (char *)read_cnt_string(fd, 1, &c); if (c <= 0) { xfree(ftp->ft_from); if (c < 0) { @@ -1147,8 +1166,8 @@ static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first) } 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; + if (first[(uint8_t)(*ftp->ft_from)] == -1) { + first[(uint8_t)(*ftp->ft_from)] = (int16_t)i; } } return 0; @@ -1196,7 +1215,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) return SP_TRUNCERROR; } p = xmalloc((size_t)ccnt + 2); - smp->sm_lead = p; + smp->sm_lead = (char *)p; // Read up to the first special char into sm_lead. int i = 0; @@ -1207,7 +1226,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) } *p++ = (char_u)c; } - smp->sm_leadlen = (int)(p - smp->sm_lead); + smp->sm_leadlen = (int)(p - (char_u *)smp->sm_lead); *p++ = NUL; // Put (abc) chars in sm_oneof, if any. @@ -1229,7 +1248,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) } // Any following chars go in sm_rules. - smp->sm_rules = p; + smp->sm_rules = (char *)p; if (i < ccnt) { // store the char we got while checking for end of sm_lead *p++ = (char_u)c; @@ -1244,7 +1263,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) *p++ = NUL; // <saltolen> <salto> - smp->sm_to = read_cnt_string(fd, 1, &ccnt); + smp->sm_to = (char *)read_cnt_string(fd, 1, &ccnt); if (ccnt < 0) { xfree(smp->sm_lead); return ccnt; @@ -1256,7 +1275,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) if (smp->sm_oneof == NULL) { smp->sm_oneof_w = NULL; } else { - smp->sm_oneof_w = mb_str2wide(smp->sm_oneof); + smp->sm_oneof_w = mb_str2wide((char *)smp->sm_oneof); } if (smp->sm_to == NULL) { smp->sm_to_w = NULL; @@ -1271,12 +1290,12 @@ static int read_sal_section(FILE *fd, slang_T *slang) smp = &((salitem_T *)gap->ga_data)[gap->ga_len]; p = xmalloc(1); p[0] = NUL; - smp->sm_lead = p; + smp->sm_lead = (char *)p; smp->sm_lead_w = mb_str2wide(smp->sm_lead); smp->sm_leadlen = 0; smp->sm_oneof = NULL; smp->sm_oneof_w = NULL; - smp->sm_rules = p; + smp->sm_rules = (char *)p; smp->sm_to = NULL; smp->sm_to_w = NULL; gap->ga_len++; @@ -1314,7 +1333,7 @@ static int read_words_section(FILE *fd, slang_T *lp, int len) } // Init the count to 10. - count_common_word(lp, word, -1, 10); + count_common_word(lp, (char *)word, -1, 10); done += i + 1; } return 0; @@ -1325,19 +1344,19 @@ static int read_words_section(FILE *fd, slang_T *lp, int len) static int read_sofo_section(FILE *fd, slang_T *slang) { int cnt; - char_u *from, *to; + char *from, *to; int res; slang->sl_sofo = true; // <sofofromlen> <sofofrom> - from = read_cnt_string(fd, 2, &cnt); + from = (char *)read_cnt_string(fd, 2, &cnt); if (cnt < 0) { return cnt; } // <sofotolen> <sofoto> - to = read_cnt_string(fd, 2, &cnt); + to = (char *)read_cnt_string(fd, 2, &cnt); if (cnt < 0) { xfree(from); return cnt; @@ -1407,7 +1426,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) return SP_TRUNCERROR; } todo -= 2; - ga_init(gap, sizeof(char_u *), c); + ga_init(gap, sizeof(char *), c); ga_grow(gap, c); while (--c >= 0) { ((char **)(gap->ga_data))[gap->ga_len++] = (char *)read_cnt_string(fd, 1, &cnt); @@ -1428,25 +1447,25 @@ static int read_compound(FILE *fd, slang_T *slang, int len) // Conversion to utf-8 may double the size. c = todo * 2 + 7; c += todo * 2; - char_u *pat = xmalloc((size_t)c); + char *pat = xmalloc((size_t)c); // We also need a list of all flags that can appear at the start and one // for all flags. - char_u *cp = xmalloc((size_t)todo + 1); + uint8_t *cp = xmalloc((size_t)todo + 1); slang->sl_compstartflags = cp; *cp = NUL; - char_u *ap = xmalloc((size_t)todo + 1); + uint8_t *ap = xmalloc((size_t)todo + 1); slang->sl_compallflags = ap; *ap = NUL; // And a list of all patterns in their original form, for checking whether // compounding may work in match_compoundrule(). This is freed when we // encounter a wildcard, the check doesn't work then. - char_u *crp = xmalloc((size_t)todo + 1); + uint8_t *crp = xmalloc((size_t)todo + 1); slang->sl_comprules = crp; - char_u *pp = pat; + char_u *pp = (char_u *)pat; *pp++ = '^'; *pp++ = '\\'; *pp++ = '('; @@ -1515,7 +1534,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) *crp = NUL; } - slang->sl_compprog = vim_regcomp((char *)pat, RE_MAGIC + RE_STRING + RE_STRICT); + slang->sl_compprog = vim_regcomp(pat, RE_MAGIC + RE_STRING + RE_STRICT); xfree(pat); if (slang->sl_compprog == NULL) { return SP_FORMERROR; @@ -1526,10 +1545,10 @@ static int read_compound(FILE *fd, slang_T *slang, int len) // Set the SOFOFROM and SOFOTO items in language "lp". // Returns SP_*ERROR flags when there is something wrong. -static int set_sofo(slang_T *lp, char_u *from, char_u *to) +static int set_sofo(slang_T *lp, char *from, char *to) { - char_u *s; - char_u *p; + char *s; + char *p; // Use "sl_sal" as an array with 256 pointers to a list of wide // characters. The index is the low byte of the character. @@ -1544,7 +1563,7 @@ static int set_sofo(slang_T *lp, char_u *from, char_u *to) // First count the number of items for each list. Temporarily use // sl_sal_first[] for this. for (p = from, s = to; *p != NUL && *s != NUL;) { - const int c = mb_cptr2char_adv((const char_u **)&p); + const int c = mb_cptr2char_adv((const char **)&p); MB_CPTR_ADV(s); if (c >= 256) { lp->sl_sal_first[c & 0xff]++; @@ -1567,8 +1586,8 @@ static int set_sofo(slang_T *lp, char_u *from, char_u *to) // list. memset(lp->sl_sal_first, 0, sizeof(salfirst_T) * 256); for (p = from, s = to; *p != NUL && *s != NUL;) { - const int c = mb_cptr2char_adv((const char_u **)&p); - const int i = mb_cptr2char_adv((const char_u **)&s); + const int c = mb_cptr2char_adv((const char **)&p); + const int i = mb_cptr2char_adv((const char **)&s); if (c >= 256) { // Append the from-to chars at the end of the list with // the low byte. @@ -1637,13 +1656,13 @@ static void set_sal_first(slang_T *lp) // Turn a multi-byte string into a wide character string. // Return it in allocated memory. -static int *mb_str2wide(char_u *s) +static int *mb_str2wide(char *s) { int i = 0; int *res = xmalloc(((size_t)mb_charlen(s) + 1) * sizeof(int)); - for (char_u *p = s; *p != NUL;) { - res[i++] = mb_ptr2char_adv((const char_u **)&p); + for (char *p = s; *p != NUL;) { + res[i++] = mb_ptr2char_adv((const char **)&p); } res[i] = NUL; @@ -1658,12 +1677,12 @@ static int *mb_str2wide(char_u *s) /// @param prefixcnt when "prefixtree" is true: prefix count /// /// @return zero when OK, SP_ value for an error. -static int spell_read_tree(FILE *fd, char_u **bytsp, long *bytsp_len, idx_T **idxsp, - bool prefixtree, int prefixcnt) +static int spell_read_tree(FILE *fd, char **bytsp, long *bytsp_len, idx_T **idxsp, bool prefixtree, + int prefixcnt) FUNC_ATTR_NONNULL_ARG(1, 2, 4) { int idx; - char_u *bp; + char *bp; idx_T *ip; // The tree size was computed when writing the file, so that we can @@ -1676,23 +1695,25 @@ static int spell_read_tree(FILE *fd, char_u **bytsp, long *bytsp_len, idx_T **id // Invalid length, multiply with sizeof(int) would overflow. return SP_FORMERROR; } - if (len > 0) { - // Allocate the byte array. - bp = xmalloc((size_t)len); - *bytsp = bp; - if (bytsp_len != NULL) { - *bytsp_len = len; - } + if (len <= 0) { + return 0; + } - // Allocate the index array. - ip = xcalloc((size_t)len, sizeof(*ip)); - *idxsp = ip; + // Allocate the byte array. + bp = xmalloc((size_t)len); + *bytsp = bp; + if (bytsp_len != NULL) { + *bytsp_len = len; + } - // Recursively read the tree and store it in the array. - idx = read_tree_node(fd, bp, ip, (int)len, 0, prefixtree, prefixcnt); - if (idx < 0) { - return idx; - } + // Allocate the index array. + ip = xcalloc((size_t)len, sizeof(*ip)); + *idxsp = ip; + + // Recursively read the tree and store it in the array. + idx = read_tree_node(fd, (char_u *)bp, ip, (int)len, 0, prefixtree, prefixcnt); + if (idx < 0) { + return idx; } return 0; } @@ -1816,15 +1837,15 @@ static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx /// Reload the spell file "fname" if it's loaded. /// /// @param added_word invoked through "zg" -static void spell_reload_one(char_u *fname, bool added_word) +static void spell_reload_one(char *fname, bool added_word) { slang_T *slang; bool didit = false; for (slang = first_lang; slang != NULL; slang = slang->sl_next) { - if (path_full_compare((char *)fname, slang->sl_fname, false, true) == kEqualFiles) { + if (path_full_compare(fname, slang->sl_fname, false, true) == kEqualFiles) { slang_clear(slang); - if (spell_load_file((char *)fname, NULL, slang, false) == NULL) { + if (spell_load_file(fname, NULL, slang, false) == NULL) { // reloading failed, clear the language slang_clear(slang); } @@ -1984,26 +2005,27 @@ static void spell_print_node(wordnode_T *node, int depth) static void spell_print_tree(wordnode_T *root) { - if (root != NULL) { - // Clear the "wn_u1.index" fields, used to remember what has been - // done. - spell_clear_flags(root); - - // Recursively print the tree. - spell_print_node(root, 0); + if (root == NULL) { + return; } + + // Clear the "wn_u1.index" fields, used to remember what has been done. + spell_clear_flags(root); + + // Recursively print the tree. + spell_print_node(root, 0); } #endif // SPELL_PRINTTREE // Reads the affix file "fname". // Returns an afffile_T, NULL for complete failure. -static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) +static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) { FILE *fd; - char_u rline[MAXLINELEN]; - char_u *line; - char_u *pc = NULL; + char rline[MAXLINELEN]; + char *line; + char *pc = NULL; #define MAXITEMCNT 30 char *(items[MAXITEMCNT]); int itemcnt; @@ -2023,26 +2045,26 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) bool found_map = false; hashitem_T *hi; int l; - int compminlen = 0; // COMPOUNDMIN value - int compsylmax = 0; // COMPOUNDSYLMAX value - int compoptions = 0; // COMP_ flags - int compmax = 0; // COMPOUNDWORDMAX value - char_u *compflags = NULL; // COMPOUNDFLAG and COMPOUNDRULE + int compminlen = 0; // COMPOUNDMIN value + int compsylmax = 0; // COMPOUNDSYLMAX value + int compoptions = 0; // COMP_ flags + int compmax = 0; // COMPOUNDWORDMAX value + char *compflags = NULL; // COMPOUNDFLAG and COMPOUNDRULE // concatenated - char_u *midword = NULL; // MIDWORD value - char_u *syllable = NULL; // SYLLABLE value - char_u *sofofrom = NULL; // SOFOFROM value - char_u *sofoto = NULL; // SOFOTO value + char *midword = NULL; // MIDWORD value + char *syllable = NULL; // SYLLABLE value + char *sofofrom = NULL; // SOFOFROM value + char *sofoto = NULL; // SOFOTO value // Open the file. - fd = os_fopen((char *)fname, "r"); + fd = os_fopen(fname, "r"); if (fd == NULL) { semsg(_(e_notopen), fname); return NULL; } - vim_snprintf((char *)IObuff, IOSIZE, _("Reading affix file %s..."), fname); - spell_message(spin, (char *)IObuff); + vim_snprintf(IObuff, IOSIZE, _("Reading affix file %s..."), fname); + spell_message(spin, IObuff); // Only do REP lines when not done in another .aff file already. do_rep = GA_EMPTY(&spin->si_rep); @@ -2075,7 +2097,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 = (char_u *)string_convert(&spin->si_conv, (char *)rline, NULL); + pc = string_convert(&spin->si_conv, rline, NULL); if (pc == NULL) { smsg(_("Conversion failure for word in %s line %d: %s"), fname, lnum, rline); @@ -2090,7 +2112,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // Split the line up in white separated items. Put a NUL after each // item. itemcnt = 0; - for (p = (char *)line;;) { + for (p = line;;) { while (*p != NUL && (uint8_t)(*p) <= ' ') { // skip white space and CR/NL p++; } @@ -2121,9 +2143,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 = (char_u *)enc_canonize((char *)items[1]); + aff->af_enc = enc_canonize((char *)items[1]); if (!spin->si_ascii - && convert_setup(&spin->si_conv, (char *)aff->af_enc, p_enc) == FAIL) { + && convert_setup(&spin->si_conv, aff->af_enc, p_enc) == FAIL) { smsg(_("Conversion in %s not supported: from %s to %s"), fname, aff->af_enc, p_enc); } @@ -2156,7 +2178,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } } else if (spell_info_item(items[0]) && itemcnt > 1) { p = getroom(spin, - (spin->si_info == NULL ? 0 : STRLEN(spin->si_info)) + (spin->si_info == NULL ? 0 : strlen(spin->si_info)) + strlen(items[0]) + strlen(items[1]) + 3, false); if (spin->si_info != NULL) { @@ -2166,63 +2188,49 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) STRCAT(p, items[0]); STRCAT(p, " "); STRCAT(p, items[1]); - spin->si_info = (char_u *)p; + spin->si_info = p; } else if (is_aff_rule(items, itemcnt, "MIDWORD", 2) && midword == NULL) { - midword = (char_u *)getroom_save(spin, (char_u *)items[1]); + midword = 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 - } - // TODO: remove "RAR" later - else if ((is_aff_rule(items, itemcnt, "RAR", 2) - || is_aff_rule(items, itemcnt, "RARE", 2)) - && aff->af_rare == 0) { - aff->af_rare = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); - } - // TODO: remove "KEP" later - else if ((is_aff_rule(items, itemcnt, "KEP", 2) - || is_aff_rule(items, itemcnt, "KEEPCASE", 2)) - && aff->af_keepcase == 0) { - aff->af_keepcase = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + } else if ((is_aff_rule(items, itemcnt, "RAR", 2) // TODO(vim): remove "RAR" later + || is_aff_rule(items, itemcnt, "RARE", 2)) + && aff->af_rare == 0) { + aff->af_rare = affitem2flag(aff->af_flagtype, items[1], fname, lnum); + } else if ((is_aff_rule(items, itemcnt, "KEP", 2) // TODO(vim): remove "KEP" later + || is_aff_rule(items, itemcnt, "KEEPCASE", 2)) + && aff->af_keepcase == 0) { + aff->af_keepcase = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if ((is_aff_rule(items, itemcnt, "BAD", 2) || is_aff_rule(items, itemcnt, "FORBIDDENWORD", 2)) && aff->af_bad == 0) { - aff->af_bad = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_bad = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if (is_aff_rule(items, itemcnt, "NEEDAFFIX", 2) && aff->af_needaffix == 0) { - aff->af_needaffix = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_needaffix = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if (is_aff_rule(items, itemcnt, "CIRCUMFIX", 2) && aff->af_circumfix == 0) { - aff->af_circumfix = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_circumfix = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if (is_aff_rule(items, itemcnt, "NOSUGGEST", 2) && aff->af_nosuggest == 0) { - aff->af_nosuggest = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_nosuggest = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if ((is_aff_rule(items, itemcnt, "NEEDCOMPOUND", 2) || is_aff_rule(items, itemcnt, "ONLYINCOMPOUND", 2)) && aff->af_needcomp == 0) { - aff->af_needcomp = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_needcomp = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if (is_aff_rule(items, itemcnt, "COMPOUNDROOT", 2) && aff->af_comproot == 0) { - aff->af_comproot = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_comproot = affitem2flag(aff->af_flagtype, items[1], fname, lnum); } else if (is_aff_rule(items, itemcnt, "COMPOUNDFORBIDFLAG", 2) && aff->af_compforbid == 0) { - aff->af_compforbid = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_compforbid = affitem2flag(aff->af_flagtype, items[1], fname, lnum); if (aff->af_pref.ht_used > 0) { smsg(_("Defining COMPOUNDFORBIDFLAG after PFX item may give wrong results in %s line %d"), fname, lnum); } } else if (is_aff_rule(items, itemcnt, "COMPOUNDPERMITFLAG", 2) && aff->af_comppermit == 0) { - aff->af_comppermit = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + aff->af_comppermit = affitem2flag(aff->af_flagtype, items[1], fname, lnum); if (aff->af_pref.ht_used > 0) { smsg(_("Defining COMPOUNDPERMITFLAG after PFX item may give wrong results in %s line %d"), fname, lnum); @@ -2234,7 +2242,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) p = getroom(spin, strlen(items[1]) + 2, false); STRCPY(p, items[1]); STRCAT(p, "+"); - compflags = (char_u *)p; + compflags = p; } else if (is_aff_rule(items, itemcnt, "COMPOUNDRULES", 2)) { // We don't use the count, but do check that it's a number and // not COMPOUNDRULE mistyped. @@ -2249,7 +2257,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // using a slash to separate them. l = (int)strlen(items[1]) + 1; if (compflags != NULL) { - l += (int)STRLEN(compflags) + 1; + l += (int)strlen(compflags) + 1; } p = getroom(spin, (size_t)l, false); if (compflags != NULL) { @@ -2257,7 +2265,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) STRCAT(p, "/"); } STRCAT(p, items[1]); - compflags = (char_u *)p; + compflags = p; } } else if (is_aff_rule(items, itemcnt, "COMPOUNDWORDMAX", 2) && compmax == 0) { @@ -2306,12 +2314,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++] = getroom_save(spin, (char_u *)items[1]); - ((char **)(gap->ga_data))[gap->ga_len++] = getroom_save(spin, (char_u *)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 = (char_u *)getroom_save(spin, (char_u *)items[1]); + syllable = 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)) { @@ -2329,7 +2337,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) && aff_todo == 0 && itemcnt >= 4) { int lasti = 4; - char_u key[AH_KEY_LEN]; + char key[AH_KEY_LEN]; if (*items[0] == 'P') { tp = &aff->af_pref; @@ -2341,7 +2349,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // times. The affix files that do this have an undocumented // "S" flag on all but the last block, thus we check for that // and store it in ah_follows. - STRLCPY(key, items[1], AH_KEY_LEN); + xstrlcpy(key, items[1], AH_KEY_LEN); hi = hash_find(tp, (char *)key); if (!HASHITEM_EMPTY(hi)) { cur_aff = HI2AH(hi); @@ -2356,8 +2364,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } else { // New affix letter. cur_aff = getroom(spin, sizeof(*cur_aff), true); - cur_aff->ah_flag = affitem2flag(aff->af_flagtype, (char_u *)items[1], - fname, lnum); + cur_aff->ah_flag = affitem2flag(aff->af_flagtype, items[1], fname, lnum); if (cur_aff->ah_flag == 0 || strlen(items[1]) >= AH_KEY_LEN) { break; } @@ -2375,7 +2382,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) fname, lnum, items[1]); } STRCPY(cur_aff->ah_key, items[1]); - hash_add(tp, (char_u *)cur_aff->ah_key); + hash_add(tp, cur_aff->ah_key); cur_aff->ah_combine = (*items[2] == 'Y'); } @@ -2444,13 +2451,13 @@ 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 = (char_u *)getroom_save(spin, (char_u *)items[2]); + aff_entry->ae_chop = getroom_save(spin, items[2]); } if (strcmp(items[3], "0") != 0) { - aff_entry->ae_add = (char_u *)getroom_save(spin, (char_u *)items[3]); + aff_entry->ae_add = 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, '/'); + aff_entry->ae_flags = vim_strchr(aff_entry->ae_add, '/'); if (aff_entry->ae_flags != NULL) { *aff_entry->ae_flags++ = NUL; aff_process_flags(aff, aff_entry); @@ -2465,15 +2472,15 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) cur_aff->ah_first = aff_entry; if (strcmp(items[4], ".") != 0) { - char_u buf[MAXLINELEN]; + char buf[MAXLINELEN]; - aff_entry->ae_cond = (char_u *)getroom_save(spin, (char_u *)items[4]); + aff_entry->ae_cond = getroom_save(spin, items[4]); if (*items[0] == 'P') { - sprintf((char *)buf, "^%s", items[4]); + sprintf(buf, "^%s", items[4]); // NOLINT(runtime/printf) } else { - sprintf((char *)buf, "%s$", items[4]); + sprintf(buf, "%s$", items[4]); // NOLINT(runtime/printf) } - aff_entry->ae_prog = vim_regcomp((char *)buf, RE_MAGIC + RE_STRING + RE_STRICT); + aff_entry->ae_prog = vim_regcomp(buf, RE_MAGIC + RE_STRING + RE_STRICT); if (aff_entry->ae_prog == NULL) { smsg(_("Broken condition in %s line %d: %s"), fname, lnum, items[4]); @@ -2493,17 +2500,16 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // be empty or start with the same letter. if (aff_entry->ae_chop != NULL && aff_entry->ae_add != NULL - && aff_entry->ae_chop[utfc_ptr2len((char *)aff_entry->ae_chop)] == + && aff_entry->ae_chop[utfc_ptr2len(aff_entry->ae_chop)] == NUL) { int c, c_up; - c = utf_ptr2char((char *)aff_entry->ae_chop); + c = utf_ptr2char(aff_entry->ae_chop); c_up = SPELL_TOUPPER(c); if (c_up != c && (aff_entry->ae_cond == NULL - || utf_ptr2char((char *)aff_entry->ae_cond) == c)) { - p = (char *)aff_entry->ae_add - + STRLEN(aff_entry->ae_add); + || utf_ptr2char(aff_entry->ae_cond) == c)) { + p = aff_entry->ae_add + strlen(aff_entry->ae_add); MB_PTR_BACK(aff_entry->ae_add, p); if (utf_ptr2char(p) == c_up) { upper = true; @@ -2514,14 +2520,13 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // actual word, thus must check for the // upper-case letter. if (aff_entry->ae_cond != NULL) { - char_u buf[MAXLINELEN]; - onecap_copy((char_u *)items[4], buf, true); - aff_entry->ae_cond = (char_u *)getroom_save(spin, buf); + char buf[MAXLINELEN]; + onecap_copy(items[4], buf, true); + aff_entry->ae_cond = getroom_save(spin, buf); if (aff_entry->ae_cond != NULL) { - sprintf((char *)buf, "^%s", - aff_entry->ae_cond); + sprintf(buf, "^%s", aff_entry->ae_cond); // NOLINT(runtime/printf) vim_regfree(aff_entry->ae_prog); - aff_entry->ae_prog = vim_regcomp((char *)buf, RE_MAGIC + RE_STRING); + aff_entry->ae_prog = vim_regcomp(buf, RE_MAGIC + RE_STRING); } } } @@ -2536,7 +2541,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // Find a previously used condition. for (idx = spin->si_prefcond.ga_len - 1; idx >= 0; idx--) { p = ((char **)spin->si_prefcond.ga_data)[idx]; - if (str_equal(p, (char *)aff_entry->ae_cond)) { + if (str_equal(p, aff_entry->ae_cond)) { break; } } @@ -2552,7 +2557,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) if (aff_entry->ae_add == NULL) { p = ""; } else { - p = (char *)aff_entry->ae_add; + p = aff_entry->ae_add; } // PFX_FLAGS is a negative number, so that @@ -2591,7 +2596,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } else if (is_aff_rule(items, itemcnt, "REP", 2) || is_aff_rule(items, itemcnt, "REPSAL", 2)) { // Ignore REP/REPSAL count - if (!isdigit(*items[1])) { + if (!isdigit((uint8_t)(*items[1]))) { smsg(_("Expected REP(SAL) count in %s line %d"), fname, lnum); } @@ -2619,14 +2624,14 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } add_fromto(spin, items[0][3] == 'S' ? &spin->si_repsal - : &spin->si_rep, (char_u *)items[1], (char_u *)items[2]); + : &spin->si_rep, items[1], items[2]); } } else if (is_aff_rule(items, itemcnt, "MAP", 2)) { // MAP item or count if (!found_map) { // First line contains the count. found_map = true; - if (!isdigit(*items[1])) { + if (!isdigit((uint8_t)(*items[1]))) { smsg(_("Expected MAP count in %s line %d"), fname, lnum); } @@ -2635,7 +2640,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // Check that every character appears only once. for (p = items[1]; *p != NUL;) { - c = mb_ptr2char_adv((const char_u **)&p); + c = mb_ptr2char_adv((const char **)&p); if ((!GA_EMPTY(&spin->si_map) && vim_strchr(spin->si_map.ga_data, c) != NULL) @@ -2664,24 +2669,24 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) spin->si_rem_accents = sal_to_bool(items[2]); } else { // when "to" is "_" it means empty - add_fromto(spin, &spin->si_sal, (char_u *)items[1], - strcmp(items[2], "_") == 0 ? (char_u *)"" - : (char_u *)items[2]); + add_fromto(spin, &spin->si_sal, items[1], + strcmp(items[2], "_") == 0 ? "" + : items[2]); } } } else if (is_aff_rule(items, itemcnt, "SOFOFROM", 2) && sofofrom == NULL) { - sofofrom = (char_u *)getroom_save(spin, (char_u *)items[1]); + sofofrom = getroom_save(spin, items[1]); } else if (is_aff_rule(items, itemcnt, "SOFOTO", 2) && sofoto == NULL) { - sofoto = (char_u *)getroom_save(spin, (char_u *)items[1]); + sofoto = getroom_save(spin, items[1]); } else if (strcmp(items[0], "COMMON") == 0) { int i; for (i = 1; i < itemcnt; i++) { if (HASHITEM_EMPTY(hash_find(&spin->si_commonwords, (char *)items[i]))) { p = xstrdup(items[i]); - hash_add(&spin->si_commonwords, (char_u *)p); + hash_add(&spin->si_commonwords, p); } } } else { @@ -2744,7 +2749,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } if (syllable != NULL) { - aff_check_string((char *)spin->si_syllable, (char *)syllable, "SYLLABLE"); + aff_check_string(spin->si_syllable, syllable, "SYLLABLE"); spin->si_syllable = syllable; } @@ -2755,15 +2760,15 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } else if (!GA_EMPTY(&spin->si_sal)) { smsg(_("Both SAL and SOFO lines in %s"), fname); } else { - aff_check_string((char *)spin->si_sofofr, (char *)sofofrom, "SOFOFROM"); - aff_check_string((char *)spin->si_sofoto, (char *)sofoto, "SOFOTO"); + aff_check_string(spin->si_sofofr, sofofrom, "SOFOFROM"); + aff_check_string(spin->si_sofoto, sofoto, "SOFOTO"); spin->si_sofofr = sofofrom; spin->si_sofoto = sofoto; } } if (midword != NULL) { - aff_check_string((char *)spin->si_midword, (char *)midword, "MIDWORD"); + aff_check_string(spin->si_midword, midword, "MIDWORD"); spin->si_midword = midword; } @@ -2785,18 +2790,18 @@ static bool is_aff_rule(char **items, int itemcnt, char *rulename, int mincount) // ae_flags to ae_comppermit and ae_compforbid. static void aff_process_flags(afffile_T *affile, affentry_T *entry) { - char_u *p; + char *p; char_u *prevp; unsigned flag; if (entry->ae_flags != NULL && (affile->af_compforbid != 0 || affile->af_comppermit != 0)) { for (p = entry->ae_flags; *p != NUL;) { - prevp = p; + prevp = (char_u *)p; flag = get_affitem(affile->af_flagtype, &p); if (flag == affile->af_comppermit || flag == affile->af_compforbid) { - STRMOVE(prevp, p); - p = prevp; + STRMOVE(prevp, (char *)p); + p = (char *)prevp; if (flag == affile->af_comppermit) { entry->ae_comppermit = true; } else { @@ -2826,10 +2831,10 @@ static bool spell_info_item(char *s) // Turn an affix flag name into a number, according to the FLAG type. // returns zero for failure. -static unsigned affitem2flag(int flagtype, char_u *item, char_u *fname, int lnum) +static unsigned affitem2flag(int flagtype, char *item, char *fname, int lnum) { unsigned res; - char_u *p = item; + char *p = item; res = get_affitem(flagtype, &p); if (res == 0) { @@ -2852,54 +2857,54 @@ static unsigned affitem2flag(int flagtype, char_u *item, char_u *fname, int lnum // Get one affix name from "*pp" and advance the pointer. // Returns ZERO_FLAG for "0". // Returns zero for an error, still advances the pointer then. -static unsigned get_affitem(int flagtype, char_u **pp) +static unsigned get_affitem(int flagtype, char **pp) { int res; if (flagtype == AFT_NUM) { if (!ascii_isdigit(**pp)) { - ++*pp; // always advance, avoid getting stuck + (*pp)++; // always advance, avoid getting stuck return 0; } - res = getdigits_int((char **)pp, true, 0); + res = getdigits_int(pp, true, 0); if (res == 0) { res = ZERO_FLAG; } } else { - res = mb_ptr2char_adv((const char_u **)pp); + res = mb_ptr2char_adv((const char **)pp); if (flagtype == AFT_LONG || (flagtype == AFT_CAPLONG && res >= 'A' && res <= 'Z')) { if (**pp == NUL) { return 0; } - res = mb_ptr2char_adv((const char_u **)pp) + (res << 16); + res = mb_ptr2char_adv((const char **)pp) + (res << 16); } } return (unsigned)res; } -// Process the "compflags" string used in an affix file and append it to -// spin->si_compflags. -// The processing involves changing the affix names to ID numbers, so that -// they fit in one byte. -static void process_compflags(spellinfo_T *spin, afffile_T *aff, char_u *compflags) +/// Process the "compflags" string used in an affix file and append it to +/// spin->si_compflags. +/// The processing involves changing the affix names to ID numbers, so that +/// they fit in one byte. +static void process_compflags(spellinfo_T *spin, afffile_T *aff, char *compflags) { - char_u *p; - char_u *prevp; + char *p; + char *prevp; unsigned flag; compitem_T *ci; int id; int len; char_u *tp; - char_u key[AH_KEY_LEN]; + char key[AH_KEY_LEN]; hashitem_T *hi; // Make room for the old and the new compflags, concatenated with a / in // between. Processing it makes it shorter, but we don't know by how // much, thus allocate the maximum. - len = (int)STRLEN(compflags) + 1; + len = (int)strlen(compflags) + 1; if (spin->si_compflags != NULL) { - len += (int)STRLEN(spin->si_compflags) + 1; + len += (int)strlen(spin->si_compflags) + 1; } p = getroom(spin, (size_t)len, false); if (spin->si_compflags != NULL) { @@ -2907,12 +2912,12 @@ static void process_compflags(spellinfo_T *spin, afffile_T *aff, char_u *compfla STRCAT(p, "/"); } spin->si_compflags = p; - tp = p + STRLEN(p); + tp = (char_u *)p + strlen(p); for (p = compflags; *p != NUL;) { - if (vim_strchr("/?*+[]", *p) != NULL) { + if (vim_strchr("/?*+[]", (uint8_t)(*p)) != NULL) { // Copy non-flag characters directly. - *tp++ = *p++; + *tp++ = (char_u)(*p++); } else { // First get the flag number, also checks validity. prevp = p; @@ -2920,7 +2925,7 @@ static void process_compflags(spellinfo_T *spin, afffile_T *aff, char_u *compfla if (flag != 0) { // Find the flag in the hashtable. If it was used before, use // the existing ID. Otherwise add a new entry. - STRLCPY(key, prevp, p - prevp + 1); + xstrlcpy(key, prevp, (size_t)(p - prevp) + 1); hi = hash_find(&aff->af_comp, (char *)key); if (!HASHITEM_EMPTY(hi)) { id = HI2CI(hi)->ci_newID; @@ -2935,7 +2940,7 @@ static void process_compflags(spellinfo_T *spin, afffile_T *aff, char_u *compfla id = spin->si_newcompID--; } while (vim_strchr("/?*+[]\\-^", id) != NULL); ci->ci_newID = id; - hash_add(&aff->af_comp, ci->ci_key); + hash_add(&aff->af_comp, (char *)ci->ci_key); } *tp++ = (char_u)id; } @@ -2961,22 +2966,22 @@ static void check_renumber(spellinfo_T *spin) } // Returns true if flag "flag" appears in affix list "afflist". -static bool flag_in_afflist(int flagtype, char_u *afflist, unsigned flag) +static bool flag_in_afflist(int flagtype, char *afflist, unsigned flag) { char *p; unsigned n; switch (flagtype) { case AFT_CHAR: - return vim_strchr((char *)afflist, (int)flag) != NULL; + return vim_strchr(afflist, (int)flag) != NULL; case AFT_CAPLONG: case AFT_LONG: - for (p = (char *)afflist; *p != NUL;) { - n = (unsigned)mb_ptr2char_adv((const char_u **)&p); + for (p = afflist; *p != NUL;) { + n = (unsigned)mb_ptr2char_adv((const char **)&p); if ((flagtype == AFT_LONG || (n >= 'A' && n <= 'Z')) && *p != NUL) { - n = (unsigned)mb_ptr2char_adv((const char_u **)&p) + (n << 16); + n = (unsigned)mb_ptr2char_adv((const char **)&p) + (n << 16); } if (n == flag) { return true; @@ -2985,7 +2990,7 @@ static bool flag_in_afflist(int flagtype, char_u *afflist, unsigned flag) break; case AFT_NUM: - for (p = (char *)afflist; *p != NUL;) { + for (p = afflist; *p != NUL;) { int digits = getdigits_int(&p, true, 0); assert(digits >= 0); n = (unsigned int)digits; @@ -3032,17 +3037,17 @@ static bool str_equal(char *s1, char *s2) return strcmp(s1, s2) == 0; } -// Add a from-to item to "gap". Used for REP and SAL items. -// They are stored case-folded. -static void add_fromto(spellinfo_T *spin, garray_T *gap, char_u *from, char_u *to) +/// Add a from-to item to "gap". Used for REP and SAL items. +/// They are stored case-folded. +static void add_fromto(spellinfo_T *spin, garray_T *gap, char *from, char *to) { - char_u word[MAXWLEN]; + char word[MAXWLEN]; fromto_T *ftp = GA_APPEND_VIA_PTR(fromto_T, gap); - (void)spell_casefold(curwin, from, (int)STRLEN(from), word, MAXWLEN); - ftp->ft_from = (char_u *)getroom_save(spin, word); - (void)spell_casefold(curwin, to, (int)STRLEN(to), word, MAXWLEN); - ftp->ft_to = (char_u *)getroom_save(spin, word); + (void)spell_casefold(curwin, from, (int)strlen(from), word, MAXWLEN); + ftp->ft_from = getroom_save(spin, word); + (void)spell_casefold(curwin, to, (int)strlen(to), word, MAXWLEN); + ftp->ft_to = getroom_save(spin, word); } /// Converts a boolean argument in a SAL line to true or false; @@ -3086,16 +3091,16 @@ static void spell_free_aff(afffile_T *aff) // Read dictionary file "fname". // Returns OK or FAIL; -static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) +static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) { hashtab_T ht; - char_u line[MAXLINELEN]; + char line[MAXLINELEN]; char_u *p; char_u *afflist; char_u store_afflist[MAXWLEN]; int pfxlen; bool need_affix; - char_u *dw; + char *dw; char_u *pc; char_u *w; int l; @@ -3111,7 +3116,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) Timestamp last_msg_time = 0; // Open the file. - fd = os_fopen((char *)fname, "r"); + fd = os_fopen(fname, "r"); if (fd == NULL) { semsg(_(e_notopen), fname); return FAIL; @@ -3120,22 +3125,22 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) // The hashtable is only used to detect duplicated words. hash_init(&ht); - vim_snprintf((char *)IObuff, IOSIZE, + vim_snprintf(IObuff, IOSIZE, _("Reading dictionary file %s..."), fname); - spell_message(spin, (char *)IObuff); + spell_message(spin, IObuff); // start with a message for the first line spin->si_msg_count = 999999; // Read and ignore the first line: word count. - if (vim_fgets(line, MAXLINELEN, fd) || !ascii_isdigit(*skipwhite((char *)line))) { + if (vim_fgets((char *)line, MAXLINELEN, fd) || !ascii_isdigit(*skipwhite((char *)line))) { semsg(_("E760: No word count in %s"), fname); } // Read all the lines in the file one by one. // The words are converted to 'encoding' here, before being added to // the hashtable. - while (!vim_fgets(line, MAXLINELEN, fd) && !got_int) { + while (!vim_fgets((char *)line, MAXLINELEN, fd) && !got_int) { line_breakcheck(); lnum++; if (line[0] == '#' || line[0] == '/') { @@ -3143,7 +3148,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) } // Remove CR, LF and white space from the end. White space halfway through // the word is kept to allow multi-word terms like "et al.". - l = (int)STRLEN(line); + l = (int)strlen(line); while (l > 0 && line[l - 1] <= ' ') { l--; } @@ -3163,7 +3168,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) w = pc; } else { pc = NULL; - w = line; + w = (char_u *)line; } // Truncate the word at the "/", set "afflist" to what follows. @@ -3171,7 +3176,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) afflist = NULL; for (p = w; *p != NUL; MB_PTR_ADV(p)) { if (*p == '\\' && (p[1] == '\\' || p[1] == '/')) { - STRMOVE(p, p + 1); + STRMOVE(p, (char *)p + 1); } else if (*p == '/') { *p = NUL; afflist = p + 1; @@ -3180,7 +3185,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) } // Skip non-ASCII words when "spin->si_ascii" is true. - if (spin->si_ascii && has_non_ascii(w)) { + if (spin->si_ascii && has_non_ascii((char *)w)) { non_ascii++; xfree(pc); continue; @@ -3205,7 +3210,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 = (char_u *)getroom_save(spin, w); + dw = getroom_save(spin, (char *)w); if (dw == NULL) { retval = FAIL; xfree(pc); @@ -3213,7 +3218,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) } hash = hash_hash(dw); - hi = hash_lookup(&ht, (const char *)dw, STRLEN(dw), hash); + hi = hash_lookup(&ht, (const char *)dw, strlen(dw), hash); if (!HASHITEM_EMPTY(hi)) { if (p_verbose > 0) { smsg(_("Duplicate word in %s line %d: %s"), @@ -3233,45 +3238,45 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) need_affix = false; if (afflist != NULL) { // Extract flags from the affix list. - flags |= get_affix_flags(affile, afflist); + flags |= get_affix_flags(affile, (char *)afflist); if (affile->af_needaffix != 0 - && flag_in_afflist(affile->af_flagtype, afflist, + && flag_in_afflist(affile->af_flagtype, (char *)afflist, affile->af_needaffix)) { need_affix = true; } if (affile->af_pfxpostpone) { // Need to store the list of prefix IDs with the word. - pfxlen = get_pfxlist(affile, afflist, store_afflist); + pfxlen = get_pfxlist(affile, (char *)afflist, store_afflist); } if (spin->si_compflags != NULL) { // Need to store the list of compound flags with the word. // Concatenate them to the list of prefix IDs. - get_compflags(affile, afflist, store_afflist + pfxlen); + get_compflags(affile, (char *)afflist, store_afflist + pfxlen); } } // Add the word to the word tree(s). if (store_word(spin, dw, flags, spin->si_region, - store_afflist, need_affix) == FAIL) { + (char *)store_afflist, need_affix) == FAIL) { retval = FAIL; } if (afflist != NULL) { // Find all matching suffixes and add the resulting words. // Additionally do matching prefixes that combine. - if (store_aff_word(spin, dw, afflist, affile, + if (store_aff_word(spin, dw, (char *)afflist, affile, &affile->af_suff, &affile->af_pref, - CONDIT_SUF, flags, store_afflist, pfxlen) == FAIL) { + CONDIT_SUF, flags, (char *)store_afflist, pfxlen) == FAIL) { retval = FAIL; } // Find all matching prefixes and add the resulting words. - if (store_aff_word(spin, dw, afflist, affile, + if (store_aff_word(spin, dw, (char *)afflist, affile, &affile->af_pref, NULL, - CONDIT_SUF, flags, store_afflist, pfxlen) == FAIL) { + CONDIT_SUF, flags, (char *)store_afflist, pfxlen) == FAIL) { retval = FAIL; } } @@ -3294,7 +3299,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) // Check for affix flags in "afflist" that are turned into word flags. // Return WF_ flags. -static int get_affix_flags(afffile_T *affile, char_u *afflist) +static int get_affix_flags(afffile_T *affile, char *afflist) { int flags = 0; @@ -3333,13 +3338,13 @@ static int get_affix_flags(afffile_T *affile, char_u *afflist) // Used for PFXPOSTPONE. // Put the resulting flags in "store_afflist[MAXWLEN]" with a terminating NUL // and return the number of affixes. -static int get_pfxlist(afffile_T *affile, char_u *afflist, char_u *store_afflist) +static int get_pfxlist(afffile_T *affile, char *afflist, char_u *store_afflist) { - char_u *p; - char_u *prevp; + char *p; + char *prevp; int cnt = 0; int id; - char_u key[AH_KEY_LEN]; + char key[AH_KEY_LEN]; hashitem_T *hi; for (p = afflist; *p != NUL;) { @@ -3347,7 +3352,7 @@ static int get_pfxlist(afffile_T *affile, char_u *afflist, char_u *store_afflist if (get_affitem(affile->af_flagtype, &p) != 0) { // A flag is a postponed prefix flag if it appears in "af_pref" // and its ID is not zero. - STRLCPY(key, prevp, p - prevp + 1); + xstrlcpy(key, prevp, (size_t)(p - prevp) + 1); hi = hash_find(&affile->af_pref, (char *)key); if (!HASHITEM_EMPTY(hi)) { id = HI2AH(hi)->ah_newID; @@ -3368,19 +3373,19 @@ static int get_pfxlist(afffile_T *affile, char_u *afflist, char_u *store_afflist // Get the list of compound IDs from the affix list "afflist" that are used // for compound words. // Puts the flags in "store_afflist[]". -static void get_compflags(afffile_T *affile, char_u *afflist, char_u *store_afflist) +static void get_compflags(afffile_T *affile, char *afflist, char_u *store_afflist) { - char_u *p; - char_u *prevp; + char *p; + char *prevp; int cnt = 0; - char_u key[AH_KEY_LEN]; + char key[AH_KEY_LEN]; hashitem_T *hi; for (p = afflist; *p != NUL;) { prevp = p; if (get_affitem(affile->af_flagtype, &p) != 0) { // A flag is a compound flag if it appears in "af_comp". - STRLCPY(key, prevp, p - prevp + 1); + xstrlcpy(key, prevp, (size_t)(p - prevp) + 1); hi = hash_find(&affile->af_comp, (char *)key); if (!HASHITEM_EMPTY(hi)) { store_afflist[cnt++] = (char_u)HI2CI(hi)->ci_newID; @@ -3409,25 +3414,25 @@ static void get_compflags(afffile_T *affile, char_u *afflist, char_u *store_affl /// @param pfxlen nr of flags in "pfxlist" for prefixes, rest is compound flags /// /// @return FAIL when out of memory. -static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, afffile_T *affile, - hashtab_T *ht, hashtab_T *xht, int condit, int flags, char_u *pfxlist, +static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_T *affile, + hashtab_T *ht, hashtab_T *xht, int condit, int flags, char *pfxlist, int pfxlen) { int todo; hashitem_T *hi; affheader_T *ah; affentry_T *ae; - char_u newword[MAXWLEN]; + char newword[MAXWLEN]; int retval = OK; int i, j; - char_u *p; + char *p; int use_flags; - char_u *use_pfxlist; + char *use_pfxlist; int use_pfxlen; bool need_affix; char_u store_afflist[MAXWLEN]; - char_u pfx_pfxlist[MAXWLEN]; - size_t wordlen = STRLEN(word); + char pfx_pfxlist[MAXWLEN]; + size_t wordlen = strlen(word); int use_condit; todo = (int)ht->ht_used; @@ -3457,7 +3462,7 @@ static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, afff || ae->ae_chop != NULL || ae->ae_flags != NULL) && (ae->ae_chop == NULL - || STRLEN(ae->ae_chop) < wordlen) + || strlen(ae->ae_chop) < wordlen) && (ae->ae_prog == NULL || vim_regexec_prog(&ae->ae_prog, false, word, (colnr_T)0)) && (((condit & CONDIT_CFIX) == 0) @@ -3471,7 +3476,7 @@ static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, afff if (ae->ae_add == NULL) { *newword = NUL; } else { - STRLCPY(newword, ae->ae_add, MAXWLEN); + xstrlcpy(newword, ae->ae_add, MAXWLEN); } p = word; if (ae->ae_chop != NULL) { @@ -3484,10 +3489,10 @@ static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, afff STRCAT(newword, p); } else { // suffix: chop/add at the end of the word - STRLCPY(newword, word, MAXWLEN); + xstrlcpy(newword, word, MAXWLEN); if (ae->ae_chop != NULL) { // Remove chop string. - p = newword + STRLEN(newword); + p = newword + strlen(newword); i = mb_charlen(ae->ae_chop); for (; i > 0; i--) { MB_PTR_BACK(newword, p); @@ -3508,16 +3513,18 @@ static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, afff // Extract flags from the affix list. use_flags |= get_affix_flags(affile, ae->ae_flags); - if (affile->af_needaffix != 0 && flag_in_afflist(affile->af_flagtype, ae->ae_flags, - affile->af_needaffix)) { + if (affile->af_needaffix != 0 + && flag_in_afflist(affile->af_flagtype, ae->ae_flags, + affile->af_needaffix)) { need_affix = true; } // When there is a CIRCUMFIX flag the other affix // must also have it and we don't add the word // with one affix. - if (affile->af_circumfix != 0 && flag_in_afflist(affile->af_flagtype, ae->ae_flags, - affile->af_circumfix)) { + if (affile->af_circumfix != 0 + && flag_in_afflist(affile->af_flagtype, ae->ae_flags, + affile->af_circumfix)) { use_condit |= CONDIT_CFIX; if ((condit & CONDIT_CFIX) == 0) { need_affix = true; @@ -3528,12 +3535,11 @@ static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, afff || spin->si_compflags != NULL) { if (affile->af_pfxpostpone) { // Get prefix IDS from the affix list. - use_pfxlen = get_pfxlist(affile, - ae->ae_flags, store_afflist); + use_pfxlen = get_pfxlist(affile, ae->ae_flags, store_afflist); } else { use_pfxlen = 0; } - use_pfxlist = store_afflist; + use_pfxlist = (char *)store_afflist; // Combine the prefix IDs. Avoid adding the // same ID twice. @@ -3551,7 +3557,7 @@ static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, afff if (spin->si_compflags != NULL) { // Get compound IDS from the affix list. get_compflags(affile, ae->ae_flags, - use_pfxlist + use_pfxlen); + (char_u *)use_pfxlist + use_pfxlen); } else { use_pfxlist[use_pfxlen] = NUL; } @@ -3576,7 +3582,7 @@ static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, afff // Obey a "COMPOUNDFORBIDFLAG" of the affix: don't // use the compound flags. if (use_pfxlist != NULL && ae->ae_compforbid) { - STRLCPY(pfx_pfxlist, use_pfxlist, use_pfxlen + 1); + xstrlcpy(pfx_pfxlist, use_pfxlist, (size_t)use_pfxlen + 1); use_pfxlist = pfx_pfxlist; } @@ -3618,7 +3624,7 @@ static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, afff if (store_aff_word(spin, newword, ae->ae_flags, affile, &affile->af_suff, xht, use_condit & (xht == NULL - ? ~0 : ~CONDIT_SUF), + ? ~0 : ~CONDIT_SUF), use_flags, use_pfxlist, pfxlen) == FAIL) { retval = FAIL; } @@ -3652,12 +3658,12 @@ static int store_aff_word(spellinfo_T *spin, char_u *word, char_u *afflist, afff } // Read a file with a list of words. -static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) +static int spell_read_wordfile(spellinfo_T *spin, char *fname) { FILE *fd; long lnum = 0; - char_u rline[MAXLINELEN]; - char_u *line; + char rline[MAXLINELEN]; + char *line; char_u *pc = NULL; char_u *p; int l; @@ -3668,14 +3674,14 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) int regionmask; // Open the file. - fd = os_fopen((char *)fname, "r"); + fd = os_fopen(fname, "r"); if (fd == NULL) { semsg(_(e_notopen), fname); return FAIL; } - vim_snprintf((char *)IObuff, IOSIZE, _("Reading word file %s..."), fname); - spell_message(spin, (char *)IObuff); + vim_snprintf(IObuff, IOSIZE, _("Reading word file %s..."), fname); + spell_message(spin, IObuff); // Read all the lines in the file one by one. while (!vim_fgets(rline, MAXLINELEN, fd) && !got_int) { @@ -3688,8 +3694,8 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) } // Remove CR, LF and white space from the end. - l = (int)STRLEN(rline); - while (l > 0 && rline[l - 1] <= ' ') { + l = (int)strlen(rline); + while (l > 0 && (uint8_t)rline[l - 1] <= ' ') { l--; } if (l == 0) { @@ -3700,13 +3706,13 @@ 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 = (char_u *)string_convert(&spin->si_conv, (char *)rline, NULL); + pc = (char_u *)string_convert(&spin->si_conv, rline, NULL); if (pc == NULL) { smsg(_("Conversion failure for word in %s line %ld: %s"), fname, lnum, rline); continue; } - line = pc; + line = (char *)pc; } else { pc = NULL; line = rline; @@ -3714,7 +3720,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) if (*line == '/') { line++; - if (STRNCMP(line, "encoding=", 9) == 0) { + if (strncmp(line, "encoding=", 9) == 0) { if (spin->si_conv.vc_type != CONV_NONE) { smsg(_("Duplicate /encoding= line ignored in %s line %ld: %s"), fname, lnum, line - 1); @@ -3726,7 +3732,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) // Setup for conversion to 'encoding'. line += 9; - enc = enc_canonize((char *)line); + enc = enc_canonize(line); if (!spin->si_ascii && convert_setup(&spin->si_conv, enc, p_enc) == FAIL) { smsg(_("Conversion in %s not supported: from %s to %s"), @@ -3738,17 +3744,17 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) continue; } - if (STRNCMP(line, "regions=", 8) == 0) { + if (strncmp(line, "regions=", 8) == 0) { if (spin->si_region_count > 1) { smsg(_("Duplicate /regions= line ignored in %s line %ld: %s"), fname, lnum, line); } else { line += 8; - if (STRLEN(line) > MAXREGIONS * 2) { + if (strlen(line) > MAXREGIONS * 2) { smsg(_("Too many regions in %s line %ld: %s"), fname, lnum, line); } else { - spin->si_region_count = (int)STRLEN(line) / 2; + spin->si_region_count = (int)strlen(line) / 2; STRCPY(spin->si_region_name, line); // Adjust the mask for a word valid in all regions. @@ -3767,7 +3773,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) regionmask = spin->si_region; // Check for flags and region after a slash. - p = (char_u *)vim_strchr((char *)line, '/'); + p = (char_u *)vim_strchr(line, '/'); if (p != NULL) { *p++ = NUL; while (*p != NUL) { @@ -3817,9 +3823,9 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) fclose(fd); if (spin->si_ascii && non_ascii > 0) { - vim_snprintf((char *)IObuff, IOSIZE, + vim_snprintf(IObuff, IOSIZE, _("Ignored %d words with non-ASCII characters"), non_ascii); - spell_message(spin, (char *)IObuff); + spell_message(spin, IObuff); } return retval; @@ -3865,9 +3871,9 @@ static void *getroom(spellinfo_T *spin, size_t len, bool align) /// 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) +static char *getroom_save(spellinfo_T *spin, char *s) { - const size_t s_size = STRLEN(s) + 1; + const size_t s_size = strlen(s) + 1; return memcpy(getroom(spin, s_size, false), s, s_size); } @@ -3918,21 +3924,21 @@ static bool valid_spell_word(const char *word, const char *end) /// @param region supported region(s) /// @param pfxlist list of prefix ids or null /// @param need_affix only store word with affix id -static int store_word(spellinfo_T *spin, char_u *word, int flags, int region, const char_u *pfxlist, +static int store_word(spellinfo_T *spin, char *word, int flags, int region, const char *pfxlist, bool need_affix) { - int len = (int)STRLEN(word); + int len = (int)strlen(word); int ct = captype(word, word + len); char_u foldword[MAXWLEN]; int res = OK; // Avoid adding illegal bytes to the word tree. - if (!valid_spell_word((char *)word, (char *)word + len)) { + if (!valid_spell_word(word, word + len)) { return FAIL; } - (void)spell_casefold(curwin, word, len, foldword, MAXWLEN); - for (const char_u *p = pfxlist; res == OK; p++) { + (void)spell_casefold(curwin, word, len, (char *)foldword, MAXWLEN); + for (const char_u *p = (char_u *)pfxlist; res == OK; p++) { if (!need_affix || (p != NULL && *p != NUL)) { res = tree_add_word(spin, foldword, spin->si_foldroot, ct | flags, region, p == NULL ? 0 : *p); @@ -3944,9 +3950,9 @@ static int store_word(spellinfo_T *spin, char_u *word, int flags, int region, co spin->si_foldwcount++; if (res == OK && (ct == WF_KEEPCAP || (flags & WF_KEEPCAP))) { - for (const char_u *p = pfxlist; res == OK; p++) { + for (const char_u *p = (char_u *)pfxlist; res == OK; p++) { if (!need_affix || (p != NULL && *p != NUL)) { - res = tree_add_word(spin, word, spin->si_keeproot, flags, + res = tree_add_word(spin, (char_u *)word, spin->si_keeproot, flags, region, p == NULL ? 0 : *p); } if (p == NULL || *p == NUL) { @@ -3962,8 +3968,8 @@ static int store_word(spellinfo_T *spin, char_u *word, int flags, int region, co // When "flags" < 0 we are adding to the prefix tree where "flags" is used for // "rare" and "region" is the condition nr. // Returns FAIL when out of memory. -static int tree_add_word(spellinfo_T *spin, char_u *word, wordnode_T *root, int flags, int region, - int affixID) +static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root, int flags, + int region, int affixID) { wordnode_T *node = root; wordnode_T *np; @@ -4093,7 +4099,7 @@ static int tree_add_word(spellinfo_T *spin, char_u *word, wordnode_T *root, int // 3. When compressed before, added "compress_added" words // (si_compress_cnt == 1) and the number of free nodes drops below the // maximum word length. -#ifndef SPELL_COMPRESS_ALLWAYS +#ifndef SPELL_COMPRESS_ALWAYS if (spin->si_compress_cnt == 1 // NOLINT(readability/braces) ? spin->si_free_count < MAXWLEN : spin->si_blocks_cnt >= compress_start) @@ -4194,31 +4200,33 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *n // Skip the root itself, it's not actually used. The first sibling is the // start of the tree. - if (root->wn_sibling != NULL) { - hash_init(&ht); - const long n = node_compress(spin, root->wn_sibling, &ht, &tot); + if (root->wn_sibling == NULL) { + return; + } + + hash_init(&ht); + const long n = node_compress(spin, root->wn_sibling, &ht, &tot); #ifndef SPELL_PRINTTREE - if (spin->si_verbose || p_verbose > 2) + if (spin->si_verbose || p_verbose > 2) #endif - { - if (tot > 1000000) { - perc = (tot - n) / (tot / 100); - } else if (tot == 0) { - perc = 0; - } else { - perc = (tot - n) * 100 / tot; - } - vim_snprintf((char *)IObuff, IOSIZE, - _("Compressed %s of %ld nodes; %ld (%ld%%) remaining"), - name, tot, tot - n, perc); - spell_message(spin, (char *)IObuff); + { + if (tot > 1000000) { + perc = (tot - n) / (tot / 100); + } else if (tot == 0) { + perc = 0; + } else { + perc = (tot - n) * 100 / tot; } + vim_snprintf(IObuff, IOSIZE, + _("Compressed %s of %ld nodes; %ld (%ld%%) remaining"), + name, tot, tot - n, perc); + spell_message(spin, IObuff); + } #ifdef SPELL_PRINTTREE - spell_print_tree(root->wn_sibling); + spell_print_tree(root->wn_sibling); #endif - hash_clear(&ht); - } + hash_clear(&ht); } /// Compress a node, its siblings and its children, depth first. @@ -4248,9 +4256,9 @@ static long node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, lo compressed += node_compress(spin, child, ht, tot); // Try to find an identical child. - hash = hash_hash(child->wn_u1.hashkey); + hash = hash_hash((char *)child->wn_u1.hashkey); hi = hash_lookup(ht, (const char *)child->wn_u1.hashkey, - STRLEN(child->wn_u1.hashkey), hash); + strlen((char *)child->wn_u1.hashkey), hash); if (!HASHITEM_EMPTY(hi)) { // There are children we encountered before with a hash value // identical to the current child. Now check if there is one @@ -4277,7 +4285,7 @@ static long node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, lo } else { // No other child has this hash value, add it to the // hashtable. - hash_add_item(ht, hi, child->wn_u1.hashkey, hash); + hash_add_item(ht, hi, (char *)child->wn_u1.hashkey, hash); } } } @@ -4343,7 +4351,7 @@ static int rep_compare(const void *s1, const void *s2) fromto_T *p1 = (fromto_T *)s1; fromto_T *p2 = (fromto_T *)s2; - return strcmp((char *)p1->ft_from, (char *)p2->ft_from); + return strcmp(p1->ft_from, p2->ft_from); } /// Write the Vim .spl file "fname". @@ -4376,7 +4384,7 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) if (spin->si_info != NULL) { putc(SN_INFO, fd); // <sectionID> putc(0, fd); // <sectionflags> - size_t i = STRLEN(spin->si_info); + size_t i = strlen(spin->si_info); put_bytes(fd, i, 4); // <sectionlen> fwv &= fwrite(spin->si_info, i, 1, fd); // <infotext> } @@ -4439,7 +4447,7 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) putc(SN_MIDWORD, fd); // <sectionID> putc(SNF_REQUIRED, fd); // <sectionflags> - size_t i = STRLEN(spin->si_midword); + size_t i = strlen(spin->si_midword); put_bytes(fd, i, 4); // <sectionlen> fwv &= fwrite(spin->si_midword, i, 1, fd); // <midword> @@ -4499,8 +4507,8 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) assert(gap->ga_len >= 0); 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> + 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> @@ -4527,8 +4535,8 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) // <sal> : <salfromlen> <salfrom> <saltolen> <salto> fromto_T *ftp = &((fromto_T *)gap->ga_data)[i]; for (unsigned int rr = 1; rr <= 2; rr++) { - char_u *p = rr == 1 ? ftp->ft_from : ftp->ft_to; - l = STRLEN(p); + char *p = rr == 1 ? ftp->ft_from : ftp->ft_to; + l = strlen(p); assert(l < INT_MAX); putc((int)l, fd); if (l > 0) { @@ -4544,13 +4552,13 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) putc(SN_SOFO, fd); // <sectionID> putc(0, fd); // <sectionflags> - size_t l = STRLEN(spin->si_sofofr); - put_bytes(fd, l + STRLEN(spin->si_sofoto) + 4, 4); // <sectionlen> + size_t l = strlen(spin->si_sofofr); + put_bytes(fd, l + strlen(spin->si_sofoto) + 4, 4); // <sectionlen> put_bytes(fd, l, 2); // <sofofromlen> fwv &= fwrite(spin->si_sofofr, l, 1, fd); // <sofofrom> - l = STRLEN(spin->si_sofoto); + l = strlen(spin->si_sofoto); put_bytes(fd, l, 2); // <sofotolen> fwv &= fwrite(spin->si_sofoto, l, 1, fd); // <sofoto> } @@ -4571,7 +4579,7 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) todo = spin->si_commonwords.ht_used; for (hi = spin->si_commonwords.ht_array; todo > 0; hi++) { if (!HASHITEM_EMPTY(hi)) { - size_t l = STRLEN(hi->hi_key) + 1; + size_t l = strlen(hi->hi_key) + 1; len += l; if (round == 2) { // <word> fwv &= fwrite(hi->hi_key, l, 1, fd); @@ -4637,7 +4645,7 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) putc(SN_COMPOUND, fd); // <sectionID> putc(0, fd); // <sectionflags> - size_t l = STRLEN(spin->si_compflags); + size_t l = strlen(spin->si_compflags); assert(spin->si_comppat.ga_len >= 0); for (size_t i = 0; i < (size_t)spin->si_comppat.ga_len; i++) { l += strlen(((char **)(spin->si_comppat.ga_data))[i]) + 1; @@ -4657,7 +4665,7 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) fwv &= fwrite(p, strlen(p), 1, fd); // <comppattext> } // <compflags> - fwv &= fwrite(spin->si_compflags, STRLEN(spin->si_compflags), 1, fd); + fwv &= fwrite(spin->si_compflags, strlen(spin->si_compflags), 1, fd); } // SN_NOBREAK: NOBREAK flag @@ -4676,7 +4684,7 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) putc(SN_SYLLABLE, fd); // <sectionID> putc(0, fd); // <sectionflags> - size_t l = STRLEN(spin->si_syllable); + size_t l = strlen(spin->si_syllable); put_bytes(fd, l, 4); // <sectionlen> fwv &= fwrite(spin->si_syllable, l, 1, fd); // <syllable> } @@ -4878,16 +4886,18 @@ void ex_mkspell(exarg_T *eap) char *arg = eap->arg; bool ascii = false; - if (STRNCMP(arg, "-ascii", 6) == 0) { + if (strncmp(arg, "-ascii", 6) == 0) { ascii = true; arg = skipwhite(arg + 6); } // Expand all the remaining arguments (e.g., $VIMRUNTIME). - if (get_arglist_exp(arg, &fcount, &fnames, false) == OK) { - mkspell(fcount, fnames, ascii, eap->forceit, false); - FreeWild(fcount, fnames); + if (get_arglist_exp(arg, &fcount, &fnames, false) != OK) { + return; } + + mkspell(fcount, fnames, ascii, eap->forceit, false); + FreeWild(fcount, fnames); } // Create the .sug file. @@ -4895,7 +4905,7 @@ void ex_mkspell(exarg_T *eap) // Writes the file with the name "wfname", with ".spl" changed to ".sug". static void spell_make_sugfile(spellinfo_T *spin, char *wfname) { - char_u *fname = NULL; + char *fname = NULL; int len; slang_T *slang; bool free_slang = false; @@ -4953,8 +4963,8 @@ static void spell_make_sugfile(spellinfo_T *spin, char *wfname) // Write the .sug file. // Make the file name by changing ".spl" to ".sug". fname = xmalloc(MAXPATHL); - STRLCPY(fname, wfname, MAXPATHL); - len = (int)STRLEN(fname); + xstrlcpy(fname, wfname, MAXPATHL); + len = (int)strlen(fname); fname[len - 2] = 'u'; fname[len - 1] = 'g'; sug_write(spin, fname); @@ -4991,7 +5001,7 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang) // Go through the whole case-folded tree, soundfold each word and put it // in the trie. - byts = slang->sl_fbyts; + byts = (char_u *)slang->sl_fbyts; idxs = slang->sl_fidxs; arridx[0] = 0; @@ -5018,7 +5028,7 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang) if (c == 0) { // Sound-fold the word. tword[depth] = NUL; - spell_soundfold(slang, tword, true, tsalword); + spell_soundfold(slang, (char *)tword, true, (char *)tsalword); // We use the "flags" field for the MSB of the wordnr, // "region" for the LSB of the wordnr. @@ -5182,18 +5192,18 @@ static int offset2bytes(int nr, char_u *buf) } // Write the .sug file in "fname". -static void sug_write(spellinfo_T *spin, char_u *fname) +static void sug_write(spellinfo_T *spin, char *fname) { // Create the file. Note that an existing file is silently overwritten! - FILE *fd = os_fopen((char *)fname, "w"); + FILE *fd = os_fopen(fname, "w"); if (fd == NULL) { semsg(_(e_notopen), fname); return; } - vim_snprintf((char *)IObuff, IOSIZE, + vim_snprintf(IObuff, IOSIZE, _("Writing suggestion file %s..."), fname); - spell_message(spin, (char *)IObuff); + spell_message(spin, IObuff); // <SUGHEADER>: <fileID> <versionnr> <timestamp> if (fwrite(VIMSUGMAGIC, VIMSUGMAGICL, (size_t)1, fd) != 1) { // <fileID> @@ -5232,8 +5242,8 @@ static void sug_write(spellinfo_T *spin, char_u *fname) for (linenr_T lnum = 1; lnum <= wcount; lnum++) { // <sugline>: <sugnr> ... NUL - char_u *line = (char_u *)ml_get_buf(spin->si_spellbuf, lnum, false); - size_t len = STRLEN(line) + 1; + char *line = ml_get_buf(spin->si_spellbuf, lnum, false); + size_t len = strlen(line) + 1; if (fwrite(line, len, 1, fd) == 0) { emsg(_(e_write)); goto theend; @@ -5247,9 +5257,9 @@ static void sug_write(spellinfo_T *spin, char_u *fname) emsg(_(e_write)); } - vim_snprintf((char *)IObuff, IOSIZE, + vim_snprintf(IObuff, IOSIZE, _("Estimated runtime memory use: %d bytes"), spin->si_memtot); - spell_message(spin, (char *)IObuff); + spell_message(spin, IObuff); theend: // close the file @@ -5267,7 +5277,7 @@ theend: /// @param added_word invoked through "zg" static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool added_word) { - char_u *fname = NULL; + char *fname = NULL; char **innames; int incount; afffile_T *(afile[MAXREGIONS]); @@ -5284,9 +5294,9 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool ga_init(&spin.si_rep, (int)sizeof(fromto_T), 20); ga_init(&spin.si_repsal, (int)sizeof(fromto_T), 20); ga_init(&spin.si_sal, (int)sizeof(fromto_T), 20); - ga_init(&spin.si_map, (int)sizeof(char_u), 100); - ga_init(&spin.si_comppat, (int)sizeof(char_u *), 20); - ga_init(&spin.si_prefcond, (int)sizeof(char_u *), 50); + ga_init(&spin.si_map, (int)sizeof(char), 100); + ga_init(&spin.si_comppat, (int)sizeof(char *), 20); + ga_init(&spin.si_prefcond, (int)sizeof(char *), 50); hash_init(&spin.si_commonwords); spin.si_newcompID = 127; // start compound ID at first maximum @@ -5298,7 +5308,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool char *wfname = xmalloc(MAXPATHL); if (fcount >= 1) { - len = (int)STRLEN(fnames[0]); + len = (int)strlen(fnames[0]); if (fcount == 1 && len > 4 && strcmp(fnames[0] + len - 4, ".add") == 0) { // For ":mkspell path/en.latin1.add" output file is // "path/en.latin1.add.spl". @@ -5308,14 +5318,14 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool // For ":mkspell path/vim" output file is "path/vim.latin1.spl". incount = 1; vim_snprintf(wfname, MAXPATHL, SPL_FNAME_TMPL, - fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc()); + fnames[0], spin.si_ascii ? "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); + xstrlcpy(wfname, fnames[0], MAXPATHL); } else { // Name should be language, make the file name from it. vim_snprintf(wfname, MAXPATHL, SPL_FNAME_TMPL, - fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc()); + fnames[0], spin.si_ascii ? "ascii" : spell_enc()); } // Check for .ascii.spl. @@ -5387,8 +5397,8 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool spin.si_conv.vc_type = CONV_NONE; spin.si_region = 1 << i; - vim_snprintf((char *)fname, MAXPATHL, "%s.aff", innames[i]); - if (os_path_exists((char *)fname)) { + vim_snprintf(fname, MAXPATHL, "%s.aff", innames[i]); + if (os_path_exists(fname)) { // Read the .aff file. Will init "spin->si_conv" based on the // "SET" line. afile[i] = spell_read_aff(&spin, fname); @@ -5396,8 +5406,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool error = true; } else { // Read the .dic file and store the words in the trees. - vim_snprintf((char *)fname, MAXPATHL, "%s.dic", - innames[i]); + vim_snprintf(fname, MAXPATHL, "%s.dic", innames[i]); if (spell_read_dic(&spin, fname, afile[i]) == FAIL) { error = true; } @@ -5405,7 +5414,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool } else { // No .aff file, try reading the file as a word list. Store // the words in the trees. - if (spell_read_wordfile(&spin, (char_u *)innames[i]) == FAIL) { + if (spell_read_wordfile(&spin, innames[i]) == FAIL) { error = true; } } @@ -5428,20 +5437,20 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool if (!error && !got_int) { // Write the info in the spell file. - vim_snprintf((char *)IObuff, IOSIZE, + vim_snprintf(IObuff, IOSIZE, _("Writing spell file %s..."), wfname); - spell_message(&spin, (char *)IObuff); + spell_message(&spin, IObuff); error = write_vim_spell(&spin, wfname) == FAIL; spell_message(&spin, _("Done!")); - vim_snprintf((char *)IObuff, IOSIZE, + vim_snprintf(IObuff, IOSIZE, _("Estimated runtime memory use: %d bytes"), spin.si_memtot); - spell_message(&spin, (char *)IObuff); + spell_message(&spin, IObuff); // If the file is loaded need to reload it. if (!error) { - spell_reload_one((char_u *)wfname, added_word); + spell_reload_one(wfname, added_word); } } @@ -5499,7 +5508,7 @@ static void spell_message(const spellinfo_T *spin, char *str) // ":[count]spellrare {word}" void ex_spell(exarg_T *eap) { - spell_add_word((char_u *)eap->arg, (int)strlen(eap->arg), + spell_add_word(eap->arg, (int)strlen(eap->arg), eap->cmdidx == CMD_spellwrong ? SPELL_ADD_BAD : eap->cmdidx == CMD_spellrare ? SPELL_ADD_RARE : SPELL_ADD_GOOD, eap->forceit ? 0 : (int)eap->line2, @@ -5511,31 +5520,31 @@ void ex_spell(exarg_T *eap) /// @param what SPELL_ADD_ values /// @param idx "zG" and "zW": zero, otherwise index in 'spellfile' /// @param bool // true for "zug", "zuG", "zuw" and "zuW" -void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo) +void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo) { FILE *fd = NULL; buf_T *buf = NULL; bool new_spf = false; char *fname; - char_u *fnamebuf = NULL; - char_u line[MAXWLEN * 2]; + char *fnamebuf = NULL; + char line[MAXWLEN * 2]; long fpos, fpos_next = 0; int i; - char_u *spf; + char *spf; - if (!valid_spell_word((char *)word, (char *)word + len)) { + if (!valid_spell_word(word, word + len)) { emsg(_(e_illegal_character_in_word)); return; } if (idx == 0) { // use internal wordlist if (int_wordlist == NULL) { - int_wordlist = (char_u *)vim_tempname(); + int_wordlist = vim_tempname(); if (int_wordlist == NULL) { return; } } - fname = (char *)int_wordlist; + fname = int_wordlist; } else { // If 'spellfile' isn't set figure out a good default value. if (*curwin->w_s->b_p_spf == NUL) { @@ -5549,8 +5558,8 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo } fnamebuf = xmalloc(MAXPATHL); - for (spf = (char_u *)curwin->w_s->b_p_spf, i = 1; *spf != NUL; i++) { - copy_option_part((char **)&spf, (char *)fnamebuf, MAXPATHL, ","); + for (spf = curwin->w_s->b_p_spf, i = 1; *spf != NUL; i++) { + copy_option_part(&spf, fnamebuf, MAXPATHL, ","); if (i == idx) { break; } @@ -5562,7 +5571,7 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo } // Check that the user isn't editing the .add file somewhere. - buf = buflist_findname_exp((char *)fnamebuf); + buf = buflist_findname_exp(fnamebuf); if (buf != NULL && buf->b_ml.ml_mfp == NULL) { buf = NULL; } @@ -5572,7 +5581,7 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo return; } - fname = (char *)fnamebuf; + fname = fnamebuf; } if (what == SPELL_ADD_BAD || undo) { @@ -5580,14 +5589,14 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo // since its flags sort before the one with WF_BANNED. fd = os_fopen(fname, "r"); if (fd != NULL) { - while (!vim_fgets(line, MAXWLEN * 2, fd)) { + while (!vim_fgets((char *)line, MAXWLEN * 2, fd)) { fpos = fpos_next; fpos_next = ftell(fd); if (fpos_next < 0) { break; // should never happen } - if (STRNCMP(word, line, len) == 0 - && (line[len] == '/' || line[len] < ' ')) { + if (strncmp(word, line, (size_t)len) == 0 + && (line[len] == '/' || (uint8_t)line[len] < ' ')) { // Found duplicate word. Remove it by writing a '#' at // the start of the line. Mixing reading and writing // doesn't work for all systems, close the file first. @@ -5599,7 +5608,7 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo if (fseek(fd, fpos, SEEK_SET) == 0) { fputc('#', fd); if (undo) { - home_replace(NULL, fname, (char *)NameBuff, MAXPATHL, true); + home_replace(NULL, fname, NameBuff, MAXPATHL, true); smsg(_("Word '%.*s' removed from %s"), len, word, NameBuff); } } @@ -5624,7 +5633,7 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo // file. We may need to create the "spell" directory first. We // already checked the runtime directory is writable in // init_spellfile(). - if (!dir_of_file_exists((char_u *)fname) + if (!dir_of_file_exists(fname) && (p = (char_u *)path_tail_with_sep(fname)) != (char_u *)fname) { int c = *p; @@ -5649,7 +5658,7 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo } fclose(fd); - home_replace(NULL, fname, (char *)NameBuff, MAXPATHL, true); + home_replace(NULL, fname, NameBuff, MAXPATHL, true); smsg(_("Word '%.*s' added to %s"), len, word, NameBuff); } } @@ -5671,84 +5680,86 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo // Initialize 'spellfile' for the current buffer. static void init_spellfile(void) { - char_u *buf; + char *buf; int l; - char_u *fname; - char_u *rtp; - char_u *lend; + char *fname; + char *rtp; + char *lend; bool aspath = false; - 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 = (char_u *)curwin->w_s->b_p_spl; *lend != NUL - && vim_strchr(",._", *lend) == NULL; lend++) { - if (vim_ispathsep(*lend)) { - aspath = true; - lstart = lend + 1; - } + char *lstart = curbuf->b_s.b_p_spl; + + if (*curwin->w_s->b_p_spl == NUL || GA_EMPTY(&curwin->w_s->b_langp)) { + return; + } + + 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 + && vim_strchr(",._", (uint8_t)(*lend)) == NULL; lend++) { + if (vim_ispathsep(*lend)) { + aspath = true; + lstart = lend + 1; } + } - // Loop over all entries in 'runtimepath'. Use the first one where we - // are allowed to write. - rtp = (char_u *)p_rtp; - while (*rtp != NUL) { + // Loop over all entries in 'runtimepath'. Use the first one where we + // are allowed to write. + rtp = p_rtp; + while (*rtp != NUL) { + if (aspath) { + // Use directory of an entry with path, e.g., for + // "/dir/lg.utf-8.spl" use "/dir". + xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lstart - curbuf->b_s.b_p_spl)); + } else { + // Copy the path from 'runtimepath' to buf[]. + copy_option_part(&rtp, buf, MAXPATHL, ","); + } + if (os_file_is_writable(buf) == 2) { + // Use the first language name from 'spelllang' and the + // encoding used in the first loaded .spl file. 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 - (char_u *)curbuf->b_s.b_p_spl); + xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lend - curbuf->b_s.b_p_spl + 1)); } else { - // Copy the path from 'runtimepath' to buf[]. - copy_option_part((char **)&rtp, (char *)buf, MAXPATHL, ","); - } - if (os_file_is_writable((char *)buf) == 2) { - // 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 - (char_u *)curbuf->b_s.b_p_spl + 1); - } else { - // Create the "spell" directory if it doesn't exist yet. - l = (int)STRLEN(buf); - vim_snprintf((char *)buf + l, MAXPATHL - (size_t)l, "/spell"); - if (os_file_is_writable((char *)buf) != 2) { - os_mkdir((char *)buf, 0755); - } - - l = (int)STRLEN(buf); - vim_snprintf((char *)buf + l, MAXPATHL - (size_t)l, - "/%.*s", (int)(lend - lstart), lstart); + // Create the "spell" directory if it doesn't exist yet. + l = (int)strlen(buf); + vim_snprintf(buf + l, MAXPATHL - (size_t)l, "/spell"); + if (os_file_is_writable(buf) != 2) { + os_mkdir(buf, 0755); } - l = (int)STRLEN(buf); - 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_give_err("spellfile", 0L, (const char *)buf, OPT_LOCAL); - break; + + l = (int)strlen(buf); + vim_snprintf(buf + l, MAXPATHL - (size_t)l, + "/%.*s", (int)(lend - lstart), lstart); } - aspath = false; + l = (int)strlen(buf); + fname = LANGP_ENTRY(curwin->w_s->b_langp, 0) + ->lp_slang->sl_fname; + vim_snprintf(buf + l, MAXPATHL - (size_t)l, ".%s.add", + ((fname != NULL + && strstr(path_tail(fname), ".ascii.") != NULL) + ? "ascii" + : (const char *)spell_enc())); + set_option_value_give_err("spellfile", 0L, buf, OPT_LOCAL); + break; } - - xfree(buf); + aspath = false; } + + xfree(buf); } /// Set the spell character tables from strings in the .spl file. /// /// @param cnt length of "flags" -static void set_spell_charflags(char_u *flags, int cnt, char_u *fol) +static void set_spell_charflags(const char_u *flags, int cnt, char *fol) { // We build the new tables here first, so that we can compare with the // previous one. spelltab_T new_st; int i; - char_u *p = fol; + char *p = fol; int c; clear_spell_chartab(&new_st); @@ -5760,7 +5771,7 @@ static void set_spell_charflags(char_u *flags, int cnt, char_u *fol) } if (*p != NUL) { - c = mb_ptr2char_adv((const char_u **)&p); + c = mb_ptr2char_adv((const char **)&p); new_st.st_fold[i + 128] = (char_u)c; if (i + 128 != c && new_st.st_isu[i + 128] && c < 256) { new_st.st_upper[c] = (char_u)(i + 128); @@ -5826,9 +5837,9 @@ static int write_spell_prefcond(FILE *fd, garray_T *gap, size_t *fwv) } // Use map string "map" for languages "lp". -static void set_map_str(slang_T *lp, char_u *map) +static void set_map_str(slang_T *lp, char *map) { - char_u *p; + char *p; int headc = 0; int c; int i; @@ -5849,7 +5860,7 @@ static void set_map_str(slang_T *lp, char_u *map) // "aaa/bbb/ccc/". Fill sl_map_array[c] with the character before c and // before the same slash. For characters above 255 sl_map_hash is used. for (p = map; *p != NUL;) { - c = mb_cptr2char_adv((const char_u **)&p); + c = mb_cptr2char_adv((const char **)&p); if (c == '/') { headc = 0; } else { @@ -5871,10 +5882,10 @@ static void set_map_str(slang_T *lp, char_u *map) b[cl] = NUL; utf_char2bytes(headc, b + cl + 1); b[cl + 1 + headcl] = NUL; - hash = hash_hash((char_u *)b); + hash = hash_hash(b); hi = hash_lookup(&lp->sl_map_hash, (const char *)b, strlen(b), hash); if (HASHITEM_EMPTY(hi)) { - hash_add_item(&lp->sl_map_hash, hi, (char_u *)b, hash); + hash_add_item(&lp->sl_map_hash, hi, b, hash); } else { // This should have been checked when generating the .spl // file. |