annotate src/spell.c @ 334:a1270013cb34

updated for version 7.0087
author vimboss
date Fri, 17 Jun 2005 21:51:16 +0000
parents f76b0d38b6bd
children 64221fecdfa1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
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 *
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
13 * 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
14 * 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
15 * 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
16 *
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
17 * 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
18 * 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
19 * number of possible bytes is stored before the list of bytes.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
20 *
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
21 * The tree uses two arrays: "byts" stores the characters, "idxs" stores
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
22 * 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
23 * to lookup "vi" this sequence is followed:
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
24 * i = 0
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
25 * len = byts[i]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
26 * n = where "v" appears in byts[i + 1] to byts[i + len]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
27 * i = idxs[n]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
28 * len = byts[i]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
29 * n = where "i" appears in byts[i + 1] to byts[i + len]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
30 * i = idxs[n]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
31 * len = byts[i]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
32 * 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
33 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
34 * There are two trees: one with case-folded words and one with words in
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
35 * 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
36 * usually small.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
37 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
38 * Thanks to Olaf Seibert for providing an example implementation of this tree
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
39 * and the compression mechanism.
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
40 *
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
41 * Matching involves checking the caps type: Onecap ALLCAP KeepCap.
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
42 *
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
43 * Why doesn't Vim use aspell/ispell/myspell/etc.?
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
44 * See ":help develop-spell".
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
45 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
46
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
47 /*
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
48 * Use this to let the score depend in how much a suggestion sounds like the
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
49 * bad word. It's quite slow and only occasionally makes the sorting better.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
50 #define SOUNDFOLD_SCORE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
51 */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
52
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
53 /*
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
54 * Use this to adjust the score after finding suggestions, based on the
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
55 * suggested word sounding like the bad word. This is much faster than doing
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
56 * it for every possible suggestion.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
57 * Disadvantage: When "the" is typed as "hte" it sounds different and goes
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
58 * down in the list.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
59 #define RESCORE(word_score, sound_score) ((2 * word_score + sound_score) / 3)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
60 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
61
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
62 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
63 * Vim spell file format: <HEADER> <SUGGEST> <LWORDTREE> <KWORDTREE>
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
64 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
65 * <HEADER>: <fileID> <regioncnt> <regionname> ...
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
66 * <charflagslen> <charflags> <fcharslen> <fchars>
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
67 *
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
68 * <fileID> 10 bytes "VIMspell06"
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
69 * <regioncnt> 1 byte number of regions following (8 supported)
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
70 * <regionname> 2 bytes Region name: ca, au, etc. Lower case.
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
71 * First <regionname> is region 1.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
72 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
73 * <charflagslen> 1 byte Number of bytes in <charflags> (should be 128).
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
74 * <charflags> N bytes List of flags (first one is for character 128):
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
75 * 0x01 word character CF_WORD
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
76 * 0x02 upper-case character CF_UPPER
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
77 * <fcharslen> 2 bytes Number of bytes in <fchars>.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
78 * <fchars> N bytes Folded characters, first one is for character 128.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
79 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
80 *
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
81 * <SUGGEST> : <repcount> <rep> ...
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
82 * <salflags> <salcount> <sal> ...
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
83 * <maplen> <mapstr>
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
84 *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
85 * <repcount> 2 bytes number of <rep> items, MSB first.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
86 *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
87 * <rep> : <repfromlen> <repfrom> <reptolen> <repto>
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
88 *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
89 * <repfromlen> 1 byte length of <repfrom>
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
90 *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
91 * <repfrom> N bytes "from" part of replacement
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
92 *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
93 * <reptolen> 1 byte length of <repto>
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
94 *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
95 * <repto> N bytes "to" part of replacement
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
96 *
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
97 * <salflags> 1 byte flags for soundsalike conversion:
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
98 * SAL_F0LLOWUP
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
99 * SAL_COLLAPSE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
100 * SAL_REM_ACCENTS
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
101 *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
102 * <sal> : <salfromlen> <salfrom> <saltolen> <salto>
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
103 *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
104 * <salfromlen> 1 byte length of <salfrom>
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
105 *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
106 * <salfrom> N bytes "from" part of soundsalike
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
107 *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
108 * <saltolen> 1 byte length of <salto>
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
109 *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
110 * <salto> N bytes "to" part of soundsalike
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
111 *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
112 * <maplen> 2 bytes length of <mapstr>, MSB first
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
113 *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
114 * <mapstr> N bytes String with sequences of similar characters,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
115 * separated by slashes.
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
116 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
117 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
118 * <LWORDTREE>: <wordtree>
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
119 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
120 * <wordtree>: <nodecount> <nodedata> ...
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
121 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
122 * <nodecount> 4 bytes Number of nodes following. MSB first.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
123 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
124 * <nodedata>: <siblingcount> <sibling> ...
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
125 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
126 * <siblingcount> 1 byte Number of siblings in this node. The siblings
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
127 * follow in sorted order.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
128 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
129 * <sibling>: <byte> [<nodeidx> <xbyte> | <flags> [<region>]]
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
130 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
131 * <byte> 1 byte Byte value of the sibling. Special cases:
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
132 * BY_NOFLAGS: End of word without flags and for all
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
133 * regions.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
134 * BY_FLAGS: End of word, <flags> follow.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
135 * BY_INDEX: Child of sibling is shared, <nodeidx>
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
136 * and <xbyte> follow.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
137 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
138 * <nodeidx> 3 bytes Index of child for this sibling, MSB first.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
139 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
140 * <xbyte> 1 byte byte value of the sibling.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
141 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
142 * <flags> 1 byte bitmask of:
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
143 * WF_ALLCAP word must have only capitals
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
144 * WF_ONECAP first char of word must be capital
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
145 * WF_RARE rare word
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
146 * WF_REGION <region> follows
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
147 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
148 * <region> 1 byte Bitmask for regions in which word is valid. When
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
149 * omitted it's valid in all regions.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
150 * Lowest bit is for region 1.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
151 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
152 * <KWORDTREE>: <wordtree>
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
153 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
154 * All text characters are in 'encoding', but stored as single bytes.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
155 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
156
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
157 #if defined(MSDOS) || defined(WIN16) || defined(WIN32) || defined(_WIN64)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
158 # include <io.h> /* for lseek(), must be before vim.h */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
159 #endif
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
160
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
161 #include "vim.h"
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
162
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
163 #if defined(FEAT_SYN_HL) || defined(PROTO)
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
164
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
165 #ifdef HAVE_FCNTL_H
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
166 # include <fcntl.h>
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
167 #endif
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
168
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
169 #define MAXWLEN 250 /* Assume max. word len is this many bytes.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
170 Some places assume a word length fits in a
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
171 byte, thus it can't be above 255. */
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
172
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
173 /* Type used for indexes in the word tree need to be at least 3 bytes. If int
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
174 * is 8 bytes we could use something smaller, but what? */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
175 #if SIZEOF_INT > 2
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
176 typedef int idx_T;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
177 #else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
178 typedef long idx_T;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
179 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
180
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
181 /* Flags used for a word. Only the lowest byte can be used, the region byte
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
182 * comes above it. */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
183 #define WF_REGION 0x01 /* region byte follows */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
184 #define WF_ONECAP 0x02 /* word with one capital (or all capitals) */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
185 #define WF_ALLCAP 0x04 /* word must be all capitals */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
186 #define WF_RARE 0x08 /* rare word */
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
187 #define WF_BANNED 0x10 /* bad word */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
188 #define WF_KEEPCAP 0x80 /* keep-case word */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
189
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
190 #define WF_CAPMASK (WF_ONECAP | WF_ALLCAP | WF_KEEPCAP)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
191
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
192 #define BY_NOFLAGS 0 /* end of word without flags or region */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
193 #define BY_FLAGS 1 /* end of word, flag byte follows */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
194 #define BY_INDEX 2 /* child is shared, index follows */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
195 #define BY_SPECIAL BY_INDEX /* hightest special byte value */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
196
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
197 /* Info from "REP" and "SAL" entries in ".aff" file used in si_rep, sl_rep,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
198 * si_sal and sl_sal.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
199 * One replacement: from "ft_from" to "ft_to". */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
200 typedef struct fromto_S
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
201 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
202 char_u *ft_from;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
203 char_u *ft_to;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
204 } fromto_T;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
205
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
206 /*
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
207 * Structure used to store words and other info for one language, loaded from
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
208 * a .spl file.
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
209 * The main access is through the tree in "sl_fbyts/sl_fidxs", storing the
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
210 * case-folded words. "sl_kbyts/sl_kidxs" is for keep-case words.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
211 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
212 * The "byts" array stores the possible bytes in each tree node, preceded by
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
213 * the number of possible bytes, sorted on byte value:
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
214 * <len> <byte1> <byte2> ...
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
215 * The "idxs" array stores the index of the child node corresponding to the
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
216 * byte in "byts".
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
217 * Exception: when the byte is zero, the word may end here and "idxs" holds
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
218 * the flags and region for the word. There may be several zeros in sequence
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
219 * for alternative flag/region combinations.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
220 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
221 typedef struct slang_S slang_T;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
222 struct slang_S
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
223 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
224 slang_T *sl_next; /* next language */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
225 char_u *sl_name; /* language name "en", "en.rare", "nl", etc. */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
226 char_u *sl_fname; /* name of .spl file */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
227 int sl_add; /* TRUE if it's a .add file. */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
228 char_u *sl_fbyts; /* case-folded word bytes */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
229 idx_T *sl_fidxs; /* case-folded word indexes */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
230 char_u *sl_kbyts; /* keep-case word bytes */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
231 idx_T *sl_kidxs; /* keep-case word indexes */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
232 char_u sl_regions[17]; /* table with up to 8 region names plus NUL */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
233
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
234 garray_T sl_rep; /* list of fromto_T entries from REP lines */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
235 short sl_rep_first[256]; /* indexes where byte first appears, -1 if
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
236 there is none */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
237 garray_T sl_sal; /* list of fromto_T entries from SAL lines */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
238 short sl_sal_first[256]; /* indexes where byte first appears, -1 if
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
239 there is none */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
240 int sl_followup; /* SAL followup */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
241 int sl_collapse; /* SAL collapse_result */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
242 int sl_rem_accents; /* SAL remove_accents */
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
243 int sl_has_map; /* TRUE if there is a MAP line */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
244 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
245 hashtab_T sl_map_hash; /* MAP for multi-byte chars */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
246 int sl_map_array[256]; /* MAP for first 256 chars */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
247 #else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
248 char_u sl_map_array[256]; /* MAP for first 256 chars */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
249 #endif
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
250 };
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
251
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
252 /* First language that is loaded, start of the linked list of loaded
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
253 * languages. */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
254 static slang_T *first_lang = NULL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
255
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
256 /* Flags used in .spl file for soundsalike flags. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
257 #define SAL_F0LLOWUP 1
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
258 #define SAL_COLLAPSE 2
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
259 #define SAL_REM_ACCENTS 4
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
260
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
261 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
262 * Structure used in "b_langp", filled from 'spelllang'.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
263 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
264 typedef struct langp_S
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
265 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
266 slang_T *lp_slang; /* info for this language (NULL for last one) */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
267 int lp_region; /* bitmask for region or REGION_ALL */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
268 } langp_T;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
269
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
270 #define LANGP_ENTRY(ga, i) (((langp_T *)(ga).ga_data) + (i))
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
271
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
272 #define REGION_ALL 0xff /* word valid in all regions */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
273
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
274 /* Result values. Lower number is accepted over higher one. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
275 #define SP_BANNED -1
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
276 #define SP_OK 0
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
277 #define SP_RARE 1
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
278 #define SP_LOCAL 2
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
279 #define SP_BAD 3
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
280
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
281 #define VIMSPELLMAGIC "VIMspell06" /* string at start of Vim spell file */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
282 #define VIMSPELLMAGICL 10
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
283
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
284 /*
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
285 * Information used when looking for suggestions.
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 suginfo_S
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
288 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
289 garray_T su_ga; /* suggestions, contains "suggest_T" */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
290 int su_maxscore; /* maximum score for adding to su_ga */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
291 int su_icase; /* accept words with wrong case */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
292 int su_icase_add; /* add matches while ignoring case */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
293 char_u *su_badptr; /* start of bad word in line */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
294 int su_badlen; /* length of detected bad word in line */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
295 char_u su_badword[MAXWLEN]; /* bad word truncated at su_badlen */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
296 char_u su_fbadword[MAXWLEN]; /* su_badword case-folded */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
297 hashtab_T su_banned; /* table with banned words */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
298 #ifdef SOUNDFOLD_SCORE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
299 slang_T *su_slang; /* currently used slang_T */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
300 char_u su_salword[MAXWLEN]; /* soundfolded badword */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
301 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
302 } suginfo_T;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
303
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
304 /* One word suggestion. Used in "si_ga". */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
305 typedef struct suggest_S
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
306 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
307 char_u *st_word; /* suggested word, allocated string */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
308 int st_orglen; /* length of replaced text */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
309 int st_score; /* lower is better */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
310 #ifdef RESCORE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
311 int st_had_bonus; /* bonus already included in score */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
312 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
313 } suggest_T;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
314
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
315 #define SUG(sup, i) (((suggest_T *)(sup)->su_ga.ga_data)[i])
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
316
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
317 /* Number of suggestions displayed. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
318 #define SUG_PROMPT_COUNT ((int)Rows - 2)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
319
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
320 /* Number of suggestions kept when cleaning up. When rescore_suggestions() is
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
321 * called the score may change, thus we need to keep more than what is
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
322 * displayed. */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
323 #define SUG_CLEAN_COUNT (SUG_PROMPT_COUNT < 25 ? 25 : SUG_PROMPT_COUNT)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
325 /* Threshold for sorting and cleaning up suggestions. Don't want to keep lots
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
326 * of suggestions that are not going to be displayed. */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
327 #define SUG_MAX_COUNT (SUG_PROMPT_COUNT + 50)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
328
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
329 /* score for various changes */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
330 #define SCORE_SPLIT 99 /* split bad word */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
331 #define SCORE_ICASE 52 /* slightly different case */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
332 #define SCORE_ALLCAP 120 /* need all-cap case */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
333 #define SCORE_REGION 70 /* word is for different region */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
334 #define SCORE_RARE 180 /* rare word */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
335
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
336 /* score for edit distance */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
337 #define SCORE_SWAP 90 /* swap two characters */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
338 #define SCORE_SWAP3 110 /* swap two characters in three */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
339 #define SCORE_REP 87 /* REP replacement */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
340 #define SCORE_SUBST 93 /* substitute a character */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
341 #define SCORE_SIMILAR 33 /* substitute a similar character */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
342 #define SCORE_DEL 94 /* delete a character */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
343 #define SCORE_INS 96 /* insert a character */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
344
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
345 #define SCORE_MAXINIT 350 /* Initial maximum score: higher == slower.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
346 * 350 allows for about three changes. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
347 #define SCORE_MAXMAX 999999 /* accept any score */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
348
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
349 /*
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
350 * Structure to store info for word matching.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
351 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
352 typedef struct matchinf_S
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
353 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
354 langp_T *mi_lp; /* info for language and region */
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
355
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
356 /* pointers to original text to be checked */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
357 char_u *mi_word; /* start of word being checked */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
358 char_u *mi_end; /* end of matching word */
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
359 char_u *mi_fend; /* next char to be added to mi_fword */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
360 char_u *mi_cend; /* char after what was used for
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
361 mi_capflags */
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
362
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
363 /* case-folded text */
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
364 char_u mi_fword[MAXWLEN + 1]; /* mi_word case-folded */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
365 int mi_fwordlen; /* nr of valid bytes in mi_fword */
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
366
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
367 /* others */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
368 int mi_result; /* result so far: SP_BAD, SP_OK, etc. */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
369 int mi_capflags; /* WF_ONECAP WF_ALLCAP WF_KEEPCAP */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
370 } matchinf_T;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
371
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
372 /*
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
373 * The tables used for recognizing word characters according to spelling.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
374 * These are only used for the first 256 characters of 'encoding'.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
375 */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
376 typedef struct spelltab_S
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
377 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
378 char_u st_isw[256]; /* flags: is word char */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
379 char_u st_isu[256]; /* flags: is uppercase char */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
380 char_u st_fold[256]; /* chars: folded case */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
381 char_u st_upper[256]; /* chars: upper case */
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
382 } spelltab_T;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
383
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
384 static spelltab_T spelltab;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
385 static int did_set_spelltab;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
386
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
387 #define CF_WORD 0x01
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
388 #define CF_UPPER 0x02
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
389
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
390 static void clear_spell_chartab __ARGS((spelltab_T *sp));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
391 static int set_spell_finish __ARGS((spelltab_T *new_st));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
392
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
393 /*
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
394 * Return TRUE if "p" points to a word character or "c" is a word character
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
395 * for spelling.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
396 * Checking for a word character is done very often, avoid the function call
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
397 * overhead.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
398 */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
399 #ifdef FEAT_MBYTE
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
400 # define SPELL_ISWORDP(p) ((has_mbyte && MB_BYTE2LEN(*(p)) > 1) \
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
401 ? (mb_get_class(p) >= 2) : spelltab.st_isw[*(p)])
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
402 #else
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
403 # define SPELL_ISWORDP(p) (spelltab.st_isw[*(p)])
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
404 #endif
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
405
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
406 /*
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
407 * For finding suggestion: At each node in the tree these states are tried:
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
408 */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
409 typedef enum
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
410 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
411 STATE_START = 0, /* At start of node, check if word may end or
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
412 * split word. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
413 STATE_SPLITUNDO, /* Undo word split. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
414 STATE_ENDNUL, /* Past NUL bytes at start of the node. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
415 STATE_PLAIN, /* Use each byte of the node. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
416 STATE_DEL, /* Delete a byte from the bad word. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
417 STATE_INS, /* Insert a byte in the bad word. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
418 STATE_SWAP, /* Swap two bytes. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
419 STATE_UNSWAP, /* Undo swap two bytes. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
420 STATE_SWAP3, /* Swap two bytes over three. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
421 STATE_UNSWAP3, /* Undo Swap two bytes over three. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
422 STATE_ROT3L, /* Rotate three bytes left */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
423 STATE_UNROT3L, /* Undo rotate three bytes left */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
424 STATE_ROT3R, /* Rotate three bytes right */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
425 STATE_UNROT3R, /* Undo rotate three bytes right */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
426 STATE_REP_INI, /* Prepare for using REP items. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
427 STATE_REP, /* Use matching REP items from the .aff file. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
428 STATE_REP_UNDO, /* Undo a REP item replacement. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
429 STATE_FINAL /* End of this node. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
430 } state_T;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
431
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
432 /*
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
433 * Struct to keep the state at each level in spell_try_change().
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
434 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
435 typedef struct trystate_S
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
436 {
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
437 state_T ts_state; /* state at this level, STATE_ */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
438 int ts_score; /* score */
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
439 short ts_curi; /* index in list of child nodes */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
440 char_u ts_fidx; /* index in fword[], case-folded bad word */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
441 char_u ts_fidxtry; /* ts_fidx at which bytes may be changed */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
442 char_u ts_twordlen; /* valid length of tword[] */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
443 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
444 char_u ts_tcharlen; /* number of bytes in tword character */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
445 char_u ts_tcharidx; /* current byte index in tword character */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
446 char_u ts_isdiff; /* DIFF_ values */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
447 char_u ts_fcharstart; /* index in fword where badword char started */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
448 #endif
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
449 idx_T ts_arridx; /* index in tree array, start of node */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
450 char_u ts_save_prewordlen; /* saved "prewordlen" */
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
451 char_u ts_save_splitoff; /* su_splitoff saved here */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
452 char_u ts_save_badflags; /* badflags saved here */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
453 } trystate_T;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
454
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
455 /* values for ts_isdiff */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
456 #define DIFF_NONE 0 /* no different byte (yet) */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
457 #define DIFF_YES 1 /* different byte found */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
458 #define DIFF_INSERT 2 /* inserting character */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
459
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
460 static slang_T *slang_alloc __ARGS((char_u *lang));
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
461 static void slang_free __ARGS((slang_T *lp));
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
462 static void slang_clear __ARGS((slang_T *lp));
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
463 static void find_word __ARGS((matchinf_T *mip, int keepcap));
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
464 static int spell_valid_case __ARGS((int origflags, int treeflags));
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
465 static void spell_load_lang __ARGS((char_u *lang));
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
466 static char_u *spell_enc __ARGS((void));
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
467 static void spell_load_cb __ARGS((char_u *fname, void *cookie));
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
468 static slang_T *spell_load_file __ARGS((char_u *fname, char_u *lang, slang_T *old_lp, int silent));
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
469 static idx_T read_tree __ARGS((FILE *fd, char_u *byts, idx_T *idxs, int maxidx, int startidx));
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
470 static int find_region __ARGS((char_u *rp, char_u *region));
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
471 static int captype __ARGS((char_u *word, char_u *end));
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
472 static void spell_reload_one __ARGS((char_u *fname, int added_word));
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
473 static int set_spell_charflags __ARGS((char_u *flags, int cnt, char_u *upp));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
474 static int set_spell_chartab __ARGS((char_u *fol, char_u *low, char_u *upp));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
475 static void write_spell_chartab __ARGS((FILE *fd));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
476 static int spell_casefold __ARGS((char_u *p, int len, char_u *buf, int buflen));
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
477 static void onecap_copy __ARGS((char_u *word, char_u *wcopy, int upper));
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
478 static void spell_try_change __ARGS((suginfo_T *su));
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
479 static int try_deeper __ARGS((suginfo_T *su, trystate_T *stack, int depth, int score_add));
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
480 static void find_keepcap_word __ARGS((slang_T *slang, char_u *fword, char_u *kword));
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
481 static void spell_try_soundalike __ARGS((suginfo_T *su));
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
482 static void make_case_word __ARGS((char_u *fword, char_u *cword, int flags));
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
483 static void set_map_str __ARGS((slang_T *lp, char_u *map));
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
484 static int similar_chars __ARGS((slang_T *slang, int c1, int c2));
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
485 #ifdef RESCORE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
486 static void add_suggestion __ARGS((suginfo_T *su, char_u *goodword, int use_score, int had_bonus));
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
487 #else
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
488 static void add_suggestion __ARGS((suginfo_T *su, char_u *goodword, int use_score));
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
489 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
490 static void add_banned __ARGS((suginfo_T *su, char_u *word));
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
491 static int was_banned __ARGS((suginfo_T *su, char_u *word));
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
492 static void free_banned __ARGS((suginfo_T *su));
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
493 #ifdef RESCORE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
494 static void rescore_suggestions __ARGS((suginfo_T *su));
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
495 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
496 static void cleanup_suggestions __ARGS((suginfo_T *su, int keep));
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
497 static void spell_soundfold __ARGS((slang_T *slang, char_u *inword, char_u *res));
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
498 #if defined(RESCORE) || defined(SOUNDFOLD_SCORE)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
499 static int spell_sound_score __ARGS((slang_T *slang, char_u *goodword, char_u *badsound));
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
500 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
501 static int spell_edit_score __ARGS((char_u *badword, char_u *goodword));
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
502
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
503 /*
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
504 * Use our own character-case definitions, because the current locale may
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
505 * differ from what the .spl file uses.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
506 * These must not be called with negative number!
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
507 */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
508 #ifndef FEAT_MBYTE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
509 /* Non-multi-byte implementation. */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
510 # define SPELL_TOFOLD(c) ((c) < 256 ? spelltab.st_fold[c] : (c))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
511 # define SPELL_TOUPPER(c) ((c) < 256 ? spelltab.st_upper[c] : (c))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
512 # define SPELL_ISUPPER(c) ((c) < 256 ? spelltab.st_isu[c] : FALSE)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
513 #else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
514 /* Multi-byte implementation. For Unicode we can call utf_*(), but don't do
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
515 * that for ASCII, because we don't want to use 'casemap' here. Otherwise use
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
516 * the "w" library function for characters above 255 if available. */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
517 # ifdef HAVE_TOWLOWER
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
518 # define SPELL_TOFOLD(c) (enc_utf8 && (c) >= 128 ? utf_fold(c) \
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
519 : (c) < 256 ? spelltab.st_fold[c] : towlower(c))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
520 # else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
521 # define SPELL_TOFOLD(c) (enc_utf8 && (c) >= 128 ? utf_fold(c) \
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
522 : (c) < 256 ? spelltab.st_fold[c] : (c))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
523 # endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
524
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
525 # ifdef HAVE_TOWUPPER
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
526 # define SPELL_TOUPPER(c) (enc_utf8 && (c) >= 128 ? utf_toupper(c) \
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
527 : (c) < 256 ? spelltab.st_upper[c] : towupper(c))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
528 # else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
529 # define SPELL_TOUPPER(c) (enc_utf8 && (c) >= 128 ? utf_toupper(c) \
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
530 : (c) < 256 ? spelltab.st_upper[c] : (c))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
531 # endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
532
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
533 # ifdef HAVE_ISWUPPER
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
534 # define SPELL_ISUPPER(c) (enc_utf8 && (c) >= 128 ? utf_isupper(c) \
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
535 : (c) < 256 ? spelltab.st_isu[c] : iswupper(c))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
536 # else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
537 # define SPELL_ISUPPER(c) (enc_utf8 && (c) >= 128 ? utf_isupper(c) \
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
538 : (c) < 256 ? spelltab.st_isu[c] : (c))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
539 # endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
540 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
541
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
542
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
543 static char *e_format = N_("E759: Format error in spell file");
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
544
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
545 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
546 * Main spell-checking function.
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
547 * "ptr" points to a character that could be the start of a word.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
548 * "*attrp" is set to the attributes for a badly spelled word. For a non-word
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
549 * or when it's OK it remains unchanged.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
550 * This must only be called when 'spelllang' is not empty.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
551 *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
552 * "sug" is normally NULL. When looking for suggestions it points to
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
553 * suginfo_T. It's passed as a void pointer to keep the struct local.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
554 *
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
555 * 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
556 * caller can skip over the word.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
557 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
558 int
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
559 spell_check(wp, ptr, attrp)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
560 win_T *wp; /* current window */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
561 char_u *ptr;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
562 int *attrp;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
563 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
564 matchinf_T mi; /* Most things are put in "mi" so that it can
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
565 be passed to functions quickly. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
566
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
567 /* A word never starts at a space or a control character. Return quickly
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
568 * then, skipping over the character. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
569 if (*ptr <= ' ')
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
570 return 1;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
571
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
572 /* A word starting with a number is always OK. Also skip hexadecimal
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
573 * numbers 0xFF99 and 0X99FF. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
574 if (*ptr >= '0' && *ptr <= '9')
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
575 {
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
576 if (*ptr == '0' && (ptr[1] == 'x' || ptr[1] == 'X'))
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
577 mi.mi_end = skiphex(ptr + 2);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
578 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
579 mi.mi_end = skipdigits(ptr);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
580 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
581 else
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
582 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
583 /* Find the end of the word. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
584 mi.mi_word = ptr;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
585 mi.mi_fend = ptr;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
586
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
587 if (SPELL_ISWORDP(mi.mi_fend))
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
588 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
589 /* Make case-folded copy of the characters until the next non-word
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
590 * character. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
591 do
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
592 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
593 mb_ptr_adv(mi.mi_fend);
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
594 } while (*mi.mi_fend != NUL && SPELL_ISWORDP(mi.mi_fend));
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
595 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
596
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
597 /* We always use the characters up to the next non-word character,
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
598 * also for bad words. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
599 mi.mi_end = mi.mi_fend;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
600
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
601 /* Check caps type later. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
602 mi.mi_capflags = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
603 mi.mi_cend = NULL;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
604
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
605 /* Include one non-word character so that we can check for the
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
606 * word end. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
607 if (*mi.mi_fend != NUL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
608 mb_ptr_adv(mi.mi_fend);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
609
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
610 (void)spell_casefold(ptr, (int)(mi.mi_fend - ptr), mi.mi_fword,
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
611 MAXWLEN + 1);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
612 mi.mi_fwordlen = STRLEN(mi.mi_fword);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
613
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
614 /* The word is bad unless we recognize it. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
615 mi.mi_result = SP_BAD;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
616
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
617 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
618 * Loop over the languages specified in 'spelllang'.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
619 * We check them all, because a matching word may be longer than an
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
620 * already found matching word.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
621 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
622 for (mi.mi_lp = LANGP_ENTRY(wp->w_buffer->b_langp, 0);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
623 mi.mi_lp->lp_slang != NULL; ++mi.mi_lp)
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
624 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
625 /* Check for a matching word in case-folded words. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
626 find_word(&mi, FALSE);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
627
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
628 /* Check for a matching word in keep-case words. */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
629 find_word(&mi, TRUE);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
630 }
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
631
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
632 if (mi.mi_result != SP_OK)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
633 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
634 /* When we are at a non-word character there is no error, just
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
635 * skip over the character (try looking for a word after it). */
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
636 if (!SPELL_ISWORDP(ptr))
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
637 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
638 #ifdef FEAT_MBYTE
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
639 if (has_mbyte)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
640 return mb_ptr2len_check(ptr);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
641 #endif
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
642 return 1;
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
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
645 if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
646 *attrp = highlight_attr[HLF_SPB];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
647 else if (mi.mi_result == SP_RARE)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
648 *attrp = highlight_attr[HLF_SPR];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
649 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
650 *attrp = highlight_attr[HLF_SPL];
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
651 }
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
652 }
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
653
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
654 return (int)(mi.mi_end - ptr);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
655 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
656
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
657 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
658 * Check if the word at "mip->mi_word" is in the tree.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
659 * When "keepcap" is TRUE check in keep-case word tree.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
660 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
661 * For a match mip->mi_result is updated.
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
662 */
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
663 static void
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
664 find_word(mip, keepcap)
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
665 matchinf_T *mip;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
666 int keepcap;
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
667 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
668 idx_T arridx = 0;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
669 int endlen[MAXWLEN]; /* length at possible word endings */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
670 idx_T endidx[MAXWLEN]; /* possible word endings */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
671 int endidxcnt = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
672 int len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
673 int wlen = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
674 int flen;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
675 int c;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
676 char_u *ptr;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
677 idx_T lo, hi, m;
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
678 #ifdef FEAT_MBYTE
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
679 char_u *s;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
680 #endif
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
681 char_u *p;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
682 int res = SP_BAD;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
683 int valid;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
684 slang_T *slang = mip->mi_lp->lp_slang;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
685 unsigned flags;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
686 char_u *byts;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
687 idx_T *idxs;
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
688
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
689 if (keepcap)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
690 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
691 /* Check for word with matching case in keep-case tree. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
692 ptr = mip->mi_word;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
693 flen = 9999; /* no case folding, always enough bytes */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
694 byts = slang->sl_kbyts;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
695 idxs = slang->sl_kidxs;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
696 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
697 else
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
698 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
699 /* Check for case-folded in case-folded tree. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
700 ptr = mip->mi_fword;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
701 flen = mip->mi_fwordlen; /* available case-folded bytes */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
702 byts = slang->sl_fbyts;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
703 idxs = slang->sl_fidxs;
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
704 }
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
705
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
706 if (byts == NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
707 return; /* array is empty */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
708
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
709 /*
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
710 * Repeat advancing in the tree until:
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
711 * - there is a byte that doesn't match,
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
712 * - we reach the end of the tree,
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
713 * - or we reach the end of the line.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
714 */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
715 for (;;)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
716 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
717 if (flen == 0 && *mip->mi_fend != NUL)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
718 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
719 /* Need to fold at least one more character. Do until next
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
720 * non-word character for efficiency. */
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
721 p = mip->mi_fend;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
722 do
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
723 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
724 mb_ptr_adv(mip->mi_fend);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
725 } while (*mip->mi_fend != NUL && SPELL_ISWORDP(mip->mi_fend));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
726
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
727 /* Include the non-word character so that we can check for the
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
728 * word end. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
729 if (*mip->mi_fend != NUL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
730 mb_ptr_adv(mip->mi_fend);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
731
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
732 (void)spell_casefold(p, (int)(mip->mi_fend - p),
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
733 mip->mi_fword + mip->mi_fwordlen,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
734 MAXWLEN - mip->mi_fwordlen);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
735 flen = STRLEN(mip->mi_fword + mip->mi_fwordlen);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
736 mip->mi_fwordlen += flen;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
737 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
738
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
739 len = byts[arridx++];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
740
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
741 /* If the first possible byte is a zero the word could end here.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
742 * Remember this index, we first check for the longest word. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
743 if (byts[arridx] == 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
744 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
745 if (endidxcnt == MAXWLEN)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
746 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
747 /* Must be a corrupted spell file. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
748 EMSG(_(e_format));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
749 return;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
750 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
751 endlen[endidxcnt] = wlen;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
752 endidx[endidxcnt++] = arridx++;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
753 --len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
754
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
755 /* Skip over the zeros, there can be several flag/region
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
756 * combinations. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
757 while (len > 0 && byts[arridx] == 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
758 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
759 ++arridx;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
760 --len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
761 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
762 if (len == 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
763 break; /* no children, word must end here */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
764 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
765
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
766 /* Stop looking at end of the line. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
767 if (ptr[wlen] == NUL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
768 break;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
769
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
770 /* Perform a binary search in the list of accepted bytes. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
771 c = ptr[wlen];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
772 lo = arridx;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
773 hi = arridx + len - 1;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
774 while (lo < hi)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
775 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
776 m = (lo + hi) / 2;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
777 if (byts[m] > c)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
778 hi = m - 1;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
779 else if (byts[m] < c)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
780 lo = m + 1;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
781 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
782 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
783 lo = hi = m;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
784 break;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
785 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
786 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
787
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
788 /* Stop if there is no matching byte. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
789 if (hi < lo || byts[lo] != c)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
790 break;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
791
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
792 /* Continue at the child (if there is one). */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
793 arridx = idxs[lo];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
794 ++wlen;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
795 --flen;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
796 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
797
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
798 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
799 * Verify that one of the possible endings is valid. Try the longest
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
800 * first.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
801 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
802 while (endidxcnt > 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
803 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
804 --endidxcnt;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
805 arridx = endidx[endidxcnt];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
806 wlen = endlen[endidxcnt];
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
807
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
808 #ifdef FEAT_MBYTE
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
809 if ((*mb_head_off)(ptr, ptr + wlen) > 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
810 continue; /* not at first byte of character */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
811 #endif
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
812 if (SPELL_ISWORDP(ptr + wlen))
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
813 continue; /* next char is a word character */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
814
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
815 #ifdef FEAT_MBYTE
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
816 if (!keepcap && has_mbyte)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
817 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
818 /* Compute byte length in original word, length may change
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
819 * when folding case. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
820 p = mip->mi_word;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
821 for (s = ptr; s < ptr + wlen; mb_ptr_adv(s))
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
822 mb_ptr_adv(p);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
823 wlen = p - mip->mi_word;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
824 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
825 #endif
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
826
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
827 /* Check flags and region. Repeat this if there are more
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
828 * flags/region alternatives until there is a match. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
829 for (len = byts[arridx - 1]; len > 0 && byts[arridx] == 0; --len)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
830 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
831 flags = idxs[arridx];
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
832
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
833 if (keepcap)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
834 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
835 /* For "keepcap" tree the case is always right. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
836 valid = TRUE;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
837 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
838 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
839 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
840 /* Check that the word is in the required case. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
841 if (mip->mi_cend != mip->mi_word + wlen)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
842 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
843 /* mi_capflags was set for a different word length, need
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
844 * to do it again. */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
845 mip->mi_cend = mip->mi_word + wlen;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
846 mip->mi_capflags = captype(mip->mi_word, mip->mi_cend);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
847 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
848
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
849 valid = spell_valid_case(mip->mi_capflags, flags);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
850 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
851
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
852 if (valid)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
853 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
854 if (flags & WF_BANNED)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
855 res = SP_BANNED;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
856 else if (flags & WF_REGION)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
857 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
858 /* Check region. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
859 if ((mip->mi_lp->lp_region & (flags >> 8)) != 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
860 res = SP_OK;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
861 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
862 res = SP_LOCAL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
863 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
864 else if (flags & WF_RARE)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
865 res = SP_RARE;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
866 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
867 res = SP_OK;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
868
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
869 /* Always use the longest match and the best result. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
870 if (mip->mi_result > res)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
871 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
872 mip->mi_result = res;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
873 mip->mi_end = mip->mi_word + wlen;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
874 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
875 else if (mip->mi_result == res
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
876 && mip->mi_end < mip->mi_word + wlen)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
877 mip->mi_end = mip->mi_word + wlen;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
878
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
879 if (res == SP_OK)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
880 break;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
881 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
882 else
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
883 res = SP_BAD;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
884
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
885 ++arridx;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
886 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
887
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
888 if (res == SP_OK)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
889 break;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
890 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
891 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
892
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
893 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
894 * 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
895 * case.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
896 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
897 static int
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
898 spell_valid_case(origflags, treeflags)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
899 int origflags; /* flags for the checked word. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
900 int treeflags; /* flags for the word in the spell tree */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
901 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
902 return (origflags == WF_ALLCAP
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
903 || ((treeflags & (WF_ALLCAP | WF_KEEPCAP)) == 0
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
904 && ((treeflags & WF_ONECAP) == 0 || origflags == WF_ONECAP)));
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
905 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
906
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
907
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
908 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
909 * Move to next spell error.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
910 * "curline" is TRUE for "z?": find word under/after cursor in the same line.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
911 * Return OK if found, FAIL otherwise.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
912 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
913 int
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
914 spell_move_to(dir, allwords, curline)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
915 int dir; /* FORWARD or BACKWARD */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
916 int allwords; /* TRUE for "[s" and "]s" */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
917 int curline;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
918 {
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
919 linenr_T lnum;
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
920 pos_T found_pos;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
921 char_u *line;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
922 char_u *p;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
923 int attr = 0;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
924 int len;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
925 int has_syntax = syntax_present(curbuf);
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
926 int col;
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
927 int can_spell;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
928
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
929 if (!curwin->w_p_spell || *curbuf->b_p_spl == NUL)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
930 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
931 EMSG(_("E756: Spell checking not enabled"));
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
932 return FAIL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
933 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
934
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
935 /*
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
936 * Start looking for bad word at the start of the line, because we can't
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
937 * start halfway a word, we don't know where it starts or ends.
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
938 *
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
939 * When searching backwards, we continue in the line to find the last
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
940 * bad word (in the cursor line: before the cursor).
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
941 */
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
942 lnum = curwin->w_cursor.lnum;
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
943 found_pos.lnum = 0;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
944
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
945 while (!got_int)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
946 {
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
947 line = ml_get(lnum);
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
948 p = line;
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
949
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
950 while (*p != NUL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
951 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
952 /* When searching backward don't search after the cursor. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
953 if (dir == BACKWARD
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
954 && lnum == curwin->w_cursor.lnum
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
955 && (colnr_T)(p - line) >= curwin->w_cursor.col)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
956 break;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
957
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
958 /* start of word */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
959 len = spell_check(curwin, p, &attr);
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
960
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
961 if (attr != 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
962 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
963 /* We found a bad word. Check the attribute. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
964 if (allwords || attr == highlight_attr[HLF_SPB])
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
965 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
966 /* When searching forward only accept a bad word after
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
967 * the cursor. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
968 if (dir == BACKWARD
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
969 || lnum > curwin->w_cursor.lnum
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
970 || (lnum == curwin->w_cursor.lnum
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
971 && (colnr_T)(curline ? p - line + len
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
972 : p - line)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
973 > curwin->w_cursor.col))
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
974 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
975 if (has_syntax)
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
976 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
977 col = p - line;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
978 (void)syn_get_id(lnum, (colnr_T)col,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
979 FALSE, &can_spell);
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
980
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
981 /* have to get the line again, a multi-line
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
982 * regexp may make it invalid */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
983 line = ml_get(lnum);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
984 p = line + col;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
985 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
986 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
987 can_spell = TRUE;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
988
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
989 if (can_spell)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
990 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
991 found_pos.lnum = lnum;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
992 found_pos.col = p - line;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
993 #ifdef FEAT_VIRTUALEDIT
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
994 found_pos.coladd = 0;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
995 #endif
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
996 if (dir == FORWARD)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
997 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
998 /* No need to search further. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
999 curwin->w_cursor = found_pos;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1000 return OK;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1001 }
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1002 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1003 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1004 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1005 attr = 0;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1006 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1007
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1008 /* advance to character after the word */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1009 p += len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1010 if (*p == NUL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1011 break;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1012 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1013
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1014 if (curline)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1015 return FAIL; /* only check cursor line */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1016
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1017 /* Advance to next line. */
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1018 if (dir == BACKWARD)
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1019 {
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1020 if (found_pos.lnum != 0)
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1021 {
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1022 /* Use the last match in the line. */
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1023 curwin->w_cursor = found_pos;
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1024 return OK;
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1025 }
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1026 if (lnum == 1)
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1027 return FAIL;
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1028 --lnum;
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1029 }
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1030 else
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1031 {
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1032 if (lnum == curbuf->b_ml.ml_line_count)
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1033 return FAIL;
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1034 ++lnum;
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1035 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1036
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1037 line_breakcheck();
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1038 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1039
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1040 return FAIL; /* interrupted */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1041 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1042
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1043 /*
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1044 * Load word list(s) for "lang" from Vim spell file(s).
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1045 * "lang" must be the language without the region: e.g., "en".
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1046 */
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1047 static void
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1048 spell_load_lang(lang)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1049 char_u *lang;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1050 {
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1051 char_u fname_enc[85];
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1052 int r;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1053 char_u langcp[MAXWLEN + 1];
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1054
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1055 /* 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
1056 * It's truncated when an error is detected. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1057 STRCPY(langcp, lang);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1058
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1059 /*
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1060 * Find the first spell file for "lang" in 'runtimepath' and load it.
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1061 */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1062 vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5,
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1063 "spell/%s.%s.spl", lang, spell_enc());
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1064 r = do_in_runtimepath(fname_enc, FALSE, spell_load_cb, &langcp);
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1065
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1066 if (r == FAIL && *langcp != NUL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1067 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1068 /* Try loading the ASCII version. */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1069 vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5,
272
ddada568db54 updated for version 7.0073
vimboss
parents: 260
diff changeset
1070 "spell/%s.ascii.spl", lang);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1071 r = do_in_runtimepath(fname_enc, FALSE, spell_load_cb, &langcp);
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1072 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1073
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1074 if (r == FAIL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1075 smsg((char_u *)_("Warning: Cannot find word list \"%s\""),
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1076 fname_enc + 6);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1077 else if (*langcp != NUL)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1078 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1079 /* Load all the additions. */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1080 STRCPY(fname_enc + STRLEN(fname_enc) - 3, "add.spl");
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1081 do_in_runtimepath(fname_enc, TRUE, spell_load_cb, &langcp);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1082 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1083 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1084
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1085 /*
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1086 * Return the encoding used for spell checking: Use 'encoding', except that we
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1087 * use "latin1" for "latin9". And limit to 60 characters (just in case).
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1088 */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1089 static char_u *
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1090 spell_enc()
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1091 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1092
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1093 #ifdef FEAT_MBYTE
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1094 if (STRLEN(p_enc) < 60 && STRCMP(p_enc, "iso-8859-15") != 0)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1095 return p_enc;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1096 #endif
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1097 return (char_u *)"latin1";
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1098 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1099
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1100 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1101 * Allocate a new slang_T.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1102 * Caller must fill "sl_next".
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1103 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1104 static slang_T *
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1105 slang_alloc(lang)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1106 char_u *lang;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1107 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1108 slang_T *lp;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1109
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1110 lp = (slang_T *)alloc_clear(sizeof(slang_T));
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1111 if (lp != NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1112 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1113 lp->sl_name = vim_strsave(lang);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1114 ga_init2(&lp->sl_rep, sizeof(fromto_T), 10);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1115 ga_init2(&lp->sl_sal, sizeof(fromto_T), 10);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1116 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1117 return lp;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1118 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1119
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1120 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1121 * Free the contents of an slang_T and the structure itself.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1122 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1123 static void
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1124 slang_free(lp)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1125 slang_T *lp;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1126 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1127 vim_free(lp->sl_name);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1128 vim_free(lp->sl_fname);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1129 slang_clear(lp);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1130 vim_free(lp);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1131 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1132
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1133 /*
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1134 * Clear an slang_T so that the file can be reloaded.
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1135 */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1136 static void
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1137 slang_clear(lp)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1138 slang_T *lp;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1139 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1140 garray_T *gap;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1141 fromto_T *ftp;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1142 int round;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1143
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1144 vim_free(lp->sl_fbyts);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1145 lp->sl_fbyts = NULL;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1146 vim_free(lp->sl_kbyts);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1147 lp->sl_kbyts = NULL;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1148 vim_free(lp->sl_fidxs);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1149 lp->sl_fidxs = NULL;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1150 vim_free(lp->sl_kidxs);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1151 lp->sl_kidxs = NULL;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1152
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1153 for (round = 1; round <= 2; ++round)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1154 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1155 gap = round == 1 ? &lp->sl_rep : &lp->sl_sal;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1156 while (gap->ga_len > 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1157 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1158 ftp = &((fromto_T *)gap->ga_data)[--gap->ga_len];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1159 vim_free(ftp->ft_from);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1160 vim_free(ftp->ft_to);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1161 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1162 ga_clear(gap);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1163 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1164
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1165 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1166 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1167 int todo = lp->sl_map_hash.ht_used;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1168 hashitem_T *hi;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1169
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1170 for (hi = lp->sl_map_hash.ht_array; todo > 0; ++hi)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1171 if (!HASHITEM_EMPTY(hi))
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1172 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1173 --todo;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1174 vim_free(hi->hi_key);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1175 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1176 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1177 hash_clear(&lp->sl_map_hash);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1178 #endif
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1179 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1180
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1181 /*
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1182 * Load one spell file and store the info into a slang_T.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1183 * Invoked through do_in_runtimepath().
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1184 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1185 static void
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1186 spell_load_cb(fname, cookie)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1187 char_u *fname;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1188 void *cookie; /* points to the language name */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1189 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1190 (void)spell_load_file(fname, (char_u *)cookie, NULL, FALSE);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1191 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1192
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1193 /*
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1194 * Load one spell file and store the info into a slang_T.
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1195 *
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1196 * This is invoked in two ways:
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1197 * - From spell_load_cb() to load a spell file for the first time. "lang" is
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1198 * the language name, "old_lp" is NULL. Will allocate an slang_T.
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1199 * - To reload a spell file that was changed. "lang" is NULL and "old_lp"
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1200 * points to the existing slang_T.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1201 * Returns the slang_T the spell file was loaded into. NULL for error.
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1202 */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1203 static slang_T *
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1204 spell_load_file(fname, lang, old_lp, silent)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1205 char_u *fname;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1206 char_u *lang;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1207 slang_T *old_lp;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1208 int silent; /* no error if file doesn't exist */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1209 {
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1210 FILE *fd;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1211 char_u buf[MAXWLEN + 1];
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1212 char_u *p;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1213 int i;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1214 int len;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1215 int round;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1216 char_u *save_sourcing_name = sourcing_name;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1217 linenr_T save_sourcing_lnum = sourcing_lnum;
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1218 int cnt, ccnt;
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1219 char_u *fol;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1220 slang_T *lp = NULL;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1221 garray_T *gap;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1222 fromto_T *ftp;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1223 int rr;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1224 short *first;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
1225 idx_T idx;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1226
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1227 fd = mch_fopen((char *)fname, "r");
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1228 if (fd == NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1229 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1230 if (!silent)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1231 EMSG2(_(e_notopen), fname);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1232 else if (p_verbose > 2)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1233 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1234 verbose_enter();
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1235 smsg((char_u *)e_notopen, fname);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1236 verbose_leave();
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1237 }
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1238 goto endFAIL;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1239 }
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1240 if (p_verbose > 2)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1241 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1242 verbose_enter();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1243 smsg((char_u *)_("Reading spell file \"%s\""), fname);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1244 verbose_leave();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1245 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1246
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1247 if (old_lp == NULL)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1248 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1249 lp = slang_alloc(lang);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1250 if (lp == NULL)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1251 goto endFAIL;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1252
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1253 /* Remember the file name, used to reload the file when it's updated. */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1254 lp->sl_fname = vim_strsave(fname);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1255 if (lp->sl_fname == NULL)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1256 goto endFAIL;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1257
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1258 /* Check for .add.spl. */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1259 lp->sl_add = strstr((char *)gettail(fname), ".add.") != NULL;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1260 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1261 else
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1262 lp = old_lp;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1263
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1264 /* Set sourcing_name, so that error messages mention the file name. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1265 sourcing_name = fname;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1266 sourcing_lnum = 0;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1267
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1268 /* <HEADER>: <fileID> <regioncnt> <regionname> ...
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1269 * <charflagslen> <charflags> <fcharslen> <fchars> */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1270 for (i = 0; i < VIMSPELLMAGICL; ++i)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1271 buf[i] = getc(fd); /* <fileID> */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1272 if (STRNCMP(buf, VIMSPELLMAGIC, VIMSPELLMAGICL) != 0)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1273 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1274 EMSG(_("E757: Wrong file ID in spell file"));
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1275 goto endFAIL;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1276 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1277
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1278 cnt = getc(fd); /* <regioncnt> */
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1279 if (cnt < 0)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1280 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1281 truncerr:
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1282 EMSG(_("E758: Truncated spell file"));
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1283 goto endFAIL;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1284 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1285 if (cnt > 8)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1286 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1287 formerr:
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1288 EMSG(_(e_format));
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1289 goto endFAIL;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1290 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1291 for (i = 0; i < cnt; ++i)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1292 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1293 lp->sl_regions[i * 2] = getc(fd); /* <regionname> */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1294 lp->sl_regions[i * 2 + 1] = getc(fd);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1295 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1296 lp->sl_regions[cnt * 2] = NUL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1297
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1298 cnt = getc(fd); /* <charflagslen> */
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1299 if (cnt > 0)
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1300 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1301 p = alloc((unsigned)cnt);
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1302 if (p == NULL)
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1303 goto endFAIL;
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1304 for (i = 0; i < cnt; ++i)
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1305 p[i] = getc(fd); /* <charflags> */
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1306
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1307 ccnt = (getc(fd) << 8) + getc(fd); /* <fcharslen> */
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1308 if (ccnt <= 0)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1309 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1310 vim_free(p);
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1311 goto formerr;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1312 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1313 fol = alloc((unsigned)ccnt + 1);
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1314 if (fol == NULL)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1315 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1316 vim_free(p);
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1317 goto endFAIL;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1318 }
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1319 for (i = 0; i < ccnt; ++i)
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1320 fol[i] = getc(fd); /* <fchars> */
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1321 fol[i] = NUL;
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1322
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
1323 /* Set the word-char flags and fill SPELL_ISUPPER() table. */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1324 i = set_spell_charflags(p, cnt, fol);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1325 vim_free(p);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1326 vim_free(fol);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1327 if (i == FAIL)
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1328 goto formerr;
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1329 }
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1330 else
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1331 {
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1332 /* When <charflagslen> is zero then <fcharlen> must also be zero. */
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1333 cnt = (getc(fd) << 8) + getc(fd);
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1334 if (cnt != 0)
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1335 goto formerr;
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1336 }
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1337
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1338 /* <SUGGEST> : <repcount> <rep> ...
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1339 * <salflags> <salcount> <sal> ...
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1340 * <maplen> <mapstr> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1341 for (round = 1; round <= 2; ++round)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1342 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1343 if (round == 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1344 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1345 gap = &lp->sl_rep;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1346 first = lp->sl_rep_first;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1347 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1348 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1349 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1350 gap = &lp->sl_sal;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1351 first = lp->sl_sal_first;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1352
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1353 i = getc(fd); /* <salflags> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1354 if (i & SAL_F0LLOWUP)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1355 lp->sl_followup = TRUE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1356 if (i & SAL_COLLAPSE)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1357 lp->sl_collapse = TRUE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1358 if (i & SAL_REM_ACCENTS)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1359 lp->sl_rem_accents = TRUE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1360 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1361
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1362 cnt = (getc(fd) << 8) + getc(fd); /* <repcount> or <salcount> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1363 if (cnt < 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1364 goto formerr;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1365
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1366 if (ga_grow(gap, cnt) == FAIL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1367 goto endFAIL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1368 for (; gap->ga_len < cnt; ++gap->ga_len)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1369 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1370 /* <rep> : <repfromlen> <repfrom> <reptolen> <repto> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1371 /* <sal> : <salfromlen> <salfrom> <saltolen> <salto> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1372 ftp = &((fromto_T *)gap->ga_data)[gap->ga_len];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1373 for (rr = 1; rr <= 2; ++rr)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1374 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1375 ccnt = getc(fd);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1376 if (ccnt < 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1377 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1378 if (rr == 2)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1379 vim_free(ftp->ft_from);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1380 goto formerr;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1381 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1382 if ((p = alloc(ccnt + 1)) == NULL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1383 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1384 if (rr == 2)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1385 vim_free(ftp->ft_from);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1386 goto endFAIL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1387 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1388 for (i = 0; i < ccnt; ++i)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1389 p[i] = getc(fd); /* <repfrom> or <salfrom> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1390 p[i] = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1391 if (rr == 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1392 ftp->ft_from = p;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1393 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1394 ftp->ft_to = p;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1395 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1396 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1397
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1398 /* Fill the first-index table. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1399 for (i = 0; i < 256; ++i)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1400 first[i] = -1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1401 for (i = 0; i < gap->ga_len; ++i)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1402 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1403 ftp = &((fromto_T *)gap->ga_data)[i];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1404 if (first[*ftp->ft_from] == -1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1405 first[*ftp->ft_from] = i;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1406 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1407 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1408
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1409 cnt = (getc(fd) << 8) + getc(fd); /* <maplen> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1410 if (cnt < 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1411 goto formerr;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1412 p = alloc(cnt + 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1413 if (p == NULL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1414 goto endFAIL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1415 for (i = 0; i < cnt; ++i)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1416 p[i] = getc(fd); /* <mapstr> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1417 p[i] = NUL;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1418 set_map_str(lp, p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
1419 vim_free(p);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1420
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1421
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1422 /* round 1: <LWORDTREE>
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1423 * round 2: <KWORDTREE> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1424 for (round = 1; round <= 2; ++round)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1425 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1426 /* The tree size was computed when writing the file, so that we can
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1427 * allocate it as one long block. <nodecount> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1428 len = (getc(fd) << 24) + (getc(fd) << 16) + (getc(fd) << 8) + getc(fd);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1429 if (len < 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1430 goto truncerr;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1431 if (len > 0)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1432 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1433 /* Allocate the byte array. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1434 p = lalloc((long_u)len, TRUE);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1435 if (p == NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1436 goto endFAIL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1437 if (round == 1)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1438 lp->sl_fbyts = p;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1439 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1440 lp->sl_kbyts = p;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1441
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1442 /* Allocate the index array. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1443 p = lalloc_clear((long_u)(len * sizeof(int)), TRUE);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1444 if (p == NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1445 goto endFAIL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1446 if (round == 1)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
1447 lp->sl_fidxs = (idx_T *)p;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1448 else
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
1449 lp->sl_kidxs = (idx_T *)p;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1450
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1451
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1452 /* Read the tree and store it in the array. */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
1453 idx = read_tree(fd,
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1454 round == 1 ? lp->sl_fbyts : lp->sl_kbyts,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1455 round == 1 ? lp->sl_fidxs : lp->sl_kidxs,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1456 len, 0);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
1457 if (idx == -1)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1458 goto truncerr;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
1459 if (idx < 0)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1460 goto formerr;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1461 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1462 }
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
1463
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1464 /* For a new file link it in the list of spell files. */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1465 if (old_lp == NULL)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1466 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1467 lp->sl_next = first_lang;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1468 first_lang = lp;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1469 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1470
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1471 goto endOK;
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1472
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1473 endFAIL:
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1474 if (lang != NULL)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1475 /* truncating the name signals the error to spell_load_lang() */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1476 *lang = NUL;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1477 if (lp != NULL && old_lp == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1478 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1479 slang_free(lp);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1480 lp = NULL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1481 }
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1482
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
1483 endOK:
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1484 if (fd != NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1485 fclose(fd);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1486 sourcing_name = save_sourcing_name;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1487 sourcing_lnum = save_sourcing_lnum;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1488
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1489 return lp;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1490 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1491
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1492 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1493 * Read one row of siblings from the spell file and store it in the byte array
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1494 * "byts" and index array "idxs". Recursively read the children.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1495 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1496 * NOTE: The code here must match put_tree().
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1497 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1498 * Returns the index follosing the siblings.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1499 * Returns -1 if the file is shorter than expected.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1500 * Returns -2 if there is a format error.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1501 */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
1502 static idx_T
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1503 read_tree(fd, byts, idxs, maxidx, startidx)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1504 FILE *fd;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1505 char_u *byts;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
1506 idx_T *idxs;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1507 int maxidx; /* size of arrays */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
1508 idx_T startidx; /* current index in "byts" and "idxs" */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1509 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1510 int len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1511 int i;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1512 int n;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
1513 idx_T idx = startidx;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1514 int c;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1515 #define SHARED_MASK 0x8000000
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1516
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1517 len = getc(fd); /* <siblingcount> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1518 if (len <= 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1519 return -1;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1520
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1521 if (startidx + len >= maxidx)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1522 return -2;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1523 byts[idx++] = len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1524
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1525 /* Read the byte values, flag/region bytes and shared indexes. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1526 for (i = 1; i <= len; ++i)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1527 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1528 c = getc(fd); /* <byte> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1529 if (c < 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1530 return -1;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1531 if (c <= BY_SPECIAL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1532 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1533 if (c == BY_NOFLAGS)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1534 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1535 /* No flags, all regions. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1536 idxs[idx] = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1537 c = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1538 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1539 else if (c == BY_FLAGS)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1540 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1541 /* Read flags and option region. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1542 c = getc(fd); /* <flags> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1543 if (c & WF_REGION)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1544 c = (getc(fd) << 8) + c; /* <region> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1545 idxs[idx] = c;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1546 c = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1547 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1548 else /* c == BY_INDEX */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1549 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1550 /* <nodeidx> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1551 n = (getc(fd) << 16) + (getc(fd) << 8) + getc(fd);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1552 if (n < 0 || n >= maxidx)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1553 return -2;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1554 idxs[idx] = n + SHARED_MASK;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1555 c = getc(fd); /* <xbyte> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1556 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1557 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1558 byts[idx++] = c;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1559 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1560
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1561 /* Recursively read the children for non-shared siblings.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1562 * Skip the end-of-word ones (zero byte value) and the shared ones (and
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1563 * remove SHARED_MASK) */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1564 for (i = 1; i <= len; ++i)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1565 if (byts[startidx + i] != 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1566 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1567 if (idxs[startidx + i] & SHARED_MASK)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1568 idxs[startidx + i] &= ~SHARED_MASK;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1569 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1570 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1571 idxs[startidx + i] = idx;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1572 idx = read_tree(fd, byts, idxs, maxidx, idx);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1573 if (idx < 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1574 break;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1575 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1576 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1577
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1578 return idx;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1579 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1580
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1581 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1582 * Parse 'spelllang' and set buf->b_langp accordingly.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1583 * Returns an error message or NULL.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1584 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1585 char_u *
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1586 did_set_spelllang(buf)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1587 buf_T *buf;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1588 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1589 garray_T ga;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1590 char_u *lang;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1591 char_u *e;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1592 char_u *region;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1593 int region_mask;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1594 slang_T *lp;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1595 int c;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1596 char_u lbuf[MAXWLEN + 1];
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1597 char_u spf_name[MAXPATHL];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1598 int did_spf = FALSE;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1599
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1600 ga_init2(&ga, sizeof(langp_T), 2);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1601
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1602 /* Get the name of the .spl file associated with 'spellfile'. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1603 if (*buf->b_p_spf == NUL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1604 did_spf = TRUE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1605 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1606 vim_snprintf((char *)spf_name, sizeof(spf_name), "%s.spl",
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1607 buf->b_p_spf);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1608
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1609 /* loop over comma separated languages. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1610 for (lang = buf->b_p_spl; *lang != NUL; lang = e)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1611 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1612 e = vim_strchr(lang, ',');
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1613 if (e == NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1614 e = lang + STRLEN(lang);
240
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
1615 region = NULL;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1616 if (e > lang + 2)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1617 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1618 if (e - lang >= MAXWLEN)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1619 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1620 ga_clear(&ga);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1621 return e_invarg;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1622 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1623 if (lang[2] == '_')
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1624 region = lang + 3;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1625 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1626
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1627 /* Check if we loaded this language before. */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1628 for (lp = first_lang; lp != NULL; lp = lp->sl_next)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1629 if (STRNICMP(lp->sl_name, lang, 2) == 0)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1630 break;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1631
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1632 if (lp == NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1633 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1634 /* Not found, load the language. */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1635 vim_strncpy(lbuf, lang, e - lang);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1636 if (region != NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1637 mch_memmove(lbuf + 2, lbuf + 5, e - lang - 4);
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1638 spell_load_lang(lbuf);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1639 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1640
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1641 /*
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1642 * Loop over the languages, there can be several files for each.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1643 */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1644 for (lp = first_lang; lp != NULL; lp = lp->sl_next)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1645 if (STRNICMP(lp->sl_name, lang, 2) == 0)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1646 {
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1647 region_mask = REGION_ALL;
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1648 if (region != NULL)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1649 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1650 /* find region in sl_regions */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1651 c = find_region(lp->sl_regions, region);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1652 if (c == REGION_ALL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1653 {
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1654 if (!lp->sl_add)
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1655 {
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1656 c = *e;
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1657 *e = NUL;
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1658 smsg((char_u *)_("Warning: region %s not supported"),
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1659 lang);
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1660 *e = c;
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1661 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1662 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1663 else
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1664 region_mask = 1 << c;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1665 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1666
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1667 if (ga_grow(&ga, 1) == FAIL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1668 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1669 ga_clear(&ga);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1670 return e_outofmem;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1671 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1672 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = lp;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1673 LANGP_ENTRY(ga, ga.ga_len)->lp_region = region_mask;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1674 ++ga.ga_len;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1675
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1676 /* Check if this is the 'spellfile' spell file. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1677 if (fullpathcmp(spf_name, lp->sl_fname, FALSE) == FPC_SAME)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1678 did_spf = TRUE;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1679 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1680
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1681 if (*e == ',')
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1682 ++e;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1683 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1684
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1685 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1686 * Make sure the 'spellfile' file is loaded. It may be in 'runtimepath',
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1687 * then it's probably loaded above already. Otherwise load it here.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1688 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1689 if (!did_spf)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1690 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1691 for (lp = first_lang; lp != NULL; lp = lp->sl_next)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1692 if (fullpathcmp(spf_name, lp->sl_fname, FALSE) == FPC_SAME)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1693 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1694 if (lp == NULL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1695 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1696 vim_strncpy(lbuf, gettail(spf_name), 2);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1697 lp = spell_load_file(spf_name, lbuf, NULL, TRUE);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1698 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1699 if (lp != NULL && ga_grow(&ga, 1) == OK)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1700 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1701 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = lp;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1702 LANGP_ENTRY(ga, ga.ga_len)->lp_region = REGION_ALL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1703 ++ga.ga_len;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1704 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1705 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1706
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1707 /* Add a NULL entry to mark the end of the list. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1708 if (ga_grow(&ga, 1) == FAIL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1709 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1710 ga_clear(&ga);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1711 return e_outofmem;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1712 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1713 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = NULL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1714 ++ga.ga_len;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1715
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1716 /* Everything is fine, store the new b_langp value. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1717 ga_clear(&buf->b_langp);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1718 buf->b_langp = ga;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1719
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1720 return NULL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1721 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1722
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1723 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1724 * Find the region "region[2]" in "rp" (points to "sl_regions").
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1725 * Each region is simply stored as the two characters of it's name.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1726 * Returns the index if found, REGION_ALL if not found.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1727 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1728 static int
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1729 find_region(rp, region)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1730 char_u *rp;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1731 char_u *region;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1732 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1733 int i;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1734
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1735 for (i = 0; ; i += 2)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1736 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1737 if (rp[i] == NUL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1738 return REGION_ALL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1739 if (rp[i] == region[0] && rp[i + 1] == region[1])
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1740 break;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1741 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1742 return i / 2;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1743 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1744
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1745 /*
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1746 * Return case type of word:
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1747 * w word 0
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1748 * Word WF_ONECAP
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1749 * W WORD WF_ALLCAP
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1750 * WoRd wOrd WF_KEEPCAP
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1751 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1752 static int
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1753 captype(word, end)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1754 char_u *word;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1755 char_u *end; /* When NULL use up to NUL byte. */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1756 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1757 char_u *p;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1758 int c;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1759 int firstcap;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1760 int allcap;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1761 int past_second = FALSE; /* past second word char */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1762
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1763 /* find first letter */
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1764 for (p = word; !SPELL_ISWORDP(p); mb_ptr_adv(p))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1765 if (end == NULL ? *p == NUL : p >= end)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1766 return 0; /* only non-word characters, illegal word */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1767 #ifdef FEAT_MBYTE
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1768 if (has_mbyte)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1769 c = mb_ptr2char_adv(&p);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1770 else
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1771 #endif
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1772 c = *p++;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
1773 firstcap = allcap = SPELL_ISUPPER(c);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1774
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1775 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1776 * Need to check all letters to find a word with mixed upper/lower.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1777 * But a word with an upper char only at start is a ONECAP.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1778 */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1779 for ( ; end == NULL ? *p != NUL : p < end; mb_ptr_adv(p))
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1780 if (SPELL_ISWORDP(p))
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1781 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1782 #ifdef FEAT_MBYTE
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1783 c = mb_ptr2char(p);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1784 #else
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1785 c = *p;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1786 #endif
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
1787 if (!SPELL_ISUPPER(c))
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1788 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1789 /* UUl -> KEEPCAP */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1790 if (past_second && allcap)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1791 return WF_KEEPCAP;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1792 allcap = FALSE;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1793 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1794 else if (!allcap)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1795 /* UlU -> KEEPCAP */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1796 return WF_KEEPCAP;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1797 past_second = TRUE;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1798 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1799
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1800 if (allcap)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1801 return WF_ALLCAP;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1802 if (firstcap)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1803 return WF_ONECAP;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1804 return 0;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1805 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1806
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1807 # if defined(FEAT_MBYTE) || defined(PROTO)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1808 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1809 * Clear all spelling tables and reload them.
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1810 * Used after 'encoding' is set and when ":mkspell" was used.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1811 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1812 void
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1813 spell_reload()
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1814 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1815 buf_T *buf;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1816 slang_T *lp;
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1817 win_T *wp;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1818
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1819 /* Initialize the table for SPELL_ISWORDP(). */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1820 init_spell_chartab();
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1821
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1822 /* Unload all allocated memory. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1823 while (first_lang != NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1824 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1825 lp = first_lang;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1826 first_lang = lp->sl_next;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1827 slang_free(lp);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1828 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1829
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1830 /* Go through all buffers and handle 'spelllang'. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1831 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1832 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1833 ga_clear(&buf->b_langp);
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1834
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1835 /* Only load the wordlists when 'spelllang' is set and there is a
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1836 * window for this buffer in which 'spell' is set. */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1837 if (*buf->b_p_spl != NUL)
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1838 {
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1839 FOR_ALL_WINDOWS(wp)
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1840 if (wp->w_buffer == buf && wp->w_p_spell)
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1841 {
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1842 (void)did_set_spelllang(buf);
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1843 # ifdef FEAT_WINDOWS
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1844 break;
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1845 # endif
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1846 }
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1847 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1848 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1849 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1850 # endif
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1851
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1852 /*
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1853 * Reload the spell file "fname" if it's loaded.
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1854 */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1855 static void
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1856 spell_reload_one(fname, added_word)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1857 char_u *fname;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1858 int added_word; /* invoked through "zg" */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1859 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1860 slang_T *lp;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1861 int didit = FALSE;
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1862
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1863 for (lp = first_lang; lp != NULL; lp = lp->sl_next)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1864 if (fullpathcmp(fname, lp->sl_fname, FALSE) == FPC_SAME)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1865 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1866 slang_clear(lp);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1867 (void)spell_load_file(fname, NULL, lp, FALSE);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1868 redraw_all_later(NOT_VALID);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1869 didit = TRUE;
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1870 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1871
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1872 /* When "zg" was used and the file wasn't loaded yet, should redo
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1873 * 'spelllang' to get it loaded. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1874 if (added_word && !didit)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1875 did_set_spelllang(curbuf);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1876 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1877
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1878
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1879 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1880 * Functions for ":mkspell".
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1881 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1882
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1883 #define MAXLINELEN 500 /* Maximum length in bytes of a line in a .aff
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1884 and .dic file. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1885 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1886 * Main structure to store the contents of a ".aff" file.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1887 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1888 typedef struct afffile_S
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1889 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1890 char_u *af_enc; /* "SET", normalized, alloc'ed string or NULL */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1891 int af_rar; /* RAR ID for rare word */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1892 int af_kep; /* KEP ID for keep-case word */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1893 hashtab_T af_pref; /* hashtable for prefixes, affheader_T */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1894 hashtab_T af_suff; /* hashtable for suffixes, affheader_T */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1895 } afffile_T;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1896
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1897 typedef struct affentry_S affentry_T;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1898 /* Affix entry from ".aff" file. Used for prefixes and suffixes. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1899 struct affentry_S
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1900 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1901 affentry_T *ae_next; /* next affix with same name/number */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1902 char_u *ae_chop; /* text to chop off basic word (can be NULL) */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1903 char_u *ae_add; /* text to add to basic word (can be NULL) */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1904 char_u *ae_cond; /* condition (NULL for ".") */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1905 regprog_T *ae_prog; /* regexp program for ae_cond or NULL */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1906 };
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1907
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1908 /* Affix header from ".aff" file. Used for af_pref and af_suff. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1909 typedef struct affheader_S
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1910 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1911 char_u ah_key[2]; /* key for hashtable == name of affix entry */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1912 int ah_combine; /* suffix may combine with prefix */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1913 affentry_T *ah_first; /* first affix entry */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1914 } affheader_T;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1915
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1916 #define HI2AH(hi) ((affheader_T *)(hi)->hi_key)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1917
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1918 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1919 * Structure that is used to store the items in the word tree. This avoids
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1920 * the need to keep track of each allocated thing, it's freed all at once
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1921 * after ":mkspell" is done.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1922 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1923 #define SBLOCKSIZE 16000 /* size of sb_data */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1924 typedef struct sblock_S sblock_T;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1925 struct sblock_S
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1926 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1927 sblock_T *sb_next; /* next block in list */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1928 int sb_used; /* nr of bytes already in use */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1929 char_u sb_data[1]; /* data, actually longer */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1930 };
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1931
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1932 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1933 * A node in the tree.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1934 */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1935 typedef struct wordnode_S wordnode_T;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1936 struct wordnode_S
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1937 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1938 char_u wn_hashkey[6]; /* room for the hash key */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1939 wordnode_T *wn_next; /* next node with same hash key */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1940 wordnode_T *wn_child; /* child (next byte in word) */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1941 wordnode_T *wn_sibling; /* next sibling (alternate byte in word,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1942 always sorted) */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1943 wordnode_T *wn_wnode; /* parent node that will write this node */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1944 int wn_index; /* index in written nodes (valid after first
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1945 round) */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1946 char_u wn_byte; /* Byte for this node. NUL for word end */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1947 char_u wn_flags; /* when wn_byte is NUL: WF_ flags */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1948 char_u wn_region; /* when wn_byte is NUL: region mask */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1949 };
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1950
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1951 #define HI2WN(hi) (wordnode_T *)((hi)->hi_key)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1952
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1953 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1954 * Info used while reading the spell files.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1955 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1956 typedef struct spellinfo_S
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1957 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1958 wordnode_T *si_foldroot; /* tree with case-folded words */
334
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
1959 long si_foldwcount; /* nr of words in si_foldroot */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1960 wordnode_T *si_keeproot; /* tree with keep-case words */
334
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
1961 long si_keepwcount; /* nr of words in si_keeproot */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1962 sblock_T *si_blocks; /* memory blocks used */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1963 int si_ascii; /* handling only ASCII words */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1964 int si_add; /* addition file */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1965 int si_region; /* region mask */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1966 vimconv_T si_conv; /* for conversion to 'encoding' */
302
250611b3068d updated for version 7.0080
vimboss
parents: 300
diff changeset
1967 int si_memtot; /* runtime memory used */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1968 int si_verbose; /* verbose messages */
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1969 int si_region_count; /* number of regions supported (1 when there
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1970 are no regions) */
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1971 char_u si_region_name[16]; /* region names (if count > 1) */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1972
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1973 garray_T si_rep; /* list of fromto_T entries from REP lines */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1974 garray_T si_sal; /* list of fromto_T entries from SAL lines */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1975 int si_followup; /* soundsalike: ? */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1976 int si_collapse; /* soundsalike: ? */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1977 int si_rem_accents; /* soundsalike: remove accents */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1978 garray_T si_map; /* MAP info concatenated */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1979 } spellinfo_T;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1980
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1981 static afffile_T *spell_read_aff __ARGS((char_u *fname, spellinfo_T *spin));
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1982 static void add_fromto __ARGS((spellinfo_T *spin, garray_T *gap, char_u *from, char_u *to));
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1983 static int sal_to_bool __ARGS((char_u *s));
240
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
1984 static int has_non_ascii __ARGS((char_u *s));
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1985 static void spell_free_aff __ARGS((afffile_T *aff));
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1986 static int spell_read_dic __ARGS((char_u *fname, spellinfo_T *spin, afffile_T *affile));
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1987 static int store_aff_word __ARGS((char_u *word, spellinfo_T *spin, char_u *afflist, hashtab_T *ht, hashtab_T *xht, int comb, int flags));
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1988 static int spell_read_wordfile __ARGS((char_u *fname, spellinfo_T *spin));
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1989 static void *getroom __ARGS((sblock_T **blp, size_t len));
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1990 static char_u *getroom_save __ARGS((sblock_T **blp, char_u *s));
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1991 static void free_blocks __ARGS((sblock_T *bl));
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1992 static wordnode_T *wordtree_alloc __ARGS((sblock_T **blp));
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1993 static int store_word __ARGS((char_u *word, spellinfo_T *spin, int flags, int region));
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1994 static int tree_add_word __ARGS((char_u *word, wordnode_T *tree, int flags, int region, sblock_T **blp));
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1995 static void wordtree_compress __ARGS((wordnode_T *root, spellinfo_T *spin));
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1996 static int node_compress __ARGS((wordnode_T *node, hashtab_T *ht, int *tot));
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1997 static int node_equal __ARGS((wordnode_T *n1, wordnode_T *n2));
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
1998 static void write_vim_spell __ARGS((char_u *fname, spellinfo_T *spin));
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1999 static int put_tree __ARGS((FILE *fd, wordnode_T *node, int index, int regionmask));
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2000 static void mkspell __ARGS((int fcount, char_u **fnames, int ascii, int overwrite, int added_word));
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2001 static void init_spellfile __ARGS((void));
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2002
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2003 /*
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2004 * Read the affix file "fname".
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2005 * Returns an afffile_T, NULL for complete failure.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2006 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2007 static afffile_T *
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2008 spell_read_aff(fname, spin)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2009 char_u *fname;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2010 spellinfo_T *spin;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2011 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2012 FILE *fd;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2013 afffile_T *aff;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2014 char_u rline[MAXLINELEN];
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2015 char_u *line;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2016 char_u *pc = NULL;
334
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2017 #define MAXITEMCNT 7
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2018 char_u *(items[MAXITEMCNT]);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2019 int itemcnt;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2020 char_u *p;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2021 int lnum = 0;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2022 affheader_T *cur_aff = NULL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2023 int aff_todo = 0;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2024 hashtab_T *tp;
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2025 char_u *low = NULL;
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2026 char_u *fol = NULL;
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2027 char_u *upp = NULL;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2028 static char *e_affname = N_("Affix name too long in %s line %d: %s");
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2029 int do_rep;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2030 int do_sal;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2031 int do_map;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2032 int found_map = FALSE;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2033 hashitem_T *hi;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2034
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2035 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2036 * Open the file.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2037 */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2038 fd = mch_fopen((char *)fname, "r");
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2039 if (fd == NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2040 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2041 EMSG2(_(e_notopen), fname);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2042 return NULL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2043 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2044
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2045 if (spin->si_verbose || p_verbose > 2)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2046 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2047 if (!spin->si_verbose)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2048 verbose_enter();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2049 smsg((char_u *)_("Reading affix file %s..."), fname);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2050 out_flush();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2051 if (!spin->si_verbose)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2052 verbose_leave();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2053 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2054
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2055 /* Only do REP lines when not done in another .aff file already. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2056 do_rep = spin->si_rep.ga_len == 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2057
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2058 /* Only do SAL lines when not done in another .aff file already. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2059 do_sal = spin->si_sal.ga_len == 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2060
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2061 /* Only do MAP lines when not done in another .aff file already. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2062 do_map = spin->si_map.ga_len == 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2063
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2064 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2065 * Allocate and init the afffile_T structure.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2066 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2067 aff = (afffile_T *)getroom(&spin->si_blocks, sizeof(afffile_T));
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2068 if (aff == NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2069 return NULL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2070 hash_init(&aff->af_pref);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2071 hash_init(&aff->af_suff);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2072
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2073 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2074 * Read all the lines in the file one by one.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2075 */
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2076 while (!vim_fgets(rline, MAXLINELEN, fd) && !got_int)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2077 {
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2078 line_breakcheck();
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2079 ++lnum;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2080
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2081 /* Skip comment lines. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2082 if (*rline == '#')
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2083 continue;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2084
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2085 /* Convert from "SET" to 'encoding' when needed. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2086 vim_free(pc);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2087 #ifdef FEAT_MBYTE
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2088 if (spin->si_conv.vc_type != CONV_NONE)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2089 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2090 pc = string_convert(&spin->si_conv, rline, NULL);
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2091 if (pc == NULL)
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2092 {
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2093 smsg((char_u *)_("Conversion failure for word in %s line %d: %s"),
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2094 fname, lnum, rline);
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2095 continue;
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2096 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2097 line = pc;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2098 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2099 else
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2100 #endif
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2101 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2102 pc = NULL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2103 line = rline;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2104 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2105
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2106 /* Split the line up in white separated items. Put a NUL after each
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2107 * item. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2108 itemcnt = 0;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2109 for (p = line; ; )
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2110 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2111 while (*p != NUL && *p <= ' ') /* skip white space and CR/NL */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2112 ++p;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2113 if (*p == NUL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2114 break;
334
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2115 if (itemcnt == MAXITEMCNT) /* too many items */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2116 break;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2117 items[itemcnt++] = p;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2118 while (*p > ' ') /* skip until white space or CR/NL */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2119 ++p;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2120 if (*p == NUL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2121 break;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2122 *p++ = NUL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2123 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2124
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2125 /* Handle non-empty lines. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2126 if (itemcnt > 0)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2127 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2128 if (STRCMP(items[0], "SET") == 0 && itemcnt == 2
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2129 && aff->af_enc == NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2130 {
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2131 #ifdef FEAT_MBYTE
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2132 /* Setup for conversion from "ENC" to 'encoding'. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2133 aff->af_enc = enc_canonize(items[1]);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2134 if (aff->af_enc != NULL && !spin->si_ascii
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2135 && convert_setup(&spin->si_conv, aff->af_enc,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2136 p_enc) == FAIL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2137 smsg((char_u *)_("Conversion in %s not supported: from %s to %s"),
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2138 fname, aff->af_enc, p_enc);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2139 #else
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2140 smsg((char_u *)_("Conversion in %s not supported"), fname);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2141 #endif
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2142 }
302
250611b3068d updated for version 7.0080
vimboss
parents: 300
diff changeset
2143 else if (STRCMP(items[0], "NOSPLITSUGS") == 0 && itemcnt == 1)
250611b3068d updated for version 7.0080
vimboss
parents: 300
diff changeset
2144 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2145 /* ignored, we always split */
302
250611b3068d updated for version 7.0080
vimboss
parents: 300
diff changeset
2146 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2147 else if (STRCMP(items[0], "TRY") == 0 && itemcnt == 2)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2148 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2149 /* ignored, we look in the tree for what chars may appear */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2150 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2151 else if (STRCMP(items[0], "RAR") == 0 && itemcnt == 2
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2152 && aff->af_rar == 0)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2153 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2154 aff->af_rar = items[1][0];
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2155 if (items[1][1] != NUL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2156 smsg((char_u *)_(e_affname), fname, lnum, items[1]);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2157 }
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2158 else if (STRCMP(items[0], "KEP") == 0 && itemcnt == 2
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2159 && aff->af_kep == 0)
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2160 {
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2161 aff->af_kep = items[1][0];
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2162 if (items[1][1] != NUL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2163 smsg((char_u *)_(e_affname), fname, lnum, items[1]);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2164 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2165 else if ((STRCMP(items[0], "PFX") == 0
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2166 || STRCMP(items[0], "SFX") == 0)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2167 && aff_todo == 0
334
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2168 && itemcnt >= 4)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2169 {
334
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2170 /* Myspell allows extra text after the item, but that might
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2171 * mean mistakes go unnoticed. Require a comment-starter. */
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2172 if (itemcnt > 4 && *items[4] != '#')
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2173 smsg((char_u *)_("Trailing text in %s line %d: %s"),
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2174 fname, lnum, items[4]);
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2175
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2176 /* New affix letter. */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2177 cur_aff = (affheader_T *)getroom(&spin->si_blocks,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2178 sizeof(affheader_T));
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2179 if (cur_aff == NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2180 break;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2181 cur_aff->ah_key[0] = *items[1];
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2182 cur_aff->ah_key[1] = NUL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2183 if (items[1][1] != NUL)
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2184 smsg((char_u *)_(e_affname), fname, lnum, items[1]);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2185 if (*items[2] == 'Y')
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2186 cur_aff->ah_combine = TRUE;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2187 else if (*items[2] != 'N')
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2188 smsg((char_u *)_("Expected Y or N in %s line %d: %s"),
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2189 fname, lnum, items[2]);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2190 if (*items[0] == 'P')
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2191 tp = &aff->af_pref;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2192 else
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2193 tp = &aff->af_suff;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2194 aff_todo = atoi((char *)items[3]);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2195 hi = hash_find(tp, cur_aff->ah_key);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2196 if (!HASHITEM_EMPTY(hi))
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2197 {
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2198 smsg((char_u *)_("Duplicate affix in %s line %d: %s"),
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2199 fname, lnum, items[1]);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2200 aff_todo = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2201 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2202 else
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2203 hash_add(tp, cur_aff->ah_key);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2204 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2205 else if ((STRCMP(items[0], "PFX") == 0
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2206 || STRCMP(items[0], "SFX") == 0)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2207 && aff_todo > 0
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2208 && STRCMP(cur_aff->ah_key, items[1]) == 0
334
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2209 && itemcnt >= 5)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2210 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2211 affentry_T *aff_entry;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2212
334
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2213 /* Myspell allows extra text after the item, but that might
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2214 * mean mistakes go unnoticed. Require a comment-starter. */
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2215 if (itemcnt > 5 && *items[5] != '#')
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2216 smsg((char_u *)_("Trailing text in %s line %d: %s"),
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2217 fname, lnum, items[5]);
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2218
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2219 /* New item for an affix letter. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2220 --aff_todo;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2221 aff_entry = (affentry_T *)getroom(&spin->si_blocks,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2222 sizeof(affentry_T));
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2223 if (aff_entry == NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2224 break;
240
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2225
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2226 if (STRCMP(items[2], "0") != 0)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2227 aff_entry->ae_chop = getroom_save(&spin->si_blocks,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2228 items[2]);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2229 if (STRCMP(items[3], "0") != 0)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2230 aff_entry->ae_add = getroom_save(&spin->si_blocks,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2231 items[3]);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2232
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2233 /* Don't use an affix entry with non-ASCII characters when
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2234 * "spin->si_ascii" is TRUE. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2235 if (!spin->si_ascii || !(has_non_ascii(aff_entry->ae_chop)
240
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2236 || has_non_ascii(aff_entry->ae_add)))
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2237 {
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2238 aff_entry->ae_next = cur_aff->ah_first;
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2239 cur_aff->ah_first = aff_entry;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2240
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2241 if (STRCMP(items[4], ".") != 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2242 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2243 char_u buf[MAXLINELEN];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2244
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2245 aff_entry->ae_cond = getroom_save(&spin->si_blocks,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2246 items[4]);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2247 if (*items[0] == 'P')
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2248 sprintf((char *)buf, "^%s", items[4]);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2249 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2250 sprintf((char *)buf, "%s$", items[4]);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2251 aff_entry->ae_prog = vim_regcomp(buf,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2252 RE_MAGIC + RE_STRING);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2253 }
240
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2254 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2255 }
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2256 else if (STRCMP(items[0], "FOL") == 0 && itemcnt == 2)
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2257 {
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2258 if (fol != NULL)
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2259 smsg((char_u *)_("Duplicate FOL in %s line %d"),
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2260 fname, lnum);
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2261 else
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2262 fol = vim_strsave(items[1]);
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2263 }
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2264 else if (STRCMP(items[0], "LOW") == 0 && itemcnt == 2)
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2265 {
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2266 if (low != NULL)
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2267 smsg((char_u *)_("Duplicate LOW in %s line %d"),
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2268 fname, lnum);
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2269 else
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2270 low = vim_strsave(items[1]);
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2271 }
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2272 else if (STRCMP(items[0], "UPP") == 0 && itemcnt == 2)
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2273 {
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2274 if (upp != NULL)
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2275 smsg((char_u *)_("Duplicate UPP in %s line %d"),
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2276 fname, lnum);
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2277 else
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2278 upp = vim_strsave(items[1]);
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2279 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2280 else if (STRCMP(items[0], "REP") == 0 && itemcnt == 2)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2281 {
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2282 /* Ignore REP count */;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2283 if (!isdigit(*items[1]))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2284 smsg((char_u *)_("Expected REP count in %s line %d"),
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2285 fname, lnum);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2286 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2287 else if (STRCMP(items[0], "REP") == 0 && itemcnt == 3)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2288 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2289 /* REP item */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2290 if (do_rep)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2291 add_fromto(spin, &spin->si_rep, items[1], items[2]);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2292 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2293 else if (STRCMP(items[0], "MAP") == 0 && itemcnt == 2)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2294 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2295 /* MAP item or count */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2296 if (!found_map)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2297 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2298 /* First line contains the count. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2299 found_map = TRUE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2300 if (!isdigit(*items[1]))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2301 smsg((char_u *)_("Expected MAP count in %s line %d"),
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2302 fname, lnum);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2303 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2304 else if (do_map)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2305 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2306 /* We simply concatenate all the MAP strings, separated by
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2307 * slashes. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2308 ga_concat(&spin->si_map, items[1]);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2309 ga_append(&spin->si_map, '/');
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2310 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2311 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2312 else if (STRCMP(items[0], "SAL") == 0 && itemcnt == 3)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2313 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2314 if (do_sal)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2315 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2316 /* SAL item (sounds-a-like)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2317 * Either one of the known keys or a from-to pair. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2318 if (STRCMP(items[1], "followup") == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2319 spin->si_followup = sal_to_bool(items[2]);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2320 else if (STRCMP(items[1], "collapse_result") == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2321 spin->si_collapse = sal_to_bool(items[2]);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2322 else if (STRCMP(items[1], "remove_accents") == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2323 spin->si_rem_accents = sal_to_bool(items[2]);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2324 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2325 /* when "to" is "_" it means empty */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2326 add_fromto(spin, &spin->si_sal, items[1],
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2327 STRCMP(items[2], "_") == 0 ? (char_u *)""
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2328 : items[2]);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2329 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2330 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2331 else
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2332 smsg((char_u *)_("Unrecognized item in %s line %d: %s"),
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2333 fname, lnum, items[0]);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2334 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2335 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2336
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2337 if (fol != NULL || low != NULL || upp != NULL)
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2338 {
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2339 /*
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2340 * Don't write a word table for an ASCII file, so that we don't check
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2341 * for conflicts with a word table that matches 'encoding'.
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2342 * Don't write one for utf-8 either, we use utf_*() and
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2343 * mb_get_class(), the list of chars in the file will be incomplete.
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2344 */
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2345 if (!spin->si_ascii
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2346 #ifdef FEAT_MBYTE
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2347 && !enc_utf8
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2348 #endif
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2349 )
260
ed33f83b42d8 updated for version 7.0071
vimboss
parents: 255
diff changeset
2350 {
ed33f83b42d8 updated for version 7.0071
vimboss
parents: 255
diff changeset
2351 if (fol == NULL || low == NULL || upp == NULL)
ed33f83b42d8 updated for version 7.0071
vimboss
parents: 255
diff changeset
2352 smsg((char_u *)_("Missing FOL/LOW/UPP line in %s"), fname);
ed33f83b42d8 updated for version 7.0071
vimboss
parents: 255
diff changeset
2353 else
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2354 (void)set_spell_chartab(fol, low, upp);
260
ed33f83b42d8 updated for version 7.0071
vimboss
parents: 255
diff changeset
2355 }
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2356
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2357 vim_free(fol);
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2358 vim_free(low);
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2359 vim_free(upp);
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2360 }
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2361
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2362 vim_free(pc);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2363 fclose(fd);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2364 return aff;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2365 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2366
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2367 /*
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2368 * Add a from-to item to "gap". Used for REP and SAL items.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2369 * They are stored case-folded.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2370 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2371 static void
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2372 add_fromto(spin, gap, from, to)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2373 spellinfo_T *spin;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2374 garray_T *gap;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2375 char_u *from;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2376 char_u *to;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2377 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2378 fromto_T *ftp;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2379 char_u word[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2380
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2381 if (ga_grow(gap, 1) == OK)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2382 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2383 ftp = ((fromto_T *)gap->ga_data) + gap->ga_len;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2384 (void)spell_casefold(from, STRLEN(from), word, MAXWLEN);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2385 ftp->ft_from = getroom_save(&spin->si_blocks, word);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2386 (void)spell_casefold(to, STRLEN(to), word, MAXWLEN);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2387 ftp->ft_to = getroom_save(&spin->si_blocks, word);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2388 ++gap->ga_len;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2389 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2390 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2391
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2392 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2393 * Convert a boolean argument in a SAL line to TRUE or FALSE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2394 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2395 static int
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2396 sal_to_bool(s)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2397 char_u *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2398 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2399 return STRCMP(s, "1") == 0 || STRCMP(s, "true") == 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2400 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2401
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2402 /*
240
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2403 * Return TRUE if string "s" contains a non-ASCII character (128 or higher).
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2404 * When "s" is NULL FALSE is returned.
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2405 */
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2406 static int
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2407 has_non_ascii(s)
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2408 char_u *s;
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2409 {
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2410 char_u *p;
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2411
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2412 if (s != NULL)
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2413 for (p = s; *p != NUL; ++p)
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2414 if (*p >= 128)
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2415 return TRUE;
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2416 return FALSE;
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2417 }
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2418
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2419 /*
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2420 * Free the structure filled by spell_read_aff().
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2421 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2422 static void
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2423 spell_free_aff(aff)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2424 afffile_T *aff;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2425 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2426 hashtab_T *ht;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2427 hashitem_T *hi;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2428 int todo;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2429 affheader_T *ah;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2430 affentry_T *ae;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2431
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2432 vim_free(aff->af_enc);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2433
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2434 /* All this trouble to foree the "ae_prog" items... */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2435 for (ht = &aff->af_pref; ; ht = &aff->af_suff)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2436 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2437 todo = ht->ht_used;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2438 for (hi = ht->ht_array; todo > 0; ++hi)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2439 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2440 if (!HASHITEM_EMPTY(hi))
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2441 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2442 --todo;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2443 ah = HI2AH(hi);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2444 for (ae = ah->ah_first; ae != NULL; ae = ae->ae_next)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2445 vim_free(ae->ae_prog);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2446 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2447 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2448 if (ht == &aff->af_suff)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2449 break;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2450 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2451
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2452 hash_clear(&aff->af_pref);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2453 hash_clear(&aff->af_suff);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2454 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2455
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2456 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2457 * Read dictionary file "fname".
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2458 * Returns OK or FAIL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2459 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2460 static int
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2461 spell_read_dic(fname, spin, affile)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2462 char_u *fname;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2463 spellinfo_T *spin;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2464 afffile_T *affile;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2465 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2466 hashtab_T ht;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2467 char_u line[MAXLINELEN];
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2468 char_u *afflist;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2469 char_u *dw;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2470 char_u *pc;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2471 char_u *w;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2472 int l;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2473 hash_T hash;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2474 hashitem_T *hi;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2475 FILE *fd;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2476 int lnum = 1;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2477 int non_ascii = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2478 int retval = OK;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2479 char_u message[MAXLINELEN + MAXWLEN];
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2480 int flags;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2481
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2482 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2483 * Open the file.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2484 */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2485 fd = mch_fopen((char *)fname, "r");
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2486 if (fd == NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2487 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2488 EMSG2(_(e_notopen), fname);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2489 return FAIL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2490 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2491
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2492 /* The hashtable is only used to detect duplicated words. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2493 hash_init(&ht);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2494
334
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2495 spin->si_foldwcount = 0;
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2496 spin->si_keepwcount = 0;
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2497
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2498 if (spin->si_verbose || p_verbose > 2)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2499 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2500 if (!spin->si_verbose)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2501 verbose_enter();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2502 smsg((char_u *)_("Reading dictionary file %s..."), fname);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2503 out_flush();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2504 if (!spin->si_verbose)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2505 verbose_leave();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2506 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2507
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2508 /* Read and ignore the first line: word count. */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2509 (void)vim_fgets(line, MAXLINELEN, fd);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2510 if (!vim_isdigit(*skipwhite(line)))
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2511 EMSG2(_("E760: No word count in %s"), fname);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2512
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2513 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2514 * Read all the lines in the file one by one.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2515 * The words are converted to 'encoding' here, before being added to
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2516 * the hashtable.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2517 */
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2518 while (!vim_fgets(line, MAXLINELEN, fd) && !got_int)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2519 {
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2520 line_breakcheck();
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2521 ++lnum;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2522
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2523 /* Remove CR, LF and white space from the end. White space halfway
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2524 * the word is kept to allow e.g., "et al.". */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2525 l = STRLEN(line);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2526 while (l > 0 && line[l - 1] <= ' ')
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2527 --l;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2528 if (l == 0)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2529 continue; /* empty line */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2530 line[l] = NUL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2531
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2532 /* This takes time, print a message now and then. */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2533 if (spin->si_verbose && (lnum & 0x3ff) == 0)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2534 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2535 vim_snprintf((char *)message, sizeof(message),
334
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2536 _("line %6d, word %6d - %s"),
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
2537 lnum, spin->si_foldwcount + spin->si_keepwcount, line);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2538 msg_start();
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2539 msg_outtrans_attr(message, 0);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2540 msg_clr_eos();
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2541 msg_didout = FALSE;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2542 msg_col = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2543 out_flush();
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2544 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2545
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2546 /* Find the optional affix names. */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2547 afflist = vim_strchr(line, '/');
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2548 if (afflist != NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2549 *afflist++ = NUL;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2550
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2551 /* Skip non-ASCII words when "spin->si_ascii" is TRUE. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2552 if (spin->si_ascii && has_non_ascii(line))
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2553 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2554 ++non_ascii;
240
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2555 continue;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2556 }
240
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2557
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2558 #ifdef FEAT_MBYTE
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2559 /* Convert from "SET" to 'encoding' when needed. */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2560 if (spin->si_conv.vc_type != CONV_NONE)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2561 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2562 pc = string_convert(&spin->si_conv, line, NULL);
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2563 if (pc == NULL)
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2564 {
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2565 smsg((char_u *)_("Conversion failure for word in %s line %d: %s"),
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2566 fname, lnum, line);
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2567 continue;
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
2568 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2569 w = pc;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2570 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2571 else
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2572 #endif
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2573 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2574 pc = NULL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2575 w = line;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2576 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2577
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2578 /* Store the word in the hashtable to be able to find duplicates. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2579 dw = (char_u *)getroom_save(&spin->si_blocks, w);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2580 if (dw == NULL)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2581 retval = FAIL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2582 vim_free(pc);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2583 if (retval == FAIL)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2584 break;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2585
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2586 hash = hash_hash(dw);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2587 hi = hash_lookup(&ht, dw, hash);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2588 if (!HASHITEM_EMPTY(hi))
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2589 smsg((char_u *)_("Duplicate word in %s line %d: %s"),
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2590 fname, lnum, line);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2591 else
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2592 hash_add_item(&ht, hi, dw, hash);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2593
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2594 flags = 0;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2595 if (afflist != NULL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2596 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2597 /* Check for affix name that stands for keep-case word and stands
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2598 * for rare word (if defined). */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2599 if (affile->af_kep != NUL
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2600 && vim_strchr(afflist, affile->af_kep) != NULL)
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2601 flags |= WF_KEEPCAP;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2602 if (affile->af_rar != NUL
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2603 && vim_strchr(afflist, affile->af_rar) != NULL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2604 flags |= WF_RARE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2605 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2606
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2607 /* Add the word to the word tree(s). */
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2608 if (store_word(dw, spin, flags, spin->si_region) == FAIL)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2609 retval = FAIL;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2610
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2611 if (afflist != NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2612 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2613 /* Find all matching suffixes and add the resulting words.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2614 * Additionally do matching prefixes that combine. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2615 if (store_aff_word(dw, spin, afflist,
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2616 &affile->af_suff, &affile->af_pref,
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2617 FALSE, flags) == FAIL)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2618 retval = FAIL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2619
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2620 /* Find all matching prefixes and add the resulting words. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2621 if (store_aff_word(dw, spin, afflist,
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2622 &affile->af_pref, NULL, FALSE, flags) == FAIL)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2623 retval = FAIL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2624 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2625 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2626
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2627 if (spin->si_ascii && non_ascii > 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2628 smsg((char_u *)_("Ignored %d words with non-ASCII characters"),
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2629 non_ascii);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2630 hash_clear(&ht);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2631
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2632 fclose(fd);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2633 return retval;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2634 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2635
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2636 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2637 * Apply affixes to a word and store the resulting words.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2638 * "ht" is the hashtable with affentry_T that need to be applied, either
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2639 * prefixes or suffixes.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2640 * "xht", when not NULL, is the prefix hashtable, to be used additionally on
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2641 * the resulting words for combining affixes.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2642 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2643 * Returns FAIL when out of memory.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2644 */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2645 static int
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2646 store_aff_word(word, spin, afflist, ht, xht, comb, flags)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2647 char_u *word; /* basic word start */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2648 spellinfo_T *spin; /* spell info */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2649 char_u *afflist; /* list of names of supported affixes */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2650 hashtab_T *ht;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2651 hashtab_T *xht;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2652 int comb; /* only use affixes that combine */
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2653 int flags; /* flags for the word */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2654 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2655 int todo;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2656 hashitem_T *hi;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2657 affheader_T *ah;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2658 affentry_T *ae;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2659 regmatch_T regmatch;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2660 char_u newword[MAXWLEN];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2661 int retval = OK;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2662 int i;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2663 char_u *p;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2664
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2665 todo = ht->ht_used;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2666 for (hi = ht->ht_array; todo > 0 && retval == OK; ++hi)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2667 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2668 if (!HASHITEM_EMPTY(hi))
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2669 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2670 --todo;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2671 ah = HI2AH(hi);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2672
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2673 /* Check that the affix combines, if required, and that the word
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2674 * supports this affix. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2675 if ((!comb || ah->ah_combine)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2676 && vim_strchr(afflist, *ah->ah_key) != NULL)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2677 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2678 /* Loop over all affix entries with this name. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2679 for (ae = ah->ah_first; ae != NULL; ae = ae->ae_next)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2680 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2681 /* Check the condition. It's not logical to match case
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2682 * here, but it is required for compatibility with
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2683 * Myspell. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2684 regmatch.regprog = ae->ae_prog;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2685 regmatch.rm_ic = FALSE;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2686 if (ae->ae_prog == NULL
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2687 || vim_regexec(&regmatch, word, (colnr_T)0))
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2688 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2689 /* Match. Remove the chop and add the affix. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2690 if (xht == NULL)
240
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2691 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2692 /* prefix: chop/add at the start of the word */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2693 if (ae->ae_add == NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2694 *newword = NUL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2695 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2696 STRCPY(newword, ae->ae_add);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2697 p = word;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2698 if (ae->ae_chop != NULL)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2699 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2700 /* Skip chop string. */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2701 #ifdef FEAT_MBYTE
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2702 if (has_mbyte)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2703 {
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2704 i = mb_charlen(ae->ae_chop);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2705 for ( ; i > 0; --i)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2706 mb_ptr_adv(p);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2707 }
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2708 else
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2709 #endif
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2710 p += STRLEN(ae->ae_chop);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2711 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2712 STRCAT(newword, p);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2713 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2714 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2715 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2716 /* suffix: chop/add at the end of the word */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2717 STRCPY(newword, word);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2718 if (ae->ae_chop != NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2719 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2720 /* Remove chop string. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2721 p = newword + STRLEN(newword);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2722 #ifdef FEAT_MBYTE
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2723 if (has_mbyte)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2724 i = mb_charlen(ae->ae_chop);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2725 else
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2726 #endif
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2727 i = STRLEN(ae->ae_chop);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2728 for ( ; i > 0; --i)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2729 mb_ptr_back(newword, p);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2730 *p = NUL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2731 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2732 if (ae->ae_add != NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2733 STRCAT(newword, ae->ae_add);
240
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2734 }
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2735
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2736 /* Store the modified word. */
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2737 if (store_word(newword, spin,
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2738 flags, spin->si_region) == FAIL)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2739 retval = FAIL;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2740
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2741 /* When added a suffix and combining is allowed also
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2742 * try adding prefixes additionally. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2743 if (xht != NULL && ah->ah_combine)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2744 if (store_aff_word(newword, spin, afflist,
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2745 xht, NULL, TRUE, flags) == FAIL)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2746 retval = FAIL;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2747 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2748 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2749 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2750 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2751 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2752
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2753 return retval;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2754 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2755
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2756 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2757 * Read a file with a list of words.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2758 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2759 static int
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2760 spell_read_wordfile(fname, spin)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2761 char_u *fname;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2762 spellinfo_T *spin;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2763 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2764 FILE *fd;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2765 long lnum = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2766 char_u rline[MAXLINELEN];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2767 char_u *line;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2768 char_u *pc = NULL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2769 int l;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2770 int retval = OK;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2771 int did_word = FALSE;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2772 int non_ascii = 0;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2773 int flags;
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2774 int regionmask;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2775
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2776 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2777 * Open the file.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2778 */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2779 fd = mch_fopen((char *)fname, "r");
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2780 if (fd == NULL)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2781 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2782 EMSG2(_(e_notopen), fname);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2783 return FAIL;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2784 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2785
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2786 if (spin->si_verbose || p_verbose > 2)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2787 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2788 if (!spin->si_verbose)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2789 verbose_enter();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2790 smsg((char_u *)_("Reading word file %s..."), fname);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2791 out_flush();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2792 if (!spin->si_verbose)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2793 verbose_leave();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2794 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2795
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2796 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2797 * Read all the lines in the file one by one.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2798 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2799 while (!vim_fgets(rline, MAXLINELEN, fd) && !got_int)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2800 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2801 line_breakcheck();
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2802 ++lnum;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2803
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2804 /* Skip comment lines. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2805 if (*rline == '#')
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2806 continue;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2807
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2808 /* Remove CR, LF and white space from the end. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2809 l = STRLEN(rline);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2810 while (l > 0 && rline[l - 1] <= ' ')
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2811 --l;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2812 if (l == 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2813 continue; /* empty or blank line */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2814 rline[l] = NUL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2815
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2816 /* Convert from "=encoding={encoding}" to 'encoding' when needed. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2817 vim_free(pc);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2818 #ifdef FEAT_MBYTE
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2819 if (spin->si_conv.vc_type != CONV_NONE)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2820 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2821 pc = string_convert(&spin->si_conv, rline, NULL);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2822 if (pc == NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2823 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2824 smsg((char_u *)_("Conversion failure for word in %s line %d: %s"),
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2825 fname, lnum, rline);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2826 continue;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2827 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2828 line = pc;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2829 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2830 else
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2831 #endif
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2832 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2833 pc = NULL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2834 line = rline;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2835 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2836
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2837 flags = 0;
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2838 regionmask = spin->si_region;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2839
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2840 if (*line == '/')
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2841 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2842 ++line;
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2843
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2844 if (STRNCMP(line, "encoding=", 9) == 0)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2845 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2846 if (spin->si_conv.vc_type != CONV_NONE)
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2847 smsg((char_u *)_("Duplicate /encoding= line ignored in %s line %d: %s"),
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2848 fname, lnum, line - 1);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2849 else if (did_word)
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2850 smsg((char_u *)_("/encoding= line after word ignored in %s line %d: %s"),
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2851 fname, lnum, line - 1);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2852 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2853 {
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2854 #ifdef FEAT_MBYTE
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2855 char_u *enc;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2856
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2857 /* Setup for conversion to 'encoding'. */
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2858 line += 10;
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2859 enc = enc_canonize(line);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2860 if (enc != NULL && !spin->si_ascii
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2861 && convert_setup(&spin->si_conv, enc,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2862 p_enc) == FAIL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2863 smsg((char_u *)_("Conversion in %s not supported: from %s to %s"),
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2864 fname, line, p_enc);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2865 vim_free(enc);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2866 #else
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2867 smsg((char_u *)_("Conversion in %s not supported"), fname);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2868 #endif
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2869 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2870 continue;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2871 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2872
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2873 if (STRNCMP(line, "regions=", 8) == 0)
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2874 {
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2875 if (spin->si_region_count > 1)
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2876 smsg((char_u *)_("Duplicate /regions= line ignored in %s line %d: %s"),
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2877 fname, lnum, line);
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2878 else
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2879 {
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2880 line += 8;
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2881 if (STRLEN(line) > 16)
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2882 smsg((char_u *)_("Too many regions in %s line %d: %s"),
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2883 fname, lnum, line);
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2884 else
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2885 {
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2886 spin->si_region_count = STRLEN(line) / 2;
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2887 STRCPY(spin->si_region_name, line);
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2888 }
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2889 }
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2890 continue;
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2891 }
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2892
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2893 if (*line == '=')
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2894 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2895 /* keep-case word */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2896 flags |= WF_KEEPCAP;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2897 ++line;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2898 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2899
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2900 if (*line == '!')
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2901 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2902 /* Bad, bad, wicked word. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2903 flags |= WF_BANNED;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2904 ++line;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2905 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2906 else if (*line == '?')
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2907 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2908 /* Rare word. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2909 flags |= WF_RARE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2910 ++line;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2911 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2912
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2913 if (VIM_ISDIGIT(*line))
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2914 {
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2915 /* region number(s) */
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2916 regionmask = 0;
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2917 while (VIM_ISDIGIT(*line))
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2918 {
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2919 l = *line - '0';
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2920 if (l > spin->si_region_count)
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2921 {
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2922 smsg((char_u *)_("Invalid region nr in %s line %d: %s"),
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2923 fname, lnum, line);
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 }
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2926 regionmask |= 1 << (l - 1);
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2927 ++line;
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2928 }
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2929 flags |= WF_REGION;
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2930 }
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2931
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2932 if (flags == 0)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2933 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2934 smsg((char_u *)_("/ line ignored in %s line %d: %s"),
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2935 fname, lnum, line);
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2936 continue;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2937 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2938 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2939
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2940 /* Skip non-ASCII words when "spin->si_ascii" is TRUE. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2941 if (spin->si_ascii && has_non_ascii(line))
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2942 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2943 ++non_ascii;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2944 continue;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2945 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2946
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2947 /* Normal word: store it. */
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2948 if (store_word(line, spin, flags, regionmask) == FAIL)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2949 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2950 retval = FAIL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2951 break;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2952 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2953 did_word = TRUE;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2954 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2955
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2956 vim_free(pc);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2957 fclose(fd);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2958
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2959 if (spin->si_ascii && non_ascii > 0 && (spin->si_verbose || p_verbose > 2))
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2960 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2961 if (p_verbose > 2)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2962 verbose_enter();
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2963 smsg((char_u *)_("Ignored %d words with non-ASCII characters"),
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2964 non_ascii);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2965 if (p_verbose > 2)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2966 verbose_leave();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2967 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2968 return retval;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2969 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2970
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2971 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2972 * Get part of an sblock_T, "len" bytes long.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2973 * This avoids calling free() for every little struct we use.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2974 * The memory is cleared to all zeros.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2975 * Returns NULL when out of memory.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2976 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2977 static void *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2978 getroom(blp, len)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2979 sblock_T **blp;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2980 size_t len; /* length needed */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2981 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2982 char_u *p;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2983 sblock_T *bl = *blp;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2984
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2985 if (bl == NULL || bl->sb_used + len > SBLOCKSIZE)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2986 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2987 /* Allocate a block of memory. This is not freed until much later. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2988 bl = (sblock_T *)alloc_clear((unsigned)(sizeof(sblock_T) + SBLOCKSIZE));
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2989 if (bl == NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2990 return NULL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2991 bl->sb_next = *blp;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2992 *blp = bl;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2993 bl->sb_used = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2994 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2995
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2996 p = bl->sb_data + bl->sb_used;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2997 bl->sb_used += len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2998
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2999 return p;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3000 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3001
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3002 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3003 * Make a copy of a string into memory allocated with getroom().
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3004 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3005 static char_u *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3006 getroom_save(blp, s)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3007 sblock_T **blp;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3008 char_u *s;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3009 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3010 char_u *sc;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3011
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3012 sc = (char_u *)getroom(blp, STRLEN(s) + 1);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3013 if (sc != NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3014 STRCPY(sc, s);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3015 return sc;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3016 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3017
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3018
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3019 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3020 * Free the list of allocated sblock_T.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3021 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3022 static void
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3023 free_blocks(bl)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3024 sblock_T *bl;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3025 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3026 sblock_T *next;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3027
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3028 while (bl != NULL)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3029 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3030 next = bl->sb_next;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3031 vim_free(bl);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3032 bl = next;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3033 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3034 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3035
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3036 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3037 * Allocate the root of a word tree.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3038 */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3039 static wordnode_T *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3040 wordtree_alloc(blp)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3041 sblock_T **blp;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3042 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3043 return (wordnode_T *)getroom(blp, sizeof(wordnode_T));
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3044 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3045
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3046 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3047 * Store a word in the tree(s).
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3048 * Always store it in the case-folded tree. A keep-case word can also be used
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3049 * with all caps.
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3050 * For a keep-case word also store it in the keep-case tree.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3051 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3052 static int
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3053 store_word(word, spin, flags, region)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3054 char_u *word;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3055 spellinfo_T *spin;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3056 int flags; /* extra flags, WF_BANNED */
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3057 int region; /* supported region(s) */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3058 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3059 int len = STRLEN(word);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3060 int ct = captype(word, word + len);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3061 char_u foldword[MAXWLEN];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3062 int res;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3063
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3064 (void)spell_casefold(word, len, foldword, MAXWLEN);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3065 res = tree_add_word(foldword, spin->si_foldroot, ct | flags,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3066 region, &spin->si_blocks);
334
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
3067 ++spin->si_foldwcount;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3068
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3069 if (res == OK && (ct == WF_KEEPCAP || flags & WF_KEEPCAP))
334
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
3070 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3071 res = tree_add_word(word, spin->si_keeproot, flags,
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3072 region, &spin->si_blocks);
334
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
3073 ++spin->si_keepwcount;
a1270013cb34 updated for version 7.0087
vimboss
parents: 330
diff changeset
3074 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3075 return res;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3076 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3077
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3078 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3079 * Add word "word" to a word tree at "root".
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3080 * Returns FAIL when out of memory.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3081 */
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3082 static int
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3083 tree_add_word(word, root, flags, region, blp)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3084 char_u *word;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3085 wordnode_T *root;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3086 int flags;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3087 int region;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3088 sblock_T **blp;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3089 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3090 wordnode_T *node = root;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3091 wordnode_T *np;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3092 wordnode_T **prev = NULL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3093 int i;
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3094
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3095 /* Add each byte of the word to the tree, including the NUL at the end. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3096 for (i = 0; ; ++i)
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3097 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3098 /* Look for the sibling that has the same character. They are sorted
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3099 * on byte value, thus stop searching when a sibling is found with a
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3100 * higher byte value. For zero bytes (end of word) check that the
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3101 * flags are equal, there is a separate zero byte for each flag value.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3102 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3103 while (node != NULL && (node->wn_byte < word[i]
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3104 || (node->wn_byte == 0 && node->wn_flags != (flags & 0xff))))
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3105 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3106 prev = &node->wn_sibling;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3107 node = *prev;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3108 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3109 if (node == NULL || node->wn_byte != word[i])
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3110 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3111 /* Allocate a new node. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3112 np = (wordnode_T *)getroom(blp, sizeof(wordnode_T));
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3113 if (np == NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3114 return FAIL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3115 np->wn_byte = word[i];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3116 *prev = np;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3117 np->wn_sibling = node;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3118 node = np;
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3119 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3120
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3121 if (word[i] == NUL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3122 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3123 node->wn_flags = flags;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3124 node->wn_region |= region;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3125 break;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3126 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3127 prev = &node->wn_child;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3128 node = *prev;
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3129 }
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3130
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3131 return OK;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3132 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3133
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3134 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3135 * Compress a tree: find tails that are identical and can be shared.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3136 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3137 static void
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3138 wordtree_compress(root, spin)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3139 wordnode_T *root;
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3140 spellinfo_T *spin;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3141 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3142 hashtab_T ht;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3143 int n;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3144 int tot = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3145
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3146 if (root != NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3147 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3148 hash_init(&ht);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3149 n = node_compress(root, &ht, &tot);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3150 if (spin->si_verbose || p_verbose > 2)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3151 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3152 if (!spin->si_verbose)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3153 verbose_enter();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3154 smsg((char_u *)_("Compressed %d of %d nodes; %d%% remaining"),
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3155 n, tot, (tot - n) * 100 / tot);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3156 if (p_verbose > 2)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3157 verbose_leave();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3158 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3159 hash_clear(&ht);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3160 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3161 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3162
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3163 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3164 * Compress a node, its siblings and its children, depth first.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3165 * Returns the number of compressed nodes.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3166 */
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3167 static int
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3168 node_compress(node, ht, tot)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3169 wordnode_T *node;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3170 hashtab_T *ht;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3171 int *tot; /* total count of nodes before compressing,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3172 incremented while going through the tree */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3173 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3174 wordnode_T *np;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3175 wordnode_T *tp;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3176 wordnode_T *child;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3177 hash_T hash;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3178 hashitem_T *hi;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3179 int len = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3180 unsigned nr, n;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3181 int compressed = 0;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3182
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3183 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3184 * Go through the list of siblings. Compress each child and then try
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3185 * finding an identical child to replace it.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3186 * Note that with "child" we mean not just the node that is pointed to,
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3187 * but the whole list of siblings, of which the node is the first.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3188 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3189 for (np = node; np != NULL; np = np->wn_sibling)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3190 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3191 ++len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3192 if ((child = np->wn_child) != NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3193 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3194 /* Compress the child. This fills wn_hashkey. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3195 compressed += node_compress(child, ht, tot);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3196
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3197 /* Try to find an identical child. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3198 hash = hash_hash(child->wn_hashkey);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3199 hi = hash_lookup(ht, child->wn_hashkey, hash);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3200 tp = NULL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3201 if (!HASHITEM_EMPTY(hi))
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3202 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3203 /* There are children with an identical hash value. Now check
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3204 * if there is one that is really identical. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3205 for (tp = HI2WN(hi); tp != NULL; tp = tp->wn_next)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3206 if (node_equal(child, tp))
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3207 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3208 /* Found one! Now use that child in place of the
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3209 * current one. This means the current child is
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3210 * dropped from the tree. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3211 np->wn_child = tp;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3212 ++compressed;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3213 break;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3214 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3215 if (tp == NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3216 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3217 /* No other child with this hash value equals the child of
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3218 * the node, add it to the linked list after the first
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3219 * item. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3220 tp = HI2WN(hi);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3221 child->wn_next = tp->wn_next;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3222 tp->wn_next = child;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3223 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3224 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3225 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3226 /* No other child has this hash value, add it to the
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3227 * hashtable. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3228 hash_add_item(ht, hi, child->wn_hashkey, hash);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3229 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3230 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3231 *tot += len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3232
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3233 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3234 * Make a hash key for the node and its siblings, so that we can quickly
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3235 * find a lookalike node. This must be done after compressing the sibling
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3236 * list, otherwise the hash key would become invalid by the compression.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3237 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3238 node->wn_hashkey[0] = len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3239 nr = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3240 for (np = node; np != NULL; np = np->wn_sibling)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3241 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3242 if (np->wn_byte == NUL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3243 /* end node: only use wn_flags and wn_region */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3244 n = np->wn_flags + (np->wn_region << 8);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3245 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3246 /* byte node: use the byte value and the child pointer */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3247 n = np->wn_byte + ((long_u)np->wn_child << 8);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3248 nr = nr * 101 + n;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3249 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3250
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3251 /* Avoid NUL bytes, it terminates the hash key. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3252 n = nr & 0xff;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3253 node->wn_hashkey[1] = n == 0 ? 1 : n;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3254 n = (nr >> 8) & 0xff;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3255 node->wn_hashkey[2] = n == 0 ? 1 : n;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3256 n = (nr >> 16) & 0xff;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3257 node->wn_hashkey[3] = n == 0 ? 1 : n;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3258 n = (nr >> 24) & 0xff;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3259 node->wn_hashkey[4] = n == 0 ? 1 : n;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3260 node->wn_hashkey[5] = NUL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3261
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3262 return compressed;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3263 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3264
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3265 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3266 * Return TRUE when two nodes have identical siblings and children.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3267 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3268 static int
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3269 node_equal(n1, n2)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3270 wordnode_T *n1;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3271 wordnode_T *n2;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3272 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3273 wordnode_T *p1;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3274 wordnode_T *p2;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3275
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3276 for (p1 = n1, p2 = n2; p1 != NULL && p2 != NULL;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3277 p1 = p1->wn_sibling, p2 = p2->wn_sibling)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3278 if (p1->wn_byte != p2->wn_byte
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3279 || (p1->wn_byte == NUL
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3280 ? (p1->wn_flags != p2->wn_flags
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3281 || p1->wn_region != p2->wn_region)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3282 : (p1->wn_child != p2->wn_child)))
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3283 break;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3284
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3285 return p1 == NULL && p2 == NULL;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3286 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3287
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3288 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3289 * Write a number to file "fd", MSB first, in "len" bytes.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3290 */
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3291 void
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3292 put_bytes(fd, nr, len)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3293 FILE *fd;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3294 long_u nr;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3295 int len;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3296 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3297 int i;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3298
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3299 for (i = len - 1; i >= 0; --i)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3300 putc((int)(nr >> (i * 8)), fd);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3301 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3302
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3303 static int
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3304 #ifdef __BORLANDC__
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3305 _RTLENTRYF
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3306 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3307 rep_compare __ARGS((const void *s1, const void *s2));
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3308
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3309 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3310 * Function given to qsort() to sort the REP items on "from" string.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3311 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3312 static int
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3313 #ifdef __BORLANDC__
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3314 _RTLENTRYF
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3315 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3316 rep_compare(s1, s2)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3317 const void *s1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3318 const void *s2;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3319 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3320 fromto_T *p1 = (fromto_T *)s1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3321 fromto_T *p2 = (fromto_T *)s2;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3322
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3323 return STRCMP(p1->ft_from, p2->ft_from);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3324 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3325
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3326 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3327 * Write the Vim spell file "fname".
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3328 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3329 static void
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3330 write_vim_spell(fname, spin)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3331 char_u *fname;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3332 spellinfo_T *spin;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3333 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3334 FILE *fd;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3335 int regionmask;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3336 int round;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3337 wordnode_T *tree;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3338 int nodecount;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3339 int i;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3340 int l;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3341 garray_T *gap;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3342 fromto_T *ftp;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3343 char_u *p;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3344 int rr;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3345
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3346 fd = mch_fopen((char *)fname, "w");
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3347 if (fd == NULL)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3348 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3349 EMSG2(_(e_notopen), fname);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3350 return;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3351 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3352
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3353 /* <HEADER>: <fileID> <regioncnt> <regionname> ...
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3354 * <charflagslen> <charflags> <fcharslen> <fchars> */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3355
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3356 /* <fileID> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3357 if (fwrite(VIMSPELLMAGIC, VIMSPELLMAGICL, (size_t)1, fd) != 1)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3358 EMSG(_(e_write));
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3359
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3360 /* write the region names if there is more than one */
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3361 if (spin->si_region_count > 1)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3362 {
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3363 putc(spin->si_region_count, fd); /* <regioncnt> <regionname> ... */
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3364 fwrite(spin->si_region_name, (size_t)(spin->si_region_count * 2),
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3365 (size_t)1, fd);
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3366 regionmask = (1 << spin->si_region_count) - 1;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3367 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3368 else
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3369 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3370 putc(0, fd);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3371 regionmask = 0;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3372 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3373
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3374 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3375 * Write the table with character flags and table for case folding.
260
ed33f83b42d8 updated for version 7.0071
vimboss
parents: 255
diff changeset
3376 * <charflagslen> <charflags> <fcharlen> <fchars>
ed33f83b42d8 updated for version 7.0071
vimboss
parents: 255
diff changeset
3377 * Skip this for ASCII, the table may conflict with the one used for
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3378 * 'encoding'.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3379 * Also skip this for an .add.spl file, the main spell file must contain
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3380 * the table (avoids that it conflicts). File is shorter too.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3381 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3382 if (spin->si_ascii || spin->si_add)
260
ed33f83b42d8 updated for version 7.0071
vimboss
parents: 255
diff changeset
3383 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3384 putc(0, fd);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3385 putc(0, fd);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3386 putc(0, fd);
260
ed33f83b42d8 updated for version 7.0071
vimboss
parents: 255
diff changeset
3387 }
ed33f83b42d8 updated for version 7.0071
vimboss
parents: 255
diff changeset
3388 else
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3389 write_spell_chartab(fd);
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3390
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3391 /* Sort the REP items. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3392 qsort(spin->si_rep.ga_data, (size_t)spin->si_rep.ga_len,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3393 sizeof(fromto_T), rep_compare);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3394
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3395 /* <SUGGEST> : <repcount> <rep> ...
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3396 * <salflags> <salcount> <sal> ...
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3397 * <maplen> <mapstr> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3398 for (round = 1; round <= 2; ++round)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3399 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3400 if (round == 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3401 gap = &spin->si_rep;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3402 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3403 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3404 gap = &spin->si_sal;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3405
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3406 i = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3407 if (spin->si_followup)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3408 i |= SAL_F0LLOWUP;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3409 if (spin->si_collapse)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3410 i |= SAL_COLLAPSE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3411 if (spin->si_rem_accents)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3412 i |= SAL_REM_ACCENTS;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3413 putc(i, fd); /* <salflags> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3414 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3415
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3416 put_bytes(fd, (long_u)gap->ga_len, 2); /* <repcount> or <salcount> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3417 for (i = 0; i < gap->ga_len; ++i)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3418 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3419 /* <rep> : <repfromlen> <repfrom> <reptolen> <repto> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3420 /* <sal> : <salfromlen> <salfrom> <saltolen> <salto> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3421 ftp = &((fromto_T *)gap->ga_data)[i];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3422 for (rr = 1; rr <= 2; ++rr)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3423 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3424 p = rr == 1 ? ftp->ft_from : ftp->ft_to;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3425 l = STRLEN(p);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3426 putc(l, fd);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3427 fwrite(p, l, (size_t)1, fd);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3428 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3429 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3430 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3431
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3432 put_bytes(fd, (long_u)spin->si_map.ga_len, 2); /* <maplen> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3433 if (spin->si_map.ga_len > 0) /* <mapstr> */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3434 fwrite(spin->si_map.ga_data, (size_t)spin->si_map.ga_len,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3435 (size_t)1, fd);
302
250611b3068d updated for version 7.0080
vimboss
parents: 300
diff changeset
3436
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3437 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3438 * <LWORDTREE> <KWORDTREE>
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3439 */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3440 spin->si_memtot = 0;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3441 for (round = 1; round <= 2; ++round)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3442 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3443 tree = (round == 1) ? spin->si_foldroot : spin->si_keeproot;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3444
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3445 /* Count the number of nodes. Needed to be able to allocate the
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3446 * memory when reading the nodes. Also fills in the index for shared
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3447 * nodes. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3448 nodecount = put_tree(NULL, tree, 0, regionmask);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3449
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3450 /* number of nodes in 4 bytes */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3451 put_bytes(fd, (long_u)nodecount, 4); /* <nodecount> */
302
250611b3068d updated for version 7.0080
vimboss
parents: 300
diff changeset
3452 spin->si_memtot += nodecount + nodecount * sizeof(int);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3453
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3454 /* Write the nodes. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3455 (void)put_tree(fd, tree, 0, regionmask);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3456 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3457
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3458 fclose(fd);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3459 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3460
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3461 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3462 * Dump a word tree at node "node".
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3463 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3464 * This first writes the list of possible bytes (siblings). Then for each
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3465 * byte recursively write the children.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3466 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3467 * NOTE: The code here must match the code in read_tree(), since assumptions
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3468 * are made about the indexes (so that we don't have to write them in the
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3469 * file).
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3470 *
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3471 * Returns the number of nodes used.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3472 */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3473 static int
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3474 put_tree(fd, node, index, regionmask)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3475 FILE *fd; /* NULL when only counting */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3476 wordnode_T *node;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3477 int index;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3478 int regionmask;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3479 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3480 int newindex = index;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3481 int siblingcount = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3482 wordnode_T *np;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3483 int flags;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3484
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3485 /* If "node" is zero the tree is empty. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3486 if (node == NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3487 return 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3488
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3489 /* Store the index where this node is written. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3490 node->wn_index = index;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3491
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3492 /* Count the number of siblings. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3493 for (np = node; np != NULL; np = np->wn_sibling)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3494 ++siblingcount;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3495
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3496 /* Write the sibling count. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3497 if (fd != NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3498 putc(siblingcount, fd); /* <siblingcount> */
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3499
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3500 /* Write each sibling byte and optionally extra info. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3501 for (np = node; np != NULL; np = np->wn_sibling)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3502 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3503 if (np->wn_byte == 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3504 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3505 if (fd != NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3506 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3507 /* For a NUL byte (end of word) instead of the byte itself
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3508 * we write the flag/region items. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3509 flags = np->wn_flags;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3510 if (regionmask != 0 && np->wn_region != regionmask)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3511 flags |= WF_REGION;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3512 if (flags == 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3513 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3514 /* word without flags or region */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3515 putc(BY_NOFLAGS, fd); /* <byte> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3516 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3517 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3518 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3519 putc(BY_FLAGS, fd); /* <byte> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3520 putc(flags, fd); /* <flags> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3521 if (flags & WF_REGION)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3522 putc(np->wn_region, fd); /* <regionmask> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3523 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3524 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3525 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3526 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3527 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3528 if (np->wn_child->wn_index != 0 && np->wn_child->wn_wnode != node)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3529 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3530 /* The child is written elsewhere, write the reference. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3531 if (fd != NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3532 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3533 putc(BY_INDEX, fd); /* <byte> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3534 /* <nodeidx> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3535 put_bytes(fd, (long_u)np->wn_child->wn_index, 3);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3536 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3537 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3538 else if (np->wn_child->wn_wnode == NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3539 /* We will write the child below and give it an index. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3540 np->wn_child->wn_wnode = node;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3541
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3542 if (fd != NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3543 if (putc(np->wn_byte, fd) == EOF) /* <byte> or <xbyte> */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3544 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3545 EMSG(_(e_write));
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3546 return 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3547 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3548 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3549 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3550
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3551 /* Space used in the array when reading: one for each sibling and one for
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3552 * the count. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3553 newindex += siblingcount + 1;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
3554
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3555 /* Recursively dump the children of each sibling. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3556 for (np = node; np != NULL; np = np->wn_sibling)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3557 if (np->wn_byte != 0 && np->wn_child->wn_wnode == node)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3558 newindex = put_tree(fd, np->wn_child, newindex, regionmask);
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
3559
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3560 return newindex;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3561 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3562
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3563
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3564 /*
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3565 * ":mkspell [-ascii] outfile infile ..."
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3566 * ":mkspell [-ascii] addfile"
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3567 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3568 void
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3569 ex_mkspell(eap)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3570 exarg_T *eap;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3571 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3572 int fcount;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3573 char_u **fnames;
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3574 char_u *arg = eap->arg;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3575 int ascii = FALSE;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3576
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3577 if (STRNCMP(arg, "-ascii", 6) == 0)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3578 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3579 ascii = TRUE;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3580 arg = skipwhite(arg + 6);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3581 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3582
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3583 /* Expand all the remaining arguments (e.g., $VIMRUNTIME). */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3584 if (get_arglist_exp(arg, &fcount, &fnames) == OK)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3585 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3586 mkspell(fcount, fnames, ascii, eap->forceit, FALSE);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3587 FreeWild(fcount, fnames);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3588 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3589 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3590
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3591 /*
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3592 * Create a Vim spell file from one or more word lists.
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3593 * "fnames[0]" is the output file name.
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3594 * "fnames[fcount - 1]" is the last input file name.
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3595 * Exception: when "fnames[0]" ends in ".add" it's used as the input file name
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3596 * and ".spl" is appended to make the output file name.
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3597 */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3598 static void
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3599 mkspell(fcount, fnames, ascii, overwrite, added_word)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3600 int fcount;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3601 char_u **fnames;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3602 int ascii; /* -ascii argument given */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3603 int overwrite; /* overwrite existing output file */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3604 int added_word; /* invoked through "zg" */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3605 {
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3606 char_u fname[MAXPATHL];
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3607 char_u wfname[MAXPATHL];
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3608 char_u **innames;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3609 int incount;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3610 afffile_T *(afile[8]);
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3611 int i;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3612 int len;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3613 struct stat st;
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3614 int error = FALSE;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3615 spellinfo_T spin;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3616
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3617 vim_memset(&spin, 0, sizeof(spin));
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3618 spin.si_verbose = !added_word;
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3619 spin.si_ascii = ascii;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3620 spin.si_followup = TRUE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3621 spin.si_rem_accents = TRUE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3622 ga_init2(&spin.si_rep, (int)sizeof(fromto_T), 20);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3623 ga_init2(&spin.si_sal, (int)sizeof(fromto_T), 20);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3624 ga_init2(&spin.si_map, (int)sizeof(char_u), 100);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3625
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3626 /* default: fnames[0] is output file, following are input files */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3627 innames = &fnames[1];
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3628 incount = fcount - 1;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3629
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3630 if (fcount >= 1)
240
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
3631 {
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3632 len = STRLEN(fnames[0]);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3633 if (fcount == 1 && len > 4 && STRCMP(fnames[0] + len - 4, ".add") == 0)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3634 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3635 /* For ":mkspell path/en.latin1.add" output file is
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3636 * "path/en.latin1.add.spl". */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3637 innames = &fnames[0];
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3638 incount = 1;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3639 vim_snprintf((char *)wfname, sizeof(wfname), "%s.spl", fnames[0]);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3640 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3641 else if (len > 4 && STRCMP(fnames[0] + len - 4, ".spl") == 0)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3642 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3643 /* Name ends in ".spl", use as the file name. */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3644 vim_strncpy(wfname, fnames[0], sizeof(wfname) - 1);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3645 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3646 else
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3647 /* Name should be language, make the file name from it. */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3648 vim_snprintf((char *)wfname, sizeof(wfname), "%s.%s.spl", fnames[0],
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3649 spin.si_ascii ? (char_u *)"ascii" : spell_enc());
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3650
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3651 /* Check for .ascii.spl. */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3652 if (strstr((char *)gettail(wfname), ".ascii.") != NULL)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3653 spin.si_ascii = TRUE;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3654
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3655 /* Check for .add.spl. */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3656 if (strstr((char *)gettail(wfname), ".add.") != NULL)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3657 spin.si_add = TRUE;
240
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
3658 }
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
3659
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3660 if (incount <= 0)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3661 EMSG(_(e_invarg)); /* need at least output and input names */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3662 else if (incount > 8)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3663 EMSG(_("E754: Only up to 8 regions supported"));
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3664 else
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3665 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3666 /* Check for overwriting before doing things that may take a lot of
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3667 * time. */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3668 if (!overwrite && mch_stat((char *)wfname, &st) >= 0)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3669 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3670 EMSG(_(e_exists));
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3671 return;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3672 }
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3673 if (mch_isdir(wfname))
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3674 {
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3675 EMSG2(_(e_isadir2), wfname);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3676 return;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3677 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3678
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3679 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3680 * Init the aff and dic pointers.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3681 * Get the region names if there are more than 2 arguments.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3682 */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3683 for (i = 0; i < incount; ++i)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3684 {
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3685 afile[i] = NULL;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3686
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3687 if (incount > 1)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3688 {
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3689 len = STRLEN(innames[i]);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3690 if (STRLEN(gettail(innames[i])) < 5
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3691 || innames[i][len - 3] != '_')
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3692 {
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3693 EMSG2(_("E755: Invalid region in %s"), innames[i]);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3694 return;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3695 }
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3696 spin.si_region_name[i * 2] = TOLOWER_ASC(innames[i][len - 2]);
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3697 spin.si_region_name[i * 2 + 1] =
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3698 TOLOWER_ASC(innames[i][len - 1]);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3699 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3700 }
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3701 spin.si_region_count = incount;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3702
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3703 if (!spin.si_add)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3704 /* Clear the char type tables, don't want to use any of the
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3705 * currently used spell properties. */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3706 init_spell_chartab();
255
c8742c8da9ab updated for version 7.0070
vimboss
parents: 249
diff changeset
3707
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3708 spin.si_foldroot = wordtree_alloc(&spin.si_blocks);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3709 spin.si_keeproot = wordtree_alloc(&spin.si_blocks);
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3710 if (spin.si_foldroot == NULL || spin.si_keeproot == NULL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3711 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3712 error = TRUE;
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3713 return;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3714 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3715
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3716 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3717 * Read all the .aff and .dic files.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3718 * Text is converted to 'encoding'.
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3719 * Words are stored in the case-folded and keep-case trees.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3720 */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3721 for (i = 0; i < incount && !error; ++i)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3722 {
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3723 spin.si_conv.vc_type = CONV_NONE;
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3724 spin.si_region = 1 << i;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3725
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3726 vim_snprintf((char *)fname, sizeof(fname), "%s.aff", innames[i]);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3727 if (mch_stat((char *)fname, &st) >= 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3728 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3729 /* Read the .aff file. Will init "spin->si_conv" based on the
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3730 * "SET" line. */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3731 afile[i] = spell_read_aff(fname, &spin);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3732 if (afile[i] == NULL)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3733 error = TRUE;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3734 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3735 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3736 /* Read the .dic file and store the words in the trees. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3737 vim_snprintf((char *)fname, sizeof(fname), "%s.dic",
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3738 innames[i]);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3739 if (spell_read_dic(fname, &spin, afile[i]) == FAIL)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3740 error = TRUE;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3741 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3742 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3743 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3744 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3745 /* No .aff file, try reading the file as a word list. Store
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3746 * the words in the trees. */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3747 if (spell_read_wordfile(innames[i], &spin) == FAIL)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3748 error = TRUE;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3749 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3750
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3751 #ifdef FEAT_MBYTE
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3752 /* Free any conversion stuff. */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3753 convert_setup(&spin.si_conv, NULL, NULL);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3754 #endif
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3755 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3756
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3757 if (!error)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3758 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3759 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3760 * Remove the dummy NUL from the start of the tree root.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3761 */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3762 spin.si_foldroot = spin.si_foldroot->wn_sibling;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3763 spin.si_keeproot = spin.si_keeproot->wn_sibling;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3764
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3765 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3766 * Combine tails in the tree.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3767 */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3768 if (!added_word || p_verbose > 2)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3769 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3770 if (added_word)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3771 verbose_enter();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3772 MSG(_("Compressing word tree..."));
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3773 out_flush();
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3774 if (added_word)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3775 verbose_leave();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3776 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3777 wordtree_compress(spin.si_foldroot, &spin);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3778 wordtree_compress(spin.si_keeproot, &spin);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3779 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3780
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3781 if (!error)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3782 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3783 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3784 * Write the info in the spell file.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3785 */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3786 if (!added_word || p_verbose > 2)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3787 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3788 if (added_word)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3789 verbose_enter();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3790 smsg((char_u *)_("Writing spell file %s..."), wfname);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3791 out_flush();
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3792 if (added_word)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3793 verbose_leave();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3794 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3795
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3796 write_vim_spell(wfname, &spin);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3797
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3798 if (!added_word || p_verbose > 2)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3799 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3800 if (added_word)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3801 verbose_enter();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3802 MSG(_("Done!"));
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3803 smsg((char_u *)_("Estimated runtime memory use: %d bytes"),
302
250611b3068d updated for version 7.0080
vimboss
parents: 300
diff changeset
3804 spin.si_memtot);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3805 out_flush();
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3806 if (added_word)
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3807 verbose_leave();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3808 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3809
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3810 /* If the file is loaded need to reload it. */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3811 spell_reload_one(wfname, added_word);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3812 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3813
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3814 /* Free the allocated memory. */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3815 free_blocks(spin.si_blocks);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3816 ga_clear(&spin.si_rep);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3817 ga_clear(&spin.si_sal);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3818 ga_clear(&spin.si_map);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3819
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3820 /* Free the .aff file structures. */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3821 for (i = 0; i < incount; ++i)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3822 if (afile[i] != NULL)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3823 spell_free_aff(afile[i]);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3824 }
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3825 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3826
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3827
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3828 /*
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3829 * ":spellgood {word}"
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3830 * ":spellwrong {word}"
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3831 */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3832 void
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3833 ex_spell(eap)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3834 exarg_T *eap;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3835 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3836 spell_add_word(eap->arg, STRLEN(eap->arg), eap->cmdidx == CMD_spellwrong);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3837 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3838
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3839 /*
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3840 * Add "word[len]" to 'spellfile' as a good or bad word.
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3841 */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3842 void
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3843 spell_add_word(word, len, bad)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3844 char_u *word;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3845 int len;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3846 int bad;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3847 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3848 FILE *fd;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3849 buf_T *buf;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3850
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3851 if (*curbuf->b_p_spf == NUL)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3852 init_spellfile();
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3853 if (*curbuf->b_p_spf == NUL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3854 EMSG(_("E764: 'spellfile' is not set"));
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3855 else
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3856 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3857 /* Check that the user isn't editing the .add file somewhere. */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3858 buf = buflist_findname_exp(curbuf->b_p_spf);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3859 if (buf != NULL && buf->b_ml.ml_mfp == NULL)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3860 buf = NULL;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3861 if (buf != NULL && bufIsChanged(buf))
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3862 EMSG(_(e_bufloaded));
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3863 else
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3864 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3865 fd = mch_fopen((char *)curbuf->b_p_spf, "a");
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3866 if (fd == NULL)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3867 EMSG2(_(e_notopen), curbuf->b_p_spf);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3868 else
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3869 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3870 if (bad)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3871 fprintf(fd, "/!%.*s\n", len, word);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3872 else
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3873 fprintf(fd, "%.*s\n", len, word);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3874 fclose(fd);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3875
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3876 /* Update the .add.spl file. */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3877 mkspell(1, &curbuf->b_p_spf, FALSE, TRUE, TRUE);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3878
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3879 /* If the .add file is edited somewhere, reload it. */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3880 if (buf != NULL)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3881 buf_reload(buf);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3882
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3883 redraw_all_later(NOT_VALID);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3884 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3885 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3886 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3887 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3888
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3889 /*
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3890 * Initialize 'spellfile' for the current buffer.
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3891 */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3892 static void
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3893 init_spellfile()
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3894 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3895 char_u buf[MAXPATHL];
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3896 int l;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3897 slang_T *sl;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3898 char_u *rtp;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3899
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3900 if (*curbuf->b_p_spl != NUL && curbuf->b_langp.ga_len > 0)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3901 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3902 /* Loop over all entries in 'runtimepath'. */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3903 rtp = p_rtp;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3904 while (*rtp != NUL)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3905 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3906 /* Copy the path from 'runtimepath' to buf[]. */
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3907 copy_option_part(&rtp, buf, MAXPATHL, ",");
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3908 if (filewritable(buf) == 2)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3909 {
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3910 /* Use the first language name from 'spelllang' and the
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3911 * encoding used in the first loaded .spl file. */
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3912 sl = LANGP_ENTRY(curbuf->b_langp, 0)->lp_slang;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3913 l = STRLEN(buf);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3914 vim_snprintf((char *)buf + l, MAXPATHL - l,
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3915 "/spell/%.*s.%s.add",
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
3916 2, curbuf->b_p_spl,
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3917 strstr((char *)gettail(sl->sl_fname), ".ascii.") != NULL
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3918 ? (char_u *)"ascii" : spell_enc());
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3919 set_option_value((char_u *)"spellfile", 0L, buf, OPT_LOCAL);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3920 break;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3921 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3922 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3923 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
3924 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
3925
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
3926
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3927 /*
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3928 * Init the chartab used for spelling for ASCII.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3929 * EBCDIC is not supported!
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3930 */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3931 static void
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3932 clear_spell_chartab(sp)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3933 spelltab_T *sp;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3934 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3935 int i;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3936
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3937 /* Init everything to FALSE. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3938 vim_memset(sp->st_isw, FALSE, sizeof(sp->st_isw));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3939 vim_memset(sp->st_isu, FALSE, sizeof(sp->st_isu));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3940 for (i = 0; i < 256; ++i)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3941 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3942 sp->st_fold[i] = i;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3943 sp->st_upper[i] = i;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3944 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3945
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3946 /* We include digits. A word shouldn't start with a digit, but handling
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3947 * that is done separately. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3948 for (i = '0'; i <= '9'; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3949 sp->st_isw[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3950 for (i = 'A'; i <= 'Z'; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3951 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3952 sp->st_isw[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3953 sp->st_isu[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3954 sp->st_fold[i] = i + 0x20;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3955 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3956 for (i = 'a'; i <= 'z'; ++i)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3957 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3958 sp->st_isw[i] = TRUE;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3959 sp->st_upper[i] = i - 0x20;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3960 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3961 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3962
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3963 /*
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3964 * Init the chartab used for spelling. Only depends on 'encoding'.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3965 * Called once while starting up and when 'encoding' changes.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3966 * 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
3967 * characters to make it possible that 'encoding' differs from the current
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3968 * locale.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3969 */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3970 void
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3971 init_spell_chartab()
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3972 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3973 int i;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3974
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3975 did_set_spelltab = FALSE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3976 clear_spell_chartab(&spelltab);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3977
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3978 #ifdef FEAT_MBYTE
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3979 if (enc_dbcs)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3980 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3981 /* DBCS: assume double-wide characters are word characters. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3982 for (i = 128; i <= 255; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3983 if (MB_BYTE2LEN(i) == 2)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3984 spelltab.st_isw[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3985 }
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3986 else if (enc_utf8)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3987 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3988 for (i = 128; i < 256; ++i)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3989 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3990 spelltab.st_isu[i] = utf_isupper(i);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3991 spelltab.st_isw[i] = spelltab.st_isu[i] || utf_islower(i);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3992 spelltab.st_fold[i] = utf_fold(i);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3993 spelltab.st_upper[i] = utf_toupper(i);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3994 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3995 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3996 else
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3997 #endif
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
3998 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3999 /* Rough guess: use locale-dependent library functions. */
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4000 for (i = 128; i < 256; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4001 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4002 if (MB_ISUPPER(i))
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4003 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4004 spelltab.st_isw[i] = TRUE;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4005 spelltab.st_isu[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4006 spelltab.st_fold[i] = MB_TOLOWER(i);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4007 }
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4008 else if (MB_ISLOWER(i))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4009 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4010 spelltab.st_isw[i] = TRUE;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4011 spelltab.st_upper[i] = MB_TOUPPER(i);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4012 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4013 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4014 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4015 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4016
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4017 static char *e_affform = N_("E761: Format error in affix file FOL, LOW or UPP");
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4018 static char *e_affrange = N_("E762: Character in FOL, LOW or UPP is out of range");
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4019
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4020 /*
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4021 * Set the spell character tables from strings in the affix file.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4022 */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4023 static int
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4024 set_spell_chartab(fol, low, upp)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4025 char_u *fol;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4026 char_u *low;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4027 char_u *upp;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4028 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4029 /* We build the new tables here first, so that we can compare with the
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4030 * previous one. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4031 spelltab_T new_st;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4032 char_u *pf = fol, *pl = low, *pu = upp;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4033 int f, l, u;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4034
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4035 clear_spell_chartab(&new_st);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4036
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4037 while (*pf != NUL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4038 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4039 if (*pl == NUL || *pu == NUL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4040 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4041 EMSG(_(e_affform));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4042 return FAIL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4043 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4044 #ifdef FEAT_MBYTE
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4045 f = mb_ptr2char_adv(&pf);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4046 l = mb_ptr2char_adv(&pl);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4047 u = mb_ptr2char_adv(&pu);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4048 #else
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4049 f = *pf++;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4050 l = *pl++;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4051 u = *pu++;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4052 #endif
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4053 /* Every character that appears is a word character. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4054 if (f < 256)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4055 new_st.st_isw[f] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4056 if (l < 256)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4057 new_st.st_isw[l] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4058 if (u < 256)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4059 new_st.st_isw[u] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4060
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4061 /* if "LOW" and "FOL" are not the same the "LOW" char needs
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4062 * case-folding */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4063 if (l < 256 && l != f)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4064 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4065 if (f >= 256)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4066 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4067 EMSG(_(e_affrange));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4068 return FAIL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4069 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4070 new_st.st_fold[l] = f;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4071 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4072
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4073 /* if "UPP" and "FOL" are not the same the "UPP" char needs
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4074 * case-folding, it's upper case and the "UPP" is the upper case of
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4075 * "FOL" . */
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4076 if (u < 256 && u != f)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4077 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4078 if (f >= 256)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4079 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4080 EMSG(_(e_affrange));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4081 return FAIL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4082 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4083 new_st.st_fold[u] = f;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4084 new_st.st_isu[u] = TRUE;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4085 new_st.st_upper[f] = u;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4086 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4087 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4088
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4089 if (*pl != NUL || *pu != NUL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4090 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4091 EMSG(_(e_affform));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4092 return FAIL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4093 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4094
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4095 return set_spell_finish(&new_st);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4096 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4097
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4098 /*
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4099 * Set the spell character tables from strings in the .spl file.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4100 */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4101 static int
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4102 set_spell_charflags(flags, cnt, upp)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4103 char_u *flags;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4104 int cnt;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4105 char_u *upp;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4106 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4107 /* We build the new tables here first, so that we can compare with the
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4108 * previous one. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4109 spelltab_T new_st;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4110 int i;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4111 char_u *p = upp;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4112 int c;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4113
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4114 clear_spell_chartab(&new_st);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4115
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4116 for (i = 0; i < cnt; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4117 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4118 new_st.st_isw[i + 128] = (flags[i] & CF_WORD) != 0;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4119 new_st.st_isu[i + 128] = (flags[i] & CF_UPPER) != 0;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4120
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4121 if (*p == NUL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4122 return FAIL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4123 #ifdef FEAT_MBYTE
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4124 c = mb_ptr2char_adv(&p);
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4125 #else
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4126 c = *p++;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4127 #endif
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4128 new_st.st_fold[i + 128] = c;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4129 if (i + 128 != c && new_st.st_isu[i + 128] && c < 256)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4130 new_st.st_upper[c] = i + 128;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4131 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4132
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4133 return set_spell_finish(&new_st);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4134 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4135
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4136 static int
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4137 set_spell_finish(new_st)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4138 spelltab_T *new_st;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4139 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4140 int i;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4141
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4142 if (did_set_spelltab)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4143 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4144 /* check that it's the same table */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4145 for (i = 0; i < 256; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4146 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4147 if (spelltab.st_isw[i] != new_st->st_isw[i]
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4148 || spelltab.st_isu[i] != new_st->st_isu[i]
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4149 || spelltab.st_fold[i] != new_st->st_fold[i]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4150 || spelltab.st_upper[i] != new_st->st_upper[i])
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4151 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4152 EMSG(_("E763: Word characters differ between spell files"));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4153 return FAIL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4154 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4155 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4156 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4157 else
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4158 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4159 /* copy the new spelltab into the one being used */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4160 spelltab = *new_st;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4161 did_set_spelltab = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4162 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4163
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4164 return OK;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4165 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4166
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4167 /*
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4168 * Write the current tables into the .spl file.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4169 * This makes sure the same characters are recognized as word characters when
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4170 * generating an when using a spell file.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4171 */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4172 static void
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4173 write_spell_chartab(fd)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4174 FILE *fd;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4175 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4176 char_u charbuf[256 * 4];
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4177 int len = 0;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4178 int flags;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4179 int i;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4180
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4181 fputc(128, fd); /* <charflagslen> */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4182 for (i = 128; i < 256; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4183 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4184 flags = 0;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4185 if (spelltab.st_isw[i])
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4186 flags |= CF_WORD;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4187 if (spelltab.st_isu[i])
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4188 flags |= CF_UPPER;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4189 fputc(flags, fd); /* <charflags> */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4190
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
4191 #ifdef FEAT_MBYTE
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
4192 if (has_mbyte)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
4193 len += mb_char2bytes(spelltab.st_fold[i], charbuf + len);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
4194 else
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
4195 #endif
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
4196 charbuf[len++] = spelltab.st_fold[i];
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4197 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4198
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4199 put_bytes(fd, (long_u)len, 2); /* <fcharlen> */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4200 fwrite(charbuf, (size_t)len, (size_t)1, fd); /* <fchars> */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4201 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4202
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4203 /*
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4204 * Case-fold "str[len]" into "buf[buflen]". The result is NUL terminated.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4205 * Uses the character definitions from the .spl file.
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4206 * When using a multi-byte 'encoding' the length may change!
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4207 * Returns FAIL when something wrong.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4208 */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4209 static int
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4210 spell_casefold(str, len, buf, buflen)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4211 char_u *str;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4212 int len;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4213 char_u *buf;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4214 int buflen;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4215 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4216 int i;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4217
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4218 if (len >= buflen)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4219 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4220 buf[0] = NUL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4221 return FAIL; /* result will not fit */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4222 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4223
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4224 #ifdef FEAT_MBYTE
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4225 if (has_mbyte)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4226 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4227 int outi = 0;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4228 char_u *p;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4229 int c;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4230
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4231 /* Fold one character at a time. */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4232 for (p = str; p < str + len; )
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4233 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4234 if (outi + MB_MAXBYTES > buflen)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4235 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4236 buf[outi] = NUL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4237 return FAIL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4238 }
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4239 c = mb_ptr2char_adv(&p);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4240 outi += mb_char2bytes(SPELL_TOFOLD(c), buf + outi);
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4241 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4242 buf[outi] = NUL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4243 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4244 else
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4245 #endif
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4246 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4247 /* Be quick for non-multibyte encodings. */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4248 for (i = 0; i < len; ++i)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4249 buf[i] = spelltab.st_fold[str[i]];
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4250 buf[i] = NUL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4251 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4252
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4253 return OK;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4254 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
4255
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4256 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4257 * "z?": Find badly spelled word under or after the cursor.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4258 * Give suggestions for the properly spelled word.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4259 * This is based on the mechanisms of Aspell, but completely reimplemented.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4260 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4261 void
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4262 spell_suggest()
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4263 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4264 char_u *line;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4265 pos_T prev_cursor = curwin->w_cursor;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4266 int attr;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4267 char_u wcopy[MAXWLEN + 2];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4268 char_u *p;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4269 int i;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4270 int c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4271 suginfo_T sug;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4272 suggest_T *stp;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4273
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4274 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4275 * Find the start of the badly spelled word.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4276 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4277 if (spell_move_to(FORWARD, TRUE, TRUE) == FAIL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4278 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4279 beep_flush();
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4280 return;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4281 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4282
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4283 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4284 * Set the info in "sug".
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4285 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4286 vim_memset(&sug, 0, sizeof(sug));
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4287 ga_init2(&sug.su_ga, (int)sizeof(suggest_T), 10);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4288 hash_init(&sug.su_banned);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4289 line = ml_get_curline();
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4290 sug.su_badptr = line + curwin->w_cursor.col;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4291 sug.su_badlen = spell_check(curwin, sug.su_badptr, &attr);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4292 if (sug.su_badlen >= MAXWLEN)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4293 sug.su_badlen = MAXWLEN - 1; /* just in case */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4294 vim_strncpy(sug.su_badword, sug.su_badptr, sug.su_badlen);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4295 (void)spell_casefold(sug.su_badptr, sug.su_badlen,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4296 sug.su_fbadword, MAXWLEN);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4297
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4298 /* Ban the bad word itself. It may appear in another region. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4299 add_banned(&sug, sug.su_badword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4300
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4301 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4302 * 1. Try inserting/deleting/swapping/changing a letter, use REP entries
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4303 * from the .aff file and inserting a space (split the word).
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4304 *
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4305 * Set a maximum score to limit the combination of operations that is
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4306 * tried.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4307 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4308 sug.su_maxscore = SCORE_MAXINIT;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4309 spell_try_change(&sug);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4310
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4311 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4312 * 2. Try finding sound-a-like words.
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4313 *
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4314 * Only do this when we don't have a lot of suggestions yet, because it's
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4315 * very slow and often doesn't find new suggestions.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4316 */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4317 if (sug.su_ga.ga_len < SUG_CLEAN_COUNT)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4318 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4319 /* Allow a higher score now. */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4320 sug.su_maxscore = SCORE_MAXMAX;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4321 spell_try_soundalike(&sug);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4322 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4324 /* When CTRL-C was hit while searching do show the results. */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4325 ui_breakcheck();
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4326 if (got_int)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4327 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4328 (void)vgetc();
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4329 got_int = FALSE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4330 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4331
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4332 if (sug.su_ga.ga_len == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4333 MSG(_("Sorry, no suggestions"));
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4334 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4335 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4336 #ifdef RESCORE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4337 /* Do slow but more accurate computation of the word score. */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4338 rescore_suggestions(&sug);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4339 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4340
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4341 /* Sort the suggestions and truncate at SUG_PROMPT_COUNT. */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4342 cleanup_suggestions(&sug, SUG_PROMPT_COUNT);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4343
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4344 /* List the suggestions. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4345 msg_start();
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4346 vim_snprintf((char *)IObuff, IOSIZE, _("Change \"%.*s\" to:"),
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4347 sug.su_badlen, sug.su_badptr);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4348 msg_puts(IObuff);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4349 msg_clr_eos();
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4350 msg_putchar('\n');
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4351 msg_scroll = TRUE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4352 for (i = 0; i < sug.su_ga.ga_len; ++i)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4353 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4354 stp = &SUG(&sug, i);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4355
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4356 /* The suggested word may replace only part of the bad word, add
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4357 * the not replaced part. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4358 STRCPY(wcopy, stp->st_word);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4359 if (sug.su_badlen > stp->st_orglen)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4360 vim_strncpy(wcopy + STRLEN(wcopy),
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4361 sug.su_badptr + stp->st_orglen,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4362 sug.su_badlen - stp->st_orglen);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4363 if (p_verbose > 0)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4364 vim_snprintf((char *)IObuff, IOSIZE, _("%2d \"%s\" (%d)"),
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4365 i + 1, wcopy, stp->st_score);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4366 else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4367 vim_snprintf((char *)IObuff, IOSIZE, _("%2d \"%s\""),
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4368 i + 1, wcopy);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4369 msg_puts(IObuff);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4370 lines_left = 3; /* avoid more prompt */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4371 msg_putchar('\n');
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4372 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4373
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4374 /* Ask for choice. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4375 i = prompt_for_number();
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4376 if (i > 0 && i <= sug.su_ga.ga_len && u_save_cursor())
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4377 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4378 /* Replace the word. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4379 stp = &SUG(&sug, i - 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4380 p = alloc(STRLEN(line) - stp->st_orglen + STRLEN(stp->st_word) + 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4381 if (p != NULL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4382 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4383 c = sug.su_badptr - line;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4384 mch_memmove(p, line, c);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4385 STRCPY(p + c, stp->st_word);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4386 STRCAT(p, sug.su_badptr + stp->st_orglen);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4387 ml_replace(curwin->w_cursor.lnum, p, FALSE);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4388 curwin->w_cursor.col = c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4389 changed_bytes(curwin->w_cursor.lnum, c);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4390 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4391 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4392 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4393 curwin->w_cursor = prev_cursor;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4394 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4395
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4396 /* Free the suggestions. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4397 for (i = 0; i < sug.su_ga.ga_len; ++i)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4398 vim_free(SUG(&sug, i).st_word);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4399 ga_clear(&sug.su_ga);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4400
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4401 /* Free the banned words. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4402 free_banned(&sug);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4403 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4404
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4405 /*
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4406 * 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
4407 * "wcopy[MAXWLEN]". "word" must not be empty.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4408 * The result is NUL terminated.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4409 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4410 static void
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4411 onecap_copy(word, wcopy, upper)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4412 char_u *word;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4413 char_u *wcopy;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4414 int upper; /* TRUE: first letter made upper case */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4415 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4416 char_u *p;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4417 int c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4418 int l;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4419
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4420 p = word;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4421 #ifdef FEAT_MBYTE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4422 if (has_mbyte)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4423 c = mb_ptr2char_adv(&p);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4424 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4425 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4426 c = *p++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4427 if (upper)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4428 c = SPELL_TOUPPER(c);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4429 else
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4430 c = SPELL_TOFOLD(c);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4431 #ifdef FEAT_MBYTE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4432 if (has_mbyte)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4433 l = mb_char2bytes(c, wcopy);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4434 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4435 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4436 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4437 l = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4438 wcopy[0] = c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4439 }
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4440 vim_strncpy(wcopy + l, p, MAXWLEN - l);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4441 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4442
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4443 /*
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4444 * Make a copy of "word" with all the letters upper cased into
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4445 * "wcopy[MAXWLEN]". The result is NUL terminated.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4446 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4447 static void
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4448 allcap_copy(word, wcopy)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4449 char_u *word;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4450 char_u *wcopy;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4451 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4452 char_u *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4453 char_u *d;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4454 int c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4455
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4456 d = wcopy;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4457 for (s = word; *s != NUL; )
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4458 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4459 #ifdef FEAT_MBYTE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4460 if (has_mbyte)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4461 c = mb_ptr2char_adv(&s);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4462 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4463 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4464 c = *s++;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4465 c = SPELL_TOUPPER(c);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4466
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4467 #ifdef FEAT_MBYTE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4468 if (has_mbyte)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4469 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4470 if (d - wcopy >= MAXWLEN - MB_MAXBYTES)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4471 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4472 d += mb_char2bytes(c, d);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4473 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4474 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4475 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4476 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4477 if (d - wcopy >= MAXWLEN - 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4478 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4479 *d++ = c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4480 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4481 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4482 *d = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4483 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4484
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4485 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4486 * Try finding suggestions by adding/removing/swapping letters.
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4487 *
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4488 * This uses a state machine. At each node in the tree we try various
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4489 * operations. When trying if an operation work "depth" is increased and the
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4490 * stack[] is used to store info. This allows combinations, thus insert one
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4491 * character, replace one and delete another. The number of changes is
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4492 * limited by su->su_maxscore, checked in try_deeper().
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4493 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4494 static void
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4495 spell_try_change(su)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4496 suginfo_T *su;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4497 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4498 char_u fword[MAXWLEN]; /* copy of the bad word, case-folded */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4499 char_u tword[MAXWLEN]; /* good word collected so far */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4500 trystate_T stack[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4501 char_u preword[MAXWLEN * 3]; /* word found with proper case (appended
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4502 * to for word split) */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4503 char_u prewordlen = 0; /* length of word in "preword" */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4504 int splitoff = 0; /* index in tword after last split */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4505 trystate_T *sp;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4506 int newscore;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4507 langp_T *lp;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4508 char_u *byts;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4509 idx_T *idxs;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4510 int depth;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4511 int c, c2, c3;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4512 int n = 0;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4513 int flags;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4514 int badflags;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4515 garray_T *gap;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4516 idx_T arridx;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4517 int len;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4518 char_u *p;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4519 fromto_T *ftp;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4520 int fl = 0, tl;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4521
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4522 /* get caps flags for bad word */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4523 badflags = captype(su->su_badptr, su->su_badptr + su->su_badlen);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4524
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4525 /* We make a copy of the case-folded bad word, so that we can modify it
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4526 * to find matches (esp. REP items). */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4527 STRCPY(fword, su->su_fbadword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4528
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4529
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4530 for (lp = LANGP_ENTRY(curwin->w_buffer->b_langp, 0);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4531 lp->lp_slang != NULL; ++lp)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4532 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4533 #ifdef SOUNDFOLD_SCORE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4534 su->su_slang = lp->lp_slang;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4535 if (lp->lp_slang->sl_sal.ga_len > 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4536 /* soundfold the bad word */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4537 spell_soundfold(lp->lp_slang, su->su_fbadword, su->su_salword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4538 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4539
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4540 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4541 * Go through the whole case-fold tree, try changes at each node.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4542 * "tword[]" contains the word collected from nodes in the tree.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4543 * "fword[]" the word we are trying to match with (initially the bad
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4544 * word).
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4545 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4546 byts = lp->lp_slang->sl_fbyts;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4547 idxs = lp->lp_slang->sl_fidxs;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4548
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4549 depth = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4550 stack[0].ts_state = STATE_START;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4551 stack[0].ts_score = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4552 stack[0].ts_curi = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4553 stack[0].ts_fidx = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4554 stack[0].ts_fidxtry = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4555 stack[0].ts_twordlen = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4556 stack[0].ts_arridx = 0;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4557 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4558 stack[0].ts_tcharlen = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4559 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4560
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4561 /*
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4562 * Loop to find all suggestions. At each round we either:
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4563 * - For the current state try one operation, advance "ts_curi",
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4564 * increase "depth".
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4565 * - When a state is done go to the next, set "ts_state".
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4566 * - When all states are tried decrease "depth".
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4567 */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4568 while (depth >= 0 && !got_int)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4569 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4570 sp = &stack[depth];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4571 switch (sp->ts_state)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4572 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4573 case STATE_START:
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4574 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4575 * Start of node: Deal with NUL bytes, which means
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4576 * tword[] may end here.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4577 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4578 arridx = sp->ts_arridx; /* current node in the tree */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4579 len = byts[arridx]; /* bytes in this node */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4580 arridx += sp->ts_curi; /* index of current byte */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4581
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4582 if (sp->ts_curi > len || (c = byts[arridx]) != 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4583 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4584 /* Past bytes in node and/or past NUL bytes. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4585 sp->ts_state = STATE_ENDNUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4586 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4587 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4588
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4589 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4590 * End of word in tree.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4591 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4592 ++sp->ts_curi; /* eat one NUL byte */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4593
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4594 flags = (int)idxs[arridx];
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4595
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4596 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4597 * Form the word with proper case in preword.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4598 * If there is a word from a previous split, append.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4599 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4600 tword[sp->ts_twordlen] = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4601 if (flags & WF_KEEPCAP)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4602 /* Must find the word in the keep-case tree. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4603 find_keepcap_word(lp->lp_slang, tword + splitoff,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4604 preword + prewordlen);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4605 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4606 /* Include badflags: if the badword is onecap or allcap
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4607 * use that for the goodword too. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4608 make_case_word(tword + splitoff,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4609 preword + prewordlen, flags | badflags);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4610
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4611 /* Don't use a banned word. It may appear again as a good
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4612 * word, thus remember it. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4613 if (flags & WF_BANNED)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4614 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4615 add_banned(su, preword + prewordlen);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4616 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4617 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4618 if (was_banned(su, preword + prewordlen))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4619 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4620
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4621 newscore = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4622 if ((flags & WF_REGION)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4623 && (((unsigned)flags >> 8) & lp->lp_region) == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4624 newscore += SCORE_REGION;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4625 if (flags & WF_RARE)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4626 newscore += SCORE_RARE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4627
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4628 if (!spell_valid_case(badflags,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4629 captype(preword + prewordlen, NULL)))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4630 newscore += SCORE_ICASE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4631
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4632 if (fword[sp->ts_fidx] == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4633 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4634 /* The badword also ends: add suggestions, */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4635 add_suggestion(su, preword, sp->ts_score + newscore
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4636 #ifdef RESCORE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4637 , FALSE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4638 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4639 );
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4640 }
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4641 else if (sp->ts_fidx >= sp->ts_fidxtry
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4642 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4643 /* Don't split halfway a character. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4644 && (!has_mbyte || sp->ts_tcharlen == 0)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4645 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4646 )
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4647 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4648 /* The word in the tree ends but the badword
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4649 * continues: try inserting a space and check that a valid
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4650 * words starts at fword[sp->ts_fidx]. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4651 if (try_deeper(su, stack, depth, newscore + SCORE_SPLIT))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4652 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4653 /* Save things to be restored at STATE_SPLITUNDO. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4654 sp->ts_save_prewordlen = prewordlen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4655 sp->ts_save_badflags = badflags;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4656 sp->ts_save_splitoff = splitoff;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4657
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4658 /* Append a space to preword. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4659 STRCAT(preword, " ");
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4660 prewordlen = STRLEN(preword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4661 splitoff = sp->ts_twordlen;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4662 #ifdef FEAT_MBYTE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4663 if (has_mbyte)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4664 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4665 int i = 0;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4666
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4667 /* Case-folding may change the number of bytes:
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4668 * Count nr of chars in fword[sp->ts_fidx] and
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4669 * advance that many chars in su->su_badptr. */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4670 for (p = fword; p < fword + sp->ts_fidx;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4671 mb_ptr_adv(p))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4672 ++i;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4673 for (p = su->su_badptr; i > 0; mb_ptr_adv(p))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4674 --i;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4675 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4676 else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4677 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4678 p = su->su_badptr + sp->ts_fidx;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
4679 badflags = captype(p, su->su_badptr + su->su_badlen);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4680
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4681 sp->ts_state = STATE_SPLITUNDO;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4682 ++depth;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4683 /* Restart at top of the tree. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4684 stack[depth].ts_arridx = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4685 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4686 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4687 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4688
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4689 case STATE_SPLITUNDO:
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4690 /* Fixup the changes done for word split. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4691 badflags = sp->ts_save_badflags;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4692 splitoff = sp->ts_save_splitoff;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4693 prewordlen = sp->ts_save_prewordlen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4694
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4695 /* Continue looking for NUL bytes. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4696 sp->ts_state = STATE_START;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4697 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4698
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4699 case STATE_ENDNUL:
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4700 /* Past the NUL bytes in the node. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4701 if (fword[sp->ts_fidx] == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4702 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4703 /* The badword ends, can't use the bytes in this node. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4704 sp->ts_state = STATE_DEL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4705 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4706 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4707 sp->ts_state = STATE_PLAIN;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4708 /*FALLTHROUGH*/
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4709
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4710 case STATE_PLAIN:
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4711 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4712 * Go over all possible bytes at this node, add each to
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4713 * tword[] and use child node. "ts_curi" is the index.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4714 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4715 arridx = sp->ts_arridx;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4716 if (sp->ts_curi > byts[arridx])
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4717 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4718 /* Done all bytes at this node, do next state. When still
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4719 * at already changed bytes skip the other tricks. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4720 if (sp->ts_fidx >= sp->ts_fidxtry)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4721 sp->ts_state = STATE_DEL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4722 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4723 sp->ts_state = STATE_FINAL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4724 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4725 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4726 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4727 arridx += sp->ts_curi++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4728 c = byts[arridx];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4729
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4730 /* Normal byte, go one level deeper. If it's not equal to
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4731 * the byte in the bad word adjust the score. But don't
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4732 * even try when the byte was already changed. */
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4733 if (c == fword[sp->ts_fidx]
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4734 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4735 || (sp->ts_tcharlen > 0
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4736 && sp->ts_isdiff != DIFF_NONE)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4737 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4738 )
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4739 newscore = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4740 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4741 newscore = SCORE_SUBST;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4742 if ((newscore == 0 || sp->ts_fidx >= sp->ts_fidxtry)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4743 && try_deeper(su, stack, depth, newscore))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4744 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4745 ++depth;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4746 sp = &stack[depth];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4747 ++sp->ts_fidx;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4748 tword[sp->ts_twordlen++] = c;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4749 sp->ts_arridx = idxs[arridx];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4750 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4751 if (newscore == SCORE_SUBST)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4752 sp->ts_isdiff = DIFF_YES;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4753 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4754 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4755 /* Multi-byte characters are a bit complicated to
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4756 * handle: They differ when any of the bytes
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4757 * differ and then their length may also differ. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4758 if (sp->ts_tcharlen == 0)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4759 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4760 /* First byte. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4761 sp->ts_tcharidx = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4762 sp->ts_tcharlen = MB_BYTE2LEN(c);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4763 sp->ts_fcharstart = sp->ts_fidx - 1;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4764 sp->ts_isdiff = (newscore != 0)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4765 ? DIFF_YES : DIFF_NONE;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4766 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4767 else if (sp->ts_isdiff == DIFF_INSERT)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4768 /* When inserting trail bytes don't advance in
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4769 * the bad word. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4770 --sp->ts_fidx;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4771 if (++sp->ts_tcharidx == sp->ts_tcharlen)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4772 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4773 /* Last byte of character. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4774 if (sp->ts_isdiff == DIFF_YES)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4775 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4776 /* Correct ts_fidx for the byte length of
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4777 * the character (we didn't check that
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4778 * before). */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4779 sp->ts_fidx = sp->ts_fcharstart
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4780 + MB_BYTE2LEN(
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4781 fword[sp->ts_fcharstart]);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4782
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4783 /* For a similar character adjust score
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4784 * from SCORE_SUBST to SCORE_SIMILAR. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4785 if (lp->lp_slang->sl_has_map
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4786 && similar_chars(lp->lp_slang,
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4787 mb_ptr2char(tword
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4788 + sp->ts_twordlen
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4789 - sp->ts_tcharlen),
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4790 mb_ptr2char(fword
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4791 + sp->ts_fcharstart)))
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4792 sp->ts_score -=
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4793 SCORE_SUBST - SCORE_SIMILAR;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4794 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4795
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4796 /* Starting a new char, reset the length. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4797 sp->ts_tcharlen = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4798 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4799 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4800 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4801 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4802 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4803 /* If we found a similar char adjust the score.
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4804 * We do this after calling try_deeper() because
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4805 * it's slow. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4806 if (newscore != 0
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4807 && lp->lp_slang->sl_has_map
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4808 && similar_chars(lp->lp_slang,
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4809 c, fword[sp->ts_fidx - 1]))
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4810 sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4811 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4812 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4813 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4814 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4815
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4816 case STATE_DEL:
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4817 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4818 /* When past the first byte of a multi-byte char don't try
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4819 * delete/insert/swap a character. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4820 if (has_mbyte && sp->ts_tcharlen > 0)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4821 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4822 sp->ts_state = STATE_FINAL;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4823 break;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4824 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4825 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4826 /*
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4827 * Try skipping one character in the bad word (delete it).
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4828 */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4829 sp->ts_state = STATE_INS;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4830 sp->ts_curi = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4831 if (fword[sp->ts_fidx] != NUL
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4832 && try_deeper(su, stack, depth, SCORE_DEL))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4833 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4834 ++depth;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4835 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4836 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4837 stack[depth].ts_fidx += MB_BYTE2LEN(fword[sp->ts_fidx]);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4838 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4839 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4840 ++stack[depth].ts_fidx;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4841 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4842 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4843 /*FALLTHROUGH*/
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4844
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4845 case STATE_INS:
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4846 /* Insert one byte. Do this for each possible byte at this
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4847 * node. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4848 n = sp->ts_arridx;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4849 if (sp->ts_curi > byts[n])
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4850 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4851 /* Done all bytes at this node, do next state. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4852 sp->ts_state = STATE_SWAP;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4853 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4854 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4855 {
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4856 /* Do one more byte at this node. Skip NUL bytes. */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4857 n += sp->ts_curi++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4858 c = byts[n];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4859 if (c != 0 && try_deeper(su, stack, depth, SCORE_INS))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4860 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4861 ++depth;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4862 sp = &stack[depth];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4863 tword[sp->ts_twordlen++] = c;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4864 sp->ts_arridx = idxs[n];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4865 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4866 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4867 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4868 fl = MB_BYTE2LEN(c);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4869 if (fl > 1)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4870 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4871 /* There are following bytes for the same
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4872 * character. We must find all bytes before
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4873 * trying delete/insert/swap/etc. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4874 sp->ts_tcharlen = fl;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4875 sp->ts_tcharidx = 1;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4876 sp->ts_isdiff = DIFF_INSERT;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4877 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4878 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4879 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4880 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4881 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4882 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4883
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4884 case STATE_SWAP:
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4885 /*
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4886 * Swap two bytes in the bad word: "12" -> "21".
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4887 * We change "fword" here, it's changed back afterwards.
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4888 */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4889 p = fword + sp->ts_fidx;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4890 c = *p;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4891 if (c == NUL)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4892 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4893 /* End of word, can't swap or replace. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4894 sp->ts_state = STATE_FINAL;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4895 break;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4896 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4897 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4898 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4899 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4900 n = mb_ptr2len_check(p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4901 c = mb_ptr2char(p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4902 c2 = mb_ptr2char(p + n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4903 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4904 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4905 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4906 c2 = p[1];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4907 if (c == c2)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4908 {
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4909 /* Characters are identical, swap won't do anything. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4910 sp->ts_state = STATE_SWAP3;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4911 break;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4912 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4913 if (c2 != NUL && try_deeper(su, stack, depth, SCORE_SWAP))
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4914 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4915 sp->ts_state = STATE_UNSWAP;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4916 ++depth;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4917 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4918 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4919 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4920 fl = mb_char2len(c2);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4921 mch_memmove(p, p + n, fl);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4922 mb_char2bytes(c, p + fl);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4923 stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4924 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4925 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4926 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4927 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4928 p[0] = c2;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4929 p[1] = c;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4930 stack[depth].ts_fidxtry = sp->ts_fidx + 2;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4931 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4932 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4933 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4934 /* If this swap doesn't work then SWAP3 won't either. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4935 sp->ts_state = STATE_REP_INI;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4936 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4937
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4938 case STATE_UNSWAP:
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4939 /* Undo the STATE_SWAP swap: "21" -> "12". */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4940 p = fword + sp->ts_fidx;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4941 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4942 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4943 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4944 n = MB_BYTE2LEN(*p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4945 c = mb_ptr2char(p + n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4946 mch_memmove(p + MB_BYTE2LEN(p[n]), p, n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4947 mb_char2bytes(c, p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4948 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4949 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4950 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4951 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4952 c = *p;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4953 *p = p[1];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4954 p[1] = c;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4955 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4956 /*FALLTHROUGH*/
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4957
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4958 case STATE_SWAP3:
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4959 /* Swap two bytes, skipping one: "123" -> "321". We change
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4960 * "fword" here, it's changed back afterwards. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4961 p = fword + sp->ts_fidx;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4962 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4963 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4964 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4965 n = mb_ptr2len_check(p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4966 c = mb_ptr2char(p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4967 fl = mb_ptr2len_check(p + n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4968 c2 = mb_ptr2char(p + n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4969 c3 = mb_ptr2char(p + n + fl);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4970 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4971 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4972 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4973 {
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4974 c = *p;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4975 c2 = p[1];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4976 c3 = p[2];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4977 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4978
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4979 /* When characters are identical: "121" then SWAP3 result is
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4980 * identical, ROT3L result is same as SWAP: "211", ROT3L
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4981 * result is same as SWAP on next char: "112". Thus skip all
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4982 * swapping. Also skip when c3 is NUL. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4983 if (c == c3 || c3 == NUL)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4984 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4985 sp->ts_state = STATE_REP_INI;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4986 break;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4987 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4988 if (try_deeper(su, stack, depth, SCORE_SWAP3))
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4989 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4990 sp->ts_state = STATE_UNSWAP3;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
4991 ++depth;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4992 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4993 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4994 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4995 tl = mb_char2len(c3);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4996 mch_memmove(p, p + n + fl, tl);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4997 mb_char2bytes(c2, p + tl);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4998 mb_char2bytes(c, p + fl + tl);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
4999 stack[depth].ts_fidxtry = sp->ts_fidx + n + fl + tl;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5000 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5001 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5002 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5003 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5004 p[0] = p[2];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5005 p[2] = c;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5006 stack[depth].ts_fidxtry = sp->ts_fidx + 3;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5007 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5008 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5009 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5010 sp->ts_state = STATE_REP_INI;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5011 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5012
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5013 case STATE_UNSWAP3:
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5014 /* Undo STATE_SWAP3: "321" -> "123" */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5015 p = fword + sp->ts_fidx;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5016 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5017 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5018 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5019 n = MB_BYTE2LEN(*p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5020 c2 = mb_ptr2char(p + n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5021 fl = MB_BYTE2LEN(p[n]);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5022 c = mb_ptr2char(p + n + fl);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5023 tl = MB_BYTE2LEN(p[n + fl]);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5024 mch_memmove(p + fl + tl, p, n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5025 mb_char2bytes(c, p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5026 mb_char2bytes(c2, p + tl);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5027 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5028 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5029 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5030 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5031 c = *p;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5032 *p = p[2];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5033 p[2] = c;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5034 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5035 /*FALLTHROUGH*/
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5036
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5037 case STATE_ROT3L:
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5038 /* Rotate three characters left: "123" -> "231". We change
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5039 * "fword" here, it's changed back afterwards. */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5040 if (try_deeper(su, stack, depth, SCORE_SWAP3))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5041 {
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5042 sp->ts_state = STATE_UNROT3L;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5043 ++depth;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5044 p = fword + sp->ts_fidx;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5045 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5046 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5047 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5048 n = mb_ptr2len_check(p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5049 c = mb_ptr2char(p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5050 fl = mb_ptr2len_check(p + n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5051 fl += mb_ptr2len_check(p + n + fl);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5052 mch_memmove(p, p + n, fl);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5053 mb_char2bytes(c, p + fl);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5054 stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5055 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5056 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5057 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5058 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5059 c = *p;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5060 *p = p[1];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5061 p[1] = p[2];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5062 p[2] = c;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5063 stack[depth].ts_fidxtry = sp->ts_fidx + 3;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5064 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5065 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5066 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5067 sp->ts_state = STATE_REP_INI;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5068 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5069
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5070 case STATE_UNROT3L:
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5071 /* Undo STATE_ROT3L: "231" -> "123" */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5072 p = fword + sp->ts_fidx;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5073 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5074 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5075 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5076 n = MB_BYTE2LEN(*p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5077 n += MB_BYTE2LEN(p[n]);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5078 c = mb_ptr2char(p + n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5079 tl = MB_BYTE2LEN(p[n]);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5080 mch_memmove(p + tl, p, n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5081 mb_char2bytes(c, p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5082 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5083 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5084 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5085 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5086 c = p[2];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5087 p[2] = p[1];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5088 p[1] = *p;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5089 *p = c;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5090 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5091 /*FALLTHROUGH*/
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5092
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5093 case STATE_ROT3R:
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5094 /* Rotate three bytes right: "123" -> "312". We change
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5095 * "fword" here, it's changed back afterwards. */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5096 if (try_deeper(su, stack, depth, SCORE_SWAP3))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5097 {
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5098 sp->ts_state = STATE_UNROT3R;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5099 ++depth;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5100 p = fword + sp->ts_fidx;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5101 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5102 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5103 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5104 n = mb_ptr2len_check(p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5105 n += mb_ptr2len_check(p + n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5106 c = mb_ptr2char(p + n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5107 tl = mb_ptr2len_check(p + n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5108 mch_memmove(p + tl, p, n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5109 mb_char2bytes(c, p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5110 stack[depth].ts_fidxtry = sp->ts_fidx + n + tl;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5111 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5112 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5113 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5114 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5115 c = p[2];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5116 p[2] = p[1];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5117 p[1] = *p;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5118 *p = c;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5119 stack[depth].ts_fidxtry = sp->ts_fidx + 3;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5120 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5121 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5122 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5123 sp->ts_state = STATE_REP_INI;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5124 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5125
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5126 case STATE_UNROT3R:
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5127 /* Undo STATE_ROT3R: "312" -> "123" */
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5128 p = fword + sp->ts_fidx;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5129 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5130 if (has_mbyte)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5131 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5132 c = mb_ptr2char(p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5133 tl = MB_BYTE2LEN(*p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5134 n = MB_BYTE2LEN(p[tl]);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5135 n += MB_BYTE2LEN(p[tl + n]);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5136 mch_memmove(p, p + tl, n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5137 mb_char2bytes(c, p + n);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5138 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5139 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5140 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5141 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5142 c = *p;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5143 *p = p[1];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5144 p[1] = p[2];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5145 p[2] = c;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5146 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5147 /*FALLTHROUGH*/
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5148
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5149 case STATE_REP_INI:
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5150 /* Check if matching with REP items from the .aff file would
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5151 * work. Quickly skip if there are no REP items or the score
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5152 * is going to be too high anyway. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5153 gap = &lp->lp_slang->sl_rep;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5154 if (gap->ga_len == 0
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5155 || sp->ts_score + SCORE_REP >= su->su_maxscore)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5156 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5157 sp->ts_state = STATE_FINAL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5158 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5159 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5160
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5161 /* Use the first byte to quickly find the first entry that
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5162 * may match. If the index is -1 there is none. */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5163 sp->ts_curi = lp->lp_slang->sl_rep_first[fword[sp->ts_fidx]];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5164 if (sp->ts_curi < 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5165 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5166 sp->ts_state = STATE_FINAL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5167 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5168 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5169
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5170 sp->ts_state = STATE_REP;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5171 /*FALLTHROUGH*/
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5172
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5173 case STATE_REP:
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5174 /* Try matching with REP items from the .aff file. For each
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5175 * match replace the characters and check if the resulting
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5176 * word is valid. */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5177 p = fword + sp->ts_fidx;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5178
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5179 gap = &lp->lp_slang->sl_rep;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5180 while (sp->ts_curi < gap->ga_len)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5181 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5182 ftp = (fromto_T *)gap->ga_data + sp->ts_curi++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5183 if (*ftp->ft_from != *p)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5184 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5185 /* past possible matching entries */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5186 sp->ts_curi = gap->ga_len;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5187 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5188 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5189 if (STRNCMP(ftp->ft_from, p, STRLEN(ftp->ft_from)) == 0
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5190 && try_deeper(su, stack, depth, SCORE_REP))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5191 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5192 /* Need to undo this afterwards. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5193 sp->ts_state = STATE_REP_UNDO;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5194
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5195 /* Change the "from" to the "to" string. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5196 ++depth;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5197 fl = STRLEN(ftp->ft_from);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5198 tl = STRLEN(ftp->ft_to);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5199 if (fl != tl)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5200 mch_memmove(p + tl, p + fl, STRLEN(p + fl) + 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5201 mch_memmove(p, ftp->ft_to, tl);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5202 stack[depth].ts_fidxtry = sp->ts_fidx + tl;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5203 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5204 stack[depth].ts_tcharlen = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5205 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5206 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5207 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5208 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5209
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5210 if (sp->ts_curi >= gap->ga_len)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5211 /* No (more) matches. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5212 sp->ts_state = STATE_FINAL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5213
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5214 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5215
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5216 case STATE_REP_UNDO:
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5217 /* Undo a REP replacement and continue with the next one. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5218 ftp = (fromto_T *)lp->lp_slang->sl_rep.ga_data
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5219 + sp->ts_curi - 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5220 fl = STRLEN(ftp->ft_from);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5221 tl = STRLEN(ftp->ft_to);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5222 p = fword + sp->ts_fidx;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5223 if (fl != tl)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5224 mch_memmove(p + fl, p + tl, STRLEN(p + tl) + 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5225 mch_memmove(p, ftp->ft_from, fl);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5226 sp->ts_state = STATE_REP;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5227 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5228
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5229 default:
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5230 /* Did all possible states at this level, go up one level. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5231 --depth;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5232 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5233
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5234 line_breakcheck();
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5235 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5236 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5237 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5238
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5239 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5240 * Try going one level deeper in the tree.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5241 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5242 static int
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5243 try_deeper(su, stack, depth, score_add)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5244 suginfo_T *su;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5245 trystate_T *stack;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5246 int depth;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5247 int score_add;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5248 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5249 int newscore;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5250
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5251 /* Refuse to go deeper if the scrore is getting too big. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5252 newscore = stack[depth].ts_score + score_add;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5253 if (newscore >= su->su_maxscore)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5254 return FALSE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5255
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5256 stack[depth + 1] = stack[depth];
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5257 stack[depth + 1].ts_state = STATE_START;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5258 stack[depth + 1].ts_score = newscore;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5259 stack[depth + 1].ts_curi = 1; /* start just after length byte */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5260 return TRUE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5261 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5262
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5263 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5264 * "fword" is a good word with case folded. Find the matching keep-case
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5265 * words and put it in "kword".
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5266 * Theoretically there could be several keep-case words that result in the
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5267 * same case-folded word, but we only find one...
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5268 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5269 static void
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5270 find_keepcap_word(slang, fword, kword)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5271 slang_T *slang;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5272 char_u *fword;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5273 char_u *kword;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5274 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5275 char_u uword[MAXWLEN]; /* "fword" in upper-case */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5276 int depth;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5277 idx_T tryidx;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5278
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5279 /* The following arrays are used at each depth in the tree. */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5280 idx_T arridx[MAXWLEN];
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5281 int round[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5282 int fwordidx[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5283 int uwordidx[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5284 int kwordlen[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5285
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5286 int flen, ulen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5287 int l;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5288 int len;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5289 int c;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5290 idx_T lo, hi, m;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5291 char_u *p;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5292 char_u *byts = slang->sl_kbyts; /* array with bytes of the words */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5293 idx_T *idxs = slang->sl_kidxs; /* array with indexes */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5294
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5295 if (byts == NULL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5296 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5297 /* array is empty: "cannot happen" */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5298 *kword = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5299 return;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5300 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5301
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5302 /* Make an all-cap version of "fword". */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5303 allcap_copy(fword, uword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5304
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5305 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5306 * Each character needs to be tried both case-folded and upper-case.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5307 * All this gets very complicated if we keep in mind that changing case
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5308 * may change the byte length of a multi-byte character...
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5309 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5310 depth = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5311 arridx[0] = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5312 round[0] = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5313 fwordidx[0] = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5314 uwordidx[0] = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5315 kwordlen[0] = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5316 while (depth >= 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5317 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5318 if (fword[fwordidx[depth]] == NUL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5319 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5320 /* 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
5321 * here we have found a match. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5322 if (byts[arridx[depth] + 1] == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5323 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5324 kword[kwordlen[depth]] = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5325 return;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5326 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5327
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5328 /* kword is getting too long, continue one level up */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5329 --depth;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5330 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5331 else if (++round[depth] > 2)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5332 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5333 /* tried both fold-case and upper-case character, continue one
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5334 * level up */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5335 --depth;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5336 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5337 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5338 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5339 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5340 * round[depth] == 1: Try using the folded-case character.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5341 * round[depth] == 2: Try using the upper-case character.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5342 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5343 #ifdef FEAT_MBYTE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5344 if (has_mbyte)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5345 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5346 flen = mb_ptr2len_check(fword + fwordidx[depth]);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5347 ulen = mb_ptr2len_check(uword + uwordidx[depth]);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5348 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5349 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5350 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5351 ulen = flen = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5352 if (round[depth] == 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5353 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5354 p = fword + fwordidx[depth];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5355 l = flen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5356 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5357 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5358 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5359 p = uword + uwordidx[depth];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5360 l = ulen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5361 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5362
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5363 for (tryidx = arridx[depth]; l > 0; --l)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5364 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5365 /* Perform a binary search in the list of accepted bytes. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5366 len = byts[tryidx++];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5367 c = *p++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5368 lo = tryidx;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5369 hi = tryidx + len - 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5370 while (lo < hi)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5371 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5372 m = (lo + hi) / 2;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5373 if (byts[m] > c)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5374 hi = m - 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5375 else if (byts[m] < c)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5376 lo = m + 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5377 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5378 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5379 lo = hi = m;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5380 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5381 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5382 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5383
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5384 /* Stop if there is no matching byte. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5385 if (hi < lo || byts[lo] != c)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5386 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5387
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5388 /* Continue at the child (if there is one). */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5389 tryidx = idxs[lo];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5390 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5391
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5392 if (l == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5393 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5394 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5395 * Found the matching char. Copy it to "kword" and go a
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5396 * level deeper.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5397 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5398 if (round[depth] == 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5399 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5400 STRNCPY(kword + kwordlen[depth], fword + fwordidx[depth],
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5401 flen);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5402 kwordlen[depth + 1] = kwordlen[depth] + flen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5403 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5404 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5405 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5406 STRNCPY(kword + kwordlen[depth], uword + uwordidx[depth],
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5407 ulen);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5408 kwordlen[depth + 1] = kwordlen[depth] + ulen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5409 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5410 fwordidx[depth + 1] = fwordidx[depth] + flen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5411 uwordidx[depth + 1] = uwordidx[depth] + ulen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5412
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5413 ++depth;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5414 arridx[depth] = tryidx;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5415 round[depth] = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5416 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5417 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5418 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5419
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5420 /* Didn't find it: "cannot happen". */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5421 *kword = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5422 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5423
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5424 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5425 * Find suggestions by comparing the word in a sound-a-like form.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5426 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5427 static void
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5428 spell_try_soundalike(su)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5429 suginfo_T *su;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5430 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5431 char_u salword[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5432 char_u tword[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5433 char_u tfword[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5434 char_u tsalword[MAXWLEN];
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5435 idx_T arridx[MAXWLEN];
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5436 int curi[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5437 langp_T *lp;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5438 char_u *byts;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5439 idx_T *idxs;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5440 int depth;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5441 int c;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5442 idx_T n;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5443 int round;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5444 int flags;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5445 int score, sound_score;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5446 char_u *bp, *sp;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5447
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5448 for (lp = LANGP_ENTRY(curwin->w_buffer->b_langp, 0);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5449 lp->lp_slang != NULL; ++lp)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5450 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5451 if (lp->lp_slang->sl_sal.ga_len > 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5452 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5453 /* soundfold the bad word */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5454 spell_soundfold(lp->lp_slang, su->su_fbadword, salword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5455
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5456 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5457 * Go through the whole tree, soundfold each word and compare.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5458 * round 1: use the case-folded tree.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5459 * round 2: use the keep-case tree.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5460 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5461 for (round = 1; round <= 2; ++round)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5462 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5463 if (round == 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5464 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5465 byts = lp->lp_slang->sl_fbyts;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5466 idxs = lp->lp_slang->sl_fidxs;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5467 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5468 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5469 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5470 byts = lp->lp_slang->sl_kbyts;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5471 idxs = lp->lp_slang->sl_kidxs;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5472 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5473
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5474 depth = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5475 arridx[0] = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5476 curi[0] = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5477 while (depth >= 0 && !got_int)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5478 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5479 if (curi[depth] > byts[arridx[depth]])
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5480 /* Done all bytes at this node, go up one level. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5481 --depth;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5482 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5483 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5484 /* Do one more byte at this node. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5485 n = arridx[depth] + curi[depth];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5486 ++curi[depth];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5487 c = byts[n];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5488 if (c == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5489 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5490 /* End of word, deal with the word. */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5491 flags = (int)idxs[n];
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5492 if (round == 2 || (flags & WF_KEEPCAP) == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5493 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5494 tword[depth] = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5495 if (round == 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5496 spell_soundfold(lp->lp_slang,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5497 tword, tsalword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5498 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5499 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5500 /* In keep-case tree need to case-fold the
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5501 * word. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5502 (void)spell_casefold(tword, depth,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5503 tfword, MAXWLEN);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5504 spell_soundfold(lp->lp_slang,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5505 tfword, tsalword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5506 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5507
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5508 /*
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5509 * Accept the word if the sound-folded words
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5510 * are (almost) equal.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5511 */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5512 for (bp = salword, sp = tsalword; *bp == *sp;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5513 ++bp, ++sp)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5514 if (*bp == NUL)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5515 break;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5516
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5517 if (*bp == *sp)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5518 /* equal */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5519 sound_score = 0;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5520 else if (*bp != NUL && bp[1] != NUL
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5521 && *bp == sp[1] && bp[1] == *sp
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5522 && STRCMP(bp + 2, sp + 2) == 0)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5523 /* swap two bytes */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5524 sound_score = SCORE_SWAP;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5525 else if (STRCMP(bp + 1, sp) == 0)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5526 /* delete byte */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5527 sound_score = SCORE_DEL;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5528 else if (STRCMP(bp, sp + 1) == 0)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5529 /* insert byte */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5530 sound_score = SCORE_INS;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5531 else if (STRCMP(bp + 1, sp + 1) == 0)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5532 /* skip one byte */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5533 sound_score = SCORE_SUBST;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5534 else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5535 /* not equal or similar */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5536 sound_score = SCORE_MAXMAX;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5537
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5538 if (sound_score < SCORE_MAXMAX)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5539 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5540 char_u cword[MAXWLEN];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5541 char_u *p;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5542
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5543 if (round == 1 && flags != 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5544 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5545 /* Need to fix case according to
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5546 * "flags". */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5547 make_case_word(tword, cword, flags);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5548 p = cword;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5549 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5550 else
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5551 p = tword;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5552
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5553 /* Compute the score. */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5554 score = spell_edit_score(su->su_badword, p);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5555 #ifdef RESCORE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5556 /* give a bonus for the good word sounding
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5557 * the same as the bad word */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5558 add_suggestion(su, tword,
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5559 RESCORE(score, sound_score),
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5560 TRUE);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5561 #else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5562 add_suggestion(su, tword,
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5563 score + sound_score);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5564 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5565 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5566 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5567
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5568 /* Skip over other NUL bytes. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5569 while (byts[n + 1] == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5570 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5571 ++n;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5572 ++curi[depth];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5573 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5574 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5575 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5576 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5577 /* Normal char, go one level deeper. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5578 tword[depth++] = c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5579 arridx[depth] = idxs[n];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5580 curi[depth] = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5581 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5582 }
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5583
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5584 line_breakcheck();
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5585 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5586 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5587 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5588 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5589 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5590
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5591 /*
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5592 * Copy "fword" to "cword", fixing case according to "flags".
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5593 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5594 static void
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5595 make_case_word(fword, cword, flags)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5596 char_u *fword;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5597 char_u *cword;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5598 int flags;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5599 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5600 if (flags & WF_ALLCAP)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5601 /* Make it all upper-case */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5602 allcap_copy(fword, cword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5603 else if (flags & WF_ONECAP)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5604 /* Make the first letter upper-case */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5605 onecap_copy(fword, cword, TRUE);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5606 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5607 /* Use goodword as-is. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5608 STRCPY(cword, fword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5609 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5610
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5611 /*
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5612 * Use map string "map" for languages "lp".
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5613 */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5614 static void
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5615 set_map_str(lp, map)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5616 slang_T *lp;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5617 char_u *map;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5618 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5619 char_u *p;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5620 int headc = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5621 int c;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5622 int i;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5623
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5624 if (*map == NUL)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5625 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5626 lp->sl_has_map = FALSE;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5627 return;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5628 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5629 lp->sl_has_map = TRUE;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5630
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5631 /* Init the array and hash table empty. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5632 for (i = 0; i < 256; ++i)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5633 lp->sl_map_array[i] = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5634 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5635 hash_init(&lp->sl_map_hash);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5636 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5637
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5638 /*
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5639 * The similar characters are stored separated with slashes:
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5640 * "aaa/bbb/ccc/". Fill sl_map_array[c] with the character before c and
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5641 * before the same slash. For characters above 255 sl_map_hash is used.
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5642 */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5643 for (p = map; *p != NUL; )
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5644 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5645 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5646 c = mb_ptr2char_adv(&p);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5647 #else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5648 c = *p++;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5649 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5650 if (c == '/')
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5651 headc = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5652 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5653 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5654 if (headc == 0)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5655 headc = c;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5656
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5657 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5658 /* Characters above 255 don't fit in sl_map_array[], put them in
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5659 * the hash table. Each entry is the char, a NUL the headchar and
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5660 * a NUL. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5661 if (c >= 256)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5662 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5663 int cl = mb_char2len(c);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5664 int headcl = mb_char2len(headc);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5665 char_u *b;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5666 hash_T hash;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5667 hashitem_T *hi;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5668
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5669 b = alloc((unsigned)(cl + headcl + 2));
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5670 if (b == NULL)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5671 return;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5672 mb_char2bytes(c, b);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5673 b[cl] = NUL;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5674 mb_char2bytes(headc, b + cl + 1);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5675 b[cl + 1 + headcl] = NUL;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5676 hash = hash_hash(b);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5677 hi = hash_lookup(&lp->sl_map_hash, b, hash);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5678 if (HASHITEM_EMPTY(hi))
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5679 hash_add_item(&lp->sl_map_hash, hi, b, hash);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5680 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5681 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5682 /* This should have been checked when generating the .spl
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5683 * file. */
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5684 EMSG(_("E999: duplicate char in MAP entry"));
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5685 vim_free(b);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5686 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5687 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5688 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5689 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5690 lp->sl_map_array[c] = headc;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5691 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5692 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5693 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5694
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5695 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5696 * Return TRUE if "c1" and "c2" are similar characters according to the MAP
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5697 * lines in the .aff file.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5698 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5699 static int
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5700 similar_chars(slang, c1, c2)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5701 slang_T *slang;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5702 int c1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5703 int c2;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5704 {
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5705 int m1, m2;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5706 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5707 char_u buf[MB_MAXBYTES];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5708 hashitem_T *hi;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5709
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5710 if (c1 >= 256)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5711 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5712 buf[mb_char2bytes(c1, buf)] = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5713 hi = hash_find(&slang->sl_map_hash, buf);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5714 if (HASHITEM_EMPTY(hi))
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5715 m1 = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5716 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5717 m1 = mb_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5718 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5719 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5720 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5721 m1 = slang->sl_map_array[c1];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5722 if (m1 == 0)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5723 return FALSE;
330
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5724
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5725
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5726 #ifdef FEAT_MBYTE
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5727 if (c2 >= 256)
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5728 {
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5729 buf[mb_char2bytes(c2, buf)] = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5730 hi = hash_find(&slang->sl_map_hash, buf);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5731 if (HASHITEM_EMPTY(hi))
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5732 m2 = 0;
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5733 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5734 m2 = mb_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1);
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5735 }
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5736 else
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5737 #endif
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5738 m2 = slang->sl_map_array[c2];
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5739
f76b0d38b6bd updated for version 7.0086
vimboss
parents: 324
diff changeset
5740 return m1 == m2;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5741 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5742
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5743 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5744 * Add a suggestion to the list of suggestions.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5745 * Do not add a duplicate suggestion or suggestions with a bad score.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5746 * When "use_score" is not zero it's used, otherwise the score is computed
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5747 * with spell_edit_score().
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5748 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5749 static void
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5750 add_suggestion(su, goodword, score
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5751 #ifdef RESCORE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5752 , had_bonus
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5753 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5754 )
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5755 suginfo_T *su;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5756 char_u *goodword;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5757 int score;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5758 #ifdef RESCORE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5759 int had_bonus; /* set st_had_bonus */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5760 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5761 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5762 suggest_T *stp;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5763 int i;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5764 #ifdef SOUNDFOLD_SCORE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5765 char_u fword[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5766 char_u salword[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5767 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5768
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5769 /* Check that the word wasn't banned. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5770 if (was_banned(su, goodword))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5771 return;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5772
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5773 if (score <= su->su_maxscore)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5774 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5775 #ifdef SOUNDFOLD_SCORE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5776 /* Add to the score when the word sounds differently.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5777 * This is slow... */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5778 if (su->su_slang->sl_sal.ga_len > 0)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5779 score += spell_sound_score(su->su_slang, fword, su->su_salword);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5780 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5781
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5782 /* Check if the word is already there. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5783 stp = &SUG(su, 0);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5784 for (i = su->su_ga.ga_len - 1; i >= 0; --i)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5785 if (STRCMP(stp[i].st_word, goodword) == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5786 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5787 /* Found it. Remember the lowest score. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5788 if (stp[i].st_score > score)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5789 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5790 stp[i].st_score = score;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5791 #ifdef RESCORE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5792 stp[i].st_had_bonus = had_bonus;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5793 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5794 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5795 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5796 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5797
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5798 if (i < 0 && ga_grow(&su->su_ga, 1) == OK)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5799 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5800 /* Add a suggestion. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5801 stp = &SUG(su, su->su_ga.ga_len);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5802 stp->st_word = vim_strsave(goodword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5803 if (stp->st_word != NULL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5804 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5805 stp->st_score = score;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5806 #ifdef RESCORE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5807 stp->st_had_bonus = had_bonus;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5808 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5809 stp->st_orglen = su->su_badlen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5810 ++su->su_ga.ga_len;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5811
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5812 /* If we have too many suggestions now, sort the list and keep
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5813 * the best suggestions. */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5814 if (su->su_ga.ga_len > SUG_MAX_COUNT)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5815 cleanup_suggestions(su, SUG_CLEAN_COUNT);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5816 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5817 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5818 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5819 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5820
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5821 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5822 * Add a word to be banned.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5823 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5824 static void
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5825 add_banned(su, word)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5826 suginfo_T *su;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5827 char_u *word;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5828 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5829 char_u *s = vim_strsave(word);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5830 hash_T hash;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5831 hashitem_T *hi;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5832
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5833 if (s != NULL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5834 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5835 hash = hash_hash(s);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5836 hi = hash_lookup(&su->su_banned, s, hash);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5837 if (HASHITEM_EMPTY(hi))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5838 hash_add_item(&su->su_banned, hi, s, hash);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5839 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5840 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5841
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5842 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5843 * Return TRUE if a word appears in the list of banned words.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5844 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5845 static int
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5846 was_banned(su, word)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5847 suginfo_T *su;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5848 char_u *word;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5849 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5850 hashitem_T *hi = hash_find(&su->su_banned, word);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5851
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5852 return !HASHITEM_EMPTY(hi);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5853 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5854
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5855 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5856 * Free the banned words in "su".
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5857 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5858 static void
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5859 free_banned(su)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5860 suginfo_T *su;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5861 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5862 int todo;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5863 hashitem_T *hi;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5864
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5865 todo = su->su_banned.ht_used;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5866 for (hi = su->su_banned.ht_array; todo > 0; ++hi)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5867 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5868 if (!HASHITEM_EMPTY(hi))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5869 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5870 vim_free(hi->hi_key);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5871 --todo;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5872 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5873 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5874 hash_clear(&su->su_banned);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5875 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5876
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5877 #ifdef RESCORE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5878 /*
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5879 * Recompute the score if sound-folding is possible. This is slow,
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5880 * thus only done for the final results.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5881 */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5882 static void
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5883 rescore_suggestions(su)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5884 suginfo_T *su;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5885 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5886 langp_T *lp;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5887 suggest_T *stp;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5888 char_u sal_badword[MAXWLEN];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5889 int score;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5890 int i;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5891
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5892 for (lp = LANGP_ENTRY(curwin->w_buffer->b_langp, 0);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5893 lp->lp_slang != NULL; ++lp)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5894 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5895 if (lp->lp_slang->sl_sal.ga_len > 0)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5896 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5897 /* soundfold the bad word */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5898 spell_soundfold(lp->lp_slang, su->su_fbadword, sal_badword);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5899
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5900 for (i = 0; i < su->su_ga.ga_len; ++i)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5901 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5902 stp = &SUG(su, i);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5903 if (!stp->st_had_bonus)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5904 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5905 score = spell_sound_score(lp->lp_slang, stp->st_word,
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5906 sal_badword);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5907 stp->st_score = RESCORE(stp->st_score, score);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5908 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5909 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5910 break;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5911 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5912 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5913 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5914 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5915
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5916 static int
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5917 #ifdef __BORLANDC__
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5918 _RTLENTRYF
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5919 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5920 sug_compare __ARGS((const void *s1, const void *s2));
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5921
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5922 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5923 * Function given to qsort() to sort the suggestions on st_score.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5924 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5925 static int
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5926 #ifdef __BORLANDC__
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5927 _RTLENTRYF
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5928 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5929 sug_compare(s1, s2)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5930 const void *s1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5931 const void *s2;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5932 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5933 suggest_T *p1 = (suggest_T *)s1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5934 suggest_T *p2 = (suggest_T *)s2;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5935
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5936 return p1->st_score - p2->st_score;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5937 }
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 * Cleanup the suggestions:
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5941 * - Sort on score.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5942 * - Remove words that won't be displayed.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5943 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5944 static void
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5945 cleanup_suggestions(su, keep)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5946 suginfo_T *su;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5947 int keep; /* nr of suggestions to keep */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5948 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5949 suggest_T *stp = &SUG(su, 0);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5950 int i;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5951
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5952 /* Sort the list. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5953 qsort(su->su_ga.ga_data, (size_t)su->su_ga.ga_len,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5954 sizeof(suggest_T), sug_compare);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5955
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5956 /* Truncate the list to the number of suggestions that will be displayed. */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5957 if (su->su_ga.ga_len > keep)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5958 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5959 for (i = keep; i < su->su_ga.ga_len; ++i)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5960 vim_free(stp[i].st_word);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5961 su->su_ga.ga_len = keep;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5962 su->su_maxscore = stp[keep - 1].st_score;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5963 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5964 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5965
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5966 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5967 * Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]".
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5968 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5969 static void
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5970 spell_soundfold(slang, inword, res)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5971 slang_T *slang;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5972 char_u *inword;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5973 char_u *res;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5974 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5975 fromto_T *ftp;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5976 char_u word[MAXWLEN];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5977 #ifdef FEAT_MBYTE
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5978 int l;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5979 int found_mbyte = FALSE;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5980 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5981 char_u *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5982 char_u *t;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5983 int i, j, z;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5984 int n, k = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5985 int z0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5986 int k0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5987 int n0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5988 int c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5989 int pri;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5990 int p0 = -333;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5991 int c0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5992
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5993 /* Remove accents, if wanted. We actually remove all non-word characters.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
5994 * But keep white space. */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5995 if (slang->sl_rem_accents)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5996 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5997 t = word;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5998 for (s = inword; *s != NUL; )
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
5999 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6000 if (vim_iswhite(*s))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6001 *t++ = *s++;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6002 #ifdef FEAT_MBYTE
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6003 else if (has_mbyte)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6004 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6005 l = mb_ptr2len_check(s);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6006 if (SPELL_ISWORDP(s))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6007 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6008 mch_memmove(t, s, l);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6009 t += l;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6010 if (l > 1)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6011 found_mbyte = TRUE;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6012 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6013 s += l;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6014 }
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6015 #endif
323
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 if (SPELL_ISWORDP(s))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6019 *t++ = *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6020 ++s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6021 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6022 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6023 *t = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6024 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6025 else
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6026 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6027 #ifdef FEAT_MBYTE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6028 if (has_mbyte)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6029 for (s = inword; *s != NUL; s += l)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6030 if ((l = mb_ptr2len_check(s)) > 1)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6031 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6032 found_mbyte = TRUE;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6033 break;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6034 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6035 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6036 STRCPY(word, inword);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6037 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6038
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6039 #ifdef FEAT_MBYTE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6040 /* If there are multi-byte characters in the word return it as-is, because
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6041 * the following won't work. */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6042 if (found_mbyte)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6043 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6044 STRCPY(res, word);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6045 return;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6046 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6047 #endif
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6048
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6049 ftp = (fromto_T *)slang->sl_sal.ga_data;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6050
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6051 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6052 * This comes from Aspell phonet.cpp. Converted from C++ to C.
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6053 * Changed to keep spaces.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6054 * TODO: support for multi-byte chars.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6055 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6056 i = j = z = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6057 while ((c = word[i]) != NUL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6058 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6059 n = slang->sl_sal_first[c];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6060 z0 = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6061
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6062 if (n >= 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6063 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6064 /* check all rules for the same letter */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6065 while (ftp[n].ft_from[0] == c)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6066 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6067 /* check whole string */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6068 k = 1; /* number of found letters */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6069 pri = 5; /* default priority */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6070 s = ftp[n].ft_from;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6071 s++; /* important for (see below) "*(s-1)" */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6072
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6073 /* Skip over normal letters that match with the word. */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6074 while (*s != NUL && word[i + k] == *s
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6075 && !vim_isdigit(*s) && strchr("(-<^$", *s) == NULL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6076 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6077 k++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6078 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6079 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6080
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6081 if (*s == '(')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6082 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6083 /* check alternate letters in "(..)" */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6084 for (t = s + 1; *t != ')' && *t != NUL; ++t)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6085 if (*t == word[i + k])
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6086 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6087 /* match */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6088 ++k;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6089 for (s = t + 1; *s != NUL; ++s)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6090 if (*s == ')')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6091 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6092 ++s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6093 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6094 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6095 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6096 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6097 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6098
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6099 p0 = *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6100 k0 = k;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6101 while (*s == '-' && k > 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6102 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6103 k--;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6104 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6105 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6106 if (*s == '<')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6107 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6108 if (vim_isdigit(*s))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6109 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6110 /* determine priority */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6111 pri = *s - '0';
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6112 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6113 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6114 if (*s == '^' && *(s + 1) == '^')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6115 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6116
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6117 if (*s == NUL
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6118 || (*s == '^'
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6119 && (i == 0 || !(word[i - 1] == ' '
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6120 || SPELL_ISWORDP(word + i - 1)))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6121 && (*(s + 1) != '$'
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6122 || (!SPELL_ISWORDP(word + i + k0))))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6123 || (*s == '$' && i > 0
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6124 && SPELL_ISWORDP(word + i - 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6125 && (!SPELL_ISWORDP(word + i + k0))))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6126 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6127 /* search for followup rules, if: */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6128 /* followup and k > 1 and NO '-' in searchstring */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6129 c0 = word[i + k - 1];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6130 n0 = slang->sl_sal_first[c0];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6131
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6132 if (slang->sl_followup && k > 1 && n0 >= 0
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6133 && p0 != '-' && word[i + k] != NUL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6134 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6135 /* test follow-up rule for "word[i + k]" */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6136 while (ftp[n0].ft_from[0] == c0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6137 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6138
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6139 /* check whole string */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6140 k0 = k;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6141 p0 = 5;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6142 s = ftp[n0].ft_from;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6143 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6144 while (*s != NUL && word[i+k0] == *s
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6145 && !vim_isdigit(*s)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6146 && strchr("(-<^$",*s) == NULL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6147 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6148 k0++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6149 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6150 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6151 if (*s == '(')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6152 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6153 /* check alternate letters in "(..)" */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6154 for (t = s + 1; *t != ')' && *t != NUL; ++t)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6155 if (*t == word[i + k0])
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6156 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6157 /* match */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6158 ++k0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6159 for (s = t + 1; *s != NUL; ++s)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6160 if (*s == ')')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6161 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6162 ++s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6163 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6164 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6165 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6166 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6167 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6168 while (*s == '-')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6169 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6170 /* "k0" gets NOT reduced */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6171 /* because "if (k0 == k)" */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6172 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6173 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6174 if (*s == '<')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6175 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6176 if (vim_isdigit(*s))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6177 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6178 p0 = *s - '0';
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6179 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6180 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6181
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6182 if (*s == NUL
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6183 /* *s == '^' cuts */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6184 || (*s == '$'
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6185 && !SPELL_ISWORDP(word + i + k0)))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6186 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6187 if (k0 == k)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6188 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6189 /* this is just a piece of the string */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6190 ++n0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6191 continue;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6192 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6193
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6194 if (p0 < pri)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6195 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6196 /* priority too low */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6197 ++n0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6198 continue;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6199 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6200 /* rule fits; stop search */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6201 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6202 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6203 ++n0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6204 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6205
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6206 if (p0 >= pri && ftp[n0].ft_from[0] == c0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6207 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6208 ++n;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6209 continue;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6210 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6211 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6212
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6213 /* replace string */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6214 s = ftp[n].ft_to;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6215 p0 = (ftp[n].ft_from[0] != NUL
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6216 && vim_strchr(ftp[n].ft_from + 1,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6217 '<') != NULL) ? 1 : 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6218 if (p0 == 1 && z == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6219 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6220 /* rule with '<' is used */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6221 if (j > 0 && *s != NUL
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6222 && (res[j - 1] == c || res[j - 1] == *s))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6223 j--;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6224 z0 = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6225 z = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6226 k0 = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6227 while (*s != NUL && word[i+k0] != NUL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6228 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6229 word[i + k0] = *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6230 k0++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6231 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6232 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6233 if (k > k0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6234 mch_memmove(word + i + k0, word + i + k,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6235 STRLEN(word + i + k) + 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6236
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6237 /* new "actual letter" */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6238 c = word[i];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6239 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6240 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6241 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6242 /* no '<' rule used */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6243 i += k - 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6244 z = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6245 while (*s != NUL && s[1] != NUL && j < MAXWLEN)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6246 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6247 if (j == 0 || res[j - 1] != *s)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6248 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6249 res[j] = *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6250 j++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6251 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6252 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6253 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6254 /* new "actual letter" */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6255 c = *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6256 if (ftp[n].ft_from[0] != NUL
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6257 && strstr((char *)ftp[n].ft_from + 1,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6258 "^^") != NULL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6259 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6260 if (c != NUL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6261 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6262 res[j] = c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6263 j++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6264 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6265 mch_memmove(word, word + i + 1,
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6266 STRLEN(word + i + 1) + 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6267 i = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6268 z0 = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6269 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6270 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6271 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6272 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6273 ++n;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6274 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6275 }
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6276 else if (vim_iswhite(c))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6277 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6278 c = ' ';
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6279 k = 1;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6280 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6281
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6282 if (z0 == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6283 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6284 if (k && !p0 && j < MAXWLEN && c != NUL
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6285 && (!slang->sl_collapse || j == 0 || res[j - 1] != c))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6286 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6287 /* condense only double letters */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6288 res[j] = c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6289 j++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6290 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6291
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6292 i++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6293 z = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6294 k = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6295 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6296 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6297
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6298 res[j] = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6299 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6300
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6301 #if defined(RESCORE) || defined(SOUNDFOLD_SCORE)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6302 /*
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6303 * Return the score for how much words sound different.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6304 */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6305 static int
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6306 spell_sound_score(slang, goodword, badsound)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6307 slang_T *slang;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6308 char_u *goodword; /* good word */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6309 char_u *badsound; /* sound-folded bad word */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6310 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6311 char_u fword[MAXWLEN];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6312 char_u goodsound[MAXWLEN];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6313 int score;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6314
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6315 /* Case-fold the word, needed for sound folding. */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6316 (void)spell_casefold(goodword, STRLEN(goodword), fword, MAXWLEN);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6317
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6318 /* sound-fold the good word */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6319 spell_soundfold(slang, fword, goodsound);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6320
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6321 /* compute the edit distance-score of the sounds */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6322 score = spell_edit_score(badsound, goodsound);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6323
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6324 /* Correction: adding/inserting "*" at the start (word starts with vowel)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6325 * shouldn't be counted so much, vowels halfway the word aren't counted at
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6326 * all. */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6327 if (*badsound != *goodsound && (*badsound == '*' || *goodsound == '*'))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6328 score -= SCORE_DEL / 2;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6329
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6330 return score;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6331 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6332 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6333
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6334 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6335 * Compute the "edit distance" to turn "badword" into "goodword". The less
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6336 * deletes/inserts/swaps are required the lower the score.
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6337 *
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6338 * The algorithm comes from Aspell editdist.cpp, edit_distance().
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6339 * It has been converted from C++ to C and modified to support multi-byte
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6340 * characters.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6341 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6342 static int
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6343 spell_edit_score(badword, goodword)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6344 char_u *badword;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6345 char_u *goodword;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6346 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6347 int *cnt;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6348 int badlen, goodlen;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6349 int j, i;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6350 int t;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6351 int bc, gc;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6352 int pbc, pgc;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6353 #ifdef FEAT_MBYTE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6354 char_u *p;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6355 int wbadword[MAXWLEN];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6356 int wgoodword[MAXWLEN];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6357
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6358 if (has_mbyte)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6359 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6360 /* Get the characters from the multi-byte strings and put them in an
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6361 * int array for easy access. */
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6362 for (p = badword, badlen = 0; *p != NUL; )
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6363 wbadword[badlen++] = mb_ptr2char_adv(&p);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6364 ++badlen;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6365 for (p = goodword, goodlen = 0; *p != NUL; )
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6366 wgoodword[goodlen++] = mb_ptr2char_adv(&p);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6367 ++goodlen;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6368 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6369 else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6370 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6371 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6372 badlen = STRLEN(badword) + 1;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6373 goodlen = STRLEN(goodword) + 1;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6374 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6375
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6376 /* We use "cnt" as an array: CNT(badword_idx, goodword_idx). */
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6377 #define CNT(a, b) cnt[(a) + (b) * (badlen + 1)]
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6378 cnt = (int *)lalloc((long_u)(sizeof(int) * (badlen + 1) * (goodlen + 1)),
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6379 TRUE);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6380 if (cnt == NULL)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6381 return 0; /* out of memory */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6382
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6383 CNT(0, 0) = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6384 for (j = 1; j <= goodlen; ++j)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6385 CNT(0, j) = CNT(0, j - 1) + SCORE_DEL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6386
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6387 for (i = 1; i <= badlen; ++i)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6388 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6389 CNT(i, 0) = CNT(i - 1, 0) + SCORE_INS;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6390 for (j = 1; j <= goodlen; ++j)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6391 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6392 #ifdef FEAT_MBYTE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6393 if (has_mbyte)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6394 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6395 bc = wbadword[i - 1];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6396 gc = wgoodword[j - 1];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6397 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6398 else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6399 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6400 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6401 bc = badword[i - 1];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6402 gc = goodword[j - 1];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6403 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6404 if (bc == gc)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6405 CNT(i, j) = CNT(i - 1, j - 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6406 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6407 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6408 /* Use a better score when there is only a case difference. */
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6409 if (SPELL_TOFOLD(bc) == SPELL_TOFOLD(gc))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6410 CNT(i, j) = SCORE_ICASE + CNT(i - 1, j - 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6411 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6412 CNT(i, j) = SCORE_SUBST + CNT(i - 1, j - 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6413
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6414 if (i > 1 && j > 1)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6415 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6416 #ifdef FEAT_MBYTE
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6417 if (has_mbyte)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6418 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6419 pbc = wbadword[i - 2];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6420 pgc = wgoodword[j - 2];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6421 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6422 else
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6423 #endif
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6424 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6425 pbc = badword[i - 2];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6426 pgc = goodword[j - 2];
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6427 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6428 if (bc == pgc && pbc == gc)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6429 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6430 t = SCORE_SWAP + CNT(i - 2, j - 2);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6431 if (t < CNT(i, j))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6432 CNT(i, j) = t;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
6433 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6434 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6435 t = SCORE_DEL + CNT(i - 1, j);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6436 if (t < CNT(i, j))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6437 CNT(i, j) = t;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6438 t = SCORE_INS + CNT(i, j - 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6439 if (t < CNT(i, j))
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6440 CNT(i, j) = t;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6441 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6442 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6443 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6444 return CNT(badlen - 1, goodlen - 1);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
6445 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
6446
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
6447 #endif /* FEAT_SYN_HL */