Mercurial > vim
comparison src/spell.c @ 944:b2dcb8457067 v7.0.070
updated for version 7.0-070
author | vimboss |
---|---|
date | Tue, 29 Aug 2006 15:30:07 +0000 |
parents | 29bf49bad20d |
children | ed44c1c436d3 |
comparison
equal
deleted
inserted
replaced
943:e70aad5761b5 | 944:b2dcb8457067 |
---|---|
2041 char_u *endp; | 2041 char_u *endp; |
2042 hlf_T attr; | 2042 hlf_T attr; |
2043 int len; | 2043 int len; |
2044 # ifdef FEAT_SYN_HL | 2044 # ifdef FEAT_SYN_HL |
2045 int has_syntax = syntax_present(wp->w_buffer); | 2045 int has_syntax = syntax_present(wp->w_buffer); |
2046 # endif | |
2046 int col; | 2047 int col; |
2047 # endif | |
2048 int can_spell; | 2048 int can_spell; |
2049 char_u *buf = NULL; | 2049 char_u *buf = NULL; |
2050 int buflen = 0; | 2050 int buflen = 0; |
2051 int skip = 0; | 2051 int skip = 0; |
2052 int capcol = -1; | 2052 int capcol = -1; |
2091 /* For checking first word with a capital skip white space. */ | 2091 /* For checking first word with a capital skip white space. */ |
2092 if (capcol == 0) | 2092 if (capcol == 0) |
2093 capcol = (int)(skipwhite(line) - line); | 2093 capcol = (int)(skipwhite(line) - line); |
2094 else if (curline && wp == curwin) | 2094 else if (curline && wp == curwin) |
2095 { | 2095 { |
2096 int col = (int)(skipwhite(line) - line); | |
2097 | |
2098 /* For spellbadword(): check if first word needs a capital. */ | 2096 /* For spellbadword(): check if first word needs a capital. */ |
2097 col = (int)(skipwhite(line) - line); | |
2099 if (check_need_cap(lnum, col)) | 2098 if (check_need_cap(lnum, col)) |
2100 capcol = col; | 2099 capcol = col; |
2101 | 2100 |
2102 /* Need to get the line again, may have looked at the previous | 2101 /* Need to get the line again, may have looked at the previous |
2103 * one. */ | 2102 * one. */ |
5059 char_u *fol = NULL; | 5058 char_u *fol = NULL; |
5060 char_u *upp = NULL; | 5059 char_u *upp = NULL; |
5061 int do_rep; | 5060 int do_rep; |
5062 int do_repsal; | 5061 int do_repsal; |
5063 int do_sal; | 5062 int do_sal; |
5064 int do_map; | 5063 int do_mapline; |
5065 int found_map = FALSE; | 5064 int found_map = FALSE; |
5066 hashitem_T *hi; | 5065 hashitem_T *hi; |
5067 int l; | 5066 int l; |
5068 int compminlen = 0; /* COMPOUNDMIN value */ | 5067 int compminlen = 0; /* COMPOUNDMIN value */ |
5069 int compsylmax = 0; /* COMPOUNDSYLMAX value */ | 5068 int compsylmax = 0; /* COMPOUNDSYLMAX value */ |
5097 | 5096 |
5098 /* Only do SAL lines when not done in another .aff file already. */ | 5097 /* Only do SAL lines when not done in another .aff file already. */ |
5099 do_sal = spin->si_sal.ga_len == 0; | 5098 do_sal = spin->si_sal.ga_len == 0; |
5100 | 5099 |
5101 /* Only do MAP lines when not done in another .aff file already. */ | 5100 /* Only do MAP lines when not done in another .aff file already. */ |
5102 do_map = spin->si_map.ga_len == 0; | 5101 do_mapline = spin->si_map.ga_len == 0; |
5103 | 5102 |
5104 /* | 5103 /* |
5105 * Allocate and init the afffile_T structure. | 5104 * Allocate and init the afffile_T structure. |
5106 */ | 5105 */ |
5107 aff = (afffile_T *)getroom(spin, sizeof(afffile_T), TRUE); | 5106 aff = (afffile_T *)getroom(spin, sizeof(afffile_T), TRUE); |
5779 found_map = TRUE; | 5778 found_map = TRUE; |
5780 if (!isdigit(*items[1])) | 5779 if (!isdigit(*items[1])) |
5781 smsg((char_u *)_("Expected MAP count in %s line %d"), | 5780 smsg((char_u *)_("Expected MAP count in %s line %d"), |
5782 fname, lnum); | 5781 fname, lnum); |
5783 } | 5782 } |
5784 else if (do_map) | 5783 else if (do_mapline) |
5785 { | 5784 { |
5786 int c; | 5785 int c; |
5787 | 5786 |
5788 /* Check that every character appears only once. */ | 5787 /* Check that every character appears only once. */ |
5789 for (p = items[1]; *p != NUL; ) | 5788 for (p = items[1]; *p != NUL; ) |
7506 int | 7505 int |
7507 spell_check_msm() | 7506 spell_check_msm() |
7508 { | 7507 { |
7509 char_u *p = p_msm; | 7508 char_u *p = p_msm; |
7510 long start = 0; | 7509 long start = 0; |
7511 long inc = 0; | 7510 long incr = 0; |
7512 long added = 0; | 7511 long added = 0; |
7513 | 7512 |
7514 if (!VIM_ISDIGIT(*p)) | 7513 if (!VIM_ISDIGIT(*p)) |
7515 return FAIL; | 7514 return FAIL; |
7516 /* block count = (value * 1024) / SBLOCKSIZE (but avoid overflow)*/ | 7515 /* block count = (value * 1024) / SBLOCKSIZE (but avoid overflow)*/ |
7518 if (*p != ',') | 7517 if (*p != ',') |
7519 return FAIL; | 7518 return FAIL; |
7520 ++p; | 7519 ++p; |
7521 if (!VIM_ISDIGIT(*p)) | 7520 if (!VIM_ISDIGIT(*p)) |
7522 return FAIL; | 7521 return FAIL; |
7523 inc = (getdigits(&p) * 102) / (SBLOCKSIZE / 10); | 7522 incr = (getdigits(&p) * 102) / (SBLOCKSIZE / 10); |
7524 if (*p != ',') | 7523 if (*p != ',') |
7525 return FAIL; | 7524 return FAIL; |
7526 ++p; | 7525 ++p; |
7527 if (!VIM_ISDIGIT(*p)) | 7526 if (!VIM_ISDIGIT(*p)) |
7528 return FAIL; | 7527 return FAIL; |
7529 added = getdigits(&p) * 1024; | 7528 added = getdigits(&p) * 1024; |
7530 if (*p != NUL) | 7529 if (*p != NUL) |
7531 return FAIL; | 7530 return FAIL; |
7532 | 7531 |
7533 if (start == 0 || inc == 0 || added == 0 || inc > start) | 7532 if (start == 0 || incr == 0 || added == 0 || incr > start) |
7534 return FAIL; | 7533 return FAIL; |
7535 | 7534 |
7536 compress_start = start; | 7535 compress_start = start; |
7537 compress_inc = inc; | 7536 compress_inc = incr; |
7538 compress_added = added; | 7537 compress_added = added; |
7539 return OK; | 7538 return OK; |
7540 } | 7539 } |
7541 | 7540 |
7542 | 7541 |
8290 * in the file). | 8289 * in the file). |
8291 * | 8290 * |
8292 * Returns the number of nodes used. | 8291 * Returns the number of nodes used. |
8293 */ | 8292 */ |
8294 static int | 8293 static int |
8295 put_node(fd, node, index, regionmask, prefixtree) | 8294 put_node(fd, node, idx, regionmask, prefixtree) |
8296 FILE *fd; /* NULL when only counting */ | 8295 FILE *fd; /* NULL when only counting */ |
8297 wordnode_T *node; | 8296 wordnode_T *node; |
8298 int index; | 8297 int idx; |
8299 int regionmask; | 8298 int regionmask; |
8300 int prefixtree; /* TRUE for PREFIXTREE */ | 8299 int prefixtree; /* TRUE for PREFIXTREE */ |
8301 { | 8300 { |
8302 int newindex = index; | 8301 int newindex = idx; |
8303 int siblingcount = 0; | 8302 int siblingcount = 0; |
8304 wordnode_T *np; | 8303 wordnode_T *np; |
8305 int flags; | 8304 int flags; |
8306 | 8305 |
8307 /* If "node" is zero the tree is empty. */ | 8306 /* If "node" is zero the tree is empty. */ |
8308 if (node == NULL) | 8307 if (node == NULL) |
8309 return 0; | 8308 return 0; |
8310 | 8309 |
8311 /* Store the index where this node is written. */ | 8310 /* Store the index where this node is written. */ |
8312 node->wn_u1.index = index; | 8311 node->wn_u1.index = idx; |
8313 | 8312 |
8314 /* Count the number of siblings. */ | 8313 /* Count the number of siblings. */ |
8315 for (np = node; np != NULL; np = np->wn_sibling) | 8314 for (np = node; np != NULL; np = np->wn_sibling) |
8316 ++siblingcount; | 8315 ++siblingcount; |
8317 | 8316 |
9242 | 9241 |
9243 /* | 9242 /* |
9244 * Add "word[len]" to 'spellfile' as a good or bad word. | 9243 * Add "word[len]" to 'spellfile' as a good or bad word. |
9245 */ | 9244 */ |
9246 void | 9245 void |
9247 spell_add_word(word, len, bad, index, undo) | 9246 spell_add_word(word, len, bad, idx, undo) |
9248 char_u *word; | 9247 char_u *word; |
9249 int len; | 9248 int len; |
9250 int bad; | 9249 int bad; |
9251 int index; /* "zG" and "zW": zero, otherwise index in | 9250 int idx; /* "zG" and "zW": zero, otherwise index in |
9252 'spellfile' */ | 9251 'spellfile' */ |
9253 int undo; /* TRUE for "zug", "zuG", "zuw" and "zuW" */ | 9252 int undo; /* TRUE for "zug", "zuG", "zuw" and "zuW" */ |
9254 { | 9253 { |
9255 FILE *fd; | 9254 FILE *fd; |
9256 buf_T *buf = NULL; | 9255 buf_T *buf = NULL; |
9260 char_u line[MAXWLEN * 2]; | 9259 char_u line[MAXWLEN * 2]; |
9261 long fpos, fpos_next = 0; | 9260 long fpos, fpos_next = 0; |
9262 int i; | 9261 int i; |
9263 char_u *spf; | 9262 char_u *spf; |
9264 | 9263 |
9265 if (index == 0) /* use internal wordlist */ | 9264 if (idx == 0) /* use internal wordlist */ |
9266 { | 9265 { |
9267 if (int_wordlist == NULL) | 9266 if (int_wordlist == NULL) |
9268 { | 9267 { |
9269 int_wordlist = vim_tempname('s'); | 9268 int_wordlist = vim_tempname('s'); |
9270 if (int_wordlist == NULL) | 9269 if (int_wordlist == NULL) |
9288 } | 9287 } |
9289 | 9288 |
9290 for (spf = curbuf->b_p_spf, i = 1; *spf != NUL; ++i) | 9289 for (spf = curbuf->b_p_spf, i = 1; *spf != NUL; ++i) |
9291 { | 9290 { |
9292 copy_option_part(&spf, fnamebuf, MAXPATHL, ","); | 9291 copy_option_part(&spf, fnamebuf, MAXPATHL, ","); |
9293 if (i == index) | 9292 if (i == idx) |
9294 break; | 9293 break; |
9295 if (*spf == NUL) | 9294 if (*spf == NUL) |
9296 { | 9295 { |
9297 EMSGN(_("E765: 'spellfile' does not have %ld entries"), index); | 9296 EMSGN(_("E765: 'spellfile' does not have %ld entries"), idx); |
9298 return; | 9297 return; |
9299 } | 9298 } |
9300 } | 9299 } |
9301 | 9300 |
9302 /* Check that the user isn't editing the .add file somewhere. */ | 9301 /* Check that the user isn't editing the .add file somewhere. */ |
13579 if (badlen == 0 && goodlen == 0) | 13578 if (badlen == 0 && goodlen == 0) |
13580 /* goodword doesn't change anything; may happen for "the the" changing | 13579 /* goodword doesn't change anything; may happen for "the the" changing |
13581 * the first "the" to itself. */ | 13580 * the first "the" to itself. */ |
13582 return; | 13581 return; |
13583 | 13582 |
13584 /* Check if the word is already there. Also check the length that is | 13583 if (gap->ga_len == 0) |
13585 * being replaced "thes," -> "these" is a different suggestion from | 13584 i = -1; |
13586 * "thes" -> "these". */ | 13585 else |
13587 stp = &SUG(*gap, 0); | 13586 { |
13588 for (i = gap->ga_len; --i >= 0; ++stp) | 13587 /* Check if the word is already there. Also check the length that is |
13589 if (stp->st_wordlen == goodlen | 13588 * being replaced "thes," -> "these" is a different suggestion from |
13590 && stp->st_orglen == badlen | 13589 * "thes" -> "these". */ |
13591 && STRNCMP(stp->st_word, goodword, goodlen) == 0) | 13590 stp = &SUG(*gap, 0); |
13592 { | 13591 for (i = gap->ga_len; --i >= 0; ++stp) |
13593 /* | 13592 if (stp->st_wordlen == goodlen |
13594 * Found it. Remember the word with the lowest score. | 13593 && stp->st_orglen == badlen |
13595 */ | 13594 && STRNCMP(stp->st_word, goodword, goodlen) == 0) |
13596 if (stp->st_slang == NULL) | 13595 { |
13597 stp->st_slang = slang; | 13596 /* |
13598 | 13597 * Found it. Remember the word with the lowest score. |
13599 new_sug.st_score = score; | 13598 */ |
13600 new_sug.st_altscore = altscore; | 13599 if (stp->st_slang == NULL) |
13601 new_sug.st_had_bonus = had_bonus; | 13600 stp->st_slang = slang; |
13602 | 13601 |
13603 if (stp->st_had_bonus != had_bonus) | 13602 new_sug.st_score = score; |
13604 { | 13603 new_sug.st_altscore = altscore; |
13605 /* Only one of the two had the soundalike score computed. | 13604 new_sug.st_had_bonus = had_bonus; |
13606 * Need to do that for the other one now, otherwise the | 13605 |
13607 * scores can't be compared. This happens because | 13606 if (stp->st_had_bonus != had_bonus) |
13608 * suggest_try_change() doesn't compute the soundalike | |
13609 * word to keep it fast, while some special methods set | |
13610 * the soundalike score to zero. */ | |
13611 if (had_bonus) | |
13612 rescore_one(su, stp); | |
13613 else | |
13614 { | 13607 { |
13615 new_sug.st_word = stp->st_word; | 13608 /* Only one of the two had the soundalike score computed. |
13616 new_sug.st_wordlen = stp->st_wordlen; | 13609 * Need to do that for the other one now, otherwise the |
13617 new_sug.st_slang = stp->st_slang; | 13610 * scores can't be compared. This happens because |
13618 new_sug.st_orglen = badlen; | 13611 * suggest_try_change() doesn't compute the soundalike |
13619 rescore_one(su, &new_sug); | 13612 * word to keep it fast, while some special methods set |
13613 * the soundalike score to zero. */ | |
13614 if (had_bonus) | |
13615 rescore_one(su, stp); | |
13616 else | |
13617 { | |
13618 new_sug.st_word = stp->st_word; | |
13619 new_sug.st_wordlen = stp->st_wordlen; | |
13620 new_sug.st_slang = stp->st_slang; | |
13621 new_sug.st_orglen = badlen; | |
13622 rescore_one(su, &new_sug); | |
13623 } | |
13620 } | 13624 } |
13621 } | 13625 |
13622 | 13626 if (stp->st_score > new_sug.st_score) |
13623 if (stp->st_score > new_sug.st_score) | 13627 { |
13624 { | 13628 stp->st_score = new_sug.st_score; |
13625 stp->st_score = new_sug.st_score; | 13629 stp->st_altscore = new_sug.st_altscore; |
13626 stp->st_altscore = new_sug.st_altscore; | 13630 stp->st_had_bonus = new_sug.st_had_bonus; |
13627 stp->st_had_bonus = new_sug.st_had_bonus; | 13631 } |
13628 } | 13632 break; |
13629 break; | 13633 } |
13630 } | 13634 } |
13631 | 13635 |
13632 if (i < 0 && ga_grow(gap, 1) == OK) | 13636 if (i < 0 && ga_grow(gap, 1) == OK) |
13633 { | 13637 { |
13634 /* Add a suggestion. */ | 13638 /* Add a suggestion. */ |
13635 stp = &SUG(*gap, gap->ga_len); | 13639 stp = &SUG(*gap, gap->ga_len); |