From ebd2372f928c6f1cfe823d36aabf479f6930232f Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Thu, 2 Feb 2023 23:56:25 +0100 Subject: refactor: use flexible arrays instead of the length-of-one trick (#22072) The "length-of-one" trick, where the last element of a struct is an array of size 1, but extra size is allocated when calling malloc where it uses more than 1 element in the array, cause problems with some compilers. Some compilers set _FORTIFY_SOURCE=2 by default which incorrectly considers it as an overflow. More information: https://github.com/neovim/neovim/issues/223#issuecomment-1413828554 Using flexible array members allows us to to properly convey to the compiler that its size may be larger than 1. This also enables us to remove lengthy workarounds that are unreliable, as they depend on CMAKE_BUILD_TYPE which isn't defined for multi-config generators. Closes: https://github.com/neovim/neovim/issues/223 --- src/nvim/spellfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 7b124ae6b6..5e7ebc4c87 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -404,7 +404,7 @@ typedef struct sblock_S sblock_T; struct sblock_S { int sb_used; // nr of bytes already in use sblock_T *sb_next; // next block in list - char_u sb_data[1]; // data, actually longer + char_u sb_data[]; // data }; // A node in the tree. -- cgit From c8c930ea785aa393ebc819139913a9e05f0ccd45 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:24:46 +0100 Subject: refactor: reduce scope of locals as per the style guide (#22206) --- src/nvim/spellfile.c | 81 ++++++++++++++++++---------------------------------- 1 file changed, 28 insertions(+), 53 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 5e7ebc4c87..594b05dd6b 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1385,7 +1385,6 @@ static int read_compound(FILE *fd, slang_T *slang, int len) int c; int atstart; int cnt; - garray_T *gap; if (todo < 2) { return SP_FORMERROR; // need at least two bytes @@ -1420,7 +1419,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) todo--; slang->sl_compoptions = c; - gap = &slang->sl_comppat; + garray_T *gap = &slang->sl_comppat; c = get2c(fd); // if (c < 0) { return SP_TRUNCERROR; @@ -1612,7 +1611,6 @@ static void set_sal_first(slang_T *lp) { salfirst_T *sfirst; salitem_T *smp; - int c; garray_T *gap = &lp->sl_sal; sfirst = lp->sl_sal_first; @@ -1624,7 +1622,7 @@ static void set_sal_first(slang_T *lp) // Use the lowest byte of the first character. For latin1 it's // the character, for other encodings it should differ for most // characters. - c = *smp[i].sm_lead_w & 0xff; + int c = *smp[i].sm_lead_w & 0xff; if (sfirst[c] == -1) { sfirst[c] = i; @@ -1738,7 +1736,6 @@ static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx int i; int n; idx_T idx = startidx; - int c; int c2; #define SHARED_MASK 0x8000000 @@ -1754,7 +1751,7 @@ static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx // Read the byte values, flag/region bytes and shared indexes. for (i = 1; i <= len; i++) { - c = getc(fd); // + int c = getc(fd); // if (c < 0) { return SP_TRUNCERROR; } @@ -2434,7 +2431,6 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) && strcmp(cur_aff->ah_key, items[1]) == 0 && itemcnt >= 5) { affentry_T *aff_entry; - bool upper = false; int lasti = 5; // Myspell allows extra text after the item, but that might @@ -2493,6 +2489,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) // COMPOUNDFORBIDFLAG and COMPOUNDPERMITFLAG. if (*items[0] == 'P' && aff->af_pfxpostpone && aff_entry->ae_flags == NULL) { + bool upper = false; // When the chop string is one lower-case letter and // the add string ends in the upper-case letter we set // the "upper" flag, clear "ae_chop" and remove the @@ -2502,10 +2499,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) && aff_entry->ae_add != NULL && aff_entry->ae_chop[utfc_ptr2len(aff_entry->ae_chop)] == NUL) { - int c, c_up; - - c = utf_ptr2char(aff_entry->ae_chop); - c_up = SPELL_TOUPPER(c); + int c = utf_ptr2char(aff_entry->ae_chop); + int c_up = SPELL_TOUPPER(c); if (c_up != c && (aff_entry->ae_cond == NULL || utf_ptr2char(aff_entry->ae_cond) == c)) { @@ -2535,8 +2530,6 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) if (aff_entry->ae_chop == NULL) { int idx; - char_u **pp; - int n; // Find a previously used condition. for (idx = spin->si_prefcond.ga_len - 1; idx >= 0; idx--) { @@ -2548,7 +2541,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) if (idx < 0) { // Not found, add a new condition. idx = spin->si_prefcond.ga_len; - pp = GA_APPEND_VIA_PTR(char_u *, &spin->si_prefcond); + char_u **pp = GA_APPEND_VIA_PTR(char_u *, &spin->si_prefcond); *pp = (aff_entry->ae_cond == NULL) ? NULL : (char_u *)getroom_save(spin, aff_entry->ae_cond); } @@ -2562,7 +2555,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) // PFX_FLAGS is a negative number, so that // tree_add_word() knows this is the prefix tree. - n = PFX_FLAGS; + int n = PFX_FLAGS; if (!cur_aff->ah_combine) { n |= WFP_NC; } @@ -2636,11 +2629,9 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) fname, lnum); } } else if (do_mapline) { - int c; - // Check that every character appears only once. for (p = items[1]; *p != NUL;) { - c = mb_ptr2char_adv((const char **)&p); + int c = mb_ptr2char_adv((const char **)&p); if ((!GA_EMPTY(&spin->si_map) && vim_strchr(spin->si_map.ga_data, c) != NULL) @@ -2791,14 +2782,12 @@ static bool is_aff_rule(char **items, int itemcnt, char *rulename, int mincount) static void aff_process_flags(afffile_T *affile, affentry_T *entry) { 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 = (char_u *)p; - flag = get_affitem(affile->af_flagtype, &p); + char_u *prevp = (char_u *)p; + unsigned flag = get_affitem(affile->af_flagtype, &p); if (flag == affile->af_comppermit || flag == affile->af_compforbid) { STRMOVE(prevp, (char *)p); p = (char *)prevp; @@ -2833,10 +2822,9 @@ static bool spell_info_item(char *s) // returns zero for failure. static unsigned affitem2flag(int flagtype, char *item, char *fname, int lnum) { - unsigned res; char *p = item; - res = get_affitem(flagtype, &p); + unsigned res = get_affitem(flagtype, &p); if (res == 0) { if (flagtype == AFT_NUM) { smsg(_("Flag is not a number in %s line %d: %s"), @@ -2889,30 +2877,27 @@ static unsigned get_affitem(int flagtype, char **pp) /// they fit in one byte. static void process_compflags(spellinfo_T *spin, afffile_T *aff, char *compflags) { - char *p; char *prevp; unsigned flag; compitem_T *ci; int id; - int len; - char_u *tp; 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; + int len = (int)strlen(compflags) + 1; if (spin->si_compflags != NULL) { len += (int)strlen(spin->si_compflags) + 1; } - p = getroom(spin, (size_t)len, false); + char *p = getroom(spin, (size_t)len, false); if (spin->si_compflags != NULL) { STRCPY(p, spin->si_compflags); STRCAT(p, "/"); } spin->si_compflags = p; - tp = (char_u *)p + strlen(p); + char_u *tp = (char_u *)p + strlen(p); for (p = compflags; *p != NUL;) { if (vim_strchr("/?*+[]", (uint8_t)(*p)) != NULL) { @@ -3061,7 +3046,6 @@ static void spell_free_aff(afffile_T *aff) { hashtab_T *ht; hashitem_T *hi; - int todo; affheader_T *ah; affentry_T *ae; @@ -3069,7 +3053,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; + int todo = (int)ht->ht_used; for (hi = ht->ht_array; todo > 0; hi++) { if (!HASHITEM_EMPTY(hi)) { todo--; @@ -3106,7 +3090,6 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) int l; hash_T hash; hashitem_T *hi; - FILE *fd; int lnum = 1; int non_ascii = 0; int retval = OK; @@ -3116,7 +3099,7 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) Timestamp last_msg_time = 0; // Open the file. - fd = os_fopen(fname, "r"); + FILE *fd = os_fopen(fname, "r"); if (fd == NULL) { semsg(_(e_notopen), fname); return FAIL; @@ -3340,15 +3323,13 @@ static int get_affix_flags(afffile_T *affile, char *afflist) // and return the number of affixes. static int get_pfxlist(afffile_T *affile, char *afflist, char_u *store_afflist) { - char *p; - char *prevp; int cnt = 0; int id; char key[AH_KEY_LEN]; hashitem_T *hi; - for (p = afflist; *p != NUL;) { - prevp = p; + for (char *p = afflist; *p != NUL;) { + char *prevp = p; 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. @@ -3375,14 +3356,12 @@ static int get_pfxlist(afffile_T *affile, char *afflist, char_u *store_afflist) // Puts the flags in "store_afflist[]". static void get_compflags(afffile_T *affile, char *afflist, char_u *store_afflist) { - char *p; - char *prevp; int cnt = 0; char key[AH_KEY_LEN]; hashitem_T *hi; - for (p = afflist; *p != NUL;) { - prevp = p; + for (char *p = afflist; *p != NUL;) { + char *prevp = p; if (get_affitem(affile->af_flagtype, &p) != 0) { // A flag is a compound flag if it appears in "af_comp". xstrlcpy(key, prevp, (size_t)(p - prevp) + 1); @@ -3418,7 +3397,6 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ 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; @@ -3435,7 +3413,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ size_t wordlen = strlen(word); int use_condit; - todo = (int)ht->ht_used; + int todo = (int)ht->ht_used; for (hi = ht->ht_array; todo > 0 && retval == OK; hi++) { if (!HASHITEM_EMPTY(hi)) { todo--; @@ -4414,7 +4392,6 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) // the table (avoids that it conflicts). File is shorter too. if (!spin->si_ascii && !spin->si_add) { char folchars[128 * 8]; - int flags; putc(SN_CHARFLAGS, fd); // putc(SNF_REQUIRED, fd); // @@ -4428,7 +4405,7 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) fputc(128, fd); // for (size_t i = 128; i < 256; i++) { - flags = 0; + int flags = 0; if (spelltab.st_isw[i]) { flags |= CF_WORD; } @@ -5528,8 +5505,6 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo) char *fname; char *fnamebuf = NULL; char line[MAXWLEN * 2]; - long fpos, fpos_next = 0; - int i; char *spf; if (!valid_spell_word(word, word + len)) { @@ -5546,6 +5521,7 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo) } fname = int_wordlist; } else { + int i; // If 'spellfile' isn't set figure out a good default value. if (*curwin->w_s->b_p_spf == NUL) { init_spellfile(); @@ -5585,6 +5561,8 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo) } if (what == SPELL_ADD_BAD || undo) { + long fpos_next = 0; + long fpos = 0; // When the word appears as good word we need to remove that one, // since its flags sort before the one with WF_BANNED. fd = os_fopen(fname, "r"); @@ -5784,11 +5762,9 @@ static void set_spell_charflags(const char_u *flags, int cnt, char *fol) static int set_spell_finish(spelltab_T *new_st) { - int i; - if (did_set_spelltab) { // check that it's the same table - for (i = 0; i < 256; i++) { + for (int 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] @@ -5841,7 +5817,6 @@ static void set_map_str(slang_T *lp, char *map) { char *p; int headc = 0; - int c; int i; if (*map == NUL) { @@ -5860,7 +5835,7 @@ static void set_map_str(slang_T *lp, char *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 **)&p); + int c = mb_cptr2char_adv((const char **)&p); if (c == '/') { headc = 0; } else { -- cgit From 4be6c6cf0ddf5e31d4103cb5df06651ba6f4897b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:05:57 +0100 Subject: refactor: replace char_u with char (#21901) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/spellfile.c | 149 ++++++++++++++++++++++++++------------------------- 1 file changed, 75 insertions(+), 74 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 594b05dd6b..22a8587f66 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -386,7 +386,7 @@ typedef struct affheader_S { // Flag used in compound items. typedef struct compitem_S { - char_u ci_key[AH_KEY_LEN]; // key for hashtab == name of compound + char ci_key[AH_KEY_LEN]; // key for hashtab == name of compound unsigned ci_flag; // affix name as number, uses "af_flagtype" int ci_newID; // affix ID after renumbering. } compitem_T; @@ -674,7 +674,7 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent) res = 0; switch (n) { case SN_INFO: - lp->sl_info = READ_STRING(fd, len); // + lp->sl_info = read_string(fd, (size_t)len); // if (lp->sl_info == NULL) { goto endFAIL; } @@ -689,7 +689,7 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent) break; case SN_MIDWORD: - lp->sl_midword = READ_STRING(fd, len); // + lp->sl_midword = read_string(fd, (size_t)len); // if (lp->sl_midword == NULL) { goto endFAIL; } @@ -716,7 +716,7 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent) break; case SN_MAP: - p = (char *)READ_STRING(fd, len); // + p = read_string(fd, (size_t)len); // if (p == NULL) { goto endFAIL; } @@ -749,7 +749,7 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent) break; case SN_SYLLABLE: - lp->sl_syllable = READ_STRING(fd, len); // + lp->sl_syllable = read_string(fd, (size_t)len); // if (lp->sl_syllable == NULL) { goto endFAIL; } @@ -838,8 +838,9 @@ endOK: // Fill in the wordcount fields for a trie. // Returns the total number of words. -static void tree_count_words(const char_u *byts, idx_T *idxs) +static void tree_count_words(const char *byts_in, idx_T *idxs) { + const uint8_t *byts= (const uint8_t *)byts_in; int depth; idx_T arridx[MAXWLEN]; int curi[MAXWLEN]; @@ -1000,8 +1001,8 @@ someerror: // Need to put word counts in the word tries, so that we can find // a word by its number. - tree_count_words((char_u *)slang->sl_fbyts, slang->sl_fidxs); - tree_count_words((char_u *)slang->sl_sbyts, slang->sl_sidxs); + tree_count_words(slang->sl_fbyts, slang->sl_fidxs); + tree_count_words(slang->sl_sbyts, slang->sl_sidxs); nextone: if (fd != NULL) { @@ -1017,10 +1018,10 @@ nextone: // Returns NULL when the count is zero. // Sets "*cntp" to SP_*ERROR when there is an error, length of the result // otherwise. -static char_u *read_cnt_string(FILE *fd, int cnt_bytes, int *cntp) +static char *read_cnt_string(FILE *fd, int cnt_bytes, int *cntp) { int cnt = 0; - char_u *str; + char *str; // read the length bytes, MSB first for (int i = 0; i < cnt_bytes; i++) { @@ -1036,7 +1037,7 @@ static char_u *read_cnt_string(FILE *fd, int cnt_bytes, int *cntp) if (cnt == 0) { return NULL; // nothing to read, return NULL } - str = READ_STRING(fd, cnt); + str = read_string(fd, (size_t)cnt); if (str == NULL) { *cntp = SP_OTHERERROR; } @@ -1065,13 +1066,13 @@ static int read_charflags_section(FILE *fd) int flagslen, follen; // - flags = (char *)read_cnt_string(fd, 1, &flagslen); + flags = read_cnt_string(fd, 1, &flagslen); if (flagslen < 0) { return flagslen; } // - fol = read_cnt_string(fd, 2, &follen); + fol = (char_u *)read_cnt_string(fd, 2, &follen); if (follen < 0) { xfree(flags); return follen; @@ -1143,14 +1144,14 @@ static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first) for (; gap->ga_len < cnt; gap->ga_len++) { int c; ftp = &((fromto_T *)gap->ga_data)[gap->ga_len]; - ftp->ft_from = (char *)read_cnt_string(fd, 1, &c); + ftp->ft_from = read_cnt_string(fd, 1, &c); if (c < 0) { return c; } if (c == 0) { return SP_FORMERROR; } - ftp->ft_to = (char *)read_cnt_string(fd, 1, &c); + ftp->ft_to = read_cnt_string(fd, 1, &c); if (c <= 0) { xfree(ftp->ft_from); if (c < 0) { @@ -1181,7 +1182,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) garray_T *gap; salitem_T *smp; int ccnt; - char_u *p; + char *p; slang->sl_sofo = false; @@ -1215,7 +1216,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) return SP_TRUNCERROR; } p = xmalloc((size_t)ccnt + 2); - smp->sm_lead = (char *)p; + smp->sm_lead = p; // Read up to the first special char into sm_lead. int i = 0; @@ -1224,9 +1225,9 @@ static int read_sal_section(FILE *fd, slang_T *slang) if (vim_strchr("0123456789(-<^$", c) != NULL) { break; } - *p++ = (char_u)c; + *p++ = (char)(uint8_t)c; } - smp->sm_leadlen = (int)(p - (char_u *)smp->sm_lead); + smp->sm_leadlen = (int)(p - smp->sm_lead); *p++ = NUL; // Put (abc) chars in sm_oneof, if any. @@ -1237,7 +1238,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) if (c == ')') { break; } - *p++ = (char_u)c; + *p++ = (char)(uint8_t)c; } *p++ = NUL; if (++i < ccnt) { @@ -1248,22 +1249,22 @@ static int read_sal_section(FILE *fd, slang_T *slang) } // Any following chars go in sm_rules. - smp->sm_rules = (char *)p; + smp->sm_rules = p; if (i < ccnt) { // store the char we got while checking for end of sm_lead - *p++ = (char_u)c; + *p++ = (char)(uint8_t)c; } i++; if (i < ccnt) { SPELL_READ_NONNUL_BYTES( // - (char *)p, (size_t)(ccnt - i), fd, + p, (size_t)(ccnt - i), fd, xfree(smp->sm_lead)); p += (ccnt - i); } *p++ = NUL; // - smp->sm_to = (char *)read_cnt_string(fd, 1, &ccnt); + smp->sm_to = read_cnt_string(fd, 1, &ccnt); if (ccnt < 0) { xfree(smp->sm_lead); return ccnt; @@ -1275,7 +1276,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((char *)smp->sm_oneof); + smp->sm_oneof_w = mb_str2wide(smp->sm_oneof); } if (smp->sm_to == NULL) { smp->sm_to_w = NULL; @@ -1290,12 +1291,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 = (char *)p; + smp->sm_lead = 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 = (char *)p; + smp->sm_rules = p; smp->sm_to = NULL; smp->sm_to_w = NULL; gap->ga_len++; @@ -1350,13 +1351,13 @@ static int read_sofo_section(FILE *fd, slang_T *slang) slang->sl_sofo = true; // - from = (char *)read_cnt_string(fd, 2, &cnt); + from = read_cnt_string(fd, 2, &cnt); if (cnt < 0) { return cnt; } // - to = (char *)read_cnt_string(fd, 2, &cnt); + to = read_cnt_string(fd, 2, &cnt); if (cnt < 0) { xfree(from); return cnt; @@ -1428,7 +1429,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) 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); + ((char **)(gap->ga_data))[gap->ga_len++] = read_cnt_string(fd, 1, &cnt); // if (cnt < 0) { return cnt; @@ -1464,7 +1465,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) uint8_t *crp = xmalloc((size_t)todo + 1); slang->sl_comprules = crp; - char_u *pp = (char_u *)pat; + char *pp = pat; *pp++ = '^'; *pp++ = '\\'; *pp++ = '('; @@ -1520,7 +1521,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) if (c == '?' || c == '+' || c == '~') { *pp++ = '\\'; // "a?" becomes "a\?", "a+" becomes "a\+" } - pp += utf_char2bytes(c, (char *)pp); + pp += utf_char2bytes(c, pp); } } @@ -1954,9 +1955,9 @@ static void spell_print_node(wordnode_T *node, int depth) PRINTSOME(line1, depth, "(%d)", node->wn_nr, 0); PRINTSOME(line2, depth, " ", 0, 0); PRINTSOME(line3, depth, " ", 0, 0); - msg((char_u *)line1); - msg((char_u *)line2); - msg((char_u *)line3); + msg(line1); + msg(line2); + msg(line3); } else { node->wn_u1.index = true; @@ -1980,9 +1981,9 @@ static void spell_print_node(wordnode_T *node, int depth) } if (node->wn_byte == NUL) { - msg((char_u *)line1); - msg((char_u *)line2); - msg((char_u *)line3); + msg(line1); + msg(line2); + msg(line3); } // do the children @@ -2789,7 +2790,7 @@ static void aff_process_flags(afffile_T *affile, affentry_T *entry) char_u *prevp = (char_u *)p; unsigned flag = get_affitem(affile->af_flagtype, &p); if (flag == affile->af_comppermit || flag == affile->af_compforbid) { - STRMOVE(prevp, (char *)p); + STRMOVE(prevp, p); p = (char *)prevp; if (flag == affile->af_comppermit) { entry->ae_comppermit = true; @@ -2925,9 +2926,9 @@ static void process_compflags(spellinfo_T *spin, afffile_T *aff, char *compflags id = spin->si_newcompID--; } while (vim_strchr("/?*+[]\\-^", id) != NULL); ci->ci_newID = id; - hash_add(&aff->af_comp, (char *)ci->ci_key); + hash_add(&aff->af_comp, ci->ci_key); } - *tp++ = (char_u)id; + *tp++ = (uint8_t)id; } if (aff->af_flagtype == AFT_NUM && *p == ',') { p++; @@ -3079,21 +3080,21 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) { hashtab_T ht; char line[MAXLINELEN]; - char_u *p; - char_u *afflist; - char_u store_afflist[MAXWLEN]; + char *p; + char *afflist; + char store_afflist[MAXWLEN]; int pfxlen; bool need_affix; char *dw; - char_u *pc; - char_u *w; + char *pc; + char *w; int l; hash_T hash; hashitem_T *hi; int lnum = 1; int non_ascii = 0; int retval = OK; - char_u message[MAXLINELEN + MAXWLEN]; + char message[MAXLINELEN + MAXWLEN]; int flags; int duplicate = 0; Timestamp last_msg_time = 0; @@ -3142,7 +3143,7 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) // Convert from "SET" to 'encoding' when needed. if (spin->si_conv.vc_type != CONV_NONE) { - pc = (char_u *)string_convert(&spin->si_conv, (char *)line, NULL); + pc = string_convert(&spin->si_conv, (char *)line, NULL); if (pc == NULL) { smsg(_("Conversion failure for word in %s line %d: %s"), fname, lnum, line); @@ -3151,7 +3152,7 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) w = pc; } else { pc = NULL; - w = (char_u *)line; + w = line; } // Truncate the word at the "/", set "afflist" to what follows. @@ -3159,7 +3160,7 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) afflist = NULL; for (p = w; *p != NUL; MB_PTR_ADV(p)) { if (*p == '\\' && (p[1] == '\\' || p[1] == '/')) { - STRMOVE(p, (char *)p + 1); + STRMOVE(p, p + 1); } else if (*p == '/') { *p = NUL; afflist = p + 1; @@ -3168,7 +3169,7 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) } // Skip non-ASCII words when "spin->si_ascii" is true. - if (spin->si_ascii && has_non_ascii((char *)w)) { + if (spin->si_ascii && has_non_ascii(w)) { non_ascii++; xfree(pc); continue; @@ -3180,11 +3181,11 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) spin->si_msg_count = 0; if (os_time() > last_msg_time) { last_msg_time = os_time(); - vim_snprintf((char *)message, sizeof(message), + vim_snprintf(message, sizeof(message), _("line %6d, word %6ld - %s"), lnum, spin->si_foldwcount + spin->si_keepwcount, w); msg_start(); - msg_outtrans_long_attr((char *)message, 0); + msg_outtrans_long_attr(message, 0); msg_clr_eos(); msg_didout = false; msg_col = 0; @@ -3193,7 +3194,7 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) } // Store the word in the hashtable to be able to find duplicates. - dw = getroom_save(spin, (char *)w); + dw = getroom_save(spin, w); if (dw == NULL) { retval = FAIL; xfree(pc); @@ -3201,7 +3202,7 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) } hash = hash_hash(dw); - hi = hash_lookup(&ht, (const char *)dw, strlen(dw), hash); + hi = hash_lookup(&ht, dw, strlen(dw), hash); if (!HASHITEM_EMPTY(hi)) { if (p_verbose > 0) { smsg(_("Duplicate word in %s line %d: %s"), @@ -3221,45 +3222,45 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) need_affix = false; if (afflist != NULL) { // Extract flags from the affix list. - flags |= get_affix_flags(affile, (char *)afflist); + flags |= get_affix_flags(affile, afflist); if (affile->af_needaffix != 0 - && flag_in_afflist(affile->af_flagtype, (char *)afflist, + && flag_in_afflist(affile->af_flagtype, 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, (char *)afflist, store_afflist); + pfxlen = get_pfxlist(affile, 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, (char *)afflist, store_afflist + pfxlen); + get_compflags(affile, afflist, (char_u *)store_afflist + pfxlen); } } // Add the word to the word tree(s). if (store_word(spin, dw, flags, spin->si_region, - (char *)store_afflist, need_affix) == FAIL) { + 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, (char *)afflist, affile, + if (store_aff_word(spin, dw, afflist, affile, &affile->af_suff, &affile->af_pref, - CONDIT_SUF, flags, (char *)store_afflist, pfxlen) == FAIL) { + CONDIT_SUF, flags, store_afflist, pfxlen) == FAIL) { retval = FAIL; } // Find all matching prefixes and add the resulting words. - if (store_aff_word(spin, dw, (char *)afflist, affile, + if (store_aff_word(spin, dw, afflist, affile, &affile->af_pref, NULL, - CONDIT_SUF, flags, (char *)store_afflist, pfxlen) == FAIL) { + CONDIT_SUF, flags, store_afflist, pfxlen) == FAIL) { retval = FAIL; } } @@ -3321,7 +3322,7 @@ static int get_affix_flags(afffile_T *affile, char *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 *afflist, char_u *store_afflist) +static int get_pfxlist(afffile_T *affile, char *afflist, char *store_afflist) { int cnt = 0; int id; @@ -3338,7 +3339,7 @@ static int get_pfxlist(afffile_T *affile, char *afflist, char_u *store_afflist) if (!HASHITEM_EMPTY(hi)) { id = HI2AH(hi)->ah_newID; if (id != 0) { - store_afflist[cnt++] = (char_u)id; + store_afflist[cnt++] = (char)(uint8_t)id; } } } @@ -3408,7 +3409,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ char *use_pfxlist; int use_pfxlen; bool need_affix; - char_u store_afflist[MAXWLEN]; + char store_afflist[MAXWLEN]; char pfx_pfxlist[MAXWLEN]; size_t wordlen = strlen(word); int use_condit; @@ -3517,7 +3518,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ } else { use_pfxlen = 0; } - use_pfxlist = (char *)store_afflist; + use_pfxlist = store_afflist; // Combine the prefix IDs. Avoid adding the // same ID twice. @@ -3642,7 +3643,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) long lnum = 0; char rline[MAXLINELEN]; char *line; - char_u *pc = NULL; + char *pc = NULL; char_u *p; int l; int retval = OK; @@ -3684,13 +3685,13 @@ static int spell_read_wordfile(spellinfo_T *spin, char *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, rline, NULL); + pc = 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 = (char *)pc; + line = pc; } else { pc = NULL; line = rline; @@ -3907,7 +3908,7 @@ static int store_word(spellinfo_T *spin, char *word, int flags, int region, cons { int len = (int)strlen(word); int ct = captype(word, word + len); - char_u foldword[MAXWLEN]; + char foldword[MAXWLEN]; int res = OK; // Avoid adding illegal bytes to the word tree. @@ -3915,10 +3916,10 @@ static int store_word(spellinfo_T *spin, char *word, int flags, int region, cons return FAIL; } - (void)spell_casefold(curwin, word, len, (char *)foldword, MAXWLEN); + (void)spell_casefold(curwin, word, len, 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, + res = tree_add_word(spin, (char_u *)foldword, spin->si_foldroot, ct | flags, region, p == NULL ? 0 : *p); } if (p == NULL || *p == NUL) { -- cgit From 5f72ab77bff1f1224be5cbbf9423bdddbc25635c Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 12 Feb 2023 18:48:49 +0100 Subject: refactor: reduce scope of locals as per the style guide 3 (#22221) refactor: reduce scope of locals as per the style guide --- src/nvim/spellfile.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 22a8587f66..e9dd0a4d5e 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -897,7 +897,6 @@ void suggest_load_files(void) char *dotp; FILE *fd; char buf[MAXWLEN]; - int i; time_t timestamp; int wcount; int wordnr; @@ -925,7 +924,7 @@ void suggest_load_files(void) } // : - for (i = 0; i < VIMSUGMAGICL; i++) { + for (int i = 0; i < VIMSUGMAGICL; i++) { buf[i] = (char)getc(fd); // } if (strncmp(buf, VIMSUGMAGIC, VIMSUGMAGICL) != 0) { @@ -1734,7 +1733,6 @@ static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx bool prefixtree, int maxprefcondnr) { int len; - int i; int n; idx_T idx = startidx; int c2; @@ -1751,7 +1749,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 (int i = 1; i <= len; i++) { int c = getc(fd); // if (c < 0) { return SP_TRUNCERROR; @@ -1814,7 +1812,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 (int i = 1; i <= len; i++) { if (byts[startidx + i] != 0) { if (idxs[startidx + i] & SHARED_MASK) { idxs[startidx + i] &= ~SHARED_MASK; @@ -2673,9 +2671,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) && sofoto == NULL) { sofoto = getroom_save(spin, items[1]); } else if (strcmp(items[0], "COMMON") == 0) { - int i; - - for (i = 1; i < itemcnt; i++) { + for (int 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, p); @@ -3954,10 +3950,9 @@ static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root wordnode_T *np; wordnode_T *copyp, **copyprev; wordnode_T **prev = NULL; - int i; // Add each byte of the word to the tree, including the NUL at the end. - for (i = 0;; i++) { + for (int 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). @@ -5737,13 +5732,12 @@ 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 *p = fol; int c; clear_spell_chartab(&new_st); - for (i = 0; i < 128; i++) { + for (int 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; @@ -5818,7 +5812,6 @@ static void set_map_str(slang_T *lp, char *map) { char *p; int headc = 0; - int i; if (*map == NUL) { lp->sl_has_map = false; @@ -5827,7 +5820,7 @@ static void set_map_str(slang_T *lp, char *map) lp->sl_has_map = true; // Init the array and hash tables empty. - for (i = 0; i < 256; i++) { + for (int i = 0; i < 256; i++) { lp->sl_map_array[i] = 0; } hash_init(&lp->sl_map_hash); -- cgit From 6cab36e5b7b0d741abe6c5a7c0e20bad30361034 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 4 Mar 2023 13:10:00 +0100 Subject: refactor: replace char_u with char or uint8_t (#22400) Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/spellfile.c | 56 +++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index e9dd0a4d5e..bb2ef1a458 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1079,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((char_u *)flags, flagslen, (char *)fol); + set_spell_charflags(flags, flagslen, (char *)fol); } xfree(flags); @@ -1314,7 +1314,7 @@ static int read_words_section(FILE *fd, slang_T *lp, int len) int done = 0; int i; int c; - char_u word[MAXWLEN]; + uint8_t word[MAXWLEN]; while (done < len) { // Read one word at a time. @@ -1323,7 +1323,7 @@ static int read_words_section(FILE *fd, slang_T *lp, int len) if (c == EOF) { return SP_TRUNCERROR; } - word[i] = (char_u)c; + word[i] = (uint8_t)c; if (word[i] == NUL) { break; } @@ -1480,7 +1480,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) // Add all flags to "sl_compallflags". if (vim_strchr("?*+[]/", c) == NULL && !byte_in_str(slang->sl_compallflags, c)) { - *ap++ = (char_u)c; + *ap++ = (uint8_t)c; *ap = NUL; } @@ -1493,7 +1493,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) atstart = 0; } else { if (!byte_in_str(slang->sl_compstartflags, c)) { - *cp++ = (char_u)c; + *cp++ = (uint8_t)c; *cp = NUL; } if (atstart == 1) { @@ -1508,7 +1508,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) XFREE_CLEAR(slang->sl_comprules); crp = NULL; } else { - *crp++ = (char_u)c; + *crp++ = (uint8_t)c; } } @@ -1709,7 +1709,7 @@ static int spell_read_tree(FILE *fd, char **bytsp, long *bytsp_len, idx_T **idxs *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); + idx = read_tree_node(fd, bp, ip, (int)len, 0, prefixtree, prefixcnt); if (idx < 0) { return idx; } @@ -1729,9 +1729,10 @@ static int spell_read_tree(FILE *fd, char **bytsp, long *bytsp_len, idx_T **idxs /// @param startidx current index in "byts" and "idxs" /// @param prefixtree true for reading PREFIXTREE /// @param maxprefcondnr maximum for -static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx_T startidx, +static idx_T read_tree_node(FILE *fd, char *byts_in, idx_T *idxs, int maxidx, idx_T startidx, bool prefixtree, int maxprefcondnr) { + uint8_t *byts = (uint8_t *)byts_in; int len; int n; idx_T idx = startidx; @@ -1746,7 +1747,7 @@ static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx if (startidx + len >= maxidx) { return SP_FORMERROR; } - byts[idx++] = (char_u)len; + byts[idx++] = (uint8_t)len; // Read the byte values, flag/region bytes and shared indexes. for (int i = 1; i <= len; i++) { @@ -1806,7 +1807,7 @@ static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx c = getc(fd); // } } - byts[idx++] = (char_u)c; + byts[idx++] = (uint8_t)c; } // Recursively read the children for non-shared siblings. @@ -1818,7 +1819,7 @@ static idx_T read_tree_node(FILE *fd, char_u *byts, idx_T *idxs, int maxidx, idx idxs[startidx + i] &= ~SHARED_MASK; } else { idxs[startidx + i] = idx; - idx = read_tree_node(fd, byts, idxs, maxidx, idx, + idx = read_tree_node(fd, (char *)byts, idxs, maxidx, idx, prefixtree, maxprefcondnr); if (idx < 0) { break; @@ -2783,11 +2784,11 @@ static void aff_process_flags(afffile_T *affile, affentry_T *entry) if (entry->ae_flags != NULL && (affile->af_compforbid != 0 || affile->af_comppermit != 0)) { for (p = entry->ae_flags; *p != NUL;) { - char_u *prevp = (char_u *)p; + char *prevp = p; unsigned flag = get_affitem(affile->af_flagtype, &p); if (flag == affile->af_comppermit || flag == affile->af_compforbid) { STRMOVE(prevp, p); - p = (char *)prevp; + p = prevp; if (flag == affile->af_comppermit) { entry->ae_comppermit = true; } else { @@ -2894,12 +2895,12 @@ static void process_compflags(spellinfo_T *spin, afffile_T *aff, char *compflags STRCAT(p, "/"); } spin->si_compflags = p; - char_u *tp = (char_u *)p + strlen(p); + uint8_t *tp = (uint8_t *)p + strlen(p); for (p = compflags; *p != NUL;) { if (vim_strchr("/?*+[]", (uint8_t)(*p)) != NULL) { // Copy non-flag characters directly. - *tp++ = (char_u)(*p++); + *tp++ = (uint8_t)(*p++); } else { // First get the flag number, also checks validity. prevp = p; @@ -3640,7 +3641,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) char rline[MAXLINELEN]; char *line; char *pc = NULL; - char_u *p; + char *p; int l; int retval = OK; bool did_word = false; @@ -3748,7 +3749,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) regionmask = spin->si_region; // Check for flags and region after a slash. - p = (char_u *)vim_strchr(line, '/'); + p = vim_strchr(line, '/'); if (p != NULL) { *p++ = NUL; while (*p != NUL) { @@ -3758,13 +3759,13 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) flags |= WF_BANNED; } else if (*p == '?') { // Rare word. flags |= WF_RARE; - } else if (ascii_isdigit(*p)) { // region number(s) + } else if (ascii_isdigit((uint8_t)(*p))) { // region number(s) if ((flags & WF_REGION) == 0) { // first one regionmask = 0; } flags |= WF_REGION; - l = *p - '0'; + l = (uint8_t)(*p) - '0'; if (l == 0 || l > spin->si_region_count) { smsg(_("Invalid region nr in %s line %ld: %s"), fname, lnum, p); @@ -3817,7 +3818,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) static void *getroom(spellinfo_T *spin, size_t len, bool align) FUNC_ATTR_NONNULL_RET { - char_u *p; + char *p; sblock_T *bl = spin->si_blocks; assert(len <= SBLOCKSIZE); @@ -3837,7 +3838,7 @@ static void *getroom(spellinfo_T *spin, size_t len, bool align) spin->si_blocks_cnt++; } - p = bl->sb_data + bl->sb_used; + p = (char *)bl->sb_data + bl->sb_used; bl->sb_used += (int)len; return p; @@ -3876,7 +3877,7 @@ static wordnode_T *wordtree_alloc(spellinfo_T *spin) /// Control characters and trailing '/' are invalid. Space is OK. static bool valid_spell_word(const char *word, const char *end) { - if (!utf_valid_string((char_u *)word, (char_u *)end)) { + if (!utf_valid_string(word, end)) { return false; } for (const char *p = word; *p != NUL && p < end; p += utfc_ptr2len(p)) { @@ -3913,7 +3914,7 @@ static int store_word(spellinfo_T *spin, char *word, int flags, int region, cons } (void)spell_casefold(curwin, word, len, foldword, MAXWLEN); - for (const char_u *p = (char_u *)pfxlist; res == OK; p++) { + for (const char *p = pfxlist; res == OK; p++) { if (!need_affix || (p != NULL && *p != NUL)) { res = tree_add_word(spin, (char_u *)foldword, spin->si_foldroot, ct | flags, region, p == NULL ? 0 : *p); @@ -3925,7 +3926,7 @@ static int store_word(spellinfo_T *spin, char *word, int flags, int region, cons spin->si_foldwcount++; if (res == OK && (ct == WF_KEEPCAP || (flags & WF_KEEPCAP))) { - for (const char_u *p = (char_u *)pfxlist; res == OK; p++) { + for (const char *p = pfxlist; res == OK; p++) { if (!need_affix || (p != NULL && *p != NUL)) { res = tree_add_word(spin, (char_u *)word, spin->si_keeproot, flags, region, p == NULL ? 0 : *p); @@ -5727,8 +5728,9 @@ static void init_spellfile(void) /// Set the spell character tables from strings in the .spl file. /// /// @param cnt length of "flags" -static void set_spell_charflags(const char_u *flags, int cnt, char *fol) +static void set_spell_charflags(const char *flags_in, int cnt, char *fol) { + const uint8_t *flags = (uint8_t *)flags_in; // We build the new tables here first, so that we can compare with the // previous one. spelltab_T new_st; @@ -5745,9 +5747,9 @@ static void set_spell_charflags(const char_u *flags, int cnt, char *fol) if (*p != NUL) { c = mb_ptr2char_adv((const char **)&p); - new_st.st_fold[i + 128] = (char_u)c; + new_st.st_fold[i + 128] = (uint8_t)c; if (i + 128 != c && new_st.st_isu[i + 128] && c < 256) { - new_st.st_upper[c] = (char_u)(i + 128); + new_st.st_upper[c] = (uint8_t)(i + 128); } } } -- cgit From dde5ce46b2e3e77efc27394b946ef49ce565cd95 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 4 Mar 2023 21:09:50 +0800 Subject: refactor(spell): use uint8_t for "byts" variables (#22519) Avoid casting back and forth. --- src/nvim/spellfile.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index bb2ef1a458..8927b599d0 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -838,9 +838,8 @@ endOK: // Fill in the wordcount fields for a trie. // Returns the total number of words. -static void tree_count_words(const char *byts_in, idx_T *idxs) +static void tree_count_words(const uint8_t *byts, idx_T *idxs) { - const uint8_t *byts= (const uint8_t *)byts_in; int depth; idx_T arridx[MAXWLEN]; int curi[MAXWLEN]; @@ -1675,12 +1674,12 @@ static int *mb_str2wide(char *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 **bytsp, long *bytsp_len, idx_T **idxsp, bool prefixtree, - int prefixcnt) +static int spell_read_tree(FILE *fd, uint8_t **bytsp, long *bytsp_len, idx_T **idxsp, + bool prefixtree, int prefixcnt) FUNC_ATTR_NONNULL_ARG(1, 2, 4) { int idx; - char *bp; + uint8_t *bp; idx_T *ip; // The tree size was computed when writing the file, so that we can @@ -1729,10 +1728,9 @@ static int spell_read_tree(FILE *fd, char **bytsp, long *bytsp_len, idx_T **idxs /// @param startidx current index in "byts" and "idxs" /// @param prefixtree true for reading PREFIXTREE /// @param maxprefcondnr maximum for -static idx_T read_tree_node(FILE *fd, char *byts_in, idx_T *idxs, int maxidx, idx_T startidx, +static idx_T read_tree_node(FILE *fd, uint8_t *byts, idx_T *idxs, int maxidx, idx_T startidx, bool prefixtree, int maxprefcondnr) { - uint8_t *byts = (uint8_t *)byts_in; int len; int n; idx_T idx = startidx; @@ -1819,8 +1817,7 @@ static idx_T read_tree_node(FILE *fd, char *byts_in, idx_T *idxs, int maxidx, id idxs[startidx + i] &= ~SHARED_MASK; } else { idxs[startidx + i] = idx; - idx = read_tree_node(fd, (char *)byts, idxs, maxidx, idx, - prefixtree, maxprefcondnr); + idx = read_tree_node(fd, byts, idxs, maxidx, idx, prefixtree, maxprefcondnr); if (idx < 0) { break; } @@ -4955,7 +4952,7 @@ theend: // Build the soundfold trie for language "slang". static int sug_filltree(spellinfo_T *spin, slang_T *slang) { - char_u *byts; + uint8_t *byts; idx_T *idxs; int depth; idx_T arridx[MAXWLEN]; @@ -4975,7 +4972,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 = (char_u *)slang->sl_fbyts; + byts = slang->sl_fbyts; idxs = slang->sl_fidxs; arridx[0] = 0; -- cgit From d5f6176e6dc4b4e12fc5061ca6e87f4af533e46a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Sat, 1 Apr 2023 02:49:51 +0200 Subject: refactor: add const and remove unnecessary casts (#22841) --- src/nvim/spellfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 8927b599d0..c68eee3526 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -608,7 +608,7 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent) semsg(_(e_notopen), fname); } else if (p_verbose > 2) { verbose_enter(); - smsg((char *)e_notopen, fname); + smsg(e_notopen, fname); verbose_leave(); } goto endFAIL; @@ -4047,7 +4047,7 @@ static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root node = *prev; } #ifdef SPELL_PRINTTREE - smsg((char_u *)"Added \"%s\"", word); + smsg("Added \"%s\"", word); spell_print_tree(root->wn_sibling); #endif -- cgit From d510bfbc8e447b1a60d5ec7faaa8f440eb4ef56f Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 2 Apr 2023 10:11:42 +0200 Subject: refactor: remove char_u (#22829) Closes https://github.com/neovim/neovim/issues/459 --- src/nvim/spellfile.c | 116 +++++++++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 58 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index c68eee3526..aa76dcbd32 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -404,14 +404,14 @@ typedef struct sblock_S sblock_T; struct sblock_S { int sb_used; // nr of bytes already in use sblock_T *sb_next; // next block in list - char_u sb_data[]; // data + char sb_data[]; // data }; // A node in the tree. typedef struct wordnode_S wordnode_T; struct wordnode_S { union { // shared to save space - char_u hashkey[6]; // the hash key, only used while compressing + uint8_t hashkey[6]; // the hash key, only used while compressing int index; // index in written nodes (valid after first // round) } wn_u1; @@ -422,17 +422,17 @@ struct wordnode_S { wordnode_T *wn_child; // child (next byte in word) wordnode_T *wn_sibling; // next sibling (alternate byte in word, // always sorted) - int wn_refs; // Nr. of references to this node. Only - // relevant for first node in a list of - // siblings, in following siblings it is - // always one. - char_u wn_byte; // Byte for this node. NUL for word end + int wn_refs; // Nr. of references to this node. Only + // relevant for first node in a list of + // siblings, in following siblings it is + // always one. + uint8_t wn_byte; // Byte for this node. NUL for word end // Info for when "wn_byte" is NUL. // In PREFIXTREE "wn_region" is used for the prefcondnr. // In the soundfolded word tree "wn_flags" has the MSW of the wordnr and // "wn_region" the LSW of the wordnr. - char_u wn_affixID; // supported/required prefix ID or 0 + uint8_t wn_affixID; // supported/required prefix ID or 0 uint16_t wn_flags; // WF_ flags int16_t wn_region; // region mask @@ -482,7 +482,7 @@ typedef struct spellinfo_S { 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]; + char si_region_name[MAXREGIONS * 2 + 1]; // region names; used only if // si_region_count > 1) @@ -508,7 +508,7 @@ typedef struct spellinfo_S { garray_T si_comppat; // CHECKCOMPOUNDPATTERN items, each stored as // a string char *si_compflags; // flags used for compounding - char_u si_nobreak; // NOBREAK + char si_nobreak; // NOBREAK char *si_syllable; // syllable string garray_T si_prefcond; // table with conditions for postponed // prefixes, each stored as a string @@ -985,7 +985,7 @@ someerror: if (c < 0) { goto someerror; } - GA_APPEND(char_u, &ga, (char_u)c); + GA_APPEND(uint8_t, &ga, (uint8_t)c); if (c == NUL) { break; } @@ -1060,7 +1060,7 @@ static int read_region_section(FILE *fd, slang_T *lp, int len) static int read_charflags_section(FILE *fd) { char *flags; - char_u *fol; + char *fol; int flagslen, follen; // @@ -1070,7 +1070,7 @@ static int read_charflags_section(FILE *fd) } // - fol = (char_u *)read_cnt_string(fd, 2, &follen); + fol = read_cnt_string(fd, 2, &follen); if (follen < 0) { xfree(flags); return follen; @@ -1078,7 +1078,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, (char *)fol); + set_spell_charflags(flags, flagslen, fol); } xfree(flags); @@ -2538,9 +2538,9 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) if (idx < 0) { // Not found, add a new condition. idx = spin->si_prefcond.ga_len; - char_u **pp = GA_APPEND_VIA_PTR(char_u *, &spin->si_prefcond); + char **pp = GA_APPEND_VIA_PTR(char *, &spin->si_prefcond); *pp = (aff_entry->ae_cond == NULL) ? - NULL : (char_u *)getroom_save(spin, aff_entry->ae_cond); + NULL : getroom_save(spin, aff_entry->ae_cond); } // Add the prefix to the prefix tree. @@ -2565,7 +2565,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) if (aff_entry->ae_compforbid) { n |= WFP_COMPFORBID; } - tree_add_word(spin, (char_u *)p, spin->si_prefroot, n, + tree_add_word(spin, p, spin->si_prefroot, n, idx, cur_aff->ah_newID); did_postpone_prefix = true; } @@ -3232,7 +3232,7 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) 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, (char_u *)store_afflist + pfxlen); + get_compflags(affile, afflist, store_afflist + pfxlen); } } @@ -3349,7 +3349,7 @@ static int get_pfxlist(afffile_T *affile, char *afflist, char *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 *afflist, char_u *store_afflist) +static void get_compflags(afffile_T *affile, char *afflist, char *store_afflist) { int cnt = 0; char key[AH_KEY_LEN]; @@ -3362,7 +3362,7 @@ static void get_compflags(afffile_T *affile, char *afflist, char_u *store_afflis 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; + store_afflist[cnt++] = (char)(uint8_t)HI2CI(hi)->ci_newID; } } if (affile->af_flagtype == AFT_NUM && *p == ',') { @@ -3530,7 +3530,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ if (spin->si_compflags != NULL) { // Get compound IDS from the affix list. get_compflags(affile, ae->ae_flags, - (char_u *)use_pfxlist + use_pfxlen); + use_pfxlist + use_pfxlen); } else { use_pfxlist[use_pfxlen] = NUL; } @@ -3835,7 +3835,7 @@ static void *getroom(spellinfo_T *spin, size_t len, bool align) spin->si_blocks_cnt++; } - p = (char *)bl->sb_data + bl->sb_used; + p = bl->sb_data + bl->sb_used; bl->sb_used += (int)len; return p; @@ -3913,7 +3913,7 @@ static int store_word(spellinfo_T *spin, char *word, int flags, int region, cons (void)spell_casefold(curwin, word, len, foldword, MAXWLEN); for (const char *p = pfxlist; res == OK; p++) { if (!need_affix || (p != NULL && *p != NUL)) { - res = tree_add_word(spin, (char_u *)foldword, spin->si_foldroot, ct | flags, + res = tree_add_word(spin, foldword, spin->si_foldroot, ct | flags, region, p == NULL ? 0 : *p); } if (p == NULL || *p == NUL) { @@ -3925,7 +3925,7 @@ static int store_word(spellinfo_T *spin, char *word, int flags, int region, cons if (res == OK && (ct == WF_KEEPCAP || (flags & WF_KEEPCAP))) { for (const char *p = pfxlist; res == OK; p++) { if (!need_affix || (p != NULL && *p != NUL)) { - res = tree_add_word(spin, (char_u *)word, spin->si_keeproot, flags, + res = tree_add_word(spin, word, spin->si_keeproot, flags, region, p == NULL ? 0 : *p); } if (p == NULL || *p == NUL) { @@ -3941,7 +3941,7 @@ static int store_word(spellinfo_T *spin, char *word, int flags, int region, cons // 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, const char_u *word, wordnode_T *root, int flags, +static int tree_add_word(spellinfo_T *spin, const char *word, wordnode_T *root, int flags, int region, int affixID) { wordnode_T *node = root; @@ -3993,7 +3993,7 @@ static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root // higher byte value. For zero bytes (end of word) the sorting is // done on flags and then on affixID. while (node != NULL - && (node->wn_byte < word[i] + && (node->wn_byte < (uint8_t)word[i] || (node->wn_byte == NUL && (flags < 0 ? node->wn_affixID < (unsigned)affixID @@ -4007,7 +4007,7 @@ static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root node = *prev; } if (node == NULL - || node->wn_byte != word[i] + || node->wn_byte != (uint8_t)word[i] || (word[i] == NUL && (flags < 0 || spin->si_sugtree @@ -4018,7 +4018,7 @@ static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root if (np == NULL) { return FAIL; } - np->wn_byte = word[i]; + np->wn_byte = (uint8_t)word[i]; // If "node" is NULL this is a new child or the end of the sibling // list: ref count is one. Otherwise use ref count of sibling and @@ -4040,7 +4040,7 @@ static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root if (word[i] == NUL) { node->wn_flags = (uint16_t)flags; node->wn_region |= (int16_t)region; - node->wn_affixID = (char_u)affixID; + node->wn_affixID = (uint8_t)affixID; break; } prev = &node->wn_child; @@ -4266,7 +4266,7 @@ static long node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, lo // Make a hash key for the node and its siblings, so that we can quickly // find a lookalike node. This must be done after compressing the sibling // list, otherwise the hash key would become invalid by the compression. - node->wn_u1.hashkey[0] = (char_u)len; + node->wn_u1.hashkey[0] = (uint8_t)len; nr = 0; for (np = node; np != NULL; np = np->wn_sibling) { if (np->wn_byte == NUL) { @@ -4281,13 +4281,13 @@ static long node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, lo // Avoid NUL bytes, it terminates the hash key. n = nr & 0xff; - node->wn_u1.hashkey[1] = n == 0 ? 1 : (char_u)n; + node->wn_u1.hashkey[1] = n == 0 ? 1 : (uint8_t)n; n = (nr >> 8) & 0xff; - node->wn_u1.hashkey[2] = n == 0 ? 1 : (char_u)n; + node->wn_u1.hashkey[2] = n == 0 ? 1 : (uint8_t)n; n = (nr >> 16) & 0xff; - node->wn_u1.hashkey[3] = n == 0 ? 1 : (char_u)n; + node->wn_u1.hashkey[3] = n == 0 ? 1 : (uint8_t)n; n = (nr >> 24) & 0xff; - node->wn_u1.hashkey[4] = n == 0 ? 1 : (char_u)n; + node->wn_u1.hashkey[4] = n == 0 ? 1 : (uint8_t)n; node->wn_u1.hashkey[5] = NUL; // Check for CTRL-C pressed now and then. @@ -4957,8 +4957,8 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang) int depth; idx_T arridx[MAXWLEN]; int curi[MAXWLEN]; - char_u tword[MAXWLEN]; - char_u tsalword[MAXWLEN]; + char tword[MAXWLEN]; + char tsalword[MAXWLEN]; int c; idx_T n; unsigned words_done = 0; @@ -4999,7 +4999,7 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang) if (c == 0) { // Sound-fold the word. tword[depth] = NUL; - spell_soundfold(slang, (char *)tword, true, (char *)tsalword); + spell_soundfold(slang, tword, true, tsalword); // We use the "flags" field for the MSB of the wordnr, // "region" for the LSB of the wordnr. @@ -5024,7 +5024,7 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang) } } else { // Normal char, go one level deeper. - tword[depth++] = (char_u)c; + tword[depth++] = (char)(uint8_t)c; arridx[depth] = idxs[n]; curi[depth] = 1; wordcount[depth] = 0; @@ -5090,12 +5090,11 @@ static int sug_filltable(spellinfo_T *spin, wordnode_T *node, int startwordnr, g // following bytes. nr -= prev_nr; prev_nr += nr; - gap->ga_len += offset2bytes(nr, - (char_u *)gap->ga_data + gap->ga_len); + gap->ga_len += offset2bytes(nr, (char *)gap->ga_data + gap->ga_len); } // add the NUL byte - ((char_u *)gap->ga_data)[gap->ga_len++] = NUL; + ((char *)gap->ga_data)[gap->ga_len++] = NUL; if (ml_append_buf(spin->si_spellbuf, (linenr_T)wordnr, gap->ga_data, gap->ga_len, true) == FAIL) { @@ -5126,8 +5125,9 @@ static int sug_filltable(spellinfo_T *spin, wordnode_T *node, int startwordnr, g // Convert an offset into a minimal number of bytes. // Similar to utf_char2byters, but use 8 bits in followup bytes and avoid NUL // bytes. -static int offset2bytes(int nr, char_u *buf) +static int offset2bytes(int nr, char *buf_in) { + uint8_t *buf = (uint8_t *)buf_in; int rem; int b1, b2, b3, b4; @@ -5140,25 +5140,25 @@ static int offset2bytes(int nr, char_u *buf) b4 = rem / 255 + 1; if (b4 > 1 || b3 > 0x1f) { // 4 bytes - buf[0] = (char_u)(0xe0 + b4); - buf[1] = (char_u)b3; - buf[2] = (char_u)b2; - buf[3] = (char_u)b1; + buf[0] = (uint8_t)(0xe0 + b4); + buf[1] = (uint8_t)b3; + buf[2] = (uint8_t)b2; + buf[3] = (uint8_t)b1; return 4; } if (b3 > 1 || b2 > 0x3f) { // 3 bytes - buf[0] = (char_u)(0xc0 + b3); - buf[1] = (char_u)b2; - buf[2] = (char_u)b1; + buf[0] = (uint8_t)(0xc0 + b3); + buf[1] = (uint8_t)b2; + buf[2] = (uint8_t)b1; return 3; } if (b2 > 1 || b1 > 0x7f) { // 2 bytes - buf[0] = (char_u)(0x80 + b2); - buf[1] = (char_u)b1; + buf[0] = (uint8_t)(0x80 + b2); + buf[1] = (uint8_t)b1; return 2; } // 1 byte - buf[0] = (char_u)b1; + buf[0] = (uint8_t)b1; return 1; } @@ -5342,8 +5342,8 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool semsg(_("E755: Invalid region in %s"), innames[i]); goto theend; } - spin.si_region_name[i * 2] = (char_u)TOLOWER_ASC(innames[i][len - 2]); - spin.si_region_name[i * 2 + 1] = (char_u)TOLOWER_ASC(innames[i][len - 1]); + spin.si_region_name[i * 2] = (char)(uint8_t)TOLOWER_ASC(innames[i][len - 2]); + spin.si_region_name[i * 2 + 1] = (char)(uint8_t)TOLOWER_ASC(innames[i][len - 1]); } } spin.si_region_count = incount; @@ -5599,21 +5599,21 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo) if (!undo) { fd = os_fopen(fname, "a"); if (fd == NULL && new_spf) { - char_u *p; + char *p; // We just initialized the 'spellfile' option and can't open the // 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(fname) - && (p = (char_u *)path_tail_with_sep(fname)) != (char_u *)fname) { - int c = *p; + && (p = path_tail_with_sep(fname)) != fname) { + char c = *p; // The directory doesn't exist. Try creating it and opening // the file again. *p = NUL; os_mkdir(fname, 0755); - *p = (char_u)c; + *p = c; fd = os_fopen(fname, "a"); } } -- cgit From 371823d407d7d7519735131bcad4670c62a731a7 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Wed, 5 Apr 2023 21:13:53 +0200 Subject: refactor: make error message definitions const message.c functions now take const char * as a format. Error message definitions can be made const. --- src/nvim/spellfile.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index aa76dcbd32..b5e0698240 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -322,11 +322,11 @@ enum { 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"); -static char *e_afftrailing = N_("Trailing text in %s line %d: %s"); -static char *e_affname = N_("Affix name too long in %s line %d: %s"); -static char *msg_compressing = N_("Compressing word tree..."); +static const char *e_spell_trunc = N_("E758: Truncated spell file"); +static const char *e_illegal_character_in_word = N_("E1280: Illegal character in word"); +static const char *e_afftrailing = N_("Trailing text in %s line %d: %s"); +static const char *e_affname = N_("Affix name too long in %s line %d: %s"); +static const char *msg_compressing = N_("Compressing word tree..."); #define MAXLINELEN 500 // Maximum length in bytes of a line in a .aff // and .dic file. -- cgit From 9408f2dcf7cade2631688300e9b58eed6bc5219a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:40:57 +0200 Subject: refactor: remove redundant const char * casts --- src/nvim/spellfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index b5e0698240..e6b3ccaa90 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -5712,7 +5712,7 @@ static void init_spellfile(void) ((fname != NULL && strstr(path_tail(fname), ".ascii.") != NULL) ? "ascii" - : (const char *)spell_enc())); + : spell_enc())); set_option_value_give_err("spellfile", 0L, buf, OPT_LOCAL); break; } @@ -5851,7 +5851,7 @@ static void set_map_str(slang_T *lp, char *map) utf_char2bytes(headc, b + cl + 1); b[cl + 1 + headcl] = NUL; hash = hash_hash(b); - hi = hash_lookup(&lp->sl_map_hash, (const char *)b, strlen(b), hash); + hi = hash_lookup(&lp->sl_map_hash, b, strlen(b), hash); if (HASHITEM_EMPTY(hi)) { hash_add_item(&lp->sl_map_hash, hi, b, hash); } else { -- cgit From 04933b1ea968f958d2541dd65fd33ebb503caac3 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:08:16 +0200 Subject: refactor: remove redundant casts --- src/nvim/spellfile.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index e6b3ccaa90..d553910ece 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -2137,7 +2137,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *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((char *)items[1]); + aff->af_enc = enc_canonize(items[1]); if (!spin->si_ascii && convert_setup(&spin->si_conv, aff->af_enc, p_enc) == FAIL) { smsg(_("Conversion in %s not supported: from %s to %s"), @@ -2240,13 +2240,13 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) } 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. - if (atoi((char *)items[1]) == 0) { + if (atoi(items[1]) == 0) { smsg(_("Wrong COMPOUNDRULES value in %s line %d: %s"), fname, lnum, items[1]); } } else if (is_aff_rule(items, itemcnt, "COMPOUNDRULE", 2)) { // Don't use the first rule if it is a number. - if (compflags != NULL || *skipdigits((char *)items[1]) != NUL) { + if (compflags != NULL || *skipdigits(items[1]) != NUL) { // Concatenate this string to previously defined ones, // using a slash to separate them. l = (int)strlen(items[1]) + 1; @@ -2263,21 +2263,21 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) } } else if (is_aff_rule(items, itemcnt, "COMPOUNDWORDMAX", 2) && compmax == 0) { - compmax = atoi((char *)items[1]); + compmax = atoi(items[1]); if (compmax == 0) { smsg(_("Wrong COMPOUNDWORDMAX value in %s line %d: %s"), fname, lnum, items[1]); } } else if (is_aff_rule(items, itemcnt, "COMPOUNDMIN", 2) && compminlen == 0) { - compminlen = atoi((char *)items[1]); + compminlen = atoi(items[1]); if (compminlen == 0) { smsg(_("Wrong COMPOUNDMIN value in %s line %d: %s"), fname, lnum, items[1]); } } else if (is_aff_rule(items, itemcnt, "COMPOUNDSYLMAX", 2) && compsylmax == 0) { - compsylmax = atoi((char *)items[1]); + compsylmax = atoi(items[1]); if (compsylmax == 0) { smsg(_("Wrong COMPOUNDSYLMAX value in %s line %d: %s"), fname, lnum, items[1]); @@ -2291,7 +2291,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDTRIPLE", 1)) { compoptions |= COMP_CHECKTRIPLE; } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDPATTERN", 2)) { - if (atoi((char *)items[1]) == 0) { + if (atoi(items[1]) == 0) { smsg(_("Wrong CHECKCOMPOUNDPATTERN value in %s line %d: %s"), fname, lnum, items[1]); } @@ -2344,7 +2344,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) // "S" flag on all but the last block, thus we check for that // and store it in ah_follows. xstrlcpy(key, items[1], AH_KEY_LEN); - hi = hash_find(tp, (char *)key); + hi = hash_find(tp, key); if (!HASHITEM_EMPTY(hi)) { cur_aff = HI2AH(hi); if (cur_aff->ah_combine != (*items[2] == 'Y')) { @@ -2421,7 +2421,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) } } - aff_todo = atoi((char *)items[3]); + aff_todo = atoi(items[3]); } else if ((strcmp(items[0], "PFX") == 0 || strcmp(items[0], "SFX") == 0) && aff_todo > 0 @@ -2640,7 +2640,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) // We simply concatenate all the MAP strings, separated by // slashes. - ga_concat(&spin->si_map, (char *)items[1]); + ga_concat(&spin->si_map, items[1]); ga_append(&spin->si_map, '/'); } } @@ -2670,7 +2670,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) sofoto = getroom_save(spin, items[1]); } else if (strcmp(items[0], "COMMON") == 0) { for (int i = 1; i < itemcnt; i++) { - if (HASHITEM_EMPTY(hash_find(&spin->si_commonwords, (char *)items[i]))) { + if (HASHITEM_EMPTY(hash_find(&spin->si_commonwords, items[i]))) { p = xstrdup(items[i]); hash_add(&spin->si_commonwords, p); } @@ -2906,7 +2906,7 @@ static void process_compflags(spellinfo_T *spin, afffile_T *aff, char *compflags // Find the flag in the hashtable. If it was used before, use // the existing ID. Otherwise add a new entry. xstrlcpy(key, prevp, (size_t)(p - prevp) + 1); - hi = hash_find(&aff->af_comp, (char *)key); + hi = hash_find(&aff->af_comp, key); if (!HASHITEM_EMPTY(hi)) { id = HI2CI(hi)->ci_newID; } else { @@ -3111,14 +3111,14 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) spin->si_msg_count = 999999; // Read and ignore the first line: word count. - if (vim_fgets((char *)line, MAXLINELEN, fd) || !ascii_isdigit(*skipwhite((char *)line))) { + if (vim_fgets(line, MAXLINELEN, fd) || !ascii_isdigit(*skipwhite(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((char *)line, MAXLINELEN, fd) && !got_int) { + while (!vim_fgets(line, MAXLINELEN, fd) && !got_int) { line_breakcheck(); lnum++; if (line[0] == '#' || line[0] == '/') { @@ -3137,7 +3137,7 @@ static int spell_read_dic(spellinfo_T *spin, char *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, (char *)line, NULL); + pc = string_convert(&spin->si_conv, line, NULL); if (pc == NULL) { smsg(_("Conversion failure for word in %s line %d: %s"), fname, lnum, line); @@ -3329,7 +3329,7 @@ static int get_pfxlist(afffile_T *affile, char *afflist, char *store_afflist) // A flag is a postponed prefix flag if it appears in "af_pref" // and its ID is not zero. xstrlcpy(key, prevp, (size_t)(p - prevp) + 1); - hi = hash_find(&affile->af_pref, (char *)key); + hi = hash_find(&affile->af_pref, key); if (!HASHITEM_EMPTY(hi)) { id = HI2AH(hi)->ah_newID; if (id != 0) { @@ -3360,7 +3360,7 @@ static void get_compflags(afffile_T *affile, char *afflist, char *store_afflist) if (get_affitem(affile->af_flagtype, &p) != 0) { // A flag is a compound flag if it appears in "af_comp". xstrlcpy(key, prevp, (size_t)(p - prevp) + 1); - hi = hash_find(&affile->af_comp, (char *)key); + hi = hash_find(&affile->af_comp, key); if (!HASHITEM_EMPTY(hi)) { store_afflist[cnt++] = (char)(uint8_t)HI2CI(hi)->ci_newID; } @@ -4393,7 +4393,7 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) // Form the string first, we need to know its length. size_t l = 0; for (size_t i = 128; i < 256; i++) { - l += (size_t)utf_char2bytes(spelltab.st_fold[i], (char *)folchars + l); + l += (size_t)utf_char2bytes(spelltab.st_fold[i], folchars + l); } put_bytes(fd, 1 + 128 + 2 + l, 4); // @@ -5561,7 +5561,7 @@ void spell_add_word(char *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((char *)line, MAXWLEN * 2, fd)) { + while (!vim_fgets(line, MAXWLEN * 2, fd)) { fpos = fpos_next; fpos_next = ftell(fd); if (fpos_next < 0) { -- cgit From 3b0df1780e2c8526bda5dead18ee7cc45925caba Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:23:44 +0200 Subject: refactor: uncrustify Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`. --- src/nvim/spellfile.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index d553910ece..d5d07df7b8 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -660,7 +660,7 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent) // :
... //
: (section contents) - for (;;) { + while (true) { n = getc(fd); // or if (n == SN_END) { break; @@ -980,7 +980,7 @@ someerror: ga_init(&ga, 1, 100); for (wordnr = 0; wordnr < wcount; wordnr++) { ga.ga_len = 0; - for (;;) { + while (true) { c = getc(fd); // if (c < 0) { goto someerror; @@ -2973,7 +2973,7 @@ static bool flag_in_afflist(int flagtype, char *afflist, unsigned flag) for (p = afflist; *p != NUL;) { int digits = getdigits_int(&p, true, 0); assert(digits >= 0); - n = (unsigned int)digits; + n = (unsigned)digits; if (n == 0) { n = ZERO_FLAG; } @@ -3597,7 +3597,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ 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; } @@ -4442,7 +4442,7 @@ static int write_vim_spell(spellinfo_T *spin, char *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 round = 1; round <= 3; round++) { garray_T *gap; if (round == 1) { gap = &spin->si_rep; @@ -4505,7 +4505,7 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) // : // : fromto_T *ftp = &((fromto_T *)gap->ga_data)[i]; - for (unsigned int rr = 1; rr <= 2; rr++) { + for (unsigned rr = 1; rr <= 2; rr++) { char *p = rr == 1 ? ftp->ft_from : ftp->ft_to; l = strlen(p); assert(l < INT_MAX); @@ -4542,7 +4542,7 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) // round 1: count the bytes // round 2: write the bytes - for (unsigned int round = 1; round <= 2; round++) { + for (unsigned round = 1; round <= 2; round++) { size_t todo; size_t len = 0; hashitem_T *hi; @@ -4665,7 +4665,7 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) // spin->si_memtot = 0; - for (unsigned int round = 1; round <= 3; round++) { + for (unsigned round = 1; round <= 3; round++) { wordnode_T *tree; if (round == 1) { tree = spin->si_foldroot->wn_sibling; -- cgit From ff34c91194f9ab9d02808f2880029c38a4655eb5 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 17 Apr 2023 17:23:47 +0100 Subject: vim-patch:9.0.1330: handling new value of an option has a long "else if" chain Problem: Handling new value of an option has a long "else if" chain. Solution: Use a function pointer. (Yegappan Lakshmanan, closes vim/vim#12015) https://github.com/vim/vim/commit/af93691b53f38784efce0b93fe7644c44a7e382e --- src/nvim/spellfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index d5d07df7b8..b93dd55042 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1851,7 +1851,7 @@ static void spell_reload_one(char *fname, bool added_word) // When "zg" was used and the file wasn't loaded yet, should redo // 'spelllang' to load it now. if (added_word && !didit) { - did_set_spelllang(curwin); + parse_spelllang(curwin); } } -- cgit From 7ddf235d7e71ee8373b11baa6a49381311f5d61d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 4 May 2023 13:49:19 +0800 Subject: vim-patch:9.0.0240: crash when using ":mkspell" with an empty .dic file Problem: Crash when using ":mkspell" with an empty .dic file. Solution: Check for an empty word tree. https://github.com/vim/vim/commit/6669de1b235843968e88844ca6d3c8dec4b01a9e Co-authored-by: Bram Moolenaar --- src/nvim/spellfile.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index b93dd55042..dae9edcf4f 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -4971,9 +4971,12 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang) spin->si_sugtree = true; // Go through the whole case-folded tree, soundfold each word and put it - // in the trie. + // in the trie. Bail out if the tree is empty. byts = slang->sl_fbyts; idxs = slang->sl_fidxs; + if (byts == NULL || idxs == NULL) { + return FAIL; + } arridx[0] = 0; curi[0] = 1; -- cgit From 88cfb49bee3c9102082c7010acb92244e4ad1348 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 07:14:39 +0800 Subject: vim-patch:8.2.4890: inconsistent capitalization in error messages Problem: Inconsistent capitalization in error messages. Solution: Make capitalization consistent. (Doug Kearns) https://github.com/vim/vim/commit/cf030578b26460643dca4a40e7f2e3bc19c749aa Co-authored-by: Bram Moolenaar --- src/nvim/spellfile.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index dae9edcf4f..5e4a429cc7 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -323,6 +323,10 @@ enum { }; static const char *e_spell_trunc = N_("E758: Truncated spell file"); +static const char e_error_while_reading_sug_file_str[] + = N_("E782: Error while reading .sug file: %s"); +static const char e_duplicate_char_in_map_entry[] + = N_("E783: Duplicate char in MAP entry"); static const char *e_illegal_character_in_word = N_("E1280: Illegal character in word"); static const char *e_afftrailing = N_("Trailing text in %s line %d: %s"); static const char *e_affname = N_("Affix name too long in %s line %d: %s"); @@ -956,7 +960,7 @@ void suggest_load_files(void) if (spell_read_tree(fd, &slang->sl_sbyts, NULL, &slang->sl_sidxs, false, 0) != 0) { someerror: - semsg(_("E782: error while reading .sug file: %s"), + semsg(_(e_error_while_reading_sug_file_str), slang->sl_fname); slang_clear_sug(slang); goto nextone; @@ -5860,7 +5864,7 @@ static void set_map_str(slang_T *lp, char *map) } else { // This should have been checked when generating the .spl // file. - emsg(_("E783: duplicate char in MAP entry")); + emsg(_(e_duplicate_char_in_map_entry)); xfree(b); } } else { -- cgit From d31f7648ecaf32426239020331d1bbe9a6f56140 Mon Sep 17 00:00:00 2001 From: julio-b Date: Fri, 26 May 2023 04:13:00 +0000 Subject: fix(mkspell): prevent Unicode character overflow (#23760) introduced in: bd22585061b6 fixes #23758 --- src/nvim/spellfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 5e4a429cc7..e81cebe18a 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -3131,7 +3131,7 @@ static int spell_read_dic(spellinfo_T *spin, char *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); - while (l > 0 && line[l - 1] <= ' ') { + while (l > 0 && (uint8_t)line[l - 1] <= ' ') { l--; } if (l == 0) { -- cgit From b3d5138fd0066fda26ef7724a542ae45eb42fc84 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 7 Jun 2023 06:05:16 +0600 Subject: refactor(options): remove `getoption_T` and introduce `OptVal` (#23850) Removes the `getoption_T` struct and also introduces the `OptVal` struct to unify the methods of getting/setting different option value types. This is the first of many PRs to reduce code duplication in the Vim option code as well as to make options easier to maintain. It also increases the flexibility and extensibility of options. Which opens the door for things like Array and Dictionary options. --- src/nvim/spellfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index e81cebe18a..330dcdad05 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -5720,7 +5720,7 @@ static void init_spellfile(void) && strstr(path_tail(fname), ".ascii.") != NULL) ? "ascii" : spell_enc())); - set_option_value_give_err("spellfile", 0L, buf, OPT_LOCAL); + set_option_value_give_err("spellfile", CSTR_AS_OPTVAL(buf), OPT_LOCAL); break; } aspath = false; -- cgit From fcf3519c65a2d6736de437f686e788684a6c8564 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 17 Apr 2023 22:18:58 +0200 Subject: refactor: remove long long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform. --- src/nvim/spellfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 330dcdad05..be982cefb3 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1688,7 +1688,7 @@ static int spell_read_tree(FILE *fd, uint8_t **bytsp, long *bytsp_len, idx_T **i // The tree size was computed when writing the file, so that we can // allocate it as one long block. - long len = get4c(fd); + int len = get4c(fd); if (len < 0) { return SP_TRUNCERROR; } @@ -1712,7 +1712,7 @@ static int spell_read_tree(FILE *fd, uint8_t **bytsp, long *bytsp_len, idx_T **i *idxsp = ip; // Recursively read the tree and store it in the array. - idx = read_tree_node(fd, bp, ip, (int)len, 0, prefixtree, prefixcnt); + idx = read_tree_node(fd, bp, ip, len, 0, prefixtree, prefixcnt); if (idx < 0) { return idx; } -- cgit From d2efcbf2dca6c2899ba0a1be7fc10dbf3f112d26 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 22 Jul 2023 18:00:55 +0800 Subject: refactor: remove some (const char **) casts (#24423) --- src/nvim/spellfile.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index be982cefb3..835ce992b3 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1547,10 +1547,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 *from, char *to) +static int set_sofo(slang_T *lp, const char *from, const char *to) { - char *s; - char *p; + const char *s; + const 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. @@ -1565,7 +1565,7 @@ static int set_sofo(slang_T *lp, char *from, char *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 **)&p); + const int c = mb_cptr2char_adv(&p); MB_CPTR_ADV(s); if (c >= 256) { lp->sl_sal_first[c & 0xff]++; @@ -1588,8 +1588,8 @@ static int set_sofo(slang_T *lp, char *from, char *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 **)&p); - const int i = mb_cptr2char_adv((const char **)&s); + const int c = mb_cptr2char_adv(&p); + const int i = mb_cptr2char_adv(&s); if (c >= 256) { // Append the from-to chars at the end of the list with // the low byte. @@ -1657,13 +1657,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 *s) +static int *mb_str2wide(const char *s) { int i = 0; int *res = xmalloc(((size_t)mb_charlen(s) + 1) * sizeof(int)); - for (char *p = s; *p != NUL;) { - res[i++] = mb_ptr2char_adv((const char **)&p); + for (const char *p = s; *p != NUL;) { + res[i++] = mb_ptr2char_adv(&p); } res[i] = NUL; @@ -5732,13 +5732,13 @@ static void init_spellfile(void) /// Set the spell character tables from strings in the .spl file. /// /// @param cnt length of "flags" -static void set_spell_charflags(const char *flags_in, int cnt, char *fol) +static void set_spell_charflags(const char *flags_in, int cnt, const char *fol) { const uint8_t *flags = (uint8_t *)flags_in; // We build the new tables here first, so that we can compare with the // previous one. spelltab_T new_st; - char *p = fol; + const char *p = fol; int c; clear_spell_chartab(&new_st); @@ -5750,7 +5750,7 @@ static void set_spell_charflags(const char *flags_in, int cnt, char *fol) } if (*p != NUL) { - c = mb_ptr2char_adv((const char **)&p); + c = mb_ptr2char_adv(&p); new_st.st_fold[i + 128] = (uint8_t)c; if (i + 128 != c && new_st.st_isu[i + 128] && c < 256) { new_st.st_upper[c] = (uint8_t)(i + 128); @@ -5814,9 +5814,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 *map) +static void set_map_str(slang_T *lp, const char *map) { - char *p; + const char *p; int headc = 0; if (*map == NUL) { @@ -5835,7 +5835,7 @@ static void set_map_str(slang_T *lp, char *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;) { - int c = mb_cptr2char_adv((const char **)&p); + int c = mb_cptr2char_adv(&p); if (c == '/') { headc = 0; } else { -- cgit From cefd774fac76b91f5368833555818c80c992c3b1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 24 Aug 2023 15:14:23 +0200 Subject: refactor(memline): distinguish mutating uses of ml_get_buf() ml_get_buf() takes a third parameters to indicate whether the caller wants to mutate the memline data in place. However the vast majority of the call sites is using this function just to specify a buffer but without any mutation. This makes it harder to grep for the places which actually perform mutation. Solution: Remove the bool param from ml_get_buf(). it now works like ml_get() except for a non-current buffer. Add a new ml_get_buf_mut() function for the mutating use-case, which can be grepped along with the other ml_replace() etc functions which can modify the memline. --- src/nvim/spellfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 835ce992b3..3337169199 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -5220,7 +5220,7 @@ static void sug_write(spellinfo_T *spin, char *fname) for (linenr_T lnum = 1; lnum <= wcount; lnum++) { // : ... NUL - char *line = ml_get_buf(spin->si_spellbuf, lnum, false); + char *line = ml_get_buf(spin->si_spellbuf, lnum); size_t len = strlen(line) + 1; if (fwrite(line, len, 1, fd) == 0) { emsg(_(e_write)); -- cgit From a1bec02c1e105eb9f49d577e04bdbeadd5a05e38 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sun, 13 Aug 2023 10:29:43 +0100 Subject: fix: use snprintf instead of sprintf Clang 14 now reports sprintf as deprecated. --- src/nvim/spellfile.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 3337169199..d7dc7fb672 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -2472,11 +2472,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) char buf[MAXLINELEN]; aff_entry->ae_cond = getroom_save(spin, items[4]); - if (*items[0] == 'P') { - sprintf(buf, "^%s", items[4]); // NOLINT(runtime/printf) - } else { - sprintf(buf, "%s$", items[4]); // NOLINT(runtime/printf) - } + snprintf(buf, sizeof(buf), *items[0] == 'P' ? "^%s" : "%s$", items[4]); 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"), @@ -2520,7 +2516,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) onecap_copy(items[4], buf, true); aff_entry->ae_cond = getroom_save(spin, buf); if (aff_entry->ae_cond != NULL) { - sprintf(buf, "^%s", aff_entry->ae_cond); // NOLINT(runtime/printf) + snprintf(buf, MAXLINELEN, "^%s", aff_entry->ae_cond); vim_regfree(aff_entry->ae_prog); aff_entry->ae_prog = vim_regcomp(buf, RE_MAGIC + RE_STRING); } -- cgit From b85f1dafc7c0a19704135617454f1c66f41202c1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 22:21:17 +0200 Subject: refactor(messages): fold msg_attr into msg problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/spellfile.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index d7dc7fb672..379342df03 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1955,9 +1955,9 @@ static void spell_print_node(wordnode_T *node, int depth) PRINTSOME(line1, depth, "(%d)", node->wn_nr, 0); PRINTSOME(line2, depth, " ", 0, 0); PRINTSOME(line3, depth, " ", 0, 0); - msg(line1); - msg(line2); - msg(line3); + msg(line1, 0); + msg(line2, 0); + msg(line3, 0); } else { node->wn_u1.index = true; @@ -1981,9 +1981,9 @@ static void spell_print_node(wordnode_T *node, int depth) } if (node->wn_byte == NUL) { - msg(line1); - msg(line2); - msg(line3); + msg(line1, 0); + msg(line2, 0); + msg(line3, 0); } // do the children @@ -2726,11 +2726,11 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) // Check that we didn't use too many renumbered flags. if (spin->si_newcompID < spin->si_newprefID) { if (spin->si_newcompID == 127 || spin->si_newcompID == 255) { - msg(_("Too many postponed prefixes")); + msg(_("Too many postponed prefixes"), 0); } else if (spin->si_newprefID == 0 || spin->si_newprefID == 127) { - msg(_("Too many compound flags")); + msg(_("Too many compound flags"), 0); } else { - msg(_("Too many postponed prefixes and/or compound flags")); + msg(_("Too many postponed prefixes and/or compound flags"), 0); } } @@ -5398,7 +5398,7 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool } if (spin.si_compflags != NULL && spin.si_nobreak) { - msg(_("Warning: both compounding and NOBREAK specified")); + msg(_("Warning: both compounding and NOBREAK specified"), 0); } if (!error && !got_int) { @@ -5468,7 +5468,7 @@ static void spell_message(const spellinfo_T *spin, char *str) if (!spin->si_verbose) { verbose_enter(); } - msg(str); + msg(str, 0); ui_flush(); if (!spin->si_verbose) { verbose_leave(); -- cgit From b07fd0e988581f6b9c620bcfc27a068ee61242c1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 29 Sep 2023 15:52:27 +0200 Subject: refactor(message): msg_outtrans_long_len_attr -> msg_outtrans_long --- src/nvim/spellfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 379342df03..1d93fe4cff 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -3179,7 +3179,7 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) _("line %6d, word %6ld - %s"), lnum, spin->si_foldwcount + spin->si_keepwcount, w); msg_start(); - msg_outtrans_long_attr(message, 0); + msg_outtrans_long(message, 0); msg_clr_eos(); msg_didout = false; msg_col = 0; -- cgit From bc13bc154aa574e0bb58a50f2e0ca4570efa57c3 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 29 Sep 2023 16:10:54 +0200 Subject: refactor(message): smsg_attr -> smsg --- src/nvim/spellfile.c | 109 ++++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 54 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 1d93fe4cff..e8ae6703c7 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -612,14 +612,14 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent) semsg(_(e_notopen), fname); } else if (p_verbose > 2) { verbose_enter(); - smsg(e_notopen, fname); + smsg(0, e_notopen, fname); verbose_leave(); } goto endFAIL; } if (p_verbose > 2) { verbose_enter(); - smsg(_("Reading spell file \"%s\""), fname); + smsg(0, _("Reading spell file \"%s\""), fname); verbose_leave(); } @@ -2097,7 +2097,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) if (spin->si_conv.vc_type != CONV_NONE) { pc = string_convert(&spin->si_conv, rline, NULL); if (pc == NULL) { - smsg(_("Conversion failure for word in %s line %d: %s"), + smsg(0, _("Conversion failure for word in %s line %d: %s"), fname, lnum, rline); continue; } @@ -2144,7 +2144,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) aff->af_enc = enc_canonize(items[1]); if (!spin->si_ascii && convert_setup(&spin->si_conv, aff->af_enc, p_enc) == FAIL) { - smsg(_("Conversion in %s not supported: from %s to %s"), + smsg(0, _("Conversion in %s not supported: from %s to %s"), fname, aff->af_enc, p_enc); } spin->si_conv.vc_fail = true; @@ -2157,7 +2157,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) } else if (strcmp(items[1], "caplong") == 0) { aff->af_flagtype = AFT_CAPLONG; } else { - smsg(_("Invalid value for FLAG in %s line %d: %s"), + smsg(0, _("Invalid value for FLAG in %s line %d: %s"), fname, lnum, items[1]); } if (aff->af_rare != 0 @@ -2171,7 +2171,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) || compflags != NULL || aff->af_suff.ht_used > 0 || aff->af_pref.ht_used > 0) { - smsg(_("FLAG after using flags in %s line %d: %s"), + smsg(0, _("FLAG after using flags in %s line %d: %s"), fname, lnum, items[1]); } } else if (spell_info_item(items[0]) && itemcnt > 1) { @@ -2223,14 +2223,16 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) && aff->af_compforbid == 0) { 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"), + smsg(0, + _("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, 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"), + smsg(0, + _("Defining COMPOUNDPERMITFLAG after PFX item may give wrong results in %s line %d"), fname, lnum); } } else if (is_aff_rule(items, itemcnt, "COMPOUNDFLAG", 2) @@ -2245,7 +2247,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) // We don't use the count, but do check that it's a number and // not COMPOUNDRULE mistyped. if (atoi(items[1]) == 0) { - smsg(_("Wrong COMPOUNDRULES value in %s line %d: %s"), + smsg(0, _("Wrong COMPOUNDRULES value in %s line %d: %s"), fname, lnum, items[1]); } } else if (is_aff_rule(items, itemcnt, "COMPOUNDRULE", 2)) { @@ -2269,21 +2271,21 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) && compmax == 0) { compmax = atoi(items[1]); if (compmax == 0) { - smsg(_("Wrong COMPOUNDWORDMAX value in %s line %d: %s"), + smsg(0, _("Wrong COMPOUNDWORDMAX value in %s line %d: %s"), fname, lnum, items[1]); } } else if (is_aff_rule(items, itemcnt, "COMPOUNDMIN", 2) && compminlen == 0) { compminlen = atoi(items[1]); if (compminlen == 0) { - smsg(_("Wrong COMPOUNDMIN value in %s line %d: %s"), + smsg(0, _("Wrong COMPOUNDMIN value in %s line %d: %s"), fname, lnum, items[1]); } } else if (is_aff_rule(items, itemcnt, "COMPOUNDSYLMAX", 2) && compsylmax == 0) { compsylmax = atoi(items[1]); if (compsylmax == 0) { - smsg(_("Wrong COMPOUNDSYLMAX value in %s line %d: %s"), + smsg(0, _("Wrong COMPOUNDSYLMAX value in %s line %d: %s"), fname, lnum, items[1]); } } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDDUP", 1)) { @@ -2296,7 +2298,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) compoptions |= COMP_CHECKTRIPLE; } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDPATTERN", 2)) { if (atoi(items[1]) == 0) { - smsg(_("Wrong CHECKCOMPOUNDPATTERN value in %s line %d: %s"), + smsg(0, _("Wrong CHECKCOMPOUNDPATTERN value in %s line %d: %s"), fname, lnum, items[1]); } } else if (is_aff_rule(items, itemcnt, "CHECKCOMPOUNDPATTERN", 3)) { @@ -2352,11 +2354,11 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) if (!HASHITEM_EMPTY(hi)) { cur_aff = HI2AH(hi); if (cur_aff->ah_combine != (*items[2] == 'Y')) { - smsg(_("Different combining flag in continued affix block in %s line %d: %s"), + smsg(0, _("Different combining flag in continued affix block in %s line %d: %s"), fname, lnum, items[1]); } if (!cur_aff->ah_follows) { - smsg(_("Duplicate affix in %s line %d: %s"), + smsg(0, _("Duplicate affix in %s line %d: %s"), fname, lnum, items[1]); } } else { @@ -2374,9 +2376,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) || cur_aff->ah_flag == aff->af_nosuggest || cur_aff->ah_flag == aff->af_needcomp || cur_aff->ah_flag == aff->af_comproot) { - smsg(_("Affix also used for " - "BAD/RARE/KEEPCASE/NEEDAFFIX/NEEDCOMPOUND/NOSUGGEST " - "in %s line %d: %s"), + smsg(0, _("Affix also used for BAD/RARE/KEEPCASE/NEEDAFFIX/NEEDCOMPOUND/NOSUGGEST " + "in %s line %d: %s"), fname, lnum, items[1]); } STRCPY(cur_aff->ah_key, items[1]); @@ -2400,11 +2401,11 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) if (itemcnt > lasti && !aff->af_ignoreextra && *items[lasti] != '#') { - smsg(_(e_afftrailing), fname, lnum, items[lasti]); + smsg(0, _(e_afftrailing), fname, lnum, items[lasti]); } if (strcmp(items[2], "Y") != 0 && strcmp(items[2], "N") != 0) { - smsg(_("Expected Y or N in %s line %d: %s"), + smsg(0, _("Expected Y or N in %s line %d: %s"), fname, lnum, items[2]); } @@ -2440,7 +2441,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) if (itemcnt > lasti && *items[lasti] != '#' && (strcmp(items[lasti], "-") != 0 || itemcnt != lasti + 1)) { - smsg(_(e_afftrailing), fname, lnum, items[lasti]); + smsg(0, _(e_afftrailing), fname, lnum, items[lasti]); } // New item for an affix letter. @@ -2475,7 +2476,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) snprintf(buf, sizeof(buf), *items[0] == 'P' ? "^%s" : "%s$", items[4]); 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"), + smsg(0, _("Broken condition in %s line %d: %s"), fname, lnum, items[4]); } } @@ -2587,7 +2588,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) || is_aff_rule(items, itemcnt, "REPSAL", 2)) { // Ignore REP/REPSAL count if (!isdigit((uint8_t)(*items[1]))) { - smsg(_("Expected REP(SAL) count in %s line %d"), + smsg(0, _("Expected REP(SAL) count in %s line %d"), fname, lnum); } } else if ((strcmp(items[0], "REP") == 0 @@ -2597,7 +2598,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) // Myspell ignores extra arguments, we require it starts with // # to detect mistakes. if (itemcnt > 3 && items[3][0] != '#') { - smsg(_(e_afftrailing), fname, lnum, items[3]); + smsg(0, _(e_afftrailing), fname, lnum, items[3]); } if (items[0][3] == 'S' ? do_repsal : do_rep) { // Replace underscore with space (can't include a space @@ -2622,7 +2623,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) // First line contains the count. found_map = true; if (!isdigit((uint8_t)(*items[1]))) { - smsg(_("Expected MAP count in %s line %d"), + smsg(0, _("Expected MAP count in %s line %d"), fname, lnum); } } else if (do_mapline) { @@ -2633,7 +2634,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) && vim_strchr(spin->si_map.ga_data, c) != NULL) || vim_strchr(p, c) != NULL) { - smsg(_("Duplicate character in MAP in %s line %d"), + smsg(0, _("Duplicate character in MAP in %s line %d"), fname, lnum); } } @@ -2676,7 +2677,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) } } } else { - smsg(_("Unrecognized or duplicate item in %s line %d: %s"), + smsg(0, _("Unrecognized or duplicate item in %s line %d: %s"), fname, lnum, items[0]); } } @@ -2708,7 +2709,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) if (compsylmax != 0) { if (syllable == NULL) { - smsg("%s", _("COMPOUNDSYLMAX used without SYLLABLE")); + smsg(0, "%s", _("COMPOUNDSYLMAX used without SYLLABLE")); } aff_check_number(spin->si_compsylmax, compsylmax, "COMPOUNDSYLMAX"); spin->si_compsylmax = compsylmax; @@ -2741,10 +2742,10 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) if (sofofrom != NULL || sofoto != NULL) { if (sofofrom == NULL || sofoto == NULL) { - smsg(_("Missing SOFO%s line in %s"), + smsg(0, _("Missing SOFO%s line in %s"), sofofrom == NULL ? "FROM" : "TO", fname); } else if (!GA_EMPTY(&spin->si_sal)) { - smsg(_("Both SAL and SOFO lines in %s"), fname); + smsg(0, _("Both SAL and SOFO lines in %s"), fname); } else { aff_check_string(spin->si_sofofr, sofofrom, "SOFOFROM"); aff_check_string(spin->si_sofoto, sofoto, "SOFOTO"); @@ -2822,15 +2823,15 @@ static unsigned affitem2flag(int flagtype, char *item, char *fname, int lnum) unsigned res = get_affitem(flagtype, &p); if (res == 0) { if (flagtype == AFT_NUM) { - smsg(_("Flag is not a number in %s line %d: %s"), + smsg(0, _("Flag is not a number in %s line %d: %s"), fname, lnum, item); } else { - smsg(_("Illegal flag in %s line %d: %s"), + smsg(0, _("Illegal flag in %s line %d: %s"), fname, lnum, item); } } if (*p != NUL) { - smsg(_(e_affname), fname, lnum, item); + smsg(0, _(e_affname), fname, lnum, item); return 0; } @@ -2993,7 +2994,7 @@ static bool flag_in_afflist(int flagtype, char *afflist, unsigned flag) static void aff_check_number(int spinval, int affval, char *name) { if (spinval != 0 && spinval != affval) { - smsg(_("%s value differs from what is used in another .aff file"), + smsg(0, _("%s value differs from what is used in another .aff file"), name); } } @@ -3002,7 +3003,7 @@ static void aff_check_number(int spinval, int affval, char *name) static void aff_check_string(char *spinval, char *affval, char *name) { if (spinval != NULL && strcmp(spinval, affval) != 0) { - smsg(_("%s value differs from what is used in another .aff file"), + smsg(0, _("%s value differs from what is used in another .aff file"), name); } } @@ -3139,7 +3140,7 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) if (spin->si_conv.vc_type != CONV_NONE) { pc = string_convert(&spin->si_conv, line, NULL); if (pc == NULL) { - smsg(_("Conversion failure for word in %s line %d: %s"), + smsg(0, _("Conversion failure for word in %s line %d: %s"), fname, lnum, line); continue; } @@ -3199,10 +3200,10 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) hi = hash_lookup(&ht, dw, strlen(dw), hash); if (!HASHITEM_EMPTY(hi)) { if (p_verbose > 0) { - smsg(_("Duplicate word in %s line %d: %s"), + smsg(0, _("Duplicate word in %s line %d: %s"), fname, lnum, dw); } else if (duplicate == 0) { - smsg(_("First duplicate word in %s line %d: %s"), + smsg(0, _("First duplicate word in %s line %d: %s"), fname, lnum, dw); } duplicate++; @@ -3263,10 +3264,10 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) } if (duplicate > 0) { - smsg(_("%d duplicate word(s) in %s"), duplicate, fname); + smsg(0, _("%d duplicate word(s) in %s"), duplicate, fname); } if (spin->si_ascii && non_ascii > 0) { - smsg(_("Ignored %d word(s) with non-ASCII characters in %s"), + smsg(0, _("Ignored %d word(s) with non-ASCII characters in %s"), non_ascii, fname); } hash_clear(&ht); @@ -3681,7 +3682,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) if (spin->si_conv.vc_type != CONV_NONE) { pc = string_convert(&spin->si_conv, rline, NULL); if (pc == NULL) { - smsg(_("Conversion failure for word in %s line %ld: %s"), + smsg(0, _("Conversion failure for word in %s line %ld: %s"), fname, lnum, rline); continue; } @@ -3695,10 +3696,10 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) line++; if (strncmp(line, "encoding=", 9) == 0) { if (spin->si_conv.vc_type != CONV_NONE) { - smsg(_("Duplicate /encoding= line ignored in %s line %ld: %s"), + smsg(0, _("Duplicate /encoding= line ignored in %s line %ld: %s"), fname, lnum, line - 1); } else if (did_word) { - smsg(_("/encoding= line after word ignored in %s line %ld: %s"), + smsg(0, _("/encoding= line after word ignored in %s line %ld: %s"), fname, lnum, line - 1); } else { char *enc; @@ -3708,7 +3709,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) 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"), + smsg(0, _("Conversion in %s not supported: from %s to %s"), fname, line, p_enc); } xfree(enc); @@ -3719,12 +3720,12 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) if (strncmp(line, "regions=", 8) == 0) { if (spin->si_region_count > 1) { - smsg(_("Duplicate /regions= line ignored in %s line %ld: %s"), + smsg(0, _("Duplicate /regions= line ignored in %s line %ld: %s"), fname, lnum, line); } else { line += 8; if (strlen(line) > MAXREGIONS * 2) { - smsg(_("Too many regions in %s line %ld: %s"), + smsg(0, _("Too many regions in %s line %ld: %s"), fname, lnum, line); } else { spin->si_region_count = (int)strlen(line) / 2; @@ -3737,7 +3738,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) continue; } - smsg(_("/ line ignored in %s line %ld: %s"), + smsg(0, _("/ line ignored in %s line %ld: %s"), fname, lnum, line - 1); continue; } @@ -3764,13 +3765,13 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) l = (uint8_t)(*p) - '0'; if (l == 0 || l > spin->si_region_count) { - smsg(_("Invalid region nr in %s line %ld: %s"), + smsg(0, _("Invalid region nr in %s line %ld: %s"), fname, lnum, p); break; } regionmask |= 1 << (l - 1); } else { - smsg(_("Unrecognized flags in %s line %ld: %s"), + smsg(0, _("Unrecognized flags in %s line %ld: %s"), fname, lnum, p); break; } @@ -4047,7 +4048,7 @@ static int tree_add_word(spellinfo_T *spin, const char *word, wordnode_T *root, node = *prev; } #ifdef SPELL_PRINTTREE - smsg("Added \"%s\"", word); + smsg(0, "Added \"%s\"", word); spell_print_tree(root->wn_sibling); #endif @@ -4924,7 +4925,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char *wfname) goto theend; } - smsg(_("Number of words after soundfolding: %" PRId64), + smsg(0, _("Number of words after soundfolding: %" PRId64), (int64_t)spin->si_spellbuf->b_ml.ml_line_count); // Compress the soundfold trie. @@ -5035,7 +5036,7 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang) } } - smsg(_("Total number of words: %d"), words_done); + smsg(0, _("Total number of words: %d"), words_done); return OK; } @@ -5584,7 +5585,7 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo) fputc('#', fd); if (undo) { home_replace(NULL, fname, NameBuff, MAXPATHL, true); - smsg(_("Word '%.*s' removed from %s"), len, word, NameBuff); + smsg(0, _("Word '%.*s' removed from %s"), len, word, NameBuff); } } if (fseek(fd, fpos_next, SEEK_SET) != 0) { @@ -5634,7 +5635,7 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo) fclose(fd); home_replace(NULL, fname, NameBuff, MAXPATHL, true); - smsg(_("Word '%.*s' added to %s"), len, word, NameBuff); + smsg(0, _("Word '%.*s' added to %s"), len, word, NameBuff); } } -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/spellfile.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index e8ae6703c7..bdeabe4b95 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -231,12 +231,12 @@ #include #include #include +#include #include #include #include #include -#include "auto/config.h" #include "nvim/arglist.h" #include "nvim/ascii.h" #include "nvim/buffer.h" @@ -265,7 +265,6 @@ #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" -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/spellfile.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index bdeabe4b95..f1df2e56f3 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -254,6 +254,7 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/os/time.h" -- cgit From e72b546354cd90bf0cd8ee6dd045538d713009ad Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/spellfile.c | 70 ++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index f1df2e56f3..25e08abb0e 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -452,24 +452,24 @@ struct wordnode_S { // Info used while reading the spell files. typedef struct spellinfo_S { wordnode_T *si_foldroot; // tree with case-folded words - long si_foldwcount; // nr of words in si_foldroot + int si_foldwcount; // nr of words in si_foldroot wordnode_T *si_keeproot; // tree with keep-case words - long si_keepwcount; // nr of words in si_keeproot + int si_keepwcount; // nr of words in si_keeproot wordnode_T *si_prefroot; // tree with postponed prefixes - long si_sugtree; // creating the soundfolding trie + int si_sugtree; // creating the soundfolding trie sblock_T *si_blocks; // memory blocks used - long si_blocks_cnt; // memory blocks allocated + int si_blocks_cnt; // memory blocks allocated int si_did_emsg; // true when ran out of memory - long si_compress_cnt; // words to add before lowering - // compression limit + int si_compress_cnt; // words to add before lowering + // compression limit wordnode_T *si_first_free; // List of nodes that have been freed during // compression, linked by "wn_child" field. - long si_free_count; // number of nodes in si_first_free + int si_free_count; // number of nodes in si_first_free #ifdef SPELL_PRINTTREE int si_wordnode_nr; // sequence nr for nodes #endif @@ -1874,24 +1874,24 @@ static void spell_reload_one(char *fname, bool added_word) // Tunable parameters for when the tree is compressed. Filled from the // 'mkspellmem' option. -static long compress_start = 30000; // memory / SBLOCKSIZE -static long compress_inc = 100; // memory / SBLOCKSIZE -static long compress_added = 500000; // word count +static int compress_start = 30000; // memory / SBLOCKSIZE +static int compress_inc = 100; // memory / SBLOCKSIZE +static int compress_added = 500000; // word count // Check the 'mkspellmem' option. Return FAIL if it's wrong. // Sets "sps_flags". int spell_check_msm(void) { char *p = p_msm; - long start = 0; - long incr = 0; - long added = 0; + int start = 0; + int incr = 0; + int added = 0; if (!ascii_isdigit(*p)) { return FAIL; } // block count = (value * 1024) / SBLOCKSIZE (but avoid overflow) - start = (getdigits_long(&p, true, 0) * 10) / (SBLOCKSIZE / 102); + start = (getdigits_int(&p, true, 0) * 10) / (SBLOCKSIZE / 102); if (*p != ',') { return FAIL; } @@ -1899,7 +1899,7 @@ int spell_check_msm(void) if (!ascii_isdigit(*p)) { return FAIL; } - incr = (getdigits_long(&p, true, 0) * 102) / (SBLOCKSIZE / 10); + incr = (getdigits_int(&p, true, 0) * 102) / (SBLOCKSIZE / 10); if (*p != ',') { return FAIL; } @@ -1907,7 +1907,7 @@ int spell_check_msm(void) if (!ascii_isdigit(*p)) { return FAIL; } - added = getdigits_long(&p, true, 0) * 1024; + added = getdigits_int(&p, true, 0) * 1024; if (*p != NUL) { return FAIL; } @@ -3177,7 +3177,7 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) if (os_time() > last_msg_time) { last_msg_time = os_time(); vim_snprintf(message, sizeof(message), - _("line %6d, word %6ld - %s"), + _("line %6d, word %6d - %s"), lnum, spin->si_foldwcount + spin->si_keepwcount, w); msg_start(); msg_outtrans_long(message, 0); @@ -3635,7 +3635,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ static int spell_read_wordfile(spellinfo_T *spin, char *fname) { FILE *fd; - long lnum = 0; + linenr_T lnum = 0; char rline[MAXLINELEN]; char *line; char *pc = NULL; @@ -3682,7 +3682,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) if (spin->si_conv.vc_type != CONV_NONE) { pc = string_convert(&spin->si_conv, rline, NULL); if (pc == NULL) { - smsg(0, _("Conversion failure for word in %s line %ld: %s"), + smsg(0, _("Conversion failure for word in %s line %" PRIdLINENR ": %s"), fname, lnum, rline); continue; } @@ -3696,10 +3696,10 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) line++; if (strncmp(line, "encoding=", 9) == 0) { if (spin->si_conv.vc_type != CONV_NONE) { - smsg(0, _("Duplicate /encoding= line ignored in %s line %ld: %s"), + smsg(0, _("Duplicate /encoding= line ignored in %s line %" PRIdLINENR ": %s"), fname, lnum, line - 1); } else if (did_word) { - smsg(0, _("/encoding= line after word ignored in %s line %ld: %s"), + smsg(0, _("/encoding= line after word ignored in %s line %" PRIdLINENR ": %s"), fname, lnum, line - 1); } else { char *enc; @@ -3720,12 +3720,12 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) if (strncmp(line, "regions=", 8) == 0) { if (spin->si_region_count > 1) { - smsg(0, _("Duplicate /regions= line ignored in %s line %ld: %s"), + smsg(0, _("Duplicate /regions= line ignored in %s line %" PRIdLINENR ": %s"), fname, lnum, line); } else { line += 8; if (strlen(line) > MAXREGIONS * 2) { - smsg(0, _("Too many regions in %s line %ld: %s"), + smsg(0, _("Too many regions in %s line %" PRIdLINENR ": %s"), fname, lnum, line); } else { spin->si_region_count = (int)strlen(line) / 2; @@ -3738,7 +3738,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) continue; } - smsg(0, _("/ line ignored in %s line %ld: %s"), + smsg(0, _("/ line ignored in %s line %" PRIdLINENR ": %s"), fname, lnum, line - 1); continue; } @@ -3765,13 +3765,13 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) l = (uint8_t)(*p) - '0'; if (l == 0 || l > spin->si_region_count) { - smsg(0, _("Invalid region nr in %s line %ld: %s"), + smsg(0, _("Invalid region nr in %s line %" PRIdLINENR ": %s"), fname, lnum, p); break; } regionmask |= 1 << (l - 1); } else { - smsg(0, _("Unrecognized flags in %s line %ld: %s"), + smsg(0, _("Unrecognized flags in %s line %" PRIdLINENR ": %s"), fname, lnum, p); break; } @@ -4168,7 +4168,7 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *n FUNC_ATTR_NONNULL_ALL { hashtab_T ht; - long tot = 0; + int tot = 0; long perc; // Skip the root itself, it's not actually used. The first sibling is the @@ -4178,7 +4178,7 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *n } hash_init(&ht); - const long n = node_compress(spin, root->wn_sibling, &ht, &tot); + const int n = node_compress(spin, root->wn_sibling, &ht, &tot); #ifndef SPELL_PRINTTREE if (spin->si_verbose || p_verbose > 2) @@ -4192,7 +4192,7 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *n perc = (tot - n) * 100 / tot; } vim_snprintf(IObuff, IOSIZE, - _("Compressed %s of %ld nodes; %ld (%ld%%) remaining"), + _("Compressed %s of %d nodes; %d (%ld%%) remaining"), name, tot, tot - n, perc); spell_message(spin, IObuff); } @@ -4206,7 +4206,7 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *n /// Returns the number of compressed nodes. /// /// @param tot total count of nodes before compressing, incremented while going through the tree -static long node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, long *tot) +static int node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, int *tot) FUNC_ATTR_NONNULL_ALL { wordnode_T *np; @@ -4216,7 +4216,7 @@ static long node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, lo hashitem_T *hi; long len = 0; unsigned nr, n; - long compressed = 0; + int compressed = 0; // Go through the list of siblings. Compress each child and then try // finding an identical child to replace it. @@ -4262,7 +4262,7 @@ static long node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, lo } } } - *tot += len + 1; // add one for the node that stores the length + *tot += (int)len + 1; // add one for the node that stores the length // Make a hash key for the node and its siblings, so that we can quickly // find a lookalike node. This must be done after compressing the sibling @@ -5559,15 +5559,15 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo) } if (what == SPELL_ADD_BAD || undo) { - long fpos_next = 0; - long fpos = 0; + int fpos_next = 0; + int fpos = 0; // When the word appears as good word we need to remove that one, // 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)) { fpos = fpos_next; - fpos_next = ftell(fd); + fpos_next = (int)ftell(fd); if (fpos_next < 0) { break; // should never happen } -- cgit From 8e932480f61d6101bf8bea1abc07ed93826221fd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/spellfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 25e08abb0e..3d3da3c3d6 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1678,7 +1678,7 @@ static int *mb_str2wide(const char *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, uint8_t **bytsp, long *bytsp_len, idx_T **idxsp, +static int spell_read_tree(FILE *fd, uint8_t **bytsp, int *bytsp_len, idx_T **idxsp, bool prefixtree, int prefixcnt) FUNC_ATTR_NONNULL_ARG(1, 2, 4) { @@ -4214,7 +4214,7 @@ static int node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, int wordnode_T *child; hash_T hash; hashitem_T *hi; - long len = 0; + int len = 0; unsigned nr, n; int compressed = 0; @@ -4262,7 +4262,7 @@ static int node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, int } } } - *tot += (int)len + 1; // add one for the node that stores the length + *tot += len + 1; // add one for the node that stores the length // Make a hash key for the node and its siblings, so that we can quickly // find a lookalike node. This must be done after compressing the sibling -- cgit From 8e58d37f2e15ac8540377148e55ed08a039aadb6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 11 Nov 2023 11:20:08 +0100 Subject: refactor: remove redundant casts --- src/nvim/spellfile.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 3d3da3c3d6..555af8bc50 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -3438,7 +3438,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ && (ae->ae_chop == NULL || strlen(ae->ae_chop) < wordlen) && (ae->ae_prog == NULL - || vim_regexec_prog(&ae->ae_prog, false, word, (colnr_T)0)) + || vim_regexec_prog(&ae->ae_prog, false, word, 0)) && (((condit & CONDIT_CFIX) == 0) == ((condit & CONDIT_AFF) == 0 || ae->ae_flags == NULL @@ -4344,7 +4344,7 @@ static int write_vim_spell(spellinfo_T *spin, char *fname) //
: // size_t fwv = fwrite(VIMSPELLMAGIC, VIMSPELLMAGICL, 1, fd); - if (fwv != (size_t)1) { + if (fwv != 1) { // Catch first write error, don't try writing more. goto theend; } @@ -4702,7 +4702,7 @@ theend: retval = FAIL; } - if (fwv != (size_t)1) { + if (fwv != 1) { retval = FAIL; } if (retval == FAIL) { @@ -5181,7 +5181,7 @@ static void sug_write(spellinfo_T *spin, char *fname) spell_message(spin, IObuff); // : - if (fwrite(VIMSUGMAGIC, VIMSUGMAGICL, (size_t)1, fd) != 1) { // + if (fwrite(VIMSUGMAGIC, VIMSUGMAGICL, 1, fd) != 1) { // emsg(_(e_write)); goto theend; } -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/spellfile.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 555af8bc50..9bf5ef3ed8 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // spellfile.c: code for reading and writing spell files. // // See spell.c for information about spell checking. @@ -1692,7 +1689,7 @@ static int spell_read_tree(FILE *fd, uint8_t **bytsp, int *bytsp_len, idx_T **id if (len < 0) { return SP_TRUNCERROR; } - if ((size_t)len >= SIZE_MAX / sizeof(int)) { // -V547 + if ((size_t)len >= SIZE_MAX / sizeof(int)) { // Invalid length, multiply with sizeof(int) would overflow. return SP_FORMERROR; } -- cgit From 28f4f3c48498086307ed825d1761edb5789ca0e8 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 15:54:54 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment - use bool to represent boolean values --- src/nvim/spellfile.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 9bf5ef3ed8..67b29e25a4 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -3395,7 +3395,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ affentry_T *ae; char newword[MAXWLEN]; int retval = OK; - int i, j; + int j; char *p; int use_flags; char *use_pfxlist; @@ -3452,7 +3452,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ p = word; if (ae->ae_chop != NULL) { // Skip chop string. - i = mb_charlen(ae->ae_chop); + int i = mb_charlen(ae->ae_chop); for (; i > 0; i--) { MB_PTR_ADV(p); } @@ -3464,7 +3464,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ if (ae->ae_chop != NULL) { // Remove chop string. p = newword + strlen(newword); - i = mb_charlen(ae->ae_chop); + int i = mb_charlen(ae->ae_chop); for (; i > 0; i--) { MB_PTR_BACK(newword, p); } @@ -3514,7 +3514,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ // Combine the prefix IDs. Avoid adding the // same ID twice. - for (i = 0; i < pfxlen; i++) { + for (int i = 0; i < pfxlen; i++) { for (j = 0; j < use_pfxlen; j++) { if (pfxlist[i] == use_pfxlist[j]) { break; @@ -3536,7 +3536,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ // 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 (int i = pfxlen; pfxlist[i] != NUL; i++) { for (j = use_pfxlen; use_pfxlist[j] != NUL; j++) { if (pfxlist[i] == use_pfxlist[j]) { break; @@ -5072,16 +5072,15 @@ static int sug_maketable(spellinfo_T *spin) /// @param gap place to store line of numbers static int sug_filltable(spellinfo_T *spin, wordnode_T *node, int startwordnr, garray_T *gap) { - wordnode_T *p, *np; int wordnr = startwordnr; int nr; int prev_nr; - for (p = node; p != NULL; p = p->wn_sibling) { + for (wordnode_T *p = node; p != NULL; p = p->wn_sibling) { if (p->wn_byte == NUL) { gap->ga_len = 0; prev_nr = 0; - for (np = p; np != NULL && np->wn_byte == NUL; np = np->wn_sibling) { + for (wordnode_T *np = p; np != NULL && np->wn_byte == NUL; np = np->wn_sibling) { ga_grow(gap, 10); nr = (np->wn_flags << 16) + (np->wn_region & 0xffff); @@ -5810,7 +5809,6 @@ 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, const char *map) { - const char *p; int headc = 0; if (*map == NUL) { @@ -5828,7 +5826,7 @@ static void set_map_str(slang_T *lp, const char *map) // The similar characters are stored separated with slashes: // "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;) { + for (const char *p = map; *p != NUL;) { int c = mb_cptr2char_adv(&p); if (c == '/') { headc = 0; -- cgit From ac1113ded5f8f09dd99a9894d7a7e795626fb728 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 13 Nov 2023 23:40:37 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment --- src/nvim/spellfile.c | 374 ++++++++++++++++++--------------------------------- 1 file changed, 129 insertions(+), 245 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 67b29e25a4..f83511dda7 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -594,16 +594,12 @@ static inline int spell_check_magic_string(FILE *const fd) /// @return the slang_T the spell file was loaded into. NULL for error. slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent) { - FILE *fd; char *p; - int n; - int len; slang_T *lp = NULL; - int c = 0; int res; bool did_estack_push = false; - fd = os_fopen(fname, "r"); + FILE *fd = os_fopen(fname, "r"); if (fd == NULL) { if (!silent) { semsg(_(e_notopen), fname); @@ -650,7 +646,7 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent) case 0: break; } - c = getc(fd); // + int c = getc(fd); // if (c < VIMSPELLVERSION) { emsg(_("E771: Old spell file, needs to be updated")); goto endFAIL; @@ -662,12 +658,12 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent) // :
... //
: (section contents) while (true) { - n = getc(fd); // or + int n = getc(fd); // or if (n == SN_END) { break; } c = getc(fd); // - len = get4c(fd); // + int len = get4c(fd); // if (len < 0) { goto truncerr; } @@ -841,17 +837,14 @@ endOK: // Returns the total number of words. static void tree_count_words(const uint8_t *byts, idx_T *idxs) { - int depth; idx_T arridx[MAXWLEN]; int curi[MAXWLEN]; - int c; - idx_T n; int wordcount[MAXWLEN]; arridx[0] = 0; curi[0] = 1; wordcount[0] = 0; - depth = 0; + int depth = 0; while (depth >= 0 && !got_int) { if (curi[depth] > byts[arridx[depth]]) { // Done all bytes at this node, go up one level. @@ -864,10 +857,10 @@ static void tree_count_words(const uint8_t *byts, idx_T *idxs) fast_breakcheck(); } else { // Do one more byte at this node. - n = arridx[depth] + curi[depth]; + idx_T n = arridx[depth] + curi[depth]; curi[depth]++; - c = byts[n]; + int c = byts[n]; if (c == 0) { // End of word, count it. wordcount[depth]++; @@ -892,33 +885,25 @@ static void tree_count_words(const uint8_t *byts, idx_T *idxs) /// 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 *dotp; - FILE *fd; char buf[MAXWLEN]; - time_t timestamp; - int wcount; - int wordnr; garray_T ga; - int c; // Do this for all languages that support sound folding. for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; lpi++) { - lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); - slang = lp->lp_slang; + langp_T *lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); + slang_T *slang = lp->lp_slang; if (slang->sl_sugtime != 0 && !slang->sl_sugloaded) { // Change ".spl" to ".sug" and open the file. When the file isn't // found silently skip it. Do set "sl_sugloaded" so that we // don't try again and again. slang->sl_sugloaded = true; - dotp = strrchr(slang->sl_fname, '.'); + char *dotp = strrchr(slang->sl_fname, '.'); if (dotp == NULL || path_fnamecmp(dotp, ".spl") != 0) { continue; } STRCPY(dotp, ".sug"); - fd = os_fopen(slang->sl_fname, "r"); + FILE *fd = os_fopen(slang->sl_fname, "r"); if (fd == NULL) { goto nextone; } @@ -932,7 +917,7 @@ void suggest_load_files(void) slang->sl_fname); goto nextone; } - c = getc(fd); // + int c = getc(fd); // if (c < VIMSUGVERSION) { semsg(_("E779: Old .sug file, needs to be updated: %s"), slang->sl_fname); @@ -945,7 +930,7 @@ void suggest_load_files(void) // Check the timestamp, it must be exactly the same as the one in // the .spl file. Otherwise the word numbers won't match. - timestamp = get8ctime(fd); // + time_t timestamp = get8ctime(fd); // if (timestamp != slang->sl_sugtime) { semsg(_("E781: .sug file doesn't match .spl file: %s"), slang->sl_fname); @@ -971,7 +956,7 @@ someerror: slang->sl_sugbuf = open_spellbuf(); // - wcount = get4c(fd); + int wcount = get4c(fd); if (wcount < 0) { goto someerror; } @@ -979,7 +964,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 (int wordnr = 0; wordnr < wcount; wordnr++) { ga.ga_len = 0; while (true) { c = getc(fd); // @@ -1020,7 +1005,6 @@ nextone: static char *read_cnt_string(FILE *fd, int cnt_bytes, int *cntp) { int cnt = 0; - char *str; // read the length bytes, MSB first for (int i = 0; i < cnt_bytes; i++) { @@ -1036,7 +1020,7 @@ static char *read_cnt_string(FILE *fd, int cnt_bytes, int *cntp) if (cnt == 0) { return NULL; // nothing to read, return NULL } - str = read_string(fd, (size_t)cnt); + char *str = read_string(fd, (size_t)cnt); if (str == NULL) { *cntp = SP_OTHERERROR; } @@ -1060,18 +1044,16 @@ static int read_region_section(FILE *fd, slang_T *lp, int len) // Return SP_*ERROR flags. static int read_charflags_section(FILE *fd) { - char *flags; - char *fol; int flagslen, follen; // - flags = read_cnt_string(fd, 1, &flagslen); + char *flags = read_cnt_string(fd, 1, &flagslen); if (flagslen < 0) { return flagslen; } // - fol = read_cnt_string(fd, 2, &follen); + char *fol = read_cnt_string(fd, 2, &follen); if (follen < 0) { xfree(flags); return follen; @@ -1129,10 +1111,9 @@ static int read_prefcond_section(FILE *fd, slang_T *lp) // Return SP_*ERROR flags. static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first) { - int cnt; fromto_T *ftp; - cnt = get2c(fd); // + int cnt = get2c(fd); // if (cnt < 0) { return SP_TRUNCERROR; } @@ -1177,12 +1158,6 @@ static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first) // Return SP_*ERROR flags. static int read_sal_section(FILE *fd, slang_T *slang) { - int cnt; - garray_T *gap; - salitem_T *smp; - int ccnt; - char *p; - slang->sl_sofo = false; const int flags = getc(fd); // @@ -1196,12 +1171,12 @@ static int read_sal_section(FILE *fd, slang_T *slang) slang->sl_rem_accents = true; } - cnt = get2c(fd); // + int cnt = get2c(fd); // if (cnt < 0) { return SP_TRUNCERROR; } - gap = &slang->sl_sal; + garray_T *gap = &slang->sl_sal; ga_init(gap, sizeof(salitem_T), 10); ga_grow(gap, cnt + 1); @@ -1209,12 +1184,12 @@ static int read_sal_section(FILE *fd, slang_T *slang) for (; gap->ga_len < cnt; gap->ga_len++) { int c = NUL; - smp = &((salitem_T *)gap->ga_data)[gap->ga_len]; - ccnt = getc(fd); // + salitem_T *smp = &((salitem_T *)gap->ga_data)[gap->ga_len]; + int ccnt = getc(fd); // if (ccnt < 0) { return SP_TRUNCERROR; } - p = xmalloc((size_t)ccnt + 2); + char *p = xmalloc((size_t)ccnt + 2); smp->sm_lead = p; // Read up to the first special char into sm_lead. @@ -1287,8 +1262,8 @@ static int read_sal_section(FILE *fd, slang_T *slang) if (!GA_EMPTY(gap)) { // Add one extra entry to mark the end with an empty sm_lead. Avoids // that we need to check the index every time. - smp = &((salitem_T *)gap->ga_data)[gap->ga_len]; - p = xmalloc(1); + salitem_T *smp = &((salitem_T *)gap->ga_data)[gap->ga_len]; + char *p = xmalloc(1); p[0] = NUL; smp->sm_lead = p; smp->sm_lead_w = mb_str2wide(smp->sm_lead); @@ -1313,13 +1288,12 @@ static int read_words_section(FILE *fd, slang_T *lp, int len) { int done = 0; int i; - int c; uint8_t word[MAXWLEN]; while (done < len) { // Read one word at a time. for (i = 0;; i++) { - c = getc(fd); + int c = getc(fd); if (c == EOF) { return SP_TRUNCERROR; } @@ -1344,19 +1318,18 @@ 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 *from, *to; int res; slang->sl_sofo = true; // - from = read_cnt_string(fd, 2, &cnt); + char *from = read_cnt_string(fd, 2, &cnt); if (cnt < 0) { return cnt; } // - to = read_cnt_string(fd, 2, &cnt); + char *to = read_cnt_string(fd, 2, &cnt); if (cnt < 0) { xfree(from); return cnt; @@ -1382,15 +1355,13 @@ static int read_sofo_section(FILE *fd, slang_T *slang) static int read_compound(FILE *fd, slang_T *slang, int len) { int todo = len; - int c; - int atstart; int cnt; if (todo < 2) { return SP_FORMERROR; // need at least two bytes } todo--; - c = getc(fd); // + int c = getc(fd); // if (c < 2) { c = MAXWLEN; } @@ -1469,7 +1440,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) *pp++ = '\\'; *pp++ = '('; - atstart = 1; + int atstart = 1; while (todo-- > 0) { c = getc(fd); // if (c == EOF) { @@ -1609,15 +1580,13 @@ static int set_sofo(slang_T *lp, const char *from, const char *to) // Fill the first-index table for "lp". static void set_sal_first(slang_T *lp) { - salfirst_T *sfirst; - salitem_T *smp; garray_T *gap = &lp->sl_sal; - sfirst = lp->sl_sal_first; + salfirst_T *sfirst = lp->sl_sal_first; for (int i = 0; i < 256; i++) { sfirst[i] = -1; } - smp = (salitem_T *)gap->ga_data; + salitem_T *smp = (salitem_T *)gap->ga_data; for (int i = 0; i < gap->ga_len; i++) { // Use the lowest byte of the first character. For latin1 it's // the character, for other encodings it should differ for most @@ -1679,10 +1648,6 @@ static int spell_read_tree(FILE *fd, uint8_t **bytsp, int *bytsp_len, idx_T **id bool prefixtree, int prefixcnt) FUNC_ATTR_NONNULL_ARG(1, 2, 4) { - int idx; - uint8_t *bp; - idx_T *ip; - // The tree size was computed when writing the file, so that we can // allocate it as one long block. int len = get4c(fd); @@ -1698,18 +1663,18 @@ static int spell_read_tree(FILE *fd, uint8_t **bytsp, int *bytsp_len, idx_T **id } // Allocate the byte array. - bp = xmalloc((size_t)len); + uint8_t *bp = xmalloc((size_t)len); *bytsp = bp; if (bytsp_len != NULL) { *bytsp_len = len; } // Allocate the index array. - ip = xcalloc((size_t)len, sizeof(*ip)); + idx_T *ip = xcalloc((size_t)len, sizeof(*ip)); *idxsp = ip; // Recursively read the tree and store it in the array. - idx = read_tree_node(fd, bp, ip, len, 0, prefixtree, prefixcnt); + int idx = read_tree_node(fd, bp, ip, len, 0, prefixtree, prefixcnt); if (idx < 0) { return idx; } @@ -1732,13 +1697,10 @@ static int spell_read_tree(FILE *fd, uint8_t **bytsp, int *bytsp_len, idx_T **id static idx_T read_tree_node(FILE *fd, uint8_t *byts, idx_T *idxs, int maxidx, idx_T startidx, bool prefixtree, int maxprefcondnr) { - int len; - int n; idx_T idx = startidx; - int c2; #define SHARED_MASK 0x8000000 - len = getc(fd); // + int len = getc(fd); // if (len <= 0) { return SP_TRUNCERROR; } @@ -1772,7 +1734,7 @@ static idx_T read_tree_node(FILE *fd, uint8_t *byts, idx_T *idxs, int maxidx, id c |= getc(fd); // - n = get2c(fd); // + int n = get2c(fd); // if (n >= maxprefcondnr) { return SP_FORMERROR; } @@ -1781,7 +1743,7 @@ static idx_T read_tree_node(FILE *fd, uint8_t *byts, idx_T *idxs, int maxidx, id // Read flags and optional region and prefix ID. In // idxs[] the flags go in the low two bytes, region above // that and prefix ID above the region. - c2 = c; + int c2 = c; c = getc(fd); // if (c2 == BY_FLAGS2) { c = (getc(fd) << 8) + c; // @@ -1798,7 +1760,7 @@ static idx_T read_tree_node(FILE *fd, uint8_t *byts, idx_T *idxs, int maxidx, id c = 0; } else { // c == BY_INDEX // - n = get3c(fd); + int n = get3c(fd); if (n < 0 || n >= maxidx) { return SP_FORMERROR; } @@ -1834,10 +1796,9 @@ static idx_T read_tree_node(FILE *fd, uint8_t *byts, idx_T *idxs, int maxidx, id /// @param added_word invoked through "zg" 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) { + for (slang_T *slang = first_lang; slang != NULL; slang = slang->sl_next) { if (path_full_compare(fname, slang->sl_fname, false, true) == kEqualFiles) { slang_clear(slang); if (spell_load_file(fname, NULL, slang, false) == NULL) { @@ -1880,15 +1841,12 @@ static int compress_added = 500000; // word count int spell_check_msm(void) { char *p = p_msm; - int start = 0; - int incr = 0; - int added = 0; if (!ascii_isdigit(*p)) { return FAIL; } // block count = (value * 1024) / SBLOCKSIZE (but avoid overflow) - start = (getdigits_int(&p, true, 0) * 10) / (SBLOCKSIZE / 102); + int start = (getdigits_int(&p, true, 0) * 10) / (SBLOCKSIZE / 102); if (*p != ',') { return FAIL; } @@ -1896,7 +1854,7 @@ int spell_check_msm(void) if (!ascii_isdigit(*p)) { return FAIL; } - incr = (getdigits_int(&p, true, 0) * 102) / (SBLOCKSIZE / 10); + int incr = (getdigits_int(&p, true, 0) * 102) / (SBLOCKSIZE / 10); if (*p != ',') { return FAIL; } @@ -1904,7 +1862,7 @@ int spell_check_msm(void) if (!ascii_isdigit(*p)) { return FAIL; } - added = getdigits_int(&p, true, 0) * 1024; + int added = getdigits_int(&p, true, 0) * 1024; if (*p != NUL) { return FAIL; } @@ -2017,13 +1975,11 @@ static void spell_print_tree(wordnode_T *root) // Returns an afffile_T, NULL for complete failure. static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) { - FILE *fd; char rline[MAXLINELEN]; char *line; char *pc = NULL; #define MAXITEMCNT 30 char *(items[MAXITEMCNT]); - int itemcnt; char *p; int lnum = 0; affheader_T *cur_aff = NULL; @@ -2033,13 +1989,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) char *low = NULL; char *fol = NULL; char *upp = NULL; - int do_rep; - int do_repsal; - int do_sal; - int do_mapline; bool found_map = false; hashitem_T *hi; - int l; int compminlen = 0; // COMPOUNDMIN value int compsylmax = 0; // COMPOUNDSYLMAX value int compoptions = 0; // COMP_ flags @@ -2052,7 +2003,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) char *sofoto = NULL; // SOFOTO value // Open the file. - fd = os_fopen(fname, "r"); + FILE *fd = os_fopen(fname, "r"); if (fd == NULL) { semsg(_(e_notopen), fname); return NULL; @@ -2062,16 +2013,16 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) spell_message(spin, IObuff); // Only do REP lines when not done in another .aff file already. - do_rep = GA_EMPTY(&spin->si_rep); + int do_rep = GA_EMPTY(&spin->si_rep); // Only do REPSAL lines when not done in another .aff file already. - do_repsal = GA_EMPTY(&spin->si_repsal); + int do_repsal = GA_EMPTY(&spin->si_repsal); // Only do SAL lines when not done in another .aff file already. - do_sal = GA_EMPTY(&spin->si_sal); + int do_sal = GA_EMPTY(&spin->si_sal); // Only do MAP lines when not done in another .aff file already. - do_mapline = GA_EMPTY(&spin->si_map); + int do_mapline = GA_EMPTY(&spin->si_map); // Allocate and init the afffile_T structure. afffile_T *aff = getroom(spin, sizeof(*aff), true); @@ -2106,7 +2057,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) // Split the line up in white separated items. Put a NUL after each // item. - itemcnt = 0; + int itemcnt = 0; for (p = line;;) { while (*p != NUL && (uint8_t)(*p) <= ' ') { // skip white space and CR/NL p++; @@ -2252,7 +2203,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) if (compflags != NULL || *skipdigits(items[1]) != NUL) { // Concatenate this string to previously defined ones, // using a slash to separate them. - l = (int)strlen(items[1]) + 1; + int l = (int)strlen(items[1]) + 1; if (compflags != NULL) { l += (int)strlen(compflags) + 1; } @@ -2774,11 +2725,9 @@ 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 *p; - if (entry->ae_flags != NULL && (affile->af_compforbid != 0 || affile->af_comppermit != 0)) { - for (p = entry->ae_flags; *p != NUL;) { + for (char *p = entry->ae_flags; *p != NUL;) { char *prevp = p; unsigned flag = get_affitem(affile->af_flagtype, &p); if (flag == affile->af_comppermit || flag == affile->af_compforbid) { @@ -2870,12 +2819,9 @@ static unsigned get_affitem(int flagtype, char **pp) /// they fit in one byte. static void process_compflags(spellinfo_T *spin, afffile_T *aff, char *compflags) { - char *prevp; - unsigned flag; compitem_T *ci; int id; 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 @@ -2898,13 +2844,13 @@ static void process_compflags(spellinfo_T *spin, afffile_T *aff, char *compflags *tp++ = (uint8_t)(*p++); } else { // First get the flag number, also checks validity. - prevp = p; - flag = get_affitem(aff->af_flagtype, &p); + char *prevp = p; + unsigned flag = get_affitem(aff->af_flagtype, &p); if (flag != 0) { // Find the flag in the hashtable. If it was used before, use // the existing ID. Otherwise add a new entry. xstrlcpy(key, prevp, (size_t)(p - prevp) + 1); - hi = hash_find(&aff->af_comp, key); + hashitem_T *hi = hash_find(&aff->af_comp, key); if (!HASHITEM_EMPTY(hi)) { id = HI2CI(hi)->ci_newID; } else { @@ -2946,17 +2892,14 @@ 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 *afflist, unsigned flag) { - char *p; - unsigned n; - switch (flagtype) { case AFT_CHAR: return vim_strchr(afflist, (int)flag) != NULL; case AFT_CAPLONG: case AFT_LONG: - for (p = afflist; *p != NUL;) { - n = (unsigned)mb_ptr2char_adv((const char **)&p); + for (char *p = afflist; *p != NUL;) { + unsigned 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 **)&p) + (n << 16); @@ -2968,10 +2911,10 @@ static bool flag_in_afflist(int flagtype, char *afflist, unsigned flag) break; case AFT_NUM: - for (p = afflist; *p != NUL;) { + for (char *p = afflist; *p != NUL;) { int digits = getdigits_int(&p, true, 0); assert(digits >= 0); - n = (unsigned)digits; + unsigned n = (unsigned)digits; if (n == 0) { n = ZERO_FLAG; } @@ -3037,21 +2980,16 @@ static bool sal_to_bool(char *s) // Free the structure filled by spell_read_aff(). static void spell_free_aff(afffile_T *aff) { - hashtab_T *ht; - hashitem_T *hi; - affheader_T *ah; - affentry_T *ae; - xfree(aff->af_enc); // All this trouble to free the "ae_prog" items... - for (ht = &aff->af_pref;; ht = &aff->af_suff) { + for (hashtab_T *ht = &aff->af_pref;; ht = &aff->af_suff) { int todo = (int)ht->ht_used; - for (hi = ht->ht_array; todo > 0; hi++) { + for (hashitem_T *hi = ht->ht_array; todo > 0; hi++) { if (!HASHITEM_EMPTY(hi)) { todo--; - ah = HI2AH(hi); - for (ae = ah->ah_first; ae != NULL; ae = ae->ae_next) { + affheader_T *ah = HI2AH(hi); + for (affentry_T *ae = ah->ah_first; ae != NULL; ae = ae->ae_next) { vim_regfree(ae->ae_prog); } } @@ -3072,22 +3010,13 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) { hashtab_T ht; char line[MAXLINELEN]; - char *p; - char *afflist; char store_afflist[MAXWLEN]; - int pfxlen; - bool need_affix; - char *dw; char *pc; char *w; - int l; - hash_T hash; - hashitem_T *hi; int lnum = 1; int non_ascii = 0; int retval = OK; char message[MAXLINELEN + MAXWLEN]; - int flags; int duplicate = 0; Timestamp last_msg_time = 0; @@ -3124,7 +3053,7 @@ static int spell_read_dic(spellinfo_T *spin, char *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); + int l = (int)strlen(line); while (l > 0 && (uint8_t)line[l - 1] <= ' ') { l--; } @@ -3149,8 +3078,8 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) // Truncate the word at the "/", set "afflist" to what follows. // Replace "\/" by "/" and "\\" by "\". - afflist = NULL; - for (p = w; *p != NUL; MB_PTR_ADV(p)) { + char *afflist = NULL; + for (char *p = w; *p != NUL; MB_PTR_ADV(p)) { if (*p == '\\' && (p[1] == '\\' || p[1] == '/')) { STRMOVE(p, p + 1); } else if (*p == '/') { @@ -3186,15 +3115,15 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) } // Store the word in the hashtable to be able to find duplicates. - dw = getroom_save(spin, w); + char *dw = getroom_save(spin, w); if (dw == NULL) { retval = FAIL; xfree(pc); break; } - hash = hash_hash(dw); - hi = hash_lookup(&ht, dw, strlen(dw), hash); + hash_T hash = hash_hash(dw); + hashitem_T *hi = hash_lookup(&ht, dw, strlen(dw), hash); if (!HASHITEM_EMPTY(hi)) { if (p_verbose > 0) { smsg(0, _("Duplicate word in %s line %d: %s"), @@ -3208,10 +3137,10 @@ static int spell_read_dic(spellinfo_T *spin, char *fname, afffile_T *affile) hash_add_item(&ht, hi, dw, hash); } - flags = 0; + int flags = 0; store_afflist[0] = NUL; - pfxlen = 0; - need_affix = false; + int pfxlen = 0; + bool need_affix = false; if (afflist != NULL) { // Extract flags from the affix list. flags |= get_affix_flags(affile, afflist); @@ -3317,9 +3246,7 @@ static int get_affix_flags(afffile_T *affile, char *afflist) static int get_pfxlist(afffile_T *affile, char *afflist, char *store_afflist) { int cnt = 0; - int id; char key[AH_KEY_LEN]; - hashitem_T *hi; for (char *p = afflist; *p != NUL;) { char *prevp = p; @@ -3327,9 +3254,9 @@ static int get_pfxlist(afffile_T *affile, char *afflist, char *store_afflist) // A flag is a postponed prefix flag if it appears in "af_pref" // and its ID is not zero. xstrlcpy(key, prevp, (size_t)(p - prevp) + 1); - hi = hash_find(&affile->af_pref, key); + hashitem_T *hi = hash_find(&affile->af_pref, key); if (!HASHITEM_EMPTY(hi)) { - id = HI2AH(hi)->ah_newID; + int id = HI2AH(hi)->ah_newID; if (id != 0) { store_afflist[cnt++] = (char)(uint8_t)id; } @@ -3351,14 +3278,13 @@ static void get_compflags(afffile_T *affile, char *afflist, char *store_afflist) { int cnt = 0; char key[AH_KEY_LEN]; - hashitem_T *hi; for (char *p = afflist; *p != NUL;) { char *prevp = p; if (get_affitem(affile->af_flagtype, &p) != 0) { // A flag is a compound flag if it appears in "af_comp". xstrlcpy(key, prevp, (size_t)(p - prevp) + 1); - hi = hash_find(&affile->af_comp, key); + hashitem_T *hi = hash_find(&affile->af_comp, key); if (!HASHITEM_EMPTY(hi)) { store_afflist[cnt++] = (char)(uint8_t)HI2CI(hi)->ci_newID; } @@ -3390,27 +3316,19 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ hashtab_T *ht, hashtab_T *xht, int condit, int flags, char *pfxlist, int pfxlen) { - hashitem_T *hi; - affheader_T *ah; affentry_T *ae; char newword[MAXWLEN]; int retval = OK; int j; - char *p; - int use_flags; - char *use_pfxlist; - int use_pfxlen; - bool need_affix; char store_afflist[MAXWLEN]; char pfx_pfxlist[MAXWLEN]; size_t wordlen = strlen(word); - int use_condit; int todo = (int)ht->ht_used; - for (hi = ht->ht_array; todo > 0 && retval == OK; hi++) { + for (hashitem_T *hi = ht->ht_array; todo > 0 && retval == OK; hi++) { if (!HASHITEM_EMPTY(hi)) { todo--; - ah = HI2AH(hi); + affheader_T *ah = HI2AH(hi); // Check that the affix combines, if required, and that the word // supports this affix. @@ -3449,7 +3367,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ } else { xstrlcpy(newword, ae->ae_add, MAXWLEN); } - p = word; + char *p = word; if (ae->ae_chop != NULL) { // Skip chop string. int i = mb_charlen(ae->ae_chop); @@ -3463,7 +3381,7 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ xstrlcpy(newword, word, MAXWLEN); if (ae->ae_chop != NULL) { // Remove chop string. - p = newword + strlen(newword); + char *p = newword + strlen(newword); int i = mb_charlen(ae->ae_chop); for (; i > 0; i--) { MB_PTR_BACK(newword, p); @@ -3475,11 +3393,11 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ } } - use_flags = flags; - use_pfxlist = pfxlist; - use_pfxlen = pfxlen; - need_affix = false; - use_condit = condit | CONDIT_COMB | CONDIT_AFF; + int use_flags = flags; + char *use_pfxlist = pfxlist; + int use_pfxlen = pfxlen; + bool need_affix = false; + int use_condit = condit | CONDIT_COMB | CONDIT_AFF; if (ae->ae_flags != NULL) { // Extract flags from the affix list. use_flags |= get_affix_flags(affile, ae->ae_flags); @@ -3631,21 +3549,16 @@ static int store_aff_word(spellinfo_T *spin, char *word, char *afflist, afffile_ // Read a file with a list of words. static int spell_read_wordfile(spellinfo_T *spin, char *fname) { - FILE *fd; linenr_T lnum = 0; char rline[MAXLINELEN]; char *line; char *pc = NULL; - char *p; - int l; int retval = OK; bool did_word = false; int non_ascii = 0; - int flags; - int regionmask; // Open the file. - fd = os_fopen(fname, "r"); + FILE *fd = os_fopen(fname, "r"); if (fd == NULL) { semsg(_(e_notopen), fname); return FAIL; @@ -3665,7 +3578,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) } // Remove CR, LF and white space from the end. - l = (int)strlen(rline); + int l = (int)strlen(rline); while (l > 0 && (uint8_t)rline[l - 1] <= ' ') { l--; } @@ -3740,11 +3653,11 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) continue; } - flags = 0; - regionmask = spin->si_region; + int flags = 0; + int regionmask = spin->si_region; // Check for flags and region after a slash. - p = vim_strchr(line, '/'); + char *p = vim_strchr(line, '/'); if (p != NULL) { *p++ = NUL; while (*p != NUL) { @@ -3813,7 +3726,6 @@ static int spell_read_wordfile(spellinfo_T *spin, char *fname) static void *getroom(spellinfo_T *spin, size_t len, bool align) FUNC_ATTR_NONNULL_RET { - char *p; sblock_T *bl = spin->si_blocks; assert(len <= SBLOCKSIZE); @@ -3833,7 +3745,7 @@ static void *getroom(spellinfo_T *spin, size_t len, bool align) spin->si_blocks_cnt++; } - p = bl->sb_data + bl->sb_used; + char *p = bl->sb_data + bl->sb_used; bl->sb_used += (int)len; return p; @@ -3851,10 +3763,8 @@ static char *getroom_save(spellinfo_T *spin, char *s) // Free the list of allocated sblock_T. static void free_blocks(sblock_T *bl) { - sblock_T *next; - while (bl != NULL) { - next = bl->sb_next; + sblock_T *next = bl->sb_next; xfree(bl); bl = next; } @@ -3943,8 +3853,6 @@ static int tree_add_word(spellinfo_T *spin, const char *word, wordnode_T *root, int region, int affixID) { wordnode_T *node = root; - wordnode_T *np; - wordnode_T *copyp, **copyprev; wordnode_T **prev = NULL; // Add each byte of the word to the tree, including the NUL at the end. @@ -3954,10 +3862,10 @@ static int tree_add_word(spellinfo_T *spin, const char *word, wordnode_T *root, // (we don't optimize for a partly shared list of siblings). if (node != NULL && node->wn_refs > 1) { node->wn_refs--; - copyprev = prev; - for (copyp = node; copyp != NULL; copyp = copyp->wn_sibling) { + wordnode_T **copyprev = prev; + for (wordnode_T *copyp = node; copyp != NULL; copyp = copyp->wn_sibling) { // Allocate a new node and copy the info. - np = get_wordnode(spin); + wordnode_T *np = get_wordnode(spin); if (np == NULL) { return FAIL; } @@ -4012,7 +3920,7 @@ static int tree_add_word(spellinfo_T *spin, const char *word, wordnode_T *root, || node->wn_flags != (flags & WN_MASK) || node->wn_affixID != affixID))) { // Allocate a new node. - np = get_wordnode(spin); + wordnode_T *np = get_wordnode(spin); if (np == NULL) { return FAIL; } @@ -4134,11 +4042,10 @@ static wordnode_T *get_wordnode(spellinfo_T *spin) static int deref_wordnode(spellinfo_T *spin, wordnode_T *node) FUNC_ATTR_NONNULL_ALL { - wordnode_T *np; int cnt = 0; if (--node->wn_refs == 0) { - for (np = node; np != NULL; np = np->wn_sibling) { + for (wordnode_T *np = node; np != NULL; np = np->wn_sibling) { if (np->wn_child != NULL) { cnt += deref_wordnode(spin, np->wn_child); } @@ -4206,29 +4113,26 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *n static int node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, int *tot) FUNC_ATTR_NONNULL_ALL { - wordnode_T *np; wordnode_T *tp; wordnode_T *child; - hash_T hash; - hashitem_T *hi; int len = 0; - unsigned nr, n; + unsigned n; int compressed = 0; // Go through the list of siblings. Compress each child and then try // finding an identical child to replace it. // Note that with "child" we mean not just the node that is pointed to, // but the whole list of siblings of which the child node is the first. - for (np = node; np != NULL && !got_int; np = np->wn_sibling) { + for (wordnode_T *np = node; np != NULL && !got_int; np = np->wn_sibling) { len++; if ((child = np->wn_child) != NULL) { // Compress the child first. This fills hashkey. compressed += node_compress(spin, child, ht, tot); // Try to find an identical child. - hash = hash_hash((char *)child->wn_u1.hashkey); - hi = hash_lookup(ht, (const char *)child->wn_u1.hashkey, - strlen((char *)child->wn_u1.hashkey), hash); + hash_T hash = hash_hash((char *)child->wn_u1.hashkey); + hashitem_T *hi = hash_lookup(ht, (const char *)child->wn_u1.hashkey, + 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 @@ -4265,8 +4169,8 @@ static int node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, int // find a lookalike node. This must be done after compressing the sibling // list, otherwise the hash key would become invalid by the compression. node->wn_u1.hashkey[0] = (uint8_t)len; - nr = 0; - for (np = node; np != NULL; np = np->wn_sibling) { + unsigned nr = 0; + for (wordnode_T *np = node; np != NULL; np = np->wn_sibling) { if (np->wn_byte == NUL) { // end node: use wn_flags, wn_region and wn_affixID n = (unsigned)(np->wn_flags + (np->wn_region << 8) + (np->wn_affixID << 16)); @@ -4714,10 +4618,8 @@ theend: // space. static void clear_node(wordnode_T *node) { - wordnode_T *np; - if (node != NULL) { - for (np = node; np != NULL; np = np->wn_sibling) { + for (wordnode_T *np = node; np != NULL; np = np->wn_sibling) { np->wn_u1.index = 0; np->wn_u2.wnode = NULL; @@ -4875,7 +4777,6 @@ void ex_mkspell(exarg_T *eap) static void spell_make_sugfile(spellinfo_T *spin, char *wfname) { char *fname = NULL; - int len; slang_T *slang; bool free_slang = false; @@ -4933,7 +4834,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char *wfname) // Make the file name by changing ".spl" to ".sug". fname = xmalloc(MAXPATHL); xstrlcpy(fname, wfname, MAXPATHL); - len = (int)strlen(fname); + int len = (int)strlen(fname); fname[len - 2] = 'u'; fname[len - 1] = 'g'; sug_write(spin, fname); @@ -4950,15 +4851,10 @@ theend: // Build the soundfold trie for language "slang". static int sug_filltree(spellinfo_T *spin, slang_T *slang) { - uint8_t *byts; - idx_T *idxs; - int depth; idx_T arridx[MAXWLEN]; int curi[MAXWLEN]; char tword[MAXWLEN]; char tsalword[MAXWLEN]; - int c; - idx_T n; unsigned words_done = 0; int wordcount[MAXWLEN]; @@ -4970,8 +4866,8 @@ 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. Bail out if the tree is empty. - byts = slang->sl_fbyts; - idxs = slang->sl_fidxs; + uint8_t *byts = slang->sl_fbyts; + idx_T *idxs = slang->sl_fidxs; if (byts == NULL || idxs == NULL) { return FAIL; } @@ -4980,7 +4876,7 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang) curi[0] = 1; wordcount[0] = 0; - depth = 0; + int depth = 0; while (depth >= 0 && !got_int) { if (curi[depth] > byts[arridx[depth]]) { // Done all bytes at this node, go up one level. @@ -4993,10 +4889,10 @@ static int sug_filltree(spellinfo_T *spin, slang_T *slang) line_breakcheck(); } else { // Do one more byte at this node. - n = arridx[depth] + curi[depth]; + idx_T n = arridx[depth] + curi[depth]; curi[depth]++; - c = byts[n]; + int c = byts[n]; if (c == 0) { // Sound-fold the word. tword[depth] = NUL; @@ -5073,17 +4969,15 @@ static int sug_maketable(spellinfo_T *spin) static int sug_filltable(spellinfo_T *spin, wordnode_T *node, int startwordnr, garray_T *gap) { int wordnr = startwordnr; - int nr; - int prev_nr; for (wordnode_T *p = node; p != NULL; p = p->wn_sibling) { if (p->wn_byte == NUL) { gap->ga_len = 0; - prev_nr = 0; + int prev_nr = 0; for (wordnode_T *np = p; np != NULL && np->wn_byte == NUL; np = np->wn_sibling) { ga_grow(gap, 10); - nr = (np->wn_flags << 16) + (np->wn_region & 0xffff); + int nr = (np->wn_flags << 16) + (np->wn_region & 0xffff); // Compute the offset from the previous nr and store the // offset in a way that it takes a minimum number of bytes. // It's a bit like utf-8, but without the need to mark @@ -5128,16 +5022,14 @@ static int sug_filltable(spellinfo_T *spin, wordnode_T *node, int startwordnr, g static int offset2bytes(int nr, char *buf_in) { uint8_t *buf = (uint8_t *)buf_in; - int rem; - int b1, b2, b3, b4; // Split the number in parts of base 255. We need to avoid NUL bytes. - b1 = nr % 255 + 1; - rem = nr / 255; - b2 = rem % 255 + 1; + int b1 = nr % 255 + 1; + int rem = nr / 255; + int b2 = rem % 255 + 1; rem = rem / 255; - b3 = rem % 255 + 1; - b4 = rem / 255 + 1; + int b3 = rem % 255 + 1; + int b4 = rem / 255 + 1; if (b4 > 1 || b3 > 0x1f) { // 4 bytes buf[0] = (uint8_t)(0xe0 + b4); @@ -5249,11 +5141,7 @@ theend: static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool added_word) { char *fname = NULL; - char **innames; - int incount; afffile_T *(afile[MAXREGIONS]); - int i; - int len; bool error = false; spellinfo_T spin; @@ -5273,13 +5161,13 @@ static void mkspell(int fcount, char **fnames, bool ascii, bool over_write, bool // default: fnames[0] is output file, following are input files // When "fcount" is 1 there is only one file. - innames = &fnames[fcount == 1 ? 0 : 1]; - incount = fcount - 1; + char **innames = &fnames[fcount == 1 ? 0 : 1]; + int incount = fcount - 1; char *wfname = xmalloc(MAXPATHL); if (fcount >= 1) { - len = (int)strlen(fnames[0]); + int 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". @@ -5332,11 +5220,11 @@ 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 (int i = 0; i < incount; i++) { afile[i] = NULL; if (incount > 1) { - len = (int)strlen(innames[i]); + int len = (int)strlen(innames[i]); if (strlen(path_tail(innames[i])) < 5 || innames[i][len - 3] != '_') { semsg(_("E755: Invalid region in %s"), innames[i]); @@ -5364,7 +5252,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 (int i = 0; i < incount && !error; i++) { spin.si_conv.vc_type = CONV_NONE; spin.si_region = 1 << i; @@ -5435,7 +5323,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 (int i = 0; i < incount; i++) { if (afile[i] != NULL) { spell_free_aff(afile[i]); } @@ -5652,10 +5540,7 @@ void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo) // Initialize 'spellfile' for the current buffer. static void init_spellfile(void) { - char *buf; int l; - char *fname; - char *rtp; char *lend; bool aspath = false; char *lstart = curbuf->b_s.b_p_spl; @@ -5664,7 +5549,7 @@ static void init_spellfile(void) return; } - buf = xmalloc(MAXPATHL); + char *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. @@ -5678,7 +5563,7 @@ static void init_spellfile(void) // Loop over all entries in 'runtimepath'. Use the first one where we // are allowed to write. - rtp = p_rtp; + char *rtp = p_rtp; while (*rtp != NUL) { if (aspath) { // Use directory of an entry with path, e.g., for @@ -5706,8 +5591,8 @@ static void init_spellfile(void) "/%.*s", (int)(lend - lstart), lstart); } l = (int)strlen(buf); - fname = LANGP_ENTRY(curwin->w_s->b_langp, 0) - ->lp_slang->sl_fname; + char *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) @@ -5732,7 +5617,6 @@ static void set_spell_charflags(const char *flags_in, int cnt, const char *fol) // previous one. spelltab_T new_st; const char *p = fol; - int c; clear_spell_chartab(&new_st); @@ -5743,7 +5627,7 @@ static void set_spell_charflags(const char *flags_in, int cnt, const char *fol) } if (*p != NUL) { - c = mb_ptr2char_adv(&p); + int c = mb_ptr2char_adv(&p); new_st.st_fold[i + 128] = (uint8_t)c; if (i + 128 != c && new_st.st_isu[i + 128] && c < 256) { new_st.st_upper[c] = (uint8_t)(i + 128); -- cgit From a6e3d93421ba13c407a96fac9cc01fa41ec7ad98 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 16 Nov 2023 10:59:11 +0100 Subject: refactor: enable formatting for ternaries This requires removing the "Inner expression should be aligned" rule from clint as it prevents essentially any formatting regarding ternary operators. --- src/nvim/spellfile.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index f83511dda7..92bbf2aebd 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -2488,8 +2488,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) // Not found, add a new condition. idx = spin->si_prefcond.ga_len; char **pp = GA_APPEND_VIA_PTR(char *, &spin->si_prefcond); - *pp = (aff_entry->ae_cond == NULL) ? - NULL : getroom_save(spin, aff_entry->ae_cond); + *pp = (aff_entry->ae_cond == NULL) + ? NULL : getroom_save(spin, aff_entry->ae_cond); } // Add the prefix to the prefix tree. @@ -2608,7 +2608,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char *fname) // when "to" is "_" it means empty add_fromto(spin, &spin->si_sal, items[1], strcmp(items[2], "_") == 0 ? "" - : items[2]); + : items[2]); } } } else if (is_aff_rule(items, itemcnt, "SOFOFROM", 2) @@ -5368,8 +5368,9 @@ static void spell_message(const spellinfo_T *spin, char *str) void ex_spell(exarg_T *eap) { 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->cmdidx == CMD_spellwrong + ? SPELL_ADD_BAD + : eap->cmdidx == CMD_spellrare ? SPELL_ADD_RARE : SPELL_ADD_GOOD, eap->forceit ? 0 : (int)eap->line2, eap->cmdidx == CMD_spellundo); } -- cgit From 38a20dd89f91c45ec8589bf1c50d50732882d38a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 20:58:37 +0800 Subject: build(IWYU): replace most private mappings with pragmas (#26247) --- src/nvim/spellfile.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 92bbf2aebd..0d76ad631e 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -252,6 +252,7 @@ #include "nvim/message.h" #include "nvim/option.h" #include "nvim/option_vars.h" +#include "nvim/os/fs.h" #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/os/time.h" -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/spellfile.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 0d76ad631e..0df00aceee 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -241,6 +241,7 @@ #include "nvim/drawscreen.h" #include "nvim/ex_cmds_defs.h" #include "nvim/fileio.h" +#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/gettext.h" #include "nvim/globals.h" -- cgit From f4aedbae4cb1f206f5b7c6142697b71dd473059b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:39:38 +0100 Subject: build(IWYU): fix includes for undo_defs.h --- src/nvim/spellfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 0df00aceee..b30e595b2f 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -258,7 +258,7 @@ #include "nvim/os/os.h" #include "nvim/os/time.h" #include "nvim/path.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/regexp.h" #include "nvim/runtime.h" #include "nvim/spell.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/spellfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/spellfile.c') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index b30e595b2f..2607fddc31 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -235,7 +235,7 @@ #include #include "nvim/arglist.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/drawscreen.h" @@ -246,7 +246,7 @@ #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/hashtab.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mbyte.h" #include "nvim/memline.h" #include "nvim/memory.h" @@ -267,7 +267,7 @@ #include "nvim/strings.h" #include "nvim/ui.h" #include "nvim/undo.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" // Special byte values for . Some are only used in the tree for // postponed prefixes, some only in the other trees. This is a bit messy... -- cgit