Mercurial > vim
annotate src/spellsuggest.c @ 34829:7e93120ed584 v9.1.0284
patch 9.1.0284: make testclean is not able to delete failed screendumps
Commit: https://github.com/vim/vim/commit/e20c7d7f442e0d42d78db7337c1b5e7a3ff91671
Author: Julio B <julio.bacel@gmail.com>
Date: Tue Apr 9 21:22:41 2024 +0200
patch 9.1.0284: make testclean is not able to delete failed screendumps
Problem: make testclean is not able to delete failed screendumps.
Solution: Remove the "failed" directory when necessary.
(Julio B)
Patch 8.1.1080 changed the way that failed screendumps are saved, but
the "rm -rf *.failed" clean command was not ported correctly.
closes: #14468
Signed-off-by: Julio B <julio.bacel@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 09 Apr 2024 21:30:04 +0200 |
parents | fd15dc02c223 |
children | ffa6ed03a9f2 |
rev | line source |
---|---|
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
8 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
9 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
10 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
11 * spellsuggest.c: functions for spelling suggestions |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
12 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
13 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
14 #include "vim.h" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
15 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
16 #if defined(FEAT_SPELL) || defined(PROTO) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
17 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
18 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
19 * Use this to adjust the score after finding suggestions, based on the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
20 * suggested word sounding like the bad word. This is much faster than doing |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
21 * it for every possible suggestion. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
22 * Disadvantage: When "the" is typed as "hte" it sounds quite different ("@" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
23 * vs "ht") and goes down in the list. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
24 * Used when 'spellsuggest' is set to "best". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
25 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
26 #define RESCORE(word_score, sound_score) ((3 * (word_score) + (sound_score)) / 4) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
27 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
28 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
29 * Do the opposite: based on a maximum end score and a known sound score, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
30 * compute the maximum word score that can be used. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
31 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
32 #define MAXSCORE(word_score, sound_score) ((4 * (word_score) - (sound_score)) / 3) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
33 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
34 // only used for su_badflags |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
35 #define WF_MIXCAP 0x20 // mix of upper and lower case: macaRONI |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
36 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
37 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
38 * Information used when looking for suggestions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
39 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
40 typedef struct suginfo_S |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
41 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
42 garray_T su_ga; // suggestions, contains "suggest_T" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
43 int su_maxcount; // max. number of suggestions displayed |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
44 int su_maxscore; // maximum score for adding to su_ga |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
45 int su_sfmaxscore; // idem, for when doing soundfold words |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
46 garray_T su_sga; // like su_ga, sound-folded scoring |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
47 char_u *su_badptr; // start of bad word in line |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
48 int su_badlen; // length of detected bad word in line |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
49 int su_badflags; // caps flags for bad word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
50 char_u su_badword[MAXWLEN]; // bad word truncated at su_badlen |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
51 char_u su_fbadword[MAXWLEN]; // su_badword case-folded |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
52 char_u su_sal_badword[MAXWLEN]; // su_badword soundfolded |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
53 hashtab_T su_banned; // table with banned words |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
54 slang_T *su_sallang; // default language for sound folding |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
55 } suginfo_T; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
56 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
57 // One word suggestion. Used in "si_ga". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
58 typedef struct suggest_S |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
59 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
60 char_u *st_word; // suggested word, allocated string |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
61 int st_wordlen; // STRLEN(st_word) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
62 int st_orglen; // length of replaced text |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
63 int st_score; // lower is better |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
64 int st_altscore; // used when st_score compares equal |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
65 int st_salscore; // st_score is for soundalike |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
66 int st_had_bonus; // bonus already included in score |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
67 slang_T *st_slang; // language used for sound folding |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
68 } suggest_T; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
69 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
70 #define SUG(ga, i) (((suggest_T *)(ga).ga_data)[i]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
71 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
72 // TRUE if a word appears in the list of banned words. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
73 #define WAS_BANNED(su, word) (!HASHITEM_EMPTY(hash_find(&(su)->su_banned, word))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
74 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
75 // Number of suggestions kept when cleaning up. We need to keep more than |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
76 // what is displayed, because when rescore_suggestions() is called the score |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
77 // may change and wrong suggestions may be removed later. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
78 #define SUG_CLEAN_COUNT(su) ((su)->su_maxcount < 130 ? 150 : (su)->su_maxcount + 20) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
79 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
80 // Threshold for sorting and cleaning up suggestions. Don't want to keep lots |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
81 // of suggestions that are not going to be displayed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
82 #define SUG_MAX_COUNT(su) (SUG_CLEAN_COUNT(su) + 50) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
83 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
84 // score for various changes |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
85 #define SCORE_SPLIT 149 // split bad word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
86 #define SCORE_SPLIT_NO 249 // split bad word with NOSPLITSUGS |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
87 #define SCORE_ICASE 52 // slightly different case |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
88 #define SCORE_REGION 200 // word is for different region |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
89 #define SCORE_RARE 180 // rare word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
90 #define SCORE_SWAP 75 // swap two characters |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
91 #define SCORE_SWAP3 110 // swap two characters in three |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
92 #define SCORE_REP 65 // REP replacement |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
93 #define SCORE_SUBST 93 // substitute a character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
94 #define SCORE_SIMILAR 33 // substitute a similar character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
95 #define SCORE_SUBCOMP 33 // substitute a composing character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
96 #define SCORE_DEL 94 // delete a character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
97 #define SCORE_DELDUP 66 // delete a duplicated character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
98 #define SCORE_DELCOMP 28 // delete a composing character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
99 #define SCORE_INS 96 // insert a character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
100 #define SCORE_INSDUP 67 // insert a duplicate character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
101 #define SCORE_INSCOMP 30 // insert a composing character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
102 #define SCORE_NONWORD 103 // change non-word to word char |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
103 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
104 #define SCORE_FILE 30 // suggestion from a file |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
105 #define SCORE_MAXINIT 350 // Initial maximum score: higher == slower. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
106 // 350 allows for about three changes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
107 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
108 #define SCORE_COMMON1 30 // subtracted for words seen before |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
109 #define SCORE_COMMON2 40 // subtracted for words often seen |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
110 #define SCORE_COMMON3 50 // subtracted for words very often seen |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
111 #define SCORE_THRES2 10 // word count threshold for COMMON2 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
112 #define SCORE_THRES3 100 // word count threshold for COMMON3 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
113 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
114 // When trying changed soundfold words it becomes slow when trying more than |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
115 // two changes. With less than two changes it's slightly faster but we miss a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
116 // few good suggestions. In rare cases we need to try three of four changes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
117 #define SCORE_SFMAX1 200 // maximum score for first try |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
118 #define SCORE_SFMAX2 300 // maximum score for second try |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
119 #define SCORE_SFMAX3 400 // maximum score for third try |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
120 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
121 #define SCORE_BIG (SCORE_INS * 3) // big difference |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
122 #define SCORE_MAXMAX 999999 // accept any score |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
123 #define SCORE_LIMITMAX 350 // for spell_edit_score_limit() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
124 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
125 // for spell_edit_score_limit() we need to know the minimum value of |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
126 // SCORE_ICASE, SCORE_SWAP, SCORE_DEL, SCORE_SIMILAR and SCORE_INS |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
127 #define SCORE_EDIT_MIN SCORE_SIMILAR |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
128 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
129 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
130 * For finding suggestions: At each node in the tree these states are tried: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
131 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
132 typedef enum |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
133 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
134 STATE_START = 0, // At start of node check for NUL bytes (goodword |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
135 // ends); if badword ends there is a match, otherwise |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
136 // try splitting word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
137 STATE_NOPREFIX, // try without prefix |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
138 STATE_SPLITUNDO, // Undo splitting. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
139 STATE_ENDNUL, // Past NUL bytes at start of the node. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
140 STATE_PLAIN, // Use each byte of the node. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
141 STATE_DEL, // Delete a byte from the bad word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
142 STATE_INS_PREP, // Prepare for inserting bytes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
143 STATE_INS, // Insert a byte in the bad word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
144 STATE_SWAP, // Swap two bytes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
145 STATE_UNSWAP, // Undo swap two characters. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
146 STATE_SWAP3, // Swap two characters over three. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
147 STATE_UNSWAP3, // Undo Swap two characters over three. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
148 STATE_UNROT3L, // Undo rotate three characters left |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
149 STATE_UNROT3R, // Undo rotate three characters right |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
150 STATE_REP_INI, // Prepare for using REP items. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
151 STATE_REP, // Use matching REP items from the .aff file. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
152 STATE_REP_UNDO, // Undo a REP item replacement. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
153 STATE_FINAL // End of this node. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
154 } state_T; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
155 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
156 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
157 * Struct to keep the state at each level in suggest_try_change(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
158 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
159 typedef struct trystate_S |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
160 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
161 state_T ts_state; // state at this level, STATE_ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
162 int ts_score; // score |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
163 idx_T ts_arridx; // index in tree array, start of node |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
164 short ts_curi; // index in list of child nodes |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
165 char_u ts_fidx; // index in fword[], case-folded bad word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
166 char_u ts_fidxtry; // ts_fidx at which bytes may be changed |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
167 char_u ts_twordlen; // valid length of tword[] |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
168 char_u ts_prefixdepth; // stack depth for end of prefix or |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
169 // PFD_PREFIXTREE or PFD_NOPREFIX |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
170 char_u ts_flags; // TSF_ flags |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
171 char_u ts_tcharlen; // number of bytes in tword character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
172 char_u ts_tcharidx; // current byte index in tword character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
173 char_u ts_isdiff; // DIFF_ values |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
174 char_u ts_fcharstart; // index in fword where badword char started |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
175 char_u ts_prewordlen; // length of word in "preword[]" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
176 char_u ts_splitoff; // index in "tword" after last split |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
177 char_u ts_splitfidx; // "ts_fidx" at word split |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
178 char_u ts_complen; // nr of compound words used |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
179 char_u ts_compsplit; // index for "compflags" where word was spit |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
180 char_u ts_save_badflags; // su_badflags saved here |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
181 char_u ts_delidx; // index in fword for char that was deleted, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
182 // valid when "ts_flags" has TSF_DIDDEL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
183 } trystate_T; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
184 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
185 // values for ts_isdiff |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
186 #define DIFF_NONE 0 // no different byte (yet) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
187 #define DIFF_YES 1 // different byte found |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
188 #define DIFF_INSERT 2 // inserting character |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
189 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
190 // values for ts_flags |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
191 #define TSF_PREFIXOK 1 // already checked that prefix is OK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
192 #define TSF_DIDSPLIT 2 // tried split at this point |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
193 #define TSF_DIDDEL 4 // did a delete, "ts_delidx" has index |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
194 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
195 // special values ts_prefixdepth |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
196 #define PFD_NOPREFIX 0xff // not using prefixes |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
197 #define PFD_PREFIXTREE 0xfe // walking through the prefix tree |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
198 #define PFD_NOTSPECIAL 0xfd // highest value that's not special |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
199 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
200 static long spell_suggest_timeout = 5000; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
201 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
202 static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int maxcount, int banbadword, int need_cap, int interactive); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
203 #ifdef FEAT_EVAL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
204 static void spell_suggest_expr(suginfo_T *su, char_u *expr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
205 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
206 static void spell_suggest_file(suginfo_T *su, char_u *fname); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
207 static void spell_suggest_intern(suginfo_T *su, int interactive); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
208 static void spell_find_cleanup(suginfo_T *su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
209 static void suggest_try_special(suginfo_T *su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
210 static void suggest_try_change(suginfo_T *su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
211 static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, int soundfold); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
212 static void go_deeper(trystate_T *stack, int depth, int score_add); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
213 static void find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
214 static void score_comp_sal(suginfo_T *su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
215 static void score_combine(suginfo_T *su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
216 static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u *badsound); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
217 static void suggest_try_soundalike_prep(void); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
218 static void suggest_try_soundalike(suginfo_T *su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
219 static void suggest_try_soundalike_finish(void); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
220 static void add_sound_suggest(suginfo_T *su, char_u *goodword, int score, langp_T *lp); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
221 static int soundfold_find(slang_T *slang, char_u *word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
222 static int similar_chars(slang_T *slang, int c1, int c2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
223 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); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
224 static void check_suggestions(suginfo_T *su, garray_T *gap); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
225 static void add_banned(suginfo_T *su, char_u *word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
226 static void rescore_suggestions(suginfo_T *su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
227 static void rescore_one(suginfo_T *su, suggest_T *stp); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
228 static int cleanup_suggestions(garray_T *gap, int maxscore, int keep); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
229 static int soundalike_score(char_u *goodsound, char_u *badsound); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
230 static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
231 static int spell_edit_score_limit(slang_T *slang, char_u *badword, char_u *goodword, int limit); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
232 static int spell_edit_score_limit_w(slang_T *slang, char_u *badword, char_u *goodword, int limit); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
233 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
234 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
235 * Return TRUE when the sequence of flags in "compflags" plus "flag" can |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
236 * possibly form a valid compounded word. This also checks the COMPOUNDRULE |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
237 * lines if they don't contain wildcards. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
238 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
239 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
240 can_be_compound( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
241 trystate_T *sp, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
242 slang_T *slang, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
243 char_u *compflags, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
244 int flag) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
245 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
246 // If the flag doesn't appear in sl_compstartflags or sl_compallflags |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
247 // then it can't possibly compound. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
248 if (!byte_in_str(sp->ts_complen == sp->ts_compsplit |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
249 ? slang->sl_compstartflags : slang->sl_compallflags, flag)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
250 return FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
251 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
252 // If there are no wildcards, we can check if the flags collected so far |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
253 // possibly can form a match with COMPOUNDRULE patterns. This only |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
254 // makes sense when we have two or more words. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
255 if (slang->sl_comprules != NULL && sp->ts_complen > sp->ts_compsplit) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
256 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
257 int v; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
258 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
259 compflags[sp->ts_complen] = flag; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
260 compflags[sp->ts_complen + 1] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
261 v = match_compoundrule(slang, compflags + sp->ts_compsplit); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
262 compflags[sp->ts_complen] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
263 return v; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
264 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
265 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
266 return TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
267 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
268 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
269 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
270 * Adjust the score of common words. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
271 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
272 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
273 score_wordcount_adj( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
274 slang_T *slang, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
275 int score, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
276 char_u *word, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
277 int split) // word was split, less bonus |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
278 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
279 hashitem_T *hi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
280 wordcount_T *wc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
281 int bonus; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
282 int newscore; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
283 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
284 hi = hash_find(&slang->sl_wordcount, word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
285 if (HASHITEM_EMPTY(hi)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
286 return score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
287 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
288 wc = HI2WC(hi); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
289 if (wc->wc_count < SCORE_THRES2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
290 bonus = SCORE_COMMON1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
291 else if (wc->wc_count < SCORE_THRES3) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
292 bonus = SCORE_COMMON2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
293 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
294 bonus = SCORE_COMMON3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
295 if (split) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
296 newscore = score - bonus / 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
297 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
298 newscore = score - bonus; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
299 if (newscore < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
300 return 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
301 return newscore; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
302 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
303 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
304 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
305 * Like captype() but for a KEEPCAP word add ONECAP if the word starts with a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
306 * capital. So that make_case_word() can turn WOrd into Word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
307 * Add ALLCAP for "WOrD". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
308 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
309 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
310 badword_captype(char_u *word, char_u *end) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
311 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
312 int flags = captype(word, end); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
313 int c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
314 int l, u; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
315 int first; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
316 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
317 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
318 if (!(flags & WF_KEEPCAP)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
319 return flags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
320 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
321 // Count the number of UPPER and lower case letters. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
322 l = u = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
323 first = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
324 for (p = word; p < end; MB_PTR_ADV(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
325 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
326 c = PTR2CHAR(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
327 if (SPELL_ISUPPER(c)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
328 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
329 ++u; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
330 if (p == word) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
331 first = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
332 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
333 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
334 ++l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
335 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
336 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
337 // If there are more UPPER than lower case letters suggest an |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
338 // ALLCAP word. Otherwise, if the first letter is UPPER then |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
339 // suggest ONECAP. Exception: "ALl" most likely should be "All", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
340 // require three upper case letters. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
341 if (u > l && u > 2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
342 flags |= WF_ALLCAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
343 else if (first) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
344 flags |= WF_ONECAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
345 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
346 if (u >= 2 && l >= 2) // maCARONI maCAroni |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
347 flags |= WF_MIXCAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
348 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
349 return flags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
350 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
351 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
352 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
353 * Opposite of offset2bytes(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
354 * "pp" points to the bytes and is advanced over it. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
355 * Returns the offset. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
356 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
357 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
358 bytes2offset(char_u **pp) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
359 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
360 char_u *p = *pp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
361 int nr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
362 int c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
363 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
364 c = *p++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
365 if ((c & 0x80) == 0x00) // 1 byte |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
366 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
367 nr = c - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
368 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
369 else if ((c & 0xc0) == 0x80) // 2 bytes |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
370 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
371 nr = (c & 0x3f) - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
372 nr = nr * 255 + (*p++ - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
373 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
374 else if ((c & 0xe0) == 0xc0) // 3 bytes |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
375 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
376 nr = (c & 0x1f) - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
377 nr = nr * 255 + (*p++ - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
378 nr = nr * 255 + (*p++ - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
379 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
380 else // 4 bytes |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
381 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
382 nr = (c & 0x0f) - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
383 nr = nr * 255 + (*p++ - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
384 nr = nr * 255 + (*p++ - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
385 nr = nr * 255 + (*p++ - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
386 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
387 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
388 *pp = p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
389 return nr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
390 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
391 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
392 // values for sps_flags |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
393 #define SPS_BEST 1 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
394 #define SPS_FAST 2 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
395 #define SPS_DOUBLE 4 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
396 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
397 static int sps_flags = SPS_BEST; // flags from 'spellsuggest' |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
398 static int sps_limit = 9999; // max nr of suggestions given |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
399 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
400 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
401 * Check the 'spellsuggest' option. Return FAIL if it's wrong. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
402 * Sets "sps_flags" and "sps_limit". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
403 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
404 int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
405 spell_check_sps(void) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
406 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
407 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
408 char_u *s; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
409 char_u buf[MAXPATHL]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
410 int f; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
411 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
412 sps_flags = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
413 sps_limit = 9999; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
414 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
415 for (p = p_sps; *p != NUL; ) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
416 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
417 copy_option_part(&p, buf, MAXPATHL, ","); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
418 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
419 f = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
420 if (VIM_ISDIGIT(*buf)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
421 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
422 s = buf; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
423 sps_limit = getdigits(&s); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
424 if (*s != NUL && !VIM_ISDIGIT(*s)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
425 f = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
426 } |
33399
95db67c7b754
patch 9.0.1958: cannot complete option values
Christian Brabandt <cb@256bit.org>
parents:
32670
diff
changeset
|
427 // Note: Keep this in sync with p_sps_values. |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
428 else if (STRCMP(buf, "best") == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
429 f = SPS_BEST; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
430 else if (STRCMP(buf, "fast") == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
431 f = SPS_FAST; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
432 else if (STRCMP(buf, "double") == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
433 f = SPS_DOUBLE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
434 else if (STRNCMP(buf, "expr:", 5) != 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
435 && STRNCMP(buf, "file:", 5) != 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
436 && (STRNCMP(buf, "timeout:", 8) != 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
437 || (!VIM_ISDIGIT(buf[8]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
438 && !(buf[8] == '-' && VIM_ISDIGIT(buf[9]))))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
439 f = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
440 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
441 if (f == -1 || (sps_flags != 0 && f != 0)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
442 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
443 sps_flags = SPS_BEST; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
444 sps_limit = 9999; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
445 return FAIL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
446 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
447 if (f != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
448 sps_flags = f; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
449 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
450 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
451 if (sps_flags == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
452 sps_flags = SPS_BEST; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
453 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
454 return OK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
455 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
456 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
457 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
458 * "z=": Find badly spelled word under or after the cursor. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
459 * Give suggestions for the properly spelled word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
460 * In Visual mode use the highlighted word as the bad word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
461 * When "count" is non-zero use that suggestion. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
462 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
463 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
464 spell_suggest(int count) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
465 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
466 char_u *line; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
467 pos_T prev_cursor = curwin->w_cursor; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
468 char_u wcopy[MAXWLEN + 2]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
469 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
470 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
471 int c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
472 suginfo_T sug; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
473 suggest_T *stp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
474 int mouse_used; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
475 int need_cap; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
476 int limit; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
477 int selected = count; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
478 int badlen = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
479 int msg_scroll_save = msg_scroll; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
480 int wo_spell_save = curwin->w_p_spell; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
481 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
482 if (!curwin->w_p_spell) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
483 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
484 parse_spelllang(curwin); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
485 curwin->w_p_spell = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
486 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
487 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
488 if (*curwin->w_s->b_p_spl == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
489 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
490 emsg(_(e_spell_checking_is_not_possible)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
491 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
492 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
493 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
494 if (VIsual_active) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
495 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
496 // Use the Visually selected text as the bad word. But reject |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
497 // a multi-line selection. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
498 if (curwin->w_cursor.lnum != VIsual.lnum) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
499 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
500 vim_beep(BO_SPELL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
501 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
502 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
503 badlen = (int)curwin->w_cursor.col - (int)VIsual.col; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
504 if (badlen < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
505 badlen = -badlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
506 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
507 curwin->w_cursor.col = VIsual.col; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
508 ++badlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
509 end_visual_mode(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
510 // make sure we don't include the NUL at the end of the line |
34540
9e093c96dff6
patch 9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Christian Brabandt <cb@256bit.org>
parents:
34309
diff
changeset
|
511 if (badlen > ml_get_curline_len() - (int)curwin->w_cursor.col) |
9e093c96dff6
patch 9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Christian Brabandt <cb@256bit.org>
parents:
34309
diff
changeset
|
512 badlen = ml_get_curline_len() - (int)curwin->w_cursor.col; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
513 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
514 // Find the start of the badly spelled word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
515 else if (spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL) == 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
516 || curwin->w_cursor.col > prev_cursor.col) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
517 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
518 // No bad word or it starts after the cursor: use the word under the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
519 // cursor. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
520 curwin->w_cursor = prev_cursor; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
521 line = ml_get_curline(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
522 p = line + curwin->w_cursor.col; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
523 // Backup to before start of word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
524 while (p > line && spell_iswordp_nmw(p, curwin)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
525 MB_PTR_BACK(line, p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
526 // Forward to start of word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
527 while (*p != NUL && !spell_iswordp_nmw(p, curwin)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
528 MB_PTR_ADV(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
529 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
530 if (!spell_iswordp_nmw(p, curwin)) // No word found. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
531 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
532 beep_flush(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
533 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
534 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
535 curwin->w_cursor.col = (colnr_T)(p - line); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
536 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
537 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
538 // Get the word and its length. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
539 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
540 // Figure out if the word should be capitalised. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
541 need_cap = check_need_cap(curwin, curwin->w_cursor.lnum, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
542 curwin->w_cursor.col); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
543 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
544 // Make a copy of current line since autocommands may free the line. |
34540
9e093c96dff6
patch 9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Christian Brabandt <cb@256bit.org>
parents:
34309
diff
changeset
|
545 line = vim_strnsave(ml_get_curline(), ml_get_curline_len()); |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
546 if (line == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
547 goto skip; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
548 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
549 // Get the list of suggestions. Limit to 'lines' - 2 or the number in |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
550 // 'spellsuggest', whatever is smaller. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
551 if (sps_limit > (int)Rows - 2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
552 limit = (int)Rows - 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
553 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
554 limit = sps_limit; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
555 spell_find_suggest(line + curwin->w_cursor.col, badlen, &sug, limit, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
556 TRUE, need_cap, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
557 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
558 if (sug.su_ga.ga_len == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
559 msg(_("Sorry, no suggestions")); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
560 else if (count > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
561 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
562 if (count > sug.su_ga.ga_len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
563 smsg(_("Sorry, only %ld suggestions"), (long)sug.su_ga.ga_len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
564 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
565 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
566 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
567 #ifdef FEAT_RIGHTLEFT |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
568 // When 'rightleft' is set the list is drawn right-left. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
569 cmdmsg_rl = curwin->w_p_rl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
570 if (cmdmsg_rl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
571 msg_col = Columns - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
572 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
573 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
574 // List the suggestions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
575 msg_start(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
576 msg_row = Rows - 1; // for when 'cmdheight' > 1 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
577 lines_left = Rows; // avoid more prompt |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
578 vim_snprintf((char *)IObuff, IOSIZE, _("Change \"%.*s\" to:"), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
579 sug.su_badlen, sug.su_badptr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
580 #ifdef FEAT_RIGHTLEFT |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
581 if (cmdmsg_rl && STRNCMP(IObuff, "Change", 6) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
582 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
583 // And now the rabbit from the high hat: Avoid showing the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
584 // untranslated message rightleft. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
585 vim_snprintf((char *)IObuff, IOSIZE, ":ot \"%.*s\" egnahC", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
586 sug.su_badlen, sug.su_badptr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
587 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
588 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
589 msg_puts((char *)IObuff); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
590 msg_clr_eos(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
591 msg_putchar('\n'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
592 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
593 msg_scroll = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
594 for (i = 0; i < sug.su_ga.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
595 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
596 int el; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
597 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
598 stp = &SUG(sug.su_ga, i); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
599 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
600 // The suggested word may replace only part of the bad word, add |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
601 // the not replaced part. But only when it's not getting too long. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
602 vim_strncpy(wcopy, stp->st_word, MAXWLEN); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
603 el = sug.su_badlen - stp->st_orglen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
604 if (el > 0 && stp->st_wordlen + el <= MAXWLEN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
605 vim_strncpy(wcopy + stp->st_wordlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
606 sug.su_badptr + stp->st_orglen, el); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
607 vim_snprintf((char *)IObuff, IOSIZE, "%2d", i + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
608 #ifdef FEAT_RIGHTLEFT |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
609 if (cmdmsg_rl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
610 rl_mirror(IObuff); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
611 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
612 msg_puts((char *)IObuff); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
613 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
614 vim_snprintf((char *)IObuff, IOSIZE, " \"%s\"", wcopy); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
615 msg_puts((char *)IObuff); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
616 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
617 // The word may replace more than "su_badlen". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
618 if (sug.su_badlen < stp->st_orglen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
619 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
620 vim_snprintf((char *)IObuff, IOSIZE, _(" < \"%.*s\""), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
621 stp->st_orglen, sug.su_badptr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
622 msg_puts((char *)IObuff); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
623 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
624 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
625 if (p_verbose > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
626 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
627 // Add the score. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
628 if (sps_flags & (SPS_DOUBLE | SPS_BEST)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
629 vim_snprintf((char *)IObuff, IOSIZE, " (%s%d - %d)", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
630 stp->st_salscore ? "s " : "", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
631 stp->st_score, stp->st_altscore); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
632 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
633 vim_snprintf((char *)IObuff, IOSIZE, " (%d)", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
634 stp->st_score); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
635 #ifdef FEAT_RIGHTLEFT |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
636 if (cmdmsg_rl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
637 // Mirror the numbers, but keep the leading space. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
638 rl_mirror(IObuff + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
639 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
640 msg_advance(30); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
641 msg_puts((char *)IObuff); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
642 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
643 msg_putchar('\n'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
644 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
645 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
646 #ifdef FEAT_RIGHTLEFT |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
647 cmdmsg_rl = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
648 msg_col = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
649 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
650 // Ask for choice. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
651 selected = prompt_for_number(&mouse_used); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
652 if (mouse_used) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
653 selected -= lines_left; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
654 lines_left = Rows; // avoid more prompt |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
655 // don't delay for 'smd' in normal_cmd() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
656 msg_scroll = msg_scroll_save; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
657 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
658 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
659 if (selected > 0 && selected <= sug.su_ga.ga_len && u_save_cursor() == OK) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
660 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
661 // Save the from and to text for :spellrepall. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
662 VIM_CLEAR(repl_from); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
663 VIM_CLEAR(repl_to); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
664 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
665 stp = &SUG(sug.su_ga, selected - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
666 if (sug.su_badlen > stp->st_orglen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
667 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
668 // Replacing less than "su_badlen", append the remainder to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
669 // repl_to. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
670 repl_from = vim_strnsave(sug.su_badptr, sug.su_badlen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
671 vim_snprintf((char *)IObuff, IOSIZE, "%s%.*s", stp->st_word, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
672 sug.su_badlen - stp->st_orglen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
673 sug.su_badptr + stp->st_orglen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
674 repl_to = vim_strsave(IObuff); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
675 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
676 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
677 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
678 // Replacing su_badlen or more, use the whole word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
679 repl_from = vim_strnsave(sug.su_badptr, stp->st_orglen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
680 repl_to = vim_strsave(stp->st_word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
681 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
682 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
683 // Replace the word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
684 p = alloc(STRLEN(line) - stp->st_orglen + stp->st_wordlen + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
685 if (p != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
686 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
687 int len_diff = stp->st_wordlen - stp->st_orglen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
688 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
689 c = (int)(sug.su_badptr - line); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
690 mch_memmove(p, line, c); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
691 STRCPY(p + c, stp->st_word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
692 STRCAT(p, sug.su_badptr + stp->st_orglen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
693 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
694 // For redo we use a change-word command. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
695 ResetRedobuff(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
696 AppendToRedobuff((char_u *)"ciw"); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
697 AppendToRedobuffLit(p + c, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
698 stp->st_wordlen + sug.su_badlen - stp->st_orglen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
699 AppendCharToRedobuff(ESC); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
700 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
701 // "p" may be freed here |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
702 ml_replace(curwin->w_cursor.lnum, p, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
703 curwin->w_cursor.col = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
704 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
705 changed_bytes(curwin->w_cursor.lnum, c); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
706 #if defined(FEAT_PROP_POPUP) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
707 if (curbuf->b_has_textprop && len_diff != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
708 adjust_prop_columns(curwin->w_cursor.lnum, c, len_diff, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
709 APC_SUBSTITUTE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
710 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
711 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
712 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
713 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
714 curwin->w_cursor = prev_cursor; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
715 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
716 spell_find_cleanup(&sug); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
717 skip: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
718 vim_free(line); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
719 curwin->w_p_spell = wo_spell_save; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
720 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
721 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
722 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
723 * Find spell suggestions for "word". Return them in the growarray "*gap" as |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
724 * a list of allocated strings. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
725 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
726 void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
727 spell_suggest_list( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
728 garray_T *gap, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
729 char_u *word, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
730 int maxcount, // maximum nr of suggestions |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
731 int need_cap, // 'spellcapcheck' matched |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
732 int interactive) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
733 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
734 suginfo_T sug; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
735 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
736 suggest_T *stp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
737 char_u *wcopy; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
738 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
739 spell_find_suggest(word, 0, &sug, maxcount, FALSE, need_cap, interactive); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
740 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
741 // Make room in "gap". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
742 ga_init2(gap, sizeof(char_u *), sug.su_ga.ga_len + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
743 if (ga_grow(gap, sug.su_ga.ga_len) == OK) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
744 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
745 for (i = 0; i < sug.su_ga.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
746 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
747 stp = &SUG(sug.su_ga, i); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
748 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
749 // The suggested word may replace only part of "word", add the not |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
750 // replaced part. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
751 wcopy = alloc(stp->st_wordlen |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
752 + (unsigned)STRLEN(sug.su_badptr + stp->st_orglen) + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
753 if (wcopy == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
754 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
755 STRCPY(wcopy, stp->st_word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
756 STRCPY(wcopy + stp->st_wordlen, sug.su_badptr + stp->st_orglen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
757 ((char_u **)gap->ga_data)[gap->ga_len++] = wcopy; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
758 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
759 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
760 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
761 spell_find_cleanup(&sug); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
762 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
763 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
764 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
765 * Find spell suggestions for the word at the start of "badptr". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
766 * Return the suggestions in "su->su_ga". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
767 * The maximum number of suggestions is "maxcount". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
768 * Note: does use info for the current window. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
769 * This is based on the mechanisms of Aspell, but completely reimplemented. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
770 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
771 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
772 spell_find_suggest( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
773 char_u *badptr, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
774 int badlen, // length of bad word or 0 if unknown |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
775 suginfo_T *su, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
776 int maxcount, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
777 int banbadword, // don't include badword in suggestions |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
778 int need_cap, // word should start with capital |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
779 int interactive) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
780 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
781 hlf_T attr = HLF_COUNT; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
782 char_u buf[MAXPATHL]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
783 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
784 int do_combine = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
785 char_u *sps_copy; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
786 #ifdef FEAT_EVAL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
787 static int expr_busy = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
788 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
789 int c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
790 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
791 langp_T *lp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
792 int did_intern = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
793 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
794 // Set the info in "*su". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
795 CLEAR_POINTER(su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
796 ga_init2(&su->su_ga, sizeof(suggest_T), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
797 ga_init2(&su->su_sga, sizeof(suggest_T), 10); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
798 if (*badptr == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
799 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
800 hash_init(&su->su_banned); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
801 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
802 su->su_badptr = badptr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
803 if (badlen != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
804 su->su_badlen = badlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
805 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
806 su->su_badlen = spell_check(curwin, su->su_badptr, &attr, NULL, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
807 su->su_maxcount = maxcount; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
808 su->su_maxscore = SCORE_MAXINIT; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
809 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
810 if (su->su_badlen >= MAXWLEN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
811 su->su_badlen = MAXWLEN - 1; // just in case |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
812 vim_strncpy(su->su_badword, su->su_badptr, su->su_badlen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
813 (void)spell_casefold(curwin, su->su_badptr, su->su_badlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
814 su->su_fbadword, MAXWLEN); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
815 // TODO: make this work if the case-folded text is longer than the original |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
816 // text. Currently an illegal byte causes wrong pointer computations. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
817 su->su_fbadword[su->su_badlen] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
818 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
819 // get caps flags for bad word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
820 su->su_badflags = badword_captype(su->su_badptr, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
821 su->su_badptr + su->su_badlen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
822 if (need_cap) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
823 su->su_badflags |= WF_ONECAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
824 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
825 // Find the default language for sound folding. We simply use the first |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
826 // one in 'spelllang' that supports sound folding. That's good for when |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
827 // using multiple files for one language, it's not that bad when mixing |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
828 // languages (e.g., "pl,en"). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
829 for (i = 0; i < curbuf->b_s.b_langp.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
830 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
831 lp = LANGP_ENTRY(curbuf->b_s.b_langp, i); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
832 if (lp->lp_sallang != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
833 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
834 su->su_sallang = lp->lp_sallang; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
835 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
836 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
837 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
838 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
839 // Soundfold the bad word with the default sound folding, so that we don't |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
840 // have to do this many times. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
841 if (su->su_sallang != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
842 spell_soundfold(su->su_sallang, su->su_fbadword, TRUE, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
843 su->su_sal_badword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
844 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
845 // If the word is not capitalised and spell_check() doesn't consider the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
846 // word to be bad then it might need to be capitalised. Add a suggestion |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
847 // for that. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
848 c = PTR2CHAR(su->su_badptr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
849 if (!SPELL_ISUPPER(c) && attr == HLF_COUNT) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
850 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
851 make_case_word(su->su_badword, buf, WF_ONECAP); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
852 add_suggestion(su, &su->su_ga, buf, su->su_badlen, SCORE_ICASE, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
853 0, TRUE, su->su_sallang, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
854 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
855 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
856 // Ban the bad word itself. It may appear in another region. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
857 if (banbadword) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
858 add_banned(su, su->su_badword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
859 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
860 // Make a copy of 'spellsuggest', because the expression may change it. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
861 sps_copy = vim_strsave(p_sps); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
862 if (sps_copy == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
863 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
864 spell_suggest_timeout = 5000; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
865 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
866 // Loop over the items in 'spellsuggest'. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
867 for (p = sps_copy; *p != NUL; ) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
868 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
869 copy_option_part(&p, buf, MAXPATHL, ","); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
870 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
871 if (STRNCMP(buf, "expr:", 5) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
872 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
873 #ifdef FEAT_EVAL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
874 // Evaluate an expression. Skip this when called recursively, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
875 // when using spellsuggest() in the expression. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
876 if (!expr_busy) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
877 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
878 expr_busy = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
879 spell_suggest_expr(su, buf + 5); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
880 expr_busy = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
881 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
882 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
883 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
884 else if (STRNCMP(buf, "file:", 5) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
885 // Use list of suggestions in a file. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
886 spell_suggest_file(su, buf + 5); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
887 else if (STRNCMP(buf, "timeout:", 8) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
888 // Limit the time searching for suggestions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
889 spell_suggest_timeout = atol((char *)buf + 8); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
890 else if (!did_intern) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
891 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
892 // Use internal method once. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
893 spell_suggest_intern(su, interactive); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
894 if (sps_flags & SPS_DOUBLE) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
895 do_combine = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
896 did_intern = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
897 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
898 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
899 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
900 vim_free(sps_copy); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
901 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
902 if (do_combine) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
903 // Combine the two list of suggestions. This must be done last, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
904 // because sorting changes the order again. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
905 score_combine(su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
906 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
907 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
908 #ifdef FEAT_EVAL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
909 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
910 * Find suggestions by evaluating expression "expr". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
911 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
912 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
913 spell_suggest_expr(suginfo_T *su, char_u *expr) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
914 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
915 list_T *list; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
916 listitem_T *li; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
917 int score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
918 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
919 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
920 // The work is split up in a few parts to avoid having to export |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
921 // suginfo_T. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
922 // First evaluate the expression and get the resulting list. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
923 list = eval_spell_expr(su->su_badword, expr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
924 if (list != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
925 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
926 // Loop over the items in the list. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
927 FOR_ALL_LIST_ITEMS(list, li) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
928 if (li->li_tv.v_type == VAR_LIST) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
929 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
930 // Get the word and the score from the items. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
931 score = get_spellword(li->li_tv.vval.v_list, &p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
932 if (score >= 0 && score <= su->su_maxscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
933 add_suggestion(su, &su->su_ga, p, su->su_badlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
934 score, 0, TRUE, su->su_sallang, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
935 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
936 list_unref(list); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
937 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
938 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
939 // Remove bogus suggestions, sort and truncate at "maxcount". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
940 check_suggestions(su, &su->su_ga); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
941 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, su->su_maxcount); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
942 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
943 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
944 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
945 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
946 * Find suggestions in file "fname". Used for "file:" in 'spellsuggest'. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
947 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
948 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
949 spell_suggest_file(suginfo_T *su, char_u *fname) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
950 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
951 FILE *fd; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
952 char_u line[MAXWLEN * 2]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
953 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
954 int len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
955 char_u cword[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
956 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
957 // Open the file. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
958 fd = mch_fopen((char *)fname, "r"); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
959 if (fd == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
960 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
961 semsg(_(e_cant_open_file_str), fname); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
962 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
963 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
964 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
965 // Read it line by line. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
966 while (!vim_fgets(line, MAXWLEN * 2, fd) && !got_int) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
967 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
968 line_breakcheck(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
969 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
970 p = vim_strchr(line, '/'); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
971 if (p == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
972 continue; // No Tab found, just skip the line. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
973 *p++ = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
974 if (STRICMP(su->su_badword, line) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
975 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
976 // Match! Isolate the good word, until CR or NL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
977 for (len = 0; p[len] >= ' '; ++len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
978 ; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
979 p[len] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
980 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
981 // If the suggestion doesn't have specific case duplicate the case |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
982 // of the bad word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
983 if (captype(p, NULL) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
984 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
985 make_case_word(p, cword, su->su_badflags); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
986 p = cword; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
987 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
988 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
989 add_suggestion(su, &su->su_ga, p, su->su_badlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
990 SCORE_FILE, 0, TRUE, su->su_sallang, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
991 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
992 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
993 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
994 fclose(fd); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
995 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
996 // Remove bogus suggestions, sort and truncate at "maxcount". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
997 check_suggestions(su, &su->su_ga); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
998 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, su->su_maxcount); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
999 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1000 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1001 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1002 * Find suggestions for the internal method indicated by "sps_flags". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1003 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1004 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1005 spell_suggest_intern(suginfo_T *su, int interactive) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1006 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1007 // Load the .sug file(s) that are available and not done yet. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1008 suggest_load_files(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1009 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1010 // 1. Try special cases, such as repeating a word: "the the" -> "the". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1011 // |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1012 // Set a maximum score to limit the combination of operations that is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1013 // tried. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1014 suggest_try_special(su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1015 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1016 // 2. Try inserting/deleting/swapping/changing a letter, use REP entries |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1017 // from the .aff file and inserting a space (split the word). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1018 suggest_try_change(su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1019 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1020 // For the resulting top-scorers compute the sound-a-like score. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1021 if (sps_flags & SPS_DOUBLE) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1022 score_comp_sal(su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1023 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1024 // 3. Try finding sound-a-like words. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1025 if ((sps_flags & SPS_FAST) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1026 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1027 if (sps_flags & SPS_BEST) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1028 // Adjust the word score for the suggestions found so far for how |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1029 // they sound like. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1030 rescore_suggestions(su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1031 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1032 // While going through the soundfold tree "su_maxscore" is the score |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1033 // for the soundfold word, limits the changes that are being tried, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1034 // and "su_sfmaxscore" the rescored score, which is set by |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1035 // cleanup_suggestions(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1036 // First find words with a small edit distance, because this is much |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1037 // faster and often already finds the top-N suggestions. If we didn't |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1038 // find many suggestions try again with a higher edit distance. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1039 // "sl_sounddone" is used to avoid doing the same word twice. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1040 suggest_try_soundalike_prep(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1041 su->su_maxscore = SCORE_SFMAX1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1042 su->su_sfmaxscore = SCORE_MAXINIT * 3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1043 suggest_try_soundalike(su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1044 if (su->su_ga.ga_len < SUG_CLEAN_COUNT(su)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1045 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1046 // We didn't find enough matches, try again, allowing more |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1047 // changes to the soundfold word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1048 su->su_maxscore = SCORE_SFMAX2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1049 suggest_try_soundalike(su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1050 if (su->su_ga.ga_len < SUG_CLEAN_COUNT(su)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1051 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1052 // Still didn't find enough matches, try again, allowing even |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1053 // more changes to the soundfold word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1054 su->su_maxscore = SCORE_SFMAX3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1055 suggest_try_soundalike(su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1056 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1057 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1058 su->su_maxscore = su->su_sfmaxscore; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1059 suggest_try_soundalike_finish(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1060 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1061 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1062 // When CTRL-C was hit while searching do show the results. Only clear |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1063 // got_int when using a command, not for spellsuggest(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1064 ui_breakcheck(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1065 if (interactive && got_int) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1066 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1067 (void)vgetc(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1068 got_int = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1069 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1070 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1071 if ((sps_flags & SPS_DOUBLE) == 0 && su->su_ga.ga_len != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1072 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1073 if (sps_flags & SPS_BEST) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1074 // Adjust the word score for how it sounds like. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1075 rescore_suggestions(su); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1076 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1077 // Remove bogus suggestions, sort and truncate at "maxcount". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1078 check_suggestions(su, &su->su_ga); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1079 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, su->su_maxcount); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1080 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1081 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1082 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1083 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1084 * Free the info put in "*su" by spell_find_suggest(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1085 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1086 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1087 spell_find_cleanup(suginfo_T *su) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1088 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1089 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1090 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1091 // Free the suggestions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1092 for (i = 0; i < su->su_ga.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1093 vim_free(SUG(su->su_ga, i).st_word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1094 ga_clear(&su->su_ga); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1095 for (i = 0; i < su->su_sga.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1096 vim_free(SUG(su->su_sga, i).st_word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1097 ga_clear(&su->su_sga); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1098 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1099 // Free the banned words. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1100 hash_clear_all(&su->su_banned, 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1101 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1102 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1103 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1104 * Try finding suggestions by recognizing specific situations. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1105 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1106 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1107 suggest_try_special(suginfo_T *su) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1108 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1109 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1110 size_t len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1111 int c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1112 char_u word[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1113 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1114 // Recognize a word that is repeated: "the the". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1115 p = skiptowhite(su->su_fbadword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1116 len = p - su->su_fbadword; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1117 p = skipwhite(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1118 if (STRLEN(p) == len && STRNCMP(su->su_fbadword, p, len) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1119 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1120 // Include badflags: if the badword is onecap or allcap |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1121 // use that for the goodword too: "The the" -> "The". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1122 c = su->su_fbadword[len]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1123 su->su_fbadword[len] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1124 make_case_word(su->su_fbadword, word, su->su_badflags); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1125 su->su_fbadword[len] = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1126 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1127 // Give a soundalike score of 0, compute the score as if deleting one |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1128 // character. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1129 add_suggestion(su, &su->su_ga, word, su->su_badlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1130 RESCORE(SCORE_REP, 0), 0, TRUE, su->su_sallang, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1131 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1132 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1133 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1134 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1135 * Change the 0 to 1 to measure how much time is spent in each state. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1136 * Output is dumped in "suggestprof". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1137 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1138 #if 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1139 # define SUGGEST_PROFILE |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1140 proftime_T current; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1141 proftime_T total; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1142 proftime_T times[STATE_FINAL + 1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1143 long counts[STATE_FINAL + 1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1144 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1145 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1146 prof_init(void) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1147 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1148 for (int i = 0; i <= STATE_FINAL; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1149 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1150 profile_zero(×[i]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1151 counts[i] = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1152 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1153 profile_start(¤t); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1154 profile_start(&total); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1155 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1156 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1157 // call before changing state |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1158 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1159 prof_store(state_T state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1160 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1161 profile_end(¤t); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1162 profile_add(×[state], ¤t); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1163 ++counts[state]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1164 profile_start(¤t); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1165 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1166 # define PROF_STORE(state) prof_store(state); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1167 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1168 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1169 prof_report(char *name) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1170 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1171 FILE *fd = fopen("suggestprof", "a"); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1172 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1173 profile_end(&total); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1174 fprintf(fd, "-----------------------\n"); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1175 fprintf(fd, "%s: %s\n", name, profile_msg(&total)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1176 for (int i = 0; i <= STATE_FINAL; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1177 fprintf(fd, "%d: %s (%ld)\n", i, profile_msg(×[i]), counts[i]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1178 fclose(fd); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1179 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1180 #else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1181 # define PROF_STORE(state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1182 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1183 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1184 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1185 * Try finding suggestions by adding/removing/swapping letters. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1186 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1187 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1188 suggest_try_change(suginfo_T *su) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1189 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1190 char_u fword[MAXWLEN]; // copy of the bad word, case-folded |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1191 int n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1192 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1193 int lpi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1194 langp_T *lp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1195 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1196 // We make a copy of the case-folded bad word, so that we can modify it |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1197 // to find matches (esp. REP items). Append some more text, changing |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1198 // chars after the bad word may help. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1199 STRCPY(fword, su->su_fbadword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1200 n = (int)STRLEN(fword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1201 p = su->su_badptr + su->su_badlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1202 (void)spell_casefold(curwin, p, (int)STRLEN(p), fword + n, MAXWLEN - n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1203 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1204 // Make sure the resulting text is not longer than the original text. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1205 n = (int)STRLEN(su->su_badptr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1206 if (n < MAXWLEN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1207 fword[n] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1208 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1209 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1210 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1211 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1212 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1213 // If reloading a spell file fails it's still in the list but |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1214 // everything has been cleared. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1215 if (lp->lp_slang->sl_fbyts == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1216 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1217 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1218 // Try it for this language. Will add possible suggestions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1219 #ifdef SUGGEST_PROFILE |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1220 prof_init(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1221 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1222 suggest_trie_walk(su, lp, fword, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1223 #ifdef SUGGEST_PROFILE |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1224 prof_report("try_change"); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1225 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1226 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1227 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1228 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1229 // Check the maximum score, if we go over it we won't try this change. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1230 #define TRY_DEEPER(su, stack, depth, add) \ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1231 ((depth) < MAXWLEN - 1 && (stack)[depth].ts_score + (add) < (su)->su_maxscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1232 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1233 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1234 * Try finding suggestions by adding/removing/swapping letters. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1235 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1236 * This uses a state machine. At each node in the tree we try various |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1237 * operations. When trying if an operation works "depth" is increased and the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1238 * stack[] is used to store info. This allows combinations, thus insert one |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1239 * character, replace one and delete another. The number of changes is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1240 * limited by su->su_maxscore. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1241 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1242 * After implementing this I noticed an article by Kemal Oflazer that |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1243 * describes something similar: "Error-tolerant Finite State Recognition with |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1244 * Applications to Morphological Analysis and Spelling Correction" (1996). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1245 * The implementation in the article is simplified and requires a stack of |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1246 * unknown depth. The implementation here only needs a stack depth equal to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1247 * the length of the word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1248 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1249 * This is also used for the sound-folded word, "soundfold" is TRUE then. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1250 * The mechanism is the same, but we find a match with a sound-folded word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1251 * that comes from one or more original words. Each of these words may be |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1252 * added, this is done by add_sound_suggest(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1253 * Don't use: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1254 * the prefix tree or the keep-case tree |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1255 * "su->su_badlen" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1256 * anything to do with upper and lower case |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1257 * anything to do with word or non-word characters ("spell_iswordp()") |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1258 * banned words |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1259 * word flags (rare, region, compounding) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1260 * word splitting for now |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1261 * "similar_chars()" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1262 * use "slang->sl_repsal" instead of "lp->lp_replang->sl_rep" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1263 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1264 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1265 suggest_trie_walk( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1266 suginfo_T *su, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1267 langp_T *lp, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1268 char_u *fword, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1269 int soundfold) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1270 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1271 char_u tword[MAXWLEN]; // good word collected so far |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1272 trystate_T stack[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1273 char_u preword[MAXWLEN * 3]; // word found with proper case; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1274 // concatenation of prefix compound |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1275 // words and split word. NUL terminated |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1276 // when going deeper but not when coming |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1277 // back. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1278 char_u compflags[MAXWLEN]; // compound flags, one for each word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1279 trystate_T *sp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1280 int newscore; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1281 int score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1282 char_u *byts, *fbyts, *pbyts; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1283 idx_T *idxs, *fidxs, *pidxs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1284 int depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1285 int c, c2, c3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1286 int n = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1287 int flags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1288 garray_T *gap; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1289 idx_T arridx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1290 int len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1291 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1292 fromto_T *ftp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1293 int fl = 0, tl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1294 int repextra = 0; // extra bytes in fword[] from REP item |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1295 slang_T *slang = lp->lp_slang; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1296 int fword_ends; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1297 int goodword_ends; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1298 #ifdef DEBUG_TRIEWALK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1299 // Stores the name of the change made at each level. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1300 char_u changename[MAXWLEN][80]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1301 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1302 int breakcheckcount = 1000; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1303 #ifdef FEAT_RELTIME |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1304 proftime_T time_limit; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1305 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1306 int compound_ok; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1307 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1308 // Go through the whole case-fold tree, try changes at each node. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1309 // "tword[]" contains the word collected from nodes in the tree. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1310 // "fword[]" the word we are trying to match with (initially the bad |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1311 // word). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1312 depth = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1313 sp = &stack[0]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1314 CLEAR_POINTER(sp); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1315 sp->ts_curi = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1316 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1317 if (soundfold) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1318 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1319 // Going through the soundfold tree. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1320 byts = fbyts = slang->sl_sbyts; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1321 idxs = fidxs = slang->sl_sidxs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1322 pbyts = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1323 pidxs = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1324 sp->ts_prefixdepth = PFD_NOPREFIX; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1325 sp->ts_state = STATE_START; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1326 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1327 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1328 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1329 // When there are postponed prefixes we need to use these first. At |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1330 // the end of the prefix we continue in the case-fold tree. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1331 fbyts = slang->sl_fbyts; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1332 fidxs = slang->sl_fidxs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1333 pbyts = slang->sl_pbyts; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1334 pidxs = slang->sl_pidxs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1335 if (pbyts != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1336 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1337 byts = pbyts; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1338 idxs = pidxs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1339 sp->ts_prefixdepth = PFD_PREFIXTREE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1340 sp->ts_state = STATE_NOPREFIX; // try without prefix first |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1341 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1342 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1343 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1344 byts = fbyts; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1345 idxs = fidxs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1346 sp->ts_prefixdepth = PFD_NOPREFIX; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1347 sp->ts_state = STATE_START; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1348 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1349 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1350 #ifdef FEAT_RELTIME |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1351 // The loop may take an indefinite amount of time. Break out after some |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1352 // time. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1353 if (spell_suggest_timeout > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1354 profile_setlimit(spell_suggest_timeout, &time_limit); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1355 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1356 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1357 // Loop to find all suggestions. At each round we either: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1358 // - For the current state try one operation, advance "ts_curi", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1359 // increase "depth". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1360 // - When a state is done go to the next, set "ts_state". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1361 // - When all states are tried decrease "depth". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1362 while (depth >= 0 && !got_int) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1363 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1364 sp = &stack[depth]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1365 switch (sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1366 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1367 case STATE_START: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1368 case STATE_NOPREFIX: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1369 // Start of node: Deal with NUL bytes, which means |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1370 // tword[] may end here. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1371 arridx = sp->ts_arridx; // current node in the tree |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1372 len = byts[arridx]; // bytes in this node |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1373 arridx += sp->ts_curi; // index of current byte |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1374 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1375 if (sp->ts_prefixdepth == PFD_PREFIXTREE) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1376 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1377 // Skip over the NUL bytes, we use them later. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1378 for (n = 0; n < len && byts[arridx + n] == 0; ++n) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1379 ; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1380 sp->ts_curi += n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1381 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1382 // Always past NUL bytes now. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1383 n = (int)sp->ts_state; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1384 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1385 sp->ts_state = STATE_ENDNUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1386 sp->ts_save_badflags = su->su_badflags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1387 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1388 // At end of a prefix or at start of prefixtree: check for |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1389 // following word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1390 if (depth < MAXWLEN - 1 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1391 && (byts[arridx] == 0 || n == (int)STATE_NOPREFIX)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1392 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1393 // Set su->su_badflags to the caps type at this position. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1394 // Use the caps type until here for the prefix itself. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1395 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1396 n = nofold_len(fword, sp->ts_fidx, su->su_badptr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1397 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1398 n = sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1399 flags = badword_captype(su->su_badptr, su->su_badptr + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1400 su->su_badflags = badword_captype(su->su_badptr + n, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1401 su->su_badptr + su->su_badlen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1402 #ifdef DEBUG_TRIEWALK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1403 sprintf(changename[depth], "prefix"); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1404 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1405 go_deeper(stack, depth, 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1406 ++depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1407 sp = &stack[depth]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1408 sp->ts_prefixdepth = depth - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1409 byts = fbyts; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1410 idxs = fidxs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1411 sp->ts_arridx = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1412 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1413 // Move the prefix to preword[] with the right case |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1414 // and make find_keepcap_word() works. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1415 tword[sp->ts_twordlen] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1416 make_case_word(tword + sp->ts_splitoff, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1417 preword + sp->ts_prewordlen, flags); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1418 sp->ts_prewordlen = (char_u)STRLEN(preword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1419 sp->ts_splitoff = sp->ts_twordlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1420 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1421 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1422 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1423 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1424 if (sp->ts_curi > len || byts[arridx] != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1425 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1426 // Past bytes in node and/or past NUL bytes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1427 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1428 sp->ts_state = STATE_ENDNUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1429 sp->ts_save_badflags = su->su_badflags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1430 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1431 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1432 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1433 // End of word in tree. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1434 ++sp->ts_curi; // eat one NUL byte |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1435 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1436 flags = (int)idxs[arridx]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1437 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1438 // Skip words with the NOSUGGEST flag. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1439 if (flags & WF_NOSUGGEST) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1440 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1441 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1442 fword_ends = (fword[sp->ts_fidx] == NUL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1443 || (soundfold |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1444 ? VIM_ISWHITE(fword[sp->ts_fidx]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1445 : !spell_iswordp(fword + sp->ts_fidx, curwin))); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1446 tword[sp->ts_twordlen] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1447 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1448 if (sp->ts_prefixdepth <= PFD_NOTSPECIAL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1449 && (sp->ts_flags & TSF_PREFIXOK) == 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1450 && pbyts != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1451 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1452 // There was a prefix before the word. Check that the prefix |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1453 // can be used with this word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1454 // Count the length of the NULs in the prefix. If there are |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1455 // none this must be the first try without a prefix. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1456 n = stack[sp->ts_prefixdepth].ts_arridx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1457 len = pbyts[n++]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1458 for (c = 0; c < len && pbyts[n + c] == 0; ++c) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1459 ; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1460 if (c > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1461 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1462 c = valid_word_prefix(c, n, flags, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1463 tword + sp->ts_splitoff, slang, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1464 if (c == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1465 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1466 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1467 // Use the WF_RARE flag for a rare prefix. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1468 if (c & WF_RAREPFX) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1469 flags |= WF_RARE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1470 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1471 // Tricky: when checking for both prefix and compounding |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1472 // we run into the prefix flag first. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1473 // Remember that it's OK, so that we accept the prefix |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1474 // when arriving at a compound flag. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1475 sp->ts_flags |= TSF_PREFIXOK; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1476 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1477 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1478 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1479 // Check NEEDCOMPOUND: can't use word without compounding. Do try |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1480 // appending another compound word below. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1481 if (sp->ts_complen == sp->ts_compsplit && fword_ends |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1482 && (flags & WF_NEEDCOMP)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1483 goodword_ends = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1484 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1485 goodword_ends = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1486 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1487 p = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1488 compound_ok = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1489 if (sp->ts_complen > sp->ts_compsplit) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1490 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1491 if (slang->sl_nobreak) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1492 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1493 // There was a word before this word. When there was no |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1494 // change in this word (it was correct) add the first word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1495 // as a suggestion. If this word was corrected too, we |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1496 // need to check if a correct word follows. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1497 if (sp->ts_fidx - sp->ts_splitfidx |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1498 == sp->ts_twordlen - sp->ts_splitoff |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1499 && STRNCMP(fword + sp->ts_splitfidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1500 tword + sp->ts_splitoff, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1501 sp->ts_fidx - sp->ts_splitfidx) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1502 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1503 preword[sp->ts_prewordlen] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1504 newscore = score_wordcount_adj(slang, sp->ts_score, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1505 preword + sp->ts_prewordlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1506 sp->ts_prewordlen > 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1507 // Add the suggestion if the score isn't too bad. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1508 if (newscore <= su->su_maxscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1509 add_suggestion(su, &su->su_ga, preword, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1510 sp->ts_splitfidx - repextra, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1511 newscore, 0, FALSE, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1512 lp->lp_sallang, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1513 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1514 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1515 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1516 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1517 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1518 // There was a compound word before this word. If this |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1519 // word does not support compounding then give up |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1520 // (splitting is tried for the word without compound |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1521 // flag). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1522 if (((unsigned)flags >> 24) == 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1523 || sp->ts_twordlen - sp->ts_splitoff |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1524 < slang->sl_compminlen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1525 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1526 // For multi-byte chars check character length against |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1527 // COMPOUNDMIN. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1528 if (has_mbyte |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1529 && slang->sl_compminlen > 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1530 && mb_charlen(tword + sp->ts_splitoff) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1531 < slang->sl_compminlen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1532 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1533 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1534 compflags[sp->ts_complen] = ((unsigned)flags >> 24); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1535 compflags[sp->ts_complen + 1] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1536 vim_strncpy(preword + sp->ts_prewordlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1537 tword + sp->ts_splitoff, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1538 sp->ts_twordlen - sp->ts_splitoff); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1539 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1540 // Verify CHECKCOMPOUNDPATTERN rules. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1541 if (match_checkcompoundpattern(preword, sp->ts_prewordlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1542 &slang->sl_comppat)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1543 compound_ok = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1544 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1545 if (compound_ok) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1546 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1547 p = preword; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1548 while (*skiptowhite(p) != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1549 p = skipwhite(skiptowhite(p)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1550 if (fword_ends && !can_compound(slang, p, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1551 compflags + sp->ts_compsplit)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1552 // Compound is not allowed. But it may still be |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1553 // possible if we add another (short) word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1554 compound_ok = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1555 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1556 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1557 // Get pointer to last char of previous word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1558 p = preword + sp->ts_prewordlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1559 MB_PTR_BACK(preword, p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1560 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1561 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1562 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1563 // Form the word with proper case in preword. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1564 // If there is a word from a previous split, append. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1565 // For the soundfold tree don't change the case, simply append. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1566 if (soundfold) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1567 STRCPY(preword + sp->ts_prewordlen, tword + sp->ts_splitoff); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1568 else if (flags & WF_KEEPCAP) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1569 // Must find the word in the keep-case tree. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1570 find_keepcap_word(slang, tword + sp->ts_splitoff, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1571 preword + sp->ts_prewordlen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1572 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1573 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1574 // Include badflags: If the badword is onecap or allcap |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1575 // use that for the goodword too. But if the badword is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1576 // allcap and it's only one char long use onecap. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1577 c = su->su_badflags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1578 if ((c & WF_ALLCAP) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1579 && su->su_badlen == (*mb_ptr2len)(su->su_badptr)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1580 c = WF_ONECAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1581 c |= flags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1582 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1583 // When appending a compound word after a word character don't |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1584 // use Onecap. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1585 if (p != NULL && spell_iswordp_nmw(p, curwin)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1586 c &= ~WF_ONECAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1587 make_case_word(tword + sp->ts_splitoff, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1588 preword + sp->ts_prewordlen, c); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1589 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1590 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1591 if (!soundfold) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1592 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1593 // Don't use a banned word. It may appear again as a good |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1594 // word, thus remember it. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1595 if (flags & WF_BANNED) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1596 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1597 add_banned(su, preword + sp->ts_prewordlen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1598 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1599 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1600 if ((sp->ts_complen == sp->ts_compsplit |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1601 && WAS_BANNED(su, preword + sp->ts_prewordlen)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1602 || WAS_BANNED(su, preword)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1603 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1604 if (slang->sl_compprog == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1605 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1606 // the word so far was banned but we may try compounding |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1607 goodword_ends = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1608 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1609 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1610 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1611 newscore = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1612 if (!soundfold) // soundfold words don't have flags |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1613 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1614 if ((flags & WF_REGION) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1615 && (((unsigned)flags >> 16) & lp->lp_region) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1616 newscore += SCORE_REGION; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1617 if (flags & WF_RARE) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1618 newscore += SCORE_RARE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1619 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1620 if (!spell_valid_case(su->su_badflags, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1621 captype(preword + sp->ts_prewordlen, NULL))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1622 newscore += SCORE_ICASE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1623 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1624 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1625 // TODO: how about splitting in the soundfold tree? |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1626 if (fword_ends |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1627 && goodword_ends |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1628 && sp->ts_fidx >= sp->ts_fidxtry |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1629 && compound_ok) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1630 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1631 // The badword also ends: add suggestions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1632 #ifdef DEBUG_TRIEWALK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1633 if (soundfold && STRCMP(preword, "smwrd") == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1634 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1635 int j; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1636 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1637 // print the stack of changes that brought us here |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1638 smsg("------ %s -------", fword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1639 for (j = 0; j < depth; ++j) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1640 smsg("%s", changename[j]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1641 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1642 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1643 if (soundfold) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1644 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1645 // For soundfolded words we need to find the original |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1646 // words, the edit distance and then add them. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1647 add_sound_suggest(su, preword, sp->ts_score, lp); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1648 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1649 else if (sp->ts_fidx > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1650 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1651 // Give a penalty when changing non-word char to word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1652 // char, e.g., "thes," -> "these". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1653 p = fword + sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1654 MB_PTR_BACK(fword, p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1655 if (!spell_iswordp(p, curwin) && *preword != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1656 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1657 p = preword + STRLEN(preword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1658 MB_PTR_BACK(preword, p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1659 if (spell_iswordp(p, curwin)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1660 newscore += SCORE_NONWORD; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1661 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1662 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1663 // Give a bonus to words seen before. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1664 score = score_wordcount_adj(slang, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1665 sp->ts_score + newscore, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1666 preword + sp->ts_prewordlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1667 sp->ts_prewordlen > 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1668 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1669 // Add the suggestion if the score isn't too bad. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1670 if (score <= su->su_maxscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1671 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1672 add_suggestion(su, &su->su_ga, preword, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1673 sp->ts_fidx - repextra, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1674 score, 0, FALSE, lp->lp_sallang, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1675 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1676 if (su->su_badflags & WF_MIXCAP) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1677 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1678 // We really don't know if the word should be |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1679 // upper or lower case, add both. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1680 c = captype(preword, NULL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1681 if (c == 0 || c == WF_ALLCAP) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1682 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1683 make_case_word(tword + sp->ts_splitoff, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1684 preword + sp->ts_prewordlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1685 c == 0 ? WF_ALLCAP : 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1686 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1687 add_suggestion(su, &su->su_ga, preword, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1688 sp->ts_fidx - repextra, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1689 score + SCORE_ICASE, 0, FALSE, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1690 lp->lp_sallang, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1691 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1692 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1693 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1694 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1695 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1696 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1697 // Try word split and/or compounding. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1698 if ((sp->ts_fidx >= sp->ts_fidxtry || fword_ends) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1699 // Don't split halfway a character. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1700 && (!has_mbyte || sp->ts_tcharlen == 0)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1701 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1702 int try_compound; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1703 int try_split; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1704 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1705 // If past the end of the bad word don't try a split. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1706 // Otherwise try changing the next word. E.g., find |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1707 // suggestions for "the the" where the second "the" is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1708 // different. It's done like a split. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1709 // TODO: word split for soundfold words |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1710 try_split = (sp->ts_fidx - repextra < su->su_badlen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1711 && !soundfold; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1712 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1713 // Get here in several situations: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1714 // 1. The word in the tree ends: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1715 // If the word allows compounding try that. Otherwise try |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1716 // a split by inserting a space. For both check that a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1717 // valid words starts at fword[sp->ts_fidx]. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1718 // For NOBREAK do like compounding to be able to check if |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1719 // the next word is valid. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1720 // 2. The badword does end, but it was due to a change (e.g., |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1721 // a swap). No need to split, but do check that the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1722 // following word is valid. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1723 // 3. The badword and the word in the tree end. It may still |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1724 // be possible to compound another (short) word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1725 try_compound = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1726 if (!soundfold |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1727 && !slang->sl_nocompoundsugs |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1728 && slang->sl_compprog != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1729 && ((unsigned)flags >> 24) != 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1730 && sp->ts_twordlen - sp->ts_splitoff |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1731 >= slang->sl_compminlen |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1732 && (!has_mbyte |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1733 || slang->sl_compminlen == 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1734 || mb_charlen(tword + sp->ts_splitoff) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1735 >= slang->sl_compminlen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1736 && (slang->sl_compsylmax < MAXWLEN |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1737 || sp->ts_complen + 1 - sp->ts_compsplit |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1738 < slang->sl_compmax) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1739 && (can_be_compound(sp, slang, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1740 compflags, ((unsigned)flags >> 24)))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1741 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1742 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1743 try_compound = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1744 compflags[sp->ts_complen] = ((unsigned)flags >> 24); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1745 compflags[sp->ts_complen + 1] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1746 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1747 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1748 // For NOBREAK we never try splitting, it won't make any word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1749 // valid. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1750 if (slang->sl_nobreak && !slang->sl_nocompoundsugs) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1751 try_compound = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1752 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1753 // If we could add a compound word, and it's also possible to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1754 // split at this point, do the split first and set |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1755 // TSF_DIDSPLIT to avoid doing it again. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1756 else if (!fword_ends |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1757 && try_compound |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1758 && (sp->ts_flags & TSF_DIDSPLIT) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1759 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1760 try_compound = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1761 sp->ts_flags |= TSF_DIDSPLIT; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1762 --sp->ts_curi; // do the same NUL again |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1763 compflags[sp->ts_complen] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1764 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1765 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1766 sp->ts_flags &= ~TSF_DIDSPLIT; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1767 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1768 if (try_split || try_compound) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1769 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1770 if (!try_compound && (!fword_ends || !goodword_ends)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1771 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1772 // If we're going to split need to check that the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1773 // words so far are valid for compounding. If there |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1774 // is only one word it must not have the NEEDCOMPOUND |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1775 // flag. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1776 if (sp->ts_complen == sp->ts_compsplit |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1777 && (flags & WF_NEEDCOMP)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1778 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1779 p = preword; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1780 while (*skiptowhite(p) != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1781 p = skipwhite(skiptowhite(p)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1782 if (sp->ts_complen > sp->ts_compsplit |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1783 && !can_compound(slang, p, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1784 compflags + sp->ts_compsplit)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1785 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1786 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1787 if (slang->sl_nosplitsugs) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1788 newscore += SCORE_SPLIT_NO; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1789 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1790 newscore += SCORE_SPLIT; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1791 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1792 // Give a bonus to words seen before. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1793 newscore = score_wordcount_adj(slang, newscore, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1794 preword + sp->ts_prewordlen, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1795 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1796 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1797 if (TRY_DEEPER(su, stack, depth, newscore)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1798 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1799 go_deeper(stack, depth, newscore); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1800 #ifdef DEBUG_TRIEWALK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1801 if (!try_compound && !fword_ends) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1802 sprintf(changename[depth], "%.*s-%s: split", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1803 sp->ts_twordlen, tword, fword + sp->ts_fidx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1804 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1805 sprintf(changename[depth], "%.*s-%s: compound", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1806 sp->ts_twordlen, tword, fword + sp->ts_fidx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1807 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1808 // Save things to be restored at STATE_SPLITUNDO. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1809 sp->ts_save_badflags = su->su_badflags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1810 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1811 sp->ts_state = STATE_SPLITUNDO; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1812 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1813 ++depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1814 sp = &stack[depth]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1815 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1816 // Append a space to preword when splitting. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1817 if (!try_compound && !fword_ends) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1818 STRCAT(preword, " "); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1819 sp->ts_prewordlen = (char_u)STRLEN(preword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1820 sp->ts_splitoff = sp->ts_twordlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1821 sp->ts_splitfidx = sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1822 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1823 // If the badword has a non-word character at this |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1824 // position skip it. That means replacing the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1825 // non-word character with a space. Always skip a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1826 // character when the word ends. But only when the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1827 // good word can end. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1828 if (((!try_compound && !spell_iswordp_nmw(fword |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1829 + sp->ts_fidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1830 curwin)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1831 || fword_ends) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1832 && fword[sp->ts_fidx] != NUL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1833 && goodword_ends) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1834 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1835 int l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1836 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1837 l = mb_ptr2len(fword + sp->ts_fidx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1838 if (fword_ends) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1839 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1840 // Copy the skipped character to preword. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1841 mch_memmove(preword + sp->ts_prewordlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1842 fword + sp->ts_fidx, l); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1843 sp->ts_prewordlen += l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1844 preword[sp->ts_prewordlen] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1845 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1846 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1847 sp->ts_score -= SCORE_SPLIT - SCORE_SUBST; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1848 sp->ts_fidx += l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1849 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1850 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1851 // When compounding include compound flag in |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1852 // compflags[] (already set above). When splitting we |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1853 // may start compounding over again. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1854 if (try_compound) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1855 ++sp->ts_complen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1856 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1857 sp->ts_compsplit = sp->ts_complen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1858 sp->ts_prefixdepth = PFD_NOPREFIX; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1859 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1860 // set su->su_badflags to the caps type at this |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1861 // position |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1862 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1863 n = nofold_len(fword, sp->ts_fidx, su->su_badptr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1864 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1865 n = sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1866 su->su_badflags = badword_captype(su->su_badptr + n, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1867 su->su_badptr + su->su_badlen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1868 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1869 // Restart at top of the tree. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1870 sp->ts_arridx = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1871 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1872 // If there are postponed prefixes, try these too. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1873 if (pbyts != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1874 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1875 byts = pbyts; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1876 idxs = pidxs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1877 sp->ts_prefixdepth = PFD_PREFIXTREE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1878 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1879 sp->ts_state = STATE_NOPREFIX; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1880 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1881 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1882 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1883 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1884 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1885 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1886 case STATE_SPLITUNDO: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1887 // Undo the changes done for word split or compound word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1888 su->su_badflags = sp->ts_save_badflags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1889 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1890 // Continue looking for NUL bytes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1891 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1892 sp->ts_state = STATE_START; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1893 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1894 // In case we went into the prefix tree. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1895 byts = fbyts; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1896 idxs = fidxs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1897 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1898 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1899 case STATE_ENDNUL: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1900 // Past the NUL bytes in the node. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1901 su->su_badflags = sp->ts_save_badflags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1902 if (fword[sp->ts_fidx] == NUL && sp->ts_tcharlen == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1903 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1904 // The badword ends, can't use STATE_PLAIN. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1905 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1906 sp->ts_state = STATE_DEL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1907 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1908 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1909 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1910 sp->ts_state = STATE_PLAIN; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1911 // FALLTHROUGH |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1912 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1913 case STATE_PLAIN: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1914 // Go over all possible bytes at this node, add each to tword[] |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1915 // and use child node. "ts_curi" is the index. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1916 arridx = sp->ts_arridx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1917 if (sp->ts_curi > byts[arridx]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1918 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1919 // Done all bytes at this node, do next state. When still at |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1920 // already changed bytes skip the other tricks. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1921 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1922 if (sp->ts_fidx >= sp->ts_fidxtry) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1923 sp->ts_state = STATE_DEL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1924 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1925 sp->ts_state = STATE_FINAL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1926 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1927 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1928 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1929 arridx += sp->ts_curi++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1930 c = byts[arridx]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1931 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1932 // Normal byte, go one level deeper. If it's not equal to the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1933 // byte in the bad word adjust the score. But don't even try |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1934 // when the byte was already changed. And don't try when we |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1935 // just deleted this byte, accepting it is always cheaper than |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1936 // delete + substitute. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1937 if (c == fword[sp->ts_fidx] |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1938 || (sp->ts_tcharlen > 0 && sp->ts_isdiff != DIFF_NONE)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1939 newscore = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1940 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1941 newscore = SCORE_SUBST; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1942 if ((newscore == 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1943 || (sp->ts_fidx >= sp->ts_fidxtry |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1944 && ((sp->ts_flags & TSF_DIDDEL) == 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1945 || c != fword[sp->ts_delidx]))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1946 && TRY_DEEPER(su, stack, depth, newscore)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1947 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1948 go_deeper(stack, depth, newscore); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1949 #ifdef DEBUG_TRIEWALK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1950 if (newscore > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1951 sprintf(changename[depth], "%.*s-%s: subst %c to %c", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1952 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1953 fword[sp->ts_fidx], c); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1954 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1955 sprintf(changename[depth], "%.*s-%s: accept %c", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1956 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1957 fword[sp->ts_fidx]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1958 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1959 ++depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1960 sp = &stack[depth]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1961 if (fword[sp->ts_fidx] != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1962 ++sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1963 tword[sp->ts_twordlen++] = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1964 sp->ts_arridx = idxs[arridx]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1965 if (newscore == SCORE_SUBST) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1966 sp->ts_isdiff = DIFF_YES; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1967 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1968 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1969 // Multi-byte characters are a bit complicated to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1970 // handle: They differ when any of the bytes differ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1971 // and then their length may also differ. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1972 if (sp->ts_tcharlen == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1973 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1974 // First byte. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1975 sp->ts_tcharidx = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1976 sp->ts_tcharlen = MB_BYTE2LEN(c); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1977 sp->ts_fcharstart = sp->ts_fidx - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1978 sp->ts_isdiff = (newscore != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1979 ? DIFF_YES : DIFF_NONE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1980 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1981 else if (sp->ts_isdiff == DIFF_INSERT |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1982 && sp->ts_fidx > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1983 // When inserting trail bytes don't advance in the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1984 // bad word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1985 --sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1986 if (++sp->ts_tcharidx == sp->ts_tcharlen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1987 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1988 // Last byte of character. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1989 if (sp->ts_isdiff == DIFF_YES) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1990 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1991 // Correct ts_fidx for the byte length of the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1992 // character (we didn't check that before). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1993 sp->ts_fidx = sp->ts_fcharstart |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1994 + mb_ptr2len( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1995 fword + sp->ts_fcharstart); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1996 // For changing a composing character adjust |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1997 // the score from SCORE_SUBST to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1998 // SCORE_SUBCOMP. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
1999 if (enc_utf8 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2000 && utf_iscomposing( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2001 utf_ptr2char(tword |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2002 + sp->ts_twordlen |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2003 - sp->ts_tcharlen)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2004 && utf_iscomposing( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2005 utf_ptr2char(fword |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2006 + sp->ts_fcharstart))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2007 sp->ts_score -= |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2008 SCORE_SUBST - SCORE_SUBCOMP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2009 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2010 // For a similar character adjust score from |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2011 // SCORE_SUBST to SCORE_SIMILAR. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2012 else if (!soundfold |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2013 && slang->sl_has_map |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2014 && similar_chars(slang, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2015 mb_ptr2char(tword |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2016 + sp->ts_twordlen |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2017 - sp->ts_tcharlen), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2018 mb_ptr2char(fword |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2019 + sp->ts_fcharstart))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2020 sp->ts_score -= |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2021 SCORE_SUBST - SCORE_SIMILAR; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2022 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2023 else if (sp->ts_isdiff == DIFF_INSERT |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2024 && sp->ts_twordlen > sp->ts_tcharlen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2025 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2026 p = tword + sp->ts_twordlen - sp->ts_tcharlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2027 c = mb_ptr2char(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2028 if (enc_utf8 && utf_iscomposing(c)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2029 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2030 // Inserting a composing char doesn't |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2031 // count that much. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2032 sp->ts_score -= SCORE_INS - SCORE_INSCOMP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2033 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2034 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2035 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2036 // If the previous character was the same, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2037 // thus doubling a character, give a bonus |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2038 // to the score. Also for the soundfold |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2039 // tree (might seem illogical but does |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2040 // give better scores). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2041 MB_PTR_BACK(tword, p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2042 if (c == mb_ptr2char(p)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2043 sp->ts_score -= SCORE_INS |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2044 - SCORE_INSDUP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2045 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2046 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2047 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2048 // Starting a new char, reset the length. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2049 sp->ts_tcharlen = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2050 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2051 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2052 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2053 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2054 // If we found a similar char adjust the score. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2055 // We do this after calling go_deeper() because |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2056 // it's slow. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2057 if (newscore != 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2058 && !soundfold |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2059 && slang->sl_has_map |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2060 && similar_chars(slang, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2061 c, fword[sp->ts_fidx - 1])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2062 sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2063 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2064 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2065 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2066 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2067 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2068 case STATE_DEL: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2069 // When past the first byte of a multi-byte char don't try |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2070 // delete/insert/swap a character. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2071 if (has_mbyte && sp->ts_tcharlen > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2072 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2073 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2074 sp->ts_state = STATE_FINAL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2075 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2076 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2077 // Try skipping one character in the bad word (delete it). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2078 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2079 sp->ts_state = STATE_INS_PREP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2080 sp->ts_curi = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2081 if (soundfold && sp->ts_fidx == 0 && fword[sp->ts_fidx] == '*') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2082 // Deleting a vowel at the start of a word counts less, see |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2083 // soundalike_score(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2084 newscore = 2 * SCORE_DEL / 3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2085 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2086 newscore = SCORE_DEL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2087 if (fword[sp->ts_fidx] != NUL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2088 && TRY_DEEPER(su, stack, depth, newscore)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2089 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2090 go_deeper(stack, depth, newscore); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2091 #ifdef DEBUG_TRIEWALK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2092 sprintf(changename[depth], "%.*s-%s: delete %c", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2093 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2094 fword[sp->ts_fidx]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2095 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2096 ++depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2097 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2098 // Remember what character we deleted, so that we can avoid |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2099 // inserting it again. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2100 stack[depth].ts_flags |= TSF_DIDDEL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2101 stack[depth].ts_delidx = sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2102 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2103 // Advance over the character in fword[]. Give a bonus to the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2104 // score if the same character is following "nn" -> "n". It's |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2105 // a bit illogical for soundfold tree but it does give better |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2106 // results. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2107 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2108 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2109 c = mb_ptr2char(fword + sp->ts_fidx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2110 stack[depth].ts_fidx += mb_ptr2len(fword + sp->ts_fidx); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2111 if (enc_utf8 && utf_iscomposing(c)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2112 stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2113 else if (c == mb_ptr2char(fword + stack[depth].ts_fidx)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2114 stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2115 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2116 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2117 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2118 ++stack[depth].ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2119 if (fword[sp->ts_fidx] == fword[sp->ts_fidx + 1]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2120 stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2121 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2122 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2123 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2124 // FALLTHROUGH |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2125 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2126 case STATE_INS_PREP: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2127 if (sp->ts_flags & TSF_DIDDEL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2128 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2129 // If we just deleted a byte then inserting won't make sense, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2130 // a substitute is always cheaper. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2131 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2132 sp->ts_state = STATE_SWAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2133 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2134 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2135 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2136 // skip over NUL bytes |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2137 n = sp->ts_arridx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2138 for (;;) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2139 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2140 if (sp->ts_curi > byts[n]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2141 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2142 // Only NUL bytes at this node, go to next state. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2143 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2144 sp->ts_state = STATE_SWAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2145 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2146 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2147 if (byts[n + sp->ts_curi] != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2148 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2149 // Found a byte to insert. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2150 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2151 sp->ts_state = STATE_INS; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2152 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2153 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2154 ++sp->ts_curi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2155 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2156 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2157 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2158 // FALLTHROUGH |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2159 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2160 case STATE_INS: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2161 // Insert one byte. Repeat this for each possible byte at this |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2162 // node. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2163 n = sp->ts_arridx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2164 if (sp->ts_curi > byts[n]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2165 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2166 // Done all bytes at this node, go to next state. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2167 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2168 sp->ts_state = STATE_SWAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2169 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2170 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2171 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2172 // Do one more byte at this node, but: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2173 // - Skip NUL bytes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2174 // - Skip the byte if it's equal to the byte in the word, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2175 // accepting that byte is always better. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2176 n += sp->ts_curi++; |
33863
3b8089d550eb
patch 9.0.2141: [security]: buffer-overflow in suggest_trie_walk
Christian Brabandt <cb@256bit.org>
parents:
33399
diff
changeset
|
2177 |
3b8089d550eb
patch 9.0.2141: [security]: buffer-overflow in suggest_trie_walk
Christian Brabandt <cb@256bit.org>
parents:
33399
diff
changeset
|
2178 // break out, if we would be accessing byts buffer out of bounds |
3b8089d550eb
patch 9.0.2141: [security]: buffer-overflow in suggest_trie_walk
Christian Brabandt <cb@256bit.org>
parents:
33399
diff
changeset
|
2179 if (byts == slang->sl_fbyts && n >= slang->sl_fbyts_len) |
3b8089d550eb
patch 9.0.2141: [security]: buffer-overflow in suggest_trie_walk
Christian Brabandt <cb@256bit.org>
parents:
33399
diff
changeset
|
2180 { |
3b8089d550eb
patch 9.0.2141: [security]: buffer-overflow in suggest_trie_walk
Christian Brabandt <cb@256bit.org>
parents:
33399
diff
changeset
|
2181 got_int = TRUE; |
3b8089d550eb
patch 9.0.2141: [security]: buffer-overflow in suggest_trie_walk
Christian Brabandt <cb@256bit.org>
parents:
33399
diff
changeset
|
2182 break; |
3b8089d550eb
patch 9.0.2141: [security]: buffer-overflow in suggest_trie_walk
Christian Brabandt <cb@256bit.org>
parents:
33399
diff
changeset
|
2183 } |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2184 c = byts[n]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2185 if (soundfold && sp->ts_twordlen == 0 && c == '*') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2186 // Inserting a vowel at the start of a word counts less, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2187 // see soundalike_score(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2188 newscore = 2 * SCORE_INS / 3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2189 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2190 newscore = SCORE_INS; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2191 if (c != fword[sp->ts_fidx] |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2192 && TRY_DEEPER(su, stack, depth, newscore)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2193 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2194 go_deeper(stack, depth, newscore); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2195 #ifdef DEBUG_TRIEWALK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2196 sprintf(changename[depth], "%.*s-%s: insert %c", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2197 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2198 c); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2199 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2200 ++depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2201 sp = &stack[depth]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2202 tword[sp->ts_twordlen++] = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2203 sp->ts_arridx = idxs[n]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2204 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2205 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2206 fl = MB_BYTE2LEN(c); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2207 if (fl > 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2208 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2209 // There are following bytes for the same character. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2210 // We must find all bytes before trying |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2211 // delete/insert/swap/etc. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2212 sp->ts_tcharlen = fl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2213 sp->ts_tcharidx = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2214 sp->ts_isdiff = DIFF_INSERT; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2215 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2216 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2217 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2218 fl = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2219 if (fl == 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2220 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2221 // If the previous character was the same, thus doubling a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2222 // character, give a bonus to the score. Also for |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2223 // soundfold words (illogical but does give a better |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2224 // score). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2225 if (sp->ts_twordlen >= 2 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2226 && tword[sp->ts_twordlen - 2] == c) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2227 sp->ts_score -= SCORE_INS - SCORE_INSDUP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2228 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2229 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2230 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2231 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2232 case STATE_SWAP: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2233 // Swap two bytes in the bad word: "12" -> "21". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2234 // We change "fword" here, it's changed back afterwards at |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2235 // STATE_UNSWAP. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2236 p = fword + sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2237 c = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2238 if (c == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2239 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2240 // End of word, can't swap or replace. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2241 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2242 sp->ts_state = STATE_FINAL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2243 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2244 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2245 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2246 // Don't swap if the first character is not a word character. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2247 // SWAP3 etc. also don't make sense then. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2248 if (!soundfold && !spell_iswordp(p, curwin)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2249 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2250 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2251 sp->ts_state = STATE_REP_INI; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2252 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2253 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2254 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2255 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2256 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2257 n = MB_CPTR2LEN(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2258 c = mb_ptr2char(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2259 if (p[n] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2260 c2 = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2261 else if (!soundfold && !spell_iswordp(p + n, curwin)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2262 c2 = c; // don't swap non-word char |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2263 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2264 c2 = mb_ptr2char(p + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2265 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2266 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2267 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2268 if (p[1] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2269 c2 = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2270 else if (!soundfold && !spell_iswordp(p + 1, curwin)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2271 c2 = c; // don't swap non-word char |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2272 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2273 c2 = p[1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2274 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2275 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2276 // When the second character is NUL we can't swap. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2277 if (c2 == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2278 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2279 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2280 sp->ts_state = STATE_REP_INI; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2281 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2282 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2283 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2284 // When characters are identical, swap won't do anything. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2285 // Also get here if the second char is not a word character. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2286 if (c == c2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2287 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2288 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2289 sp->ts_state = STATE_SWAP3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2290 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2291 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2292 if (c2 != NUL && TRY_DEEPER(su, stack, depth, SCORE_SWAP)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2293 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2294 go_deeper(stack, depth, SCORE_SWAP); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2295 #ifdef DEBUG_TRIEWALK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2296 sprintf(changename[depth], "%.*s-%s: swap %c and %c", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2297 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2298 c, c2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2299 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2300 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2301 sp->ts_state = STATE_UNSWAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2302 ++depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2303 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2304 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2305 fl = mb_char2len(c2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2306 mch_memmove(p, p + n, fl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2307 mb_char2bytes(c, p + fl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2308 stack[depth].ts_fidxtry = sp->ts_fidx + n + fl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2309 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2310 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2311 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2312 p[0] = c2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2313 p[1] = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2314 stack[depth].ts_fidxtry = sp->ts_fidx + 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2315 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2316 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2317 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2318 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2319 // If this swap doesn't work then SWAP3 won't either. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2320 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2321 sp->ts_state = STATE_REP_INI; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2322 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2323 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2324 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2325 case STATE_UNSWAP: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2326 // Undo the STATE_SWAP swap: "21" -> "12". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2327 p = fword + sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2328 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2329 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2330 n = mb_ptr2len(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2331 c = mb_ptr2char(p + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2332 mch_memmove(p + mb_ptr2len(p + n), p, n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2333 mb_char2bytes(c, p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2334 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2335 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2336 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2337 c = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2338 *p = p[1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2339 p[1] = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2340 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2341 // FALLTHROUGH |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2342 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2343 case STATE_SWAP3: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2344 // Swap two bytes, skipping one: "123" -> "321". We change |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2345 // "fword" here, it's changed back afterwards at STATE_UNSWAP3. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2346 p = fword + sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2347 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2348 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2349 n = MB_CPTR2LEN(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2350 c = mb_ptr2char(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2351 fl = MB_CPTR2LEN(p + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2352 c2 = mb_ptr2char(p + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2353 if (!soundfold && !spell_iswordp(p + n + fl, curwin)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2354 c3 = c; // don't swap non-word char |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2355 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2356 c3 = mb_ptr2char(p + n + fl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2357 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2358 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2359 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2360 c = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2361 c2 = p[1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2362 if (!soundfold && !spell_iswordp(p + 2, curwin)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2363 c3 = c; // don't swap non-word char |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2364 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2365 c3 = p[2]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2366 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2367 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2368 // When characters are identical: "121" then SWAP3 result is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2369 // identical, ROT3L result is same as SWAP: "211", ROT3L result is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2370 // same as SWAP on next char: "112". Thus skip all swapping. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2371 // Also skip when c3 is NUL. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2372 // Also get here when the third character is not a word character. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2373 // Second character may any char: "a.b" -> "b.a" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2374 if (c == c3 || c3 == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2375 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2376 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2377 sp->ts_state = STATE_REP_INI; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2378 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2379 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2380 if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2381 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2382 go_deeper(stack, depth, SCORE_SWAP3); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2383 #ifdef DEBUG_TRIEWALK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2384 sprintf(changename[depth], "%.*s-%s: swap3 %c and %c", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2385 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2386 c, c3); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2387 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2388 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2389 sp->ts_state = STATE_UNSWAP3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2390 ++depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2391 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2392 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2393 tl = mb_char2len(c3); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2394 mch_memmove(p, p + n + fl, tl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2395 mb_char2bytes(c2, p + tl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2396 mb_char2bytes(c, p + fl + tl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2397 stack[depth].ts_fidxtry = sp->ts_fidx + n + fl + tl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2398 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2399 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2400 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2401 p[0] = p[2]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2402 p[2] = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2403 stack[depth].ts_fidxtry = sp->ts_fidx + 3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2404 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2405 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2406 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2407 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2408 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2409 sp->ts_state = STATE_REP_INI; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2410 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2411 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2412 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2413 case STATE_UNSWAP3: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2414 // Undo STATE_SWAP3: "321" -> "123" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2415 p = fword + sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2416 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2417 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2418 n = mb_ptr2len(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2419 c2 = mb_ptr2char(p + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2420 fl = mb_ptr2len(p + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2421 c = mb_ptr2char(p + n + fl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2422 tl = mb_ptr2len(p + n + fl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2423 mch_memmove(p + fl + tl, p, n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2424 mb_char2bytes(c, p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2425 mb_char2bytes(c2, p + tl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2426 p = p + tl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2427 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2428 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2429 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2430 c = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2431 *p = p[2]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2432 p[2] = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2433 ++p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2434 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2435 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2436 if (!soundfold && !spell_iswordp(p, curwin)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2437 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2438 // Middle char is not a word char, skip the rotate. First and |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2439 // third char were already checked at swap and swap3. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2440 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2441 sp->ts_state = STATE_REP_INI; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2442 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2443 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2444 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2445 // Rotate three characters left: "123" -> "231". We change |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2446 // "fword" here, it's changed back afterwards at STATE_UNROT3L. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2447 if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2448 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2449 go_deeper(stack, depth, SCORE_SWAP3); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2450 #ifdef DEBUG_TRIEWALK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2451 p = fword + sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2452 sprintf(changename[depth], "%.*s-%s: rotate left %c%c%c", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2453 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2454 p[0], p[1], p[2]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2455 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2456 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2457 sp->ts_state = STATE_UNROT3L; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2458 ++depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2459 p = fword + sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2460 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2461 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2462 n = MB_CPTR2LEN(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2463 c = mb_ptr2char(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2464 fl = MB_CPTR2LEN(p + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2465 fl += MB_CPTR2LEN(p + n + fl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2466 mch_memmove(p, p + n, fl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2467 mb_char2bytes(c, p + fl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2468 stack[depth].ts_fidxtry = sp->ts_fidx + n + fl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2469 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2470 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2471 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2472 c = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2473 *p = p[1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2474 p[1] = p[2]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2475 p[2] = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2476 stack[depth].ts_fidxtry = sp->ts_fidx + 3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2477 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2478 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2479 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2480 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2481 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2482 sp->ts_state = STATE_REP_INI; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2483 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2484 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2485 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2486 case STATE_UNROT3L: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2487 // Undo ROT3L: "231" -> "123" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2488 p = fword + sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2489 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2490 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2491 n = mb_ptr2len(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2492 n += mb_ptr2len(p + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2493 c = mb_ptr2char(p + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2494 tl = mb_ptr2len(p + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2495 mch_memmove(p + tl, p, n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2496 mb_char2bytes(c, p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2497 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2498 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2499 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2500 c = p[2]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2501 p[2] = p[1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2502 p[1] = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2503 *p = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2504 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2505 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2506 // Rotate three bytes right: "123" -> "312". We change "fword" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2507 // here, it's changed back afterwards at STATE_UNROT3R. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2508 if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2509 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2510 go_deeper(stack, depth, SCORE_SWAP3); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2511 #ifdef DEBUG_TRIEWALK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2512 p = fword + sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2513 sprintf(changename[depth], "%.*s-%s: rotate right %c%c%c", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2514 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2515 p[0], p[1], p[2]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2516 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2517 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2518 sp->ts_state = STATE_UNROT3R; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2519 ++depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2520 p = fword + sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2521 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2522 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2523 n = MB_CPTR2LEN(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2524 n += MB_CPTR2LEN(p + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2525 c = mb_ptr2char(p + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2526 tl = MB_CPTR2LEN(p + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2527 mch_memmove(p + tl, p, n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2528 mb_char2bytes(c, p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2529 stack[depth].ts_fidxtry = sp->ts_fidx + n + tl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2530 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2531 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2532 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2533 c = p[2]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2534 p[2] = p[1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2535 p[1] = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2536 *p = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2537 stack[depth].ts_fidxtry = sp->ts_fidx + 3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2538 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2539 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2540 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2541 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2542 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2543 sp->ts_state = STATE_REP_INI; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2544 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2545 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2546 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2547 case STATE_UNROT3R: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2548 // Undo ROT3R: "312" -> "123" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2549 p = fword + sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2550 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2551 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2552 c = mb_ptr2char(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2553 tl = mb_ptr2len(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2554 n = mb_ptr2len(p + tl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2555 n += mb_ptr2len(p + tl + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2556 mch_memmove(p, p + tl, n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2557 mb_char2bytes(c, p + n); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2558 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2559 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2560 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2561 c = *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2562 *p = p[1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2563 p[1] = p[2]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2564 p[2] = c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2565 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2566 // FALLTHROUGH |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2567 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2568 case STATE_REP_INI: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2569 // Check if matching with REP items from the .aff file would work. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2570 // Quickly skip if: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2571 // - there are no REP items and we are not in the soundfold trie |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2572 // - the score is going to be too high anyway |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2573 // - already applied a REP item or swapped here |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2574 if ((lp->lp_replang == NULL && !soundfold) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2575 || sp->ts_score + SCORE_REP >= su->su_maxscore |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2576 || sp->ts_fidx < sp->ts_fidxtry) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2577 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2578 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2579 sp->ts_state = STATE_FINAL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2580 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2581 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2582 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2583 // Use the first byte to quickly find the first entry that may |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2584 // match. If the index is -1 there is none. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2585 if (soundfold) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2586 sp->ts_curi = slang->sl_repsal_first[fword[sp->ts_fidx]]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2587 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2588 sp->ts_curi = lp->lp_replang->sl_rep_first[fword[sp->ts_fidx]]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2589 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2590 if (sp->ts_curi < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2591 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2592 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2593 sp->ts_state = STATE_FINAL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2594 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2595 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2596 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2597 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2598 sp->ts_state = STATE_REP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2599 // FALLTHROUGH |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2600 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2601 case STATE_REP: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2602 // Try matching with REP items from the .aff file. For each match |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2603 // replace the characters and check if the resulting word is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2604 // valid. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2605 p = fword + sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2606 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2607 if (soundfold) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2608 gap = &slang->sl_repsal; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2609 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2610 gap = &lp->lp_replang->sl_rep; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2611 while (sp->ts_curi < gap->ga_len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2612 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2613 ftp = (fromto_T *)gap->ga_data + sp->ts_curi++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2614 if (*ftp->ft_from != *p) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2615 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2616 // past possible matching entries |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2617 sp->ts_curi = gap->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2618 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2619 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2620 if (STRNCMP(ftp->ft_from, p, STRLEN(ftp->ft_from)) == 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2621 && TRY_DEEPER(su, stack, depth, SCORE_REP)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2622 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2623 go_deeper(stack, depth, SCORE_REP); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2624 #ifdef DEBUG_TRIEWALK |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2625 sprintf(changename[depth], "%.*s-%s: replace %s with %s", |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2626 sp->ts_twordlen, tword, fword + sp->ts_fidx, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2627 ftp->ft_from, ftp->ft_to); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2628 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2629 // Need to undo this afterwards. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2630 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2631 sp->ts_state = STATE_REP_UNDO; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2632 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2633 // Change the "from" to the "to" string. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2634 ++depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2635 fl = (int)STRLEN(ftp->ft_from); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2636 tl = (int)STRLEN(ftp->ft_to); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2637 if (fl != tl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2638 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2639 STRMOVE(p + tl, p + fl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2640 repextra += tl - fl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2641 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2642 mch_memmove(p, ftp->ft_to, tl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2643 stack[depth].ts_fidxtry = sp->ts_fidx + tl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2644 stack[depth].ts_tcharlen = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2645 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2646 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2647 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2648 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2649 if (sp->ts_curi >= gap->ga_len && sp->ts_state == STATE_REP) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2650 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2651 // No (more) matches. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2652 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2653 sp->ts_state = STATE_FINAL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2654 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2655 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2656 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2657 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2658 case STATE_REP_UNDO: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2659 // Undo a REP replacement and continue with the next one. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2660 if (soundfold) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2661 gap = &slang->sl_repsal; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2662 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2663 gap = &lp->lp_replang->sl_rep; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2664 ftp = (fromto_T *)gap->ga_data + sp->ts_curi - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2665 fl = (int)STRLEN(ftp->ft_from); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2666 tl = (int)STRLEN(ftp->ft_to); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2667 p = fword + sp->ts_fidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2668 if (fl != tl) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2669 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2670 STRMOVE(p + fl, p + tl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2671 repextra -= tl - fl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2672 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2673 mch_memmove(p, ftp->ft_from, fl); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2674 PROF_STORE(sp->ts_state) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2675 sp->ts_state = STATE_REP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2676 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2677 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2678 default: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2679 // Did all possible states at this level, go up one level. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2680 --depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2681 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2682 if (depth >= 0 && stack[depth].ts_prefixdepth == PFD_PREFIXTREE) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2683 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2684 // Continue in or go back to the prefix tree. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2685 byts = pbyts; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2686 idxs = pidxs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2687 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2688 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2689 // Don't check for CTRL-C too often, it takes time. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2690 if (--breakcheckcount == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2691 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2692 ui_breakcheck(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2693 breakcheckcount = 1000; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2694 #ifdef FEAT_RELTIME |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2695 if (spell_suggest_timeout > 0 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2696 && profile_passed_limit(&time_limit)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2697 got_int = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2698 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2699 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2700 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2701 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2702 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2703 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2704 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2705 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2706 * Go one level deeper in the tree. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2707 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2708 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2709 go_deeper(trystate_T *stack, int depth, int score_add) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2710 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2711 stack[depth + 1] = stack[depth]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2712 stack[depth + 1].ts_state = STATE_START; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2713 stack[depth + 1].ts_score = stack[depth].ts_score + score_add; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2714 stack[depth + 1].ts_curi = 1; // start just after length byte |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2715 stack[depth + 1].ts_flags = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2716 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2717 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2718 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2719 * "fword" is a good word with case folded. Find the matching keep-case |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2720 * words and put it in "kword". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2721 * Theoretically there could be several keep-case words that result in the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2722 * same case-folded word, but we only find one... |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2723 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2724 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2725 find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2726 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2727 char_u uword[MAXWLEN]; // "fword" in upper-case |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2728 int depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2729 idx_T tryidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2730 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2731 // The following arrays are used at each depth in the tree. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2732 idx_T arridx[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2733 int round[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2734 int fwordidx[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2735 int uwordidx[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2736 int kwordlen[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2737 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2738 int flen, ulen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2739 int l; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2740 int len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2741 int c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2742 idx_T lo, hi, m; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2743 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2744 char_u *byts = slang->sl_kbyts; // array with bytes of the words |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2745 idx_T *idxs = slang->sl_kidxs; // array with indexes |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2746 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2747 if (byts == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2748 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2749 // array is empty: "cannot happen" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2750 *kword = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2751 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2752 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2753 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2754 // Make an all-cap version of "fword". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2755 allcap_copy(fword, uword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2756 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2757 // Each character needs to be tried both case-folded and upper-case. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2758 // All this gets very complicated if we keep in mind that changing case |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2759 // may change the byte length of a multi-byte character... |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2760 depth = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2761 arridx[0] = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2762 round[0] = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2763 fwordidx[0] = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2764 uwordidx[0] = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2765 kwordlen[0] = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2766 while (depth >= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2767 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2768 if (fword[fwordidx[depth]] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2769 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2770 // We are at the end of "fword". If the tree allows a word to end |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2771 // here we have found a match. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2772 if (byts[arridx[depth] + 1] == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2773 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2774 kword[kwordlen[depth]] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2775 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2776 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2777 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2778 // kword is getting too long, continue one level up |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2779 --depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2780 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2781 else if (++round[depth] > 2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2782 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2783 // tried both fold-case and upper-case character, continue one |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2784 // level up |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2785 --depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2786 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2787 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2788 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2789 // round[depth] == 1: Try using the folded-case character. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2790 // round[depth] == 2: Try using the upper-case character. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2791 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2792 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2793 flen = MB_CPTR2LEN(fword + fwordidx[depth]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2794 ulen = MB_CPTR2LEN(uword + uwordidx[depth]); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2795 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2796 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2797 ulen = flen = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2798 if (round[depth] == 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2799 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2800 p = fword + fwordidx[depth]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2801 l = flen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2802 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2803 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2804 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2805 p = uword + uwordidx[depth]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2806 l = ulen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2807 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2808 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2809 for (tryidx = arridx[depth]; l > 0; --l) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2810 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2811 // Perform a binary search in the list of accepted bytes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2812 len = byts[tryidx++]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2813 c = *p++; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2814 lo = tryidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2815 hi = tryidx + len - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2816 while (lo < hi) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2817 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2818 m = (lo + hi) / 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2819 if (byts[m] > c) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2820 hi = m - 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2821 else if (byts[m] < c) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2822 lo = m + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2823 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2824 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2825 lo = hi = m; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2826 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2827 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2828 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2829 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2830 // Stop if there is no matching byte. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2831 if (hi < lo || byts[lo] != c) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2832 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2833 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2834 // Continue at the child (if there is one). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2835 tryidx = idxs[lo]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2836 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2837 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2838 if (l == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2839 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2840 // Found the matching char. Copy it to "kword" and go a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2841 // level deeper. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2842 if (round[depth] == 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2843 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2844 STRNCPY(kword + kwordlen[depth], fword + fwordidx[depth], |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2845 flen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2846 kwordlen[depth + 1] = kwordlen[depth] + flen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2847 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2848 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2849 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2850 STRNCPY(kword + kwordlen[depth], uword + uwordidx[depth], |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2851 ulen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2852 kwordlen[depth + 1] = kwordlen[depth] + ulen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2853 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2854 fwordidx[depth + 1] = fwordidx[depth] + flen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2855 uwordidx[depth + 1] = uwordidx[depth] + ulen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2856 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2857 ++depth; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2858 arridx[depth] = tryidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2859 round[depth] = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2860 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2861 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2862 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2863 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2864 // Didn't find it: "cannot happen". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2865 *kword = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2866 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2867 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2868 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2869 * Compute the sound-a-like score for suggestions in su->su_ga and add them to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2870 * su->su_sga. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2871 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2872 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2873 score_comp_sal(suginfo_T *su) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2874 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2875 langp_T *lp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2876 char_u badsound[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2877 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2878 suggest_T *stp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2879 suggest_T *sstp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2880 int score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2881 int lpi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2882 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2883 if (ga_grow(&su->su_sga, su->su_ga.ga_len) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2884 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2885 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2886 // Use the sound-folding of the first language that supports it. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2887 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2888 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2889 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2890 if (lp->lp_slang->sl_sal.ga_len > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2891 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2892 // soundfold the bad word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2893 spell_soundfold(lp->lp_slang, su->su_fbadword, TRUE, badsound); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2894 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2895 for (i = 0; i < su->su_ga.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2896 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2897 stp = &SUG(su->su_ga, i); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2898 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2899 // Case-fold the suggested word, sound-fold it and compute the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2900 // sound-a-like score. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2901 score = stp_sal_score(stp, su, lp->lp_slang, badsound); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2902 if (score < SCORE_MAXMAX) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2903 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2904 // Add the suggestion. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2905 sstp = &SUG(su->su_sga, su->su_sga.ga_len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2906 sstp->st_word = vim_strsave(stp->st_word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2907 if (sstp->st_word != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2908 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2909 sstp->st_wordlen = stp->st_wordlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2910 sstp->st_score = score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2911 sstp->st_altscore = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2912 sstp->st_orglen = stp->st_orglen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2913 ++su->su_sga.ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2914 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2915 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2916 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2917 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2918 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2919 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2920 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2921 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2922 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2923 * Combine the list of suggestions in su->su_ga and su->su_sga. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2924 * They are entwined. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2925 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2926 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2927 score_combine(suginfo_T *su) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2928 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2929 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2930 int j; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2931 garray_T ga; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2932 garray_T *gap; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2933 langp_T *lp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2934 suggest_T *stp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2935 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2936 char_u badsound[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2937 int round; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2938 int lpi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2939 slang_T *slang = NULL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2940 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2941 // Add the alternate score to su_ga. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2942 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2943 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2944 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2945 if (lp->lp_slang->sl_sal.ga_len > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2946 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2947 // soundfold the bad word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2948 slang = lp->lp_slang; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2949 spell_soundfold(slang, su->su_fbadword, TRUE, badsound); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2950 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2951 for (i = 0; i < su->su_ga.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2952 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2953 stp = &SUG(su->su_ga, i); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2954 stp->st_altscore = stp_sal_score(stp, su, slang, badsound); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2955 if (stp->st_altscore == SCORE_MAXMAX) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2956 stp->st_score = (stp->st_score * 3 + SCORE_BIG) / 4; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2957 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2958 stp->st_score = (stp->st_score * 3 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2959 + stp->st_altscore) / 4; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2960 stp->st_salscore = FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2961 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2962 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2963 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2964 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2965 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2966 if (slang == NULL) // Using "double" without sound folding. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2967 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2968 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2969 su->su_maxcount); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2970 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2971 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2972 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2973 // Add the alternate score to su_sga. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2974 for (i = 0; i < su->su_sga.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2975 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2976 stp = &SUG(su->su_sga, i); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2977 stp->st_altscore = spell_edit_score(slang, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2978 su->su_badword, stp->st_word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2979 if (stp->st_score == SCORE_MAXMAX) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2980 stp->st_score = (SCORE_BIG * 7 + stp->st_altscore) / 8; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2981 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2982 stp->st_score = (stp->st_score * 7 + stp->st_altscore) / 8; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2983 stp->st_salscore = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2984 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2985 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2986 // Remove bad suggestions, sort the suggestions and truncate at "maxcount" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2987 // for both lists. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2988 check_suggestions(su, &su->su_ga); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2989 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, su->su_maxcount); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2990 check_suggestions(su, &su->su_sga); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2991 (void)cleanup_suggestions(&su->su_sga, su->su_maxscore, su->su_maxcount); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2992 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2993 ga_init2(&ga, sizeof(suginfo_T), 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2994 if (ga_grow(&ga, su->su_ga.ga_len + su->su_sga.ga_len) == FAIL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2995 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2996 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2997 stp = &SUG(ga, 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2998 for (i = 0; i < su->su_ga.ga_len || i < su->su_sga.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
2999 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3000 // round 1: get a suggestion from su_ga |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3001 // round 2: get a suggestion from su_sga |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3002 for (round = 1; round <= 2; ++round) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3003 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3004 gap = round == 1 ? &su->su_ga : &su->su_sga; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3005 if (i < gap->ga_len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3006 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3007 // Don't add a word if it's already there. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3008 p = SUG(*gap, i).st_word; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3009 for (j = 0; j < ga.ga_len; ++j) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3010 if (STRCMP(stp[j].st_word, p) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3011 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3012 if (j == ga.ga_len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3013 stp[ga.ga_len++] = SUG(*gap, i); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3014 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3015 vim_free(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3016 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3017 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3018 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3019 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3020 ga_clear(&su->su_ga); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3021 ga_clear(&su->su_sga); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3022 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3023 // Truncate the list to the number of suggestions that will be displayed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3024 if (ga.ga_len > su->su_maxcount) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3025 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3026 for (i = su->su_maxcount; i < ga.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3027 vim_free(stp[i].st_word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3028 ga.ga_len = su->su_maxcount; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3029 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3030 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3031 su->su_ga = ga; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3032 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3033 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3034 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3035 * For the goodword in "stp" compute the soundalike score compared to the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3036 * badword. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3037 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3038 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3039 stp_sal_score( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3040 suggest_T *stp, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3041 suginfo_T *su, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3042 slang_T *slang, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3043 char_u *badsound) // sound-folded badword |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3044 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3045 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3046 char_u *pbad; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3047 char_u *pgood; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3048 char_u badsound2[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3049 char_u fword[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3050 char_u goodsound[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3051 char_u goodword[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3052 int lendiff; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3053 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3054 lendiff = (int)(su->su_badlen - stp->st_orglen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3055 if (lendiff >= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3056 pbad = badsound; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3057 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3058 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3059 // soundfold the bad word with more characters following |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3060 (void)spell_casefold(curwin, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3061 su->su_badptr, stp->st_orglen, fword, MAXWLEN); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3062 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3063 // When joining two words the sound often changes a lot. E.g., "t he" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3064 // sounds like "t h" while "the" sounds like "@". Avoid that by |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3065 // removing the space. Don't do it when the good word also contains a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3066 // space. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3067 if (VIM_ISWHITE(su->su_badptr[su->su_badlen]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3068 && *skiptowhite(stp->st_word) == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3069 for (p = fword; *(p = skiptowhite(p)) != NUL; ) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3070 STRMOVE(p, p + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3071 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3072 spell_soundfold(slang, fword, TRUE, badsound2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3073 pbad = badsound2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3074 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3075 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3076 if (lendiff > 0 && stp->st_wordlen + lendiff < MAXWLEN) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3077 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3078 // Add part of the bad word to the good word, so that we soundfold |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3079 // what replaces the bad word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3080 STRCPY(goodword, stp->st_word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3081 vim_strncpy(goodword + stp->st_wordlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3082 su->su_badptr + su->su_badlen - lendiff, lendiff); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3083 pgood = goodword; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3084 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3085 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3086 pgood = stp->st_word; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3087 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3088 // Sound-fold the word and compute the score for the difference. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3089 spell_soundfold(slang, pgood, FALSE, goodsound); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3090 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3091 return soundalike_score(goodsound, pbad); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3092 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3093 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3094 // structure used to store soundfolded words that add_sound_suggest() has |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3095 // handled already. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3096 typedef struct |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3097 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3098 short sft_score; // lowest score used |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3099 char_u sft_word[1]; // soundfolded word, actually longer |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3100 } sftword_T; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3101 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3102 static sftword_T dumsft; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3103 #define HIKEY2SFT(p) ((sftword_T *)((p) - (dumsft.sft_word - (char_u *)&dumsft))) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3104 #define HI2SFT(hi) HIKEY2SFT((hi)->hi_key) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3105 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3106 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3107 * Prepare for calling suggest_try_soundalike(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3108 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3109 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3110 suggest_try_soundalike_prep(void) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3111 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3112 langp_T *lp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3113 int lpi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3114 slang_T *slang; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3115 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3116 // Do this for all languages that support sound folding and for which a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3117 // .sug file has been loaded. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3118 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3119 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3120 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3121 slang = lp->lp_slang; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3122 if (slang->sl_sal.ga_len > 0 && slang->sl_sbyts != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3123 // prepare the hashtable used by add_sound_suggest() |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3124 hash_init(&slang->sl_sounddone); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3125 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3126 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3127 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3128 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3129 * Find suggestions by comparing the word in a sound-a-like form. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3130 * Note: This doesn't support postponed prefixes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3131 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3132 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3133 suggest_try_soundalike(suginfo_T *su) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3134 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3135 char_u salword[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3136 langp_T *lp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3137 int lpi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3138 slang_T *slang; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3139 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3140 // Do this for all languages that support sound folding and for which a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3141 // .sug file has been loaded. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3142 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3143 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3144 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3145 slang = lp->lp_slang; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3146 if (slang->sl_sal.ga_len > 0 && slang->sl_sbyts != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3147 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3148 // soundfold the bad word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3149 spell_soundfold(slang, su->su_fbadword, TRUE, salword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3150 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3151 // try all kinds of inserts/deletes/swaps/etc. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3152 // TODO: also soundfold the next words, so that we can try joining |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3153 // and splitting |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3154 #ifdef SUGGEST_PROFILE |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3155 prof_init(); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3156 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3157 suggest_trie_walk(su, lp, salword, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3158 #ifdef SUGGEST_PROFILE |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3159 prof_report("soundalike"); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3160 #endif |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3161 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3162 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3163 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3164 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3165 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3166 * Finish up after calling suggest_try_soundalike(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3167 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3168 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3169 suggest_try_soundalike_finish(void) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3170 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3171 langp_T *lp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3172 int lpi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3173 slang_T *slang; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3174 int todo; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3175 hashitem_T *hi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3176 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3177 // Do this for all languages that support sound folding and for which a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3178 // .sug file has been loaded. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3179 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3180 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3181 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3182 slang = lp->lp_slang; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3183 if (slang->sl_sal.ga_len > 0 && slang->sl_sbyts != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3184 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3185 // Free the info about handled words. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3186 todo = (int)slang->sl_sounddone.ht_used; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3187 FOR_ALL_HASHTAB_ITEMS(&slang->sl_sounddone, hi, todo) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3188 if (!HASHITEM_EMPTY(hi)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3189 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3190 vim_free(HI2SFT(hi)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3191 --todo; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3192 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3193 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3194 // Clear the hashtable, it may also be used by another region. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3195 hash_clear(&slang->sl_sounddone); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3196 hash_init(&slang->sl_sounddone); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3197 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3198 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3199 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3200 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3201 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3202 * A match with a soundfolded word is found. Add the good word(s) that |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3203 * produce this soundfolded word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3204 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3205 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3206 add_sound_suggest( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3207 suginfo_T *su, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3208 char_u *goodword, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3209 int score, // soundfold score |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3210 langp_T *lp) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3211 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3212 slang_T *slang = lp->lp_slang; // language for sound folding |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3213 int sfwordnr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3214 char_u *nrline; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3215 int orgnr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3216 char_u theword[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3217 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3218 int wlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3219 char_u *byts; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3220 idx_T *idxs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3221 int n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3222 int wordcount; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3223 int wc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3224 int goodscore; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3225 hash_T hash; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3226 hashitem_T *hi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3227 sftword_T *sft; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3228 int bc, gc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3229 int limit; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3230 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3231 // It's very well possible that the same soundfold word is found several |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3232 // times with different scores. Since the following is quite slow only do |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3233 // the words that have a better score than before. Use a hashtable to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3234 // remember the words that have been done. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3235 hash = hash_hash(goodword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3236 hi = hash_lookup(&slang->sl_sounddone, goodword, hash); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3237 if (HASHITEM_EMPTY(hi)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3238 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3239 sft = alloc(offsetof(sftword_T, sft_word) + STRLEN(goodword) + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3240 if (sft != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3241 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3242 sft->sft_score = score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3243 STRCPY(sft->sft_word, goodword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3244 hash_add_item(&slang->sl_sounddone, hi, sft->sft_word, hash); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3245 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3246 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3247 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3248 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3249 sft = HI2SFT(hi); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3250 if (score >= sft->sft_score) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3251 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3252 sft->sft_score = score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3253 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3254 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3255 // Find the word nr in the soundfold tree. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3256 sfwordnr = soundfold_find(slang, goodword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3257 if (sfwordnr < 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3258 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3259 internal_error("add_sound_suggest()"); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3260 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3261 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3262 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3263 // go over the list of good words that produce this soundfold word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3264 nrline = ml_get_buf(slang->sl_sugbuf, (linenr_T)(sfwordnr + 1), FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3265 orgnr = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3266 while (*nrline != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3267 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3268 // The wordnr was stored in a minimal nr of bytes as an offset to the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3269 // previous wordnr. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3270 orgnr += bytes2offset(&nrline); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3271 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3272 byts = slang->sl_fbyts; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3273 idxs = slang->sl_fidxs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3274 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3275 // Lookup the word "orgnr" one of the two tries. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3276 n = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3277 wordcount = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3278 for (wlen = 0; wlen < MAXWLEN - 3; ++wlen) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3279 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3280 i = 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3281 if (wordcount == orgnr && byts[n + 1] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3282 break; // found end of word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3283 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3284 if (byts[n + 1] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3285 ++wordcount; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3286 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3287 // skip over the NUL bytes |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3288 for ( ; byts[n + i] == NUL; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3289 if (i > byts[n]) // safety check |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3290 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3291 STRCPY(theword + wlen, "BAD"); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3292 wlen += 3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3293 goto badword; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3294 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3295 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3296 // One of the siblings must have the word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3297 for ( ; i < byts[n]; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3298 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3299 wc = idxs[idxs[n + i]]; // nr of words under this byte |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3300 if (wordcount + wc > orgnr) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3301 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3302 wordcount += wc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3303 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3304 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3305 theword[wlen] = byts[n + i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3306 n = idxs[n + i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3307 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3308 badword: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3309 theword[wlen] = NUL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3310 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3311 // Go over the possible flags and regions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3312 for (; i <= byts[n] && byts[n + i] == NUL; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3313 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3314 char_u cword[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3315 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3316 int flags = (int)idxs[n + i]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3317 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3318 // Skip words with the NOSUGGEST flag |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3319 if (flags & WF_NOSUGGEST) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3320 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3321 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3322 if (flags & WF_KEEPCAP) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3323 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3324 // Must find the word in the keep-case tree. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3325 find_keepcap_word(slang, theword, cword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3326 p = cword; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3327 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3328 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3329 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3330 flags |= su->su_badflags; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3331 if ((flags & WF_CAPMASK) != 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3332 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3333 // Need to fix case according to "flags". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3334 make_case_word(theword, cword, flags); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3335 p = cword; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3336 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3337 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3338 p = theword; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3339 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3340 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3341 // Add the suggestion. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3342 if (sps_flags & SPS_DOUBLE) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3343 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3344 // Add the suggestion if the score isn't too bad. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3345 if (score <= su->su_maxscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3346 add_suggestion(su, &su->su_sga, p, su->su_badlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3347 score, 0, FALSE, slang, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3348 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3349 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3350 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3351 // Add a penalty for words in another region. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3352 if ((flags & WF_REGION) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3353 && (((unsigned)flags >> 16) & lp->lp_region) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3354 goodscore = SCORE_REGION; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3355 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3356 goodscore = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3357 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3358 // Add a small penalty for changing the first letter from |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3359 // lower to upper case. Helps for "tath" -> "Kath", which is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3360 // less common than "tath" -> "path". Don't do it when the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3361 // letter is the same, that has already been counted. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3362 gc = PTR2CHAR(p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3363 if (SPELL_ISUPPER(gc)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3364 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3365 bc = PTR2CHAR(su->su_badword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3366 if (!SPELL_ISUPPER(bc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3367 && SPELL_TOFOLD(bc) != SPELL_TOFOLD(gc)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3368 goodscore += SCORE_ICASE / 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3369 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3370 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3371 // Compute the score for the good word. This only does letter |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3372 // insert/delete/swap/replace. REP items are not considered, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3373 // which may make the score a bit higher. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3374 // Use a limit for the score to make it work faster. Use |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3375 // MAXSCORE(), because RESCORE() will change the score. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3376 // If the limit is very high then the iterative method is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3377 // inefficient, using an array is quicker. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3378 limit = MAXSCORE(su->su_sfmaxscore - goodscore, score); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3379 if (limit > SCORE_LIMITMAX) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3380 goodscore += spell_edit_score(slang, su->su_badword, p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3381 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3382 goodscore += spell_edit_score_limit(slang, su->su_badword, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3383 p, limit); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3384 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3385 // When going over the limit don't bother to do the rest. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3386 if (goodscore < SCORE_MAXMAX) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3387 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3388 // Give a bonus to words seen before. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3389 goodscore = score_wordcount_adj(slang, goodscore, p, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3390 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3391 // Add the suggestion if the score isn't too bad. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3392 goodscore = RESCORE(goodscore, score); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3393 if (goodscore <= su->su_sfmaxscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3394 add_suggestion(su, &su->su_ga, p, su->su_badlen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3395 goodscore, score, TRUE, slang, TRUE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3396 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3397 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3398 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3399 // smsg("word %s (%d): %s (%d)", sftword, sftnr, theword, orgnr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3400 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3401 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3402 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3403 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3404 * Find word "word" in fold-case tree for "slang" and return the word number. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3405 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3406 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3407 soundfold_find(slang_T *slang, char_u *word) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3408 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3409 idx_T arridx = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3410 int len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3411 int wlen = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3412 int c; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3413 char_u *ptr = word; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3414 char_u *byts; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3415 idx_T *idxs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3416 int wordnr = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3417 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3418 byts = slang->sl_sbyts; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3419 idxs = slang->sl_sidxs; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3420 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3421 for (;;) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3422 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3423 // First byte is the number of possible bytes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3424 len = byts[arridx++]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3425 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3426 // If the first possible byte is a zero the word could end here. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3427 // If the word ends we found the word. If not skip the NUL bytes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3428 c = ptr[wlen]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3429 if (byts[arridx] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3430 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3431 if (c == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3432 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3433 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3434 // Skip over the zeros, there can be several. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3435 while (len > 0 && byts[arridx] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3436 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3437 ++arridx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3438 --len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3439 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3440 if (len == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3441 return -1; // no children, word should have ended here |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3442 ++wordnr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3443 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3444 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3445 // If the word ends we didn't find it. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3446 if (c == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3447 return -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3448 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3449 // Perform a binary search in the list of accepted bytes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3450 if (c == TAB) // <Tab> is handled like <Space> |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3451 c = ' '; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3452 while (byts[arridx] < c) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3453 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3454 // The word count is in the first idxs[] entry of the child. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3455 wordnr += idxs[idxs[arridx]]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3456 ++arridx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3457 if (--len == 0) // end of the bytes, didn't find it |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3458 return -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3459 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3460 if (byts[arridx] != c) // didn't find the byte |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3461 return -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3462 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3463 // Continue at the child (if there is one). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3464 arridx = idxs[arridx]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3465 ++wlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3466 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3467 // One space in the good word may stand for several spaces in the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3468 // checked word. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3469 if (c == ' ') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3470 while (ptr[wlen] == ' ' || ptr[wlen] == TAB) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3471 ++wlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3472 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3473 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3474 return wordnr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3475 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3476 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3477 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3478 * Return TRUE if "c1" and "c2" are similar characters according to the MAP |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3479 * lines in the .aff file. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3480 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3481 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3482 similar_chars(slang_T *slang, int c1, int c2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3483 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3484 int m1, m2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3485 char_u buf[MB_MAXBYTES + 1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3486 hashitem_T *hi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3487 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3488 if (c1 >= 256) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3489 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3490 buf[mb_char2bytes(c1, buf)] = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3491 hi = hash_find(&slang->sl_map_hash, buf); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3492 if (HASHITEM_EMPTY(hi)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3493 m1 = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3494 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3495 m1 = mb_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3496 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3497 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3498 m1 = slang->sl_map_array[c1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3499 if (m1 == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3500 return FALSE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3501 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3502 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3503 if (c2 >= 256) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3504 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3505 buf[mb_char2bytes(c2, buf)] = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3506 hi = hash_find(&slang->sl_map_hash, buf); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3507 if (HASHITEM_EMPTY(hi)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3508 m2 = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3509 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3510 m2 = mb_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3511 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3512 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3513 m2 = slang->sl_map_array[c2]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3514 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3515 return m1 == m2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3516 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3517 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3518 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3519 * Add a suggestion to the list of suggestions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3520 * For a suggestion that is already in the list the lowest score is remembered. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3521 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3522 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3523 add_suggestion( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3524 suginfo_T *su, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3525 garray_T *gap, // either su_ga or su_sga |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3526 char_u *goodword, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3527 int badlenarg, // len of bad word replaced with "goodword" |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3528 int score, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3529 int altscore, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3530 int had_bonus, // value for st_had_bonus |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3531 slang_T *slang, // language for sound folding |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3532 int maxsf) // su_maxscore applies to soundfold score, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3533 // su_sfmaxscore to the total score. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3534 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3535 int goodlen; // len of goodword changed |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3536 int badlen; // len of bad word changed |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3537 suggest_T *stp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3538 suggest_T new_sug; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3539 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3540 char_u *pgood, *pbad; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3541 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3542 // Minimize "badlen" for consistency. Avoids that changing "the the" to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3543 // "thee the" is added next to changing the first "the" the "thee". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3544 pgood = goodword + STRLEN(goodword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3545 pbad = su->su_badptr + badlenarg; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3546 for (;;) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3547 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3548 goodlen = (int)(pgood - goodword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3549 badlen = (int)(pbad - su->su_badptr); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3550 if (goodlen <= 0 || badlen <= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3551 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3552 MB_PTR_BACK(goodword, pgood); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3553 MB_PTR_BACK(su->su_badptr, pbad); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3554 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3555 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3556 if (mb_ptr2char(pgood) != mb_ptr2char(pbad)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3557 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3558 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3559 else if (*pgood != *pbad) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3560 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3561 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3562 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3563 if (badlen == 0 && goodlen == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3564 // goodword doesn't change anything; may happen for "the the" changing |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3565 // the first "the" to itself. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3566 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3567 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3568 if (gap->ga_len == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3569 i = -1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3570 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3571 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3572 // Check if the word is already there. Also check the length that is |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3573 // being replaced "thes," -> "these" is a different suggestion from |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3574 // "thes" -> "these". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3575 stp = &SUG(*gap, 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3576 for (i = gap->ga_len; --i >= 0; ++stp) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3577 if (stp->st_wordlen == goodlen |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3578 && stp->st_orglen == badlen |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3579 && STRNCMP(stp->st_word, goodword, goodlen) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3580 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3581 // Found it. Remember the word with the lowest score. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3582 if (stp->st_slang == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3583 stp->st_slang = slang; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3584 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3585 new_sug.st_score = score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3586 new_sug.st_altscore = altscore; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3587 new_sug.st_had_bonus = had_bonus; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3588 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3589 if (stp->st_had_bonus != had_bonus) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3590 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3591 // Only one of the two had the soundalike score computed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3592 // Need to do that for the other one now, otherwise the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3593 // scores can't be compared. This happens because |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3594 // suggest_try_change() doesn't compute the soundalike |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3595 // word to keep it fast, while some special methods set |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3596 // the soundalike score to zero. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3597 if (had_bonus) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3598 rescore_one(su, stp); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3599 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3600 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3601 new_sug.st_word = stp->st_word; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3602 new_sug.st_wordlen = stp->st_wordlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3603 new_sug.st_slang = stp->st_slang; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3604 new_sug.st_orglen = badlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3605 rescore_one(su, &new_sug); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3606 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3607 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3608 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3609 if (stp->st_score > new_sug.st_score) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3610 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3611 stp->st_score = new_sug.st_score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3612 stp->st_altscore = new_sug.st_altscore; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3613 stp->st_had_bonus = new_sug.st_had_bonus; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3614 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3615 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3616 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3617 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3618 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3619 if (i < 0 && ga_grow(gap, 1) == OK) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3620 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3621 // Add a suggestion. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3622 stp = &SUG(*gap, gap->ga_len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3623 stp->st_word = vim_strnsave(goodword, goodlen); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3624 if (stp->st_word != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3625 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3626 stp->st_wordlen = goodlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3627 stp->st_score = score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3628 stp->st_altscore = altscore; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3629 stp->st_had_bonus = had_bonus; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3630 stp->st_orglen = badlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3631 stp->st_slang = slang; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3632 ++gap->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3633 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3634 // If we have too many suggestions now, sort the list and keep |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3635 // the best suggestions. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3636 if (gap->ga_len > SUG_MAX_COUNT(su)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3637 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3638 if (maxsf) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3639 su->su_sfmaxscore = cleanup_suggestions(gap, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3640 su->su_sfmaxscore, SUG_CLEAN_COUNT(su)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3641 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3642 su->su_maxscore = cleanup_suggestions(gap, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3643 su->su_maxscore, SUG_CLEAN_COUNT(su)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3644 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3645 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3646 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3647 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3648 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3649 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3650 * Suggestions may in fact be flagged as errors. Esp. for banned words and |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3651 * for split words, such as "the the". Remove these from the list here. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3652 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3653 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3654 check_suggestions( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3655 suginfo_T *su, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3656 garray_T *gap) // either su_ga or su_sga |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3657 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3658 suggest_T *stp; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3659 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3660 char_u longword[MAXWLEN + 1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3661 int len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3662 hlf_T attr; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3663 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3664 if (gap->ga_len == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3665 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3666 stp = &SUG(*gap, 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3667 for (i = gap->ga_len - 1; i >= 0; --i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3668 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3669 // Need to append what follows to check for "the the". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3670 vim_strncpy(longword, stp[i].st_word, MAXWLEN); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3671 len = stp[i].st_wordlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3672 vim_strncpy(longword + len, su->su_badptr + stp[i].st_orglen, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3673 MAXWLEN - len); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3674 attr = HLF_COUNT; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3675 (void)spell_check(curwin, longword, &attr, NULL, FALSE); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3676 if (attr != HLF_COUNT) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3677 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3678 // Remove this entry. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3679 vim_free(stp[i].st_word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3680 --gap->ga_len; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3681 if (i < gap->ga_len) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3682 mch_memmove(stp + i, stp + i + 1, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3683 sizeof(suggest_T) * (gap->ga_len - i)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3684 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3685 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3686 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3687 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3688 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3689 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3690 * Add a word to be banned. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3691 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3692 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3693 add_banned( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3694 suginfo_T *su, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3695 char_u *word) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3696 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3697 char_u *s; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3698 hash_T hash; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3699 hashitem_T *hi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3700 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3701 hash = hash_hash(word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3702 hi = hash_lookup(&su->su_banned, word, hash); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3703 if (!HASHITEM_EMPTY(hi)) // already present |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3704 return; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3705 s = vim_strsave(word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3706 if (s != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3707 hash_add_item(&su->su_banned, hi, s, hash); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3708 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3709 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3710 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3711 * Recompute the score for all suggestions if sound-folding is possible. This |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3712 * is slow, thus only done for the final results. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3713 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3714 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3715 rescore_suggestions(suginfo_T *su) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3716 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3717 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3718 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3719 if (su->su_sallang != NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3720 for (i = 0; i < su->su_ga.ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3721 rescore_one(su, &SUG(su->su_ga, i)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3722 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3723 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3724 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3725 * Recompute the score for one suggestion if sound-folding is possible. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3726 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3727 static void |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3728 rescore_one(suginfo_T *su, suggest_T *stp) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3729 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3730 slang_T *slang = stp->st_slang; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3731 char_u sal_badword[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3732 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3733 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3734 // Only rescore suggestions that have no sal score yet and do have a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3735 // language. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3736 if (slang != NULL && slang->sl_sal.ga_len > 0 && !stp->st_had_bonus) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3737 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3738 if (slang == su->su_sallang) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3739 p = su->su_sal_badword; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3740 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3741 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3742 spell_soundfold(slang, su->su_fbadword, TRUE, sal_badword); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3743 p = sal_badword; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3744 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3745 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3746 stp->st_altscore = stp_sal_score(stp, su, slang, p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3747 if (stp->st_altscore == SCORE_MAXMAX) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3748 stp->st_altscore = SCORE_BIG; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3749 stp->st_score = RESCORE(stp->st_score, stp->st_altscore); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3750 stp->st_had_bonus = TRUE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3751 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3752 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3753 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3754 static int sug_compare(const void *s1, const void *s2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3755 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3756 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3757 * Function given to qsort() to sort the suggestions on st_score. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3758 * First on "st_score", then "st_altscore" then alphabetically. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3759 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3760 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3761 sug_compare(const void *s1, const void *s2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3762 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3763 suggest_T *p1 = (suggest_T *)s1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3764 suggest_T *p2 = (suggest_T *)s2; |
34309
d7cfd8fb1d75
patch 9.1.0089: qsort() comparison functions should be transitive
Christian Brabandt <cb@256bit.org>
parents:
33863
diff
changeset
|
3765 int n; |
d7cfd8fb1d75
patch 9.1.0089: qsort() comparison functions should be transitive
Christian Brabandt <cb@256bit.org>
parents:
33863
diff
changeset
|
3766 |
d7cfd8fb1d75
patch 9.1.0089: qsort() comparison functions should be transitive
Christian Brabandt <cb@256bit.org>
parents:
33863
diff
changeset
|
3767 n = p1->st_score == p2->st_score ? 0 : |
d7cfd8fb1d75
patch 9.1.0089: qsort() comparison functions should be transitive
Christian Brabandt <cb@256bit.org>
parents:
33863
diff
changeset
|
3768 p1->st_score > p2->st_score ? 1 : -1; |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3769 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3770 if (n == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3771 { |
34309
d7cfd8fb1d75
patch 9.1.0089: qsort() comparison functions should be transitive
Christian Brabandt <cb@256bit.org>
parents:
33863
diff
changeset
|
3772 n = p1->st_altscore == p2->st_altscore ? 0 : |
d7cfd8fb1d75
patch 9.1.0089: qsort() comparison functions should be transitive
Christian Brabandt <cb@256bit.org>
parents:
33863
diff
changeset
|
3773 p1->st_altscore > p2->st_altscore ? 1 : -1; |
d7cfd8fb1d75
patch 9.1.0089: qsort() comparison functions should be transitive
Christian Brabandt <cb@256bit.org>
parents:
33863
diff
changeset
|
3774 |
32670
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3775 if (n == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3776 n = STRICMP(p1->st_word, p2->st_word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3777 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3778 return n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3779 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3780 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3781 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3782 * Cleanup the suggestions: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3783 * - Sort on score. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3784 * - Remove words that won't be displayed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3785 * Returns the maximum score in the list or "maxscore" unmodified. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3786 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3787 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3788 cleanup_suggestions( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3789 garray_T *gap, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3790 int maxscore, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3791 int keep) // nr of suggestions to keep |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3792 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3793 if (gap->ga_len <= 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3794 return maxscore; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3795 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3796 // Sort the list. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3797 qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3798 sug_compare); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3799 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3800 // Truncate the list to the number of suggestions that will be |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3801 // displayed. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3802 if (gap->ga_len > keep) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3803 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3804 int i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3805 suggest_T *stp = &SUG(*gap, 0); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3806 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3807 for (i = keep; i < gap->ga_len; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3808 vim_free(stp[i].st_word); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3809 gap->ga_len = keep; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3810 if (keep >= 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3811 return stp[keep - 1].st_score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3812 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3813 return maxscore; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3814 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3815 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3816 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3817 * Compute a score for two sound-a-like words. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3818 * This permits up to two inserts/deletes/swaps/etc. to keep things fast. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3819 * Instead of a generic loop we write out the code. That keeps it fast by |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3820 * avoiding checks that will not be possible. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3821 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3822 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3823 soundalike_score( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3824 char_u *goodstart, // sound-folded good word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3825 char_u *badstart) // sound-folded bad word |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3826 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3827 char_u *goodsound = goodstart; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3828 char_u *badsound = badstart; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3829 int goodlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3830 int badlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3831 int n; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3832 char_u *pl, *ps; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3833 char_u *pl2, *ps2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3834 int score = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3835 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3836 // Adding/inserting "*" at the start (word starts with vowel) shouldn't be |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3837 // counted so much, vowels halfway the word aren't counted at all. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3838 if ((*badsound == '*' || *goodsound == '*') && *badsound != *goodsound) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3839 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3840 if ((badsound[0] == NUL && goodsound[1] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3841 || (goodsound[0] == NUL && badsound[1] == NUL)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3842 // changing word with vowel to word without a sound |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3843 return SCORE_DEL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3844 if (badsound[0] == NUL || goodsound[0] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3845 // more than two changes |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3846 return SCORE_MAXMAX; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3847 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3848 if (badsound[1] == goodsound[1] |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3849 || (badsound[1] != NUL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3850 && goodsound[1] != NUL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3851 && badsound[2] == goodsound[2])) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3852 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3853 // handle like a substitute |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3854 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3855 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3856 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3857 score = 2 * SCORE_DEL / 3; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3858 if (*badsound == '*') |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3859 ++badsound; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3860 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3861 ++goodsound; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3862 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3863 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3864 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3865 goodlen = (int)STRLEN(goodsound); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3866 badlen = (int)STRLEN(badsound); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3867 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3868 // Return quickly if the lengths are too different to be fixed by two |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3869 // changes. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3870 n = goodlen - badlen; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3871 if (n < -2 || n > 2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3872 return SCORE_MAXMAX; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3873 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3874 if (n > 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3875 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3876 pl = goodsound; // goodsound is longest |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3877 ps = badsound; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3878 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3879 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3880 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3881 pl = badsound; // badsound is longest |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3882 ps = goodsound; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3883 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3884 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3885 // Skip over the identical part. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3886 while (*pl == *ps && *pl != NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3887 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3888 ++pl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3889 ++ps; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3890 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3891 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3892 switch (n) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3893 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3894 case -2: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3895 case 2: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3896 // Must delete two characters from "pl". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3897 ++pl; // first delete |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3898 while (*pl == *ps) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3899 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3900 ++pl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3901 ++ps; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3902 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3903 // strings must be equal after second delete |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3904 if (STRCMP(pl + 1, ps) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3905 return score + SCORE_DEL * 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3906 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3907 // Failed to compare. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3908 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3909 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3910 case -1: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3911 case 1: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3912 // Minimal one delete from "pl" required. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3913 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3914 // 1: delete |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3915 pl2 = pl + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3916 ps2 = ps; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3917 while (*pl2 == *ps2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3918 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3919 if (*pl2 == NUL) // reached the end |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3920 return score + SCORE_DEL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3921 ++pl2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3922 ++ps2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3923 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3924 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3925 // 2: delete then swap, then rest must be equal |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3926 if (pl2[0] == ps2[1] && pl2[1] == ps2[0] |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3927 && STRCMP(pl2 + 2, ps2 + 2) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3928 return score + SCORE_DEL + SCORE_SWAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3929 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3930 // 3: delete then substitute, then the rest must be equal |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3931 if (STRCMP(pl2 + 1, ps2 + 1) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3932 return score + SCORE_DEL + SCORE_SUBST; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3933 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3934 // 4: first swap then delete |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3935 if (pl[0] == ps[1] && pl[1] == ps[0]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3936 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3937 pl2 = pl + 2; // swap, skip two chars |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3938 ps2 = ps + 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3939 while (*pl2 == *ps2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3940 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3941 ++pl2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3942 ++ps2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3943 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3944 // delete a char and then strings must be equal |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3945 if (STRCMP(pl2 + 1, ps2) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3946 return score + SCORE_SWAP + SCORE_DEL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3947 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3948 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3949 // 5: first substitute then delete |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3950 pl2 = pl + 1; // substitute, skip one char |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3951 ps2 = ps + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3952 while (*pl2 == *ps2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3953 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3954 ++pl2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3955 ++ps2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3956 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3957 // delete a char and then strings must be equal |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3958 if (STRCMP(pl2 + 1, ps2) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3959 return score + SCORE_SUBST + SCORE_DEL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3960 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3961 // Failed to compare. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3962 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3963 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3964 case 0: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3965 // Lengths are equal, thus changes must result in same length: An |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3966 // insert is only possible in combination with a delete. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3967 // 1: check if for identical strings |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3968 if (*pl == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3969 return score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3970 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3971 // 2: swap |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3972 if (pl[0] == ps[1] && pl[1] == ps[0]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3973 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3974 pl2 = pl + 2; // swap, skip two chars |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3975 ps2 = ps + 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3976 while (*pl2 == *ps2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3977 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3978 if (*pl2 == NUL) // reached the end |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3979 return score + SCORE_SWAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3980 ++pl2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3981 ++ps2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3982 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3983 // 3: swap and swap again |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3984 if (pl2[0] == ps2[1] && pl2[1] == ps2[0] |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3985 && STRCMP(pl2 + 2, ps2 + 2) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3986 return score + SCORE_SWAP + SCORE_SWAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3987 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3988 // 4: swap and substitute |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3989 if (STRCMP(pl2 + 1, ps2 + 1) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3990 return score + SCORE_SWAP + SCORE_SUBST; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3991 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3992 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3993 // 5: substitute |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3994 pl2 = pl + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3995 ps2 = ps + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3996 while (*pl2 == *ps2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3997 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3998 if (*pl2 == NUL) // reached the end |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
3999 return score + SCORE_SUBST; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4000 ++pl2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4001 ++ps2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4002 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4003 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4004 // 6: substitute and swap |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4005 if (pl2[0] == ps2[1] && pl2[1] == ps2[0] |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4006 && STRCMP(pl2 + 2, ps2 + 2) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4007 return score + SCORE_SUBST + SCORE_SWAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4008 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4009 // 7: substitute and substitute |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4010 if (STRCMP(pl2 + 1, ps2 + 1) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4011 return score + SCORE_SUBST + SCORE_SUBST; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4012 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4013 // 8: insert then delete |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4014 pl2 = pl; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4015 ps2 = ps + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4016 while (*pl2 == *ps2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4017 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4018 ++pl2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4019 ++ps2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4020 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4021 if (STRCMP(pl2 + 1, ps2) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4022 return score + SCORE_INS + SCORE_DEL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4023 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4024 // 9: delete then insert |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4025 pl2 = pl + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4026 ps2 = ps; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4027 while (*pl2 == *ps2) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4028 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4029 ++pl2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4030 ++ps2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4031 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4032 if (STRCMP(pl2, ps2 + 1) == 0) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4033 return score + SCORE_INS + SCORE_DEL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4034 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4035 // Failed to compare. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4036 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4037 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4038 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4039 return SCORE_MAXMAX; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4040 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4041 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4042 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4043 * Compute the "edit distance" to turn "badword" into "goodword". The less |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4044 * deletes/inserts/substitutes/swaps are required the lower the score. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4045 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4046 * The algorithm is described by Du and Chang, 1992. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4047 * The implementation of the algorithm comes from Aspell editdist.cpp, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4048 * edit_distance(). It has been converted from C++ to C and modified to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4049 * support multi-byte characters. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4050 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4051 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4052 spell_edit_score( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4053 slang_T *slang, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4054 char_u *badword, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4055 char_u *goodword) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4056 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4057 int *cnt; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4058 int badlen, goodlen; // lengths including NUL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4059 int j, i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4060 int t; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4061 int bc, gc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4062 int pbc, pgc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4063 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4064 int wbadword[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4065 int wgoodword[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4066 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4067 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4068 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4069 // Get the characters from the multi-byte strings and put them in an |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4070 // int array for easy access. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4071 for (p = badword, badlen = 0; *p != NUL; ) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4072 wbadword[badlen++] = mb_cptr2char_adv(&p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4073 wbadword[badlen++] = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4074 for (p = goodword, goodlen = 0; *p != NUL; ) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4075 wgoodword[goodlen++] = mb_cptr2char_adv(&p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4076 wgoodword[goodlen++] = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4077 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4078 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4079 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4080 badlen = (int)STRLEN(badword) + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4081 goodlen = (int)STRLEN(goodword) + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4082 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4083 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4084 // We use "cnt" as an array: CNT(badword_idx, goodword_idx). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4085 #define CNT(a, b) cnt[(a) + (b) * (badlen + 1)] |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4086 cnt = ALLOC_MULT(int, (badlen + 1) * (goodlen + 1)); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4087 if (cnt == NULL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4088 return 0; // out of memory |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4089 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4090 CNT(0, 0) = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4091 for (j = 1; j <= goodlen; ++j) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4092 CNT(0, j) = CNT(0, j - 1) + SCORE_INS; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4093 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4094 for (i = 1; i <= badlen; ++i) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4095 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4096 CNT(i, 0) = CNT(i - 1, 0) + SCORE_DEL; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4097 for (j = 1; j <= goodlen; ++j) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4098 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4099 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4100 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4101 bc = wbadword[i - 1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4102 gc = wgoodword[j - 1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4103 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4104 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4105 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4106 bc = badword[i - 1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4107 gc = goodword[j - 1]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4108 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4109 if (bc == gc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4110 CNT(i, j) = CNT(i - 1, j - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4111 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4112 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4113 // Use a better score when there is only a case difference. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4114 if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4115 CNT(i, j) = SCORE_ICASE + CNT(i - 1, j - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4116 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4117 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4118 // For a similar character use SCORE_SIMILAR. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4119 if (slang != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4120 && slang->sl_has_map |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4121 && similar_chars(slang, gc, bc)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4122 CNT(i, j) = SCORE_SIMILAR + CNT(i - 1, j - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4123 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4124 CNT(i, j) = SCORE_SUBST + CNT(i - 1, j - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4125 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4126 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4127 if (i > 1 && j > 1) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4128 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4129 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4130 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4131 pbc = wbadword[i - 2]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4132 pgc = wgoodword[j - 2]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4133 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4134 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4135 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4136 pbc = badword[i - 2]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4137 pgc = goodword[j - 2]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4138 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4139 if (bc == pgc && pbc == gc) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4140 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4141 t = SCORE_SWAP + CNT(i - 2, j - 2); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4142 if (t < CNT(i, j)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4143 CNT(i, j) = t; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4144 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4145 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4146 t = SCORE_DEL + CNT(i - 1, j); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4147 if (t < CNT(i, j)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4148 CNT(i, j) = t; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4149 t = SCORE_INS + CNT(i, j - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4150 if (t < CNT(i, j)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4151 CNT(i, j) = t; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4152 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4153 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4154 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4155 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4156 i = CNT(badlen - 1, goodlen - 1); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4157 vim_free(cnt); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4158 return i; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4159 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4160 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4161 typedef struct |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4162 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4163 int badi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4164 int goodi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4165 int score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4166 } limitscore_T; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4167 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4168 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4169 * Like spell_edit_score(), but with a limit on the score to make it faster. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4170 * May return SCORE_MAXMAX when the score is higher than "limit". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4171 * |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4172 * This uses a stack for the edits still to be tried. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4173 * The idea comes from Aspell leditdist.cpp. Rewritten in C and added support |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4174 * for multi-byte characters. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4175 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4176 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4177 spell_edit_score_limit( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4178 slang_T *slang, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4179 char_u *badword, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4180 char_u *goodword, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4181 int limit) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4182 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4183 limitscore_T stack[10]; // allow for over 3 * 2 edits |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4184 int stackidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4185 int bi, gi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4186 int bi2, gi2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4187 int bc, gc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4188 int score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4189 int score_off; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4190 int minscore; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4191 int round; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4192 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4193 // Multi-byte characters require a bit more work, use a different function |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4194 // to avoid testing "has_mbyte" quite often. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4195 if (has_mbyte) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4196 return spell_edit_score_limit_w(slang, badword, goodword, limit); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4197 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4198 // The idea is to go from start to end over the words. So long as |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4199 // characters are equal just continue, this always gives the lowest score. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4200 // When there is a difference try several alternatives. Each alternative |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4201 // increases "score" for the edit distance. Some of the alternatives are |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4202 // pushed unto a stack and tried later, some are tried right away. At the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4203 // end of the word the score for one alternative is known. The lowest |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4204 // possible score is stored in "minscore". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4205 stackidx = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4206 bi = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4207 gi = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4208 score = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4209 minscore = limit + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4210 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4211 for (;;) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4212 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4213 // Skip over an equal part, score remains the same. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4214 for (;;) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4215 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4216 bc = badword[bi]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4217 gc = goodword[gi]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4218 if (bc != gc) // stop at a char that's different |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4219 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4220 if (bc == NUL) // both words end |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4221 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4222 if (score < minscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4223 minscore = score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4224 goto pop; // do next alternative |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4225 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4226 ++bi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4227 ++gi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4228 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4229 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4230 if (gc == NUL) // goodword ends, delete badword chars |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4231 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4232 do |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4233 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4234 if ((score += SCORE_DEL) >= minscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4235 goto pop; // do next alternative |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4236 } while (badword[++bi] != NUL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4237 minscore = score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4238 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4239 else if (bc == NUL) // badword ends, insert badword chars |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4240 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4241 do |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4242 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4243 if ((score += SCORE_INS) >= minscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4244 goto pop; // do next alternative |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4245 } while (goodword[++gi] != NUL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4246 minscore = score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4247 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4248 else // both words continue |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4249 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4250 // If not close to the limit, perform a change. Only try changes |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4251 // that may lead to a lower score than "minscore". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4252 // round 0: try deleting a char from badword |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4253 // round 1: try inserting a char in badword |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4254 for (round = 0; round <= 1; ++round) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4255 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4256 score_off = score + (round == 0 ? SCORE_DEL : SCORE_INS); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4257 if (score_off < minscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4258 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4259 if (score_off + SCORE_EDIT_MIN >= minscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4260 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4261 // Near the limit, rest of the words must match. We |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4262 // can check that right now, no need to push an item |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4263 // onto the stack. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4264 bi2 = bi + 1 - round; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4265 gi2 = gi + round; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4266 while (goodword[gi2] == badword[bi2]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4267 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4268 if (goodword[gi2] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4269 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4270 minscore = score_off; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4271 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4272 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4273 ++bi2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4274 ++gi2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4275 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4276 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4277 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4278 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4279 // try deleting/inserting a character later |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4280 stack[stackidx].badi = bi + 1 - round; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4281 stack[stackidx].goodi = gi + round; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4282 stack[stackidx].score = score_off; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4283 ++stackidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4284 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4285 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4286 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4287 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4288 if (score + SCORE_SWAP < minscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4289 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4290 // If swapping two characters makes a match then the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4291 // substitution is more expensive, thus there is no need to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4292 // try both. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4293 if (gc == badword[bi + 1] && bc == goodword[gi + 1]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4294 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4295 // Swap two characters, that is: skip them. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4296 gi += 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4297 bi += 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4298 score += SCORE_SWAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4299 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4300 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4301 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4302 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4303 // Substitute one character for another which is the same |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4304 // thing as deleting a character from both goodword and badword. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4305 // Use a better score when there is only a case difference. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4306 if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4307 score += SCORE_ICASE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4308 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4309 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4310 // For a similar character use SCORE_SIMILAR. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4311 if (slang != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4312 && slang->sl_has_map |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4313 && similar_chars(slang, gc, bc)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4314 score += SCORE_SIMILAR; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4315 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4316 score += SCORE_SUBST; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4317 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4318 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4319 if (score < minscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4320 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4321 // Do the substitution. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4322 ++gi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4323 ++bi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4324 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4325 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4326 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4327 pop: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4328 // Get here to try the next alternative, pop it from the stack. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4329 if (stackidx == 0) // stack is empty, finished |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4330 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4331 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4332 // pop an item from the stack |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4333 --stackidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4334 gi = stack[stackidx].goodi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4335 bi = stack[stackidx].badi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4336 score = stack[stackidx].score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4337 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4338 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4339 // When the score goes over "limit" it may actually be much higher. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4340 // Return a very large number to avoid going below the limit when giving a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4341 // bonus. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4342 if (minscore > limit) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4343 return SCORE_MAXMAX; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4344 return minscore; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4345 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4346 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4347 /* |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4348 * Multi-byte version of spell_edit_score_limit(). |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4349 * Keep it in sync with the above! |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4350 */ |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4351 static int |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4352 spell_edit_score_limit_w( |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4353 slang_T *slang, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4354 char_u *badword, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4355 char_u *goodword, |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4356 int limit) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4357 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4358 limitscore_T stack[10]; // allow for over 3 * 2 edits |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4359 int stackidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4360 int bi, gi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4361 int bi2, gi2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4362 int bc, gc; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4363 int score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4364 int score_off; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4365 int minscore; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4366 int round; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4367 char_u *p; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4368 int wbadword[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4369 int wgoodword[MAXWLEN]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4370 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4371 // Get the characters from the multi-byte strings and put them in an |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4372 // int array for easy access. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4373 bi = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4374 for (p = badword; *p != NUL; ) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4375 wbadword[bi++] = mb_cptr2char_adv(&p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4376 wbadword[bi++] = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4377 gi = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4378 for (p = goodword; *p != NUL; ) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4379 wgoodword[gi++] = mb_cptr2char_adv(&p); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4380 wgoodword[gi++] = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4381 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4382 // The idea is to go from start to end over the words. So long as |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4383 // characters are equal just continue, this always gives the lowest score. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4384 // When there is a difference try several alternatives. Each alternative |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4385 // increases "score" for the edit distance. Some of the alternatives are |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4386 // pushed unto a stack and tried later, some are tried right away. At the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4387 // end of the word the score for one alternative is known. The lowest |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4388 // possible score is stored in "minscore". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4389 stackidx = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4390 bi = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4391 gi = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4392 score = 0; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4393 minscore = limit + 1; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4394 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4395 for (;;) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4396 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4397 // Skip over an equal part, score remains the same. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4398 for (;;) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4399 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4400 bc = wbadword[bi]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4401 gc = wgoodword[gi]; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4402 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4403 if (bc != gc) // stop at a char that's different |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4404 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4405 if (bc == NUL) // both words end |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4406 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4407 if (score < minscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4408 minscore = score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4409 goto pop; // do next alternative |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4410 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4411 ++bi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4412 ++gi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4413 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4414 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4415 if (gc == NUL) // goodword ends, delete badword chars |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4416 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4417 do |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4418 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4419 if ((score += SCORE_DEL) >= minscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4420 goto pop; // do next alternative |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4421 } while (wbadword[++bi] != NUL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4422 minscore = score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4423 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4424 else if (bc == NUL) // badword ends, insert badword chars |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4425 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4426 do |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4427 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4428 if ((score += SCORE_INS) >= minscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4429 goto pop; // do next alternative |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4430 } while (wgoodword[++gi] != NUL); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4431 minscore = score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4432 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4433 else // both words continue |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4434 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4435 // If not close to the limit, perform a change. Only try changes |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4436 // that may lead to a lower score than "minscore". |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4437 // round 0: try deleting a char from badword |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4438 // round 1: try inserting a char in badword |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4439 for (round = 0; round <= 1; ++round) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4440 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4441 score_off = score + (round == 0 ? SCORE_DEL : SCORE_INS); |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4442 if (score_off < minscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4443 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4444 if (score_off + SCORE_EDIT_MIN >= minscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4445 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4446 // Near the limit, rest of the words must match. We |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4447 // can check that right now, no need to push an item |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4448 // onto the stack. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4449 bi2 = bi + 1 - round; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4450 gi2 = gi + round; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4451 while (wgoodword[gi2] == wbadword[bi2]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4452 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4453 if (wgoodword[gi2] == NUL) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4454 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4455 minscore = score_off; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4456 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4457 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4458 ++bi2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4459 ++gi2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4460 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4461 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4462 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4463 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4464 // try deleting a character from badword later |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4465 stack[stackidx].badi = bi + 1 - round; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4466 stack[stackidx].goodi = gi + round; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4467 stack[stackidx].score = score_off; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4468 ++stackidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4469 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4470 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4471 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4472 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4473 if (score + SCORE_SWAP < minscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4474 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4475 // If swapping two characters makes a match then the |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4476 // substitution is more expensive, thus there is no need to |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4477 // try both. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4478 if (gc == wbadword[bi + 1] && bc == wgoodword[gi + 1]) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4479 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4480 // Swap two characters, that is: skip them. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4481 gi += 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4482 bi += 2; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4483 score += SCORE_SWAP; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4484 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4485 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4486 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4487 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4488 // Substitute one character for another which is the same |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4489 // thing as deleting a character from both goodword and badword. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4490 // Use a better score when there is only a case difference. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4491 if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4492 score += SCORE_ICASE; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4493 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4494 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4495 // For a similar character use SCORE_SIMILAR. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4496 if (slang != NULL |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4497 && slang->sl_has_map |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4498 && similar_chars(slang, gc, bc)) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4499 score += SCORE_SIMILAR; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4500 else |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4501 score += SCORE_SUBST; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4502 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4503 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4504 if (score < minscore) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4505 { |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4506 // Do the substitution. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4507 ++gi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4508 ++bi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4509 continue; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4510 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4511 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4512 pop: |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4513 // Get here to try the next alternative, pop it from the stack. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4514 if (stackidx == 0) // stack is empty, finished |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4515 break; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4516 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4517 // pop an item from the stack |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4518 --stackidx; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4519 gi = stack[stackidx].goodi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4520 bi = stack[stackidx].badi; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4521 score = stack[stackidx].score; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4522 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4523 |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4524 // When the score goes over "limit" it may actually be much higher. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4525 // Return a very large number to avoid going below the limit when giving a |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4526 // bonus. |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4527 if (minscore > limit) |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4528 return SCORE_MAXMAX; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4529 return minscore; |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4530 } |
695b50472e85
Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents:
32669
diff
changeset
|
4531 #endif // FEAT_SPELL |