annotate src/spell.c @ 10613:196757b230a2 v8.0.0196

patch 8.0.0196: profile test is slo and does not work on MS-Windows commit https://github.com/vim/vim/commit/c011a3d083001bcd9853b4447422f1819f3cee2f Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jan 16 22:37:42 2017 +0100 patch 8.0.0196: profile test is slo and does not work on MS-Windows Problem: The test for :profile is slow and does not work on MS-Windows. Solution: Use the "-es" argument. (Dominique Pelle) Swap single and double quotes for system()
author Christian Brabandt <cb@256bit.org>
date Mon, 16 Jan 2017 22:45:04 +0100
parents 66f1b5bf3fa6
children 2297aae8e127
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 9953
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
2 *
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
4 *
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
8 */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
9
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
10 /*
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
11 * spell.c: code for spell checking
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
12 *
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
13 * See spellfile.c for the Vim spell file format.
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
14 *
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
15 * The spell checking mechanism uses a tree (aka trie). Each node in the tree
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
16 * has a list of bytes that can appear (siblings). For each byte there is a
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
17 * pointer to the node with the byte that follows in the word (child).
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
18 *
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
19 * A NUL byte is used where the word may end. The bytes are sorted, so that
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
20 * binary searching can be used and the NUL bytes are at the start. The
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
21 * number of possible bytes is stored before the list of bytes.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
22 *
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
23 * The tree uses two arrays: "byts" stores the characters, "idxs" stores
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
24 * either the next index or flags. The tree starts at index 0. For example,
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
25 * to lookup "vi" this sequence is followed:
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
26 * i = 0
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
27 * len = byts[i]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
28 * n = where "v" appears in byts[i + 1] to byts[i + len]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
29 * i = idxs[n]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
30 * len = byts[i]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
31 * n = where "i" appears in byts[i + 1] to byts[i + len]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
32 * i = idxs[n]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
33 * len = byts[i]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
34 * find that byts[i + 1] is 0, idxs[i + 1] has flags for "vi".
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
35 *
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
36 * There are two word trees: one with case-folded words and one with words in
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
37 * original case. The second one is only used for keep-case words and is
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
38 * usually small.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
39 *
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
40 * There is one additional tree for when not all prefixes are applied when
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
41 * generating the .spl file. This tree stores all the possible prefixes, as
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
42 * if they were words. At each word (prefix) end the prefix nr is stored, the
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
43 * following word must support this prefix nr. And the condition nr is
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
44 * stored, used to lookup the condition that the word must match with.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
45 *
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
46 * Thanks to Olaf Seibert for providing an example implementation of this tree
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
47 * and the compression mechanism.
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
48 * LZ trie ideas:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
49 * http://www.irb.hr/hr/home/ristov/papers/RistovLZtrieRevision1.pdf
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
50 * More papers: http://www-igm.univ-mlv.fr/~laporte/publi_en.html
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
51 *
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
52 * Matching involves checking the caps type: Onecap ALLCAP KeepCap.
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
53 *
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
54 * Why doesn't Vim use aspell/ispell/myspell/etc.?
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
55 * See ":help develop-spell".
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
56 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
57
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
58 /*
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
59 * Use this to adjust the score after finding suggestions, based on the
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
60 * suggested word sounding like the bad word. This is much faster than doing
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
61 * it for every possible suggestion.
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
62 * Disadvantage: When "the" is typed as "hte" it sounds quite different ("@"
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
63 * vs "ht") and goes down in the list.
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
64 * Used when 'spellsuggest' is set to "best".
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
65 */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
66 #define RESCORE(word_score, sound_score) ((3 * word_score + sound_score) / 4)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
67
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
68 /*
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
69 * Do the opposite: based on a maximum end score and a known sound score,
1705
5b43a3a9454a updated for version 7.2-003
vimboss
parents: 1619
diff changeset
70 * compute the maximum word score that can be used.
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
71 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
72 #define MAXSCORE(word_score, sound_score) ((4 * word_score - sound_score) / 3)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
73
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
74 #define IN_SPELL_C
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
75 #include "vim.h"
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
76
737
59971e227f8c updated for version 7.0222
vimboss
parents: 718
diff changeset
77 #if defined(FEAT_SPELL) || defined(PROTO)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
78
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
79 #ifndef UNIX /* it's in os_unix.h for Unix */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
80 # include <time.h> /* for time_t */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
81 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
82
633
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
83 /* only used for su_badflags */
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
84 #define WF_MIXCAP 0x20 /* mix of upper and lower case: macaRONI */
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
85
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
86 #define WF_CAPMASK (WF_ONECAP | WF_ALLCAP | WF_KEEPCAP | WF_FIXCAP)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
87
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
88 #define REGION_ALL 0xff /* word valid in all regions */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
89
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
90 #define VIMSUGMAGIC "VIMsug" /* string at start of Vim .sug file */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
91 #define VIMSUGMAGICL 6
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
92 #define VIMSUGVERSION 1
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
93
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
94 /* Result values. Lower number is accepted over higher one. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
95 #define SP_BANNED -1
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
96 #define SP_OK 0
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
97 #define SP_RARE 1
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
98 #define SP_LOCAL 2
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
99 #define SP_BAD 3
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
100
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
101 typedef struct wordcount_S
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
102 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
103 short_u wc_count; /* nr of times word was seen */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
104 char_u wc_word[1]; /* word, actually longer */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
105 } wordcount_T;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
106
9570
695186e11daa commit https://github.com/vim/vim/commit/840268400dc8fda62a14f8a084e8b1ea46619454
Christian Brabandt <cb@256bit.org>
parents: 9487
diff changeset
107 #define WC_KEY_OFF offsetof(wordcount_T, wc_word)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
108 #define HI2WC(hi) ((wordcount_T *)((hi)->hi_key - WC_KEY_OFF))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
109 #define MAXWORDCOUNT 0xffff
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
110
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
111 /*
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
112 * Information used when looking for suggestions.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
113 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
114 typedef struct suginfo_S
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
115 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
116 garray_T su_ga; /* suggestions, contains "suggest_T" */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
117 int su_maxcount; /* max. number of suggestions displayed */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
118 int su_maxscore; /* maximum score for adding to su_ga */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
119 int su_sfmaxscore; /* idem, for when doing soundfold words */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
120 garray_T su_sga; /* like su_ga, sound-folded scoring */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
121 char_u *su_badptr; /* start of bad word in line */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
122 int su_badlen; /* length of detected bad word in line */
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
123 int su_badflags; /* caps flags for bad word */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
124 char_u su_badword[MAXWLEN]; /* bad word truncated at su_badlen */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
125 char_u su_fbadword[MAXWLEN]; /* su_badword case-folded */
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
126 char_u su_sal_badword[MAXWLEN]; /* su_badword soundfolded */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
127 hashtab_T su_banned; /* table with banned words */
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
128 slang_T *su_sallang; /* default language for sound folding */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
129 } suginfo_T;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
130
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
131 /* One word suggestion. Used in "si_ga". */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
132 typedef struct suggest_S
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
133 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
134 char_u *st_word; /* suggested word, allocated string */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
135 int st_wordlen; /* STRLEN(st_word) */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
136 int st_orglen; /* length of replaced text */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
137 int st_score; /* lower is better */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
138 int st_altscore; /* used when st_score compares equal */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
139 int st_salscore; /* st_score is for soundalike */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
140 int st_had_bonus; /* bonus already included in score */
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
141 slang_T *st_slang; /* language used for sound folding */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
142 } suggest_T;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
143
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
144 #define SUG(ga, i) (((suggest_T *)(ga).ga_data)[i])
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
145
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
146 /* TRUE if a word appears in the list of banned words. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
147 #define WAS_BANNED(su, word) (!HASHITEM_EMPTY(hash_find(&su->su_banned, word)))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
148
1705
5b43a3a9454a updated for version 7.2-003
vimboss
parents: 1619
diff changeset
149 /* Number of suggestions kept when cleaning up. We need to keep more than
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
150 * what is displayed, because when rescore_suggestions() is called the score
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
151 * may change and wrong suggestions may be removed later. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
152 #define SUG_CLEAN_COUNT(su) ((su)->su_maxcount < 130 ? 150 : (su)->su_maxcount + 20)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
153
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
154 /* Threshold for sorting and cleaning up suggestions. Don't want to keep lots
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
155 * of suggestions that are not going to be displayed. */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
156 #define SUG_MAX_COUNT(su) (SUG_CLEAN_COUNT(su) + 50)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
157
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
158 /* score for various changes */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
159 #define SCORE_SPLIT 149 /* split bad word */
698
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
160 #define SCORE_SPLIT_NO 249 /* split bad word with NOSPLITSUGS */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
161 #define SCORE_ICASE 52 /* slightly different case */
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
162 #define SCORE_REGION 200 /* word is for different region */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
163 #define SCORE_RARE 180 /* rare word */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
164 #define SCORE_SWAP 75 /* swap two characters */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
165 #define SCORE_SWAP3 110 /* swap two characters in three */
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 529
diff changeset
166 #define SCORE_REP 65 /* REP replacement */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
167 #define SCORE_SUBST 93 /* substitute a character */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
168 #define SCORE_SIMILAR 33 /* substitute a similar character */
479
147da3983fca updated for version 7.0129
vimboss
parents: 475
diff changeset
169 #define SCORE_SUBCOMP 33 /* substitute a composing character */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
170 #define SCORE_DEL 94 /* delete a character */
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 529
diff changeset
171 #define SCORE_DELDUP 66 /* delete a duplicated character */
479
147da3983fca updated for version 7.0129
vimboss
parents: 475
diff changeset
172 #define SCORE_DELCOMP 28 /* delete a composing character */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
173 #define SCORE_INS 96 /* insert a character */
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 529
diff changeset
174 #define SCORE_INSDUP 67 /* insert a duplicate character */
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
175 #define SCORE_INSCOMP 30 /* insert a composing character */
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
176 #define SCORE_NONWORD 103 /* change non-word to word char */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
177
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
178 #define SCORE_FILE 30 /* suggestion from a file */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
179 #define SCORE_MAXINIT 350 /* Initial maximum score: higher == slower.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
180 * 350 allows for about three changes. */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
181
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
182 #define SCORE_COMMON1 30 /* subtracted for words seen before */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
183 #define SCORE_COMMON2 40 /* subtracted for words often seen */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
184 #define SCORE_COMMON3 50 /* subtracted for words very often seen */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
185 #define SCORE_THRES2 10 /* word count threshold for COMMON2 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
186 #define SCORE_THRES3 100 /* word count threshold for COMMON3 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
187
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
188 /* When trying changed soundfold words it becomes slow when trying more than
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
189 * two changes. With less then two changes it's slightly faster but we miss a
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
190 * few good suggestions. In rare cases we need to try three of four changes.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
191 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
192 #define SCORE_SFMAX1 200 /* maximum score for first try */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
193 #define SCORE_SFMAX2 300 /* maximum score for second try */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
194 #define SCORE_SFMAX3 400 /* maximum score for third try */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
195
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
196 #define SCORE_BIG SCORE_INS * 3 /* big difference */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
197 #define SCORE_MAXMAX 999999 /* accept any score */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
198 #define SCORE_LIMITMAX 350 /* for spell_edit_score_limit() */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
199
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
200 /* for spell_edit_score_limit() we need to know the minimum value of
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
201 * SCORE_ICASE, SCORE_SWAP, SCORE_DEL, SCORE_SIMILAR and SCORE_INS */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
202 #define SCORE_EDIT_MIN SCORE_SIMILAR
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
203
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
204 /*
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
205 * Structure to store info for word matching.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
206 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
207 typedef struct matchinf_S
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
208 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
209 langp_T *mi_lp; /* info for language and region */
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
210
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
211 /* pointers to original text to be checked */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
212 char_u *mi_word; /* start of word being checked */
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
213 char_u *mi_end; /* end of matching word so far */
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
214 char_u *mi_fend; /* next char to be added to mi_fword */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
215 char_u *mi_cend; /* char after what was used for
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
216 mi_capflags */
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
217
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
218 /* case-folded text */
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
219 char_u mi_fword[MAXWLEN + 1]; /* mi_word case-folded */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
220 int mi_fwordlen; /* nr of valid bytes in mi_fword */
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
221
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
222 /* for when checking word after a prefix */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
223 int mi_prefarridx; /* index in sl_pidxs with list of
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
224 affixID/condition */
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
225 int mi_prefcnt; /* number of entries at mi_prefarridx */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
226 int mi_prefixlen; /* byte length of prefix */
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
227 #ifdef FEAT_MBYTE
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
228 int mi_cprefixlen; /* byte length of prefix in original
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
229 case */
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
230 #else
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
231 # define mi_cprefixlen mi_prefixlen /* it's the same value */
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
232 #endif
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
233
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
234 /* for when checking a compound word */
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
235 int mi_compoff; /* start of following word offset */
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
236 char_u mi_compflags[MAXWLEN]; /* flags for compound words used */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
237 int mi_complen; /* nr of compound words used */
809
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
238 int mi_compextra; /* nr of COMPOUNDROOT words */
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
239
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
240 /* others */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
241 int mi_result; /* result so far: SP_BAD, SP_OK, etc. */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
242 int mi_capflags; /* WF_ONECAP WF_ALLCAP WF_KEEPCAP */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
243 win_T *mi_win; /* buffer being checked */
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
244
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
245 /* for NOBREAK */
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
246 int mi_result2; /* "mi_resul" without following word */
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
247 char_u *mi_end2; /* "mi_end" without following word */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
248 } matchinf_T;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
249
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
250
7805
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
251 static int spell_iswordp(char_u *p, win_T *wp);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
252 #ifdef FEAT_MBYTE
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
253 static int spell_mb_isword_class(int cl, win_T *wp);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
254 static int spell_iswordp_w(int *p, win_T *wp);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
255 #endif
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
256
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
257 /*
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
258 * For finding suggestions: At each node in the tree these states are tried:
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
259 */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
260 typedef enum
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
261 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
262 STATE_START = 0, /* At start of node check for NUL bytes (goodword
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
263 * ends); if badword ends there is a match, otherwise
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
264 * try splitting word. */
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
265 STATE_NOPREFIX, /* try without prefix */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
266 STATE_SPLITUNDO, /* Undo splitting. */
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
267 STATE_ENDNUL, /* Past NUL bytes at start of the node. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
268 STATE_PLAIN, /* Use each byte of the node. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
269 STATE_DEL, /* Delete a byte from the bad word. */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
270 STATE_INS_PREP, /* Prepare for inserting bytes. */
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
271 STATE_INS, /* Insert a byte in the bad word. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
272 STATE_SWAP, /* Swap two bytes. */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
273 STATE_UNSWAP, /* Undo swap two characters. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
274 STATE_SWAP3, /* Swap two characters over three. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
275 STATE_UNSWAP3, /* Undo Swap two characters over three. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
276 STATE_UNROT3L, /* Undo rotate three characters left */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
277 STATE_UNROT3R, /* Undo rotate three characters right */
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
278 STATE_REP_INI, /* Prepare for using REP items. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
279 STATE_REP, /* Use matching REP items from the .aff file. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
280 STATE_REP_UNDO, /* Undo a REP item replacement. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
281 STATE_FINAL /* End of this node. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
282 } state_T;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
283
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
284 /*
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
285 * Struct to keep the state at each level in suggest_try_change().
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
286 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
287 typedef struct trystate_S
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
288 {
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
289 state_T ts_state; /* state at this level, STATE_ */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
290 int ts_score; /* score */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
291 idx_T ts_arridx; /* index in tree array, start of node */
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
292 short ts_curi; /* index in list of child nodes */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
293 char_u ts_fidx; /* index in fword[], case-folded bad word */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
294 char_u ts_fidxtry; /* ts_fidx at which bytes may be changed */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
295 char_u ts_twordlen; /* valid length of tword[] */
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
296 char_u ts_prefixdepth; /* stack depth for end of prefix or
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
297 * PFD_PREFIXTREE or PFD_NOPREFIX */
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
298 char_u ts_flags; /* TSF_ flags */
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
299 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
300 char_u ts_tcharlen; /* number of bytes in tword character */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
301 char_u ts_tcharidx; /* current byte index in tword character */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
302 char_u ts_isdiff; /* DIFF_ values */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
303 char_u ts_fcharstart; /* index in fword where badword char started */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
304 #endif
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
305 char_u ts_prewordlen; /* length of word in "preword[]" */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
306 char_u ts_splitoff; /* index in "tword" after last split */
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
307 char_u ts_splitfidx; /* "ts_fidx" at word split */
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
308 char_u ts_complen; /* nr of compound words used */
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
309 char_u ts_compsplit; /* index for "compflags" where word was spit */
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
310 char_u ts_save_badflags; /* su_badflags saved here */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
311 char_u ts_delidx; /* index in fword for char that was deleted,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
312 valid when "ts_flags" has TSF_DIDDEL */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
313 } trystate_T;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
314
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
315 /* values for ts_isdiff */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
316 #define DIFF_NONE 0 /* no different byte (yet) */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
317 #define DIFF_YES 1 /* different byte found */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
318 #define DIFF_INSERT 2 /* inserting character */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
319
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
320 /* values for ts_flags */
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
321 #define TSF_PREFIXOK 1 /* already checked that prefix is OK */
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
322 #define TSF_DIDSPLIT 2 /* tried split at this point */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
323 #define TSF_DIDDEL 4 /* did a delete, "ts_delidx" has index */
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
324
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
325 /* special values ts_prefixdepth */
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
326 #define PFD_NOPREFIX 0xff /* not using prefixes */
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
327 #define PFD_PREFIXTREE 0xfe /* walking through the prefix tree */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
328 #define PFD_NOTSPECIAL 0xfd /* highest value that's not special */
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
329
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
330 /* mode values for find_word */
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
331 #define FIND_FOLDWORD 0 /* find word case-folded */
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
332 #define FIND_KEEPWORD 1 /* find keep-case word */
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
333 #define FIND_PREFIX 2 /* find word after prefix */
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
334 #define FIND_COMPOUND 3 /* find case-folded compound word */
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
335 #define FIND_KEEPCOMPOUND 4 /* find keep-case compound word */
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
336
7805
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
337 static void find_word(matchinf_T *mip, int mode);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
338 static int match_checkcompoundpattern(char_u *ptr, int wlen, garray_T *gap);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
339 static int can_compound(slang_T *slang, char_u *word, char_u *flags);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
340 static int can_be_compound(trystate_T *sp, slang_T *slang, char_u *compflags, int flag);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
341 static int match_compoundrule(slang_T *slang, char_u *compflags);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
342 static int valid_word_prefix(int totprefcnt, int arridx, int flags, char_u *word, slang_T *slang, int cond_req);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
343 static void find_prefix(matchinf_T *mip, int mode);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
344 static int fold_more(matchinf_T *mip);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
345 static int spell_valid_case(int wordflags, int treeflags);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
346 static int no_spell_checking(win_T *wp);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
347 static void spell_load_lang(char_u *lang);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
348 static void int_wordlist_spl(char_u *fname);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
349 static void spell_load_cb(char_u *fname, void *cookie);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
350 static int score_wordcount_adj(slang_T *slang, int score, char_u *word, int split);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
351 static int count_syllables(slang_T *slang, char_u *word);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
352 static void clear_midword(win_T *buf);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
353 static void use_midword(slang_T *lp, win_T *buf);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
354 static int find_region(char_u *rp, char_u *region);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
355 static int badword_captype(char_u *word, char_u *end);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
356 static int check_need_cap(linenr_T lnum, colnr_T col);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
357 static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int maxcount, int banbadword, int need_cap, int interactive);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
358 #ifdef FEAT_EVAL
7805
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
359 static void spell_suggest_expr(suginfo_T *su, char_u *expr);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
360 #endif
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
361 static void spell_suggest_file(suginfo_T *su, char_u *fname);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
362 static void spell_suggest_intern(suginfo_T *su, int interactive);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
363 static void spell_find_cleanup(suginfo_T *su);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
364 static void allcap_copy(char_u *word, char_u *wcopy);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
365 static void suggest_try_special(suginfo_T *su);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
366 static void suggest_try_change(suginfo_T *su);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
367 static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, int soundfold);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
368 static void go_deeper(trystate_T *stack, int depth, int score_add);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
369 #ifdef FEAT_MBYTE
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
370 static int nofold_len(char_u *fword, int flen, char_u *word);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
371 #endif
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
372 static void find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
373 static void score_comp_sal(suginfo_T *su);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
374 static void score_combine(suginfo_T *su);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
375 static int stp_sal_score(suggest_T *stp, suginfo_T *su, slang_T *slang, char_u *badsound);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
376 static void suggest_try_soundalike_prep(void);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
377 static void suggest_try_soundalike(suginfo_T *su);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
378 static void suggest_try_soundalike_finish(void);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
379 static void add_sound_suggest(suginfo_T *su, char_u *goodword, int score, langp_T *lp);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
380 static int soundfold_find(slang_T *slang, char_u *word);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
381 static void make_case_word(char_u *fword, char_u *cword, int flags);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
382 static int similar_chars(slang_T *slang, int c1, int c2);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
383 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);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
384 static void check_suggestions(suginfo_T *su, garray_T *gap);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
385 static void add_banned(suginfo_T *su, char_u *word);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
386 static void rescore_suggestions(suginfo_T *su);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
387 static void rescore_one(suginfo_T *su, suggest_T *stp);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
388 static int cleanup_suggestions(garray_T *gap, int maxscore, int keep);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
389 static void spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
390 static void spell_soundfold_sal(slang_T *slang, char_u *inword, char_u *res);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
391 #ifdef FEAT_MBYTE
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
392 static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
393 #endif
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
394 static int soundalike_score(char_u *goodsound, char_u *badsound);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
395 static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
396 static int spell_edit_score_limit(slang_T *slang, char_u *badword, char_u *goodword, int limit);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
397 #ifdef FEAT_MBYTE
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
398 static int spell_edit_score_limit_w(slang_T *slang, char_u *badword, char_u *goodword, int limit);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
399 #endif
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
400 static void dump_word(slang_T *slang, char_u *word, char_u *pat, int *dir, int round, int flags, linenr_T lnum);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
401 static linenr_T dump_prefixes(slang_T *slang, char_u *word, char_u *pat, int *dir, int round, int flags, linenr_T startlnum);
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
402
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
403
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
404 /* Remember what "z?" replaced. */
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
405 static char_u *repl_from = NULL;
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
406 static char_u *repl_to = NULL;
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
407
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
408 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
409 * Main spell-checking function.
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
410 * "ptr" points to a character that could be the start of a word.
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
411 * "*attrp" is set to the highlight index for a badly spelled word. For a
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
412 * non-word or when it's OK it remains unchanged.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
413 * This must only be called when 'spelllang' is not empty.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
414 *
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
415 * "capcol" is used to check for a Capitalised word after the end of a
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
416 * sentence. If it's zero then perform the check. Return the column where to
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
417 * check next, or -1 when no sentence end was found. If it's NULL then don't
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
418 * worry.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
419 *
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
420 * Returns the length of the word in bytes, also when it's OK, so that the
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
421 * caller can skip over the word.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
422 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
423 int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
424 spell_check(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
425 win_T *wp, /* current window */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
426 char_u *ptr,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
427 hlf_T *attrp,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
428 int *capcol, /* column to check for Capital */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
429 int docount) /* count good words */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
430 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
431 matchinf_T mi; /* Most things are put in "mi" so that it can
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
432 be passed to functions quickly. */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
433 int nrlen = 0; /* found a number first */
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
434 int c;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
435 int wrongcaplen = 0;
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
436 int lpi;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
437 int count_word = docount;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
438
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
439 /* A word never starts at a space or a control character. Return quickly
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
440 * then, skipping over the character. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
441 if (*ptr <= ' ')
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
442 return 1;
690
0e922220d322 updated for version 7.0208
vimboss
parents: 649
diff changeset
443
0e922220d322 updated for version 7.0208
vimboss
parents: 649
diff changeset
444 /* Return here when loading language files failed. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
445 if (wp->w_s->b_langp.ga_len == 0)
690
0e922220d322 updated for version 7.0208
vimboss
parents: 649
diff changeset
446 return 1;
0e922220d322 updated for version 7.0208
vimboss
parents: 649
diff changeset
447
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
448 vim_memset(&mi, 0, sizeof(matchinf_T));
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
449
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
450 /* A number is always OK. Also skip hexadecimal numbers 0xFF99 and
584
5953bf5509ec updated for version 7.0166
vimboss
parents: 548
diff changeset
451 * 0X99FF. But always do check spelling to find "3GPP" and "11
5953bf5509ec updated for version 7.0166
vimboss
parents: 548
diff changeset
452 * julifeest". */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
453 if (*ptr >= '0' && *ptr <= '9')
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
454 {
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
455 if (*ptr == '0' && (ptr[1] == 'b' || ptr[1] == 'B'))
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
456 mi.mi_end = skipbin(ptr + 2);
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
457 else if (*ptr == '0' && (ptr[1] == 'x' || ptr[1] == 'X'))
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
458 mi.mi_end = skiphex(ptr + 2);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
459 else
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
460 mi.mi_end = skipdigits(ptr);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
461 nrlen = (int)(mi.mi_end - ptr);
584
5953bf5509ec updated for version 7.0166
vimboss
parents: 548
diff changeset
462 }
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
463
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
464 /* Find the normal end of the word (until the next non-word character). */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
465 mi.mi_word = ptr;
584
5953bf5509ec updated for version 7.0166
vimboss
parents: 548
diff changeset
466 mi.mi_fend = ptr;
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
467 if (spell_iswordp(mi.mi_fend, wp))
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
468 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
469 do
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
470 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
471 mb_ptr_adv(mi.mi_fend);
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
472 } while (*mi.mi_fend != NUL && spell_iswordp(mi.mi_fend, wp));
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
473
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
474 if (capcol != NULL && *capcol == 0 && wp->w_s->b_cap_prog != NULL)
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
475 {
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
476 /* Check word starting with capital letter. */
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
477 c = PTR2CHAR(ptr);
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
478 if (!SPELL_ISUPPER(c))
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
479 wrongcaplen = (int)(mi.mi_fend - ptr);
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
480 }
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
481 }
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
482 if (capcol != NULL)
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
483 *capcol = -1;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
484
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
485 /* We always use the characters up to the next non-word character,
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
486 * also for bad words. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
487 mi.mi_end = mi.mi_fend;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
488
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
489 /* Check caps type later. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
490 mi.mi_capflags = 0;
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
491 mi.mi_cend = NULL;
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
492 mi.mi_win = wp;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
493
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
494 /* case-fold the word with one non-word character, so that we can check
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
495 * for the word end. */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
496 if (*mi.mi_fend != NUL)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
497 mb_ptr_adv(mi.mi_fend);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
498
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
499 (void)spell_casefold(ptr, (int)(mi.mi_fend - ptr), mi.mi_fword,
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
500 MAXWLEN + 1);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
501 mi.mi_fwordlen = (int)STRLEN(mi.mi_fword);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
502
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
503 /* The word is bad unless we recognize it. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
504 mi.mi_result = SP_BAD;
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
505 mi.mi_result2 = SP_BAD;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
506
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
507 /*
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
508 * Loop over the languages specified in 'spelllang'.
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
509 * We check them all, because a word may be matched longer in another
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
510 * language.
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
511 */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
512 for (lpi = 0; lpi < wp->w_s->b_langp.ga_len; ++lpi)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
513 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
514 mi.mi_lp = LANGP_ENTRY(wp->w_s->b_langp, lpi);
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
515
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
516 /* If reloading fails the language is still in the list but everything
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
517 * has been cleared. */
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
518 if (mi.mi_lp->lp_slang->sl_fidxs == NULL)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
519 continue;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
520
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
521 /* Check for a matching word in case-folded words. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
522 find_word(&mi, FIND_FOLDWORD);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
523
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
524 /* Check for a matching word in keep-case words. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
525 find_word(&mi, FIND_KEEPWORD);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
526
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
527 /* Check for matching prefixes. */
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
528 find_prefix(&mi, FIND_FOLDWORD);
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
529
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
530 /* For a NOBREAK language, may want to use a word without a following
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
531 * word as a backup. */
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
532 if (mi.mi_lp->lp_slang->sl_nobreak && mi.mi_result == SP_BAD
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
533 && mi.mi_result2 != SP_BAD)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
534 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
535 mi.mi_result = mi.mi_result2;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
536 mi.mi_end = mi.mi_end2;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
537 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
538
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
539 /* Count the word in the first language where it's found to be OK. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
540 if (count_word && mi.mi_result == SP_OK)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
541 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
542 count_common_word(mi.mi_lp->lp_slang, ptr,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
543 (int)(mi.mi_end - ptr), 1);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
544 count_word = FALSE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
545 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
546 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
547
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
548 if (mi.mi_result != SP_OK)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
549 {
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
550 /* If we found a number skip over it. Allows for "42nd". Do flag
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
551 * rare and local words, e.g., "3GPP". */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
552 if (nrlen > 0)
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
553 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
554 if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
555 return nrlen;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
556 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
557
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
558 /* When we are at a non-word character there is no error, just
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
559 * skip over the character (try looking for a word after it). */
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
560 else if (!spell_iswordp_nmw(ptr, wp))
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
561 {
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
562 if (capcol != NULL && wp->w_s->b_cap_prog != NULL)
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
563 {
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
564 regmatch_T regmatch;
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
565 int r;
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
566
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
567 /* Check for end of sentence. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
568 regmatch.regprog = wp->w_s->b_cap_prog;
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
569 regmatch.rm_ic = FALSE;
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
570 r = vim_regexec(&regmatch, ptr, 0);
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
571 wp->w_s->b_cap_prog = regmatch.regprog;
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
572 if (r)
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
573 *capcol = (int)(regmatch.endp[0] - ptr);
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
574 }
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
575
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
576 #ifdef FEAT_MBYTE
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
577 if (has_mbyte)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
578 return (*mb_ptr2len)(ptr);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
579 #endif
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
580 return 1;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
581 }
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
582 else if (mi.mi_end == ptr)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
583 /* Always include at least one character. Required for when there
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
584 * is a mixup in "midword". */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
585 mb_ptr_adv(mi.mi_end);
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
586 else if (mi.mi_result == SP_BAD
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
587 && LANGP_ENTRY(wp->w_s->b_langp, 0)->lp_slang->sl_nobreak)
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
588 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
589 char_u *p, *fp;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
590 int save_result = mi.mi_result;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
591
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
592 /* First language in 'spelllang' is NOBREAK. Find first position
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
593 * at which any word would be valid. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
594 mi.mi_lp = LANGP_ENTRY(wp->w_s->b_langp, 0);
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
595 if (mi.mi_lp->lp_slang->sl_fidxs != NULL)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
596 {
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
597 p = mi.mi_word;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
598 fp = mi.mi_fword;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
599 for (;;)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
600 {
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
601 mb_ptr_adv(p);
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
602 mb_ptr_adv(fp);
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
603 if (p >= mi.mi_end)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
604 break;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
605 mi.mi_compoff = (int)(fp - mi.mi_fword);
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
606 find_word(&mi, FIND_COMPOUND);
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
607 if (mi.mi_result != SP_BAD)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
608 {
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
609 mi.mi_end = p;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
610 break;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
611 }
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
612 }
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
613 mi.mi_result = save_result;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
614 }
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
615 }
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
616
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
617 if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED)
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
618 *attrp = HLF_SPB;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
619 else if (mi.mi_result == SP_RARE)
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
620 *attrp = HLF_SPR;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
621 else
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
622 *attrp = HLF_SPL;
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
623 }
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
624
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
625 if (wrongcaplen > 0 && (mi.mi_result == SP_OK || mi.mi_result == SP_RARE))
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
626 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
627 /* Report SpellCap only when the word isn't badly spelled. */
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
628 *attrp = HLF_SPC;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
629 return wrongcaplen;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
630 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
631
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
632 return (int)(mi.mi_end - ptr);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
633 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
634
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
635 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
636 * Check if the word at "mip->mi_word" is in the tree.
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
637 * When "mode" is FIND_FOLDWORD check in fold-case word tree.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
638 * When "mode" is FIND_KEEPWORD check in keep-case word tree.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
639 * When "mode" is FIND_PREFIX check for word after prefix in fold-case word
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
640 * tree.
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
641 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
642 * For a match mip->mi_result is updated.
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
643 */
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
644 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
645 find_word(matchinf_T *mip, int mode)
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
646 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
647 idx_T arridx = 0;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
648 int endlen[MAXWLEN]; /* length at possible word endings */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
649 idx_T endidx[MAXWLEN]; /* possible word endings */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
650 int endidxcnt = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
651 int len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
652 int wlen = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
653 int flen;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
654 int c;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
655 char_u *ptr;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
656 idx_T lo, hi, m;
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
657 #ifdef FEAT_MBYTE
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
658 char_u *s;
490
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
659 #endif
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
660 char_u *p;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
661 int res = SP_BAD;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
662 slang_T *slang = mip->mi_lp->lp_slang;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
663 unsigned flags;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
664 char_u *byts;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
665 idx_T *idxs;
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
666 int word_ends;
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
667 int prefix_found;
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
668 int nobreak_result;
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
669
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
670 if (mode == FIND_KEEPWORD || mode == FIND_KEEPCOMPOUND)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
671 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
672 /* Check for word with matching case in keep-case tree. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
673 ptr = mip->mi_word;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
674 flen = 9999; /* no case folding, always enough bytes */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
675 byts = slang->sl_kbyts;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
676 idxs = slang->sl_kidxs;
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
677
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
678 if (mode == FIND_KEEPCOMPOUND)
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
679 /* Skip over the previously found word(s). */
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
680 wlen += mip->mi_compoff;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
681 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
682 else
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
683 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
684 /* Check for case-folded in case-folded tree. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
685 ptr = mip->mi_fword;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
686 flen = mip->mi_fwordlen; /* available case-folded bytes */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
687 byts = slang->sl_fbyts;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
688 idxs = slang->sl_fidxs;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
689
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
690 if (mode == FIND_PREFIX)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
691 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
692 /* Skip over the prefix. */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
693 wlen = mip->mi_prefixlen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
694 flen -= mip->mi_prefixlen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
695 }
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
696 else if (mode == FIND_COMPOUND)
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
697 {
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
698 /* Skip over the previously found word(s). */
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
699 wlen = mip->mi_compoff;
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
700 flen -= mip->mi_compoff;
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
701 }
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
702
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
703 }
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
704
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
705 if (byts == NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
706 return; /* array is empty */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
707
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
708 /*
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
709 * Repeat advancing in the tree until:
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
710 * - there is a byte that doesn't match,
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
711 * - we reach the end of the tree,
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
712 * - or we reach the end of the line.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
713 */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
714 for (;;)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
715 {
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
716 if (flen <= 0 && *mip->mi_fend != NUL)
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
717 flen = fold_more(mip);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
718
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
719 len = byts[arridx++];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
720
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
721 /* If the first possible byte is a zero the word could end here.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
722 * Remember this index, we first check for the longest word. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
723 if (byts[arridx] == 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
724 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
725 if (endidxcnt == MAXWLEN)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
726 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
727 /* Must be a corrupted spell file. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
728 EMSG(_(e_format));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
729 return;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
730 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
731 endlen[endidxcnt] = wlen;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
732 endidx[endidxcnt++] = arridx++;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
733 --len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
734
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
735 /* Skip over the zeros, there can be several flag/region
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
736 * combinations. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
737 while (len > 0 && byts[arridx] == 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
738 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
739 ++arridx;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
740 --len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
741 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
742 if (len == 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
743 break; /* no children, word must end here */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
744 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
745
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
746 /* Stop looking at end of the line. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
747 if (ptr[wlen] == NUL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
748 break;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
749
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
750 /* Perform a binary search in the list of accepted bytes. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
751 c = ptr[wlen];
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
752 if (c == TAB) /* <Tab> is handled like <Space> */
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
753 c = ' ';
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
754 lo = arridx;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
755 hi = arridx + len - 1;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
756 while (lo < hi)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
757 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
758 m = (lo + hi) / 2;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
759 if (byts[m] > c)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
760 hi = m - 1;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
761 else if (byts[m] < c)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
762 lo = m + 1;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
763 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
764 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
765 lo = hi = m;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
766 break;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
767 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
768 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
769
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
770 /* Stop if there is no matching byte. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
771 if (hi < lo || byts[lo] != c)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
772 break;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
773
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
774 /* Continue at the child (if there is one). */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
775 arridx = idxs[lo];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
776 ++wlen;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
777 --flen;
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
778
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
779 /* One space in the good word may stand for several spaces in the
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
780 * checked word. */
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
781 if (c == ' ')
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
782 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
783 for (;;)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
784 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
785 if (flen <= 0 && *mip->mi_fend != NUL)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
786 flen = fold_more(mip);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
787 if (ptr[wlen] != ' ' && ptr[wlen] != TAB)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
788 break;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
789 ++wlen;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
790 --flen;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
791 }
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
792 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
793 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
794
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
795 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
796 * Verify that one of the possible endings is valid. Try the longest
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
797 * first.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
798 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
799 while (endidxcnt > 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
800 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
801 --endidxcnt;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
802 arridx = endidx[endidxcnt];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
803 wlen = endlen[endidxcnt];
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
804
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
805 #ifdef FEAT_MBYTE
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
806 if ((*mb_head_off)(ptr, ptr + wlen) > 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
807 continue; /* not at first byte of character */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
808 #endif
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
809 if (spell_iswordp(ptr + wlen, mip->mi_win))
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
810 {
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
811 if (slang->sl_compprog == NULL && !slang->sl_nobreak)
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
812 continue; /* next char is a word character */
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
813 word_ends = FALSE;
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
814 }
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
815 else
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
816 word_ends = TRUE;
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
817 /* The prefix flag is before compound flags. Once a valid prefix flag
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
818 * has been found we try compound flags. */
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
819 prefix_found = FALSE;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
820
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
821 #ifdef FEAT_MBYTE
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
822 if (mode != FIND_KEEPWORD && has_mbyte)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
823 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
824 /* Compute byte length in original word, length may change
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
825 * when folding case. This can be slow, take a shortcut when the
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
826 * case-folded word is equal to the keep-case word. */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
827 p = mip->mi_word;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
828 if (STRNCMP(ptr, p, wlen) != 0)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
829 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
830 for (s = ptr; s < ptr + wlen; mb_ptr_adv(s))
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
831 mb_ptr_adv(p);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
832 wlen = (int)(p - mip->mi_word);
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
833 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
834 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
835 #endif
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
836
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
837 /* Check flags and region. For FIND_PREFIX check the condition and
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
838 * prefix ID.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
839 * Repeat this if there are more flags/region alternatives until there
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
840 * is a match. */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
841 res = SP_BAD;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
842 for (len = byts[arridx - 1]; len > 0 && byts[arridx] == 0;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
843 --len, ++arridx)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
844 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
845 flags = idxs[arridx];
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
846
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
847 /* For the fold-case tree check that the case of the checked word
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
848 * matches with what the word in the tree requires.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
849 * For keep-case tree the case is always right. For prefixes we
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
850 * don't bother to check. */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
851 if (mode == FIND_FOLDWORD)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
852 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
853 if (mip->mi_cend != mip->mi_word + wlen)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
854 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
855 /* mi_capflags was set for a different word length, need
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
856 * to do it again. */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
857 mip->mi_cend = mip->mi_word + wlen;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
858 mip->mi_capflags = captype(mip->mi_word, mip->mi_cend);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
859 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
860
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
861 if (mip->mi_capflags == WF_KEEPCAP
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
862 || !spell_valid_case(mip->mi_capflags, flags))
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
863 continue;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
864 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
865
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
866 /* When mode is FIND_PREFIX the word must support the prefix:
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
867 * check the prefix ID and the condition. Do that for the list at
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
868 * mip->mi_prefarridx that find_prefix() filled. */
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
869 else if (mode == FIND_PREFIX && !prefix_found)
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
870 {
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
871 c = valid_word_prefix(mip->mi_prefcnt, mip->mi_prefarridx,
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
872 flags,
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
873 mip->mi_word + mip->mi_cprefixlen, slang,
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
874 FALSE);
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
875 if (c == 0)
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
876 continue;
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
877
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
878 /* Use the WF_RARE flag for a rare prefix. */
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
879 if (c & WF_RAREPFX)
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
880 flags |= WF_RARE;
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
881 prefix_found = TRUE;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
882 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
883
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
884 if (slang->sl_nobreak)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
885 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
886 if ((mode == FIND_COMPOUND || mode == FIND_KEEPCOMPOUND)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
887 && (flags & WF_BANNED) == 0)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
888 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
889 /* NOBREAK: found a valid following word. That's all we
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
890 * need to know, so return. */
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
891 mip->mi_result = SP_OK;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
892 break;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
893 }
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
894 }
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
895
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
896 else if ((mode == FIND_COMPOUND || mode == FIND_KEEPCOMPOUND
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
897 || !word_ends))
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
898 {
974
ed44c1c436d3 updated for version 7.0-100
vimboss
parents: 944
diff changeset
899 /* If there is no compound flag or the word is shorter than
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
900 * COMPOUNDMIN reject it quickly.
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
901 * Makes you wonder why someone puts a compound flag on a word
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
902 * that's too short... Myspell compatibility requires this
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
903 * anyway. */
490
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
904 if (((unsigned)flags >> 24) == 0
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
905 || wlen - mip->mi_compoff < slang->sl_compminlen)
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
906 continue;
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
907 #ifdef FEAT_MBYTE
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
908 /* For multi-byte chars check character length against
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
909 * COMPOUNDMIN. */
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
910 if (has_mbyte
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
911 && slang->sl_compminlen > 0
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
912 && mb_charlen_len(mip->mi_word + mip->mi_compoff,
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
913 wlen - mip->mi_compoff) < slang->sl_compminlen)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
914 continue;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
915 #endif
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
916
809
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
917 /* Limit the number of compound words to COMPOUNDWORDMAX if no
490
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
918 * maximum for syllables is specified. */
809
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
919 if (!word_ends && mip->mi_complen + mip->mi_compextra + 2
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
920 > slang->sl_compmax
490
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
921 && slang->sl_compsylmax == MAXWLEN)
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
922 continue;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
923
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
924 /* Don't allow compounding on a side where an affix was added,
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
925 * unless COMPOUNDPERMITFLAG was used. */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
926 if (mip->mi_complen > 0 && (flags & WF_NOCOMPBEF))
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
927 continue;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
928 if (!word_ends && (flags & WF_NOCOMPAFT))
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
929 continue;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
930
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
931 /* Quickly check if compounding is possible with this flag. */
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
932 if (!byte_in_str(mip->mi_complen == 0
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
933 ? slang->sl_compstartflags
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
934 : slang->sl_compallflags,
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
935 ((unsigned)flags >> 24)))
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
936 continue;
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
937
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
938 /* If there is a match with a CHECKCOMPOUNDPATTERN rule
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
939 * discard the compound word. */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
940 if (match_checkcompoundpattern(ptr, wlen, &slang->sl_comppat))
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
941 continue;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
942
490
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
943 if (mode == FIND_COMPOUND)
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
944 {
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
945 int capflags;
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
946
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
947 /* Need to check the caps type of the appended compound
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
948 * word. */
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
949 #ifdef FEAT_MBYTE
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
950 if (has_mbyte && STRNCMP(ptr, mip->mi_word,
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
951 mip->mi_compoff) != 0)
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
952 {
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
953 /* case folding may have changed the length */
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
954 p = mip->mi_word;
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
955 for (s = ptr; s < ptr + mip->mi_compoff; mb_ptr_adv(s))
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
956 mb_ptr_adv(p);
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
957 }
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
958 else
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
959 #endif
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
960 p = mip->mi_word + mip->mi_compoff;
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
961 capflags = captype(p, mip->mi_word + wlen);
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
962 if (capflags == WF_KEEPCAP || (capflags == WF_ALLCAP
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
963 && (flags & WF_FIXCAP) != 0))
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
964 continue;
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
965
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
966 if (capflags != WF_ALLCAP)
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
967 {
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
968 /* When the character before the word is a word
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
969 * character we do not accept a Onecap word. We do
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
970 * accept a no-caps word, even when the dictionary
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
971 * word specifies ONECAP. */
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
972 mb_ptr_back(mip->mi_word, p);
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
973 if (spell_iswordp_nmw(p, mip->mi_win)
490
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
974 ? capflags == WF_ONECAP
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
975 : (flags & WF_ONECAP) != 0
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
976 && capflags != WF_ONECAP)
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
977 continue;
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
978 }
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
979 }
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
980
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
981 /* If the word ends the sequence of compound flags of the
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
982 * words must match with one of the COMPOUNDRULE items and
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
983 * the number of syllables must not be too large. */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
984 mip->mi_compflags[mip->mi_complen] = ((unsigned)flags >> 24);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
985 mip->mi_compflags[mip->mi_complen + 1] = NUL;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
986 if (word_ends)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
987 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
988 char_u fword[MAXWLEN];
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
989
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
990 if (slang->sl_compsylmax < MAXWLEN)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
991 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
992 /* "fword" is only needed for checking syllables. */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
993 if (ptr == mip->mi_word)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
994 (void)spell_casefold(ptr, wlen, fword, MAXWLEN);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
995 else
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
996 vim_strncpy(fword, ptr, endlen[endidxcnt]);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
997 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
998 if (!can_compound(slang, fword, mip->mi_compflags))
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
999 continue;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1000 }
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1001 else if (slang->sl_comprules != NULL
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1002 && !match_compoundrule(slang, mip->mi_compflags))
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1003 /* The compound flags collected so far do not match any
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1004 * COMPOUNDRULE, discard the compounded word. */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1005 continue;
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1006 }
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1007
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1008 /* Check NEEDCOMPOUND: can't use word without compounding. */
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1009 else if (flags & WF_NEEDCOMP)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1010 continue;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1011
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1012 nobreak_result = SP_OK;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1013
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1014 if (!word_ends)
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1015 {
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1016 int save_result = mip->mi_result;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1017 char_u *save_end = mip->mi_end;
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1018 langp_T *save_lp = mip->mi_lp;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1019 int lpi;
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1020
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1021 /* Check that a valid word follows. If there is one and we
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1022 * are compounding, it will set "mi_result", thus we are
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1023 * always finished here. For NOBREAK we only check that a
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1024 * valid word follows.
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1025 * Recursive! */
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1026 if (slang->sl_nobreak)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1027 mip->mi_result = SP_BAD;
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1028
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1029 /* Find following word in case-folded tree. */
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1030 mip->mi_compoff = endlen[endidxcnt];
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1031 #ifdef FEAT_MBYTE
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1032 if (has_mbyte && mode == FIND_KEEPWORD)
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1033 {
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1034 /* Compute byte length in case-folded word from "wlen":
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1035 * byte length in keep-case word. Length may change when
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1036 * folding case. This can be slow, take a shortcut when
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1037 * the case-folded word is equal to the keep-case word. */
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1038 p = mip->mi_fword;
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1039 if (STRNCMP(ptr, p, wlen) != 0)
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1040 {
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1041 for (s = ptr; s < ptr + wlen; mb_ptr_adv(s))
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1042 mb_ptr_adv(p);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1043 mip->mi_compoff = (int)(p - mip->mi_fword);
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1044 }
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1045 }
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1046 #endif
8956
d9e671c5afe6 commit https://github.com/vim/vim/commit/ba53435144f46eaaa53c63a62e748b3feee9742c
Christian Brabandt <cb@256bit.org>
parents: 8524
diff changeset
1047 #if 0 /* Disabled, see below */
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1048 c = mip->mi_compoff;
8956
d9e671c5afe6 commit https://github.com/vim/vim/commit/ba53435144f46eaaa53c63a62e748b3feee9742c
Christian Brabandt <cb@256bit.org>
parents: 8524
diff changeset
1049 #endif
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1050 ++mip->mi_complen;
809
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
1051 if (flags & WF_COMPROOT)
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
1052 ++mip->mi_compextra;
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1053
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1054 /* For NOBREAK we need to try all NOBREAK languages, at least
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1055 * to find the ".add" file(s). */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1056 for (lpi = 0; lpi < mip->mi_win->w_s->b_langp.ga_len; ++lpi)
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1057 {
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1058 if (slang->sl_nobreak)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1059 {
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1060 mip->mi_lp = LANGP_ENTRY(mip->mi_win->w_s->b_langp, lpi);
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1061 if (mip->mi_lp->lp_slang->sl_fidxs == NULL
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1062 || !mip->mi_lp->lp_slang->sl_nobreak)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1063 continue;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1064 }
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1065
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1066 find_word(mip, FIND_COMPOUND);
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1067
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1068 /* When NOBREAK any word that matches is OK. Otherwise we
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1069 * need to find the longest match, thus try with keep-case
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1070 * and prefix too. */
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1071 if (!slang->sl_nobreak || mip->mi_result == SP_BAD)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1072 {
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1073 /* Find following word in keep-case tree. */
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1074 mip->mi_compoff = wlen;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1075 find_word(mip, FIND_KEEPCOMPOUND);
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1076
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
1077 #if 0 /* Disabled, a prefix must not appear halfway a compound word,
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
1078 unless the COMPOUNDPERMITFLAG is used and then it can't be a
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
1079 postponed prefix. */
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1080 if (!slang->sl_nobreak || mip->mi_result == SP_BAD)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1081 {
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1082 /* Check for following word with prefix. */
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1083 mip->mi_compoff = c;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1084 find_prefix(mip, FIND_COMPOUND);
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1085 }
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
1086 #endif
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1087 }
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1088
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1089 if (!slang->sl_nobreak)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1090 break;
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1091 }
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1092 --mip->mi_complen;
809
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
1093 if (flags & WF_COMPROOT)
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
1094 --mip->mi_compextra;
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1095 mip->mi_lp = save_lp;
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1096
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1097 if (slang->sl_nobreak)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1098 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1099 nobreak_result = mip->mi_result;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1100 mip->mi_result = save_result;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1101 mip->mi_end = save_end;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1102 }
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1103 else
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1104 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1105 if (mip->mi_result == SP_OK)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1106 break;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1107 continue;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1108 }
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1109 }
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1110
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1111 if (flags & WF_BANNED)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1112 res = SP_BANNED;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1113 else if (flags & WF_REGION)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1114 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1115 /* Check region. */
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1116 if ((mip->mi_lp->lp_region & (flags >> 16)) != 0)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1117 res = SP_OK;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1118 else
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1119 res = SP_LOCAL;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1120 }
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1121 else if (flags & WF_RARE)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1122 res = SP_RARE;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1123 else
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1124 res = SP_OK;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1125
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1126 /* Always use the longest match and the best result. For NOBREAK
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1127 * we separately keep the longest match without a following good
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1128 * word as a fall-back. */
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1129 if (nobreak_result == SP_BAD)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1130 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1131 if (mip->mi_result2 > res)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1132 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1133 mip->mi_result2 = res;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1134 mip->mi_end2 = mip->mi_word + wlen;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1135 }
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1136 else if (mip->mi_result2 == res
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1137 && mip->mi_end2 < mip->mi_word + wlen)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1138 mip->mi_end2 = mip->mi_word + wlen;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1139 }
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1140 else if (mip->mi_result > res)
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1141 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1142 mip->mi_result = res;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1143 mip->mi_end = mip->mi_word + wlen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1144 }
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1145 else if (mip->mi_result == res && mip->mi_end < mip->mi_word + wlen)
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1146 mip->mi_end = mip->mi_word + wlen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1147
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1148 if (mip->mi_result == SP_OK)
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1149 break;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1150 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1151
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
1152 if (mip->mi_result == SP_OK)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1153 break;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1154 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1155 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1156
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1157 /*
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1158 * Return TRUE if there is a match between the word ptr[wlen] and
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1159 * CHECKCOMPOUNDPATTERN rules, assuming that we will concatenate with another
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1160 * word.
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1161 * A match means that the first part of CHECKCOMPOUNDPATTERN matches at the
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1162 * end of ptr[wlen] and the second part matches after it.
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1163 */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1164 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1165 match_checkcompoundpattern(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1166 char_u *ptr,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1167 int wlen,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1168 garray_T *gap) /* &sl_comppat */
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1169 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1170 int i;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1171 char_u *p;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1172 int len;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1173
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1174 for (i = 0; i + 1 < gap->ga_len; i += 2)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1175 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1176 p = ((char_u **)gap->ga_data)[i + 1];
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1177 if (STRNCMP(ptr + wlen, p, STRLEN(p)) == 0)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1178 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1179 /* Second part matches at start of following compound word, now
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1180 * check if first part matches at end of previous word. */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1181 p = ((char_u **)gap->ga_data)[i];
1771
1f90fab89ce3 updated for version 7.2-069
vimboss
parents: 1762
diff changeset
1182 len = (int)STRLEN(p);
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1183 if (len <= wlen && STRNCMP(ptr + wlen - len, p, len) == 0)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1184 return TRUE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1185 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1186 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1187 return FALSE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1188 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1189
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1190 /*
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
1191 * Return TRUE if "flags" is a valid sequence of compound flags and "word"
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
1192 * does not have too many syllables.
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
1193 */
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
1194 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1195 can_compound(slang_T *slang, char_u *word, char_u *flags)
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1196 {
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1197 #ifdef FEAT_MBYTE
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1198 char_u uflags[MAXWLEN * 2];
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1199 int i;
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1200 #endif
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1201 char_u *p;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1202
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1203 if (slang->sl_compprog == NULL)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1204 return FALSE;
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1205 #ifdef FEAT_MBYTE
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1206 if (enc_utf8)
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1207 {
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1208 /* Need to convert the single byte flags to utf8 characters. */
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1209 p = uflags;
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1210 for (i = 0; flags[i] != NUL; ++i)
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1211 p += mb_char2bytes(flags[i], p);
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1212 *p = NUL;
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1213 p = uflags;
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1214 }
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1215 else
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1216 #endif
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1217 p = flags;
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
1218 if (!vim_regexec_prog(&slang->sl_compprog, FALSE, p, 0))
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1219 return FALSE;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1220
490
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
1221 /* Count the number of syllables. This may be slow, do it last. If there
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
1222 * are too many syllables AND the number of compound words is above
809
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
1223 * COMPOUNDWORDMAX then compounding is not allowed. */
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1224 if (slang->sl_compsylmax < MAXWLEN
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1225 && count_syllables(slang, word) > slang->sl_compsylmax)
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1226 return (int)STRLEN(flags) < slang->sl_compmax;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1227 return TRUE;
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
1228 }
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
1229
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
1230 /*
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1231 * Return TRUE when the sequence of flags in "compflags" plus "flag" can
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1232 * possibly form a valid compounded word. This also checks the COMPOUNDRULE
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1233 * lines if they don't contain wildcards.
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1234 */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1235 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1236 can_be_compound(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1237 trystate_T *sp,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1238 slang_T *slang,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1239 char_u *compflags,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1240 int flag)
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1241 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1242 /* If the flag doesn't appear in sl_compstartflags or sl_compallflags
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1243 * then it can't possibly compound. */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1244 if (!byte_in_str(sp->ts_complen == sp->ts_compsplit
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1245 ? slang->sl_compstartflags : slang->sl_compallflags, flag))
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1246 return FALSE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1247
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1248 /* If there are no wildcards, we can check if the flags collected so far
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1249 * possibly can form a match with COMPOUNDRULE patterns. This only
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1250 * makes sense when we have two or more words. */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1251 if (slang->sl_comprules != NULL && sp->ts_complen > sp->ts_compsplit)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1252 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1253 int v;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1254
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1255 compflags[sp->ts_complen] = flag;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1256 compflags[sp->ts_complen + 1] = NUL;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1257 v = match_compoundrule(slang, compflags + sp->ts_compsplit);
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1258 compflags[sp->ts_complen] = NUL;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1259 return v;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1260 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1261
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1262 return TRUE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1263 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1264
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1265
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1266 /*
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1267 * Return TRUE if the compound flags in compflags[] match the start of any
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1268 * compound rule. This is used to stop trying a compound if the flags
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1269 * collected so far can't possibly match any compound rule.
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1270 * Caller must check that slang->sl_comprules is not NULL.
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1271 */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1272 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1273 match_compoundrule(slang_T *slang, char_u *compflags)
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1274 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1275 char_u *p;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1276 int i;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1277 int c;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1278
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1279 /* loop over all the COMPOUNDRULE entries */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1280 for (p = slang->sl_comprules; *p != NUL; ++p)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1281 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1282 /* loop over the flags in the compound word we have made, match
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1283 * them against the current rule entry */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1284 for (i = 0; ; ++i)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1285 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1286 c = compflags[i];
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1287 if (c == NUL)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1288 /* found a rule that matches for the flags we have so far */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1289 return TRUE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1290 if (*p == '/' || *p == NUL)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1291 break; /* end of rule, it's too short */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1292 if (*p == '[')
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1293 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1294 int match = FALSE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1295
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1296 /* compare against all the flags in [] */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1297 ++p;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1298 while (*p != ']' && *p != NUL)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1299 if (*p++ == c)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1300 match = TRUE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1301 if (!match)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1302 break; /* none matches */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1303 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1304 else if (*p != c)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1305 break; /* flag of word doesn't match flag in pattern */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1306 ++p;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1307 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1308
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1309 /* Skip to the next "/", where the next pattern starts. */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1310 p = vim_strchr(p, '/');
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1311 if (p == NULL)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1312 break;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1313 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1314
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1315 /* Checked all the rules and none of them match the flags, so there
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1316 * can't possibly be a compound starting with these flags. */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1317 return FALSE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1318 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1319
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1320 /*
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1321 * Return non-zero if the prefix indicated by "arridx" matches with the prefix
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1322 * ID in "flags" for the word "word".
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
1323 * The WF_RAREPFX flag is included in the return value for a rare prefix.
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1324 */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1325 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1326 valid_word_prefix(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1327 int totprefcnt, /* nr of prefix IDs */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1328 int arridx, /* idx in sl_pidxs[] */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1329 int flags,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1330 char_u *word,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1331 slang_T *slang,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1332 int cond_req) /* only use prefixes with a condition */
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1333 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1334 int prefcnt;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1335 int pidx;
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
1336 regprog_T **rp;
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1337 int prefid;
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1338
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1339 prefid = (unsigned)flags >> 24;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1340 for (prefcnt = totprefcnt - 1; prefcnt >= 0; --prefcnt)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1341 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1342 pidx = slang->sl_pidxs[arridx + prefcnt];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1343
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1344 /* Check the prefix ID. */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1345 if (prefid != (pidx & 0xff))
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1346 continue;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1347
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1348 /* Check if the prefix doesn't combine and the word already has a
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1349 * suffix. */
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1350 if ((flags & WF_HAS_AFF) && (pidx & WF_PFX_NC))
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1351 continue;
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1352
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1353 /* Check the condition, if there is one. The condition index is
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
1354 * stored in the two bytes above the prefix ID byte. */
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
1355 rp = &slang->sl_prefprog[((unsigned)pidx >> 8) & 0xffff];
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
1356 if (*rp != NULL)
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
1357 {
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
1358 if (!vim_regexec_prog(rp, FALSE, word, 0))
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1359 continue;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1360 }
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1361 else if (cond_req)
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1362 continue;
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1363
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1364 /* It's a match! Return the WF_ flags. */
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
1365 return pidx;
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
1366 }
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
1367 return 0;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1368 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1369
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1370 /*
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1371 * Check if the word at "mip->mi_word" has a matching prefix.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1372 * If it does, then check the following word.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1373 *
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1374 * If "mode" is "FIND_COMPOUND" then do the same after another word, find a
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1375 * prefix in a compound word.
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1376 *
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1377 * For a match mip->mi_result is updated.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1378 */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1379 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1380 find_prefix(matchinf_T *mip, int mode)
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1381 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1382 idx_T arridx = 0;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1383 int len;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1384 int wlen = 0;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1385 int flen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1386 int c;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1387 char_u *ptr;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1388 idx_T lo, hi, m;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1389 slang_T *slang = mip->mi_lp->lp_slang;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1390 char_u *byts;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1391 idx_T *idxs;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1392
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
1393 byts = slang->sl_pbyts;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
1394 if (byts == NULL)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
1395 return; /* array is empty */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
1396
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1397 /* We use the case-folded word here, since prefixes are always
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1398 * case-folded. */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1399 ptr = mip->mi_fword;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1400 flen = mip->mi_fwordlen; /* available case-folded bytes */
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1401 if (mode == FIND_COMPOUND)
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1402 {
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1403 /* Skip over the previously found word(s). */
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1404 ptr += mip->mi_compoff;
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1405 flen -= mip->mi_compoff;
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1406 }
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1407 idxs = slang->sl_pidxs;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1408
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1409 /*
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1410 * Repeat advancing in the tree until:
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1411 * - there is a byte that doesn't match,
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1412 * - we reach the end of the tree,
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1413 * - or we reach the end of the line.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1414 */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1415 for (;;)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1416 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1417 if (flen == 0 && *mip->mi_fend != NUL)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1418 flen = fold_more(mip);
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1419
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1420 len = byts[arridx++];
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1421
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1422 /* If the first possible byte is a zero the prefix could end here.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1423 * Check if the following word matches and supports the prefix. */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1424 if (byts[arridx] == 0)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1425 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1426 /* There can be several prefixes with different conditions. We
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1427 * try them all, since we don't know which one will give the
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1428 * longest match. The word is the same each time, pass the list
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1429 * of possible prefixes to find_word(). */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1430 mip->mi_prefarridx = arridx;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1431 mip->mi_prefcnt = len;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1432 while (len > 0 && byts[arridx] == 0)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1433 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1434 ++arridx;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1435 --len;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1436 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1437 mip->mi_prefcnt -= len;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1438
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1439 /* Find the word that comes after the prefix. */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1440 mip->mi_prefixlen = wlen;
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1441 if (mode == FIND_COMPOUND)
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1442 /* Skip over the previously found word(s). */
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1443 mip->mi_prefixlen += mip->mi_compoff;
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1444
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1445 #ifdef FEAT_MBYTE
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1446 if (has_mbyte)
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1447 {
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1448 /* Case-folded length may differ from original length. */
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1449 mip->mi_cprefixlen = nofold_len(mip->mi_fword,
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1450 mip->mi_prefixlen, mip->mi_word);
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1451 }
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1452 else
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1453 mip->mi_cprefixlen = mip->mi_prefixlen;
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1454 #endif
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1455 find_word(mip, FIND_PREFIX);
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1456
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1457
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1458 if (len == 0)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1459 break; /* no children, word must end here */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1460 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1461
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1462 /* Stop looking at end of the line. */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1463 if (ptr[wlen] == NUL)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1464 break;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1465
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1466 /* Perform a binary search in the list of accepted bytes. */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1467 c = ptr[wlen];
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1468 lo = arridx;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1469 hi = arridx + len - 1;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1470 while (lo < hi)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1471 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1472 m = (lo + hi) / 2;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1473 if (byts[m] > c)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1474 hi = m - 1;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1475 else if (byts[m] < c)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1476 lo = m + 1;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1477 else
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1478 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1479 lo = hi = m;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1480 break;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1481 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1482 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1483
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1484 /* Stop if there is no matching byte. */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1485 if (hi < lo || byts[lo] != c)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1486 break;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1487
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1488 /* Continue at the child (if there is one). */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1489 arridx = idxs[lo];
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1490 ++wlen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1491 --flen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1492 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1493 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1494
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1495 /*
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1496 * Need to fold at least one more character. Do until next non-word character
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
1497 * for efficiency. Include the non-word character too.
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1498 * Return the length of the folded chars in bytes.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1499 */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1500 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1501 fold_more(matchinf_T *mip)
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1502 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1503 int flen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1504 char_u *p;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1505
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1506 p = mip->mi_fend;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1507 do
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1508 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1509 mb_ptr_adv(mip->mi_fend);
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1510 } while (*mip->mi_fend != NUL && spell_iswordp(mip->mi_fend, mip->mi_win));
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1511
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
1512 /* Include the non-word character so that we can check for the word end. */
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1513 if (*mip->mi_fend != NUL)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1514 mb_ptr_adv(mip->mi_fend);
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1515
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1516 (void)spell_casefold(p, (int)(mip->mi_fend - p),
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1517 mip->mi_fword + mip->mi_fwordlen,
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1518 MAXWLEN - mip->mi_fwordlen);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1519 flen = (int)STRLEN(mip->mi_fword + mip->mi_fwordlen);
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1520 mip->mi_fwordlen += flen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1521 return flen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1522 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1523
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1524 /*
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1525 * Check case flags for a word. Return TRUE if the word has the requested
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1526 * case.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1527 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1528 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1529 spell_valid_case(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1530 int wordflags, /* flags for the checked word. */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1531 int treeflags) /* flags for the word in the spell tree */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1532 {
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
1533 return ((wordflags == WF_ALLCAP && (treeflags & WF_FIXCAP) == 0)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1534 || ((treeflags & (WF_ALLCAP | WF_KEEPCAP)) == 0
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
1535 && ((treeflags & WF_ONECAP) == 0
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
1536 || (wordflags & WF_ONECAP) != 0)));
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1537 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1538
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1539 /*
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1540 * Return TRUE if spell checking is not enabled.
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1541 */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1542 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1543 no_spell_checking(win_T *wp)
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1544 {
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1545 if (!wp->w_p_spell || *wp->w_s->b_p_spl == NUL
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1546 || wp->w_s->b_langp.ga_len == 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1547 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1548 EMSG(_("E756: Spell checking is not enabled"));
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1549 return TRUE;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1550 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1551 return FALSE;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1552 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1553
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1554 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1555 * Move to next spell error.
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1556 * "curline" is FALSE for "[s", "]s", "[S" and "]S".
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1557 * "curline" is TRUE to find word under/after cursor in the same line.
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1558 * For Insert mode completion "dir" is BACKWARD and "curline" is TRUE: move
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1559 * to after badly spelled word before the cursor.
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1560 * Return 0 if not found, length of the badly spelled word otherwise.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1561 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1562 int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1563 spell_move_to(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1564 win_T *wp,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1565 int dir, /* FORWARD or BACKWARD */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1566 int allwords, /* TRUE for "[s"/"]s", FALSE for "[S"/"]S" */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1567 int curline,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1568 hlf_T *attrp) /* return: attributes of bad word or NULL
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
1569 (only when "dir" is FORWARD) */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1570 {
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1571 linenr_T lnum;
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1572 pos_T found_pos;
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1573 int found_len = 0;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1574 char_u *line;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1575 char_u *p;
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1576 char_u *endp;
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
1577 hlf_T attr;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1578 int len;
5519
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
1579 #ifdef FEAT_SYN_HL
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1580 int has_syntax = syntax_present(wp);
5519
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
1581 #endif
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1582 int col;
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1583 int can_spell;
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1584 char_u *buf = NULL;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1585 int buflen = 0;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1586 int skip = 0;
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1587 int capcol = -1;
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1588 int found_one = FALSE;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1589 int wrapped = FALSE;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1590
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1591 if (no_spell_checking(wp))
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1592 return 0;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1593
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1594 /*
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1595 * Start looking for bad word at the start of the line, because we can't
817
6897668c467f updated for version 7.0c03
vimboss
parents: 810
diff changeset
1596 * start halfway a word, we don't know where it starts or ends.
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1597 *
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1598 * When searching backwards, we continue in the line to find the last
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1599 * bad word (in the cursor line: before the cursor).
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1600 *
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1601 * We concatenate the start of the next line, so that wrapped words work
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1602 * (e.g. "et<line-break>cetera"). Doesn't work when searching backwards
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1603 * though...
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1604 */
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1605 lnum = wp->w_cursor.lnum;
698
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
1606 clearpos(&found_pos);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1607
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1608 while (!got_int)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1609 {
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1610 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1611
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1612 len = (int)STRLEN(line);
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1613 if (buflen < len + MAXWLEN + 2)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1614 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1615 vim_free(buf);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1616 buflen = len + MAXWLEN + 2;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1617 buf = alloc(buflen);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1618 if (buf == NULL)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1619 break;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1620 }
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1621
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1622 /* In first line check first word for Capital. */
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1623 if (lnum == 1)
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1624 capcol = 0;
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1625
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1626 /* For checking first word with a capital skip white space. */
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1627 if (capcol == 0)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1628 capcol = (int)(skipwhite(line) - line);
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1629 else if (curline && wp == curwin)
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1630 {
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1631 /* For spellbadword(): check if first word needs a capital. */
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
1632 col = (int)(skipwhite(line) - line);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1633 if (check_need_cap(lnum, col))
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1634 capcol = col;
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1635
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1636 /* Need to get the line again, may have looked at the previous
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1637 * one. */
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1638 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1639 }
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1640
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1641 /* Copy the line into "buf" and append the start of the next line if
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1642 * possible. */
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1643 STRCPY(buf, line);
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1644 if (lnum < wp->w_buffer->b_ml.ml_line_count)
883
7c28790fa8b4 updated for version 7.0-009
vimboss
parents: 866
diff changeset
1645 spell_cat_line(buf + STRLEN(buf),
7c28790fa8b4 updated for version 7.0-009
vimboss
parents: 866
diff changeset
1646 ml_get_buf(wp->w_buffer, lnum + 1, FALSE), MAXWLEN);
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1647
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1648 p = buf + skip;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1649 endp = buf + len;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1650 while (p < endp)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1651 {
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1652 /* When searching backward don't search after the cursor. Unless
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1653 * we wrapped around the end of the buffer. */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1654 if (dir == BACKWARD
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1655 && lnum == wp->w_cursor.lnum
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1656 && !wrapped
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1657 && (colnr_T)(p - buf) >= wp->w_cursor.col)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1658 break;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1659
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1660 /* start of word */
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
1661 attr = HLF_COUNT;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1662 len = spell_check(wp, p, &attr, &capcol, FALSE);
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1663
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
1664 if (attr != HLF_COUNT)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1665 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1666 /* We found a bad word. Check the attribute. */
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
1667 if (allwords || attr == HLF_SPB)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1668 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1669 /* When searching forward only accept a bad word after
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1670 * the cursor. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1671 if (dir == BACKWARD
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1672 || lnum != wp->w_cursor.lnum
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1673 || (lnum == wp->w_cursor.lnum
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1674 && (wrapped
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1675 || (colnr_T)(curline ? p - buf + len
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1676 : p - buf)
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1677 > wp->w_cursor.col)))
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1678 {
5519
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
1679 #ifdef FEAT_SYN_HL
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1680 if (has_syntax)
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1681 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1682 col = (int)(p - buf);
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1683 (void)syn_get_id(wp, lnum, (colnr_T)col,
1504
1b55bbf5c580 updated for version 7.1-219
vimboss
parents: 1337
diff changeset
1684 FALSE, &can_spell, FALSE);
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 844
diff changeset
1685 if (!can_spell)
b933657f7c9d updated for version 7.0g01
vimboss
parents: 844
diff changeset
1686 attr = HLF_COUNT;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1687 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1688 else
737
59971e227f8c updated for version 7.0222
vimboss
parents: 718
diff changeset
1689 #endif
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1690 can_spell = TRUE;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1691
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1692 if (can_spell)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1693 {
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 844
diff changeset
1694 found_one = TRUE;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1695 found_pos.lnum = lnum;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1696 found_pos.col = (int)(p - buf);
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1697 #ifdef FEAT_VIRTUALEDIT
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1698 found_pos.coladd = 0;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1699 #endif
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1700 if (dir == FORWARD)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1701 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1702 /* No need to search further. */
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1703 wp->w_cursor = found_pos;
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1704 vim_free(buf);
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1705 if (attrp != NULL)
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1706 *attrp = attr;
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1707 return len;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1708 }
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1709 else if (curline)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1710 /* Insert mode completion: put cursor after
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1711 * the bad word. */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1712 found_pos.col += len;
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1713 found_len = len;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1714 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1715 }
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 844
diff changeset
1716 else
b933657f7c9d updated for version 7.0g01
vimboss
parents: 844
diff changeset
1717 found_one = TRUE;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1718 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1719 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1720
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1721 /* advance to character after the word */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1722 p += len;
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1723 capcol -= len;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1724 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1725
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1726 if (dir == BACKWARD && found_pos.lnum != 0)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1727 {
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1728 /* Use the last match in the line (before the cursor). */
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1729 wp->w_cursor = found_pos;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1730 vim_free(buf);
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1731 return found_len;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1732 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1733
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1734 if (curline)
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1735 break; /* only check cursor line */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1736
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1737 /* Advance to next line. */
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1738 if (dir == BACKWARD)
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1739 {
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1740 /* If we are back at the starting line and searched it again there
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1741 * is no match, give up. */
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1742 if (lnum == wp->w_cursor.lnum && wrapped)
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1743 break;
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1744
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1745 if (lnum > 1)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1746 --lnum;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1747 else if (!p_ws)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1748 break; /* at first line and 'nowrapscan' */
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1749 else
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1750 {
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1751 /* Wrap around to the end of the buffer. May search the
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1752 * starting line again and accept the last match. */
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1753 lnum = wp->w_buffer->b_ml.ml_line_count;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1754 wrapped = TRUE;
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
1755 if (!shortmess(SHM_SEARCH))
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
1756 give_warning((char_u *)_(top_bot_msg), TRUE);
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1757 }
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1758 capcol = -1;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1759 }
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1760 else
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1761 {
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1762 if (lnum < wp->w_buffer->b_ml.ml_line_count)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1763 ++lnum;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1764 else if (!p_ws)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1765 break; /* at first line and 'nowrapscan' */
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1766 else
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1767 {
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1768 /* Wrap around to the start of the buffer. May search the
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1769 * starting line again and accept the first match. */
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1770 lnum = 1;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1771 wrapped = TRUE;
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
1772 if (!shortmess(SHM_SEARCH))
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
1773 give_warning((char_u *)_(bot_top_msg), TRUE);
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1774 }
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1775
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1776 /* If we are back at the starting line and there is no match then
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1777 * give up. */
1808
e2d7622d7089 updated for version 7.2-106
vimboss
parents: 1771
diff changeset
1778 if (lnum == wp->w_cursor.lnum && (!found_one || wrapped))
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1779 break;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1780
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1781 /* Skip the characters at the start of the next line that were
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1782 * included in a match crossing line boundaries. */
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
1783 if (attr == HLF_COUNT)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1784 skip = (int)(p - endp);
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1785 else
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1786 skip = 0;
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1787
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1788 /* Capcol skips over the inserted space. */
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1789 --capcol;
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1790
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1791 /* But after empty line check first word in next line */
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1792 if (*skipwhite(line) == NUL)
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1793 capcol = 0;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1794 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1795
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1796 line_breakcheck();
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1797 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1798
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1799 vim_free(buf);
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1800 return 0;
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1801 }
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1802
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1803 /*
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1804 * For spell checking: concatenate the start of the following line "line" into
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1805 * "buf", blanking-out special characters. Copy less then "maxlen" bytes.
1577
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1806 * Keep the blanks at the start of the next line, this is used in win_line()
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1807 * to skip those bytes if the word was OK.
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1808 */
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1809 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1810 spell_cat_line(char_u *buf, char_u *line, int maxlen)
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1811 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1812 char_u *p;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1813 int n;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1814
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1815 p = skipwhite(line);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1816 while (vim_strchr((char_u *)"*#/\"\t", *p) != NULL)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1817 p = skipwhite(p + 1);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1818
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1819 if (*p != NUL)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1820 {
1577
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1821 /* Only worth concatenating if there is something else than spaces to
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1822 * concatenate. */
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1823 n = (int)(p - line) + 1;
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1824 if (n < maxlen - 1)
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1825 {
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1826 vim_memset(buf, ' ', n);
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1827 vim_strncpy(buf + n, p, maxlen - 1 - n);
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1828 }
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1829 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1830 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1831
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
1832 /*
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
1833 * Structure used for the cookie argument of do_in_runtimepath().
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
1834 */
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1835 typedef struct spelload_S
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1836 {
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1837 char_u sl_lang[MAXWLEN + 1]; /* language name */
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1838 slang_T *sl_slang; /* resulting slang_T struct */
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1839 int sl_nobreak; /* NOBREAK language found */
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1840 } spelload_T;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1841
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1842 /*
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1843 * Load word list(s) for "lang" from Vim spell file(s).
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1844 * "lang" must be the language without the region: e.g., "en".
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1845 */
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1846 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1847 spell_load_lang(char_u *lang)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1848 {
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1849 char_u fname_enc[85];
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1850 int r;
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1851 spelload_T sl;
649
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1852 #ifdef FEAT_AUTOCMD
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1853 int round;
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1854 #endif
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1855
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1856 /* Copy the language name to pass it to spell_load_cb() as a cookie.
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1857 * It's truncated when an error is detected. */
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1858 STRCPY(sl.sl_lang, lang);
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1859 sl.sl_slang = NULL;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1860 sl.sl_nobreak = FALSE;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1861
649
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1862 #ifdef FEAT_AUTOCMD
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1863 /* We may retry when no spell file is found for the language, an
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1864 * autocommand may load it then. */
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1865 for (round = 1; round <= 2; ++round)
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1866 #endif
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1867 {
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1868 /*
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1869 * Find the first spell file for "lang" in 'runtimepath' and load it.
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1870 */
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1871 vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5,
2660
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1872 #ifdef VMS
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1873 "spell/%s_%s.spl",
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1874 #else
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1875 "spell/%s.%s.spl",
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1876 #endif
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1877 lang, spell_enc());
8524
2f57bbe870ea commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents: 7835
diff changeset
1878 r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl);
649
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1879
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1880 if (r == FAIL && *sl.sl_lang != NUL)
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1881 {
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1882 /* Try loading the ASCII version. */
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1883 vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5,
2660
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1884 #ifdef VMS
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1885 "spell/%s_ascii.spl",
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1886 #else
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1887 "spell/%s.ascii.spl",
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1888 #endif
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1889 lang);
8524
2f57bbe870ea commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents: 7835
diff changeset
1890 r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl);
649
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1891
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1892 #ifdef FEAT_AUTOCMD
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1893 if (r == FAIL && *sl.sl_lang != NUL && round == 1
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1894 && apply_autocmds(EVENT_SPELLFILEMISSING, lang,
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1895 curbuf->b_fname, FALSE, curbuf))
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1896 continue;
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1897 break;
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1898 #endif
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1899 }
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
1900 #ifdef FEAT_AUTOCMD
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
1901 break;
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
1902 #endif
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1903 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1904
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1905 if (r == FAIL)
649
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1906 {
2660
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1907 smsg((char_u *)
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1908 #ifdef VMS
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1909 _("Warning: Cannot find word list \"%s_%s.spl\" or \"%s_ascii.spl\""),
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1910 #else
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1911 _("Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\""),
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1912 #endif
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1913 lang, spell_enc(), lang);
649
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1914 }
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1915 else if (sl.sl_slang != NULL)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1916 {
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
1917 /* At least one file was loaded, now load ALL the additions. */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1918 STRCPY(fname_enc + STRLEN(fname_enc) - 3, "add.spl");
8524
2f57bbe870ea commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents: 7835
diff changeset
1919 do_in_runtimepath(fname_enc, DIP_ALL, spell_load_cb, &sl);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1920 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1921 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1922
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1923 /*
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1924 * Return the encoding used for spell checking: Use 'encoding', except that we
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1925 * use "latin1" for "latin9". And limit to 60 characters (just in case).
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1926 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
1927 char_u *
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1928 spell_enc(void)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1929 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1930
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1931 #ifdef FEAT_MBYTE
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1932 if (STRLEN(p_enc) < 60 && STRCMP(p_enc, "iso-8859-15") != 0)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1933 return p_enc;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1934 #endif
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1935 return (char_u *)"latin1";
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1936 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1937
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1938 /*
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1939 * Get the name of the .spl file for the internal wordlist into
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1940 * "fname[MAXPATHL]".
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1941 */
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1942 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1943 int_wordlist_spl(char_u *fname)
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1944 {
2660
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1945 vim_snprintf((char *)fname, MAXPATHL, SPL_FNAME_TMPL,
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1946 int_wordlist, spell_enc());
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1947 }
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1948
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1949 /*
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1950 * Allocate a new slang_T for language "lang". "lang" can be NULL.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1951 * Caller must fill "sl_next".
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1952 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
1953 slang_T *
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1954 slang_alloc(char_u *lang)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1955 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1956 slang_T *lp;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1957
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1958 lp = (slang_T *)alloc_clear(sizeof(slang_T));
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1959 if (lp != NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1960 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1961 if (lang != NULL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1962 lp->sl_name = vim_strsave(lang);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1963 ga_init2(&lp->sl_rep, sizeof(fromto_T), 10);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1964 ga_init2(&lp->sl_repsal, sizeof(fromto_T), 10);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1965 lp->sl_compmax = MAXWLEN;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1966 lp->sl_compsylmax = MAXWLEN;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1967 hash_init(&lp->sl_wordcount);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1968 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1969
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1970 return lp;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1971 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1972
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1973 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1974 * Free the contents of an slang_T and the structure itself.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1975 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
1976 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1977 slang_free(slang_T *lp)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1978 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1979 vim_free(lp->sl_name);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1980 vim_free(lp->sl_fname);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1981 slang_clear(lp);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1982 vim_free(lp);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1983 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1984
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1985 /*
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1986 * Clear an slang_T so that the file can be reloaded.
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1987 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
1988 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1989 slang_clear(slang_T *lp)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1990 {
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1991 garray_T *gap;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1992 fromto_T *ftp;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
1993 salitem_T *smp;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1994 int i;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1995 int round;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1996
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1997 vim_free(lp->sl_fbyts);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1998 lp->sl_fbyts = NULL;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1999 vim_free(lp->sl_kbyts);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2000 lp->sl_kbyts = NULL;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
2001 vim_free(lp->sl_pbyts);
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
2002 lp->sl_pbyts = NULL;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
2003
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2004 vim_free(lp->sl_fidxs);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2005 lp->sl_fidxs = NULL;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2006 vim_free(lp->sl_kidxs);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2007 lp->sl_kidxs = NULL;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
2008 vim_free(lp->sl_pidxs);
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
2009 lp->sl_pidxs = NULL;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2010
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2011 for (round = 1; round <= 2; ++round)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2012 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2013 gap = round == 1 ? &lp->sl_rep : &lp->sl_repsal;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2014 while (gap->ga_len > 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2015 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2016 ftp = &((fromto_T *)gap->ga_data)[--gap->ga_len];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2017 vim_free(ftp->ft_from);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2018 vim_free(ftp->ft_to);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2019 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2020 ga_clear(gap);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2021 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
2022
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
2023 gap = &lp->sl_sal;
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2024 if (lp->sl_sofo)
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2025 {
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2026 /* "ga_len" is set to 1 without adding an item for latin1 */
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2027 if (gap->ga_data != NULL)
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2028 /* SOFOFROM and SOFOTO items: free lists of wide characters. */
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2029 for (i = 0; i < gap->ga_len; ++i)
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2030 vim_free(((int **)gap->ga_data)[i]);
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2031 }
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2032 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2033 /* SAL items: free salitem_T items */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2034 while (gap->ga_len > 0)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2035 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2036 smp = &((salitem_T *)gap->ga_data)[--gap->ga_len];
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2037 vim_free(smp->sm_lead);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2038 /* Don't free sm_oneof and sm_rules, they point into sm_lead. */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2039 vim_free(smp->sm_to);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2040 #ifdef FEAT_MBYTE
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2041 vim_free(smp->sm_lead_w);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2042 vim_free(smp->sm_oneof_w);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2043 vim_free(smp->sm_to_w);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2044 #endif
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
2045 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
2046 ga_clear(gap);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2047
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
2048 for (i = 0; i < lp->sl_prefixcnt; ++i)
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
2049 vim_regfree(lp->sl_prefprog[i]);
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2050 lp->sl_prefixcnt = 0;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
2051 vim_free(lp->sl_prefprog);
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2052 lp->sl_prefprog = NULL;
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2053
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
2054 vim_free(lp->sl_info);
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
2055 lp->sl_info = NULL;
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
2056
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2057 vim_free(lp->sl_midword);
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2058 lp->sl_midword = NULL;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
2059
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
2060 vim_regfree(lp->sl_compprog);
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
2061 vim_free(lp->sl_comprules);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2062 vim_free(lp->sl_compstartflags);
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
2063 vim_free(lp->sl_compallflags);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2064 lp->sl_compprog = NULL;
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
2065 lp->sl_comprules = NULL;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2066 lp->sl_compstartflags = NULL;
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
2067 lp->sl_compallflags = NULL;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2068
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2069 vim_free(lp->sl_syllable);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2070 lp->sl_syllable = NULL;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2071 ga_clear(&lp->sl_syl_items);
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
2072
809
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
2073 ga_clear_strings(&lp->sl_comppat);
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
2074
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2075 hash_clear_all(&lp->sl_wordcount, WC_KEY_OFF);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2076 hash_init(&lp->sl_wordcount);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2077
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2078 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2079 hash_clear_all(&lp->sl_map_hash, 0);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2080 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2081
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2082 /* Clear info from .sug file. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2083 slang_clear_sug(lp);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2084
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2085 lp->sl_compmax = MAXWLEN;
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2086 lp->sl_compminlen = 0;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2087 lp->sl_compsylmax = MAXWLEN;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2088 lp->sl_regions[0] = NUL;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2089 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2090
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2091 /*
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2092 * Clear the info from the .sug file in "lp".
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2093 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
2094 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2095 slang_clear_sug(slang_T *lp)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2096 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2097 vim_free(lp->sl_sbyts);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2098 lp->sl_sbyts = NULL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2099 vim_free(lp->sl_sidxs);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2100 lp->sl_sidxs = NULL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2101 close_spellbuf(lp->sl_sugbuf);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2102 lp->sl_sugbuf = NULL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2103 lp->sl_sugloaded = FALSE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2104 lp->sl_sugtime = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2105 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2106
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2107 /*
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2108 * Load one spell file and store the info into a slang_T.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2109 * Invoked through do_in_runtimepath().
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2110 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2111 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2112 spell_load_cb(char_u *fname, void *cookie)
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2113 {
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2114 spelload_T *slp = (spelload_T *)cookie;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2115 slang_T *slang;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2116
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2117 slang = spell_load_file(fname, slp->sl_lang, NULL, FALSE);
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2118 if (slang != NULL)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2119 {
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2120 /* When a previously loaded file has NOBREAK also use it for the
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2121 * ".add" files. */
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2122 if (slp->sl_nobreak && slang->sl_add)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2123 slang->sl_nobreak = TRUE;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2124 else if (slang->sl_nobreak)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2125 slp->sl_nobreak = TRUE;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2126
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2127 slp->sl_slang = slang;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2128 }
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2129 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2130
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2131
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2132 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2133 * Add a word to the hashtable of common words.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2134 * If it's already there then the counter is increased.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2135 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
2136 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2137 count_common_word(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2138 slang_T *lp,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2139 char_u *word,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2140 int len, /* word length, -1 for upto NUL */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2141 int count) /* 1 to count once, 10 to init */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2142 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2143 hash_T hash;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2144 hashitem_T *hi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2145 wordcount_T *wc;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2146 char_u buf[MAXWLEN];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2147 char_u *p;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2148
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2149 if (len == -1)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2150 p = word;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2151 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2152 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2153 vim_strncpy(buf, word, len);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2154 p = buf;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2155 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2156
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2157 hash = hash_hash(p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2158 hi = hash_lookup(&lp->sl_wordcount, p, hash);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2159 if (HASHITEM_EMPTY(hi))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2160 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
2161 wc = (wordcount_T *)alloc((unsigned)(sizeof(wordcount_T) + STRLEN(p)));
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2162 if (wc == NULL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2163 return;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2164 STRCPY(wc->wc_word, p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2165 wc->wc_count = count;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2166 hash_add_item(&lp->sl_wordcount, hi, wc->wc_word, hash);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2167 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2168 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2169 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2170 wc = HI2WC(hi);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2171 if ((wc->wc_count += count) < (unsigned)count) /* check for overflow */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2172 wc->wc_count = MAXWORDCOUNT;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2173 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2174 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2175
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2176 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2177 * Adjust the score of common words.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2178 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2179 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2180 score_wordcount_adj(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2181 slang_T *slang,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2182 int score,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2183 char_u *word,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2184 int split) /* word was split, less bonus */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2185 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2186 hashitem_T *hi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2187 wordcount_T *wc;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2188 int bonus;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2189 int newscore;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2190
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2191 hi = hash_find(&slang->sl_wordcount, word);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2192 if (!HASHITEM_EMPTY(hi))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2193 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2194 wc = HI2WC(hi);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2195 if (wc->wc_count < SCORE_THRES2)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2196 bonus = SCORE_COMMON1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2197 else if (wc->wc_count < SCORE_THRES3)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2198 bonus = SCORE_COMMON2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2199 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2200 bonus = SCORE_COMMON3;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2201 if (split)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2202 newscore = score - bonus / 2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2203 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2204 newscore = score - bonus;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2205 if (newscore < 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2206 return 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2207 return newscore;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2208 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2209 return score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2210 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2211
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2212
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
2213 /*
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
2214 * Return TRUE if byte "n" appears in "str".
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
2215 * Like strchr() but independent of locale.
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
2216 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
2217 int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2218 byte_in_str(char_u *str, int n)
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
2219 {
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
2220 char_u *p;
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
2221
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
2222 for (p = str; *p != NUL; ++p)
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
2223 if (*p == n)
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
2224 return TRUE;
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
2225 return FALSE;
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
2226 }
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
2227
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2228 #define SY_MAXLEN 30
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2229 typedef struct syl_item_S
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2230 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2231 char_u sy_chars[SY_MAXLEN]; /* the sequence of chars */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2232 int sy_len;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2233 } syl_item_T;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2234
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2235 /*
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2236 * Truncate "slang->sl_syllable" at the first slash and put the following items
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2237 * in "slang->sl_syl_items".
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2238 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
2239 int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2240 init_syl_tab(slang_T *slang)
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2241 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2242 char_u *p;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2243 char_u *s;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2244 int l;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2245 syl_item_T *syl;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2246
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2247 ga_init2(&slang->sl_syl_items, sizeof(syl_item_T), 4);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2248 p = vim_strchr(slang->sl_syllable, '/');
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2249 while (p != NULL)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2250 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2251 *p++ = NUL;
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
2252 if (*p == NUL) /* trailing slash */
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2253 break;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2254 s = p;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2255 p = vim_strchr(p, '/');
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2256 if (p == NULL)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
2257 l = (int)STRLEN(s);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2258 else
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
2259 l = (int)(p - s);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2260 if (l >= SY_MAXLEN)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2261 return SP_FORMERROR;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2262 if (ga_grow(&slang->sl_syl_items, 1) == FAIL)
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
2263 return SP_OTHERERROR;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2264 syl = ((syl_item_T *)slang->sl_syl_items.ga_data)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2265 + slang->sl_syl_items.ga_len++;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2266 vim_strncpy(syl->sy_chars, s, l);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2267 syl->sy_len = l;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2268 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2269 return OK;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2270 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2271
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2272 /*
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2273 * Count the number of syllables in "word".
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2274 * When "word" contains spaces the syllables after the last space are counted.
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2275 * Returns zero if syllables are not defines.
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2276 */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2277 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2278 count_syllables(slang_T *slang, char_u *word)
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2279 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2280 int cnt = 0;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2281 int skip = FALSE;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2282 char_u *p;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2283 int len;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2284 int i;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2285 syl_item_T *syl;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2286 int c;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2287
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2288 if (slang->sl_syllable == NULL)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2289 return 0;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2290
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2291 for (p = word; *p != NUL; p += len)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2292 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2293 /* When running into a space reset counter. */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2294 if (*p == ' ')
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2295 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2296 len = 1;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2297 cnt = 0;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2298 continue;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2299 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2300
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2301 /* Find longest match of syllable items. */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2302 len = 0;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2303 for (i = 0; i < slang->sl_syl_items.ga_len; ++i)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2304 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2305 syl = ((syl_item_T *)slang->sl_syl_items.ga_data) + i;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2306 if (syl->sy_len > len
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2307 && STRNCMP(p, syl->sy_chars, syl->sy_len) == 0)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2308 len = syl->sy_len;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2309 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2310 if (len != 0) /* found a match, count syllable */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2311 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2312 ++cnt;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2313 skip = FALSE;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2314 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2315 else
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2316 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2317 /* No recognized syllable item, at least a syllable char then? */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2318 #ifdef FEAT_MBYTE
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2319 c = mb_ptr2char(p);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2320 len = (*mb_ptr2len)(p);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2321 #else
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2322 c = *p;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2323 len = 1;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2324 #endif
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2325 if (vim_strchr(slang->sl_syllable, c) == NULL)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2326 skip = FALSE; /* No, search for next syllable */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2327 else if (!skip)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2328 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2329 ++cnt; /* Yes, count it */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2330 skip = TRUE; /* don't count following syllable chars */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2331 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2332 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2333 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2334 return cnt;
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2335 }
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2336
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2337 /*
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2338 * Parse 'spelllang' and set w_s->b_langp accordingly.
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2339 * Returns NULL if it's OK, an error message otherwise.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2340 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2341 char_u *
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2342 did_set_spelllang(win_T *wp)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2343 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2344 garray_T ga;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2345 char_u *splp;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2346 char_u *region;
416
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2347 char_u region_cp[3];
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2348 int filename;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2349 int region_mask;
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2350 slang_T *slang;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2351 int c;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2352 char_u lang[MAXWLEN + 1];
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2353 char_u spf_name[MAXPATHL];
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2354 int len;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2355 char_u *p;
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2356 int round;
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2357 char_u *spf;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2358 char_u *use_region = NULL;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2359 int dont_use_region = FALSE;
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2360 int nobreak = FALSE;
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2361 int i, j;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2362 langp_T *lp, *lp2;
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2363 static int recursive = FALSE;
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2364 char_u *ret_msg = NULL;
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2365 char_u *spl_copy;
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
2366 #ifdef FEAT_AUTOCMD
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
2367 bufref_T bufref;
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
2368
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
2369 set_bufref(&bufref, wp->w_buffer);
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
2370 #endif
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2371
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2372 /* We don't want to do this recursively. May happen when a language is
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2373 * not available and the SpellFileMissing autocommand opens a new buffer
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2374 * in which 'spell' is set. */
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2375 if (recursive)
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2376 return NULL;
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2377 recursive = TRUE;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2378
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2379 ga_init2(&ga, sizeof(langp_T), 2);
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2380 clear_midword(wp);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2381
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 3620
diff changeset
2382 /* Make a copy of 'spelllang', the SpellFileMissing autocommands may change
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2383 * it under our fingers. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2384 spl_copy = vim_strsave(wp->w_s->b_p_spl);
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2385 if (spl_copy == NULL)
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2386 goto theend;
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2387
5485
1b4cb2c6b285 updated for version 7.4.092
Bram Moolenaar <bram@vim.org>
parents: 5477
diff changeset
2388 #ifdef FEAT_MBYTE
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2389 wp->w_s->b_cjk = 0;
5485
1b4cb2c6b285 updated for version 7.4.092
Bram Moolenaar <bram@vim.org>
parents: 5477
diff changeset
2390 #endif
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2391
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2392 /* Loop over comma separated language names. */
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2393 for (splp = spl_copy; *splp != NUL; )
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2394 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2395 /* Get one language name. */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2396 copy_option_part(&splp, lang, MAXWLEN, ",");
240
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2397 region = NULL;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
2398 len = (int)STRLEN(lang);
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2399
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2400 if (STRCMP(lang, "cjk") == 0)
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2401 {
5485
1b4cb2c6b285 updated for version 7.4.092
Bram Moolenaar <bram@vim.org>
parents: 5477
diff changeset
2402 #ifdef FEAT_MBYTE
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2403 wp->w_s->b_cjk = 1;
5485
1b4cb2c6b285 updated for version 7.4.092
Bram Moolenaar <bram@vim.org>
parents: 5477
diff changeset
2404 #endif
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2405 continue;
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2406 }
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2407
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2408 /* If the name ends in ".spl" use it as the name of the spell file.
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2409 * If there is a region name let "region" point to it and remove it
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2410 * from the name. */
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2411 if (len > 4 && fnamecmp(lang + len - 4, ".spl") == 0)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2412 {
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2413 filename = TRUE;
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2414
416
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2415 /* Locate a region and remove it from the file name. */
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2416 p = vim_strchr(gettail(lang), '_');
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2417 if (p != NULL && ASCII_ISALPHA(p[1]) && ASCII_ISALPHA(p[2])
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2418 && !ASCII_ISALPHA(p[3]))
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2419 {
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2420 vim_strncpy(region_cp, p + 1, 2);
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2421 mch_memmove(p, p + 3, len - (p - lang) - 2);
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2422 len -= 3;
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2423 region = region_cp;
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2424 }
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2425 else
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2426 dont_use_region = TRUE;
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2427
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2428 /* Check if we loaded this language before. */
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2429 for (slang = first_lang; slang != NULL; slang = slang->sl_next)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2430 if (fullpathcmp(lang, slang->sl_fname, FALSE) == FPC_SAME)
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2431 break;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2432 }
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2433 else
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2434 {
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2435 filename = FALSE;
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2436 if (len > 3 && lang[len - 3] == '_')
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2437 {
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2438 region = lang + len - 2;
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2439 len -= 3;
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2440 lang[len] = NUL;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2441 }
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2442 else
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2443 dont_use_region = TRUE;
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2444
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2445 /* Check if we loaded this language before. */
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2446 for (slang = first_lang; slang != NULL; slang = slang->sl_next)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2447 if (STRICMP(lang, slang->sl_name) == 0)
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2448 break;
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2449 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2450
416
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2451 if (region != NULL)
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2452 {
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2453 /* If the region differs from what was used before then don't
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2454 * use it for 'spellfile'. */
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2455 if (use_region != NULL && STRCMP(region, use_region) != 0)
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2456 dont_use_region = TRUE;
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2457 use_region = region;
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2458 }
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2459
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2460 /* If not found try loading the language now. */
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2461 if (slang == NULL)
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2462 {
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2463 if (filename)
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2464 (void)spell_load_file(lang, lang, NULL, FALSE);
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2465 else
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2466 {
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2467 spell_load_lang(lang);
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2468 #ifdef FEAT_AUTOCMD
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2469 /* SpellFileMissing autocommands may do anything, including
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2470 * destroying the buffer we are using... */
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
2471 if (!bufref_valid(&bufref))
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2472 {
9953
9560a2eb7968 commit https://github.com/vim/vim/commit/5b30291785e6b9be1a607504c14bd03c601b59a6
Christian Brabandt <cb@256bit.org>
parents: 9898
diff changeset
2473 ret_msg = (char_u *)N_("E797: SpellFileMissing autocommand deleted buffer");
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2474 goto theend;
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2475 }
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2476 #endif
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2477 }
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2478 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2479
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2480 /*
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2481 * Loop over the languages, there can be several files for "lang".
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2482 */
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2483 for (slang = first_lang; slang != NULL; slang = slang->sl_next)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2484 if (filename ? fullpathcmp(lang, slang->sl_fname, FALSE) == FPC_SAME
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2485 : STRICMP(lang, slang->sl_name) == 0)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2486 {
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2487 region_mask = REGION_ALL;
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2488 if (!filename && region != NULL)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2489 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2490 /* find region in sl_regions */
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2491 c = find_region(slang->sl_regions, region);
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2492 if (c == REGION_ALL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2493 {
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2494 if (slang->sl_add)
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2495 {
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2496 if (*slang->sl_regions != NUL)
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2497 /* This addition file is for other regions. */
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2498 region_mask = 0;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2499 }
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2500 else
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2501 /* This is probably an error. Give a warning and
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2502 * accept the words anyway. */
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2503 smsg((char_u *)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2504 _("Warning: region %s not supported"),
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2505 region);
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2506 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2507 else
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2508 region_mask = 1 << c;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2509 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2510
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2511 if (region_mask != 0)
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2512 {
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2513 if (ga_grow(&ga, 1) == FAIL)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2514 {
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2515 ga_clear(&ga);
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2516 ret_msg = e_outofmem;
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2517 goto theend;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2518 }
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2519 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = slang;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2520 LANGP_ENTRY(ga, ga.ga_len)->lp_region = region_mask;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2521 ++ga.ga_len;
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2522 use_midword(slang, wp);
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2523 if (slang->sl_nobreak)
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2524 nobreak = TRUE;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2525 }
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2526 }
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2527 }
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2528
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2529 /* round 0: load int_wordlist, if possible.
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2530 * round 1: load first name in 'spellfile'.
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2531 * round 2: load second name in 'spellfile.
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2532 * etc. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2533 spf = curwin->w_s->b_p_spf;
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2534 for (round = 0; round == 0 || *spf != NUL; ++round)
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2535 {
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2536 if (round == 0)
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2537 {
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2538 /* Internal wordlist, if there is one. */
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2539 if (int_wordlist == NULL)
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2540 continue;
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2541 int_wordlist_spl(spf_name);
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2542 }
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2543 else
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2544 {
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2545 /* One entry in 'spellfile'. */
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2546 copy_option_part(&spf, spf_name, MAXPATHL - 5, ",");
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2547 STRCAT(spf_name, ".spl");
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2548
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2549 /* If it was already found above then skip it. */
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2550 for (c = 0; c < ga.ga_len; ++c)
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
2551 {
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
2552 p = LANGP_ENTRY(ga, c)->lp_slang->sl_fname;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
2553 if (p != NULL && fullpathcmp(spf_name, p, FALSE) == FPC_SAME)
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2554 break;
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
2555 }
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2556 if (c < ga.ga_len)
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2557 continue;
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2558 }
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2559
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2560 /* Check if it was loaded already. */
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2561 for (slang = first_lang; slang != NULL; slang = slang->sl_next)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2562 if (fullpathcmp(spf_name, slang->sl_fname, FALSE) == FPC_SAME)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2563 break;
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2564 if (slang == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2565 {
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2566 /* Not loaded, try loading it now. The language name includes the
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2567 * region name, the region is ignored otherwise. for int_wordlist
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2568 * use an arbitrary name. */
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2569 if (round == 0)
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2570 STRCPY(lang, "internal wordlist");
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2571 else
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2572 {
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2573 vim_strncpy(lang, gettail(spf_name), MAXWLEN);
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2574 p = vim_strchr(lang, '.');
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2575 if (p != NULL)
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2576 *p = NUL; /* truncate at ".encoding.add" */
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2577 }
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2578 slang = spell_load_file(spf_name, lang, NULL, TRUE);
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2579
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2580 /* If one of the languages has NOBREAK we assume the addition
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2581 * files also have this. */
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2582 if (slang != NULL && nobreak)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2583 slang->sl_nobreak = TRUE;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2584 }
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2585 if (slang != NULL && ga_grow(&ga, 1) == OK)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2586 {
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2587 region_mask = REGION_ALL;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2588 if (use_region != NULL && !dont_use_region)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2589 {
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2590 /* find region in sl_regions */
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2591 c = find_region(slang->sl_regions, use_region);
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2592 if (c != REGION_ALL)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2593 region_mask = 1 << c;
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2594 else if (*slang->sl_regions != NUL)
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2595 /* This spell file is for other regions. */
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2596 region_mask = 0;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2597 }
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2598
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2599 if (region_mask != 0)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2600 {
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2601 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = slang;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2602 LANGP_ENTRY(ga, ga.ga_len)->lp_sallang = NULL;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2603 LANGP_ENTRY(ga, ga.ga_len)->lp_replang = NULL;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2604 LANGP_ENTRY(ga, ga.ga_len)->lp_region = region_mask;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2605 ++ga.ga_len;
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2606 use_midword(slang, wp);
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2607 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2608 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2609 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2610
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2611 /* Everything is fine, store the new b_langp value. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2612 ga_clear(&wp->w_s->b_langp);
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2613 wp->w_s->b_langp = ga;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2614
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2615 /* For each language figure out what language to use for sound folding and
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2616 * REP items. If the language doesn't support it itself use another one
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2617 * with the same name. E.g. for "en-math" use "en". */
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2618 for (i = 0; i < ga.ga_len; ++i)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2619 {
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2620 lp = LANGP_ENTRY(ga, i);
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2621
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2622 /* sound folding */
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2623 if (lp->lp_slang->sl_sal.ga_len > 0)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2624 /* language does sound folding itself */
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2625 lp->lp_sallang = lp->lp_slang;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2626 else
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2627 /* find first similar language that does sound folding */
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2628 for (j = 0; j < ga.ga_len; ++j)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2629 {
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2630 lp2 = LANGP_ENTRY(ga, j);
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2631 if (lp2->lp_slang->sl_sal.ga_len > 0
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2632 && STRNCMP(lp->lp_slang->sl_name,
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2633 lp2->lp_slang->sl_name, 2) == 0)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2634 {
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2635 lp->lp_sallang = lp2->lp_slang;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2636 break;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2637 }
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2638 }
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2639
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2640 /* REP items */
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2641 if (lp->lp_slang->sl_rep.ga_len > 0)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2642 /* language has REP items itself */
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2643 lp->lp_replang = lp->lp_slang;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2644 else
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2645 /* find first similar language that has REP items */
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2646 for (j = 0; j < ga.ga_len; ++j)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2647 {
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2648 lp2 = LANGP_ENTRY(ga, j);
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2649 if (lp2->lp_slang->sl_rep.ga_len > 0
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2650 && STRNCMP(lp->lp_slang->sl_name,
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2651 lp2->lp_slang->sl_name, 2) == 0)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2652 {
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2653 lp->lp_replang = lp2->lp_slang;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2654 break;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2655 }
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2656 }
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2657 }
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2658
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2659 theend:
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2660 vim_free(spl_copy);
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2661 recursive = FALSE;
5891
7965cb6a435a updated for version 7.4.288
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2662 redraw_win_later(wp, NOT_VALID);
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2663 return ret_msg;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2664 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2665
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2666 /*
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2667 * Clear the midword characters for buffer "buf".
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2668 */
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2669 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2670 clear_midword(win_T *wp)
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2671 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2672 vim_memset(wp->w_s->b_spell_ismw, 0, 256);
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2673 #ifdef FEAT_MBYTE
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2674 vim_free(wp->w_s->b_spell_ismw_mb);
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2675 wp->w_s->b_spell_ismw_mb = NULL;
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2676 #endif
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2677 }
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2678
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2679 /*
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2680 * Use the "sl_midword" field of language "lp" for buffer "buf".
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2681 * They add up to any currently used midword characters.
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2682 */
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2683 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2684 use_midword(slang_T *lp, win_T *wp)
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2685 {
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2686 char_u *p;
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2687
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2688 if (lp->sl_midword == NULL) /* there aren't any */
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2689 return;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2690
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2691 for (p = lp->sl_midword; *p != NUL; )
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2692 #ifdef FEAT_MBYTE
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2693 if (has_mbyte)
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2694 {
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2695 int c, l, n;
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2696 char_u *bp;
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2697
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2698 c = mb_ptr2char(p);
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2699 l = (*mb_ptr2len)(p);
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2700 if (c < 256 && l <= 2)
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2701 wp->w_s->b_spell_ismw[c] = TRUE;
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2702 else if (wp->w_s->b_spell_ismw_mb == NULL)
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2703 /* First multi-byte char in "b_spell_ismw_mb". */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2704 wp->w_s->b_spell_ismw_mb = vim_strnsave(p, l);
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2705 else
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2706 {
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2707 /* Append multi-byte chars to "b_spell_ismw_mb". */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2708 n = (int)STRLEN(wp->w_s->b_spell_ismw_mb);
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2709 bp = vim_strnsave(wp->w_s->b_spell_ismw_mb, n + l);
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2710 if (bp != NULL)
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2711 {
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2712 vim_free(wp->w_s->b_spell_ismw_mb);
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2713 wp->w_s->b_spell_ismw_mb = bp;
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2714 vim_strncpy(bp + n, p, l);
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2715 }
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2716 }
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2717 p += l;
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2718 }
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2719 else
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2720 #endif
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2721 wp->w_s->b_spell_ismw[*p++] = TRUE;
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2722 }
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2723
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2724 /*
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2725 * Find the region "region[2]" in "rp" (points to "sl_regions").
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2726 * Each region is simply stored as the two characters of it's name.
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2727 * Returns the index if found (first is 0), REGION_ALL if not found.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2728 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2729 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2730 find_region(char_u *rp, char_u *region)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2731 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2732 int i;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2733
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2734 for (i = 0; ; i += 2)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2735 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2736 if (rp[i] == NUL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2737 return REGION_ALL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2738 if (rp[i] == region[0] && rp[i + 1] == region[1])
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2739 break;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2740 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2741 return i / 2;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2742 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2743
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2744 /*
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2745 * Return case type of word:
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2746 * w word 0
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2747 * Word WF_ONECAP
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2748 * W WORD WF_ALLCAP
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2749 * WoRd wOrd WF_KEEPCAP
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2750 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
2751 int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2752 captype(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2753 char_u *word,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2754 char_u *end) /* When NULL use up to NUL byte. */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2755 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2756 char_u *p;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2757 int c;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2758 int firstcap;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2759 int allcap;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2760 int past_second = FALSE; /* past second word char */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2761
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2762 /* find first letter */
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2763 for (p = word; !spell_iswordp_nmw(p, curwin); mb_ptr_adv(p))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2764 if (end == NULL ? *p == NUL : p >= end)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2765 return 0; /* only non-word characters, illegal word */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2766 #ifdef FEAT_MBYTE
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2767 if (has_mbyte)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2768 c = mb_ptr2char_adv(&p);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2769 else
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2770 #endif
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2771 c = *p++;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2772 firstcap = allcap = SPELL_ISUPPER(c);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2773
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2774 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2775 * Need to check all letters to find a word with mixed upper/lower.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2776 * But a word with an upper char only at start is a ONECAP.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2777 */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2778 for ( ; end == NULL ? *p != NUL : p < end; mb_ptr_adv(p))
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2779 if (spell_iswordp_nmw(p, curwin))
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2780 {
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
2781 c = PTR2CHAR(p);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2782 if (!SPELL_ISUPPER(c))
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2783 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2784 /* UUl -> KEEPCAP */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2785 if (past_second && allcap)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2786 return WF_KEEPCAP;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2787 allcap = FALSE;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2788 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2789 else if (!allcap)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2790 /* UlU -> KEEPCAP */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2791 return WF_KEEPCAP;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2792 past_second = TRUE;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2793 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2794
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2795 if (allcap)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2796 return WF_ALLCAP;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2797 if (firstcap)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2798 return WF_ONECAP;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2799 return 0;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2800 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2801
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2802 /*
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2803 * Like captype() but for a KEEPCAP word add ONECAP if the word starts with a
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2804 * capital. So that make_case_word() can turn WOrd into Word.
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2805 * Add ALLCAP for "WOrD".
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2806 */
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2807 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2808 badword_captype(char_u *word, char_u *end)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2809 {
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2810 int flags = captype(word, end);
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2811 int c;
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2812 int l, u;
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2813 int first;
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2814 char_u *p;
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2815
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2816 if (flags & WF_KEEPCAP)
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2817 {
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2818 /* Count the number of UPPER and lower case letters. */
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2819 l = u = 0;
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2820 first = FALSE;
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2821 for (p = word; p < end; mb_ptr_adv(p))
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2822 {
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2823 c = PTR2CHAR(p);
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2824 if (SPELL_ISUPPER(c))
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2825 {
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2826 ++u;
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2827 if (p == word)
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2828 first = TRUE;
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2829 }
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2830 else
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2831 ++l;
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2832 }
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2833
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2834 /* If there are more UPPER than lower case letters suggest an
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2835 * ALLCAP word. Otherwise, if the first letter is UPPER then
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2836 * suggest ONECAP. Exception: "ALl" most likely should be "All",
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2837 * require three upper case letters. */
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2838 if (u > l && u > 2)
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2839 flags |= WF_ALLCAP;
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2840 else if (first)
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2841 flags |= WF_ONECAP;
633
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
2842
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
2843 if (u >= 2 && l >= 2) /* maCARONI maCAroni */
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
2844 flags |= WF_MIXCAP;
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2845 }
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2846 return flags;
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2847 }
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2848
5519
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2849 /*
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2850 * Delete the internal wordlist and its .spl file.
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2851 */
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2852 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2853 spell_delete_wordlist(void)
5519
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2854 {
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2855 char_u fname[MAXPATHL];
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2856
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2857 if (int_wordlist != NULL)
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2858 {
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2859 mch_remove(int_wordlist);
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2860 int_wordlist_spl(fname);
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2861 mch_remove(fname);
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2862 vim_free(int_wordlist);
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2863 int_wordlist = NULL;
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2864 }
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2865 }
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2866
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2867 #if defined(FEAT_MBYTE) || defined(EXITFREE) || defined(PROTO)
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2868 /*
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2869 * Free all languages.
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2870 */
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2871 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2872 spell_free_all(void)
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2873 {
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2874 slang_T *slang;
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2875 buf_T *buf;
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2876
2580
06aa43dde561 updated for version 7.3.006
Bram Moolenaar <bram@vim.org>
parents: 2457
diff changeset
2877 /* Go through all buffers and handle 'spelllang'. <VN> */
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9583
diff changeset
2878 FOR_ALL_BUFFERS(buf)
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2879 ga_clear(&buf->b_s.b_langp);
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2880
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2881 while (first_lang != NULL)
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2882 {
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2883 slang = first_lang;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2884 first_lang = slang->sl_next;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2885 slang_free(slang);
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2886 }
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2887
5519
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2888 spell_delete_wordlist();
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2889
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
2890 vim_free(repl_to);
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
2891 repl_to = NULL;
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
2892 vim_free(repl_from);
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
2893 repl_from = NULL;
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2894 }
5519
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2895 #endif
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2896
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2897 #if defined(FEAT_MBYTE) || defined(PROTO)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2898 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2899 * Clear all spelling tables and reload them.
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2900 * Used after 'encoding' is set and when ":mkspell" was used.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2901 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2902 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2903 spell_reload(void)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2904 {
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2905 win_T *wp;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2906
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
2907 /* Initialize the table for spell_iswordp(). */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2908 init_spell_chartab();
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2909
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2910 /* Unload all allocated memory. */
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2911 spell_free_all();
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2912
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2913 /* Go through all buffers and handle 'spelllang'. */
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9583
diff changeset
2914 FOR_ALL_WINDOWS(wp)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2915 {
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2916 /* Only load the wordlists when 'spelllang' is set and there is a
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2917 * window for this buffer in which 'spell' is set. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2918 if (*wp->w_s->b_p_spl != NUL)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2919 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2920 if (wp->w_p_spell)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2921 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2922 (void)did_set_spelllang(wp);
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2923 # ifdef FEAT_WINDOWS
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2924 break;
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2925 # endif
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2926 }
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2927 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2928 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2929 }
5519
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2930 #endif
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2931
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2932 /*
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2933 * Opposite of offset2bytes().
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2934 * "pp" points to the bytes and is advanced over it.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2935 * Returns the offset.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2936 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2937 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2938 bytes2offset(char_u **pp)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2939 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2940 char_u *p = *pp;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2941 int nr;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2942 int c;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2943
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2944 c = *p++;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2945 if ((c & 0x80) == 0x00) /* 1 byte */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2946 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2947 nr = c - 1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2948 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2949 else if ((c & 0xc0) == 0x80) /* 2 bytes */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2950 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2951 nr = (c & 0x3f) - 1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2952 nr = nr * 255 + (*p++ - 1);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2953 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2954 else if ((c & 0xe0) == 0xc0) /* 3 bytes */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2955 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2956 nr = (c & 0x1f) - 1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2957 nr = nr * 255 + (*p++ - 1);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2958 nr = nr * 255 + (*p++ - 1);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2959 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2960 else /* 4 bytes */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2961 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2962 nr = (c & 0x0f) - 1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2963 nr = nr * 255 + (*p++ - 1);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2964 nr = nr * 255 + (*p++ - 1);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2965 nr = nr * 255 + (*p++ - 1);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2966 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2967
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2968 *pp = p;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2969 return nr;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2970 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2971
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2972
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2973 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2974 * Open a spell buffer. This is a nameless buffer that is not in the buffer
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2975 * list and only contains text lines. Can use a swapfile to reduce memory
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2976 * use.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2977 * Most other fields are invalid! Esp. watch out for string options being
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2978 * NULL and there is no undo info.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2979 * Returns NULL when out of memory.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2980 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
2981 buf_T *
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2982 open_spellbuf(void)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2983 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2984 buf_T *buf;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2985
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2986 buf = (buf_T *)alloc_clear(sizeof(buf_T));
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2987 if (buf != NULL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2988 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2989 buf->b_spell = TRUE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2990 buf->b_p_swf = TRUE; /* may create a swap file */
5204
7aca84c0cd37 updated for version 7.4a.028
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2991 #ifdef FEAT_CRYPT
7aca84c0cd37 updated for version 7.4a.028
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2992 buf->b_p_key = empty_option;
7aca84c0cd37 updated for version 7.4a.028
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2993 #endif
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2994 ml_open(buf);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2995 ml_open_file(buf); /* create swap file now */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2996 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2997 return buf;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2998 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2999
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3000 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3001 * Close the buffer used for spell info.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3002 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
3003 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3004 close_spellbuf(buf_T *buf)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3005 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3006 if (buf != NULL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3007 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3008 ml_close(buf, TRUE);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3009 vim_free(buf);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3010 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3011 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3012
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3013 /*
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3014 * Init the chartab used for spelling for ASCII.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3015 * EBCDIC is not supported!
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3016 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
3017 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3018 clear_spell_chartab(spelltab_T *sp)
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3019 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3020 int i;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3021
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3022 /* Init everything to FALSE. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3023 vim_memset(sp->st_isw, FALSE, sizeof(sp->st_isw));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3024 vim_memset(sp->st_isu, FALSE, sizeof(sp->st_isu));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3025 for (i = 0; i < 256; ++i)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3026 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3027 sp->st_fold[i] = i;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3028 sp->st_upper[i] = i;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3029 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3030
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3031 /* We include digits. A word shouldn't start with a digit, but handling
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3032 * that is done separately. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3033 for (i = '0'; i <= '9'; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3034 sp->st_isw[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3035 for (i = 'A'; i <= 'Z'; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3036 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3037 sp->st_isw[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3038 sp->st_isu[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3039 sp->st_fold[i] = i + 0x20;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3040 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3041 for (i = 'a'; i <= 'z'; ++i)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3042 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3043 sp->st_isw[i] = TRUE;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3044 sp->st_upper[i] = i - 0x20;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3045 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3046 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3047
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3048 /*
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3049 * Init the chartab used for spelling. Only depends on 'encoding'.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3050 * Called once while starting up and when 'encoding' changes.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3051 * The default is to use isalpha(), but the spell file should define the word
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3052 * characters to make it possible that 'encoding' differs from the current
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3053 * locale. For utf-8 we don't use isalpha() but our own functions.
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3054 */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3055 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3056 init_spell_chartab(void)
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3057 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3058 int i;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3059
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3060 did_set_spelltab = FALSE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3061 clear_spell_chartab(&spelltab);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3062 #ifdef FEAT_MBYTE
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3063 if (enc_dbcs)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3064 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3065 /* DBCS: assume double-wide characters are word characters. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3066 for (i = 128; i <= 255; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3067 if (MB_BYTE2LEN(i) == 2)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3068 spelltab.st_isw[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3069 }
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3070 else if (enc_utf8)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3071 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3072 for (i = 128; i < 256; ++i)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3073 {
2140
12aba62fa7c6 updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents: 2046
diff changeset
3074 int f = utf_fold(i);
12aba62fa7c6 updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents: 2046
diff changeset
3075 int u = utf_toupper(i);
12aba62fa7c6 updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents: 2046
diff changeset
3076
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3077 spelltab.st_isu[i] = utf_isupper(i);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3078 spelltab.st_isw[i] = spelltab.st_isu[i] || utf_islower(i);
2140
12aba62fa7c6 updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents: 2046
diff changeset
3079 /* The folded/upper-cased value is different between latin1 and
12aba62fa7c6 updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents: 2046
diff changeset
3080 * utf8 for 0xb5, causing E763 for no good reason. Use the latin1
12aba62fa7c6 updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents: 2046
diff changeset
3081 * value for utf-8 to avoid this. */
12aba62fa7c6 updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents: 2046
diff changeset
3082 spelltab.st_fold[i] = (f < 256) ? f : i;
12aba62fa7c6 updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents: 2046
diff changeset
3083 spelltab.st_upper[i] = (u < 256) ? u : i;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3084 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3085 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3086 else
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3087 #endif
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3088 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3089 /* Rough guess: use locale-dependent library functions. */
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3090 for (i = 128; i < 256; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3091 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3092 if (MB_ISUPPER(i))
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3093 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3094 spelltab.st_isw[i] = TRUE;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3095 spelltab.st_isu[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3096 spelltab.st_fold[i] = MB_TOLOWER(i);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3097 }
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3098 else if (MB_ISLOWER(i))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3099 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3100 spelltab.st_isw[i] = TRUE;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3101 spelltab.st_upper[i] = MB_TOUPPER(i);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3102 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3103 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3104 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3105 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3106
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3107
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3108 /*
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
3109 * Return TRUE if "p" points to a word character.
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3110 * As a special case we see "midword" characters as word character when it is
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
3111 * followed by a word character. This finds they'there but not 'they there'.
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3112 * Thus this only works properly when past the first character of the word.
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
3113 */
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
3114 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3115 spell_iswordp(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3116 char_u *p,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3117 win_T *wp) /* buffer used */
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
3118 {
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3119 #ifdef FEAT_MBYTE
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
3120 char_u *s;
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3121 int l;
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3122 int c;
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3123
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3124 if (has_mbyte)
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3125 {
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3126 l = MB_BYTE2LEN(*p);
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
3127 s = p;
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3128 if (l == 1)
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3129 {
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3130 /* be quick for ASCII */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3131 if (wp->w_s->b_spell_ismw[*p])
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3132 s = p + 1; /* skip a mid-word character */
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3133 }
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3134 else
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3135 {
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3136 c = mb_ptr2char(p);
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3137 if (c < 256 ? wp->w_s->b_spell_ismw[c]
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3138 : (wp->w_s->b_spell_ismw_mb != NULL
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3139 && vim_strchr(wp->w_s->b_spell_ismw_mb, c) != NULL))
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3140 s = p + l;
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3141 }
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3142
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3143 c = mb_ptr2char(s);
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3144 if (c > 255)
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3145 return spell_mb_isword_class(mb_get_class(s), wp);
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3146 return spelltab.st_isw[c];
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3147 }
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
3148 #endif
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
3149
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3150 return spelltab.st_isw[wp->w_s->b_spell_ismw[*p] ? p[1] : p[0]];
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
3151 }
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
3152
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
3153 /*
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
3154 * Return TRUE if "p" points to a word character.
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
3155 * Unlike spell_iswordp() this doesn't check for "midword" characters.
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
3156 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
3157 int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3158 spell_iswordp_nmw(char_u *p, win_T *wp)
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
3159 {
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
3160 #ifdef FEAT_MBYTE
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3161 int c;
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3162
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3163 if (has_mbyte)
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3164 {
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3165 c = mb_ptr2char(p);
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3166 if (c > 255)
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3167 return spell_mb_isword_class(mb_get_class(p), wp);
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3168 return spelltab.st_isw[c];
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3169 }
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
3170 #endif
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
3171 return spelltab.st_isw[*p];
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
3172 }
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
3173
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3174 #ifdef FEAT_MBYTE
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3175 /*
1580
5e75d07bfe75 updated for version 7.1-293
vimboss
parents: 1577
diff changeset
3176 * Return TRUE if word class indicates a word character.
5e75d07bfe75 updated for version 7.1-293
vimboss
parents: 1577
diff changeset
3177 * Only for characters above 255.
5e75d07bfe75 updated for version 7.1-293
vimboss
parents: 1577
diff changeset
3178 * Unicode subscript and superscript are not considered word characters.
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3179 * See also dbcs_class() and utf_class() in mbyte.c.
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3180 */
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3181 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3182 spell_mb_isword_class(int cl, win_T *wp)
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3183 {
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3184 if (wp->w_s->b_cjk)
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3185 /* East Asian characters are not considered word characters. */
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3186 return cl == 2 || cl == 0x2800;
1580
5e75d07bfe75 updated for version 7.1-293
vimboss
parents: 1577
diff changeset
3187 return cl >= 2 && cl != 0x2070 && cl != 0x2080;
5e75d07bfe75 updated for version 7.1-293
vimboss
parents: 1577
diff changeset
3188 }
5e75d07bfe75 updated for version 7.1-293
vimboss
parents: 1577
diff changeset
3189
5e75d07bfe75 updated for version 7.1-293
vimboss
parents: 1577
diff changeset
3190 /*
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3191 * Return TRUE if "p" points to a word character.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3192 * Wide version of spell_iswordp().
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3193 */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3194 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3195 spell_iswordp_w(int *p, win_T *wp)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3196 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3197 int *s;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3198
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3199 if (*p < 256 ? wp->w_s->b_spell_ismw[*p]
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3200 : (wp->w_s->b_spell_ismw_mb != NULL
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3201 && vim_strchr(wp->w_s->b_spell_ismw_mb, *p) != NULL))
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3202 s = p + 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3203 else
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3204 s = p;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3205
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3206 if (*s > 255)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3207 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3208 if (enc_utf8)
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3209 return spell_mb_isword_class(utf_class(*s), wp);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3210 if (enc_dbcs)
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3211 return spell_mb_isword_class(
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3212 dbcs_class((unsigned)*s >> 8, *s & 0xff), wp);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3213 return 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3214 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3215 return spelltab.st_isw[*s];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3216 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3217 #endif
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3218
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
3219 /*
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3220 * Case-fold "str[len]" into "buf[buflen]". The result is NUL terminated.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3221 * Uses the character definitions from the .spl file.
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3222 * When using a multi-byte 'encoding' the length may change!
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3223 * Returns FAIL when something wrong.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3224 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
3225 int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3226 spell_casefold(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3227 char_u *str,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3228 int len,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3229 char_u *buf,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3230 int buflen)
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3231 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3232 int i;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3233
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3234 if (len >= buflen)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3235 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3236 buf[0] = NUL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3237 return FAIL; /* result will not fit */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3238 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3239
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3240 #ifdef FEAT_MBYTE
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3241 if (has_mbyte)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3242 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3243 int outi = 0;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3244 char_u *p;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3245 int c;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3246
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3247 /* Fold one character at a time. */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3248 for (p = str; p < str + len; )
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3249 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3250 if (outi + MB_MAXBYTES > buflen)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3251 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3252 buf[outi] = NUL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3253 return FAIL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3254 }
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3255 c = mb_cptr2char_adv(&p);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3256 outi += mb_char2bytes(SPELL_TOFOLD(c), buf + outi);
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3257 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3258 buf[outi] = NUL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3259 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3260 else
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3261 #endif
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3262 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3263 /* Be quick for non-multibyte encodings. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3264 for (i = 0; i < len; ++i)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3265 buf[i] = spelltab.st_fold[str[i]];
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3266 buf[i] = NUL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3267 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3268
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3269 return OK;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3270 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3271
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3272 /* values for sps_flags */
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3273 #define SPS_BEST 1
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3274 #define SPS_FAST 2
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3275 #define SPS_DOUBLE 4
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3276
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3277 static int sps_flags = SPS_BEST; /* flags from 'spellsuggest' */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3278 static int sps_limit = 9999; /* max nr of suggestions given */
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3279
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3280 /*
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3281 * Check the 'spellsuggest' option. Return FAIL if it's wrong.
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3282 * Sets "sps_flags" and "sps_limit".
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3283 */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3284 int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3285 spell_check_sps(void)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3286 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3287 char_u *p;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3288 char_u *s;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3289 char_u buf[MAXPATHL];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3290 int f;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3291
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3292 sps_flags = 0;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3293 sps_limit = 9999;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3294
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3295 for (p = p_sps; *p != NUL; )
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3296 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3297 copy_option_part(&p, buf, MAXPATHL, ",");
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3298
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3299 f = 0;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3300 if (VIM_ISDIGIT(*buf))
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3301 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3302 s = buf;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3303 sps_limit = getdigits(&s);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3304 if (*s != NUL && !VIM_ISDIGIT(*s))
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3305 f = -1;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3306 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3307 else if (STRCMP(buf, "best") == 0)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3308 f = SPS_BEST;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3309 else if (STRCMP(buf, "fast") == 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3310 f = SPS_FAST;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3311 else if (STRCMP(buf, "double") == 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3312 f = SPS_DOUBLE;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3313 else if (STRNCMP(buf, "expr:", 5) != 0
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3314 && STRNCMP(buf, "file:", 5) != 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3315 f = -1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3316
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3317 if (f == -1 || (sps_flags != 0 && f != 0))
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3318 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3319 sps_flags = SPS_BEST;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3320 sps_limit = 9999;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3321 return FAIL;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3322 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3323 if (f != 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3324 sps_flags = f;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3325 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3326
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3327 if (sps_flags == 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3328 sps_flags = SPS_BEST;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3329
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3330 return OK;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3331 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3332
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3333 /*
5374
6daa78b6b99a updated for version 7.4.038
Bram Moolenaar <bram@vim.org>
parents: 5204
diff changeset
3334 * "z=": Find badly spelled word under or after the cursor.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3335 * Give suggestions for the properly spelled word.
638
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3336 * In Visual mode use the highlighted word as the bad word.
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3337 * When "count" is non-zero use that suggestion.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3338 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3339 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3340 spell_suggest(int count)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3341 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3342 char_u *line;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3343 pos_T prev_cursor = curwin->w_cursor;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3344 char_u wcopy[MAXWLEN + 2];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3345 char_u *p;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3346 int i;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3347 int c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3348 suginfo_T sug;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3349 suggest_T *stp;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3350 int mouse_used;
388
f92bb1845823 updated for version 7.0101
vimboss
parents: 385
diff changeset
3351 int need_cap;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3352 int limit;
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3353 int selected = count;
638
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3354 int badlen = 0;
1938
5ed9395c1864 updated for version 7.2-235
vimboss
parents: 1883
diff changeset
3355 int msg_scroll_save = msg_scroll;
638
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3356
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3357 if (no_spell_checking(curwin))
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3358 return;
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3359
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3360 if (VIsual_active)
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3361 {
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3362 /* Use the Visually selected text as the bad word. But reject
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3363 * a multi-line selection. */
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3364 if (curwin->w_cursor.lnum != VIsual.lnum)
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3365 {
6949
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6721
diff changeset
3366 vim_beep(BO_SPELL);
638
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3367 return;
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3368 }
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3369 badlen = (int)curwin->w_cursor.col - (int)VIsual.col;
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3370 if (badlen < 0)
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3371 badlen = -badlen;
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3372 else
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3373 curwin->w_cursor.col = VIsual.col;
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3374 ++badlen;
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3375 end_visual_mode();
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3376 }
5735
50dbef5e774a updated for version 7.4.212
Bram Moolenaar <bram@vim.org>
parents: 5695
diff changeset
3377 /* Find the start of the badly spelled word. */
50dbef5e774a updated for version 7.4.212
Bram Moolenaar <bram@vim.org>
parents: 5695
diff changeset
3378 else if (spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL) == 0
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3379 || curwin->w_cursor.col > prev_cursor.col)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3380 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3381 /* No bad word or it starts after the cursor: use the word under the
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3382 * cursor. */
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3383 curwin->w_cursor = prev_cursor;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3384 line = ml_get_curline();
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3385 p = line + curwin->w_cursor.col;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3386 /* Backup to before start of word. */
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3387 while (p > line && spell_iswordp_nmw(p, curwin))
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3388 mb_ptr_back(line, p);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3389 /* Forward to start of word. */
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3390 while (*p != NUL && !spell_iswordp_nmw(p, curwin))
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3391 mb_ptr_adv(p);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3392
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3393 if (!spell_iswordp_nmw(p, curwin)) /* No word found. */
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3394 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3395 beep_flush();
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3396 return;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3397 }
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
3398 curwin->w_cursor.col = (colnr_T)(p - line);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3399 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3400
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3401 /* Get the word and its length. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3402
388
f92bb1845823 updated for version 7.0101
vimboss
parents: 385
diff changeset
3403 /* Figure out if the word should be capitalised. */
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3404 need_cap = check_need_cap(curwin->w_cursor.lnum, curwin->w_cursor.col);
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3405
2046
d433f43849ba updated for version 7.2.332
Bram Moolenaar <bram@zimbu.org>
parents: 1938
diff changeset
3406 /* Make a copy of current line since autocommands may free the line. */
d433f43849ba updated for version 7.2.332
Bram Moolenaar <bram@zimbu.org>
parents: 1938
diff changeset
3407 line = vim_strsave(ml_get_curline());
d433f43849ba updated for version 7.2.332
Bram Moolenaar <bram@zimbu.org>
parents: 1938
diff changeset
3408 if (line == NULL)
d433f43849ba updated for version 7.2.332
Bram Moolenaar <bram@zimbu.org>
parents: 1938
diff changeset
3409 goto skip;
388
f92bb1845823 updated for version 7.0101
vimboss
parents: 385
diff changeset
3410
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3411 /* Get the list of suggestions. Limit to 'lines' - 2 or the number in
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3412 * 'spellsuggest', whatever is smaller. */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3413 if (sps_limit > (int)Rows - 2)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3414 limit = (int)Rows - 2;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3415 else
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3416 limit = sps_limit;
638
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3417 spell_find_suggest(line + curwin->w_cursor.col, badlen, &sug, limit,
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3418 TRUE, need_cap, TRUE);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3419
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3420 if (sug.su_ga.ga_len == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3421 MSG(_("Sorry, no suggestions"));
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3422 else if (count > 0)
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3423 {
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3424 if (count > sug.su_ga.ga_len)
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3425 smsg((char_u *)_("Sorry, only %ld suggestions"),
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3426 (long)sug.su_ga.ga_len);
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3427 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3428 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3429 {
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3430 vim_free(repl_from);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3431 repl_from = NULL;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3432 vim_free(repl_to);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3433 repl_to = NULL;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3434
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3435 #ifdef FEAT_RIGHTLEFT
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3436 /* When 'rightleft' is set the list is drawn right-left. */
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3437 cmdmsg_rl = curwin->w_p_rl;
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3438 if (cmdmsg_rl)
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3439 msg_col = Columns - 1;
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3440 #endif
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3441
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3442 /* List the suggestions. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3443 msg_start();
914
bc68103ea3f6 updated for version 7.0-040
vimboss
parents: 883
diff changeset
3444 msg_row = Rows - 1; /* for when 'cmdheight' > 1 */
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3445 lines_left = Rows; /* avoid more prompt */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3446 vim_snprintf((char *)IObuff, IOSIZE, _("Change \"%.*s\" to:"),
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3447 sug.su_badlen, sug.su_badptr);
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3448 #ifdef FEAT_RIGHTLEFT
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3449 if (cmdmsg_rl && STRNCMP(IObuff, "Change", 6) == 0)
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3450 {
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3451 /* And now the rabbit from the high hat: Avoid showing the
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3452 * untranslated message rightleft. */
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3453 vim_snprintf((char *)IObuff, IOSIZE, ":ot \"%.*s\" egnahC",
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3454 sug.su_badlen, sug.su_badptr);
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3455 }
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3456 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3457 msg_puts(IObuff);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3458 msg_clr_eos();
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3459 msg_putchar('\n');
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3460
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3461 msg_scroll = TRUE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3462 for (i = 0; i < sug.su_ga.ga_len; ++i)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3463 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3464 stp = &SUG(sug.su_ga, i);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3465
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3466 /* The suggested word may replace only part of the bad word, add
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3467 * the not replaced part. */
2768
c5e47b752f07 updated for version 7.3.160
Bram Moolenaar <bram@vim.org>
parents: 2691
diff changeset
3468 vim_strncpy(wcopy, stp->st_word, MAXWLEN);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3469 if (sug.su_badlen > stp->st_orglen)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3470 vim_strncpy(wcopy + stp->st_wordlen,
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3471 sug.su_badptr + stp->st_orglen,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3472 sug.su_badlen - stp->st_orglen);
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3473 vim_snprintf((char *)IObuff, IOSIZE, "%2d", i + 1);
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3474 #ifdef FEAT_RIGHTLEFT
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3475 if (cmdmsg_rl)
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3476 rl_mirror(IObuff);
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3477 #endif
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3478 msg_puts(IObuff);
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3479
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3480 vim_snprintf((char *)IObuff, IOSIZE, " \"%s\"", wcopy);
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3481 msg_puts(IObuff);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3482
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3483 /* The word may replace more than "su_badlen". */
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3484 if (sug.su_badlen < stp->st_orglen)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3485 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3486 vim_snprintf((char *)IObuff, IOSIZE, _(" < \"%.*s\""),
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3487 stp->st_orglen, sug.su_badptr);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3488 msg_puts(IObuff);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3489 }
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3490
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3491 if (p_verbose > 0)
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3492 {
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3493 /* Add the score. */
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3494 if (sps_flags & (SPS_DOUBLE | SPS_BEST))
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3495 vim_snprintf((char *)IObuff, IOSIZE, " (%s%d - %d)",
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3496 stp->st_salscore ? "s " : "",
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3497 stp->st_score, stp->st_altscore);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3498 else
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3499 vim_snprintf((char *)IObuff, IOSIZE, " (%d)",
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3500 stp->st_score);
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3501 #ifdef FEAT_RIGHTLEFT
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3502 if (cmdmsg_rl)
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3503 /* Mirror the numbers, but keep the leading space. */
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3504 rl_mirror(IObuff + 1);
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3505 #endif
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3506 msg_advance(30);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3507 msg_puts(IObuff);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3508 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3509 msg_putchar('\n');
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3510 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3511
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3512 #ifdef FEAT_RIGHTLEFT
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3513 cmdmsg_rl = FALSE;
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3514 msg_col = 0;
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3515 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3516 /* Ask for choice. */
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3517 selected = prompt_for_number(&mouse_used);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3518 if (mouse_used)
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3519 selected -= lines_left;
1938
5ed9395c1864 updated for version 7.2-235
vimboss
parents: 1883
diff changeset
3520 lines_left = Rows; /* avoid more prompt */
5ed9395c1864 updated for version 7.2-235
vimboss
parents: 1883
diff changeset
3521 /* don't delay for 'smd' in normal_cmd() */
5ed9395c1864 updated for version 7.2-235
vimboss
parents: 1883
diff changeset
3522 msg_scroll = msg_scroll_save;
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3523 }
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3524
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3525 if (selected > 0 && selected <= sug.su_ga.ga_len && u_save_cursor() == OK)
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3526 {
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3527 /* Save the from and to text for :spellrepall. */
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3528 stp = &SUG(sug.su_ga, selected - 1);
548
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3529 if (sug.su_badlen > stp->st_orglen)
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3530 {
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3531 /* Replacing less than "su_badlen", append the remainder to
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3532 * repl_to. */
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3533 repl_from = vim_strnsave(sug.su_badptr, sug.su_badlen);
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3534 vim_snprintf((char *)IObuff, IOSIZE, "%s%.*s", stp->st_word,
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3535 sug.su_badlen - stp->st_orglen,
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3536 sug.su_badptr + stp->st_orglen);
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3537 repl_to = vim_strsave(IObuff);
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3538 }
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3539 else
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3540 {
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3541 /* Replacing su_badlen or more, use the whole word. */
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3542 repl_from = vim_strnsave(sug.su_badptr, stp->st_orglen);
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3543 repl_to = vim_strsave(stp->st_word);
f43150a669dc updated for version 7.0155
vimboss
parents: 539
diff changeset
3544 }
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3545
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3546 /* Replace the word. */
1938
5ed9395c1864 updated for version 7.2-235
vimboss
parents: 1883
diff changeset
3547 p = alloc((unsigned)STRLEN(line) - stp->st_orglen
5ed9395c1864 updated for version 7.2-235
vimboss
parents: 1883
diff changeset
3548 + stp->st_wordlen + 1);
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3549 if (p != NULL)
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3550 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
3551 c = (int)(sug.su_badptr - line);
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3552 mch_memmove(p, line, c);
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3553 STRCPY(p + c, stp->st_word);
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3554 STRCAT(p, sug.su_badptr + stp->st_orglen);
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3555 ml_replace(curwin->w_cursor.lnum, p, FALSE);
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3556 curwin->w_cursor.col = c;
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3557
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3558 /* For redo we use a change-word command. */
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3559 ResetRedobuff();
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3560 AppendToRedobuff((char_u *)"ciw");
620
9e359e5759f6 updated for version 7.0177
vimboss
parents: 592
diff changeset
3561 AppendToRedobuffLit(p + c,
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3562 stp->st_wordlen + sug.su_badlen - stp->st_orglen);
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3563 AppendCharToRedobuff(ESC);
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
3564
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
3565 /* After this "p" may be invalid. */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
3566 changed_bytes(curwin->w_cursor.lnum, c);
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3567 }
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3568 }
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3569 else
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3570 curwin->w_cursor = prev_cursor;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3571
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3572 spell_find_cleanup(&sug);
2046
d433f43849ba updated for version 7.2.332
Bram Moolenaar <bram@zimbu.org>
parents: 1938
diff changeset
3573 skip:
d433f43849ba updated for version 7.2.332
Bram Moolenaar <bram@zimbu.org>
parents: 1938
diff changeset
3574 vim_free(line);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3575 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3576
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3577 /*
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3578 * Check if the word at line "lnum" column "col" is required to start with a
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3579 * capital. This uses 'spellcapcheck' of the current buffer.
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3580 */
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3581 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3582 check_need_cap(linenr_T lnum, colnr_T col)
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3583 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3584 int need_cap = FALSE;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3585 char_u *line;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3586 char_u *line_copy = NULL;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3587 char_u *p;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3588 colnr_T endcol;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3589 regmatch_T regmatch;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3590
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3591 if (curwin->w_s->b_cap_prog == NULL)
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3592 return FALSE;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3593
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3594 line = ml_get_curline();
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3595 endcol = 0;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3596 if ((int)(skipwhite(line) - line) >= (int)col)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3597 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3598 /* At start of line, check if previous line is empty or sentence
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3599 * ends there. */
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3600 if (lnum == 1)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3601 need_cap = TRUE;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3602 else
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3603 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3604 line = ml_get(lnum - 1);
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3605 if (*skipwhite(line) == NUL)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3606 need_cap = TRUE;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3607 else
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3608 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3609 /* Append a space in place of the line break. */
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3610 line_copy = concat_str(line, (char_u *)" ");
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3611 line = line_copy;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
3612 endcol = (colnr_T)STRLEN(line);
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3613 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3614 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3615 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3616 else
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3617 endcol = col;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3618
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3619 if (endcol > 0)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3620 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3621 /* Check if sentence ends before the bad word. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3622 regmatch.regprog = curwin->w_s->b_cap_prog;
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3623 regmatch.rm_ic = FALSE;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3624 p = line + endcol;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3625 for (;;)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3626 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3627 mb_ptr_back(line, p);
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3628 if (p == line || spell_iswordp_nmw(p, curwin))
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3629 break;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3630 if (vim_regexec(&regmatch, p, 0)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3631 && regmatch.endp[0] == line + endcol)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3632 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3633 need_cap = TRUE;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3634 break;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3635 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3636 }
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
3637 curwin->w_s->b_cap_prog = regmatch.regprog;
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3638 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3639
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3640 vim_free(line_copy);
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3641
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3642 return need_cap;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3643 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3644
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3645
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
3646 /*
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3647 * ":spellrepall"
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3648 */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3649 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3650 ex_spellrepall(exarg_T *eap UNUSED)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3651 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3652 pos_T pos = curwin->w_cursor;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3653 char_u *frompat;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3654 int addlen;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3655 char_u *line;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3656 char_u *p;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3657 int save_ws = p_ws;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3658 linenr_T prev_lnum = 0;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3659
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3660 if (repl_from == NULL || repl_to == NULL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3661 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3662 EMSG(_("E752: No previous spell replacement"));
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3663 return;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3664 }
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
3665 addlen = (int)(STRLEN(repl_to) - STRLEN(repl_from));
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
3666
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
3667 frompat = alloc((unsigned)STRLEN(repl_from) + 7);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3668 if (frompat == NULL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3669 return;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3670 sprintf((char *)frompat, "\\V\\<%s\\>", repl_from);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3671 p_ws = FALSE;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3672
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3673 sub_nsubs = 0;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3674 sub_nlines = 0;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3675 curwin->w_cursor.lnum = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3676 while (!got_int)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3677 {
1521
cc4fe241baa3 updated for version 7.1-236
vimboss
parents: 1504
diff changeset
3678 if (do_search(NULL, '/', frompat, 1L, SEARCH_KEEP, NULL) == 0
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3679 || u_save_cursor() == FAIL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3680 break;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3681
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3682 /* Only replace when the right word isn't there yet. This happens
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3683 * when changing "etc" to "etc.". */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3684 line = ml_get_curline();
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3685 if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col,
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3686 repl_to, STRLEN(repl_to)) != 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3687 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
3688 p = alloc((unsigned)STRLEN(line) + addlen + 1);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3689 if (p == NULL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3690 break;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3691 mch_memmove(p, line, curwin->w_cursor.col);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3692 STRCPY(p + curwin->w_cursor.col, repl_to);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3693 STRCAT(p, line + curwin->w_cursor.col + STRLEN(repl_from));
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3694 ml_replace(curwin->w_cursor.lnum, p, FALSE);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3695 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3696
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3697 if (curwin->w_cursor.lnum != prev_lnum)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3698 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3699 ++sub_nlines;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3700 prev_lnum = curwin->w_cursor.lnum;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3701 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3702 ++sub_nsubs;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3703 }
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
3704 curwin->w_cursor.col += (colnr_T)STRLEN(repl_to);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3705 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3706
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3707 p_ws = save_ws;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3708 curwin->w_cursor = pos;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3709 vim_free(frompat);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3710
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3711 if (sub_nsubs == 0)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3712 EMSG2(_("E753: Not found: %s"), repl_from);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3713 else
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
3714 do_sub_msg(FALSE);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3715 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3716
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3717 /*
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3718 * Find spell suggestions for "word". Return them in the growarray "*gap" as
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3719 * a list of allocated strings.
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3720 */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3721 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3722 spell_suggest_list(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3723 garray_T *gap,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3724 char_u *word,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3725 int maxcount, /* maximum nr of suggestions */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3726 int need_cap, /* 'spellcapcheck' matched */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3727 int interactive)
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3728 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3729 suginfo_T sug;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3730 int i;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3731 suggest_T *stp;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3732 char_u *wcopy;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3733
638
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3734 spell_find_suggest(word, 0, &sug, maxcount, FALSE, need_cap, interactive);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3735
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3736 /* Make room in "gap". */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3737 ga_init2(gap, sizeof(char_u *), sug.su_ga.ga_len + 1);
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3738 if (ga_grow(gap, sug.su_ga.ga_len) == OK)
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3739 {
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3740 for (i = 0; i < sug.su_ga.ga_len; ++i)
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3741 {
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3742 stp = &SUG(sug.su_ga, i);
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3743
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3744 /* The suggested word may replace only part of "word", add the not
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3745 * replaced part. */
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3746 wcopy = alloc(stp->st_wordlen
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
3747 + (unsigned)STRLEN(sug.su_badptr + stp->st_orglen) + 1);
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3748 if (wcopy == NULL)
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3749 break;
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3750 STRCPY(wcopy, stp->st_word);
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3751 STRCPY(wcopy + stp->st_wordlen, sug.su_badptr + stp->st_orglen);
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3752 ((char_u **)gap->ga_data)[gap->ga_len++] = wcopy;
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3753 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3754 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3755
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3756 spell_find_cleanup(&sug);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3757 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3758
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3759 /*
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3760 * Find spell suggestions for the word at the start of "badptr".
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3761 * Return the suggestions in "su->su_ga".
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3762 * The maximum number of suggestions is "maxcount".
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3763 * Note: does use info for the current window.
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3764 * This is based on the mechanisms of Aspell, but completely reimplemented.
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3765 */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3766 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3767 spell_find_suggest(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3768 char_u *badptr,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3769 int badlen, /* length of bad word or 0 if unknown */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3770 suginfo_T *su,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3771 int maxcount,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3772 int banbadword, /* don't include badword in suggestions */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3773 int need_cap, /* word should start with capital */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3774 int interactive)
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3775 {
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
3776 hlf_T attr = HLF_COUNT;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3777 char_u buf[MAXPATHL];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3778 char_u *p;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3779 int do_combine = FALSE;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3780 char_u *sps_copy;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3781 #ifdef FEAT_EVAL
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3782 static int expr_busy = FALSE;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3783 #endif
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
3784 int c;
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
3785 int i;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
3786 langp_T *lp;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3787
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3788 /*
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3789 * Set the info in "*su".
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3790 */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3791 vim_memset(su, 0, sizeof(suginfo_T));
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3792 ga_init2(&su->su_ga, (int)sizeof(suggest_T), 10);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3793 ga_init2(&su->su_sga, (int)sizeof(suggest_T), 10);
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
3794 if (*badptr == NUL)
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
3795 return;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3796 hash_init(&su->su_banned);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3797
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3798 su->su_badptr = badptr;
638
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3799 if (badlen != 0)
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3800 su->su_badlen = badlen;
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3801 else
593092a5362b updated for version 7.0185
vimboss
parents: 633
diff changeset
3802 su->su_badlen = spell_check(curwin, su->su_badptr, &attr, NULL, FALSE);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3803 su->su_maxcount = maxcount;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3804 su->su_maxscore = SCORE_MAXINIT;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3805
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3806 if (su->su_badlen >= MAXWLEN)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3807 su->su_badlen = MAXWLEN - 1; /* just in case */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3808 vim_strncpy(su->su_badword, su->su_badptr, su->su_badlen);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3809 (void)spell_casefold(su->su_badptr, su->su_badlen,
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3810 su->su_fbadword, MAXWLEN);
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
3811 /* get caps flags for bad word */
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3812 su->su_badflags = badword_captype(su->su_badptr,
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3813 su->su_badptr + su->su_badlen);
388
f92bb1845823 updated for version 7.0101
vimboss
parents: 385
diff changeset
3814 if (need_cap)
f92bb1845823 updated for version 7.0101
vimboss
parents: 385
diff changeset
3815 su->su_badflags |= WF_ONECAP;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3816
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
3817 /* Find the default language for sound folding. We simply use the first
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
3818 * one in 'spelllang' that supports sound folding. That's good for when
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
3819 * using multiple files for one language, it's not that bad when mixing
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
3820 * languages (e.g., "pl,en"). */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3821 for (i = 0; i < curbuf->b_s.b_langp.ga_len; ++i)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3822 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3823 lp = LANGP_ENTRY(curbuf->b_s.b_langp, i);
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
3824 if (lp->lp_sallang != NULL)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
3825 {
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
3826 su->su_sallang = lp->lp_sallang;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
3827 break;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
3828 }
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
3829 }
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
3830
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
3831 /* Soundfold the bad word with the default sound folding, so that we don't
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
3832 * have to do this many times. */
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
3833 if (su->su_sallang != NULL)
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
3834 spell_soundfold(su->su_sallang, su->su_fbadword, TRUE,
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
3835 su->su_sal_badword);
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
3836
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
3837 /* If the word is not capitalised and spell_check() doesn't consider the
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
3838 * word to be bad then it might need to be capitalised. Add a suggestion
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
3839 * for that. */
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
3840 c = PTR2CHAR(su->su_badptr);
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
3841 if (!SPELL_ISUPPER(c) && attr == HLF_COUNT)
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
3842 {
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
3843 make_case_word(su->su_badword, buf, WF_ONECAP);
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
3844 add_suggestion(su, &su->su_ga, buf, su->su_badlen, SCORE_ICASE,
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3845 0, TRUE, su->su_sallang, FALSE);
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
3846 }
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
3847
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3848 /* Ban the bad word itself. It may appear in another region. */
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
3849 if (banbadword)
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
3850 add_banned(su, su->su_badword);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3851
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3852 /* Make a copy of 'spellsuggest', because the expression may change it. */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3853 sps_copy = vim_strsave(p_sps);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3854 if (sps_copy == NULL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3855 return;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3856
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3857 /* Loop over the items in 'spellsuggest'. */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3858 for (p = sps_copy; *p != NUL; )
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3859 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3860 copy_option_part(&p, buf, MAXPATHL, ",");
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3861
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3862 if (STRNCMP(buf, "expr:", 5) == 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3863 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3864 #ifdef FEAT_EVAL
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3865 /* Evaluate an expression. Skip this when called recursively,
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3866 * when using spellsuggest() in the expression. */
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3867 if (!expr_busy)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3868 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3869 expr_busy = TRUE;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3870 spell_suggest_expr(su, buf + 5);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3871 expr_busy = FALSE;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3872 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3873 #endif
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3874 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3875 else if (STRNCMP(buf, "file:", 5) == 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3876 /* Use list of suggestions in a file. */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3877 spell_suggest_file(su, buf + 5);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3878 else
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3879 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3880 /* Use internal method. */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3881 spell_suggest_intern(su, interactive);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3882 if (sps_flags & SPS_DOUBLE)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3883 do_combine = TRUE;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3884 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3885 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3886
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3887 vim_free(sps_copy);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3888
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3889 if (do_combine)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3890 /* Combine the two list of suggestions. This must be done last,
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3891 * because sorting changes the order again. */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3892 score_combine(su);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3893 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3894
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3895 #ifdef FEAT_EVAL
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3896 /*
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3897 * Find suggestions by evaluating expression "expr".
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3898 */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3899 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3900 spell_suggest_expr(suginfo_T *su, char_u *expr)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3901 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3902 list_T *list;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3903 listitem_T *li;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3904 int score;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3905 char_u *p;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3906
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3907 /* The work is split up in a few parts to avoid having to export
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3908 * suginfo_T.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3909 * First evaluate the expression and get the resulting list. */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3910 list = eval_spell_expr(su->su_badword, expr);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3911 if (list != NULL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3912 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3913 /* Loop over the items in the list. */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3914 for (li = list->lv_first; li != NULL; li = li->li_next)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3915 if (li->li_tv.v_type == VAR_LIST)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3916 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3917 /* Get the word and the score from the items. */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3918 score = get_spellword(li->li_tv.vval.v_list, &p);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3919 if (score >= 0 && score <= su->su_maxscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3920 add_suggestion(su, &su->su_ga, p, su->su_badlen,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3921 score, 0, TRUE, su->su_sallang, FALSE);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3922 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3923 list_unref(list);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3924 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3925
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3926 /* Remove bogus suggestions, sort and truncate at "maxcount". */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3927 check_suggestions(su, &su->su_ga);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3928 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, su->su_maxcount);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3929 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3930 #endif
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3931
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3932 /*
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3933 * Find suggestions in file "fname". Used for "file:" in 'spellsuggest'.
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3934 */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3935 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3936 spell_suggest_file(suginfo_T *su, char_u *fname)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3937 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3938 FILE *fd;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3939 char_u line[MAXWLEN * 2];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3940 char_u *p;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3941 int len;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3942 char_u cword[MAXWLEN];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3943
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3944 /* Open the file. */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3945 fd = mch_fopen((char *)fname, "r");
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3946 if (fd == NULL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3947 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3948 EMSG2(_(e_notopen), fname);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3949 return;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3950 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3951
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3952 /* Read it line by line. */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3953 while (!vim_fgets(line, MAXWLEN * 2, fd) && !got_int)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3954 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3955 line_breakcheck();
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3956
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3957 p = vim_strchr(line, '/');
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3958 if (p == NULL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3959 continue; /* No Tab found, just skip the line. */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3960 *p++ = NUL;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3961 if (STRICMP(su->su_badword, line) == 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3962 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3963 /* Match! Isolate the good word, until CR or NL. */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3964 for (len = 0; p[len] >= ' '; ++len)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3965 ;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3966 p[len] = NUL;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3967
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3968 /* If the suggestion doesn't have specific case duplicate the case
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3969 * of the bad word. */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3970 if (captype(p, NULL) == 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3971 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3972 make_case_word(p, cword, su->su_badflags);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3973 p = cword;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3974 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3975
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3976 add_suggestion(su, &su->su_ga, p, su->su_badlen,
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3977 SCORE_FILE, 0, TRUE, su->su_sallang, FALSE);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3978 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3979 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3980
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3981 fclose(fd);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3982
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3983 /* Remove bogus suggestions, sort and truncate at "maxcount". */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3984 check_suggestions(su, &su->su_ga);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3985 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, su->su_maxcount);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3986 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3987
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3988 /*
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3989 * Find suggestions for the internal method indicated by "sps_flags".
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3990 */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3991 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3992 spell_suggest_intern(suginfo_T *su, int interactive)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3993 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3994 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3995 * Load the .sug file(s) that are available and not done yet.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3996 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3997 suggest_load_files();
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3998
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3999 /*
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4000 * 1. Try special cases, such as repeating a word: "the the" -> "the".
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4001 *
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4002 * Set a maximum score to limit the combination of operations that is
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4003 * tried.
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4004 */
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4005 suggest_try_special(su);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4006
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4007 /*
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4008 * 2. Try inserting/deleting/swapping/changing a letter, use REP entries
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4009 * from the .aff file and inserting a space (split the word).
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4010 */
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4011 suggest_try_change(su);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4012
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4013 /* For the resulting top-scorers compute the sound-a-like score. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4014 if (sps_flags & SPS_DOUBLE)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4015 score_comp_sal(su);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4016
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4017 /*
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4018 * 3. Try finding sound-a-like words.
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4019 */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4020 if ((sps_flags & SPS_FAST) == 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4021 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4022 if (sps_flags & SPS_BEST)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4023 /* Adjust the word score for the suggestions found so far for how
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4024 * they sounds like. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4025 rescore_suggestions(su);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4026
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4027 /*
2046
d433f43849ba updated for version 7.2.332
Bram Moolenaar <bram@zimbu.org>
parents: 1938
diff changeset
4028 * While going through the soundfold tree "su_maxscore" is the score
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4029 * for the soundfold word, limits the changes that are being tried,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4030 * and "su_sfmaxscore" the rescored score, which is set by
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4031 * cleanup_suggestions().
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4032 * First find words with a small edit distance, because this is much
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4033 * faster and often already finds the top-N suggestions. If we didn't
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4034 * find many suggestions try again with a higher edit distance.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4035 * "sl_sounddone" is used to avoid doing the same word twice.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4036 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4037 suggest_try_soundalike_prep();
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4038 su->su_maxscore = SCORE_SFMAX1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4039 su->su_sfmaxscore = SCORE_MAXINIT * 3;
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4040 suggest_try_soundalike(su);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4041 if (su->su_ga.ga_len < SUG_CLEAN_COUNT(su))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4042 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4043 /* We didn't find enough matches, try again, allowing more
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4044 * changes to the soundfold word. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4045 su->su_maxscore = SCORE_SFMAX2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4046 suggest_try_soundalike(su);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4047 if (su->su_ga.ga_len < SUG_CLEAN_COUNT(su))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4048 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4049 /* Still didn't find enough matches, try again, allowing even
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4050 * more changes to the soundfold word. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4051 su->su_maxscore = SCORE_SFMAX3;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4052 suggest_try_soundalike(su);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4053 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4054 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4055 su->su_maxscore = su->su_sfmaxscore;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4056 suggest_try_soundalike_finish();
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4057 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4058
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4059 /* When CTRL-C was hit while searching do show the results. Only clear
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4060 * got_int when using a command, not for spellsuggest(). */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4061 ui_breakcheck();
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4062 if (interactive && got_int)
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4063 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4064 (void)vgetc();
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4065 got_int = FALSE;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4066 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4067
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
4068 if ((sps_flags & SPS_DOUBLE) == 0 && su->su_ga.ga_len != 0)
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4069 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4070 if (sps_flags & SPS_BEST)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4071 /* Adjust the word score for how it sounds like. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4072 rescore_suggestions(su);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4073
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4074 /* Remove bogus suggestions, sort and truncate at "maxcount". */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4075 check_suggestions(su, &su->su_ga);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
4076 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, su->su_maxcount);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4077 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4078 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4079
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4080 /*
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4081 * Free the info put in "*su" by spell_find_suggest().
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4082 */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4083 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
4084 spell_find_cleanup(suginfo_T *su)
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4085 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4086 int i;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4087
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4088 /* Free the suggestions. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4089 for (i = 0; i < su->su_ga.ga_len; ++i)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4090 vim_free(SUG(su->su_ga, i).st_word);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4091 ga_clear(&su->su_ga);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4092 for (i = 0; i < su->su_sga.ga_len; ++i)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4093 vim_free(SUG(su->su_sga, i).st_word);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
4094 ga_clear(&su->su_sga);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4095
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4096 /* Free the banned words. */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4097 hash_clear_all(&su->su_banned, 0);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4098 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4099
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4100 /*
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4101 * Make a copy of "word", with the first letter upper or lower cased, to
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4102 * "wcopy[MAXWLEN]". "word" must not be empty.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4103 * The result is NUL terminated.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4104 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
4105 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
4106 onecap_copy(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
4107 char_u *word,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
4108 char_u *wcopy,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
4109 int upper) /* TRUE: first letter made upper case */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4110 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4111 char_u *p;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4112 int c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4113 int l;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4114
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4115 p = word;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4116 #ifdef FEAT_MBYTE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4117 if (has_mbyte)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
4118 c = mb_cptr2char_adv(&p);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4119 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4120 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4121 c = *p++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4122 if (upper)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4123 c = SPELL_TOUPPER(c);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4124 else
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4125 c = SPELL_TOFOLD(c);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4126 #ifdef FEAT_MBYTE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4127 if (has_mbyte)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4128 l = mb_char2bytes(c, wcopy);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4129 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4130 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4131 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4132 l = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4133 wcopy[0] = c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4134 }
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4135 vim_strncpy(wcopy + l, p, MAXWLEN - l - 1);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4136 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4137
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4138 /*
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4139 * Make a copy of "word" with all the letters upper cased into
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4140 * "wcopy[MAXWLEN]". The result is NUL terminated.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4141 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4142 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
4143 allcap_copy(char_u *word, char_u *wcopy)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4144 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4145 char_u *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4146 char_u *d;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4147 int c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4148
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4149 d = wcopy;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4150 for (s = word; *s != NUL; )
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4151 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4152 #ifdef FEAT_MBYTE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4153 if (has_mbyte)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
4154 c = mb_cptr2char_adv(&s);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4155 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4156 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4157 c = *s++;
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4158
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4159 #ifdef FEAT_MBYTE
3042
6cd0d6413a2e updated for version 7.3.293
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
4160 /* We only change 0xdf to SS when we are certain latin1 is used. It
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4161 * would cause weird errors in other 8-bit encodings. */
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4162 if (enc_latin1like && c == 0xdf)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4163 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4164 c = 'S';
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4165 if (d - wcopy >= MAXWLEN - 1)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4166 break;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4167 *d++ = c;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4168 }
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4169 else
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4170 #endif
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4171 c = SPELL_TOUPPER(c);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4172
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4173 #ifdef FEAT_MBYTE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4174 if (has_mbyte)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4175 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4176 if (d - wcopy >= MAXWLEN - MB_MAXBYTES)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4177 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4178 d += mb_char2bytes(c, d);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4179 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4180 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4181 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4182 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4183 if (d - wcopy >= MAXWLEN - 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4184 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4185 *d++ = c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4186 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4187 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4188 *d = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4189 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4190
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4191 /*
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4192 * Try finding suggestions by recognizing specific situations.
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4193 */
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4194 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
4195 suggest_try_special(suginfo_T *su)
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4196 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4197 char_u *p;
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4198 size_t len;
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4199 int c;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4200 char_u word[MAXWLEN];
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4201
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4202 /*
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4203 * Recognize a word that is repeated: "the the".
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4204 */
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4205 p = skiptowhite(su->su_fbadword);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4206 len = p - su->su_fbadword;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4207 p = skipwhite(p);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4208 if (STRLEN(p) == len && STRNCMP(su->su_fbadword, p, len) == 0)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4209 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4210 /* Include badflags: if the badword is onecap or allcap
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4211 * use that for the goodword too: "The the" -> "The". */
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4212 c = su->su_fbadword[len];
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4213 su->su_fbadword[len] = NUL;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4214 make_case_word(su->su_fbadword, word, su->su_badflags);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4215 su->su_fbadword[len] = c;
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
4216
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
4217 /* Give a soundalike score of 0, compute the score as if deleting one
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
4218 * character. */
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
4219 add_suggestion(su, &su->su_ga, word, su->su_badlen,
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4220 RESCORE(SCORE_REP, 0), 0, TRUE, su->su_sallang, FALSE);
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4221 }
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4222 }
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4223
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4224 /*
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4225 * Change the 0 to 1 to measure how much time is spent in each state.
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4226 * Output is dumped in "suggestprof".
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4227 */
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4228 #if 0
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4229 # define SUGGEST_PROFILE
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4230 proftime_T current;
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4231 proftime_T total;
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4232 proftime_T times[STATE_FINAL + 1];
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4233 long counts[STATE_FINAL + 1];
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4234
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4235 static void
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4236 prof_init(void)
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4237 {
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4238 for (int i = 0; i <= STATE_FINAL; ++i)
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4239 {
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4240 profile_zero(&times[i]);
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4241 counts[i] = 0;
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4242 }
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4243 profile_start(&current);
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4244 profile_start(&total);
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4245 }
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4246
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4247 /* call before changing state */
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4248 static void
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4249 prof_store(state_T state)
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4250 {
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4251 profile_end(&current);
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4252 profile_add(&times[state], &current);
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4253 ++counts[state];
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4254 profile_start(&current);
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4255 }
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4256 # define PROF_STORE(state) prof_store(state);
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4257
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4258 static void
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4259 prof_report(char *name)
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4260 {
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4261 FILE *fd = fopen("suggestprof", "a");
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4262
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4263 profile_end(&total);
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4264 fprintf(fd, "-----------------------\n");
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4265 fprintf(fd, "%s: %s\n", name, profile_msg(&total));
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4266 for (int i = 0; i <= STATE_FINAL; ++i)
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4267 fprintf(fd, "%d: %s (%ld)\n", i, profile_msg(&times[i]), counts[i]);
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4268 fclose(fd);
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4269 }
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4270 #else
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4271 # define PROF_STORE(state)
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4272 #endif
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4273
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4274 /*
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4275 * Try finding suggestions by adding/removing/swapping letters.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4276 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4277 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
4278 suggest_try_change(suginfo_T *su)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4279 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4280 char_u fword[MAXWLEN]; /* copy of the bad word, case-folded */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4281 int n;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4282 char_u *p;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4283 int lpi;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4284 langp_T *lp;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4285
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4286 /* We make a copy of the case-folded bad word, so that we can modify it
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4287 * to find matches (esp. REP items). Append some more text, changing
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4288 * chars after the bad word may help. */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4289 STRCPY(fword, su->su_fbadword);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
4290 n = (int)STRLEN(fword);
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4291 p = su->su_badptr + su->su_badlen;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
4292 (void)spell_casefold(p, (int)STRLEN(p), fword + n, MAXWLEN - n);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4293
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
4294 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
4295 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
4296 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4297
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
4298 /* If reloading a spell file fails it's still in the list but
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
4299 * everything has been cleared. */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4300 if (lp->lp_slang->sl_fbyts == NULL)
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
4301 continue;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
4302
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4303 /* Try it for this language. Will add possible suggestions. */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4304 #ifdef SUGGEST_PROFILE
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4305 prof_init();
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4306 #endif
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4307 suggest_trie_walk(su, lp, fword, FALSE);
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4308 #ifdef SUGGEST_PROFILE
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4309 prof_report("try_change");
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4310 #endif
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4311 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4312 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4313
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4314 /* Check the maximum score, if we go over it we won't try this change. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4315 #define TRY_DEEPER(su, stack, depth, add) \
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4316 (stack[depth].ts_score + (add) < su->su_maxscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4317
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4318 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4319 * Try finding suggestions by adding/removing/swapping letters.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4320 *
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4321 * This uses a state machine. At each node in the tree we try various
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4322 * operations. When trying if an operation works "depth" is increased and the
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4323 * stack[] is used to store info. This allows combinations, thus insert one
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4324 * character, replace one and delete another. The number of changes is
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4325 * limited by su->su_maxscore.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4326 *
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4327 * After implementing this I noticed an article by Kemal Oflazer that
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4328 * describes something similar: "Error-tolerant Finite State Recognition with
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4329 * Applications to Morphological Analysis and Spelling Correction" (1996).
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4330 * The implementation in the article is simplified and requires a stack of
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4331 * unknown depth. The implementation here only needs a stack depth equal to
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4332 * the length of the word.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4333 *
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4334 * This is also used for the sound-folded word, "soundfold" is TRUE then.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4335 * The mechanism is the same, but we find a match with a sound-folded word
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4336 * that comes from one or more original words. Each of these words may be
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4337 * added, this is done by add_sound_suggest().
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4338 * Don't use:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4339 * the prefix tree or the keep-case tree
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4340 * "su->su_badlen"
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4341 * anything to do with upper and lower case
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4342 * anything to do with word or non-word characters ("spell_iswordp()")
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4343 * banned words
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4344 * word flags (rare, region, compounding)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4345 * word splitting for now
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4346 * "similar_chars()"
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4347 * use "slang->sl_repsal" instead of "lp->lp_replang->sl_rep"
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4348 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4349 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
4350 suggest_trie_walk(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
4351 suginfo_T *su,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
4352 langp_T *lp,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
4353 char_u *fword,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
4354 int soundfold)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4355 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4356 char_u tword[MAXWLEN]; /* good word collected so far */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4357 trystate_T stack[MAXWLEN];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4358 char_u preword[MAXWLEN * 3]; /* word found with proper case;
2046
d433f43849ba updated for version 7.2.332
Bram Moolenaar <bram@zimbu.org>
parents: 1938
diff changeset
4359 * concatenation of prefix compound
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4360 * words and split word. NUL terminated
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4361 * when going deeper but not when coming
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4362 * back. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4363 char_u compflags[MAXWLEN]; /* compound flags, one for each word */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4364 trystate_T *sp;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4365 int newscore;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4366 int score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4367 char_u *byts, *fbyts, *pbyts;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4368 idx_T *idxs, *fidxs, *pidxs;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4369 int depth;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4370 int c, c2, c3;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4371 int n = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4372 int flags;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4373 garray_T *gap;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4374 idx_T arridx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4375 int len;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4376 char_u *p;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4377 fromto_T *ftp;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4378 int fl = 0, tl;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4379 int repextra = 0; /* extra bytes in fword[] from REP item */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4380 slang_T *slang = lp->lp_slang;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4381 int fword_ends;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4382 int goodword_ends;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4383 #ifdef DEBUG_TRIEWALK
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4384 /* Stores the name of the change made at each level. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4385 char_u changename[MAXWLEN][80];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4386 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4387 int breakcheckcount = 1000;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4388 int compound_ok;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4389
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4390 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4391 * Go through the whole case-fold tree, try changes at each node.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4392 * "tword[]" contains the word collected from nodes in the tree.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4393 * "fword[]" the word we are trying to match with (initially the bad
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4394 * word).
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4395 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4396 depth = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4397 sp = &stack[0];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4398 vim_memset(sp, 0, sizeof(trystate_T));
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4399 sp->ts_curi = 1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4400
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4401 if (soundfold)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4402 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4403 /* Going through the soundfold tree. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4404 byts = fbyts = slang->sl_sbyts;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4405 idxs = fidxs = slang->sl_sidxs;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4406 pbyts = NULL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4407 pidxs = NULL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4408 sp->ts_prefixdepth = PFD_NOPREFIX;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4409 sp->ts_state = STATE_START;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4410 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4411 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4412 {
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4413 /*
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
4414 * When there are postponed prefixes we need to use these first. At
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
4415 * the end of the prefix we continue in the case-fold tree.
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
4416 */
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4417 fbyts = slang->sl_fbyts;
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4418 fidxs = slang->sl_fidxs;
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4419 pbyts = slang->sl_pbyts;
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4420 pidxs = slang->sl_pidxs;
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
4421 if (pbyts != NULL)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
4422 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
4423 byts = pbyts;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
4424 idxs = pidxs;
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4425 sp->ts_prefixdepth = PFD_PREFIXTREE;
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
4426 sp->ts_state = STATE_NOPREFIX; /* try without prefix first */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
4427 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
4428 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
4429 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
4430 byts = fbyts;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
4431 idxs = fidxs;
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4432 sp->ts_prefixdepth = PFD_NOPREFIX;
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4433 sp->ts_state = STATE_START;
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
4434 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4435 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4436
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4437 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4438 * Loop to find all suggestions. At each round we either:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4439 * - For the current state try one operation, advance "ts_curi",
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4440 * increase "depth".
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4441 * - When a state is done go to the next, set "ts_state".
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4442 * - When all states are tried decrease "depth".
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4443 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4444 while (depth >= 0 && !got_int)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4445 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4446 sp = &stack[depth];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4447 switch (sp->ts_state)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4448 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4449 case STATE_START:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4450 case STATE_NOPREFIX:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4451 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4452 * Start of node: Deal with NUL bytes, which means
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4453 * tword[] may end here.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4454 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4455 arridx = sp->ts_arridx; /* current node in the tree */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4456 len = byts[arridx]; /* bytes in this node */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4457 arridx += sp->ts_curi; /* index of current byte */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4458
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4459 if (sp->ts_prefixdepth == PFD_PREFIXTREE)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4460 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4461 /* Skip over the NUL bytes, we use them later. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4462 for (n = 0; n < len && byts[arridx + n] == 0; ++n)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4463 ;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4464 sp->ts_curi += n;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4465
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4466 /* Always past NUL bytes now. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4467 n = (int)sp->ts_state;
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4468 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4469 sp->ts_state = STATE_ENDNUL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4470 sp->ts_save_badflags = su->su_badflags;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4471
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4472 /* At end of a prefix or at start of prefixtree: check for
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4473 * following word. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4474 if (byts[arridx] == 0 || n == (int)STATE_NOPREFIX)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4475 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4476 /* Set su->su_badflags to the caps type at this position.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4477 * Use the caps type until here for the prefix itself. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4478 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4479 if (has_mbyte)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4480 n = nofold_len(fword, sp->ts_fidx, su->su_badptr);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4481 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4482 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4483 n = sp->ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4484 flags = badword_captype(su->su_badptr, su->su_badptr + n);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4485 su->su_badflags = badword_captype(su->su_badptr + n,
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4486 su->su_badptr + su->su_badlen);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4487 #ifdef DEBUG_TRIEWALK
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4488 sprintf(changename[depth], "prefix");
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4489 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4490 go_deeper(stack, depth, 0);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4491 ++depth;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4492 sp = &stack[depth];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4493 sp->ts_prefixdepth = depth - 1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4494 byts = fbyts;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4495 idxs = fidxs;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4496 sp->ts_arridx = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4497
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4498 /* Move the prefix to preword[] with the right case
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4499 * and make find_keepcap_word() works. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4500 tword[sp->ts_twordlen] = NUL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4501 make_case_word(tword + sp->ts_splitoff,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4502 preword + sp->ts_prewordlen, flags);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
4503 sp->ts_prewordlen = (char_u)STRLEN(preword);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4504 sp->ts_splitoff = sp->ts_twordlen;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4505 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4506 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4507 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4508
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4509 if (sp->ts_curi > len || byts[arridx] != 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4510 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4511 /* Past bytes in node and/or past NUL bytes. */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4512 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4513 sp->ts_state = STATE_ENDNUL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4514 sp->ts_save_badflags = su->su_badflags;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4515 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4516 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4517
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4518 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4519 * End of word in tree.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4520 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4521 ++sp->ts_curi; /* eat one NUL byte */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4522
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4523 flags = (int)idxs[arridx];
698
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
4524
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
4525 /* Skip words with the NOSUGGEST flag. */
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
4526 if (flags & WF_NOSUGGEST)
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
4527 break;
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
4528
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4529 fword_ends = (fword[sp->ts_fidx] == NUL
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4530 || (soundfold
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4531 ? vim_iswhite(fword[sp->ts_fidx])
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
4532 : !spell_iswordp(fword + sp->ts_fidx, curwin)));
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4533 tword[sp->ts_twordlen] = NUL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4534
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4535 if (sp->ts_prefixdepth <= PFD_NOTSPECIAL
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4536 && (sp->ts_flags & TSF_PREFIXOK) == 0)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4537 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4538 /* There was a prefix before the word. Check that the prefix
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4539 * can be used with this word. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4540 /* Count the length of the NULs in the prefix. If there are
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4541 * none this must be the first try without a prefix. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4542 n = stack[sp->ts_prefixdepth].ts_arridx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4543 len = pbyts[n++];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4544 for (c = 0; c < len && pbyts[n + c] == 0; ++c)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4545 ;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4546 if (c > 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4547 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4548 c = valid_word_prefix(c, n, flags,
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
4549 tword + sp->ts_splitoff, slang, FALSE);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4550 if (c == 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4551 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4552
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4553 /* Use the WF_RARE flag for a rare prefix. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4554 if (c & WF_RAREPFX)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4555 flags |= WF_RARE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4556
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4557 /* Tricky: when checking for both prefix and compounding
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4558 * we run into the prefix flag first.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4559 * Remember that it's OK, so that we accept the prefix
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4560 * when arriving at a compound flag. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4561 sp->ts_flags |= TSF_PREFIXOK;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4562 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4563 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4564
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4565 /* Check NEEDCOMPOUND: can't use word without compounding. Do try
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4566 * appending another compound word below. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4567 if (sp->ts_complen == sp->ts_compsplit && fword_ends
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
4568 && (flags & WF_NEEDCOMP))
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4569 goodword_ends = FALSE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4570 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4571 goodword_ends = TRUE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4572
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4573 p = NULL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4574 compound_ok = TRUE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4575 if (sp->ts_complen > sp->ts_compsplit)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4576 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4577 if (slang->sl_nobreak)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4578 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4579 /* There was a word before this word. When there was no
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4580 * change in this word (it was correct) add the first word
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4581 * as a suggestion. If this word was corrected too, we
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4582 * need to check if a correct word follows. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4583 if (sp->ts_fidx - sp->ts_splitfidx
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4584 == sp->ts_twordlen - sp->ts_splitoff
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4585 && STRNCMP(fword + sp->ts_splitfidx,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4586 tword + sp->ts_splitoff,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4587 sp->ts_fidx - sp->ts_splitfidx) == 0)
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4588 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4589 preword[sp->ts_prewordlen] = NUL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4590 newscore = score_wordcount_adj(slang, sp->ts_score,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4591 preword + sp->ts_prewordlen,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4592 sp->ts_prewordlen > 0);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4593 /* Add the suggestion if the score isn't too bad. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4594 if (newscore <= su->su_maxscore)
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4595 add_suggestion(su, &su->su_ga, preword,
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
4596 sp->ts_splitfidx - repextra,
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4597 newscore, 0, FALSE,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4598 lp->lp_sallang, FALSE);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4599 break;
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4600 }
490
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
4601 }
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
4602 else
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4603 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4604 /* There was a compound word before this word. If this
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4605 * word does not support compounding then give up
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4606 * (splitting is tried for the word without compound
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4607 * flag). */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4608 if (((unsigned)flags >> 24) == 0
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4609 || sp->ts_twordlen - sp->ts_splitoff
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4610 < slang->sl_compminlen)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4611 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4612 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4613 /* For multi-byte chars check character length against
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4614 * COMPOUNDMIN. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4615 if (has_mbyte
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4616 && slang->sl_compminlen > 0
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4617 && mb_charlen(tword + sp->ts_splitoff)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4618 < slang->sl_compminlen)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4619 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4620 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4621
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4622 compflags[sp->ts_complen] = ((unsigned)flags >> 24);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4623 compflags[sp->ts_complen + 1] = NUL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4624 vim_strncpy(preword + sp->ts_prewordlen,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4625 tword + sp->ts_splitoff,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4626 sp->ts_twordlen - sp->ts_splitoff);
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4627
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4628 /* Verify CHECKCOMPOUNDPATTERN rules. */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4629 if (match_checkcompoundpattern(preword, sp->ts_prewordlen,
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4630 &slang->sl_comppat))
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4631 compound_ok = FALSE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4632
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4633 if (compound_ok)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4634 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4635 p = preword;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4636 while (*skiptowhite(p) != NUL)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4637 p = skipwhite(skiptowhite(p));
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4638 if (fword_ends && !can_compound(slang, p,
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4639 compflags + sp->ts_compsplit))
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4640 /* Compound is not allowed. But it may still be
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4641 * possible if we add another (short) word. */
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4642 compound_ok = FALSE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4643 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4644
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4645 /* Get pointer to last char of previous word. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4646 p = preword + sp->ts_prewordlen;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4647 mb_ptr_back(preword, p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4648 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4649 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4650
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4651 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4652 * Form the word with proper case in preword.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4653 * If there is a word from a previous split, append.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4654 * For the soundfold tree don't change the case, simply append.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4655 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4656 if (soundfold)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4657 STRCPY(preword + sp->ts_prewordlen, tword + sp->ts_splitoff);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4658 else if (flags & WF_KEEPCAP)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4659 /* Must find the word in the keep-case tree. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4660 find_keepcap_word(slang, tword + sp->ts_splitoff,
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
4661 preword + sp->ts_prewordlen);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4662 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4663 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4664 /* Include badflags: If the badword is onecap or allcap
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4665 * use that for the goodword too. But if the badword is
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4666 * allcap and it's only one char long use onecap. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4667 c = su->su_badflags;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4668 if ((c & WF_ALLCAP)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4669 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4670 && su->su_badlen == (*mb_ptr2len)(su->su_badptr)
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4671 #else
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4672 && su->su_badlen == 1
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4673 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4674 )
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4675 c = WF_ONECAP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4676 c |= flags;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4677
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4678 /* When appending a compound word after a word character don't
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4679 * use Onecap. */
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
4680 if (p != NULL && spell_iswordp_nmw(p, curwin))
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4681 c &= ~WF_ONECAP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4682 make_case_word(tword + sp->ts_splitoff,
490
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
4683 preword + sp->ts_prewordlen, c);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4684 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4685
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4686 if (!soundfold)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4687 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4688 /* Don't use a banned word. It may appear again as a good
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4689 * word, thus remember it. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4690 if (flags & WF_BANNED)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4691 {
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
4692 add_banned(su, preword + sp->ts_prewordlen);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4693 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4694 }
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
4695 if ((sp->ts_complen == sp->ts_compsplit
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4696 && WAS_BANNED(su, preword + sp->ts_prewordlen))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4697 || WAS_BANNED(su, preword))
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
4698 {
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
4699 if (slang->sl_compprog == NULL)
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
4700 break;
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
4701 /* the word so far was banned but we may try compounding */
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
4702 goodword_ends = FALSE;
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
4703 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4704 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4705
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4706 newscore = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4707 if (!soundfold) /* soundfold words don't have flags */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4708 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4709 if ((flags & WF_REGION)
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
4710 && (((unsigned)flags >> 16) & lp->lp_region) == 0)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4711 newscore += SCORE_REGION;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4712 if (flags & WF_RARE)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4713 newscore += SCORE_RARE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4714
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4715 if (!spell_valid_case(su->su_badflags,
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
4716 captype(preword + sp->ts_prewordlen, NULL)))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4717 newscore += SCORE_ICASE;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4718 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4719
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4720 /* TODO: how about splitting in the soundfold tree? */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4721 if (fword_ends
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4722 && goodword_ends
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4723 && sp->ts_fidx >= sp->ts_fidxtry
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4724 && compound_ok)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4725 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4726 /* The badword also ends: add suggestions. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4727 #ifdef DEBUG_TRIEWALK
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4728 if (soundfold && STRCMP(preword, "smwrd") == 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4729 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4730 int j;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4731
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4732 /* print the stack of changes that brought us here */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4733 smsg("------ %s -------", fword);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4734 for (j = 0; j < depth; ++j)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4735 smsg("%s", changename[j]);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4736 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4737 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4738 if (soundfold)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4739 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4740 /* For soundfolded words we need to find the original
1188
2a276274c592 updated for version 7.1b
vimboss
parents: 1185
diff changeset
4741 * words, the edit distance and then add them. */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4742 add_sound_suggest(su, preword, sp->ts_score, lp);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4743 }
2457
6c1d10a85398 Avoid illegal memory access in spell suggestion. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents: 2455
diff changeset
4744 else if (sp->ts_fidx > 0)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4745 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4746 /* Give a penalty when changing non-word char to word
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4747 * char, e.g., "thes," -> "these". */
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
4748 p = fword + sp->ts_fidx;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4749 mb_ptr_back(fword, p);
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
4750 if (!spell_iswordp(p, curwin))
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
4751 {
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
4752 p = preword + STRLEN(preword);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4753 mb_ptr_back(preword, p);
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
4754 if (spell_iswordp(p, curwin))
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
4755 newscore += SCORE_NONWORD;
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
4756 }
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
4757
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4758 /* Give a bonus to words seen before. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4759 score = score_wordcount_adj(slang,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4760 sp->ts_score + newscore,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4761 preword + sp->ts_prewordlen,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4762 sp->ts_prewordlen > 0);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4763
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4764 /* Add the suggestion if the score isn't too bad. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4765 if (score <= su->su_maxscore)
633
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4766 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4767 add_suggestion(su, &su->su_ga, preword,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4768 sp->ts_fidx - repextra,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4769 score, 0, FALSE, lp->lp_sallang, FALSE);
633
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4770
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4771 if (su->su_badflags & WF_MIXCAP)
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4772 {
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4773 /* We really don't know if the word should be
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4774 * upper or lower case, add both. */
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4775 c = captype(preword, NULL);
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4776 if (c == 0 || c == WF_ALLCAP)
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4777 {
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4778 make_case_word(tword + sp->ts_splitoff,
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4779 preword + sp->ts_prewordlen,
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4780 c == 0 ? WF_ALLCAP : 0);
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4781
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4782 add_suggestion(su, &su->su_ga, preword,
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4783 sp->ts_fidx - repextra,
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4784 score + SCORE_ICASE, 0, FALSE,
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4785 lp->lp_sallang, FALSE);
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4786 }
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4787 }
7437be625546 updated for version 7.0183
vimboss
parents: 627
diff changeset
4788 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4789 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4790 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4791
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4792 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4793 * Try word split and/or compounding.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4794 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4795 if ((sp->ts_fidx >= sp->ts_fidxtry || fword_ends)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4796 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4797 /* Don't split halfway a character. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4798 && (!has_mbyte || sp->ts_tcharlen == 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4799 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4800 )
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4801 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4802 int try_compound;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4803 int try_split;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4804
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4805 /* If past the end of the bad word don't try a split.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4806 * Otherwise try changing the next word. E.g., find
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4807 * suggestions for "the the" where the second "the" is
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4808 * different. It's done like a split.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4809 * TODO: word split for soundfold words */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4810 try_split = (sp->ts_fidx - repextra < su->su_badlen)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4811 && !soundfold;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4812
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4813 /* Get here in several situations:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4814 * 1. The word in the tree ends:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4815 * If the word allows compounding try that. Otherwise try
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4816 * a split by inserting a space. For both check that a
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4817 * valid words starts at fword[sp->ts_fidx].
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4818 * For NOBREAK do like compounding to be able to check if
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4819 * the next word is valid.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4820 * 2. The badword does end, but it was due to a change (e.g.,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4821 * a swap). No need to split, but do check that the
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4822 * following word is valid.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4823 * 3. The badword and the word in the tree end. It may still
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4824 * be possible to compound another (short) word.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4825 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4826 try_compound = FALSE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4827 if (!soundfold
7526
08c1f73efcde commit https://github.com/vim/vim/commit/7b877b360532713dc21a0ff3d55a76ac02eaf573
Christian Brabandt <cb@256bit.org>
parents: 7509
diff changeset
4828 && !slang->sl_nocompoundsugs
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4829 && slang->sl_compprog != NULL
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4830 && ((unsigned)flags >> 24) != 0
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4831 && sp->ts_twordlen - sp->ts_splitoff
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4832 >= slang->sl_compminlen
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4833 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4834 && (!has_mbyte
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4835 || slang->sl_compminlen == 0
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4836 || mb_charlen(tword + sp->ts_splitoff)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4837 >= slang->sl_compminlen)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4838 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4839 && (slang->sl_compsylmax < MAXWLEN
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4840 || sp->ts_complen + 1 - sp->ts_compsplit
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4841 < slang->sl_compmax)
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4842 && (can_be_compound(sp, slang,
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4843 compflags, ((unsigned)flags >> 24))))
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
4844
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4845 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4846 try_compound = TRUE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4847 compflags[sp->ts_complen] = ((unsigned)flags >> 24);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4848 compflags[sp->ts_complen + 1] = NUL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4849 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4850
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4851 /* For NOBREAK we never try splitting, it won't make any word
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4852 * valid. */
7526
08c1f73efcde commit https://github.com/vim/vim/commit/7b877b360532713dc21a0ff3d55a76ac02eaf573
Christian Brabandt <cb@256bit.org>
parents: 7509
diff changeset
4853 if (slang->sl_nobreak && !slang->sl_nocompoundsugs)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4854 try_compound = TRUE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4855
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4856 /* If we could add a compound word, and it's also possible to
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4857 * split at this point, do the split first and set
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4858 * TSF_DIDSPLIT to avoid doing it again. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4859 else if (!fword_ends
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4860 && try_compound
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4861 && (sp->ts_flags & TSF_DIDSPLIT) == 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4862 {
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4863 try_compound = FALSE;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4864 sp->ts_flags |= TSF_DIDSPLIT;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4865 --sp->ts_curi; /* do the same NUL again */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4866 compflags[sp->ts_complen] = NUL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4867 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4868 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4869 sp->ts_flags &= ~TSF_DIDSPLIT;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4870
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4871 if (try_split || try_compound)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4872 {
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
4873 if (!try_compound && (!fword_ends || !goodword_ends))
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4874 {
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4875 /* If we're going to split need to check that the
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
4876 * words so far are valid for compounding. If there
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
4877 * is only one word it must not have the NEEDCOMPOUND
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
4878 * flag. */
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
4879 if (sp->ts_complen == sp->ts_compsplit
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
4880 && (flags & WF_NEEDCOMP))
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
4881 break;
490
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
4882 p = preword;
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
4883 while (*skiptowhite(p) != NUL)
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
4884 p = skipwhite(skiptowhite(p));
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4885 if (sp->ts_complen > sp->ts_compsplit
490
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
4886 && !can_compound(slang, p,
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4887 compflags + sp->ts_compsplit))
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4888 break;
698
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
4889
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
4890 if (slang->sl_nosplitsugs)
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
4891 newscore += SCORE_SPLIT_NO;
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
4892 else
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
4893 newscore += SCORE_SPLIT;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4894
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4895 /* Give a bonus to words seen before. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4896 newscore = score_wordcount_adj(slang, newscore,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4897 preword + sp->ts_prewordlen, TRUE);
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4898 }
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4899
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4900 if (TRY_DEEPER(su, stack, depth, newscore))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4901 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4902 go_deeper(stack, depth, newscore);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4903 #ifdef DEBUG_TRIEWALK
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4904 if (!try_compound && !fword_ends)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4905 sprintf(changename[depth], "%.*s-%s: split",
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4906 sp->ts_twordlen, tword, fword + sp->ts_fidx);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4907 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4908 sprintf(changename[depth], "%.*s-%s: compound",
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4909 sp->ts_twordlen, tword, fword + sp->ts_fidx);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4910 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4911 /* Save things to be restored at STATE_SPLITUNDO. */
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
4912 sp->ts_save_badflags = su->su_badflags;
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4913 PROF_STORE(sp->ts_state)
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4914 sp->ts_state = STATE_SPLITUNDO;
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4915
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4916 ++depth;
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4917 sp = &stack[depth];
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4918
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4919 /* Append a space to preword when splitting. */
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4920 if (!try_compound && !fword_ends)
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4921 STRCAT(preword, " ");
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
4922 sp->ts_prewordlen = (char_u)STRLEN(preword);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
4923 sp->ts_splitoff = sp->ts_twordlen;
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
4924 sp->ts_splitfidx = sp->ts_fidx;
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4925
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4926 /* If the badword has a non-word character at this
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4927 * position skip it. That means replacing the
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4928 * non-word character with a space. Always skip a
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
4929 * character when the word ends. But only when the
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
4930 * good word can end. */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4931 if (((!try_compound && !spell_iswordp_nmw(fword
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
4932 + sp->ts_fidx,
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
4933 curwin))
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4934 || fword_ends)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4935 && fword[sp->ts_fidx] != NUL
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4936 && goodword_ends)
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4937 {
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4938 int l;
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4939
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4940 #ifdef FEAT_MBYTE
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4941 if (has_mbyte)
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4942 l = MB_BYTE2LEN(fword[sp->ts_fidx]);
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4943 else
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4944 #endif
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4945 l = 1;
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4946 if (fword_ends)
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4947 {
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4948 /* Copy the skipped character to preword. */
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
4949 mch_memmove(preword + sp->ts_prewordlen,
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4950 fword + sp->ts_fidx, l);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
4951 sp->ts_prewordlen += l;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
4952 preword[sp->ts_prewordlen] = NUL;
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4953 }
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4954 else
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4955 sp->ts_score -= SCORE_SPLIT - SCORE_SUBST;
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4956 sp->ts_fidx += l;
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4957 }
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4958
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4959 /* When compounding include compound flag in
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4960 * compflags[] (already set above). When splitting we
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4961 * may start compounding over again. */
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4962 if (try_compound)
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
4963 ++sp->ts_complen;
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4964 else
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4965 sp->ts_compsplit = sp->ts_complen;
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4966 sp->ts_prefixdepth = PFD_NOPREFIX;
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
4967
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4968 /* set su->su_badflags to the caps type at this
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4969 * position */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4970 #ifdef FEAT_MBYTE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4971 if (has_mbyte)
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4972 n = nofold_len(fword, sp->ts_fidx, su->su_badptr);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4973 else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4974 #endif
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4975 n = sp->ts_fidx;
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
4976 su->su_badflags = badword_captype(su->su_badptr + n,
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4977 su->su_badptr + su->su_badlen);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4978
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4979 /* Restart at top of the tree. */
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4980 sp->ts_arridx = 0;
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4981
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4982 /* If there are postponed prefixes, try these too. */
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4983 if (pbyts != NULL)
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4984 {
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4985 byts = pbyts;
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4986 idxs = pidxs;
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4987 sp->ts_prefixdepth = PFD_PREFIXTREE;
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
4988 PROF_STORE(sp->ts_state)
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4989 sp->ts_state = STATE_NOPREFIX;
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
4990 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4991 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4992 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4993 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4994 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4995
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4996 case STATE_SPLITUNDO:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4997 /* Undo the changes done for word split or compound word. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4998 su->su_badflags = sp->ts_save_badflags;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4999
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5000 /* Continue looking for NUL bytes. */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5001 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5002 sp->ts_state = STATE_START;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5003
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5004 /* In case we went into the prefix tree. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5005 byts = fbyts;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5006 idxs = fidxs;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5007 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5008
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5009 case STATE_ENDNUL:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5010 /* Past the NUL bytes in the node. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5011 su->su_badflags = sp->ts_save_badflags;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5012 if (fword[sp->ts_fidx] == NUL
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5013 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5014 && sp->ts_tcharlen == 0
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5015 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5016 )
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5017 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5018 /* The badword ends, can't use STATE_PLAIN. */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5019 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5020 sp->ts_state = STATE_DEL;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5021 break;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5022 }
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5023 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5024 sp->ts_state = STATE_PLAIN;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5025 /*FALLTHROUGH*/
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5026
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5027 case STATE_PLAIN:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5028 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5029 * Go over all possible bytes at this node, add each to tword[]
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5030 * and use child node. "ts_curi" is the index.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5031 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5032 arridx = sp->ts_arridx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5033 if (sp->ts_curi > byts[arridx])
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5034 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5035 /* Done all bytes at this node, do next state. When still at
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5036 * already changed bytes skip the other tricks. */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5037 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5038 if (sp->ts_fidx >= sp->ts_fidxtry)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5039 sp->ts_state = STATE_DEL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5040 else
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5041 sp->ts_state = STATE_FINAL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5042 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5043 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5044 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5045 arridx += sp->ts_curi++;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5046 c = byts[arridx];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5047
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5048 /* Normal byte, go one level deeper. If it's not equal to the
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5049 * byte in the bad word adjust the score. But don't even try
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5050 * when the byte was already changed. And don't try when we
5695
a8650e2a0b5a updated for version 7.4.193
Bram Moolenaar <bram@vim.org>
parents: 5684
diff changeset
5051 * just deleted this byte, accepting it is always cheaper than
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5052 * delete + substitute. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5053 if (c == fword[sp->ts_fidx]
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5054 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5055 || (sp->ts_tcharlen > 0 && sp->ts_isdiff != DIFF_NONE)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5056 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5057 )
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5058 newscore = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5059 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5060 newscore = SCORE_SUBST;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5061 if ((newscore == 0
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5062 || (sp->ts_fidx >= sp->ts_fidxtry
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5063 && ((sp->ts_flags & TSF_DIDDEL) == 0
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5064 || c != fword[sp->ts_delidx])))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5065 && TRY_DEEPER(su, stack, depth, newscore))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5066 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5067 go_deeper(stack, depth, newscore);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5068 #ifdef DEBUG_TRIEWALK
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5069 if (newscore > 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5070 sprintf(changename[depth], "%.*s-%s: subst %c to %c",
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5071 sp->ts_twordlen, tword, fword + sp->ts_fidx,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5072 fword[sp->ts_fidx], c);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5073 else
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5074 sprintf(changename[depth], "%.*s-%s: accept %c",
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5075 sp->ts_twordlen, tword, fword + sp->ts_fidx,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5076 fword[sp->ts_fidx]);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5077 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5078 ++depth;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5079 sp = &stack[depth];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5080 ++sp->ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5081 tword[sp->ts_twordlen++] = c;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5082 sp->ts_arridx = idxs[arridx];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5083 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5084 if (newscore == SCORE_SUBST)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5085 sp->ts_isdiff = DIFF_YES;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5086 if (has_mbyte)
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
5087 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5088 /* Multi-byte characters are a bit complicated to
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5089 * handle: They differ when any of the bytes differ
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5090 * and then their length may also differ. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5091 if (sp->ts_tcharlen == 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5092 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5093 /* First byte. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5094 sp->ts_tcharidx = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5095 sp->ts_tcharlen = MB_BYTE2LEN(c);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5096 sp->ts_fcharstart = sp->ts_fidx - 1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5097 sp->ts_isdiff = (newscore != 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5098 ? DIFF_YES : DIFF_NONE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5099 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5100 else if (sp->ts_isdiff == DIFF_INSERT)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5101 /* When inserting trail bytes don't advance in the
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5102 * bad word. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5103 --sp->ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5104 if (++sp->ts_tcharidx == sp->ts_tcharlen)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5105 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5106 /* Last byte of character. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5107 if (sp->ts_isdiff == DIFF_YES)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5108 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5109 /* Correct ts_fidx for the byte length of the
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5110 * character (we didn't check that before). */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5111 sp->ts_fidx = sp->ts_fcharstart
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5112 + MB_BYTE2LEN(
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5113 fword[sp->ts_fcharstart]);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5114
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5115 /* For changing a composing character adjust
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5116 * the score from SCORE_SUBST to
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5117 * SCORE_SUBCOMP. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5118 if (enc_utf8
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5119 && utf_iscomposing(
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5120 mb_ptr2char(tword
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5121 + sp->ts_twordlen
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5122 - sp->ts_tcharlen))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5123 && utf_iscomposing(
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5124 mb_ptr2char(fword
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5125 + sp->ts_fcharstart)))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5126 sp->ts_score -=
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5127 SCORE_SUBST - SCORE_SUBCOMP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5128
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5129 /* For a similar character adjust score from
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5130 * SCORE_SUBST to SCORE_SIMILAR. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5131 else if (!soundfold
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5132 && slang->sl_has_map
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5133 && similar_chars(slang,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5134 mb_ptr2char(tword
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5135 + sp->ts_twordlen
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5136 - sp->ts_tcharlen),
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5137 mb_ptr2char(fword
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5138 + sp->ts_fcharstart)))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5139 sp->ts_score -=
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5140 SCORE_SUBST - SCORE_SIMILAR;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5141 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5142 else if (sp->ts_isdiff == DIFF_INSERT
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5143 && sp->ts_twordlen > sp->ts_tcharlen)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5144 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5145 p = tword + sp->ts_twordlen - sp->ts_tcharlen;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5146 c = mb_ptr2char(p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5147 if (enc_utf8 && utf_iscomposing(c))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5148 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5149 /* Inserting a composing char doesn't
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5150 * count that much. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5151 sp->ts_score -= SCORE_INS - SCORE_INSCOMP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5152 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5153 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5154 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5155 /* If the previous character was the same,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5156 * thus doubling a character, give a bonus
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5157 * to the score. Also for the soundfold
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5158 * tree (might seem illogical but does
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5159 * give better scores). */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5160 mb_ptr_back(tword, p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5161 if (c == mb_ptr2char(p))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5162 sp->ts_score -= SCORE_INS
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5163 - SCORE_INSDUP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5164 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5165 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5166
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5167 /* Starting a new char, reset the length. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5168 sp->ts_tcharlen = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5169 }
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
5170 }
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5171 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5172 #endif
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
5173 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5174 /* If we found a similar char adjust the score.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5175 * We do this after calling go_deeper() because
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5176 * it's slow. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5177 if (newscore != 0
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5178 && !soundfold
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5179 && slang->sl_has_map
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5180 && similar_chars(slang,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5181 c, fword[sp->ts_fidx - 1]))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5182 sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR;
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
5183 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5184 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5185 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5186 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5187
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5188 case STATE_DEL:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5189 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5190 /* When past the first byte of a multi-byte char don't try
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5191 * delete/insert/swap a character. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5192 if (has_mbyte && sp->ts_tcharlen > 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5193 {
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5194 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5195 sp->ts_state = STATE_FINAL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5196 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5197 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5198 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5199 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5200 * Try skipping one character in the bad word (delete it).
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5201 */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5202 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5203 sp->ts_state = STATE_INS_PREP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5204 sp->ts_curi = 1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5205 if (soundfold && sp->ts_fidx == 0 && fword[sp->ts_fidx] == '*')
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5206 /* Deleting a vowel at the start of a word counts less, see
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5207 * soundalike_score(). */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5208 newscore = 2 * SCORE_DEL / 3;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5209 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5210 newscore = SCORE_DEL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5211 if (fword[sp->ts_fidx] != NUL
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5212 && TRY_DEEPER(su, stack, depth, newscore))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5213 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5214 go_deeper(stack, depth, newscore);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5215 #ifdef DEBUG_TRIEWALK
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5216 sprintf(changename[depth], "%.*s-%s: delete %c",
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5217 sp->ts_twordlen, tword, fword + sp->ts_fidx,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5218 fword[sp->ts_fidx]);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5219 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5220 ++depth;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5221
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5222 /* Remember what character we deleted, so that we can avoid
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5223 * inserting it again. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5224 stack[depth].ts_flags |= TSF_DIDDEL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5225 stack[depth].ts_delidx = sp->ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5226
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5227 /* Advance over the character in fword[]. Give a bonus to the
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5228 * score if the same character is following "nn" -> "n". It's
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5229 * a bit illogical for soundfold tree but it does give better
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5230 * results. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5231 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5232 if (has_mbyte)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5233 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5234 c = mb_ptr2char(fword + sp->ts_fidx);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5235 stack[depth].ts_fidx += MB_BYTE2LEN(fword[sp->ts_fidx]);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5236 if (enc_utf8 && utf_iscomposing(c))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5237 stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5238 else if (c == mb_ptr2char(fword + stack[depth].ts_fidx))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5239 stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5240 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5241 else
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5242 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5243 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5244 ++stack[depth].ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5245 if (fword[sp->ts_fidx] == fword[sp->ts_fidx + 1])
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5246 stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5247 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5248 break;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5249 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5250 /*FALLTHROUGH*/
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5251
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5252 case STATE_INS_PREP:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5253 if (sp->ts_flags & TSF_DIDDEL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5254 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5255 /* If we just deleted a byte then inserting won't make sense,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5256 * a substitute is always cheaper. */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5257 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5258 sp->ts_state = STATE_SWAP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5259 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5260 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5261
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5262 /* skip over NUL bytes */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5263 n = sp->ts_arridx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5264 for (;;)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5265 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5266 if (sp->ts_curi > byts[n])
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5267 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5268 /* Only NUL bytes at this node, go to next state. */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5269 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5270 sp->ts_state = STATE_SWAP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5271 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5272 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5273 if (byts[n + sp->ts_curi] != NUL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5274 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5275 /* Found a byte to insert. */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5276 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5277 sp->ts_state = STATE_INS;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5278 break;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5279 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5280 ++sp->ts_curi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5281 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5282 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5283
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5284 /*FALLTHROUGH*/
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5285
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5286 case STATE_INS:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5287 /* Insert one byte. Repeat this for each possible byte at this
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5288 * node. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5289 n = sp->ts_arridx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5290 if (sp->ts_curi > byts[n])
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5291 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5292 /* Done all bytes at this node, go to next state. */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5293 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5294 sp->ts_state = STATE_SWAP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5295 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5296 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5297
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5298 /* Do one more byte at this node, but:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5299 * - Skip NUL bytes.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5300 * - Skip the byte if it's equal to the byte in the word,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5301 * accepting that byte is always better.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5302 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5303 n += sp->ts_curi++;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5304 c = byts[n];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5305 if (soundfold && sp->ts_twordlen == 0 && c == '*')
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5306 /* Inserting a vowel at the start of a word counts less,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5307 * see soundalike_score(). */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5308 newscore = 2 * SCORE_INS / 3;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5309 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5310 newscore = SCORE_INS;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5311 if (c != fword[sp->ts_fidx]
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5312 && TRY_DEEPER(su, stack, depth, newscore))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5313 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5314 go_deeper(stack, depth, newscore);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5315 #ifdef DEBUG_TRIEWALK
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5316 sprintf(changename[depth], "%.*s-%s: insert %c",
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5317 sp->ts_twordlen, tword, fword + sp->ts_fidx,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5318 c);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5319 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5320 ++depth;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5321 sp = &stack[depth];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5322 tword[sp->ts_twordlen++] = c;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5323 sp->ts_arridx = idxs[n];
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5324 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5325 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5326 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5327 fl = MB_BYTE2LEN(c);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5328 if (fl > 1)
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5329 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5330 /* There are following bytes for the same character.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5331 * We must find all bytes before trying
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5332 * delete/insert/swap/etc. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5333 sp->ts_tcharlen = fl;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5334 sp->ts_tcharidx = 1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5335 sp->ts_isdiff = DIFF_INSERT;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5336 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5337 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5338 else
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5339 fl = 1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5340 if (fl == 1)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5341 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5342 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5343 /* If the previous character was the same, thus doubling a
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5344 * character, give a bonus to the score. Also for
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5345 * soundfold words (illogical but does give a better
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5346 * score). */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5347 if (sp->ts_twordlen >= 2
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5348 && tword[sp->ts_twordlen - 2] == c)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5349 sp->ts_score -= SCORE_INS - SCORE_INSDUP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5350 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5351 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5352 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5353
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5354 case STATE_SWAP:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5355 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5356 * Swap two bytes in the bad word: "12" -> "21".
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5357 * We change "fword" here, it's changed back afterwards at
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5358 * STATE_UNSWAP.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5359 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5360 p = fword + sp->ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5361 c = *p;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5362 if (c == NUL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5363 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5364 /* End of word, can't swap or replace. */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5365 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5366 sp->ts_state = STATE_FINAL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5367 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5368 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5369
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5370 /* Don't swap if the first character is not a word character.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5371 * SWAP3 etc. also don't make sense then. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
5372 if (!soundfold && !spell_iswordp(p, curwin))
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5373 {
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5374 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5375 sp->ts_state = STATE_REP_INI;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5376 break;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5377 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5378
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5379 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5380 if (has_mbyte)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5381 {
9898
bff8a09016a5 commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5382 n = MB_CPTR2LEN(p);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5383 c = mb_ptr2char(p);
1337
36275e20d997 updated for version 7.1-051
vimboss
parents: 1320
diff changeset
5384 if (p[n] == NUL)
36275e20d997 updated for version 7.1-051
vimboss
parents: 1320
diff changeset
5385 c2 = NUL;
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
5386 else if (!soundfold && !spell_iswordp(p + n, curwin))
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5387 c2 = c; /* don't swap non-word char */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5388 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5389 c2 = mb_ptr2char(p + n);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5390 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5391 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5392 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5393 {
1337
36275e20d997 updated for version 7.1-051
vimboss
parents: 1320
diff changeset
5394 if (p[1] == NUL)
36275e20d997 updated for version 7.1-051
vimboss
parents: 1320
diff changeset
5395 c2 = NUL;
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
5396 else if (!soundfold && !spell_iswordp(p + 1, curwin))
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5397 c2 = c; /* don't swap non-word char */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5398 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5399 c2 = p[1];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5400 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5401
1337
36275e20d997 updated for version 7.1-051
vimboss
parents: 1320
diff changeset
5402 /* When the second character is NUL we can't swap. */
36275e20d997 updated for version 7.1-051
vimboss
parents: 1320
diff changeset
5403 if (c2 == NUL)
36275e20d997 updated for version 7.1-051
vimboss
parents: 1320
diff changeset
5404 {
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5405 PROF_STORE(sp->ts_state)
1337
36275e20d997 updated for version 7.1-051
vimboss
parents: 1320
diff changeset
5406 sp->ts_state = STATE_REP_INI;
36275e20d997 updated for version 7.1-051
vimboss
parents: 1320
diff changeset
5407 break;
36275e20d997 updated for version 7.1-051
vimboss
parents: 1320
diff changeset
5408 }
36275e20d997 updated for version 7.1-051
vimboss
parents: 1320
diff changeset
5409
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5410 /* When characters are identical, swap won't do anything.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5411 * Also get here if the second char is not a word character. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5412 if (c == c2)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5413 {
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5414 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5415 sp->ts_state = STATE_SWAP3;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5416 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5417 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5418 if (c2 != NUL && TRY_DEEPER(su, stack, depth, SCORE_SWAP))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5419 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5420 go_deeper(stack, depth, SCORE_SWAP);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5421 #ifdef DEBUG_TRIEWALK
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5422 sprintf(changename[depth], "%.*s-%s: swap %c and %c",
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5423 sp->ts_twordlen, tword, fword + sp->ts_fidx,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5424 c, c2);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5425 #endif
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5426 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5427 sp->ts_state = STATE_UNSWAP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5428 ++depth;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5429 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5430 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5431 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5432 fl = mb_char2len(c2);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5433 mch_memmove(p, p + n, fl);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5434 mb_char2bytes(c, p + fl);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5435 stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5436 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5437 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5438 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5439 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5440 p[0] = c2;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5441 p[1] = c;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5442 stack[depth].ts_fidxtry = sp->ts_fidx + 2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5443 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5444 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5445 else
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5446 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5447 /* If this swap doesn't work then SWAP3 won't either. */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5448 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5449 sp->ts_state = STATE_REP_INI;
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5450 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5451 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5452
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5453 case STATE_UNSWAP:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5454 /* Undo the STATE_SWAP swap: "21" -> "12". */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5455 p = fword + sp->ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5456 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5457 if (has_mbyte)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5458 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5459 n = MB_BYTE2LEN(*p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5460 c = mb_ptr2char(p + n);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5461 mch_memmove(p + MB_BYTE2LEN(p[n]), p, n);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5462 mb_char2bytes(c, p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5463 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5464 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5465 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5466 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5467 c = *p;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5468 *p = p[1];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5469 p[1] = c;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5470 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5471 /*FALLTHROUGH*/
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5472
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5473 case STATE_SWAP3:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5474 /* Swap two bytes, skipping one: "123" -> "321". We change
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5475 * "fword" here, it's changed back afterwards at STATE_UNSWAP3. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5476 p = fword + sp->ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5477 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5478 if (has_mbyte)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5479 {
9898
bff8a09016a5 commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5480 n = MB_CPTR2LEN(p);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5481 c = mb_ptr2char(p);
9898
bff8a09016a5 commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5482 fl = MB_CPTR2LEN(p + n);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5483 c2 = mb_ptr2char(p + n);
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
5484 if (!soundfold && !spell_iswordp(p + n + fl, curwin))
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5485 c3 = c; /* don't swap non-word char */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5486 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5487 c3 = mb_ptr2char(p + n + fl);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5488 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5489 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5490 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5491 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5492 c = *p;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5493 c2 = p[1];
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
5494 if (!soundfold && !spell_iswordp(p + 2, curwin))
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5495 c3 = c; /* don't swap non-word char */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5496 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5497 c3 = p[2];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5498 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5499
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5500 /* When characters are identical: "121" then SWAP3 result is
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5501 * identical, ROT3L result is same as SWAP: "211", ROT3L result is
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5502 * same as SWAP on next char: "112". Thus skip all swapping.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5503 * Also skip when c3 is NUL.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5504 * Also get here when the third character is not a word character.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5505 * Second character may any char: "a.b" -> "b.a" */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5506 if (c == c3 || c3 == NUL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5507 {
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5508 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5509 sp->ts_state = STATE_REP_INI;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5510 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5511 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5512 if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5513 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5514 go_deeper(stack, depth, SCORE_SWAP3);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5515 #ifdef DEBUG_TRIEWALK
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5516 sprintf(changename[depth], "%.*s-%s: swap3 %c and %c",
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5517 sp->ts_twordlen, tword, fword + sp->ts_fidx,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5518 c, c3);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5519 #endif
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5520 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5521 sp->ts_state = STATE_UNSWAP3;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5522 ++depth;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5523 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5524 if (has_mbyte)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5525 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5526 tl = mb_char2len(c3);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5527 mch_memmove(p, p + n + fl, tl);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5528 mb_char2bytes(c2, p + tl);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5529 mb_char2bytes(c, p + fl + tl);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5530 stack[depth].ts_fidxtry = sp->ts_fidx + n + fl + tl;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5531 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5532 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5533 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5534 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5535 p[0] = p[2];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5536 p[2] = c;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5537 stack[depth].ts_fidxtry = sp->ts_fidx + 3;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5538 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5539 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5540 else
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5541 {
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5542 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5543 sp->ts_state = STATE_REP_INI;
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5544 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5545 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5546
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5547 case STATE_UNSWAP3:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5548 /* Undo STATE_SWAP3: "321" -> "123" */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5549 p = fword + sp->ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5550 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5551 if (has_mbyte)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5552 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5553 n = MB_BYTE2LEN(*p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5554 c2 = mb_ptr2char(p + n);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5555 fl = MB_BYTE2LEN(p[n]);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5556 c = mb_ptr2char(p + n + fl);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5557 tl = MB_BYTE2LEN(p[n + fl]);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5558 mch_memmove(p + fl + tl, p, n);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5559 mb_char2bytes(c, p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5560 mb_char2bytes(c2, p + tl);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5561 p = p + tl;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5562 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5563 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5564 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5565 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5566 c = *p;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5567 *p = p[2];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5568 p[2] = c;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5569 ++p;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5570 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5571
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
5572 if (!soundfold && !spell_iswordp(p, curwin))
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5573 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5574 /* Middle char is not a word char, skip the rotate. First and
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5575 * third char were already checked at swap and swap3. */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5576 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5577 sp->ts_state = STATE_REP_INI;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5578 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5579 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5580
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5581 /* Rotate three characters left: "123" -> "231". We change
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5582 * "fword" here, it's changed back afterwards at STATE_UNROT3L. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5583 if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5584 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5585 go_deeper(stack, depth, SCORE_SWAP3);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5586 #ifdef DEBUG_TRIEWALK
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5587 p = fword + sp->ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5588 sprintf(changename[depth], "%.*s-%s: rotate left %c%c%c",
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5589 sp->ts_twordlen, tword, fword + sp->ts_fidx,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5590 p[0], p[1], p[2]);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5591 #endif
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5592 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5593 sp->ts_state = STATE_UNROT3L;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5594 ++depth;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5595 p = fword + sp->ts_fidx;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5596 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5597 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5598 {
9898
bff8a09016a5 commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5599 n = MB_CPTR2LEN(p);
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5600 c = mb_ptr2char(p);
9898
bff8a09016a5 commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5601 fl = MB_CPTR2LEN(p + n);
bff8a09016a5 commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5602 fl += MB_CPTR2LEN(p + n + fl);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5603 mch_memmove(p, p + n, fl);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5604 mb_char2bytes(c, p + fl);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5605 stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5606 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5607 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5608 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5609 {
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5610 c = *p;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5611 *p = p[1];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5612 p[1] = p[2];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5613 p[2] = c;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5614 stack[depth].ts_fidxtry = sp->ts_fidx + 3;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5615 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5616 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5617 else
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5618 {
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5619 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5620 sp->ts_state = STATE_REP_INI;
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5621 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5622 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5623
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5624 case STATE_UNROT3L:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5625 /* Undo ROT3L: "231" -> "123" */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5626 p = fword + sp->ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5627 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5628 if (has_mbyte)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5629 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5630 n = MB_BYTE2LEN(*p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5631 n += MB_BYTE2LEN(p[n]);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5632 c = mb_ptr2char(p + n);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5633 tl = MB_BYTE2LEN(p[n]);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5634 mch_memmove(p + tl, p, n);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5635 mb_char2bytes(c, p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5636 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5637 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5638 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5639 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5640 c = p[2];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5641 p[2] = p[1];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5642 p[1] = *p;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5643 *p = c;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5644 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5645
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5646 /* Rotate three bytes right: "123" -> "312". We change "fword"
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5647 * here, it's changed back afterwards at STATE_UNROT3R. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5648 if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5649 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5650 go_deeper(stack, depth, SCORE_SWAP3);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5651 #ifdef DEBUG_TRIEWALK
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5652 p = fword + sp->ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5653 sprintf(changename[depth], "%.*s-%s: rotate right %c%c%c",
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5654 sp->ts_twordlen, tword, fword + sp->ts_fidx,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5655 p[0], p[1], p[2]);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5656 #endif
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5657 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5658 sp->ts_state = STATE_UNROT3R;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5659 ++depth;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5660 p = fword + sp->ts_fidx;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5661 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5662 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5663 {
9898
bff8a09016a5 commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5664 n = MB_CPTR2LEN(p);
bff8a09016a5 commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5665 n += MB_CPTR2LEN(p + n);
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5666 c = mb_ptr2char(p + n);
9898
bff8a09016a5 commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5667 tl = MB_CPTR2LEN(p + n);
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5668 mch_memmove(p + tl, p, n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5669 mb_char2bytes(c, p);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5670 stack[depth].ts_fidxtry = sp->ts_fidx + n + tl;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5671 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5672 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5673 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5674 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5675 c = p[2];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5676 p[2] = p[1];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5677 p[1] = *p;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5678 *p = c;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5679 stack[depth].ts_fidxtry = sp->ts_fidx + 3;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5680 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5681 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5682 else
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5683 {
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5684 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5685 sp->ts_state = STATE_REP_INI;
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5686 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5687 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5688
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5689 case STATE_UNROT3R:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5690 /* Undo ROT3R: "312" -> "123" */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5691 p = fword + sp->ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5692 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5693 if (has_mbyte)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5694 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5695 c = mb_ptr2char(p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5696 tl = MB_BYTE2LEN(*p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5697 n = MB_BYTE2LEN(p[tl]);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5698 n += MB_BYTE2LEN(p[tl + n]);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5699 mch_memmove(p, p + tl, n);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5700 mb_char2bytes(c, p + n);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5701 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5702 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5703 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5704 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5705 c = *p;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5706 *p = p[1];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5707 p[1] = p[2];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5708 p[2] = c;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5709 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5710 /*FALLTHROUGH*/
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5711
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5712 case STATE_REP_INI:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5713 /* Check if matching with REP items from the .aff file would work.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5714 * Quickly skip if:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5715 * - there are no REP items and we are not in the soundfold trie
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5716 * - the score is going to be too high anyway
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5717 * - already applied a REP item or swapped here */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5718 if ((lp->lp_replang == NULL && !soundfold)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5719 || sp->ts_score + SCORE_REP >= su->su_maxscore
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5720 || sp->ts_fidx < sp->ts_fidxtry)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5721 {
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5722 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5723 sp->ts_state = STATE_FINAL;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5724 break;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5725 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5726
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5727 /* Use the first byte to quickly find the first entry that may
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5728 * match. If the index is -1 there is none. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5729 if (soundfold)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5730 sp->ts_curi = slang->sl_repsal_first[fword[sp->ts_fidx]];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5731 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5732 sp->ts_curi = lp->lp_replang->sl_rep_first[fword[sp->ts_fidx]];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5733
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5734 if (sp->ts_curi < 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5735 {
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5736 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5737 sp->ts_state = STATE_FINAL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5738 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5739 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5740
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5741 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5742 sp->ts_state = STATE_REP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5743 /*FALLTHROUGH*/
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5744
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5745 case STATE_REP:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5746 /* Try matching with REP items from the .aff file. For each match
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5747 * replace the characters and check if the resulting word is
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5748 * valid. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5749 p = fword + sp->ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5750
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5751 if (soundfold)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5752 gap = &slang->sl_repsal;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5753 else
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
5754 gap = &lp->lp_replang->sl_rep;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5755 while (sp->ts_curi < gap->ga_len)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5756 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5757 ftp = (fromto_T *)gap->ga_data + sp->ts_curi++;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5758 if (*ftp->ft_from != *p)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5759 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5760 /* past possible matching entries */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5761 sp->ts_curi = gap->ga_len;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5762 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5763 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5764 if (STRNCMP(ftp->ft_from, p, STRLEN(ftp->ft_from)) == 0
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5765 && TRY_DEEPER(su, stack, depth, SCORE_REP))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5766 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5767 go_deeper(stack, depth, SCORE_REP);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5768 #ifdef DEBUG_TRIEWALK
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5769 sprintf(changename[depth], "%.*s-%s: replace %s with %s",
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5770 sp->ts_twordlen, tword, fword + sp->ts_fidx,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5771 ftp->ft_from, ftp->ft_to);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5772 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5773 /* Need to undo this afterwards. */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5774 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5775 sp->ts_state = STATE_REP_UNDO;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5776
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5777 /* Change the "from" to the "to" string. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5778 ++depth;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
5779 fl = (int)STRLEN(ftp->ft_from);
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
5780 tl = (int)STRLEN(ftp->ft_to);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5781 if (fl != tl)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5782 {
1619
b9740fb41986 updated for version 7.2a
vimboss
parents: 1580
diff changeset
5783 STRMOVE(p + tl, p + fl);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5784 repextra += tl - fl;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5785 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5786 mch_memmove(p, ftp->ft_to, tl);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5787 stack[depth].ts_fidxtry = sp->ts_fidx + tl;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5788 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5789 stack[depth].ts_tcharlen = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5790 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5791 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5792 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5793 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5794
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5795 if (sp->ts_curi >= gap->ga_len && sp->ts_state == STATE_REP)
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5796 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5797 /* No (more) matches. */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5798 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5799 sp->ts_state = STATE_FINAL;
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5800 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5801
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5802 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5803
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5804 case STATE_REP_UNDO:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5805 /* Undo a REP replacement and continue with the next one. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5806 if (soundfold)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5807 gap = &slang->sl_repsal;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5808 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5809 gap = &lp->lp_replang->sl_rep;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5810 ftp = (fromto_T *)gap->ga_data + sp->ts_curi - 1;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
5811 fl = (int)STRLEN(ftp->ft_from);
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
5812 tl = (int)STRLEN(ftp->ft_to);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5813 p = fword + sp->ts_fidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5814 if (fl != tl)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5815 {
1619
b9740fb41986 updated for version 7.2a
vimboss
parents: 1580
diff changeset
5816 STRMOVE(p + fl, p + tl);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5817 repextra -= tl - fl;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5818 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5819 mch_memmove(p, ftp->ft_from, fl);
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
5820 PROF_STORE(sp->ts_state)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5821 sp->ts_state = STATE_REP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5822 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5823
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5824 default:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5825 /* Did all possible states at this level, go up one level. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5826 --depth;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5827
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5828 if (depth >= 0 && stack[depth].ts_prefixdepth == PFD_PREFIXTREE)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5829 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5830 /* Continue in or go back to the prefix tree. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5831 byts = pbyts;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5832 idxs = pidxs;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5833 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5834
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5835 /* Don't check for CTRL-C too often, it takes time. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5836 if (--breakcheckcount == 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5837 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5838 ui_breakcheck();
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5839 breakcheckcount = 1000;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5840 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5841 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5842 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5843 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5844
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5845
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5846 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5847 * Go one level deeper in the tree.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5848 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5849 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
5850 go_deeper(trystate_T *stack, int depth, int score_add)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5851 {
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5852 stack[depth + 1] = stack[depth];
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5853 stack[depth + 1].ts_state = STATE_START;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
5854 stack[depth + 1].ts_score = stack[depth].ts_score + score_add;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5855 stack[depth + 1].ts_curi = 1; /* start just after length byte */
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
5856 stack[depth + 1].ts_flags = 0;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5857 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5858
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5859 #ifdef FEAT_MBYTE
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5860 /*
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5861 * Case-folding may change the number of bytes: Count nr of chars in
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5862 * fword[flen] and return the byte length of that many chars in "word".
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5863 */
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5864 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
5865 nofold_len(char_u *fword, int flen, char_u *word)
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5866 {
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5867 char_u *p;
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5868 int i = 0;
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5869
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5870 for (p = fword; p < fword + flen; mb_ptr_adv(p))
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5871 ++i;
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5872 for (p = word; i > 0; mb_ptr_adv(p))
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5873 --i;
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5874 return (int)(p - word);
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5875 }
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5876 #endif
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
5877
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5878 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5879 * "fword" is a good word with case folded. Find the matching keep-case
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5880 * words and put it in "kword".
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5881 * Theoretically there could be several keep-case words that result in the
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5882 * same case-folded word, but we only find one...
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5883 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5884 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
5885 find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5886 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5887 char_u uword[MAXWLEN]; /* "fword" in upper-case */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5888 int depth;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5889 idx_T tryidx;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5890
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5891 /* The following arrays are used at each depth in the tree. */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5892 idx_T arridx[MAXWLEN];
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5893 int round[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5894 int fwordidx[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5895 int uwordidx[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5896 int kwordlen[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5897
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5898 int flen, ulen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5899 int l;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5900 int len;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5901 int c;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5902 idx_T lo, hi, m;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5903 char_u *p;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5904 char_u *byts = slang->sl_kbyts; /* array with bytes of the words */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5905 idx_T *idxs = slang->sl_kidxs; /* array with indexes */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5906
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5907 if (byts == NULL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5908 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5909 /* array is empty: "cannot happen" */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5910 *kword = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5911 return;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5912 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5913
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5914 /* Make an all-cap version of "fword". */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5915 allcap_copy(fword, uword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5916
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5917 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5918 * Each character needs to be tried both case-folded and upper-case.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5919 * All this gets very complicated if we keep in mind that changing case
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5920 * may change the byte length of a multi-byte character...
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5921 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5922 depth = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5923 arridx[0] = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5924 round[0] = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5925 fwordidx[0] = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5926 uwordidx[0] = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5927 kwordlen[0] = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5928 while (depth >= 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5929 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5930 if (fword[fwordidx[depth]] == NUL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5931 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5932 /* We are at the end of "fword". If the tree allows a word to end
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5933 * here we have found a match. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5934 if (byts[arridx[depth] + 1] == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5935 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5936 kword[kwordlen[depth]] = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5937 return;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5938 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5939
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5940 /* kword is getting too long, continue one level up */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5941 --depth;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5942 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5943 else if (++round[depth] > 2)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5944 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5945 /* tried both fold-case and upper-case character, continue one
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5946 * level up */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5947 --depth;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5948 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5949 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5950 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5951 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5952 * round[depth] == 1: Try using the folded-case character.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5953 * round[depth] == 2: Try using the upper-case character.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5954 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5955 #ifdef FEAT_MBYTE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5956 if (has_mbyte)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5957 {
9898
bff8a09016a5 commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5958 flen = MB_CPTR2LEN(fword + fwordidx[depth]);
bff8a09016a5 commit https://github.com/vim/vim/commit/d3c907b5d2b352482b580a0cf687cbbea4c19ea1
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
5959 ulen = MB_CPTR2LEN(uword + uwordidx[depth]);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5960 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5961 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5962 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5963 ulen = flen = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5964 if (round[depth] == 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5965 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5966 p = fword + fwordidx[depth];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5967 l = flen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5968 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5969 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5970 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5971 p = uword + uwordidx[depth];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5972 l = ulen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5973 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5974
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5975 for (tryidx = arridx[depth]; l > 0; --l)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5976 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5977 /* Perform a binary search in the list of accepted bytes. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5978 len = byts[tryidx++];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5979 c = *p++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5980 lo = tryidx;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5981 hi = tryidx + len - 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5982 while (lo < hi)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5983 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5984 m = (lo + hi) / 2;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5985 if (byts[m] > c)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5986 hi = m - 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5987 else if (byts[m] < c)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5988 lo = m + 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5989 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5990 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5991 lo = hi = m;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5992 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5993 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5994 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5995
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5996 /* Stop if there is no matching byte. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5997 if (hi < lo || byts[lo] != c)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5998 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5999
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6000 /* Continue at the child (if there is one). */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6001 tryidx = idxs[lo];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6002 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6003
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6004 if (l == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6005 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6006 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6007 * Found the matching char. Copy it to "kword" and go a
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6008 * level deeper.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6009 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6010 if (round[depth] == 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6011 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6012 STRNCPY(kword + kwordlen[depth], fword + fwordidx[depth],
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6013 flen);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6014 kwordlen[depth + 1] = kwordlen[depth] + flen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6015 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6016 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6017 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6018 STRNCPY(kword + kwordlen[depth], uword + uwordidx[depth],
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6019 ulen);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6020 kwordlen[depth + 1] = kwordlen[depth] + ulen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6021 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6022 fwordidx[depth + 1] = fwordidx[depth] + flen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6023 uwordidx[depth + 1] = uwordidx[depth] + ulen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6024
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6025 ++depth;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6026 arridx[depth] = tryidx;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6027 round[depth] = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6028 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6029 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6030 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6031
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6032 /* Didn't find it: "cannot happen". */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6033 *kword = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6034 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6035
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6036 /*
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6037 * Compute the sound-a-like score for suggestions in su->su_ga and add them to
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6038 * su->su_sga.
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6039 */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6040 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6041 score_comp_sal(suginfo_T *su)
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6042 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6043 langp_T *lp;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6044 char_u badsound[MAXWLEN];
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6045 int i;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6046 suggest_T *stp;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6047 suggest_T *sstp;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6048 int score;
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
6049 int lpi;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6050
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6051 if (ga_grow(&su->su_sga, su->su_ga.ga_len) == FAIL)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6052 return;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6053
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6054 /* Use the sound-folding of the first language that supports it. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6055 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6056 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6057 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6058 if (lp->lp_slang->sl_sal.ga_len > 0)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6059 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6060 /* soundfold the bad word */
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
6061 spell_soundfold(lp->lp_slang, su->su_fbadword, TRUE, badsound);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6062
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6063 for (i = 0; i < su->su_ga.ga_len; ++i)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6064 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6065 stp = &SUG(su->su_ga, i);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6066
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6067 /* Case-fold the suggested word, sound-fold it and compute the
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6068 * sound-a-like score. */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6069 score = stp_sal_score(stp, su, lp->lp_slang, badsound);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6070 if (score < SCORE_MAXMAX)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6071 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6072 /* Add the suggestion. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6073 sstp = &SUG(su->su_sga, su->su_sga.ga_len);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6074 sstp->st_word = vim_strsave(stp->st_word);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6075 if (sstp->st_word != NULL)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6076 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6077 sstp->st_wordlen = stp->st_wordlen;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6078 sstp->st_score = score;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6079 sstp->st_altscore = 0;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6080 sstp->st_orglen = stp->st_orglen;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6081 ++su->su_sga.ga_len;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6082 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6083 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6084 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6085 break;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6086 }
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
6087 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6088 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6089
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6090 /*
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6091 * Combine the list of suggestions in su->su_ga and su->su_sga.
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 3620
diff changeset
6092 * They are entwined.
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6093 */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6094 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6095 score_combine(suginfo_T *su)
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6096 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6097 int i;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6098 int j;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6099 garray_T ga;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6100 garray_T *gap;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6101 langp_T *lp;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6102 suggest_T *stp;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6103 char_u *p;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6104 char_u badsound[MAXWLEN];
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6105 int round;
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
6106 int lpi;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6107 slang_T *slang = NULL;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6108
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6109 /* Add the alternate score to su_ga. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6110 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6111 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6112 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6113 if (lp->lp_slang->sl_sal.ga_len > 0)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6114 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6115 /* soundfold the bad word */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6116 slang = lp->lp_slang;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6117 spell_soundfold(slang, su->su_fbadword, TRUE, badsound);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6118
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6119 for (i = 0; i < su->su_ga.ga_len; ++i)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6120 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6121 stp = &SUG(su->su_ga, i);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6122 stp->st_altscore = stp_sal_score(stp, su, slang, badsound);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6123 if (stp->st_altscore == SCORE_MAXMAX)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6124 stp->st_score = (stp->st_score * 3 + SCORE_BIG) / 4;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6125 else
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6126 stp->st_score = (stp->st_score * 3
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6127 + stp->st_altscore) / 4;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6128 stp->st_salscore = FALSE;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6129 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6130 break;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6131 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6132 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6133
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
6134 if (slang == NULL) /* Using "double" without sound folding. */
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
6135 {
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
6136 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore,
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
6137 su->su_maxcount);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6138 return;
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
6139 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6140
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6141 /* Add the alternate score to su_sga. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6142 for (i = 0; i < su->su_sga.ga_len; ++i)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6143 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6144 stp = &SUG(su->su_sga, i);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6145 stp->st_altscore = spell_edit_score(slang,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6146 su->su_badword, stp->st_word);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6147 if (stp->st_score == SCORE_MAXMAX)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6148 stp->st_score = (SCORE_BIG * 7 + stp->st_altscore) / 8;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6149 else
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6150 stp->st_score = (stp->st_score * 7 + stp->st_altscore) / 8;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6151 stp->st_salscore = TRUE;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6152 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6153
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6154 /* Remove bad suggestions, sort the suggestions and truncate at "maxcount"
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6155 * for both lists. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6156 check_suggestions(su, &su->su_ga);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6157 (void)cleanup_suggestions(&su->su_ga, su->su_maxscore, su->su_maxcount);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6158 check_suggestions(su, &su->su_sga);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6159 (void)cleanup_suggestions(&su->su_sga, su->su_maxscore, su->su_maxcount);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6160
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6161 ga_init2(&ga, (int)sizeof(suginfo_T), 1);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6162 if (ga_grow(&ga, su->su_ga.ga_len + su->su_sga.ga_len) == FAIL)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6163 return;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6164
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6165 stp = &SUG(ga, 0);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6166 for (i = 0; i < su->su_ga.ga_len || i < su->su_sga.ga_len; ++i)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6167 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6168 /* round 1: get a suggestion from su_ga
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6169 * round 2: get a suggestion from su_sga */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6170 for (round = 1; round <= 2; ++round)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6171 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6172 gap = round == 1 ? &su->su_ga : &su->su_sga;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6173 if (i < gap->ga_len)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6174 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6175 /* Don't add a word if it's already there. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6176 p = SUG(*gap, i).st_word;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6177 for (j = 0; j < ga.ga_len; ++j)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6178 if (STRCMP(stp[j].st_word, p) == 0)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6179 break;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6180 if (j == ga.ga_len)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6181 stp[ga.ga_len++] = SUG(*gap, i);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6182 else
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6183 vim_free(p);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6184 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6185 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6186 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6187
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6188 ga_clear(&su->su_ga);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6189 ga_clear(&su->su_sga);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6190
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6191 /* Truncate the list to the number of suggestions that will be displayed. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6192 if (ga.ga_len > su->su_maxcount)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6193 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6194 for (i = su->su_maxcount; i < ga.ga_len; ++i)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6195 vim_free(stp[i].st_word);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6196 ga.ga_len = su->su_maxcount;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6197 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6198
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6199 su->su_ga = ga;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6200 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6201
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6202 /*
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6203 * For the goodword in "stp" compute the soundalike score compared to the
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6204 * badword.
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6205 */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6206 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6207 stp_sal_score(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6208 suggest_T *stp,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6209 suginfo_T *su,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6210 slang_T *slang,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6211 char_u *badsound) /* sound-folded badword */
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6212 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6213 char_u *p;
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6214 char_u *pbad;
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6215 char_u *pgood;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6216 char_u badsound2[MAXWLEN];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6217 char_u fword[MAXWLEN];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6218 char_u goodsound[MAXWLEN];
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6219 char_u goodword[MAXWLEN];
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6220 int lendiff;
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6221
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6222 lendiff = (int)(su->su_badlen - stp->st_orglen);
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6223 if (lendiff >= 0)
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6224 pbad = badsound;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6225 else
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6226 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6227 /* soundfold the bad word with more characters following */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6228 (void)spell_casefold(su->su_badptr, stp->st_orglen, fword, MAXWLEN);
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6229
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6230 /* When joining two words the sound often changes a lot. E.g., "t he"
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6231 * sounds like "t h" while "the" sounds like "@". Avoid that by
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6232 * removing the space. Don't do it when the good word also contains a
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6233 * space. */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6234 if (vim_iswhite(su->su_badptr[su->su_badlen])
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6235 && *skiptowhite(stp->st_word) == NUL)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6236 for (p = fword; *(p = skiptowhite(p)) != NUL; )
1619
b9740fb41986 updated for version 7.2a
vimboss
parents: 1580
diff changeset
6237 STRMOVE(p, p + 1);
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6238
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
6239 spell_soundfold(slang, fword, TRUE, badsound2);
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6240 pbad = badsound2;
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6241 }
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6242
2768
c5e47b752f07 updated for version 7.3.160
Bram Moolenaar <bram@vim.org>
parents: 2691
diff changeset
6243 if (lendiff > 0 && stp->st_wordlen + lendiff < MAXWLEN)
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6244 {
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6245 /* Add part of the bad word to the good word, so that we soundfold
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6246 * what replaces the bad word. */
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6247 STRCPY(goodword, stp->st_word);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6248 vim_strncpy(goodword + stp->st_wordlen,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6249 su->su_badptr + su->su_badlen - lendiff, lendiff);
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6250 pgood = goodword;
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6251 }
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6252 else
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6253 pgood = stp->st_word;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6254
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
6255 /* Sound-fold the word and compute the score for the difference. */
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6256 spell_soundfold(slang, pgood, FALSE, goodsound);
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6257
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6258 return soundalike_score(goodsound, pbad);
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6259 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6260
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6261 /* structure used to store soundfolded words that add_sound_suggest() has
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6262 * handled already. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6263 typedef struct
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6264 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6265 short sft_score; /* lowest score used */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6266 char_u sft_word[1]; /* soundfolded word, actually longer */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6267 } sftword_T;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6268
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6269 static sftword_T dumsft;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6270 #define HIKEY2SFT(p) ((sftword_T *)(p - (dumsft.sft_word - (char_u *)&dumsft)))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6271 #define HI2SFT(hi) HIKEY2SFT((hi)->hi_key)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6272
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6273 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6274 * Prepare for calling suggest_try_soundalike().
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6275 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6276 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6277 suggest_try_soundalike_prep(void)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6278 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6279 langp_T *lp;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6280 int lpi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6281 slang_T *slang;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6282
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6283 /* Do this for all languages that support sound folding and for which a
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6284 * .sug file has been loaded. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6285 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6286 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6287 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6288 slang = lp->lp_slang;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6289 if (slang->sl_sal.ga_len > 0 && slang->sl_sbyts != NULL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6290 /* prepare the hashtable used by add_sound_suggest() */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6291 hash_init(&slang->sl_sounddone);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6292 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6293 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6294
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
6295 /*
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6296 * Find suggestions by comparing the word in a sound-a-like form.
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
6297 * Note: This doesn't support postponed prefixes.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6298 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6299 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6300 suggest_try_soundalike(suginfo_T *su)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6301 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6302 char_u salword[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6303 langp_T *lp;
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
6304 int lpi;
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
6305 slang_T *slang;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6306
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6307 /* Do this for all languages that support sound folding and for which a
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6308 * .sug file has been loaded. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6309 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6310 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6311 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6312 slang = lp->lp_slang;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6313 if (slang->sl_sal.ga_len > 0 && slang->sl_sbyts != NULL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6314 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6315 /* soundfold the bad word */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6316 spell_soundfold(slang, su->su_fbadword, TRUE, salword);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6317
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6318 /* try all kinds of inserts/deletes/swaps/etc. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6319 /* TODO: also soundfold the next words, so that we can try joining
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6320 * and splitting */
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
6321 #ifdef SUGGEST_PROFILE
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
6322 prof_init();
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
6323 #endif
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6324 suggest_trie_walk(su, lp, salword, TRUE);
7509
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
6325 #ifdef SUGGEST_PROFILE
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
6326 prof_report("soundalike");
a64793340689 commit https://github.com/vim/vim/commit/ca1fe985175385c609f8e06672a1014729aba05c
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
6327 #endif
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6328 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6329 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6330 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6331
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6332 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6333 * Finish up after calling suggest_try_soundalike().
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6334 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6335 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6336 suggest_try_soundalike_finish(void)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6337 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6338 langp_T *lp;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6339 int lpi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6340 slang_T *slang;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6341 int todo;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6342 hashitem_T *hi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6343
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6344 /* Do this for all languages that support sound folding and for which a
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6345 * .sug file has been loaded. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6346 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6347 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
6348 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
6349 slang = lp->lp_slang;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6350 if (slang->sl_sal.ga_len > 0 && slang->sl_sbyts != NULL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6351 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6352 /* Free the info about handled words. */
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
6353 todo = (int)slang->sl_sounddone.ht_used;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6354 for (hi = slang->sl_sounddone.ht_array; todo > 0; ++hi)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6355 if (!HASHITEM_EMPTY(hi))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6356 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6357 vim_free(HI2SFT(hi));
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6358 --todo;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6359 }
1087
c94bbf85eb16 updated for version 7.0-213
vimboss
parents: 977
diff changeset
6360
c94bbf85eb16 updated for version 7.0-213
vimboss
parents: 977
diff changeset
6361 /* Clear the hashtable, it may also be used by another region. */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6362 hash_clear(&slang->sl_sounddone);
1087
c94bbf85eb16 updated for version 7.0-213
vimboss
parents: 977
diff changeset
6363 hash_init(&slang->sl_sounddone);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6364 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6365 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6366 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6367
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6368 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6369 * A match with a soundfolded word is found. Add the good word(s) that
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6370 * produce this soundfolded word.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6371 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6372 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6373 add_sound_suggest(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6374 suginfo_T *su,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6375 char_u *goodword,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6376 int score, /* soundfold score */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6377 langp_T *lp)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6378 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6379 slang_T *slang = lp->lp_slang; /* language for sound folding */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6380 int sfwordnr;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6381 char_u *nrline;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6382 int orgnr;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6383 char_u theword[MAXWLEN];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6384 int i;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6385 int wlen;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6386 char_u *byts;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6387 idx_T *idxs;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6388 int n;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6389 int wordcount;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6390 int wc;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6391 int goodscore;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6392 hash_T hash;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6393 hashitem_T *hi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6394 sftword_T *sft;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6395 int bc, gc;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6396 int limit;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6397
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6398 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6399 * It's very well possible that the same soundfold word is found several
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6400 * times with different scores. Since the following is quite slow only do
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6401 * the words that have a better score than before. Use a hashtable to
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6402 * remember the words that have been done.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6403 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6404 hash = hash_hash(goodword);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6405 hi = hash_lookup(&slang->sl_sounddone, goodword, hash);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6406 if (HASHITEM_EMPTY(hi))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6407 {
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
6408 sft = (sftword_T *)alloc((unsigned)(sizeof(sftword_T)
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
6409 + STRLEN(goodword)));
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6410 if (sft != NULL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6411 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6412 sft->sft_score = score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6413 STRCPY(sft->sft_word, goodword);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6414 hash_add_item(&slang->sl_sounddone, hi, sft->sft_word, hash);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6415 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6416 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6417 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6418 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6419 sft = HI2SFT(hi);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6420 if (score >= sft->sft_score)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6421 return;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6422 sft->sft_score = score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6423 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6424
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6425 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6426 * Find the word nr in the soundfold tree.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6427 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6428 sfwordnr = soundfold_find(slang, goodword);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6429 if (sfwordnr < 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6430 {
10359
66f1b5bf3fa6 commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents: 10277
diff changeset
6431 internal_error("add_sound_suggest()");
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6432 return;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6433 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6434
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6435 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6436 * go over the list of good words that produce this soundfold word
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6437 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6438 nrline = ml_get_buf(slang->sl_sugbuf, (linenr_T)(sfwordnr + 1), FALSE);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6439 orgnr = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6440 while (*nrline != NUL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6441 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6442 /* The wordnr was stored in a minimal nr of bytes as an offset to the
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6443 * previous wordnr. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6444 orgnr += bytes2offset(&nrline);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6445
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6446 byts = slang->sl_fbyts;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6447 idxs = slang->sl_fidxs;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6448
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6449 /* Lookup the word "orgnr" one of the two tries. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6450 n = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6451 wordcount = 0;
5506
9417f4de27a2 updated for version 7.4.102
Bram Moolenaar <bram@vim.org>
parents: 5485
diff changeset
6452 for (wlen = 0; wlen < MAXWLEN - 3; ++wlen)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6453 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6454 i = 1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6455 if (wordcount == orgnr && byts[n + 1] == NUL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6456 break; /* found end of word */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6457
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6458 if (byts[n + 1] == NUL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6459 ++wordcount;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6460
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6461 /* skip over the NUL bytes */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6462 for ( ; byts[n + i] == NUL; ++i)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6463 if (i > byts[n]) /* safety check */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6464 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6465 STRCPY(theword + wlen, "BAD");
5506
9417f4de27a2 updated for version 7.4.102
Bram Moolenaar <bram@vim.org>
parents: 5485
diff changeset
6466 wlen += 3;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6467 goto badword;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6468 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6469
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6470 /* One of the siblings must have the word. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6471 for ( ; i < byts[n]; ++i)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6472 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6473 wc = idxs[idxs[n + i]]; /* nr of words under this byte */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6474 if (wordcount + wc > orgnr)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6475 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6476 wordcount += wc;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6477 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6478
5506
9417f4de27a2 updated for version 7.4.102
Bram Moolenaar <bram@vim.org>
parents: 5485
diff changeset
6479 theword[wlen] = byts[n + i];
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6480 n = idxs[n + i];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6481 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6482 badword:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6483 theword[wlen] = NUL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6484
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6485 /* Go over the possible flags and regions. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6486 for (; i <= byts[n] && byts[n + i] == NUL; ++i)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6487 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6488 char_u cword[MAXWLEN];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6489 char_u *p;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6490 int flags = (int)idxs[n + i];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6491
698
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
6492 /* Skip words with the NOSUGGEST flag */
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
6493 if (flags & WF_NOSUGGEST)
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
6494 continue;
e402b0af6083 updated for version 7.0211
vimboss
parents: 695
diff changeset
6495
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6496 if (flags & WF_KEEPCAP)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6497 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6498 /* Must find the word in the keep-case tree. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6499 find_keepcap_word(slang, theword, cword);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6500 p = cword;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6501 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6502 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6503 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6504 flags |= su->su_badflags;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6505 if ((flags & WF_CAPMASK) != 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6506 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6507 /* Need to fix case according to "flags". */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6508 make_case_word(theword, cword, flags);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6509 p = cword;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6510 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6511 else
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6512 p = theword;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6513 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6514
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6515 /* Add the suggestion. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6516 if (sps_flags & SPS_DOUBLE)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6517 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6518 /* Add the suggestion if the score isn't too bad. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6519 if (score <= su->su_maxscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6520 add_suggestion(su, &su->su_sga, p, su->su_badlen,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6521 score, 0, FALSE, slang, FALSE);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6522 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6523 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6524 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6525 /* Add a penalty for words in another region. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6526 if ((flags & WF_REGION)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6527 && (((unsigned)flags >> 16) & lp->lp_region) == 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6528 goodscore = SCORE_REGION;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6529 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6530 goodscore = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6531
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6532 /* Add a small penalty for changing the first letter from
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6533 * lower to upper case. Helps for "tath" -> "Kath", which is
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 3620
diff changeset
6534 * less common than "tath" -> "path". Don't do it when the
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6535 * letter is the same, that has already been counted. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6536 gc = PTR2CHAR(p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6537 if (SPELL_ISUPPER(gc))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6538 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6539 bc = PTR2CHAR(su->su_badword);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6540 if (!SPELL_ISUPPER(bc)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6541 && SPELL_TOFOLD(bc) != SPELL_TOFOLD(gc))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6542 goodscore += SCORE_ICASE / 2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6543 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6544
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6545 /* Compute the score for the good word. This only does letter
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6546 * insert/delete/swap/replace. REP items are not considered,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6547 * which may make the score a bit higher.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6548 * Use a limit for the score to make it work faster. Use
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6549 * MAXSCORE(), because RESCORE() will change the score.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6550 * If the limit is very high then the iterative method is
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6551 * inefficient, using an array is quicker. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6552 limit = MAXSCORE(su->su_sfmaxscore - goodscore, score);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6553 if (limit > SCORE_LIMITMAX)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6554 goodscore += spell_edit_score(slang, su->su_badword, p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6555 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6556 goodscore += spell_edit_score_limit(slang, su->su_badword,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6557 p, limit);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6558
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6559 /* When going over the limit don't bother to do the rest. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6560 if (goodscore < SCORE_MAXMAX)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6561 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6562 /* Give a bonus to words seen before. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6563 goodscore = score_wordcount_adj(slang, goodscore, p, FALSE);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6564
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6565 /* Add the suggestion if the score isn't too bad. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6566 goodscore = RESCORE(goodscore, score);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6567 if (goodscore <= su->su_sfmaxscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6568 add_suggestion(su, &su->su_ga, p, su->su_badlen,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6569 goodscore, score, TRUE, slang, TRUE);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6570 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6571 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6572 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6573 /* smsg("word %s (%d): %s (%d)", sftword, sftnr, theword, orgnr); */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6574 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6575 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6576
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6577 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6578 * Find word "word" in fold-case tree for "slang" and return the word number.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6579 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6580 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6581 soundfold_find(slang_T *slang, char_u *word)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6582 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6583 idx_T arridx = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6584 int len;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6585 int wlen = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6586 int c;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6587 char_u *ptr = word;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6588 char_u *byts;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6589 idx_T *idxs;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6590 int wordnr = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6591
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6592 byts = slang->sl_sbyts;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6593 idxs = slang->sl_sidxs;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6594
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6595 for (;;)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6596 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6597 /* First byte is the number of possible bytes. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6598 len = byts[arridx++];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6599
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6600 /* If the first possible byte is a zero the word could end here.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6601 * If the word ends we found the word. If not skip the NUL bytes. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6602 c = ptr[wlen];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6603 if (byts[arridx] == NUL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6604 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6605 if (c == NUL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6606 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6607
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6608 /* Skip over the zeros, there can be several. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6609 while (len > 0 && byts[arridx] == NUL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6610 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6611 ++arridx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6612 --len;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6613 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6614 if (len == 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6615 return -1; /* no children, word should have ended here */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6616 ++wordnr;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6617 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6618
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6619 /* If the word ends we didn't find it. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6620 if (c == NUL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6621 return -1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6622
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6623 /* Perform a binary search in the list of accepted bytes. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6624 if (c == TAB) /* <Tab> is handled like <Space> */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6625 c = ' ';
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6626 while (byts[arridx] < c)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6627 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6628 /* The word count is in the first idxs[] entry of the child. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6629 wordnr += idxs[idxs[arridx]];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6630 ++arridx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6631 if (--len == 0) /* end of the bytes, didn't find it */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6632 return -1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6633 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6634 if (byts[arridx] != c) /* didn't find the byte */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6635 return -1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6636
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6637 /* Continue at the child (if there is one). */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6638 arridx = idxs[arridx];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6639 ++wlen;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6640
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6641 /* One space in the good word may stand for several spaces in the
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6642 * checked word. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6643 if (c == ' ')
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6644 while (ptr[wlen] == ' ' || ptr[wlen] == TAB)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6645 ++wlen;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6646 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6647
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6648 return wordnr;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6649 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6650
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6651 /*
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6652 * Copy "fword" to "cword", fixing case according to "flags".
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6653 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6654 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6655 make_case_word(char_u *fword, char_u *cword, int flags)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6656 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6657 if (flags & WF_ALLCAP)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6658 /* Make it all upper-case */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6659 allcap_copy(fword, cword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6660 else if (flags & WF_ONECAP)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6661 /* Make the first letter upper-case */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6662 onecap_copy(fword, cword, TRUE);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6663 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6664 /* Use goodword as-is. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6665 STRCPY(cword, fword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6666 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6667
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6668
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6669 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6670 * Return TRUE if "c1" and "c2" are similar characters according to the MAP
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6671 * lines in the .aff file.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6672 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6673 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6674 similar_chars(slang_T *slang, int c1, int c2)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6675 {
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6676 int m1, m2;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6677 #ifdef FEAT_MBYTE
3549
f52d2ea0f81c updated for version 7.3.535
Bram Moolenaar <bram@vim.org>
parents: 3520
diff changeset
6678 char_u buf[MB_MAXBYTES + 1];
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6679 hashitem_T *hi;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6680
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6681 if (c1 >= 256)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6682 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6683 buf[mb_char2bytes(c1, buf)] = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6684 hi = hash_find(&slang->sl_map_hash, buf);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6685 if (HASHITEM_EMPTY(hi))
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6686 m1 = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6687 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6688 m1 = mb_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6689 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6690 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6691 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6692 m1 = slang->sl_map_array[c1];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6693 if (m1 == 0)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6694 return FALSE;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6695
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6696
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6697 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6698 if (c2 >= 256)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6699 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6700 buf[mb_char2bytes(c2, buf)] = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6701 hi = hash_find(&slang->sl_map_hash, buf);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6702 if (HASHITEM_EMPTY(hi))
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6703 m2 = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6704 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6705 m2 = mb_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6706 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6707 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6708 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6709 m2 = slang->sl_map_array[c2];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6710
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
6711 return m1 == m2;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6712 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6713
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6714 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6715 * Add a suggestion to the list of suggestions.
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6716 * For a suggestion that is already in the list the lowest score is remembered.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6717 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6718 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6719 add_suggestion(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6720 suginfo_T *su,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6721 garray_T *gap, /* either su_ga or su_sga */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6722 char_u *goodword,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6723 int badlenarg, /* len of bad word replaced with "goodword" */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6724 int score,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6725 int altscore,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6726 int had_bonus, /* value for st_had_bonus */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6727 slang_T *slang, /* language for sound folding */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6728 int maxsf) /* su_maxscore applies to soundfold score,
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6729 su_sfmaxscore to the total score. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6730 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6731 int goodlen; /* len of goodword changed */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6732 int badlen; /* len of bad word changed */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6733 suggest_T *stp;
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6734 suggest_T new_sug;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6735 int i;
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6736 char_u *pgood, *pbad;
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 529
diff changeset
6737
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6738 /* Minimize "badlen" for consistency. Avoids that changing "the the" to
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6739 * "thee the" is added next to changing the first "the" the "thee". */
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6740 pgood = goodword + STRLEN(goodword);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6741 pbad = su->su_badptr + badlenarg;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6742 for (;;)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6743 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
6744 goodlen = (int)(pgood - goodword);
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
6745 badlen = (int)(pbad - su->su_badptr);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6746 if (goodlen <= 0 || badlen <= 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6747 break;
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6748 mb_ptr_back(goodword, pgood);
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6749 mb_ptr_back(su->su_badptr, pbad);
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6750 #ifdef FEAT_MBYTE
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6751 if (has_mbyte)
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6752 {
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6753 if (mb_ptr2char(pgood) != mb_ptr2char(pbad))
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6754 break;
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
6755 }
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
6756 else
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6757 #endif
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6758 if (*pgood != *pbad)
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6759 break;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6760 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6761
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6762 if (badlen == 0 && goodlen == 0)
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6763 /* goodword doesn't change anything; may happen for "the the" changing
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6764 * the first "the" to itself. */
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6765 return;
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
6766
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6767 if (gap->ga_len == 0)
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6768 i = -1;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6769 else
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6770 {
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6771 /* Check if the word is already there. Also check the length that is
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6772 * being replaced "thes," -> "these" is a different suggestion from
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6773 * "thes" -> "these". */
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6774 stp = &SUG(*gap, 0);
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6775 for (i = gap->ga_len; --i >= 0; ++stp)
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6776 if (stp->st_wordlen == goodlen
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6777 && stp->st_orglen == badlen
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6778 && STRNCMP(stp->st_word, goodword, goodlen) == 0)
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6779 {
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6780 /*
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6781 * Found it. Remember the word with the lowest score.
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6782 */
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6783 if (stp->st_slang == NULL)
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6784 stp->st_slang = slang;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6785
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6786 new_sug.st_score = score;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6787 new_sug.st_altscore = altscore;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6788 new_sug.st_had_bonus = had_bonus;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6789
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6790 if (stp->st_had_bonus != had_bonus)
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6791 {
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6792 /* Only one of the two had the soundalike score computed.
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6793 * Need to do that for the other one now, otherwise the
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6794 * scores can't be compared. This happens because
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6795 * suggest_try_change() doesn't compute the soundalike
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6796 * word to keep it fast, while some special methods set
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6797 * the soundalike score to zero. */
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6798 if (had_bonus)
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6799 rescore_one(su, stp);
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6800 else
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6801 {
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6802 new_sug.st_word = stp->st_word;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6803 new_sug.st_wordlen = stp->st_wordlen;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6804 new_sug.st_slang = stp->st_slang;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6805 new_sug.st_orglen = badlen;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6806 rescore_one(su, &new_sug);
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6807 }
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6808 }
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6809
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6810 if (stp->st_score > new_sug.st_score)
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6811 {
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6812 stp->st_score = new_sug.st_score;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6813 stp->st_altscore = new_sug.st_altscore;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6814 stp->st_had_bonus = new_sug.st_had_bonus;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6815 }
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6816 break;
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6817 }
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
6818 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6819
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6820 if (i < 0 && ga_grow(gap, 1) == OK)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6821 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6822 /* Add a suggestion. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6823 stp = &SUG(*gap, gap->ga_len);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6824 stp->st_word = vim_strnsave(goodword, goodlen);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6825 if (stp->st_word != NULL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6826 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6827 stp->st_wordlen = goodlen;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6828 stp->st_score = score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6829 stp->st_altscore = altscore;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6830 stp->st_had_bonus = had_bonus;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6831 stp->st_orglen = badlen;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6832 stp->st_slang = slang;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6833 ++gap->ga_len;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6834
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6835 /* If we have too many suggestions now, sort the list and keep
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6836 * the best suggestions. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6837 if (gap->ga_len > SUG_MAX_COUNT(su))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6838 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6839 if (maxsf)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6840 su->su_sfmaxscore = cleanup_suggestions(gap,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6841 su->su_sfmaxscore, SUG_CLEAN_COUNT(su));
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6842 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6843 su->su_maxscore = cleanup_suggestions(gap,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6844 su->su_maxscore, SUG_CLEAN_COUNT(su));
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6845 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6846 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6847 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6848 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6849
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6850 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6851 * Suggestions may in fact be flagged as errors. Esp. for banned words and
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6852 * for split words, such as "the the". Remove these from the list here.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6853 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6854 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6855 check_suggestions(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6856 suginfo_T *su,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6857 garray_T *gap) /* either su_ga or su_sga */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6858 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6859 suggest_T *stp;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6860 int i;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6861 char_u longword[MAXWLEN + 1];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6862 int len;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6863 hlf_T attr;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6864
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6865 stp = &SUG(*gap, 0);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6866 for (i = gap->ga_len - 1; i >= 0; --i)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6867 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6868 /* Need to append what follows to check for "the the". */
2768
c5e47b752f07 updated for version 7.3.160
Bram Moolenaar <bram@vim.org>
parents: 2691
diff changeset
6869 vim_strncpy(longword, stp[i].st_word, MAXWLEN);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6870 len = stp[i].st_wordlen;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6871 vim_strncpy(longword + len, su->su_badptr + stp[i].st_orglen,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6872 MAXWLEN - len);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6873 attr = HLF_COUNT;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6874 (void)spell_check(curwin, longword, &attr, NULL, FALSE);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6875 if (attr != HLF_COUNT)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6876 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6877 /* Remove this entry. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6878 vim_free(stp[i].st_word);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6879 --gap->ga_len;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6880 if (i < gap->ga_len)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6881 mch_memmove(stp + i, stp + i + 1,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6882 sizeof(suggest_T) * (gap->ga_len - i));
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6883 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6884 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6885 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6886
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6887
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6888 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6889 * Add a word to be banned.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6890 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6891 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6892 add_banned(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6893 suginfo_T *su,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6894 char_u *word)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6895 {
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
6896 char_u *s;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6897 hash_T hash;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6898 hashitem_T *hi;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6899
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6900 hash = hash_hash(word);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6901 hi = hash_lookup(&su->su_banned, word, hash);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6902 if (HASHITEM_EMPTY(hi))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6903 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6904 s = vim_strsave(word);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6905 if (s != NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6906 hash_add_item(&su->su_banned, hi, s, hash);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
6907 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6908 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6909
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6910 /*
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6911 * Recompute the score for all suggestions if sound-folding is possible. This
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6912 * is slow, thus only done for the final results.
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6913 */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6914 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6915 rescore_suggestions(suginfo_T *su)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6916 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6917 int i;
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6918
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6919 if (su->su_sallang != NULL)
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
6920 for (i = 0; i < su->su_ga.ga_len; ++i)
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6921 rescore_one(su, &SUG(su->su_ga, i));
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6922 }
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6923
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6924 /*
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6925 * Recompute the score for one suggestion if sound-folding is possible.
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6926 */
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6927 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6928 rescore_one(suginfo_T *su, suggest_T *stp)
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6929 {
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6930 slang_T *slang = stp->st_slang;
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6931 char_u sal_badword[MAXWLEN];
535
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
6932 char_u *p;
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6933
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6934 /* Only rescore suggestions that have no sal score yet and do have a
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6935 * language. */
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6936 if (slang != NULL && slang->sl_sal.ga_len > 0 && !stp->st_had_bonus)
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6937 {
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6938 if (slang == su->su_sallang)
535
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
6939 p = su->su_sal_badword;
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6940 else
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6941 {
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6942 spell_soundfold(slang, su->su_fbadword, TRUE, sal_badword);
535
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
6943 p = sal_badword;
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
6944 }
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
6945
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
6946 stp->st_altscore = stp_sal_score(stp, su, slang, p);
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6947 if (stp->st_altscore == SCORE_MAXMAX)
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6948 stp->st_altscore = SCORE_BIG;
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6949 stp->st_score = RESCORE(stp->st_score, stp->st_altscore);
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
6950 stp->st_had_bonus = TRUE;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6951 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6952 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6953
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6954 static int
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6955 #ifdef __BORLANDC__
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6956 _RTLENTRYF
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6957 #endif
7805
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7526
diff changeset
6958 sug_compare(const void *s1, const void *s2);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6959
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6960 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6961 * Function given to qsort() to sort the suggestions on st_score.
529
0d6092bb72e6 updated for version 7.0148
vimboss
parents: 523
diff changeset
6962 * First on "st_score", then "st_altscore" then alphabetically.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6963 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6964 static int
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6965 #ifdef __BORLANDC__
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6966 _RTLENTRYF
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6967 #endif
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6968 sug_compare(const void *s1, const void *s2)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6969 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6970 suggest_T *p1 = (suggest_T *)s1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6971 suggest_T *p2 = (suggest_T *)s2;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6972 int n = p1->st_score - p2->st_score;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6973
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6974 if (n == 0)
529
0d6092bb72e6 updated for version 7.0148
vimboss
parents: 523
diff changeset
6975 {
0d6092bb72e6 updated for version 7.0148
vimboss
parents: 523
diff changeset
6976 n = p1->st_altscore - p2->st_altscore;
0d6092bb72e6 updated for version 7.0148
vimboss
parents: 523
diff changeset
6977 if (n == 0)
0d6092bb72e6 updated for version 7.0148
vimboss
parents: 523
diff changeset
6978 n = STRICMP(p1->st_word, p2->st_word);
0d6092bb72e6 updated for version 7.0148
vimboss
parents: 523
diff changeset
6979 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6980 return n;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6981 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6982
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6983 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6984 * Cleanup the suggestions:
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6985 * - Sort on score.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6986 * - Remove words that won't be displayed.
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6987 * Returns the maximum score in the list or "maxscore" unmodified.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6988 */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6989 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6990 cleanup_suggestions(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6991 garray_T *gap,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6992 int maxscore,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
6993 int keep) /* nr of suggestions to keep */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6994 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6995 suggest_T *stp = &SUG(*gap, 0);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6996 int i;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6997
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6998 /* Sort the list. */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
6999 qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), sug_compare);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7000
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7001 /* Truncate the list to the number of suggestions that will be displayed. */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7002 if (gap->ga_len > keep)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7003 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7004 for (i = keep; i < gap->ga_len; ++i)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7005 vim_free(stp[i].st_word);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7006 gap->ga_len = keep;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7007 return stp[keep - 1].st_score;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7008 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7009 return maxscore;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7010 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7011
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7012 #if defined(FEAT_EVAL) || defined(PROTO)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7013 /*
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7014 * Soundfold a string, for soundfold().
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7015 * Result is in allocated memory, NULL for an error.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7016 */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7017 char_u *
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7018 eval_soundfold(char_u *word)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7019 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7020 langp_T *lp;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7021 char_u sound[MAXWLEN];
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
7022 int lpi;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7023
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
7024 if (curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7025 /* Use the sound-folding of the first language that supports it. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
7026 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
7027 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
7028 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7029 if (lp->lp_slang->sl_sal.ga_len > 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7030 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7031 /* soundfold the word */
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7032 spell_soundfold(lp->lp_slang, word, FALSE, sound);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7033 return vim_strsave(sound);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7034 }
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
7035 }
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7036
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7037 /* No language with sound folding, return word as-is. */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7038 return vim_strsave(word);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7039 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7040 #endif
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7041
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7042 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7043 * Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]".
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
7044 *
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
7045 * There are many ways to turn a word into a sound-a-like representation. The
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
7046 * oldest is Soundex (1918!). A nice overview can be found in "Approximate
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
7047 * swedish name matching - survey and test of different algorithms" by Klas
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
7048 * Erikson.
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
7049 *
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
7050 * We support two methods:
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
7051 * 1. SOFOFROM/SOFOTO do a simple character mapping.
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
7052 * 2. SAL items define a more advanced sound-folding (and much slower).
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7053 */
9583
b0c7061d6439 commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents: 9570
diff changeset
7054 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7055 spell_soundfold(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7056 slang_T *slang,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7057 char_u *inword,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7058 int folded, /* "inword" is already case-folded */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7059 char_u *res)
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7060 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7061 char_u fword[MAXWLEN];
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7062 char_u *word;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7063
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7064 if (slang->sl_sofo)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7065 /* SOFOFROM and SOFOTO used */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7066 spell_soundfold_sofo(slang, inword, res);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7067 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7068 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7069 /* SAL items used. Requires the word to be case-folded. */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7070 if (folded)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7071 word = inword;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7072 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7073 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
7074 (void)spell_casefold(inword, (int)STRLEN(inword), fword, MAXWLEN);
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7075 word = fword;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7076 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7077
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7078 #ifdef FEAT_MBYTE
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7079 if (has_mbyte)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7080 spell_soundfold_wsal(slang, word, res);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7081 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7082 #endif
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7083 spell_soundfold_sal(slang, word, res);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7084 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7085 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7086
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7087 /*
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7088 * Perform sound folding of "inword" into "res" according to SOFOFROM and
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7089 * SOFOTO lines.
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7090 */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7091 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7092 spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res)
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7093 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7094 char_u *s;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7095 int ri = 0;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7096 int c;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7097
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7098 #ifdef FEAT_MBYTE
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7099 if (has_mbyte)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7100 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7101 int prevc = 0;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7102 int *ip;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7103
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7104 /* The sl_sal_first[] table contains the translation for chars up to
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7105 * 255, sl_sal the rest. */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7106 for (s = inword; *s != NUL; )
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7107 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
7108 c = mb_cptr2char_adv(&s);
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7109 if (enc_utf8 ? utf_class(c) == 0 : vim_iswhite(c))
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7110 c = ' ';
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7111 else if (c < 256)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7112 c = slang->sl_sal_first[c];
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7113 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7114 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7115 ip = ((int **)slang->sl_sal.ga_data)[c & 0xff];
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7116 if (ip == NULL) /* empty list, can't match */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7117 c = NUL;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7118 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7119 for (;;) /* find "c" in the list */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7120 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7121 if (*ip == 0) /* not found */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7122 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7123 c = NUL;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7124 break;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7125 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7126 if (*ip == c) /* match! */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7127 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7128 c = ip[1];
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7129 break;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7130 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7131 ip += 2;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7132 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7133 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7134
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7135 if (c != NUL && c != prevc)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7136 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7137 ri += mb_char2bytes(c, res + ri);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7138 if (ri + MB_MAXBYTES > MAXWLEN)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7139 break;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7140 prevc = c;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7141 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7142 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7143 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7144 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7145 #endif
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7146 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7147 /* The sl_sal_first[] table contains the translation. */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7148 for (s = inword; (c = *s) != NUL; ++s)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7149 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7150 if (vim_iswhite(c))
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7151 c = ' ';
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7152 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7153 c = slang->sl_sal_first[c];
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7154 if (c != NUL && (ri == 0 || res[ri - 1] != c))
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7155 res[ri++] = c;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7156 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7157 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7158
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7159 res[ri] = NUL;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7160 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7161
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7162 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7163 spell_soundfold_sal(slang_T *slang, char_u *inword, char_u *res)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7164 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7165 salitem_T *smp;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7166 char_u word[MAXWLEN];
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7167 char_u *s = inword;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7168 char_u *t;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7169 char_u *pf;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7170 int i, j, z;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7171 int reslen;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7172 int n, k = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7173 int z0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7174 int k0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7175 int n0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7176 int c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7177 int pri;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7178 int p0 = -333;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7179 int c0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7180
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
7181 /* Remove accents, if wanted. We actually remove all non-word characters.
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7182 * But keep white space. We need a copy, the word may be changed here. */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7183 if (slang->sl_rem_accents)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7184 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7185 t = word;
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7186 while (*s != NUL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7187 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
7188 if (vim_iswhite(*s))
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7189 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7190 *t++ = ' ';
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7191 s = skipwhite(s);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7192 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7193 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7194 {
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
7195 if (spell_iswordp_nmw(s, curwin))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7196 *t++ = *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7197 ++s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7198 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7199 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7200 *t = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7201 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7202 else
2768
c5e47b752f07 updated for version 7.3.160
Bram Moolenaar <bram@vim.org>
parents: 2691
diff changeset
7203 vim_strncpy(word, s, MAXWLEN - 1);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7204
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7205 smp = (salitem_T *)slang->sl_sal.ga_data;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7206
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7207 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7208 * This comes from Aspell phonet.cpp. Converted from C++ to C.
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
7209 * Changed to keep spaces.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7210 */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7211 i = reslen = z = 0;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7212 while ((c = word[i]) != NUL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7213 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7214 /* Start with the first rule that has the character in the word. */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7215 n = slang->sl_sal_first[c];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7216 z0 = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7217
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7218 if (n >= 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7219 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7220 /* check all rules for the same letter */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7221 for (; (s = smp[n].sm_lead)[0] == c; ++n)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7222 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7223 /* Quickly skip entries that don't match the word. Most
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7224 * entries are less then three chars, optimize for that. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7225 k = smp[n].sm_leadlen;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7226 if (k > 1)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7227 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7228 if (word[i + 1] != s[1])
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7229 continue;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7230 if (k > 2)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7231 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7232 for (j = 2; j < k; ++j)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7233 if (word[i + j] != s[j])
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7234 break;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7235 if (j < k)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7236 continue;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7237 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7238 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7239
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7240 if ((pf = smp[n].sm_oneof) != NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7241 {
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7242 /* Check for match with one of the chars in "sm_oneof". */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7243 while (*pf != NUL && *pf != word[i + k])
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7244 ++pf;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7245 if (*pf == NUL)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7246 continue;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7247 ++k;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7248 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7249 s = smp[n].sm_rules;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7250 pri = 5; /* default priority */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7251
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7252 p0 = *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7253 k0 = k;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7254 while (*s == '-' && k > 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7255 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7256 k--;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7257 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7258 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7259 if (*s == '<')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7260 s++;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7261 if (VIM_ISDIGIT(*s))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7262 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7263 /* determine priority */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7264 pri = *s - '0';
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7265 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7266 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7267 if (*s == '^' && *(s + 1) == '^')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7268 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7269
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7270 if (*s == NUL
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7271 || (*s == '^'
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
7272 && (i == 0 || !(word[i - 1] == ' '
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
7273 || spell_iswordp(word + i - 1, curwin)))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7274 && (*(s + 1) != '$'
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
7275 || (!spell_iswordp(word + i + k0, curwin))))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7276 || (*s == '$' && i > 0
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
7277 && spell_iswordp(word + i - 1, curwin)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
7278 && (!spell_iswordp(word + i + k0, curwin))))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7279 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7280 /* search for followup rules, if: */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7281 /* followup and k > 1 and NO '-' in searchstring */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7282 c0 = word[i + k - 1];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7283 n0 = slang->sl_sal_first[c0];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7284
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7285 if (slang->sl_followup && k > 1 && n0 >= 0
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7286 && p0 != '-' && word[i + k] != NUL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7287 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7288 /* test follow-up rule for "word[i + k]" */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7289 for ( ; (s = smp[n0].sm_lead)[0] == c0; ++n0)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7290 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7291 /* Quickly skip entries that don't match the word.
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7292 * */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7293 k0 = smp[n0].sm_leadlen;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7294 if (k0 > 1)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7295 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7296 if (word[i + k] != s[1])
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7297 continue;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7298 if (k0 > 2)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7299 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7300 pf = word + i + k + 1;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7301 for (j = 2; j < k0; ++j)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7302 if (*pf++ != s[j])
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7303 break;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7304 if (j < k0)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7305 continue;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7306 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7307 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7308 k0 += k - 1;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7309
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7310 if ((pf = smp[n0].sm_oneof) != NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7311 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7312 /* Check for match with one of the chars in
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7313 * "sm_oneof". */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7314 while (*pf != NUL && *pf != word[i + k0])
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7315 ++pf;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7316 if (*pf == NUL)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7317 continue;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7318 ++k0;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7319 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7320
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7321 p0 = 5;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7322 s = smp[n0].sm_rules;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7323 while (*s == '-')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7324 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7325 /* "k0" gets NOT reduced because
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7326 * "if (k0 == k)" */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7327 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7328 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7329 if (*s == '<')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7330 s++;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7331 if (VIM_ISDIGIT(*s))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7332 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7333 p0 = *s - '0';
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7334 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7335 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7336
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7337 if (*s == NUL
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7338 /* *s == '^' cuts */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7339 || (*s == '$'
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
7340 && !spell_iswordp(word + i + k0,
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
7341 curwin)))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7342 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7343 if (k0 == k)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7344 /* this is just a piece of the string */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7345 continue;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7346
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7347 if (p0 < pri)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7348 /* priority too low */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7349 continue;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7350 /* rule fits; stop search */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7351 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7352 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7353 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7354
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7355 if (p0 >= pri && smp[n0].sm_lead[0] == c0)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7356 continue;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7357 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7358
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7359 /* replace string */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7360 s = smp[n].sm_to;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7361 if (s == NULL)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7362 s = (char_u *)"";
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7363 pf = smp[n].sm_rules;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7364 p0 = (vim_strchr(pf, '<') != NULL) ? 1 : 0;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7365 if (p0 == 1 && z == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7366 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7367 /* rule with '<' is used */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7368 if (reslen > 0 && *s != NUL && (res[reslen - 1] == c
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7369 || res[reslen - 1] == *s))
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7370 reslen--;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7371 z0 = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7372 z = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7373 k0 = 0;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7374 while (*s != NUL && word[i + k0] != NUL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7375 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7376 word[i + k0] = *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7377 k0++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7378 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7379 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7380 if (k > k0)
1619
b9740fb41986 updated for version 7.2a
vimboss
parents: 1580
diff changeset
7381 STRMOVE(word + i + k0, word + i + k);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7382
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7383 /* new "actual letter" */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7384 c = word[i];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7385 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7386 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7387 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7388 /* no '<' rule used */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7389 i += k - 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7390 z = 0;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7391 while (*s != NUL && s[1] != NUL && reslen < MAXWLEN)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7392 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7393 if (reslen == 0 || res[reslen - 1] != *s)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7394 res[reslen++] = *s;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7395 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7396 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7397 /* new "actual letter" */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7398 c = *s;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7399 if (strstr((char *)pf, "^^") != NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7400 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7401 if (c != NUL)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7402 res[reslen++] = c;
1619
b9740fb41986 updated for version 7.2a
vimboss
parents: 1580
diff changeset
7403 STRMOVE(word, word + i + 1);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7404 i = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7405 z0 = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7406 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7407 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7408 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7409 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7410 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7411 }
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
7412 else if (vim_iswhite(c))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
7413 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
7414 c = ' ';
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
7415 k = 1;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
7416 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7417
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7418 if (z0 == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7419 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7420 if (k && !p0 && reslen < MAXWLEN && c != NUL
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7421 && (!slang->sl_collapse || reslen == 0
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7422 || res[reslen - 1] != c))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7423 /* condense only double letters */
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7424 res[reslen++] = c;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7425
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7426 i++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7427 z = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7428 k = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7429 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7430 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7431
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7432 res[reslen] = NUL;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7433 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7434
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7435 #ifdef FEAT_MBYTE
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7436 /*
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7437 * Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]".
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7438 * Multi-byte version of spell_soundfold().
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7439 */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7440 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7441 spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7442 {
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7443 salitem_T *smp = (salitem_T *)slang->sl_sal.ga_data;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7444 int word[MAXWLEN];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7445 int wres[MAXWLEN];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7446 int l;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7447 char_u *s;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7448 int *ws;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7449 char_u *t;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7450 int *pf;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7451 int i, j, z;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7452 int reslen;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7453 int n, k = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7454 int z0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7455 int k0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7456 int n0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7457 int c;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7458 int pri;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7459 int p0 = -333;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7460 int c0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7461 int did_white = FALSE;
3520
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
7462 int wordlen;
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
7463
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7464
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7465 /*
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7466 * Convert the multi-byte string to a wide-character string.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7467 * Remove accents, if wanted. We actually remove all non-word characters.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7468 * But keep white space.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7469 */
3520
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
7470 wordlen = 0;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7471 for (s = inword; *s != NUL; )
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7472 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7473 t = s;
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
7474 c = mb_cptr2char_adv(&s);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7475 if (slang->sl_rem_accents)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7476 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7477 if (enc_utf8 ? utf_class(c) == 0 : vim_iswhite(c))
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7478 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7479 if (did_white)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7480 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7481 c = ' ';
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7482 did_white = TRUE;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7483 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7484 else
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7485 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7486 did_white = FALSE;
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
7487 if (!spell_iswordp_nmw(t, curwin))
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7488 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7489 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7490 }
3520
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
7491 word[wordlen++] = c;
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
7492 }
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
7493 word[wordlen] = NUL;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7494
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7495 /*
3520
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
7496 * This algorithm comes from Aspell phonet.cpp.
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7497 * Converted from C++ to C. Added support for multi-byte chars.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7498 * Changed to keep spaces.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7499 */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7500 i = reslen = z = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7501 while ((c = word[i]) != NUL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7502 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7503 /* Start with the first rule that has the character in the word. */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7504 n = slang->sl_sal_first[c & 0xff];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7505 z0 = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7506
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7507 if (n >= 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7508 {
2455
9367de3e2e1b Fix: crash in spell checking with a 0x300 character.
Bram Moolenaar <bram@vim.org>
parents: 2454
diff changeset
7509 /* Check all rules for the same index byte.
9367de3e2e1b Fix: crash in spell checking with a 0x300 character.
Bram Moolenaar <bram@vim.org>
parents: 2454
diff changeset
7510 * If c is 0x300 need extra check for the end of the array, as
9367de3e2e1b Fix: crash in spell checking with a 0x300 character.
Bram Moolenaar <bram@vim.org>
parents: 2454
diff changeset
7511 * (c & 0xff) is NUL. */
9367de3e2e1b Fix: crash in spell checking with a 0x300 character.
Bram Moolenaar <bram@vim.org>
parents: 2454
diff changeset
7512 for (; ((ws = smp[n].sm_lead_w)[0] & 0xff) == (c & 0xff)
9367de3e2e1b Fix: crash in spell checking with a 0x300 character.
Bram Moolenaar <bram@vim.org>
parents: 2454
diff changeset
7513 && ws[0] != NUL; ++n)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7514 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7515 /* Quickly skip entries that don't match the word. Most
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7516 * entries are less then three chars, optimize for that. */
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7517 if (c != ws[0])
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7518 continue;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7519 k = smp[n].sm_leadlen;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7520 if (k > 1)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7521 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7522 if (word[i + 1] != ws[1])
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7523 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7524 if (k > 2)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7525 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7526 for (j = 2; j < k; ++j)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7527 if (word[i + j] != ws[j])
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7528 break;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7529 if (j < k)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7530 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7531 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7532 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7533
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7534 if ((pf = smp[n].sm_oneof_w) != NULL)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7535 {
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7536 /* Check for match with one of the chars in "sm_oneof". */
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7537 while (*pf != NUL && *pf != word[i + k])
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7538 ++pf;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7539 if (*pf == NUL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7540 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7541 ++k;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7542 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7543 s = smp[n].sm_rules;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7544 pri = 5; /* default priority */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7545
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7546 p0 = *s;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7547 k0 = k;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7548 while (*s == '-' && k > 1)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7549 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7550 k--;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7551 s++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7552 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7553 if (*s == '<')
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7554 s++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7555 if (VIM_ISDIGIT(*s))
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7556 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7557 /* determine priority */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7558 pri = *s - '0';
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7559 s++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7560 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7561 if (*s == '^' && *(s + 1) == '^')
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7562 s++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7563
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7564 if (*s == NUL
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7565 || (*s == '^'
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7566 && (i == 0 || !(word[i - 1] == ' '
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
7567 || spell_iswordp_w(word + i - 1, curwin)))
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7568 && (*(s + 1) != '$'
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
7569 || (!spell_iswordp_w(word + i + k0, curwin))))
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7570 || (*s == '$' && i > 0
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
7571 && spell_iswordp_w(word + i - 1, curwin)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
7572 && (!spell_iswordp_w(word + i + k0, curwin))))
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7573 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7574 /* search for followup rules, if: */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7575 /* followup and k > 1 and NO '-' in searchstring */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7576 c0 = word[i + k - 1];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7577 n0 = slang->sl_sal_first[c0 & 0xff];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7578
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7579 if (slang->sl_followup && k > 1 && n0 >= 0
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7580 && p0 != '-' && word[i + k] != NUL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7581 {
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7582 /* Test follow-up rule for "word[i + k]"; loop over
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7583 * all entries with the same index byte. */
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7584 for ( ; ((ws = smp[n0].sm_lead_w)[0] & 0xff)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7585 == (c0 & 0xff); ++n0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7586 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7587 /* Quickly skip entries that don't match the word.
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7588 */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7589 if (c0 != ws[0])
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7590 continue;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7591 k0 = smp[n0].sm_leadlen;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7592 if (k0 > 1)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7593 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7594 if (word[i + k] != ws[1])
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7595 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7596 if (k0 > 2)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7597 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7598 pf = word + i + k + 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7599 for (j = 2; j < k0; ++j)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7600 if (*pf++ != ws[j])
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7601 break;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7602 if (j < k0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7603 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7604 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7605 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7606 k0 += k - 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7607
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7608 if ((pf = smp[n0].sm_oneof_w) != NULL)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7609 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7610 /* Check for match with one of the chars in
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
7611 * "sm_oneof". */
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7612 while (*pf != NUL && *pf != word[i + k0])
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7613 ++pf;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7614 if (*pf == NUL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7615 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7616 ++k0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7617 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7618
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7619 p0 = 5;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7620 s = smp[n0].sm_rules;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7621 while (*s == '-')
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7622 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7623 /* "k0" gets NOT reduced because
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7624 * "if (k0 == k)" */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7625 s++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7626 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7627 if (*s == '<')
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7628 s++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7629 if (VIM_ISDIGIT(*s))
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7630 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7631 p0 = *s - '0';
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7632 s++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7633 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7634
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7635 if (*s == NUL
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7636 /* *s == '^' cuts */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7637 || (*s == '$'
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
7638 && !spell_iswordp_w(word + i + k0,
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
7639 curwin)))
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7640 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7641 if (k0 == k)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7642 /* this is just a piece of the string */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7643 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7644
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7645 if (p0 < pri)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7646 /* priority too low */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7647 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7648 /* rule fits; stop search */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7649 break;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7650 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7651 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7652
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7653 if (p0 >= pri && (smp[n0].sm_lead_w[0] & 0xff)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7654 == (c0 & 0xff))
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7655 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7656 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7657
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7658 /* replace string */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7659 ws = smp[n].sm_to_w;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7660 s = smp[n].sm_rules;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7661 p0 = (vim_strchr(s, '<') != NULL) ? 1 : 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7662 if (p0 == 1 && z == 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7663 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7664 /* rule with '<' is used */
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7665 if (reslen > 0 && ws != NULL && *ws != NUL
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7666 && (wres[reslen - 1] == c
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7667 || wres[reslen - 1] == *ws))
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7668 reslen--;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7669 z0 = 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7670 z = 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7671 k0 = 0;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7672 if (ws != NULL)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7673 while (*ws != NUL && word[i + k0] != NUL)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7674 {
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7675 word[i + k0] = *ws;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7676 k0++;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7677 ws++;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7678 }
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7679 if (k > k0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7680 mch_memmove(word + i + k0, word + i + k,
3520
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
7681 sizeof(int) * (wordlen - (i + k) + 1));
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7682
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7683 /* new "actual letter" */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7684 c = word[i];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7685 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7686 else
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7687 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7688 /* no '<' rule used */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7689 i += k - 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7690 z = 0;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7691 if (ws != NULL)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7692 while (*ws != NUL && ws[1] != NUL
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7693 && reslen < MAXWLEN)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7694 {
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7695 if (reslen == 0 || wres[reslen - 1] != *ws)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7696 wres[reslen++] = *ws;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7697 ws++;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7698 }
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7699 /* new "actual letter" */
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7700 if (ws == NULL)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7701 c = NUL;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7702 else
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
7703 c = *ws;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7704 if (strstr((char *)s, "^^") != NULL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7705 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7706 if (c != NUL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7707 wres[reslen++] = c;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7708 mch_memmove(word, word + i + 1,
3520
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
7709 sizeof(int) * (wordlen - (i + 1) + 1));
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7710 i = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7711 z0 = 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7712 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7713 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7714 break;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7715 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7716 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7717 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7718 else if (vim_iswhite(c))
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7719 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7720 c = ' ';
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7721 k = 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7722 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7723
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7724 if (z0 == 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7725 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7726 if (k && !p0 && reslen < MAXWLEN && c != NUL
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7727 && (!slang->sl_collapse || reslen == 0
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7728 || wres[reslen - 1] != c))
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7729 /* condense only double letters */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7730 wres[reslen++] = c;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7731
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7732 i++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7733 z = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7734 k = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7735 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7736 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7737
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7738 /* Convert wide characters in "wres" to a multi-byte string in "res". */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7739 l = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7740 for (n = 0; n < reslen; ++n)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7741 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7742 l += mb_char2bytes(wres[n], res + l);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7743 if (l + MB_MAXBYTES > MAXWLEN)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7744 break;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7745 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7746 res[l] = NUL;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7747 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7748 #endif
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
7749
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
7750 /*
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7751 * Compute a score for two sound-a-like words.
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7752 * This permits up to two inserts/deletes/swaps/etc. to keep things fast.
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7753 * Instead of a generic loop we write out the code. That keeps it fast by
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7754 * avoiding checks that will not be possible.
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7755 */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7756 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7757 soundalike_score(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7758 char_u *goodstart, /* sound-folded good word */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7759 char_u *badstart) /* sound-folded bad word */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7760 {
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7761 char_u *goodsound = goodstart;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7762 char_u *badsound = badstart;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7763 int goodlen;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7764 int badlen;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7765 int n;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7766 char_u *pl, *ps;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7767 char_u *pl2, *ps2;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7768 int score = 0;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7769
2454
91fec91a522c Fix: uninitialized memory access. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents: 2445
diff changeset
7770 /* Adding/inserting "*" at the start (word starts with vowel) shouldn't be
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7771 * counted so much, vowels halfway the word aren't counted at all. */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7772 if ((*badsound == '*' || *goodsound == '*') && *badsound != *goodsound)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7773 {
2454
91fec91a522c Fix: uninitialized memory access. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents: 2445
diff changeset
7774 if ((badsound[0] == NUL && goodsound[1] == NUL)
91fec91a522c Fix: uninitialized memory access. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents: 2445
diff changeset
7775 || (goodsound[0] == NUL && badsound[1] == NUL))
91fec91a522c Fix: uninitialized memory access. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents: 2445
diff changeset
7776 /* changing word with vowel to word without a sound */
91fec91a522c Fix: uninitialized memory access. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents: 2445
diff changeset
7777 return SCORE_DEL;
91fec91a522c Fix: uninitialized memory access. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents: 2445
diff changeset
7778 if (badsound[0] == NUL || goodsound[0] == NUL)
91fec91a522c Fix: uninitialized memory access. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents: 2445
diff changeset
7779 /* more than two changes */
91fec91a522c Fix: uninitialized memory access. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents: 2445
diff changeset
7780 return SCORE_MAXMAX;
91fec91a522c Fix: uninitialized memory access. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents: 2445
diff changeset
7781
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
7782 if (badsound[1] == goodsound[1]
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
7783 || (badsound[1] != NUL
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
7784 && goodsound[1] != NUL
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
7785 && badsound[2] == goodsound[2]))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
7786 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
7787 /* handle like a substitute */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
7788 }
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7789 else
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
7790 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
7791 score = 2 * SCORE_DEL / 3;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
7792 if (*badsound == '*')
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
7793 ++badsound;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
7794 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
7795 ++goodsound;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
7796 }
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7797 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7798
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
7799 goodlen = (int)STRLEN(goodsound);
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
7800 badlen = (int)STRLEN(badsound);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7801
1188
2a276274c592 updated for version 7.1b
vimboss
parents: 1185
diff changeset
7802 /* Return quickly if the lengths are too different to be fixed by two
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7803 * changes. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7804 n = goodlen - badlen;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7805 if (n < -2 || n > 2)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7806 return SCORE_MAXMAX;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7807
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7808 if (n > 0)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7809 {
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7810 pl = goodsound; /* goodsound is longest */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7811 ps = badsound;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7812 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7813 else
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7814 {
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7815 pl = badsound; /* badsound is longest */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7816 ps = goodsound;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7817 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7818
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7819 /* Skip over the identical part. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7820 while (*pl == *ps && *pl != NUL)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7821 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7822 ++pl;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7823 ++ps;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7824 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7825
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7826 switch (n)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7827 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7828 case -2:
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7829 case 2:
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7830 /*
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7831 * Must delete two characters from "pl".
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7832 */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7833 ++pl; /* first delete */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7834 while (*pl == *ps)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7835 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7836 ++pl;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7837 ++ps;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7838 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7839 /* strings must be equal after second delete */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7840 if (STRCMP(pl + 1, ps) == 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7841 return score + SCORE_DEL * 2;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7842
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7843 /* Failed to compare. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7844 break;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7845
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7846 case -1:
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7847 case 1:
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7848 /*
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7849 * Minimal one delete from "pl" required.
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7850 */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7851
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7852 /* 1: delete */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7853 pl2 = pl + 1;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7854 ps2 = ps;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7855 while (*pl2 == *ps2)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7856 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7857 if (*pl2 == NUL) /* reached the end */
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7858 return score + SCORE_DEL;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7859 ++pl2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7860 ++ps2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7861 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7862
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7863 /* 2: delete then swap, then rest must be equal */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7864 if (pl2[0] == ps2[1] && pl2[1] == ps2[0]
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7865 && STRCMP(pl2 + 2, ps2 + 2) == 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7866 return score + SCORE_DEL + SCORE_SWAP;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7867
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7868 /* 3: delete then substitute, then the rest must be equal */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7869 if (STRCMP(pl2 + 1, ps2 + 1) == 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7870 return score + SCORE_DEL + SCORE_SUBST;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7871
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7872 /* 4: first swap then delete */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7873 if (pl[0] == ps[1] && pl[1] == ps[0])
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7874 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7875 pl2 = pl + 2; /* swap, skip two chars */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7876 ps2 = ps + 2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7877 while (*pl2 == *ps2)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7878 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7879 ++pl2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7880 ++ps2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7881 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7882 /* delete a char and then strings must be equal */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7883 if (STRCMP(pl2 + 1, ps2) == 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7884 return score + SCORE_SWAP + SCORE_DEL;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7885 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7886
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7887 /* 5: first substitute then delete */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7888 pl2 = pl + 1; /* substitute, skip one char */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7889 ps2 = ps + 1;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7890 while (*pl2 == *ps2)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7891 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7892 ++pl2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7893 ++ps2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7894 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7895 /* delete a char and then strings must be equal */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7896 if (STRCMP(pl2 + 1, ps2) == 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7897 return score + SCORE_SUBST + SCORE_DEL;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7898
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7899 /* Failed to compare. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7900 break;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7901
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7902 case 0:
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7903 /*
1808
e2d7622d7089 updated for version 7.2-106
vimboss
parents: 1771
diff changeset
7904 * Lengths are equal, thus changes must result in same length: An
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7905 * insert is only possible in combination with a delete.
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7906 * 1: check if for identical strings
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7907 */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7908 if (*pl == NUL)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7909 return score;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7910
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7911 /* 2: swap */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7912 if (pl[0] == ps[1] && pl[1] == ps[0])
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7913 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7914 pl2 = pl + 2; /* swap, skip two chars */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7915 ps2 = ps + 2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7916 while (*pl2 == *ps2)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7917 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7918 if (*pl2 == NUL) /* reached the end */
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7919 return score + SCORE_SWAP;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7920 ++pl2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7921 ++ps2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7922 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7923 /* 3: swap and swap again */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7924 if (pl2[0] == ps2[1] && pl2[1] == ps2[0]
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7925 && STRCMP(pl2 + 2, ps2 + 2) == 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7926 return score + SCORE_SWAP + SCORE_SWAP;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7927
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7928 /* 4: swap and substitute */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7929 if (STRCMP(pl2 + 1, ps2 + 1) == 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7930 return score + SCORE_SWAP + SCORE_SUBST;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7931 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7932
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7933 /* 5: substitute */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7934 pl2 = pl + 1;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7935 ps2 = ps + 1;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7936 while (*pl2 == *ps2)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7937 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7938 if (*pl2 == NUL) /* reached the end */
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7939 return score + SCORE_SUBST;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7940 ++pl2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7941 ++ps2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7942 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7943
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7944 /* 6: substitute and swap */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7945 if (pl2[0] == ps2[1] && pl2[1] == ps2[0]
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7946 && STRCMP(pl2 + 2, ps2 + 2) == 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7947 return score + SCORE_SUBST + SCORE_SWAP;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7948
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7949 /* 7: substitute and substitute */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7950 if (STRCMP(pl2 + 1, ps2 + 1) == 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7951 return score + SCORE_SUBST + SCORE_SUBST;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7952
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7953 /* 8: insert then delete */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7954 pl2 = pl;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7955 ps2 = ps + 1;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7956 while (*pl2 == *ps2)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7957 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7958 ++pl2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7959 ++ps2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7960 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7961 if (STRCMP(pl2 + 1, ps2) == 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7962 return score + SCORE_INS + SCORE_DEL;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7963
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7964 /* 9: delete then insert */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7965 pl2 = pl + 1;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7966 ps2 = ps;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7967 while (*pl2 == *ps2)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7968 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7969 ++pl2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7970 ++ps2;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7971 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7972 if (STRCMP(pl2, ps2 + 1) == 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
7973 return score + SCORE_INS + SCORE_DEL;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7974
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7975 /* Failed to compare. */
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7976 break;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7977 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7978
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7979 return SCORE_MAXMAX;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7980 }
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
7981
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7982 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7983 * Compute the "edit distance" to turn "badword" into "goodword". The less
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
7984 * deletes/inserts/substitutes/swaps are required the lower the score.
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
7985 *
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
7986 * The algorithm is described by Du and Chang, 1992.
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
7987 * The implementation of the algorithm comes from Aspell editdist.cpp,
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
7988 * edit_distance(). It has been converted from C++ to C and modified to
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
7989 * support multi-byte characters.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7990 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7991 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7992 spell_edit_score(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7993 slang_T *slang,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7994 char_u *badword,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
7995 char_u *goodword)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7996 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7997 int *cnt;
1188
2a276274c592 updated for version 7.1b
vimboss
parents: 1185
diff changeset
7998 int badlen, goodlen; /* lengths including NUL */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
7999 int j, i;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8000 int t;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8001 int bc, gc;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8002 int pbc, pgc;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8003 #ifdef FEAT_MBYTE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8004 char_u *p;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8005 int wbadword[MAXWLEN];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8006 int wgoodword[MAXWLEN];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8007
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8008 if (has_mbyte)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8009 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8010 /* Get the characters from the multi-byte strings and put them in an
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8011 * int array for easy access. */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8012 for (p = badword, badlen = 0; *p != NUL; )
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
8013 wbadword[badlen++] = mb_cptr2char_adv(&p);
398
d5dbe17efce2 updated for version 7.0105
vimboss
parents: 393
diff changeset
8014 wbadword[badlen++] = 0;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8015 for (p = goodword, goodlen = 0; *p != NUL; )
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
8016 wgoodword[goodlen++] = mb_cptr2char_adv(&p);
398
d5dbe17efce2 updated for version 7.0105
vimboss
parents: 393
diff changeset
8017 wgoodword[goodlen++] = 0;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8018 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8019 else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8020 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8021 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
8022 badlen = (int)STRLEN(badword) + 1;
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
8023 goodlen = (int)STRLEN(goodword) + 1;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8024 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8025
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8026 /* We use "cnt" as an array: CNT(badword_idx, goodword_idx). */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8027 #define CNT(a, b) cnt[(a) + (b) * (badlen + 1)]
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8028 cnt = (int *)lalloc((long_u)(sizeof(int) * (badlen + 1) * (goodlen + 1)),
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8029 TRUE);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8030 if (cnt == NULL)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8031 return 0; /* out of memory */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8032
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8033 CNT(0, 0) = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8034 for (j = 1; j <= goodlen; ++j)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8035 CNT(0, j) = CNT(0, j - 1) + SCORE_INS;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8036
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8037 for (i = 1; i <= badlen; ++i)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8038 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8039 CNT(i, 0) = CNT(i - 1, 0) + SCORE_DEL;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8040 for (j = 1; j <= goodlen; ++j)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8041 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8042 #ifdef FEAT_MBYTE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8043 if (has_mbyte)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8044 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8045 bc = wbadword[i - 1];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8046 gc = wgoodword[j - 1];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8047 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8048 else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8049 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8050 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8051 bc = badword[i - 1];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8052 gc = goodword[j - 1];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8053 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8054 if (bc == gc)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8055 CNT(i, j) = CNT(i - 1, j - 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8056 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8057 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8058 /* Use a better score when there is only a case difference. */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8059 if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8060 CNT(i, j) = SCORE_ICASE + CNT(i - 1, j - 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8061 else
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8062 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8063 /* For a similar character use SCORE_SIMILAR. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8064 if (slang != NULL
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8065 && slang->sl_has_map
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8066 && similar_chars(slang, gc, bc))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8067 CNT(i, j) = SCORE_SIMILAR + CNT(i - 1, j - 1);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8068 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8069 CNT(i, j) = SCORE_SUBST + CNT(i - 1, j - 1);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8070 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8071
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8072 if (i > 1 && j > 1)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8073 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8074 #ifdef FEAT_MBYTE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8075 if (has_mbyte)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8076 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8077 pbc = wbadword[i - 2];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8078 pgc = wgoodword[j - 2];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8079 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8080 else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8081 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8082 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8083 pbc = badword[i - 2];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8084 pgc = goodword[j - 2];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8085 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8086 if (bc == pgc && pbc == gc)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8087 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8088 t = SCORE_SWAP + CNT(i - 2, j - 2);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8089 if (t < CNT(i, j))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8090 CNT(i, j) = t;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
8091 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8092 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8093 t = SCORE_DEL + CNT(i - 1, j);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8094 if (t < CNT(i, j))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8095 CNT(i, j) = t;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8096 t = SCORE_INS + CNT(i, j - 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8097 if (t < CNT(i, j))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8098 CNT(i, j) = t;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8099 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8100 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8101 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
8102
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
8103 i = CNT(badlen - 1, goodlen - 1);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
8104 vim_free(cnt);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
8105 return i;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
8106 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
8107
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8108 typedef struct
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8109 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8110 int badi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8111 int goodi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8112 int score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8113 } limitscore_T;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8114
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8115 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8116 * Like spell_edit_score(), but with a limit on the score to make it faster.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8117 * May return SCORE_MAXMAX when the score is higher than "limit".
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8118 *
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8119 * This uses a stack for the edits still to be tried.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8120 * The idea comes from Aspell leditdist.cpp. Rewritten in C and added support
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8121 * for multi-byte characters.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8122 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8123 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8124 spell_edit_score_limit(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8125 slang_T *slang,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8126 char_u *badword,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8127 char_u *goodword,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8128 int limit)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8129 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8130 limitscore_T stack[10]; /* allow for over 3 * 2 edits */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8131 int stackidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8132 int bi, gi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8133 int bi2, gi2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8134 int bc, gc;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8135 int score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8136 int score_off;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8137 int minscore;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8138 int round;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8139
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8140 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8141 /* Multi-byte characters require a bit more work, use a different function
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8142 * to avoid testing "has_mbyte" quite often. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8143 if (has_mbyte)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8144 return spell_edit_score_limit_w(slang, badword, goodword, limit);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8145 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8146
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8147 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8148 * The idea is to go from start to end over the words. So long as
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8149 * characters are equal just continue, this always gives the lowest score.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8150 * When there is a difference try several alternatives. Each alternative
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8151 * increases "score" for the edit distance. Some of the alternatives are
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8152 * pushed unto a stack and tried later, some are tried right away. At the
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8153 * end of the word the score for one alternative is known. The lowest
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8154 * possible score is stored in "minscore".
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8155 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8156 stackidx = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8157 bi = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8158 gi = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8159 score = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8160 minscore = limit + 1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8161
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8162 for (;;)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8163 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8164 /* Skip over an equal part, score remains the same. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8165 for (;;)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8166 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8167 bc = badword[bi];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8168 gc = goodword[gi];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8169 if (bc != gc) /* stop at a char that's different */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8170 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8171 if (bc == NUL) /* both words end */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8172 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8173 if (score < minscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8174 minscore = score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8175 goto pop; /* do next alternative */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8176 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8177 ++bi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8178 ++gi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8179 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8180
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8181 if (gc == NUL) /* goodword ends, delete badword chars */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8182 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8183 do
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8184 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8185 if ((score += SCORE_DEL) >= minscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8186 goto pop; /* do next alternative */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8187 } while (badword[++bi] != NUL);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8188 minscore = score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8189 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8190 else if (bc == NUL) /* badword ends, insert badword chars */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8191 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8192 do
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8193 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8194 if ((score += SCORE_INS) >= minscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8195 goto pop; /* do next alternative */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8196 } while (goodword[++gi] != NUL);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8197 minscore = score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8198 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8199 else /* both words continue */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8200 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8201 /* If not close to the limit, perform a change. Only try changes
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8202 * that may lead to a lower score than "minscore".
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8203 * round 0: try deleting a char from badword
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8204 * round 1: try inserting a char in badword */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8205 for (round = 0; round <= 1; ++round)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8206 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8207 score_off = score + (round == 0 ? SCORE_DEL : SCORE_INS);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8208 if (score_off < minscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8209 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8210 if (score_off + SCORE_EDIT_MIN >= minscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8211 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8212 /* Near the limit, rest of the words must match. We
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8213 * can check that right now, no need to push an item
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8214 * onto the stack. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8215 bi2 = bi + 1 - round;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8216 gi2 = gi + round;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8217 while (goodword[gi2] == badword[bi2])
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8218 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8219 if (goodword[gi2] == NUL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8220 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8221 minscore = score_off;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8222 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8223 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8224 ++bi2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8225 ++gi2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8226 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8227 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8228 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8229 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8230 /* try deleting/inserting a character later */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8231 stack[stackidx].badi = bi + 1 - round;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8232 stack[stackidx].goodi = gi + round;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8233 stack[stackidx].score = score_off;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8234 ++stackidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8235 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8236 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8237 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8238
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8239 if (score + SCORE_SWAP < minscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8240 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8241 /* If swapping two characters makes a match then the
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8242 * substitution is more expensive, thus there is no need to
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8243 * try both. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8244 if (gc == badword[bi + 1] && bc == goodword[gi + 1])
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8245 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8246 /* Swap two characters, that is: skip them. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8247 gi += 2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8248 bi += 2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8249 score += SCORE_SWAP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8250 continue;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8251 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8252 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8253
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8254 /* Substitute one character for another which is the same
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8255 * thing as deleting a character from both goodword and badword.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8256 * Use a better score when there is only a case difference. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8257 if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8258 score += SCORE_ICASE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8259 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8260 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8261 /* For a similar character use SCORE_SIMILAR. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8262 if (slang != NULL
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8263 && slang->sl_has_map
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8264 && similar_chars(slang, gc, bc))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8265 score += SCORE_SIMILAR;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8266 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8267 score += SCORE_SUBST;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8268 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8269
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8270 if (score < minscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8271 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8272 /* Do the substitution. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8273 ++gi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8274 ++bi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8275 continue;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8276 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8277 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8278 pop:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8279 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8280 * Get here to try the next alternative, pop it from the stack.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8281 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8282 if (stackidx == 0) /* stack is empty, finished */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8283 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8284
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8285 /* pop an item from the stack */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8286 --stackidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8287 gi = stack[stackidx].goodi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8288 bi = stack[stackidx].badi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8289 score = stack[stackidx].score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8290 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8291
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8292 /* When the score goes over "limit" it may actually be much higher.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8293 * Return a very large number to avoid going below the limit when giving a
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8294 * bonus. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8295 if (minscore > limit)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8296 return SCORE_MAXMAX;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8297 return minscore;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8298 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8299
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8300 #ifdef FEAT_MBYTE
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8301 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8302 * Multi-byte version of spell_edit_score_limit().
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8303 * Keep it in sync with the above!
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8304 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8305 static int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8306 spell_edit_score_limit_w(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8307 slang_T *slang,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8308 char_u *badword,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8309 char_u *goodword,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8310 int limit)
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8311 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8312 limitscore_T stack[10]; /* allow for over 3 * 2 edits */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8313 int stackidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8314 int bi, gi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8315 int bi2, gi2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8316 int bc, gc;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8317 int score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8318 int score_off;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8319 int minscore;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8320 int round;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8321 char_u *p;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8322 int wbadword[MAXWLEN];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8323 int wgoodword[MAXWLEN];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8324
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8325 /* Get the characters from the multi-byte strings and put them in an
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8326 * int array for easy access. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8327 bi = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8328 for (p = badword; *p != NUL; )
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8329 wbadword[bi++] = mb_cptr2char_adv(&p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8330 wbadword[bi++] = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8331 gi = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8332 for (p = goodword; *p != NUL; )
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8333 wgoodword[gi++] = mb_cptr2char_adv(&p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8334 wgoodword[gi++] = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8335
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8336 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8337 * The idea is to go from start to end over the words. So long as
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8338 * characters are equal just continue, this always gives the lowest score.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8339 * When there is a difference try several alternatives. Each alternative
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8340 * increases "score" for the edit distance. Some of the alternatives are
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8341 * pushed unto a stack and tried later, some are tried right away. At the
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8342 * end of the word the score for one alternative is known. The lowest
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8343 * possible score is stored in "minscore".
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8344 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8345 stackidx = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8346 bi = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8347 gi = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8348 score = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8349 minscore = limit + 1;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8350
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8351 for (;;)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8352 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8353 /* Skip over an equal part, score remains the same. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8354 for (;;)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8355 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8356 bc = wbadword[bi];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8357 gc = wgoodword[gi];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8358
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8359 if (bc != gc) /* stop at a char that's different */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8360 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8361 if (bc == NUL) /* both words end */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8362 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8363 if (score < minscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8364 minscore = score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8365 goto pop; /* do next alternative */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8366 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8367 ++bi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8368 ++gi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8369 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8370
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8371 if (gc == NUL) /* goodword ends, delete badword chars */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8372 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8373 do
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8374 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8375 if ((score += SCORE_DEL) >= minscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8376 goto pop; /* do next alternative */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8377 } while (wbadword[++bi] != NUL);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8378 minscore = score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8379 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8380 else if (bc == NUL) /* badword ends, insert badword chars */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8381 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8382 do
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8383 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8384 if ((score += SCORE_INS) >= minscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8385 goto pop; /* do next alternative */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8386 } while (wgoodword[++gi] != NUL);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8387 minscore = score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8388 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8389 else /* both words continue */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8390 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8391 /* If not close to the limit, perform a change. Only try changes
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8392 * that may lead to a lower score than "minscore".
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8393 * round 0: try deleting a char from badword
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8394 * round 1: try inserting a char in badword */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8395 for (round = 0; round <= 1; ++round)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8396 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8397 score_off = score + (round == 0 ? SCORE_DEL : SCORE_INS);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8398 if (score_off < minscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8399 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8400 if (score_off + SCORE_EDIT_MIN >= minscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8401 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8402 /* Near the limit, rest of the words must match. We
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8403 * can check that right now, no need to push an item
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8404 * onto the stack. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8405 bi2 = bi + 1 - round;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8406 gi2 = gi + round;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8407 while (wgoodword[gi2] == wbadword[bi2])
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8408 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8409 if (wgoodword[gi2] == NUL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8410 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8411 minscore = score_off;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8412 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8413 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8414 ++bi2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8415 ++gi2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8416 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8417 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8418 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8419 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8420 /* try deleting a character from badword later */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8421 stack[stackidx].badi = bi + 1 - round;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8422 stack[stackidx].goodi = gi + round;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8423 stack[stackidx].score = score_off;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8424 ++stackidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8425 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8426 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8427 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8428
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8429 if (score + SCORE_SWAP < minscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8430 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8431 /* If swapping two characters makes a match then the
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8432 * substitution is more expensive, thus there is no need to
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8433 * try both. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8434 if (gc == wbadword[bi + 1] && bc == wgoodword[gi + 1])
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8435 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8436 /* Swap two characters, that is: skip them. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8437 gi += 2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8438 bi += 2;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8439 score += SCORE_SWAP;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8440 continue;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8441 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8442 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8443
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8444 /* Substitute one character for another which is the same
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8445 * thing as deleting a character from both goodword and badword.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8446 * Use a better score when there is only a case difference. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8447 if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8448 score += SCORE_ICASE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8449 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8450 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8451 /* For a similar character use SCORE_SIMILAR. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8452 if (slang != NULL
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8453 && slang->sl_has_map
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8454 && similar_chars(slang, gc, bc))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8455 score += SCORE_SIMILAR;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8456 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8457 score += SCORE_SUBST;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8458 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8459
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8460 if (score < minscore)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8461 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8462 /* Do the substitution. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8463 ++gi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8464 ++bi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8465 continue;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8466 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8467 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8468 pop:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8469 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8470 * Get here to try the next alternative, pop it from the stack.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8471 */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8472 if (stackidx == 0) /* stack is empty, finished */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8473 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8474
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8475 /* pop an item from the stack */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8476 --stackidx;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8477 gi = stack[stackidx].goodi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8478 bi = stack[stackidx].badi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8479 score = stack[stackidx].score;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8480 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8481
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8482 /* When the score goes over "limit" it may actually be much higher.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8483 * Return a very large number to avoid going below the limit when giving a
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8484 * bonus. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8485 if (minscore > limit)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8486 return SCORE_MAXMAX;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8487 return minscore;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8488 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8489 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8490
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8491 /*
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8492 * ":spellinfo"
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8493 */
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8494 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8495 ex_spellinfo(exarg_T *eap UNUSED)
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8496 {
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8497 int lpi;
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8498 langp_T *lp;
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8499 char_u *p;
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8500
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8501 if (no_spell_checking(curwin))
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8502 return;
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8503
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8504 msg_start();
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
8505 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len && !got_int; ++lpi)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
8506 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
8507 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8508 msg_puts((char_u *)"file: ");
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8509 msg_puts(lp->lp_slang->sl_fname);
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8510 msg_putchar('\n');
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8511 p = lp->lp_slang->sl_info;
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8512 if (p != NULL)
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8513 {
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8514 msg_puts(p);
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8515 msg_putchar('\n');
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8516 }
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8517 }
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8518 msg_end();
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8519 }
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8520
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8521 #define DUMPFLAG_KEEPCASE 1 /* round 2: keep-case tree */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8522 #define DUMPFLAG_COUNT 2 /* include word count */
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8523 #define DUMPFLAG_ICASE 4 /* ignore case when finding matches */
710
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8524 #define DUMPFLAG_ONECAP 8 /* pattern starts with capital */
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8525 #define DUMPFLAG_ALLCAP 16 /* pattern is all capitals */
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8526
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8527 /*
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8528 * ":spelldump"
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8529 */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8530 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8531 ex_spelldump(exarg_T *eap)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8532 {
5382
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
8533 char_u *spl;
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
8534 long dummy;
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
8535
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8536 if (no_spell_checking(curwin))
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8537 return;
5382
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
8538 get_option_value((char_u*)"spl", &dummy, &spl, OPT_LOCAL);
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
8539
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
8540 /* Create a new empty buffer in a new window. */
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8541 do_cmdline_cmd((char_u *)"new");
5382
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
8542
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
8543 /* enable spelling locally in the new window */
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
8544 set_option_value((char_u*)"spell", TRUE, (char_u*)"", OPT_LOCAL);
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 6949
diff changeset
8545 set_option_value((char_u*)"spl", dummy, spl, OPT_LOCAL);
5382
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
8546 vim_free(spl);
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
8547
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
8548 if (!bufempty())
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8549 return;
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8550
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
8551 spell_dump_compl(NULL, 0, NULL, eap->forceit ? DUMPFLAG_COUNT : 0);
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8552
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8553 /* Delete the empty line that we started with. */
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8554 if (curbuf->b_ml.ml_line_count > 1)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8555 ml_delete(curbuf->b_ml.ml_line_count, FALSE);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8556
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8557 redraw_later(NOT_VALID);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8558 }
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8559
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8560 /*
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8561 * Go through all possible words and:
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8562 * 1. When "pat" is NULL: dump a list of all words in the current buffer.
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8563 * "ic" and "dir" are not used.
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8564 * 2. When "pat" is not NULL: add matching words to insert mode completion.
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8565 */
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8566 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8567 spell_dump_compl(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8568 char_u *pat, /* leading part of the word */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8569 int ic, /* ignore case */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8570 int *dir, /* direction for adding matches */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8571 int dumpflags_arg) /* DUMPFLAG_* */
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8572 {
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8573 langp_T *lp;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8574 slang_T *slang;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8575 idx_T arridx[MAXWLEN];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8576 int curi[MAXWLEN];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8577 char_u word[MAXWLEN];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8578 int c;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8579 char_u *byts;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8580 idx_T *idxs;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8581 linenr_T lnum = 0;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8582 int round;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8583 int depth;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8584 int n;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8585 int flags;
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8586 char_u *region_names = NULL; /* region names being used */
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8587 int do_region = TRUE; /* dump region names and numbers */
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8588 char_u *p;
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
8589 int lpi;
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8590 int dumpflags = dumpflags_arg;
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8591 int patlen;
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8592
710
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8593 /* When ignoring case or when the pattern starts with capital pass this on
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8594 * to dump_word(). */
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8595 if (pat != NULL)
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8596 {
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8597 if (ic)
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8598 dumpflags |= DUMPFLAG_ICASE;
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8599 else
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8600 {
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8601 n = captype(pat, NULL);
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8602 if (n == WF_ONECAP)
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8603 dumpflags |= DUMPFLAG_ONECAP;
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8604 else if (n == WF_ALLCAP
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8605 #ifdef FEAT_MBYTE
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8606 && (int)STRLEN(pat) > mb_ptr2len(pat)
710
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8607 #else
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
8608 && (int)STRLEN(pat) > 1
710
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8609 #endif
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8610 )
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8611 dumpflags |= DUMPFLAG_ALLCAP;
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8612 }
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8613 }
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8614
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8615 /* Find out if we can support regions: All languages must support the same
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8616 * regions or none at all. */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
8617 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
8618 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
8619 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8620 p = lp->lp_slang->sl_regions;
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8621 if (p[0] != 0)
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8622 {
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8623 if (region_names == NULL) /* first language with regions */
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8624 region_names = p;
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8625 else if (STRCMP(region_names, p) != 0)
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8626 {
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8627 do_region = FALSE; /* region names are different */
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8628 break;
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8629 }
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8630 }
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8631 }
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8632
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8633 if (do_region && region_names != NULL)
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8634 {
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8635 if (pat == NULL)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8636 {
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8637 vim_snprintf((char *)IObuff, IOSIZE, "/regions=%s", region_names);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8638 ml_append(lnum++, IObuff, (colnr_T)0, FALSE);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8639 }
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8640 }
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8641 else
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8642 do_region = FALSE;
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8643
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8644 /*
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8645 * Loop over all files loaded for the entries in 'spelllang'.
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8646 */
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
8647 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi)
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
8648 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
8649 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8650 slang = lp->lp_slang;
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
8651 if (slang->sl_fbyts == NULL) /* reloading failed */
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
8652 continue;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8653
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8654 if (pat == NULL)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8655 {
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8656 vim_snprintf((char *)IObuff, IOSIZE, "# file: %s", slang->sl_fname);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8657 ml_append(lnum++, IObuff, (colnr_T)0, FALSE);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8658 }
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8659
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8660 /* When matching with a pattern and there are no prefixes only use
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8661 * parts of the tree that match "pat". */
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8662 if (pat != NULL && slang->sl_pbyts == NULL)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
8663 patlen = (int)STRLEN(pat);
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8664 else
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 835
diff changeset
8665 patlen = -1;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8666
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8667 /* round 1: case-folded tree
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8668 * round 2: keep-case tree */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8669 for (round = 1; round <= 2; ++round)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8670 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8671 if (round == 1)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8672 {
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8673 dumpflags &= ~DUMPFLAG_KEEPCASE;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8674 byts = slang->sl_fbyts;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8675 idxs = slang->sl_fidxs;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8676 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8677 else
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8678 {
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8679 dumpflags |= DUMPFLAG_KEEPCASE;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8680 byts = slang->sl_kbyts;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8681 idxs = slang->sl_kidxs;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8682 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8683 if (byts == NULL)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8684 continue; /* array is empty */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8685
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8686 depth = 0;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8687 arridx[0] = 0;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8688 curi[0] = 1;
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8689 while (depth >= 0 && !got_int
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8690 && (pat == NULL || !compl_interrupted))
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8691 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8692 if (curi[depth] > byts[arridx[depth]])
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8693 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8694 /* Done all bytes at this node, go up one level. */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8695 --depth;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8696 line_breakcheck();
10277
154d5a2e7395 commit https://github.com/vim/vim/commit/472e85970ee3a80abd824bef510df12e9cfe9e96
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
8697 ins_compl_check_keys(50, FALSE);
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8698 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8699 else
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8700 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8701 /* Do one more byte at this node. */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8702 n = arridx[depth] + curi[depth];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8703 ++curi[depth];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8704 c = byts[n];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8705 if (c == 0)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8706 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8707 /* End of word, deal with the word.
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8708 * Don't use keep-case words in the fold-case tree,
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8709 * they will appear in the keep-case tree.
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8710 * Only use the word when the region matches. */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8711 flags = (int)idxs[n];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8712 if ((round == 2 || (flags & WF_KEEPCAP) == 0)
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
8713 && (flags & WF_NEEDCOMP) == 0
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8714 && (do_region
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8715 || (flags & WF_REGION) == 0
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
8716 || (((unsigned)flags >> 16)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8717 & lp->lp_region) != 0))
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8718 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8719 word[depth] = NUL;
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8720 if (!do_region)
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8721 flags &= ~WF_REGION;
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
8722
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
8723 /* Dump the basic word if there is no prefix or
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
8724 * when it's the first one. */
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
8725 c = (unsigned)flags >> 24;
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
8726 if (c == 0 || curi[depth] == 2)
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8727 {
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8728 dump_word(slang, word, pat, dir,
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8729 dumpflags, flags, lnum);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8730 if (pat == NULL)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8731 ++lnum;
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8732 }
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8733
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8734 /* Apply the prefix, if there is one. */
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
8735 if (c != 0)
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8736 lnum = dump_prefixes(slang, word, pat, dir,
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8737 dumpflags, flags, lnum);
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8738 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8739 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8740 else
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8741 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8742 /* Normal char, go one level deeper. */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8743 word[depth++] = c;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8744 arridx[depth] = idxs[n];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8745 curi[depth] = 1;
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8746
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8747 /* Check if this characters matches with the pattern.
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8748 * If not skip the whole tree below it.
710
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8749 * Always ignore case here, dump_word() will check
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8750 * proper case later. This isn't exactly right when
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8751 * length changes for multi-byte characters with
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8752 * ignore case... */
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8753 if (depth <= patlen
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8754 && MB_STRNICMP(word, pat, depth) != 0)
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8755 --depth;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8756 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8757 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8758 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8759 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8760 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8761 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8762
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8763 /*
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8764 * Dump one word: apply case modifications and append a line to the buffer.
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8765 * When "lnum" is zero add insert mode completion.
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8766 */
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8767 static void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8768 dump_word(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8769 slang_T *slang,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8770 char_u *word,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8771 char_u *pat,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8772 int *dir,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8773 int dumpflags,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8774 int wordflags,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8775 linenr_T lnum)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8776 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8777 int keepcap = FALSE;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8778 char_u *p;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8779 char_u *tw;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8780 char_u cword[MAXWLEN];
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8781 char_u badword[MAXWLEN + 10];
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
8782 int i;
710
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8783 int flags = wordflags;
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8784
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8785 if (dumpflags & DUMPFLAG_ONECAP)
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8786 flags |= WF_ONECAP;
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8787 if (dumpflags & DUMPFLAG_ALLCAP)
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8788 flags |= WF_ALLCAP;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8789
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8790 if ((dumpflags & DUMPFLAG_KEEPCASE) == 0 && (flags & WF_CAPMASK) != 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8791 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8792 /* Need to fix case according to "flags". */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8793 make_case_word(word, cword, flags);
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8794 p = cword;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8795 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8796 else
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8797 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8798 p = word;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8799 if ((dumpflags & DUMPFLAG_KEEPCASE)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8800 && ((captype(word, NULL) & WF_KEEPCAP) == 0
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
8801 || (flags & WF_FIXCAP) != 0))
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8802 keepcap = TRUE;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8803 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8804 tw = p;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8805
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8806 if (pat == NULL)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8807 {
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8808 /* Add flags and regions after a slash. */
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8809 if ((flags & (WF_BANNED | WF_RARE | WF_REGION)) || keepcap)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8810 {
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8811 STRCPY(badword, p);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8812 STRCAT(badword, "/");
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8813 if (keepcap)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8814 STRCAT(badword, "=");
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8815 if (flags & WF_BANNED)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8816 STRCAT(badword, "!");
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8817 else if (flags & WF_RARE)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8818 STRCAT(badword, "?");
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8819 if (flags & WF_REGION)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8820 for (i = 0; i < 7; ++i)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8821 if (flags & (0x10000 << i))
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8822 sprintf((char *)badword + STRLEN(badword), "%d", i + 1);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8823 p = badword;
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8824 }
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8825
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8826 if (dumpflags & DUMPFLAG_COUNT)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8827 {
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8828 hashitem_T *hi;
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8829
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8830 /* Include the word count for ":spelldump!". */
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8831 hi = hash_find(&slang->sl_wordcount, tw);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8832 if (!HASHITEM_EMPTY(hi))
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8833 {
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8834 vim_snprintf((char *)IObuff, IOSIZE, "%s\t%d",
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
8835 tw, HI2WC(hi)->wc_count);
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8836 p = IObuff;
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8837 }
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8838 }
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8839
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8840 ml_append(lnum, p, (colnr_T)0, FALSE);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8841 }
710
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8842 else if (((dumpflags & DUMPFLAG_ICASE)
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8843 ? MB_STRNICMP(p, pat, STRLEN(pat)) == 0
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8844 : STRNCMP(p, pat, STRLEN(pat)) == 0)
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8845 && ins_compl_add_infercase(p, (int)STRLEN(p),
942
29bf49bad20d updated for version 7.0-068
vimboss
parents: 914
diff changeset
8846 p_ic, NULL, *dir, 0) == OK)
710
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8847 /* if dir was BACKWARD then honor it just once */
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
8848 *dir = FORWARD;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8849 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8850
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8851 /*
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
8852 * For ":spelldump": Find matching prefixes for "word". Prepend each to
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
8853 * "word" and append a line to the buffer.
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8854 * When "lnum" is zero add insert mode completion.
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8855 * Return the updated line number.
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8856 */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8857 static linenr_T
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8858 dump_prefixes(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8859 slang_T *slang,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8860 char_u *word, /* case-folded word */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8861 char_u *pat,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8862 int *dir,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8863 int dumpflags,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8864 int flags, /* flags with prefix ID */
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8865 linenr_T startlnum)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8866 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8867 idx_T arridx[MAXWLEN];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8868 int curi[MAXWLEN];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8869 char_u prefix[MAXWLEN];
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8870 char_u word_up[MAXWLEN];
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8871 int has_word_up = FALSE;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8872 int c;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8873 char_u *byts;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8874 idx_T *idxs;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8875 linenr_T lnum = startlnum;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8876 int depth;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8877 int n;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8878 int len;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8879 int i;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8880
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
8881 /* If the word starts with a lower-case letter make the word with an
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8882 * upper-case letter in word_up[]. */
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8883 c = PTR2CHAR(word);
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8884 if (SPELL_TOUPPER(c) != c)
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8885 {
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8886 onecap_copy(word, word_up, TRUE);
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8887 has_word_up = TRUE;
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8888 }
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8889
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8890 byts = slang->sl_pbyts;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8891 idxs = slang->sl_pidxs;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8892 if (byts != NULL) /* array not is empty */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8893 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8894 /*
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8895 * Loop over all prefixes, building them byte-by-byte in prefix[].
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
8896 * When at the end of a prefix check that it supports "flags".
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8897 */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8898 depth = 0;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8899 arridx[0] = 0;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8900 curi[0] = 1;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8901 while (depth >= 0 && !got_int)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8902 {
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
8903 n = arridx[depth];
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
8904 len = byts[n];
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
8905 if (curi[depth] > len)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8906 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8907 /* Done all bytes at this node, go up one level. */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8908 --depth;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8909 line_breakcheck();
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8910 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8911 else
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8912 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8913 /* Do one more byte at this node. */
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
8914 n += curi[depth];
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8915 ++curi[depth];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8916 c = byts[n];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8917 if (c == 0)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8918 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8919 /* End of prefix, find out how many IDs there are. */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8920 for (i = 1; i < len; ++i)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8921 if (byts[n + i] != 0)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8922 break;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8923 curi[depth] += i - 1;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8924
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8925 c = valid_word_prefix(i, n, flags, word, slang, FALSE);
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8926 if (c != 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8927 {
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
8928 vim_strncpy(prefix + depth, word, MAXWLEN - depth - 1);
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8929 dump_word(slang, prefix, pat, dir, dumpflags,
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8930 (c & WF_RAREPFX) ? (flags | WF_RARE)
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8931 : flags, lnum);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8932 if (lnum != 0)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8933 ++lnum;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8934 }
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8935
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8936 /* Check for prefix that matches the word when the
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8937 * first letter is upper-case, but only if the prefix has
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8938 * a condition. */
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8939 if (has_word_up)
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8940 {
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8941 c = valid_word_prefix(i, n, flags, word_up, slang,
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8942 TRUE);
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8943 if (c != 0)
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8944 {
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8945 vim_strncpy(prefix + depth, word_up,
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8946 MAXWLEN - depth - 1);
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8947 dump_word(slang, prefix, pat, dir, dumpflags,
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8948 (c & WF_RAREPFX) ? (flags | WF_RARE)
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8949 : flags, lnum);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8950 if (lnum != 0)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
8951 ++lnum;
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8952 }
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
8953 }
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8954 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8955 else
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8956 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8957 /* Normal char, go one level deeper. */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8958 prefix[depth++] = c;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8959 arridx[depth] = idxs[n];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8960 curi[depth] = 1;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8961 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8962 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8963 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8964 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8965
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8966 return lnum;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8967 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
8968
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
8969 /*
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
8970 * Move "p" to the end of word "start".
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
8971 * Uses the spell-checking word characters.
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
8972 */
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
8973 char_u *
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8974 spell_to_word_end(char_u *start, win_T *win)
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
8975 {
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
8976 char_u *p = start;
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
8977
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
8978 while (*p != NUL && spell_iswordp(p, win))
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
8979 mb_ptr_adv(p);
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
8980 return p;
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
8981 }
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
8982
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
8983 #if defined(FEAT_INS_EXPAND) || defined(PROTO)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
8984 /*
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
8985 * For Insert mode completion CTRL-X s:
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
8986 * Find start of the word in front of column "startcol".
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
8987 * We don't check if it is badly spelled, with completion we can only change
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
8988 * the word in front of the cursor.
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
8989 * Returns the column number of the word.
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
8990 */
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
8991 int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
8992 spell_word_start(int startcol)
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
8993 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
8994 char_u *line;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
8995 char_u *p;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
8996 int col = 0;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
8997
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
8998 if (no_spell_checking(curwin))
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
8999 return startcol;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9000
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9001 /* Find a word character before "startcol". */
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9002 line = ml_get_curline();
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9003 for (p = line + startcol; p > line; )
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9004 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9005 mb_ptr_back(line, p);
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
9006 if (spell_iswordp_nmw(p, curwin))
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9007 break;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9008 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9009
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9010 /* Go back to start of the word. */
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9011 while (p > line)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9012 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
9013 col = (int)(p - line);
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9014 mb_ptr_back(line, p);
2250
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
9015 if (!spell_iswordp(p, curwin))
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9016 break;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9017 col = 0;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9018 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9019
535
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
9020 return col;
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
9021 }
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
9022
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
9023 /*
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
9024 * Need to check for 'spellcapcheck' now, the word is removed before
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
9025 * expand_spelling() is called. Therefore the ugly global variable.
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
9026 */
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
9027 static int spell_expand_need_cap;
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
9028
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
9029 void
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
9030 spell_expand_check_cap(colnr_T col)
535
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
9031 {
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9032 spell_expand_need_cap = check_need_cap(curwin->w_cursor.lnum, col);
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9033 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9034
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9035 /*
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9036 * Get list of spelling suggestions.
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9037 * Used for Insert mode completion CTRL-X ?.
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9038 * Returns the number of matches. The matches are in "matchp[]", array of
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9039 * allocated strings.
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9040 */
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9041 int
7835
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
9042 expand_spelling(
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
9043 linenr_T lnum UNUSED,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
9044 char_u *pat,
4d7ce6c03fda commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
9045 char_u ***matchp)
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9046 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9047 garray_T ga;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9048
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
9049 spell_suggest_list(&ga, pat, 100, spell_expand_need_cap, TRUE);
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9050 *matchp = ga.ga_data;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9051 return ga.ga_len;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9052 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9053 #endif
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
9054
737
59971e227f8c updated for version 7.0222
vimboss
parents: 718
diff changeset
9055 #endif /* FEAT_SPELL */