Mercurial > vim
annotate src/spellsuggest.c @ 22858:52b5aa2e8c8f v8.2.1976
patch 8.2.1976: cannot backspace in prompt buffer after using cursor-left
Commit: https://github.com/vim/vim/commit/6f6244855fbce5aaa718cd5001a29aac3c5c15d6
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Nov 11 20:52:40 2020 +0100
patch 8.2.1976: cannot backspace in prompt buffer after using cursor-left
Problem: Cannot backspace in prompt buffer after using cursor-left. (Maxim
Kim)
Solution: Ignore "arrow_used" in a prompt buffer. (closes #7281)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 11 Nov 2020 21:00:05 +0100 |
parents | 2d6d70a913c1 |
children | 21f49d327f00 |
rev | line source |
---|---|
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * spellsuggest.c: functions for spelling suggestions |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 #if defined(FEAT_SPELL) || defined(PROTO) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 * Use this to adjust the score after finding suggestions, based on the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 * suggested word sounding like the bad word. This is much faster than doing |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 * it for every possible suggestion. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 * Disadvantage: When "the" is typed as "hte" it sounds quite different ("@" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 * vs "ht") and goes down in the list. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 * Used when 'spellsuggest' is set to "best". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 #define RESCORE(word_score, sound_score) ((3 * word_score + sound_score) / 4) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 * Do the opposite: based on a maximum end score and a known sound score, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 * compute the maximum word score that can be used. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 #define MAXSCORE(word_score, sound_score) ((4 * word_score - sound_score) / 3) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 // only used for su_badflags |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 #define WF_MIXCAP 0x20 // mix of upper and lower case: macaRONI |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 * Information used when looking for suggestions. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 typedef struct suginfo_S |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 garray_T su_ga; // suggestions, contains "suggest_T" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 int su_maxcount; // max. number of suggestions displayed |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 int su_maxscore; // maximum score for adding to su_ga |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 int su_sfmaxscore; // idem, for when doing soundfold words |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 garray_T su_sga; // like su_ga, sound-folded scoring |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 char_u *su_badptr; // start of bad word in line |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 int su_badlen; // length of detected bad word in line |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 int su_badflags; // caps flags for bad word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 char_u su_badword[MAXWLEN]; // bad word truncated at su_badlen |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 char_u su_fbadword[MAXWLEN]; // su_badword case-folded |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 char_u su_sal_badword[MAXWLEN]; // su_badword soundfolded |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 hashtab_T su_banned; // table with banned words |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 slang_T *su_sallang; // default language for sound folding |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 } suginfo_T; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 // One word suggestion. Used in "si_ga". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 typedef struct suggest_S |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 char_u *st_word; // suggested word, allocated string |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 int st_wordlen; // STRLEN(st_word) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 int st_orglen; // length of replaced text |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 int st_score; // lower is better |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 int st_altscore; // used when st_score compares equal |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 int st_salscore; // st_score is for soundalike |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 int st_had_bonus; // bonus already included in score |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 slang_T *st_slang; // language used for sound folding |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 } suggest_T; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 #define SUG(ga, i) (((suggest_T *)(ga).ga_data)[i]) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 // TRUE if a word appears in the list of banned words. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 #define WAS_BANNED(su, word) (!HASHITEM_EMPTY(hash_find(&su->su_banned, word))) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 // Number of suggestions kept when cleaning up. We need to keep more than |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 // what is displayed, because when rescore_suggestions() is called the score |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 // may change and wrong suggestions may be removed later. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 #define SUG_CLEAN_COUNT(su) ((su)->su_maxcount < 130 ? 150 : (su)->su_maxcount + 20) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 // Threshold for sorting and cleaning up suggestions. Don't want to keep lots |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 // of suggestions that are not going to be displayed. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 #define SUG_MAX_COUNT(su) (SUG_CLEAN_COUNT(su) + 50) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 // score for various changes |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 #define SCORE_SPLIT 149 // split bad word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 #define SCORE_SPLIT_NO 249 // split bad word with NOSPLITSUGS |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 #define SCORE_ICASE 52 // slightly different case |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 #define SCORE_REGION 200 // word is for different region |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 #define SCORE_RARE 180 // rare word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 #define SCORE_SWAP 75 // swap two characters |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 #define SCORE_SWAP3 110 // swap two characters in three |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 #define SCORE_REP 65 // REP replacement |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 #define SCORE_SUBST 93 // substitute a character |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 #define SCORE_SIMILAR 33 // substitute a similar character |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 #define SCORE_SUBCOMP 33 // substitute a composing character |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 #define SCORE_DEL 94 // delete a character |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 #define SCORE_DELDUP 66 // delete a duplicated character |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 #define SCORE_DELCOMP 28 // delete a composing character |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 #define SCORE_INS 96 // insert a character |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 #define SCORE_INSDUP 67 // insert a duplicate character |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 #define SCORE_INSCOMP 30 // insert a composing character |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 #define SCORE_NONWORD 103 // change non-word to word char |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 #define SCORE_FILE 30 // suggestion from a file |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 #define SCORE_MAXINIT 350 // Initial maximum score: higher == slower. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 // 350 allows for about three changes. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 #define SCORE_COMMON1 30 // subtracted for words seen before |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 #define SCORE_COMMON2 40 // subtracted for words often seen |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 #define SCORE_COMMON3 50 // subtracted for words very often seen |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 #define SCORE_THRES2 10 // word count threshold for COMMON2 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 #define SCORE_THRES3 100 // word count threshold for COMMON3 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 // When trying changed soundfold words it becomes slow when trying more than |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 // two changes. With less then two changes it's slightly faster but we miss a |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 // few good suggestions. In rare cases we need to try three of four changes. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 #define SCORE_SFMAX1 200 // maximum score for first try |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 #define SCORE_SFMAX2 300 // maximum score for second try |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 #define SCORE_SFMAX3 400 // maximum score for third try |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 #define SCORE_BIG SCORE_INS * 3 // big difference |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 #define SCORE_MAXMAX 999999 // accept any score |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 #define SCORE_LIMITMAX 350 // for spell_edit_score_limit() |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 // for spell_edit_score_limit() we need to know the minimum value of |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 // SCORE_ICASE, SCORE_SWAP, SCORE_DEL, SCORE_SIMILAR and SCORE_INS |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 #define SCORE_EDIT_MIN SCORE_SIMILAR |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 * For finding suggestions: At each node in the tree these states are tried: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 typedef enum |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 STATE_START = 0, // At start of node check for NUL bytes (goodword |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 // ends); if badword ends there is a match, otherwise |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 // try splitting word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 STATE_NOPREFIX, // try without prefix |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 STATE_SPLITUNDO, // Undo splitting. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 STATE_ENDNUL, // Past NUL bytes at start of the node. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 STATE_PLAIN, // Use each byte of the node. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 STATE_DEL, // Delete a byte from the bad word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 STATE_INS_PREP, // Prepare for inserting bytes. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 STATE_INS, // Insert a byte in the bad word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 STATE_SWAP, // Swap two bytes. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 STATE_UNSWAP, // Undo swap two characters. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 STATE_SWAP3, // Swap two characters over three. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 STATE_UNSWAP3, // Undo Swap two characters over three. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 STATE_UNROT3L, // Undo rotate three characters left |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 STATE_UNROT3R, // Undo rotate three characters right |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 STATE_REP_INI, // Prepare for using REP items. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 STATE_REP, // Use matching REP items from the .aff file. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 STATE_REP_UNDO, // Undo a REP item replacement. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 STATE_FINAL // End of this node. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 } state_T; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 * Struct to keep the state at each level in suggest_try_change(). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
159 typedef struct trystate_S |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 state_T ts_state; // state at this level, STATE_ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 int ts_score; // score |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 idx_T ts_arridx; // index in tree array, start of node |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 short ts_curi; // index in list of child nodes |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 char_u ts_fidx; // index in fword[], case-folded bad word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 char_u ts_fidxtry; // ts_fidx at which bytes may be changed |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 char_u ts_twordlen; // valid length of tword[] |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 char_u ts_prefixdepth; // stack depth for end of prefix or |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 // PFD_PREFIXTREE or PFD_NOPREFIX |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 char_u ts_flags; // TSF_ flags |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 char_u ts_tcharlen; // number of bytes in tword character |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 char_u ts_tcharidx; // current byte index in tword character |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 char_u ts_isdiff; // DIFF_ values |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 char_u ts_fcharstart; // index in fword where badword char started |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 char_u ts_prewordlen; // length of word in "preword[]" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 char_u ts_splitoff; // index in "tword" after last split |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 char_u ts_splitfidx; // "ts_fidx" at word split |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 char_u ts_complen; // nr of compound words used |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 char_u ts_compsplit; // index for "compflags" where word was spit |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 char_u ts_save_badflags; // su_badflags saved here |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 char_u ts_delidx; // index in fword for char that was deleted, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
182 // valid when "ts_flags" has TSF_DIDDEL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
183 } trystate_T; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 // values for ts_isdiff |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 #define DIFF_NONE 0 // no different byte (yet) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 #define DIFF_YES 1 // different byte found |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 #define DIFF_INSERT 2 // inserting character |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 // values for ts_flags |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 #define TSF_PREFIXOK 1 // already checked that prefix is OK |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 #define TSF_DIDSPLIT 2 // tried split at this point |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 #define TSF_DIDDEL 4 // did a delete, "ts_delidx" has index |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 // special values ts_prefixdepth |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 #define PFD_NOPREFIX 0xff // not using prefixes |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 #define PFD_PREFIXTREE 0xfe // walking through the prefix tree |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 #define PFD_NOTSPECIAL 0xfd // highest value that's not special |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int maxcount, int banbadword, int need_cap, int interactive); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
201 #ifdef FEAT_EVAL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 static void spell_suggest_expr(suginfo_T *su, char_u *expr); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
204 static void spell_suggest_file(suginfo_T *su, char_u *fname); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
205 static void spell_suggest_intern(suginfo_T *su, int interactive); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 static void spell_find_cleanup(suginfo_T *su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 static void suggest_try_special(suginfo_T *su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 static void suggest_try_change(suginfo_T *su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, int soundfold); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 static void go_deeper(trystate_T *stack, int depth, int score_add); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 static void find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 static void score_comp_sal(suginfo_T *su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 static void score_combine(suginfo_T *su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u *badsound); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 static void suggest_try_soundalike_prep(void); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 static void suggest_try_soundalike(suginfo_T *su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 static void suggest_try_soundalike_finish(void); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 static void add_sound_suggest(suginfo_T *su, char_u *goodword, int score, langp_T *lp); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 static int soundfold_find(slang_T *slang, char_u *word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 static int similar_chars(slang_T *slang, int c1, int c2); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
221 static void add_suggestion(suginfo_T *su, garray_T *gap, char_u *goodword, int badlen, int score, int altscore, int had_bonus, slang_T *slang, int maxsf); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 static void check_suggestions(suginfo_T *su, garray_T *gap); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 static void add_banned(suginfo_T *su, char_u *word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 static void rescore_suggestions(suginfo_T *su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 static void rescore_one(suginfo_T *su, suggest_T *stp); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 static int cleanup_suggestions(garray_T *gap, int maxscore, int keep); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 static int soundalike_score(char_u *goodsound, char_u *badsound); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
228 static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 static int spell_edit_score_limit(slang_T *slang, char_u *badword, char_u *goodword, int limit); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 static int spell_edit_score_limit_w(slang_T *slang, char_u *badword, char_u *goodword, int limit); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 * Return TRUE when the sequence of flags in "compflags" plus "flag" can |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
234 * possibly form a valid compounded word. This also checks the COMPOUNDRULE |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
235 * lines if they don't contain wildcards. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 static int |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 can_be_compound( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
239 trystate_T *sp, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
240 slang_T *slang, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 char_u *compflags, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 int flag) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
243 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
244 // If the flag doesn't appear in sl_compstartflags or sl_compallflags |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 // then it can't possibly compound. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 if (!byte_in_str(sp->ts_complen == sp->ts_compsplit |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 ? slang->sl_compstartflags : slang->sl_compallflags, flag)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 return FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
250 // If there are no wildcards, we can check if the flags collected so far |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
251 // possibly can form a match with COMPOUNDRULE patterns. This only |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
252 // makes sense when we have two or more words. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 if (slang->sl_comprules != NULL && sp->ts_complen > sp->ts_compsplit) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 int v; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
256 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
257 compflags[sp->ts_complen] = flag; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
258 compflags[sp->ts_complen + 1] = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 v = match_compoundrule(slang, compflags + sp->ts_compsplit); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 compflags[sp->ts_complen] = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
261 return v; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
262 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
263 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 return TRUE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
265 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 * Adjust the score of common words. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
269 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 static int |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
271 score_wordcount_adj( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 slang_T *slang, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
273 int score, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
274 char_u *word, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 int split) // word was split, less bonus |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 hashitem_T *hi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
278 wordcount_T *wc; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
279 int bonus; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
280 int newscore; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
282 hi = hash_find(&slang->sl_wordcount, word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 if (!HASHITEM_EMPTY(hi)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
284 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 wc = HI2WC(hi); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
286 if (wc->wc_count < SCORE_THRES2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 bonus = SCORE_COMMON1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
288 else if (wc->wc_count < SCORE_THRES3) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
289 bonus = SCORE_COMMON2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
290 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
291 bonus = SCORE_COMMON3; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 if (split) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
293 newscore = score - bonus / 2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
294 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 newscore = score - bonus; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
296 if (newscore < 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 return 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 return newscore; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
299 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 return score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
303 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
304 * Like captype() but for a KEEPCAP word add ONECAP if the word starts with a |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
305 * capital. So that make_case_word() can turn WOrd into Word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
306 * Add ALLCAP for "WOrD". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
307 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
308 static int |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
309 badword_captype(char_u *word, char_u *end) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
310 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
311 int flags = captype(word, end); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
312 int c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
313 int l, u; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 int first; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
315 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
316 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 if (flags & WF_KEEPCAP) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
318 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
319 // Count the number of UPPER and lower case letters. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
320 l = u = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
321 first = FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 for (p = word; p < end; MB_PTR_ADV(p)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 c = PTR2CHAR(p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
325 if (SPELL_ISUPPER(c)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
326 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 ++u; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
328 if (p == word) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
329 first = TRUE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
331 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
332 ++l; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
335 // If there are more UPPER than lower case letters suggest an |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
336 // ALLCAP word. Otherwise, if the first letter is UPPER then |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
337 // suggest ONECAP. Exception: "ALl" most likely should be "All", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
338 // require three upper case letters. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
339 if (u > l && u > 2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
340 flags |= WF_ALLCAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 else if (first) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 flags |= WF_ONECAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
343 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
344 if (u >= 2 && l >= 2) // maCARONI maCAroni |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
345 flags |= WF_MIXCAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
346 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 return flags; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
349 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
350 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
351 * Opposite of offset2bytes(). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
352 * "pp" points to the bytes and is advanced over it. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
353 * Returns the offset. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
354 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 static int |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 bytes2offset(char_u **pp) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
357 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
358 char_u *p = *pp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
359 int nr; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
360 int c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
362 c = *p++; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
363 if ((c & 0x80) == 0x00) // 1 byte |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
364 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
365 nr = c - 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
366 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
367 else if ((c & 0xc0) == 0x80) // 2 bytes |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
368 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
369 nr = (c & 0x3f) - 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
370 nr = nr * 255 + (*p++ - 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 else if ((c & 0xe0) == 0xc0) // 3 bytes |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 nr = (c & 0x1f) - 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 nr = nr * 255 + (*p++ - 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
376 nr = nr * 255 + (*p++ - 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
377 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 else // 4 bytes |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 nr = (c & 0x0f) - 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 nr = nr * 255 + (*p++ - 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 nr = nr * 255 + (*p++ - 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 nr = nr * 255 + (*p++ - 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
385 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
386 *pp = p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 return nr; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
388 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
389 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
390 // values for sps_flags |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 #define SPS_BEST 1 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
392 #define SPS_FAST 2 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 #define SPS_DOUBLE 4 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
394 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 static int sps_flags = SPS_BEST; // flags from 'spellsuggest' |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 static int sps_limit = 9999; // max nr of suggestions given |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
399 * Check the 'spellsuggest' option. Return FAIL if it's wrong. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
400 * Sets "sps_flags" and "sps_limit". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
402 int |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
403 spell_check_sps(void) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
404 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
406 char_u *s; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 char_u buf[MAXPATHL]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 int f; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 sps_flags = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 sps_limit = 9999; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 for (p = p_sps; *p != NUL; ) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 copy_option_part(&p, buf, MAXPATHL, ","); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 f = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 if (VIM_ISDIGIT(*buf)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 s = buf; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 sps_limit = getdigits(&s); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 if (*s != NUL && !VIM_ISDIGIT(*s)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 f = -1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 else if (STRCMP(buf, "best") == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 f = SPS_BEST; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 else if (STRCMP(buf, "fast") == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
428 f = SPS_FAST; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 else if (STRCMP(buf, "double") == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
430 f = SPS_DOUBLE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
431 else if (STRNCMP(buf, "expr:", 5) != 0 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 && STRNCMP(buf, "file:", 5) != 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 f = -1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
435 if (f == -1 || (sps_flags != 0 && f != 0)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
436 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 sps_flags = SPS_BEST; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 sps_limit = 9999; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 return FAIL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 if (f != 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 sps_flags = f; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 if (sps_flags == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 sps_flags = SPS_BEST; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 return OK; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 * "z=": Find badly spelled word under or after the cursor. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 * Give suggestions for the properly spelled word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 * In Visual mode use the highlighted word as the bad word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 * When "count" is non-zero use that suggestion. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 spell_suggest(int count) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 char_u *line; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 pos_T prev_cursor = curwin->w_cursor; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 char_u wcopy[MAXWLEN + 2]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 int i; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 int c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 suginfo_T sug; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 suggest_T *stp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 int mouse_used; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 int need_cap; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 int limit; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 int selected = count; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 int badlen = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
473 int msg_scroll_save = msg_scroll; |
20786
90b96fa35e4b
patch 8.2.0945: cannot use "z=" when 'spell' is off
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
474 int wo_spell_save = curwin->w_p_spell; |
90b96fa35e4b
patch 8.2.0945: cannot use "z=" when 'spell' is off
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
475 |
90b96fa35e4b
patch 8.2.0945: cannot use "z=" when 'spell' is off
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
476 if (!curwin->w_p_spell) |
90b96fa35e4b
patch 8.2.0945: cannot use "z=" when 'spell' is off
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
477 { |
90b96fa35e4b
patch 8.2.0945: cannot use "z=" when 'spell' is off
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
478 did_set_spelllang(curwin); |
90b96fa35e4b
patch 8.2.0945: cannot use "z=" when 'spell' is off
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
479 curwin->w_p_spell = TRUE; |
90b96fa35e4b
patch 8.2.0945: cannot use "z=" when 'spell' is off
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
480 } |
90b96fa35e4b
patch 8.2.0945: cannot use "z=" when 'spell' is off
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
481 |
90b96fa35e4b
patch 8.2.0945: cannot use "z=" when 'spell' is off
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
482 if (*curwin->w_s->b_p_spl == NUL) |
90b96fa35e4b
patch 8.2.0945: cannot use "z=" when 'spell' is off
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
483 { |
90b96fa35e4b
patch 8.2.0945: cannot use "z=" when 'spell' is off
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
484 emsg(_(e_no_spell)); |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 return; |
20786
90b96fa35e4b
patch 8.2.0945: cannot use "z=" when 'spell' is off
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
486 } |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 if (VIsual_active) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 // Use the Visually selected text as the bad word. But reject |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
491 // a multi-line selection. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 if (curwin->w_cursor.lnum != VIsual.lnum) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 vim_beep(BO_SPELL); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 return; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 badlen = (int)curwin->w_cursor.col - (int)VIsual.col; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 if (badlen < 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 badlen = -badlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 curwin->w_cursor.col = VIsual.col; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 ++badlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 end_visual_mode(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 // Find the start of the badly spelled word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 else if (spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL) == 0 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
507 || curwin->w_cursor.col > prev_cursor.col) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 // No bad word or it starts after the cursor: use the word under the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 // cursor. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 curwin->w_cursor = prev_cursor; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
512 line = ml_get_curline(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
513 p = line + curwin->w_cursor.col; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
514 // Backup to before start of word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
515 while (p > line && spell_iswordp_nmw(p, curwin)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 MB_PTR_BACK(line, p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 // Forward to start of word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 while (*p != NUL && !spell_iswordp_nmw(p, curwin)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 MB_PTR_ADV(p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 if (!spell_iswordp_nmw(p, curwin)) // No word found. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
523 beep_flush(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 return; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 curwin->w_cursor.col = (colnr_T)(p - line); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
528 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
529 // Get the word and its length. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 // Figure out if the word should be capitalised. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 need_cap = check_need_cap(curwin->w_cursor.lnum, curwin->w_cursor.col); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
534 // Make a copy of current line since autocommands may free the line. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
535 line = vim_strsave(ml_get_curline()); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 if (line == NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
537 goto skip; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
539 // Get the list of suggestions. Limit to 'lines' - 2 or the number in |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 // 'spellsuggest', whatever is smaller. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 if (sps_limit > (int)Rows - 2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 limit = (int)Rows - 2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
544 limit = sps_limit; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
545 spell_find_suggest(line + curwin->w_cursor.col, badlen, &sug, limit, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
546 TRUE, need_cap, TRUE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
547 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
548 if (sug.su_ga.ga_len == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
549 msg(_("Sorry, no suggestions")); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
550 else if (count > 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
551 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
552 if (count > sug.su_ga.ga_len) |
18960
34aa888bf5ad
patch 8.2.0041: leaking memory when selecting spell suggestion
Bram Moolenaar <Bram@vim.org>
parents:
18957
diff
changeset
|
553 smsg(_("Sorry, only %ld suggestions"), (long)sug.su_ga.ga_len); |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
554 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
555 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
556 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
557 #ifdef FEAT_RIGHTLEFT |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 // When 'rightleft' is set the list is drawn right-left. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
559 cmdmsg_rl = curwin->w_p_rl; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
560 if (cmdmsg_rl) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
561 msg_col = Columns - 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 // List the suggestions. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 msg_start(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 msg_row = Rows - 1; // for when 'cmdheight' > 1 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
567 lines_left = Rows; // avoid more prompt |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 vim_snprintf((char *)IObuff, IOSIZE, _("Change \"%.*s\" to:"), |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 sug.su_badlen, sug.su_badptr); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 #ifdef FEAT_RIGHTLEFT |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 if (cmdmsg_rl && STRNCMP(IObuff, "Change", 6) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 // And now the rabbit from the high hat: Avoid showing the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
574 // untranslated message rightleft. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 vim_snprintf((char *)IObuff, IOSIZE, ":ot \"%.*s\" egnahC", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
576 sug.su_badlen, sug.su_badptr); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
577 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
578 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
579 msg_puts((char *)IObuff); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
580 msg_clr_eos(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
581 msg_putchar('\n'); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
582 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 msg_scroll = TRUE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 for (i = 0; i < sug.su_ga.ga_len; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
585 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 stp = &SUG(sug.su_ga, i); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
587 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 // The suggested word may replace only part of the bad word, add |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
589 // the not replaced part. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
590 vim_strncpy(wcopy, stp->st_word, MAXWLEN); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
591 if (sug.su_badlen > stp->st_orglen) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
592 vim_strncpy(wcopy + stp->st_wordlen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 sug.su_badptr + stp->st_orglen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
594 sug.su_badlen - stp->st_orglen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
595 vim_snprintf((char *)IObuff, IOSIZE, "%2d", i + 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
596 #ifdef FEAT_RIGHTLEFT |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
597 if (cmdmsg_rl) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
598 rl_mirror(IObuff); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
599 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
600 msg_puts((char *)IObuff); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
602 vim_snprintf((char *)IObuff, IOSIZE, " \"%s\"", wcopy); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 msg_puts((char *)IObuff); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
604 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
605 // The word may replace more than "su_badlen". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
606 if (sug.su_badlen < stp->st_orglen) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
607 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 vim_snprintf((char *)IObuff, IOSIZE, _(" < \"%.*s\""), |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
609 stp->st_orglen, sug.su_badptr); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
610 msg_puts((char *)IObuff); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
611 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
612 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 if (p_verbose > 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
614 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
615 // Add the score. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 if (sps_flags & (SPS_DOUBLE | SPS_BEST)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
617 vim_snprintf((char *)IObuff, IOSIZE, " (%s%d - %d)", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
618 stp->st_salscore ? "s " : "", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
619 stp->st_score, stp->st_altscore); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
621 vim_snprintf((char *)IObuff, IOSIZE, " (%d)", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
622 stp->st_score); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
623 #ifdef FEAT_RIGHTLEFT |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
624 if (cmdmsg_rl) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
625 // Mirror the numbers, but keep the leading space. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 rl_mirror(IObuff + 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 msg_advance(30); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 msg_puts((char *)IObuff); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
631 msg_putchar('\n'); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
632 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
634 #ifdef FEAT_RIGHTLEFT |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
635 cmdmsg_rl = FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
636 msg_col = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
637 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
638 // Ask for choice. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 selected = prompt_for_number(&mouse_used); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
640 if (mouse_used) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 selected -= lines_left; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 lines_left = Rows; // avoid more prompt |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 // don't delay for 'smd' in normal_cmd() |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 msg_scroll = msg_scroll_save; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
645 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
646 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 if (selected > 0 && selected <= sug.su_ga.ga_len && u_save_cursor() == OK) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
648 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
649 // Save the from and to text for :spellrepall. |
18960
34aa888bf5ad
patch 8.2.0041: leaking memory when selecting spell suggestion
Bram Moolenaar <Bram@vim.org>
parents:
18957
diff
changeset
|
650 VIM_CLEAR(repl_from); |
34aa888bf5ad
patch 8.2.0041: leaking memory when selecting spell suggestion
Bram Moolenaar <Bram@vim.org>
parents:
18957
diff
changeset
|
651 VIM_CLEAR(repl_to); |
34aa888bf5ad
patch 8.2.0041: leaking memory when selecting spell suggestion
Bram Moolenaar <Bram@vim.org>
parents:
18957
diff
changeset
|
652 |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
653 stp = &SUG(sug.su_ga, selected - 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
654 if (sug.su_badlen > stp->st_orglen) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
655 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
656 // Replacing less than "su_badlen", append the remainder to |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
657 // repl_to. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
658 repl_from = vim_strnsave(sug.su_badptr, sug.su_badlen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
659 vim_snprintf((char *)IObuff, IOSIZE, "%s%.*s", stp->st_word, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
660 sug.su_badlen - stp->st_orglen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 sug.su_badptr + stp->st_orglen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
662 repl_to = vim_strsave(IObuff); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
663 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
664 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
665 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
666 // Replacing su_badlen or more, use the whole word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 repl_from = vim_strnsave(sug.su_badptr, stp->st_orglen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
668 repl_to = vim_strsave(stp->st_word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
670 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
671 // Replace the word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
672 p = alloc(STRLEN(line) - stp->st_orglen + stp->st_wordlen + 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 if (p != NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 c = (int)(sug.su_badptr - line); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 mch_memmove(p, line, c); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 STRCPY(p + c, stp->st_word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 STRCAT(p, sug.su_badptr + stp->st_orglen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
679 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 // For redo we use a change-word command. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
681 ResetRedobuff(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 AppendToRedobuff((char_u *)"ciw"); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
683 AppendToRedobuffLit(p + c, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
684 stp->st_wordlen + sug.su_badlen - stp->st_orglen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
685 AppendCharToRedobuff(ESC); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
686 |
21087
e01b20e3a720
patch 8.2.1095: may use pointer after freeing it
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
687 // "p" may be freed here |
e01b20e3a720
patch 8.2.1095: may use pointer after freeing it
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
688 ml_replace(curwin->w_cursor.lnum, p, FALSE); |
e01b20e3a720
patch 8.2.1095: may use pointer after freeing it
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
689 curwin->w_cursor.col = c; |
e01b20e3a720
patch 8.2.1095: may use pointer after freeing it
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
690 |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 changed_bytes(curwin->w_cursor.lnum, c); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
692 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 curwin->w_cursor = prev_cursor; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
696 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
697 spell_find_cleanup(&sug); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 skip: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 vim_free(line); |
20786
90b96fa35e4b
patch 8.2.0945: cannot use "z=" when 'spell' is off
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
700 curwin->w_p_spell = wo_spell_save; |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
702 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
704 * Find spell suggestions for "word". Return them in the growarray "*gap" as |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 * a list of allocated strings. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
706 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
707 void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
708 spell_suggest_list( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
709 garray_T *gap, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
710 char_u *word, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
711 int maxcount, // maximum nr of suggestions |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
712 int need_cap, // 'spellcapcheck' matched |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
713 int interactive) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
714 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
715 suginfo_T sug; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
716 int i; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
717 suggest_T *stp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
718 char_u *wcopy; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
719 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
720 spell_find_suggest(word, 0, &sug, maxcount, FALSE, need_cap, interactive); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
721 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
722 // Make room in "gap". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
723 ga_init2(gap, sizeof(char_u *), sug.su_ga.ga_len + 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
724 if (ga_grow(gap, sug.su_ga.ga_len) == OK) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
725 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
726 for (i = 0; i < sug.su_ga.ga_len; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
727 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
728 stp = &SUG(sug.su_ga, i); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
729 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
730 // The suggested word may replace only part of "word", add the not |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
731 // replaced part. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
732 wcopy = alloc(stp->st_wordlen |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 + (unsigned)STRLEN(sug.su_badptr + stp->st_orglen) + 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 if (wcopy == NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
736 STRCPY(wcopy, stp->st_word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
737 STRCPY(wcopy + stp->st_wordlen, sug.su_badptr + stp->st_orglen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 ((char_u **)gap->ga_data)[gap->ga_len++] = wcopy; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
740 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
741 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
742 spell_find_cleanup(&sug); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
743 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
745 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
746 * Find spell suggestions for the word at the start of "badptr". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 * Return the suggestions in "su->su_ga". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
748 * The maximum number of suggestions is "maxcount". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 * Note: does use info for the current window. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
750 * This is based on the mechanisms of Aspell, but completely reimplemented. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
751 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
752 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
753 spell_find_suggest( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
754 char_u *badptr, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
755 int badlen, // length of bad word or 0 if unknown |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 suginfo_T *su, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
757 int maxcount, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
758 int banbadword, // don't include badword in suggestions |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 int need_cap, // word should start with capital |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
760 int interactive) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
761 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
762 hlf_T attr = HLF_COUNT; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
763 char_u buf[MAXPATHL]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
764 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
765 int do_combine = FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
766 char_u *sps_copy; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
767 #ifdef FEAT_EVAL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
768 static int expr_busy = FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
769 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
770 int c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
771 int i; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
772 langp_T *lp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
773 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
774 // Set the info in "*su". |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
775 CLEAR_POINTER(su); |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
776 ga_init2(&su->su_ga, (int)sizeof(suggest_T), 10); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 ga_init2(&su->su_sga, (int)sizeof(suggest_T), 10); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
778 if (*badptr == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
779 return; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
780 hash_init(&su->su_banned); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
781 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 su->su_badptr = badptr; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
783 if (badlen != 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
784 su->su_badlen = badlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
785 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
786 su->su_badlen = spell_check(curwin, su->su_badptr, &attr, NULL, FALSE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
787 su->su_maxcount = maxcount; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
788 su->su_maxscore = SCORE_MAXINIT; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
789 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
790 if (su->su_badlen >= MAXWLEN) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
791 su->su_badlen = MAXWLEN - 1; // just in case |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
792 vim_strncpy(su->su_badword, su->su_badptr, su->su_badlen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
793 (void)spell_casefold(su->su_badptr, su->su_badlen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
794 su->su_fbadword, MAXWLEN); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
795 // TODO: make this work if the case-folded text is longer than the original |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
796 // text. Currently an illegal byte causes wrong pointer computations. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
797 su->su_fbadword[su->su_badlen] = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
798 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
799 // get caps flags for bad word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
800 su->su_badflags = badword_captype(su->su_badptr, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
801 su->su_badptr + su->su_badlen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
802 if (need_cap) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
803 su->su_badflags |= WF_ONECAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
804 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
805 // Find the default language for sound folding. We simply use the first |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
806 // one in 'spelllang' that supports sound folding. That's good for when |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
807 // using multiple files for one language, it's not that bad when mixing |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
808 // languages (e.g., "pl,en"). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
809 for (i = 0; i < curbuf->b_s.b_langp.ga_len; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
810 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
811 lp = LANGP_ENTRY(curbuf->b_s.b_langp, i); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
812 if (lp->lp_sallang != NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
813 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
814 su->su_sallang = lp->lp_sallang; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
815 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
816 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
817 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
818 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
819 // Soundfold the bad word with the default sound folding, so that we don't |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 // have to do this many times. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
821 if (su->su_sallang != NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 spell_soundfold(su->su_sallang, su->su_fbadword, TRUE, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 su->su_sal_badword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
824 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 // If the word is not capitalised and spell_check() doesn't consider the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
826 // word to be bad then it might need to be capitalised. Add a suggestion |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
827 // for that. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
828 c = PTR2CHAR(su->su_badptr); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
829 if (!SPELL_ISUPPER(c) && attr == HLF_COUNT) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
830 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
831 make_case_word(su->su_badword, buf, WF_ONECAP); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
832 add_suggestion(su, &su->su_ga, buf, su->su_badlen, SCORE_ICASE, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
833 0, TRUE, su->su_sallang, FALSE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 // Ban the bad word itself. It may appear in another region. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 if (banbadword) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
838 add_banned(su, su->su_badword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
839 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 // Make a copy of 'spellsuggest', because the expression may change it. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
841 sps_copy = vim_strsave(p_sps); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
842 if (sps_copy == NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
843 return; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 // Loop over the items in 'spellsuggest'. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
846 for (p = sps_copy; *p != NUL; ) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
847 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 copy_option_part(&p, buf, MAXPATHL, ","); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
849 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
850 if (STRNCMP(buf, "expr:", 5) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
851 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
852 #ifdef FEAT_EVAL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
853 // Evaluate an expression. Skip this when called recursively, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
854 // when using spellsuggest() in the expression. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
855 if (!expr_busy) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
856 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 expr_busy = TRUE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
858 spell_suggest_expr(su, buf + 5); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
859 expr_busy = FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
860 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
861 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
862 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
863 else if (STRNCMP(buf, "file:", 5) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 // Use list of suggestions in a file. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
865 spell_suggest_file(su, buf + 5); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
866 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
868 // Use internal method. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
869 spell_suggest_intern(su, interactive); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
870 if (sps_flags & SPS_DOUBLE) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
871 do_combine = TRUE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
872 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
873 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
874 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
875 vim_free(sps_copy); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
876 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
877 if (do_combine) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
878 // Combine the two list of suggestions. This must be done last, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
879 // because sorting changes the order again. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
880 score_combine(su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
881 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
882 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
883 #ifdef FEAT_EVAL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
884 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
885 * Find suggestions by evaluating expression "expr". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
886 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
887 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
888 spell_suggest_expr(suginfo_T *su, char_u *expr) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
889 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
890 list_T *list; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
891 listitem_T *li; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
892 int score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
893 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
894 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
895 // The work is split up in a few parts to avoid having to export |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
896 // suginfo_T. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
897 // First evaluate the expression and get the resulting list. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
898 list = eval_spell_expr(su->su_badword, expr); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
899 if (list != NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
900 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
901 // Loop over the items in the list. |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19661
diff
changeset
|
902 FOR_ALL_LIST_ITEMS(list, li) |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
903 if (li->li_tv.v_type == VAR_LIST) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
904 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
905 // Get the word and the score from the items. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
906 score = get_spellword(li->li_tv.vval.v_list, &p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
907 if (score >= 0 && score <= su->su_maxscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
908 add_suggestion(su, &su->su_ga, p, su->su_badlen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
909 score, 0, TRUE, su->su_sallang, FALSE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
910 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
911 list_unref(list); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
912 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
913 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
914 // Remove bogus suggestions, sort and truncate at "maxcount". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
915 check_suggestions(su, &su->su_ga); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
916 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, su->su_maxcount); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
917 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
918 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
919 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
920 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
921 * Find suggestions in file "fname". Used for "file:" in 'spellsuggest'. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
922 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
923 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
924 spell_suggest_file(suginfo_T *su, char_u *fname) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
925 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
926 FILE *fd; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
927 char_u line[MAXWLEN * 2]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
929 int len; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
930 char_u cword[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
931 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
932 // Open the file. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
933 fd = mch_fopen((char *)fname, "r"); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
934 if (fd == NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
935 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
936 semsg(_(e_notopen), fname); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
937 return; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
938 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
939 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
940 // Read it line by line. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
941 while (!vim_fgets(line, MAXWLEN * 2, fd) && !got_int) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 line_breakcheck(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 p = vim_strchr(line, '/'); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 if (p == NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 continue; // No Tab found, just skip the line. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
948 *p++ = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
949 if (STRICMP(su->su_badword, line) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
950 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
951 // Match! Isolate the good word, until CR or NL. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
952 for (len = 0; p[len] >= ' '; ++len) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
953 ; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
954 p[len] = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
955 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
956 // If the suggestion doesn't have specific case duplicate the case |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
957 // of the bad word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
958 if (captype(p, NULL) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
959 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
960 make_case_word(p, cword, su->su_badflags); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 p = cword; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 add_suggestion(su, &su->su_ga, p, su->su_badlen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
965 SCORE_FILE, 0, TRUE, su->su_sallang, FALSE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 fclose(fd); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 // Remove bogus suggestions, sort and truncate at "maxcount". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 check_suggestions(su, &su->su_ga); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
973 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, su->su_maxcount); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
974 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 * Find suggestions for the internal method indicated by "sps_flags". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 spell_suggest_intern(suginfo_T *su, int interactive) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 // Load the .sug file(s) that are available and not done yet. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 suggest_load_files(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 // 1. Try special cases, such as repeating a word: "the the" -> "the". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 // |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
987 // Set a maximum score to limit the combination of operations that is |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
988 // tried. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 suggest_try_special(su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 // 2. Try inserting/deleting/swapping/changing a letter, use REP entries |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 // from the .aff file and inserting a space (split the word). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 suggest_try_change(su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 // For the resulting top-scorers compute the sound-a-like score. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 if (sps_flags & SPS_DOUBLE) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 score_comp_sal(su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 // 3. Try finding sound-a-like words. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1000 if ((sps_flags & SPS_FAST) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 if (sps_flags & SPS_BEST) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 // Adjust the word score for the suggestions found so far for how |
18498
9e6d5a4abb1c
patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
1004 // they sound like. |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 rescore_suggestions(su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 // While going through the soundfold tree "su_maxscore" is the score |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 // for the soundfold word, limits the changes that are being tried, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 // and "su_sfmaxscore" the rescored score, which is set by |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 // cleanup_suggestions(). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 // First find words with a small edit distance, because this is much |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 // faster and often already finds the top-N suggestions. If we didn't |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 // find many suggestions try again with a higher edit distance. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 // "sl_sounddone" is used to avoid doing the same word twice. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 suggest_try_soundalike_prep(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 su->su_maxscore = SCORE_SFMAX1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 su->su_sfmaxscore = SCORE_MAXINIT * 3; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 suggest_try_soundalike(su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 if (su->su_ga.ga_len < SUG_CLEAN_COUNT(su)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 // We didn't find enough matches, try again, allowing more |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 // changes to the soundfold word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 su->su_maxscore = SCORE_SFMAX2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 suggest_try_soundalike(su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 if (su->su_ga.ga_len < SUG_CLEAN_COUNT(su)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 // Still didn't find enough matches, try again, allowing even |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 // more changes to the soundfold word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 su->su_maxscore = SCORE_SFMAX3; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 suggest_try_soundalike(su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1031 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 su->su_maxscore = su->su_sfmaxscore; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 suggest_try_soundalike_finish(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 // When CTRL-C was hit while searching do show the results. Only clear |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 // got_int when using a command, not for spellsuggest(). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 ui_breakcheck(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 if (interactive && got_int) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 (void)vgetc(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 got_int = FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 if ((sps_flags & SPS_DOUBLE) == 0 && su->su_ga.ga_len != 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 if (sps_flags & SPS_BEST) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 // Adjust the word score for how it sounds like. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 rescore_suggestions(su); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 // Remove bogus suggestions, sort and truncate at "maxcount". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 check_suggestions(su, &su->su_ga); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, su->su_maxcount); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 * Free the info put in "*su" by spell_find_suggest(). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 spell_find_cleanup(suginfo_T *su) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 int i; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 // Free the suggestions. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 for (i = 0; i < su->su_ga.ga_len; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 vim_free(SUG(su->su_ga, i).st_word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 ga_clear(&su->su_ga); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1070 for (i = 0; i < su->su_sga.ga_len; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 vim_free(SUG(su->su_sga, i).st_word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1072 ga_clear(&su->su_sga); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 // Free the banned words. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 hash_clear_all(&su->su_banned, 0); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 * Try finding suggestions by recognizing specific situations. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1082 suggest_try_special(suginfo_T *su) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1083 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1084 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 size_t len; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 int c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 char_u word[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1088 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 // Recognize a word that is repeated: "the the". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1090 p = skiptowhite(su->su_fbadword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 len = p - su->su_fbadword; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 p = skipwhite(p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 if (STRLEN(p) == len && STRNCMP(su->su_fbadword, p, len) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 // Include badflags: if the badword is onecap or allcap |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 // use that for the goodword too: "The the" -> "The". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 c = su->su_fbadword[len]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 su->su_fbadword[len] = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 make_case_word(su->su_fbadword, word, su->su_badflags); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 su->su_fbadword[len] = c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1102 // Give a soundalike score of 0, compute the score as if deleting one |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 // character. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1104 add_suggestion(su, &su->su_ga, word, su->su_badlen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1105 RESCORE(SCORE_REP, 0), 0, TRUE, su->su_sallang, FALSE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 * Change the 0 to 1 to measure how much time is spent in each state. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1111 * Output is dumped in "suggestprof". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1113 #if 0 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 # define SUGGEST_PROFILE |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 proftime_T current; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 proftime_T total; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 proftime_T times[STATE_FINAL + 1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1118 long counts[STATE_FINAL + 1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 prof_init(void) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 for (int i = 0; i <= STATE_FINAL; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 profile_zero(×[i]); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 counts[i] = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 profile_start(¤t); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 profile_start(&total); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1132 // call before changing state |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1133 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1134 prof_store(state_T state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1135 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1136 profile_end(¤t); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1137 profile_add(×[state], ¤t); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1138 ++counts[state]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1139 profile_start(¤t); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1140 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 # define PROF_STORE(state) prof_store(state); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1142 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1143 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1144 prof_report(char *name) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1146 FILE *fd = fopen("suggestprof", "a"); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1147 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1148 profile_end(&total); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1149 fprintf(fd, "-----------------------\n"); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 fprintf(fd, "%s: %s\n", name, profile_msg(&total)); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 for (int i = 0; i <= STATE_FINAL; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 fprintf(fd, "%d: %s (%ld)\n", i, profile_msg(×[i]), counts[i]); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 fclose(fd); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 #else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1156 # define PROF_STORE(state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1159 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1160 * Try finding suggestions by adding/removing/swapping letters. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1163 suggest_try_change(suginfo_T *su) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1164 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1165 char_u fword[MAXWLEN]; // copy of the bad word, case-folded |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 int n; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 int lpi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 langp_T *lp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 // We make a copy of the case-folded bad word, so that we can modify it |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 // to find matches (esp. REP items). Append some more text, changing |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1173 // chars after the bad word may help. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 STRCPY(fword, su->su_fbadword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1175 n = (int)STRLEN(fword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1176 p = su->su_badptr + su->su_badlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 (void)spell_casefold(p, (int)STRLEN(p), fword + n, MAXWLEN - n); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1181 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1183 // If reloading a spell file fails it's still in the list but |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1184 // everything has been cleared. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 if (lp->lp_slang->sl_fbyts == NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 continue; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 // Try it for this language. Will add possible suggestions. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1189 #ifdef SUGGEST_PROFILE |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1190 prof_init(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1191 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 suggest_trie_walk(su, lp, fword, FALSE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1193 #ifdef SUGGEST_PROFILE |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 prof_report("try_change"); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1195 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1196 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1197 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1198 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1199 // Check the maximum score, if we go over it we won't try this change. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 #define TRY_DEEPER(su, stack, depth, add) \ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 (stack[depth].ts_score + (add) < su->su_maxscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1203 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 * Try finding suggestions by adding/removing/swapping letters. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 * |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 * This uses a state machine. At each node in the tree we try various |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 * operations. When trying if an operation works "depth" is increased and the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 * stack[] is used to store info. This allows combinations, thus insert one |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1209 * character, replace one and delete another. The number of changes is |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1210 * limited by su->su_maxscore. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1211 * |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 * After implementing this I noticed an article by Kemal Oflazer that |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1213 * describes something similar: "Error-tolerant Finite State Recognition with |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 * Applications to Morphological Analysis and Spelling Correction" (1996). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1215 * The implementation in the article is simplified and requires a stack of |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1216 * unknown depth. The implementation here only needs a stack depth equal to |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1217 * the length of the word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1218 * |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1219 * This is also used for the sound-folded word, "soundfold" is TRUE then. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1220 * The mechanism is the same, but we find a match with a sound-folded word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 * that comes from one or more original words. Each of these words may be |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1222 * added, this is done by add_sound_suggest(). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1223 * Don't use: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1224 * the prefix tree or the keep-case tree |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1225 * "su->su_badlen" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1226 * anything to do with upper and lower case |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1227 * anything to do with word or non-word characters ("spell_iswordp()") |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 * banned words |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1229 * word flags (rare, region, compounding) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1230 * word splitting for now |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1231 * "similar_chars()" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1232 * use "slang->sl_repsal" instead of "lp->lp_replang->sl_rep" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1235 suggest_trie_walk( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1236 suginfo_T *su, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 langp_T *lp, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 char_u *fword, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 int soundfold) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 char_u tword[MAXWLEN]; // good word collected so far |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1242 trystate_T stack[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 char_u preword[MAXWLEN * 3]; // word found with proper case; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1244 // concatenation of prefix compound |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1245 // words and split word. NUL terminated |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1246 // when going deeper but not when coming |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1247 // back. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1248 char_u compflags[MAXWLEN]; // compound flags, one for each word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 trystate_T *sp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1250 int newscore; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1251 int score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1252 char_u *byts, *fbyts, *pbyts; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1253 idx_T *idxs, *fidxs, *pidxs; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1254 int depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 int c, c2, c3; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1256 int n = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1257 int flags; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1258 garray_T *gap; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1259 idx_T arridx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1260 int len; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1261 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1262 fromto_T *ftp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1263 int fl = 0, tl; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1264 int repextra = 0; // extra bytes in fword[] from REP item |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1265 slang_T *slang = lp->lp_slang; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 int fword_ends; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1267 int goodword_ends; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 #ifdef DEBUG_TRIEWALK |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 // Stores the name of the change made at each level. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 char_u changename[MAXWLEN][80]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1271 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1272 int breakcheckcount = 1000; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1273 int compound_ok; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1274 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1275 // Go through the whole case-fold tree, try changes at each node. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1276 // "tword[]" contains the word collected from nodes in the tree. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1277 // "fword[]" the word we are trying to match with (initially the bad |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 // word). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1279 depth = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1280 sp = &stack[0]; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1281 CLEAR_POINTER(sp); |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1282 sp->ts_curi = 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1283 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1284 if (soundfold) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1285 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1286 // Going through the soundfold tree. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1287 byts = fbyts = slang->sl_sbyts; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1288 idxs = fidxs = slang->sl_sidxs; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1289 pbyts = NULL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 pidxs = NULL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1291 sp->ts_prefixdepth = PFD_NOPREFIX; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1292 sp->ts_state = STATE_START; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1293 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1294 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1295 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1296 // When there are postponed prefixes we need to use these first. At |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1297 // the end of the prefix we continue in the case-fold tree. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1298 fbyts = slang->sl_fbyts; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1299 fidxs = slang->sl_fidxs; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1300 pbyts = slang->sl_pbyts; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1301 pidxs = slang->sl_pidxs; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1302 if (pbyts != NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1303 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1304 byts = pbyts; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1305 idxs = pidxs; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1306 sp->ts_prefixdepth = PFD_PREFIXTREE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1307 sp->ts_state = STATE_NOPREFIX; // try without prefix first |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1308 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1309 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1310 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1311 byts = fbyts; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1312 idxs = fidxs; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1313 sp->ts_prefixdepth = PFD_NOPREFIX; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1314 sp->ts_state = STATE_START; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1315 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1316 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1318 // Loop to find all suggestions. At each round we either: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1319 // - For the current state try one operation, advance "ts_curi", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1320 // increase "depth". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1321 // - When a state is done go to the next, set "ts_state". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1322 // - When all states are tried decrease "depth". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1323 while (depth >= 0 && !got_int) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1324 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1325 sp = &stack[depth]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 switch (sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1327 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1328 case STATE_START: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 case STATE_NOPREFIX: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1330 // Start of node: Deal with NUL bytes, which means |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1331 // tword[] may end here. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1332 arridx = sp->ts_arridx; // current node in the tree |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1333 len = byts[arridx]; // bytes in this node |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1334 arridx += sp->ts_curi; // index of current byte |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1335 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1336 if (sp->ts_prefixdepth == PFD_PREFIXTREE) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1337 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1338 // Skip over the NUL bytes, we use them later. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1339 for (n = 0; n < len && byts[arridx + n] == 0; ++n) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1340 ; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1341 sp->ts_curi += n; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1342 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1343 // Always past NUL bytes now. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1344 n = (int)sp->ts_state; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1345 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1346 sp->ts_state = STATE_ENDNUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1347 sp->ts_save_badflags = su->su_badflags; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1348 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1349 // At end of a prefix or at start of prefixtree: check for |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1350 // following word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1351 if (byts[arridx] == 0 || n == (int)STATE_NOPREFIX) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1352 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1353 // Set su->su_badflags to the caps type at this position. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1354 // Use the caps type until here for the prefix itself. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1355 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1356 n = nofold_len(fword, sp->ts_fidx, su->su_badptr); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1357 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1358 n = sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1359 flags = badword_captype(su->su_badptr, su->su_badptr + n); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1360 su->su_badflags = badword_captype(su->su_badptr + n, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1361 su->su_badptr + su->su_badlen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1362 #ifdef DEBUG_TRIEWALK |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1363 sprintf(changename[depth], "prefix"); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1364 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1365 go_deeper(stack, depth, 0); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1366 ++depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1367 sp = &stack[depth]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1368 sp->ts_prefixdepth = depth - 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1369 byts = fbyts; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1370 idxs = fidxs; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1371 sp->ts_arridx = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1372 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1373 // Move the prefix to preword[] with the right case |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1374 // and make find_keepcap_word() works. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1375 tword[sp->ts_twordlen] = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1376 make_case_word(tword + sp->ts_splitoff, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1377 preword + sp->ts_prewordlen, flags); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1378 sp->ts_prewordlen = (char_u)STRLEN(preword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 sp->ts_splitoff = sp->ts_twordlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1380 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1381 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1382 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1383 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1384 if (sp->ts_curi > len || byts[arridx] != 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1385 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1386 // Past bytes in node and/or past NUL bytes. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1387 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1388 sp->ts_state = STATE_ENDNUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1389 sp->ts_save_badflags = su->su_badflags; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1390 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1392 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1393 // End of word in tree. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1394 ++sp->ts_curi; // eat one NUL byte |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1395 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1396 flags = (int)idxs[arridx]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1397 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1398 // Skip words with the NOSUGGEST flag. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 if (flags & WF_NOSUGGEST) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1401 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1402 fword_ends = (fword[sp->ts_fidx] == NUL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1403 || (soundfold |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1404 ? VIM_ISWHITE(fword[sp->ts_fidx]) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1405 : !spell_iswordp(fword + sp->ts_fidx, curwin))); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1406 tword[sp->ts_twordlen] = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1407 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1408 if (sp->ts_prefixdepth <= PFD_NOTSPECIAL |
21106
47978b89a02e
patch 8.2.1104: Coverity warnts for possible NULL pointer use
Bram Moolenaar <Bram@vim.org>
parents:
21087
diff
changeset
|
1409 && (sp->ts_flags & TSF_PREFIXOK) == 0 |
47978b89a02e
patch 8.2.1104: Coverity warnts for possible NULL pointer use
Bram Moolenaar <Bram@vim.org>
parents:
21087
diff
changeset
|
1410 && pbyts != NULL) |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1411 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1412 // There was a prefix before the word. Check that the prefix |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 // can be used with this word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1414 // Count the length of the NULs in the prefix. If there are |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 // none this must be the first try without a prefix. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1416 n = stack[sp->ts_prefixdepth].ts_arridx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1417 len = pbyts[n++]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1418 for (c = 0; c < len && pbyts[n + c] == 0; ++c) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1419 ; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1420 if (c > 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1421 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1422 c = valid_word_prefix(c, n, flags, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1423 tword + sp->ts_splitoff, slang, FALSE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1424 if (c == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1425 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1426 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1427 // Use the WF_RARE flag for a rare prefix. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1428 if (c & WF_RAREPFX) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1429 flags |= WF_RARE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1430 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1431 // Tricky: when checking for both prefix and compounding |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1432 // we run into the prefix flag first. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 // Remember that it's OK, so that we accept the prefix |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1434 // when arriving at a compound flag. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1435 sp->ts_flags |= TSF_PREFIXOK; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1436 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1437 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1439 // Check NEEDCOMPOUND: can't use word without compounding. Do try |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1440 // appending another compound word below. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1441 if (sp->ts_complen == sp->ts_compsplit && fword_ends |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1442 && (flags & WF_NEEDCOMP)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1443 goodword_ends = FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1444 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 goodword_ends = TRUE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1446 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1447 p = NULL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1448 compound_ok = TRUE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1449 if (sp->ts_complen > sp->ts_compsplit) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1450 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1451 if (slang->sl_nobreak) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1452 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1453 // There was a word before this word. When there was no |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1454 // change in this word (it was correct) add the first word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1455 // as a suggestion. If this word was corrected too, we |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1456 // need to check if a correct word follows. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1457 if (sp->ts_fidx - sp->ts_splitfidx |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1458 == sp->ts_twordlen - sp->ts_splitoff |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1459 && STRNCMP(fword + sp->ts_splitfidx, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1460 tword + sp->ts_splitoff, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1461 sp->ts_fidx - sp->ts_splitfidx) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1463 preword[sp->ts_prewordlen] = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1464 newscore = score_wordcount_adj(slang, sp->ts_score, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1465 preword + sp->ts_prewordlen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1466 sp->ts_prewordlen > 0); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1467 // Add the suggestion if the score isn't too bad. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1468 if (newscore <= su->su_maxscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1469 add_suggestion(su, &su->su_ga, preword, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1470 sp->ts_splitfidx - repextra, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1471 newscore, 0, FALSE, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1472 lp->lp_sallang, FALSE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1473 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1474 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1475 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1476 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1477 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1478 // There was a compound word before this word. If this |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1479 // word does not support compounding then give up |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1480 // (splitting is tried for the word without compound |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1481 // flag). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1482 if (((unsigned)flags >> 24) == 0 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1483 || sp->ts_twordlen - sp->ts_splitoff |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1484 < slang->sl_compminlen) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1485 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1486 // For multi-byte chars check character length against |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1487 // COMPOUNDMIN. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1488 if (has_mbyte |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1489 && slang->sl_compminlen > 0 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1490 && mb_charlen(tword + sp->ts_splitoff) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1491 < slang->sl_compminlen) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1492 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1493 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1494 compflags[sp->ts_complen] = ((unsigned)flags >> 24); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1495 compflags[sp->ts_complen + 1] = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1496 vim_strncpy(preword + sp->ts_prewordlen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1497 tword + sp->ts_splitoff, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1498 sp->ts_twordlen - sp->ts_splitoff); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1499 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1500 // Verify CHECKCOMPOUNDPATTERN rules. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1501 if (match_checkcompoundpattern(preword, sp->ts_prewordlen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1502 &slang->sl_comppat)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1503 compound_ok = FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1504 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1505 if (compound_ok) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1506 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1507 p = preword; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1508 while (*skiptowhite(p) != NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1509 p = skipwhite(skiptowhite(p)); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1510 if (fword_ends && !can_compound(slang, p, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1511 compflags + sp->ts_compsplit)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1512 // Compound is not allowed. But it may still be |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1513 // possible if we add another (short) word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1514 compound_ok = FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1515 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1516 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1517 // Get pointer to last char of previous word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1518 p = preword + sp->ts_prewordlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1519 MB_PTR_BACK(preword, p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1520 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1521 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1522 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1523 // Form the word with proper case in preword. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1524 // If there is a word from a previous split, append. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1525 // For the soundfold tree don't change the case, simply append. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1526 if (soundfold) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1527 STRCPY(preword + sp->ts_prewordlen, tword + sp->ts_splitoff); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1528 else if (flags & WF_KEEPCAP) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1529 // Must find the word in the keep-case tree. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1530 find_keepcap_word(slang, tword + sp->ts_splitoff, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1531 preword + sp->ts_prewordlen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1532 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1533 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1534 // Include badflags: If the badword is onecap or allcap |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1535 // use that for the goodword too. But if the badword is |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1536 // allcap and it's only one char long use onecap. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1537 c = su->su_badflags; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1538 if ((c & WF_ALLCAP) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1539 && su->su_badlen == (*mb_ptr2len)(su->su_badptr)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1540 c = WF_ONECAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1541 c |= flags; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1542 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1543 // When appending a compound word after a word character don't |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1544 // use Onecap. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1545 if (p != NULL && spell_iswordp_nmw(p, curwin)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1546 c &= ~WF_ONECAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1547 make_case_word(tword + sp->ts_splitoff, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1548 preword + sp->ts_prewordlen, c); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1549 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1550 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1551 if (!soundfold) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1552 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1553 // Don't use a banned word. It may appear again as a good |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1554 // word, thus remember it. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1555 if (flags & WF_BANNED) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1556 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1557 add_banned(su, preword + sp->ts_prewordlen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1558 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1559 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1560 if ((sp->ts_complen == sp->ts_compsplit |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1561 && WAS_BANNED(su, preword + sp->ts_prewordlen)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1562 || WAS_BANNED(su, preword)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1563 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1564 if (slang->sl_compprog == NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1565 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1566 // the word so far was banned but we may try compounding |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1567 goodword_ends = FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1568 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1569 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1570 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1571 newscore = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1572 if (!soundfold) // soundfold words don't have flags |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1573 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1574 if ((flags & WF_REGION) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1575 && (((unsigned)flags >> 16) & lp->lp_region) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1576 newscore += SCORE_REGION; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1577 if (flags & WF_RARE) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1578 newscore += SCORE_RARE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1579 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1580 if (!spell_valid_case(su->su_badflags, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1581 captype(preword + sp->ts_prewordlen, NULL))) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1582 newscore += SCORE_ICASE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1583 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1584 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1585 // TODO: how about splitting in the soundfold tree? |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1586 if (fword_ends |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1587 && goodword_ends |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1588 && sp->ts_fidx >= sp->ts_fidxtry |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1589 && compound_ok) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1590 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1591 // The badword also ends: add suggestions. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1592 #ifdef DEBUG_TRIEWALK |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1593 if (soundfold && STRCMP(preword, "smwrd") == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1594 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1595 int j; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1596 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1597 // print the stack of changes that brought us here |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1598 smsg("------ %s -------", fword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1599 for (j = 0; j < depth; ++j) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1600 smsg("%s", changename[j]); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1601 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1602 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1603 if (soundfold) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1604 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1605 // For soundfolded words we need to find the original |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1606 // words, the edit distance and then add them. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1607 add_sound_suggest(su, preword, sp->ts_score, lp); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1608 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1609 else if (sp->ts_fidx > 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1610 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1611 // Give a penalty when changing non-word char to word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1612 // char, e.g., "thes," -> "these". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1613 p = fword + sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1614 MB_PTR_BACK(fword, p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1615 if (!spell_iswordp(p, curwin)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1616 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1617 p = preword + STRLEN(preword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1618 MB_PTR_BACK(preword, p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1619 if (spell_iswordp(p, curwin)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1620 newscore += SCORE_NONWORD; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1621 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1622 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1623 // Give a bonus to words seen before. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1624 score = score_wordcount_adj(slang, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1625 sp->ts_score + newscore, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1626 preword + sp->ts_prewordlen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1627 sp->ts_prewordlen > 0); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1628 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1629 // Add the suggestion if the score isn't too bad. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1630 if (score <= su->su_maxscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1631 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1632 add_suggestion(su, &su->su_ga, preword, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1633 sp->ts_fidx - repextra, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1634 score, 0, FALSE, lp->lp_sallang, FALSE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1635 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1636 if (su->su_badflags & WF_MIXCAP) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1637 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1638 // We really don't know if the word should be |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1639 // upper or lower case, add both. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1640 c = captype(preword, NULL); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1641 if (c == 0 || c == WF_ALLCAP) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1642 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1643 make_case_word(tword + sp->ts_splitoff, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1644 preword + sp->ts_prewordlen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1645 c == 0 ? WF_ALLCAP : 0); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1646 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1647 add_suggestion(su, &su->su_ga, preword, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1648 sp->ts_fidx - repextra, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1649 score + SCORE_ICASE, 0, FALSE, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1650 lp->lp_sallang, FALSE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1651 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1652 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1653 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1654 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1655 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1656 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1657 // Try word split and/or compounding. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1658 if ((sp->ts_fidx >= sp->ts_fidxtry || fword_ends) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1659 // Don't split halfway a character. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1660 && (!has_mbyte || sp->ts_tcharlen == 0)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1661 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1662 int try_compound; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1663 int try_split; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1664 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1665 // If past the end of the bad word don't try a split. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1666 // Otherwise try changing the next word. E.g., find |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1667 // suggestions for "the the" where the second "the" is |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1668 // different. It's done like a split. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1669 // TODO: word split for soundfold words |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1670 try_split = (sp->ts_fidx - repextra < su->su_badlen) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1671 && !soundfold; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1672 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1673 // Get here in several situations: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1674 // 1. The word in the tree ends: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1675 // If the word allows compounding try that. Otherwise try |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1676 // a split by inserting a space. For both check that a |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1677 // valid words starts at fword[sp->ts_fidx]. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1678 // For NOBREAK do like compounding to be able to check if |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1679 // the next word is valid. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1680 // 2. The badword does end, but it was due to a change (e.g., |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1681 // a swap). No need to split, but do check that the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1682 // following word is valid. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1683 // 3. The badword and the word in the tree end. It may still |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1684 // be possible to compound another (short) word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1685 try_compound = FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1686 if (!soundfold |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1687 && !slang->sl_nocompoundsugs |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1688 && slang->sl_compprog != NULL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1689 && ((unsigned)flags >> 24) != 0 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1690 && sp->ts_twordlen - sp->ts_splitoff |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1691 >= slang->sl_compminlen |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1692 && (!has_mbyte |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1693 || slang->sl_compminlen == 0 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1694 || mb_charlen(tword + sp->ts_splitoff) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1695 >= slang->sl_compminlen) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1696 && (slang->sl_compsylmax < MAXWLEN |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1697 || sp->ts_complen + 1 - sp->ts_compsplit |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1698 < slang->sl_compmax) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1699 && (can_be_compound(sp, slang, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1700 compflags, ((unsigned)flags >> 24)))) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1701 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1702 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1703 try_compound = TRUE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1704 compflags[sp->ts_complen] = ((unsigned)flags >> 24); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1705 compflags[sp->ts_complen + 1] = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1706 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1707 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1708 // For NOBREAK we never try splitting, it won't make any word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1709 // valid. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1710 if (slang->sl_nobreak && !slang->sl_nocompoundsugs) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1711 try_compound = TRUE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1712 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1713 // If we could add a compound word, and it's also possible to |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1714 // split at this point, do the split first and set |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1715 // TSF_DIDSPLIT to avoid doing it again. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1716 else if (!fword_ends |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1717 && try_compound |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1718 && (sp->ts_flags & TSF_DIDSPLIT) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1719 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1720 try_compound = FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1721 sp->ts_flags |= TSF_DIDSPLIT; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1722 --sp->ts_curi; // do the same NUL again |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1723 compflags[sp->ts_complen] = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1724 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1725 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1726 sp->ts_flags &= ~TSF_DIDSPLIT; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1727 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1728 if (try_split || try_compound) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1729 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1730 if (!try_compound && (!fword_ends || !goodword_ends)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1731 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1732 // If we're going to split need to check that the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1733 // words so far are valid for compounding. If there |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1734 // is only one word it must not have the NEEDCOMPOUND |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1735 // flag. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1736 if (sp->ts_complen == sp->ts_compsplit |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1737 && (flags & WF_NEEDCOMP)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1738 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1739 p = preword; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1740 while (*skiptowhite(p) != NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1741 p = skipwhite(skiptowhite(p)); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1742 if (sp->ts_complen > sp->ts_compsplit |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1743 && !can_compound(slang, p, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1744 compflags + sp->ts_compsplit)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1745 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1746 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1747 if (slang->sl_nosplitsugs) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1748 newscore += SCORE_SPLIT_NO; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1749 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1750 newscore += SCORE_SPLIT; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1751 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1752 // Give a bonus to words seen before. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1753 newscore = score_wordcount_adj(slang, newscore, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1754 preword + sp->ts_prewordlen, TRUE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1755 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1756 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1757 if (TRY_DEEPER(su, stack, depth, newscore)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1758 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1759 go_deeper(stack, depth, newscore); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1760 #ifdef DEBUG_TRIEWALK |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1761 if (!try_compound && !fword_ends) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1762 sprintf(changename[depth], "%.*s-%s: split", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1763 sp->ts_twordlen, tword, fword + sp->ts_fidx); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1764 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1765 sprintf(changename[depth], "%.*s-%s: compound", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1766 sp->ts_twordlen, tword, fword + sp->ts_fidx); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1767 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1768 // Save things to be restored at STATE_SPLITUNDO. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1769 sp->ts_save_badflags = su->su_badflags; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1770 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1771 sp->ts_state = STATE_SPLITUNDO; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1772 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1773 ++depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1774 sp = &stack[depth]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1775 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1776 // Append a space to preword when splitting. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1777 if (!try_compound && !fword_ends) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1778 STRCAT(preword, " "); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1779 sp->ts_prewordlen = (char_u)STRLEN(preword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1780 sp->ts_splitoff = sp->ts_twordlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1781 sp->ts_splitfidx = sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1782 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1783 // If the badword has a non-word character at this |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1784 // position skip it. That means replacing the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1785 // non-word character with a space. Always skip a |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1786 // character when the word ends. But only when the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1787 // good word can end. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1788 if (((!try_compound && !spell_iswordp_nmw(fword |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1789 + sp->ts_fidx, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1790 curwin)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1791 || fword_ends) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1792 && fword[sp->ts_fidx] != NUL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1793 && goodword_ends) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1794 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1795 int l; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1796 |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
1797 l = mb_ptr2len(fword + sp->ts_fidx); |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1798 if (fword_ends) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1799 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1800 // Copy the skipped character to preword. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1801 mch_memmove(preword + sp->ts_prewordlen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1802 fword + sp->ts_fidx, l); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1803 sp->ts_prewordlen += l; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1804 preword[sp->ts_prewordlen] = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1805 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1806 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1807 sp->ts_score -= SCORE_SPLIT - SCORE_SUBST; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1808 sp->ts_fidx += l; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1809 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1810 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1811 // When compounding include compound flag in |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1812 // compflags[] (already set above). When splitting we |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1813 // may start compounding over again. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1814 if (try_compound) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1815 ++sp->ts_complen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1816 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1817 sp->ts_compsplit = sp->ts_complen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1818 sp->ts_prefixdepth = PFD_NOPREFIX; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1819 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1820 // set su->su_badflags to the caps type at this |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1821 // position |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1822 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1823 n = nofold_len(fword, sp->ts_fidx, su->su_badptr); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1824 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1825 n = sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1826 su->su_badflags = badword_captype(su->su_badptr + n, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1827 su->su_badptr + su->su_badlen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1828 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1829 // Restart at top of the tree. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1830 sp->ts_arridx = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1831 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1832 // If there are postponed prefixes, try these too. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1833 if (pbyts != NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1834 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1835 byts = pbyts; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1836 idxs = pidxs; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1837 sp->ts_prefixdepth = PFD_PREFIXTREE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1838 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1839 sp->ts_state = STATE_NOPREFIX; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1840 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1841 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1842 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1843 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1844 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1845 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1846 case STATE_SPLITUNDO: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1847 // Undo the changes done for word split or compound word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1848 su->su_badflags = sp->ts_save_badflags; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1849 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1850 // Continue looking for NUL bytes. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1851 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1852 sp->ts_state = STATE_START; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1853 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1854 // In case we went into the prefix tree. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1855 byts = fbyts; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1856 idxs = fidxs; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1857 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1858 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1859 case STATE_ENDNUL: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1860 // Past the NUL bytes in the node. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1861 su->su_badflags = sp->ts_save_badflags; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1862 if (fword[sp->ts_fidx] == NUL && sp->ts_tcharlen == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1863 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1864 // The badword ends, can't use STATE_PLAIN. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1865 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1866 sp->ts_state = STATE_DEL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1867 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1868 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1869 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1870 sp->ts_state = STATE_PLAIN; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1871 // FALLTHROUGH |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1872 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1873 case STATE_PLAIN: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1874 // Go over all possible bytes at this node, add each to tword[] |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1875 // and use child node. "ts_curi" is the index. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1876 arridx = sp->ts_arridx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1877 if (sp->ts_curi > byts[arridx]) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1878 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1879 // Done all bytes at this node, do next state. When still at |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1880 // already changed bytes skip the other tricks. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1881 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1882 if (sp->ts_fidx >= sp->ts_fidxtry) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1883 sp->ts_state = STATE_DEL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1884 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1885 sp->ts_state = STATE_FINAL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1886 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1887 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1888 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1889 arridx += sp->ts_curi++; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1890 c = byts[arridx]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1891 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1892 // Normal byte, go one level deeper. If it's not equal to the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1893 // byte in the bad word adjust the score. But don't even try |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1894 // when the byte was already changed. And don't try when we |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1895 // just deleted this byte, accepting it is always cheaper than |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1896 // delete + substitute. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1897 if (c == fword[sp->ts_fidx] |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1898 || (sp->ts_tcharlen > 0 && sp->ts_isdiff != DIFF_NONE)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1899 newscore = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1900 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1901 newscore = SCORE_SUBST; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1902 if ((newscore == 0 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1903 || (sp->ts_fidx >= sp->ts_fidxtry |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1904 && ((sp->ts_flags & TSF_DIDDEL) == 0 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1905 || c != fword[sp->ts_delidx]))) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1906 && TRY_DEEPER(su, stack, depth, newscore)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1907 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1908 go_deeper(stack, depth, newscore); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1909 #ifdef DEBUG_TRIEWALK |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1910 if (newscore > 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1911 sprintf(changename[depth], "%.*s-%s: subst %c to %c", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1912 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1913 fword[sp->ts_fidx], c); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1914 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1915 sprintf(changename[depth], "%.*s-%s: accept %c", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1916 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1917 fword[sp->ts_fidx]); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1918 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1919 ++depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1920 sp = &stack[depth]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1921 ++sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1922 tword[sp->ts_twordlen++] = c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1923 sp->ts_arridx = idxs[arridx]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1924 if (newscore == SCORE_SUBST) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1925 sp->ts_isdiff = DIFF_YES; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1926 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1927 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1928 // Multi-byte characters are a bit complicated to |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1929 // handle: They differ when any of the bytes differ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1930 // and then their length may also differ. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1931 if (sp->ts_tcharlen == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1932 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1933 // First byte. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1934 sp->ts_tcharidx = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1935 sp->ts_tcharlen = MB_BYTE2LEN(c); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1936 sp->ts_fcharstart = sp->ts_fidx - 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1937 sp->ts_isdiff = (newscore != 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1938 ? DIFF_YES : DIFF_NONE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1939 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1940 else if (sp->ts_isdiff == DIFF_INSERT) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1941 // When inserting trail bytes don't advance in the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1942 // bad word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1943 --sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1944 if (++sp->ts_tcharidx == sp->ts_tcharlen) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1945 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1946 // Last byte of character. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1947 if (sp->ts_isdiff == DIFF_YES) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1948 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1949 // Correct ts_fidx for the byte length of the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1950 // character (we didn't check that before). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1951 sp->ts_fidx = sp->ts_fcharstart |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
1952 + mb_ptr2len( |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1953 fword + sp->ts_fcharstart); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1954 // For changing a composing character adjust |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1955 // the score from SCORE_SUBST to |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1956 // SCORE_SUBCOMP. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1957 if (enc_utf8 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1958 && utf_iscomposing( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1959 utf_ptr2char(tword |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1960 + sp->ts_twordlen |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1961 - sp->ts_tcharlen)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1962 && utf_iscomposing( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1963 utf_ptr2char(fword |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1964 + sp->ts_fcharstart))) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1965 sp->ts_score -= |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1966 SCORE_SUBST - SCORE_SUBCOMP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1967 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1968 // For a similar character adjust score from |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1969 // SCORE_SUBST to SCORE_SIMILAR. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1970 else if (!soundfold |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1971 && slang->sl_has_map |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1972 && similar_chars(slang, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1973 mb_ptr2char(tword |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1974 + sp->ts_twordlen |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1975 - sp->ts_tcharlen), |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1976 mb_ptr2char(fword |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1977 + sp->ts_fcharstart))) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1978 sp->ts_score -= |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1979 SCORE_SUBST - SCORE_SIMILAR; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1980 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1981 else if (sp->ts_isdiff == DIFF_INSERT |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1982 && sp->ts_twordlen > sp->ts_tcharlen) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1983 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1984 p = tword + sp->ts_twordlen - sp->ts_tcharlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1985 c = mb_ptr2char(p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1986 if (enc_utf8 && utf_iscomposing(c)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1987 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1988 // Inserting a composing char doesn't |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1989 // count that much. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1990 sp->ts_score -= SCORE_INS - SCORE_INSCOMP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1991 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1992 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1993 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1994 // If the previous character was the same, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1995 // thus doubling a character, give a bonus |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1996 // to the score. Also for the soundfold |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1997 // tree (might seem illogical but does |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1998 // give better scores). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1999 MB_PTR_BACK(tword, p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2000 if (c == mb_ptr2char(p)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2001 sp->ts_score -= SCORE_INS |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2002 - SCORE_INSDUP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2003 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2004 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2005 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2006 // Starting a new char, reset the length. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2007 sp->ts_tcharlen = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2008 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2009 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2010 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2011 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2012 // If we found a similar char adjust the score. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2013 // We do this after calling go_deeper() because |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2014 // it's slow. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2015 if (newscore != 0 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2016 && !soundfold |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2017 && slang->sl_has_map |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2018 && similar_chars(slang, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2019 c, fword[sp->ts_fidx - 1])) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2020 sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2021 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2022 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2023 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2024 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2025 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2026 case STATE_DEL: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2027 // When past the first byte of a multi-byte char don't try |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2028 // delete/insert/swap a character. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2029 if (has_mbyte && sp->ts_tcharlen > 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2030 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2031 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2032 sp->ts_state = STATE_FINAL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2033 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2034 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2035 // Try skipping one character in the bad word (delete it). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2036 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2037 sp->ts_state = STATE_INS_PREP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2038 sp->ts_curi = 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2039 if (soundfold && sp->ts_fidx == 0 && fword[sp->ts_fidx] == '*') |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2040 // Deleting a vowel at the start of a word counts less, see |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2041 // soundalike_score(). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2042 newscore = 2 * SCORE_DEL / 3; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2043 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2044 newscore = SCORE_DEL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2045 if (fword[sp->ts_fidx] != NUL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2046 && TRY_DEEPER(su, stack, depth, newscore)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2047 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2048 go_deeper(stack, depth, newscore); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2049 #ifdef DEBUG_TRIEWALK |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2050 sprintf(changename[depth], "%.*s-%s: delete %c", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2051 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2052 fword[sp->ts_fidx]); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2053 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2054 ++depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2055 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2056 // Remember what character we deleted, so that we can avoid |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2057 // inserting it again. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2058 stack[depth].ts_flags |= TSF_DIDDEL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2059 stack[depth].ts_delidx = sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2060 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2061 // Advance over the character in fword[]. Give a bonus to the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2062 // score if the same character is following "nn" -> "n". It's |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2063 // a bit illogical for soundfold tree but it does give better |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2064 // results. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2065 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2066 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2067 c = mb_ptr2char(fword + sp->ts_fidx); |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
2068 stack[depth].ts_fidx += mb_ptr2len(fword + sp->ts_fidx); |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2069 if (enc_utf8 && utf_iscomposing(c)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2070 stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2071 else if (c == mb_ptr2char(fword + stack[depth].ts_fidx)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2072 stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2073 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2074 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2075 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2076 ++stack[depth].ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2077 if (fword[sp->ts_fidx] == fword[sp->ts_fidx + 1]) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2078 stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2079 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2080 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2081 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2082 // FALLTHROUGH |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2083 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2084 case STATE_INS_PREP: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2085 if (sp->ts_flags & TSF_DIDDEL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2086 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2087 // If we just deleted a byte then inserting won't make sense, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2088 // a substitute is always cheaper. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2089 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2090 sp->ts_state = STATE_SWAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2091 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2092 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2093 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2094 // skip over NUL bytes |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2095 n = sp->ts_arridx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2096 for (;;) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2097 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2098 if (sp->ts_curi > byts[n]) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2099 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2100 // Only NUL bytes at this node, go to next state. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2101 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2102 sp->ts_state = STATE_SWAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2103 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2104 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2105 if (byts[n + sp->ts_curi] != NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2106 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2107 // Found a byte to insert. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2108 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2109 sp->ts_state = STATE_INS; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2110 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2111 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2112 ++sp->ts_curi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2113 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2114 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2115 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2116 // FALLTHROUGH |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2117 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2118 case STATE_INS: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2119 // Insert one byte. Repeat this for each possible byte at this |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2120 // node. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2121 n = sp->ts_arridx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2122 if (sp->ts_curi > byts[n]) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2123 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2124 // Done all bytes at this node, go to next state. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2125 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2126 sp->ts_state = STATE_SWAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2127 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2128 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2129 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2130 // Do one more byte at this node, but: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2131 // - Skip NUL bytes. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2132 // - Skip the byte if it's equal to the byte in the word, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2133 // accepting that byte is always better. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2134 n += sp->ts_curi++; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2135 c = byts[n]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2136 if (soundfold && sp->ts_twordlen == 0 && c == '*') |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2137 // Inserting a vowel at the start of a word counts less, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2138 // see soundalike_score(). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2139 newscore = 2 * SCORE_INS / 3; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2140 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2141 newscore = SCORE_INS; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2142 if (c != fword[sp->ts_fidx] |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2143 && TRY_DEEPER(su, stack, depth, newscore)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2144 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2145 go_deeper(stack, depth, newscore); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2146 #ifdef DEBUG_TRIEWALK |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2147 sprintf(changename[depth], "%.*s-%s: insert %c", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2148 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2149 c); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2150 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2151 ++depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2152 sp = &stack[depth]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2153 tword[sp->ts_twordlen++] = c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2154 sp->ts_arridx = idxs[n]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2155 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2156 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2157 fl = MB_BYTE2LEN(c); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2158 if (fl > 1) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2159 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2160 // There are following bytes for the same character. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2161 // We must find all bytes before trying |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2162 // delete/insert/swap/etc. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2163 sp->ts_tcharlen = fl; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2164 sp->ts_tcharidx = 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2165 sp->ts_isdiff = DIFF_INSERT; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2166 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2167 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2168 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2169 fl = 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2170 if (fl == 1) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2171 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2172 // If the previous character was the same, thus doubling a |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2173 // character, give a bonus to the score. Also for |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2174 // soundfold words (illogical but does give a better |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2175 // score). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2176 if (sp->ts_twordlen >= 2 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2177 && tword[sp->ts_twordlen - 2] == c) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2178 sp->ts_score -= SCORE_INS - SCORE_INSDUP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2179 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2180 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2181 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2182 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2183 case STATE_SWAP: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2184 // Swap two bytes in the bad word: "12" -> "21". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2185 // We change "fword" here, it's changed back afterwards at |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2186 // STATE_UNSWAP. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2187 p = fword + sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2188 c = *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2189 if (c == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2190 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2191 // End of word, can't swap or replace. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2192 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2193 sp->ts_state = STATE_FINAL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2194 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2195 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2196 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2197 // Don't swap if the first character is not a word character. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2198 // SWAP3 etc. also don't make sense then. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2199 if (!soundfold && !spell_iswordp(p, curwin)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2200 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2201 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2202 sp->ts_state = STATE_REP_INI; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2203 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2204 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2205 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2206 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2207 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2208 n = MB_CPTR2LEN(p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2209 c = mb_ptr2char(p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2210 if (p[n] == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2211 c2 = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2212 else if (!soundfold && !spell_iswordp(p + n, curwin)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2213 c2 = c; // don't swap non-word char |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2214 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2215 c2 = mb_ptr2char(p + n); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2216 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2217 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2218 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2219 if (p[1] == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2220 c2 = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2221 else if (!soundfold && !spell_iswordp(p + 1, curwin)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2222 c2 = c; // don't swap non-word char |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2223 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2224 c2 = p[1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2225 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2226 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2227 // When the second character is NUL we can't swap. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2228 if (c2 == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2229 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2230 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2231 sp->ts_state = STATE_REP_INI; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2232 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2233 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2234 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2235 // When characters are identical, swap won't do anything. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2236 // Also get here if the second char is not a word character. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2237 if (c == c2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2238 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2239 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2240 sp->ts_state = STATE_SWAP3; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2241 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2242 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2243 if (c2 != NUL && TRY_DEEPER(su, stack, depth, SCORE_SWAP)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2244 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2245 go_deeper(stack, depth, SCORE_SWAP); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2246 #ifdef DEBUG_TRIEWALK |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2247 sprintf(changename[depth], "%.*s-%s: swap %c and %c", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2248 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2249 c, c2); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2250 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2251 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2252 sp->ts_state = STATE_UNSWAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2253 ++depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2254 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2255 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2256 fl = mb_char2len(c2); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2257 mch_memmove(p, p + n, fl); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2258 mb_char2bytes(c, p + fl); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2259 stack[depth].ts_fidxtry = sp->ts_fidx + n + fl; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2260 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2261 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2262 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2263 p[0] = c2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2264 p[1] = c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2265 stack[depth].ts_fidxtry = sp->ts_fidx + 2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2266 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2267 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2268 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2269 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2270 // If this swap doesn't work then SWAP3 won't either. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2271 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2272 sp->ts_state = STATE_REP_INI; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2273 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2274 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2275 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2276 case STATE_UNSWAP: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2277 // Undo the STATE_SWAP swap: "21" -> "12". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2278 p = fword + sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2279 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2280 { |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
2281 n = mb_ptr2len(p); |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2282 c = mb_ptr2char(p + n); |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
2283 mch_memmove(p + mb_ptr2len(p + n), p, n); |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2284 mb_char2bytes(c, p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2285 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2286 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2287 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2288 c = *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2289 *p = p[1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2290 p[1] = c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2291 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2292 // FALLTHROUGH |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2293 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2294 case STATE_SWAP3: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2295 // Swap two bytes, skipping one: "123" -> "321". We change |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2296 // "fword" here, it's changed back afterwards at STATE_UNSWAP3. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2297 p = fword + sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2298 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2299 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2300 n = MB_CPTR2LEN(p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2301 c = mb_ptr2char(p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2302 fl = MB_CPTR2LEN(p + n); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2303 c2 = mb_ptr2char(p + n); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2304 if (!soundfold && !spell_iswordp(p + n + fl, curwin)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2305 c3 = c; // don't swap non-word char |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2306 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2307 c3 = mb_ptr2char(p + n + fl); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2308 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2309 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2310 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2311 c = *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2312 c2 = p[1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2313 if (!soundfold && !spell_iswordp(p + 2, curwin)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2314 c3 = c; // don't swap non-word char |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2315 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2316 c3 = p[2]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2317 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2318 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2319 // When characters are identical: "121" then SWAP3 result is |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2320 // identical, ROT3L result is same as SWAP: "211", ROT3L result is |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2321 // same as SWAP on next char: "112". Thus skip all swapping. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2322 // Also skip when c3 is NUL. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2323 // Also get here when the third character is not a word character. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2324 // Second character may any char: "a.b" -> "b.a" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2325 if (c == c3 || c3 == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2326 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2327 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2328 sp->ts_state = STATE_REP_INI; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2329 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2330 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2331 if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2332 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2333 go_deeper(stack, depth, SCORE_SWAP3); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2334 #ifdef DEBUG_TRIEWALK |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2335 sprintf(changename[depth], "%.*s-%s: swap3 %c and %c", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2336 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2337 c, c3); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2338 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2339 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2340 sp->ts_state = STATE_UNSWAP3; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2341 ++depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2342 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2343 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2344 tl = mb_char2len(c3); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2345 mch_memmove(p, p + n + fl, tl); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2346 mb_char2bytes(c2, p + tl); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2347 mb_char2bytes(c, p + fl + tl); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2348 stack[depth].ts_fidxtry = sp->ts_fidx + n + fl + tl; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2349 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2350 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2351 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2352 p[0] = p[2]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2353 p[2] = c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2354 stack[depth].ts_fidxtry = sp->ts_fidx + 3; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2355 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2356 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2357 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2358 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2359 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2360 sp->ts_state = STATE_REP_INI; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2361 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2362 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2363 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2364 case STATE_UNSWAP3: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2365 // Undo STATE_SWAP3: "321" -> "123" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2366 p = fword + sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2367 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2368 { |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
2369 n = mb_ptr2len(p); |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2370 c2 = mb_ptr2char(p + n); |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
2371 fl = mb_ptr2len(p + n); |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2372 c = mb_ptr2char(p + n + fl); |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
2373 tl = mb_ptr2len(p + n + fl); |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2374 mch_memmove(p + fl + tl, p, n); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2375 mb_char2bytes(c, p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2376 mb_char2bytes(c2, p + tl); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2377 p = p + tl; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2378 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2379 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2380 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2381 c = *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2382 *p = p[2]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2383 p[2] = c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2384 ++p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2385 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2386 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2387 if (!soundfold && !spell_iswordp(p, curwin)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2388 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2389 // Middle char is not a word char, skip the rotate. First and |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2390 // third char were already checked at swap and swap3. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2391 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2392 sp->ts_state = STATE_REP_INI; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2393 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2394 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2395 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2396 // Rotate three characters left: "123" -> "231". We change |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2397 // "fword" here, it's changed back afterwards at STATE_UNROT3L. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2398 if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2399 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2400 go_deeper(stack, depth, SCORE_SWAP3); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2401 #ifdef DEBUG_TRIEWALK |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2402 p = fword + sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2403 sprintf(changename[depth], "%.*s-%s: rotate left %c%c%c", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2404 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2405 p[0], p[1], p[2]); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2406 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2407 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2408 sp->ts_state = STATE_UNROT3L; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2409 ++depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2410 p = fword + sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2411 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2412 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2413 n = MB_CPTR2LEN(p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2414 c = mb_ptr2char(p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2415 fl = MB_CPTR2LEN(p + n); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2416 fl += MB_CPTR2LEN(p + n + fl); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2417 mch_memmove(p, p + n, fl); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2418 mb_char2bytes(c, p + fl); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2419 stack[depth].ts_fidxtry = sp->ts_fidx + n + fl; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2420 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2421 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2422 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2423 c = *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2424 *p = p[1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2425 p[1] = p[2]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2426 p[2] = c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2427 stack[depth].ts_fidxtry = sp->ts_fidx + 3; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2428 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2429 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2430 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2431 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2432 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2433 sp->ts_state = STATE_REP_INI; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2434 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2435 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2436 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2437 case STATE_UNROT3L: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2438 // Undo ROT3L: "231" -> "123" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2439 p = fword + sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2440 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2441 { |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
2442 n = mb_ptr2len(p); |
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
2443 n += mb_ptr2len(p + n); |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2444 c = mb_ptr2char(p + n); |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
2445 tl = mb_ptr2len(p + n); |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2446 mch_memmove(p + tl, p, n); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2447 mb_char2bytes(c, p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2448 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2449 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2450 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2451 c = p[2]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2452 p[2] = p[1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2453 p[1] = *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2454 *p = c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2455 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2456 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2457 // Rotate three bytes right: "123" -> "312". We change "fword" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2458 // here, it's changed back afterwards at STATE_UNROT3R. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2459 if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2460 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2461 go_deeper(stack, depth, SCORE_SWAP3); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2462 #ifdef DEBUG_TRIEWALK |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2463 p = fword + sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2464 sprintf(changename[depth], "%.*s-%s: rotate right %c%c%c", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2465 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2466 p[0], p[1], p[2]); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2467 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2468 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2469 sp->ts_state = STATE_UNROT3R; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2470 ++depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2471 p = fword + sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2472 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2473 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2474 n = MB_CPTR2LEN(p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2475 n += MB_CPTR2LEN(p + n); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2476 c = mb_ptr2char(p + n); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2477 tl = MB_CPTR2LEN(p + n); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2478 mch_memmove(p + tl, p, n); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2479 mb_char2bytes(c, p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2480 stack[depth].ts_fidxtry = sp->ts_fidx + n + tl; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2481 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2482 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2483 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2484 c = p[2]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2485 p[2] = p[1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2486 p[1] = *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2487 *p = c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2488 stack[depth].ts_fidxtry = sp->ts_fidx + 3; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2489 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2490 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2491 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2492 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2493 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2494 sp->ts_state = STATE_REP_INI; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2495 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2496 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2497 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2498 case STATE_UNROT3R: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2499 // Undo ROT3R: "312" -> "123" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2500 p = fword + sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2501 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2502 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2503 c = mb_ptr2char(p); |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
2504 tl = mb_ptr2len(p); |
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
2505 n = mb_ptr2len(p + tl); |
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
2506 n += mb_ptr2len(p + tl + n); |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2507 mch_memmove(p, p + tl, n); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2508 mb_char2bytes(c, p + n); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2509 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2510 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2511 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2512 c = *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2513 *p = p[1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2514 p[1] = p[2]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2515 p[2] = c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2516 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2517 // FALLTHROUGH |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2518 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2519 case STATE_REP_INI: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2520 // Check if matching with REP items from the .aff file would work. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2521 // Quickly skip if: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2522 // - there are no REP items and we are not in the soundfold trie |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2523 // - the score is going to be too high anyway |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2524 // - already applied a REP item or swapped here |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2525 if ((lp->lp_replang == NULL && !soundfold) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2526 || sp->ts_score + SCORE_REP >= su->su_maxscore |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2527 || sp->ts_fidx < sp->ts_fidxtry) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2528 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2529 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2530 sp->ts_state = STATE_FINAL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2531 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2532 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2533 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2534 // Use the first byte to quickly find the first entry that may |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2535 // match. If the index is -1 there is none. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2536 if (soundfold) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2537 sp->ts_curi = slang->sl_repsal_first[fword[sp->ts_fidx]]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2538 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2539 sp->ts_curi = lp->lp_replang->sl_rep_first[fword[sp->ts_fidx]]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2540 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2541 if (sp->ts_curi < 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2542 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2543 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2544 sp->ts_state = STATE_FINAL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2545 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2546 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2547 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2548 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2549 sp->ts_state = STATE_REP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2550 // FALLTHROUGH |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2551 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2552 case STATE_REP: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2553 // Try matching with REP items from the .aff file. For each match |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2554 // replace the characters and check if the resulting word is |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2555 // valid. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2556 p = fword + sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2557 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2558 if (soundfold) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2559 gap = &slang->sl_repsal; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2560 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2561 gap = &lp->lp_replang->sl_rep; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2562 while (sp->ts_curi < gap->ga_len) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2563 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2564 ftp = (fromto_T *)gap->ga_data + sp->ts_curi++; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2565 if (*ftp->ft_from != *p) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2566 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2567 // past possible matching entries |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2568 sp->ts_curi = gap->ga_len; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2569 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2570 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2571 if (STRNCMP(ftp->ft_from, p, STRLEN(ftp->ft_from)) == 0 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2572 && TRY_DEEPER(su, stack, depth, SCORE_REP)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2573 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2574 go_deeper(stack, depth, SCORE_REP); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2575 #ifdef DEBUG_TRIEWALK |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2576 sprintf(changename[depth], "%.*s-%s: replace %s with %s", |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2577 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2578 ftp->ft_from, ftp->ft_to); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2579 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2580 // Need to undo this afterwards. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2581 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2582 sp->ts_state = STATE_REP_UNDO; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2583 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2584 // Change the "from" to the "to" string. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2585 ++depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2586 fl = (int)STRLEN(ftp->ft_from); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2587 tl = (int)STRLEN(ftp->ft_to); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2588 if (fl != tl) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2589 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2590 STRMOVE(p + tl, p + fl); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2591 repextra += tl - fl; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2592 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2593 mch_memmove(p, ftp->ft_to, tl); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2594 stack[depth].ts_fidxtry = sp->ts_fidx + tl; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2595 stack[depth].ts_tcharlen = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2596 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2597 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2598 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2599 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2600 if (sp->ts_curi >= gap->ga_len && sp->ts_state == STATE_REP) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2601 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2602 // No (more) matches. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2603 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2604 sp->ts_state = STATE_FINAL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2605 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2606 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2607 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2608 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2609 case STATE_REP_UNDO: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2610 // Undo a REP replacement and continue with the next one. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2611 if (soundfold) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2612 gap = &slang->sl_repsal; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2613 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2614 gap = &lp->lp_replang->sl_rep; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2615 ftp = (fromto_T *)gap->ga_data + sp->ts_curi - 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2616 fl = (int)STRLEN(ftp->ft_from); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2617 tl = (int)STRLEN(ftp->ft_to); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2618 p = fword + sp->ts_fidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2619 if (fl != tl) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2620 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2621 STRMOVE(p + fl, p + tl); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2622 repextra -= tl - fl; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2623 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2624 mch_memmove(p, ftp->ft_from, fl); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2625 PROF_STORE(sp->ts_state) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2626 sp->ts_state = STATE_REP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2627 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2628 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2629 default: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2630 // Did all possible states at this level, go up one level. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2631 --depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2632 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2633 if (depth >= 0 && stack[depth].ts_prefixdepth == PFD_PREFIXTREE) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2634 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2635 // Continue in or go back to the prefix tree. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2636 byts = pbyts; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2637 idxs = pidxs; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2638 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2639 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2640 // Don't check for CTRL-C too often, it takes time. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2641 if (--breakcheckcount == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2642 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2643 ui_breakcheck(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2644 breakcheckcount = 1000; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2645 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2646 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2647 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2648 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2649 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2650 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2651 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2652 * Go one level deeper in the tree. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2653 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2654 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2655 go_deeper(trystate_T *stack, int depth, int score_add) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2656 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2657 stack[depth + 1] = stack[depth]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2658 stack[depth + 1].ts_state = STATE_START; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2659 stack[depth + 1].ts_score = stack[depth].ts_score + score_add; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2660 stack[depth + 1].ts_curi = 1; // start just after length byte |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2661 stack[depth + 1].ts_flags = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2662 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2663 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2664 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2665 * "fword" is a good word with case folded. Find the matching keep-case |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2666 * words and put it in "kword". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2667 * Theoretically there could be several keep-case words that result in the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2668 * same case-folded word, but we only find one... |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2669 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2670 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2671 find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2672 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2673 char_u uword[MAXWLEN]; // "fword" in upper-case |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2674 int depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2675 idx_T tryidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2676 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2677 // The following arrays are used at each depth in the tree. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2678 idx_T arridx[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2679 int round[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2680 int fwordidx[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2681 int uwordidx[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2682 int kwordlen[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2683 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2684 int flen, ulen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2685 int l; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2686 int len; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2687 int c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2688 idx_T lo, hi, m; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2689 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2690 char_u *byts = slang->sl_kbyts; // array with bytes of the words |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2691 idx_T *idxs = slang->sl_kidxs; // array with indexes |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2692 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2693 if (byts == NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2694 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2695 // array is empty: "cannot happen" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2696 *kword = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2697 return; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2698 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2699 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2700 // Make an all-cap version of "fword". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2701 allcap_copy(fword, uword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2702 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2703 // Each character needs to be tried both case-folded and upper-case. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2704 // All this gets very complicated if we keep in mind that changing case |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2705 // may change the byte length of a multi-byte character... |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2706 depth = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2707 arridx[0] = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2708 round[0] = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2709 fwordidx[0] = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2710 uwordidx[0] = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2711 kwordlen[0] = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2712 while (depth >= 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2713 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2714 if (fword[fwordidx[depth]] == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2715 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2716 // We are at the end of "fword". If the tree allows a word to end |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2717 // here we have found a match. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2718 if (byts[arridx[depth] + 1] == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2719 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2720 kword[kwordlen[depth]] = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2721 return; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2722 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2723 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2724 // kword is getting too long, continue one level up |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2725 --depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2726 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2727 else if (++round[depth] > 2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2728 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2729 // tried both fold-case and upper-case character, continue one |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2730 // level up |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2731 --depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2732 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2733 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2734 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2735 // round[depth] == 1: Try using the folded-case character. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2736 // round[depth] == 2: Try using the upper-case character. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2737 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2738 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2739 flen = MB_CPTR2LEN(fword + fwordidx[depth]); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2740 ulen = MB_CPTR2LEN(uword + uwordidx[depth]); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2741 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2742 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2743 ulen = flen = 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2744 if (round[depth] == 1) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2745 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2746 p = fword + fwordidx[depth]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2747 l = flen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2748 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2749 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2750 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2751 p = uword + uwordidx[depth]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2752 l = ulen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2753 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2754 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2755 for (tryidx = arridx[depth]; l > 0; --l) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2756 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2757 // Perform a binary search in the list of accepted bytes. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2758 len = byts[tryidx++]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2759 c = *p++; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2760 lo = tryidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2761 hi = tryidx + len - 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2762 while (lo < hi) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2763 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2764 m = (lo + hi) / 2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2765 if (byts[m] > c) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2766 hi = m - 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2767 else if (byts[m] < c) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2768 lo = m + 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2769 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2770 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2771 lo = hi = m; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2772 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2773 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2774 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2775 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2776 // Stop if there is no matching byte. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2777 if (hi < lo || byts[lo] != c) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2778 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2779 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2780 // Continue at the child (if there is one). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2781 tryidx = idxs[lo]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2782 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2783 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2784 if (l == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2785 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2786 // Found the matching char. Copy it to "kword" and go a |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2787 // level deeper. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2788 if (round[depth] == 1) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2789 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2790 STRNCPY(kword + kwordlen[depth], fword + fwordidx[depth], |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2791 flen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2792 kwordlen[depth + 1] = kwordlen[depth] + flen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2793 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2794 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2795 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2796 STRNCPY(kword + kwordlen[depth], uword + uwordidx[depth], |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2797 ulen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2798 kwordlen[depth + 1] = kwordlen[depth] + ulen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2799 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2800 fwordidx[depth + 1] = fwordidx[depth] + flen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2801 uwordidx[depth + 1] = uwordidx[depth] + ulen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2802 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2803 ++depth; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2804 arridx[depth] = tryidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2805 round[depth] = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2806 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2807 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2808 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2809 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2810 // Didn't find it: "cannot happen". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2811 *kword = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2812 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2813 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2814 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2815 * Compute the sound-a-like score for suggestions in su->su_ga and add them to |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2816 * su->su_sga. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2817 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2818 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2819 score_comp_sal(suginfo_T *su) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2820 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2821 langp_T *lp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2822 char_u badsound[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2823 int i; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2824 suggest_T *stp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2825 suggest_T *sstp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2826 int score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2827 int lpi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2828 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2829 if (ga_grow(&su->su_sga, su->su_ga.ga_len) == FAIL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2830 return; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2831 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2832 // Use the sound-folding of the first language that supports it. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2833 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2834 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2835 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2836 if (lp->lp_slang->sl_sal.ga_len > 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2837 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2838 // soundfold the bad word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2839 spell_soundfold(lp->lp_slang, su->su_fbadword, TRUE, badsound); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2840 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2841 for (i = 0; i < su->su_ga.ga_len; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2842 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2843 stp = &SUG(su->su_ga, i); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2844 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2845 // Case-fold the suggested word, sound-fold it and compute the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2846 // sound-a-like score. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2847 score = stp_sal_score(stp, su, lp->lp_slang, badsound); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2848 if (score < SCORE_MAXMAX) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2849 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2850 // Add the suggestion. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2851 sstp = &SUG(su->su_sga, su->su_sga.ga_len); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2852 sstp->st_word = vim_strsave(stp->st_word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2853 if (sstp->st_word != NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2854 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2855 sstp->st_wordlen = stp->st_wordlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2856 sstp->st_score = score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2857 sstp->st_altscore = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2858 sstp->st_orglen = stp->st_orglen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2859 ++su->su_sga.ga_len; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2860 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2861 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2862 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2863 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2864 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2865 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2866 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2867 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2868 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2869 * Combine the list of suggestions in su->su_ga and su->su_sga. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2870 * They are entwined. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2871 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2872 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2873 score_combine(suginfo_T *su) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2874 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2875 int i; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2876 int j; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2877 garray_T ga; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2878 garray_T *gap; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2879 langp_T *lp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2880 suggest_T *stp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2881 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2882 char_u badsound[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2883 int round; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2884 int lpi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2885 slang_T *slang = NULL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2886 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2887 // Add the alternate score to su_ga. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2888 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2889 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2890 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2891 if (lp->lp_slang->sl_sal.ga_len > 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2892 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2893 // soundfold the bad word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2894 slang = lp->lp_slang; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2895 spell_soundfold(slang, su->su_fbadword, TRUE, badsound); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2896 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2897 for (i = 0; i < su->su_ga.ga_len; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2898 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2899 stp = &SUG(su->su_ga, i); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2900 stp->st_altscore = stp_sal_score(stp, su, slang, badsound); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2901 if (stp->st_altscore == SCORE_MAXMAX) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2902 stp->st_score = (stp->st_score * 3 + SCORE_BIG) / 4; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2903 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2904 stp->st_score = (stp->st_score * 3 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2905 + stp->st_altscore) / 4; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2906 stp->st_salscore = FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2907 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2908 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2909 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2910 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2911 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2912 if (slang == NULL) // Using "double" without sound folding. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2913 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2914 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2915 su->su_maxcount); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2916 return; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2917 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2918 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2919 // Add the alternate score to su_sga. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2920 for (i = 0; i < su->su_sga.ga_len; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2921 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2922 stp = &SUG(su->su_sga, i); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2923 stp->st_altscore = spell_edit_score(slang, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2924 su->su_badword, stp->st_word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2925 if (stp->st_score == SCORE_MAXMAX) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2926 stp->st_score = (SCORE_BIG * 7 + stp->st_altscore) / 8; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2927 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2928 stp->st_score = (stp->st_score * 7 + stp->st_altscore) / 8; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2929 stp->st_salscore = TRUE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2930 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2931 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2932 // Remove bad suggestions, sort the suggestions and truncate at "maxcount" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2933 // for both lists. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2934 check_suggestions(su, &su->su_ga); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2935 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, su->su_maxcount); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2936 check_suggestions(su, &su->su_sga); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2937 (void)cleanup_suggestions(&su->su_sga, su->su_maxscore, su->su_maxcount); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2938 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2939 ga_init2(&ga, (int)sizeof(suginfo_T), 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2940 if (ga_grow(&ga, su->su_ga.ga_len + su->su_sga.ga_len) == FAIL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2941 return; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2942 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2943 stp = &SUG(ga, 0); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2944 for (i = 0; i < su->su_ga.ga_len || i < su->su_sga.ga_len; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2945 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2946 // round 1: get a suggestion from su_ga |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2947 // round 2: get a suggestion from su_sga |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2948 for (round = 1; round <= 2; ++round) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2949 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2950 gap = round == 1 ? &su->su_ga : &su->su_sga; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2951 if (i < gap->ga_len) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2952 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2953 // Don't add a word if it's already there. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2954 p = SUG(*gap, i).st_word; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2955 for (j = 0; j < ga.ga_len; ++j) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2956 if (STRCMP(stp[j].st_word, p) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2957 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2958 if (j == ga.ga_len) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2959 stp[ga.ga_len++] = SUG(*gap, i); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2960 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2961 vim_free(p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2962 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2963 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2964 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2965 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2966 ga_clear(&su->su_ga); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2967 ga_clear(&su->su_sga); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2968 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2969 // Truncate the list to the number of suggestions that will be displayed. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2970 if (ga.ga_len > su->su_maxcount) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2971 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2972 for (i = su->su_maxcount; i < ga.ga_len; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2973 vim_free(stp[i].st_word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2974 ga.ga_len = su->su_maxcount; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2975 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2976 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2977 su->su_ga = ga; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2978 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2979 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2980 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2981 * For the goodword in "stp" compute the soundalike score compared to the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2982 * badword. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2983 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2984 static int |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2985 stp_sal_score( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2986 suggest_T *stp, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2987 suginfo_T *su, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2988 slang_T *slang, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2989 char_u *badsound) // sound-folded badword |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2990 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2991 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2992 char_u *pbad; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2993 char_u *pgood; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2994 char_u badsound2[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2995 char_u fword[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2996 char_u goodsound[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2997 char_u goodword[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2998 int lendiff; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2999 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3000 lendiff = (int)(su->su_badlen - stp->st_orglen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3001 if (lendiff >= 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3002 pbad = badsound; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3003 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3004 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3005 // soundfold the bad word with more characters following |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3006 (void)spell_casefold(su->su_badptr, stp->st_orglen, fword, MAXWLEN); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3007 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3008 // When joining two words the sound often changes a lot. E.g., "t he" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3009 // sounds like "t h" while "the" sounds like "@". Avoid that by |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3010 // removing the space. Don't do it when the good word also contains a |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3011 // space. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3012 if (VIM_ISWHITE(su->su_badptr[su->su_badlen]) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3013 && *skiptowhite(stp->st_word) == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3014 for (p = fword; *(p = skiptowhite(p)) != NUL; ) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3015 STRMOVE(p, p + 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3016 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3017 spell_soundfold(slang, fword, TRUE, badsound2); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3018 pbad = badsound2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3019 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3020 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3021 if (lendiff > 0 && stp->st_wordlen + lendiff < MAXWLEN) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3022 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3023 // Add part of the bad word to the good word, so that we soundfold |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3024 // what replaces the bad word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3025 STRCPY(goodword, stp->st_word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3026 vim_strncpy(goodword + stp->st_wordlen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3027 su->su_badptr + su->su_badlen - lendiff, lendiff); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3028 pgood = goodword; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3029 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3030 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3031 pgood = stp->st_word; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3032 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3033 // Sound-fold the word and compute the score for the difference. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3034 spell_soundfold(slang, pgood, FALSE, goodsound); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3035 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3036 return soundalike_score(goodsound, pbad); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3037 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3038 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3039 // structure used to store soundfolded words that add_sound_suggest() has |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3040 // handled already. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3041 typedef struct |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3042 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3043 short sft_score; // lowest score used |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3044 char_u sft_word[1]; // soundfolded word, actually longer |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3045 } sftword_T; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3046 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3047 static sftword_T dumsft; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3048 #define HIKEY2SFT(p) ((sftword_T *)(p - (dumsft.sft_word - (char_u *)&dumsft))) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3049 #define HI2SFT(hi) HIKEY2SFT((hi)->hi_key) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3050 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3051 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3052 * Prepare for calling suggest_try_soundalike(). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3053 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3054 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3055 suggest_try_soundalike_prep(void) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3056 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3057 langp_T *lp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3058 int lpi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3059 slang_T *slang; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3060 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3061 // Do this for all languages that support sound folding and for which a |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3062 // .sug file has been loaded. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3063 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3064 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3065 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3066 slang = lp->lp_slang; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3067 if (slang->sl_sal.ga_len > 0 && slang->sl_sbyts != NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3068 // prepare the hashtable used by add_sound_suggest() |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3069 hash_init(&slang->sl_sounddone); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3070 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3071 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3072 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3073 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3074 * Find suggestions by comparing the word in a sound-a-like form. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3075 * Note: This doesn't support postponed prefixes. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3076 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3077 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3078 suggest_try_soundalike(suginfo_T *su) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3079 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3080 char_u salword[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3081 langp_T *lp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3082 int lpi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3083 slang_T *slang; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3084 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3085 // Do this for all languages that support sound folding and for which a |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3086 // .sug file has been loaded. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3087 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3088 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3089 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3090 slang = lp->lp_slang; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3091 if (slang->sl_sal.ga_len > 0 && slang->sl_sbyts != NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3092 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3093 // soundfold the bad word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3094 spell_soundfold(slang, su->su_fbadword, TRUE, salword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3095 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3096 // try all kinds of inserts/deletes/swaps/etc. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3097 // TODO: also soundfold the next words, so that we can try joining |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3098 // and splitting |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3099 #ifdef SUGGEST_PROFILE |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3100 prof_init(); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3101 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3102 suggest_trie_walk(su, lp, salword, TRUE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3103 #ifdef SUGGEST_PROFILE |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3104 prof_report("soundalike"); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3105 #endif |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3106 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3107 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3108 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3109 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3110 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3111 * Finish up after calling suggest_try_soundalike(). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3112 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3113 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3114 suggest_try_soundalike_finish(void) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3115 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3116 langp_T *lp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3117 int lpi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3118 slang_T *slang; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3119 int todo; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3120 hashitem_T *hi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3121 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3122 // Do this for all languages that support sound folding and for which a |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3123 // .sug file has been loaded. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3124 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3125 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3126 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3127 slang = lp->lp_slang; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3128 if (slang->sl_sal.ga_len > 0 && slang->sl_sbyts != NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3129 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3130 // Free the info about handled words. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3131 todo = (int)slang->sl_sounddone.ht_used; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3132 for (hi = slang->sl_sounddone.ht_array; todo > 0; ++hi) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3133 if (!HASHITEM_EMPTY(hi)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3134 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3135 vim_free(HI2SFT(hi)); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3136 --todo; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3137 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3138 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3139 // Clear the hashtable, it may also be used by another region. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3140 hash_clear(&slang->sl_sounddone); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3141 hash_init(&slang->sl_sounddone); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3142 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3143 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3144 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3145 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3146 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3147 * A match with a soundfolded word is found. Add the good word(s) that |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3148 * produce this soundfolded word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3149 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3150 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3151 add_sound_suggest( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3152 suginfo_T *su, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3153 char_u *goodword, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3154 int score, // soundfold score |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3155 langp_T *lp) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3156 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3157 slang_T *slang = lp->lp_slang; // language for sound folding |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3158 int sfwordnr; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3159 char_u *nrline; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3160 int orgnr; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3161 char_u theword[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3162 int i; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3163 int wlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3164 char_u *byts; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3165 idx_T *idxs; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3166 int n; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3167 int wordcount; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3168 int wc; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3169 int goodscore; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3170 hash_T hash; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3171 hashitem_T *hi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3172 sftword_T *sft; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3173 int bc, gc; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3174 int limit; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3175 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3176 // It's very well possible that the same soundfold word is found several |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3177 // times with different scores. Since the following is quite slow only do |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3178 // the words that have a better score than before. Use a hashtable to |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3179 // remember the words that have been done. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3180 hash = hash_hash(goodword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3181 hi = hash_lookup(&slang->sl_sounddone, goodword, hash); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3182 if (HASHITEM_EMPTY(hi)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3183 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3184 sft = alloc(sizeof(sftword_T) + STRLEN(goodword)); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3185 if (sft != NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3186 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3187 sft->sft_score = score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3188 STRCPY(sft->sft_word, goodword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3189 hash_add_item(&slang->sl_sounddone, hi, sft->sft_word, hash); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3190 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3191 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3192 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3193 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3194 sft = HI2SFT(hi); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3195 if (score >= sft->sft_score) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3196 return; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3197 sft->sft_score = score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3198 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3199 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3200 // Find the word nr in the soundfold tree. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3201 sfwordnr = soundfold_find(slang, goodword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3202 if (sfwordnr < 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3203 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3204 internal_error("add_sound_suggest()"); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3205 return; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3206 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3207 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3208 // go over the list of good words that produce this soundfold word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3209 nrline = ml_get_buf(slang->sl_sugbuf, (linenr_T)(sfwordnr + 1), FALSE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3210 orgnr = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3211 while (*nrline != NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3212 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3213 // The wordnr was stored in a minimal nr of bytes as an offset to the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3214 // previous wordnr. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3215 orgnr += bytes2offset(&nrline); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3216 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3217 byts = slang->sl_fbyts; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3218 idxs = slang->sl_fidxs; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3219 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3220 // Lookup the word "orgnr" one of the two tries. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3221 n = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3222 wordcount = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3223 for (wlen = 0; wlen < MAXWLEN - 3; ++wlen) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3224 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3225 i = 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3226 if (wordcount == orgnr && byts[n + 1] == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3227 break; // found end of word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3228 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3229 if (byts[n + 1] == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3230 ++wordcount; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3231 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3232 // skip over the NUL bytes |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3233 for ( ; byts[n + i] == NUL; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3234 if (i > byts[n]) // safety check |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3235 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3236 STRCPY(theword + wlen, "BAD"); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3237 wlen += 3; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3238 goto badword; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3239 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3240 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3241 // One of the siblings must have the word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3242 for ( ; i < byts[n]; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3243 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3244 wc = idxs[idxs[n + i]]; // nr of words under this byte |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3245 if (wordcount + wc > orgnr) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3246 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3247 wordcount += wc; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3248 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3249 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3250 theword[wlen] = byts[n + i]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3251 n = idxs[n + i]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3252 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3253 badword: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3254 theword[wlen] = NUL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3255 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3256 // Go over the possible flags and regions. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3257 for (; i <= byts[n] && byts[n + i] == NUL; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3258 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3259 char_u cword[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3260 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3261 int flags = (int)idxs[n + i]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3262 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3263 // Skip words with the NOSUGGEST flag |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3264 if (flags & WF_NOSUGGEST) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3265 continue; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3266 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3267 if (flags & WF_KEEPCAP) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3268 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3269 // Must find the word in the keep-case tree. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3270 find_keepcap_word(slang, theword, cword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3271 p = cword; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3272 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3273 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3274 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3275 flags |= su->su_badflags; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3276 if ((flags & WF_CAPMASK) != 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3277 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3278 // Need to fix case according to "flags". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3279 make_case_word(theword, cword, flags); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3280 p = cword; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3281 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3282 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3283 p = theword; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3284 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3285 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3286 // Add the suggestion. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3287 if (sps_flags & SPS_DOUBLE) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3288 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3289 // Add the suggestion if the score isn't too bad. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3290 if (score <= su->su_maxscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3291 add_suggestion(su, &su->su_sga, p, su->su_badlen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3292 score, 0, FALSE, slang, FALSE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3293 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3294 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3295 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3296 // Add a penalty for words in another region. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3297 if ((flags & WF_REGION) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3298 && (((unsigned)flags >> 16) & lp->lp_region) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3299 goodscore = SCORE_REGION; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3300 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3301 goodscore = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3302 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3303 // Add a small penalty for changing the first letter from |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3304 // lower to upper case. Helps for "tath" -> "Kath", which is |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3305 // less common than "tath" -> "path". Don't do it when the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3306 // letter is the same, that has already been counted. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3307 gc = PTR2CHAR(p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3308 if (SPELL_ISUPPER(gc)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3309 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3310 bc = PTR2CHAR(su->su_badword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3311 if (!SPELL_ISUPPER(bc) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3312 && SPELL_TOFOLD(bc) != SPELL_TOFOLD(gc)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3313 goodscore += SCORE_ICASE / 2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3314 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3315 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3316 // Compute the score for the good word. This only does letter |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3317 // insert/delete/swap/replace. REP items are not considered, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3318 // which may make the score a bit higher. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3319 // Use a limit for the score to make it work faster. Use |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3320 // MAXSCORE(), because RESCORE() will change the score. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3321 // If the limit is very high then the iterative method is |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3322 // inefficient, using an array is quicker. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3323 limit = MAXSCORE(su->su_sfmaxscore - goodscore, score); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3324 if (limit > SCORE_LIMITMAX) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3325 goodscore += spell_edit_score(slang, su->su_badword, p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3326 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3327 goodscore += spell_edit_score_limit(slang, su->su_badword, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3328 p, limit); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3329 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3330 // When going over the limit don't bother to do the rest. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3331 if (goodscore < SCORE_MAXMAX) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3332 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3333 // Give a bonus to words seen before. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3334 goodscore = score_wordcount_adj(slang, goodscore, p, FALSE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3335 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3336 // Add the suggestion if the score isn't too bad. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3337 goodscore = RESCORE(goodscore, score); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3338 if (goodscore <= su->su_sfmaxscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3339 add_suggestion(su, &su->su_ga, p, su->su_badlen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3340 goodscore, score, TRUE, slang, TRUE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3341 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3342 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3343 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3344 // smsg("word %s (%d): %s (%d)", sftword, sftnr, theword, orgnr); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3345 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3346 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3347 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3348 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3349 * Find word "word" in fold-case tree for "slang" and return the word number. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3350 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3351 static int |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3352 soundfold_find(slang_T *slang, char_u *word) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3353 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3354 idx_T arridx = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3355 int len; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3356 int wlen = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3357 int c; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3358 char_u *ptr = word; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3359 char_u *byts; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3360 idx_T *idxs; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3361 int wordnr = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3362 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3363 byts = slang->sl_sbyts; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3364 idxs = slang->sl_sidxs; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3365 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3366 for (;;) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3367 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3368 // First byte is the number of possible bytes. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3369 len = byts[arridx++]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3370 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3371 // If the first possible byte is a zero the word could end here. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3372 // If the word ends we found the word. If not skip the NUL bytes. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3373 c = ptr[wlen]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3374 if (byts[arridx] == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3375 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3376 if (c == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3377 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3378 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3379 // Skip over the zeros, there can be several. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3380 while (len > 0 && byts[arridx] == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3381 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3382 ++arridx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3383 --len; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3384 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3385 if (len == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3386 return -1; // no children, word should have ended here |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3387 ++wordnr; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3388 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3389 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3390 // If the word ends we didn't find it. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3391 if (c == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3392 return -1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3393 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3394 // Perform a binary search in the list of accepted bytes. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3395 if (c == TAB) // <Tab> is handled like <Space> |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3396 c = ' '; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3397 while (byts[arridx] < c) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3398 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3399 // The word count is in the first idxs[] entry of the child. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3400 wordnr += idxs[idxs[arridx]]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3401 ++arridx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3402 if (--len == 0) // end of the bytes, didn't find it |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3403 return -1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3404 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3405 if (byts[arridx] != c) // didn't find the byte |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3406 return -1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3407 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3408 // Continue at the child (if there is one). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3409 arridx = idxs[arridx]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3410 ++wlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3411 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3412 // One space in the good word may stand for several spaces in the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3413 // checked word. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3414 if (c == ' ') |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3415 while (ptr[wlen] == ' ' || ptr[wlen] == TAB) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3416 ++wlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3417 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3418 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3419 return wordnr; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3420 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3421 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3422 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3423 * Return TRUE if "c1" and "c2" are similar characters according to the MAP |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3424 * lines in the .aff file. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3425 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3426 static int |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3427 similar_chars(slang_T *slang, int c1, int c2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3428 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3429 int m1, m2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3430 char_u buf[MB_MAXBYTES + 1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3431 hashitem_T *hi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3432 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3433 if (c1 >= 256) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3434 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3435 buf[mb_char2bytes(c1, buf)] = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3436 hi = hash_find(&slang->sl_map_hash, buf); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3437 if (HASHITEM_EMPTY(hi)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3438 m1 = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3439 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3440 m1 = mb_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3441 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3442 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3443 m1 = slang->sl_map_array[c1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3444 if (m1 == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3445 return FALSE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3446 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3447 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3448 if (c2 >= 256) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3449 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3450 buf[mb_char2bytes(c2, buf)] = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3451 hi = hash_find(&slang->sl_map_hash, buf); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3452 if (HASHITEM_EMPTY(hi)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3453 m2 = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3454 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3455 m2 = mb_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3456 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3457 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3458 m2 = slang->sl_map_array[c2]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3459 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3460 return m1 == m2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3461 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3462 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3463 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3464 * Add a suggestion to the list of suggestions. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3465 * For a suggestion that is already in the list the lowest score is remembered. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3466 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3467 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3468 add_suggestion( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3469 suginfo_T *su, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3470 garray_T *gap, // either su_ga or su_sga |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3471 char_u *goodword, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3472 int badlenarg, // len of bad word replaced with "goodword" |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3473 int score, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3474 int altscore, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3475 int had_bonus, // value for st_had_bonus |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3476 slang_T *slang, // language for sound folding |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3477 int maxsf) // su_maxscore applies to soundfold score, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3478 // su_sfmaxscore to the total score. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3479 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3480 int goodlen; // len of goodword changed |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3481 int badlen; // len of bad word changed |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3482 suggest_T *stp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3483 suggest_T new_sug; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3484 int i; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3485 char_u *pgood, *pbad; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3486 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3487 // Minimize "badlen" for consistency. Avoids that changing "the the" to |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3488 // "thee the" is added next to changing the first "the" the "thee". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3489 pgood = goodword + STRLEN(goodword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3490 pbad = su->su_badptr + badlenarg; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3491 for (;;) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3492 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3493 goodlen = (int)(pgood - goodword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3494 badlen = (int)(pbad - su->su_badptr); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3495 if (goodlen <= 0 || badlen <= 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3496 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3497 MB_PTR_BACK(goodword, pgood); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3498 MB_PTR_BACK(su->su_badptr, pbad); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3499 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3500 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3501 if (mb_ptr2char(pgood) != mb_ptr2char(pbad)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3502 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3503 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3504 else if (*pgood != *pbad) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3505 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3506 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3507 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3508 if (badlen == 0 && goodlen == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3509 // goodword doesn't change anything; may happen for "the the" changing |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3510 // the first "the" to itself. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3511 return; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3512 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3513 if (gap->ga_len == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3514 i = -1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3515 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3516 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3517 // Check if the word is already there. Also check the length that is |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3518 // being replaced "thes," -> "these" is a different suggestion from |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3519 // "thes" -> "these". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3520 stp = &SUG(*gap, 0); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3521 for (i = gap->ga_len; --i >= 0; ++stp) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3522 if (stp->st_wordlen == goodlen |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3523 && stp->st_orglen == badlen |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3524 && STRNCMP(stp->st_word, goodword, goodlen) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3525 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3526 // Found it. Remember the word with the lowest score. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3527 if (stp->st_slang == NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3528 stp->st_slang = slang; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3529 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3530 new_sug.st_score = score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3531 new_sug.st_altscore = altscore; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3532 new_sug.st_had_bonus = had_bonus; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3533 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3534 if (stp->st_had_bonus != had_bonus) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3535 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3536 // Only one of the two had the soundalike score computed. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3537 // Need to do that for the other one now, otherwise the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3538 // scores can't be compared. This happens because |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3539 // suggest_try_change() doesn't compute the soundalike |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3540 // word to keep it fast, while some special methods set |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3541 // the soundalike score to zero. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3542 if (had_bonus) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3543 rescore_one(su, stp); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3544 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3545 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3546 new_sug.st_word = stp->st_word; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3547 new_sug.st_wordlen = stp->st_wordlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3548 new_sug.st_slang = stp->st_slang; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3549 new_sug.st_orglen = badlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3550 rescore_one(su, &new_sug); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3551 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3552 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3553 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3554 if (stp->st_score > new_sug.st_score) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3555 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3556 stp->st_score = new_sug.st_score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3557 stp->st_altscore = new_sug.st_altscore; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3558 stp->st_had_bonus = new_sug.st_had_bonus; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3559 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3560 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3561 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3562 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3563 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3564 if (i < 0 && ga_grow(gap, 1) == OK) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3565 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3566 // Add a suggestion. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3567 stp = &SUG(*gap, gap->ga_len); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3568 stp->st_word = vim_strnsave(goodword, goodlen); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3569 if (stp->st_word != NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3570 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3571 stp->st_wordlen = goodlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3572 stp->st_score = score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3573 stp->st_altscore = altscore; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3574 stp->st_had_bonus = had_bonus; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3575 stp->st_orglen = badlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3576 stp->st_slang = slang; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3577 ++gap->ga_len; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3578 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3579 // If we have too many suggestions now, sort the list and keep |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3580 // the best suggestions. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3581 if (gap->ga_len > SUG_MAX_COUNT(su)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3582 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3583 if (maxsf) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3584 su->su_sfmaxscore = cleanup_suggestions(gap, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3585 su->su_sfmaxscore, SUG_CLEAN_COUNT(su)); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3586 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3587 su->su_maxscore = cleanup_suggestions(gap, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3588 su->su_maxscore, SUG_CLEAN_COUNT(su)); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3589 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3590 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3591 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3592 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3593 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3594 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3595 * Suggestions may in fact be flagged as errors. Esp. for banned words and |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3596 * for split words, such as "the the". Remove these from the list here. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3597 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3598 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3599 check_suggestions( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3600 suginfo_T *su, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3601 garray_T *gap) // either su_ga or su_sga |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3602 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3603 suggest_T *stp; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3604 int i; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3605 char_u longword[MAXWLEN + 1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3606 int len; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3607 hlf_T attr; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3608 |
22021
514d622473af
patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents:
21106
diff
changeset
|
3609 if (gap->ga_len == 0) |
514d622473af
patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents:
21106
diff
changeset
|
3610 return; |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3611 stp = &SUG(*gap, 0); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3612 for (i = gap->ga_len - 1; i >= 0; --i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3613 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3614 // Need to append what follows to check for "the the". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3615 vim_strncpy(longword, stp[i].st_word, MAXWLEN); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3616 len = stp[i].st_wordlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3617 vim_strncpy(longword + len, su->su_badptr + stp[i].st_orglen, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3618 MAXWLEN - len); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3619 attr = HLF_COUNT; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3620 (void)spell_check(curwin, longword, &attr, NULL, FALSE); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3621 if (attr != HLF_COUNT) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3622 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3623 // Remove this entry. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3624 vim_free(stp[i].st_word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3625 --gap->ga_len; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3626 if (i < gap->ga_len) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3627 mch_memmove(stp + i, stp + i + 1, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3628 sizeof(suggest_T) * (gap->ga_len - i)); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3629 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3630 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3631 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3632 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3633 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3634 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3635 * Add a word to be banned. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3636 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3637 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3638 add_banned( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3639 suginfo_T *su, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3640 char_u *word) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3641 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3642 char_u *s; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3643 hash_T hash; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3644 hashitem_T *hi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3645 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3646 hash = hash_hash(word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3647 hi = hash_lookup(&su->su_banned, word, hash); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3648 if (HASHITEM_EMPTY(hi)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3649 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3650 s = vim_strsave(word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3651 if (s != NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3652 hash_add_item(&su->su_banned, hi, s, hash); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3653 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3654 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3655 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3656 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3657 * Recompute the score for all suggestions if sound-folding is possible. This |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3658 * is slow, thus only done for the final results. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3659 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3660 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3661 rescore_suggestions(suginfo_T *su) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3662 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3663 int i; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3664 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3665 if (su->su_sallang != NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3666 for (i = 0; i < su->su_ga.ga_len; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3667 rescore_one(su, &SUG(su->su_ga, i)); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3668 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3669 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3670 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3671 * Recompute the score for one suggestion if sound-folding is possible. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3672 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3673 static void |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3674 rescore_one(suginfo_T *su, suggest_T *stp) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3675 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3676 slang_T *slang = stp->st_slang; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3677 char_u sal_badword[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3678 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3679 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3680 // Only rescore suggestions that have no sal score yet and do have a |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3681 // language. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3682 if (slang != NULL && slang->sl_sal.ga_len > 0 && !stp->st_had_bonus) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3683 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3684 if (slang == su->su_sallang) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3685 p = su->su_sal_badword; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3686 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3687 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3688 spell_soundfold(slang, su->su_fbadword, TRUE, sal_badword); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3689 p = sal_badword; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3690 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3691 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3692 stp->st_altscore = stp_sal_score(stp, su, slang, p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3693 if (stp->st_altscore == SCORE_MAXMAX) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3694 stp->st_altscore = SCORE_BIG; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3695 stp->st_score = RESCORE(stp->st_score, stp->st_altscore); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3696 stp->st_had_bonus = TRUE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3697 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3698 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3699 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3700 static int sug_compare(const void *s1, const void *s2); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3701 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3702 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3703 * Function given to qsort() to sort the suggestions on st_score. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3704 * First on "st_score", then "st_altscore" then alphabetically. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3705 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3706 static int |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3707 sug_compare(const void *s1, const void *s2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3708 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3709 suggest_T *p1 = (suggest_T *)s1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3710 suggest_T *p2 = (suggest_T *)s2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3711 int n = p1->st_score - p2->st_score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3712 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3713 if (n == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3714 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3715 n = p1->st_altscore - p2->st_altscore; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3716 if (n == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3717 n = STRICMP(p1->st_word, p2->st_word); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3718 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3719 return n; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3720 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3721 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3722 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3723 * Cleanup the suggestions: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3724 * - Sort on score. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3725 * - Remove words that won't be displayed. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3726 * Returns the maximum score in the list or "maxscore" unmodified. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3727 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3728 static int |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3729 cleanup_suggestions( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3730 garray_T *gap, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3731 int maxscore, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3732 int keep) // nr of suggestions to keep |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3733 { |
19661
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3734 if (gap->ga_len > 0) |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3735 { |
19661
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3736 // Sort the list. |
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3737 qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), |
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3738 sug_compare); |
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3739 |
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3740 // Truncate the list to the number of suggestions that will be |
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3741 // displayed. |
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3742 if (gap->ga_len > keep) |
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3743 { |
22029
2d6d70a913c1
patch 8.2.1564: a few remaining errors from ubsan
Bram Moolenaar <Bram@vim.org>
parents:
22021
diff
changeset
|
3744 int i; |
2d6d70a913c1
patch 8.2.1564: a few remaining errors from ubsan
Bram Moolenaar <Bram@vim.org>
parents:
22021
diff
changeset
|
3745 suggest_T *stp = &SUG(*gap, 0); |
2d6d70a913c1
patch 8.2.1564: a few remaining errors from ubsan
Bram Moolenaar <Bram@vim.org>
parents:
22021
diff
changeset
|
3746 |
19661
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3747 for (i = keep; i < gap->ga_len; ++i) |
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3748 vim_free(stp[i].st_word); |
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3749 gap->ga_len = keep; |
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3750 if (keep >= 1) |
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3751 return stp[keep - 1].st_score; |
31d303c0c464
patch 8.2.0387: error for possible NULL argument to qsort()
Bram Moolenaar <Bram@vim.org>
parents:
18960
diff
changeset
|
3752 } |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3753 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3754 return maxscore; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3755 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3756 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3757 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3758 * Compute a score for two sound-a-like words. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3759 * This permits up to two inserts/deletes/swaps/etc. to keep things fast. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3760 * Instead of a generic loop we write out the code. That keeps it fast by |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3761 * avoiding checks that will not be possible. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3762 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3763 static int |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3764 soundalike_score( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3765 char_u *goodstart, // sound-folded good word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3766 char_u *badstart) // sound-folded bad word |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3767 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3768 char_u *goodsound = goodstart; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3769 char_u *badsound = badstart; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3770 int goodlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3771 int badlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3772 int n; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3773 char_u *pl, *ps; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3774 char_u *pl2, *ps2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3775 int score = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3776 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3777 // Adding/inserting "*" at the start (word starts with vowel) shouldn't be |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3778 // counted so much, vowels halfway the word aren't counted at all. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3779 if ((*badsound == '*' || *goodsound == '*') && *badsound != *goodsound) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3780 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3781 if ((badsound[0] == NUL && goodsound[1] == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3782 || (goodsound[0] == NUL && badsound[1] == NUL)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3783 // changing word with vowel to word without a sound |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3784 return SCORE_DEL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3785 if (badsound[0] == NUL || goodsound[0] == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3786 // more than two changes |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3787 return SCORE_MAXMAX; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3788 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3789 if (badsound[1] == goodsound[1] |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3790 || (badsound[1] != NUL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3791 && goodsound[1] != NUL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3792 && badsound[2] == goodsound[2])) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3793 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3794 // handle like a substitute |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3795 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3796 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3797 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3798 score = 2 * SCORE_DEL / 3; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3799 if (*badsound == '*') |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3800 ++badsound; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3801 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3802 ++goodsound; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3803 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3804 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3805 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3806 goodlen = (int)STRLEN(goodsound); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3807 badlen = (int)STRLEN(badsound); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3808 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3809 // Return quickly if the lengths are too different to be fixed by two |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3810 // changes. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3811 n = goodlen - badlen; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3812 if (n < -2 || n > 2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3813 return SCORE_MAXMAX; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3814 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3815 if (n > 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3816 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3817 pl = goodsound; // goodsound is longest |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3818 ps = badsound; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3819 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3820 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3821 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3822 pl = badsound; // badsound is longest |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3823 ps = goodsound; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3824 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3825 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3826 // Skip over the identical part. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3827 while (*pl == *ps && *pl != NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3828 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3829 ++pl; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3830 ++ps; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3831 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3832 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3833 switch (n) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3834 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3835 case -2: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3836 case 2: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3837 // Must delete two characters from "pl". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3838 ++pl; // first delete |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3839 while (*pl == *ps) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3840 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3841 ++pl; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3842 ++ps; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3843 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3844 // strings must be equal after second delete |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3845 if (STRCMP(pl + 1, ps) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3846 return score + SCORE_DEL * 2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3847 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3848 // Failed to compare. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3849 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3850 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3851 case -1: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3852 case 1: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3853 // Minimal one delete from "pl" required. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3854 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3855 // 1: delete |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3856 pl2 = pl + 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3857 ps2 = ps; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3858 while (*pl2 == *ps2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3859 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3860 if (*pl2 == NUL) // reached the end |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3861 return score + SCORE_DEL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3862 ++pl2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3863 ++ps2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3864 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3865 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3866 // 2: delete then swap, then rest must be equal |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3867 if (pl2[0] == ps2[1] && pl2[1] == ps2[0] |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3868 && STRCMP(pl2 + 2, ps2 + 2) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3869 return score + SCORE_DEL + SCORE_SWAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3870 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3871 // 3: delete then substitute, then the rest must be equal |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3872 if (STRCMP(pl2 + 1, ps2 + 1) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3873 return score + SCORE_DEL + SCORE_SUBST; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3874 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3875 // 4: first swap then delete |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3876 if (pl[0] == ps[1] && pl[1] == ps[0]) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3877 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3878 pl2 = pl + 2; // swap, skip two chars |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3879 ps2 = ps + 2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3880 while (*pl2 == *ps2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3881 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3882 ++pl2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3883 ++ps2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3884 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3885 // delete a char and then strings must be equal |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3886 if (STRCMP(pl2 + 1, ps2) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3887 return score + SCORE_SWAP + SCORE_DEL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3888 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3889 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3890 // 5: first substitute then delete |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3891 pl2 = pl + 1; // substitute, skip one char |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3892 ps2 = ps + 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3893 while (*pl2 == *ps2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3894 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3895 ++pl2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3896 ++ps2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3897 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3898 // delete a char and then strings must be equal |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3899 if (STRCMP(pl2 + 1, ps2) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3900 return score + SCORE_SUBST + SCORE_DEL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3901 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3902 // Failed to compare. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3903 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3904 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3905 case 0: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3906 // Lengths are equal, thus changes must result in same length: An |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3907 // insert is only possible in combination with a delete. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3908 // 1: check if for identical strings |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3909 if (*pl == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3910 return score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3911 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3912 // 2: swap |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3913 if (pl[0] == ps[1] && pl[1] == ps[0]) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3914 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3915 pl2 = pl + 2; // swap, skip two chars |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3916 ps2 = ps + 2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3917 while (*pl2 == *ps2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3918 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3919 if (*pl2 == NUL) // reached the end |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3920 return score + SCORE_SWAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3921 ++pl2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3922 ++ps2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3923 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3924 // 3: swap and swap again |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3925 if (pl2[0] == ps2[1] && pl2[1] == ps2[0] |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3926 && STRCMP(pl2 + 2, ps2 + 2) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3927 return score + SCORE_SWAP + SCORE_SWAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3928 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3929 // 4: swap and substitute |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3930 if (STRCMP(pl2 + 1, ps2 + 1) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3931 return score + SCORE_SWAP + SCORE_SUBST; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3932 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3933 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3934 // 5: substitute |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3935 pl2 = pl + 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3936 ps2 = ps + 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3937 while (*pl2 == *ps2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3938 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3939 if (*pl2 == NUL) // reached the end |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3940 return score + SCORE_SUBST; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3941 ++pl2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3942 ++ps2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3943 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3944 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3945 // 6: substitute and swap |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3946 if (pl2[0] == ps2[1] && pl2[1] == ps2[0] |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3947 && STRCMP(pl2 + 2, ps2 + 2) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3948 return score + SCORE_SUBST + SCORE_SWAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3949 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3950 // 7: substitute and substitute |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3951 if (STRCMP(pl2 + 1, ps2 + 1) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3952 return score + SCORE_SUBST + SCORE_SUBST; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3953 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3954 // 8: insert then delete |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3955 pl2 = pl; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3956 ps2 = ps + 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3957 while (*pl2 == *ps2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3958 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3959 ++pl2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3960 ++ps2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3961 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3962 if (STRCMP(pl2 + 1, ps2) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3963 return score + SCORE_INS + SCORE_DEL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3964 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3965 // 9: delete then insert |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3966 pl2 = pl + 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3967 ps2 = ps; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3968 while (*pl2 == *ps2) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3969 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3970 ++pl2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3971 ++ps2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3972 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3973 if (STRCMP(pl2, ps2 + 1) == 0) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3974 return score + SCORE_INS + SCORE_DEL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3975 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3976 // Failed to compare. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3977 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3978 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3979 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3980 return SCORE_MAXMAX; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3981 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3982 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3983 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3984 * Compute the "edit distance" to turn "badword" into "goodword". The less |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3985 * deletes/inserts/substitutes/swaps are required the lower the score. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3986 * |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3987 * The algorithm is described by Du and Chang, 1992. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3988 * The implementation of the algorithm comes from Aspell editdist.cpp, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3989 * edit_distance(). It has been converted from C++ to C and modified to |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3990 * support multi-byte characters. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3991 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3992 static int |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3993 spell_edit_score( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3994 slang_T *slang, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3995 char_u *badword, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3996 char_u *goodword) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3997 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3998 int *cnt; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3999 int badlen, goodlen; // lengths including NUL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4000 int j, i; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4001 int t; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4002 int bc, gc; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4003 int pbc, pgc; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4004 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4005 int wbadword[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4006 int wgoodword[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4007 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4008 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4009 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4010 // Get the characters from the multi-byte strings and put them in an |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4011 // int array for easy access. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4012 for (p = badword, badlen = 0; *p != NUL; ) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4013 wbadword[badlen++] = mb_cptr2char_adv(&p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4014 wbadword[badlen++] = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4015 for (p = goodword, goodlen = 0; *p != NUL; ) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4016 wgoodword[goodlen++] = mb_cptr2char_adv(&p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4017 wgoodword[goodlen++] = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4018 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4019 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4020 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4021 badlen = (int)STRLEN(badword) + 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4022 goodlen = (int)STRLEN(goodword) + 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4023 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4024 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4025 // We use "cnt" as an array: CNT(badword_idx, goodword_idx). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4026 #define CNT(a, b) cnt[(a) + (b) * (badlen + 1)] |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4027 cnt = ALLOC_MULT(int, (badlen + 1) * (goodlen + 1)); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4028 if (cnt == NULL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4029 return 0; // out of memory |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4030 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4031 CNT(0, 0) = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4032 for (j = 1; j <= goodlen; ++j) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4033 CNT(0, j) = CNT(0, j - 1) + SCORE_INS; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4034 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4035 for (i = 1; i <= badlen; ++i) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4036 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4037 CNT(i, 0) = CNT(i - 1, 0) + SCORE_DEL; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4038 for (j = 1; j <= goodlen; ++j) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4039 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4040 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4041 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4042 bc = wbadword[i - 1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4043 gc = wgoodword[j - 1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4044 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4045 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4046 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4047 bc = badword[i - 1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4048 gc = goodword[j - 1]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4049 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4050 if (bc == gc) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4051 CNT(i, j) = CNT(i - 1, j - 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4052 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4053 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4054 // Use a better score when there is only a case difference. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4055 if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4056 CNT(i, j) = SCORE_ICASE + CNT(i - 1, j - 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4057 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4058 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4059 // For a similar character use SCORE_SIMILAR. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4060 if (slang != NULL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4061 && slang->sl_has_map |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4062 && similar_chars(slang, gc, bc)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4063 CNT(i, j) = SCORE_SIMILAR + CNT(i - 1, j - 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4064 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4065 CNT(i, j) = SCORE_SUBST + CNT(i - 1, j - 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4066 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4067 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4068 if (i > 1 && j > 1) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4069 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4070 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4071 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4072 pbc = wbadword[i - 2]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4073 pgc = wgoodword[j - 2]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4074 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4075 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4076 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4077 pbc = badword[i - 2]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4078 pgc = goodword[j - 2]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4079 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4080 if (bc == pgc && pbc == gc) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4081 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4082 t = SCORE_SWAP + CNT(i - 2, j - 2); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4083 if (t < CNT(i, j)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4084 CNT(i, j) = t; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4085 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4086 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4087 t = SCORE_DEL + CNT(i - 1, j); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4088 if (t < CNT(i, j)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4089 CNT(i, j) = t; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4090 t = SCORE_INS + CNT(i, j - 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4091 if (t < CNT(i, j)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4092 CNT(i, j) = t; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4093 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4094 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4095 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4096 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4097 i = CNT(badlen - 1, goodlen - 1); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4098 vim_free(cnt); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4099 return i; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4100 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4101 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4102 typedef struct |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4103 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4104 int badi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4105 int goodi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4106 int score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4107 } limitscore_T; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4108 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4109 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4110 * Like spell_edit_score(), but with a limit on the score to make it faster. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4111 * May return SCORE_MAXMAX when the score is higher than "limit". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4112 * |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4113 * This uses a stack for the edits still to be tried. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4114 * The idea comes from Aspell leditdist.cpp. Rewritten in C and added support |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4115 * for multi-byte characters. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4116 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4117 static int |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4118 spell_edit_score_limit( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4119 slang_T *slang, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4120 char_u *badword, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4121 char_u *goodword, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4122 int limit) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4123 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4124 limitscore_T stack[10]; // allow for over 3 * 2 edits |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4125 int stackidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4126 int bi, gi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4127 int bi2, gi2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4128 int bc, gc; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4129 int score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4130 int score_off; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4131 int minscore; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4132 int round; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4133 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4134 // Multi-byte characters require a bit more work, use a different function |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4135 // to avoid testing "has_mbyte" quite often. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4136 if (has_mbyte) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4137 return spell_edit_score_limit_w(slang, badword, goodword, limit); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4138 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4139 // The idea is to go from start to end over the words. So long as |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4140 // characters are equal just continue, this always gives the lowest score. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4141 // When there is a difference try several alternatives. Each alternative |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4142 // increases "score" for the edit distance. Some of the alternatives are |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4143 // pushed unto a stack and tried later, some are tried right away. At the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4144 // end of the word the score for one alternative is known. The lowest |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4145 // possible score is stored in "minscore". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4146 stackidx = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4147 bi = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4148 gi = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4149 score = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4150 minscore = limit + 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4151 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4152 for (;;) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4153 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4154 // Skip over an equal part, score remains the same. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4155 for (;;) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4156 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4157 bc = badword[bi]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4158 gc = goodword[gi]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4159 if (bc != gc) // stop at a char that's different |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4160 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4161 if (bc == NUL) // both words end |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4162 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4163 if (score < minscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4164 minscore = score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4165 goto pop; // do next alternative |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4166 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4167 ++bi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4168 ++gi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4169 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4170 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4171 if (gc == NUL) // goodword ends, delete badword chars |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4172 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4173 do |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4174 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4175 if ((score += SCORE_DEL) >= minscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4176 goto pop; // do next alternative |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4177 } while (badword[++bi] != NUL); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4178 minscore = score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4179 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4180 else if (bc == NUL) // badword ends, insert badword chars |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4181 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4182 do |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4183 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4184 if ((score += SCORE_INS) >= minscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4185 goto pop; // do next alternative |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4186 } while (goodword[++gi] != NUL); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4187 minscore = score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4188 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4189 else // both words continue |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4190 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4191 // If not close to the limit, perform a change. Only try changes |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4192 // that may lead to a lower score than "minscore". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4193 // round 0: try deleting a char from badword |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4194 // round 1: try inserting a char in badword |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4195 for (round = 0; round <= 1; ++round) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4196 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4197 score_off = score + (round == 0 ? SCORE_DEL : SCORE_INS); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4198 if (score_off < minscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4199 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4200 if (score_off + SCORE_EDIT_MIN >= minscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4201 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4202 // Near the limit, rest of the words must match. We |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4203 // can check that right now, no need to push an item |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4204 // onto the stack. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4205 bi2 = bi + 1 - round; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4206 gi2 = gi + round; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4207 while (goodword[gi2] == badword[bi2]) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4208 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4209 if (goodword[gi2] == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4210 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4211 minscore = score_off; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4212 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4213 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4214 ++bi2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4215 ++gi2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4216 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4217 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4218 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4219 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4220 // try deleting/inserting a character later |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4221 stack[stackidx].badi = bi + 1 - round; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4222 stack[stackidx].goodi = gi + round; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4223 stack[stackidx].score = score_off; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4224 ++stackidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4225 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4226 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4227 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4228 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4229 if (score + SCORE_SWAP < minscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4230 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4231 // If swapping two characters makes a match then the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4232 // substitution is more expensive, thus there is no need to |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4233 // try both. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4234 if (gc == badword[bi + 1] && bc == goodword[gi + 1]) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4235 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4236 // Swap two characters, that is: skip them. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4237 gi += 2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4238 bi += 2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4239 score += SCORE_SWAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4240 continue; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4241 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4242 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4243 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4244 // Substitute one character for another which is the same |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4245 // thing as deleting a character from both goodword and badword. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4246 // Use a better score when there is only a case difference. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4247 if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4248 score += SCORE_ICASE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4249 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4250 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4251 // For a similar character use SCORE_SIMILAR. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4252 if (slang != NULL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4253 && slang->sl_has_map |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4254 && similar_chars(slang, gc, bc)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4255 score += SCORE_SIMILAR; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4256 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4257 score += SCORE_SUBST; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4258 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4259 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4260 if (score < minscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4261 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4262 // Do the substitution. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4263 ++gi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4264 ++bi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4265 continue; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4266 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4267 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4268 pop: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4269 // Get here to try the next alternative, pop it from the stack. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4270 if (stackidx == 0) // stack is empty, finished |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4271 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4272 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4273 // pop an item from the stack |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4274 --stackidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4275 gi = stack[stackidx].goodi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4276 bi = stack[stackidx].badi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4277 score = stack[stackidx].score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4278 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4279 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4280 // When the score goes over "limit" it may actually be much higher. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4281 // Return a very large number to avoid going below the limit when giving a |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4282 // bonus. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4283 if (minscore > limit) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4284 return SCORE_MAXMAX; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4285 return minscore; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4286 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4287 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4288 /* |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4289 * Multi-byte version of spell_edit_score_limit(). |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4290 * Keep it in sync with the above! |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4291 */ |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4292 static int |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4293 spell_edit_score_limit_w( |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4294 slang_T *slang, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4295 char_u *badword, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4296 char_u *goodword, |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4297 int limit) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4298 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4299 limitscore_T stack[10]; // allow for over 3 * 2 edits |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4300 int stackidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4301 int bi, gi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4302 int bi2, gi2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4303 int bc, gc; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4304 int score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4305 int score_off; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4306 int minscore; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4307 int round; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4308 char_u *p; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4309 int wbadword[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4310 int wgoodword[MAXWLEN]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4311 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4312 // Get the characters from the multi-byte strings and put them in an |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4313 // int array for easy access. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4314 bi = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4315 for (p = badword; *p != NUL; ) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4316 wbadword[bi++] = mb_cptr2char_adv(&p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4317 wbadword[bi++] = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4318 gi = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4319 for (p = goodword; *p != NUL; ) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4320 wgoodword[gi++] = mb_cptr2char_adv(&p); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4321 wgoodword[gi++] = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4322 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4323 // The idea is to go from start to end over the words. So long as |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4324 // characters are equal just continue, this always gives the lowest score. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4325 // When there is a difference try several alternatives. Each alternative |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4326 // increases "score" for the edit distance. Some of the alternatives are |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4327 // pushed unto a stack and tried later, some are tried right away. At the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4328 // end of the word the score for one alternative is known. The lowest |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4329 // possible score is stored in "minscore". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4330 stackidx = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4331 bi = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4332 gi = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4333 score = 0; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4334 minscore = limit + 1; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4335 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4336 for (;;) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4337 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4338 // Skip over an equal part, score remains the same. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4339 for (;;) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4340 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4341 bc = wbadword[bi]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4342 gc = wgoodword[gi]; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4343 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4344 if (bc != gc) // stop at a char that's different |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4345 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4346 if (bc == NUL) // both words end |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4347 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4348 if (score < minscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4349 minscore = score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4350 goto pop; // do next alternative |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4351 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4352 ++bi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4353 ++gi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4354 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4355 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4356 if (gc == NUL) // goodword ends, delete badword chars |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4357 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4358 do |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4359 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4360 if ((score += SCORE_DEL) >= minscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4361 goto pop; // do next alternative |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4362 } while (wbadword[++bi] != NUL); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4363 minscore = score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4364 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4365 else if (bc == NUL) // badword ends, insert badword chars |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4366 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4367 do |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4368 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4369 if ((score += SCORE_INS) >= minscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4370 goto pop; // do next alternative |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4371 } while (wgoodword[++gi] != NUL); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4372 minscore = score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4373 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4374 else // both words continue |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4375 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4376 // If not close to the limit, perform a change. Only try changes |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4377 // that may lead to a lower score than "minscore". |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4378 // round 0: try deleting a char from badword |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4379 // round 1: try inserting a char in badword |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4380 for (round = 0; round <= 1; ++round) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4381 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4382 score_off = score + (round == 0 ? SCORE_DEL : SCORE_INS); |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4383 if (score_off < minscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4384 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4385 if (score_off + SCORE_EDIT_MIN >= minscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4386 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4387 // Near the limit, rest of the words must match. We |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4388 // can check that right now, no need to push an item |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4389 // onto the stack. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4390 bi2 = bi + 1 - round; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4391 gi2 = gi + round; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4392 while (wgoodword[gi2] == wbadword[bi2]) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4393 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4394 if (wgoodword[gi2] == NUL) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4395 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4396 minscore = score_off; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4397 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4398 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4399 ++bi2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4400 ++gi2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4401 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4402 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4403 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4404 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4405 // try deleting a character from badword later |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4406 stack[stackidx].badi = bi + 1 - round; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4407 stack[stackidx].goodi = gi + round; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4408 stack[stackidx].score = score_off; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4409 ++stackidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4410 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4411 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4412 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4413 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4414 if (score + SCORE_SWAP < minscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4415 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4416 // If swapping two characters makes a match then the |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4417 // substitution is more expensive, thus there is no need to |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4418 // try both. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4419 if (gc == wbadword[bi + 1] && bc == wgoodword[gi + 1]) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4420 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4421 // Swap two characters, that is: skip them. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4422 gi += 2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4423 bi += 2; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4424 score += SCORE_SWAP; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4425 continue; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4426 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4427 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4428 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4429 // Substitute one character for another which is the same |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4430 // thing as deleting a character from both goodword and badword. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4431 // Use a better score when there is only a case difference. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4432 if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4433 score += SCORE_ICASE; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4434 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4435 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4436 // For a similar character use SCORE_SIMILAR. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4437 if (slang != NULL |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4438 && slang->sl_has_map |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4439 && similar_chars(slang, gc, bc)) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4440 score += SCORE_SIMILAR; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4441 else |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4442 score += SCORE_SUBST; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4443 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4444 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4445 if (score < minscore) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4446 { |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4447 // Do the substitution. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4448 ++gi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4449 ++bi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4450 continue; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4451 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4452 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4453 pop: |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4454 // Get here to try the next alternative, pop it from the stack. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4455 if (stackidx == 0) // stack is empty, finished |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4456 break; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4457 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4458 // pop an item from the stack |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4459 --stackidx; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4460 gi = stack[stackidx].goodi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4461 bi = stack[stackidx].badi; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4462 score = stack[stackidx].score; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4463 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4464 |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4465 // When the score goes over "limit" it may actually be much higher. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4466 // Return a very large number to avoid going below the limit when giving a |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4467 // bonus. |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4468 if (minscore > limit) |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4469 return SCORE_MAXMAX; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4470 return minscore; |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4471 } |
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4472 #endif // FEAT_SPELL |